![]() ![]() Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Given the root to a binary tree, count the number of unival subtrees.įor example, the following tree has 5 unival subtrees: For example, '001' is not allowed.Ī unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. You can assume that the messages are decodable. z = 26, and an encoded message, count the number of ways it can be decoded.įor example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'. If using a language that has no pointers (such as Python), you can assume you have access to get_pointer and dereference_pointer functions that converts between nodes and memory addresses. Implement an XOR linked list it has an add(element) which adds the element to the end, and a get(index) which returns the node at index. Instead of each node holding next and prev fields, it holds a field named both, which is an XOR of the next node and the previous node. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4.Īn XOR linked list is a more memory efficient doubly linked list. The input should give 3.Ĭons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. The array can contain duplicates and negative numbers as well.įor example, the input should give 2. In other words, find the lowest positive integer that does not exist in the array. Given an array of integers, find the first missing positive integer in linear time and constant space. Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree. ![]() įollow-up: what if you can't use division? If our input was, the expected output would be. 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 original array except the one at i.įor example, if our input was, the expected output would be. Given a list of numbers, return whether any two sums to k.įor example, given and k of 17, return true since 10 + 7 is 17.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |