Skip to content
Tutorials Center
My learning

Topics

Lesson 77 of 77 ยท Interview Day

Interview Cheat Sheet

A one-page tech interview cheat sheet: complexity tables, key definitions, problem-solving patterns, SQL and JavaScript gotchas and a pre-interview checklist.

This is the page to read on the morning of an interview. It does not teach anything from scratch. It collects the facts people most often blank on, in tables you can scan in a few minutes: complexities, definitions, patterns for coding problems, classic SQL and JavaScript gotchas, and a last checklist. Each section points back to the lesson where the idea is explained.

If something here looks unfamiliar, treat that as a signal: open the linked lesson instead of memorizing the line. The two TryIts at the end are small stand-ins: one prints how fast common complexities grow, and one runs the JavaScript gotchas so you can see the output yourself.

The one-page plan

Complexity Know the table cold.
Patterns Name the pattern first.
Gotchas Traps are favorite questions.
Checklist Same routine every time.

Skim, then close the page and do a problem.

1 / 2

Complexity at a glance

Time complexity of common operations. "Avg" means the typical case and "worst" the bad case.

Structure Access Search Insert Delete Notes
Array O(1) O(n) O(n) O(n) Append at end is amortized O(1)
Linked list O(n) O(n) O(1) at a known node O(1) at a known node No index access
Hash table n/a O(1) avg, O(n) worst O(1) avg O(1) avg Unordered unless the language keeps order
Stack / queue n/a O(n) O(1) O(1) Push/pop or enqueue/dequeue
Binary search tree O(h) O(h) O(h) O(h) h is log n if balanced, n if skewed
Balanced tree O(log n) O(log n) O(log n) O(log n) Red-black, AVL, B-tree
Binary heap n/a O(n) O(log n) O(log n) Peek min or max in O(1)

Sorting algorithms:

Algorithm Average Worst Extra space Stable
Quicksort O(n log n) O(n^2) O(log n) No
Merge sort O(n log n) O(n log n) O(n) Yes
Heap sort O(n log n) O(n log n) O(1) No
Insertion sort O(n^2) O(n^2) O(1) Yes
Counting sort O(n + k) O(n + k) O(k) Yes

Graph algorithms, with V vertices and E edges: BFS and DFS are O(V + E); Dijkstra with a binary heap is O((V + E) log V) and needs non-negative weights; Bellman-Ford is O(V * E) and handles negative edges; topological sort is O(V + E) on a directed acyclic graph.

A quick reading guide for estimating Big O: one loop over n is O(n); nested loops over n are O(n^2); halving the problem each step is O(log n); trying every subset is O(2^n); trying every ordering is O(n!). Always state the space cost too, and note that recursion uses stack space. See the complexity questions lesson.

Key definitions

Four ideas to state clearly

ACID Atomic, consistent, isolated, durable.
CAP In a partition, pick consistency or availability.
SOLID Five design principles for classes.
Idempotent Repeating it changes nothing more.

If you can say each in one sentence, you are ready for the follow-up.

1 / 2
Term One-line meaning
Process / thread Separate memory space / execution path sharing memory
Deadlock Tasks wait on each other forever (needs mutual exclusion, hold and wait, no preemption, circular wait)
Race condition Result depends on the timing of unsynchronized access
Closure Function plus the variables of the scope it was created in
Immutable Cannot change after creation; safe to share
Pure function Same input gives same output, with no side effects
Hashing / encryption One-way fingerprint / reversible with a key
Cache-aside Read cache, on a miss load from the source and store
Eventual consistency Replicas converge if updates stop
Sharding / replication Split data across nodes / copy data to nodes
Load balancer Distributes requests across servers
CDN Cached content served near the user
Rate limiting Cap the request rate (token bucket, sliding window)
REST Resource-based HTTP API using standard methods and status codes
JWT Signed (not encrypted) token carrying claims
XSS / CSRF / SQL injection Script injection into a page / forged requests from a logged-in browser / user input run as SQL

Deeper explanations live in OS and concurrency, NoSQL and caching, OOP, SOLID and patterns and security.

Problem-solving patterns

When you read a coding problem, look for the shape first.

Clue in the problem Try this pattern
Sorted array, find a pair or target Two pointers or binary search
Contiguous subarray or substring, longest/shortest/max sum Sliding window or prefix sums
"Have I seen this before?", counts, duplicates Hash map or set
Parentheses, undo, nested structure Stack
Level by level, shortest path in an unweighted graph BFS with a queue
All paths, connected components, tree depth DFS or recursion
Top k, running median, merge k lists Heap
Count ways, min cost, choices that overlap Dynamic programming
All combinations or permutations Backtracking
Order with dependencies Topological sort
Intervals Sort by start, then merge in one pass
Cycle in a linked list Fast and slow pointers

Routine for any coding problem: restate it, ask about edge cases, work a tiny example, propose a brute-force solution and its cost, improve it with a pattern, code it, test with the example and the edge cases (empty input, one item, duplicates, negatives, very large input). The lessons array and string patterns, trees and graphs and recursion and dynamic programming practice these.

SQL gotchas

