Given a number n
, check if this number is a power of three, that is that it can be represented by 3^x
.
A straightforward solution looks as follows. Multiply by 3
until we reach n
. If we’re greater than n
, return False
, and True
otherwise.
Given a n*n
matrix, find the kth
smallest element. Each row in the matrix is sorted in ascending order and independent of the other rows. Do not use O(n*n)
space when solving this. One example matrix looks like this:
Given a head
of a list with pointers to next
and a random
element, copy the list to a new list without any random pointers pointing to the old list.
Characters can be encoded via different numbers. A -> 1, B -> 2, ..., Z -> 26
. Given a string s
of numbers, return the number of possible decodings. For example 12
can be decoded as A,B
and as L
.
Given two lists of a preorder
and inorder
, create a tree and return the root
node.
null
values for the places where the tree does not contain nodes, we could simply iterate over this list and reconstruct the tree from there. But since the null
values are missing, we also need to take a look at the inorder
list.