mail.kshitij.jain
BAN USER- 2of 2 votes
Answers"Given an array of strings, find the string which is made up of maximum number of other strings contained in the same array.
- mail.kshitij.jain in India
e.g. “rat”, ”cat”, “abc”, “xyz”, “abcxyz”, “ratcatabc”, “xyzcatratabc”
Answer: “xyzcatratabc”
“abcxyz” contains 2 other strings,
“ratcatabc” contains 3 other strings,
“xyzcatratabc” contains 4 other strings"| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersGiven a class with n people,where each people plays a game with all other people. Results are with you. You have to arrange them in a queue with a condition that, a[i] should have won a[i-1], for all I, you don’t need to care about a[i-2] . (a[i] may win or lose a[i-2]).
- mail.kshitij.jain in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 2of 2 votes
AnswersYou are given an array whose each element represents the height of the tower. The width of every tower is 1. It starts raining. How much water is collected between the towers?
- mail.kshitij.jain in India
Eg. [1,5,3,7,2] – then answer is 2 units between towers 5 and 7.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm
Here is the solution of this problem :
private static int getMaxWeight(Node root) {
int a = 0;
int b = 0;
if (root == null) {
return 0;
}
if (root.left != null) {
a = getMaxWeight(root.left.left) + getMaxWeight(root.left.right);
}
if (root.right != null) {
b = getMaxWeight(root.right.left) + getMaxWeight(root.right.right);
}
int x = root.val + a + b;
int y = getMaxWeight(root.left) + getMaxWeight(root.right);
if (x >= y) {
return x;
} else {
return y;
}
}
Simple Respect!!! Awesome man !!!! kudos
- mail.kshitij.jain October 07, 2013