Ajay Kumar
BAN USER- 0of 0 votes
AnswersGiven deck of cards let se 50 cards, now all are thrown on a table, after throwing some cards of them are now with face up and some are with face down, tell the probability of sum of all the face up cards is divisible by 7.
- Ajay Kumar in United States for Google Docs
Assume cards from 1 to 10, Answer should be generic so that we can get results for any number of cards, don't compare cards with playing cards, cards can be numbered from 1 to n| Report Duplicate | Flag | PURGE
Google Software Engineer Algorithm - 0of 0 votes
AnswersFind the successor of a node in inorder traversal.
- Ajay Kumar in India for Development| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 1of 1 vote
AnswersAlgorithm to check a linked list is palindrome or not, each node contains a single character.
- Ajay Kumar in India for Development| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersHow to store a binary tree in a file so that we can re construct the same tree with that file
- Ajay Kumar in India for Development| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersGiven two nodes of a tree, find the first common ancestor of these node.
- Ajay Kumar in India for Development| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer - 0of 0 votes
AnswersWhat data structure you will use if you have to implement google map like utility, you will be able to search the city, you will be able to find shortest path between two nodes. And you have to implement one more feature of auto suggestion which means if user type "Na" then you should show all the cities starting with letter Na in a list. And algo should be very efficient because it should update things as soon as user changes the typed character.
- Ajay Kumar in India for Development| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
public static int maxSumWithK() {
int[] a = { 1, 1, 1, 1, 1, 1, 1 };
int k = 2;
int maxSum[] = new int[a.length];
int sum = a[0];
maxSum[0] = sum;
for (int i = 1; i < maxSum.length; i++) {
sum += a[i];
if (sum > a[i]) {
maxSum[i] = sum;
} else {
maxSum[i] = a[i];
sum = a[i];
}
}
sum = 0;
for (int i = 0; i < k; i++) {
sum += a[i];
}
int max = sum;
for (int i = k; i < maxSum.length; i++) {
sum = sum + a[i] - a[i - k];
if (sum + maxSum[i - k] > max)
max = sum + maxSum[i - k];
}
return max;
}
- Ajay Kumar May 13, 2017According to me 5 objects will get created, A, B, C, AB and ABC.
- Ajay Kumar July 18, 2014What about store group as string eg: "0-25", which ca be used as key in a HashMap. By this way we can retrieve element in constant time :)
- Ajay Kumar May 27, 2014What If, If I put bottles one by one on the weighting machine and keep checking the weights, every time when we put bottle of same weight the total weight will be multiple of weight of one bottle but as soon as we put less weight bottle it will be less than that, and thus we come to know which bottle is less heavy, not sure It might be a very bad idea ;)
- Ajay Kumar May 05, 2014What about this??
private HashMap<Integer> count=new HashMap<Integer>();
public void printInteger(int a) {
synchronized (count) {
while (count.contains(a)) {
try {
count.wait();
} catch (InterruptedException e) {
}
System.out.println(a);
count.remove(a);
return;
}
}
}
Idea is ok, but I dont think above code will work correctly, as synchronization is not been taken care while putting element into the Map.
- Ajay Kumar April 12, 2014Why we are calculating the arrays, we just need to find which element will seat in middle if we will make such an array which can be done in constant time. Give reasons If you don't agree.
Thanks
What is minimum sequence length? Like in case of 11, will it be acceptable?
- Ajay Kumar March 13, 2012What is minimum sequence length? Like in case of 11, will it be acceptable?
- Ajay Kumar March 13, 2012What is minimum sequence length? Like in case of 11, will it be acceptable?
- Ajay Kumar March 13, 2012What is minimum sequence length? Like in case of 11, will it be acceptable?
- Ajay Kumar March 13, 2012What is minimum sequence length? Like in case of 11, will it be acceptable?
- Ajay Kumar March 13, 2012What is minimum sequence length? Like in case of 11, will it be acceptable?
- Ajay Kumar March 13, 2012What is minimum sequence length? Like in case of 11, will it be acceptable?
- Ajay Kumar March 13, 2012How will you traverse a singly list from both sides right to left and left to right?
- Ajay Kumar February 27, 2012you have to do this with minimum traversal, traversing whole tree is not an optimal solution.
- Ajay Kumar February 27, 2012
O(n) solution:
}
- Ajay Kumar May 13, 2017