Largest Opening After Removing Bars
Updated
Problem statement
For this exercise, assume a rectangular grid of bars has n removable horizontal bars numbered 1..n and m removable vertical bars numbered 1..m. Each bar crosses the whole grid, 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.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- API Rate Limit Violation DetectionTekion · OATekion interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Convert Sparse Records to a Filled TableNetflix · OANetflix interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
- Rank Teams by VotesAtlassian · OAAtlassian interview questions