#Leetcode

LeetCode MEDIUM 503 Next Greater Element II Summary

Generated by Codex with GPT-5

Quick facts

What the problem is really asking

The input is an integer array nums, but the array is circular. After the last index, the scan wraps back to index 0.

For each index i, the task is to find the first value that is strictly greater than nums[i] when walking forward through this circular array. If no greater value appears before returning to i, the answer for that index is -1.

Continue ...

LeetCode MEDIUM 777 Swap Adjacent in LR String Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM
Problem: Swap Adjacent in LR String

Problem gist

The string contains three characters: L, R, and X. Think of X as an empty space. The only allowed moves are:

  1. XL -> LX, which moves an L one position to the left.
  2. RX -> XR, which moves an R one position to the right.

Given start and end, the task is to decide whether start can become end after any number of those moves.

Continue ...

LeetCode MEDIUM 122 Best Time to Buy and Sell Stock II Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM
Problem: Best Time to Buy and Sell Stock II

Problem gist

The input is a list of stock prices where prices[i] is the price on day i. The goal is to make as much profit as possible by buying and selling any number of times.

Continue ...

LeetCode MEDIUM 139 Word Break Summary

Generated by Codex with GPT-5

Quick facts

  • Difficulty: MEDIUM
  • Problem: Word Break
  • Main tags: String, Hash Table, Dynamic Programming, Trie

What the problem is really asking

The input is a string s and a dictionary of valid words. The task is to decide whether s can be split into one or more dictionary words. Words may be reused, so the question is not about consuming the dictionary; it is about whether every character in the string can be covered by valid dictionary chunks.

Continue ...

LeetCode MEDIUM 799 Champagne Tower Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM
Problem: Champagne Tower

Problem gist

A tower of glasses is stacked in rows. Row 0 has one glass, row 1 has two glasses, and so on. Each glass can hold exactly one cup. If a glass receives more than one cup, the extra amount spills equally into the two glasses directly below it.

Continue ...

LeetCode MEDIUM 739 Daily Temperatures Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM

Problem: Daily Temperatures

Problem gist

Given a list of daily temperatures, return a new list where each position says how many days must pass before a strictly warmer temperature appears. If no warmer future day exists, that position should be 0.

For example, if the temperatures are:

Continue ...

LeetCode MEDIUM 743 Network Delay Time Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM
Problem: Network Delay Time

Problem gist

The input describes a directed, weighted graph. Each edge u -> v has a travel time w, and a signal starts at node k. The task is to return how long it takes until every node receives the signal. If some node can never receive it, return -1.

Continue ...

LeetCode MEDIUM 249 Group Shifted Strings Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM

Problem: Group Shifted Strings

Problem gist

Each string can be shifted forward through the alphabet, wrapping from z to a. For example, shifting "abc" once gives "bcd", and shifting "az" once gives "ba". The task is to group strings that can become each other by applying the same shift amount to every character.

Continue ...

LeetCode MEDIUM 528 Random Pick with Weight Summary

Generated by Codex with GPT-5

Quick facts

What the problem is really asking

The class receives an array of positive weights, where w[i] describes how likely index i should be picked. Calling pickIndex() should return one index at random, but not uniformly. Index i should be returned with probability:

Continue ...

LeetCode MEDIUM 151 Reverse Words in a String Summary

Generated by Codex with GPT-5

Difficulty: MEDIUM
Problem: Reverse Words in a String

Problem gist

The input is a string that contains words separated by spaces. The output should contain the same words in reverse order, with exactly one space between adjacent words and no leading or trailing spaces.

The important detail is that the function is not reversing letters inside each word. It is reversing the sequence of words. For example, the words ["the", "sky", "is", "blue"] become ["blue", "is", "sky", "the"].

Continue ...