amazon 面經3

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   io   strong   

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 list2) Take "tail" pointer, which will point to end of the first level of the list3) 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  PageIDA          1A          2A          3B          2B          3C          1B          4A          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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.