I calculated all the continuous lengths(1,2,6,7....) , then I went on reducing k(k--) to convert all segments(l_seg) of a particular length (z) into three segments of lengths 1,(2 of l_seg/2)(odd), (l_seg/2,l_seg/2 -1)(even) and removed the original length and it's count by these three lengths of samecount . When the highest length reached 2 I calculated the minimum no of flips required to make it 1 by adding the alternate distances between segments of length 2 and then taking the minimum of two len, if it was less than k , ans is 1 or its two . at any point if k becomes 0 ans is the length of next big segment , if k becomes less than 0 than ans is that particular segment.
Please tell me where is it wrong , I was getting 5 of 9 cases correct.