2025-01-09 20:29:41 +08:00
< p > You are given the two integers, < code > n< / code > and < code > m< / code > and two integer arrays, < code > hBars< / code > and < code > vBars< / code > . The grid has < code > n + 2< / code > horizontal and < code > m + 2< / code > vertical bars, creating 1 x 1 unit cells. The bars are indexed starting from < code > 1< / code > .< / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > You can < strong > remove< / strong > some of the bars in < code > hBars< / code > from horizontal bars and some of the bars in < code > vBars< / code > from vertical bars. Note that other bars are fixed and cannot be removed.< / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > Return an integer denoting the < strong > maximum area< / strong > of a < em > square-shaped< / em > hole in the grid, after removing some bars (possibly none).< / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > < / p >
< p > < strong class = "example" > Example 1:< / strong > < / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > < img alt = "" src = "https://assets.leetcode.com/uploads/2023/11/05/screenshot-from-2023-11-05-22-40-25.png" style = "width: 411px; height: 220px;" / > < / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< div class = "example-block" style = "border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;" >
< p > < strong > Input: < / strong > < span class = "example-io" style = "font-family: Menlo,sans-serif; font-size: 0.85rem;" > n = 2, m = 1, hBars = [2,3], vBars = [2]< / span > < / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > < strong > Output: < / strong > < span class = "example-io" style = "font-family: Menlo,sans-serif; font-size: 0.85rem;" > 4< / span > < / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > < strong > Explanation:< / strong > < / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > The left image shows the initial grid formed by the bars. The horizontal bars are < code > [1,2,3,4]< / code > , and the vertical bars are < code > [1,2,3]< / code > .< / p >
2023-12-09 01:16:38 +08:00
2025-01-09 20:29:41 +08:00
< p > One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.< / p >
< / div >
2023-12-09 01:16:38 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
< p > < img alt = "" src = "https://assets.leetcode.com/uploads/2023/11/04/screenshot-from-2023-11-04-17-01-02.png" style = "width: 368px; height: 145px;" / > < / p >
2025-01-09 20:29:41 +08:00
< div class = "example-block" style = "border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;" >
< p > < strong > Input: < / strong > < span class = "example-io" style = "font-family: Menlo,sans-serif; font-size: 0.85rem;" > n = 1, m = 1, hBars = [2], vBars = [2]< / span > < / p >
< p > < strong > Output: < / strong > < span class = "example-io" style = "font-family: Menlo,sans-serif; font-size: 0.85rem;" > 4< / span > < / p >
< p > < strong > Explanation:< / strong > < / p >
< p > To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.< / p >
< / div >
2023-12-09 01:16:38 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2025-01-09 20:29:41 +08:00
< p > < img alt = "" src = "https://assets.leetcode.com/uploads/2024/03/12/unsaved-image-2.png" style = "width: 648px; height: 218px;" / > < / p >
< div class = "example-block" style = "border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;" >
< p > < strong > Input: < / strong > < span class = "example-io" style = "font-family: Menlo,sans-serif; font-size: 0.85rem;" > n = 2, m = 3, hBars = [2,3], vBars = [2,4]< / span > < / p >
< p > < strong > Output: < / strong > < span class = "example-io" style = "font-family: Menlo,sans-serif; font-size: 0.85rem;" > 4< / span > < / p >
< p > < strong > Explanation:< / strong > < / p >
< p > < span style = "color: var(--text-secondary); font-size: 0.875rem;" > One way to get the maximum square-shaped hole is by removing horizontal bar 3, and vertical bar 4.< / span > < / p >
< / div >
2023-12-09 01:16:38 +08:00
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = n < = 10< sup > 9< / sup > < / code > < / li >
< li > < code > 1 < = m < = 10< sup > 9< / sup > < / code > < / li >
< li > < code > 1 < = hBars.length < = 100< / code > < / li >
< li > < code > 2 < = hBars[i] < = n + 1< / code > < / li >
< li > < code > 1 < = vBars.length < = 100< / code > < / li >
< li > < code > 2 < = vBars[i] < = m + 1< / code > < / li >
< li > All values in < code > hBars< / code > are distinct.< / li >
< li > All values in < code > vBars< / code > are distinct.< / li >
< / ul >