Meta Interview Question

1)- programmingl find the max no from the given set of elements in an array (without using max function) 2)- Find the minimum absolute difference between the set of elements of an array.

Interview Answers

Anonymous

Oct 28, 2017

For 1 you need not sort it, sorting is O(NlogN), you can just traverse once keeping track of max number and replacing it when u find something larger than that. This would be O(N).

Anonymous

Apr 16, 2018

2nd wont work if there is a negative value. My solution n = input() val = 100**100 arr = map(int, raw_input().split()) arr.sort() for i in range(n - 1): val = min(val, abs(arr[i] - arr[i+1])) print val

Anonymous

Oct 1, 2018

l={1,4,5,7,6,4,3} max=0 for i in l: if i > max: max=i print(max)

Anonymous

Mar 14, 2017

1) sort in descending order and print the first element 2) sort in ascending order and report the difference between the first two