This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
Given a non-empty array of digits representing a non-negative integer, plus one to the | |
integer. The digits are stored such that the most significant digit is at the head of | |
the list, and each element in the array contain a single digit. You may assume the | |
integer does not contain any leading zero, except the number 0 itself. | |
Examples: | |
Input: [1,2,3] | |
Output: [1,2,4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
Given a matrix of m x n elements (m rows, n columns), return all elements of the | |
matrix in spiral order. | |
Examples: | |
Input: | |
[ | |
[ 1, 2, 3 ], | |
[ 4, 5, 6 ], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
There is a new alien language which uses the latin alphabet. However, the order among | |
letters are unknown to you. You receive a list of non-empty words from the dictionary, | |
where words are sorted lexicographically by the rules of this new language. Derive the | |
order of letters in this language. | |
- You may assume all letters are in lowercase. | |
- You may assume that if a is a prefix of b, then a must appear before b in the given dictionary. | |
- If the order is invalid, return an empty string. | |
- There may be multiple valid order of letters, return any one of them is fine. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
A 2d grid map of m rows and n columns is initially filled with water. We may perform | |
an addLand operation which turns the water at position (row, col) into a land. Given | |
a list of positions to operate, count the number of islands after each addLand | |
operation. An island is surrounded by water and is formed by connecting adjacent lands | |
horizontally or vertically. You may assume all four edges of the grid are all | |
surrounded by water. | |
Example: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
Given a non-empty array of integers, every element appears twice except for one. Find | |
that single one. The algorithm should have a linear runtime complexity. | |
Examples: | |
Input: [2,2,1] | |
Output: 1 | |
Input: [4,1,2,1,2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
Given a list of unique words, find all pairs of distinct indices (i, j) in the given | |
list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. | |
Examples: | |
Input: ["abcd","dcba","lls","s","sssll"] | |
Output: [[0,1],[1,0],[3,2],[2,4]] | |
parlindromes are: ["dcbaabcd","abcddcba","slls","llssssll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
Given a string S and a string T, find the minimum window in S which will contain all | |
the characters in T in complexity O(n). | |
- If there is no such window in S that covers all characters in T, return the empty string "". | |
- If there is such window, you are guaranteed that there will always be only one unique | |
minimum window in S. | |
Examples: | |
Input: S = "ADOBECODEBANC", T = "ABC" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
Convert a non-negative integer to its english words representation. Given input is | |
guaranteed to be less than 2**31 - 1. | |
Examples: | |
Input: 123 | |
Output: "One Hundred Twenty Three" | |
Input: 12345 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a char array representing tasks CPU need to do. It contains capital letters A to | |
Z where different letters represent different tasks.Tasks could be done without | |
original order. Each task could be done in one interval. For each interval, CPU could | |
finish one task or just be idle. However, there is a non-negative cooling interval n | |
that means between two same tasks, there must be at least n intervals that CPU are | |
doing different tasks or just be idle. | |
You need to return the least number of intervals the CPU will take to finish all the | |
given tasks. | |
- The number of tasks is in the range [1, 10000]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Description: | |
Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, | |
there may exist one celebrity. The definition of a celebrity is that all the other | |
n - 1 people know him/her but he/she does not know any of them. | |
Now you want to find out who the celebrity is or verify that there is not one. The only | |
thing you are allowed to do is to ask questions like: "Hi, A. Do you know B?" to get | |
information of whether A knows B. You need to find out the celebrity (or verify there | |
is not one) by asking as few questions as possible (in the asymptotic sense). |