I recently came across a coding question in a contest and I'm unable to figure out a way to solve this. (I'm out of the contest :) )
So here is the question: Consider an array of integers where each element can be modified by two operations. Either divide the element by 2 or multiply the element by 2.
Given k chances to modify the elements of the array by above mentioned operations (each time an element is modified is considered as one operation) ,find out the maximum length contiguous sub array such that all the elements in the sub array have the same parity.
Parity - Remainder when a number is divided by 2
eg :- consider an array 12,11,10,4 and k = 1 Here the parity of the elements is 0,1,0,0. On multiplying 2nd element 11 with 2(and hence completing one operation) we can obtain a parity of 0 (As 22 leaves a remainder 0) and hence given k=1 operations, max length of a contiguous sub array with elements having same parity is 4