NASKAR

Tuesday, May 02, 2006

Programming Questions:

This is a summary of the questions I got in 9 in-person interviews with 5 companies and about 10 phone screens 8/02-11/02.
The interviews were pretty evenly split between very large, large, and startup-sized tech companies.

The good news is that interview question repertoire is generally very limited.
The
Programming Interviews Exposed
book covered or helped on probably 60-70% of questions I got. Well worth the
$20.
A) Linked Lists
This is an extremely popular topic. I've had linked lists on every interview.You must be able to produce simple clean linked list implementations quickly.
1. Implement Insert and Delete for
- singly-linked linked list
- sorted linked list
- circular linked list

int Insert(node** head, int data)int Delete(node**
head, int deleteMe)


2. Split a linked list given a pivot value
void Split(node* head, int pivot, node** lt, node** gt)

3. Find if a linked list has a cycle in it. Now do it without marking nodes.

4. Find the middle of a linked list. Now do it while only going through the list once. (same solution as finding cycles)

B) Strings
1. Reverse words in a string (words are separated by one or more spaces). Now do it in-place. By far the most popular string question!

2. Reverse a string

3. Strip whitespace from a string in-place
void StripWhitespace(char* szStr)

4. Remove duplicate chars from a string ("AAA BBB" -> "A B")
int RemoveDups(char* szStr)

5. Find the first non-repeating character in a string:("ABCA" -> B )
int FindFirstUnique(char* szStr)

C) More Advanced Topics:
You may be asked about using Unicode strings. What the interviewer is usually looking for is:
each character will be two bytes (so, for example, char lookup table you may have allocated needs to be expanded from 256 to 256 * 256 = 65536 elements)
- that you would need to use wide char types (wchar_t instead of char)
- that you would need to use wide string functions (like wprintf instead of printf)
Guarding against being passed invalid string pointers or non nul-terminated strings (using walking through a string and catching memory exceptions

D) Binary Trees
Implement the following functions for a binary tree:
- Insert
- PrintInOrder
- PrintPreOrder
- PrintPostOrder

Implement a non-recursive PrintInOrder

E) Arrays
1. You are given an array with integers between 1 and 1,000,000. One integer is in the array twice. How can you determine which one? Can you think of a way to do it using little extra memory.

2. You are given an array with integers between 1 and 1,000,000. One integer is missing. How can you determine which one? Can you think of a way to do it while iterating through the array only once. Is overflow a problem in the solution? Why not?

3. Returns the largest sum of contiguous integers in the arrayExample: if the input is (-10, 2, 3, -2, 0, 5, -15), the largest sum is 8
int GetLargestContiguousSum(int* anData, int len)

4. Implement Shuffle given an array containing a deck of cards and the number of cards. Now make it O(n).
Return the sum two largest integers in an array.
int SumTwoLargest(int* anData, int size)

5. Sum n largest integers in an array of integers where every integer is between 0 and 9int SumNLargest(int* anData, int size, int n)

F) Queues
Implement a Queue class in C++ (which data structure to use internally? why? how to notify of errors?)

G) Other

1. Count the number of set bits in a byte/int32 (7 different solutions)

2. Difference between heap and stack? Write a function to figure out if stack grows up or down.

3. SQL query to select some rows out of a table (only because I had SQL on the resume)

4. Open a file as securely as possible (assume the user is hostile -- list all the nasty things that could happen and checks you would have to do to)

5. Implement a function to return a ratio from a double (ie 0.25 -> 1/4). The function will also take a tolerance so if toleran ce is .01 then FindRatio(.24, .01) -> 1/4int FindRatio(double val, double tolerance,
int& numerator, int& denominator)

6. Write a program that tests whether a floating point number is zero. (Hint: You shouldn't generally use the equality operator == with floating point numbers, since floating point numbers by nature are hard to match exactly. Instead, test whether the number is close to zero.)

public class FloatTest {
public static void main(String[] args) {
float f = 100.0f;
float MAX = 0.001f;
float MIN = -MAX;
System.out.print(String.valueOf(f));
if ((f <> MIN)) {
System.out.println(" is pretty darn close to 0.");
} else {
System.out.println(" is not close to 0.");
}
}
}



F) Puzzles

