Home > Software engineering >  LeetCode #849: Maximize Distance to Closest Person
LeetCode #849: Maximize Distance to Closest Person

Time:12-22

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:

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?

CodePudding user response:

"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.
  • Related