CF Blogs | Permutations on String | Number of Strings with no K consequetive equal letters

Revision en1, by samadeep, 2023-11-06 13:34:50

Permuation Question : Number of Strings with no K consequetive equal letters given the string is made of lower case alphabets

Read here : Explanation It has beautiful solution using recurrence formulaes.

Basically the Recurrence is :
if k == n:    ways[n] = (power(26,k) - 26)
if n <= k - 1:   ways[n] = power(26,n)
else ways[n] = (countValid(n-1,k) + countValid(n-k,k))

You need to take care of modular arithmetic of course as the numbers get really large BTW it was there in Atlassain OA — best OA ever

C++
python
Tags permutations, strings, combinations

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English samadeep 2023-11-06 13:34:50 3280 Initial revision (published)