227. Reorganize String (Feasibility)

MediumStringString

Given a string s, determine whether its characters can be rearranged so that no two adjacent characters are the same. Return true if possible, otherwise false.

Input: A quoted string s.

Output: Boolean — true or false.

Examples

Example 1
Input: "aab"
Output: true
Explanation: 'aba' works.
Example 2
Input: "aaab"
Output: false
Explanation: Too many a's.
Example 3
Input: "a"
Output: true
Explanation: Single char.

Constraints

Asked by

AmazonOracleGoogleMicrosoftIBMBloomberg
Solve this problem in the editor →