The first problem evaluates graph traversal and reachability by modeling rooms and keys as an implicit graph, and it is commonly asked to assess reasoning about connectivity and exploration in graph-theoretic settings; this falls under the algorithms/graph theory domain and emphasizes practical application of traversal techniques.
There are n rooms labeled 0..n-1. All rooms are locked except room 0.
rooms[i]
.
k
that unlocks room
k
.
Task: Given rooms: List[List[int]], return true if you can eventually visit every room starting from room 0, otherwise return false.
Input/Output
rooms
, where
rooms[i]
is the list of keys in room
i
Constraints (typical):
1 <= n <= 10^4
0 <= rooms[i].length <= 10^4
0..n-1
(may include duplicates)
You are given a balanced parentheses string s consisting only of '(' and ')'.
Define the score recursively:
"()"
has score
1
A
and
B
are balanced, then
score(A + B) = score(A) + score(B)
A
is balanced, then
score("(" + A + ")") = 2 * score(A)
Task: Return score(s).
Input/Output
s
Constraints (typical):
1 <= s.length <= 10^5
s
is guaranteed balanced