90 minutes, 3 problems. Felt like every problem was medium+ difficulty. I only managed to solve the first one, and even that had a TLE.
LeetCode 2551
Given two vectors of equal length, for each index [i] there is guaranteed to be an edge between v1[i] and v2[i]. Within the same vector, earlier elements sit at a higher level and later elements sit at a lower level, and together they end up forming a tree. For n query inputs, each query has as many elements as the tree has nodes, and a query represents a BFS traversal of that tree — you need to determine whether each query is a valid BFS order.
Example:
vec1=[1,1,4]
vec2=[3,2,3]
The resulting tree is:
1
| |
3 2
|
4
query=[[1,2,3,4]] is valid.
(The original problem statement was very long and needed careful reading comprehension:
Using a queue (FIFO): for these two vectors, 1 goes in first, then comes out; 2 and 3 go in. out = [1]
Then 2 and 3 come out, 4 goes in. out = [1,2,3]
Then 4 comes out. out = [1,2,3,4], which matches the query.
Someone had posted this problem on the forum before, but I didn't understand their post at the time... so I still couldn't solve it.
There are N people, each with a work-time interval [start_i, end_i]. I need to find the group with the most people in it and return that group's size.
A group is defined as:
For any two people A and B in the group, they don't need to be able to communicate directly, but there must be some communication path between them within the group.
Communication is defined as:
Their working-time intervals overlap.
For example, if A and B's times overlap, and B and C's times overlap, then even though A and C's times don't overlap, A, B, and C can still form a group.
I felt their problems were extremely long-winded — just understanding the problem statement took me about 30 minutes.
Discussion
Loading comments…