Picking Tickets
Updated
Problem statement
Given an array of ticket values tickets, choose as many tickets as possible. You may reorder the chosen tickets.
After ordering them from smallest to largest, the difference between every pair of neighboring values must be at most 1. Equal values are allowed, and each duplicate is a separate ticket.
Return the maximum number of tickets you can choose. A chain may span more than two distinct values; the rule applies to neighboring values in the sorted selection.
Function
maxTickets(tickets: int[]) → intExamples
Example 1
tickets = [8,5,4,8,4]return = 3Choose [4,4,5]. The two 8 tickets form a smaller valid group.
Example 2
tickets = [3,1,2]return = 3Reorder to [1,2,3]. Both neighboring differences equal 1, so the whole chain qualifies.
Constraints
1 <= tickets.length <= 10^5.1 <= tickets[i] <= 10^9.
More Vanguard Online Assessment questions
- Two SumOA · Seen Sep 2026
- Valid ParenthesesOA · Seen Sep 2026
- Are They PangramsOA · Seen Nov 2025
- Missing WordsOA · Seen Nov 2025
- Spam DetectionOA · Seen Nov 2025
- Binge WatchingOA · Seen Jan 2023
- Minimum Moves Around a Circular ArrayOA · Seen Aug 2022
- Maximum Occurring CharacterOA · Seen Mar 2022
- Tool List: Two Smallest ValuesOA · Seen Nov 2021
- Group AnagramsOA · Seen Nov 2019
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Rank Football TeamsCapital One · OACapital One interview questions
- Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
- Rank Football TeamsPersona · OAPersona interview questions
- Meandering ArrayVerisk · OA
- Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
- Find Top Two TeamsAutodesk · OAAutodesk interview questions
- Total Server DowntimeVisa · OAVisa interview questions