Special String Again

  • + 0 comments

    Hi. I'm not sure if is possible to solve the problem using triangular number only. Triangular number is just an especific sequence and in this solution, triangular number is part of the solution. I'll try explain the solution step by step :

    1) len(s) -> count all char of the word;

    2) exp1 -> count all words that follow this rule: a_a also aaaa_aaaa;

    3) exp2 -> count all repeated char of the word and with triangular number all combinations of these repeated chars. Example of this step is: aaaa has the combination of:

    'aa'+'aa'+'aa'

    +'aaa'+'aaa'

    +'aaaa' = 6 (realize 6 is the same T3 of triangular number sequence).

    The final answer is the sum of all these steps.