← Questions

Can every car park with preferred spots and forward-only overflow

0
MercorCodingLast asked Sep 2026

A one-way street has n spots numbered 0 to n - 1. Cars arrive in order; car i wants spot preferences[i], takes it if free, and otherwise drives forward to the next free spot. A car that passes the last spot fails to park. Decide whether every car finds a spot, and do better than simulating each car's walk.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding