Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

LeetCode #849: Maximize Distance to Closest Person

I am trying to solve the problem in the link below from LeetCode:

LeetCode: #849

But, I ask because I don’t understand some edge case below:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Input: [1, 0, 0, 1]

Expected: 1

I believe the rule returns the result value as shown below:

The following image shows my edge case outcome based on the preceding rule:

Based on the rules shown in Figure #1, Alex must sit in the seat with index 1 or 2 in Figure #2.

In such situation, Alex’s neighbor’s maximum distance should be 2.

However, the expected answer is that the maximum distance is 1.

Can anyone explain why the max distance has to be 1?

>Solution :

"Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized."

[1, [0], 0, 1]
Closest to is to the left.

[1, 0, [0], 1]
Closest is to the right.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading