Try   HackMD

2021 年「資訊科技產業專案設計」

貢獻者: 阿雷
video

hw1

9. Palindrome Number

C

bool isPalindrome(int x){
    // 12 12
    if(x<0 || (x%10==0 &&x!=0) )
        return false;
    int r = 0;
    while(x>r){
        r = x%10 + r*10;
        x /= 10;
    }
    return x==r || x == r/10; //1 12 
}

C++

可以根據 Palindrome 的定義,首先把輸入的 int x 轉換成 string 再創造另一個 string 為其的 reverse 最後直接比對兩者是否一樣。

class Solution { public: bool isPalindrome(int x) { string a = to_string(x); string b = a; reverse(b.begin(), b.end()); return a==b; } };

嘗試不用 C++ 提供的 library

class Solution { public: bool isPalindrome(int x) { if(x<0 || (x%10==0 &&x!=0) ) return false; int r = 0; while(x>r){ r = x%10 + r*10; x /= 10; } return x==r || x == r/10; //1 12 } };

20. Valid Parentheses

C

bool isValid(char * s){ char a[10001]; int index = 0; for(int i = 0;i<strlen(s);i++){ if(s[i] == '{' || s[i] == '[' || s[i] == '('){ a[index++] = s[i]; }else{ if(index == 0){ return false; } else if(a[index-1] == s[i] -1 || a[index-1] == s[i] -2 ) index--; else return false; } } return index==0; }

C++

class Solution { public: bool isValid(string s) { stack<char> a; for(int i = 0;i<s.length();i++){ if(s[i] == '(' || s[i] == '[' || s[i]=='{'){ a.push(s[i]); }else{ if(a.empty()) return false; else if(s[i] == a.top() + 1 || s[i] == a.top()+2){ a.pop(); }else return false; } } return a.empty(); } };

50.

C

double myPow(double x, int n){ double ans = 1; long long f = n; long long nn = n; nn = (f>0)?nn:-nn; // 2^10 4^5 4*4^4 4^(16^2) .... while(nn){ if(nn&1){ ans*=x; nn--; }else{ x*=x; nn/=2; } } return (f>0)? ans:1/ans; }

C++

class Solution { public: double myPow(double x, int n) { double ans = 1; long long f = n; long long nn = n; nn = (f>0)?nn:-nn; //2^10 4^5 4*4^4 4*(16^2).... while(nn){ if(nn&1){ ans *= x; nn--; }else{ x*=x; nn/=2; } } return (f>0)?ans:1/ans; } };

這次錄影時忘記將應用場景一同帶入,像 valid parentheses 在實作 Compiler 時就是最常用到的,導致就像考試一樣把主考官的題目解出來沒什麼互動及行銷自己。
另外有關於一些運算的英文用語其實不太熟悉,導致要解釋

Pow(x,n) 這種數學題型會很卡

note
Interviewer 可以用一些範例引導來破題,ex 知道那些樹 -> 反轉二元樹

hw2

第三次作業 - 他評

Interviewer

優點

  • 有討論題目背景
  • 有與面試者討論程式碼有缺陷的部分

缺點

  • 沒有討論時間複雜度的部分

Interviwee

優點

  • 第二個做法有舉出 Examples 在開始寫程式碼

缺點

  • 影片最一開始沒有做 Repeat 和 Examples

    • Repeat: 重複提問,確認自己理解原本的要求
    • Examples: 針對題目條件,舉出符合的案例,不限於特例
  • 00:48 應該是判斷他是不是回文

  • 01:56 程式碼完成後沒有舉出例子來 Test

    • Test: 若不能實際測試,那說明驗證程式的方案
  • 03:35 04:10 是最後一位整數,應該不能說 bit

  • 04:46 這邊是 x < r,x < r 才代表 x 的位數比 r 還小

  • 06:18 只有直接說出 x 是 10 的倍數的時候會出現問題,但並沒有提到因為 x 是 10 的倍數的話, 在做 r = X % 10 + r * 10 時,0 會被略掉,可以舉一個例子說明,不止後面的判斷 x == r/10 會有問題,後面的判斷 x == r也有可能出現問題

Ex:
x = 110, r = 0
第一次 loop
x = 11, r = 0
第二次 loop 
x = 1, r = 1
return true (wrong answer)
  • 沒有討論時間複雜度的部分

20. Valid Parentheses

Interviewer

優點

  • 將題目對應到相關工作以及相關經驗會遇到的情形

缺點

  • 題目的敘述沒有很請楚

Interviewee

優點

  • 有完整 REACT

缺點

  • 9:45 這邊有一段時間都沒有任何聲音,寫程式碼時可以做一些簡單的解釋,例如可以說用一個 for 迴圈檢查整串字串等等
  • 10:22 從這邊開始就沒有聲音了,無法判斷後面做了什麼解釋或是測試 QAQ,不過看畫面上的呈現應該是有做 Test 的部分

第三次作業 - 他評2

Palindrome Number

Interviewer

  • 2:15 有討論到不用先把 int 轉成 string 再判斷回文的方法。
  • 5:55 Interviewer 有即時指出 Interviewee 的 bug。
  • 可以試問 Palindrome Number 的變形題,ex: 234. Palindrome Linked List。

Interviewee

  • 0:38 可以先不用急著寫 code,應該要先 "Repeat" 問題,確認題目的要求。
  • 2:44 舉例和 code 分開比較好。
  • 6:19 if else 的判斷式"(x%10==0 && x!=0)",希望能帶出例子來幫助 Interviewer 清楚理解。

Valid Parentheses

Interviewer

  • 6:56 有仔細觀察 Interviewer 的背景後,帶出相關問題。

Interviewee

  • 9:46 敲打程式碼的同時,可以對你所寫的程式碼多加說明,避免沉默。
  • 10:20 這邊開始沒有聲音,不知道後面 Interviewer 和 Interviewee 做了什麼樣的互動。

第三次作業 - 他評3

Palindrome Number

I. Interviewer

  • 有近一步要求單純針對integer進行操作
    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猜到後續題目方向,而背出答案。
  • 沒有針對運行的複雜度以及題目其他變形進行提問。

II. Interviewee

  • 0.35處可循REACTO的步驟,在提出Approach前針對題目先做Repeat和提出Example,也可以趁此機會確認題目的Constraint。
  • 3.23此處「後面這個東西」的指涉不太精確,會造成說明跟理解的誤會。
  • 缺少REACTO中Test和Optimize的部分。

Valid Parentheses

I. 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 →

I. Interviewee

  • 8.38有循REACTO進行Repeat和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 →
    ,但未向interviewer進一步確認Constraints。

第三次作業 - 他評04(阿雷-Rex)

優點

Interviewer 和 Interviewee 之間的互動自然。
Interviewee 有照著 REACTO 的流程。

缺點

00:46 判斷它是不是"迴文"。
04:06 用語不恰當,bit 為用於 2 進制的單位,應該更正為"最後一位數"。
05:06 奇數位元,應更正為"這個數字位數是奇數"。
07:58 ~ 08:23 Interviewee 說話的音量不穩定且變小聲,有些字沒辦法聽得很清楚。
10:09 這之後都沒有聲音。
11:42 這種寫法必須去查表才能知道為何這樣寫,不好維護,並且如果沒有保證字串內的字元都屬於()[]{}的話,會發生預期外的錯誤。

  • (* ascii code 40, 42
  • [\ ascii code 91, 92
  • {| ascii code 123, 124

小結

前面看起來很棒,除了有些用詞有誤外。
後面整個聲音都沒了,剪輯時請注意素材是否是正常的 QQ。