amazon 面经3

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

amazon 面经3

时间: 2024-10-12 21:18:04

amazon 面经3的相关文章

VMware与宿敌Amazon一笑泯恩仇:重新定义混合云?

[阅读原文] 三年前,虚拟化巨头VMware曾对亚马逊Amazon云服务AWS竖过中指:我们怎么可能打不过卖书的?并严厉警告其合作伙伴:"如果我们的客户都用了AWS公有云,你们统统破产关门!" AWS呵呵:"如果有人认为我们只是书贩子,那好极了!" 随后,VMware在一年一度的VMworld大会上公布了备受瞩目的vCloud Hybrid Service (以下简称vCHS) 混合云服务.而这一项服务的推出,意味着VMware已经走出单一的私有云市场,去拓展更大的

网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息及ISBN码

这一篇首先从allitebooks.com里抓取书籍列表的书籍信息和每本书对应的ISBN码. 一.分析需求和网站结构 allitebooks.com这个网站的结构很简单,分页+书籍列表+书籍详情页. 要想得到书籍的详细信息和ISBN码,我们需要遍历所有的页码,进入到书籍列表,然后从书籍列表进入到每本书的详情页里,这样就能够抓取详情信息和ISBN码了. 二.从分页里遍历每一页书籍列表 通过查看分页功能的HTML代码,通过class="current"可以定位当前页码所在span标签,此s

Amazon EC2分区

亚马逊云主机Amazon EC2主机为开发者提供了一条免费途径不过需要信用卡申请,也蛮麻烦,公司海外业务用到过亚马逊云,个人感觉centos选镜像定制实例挂磁盘和国内差不多,不过亚马逊加的硬盘刚开始进系统是看不到买的盘只能看到默认的20G的盘,需要一个resize2fs初始化脚本才能看到,但是找到脚本以后也是运行不起来,折腾好久,最终几条简单命令解决了,亚马逊云EC2centos挂盘初始化很不人性化, 查看好挂载的那个盘符,然后直接resize2fs 命令初始化分区,然后保存挂载,大概是这样的:

Secrets To Getting Amazon gift card codes To Complete Tasks Quickly And Efficiently

Amazon gift card are not as easy to get if you do not know how to complet a survey . Amazon gift card are difficult and as hard to combact with the survey . So please do not hurry you should try the new method to get free amazon gift card codes . For

HTTPS连接的前几毫秒发生了什么——Amazon HTTPS案例分析

转自: http://blog.jobbole.com/48369/ 提示:英文原文写于2009年,当时的Firefox和最新版的Firefox,界面也有很大改动.以下是正文. 花了数小时阅读了如潮的好评,Bob最终迫不及待为他购买的托斯卡纳全脂牛奶点击了“进行结算”,然后…… 哇!刚刚发生了什么? 在点击按钮过后的220毫秒时间内,发生了一系列有趣的事情,火狐浏览器(Firefox)不仅改变了地址栏颜色,而且在浏览器的右下角出现了一个 小锁头的标志.在我最喜欢的互联网工具Wireshark的帮

Amazon才推众包物流,“京东众包”已红绿上阵,“达达”还手握10万配送大军

据外媒消息,Amazon正在开发一款App,想让大家都来为他家送包裹. Amazon的设想是,在市区招募实体零售商,租用空间或者按包裹向其支付费用.这项服务在内部代号为“On My Way”,目前还在测试阶段,未明确上线时间,也有可能永远不会上线. 平均每天要发350万个包裹的Amazon的状况是,运输成本在去年增长了31%,相比之下,营收增长速度仅为19.5%.去年,Amazon曾短暂测试付费5美元让Uber和出租车司机在旧金山送货,但由于Uber本身就在做物流的事,Amazon最终未能扩大该

AMAZON PRICE TRACKER, AMAZON PRICE HISTORY, AMAZON PRICE DROP ALERT | DROPGG.COM

DropGG.com is the destination for savvy shoppers looking to save money by buying smart. DropGG.com allows you to easily view the recent price history of any product in our vast database and also lets you set email or Twitter price drop alerts for pro

在Amazon EC2上安装VPN服务

操作系统我选的是Amazon Linux,感觉Amazon的定制版更高效,尽管它可能没有Ubuntu那么强大. 安装过程如下: 1. 安装ppp: yum install ppp 2. 下载并安装pptpd: wget http://poptop.sourceforge.net/yum/stable/packages/pptpd-1.4.0-1.el6.i686.rpmrpm -Uhv pptpd*.rpm 3. 修改/etc/ppp/options.pptpd 文件中添加DNS服务器: ms-

【Amazon Linux】免费搭建subversion服务器

Amazon的EC2服务器可以免费试用一年.在这里申请: https://aws.amazon.com/cn/free/ 尝试把它弄成一个svn库来保存代码.按照 http://northwaygames.com/setting-up-subversion-on-amazon-ec2-for-free/ 这里介绍的方法一步一步安装.可是到了最后一步http://主机号/repos/库名 却怎么都不成功. 后来才发现是因为我没有配置Amazon服务器的端口号.点击安全组->编辑 ->添加 —&g

Amazon 解决下载文件乱码

Amazon 解决下载文件乱码 大家在做多个站点的时候,可能会遇到下载下来的报告文件出现乱码. 法国站点和意大利站点均会出现这样的情况,那怎么解决呢? 这是由于编码的问题而导致,在我们读取数据插入到本地数据库的时候,不妨先将格式转成对应国家能正确识别的格式. 在文档中也有看到. 还要一个问题需要说明,由于操作系统设置默认语言的原因,在小国家站点,我们下载下来的报告可能会出现乱码的情况.这种情况很正常,在调用接口的时候,也没有办法去解决直接下载就出现正常编码. 现在的方法是将下载下来的乱码文件,通