Skip to content

Practice Largest Number After Digit Swaps by Parity

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2231
LeetCode Problem

Largest Number After Digit Swaps by Parity

Problem Statement

You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits). Return the largest possible value of num after any number of swaps.

Source: Largest Number After Digit Swaps by Parity on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
num = 1234
Output
3412

# Example 2

Input
num = 65875
Output
87655

Constraints

1 <= num <= 10^9

Related LeetCode Problems

Practice more problems similar to Largest Number After Digit Swaps by Parity.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.