File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 47
47
48
48
## Week 5 🚧
49
49
50
- Coming Soon...
50
+ 1 . [ Maximize Distance to Closest Person ] ( https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/563/week-5-october-29th-october-31st/3512/ ) ➡️ [ CPP Solution ] ( Week5/maxDistToClosest.cpp )
51
51
52
52
## Other Challenges 💪
53
53
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ int maxDistToClosest (vector<int >& seats) {
4
+ vector<int > onesPos;
5
+ int n = seats.size ();
6
+ int maxDistance = 0 ;
7
+
8
+ for (int i = 0 ; i < n; ++i) {
9
+ if (seats[i] == 1 ) onesPos.push_back (i);
10
+ }
11
+
12
+ int m = onesPos.size ();
13
+
14
+ if (onesPos[0 ] != 0 )
15
+ maxDistance = max (maxDistance, onesPos[0 ]);
16
+
17
+ for (int i = 0 ; i < m - 1 ; ++i)
18
+ maxDistance = max (maxDistance, (onesPos[i + 1 ] - onesPos[i]) / 2 );
19
+
20
+ if (onesPos[m - 1 ] != n - 1 )
21
+ maxDistance = max (maxDistance, n - 1 - onesPos[m - 1 ]);
22
+
23
+ return maxDistance;
24
+ }
25
+ };
You can’t perform that action at this time.
0 commit comments