Amazon face Sutra 3

Source: Internet
Author: User

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; // find a value smaller than num [I] int COUNT = 1; set. remove (Num [I]); // remove in time to reduce the later search time while (set. contains (next) {set. remove (next); next --; count ++;} next = num [I] + 1; // find a value larger than 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.