# 資訊科技產業專案設計課程作業 4
Contributed by 喵喵仔
Video link : [Youtube](https://youtu.be/nz1ayj9u_ZQ)
### Issue 1
Interviewer: 芋頭-Taro
Interviewee: 喵喵仔-cute cat
**Interviewer**
I have [issue](https://leetcode.com/problems/pascals-triangle/) here.
Given an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it as show.
```
1
1 1
1 2 1
1 3 3 1
```
**Interviewee**
I follow the workflow of REACTO. I take example for this.
if I get n = 1, output [[1]]
n = 2, output [[1],[1,1]]
n = 3, output [[1],[1,1],[1,2,1]]
n = 4, output [[1],[1,1],[1,2,1],[1,3,3,1]]
In the beginning, I had no idea how to process the issue. I give the approach.
The first step is processing the n=1 Pascal's triangle; the other n would go to the `else` section.
```c++=
class Solution {
public:
vector<vector<int>> generate(int num) {
vector<vector<int>> curr;
if(num==1) curr.push_back([1]);
else{
vector v(num,1);
for(int i=0;i<num;i++){
if(i!=0 || i!=num-1){
...
}
}
}
return curr;
}
};
```
But this approach couldn't work. I don't have the previous result to help me find the current result. So, I have found another approach to help us solve this issue.
Therefore, I use the `re` to store each iteration result. In each iteration, I build the vector and use the second for loop to change the element in the vector depending on the previous vector. At the end of the iteration, push the vector to the container named as `re`.
```c++=
class Solution {
public:
vector<vector<int>> generate(int num) {
vector<vector<int>> re;
for(int i=1;i<=num;i++){
vector v(i,1); //i=1 [1] i=2 [1,1] i=3 [1,2,1] i=4 [1,3,3,1]
for(int j=2;j<i;j++){
v[j-1] = re[i-2][j-2]+re[i-2][j-1];
}
re.push_back(v);
}
return re;
}
};
```
The above code pass the test from [leetcode](https://leetcode.com/problems/pascals-triangle/solutions/4209899/javascript-c/).
### Issue 2
Interviewer: 喵喵仔-cute cat
Interviewee: 芋頭-Taro
**Interviewer**
Please try to solve this issue.
Reverse bits of a given 32 bits unsigned integer.
And, I give an example as below.
Input: n = 00000010100101000001111010011100
Output: 964176192 (00111001011110000010100101000000)
Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
In the beginning, Taro would like to take the sum variable to store the result of each iteration and filter shift right by 1 in each iteration.
```
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
vector<int> v;
uint32_t sum = 0;
uint32_t filter 1<<31;
for(int i=0;i<32;i++){
sum += (filter & n)<<i;
filter>>=1;
}
return sum;
}
};
```
But the interviewer gives a hint to the interviewee. The interviewer says that you should try to use the basic operation, such as the OR operation. Provide guidance and tips when the interviewee gets stuck.
Following, the interviewee figures out the new approach as below: The interviewee separates the 32 bits into two parts. First, he processes the front half of 32 bits. Then, use the same filter to extract the specific bit to do the shift left operation. But the interviewer forgot to tell the interviewee that he proposed an improved approach based on the current approach. This is the cute cat's weakness.
Use a checking list to help us evaluate the shortcoming.
### Interviewer
- [x] 給予 interviewee 適量的題目說明
- [x] 足夠讓 interviewee 理解題目
- [x] 但有許多細節希望 interviewee 自己透過提問問出來
- [x] 在 interviewee 卡住時給予引導和提示
- [ ] 也要注意是否過度引導,在真實面試中也許不會有這麼多引導
### Interviewee
- [x] 盡量避免雙方同時沉默的情況
- [x] Apply Think out loud: 有成功的把自己在思考的部分講出來
- [ ] 有把所有細節想好才開始實作
- [x] 應加強實作後的測試部分
- [x] 加強英文口說流暢度
- [ ] 解釋想法精簡扼要,只講重點
- [ ] 需多考慮 edge case
- [ ] 若題目有 complexity 限制,在解釋 approach 時也該提到為何會滿足限制
- [x] 提出改進方法後不要馬上實作,要先和 interviewer 討論
- [x] 嚴謹的測試很花時間,但又不應該花太多時間在測試,重點應在 problem solving 能力,要注意 test 的重要程度跟解題之間的平衡
- [ ] 程式實作邏輯若有誤,但 interviewer 並未提出,也許該自己點出來
- [ ] 有模組化自己的解答
- [ ] 實作時可以詢問 interviewer 能否略過瑣碎不重要細節