From e21a49ff5c7eab37c4e8f23395496a6a823fb571 Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Tue, 10 Feb 2026 09:36:10 -0500 Subject: [PATCH 1/6] learn: cycle 1 - count fresh oranges and return 0 if none --- .../medium/0994-rotting-oranges/README.md | 47 +++++++++++++++++++ .../rotting-oranges.test.ts | 9 ++++ .../0994-rotting-oranges/rotting-oranges.ts | 26 ++++++++++ 3 files changed, 82 insertions(+) create mode 100644 leetcode/medium/0994-rotting-oranges/README.md create mode 100644 leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts create mode 100644 leetcode/medium/0994-rotting-oranges/rotting-oranges.ts diff --git a/leetcode/medium/0994-rotting-oranges/README.md b/leetcode/medium/0994-rotting-oranges/README.md new file mode 100644 index 0000000..903ee2c --- /dev/null +++ b/leetcode/medium/0994-rotting-oranges/README.md @@ -0,0 +1,47 @@ +# [994. Rotting Oranges](https://leetcode.com/problems/rotting-oranges/) + +![Medium](https://img.shields.io/badge/Medium-orange) + +## Problem Description + +You are given an `m x n` grid where each cell can have one of three values: + +- `0` representing an empty cell +- `1` representing a fresh orange +- `2` representing a rotten orange + +Every minute, any fresh orange that is **4-directionally adjacent** (up, down, left, right) to a rotten orange becomes rotten. + +Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return `-1`. + +## Examples + +**Example 1:** + +```text +Input: grid = [[2,1,1],[1,1,0],[0,1,1]] +Output: 4 +``` + +**Example 2:** + +```text +Input: grid = [[2,1,1],[0,1,1],[1,0,1]] +Output: -1 +Explanation: The orange in the bottom left corner (row 2, column 0) is never rotten, because rotting only happens 4-directionally. +``` + +**Example 3:** + +```text +Input: grid = [[0,2]] +Output: 0 +Explanation: Since there are already no fresh oranges at minute 0, the answer is just 0. +``` + +## Constraints + +- `m == grid.length` +- `n == grid[i].length` +- `1 <= m, n <= 10` +- `grid[i][j]` is `0`, `1`, or `2` diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts new file mode 100644 index 0000000..595fb0a --- /dev/null +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts @@ -0,0 +1,9 @@ +import { describe, it, expect } from 'vitest'; +import { orangesRotting } from './rotting-oranges'; + +describe('Rotting Oranges', () => { + it('should return 0 when there are no oranges at all', () => { + const grid = [[0, 0]]; + expect(orangesRotting(grid)).toBe(0); + }); +}); diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts new file mode 100644 index 0000000..ce19bce --- /dev/null +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts @@ -0,0 +1,26 @@ +export function orangesRotting(grid: number[][]): number { + let freshCount: number = 0; + + for (let i = 0; i < grid.length; i++) { + for (let j = 0; j < grid[i].length; j++) { + if (grid[i][j] === 1) { + freshCount++; + } + } + } + + if (freshCount === 0) { + return 0; + } + + // TODO: Initialize a queue with all initially rotten oranges (value 2) + // INVARIANT: The queue contains [row, col, minutes] for each rotten orange at the start + + // TODO: Run BFS - while queue is not empty, process each rotten orange and rot adjacent fresh oranges + // INVARIANT: Each level of BFS represents one minute passing; freshCount decreases as oranges rot + + // TODO: After BFS completes, if any fresh oranges remain, return -1; otherwise return the minutes elapsed + // INVARIANT: freshCount === 0 means all oranges rotted successfully + + return -1; +} From 084bf92ef0ac1f3a3a9674017e181335531c2f11 Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Tue, 10 Feb 2026 09:37:28 -0500 Subject: [PATCH 2/6] learn: cycle 2 - test only rotten oranges (already passing) --- leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts index 595fb0a..4b39f5d 100644 --- a/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts @@ -6,4 +6,9 @@ describe('Rotting Oranges', () => { const grid = [[0, 0]]; expect(orangesRotting(grid)).toBe(0); }); + + it('should return 0 when there are only rotten oranges', () => { + const grid = [[2]]; + expect(orangesRotting(grid)).toBe(0); + }); }); From 2064076d8fa50d777a95101e2b810184cbc61812 Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Tue, 10 Feb 2026 20:26:49 -0500 Subject: [PATCH 3/6] learn: cycle 3 - implement BFS with level-by-level processing --- .../rotting-oranges.test.ts | 9 +++ .../0994-rotting-oranges/rotting-oranges.ts | 60 +++++++++++++++---- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts index 4b39f5d..c760867 100644 --- a/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts @@ -11,4 +11,13 @@ describe('Rotting Oranges', () => { const grid = [[2]]; expect(orangesRotting(grid)).toBe(0); }); + + it('should return correct minutes for basic rotting scenario', () => { + const grid = [ + [2, 1, 1], + [1, 1, 0], + [0, 1, 1] + ]; + expect(orangesRotting(grid)).toBe(4); + }); }); diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts index ce19bce..6b9625d 100644 --- a/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts @@ -1,26 +1,60 @@ export function orangesRotting(grid: number[][]): number { let freshCount: number = 0; + let minutes = 0; - for (let i = 0; i < grid.length; i++) { - for (let j = 0; j < grid[i].length; j++) { - if (grid[i][j] === 1) { - freshCount++; + // TODO: Initialize a queue with all initially rotten oranges (value 2) + const queue = []; + // INVARIANT: The queue contains [row, col, minutes] for each rotten orange at the start + for (let row = 0; row < grid.length; row++) { + for (let col = 0; col < grid[row].length; col++) { + if (grid[row][col] === 2) { + queue.push([row, col, minutes]); } } } - if (freshCount === 0) { - return 0; - } - - // TODO: Initialize a queue with all initially rotten oranges (value 2) - // INVARIANT: The queue contains [row, col, minutes] for each rotten orange at the start - // TODO: Run BFS - while queue is not empty, process each rotten orange and rot adjacent fresh oranges // INVARIANT: Each level of BFS represents one minute passing; freshCount decreases as oranges rot + while (queue.length > 0) { + // how many oranges rot at this minutes + const levelSize = queue.length; + + // process all oranges at this level + for (let i = 0; i < levelSize; i++) { + const [row, col] = queue.shift(); + + // check all 4 neighbors + if (row + 1 < grid.length && grid[row + 1][col] === 1) { + queue.push([row + 1, col, minutes]); + grid[row + 1][col] = 2; + freshCount--; + } + if (row - 1 >= 0 && grid[row - 1][col] === 1) { + queue.push([row - 1, col, minutes]); + grid[row - 1][col] = 2; + freshCount--; + } + + if (col + 1 < grid[0].length && grid[row][col + 1] === 1) { + queue.push([row, col + 1, minutes]); + grid[row][col + 1] = 2; + freshCount--; + } + if (col - 1 >= 0 && grid[row][col - 1] === 1) { + queue.push([row, col - 1, minutes]); + grid[row][col - 1] = 2; + freshCount--; + } + } + + // after processing the whole level, increment minutes + // but only if we actually added new rotten oranges to the queue + if (queue.length > 0) { + minutes++; + } + } // TODO: After BFS completes, if any fresh oranges remain, return -1; otherwise return the minutes elapsed // INVARIANT: freshCount === 0 means all oranges rotted successfully - - return -1; + return freshCount > 0 ? -1 : minutes; } From 5dae14fe665df8b64b8ddacb3374bb5454a65538 Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Tue, 10 Feb 2026 20:33:25 -0500 Subject: [PATCH 4/6] learn: cycle 4 - fix freshCount initialization to count fresh oranges --- .../rotting-oranges.test.ts | 9 ++++++ .../0994-rotting-oranges/rotting-oranges.ts | 32 ++++++++----------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts index c760867..19d1acd 100644 --- a/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.test.ts @@ -20,4 +20,13 @@ describe('Rotting Oranges', () => { ]; expect(orangesRotting(grid)).toBe(4); }); + + it('should return -1 when impossible to rot all oranges', () => { + const grid = [ + [2, 1, 1], + [0, 1, 1], + [1, 0, 1] + ]; + expect(orangesRotting(grid)).toBe(-1); + }); }); diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts index 6b9625d..f9cf633 100644 --- a/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts @@ -2,59 +2,53 @@ export function orangesRotting(grid: number[][]): number { let freshCount: number = 0; let minutes = 0; - // TODO: Initialize a queue with all initially rotten oranges (value 2) - const queue = []; - // INVARIANT: The queue contains [row, col, minutes] for each rotten orange at the start + const queue: number[][] = []; + + // Initialize queue with all initially rotten oranges and count fresh oranges for (let row = 0; row < grid.length; row++) { for (let col = 0; col < grid[row].length; col++) { if (grid[row][col] === 2) { - queue.push([row, col, minutes]); + queue.push([row, col]); + } else if (grid[row][col] === 1) { + freshCount++; } } } - // TODO: Run BFS - while queue is not empty, process each rotten orange and rot adjacent fresh oranges - // INVARIANT: Each level of BFS represents one minute passing; freshCount decreases as oranges rot + // BFS: Process oranges level-by-level (each level = 1 minute) while (queue.length > 0) { - // how many oranges rot at this minutes const levelSize = queue.length; - // process all oranges at this level for (let i = 0; i < levelSize; i++) { - const [row, col] = queue.shift(); + const [row, col] = queue.shift()!; - // check all 4 neighbors + // Check all 4 neighbors if (row + 1 < grid.length && grid[row + 1][col] === 1) { - queue.push([row + 1, col, minutes]); + queue.push([row + 1, col]); grid[row + 1][col] = 2; freshCount--; } if (row - 1 >= 0 && grid[row - 1][col] === 1) { - queue.push([row - 1, col, minutes]); + queue.push([row - 1, col]); grid[row - 1][col] = 2; freshCount--; } - if (col + 1 < grid[0].length && grid[row][col + 1] === 1) { - queue.push([row, col + 1, minutes]); + queue.push([row, col + 1]); grid[row][col + 1] = 2; freshCount--; } if (col - 1 >= 0 && grid[row][col - 1] === 1) { - queue.push([row, col - 1, minutes]); + queue.push([row, col - 1]); grid[row][col - 1] = 2; freshCount--; } } - // after processing the whole level, increment minutes - // but only if we actually added new rotten oranges to the queue if (queue.length > 0) { minutes++; } } - // TODO: After BFS completes, if any fresh oranges remain, return -1; otherwise return the minutes elapsed - // INVARIANT: freshCount === 0 means all oranges rotted successfully return freshCount > 0 ? -1 : minutes; } From 278ba221abeec3353ee4a806368730a27704f98d Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Tue, 10 Feb 2026 20:36:16 -0500 Subject: [PATCH 5/6] learn: solve Rotting Oranges (#994) via guided TDD --- docs/PROBLEMS.md | 2 + .../0994-rotting-oranges/POST_MORTEM.md | 188 ++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 leetcode/medium/0994-rotting-oranges/POST_MORTEM.md diff --git a/docs/PROBLEMS.md b/docs/PROBLEMS.md index 93e0437..1a66a26 100644 --- a/docs/PROBLEMS.md +++ b/docs/PROBLEMS.md @@ -210,6 +210,7 @@ Complete list of all solved problems, organized by difficulty and topic. - [0881 - Loud and Rich](../leetcode/medium/0881-loud-and-rich) ![Medium](https://img.shields.io/badge/Medium-orange) - [0922 - Possible Bipartition](../leetcode/medium/0922-possible-bipartition) ![Medium](https://img.shields.io/badge/Medium-orange) - [0984 - Most Stones Removed with Same Row or Column](../leetcode/medium/0984-most-stones-removed-with-same-row-or-column) ![Medium](https://img.shields.io/badge/Medium-orange) +- [0994 - Rotting Oranges](../leetcode/medium/0994-rotting-oranges) ![Medium](https://img.shields.io/badge/Medium-orange) - [1100 - Connecting Cities With Minimum Cost](../leetcode/medium/1100-connecting-cities-with-minimum-cost) ![Medium](https://img.shields.io/badge/Medium-orange) - [1101 - Parallel Courses](../leetcode/medium/1101-parallel-courses) ![Medium](https://img.shields.io/badge/Medium-orange) - [1120 - Flower Planting With No Adjacent](../leetcode/medium/1120-flower-planting-with-no-adjacent) ![Medium](https://img.shields.io/badge/Medium-orange) @@ -299,3 +300,4 @@ Complete list of all solved problems, organized by difficulty and topic. - [0210 - Course Schedule II](../leetcode/medium/0210-course-schedule-ii) - Medium - [0269 - Alien Dictionary](../leetcode/hard/0269-alien-dictionary) - Hard - [0329 - Longest Increasing Path in a Matrix](../leetcode/hard/0329-longest-increasing-path-in-a-matrix) - Hard +- [0994 - Rotting Oranges](../leetcode/medium/0994-rotting-oranges) - Medium diff --git a/leetcode/medium/0994-rotting-oranges/POST_MORTEM.md b/leetcode/medium/0994-rotting-oranges/POST_MORTEM.md new file mode 100644 index 0000000..61f3ae5 --- /dev/null +++ b/leetcode/medium/0994-rotting-oranges/POST_MORTEM.md @@ -0,0 +1,188 @@ +# Interview Debrief — Rotting Oranges + +**Date:** 2026-02-10 +**Problem:** [994 - Rotting Oranges](https://leetcode.com/problems/rotting-oranges/) — Medium +**Duration:** ~90 minutes (estimated based on 4 TDD cycles) +**Mode:** Guided TDD (Coach Mode) + +--- + +## Session Overview + +The candidate successfully solved Rotting Oranges using a guided TDD approach in coach mode. They demonstrated solid pattern recognition (correctly identified BFS early in the session) and implemented a clean level-by-level BFS solution after receiving Level 2 hints for the more complex aspects (bounds checking and level tracking). The candidate wrote all implementation code independently, showed good debugging skills when issues arose, and progressively took ownership of test design as the session progressed. Overall performance indicates a solid mid-level engineer with room for growth in translating conceptual understanding to code. + +--- + +## Problem Solving + +Score: 4/5 + +**Strengths:** + +- Correctly identified BFS as the appropriate pattern in the initial pattern checkpoint, demonstrating good algorithmic intuition +- Understood the "shortest path" nature of the problem and why breadth-first traversal guarantees the minimum minutes +- Proposed logical test cases that covered important edge cases (no oranges, only rotten, impossible case) +- Showed good problem decomposition by accepting the incremental TDD approach + +**Areas for Improvement:** + +- Initial pattern checkpoint answer was incomplete regarding state variables — mentioned "track minimum minutes" but missed the need to track freshCount and queue state +- Didn't initially understand the invariant concept; needed clarification on what it means for level-by-level processing to maintain correctness +- Required Level 2 hints to understand the level-tracking pattern (snapshotting `levelSize` before processing) + +**Help Needed:** Moderate — needed Level 2 pattern hints for bounds checking and level-by-level BFS, but applied them correctly once explained + +--- + +## Coding + +Score: 4/5 + +**Strengths:** + +- Wrote clean, readable nested loops for grid traversal (lines 8-16 in final solution) +- Good variable naming throughout (`freshCount`, `levelSize`, `row`, `col`) +- Correctly implemented all four directional checks with proper bounds validation after guidance +- Successfully marked oranges as rotten in the grid (`grid[newRow][newCol] = 2`) to prevent duplicate processing +- Final code is well-structured with clear comments explaining BFS logic + +**Areas for Improvement:** + +- Needed multiple attempts to get bounds checking right — initially checked current `row`/`col` instead of the new positions being accessed (`row + 1`, `col - 1`, etc.) +- Made a typo in cycle 3 (line 26: `queue.push([row + 1, col])` when checking `row - 1`), though this was fixed in subsequent iteration +- Forgot to count fresh oranges initially in cycle 3, only adding the counting loop after cycle 4 test failure + +**Debugging Process:** + +- Systematic debugging when tests failed — responded well to guided questions about what values variables could have +- Quickly identified the freshCount initialization bug in cycle 4 after being asked "what should freshCount count?" +- Fixed the bug independently once the issue was clarified (counting rotten oranges vs fresh oranges) + +--- + +## Verification + +Score: 3/5 + +**Strengths:** + +- Good test case selection — proposed edge cases like "no oranges" and "impossible to rot all" without prompting +- Understood the importance of testing the -1 return case (impossible scenario) +- Accepted the TDD discipline of writing tests first + +**Areas for Improvement:** + +- Didn't proactively trace through examples before coding — would have caught the freshCount initialization issue earlier +- Didn't mention verifying the invariant (that each BFS level represents exactly one minute) during implementation +- Could have been more proactive about considering what state needs to be tracked before writing code + +--- + +## Communication + +Score: 4/5 + +**Strengths:** + +- Asked clarifying questions when confused ("I don't understand what deltaRow and deltaCol are") rather than blindly copying code +- Clearly stated when ready to proceed ("continue") vs when stuck +- Pattern checkpoint response showed good high-level thinking ("BFS because we're looking for shortest path") +- Explained the fix clearly in cycle 4 ("removed freshCount from the if condition for cell being 2, added another if for cell 1") + +**Areas for Improvement:** + +- Pattern checkpoint could have been more detailed regarding state variables and invariants +- Could have articulated _why_ level-by-level processing is needed more explicitly (to ensure each level = 1 minute) +- Silent during most coding — could have verbalized more of the implementation thought process + +--- + +## Complexity Analysis + +Score: 3/5 + +**Strengths:** + +- Understood that BFS is an O(n) traversal pattern conceptually +- Recognized that visiting every cell is necessary for completeness + +**Areas for Improvement:** + +- Did not explicitly state time complexity as O(m × n) where m = rows, n = columns +- Did not mention space complexity (O(m × n) worst case for the queue when all cells are rotten initially) +- Could not explain _why_ the level-by-level approach doesn't change the overall O(m × n) complexity + +--- + +## Pattern Recognition + +- **Pattern Used:** Multi-Source Breadth-First Search (BFS) +- **Key Insight:** The "aha moment" was understanding that BFS processes nodes level-by-level, and each level represents one minute of elapsed time. By snapshotting the queue size before processing, we ensure all oranges at distance D rot before any at distance D+1, guaranteeing the minimum time. +- **Pattern Checkpoint Results:** 1/1 correct on first attempt (identified BFS), but needed follow-up clarification on state variables and invariants +- **Related Problems to Practice:** + - **[286 - Walls and Gates](https://leetcode.com/problems/walls-and-gates/)** — Multi-source BFS from gates to fill distances; reinforces the same "start from all sources" pattern + - **[1091 - Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix/)** — Single-source BFS with 8-directional movement; practices bounds checking and level tracking + - **[542 - 01 Matrix](https://leetcode.com/problems/01-matrix/)** — Multi-source BFS to find nearest 0 for each cell; same pattern, different domain + +--- + +## Session Progression + +The candidate showed steady improvement throughout the session. Cycle 1 established basic grid traversal skills. Cycles 2-3 required significant coaching on BFS mechanics (bounds checking, level tracking), but once the pattern was explained, the candidate implemented it correctly. Cycle 4 demonstrated good debugging ability when catching the freshCount initialization bug independently after guided questioning. + +| Cycle | What Was Tested | Test Ownership Level | Hint Level | Pattern Checkpoint | Notes | +| ----- | ----------------------------------------- | -------------------- | ---------- | ------------------ | ------------------------------------------------------------------- | +| 1 | No oranges at all → return 0 | L1 | 1 | PASS | Needed hints on variable initialization (started at 1 instead of 0) | +| 2 | Only rotten oranges → return 0 | L1 | 0 | N/A | Test passed immediately (existing code handled it) | +| 3 | Basic rotting scenario → return 4 | L2 | 2 | PASS (w/ followup) | Needed L2 hints for bounds checking and level-by-level BFS pattern | +| 4 | Impossible case (unreachable) → return -1 | L2 | 1 | N/A | Debugging cycle — identified freshCount bug after guided questions | + +--- + +## No-Hire Trigger Check + +- **Critical Triggers Observed:** none +- **Recovery Evidence:** none needed +- **Guardrail Applied:** none + +**Trigger Analysis:** + +- **Core invariant explanation:** Candidate understood level-by-level invariant after explanation (no trigger) +- **Level 3 hints for core logic:** Only needed Level 2 hints, not Level 3 (no trigger) +- **Final complexity explanation:** Did not provide detailed complexity analysis, but understood O(n) traversal concept (borderline but not critical) +- **Solution correctness justification:** Could explain why BFS guarantees minimum time after coaching (no trigger) +- **Repeated failing assertions:** Fixed issues within 1-2 attempts after hints (no trigger) +- **Unresolved bugs at end:** All tests passing, no unresolved issues (no trigger) + +--- + +## Overall Assessment + +**Interview Recommendation:** Lean Recommend +**Hiring Decision:** Lean Hire +**Would Move Forward to Next Round:** Yes +**Confidence:** Medium + +**Summary:** + +I would move this candidate forward with a lean hire recommendation. They demonstrated solid algorithmic intuition by correctly identifying BFS as the pattern, and successfully implemented the solution after receiving moderate coaching. The candidate's debugging skills were good — they systematically worked through issues and fixed the freshCount initialization bug independently after guided questioning. However, they required Level 2 hints for bounds checking and level-tracking patterns, which suggests they would benefit from more practice translating conceptual understanding into code. Their communication was generally clear, though they could verbalize their thought process more during implementation. Overall, this is a capable mid-level engineer who would likely succeed with continued mentorship. + +**Strengths to Build On:** + +- Pattern recognition skills — correctly identified BFS early in the session +- Debugging mindset — asked clarifying questions and fixed bugs systematically +- Clean code style with good variable naming and structure + +**Priority Areas for Growth:** + +- Practice translating BFS patterns to code without Level 2 hints (bounds checking, level tracking) +- Articulate complexity analysis more explicitly (state Big O for both time and space) +- Verbalize implementation thought process more during coding (helps catch issues early) + +**Recommended Next Steps:** + +- **Practice similar multi-source BFS problems:** Walls and Gates (#286), 01 Matrix (#542) — build muscle memory for the level-tracking pattern +- **Study the bounds-checking pattern:** Always check the NEW position (`row + 1`, `col - 1`) before accessing it, not the current position +- **Before coding, trace through a small example:** This helps verify state variables and invariants upfront, catching issues like the freshCount initialization bug earlier + +--- From adc6d3bf2772dd16aefd945757f7e261dacf72cb Mon Sep 17 00:00:00 2001 From: Rob Simpson Date: Tue, 10 Feb 2026 20:51:14 -0500 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- leetcode/medium/0994-rotting-oranges/rotting-oranges.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts index f9cf633..cfd4035 100644 --- a/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts +++ b/leetcode/medium/0994-rotting-oranges/rotting-oranges.ts @@ -2,7 +2,7 @@ export function orangesRotting(grid: number[][]): number { let freshCount: number = 0; let minutes = 0; - const queue: number[][] = []; + const queue: [number, number][] = []; // Initialize queue with all initially rotten oranges and count fresh oranges for (let row = 0; row < grid.length; row++) {