#Leetcode

LeetCode MEDIUM 236 Lowest Common Ancestor of a Binary Tree Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM
Problem: Lowest Common Ancestor of a Binary Tree

Problem gist

Given the root of a binary tree and two existing nodes p and q, return their lowest common ancestor.

An ancestor can be the node itself. That detail matters: if p is above q, then p is the answer. “Lowest” means deepest in the tree, not smallest by value. This is a normal binary tree, so there is no useful ordering rule like there would be in a binary search tree.

Continue ...

LeetCode HARD 127 Word Ladder Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: HARD
  • Problem: Word Ladder
  • Main tags: Breadth-First Search, Hash Table, String, Graph

What the problem is really asking

The input gives a beginWord, an endWord, and a dictionary called wordList.

Each move can change exactly one letter, and every intermediate word must appear in wordList. The task is to return the number of words in the shortest valid transformation sequence from beginWord to endWord. If no such sequence exists, return 0.

Continue ...

LeetCode MEDIUM 380 Insert Delete GetRandom O(1) Summary

Generated by Codex with GPT-5

Quick facts

What the problem is really asking

The task is to design a set-like data structure with three operations:

  • insert(val) adds a value only if it is not already present.
  • remove(val) deletes a value only if it is present.
  • getRandom() returns one currently stored value, with every stored value equally likely.

The important constraint is that all three operations should run in average O(1) time.

Continue ...

LeetCode HARD 224 Basic Calculator Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: HARD
  • Problem: Basic Calculator
  • Main tags: Math, String, Stack, Recursion

What the problem is really asking

The input is a string expression that contains non-negative integers, +, -, parentheses, and spaces. The task is to return the final numeric value without using Python’s built-in expression evaluator.

Continue ...

LeetCode MEDIUM 155 Min Stack Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: MEDIUM
  • Problem: Min Stack
  • Main tags: Stack, Design

What the problem is really asking

The API looks simple: push, pop, top, and getMin.

The real requirement is hidden in getMin: it must return the current minimum in constant time, not by scanning the whole stack.

Continue ...

LeetCode MEDIUM 102 Binary Tree Level Order Traversal Summary

Generated by Codex with GPT-5

Quick facts

What the problem is really asking

The task is to read a binary tree one layer at a time.

Instead of visiting nodes in a depth-first order such as root, left subtree, right subtree, the problem wants the tree grouped by depth:

Continue ...

LeetCode MEDIUM 3453 Separate Squares I Summary

Generated by Codex with GPT-5

Quick facts

What the problem is really asking

This problem looks geometric, but the core idea is much simpler than it first appears.

The task is to place a horizontal line y = cut so that:

Continue ...

LeetCode MEDIUM 518 Coin Change II Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: MEDIUM
  • Problem: Coin Change II
  • Main tags: Array, Dynamic Programming

What the problem is really asking

The input gives a target amount and a list of coin denominations. Each denomination can be used as many times as needed.

The task is to count how many distinct combinations can make the amount exactly. It is not asking for the minimum number of coins, and it is not asking whether the amount is possible at all.

Continue ...

LeetCode MEDIUM 322 Coin Change Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: MEDIUM
  • Problem: Coin Change
  • Main tags: Array, Dynamic Programming, Breadth-First Search

What the problem is really asking

The input gives a set of coin denominations and a target amount. Each coin can be used as many times as needed.

The goal is not to count how many different ways the amount can be formed. The goal is to find the fewest coins needed to reach the exact amount. If the amount cannot be formed exactly, the answer is -1.

Continue ...

LeetCode HARD 239 Sliding Window Maximum Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: HARD
  • Problem: Sliding Window Maximum
  • Main tags: Array, Queue, Sliding Window, Heap (Priority Queue), Monotonic Queue

What the problem is really asking

The input gives an array and a window size k. Imagine placing a length-k window over the first k elements, recording the maximum value inside that window, then moving the window one step to the right and repeating until the end.

Continue ...