-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q9.py
42 lines (28 loc) · 788 Bytes
/
Q9.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# https://practice.geeksforgeeks.org/problems/leaders-in-an-array-1587115620/1
class Solution:
def leaders(self, A, N):
flag = 0
li = []
for i in range(len(A) - 1):
for j in range(i + 1, len(A)):
if A[i] < A[j]:
flag = 1
if flag == 0:
li.append(A[i])
flag = 0
li.append(A[-1])
return li
import math
def main():
T=int(input())
while(T>0):
N=int(input())
A=[int(x) for x in input().strip().split()]
obj = Solution()
A=obj.leaders(A,N)
for i in A:
print(i,end=" ")
print()
T-=1
if __name__=="__main__":
main()