DEV Community

Hasanul
Hasanul

Posted on

Such a helpful community.

When you start by setting largest and second_largest to the largest element (the first one in this case):

largest = nums[0]
second_largest = nums[0]

then the expressions:

nums[i] > largest
nums[i] > second_largest

will never be true. Hence second_largest will never change from the initial largest value.

If you still…

Top comments (0)