Last Updated: 29 Aug, 2025

Optimal Interval Excitement

Easy

Problem statement

You are given an array of integers B of size N. Your task is to find an optimal numeric interval [X, Y] that results in the maximum and minimum possible final "excitement levels".

The excitement level starts at 0 and is calculated by iterating through each number in the array B:

1) If a number is within the interval X, Y, the excitement level increases by 1.
2) If a number is outside the interval [X, Y], the excitement level decreases by 1.

You have complete freedom to choose the integers X and Y to define the interval. You need to return the maximum and minimum possible final excitement levels.


Input Format:
The first line of input contains an integer 'N', the size of the array.

The second line contains 'N' space-separated integers, representing the elements of the array B.


Output Format:
Print a single line containing two space-separated integers: the maximum possible excitement level followed by the minimum possible excitement level.


Note:
The final excitement level only depends on c, the count of numbers from the array that fall within the chosen interval [X, Y].

The formula for the final excitement level is c - (N - c), which simplifies to 2*c - N.

To maximize excitement, you must choose an interval that maximizes c.

To minimize excitement, you must choose an interval that minimizes c.