Problem · String

No Adjacent Characters

EasyNutanixOA

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:

  1. Re-arrangement is required but is not possible.

Return "POSSIBLE" if:

  1. There is no rearrangement required as the string is already in the right format.
  2. Re-arrangement is required and a new string has no adjacent alphabets which are the same.

Function Description

Complete the function canRearrangeString in the editor.

canRearrangeString has the following parameter:

  1. String s: the string to check

Returns

String: either "POSSIBLE" or "NOT POSSIBLE"

Examples
01 · Example 1
s = "ab"
return = "POSSIBLE"
Re-arrangement is required and the new string has no adjacent alphabets which are the same. We can create the string as "aba".
More Nutanix problems
drafts saved locally
public String canRearrangeString(String s) {
  // write your code here
}
s"ab"
expected"POSSIBLE"
sign in to submit