GeeksforGeeks » Interview Questions
Amazon Hyderabad Interview Question
(7 posts)-
Reverse a binary search tree in such a manner so that parent child relationship maintained and left child become right child and vice versa.
Find the minimum and maximum element in stack in O(1).
given an array find the next minimum element in array for each element. for example if give array is 4,2,1,5,3 resultant array would be 2,1,-1,3,-1.
Given two string A and B . remove each character from string A which occur in B. if a occur 2 times in B remove 2 a from A.
Given an array find the Median of array in minimum time complexity.
make copy of a linked list which has two pointer one point to next node and other one point to arbitrary node in linked list.
if u will access data from a social networking site such as Facebook . suggest some method to remove latency to access data.
Given a coordinate system in which there are n points. you have to calculate the m minimum points from some origin point. Suggest a data structure for this.
some question on has data structure.Given a linked list and some no n . you have to reverse the node of linked list in pair of n. consider all test cases for this.
Given a array where the difference between two consecutive element is 1. Given a no find that no in array in minimum time complexity.
how to check singly linked list is palindrome or not.
Given a preorder of binary tree such that in tree each node have either 0 or two childern. and each leaf node is represented by N. construct a tree from this.
you have given a string of multiline. you have to print the maximum occupancy word in each line and if there is some capital letter in each line then print each capital letter occupancy and then small letter occurancy. ex given string is
Abccddegdkshsl
aghdoiuuaknclna
AHBalowknxxbb
ajhduiaklaLLL
your o/p should be :
A -1, d-3
a-3
A-1,H-1,B-1,x-2,b-2
L-3,a-3one question related to password matching you have given some precondition for password then user input some password then you will validate the password with each condition if any one condition failed then you have to show password Rejected.
-
Reverse a binary search tree in such a manner so that parent child relationship maintained and left child become right child and vice versa.
void covertToMirror(struct node* root) { if(root != NULL) { // convert letf and right subtress covertToMirror(root->left); covertToMirror(root->right); // swap left and right pointers for root struct node *temp = root->left; root->left = root->right; root->right = temp; } } -
Find the minimum and maximum element in stack in O(1).
See http://www.geeksforgeeks.org/archives/14149 -
given an array find the next minimum element in array for each element. for example if give array is 4,2,1,5,3 resultant array would be 2,1,-1,3,-1.
Method 1
1) Travers the arrat and build a balanced BST of array elements
2) Again traverse the array and find inorder predecessor of every array element.Method 2
1) Sort the array and store the sorted array in inother temp array
2) For each element in the original array, find the smaller element using modified binary searchIf the order is not important, then only first step will do.
-
Given two string A and B . remove each character from string A which occur in B. if a occur 2 times in B remove 2 a from A.
See http://www.geeksforgeeks.org/archives/353Given an array find the Median of array in minimum time complexity.
Can be done in O(n) time. Google for order statisticsmake copy of a linked list which has two pointer one point to next node and other one point to arbitrary node in linked list.
http://www.geeksforgeeks.org/archives/1155 -
finding a number in array...any two consecutive number differ by 1
int find(int arr[],int size,int num) { int j=0; while(j<size) { if((arr[j]-num)==0) return j; else j+=abs(arr[j]-num); } return -1; } -
preorder..construct tree.. 0 child or 2 child of a node.
N represents leaf node in stringint i=0;
char str[]="12N4NN5NN";
int len=strlen(str);
node * root=make(str,i,len);node * make(char str[],int &i,int len) { node *x; x = new node; x->data=str[i]; //for leaf nodes if((str[i]=='N')||(str[i]=='n')) { x->left=x->right=NULL; return x; } if((i+1)<len)//checking end of string { i++; x->left=make(str,i,len); if((i+1)<len) //checking end of string { i++; x->right=make(str,i,len); } } return x; }
Reply
You must log in to post.