Interview Question

Anonymous Interview

how to find the min and max in an array

Answer

Interview Answer

1 Answer

0

Find max: O(n)
max = arr[0];
i: 1->n-1
   if(max < arr[i])
      max = arr[i];

Find min: O(n)
min = arr[0];
i: 1->n-1
   if(min > arr[i])
      min = arr[i];

Rohan on Mar 11, 2012

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up