A knowledge aid is a condensed, high-signal reference designed for rapid recall during interviews, contests, or revision. Unlike tutorials that teach from scratch, knowledge aids assume familiarity and focus on pattern recognition, decision shortcuts, and common pitfalls.
Motivation: In a 45-minute interview, you have ~2 minutes to identify the right technique. A mental decision tree turns that from guesswork into systematic elimination.
// Sorted array: find pair with target sum
int left = 0, right = n - 1;
while (left < right) {
int sum = arr[left] + arr[right];
if (sum == target) { /* found */ break; }
else if (sum < target) left++;
else right--;
}
# Sorted array: find pair with target sum
left, right = 0, len(arr) - 1
while left < right:
s = arr[left] + arr[right]
if s == target:
break # found
elif s < target:
left += 1
else:
right -= 1
// Sorted array: find pair with target sum
int left = 0, right = arr.length - 1;
while (left < right) {
int sum = arr[left] + arr[right];
if (sum == target) { break; } // found
else if (sum < target) left++;
else right--;
}
// Longest subarray with sum <= k
int left = 0, sum = 0, maxLen = 0;
for (int right = 0; right < n; right++) {
sum += arr[right];
while (sum > k) sum -= arr[left++];
maxLen = max(maxLen, right - left + 1);
}
# Longest subarray with sum <= k
left = s = max_len = 0
for right in range(len(arr)):
s += arr[right]
while s > k:
s -= arr[left]
left += 1
max_len = max(max_len, right - left + 1)
// Longest subarray with sum <= k
int left = 0, sum = 0, maxLen = 0;
for (int right = 0; right < n; right++) {
sum += arr[right];
while (sum > k) sum -= arr[left++];
maxLen = Math.max(maxLen, right - left + 1);
}
// Minimum value that satisfies condition
int lo = minPossible, hi = maxPossible;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (condition(mid)) hi = mid; // mid works, try smaller
else lo = mid + 1; // mid too small
}
// lo is the answer
# Minimum value that satisfies condition
lo, hi = min_possible, max_possible
while lo < hi:
mid = (lo + hi) // 2
if condition(mid):
hi = mid # mid works, try smaller
else:
lo = mid + 1 # mid too small
# lo is the answer
// Minimum value that satisfies condition
int lo = minPossible, hi = maxPossible;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (condition(mid)) hi = mid;
else lo = mid + 1;
}
// lo is the answer
□ Clarify problem (2 min)
- Input format, constraints, edge cases
- Ask about duplicates, negatives, empty input
□ Work examples by hand (2 min)
- At least 2 examples: normal + edge case
- Trace through your intended approach
□ State approach + complexity (2 min)
- "I'll use X because Y, time O(?), space O(?)"
- Mention alternatives and why you chose this one
□ Code cleanly (10 min)
- Meaningful variable names
- Handle edge cases inline
- Don't premature-optimize
□ Trace through example (2 min)
- Walk through code with your example
- Check off-by-one, boundary conditions
□ Test edge cases (2 min)
- Empty input, single element, all same, sorted reverse
- Integer overflow for large inputs
□ Discuss optimizations (if time)
- Can you do better time? Better space?
- Any preprocessing that helps?
Key Insight: The best interview performers don’t know more algorithms — they recognize patterns faster. Use this chapter as a mental model to build that recognition.