question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
⌀
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
exam-room
I think this is a hard problem
i-think-this-is-a-hard-problem-by-yituoz-26ln
This really is a hard problem, there are so many tricky things to handle.
yituozong
NORMAL
2022-06-24T21:21:05.324630+00:00
2022-06-24T21:21:05.324666+00:00
763
false
This really is a hard problem, there are so many tricky things to handle.
8
0
[]
0
exam-room
[Python3] heap & hash table
python3-heap-hash-table-by-ye15-m8ue
\n\nclass ExamRoom:\n\n def __init__(self, n: int):\n self.n = n\n self.pq = [(-n, -1, n)]\n self.nei = {-1: [None, n], n: [-1, None]} #
ye15
NORMAL
2021-07-23T20:35:39.786417+00:00
2021-07-23T20:35:50.497408+00:00
1,240
false
\n```\nclass ExamRoom:\n\n def __init__(self, n: int):\n self.n = n\n self.pq = [(-n, -1, n)]\n self.nei = {-1: [None, n], n: [-1, None]} # dummy head & tail \n\n def seat(self) -> int:\n while self.nei.get(self.pq[0][1], [None]*2)[1] != self.pq[0][2] or self.pq[0][1] != self.nei.get(s...
6
0
['Python3']
1
exam-room
Python heap solution with idea explanation
python-heap-solution-with-idea-explanati-jts7
The basic idea is to use a heap to give access to the largest distance.\nThe item in the heap is [-distance, left, right, valid]\nleft and right are the most le
hongsenyu
NORMAL
2020-04-13T09:22:39.313564+00:00
2020-04-13T09:36:01.482301+00:00
510
false
The basic idea is to use a heap to give access to the largest distance.\nThe item in the heap is [-distance, left, right, valid]\nleft and right are the most left and the most right empty space for a empty segment.\nUse a dict to support the random access to items in heap, (left, right):[-distance, left, right, valid]\...
6
0
[]
1
exam-room
Java TreeSet both operation O(log n)
java-treeset-both-operation-olog-n-by-ch-88kh
Some people use PriorityQueue to slove this problem, storing interval with descending dist order.\nBut priority queue takes O(n) to delete element.\nSo i wonder
chriszzt
NORMAL
2018-11-24T01:56:27.756854+00:00
2018-11-24T01:56:27.756897+00:00
494
false
Some people use PriorityQueue to slove this problem, storing interval with descending dist order.\nBut priority queue takes O(n) to delete element.\nSo i wonder if we could use treeSet that could take advantage of sorting and deleting by O(logn)\n\nWe need two treeSet, one is for storing Interval called heap\none is fo...
6
0
[]
2
exam-room
c++ | Explain | Set
c-explain-set-by-chirag1293-w0zu
Upvote if you liked the solution\n\nI commented the code for better understanding\n\nIdea:\nThere can be 3 possible ways to position a person\n1. At the 0th ind
chirag1293
NORMAL
2022-07-25T11:39:03.985685+00:00
2022-07-25T11:39:03.985728+00:00
1,007
false
***Upvote if you liked the solution***\n\nI commented the code for better understanding\n\nIdea:\nThere can be 3 possible ways to position a person\n1. At the 0th index\n2. Somewhere in between\n3. At the end\n\nSo first check if 0th position is not present in the set? is yes place the person and return\nfor in between...
5
0
['C', 'Ordered Set']
0
exam-room
C++ Set, O(n) seat and O(log(n)) leave
c-set-on-seat-and-ologn-leave-by-mcglam-3r2l
\nclass ExamRoom {\npublic:\n ExamRoom(int N) {\n n = N;\n }\n \n int seat() {\n //If seats are all availble, just seat at 0\n
mcglam
NORMAL
2018-09-25T19:05:53.307896+00:00
2018-10-08T22:35:05.857429+00:00
738
false
```\nclass ExamRoom {\npublic:\n ExamRoom(int N) {\n n = N;\n }\n \n int seat() {\n //If seats are all availble, just seat at 0\n if (seats.empty()) {\n seats.insert(0);\n return 0;\n }\n \n //Consider middle seats \n int res;\n a...
5
0
[]
2
exam-room
[Java/C++] Short TreeSet PriorityQueue Lambda O(logn) solution with explanation
javac-short-treeset-priorityqueue-lambda-83zq
define a triplet(dist, pre, suc) as a gap. dist = (suc - pre) / 2\n- only put gap with dist >= 1 to the pq. dist == 0 means there is no gap\n- when poll from pq
bitcoinevangelist
NORMAL
2018-06-17T03:45:47.495727+00:00
2018-08-12T20:07:32.220823+00:00
1,732
false
- define a triplet(dist, pre, suc) as a gap. dist = (suc - pre) / 2\n- only put gap with dist >= 1 to the pq. dist == 0 means there is no gap\n- when poll from pq, check the pre and suc of this gap exist and next to each other in the TreeSet or not. If not, discard this gap.\n```java\nclass ExamRoom {\n\n int N;\n ...
5
0
[]
0
exam-room
Best Explanation in whole of solutions 💯 | Don't Miss
best-explanation-in-whole-of-solutions-d-992k
Intuition\nThe problem requires us to seat students in such a way that they are seated as far as possible from the already seated students . \nThe challenge lie
Uday__01
NORMAL
2024-09-29T17:34:34.005087+00:00
2024-09-29T17:44:08.448043+00:00
293
false
# Intuition\nThe problem requires us to seat students in such a way that they are seated as far as possible from the already seated students . \nThe challenge lies in efficiently finding the optimal seat given potentially many occupied seats while ensuring that we can update our data structure when a student leaves. \n...
4
0
['C++']
0
exam-room
Java simple one TreeSet solution with O(N) seat and O(logN) leave
java-simple-one-treeset-solution-with-on-rrwp
Code\n\nclass ExamRoom {\n int N;\n TreeSet<Integer> seats;\n public ExamRoom(int n) {\n seats = new TreeSet<>(); // ordered set to keep track o
space_cat
NORMAL
2022-11-17T17:05:41.574158+00:00
2022-11-17T17:06:57.996668+00:00
1,746
false
# Code\n```\nclass ExamRoom {\n int N;\n TreeSet<Integer> seats;\n public ExamRoom(int n) {\n seats = new TreeSet<>(); // ordered set to keep track of students\n this.N = n;\n }\n \n public int seat() {\n int student = 0;\n \n if (seats.size() > 0) { // if at least o...
4
0
['Java']
2
exam-room
[JAVA] O(logN) seat/leave - TreeSet solution
java-ologn-seatleave-treeset-solution-by-41z2
\nclass ExamRoom {\n \n private final int max;\n private final TreeSet<Interval> available;\n private final TreeSet<Integer> taken;\n \n publi
yurokusa
NORMAL
2022-05-28T20:58:54.652849+00:00
2022-05-28T20:58:54.652879+00:00
936
false
```\nclass ExamRoom {\n \n private final int max;\n private final TreeSet<Interval> available;\n private final TreeSet<Integer> taken;\n \n public ExamRoom(int n) {\n this.max = n - 1;\n this.available = new TreeSet<>((a, b) -> {\n var distA = getMinDistance(a);\n v...
4
0
['Java']
0
exam-room
Java TreeSet Solution: Both seat() and leave() in O(log(N)), Beating the Leetcode Solution
java-treeset-solution-both-seat-and-leav-d41a
My idea is to maintain an ordered treeset of intervals rather than students. \nEach seat() will poll the first interval. \n\n\nclass Pair{\n\tInteger start;\n\t
saraband
NORMAL
2020-04-12T05:30:12.104109+00:00
2020-04-12T05:31:22.373634+00:00
1,078
false
My idea is to maintain an ordered treeset of intervals rather than students. \nEach seat() will poll the first interval. \n\n```\nclass Pair{\n\tInteger start;\n\tInteger end;\n\tint N;\n \n\tpublic int seat() {\n\t\tif (start == null) return 0;\n\t\tif (end == null) return N-1;\n\t\treturn (start + end) / 2;\n\t}\n\tp...
4
0
['Tree', 'Java']
1
exam-room
OOP design simplifies this to log(N) seat + leave. Java code attached.
oop-design-simplifies-this-to-logn-seat-vyy7m
This has better order complexity than the one mentioned in the editorial.\n\n\nclass ExamRoom {\n final int N;\n final IntervalQueue queue;\n public Ex
gauravsen
NORMAL
2019-11-26T07:13:15.934609+00:00
2019-11-26T07:13:15.934645+00:00
395
false
This has better order complexity than the one mentioned in the editorial.\n\n```\nclass ExamRoom {\n final int N;\n final IntervalQueue queue;\n public ExamRoom(int N) {\n queue = new IntervalQueue(N);\n this.N = N;\n }\n \n public int seat() {\n final Interval largestInterval = q...
4
1
[]
0
exam-room
Pyhton Solution using Heaps
pyhton-solution-using-heaps-by-abishek_9-dwxv
Solution Intuition - \n\nKeep track of the following data structure. A heap of ([ left-right, left,right]) called stack in the code below, where the students ar
abishek_90
NORMAL
2019-03-31T17:20:12.815304+00:00
2019-03-31T17:20:12.815345+00:00
631
false
Solution Intuition - \n\nKeep track of the following data structure. A heap of ([ left-right, left,right]) called stack in the code below, where the students are currently in positions left and right. \n\nOn arrival of a student, sample from this min-heap and place the new student in the middle of left and right. Some ...
4
0
[]
2
exam-room
Python PriorityQueue solution
python-priorityqueue-solution-by-pl04351-grvr
Same idea with https://leetcode.com/problems/exam-room/discuss/148595/Java-PriorityQueue-with-customized-object.-seat:-O(logn)-leave-O(n)-with-explanation. \n\n
pl04351820
NORMAL
2018-10-27T22:46:10.020001+00:00
2018-10-27T22:46:10.020066+00:00
742
false
Same idea with https://leetcode.com/problems/exam-room/discuss/148595/Java-PriorityQueue-with-customized-object.-seat:-O(logn)-leave-O(n)-with-explanation. \n\n```\nfrom heapq import heappush, heappop, heapify\nclass Interval:\n def __init__(self, l, r, N):\n self.l = l\n self.r = r\n if l == -1...
4
0
[]
2
exam-room
O(logn) for both seat and leave. Easy and well commented solution with approach.
ologn-for-both-seat-and-leave-easy-and-w-r88x
The idea is that whenever we seat a student, the student divides the interval between the next available left and right students into two parts. \n2. Have a Pri
usn001
NORMAL
2021-09-07T10:10:36.523770+00:00
2021-09-07T10:12:12.302928+00:00
446
false
1. The idea is that whenever we seat a student, the student divides the interval between the next available left and right students into two parts. \n2. Have a PriorityQueue(TreeSet here) that gives you the largest interval where a new student can sit at any point\n3. Whenever a student leaves merge the left and right ...
3
5
[]
0
exam-room
[C++] O(logn) for both leave and seat using hash map and set
c-ologn-for-both-leave-and-seat-using-ha-12g0
First let\'s define a segment to be a tuple of {start, end} indicating that the seats between start and end (inclusive) are available. When a student is taking
hoangnhat
NORMAL
2021-07-27T07:12:22.276588+00:00
2021-07-27T07:13:20.771141+00:00
458
false
First let\'s define a segment to be a tuple of `{start, end}` indicating that the seats between `start` and `end` (inclusive) are available. When a student is taking a seat, in order to maximize the distance to the closest student, we must find the **largest** available segment. Initially, all seats are empty, so the ...
3
0
[]
0
exam-room
C# O(1) Leave O(n) Seat
c-o1-leave-on-seat-by-jakobwwilson-hfko
\nVery similar to other solutions, but since no two people will ever sit in the same place at the same time, we can store our linked list nodes in a dictionary
jakobwwilson
NORMAL
2021-06-19T17:56:05.436123+00:00
2021-06-19T17:56:51.898699+00:00
248
false
\nVery similar to other solutions, but since no two people will ever sit in the same place at the same time, we can store our linked list nodes in a dictionary for quick lookup to remove them. Since we store the linked list node instead of just the value, we can do a O(1) removal because the linked list does not have t...
3
0
[]
1
exam-room
[C++] (log n) for both operations. Using two std::sets
c-log-n-for-both-operations-using-two-st-rz7b
The basic idea is we keep current people seating in set "cur" and candidates for seating next in set "cand".\nlet\'s talk a little bit about candidate set, it i
kkgmig29
NORMAL
2020-09-09T02:01:20.893643+00:00
2020-09-09T02:01:20.893697+00:00
460
false
The basic idea is we keep current people seating in set "cur" and candidates for seating next in set "cand".\nlet\'s talk a little bit about candidate set, it is a set of pair<int, int> and the first element is distance from the next person and the second element is the index. We sort this set using greater<pair<int,in...
3
0
[]
0
exam-room
Confusion in sample example
confusion-in-sample-example-by-foodie_co-xx80
can someone help me understand how student will sit at seat 2, and not at seat 6 at line marked with *****\n\nvim\nInput: ["ExamRoom","seat","seat","seat","seat
foodie_codes
NORMAL
2020-08-31T10:16:36.817167+00:00
2020-08-31T10:16:36.817213+00:00
185
false
can someone help me understand how student will sit at seat 2, and not at seat 6 at line marked with `*****`\n\n```vim\nInput: ["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]\nOutput: [null,0,9,4,2,null,5]\n\nExplanation:\nExamRoom(10) -> null\nseat() -> 0, no one is in the room, then...
3
0
[]
3
exam-room
Java Binary Search O(nlogn) seat() O(1) leave() TLE
java-binary-search-onlogn-seat-o1-leave-7a631
Haven\'t seen any other similar approaches using binary search.\nHeres a solution that tries to leverage the binary search approach, although it TLEs\n\nThe ide
yjin02
NORMAL
2020-08-18T01:55:54.537609+00:00
2020-08-19T03:18:33.717978+00:00
719
false
Haven\'t seen any other similar approaches using binary search.\nHeres a solution that tries to leverage the binary search approach, although it TLEs\n\nThe idea here is we know the max distance between student is N - 1, and the min is 0,\nso we use binary search to optimally guess that optimal seat \n\nWe do this by m...
3
0
['Binary Search', 'Java']
0
exam-room
Changing TreeMap to PriorityQueue reduced runtime by 10ms [ Java]
changing-treemap-to-priorityqueue-reduce-8czf
This is one of the good examples to understand scenarios where queue would perform better vs treeMap.\n- TreeMap always maintains the sort order in insertions a
shradha1994
NORMAL
2020-05-14T05:40:31.238673+00:00
2020-05-14T05:49:04.594652+00:00
431
false
This is one of the good examples to understand scenarios where queue would perform better vs treeMap.\n- TreeMap always maintains the sort order in insertions and deletions. Hence for every insertion and deletion, the time required would be O(logn) \n- Whereas priority queue only maintains heap property (max heap or mi...
3
0
[]
0
exam-room
Java simple O(logN) for both seat() and leave()
java-simple-ologn-for-both-seat-and-leav-zf8s
Extended the idea of zzzliu\'s solution to make it log(n) for both seat() and leave(). The idea is to basically maintain the gaps or intervals in a treeset and
abhilashv
NORMAL
2020-02-12T08:03:40.626197+00:00
2020-02-12T08:03:40.626247+00:00
495
false
Extended the idea of [zzzliu\'s](https://leetcode.com/problems/exam-room/discuss/193295/My-Elegant-Java-Solution-Beats-99.84) solution to make it log(n) for both seat() and leave(). The idea is to basically maintain the gaps or intervals in a treeset and track their boundaries in a hashmap. Code is self-explanatory. \n...
3
0
[]
0
exam-room
c++ set with lambda logN seat logN leave time
c-set-with-lambda-logn-seat-logn-leave-t-wyea
\ntypedef set<pair<int,int>, function<bool(const pair<int, int>&, const pair<int, int>&)>> customSet;\nclass ExamRoom {\nprivate:\n int N;\n customSet pq;
neal_yang
NORMAL
2019-12-31T06:50:44.319801+00:00
2019-12-31T06:51:00.319617+00:00
339
false
```\ntypedef set<pair<int,int>, function<bool(const pair<int, int>&, const pair<int, int>&)>> customSet;\nclass ExamRoom {\nprivate:\n int N;\n customSet pq;\n unordered_map<int, pair<customSet::iterator, customSet::iterator>> indexes;\npublic:\n ExamRoom(int N) {\n this->N = N;\n auto comp = ...
3
0
[]
2
exam-room
Simple C++ solution using hashmap
simple-c-solution-using-hashmap-by-emine-tviw
\nclass ExamRoom \n{\n public:\n int n;\n map<int,int> total;\n ExamRoom(int N) \n {\n n=N;\n }\n \n int seat() \n {\n
eminem18753
NORMAL
2019-09-26T16:09:11.973709+00:00
2019-09-26T16:09:11.973746+00:00
351
false
```\nclass ExamRoom \n{\n public:\n int n;\n map<int,int> total;\n ExamRoom(int N) \n {\n n=N;\n }\n \n int seat() \n {\n int index=-1;\n if(total.size()==0)\n {\n total[0]=1;\n return 0;\n }\n else\n {\n int la...
3
0
[]
0
exam-room
c++ STL set
c-stl-set-by-anilnagori-t5im
\n\nclass ExamRoom {\npublic:\n ExamRoom(int N) : N(N) {\n \n }\n \n int seat() {\n // Seat at 0 if all empty\n if (seated.empt
anilnagori
NORMAL
2018-10-30T21:33:41.720020+00:00
2018-10-30T21:33:41.720062+00:00
415
false
```\n\nclass ExamRoom {\npublic:\n ExamRoom(int N) : N(N) {\n \n }\n \n int seat() {\n // Seat at 0 if all empty\n if (seated.empty()) {\n seated.insert(0);\n return 0;\n }\n \n // Choices:\n // Seat at 0 if vacant\n // Seat at N ...
3
1
[]
0
exam-room
it's ugly but it's mine - O(log(n))
its-ugly-but-its-mine-ologn-by-marksman-mbu5
I\'m maintaing a set of pair of available seats. We also have a map of int to set>, which stores size to available ranges of that size. \n\nI specially need to
marksman_
NORMAL
2024-11-12T15:48:37.912066+00:00
2024-11-12T15:48:37.912103+00:00
149
false
I\'m maintaing a set of pair<int, int> of available seats. We also have a map of int to set<pair<int, int>>, which stores size to available ranges of that size. \n\nI specially need to handle the code for first and last seat, rest of it is pretty simple. We will either use the first range from largest size, or the firs...
2
0
['C++']
0
exam-room
Java Double TreeSet the Cleanest Both O(logn) Solution
java-double-treeset-the-cleanest-both-ol-04dl
Intuition\n Describe your first thoughts on how to solve this problem. \nCapture all the "gaps" between occupied seat pairs. With each pair of seat ids we can c
traderqiu
NORMAL
2024-02-08T02:39:28.851532+00:00
2024-02-08T02:39:28.851562+00:00
237
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCapture all the "gaps" between occupied seat pairs. With each pair of seat ids we can compute the minimum distance to neighbouring students after seating as well as the new target seat id.\n# Approach\n<!-- Describe your approach to solvi...
2
0
['Ordered Set', 'Java']
0
exam-room
Solution
solution-by-deleted_user-9deu
C++ []\nclass ExamRoom {\npublic:\n\tstruct gap_t {\n\t\tint get_best_seat(int n) const {\n\t\t\tif (start == 0) {\n\t\t\t\treturn 0;\n\t\t\t} if (start + size
deleted_user
NORMAL
2023-05-07T05:06:14.482179+00:00
2023-05-07T06:05:10.035923+00:00
1,994
false
```C++ []\nclass ExamRoom {\npublic:\n\tstruct gap_t {\n\t\tint get_best_seat(int n) const {\n\t\t\tif (start == 0) {\n\t\t\t\treturn 0;\n\t\t\t} if (start + size == n) {\n\t\t\t\treturn n - 1;\n\t\t\t} return start + size / 2 - (size % 2 ^ 1);\n\t\t}\n\t\tint max_seat_dist(int n) const {\n\t\t\tif (start == 0) {\n\t\t...
2
0
['C++', 'Java', 'Python3']
0
exam-room
C# Solution || Easy Solution
c-solution-easy-solution-by-mohamedabdel-rl67
Complexity\n- Time complexity:\nRemove => O(1), Seat => O(N)\n- Space complexity:\nO(N)\n# Code\n\npublic class ExamRoom {\n SortedSet<int> reserved;\n in
mohamedAbdelety
NORMAL
2023-03-12T07:36:02.307844+00:00
2023-03-12T07:36:02.307893+00:00
104
false
# Complexity\n- Time complexity:\nRemove => O(1), Seat => O(N)\n- Space complexity:\nO(N)\n# Code\n```\npublic class ExamRoom {\n SortedSet<int> reserved;\n int N;\n public ExamRoom(int n) {\n reserved = new SortedSet<int>();\n N = n - 1;\n } \n public int Seat() { \n int cur = 0, d...
2
0
['Ordered Set', 'C#']
0
exam-room
Python Very Easy solution Using Lists
python-very-easy-solution-using-lists-by-0inv
Runtime: 364 ms, faster than 37.72% of Python3 online submissions for Exam Room.\nMemory Usage: 14.2 MB, less than 98.78% of Python3 online submissions for Exam
reaper_27
NORMAL
2022-03-02T11:22:38.928669+00:00
2022-03-02T11:22:38.928704+00:00
1,301
false
**Runtime: 364 ms, faster than 37.72% of Python3 online submissions for Exam Room.\nMemory Usage: 14.2 MB, less than 98.78% of Python3 online submissions for Exam Room.**\n```\nclass ExamRoom:\n\n def __init__(self, n: int):\n self.n = n\n self.lst = []\n\n def seat(self) -> int:\n if self.ls...
2
0
['Python', 'Python3']
1
exam-room
[Java] Only one TreeSet solution | O(N) for seat() & O(logN) for leave()
java-only-one-treeset-solution-on-for-se-ybh9
\nclass ExamRoom {\n \n TreeSet<Integer> set;\n int n;\n\n public ExamRoom(int n) {\n set = new TreeSet<>();\n this.n = n-1;\n }\n
anandkulkarni147
NORMAL
2022-01-31T10:26:49.513071+00:00
2022-02-05T06:03:51.384378+00:00
899
false
```\nclass ExamRoom {\n \n TreeSet<Integer> set;\n int n;\n\n public ExamRoom(int n) {\n set = new TreeSet<>();\n this.n = n-1;\n }\n \n public int seat() {\n //Add first seat if all seats are empty\n if (set.size() == 0) {\n set.add(0);\n return 0;...
2
0
['Tree', 'Binary Tree', 'Ordered Set', 'Java']
0
exam-room
C# SortedSet solution
c-sortedset-solution-by-newbiecoder1-aegq
\n\n\npublic class ExamRoom {\n\n private SortedSet<int> seats;\n private int N;\n \n public ExamRoom(int n) {\n \n seats = new Sorted
newbiecoder1
NORMAL
2022-01-17T22:43:57.447116+00:00
2022-01-17T23:03:41.451669+00:00
185
false
![image](https://assets.leetcode.com/users/images/b2326164-b073-497b-84e7-db7d0550976d_1642460586.7792268.png)\n\n```\npublic class ExamRoom {\n\n private SortedSet<int> seats;\n private int N;\n \n public ExamRoom(int n) {\n \n seats = new SortedSet<int>();\n N = n;\n }\n \n /...
2
0
[]
0
exam-room
C++ simple solution using vectors
c-simple-solution-using-vectors-by-maitr-ff1i
You want to simulate an exam room where every next student seats furthest from its closest neighbour. So create a vector that will store all the seats filled un
maitreya47
NORMAL
2021-08-21T20:29:25.163910+00:00
2021-08-21T20:29:25.163961+00:00
923
false
You want to simulate an exam room where every next student seats furthest from its closest neighbour. So create a vector that will store all the seats filled until now. Idea is to find the maximum distance available between any two students and seat the current student in the middle of that gap.\nFor example, students ...
2
0
['C', 'C++']
0
exam-room
C++ Solution
c-solution-by-oqaistanvir-jjl2
```\nclass ExamRoom {\nprivate:\n setseats;\n int capacity;\npublic:\n ExamRoom(int n) {\n capacity=n;\n }\n \n int seat() {\n i
oqaistanvir
NORMAL
2021-07-15T10:56:29.142744+00:00
2021-07-15T10:56:29.142785+00:00
224
false
```\nclass ExamRoom {\nprivate:\n set<int>seats;\n int capacity;\npublic:\n ExamRoom(int n) {\n capacity=n;\n }\n \n int seat() {\n if(seats.size()==0){\n seats.insert(0);\n return 0;\n }\n int slow=0,fast=0,mid_dist=0,mid;\n bool first=true;\n ...
2
0
[]
0
exam-room
JavaScript Simple O(n) Seat and Leave Solution With Detailed Comments
javascript-simple-on-seat-and-leave-solu-xkk4
\n/**\n * @param {number} n\n */\nvar ExamRoom = function(n) {\n this.n = n\n this.list = []\n};\n\n/**\n * @return {number}\n */\nExamRoom.prototype.seat
crystallili
NORMAL
2021-06-17T07:04:07.177415+00:00
2021-06-17T07:04:42.122457+00:00
501
false
```\n/**\n * @param {number} n\n */\nvar ExamRoom = function(n) {\n this.n = n\n this.list = []\n};\n\n/**\n * @return {number}\n */\nExamRoom.prototype.seat = function() {\n // if nothing in the list, seat the first student at index 0.\n if(this.list.length === 0){\n this.list.push(0)\n retur...
2
0
['JavaScript']
1
exam-room
Java TreeSet
java-treeset-by-hero18-ni4b
\nclass ExamRoom {\n private int N;\n private TreeSet<Integer> treeSet;\n public ExamRoom(int N) {\n this.N = N;\n this.treeSet = new Tre
hero18
NORMAL
2020-12-26T20:12:48.378088+00:00
2020-12-26T20:12:48.378121+00:00
222
false
```\nclass ExamRoom {\n private int N;\n private TreeSet<Integer> treeSet;\n public ExamRoom(int N) {\n this.N = N;\n this.treeSet = new TreeSet<>();\n }\n \n public int seat() {\n int p = 0;\n if(treeSet.size() > 0) {\n int dist = treeSet.first();\n I...
2
0
[]
0
exam-room
Python heapq solution with comments, seat O(logn) leave O(n)
python-heapq-solution-with-comments-seat-rc5b
\nimport heapq\nclass ExamRoom(object):\n\n def dist(self, x, y):\n # This handles the case when there are 0 or 1 students.\n if x == -1 or y =
csd2592
NORMAL
2020-05-20T23:54:40.416768+00:00
2020-05-20T23:54:40.416801+00:00
338
false
```\nimport heapq\nclass ExamRoom(object):\n\n def dist(self, x, y):\n # This handles the case when there are 0 or 1 students.\n if x == -1 or y == self.N:\n return abs(y - 1 - x)\n else:\n # This will be the min diff when we decide to seat at (y + x) / 2.\n retu...
2
0
[]
0
exam-room
Swift Solution beats 100%
swift-solution-beats-100-by-twho-m27d
swift\nclass ExamRoom {\n var capacity = 0\n var seats = [Int]()\n\n init(_ N: Int) {\n capacity = N\n }\n \n func seat() -> Int {\n
twho
NORMAL
2019-06-14T20:28:09.523891+00:00
2019-06-15T18:30:24.428954+00:00
251
false
```swift\nclass ExamRoom {\n var capacity = 0\n var seats = [Int]()\n\n init(_ N: Int) {\n capacity = N\n }\n \n func seat() -> Int {\n if seats.count == 0 {\n seats.append(0)\n return 0\n } else if seats.count == capacity {\n return -1\n } ...
2
0
[]
0
exam-room
JavaScript 100% Solution with Comments
javascript-100-solution-with-comments-by-qu63
\n/**\n * @param {number} N\n */\nvar ExamRoom = function(N) {\n this.len=N;//For Length\n this.seats=new Array();//For Storing Used Seats (Sorted)\n};\n\
prajwalroxman
NORMAL
2019-06-13T14:07:24.095926+00:00
2019-06-13T14:07:24.095958+00:00
348
false
```\n/**\n * @param {number} N\n */\nvar ExamRoom = function(N) {\n this.len=N;//For Length\n this.seats=new Array();//For Storing Used Seats (Sorted)\n};\n\n/**\n * @return {number}\n */\nExamRoom.prototype.seat = function() {\n \n /*If all seats empty*/\n if(this.seats.length<=0){\n ...
2
0
[]
0
exam-room
Python Bisect Insort
python-bisect-insort-by-infinute-sqvk
Use a sorted list self.occupied to keep track of everyone\'s position. Everytime a new person comes in, find the best location between left and right and seat t
infinute
NORMAL
2019-03-14T04:50:01.856896+00:00
2019-03-14T04:50:01.856966+00:00
847
false
Use a sorted list `self.occupied` to keep track of everyone\'s position. Everytime a new person comes in, find the best location between `left` and `right` and seat the person in `(left + right) // 2` using `bisect.insort()`. Don\'t forget the consider the positions before the first person `self.occupied[0]` and after ...
2
1
['Python']
0
exam-room
Java clean O(log n) seat O(log n) leave
java-clean-olog-n-seat-olog-n-leave-by-d-h5ss
Use a TreeMap to find longest distance between students\nUse a HashMap to find distance to previous/next student\n\nTreeMap lastKey() is O(long n), no need to t
dancingpizza
NORMAL
2019-01-29T08:01:06.213597+00:00
2019-01-29T08:01:06.213666+00:00
442
false
Use a TreeMap to find longest distance between students\nUse a HashMap to find distance to previous/next student\n\nTreeMap lastKey() is O(long n), no need to traverse the whole tree\n```\nclass ExamRoom {\n private int n,sift=1000_000_000;\n private Map<Integer,int[]>m;\n private TreeMap<Long,Integer>map;\n ...
2
1
[]
1
exam-room
Java TreeSet Solution
java-treeset-solution-by-adw12382-9fv3
\nclass ExamRoom {\n // TreeSet keeps numbers in ascending order\n private TreeSet<Integer> seats = new TreeSet<>();\n private int length;\n \n p
adw12382
NORMAL
2018-10-19T07:17:42.066082+00:00
2018-10-19T07:19:27.716246+00:00
299
false
```\nclass ExamRoom {\n // TreeSet keeps numbers in ascending order\n private TreeSet<Integer> seats = new TreeSet<>();\n private int length;\n \n public ExamRoom(int N) {\n this.length = N;\n }\n \n public int seat() {\n // First student always sits at seats[0]\n if(seats.s...
2
0
[]
0
exam-room
[Java] Clean code
java-clean-code-by-postyfranky-7frs
Clean Code means clear mind. I love clean code.\n\nclass ExamRoom {\n \n private static class Interval implements Comparable<Interval> {\n private
PostyFranky
NORMAL
2018-10-06T00:29:11.229743+00:00
2018-10-08T16:25:02.900178+00:00
490
false
Clean Code means clear mind. I love clean code.\n```\nclass ExamRoom {\n \n private static class Interval implements Comparable<Interval> {\n private final int start;\n private final int end;\n private final int length;\n private Interval(int start, int end, int length) {\n ...
2
0
[]
3
exam-room
C++ set solution with detailed comments
c-set-solution-with-detailed-comments-by-p8az
\nclass ExamRoom {\npublic:\n \n set<int> locations;\n int numOfStudents;\n \n ExamRoom(int N):numOfStudents(N){\n }\n \n int seat() {\n
galster
NORMAL
2018-10-05T19:00:38.217583+00:00
2018-10-05T19:00:38.217648+00:00
257
false
```\nclass ExamRoom {\npublic:\n \n set<int> locations;\n int numOfStudents;\n \n ExamRoom(int N):numOfStudents(N){\n }\n \n int seat() {\n int dist = 0;\n int studentToSit = 0;\n \n //no students - just insert 0\n if(!locations.empty()){\n \n ...
2
0
[]
0
exam-room
log(n) for both seat and leave in c++
logn-for-both-seat-and-leave-in-c-by-sil-8hdr
The basic idea is we build a tree set in which distance means that the seat\'s distance to its cloest seat(which already be taken), and pos means the seat\'s po
silvernarcissus
NORMAL
2018-06-17T03:25:37.127247+00:00
2018-06-17T03:25:37.127247+00:00
559
false
The basic idea is we build a tree set<distance, pos> in which distance means that the seat\'s distance to its cloest seat(which already be taken), and pos means the seat\'s position. When we insert a seat what we should do is add 2 new candidate seat in to the tree. When we remove a seat what we should do is remove 2 c...
2
0
[]
0
exam-room
Simple TreeSet solution with reasoning
simple-treeset-solution-with-reasoning-b-pclr
Intuition\n Describe your first thoughts on how to solve this problem. \nTreeSet can give us lower and higher elements in log n time. We utilise the same data s
b23karali
NORMAL
2024-11-02T08:56:31.324300+00:00
2024-11-02T08:56:31.324321+00:00
86
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTreeSet can give us lower and higher elements in log n time. We utilise the same data structure here.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. If no seats are occupied sit at 0\n2. Else find all compute t...
1
0
['Java']
0
exam-room
log(n)
logn-by-ayush2375-avkf
Intuition\n Describe your first thoughts on how to solve this problem. \n- Maintain occupied pos and interval in the set. \n- Add a very large interval in the s
ayush2375
NORMAL
2024-08-15T13:47:16.149488+00:00
2024-08-15T13:47:16.149518+00:00
36
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Maintain occupied pos and interval in the set. \n- Add a very large interval in the starting to handle edge cases. \n- If an interval lower or higher boundary does not exist, person will be placed on either of the boundary otherwise in ...
1
0
['Java']
0
exam-room
Prettiest solution
prettiest-solution-by-sheshhh-tpws
Intuition\n Describe your first thoughts on how to solve this problem. \nWe use a treeset to maintain the order of gaps created each time when inserting a perso
sheshhh
NORMAL
2024-07-31T13:56:18.800502+00:00
2024-07-31T13:56:18.800523+00:00
38
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe use a treeset to maintain the order of gaps created each time when inserting a person , in form of arrays those gaps will be sorted in decreasing order with left and right index where left index is sorted in inceasing order because whe...
1
0
['Hash Table', 'Java']
1
exam-room
Using sorted list O(log n) solution
using-sorted-list-olog-n-solution-by-fan-zpll
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTo solve this problem, we need to implement an ExamRoom class that effect
fangdream
NORMAL
2024-05-27T14:34:19.847436+00:00
2024-05-27T14:34:19.847453+00:00
250
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTo solve this problem, we need to implement an ExamRoom class that effectively manages seat assignments to maximize the distance between students and properly handles students leaving. Here\'s how we can achieve that:\n\n###...
1
1
['Python3']
2
exam-room
✅ C++ | BEATS 98.74% | SET
c-beats-9874-set-by-minhuchiha-g2ic
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(\log{n})\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\n
minhuchiha
NORMAL
2023-10-03T23:32:17.342987+00:00
2023-10-03T23:32:50.540171+00:00
205
false
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(\\log{n})$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\nclass ExamRoom {\nprivate:\n int N;\n struct Inv {\n int l, r, n;\n Inv(int l, int r, int n) :...
1
0
['C++']
0
exam-room
TreeSet Solution Design
treeset-solution-design-by-shree_govind_-rj2n
\n\n# Code\n\nclass ExamRoom {\n\n int capacity;\n TreeSet<Integer> ts;\n\n//TC:-O(1)\n public ExamRoom(int n) {\n this.capacity = n;\n t
Shree_Govind_Jee
NORMAL
2023-09-30T05:58:23.085931+00:00
2023-09-30T05:58:23.085958+00:00
83
false
\n\n# Code\n```\nclass ExamRoom {\n\n int capacity;\n TreeSet<Integer> ts;\n\n//TC:-O(1)\n public ExamRoom(int n) {\n this.capacity = n;\n this.ts = new TreeSet<>();\n }\n \n\n// TC:- O(N)\n public int seat() {\n int count=0;\n if(ts.size() > 0){\n Integer prev = nu...
1
0
['Design', 'Heap (Priority Queue)', 'Ordered Set', 'Java']
1
exam-room
Python3 Solution
python3-solution-by-kkkkshi-htdn
Intuition\nFirst, initialize the heap with two fake seats, -1 and N. If we hit -1, we get the set 0. If we hit N, we get the set N-1. The main function is to us
KKKKSHI
NORMAL
2023-08-06T02:12:12.249140+00:00
2023-08-06T02:12:12.249160+00:00
121
false
# Intuition\nFirst, initialize the heap with two fake seats, -1 and N. If we hit -1, we get the set 0. If we hit N, we get the set N-1. The main function is to use a heap to organize the distance. We pop the minimum distance between two points each time if we need to add a person. We break the length into half and put ...
1
0
['Python3']
0
exam-room
C++ Map Solution | Detailed Explanation
c-map-solution-detailed-explanation-by-y-h4l7
Intuition\n Describe your first thoughts on how to solve this problem. \nAs the questions asks about longest distance betweeen 2 students, we need to store the
YashGadia36
NORMAL
2023-07-27T11:12:41.995688+00:00
2023-07-27T11:12:41.995718+00:00
652
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs the questions asks about longest distance betweeen 2 students, we need to store the indexes where the previous students are currently sitting. So, we can think of `map` data structure.\nWe ierate over the map for each call for `seat` a...
1
0
['Ordered Map', 'C++']
1
exam-room
C++ Using Set -- Basic approach (No optimizations)
c-using-set-basic-approach-no-optimizati-q8tw
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst approach one can think of. No algorithms, just implementation using appropriate D
black_mamba666
NORMAL
2023-05-31T07:05:39.224827+00:00
2023-05-31T07:05:39.224875+00:00
518
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst approach one can think of. No algorithms, just implementation using appropriate DS.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCalculating correct postion iteratively using brute force.\n\n<!-- # Complex...
1
0
['C++']
0
exam-room
Swift linear solution
swift-linear-solution-by-ericdrew08-gg2z
Code\n\n\nclass ExamRoom {\n // seated is an array of seats taken\n // a sorted set may be faster\n var seated: [Int]\n let n: Int\n\n init(_ n:
ericdrew08
NORMAL
2023-03-12T21:39:56.125741+00:00
2023-03-12T21:39:56.125779+00:00
652
false
# Code\n```\n\nclass ExamRoom {\n // seated is an array of seats taken\n // a sorted set may be faster\n var seated: [Int]\n let n: Int\n\n init(_ n: Int) {\n self.n = n\n seated = []\n }\n \n func seat() -> Int {\n if seated.isEmpty {\n seated.append(0)\n ...
1
0
['Swift']
1
exam-room
Fully Explained: Python Fast O(log occupied) seat and leave
fully-explained-python-fast-olog-occupie-yl4e
Background\n Describe your first thoughts on how to solve this problem. \n- This problem is similar to 849. Maximize Distance to Closest Person but with some di
PabloLION
NORMAL
2023-03-02T06:56:35.436457+00:00
2023-04-18T04:49:45.526643+00:00
527
false
# Background\n<!-- Describe your first thoughts on how to solve this problem. -->\n- This problem is similar to [849. Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person/description/) but with some differences:\n\n 1. input comes in a stream instead of a single inpu...
1
0
['Python3']
0
exam-room
c++ | easy | faster and easy
c-easy-faster-and-easy-by-venomhighs7-qr5s
\n\n# Code\n\nstruct IntV\n{\n static int N;\n int l, r;\n IntV(int l, int r) : l(l), r(r) {}\n int getD() const\n {\n if(l == 0) return r
venomhighs7
NORMAL
2022-10-30T04:40:39.449350+00:00
2022-10-30T04:40:39.449388+00:00
634
false
\n\n# Code\n```\nstruct IntV\n{\n static int N;\n int l, r;\n IntV(int l, int r) : l(l), r(r) {}\n int getD() const\n {\n if(l == 0) return r;\n if(r == N - 1) return N - 1 - l;\n if(r < l) return -1;\n else return (r - l) / 2;\n }\n int getP() const\n {\n if(l...
1
1
['C++']
1
exam-room
C++✅ || Easy || Solution
c-easy-solution-by-prinzeop-e9hr
\nclass ExamRoom {\nprivate:\n\tvector<int> v;\n\tint sz;\npublic:\n\tExamRoom(int n) {\n\t\tsz = n;\n\t}\n\n\tint seat() {\n\t\tif (v.size() == 0) {\n\t\t\tv.p
casperZz
NORMAL
2022-08-16T12:14:25.284112+00:00
2022-08-16T12:14:25.284158+00:00
224
false
```\nclass ExamRoom {\nprivate:\n\tvector<int> v;\n\tint sz;\npublic:\n\tExamRoom(int n) {\n\t\tsz = n;\n\t}\n\n\tint seat() {\n\t\tif (v.size() == 0) {\n\t\t\tv.push_back(0);\n\t\t\treturn 0;\n\t\t}\n\t\tint maxi = max(v[0], sz - 1 - v.back());\n\t\tfor (int i = 0; i < v.size() - 1; ++i) maxi = max(maxi, (v[i + 1] - v...
1
1
['C']
0
exam-room
My solution using Heap and TreeMap
my-solution-using-heap-and-treemap-by-ja-oe31
Used concept (-1, N) and different distance measuring from below link.\nhttps://leetcode.com/problems/exam-room/discuss/404676/Java-Two-TreeSets-Solution.-Both-
jaehoonlee88
NORMAL
2022-08-14T02:08:12.888686+00:00
2022-08-14T02:09:13.277544+00:00
374
false
Used concept (-1, N) and different distance measuring from below link.\nhttps://leetcode.com/problems/exam-room/discuss/404676/Java-Two-TreeSets-Solution.-Both-Seat-and-Leave-O(log-n)-Time-Complexity\n\n\n```\n// 0 to x1\n// xn to xn+1\n// xn to last\n\nclass ExamRoom {\n\n int N;\n class Interval {\n in...
1
0
[]
1
exam-room
[Python] O(logn) both seat and leave. Easier to understand
python-ologn-both-seat-and-leave-easier-uibvw
The intuition is that, \n when to seat, use a heap to figure out the seat with max distance to neighbor.\n when to leave, use a seat to neighbor dict to get lef
subtlecold
NORMAL
2022-08-12T07:06:26.132998+00:00
2022-08-12T07:14:25.756265+00:00
330
false
The intuition is that, \n* when to seat, use a heap to figure out the seat with max distance to neighbor.\n* when to leave, use a seat to neighbor dict to get left and right neighbors, then update both neighbors pointing to each other, then remove this student from dict.\n\nOf course, we also need to update neighbors w...
1
0
[]
1
exam-room
C# | Quick learner | Two practices
c-quick-learner-two-practices-by-jianmin-xfwu
July 21, 2022\n\nProblem statement:\nThere is an exam room with n seats in a single row labeled from 0 to n - 1.\n\nWhen a student enters the room, they must si
jianminchen
NORMAL
2022-07-21T21:26:20.680756+00:00
2022-08-04T23:11:15.824080+00:00
111
false
July 21, 2022\n\nProblem statement:\nThere is an exam room with n seats in a single row labeled from 0 to n - 1.\n\nWhen a student enters the room, they must sit in the seat that maximizes the distance to the closest person. If there are multiple such seats, they sit in the seat with the lowest number. If no one is in ...
1
0
[]
0
exam-room
Java || Detail explanation of the solution || Better variable names || TC & SC explained
java-detail-explanation-of-the-solution-eihrj
// TC : Adding/Removing from TreeSet takes O(logN) times\n// SC : O(N)\n\nclass ExamRoom {\n\n TreeSet<Integer> seatTakenAtI; // TreeSet because of lower() a
ICodeToSurvive
NORMAL
2022-07-14T02:24:07.499702+00:00
2022-07-14T02:24:07.499742+00:00
280
false
// TC : Adding/Removing from TreeSet takes O(logN) times\n// SC : O(N)\n```\nclass ExamRoom {\n\n TreeSet<Integer> seatTakenAtI; // TreeSet because of lower() and higher() methods\n TreeSet<Intervals> nextIntervalToFill; // Priority Queue could also be used here with custom Comparator (removing any obj other than...
1
0
[]
0
exam-room
Most Complex Question Till Now (soln)
most-complex-question-till-now-soln-by-t-4f2z
If u can understand this solution easily then u should stop dude...XD :)\n`\nclass ExamRoom {\npublic:\n set<int> s;\n\n int n;\n ExamRoom(int N) {\n
tanuj_1099
NORMAL
2022-06-19T17:47:35.585129+00:00
2022-06-19T17:47:35.585175+00:00
378
false
If u can understand this solution easily then u should stop dude...XD :)\n```\nclass ExamRoom {\npublic:\n set<int> s;\n\n int n;\n ExamRoom(int N) {\n n=N;\n \n }\n \n int seat() {\n if(s.empty())\n {\n s.insert(0);\n return 0;\n }\n int x...
1
0
['C', 'Ordered Set']
1
exam-room
Java TreeSet
java-treeset-by-tomythliu-s2zh
\n\n\nclass ExamRoom {\n int n; \n \n class Interval {\n int l;\n int r;\n int dis;\n boolean isStart;\n boolean
tomythliu
NORMAL
2022-06-14T00:38:14.004699+00:00
2022-06-14T00:38:14.004730+00:00
159
false
```\n\n\nclass ExamRoom {\n int n; \n \n class Interval {\n int l;\n int r;\n int dis;\n boolean isStart;\n boolean isEnd;\n \n Interval(int l, int r) {\n this.l = l;\n this.r = r;\n if(l == -1) {\n this.dis = r...
1
0
[]
0
exam-room
C++ || Set and Vector
c-set-and-vector-by-be_quick-ulbg
\nstruct interval{\n static int tot;\n int l,r;\n int dist;\n\n interval(int l,int r){\n this->l = l;\n this->r = r;\n if(l==0)
be_quick
NORMAL
2022-04-01T20:19:24.344859+00:00
2022-04-01T20:19:41.232240+00:00
229
false
```\nstruct interval{\n static int tot;\n int l,r;\n int dist;\n\n interval(int l,int r){\n this->l = l;\n this->r = r;\n if(l==0)dist = r;\n else if((r+1)==tot)dist = r-l;\n else dist = (r-l)/2;\n }\n};\n\nint interval::tot = 0;\nauto comp = [](interval a,interval b)->...
1
0
['Binary Tree', 'Ordered Set']
0
exam-room
C++ | faster than 97%
c-faster-than-97-by-arvinleetcode-8yjo
The not so difficult solution is to use a sliding window (2 pointer) approach to find the next location each time a seat is asked. That would take O(n) and ther
arvinleetcode
NORMAL
2022-01-16T10:28:42.589171+00:00
2022-01-16T10:56:54.026492+00:00
368
false
The not so difficult solution is to use a sliding window (2 pointer) approach to find the next location each time a seat is asked. That would take O(n) and there is a leetcode for that. First tried and that approach exceeds the time limit for the last test cases. So O(n) for each command is not acceptable.\nThe solutio...
1
0
[]
0
exam-room
Kotlin - Treeset
kotlin-treeset-by-yuanchac-bjbo
\nclass ExamRoom(n: Int) {\n\n val seated = TreeSet<Int>()\n val capacity = n\n \n fun seat(): Int {\n if(seated.isEmpty()){\n sea
yuanchac
NORMAL
2021-10-04T13:41:09.151061+00:00
2021-10-04T13:41:09.151135+00:00
90
false
```\nclass ExamRoom(n: Int) {\n\n val seated = TreeSet<Int>()\n val capacity = n\n \n fun seat(): Int {\n if(seated.isEmpty()){\n seated.add(0)\n return 0\n }\n \n var seatNum = 0\n \n var maxDistance = seated.first()\n var pre = -1\n ...
1
0
[]
0
exam-room
Python seat logN, leave logN solution
python-seat-logn-leave-logn-solution-by-t5lgd
The idea is to maintain valid intervals in the dictionary d. Key is seat and value is intervals that contain key. For example, students have seats 0,4,9, then t
arsamigullin
NORMAL
2021-09-24T08:10:32.671088+00:00
2021-09-24T23:58:50.274288+00:00
1,796
false
The idea is to maintain valid intervals in the dictionary d. Key is seat and value is intervals that contain key. For example, students have seats 0,4,9, then the dictionary with valid intervals is\n```\nintervals = {0:{(0,4)}, 4:{(0,4),(4,9)}, 9:{(4,9)}}\n```\nEvery value in intervals is the set of length at most 2 be...
1
0
['Heap (Priority Queue)', 'Python', 'Python3']
3
exam-room
Maximum of Difference Between Allotted Seats.
maximum-of-difference-between-allotted-s-90tp
Take Difference between Neighbouring Alloted Seats. The Max of difference will be the required Distance for each New Seat.\n\nclass ExamRoom:\n\n def __init_
adarsh_gogreen
NORMAL
2021-06-13T11:05:21.607410+00:00
2021-06-13T11:05:21.607470+00:00
148
false
Take Difference between Neighbouring Alloted Seats. The Max of difference will be the required Distance for each New Seat.\n```\nclass ExamRoom:\n\n def __init__(self, n: int):\n self.c=0\n self.akk=[]\n self.n=n\n def seat(self) -> int:\n if(self.c==0):\n self.akk.append(0)...
1
0
[]
0
exam-room
Python Indexed Priority Queue O(logN) seat(), O(logN) leave()
python-indexed-priority-queue-ologn-seat-xqnp
Inspired by William Fiset\'s binary heap indexed priority queue implementation:\n\nhttps://www.youtube.com/watch?v=jND_WJ8r7FE&t=342s\n\nAlso took some notes fr
alando46
NORMAL
2021-01-19T05:14:03.774250+00:00
2021-01-19T05:18:41.602891+00:00
734
false
Inspired by William Fiset\'s binary heap indexed priority queue implementation:\n\nhttps://www.youtube.com/watch?v=jND_WJ8r7FE&t=342s\n\nAlso took some notes from @spatar \'s implementation:\n\nhttps://leetcode.com/problems/exam-room/discuss/139941/Python-O(log-n)-time-for-both-seat()-and-leave()-with-heapq-and-dicts-D...
1
1
['Heap (Priority Queue)']
0
exam-room
Java hashmap and treeset solution faster than 81% with seat O(logN) and leave O(1))
java-hashmap-and-treeset-solution-faster-zarx
\nclass ExamRoom {\n\n int count = 0;\n int capability;\n TreeSet<int[]> pq; \n Map<Integer, Pair<Integer, Integer>> map; // key is seat itself, va
yzhou78
NORMAL
2020-11-14T19:36:03.957385+00:00
2020-11-14T19:42:15.212098+00:00
188
false
```\nclass ExamRoom {\n\n int count = 0;\n int capability;\n TreeSet<int[]> pq; \n Map<Integer, Pair<Integer, Integer>> map; // key is seat itself, value is pair which record its\' left and right neighbors\n \n public ExamRoom(int N) {\n this.capability = N;\n this.count = 0;\n t...
1
0
[]
0
exam-room
[Python] O(logN) time for both seat() and leave() Using Segment Tree
python-ologn-time-for-both-seat-and-leav-plum
\nclass SegmentTree(object):\n def __init__(self, start, end, size, rank=1):\n self.rank = rank # rank is the number of leaves of this segment tree,
shoomoon
NORMAL
2020-09-10T01:48:20.765258+00:00
2020-09-10T01:48:20.765297+00:00
273
false
```\nclass SegmentTree(object):\n def __init__(self, start, end, size, rank=1):\n self.rank = rank # rank is the number of leaves of this segment tree, to keep the segment tree balance and reduce the depth of the tree\n self.start = start\n self.end = end\n self.left = None\n self...
1
0
[]
1
exam-room
[Java] O(log n) for both operations using TreeSet
java-olog-n-for-both-operations-using-tr-3p66
\nclass ExamRoom {\n class Interval implements Comparable<Interval> {\n public int L, R, dist, index;\n Interval(int L, int R) {\n t
shk10
NORMAL
2020-09-07T02:32:48.397450+00:00
2020-09-07T02:32:48.397541+00:00
219
false
```\nclass ExamRoom {\n class Interval implements Comparable<Interval> {\n public int L, R, dist, index;\n Interval(int L, int R) {\n this.L = L;\n this.R = R;\n if(L == 0) {\n dist = R - L; index = L;\n } else if(R == N - 1) {\n ...
1
0
[]
0
exam-room
[Python] logN logN SortedList
python-logn-logn-sortedlist-by-cheol-uewe
python\nfrom sortedcontainers import SortedList\n\n\nclass ExamRoom:\n\n def __init__(self, N: int):\n self.starts = dict()\n self.ends = dict(
cheol
NORMAL
2020-08-18T16:39:28.575562+00:00
2020-08-20T11:04:54.590086+00:00
300
false
```python\nfrom sortedcontainers import SortedList\n\n\nclass ExamRoom:\n\n def __init__(self, N: int):\n self.starts = dict()\n self.ends = dict()\n # Alternative Heap \n self.fragments = SortedList()\n self.n = N\n \n self.add_fragment((0, N-1))\n \n def dista...
1
0
[]
1
exam-room
Golang 8ms 100% Solution
golang-8ms-100-solution-by-tjucoder-7eqc
go\ntype ExamRoom struct {\n\tseat int\n\tstudent []int\n}\n\nfunc Constructor(N int) ExamRoom {\n\treturn ExamRoom{\n\t\tseat: N,\n\t\tstudent: []int{},\
tjucoder
NORMAL
2020-08-14T13:53:44.385913+00:00
2020-08-14T13:53:44.385948+00:00
219
false
```go\ntype ExamRoom struct {\n\tseat int\n\tstudent []int\n}\n\nfunc Constructor(N int) ExamRoom {\n\treturn ExamRoom{\n\t\tseat: N,\n\t\tstudent: []int{},\n\t}\n}\n\nfunc (er *ExamRoom) Seat() int {\n\tif len(er.student) == 0 {\n\t\ter.student = append(er.student, 0)\n\t\treturn 0\n\t}\n\tseat, distance, index ...
1
0
['Go']
0
exam-room
C++ Solution
c-solution-by-indrajohn-e22y
\nclass ExamRoom {\npublic:\n int num;\n set<int> sec;\n ExamRoom(int N) {\n num = N;\n }\n \n int seat() {\n if (sec.size() ==
indrajohn
NORMAL
2020-07-27T09:50:50.139745+00:00
2020-07-27T09:50:50.139791+00:00
311
false
```\nclass ExamRoom {\npublic:\n int num;\n set<int> sec;\n ExamRoom(int N) {\n num = N;\n }\n \n int seat() {\n if (sec.size() == 0){\n sec.insert(0);\n return 0;\n } else if (sec.size() == 1) {\n set<int> :: iterator it = sec.begin();\n ...
1
0
[]
0
exam-room
Elegant O(LogN) C++ solution with set and map
elegant-ologn-c-solution-with-set-and-ma-bn4q
\nstruct Interval {\n Interval(int _left, int _right, int _n) \n : left(_left), \n right(_right), \n N(_n) {\n \n } \n
etotuan
NORMAL
2020-06-22T04:08:52.228520+00:00
2020-06-22T04:08:52.228575+00:00
212
false
```\nstruct Interval {\n Interval(int _left, int _right, int _n) \n : left(_left), \n right(_right), \n N(_n) {\n \n } \n \n int get_minimax() const {\n return (left<0) ? ((right < 0) ? N - 1 : right) \n : ((right < 0) ? N - 1 - left \n ...
1
0
[]
0
exam-room
O(log n) for both seat and leave, but it is harder than most hard problems
olog-n-for-both-seat-and-leave-but-it-is-f38a
Idea: use a heap to maintain the vacant segment, but there are so many tricky things to handle.\n\n\nclass Segment:\n def __init__(self, MAX, start, end):\n
fang15
NORMAL
2020-06-07T14:33:21.901602+00:00
2020-06-07T14:33:21.901650+00:00
218
false
Idea: use a heap to maintain the vacant segment, but there are so many tricky things to handle.\n\n```\nclass Segment:\n def __init__(self, MAX, start, end):\n self.MAX = MAX # the most right spot\n self.start = start\n self.end = end\n self.status = True\n \n @property\n def len...
1
0
[]
0
exam-room
Simple C++ solution
simple-c-solution-by-caspar-chen-hku-5swi
\nclass ExamRoom {\npublic:\n \n vector<int> seats;\n int num;\n \n ExamRoom(int N) {\n num = N;\n }\n \n int seat() {\n i
caspar-chen-hku
NORMAL
2020-05-20T15:47:18.496044+00:00
2020-05-20T15:47:18.496097+00:00
282
false
```\nclass ExamRoom {\npublic:\n \n vector<int> seats;\n int num;\n \n ExamRoom(int N) {\n num = N;\n }\n \n int seat() {\n if (seats.empty()){\n seats.push_back(0); return 0;\n }else{\n int maxSeat = 0, maxDis = seats[0], toinsert = 0;\n for...
1
0
[]
0
exam-room
Clean python solution
clean-python-solution-by-olivia_xie_93-xirv
python\nclass ExamRoom:\n\n def __init__(self, N: int):\n self.n = N\n self.seats = []\n\n def seat(self) -> int:\n n = self.n\n
olivia_xie_93
NORMAL
2020-05-17T23:38:20.270080+00:00
2020-05-17T23:38:20.270129+00:00
242
false
```python\nclass ExamRoom:\n\n def __init__(self, N: int):\n self.n = N\n self.seats = []\n\n def seat(self) -> int:\n n = self.n\n last_seat = -1\n dist = 0\n seat = -1\n idx = -1\n \n for i in range(len(self.seats)):\n if last_seat == -1:...
1
0
[]
1
exam-room
Clean Python Solution
clean-python-solution-by-olivia_xie_93-onjj
This is question is similar to 849. Maximize Distance to Closest Person. Additionally, we need to know where Alex will take a seat (suppose choose the smaller i
olivia_xie_93
NORMAL
2020-04-17T20:43:53.554484+00:00
2020-04-17T20:43:53.554524+00:00
228
false
This is question is similar to [849. Maximize Distance to Closest Person](https://leetcode.com/problems/maximize-distance-to-closest-person/). Additionally, we need to know where Alex will take a seat (suppose choose the smaller index when same maximum distances exist).\n\n\n```python\nclass Solution:\n def maxDistT...
1
0
[]
0
select-cells-in-grid-with-maximum-score
Focus on uniqueness in values first, then uniqueness in rows | Full explanation
focus-on-uniqueness-in-values-first-then-vbva
So this one is a tricky one. Brute force suggests to try all possibilities on rows and maintain uniqueness through sets, which results in tle.\n\nThe optimisati
virujthakur01
NORMAL
2024-09-01T04:05:09.950549+00:00
2024-09-01T04:08:42.206673+00:00
7,900
false
So this one is a tricky one. Brute force suggests to try all possibilities on rows and maintain uniqueness through sets, which results in tle.\n\nThe optimisation lies in the fact that we can store values in increasing/ decreasing order and then only select values greater than / less than the previous value. This ensur...
70
2
['Dynamic Programming', 'Bitmask', 'C++']
20
select-cells-in-grid-with-maximum-score
Python | Java DFS in descending orders with detailed explanation.
python-java-dfs-in-descending-orders-wit-m5c1
\n# Intuition\nThere are two constraints to consider:\n- Each row can only contain one value.\n- All values must be unique.\n\nThese constraints imply that, whe
leet_go
NORMAL
2024-09-01T04:03:57.424141+00:00
2024-09-01T05:43:59.655607+00:00
3,047
false
\n# Intuition\nThere are two constraints to consider:\n- Each row can only contain one value.\n- All values must be unique.\n\nThese constraints imply that, when aiming to maximize the values in all cells, the largest value in the grid must be included. This is because, for any set of values chosen from the grid that e...
28
1
['Depth-First Search', 'Java', 'Python3']
10
select-cells-in-grid-with-maximum-score
Min-Cost Max-Flow Solution (With Diagrams)
min-cost-max-flow-solution-with-diagrams-cz81
Intuition\n Matching problems can often be modeled into a flow network in which the min-cost max-flow represents the optimal solution.\n The key challenge here
whynot4
NORMAL
2024-09-01T05:06:45.634463+00:00
2024-09-08T06:07:28.978478+00:00
877
false
# Intuition\n* Matching problems can often be modeled into a flow network in which the min-cost max-flow represents the optimal solution.\n* The key challenge here is figuring out how to transform the input grid into such a network that respects the contstraints of the problem (i.e. uniqueness and the "1 selection per ...
26
0
['Graph', 'Java']
6
select-cells-in-grid-with-maximum-score
Easy Video Solution 🔥 || How to 🤔 in Interview || Focus on uniqueness || Memo + Bitmasking 🥲
easy-video-solution-how-to-in-interview-mpk5v
If you like the solution Please Upvote and subscribe to my youtube channel\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \nTry to
ayushnemmaniwar12
NORMAL
2024-09-01T05:08:20.233935+00:00
2024-09-01T07:25:30.961610+00:00
2,462
false
***If you like the solution Please Upvote and subscribe to my youtube channel***\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to think in terms of values, Ascending or Desending\n\n\n\n***Easy Video Explanation with Proofs***\n\nhttps://youtu.be/lvUte5NcTJ4\n \n\n# Code\n\...
25
1
['Memoization', 'Bitmask', 'C++', 'Java', 'Python3']
5
select-cells-in-grid-with-maximum-score
[Python] Hungarian, 5 lines
python-hungarian-5-lines-by-lee215-1a4d
Hungarian problem.\n\nTime O(100^3)\nSpace O(100^2)\n\n\n\nPython\npy\n def maxScore(self, grid: List[List[int]]) -> int:\n A = numpy.array([[0] * 101
lee215
NORMAL
2024-09-01T04:45:43.717460+00:00
2024-09-01T09:42:53.851742+00:00
1,565
false
Hungarian problem.\n\nTime `O(100^3)`\nSpace `O(100^2)`\n<br>\n\n\n**Python**\n```py\n def maxScore(self, grid: List[List[int]]) -> int:\n A = numpy.array([[0] * 101 for r in grid])\n for i,r in enumerate(grid):\n for a in r:\n A[i][a] = -a\n return int(-A[scipy.optimiz...
18
2
[]
4
select-cells-in-grid-with-maximum-score
DP - Bitmask without sorting (Simple rundown from 100) || Well explained || Easy
dp-bitmask-without-sorting-simple-rundow-tji2
Intuition\n Describe your first thoughts on how to solve this problem. \nNoticing the constrains, my first thoughts were backtracking. Then I observed that not
rubixxzone218
NORMAL
2024-09-01T12:23:53.191679+00:00
2024-09-05T08:04:27.593748+00:00
566
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. --> \nNoticing the constrains, my first thoughts were backtracking. Then I observed that not only the size of the grid has a small cap but also the value at every cell is also capped at 100. This naturally steered me to a bitmask dp approach.\...
17
0
['Dynamic Programming', 'Bitmask', 'C++']
2
select-cells-in-grid-with-maximum-score
Bitmask DP mask of used rows
bitmask-dp-mask-of-used-rows-by-theabbie-xtq6
\nclass Solution:\n def maxScore(self, grid: List[List[int]]) -> int:\n n = len(grid)\n vals = {}\n for i in range(n):\n for
theabbie
NORMAL
2024-09-01T04:00:36.902058+00:00
2024-09-01T04:00:36.902091+00:00
2,105
false
```\nclass Solution:\n def maxScore(self, grid: List[List[int]]) -> int:\n n = len(grid)\n vals = {}\n for i in range(n):\n for h in grid[i]:\n if h not in vals:\n vals[h] = []\n vals[h].append(i)\n vals = list(vals.items())\n ...
17
1
['Python']
6
select-cells-in-grid-with-maximum-score
solution explained [recursion -> bitmask DP -> greedy + bitmasking]
solution-explained-recursion-bitmask-dp-t3ggk
Recursion \n\n#### approach \n\nWe will start by picking each element one by one from every row to see what is the maximum score we can get from all the combina
niti_n_n_itin
NORMAL
2024-09-01T06:01:41.705987+00:00
2024-09-01T07:26:36.056448+00:00
1,055
false
## Recursion \n\n#### approach \n\nWe will start by picking each element one by one from every row to see what is the maximum score we can get from all the combinations.\n\nNote: `We can even decide not to choose any number from a row.`\n\nfor ex : \n[5 , 5]\n[5, 5]\n[10, 1]\n\nIn the above case, we will not pick any n...
14
0
['Greedy', 'Recursion', 'C', 'C++']
5
select-cells-in-grid-with-maximum-score
DP APPROACH || C++
dp-approach-c-by-_shivam_kmr-jf3b
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
_shivam_kmr_
NORMAL
2024-09-01T04:10:31.953260+00:00
2024-09-01T04:10:31.953297+00:00
2,658
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
13
0
['Dynamic Programming', 'Memoization', 'C++']
4
select-cells-in-grid-with-maximum-score
Python3 || recursion, cache, masks || T/S: 97% / 59%
python3-recursion-cache-masks-ts-97-59-b-rbuw
Here\'s the intuiton:\n\n1. We manually map the grid to d, a dictionary that maps each value in the grid to a bitmask, which indicates which rows contain that v
Spaulding_
NORMAL
2024-09-02T23:25:24.320680+00:00
2024-09-02T23:25:36.861716+00:00
250
false
Here\'s the intuiton:\n\n1. We manually map the grid to `d`, a dictionary that maps each value in the grid to a bitmask, which indicates which rows contain that value. \n\n1. We use recursion with caching to evaluate possible selections of values from the grid, moving from greater values to lesser values. \n\n1. We emp...
9
0
['Python3']
0
select-cells-in-grid-with-maximum-score
Video Explanation (Optimising brute force solution step-by-step)
video-explanation-optimising-brute-force-6blz
Explanation\n\nClick here for the video\n\n# Code\ncpp []\nint dp[101][1024];\n\nclass Solution {\n \n int rows, cols;\n vector<vector<int>> grid;\n
codingmohan
NORMAL
2024-09-01T06:23:17.122347+00:00
2024-09-01T06:23:17.122382+00:00
271
false
# Explanation\n\n[Click here for the video](https://youtu.be/xDiSlVmMFTk)\n\n# Code\n```cpp []\nint dp[101][1024];\n\nclass Solution {\n \n int rows, cols;\n vector<vector<int>> grid;\n \n int Score (int val, int row_mask) {\n if (val > 100) return 0;\n \n int &ans = dp[val][row_mask...
8
1
['C++']
0
select-cells-in-grid-with-maximum-score
Hungarian Algorithm
hungarian-algorithm-by-iyerke-88eo
Intuition\nThe problem of selecting unique values from a 2D matrix such that no two selected cells are in the same row can be modeled as an assignment problem.
iyerke
NORMAL
2024-09-01T04:01:22.700172+00:00
2024-09-01T04:22:43.198006+00:00
972
false
### Intuition\nThe problem of selecting unique values from a 2D matrix such that no two selected cells are in the same row can be modeled as an [assignment problem](https://en.wikipedia.org/wiki/Assignment_problem). This is a classical optimization problem that can be effectively solved using graph theory. Specifically...
8
1
['Python3']
1
select-cells-in-grid-with-maximum-score
Bitmask DP || All Bitmask DP Lists || Detail Explained || 100% common topics in today's contest!
bitmask-dp-all-bitmask-dp-lists-detail-e-4w0q
Bitmask DP Lists: https://leetcode.com/problem-list/mtxjny0h/\n\n# Code\ncpp []\n\n#define ll long long\n#define rep0(i,n) for(ll i = 0; i < n; i++)\n#define me
suvro_datta
NORMAL
2024-09-01T05:09:52.252540+00:00
2024-09-01T09:21:47.379031+00:00
667
false
Bitmask DP Lists: https://leetcode.com/problem-list/mtxjny0h/\n\n# Code\n```cpp []\n\n#define ll long long\n#define rep0(i,n) for(ll i = 0; i < n; i++)\n#define memo(a) memset(a, -1, sizeof(a));\n#define len(x) ((ll)x.size()) \n#define pb push_back\n\nclass Solution {\npublic:\n vector<vector<int>> nums;\n int dp...
5
0
['Dynamic Programming', 'Memoization', 'Bitmask', 'C++']
5
select-cells-in-grid-with-maximum-score
Beats 100% time , Beats 100% space: Greedy TreeMap
beats-100-time-beats-100-space-greedy-tr-robr
\n\n# Intution\n\nWe create a TreeMap in which the key is an element of the grid and the value is a set of rowIndexes that had the element.\n\nWe start from the
navid
NORMAL
2024-09-01T04:03:51.530765+00:00
2024-09-01T21:13:36.228111+00:00
1,120
false
![image.png](https://assets.leetcode.com/users/images/2959b070-4f16-4f12-84b2-206afa91278a_1725167093.7640224.png)\n\n# Intution\n\nWe create a TreeMap in which the key is an element of the grid and the value is a set of rowIndexes that had the element.\n\nWe start from the biggest number and keep going down. We also k...
5
0
['Java']
3
select-cells-in-grid-with-maximum-score
bit-mask DP by limiting and enumerating the current largest element
bit-mask-dp-by-limiting-and-enumerating-jwh2l
Intuition\n1. Bit-mask DP takes care of the first condition: "no two selected cells are in the same row of the matrix."\n2. To satisfy the second requirement: "
lydxlx
NORMAL
2024-09-01T04:27:53.913809+00:00
2024-09-01T20:51:58.045437+00:00
164
false
# Intuition\n1. Bit-mask DP takes care of the first condition: "no two selected cells are in the same row of the matrix."\n2. To satisfy the second requirement: "the values in the set of selected cells are unique," we can require the selected value list is strictly decreasing. One way to achieve in DP is to add a new d...
4
0
['Python3']
1
select-cells-in-grid-with-maximum-score
DP Bitmasking | Intuition Building | Full Explanation⚡⚡
dp-bitmasking-intuition-building-full-ex-hoqn
\nObservation:\n 1 <= row <= 10 and 1 <= value <= 100\n so we have to iterate over values,\n and we can mask the rows, \n (masking value will be a t
kaushalShinde
NORMAL
2024-09-02T06:50:53.181686+00:00
2024-09-02T06:55:53.430125+00:00
86
false
\n**Observation:**\n 1 <= row <= 10 and 1 <= value <= 100\n so we have to iterate over values,\n and we can mask the rows, \n (masking value will be a tedious task and gives tle, as we need to take `bitset<101>`)\n\n---\n\n**Intuition:**\nfor each value from 1 to 100 we will store in which row the value occ...
3
0
['Dynamic Programming', 'Bit Manipulation', 'Recursion', 'Bitmask', 'C++']
0
select-cells-in-grid-with-maximum-score
Easy Recursive dp solution
easy-recursive-dp-solution-by-kvivekcode-wt4c
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
kvivekcodes
NORMAL
2024-09-01T05:27:20.115701+00:00
2024-09-01T05:27:20.115727+00:00
535
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['Dynamic Programming', 'Sorting', 'Bitmask', 'C++']
0
select-cells-in-grid-with-maximum-score
Intuition and Approach are commented in Code..
intuition-and-approach-are-commented-in-qs6ty
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Animesh_Maurya
NORMAL
2024-10-21T11:44:05.842872+00:00
2024-10-21T11:44:05.842896+00:00
16
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Array', 'Dynamic Programming', 'Bit Manipulation', 'Matrix', 'Bitmask', 'C++']
1
select-cells-in-grid-with-maximum-score
🔥Memoization with BitMasking⭐|| 💯Clean & Best Code⚡
memoization-with-bitmasking-clean-best-c-x6ai
Complexity\n\n- Time complexity:\nO((1 << m) * max(grid[i][j]) * m * n)\n\n- Space complexity:\nO((1 << m) * max(grid[i][j]))\n\n\n# Code\n# Please Upvote if it
aDish_21
NORMAL
2024-09-13T19:09:03.954492+00:00
2024-09-13T19:09:03.954515+00:00
36
false
# Complexity\n```\n- Time complexity:\nO((1 << m) * max(grid[i][j]) * m * n)\n\n- Space complexity:\nO((1 << m) * max(grid[i][j]))\n```\n\n# Code\n# Please Upvote if it helps\uD83E\uDD17\n```cpp []\nclass Solution {\npublic:\n int dp[101][1024];\n int helper(int prev_val, vector<vector<int>>& grid, int mask){\n ...
2
0
['Array', 'Dynamic Programming', 'Bit Manipulation', 'Memoization', 'Matrix', 'Bitmask', 'C++']
0