counter case for 2nd implementation is: n = 15, x = 12 I would suggest to generate some random input and test your program if you get wrong answer and are unable to figure it out Hope this helps answered 15 Jan '18, 17:42
thanks for the tc @inovation123
(15 Jan '18, 18:12)

The solution for 2nd implementation would work if you would write else if instead of if when you are checking that whether sum is greater than i or not. answered 15 Jan '18, 17:46

Hey @vikaskodag98 :) Well your second implementation is a bit buggy. It will fail at some test cases like: 24,32 ; 12 15 ; 65 90 etc... Suppose the test case is (12,15) then your program will evaluate 'sum' initially as 54. Since you are iterating from last number i.e. 15, a[15]=1 (as sum= 54 is well greater than i=15) and it continues till i=13 where sum remains to be 25. Here your program decrements i as (sumi)==x gets true(since x=12 here). Now you are left with i=12 and sum= 25 and since (sum>i) gets true in your second if block you evaluate a[12]= 1 which is wrong. answered 15 Jan '18, 18:18
thanks for pointing out the mistake @ayush_0101. It was a silly mistake i overlooked.
(15 Jan '18, 18:26)
