Interview Stages
- Online coding challenge: typically done on www.hackerrank.com
- HR phone screen: why are you interested in this company, what role (front-end vs back-end vs data science), verify/clarify some points on your resume
- One or two phone interviews (on-campus interviews are equivalent)
- Onsite interview
An Interview May Cover ...
- Anything on your resume (interesting projects, internships, etc)
- Basic data structures and algorithms - hash tables, binary search trees, sorting algorithms, heaps, etc.
- Other CS Fundamentals
- Language-specific questions
- (Onsite interviews only) Coding on a whiteboard. For each question, you need to
- Develop the algorithm
- Implement your algorithm in Java/C++/Python/...
- Come up with test cases to find and fix the bugs in your code
- Analyze the time and space complexity of your implementation
- Logic puzzles
- System design
- Behavioral Questions
How to Succeed During an Interview
Many interviewers intentionally ask the question in an ambiguous fashion to invite clarification questions. Before proceeding, ask the interviewer some clarification questions such as
"What should I do if the array is empty"
"Can I expect the input to be reasonable?"
"Can there be duplicates in the input array?".If you need to assume something - verbally check it's a correct assumption!
Make sure you comprehend the question. Ask for specific input/output examples if you don't.
- Always let your interviewer know what you are thinking as he/she will be as interested in your process of thought as your solution. Also, if you're stuck, they may provide hints if they know what you're doing.
- Approach the problem as if you were trying to solve it with a colleague at work, in which case it would be more of a discussion rather than a test.
- Listen - don't miss a hint if your interviewer is trying to assist you! Being able to take hints shows that you are open to new ideas.
- Never stop optimizing. If you think your algorithm reaches the best possible run time, why? Can the space complexity be further optimized then?
- Write clean code. Break a long function into smaller independent pieces shows good design, makes your code understandable and easily testable.
- Discuss trade-offs. For this problem, why did you use a hashmap instead of a hashset? Why is it better to use iteration instead of recursion? If this problem can be solved in two ways -- implementation A requires linear time complexity and quadratic space complexity and implementation B requires quadratic space complexity and linear time complexity, when would you use which?
- Interviewers like to leave the last ten minutes of the interview for your questions about the company, work environment, their personal experience, etc. So remember to do some research about the company to have a decent understanding of the company as a business (how do they make profit) beyond their main products.
- Saying what you know can get you easy points. Specifically it will convey a lot of your knowledge while spending little interview time.
- ex: “I would normally use StringBuilder, but in the interest of time, I’ll use the + syntax because it is quicker to write.”
- ex: “Under the hood, string concatenation with + uses a StringBuilder. So using + is ok in a single line.”
- ex: “The time complexity of resizing an array can be amortized over the total number of insertions.”
- ex: “We could use recursion, but recursion uses a whole stack frame per call and does not scale well. It is better suited for cases where you’d need a small, bounded number of calls”
- ex: “In practice, I’d use descriptive variable names, but on the board, shorter variables help save time.”
- If you are familiar with a more complex data structure or algorithm that fits a particular situation, mention it. Be ready for follow up questions. (ex: a redblack tree, DFSID, A*)
- If using Java, proper use of an interface, generics, final/static are all a plus.
- Don’t stress small syntactical errors.
- If you can’t remember whether the method is substring(start, end) or substring(start, length), just pick one and let your interviewer know. In the real world you could just check the documentation or even autocomplete.
- Don’t worry about occasionally missing a semicolon either.
Algorithms
For the following algorithms, especially those in bold, you need to know their time and space complexities and implementation details.
- Sorting algorithms: merge sort, quicksort (merge sort can be highly useful in situations where quicksort is impractical, why?), selection sort, bucket sort
- Binary search
- Graph algorithms: tree traversals (preorder, inorder, postorder), BFS, DFS(tradeoffs between BFS and DFS), topological sort, dijkstra's algorithm, A* search
- Dynamic programming
- Recursion and divide-and-conquer
- Bit manipulations
- Greedy
- Backtracking
Data Structures
- Arrays
- Strings
- Linked Lists (when to use a linked list over an array and vice versa)
- Stacks, Queues, and Deques
- Trees, Heaps
- Binary Search Tree (lookup, insertion, deletion)
- Graphs: There are three basic ways to represent a graph in memory (objects and pointers, matrix, and adjacency list); familiarize yourself with each representation and its pros & cons.
- Sets (Why use a set over an array? Why use a HashSet over a HashMap?)
- Hashtables (single most important data structure to know; you need to know everything about hashtables!). Also, HashMap vs TreeMap
- Tries1
- Union Find2
1. Trie problem rarely appear before the onsite interview stage. ↩
2. Most likely to appear in online coding challenges. ↩
Other CS Fundamentals
- What's an object?
- Difference between threads and processes. How do threads communicate?
- How to speed up a website?
- CAP Theorem
- Characterstics of good code?
- Dynamic binding vs static binding
- TCP vs UDP
- Concurrency issues: Know about locks and mutexes and semaphores and monitors and how they work.
- When can a deadlock occur? What's the difference between a deadlock and a livelock? How do we avoid them?
- Design patterns: when to use them? Which ones have you used?
- What are the benefits and drawbacks of database normalization?
- Know what resources a processes needs, and a thread needs, and how context switching works, and how it's initiated by the operating system and underlying hardware.
- Know a little about scheduling. The world is rapidly moving towards multi-core, so know the fundamentals of "modern" concurrency constructs.
- How would you find whether a remote server is online or not?
- How does the domain name map to IP address?
- Throughput vs latency
Language specific Questions
- What objects in Python are immutable? Are they truly "immutable"?
- When to use Reflection in Java?
- Difference between vector and array in Java.
- In Java, what purpose do the keywords
final,finallyandfinalizeserve? - Difference between an abstract class and an interface in Java.
Behavioral Questions
- What made you want to study computer science?
- What is your favorite programming language? Why?
- If you could change one thing about that language, what would that be?
- Tell me about your favorite/most challenging programming project.
- Tell me about a project where you worked as part of a team.
- Have you ever had a disagreement with a team member? How was it resolved?
- Tell me about a bug that you recently faced. How did you discover it? How did you fix it?
- If your teammates were to complain something about you, what would that be?
- Among all the courses you are taking right now, which one is your least favorite? Why?
Hackerrank Problems
In many of the HackerRank challenges, you need to read input from stdin (standard input) and write your output in stdout (standard output). You need to be familiar with how to take input from stdin in your favorite language.
In Python, you will find functions like input, raw_input, split, join extremely useful. Go ahead, try the following problem.
Print Integers in Reverse Order
Given an array of
Nintegers, print the integers in reverse order.Input Format
The first line of input contains
N, the number of integers. The next line containsNintegers separated by a space.Output Format
Print the
Nintegers of the array in the reverse order on a single line separated by single spaces.Sample Input
4 1 4 3 2
Sample Output
2 3 4 1
Solution:
N = input()
arr = [int(n) for n in raw_input().split(' ')]
print ' '.join(str(c) for c in reversed(arr))