Skip to content

Commit

Permalink
Added max_value_arr file
Browse files Browse the repository at this point in the history
Added a python file with three various approaches
  • Loading branch information
meghamsh253 authored Oct 17, 2023
1 parent 1867788 commit 96606fb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions max_value_arr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#APPROACH -1
#SORTING THE INITIAL LIST AND RETURNING THE LAST ELEMENT OF LIST
def max(arr):

arr.sort()
return arr[-1]
#APPROACH -2
#ITERATING THROUGH ALL THE ELEMENTS IN LIST AND COMPARING EACH ELEMENT

def max(arr):

max_element = arr[0]

for i in range(len(arr)):
if arr[i] > max_element:
max_element = arr[i]

return (max_element)

#APPROACH-3
#USING INBUILT FUNCTION
def max(arr):
return (max(arr))

0 comments on commit 96606fb

Please sign in to comment.