arr
and store it in maxElement
.queue
with all elements of arr
except the first one.curr
to the first element of arr
and winstreak
to 0.queue
is not empty:
a. Dequeue an element from queue
and store it in opponent
.
b. If curr
is greater than opponent
:
i. Increment winstreak
.
ii. Enqueue opponent
to the back of queue
.
c. Else:
i. Set curr
to opponent
.
ii. Reset winstreak
to 1.
iii. Enqueue the previous curr
to the back of queue
.
d. If winstreak
equals k
or curr
equals maxElement
, return curr
.