Swap Parity

Problem Overview

  • Rearrange a numeric string by swapping adjacent digits only when both have the same parity (both odd or both even) to form the largest possible number.
  • Input: string num (digits 0–9), length 1–1e5. Output: largest number as a string.
  • Domain: string manipulation and parity-based digit grouping in number formatting.
  • Palantir interview question; a coding interview problem for constraint-heavy reasoning.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: