Empty Shelf

Asked at Squarepoint · Coding Questions · Difficulty: Hard · Last asked Jul 15, 2026

You are given a 2D vector `bookshelf`, where each element represents a book type numbered from `1` to `k`. The task is to empty the bookshelf by selecting a book and removing all books of the same type that lie in the same row or column as the selected book. The goal is to determine the minimum number of turns needed to completely clear the bookshelf.

Loading the problem…