grave
- 22
0of 0 votes
AnswersGiven a string containing only digits, restore it by returning all possible valid IP address combinations.
- grave on September 07, 2012 in India Edit | Report Duplicate | Flag
For example:
Given "25525511135",
return ["255.255.11.135", "255.255.111.35"]{hint:recursion,backtrack}
Amazon Software Engineer / Developer Algorithm - 28
0of 0 votes
AnswersGiven a m * n matrix and value k. Find k * k matrix within the given matrix whose sum is maximum.
- grave on August 12, 2012 in India Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm Matrix - 52
0of 0 votes
AnswersFind the longest
- grave on August 05, 2012 in India Edit | Report Duplicate | Flag
subarray which consists of numbers that can be arranged in a continuous sequence.
For ex- {4,5,1,5,7,6,8,4,1}
output-{5,7,6,8,4}.Find the longest.
Amazon Software Engineer / Developer Algorithm Coding - 24
0of 0 votes
AnswersGiven a stream of text eg you can read 1 char at a time, write fn that will return true if you can find a string str is in the stream before the stream runs out.Do not store the stream.
- grave on August 05, 2012 in India Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm String Manipulation - 17
0of 0 votes
AnswersPrint all combinations of M members of a set of N elements in a sequence such that each set can be obtained from the previous set by deleting one member and adding one member.
- grave on August 03, 2012 in India Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm Coding - 32
0of 0 votes
AnswersGiven the Pre-order of the BST .check if each non-leaf node has only one child.Linear Time is expected.
- grave on July 31, 2012 in India Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 14
0of 0 votes
AnswersGiven a boolean matrix where 0 represent the blank and 1 represent the dot.So,dots form a image.Find the number of images.i.e.
- grave on July 25, 2012 in India Edit | Report Duplicate | Flag
You have to find the number of blocks having continuous 1s.
11000
01001
10011
00000
10101
here,it is 5 images.
Amazon Software Engineer / Developer Algorithm - 7
0of 0 votes
AnswersDelete the tree completely.Tree need not be a binary tree.
- grave on July 25, 2012 in India Edit | Report Duplicate | Flag
Write clean code.
Amazon Software Engineer / Developer Algorithm - 16
0of 0 votes
AnswersGiven a1a2a3a4...anb1b2b3b4..bnc1c2c3..cn.
- grave on July 25, 2012 in India Edit | Report Duplicate | Flag
Convert this array to
a1b1c1a2b2c2...anbncn.
Amazon Software Engineer / Developer Algorithm - 14
0of 0 votes
AnswersGiven a Binary tree,find the level at which the tree is complete.Complete Binary tree-All leaves should be at same level and every internal node should have two children.
- grave on July 25, 2012 in India Edit | Report Duplicate | Flag
Asked to write both Recursive and iterative code.
Amazon Software Engineer / Developer Algorithm Trees and Graphs - 15
0of 0 votes
AnswersCreate the n-ary tree from the ancestor matrix.
- grave on July 19, 2012 in India Edit | Report Duplicate | Flag
matrix[i][j]=1 if i is the ancestor of j.
My answer-
find the root (row with all zeroes).
Set the column with a[i][root] =0
find all the rows with all zeroes.insert into the tree all the children.and push all into the queue.
pop and find the children ,insert into the tree with popped node as parent and push into the queue.
Can not implement properly as it needed some modifications.
This is asked from my friend at amazon bangalore.
Amazon Software Engineer / Developer Algorithm Arrays Data Structures Trees and Graphs - 19
0of 0 votes
AnswersTokenize the given string.
- grave on July 16, 2012 in India for kindle Edit | Report Duplicate | Flag
node* strtok(char* input ,char* delims)
Put the words seperated into the linked list and return the linked list.delims can be a single character or group of characters like "abc".
Dictate the code as you write.
Amazon Software Engineer / Developer Algorithm Coding String Manipulation - 51
0of 0 votes
AnswersGiven two strings .Print all the interleavings of the two strings.
- grave on July 10, 2012 in India Edit | Report Duplicate | Flag
Interleaving means that the if B comes after A .It should also come after A in the interleaved string.
ex-
AB and CD
ABCD
ACBD
ACDB
CABD
CADB
CDAB
Google Software Engineer / Developer Algorithm String Manipulation - 35
0of 0 votes
AnswersGiven an array which contains the parent of the ith element in the n-ary tree.Parent[i] = -1 for root.
- grave on July 07, 2012 in India Edit | Report Duplicate | Flag
Find the height of the tree.
Gave O(n2) ,space O(1).
Expected Complexity- Linear
You can use extra space if you want.
Example-
{-1 0 1 6 6 0 0 2 7}
0 1 2 3 4 5 6 7 8
0 is the root here.
0 is the parent of 1 5 6
1 is parnt of 2
6 is parent of 3 4
2 is of 7 which is parent of 8.
Amazon Software Engineer / Developer Algorithm Data Structures Hash Table Trees and Graphs - 44
0of 0 votes
AnswersFind the(two) nodes which are at maximum distance in a binary tree?
- grave on May 31, 2012 in India Edit | Report Duplicate | Flag
This is not finding the distance but the nodes which are farthest.
Amazon Software Engineer / Developer Algorithm Data Structures Trees and Graphs
node* leftmostcousin(node* root, int level,int value)
{
if(root == NULL)
return NULL;
if(level<=0)
return NULL;
if(level ==1 &&(root->left->data == value ||root->right->data == value))
return NULL;
if(level ==1)
{
if(root->left)
return root->left;
else if(root->right)
return root->right;
else
return NULL;
}
node * lefti = leftmostcousin(root->left,level-1,value);
if(lefti !=NULL)
return lefti;
else
return leftmostcousin(root->right,level-1,value);
return NULL;
}
Can we do,
take increasing sequence from root and monotonic decreasing sequence from root and compare.
After comparing number of elements and all elements are same.
e.g. {10 12 13 11 4 2 6 } and {10 12 11 13 4 6 2}
from 1st array 10,12,13 from second 10,12,13
decreasing 10 4 2 and 10 ,4,2
?
int noSibSum(node* root)
{
if(root == NULL ||(root->left==NULL && root->right == NULL))
return 0;
if(root->left!=NULL && root->right == NULL)
return root->left->data + noSibSum(root->left);
else if(root->right!=NULL && root->left == NULL)
return root->right->data+noSibSum(root->right);
else{
return noSibSum(root->left)+noSibSum(root->right);
}
}
I think,this can be like number of connected components.
We can do dfs from a 1 do dfs upto we find a zero.Also maintain another matrix which records if the cell is visited or not.then we can choose next 1 which is not visited and do dfs from there.
Comments or Solution?
You just have to make ips from the given string.Why you are appending 0s?
- grave on September 08, 2012 Edit | Flag View Reply