I have been asked this question where I am asked to find the Nth number in the sequence. The sequence goes like this 555 35 1315 11131115 31133115 1321232115.
The sequence is a count of each character in the string. Let's say I start with 555, then since I have three occurances of '5', the next number would be 35. Similarly, since I have one occurance of 3, and one occurance of 5, the next number would be 1315.
Now, I was asked this question where I have to get the nth number of such sequence with input being any random number. I have suggested a bruteforce approach, or if there are a fixed set of numbers, then we could cache the results. I want to know if there is a better way to code this? or is there any existing algorithm for such a problem statement?