> For the complete documentation index, see [llms.txt](https://jaywin.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jaywin.gitbook.io/leetcode/solutions/0302-smallest-rectangle-enclosing-black-pixels.md).

# 0302. Smallest Rectangle Enclosing Black Pixels

<https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels>

## Description

You are given an `m x n` binary matrix `image` where `0` represents a white pixel and `1` represents a black pixel.

The black pixels are connected (i.e., there is only one black region). Pixels are connected horizontally and vertically.

Given two integers `x` and `y` that represents the location of one of the black pixels, return *the area of the smallest (axis-aligned) rectangle that encloses all black pixels*.

You must write an algorithm with less than `O(mn)` runtime complexity

**Example 1:**

![](https://assets.leetcode.com/uploads/2021/03/14/pixel-grid.jpg)

```
**Input:** image = [["0","0","1","0"],["0","1","1","0"],["0","1","0","0"]], x = 0, y = 2
**Output:** 6
```

**Example 2:**

```
**Input:** image = [["1"]], x = 0, y = 0
**Output:** 1
```

**Constraints:**

* `m == image.length`
* `n == image[i].length`
* `1 <= m, n <= 100`
* `image[i][j]` is either `'0'` or `'1'`.
* `1 <= x < m`
* `1 <= y < n`
* `image[x][y] == '1'.`
* The black pixels in the `image` only form **one component**.

## ac

```java
```
