Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 4.08 KB

File metadata and controls

72 lines (48 loc) · 4.08 KB

DailyCodingProblem

[Index]

Problem 1: Done

Given a list of numbers and a number k, return whether any two numbers from the list add up to k.

Problem 2: Done

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.

Problem 3:

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.

Problem 4: Done

Given an array of integers, find the first missing positive integer in linear time and constant space. In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well.

Problem 5:

cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4

Problem 6:

An XOR linked list is a more memory efficient doubly linked list. 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. 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.

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.

Problem 7: Done

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.

Problem 8: Done

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.

Problem 9: Done

Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative.

Problem 10:

Implement a job scheduler which takes in a function f and an integer n, and calls f after n milliseconds.

Problem 11:

Implement an autocomplete system. That is, given a query string s and a set of all possible query strings, return all strings in the set that have s as a prefix.

Problem 12: Done

There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters.

Problem 13: Done

Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters.

Problem 14:

The area of a circle is defined as πr^2. Estimate π to 3 decimal places using a Monte Carlo method.

Problem 15:

Given a stream of elements too large to store in memory, pick a random element from the stream with uniform probability.

Problem 16:

You run an e-commerce website and want to record the last N order ids in a log. Implement a data structure to accomplish this.

Problem 17:

Given a string representing the file system in the above format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0.

Problem 18: Done

Given an array of integers and a number k, where 1 <= k <= length of the array, compute the maximum values of each subarray of length k.>>

Problem 19:

Given an N by K matrix where the nth row and kth column represents the cost to build the nth house with kth color, return the minimum cost which achieves this goal.

Problem 20: Done

Given two singly linked lists that intersect at some point, find the intersecting node. The lists are non-cyclical.

Problem 21: Done

Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required.

Problem 22:

Given a dictionary of words and a string made up of those words (no spaces), return the original sentence in a list. If there is more than one possible reconstruction, return any of them. If there is no possible reconstruction, then return null.