Maximize Array Beauty After Deletions
Updated
Problem statement
You are given an integer array values. Delete any number of elements while preserving the relative order of the elements that remain. At least one element must remain.
The beauty of the final array is the number of its 1-indexed positions i for which the value at that position equals i.
Return the maximum beauty obtainable after deletions.
Function
maximizeArrayBeauty(values: int[]) → intExamples
Example 1
values = [2,2,1,3,4]return = 3Delete the third element to obtain [2,2,3,4]. Its values match positions 2, 3, and 4.
Example 2
values = [4,1,2,3,4]return = 4Delete the first element. The remaining array is [1,2,3,4], so every position contributes to the beauty.
Example 3
values = [2,3,4,5]return = 0No non-empty subsequence can place any of these values at an equal 1-indexed position.
Constraints
1 <= values.length <= 200000-10^9 <= values[i] <= 10^9
More Point72 interview questions
- Simulate a Deterministic Finite AutomatonOA · Seen Aug 2026
- Initial Public OfferingOA · Seen Jul 2026
- Test the HypothesisOA · Seen Jul 2026
- Get Triplet CountOA · Seen Jul 2026
- Internet Service Provider Monthly ReportOA · Seen Jul 2026
- Server SelectionOA · Seen Jul 2026
- Lexicographically Smallest String After Substring OperationOA · Seen May 2026
- Best Time to Buy and Sell Stock IIPHONE SCREEN · Seen Aug 2026
- Find Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Aug 2026
- Generate an Optimal Portfolio Trading ReportPHONE SCREEN · Seen Apr 2026
Similar questions at other companies
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Split Array Largest SumAuxoAI · OA
- Maximum Non-Decreasing Array LengthVisa · OAVisa interview questions
- Min Elements to Remove to Make Almost Sorted ArraySalesforce · OASalesforce interview questions
- Allocate Wells for Fair DistributionWells Fargo · OAWells Fargo interview questions
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Fill a Time Window with SongsMicrosoft · OAMicrosoft interview questions
- Longest Increasing Subsequence from Two ArraysSquarepoint Capital · OASquarepoint Capital interview questions
- Split Array Largest SumLinkedIn · OALinkedIn interview questions
- Longest Increasing SubsequenceAtlassian · OAAtlassian interview questions