![]() |
VOOZH | about |
Given an arr[] of elements of size n, return the largest element given in the array.
Examples:
Input: arr[] = [10, 20, 4]
Output: 20
Explanation: Among 10, 20 and 4, 20 is the largest.Input: arr[] = [20, 10, 20, 4, 100]
Output: 100
Table of Content
Traverse the entire array and keep track of the largest element encountered. Update the maximum value whenever a larger element is found, and after scanning all elements, the stored value represents the largest element in the array.
100
The idea is similar to the iterative approach. Here the traversal of the array is done recursively instead of an iterative loop.
100
Most of the languages have a relevant max() type in-built function to find the maximum element, such as std::max_element in C++. We can use this function to directly find the maximum element.
100