Given an array of integers, return a new array such that each element at index $i$ of the new array is the product of all the numbers in the originial array except the one at $i$. For example, if our input was $[1,2,3,4,5]$ the expected output would be $[120,60,40,30,24]$. If our input was $[3,2,1]$, the expected output would be $[2,3,6]$.
Follow-up: what if you can't use division?
Given an array of intergers that are out of order, determine the bounds of the smallest window that must be sorted in order for the entire array to be sorted. For example given $[3,7,5,6,9]$, you should return $(1,3)$.
Given the head of singly linked list, reverse it in place.
We can represent an integer in a linked list format by having each node represent a digit in the number. The nodes are connected in reverse order, such that the number $54321$ is represented by the following linked list: $5 \leftarrow 4 \leftarrow 3 \leftarrow 2 \leftarrow 1$. Given two linked lists in this format, return their sum. For example, given $9 \rightarrow 9$ and $5 \rightarrow 2$ you should return $124$ $(99+25)$ as $4 \rightarrow 2 \rightarrow 1$.
Given a linked list, rearrange the node values such that they appear in alternating $low \rightarrow high \rightarrow low \rightarrow high \rightarrow ...$ form. For example, given $1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 5$ you should return $1 \rightarrow 3 \rightarrow 2 \rightarrow 5 \rightarrow 4$.
Given two singly linked lists that intersect at some point, found the intersecting node. Assume the lists are non-cyclical. For example, given $A = 3 \rightarrow 7 \rightarrow 8 \rightarrow 10$ and B = $99 \rightarrow 1 \rightarrow 8 \rightarrow 10$, return the node with value $8$. In this example, assume nodes with the same value are the exact same node objects. Do this in $O(m+n)$ time (where $m$ and $n$ are the length of the lists) and constant space.
Implement a stack that has the following methods:
push(val)
: push val
onto the stackpop
: pop off and return the topmost element of the stack. If there are no elements in the stack, throw an error.max
: return the maximum value in the stack currently. If there are no elements in the stack, throw an error. Each method should run in constant time.
Given a string of round, curly, and square opening and closing brackets, return whether the brackets are balanced (well-formed). For example, given the string "( [ ] ) [ ] ( { } )", you should return True
. Given the string "( [ ) ]" or "( ( ( )" you should return False
.
Similar problem: aoc 2017 day 9
The sequence $[0,1,...,N]$ has been jumbled, and the only clue you have for its order is an array representing whether each number is larger or smaller than the last. Given this information, reconstruct an array that is consistent with it. For example, given $[\text{None}, +,+,-,+]$ you should return $[0,1,3,2,4]$.
A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. Given the root to a binary tree, count the number of unival subtrees. For example, the following tree has 5 unival subtrees:
Suppose an arithmetic expression is given as a binary tree. Each leaf is an integer and each internal node is one of +,-,* or /. Given the root to such a node, write a function to evaluate it. For example, given the following tree:
You should return $45$ as it is $(3+2) * (4+5)$
Given a binary tree, return the level of the tree that has the minimum sum. The level of a node is defined as the number of connections required to get to the root, with the root having level zero. For example:
In this tree, level $0$ has sum $1$, level $1$ has sum $5$ and level $2$ has sum $9$, so the level with the minimum sum is $0$.