Flip

Given an array of n 1s, and an integer k, how do I find the minimum number of turns it takes for me to turn the 1s to 0s, if at each turn I can select the ith integer in the array and conver all k elements to the left and right of it to 0, while also making it a 0.
Can you show an example? Your title says "flip" but your description doesn't talk about flipping at all. I assume by "conver[t] all k elements to the left and right of it to 0", you mean flip them either from 0 to 1 or 1 to 0?

n = 5
k = 2
[ 1 1 1 1 1 ]
choose i = 2
[ 0 0 0 0 0 ]


n = 6
k = 2
[ 1 1 1 1 1 1]

choose i = 2
[ 0 0 0 0 0 1 ]

choose i = 3
[ 0 1 1 1 1 0 ]

choose i = 2
[ 1 0 0 0 0 0 ]

choose i = 3
[ 1 1 1 1 1 1 ]

(I'm not sure if this is even possible in general, I'm not sure what restrictions you have.
Can the k elements left or right go out of bounds?)

Last edited on
stop borrowing trouble Ganado! The answer is clearly 1 turn, I like easy problems :) Choose any location set it to zero, set left to zero, set right to zero, look, all zeros!



Topic archived. No new replies allowed.