Contributor: 六六 Leo
video
Google Docs
面試過程
Repeat
- Interviewer: Hi, I'm today's interviewer. If you are ready. let's get started. Suppose we have an integer array nums sorted in non-decreasing order, please write a function that returns an array of the squares of each number sorted in non-decreasing order.
- Interviewee: Let me make sure I understand the problem correctly. What is the range of the element of input array?
- Interviewer: The element of the input array is between 10,000 and negative 10,000.
- Interviewee: How many elements at most in the input array?
- Interviewer: 10,000 elements
- Interviewee: Can the input array be empty?
- Interviewer: No, you can assume the input array has at least one element.
- Interviewee: Should I sort the array in-place or out-of-place?
- Interviewer: You should not modify the input array. Please use an out-of-place appoarch.
Examples
- Interviewee: No problem. So if I have an array
[1, 2, 3]
then I should returns [1, 4, 9]
right?
- Interviewer: Yes.
- Interviewee: If a have an array
[-2, -1, 0, 1, 2]
, then I should returns [0, 1, 1, 4, 4]
.
- Interviewer: Yes.
Approach
- Interviewee: Thanks for clarifying. In this problem. I would first allocate a memory space for the output array, which has the same length as the input array. Its element is the squares of each element of input array with the same index. Finally, sort the output array.
- Interviewer: Good. Can you write down the code?
Code
Optimization
- Interviewer: It looks no problem. But if the length of input array grows, what does the execution time be affected?
- Interviewee: As the length of input array grows, the execution time will grows in an level.
- Interviewer: Is there a better way?
- Interviewee: Yes, we can use the techniques of two pointers to optimize the execution time to .
- Interviewer: Can you explain the
- Interviewer: We don't have much time left. I think this is good enough. So That's the interview for today. Thank you for your time.
video
Google Docs
面試過程
Repeat
- Interviewer: Given an integer , check if it is a power of 2.
- Interviewee: So if the number is power of 2, then returns
true
. Ohterwise returns false
, right?
- Interviewer: Yes.
- Interviewee: What is the range of the input number ?
- Interviewer: is between negative 2 to the power of 31 and 2 to the power of 31 minus 1 ().
Examples
- Interviewee: So if is negative or 0, then I should return
false
, right?
- Interviewer: Yes.
Approach
- Intervieree: I would use the recursive method. If n is not divisible by 2, it is definitely not a power of 2, then return
false
. If n is divisible by 2, then continue to check if n/2 is a power of 2 until n/2 equals 2.
- Intervieree: And before entering the recusive function, I would first check if is positive
Code
Optimization
- Interviewer: Well, it looks no problem. Can you figure out another method that execute in constant time?
- Interviewee: OK, let me give it a try. I would like to observe the binary representation of the power of two by writing it down. And then we can find it that if a number is the power of 2, then its binary representation would be a 1 followed by several or no 0s. Otherwise, would not be power of 2. Therefore, we can check if is power of 2 by masking with
video
Google Docs
面試過程
Repeat
Interviewer: 同學你好,我是今天的面試官,讓我們開始今天的面試。首先給定一個字串 s
,請你依照裡面每個字元出現的頻率做遞減排序,也就是出現次出越高的字元排在前面,出現次數越少的字元排在後面,最後將排序好的字串回傳,如果有多種可能的排法,則回傳其中一種即可。
Examples
Interviewee: 好的,所以說我要針對一個字串中的字元頻率做排序,也就是如果 s
是 "tree"
,那我得回傳 "eert"
,如果 s
是 "cccaaa"
,那回傳 "cccaaa"
或 "aaaccc"
都可以,對嗎?
Interviewer: 對,你理解得沒錯
Approach
Interviewee: 針對這題我會使用 hash map 的方式,先計算字串中每個字元出現的次數,然後對次數做排序,最後產生要回傳的字串
Interviewer: 好的,請你將程式碼實作出來
- count the frequency of characters
- sort by frequency
- generate output string
Code
Interviewer: 好的程式碼看起來沒什麼問題,那我們時間差不多了,今天的面試就先告一段落,謝謝
初步檢討
- REACTO 的 Test 並沒有確實執行
- 第三題 (451. Sort Characters By Frequency) 的程式實作中,
map
的記憶體用完應該要記得用 free
釋放掉
第二次作業 - 他評 01
Interviewer
Interviewee
第二次作業 - 他評 02
Interviewer
- 題目部分,不要直接給定 Leetcode 題號,容易讓受訪者背誦題目。
- 跟interviewee沒有太多互動,像是在考試一樣。
Interviewee
- 舉例清楚,撰寫程式時的註解也有幫助理解的功用
- A 的部分一條條列出來,對理解想法上有幫助。
- R 的部分跳過了,直接快進到了 E 的部分。
- 知道自己在講什麼,實作上的細節都有講到,但可以稍微放慢速度,略顯緊張
第二次作業 - 他評 03
Interviewer
- (第一題) 06:27: "Can you come up with a better way?" 可以改成更明確的說法,像是 "How can you improve the time complexity?",可以讓 interviewer 不需要揣測要做什麼。
Interviewee
- 在寫程式的時候,filler (如 uh) 有點多。可以稍微有點沉默,等確定想好以後再一次把句子講完。
- (第一題) 07:07: 講解比較大小的條件時,可以把條件和要做的事情寫成 pseudo code,會比直接聽更好懂。
- (第二題) 06:20: 「因為使用遞迴,所以時間複雜度是 )」,應該可以改成說「如果 n 為二的 k 次方,則需要呼叫遞迴函式 k 次,也就是 次,因此時間複雜度為 」,會解釋得比較清楚。
第二次作業 - 他評 04
Interviewer
Interviewee
- 英文講得很好
- 打字速度很快,排版整齊
- 對問題的提問很全面
- 寫程式時會一邊寫一邊解釋程式,很棒
- 第一題 two pointer 講解很清楚,用 ^ 在 array 的下一行代表pointer是個好方法
- 第三題寫程式前先用註解寫大綱很清楚的表達了程式內容
第二次作業 - 他評 05
Interviewer
- 避免自稱 interviewer
- 0:00:除了口頭帶過題目,也在螢幕上顯示題目
- 避免使用 LeetCode 原題,建議適度做更改,或結合實例
Interviewee
- 咬字清楚,語速與音量適當
- Repeat 及 Example 部分 解釋得非常清楚,非常棒
- Coding 部分有做到邊寫程式邊做講解,令人刮目相看
- 1:22:向面試官詢問能否進行 in-place 排序,展現自己的細心