555.Count How Often the Maximum Appears
Easy
Given an array
nums, return how many times its largest value appears.
Both solutions are O(n)Linear Time O(n)Work that grows in direct proportion to the input size: twice the data, about twice the time.: every element is looked at a fixed number of times, so doubling the array roughly doubles the work. Two passes cost 2n and one pass costs n, but Big-O ignores constant factors — both are linear. Linear time is usually the best possible when every element has to be inspected.
Example 1:
Input: nums = [3,9,2,9,9]
Output: 3
Example 2:
Input: nums = [-4,-7]
Output: 1
+ 5 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ nums.length ≤ 1000 - ●
-1000000 ≤ nums[i] ≤ 1000000
nums =
[3, 9, 2, 9, 9]