This file contains hidden or 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
1) You have been given a triangle of numbers as shown below. You are supposed to start at the top and go to the base of the triangle by taking a path which gives the maximum sum. You have to print this maximum sum at the end. A path is formed by moving down 1 row at each step to either of the immediately diagonal elements. | |
[2], | |
[3,4], | |
[6,5,7], | |
[4,1,8,3] | |
2-4-7-8 | |
2) Given an array of strings, display all the strings that are not prefix of any other string in the array. | |
(Hint #1: Sorting; Hint #2: Trie) |
This file contains hidden or 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
A search engine is badly in need of a feature where it can understand common acronyms, or abbreviations. | |
To begin with, we’d like it to be able to figure out, the expansions of abbreviations which refer to popular organizations, which might include agencies, colleges, universities or companies. | |
Input format | |
The first line contains N. N lines follow. Each line will contain a small text snippet, picked up from either their Wikipedia entry, or the home page of that organization. Each snippet will be a one liner. From each snippet, you need to identify the acronyms/abbreviations, and their expansions. | |
This is followed by N tests, each in a new line. Each of these tests, contains an acronym/abbreviation (not necessarily in the same order) which you will need to expand. | |
Constraints |
This file contains hidden or 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 string s, partition s such that every substring of the partition is a palindrome. | |
Return all possible palindrome partitioning of s. | |
For example, given s = "aab", | |
Return | |
[ | |
["aa","b"], | |
["a","a","b"] |
This file contains hidden or 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 string s, partition s such that every substring of the partition is a palindrome. | |
Return the minimum cuts needed for a palindrome partitioning of s. | |
For example, given s = "aab", | |
Return 1 since the palindrome partitioning ["aa","b"] could be produced using 1 cut. |
This file contains hidden or 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 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. | |
A region is captured by flipping all 'O's into 'X's in that surrounded region . | |
For example, | |
X X X X | |
X O O X | |
X X O X | |
X O X X |
This file contains hidden or 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 binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. | |
An example is the root-to-leaf path 1->2->3 which represents the number 123. | |
Find the total sum of all root-to-leaf numbers. | |
For example, | |
1 | |
/ \ |
This file contains hidden or 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 an unsorted array of integers, find the length of the longest consecutive elements sequence. | |
For example, | |
Given [100, 4, 200, 1, 3, 2], | |
The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4. | |
Your algorithm should run in O(n) complexity. |
This file contains hidden or 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
/* | |
* 给定一个表达式2^i*2^j,其中i,j为非负整数。请找到一种方法,生成如下序列: | |
* 2^0 * 5^0 = 1 | |
* 2^1 * 5^0 = 2 | |
* 2^2 * 5^0 = 4 | |
* 2^0 * 5^1 = 5 | |
* 2^3 * 5^0 = 8 | |
* 2^1 * 5^1 = 10 | |
* 2^4 * 5^0 = 16 | |
* 2^2 * 5^1 = 20 |
This file contains hidden or 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 two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: | |
Only one letter can be changed at a time | |
Each intermediate word must exist in the dictionary | |
For example, | |
Given: | |
start = "hit" | |
end = "cog" | |
dict = ["hot","dot","dog","lot","log"] |
This file contains hidden or 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 two words (start and end), and a dictionary, find all shortest transformation sequence(s) from start to end, such that: | |
Only one letter can be changed at a time | |
Each intermediate word must exist in the dictionary | |
For example, | |
Given: | |
start = "hit" | |
end = "cog" | |
dict = ["hot","dot","dog","lot","log"] |