FastPrepLargest Opening After Removing Bars

Largest Opening After Removing Bars

Roblox logoRoblox● MediumNEW GRADOA
Learn

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[]) → long

Examples

Example 1

n = 3m = 3horizontal = [1,2]vertical = [2]return = 6

Removing 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 = 1

No bars are removed, so all openings stay 1 by 1.

Example 3

n = 2m = 2horizontal = [2,1]vertical = [1,2]return = 9

All internal bars disappear, leaving a 3 by 3 opening.

Constraints

  • 1 <= n, m <= 1000000000.
  • 0 <= horizontal.length <= min(n, 100000) and 0 <= vertical.length <= min(m, 100000).
  • Horizontal IDs are distinct integers in 1..n; vertical IDs are distinct integers in 1..m. Either list may be unsorted.
  • Return a signed 64-bit integer area.

More Roblox problems

See Roblox hiring insights
public long largestOpeningArea(int n, int m, int[] horizontal, int[] vertical) {
    // write your code here
}
n3
m3
horizontal[1,2]
vertical[2]
expected6
Checking account…