Super Washing Machines
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
There are n washing machines in a line, and machines[i] is the number of dresses in machine i. In one move you may pick **any number** of machines at once; each chosen machine that holds at least one dress passes exactly one dress to one of its adjacent machines. All passes in a move happen simultaneously.
Return the minimum number of moves needed to make every machine hold the same number of dresses, or -1 if that is impossible.
It is impossible exactly when the total number of dresses is not divisible by n. Aim for O(n) time.
Examples
Constraints
- n == machines.length
- 1 <= n <= 10^4
- 0 <= machines[i] <= 10^5
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.