Build Cyclic String Endpoint Pairs
Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The ZipRecruiter OA reported in October 2023 looks like a warm-up, and that's the trap. You get an array of strings treated as a circle, and for each index you glue the first character of the current string to the last character of the next one. It's a string problem with one wrap-around. Most people write the loop in two minutes and then lose points on the single-element case. If you blank on the edge handling during the live assessment, StealthCoder sits invisibly on your screen as a safety net and hands you the clean version.
The problem
Given a nonempty array of nonempty strings treated cyclically, output at index i is the first character of values[i] followed by the last character of values[(i + 1) mod n]. Function cyclicEndpointPairs(values: String[]) → String[] Examples Example 1 values = ["abc","def","ghi"] return = ["af","di","gc"] Each current first character pairs with the next cyclic last character. Example 2 values = ["cat","dog","bee"] return = ["cg","de","bt"] The pairs use c with g, d with e, and b with the wrapped t. Constraints 1 <= values.length <= 100000 Every string is nonempty.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is the modulo. For each i, output values[i][0] plus values[(i + 1) % n][len - 1]. That's one pass, O(n) time, and the output array is O(n). The edge case that breaks a naive solution is the last index. Without the modulo you read past the end of the array, or you special-case it and get it wrong. The second edge is n = 1. Then the next string is the string itself, so you pair its first character with its own last character. A one-character string works too, because first and last are the same character. Don't slice or build substrings per element. Index directly into the characters so you stay linear with n up to 100000. Use a list and join each pair, or append characters, rather than repeated string concatenation in a loop. If the wrap-around logic slips under time pressure, StealthCoder is the hedge for the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Build Cyclic String Endpoint 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass ZipRecruiter's OA.
ZipRecruiter reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Build Cyclic String Endpoint Pairs FAQ
How hard is the ZipRecruiter cyclic endpoint pairs question really?+
It's easy. One pass, no data structures, no tricky algorithm. The only real risk is the wrap-around at the last index and the single-element array. If you handle those two, you're done. Spend your remaining time checking the output order and types.
What's the trick to this problem?+
Use modulo for the next index: (i + 1) % n. Take the first character of values[i] and the last character of values[(i + 1) % n]. That one expression covers the wrap and the n = 1 case without special branches.
What edge cases should I test before submitting?+
Test n = 1, where a string pairs with itself. Test strings of length 1, where first and last are the same character. Test n = 2, where the wrap happens immediately. Then run both examples: abc, def, ghi gives af, di, gc.
Will this pass with 100000 strings?+
Yes, if you stay O(n). Index characters directly and build each two-character result once. Avoid slicing whole strings or repeated concatenation on a growing string. A single pass with a preallocated list or an appended list is plenty.
How do I prepare for this in 48 hours?+
Practice circular array indexing with modulo and basic string indexing in your language. Write this one from scratch twice, including the n = 1 case. It takes ten minutes. Then spend the rest of your time on harder string and hash-map problems, since the other OA questions may be tougher.