Maximum and Minimum - II

You are given an integer array nums of size N. Using recursion, find and return the maximum and minimum elements of the array.

The maximum element is the largest value in the array, while the minimum element is the smallest value. The maximum and minimum are printed in that order, separated by a single space.

Note:

A normal iterative solution will pass the test cases, but the goal of this problem is to solve it using recursion and strengthen your understanding of recursive calls and base cases.

Example 1:

Input: nums = [1, 2, 3, 4, 5]

Output: 5 1

Explanation: The maximum element is 5 and the minimum element is 1.

Example 2:

Input: nums = [1, 0, 2, -10]

Output: 2 -10

Explanation: The maximum element is 2 and the minimum element is -10.

Now Your Turn!

Pick the correct output for the given input

Input: nums = [4, 1, 0, 6, -12]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= N <= 100
  • -105 <= nums[i] <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int findMaximum(int nums[], int N) {
// Your code goes here
}
 
int findMinimum(int nums[], int N) {
// Your code goes here
}
};
Test Case

Input:

Nums