Wormhole Spacecraft Overtakes
Reported by candidates from Kickdrum's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The whole Kickdrum Wormhole Spacecraft Overtakes question hinges on one data structure: a hash map from spacecraft ID to exit position. Kickdrum candidates reported it in September 2026. With n up to 200000, the obvious pair check dies fast, so the OA is really testing whether you can turn this into a clean array problem. Map each ID to its exit rank, read the entry order as a sequence of numbers, and you're counting elements that belong to an inversion. If you blank on the reduction during the live OA, StealthCoder runs invisibly as a safety net and hands you the approach.
The problem
Distinct spacecraft enter a wormhole one at a time in entryOrder and emerge in exitOrder. Both arrays contain the same identifiers exactly once. Two spacecraft crossed if the one that entered later emerged earlier. Return the number of distinct spacecraft that crossed at least one other spacecraft. Count each spacecraft at most once. Function countCrossingSpacecraft(entryOrder: String[], exitOrder: String[]) → int Examples Example 1 entryOrder = ["A","B","C","D"] exitOrder = ["A","C","B","D"] return = 2 B entered before C but emerged after it, so exactly those two spacecraft participated in a crossing. Example 2 entryOrder = ["A","B","C"] exitOrder = ["C","B","A"] return = 3 Every spacecraft belongs to at least one inverted pair. Constraints 1 <= entryOrder.length = exitOrder.length <= 200000. Each identifier contains 1 to 20 ASCII letters, digits, or underscores. Every identifier occurs exactly once in each array.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: replace each ID in entryOrder with its index in exitOrder using a hash map. Now you have a permutation, and a spacecraft crossed someone if it's part of any inversion. Here's the clean test. An element is NOT in any inversion only if every earlier element is smaller and every later element is larger. So compute prefix max and suffix min in O(n). Element i is safe if prefixMax of the elements before i is less than rank[i] and suffixMin of the elements after i is greater than rank[i]. Answer is n minus the safe count. The common pitfall is counting inverted pairs with a Fenwick tree and then double counting spacecraft, or writing O(n^2) loops that time out at 200000. Another slip is comparing strings instead of mapped integers. StealthCoder is your hedge in the live OA if the prefix max and suffix min idea doesn't come to you under pressure.
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 Wormhole Spacecraft Overtakes 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
You've seen the question.
Make sure you actually pass Kickdrum's OA.
Kickdrum 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.
Wormhole Spacecraft Overtakes FAQ
What's the trick in Wormhole Spacecraft Overtakes?+
Map each ID to its position in exitOrder, then read entryOrder as a permutation of those positions. A spacecraft crossed another if it's in an inversion. You don't need to count pairs. You only need to know which elements are in at least one inversion.
How hard is this problem really?+
Medium. The reduction to a permutation is easy once you see it. The harder part is avoiding the O(n^2) pair check and finding the O(n) prefix max and suffix min test. With n up to 200000, brute force won't pass.
Do I need a Fenwick tree or merge sort?+
No. Those count inversions, but you only need which elements are involved. A prefix max array and suffix min array do it in linear time. A Fenwick tree works but is more code and easier to get wrong.
How do I tell if a spacecraft is not part of any crossing?+
After mapping to exit ranks, element i is safe if everything before it has a smaller rank and everything after it has a larger rank. Check max of the prefix is below rank[i] and min of the suffix is above it. Count the safe ones and subtract from n.
How do I prepare for this in 48 hours?+
Write the hash map plus prefix max and suffix min solution once from scratch. Test it on both examples, a fully sorted case where the answer is 0, and a fully reversed case where the answer is n. Check edge cases like n equals 1.