You are given three independent coding tasks.
1) Bounded cache with eviction
Design a data structure that stores key–value pairs with a fixed capacity and supports:
-
get(key) -> value
:
-
Return the value if
key
exists, otherwise return
-1
.
-
Mark the key as
most recently used
.
-
put(key, value)
:
-
Insert or update the value.
-
Mark the key as
most recently used
.
-
If inserting causes the number of keys to exceed
capacity
, evict exactly one key: the
least recently used
key.
Requirements
-
Aim for
O(1)
average time per operation.
Constraints (typical)
-
1 <= capacity <= 10^5
-
Up to
10^5
operations.
2) Maximize the minimum value on a grid path
You are given an m x n integer grid grid. A path starts at (0,0) and ends at (m-1,n-1), moving only in 4 directions (up/down/left/right) within bounds.
Define the score of a path as the minimum value among all cells on the path.
Return the maximum possible score among all valid paths.
Constraints (typical)
-
1 <= m, n <= 100
-
Cell values are integers within a reasonable range (e.g.,
0..10^9
).
3) Longest substring without repeating characters
Given a string s, return the length of the longest contiguous substring that contains no repeated characters.
Constraints (typical)
-
0 <= |s| <= 10^5
-
s
may contain ASCII/Unicode characters (clarify with interviewer if needed).