Amazon Interview Question
SDE1sCountry: United States
I think this would be easier... Note: don forget to write code to populate the tree
import java.util.List;
public class RobNTree
{
static int max;
static class TreeNode
{
int val;
List<TreeNode> kids;
}
public static void main(String[] args)
{
max = 0;
TreeNode root = null;
// populate tree
if (root != null)
traverse(root, 0);
System.out.println("The max possible loot is " + max);
}
private static void traverse(TreeNode node, int sum)
{
sum += node.val;
if (node.kids.isEmpty())
max = (sum > max) ? sum : max;
else
for (int i = 0; i < node.kids.size(); i++)
traverse(node.kids.get(i), sum);
}
}
Howdy Mate,
Amazon Interview Question for SDE1s being contrived to exist for many projects simply so it can be run will be the first to hit the wall, but those projects where the functions to make existing transactions cheaper in real world applications will find the elusive real world demand.
I recently attended the AWS Summit London 2018. During the afternoon session about "Open Source at AWS" there were some resources mentioned for persuading your company that open source can be a great benefit to them.
Unfortunately this wasn't one of the slide sets which has been made available after the event.
Follow my new blog if you interested in just tag along me in any social media platforms!
Cheers,
Radhey
Looking for coaching on interview preparation?
Visit AONECODE.COM for ONE-TO-ONE private lessons by FB, Google and Uber engineers!
System Design (for candidates of FB, LinkedIn, AMZ, Google and Uber etc)
Algorithms (DP, Greedy, Graph etc. advanced algorithms and clean coding)
Interview questions sorted by companies
Mock Interviews
Ace G, U, FB, Amazon, LinkedIn, MS and other top-tier interviews in weeks of training.
Feel free to email us aonecoding@gmail.com with any questions. Thanks!
SOLUTION:
- aonecoding April 01, 2018