- Set largest = arr[0]
- Loop through the array
- If arr[i] > largest, update largest
- Print largest.
The above optimal solution's time complexity reduces to o(n) and space complexity to o(1). However,it can also be solved by Brute force technique, which sorts the array in ascending order. The element at the last index position is the largest number. But its time complexity is o(nlog(n)) and space complexity is o(1), which is inefficient.