Trap What happens
NULL = NULL Evaluates to unknown, not true; use IS NULL
WHERE versus HAVING WHERE filters rows before grouping, HAVING filters groups
COUNT(*) versus COUNT(col) The second skips rows where col is null
LEFT JOIN with a WHERE on the right table Turns it into an inner join; filter in the ON clause instead
NOT IN with a null in the list Returns no rows; prefer NOT EXISTS
UNION versus UNION ALL UNION removes duplicates (slower); UNION ALL keeps them
Selecting a non-grouped column Error in strict engines, arbitrary value in lenient ones
ORDER BY without a clear key plus LIMIT Unstable page contents; add a tiebreaker column
Function on an indexed column in WHERE The index may not be used (WHERE LOWER(name) = ...)

Typical task shapes: second highest value (a subquery, DENSE_RANK, or LIMIT with OFFSET), duplicates (GROUP BY ... HAVING COUNT(*) > 1), top n per group (ROW_NUMBER() OVER (PARTITION BY ...)), gaps and running totals (window functions). Practice in SQL query questions and indexes, normalization and transactions.

JavaScript gotchas

Expression Result Why
typeof null "object" Historical bug
0.1 + 0.2 0.30000000000000004 Binary floating point
[] + {} "[object Object]" Both converted to strings
[10, 9, 1].sort() [1, 10, 9] Default sort compares strings
"5" - 2 and "5" + 2 3 and "52" - converts to number, + may concatenate
NaN === NaN false Use Number.isNaN
parseInt("08px") 8 Parses a leading number
[1, 2, 3].map(parseInt) [1, NaN, NaN] map passes the index as radix

Behavior rules worth remembering: var is function-scoped and let/const block-scoped with a temporal dead zone; arrow functions take this from their surrounding scope; promise callbacks (microtasks) run before setTimeout callbacks (macrotasks); async functions always return a promise. See types and coercion, scope and closures and the event loop.

Some facts differ between languages or versions (sort stability, integer sizes, default behaviors). If you are unsure whether a rule applies to the language in your interview, say so and state what you would check, rather than guessing.

Python and Java one-liners

  • Python: is compares identity, == equality; mutable default arguments are shared; the default CPython build has a GIL, so use processes for CPU-bound parallelism; dict keeps insertion order; use collections.Counter, defaultdict and heapq in algorithm problems.
  • Java: override equals and hashCode together; String is immutable; HashMap is not thread-safe (use ConcurrentHashMap); volatile is visibility, not atomicity; prefer ArrayList unless you have a reason; try-with-resources closes resources for you.

System design in five lines

Clarify requirements and scale, estimate traffic and storage, sketch the main components (clients, load balancer, services, cache, database, queue), go deeper on the hardest part (data model, scaling, consistency), and finish with trade-offs and failure handling. Practice with the building blocks and rate limiters, feeds and chat.

Run it: how complexities grow

This stand-in prints roughly how many steps each complexity class takes for several input sizes. It helps you feel why O(n^2) breaks at a million items while O(n log n) does not.

JS Growth of common complexities

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Run it: the JavaScript gotchas

Run the table above for yourself. Seeing the output once is worth more than reading it ten times.

JS Check the JavaScript gotcha table

Press Run (or Ctrl + Enter) to see the console output here.

No output.

What is real and what is the stand-in: the tables and rules are the real facts; the code only prints numbers and results so that you can see them. Nothing here touches a database or a browser outside the editor, so the SQL table is read-only.

The pre-interview checklist

  • I can state the complexity of arrays, hash tables, trees, heaps and the common sorts.
  • I can explain a closure, a deadlock, ACID and idempotency in one sentence each.
  • I have a pattern for each clue in the problem-pattern table.
  • I know where my weak topics are and have reviewed them once more.
  • I have three to five behavioral stories and a list of questions to ask.
  • My setup, route or meeting link is tested (see the interview day checklist).
  • I will clarify, narrate, test and talk about trade-offs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A problem asks for the longest substring with at most two distinct characters. Which pattern fits best?

    A contiguous substring with a constraint on its contents is the classic sliding window, with a map to track the distinct characters.
  2. 2. Why can NOT IN return no rows at all?

    If the list contains NULL, "x NOT IN (..., NULL)" is never true, so every row is filtered out. Use NOT EXISTS or filter out the nulls.
  3. 3. What does [10, 9, 1].sort() return in JavaScript?

    The default comparison converts elements to strings, so "1" < "10" < "9". Pass (a, b) => a - b for numeric order.
  4. 4. Which sorting algorithm is stable and O(n log n) in the worst case?

    Merge sort keeps equal elements in order and always runs in O(n log n), at the cost of O(n) extra space. Quicksort and heap sort are not stable; insertion sort is O(n^2).

Summary

  • Know the complexity table: arrays, hash tables, trees, heaps, sorts and graph algorithms.
  • State key definitions (ACID, CAP, SOLID, idempotency, deadlock, closure) in one clear sentence.
  • Spot the pattern from the clue in the problem, then follow a steady routine: clarify, example, brute force, improve, code, test.
  • Remember the classic traps: SQL nulls and joins, and JavaScript coercion, sorting and event-loop order.
  • Finish with the checklist, then rest.

Good luck. If you want more practice, go back to the practice sets or review the study plan.