Suffix Maximum Frequency Queries
Updated
Problem statement
You are given a nonempty integer array nums and an array of zero-based query indices queries.
For each query index i, consider the suffix nums[i..nums.length - 1]. Find the maximum value in that suffix and count how many times that maximum occurs within the same suffix.
Return the counts in the original order of queries. Repeated query indices are answered independently.
Function
suffixMaximumFrequencies(nums: int[], queries: int[]) → int[]Examples
Example 1
nums = [7,5,7,2,7]queries = [0,1,2,3,4]return = [3,2,2,1,1]At index 0, the suffix maximum 7 appears three times. At indices 1 and 2, it appears twice. The final two suffixes each contain their maximum once.
Example 2
nums = [4,4,1,4]queries = [1,2,3]return = [2,1,1]The suffix beginning at 1 contains two copies of its maximum 4. The suffixes beginning at 2 and 3 contain only one copy of their respective maxima.
Example 3
nums = [-3,-1,-1,-2]queries = [0,1,3]return = [2,2,1]Negative values follow the same rule. The maximum of the first two queried suffixes is -1, which occurs twice; the last suffix contains only -2.
Constraints
1 ≤ nums.length ≤ 200000.1 ≤ queries.length ≤ 200000.-10^9 ≤ nums[i] ≤ 10^9.0 ≤ queries[i] < nums.length.
More Microsoft Phone Screen questions
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
- Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
- Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
- 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
- Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
- Most Visited String SectorsPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Pascal's TriangleBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Best Time to Buy and Sell StockMeta · PHONE SCREENMeta interview questions
- Speed Up a Slow FunctionCitadel · OA · PHONE SCREENCitadel interview questions
- Best Time to Buy and Sell StockSwiggy · PHONE SCREEN
- Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Best Time to Buy and Sell StockJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Find Max Length of SubsequenceGoogle · PHONE SCREENGoogle interview questions
- Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
- Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)