length `length` and 'K factor' = `k_factor` which belong to the criteria represented by that index: - dp[length][k_factor][0] can be the number of strings of length `length` and K-factor = `k_factor` which end with substring 'a' - dp[length][k_factor][1] can be the number of strings of length `length` and K-factor = `k_factor` which end with substring 'ab' - dp[length][k_factor][2] can be the number of strings of length `length` and K-factor = `k_factor` which end with subs
Code!!!!!!'
The K factor of a string is defined as the number of times 'abba' appears as a
substring. Given two numbers `length` and `k_factor`, find the number of
strings of length `length` with 'K factor' = `k_factor`.
The
dp[length][k_factor] will be a 4 element array, wherein each element can be the
number of strings of length `length` and 'K factor' = `k_factor` which belong
to the criteria represented by that index:
- dp[length][k_factor][0] can be the number of strings of length `length`
and K-factor = `k_factor` which end with substring 'a'
- dp[length][k_factor][1] can be the number of strings of length `length`
and K-factor = `k_factor` which end with substring 'ab'
- dp[length][k_factor][2] can be the number of strings of length `length`
and K-factor = `k_factor` which end with substring 'abb'
- dp[length][k_factor][3] can be the number of strings of `length` and
K-factor = `k_factor` which end with anything other than the above
substrings (anything other than 'a' 'ab' 'abb')
Example inputs
length=4 k_factor=1 no of strings = 1
length=7 k_factor=1 no of strings = 70302
length=10 k_factor=2 no of strings = 74357.
No chatgp.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)