DEV Community

DAVID ARAVINDHRAJ
DAVID ARAVINDHRAJ

Posted on

Pk finds it difficult to judge the minimum element in the list of elements given to him.

Pk finds it difficult to judge the minimum element in the list of elements given to him. Your task is to develop the algorithm in order to find the minimum element.

Sample Input :
5
3 4 9 1 6

Sample Output :
1

#method to find minimum element from a list
def pk_find_min(arr):
    n = len(arr)
    #initialize first list element to 'min'
    min = arr[0]
    for i in range(n-1,0,-1):
        #compare list element with 'min' and overwrite 'min' with minimum element
        if min > arr[i]:
            min = arr[i]
    return(min)


if __name__ == "__main__":
    n = int(input())
    ip_list = list(input().split())
    print(pk_find_min(ip_list))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)