You're given a 2D grid filled with positive integers, and your goal is to become a strategic treasure hunter! ๐
Your mission: Select cells from the grid to maximize your score (sum of selected values), but there are two crucial rules:
- No two cells from the same row - each row can contribute at most one treasure
- All selected values must be unique - no duplicates allowed in your collection
Think of it as choosing the best representatives from each row, where each representative must have a unique value that hasn't been chosen before.
Example: In grid [[1,2,3],[4,3,2],[1,1,1]], you could select 3 from row 0 and 4 from row 1 for a score of 7, but you can't select another 3 since values must be unique!
Input & Output
Visualization
Time & Space Complexity
For each row, we try all possible column choices, leading to exponential combinations
Recursion stack depth and space to track current selection
Constraints
- 1 โค grid.length, grid[i].length โค 10
- 1 โค grid[i][j] โค 100
- All values in the grid are positive integers
- You must select at least one cell to get a non-zero score