刚刚参加完Amazon的面试,来写一下自己的面试过程。我申请的是SDE-1的职位。面试流程是2轮电面,4轮Onsite. 一开始是电面。 第一轮 电面 1 翻转字符串 reverse words in a string。 LintCode原题: http://www.lintcode.com/en/problem/reverse-words-in-a-string/ 参考答案: http://www.jiuzhang.com/solutions/reverse-words-in-a-string/ follow-up: 翻转的时候如何处理空格 划分数组。 LintCode原题: http://www.lintcode.com/zh-cn/problem/partition-array/ 参考答案: http://www.jiuzhang.com/solutions/partition-array/ 第二轮 电面2 链表求和。要求O(n)的时间复杂度。 LintCode原题: http://www.lintcode.com/zh-cn/problem/add-two-numbers/ 参考答案: http://www.jiuzhang.com/solutions/reverse-words-in-a-string/ Find all ancestors of LCA. 给出两个节点,打印出两个节点的所有公共祖先节点,算法也就是找出最近公共祖先(LCA),然后打印root到LCA的所有节点。 LintCode原题: http://www.lintcode.com/zh-cn/problem/lowest-common-ancestor/ 参考答案: http://www.jiuzhang.com/solutions/lowest-common-ancestor/ follow-up: 问了一些关于堆和宽度优先搜索(heap & BST)的知识点。像是什么时候用宽度优先搜索,这个在《九章算法班》有讲。 电面结束后几天,HR告诉我面试通过了,并安排我去参加Onsite. 第三轮 Onsite 1 面试官先是问了我一些简历上的问题,比如我简历上的项目经验,问的还算比较细。 接着问了1道算...
【题目描述】 Given a set of distinct integers, return all possible subsets. Notice:Elements in a subset must be in non-descending order;The solution set must not contain duplicate subsets. 给定一个含不同整数的集合,返回其所有的子集 注意:子集中的元素排列必须是非降序的,解集必须不包含重复的子集 【题目链接】 http://www.lintcode.com/en/problem/subsets/ 【题目解析】 子集类问题类似Combination,以输入数组[1, 2, 3]分析,根据题意,最终返回结果中子集类的元素应该按照升序排列,故首先需要对原数组进行排序。题目的第二点要求是子集不能重复,至此原题即转化为数学中的组合问题。我们首先尝试使用 DFS 进行求解,大致步骤如下: [1] -> [1, 2] -> [1, 2, 3] [2] -> [2, 3] [3] 将上述过程转化为代码即为对数组遍历,每一轮都保存之前的结果并将其依次加入到最终返回结果中。 【答案链接】 http://www.jiuzhang.com/solution/subsets/