Compiling brilliance
Did you know? An LRU cache is a HashMap + a doubly-linked list → O(1) get & put.
Compiling brilliance
Did you know? An LRU cache is a HashMap + a doubly-linked list → O(1) get & put.
Tag
68 articles tagged java.
A diagram-first guide to the array and dynamic array data structure: O(1) random access, why append is amortized O(1) via doubling, time complexity, and interview questions.
Balanced search trees explained: AVL and red-black, the self-balancing binary search tree data structure that guarantees O(log n). Rotations, time complexity, and interview questions.
A diagram-first guide to Big-O notation and time complexity analysis: the growth classes from O(1) to O(n!), reading complexity off code, space complexity, amortized analysis, and interview prep.
A diagram-first guide to the binary search algorithm: the lo/hi/mid loop, avoiding overflow, lower and upper bound, binary search on the answer, O(log n) time complexity, and interview prep.
A diagram-first guide to the binary search tree data structure and its algorithms: search, insert, in-order sort, and the three delete cases, with time complexity and interview questions.
A diagram-first guide to the binary tree data structure: nodes, terminology, the three DFS traversals plus level-order BFS, height and time complexity, and a complete interview-ready implementation.
The breadth-first search (BFS) algorithm: explore a graph level by level with a queue, find the shortest path in an unweighted graph, grid and multi-source BFS, time complexity, and interview prep.
Coding questions to memorise for interviews: the pattern templates — two pointers, sliding window, binary search, backtracking, DP — that solve most coding interview questions from memory.
Concurrency patterns explained: producer-consumer, thread pool, future, read-write lock, thread-safe singleton, and a semaphore-bounded pool for safe multithreaded design.
The depth-first search (DFS) algorithm explained: recursion vs an explicit stack, three-colour cycle detection, connected components, flood fill, O(V+E) time complexity, and interview questions.
Design patterns explained for interviews and low-level design: the Gang of Four patterns — factory, builder, singleton, adapter, decorator, strategy, observer, state, template method, command.
The dynamic programming algorithm explained: memoization vs tabulation, optimal substructure, overlapping subproblems, the 0/1 knapsack, time complexity, and interview prep.
A diagram-first guide to the graph data structure: vertices and edges, adjacency list vs matrix, degree, connected components, time complexity, and a complete implementation for interviews.
A diagram-first guide to greedy algorithms: interval scheduling, the exchange argument that proves a greedy choice is safe, where greedy fails, time complexity, and interview prep.
A diagram-first guide to the hash table data structure: hashing, buckets, collisions, chaining, load factor, resize, equals/hashCode contract, time complexity, and hash map interview questions.
A friendly, diagram-first guide to the binary heap and priority queue data structure: the array embedding, sift-up and sift-down, heapify, time complexity, and interview follow-ups.
A diagram-first guide to the linked list data structure: singly vs doubly linked nodes, O(1) splicing, in-place reversal, Floyd cycle detection, plus time complexity and interview prep.
Object-oriented programming explained for interviews: encapsulation, abstraction, inheritance, polymorphism, and composition over inheritance (is-a vs has-a) with a worked payment-system example.
A diagram-first guide to the queue and deque data structure: FIFO enqueue and dequeue, the circular buffer (ring) fix, sliding window maximum, time complexity, and interview questions.
Recursion and backtracking explained with diagrams: base case, call stack, choose-explore-unchoose, pruning, time complexity, and interview code for subsets, permutations, and N-queens.
The sliding window algorithm explained: fixed and variable windows, the two-pointer technique, amortized O(n) time complexity, and interview code for max subarray sum and longest substring.
The SOLID design principles explained with code: single responsibility, open/closed, Liskov substitution, interface segregation, dependency inversion, plus DRY, KISS and YAGNI for low-level design.
A diagram-first guide to sorting algorithms: insertion sort, merge sort, quicksort partition and pivot, heap sort, stability, the O(n log n) lower bound, time complexity, and interview prep.
The stack data structure (LIFO) explained: push, pop, peek in O(1), the call stack behind recursion, and the monotonic stack, with time complexity and a full implementation for your coding interview.
The topological sort algorithm on a DAG: Kahn's algorithm with in-degrees and DFS post-order, how it detects a cycle, O(V+E) time complexity, and interview questions.
The two pointers algorithm explained: converging and fast/slow pointers, two-sum on a sorted array, valid palindrome, container with most water, O(n) time complexity, and interview prep.
A diagram-first guide to the union-find (disjoint set union) data structure: find and union, path compression, union by rank, near-constant time complexity, and interview code.
The Uber ride concurrency interview question: seat ride-request threads into cabs of four — 4+0, 0+4, or 2+2 only — with a mutex, two semaphores, and a barrier. Deadlock-free, stress-tested.
A low-level design walkthrough of a web crawler core: the frontier queue, URL normalization before deduplication, a shared seen-set, per-host politeness, and termination by in-flight count.
A low-level design walkthrough of an online voting system: separating eligibility from the ballot so one vote per voter never links who voted to what, with an append-only, recountable tally.
A low-level design walkthrough of audio fingerprinting like Shazam: reducing a spectrogram to peak landmarks, hashing point pairs, and matching a noisy snippet by voting on a consistent offset.
A low-level design walkthrough of TOTP and Google Authenticator: a shared secret and the clock through HMAC to six digits, with an acceptance window that tolerates skew and blocks replay.
A low-level design walkthrough of a text editor core like Sublime: the gap buffer for fast cursor-local edits, plus undo/redo stacks built from edits that describe their own inverse.
A low-level design walkthrough of a download manager: splitting a file into byte-range segments, downloading them in parallel with retries, and resuming after a crash from an on-disk journal.
A low-level design walkthrough of a bar graph chart library: series data, a linear scale with nice ceilings, and pluggable renderers that draw the same chart in the console and as SVG.
A low-level design walkthrough of a coupon and promo system: eligibility rules as composable data, discounts with caps, the preview-redeem split, and usage limits that survive a rush.
A low-level design walkthrough of the Android unlock pattern: the crossing rule as a lookup table, pattern validation in O(1) per move, and counting all valid patterns with backtracking and symmetry.
A low-level design walkthrough of an online book reader system: a catalog of shared books, per-user sessions, page navigation that clamps at the covers, and the user-book bookmark as the hidden noun.
A low-level design walkthrough of a car rental system: reservations against category capacity instead of specific cars, interval counting on the calendar, pickup-time assignment, and late-fee billing.
A low-level design walkthrough of a thread pool: the bounded work queue, the worker loop that must never die, saturation and rejection, and the graceful shutdown promise — fully tested.
A low-level design walkthrough of a Splitwise expense sharing system: immutable expenses, derived balances, split strategies with the rounding paisa rule, and greedy debt simplification.
A low-level design walkthrough of a call center: rank-based dispatch across respondents, managers and a director, escalation that re-dispatches, queues per rank, and the freed agent who drains them.
A low-level design walkthrough of an elevator system: why first-come-first-served zigzags, the LOOK sweep algorithm, hall calls vs car calls, direction as state — fully implemented and tested.
A low-level design walkthrough of an AWS-style alarm and alert service: threshold rules as data, consecutive-breach debouncing, three honest states, and observers notified on transitions only.
A low-level design walkthrough of an airline booking system: identity inventory where seat 12A is nobody's substitute, the PNR as hidden noun, and seat holds that expire by the lazy clock.
A low-level design walkthrough of a hotel management system: half-open date ranges, the one-line overlap formula, booking a room type while the hotel assigns the room — fully implemented.
A low-level design walkthrough of an inventory management system: on-hand vs reserved vs available, two-phase reservations with commit and release, and the race that double-sells the last unit.
A low-level design walkthrough of a restaurant management system: seating by table fit, order tickets through a kitchen queue, and billing that frees the table — coordinated state machines.
A low-level design walkthrough of an in-memory file system: files and directories behind one Node interface, path resolution as a walk, recursive size via the Composite pattern — fully implemented.
A low-level design walkthrough of a JSON parser: the grammar as a call graph, recursive descent with a position cursor, escape and number handling, and error messages that point.
A low-level design walkthrough of a logging library: ordered levels, a cheap threshold gate, formatters, appenders as a Strategy, and the complete implementation of the log4j shape.
A low-level design walkthrough of an ATM: a state machine that retains cards after three wrong PINs, a bank service interface because the ATM owns no truth, and cash planned before any debit.
A low-level design walkthrough of chess: scoping the unbuildable, one movement rule per piece via the Strategy pattern, a shared path-clear helper for sliding pieces, and the complete implementation.
A low-level design walkthrough of Tetris: why the falling piece never lives on the board, rotation as pure arithmetic, line clears as a filter, and the complete implementation of the classic.
A low-level design walkthrough of a jackpot slot machine: independent reels with injected randomness, the paytable as data instead of if-chains, and a credits ledger that always balances.
A low-level design walkthrough of minesweeper: separating truth from view, the flood fill cascade done with discipline, first-click safety, and the complete implementation of the classic.
A low-level design walkthrough of the 2048 game: the merge-once rule everyone breaks, why all four directions are one mergeLeft function, win and lose detection, and the complete implementation.
A low-level design walkthrough of snake and ladder: why snakes and ladders are one Map, how injecting the die makes the game testable, and the complete implementation with a clean turn loop.
A low-level design walkthrough of a vending machine: coins, inventory, the can't-make-change trap, and when design patterns earn their keep — the honest path from if-checks to the State pattern.
A low-level design walkthrough of tic tac toe (Tic-Tac-Toe): an O(1) win check with counters, a clean state machine, and the complete implementation of the classic warm-up interview question.
How to approach any low-level design interview: turn requirements into classes, methods, and state machines — the parking lot classic, fully built — plus a cheat sheet for picking design patterns.
A low-level design walkthrough of a rate limiter: the token bucket class, the race condition that breaks it, making it thread-safe, a per-client registry, and the complete implementation.
A friendly tour of the Stream API and functional programming: lambdas, pipelines, laziness, collectors — then interview questions on frequency counts, grouping, duplicates and second-highest.
A friendly tour of multithreading: threads, race conditions, synchronized, wait/notify — then the classic interview questions, odd-even printing, producer-consumer and deadlocks, solved and explained.
A friendly, diagram-first tour of the trie (prefix tree), the data structure behind autocomplete: insert, search, and prefix lookups step by step, plus a complete implementation.
A low-level design walkthrough of an O(1) LRU cache — a hash map plus a doubly linked list — how eviction works, the locking story, and the full browsable implementation.
A friendly, diagram-first walk through Dijkstra's shortest path algorithm: the ripple intuition, the invariant behind it, a step-by-step trace on a real graph, and a complete implementation.
The system design classic: where a rate limiter sits in your architecture, fixed window vs sliding window vs token bucket, going distributed with Redis, and a thread-safe core you can ship.