注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
- 給一個target, 跟array, 計算大於target的count, 跟小於target的count,大的比較多就回傳greater, 反之smaller,一樣就回傳tie
- 給一個initial state, season, day,回傳最後這個幾月幾號的state。月亮的週期是八天,八種state, 給initial state是這一年第一天的state。season / day代表幾月幾號
第三题:给一个n * m matrix和一个commands (list of command), example of commands ["reverseRow r", "swap r1, r2", "rotate"],
"reverseRow r": given row index r (int), reverse the number in this row
"swap r1, r2": given row index r1, r2, swap
"rotate": rotate the matrix 90 degree, clockwise
return the matrix after implementing all the commands
第四題:
给一个list,每个数字代表index,返回目前为止最长的连续sequence。比如【2,3,0,4】,就返回【1,2,2,3】。因为最开始“2”的长度是1,加入3后变 “2,3”长度为2,加入“0”并不连贯,还是2,然后加入4变成“2,3,4”长度为3。
太長了寫不完....掛
——————
Summary
2025 Oct to 2026 Jan
第四题: give a list of integer and a number, return the number of pair such that the combination is the same to the given number.
e.g. numbers = [1, 212, 12, 12], target = 1212,
pair 1: numbers[0], numbers[1]=>1, 212 => 1212
pair 2: number下规则改变array,返回需要多少轮能到最终状态
如果array末尾的'P'数量大于或者等于replacement rate,去除末尾的‘P‘,去除数量为replacement rate
如果array里有'A’,把最后一个'A’换成'P’
否则,到达最终状态
3
【’A’,’A’,’P’】
【’A’,’P’,’P’】
【’P’,’P’,’P’】
【】
ANS:
=>停止的條件:
沒有’A’
‘P’少於replacement rate
能用數學嗎?不然就用暴力解
———
第三题,memory allocation and removal,给一个1d array (memory)和一个2d array (queries)。每个query要么allocate memory,要么根据id,erase memory。
ANS:
代码量比较大,直接写就行
———
第四题,给一个数组和整数(distance),找数组里数值最接近的两个数,这两个数的距离要不小于distance。好像是利口原题,记不清了。
ANS:
應該是sort之後用sliding window/ two pointer
Left, right都從左邊開始,
增加窗口:遍歷右邊
縮減窗口:在Left, right的距离要不小于distance清況下
回傳最後的答案
O(n lg n)
———
第二题:将一数组(A)拆分为两组(B和C),对一元素a,若B中比a大的元素数目比C中比a大的元素数目要多,则将a放入B中,否则放入C中。若平局,则放入B、C中较短的,若再平局,放入B中。(不要求最佳解)
[1,2,3,4,5]
=>
[1,3,5]
[2,4]
ANS:
先sort之後,分別放入B跟C
|