Reported September 2024
Ciscogreedy

Find Min Cost To Shift Machines

Reported by candidates from Cisco's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Cisco OA. Under 2s to a working solution.
Founder's read

Cisco's 'Find Min Cost To Shift Machines' problem hit the OA circuit in September 2024, and it's testing whether you can spot the greedy move under time pressure. You're likely working with machine positions and costs, trying to minimize the total expense of shifting them to some optimal state. The trap is overthinking the order of operations. StealthCoder runs invisible during your assessment, so if you freeze on the greedy choice, you have a safety net.

Pattern and pitfall

This is a classic greedy problem disguised as optimization. The core trick: once you identify what 'optimal' means (usually a target position or clustering), you don't need dynamic programming. Greedy works because the cost structure allows you to make locally optimal choices that compound into a global minimum. The pitfall is treating it like a DP problem and burning time on state transitions. The greedy angle usually hinges on sorting by position or cost, then processing left-to-right without backtracking. StealthCoder can hand you the pattern instantly if you blank on whether to iterate forward, backward, or by some derived metric. Focus on why the greedy choice never regrets itself.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Find Min Cost To Shift Machines 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 StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as minimum cost to make array equal. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Cisco's OA.

Cisco 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.

Find Min Cost To Shift Machines FAQ

Is this problem asking me to move all machines to a single position?+

Most likely, yes. That's the canonical version. The greedy insight: find the median or weighted median position, then sum distances. Avoid overthinking multi-target or cluster variations unless the problem explicitly mentions them.

What if the cost per unit distance varies by machine?+

Then you're weighting each machine's contribution to the final position. Sort by position, compute a weighted median, and sum weighted distances. It's still greedy; the sorting step is your leverage point.

Do I need to consider negative positions or wrap-around?+

Not unless stated. Assume a linear number line. Cisco's version almost certainly avoids wraparound and complex coordinate systems. Keep it simple.

How do I verify my greedy choice is correct?+

Prove that moving any machine further from the target increases cost. If the cost function is convex (sum of distances), the median target is unbeatable. Check a small test case by hand.

What's the time complexity I should aim for?+

O(n log n) from sorting, then O(n) to compute cost. If you're doing anything worse, you've overengineered. Greedy problems reward simplicity.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Cisco.

OA at Cisco?
Invisible during screen share
Get it