貢獻者 : 秘客 Cypto
模擬面試錄影(漢)
模擬面試錄影(漢)
模擬面試錄影(英)
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 →
: Interviewee9. Palindrome 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 →
: 那我想請你實作一個function,輸入是一個整數,回傳此整數是否符回文的規定。
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 →
: 好的,所以我需要製作一個function,檢查輸入進來的整數是否頭尾對應的數字相同,如果對應數字都相同就代表是回文數值對嗎?
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 →
: 是的。
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 →
: 好,那舉例來說 : 121、2442 ,這些都是符合條件的數字,356,就是不符合回文的。
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 →
: 那就我現在的觀察來說,因為要前後進行比對,所以我先把數字轉變成字串的型態,然後用兩個指標,一個從前面一個從後面,利用迴圈開始進行比對。
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 →
:那我想請問一下題目是否有規定輸入述職的大小範圍。
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 →
: 有的,介於 -232 跟 232 之間。
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 →
: 好那我就開始進行實作。
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 →
: 那你是否有辦法不轉換成字串來進行判斷?
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 →
: 好的,那我這邊的想法是先做出一個反轉過來的數字,再跟原本的數字去進行比對。
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 →
: 這邊就是我利用數值運算所做出的function,想請問對於我的方法有沒有什麼問題。
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 →
: 沒有,第一題的面試就到這邊結束。同儕檢討
- 00:03 不要講第幾第幾道題目
- 00:26 對稱的數字聽起來不是很直覺(以不知道回文的定義來說)到底是從中間切開用鏡子來看一樣(eg.151不是回文,101是回文),還是真正回文的定義(151 和 101 都是回文)。
- 00:36 這邊舉例就可以把上面那一點簡單的的說明一下。
- 01:33 char 宣告大小的取捨。
- 05:39
retrun x;
這裡沒有考慮到 0 這個整數的問題,會回傳 false 而不是 true 。
- 11:25 跟上個一樣
return x;
沒有考慮到 0 的狀況。
- 12:29 把
if(x<0||(x%10 == 0 && x!=0)) return false;
放到 int tmp = 0;
前面會比較好一點。
- 13:34 最後面的
if
可以用以下寫法會比較簡潔。
- 13:36 是不是可以比較一下時間跟空間複雜度之於這兩種不同方法。
針對 interviwer 的檢討:
- 應該要稍微講解回文定義,interviweee才能夠更好理解題目。
- 應該要主動講出給定數值的範圍,這樣對於interviwer會比較好構思。
- 針對 follow-ups,可改為給定數值的二進位型態 (binary representation) 是否為 palindrome,這樣問題不僅更貼合現實應用場景,還能看出 interviewee 的程式設計基本功 (如 bitwise 運算)
針對 interviwee 的檢討:
- 在選擇利用字串進行處理時要考慮到空間複雜度的問題,如果字串設太大會有空間浪費
- 如果限制不能使用乘法和除法運算,那 bitwise 運算就是關鍵,可見以下實作:
上方程式碼之改進如下:
- 第 13 行: q 得到的結果逼近 0.79999999981 倍的 x,約為 0.8x
- 第 15 行: q 除以 8 得到逼近 0.1x (x/10)
- 第 16 行:
qq & ~7UL
為將最右邊三個 bits 設為 0,相當於 q << 3
- 第 17 行: x - (0.2x + 0.8x),x - (x/10)*10 取得最後一個位數
- 第 18 行: 因為此計算方式是模擬除以 10,當 rem > 9 時,代表有誤差存在,q (商) 比預期少 1,故 q += 1、rem -= 10
- 以測資 INT_MAX (2147483647) 進行測試會發現 q 的誤差剛好是 1
- 在第 15 行新增以下程式碼印出 q 值
(點擊展開) 得到以下結果:
- 第 20 行: rev = (2 * rev + 8 * rev ) + rem = 10 * rev + rem
24. Swap Nodes in Pairs
測驗說明問與答
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 →
: 第二個問題,給定一個linked list,請你寫出一個function將linked list裡面的每兩個node進行互換,且不能夠直接改變node裡面的value。
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 →
: 好的,所以我需要把這個linked list裡面的node兩個為一組進行交換,且不能夠透過直接改值來完成。
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 →
: 舉例來說[1,2,3,4]經過function交換過後應該會變為,[2,1,4,3]。
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 →
: 我的想法是既然不能夠改值,那就是直接對linked list連接的位址去進行變動,利用迴圈兩兩一組進行改動下去。同儕檢討
- 01:00 我覺得這題的題目沒有敘述得很清楚,到底是 (1,2) 互換 (3,4) 互換還是 (1,2) 先換 (2,3) 再換…以此類推。所以我會問得更詳細一點。
- 03:51 NULL 發音問題,而且
if(head->next != NULL)
這個部分,如果輸入值為[]
的時候,會有存取空指標的錯誤產生。
針對 interviwer 的檢討:
- 不能直接改node值,應該要明說不能直接改node裡的value值會比較好。
針對 interviwee 的檢討:
- 在講程式中間的指標變換的時候可以把current等等標記在範例上,會比只用說的更好去理解。
21. Merge Two Sorted Lists
測驗說明問與答
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,next problem. You are given the heads of two sorted linked lists .
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 →
: Please Merge the two linked list into one sorted linked list , and return the head of the merged linked list .
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 need to merge two linked list and keep the merged linked list be sorted .
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 , list1 = [1,3,5] 、 list2 = [2,4,6] , result = [1,2,3,4,5,6] .
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 →
: My ideal is to compare this two's front node , and put the minimum node into new linked list untill all node is finish .針對 interviwer 的檢討:
- 應該要提供linked list的資料結構定義,interviwee會比較方便撰寫程式。
針對 interviwee 的檢討: