Tap here to switch tabs
Problem
Submissions

Problem: Maximize Area of Square Hole in Grid

med
30 min
Try to solve the Maximize Area of Square Hole in Grid problem.

Statement

You are given two integers, n and m, representing a grid that contains n+2n + 2 horizontal bars and m+2m + 2 vertical bars. The horizontal bars are numbered from 11 to n+2n + 2, and the vertical bars are numbered from 11 to m+2m + 2.

You are also given two integer arrays, hBars and vBars.
The array hBars contains the indices of horizontal bars that can be removed.
The array vBars contains the indices of vertical bars that can be removed.

A hole is a contiguous empty region formed by removing some bars. Return the maximum area of a square hole that can be created by removing any combination of the available bars.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

  • 1≤1 \leq m ≤109\leq 10^9

  • 1≤1 \leq hBars.length ≤100\leq 100

  • 2≤2 \leq hBars[i] ≤\leq n +1+ 1

  • 1≤1 \leq vBars.length ≤100\leq 100

  • 2≤2 \leq vBars[i] ≤\leq m +1+ 1

  • All values in hBars are distinct.

  • All values in vBars are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Area of Square Hole in Grid

med
30 min
Try to solve the Maximize Area of Square Hole in Grid problem.

Statement

You are given two integers, n and m, representing a grid that contains n+2n + 2 horizontal bars and m+2m + 2 vertical bars. The horizontal bars are numbered from 11 to n+2n + 2, and the vertical bars are numbered from 11 to m+2m + 2.

You are also given two integer arrays, hBars and vBars.
The array hBars contains the indices of horizontal bars that can be removed.
The array vBars contains the indices of vertical bars that can be removed.

A hole is a contiguous empty region formed by removing some bars. Return the maximum area of a square hole that can be created by removing any combination of the available bars.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

  • 1≤1 \leq m ≤109\leq 10^9

  • 1≤1 \leq hBars.length ≤100\leq 100

  • 2≤2 \leq hBars[i] ≤\leq n +1+ 1

  • 1≤1 \leq vBars.length ≤100\leq 100

  • 2≤2 \leq vBars[i] ≤\leq m +1+ 1

  • All values in hBars are distinct.

  • All values in vBars are distinct.