Skip to content

Practice Reformat The String

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

Easy#1417
LeetCode Problem

Reformat The String

Problem Statement

You are given an alphanumeric string s. (Alphanumeric string is a string consisting of lowercase English letters and digits). You have to find a permutation of the string where no letter is followed by another letter and no digit is followed by another digit. That is, no two adjacent characters have the same type. Return the reformatted string or return an empty string if it is impossible to reformat the string.

Source: Reformat The String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "a0b1c2"
Output
"0a1b2c"

# Example 2

Input
s = "leetcode"
Output
""

# Example 3

Input
s = "1229857369"
Output
""

Constraints

1 <= s.length <= 500
s consists of only lowercase English letters and/or digits.

Related LeetCode Problems

Practice more problems similar to Reformat The String.

Review your practice with PhantomCodeAI

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