Skip to content

Commit 18c0c93

Browse files
author
shiv
committed
added maximum index for given condition code. Good question
1 parent 4819d7b commit 18c0c93

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

1

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
9
3+
34 8 10 3 2 80 30 33 1

ip.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
1
2-
7
3-
6 2 5 4 5 1 6
2+
9
3+
34 8 10 3 2 80 30 33 1

max_index.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#SHIV's code for maximum index
2+
3+
'''
4+
1
5+
9
6+
34 8 10 3 2 80 30 33 1
7+
'''
8+
9+
tn = int(input())
10+
11+
def process(arr):
12+
max_arr = []
13+
for ind, i in enumerate(arr):
14+
interm = []
15+
for ind2, j in enumerate(arr):
16+
if ind2 < ind: continue
17+
if i<=j:
18+
interm.append(((ind, ind2),ind2-ind))
19+
if interm:
20+
max_dist = max(interm, key=lambda x: x[1])
21+
max_arr.append(max_dist)
22+
else: max_arr.append(((i, i), 0))
23+
print(max(max_arr, key=lambda x:x[1]))
24+
25+
for i in range(tn):
26+
ns = int(input())
27+
arr = list(map(int, input().split()))
28+
process(arr)

0 commit comments

Comments
 (0)