Round-Robin WDL Order
Learn this problemProblem statement
Given a string sequence containing only W, D, and L, build a reordered string by consuming the available characters cyclically in this order:
- Append
Wif anyWcharacters remain. - Append
Dif anyDcharacters remain. - Append
Lif anyLcharacters 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
reorderWdl(sequence: String) → StringExamples
Example 1
sequence = "WWWLLDDLD"return = "WDLWDLWDL"The input has three copies of each character. Each complete W, D, L cycle consumes one of each, producing WDLWDLWDL.
Example 2
sequence = "WLDDL"return = "WDLDL"The first cycle produces WDL. No W remains, so the next cycle skips W and appends D followed by L, producing WDLDL.
Example 3
sequence = "WWWWLDDL"return = "WDLWDLWW"Two complete cycles consume two copies of each character and produce WDLWDL. Only two W characters remain, so they are appended in the next two cycles, producing WDLWDLWW.
Constraints
- Every character in
sequenceisW,D, orL.
More Capital One problems
- Compare Counts Around PivotOA · Seen Jul 2026
- Format a Newspaper PageOA · Seen Jul 2026
- Laser Robot Safe PathOA · Seen Jul 2026
- Match Consecutive Word BoundariesOA · Seen Jul 2026
- Reconstruct Landmark JourneyOA · Seen Jul 2026
- Rightmost Longest Character RunOA · Seen Jul 2026
- Track Received Byte RangesOA · Seen Jul 2026
- Alternate String EndsOA · Seen Jul 2026