Sum of Scores of Built Strings
You are constructing a string s of length n one character at a time, adding each new character to the front of the string. The strings are labeled from 1 to n, where the string with length i is labeled s[i].
For instance, if s = "abaca", then s[1] == "a", s[2] == "ca", s[3] == "aca", and so on. The score of s[i] is defined as the length of the longest common prefix between s[i] and s[n] (where s == s[n]).
Given the final string s, your task is to calculate and print the sum of the scores of all strings s[i].
Ada AI
I want to discuss a solution
Help me solve this
Give more examples
What's wrong with my code?
How to use 'for loop' in javascript?
javascript (node 13.12.0)