CT044

Array Min Max Efficient

MediumAcceptance: 0.0%

Given an array of numbers, find both the minimum and maximum using fewer than 2*(n-2) comparisons. Use a divide-and-conquer approach. Input: first line n, second line n space-separated integers. Output: minimum and maximum separated by space.

Example 1:

Input: 7 4 2 7 5 -1 3 6
Output: -1 7

Example 2:

Input: 5 3 1 4 1 5
Output: 1 5

Constraints:

1 <= n <= 10^5 -10^9 <= arr[i] <= 10^9

Tags:

divide-and-conquer recursion array
Loading...
Test Cases:No test cases
No test cases available.
Coding Problem Not Found | CodeTikki