Mutual Wishlist Rankings
Reported by candidates from Stripe's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Stripe question is treating CHANGED as a full recompute. It was reported in September 2021, and the trap is easy to miss. Mutual Wishlist Rankings gives you ordered wishlists and two operations: MUTUAL checks whether two users rank each other at the same position, and CHANGED asks who flips status if you hypothetically swap two adjacent ranks. It's a hash map and careful case analysis problem, not anything exotic. If you blank on the swap logic during the live OA, StealthCoder is the safety net that reads the prompt and hands you a working solution.
The problem
Users of an apartment-exchange service keep ordered wishlists of other users' apartments. Each wishlist row is user:choice1,choice2,..., with rank 0 as the first choice. Process two kinds of operations: MUTUAL user rank: return true when the apartment at that rank belongs to another user who also places user at the same rank. CHANGED user rank: rank is at least 1. Imagine moving that entry up one position by swapping ranks rank and rank-1. Without mutating the stored wishlist, return the users whose mutual-ranked status with user would change. Return one string per operation. A changed list is formatted as sorted usernames inside brackets, for example [a,c] or []. Function evaluateWishlist(wishlists: String[], operations: String[]) → String[] Examples Example 1 wishlists = ["a:c,d","b:d,a,c","c:a,b","d:c,a,b"] operations = ["MUTUAL a 0","MUTUAL b 0","MUTUAL a 1","CHANGED d 1","CHANGED b 2","CHANGED b 1"] return = ["true","false","true","[a]","[c]","[]"] a/c are mutual first choices, a/d are mutual second choices, and only the source-described pairings change under each hypothetical rank bump. Example 2 wishlists = ["amy:bo,cy","bo:cy,amy","cy:amy,bo"] operations = ["MUTUAL amy 0","MUTUAL amy 1","CHANGED amy 1"] return = ["false","false","[bo,cy]"] Neither original rank is mutual. Swapping amy's choices creates mutual rank 0 with cy and mutual rank 1 with bo. Constraints 1 <= wishlists.length <= 1000. Usernames are unique, and every listed choice names another supplied user at most once. 1 <= operations.length <= 10000. A MUTUAL rank may be out of range and then returns false. A CHANGED rank is valid and at least 1. Operations do not mutate the wishlists.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Parse each row into a map from user to list, plus a map from user to choice-to-rank. MUTUAL is then O(1): look up the choice at that rank, then check that the other user's list has your name at the same rank. Out-of-range rank returns false. For CHANGED user rank, only two entries move: the user at rank and the user at rank-1. Only those two users can change status with the given user, so you never recompute everything. For each of them, compare mutual status before the swap and after, using the swapped positions virtually. Collect the ones that differ, sort, and format as [a,c]. The pitfall is mutating the stored list, or forgetting that each of the two users can flip in either direction. Check against Example 2 by hand. StealthCoder is the hedge if the swap bookkeeping tangles under pressure.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Mutual Wishlist Rankings 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Stripe's OA.
Stripe reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Mutual Wishlist Rankings FAQ
What's the trick in Mutual Wishlist Rankings?+
Only two users can change in a CHANGED operation: the ones at rank and rank-1 in the target's list. Check each one's mutual status before and after the virtual swap. Don't rebuild anything. That keeps each operation constant time apart from sorting a tiny result.
How hard is this Stripe OA question really?+
Medium at most. The data structures are simple maps and lists. The difficulty is the case analysis for CHANGED and not mutating the stored wishlists. Walk Example 2 by hand and you'll catch most bugs before submitting.
How should I store the wishlists?+
Keep a map from username to the ordered list of choices. That gives O(1) access to who sits at any rank. To test mutuality, you fetch the choice at a rank, then check that user's list has your name at that same rank.
What edge cases break solutions?+
Out-of-range MUTUAL ranks must return false. CHANGED with an empty result must print []. Sorting usernames before formatting matters. Also, a user whose list is shorter than the rank must not throw an index error when you check the other side.
Can I prepare for this in 48 hours?+
Yes. Practice parse-and-lookup problems with hash maps, then write the swap check as a helper that takes a virtual list. Test both examples and a case with a rank beyond the list length. The structure repeats across string-operation OAs like this one.