Search code examples
arraysalgorithmlanguage-agnostic

Find Maximum Integer in Array?


I have two arrays, one is very large (more than million entries) and other array is small (less than 1000 entries), what would be the best approach to find maximum number out of all entries in arrays ?

Thanks.


Solution

  • If the arrays are unsorted then you must do a linear search to find the largest value in each. If the arrays are sorted then simply take the first or last element from each array (depending on the sort order).