-
I'm very curious on this and I would appreciate it if someone could answer my question on this subject, as I don't have the most experience, and I know there's programmers out there who could assist me on my question. thank you if you do decide to help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Iterative Approach – O(n) Time and O(1) Space Recursive Approach – O(n) Time and O(n) Space Using Library Methods – O(n) Time and O(1) Space |
Beta Was this translation helpful? Give feedback.
Iterative Approach – O(n) Time and O(1) Space
The approach to solve this problem is to traverse the whole array and find the maximum among them.
Recursive Approach – O(n) Time and O(n) Space
The idea is similar to the iterative approach. Here the traversal of the array is done recursively instead of an iterative loop.
Using Library Methods – O(n) Time and O(1) Space
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.