answer re: Not giving the right answer when putting the largest number at first position of the list
1
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)