Amazon Interview Question for Backend Developers


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

@ ajay.raj HOW MANY INTERVIEWS YOU DO ? I saw you post a lot of questions for different companies!!!

- Mehdi March 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Mehdi. Haha true. I think he just gets the interview questions from various companies and posts them. I don't think he physically attends that many interviews or I might be wrong. Or he might be the interviewer himself and might share the questions. :P :D

- prudent_programmer March 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class NodeScanner {

	  static class Node{
	    String key;
	    String value;
	    
	    List<Node> children = new LinkedList<>();
	    Node parent;
	    
	    public Node(){
	    	  key = "";
	    	  parent = null;
	    	}
	
		public Node(String key, Node parent){  
			this.key = key; 
			this.parent = parent; 
		}
	
		public void addChild(Node e){ children.add(e); }
	
		private List<String> getChildrensKeys(){
		  List<String> keys = new LinkedList<>();
		  children.stream().forEach(e -> keys.add(e.key));
		  return keys;
		}
	  }


	static class Tree{
		Node root;
		
		public Tree(){ root = new Node(); }

		boolean isEmpty(){ return root.key == ""; }


		public Tree(String str){
			this();
			Scanner sc = new Scanner(str.trim()).useDelimiter("><|>|<");
			parse(root, sc);
		}

		public void walk() { printNode(root); }

		private void printNode(Node n){
			System.out.printf("<%s>\n%s\n", n.key, n.value);
			for(Node child : n.children)
				printNode(child);
			System.out.printf("</%s>\n", n.key);
		}


	private void parse(Node cur, Scanner sc){
		String v = sc.next();
		Node next;
		if(cur.key == ""){
			cur.key = v;
			next = cur;
		}else 
			if(v.matches("^node[0-9]{1,}$")){
				Node n = new Node(v, cur);
				cur.addChild(n);
				next = n;
			}else 
				if(v.matches("^/node[0-9]{1,}$")){
					next = cur.parent;
			}else{
				cur.value = v;
				next = cur;
			}
		
		if(sc.hasNext())
			parse(next,sc);
	}

}

/*
 * 
 * <node0>
 * 000000
 * 		<node1>
 *  		11111
 *  			<node3>3333</node3>
 *  			<node2>
 *  			2222
 *  				<node5>5555555</node5>
 *  				<node6>66</node6>
 * 			</node2>
 * 		</node1>
 * </node0>
 * 
 * */
	public static void main(String[] args) {
		String str = "<node0>000000<node1>11111<node3>3333</node3><node2>2222<node5>5555555</node5><node6>66</node6></node2></node1></node0>";
		Tree tree = new Tree(str);
		tree.walk();
	}

}

- lareinev March 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class NodeScanner {

	  static class Node{
	    String key;
	    String value;
	    
	    List<Node> children = new LinkedList<>();
	    Node parent;
	    
	    public Node(){
	    	  key = "";
	    	  parent = null;
	    	}
	
		public Node(String key, Node parent){  
			this.key = key; 
			this.parent = parent; 
		}
	
		public void addChild(Node e){ children.add(e); }
	
		private List<String> getChildrensKeys(){
		  List<String> keys = new LinkedList<>();
		  children.stream().forEach(e -> keys.add(e.key));
		  return keys;
		}
	  }


	static class Tree{
		Node root;
		
		public Tree(){ root = new Node(); }

		boolean isEmpty(){ return root.key == ""; }


		public Tree(String str){
			this();
			Scanner sc = new Scanner(str.trim()).useDelimiter("><|>|<");
			parse(root, sc);
		}

		public void walk() { printNode(root); }

		private void printNode(Node n){
			System.out.printf("<%s>\n%s\n", n.key, n.value);
			for(Node child : n.children)
				printNode(child);
			System.out.printf("</%s>\n", n.key);
		}


	private void parse(Node cur, Scanner sc){
		String v = sc.next();
		Node next;
		if(cur.key == ""){
			cur.key = v;
			next = cur;
		}else 
			if(v.matches("^node[0-9]{1,}$")){
				Node n = new Node(v, cur);
				cur.addChild(n);
				next = n;
			}else 
				if(v.matches("^/node[0-9]{1,}$")){
					next = cur.parent;
			}else{
				cur.value = v;
				next = cur;
			}
		
		if(sc.hasNext())
			parse(next,sc);
	}

}

/*
 * 
 * <node0>
 * 000000
 * 		<node1>
 *  		11111
 *  			<node3>3333</node3>
 *  			<node2>
 *  			2222
 *  				<node5>5555555</node5>
 *  				<node6>66</node6>
 * 			</node2>
 * 		</node1>
 * </node0>
 * 
 * */
	public static void main(String[] args) {
		String str = "<node0>000000<node1>11111<node3>3333</node3><node2>2222<node5>5555555</node5><node6>66</node6></node2></node1></node0>";
		Tree tree = new Tree(str);
		tree.walk();
	}
}

- Anonymous March 27, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More