Grokking Meta Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Maximum Swap (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given a non-negative integer num, return the maximum number, which you can create by swapping any two digits of the number only once. If no swaps can improve the number, return the original number.

Examples

  1. Example 1:

    • Input: 2736
    • Expected Output: 7236
    • Justification: Swapping the first and second digits (2 and 7) results in the largest possible number.
  2. Example 2:

    • Input: 9965
    • Expected Output: 9965
    • Justification: The number is already in its maximum form, so no swap is needed.
  3. Example 3:

    • Input: 7281912
    • Expected Output: 9281712
    • Justification: Swapping the first digit (7) with the first 9 found from the left results in the maximum number.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible