You are given 4 parameters
- a string that is only 0 and 1’s
- n which is the length of the string
- k which is the number of items you can insert and
- m which is the position that is taken at the end
The problem is that you have to insert 1’s into the string (from 0 to k) and in the end you take the m-th positions. The algorithm has to find the best places to insert in order to get the lowest sum on the m-th positions.
Example:
n = 35 k = 6 m = 8 string = 11011001000011010101010101110010111
You can insert 6 ones into the string and after you insert each 8-th number will be taken and summed.
Solution:
sum = 0 index of insertion = 7 31
I tried a recursive solution which would try each possible combination of insertions, but the problem is that with larger examples it takes too long.
Domen Hribernik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.