#Leetcode

LeetCode MEDIUM 1922 Count Good Numbers Summary

Generated by Codex with GPT-5

Quick facts

Problem gist

The problem asks for the number of length-n digit strings that satisfy two position rules:

  • Digits at even indices can be one of 0, 2, 4, 6, or 8.
  • Digits at odd indices can be one of 2, 3, 5, or 7.

Indices are zero-based, so index 0 is even. The string can start with 0; this is a digit string, not a normal integer representation. Because the answer can be enormous, return it modulo 1_000_000_007.

Continue ...

LeetCode MEDIUM 1143 Longest Common Subsequence Summary

Generated by Codex with GPT-5

Quick facts

Problem gist

Given two strings, the task is to find the length of the longest sequence of characters that appears in both strings in the same relative order.

The characters do not need to be contiguous. For example, "ace" is a subsequence of "abcde" because a, c, and e appear in order, even though there are skipped characters between them.

Continue ...

LeetCode MEDIUM 1094 Car Pooling Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: MEDIUM
  • Problem: Car Pooling
  • Topics: Array, Sorting, Heap (Priority Queue), Simulation, Prefix Sum

What the problem is really asking

A car has a fixed number of seats and only travels east. Each trip is described as [passengers, pickup, dropoff]: the passengers enter at pickup and leave at dropoff.

Continue ...

LeetCode MEDIUM 1011 Capacity To Ship Packages Within D Days Summary

Generated by Codex with GPT-5

Quick facts

Problem gist

There is a line of packages, each with a weight. A ship moves packages in the given order, and each day it can carry packages only until the total loaded weight reaches its capacity. The task is to find the smallest ship capacity that can move every package within days days.

Continue ...

LeetCode MEDIUM 833 Find And Replace in String Summary

Generated by Codex with GPT-5

Quick facts

Problem gist

The input is a base string s and three parallel arrays:

  • indices[i] says where a possible replacement starts.
  • sources[i] says what text must already appear there.
  • targets[i] says what text to write if the source matches.

Every replacement is checked against the original string, not against a partially edited string. That “simultaneous” detail is the core of the problem. If s = "abcd", indices = [0, 2], sources = ["a", "cd"], and targets = ["eee", "ffff"], both checks happen on "abcd", so the answer is "eeebffff".

Continue ...

LeetCode MEDIUM 787 Cheapest Flights Within K Stops Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: MEDIUM
  • Problem: Cheapest Flights Within K Stops
  • Topics: Dynamic Programming, Depth-First Search, Breadth-First Search, Graph Theory, Heap (Priority Queue), Shortest Path

Problem gist

There are n cities, and each directed flight has a departure city, an arrival city, and a price. Given src, dst, and k, return the cheapest price from src to dst using at most k stops. If no such route exists, return -1.

Continue ...

LeetCode MEDIUM 662 Maximum Width of Binary Tree Summary

Generated by Codex with GPT-5

Quick facts

Problem gist

The input is the root of a binary tree. The task is to find the largest width across all levels.

The subtle part is how width is defined. It is not just the number of real nodes on a level. The width runs from the leftmost real node to the rightmost real node on that level, counting the missing null positions between them as if the tree were laid out like a complete binary tree.

Continue ...

LeetCode MEDIUM 658 Find K Closest Elements Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: MEDIUM
  • Problem: Find K Closest Elements
  • Topics: Array, Two Pointers, Binary Search, Sliding Window, Sorting, Heap (Priority Queue)

What the problem is asking

The input is already sorted. Given a target value x, the task is to return the k values that are closest to it, still in sorted order.

Continue ...

LeetCode MEDIUM 444 Sequence Reconstruction Summary

Generated by Codex with GPT-5

Quick facts

What the problem is asking

The input gives a target sequence nums and a list of shorter sequences. Each shorter sequence says, “these numbers must appear in this relative order.”

The task is not just to ask whether nums can be built from those constraints. It asks whether nums is the only shortest sequence that satisfies every constraint. If another sequence of the same shortest length can also satisfy the constraints, the answer is False.

Continue ...

LeetCode MEDIUM 442 Find All Duplicates in an Array Summary

Generated by Codex with GPT-5

Quick facts

Problem gist

The input is an array nums of length n. Every value is in the range 1 through n, and each value appears either once or twice. The task is to return every value that appears twice.

Continue ...