Created
October 11, 2016 23:26
-
-
Save itsmuriuki/ff35372e081ba2e35cf94c0e5ca8cfec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_min(arr): | |
mini=arr[0] | |
maxi=arr[0] | |
for x in arr: | |
if maxi<x: | |
maxi=x | |
if mini>x: | |
mini=x | |
max_and_min=[maxi,mini] | |
return max_and_min | |
arr=[3,4,5,1,7,9,6] | |
print(max_min(arr)) | |
def max_min2(arr): | |
mini=arr[0] | |
maxi=arr[0] | |
maxi2=arr[0] | |
mini2=arr[0] | |
for x in arr: | |
if maxi<x: | |
maxi2=maxi | |
maxi=x | |
elif maxi2<x and x!=maxi: | |
maxi2=x | |
for m in arr: | |
if mini>m: | |
mini2=mini | |
mini=m | |
elif mini2==mini: | |
mini2=m | |
elif mini2>m: | |
mini2=m | |
arr1=[mini2, maxi2] | |
return arr1 | |
arr2=[4,7,5,10,12,3,2,16, 14] | |
print(max_min2(arr2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment