Maximum Distinct Items Within a Budget
Updated
Problem statement
There are n items, numbered 1 through n. Item i costs i dollars. You already own the item IDs in arr and have k dollars to spend.
Return the largest total number of distinct items you can own after buying any additional items. An item already owned needs no further purchase, and buying another copy does not increase the distinct count.
Function
findMaxDistinctItems(n: int, arr: int[], k: long) → intExamples
Example 1
n = 10arr = [1,3,8]k = 10return = 5You already own three distinct items. Buy items 2 and 4 for 6 dollars. A third new item costs at least 5, which would make the total 11. The best total distinct count is 5.
Example 2
n = 4arr = [4]k = 6return = 4You already own item 4. Buy items 1,2,3 for 6 dollars, so you own all four distinct items.
Constraints
- 1 <= n <= 1000000.
- 1 <= arr.length <= 100000.
- Every arr[i] is an item ID from 1 through n. Repeated IDs represent the same owned item.
- For this exercise, assume 0 <= k <= 10^12.
Source note: Original OA task images and any included source example. The practice contract follows the rules stated in the problem and source note.
More Adobe Online Assessment questions
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Top-Funded Villages and ProjectsOA · Seen Aug 2026
- Count Parent Nodes With a Target SumOA · Seen Aug 2026
- Largest Binary Number by ConcatenationOA · Seen Aug 2026
- Count Events by CategoryOA · Seen Aug 2026
- Graph M-ColoringOA · Seen Aug 2026
- Hall of Shifting TilesOA · Seen Aug 2026
- K-th Ancestor Subtree Preorder QueryOA · Seen Aug 2026
- Maze ReachabilityOA · Seen Aug 2026
- Minimum Numeric Code TransformationOA · Seen Aug 2026
Similar questions at other companies
- Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
- Optimal TransferSnowflake · OASnowflake interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Robot and Human Fulfillment TimeAmazon · OA
- Minimize Maximum Group DifferenceDRW · OADRW interview questions
- Array NullificationQRT · OA
- Gas Station Loop StartNutanix · OANutanix interview questions
- Minimum-Cost Solar Rooftop AllocationDeloitte · OADeloitte interview questions
- Three-Part Partition with Minimum Largest RangeLSEG · OALSEG interview questions
- K-Means ClusteringAtlassian · OAAtlassian interview questions
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
- Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)