Given an array a of length n of $-1$s and $1$s, and another input $m$, I was supposed to minimize the longest continuous streak of $1$s or $-1$s after flipping $m$ $-1$s to $1$s or vice versa.I know how to maximize it but can't figure out how to minimize it. I maximize the number of $1's$ by sliding window method. Take a window ($wleft$ , $wright$).It covers given array from index $wleft$ to $wright$.I represent $-1$ with $0$ for ease.Suppose number of zeros in window in $wzeros$.Algorithm :while wright < length of array {     wzeros <= m: increment wright     wzeros>m: increment wleft   // Update the max window size during this whole process.         int temp = wright-wleft;        if(temp > mx_length){          mx_length = temp;          solution_window = wleft;              }           }This code maximizes the number of consecutive $1$s whereas I want to minimize the number of consecutive $1$s and $-1($or $0)$s. How do I modify the algorithm/code to achieve so ?
Minimize longest continuous streak of $1$s after flipping $m$ $-1$s to $1$s
number theory;searching