FastPrepMaximum Distinct Values After Cross-Array Swaps
Problems/Maximum Distinct Values After Cross-Array Swaps

Maximum Distinct Values After Cross-Array Swaps

Scale AI logoScale AI● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Scale AI online assessment. The report gives the goal of at most k swaps between two arrays, and arrays for an example. Its text says three distinct values, but the result shown has four and the stated return is 4. Our version uses the value that is consistent, which is 4. We added the general limits and the function signature. Our version is about 94% the same as the reported question.

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) → int

Examples

Example 1

a = [2,3,3,2,2]b = [1,3,2,4,1]k = 4return = 4

Replace 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 = 4

Swap duplicate copies for 3 and 4.

Example 3

a = [1,2,3]b = [4,5]k = 2return = 3

a 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

Interview reports that mention this question

  • Scale AI OA: What It Tests (2026)
  • Scale AI New Grad SWE and MLE Question Bank
  • Scale AI New Grad OA: Three Coding Problems

Scale AI interview experiences

  • Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
  • Scale AI ML Research Engineering Intern Interviews: 1 Experience
  • Scale AI SWE Intern Debugging Interview: 9 Experiences
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public int maximumDistinctAfterSwaps(int[] a, int[] b, int k) {
        // write your code here
    }
}
Checking account…