Python leetcode solution 3
Python leetcode solution 3
Arth Agrawal
(22BCE3196)
Problem Statement
Test Cases and Constraints
Example 1:
Output: 5
1 | [2,1,3,5,4,6,7] | 2 | 1
2 | [2,3,5,4,6,7,1] | 3 | 1
3 | [3,5,4,6,7,1,2] | 5 | 1
4 | [5,4,6,7,1,2,3] | 5 | 2
So we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games.
Example 2:
k = 10
Output: 3
Output = 8
1 | [6,1,3,7,4,8] | 6 | 1
2 | [6,3,7,4,8,1] | 6 | 2
3 | [6,7,4,8,1,3] | 7 | 1
4 | [7,4,8,1,3,6] | 7 | 2
5 | [7,8,1,3,6,4] | 8 | 1
6 | [8,1,3,6,4,7] | 8 | 2
7 | [8,3,6,4,7,1] | 8 | 3
Since, 8 has won three consecutive times, the no. 8 is the winner and it is printed.
Question Interpretation
Firstly we compare the first two elements of the given
aray.