Construct WDL String
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The TikTok OA reported in September 2026 hands you a string of only W, D, and L and asks you to rebuild it in rounds: take one W, one D, one L, repeat until nothing's left. It looks like a simulation, and it basically is. The catch is that you shouldn't literally delete characters from a string over and over. This is a counting problem in disguise, and it's one of the easier string questions you'll see. If you blank under the clock, StealthCoder runs invisibly during the live OA and can hand you the approach as a safety net.
The problem
You are given a string inputStr containing only the letters W, D, and L. Construct a new string from the characters of inputStr using the following algorithm. Begin with an empty string output = "". If inputStr contains a W, remove any one W from inputStr and append W to the end of output. If inputStr contains a D, remove any one D from inputStr and append D to the end of output. If inputStr contains an L, remove any one L from inputStr and append L to the end of output. If inputStr is empty, stop. Otherwise, repeat from the W step. Return output after the algorithm is complete. Function constructWdlString(inputStr: String) → String Examples Example 1 inputStr = "LDWDL" return = "WDLDL" The first pass appends W, D, and L, leaving one D and one L. The second pass appends D and L, so the final string is "WDLDL". Example 2 inputStr = "LLDWW" return = "WDLWL" There are two W letters, one D letter, and two L letters. The algorithm appends W, D, L in the first pass, then W and L in the second pass. Constraints inputStr contains only the letters W, D, and L. A solution with time complexity no worse than O(inputStr.length2) fits within the execution time limit.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to count, not simulate. Tally how many W, D, and L characters exist. Then loop: while any count is above zero, append W if wCount > 0 and decrement, then D, then L, in that fixed order. Each pass skips letters that have run out, which is exactly what the algorithm says. That's O(n) time and O(1) extra space beyond the output. The stated bound allows O(n^2), so a naive remove-and-rebuild approach passes too, but counting is cleaner and safer. Common pitfalls: appending in the wrong order, forgetting that exhausted letters get skipped rather than stopping the loop, and building the result with repeated string concatenation in a slow language. Use a list or StringBuilder. Check Example 2, LLDWW, giving WDLWL. If you freeze on the live OA, StealthCoder is the hedge that gets you unstuck fast.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Construct WDL String cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as increasing decreasing string. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Construct WDL String FAQ
How hard is the TikTok Construct WDL String problem really?+
Easy. It's a counting problem with a fixed output order. If you can count characters and write a while loop, you can solve it. The risk is overthinking it, not the difficulty. Most of your time should go to edge cases and clean code.
What's the trick to Construct WDL String?+
Count each of W, D, and L first. Then repeat rounds: append W if any remain, then D, then L, decrementing as you go. Stop when all three counts hit zero. No string deletion is needed, which keeps it linear.
Can I just simulate the removals directly?+
Yes, the constraint allows O(n^2), so removing characters from the string each pass will pass. It's slower and messier though. Counting is just as easy to write and avoids index bugs and repeated string copying.
What edge cases should I test?+
Test a string with only one letter type, like WWW, which should return WWW. Test an empty-like minimal input of one character. Test uneven counts like LLDWW, expecting WDLWL. Also confirm the order stays W, D, L each round even when some letters are exhausted.
How do I prepare for this in 48 hours?+
Don't binge problems. Rehearse the frequency-count pattern and writing a loop that cycles through a fixed order with skip conditions. Solve this one and two similar string-rebuild problems, and practice writing output with a list join. That's enough for this tier of question.