{ Cracking The Coding Interview: 150 programming Q&A } 5th edition Part II
2015-11-25 00:37
411 查看
Chap 6 Technical questions
How to practice a question:1. solve by myself
2. write code on paper
3. test on paper
4. type to computer and record bugs
Handling technical questions:
1. ask questions to resolve ambiguity
data types, data amout, assumptions, user?
2. design an algorithm
time and space complexity, what happens if lots of data, cause other issues, with limitations how to make trade-offs, with specific data have you leveraged the information?
First give brute force solution, then optimize it.
3. pseudocode
first write false codes, and then tell interviewers that you will start writing real codes.
4. code
write codes at a nice, slow, methodical pace.
Use data structures generously: show that you have concern about this basic fondations.
Don't crowd your coding: start from left-upper and leave enough space to write other codes.
5. test
extreme cases, user error, general cases.
When finding bugs, first think about why and then correct it.
Five algorithm approaches:
1. Examplify
Write out specific examples of the problem and see if you can derive a general rule from there.
E.g Find the angle between hour and minute hands.
The angle between the minute hand and 12 o'clock: 360 * m / 60
The angle between the hour hand and 12 o'clock: 360 * ( h % 12 ) / 12 + 360 * ( m / 60 ) / 12
So : (hour angle - minute angle) % 360 = (30 * h - 5.5 * m ) % 360
2. Pattern matching
Consider what problems the algorithm is similar to and try to modify the existing solution to solve the problem.
E.g A sorted array has been rotated such as 4567123, how you find the minium element? Assume all elements are unique.
1. Find the minimum element. --- Not useful, it doesn't use the information.
2. Binary search --- If MID < RIGHT then the minimun element must be less then MID.
3. Simplify and generalize
First, we change a contraint such as the data type or amount of data.
Then, we solve this new simplified problem.
Finally, we try to generalize the earlier solution for more complex version.
4. Base case and build
We first solve the problem for base case (e.g. n = 1) and then for n = 2, 3... assuming we have the solutions for previous cases. Like
recursive.
5. Data structure brainstorm
Simply run through a list of data structures and try to apply each one.
E.g numbers are randomly generated and stored in an array, how to keep track of the median?
LinkedList? not good at accessing and storing data.
Array? already have.
Binary tree? binary search tree, but the root cannot be 2 elements.
Heap? use 2 heaps to separate bigger half and smaller half. Good solution!
What good coding looks like?
Correct, efficient, simple, readable, maintainable.
Tips:
1. use data structures more generally
2. appropriate code reuse
3. modular
4. flexible and robust
5. error checking
Chap 7 The offer and beyond
Evaluating the offer1. financial package
signing bonus, relocation, and other time perks.
cost of living difference.
annual bonus.
stock options and grants.
2. career development
3. company stability
4. the happiness factor
the product, manager and teammates, company culture, hours.
5. negotiation if necessary
On the job:
1. set a timeline for your career path
2. build strong relationships
3. ask for what you want
相关文章推荐
- 设计模式四之工厂模式1
- Qt 学习之路 2(29):绘制设备
- Beta版本冲刺计划及安排
- Java设计模式——观察者模式
- Java设计模式——观察者模式
- 简单的C编程题
- 【Cocos2d-x 3.x】 动作类Action源码分析
- UITableViewCell的重用代码
- 信息安全系统设计基础实验二:固件设计(20135229,20135234)
- 全面解析《嵌入式程序员应该知道的16个问题》
- 黑马程序员_java多线程玩玩IO流,求开导!!
- 字符处理库函数
- struts中利用jquery的$.ajax方法来动态获得图片以及信息
- 坐标系统 Qt 学习之路 2(28):坐标系统
- Shell之readelf命令简介
- FOJ 11月月赛题解
- Shell之objdump用法简介
- 多线程
- Python文件打包成EXE文件
- [nodejs入门]第一篇,javascript基础(1)