MEDIUMasked at 2 companies

Minimum Cost Homecoming of a Robot in a Grid

A medium-tier problem at 51% community acceptance, tagged with Array, Greedy. Reported in interviews at HP and 1 others.

Founder's read

Minimum Cost Homecoming of a Robot in a Grid is a medium-difficulty grid traversal problem that HP and Goldman Sachs have both asked in their assessments. The 51% acceptance rate signals that candidates who nail the greedy insight pass cleanly, while those missing the pattern get trapped in suboptimal search. The trick is recognizing that you can't just pick the cheapest move at each step. You need to understand directional movement costs and when backtracking actually saves money. If this problem hits your live OA and you're unsure whether to simulate or jump to a greedy choice, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
51%

Companies that ask "Minimum Cost Homecoming of a Robot in a Grid"

If this hits your live OA

Minimum Cost Homecoming of a Robot in a Grid 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 an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The problem requires moving a robot from a start position back to the origin with minimum total cost. Each move has a directional cost (horizontal or vertical), and the naive approach of always picking the cheapest next move fails because costs often depend on which direction you're already moving or switching directions. The key insight is recognizing that some sequences of moves are cheaper than others when you factor in directional changes. A greedy approach works once you correctly model the cost structure: identify the net displacement needed in each dimension, then find the optimal order and mix of moves. Most candidates miss that you might need to overshoot in one direction to avoid expensive transitions, or that consecutive moves in the same direction have different costs than mixed moves. StealthCoder handles the cost logic and move sequencing when the pattern isn't immediately obvious during the assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Minimum Cost Homecoming of a Robot in a Grid recycles across companies for a reason. It's medium-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 an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Cost Homecoming of a Robot in a Grid interview FAQ

Is this really about greedy, or is there a DP angle?+

It's greedy once you model it right. The problem looks like it could be DP because of the grid, but the actual solution is identifying the optimal sequence of directional moves to minimize cost transitions. Understanding the cost structure makes greedy work. Don't overthink it into DP territory.

Why do 49% of candidates fail if the acceptance is 51%?+

Most failures come from trying to simulate movement step-by-step without recognizing the underlying directional cost pattern. Candidates also sometimes misread whether move costs are per cell or per direction switch. Clarity on cost attribution is the difference between pass and timeout.

Do HP and Goldman Sachs weight this problem differently in their interviews?+

Both companies have asked it, suggesting they value the greedy pattern recognition and cost optimization logic equally. It's not a gimmick question either placed. Expect it to carry standard medium-difficulty weight in your assessment.

What's the most common wrong approach here?+

Treating it as shortest path and running BFS or Dijkstra, when the actual solution is a math-based greedy walk. Grid problems tempt you toward search, but this one rewards understanding the cost model instead. Recognize the problem type early and skip search.

How much do I need to practice similar problems before an OA?+

One or two solid greedy grid problems will give you the intuition. If you've done movement cost optimization before, this becomes straightforward. If not, the gap between 'obvious' and 'tricky' is real. That's where the 51% acceptance sits.

Want the actual problem statement? View "Minimum Cost Homecoming of a Robot in a Grid" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.