Empty Shelf

Problem Overview

  • Given a 2D bookshelf (types 1..k), each turn select a book and remove all books of that type in the same row or column; find the minimum turns to empty the shelf.
  • Input: m×n grid, 1<=m,n<=100, 1<=k<=100. Output: smallest number of turns.
  • Real-world context: managing a bookshelf/inventory by clearing matching items along rows and columns.
  • From Square_point interviews; a coding interview problem often asked as an interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: