The draft version of EPI in Java is ready!
EPI is a community book - its content, quality, and very existence,
are a testament to the engagement and enthusiasm of its readers.
In this spirit, we are asking readers to help us by providing
feedback on 1-2 chapters on the Java draft.
By acting as a reviewer, you will get
- a chance to perfect your interviewing skills,
- an early look at the book,
- our undying gratitude, and,
- a free hardcopy of the book, if you are one of the first 25 reviewers or make great contributions to this review.
Due to enormous interest, we are no longer signing up reviewers. If you are very keen on participating,
If you are interested, please sign up via this –>Google form.
please write directly to us - you can use email@example.com.
We expect reviewers to spend one to two afternoons going through
the chapter, and identify an issue every 1 to 2 pages. The text is very similar to that of
the current version - the big difference is in the programs which are now in Java.
The perfect is the enemy of the good - please send us your inputs as soon as you can. (We are hoping
to have a substantial amount of feedback by the end of August.)
Issues can be typos, language that is misleading, suboptimum solutions, bad programming practices - in short
anything that can improve the quality of the book.
Every individual issue you identify should be reported through a Google form, which you
can view here.
Here are some examples of issues reported by readers.
Note how specific these suggestions are - they have details on where the issue was, what the problem was, what the right wording should be, etc.
- Typo: 3rd paragraph, 3rd line: “<0, 7="" 0,="" 2,="" 3,="" 5,="">“. According to the input array, it should be “<0, 7="" 0,="" 2,="" 3,="" 6,="">“, because when we reach day 6, the max profit is 14 - 8 = 6, not 14 - 9 = 5.
This means on the last line of this paragraph, the last two elements in M should be 8 and 6 (instead of 7 and 5).
- Comment: Why in problem 6.19 and the variant, we need to assume that n = 2^k? This condition is not really used in current solutions (unless you meant to discuss an alternate solution that uses divide and conquer to rotate the matrix by quarters).
- Clarification: Solution 12.14: I feel the parameters in recursive function are confusing. Would it not be better to use two integers to keep track of the number of left parens we need and the number of right parens we need? If the first one is larger than 0, then we can add either left or right paren; otherwise we just add right parens. When both are 0, we save the valid prefix.
- Error: Program in Solution 8.4 goes into an infinite loop
if there are duplicates entries in the input list. The problem statement should either explicitly
rule that out, or you should use a container which supports duplicate entries.
- Suggestion: Drop Variant 10.16.1, as it is effectively the same as Problem 10.18.0,>0,>
A number of readers have suggested integrating solutions with problems, that is presenting
the solution immediately after the problem. Their goal is to avoid having to go back
This has been particularly challenging for readers using the Ebook - Google Play strips
the links we provide in the PDF between problems and solutions (and also to page and figure references).
We have updated EPI to have this integration. The new version is now available from Amazon.
If you have an Ebook, you can always get the latest version for free from Google Play.
The EPI Team
The programming exercises in EPI are representative of what you will be asked
in an interview. We do not provide textbook-style review questions.
In this document, we present a small set of programming exercises suitable for
someone who needs to review basics. (You are unlikely to be
asked these questions - their purpose is to bootstrap reading EPI.)
When you write your solutions to these exercises, please code to the following constraints:
- Do not use library calls.
- Do not try to design clever solutions. (This means it is fine to use brute-force approaches.)
- Assume valid inputs, and ignore internal errors like overflow, IO exceptions, etc.
- Write unit tests for your programs.
- Analyze your programs for time and space complexity.
Exercises, one for each EPI chapter
- Primitive types: write a program that takes as input an integer, N, and prints
all the integers from 1 to N, replacing numbers divisible by 3 with “fizz”, numbers divisible by
5 with “buzz”, and numbers divisible by both with “fizz buzz”.
- Arrays: Write a program that tests if a 2D square array is symmetric about the diagonal
from (0,0) to (n-1,n-1).
- Strings: Write a program to find the longest substring that consists of a single
character in an input string.
- Linked Lists: Implement a doubly linked list of integers class. Write a reverse method for your list class
that reverses a list without changing the node contents.
- Stacks and Queues: Write a programt to evaluate arithmetical expressions that use + and applied
to nonnegative integer arguments. Expressions are in reverse-Polish notation, e.g., 3 4 + 5 , 1 3 + 5 7 + *.
- Binary Trees: Write inorder, preorder and postorder traversal methods for a binary tree. (You will need
to implement a class suitable for representing binary trees, but do not need to implement
add, lookup, delete, etc. methods.)
- Heaps: Write a program that builds a max-heap from an integer array. (You will need to implement
a class suitable for representing heaps, but do not need to implement extract-max, insert key, etc.)
- Searching: Write a nonrecursive program to perform binary search over a sorted array.
- Hash tables: Write a program that finds the most common object in an array of objects. The
objects consists of pairs of strings. Treat strings as being the same if they are equal when converted to lower case.
- BSTs: Write a program that searches a BST on integer keys for a given value. (You will need to
implement a class suitable for representing BSTs, but do not need to implement
add, lookup, delete, etc. methods.)
- Write a recursive program that takes as input positive integers x and N, and returns x to the power N.
You should use O(log N) multiplications.
- Dynamic Programming: Write a program that takes a positive integer N, and returns the number
of binary strings of length N such that there are no consecutive 1s. For example, if N = 3, the result
is 5, corresponding to the strings 000, 001, 010, 100, 101.
- Greedy Algorithms and Invariants: Write a program that takes an input a positive integer
N, and returns the minimum number of coins in the US coinage system to create N cents. For example, if
N = 37, the answer is 4, corresponding to a quarter, a dime, and two pennies.
- Graphs: Implement Depth First Search and Breadth First Search. (You will need to implement
classes suitable to representing graphs.)
- Parallel Computing: Write a program which uses two threads to print the numbers from
1 to 100 in order. One thread can only print odd numbers, the other can only print even numbers.
Debugging and testing are topics which are not usually the focus of university teaching.
We highly recommend The Practice of Programming by Kernighan and
Pike, which teaches much more than just writing code. Specifically, it covers testing,
debugging, portability, performance, and design alternatives.
- What was your last bug? What was your hardest bug?
- How would you debug a distributed program?
- A program works sometimes and fails other times - why?
- A program works sometimes and fails other times on the exact same input - why?
- How would you determine where a program spends most of its time?
- How does JUnit make the process of testing easier?
- List five ways in which C code can be non-portable. What can you do to make the code portable?
- Write tests for implementation of an isupper() function.
- Should you test private methods? Should you test one line methods?
- If you find and fix an error by adding debug code, should you remove the debug code afterwards? Should you leave them in with a conditional compilation flag or with a run time flag?
- What is a buffer overflow and how can hackers exploit it?
- How can you use Valgrind to solve segfault problems?
- How does Valgrind catch access uninitialized memory?
Our book is focused on questions that entail writing programs. You may be asked
questions related to general programming practices, which are conceptual and/or
knowledge-based, and do not require writing a program. (The extent to which
you are asked such questions depends on the company, your experience, the job, etc.)
Such questions tend to be narrow, and as such are not appropriate for our book.
We have begun the process of collecting representative questions, which you can see below.
Debugging and Testing,
We have also put together a small list of warm up exercises that are appropriate
for someone who is a little rusty.
- What are the types in C, Java, C++, and Perl? How many bits does it take
to represent the basic types?
- What do floating point numbers look like in
memory? Specifically, how many bits are there in a double and
what sequence to the bits appear in?
- What is twos-complement notation?
- How would you implement a bit array class?
- Does the check x == x + 1 always return false for integer x?
- What does a C struct look like in memory? What does a C++
object look like in memory? What does a Java object look like in
- What is the difference between an interpreted and a compiled language?
- What is garbage collection?
- How would you determine if call stack grows up or down relative
to memory addresses?
- Give an example of a memory leak in Java.
- What is tail recursion? How can it be removed automatically?
- Is the natural recursive program for computing n! tail recursive?
- Your manager reads an online article that says it is 10X faster to code in Python than in C++. He wants you to code exclusively in Python from now on. What would you say to him?
- What does an executable look like as a sequence of bytes?
A programmer who regularly implements complex algorithms such as KMP
string matching or the Dijkstra shortest path computation quickly
will not advance very far. Solutions to such problems are well-known and have
high quality, thoroughly tested, and debugged implementations, often
available as open source. Programmers should know and use these libraries.
- Give an example of a function which is in the C standard library.
- Give an example of a commonly used function which is not in the C standard library.
- What library would you use to determine the current date in Java?
- What library would you use in Java if you had to implement a tinyurl service?
- How does STL implement sets?
- How does the library code compute trigonometric functions?
- The strtok(char s1, char s2) function in the C standard library successively returns occurrences of the characters in s2 in string s1; it returns null if there are no more occurrences.
- What makes this a dangerous function to use in a multithreaded program?
Programming language implementation
- Give an example of a language which cannot be parsed by any computer.
- What problems does dynamic linkage solve? What problems does it introduce?
- What is a functional language?
- What is a virtual function?
- How is method dispatch implemented in Java?
- What is automatic garbage collection and how is it implemented?
- What is a type-safe language?
- What is the difference between a lexer and a parser?
- Give an example of a language which cannot be recognized by a lexer.
- Give an example of a language which cannot be parsed by a parser.
Modern Operating Systems by Tanenbaum is widely used;
one of its claims to fame is that Linux was developed from the Minix
OS developed in an earlier version of this book.
- What is a system call?
- How is a system call different from a library call?
- What is a device driver?
- What is livelock? What is deadlock? Give examples of each.
- What is a race? What can you do to prevent races?
- What is a mutex? What are semaphores? How are they implemented?
- Give examples of system calls that are not related to input-output.
- Give examples of library functions that call a system function all the time, none of the time, and some of the time.
- What is the time lag between the system call on the client side and the receipt of the packet on the server on a LAN?
- How fast can you write a gigabyte of data from RAM to disk?
- How does TCP/IP work?
- What is DNS?
Building and maintaining programs
- What version control system do you use?
- What coverage tool do you use?
- What build system do you use?
- What documentation system do you use?
- What bug tracking system do you use?
- How is branching implemented in a version control system?
- Are deltas in the branching for a revision tree stored out forwards
or backwards? What are the benefits of each approach?
- What are the advantages and disadvantages of a version control system that locks files?
There are scores, if not hundreds of books on the UNIX shell and related tools.
We have enjoyed LINUX 101 Hacks by Natarajan. It introduces
these tools through useful hacks, such as the use of find
to find all files that have not been modified in the past 100 days
and are larger than 100~megabytes in size, sorting the password file on the third field, etc.
- Write a regular expression for identifying social security numbers in a file.
- Write a command that prints out lines in a text file which contain the
strings foo and bar in any order.
- Write a command which replaces every occurrence of a foo followed by a bar (with
possibly some other characters in between) by widget.
- Given a text file with two columns of integers, i.e., two integers encoded in ASCII per line, write a filter which sorts lines in the file by the second integer.
- How would you take two documents in PDF and create a new document which consists of the pages of the two original documents interleaved in order?
- How would you write a program which checks every hour if a network connection is up?
- How would you write a program which checks the price of a Nikon D5300 DLSR each day on amazon.com?
We’ve begun the process of writing Python solutions!
Python versions of the program in the EPI sampler are listed below and
we would really appreciate your thoughts on them with respect to idiomaticity and clarity.
Python has exceptionally powerful libraries. Our programs by design use a simple subset of the
library but in many cases we also provide alternative Pythonistic solutions.
Solutions are written for Python 3.4.
Fill out this registration form to get updates on interviewing trends, good practice problems, links to our blog posts, and updates to the book/website.
For example, we are implementing an online solution checking system, and would like to be able to let you know when it’s ready.
We will not be spamming you, and you will always have the option of opting out of receiving emails at any time. We reach out to you individually for feedback.