Problem 4046 · Medium

Minimum Cost Path With At Most K Turns

Run a cheapest-first search whose states also remember the direction and how many turns were spent; the first time the corner is popped gives the answer.

Open the interactive visualisation