Understand the problem
Talk out the problem
Give the questions in the order assigned
State the question clearly and concisely
Give hints if stuck
Watch the time
Question-Specific |
---|
Did the student state the assumptions they are making about the problem and design of the solution verbally or in writing, including drawing diagrams as appropriate? |
Did the student “talk-out” (verbally express) their thought process as they were implementing the solution? |
Ask the student to explain why some portion of their code is important to solving the problem. Are they able to provide a brief, understandable, and compelling explanation? |
Were the solutions syntactically correct for Java (7/8), Python, or Javascript, as appropriate? |
Ask for an explanation of the solution they provide and why they think it is best. How well is the student able to explain it to you? |
Entire Interview |
---|
Was the student attentive and focused on the interview? |
How knowledgeable or confident did the student appear to you? |
Was the student polite and amiable? (5 = exellent to 0 = poor) |
Did the student seem like they would be a good team player? (i.e. were they willing to explore alternative suggestions?) |
How many hints did the student need over the entire interview? (5 = none, 4 = one or two, 3 = 3-4, 2 = 5-6, 1 = more than six) |
Extremes
Error conditions
Defensive programming involves writing code that actively prevents errors during runtime by anticipating and handling unexpected conditions.
Check inputs
int factorial(int n) {
if (n == 1) return 1; // What if `n < 1`?
return n * factorial(n-1);
}
void inorderTrav(Node root) {
inorderTrav(root.left); // What if `root == null`?
System.out.println(root.v);
inorderTrav(root.right);
}
Check intermediate results
int funcA() {
int value = funcB(); // What if funcB fails? What if funcB returns value not valid?
...
}
The Robustness Principle, a.k.a. Postel's Law, is a design guideline for software and systems, particularly in networking, which states:
"Be conservative in what you send, be liberal in what you accept."
When generating output (e.g., sending data), adhere strictly to protocol or specification to avoid creating ambiguous or invalid data that might cause errors for other systems or software.
When receiving input, be tolerant and flexible, gracefully handle imperfect or unexpected input to avoid crashing or malfunctioning.row-major
Java arrays are stored in a row-major order, meaning that the elements in each row are stored sequentially in memory.
Efficient (row-major)
for (int[] row : a) { // Iterates through each row
for (int element : row) { // Iterates through each element in the row
...
}
}
Inefficient (column-major)
for (int col = 0; col < numCols; col++) {
for (int row = 0; row < numRows; row++) {
int element = array[row][col];
// Do something with element
}
}
Race condition: occurs when two or more threads access shared data or resources concurrently, and the outcome of the execution depends on the sequence or timing of these threads.
Fixing data races
The volatile
keyword ensures that the value of a variable is always read from and written to main memory, rather than being cached in the thread’s local memory (cache).
The synchronized
keyword enforces mutual exclusion, ensuring that only one thread can access a critical section of code (such as a method or block) at a time.
Both volatile
and synchronized
slow down the program; Use when neccessary to ensure correctness
volatile
prevents various optimizations, forces memory accessessynchronized
prevents parallelism on multi-core machines