Track the Maximum Value
Updated
Problem statement
Build a tracker for the largest value received so far. You are given an integer array values in arrival order.
Start with an empty tracker and process the array from left to right. Insert each value, then query the maximum of all values inserted so far. Return these query results in the same order.
In other words, the result at index i is the maximum of values[0] through values[i], inclusive. Equal values do not change the maximum. Negative values and zero are valid.
If values is empty, return an empty array. No maximum query is made before the first insertion. Values are never removed or expired.
Do not change the input. Every call starts with a fresh tracker and returns a new result array that is independent of the input and results from earlier calls.
Function
trackMaximum(values: int[]) → int[]Examples
Example 1
values = [3,1,5,5,2]return = [3,3,5,5,5]The first value makes the maximum 3. Inserting 1 keeps it at 3. Inserting 5 raises it to 5. The repeated 5 and the final 2 keep it at 5, giving [3,3,5,5,5].
Example 2
values = [-5,-8,-2,-9]return = [-5,-5,-2,-2]The first maximum is -5. Inserting -8 leaves it at -5. Inserting -2 raises it to -2, and inserting -9 leaves it there. The result is [-5,-5,-2,-2]. The initial maximum must come from an inserted value, even when every value is negative.
Example 3
values = []return = []There are no insertions and therefore no queries. Return an empty array.
Constraints
0 <= values.length <= 60.- Each integer in
valuesis between-10^6and10^6, inclusive.
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Best Stock Trade with Buy and Sell DaysGoogle · PHONE SCREENGoogle interview questions
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
- Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
- Find Unique ElementsCisco · PHONE SCREENCisco interview questions
- Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
Interview reports that mention this question
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)