educative.io

Educative

Example 1 doubt

hi, for Example 1, the sum is 31 but the program output is 32. How is the output 32?


Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5633779737559040
Lesson: https://www.educative.io/collection/page/5668639101419520/5633779737559040/5634208160546816

Hello @Ashish_D,

In example 1, there are two increasing sequences. First one is {1,2,6,10,12} whose sum is 31 and the second is {4,6,10,12} whose sum is 32. This makes {4,6,10,12} the increasing sequence with the highest sum and hence, the output will be 32 and not 31.

Hope this helps!