NutanixOA #5
No Adjacent Characters
估计简单评测数据准备中,可先阅读题面
You are given a string with only one repetitive alphabet. Determine if it is possible to create a string with no adjacent alphabets being the same. Return "NOT POSSIBLE" if:
- Re-arrangement is required but is not possible. Return "POSSIBLE" if:
- There is no rearrangement required as the string is already in the right format.
- Re-arrangement is required and a new string has no adjacent alphabets which are the same.
Function Description
Complete the function
canRearrangeStringin the editor.canRearrangeStringhas the following parameter: String s: the string to check ReturnsString: either "POSSIBLE" or "NOT POSSIBLE"
Constraints
N/A
Example 1
Input:
s = "ab"
Output:
"POSSIBLE"
Explanation: Re-arrangement is required and the new string has no adjacent alphabets which are the same. We can create the string as "aba".