http://www.geeksforgeeks.org/amazon-interview-set-108-campus/
F2F-1:
1) Given a sorted circular link list and a pointer to random node, now insert a new node. I did it , but i used if and else for some special cases in my code so he asked me to do it without if else for special cases (generic & simple code ).
待续
2) Given a string of letters from alphabet. Remove all pairs(2 consecutive same character) of characters which occur consecutively.And do it recursively on remaining string.
Eg given string abcdaadhhhhhzppzl then output string should be : abchl
Stack 就 解决了
3)Populating Next Right Pointers in Each Node
* BFS requires memory space to store Nodes into a queue. Can we do better without extra space?We know this problem requires a recursive solution,My first thought is to use Breadth-First Search (BFS). After all, we are connecting the nextRight node level-by-level, it is only natural to apply BFS to this problem. I mentioned this approach to the interviewer, but he was not too satisfied with it. * */ public class Solution { public void connect(TreeLinkNode root) { if(root == null) return; if(root.left!=null) root.left.next = root.right; if(root.right!=null){ root.right.next = (root.next==null)? null : root.next.left; } connect(root.left); connect(root.right); return; } }
4) hashing
This data structure (the hash table) is a big array of O(n) elements, called buckets.We provide a hash function h(e) that given a set element e returns the index of a bucket that element should be stored into are O(1) on average The worst-case performance of a hash table is the same as the underlying bucket data structure, (O(n) in the case of a linked list) But if we want O(lg n) worst-case performance from our hash tables, we can use a balanced binary tree for each bucket. Each resizing operation takes O(n) time where n is the size of the hash table being resized. Therefore the O(1) performance of the hash table operations no longer holds in the case of add: its worst-case performance is O(n). Modulo the size of buckets.
F2F 3
2) Given a singly link list reverse every 3 nodes and if nodes are less than 3 then reverse them also.
Eg: Input: 1->2->3->4->5->6->7->8 Output: 3->2->1->6->5->4->8->7
3) Given a string of letters from alphabet insert frequency of each character in the string
Eg: Input: aaabbbccdefgggaaa Output: a3b3c2d1e1f1g3a3
public static String func(String str){ char[] c = str.toCharArray(); int count =1; int j=0; int i=1; StringBuffer buf =new StringBuffer(); buf.append(c[0]); while(i<str.length()){ if(c[i]==c[i-1]){ count++; i++; }else{ buf.append((char)(count+'0')); buf.append(c[i]); i++; count=1; } } buf.append((char)(count+'0')); return buf.toString(); }
sBar rasier.
3) What do you understand by 32 bit and 64 bit OS ? . He asked for explanations in terms of hardware and software . Then he asked me that will a 16 bit program run on 64 bit OS without any problem . He asked me what can be the reason for problem faced .
4)What happens when you type www.amazon.in in your browser ? . He asked me for the set of activities that take place during this time . Then he went into asking how do you get to know the IP address of your ISP . Then after a lot of discussion he was satisfied .
what happens when you type in a URL in browser In an extremely rough and simplified sketch, assuming the simplest possible HTTP request, no proxies and IPv4 (this would work similarly for IPv6-only client, but I have yet to see such workstation): browser checks cache; if requested object is in cache and is fresh, skip to #9 browser asks OS for server's IP address OS makes a DNS lookup and replies the IP address to the browser browser opens a TCP connection to server (this step is much more complex with HTTPS) browser sends the HTTP request through TCP connection browser receives HTTP response and may close the TCP connection, or reuse it for another request browser checks if the response is a redirect (3xx result status codes), authorization request (401), error (4xx and 5xx), etc.; these are handled differently from normal responses (2xx) if cacheable, response is stored in cache browser decodes response (e.g. if it's gzipped) browser determines what to do with response (e.g. is it a HTML page, is it an image, is it a sound clip?) browser renders response, or offers a download dialog for unrecognized types