We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
its from a formula n(n+1)/2 which give the sum of all term, like n = 5, 1+2+3+4+5 = 5(5+1)/2 = 15.
Its used because if you have "aaaa" , you can have "a,a,a,a", "aa,aa,aa", "aaa,aaa" and "aaaa", we can see the partern of 4,3,2,1 groups, so in this case there's 15 groups!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Special String Again
You are viewing a single comment's thread. Return to all comments →
For those who doesn't understand this line,
for i in l: ans += (i[1] * (i[1] + 1)) / 2
its from a formula n(n+1)/2 which give the sum of all term, like n = 5, 1+2+3+4+5 = 5(5+1)/2 = 15.
Its used because if you have "aaaa" , you can have "a,a,a,a", "aa,aa,aa", "aaa,aaa" and "aaaa", we can see the partern of 4,3,2,1 groups, so in this case there's 15 groups!