1. You are given
a list of numbers, and a target number k.
Return whether or not there are two numbers in the list that add up to k.
Example:
Given [4, 7, 1 , -3, 2] and k = 5,
return true since 4 + 1 = 5.
Example:
Given [4, 7, 1 , -3, 2] and k = 5,
return true since 4 + 1 = 5.
2. Given
a list of numbers, where every number shows up twice except for one number,
find that one number.
Example:
Example:
Input: [4, 3, 2, 4, 1, 3, 2]
Output: 1
Output: 1
3. Given
a sequence of numbers, find the longest sequence that contains only 2 unique
numbers.
Example:
Example:
Input: [1, 3, 5, 3, 1, 3, 1, 5]
Output: 4
Output: 4
The longest sequence that
contains just 2 unique numbers is [3, 1, 3, 1]
4. Given an
undirected graph, determine if a cycle exists in the graph.
5. Given an array nums, write a function to move
all 0's to the end of it while maintaining the relative order of the non-zero
elements.
Example:
Example:
Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
Output: [1,3,12,0,0]
6. Given a list, find the k-th largest element in
the list.
Input: list = [3, 5, 2, 4, 6, 8], k = 3
Output: 5
Output: 5
7. You are given an array of integers. Return the smallest
positive integer that is not present in the array. The array may contain
duplicate entries.
For example, the input [3, 4, -1, 1] should return 2 because it is the smallest positive integer that doesn't exist in the array.
Your solution should run in linear time and use constant space.
For example, the input [3, 4, -1, 1] should return 2 because it is the smallest positive integer that doesn't exist in the array.
Your solution should run in linear time and use constant space.
8. You are given the root of a binary search tree. Return
true if it is a valid binary search tree, and false otherwise. Recall that a
binary search tree has the property that all values in the left subtree are
less than or equal to the root, and all values in the right subtree are greater
than or equal to the root.
9. Given
a string, you need to reverse the order of characters in each word within a
sentence while still preserving whitespace and initial word order.
Example 1:
Example 1:
Input: "The cat in the hat"
Output: "ehT tac ni eht tah"
Output: "ehT tac ni eht tah"
Note: In the string, each word is separated by single space
and there will not be any extra space in the string.
10. Given a sorted list of numbers, return a list of strings
that represent all of the consecutive numbers.
Example:
Example:
Input: [0, 1, 2, 5, 7, 8, 9, 9, 10, 11, 15]
Output: ['0->2', '5->5', '7->11', '15->15']
Output: ['0->2', '5->5', '7->11', '15->15']
Assume that all numbers will be greater than or equal to 0,
and each element can repeat.
11. Two
words can be 'chained' if the last character of the first word is the same as
the first character of the second word.
Given a list of words, determine if there is a way to 'chain' all the words in a circle.
Example:
Given a list of words, determine if there is a way to 'chain' all the words in a circle.
Example:
Input: ['eggs', 'karat', 'apple', 'snack',
'tuna']
Output: True
Output: True
Explanation:
The words in the order of ['apple', 'eggs', 'snack', 'karat', 'tuna'] creates a circle of chained words.
The words in the order of ['apple', 'eggs', 'snack', 'karat', 'tuna'] creates a circle of chained words.
12. Starting at index 0, for an element n at index i, you are allowed to jump at most n indexes ahead. Given a list of numbers, find the minimum number of
jumps to reach the end of the list.
Example:
Example:
Input: [3, 2, 5, 1, 1, 9, 3, 4]
Output: 2
Output: 2
Explanation:
The minimum number of jumps to get to the end of the list is 2:
3 -> 5 -> 4
The minimum number of jumps to get to the end of the list is 2:
3 -> 5 -> 4
13. You are given
the root of a binary tree. Find the path between 2 nodes that maximizes the sum
of all the nodes in the path, and return the sum. The path does not necessarily
need to go through the root.
14. You are given an array
of integers. Return all the permutations of this array.
15. Given
a file path with folder names, '..' (Parent directory), and '.' (Current
directory), return the shortest possible file path (Eliminate all the '..' and
'.').
Example
Example
Input:
'/Users/Joma/Documents/../Desktop/./../'
Output: '/Users/Joma/'
Output: '/Users/Joma/'
16. Given a directed graph, reverse the directed
graph so all directed edges are reversed.
Example:
Example:
Input:
A -> B, B -> C, A ->C
Output:
B->A, C -> B, C -> A
A -> B, B -> C, A ->C
Output:
B->A, C -> B, C -> A
17. Kaprekar's Constant is
the number 6174. This number is special because it has the property where for any
4-digit number that has 2 or more unique digits, if you repeatedly apply a
certain function it always reaches the number 6174.
This certain function is as follows:
- Order the number in ascending form and descending form to create 2 numbers.
- Pad the descending number with zeros until it is 4 digits in length.
- Subtract the ascending number from the descending number.
- Repeat.
This certain function is as follows:
- Order the number in ascending form and descending form to create 2 numbers.
- Pad the descending number with zeros until it is 4 digits in length.
- Subtract the ascending number from the descending number.
- Repeat.
18. Given a list of
building in the form of (left, right, height), return what the skyline should look like. The
skyline should be in the form of a list of (x-axis, height), where x-axis is the next point where there is a change in height starting from
0, and height is the new height
starting from the x-axis.
19. Given an expression (as a list) in reverse polish
notation, evaluate the expression. Reverse polish notation is where the numbers
come before the operand. Note that there can be the 4 operands '+', '-', '*', '/'. You can also assume the expression will be well
formed.
Example
Example
Input: [1, 2, 3, '+', 2, '*', '-']
Output: -9
Output: -9
The equivalent expression of the above reverse polish
notation would be (1 - ((2 + 3) * 2)).
20. Given a list of words, for each word find the shortest
unique prefix. You can assume a word will not be a substring of another word
(ie play and playing won't
be in the same words list)
Example
Example
Input: ['joma', 'john', 'jack', 'techlead']
Output: ['jom', 'joh', 'ja', 't']
Output: ['jom', 'joh', 'ja', 't']
21. Given an array and an
integer k, rotate
the array by k spaces. Do this
without generating a new array and without using extra space.
22. A
Sudoku board is a 9x9 grid, where each row, column and each 3x3 subbox contains
the number from 1-9. Here's an example of a Sudoku board.
-------------
|534|678|912|
|672|195|348|
|198|342|567|
|------------
|859|761|423|
|426|853|791|
|713|924|856|
|------------
|961|537|284|
|287|419|635|
|345|286|179|
|------------
|534|678|912|
|672|195|348|
|198|342|567|
|------------
|859|761|423|
|426|853|791|
|713|924|856|
|------------
|961|537|284|
|287|419|635|
|345|286|179|
|------------
Given a 9x9 board, determine if it is a valid Sudoku board.
The board may be partially filled, where an empty cell will be represented by
the space character ' '
23. Given a number n, find the least number of squares needed to sum up to the number.
24. Given a list of
meetings that will happen during a day, find the minimum number of meeting
rooms that can fit all meetings.
Each meeting will be represented by a tuple of (start_time, end_time), where both start_time and end_time will be represented by an integer to indicate the time. start_time will be inclusive, and end_time will be exclusive, meaning a meeting of (0, 10) and (10, 20) will only require 1 meeting room.
Each meeting will be represented by a tuple of (start_time, end_time), where both start_time and end_time will be represented by an integer to indicate the time. start_time will be inclusive, and end_time will be exclusive, meaning a meeting of (0, 10) and (10, 20) will only require 1 meeting room.
25. Given a numerator and
a denominator, find what the equivalent decimal representation is as a string.
If the decimal representation has recurring digits, then put those digits in
brackets (ie 4/3 should be represented by 1.(3) to represent 1.333...). Do not use any built in evaluator
functions like python's eval. You
can also assume that the denominator will be nonzero.
26. Given two binary
numbers represented as strings, return the sum of the two binary numbers as a
new binary represented as a string. Do this without converting the whole binary
string into an integer.
27. Reshaping a matrix
means to take the same elements in a matrix but change the row and column
length. This means that the new matrix needs to have the same elements filled
in the same row order as the old matrix. Given a matrix, a new row size x and a new column
size y, reshape the matrix. If it is
not possible to reshape, return None.
28. Given a matrix that is
organized such that the numbers will always be sorted left to right, and the
first number of each row will always be greater than the last element of the
last row (mat[i][0] > mat[i - 1][-1]), search for a specific value in the matrix and
return whether it exists.
29. Given a list of unique
numbers, generate all possible subsets without duplicates. This includes the
empty set as well.
30. Given a list of
building in the form of (left, right, height), return what the skyline should look like. The
skyline should be in the form of a list of (x-axis, height), where x-axis is the next point where there is a change in height starting from
0, and height is the new height
starting from the x-axis.
31. Given
an expression (as a list) in reverse polish notation, evaluate the expression.
Reverse polish notation is where the numbers come before the operand. Note that
there can be the 4 operands '+', '-', '*', '/'. You can also
assume the expression will be well formed.
Example
Example
Input: [1, 2, 3, '+', 2, '*', '-']
Output: -9
Output: -9
The equivalent expression of the above reverse polish
notation would be (1 - ((2 + 3) * 2)).
32. Given a list of unique
numbers, generate all possible subsets without duplicates. This includes the
empty set as well.
33. Given a number n, find the least number of
squares needed to sum up to the number.
34. Kaprekar's Constant is
the number 6174. This number is special because it has the property where for any
4-digit number that has 2 or more unique digits, if you repeatedly apply a
certain function it always reaches the number 6174.
This certain function is as follows:
- Order the number in ascending form and descending form to create 2 numbers.
- Pad the descending number with zeros until it is 4 digits in length.
- Subtract the ascending number from the descending number.
- Repeat.
Given a number n, find the number of times the function needs to be applied to reach Kaprekar's constant. Here's some starter code:
This certain function is as follows:
- Order the number in ascending form and descending form to create 2 numbers.
- Pad the descending number with zeros until it is 4 digits in length.
- Subtract the ascending number from the descending number.
- Repeat.
Given a number n, find the number of times the function needs to be applied to reach Kaprekar's constant. Here's some starter code:
35. Given an expression (as a list) in reverse
polish notation, evaluate the expression. Reverse polish notation is where the
numbers come before the operand. Note that there can be the 4 operands '+', '-', '*', '/'. You can also assume the expression will be well
formed.
Example
Example
Input: [1, 2, 3, '+', 2, '*', '-']
Output: -9
Output: -9
The equivalent expression of the above reverse polish
notation would be (1 - ((2 + 3) * 2)).
36. Given a list of words, for each word find the
shortest unique prefix. You can assume a word will not be a substring of
another word (ie play and playing won't be in the same words list)
Example
Example
Input: ['joma', 'john', 'jack', 'techlead']
Output: ['jom', 'joh', 'ja', 't']
Output: ['jom', 'joh', 'ja', 't']
37. Given an
undirected graph, determine if a cycle exists in the graph.
0 Comments
Please do not Enter any spam link in the comment box