注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
刚刚做了亚麻 AS Intern的OA
. .и- 在Hackerrank上
- 70min 2题
- 把地里所有相关的帖子整理了一遍发现就五道题,然后把答案都写了一遍。
- 最后发现我抽到的题目不在那五道题里面哈哈哈哈
Anyway
我抽到的是这两题,感觉过于简单了,不知道是不是因为亚麻打算摆烂不招人了
- Reverse Array Queries 这个直接搜stackoverflow 里面有一样的 不过本来也很简单
- Validating Strings with RegEx 这个直接搜 利口 里面有讨论这题的 答案应该是这个 r'^(.).*\1$|[ab]$'
.--
下面是我整理的5道历史题目和我自己结合资料做的答案 ..
求加米!!(
A list of unique product IDs needs to be extracted from a database of products available on Amazon's website. In the database, multiple versions of the products IDs exist such that the order of the characters varies (e.g, code and ecod are the same product). To create the unique list, all anagrams must be removed. Two strings are anagrams if they are permutations of each other. In other words, both strings have the same size and the same characters. For example, ""aaagmnrs"" is an anagram of "anagrams"". Given an list of strings, remove each string that is an anagram of an earlieositive integer values that evenly divide into a number) and then return the p element of the list, sorted ascending. If there is no p" element return 0.. Waral dи,
Example
n 20. 1point3acres
p =3
. 1point 3 acres
The factors of 20 in ascending order are (1, 2, 4 5, 10, 20). Using 1- based indexing, if p =3, then 4 is returned. If p > 6, 0 would be
. .и
n = 20. 1point3acres
p = 3- <div>def ith_factor(n,p):</div><div> factor = [[i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0]</div><div> factor = sorted(sum(factor, []))</div><div> if p > len(factor):</div><div> return 0</div><div> else:</div><div> return(factor[p-1])</div><div>
- </div><div>ith_factor(20,3)</div>
复制代码 4
[url]https://assets.leetcode.com/users/images/b2d78610-ec5a-4130-b798-41375791c8ee_1647994025.476528.png[/url]
这题原来的答案不太对 我按照讨论里的重新修改了下~- <div>def droppedRequests(requestTime):</div><div> requestDrop = 0</div><div> request01 = []</div><div> request10 = []</div><div> request60 = []</div><div>. 1point3acres
- </div><div> for i in range(len(requestTime)):</div><div> currRequest = requestTime[i]</div><div>
- </div><div> currTime = currRequest</div><div> pre01 = max(currTime - 1, 1)</div><div> pre10 = max(currTime - 9, 1)</div><div> pre60 = max(currTime - 59, 1)</div><div>. Waral dи,
- </div><div> drop01, drop10, drop60 = False, False, False</div><div>
- </div><div> while request01 and request01[0] < currTime:</div><div> request01.pop(0)</div><div> while request10 and request10[0] < pre10:</div><div> request10.pop(0)</div><div> while request60 and request60[0] < pre60:</div><div> request60.pop(0)</div><div> </div><div> request01.append(currRequest)</div><div> request10.append(currRequest)</div><div> request60.append(currRequest)</div><div>
- </div><div> if len(request01) > 3:</div><div> drop01 = True</div><div> if len(request10) > 20:</div><div> drop10 = True</div><div> if len(request60) > 60:</div><div> drop60 = True</div><div> </div><div> if drop01 or drop10 or drop60:</div><div> requestDrop += 1</div><div> </div><div> return requestDrop</div><div>a = [1,2,3,4]</div><div>a[1:3] = a[2:0:-1]</div><div>a</div><div>[1, 3, 2, 4]</div><div>droppedRequests([1,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,11,11,11,11])</div>
复制代码 |