You are given several independent coding interview tasks. Solve each with the required time/space complexity.
You are given an array nums of distinct integers that was originally sorted in increasing order and then rotated at an unknown pivot (e.g., [4,5,6,7,0,1,2]).
nums: int[]
nums
1 ≤ len(nums) ≤ 2e5
O(log n)
time,
O(1)
extra space
Design a data structure that supports storing and querying values for a key over time.
Support the following operations:
set(key: string, value: string, timestamp: int) -> void
key
at the given timestamp.
get(key: string, timestamp: int) -> string
key
at the
largest timestamp ≤ query timestamp
.
Assumptions/constraints:
set()
calls may arrive in increasing timestamp order (state your assumption); handle the general case if not.
O(log m)
per
get()
for
m
versions of a key.
Given the root of a binary tree and two nodes p and q that both exist in the tree, return their lowest common ancestor (LCA).
p
and
q
is the lowest node in the tree that has both
p
and
q
as descendants (a node can be a descendant of itself).
You are given:
maze
represented as a list of equal-length strings.
'#'
= wall
'.'
= open cell
'e'
= entrance (must stay as
'e'
)
'E'
= exit (must stay as
'E'
)
path
of coordinates (row, col) representing a valid path through the maze
including the entrance and exit
.
Write a function that returns a new maze where every coordinate in path is replaced with '*', except the entrance 'e' and exit 'E', which must not be changed.
maze: string[]
,
path: (int row, int col)[]
string[]
(the updated maze)
path
contains only in-bounds coordinates and forms a valid path through open cells.