grave
BAN USER 21of 27 votes
AnswersYou are given two array, first array contain integer which represent heights of persons and second array contain how many persons in front of him are standing who are greater than him in term of height and forming a queue. Ex
 grave in India
A: 3 2 1
B: 0 1 1
It means in front of person of height 3 there is no person standing, person of height 2 there is one person in front of him who has greater height then he, similar to person of height 1. Your task to arrange them
Ouput should be.
3 1 2
Here  3 is at front, 1 has 3 in front ,2 has 1 and 3 in front. Report Duplicate  Flag  PURGE
Google Software Engineer / Developer Algorithm  0of 0 votes
AnswersDesign a tree, in which a node can have unlimited children and write a code to print each level in separate level.
 grave in India
(As the number of children is large we cant store them in queue.Can we do it without extra space ?) Report Duplicate  Flag  PURGE
Amazon SDE1 Algorithm  1of 1 vote
AnswersTwo files containing large number, one in each. You have only fopen(), int read(fp), fclose(), fwrite(). Add these two numbers and write in third file with the help of given functions only.
 grave in India Report Duplicate  Flag  PURGE
Amazon SDE1 Algorithm C# C++ Coding Data Structures  1of 1 vote
AnswersGiven a string containing only digits, restore it by returning all possible valid IP address combinations.
 grave in India
For example:
Given "25525511135",
return ["255.255.11.135", "255.255.111.35"]{hint:recursion,backtrack} Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm  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 in India Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm String Manipulation  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 in India Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm Coding  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 in India
You have to find the number of blocks having continuous 1s.
11000
01001
10011
00000
10101
here,it is 5 images. Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm  0of 0 votes
AnswersGiven a Binary tree,find the level at which the tree is complete.Complete Binary treeAll leaves should be at same level and every internal node should have two children.
 grave in India
Asked to write both Recursive and iterative code. Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm Trees and Graphs  0of 0 votes
AnswersCreate the nary tree from the ancestor matrix.
 grave in India
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. Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm Arrays Data Structures Trees and Graphs  0of 0 votes
AnswersTokenize the given string.
 grave in India for kindle
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. Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm Coding String Manipulation  5of 5 votes
AnswersGiven two strings .Print all the interleavings of the two strings.
 grave in India
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 Report Duplicate  Flag  PURGE
Google Software Engineer / Developer Algorithm String Manipulation  1of 1 vote
AnswersGiven an array which contains the parent of the ith element in the nary tree.Parent[i] = 1 for root.
 grave in India
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. Report Duplicate  Flag  PURGE
Amazon Software Engineer / Developer Algorithm Data Structures Hash Table 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,level1,value);
if(lefti !=NULL)
return lefti;
else
return leftmostcousin(root>right,level1,value);
return NULL;
}

grave
August 05, 2012 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);
}
}

grave
July 28, 2012 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?
Repggeraldinejrivera, Aghori Mahakal Tantrik at ABC TECH SUPPORT
I am a fashion model, talented in runway turns and photoshoot prep. I Have worked at two displaying organizations and ...
Replarryehickl, Associate at ABC TECH SUPPORT
I am a blogger in the Geek system operator . As an editor with a strong background in english and hindi ...
What is square root of an algorithm ?
 grave June 27, 2013Though, we can find the square root in O(logn) using binary search.
make low as 0 and high as number.
if mid*mid ==n then mid is square root if lesser,low mid+1
else high = mid1
This wont work if the number is not perfect square.
We can use newton raphson method for that.