You are viewing a single comment's thread. Return to all comments →
what [-2] does please explain.
Refers to the second to last element.
what if there is a repetition of the max number -2 wont work there
code uses a set(only distinct numbers)
Set can have only non-repeating values
The list can be accessed from last, considering last element of index -1 and second last element of index -2 and so on...
like we have list=['1','4','6','7'] then [-1]=7 and similarly [-2]=6 that all.
[-2] this is indexing in this case it is used to find number which is second largest number after sorting the list
that's the second item of the list from the right. for example: if you have a list=[1,4,6,9,11] list[-1] returns 11 list[-2] returns 9
-ve index signifies starting from last index
Find the Runner-Up Score!
You are viewing a single comment's thread. Return to all comments →
what [-2] does please explain.
Refers to the second to last element.
what if there is a repetition of the max number -2 wont work there
code uses a set(only distinct numbers)
Set can have only non-repeating values
Set can have only non-repeating values
The list can be accessed from last, considering last element of index -1 and second last element of index -2 and so on...
like we have list=['1','4','6','7'] then [-1]=7 and similarly [-2]=6 that all.
[-2] this is indexing in this case it is used to find number which is second largest number after sorting the list
that's the second item of the list from the right. for example: if you have a list=[1,4,6,9,11] list[-1] returns 11 list[-2] returns 9
-ve index signifies starting from last index