1. You have 2 supposedly unbreakable light bulbs and a 100-floor building. Using fewest possible drops, determine how much of an impact this type of light bulb can withstand. (i.e. it can withstand a drop from 17th
floor, but breaks from the 18th).Note that the ever-popular binary search will give you a worst case of 50 drops. You should be able to do it with under 20.

2. There are n gas stations positioned along a circular road. Each has a limited supply of gas. You can only drive clockwise around the road. You start with zero gas. Knowing how much gas you need to get from each gas station to the next and how much gas you can get at each station, design an algorithm to find the gas station you need to start at to get all the way around the circle.

3. Out of 10 coins, one weighs less then the others. You have a scale. How can you determine which one weighs less in 3 weighs? Now how would you do it if you didn't know if the odd coin weighs less or more?

4. What is the next line in the following sequence:11121Answer: it's 1211 and the next is 111221

G) Design Questions

1. How would you design a server that has to process a fair number of good number of requests a second. What if you didn't know how many requests you'd be getting? What if requests had different priorities? (I always think of the
Apache design for this question)

2. Design malloc and free. (give up? see
how G++ malloc works or this page for more examples)

3. Design an elevator control system. Don't forget buttons on every floor and supporting multiple elevators. (What objects/methods/properties/how components communicate)

4. Design a chess game (what objects? what methods? which data where? how will it work?)

5. Design a deck of cards class (object/methods/data)

6. How would you design the infrastructure front half of a very large web ecommerce site? what if it was very personalized? (how sessions are handled? where and what you can cache? how to load-balance?)

H) Concurrency

1. Difference between Mutexes and Critical Sections?

2. What are Reentrant Locks? Implement a Reentrant Lock with Mutexes.

3. Implement a thread-safe class that will read/write to/from a buffer

TSBuffer::TSBuffer(int size)
int TSBuffer::Read(char* buff, int max_size)
int TSBuffer::Write(char* buff, int size)

I) Windows-specific Questions

1. What is the IUnknown COM interface?
2. Synchronization primitives available in Windows (see
MSDN documentation)
3. Basic structure of a Win32 program (WinMain, Message processing)

J) Networking

1. Difference between TCP and UDP? When would you want to use one over the other?
2. How would approach guaging performance of webpages/parts on a very large website?

K) Questions you are unlikely to get unless you claim a lot of IP experience

1. How does traceroute work?
2. How does path MTU discovery work?
3. How can one poison a BGP peer?

L) Non-Technical Questions

All of the following are very common. It's best to have canned answers.
1. What do you want to do?
2. Describe your perfect job?
3. How did your interview go? How did you like the group you interviewed with?
4. Rate your C++ proficiency on the scale of 1 to 10.
5. What have you been up to since you were laid off or finished school?
6. Why do you want to work at X?
7. What reservations do you have working at X?
8. Do you like working alone or in a group?
9. Discuss your greatest accomplishment over the last couple years.
10. Discuss one big problem you solved in a work/school project.
11. How do you handle conflict in a group?
12. How much do you want to make? How much did you make at your previous position?

M) Marketing Questions

Questions for Marketing candidates.

1. How would you market a [specific product this company makes] to a [specific population you are familiar with]? (Example: How would you market Word to college students?)
2. How would you expand a [business you are familar with]?

Links:
The best book for tech interviews, in my opinion - "Programming Interviews Exposed"
Joel On Software article about resumes - must read
Joel On Software techInterview section - more questions and answers
Seven Questions Employees Should Ask Before Joining a Startup

Programming Books:

The original and best C reference by the creators of C:

C Programming Language (2nd Edition) by Brian W. Kernighan
and
Dennis M. Ritchie


The original and best C++ reference by the creator of
C++:
The C++ Programming Language (Special 3rd Edition)
by

Bjarne Stroustrup
(creator of C++)

0 Comments:

Post a Comment

<< Home