Programming Interview Questions
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.
- Implement
InsertandDeletefor- singly-linked linked list
- sorted linked list
- circular linked list
int Insert(node** head, int data)
int Delete(node** head, int deleteMe) - Split a linked list given a pivot value
void Split(node* head, int pivot, node** lt, node** gt) - Find if a linked list has a cycle in it. Now do it without marking nodes.
- Find the middle of a linked list. Now do it while only going through the list once. (same solution as finding cycles)
Strings
- 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!
- Reverse a string
- Strip whitespace from a string in-place
void StripWhitespace(char* szStr) - Remove duplicate chars from a string ("AAA BBB" -> "A B")
int RemoveDups(char* szStr) - Find the first non-repeating character in a string:("ABCA" -> B )
int FindFirstUnique(char* szStr) - 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
- You may be asked about using Unicode strings. What the interviewer is usually looking for is:
Read full article from Programming Interview Questions
No comments:
Post a Comment