Reverse Letters in Pairs
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip away the wording and this TikTok OA question from September 2026 is just swapping neighbors in a string. That's it. Reverse Letters in Pairs takes a lowercase string and flips each adjacent pair, leaving the last letter alone if the length is odd. It's tagged two-pointers, but a single index stepping by 2 does the whole job. If you've got an OA invite and 48 hours, this one shouldn't scare you. The risk is a silly off-by-one on odd lengths, not the idea. And if you blank mid-assessment, StealthCoder runs invisibly as a safety net and puts the answer on screen.
The problem
Given a string s of lowercase English letters, reverse its letters in adjacent pairs. For every pair of positions (0,1), (2,3), and so on, place the second letter before the first. If the string has odd length, leave its final letter in the same position. Return the resulting string. Function reverseLetterPairs(s: String) → String Examples Example 1 s = "abcdef" return = "badcfe" The pairs ab, cd, and ef become ba, dc, and fe. Example 2 s = "abcde" return = "badce" The pairs ab and cd are reversed. The unpaired final letter e stays in place. Example 3 s = "z" return = "z" A one-letter string has no complete pair, so it is unchanged. Constraints 1 <= s.length <= 100 s contains only lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: strings are immutable in most languages, so convert to a character array first. Then loop i from 0 while i + 1 < n, swap a[i] and a[i+1], and step i by 2. The condition i + 1 < n is what protects the odd-length case. The last letter never gets a partner, so it never moves. Return the joined array. Time is O(n), space is O(n) for the copy. The common pitfall is looping to i < n and then reading past the end, or stepping by 1 and swapping everything back and forth. Another is building the result with repeated string concatenation, which is fine at length 100 but sloppy. Test with "z", "ab", and "abcde" before you submit. If the live OA has you freezing on something this small, StealthCoder is the hedge, reading the prompt and handing you the clean loop.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Reverse Letters in Pairs 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Reverse Letters in Pairs FAQ
How hard is Reverse Letters in Pairs really?+
Easy. The input is capped at 100 characters, so there's no performance trap. You swap neighbors in steps of two. The only real way to lose points is mishandling an odd-length string or indexing past the end.
What's the trick to this TikTok question?+
Convert the string to a character array, then iterate i by 2 while i + 1 < n, swapping a[i] and a[i+1]. That bounds check handles odd lengths automatically. Join the array back into a string and return it.
Is it really a two-pointers problem?+
Loosely. The hint says two-pointers, but the pointers are just i and i+1 moving together by 2. You don't need left and right converging. Think of it as a fixed-stride swap, not a classic opposite-ends scan.
What edge cases should I test?+
Test a single letter like "z", which must return unchanged. Test an even string like "abcdef" and an odd one like "abcde". Also try two letters, "ab", which should become "ba". Those four cover every branch of the loop.
How do I prep for this in 48 hours?+
Don't grind. Write this swap loop once in your OA language and confirm how it makes a mutable character array from a string. Then spend the time on other array and string basics, since the TikTok OA likely has more than one question.