Hallo, i got an assignment, to write an efficient program that would select the longest substring of the same character from a string. let's say character is 'a' and string is aasddaaa. So the resulting output is "aaa". And here comes the question: how should i understand word efficient, is there an algorithm or smth. I would be very appreciated if someone claryfied it to me.
Efficient to me would mean code that runs most efficiently. There is very little overhead, no unnecessary objects instantiated, none left hanging around when not necessary. From the sounds of your question though, I'd say you have to come up with the cleverest way of performing this with the least amount of written code.
I'd say that the aim of the assignment is to get you to think about problem solving a little rather than just writing code. For this kind of problem, there are a range of "right" solutions but I'm guessing that whoever set the assignment just wants you to have a go at implementing what you perceive is a reasonably effective solution. e.g. one way to solve it would be to step through the alphabet and count all the instances of each letter in the String... this would obviously work for strings using only the letters of the english language, but would require lots of unnecessary comparisons. better to start with the first letter, count the instances... For this kind of assignment, by far the best solution is to have a go, get something to work, analyse where code is redundant or calculations are lengthy and try to work on that part in isolation. Have fun!