http://www.geeksforgeeks.org/amazon-interview-set-107/
F2F-I:
1) Brief discussion on work in current company
2) Flatten linked list – http://www.geeksforgeeks.org/flatten-a-linked-list-with-next-and-child-pointers/
The problem clearly say that we need to flatten level by level. The idea of solution is, we start from first level, process all nodes one by one, if a node has a child, then we append the child at the end of list, otherwise we don’t do anything. After the first level is processed, all next level nodes will be appended after first level. Same process is followed for the appended nodes. 1) Take "cur" pointer, which will point to head of the fist level of the list 2) Take "tail" pointer, which will point to end of the first level of the list 3) Repeat the below procedure while "curr" is not NULL. I) if current node has a child then a) append this new child list to the "tail" tail->next = cur->child b) find the last node of new child list and update "tail" tmp = cur->child; while (tmp->next != NULL) tmp = tmp->next; tail = tmp; II) move to the next node. i.e. cur = cur->next
3) Design a data structure which holds number 1 to n such that insert, remove(this operation will take in a number between 1 to n as argument and remove that number from data structure if it exists) and get valid element in the data structure operations are done with O(1) complexity
what is it the maximum number of the elements
combination array and hashtable
F2F-2:
1) Brief discussion of work in current company
2) Find and print longest consecutive number sequence in a given sequence
Ex: Input: 1 2 5 3 6 8 7 Output: 5 6 7 8
public class Solution { public int longestConsecutive(int[] num) { Set<Integer> set = new HashSet<Integer>(); for (int i : num) { set.add(i); } int max = 0; for(int i=0; i<num.length; i++){ if(set.contains(num[i])){ int next = num[i] - 1; // 找比num[i]小一个的值 int count = 1; set.remove(num[i]); // 及时的移除,减少之后的查找时间 while(set.contains(next)){ set.remove(next); next--; count++; } next = num[i] + 1; // 找比num[i]大一个的值 while(set.contains(next)){ set.remove(next); next++; count++; } max = Math.max(max, count); } } return max; }
3) A fair die is thrown k times. What is the probability of sum of k throws to be equal to a number n?
F2F-3:
1) Brief discussion of work in current company. Why Amazon?
2) Why do you want to leave current company? What do you like most and dislike most about your current company?
3) Sum two numbers represented by linked list iteratively and recursively.
public class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode c1 = l1; ListNode c2 = l2; ListNode sentinel = new ListNode(0); ListNode d = sentinel; int sum = 0; while (c1 != null || c2 != null) { sum /= 10; if (c1 != null) { sum += c1.val; c1 = c1.next; } if (c2 != null) { sum += c2.val; c2 = c2.next; } d.next = new ListNode(sum % 10); d = d.next; } if (sum / 10 == 1) d.next = new ListNode(1); return sentinel.next; } }
4) You are given an infinite sorted array containing only numbers 0 and 1. Find the transition point efficiently.
divide and conquer
1) Lots of HR, behavioral and team fit questions
2) User statistics are logged in the following format –
user_id|page|time at which page was accessed We need to identify most followed 3 page sequence by users. Example: Input: U1|Page1|05/08/2014 10:00 U1|Page2|05/08/2014 10:01 U1|Page3|05/08/2014 10:02 U1|Page4|05/08/2014 10:03 U2|Page2|05/08/2014 10:02 U2|Page3|05/08/2014 10:04 U2|Page4|05/08/2014 10:05 U3|Page3|05/08/2014 10:04 U3|Page4|05/08/2014 10:05 U3|Page5|05/08/2014 10:06 Output: Most followed 3 page sequence for the input is Page2 -> Page3 -> Page4.
Userid PageID
A 1
A 2
A 3
B 2
B 3
C 1
B 4
A 4
Find the most frequent visit sequence of page-ID:
for A : 1-2-3, 2-3-4
for B : 2-3-4
so, 2-3-4 is the most frequent.
smaill elements:
Put each item of the file into map1<key:user_id, list<pageID> >. When list.size() == 3, create a new struct three_hits to hold the three pageID. Put it in into map2<struct three_hits, int counter>. Then, find the item in map2 with largest counter value.
huge elements:
If you want to quickly get an approximate result, use hash tables, as you intended, but add a limited-size queue to each hash table to drop least recently used entries. If you want exact result, use external sort procedure to sort logs by userid, then combine every 3 consecutive entries and sort again, this time - by page IDs. Why not just cut the log file into slices that are each big enough to hold in memory
原文:http://www.cnblogs.com/leetcode/p/3898513.html