面试题目总结 转载
标签(空格分隔): interview
转载于chengdujin博客
- 终于找到这篇了, 之前看过, 整理的很全面, 后来丢掉了链接...
Data Structures
- Integer
- find number of 1s
- next largest smaller
- smallest larger number
- determine if is palindrom
- itoa, atoi
- add 2 numbers w/o using + or arithmetic operators
- implement *, -, / using only +
- find max of two numbers w/o comparison
- swap two numbers with +/-
- swap two numbers with ^
- given an integer, find the closest number that is palindrome
- implement putlong() by putchar()
- Bit array
- Linked list
- find cycle,
- find position of cycle starts
- reverse LL
- delete a node in middle
- each node contains a value pointer pointing to a node, duplicate LL.
- remove duplicates from sorted/un-sorted LL.
- find n-th to last node to end
- number is represented by LL, add 2 numbers
- Array
- Longest common substring (LCSubstr)
- Longest common subsequence (LCS).
- Longest increasing subsequence (LIS).
- Longest palingdrome in string.
- array, elements are +/-, find subsequence of max sum
- circular array, elements are +/-, find subsequence of max sum
- find all pairs of integers add up to a sum
- find all pairs of integers add up to a sum, integers are +/- and sorted
- find one missing number in N numbers in range [0, N]
- find two missing number in N numbers in range [0, N].
- binary search circular array
- Given {a1, a2, a3, ..}, {b1, b2, b3, ...}, get {a1, b1, a2, b2, ...}
- Given 2 arrays A and B, A large enough to hold both, merge B into A.
- String
- KMP, Rabin-Karp, Boyer Moore
- reverse string
- reverse words in string
- strcpy, strcmp, strstr, atoi, itoa, strdup
- remove duplicate characters in O(1) space
- Given dictionary, transform one word to another of same length.
- Given large text, find min cover distance of n words.
- find longest word made of other words
- find first non-repeated char
- remove specified char from a string
- Matrix
- matrix elements are +/-, find submatrix of max sum
- rotate a matrix by 90 degrees
- each cell is black/white, find max subsquare with black border.
- binary matrix, find largest square matrix with 1s
- binary matrix, find largest rectangle matrix with 1s
- Stack
- implement stack by queue.
- augmented stack with O(1) push, pop, min
- use single array to implement 3 stacks
- sort a stack in ascending order using only push/pop/top/isEmpty/isFull
- Queue
- implement queue by 2 stacks
- Priority Queue
- Heap
- create heap on array
- Young Tableau
- find element
- get k-th element
- BST
- pre/in/post-order traversal, recursive and iterative
- pre/in/post-order traversal, recursive and iterative, with parent pointer
- find height
- determine IsBST
- find "next" node of a given node in inorder sequence
- find k-th inorder element
- find range of elements
- find diameter
- find all path adding to a sum
- Check if a tree is balanced
- Convert sorted array into balanced BST
- Find first common ancestor of two nodes in a BT or BST
- Link each node to its right sibling
- Print by level (BFS)
- Print by level (BFS) in reverse order
- Determine if 2 BSTs have the same structure
- Create a mirror BT of a BT
- Replicate a linked structure
- 2-3-4 Tree
- Red-Black Tree
- Splay Tree
- AVL Tree
- Trie
- Suffix Array
- Suffix Tree
- LCSubstr (longest common substring)
- Longest repeated substring
- longest palindrome
- substring search
- data compression
- B-Tree
- KD Tree
- Range Tree
- Hash Table
- Bloom filter
- Disjoint set
- Graph
- DFS, BFS
- find path existence between two nodes
- Min vertice set covering all edges
- shortest path
- minimum spanning tree
- min edge coverage by vertex
Sorting
- Bubble sort
- Insertion sort
- Selection sort
- Shell sort
- Heap sort
- Quick sort
- Merge sort
- N-way merge sort (external sort)
- Counting sort
- Bucket sort
Search
- Linear search
- Binary search
- Binary search, iterative/recursive
- find missing number is sorted array
- search in circular sorted array
- Quick Select
Dynamic programming
- BST
- COV
- ILP
- KS
- LCS
- LSP
- MCM
- ODP
- SCP
- SPA
- SPC
- TSP
- Given array a[], when i < j, get max(a[i] - a[j]).
- levenshtein edit distance
- Coin Change problem.
Large-scale system
- Bloom filter
- Bit-array/bit-map
- Heap
- Hash table
- d-left hashing
- Sub-division
- Database indexing
- Inverted index
- External sort
- Map-reduce
Discrete math, Probability and Statistics, Numerical Computation
- Permutation
- 3 colors, how many ways to color a cube?
- robot, ways to go to diagonal corner on NxN matrix?
- print all combinations of valid n-pairs of parentheses
- print all subsets of a set
- Combination
- Sampling
- Random number generator
- What's a good random number generator?
- Given random generator [1, 2, 3, 4, 5], generate random in [1..7].
- Reservoir sampling
- Find median in stream
- Card shuffling
- Primality testing
- Find prime numbers: naive, sieve of Eratosthenes, sieve of Atkin
- Randomized primality testing, what's good random generator
- Fibonacci sequence
- Factorial numbers
- Frobenous numbers
- Newton-Ralphson algorithm
- Bayes theorem
Computational algebra
- Convex-hull
- Closest pairs
Computational theory
- Automata theory
- DFA
- NFA
- Regular language
- Pumping lemma
- Turing machine
- NP-completeness
- TSP
- Vertex-cover problem
- Set-covering problem.
- Subset-sum problem.
OS
- Process and thread
- Semaphore, mutex, monitor
- Function call/call frame
- Context switch
- Multi-threading
- Multi-process
- Thread safety
- Big/Little-endian
- Heap/stack
- Malloc/free
- Virtual memory, page fault, thrashing
- DMA (Direct Memory Access)
Networking
- 7-layer OSI model
- 4-layer TCP/UDP model
- TCP/UDP
- TCP 3-way handshake (ACK machanism), flow control, congestion control
- Things happen after entering url
- Routing protocols: BGP, OSPF, RIP
- Subnet mask, packet routing on same/different network.
- Performance
Database
- Normalization
- External sorting
- B-tree, B+-tree.
- Relational algebra
Compiler
- LL, SLR, LALR, LR, GLR
- recursive precedence
- Operator precedence
- Postfix evaluation of arithmetic expression
- implement a calculator
C/C++/Java
- const char , char const, const char * const
- static
- volatile
- explicit
- Object/class
- Inheritance
- Encapsulation
- Polymorphism
- operator overloading
- Composition/inheritance
- Interface, abstract class
- Struct/class
- 4 default methods of a C++ struct/class
- deep copy/shallow copy
- C++ name hiding
- C++ smart pointer
- friend function/class
- Multiple inheritance
- Virtual inheritance
- Constructor
- Copy/assignment constructor
- Virtual destructor
- Virtual function, vtable
- Pure virtual function
- Macro, typedef, inline
- C, C++, Java comparison
- Garbage collection
- Dangling pointer, free null pointer, memory leak
- New/Delete
- Malloc/free/realloc/calloc
- Lock
- Dead lock's four conditions
#pragma
directive- Exception handling
- try/catch/finally
- final, finally, finalize
- Java object reflection
- C++ templates, java generics
- Effect of keeping constructor private
- Pass by Value, reference, pointer
- Reference v.s. pointer
- In-memory file system data structures and algorithms?
- Implement singleton
- Implement singleton w/o static/global variable
- Thread programming possible problems
- sizeof operator.
- Java: vector v.s. ArrayList
- int (a*)[10]
- Implement a lock.
- Implement a buffer for DataOutputStream.
- awk, tr, uniq, grep
Other problems
- 2 eggs, 100 floors, find floor that breaks egg minimizing number of drops.
- 5 quart jug and 3 quart jug, measure 4 quarts of water.
- 100 lockers, open every other i-th locker (i = 1, 2, ..., 100). Final open?
- Men on island, can see hat on others only. N men, C hats, days to remove?
- 8/12 balls, find the one lighter/heavier
- 8/12 balls, find one weighs different
- 2 fuses each burns in 1 hour, measure 45 minutes
- Bridge crossing, 1, 2, 5, 10. Minual number to pass bridge
- Orange, apple, orange and apple, all labeled wrong. Find out.
- 3 light switches, only one can be on at a time. Find it out.
- Find the biggest, 2 biggest, biggest & smallest
- nmk cube, how many are on the surface?
- Test a pen, ATM machine, webpage, vending machine, program crash?
- Given phone #, print all word representations on phone pad.
- Find overlap of rectangles
- Find median of two sorted arrays.
- N computers each hold N numbers. Find median of these N*N numbers.
- Recontruct a BT from pre/in/post-order traversal
- Recontruct a BST from pre/in/post-order traversal
- Find longest prefix common to all strings
- Implement LRU cache system, O(1) find and update
- Shifted sorted array, rotate.
- Histogram, find max internal rectangle.
- Tournament problem
- N people, 1 celebrity, find celebrity in O(n) time.
- 4 jars, 1 polluted so pills weigh +1, find out which jar
- 25 horses, 5 horses maximal each match. Find the fastest 3
- Mirror, why left/right reversed, not up/down?
- How is next_permutation() in STL implemented?
- N line segments on number axis, calculate common coverage
- wild card match on patterns * (0-n) and ? (1).
- Find number of trailing zeros in n!
- Print square matrix in a spiral inwardly.
- Find one's phone number given resume only
- N stairs, each time can go up 1 or 2. How many ways to go up?
- Find majority element in an array.
- Two cubes as a calendar
- Coin change problem
- Josephus Circle, last survivor?
- Pick marbles, strategy to win?
- Get sequence 1, 11, 21, 1211, ...
- C program that prints itself
- Print week given date
- enter code, allow one miss
- Check equality of two number sets