FastPrepMaximum Number after K Swaps
Problems/Maximum Number after K Swaps

Maximum Number after K Swaps

Intuit logoIntuit● MediumINTERNOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source names maximum number after K swaps. This version uses at most K arbitrary swaps, keeps digits as strings, and declares finite search bounds; about 95% match.

Given a decimal digit string, swap any two positions at most k times. Return the greatest resulting fixed-length digit string. Leading zeros created by a swap are allowed as intermediate strings, but comparisons use the whole equal-length string. You may use fewer than k swaps, including zero.

Function

maximumNumber(number: String, k: int) → String

Examples

Example 1

number = "123"k = 1return = "321"

Swap the first and last digits.

Example 2

number = "987"k = 2return = "987"

Using fewer than k swaps is allowed.

Constraints

  • For this exercise, assume 1 <= number.length <= 9 and 0 <= k <= 4. The input has no leading zero unless it is "0".

More Intuit Online Assessment questions

  • Employee Promotion OpportunitiesOA · Seen Oct 2026
  • Next Pascal Row CoefficientOA · Seen Oct 2026
  • Parse Router LogsOA · Seen Oct 2026
  • Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
  • Maximum Square-Free DivisorOA · Seen Oct 2026
  • Two Tribes from Taller-Person CountsOA · Seen Oct 2026
  • Shortest Path from an Encoded GraphOA · Seen Sep 2026
  • Oldest and Youngest EmployeesOA · Seen Sep 2026
  • Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
  • Submask Sum QueriesOA · Seen Sep 2026

Similar questions at other companies

  • Next Number with Disjoint DigitsElevenLabs · OAElevenLabs interview questions
  • String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
  • Generate ParenthesesThe Walt Disney Company · OAThe Walt Disney Company interview questions
  • Reverse and AppendUber · OAUber interview questions
  • All Palindrome PartitionsExpedia · OAExpedia interview questions
  • Generate ParenthesesAtlassian · OAAtlassian interview questions
  • Equal-Sum Digit PartitionsAlchemy · OA
  • Generate Balanced ParenthesesInMobi · OAInMobi interview questions
  • Work ScheduleSnowflake · OASnowflake interview questions
  • Work Schedules (for MTS2)Nutanix · OANutanix interview questions

Intuit interview experiences

  • Intuit Software Engineering Intern - Full Stack OA Format
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public String maximumNumber(String number, int k) {
        // Write your code here
    }
}
Checking account…