当了5年亚马逊面试官,我总结出了一套算法面试经验
很多同学反馈亚麻的面试一直是状况不断,喜怒无常。
亚马逊面试需要注意哪些?
亚麻的OA一般有3轮
算法题来自题库,都比较简单
比较麻烦的是OA3的Work Simulation和logic题
需要多看面经提前了解题型和考察的内容
OA1
多为debug题,20分钟7道题目,网上面经很全
OA2
通常是coding题,两道题70min
OA3
Work Simulation 120分钟
logic选择题35分钟
下面给大家一道亚马逊2021最新算法面试真题感受一下:
LintCode 1457.
查找子数组
题目描述
给定一个数组arr和一个非负整数k,你需要从这个数组中找到一个连续子数组,使得这个子数组的和为k。返回这个子数组的长度。如果有多个这样的子串,返回结束位置最小的,如果还有多个,返回起始位置最小的。如果找不到这样的子数组,返回-1。
数组的长度不超过106,数组中每个数小于等于106,k不超过106。
扫码免费做题
样例1:
输入:arr=[1,2,3,4,5] ,k=5
输出:2
解释:
该数组中,最早出现的连续子串和为5的是[2,3]。
样例 2:
输入:arr=[3,5,7,10,2] ,k=12
输出:2
解释:
该数组中,最早出现的连续子串和为12的是[5,7]。
解题思路
先求出前缀和,然后对每一个前缀和,查找与k的差值是否被标记,标记了直接return,否则在map上做标记。时间复杂度O(n)。
代码
classSolution:
"""
@param arr: The array
@param k: the sum
@return: The length of the array
"""
deflent(self, arr):
return len(arr)
defsearchSubarray(self, arr, k):
# Write your code here
n = self.lent(arr)
sum = 0
maps = {}
maps[sum] = 0;
st = n + 5;
len = 0;
for i in range(0, n):
sum += arr[i]
if sum - k in maps:
if (st > maps[sum - k]):
st = maps[sum - k]
len = i + 1 - maps[sum - k]
if sum notin maps:
maps[sum] = i + 1;
if (st == n + 5):
return-1;
else:
return len;
关键词
算法
数组中
题目
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。