Algorithm to compute the sum of digits in the nth Look and Say Sequence

Viewed 11

I was recently given a problem on a Hackerrank that, given a set of queries Q, for each query Q[i] compute the sum of the digits in the Q[i]th look-and-say sequence. My bounds were as follows: Q.length <= 1000, Q[i] <= 54. Of course, the brute force approach times out, how would I approach this problem given these bounds? My idea was to use a segment tree or DP but I ran out of time.

0 Answers
Related