Maximize Area of Square Hole in Grid - Problem
You are given two integers n and m representing a grid with n + 2 horizontal and m + 2 vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from 1.
You are also given two integer arrays hBars and vBars representing the bars that can be removed from horizontal and vertical bars respectively. Note that other bars are fixed and cannot be removed.
Return an integer denoting the maximum area of a square-shaped hole that can be created in the grid after removing some bars (possibly none).
Input & Output
Example 1 — Basic Grid
$
Input:
n = 2, m = 3, hBars = [2, 3], vBars = [2, 4]
›
Output:
4
💡 Note:
Remove horizontal bars 2,3 and vertical bars 2,4 to create a 2×2 square hole with area 4.
Example 2 — Small Grid
$
Input:
n = 1, m = 1, hBars = [2], vBars = [2]
›
Output:
4
💡 Note:
Remove both removable bars to create a 2×2 square hole.
Example 3 — No Removable Bars
$
Input:
n = 2, m = 2, hBars = [], vBars = []
›
Output:
1
💡 Note:
Cannot remove any bars, so maximum hole is 1×1 with area 1.
Constraints
- 1 ≤ n, m ≤ 100
- 1 ≤ hBars.length, vBars.length ≤ n+1, m+1
- 1 ≤ hBars[i] ≤ n+1
- 1 ≤ vBars[i] ≤ m+1
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code