FastPrepRound-Robin WDL Order

Round-Robin WDL Order

Hudson River Trading logoHudson River Trading● EasyNEW GRADINTERNOA
Learn

Problem statement

Given a string inputStr containing only W, D, and L, build a reordered string by consuming the available characters cyclically in this order:

  1. Append W if any W characters remain.
  2. Append D if any D characters remain.
  3. Append L if any L characters remain.

Repeat this cycle until every input character has been consumed. When a character is exhausted, skip it in later cycles while continuing to consume the other characters in the same cyclic order.

Return the reordered string.

Function

solution(inputStr: String) → String

Examples

Example 1

inputStr = "LDWDL"return = "WDLDL"

The first round appends W, then D, then L. The remaining D and L are appended in that order during the next round.

Example 2

inputStr = "WWWLLDDLD"return = "WDLWDLWDL"

There are three copies of each character, so three complete W, D, L rounds consume the string.

Example 3

inputStr = "LLLL"return = "LLLL"

Every round skips W and D, then appends one remaining L.

Constraints

  • Every character in inputStr is W, D, or L.

More Hudson River Trading problems

See Hudson River Trading hiring insights
public String solution(String inputStr) {
  // Write your code here.
}
inputStr"LDWDL"
expected"WDLDL"
Checking account…