Date:July 1st, 2022
Study Plan and Problem Number: Top Interview Questions 1 & 2
Problem 1: Two Sum
Syntax:
- To make hash table, it's convenient to apply 'pair' in C++
vector<pair<int, int>> hashT; //first element: vector[i].first; //second element: vector[i].second;
Algorithm & Structure:
- Hash table: it allows the look up time as a constant, so it will reduce a dimension of time complexity.
Bug:
Problem 2:
Syntax:
- Conditional operator is useful and simple
int var = a > b ? c: d; //if(a>b){ // int var = c; //}else{ // int var = d; //}
notiuce that the first half statement can be the determination of nullptr.
-
Operation of queue:
queue<int> q; q.pop(); q.push(); q.front(); q.size();
Algorithm & Structure:
- This question is simply the carry forward question, that the design of reversed linked list is just so easy for us to calculate digit by digit.
- Even though the original code of mine:
has the timing issue due to the power calculation, but the thought of utilizing a queue is noticable. It basically appiles when we need to consider the order of data structure and make some operation one by one.
Bug:
- In linked list, we must declare the 'next' pointer then assign the 'temp' variable to it, that is to say, the iteration can't continue like this
Node* head = new Node(); Node* temp = head; while(temp){ //do something about he value temp = temp -> next; }
Conclusion:
- When it comes to 'one by one' quesiton, consider queue, stack, and especially the relation between the unit and the result. The carry-out addition method is really simple and applies to the question.
Next Plan:
- 2-4 problems in top interview questions.
种一棵树最好的时机是十年前 其次是现在。