{ Cracking The Coding Interview: 150 programming Q&A } 5th edition Part II

来源:互联网 发布:香港最新直播软件 编辑:程序博客网 时间:2024/06/07 03:59

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. Likerecursive.


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 offer

1. 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




0 0
原创粉丝点击