A market analyst recorded the net price change of a stock at the close of every trading session over a period, and sorted the list of changes from most negative to most positive.
A session is a gain session if its net change is strictly positive, and a loss session if its net change is strictly negative. A session with a net change of exactly zero counts as neither.
Given the sorted list, report whichever of the two counts -- gain sessions or loss sessions -- is larger (if they are equal, report that common count).
Line 1: an integer n, the number of sessions.
Line 2: n integers, the net changes, separated by single spaces, given in non-decreasing sorted order.
A single integer: the larger of the gain-session count and the loss-session count.
Example 1
Input
7 -3 -2 -1 0 0 1 2
Expected
3
Explanation
Loss sessions are -3, -2, -1 (count 3). Gain sessions are 1, 2 (count 2). The two zero-change sessions count as neither. The larger count is 3.
Example 2
Input
4 5 20 66 1314
Expected
4
Explanation
All four sessions have strictly positive net change, so gain sessions = 4 and loss sessions = 0. The larger count is 4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →