Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8afa77f

Browse files
author
Amogh Singhal
authored
Create min_max_array_oneLoop.py
1 parent af3c6b9 commit 8afa77f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎min_max_array_oneLoop.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def maxMinIndex(arr):
2+
3+
max_index = 0
4+
min_index = 0
5+
6+
# using two counters in single for loop
7+
for i, j in zip(range(1, len(arr)), range(1, len(arr))):
8+
if arr[max_index] < arr[i]:
9+
max_index = i
10+
if arr[min_index] > arr[i]:
11+
min_index = i
12+
13+
return max_index, min_index
14+
15+
arr = [4,5,6,7,8,1,2,11,12,13,3,9,10]
16+
res = maxMinIndex(arr)
17+
print("maximum element is", arr[res[0]],"at index:", res[0])
18+
print("minimum element is", arr[res[1]],"at index:", res[1])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /