This set evaluates algorithmic problem-solving and data-structure competence, including mastery of hash tables, linked lists, stacks, queues, heaps, graphs, sliding-window and two-pointer techniques, complexity analysis, and in-place transformations.
The post summarizes high-frequency coding problems reported for Apple Software Engineer interviews. Practice the following algorithm and data-structure questions:
get(key)
and
put(key, value)
operations. Both operations should run in
O(1)
average time. When the cache is full, evict the
least recently used
item.
insert(val)
,
remove(val)
, and
getRandom()
, where each operation runs in
O(1)
average time.
insert(word)
,
search(word)
, and
startsWith(prefix)
.
nums = [1,1,1,2,2,3]
and
k = 2
, return the
k
values that appear most often, for example
[1,2]
in any order.
[1,2,3,4]
, return an array where each position contains the product of all other elements, for example
[24,12,8,6]
. Do not use division, and aim for
O(n)
time.
[0,1,0,2,1,0,1,3,2,1,2,1]
, compute how much rainwater can be trapped.
"abcabcbb"
, return the length of the longest substring that contains no repeated characters. For this example, the answer is
3
.
["eat","tea","tan","ate","nat","bat"]
, group together words that are made of the same letters, for example
[["eat","tea","ate"],["tan","nat"],["bat"]]
.
"3[a2[c]]"
, return its decoded form. For this example, the result is
"accaccacc"
.
n
courses and a list of prerequisite pairs, determine whether it is possible to finish all courses. This is a graph cycle-detection / topological-order problem.
k
sorted linked lists such as
1->4->5
,
1->3->4
, and
2->6
, merge them into one sorted linked list:
1->1->2->3->4->4->5->6
.
n x n
matrix, rotate it
90 degrees clockwise in place
. Example:
[[1,2,3],[4,5,6],[7,8,9]]
becomes
[[7,4,1],[8,5,2],[9,6,3]]
.
[2,1,4,7,3,2,5]
, return the length of the longest contiguous subarray that strictly increases and then strictly decreases. In this example, the longest mountain is
[1,4,7,3,2]
, so the answer is
5
.