KRISH_FOUSC's blog

By KRISH_FOUSC, history, 5 months ago, In English
  • Vote: I like it
  • -8
  • Vote: I do not like it

»
5 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Instead of calculating min 1’s and min 2’s required for each subarray . Calculate min 1’s and 2’s required for whole array then compare the subarray sum with min sum

My submission : 248010905

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

There is a flaw in your logic. Consider 8 1 1 1 1 1 1 1 1, according to your logic, the corresponding array should have atleast a sum of 14 to make this one good. The correct answer is however 17.

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The condition sum>=req in code is a necessary condition but not sufficient. The distribution of this sum matters consider the example 1,1,2,2 works fine with the logic but if we have 1,1,1,3 here though it has the same sum as before but the distribution of this sum is different, each of the ones must be incremented by atleast 1 so we need -3 from some element to maintain constant sum as per question but last element can't give 3 as it will become 0 after that.