Problem
Ask
Submissions

Problem: Largest Number After Digit Swaps by Parity

Medium
30 min
Explore how to rearrange digits within a number to form the largest value by swapping digits sharing the same parity. Learn to apply heaps to efficiently manage these swaps and implement a solution that respects parity constraints and optimization principles.

Statement

You are given a positive integer num. You can swap any two digits of num as long as they share the same parity (both are odd or both are even).

Your task is to return the largest possible value of num after performing any number of such swaps.

Constraints:

  • 11 \leq num 109\leq 10^9

Problem
Ask
Submissions

Problem: Largest Number After Digit Swaps by Parity

Medium
30 min
Explore how to rearrange digits within a number to form the largest value by swapping digits sharing the same parity. Learn to apply heaps to efficiently manage these swaps and implement a solution that respects parity constraints and optimization principles.

Statement

You are given a positive integer num. You can swap any two digits of num as long as they share the same parity (both are odd or both are even).

Your task is to return the largest possible value of num after performing any number of such swaps.

Constraints:

  • 11 \leq num 109\leq 10^9