赞
踩
《Cracking the coding interview》是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book。 里面有150道程序员面试题目及相应的解答。书中大部分是编程题目, 并且配有相应的java程序(有些地方有错误或是有更优的方案)。我把书中的题目做了一遍, 并且记录下来,包含自己对问题的一些思路及看法,许多问题给出了两种以上的解答方案。 由于个人平时使用较多的是C++,所以程序是用C++编写,所有的代码都托管在Github上:
https://github.com/Hawstein/cracking-the-coding-interview
记录下来的主要目的是加深自己对问题的理解,如果此外还能对一两个人起到帮助作用, 那真真是再好不过了。:P
Chapter 1 | Arrays and Strings
1.4 Write a method to decide if two strings are anagrams or not.
1.5 Write a method to replace all spaces in a string with ‘%20’.
Chapter 2 | Linked Lists
2.2 Implement an algorithm to find the nth to last element of a singly linked list.
Chapter 3 | Stacks and Queues
3.1 Describe how you could use a single array to implement three stacks.
3.5 Implement a MyQueue class which implements a queue using two stacks.
Chapter 4 | Trees and Graphs
4.2 Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
Chapter 5 | Bit Manipulation
5.4 Explain what the following code does: ((n & (n-1)) == 0).
Chapter 6 | Brain Teasers
Cracking the coding interview—Q6.1~Q6.6
Chapter 7 | Object Oriented Design
XDDDDDD
Chapter 8 | Recursion
8.1 Write a method to generate the nth Fibonacci number.
8.3 Write a method that returns all subsets of a set.
8.4 Write a method to compute all permutations of a string.
Chapter 9 | Sorting and Searching
9.2 Write a method to sort an array of strings so that all the anagrams are next to each other.
9.6 Given a matrix in which each row and each column is sorted, write a method to find an element in it.
Chapter 10 | Mathematical
Cracking the coding interview—Q10.1~Q10.7
Chapter 11 | Testing
Cracking the coding interview—Q11.1~Q11.6
Chapter 12 | System Design and Memory Limits
12.5 If you were designing a web crawler, how would you avoid getting into infinite loops?
12.6 You have a billion urls, where each is a huge page. How do you detect the duplicate documents?
Chapter 13 | C++
13.1 Write a method to print the last K lines of an input file using C++.
13.3 How do virtual functions work in C++?
13.4 What is the difference between deep copy and shallow copy? Explain how you would use each.
13.5 What is the significance of the keyword “volatile” in C?
13.6 What is name hiding in C++?
13.7 Why does a destructor in base class need to be declared virtual?
13.9 Write a smart pointer (smart_ptr) class.
Chapter 14 | Java
Pass
Chapter 15 | Databases
15.1 Write a method to find the number of employees in each department.
15.3 What is denormalization? Explain the pros and cons.
Chapter 16 | Low Level
16.1 Explain the following terms: virtual memory, page fault, thrashing.
16.5 Write a program to find whether a machine is big endian or little endian.
Chapter 17 | Networking
17.2 Explain any common routing protocol in detail. For example: BGP, OSPF, RIP.
17.3 Compare and contrast the IPv4 and IPv6 protocols.
Chapter 18 | Threads and Locks
18.1 What’s the difference between a thread and a process?
18.2 How can you measure the time spent in a context switch?
Chapter 19 | Moderate
19.1 Write a function to swap a number in place without temporary variables.
19.2 Design an algorithm to figure out if someone has won in a game of tic-tac-toe.
19.3 Write an algorithm which computes the number of trailing zeros in n factorial.
19.8 Design a method to find the frequency of occurrences of any given word in a book.
19.11 Design an algorithm to find all pairs of integers within an array which sum to a specified value.
Chapter 20 | Hard
20.1 Write a function that adds two numbers. You should not use + or any arithmetic operators.
20.4 Write a method to count the number of 2s between 0 and n.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。