817D: Imbalanced Array
Why I didn’t solve it
I got the idea, but I had problem handling the tiebreaker case!!!, i.e., what if within the same segment, there are multiple minival values, which one to pick?
To handle the tie breaker, we just calculate for each value, how many values this value is the LEFTMOST smallest value, i.e., to handle tie breaker, we introduce a secondary condition that helps us identify.
Similarly, for the rightside, we just use a silghtly different procecure to calculate the first number to the right that is greater than the current one