Maximum Number after K Swaps
Updated
Problem statement
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) → StringExamples
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