作者: 詮贏慕 fullscreen
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Interviewee
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Interviewer
模擬面試錄影(漢)
模擬面試錄影(英)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Hi my name is fullscreen.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Hi fullscreen, I'm your interviewer. Here is your questions.
Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.
Here are some constrains:
n is euqal to the length of nums.
1 <= n <=
0 <= nums[i] <= n
All the numbers are unique.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Will all the number be integers?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Yes they are.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: So the I will be given n distinct numbers in the range from 0 to n, which the range contains n+1 numbers. My job is to find the missing number that is in the range.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: You are right.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: For example, given input [2, 3, 1, 4], I should output 0. Given input [0], I should output 1.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Yes!
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ok, I think I can use an naive iterative approach. I iterate over and keep the record of the value I've seen. Finally return unseen value. Which will be time complexity and space complexity because I need an array to keep track of what numbers I've seen.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Sounds straight forward for me. Can you code it out?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Oh, wait. I actually have an better solution. I sum all the numbers in and store it in a variable . And sum all the number from 0 to and store it in variable . Then I just need to subtract from to get the missing numbers!! In this approach I'll have a time complexity of but a much less space complexity of .
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Can you show me why this method works?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Sure. Here is the proof.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Great now let's see how you will implement this.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ok. First, let's define a function that accept a vector<int>
as the input and returns an int
.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Next, we want to get sum of and sum of and subtract the two to get the missing number.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Now, let's implement get_sum_of_range
. We can use the mathematical formula.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: And get the sum of nums by iterating through the nums.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: So we will have the final code like this.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Let's plug-in some test case to see if the code work.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Greate can you tell me what's the time and space complexity of your implementation?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Sure. Let's talk about time complexity first. I iterated through the whole array to get its sum, so get_sum_of_vector
is . I use the math formula to calculate sum of range, so get_sum_of_range
is . So the total time complexity is .
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ok~ What about space complexity?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Because I did not use any data structure with size that is related to the input array's length so this implementation have a space complexity of .
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Okay let's spice thing up a little bit. What if the have integers. And all the element is between inclusive. And there is only one number that is repeated at least twice. Can you find a way to get this reapeated number? Try to solve it without modifying the and use only constant extra space. (287. Find the Duplicate Number)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: So now I have an array of interger. All of the integer a in the range of . And there is only one number that is repeated. And the number of time of the repetition is at least twice. My job is to find the repeated number is that correct?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: You are right.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: For example
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: You are right. What approache are you going to use?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: The first things that comes to mind is a brute force solution. I keep a array of counter of each number in the range of . And I iterate over the array to count the occurance of each number. If any counter reach 2 then I return the number. This solution runs and did not modify the array but use space.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: If I can sort the array the problem will be easy. I just need to iterate over the arrary once and check if any neighborhood number are the same. But I'll either have to copy or modify the array if I want to sort the array. But either of them is allowed. This one is hard.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ok, I'll give you a hint if you can prove that there is at least one duplicate number in .
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Because all the numbers have to be in the range of but there are numbers in the arrary. By pigeonhole principle there must be at least one number that is duplicated.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ok, here is your hint. This problem can be solved using binary search in time complexity and constant space complexity without modifying the arrary.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Umm, interesting. To my understanding, usually we will apply binary search on list that is sorted. But in this problem I'm not allowed to modify the array. And usually you will have a time complexity if you are using binary search.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Seems like I will have to apply binary search times. Maybe it is like iterate over the array every time I do a binary search.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: You are very close.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: The array is not sorted. But the range of interger is like a sorted array. Maybe you want me to do a binary search in ?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Yes your are very very close.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ah ha! I think I got a solution. If every element in the arrary is unique. And we only have n elements in the array. And the elements are all in the range of . Then each number in actually represent the number of elements in the arrary that is smaller or equal to the number. For example 2 means there are 2 number (1, 2) that is smaller or equal to the number.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: But if there are duplications in the array, then this balance will be broken. Or we should say that if the equation holds that means the duplicate number is not below the number we are checking.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Interesting, can you implement your idea?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Sure! First we need a function that take an array as input and output an interger.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Let's type out some comment to show my thoughts.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Let's implement it.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: And let's plug in some examples.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Great, I think you did a great job. Thank you for participate in our interview today.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Thankyou!同儕互評 - 01
Interviewee
- 優點
- 05:48 : interviewee 主動提出更好的做法,掌握主導權,藉此吸引 interviewer 的目光,有助於增加面試的互動性。
- 撰寫程式碼時的思考流程很有條理,看起來不像是死背答案的 interviewee
- 缺點
- 程式碼的行距可以小一點, 可以看到比較多行,畫面也不會一直上下滾動。
Interveiwer
- 優點
- 20:40 : Interviewer 沒有直接給提示,而是引導 interviewee 思考,順便可以檢驗 interviewee 的數學能力,讓整個面試增加更多互動。
- 缺點
- 13:30 : Interviewer 還是可以說明題目,增加互動機會,不要讓 interviewee 自己去讀。
- 30:06 : 可以針對 interviewee 的想法提出問題,增加互動性
- 37:40 : 沒有針對 interviewee 的程式碼做提問,也沒有針對此問題的後續應用做出更多討論,錯失驗證 interviewee 能力的機會。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Here is another problem for you, fullscreen.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: So I will be given an integer array with integer greater or equal to 0 and less or equal to . Each element in the array represent the maximum jump I can make. And I'm initially at index 0 of the array. I need to decide wheather I can reach the last index. Return true if I can, otherwise return false.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: For example:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: You are correct. Do you have any other questions?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Yes, I do. Am I allow to make backward jump and wrapping around when exceed the boarder? For example if the input is [1, 0, 0]
, can I jump from index 0 to the last index?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Good question, jump does not wrap around when you exceed the boarder.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ok, I think I understand the question fully. What I have in mind right now is recursion. Starting from the last index I check which index are able to lead me to the last index. I'll then check if any of these indexes is 0. If there is, then I return true. Otherwise, I will push those candidates in a queue. And pop the next item in the queue to perform the check again.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Sounds good, can you show me the code?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Ok, so I need a function which take a integer array as input and return a boolean.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Let's write some comments to illustate what I mean.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Let's write some code.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: The get_reachables
function will take an array of integer and a integer (represent the current index) as input. And it will return an array of integers as output.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Starting from the index before the current index. We check the index backward until we reach index 0. Let the current index is and the index we are checking is , and , we push index into the output array.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: So the overall code looks like this.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Let's plugin some test case to see if the algorithm is correct.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Greate, what is the space and time complexity of this algorithm?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: The time complexity is because for each element we will need to check at most n-1. And the space complexity is because we could have push n-1 candidate to the stack at each check.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Can you think of a better solution?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
If we don't check the element we already check then we can reduce our time complexity to . We can use a vector to store the index we have check. And this modification will give us a space complexity of .
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Can you do it better? Like time complexity and space complexity ?
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: I think I can modify the solution. I iterate through the and record the farest index I can reach. If the farest index I can reach is the last index, then I return true. Otherwise, return false.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: This method have an time complexity and a space complexity .
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
: Very good. I think that is it for today. Thank you for your participation.同儕互評 - 01
Interviewer
- 優點
- 缺點
- 01:03 : 與其照唸題目,不如多舉些例子,讓 interviewee 更了解題目需求
- 06:14 : 這邊不應該對 interviewee 的想法照單全收,要適時的針對 interviewee 的想法提出問題 (例如:為什麼用 stack 比用 queue 好?有什麼好處?),與其讓 interviewee 盡快寫程式(讓死背考題的 interviewee 有機可趁),不如先檢驗 interviewee 解決問題的能力以及相關程式能力。
- 16:22 : 從
16:22
- 21:11
interviewee 花了將近5分鐘在代數字測試, 也許 interviewer 可以適時的打斷,直接問更深入的問題(例如:應用場景、如何優化…等),畢竟 interviewer 看完程式碼就應該知道 interviewee 的思路是否正確,不需要再浪費時間代數字。
- 25:40 : 與其直接問 interviewee 「有沒有更好的解法」,不如用討論的方式對 interviewee 的程式碼做優化,畢竟這些 interviewee 將來可能會是你的同事,不如藉此機會來測試 interviewee 的溝通與合作能力。
Interviewee
- 優點
- 撰寫程式碼時的思考流程很有條理,看起來不像是死背答案的 interviewee
- 缺點
同儕互評 - 02
-
面試者
- 01:30追問題目細節、主動給予範例、討論 edge-case,都很流暢
- 05:49 講完 brute-force 就直接講能不能做得更好,自問自答雖然很積極,但也可以考慮先暫停一下,讓面試官有機會插嘴問一些問題。
- 11:11 把測資帶進寫好的程式碼驗證也很棒
- 20:15 在做完一定分析後,勇敢要提示,很棒 (而不是什麼都沒講就要提示)
-
面試官
- 00:02 確認面試者名字時,講"是吧?" 有可能挑起對方一點不舒服的情緒
- 01:25 面試官也許可以一開始講解題目時就給一些範例
- 13:24 變化版的題目,可以嘗試由面試官直接講解,而不是讓面試者自己看,因為面試時間通常不會太長,除非就是要考驗面試者閱讀問題的能力,不然建議可以由面試官簡潔的講完問題並強調重點後,留更多的時間讓面試者闡述想法
- 20:17 在面試者請求提示時,先問他一些問題來引導,我覺得是很棒的互動
- 37:35 可以問問看,什麼時候、或在什麼應用中,會需要用到你們今天討論到的內容
初步檢討
- interviewer 照著題目念,並沒有把題目稍微修改,這樣遇到死背解法的就無法發現
- interviewee 可以舉一些該演算法或是問題在日常生活的應用,趁機展現自己的知識
- binary search 的時間複雜度一般來說是,影片裡有講錯