--- tags: info2023-homework1 --- # 2023 年「[資訊科技產業專案設計](https://hackmd.io/@sysprog/info2023)」作業 1 > 貢獻者: 失去倪-RBIN > [模擬面試錄影(漢)](https://www.youtube.com/watch?v=iC9Obe5UjUc) > [模擬面試錄影(漢)](https://www.youtube.com/watch?v=uiTcoU3Ksns) > [模擬面試錄影(英)](https://youtu.be/c8N6OdbDMMs) ## [9. Palindrome Number](https://leetcode.com/problems/palindrome-number/) ### 面試過程 ```c bool isPalindrome(int x){ if(x<0 || x!=0 && x%10 ==0 ) return false; int check=0; while(x>check){ check = check*10 + x%10; x/=10; } return (x==check || x==check/10); } ``` > Time complexity: $O(n)$ > Space complexity: $O(1)$ 針對 interviewer 的檢討: 針對 interviewee 的檢討: ## [11. Container With Most Water](https://leetcode.com/problems/container-with-most-water/) > 影片 ### 面試過程 - [ ] Brute force ```c int maxArea(int* height, int heightSize){ int max = height[0], hgt = 0, temp = 0, result = 0; if(heightSize == 1){ return height[0]; } else{ for(int i = 0; i < heightSize - 1; i++){ for(int j = 1; j < heightSize; j++){ if(height[i] < height[j]){ hgt = height[i]; } else{ hgt = height[j]; } temp = (j - i) * hgt; if(temp > result){ result = temp; } } } } return result; } ``` > Time complexity: $O(n^2)$ - [ ] 從兩側端點找 ```c int maxArea(int* arr, int N){ int max = 0,test,i=0,j=N-1; while(j>i){ test = arr[i]; if(test>arr[j]) test = arr[j]; test = (j - i) * test; if(max < test) max = test; if(arr[i] < arr[j]) i++ ; else j--; } return max; } ``` > Time complexity: $O(n)$ ## [7. Reverse Integer](https://leetcode.com/problems/reverse-integer/) ### 面試過程 ```c int reverse(int x){ int j = 1, res = 0; for(int i = 0; i < j; i++){ if(res > INT_MAX / 10 || res < INT_MIN / 10){ return 0; } res *= 10; res += x % 10; x /= 10; if(x != 0){ j++; } } return res; } ``` > Time complexity: $O(n)$ > Space complexity: $O(1)$ --- ## 他評-01 ### interviewer - [ ] 可改進之處 - [0:28](https://youtu.be/uiTcoU3Ksns?t=28) 題目說明過於詳細 ### interviewee - [ ] 優點 * [3:01](https://youtu.be/iC9Obe5UjUc?t=181): 在撰寫程式碼時,有說明這個程式碼的意義 - [ ] 可改進之處 * 在程式碼完成之後,可以用先前舉的例子來驗證(Test) ## 他評 - 02 - [ ] 優點 * [Palindrome Number](https://leetcode.com/problems/palindrome-number/) [1:10](https://www.youtube.com/watch?v=iC9Obe5UjUc): 實作時,有先將此解法的重點概念講出來 (`check = check * 10 + x % 10`),後續實作時才把其他細節補上 * 寫程式時有一直說明自己的想法,沒有停頓太久 * [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) 一樣寫程式時有一直說明自己的想法,沒有停頓太久。這次執行 Optimization 的部分 - [ ] 可改進之處 * [Palindrome Number](https://leetcode.com/problems/palindrome-number/) * 要確實依照 REACTO 的步驟去解題 * [5:58](https://www.youtube.com/watch?v=iC9Obe5UjUc): 提到時間複雜度 $O(n)$ 時,可以口頭提一下 $n$ 為 `x` 的長度 * 除了對數值本身進行運算的解法,Interviewer 還可以提問有沒有其他作法 (因為 Palindrome Number 還有許多解法,例如雙重指標或遞迴的寫法,可參考[這篇文章](https://matthung0807.blogspot.com/2019/10/java-palindrome-string.html)) * [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) * REACTO 的 Repeat 與 Example 建議要簡單 * 可以說明一下 Space Complexity * 變數的宣告與使用要多加注意 : * [2:16](https://www.youtube.com/watch?v=uiTcoU3Ksns): 宣告了 `max`,但後面沒用到 * [2:19](https://www.youtube.com/watch?v=uiTcoU3Ksns): `hgt` 與 `temp` 只是在迴圈中用於比較的變數而已,一開始就宣告有點奇怪。另外,宣告這些變數時可以提一下它個別的功能是做什麼的 * [7:23](https://www.youtube.com/watch?v=uiTcoU3Ksns): `test` 也是一樣 * [10:05](https://www.youtube.com/watch?v=uiTcoU3Ksns): 移動指標的狀況建議說明清楚,或是 Interviewer 可以從這部分切入問題 * 像是「為何可以利用判斷 `arr[i]` 與 `arr[j]` 的大小關係,來選擇要移動的指標?」(可參考 Leetcode 上的[這個 Solution](https://leetcode.com/problems/container-with-most-water/solutions/6100/simple-and-clear-proof-explanation/)) :::spoiler 上述問題之原因 1. 假設此回合 `arr[i]` 比較小,代表此回合的 Container 是以 `arr[i]` 做為高度 2. 而當要選擇移動哪個指標時,會選擇 `arr[i]`,因為++我們期望在 `arr[i]` 右側會有比它還大的元素,該容量會比此回合的 Container 還大++ 3. 反之,若選擇 `arr[j]` 作為移動的指標,不管後續有沒有走訪到更大的元素,Container 的高度仍會受到 `arr[i]` 所限制 ::: ## 他評-03 - [ ] 可改進之處 * 錄影遮蔽處過多,無法看到肢體動作,喪失檢討的效益 ## 他評-04 ### interviewer - [ ] 可改進之處 * [0:28](https://youtu.be/uiTcoU3Ksns?t=28): 滑鼠不該一直繞圈,會讓面試者不太舒服。 * 可以用一些實際的例子包裝題目。 * 面試可以做一些延伸,例如 Palindrome Number可以討論如果轉成string再做判斷的好處會是甚麼?因為在某些情況下整數的運算其實是很耗時的。 ### interviewee - [ ] 優點 * 口齒清晰,解題過程有條有序。 - [ ] 可改進的地方 * 可以近一步完善REACTO所有步驟,例如Test。 ## 他評-05 ### interviewer - [ ] 優點 * 題目非常的簡短且簡單明瞭,也能夠把題目英文單詞轉換成中文,這樣interviewee如果對於中文的熟悉度更高的話有機會一聽到關鍵字就建構程式碼。 - [ ] 可改進的地方 * 第一題的題目在設計上比較缺乏可優化的屬性,如果可以的話應該要設計一些解可能有很多種,但是各種解之間可能具有可優化的關聯性的題目。 ### interviewee - [ ] 優點 * 可以在不了解題目清楚意涵的時候就提出問題,以幫助面試順利進行,如此一來可以幫助後續的面試過程更順利,只要專注於程式碼的優化以及撰寫就好。 - [ ] 可改進的地方 * 比較缺乏驗證的步驟,如果可以用簡單的例子順過一次各個解法,這樣對於兩種解之間的差異可能會有夠深刻的體會。