劍指offer刷題心得(面試篇)
阿新 • • 發佈:2019-02-01
行為面試=》技術面試=》應聘者提問
1. 行為面試環節
- 專案經驗是重中之重,簡歷撰寫參考STAR模型:即Situation(簡短的專案背景),Task(完成的任務),Action(為完成任務做了哪些工作,怎麼做的),Result(自己的貢獻)。
- 準確描述對技能的定位:瞭解,熟悉,精通。
- .回答為什麼跳槽。一定要往積極方面去回答,如個人技術瓶頸,想尋找一份更有挑戰的工作。
2. 技術面試環節
基礎知識紮實全面,包括程式語言,資料結構,演算法等等;
能寫出正確的,完整的,魯棒的高質量程式碼;
能思路清晰地分析,解決複雜問題;
能從時間,空間複雜度兩個方面優化演算法效率;
具備優秀的溝通能力,學習能力,發散思維能力等
- 紮實的基礎知識:程式語言,資料結構和演算法。連結串列,樹,棧,佇列和雜湊表等。
a.大公司傾向於連結串列和二叉樹相關的問題:連結串列的插入和刪除;二叉樹的各種遍歷方法的迴圈和遞迴
b.大部分公司都會考察查詢, 歸併排序和快速排序
c.bat等高科技公司比較注重動態規劃和貪婪演算法 - 高質量的程式碼
a.邊界條件,特殊輸入等測試案例 - 清晰的思路
a.列舉法
b.圖例法
c.複雜問題簡單化(分治法和動態規劃) - 優化效率的能力
a.尋找時間消耗或者空間消耗上可以優化的地方
b.犧牲小小空間換取大的時間優化-文波那契數列
*遞迴法O(2^n),
*歸納法O(n)(f(1)+f(2)->f(3), f(2)+f(3)->f(4)),…, f(n-2)+f(n-1) = f(n) - .溝通能力和遷移學習能力
3. 應聘者提問
有針對的準備,預備三四個有技術含量的問題
例項展示
/*Good Practice 1*/
int StrToInt(char* string)
{
int sign = 1;
__int64 number;//declare as longlong int type
//protect against null point
if(NULL == string)
{
printf("Null pointer exception!");
return 0;
}
//consider sign of number, taking first non-digit character
if(*string == '+')
{
sign = 1;
++string;
}
if(*string == '-')
{
sign = -1;
++string;
}
//Return directly if starts from zero
if(*string == '0')
{
printf("Result is:0.");
return 0;
}
//stop on encountering ending character
while(*string != '\0')
{
//skip space and tab character
if(*string == ' ' || *string == '\t')
{
++string;
}
//core computation algorithm
number = 10*number + sign*(*string-'0');
//deal with int type overflow
if( (sign > 0 && number > INT_MAX) ||
(sign < 0 && number < INT_MIN) )
{
printf("The input numbers are overflow!");
break;
}
++string;
};
return number;
}
/*Good Practice 2*/
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k)
{
//check input
if(NULL == pListHead)
{
return NULL;
}
//check input
if(k == 0 || K == 1)
{
return pListHead;
}
ListNode* pKthTracker = pListHead;
ListNode* pTrailer = pListHead;
for(unsigned int inx = 0; inx < k-1; ++inx)
{
//always check pointer
if(NULL == pTrailer) return NULL;
pTrailer = pTrailer->next;
}
while(pTrailer->next != NULL)
{
pKthTracker = pKthTracker->next;
pTrailer = pTrailer->next;
}
return pKthTracker;
}
/*Good Practice 3 - Recursive method
f(n) = f(n-1) + f(n-2)
*/
//Recursive formula
int SolvePhi(int n)
{
//stop condition
if(n == 1)
{
return 1;
}
if(n == 2)
{
return 2;
}
//Recursive formula
return RecursiveSolvePhi(n-1) + RecursiveSolvePhi(n-2);
}
//Dynamic programming
int SolvePhi(int n)
{
if(n == 1)return 1;
if( n == 2) return 1;
int fn_1 = 2;
int fn_2 = 1;
int fn = 0;
for(int inx = 3; inx < n; ++inx)
{
fn = fn_1 + fn_2;
fn_2 = fn_1;
fn_1 = fn;
}
return fn;
}