Java interview question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java interview question

Given a string "aaabbbcc", compress it, = "a3b3c2" . Given that output string's length is always smaller than input string, you have do it inplace. No extra space Please answer anyone

9th Mar 2020, 10:37 AM
Haritha Vuppula
Haritha Vuppula - avatar
4 Answers
0
Is there any other constrains? If there is atleast one, one char of 3times then only string length is become smaller than original. Use a for to traverse string, start at index 1. If charAt(i) ==charAt(i-1) count increment, continue, Else append char and count, proceed to next one... This way you can do it... There may be better solution... Edit: As a code practice, can you try to code and share it?
9th Mar 2020, 12:53 PM
Jayakrishna 🇮🇳
+ 5
Post your code then we will help you
9th Mar 2020, 11:18 AM
Pedro H.J
Pedro H.J - avatar
0
i dont know code that was the question to code
9th Mar 2020, 12:21 PM
Haritha Vuppula
Haritha Vuppula - avatar
0
There are somany java interview questions found on google. If you're looking for those questions to crack the interviews, then go through these blogs: * https://www.javatpoint.com/corejava-interview-questions * https://www.interviewbit.com/java-interview-questions/ * https://www.techgeekbuzz.com/core-java-interview-questions/ * https://www.techgeekbuzz.com/top-tcs-interview-questions/ You can find somany java interview questions that can help you land your dream jobs.
8th Mar 2022, 6:28 AM
cloudy tech