Maximum Distinct Values After Cross-Array Swaps
Updated
Problem statement
You are given integer arrays a and b and an integer k.
In one operation, choose any index in a and any index in b, then swap those two elements. Return the maximum possible number of distinct values in a after at most k operations.
Function
maximumDistinctAfterSwaps(a: int[], b: int[], k: int) → intExamples
Example 1
a = [2,3,3,2,2]b = [1,3,2,4,1]k = 4return = 4Replace duplicate copies in a with the new values 1 and 4.
Example 2
a = [1,1,2,2]b = [3,4,1,5]k = 2return = 4Swap duplicate copies for 3 and 4.
Example 3
a = [1,2,3]b = [4,5]k = 2return = 3a is already fully distinct; replacing a unique value cannot increase its count.
Constraints
1 <= a.length, b.length <= 200000.0 <= k <= 200000.-1000000000 <= a[i], b[i] <= 1000000000.
More Scale AI Online Assessment questions
- Part 2: Batch Access ReviewOA · Seen Nov 2026
- Part 1: The Narrowest KeyOA · Seen Nov 2026
- Build Sessions from Unordered Events (Part 1)OA · Seen Oct 2026
- Match Billing Charges to User Sessions (Part 2)OA · Seen Oct 2026
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Compare Labeling Worker AnnotationsOA · Seen Mar 2025
- Count Stable Server SubsegmentsOA · Seen Nov 2024
- Distinct OR Values of Increasing SubsequencesOA · Seen Nov 2024
- Running Through Walls with Limited EnergyOA · Seen Sep 2024
Similar questions at other companies
- Maximum Distinct Values After SwapsAkuna Capital · OAAkuna Capital interview questions
- Min OperationAmazon · OA
- Min Cost to Complete All ProjectsSalesforce · OASalesforce interview questions
- Freelancing PlatformJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Operations to Make a SubsequenceGoogle · OAGoogle interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- 🐘 Keep Them Apart 🦙QRT · OA