Practice Lexicographically Smallest String After a Swap
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given a string s containing only digits, return the lexicographically smallest string that can be obtained after swapping adjacent digits in s with the same parity at most once. Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 do not.
Source: Lexicographically Smallest String After a Swap on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "45320"
"43520"
# Example 2
s = "001"
"001"
Constraints
Related LeetCode Problems
Practice more problems similar to Lexicographically Smallest String After a Swap.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.