Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Continuous subarray sum and Cutting ribbons



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Maximum Digit Swap

Maximum Digit Swap

Problem Statement

Given a non-negative integer, you can switch the position of two digits at most once to create the largest possible number. Return the highest number you can form after performing this single swap.

If no swap can increase the number, return the original number.

Examples

Example 1:
Input:  3821
Output: 8321
Explanation: Swap the digit 3 with 8 to get the maximum number.

Example 2:
Input:  7645
Output: 7645
Explanation: No swap can improve the number, so it remains the same.

Example 3:
Input:  1993
Output: 9913
Explanation: Swap the first 1 with 9 to get the maximum number.
  

Constraints

  • The input integer is in the range [0, 107].