> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/hashmap-and-hashset-and-sliding-window/line-reflection.md).

# Line Reflection

Given `n` points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points.

#### Example

**Example1**

```
Input: [[1,1],[-1,1]]
Output: true
```

**Example2**

```
Input: [[1,1],[-1,-1]]
Output: false
```

#### Challenge

Could you do better than O(n2)?

```java
public class Solution {
    public boolean isReflected(int[][] points) {
        int minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE;
        Set<String> set = new HashSet<>();
        for (int[] p : points) {
            minX = Math.min(minX, p[0]);
            maxX = Math.max(maxX, p[0]);
            String str = Double.toString((double) p[0]) + " " + Double.toString((double) p[1]);

            set.add(str);
        }
        // This will be our reflection line
        double mid = (double) ((minX + maxX)) / 2.0;

        for (int[] p : points) {
            double dist = Math.abs((double) p[0] - mid);
            String key = Double.toString(p[0] > mid ? (double) p[0] - 2 * dist : (double) p[0] + 2 * dist) + " "
                    + Double.toString((double) p[1]);
            if (!set.contains(key))
                return false;
        }
        return true;
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mayanktyagi3111.gitbook.io/interview-prep/hashmap-and-hashset-and-sliding-window/line-reflection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
