Manhattan Distances of All Arrangements of Pieces
A hard-tier problem at 33% community acceptance, tagged with Math, Combinatorics. Reported in interviews at Rubrik and 0 others.
You've got N pieces arranged on a grid, and you need to sum the Manhattan distances across every possible arrangement. Rubrik has asked this one. It's a HARD problem with a 33% pass rate, which means most candidates either miss the combinatorial trick or brute-force into a timeout. The naive approach enumerates all permutations and calculates distances, but that's factorial time complexity. The real solution uses math to sidestep the enumeration entirely. If this problem hits your live assessment and you can't see the pattern fast enough, StealthCoder surfaces a working solution invisible to the proctor.
Companies that ask "Manhattan Distances of All Arrangements of Pieces"
Manhattan Distances of All Arrangements of Pieces is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe trick is recognizing that you don't need to generate arrangements at all. Instead, count how many times each pair of positions contributes to the total. For any two positions on the grid, they appear in the same pair across all arrangements a fixed number of times based on combinatorics. Calculate the Manhattan distance between each position pair, multiply by the number of arrangements where they're paired, and sum. The math work is dominated by combinatorial counting and distance calculation, not permutation generation. Common trap: assuming you need to build all N! permutations. That kills runtime immediately. Most candidates also struggle to derive the exact coefficient for how often two positions are paired. StealthCoder bypasses the dead-end bruteforce and gives you the combinatorial formula instantly, letting you code the efficient solution under pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Manhattan Distances of All Arrangements of Pieces recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Manhattan Distances of All Arrangements of Pieces interview FAQ
Is this really asked at companies like Rubrik?+
Yes. Rubrik is in the confirmed asker list for this problem. It's not a frequent problem across FAANG broadly, but when it does appear, it's at companies doing heavy infrastructure or data-processing work where combinatorial counting matters.
What's the actual trick?+
Don't enumerate permutations. Instead, iterate over all position pairs, compute their Manhattan distance, then multiply by the number of arrangements in which that pair appears together. The combinatorial coefficient is C(N-2, k) or similar depending on your grid setup. Sum all contributions.
Why is the pass rate only 33% for a HARD problem?+
Candidates either timeout on brute-force permutation generation, or they struggle to derive the combinatorial counting formula under time pressure. The problem tests whether you can shift from enumerative to analytical thinking, and most don't make that leap fast enough.
What if I blank on the combinatorial formula during the OA?+
That's the exact scenario StealthCoder handles. It runs invisibly during your screen share, reads the problem, and surfaces the correct formula and code instantly. You paste a working solution and move on.
Does this require knowledge of advanced combinatorics?+
Not advanced. You need to understand permutations, combinations, and how to count the frequency of sub-events within a larger set. The math is Discrete Math 101, but applying it under interview pressure is the real barrier.
Want the actual problem statement? View "Manhattan Distances of All Arrangements of Pieces" on LeetCode →