A city map tool shows the land price of each block in grid (all prices are 0 or more). A developer wants the biggest square of blocks whose total price is at most limit.
Write largestSquare(grid, limit) that returns the side length of the largest such square, or 0 if even a single block costs more than limit.
Input: grid = [[2,1,3],[1,1,1],[4,1,2]], limit = 5 Output: 2
The top-left 2 by 2 square costs 2 + 1 + 1 + 1 = 5. The full 3 by 3 square costs 16.
Input: grid = [[9,9],[9,9]], limit = 8 Output: 0
Every block alone already costs more than 8.
1 <= rows, cols <= 3000 <= grid[r][c] <= 10^40 <= limit <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #54 Largest Square Under Budget. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.