• + 0 comments

    d[i] is value not key. The logic is brilliant. a is taking the sum of the consequitive steps of the path.So, after decending a valley if someone ascending to sea level then a=0 and if again it is negative that means new valley is explored so b will be increased 1 otherwise no change.