← All problemsSign in

LEAST NUMBER OF MOVES

You have $n$ squares. You are given a binary string squares of length $n$. where squares[i] is $0$ if the i-th square is empty, and $1$ if the i-th square contains a ball. In one operation you can move only one ball from a square to an adjacent square, square $i$ is adjacent to square $j$ if abs$(i-j)$==1. - Note: After doing so, there may be more than one ball in some squares. Print t

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start