Largest Opening After Removing Bars
Problem statement
For this exercise, assume a rectangular lattice has n removable horizontal bars numbered 1..n and m removable vertical bars numbered 1..m. All bars span the full lattice, adjacent bars are one unit apart, and fixed outer boundaries lie at horizontal positions 0 and n+1 and vertical positions 0 and m+1.
Remove exactly the horizontal bars listed in horizontal and vertical bars listed in vertical. Return the area of the largest rectangular opening formed between remaining bars or outer boundaries. Do not remove any additional bars or change the input arrays. If no bars are removed, every opening is a unit square.
Function
largestOpeningArea(n: int, m: int, horizontal: int[], vertical: int[]) → longExamples
Example 1
n = 3m = 3horizontal = [1,2]vertical = [2]return = 6Removing horizontal bars 1 and 2 creates a 3-unit height; removing vertical bar 2 creates a 2-unit width.
Example 2
n = 4m = 5horizontal = []vertical = []return = 1No bars are removed, so all openings stay 1 by 1.
Example 3
n = 2m = 2horizontal = [2,1]vertical = [1,2]return = 9All internal bars disappear, leaving a 3 by 3 opening.
Constraints
1 <= n, m <= 1000000000.0 <= horizontal.length <= min(n, 100000)and0 <= vertical.length <= min(m, 100000).- Horizontal IDs are distinct integers in
1..n; vertical IDs are distinct integers in1..m. Either list may be unsorted. - Return a signed 64-bit integer area.