offcode 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -2
- package/data/index.json +1 -0
- package/data/problems/01-matrix.json +1 -0
- package/data/problems/1-bit-and-2-bit-characters.json +1 -0
- package/data/problems/132-pattern.json +1 -0
- package/data/problems/2-keys-keyboard.json +1 -0
- package/data/problems/24-game.json +1 -0
- package/data/problems/3sum-closest.json +1 -0
- package/data/problems/3sum-smaller.json +1 -0
- package/data/problems/3sum-with-multiplicity.json +1 -0
- package/data/problems/3sum.json +1 -0
- package/data/problems/4-keys-keyboard.json +1 -0
- package/data/problems/4sum-ii.json +1 -0
- package/data/problems/4sum.json +1 -0
- package/data/problems/accounts-merge.json +1 -0
- package/data/problems/add-binary.json +1 -0
- package/data/problems/add-bold-tag-in-string.json +1 -0
- package/data/problems/add-digits.json +1 -0
- package/data/problems/add-one-row-to-tree.json +1 -0
- package/data/problems/add-strings.json +1 -0
- package/data/problems/add-to-array-form-of-integer.json +1 -0
- package/data/problems/add-two-numbers-ii.json +1 -0
- package/data/problems/add-two-numbers.json +1 -0
- package/data/problems/additive-number.json +1 -0
- package/data/problems/advantage-shuffle.json +1 -0
- package/data/problems/alien-dictionary.json +1 -0
- package/data/problems/all-nodes-distance-k-in-binary-tree.json +1 -0
- package/data/problems/all-oone-data-structure.json +1 -0
- package/data/problems/all-paths-from-source-to-target.json +1 -0
- package/data/problems/all-possible-full-binary-trees.json +1 -0
- package/data/problems/ambiguous-coordinates.json +1 -0
- package/data/problems/android-unlock-patterns.json +1 -0
- package/data/problems/arithmetic-slices-ii-subsequence.json +1 -0
- package/data/problems/arithmetic-slices.json +1 -0
- package/data/problems/arranging-coins.json +1 -0
- package/data/problems/array-nesting.json +1 -0
- package/data/problems/array-of-doubled-pairs.json +1 -0
- package/data/problems/array-partition.json +1 -0
- package/data/problems/assign-cookies.json +1 -0
- package/data/problems/asteroid-collision.json +1 -0
- package/data/problems/available-captures-for-rook.json +1 -0
- package/data/problems/average-of-levels-in-binary-tree.json +1 -0
- package/data/problems/backspace-string-compare.json +1 -0
- package/data/problems/bag-of-tokens.json +1 -0
- package/data/problems/balanced-binary-tree.json +1 -0
- package/data/problems/base-7.json +1 -0
- package/data/problems/baseball-game.json +1 -0
- package/data/problems/basic-absolute-value.json +1 -0
- package/data/problems/basic-array-max.json +1 -0
- package/data/problems/basic-array-min.json +1 -0
- package/data/problems/basic-array-sum-rec.json +1 -0
- package/data/problems/basic-array-sum.json +1 -0
- package/data/problems/basic-average-floor.json +1 -0
- package/data/problems/basic-bubble-sort.json +1 -0
- package/data/problems/basic-calculator-ii.json +1 -0
- package/data/problems/basic-calculator-iii.json +1 -0
- package/data/problems/basic-calculator-iv.json +1 -0
- package/data/problems/basic-calculator.json +1 -0
- package/data/problems/basic-collatz-steps.json +1 -0
- package/data/problems/basic-contains-value.json +1 -0
- package/data/problems/basic-count-above.json +1 -0
- package/data/problems/basic-count-char.json +1 -0
- package/data/problems/basic-count-digits.json +1 -0
- package/data/problems/basic-count-evens.json +1 -0
- package/data/problems/basic-count-pairs.json +1 -0
- package/data/problems/basic-count-vowels.json +1 -0
- package/data/problems/basic-count-words.json +1 -0
- package/data/problems/basic-countdown.json +1 -0
- package/data/problems/basic-double-array.json +1 -0
- package/data/problems/basic-factorial-rec.json +1 -0
- package/data/problems/basic-factorial.json +1 -0
- package/data/problems/basic-fibonacci.json +1 -0
- package/data/problems/basic-find-index.json +1 -0
- package/data/problems/basic-gcd.json +1 -0
- package/data/problems/basic-grade-letter.json +1 -0
- package/data/problems/basic-has-duplicate.json +1 -0
- package/data/problems/basic-is-even.json +1 -0
- package/data/problems/basic-is-leap-year.json +1 -0
- package/data/problems/basic-is-sorted.json +1 -0
- package/data/problems/basic-max-frequency.json +1 -0
- package/data/problems/basic-max-of-three.json +1 -0
- package/data/problems/basic-max-of-two.json +1 -0
- package/data/problems/basic-palindrome-text.json +1 -0
- package/data/problems/basic-power-rec.json +1 -0
- package/data/problems/basic-power.json +1 -0
- package/data/problems/basic-repeat-string.json +1 -0
- package/data/problems/basic-reverse-array.json +1 -0
- package/data/problems/basic-reverse-number.json +1 -0
- package/data/problems/basic-reverse-text-rec.json +1 -0
- package/data/problems/basic-reverse-text.json +1 -0
- package/data/problems/basic-second-largest.json +1 -0
- package/data/problems/basic-sort-two.json +1 -0
- package/data/problems/basic-staircase.json +1 -0
- package/data/problems/basic-string-length.json +1 -0
- package/data/problems/basic-sum-1-to-n.json +1 -0
- package/data/problems/basic-sum-digits-rec.json +1 -0
- package/data/problems/basic-sum-multiples.json +1 -0
- package/data/problems/basic-sum-of-digits.json +1 -0
- package/data/problems/basic-temperature-advice.json +1 -0
- package/data/problems/basic-to-upper.json +1 -0
- package/data/problems/basic-triangle-sum.json +1 -0
- package/data/problems/battleships-in-a-board.json +1 -0
- package/data/problems/beautiful-arrangement-ii.json +1 -0
- package/data/problems/beautiful-arrangement.json +1 -0
- package/data/problems/beautiful-array.json +1 -0
- package/data/problems/best-meeting-point.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-ii.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-iii.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-iv.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-with-cooldown.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-with-transaction-fee.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock.json +1 -0
- package/data/problems/binary-gap.json +1 -0
- package/data/problems/binary-number-with-alternating-bits.json +1 -0
- package/data/problems/binary-search-tree-iterator.json +1 -0
- package/data/problems/binary-search.json +1 -0
- package/data/problems/binary-subarrays-with-sum.json +1 -0
- package/data/problems/binary-tree-cameras.json +1 -0
- package/data/problems/binary-tree-inorder-traversal.json +1 -0
- package/data/problems/binary-tree-level-order-traversal-ii.json +1 -0
- package/data/problems/binary-tree-level-order-traversal.json +1 -0
- package/data/problems/binary-tree-longest-consecutive-sequence-ii.json +1 -0
- package/data/problems/binary-tree-longest-consecutive-sequence.json +1 -0
- package/data/problems/binary-tree-maximum-path-sum.json +1 -0
- package/data/problems/binary-tree-paths.json +1 -0
- package/data/problems/binary-tree-postorder-traversal.json +1 -0
- package/data/problems/binary-tree-preorder-traversal.json +1 -0
- package/data/problems/binary-tree-pruning.json +1 -0
- package/data/problems/binary-tree-right-side-view.json +1 -0
- package/data/problems/binary-tree-tilt.json +1 -0
- package/data/problems/binary-tree-upside-down.json +1 -0
- package/data/problems/binary-tree-vertical-order-traversal.json +1 -0
- package/data/problems/binary-tree-zigzag-level-order-traversal.json +1 -0
- package/data/problems/binary-trees-with-factors.json +1 -0
- package/data/problems/binary-watch.json +1 -0
- package/data/problems/bitwise-and-of-numbers-range.json +1 -0
- package/data/problems/bitwise-ors-of-subarrays.json +1 -0
- package/data/problems/boats-to-save-people.json +1 -0
- package/data/problems/bold-words-in-string.json +1 -0
- package/data/problems/bomb-enemy.json +1 -0
- package/data/problems/boundary-of-binary-tree.json +1 -0
- package/data/problems/brick-wall.json +1 -0
- package/data/problems/bricks-falling-when-hit.json +1 -0
- package/data/problems/broken-calculator.json +1 -0
- package/data/problems/buddy-strings.json +1 -0
- package/data/problems/build-a-matrix-with-conditions.json +1 -0
- package/data/problems/bulb-switcher-ii.json +1 -0
- package/data/problems/bulb-switcher.json +1 -0
- package/data/problems/bulls-and-cows.json +1 -0
- package/data/problems/burst-balloons.json +1 -0
- package/data/problems/bus-routes.json +1 -0
- package/data/problems/can-i-win.json +1 -0
- package/data/problems/can-place-flowers.json +1 -0
- package/data/problems/candy-crush.json +1 -0
- package/data/problems/candy.json +1 -0
- package/data/problems/capacity-to-ship-packages-within-d-days.json +1 -0
- package/data/problems/car-fleet.json +1 -0
- package/data/problems/car-pooling.json +1 -0
- package/data/problems/card-flipping-game.json +1 -0
- package/data/problems/cat-and-mouse.json +1 -0
- package/data/problems/chalkboard-xor-game.json +1 -0
- package/data/problems/champagne-tower.json +1 -0
- package/data/problems/cheapest-flights-within-k-stops.json +1 -0
- package/data/problems/check-completeness-of-a-binary-tree.json +1 -0
- package/data/problems/cherry-pickup.json +1 -0
- package/data/problems/circular-array-loop.json +1 -0
- package/data/problems/climbing-stairs.json +1 -0
- package/data/problems/clone-graph.json +1 -0
- package/data/problems/closest-binary-search-tree-value-ii.json +1 -0
- package/data/problems/closest-binary-search-tree-value.json +1 -0
- package/data/problems/closest-leaf-in-a-binary-tree.json +1 -0
- package/data/problems/coin-change-ii.json +1 -0
- package/data/problems/coin-change.json +1 -0
- package/data/problems/coin-path.json +1 -0
- package/data/problems/combination-sum-ii.json +1 -0
- package/data/problems/combination-sum-iii.json +1 -0
- package/data/problems/combination-sum-iv.json +1 -0
- package/data/problems/combination-sum.json +1 -0
- package/data/problems/combinations.json +1 -0
- package/data/problems/compare-version-numbers.json +1 -0
- package/data/problems/complete-binary-tree-inserter.json +1 -0
- package/data/problems/complex-number-multiplication.json +1 -0
- package/data/problems/concatenated-words.json +1 -0
- package/data/problems/concatenation-of-array.json +1 -0
- package/data/problems/consecutive-numbers-sum.json +1 -0
- package/data/problems/construct-binary-tree-from-inorder-and-postorder-traversal.json +1 -0
- package/data/problems/construct-binary-tree-from-preorder-and-inorder-traversal.json +1 -0
- package/data/problems/construct-binary-tree-from-preorder-and-postorder-traversal.json +1 -0
- package/data/problems/construct-binary-tree-from-string.json +1 -0
- package/data/problems/construct-quad-tree.json +1 -0
- package/data/problems/construct-string-from-binary-tree.json +1 -0
- package/data/problems/construct-the-rectangle.json +1 -0
- package/data/problems/contain-virus.json +1 -0
- package/data/problems/container-with-most-water.json +1 -0
- package/data/problems/contains-duplicate-ii.json +1 -0
- package/data/problems/contains-duplicate-iii.json +1 -0
- package/data/problems/contains-duplicate.json +1 -0
- package/data/problems/contiguous-array.json +1 -0
- package/data/problems/continuous-subarray-sum.json +1 -0
- package/data/problems/convert-a-number-to-hexadecimal.json +1 -0
- package/data/problems/convert-binary-search-tree-to-sorted-doubly-linked-list.json +1 -0
- package/data/problems/convert-bst-to-greater-tree.json +1 -0
- package/data/problems/convert-sorted-array-to-binary-search-tree.json +1 -0
- package/data/problems/convert-sorted-list-to-binary-search-tree.json +1 -0
- package/data/problems/convex-polygon.json +1 -0
- package/data/problems/copy-list-with-random-pointer.json +1 -0
- package/data/problems/count-and-say.json +1 -0
- package/data/problems/count-binary-substrings.json +1 -0
- package/data/problems/count-complete-tree-nodes.json +1 -0
- package/data/problems/count-different-palindromic-subsequences.json +1 -0
- package/data/problems/count-good-nodes-in-binary-tree.json +1 -0
- package/data/problems/count-numbers-with-unique-digits.json +1 -0
- package/data/problems/count-of-range-sum.json +1 -0
- package/data/problems/count-of-smaller-numbers-after-self.json +1 -0
- package/data/problems/count-primes.json +1 -0
- package/data/problems/count-the-repetitions.json +1 -0
- package/data/problems/count-unique-characters-of-all-substrings-of-a-given-string.json +1 -0
- package/data/problems/count-univalue-subtrees.json +1 -0
- package/data/problems/counting-bits.json +1 -0
- package/data/problems/couples-holding-hands.json +1 -0
- package/data/problems/course-schedule-ii.json +1 -0
- package/data/problems/course-schedule-iii.json +1 -0
- package/data/problems/course-schedule-iv.json +1 -0
- package/data/problems/course-schedule.json +1 -0
- package/data/problems/cousins-in-binary-tree.json +1 -0
- package/data/problems/cracking-the-safe.json +1 -0
- package/data/problems/create-maximum-number.json +1 -0
- package/data/problems/custom-sort-string.json +1 -0
- package/data/problems/cut-off-trees-for-golf-event.json +1 -0
- package/data/problems/daily-temperatures.json +1 -0
- package/data/problems/data-stream-as-disjoint-intervals.json +1 -0
- package/data/problems/decode-string.json +1 -0
- package/data/problems/decode-ways-ii.json +1 -0
- package/data/problems/decode-ways.json +1 -0
- package/data/problems/decoded-string-at-index.json +1 -0
- package/data/problems/degree-of-an-array.json +1 -0
- package/data/problems/delete-and-earn.json +1 -0
- package/data/problems/delete-columns-to-make-sorted-ii.json +1 -0
- package/data/problems/delete-columns-to-make-sorted-iii.json +1 -0
- package/data/problems/delete-columns-to-make-sorted.json +1 -0
- package/data/problems/delete-leaves-with-a-given-value.json +1 -0
- package/data/problems/delete-node-in-a-bst.json +1 -0
- package/data/problems/delete-node-in-a-linked-list.json +1 -0
- package/data/problems/delete-operation-for-two-strings.json +1 -0
- package/data/problems/design-add-and-search-words-data-structure.json +1 -0
- package/data/problems/design-circular-deque.json +1 -0
- package/data/problems/design-circular-queue.json +1 -0
- package/data/problems/design-compressed-string-iterator.json +1 -0
- package/data/problems/design-excel-sum-formula.json +1 -0
- package/data/problems/design-hashmap.json +1 -0
- package/data/problems/design-hashset.json +1 -0
- package/data/problems/design-hit-counter.json +1 -0
- package/data/problems/design-in-memory-file-system.json +1 -0
- package/data/problems/design-linked-list.json +1 -0
- package/data/problems/design-log-storage-system.json +1 -0
- package/data/problems/design-phone-directory.json +1 -0
- package/data/problems/design-search-autocomplete-system.json +1 -0
- package/data/problems/design-snake-game.json +1 -0
- package/data/problems/design-tic-tac-toe.json +1 -0
- package/data/problems/design-twitter.json +1 -0
- package/data/problems/detect-capital.json +1 -0
- package/data/problems/detect-squares.json +1 -0
- package/data/problems/di-string-match.json +1 -0
- package/data/problems/diagonal-traverse.json +1 -0
- package/data/problems/diameter-of-binary-tree.json +1 -0
- package/data/problems/different-ways-to-add-parentheses.json +1 -0
- package/data/problems/distinct-subsequences-ii.json +1 -0
- package/data/problems/distinct-subsequences.json +1 -0
- package/data/problems/distribute-candies.json +1 -0
- package/data/problems/distribute-coins-in-binary-tree.json +1 -0
- package/data/problems/divide-two-integers.json +1 -0
- package/data/problems/domino-and-tromino-tiling.json +1 -0
- package/data/problems/dota2-senate.json +1 -0
- package/data/problems/dungeon-game.json +1 -0
- package/data/problems/edit-distance.json +1 -0
- package/data/problems/elimination-game.json +1 -0
- package/data/problems/employee-free-time.json +1 -0
- package/data/problems/employee-importance.json +1 -0
- package/data/problems/encode-and-decode-strings.json +1 -0
- package/data/problems/encode-and-decode-tinyurl.json +1 -0
- package/data/problems/encode-n-ary-tree-to-binary-tree.json +1 -0
- package/data/problems/encode-string-with-shortest-length.json +1 -0
- package/data/problems/equal-rational-numbers.json +1 -0
- package/data/problems/equal-tree-partition.json +1 -0
- package/data/problems/erect-the-fence.json +1 -0
- package/data/problems/escape-the-ghosts.json +1 -0
- package/data/problems/evaluate-division.json +1 -0
- package/data/problems/evaluate-reverse-polish-notation.json +1 -0
- package/data/problems/exam-room.json +1 -0
- package/data/problems/excel-sheet-column-number.json +1 -0
- package/data/problems/excel-sheet-column-title.json +1 -0
- package/data/problems/exclusive-time-of-functions.json +1 -0
- package/data/problems/expression-add-operators.json +1 -0
- package/data/problems/expressive-words.json +1 -0
- package/data/problems/extra-characters-in-a-string.json +1 -0
- package/data/problems/factor-combinations.json +1 -0
- package/data/problems/factorial-trailing-zeroes.json +1 -0
- package/data/problems/fair-candy-swap.json +1 -0
- package/data/problems/falling-squares.json +1 -0
- package/data/problems/fibonacci-number.json +1 -0
- package/data/problems/find-all-anagrams-in-a-string.json +1 -0
- package/data/problems/find-all-duplicates-in-an-array.json +1 -0
- package/data/problems/find-all-numbers-disappeared-in-an-array.json +1 -0
- package/data/problems/find-anagram-mappings.json +1 -0
- package/data/problems/find-and-replace-in-string.json +1 -0
- package/data/problems/find-and-replace-pattern.json +1 -0
- package/data/problems/find-bottom-left-tree-value.json +1 -0
- package/data/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.json +1 -0
- package/data/problems/find-duplicate-file-in-system.json +1 -0
- package/data/problems/find-duplicate-subtrees.json +1 -0
- package/data/problems/find-eventual-safe-states.json +1 -0
- package/data/problems/find-first-and-last-position-of-element-in-sorted-array.json +1 -0
- package/data/problems/find-in-mountain-array.json +1 -0
- package/data/problems/find-k-closest-elements.json +1 -0
- package/data/problems/find-k-pairs-with-smallest-sums.json +1 -0
- package/data/problems/find-k-th-smallest-pair-distance.json +1 -0
- package/data/problems/find-largest-value-in-each-tree-row.json +1 -0
- package/data/problems/find-leaves-of-binary-tree.json +1 -0
- package/data/problems/find-median-from-data-stream.json +1 -0
- package/data/problems/find-minimum-in-rotated-sorted-array-ii.json +1 -0
- package/data/problems/find-minimum-in-rotated-sorted-array.json +1 -0
- package/data/problems/find-mode-in-binary-search-tree.json +1 -0
- package/data/problems/find-peak-element.json +1 -0
- package/data/problems/find-permutation.json +1 -0
- package/data/problems/find-pivot-index.json +1 -0
- package/data/problems/find-right-interval.json +1 -0
- package/data/problems/find-smallest-letter-greater-than-target.json +1 -0
- package/data/problems/find-the-celebrity.json +1 -0
- package/data/problems/find-the-closest-palindrome.json +1 -0
- package/data/problems/find-the-derangement-of-an-array.json +1 -0
- package/data/problems/find-the-difference.json +1 -0
- package/data/problems/find-the-duplicate-number.json +1 -0
- package/data/problems/find-the-index-of-the-first-occurrence-in-a-string.json +1 -0
- package/data/problems/find-the-shortest-superstring.json +1 -0
- package/data/problems/find-the-town-judge.json +1 -0
- package/data/problems/first-bad-version.json +1 -0
- package/data/problems/first-missing-positive.json +1 -0
- package/data/problems/first-unique-character-in-a-string.json +1 -0
- package/data/problems/fizz-buzz.json +1 -0
- package/data/problems/flatten-2d-vector.json +1 -0
- package/data/problems/flatten-a-multilevel-doubly-linked-list.json +1 -0
- package/data/problems/flatten-binary-tree-to-linked-list.json +1 -0
- package/data/problems/flatten-nested-list-iterator.json +1 -0
- package/data/problems/flip-binary-tree-to-match-preorder-traversal.json +1 -0
- package/data/problems/flip-equivalent-binary-trees.json +1 -0
- package/data/problems/flip-game-ii.json +1 -0
- package/data/problems/flip-game.json +1 -0
- package/data/problems/flip-string-to-monotone-increasing.json +1 -0
- package/data/problems/flipping-an-image.json +1 -0
- package/data/problems/flood-fill.json +1 -0
- package/data/problems/fraction-addition-and-subtraction.json +1 -0
- package/data/problems/fraction-to-recurring-decimal.json +1 -0
- package/data/problems/freedom-trail.json +1 -0
- package/data/problems/friends-of-appropriate-ages.json +1 -0
- package/data/problems/frog-jump.json +1 -0
- package/data/problems/fruit-into-baskets.json +1 -0
- package/data/problems/game-of-life.json +1 -0
- package/data/problems/gas-station.json +1 -0
- package/data/problems/generalized-abbreviation.json +1 -0
- package/data/problems/generate-parentheses.json +1 -0
- package/data/problems/generate-random-point-in-a-circle.json +1 -0
- package/data/problems/global-and-local-inversions.json +1 -0
- package/data/problems/goat-latin.json +1 -0
- package/data/problems/graph-valid-tree.json +1 -0
- package/data/problems/gray-code.json +1 -0
- package/data/problems/greatest-common-divisor-of-strings.json +1 -0
- package/data/problems/greatest-common-divisor-traversal.json +1 -0
- package/data/problems/group-anagrams.json +1 -0
- package/data/problems/group-shifted-strings.json +1 -0
- package/data/problems/groups-of-special-equivalent-strings.json +1 -0
- package/data/problems/guess-number-higher-or-lower-ii.json +1 -0
- package/data/problems/guess-number-higher-or-lower.json +1 -0
- package/data/problems/guess-the-word.json +1 -0
- package/data/problems/h-index-ii.json +1 -0
- package/data/problems/h-index.json +1 -0
- package/data/problems/hamming-distance.json +1 -0
- package/data/problems/hand-of-straights.json +1 -0
- package/data/problems/happy-number.json +1 -0
- package/data/problems/heaters.json +1 -0
- package/data/problems/house-robber-ii.json +1 -0
- package/data/problems/house-robber-iii.json +1 -0
- package/data/problems/house-robber.json +1 -0
- package/data/problems/image-overlap.json +1 -0
- package/data/problems/image-smoother.json +1 -0
- package/data/problems/implement-magic-dictionary.json +1 -0
- package/data/problems/implement-queue-using-stacks.json +1 -0
- package/data/problems/implement-rand10-using-rand7.json +1 -0
- package/data/problems/implement-stack-using-queues.json +1 -0
- package/data/problems/implement-trie-prefix-tree.json +1 -0
- package/data/problems/increasing-order-search-tree.json +1 -0
- package/data/problems/increasing-triplet-subsequence.json +1 -0
- package/data/problems/inorder-successor-in-bst-ii.json +1 -0
- package/data/problems/inorder-successor-in-bst.json +1 -0
- package/data/problems/insert-delete-getrandom-o1-duplicates-allowed.json +1 -0
- package/data/problems/insert-delete-getrandom-o1.json +1 -0
- package/data/problems/insert-greatest-common-divisors-in-linked-list.json +1 -0
- package/data/problems/insert-interval.json +1 -0
- package/data/problems/insert-into-a-binary-search-tree.json +1 -0
- package/data/problems/insert-into-a-sorted-circular-linked-list.json +1 -0
- package/data/problems/insertion-sort-list.json +1 -0
- package/data/problems/integer-break.json +1 -0
- package/data/problems/integer-replacement.json +1 -0
- package/data/problems/integer-to-english-words.json +1 -0
- package/data/problems/integer-to-roman.json +1 -0
- package/data/problems/interleaving-string.json +1 -0
- package/data/problems/intersection-of-two-arrays-ii.json +1 -0
- package/data/problems/intersection-of-two-arrays.json +1 -0
- package/data/problems/intersection-of-two-linked-lists.json +1 -0
- package/data/problems/interval-list-intersections.json +1 -0
- package/data/problems/invert-binary-tree.json +1 -0
- package/data/problems/ip-to-cidr.json +1 -0
- package/data/problems/ipo.json +1 -0
- package/data/problems/is-graph-bipartite.json +1 -0
- package/data/problems/is-subsequence.json +1 -0
- package/data/problems/island-perimeter.json +1 -0
- package/data/problems/isomorphic-strings.json +1 -0
- package/data/problems/jewels-and-stones.json +1 -0
- package/data/problems/jump-game-ii.json +1 -0
- package/data/problems/jump-game-vii.json +1 -0
- package/data/problems/jump-game.json +1 -0
- package/data/problems/k-closest-points-to-origin.json +1 -0
- package/data/problems/k-diff-pairs-in-an-array.json +1 -0
- package/data/problems/k-empty-slots.json +1 -0
- package/data/problems/k-inverse-pairs-array.json +1 -0
- package/data/problems/k-similar-strings.json +1 -0
- package/data/problems/k-th-smallest-in-lexicographical-order.json +1 -0
- package/data/problems/k-th-smallest-prime-fraction.json +1 -0
- package/data/problems/k-th-symbol-in-grammar.json +1 -0
- package/data/problems/keyboard-row.json +1 -0
- package/data/problems/keys-and-rooms.json +1 -0
- package/data/problems/kill-process.json +1 -0
- package/data/problems/knight-dialer.json +1 -0
- package/data/problems/knight-probability-in-chessboard.json +1 -0
- package/data/problems/koko-eating-bananas.json +1 -0
- package/data/problems/kth-largest-element-in-a-stream.json +1 -0
- package/data/problems/kth-largest-element-in-an-array.json +1 -0
- package/data/problems/kth-smallest-element-in-a-bst.json +1 -0
- package/data/problems/kth-smallest-element-in-a-sorted-matrix.json +1 -0
- package/data/problems/kth-smallest-number-in-multiplication-table.json +1 -0
- package/data/problems/largest-bst-subtree.json +1 -0
- package/data/problems/largest-component-size-by-common-factor.json +1 -0
- package/data/problems/largest-divisible-subset.json +1 -0
- package/data/problems/largest-number-at-least-twice-of-others.json +1 -0
- package/data/problems/largest-number.json +1 -0
- package/data/problems/largest-palindrome-product.json +1 -0
- package/data/problems/largest-perimeter-triangle.json +1 -0
- package/data/problems/largest-plus-sign.json +1 -0
- package/data/problems/largest-rectangle-in-histogram.json +1 -0
- package/data/problems/largest-sum-of-averages.json +1 -0
- package/data/problems/largest-time-for-given-digits.json +1 -0
- package/data/problems/largest-triangle-area.json +1 -0
- package/data/problems/last-stone-weight-ii.json +1 -0
- package/data/problems/last-stone-weight.json +1 -0
- package/data/problems/leaf-similar-trees.json +1 -0
- package/data/problems/least-operators-to-express-number.json +1 -0
- package/data/problems/lemonade-change.json +1 -0
- package/data/problems/length-of-last-word.json +1 -0
- package/data/problems/length-of-longest-fibonacci-subsequence.json +1 -0
- package/data/problems/letter-case-permutation.json +1 -0
- package/data/problems/letter-combinations-of-a-phone-number.json +1 -0
- package/data/problems/lexicographical-numbers.json +1 -0
- package/data/problems/lfu-cache.json +1 -0
- package/data/problems/license-key-formatting.json +1 -0
- package/data/problems/line-reflection.json +1 -0
- package/data/problems/linked-list-components.json +1 -0
- package/data/problems/linked-list-cycle-ii.json +1 -0
- package/data/problems/linked-list-cycle.json +1 -0
- package/data/problems/linked-list-random-node.json +1 -0
- package/data/problems/logger-rate-limiter.json +1 -0
- package/data/problems/logical-or-of-two-binary-grids-represented-as-quad-trees.json +1 -0
- package/data/problems/lonely-pixel-i.json +1 -0
- package/data/problems/lonely-pixel-ii.json +1 -0
- package/data/problems/long-pressed-name.json +1 -0
- package/data/problems/longest-absolute-file-path.json +1 -0
- package/data/problems/longest-common-prefix.json +1 -0
- package/data/problems/longest-common-subsequence.json +1 -0
- package/data/problems/longest-consecutive-sequence.json +1 -0
- package/data/problems/longest-continuous-increasing-subsequence.json +1 -0
- package/data/problems/longest-happy-string.json +1 -0
- package/data/problems/longest-harmonious-subsequence.json +1 -0
- package/data/problems/longest-increasing-path-in-a-matrix.json +1 -0
- package/data/problems/longest-increasing-subsequence.json +1 -0
- package/data/problems/longest-line-of-consecutive-one-in-matrix.json +1 -0
- package/data/problems/longest-mountain-in-array.json +1 -0
- package/data/problems/longest-palindrome.json +1 -0
- package/data/problems/longest-palindromic-subsequence.json +1 -0
- package/data/problems/longest-palindromic-substring.json +1 -0
- package/data/problems/longest-repeating-character-replacement.json +1 -0
- package/data/problems/longest-substring-with-at-least-k-repeating-characters.json +1 -0
- package/data/problems/longest-substring-with-at-most-k-distinct-characters.json +1 -0
- package/data/problems/longest-substring-with-at-most-two-distinct-characters.json +1 -0
- package/data/problems/longest-substring-without-repeating-characters.json +1 -0
- package/data/problems/longest-turbulent-subarray.json +1 -0
- package/data/problems/longest-uncommon-subsequence-i.json +1 -0
- package/data/problems/longest-uncommon-subsequence-ii.json +1 -0
- package/data/problems/longest-univalue-path.json +1 -0
- package/data/problems/longest-valid-parentheses.json +1 -0
- package/data/problems/longest-word-in-dictionary-through-deleting.json +1 -0
- package/data/problems/longest-word-in-dictionary.json +1 -0
- package/data/problems/loud-and-rich.json +1 -0
- package/data/problems/lowest-common-ancestor-of-a-binary-search-tree.json +1 -0
- package/data/problems/lowest-common-ancestor-of-a-binary-tree.json +1 -0
- package/data/problems/lru-cache.json +1 -0
- package/data/problems/magic-squares-in-grid.json +1 -0
- package/data/problems/magical-string.json +1 -0
- package/data/problems/majority-element-ii.json +1 -0
- package/data/problems/majority-element.json +1 -0
- package/data/problems/making-a-large-island.json +1 -0
- package/data/problems/map-sum-pairs.json +1 -0
- package/data/problems/masking-personal-information.json +1 -0
- package/data/problems/matchsticks-to-square.json +1 -0
- package/data/problems/max-area-of-island.json +1 -0
- package/data/problems/max-chunks-to-make-sorted-ii.json +1 -0
- package/data/problems/max-chunks-to-make-sorted.json +1 -0
- package/data/problems/max-consecutive-ones-ii.json +1 -0
- package/data/problems/max-consecutive-ones.json +1 -0
- package/data/problems/max-increase-to-keep-city-skyline.json +1 -0
- package/data/problems/max-points-on-a-line.json +1 -0
- package/data/problems/max-stack.json +1 -0
- package/data/problems/max-sum-of-rectangle-no-larger-than-k.json +1 -0
- package/data/problems/maximal-rectangle.json +1 -0
- package/data/problems/maximal-square.json +1 -0
- package/data/problems/maximize-distance-to-closest-person.json +1 -0
- package/data/problems/maximum-average-subarray-i.json +1 -0
- package/data/problems/maximum-average-subarray-ii.json +1 -0
- package/data/problems/maximum-binary-tree-ii.json +1 -0
- package/data/problems/maximum-binary-tree.json +1 -0
- package/data/problems/maximum-depth-of-binary-tree.json +1 -0
- package/data/problems/maximum-depth-of-n-ary-tree.json +1 -0
- package/data/problems/maximum-distance-in-arrays.json +1 -0
- package/data/problems/maximum-frequency-stack.json +1 -0
- package/data/problems/maximum-gap.json +1 -0
- package/data/problems/maximum-length-of-pair-chain.json +1 -0
- package/data/problems/maximum-length-of-repeated-subarray.json +1 -0
- package/data/problems/maximum-product-of-three-numbers.json +1 -0
- package/data/problems/maximum-product-of-word-lengths.json +1 -0
- package/data/problems/maximum-product-subarray.json +1 -0
- package/data/problems/maximum-size-subarray-sum-equals-k.json +1 -0
- package/data/problems/maximum-subarray.json +1 -0
- package/data/problems/maximum-sum-circular-subarray.json +1 -0
- package/data/problems/maximum-sum-of-3-non-overlapping-subarrays.json +1 -0
- package/data/problems/maximum-swap.json +1 -0
- package/data/problems/maximum-vacation-days.json +1 -0
- package/data/problems/maximum-width-of-binary-tree.json +1 -0
- package/data/problems/maximum-width-ramp.json +1 -0
- package/data/problems/maximum-xor-of-two-numbers-in-an-array.json +1 -0
- package/data/problems/median-of-two-sorted-arrays.json +1 -0
- package/data/problems/meeting-rooms-ii.json +1 -0
- package/data/problems/meeting-rooms-iii.json +1 -0
- package/data/problems/meeting-rooms.json +1 -0
- package/data/problems/merge-intervals.json +1 -0
- package/data/problems/merge-k-sorted-lists.json +1 -0
- package/data/problems/merge-sorted-array.json +1 -0
- package/data/problems/merge-strings-alternately.json +1 -0
- package/data/problems/merge-triplets-to-form-target-triplet.json +1 -0
- package/data/problems/merge-two-binary-trees.json +1 -0
- package/data/problems/merge-two-sorted-lists.json +1 -0
- package/data/problems/middle-of-the-linked-list.json +1 -0
- package/data/problems/min-cost-climbing-stairs.json +1 -0
- package/data/problems/min-cost-to-connect-all-points.json +1 -0
- package/data/problems/min-stack.json +1 -0
- package/data/problems/minesweeper.json +1 -0
- package/data/problems/mini-parser.json +1 -0
- package/data/problems/minimize-malware-spread-ii.json +1 -0
- package/data/problems/minimize-malware-spread.json +1 -0
- package/data/problems/minimize-max-distance-to-gas-station.json +1 -0
- package/data/problems/minimum-absolute-difference-in-bst.json +1 -0
- package/data/problems/minimum-add-to-make-parentheses-valid.json +1 -0
- package/data/problems/minimum-area-rectangle-ii.json +1 -0
- package/data/problems/minimum-area-rectangle.json +1 -0
- package/data/problems/minimum-array-end.json +1 -0
- package/data/problems/minimum-ascii-delete-sum-for-two-strings.json +1 -0
- package/data/problems/minimum-cost-for-tickets.json +1 -0
- package/data/problems/minimum-cost-to-hire-k-workers.json +1 -0
- package/data/problems/minimum-cost-to-merge-stones.json +1 -0
- package/data/problems/minimum-depth-of-binary-tree.json +1 -0
- package/data/problems/minimum-distance-between-bst-nodes.json +1 -0
- package/data/problems/minimum-factorization.json +1 -0
- package/data/problems/minimum-falling-path-sum.json +1 -0
- package/data/problems/minimum-genetic-mutation.json +1 -0
- package/data/problems/minimum-height-trees.json +1 -0
- package/data/problems/minimum-increment-to-make-array-unique.json +1 -0
- package/data/problems/minimum-index-sum-of-two-lists.json +1 -0
- package/data/problems/minimum-interval-to-include-each-query.json +1 -0
- package/data/problems/minimum-moves-to-equal-array-elements-ii.json +1 -0
- package/data/problems/minimum-moves-to-equal-array-elements.json +1 -0
- package/data/problems/minimum-number-of-arrows-to-burst-balloons.json +1 -0
- package/data/problems/minimum-number-of-k-consecutive-bit-flips.json +1 -0
- package/data/problems/minimum-number-of-refueling-stops.json +1 -0
- package/data/problems/minimum-path-sum.json +1 -0
- package/data/problems/minimum-size-subarray-sum.json +1 -0
- package/data/problems/minimum-swaps-to-make-sequences-increasing.json +1 -0
- package/data/problems/minimum-time-difference.json +1 -0
- package/data/problems/minimum-unique-word-abbreviation.json +1 -0
- package/data/problems/minimum-window-subsequence.json +1 -0
- package/data/problems/minimum-window-substring.json +1 -0
- package/data/problems/mirror-reflection.json +1 -0
- package/data/problems/missing-number.json +1 -0
- package/data/problems/missing-ranges.json +1 -0
- package/data/problems/monotone-increasing-digits.json +1 -0
- package/data/problems/monotonic-array.json +1 -0
- package/data/problems/most-common-word.json +1 -0
- package/data/problems/most-frequent-subtree-sum.json +1 -0
- package/data/problems/most-profit-assigning-work.json +1 -0
- package/data/problems/most-stones-removed-with-same-row-or-column.json +1 -0
- package/data/problems/move-zeroes.json +1 -0
- package/data/problems/moving-average-from-data-stream.json +1 -0
- package/data/problems/multiply-strings.json +1 -0
- package/data/problems/my-calendar-i.json +1 -0
- package/data/problems/my-calendar-ii.json +1 -0
- package/data/problems/my-calendar-iii.json +1 -0
- package/data/problems/n-ary-tree-level-order-traversal.json +1 -0
- package/data/problems/n-ary-tree-postorder-traversal.json +1 -0
- package/data/problems/n-ary-tree-preorder-traversal.json +1 -0
- package/data/problems/n-queens-ii.json +1 -0
- package/data/problems/n-queens.json +1 -0
- package/data/problems/n-repeated-element-in-size-2n-array.json +1 -0
- package/data/problems/n-th-tribonacci-number.json +1 -0
- package/data/problems/nested-list-weight-sum-ii.json +1 -0
- package/data/problems/nested-list-weight-sum.json +1 -0
- package/data/problems/network-delay-time.json +1 -0
- package/data/problems/new-21-game.json +1 -0
- package/data/problems/next-closest-time.json +1 -0
- package/data/problems/next-greater-element-i.json +1 -0
- package/data/problems/next-greater-element-ii.json +1 -0
- package/data/problems/next-greater-element-iii.json +1 -0
- package/data/problems/next-permutation.json +1 -0
- package/data/problems/nim-game.json +1 -0
- package/data/problems/non-decreasing-array.json +1 -0
- package/data/problems/non-decreasing-subsequences.json +1 -0
- package/data/problems/non-negative-integers-without-consecutive-ones.json +1 -0
- package/data/problems/non-overlapping-intervals.json +1 -0
- package/data/problems/nth-digit.json +1 -0
- package/data/problems/nth-magical-number.json +1 -0
- package/data/problems/number-complement.json +1 -0
- package/data/problems/number-of-1-bits.json +1 -0
- package/data/problems/number-of-atoms.json +1 -0
- package/data/problems/number-of-boomerangs.json +1 -0
- package/data/problems/number-of-connected-components-in-an-undirected-graph.json +1 -0
- package/data/problems/number-of-corner-rectangles.json +1 -0
- package/data/problems/number-of-digit-one.json +1 -0
- package/data/problems/number-of-distinct-islands-ii.json +1 -0
- package/data/problems/number-of-distinct-islands.json +1 -0
- package/data/problems/number-of-islands-ii.json +1 -0
- package/data/problems/number-of-islands.json +1 -0
- package/data/problems/number-of-lines-to-write-string.json +1 -0
- package/data/problems/number-of-longest-increasing-subsequence.json +1 -0
- package/data/problems/number-of-matching-subsequences.json +1 -0
- package/data/problems/number-of-music-playlists.json +1 -0
- package/data/problems/number-of-provinces.json +1 -0
- package/data/problems/number-of-recent-calls.json +1 -0
- package/data/problems/number-of-segments-in-a-string.json +1 -0
- package/data/problems/number-of-squareful-arrays.json +1 -0
- package/data/problems/number-of-subarrays-with-bounded-maximum.json +1 -0
- package/data/problems/numbers-at-most-n-given-digit-set.json +1 -0
- package/data/problems/numbers-with-same-consecutive-differences.json +1 -0
- package/data/problems/odd-even-jump.json +1 -0
- package/data/problems/odd-even-linked-list.json +1 -0
- package/data/problems/one-edit-distance.json +1 -0
- package/data/problems/ones-and-zeroes.json +1 -0
- package/data/problems/online-election.json +1 -0
- package/data/problems/online-stock-span.json +1 -0
- package/data/problems/open-the-lock.json +1 -0
- package/data/problems/optimal-account-balancing.json +1 -0
- package/data/problems/optimal-division.json +1 -0
- package/data/problems/orderly-queue.json +1 -0
- package/data/problems/out-of-boundary-paths.json +1 -0
- package/data/problems/output-contest-matches.json +1 -0
- package/data/problems/pacific-atlantic-water-flow.json +1 -0
- package/data/problems/paint-fence.json +1 -0
- package/data/problems/paint-house-ii.json +1 -0
- package/data/problems/paint-house.json +1 -0
- package/data/problems/palindrome-linked-list.json +1 -0
- package/data/problems/palindrome-number.json +1 -0
- package/data/problems/palindrome-pairs.json +1 -0
- package/data/problems/palindrome-partitioning-ii.json +1 -0
- package/data/problems/palindrome-partitioning.json +1 -0
- package/data/problems/palindrome-permutation-ii.json +1 -0
- package/data/problems/palindrome-permutation.json +1 -0
- package/data/problems/palindromic-substrings.json +1 -0
- package/data/problems/pancake-sorting.json +1 -0
- package/data/problems/parse-lisp-expression.json +1 -0
- package/data/problems/partition-array-into-disjoint-intervals.json +1 -0
- package/data/problems/partition-equal-subset-sum.json +1 -0
- package/data/problems/partition-labels.json +1 -0
- package/data/problems/partition-list.json +1 -0
- package/data/problems/partition-to-k-equal-sum-subsets.json +1 -0
- package/data/problems/pascals-triangle-ii.json +1 -0
- package/data/problems/pascals-triangle.json +1 -0
- package/data/problems/patching-array.json +1 -0
- package/data/problems/path-sum-ii.json +1 -0
- package/data/problems/path-sum-iii.json +1 -0
- package/data/problems/path-sum-iv.json +1 -0
- package/data/problems/path-sum.json +1 -0
- package/data/problems/path-with-minimum-effort.json +1 -0
- package/data/problems/peak-index-in-a-mountain-array.json +1 -0
- package/data/problems/peeking-iterator.json +1 -0
- package/data/problems/perfect-number.json +1 -0
- package/data/problems/perfect-rectangle.json +1 -0
- package/data/problems/perfect-squares.json +1 -0
- package/data/problems/permutation-in-string.json +1 -0
- package/data/problems/permutation-sequence.json +1 -0
- package/data/problems/permutations-ii.json +1 -0
- package/data/problems/permutations.json +1 -0
- package/data/problems/plus-one-linked-list.json +1 -0
- package/data/problems/plus-one.json +1 -0
- package/data/problems/poor-pigs.json +1 -0
- package/data/problems/populating-next-right-pointers-in-each-node-ii.json +1 -0
- package/data/problems/populating-next-right-pointers-in-each-node.json +1 -0
- package/data/problems/positions-of-large-groups.json +1 -0
- package/data/problems/possible-bipartition.json +1 -0
- package/data/problems/pour-water.json +1 -0
- package/data/problems/power-of-four.json +1 -0
- package/data/problems/power-of-three.json +1 -0
- package/data/problems/power-of-two.json +1 -0
- package/data/problems/powerful-integers.json +1 -0
- package/data/problems/powx-n.json +1 -0
- package/data/problems/predict-the-winner.json +1 -0
- package/data/problems/prefix-and-suffix-search.json +1 -0
- package/data/problems/preimage-size-of-factorial-zeroes-function.json +1 -0
- package/data/problems/prime-number-of-set-bits-in-binary-representation.json +1 -0
- package/data/problems/prime-palindrome.json +1 -0
- package/data/problems/print-binary-tree.json +1 -0
- package/data/problems/prison-cells-after-n-days.json +1 -0
- package/data/problems/product-of-array-except-self.json +1 -0
- package/data/problems/profitable-schemes.json +1 -0
- package/data/problems/projection-area-of-3d-shapes.json +1 -0
- package/data/problems/push-dominoes.json +1 -0
- package/data/problems/pyramid-transition-matrix.json +1 -0
- package/data/problems/queue-reconstruction-by-height.json +1 -0
- package/data/problems/rabbits-in-forest.json +1 -0
- package/data/problems/race-car.json +1 -0
- package/data/problems/random-flip-matrix.json +1 -0
- package/data/problems/random-pick-index.json +1 -0
- package/data/problems/random-pick-with-blacklist.json +1 -0
- package/data/problems/random-pick-with-weight.json +1 -0
- package/data/problems/random-point-in-non-overlapping-rectangles.json +1 -0
- package/data/problems/range-addition-ii.json +1 -0
- package/data/problems/range-addition.json +1 -0
- package/data/problems/range-module.json +1 -0
- package/data/problems/range-sum-of-bst.json +1 -0
- package/data/problems/range-sum-query-2d-immutable.json +1 -0
- package/data/problems/range-sum-query-2d-mutable.json +1 -0
- package/data/problems/range-sum-query-immutable.json +1 -0
- package/data/problems/range-sum-query-mutable.json +1 -0
- package/data/problems/ransom-note.json +1 -0
- package/data/problems/reach-a-number.json +1 -0
- package/data/problems/reachable-nodes-in-subdivided-graph.json +1 -0
- package/data/problems/reaching-points.json +1 -0
- package/data/problems/read-n-characters-given-read4-ii-call-multiple-times.json +1 -0
- package/data/problems/read-n-characters-given-read4.json +1 -0
- package/data/problems/rearrange-string-k-distance-apart.json +1 -0
- package/data/problems/reconstruct-itinerary.json +1 -0
- package/data/problems/reconstruct-original-digits-from-english.json +1 -0
- package/data/problems/recover-binary-search-tree.json +1 -0
- package/data/problems/rectangle-area-ii.json +1 -0
- package/data/problems/rectangle-area.json +1 -0
- package/data/problems/rectangle-overlap.json +1 -0
- package/data/problems/redundant-connection-ii.json +1 -0
- package/data/problems/redundant-connection.json +1 -0
- package/data/problems/regions-cut-by-slashes.json +1 -0
- package/data/problems/regular-expression-matching.json +1 -0
- package/data/problems/relative-ranks.json +1 -0
- package/data/problems/remove-9.json +1 -0
- package/data/problems/remove-boxes.json +1 -0
- package/data/problems/remove-comments.json +1 -0
- package/data/problems/remove-duplicate-letters.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-array-ii.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-array.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-list-ii.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-list.json +1 -0
- package/data/problems/remove-element.json +1 -0
- package/data/problems/remove-invalid-parentheses.json +1 -0
- package/data/problems/remove-k-digits.json +1 -0
- package/data/problems/remove-linked-list-elements.json +1 -0
- package/data/problems/remove-nth-node-from-end-of-list.json +1 -0
- package/data/problems/reorder-data-in-log-files.json +1 -0
- package/data/problems/reorder-list.json +1 -0
- package/data/problems/reordered-power-of-2.json +1 -0
- package/data/problems/reorganize-string.json +1 -0
- package/data/problems/repeated-dna-sequences.json +1 -0
- package/data/problems/repeated-string-match.json +1 -0
- package/data/problems/repeated-substring-pattern.json +1 -0
- package/data/problems/replace-words.json +1 -0
- package/data/problems/reshape-the-matrix.json +1 -0
- package/data/problems/restore-ip-addresses.json +1 -0
- package/data/problems/reveal-cards-in-increasing-order.json +1 -0
- package/data/problems/reverse-bits.json +1 -0
- package/data/problems/reverse-integer.json +1 -0
- package/data/problems/reverse-linked-list-ii.json +1 -0
- package/data/problems/reverse-linked-list.json +1 -0
- package/data/problems/reverse-nodes-in-k-group.json +1 -0
- package/data/problems/reverse-only-letters.json +1 -0
- package/data/problems/reverse-pairs.json +1 -0
- package/data/problems/reverse-string-ii.json +1 -0
- package/data/problems/reverse-string.json +1 -0
- package/data/problems/reverse-vowels-of-a-string.json +1 -0
- package/data/problems/reverse-words-in-a-string-ii.json +1 -0
- package/data/problems/reverse-words-in-a-string-iii.json +1 -0
- package/data/problems/reverse-words-in-a-string.json +1 -0
- package/data/problems/rle-iterator.json +1 -0
- package/data/problems/robot-return-to-origin.json +1 -0
- package/data/problems/robot-room-cleaner.json +1 -0
- package/data/problems/roman-to-integer.json +1 -0
- package/data/problems/rotate-array.json +1 -0
- package/data/problems/rotate-function.json +1 -0
- package/data/problems/rotate-image.json +1 -0
- package/data/problems/rotate-list.json +1 -0
- package/data/problems/rotate-string.json +1 -0
- package/data/problems/rotated-digits.json +1 -0
- package/data/problems/rotting-oranges.json +1 -0
- package/data/problems/russian-doll-envelopes.json +1 -0
- package/data/problems/same-tree.json +1 -0
- package/data/problems/satisfiability-of-equality-equations.json +1 -0
- package/data/problems/score-after-flipping-matrix.json +1 -0
- package/data/problems/score-of-parentheses.json +1 -0
- package/data/problems/scramble-string.json +1 -0
- package/data/problems/search-a-2d-matrix-ii.json +1 -0
- package/data/problems/search-a-2d-matrix.json +1 -0
- package/data/problems/search-in-a-binary-search-tree.json +1 -0
- package/data/problems/search-in-a-sorted-array-of-unknown-size.json +1 -0
- package/data/problems/search-in-rotated-sorted-array-ii.json +1 -0
- package/data/problems/search-in-rotated-sorted-array.json +1 -0
- package/data/problems/search-insert-position.json +1 -0
- package/data/problems/second-minimum-node-in-a-binary-tree.json +1 -0
- package/data/problems/self-crossing.json +1 -0
- package/data/problems/self-dividing-numbers.json +1 -0
- package/data/problems/sentence-screen-fitting.json +1 -0
- package/data/problems/sentence-similarity-ii.json +1 -0
- package/data/problems/sentence-similarity.json +1 -0
- package/data/problems/sequence-reconstruction.json +1 -0
- package/data/problems/serialize-and-deserialize-binary-tree.json +1 -0
- package/data/problems/serialize-and-deserialize-bst.json +1 -0
- package/data/problems/serialize-and-deserialize-n-ary-tree.json +1 -0
- package/data/problems/set-intersection-size-at-least-two.json +1 -0
- package/data/problems/set-matrix-zeroes.json +1 -0
- package/data/problems/set-mismatch.json +1 -0
- package/data/problems/shifting-letters.json +1 -0
- package/data/problems/shopping-offers.json +1 -0
- package/data/problems/short-encoding-of-words.json +1 -0
- package/data/problems/shortest-bridge.json +1 -0
- package/data/problems/shortest-completing-word.json +1 -0
- package/data/problems/shortest-distance-from-all-buildings.json +1 -0
- package/data/problems/shortest-distance-to-a-character.json +1 -0
- package/data/problems/shortest-palindrome.json +1 -0
- package/data/problems/shortest-path-to-get-all-keys.json +1 -0
- package/data/problems/shortest-path-visiting-all-nodes.json +1 -0
- package/data/problems/shortest-subarray-with-sum-at-least-k.json +1 -0
- package/data/problems/shortest-unsorted-continuous-subarray.json +1 -0
- package/data/problems/shortest-word-distance-ii.json +1 -0
- package/data/problems/shortest-word-distance-iii.json +1 -0
- package/data/problems/shortest-word-distance.json +1 -0
- package/data/problems/shuffle-an-array.json +1 -0
- package/data/problems/similar-rgb-color.json +1 -0
- package/data/problems/similar-string-groups.json +1 -0
- package/data/problems/simplify-path.json +1 -0
- package/data/problems/single-element-in-a-sorted-array.json +1 -0
- package/data/problems/single-number-ii.json +1 -0
- package/data/problems/single-number-iii.json +1 -0
- package/data/problems/single-number.json +1 -0
- package/data/problems/single-threaded-cpu.json +1 -0
- package/data/problems/sliding-puzzle.json +1 -0
- package/data/problems/sliding-window-maximum.json +1 -0
- package/data/problems/sliding-window-median.json +1 -0
- package/data/problems/smallest-good-base.json +1 -0
- package/data/problems/smallest-range-covering-elements-from-k-lists.json +1 -0
- package/data/problems/smallest-range-i.json +1 -0
- package/data/problems/smallest-range-ii.json +1 -0
- package/data/problems/smallest-rectangle-enclosing-black-pixels.json +1 -0
- package/data/problems/smallest-rotation-with-highest-score.json +1 -0
- package/data/problems/smallest-string-starting-from-leaf.json +1 -0
- package/data/problems/smallest-subtree-with-all-the-deepest-nodes.json +1 -0
- package/data/problems/snakes-and-ladders.json +1 -0
- package/data/problems/solve-the-equation.json +1 -0
- package/data/problems/sort-an-array.json +1 -0
- package/data/problems/sort-array-by-parity-ii.json +1 -0
- package/data/problems/sort-array-by-parity.json +1 -0
- package/data/problems/sort-characters-by-frequency.json +1 -0
- package/data/problems/sort-colors.json +1 -0
- package/data/problems/sort-list.json +1 -0
- package/data/problems/sort-transformed-array.json +1 -0
- package/data/problems/soup-servings.json +1 -0
- package/data/problems/sparse-matrix-multiplication.json +1 -0
- package/data/problems/special-binary-string.json +1 -0
- package/data/problems/spiral-matrix-ii.json +1 -0
- package/data/problems/spiral-matrix-iii.json +1 -0
- package/data/problems/spiral-matrix.json +1 -0
- package/data/problems/split-array-into-consecutive-subsequences.json +1 -0
- package/data/problems/split-array-into-fibonacci-sequence.json +1 -0
- package/data/problems/split-array-largest-sum.json +1 -0
- package/data/problems/split-array-with-equal-sum.json +1 -0
- package/data/problems/split-array-with-same-average.json +1 -0
- package/data/problems/split-bst.json +1 -0
- package/data/problems/split-concatenated-strings.json +1 -0
- package/data/problems/split-linked-list-in-parts.json +1 -0
- package/data/problems/sqrtx.json +1 -0
- package/data/problems/squares-of-a-sorted-array.json +1 -0
- package/data/problems/squirrel-simulation.json +1 -0
- package/data/problems/stamping-the-sequence.json +1 -0
- package/data/problems/stickers-to-spell-word.json +1 -0
- package/data/problems/stone-game-ii.json +1 -0
- package/data/problems/stone-game-iii.json +1 -0
- package/data/problems/stone-game.json +1 -0
- package/data/problems/strange-printer.json +1 -0
- package/data/problems/string-compression.json +1 -0
- package/data/problems/string-to-integer-atoi.json +1 -0
- package/data/problems/string-without-aaa-or-bbb.json +1 -0
- package/data/problems/strobogrammatic-number-ii.json +1 -0
- package/data/problems/strobogrammatic-number-iii.json +1 -0
- package/data/problems/strobogrammatic-number.json +1 -0
- package/data/problems/strong-password-checker.json +1 -0
- package/data/problems/student-attendance-record-i.json +1 -0
- package/data/problems/student-attendance-record-ii.json +1 -0
- package/data/problems/subarray-product-less-than-k.json +1 -0
- package/data/problems/subarray-sum-equals-k.json +1 -0
- package/data/problems/subarray-sums-divisible-by-k.json +1 -0
- package/data/problems/subarrays-with-k-different-integers.json +1 -0
- package/data/problems/subdomain-visit-count.json +1 -0
- package/data/problems/subsets-ii.json +1 -0
- package/data/problems/subsets.json +1 -0
- package/data/problems/substring-with-concatenation-of-all-words.json +1 -0
- package/data/problems/subtree-of-another-tree.json +1 -0
- package/data/problems/sudoku-solver.json +1 -0
- package/data/problems/sum-of-all-subset-xor-totals.json +1 -0
- package/data/problems/sum-of-distances-in-tree.json +1 -0
- package/data/problems/sum-of-even-numbers-after-queries.json +1 -0
- package/data/problems/sum-of-left-leaves.json +1 -0
- package/data/problems/sum-of-square-numbers.json +1 -0
- package/data/problems/sum-of-subarray-minimums.json +1 -0
- package/data/problems/sum-of-subsequence-widths.json +1 -0
- package/data/problems/sum-of-two-integers.json +1 -0
- package/data/problems/sum-root-to-leaf-numbers.json +1 -0
- package/data/problems/summary-ranges.json +1 -0
- package/data/problems/super-egg-drop.json +1 -0
- package/data/problems/super-palindromes.json +1 -0
- package/data/problems/super-pow.json +1 -0
- package/data/problems/super-ugly-number.json +1 -0
- package/data/problems/super-washing-machines.json +1 -0
- package/data/problems/surface-area-of-3d-shapes.json +1 -0
- package/data/problems/surrounded-regions.json +1 -0
- package/data/problems/swap-adjacent-in-lr-string.json +1 -0
- package/data/problems/swap-nodes-in-pairs.json +1 -0
- package/data/problems/swim-in-rising-water.json +1 -0
- package/data/problems/symmetric-tree.json +1 -0
- package/data/problems/tag-validator.json +1 -0
- package/data/problems/tallest-billboard.json +1 -0
- package/data/problems/target-sum.json +1 -0
- package/data/problems/task-scheduler.json +1 -0
- package/data/problems/teemo-attacking.json +1 -0
- package/data/problems/ternary-expression-parser.json +1 -0
- package/data/problems/text-justification.json +1 -0
- package/data/problems/the-maze-ii.json +1 -0
- package/data/problems/the-maze-iii.json +1 -0
- package/data/problems/the-maze.json +1 -0
- package/data/problems/the-skyline-problem.json +1 -0
- package/data/problems/third-maximum-number.json +1 -0
- package/data/problems/three-equal-parts.json +1 -0
- package/data/problems/time-based-key-value-store.json +1 -0
- package/data/problems/to-lower-case.json +1 -0
- package/data/problems/toeplitz-matrix.json +1 -0
- package/data/problems/top-k-frequent-elements.json +1 -0
- package/data/problems/top-k-frequent-words.json +1 -0
- package/data/problems/total-hamming-distance.json +1 -0
- package/data/problems/transform-to-chessboard.json +1 -0
- package/data/problems/transpose-matrix.json +1 -0
- package/data/problems/trapping-rain-water-ii.json +1 -0
- package/data/problems/trapping-rain-water.json +1 -0
- package/data/problems/triangle.json +1 -0
- package/data/problems/trim-a-binary-search-tree.json +1 -0
- package/data/problems/triples-with-bitwise-and-equal-to-zero.json +1 -0
- package/data/problems/two-sum-ii-input-array-is-sorted.json +1 -0
- package/data/problems/two-sum-iii-data-structure-design.json +1 -0
- package/data/problems/two-sum-iv-input-is-a-bst.json +1 -0
- package/data/problems/two-sum.json +1 -0
- package/data/problems/ugly-number-ii.json +1 -0
- package/data/problems/ugly-number.json +1 -0
- package/data/problems/uncommon-words-from-two-sentences.json +1 -0
- package/data/problems/unique-binary-search-trees-ii.json +1 -0
- package/data/problems/unique-binary-search-trees.json +1 -0
- package/data/problems/unique-email-addresses.json +1 -0
- package/data/problems/unique-morse-code-words.json +1 -0
- package/data/problems/unique-paths-ii.json +1 -0
- package/data/problems/unique-paths-iii.json +1 -0
- package/data/problems/unique-paths.json +1 -0
- package/data/problems/unique-substrings-in-wraparound-string.json +1 -0
- package/data/problems/unique-word-abbreviation.json +1 -0
- package/data/problems/univalued-binary-tree.json +1 -0
- package/data/problems/utf-8-validation.json +1 -0
- package/data/problems/valid-anagram.json +1 -0
- package/data/problems/valid-mountain-array.json +1 -0
- package/data/problems/valid-number.json +1 -0
- package/data/problems/valid-palindrome-ii.json +1 -0
- package/data/problems/valid-palindrome.json +1 -0
- package/data/problems/valid-parentheses.json +1 -0
- package/data/problems/valid-parenthesis-string.json +1 -0
- package/data/problems/valid-perfect-square.json +1 -0
- package/data/problems/valid-permutations-for-di-sequence.json +1 -0
- package/data/problems/valid-square.json +1 -0
- package/data/problems/valid-sudoku.json +1 -0
- package/data/problems/valid-tic-tac-toe-state.json +1 -0
- package/data/problems/valid-triangle-number.json +1 -0
- package/data/problems/valid-word-abbreviation.json +1 -0
- package/data/problems/valid-word-square.json +1 -0
- package/data/problems/validate-binary-search-tree.json +1 -0
- package/data/problems/validate-ip-address.json +1 -0
- package/data/problems/validate-stack-sequences.json +1 -0
- package/data/problems/verify-preorder-sequence-in-binary-search-tree.json +1 -0
- package/data/problems/verify-preorder-serialization-of-a-binary-tree.json +1 -0
- package/data/problems/verifying-an-alien-dictionary.json +1 -0
- package/data/problems/vertical-order-traversal-of-a-binary-tree.json +1 -0
- package/data/problems/vowel-spellchecker.json +1 -0
- package/data/problems/walking-robot-simulation.json +1 -0
- package/data/problems/walls-and-gates.json +1 -0
- package/data/problems/water-and-jug-problem.json +1 -0
- package/data/problems/wiggle-sort-ii.json +1 -0
- package/data/problems/wiggle-sort.json +1 -0
- package/data/problems/wiggle-subsequence.json +1 -0
- package/data/problems/wildcard-matching.json +1 -0
- package/data/problems/word-abbreviation.json +1 -0
- package/data/problems/word-break-ii.json +1 -0
- package/data/problems/word-break.json +1 -0
- package/data/problems/word-ladder-ii.json +1 -0
- package/data/problems/word-ladder.json +1 -0
- package/data/problems/word-pattern-ii.json +1 -0
- package/data/problems/word-pattern.json +1 -0
- package/data/problems/word-search-ii.json +1 -0
- package/data/problems/word-search.json +1 -0
- package/data/problems/word-squares.json +1 -0
- package/data/problems/word-subsets.json +1 -0
- package/data/problems/x-of-a-kind-in-a-deck-of-cards.json +1 -0
- package/data/problems/zigzag-conversion.json +1 -0
- package/data/problems/zigzag-iterator.json +1 -0
- package/data/problems/zuma-game.json +1 -0
- package/dist/cli.js +793 -0
- package/dist/web/assets/index-7tyR3Zsa.js +147 -0
- package/dist/web/assets/index-oer4U46K.css +1 -0
- package/dist/web/index.html +13 -0
- package/package.json +42 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "91", "slug": "median-of-two-sorted-arrays", "id": 91, "title": "Median of Two Sorted Arrays", "difficulty": "Hard", "category": "binary-search", "link": "https://leetcode.com/problems/median-of-two-sorted-arrays/", "examples": [{"input": "nums1 = [1,3], nums2 = [2]", "output": "\"2.0\"", "explanation": "The combined sorted array is [1, 2, 3]. With 3 elements, the median is the middle value, 2.0."}, {"input": "nums1 = [1,2], nums2 = [3,4]", "output": "\"2.5\"", "explanation": "The combined sorted array is [1, 2, 3, 4]. With 4 elements, the median is the average of the two middle values, 2.5."}, {"input": "nums1 = [], nums2 = [1]", "output": "\"1.0\"", "explanation": "The combined sorted array is [1]. With 1 element, the median is the only value, 1.0."}], "hints": ["Binary-search a partition in the shorter array and infer the matching partition in the longer array.", "A partition is valid when every value on the left is no greater than every value on the right.", "Use wide integer arithmetic before averaging the two middle values to avoid overflow."], "statement": "Two integer arrays `nums1` and `nums2` arrive already ordered from smallest to largest. Conceptually merge their contents and report the middle value, or the mean of the two middle values when the combined size is even. At least one of the two inputs contains an element.\n\nAn efficient procedure is expected, with total running time `O(log(min(nums1.length, nums2.length)))`.\n\n**Constraints:**\n\n- `0 <= nums1.length, nums2.length <= 1000`\n- `1 <= nums1.length + nums2.length <= 2000`\n- `-10^6 <= nums1[i], nums2[i] <= 10^6`\n- Both arrays are sorted in nondecreasing order.\n\n**Portable interface:** Provide `findMedianSortedArrays(nums1, nums2)`. Because floating-point rendering varies between languages, this version expresses the answer as a normalized decimal string: a whole-number median ends in `.0` and a halfway median ends in `.5`, such as `\"2.0\"`, `\"2.5\"`, or `\"-0.5\"`.\n", "solution": "## Approach\n\nBinary-search a partition in the shorter array and infer the partition in the longer array so the left side contains half of all values. A partition is valid when both left boundary values are no greater than the opposite right boundary values. Use the middle boundary value or pair of values to produce the required canonical `.0` or `.5` string without floating-point arithmetic.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log(min(m, n))), where `m` and `n` are the input lengths.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> str:\n if len(nums1) > len(nums2):\n return self.findMedianSortedArrays(nums2, nums1)\n\n total = len(nums1) + len(nums2)\n left_size = (total + 1) // 2\n low, high = 0, len(nums1)\n\n while low <= high:\n partition1 = low + (high - low) // 2\n partition2 = left_size - partition1\n left1 = -(2**63) if partition1 == 0 else nums1[partition1 - 1]\n right1 = 2**63 - 1 if partition1 == len(nums1) else nums1[partition1]\n left2 = -(2**63) if partition2 == 0 else nums2[partition2 - 1]\n right2 = 2**63 - 1 if partition2 == len(nums2) else nums2[partition2]\n\n if left1 <= right2 and left2 <= right1:\n lower = max(left1, left2)\n if total % 2 == 1:\n return f\"{lower}.0\"\n total_middle = lower + min(right1, right2)\n if total_middle % 2 == 0:\n return f\"{total_middle // 2}.0\"\n sign = \"-\" if total_middle < 0 else \"\"\n return f\"{sign}{abs(total_middle) // 2}.5\"\n\n if left1 > right2:\n high = partition1 - 1\n else:\n low = partition1 + 1\n\n raise ValueError(\"Input arrays must be sorted\")\n```\n", "starter": {"go": "package main\n\nfunc FindMedianSortedArrays(nums1 []int, nums2 []int) string {\n return \"0.0\"\n}", "python": "from typing import List\n\nclass Solution:\n def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> str:\n return \"0.0\"\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n string findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) {\n return \"0.0\";\n }\n};"}, "fn": "findMedianSortedArrays", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}], "outputType": "string", "tests": [["[1,3]", "[2]"], ["[1,2]", "[3,4]"], ["[]", "[1]"], ["[2]", "[]"], ["[0,0]", "[0,0]"], ["[]", "[1,2]"], ["[-1]", "[1]"], ["[-5,-3,-1]", "[-2]"], ["[-5,-3]", "[-4,-2]"], ["[1]", "[2,3,4,5]"], ["[1,2,3,4]", "[5]"], ["[1,10]", "[2,3,4,5,6,7,8,9]"], ["[1,2,3,4,5]", "[6,7,8,9,10]"], ["[1,1,1]", "[1,1]"], ["[1,1,2]", "[2,2,2]"], ["[-10,-5,0]", "[5,10]"], ["[-10,-5]", "[0,5,10]"], ["[-2,-1]", "[1,2]"], ["[-3,-2,-1]", "[1,2,3]"], ["[100]", "[101]"], ["[-1000000]", "[1000000]"], ["[1000000]", "[1000000]"], ["[-1000000]", "[-1000000]"], ["[-1000000,-999999]", "[999999,1000000]"], ["[1,4,7]", "[2,3,5,6]"], ["[2,3,5,6]", "[1,4,7]"], ["[]", "[-10,-5,-1,0]"], ["[-10,-5,-1,0]", "[]"], ["[]", "[-9,-3,0,4,12]"], ["[-9,-3,0,4,12]", "[]"], ["[1,2]", "[100,101,102,103]"], ["[100,101]", "[1,2,3,4]"], ["[1,5,9]", "[2,3,7,11]"], ["[1,5,9,13]", "[2,3,7,11]"], ["[5,5,5,5]", "[5,5,5]"], ["[-1,0,0]", "[0,0,1]"], ["[-1000000,1000000]", "[0]"], ["[-1000000]", "[1000000,1000000]"], ["[-1000000,-1000000]", "[1000000]"], ["[2,2,2,2]", "[2]"], ["[1,2,2]", "[2,3,4]"], ["[1,1,1,10]", "[2,3,4,5,6]"], ["[-4,-3]", "[-2,-1]"], ["[-1,0]", "[1,2]"], ["[-2,0]", "[1,3]"], ["[-7]", "[-6,-5,-4,-3,-2]"], ["[3,8,12,20]", "[1,4,7,9,15]"], ["[1,4,7,9,15]", "[3,8,12,20]"], ["[2,6,10,14,18,22]", "[1,3,5,7,9,11,13]"], ["[-20,-15,-10,-5,0,5,10,15,20,25]", "[-18,-12,-6,-1,4,9,14,19,24,30]"], ["@javascript:JSON.stringify(Array.from({length:1000},(_,i)=>-1000000+i))", "@javascript:JSON.stringify(Array.from({length:1000},(_,i)=>999001+i))"]], "expected": ["2.0", "2.5", "1.0", "2.0", "0.0", "1.5", "0.0", "-2.5", "-3.5", "3.0", "3.0", "5.5", "5.5", "1.0", "2.0", "0.0", "0.0", "0.0", "0.0", "100.5", "0.0", "1000000.0", "-1000000.0", "0.0", "4.0", "4.0", "-3.0", "-3.0", "0.0", "0.0", "100.5", "3.5", "5.0", "6.0", "5.0", "0.0", "0.0", "1000000.0", "-1000000.0", "2.0", "2.0", "3.0", "-2.5", "0.5", "0.5", "-4.5", "8.0", "8.0", "9.0", "4.5", "0.0"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "39", "slug": "meeting-rooms-ii", "id": 39, "title": "Meeting Rooms II", "difficulty": "Medium", "category": "interval", "link": "https://leetcode.com/problems/meeting-rooms-ii/", "examples": [{"input": "intervals = [[0,30],[5,10],[15,20]]", "output": "2", "explanation": "Intervals [5,10] and [15,20] both overlap within [0,30], so 2 rooms are needed."}, {"input": "intervals = [[7,10],[2,4]]", "output": "1", "explanation": "Intervals [7,10] and [2,4] do not overlap, so 1 room suffices."}], "hints": ["Use a min-heap of end times: for each interval in start-sorted order, free rooms with end <= start, then add current end; heap size is rooms needed.", "Equivalent two-pointer approach: sort starts and ends separately, advance pointers and track concurrent meetings.", "Edge case: empty input requires 0 rooms."], "statement": "Given an array of meeting time intervals `intervals`, where\n`intervals[i] = [start_i, end_i]`, return the minimum number of conference rooms\nrequired to host every meeting.\n\nMeetings that overlap must use different rooms. If one meeting ends at the exact\ntime another begins, the two meetings may use the same room.\n\n\n**Constraints:**\n\n- `0 <= intervals.length <= 10^4`\n- `intervals[i].length == 2`\n- `0 <= start_i < end_i <= 10^6`\n", "solution": "## Approach\nSweep line algorithm: sort start and end times separately, then advance through them with two pointers. Each start increments the concurrent meeting count, each end decrements it. Track the maximum count.\n\n## Complexity Analysis\n- **Time Complexity:** O(n log n)\n- **Space Complexity:** O(n)\n\n## Implementation\n```python\nfrom typing import List\nclass Solution:\n def minMeetingRooms(self, intervals: List[List[int]]) -> int:\n starts = sorted(i[0] for i in intervals)\n ends = sorted(i[1] for i in intervals)\n s = e = 0\n cnt = 0\n res = 0\n while s < len(starts):\n if starts[s] < ends[e]:\n cnt += 1\n s += 1\n else:\n cnt -= 1\n e += 1\n res = max(res, cnt)\n return res\n```\n", "starter": {"go": "package main\n\nfunc MinMeetingRooms(intervals [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def minMeetingRooms(self, intervals: List[List[int]]) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minMeetingRooms(vector<vector<int>>& intervals) {\n return 0;\n }\n};"}, "fn": "minMeetingRooms", "params": [{"name": "intervals", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0,30],[5,10],[15,20]]"], ["[[7,10],[2,4]]"], ["[]"], ["[[1,5]]"], ["[[1,5],[5,6]]"], ["[[1,5],[4,6]]"], ["[[1,4],[2,3],[3,5],[7,8]]"], ["[[0,5],[5,10],[10,15]]"], ["[[1,2],[3,4],[5,6]]"], ["[[1,10],[2,3],[4,5]]"], ["[[2,4],[2,4]]"], ["[[0,1],[1,2],[2,3],[3,4]]"], ["[[5,8],[1,3],[3,5]]"], ["[[1,5],[2,6],[3,7]]"], ["[[0,10],[10,20],[5,15]]"], ["[[100,200],[300,400]]"], ["[[1,100],[2,3]]"], ["[[1,3],[2,4],[3,5],[4,6]]"], ["[[1,2],[2,3],[3,4],[1,4]]"], ["[[0,30],[5,10],[5,10]]"], ["[[6,10],[1,4],[2,5],[7,9]]"], ["[[1,7],[2,4],[4,6],[6,8]]"], ["[[0,5],[1,6],[2,7],[3,8]]"], ["[[9,12],[1,4],[4,9]]"], ["[[0,5],[4,6],[6,10]]"], ["[[1,3],[3,5],[5,7],[2,6]]"], ["[[10,20],[0,10],[20,30]]"], ["[[5,9],[1,5],[9,13],[2,6]]"], ["[[0,4],[1,2],[2,3],[3,5]]"], ["[[8,12],[3,7],[1,3],[5,8]]"]], "expected": [2, 1, 0, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 3, 2, 1, 2, 2, 2, 3, 2, 2, 4, 1, 2, 2, 1, 2, 2, 2], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "242", "slug": "meeting-rooms-iii", "id": 242, "title": "Meeting Rooms III", "difficulty": "Hard", "category": "interval", "link": "https://leetcode.com/problems/meeting-rooms-iii/", "examples": [{"input": "n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]", "output": "0"}, {"input": "n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]", "output": "1"}], "hints": ["Sort meetings by start. Use two heaps: free rooms and busy rooms (end time, room)."], "statement": "There are `n` meeting rooms labelled `0` through `n - 1`.\n\nA 2D integer array `meetings` lists the bookings, with `meetings[i] = [starti, endi]` denoting a booking that occupies the half-open span `[starti, endi)` (it includes `starti` and excludes `endi`). Every `starti` value occurs only once.\n\nBookings occupy rooms according to these rules:\n1. A booking goes to the currently free room with the smallest label.\n2. When every room is occupied, the booking waits until some room is released; the postponed booking keeps its original length.\n3. Whenever a room is released, it is offered to the waiting booking whose original `starti` is earliest.\n\nCount how many bookings each room hosts, and output the label of the room with the highest count. Break ties toward the smaller label.\n\n**Constraints:**\n- `1 <= n <= 100`\n- `1 <= meetings.length <= 10^5`\n- `meetings[i].length == 2`\n- `0 <= starti < endi <= 5 * 10^5`\n- All the values of `starti` are unique\n", "solution": "## Approach\n\nSort meetings by start. Maintain free rooms (min-heap by id) and busy rooms (min-heap by end time). Assign the lowest free room, or delay until the earliest busy room frees.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m log m + m log n)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\nclass Solution:\n def mostBooked(self, n: int, meetings: List[List[int]]) -> int:\n meetings = sorted(meetings)\n free = list(range(n))\n heapq.heapify(free)\n busy = [] # (end, room)\n count = [0] * n\n for start, end in meetings:\n while busy and busy[0][0] <= start:\n _, r = heapq.heappop(busy)\n heapq.heappush(free, r)\n dur = end - start\n if free:\n r = heapq.heappop(free)\n heapq.heappush(busy, (start + dur, r))\n else:\n t, r = heapq.heappop(busy)\n heapq.heappush(busy, (t + dur, r))\n count[r] += 1\n return max(range(n), key=lambda i: (count[i], -i))\n```\n", "starter": {"go": "package main\n\nfunc MostBooked(n int, meetings [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def mostBooked(self, n: int, meetings: List[List[int]]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int mostBooked(int n, vector<vector<int>>& meetings) {\n return 0;\n }\n};"}, "fn": "mostBooked", "params": [{"name": "n", "type": "int"}, {"name": "meetings", "type": "int_array_2d"}], "outputType": "int", "tests": [["2", "[[0,10],[1,5],[2,7],[3,4]]"], ["3", "[[1,20],[2,10],[3,5],[4,9],[6,8]]"], ["1", "[[0,5],[5,10]]"], ["2", "[[0,5],[1,2],[2,3]]"], ["4", "[[0,1],[1,2],[2,3],[3,4]]"], ["2", "[[10,20],[1,5],[2,7],[3,4]]"], ["3", "[[0,10],[1,5],[2,7],[3,4],[8,12]]"], ["2", "[[0,100],[1,2],[2,3],[3,4],[4,5]]"], ["1", "[[2,5],[6,9]]"], ["2", "[[0,3],[1,4],[4,6]]"], ["3", "[[0,2],[1,3],[2,4],[3,5]]"], ["2", "[[5,10],[0,2],[3,4]]"], ["1", "[[0,10],[10,20],[20,30]]"], ["3", "[[0,5],[1,2],[2,3],[3,4],[4,5]]"], ["2", "[[0,4],[1,2],[5,6],[2,5]]"], ["4", "[[0,3],[1,4],[2,5],[3,6]]"], ["2", "[[0,2],[3,5],[1,6],[7,8]]"], ["3", "[[5,9],[0,4],[6,10]]"], ["1", "[[1,3],[4,6],[7,9]]"], ["2", "[[0,10],[5,6],[6,7],[7,8]]"], ["5", "[[0,1],[2,3],[4,5]]"], ["2", "[[3,8],[0,2],[5,6]]"], ["3", "[[0,6],[1,2],[4,5],[2,3]]"], ["2", "[[0,5],[6,10],[1,3],[7,9]]"], ["3", "[[10,15],[0,5],[6,9]]"], ["2", "[[1,4],[2,3],[5,7]]"], ["4", "[[0,5],[1,3],[6,8],[2,4]]"], ["1", "[[5,8]]"], ["2", "[[0,6],[2,4],[4,8]]"], ["3", "[[0,3],[4,7],[1,5],[8,10]]"]], "expected": [0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "38", "slug": "meeting-rooms", "id": 38, "title": "Meeting Rooms", "difficulty": "Easy", "category": "interval", "link": "https://leetcode.com/problems/meeting-rooms/", "examples": [{"input": "intervals = [[0,30],[5,10],[15,20]]", "output": "false", "explanation": "Intervals [0,30] overlaps with [5,10] and [15,20], so not all meetings can fit in one room."}, {"input": "intervals = [[7,10],[2,4]]", "output": "true", "explanation": "Intervals [7,10] and [2,4] do not overlap, so one room suffices."}], "hints": ["Sort intervals by start time and check adjacent pairs: if intervals[i].start < intervals[i-1].end then there's a conflict.", "Alternatively, sort starts and ends separately and sweep with two pointers to detect overlaps.", "Empty or single interval inputs are always attendable."], "statement": "Determine if a person could attend all meetings given start-end intervals.\n\nTwo intervals that only touch at an endpoint are **not** considered overlapping: for interval `i` appearing before interval `j`, `intervals[i].end == intervals[j].start` does not cause overlap (only when `intervals[i].end > intervals[j].start`).\n\n**Constraints:**\n\n- 0 <= intervals.length <= 10^4\n- intervals[i].length == 2\n- 0 <= starti < endi <= 10^6\n", "solution": "## Approach\nSort intervals by start time, then iterate through them checking if any meeting overlaps with the previous one (i.e., the current start is before the previous end). If any overlap is found, return `false`.\n\n## Complexity Analysis\n- **Time Complexity:** O(n log n)\n- **Space Complexity:** O(1)\n\n## Implementation\n```python\nfrom typing import List\nclass Solution:\n def canAttendMeetings(self, intervals: List[List[int]]) -> bool:\n intervals.sort(key=lambda x: x[0])\n for i in range(1, len(intervals)):\n if intervals[i][0] < intervals[i - 1][1]:\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc CanAttendMeetings(intervals [][]int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def canAttendMeetings(self, intervals: List[List[int]]) -> bool:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool canAttendMeetings(vector<vector<int>>& intervals) {\n return true;\n }\n};"}, "fn": "canAttendMeetings", "params": [{"name": "intervals", "type": "int_array_2d"}], "outputType": "boolean", "tests": [["[[0,30],[5,10],[15,20]]"], ["[[7,10],[2,4]]"], ["[]"], ["[[1,5]]"], ["[[1,5],[5,6]]"], ["[[1,5],[4,6]]"], ["[[0,5],[5,10],[10,15]]"], ["[[1,2],[3,4],[5,6]]"], ["[[1,10],[2,3],[4,5]]"], ["[[2,4],[2,4]]"], ["[[0,1],[1,2],[2,3],[3,4]]"], ["[[5,8],[1,3],[3,5]]"], ["[[5,8],[1,6]]"], ["[[10,20]]"], ["[[0,100],[10,20],[30,40]]"], ["[[1,3],[3,5],[5,7],[7,9]]"], ["[[1,3],[2,4],[3,5]]"], ["[[0,2],[2,4],[4,6],[6,8],[8,10]]"], ["[[0,10],[10,20],[5,15]]"], ["[[100,200],[300,400]]"], ["[[1,100],[2,3]]"], ["[[4,9],[9,12],[1,4]]"], ["[[4,9],[8,12],[1,4]]"], ["[[0,5],[6,10],[5,6]]"], ["[[0,5],[4,6],[6,10]]"], ["[[13,17],[2,6],[6,13]]"], ["[[13,17],[2,6],[5,13]]"], ["[[1,2],[2,3],[3,4],[4,5],[5,6],[1,6]]"], ["[[7,9],[1,2],[3,5],[5,7]]"], ["[[0,30],[31,60],[15,31]]"]], "expected": [false, true, true, true, true, false, true, true, false, false, true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, false, true, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "36", "slug": "merge-intervals", "id": 36, "title": "Merge Intervals", "difficulty": "Medium", "category": "interval", "link": "https://leetcode.com/problems/merge-intervals/", "examples": [{"input": "intervals = [[1,3],[2,6],[8,10],[15,18]]", "output": "[[1,6],[8,10],[15,18]]", "explanation": "Intervals [1,3] and [2,6] overlap (2 \u2264 3), so they merge to [1,6]; [8,10] and [15,18] are disjoint."}, {"input": "intervals = [[1,4],[4,5]]", "output": "[[1,5]]", "explanation": "Intervals [1,4] and [4,5] touch (4 \u2264 4), so they merge to [1,5]."}], "hints": ["Sort intervals by start time first.", "Maintain a current merged interval [s, e]; for each interval [a, b], if a <= e, merge by setting e = max(e, b), otherwise push [s, e] and start a new one.", "The sort dominates the complexity: O(n log n).", "Watch out for touching intervals like [1,4] and [4,5] \u2014 they should be merged."], "statement": "Merge all overlapping intervals and return the resulting non-overlapping intervals covering the same ranges.\n\n**Constraints:**\n\n- 1 \u2264 intervals.length \u2264 10^4\n- intervals[i].length == 2\n- 0 \u2264 starti \u2264 endi \u2264 10^4\n", "solution": "## Approach\nSort intervals by start time, then iterate through them. If the result list is empty or the current interval does not overlap with the last merged interval, append it. Otherwise, merge by extending the end of the last interval.\n\n## Complexity Analysis\n- **Time Complexity:** O(n log n)\n- **Space Complexity:** O(n)\n\n## Implementation\n```python\nfrom typing import List\nclass Solution:\n def merge(self, intervals: List[List[int]]) -> List[List[int]]:\n intervals.sort(key=lambda x: x[0])\n res = []\n for iv in intervals:\n if not res or res[-1][1] < iv[0]:\n res.append(iv)\n else:\n res[-1][1] = max(res[-1][1], iv[1])\n return res\n```\n", "starter": {"go": "package main\n\nfunc Merge(intervals [][]int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def merge(self, intervals: List[List[int]]) -> List[List[int]]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> merge(vector<vector<int>>& intervals) {\n return {};\n }\n};"}, "fn": "merge", "params": [{"name": "intervals", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[1,3],[2,6],[8,10],[15,18]]"], ["[[1,4],[4,5]]"], ["[[1,4],[0,2],[3,5]]"], ["[[1,4],[5,6]]"], ["[[1,10],[2,3],[4,5],[6,7],[8,9]]"], ["[[1,2]]"], ["[[1,4],[2,3]]"], ["[[2,3],[4,5],[6,7]]"], ["[[1,5],[2,3]]"], ["[[5,7],[1,3]]"], ["[[1,2],[3,4],[2,3]]"], ["[[10,12],[0,2],[3,6]]"], ["[[1,100],[10,20],[30,40]]"], ["[[0,0],[1,1]]"], ["[[3,5],[3,5]]"], ["[[6,8],[1,2],[3,4],[9,10]]"], ["[[2,4],[6,8],[1,10]]"], ["[[0,5],[5,10],[10,15]]"], ["[[7,9],[7,9],[7,9]]"], ["[[1,3],[5,7],[2,6]]"], ["[[20,25],[0,5],[10,15],[5,10]]"], ["[[4,6],[1,3],[7,9],[2,5]]"], ["[[0,10],[0,10]]"], ["[[9,12],[4,8],[1,3]]"], ["[[2,5],[6,9],[1,3],[10,12]]"], ["[[5,6],[1,2],[3,4]]"], ["[[0,4],[1,2],[5,9],[8,10]]"], ["[[3,4],[1,2],[5,6],[7,8]]"], ["[[15,20],[5,10],[0,3],[8,12]]"], ["[[2,10],[3,5],[6,7]]"]], "expected": [[[1, 6], [8, 10], [15, 18]], [[1, 5]], [[0, 5]], [[1, 4], [5, 6]], [[1, 10]], [[1, 2]], [[1, 4]], [[2, 3], [4, 5], [6, 7]], [[1, 5]], [[1, 3], [5, 7]], [[1, 4]], [[0, 2], [3, 6], [10, 12]], [[1, 100]], [[0, 0], [1, 1]], [[3, 5]], [[1, 2], [3, 4], [6, 8], [9, 10]], [[1, 10]], [[0, 15]], [[7, 9]], [[1, 7]], [[0, 15], [20, 25]], [[1, 6], [7, 9]], [[0, 10]], [[1, 3], [4, 8], [9, 12]], [[1, 5], [6, 9], [10, 12]], [[1, 2], [3, 4], [5, 6]], [[0, 4], [5, 10]], [[1, 2], [3, 4], [5, 6], [7, 8]], [[0, 3], [5, 12], [15, 20]], [[2, 10]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "43", "slug": "merge-k-sorted-lists", "id": 43, "title": "Merge K Sorted Lists", "difficulty": "Hard", "category": "linked-list", "link": "https://leetcode.com/problems/merge-k-sorted-lists/", "examples": [{"input": "lists = [[1,4,5],[1,3,4],[2,6]]", "output": "[1,1,2,3,4,4,5,6]", "explanation": "All lists [[1,4,5],[1,3,4],[2,6]] are merged into one sorted list: [1,1,2,3,4,4,5,6]."}, {"input": "lists = []", "output": "[]", "explanation": "No lists to merge; the result is empty."}, {"input": "lists = [[]]", "output": "[]", "explanation": "The only list is empty, so the result is empty."}], "hints": ["Use a min-heap (priority queue) of size k to always extract the smallest head; push the next node from the extracted list. Time: O(N log k).", "Alternatively, merge lists in a divide-and-conquer fashion (pairwise merge like merge sort). Time: O(N log k), Space: O(1) extra (if iterative).", "Re-use existing nodes by rewiring next pointers; you don't need to allocate new nodes.", "Edge cases: empty array, lists containing null heads, and lists with only one element."], "statement": "You receive `k` linked lists, each already ordered increasingly. Weave all of their nodes into a single linked list that remains ordered increasingly, and return its head.\n\n**Constraints:**\n\n- k == lists.length\n- 0 \u2264 k \u2264 10^4\n- 0 \u2264 lists[i].length \u2264 500\n- -10^4 \u2264 lists[i][j] \u2264 10^4\n- lists[i] is sorted in ascending order.\n- The sum of lists[i].length will not exceed 10^4.\n", "solution": "## Approach\nUse a min-heap to store the head of each non-empty linked list. Repeatedly pop the smallest node, append it to the result, and push its next node back into the heap. Continue until the heap is empty.\n\n## Complexity Analysis\n- **Time Complexity:** O(n log k)\n- **Space Complexity:** O(k)\n\n## Implementation\n```python\nfrom typing import List, Optional\nimport heapq\nclass Solution:\n def mergeKLists(self, lists: List[Optional[ListNode]]) -> Optional[ListNode]:\n heap = []\n for i, node in enumerate(lists):\n if node:\n heapq.heappush(heap, (node.val, i, node))\n dummy = ListNode(0)\n cur = dummy\n while heap:\n val, i, node = heapq.heappop(heap)\n cur.next = node\n cur = cur.next\n if node.next:\n heapq.heappush(heap, (node.next.val, i, node.next))\n return dummy.next\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc MergeKLists(lists []*ListNode) *ListNode {\n \n}", "python": "# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def mergeKLists(self, lists):\n pass\n", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n ListNode* mergeKLists(vector<ListNode*>& lists) {\n return nullptr;\n }\n};\n"}, "fn": "mergeKLists", "params": [{"name": "lists", "type": "list_node_array"}], "outputType": "list_node", "tests": [["[[1,4,5],[1,3,4],[2,6]]"], ["[]"], ["[[]]"], ["[[1],[1,2,3]]"], ["[[1,1,1],[1,1]]"], ["[[1,2,3]]"], ["[[2],[1]]"], ["[[-3,-1,2],[0,5]]"], ["[[],[1,2]]"], ["[[5,10,15],[1,2],[3,4,5,6]]"], ["[[-5,-5,-5]]"], ["[[1,1,2,3,5,8]]"], ["[[0],[0],[0]]"], ["[[-10,-5,0,5,10]]"], ["[[3,7],[1,9],[2,8],[0,4]]"], ["[[1,2],[3,4],[5,6]]"], ["[[10,20],[5,15],[1,30]]"], ["[[-2,0,2],[-1,1,3]]"], ["[[7]]"], ["[[-1],[0],[1]]"], ["[[2,2,2],[3,3,3]]"], ["[[1,5],[2,6],[3,7],[4,8]]"], ["[[-4,-2],[0,2],[4,6]]"], ["[[100,200,300]]"], ["[[1,3],[2],[4,5,6,7]]"], ["[[-1,0,1],[2,3,4]]"], ["[[9,9],[1,1],[5,5]]"], ["[[0,1],[0,1],[0,1]]"], ["[[-8,-3,1],[2,4],[6]]"], ["[[4,8,12,16],[1,2,3]]"]], "expected": [[1, 1, 2, 3, 4, 4, 5, 6], null, null, [1, 1, 2, 3], [1, 1, 1, 1, 1], [1, 2, 3], [1, 2], [-3, -1, 0, 2, 5], [1, 2], [1, 2, 3, 4, 5, 5, 6, 10, 15], [-5, -5, -5], [1, 1, 2, 3, 5, 8], [0, 0, 0], [-10, -5, 0, 5, 10], [0, 1, 2, 3, 4, 7, 8, 9], [1, 2, 3, 4, 5, 6], [1, 5, 10, 15, 20, 30], [-2, -1, 0, 1, 2, 3], [7], [-1, 0, 1], [2, 2, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7, 8], [-4, -2, 0, 2, 4, 6], [100, 200, 300], [1, 2, 3, 4, 5, 6, 7], [-1, 0, 1, 2, 3, 4], [1, 1, 5, 5, 9, 9], [0, 0, 0, 1, 1, 1], [-8, -3, 1, 2, 4, 6], [1, 2, 3, 4, 8, 12, 16]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "168", "slug": "merge-sorted-array", "id": 168, "title": "Merge Sorted Array", "difficulty": "Easy", "category": "two-pointer", "link": "https://leetcode.com/problems/merge-sorted-array/", "examples": [{"input": "nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3", "output": "[1,2,2,3,5,6]", "explanation": "The arrays to merge are [1,2,3] and [2,5,6]; the merged sorted array is [1,2,2,3,5,6]."}, {"input": "nums1 = [1], m = 1, nums2 = [], n = 0", "output": "[1]", "explanation": "The arrays to merge are [1] and []; the merged sorted array is [1]."}, {"input": "nums1 = [0], m = 0, nums2 = [1], n = 1", "output": "[1]", "explanation": "The arrays to merge are [] and [1]; the merged sorted array is [1]."}], "hints": ["Merge from the back of nums1, comparing the largest remaining elements of each array.", "When one array is exhausted, copy the remaining elements of the other array."], "statement": "Two integer arrays `nums1` and `nums2` are provided in non-decreasing order, together with integers `m` and `n` stating how many meaningful entries each one contributes.\n\nThe array `nums1` has total capacity `m + n`: its leading `m` positions contain the values to keep, while its trailing `n` positions are placeholders filled with `0` and carry no information. The array `nums2` holds exactly `n` values.\n\nCombine the `m` kept values of `nums1` with the `n` values of `nums2` into one collection ordered from smallest to largest, and return that combined array.\n\n**Constraints:**\n\n- nums1.length == m + n\n- nums2.length == n\n- 0 \u2264 m, n \u2264 200\n- 1 \u2264 m + n \u2264 200\n- -10^9 \u2264 nums1[i], nums2[j] \u2264 10^9\n", "solution": "## Approach\n\nMerge from the back of `nums1` (or with a new result array): compare the largest remaining elements of the first `m` entries of `nums1` and the first `n` entries of `nums2`, placing the larger one at the end of the result and moving the corresponding pointer. When one side is exhausted, copy the remainder of the other side.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m + n). Each element is visited once.\n- **Space Complexity:** O(m + n) for the returned array (O(1) extra if merging in place from the back).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> List[int]:\n a = nums1[:m]\n b = nums2[:n]\n i = j = 0\n res = []\n while i < m and j < n:\n if a[i] <= b[j]:\n res.append(a[i]); i += 1\n else:\n res.append(b[j]); j += 1\n res.extend(a[i:])\n res.extend(b[j:])\n return res\n```\n", "starter": {"go": "package main\n\nfunc Merge(nums1 []int, m int, nums2 []int, n int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {\n return {};\n }\n};"}, "fn": "merge", "params": [{"name": "nums1", "type": "int_array"}, {"name": "m", "type": "int"}, {"name": "nums2", "type": "int_array"}, {"name": "n", "type": "int"}], "outputType": "int_array", "tests": [["[1,2,3,0,0,0]", "3", "[2,5,6]", "3"], ["[1]", "1", "[]", "0"], ["[0]", "0", "[1]", "1"], ["[4,5,6,0,0,0]", "3", "[1,2,3]", "3"], ["[1,2,0,0,0]", "2", "[2,5,6]", "3"], ["[-5,-3,0,0,0]", "2", "[-4,-1,2]", "3"], ["[2,0]", "1", "[1]", "1"], ["[0,0,0,0,0]", "0", "[-2,-1,0,1,2]", "5"], ["[1,2,3,4,5]", "5", "[]", "0"], ["[1,3,5,0,0,0]", "3", "[2,4,6]", "3"], ["[-1,0,0,3,3,3,0,0,0]", "6", "[1,2,2]", "3"], ["[4,0,0,0,0,0]", "1", "[1,2,3,5,6]", "5"], ["[2,4,6,0,0]", "3", "[1,3]", "2"], ["[1,2,3,0]", "3", "[4]", "1"], ["[4,5,0]", "2", "[1]", "1"], ["[0,0]", "0", "[0,0]", "2"], ["[1,1,0,0]", "2", "[1,1]", "2"], ["[3,0,0]", "1", "[1,2]", "2"], ["[-3,-2,-1,0,0,0]", "3", "[0,0,1]", "3"], ["[5,0]", "1", "[2]", "1"], ["[1,4,0,0,0,0]", "2", "[2,3,5,6]", "4"], ["[0,0,0]", "0", "[1,2,3]", "3"], ["[7,8,9]", "3", "[]", "0"], ["[2,2,2,0,0,0]", "3", "[2,2,2]", "3"], ["[-10,0,10,0,0]", "3", "[-5,5]", "2"], ["[6,0,0,0]", "1", "[2,4,8]", "3"], ["[1,5,9,0]", "3", "[3]", "1"], ["[5]", "1", "[]", "0"], ["[-2,0]", "1", "[-1]", "1"], ["[3,7,0,0]", "2", "[4,8]", "2"]], "expected": [[1, 2, 2, 3, 5, 6], [1], [1], [1, 2, 3, 4, 5, 6], [1, 2, 2, 5, 6], [-5, -4, -3, -1, 2], [1, 2], [-2, -1, 0, 1, 2], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6], [-1, 0, 0, 1, 2, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 6], [1, 2, 3, 4], [1, 4, 5], [0, 0], [1, 1, 1, 1], [1, 2, 3], [-3, -2, -1, 0, 0, 1], [2, 5], [1, 2, 3, 4, 5, 6], [1, 2, 3], [7, 8, 9], [2, 2, 2, 2, 2, 2], [-10, -5, 0, 5, 10], [2, 4, 6, 8], [1, 3, 5, 9], [5], [-2, -1], [3, 4, 7, 8]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "167", "slug": "merge-strings-alternately", "id": 167, "title": "Merge Strings Alternately", "difficulty": "Easy", "category": "two-pointer", "link": "https://leetcode.com/problems/merge-strings-alternately/", "examples": [{"input": "word1 = \"abc\", word2 = \"pqr\"", "output": "\"apbqcr\"", "explanation": "The merged string is \"apbqcr\"."}, {"input": "word1 = \"ab\", word2 = \"pqrs\"", "output": "\"apbqrs\"", "explanation": "As word2 is longer, \"rs\" is appended to the end."}, {"input": "word1 = \"abcd\", word2 = \"pq\"", "output": "\"apbqcd\"", "explanation": "As word1 is longer, \"cd\" is appended to the end."}], "hints": ["Use two pointers, one for each string, and alternately append characters.", "When one pointer reaches the end, append the remainder of the other string."], "statement": "Two strings `word1` and `word2` are provided. Construct a new string by taking characters in turn, beginning with the first character of `word1`, then the first character of `word2`, then the second character of `word1`, and so on. Once the shorter input runs out, attach whatever remains of the longer input to the tail of the result.\n\nOutput the string built this way.\n\n**Constraints:**\n\n- 1 \u2264 word1.length, word2.length \u2264 100\n- word1 and word2 consist of lowercase English letters.\n", "solution": "## Approach\n\nUse two pointers `i` for `word1` and `j` for `word2`. Alternately append one character from each string while either pointer is in range. When one string is exhausted, append the remainder of the other string.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + m), where n and m are the lengths of the two strings.\n- **Space Complexity:** O(n + m) for the merged result.\n\n## Implementation\n\n```python\nclass Solution:\n def mergeAlternately(self, word1: str, word2: str) -> str:\n res = []\n i = j = 0\n while i < len(word1) or j < len(word2):\n if i < len(word1):\n res.append(word1[i])\n i += 1\n if j < len(word2):\n res.append(word2[j])\n j += 1\n return \"\".join(res)\n```\n", "starter": {"go": "package main\n\nfunc MergeAlternately(word1 string, word2 string) string {\n return \"\"\n}", "python": "class Solution:\n def mergeAlternately(self, word1: str, word2: str) -> str:\n return \"\"\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n return \"\";\n }\n};"}, "fn": "mergeAlternately", "params": [{"name": "word1", "type": "string"}, {"name": "word2", "type": "string"}], "outputType": "string", "tests": [["abc", "pqr"], ["ab", "pqrs"], ["abcd", "pq"], ["a", "b"], ["ab", "cd"], ["a", "bcdef"], ["abcde", "f"], ["xyz", "xyz"], ["hello", "world"], ["a", "a"], ["abcdefghij", "klm"], ["q", "wertyuiop"], ["b", "cd"], ["ab", "c"], ["z", "a"], ["aaa", "bbb"], ["mn", "opqrst"], ["uvw", "xy"], ["abc", "abc"], ["p", "qrs"], ["rst", "p"], ["long", "short"], ["cat", "dog"], ["abcd", "efgh"], ["x", "yz"], ["lmno", "pqrs"], ["test", "case"], ["foo", "barbaz"], ["j", "k"], ["code", "go"]], "expected": ["apbqcr", "apbqrs", "apbqcd", "ab", "acbd", "abcdef", "afbcde", "xxyyzz", "hweolrllod", "aa", "akblcmdefghij", "qwertyuiop", "bcd", "acb", "za", "ababab", "monpqrst", "uxvyw", "aabbcc", "pqrs", "rpst", "lsohnogrt", "cdaotg", "aebfcgdh", "xyz", "lpmqnros", "tceasste", "fboaorbaz", "jk", "cgoode"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "142", "slug": "merge-triplets-to-form-target-triplet", "id": 142, "title": "Merge Triplets to Form Target Triplet", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/merge-triplets-to-form-target-triplet/", "examples": [{"input": "triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]", "output": "true", "explanation": "The first and third rows merge to the target; the row exceeding the target is ignored."}, {"input": "triplets = [[3,4,5],[4,5,6]], target = [3,2,5]", "output": "false", "explanation": "The target triplet cannot be formed by merging."}, {"input": "triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]", "output": "true", "explanation": "The target [5,5,5] is achievable from the given triplets."}], "hints": ["Any row with a coordinate greater than the corresponding target coordinate can never be used, because maxima cannot decrease.", "Among the remaining rows, record which target coordinates can be matched exactly.", "The target is possible exactly when all three coordinates are matched by safe rows."], "statement": "A triplet is an array of three positive integers. You are given `triplets` and a positive target triplet `target`.\n\nYou may repeatedly choose two different triplets and replace one of them with their element-wise maximum. Return `true` if some sequence of operations can produce `target`; otherwise, return `false`.\n\nEquivalently, you may choose a subset of the input rows whose element-wise maximum is exactly `target`.\n\n**Constraints:**\n\n- `1 <= triplets.length <= 100000`\n- `triplets[i].length == 3`\n- `target.length == 3`\n- `1 <= triplets[i][j], target[j] <= 1000`\n", "solution": "## Approach\n\nIgnore any triplet with a coordinate greater than the corresponding target coordinate, because element-wise maximum operations can never reduce that value. Every remaining triplet is safe to merge. Record which of the three target coordinates are matched exactly by safe triplets; the target is reachable if and only if all three coordinates are matched.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), because each triplet has exactly three coordinates.\n- **Space Complexity:** O(1) auxiliary space.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:\n matched = [False, False, False]\n for triplet in triplets:\n if any(triplet[index] > target[index] for index in range(3)):\n continue\n for index in range(3):\n matched[index] |= triplet[index] == target[index]\n return all(matched)\n```\n", "starter": {"go": "package main\n\nfunc MergeTriplets(triplets [][]int, target []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool mergeTriplets(vector<vector<int>>& triplets, vector<int>& target) {\n return false;\n }\n};"}, "fn": "mergeTriplets", "params": [{"name": "triplets", "type": "int_array_2d"}, {"name": "target", "type": "int_array"}], "outputType": "boolean", "tests": [["[[2,5,3],[1,8,4],[1,7,5]]", "[2,7,5]"], ["[[3,4,5],[4,5,6]]", "[3,2,5]"], ["[[2,5,3],[2,3,4],[1,2,5],[5,2,3]]", "[5,5,5]"], ["[[1,2,3]]", "[1,2,3]"], ["[[1,1,1]]", "[2,2,2]"], ["[[3,1,1]]", "[2,2,2]"], ["[[5,1,1],[1,5,1],[1,1,5]]", "[5,5,5]"], ["[[6,1,1],[1,6,1],[1,1,6]]", "[5,5,5]"], ["[[2,2,2],[2,2,2]]", "[2,2,2]"], ["[[1,1,1],[2,1,1],[1,2,1],[1,1,2]]", "[2,2,2]"], ["[[2,3,1],[1,2,3]]", "[2,3,3]"], ["[[2,4,1],[1,2,3]]", "[2,3,3]"], ["[[4,2,3],[3,5,2],[2,1,6]]", "[4,5,6]"], ["[[4,6,3],[3,5,2],[2,1,6]]", "[4,5,6]"], ["[[10,1,1],[1,10,1],[1,1,10],[9,9,9]]", "[10,10,10]"], ["[[9,10,10],[10,9,10],[10,10,9]]", "[10,10,10]"], ["[[9,9,9],[8,8,8]]", "[10,10,10]"], ["[[1,2,1],[2,1,1],[1,1,2],[3,3,3]]", "[2,2,2]"], ["[[7,3,4],[6,8,4],[6,3,9]]", "[7,8,9]"], ["[[7,9,4],[6,8,4],[6,3,9]]", "[7,8,9]"], ["[[3,3,3],[1,3,2],[3,2,1]]", "[3,3,3]"], ["[[3,4,3],[3,3,4]]", "[3,3,3]"], ["[[1,4,2],[2,3,5],[6,2,1]]", "[6,4,5]"], ["[[1,4,6],[2,3,5],[6,2,1]]", "[6,4,5]"], ["[[8,1,2],[7,9,2],[7,1,10]]", "[8,9,10]"], ["[[8,10,2],[7,9,2],[7,1,10]]", "[8,9,10]"], ["[[1,1,4],[1,4,1],[4,1,1],[2,2,2]]", "[4,4,4]"], ["[[1,1,4],[1,4,1],[3,1,1]]", "[4,4,4]"], ["[[100,1,1],[1,100,1],[1,1,100]]", "[100,100,100]"], ["[[100,101,1],[1,100,1],[1,1,100]]", "[100,100,100]"], ["[[2,6,4],[5,3,4],[5,6,1]]", "[5,6,4]"], ["[[2,6,5],[5,3,4],[5,6,1]]", "[5,6,4]"], ["[[1,7,3],[9,2,3],[2,2,8]]", "[9,7,8]"], ["[[1,7,9],[9,2,3],[2,2,8]]", "[9,7,8]"], ["[[3,1,5],[2,4,5],[3,4,2]]", "[3,4,5]"], ["[[4,1,5],[2,4,5],[3,4,2]]", "[3,4,5]"], ["[[6,6,1],[6,1,6],[1,6,6]]", "[6,6,6]"], ["[[6,7,1],[6,1,6],[1,6,6]]", "[6,6,6]"], ["[[2,2,7],[2,7,2],[7,2,2],[7,7,7]]", "[7,7,7]"], ["[[2,2,8],[2,7,2],[7,2,2]]", "[7,7,7]"], ["[[4,5,1],[4,1,5],[1,5,5]]", "[4,5,5]"], ["[[4,6,1],[4,1,5],[1,5,5]]", "[4,5,5]"], ["[[11,2,3],[4,12,3],[4,2,13]]", "[11,12,13]"], ["[[11,2,14],[4,12,3],[4,2,13]]", "[11,12,13]"], ["[[1,9,2],[8,1,2],[3,4,7]]", "[8,9,7]"], ["[[1,9,8],[8,1,2],[3,4,7]]", "[8,9,7]"], ["[[5,2,9],[1,8,9],[5,8,3]]", "[5,8,9]"], ["[[6,2,9],[1,8,9],[5,8,3]]", "[5,8,9]"], ["[[2,10,1],[9,3,1],[9,10,6]]", "[9,10,6]"], ["[[2,10,7],[9,3,1],[8,10,6]]", "[9,10,6]"], ["[[3,7,4],[6,2,4],[6,7,1],[2,5,8]]", "[6,7,8]"], ["[[3,7,9],[6,2,4],[6,7,1],[2,5,8]]", "[6,7,8]"], ["[[1,1,1],[2,2,2],[3,3,3],[4,4,4]]", "[4,4,4]"], ["[[1,2,3],[3,2,1],[2,3,2]]", "[3,3,3]"], ["[[1,2,4],[3,2,1],[2,3,2]]", "[3,3,3]"], ["[[1,1,1]]", "[1,1,1]"], ["[[1000,1,1],[1,1000,1],[1,1,1000]]", "[1000,1000,1000]"], ["@javascript:Array.from({length:50000},(_,i)=>i===49999?[1000,1000,1000]:[1,1,1])", "[1000,1000,1000]"]], "expected": [true, false, true, true, false, false, true, false, true, true, true, false, true, false, true, true, false, true, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, false, true, true, true, true, true, false, true, true, true, false, true, false, true, true, true, true, true, true, true, true, false, true, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "646", "slug": "merge-two-binary-trees", "id": 646, "title": "Merge Two Binary Trees", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/merge-two-binary-trees/", "examples": [{"input": "root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7]", "output": "[3,4,5,5,4,null,7]", "explanation": "Overlapping values add (1+2=3, 3+1=4, 2+3=5); lone subtrees are kept as-is."}, {"input": "root1 = [1], root2 = [1,2]", "output": "[2,2]", "explanation": "Roots add to 2; the extra left child 2 is carried over."}, {"input": "root1 = [], root2 = []", "output": "[]", "explanation": "Two empty trees merge to empty."}], "hints": ["Handle the empty cases first: missing on one side means returning the other side.", "Otherwise add the two values and recurse on the left pair and the right pair.", "Build fresh nodes (or reuse carefully) so the checker comparing shapes sees the summed tree."], "statement": "You are given the roots of two binary trees. Overlay them into one tree by the following rule applied at every overlapping position:\n\n- When both nodes exist, the new value is their sum.\n- When only one side exists, that whole subtree is kept unchanged.\n- When neither exists, nothing is placed.\n\nRecurse the same way on left children and on right children, then return the root of the combined tree.\n\n**Constraints:**\n- Each tree holds between 0 and 2000 nodes.\n- Values stay within a small integer range; sums fit in a 32-bit signed integer.\n", "solution": "## Approach\n\nRecurse on node pairs. Empty on both sides yields empty; empty on one side yields a copy of the other side; otherwise create a node holding the summed value whose left is the merge of the left pair and whose right is the merge of the right pair. Copying rather than mutating keeps the inputs intact for the checker.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the total nodes across both trees (each pair visited once).\n- **Space Complexity:** O(m) for the new tree plus recursion depth.\n\n## Implementation\n\n```python\nclass Solution:\n def mergeTrees(self, root1, root2):\n if root1 is None:\n return root2\n if root2 is None:\n return root1\n root1.val += root2.val\n root1.left = self.mergeTrees(root1.left, root2.left)\n root1.right = self.mergeTrees(root1.right, root2.right)\n return root1\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc MergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def mergeTrees(self, root1, root2):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* mergeTrees(TreeNode* root1, TreeNode* root2) {\n \n }\n};"}, "fn": "mergeTrees", "params": [{"name": "root1", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "root2", "type": "tree_node"}], "outputType": "tree_node", "tests": [["[1,3,2,5]", "[2,1,3,null,4,null,7]"], ["[1]", "[1,2]"], ["[]", "[]"], ["[1]", "[]"], ["[]", "[1]"], ["[1,2,3]", "[1,2,3]"], ["[5]", "[5]"], ["[1,2,null,3]", "[1,null,2,null,3]"], ["[0]", "[0]"], ["[-1,-2]", "[1,2]"], ["[1,null,2]", "[2,1,null]"], ["[3,4,5]", "[1,2]"], ["[1,2,3,4,5]", "[5,4,3,2,1]"], ["[10]", "[20,30,40]"], ["[1,2]", "[1,null,2]"], ["[7,7,7]", "[7,7,7]"], ["[1,null,2,null,3]", "[1,2,3]"], ["[2]", "[3,4,5]"], ["[1000]", "[-1000]"], ["[1,3,null,5]", "[2,1,3,null,4,null,7]"], ["[4,2,7]", "[4,2,7]"], ["[1,2,3,null,null,4,5]", "[1]"], ["[]", "[1,2,3]"], ["[1,2,3]", "[]"], ["[5,3,8,1,4]", "[2,1,6,null,3]"], ["[1,2,null,3,null,4]", "[1,2,null,3]"], ["[9]", "[9,9,9,9]"], ["[6,5,4,3,2,1]", "[1,2,3,4,5,6]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "42", "slug": "merge-two-sorted-lists", "id": 42, "title": "Merge Two Sorted Lists", "difficulty": "Easy", "category": "linked-list", "link": "https://leetcode.com/problems/merge-two-sorted-lists/", "examples": [{"input": "list1 = [1,2,4], list2 = [1,3,4]", "output": "[1,1,2,3,4,4]", "explanation": "Merging the sorted lists [1,2,4] and [1,3,4] produces the sorted list [1,1,2,3,4,4]."}, {"input": "list1 = [], list2 = []", "output": "[]", "explanation": "Merging the sorted lists [] and [] produces the sorted list []."}, {"input": "list1 = [], list2 = [0]", "output": "[0]", "explanation": "Merging the sorted lists [] and [0] produces the sorted list [0]."}], "hints": ["Use a dummy head and a tail pointer; at each step, attach the smaller of list1 or list2 and advance that list.", "When one list runs out, attach the remainder of the other list.", "You can do this iteratively (preferred for O(1) stack) or recursively (clearer but uses call stack).", "Re-use nodes by adjusting next pointers; don't allocate new nodes unless required by the environment."], "statement": "Two singly linked lists `list1` and `list2`, each already arranged from smallest to largest, are given. Interleave their nodes into one list that stays ordered increasingly, and return its head.\n\n**Constraints:**\n\n- The number of nodes in both lists is in the range [0, 50].\n- -100 \u2264 Node.val \u2264 100\n- Both list1 and list2 are sorted in non-decreasing order.\n", "solution": "## Approach\nUse a dummy head to simplify pointer manipulation. Compare the heads of both lists, attach the smaller node to the result, and advance the corresponding pointer. Once one list is exhausted, attach the remainder of the other list.\n\n## Complexity Analysis\n- **Time Complexity:** O(n + m)\n- **Space Complexity:** O(1)\n\n## Implementation\n```python\nfrom typing import Optional\nclass Solution:\n def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:\n dummy = ListNode(0)\n cur = dummy\n while list1 and list2:\n if list1.val <= list2.val:\n cur.next = list1\n list1 = list1.next\n else:\n cur.next = list2\n list2 = list2.next\n cur = cur.next\n cur.next = list1 or list2\n return dummy.next\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc MergeTwoLists(list1 *ListNode, list2 *ListNode) *ListNode {\n \n}", "python": "# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def mergeTwoLists(self, list1, list2):\n pass\n", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {\n return nullptr;\n }\n};\n"}, "fn": "mergeTwoLists", "params": [{"name": "list1", "type": "list_node"}, {"name": "list2", "type": "list_node"}], "outputType": "list_node", "tests": [["[1,2,4]", "[1,3,4]"], ["[]", "[]"], ["[]", "[0]"], ["[2,6,8]", "[1,3,7,9,10]"], ["[1,1,1]", "[1,1]"], ["[0]", "[]"], ["[5]", "[1,2,3]"], ["[-100,-50,0,50,100]", "[-100,-50,0,50,100]"], ["[-5,-3,-1]", "[-4,-2,0]"], ["[1,2,3,4,5]", "[]"], ["[]", "[1,2,3,4,5]"], ["[-1]", "[1]"], ["[1]", "[1]"], ["[-100]", "[100]"], ["[1,3,5,7]", "[2,4,6,8]"], ["[1,2,3]", "[4,5,6]"], ["[4,5,6]", "[1,2,3]"], ["[-3,-2,-1,0,1,2,3]", "[-3,-2,-1,0,1,2,3]"], ["[0,0,0]", "[0,0,0]"], ["[-10,-10,0,10,10]", "[-10,0,10]"], ["[1,5,9]", "[2,3,4,6,7,8,10]"], ["[100]", "[100]"], ["[-100]", "[-100]"], ["[1,2]", "[1,2]"], ["[-5,5]", "[-4,4]"], ["[3]", "[1,2,3,4,5]"], ["[1,10,20,30]", "[5,15,25]"], ["[-2,-1,0]", "[0,1,2]"], ["[7,7,7,7]", "[7]"], ["[-50,-25,0,25,50]", "[-40,-20,20,40]"]], "expected": [[1, 1, 2, 3, 4, 4], null, [0], [1, 2, 3, 6, 7, 8, 9, 10], [1, 1, 1, 1, 1], [0], [1, 2, 3, 5], [-100, -100, -50, -50, 0, 0, 50, 50, 100, 100], [-5, -4, -3, -2, -1, 0], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [-1, 1], [1, 1], [-100, 100], [1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], [-3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3], [0, 0, 0, 0, 0, 0], [-10, -10, -10, 0, 0, 10, 10, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [100, 100], [-100, -100], [1, 1, 2, 2], [-5, -4, 4, 5], [1, 2, 3, 3, 4, 5], [1, 5, 10, 15, 20, 25, 30], [-2, -1, 0, 0, 1, 2], [7, 7, 7, 7, 7], [-50, -40, -25, -20, 0, 20, 25, 40, 50]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "869", "slug": "middle-of-the-linked-list", "id": 869, "title": "Middle of the Linked List", "difficulty": "Easy", "category": "linked-list", "link": "https://leetcode.com/problems/middle-of-the-linked-list/", "examples": [{"input": "head = [1,2,3,4,5]", "output": "[3,4,5]", "explanation": "With five nodes the middle one holds 3, so the list from there on is [3,4,5]."}, {"input": "head = [1,2,3,4,5,6]", "output": "[4,5,6]", "explanation": "With six nodes there are two centers (3 and 4); the second one holds 4, so the answer is [4,5,6]."}], "hints": ["Advance two pointers at different speeds: one moves a single node per step while the other moves two.", "When the fast pointer reaches the end, the slow pointer sits on the middle (and naturally on the second middle for even lengths)."], "statement": "You are given the head of a singly linked list. Walk to the middle of the list and return that node: when the list has an odd number of nodes, return the exact center; when it has an even number, return the second of the two central nodes.\n\n**Constraints:**\n- The list holds between `1` and `100` nodes.\n- `1 <= Node.val <= 100`\n", "solution": "## Approach\n\nSend two pointers down the list together: a slow one advancing one node at a time and a fast one advancing two nodes at a time. Because the fast pointer covers ground twice as quickly, it reaches the end exactly when the slow pointer arrives at the middle. For even-length lists this landing spot is the second of the two central nodes, as required.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. The list is traversed once.\n- **Space Complexity:** O(1); only two pointers are used.\n\n## Implementation\n\n```python\nclass Solution:\n def middleNode(self, head):\n slow = fast = head\n while fast is not None and fast.next is not None:\n slow = slow.next\n fast = fast.next.next\n return slow\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc MiddleNode(head *ListNode) *ListNode {\n return nil\n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def middleNode(self, head):\n pass", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* middleNode(ListNode* head) {\n return nullptr;\n }\n};"}, "fn": "middleNode", "params": [{"name": "head", "type": "list_node"}], "outputType": "list_node", "tests": [["[1,2,3,4,5]"], ["[1,2,3,4,5,6]"], ["[1]"], ["[1,2]"], ["[1,2,3]"], ["[1,2,3,4]"], ["[7]"], ["[1,1,1,1,1]"], ["[1,2,3,4,5,6,7]"], ["[1,2,3,4,5,6,7,8]"], ["[10,20,30,40,50,60,70,80,90]"], ["[5,4,3,2,1]"], ["[1,3,5,7,9,11]"], ["[2,4,6,8,10,12,14,16,18,20]"], ["[99,100]"], ["[1,2,3,4,5,6,7,8,9,10,11]"], ["[3,1,4,1,5,9,2,6]"], ["[1,1,1]"], ["[1,2,3,4,5,6,7,8,9]"], ["[42]"], ["[8,6,7,5,3,0,9]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[11,22]"], ["[5,5,5,5,5,5,5,5,5,5,5,5]"], ["[1,100,2,99,3,98,4]"], ["[7,7,7,7]"], ["[9,8,7,6,5,4,3,2,1,0]"], ["[1,2,3,4,5,6,7,8,9,10,11,12,13]"]], "expected": [[3, 4, 5], [4, 5, 6], [1], [2], [2, 3], [3, 4], [7], [1, 1, 1], [4, 5, 6, 7], [5, 6, 7, 8], [50, 60, 70, 80, 90], [3, 2, 1], [7, 9, 11], [12, 14, 16, 18, 20], [100], [6, 7, 8, 9, 10, 11], [5, 9, 2, 6], [1, 1], [5, 6, 7, 8, 9], [42], [5, 3, 0, 9], [6, 7, 8, 9, 10], [22], [5, 5, 5, 5, 5, 5], [99, 3, 98, 4], [7, 7], [4, 3, 2, 1, 0], [7, 8, 9, 10, 11, 12, 13]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "127", "slug": "min-cost-climbing-stairs", "id": 127, "title": "Min Cost Climbing Stairs", "difficulty": "Easy", "category": "dp", "link": "https://leetcode.com/problems/min-cost-climbing-stairs/", "examples": [{"input": "cost = [10,15,20]", "output": "15", "explanation": "Start on stair 1 and climb two stairs to the top."}, {"input": "cost = [1,100,1,1,1,100,1,1,100,1]", "output": "6", "explanation": "The minimum cost to reach the top with cost array [1,100,1,1,1,100,1,1,100,1] is 6."}], "hints": ["Let the cost to reach a stair depend only on the two preceding stairs.", "The answer is the smaller accumulated cost at either of the final two stairs."], "statement": "An array `cost` is given, where `cost[i]` represents the fee charged for standing on step `i`; once that fee is settled you may advance upward by one step or by two steps.\n\nClimbing may begin at step `0` or at step `1` without paying for any earlier step. Compute the smallest total fee that reaches the summit, where the summit sits one position past the final index.\n\n**Constraints:**\n- `2 <= cost.length <= 1000`\n- `0 <= cost[i] <= 999`\n", "solution": "## Approach\n\nTrack the minimum accumulated cost of standing on the previous two stairs. The cost\nfor the current stair is its own cost plus the smaller of those two values. After the\nlast stair, the top is reachable from either of the final two stairs, so return their\nminimum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where `n` is the number of stairs.\n- **Space Complexity:** O(1) auxiliary space.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def minCostClimbingStairs(self, cost: List[int]) -> int:\n two_back, one_back = cost[0], cost[1]\n for i in range(2, len(cost)):\n two_back, one_back = one_back, cost[i] + min(two_back, one_back)\n return min(two_back, one_back)\n```\n", "starter": {"go": "package main\n\nfunc MinCostClimbingStairs(cost []int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def minCostClimbingStairs(self, cost: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int minCostClimbingStairs(vector<int>& cost) {\n return 0;\n }\n};"}, "fn": "minCostClimbingStairs", "params": [{"name": "cost", "type": "int_array"}], "outputType": "int", "tests": [["[10,15,20]"], ["[1,100,1,1,1,100,1,1,100,1]"], ["[0,0]"], ["[5,6]"], ["[1,2]"], ["[2,1]"], ["[7,7]"], ["[0,5]"], ["[5,0]"], ["[1,2,3]"], ["[3,2,1]"], ["[1,1,1]"], ["[0,1,0]"], ["[100,1,100]"], ["[5,6,2,4]"], ["[9,8,7,6]"], ["[1,3,5,7,9]"], ["[9,7,5,3,1]"], ["[2,2,2,2,2]"], ["[0,10,0,10,0]"], ["[10,0,10,0,10]"], ["[6,4,3,7,2,8]"], ["[4,1,6,3,8,2,5]"], ["[20,19,18,17,16,15]"], ["[15,16,17,18,19,20]"], ["[8,1,9,2,10,3,11,4]"], ["[1,8,2,9,3,10,4,11]"], ["[999,999]"], ["[999,0,999,0]"], ["[0,999,999,0]"], ["[13,7,4,8,6,5,9]"], ["[3,14,15,9,26,5,35]"], ["[11,2,50,3,40,4,30,5]"], ["[50,2,3,50,2,3,50]"], ["[1,100,1,100,1,100,1]"], ["[100,1,100,1,100,1,100]"], ["[0,0,0,0,0,0]"], ["[1,0,1,0,1,0,1,0]"], ["[2,7,9,3,1]"], ["[12,4,8,15,3,6,10,2]"], ["[5,10,15,20,25,30,35,40]"], ["[40,35,30,25,20,15,10,5]"], ["[17,17,17,17,17,17,17,17,17,17]"], ["[1,1,2,3,5,8,13,21,34,55,89]"], ["[2,3,5,7,11,13,17,19,23,29]"], ["[90,10,80,20,70,30,60,40,50]"], ["[10,90,20,80,30,70,40,60,50]"], ["[4,9,1,7,3,8,2,6,5]"], ["[25,1,25,1,25,1,25,1,25]"], ["[1,25,1,25,1,25,1,25,1]"], ["[31,41,59,26,53,58,97,93]"], ["[6,2,4,8,1,3,5,7,9,0]"], ["[200,100,50,25,12,6,3,1]"], ["[999,1,1,999,1,1,999,1,1]"], ["[42,0,17,23,5,88,12,34,56,7,91,3,45,29,60,11,72,8,19,37]"], ["[0,999,0,999,0,999,0,999,0,999,0,999]"], ["@javascript:JSON.stringify(Array(1000).fill(999))"]], "expected": [15, 6, 0, 5, 1, 1, 7, 0, 0, 2, 2, 1, 0, 1, 7, 14, 10, 10, 4, 0, 0, 9, 6, 51, 51, 10, 10, 999, 0, 999, 20, 28, 14, 10, 4, 3, 0, 0, 10, 23, 80, 80, 85, 88, 58, 100, 150, 15, 4, 5, 217, 17, 132, 5, 145, 0, 499500], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "123", "slug": "min-cost-to-connect-all-points", "id": 123, "title": "Min Cost to Connect All Points", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/min-cost-to-connect-all-points/", "examples": [{"input": "points = [[0,0],[2,2],[3,10],[5,2],[7,0]]", "output": "20", "explanation": "The minimum Manhattan distance to connect all 5 points is 20."}, {"input": "points = [[3,12],[-2,5],[-4,1]]", "output": "18", "explanation": "The minimum Manhattan distance to connect all 3 points is 18."}], "hints": ["This is a minimum spanning tree problem on a complete graph whose edge weights are Manhattan distances.", "Prim's algorithm can update each unvisited point's cheapest connection without explicitly storing all O(n^2) edges.", "An O(n^2) implementation of Prim's algorithm uses O(n) auxiliary space and is sufficient for the constraints."], "statement": "You are given points in the plane, where `points[i] = [xi, yi]`. The cost of\nconnecting two points is their Manhattan distance:\n`|xi - xj| + |yi - yj|`.\n\nReturn the minimum total cost needed to connect every point so that there is\nexactly one path between every pair of points.\n\n**Constraints:**\n\n- `1 <= points.length <= 1000`\n- `points[i].length == 2`\n- `-10^6 <= xi, yi <= 10^6`\n- All points are distinct.\n- The answer fits in a 32-bit signed integer.\n", "solution": "## Approach\n\nThe points form a complete weighted graph whose edge costs are Manhattan distances. Use Prim's algorithm without materializing all edges: `best[i]` stores the cheapest known connection from the current tree to point `i`. Repeatedly add the unvisited point with minimum connection cost and update every remaining point.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(N^2), where N is the number of points.\n- **Space Complexity:** O(N) auxiliary space.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def minCostConnectPoints(self, points: List[List[int]]) -> int:\n n = len(points)\n best = [float(\"inf\")] * n\n in_tree = [False] * n\n best[0] = 0\n total = 0\n\n for _ in range(n):\n next_point = -1\n for i in range(n):\n if not in_tree[i] and (next_point == -1 or best[i] < best[next_point]):\n next_point = i\n\n in_tree[next_point] = True\n total += best[next_point]\n for i in range(n):\n if not in_tree[i]:\n distance = abs(points[next_point][0] - points[i][0]) + abs(\n points[next_point][1] - points[i][1]\n )\n best[i] = min(best[i], distance)\n\n return total\n```\n", "starter": {"go": "package main\n\nfunc MinCostConnectPoints(points [][]int) int {\n return 0\n}\n", "python": "from typing import List\n\nclass Solution:\n def minCostConnectPoints(self, points: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int minCostConnectPoints(vector<vector<int>>& points) {\n return 0;\n }\n};"}, "fn": "minCostConnectPoints", "params": [{"name": "points", "type": "int_array_2d", "visualizeType": "points"}], "outputType": "int", "tests": [["[[0,0]]"], ["[[0,0],[1,1]]"], ["[[-1,-1],[1,1]]"], ["[[0,0],[0,5]]"], ["[[0,0],[5,0]]"], ["[[0,0],[2,2],[3,10],[5,2],[7,0]]"], ["[[3,12],[-2,5],[-4,1]]"], ["[[0,0],[1,1],[1,0],[-1,1]]"], ["[[0,0],[2,0],[4,0]]"], ["[[0,0],[0,2],[0,4]]"], ["[[-5,0],[-2,0],[3,0],[10,0]]"], ["[[0,-5],[0,-1],[0,4],[0,9]]"], ["[[0,0],[1,0],[2,0],[3,0],[4,0]]"], ["[[0,0],[0,1],[0,2],[0,3],[0,4]]"], ["[[0,0],[1,1],[2,2],[3,3],[4,4]]"], ["[[0,4],[1,3],[2,2],[3,1],[4,0]]"], ["[[-2,-2],[-1,3],[4,1]]"], ["[[5,5],[-5,5],[-5,-5],[5,-5]]"], ["[[0,0],[0,10],[10,10],[10,0],[5,5]]"], ["[[1,2],[3,4],[5,6],[7,8]]"], ["[[-1,2],[3,-4],[-5,6],[7,-8]]"], ["[[2,3],[4,-1],[-2,5],[-6,-3],[0,0]]"], ["[[10,10],[12,9],[9,14],[15,15],[7,8]]"], ["[[-10,-10],[-12,-9],[-9,-14],[-15,-15],[-7,-8]]"], ["[[0,0],[100,0],[0,100],[100,100]]"], ["[[0,0],[1000,1],[2,1000],[999,999]]"], ["[[-1000000,-1000000],[1000000,1000000]]"], ["[[-1000000,0],[0,1000000],[1000000,0],[0,-1000000]]"], ["[[1,1],[2,3],[4,2],[6,6],[7,1],[9,4]]"], ["[[-9,4],[-7,1],[-6,6],[-4,2],[-2,3],[-1,1]]"], ["[[0,0],[2,1],[4,0],[6,1],[8,0],[10,1]]"], ["[[0,0],[1,2],[0,4],[1,6],[0,8],[1,10]]"], ["[[0,0],[3,0],[6,0],[0,3],[3,3],[6,3],[0,6],[3,6],[6,6]]"], ["[[1,1],[2,2],[3,1],[2,0],[0,2]]"], ["[[8,1],[1,8],[-8,1],[1,-8],[0,0]]"], ["[[4,7],[2,9],[-3,5],[-6,-1],[0,-4],[7,-2]]"], ["[[-4,-7],[-2,-9],[3,-5],[6,1],[0,4],[-7,2]]"], ["[[11,3],[2,17],[-5,8],[9,-4],[-12,-6],[0,0]]"], ["[[20,20],[18,3],[4,16],[-7,9],[-15,-2],[-3,-14],[12,-10]]"], ["[[0,0],[1,10],[2,0],[3,10],[4,0],[5,10],[6,0]]"], ["[[0,0],[10,1],[0,2],[10,3],[0,4],[10,5],[0,6]]"], ["[[0,0],[5,2],[10,4],[15,6],[20,8],[25,10],[30,12]]"], ["[[0,0],[-5,2],[-10,4],[-15,6],[-20,8],[-25,10],[-30,12]]"], ["[[3,1],[8,2],[2,6],[7,7],[1,11],[6,12],[11,5],[12,10]]"], ["[[-3,-1],[-8,-2],[-2,-6],[-7,-7],[-1,-11],[-6,-12],[-11,-5],[-12,-10]]"], ["[[100,100],[101,99],[99,101],[-100,-100],[-101,-99],[-99,-101]]"], ["[[13,27],[-8,19],[22,-14],[-17,-25],[0,31],[29,4],[-30,2]]"], ["[[0,0],[2,5],[5,2],[7,7],[9,1],[11,6],[14,3],[16,8]]"], ["[[0,0],[1,3],[4,4],[6,1],[8,5],[11,2],[13,7],[17,3],[19,9]]"], ["[[-20,4],[-15,-3],[-9,8],[-2,-7],[3,5],[9,-1],[14,10],[21,0]]"], ["[[0,0],[10,0],[20,0],[30,0],[5,5],[15,5],[25,5],[10,10],[20,10]]"], ["[[-1000,500],[-700,-200],[-300,900],[100,-800],[500,300],[900,-100],[1200,700]]"], ["@javascript:JSON.stringify(Array.from({length:1000},(_,i)=>{const coordinate=-1000000+Math.floor(2000000*i/999);return [coordinate,coordinate];}))"]], "expected": [0, 2, 4, 5, 5, 20, 18, 4, 4, 4, 15, 14, 4, 4, 8, 8, 13, 30, 40, 12, 26, 25, 20, 20, 300, 2998, 4000000, 6000000, 20, 20, 15, 15, 24, 8, 36, 40, 40, 69, 114, 21, 21, 42, 42, 42, 42, 408, 180, 43, 46, 100, 80, 6800, 4000000], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "79", "slug": "min-stack", "id": 79, "title": "Min Stack", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/min-stack/", "examples": [{"input": "operations = [\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"top\",\"getMin\"], values = [-2,0,-3,0,0,0,0]", "output": "[-3,0,-2]", "explanation": "After pushing -2, 0, and -3, getMin returns -3. Pop removes -3, then top returns 0, and getMin returns -2."}, {"input": "operations = [\"push\",\"push\",\"getMin\",\"top\",\"pop\",\"getMin\"], values = [5,5,0,0,0,0]", "output": "[5,5,5]", "explanation": "After pushing 5 twice, getMin returns 5 and top returns 5. Pop removes one 5, then getMin returns 5."}, {"input": "operations = [\"push\",\"top\",\"getMin\"], values = [7,0,0]", "output": "[7,7]", "explanation": "After pushing 7, top returns 7 and getMin returns 7."}], "hints": ["Keep a normal stack and a second stack containing the minimum at each relevant depth.", "Push to the minimum stack when a value is less than or equal to its current top so duplicate minima are handled correctly."], "statement": "Process a trace of operations on a stack that supports retrieving its minimum\nelement in constant time.\n\n`operations[i]` is one of `push`, `pop`, `top`, or `getMin`. The aligned value\n`values[i]` is used only by `push`; it is ignored for every other operation.\nReturn an array containing the result of each `top` and `getMin` operation, in\nthe order those queries occur. `push` and `pop` do not add anything to the\nreturned array.\n\nEvery trace is valid: `pop`, `top`, and `getMin` are never called on an empty\nstack.\n\n**Constraints:**\n\n- `1 <= operations.length == values.length <= 30000`\n- `operations[i]` is `push`, `pop`, `top`, or `getMin`.\n- Push values fit in a signed 32-bit integer.\n", "solution": "## Approach\n\nUse one stack for all pushed values and a second stack for active minimums.\nPush a value onto the minimum stack when it is no greater than the current\nminimum, including equal values so duplicate minima are removed correctly.\nCollect results only for `top` and `getMin` operations.\n\n## Complexity Analysis\n\n- **Time Complexity:** `O(m)` for `m` operations, with `O(1)` work per operation.\n- **Space Complexity:** `O(m)` in the worst case, excluding the returned answers.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def runMinStack(self, operations: List[str], values: List[int]) -> List[int]:\n stack: List[int] = []\n minimums: List[int] = []\n answers: List[int] = []\n for operation, value in zip(operations, values):\n if operation == \"push\":\n stack.append(value)\n if not minimums or value <= minimums[-1]:\n minimums.append(value)\n elif operation == \"pop\":\n removed = stack.pop()\n if removed == minimums[-1]:\n minimums.pop()\n elif operation == \"top\":\n answers.append(stack[-1])\n else:\n answers.append(minimums[-1])\n return answers\n```\n", "starter": {"go": "package main\n\nfunc RunMinStack(operations []string, values []int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runMinStack(self, operations: List[str], values: List[int]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runMinStack(vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runMinStack", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"top\",\"getMin\"]", "[-2,0,-3,0,0,0,0]"], ["[\"push\",\"push\",\"getMin\",\"top\",\"pop\",\"getMin\"]", "[5,5,0,0,0,0]"], ["[\"push\",\"push\",\"getMin\",\"top\",\"pop\",\"top\"]", "[-2147483648,2147483647,0,0,0,0]"], ["[\"push\",\"pop\"]", "[7,0]"], ["[\"push\",\"top\",\"getMin\"]", "[7,0,0]"], ["[\"push\",\"push\",\"top\",\"getMin\",\"top\",\"push\",\"pop\",\"pop\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"top\",\"top\",\"getMin\",\"push\",\"push\",\"push\",\"pop\",\"getMin\",\"getMin\",\"push\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"push\",\"top\",\"push\",\"getMin\",\"pop\",\"push\",\"top\"]", "[316,-988,0,0,0,-911,0,0,887,0,0,921,-698,0,0,867,0,0,0,-830,-690,-576,0,0,0,962,8,0,-220,0,-132,698,0,-242,0,0,-950,0]"], ["[\"push\",\"push\",\"getMin\",\"push\",\"getMin\",\"push\",\"push\",\"pop\",\"getMin\",\"getMin\",\"push\",\"push\",\"push\",\"getMin\",\"top\",\"push\",\"push\",\"top\",\"pop\",\"top\",\"push\",\"push\",\"pop\",\"getMin\",\"getMin\",\"push\",\"top\",\"push\",\"getMin\",\"pop\",\"pop\",\"push\",\"pop\",\"getMin\",\"getMin\",\"push\",\"getMin\",\"push\",\"pop\",\"pop\"]", "[-398,352,0,-939,0,977,-700,0,0,0,-999,-416,308,0,0,-525,780,0,0,0,-242,160,0,0,0,415,0,976,0,0,0,-261,0,0,0,-806,0,-616,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"getMin\",\"top\",\"pop\",\"top\",\"getMin\",\"top\",\"push\",\"push\",\"pop\",\"top\",\"getMin\",\"pop\",\"pop\",\"push\"]", "[26,-962,468,470,0,0,0,0,0,0,-343,819,0,0,0,0,0,-159]"], ["[\"push\",\"push\",\"pop\",\"push\",\"getMin\",\"pop\",\"push\",\"pop\",\"push\",\"top\",\"getMin\",\"pop\",\"push\",\"push\",\"pop\",\"getMin\",\"pop\",\"push\",\"pop\",\"top\",\"push\",\"pop\",\"pop\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"push\",\"top\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"pop\",\"push\",\"push\"]", "[491,-548,0,-234,0,0,-343,0,-495,0,0,0,-955,-204,0,0,0,731,0,0,148,0,0,351,0,779,835,-486,-351,-276,0,-648,-535,-846,0,235,146,0,518,-516]"], ["[\"push\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"top\",\"pop\",\"getMin\",\"push\",\"top\",\"push\",\"top\",\"push\",\"push\",\"push\",\"top\",\"push\",\"pop\",\"pop\"]", "[-281,0,636,-475,-146,-869,0,0,0,0,-981,0,-966,0,802,-241,835,0,93,0,0]"], ["[\"push\",\"getMin\",\"getMin\",\"push\",\"push\",\"top\",\"pop\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"top\",\"getMin\",\"getMin\",\"top\",\"pop\",\"push\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"top\",\"push\",\"pop\",\"push\"]", "[-907,0,0,-963,-918,0,0,0,0,46,788,999,0,-256,0,0,72,529,83,-988,-170,-537,0,0,0,0,0,238,-714,0,0,607,171,-941,-896,0,237,0,0,-368,-605,-555,44,0,490,0,31]"], ["[\"push\",\"push\",\"getMin\",\"top\",\"push\",\"top\",\"push\",\"push\",\"top\",\"push\",\"push\",\"push\",\"top\",\"push\",\"pop\",\"push\",\"push\",\"top\",\"getMin\",\"pop\",\"push\",\"push\",\"top\",\"push\",\"push\",\"push\",\"top\",\"top\",\"push\",\"pop\",\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"pop\",\"push\",\"top\",\"push\",\"top\",\"pop\",\"getMin\",\"push\",\"pop\",\"top\",\"pop\",\"push\",\"getMin\",\"pop\",\"getMin\",\"getMin\"]", "[-350,728,0,0,-793,0,427,91,0,823,212,-704,0,-482,0,-660,-254,0,0,0,-501,-537,0,-896,740,-381,0,0,517,0,-986,159,0,-749,0,0,572,0,87,0,0,0,-502,0,0,0,-334,0,0,0,0]"], ["[\"push\",\"getMin\",\"top\",\"pop\",\"push\",\"getMin\",\"push\",\"top\",\"push\",\"getMin\",\"push\",\"pop\",\"push\",\"pop\",\"top\",\"pop\",\"top\",\"getMin\",\"getMin\",\"pop\",\"push\",\"pop\",\"push\",\"pop\",\"pop\",\"push\",\"getMin\",\"push\"]", "[-528,0,0,0,366,0,178,0,305,0,191,0,708,0,0,0,0,0,0,0,908,0,-499,0,0,781,0,941]"], ["[\"push\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"pop\",\"top\",\"getMin\",\"pop\",\"top\",\"top\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"top\",\"push\",\"push\",\"push\",\"top\",\"push\",\"pop\",\"push\",\"push\",\"pop\"]", "[-850,0,870,889,-904,0,-390,337,0,0,946,0,0,0,0,0,0,0,224,-487,473,0,0,0,-926,759,122,0,-265,0,400,-726,0]"], ["[\"push\",\"pop\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"pop\",\"push\",\"top\"]", "[-611,0,-414,449,0,-586,99,0,-486,0]"], ["[\"push\",\"getMin\",\"top\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"pop\",\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"getMin\",\"getMin\",\"pop\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"getMin\",\"getMin\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"pop\",\"top\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"pop\",\"top\",\"pop\",\"push\",\"push\",\"push\",\"push\"]", "[517,0,0,0,-958,-654,924,0,0,0,-519,651,0,294,0,0,0,0,0,0,118,-569,-937,0,0,-419,0,-105,205,568,358,0,-271,210,0,0,-409,0,0,891,-277,0,0,0,-95,156,-214,117]"], ["[\"push\",\"top\",\"push\",\"getMin\",\"top\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"getMin\",\"top\",\"getMin\",\"pop\",\"push\",\"getMin\",\"push\",\"getMin\",\"push\",\"getMin\",\"push\",\"pop\",\"push\",\"pop\",\"push\",\"top\",\"getMin\",\"push\",\"pop\",\"push\",\"push\",\"push\"]", "[-793,0,-705,0,0,890,-14,613,0,349,689,0,0,0,0,-243,0,-281,0,382,0,933,0,680,0,156,0,0,529,0,129,941,-57]"], ["[\"push\",\"top\",\"pop\",\"push\",\"top\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"top\",\"push\",\"top\",\"push\",\"top\",\"top\",\"top\",\"push\",\"getMin\",\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"push\",\"push\",\"top\",\"pop\",\"top\",\"push\",\"top\",\"pop\"]", "[265,0,0,-65,0,0,94,162,583,-118,716,0,-419,0,0,638,0,-762,0,0,0,-574,0,-898,-967,0,803,0,-410,0,-222,497,549,353,512,676,-12,-237,0,0,430,-77,0,0,0,531,0,0]"], ["[\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"pop\",\"top\",\"top\",\"push\",\"top\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"getMin\",\"pop\",\"top\",\"pop\",\"push\",\"pop\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"getMin\",\"getMin\",\"top\",\"pop\",\"top\",\"getMin\",\"pop\",\"push\",\"pop\",\"pop\",\"getMin\",\"push\",\"push\",\"top\",\"push\"]", "[-766,815,0,807,0,0,0,0,503,0,-273,0,-536,783,-731,0,0,0,0,0,0,808,0,0,0,-24,438,786,0,609,-524,816,0,14,0,-306,0,0,0,0,0,0,0,919,0,0,0,851,-803,0,527]"], ["[\"push\",\"getMin\",\"push\",\"getMin\",\"push\",\"getMin\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"top\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"pop\",\"push\",\"top\",\"push\",\"pop\",\"getMin\",\"pop\",\"getMin\",\"top\",\"getMin\",\"push\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"getMin\",\"push\",\"push\"]", "[817,0,268,0,485,0,0,-95,-15,57,767,0,0,9,219,101,0,23,894,0,316,0,997,0,0,0,0,0,0,370,-703,0,0,208,383,0,-241,415]"], ["[\"push\",\"top\",\"top\",\"push\",\"pop\",\"pop\",\"push\",\"top\",\"top\",\"getMin\",\"getMin\",\"getMin\",\"push\",\"push\",\"top\",\"top\",\"getMin\",\"getMin\",\"push\",\"pop\",\"top\",\"top\",\"pop\",\"pop\",\"push\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"top\",\"push\",\"push\",\"push\",\"pop\",\"push\"]", "[-502,0,0,36,0,0,-905,0,0,0,0,0,-896,-55,0,0,0,0,-901,0,0,0,0,0,673,422,0,-494,0,-246,0,91,-637,-94,0,218]"], ["[\"push\",\"getMin\",\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"top\",\"push\",\"push\",\"push\",\"push\",\"push\"]", "[883,0,-775,-578,0,-389,0,0,-633,-146,44,0,462,0,555,0,-905,342,-682,-219,-50]"], ["[\"push\",\"top\",\"pop\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"pop\",\"top\",\"push\",\"pop\",\"top\",\"push\",\"push\",\"push\",\"push\",\"top\",\"push\",\"top\",\"pop\",\"getMin\",\"getMin\",\"push\",\"pop\",\"getMin\",\"push\",\"getMin\",\"push\",\"getMin\",\"pop\",\"pop\",\"push\"]", "[619,0,0,750,125,97,0,556,0,0,49,0,0,-179,-999,603,745,0,985,0,0,0,0,771,0,0,-74,0,-691,0,0,0,-69]"], ["[\"push\",\"top\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"pop\",\"push\",\"getMin\",\"getMin\",\"push\",\"top\",\"push\",\"pop\",\"pop\",\"push\",\"top\",\"push\",\"push\",\"getMin\",\"push\",\"getMin\",\"getMin\",\"pop\",\"push\",\"top\",\"push\",\"getMin\",\"pop\",\"push\",\"top\",\"push\",\"getMin\",\"push\",\"getMin\",\"push\"]", "[-161,0,-591,744,310,0,-717,745,0,392,-750,0,943,437,0,-844,0,0,722,0,774,0,0,-606,0,808,-708,0,-151,0,0,0,75,0,-799,0,0,-347,0,-868,0,-69,0,-79]"], ["[\"push\",\"pop\",\"push\",\"push\",\"pop\",\"getMin\",\"push\",\"getMin\",\"push\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"pop\",\"top\",\"push\"]", "[25,0,100,668,0,0,264,0,113,0,0,501,878,207,0,0,0,0,863]"], ["[\"push\",\"push\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"getMin\",\"getMin\",\"pop\",\"getMin\",\"push\",\"top\",\"pop\",\"top\",\"top\",\"push\",\"getMin\",\"top\",\"getMin\",\"push\",\"push\",\"pop\"]", "[-362,-452,0,0,434,-159,-195,-797,0,0,0,0,0,955,0,0,0,0,868,0,0,0,896,-487,0]"], ["[\"push\",\"top\",\"getMin\",\"top\",\"push\",\"top\",\"push\",\"push\",\"getMin\",\"top\",\"getMin\",\"push\",\"getMin\",\"push\",\"push\",\"getMin\",\"top\",\"pop\",\"getMin\",\"top\",\"top\",\"top\",\"pop\",\"push\",\"push\",\"pop\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"top\",\"push\",\"push\",\"top\",\"top\",\"top\",\"getMin\",\"pop\",\"getMin\",\"push\",\"push\",\"getMin\",\"top\",\"getMin\",\"top\",\"push\",\"pop\",\"pop\",\"push\",\"pop\"]", "[-184,0,0,0,647,0,-185,344,0,0,0,-20,0,837,777,0,0,0,0,0,0,0,0,816,-878,0,0,0,742,-855,-599,0,0,750,-160,0,0,0,0,0,0,170,-59,0,0,0,0,-514,0,0,798,0]"], ["[\"push\",\"top\",\"push\",\"pop\",\"pop\",\"push\",\"getMin\",\"push\"]", "[123,0,941,0,0,277,0,468]"], ["[\"push\",\"top\",\"getMin\",\"top\",\"top\",\"pop\",\"push\",\"push\",\"getMin\",\"pop\",\"push\",\"getMin\",\"getMin\",\"pop\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"getMin\",\"getMin\",\"getMin\",\"push\",\"push\",\"getMin\",\"pop\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"top\",\"push\",\"top\",\"top\",\"getMin\",\"getMin\",\"push\",\"getMin\",\"push\",\"getMin\"]", "[-247,0,0,0,0,0,-660,-152,0,0,751,0,0,0,935,-371,231,0,-955,-597,0,0,0,-902,421,0,0,424,544,947,0,0,0,794,0,0,0,0,-257,0,635,0]"], ["[\"push\",\"getMin\",\"pop\",\"push\",\"getMin\",\"getMin\",\"top\",\"getMin\",\"push\",\"push\",\"top\",\"push\",\"push\",\"pop\",\"push\",\"top\",\"push\",\"push\",\"top\",\"top\",\"push\",\"push\",\"top\",\"push\",\"pop\",\"push\"]", "[-387,0,0,263,0,0,0,0,901,472,0,82,323,0,360,0,-396,-964,0,0,-462,-704,0,140,0,-245]"], ["[\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"getMin\",\"top\",\"push\",\"push\"]", "[140,514,-297,435,-58,648,0,678,198,763,0,0,-439,999]"], ["[\"push\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"push\",\"top\",\"push\",\"pop\",\"getMin\",\"top\",\"getMin\",\"pop\",\"getMin\",\"top\",\"getMin\",\"pop\",\"top\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"top\",\"top\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"push\"]", "[-184,850,-30,-710,0,0,570,0,-707,0,0,0,0,0,0,0,0,0,0,0,376,-150,-822,631,49,-392,0,0,0,981,-695,-322,538,-121]"], ["[\"push\",\"push\",\"getMin\",\"top\",\"push\",\"pop\",\"pop\",\"pop\",\"push\",\"push\",\"getMin\",\"pop\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"top\",\"pop\"]", "[-67,-55,0,0,781,0,0,0,438,-181,0,0,246,-353,0,847,542,-880,0,0,0]"], ["[\"push\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"getMin\",\"top\",\"push\",\"top\",\"push\",\"push\",\"pop\",\"getMin\",\"getMin\",\"getMin\",\"push\",\"pop\",\"push\",\"push\",\"getMin\",\"getMin\",\"push\",\"pop\"]", "[-904,721,675,0,108,161,-248,-730,0,-440,0,0,367,0,152,596,0,0,0,0,-867,0,-290,705,0,0,-966,0]"], ["[\"push\",\"push\",\"getMin\",\"top\",\"pop\",\"pop\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"push\",\"top\",\"top\",\"pop\",\"push\",\"top\",\"top\",\"push\",\"top\",\"pop\",\"push\"]", "[-167,536,0,0,0,0,707,-173,0,0,353,572,-424,880,-32,0,0,0,-51,0,0,714,0,0,-755]"], ["[\"push\",\"push\",\"pop\",\"getMin\",\"pop\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"getMin\",\"push\",\"push\",\"getMin\",\"push\",\"getMin\",\"getMin\",\"top\",\"push\",\"getMin\",\"push\",\"pop\"]", "[960,-277,0,0,0,-434,0,-419,0,-628,0,104,-65,0,720,0,0,0,541,0,-532,0]"], ["[\"push\",\"push\",\"top\",\"push\",\"push\",\"top\",\"top\",\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"getMin\",\"top\",\"top\",\"getMin\",\"getMin\",\"getMin\",\"getMin\",\"push\",\"push\",\"push\",\"top\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"top\",\"top\"]", "[487,-903,0,490,-67,0,0,-342,581,940,-49,93,0,0,0,0,0,0,0,0,800,-92,683,0,604,769,0,-704,-896,486,0,0]"], ["[\"push\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"top\",\"pop\",\"pop\",\"push\",\"pop\",\"push\",\"push\",\"getMin\",\"pop\",\"push\",\"push\",\"getMin\",\"top\",\"top\",\"pop\",\"pop\",\"pop\",\"push\",\"getMin\",\"push\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"top\",\"push\",\"push\",\"top\",\"push\",\"getMin\",\"push\",\"top\",\"getMin\",\"pop\",\"push\",\"push\",\"top\",\"top\"]", "[73,211,0,646,385,-869,0,0,0,0,0,-604,0,-497,-13,0,0,-625,304,0,0,0,0,0,0,24,0,-458,-82,0,0,655,-909,0,-536,-497,0,-487,0,854,0,0,0,-434,983,0,0]"], ["[\"push\",\"getMin\",\"top\",\"top\",\"pop\",\"push\",\"top\",\"push\",\"getMin\",\"top\"]", "[966,0,0,0,0,633,0,-592,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"pop\",\"pop\",\"push\",\"getMin\",\"top\",\"pop\"]", "[-367,-795,-728,913,0,0,0,0,-96,0,0,0]"], ["[\"push\",\"push\",\"getMin\",\"top\",\"push\",\"top\",\"getMin\",\"getMin\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"push\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"top\",\"getMin\",\"push\",\"getMin\",\"top\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"top\",\"top\",\"top\",\"push\",\"top\",\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"top\",\"push\",\"pop\"]", "[923,600,0,0,-277,0,0,0,994,0,589,227,-197,0,0,-172,675,0,0,134,-115,-163,0,-203,0,0,251,0,0,233,-723,0,0,680,0,0,0,-89,0,41,973,-82,-651,77,0,0,847,0]"], ["[\"push\",\"top\",\"top\",\"top\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"push\",\"top\",\"push\",\"push\",\"top\",\"push\",\"pop\",\"top\",\"push\",\"push\",\"pop\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"pop\",\"pop\",\"getMin\",\"top\",\"top\",\"getMin\",\"push\",\"getMin\",\"push\",\"getMin\",\"pop\",\"push\",\"top\",\"pop\",\"pop\",\"pop\"]", "[-894,0,0,0,-235,-624,822,0,0,-766,-464,0,305,822,0,-26,0,0,-525,-99,0,0,0,-13,-792,-285,0,0,0,0,0,0,0,0,590,0,-453,0,0,795,0,0,0,0]"], ["[\"push\",\"pop\",\"push\",\"push\",\"top\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"pop\",\"getMin\",\"push\",\"getMin\",\"getMin\",\"push\",\"push\",\"getMin\",\"top\",\"push\",\"pop\"]", "[-266,0,-981,462,0,-910,138,839,0,496,782,0,0,-4,0,0,426,982,0,0,884,0]"], ["[\"push\",\"getMin\",\"getMin\",\"push\",\"top\",\"pop\",\"push\",\"top\",\"pop\",\"push\",\"pop\",\"push\",\"pop\",\"getMin\",\"top\",\"getMin\",\"push\",\"top\",\"push\",\"top\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"getMin\",\"getMin\",\"top\",\"pop\",\"getMin\",\"top\",\"pop\",\"getMin\",\"push\",\"push\",\"top\",\"push\",\"getMin\",\"getMin\"]", "[218,0,0,700,0,0,-347,0,0,-552,0,772,0,0,0,0,957,0,-389,0,0,-895,-611,-911,901,0,0,0,0,0,0,0,0,556,472,0,134,0,0]"], ["[\"push\",\"getMin\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"pop\",\"top\",\"push\",\"getMin\",\"getMin\"]", "[349,0,98,0,0,-223,196,55,0,724,683,0,0,-610,0,0]"], ["[\"push\",\"getMin\",\"push\",\"getMin\",\"push\",\"top\",\"top\",\"pop\",\"top\",\"top\",\"top\",\"getMin\",\"pop\",\"push\",\"pop\",\"push\",\"pop\",\"push\",\"push\"]", "[448,0,14,0,462,0,0,0,0,0,0,0,0,601,0,-316,0,650,-885]"], ["[\"push\",\"getMin\",\"getMin\",\"top\",\"getMin\",\"pop\",\"push\",\"top\",\"pop\",\"push\",\"getMin\"]", "[756,0,0,0,0,0,-793,0,0,826,0]"], ["[\"push\",\"pop\",\"push\",\"top\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"pop\",\"top\",\"getMin\",\"getMin\",\"push\",\"top\",\"push\",\"getMin\",\"getMin\",\"getMin\",\"top\",\"pop\",\"push\",\"top\",\"push\",\"getMin\",\"top\",\"getMin\",\"top\"]", "[367,0,-340,0,0,10,-311,357,-84,0,-614,-880,0,0,0,0,-51,0,430,0,0,0,0,0,289,0,-148,0,0,0,0]"], ["[\"push\",\"pop\",\"push\",\"getMin\",\"top\",\"push\",\"getMin\",\"push\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"getMin\",\"pop\",\"getMin\",\"getMin\",\"getMin\",\"push\",\"top\",\"push\",\"top\",\"pop\",\"pop\",\"pop\",\"push\",\"pop\",\"top\",\"push\",\"getMin\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"getMin\",\"push\",\"pop\"]", "[-420,0,501,0,0,266,0,64,-879,0,0,697,118,0,0,0,0,0,305,0,512,0,0,0,0,-617,0,0,-526,0,0,0,516,744,885,0,-635,0]"], ["[\"push\",\"push\",\"pop\",\"pop\",\"push\",\"top\",\"pop\",\"push\",\"getMin\",\"getMin\",\"getMin\",\"top\",\"top\",\"push\",\"pop\",\"push\",\"push\",\"pop\",\"getMin\",\"top\",\"pop\",\"push\",\"push\",\"getMin\",\"pop\",\"pop\",\"top\",\"top\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"getMin\",\"push\",\"top\",\"getMin\",\"pop\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"pop\"]", "[376,447,0,0,-749,0,0,-881,0,0,0,0,0,-90,0,704,-96,0,0,0,0,263,-56,0,0,0,0,0,114,-100,0,0,-848,0,-312,0,0,0,0,-368,491,-535,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"push\",\"pop\",\"getMin\",\"push\",\"push\",\"push\",\"push\",\"top\",\"getMin\",\"pop\",\"push\",\"push\"]", "[711,-767,934,822,0,0,-206,0,0,565,539,722,-774,0,0,0,805,-41]"], ["[\"push\",\"top\",\"push\",\"push\",\"top\",\"top\",\"pop\",\"push\",\"top\",\"push\",\"getMin\",\"push\",\"getMin\",\"pop\",\"top\",\"pop\",\"push\",\"push\",\"getMin\",\"push\",\"top\",\"getMin\",\"pop\",\"top\",\"push\",\"top\",\"top\",\"pop\",\"pop\",\"top\"]", "[-593,0,-944,-563,0,0,0,-241,0,-91,0,-28,0,0,0,0,157,428,0,-591,0,0,0,0,-444,0,0,0,0,0]"], ["[\"push\",\"top\",\"pop\",\"push\",\"top\",\"push\",\"pop\",\"push\",\"push\",\"getMin\",\"getMin\",\"pop\",\"top\",\"push\",\"push\",\"top\",\"top\",\"pop\",\"push\",\"pop\",\"top\",\"top\",\"push\",\"getMin\",\"getMin\",\"pop\",\"push\",\"push\",\"push\",\"top\",\"push\",\"push\",\"push\",\"pop\",\"top\",\"push\",\"top\",\"getMin\",\"top\",\"push\",\"getMin\",\"push\",\"top\"]", "[946,0,0,-165,0,523,0,206,-643,0,0,0,0,-821,195,0,0,0,-588,0,0,0,-327,0,0,0,-645,846,-637,0,698,-100,-154,0,0,385,0,0,0,533,0,587,0]"], ["[\"push\",\"pop\",\"push\",\"top\",\"pop\",\"push\",\"push\",\"getMin\",\"pop\",\"getMin\",\"top\",\"push\",\"top\",\"top\",\"push\",\"getMin\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"getMin\",\"getMin\",\"top\",\"getMin\",\"push\",\"top\",\"getMin\",\"push\",\"push\",\"top\"]", "[301,0,870,0,0,431,295,0,0,0,0,70,0,0,687,0,-915,0,-919,251,56,703,0,0,0,0,940,0,0,231,-631,0]"], ["[\"push\",\"push\",\"push\",\"getMin\",\"getMin\",\"getMin\",\"pop\",\"push\",\"push\",\"top\",\"getMin\",\"getMin\",\"push\",\"push\",\"top\",\"pop\",\"push\",\"pop\",\"push\",\"getMin\",\"top\",\"top\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"getMin\",\"top\",\"push\",\"getMin\",\"top\",\"pop\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"top\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"push\",\"pop\",\"push\"]", "[-296,-253,343,0,0,0,0,866,647,0,0,0,-709,-156,0,0,-489,0,-375,0,0,0,-407,0,-17,-119,-686,0,0,888,0,0,0,987,0,-730,-854,-832,729,0,-42,0,-820,0,955,57,0,701,266,-509,0,563]"], ["[\"push\",\"getMin\",\"getMin\",\"pop\",\"push\",\"pop\",\"push\",\"top\",\"pop\",\"push\",\"getMin\",\"push\",\"pop\",\"push\"]", "[260,0,0,0,828,0,459,0,0,-421,0,-217,0,-86]"], ["[\"push\",\"pop\",\"push\",\"pop\",\"push\",\"push\",\"top\",\"top\",\"pop\",\"push\",\"getMin\"]", "[407,0,-549,0,-257,-70,0,0,0,23,0]"], ["[\"push\",\"push\",\"top\",\"push\",\"push\",\"getMin\",\"top\",\"getMin\",\"top\",\"getMin\",\"pop\",\"push\",\"pop\",\"getMin\",\"push\",\"pop\",\"push\"]", "[-655,-763,0,182,161,0,0,0,0,0,0,-754,0,0,-94,0,310]"], ["[\"push\",\"pop\",\"push\",\"pop\",\"push\",\"pop\",\"push\",\"getMin\",\"push\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"pop\",\"pop\",\"push\",\"getMin\",\"push\",\"pop\",\"top\",\"getMin\",\"top\",\"push\",\"getMin\",\"getMin\",\"top\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"push\",\"pop\",\"pop\",\"top\",\"push\",\"top\",\"push\",\"push\",\"push\",\"getMin\",\"getMin\"]", "[-978,0,741,0,-225,0,707,0,-959,408,0,207,-597,-625,0,0,934,0,0,710,0,-862,0,0,0,0,64,0,0,0,-196,643,-199,0,-637,243,0,0,0,160,0,-39,-323,-510,0,0]"], ["[\"push\",\"getMin\",\"pop\",\"push\",\"top\",\"push\",\"push\",\"getMin\",\"pop\",\"push\",\"top\",\"push\",\"push\",\"top\",\"push\",\"getMin\",\"push\",\"push\",\"push\",\"getMin\",\"pop\",\"pop\",\"top\",\"top\"]", "[-648,0,0,720,0,-11,616,0,0,-96,0,765,680,0,-469,0,-682,-513,-206,0,0,0,0,0]"], ["[\"push\"]", "[-2147483648]"], ["@javascript:JSON.stringify([...Array(15000).fill('push'),...Array(14999).fill('pop'),'getMin'])", "@javascript:JSON.stringify([...Array.from({length:15000},(_,i)=>i===0?-2147483648:i===14999?2147483647:i),...Array(15000).fill(0)])"]], "expected": [[-3, 0, -2], [5, 5, 5], [-2147483648, 2147483647, -2147483648], [], [7, 7], [-988, -988, -988, 316, 867, 867, 316, -830, -830, -830, 698, -830, -950], [-398, -939, -939, -939, -999, 308, 780, -525, -999, -999, 415, -999, -999, -999, -999], [-962, 470, 468, -962, 468, -343, -962], [-234, -495, -495, -955, 491, -276], [-146, -475, -981, -966, 835], [-907, -907, -918, 999, 46, -537, -988, -988, -537, -988, -988, 44], [-350, 728, -793, 91, -704, -254, -793, -537, -381, -381, -986, 572, 87, -986, 572, -986, -986, -986], [-528, -528, 366, 178, 178, 305, 178, 178, 178, 781], [-904, -904, -904, 889, 889, 473, -487, 122], [-486], [517, 517, 924, -958, -958, -958, -958, -958, -958, -958, -958, -271, -958, 891], [-793, -793, -705, -793, 689, -793, -793, -793, -793, 156, -793], [265, -65, -118, 716, 638, -762, -762, -762, -762, -967, -967, -967, -77, 430, 531], [-766, -766, -766, 503, -731, -766, -536, -524, -524, -524, -306, 14, -524, -24, -803], [817, 268, 268, 57, -95, 316, -95, -95, 23, -95, -95, -95], [-502, -502, -905, -905, -905, -905, -905, -55, -55, -905, -905, -55, -55, -905, -246], [883, -775, -775, -775, 555], [619, 97, 97, 97, 745, 985, -999, -999, -999, -999, -999], [-161, -591, -717, -750, -844, -844, 722, -606, -844, -844, -844, 75, -844, -347, -868, -868], [100, 100, 207, 501], [-195, -195, -159, 955, -159, -159, -159, 868, -159], [-184, -184, -184, 647, -185, 344, -185, -185, -185, 777, -185, 837, 837, 837, -599, -599, -160, -160, -160, -855, -855, -855, -59, -855, -59], [123, 277], [-247, -247, -247, -247, -660, -660, -660, -955, -955, -955, -955, 424, 794, 794, -955, -955, -955, -955], [-387, 263, 263, 263, 263, 472, 360, -964, -964, -704], [-297, 763], [-710, 570, -184, 570, -184, -184, -30, -184, 850, -184, -392, -392, -822], [-67, -55, -181, -880, -880], [-904, -904, -904, -440, 367, -904, -904, -904, -904, -904], [-167, 536, -32, -32, -51, -51, 714], [960, -419, -628, -628, -628, -628, 720, -628], [-903, -67, -67, -903, -49, -49, -903, -903, -903, -903, 683, -903, 486, 486], [646, -497, -625, 304, 304, 24, -458, -909, -497, -909, 854, -909, 983, 983], [966, 966, 966, 633, -592, -592], [913, -367, -96], [600, 600, -277, -277, -277, -277, -197, -277, -203, -277, -277, 251, 680, 680, 680, -89, -651], [-894, -894, -894, -464, 822, 822, -894, -894, -894, 822, 822, -894, -894, -894, 795], [462, -981, -981, -981, -981, 982], [218, 218, 700, -347, 218, 218, 218, 957, -389, -389, -911, -911, 901, -911, -911, -895, 472, -895, -895], [349, 349, -223, 724, -610, -610], [448, 14, 462, 462, 14, 14, 14, 14], [756, 756, 756, 756, -793, 826], [-340, -614, -614, -614, -51, -614, -614, -614, 430, 289, -614, -148, -614, -148], [501, 501, 266, 64, 64, 64, 64, 64, 305, 512, 64, -526, 266], [-749, -881, -881, -881, -881, -881, -881, 704, -881, -881, -881, -881, -312, -881, -535], [-767, -767, -774, -774], [-593, -563, -563, -241, -944, -944, -91, -944, -591, -944, 428, -444, -444, 157], [946, -165, -643, -643, 206, 195, 195, -821, -821, -821, -821, -637, -100, 385, -821, 385, -821, 587], [870, 295, 431, 431, 70, 70, 70, -919, -919, 703, -919, 940, -919, -631], [-296, -296, -296, 647, -296, -296, -156, -709, -375, -375, -709, -709, -686, -709, 888, -854, -820], [260, 260, 459, -421], [-70, -70, -257], [-763, -763, 161, -763, 161, -763, -763], [707, -959, -959, 710, -959, 710, -959, -959, 64, 643, 160, -959, -959], [-648, 720, -11, -96, 680, -469, -682, -682, -682], [], [-2147483648]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "588", "slug": "minesweeper", "id": 588, "title": "Minesweeper", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/minesweeper/", "examples": [{"input": "board = [[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"]], click = [3,0]", "output": "[\"B1E1B\",\"B1M1B\",\"B111B\",\"BBBBB\"]", "explanation": "A blank region floods outward until it touches numbered squares bordering the mine."}, {"input": "board = [[\"B\",\"1\",\"E\",\"1\",\"B\"],[\"B\",\"1\",\"M\",\"1\",\"B\"],[\"B\",\"1\",\"1\",\"1\",\"B\"],[\"B\",\"B\",\"B\",\"B\",\"B\"]], click = [1,2]", "output": "[\"B1E1B\",\"B1X1B\",\"B111B\",\"BBBBB\"]", "explanation": "The clicked square hides a mine, so it is marked X."}], "hints": ["Handle the mine click first: M becomes X with no further changes.", "For an empty square, count mines in all 8 neighboring cells before deciding between a digit and B.", "Only blank (zero-neighbor) squares trigger recursion into still-unrevealed E neighbors; join each finished row into one answer string. Adaptation: the board is a char_array_2d input while the updated board is returned as row strings (string_list). Rust note: the board arrives as its encoded string; parse it before solving."], "statement": "You are given a Minesweeper board where each cell holds one character:\n- `E`: an unrevealed empty square,\n- `M`: an unrevealed mine,\n- `B`: a revealed blank square (no neighboring mines),\n- `1`\u2013`8`: a revealed square showing its count of neighboring mines,\n- `X`: a revealed mine.\n\nYou are also given a click position `[r, c]`. Apply one reveal step and return the updated board:\n- If the clicked square hides a mine (`M`), it becomes `X` and the game ends.\n- If the clicked square is empty (`E`), count its neighboring mines in all 8 directions (horizontal, vertical, diagonal). If the count is positive, write it as a digit character. If it is zero, write `B` and repeat the same reveal step for every neighboring square (neighbors that are already revealed stay as they are).\n- Clicking an already revealed square changes nothing.\n\nReturn the updated board as a list of row strings: row `r` of the answer is the string formed by that row's characters from left to right.\n\n*Adaptation note:* the board is passed in as a 2D grid of characters and the answer is read back as a list of strings (one per row) so every supported language can express it.\n\n**Constraints:**\n- `1 <= board.length, board[i].length <= 50`\n- The board is rectangular; every cell holds one of `E`, `M`, `B`, `X`, or a digit `1`\u2013`8`.\n- `click.length == 2` and the position is inside the board.\n", "solution": "## Approach\n\nA mine click ends immediately by marking `X`. Otherwise a depth-first reveal handles empty squares: count adjacent mines across the 8 neighbors; write the digit when the count is positive, else write `B` and recurse into every neighbor. The guard that only unrevealed `E` cells are processed keeps already-revealed squares untouched and prevents infinite loops.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), where m and n are the board dimensions. Each cell is revealed at most once.\n- **Space Complexity:** O(m * n) in the worst case for the recursion stack and flood region.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def updateBoard(self, board: List[List[str]], click: List[int]) -> List[str]:\n r, c = click\n if board[r][c] == 'M':\n board[r][c] = 'X'\n else:\n m, n = len(board), len(board[0])\n dirs = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]\n def reveal(x, y):\n if not (0 <= x < m and 0 <= y < n) or board[x][y] != 'E':\n return\n mines = sum(1 for dx, dy in dirs\n if 0 <= x+dx < m and 0 <= y+dy < n\n and board[x+dx][y+dy] in ('M', 'X'))\n if mines > 0:\n board[x][y] = str(mines)\n else:\n board[x][y] = 'B'\n for dx, dy in dirs:\n reveal(x+dx, y+dy)\n reveal(r, c)\n return [''.join(row) for row in board]\n```\n", "starter": {"go": "package main\n\nfunc UpdateBoard(board [][]byte, click []int) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def updateBoard(self, board: List[List[str]], click: List[int]) -> List[str]:\n return []\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> updateBoard(vector<vector<char>>& board, vector<int>& click) {\n return {};\n }\n};"}, "fn": "updateBoard", "params": [{"name": "board", "type": "char_array_2d"}, {"name": "click", "type": "int_array"}], "outputType": "string_list", "tests": [["[[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"]]", "[3,0]"], ["[[\"B\",\"1\",\"E\",\"1\",\"B\"],[\"B\",\"1\",\"M\",\"1\",\"B\"],[\"B\",\"1\",\"1\",\"1\",\"B\"],[\"B\",\"B\",\"B\",\"B\",\"B\"]]", "[1,2]"], ["[[\"E\",\"E\"],[\"E\",\"E\"]]", "[0,0]"], ["[[\"E\",\"M\"],[\"E\",\"E\"]]", "[0,1]"], ["[[\"M\",\"E\"],[\"E\",\"E\"]]", "[0,0]"], ["[[\"M\",\"E\"],[\"E\",\"E\"]]", "[1,1]"], ["[[\"E\",\"E\",\"E\"],[\"E\",\"M\",\"E\"],[\"E\",\"E\",\"E\"]]", "[0,0]"], ["[[\"E\",\"E\",\"E\"],[\"E\",\"M\",\"E\"],[\"E\",\"E\",\"E\"]]", "[2,2]"], ["[[\"E\",\"E\",\"E\"],[\"E\",\"M\",\"E\"],[\"E\",\"E\",\"E\"]]", "[1,1]"], ["[[\"E\"]]", "[0,0]"], ["[[\"M\"]]", "[0,0]"], ["[[\"E\",\"E\",\"M\",\"E\",\"E\"]]", "[0,0]"], ["[[\"E\",\"E\",\"M\",\"E\",\"E\"]]", "[0,4]"], ["[[\"E\",\"E\",\"M\",\"E\",\"E\"]]", "[0,2]"], ["[[\"E\"],[\"E\"],[\"M\"],[\"E\"],[\"E\"]]", "[0,0]"], ["[[\"E\"],[\"E\"],[\"M\"],[\"E\"],[\"E\"]]", "[4,0]"], ["[[\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\"]]", "[1,1]"], ["[[\"M\",\"M\",\"M\"],[\"M\",\"M\",\"M\"],[\"M\",\"M\",\"M\"]]", "[1,1]"], ["[[\"M\",\"E\",\"M\",\"E\"],[\"E\",\"M\",\"E\",\"M\"],[\"M\",\"E\",\"M\",\"E\"],[\"E\",\"M\",\"E\",\"M\"]]", "[0,1]"], ["[[\"E\",\"M\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"M\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"M\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"]]", "[0,0]"], ["[[\"E\",\"M\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"M\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"M\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"]]", "[4,4]"], ["[[\"E\",\"M\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"M\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"M\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"]]", "[0,1]"], ["[[\"E\",\"M\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"M\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\"],[\"M\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\"]]", "[2,2]"], ["[[\"E\",\"M\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\"],[\"M\",\"E\",\"E\",\"E\"]]", "[2,3]"], ["[[\"E\",\"M\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\"],[\"M\",\"E\",\"E\",\"E\"]]", "[0,0]"], ["[[\"E\",\"M\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\"],[\"M\",\"E\",\"E\",\"E\"]]", "[1,2]"], ["[[\"E\",\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"M\",\"E\"],[\"M\",\"E\",\"E\",\"E\",\"E\",\"E\"]]", "[5,1]"], ["[[\"E\",\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"M\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"E\",\"E\"],[\"E\",\"E\",\"E\",\"E\",\"M\",\"E\"],[\"M\",\"E\",\"E\",\"E\",\"E\",\"E\"]]", "[0,5]"]], "expected": [["B1E1B", "B1M1B", "B111B", "BBBBB"], ["B1E1B", "B1X1B", "B111B", "BBBBB"], ["BB", "BB"], ["EX", "EE"], ["XE", "EE"], ["ME", "E1"], ["1EE", "EME", "EEE"], ["EEE", "EME", "EE1"], ["EEE", "EXE", "EEE"], ["B"], ["X"], ["B1MEE"], ["EEM1B"], ["EEXEE"], ["B", "1", "M", "E", "E"], ["E", "E", "M", "1", "B"], ["BBB", "BBB", "BBB"], ["MMM", "MXM", "MMM"], ["M3ME", "EMEM", "MEME", "EMEM"], ["1MEEE", "EEEME", "EEEEE", "MEEEE", "EEMEE"], ["EMEEE", "EEEME", "EEE11", "MEE1B", "EEM1B"], ["EXEEE", "EEEME", "EEEEE", "MEEEE", "EEMEE"], ["EMEEE", "EEEME", "EE1EE", "MEEEE", "EEMEE"], ["EMEE", "EEME", "MEE1"], ["1MEE", "EEME", "MEEE"], ["EMEE", "EEXE", "MEEE"], ["EEEEEE", "EEEEEE", "EEMEEE", "EEEEEE", "EEEEME", "M1EEEE"], ["BBBBBB", "B111BB", "B1M1BB", "B1E211", "11EEME", "MEEEEE"]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "461", "slug": "mini-parser", "id": 461, "title": "Mini Parser", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/mini-parser/", "examples": [{"input": "s = \"324\"", "output": "\"324\"", "explanation": "Single integer round-trips."}, {"input": "s = \"[123,[456,[789]]]\"", "output": "\"[123,[456,[789]]]\"", "explanation": "Nesting preserved."}, {"input": "s = \"[123,456,[789,[]]]\"", "output": "\"[123,456,[789,[]]]\"", "explanation": "Empty list survives."}], "hints": ["A lone number with no brackets is its own answer.", "Otherwise scan with a stack: push a new list on '[', close it on ']', and flush numbers on ',' or ']' boundaries.", "Re-serialize the parsed tree canonically instead of echoing the raw input."], "statement": "Parse a nested-list string and hand back its canonical spelling.\n\nYou receive a string `s` that encodes either a single integer (for example `\"324\"`) or a nested list of integers and lists (for example `\"[123,[456,[789]]]\"`). It uses only digits, `-`, `,`, `[`, and `]`, and it is guaranteed to be a valid encoding with values in `[-10^6, 10^6]`. Implement `deserialize(s)`, which parses this structure and returns its normalized serialization: the same canonical text with no extra spacing, integers in plain decimal form, and lists wrapped in matched brackets separated by single commas.\n\n*Portable adaptation:* the classic version returns a `NestedInteger` object graph, which this judge cannot express; returning the canonical string captures the same parsing work and is compared structurally, so harmless spelling differences that parse to the same shape are still accepted.\n\n**Constraints:**\n- `1 <= s.length <= 5 * 10^4`\n- `s` holds only digits, `-`, `,`, `[`, `]`.\n- `s` is a valid nested-list serialization.\n- Every integer lies in `[-10^6, 10^6]`.\n", "solution": "## Approach\n\nWhen the text holds no opening bracket it is a bare integer and is returned as is. Otherwise walk the characters with a recursive descent: `[` opens a fresh list, `]` closes it, commas separate entries, and digit runs (with an optional minus) become integer leaves. Serializing the parsed tree canonically yields the normalized answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`, with one pass to parse and one to print.\n- **Space Complexity:** O(n) for the parse tree and the output.\n\n## Implementation\n\n```python\nclass Solution:\n def deserialize(self, s: str) -> str:\n self.i = 0\n self.s = s\n node = self._parse()\n return self._ser(node)\n\n def _parse(self):\n if self.s[self.i] == '[':\n self.i += 1\n items = []\n while self.s[self.i] != ']':\n items.append(self._parse())\n if self.s[self.i] == ',':\n self.i += 1\n self.i += 1\n return ('list', items)\n start = self.i\n if self.s[self.i] == '-':\n self.i += 1\n while self.i < len(self.s) and self.s[self.i].isdigit():\n self.i += 1\n return ('int', int(self.s[start:self.i]))\n\n def _ser(self, node):\n if node[0] == 'int':\n return str(node[1])\n return '[' + ','.join(self._ser(x) for x in node[1]) + ']'\n```\n", "starter": {"go": "package main\n\nfunc Deserialize(s string) string {\n return \"\"\n}", "python": "class Solution:\n def deserialize(self, s: str) -> str:\n return \"\"\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string deserialize(string s) {\n return \"\";\n }\n};"}, "fn": "deserialize", "params": [{"name": "s", "type": "string"}], "outputType": "string", "tests": [["324"], ["[123,[456,[789]]]"], ["[123,456,[789,[]]]"], ["[]"], ["0"], ["-1"], ["[0]"], ["[-1,-2,-3]"], ["[123,456,789]"], ["[[]]"], ["[[],[]]"], ["[1,[2,[3,[4]]]]"], ["[[1,2],[3,4]]"], ["[-1000000,1000000]"], ["[10,[20,[30]]]"], ["[1,2,3,4,5]"], ["[[[]]]"], ["[100,200,300,[400,500]]"], ["-456"], ["1000000"], ["-1000000"], ["[1]"], ["[1,[]]"], ["[[1],2,3]"], ["[[1,2],3,[4,5]]"], ["[0,0,0]"], ["[123]"], ["[[123]]"], ["[1,[2],3,[4,[5]]]"], ["[-5,[-10,[15]]]"]], "expected": ["324", "[123,[456,[789]]]", "[123,456,[789,[]]]", "[]", "0", "-1", "[0]", "[-1,-2,-3]", "[123,456,789]", "[[]]", "[[],[]]", "[1,[2,[3,[4]]]]", "[[1,2],[3,4]]", "[-1000000,1000000]", "[10,[20,[30]]]", "[1,2,3,4,5]", "[[[]]]", "[100,200,300,[400,500]]", "-456", "1000000", "-1000000", "[1]", "[1,[]]", "[[1],2,3]", "[[1,2],3,[4,5]]", "[0,0,0]", "[123]", "[[123]]", "[1,[2],3,[4,[5]]]", "[-5,[-10,[15]]]"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "915", "slug": "minimize-malware-spread-ii", "id": 915, "title": "Minimize Malware Spread II", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/minimize-malware-spread-ii/", "examples": [{"input": "graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]", "output": "0", "explanation": "Either removal leaves one infection; pick the smaller index."}, {"input": "graph = [[1,1,0],[1,1,1],[0,1,1]], initial = [0,1]", "output": "1", "explanation": "Removing 1 isolates computer 0."}, {"input": "graph = [[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]], initial = [0,1]", "output": "1"}], "hints": ["Simulate removal: for each candidate, traverse only from the remaining infected nodes while blocking the removed one.", "Count all visited computers; the removed node itself is never counted.", "Iterate candidates in sorted order so ties naturally keep the smallest index."], "statement": "You are given an undirected network as an adjacency matrix `graph`, where `graph[i][j] == 1` links computers `i` and `j` (every computer links to itself). A few computers in `initial` start infected.\n\nYou may pick exactly one computer from `initial` to fully remove (it can neither be infected nor pass infection). Afterwards infection spreads through connected computers in the usual way. Return the computer whose removal leaves the fewest infected computers overall. When several choices tie, return the smallest index.\n\n**Constraints:**\n- `2 <= graph.length <= 100`\n- `graph` is square, symmetric, with ones on the diagonal.\n- `1 <= initial.length < graph.length`, all entries distinct.\n", "solution": "## Approach\n\nTry every candidate in `initial` in increasing order. For a fixed removed node, run breadth-first searches from all other infected nodes while never stepping onto the removed node, counting every reached computer. The candidate with the smallest reached total wins; scanning in sorted order handles the tie-break automatically.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k * (n + e)), where k is the size of `initial`, n the computers, and e the edges. Each trial is a graph traversal.\n- **Space Complexity:** O(n) for the visited flags and queue.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n n = len(graph)\n best = min(initial)\n best_count = 10 ** 9\n for rem in sorted(initial):\n seen = [False] * n\n seen[rem] = True\n total = 0\n for s in initial:\n if s == rem or seen[s]:\n continue\n q = deque([s])\n seen[s] = True\n sz = 0\n while q:\n u = q.popleft()\n sz += 1\n for v in range(n):\n if graph[u][v] == 1 and not seen[v]:\n seen[v] = True\n q.append(v)\n total += sz\n if total < best_count:\n best_count = total\n best = rem\n return best\n```\n", "starter": {"go": "package main\n\nfunc MinMalwareSpread(graph [][]int, initial []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n return 0;\n }\n};"}, "fn": "minMalwareSpread", "params": [{"name": "graph", "type": "int_array_2d"}, {"name": "initial", "type": "int_array"}], "outputType": "int", "tests": [["[[1,1,0],[1,1,0],[0,0,1]]", "[0,1]"], ["[[1,1,0],[1,1,1],[0,1,1]]", "[0,1]"], ["[[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]]", "[0,1]"], ["[[1,1,1],[1,1,1],[1,1,1]]", "[0,1,2]"], ["[[1,0,0],[0,1,0],[0,0,1]]", "[0,1]"], ["[[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]", "[0,2]"], ["[[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]", "[0,1,2,3]"], ["[[1,0,1],[0,1,0],[1,0,1]]", "[0,2]"], ["[[1,1,1,0],[1,1,0,0],[1,0,1,1],[0,0,1,1]]", "[0,3]"], ["[[1,1],[1,1]]", "[0]"], ["[[1,1],[1,1]]", "[0,1]"], ["[[1,0,0,0],[0,1,1,0],[0,1,1,1],[0,0,1,1]]", "[1,2]"], ["[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]", "[1,3]"], ["[[1,0,0,1],[0,1,1,0],[0,1,1,0],[1,0,0,1]]", "[0,1]"], ["[[1,1,0,1],[1,1,1,0],[0,1,1,0],[1,0,0,1]]", "[0,2]"], ["[[1,1,0,0,0],[1,1,1,0,0],[0,1,1,1,0],[0,0,1,1,1],[0,0,0,1,1]]", "[0,4]"], ["[[1,1,0,0,0],[1,1,1,0,0],[0,1,1,1,0],[0,0,1,1,1],[0,0,0,1,1]]", "[1,3]"], ["[[1,0,1,0],[0,1,0,1],[1,0,1,0],[0,1,0,1]]", "[0,1,2,3]"], ["[[1,1,1,0,0],[1,1,0,0,0],[1,0,1,0,0],[0,0,0,1,1],[0,0,0,1,1]]", "[0,3]"], ["[[1,1,0],[1,1,1],[0,1,1]]", "[2]"], ["[[1,0,0],[0,1,1],[0,1,1]]", "[0]"], ["[[1,0,0],[0,1,1],[0,1,1]]", "[0,1]"], ["[[1,1,0,0,0,0],[1,1,1,0,0,0],[0,1,1,1,0,0],[0,0,1,1,1,0],[0,0,0,1,1,1],[0,0,0,0,1,1]]", "[0,5]"], ["[[1,1,0,0,0,0],[1,1,1,0,0,0],[0,1,1,1,0,0],[0,0,1,1,1,0],[0,0,0,1,1,1],[0,0,0,0,1,1]]", "[2,4]"], ["[[1,0,1,1],[0,1,0,0],[1,0,1,1],[1,0,1,1]]", "[0,1]"], ["[[1,1,1],[1,1,0],[1,0,1]]", "[0,1]"], ["[[1,1,0,0],[1,1,1,1],[0,1,1,0],[0,1,0,1]]", "[1,2,3]"], ["[[1,0,0,0,1],[0,1,1,0,0],[0,1,1,0,0],[0,0,0,1,1],[1,0,0,1,1]]", "[1,4]"]], "expected": [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 2, 0, 0, 1, 4], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "911", "slug": "minimize-malware-spread", "id": 911, "title": "Minimize Malware Spread", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/minimize-malware-spread/", "examples": [{"input": "graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]", "output": "0", "explanation": "Removing 0 leaves node 1 infected in its pair while node 2 stays clean; removing 1 instead leaves 0 infected too, so 0 is the better removal."}, {"input": "graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]", "output": "0", "explanation": "No spread is possible, so the smallest index wins the tie."}, {"input": "graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]", "output": "1", "explanation": "One connected component holds both infected nodes, so removal cannot stop the spread; return the smaller index."}], "hints": ["Infection floods whole connected components, so group nodes with union-find (or BFS) first.", "Only a component containing exactly one initially infected node can be saved, and removing that node saves the entire component.", "Pick the removal saving the most nodes, breaking ties by the smaller index; if nothing can be saved, return the smallest initial index."], "statement": "A network of `n` computers is described by `graph`, where `graph[i][j] = 1` means computers `i` and `j` are directly linked (links are mutual and every computer links to itself). Malware starts on every computer in `initial` and spreads along links: any healthy computer directly or indirectly linked to an infected one becomes infected.\n\nYou may remove exactly one computer from `initial` (it and its links vanish, and it never gets infected). Return the computer whose removal leaves the fewest computers infected in the end. When several choices tie, return the smallest index.\n\n**Constraints:**\n- `2 <= n == graph.length <= 300`\n- `graph[i][j]` is `0` or `1`, the matrix is symmetric with all `graph[i][i] == 1`\n- `1 <= initial.length < n`, all entries distinct and in `[0, n - 1]`\n", "solution": "## Approach\n\nMerge linked computers into components with union-find and count each component's size plus how many initially infected nodes it holds. Removing a candidate only helps when its component has no other infection source, in which case the whole component is rescued. Choose the candidate rescuing the largest component, preferring the smaller index on ties (zero rescued when every candidate shares its component, which still falls back to the smallest index).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) to union over the adjacency matrix, plus near-constant finds.\n- **Space Complexity:** O(n) for the union-find arrays.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n n = len(graph)\n parent = list(range(n))\n def find(x):\n while parent[x] != x:\n parent[x] = parent[parent[x]]\n x = parent[x]\n return x\n for i in range(n):\n for j in range(i + 1, n):\n if graph[i][j] == 1:\n parent[find(i)] = find(j)\n size = [0] * n\n for i in range(n):\n size[find(i)] += 1\n infected = [0] * n\n for v in initial:\n infected[find(v)] += 1\n best, best_saved = min(initial), -1\n for v in initial:\n saved = size[find(v)] if infected[find(v)] == 1 else 0\n if saved > best_saved or (saved == best_saved and v < best):\n best_saved, best = saved, v\n return best\n```\n", "starter": {"go": "package main\n\nfunc MinMalwareSpread(graph [][]int, initial []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n return 0;\n }\n};"}, "fn": "minMalwareSpread", "params": [{"name": "graph", "type": "int_array_2d"}, {"name": "initial", "type": "int_array"}], "outputType": "int", "tests": [["[[1,1,0],[1,1,0],[0,0,1]]", "[0,1]"], ["[[1,0,0],[0,1,0],[0,0,1]]", "[0,2]"], ["[[1,1,1],[1,1,1],[1,1,1]]", "[1,2]"], ["[[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]]", "[0,3]"], ["[[1, 1, 1, 0, 1, 1], [1, 1, 0, 0, 1, 0], [1, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 1], [1, 1, 0, 0, 1, 1], [1, 0, 0, 1, 1, 1]]", "[3, 1, 0, 4]"], ["[[1, 0], [0, 1]]", "[1]"], ["[[1, 1, 0, 1, 0], [1, 1, 1, 1, 0], [0, 1, 1, 0, 0], [1, 1, 0, 1, 1], [0, 0, 0, 1, 1]]", "[0, 1, 3, 4]"], ["[[1, 0, 1], [0, 1, 0], [1, 0, 1]]", "[2]"], ["[[1, 0], [0, 1]]", "[0]"], ["[[1, 0, 0, 1, 0, 1, 1, 1], [0, 1, 1, 1, 0, 1, 1, 1], [0, 1, 1, 1, 1, 0, 1, 0], [1, 1, 1, 1, 1, 0, 0, 1], [0, 0, 1, 1, 1, 0, 1, 0], [1, 1, 0, 0, 0, 1, 0, 0], [1, 1, 1, 0, 1, 0, 1, 1], [1, 1, 0, 1, 0, 0, 1, 1]]", "[0, 2, 5, 4, 7, 3]"], ["[[1, 0, 0, 1, 1, 0], [0, 1, 0, 0, 0, 1], [0, 0, 1, 0, 1, 1], [1, 0, 0, 1, 1, 0], [1, 0, 1, 1, 1, 1], [0, 1, 1, 0, 1, 1]]", "[0, 1, 4, 2, 3]"], ["[[1, 0, 1], [0, 1, 1], [1, 1, 1]]", "[0]"], ["[[1, 1, 1, 0, 0, 1], [1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 0, 1], [0, 0, 1, 1, 1, 0], [0, 1, 0, 1, 1, 0], [1, 1, 1, 0, 0, 1]]", "[2, 3, 0, 5, 4]"], ["[[1, 1, 1, 1, 0, 1], [1, 1, 0, 0, 0, 1], [1, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 0], [0, 0, 1, 0, 1, 1], [1, 1, 0, 0, 1, 1]]", "[0, 3, 5]"], ["[[1, 1], [1, 1]]", "[1]"], ["[[1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 1, 1], [1, 0, 1, 0, 0, 1], [0, 1, 0, 1, 1, 1], [1, 1, 0, 1, 1, 1], [0, 1, 1, 1, 1, 1]]", "[0, 1, 2, 3]"], ["[[1, 0, 0, 0, 1, 0], [0, 1, 1, 1, 1, 1], [0, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0], [1, 1, 1, 0, 1, 1], [0, 1, 0, 0, 1, 1]]", "[2, 5, 1]"], ["[[1, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0, 1], [0, 0, 1, 1, 0, 1, 0, 1], [0, 0, 1, 1, 0, 1, 0, 1], [0, 1, 0, 0, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 0, 1]]", "[3, 7, 1, 6, 0, 5, 2]"], ["[[1, 1], [1, 1]]", "[1]"], ["[[1, 1, 0, 0, 0, 0], [1, 1, 0, 1, 0, 0], [0, 0, 1, 1, 0, 1], [0, 1, 1, 1, 1, 0], [0, 0, 0, 1, 1, 0], [0, 0, 1, 0, 0, 1]]", "[1, 4, 0]"], ["[[1, 0, 0, 0, 1, 1], [0, 1, 1, 1, 1, 1], [0, 1, 1, 0, 1, 0], [0, 1, 0, 1, 0, 0], [1, 1, 1, 0, 1, 0], [1, 1, 0, 0, 0, 1]]", "[0, 1, 2, 3, 5]"], ["[[1, 0, 0, 1, 1, 1], [0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 1, 1], [1, 0, 0, 1, 0, 0], [1, 1, 1, 0, 1, 0], [1, 0, 1, 0, 0, 1]]", "[1, 2, 3]"], ["[[1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 0, 1, 0, 0], [1, 0, 1, 1, 0, 1, 0], [1, 0, 1, 1, 0, 1, 1], [0, 1, 0, 0, 1, 1, 0], [1, 0, 1, 1, 1, 1, 1], [0, 0, 0, 1, 0, 1, 1]]", "[1, 2, 3, 5, 6]"], ["[[1, 0], [0, 1]]", "[1]"], ["[[1, 0], [0, 1]]", "[1]"], ["[[1, 1, 1, 0], [1, 1, 1, 1], [1, 1, 1, 1], [0, 1, 1, 1]]", "[0, 1, 3]"], ["[[1, 1], [1, 1]]", "[1]"], ["[[1, 1, 1, 0, 1], [1, 1, 1, 1, 0], [1, 1, 1, 1, 0], [0, 1, 1, 1, 0], [1, 0, 0, 0, 1]]", "[3, 4]"]], "expected": [0, 0, 1, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 3], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "774", "slug": "minimize-max-distance-to-gas-station", "id": 774, "title": "Minimize Max Distance to Gas Station", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/minimize-max-distance-to-gas-station/", "examples": [{"input": "stations = [1,2,3,4,5,6,7,8,9,10], k = 9", "output": "\"0.5\"", "explanation": "Halve every unit gap."}, {"input": "stations = [23,24,36,39,46,56,57,65,84,98], k = 1", "output": "\"14.0\"", "explanation": "Splitting 65-84 leaves 84-98 as the max."}, {"input": "stations = [1,10], k = 1", "output": "\"4.5\"", "explanation": "Halve the single gap."}], "hints": ["This is a portable adaptation: take integer stations and return the optimum as a double-parseable decimal string (tolerance 1e-5).", "Decide feasibility for a guess D: each gap of length g needs ceil(g / D) - 1 new stops; sum over gaps and compare with k.", "Feasibility is monotone in D, so binary-search the smallest feasible D (about 60 halvings from [0, 1e8])."], "statement": "You are given the sorted positions `stations` of existing gas stops on a line and an integer `k`. You may build at most `k` extra stops at any real-valued positions you choose.\n\nAfter placement, look at the gaps between consecutive stops (old and new). Your goal is to make the largest such gap as small as possible.\n\nBecause distances are fractional, this judge exchanges them as decimal strings: implement `minmaxGasDist(stations, k)` returning a finite decimal string parseable as a double. An answer is accepted when it lies within `1e-5` of the true optimum (absolute or relative).\n\n**Constraints:**\n- `2 <= stations.length <= 2000`\n- `0 <= stations[i] <= 10^8` and `stations` is strictly increasing\n- `1 <= k <= 10^5`\n- The output must be a finite decimal string parseable as a double\n", "solution": "## Approach\n\nFor a candidate cap D, each gap of length g can be tamed with ceil(g / D) - 1 added stops, so summing that need over all gaps tests whether k stops suffice. Feasibility shrinks monotonically as D grows, which makes the minimal feasible D searchable by binary search from 0 to 1e8. About eighty halvings settle far beyond the required precision, and the result is returned as a decimal string.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * log precision) with n gaps and ~80 feasibility scans.\n- **Space Complexity:** O(1) besides the input.\n\n## Implementation\n\n```python\nfrom typing import List\nimport math\nclass Solution:\n def minmaxGasDist(self, stations: List[int], k: int) -> str:\n def feasible(d: float) -> bool:\n need = 0\n for i in range(1, len(stations)):\n gap = stations[i] - stations[i - 1]\n need += int((gap - 1e-9) / d)\n if need > k:\n return False\n return need <= k\n lo, hi = 0.0, 1e8\n for _ in range(80):\n mid = (lo + hi) / 2\n if feasible(mid):\n hi = mid\n else:\n lo = mid\n return str(hi)\n```\n", "starter": {"go": "package main\n\nfunc MinmaxGasDist(stations []int, k int) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def minmaxGasDist(self, stations: List[int], k: int) -> str:\n pass\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string minmaxGasDist(vector<int>& stations, int k) {\n return \"\";\n }\n};"}, "fn": "minmaxGasDist", "params": [{"name": "stations", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "string", "tests": [["[1,2,3,4,5,6,7,8,9,10]", "9"], ["[23,24,36,39,46,56,57,65,84,98]", "1"], ["[1,10]", "1"], ["[0,100]", "1"], ["[0,100]", "3"], ["[0,10,20]", "1"], ["[1,2,3,4,5]", "1"], ["[10,20,30,40]", "2"], ["[0,5,10]", "2"], ["[1,100000000]", "1"], ["[0,1]", "1"], ["[0,2]", "1"], ["[5,15,25,35]", "5"], ["[1,5,10,15]", "2"], ["[0,10]", "9"], ["[2,4,8,16]", "3"], ["[100,200,300]", "10"], ["[0,1000]", "9"], ["[1,3,6,10,15]", "4"], ["[7,17,27,37,47]", "6"], ["[0,50,100]", "1"], ["[10,11,12,13,20]", "2"], ["[1,2]", "100"], ["[0,1000000]", "100"], ["[3,6,12,19,33]", "2"], ["[50,60,70,80,90,100]", "4"], ["[0,20,40,60,80,100]", "3"], ["[11,22,33,44]", "7"]], "expected": ["0.49999999950000007", "13.999999999000002", "4.499999999500001", "49.999999999500005", "24.999999999750003", "9.999999999000002", "0.9999999990000001", "9.999999999000002", "2.4999999995000004", "4.999999950000001E7", "0.49999999950000007", "0.9999999995000001", "4.999999999500001", "3.9999999990000004", "0.9999999999000001", "2.6666666663333336", "16.666666666500003", "99.99999999990001", "1.9999999995000002", "4.999999999500001", "49.99999999900001", "2.3333333330000006", "0.009900990089108986", "9900.990099009892", "6.999999999000001", "9.999999999000002", "19.999999999000003", "3.6666666663333336"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "589", "slug": "minimum-absolute-difference-in-bst", "id": 589, "title": "Minimum Absolute Difference in BST", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/minimum-absolute-difference-in-bst/", "examples": [{"input": "root = [4,2,6,1,3]", "output": "1", "explanation": "The pair (2,3) differs by 1, and no pair is closer."}, {"input": "root = [1,0,48,null,null,12,49]", "output": "1", "explanation": "The pair (48,49) differs by 1, the minimum over all pairs."}, {"input": "root = [1,null,2]", "output": "1", "explanation": "The only pair (1,2) differs by 1."}], "hints": ["An inorder walk of a BST visits values in ascending order.", "In a sorted sequence, the closest pair must be neighbors, so compare each value with its predecessor.", "Keep the previous value and the best gap seen; update both during the walk."], "statement": "You are given the root of a binary search tree (BST): for every node, all values in its left subtree are smaller and all values in its right subtree are larger. Return the smallest absolute difference between the values of any two nodes in the tree.\n\n**Constraints:**\n- The tree holds between 2 and 10^4 nodes.\n- `0 <= Node.val <= 10^5`\n- The tree is a valid BST with distinct values.\n", "solution": "## Approach\n\nAn inorder traversal of a binary search tree lists its values from smallest to largest. In sorted order the closest pair of values must sit next to each other, so a single pass comparing every value with its predecessor finds the minimum gap. The walk remembers the previous value and the tightest difference observed.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited once.\n- **Space Complexity:** O(h) for the recursion stack, where h is the tree height.\n\n## Implementation\n\n```python\nclass Solution:\n def getMinimumDifference(self, root) -> int:\n self.best = float('inf')\n self.prev = None\n def inorder(node):\n if not node:\n return\n inorder(node.left)\n if self.prev is not None:\n self.best = min(self.best, node.val - self.prev)\n self.prev = node.val\n inorder(node.right)\n inorder(root)\n return self.best\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc GetMinimumDifference(root *TreeNode) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def getMinimumDifference(self, root) -> int:\n pass\n", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n};\n*/\nclass Solution {\npublic:\n int getMinimumDifference(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "getMinimumDifference", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int", "tests": [["[4,2,6,1,3]"], ["[1,0,48,null,null,12,49]"], ["[1,null,2]"], ["[2,1,3]"], ["[5,3,7,2,4,6,8]"], ["[10,5,15,2,7,12,20]"], ["[0,-10,5,null,-3,null,9]"], ["[1,null,3,2]"], ["[236,104,701,null,227,null,911]"], ["[100,50,150,25,75,125,175]"], ["[7,3,9,1,5,null,10]"], ["[50,30,70,20,40,60,80]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[1,0,2]"], ["[3,1,4,null,2]"], ["[5,1,9,0,2,7,10]"], ["[20,10,30,5,15,25,35]"], ["[6,2,8,0,4,7,9,null,null,3,5]"], ["[45,20,60,10,30,55,70]"], ["[2,0,4,-1,1,3,5]"], ["[15,6,20,3,9,17,25]"], ["[11,5,18,2,8,14,22]"], ["[9,4,14,2,6,12,16]"], ["[27,14,40,7,20,33,47]"], ["[60,30,90,15,45,75,105]"], ["[4,1,7,0,2,5,9]"], ["[13,6,19,3,9,16,23]"], ["[99,49,149,24,74,124,174]"]], "expected": [1, 1, 1, 1, 1, 2, 3, 1, 9, 25, 1, 10, 1, 1, 1, 1, 5, 1, 5, 1, 2, 3, 2, 6, 15, 1, 3, 25], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "908", "slug": "minimum-add-to-make-parentheses-valid", "id": 908, "title": "Minimum Add to Make Parentheses Valid", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/", "examples": [{"input": "s = \"())\"", "output": "1", "explanation": "One extra ')' has no partner; adding a single '(' at the front balances it."}, {"input": "s = \"(((\"", "output": "3", "explanation": "Three unmatched opens each need a closing partner."}, {"input": "s = \"()\"", "output": "0", "explanation": "Already balanced."}, {"input": "s = \"()))((\"", "output": "4", "explanation": "The middle is balanced; the stray ')' needs one '(' and the two trailing '(' need two ')'."}], "hints": ["Track the current open balance: '(' raises it, ')' lowers it.", "A ')' arriving at balance 0 has no partner, so count one needed '(' and keep the balance at 0.", "Leftover open balance at the end needs that many ')' characters; add both counts."], "statement": "You are given a string `s` containing only `'('` and `')'`. In one move you may insert a single parenthesis at any position. Return the smallest number of moves that turns `s` into a balanced (valid) parenthesis string, where every opening bracket is closed by a later closing bracket in the usual nested order.\n\n**Constraints:**\n- `1 <= s.length <= 1000`\n- `s` consists of `'('` and `')'` only\n", "solution": "## Approach\n\nSweep once while holding the count of unmatched opens. A close with no open partner forces one inserted open; otherwise it cancels an open. Unmatched opens left at the end each force one inserted close, so the answer is the sum of both kinds of debt.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for a single pass.\n- **Space Complexity:** O(1) extra space.\n\n## Implementation\n\n```python\nclass Solution:\n def minAddToMakeValid(self, s: str) -> int:\n open_count = 0\n need = 0\n for c in s:\n if c == '(':\n open_count += 1\n elif open_count > 0:\n open_count -= 1\n else:\n need += 1\n return open_count + need\n```\n", "starter": {"go": "package main\n\nfunc MinAddToMakeValid(s string) int {\n \n}", "python": "class Solution:\n def minAddToMakeValid(self, s: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int minAddToMakeValid(string s) {\n return 0;\n }\n};"}, "fn": "minAddToMakeValid", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["())"], ["((("], ["()"], ["()))(("], ["("], [")"], ["(("], ["))"], ["()()"], ["(()"], ["())("], ["((()))"], ["(()())"], [")()("], ["))))"], ["(((("], ["()((()))"], [")("], ["()()()"], ["((())"], ["(()))("], [")())("], ["(()(()))"], [")))((("], ["()("], [")()"], ["((()()()))"], [")()())(()(()("]], "expected": [1, 3, 0, 4, 1, 1, 2, 2, 0, 1, 2, 0, 0, 2, 4, 4, 0, 2, 0, 1, 2, 3, 0, 6, 1, 1, 0, 5], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "949", "slug": "minimum-area-rectangle-ii", "id": 949, "title": "Minimum Area Rectangle II", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/minimum-area-rectangle-ii/", "examples": [{"input": "points = [[1,2],[2,1],[1,0],[0,1]]", "output": "2", "explanation": "The four points are the corners of a tilted square whose area is 2."}, {"input": "points = [[0,1],[2,1],[1,1],[1,0],[2,0]]", "output": "1", "explanation": "Points (1,0), (1,1), (2,0) and (2,1) outline a unit square of area 1."}, {"input": "points = [[0,3],[1,2],[3,1],[1,3],[2,1]]", "output": "0", "explanation": "No four of these points form a rectangle, so the answer is 0."}], "hints": ["Two segments are a rectangle's diagonals exactly when they share midpoint and length.", "Group point pairs by (midpoint, squared length) and check pairs within each group.", "All coordinates are integers, so the area is an exact integer \u2014 no floating point needed."], "statement": "Given a set of distinct points on the integer grid, consider every rectangle (of any tilt, not just axis-aligned) whose four corners all belong to the set. Return the smallest such rectangle's area, or 0 when no four points form a rectangle.\n\nAdaptation note: because all coordinates are integers, the area of any qualifying rectangle is always a whole number, so this task returns that exact integer area rather than a floating-point value.\n\n**Constraints:**\n- `1 <= points.length <= 50`\n- All points are distinct.\n- `0 <= points[i][0], points[i][1] <= 40000`\n- The points arrive as a 2D integer array.\n", "solution": "## Approach\n\nTwo segments form the diagonals of a rectangle exactly when they share the same midpoint and the same length. Group all point pairs by (midpoint, squared length); any two pairs in one group are candidate diagonals, and the area follows from the cross product of edge vectors built from three of the four endpoints. All arithmetic stays in integers, and the minimum positive area over every group is the answer (0 when no group yields one).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^4) worst-case pair-of-pair checks for n points (n <= 50 keeps this fast).\n- **Space Complexity:** O(n^2) for the diagonal groups.\n\n## Implementation\n\n```python\nclass Solution:\n def minAreaFreeRect(self, points: list[list[int]]) -> int:\n n = len(points)\n groups = {}\n for i in range(n):\n for j in range(i + 1, n):\n sx = points[i][0] + points[j][0]\n sy = points[i][1] + points[j][1]\n d = (points[i][0] - points[j][0]) ** 2 + (points[i][1] - points[j][1]) ** 2\n groups.setdefault((sx, sy, d), []).append((i, j))\n best = None\n for pairs in groups.values():\n for a in range(len(pairs)):\n for b in range(a + 1, len(pairs)):\n i, _ = pairs[a]\n k, l = pairs[b]\n ax, ay = points[i]\n area = abs((points[k][0] - ax) * (points[l][1] - ay)\n - (points[l][0] - ax) * (points[k][1] - ay))\n if area > 0 and (best is None or area < best):\n best = area\n return best if best is not None else 0\n```\n", "starter": {"go": "package main\n\nfunc MinAreaFreeRect(points [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minAreaFreeRect(self, points: List[List[int]]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int minAreaFreeRect(vector<vector<int>>& points) {\n return 0;\n }\n};"}, "fn": "minAreaFreeRect", "params": [{"name": "points", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,2],[2,1],[1,0],[0,1]]"], ["[[0,1],[2,1],[1,1],[1,0],[2,0]]"], ["[[0,3],[1,2],[3,1],[1,3],[2,1]]"], ["[[3,1],[1,1],[0,1],[2,1],[3,3],[3,2],[0,2],[2,3]]"], ["[[0,0],[1,1],[2,2]]"], ["[[0,0],[0,1],[1,0],[1,1]]"], ["[[0,0],[2,0],[2,2],[0,2],[1,1]]"], ["[[0,0],[1,0],[0,1]]"], ["[[0,0],[3,0],[3,4],[0,4]]"], ["[[1,1],[1,3],[3,1],[3,3],[2,2]]"], ["[[0,0],[2,1],[3,3],[1,2]]"], ["[[5,5]]"], ["[[0,0],[1,0]]"], ["[[0,0],[4,0],[4,3],[0,3],[2,1]]"], ["[[2,0],[0,2],[2,4],[4,2],[1,1],[3,3]]"], ["[[0,0],[1,2],[2,4],[3,6]]"], ["[[0,0],[5,0],[5,5],[0,5],[2,2],[3,3]]"], ["[[1,0],[0,1],[2,1],[1,2]]"], ["[[0,0],[6,0],[6,8],[0,8]]"], ["[[1,0],[0,1],[2,1],[1,2]]"], ["[[3,4],[7,4],[7,9],[3,9],[5,6]]"], ["[[0,0],[10,0],[10,1],[0,1]]"], ["[[4,4],[4,8],[8,8],[8,4],[6,6]]"], ["[[1,1],[4,5],[7,1],[4,2]]"], ["[[0,2],[2,0],[4,2],[2,4],[2,2]]"], ["[[9,9],[9,0],[0,9],[0,0]]"], ["[[1,3],[3,7],[7,3],[5,-1]]"], ["[[2,2],[5,6],[8,2],[5,-2]]"]], "expected": [2, 1, 0, 2, 0, 1, 4, 0, 12, 4, 0, 0, 0, 12, 4, 0, 25, 2, 48, 2, 20, 10, 16, 0, 8, 81, 0, 0], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "926", "slug": "minimum-area-rectangle", "id": 926, "title": "Minimum Area Rectangle", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/minimum-area-rectangle/", "examples": [{"input": "points = [[1,1],[1,3],[3,1],[3,3],[2,2]]", "output": "4", "explanation": "The outer four points form a 2 by 2 square."}, {"input": "points = [[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]", "output": "2", "explanation": "Columns 3 and 4 with rows 1 and 3 give area 2."}, {"input": "points = [[1,1],[2,2],[3,3]]", "output": "0", "explanation": "No four points align into a rectangle."}], "hints": ["A pair of points can be a diagonal only when both x and y differ.", "The other two corners (x1,y2) and (x2,y1) must both exist; a hash set makes this O(1).", "Track the minimum width-times-height; 1 is the smallest possible positive area."], "statement": "You are given distinct points on a 2D plane. An axis-aligned rectangle uses four of the points as corners, with sides parallel to the axes.\n\nReturn the smallest area among all such rectangles, or `0` when none exists.\n\n**Constraints:**\n- `1 <= points.length <= 500`\n- Coordinates satisfy `0 <= x, y <= 40000`, all points distinct.\n", "solution": "## Approach\n\nStore every point in a hash set for O(1) lookups. Treat each pair as a potential diagonal: it defines a rectangle exactly when the other two corners exist in the set. Track the minimum width-times-height over all valid diagonals.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), where n is the number of points. Each pair is checked once.\n- **Space Complexity:** O(n) for the point set.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minAreaRect(self, points: List[List[int]]) -> int:\n s = {(x, y) for x, y in points}\n best = float('inf')\n n = len(points)\n for i in range(n):\n x1, y1 = points[i]\n for j in range(i + 1, n):\n x2, y2 = points[j]\n if x1 == x2 or y1 == y2:\n continue\n if (x1, y2) in s and (x2, y1) in s:\n best = min(best, abs(x1 - x2) * abs(y1 - y2))\n if best == 1:\n return 1\n return 0 if best == float('inf') else best\n```\n", "starter": {"go": "package main\n\nfunc MinAreaRect(points [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minAreaRect(self, points: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int minAreaRect(vector<vector<int>>& points) {\n return 0;\n }\n};"}, "fn": "minAreaRect", "params": [{"name": "points", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,1],[1,3],[3,1],[3,3],[2,2]]"], ["[[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]"], ["[[1,1],[2,2],[3,3]]"], ["[[0,0],[0,1],[1,0],[1,1]]"], ["[[0,0],[0,2],[2,0],[2,2],[1,1]]"], ["[[0,0],[1,1],[2,2]]"], ["[[1,1]]"], ["[[0,0],[0,1],[1,0]]"], ["[[0,0],[0,10],[10,0],[10,10]]"], ["[[3,3],[3,5],[5,3],[5,5],[3,4]]"], ["[[0,0],[0,3],[2,0],[2,3],[0,1],[2,1]]"], ["[[1,0],[0,1],[1,1],[0,0]]"], ["[[0,0],[1,0],[0,1],[1,1],[2,0],[2,1]]"], ["[[0,0],[5,0],[0,5],[5,5],[2,2],[2,3],[3,2],[3,3]]"], ["[[0,0],[2,0],[0,2],[2,2],[1,0],[1,2]]"], ["[[1,1],[1,2],[2,1],[2,2],[3,1],[3,2]]"], ["[[0,0],[10,0],[0,1],[10,1]]"], ["[[0,0],[3,0],[0,4],[3,4]]"], ["[[5,5],[5,6],[6,5],[6,6]]"], ["[[0,1],[1,0],[1,1],[0,0],[2,0],[2,1]]"], ["[[100,100],[100,200],[200,100],[200,200]]"], ["[[0,0],[0,5],[5,0]]"], ["[[1,2],[2,1],[3,4],[4,3]]"], ["[[0,0],[0,4],[4,0],[4,4],[2,2]]"], ["[[1,1],[1,4],[4,1],[4,4],[2,2],[2,5],[5,2],[5,5]]"], ["[[0,0],[1,0],[2,0],[0,1],[1,1],[2,1]]"], ["[[7,7],[7,9],[9,7],[9,9],[8,8]]"], ["[[0,0],[0,6],[6,0],[6,6],[3,0],[3,6]]"]], "expected": [4, 2, 0, 1, 4, 0, 0, 0, 100, 4, 2, 1, 1, 1, 2, 1, 10, 12, 1, 1, 10000, 0, 0, 16, 9, 1, 4, 18], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "250", "slug": "minimum-array-end", "id": 250, "title": "Minimum Array End", "difficulty": "Medium", "category": "bit-manipulation", "link": "https://leetcode.com/problems/minimum-array-end/", "examples": [{"input": "n = 3, x = 4", "output": "6", "explanation": "The array [4, 5, 6] is valid since 4 AND 5 AND 6 = 4 and the elements are strictly increasing. 6 is the minimum possible value of nums[2]."}, {"input": "n = 2, x = 7", "output": "15", "explanation": "The array [7, 15] is valid since 7 AND 15 = 7 and the elements are strictly increasing. 15 is the minimum possible value of nums[1]."}], "hints": ["Every element in the array must contain all the set bits of x, since their bitwise AND must equal x.", "The minimum possible nums[n - 1] is formed by \"merging\" x with n - 1: keep the set bits of x, and place the bits of n - 1 into the lowest free (zero) bit positions of x.", "So the result is x with n - 1 inserted into its zero bits, which can exceed 32-bit range and must be computed in 64-bit."], "statement": "Two integers `n` and `x` are supplied. Consider positive-integer arrays `nums` of length `n` that climb strictly at each position, so `nums[i + 1]` is always larger than `nums[i]` for `0 <= i < n - 1`, and whose cumulative bitwise AND across all positions equals `x`.\n\nAmong every array meeting those two requirements, make the final entry `nums[n - 1]` as small as possible, and output that smallest achievable final value.\n\n**Constraints:**\n\n- `1 <= n, x <= 10^8`\n", "solution": "## Approach\n\nEvery element of `nums` must keep all of the set bits of `x`, because the AND of the whole array equals `x`. The minimum possible last element is built by \"merging\" `x` with the counter value `n - 1`: keep the bits of `x`, then insert the bits of `n - 1` into the lowest free (zero) positions of `x`, least significant first.\n\nSince the resulting value can exceed the 32-bit range (up to ~2^53 for the given constraints), it must be computed with 64-bit arithmetic.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1), bounded by the fixed bit width (at most ~64 iterations).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def minEnd(self, n: int, x: int) -> int:\n result = x\n remaining = n - 1\n bit = 1\n while remaining > 0:\n if (result & bit) == 0:\n result |= (remaining & 1) * bit\n remaining >>= 1\n bit <<= 1\n return result\n```", "starter": {"go": "package main\n\nfunc MinEnd(n int, x int) int64 {\n return 0\n}", "python": "class Solution:\n def minEnd(self, n: int, x: int) -> int:\n ", "cpp": "#include <cstdint>\nusing namespace std;\n\nclass Solution {\npublic:\n long long minEnd(int n, int x) {\n \n }\n};"}, "fn": "minEnd", "params": [{"name": "n", "type": "int"}, {"name": "x", "type": "int"}], "outputType": "string", "tests": [["3", "4"], ["2", "7"], ["1", "1"], ["1", "100000000"], ["2", "100000000"], ["100000000", "1"], ["100000000", "67108863"], ["100000000", "100000000"], ["5", "16"], ["1000", "1024"], ["99999999", "8"], ["100000000", "2"], ["7", "92274688"], ["4", "4"], ["2", "1"], ["3", "1"], ["4", "1"], ["5", "1"], ["2", "2"], ["3", "2"], ["4", "8"], ["6", "8"], ["10", "10"], ["8", "15"], ["16", "16"], ["2", "3"], ["3", "5"], ["10", "7"], ["100", "100"], ["50", "32"]], "expected": ["6", "15", "1", "100000000", "100000001", "199999999", "6710886399999999", "409632367103", "20", "2023", "199999998", "199999999", "92274694", "7", "3", "5", "7", "9", "3", "6", "11", "13", "43", "127", "31", "7", "13", "79", "871", "113"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "720", "slug": "minimum-ascii-delete-sum-for-two-strings", "id": 720, "title": "Minimum ASCII Delete Sum for Two Strings", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/", "examples": [{"input": "s1 = \"sea\", s2 = \"eat\"", "output": "231", "explanation": "Delete s from sea (115) and t from eat (116); the shared eat remains, costing 231."}, {"input": "s1 = \"delete\", s2 = \"leet\"", "output": "403", "explanation": "Keep the shared leet and remove the extra d and extra e costs, totaling 403."}, {"input": "s1 = \"a\", s2 = \"b\"", "output": "195", "explanation": "No character matches, so both letters are removed: 97 + 98."}], "hints": ["Think of the kept characters as a common subsequence; minimizing deletions equals maximizing kept ASCII sum.", "Use a 2D table where cell (i,j) holds the cheapest cost for the two prefixes ending there.", "When the current letters match, carry the diagonal value; otherwise drop the cheaper of the two single-side deletions."], "statement": "Given two strings, you may delete any characters from either string. Each deleted letter costs its ASCII code. After deletions the two results must read identically, and you want the smallest possible total price.\n\nKeeping a shared subsequence for free while paying for everything else is the goal. For instance, turning `sea` into `eat` keeps `ea` and pays for one `s` plus one `t`.\n\nReturn the minimum deletion cost.\n\n**Constraints:**\n- `1 <= s1.length, s2.length <= 1000`\n- Both strings contain lowercase English letters.\n", "solution": "## Approach\n\nFill a table over the two prefixes. The first row and column accumulate the cost of deleting everything on one side. For other cells, equal letters carry the diagonal value for free, while differing letters pay the cheaper of deleting from the first or the second string. The bottom-right cell is the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m*n), where m and n are the string lengths.\n- **Space Complexity:** O(m*n), reducible to O(min(m,n)) with rolling rows.\n\n## Implementation\n\n```python\nclass Solution:\n def minimumDeleteSum(self, s1: str, s2: str) -> int:\n m, n = len(s1), len(s2)\n dp = [[0]*(n+1) for _ in range(m+1)]\n for i in range(1, m+1):\n dp[i][0] = dp[i-1][0] + ord(s1[i-1])\n for j in range(1, n+1):\n dp[0][j] = dp[0][j-1] + ord(s2[j-1])\n for i in range(1, m+1):\n for j in range(1, n+1):\n if s1[i-1] == s2[j-1]:\n dp[i][j] = dp[i-1][j-1]\n else:\n dp[i][j] = min(dp[i-1][j] + ord(s1[i-1]), dp[i][j-1] + ord(s2[j-1]))\n return dp[m][n]\n```\n", "starter": {"go": "package main\n\nfunc MinimumDeleteSum(s1 string, s2 string) int {\n return 0\n}", "python": "class Solution:\n def minimumDeleteSum(self, s1: str, s2: str) -> int:\n return 0", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int minimumDeleteSum(string s1, string s2) {\n return 0;\n }\n};"}, "fn": "minimumDeleteSum", "params": [{"name": "s1", "type": "string"}, {"name": "s2", "type": "string"}], "outputType": "int", "tests": [["sea", "eat"], ["delete", "leet"], ["a", "b"], ["a", "a"], ["abc", "abc"], ["abc", "def"], ["", ""], ["a", ""], ["", "abc"], ["x", "x"], ["ab", "ba"], ["aaa", "aa"], ["hello", "world"], ["abcd", "efgh"], ["zzzz", "zzzz"], ["abcde", "ace"], ["eat", "sea"], ["aab", "abb"], ["longstringtest", "anotherlongtest"], ["qwerty", "qwerty"], ["ab", "ab"], ["a", "ab"], ["ab", "a"], ["mx", "xm"], ["abcdefgh", "hgfedcba"], ["aaaa", "bbbb"], ["abcdabcd", "abcd"], ["xyz", "xyz"]], "expected": [231, 403, 195, 0, 0, 597, 0, 97, 294, 0, 194, 97, 862, 804, 0, 198, 231, 195, 1172, 0, 0, 98, 98, 218, 1400, 780, 394, 0], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "966", "slug": "minimum-cost-for-tickets", "id": 966, "title": "Minimum Cost For Tickets", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/minimum-cost-for-tickets/", "examples": [{"input": "days = [1,4,6,7,8,20], costs = [2,7,15]", "output": "11", "explanation": "A 7-day pass covering days 4-10 plus two 1-day passes totals 7+2+2 = 11."}, {"input": "days = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]", "output": "17", "explanation": "Combining weekly and daily passes optimally costs 17."}], "hints": ["Build day-by-day costs over the calendar year: non-travel days copy the previous total.", "On a travel day take the cheapest of yesterday plus a 1-day pass, 7 days back plus a weekly pass, or 30 days back plus a monthly pass.", "A boolean travel-day lookup makes the scan O(365)."], "statement": "You plan to travel on the calendar days listed in the strictly increasing array `days`. There are three pass kinds with prices in `costs`: `costs[0]` covers one day, `costs[1]` covers any 7 consecutive days, and `costs[2]` covers any 30 consecutive days. A pass can start on any day and covers that day plus the following days in its window.\n\nBuy passes so that every listed travel day is covered with the smallest possible total price. Return that minimum price.\n\n**Constraints:**\n- `1 <= days.length <= 365`\n- `1 <= days[i] <= 365`, strictly increasing.\n- `1 <= costs.length == 3`, `1 <= costs[i] <= 1000`.\n", "solution": "## Approach\n\nMark the travel days on a 365-day calendar and sweep forward with dynamic programming. Days without travel inherit the previous cost. On travel days, compare buying a 1-day pass from yesterday, a 7-day pass from seven days back, and a 30-day pass from thirty days back, keeping the cheapest. The table entry at day 365 is the optimum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(365) = O(1) bounded calendar work plus O(days) to mark travel.\n- **Space Complexity:** O(365) = O(1) for the calendar and DP arrays.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def mincostTickets(self, days: List[int], costs: List[int]) -> int:\n travel = [False] * 366\n for d in days:\n travel[d] = True\n dp = [0] * 366\n for d in range(1, 366):\n if not travel[d]:\n dp[d] = dp[d - 1]\n else:\n dp[d] = min(dp[d - 1] + costs[0], dp[max(0, d - 7)] + costs[1], dp[max(0, d - 30)] + costs[2])\n return dp[365]\n```\n", "starter": {"go": "package main\n\nfunc MincostTickets(days []int, costs []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def mincostTickets(self, days: List[int], costs: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int mincostTickets(vector<int>& days, vector<int>& costs) {\n return 0;\n }\n};"}, "fn": "mincostTickets", "params": [{"name": "days", "type": "int_array"}, {"name": "costs", "type": "int_array"}], "outputType": "int", "tests": [["[1,4,6,7,8,20]", "[2,7,15]"], ["[1,2,3,4,5,6,7,8,9,10,30,31]", "[2,7,15]"], ["[1]", "[2,7,15]"], ["[365]", "[2,7,15]"], ["[1,2,3,4,5,6,7]", "[2,7,15]"], ["[1,10,20,30]", "[2,7,15]"], ["[1,2,3,4,5]", "[5,10,20]"], ["[1,4,6,7,8,20]", "[7,2,15]"], ["[1,4,6,7,8,20]", "[2,7,1]"], ["[6,8,9,18,20,21,23,25]", "[2,7,15]"], ["[1,2,3,4,30,31]", "[2,7,15]"], ["[1,2,3,28,29,30]", "[2,7,15]"], ["[10,20,30,40,50]", "[3,8,20]"], ["[1,3,5,7,9]", "[1,4,10]"], ["[100,101,102,200,201]", "[2,7,15]"], ["[1,2,3,4,5,6,7,8]", "[1,4,10]"], ["[50]", "[10,20,30]"], ["[1,30,31,60,61,90]", "[2,7,15]"], ["[1,2,3,4,5,6,7,28,29,30]", "[2,7,15]"], ["[200,201,202,203]", "[5,5,5]"], ["[1,5,9,13,17,21]", "[2,7,15]"], ["[1,2,3,4,5,6,7,8,9,10]", "[2,7,15]"], ["[15,16,17,18,19,20,21]", "[2,7,15]"], ["[1,365]", "[2,7,15]"], ["[100,110,120,130,140]", "[2,7,15]"], ["[1,2,30,31,60]", "[4,9,20]"], ["[5,6,7,28,29,30,31]", "[2,7,15]"], ["[1,4,6,7,8,20,21,22,23,24]", "[2,7,15]"]], "expected": [11, 17, 2, 2, 7, 8, 10, 6, 1, 15, 11, 12, 15, 5, 10, 5, 10, 12, 13, 5, 12, 13, 7, 4, 10, 20, 13, 15], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "853", "slug": "minimum-cost-to-hire-k-workers", "id": 853, "title": "Minimum Cost to Hire K Workers", "difficulty": "Hard", "category": "heap", "link": "https://leetcode.com/problems/minimum-cost-to-hire-k-workers/", "examples": [{"input": "quality = [10,20,5], wage = [70,50,30], k = 2", "output": "\"105.0\"", "explanation": "Pick qualities 5 and 10 at rate 7 for payments 35 and 70."}, {"input": "quality = [3,1,10,10,1], wage = [4,8,2,2,7], k = 3", "output": "\"30.66667\"", "explanation": "The cheapest feasible trio costs about 30.67 within tolerance."}, {"input": "quality = [5], wage = [10], k = 1", "output": "\"10.0\"", "explanation": "Only one choice, paid exactly the asking wage."}], "hints": ["This is a portable adaptation: return the minimum cost as a finite, double-parseable decimal string.", "Sort candidates by the ratio wage / quality. Once the rate is fixed by the last person in order, earlier people are cheaper to include when their quality is small.", "Scan the sorted order while keeping the `k` smallest qualities seen so far in a max-heap; the candidate cost at each step is heap-sum times the current ratio, and the best over all steps wins."], "statement": "You are given two arrays, `quality` and `wage`, each with `n` entries describing `n` candidates. Candidate `i` produces `quality[i]` units of work and asks for at least `wage[i]` in pay. You must hire exactly `k` people.\n\nAll hired people are paid under one common rate `r` (pay per unit of quality), so person `i` receives `r * quality[i]`. The rate must be high enough that everyone hired gets at least what they asked for. Among all choices of `k` people and all feasible rates, minimize the total payroll.\n\nBecause the answer can be fractional, return it as a finite decimal string (for example `\"105.0\"`). A response is accepted when it matches the true minimum within a small tolerance.\n\nAdaptation note: the original task expects a floating number; here you return the value encoded as a decimal string so every language uses the same `string` type.\n\n**Constraints:**\n- `1 <= k <= n <= 10^4`\n- `1 <= quality[i], wage[i] <= 10^4`\n", "solution": "## Approach\n\nPay is governed by the largest wage-to-quality ratio in the hired group, so sorting everyone by that ratio turns the problem into picking the cheapest companions for each possible rate-setter. While scanning the sorted order, keep the `k` smallest qualities seen so far with a max-heap and track their sum; multiplying the sum by the current ratio gives the cheapest total using the current person as the rate. The minimum over the scan is the answer, returned as a decimal string.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting plus O(n log k) heap work.\n- **Space Complexity:** O(n) for the ordering and O(k) for the heap.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\n\nclass Solution:\n def mincostToHireWorkers(self, quality: List[int], wage: List[int], k: int) -> str:\n order = sorted(range(len(quality)), key=lambda i: wage[i] / quality[i])\n heap = []\n sum_q = 0\n best = float('inf')\n for i in order:\n heapq.heappush(heap, -quality[i])\n sum_q += quality[i]\n if len(heap) > k:\n sum_q += heapq.heappop(heap)\n if len(heap) == k:\n best = min(best, sum_q * wage[i] / quality[i])\n return str(best)\n```\n", "starter": {"go": "package main\n\nfunc MincostToHireWorkers(quality []int, wage []int, k int) string {\n return \"0.0\"\n}", "python": "from typing import List\n\nclass Solution:\n def mincostToHireWorkers(self, quality: List[int], wage: List[int], k: int) -> str:\n return \"0.0\"\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n string mincostToHireWorkers(vector<int>& quality, vector<int>& wage, int k) {\n return \"0.0\";\n }\n};"}, "fn": "mincostToHireWorkers", "params": [{"name": "quality", "type": "int_array"}, {"name": "wage", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "string", "tests": [["[10,20,5]", "[70,50,30]", "2"], ["[3,1,10,10,1]", "[4,8,2,2,7]", "3"], ["[5]", "[10]", "1"], ["[10,20]", "[30,40]", "1"], ["[1,2,3]", "[10,20,30]", "2"], ["[4,4,4]", "[10,10,10]", "3"], ["[1,1,1,1]", "[5,4,3,2]", "2"], ["[2,3,5]", "[10,10,10]", "2"], ["[10000,10000]", "[10000,10000]", "2"], ["[1,100]", "[100,1]", "1"], ["[1,2,3,4,5]", "[5,4,3,2,1]", "3"], ["[7,7,7,7]", "[14,21,7,28]", "2"], ["[25,30,35]", "[100,120,140]", "2"], ["[3,3,3]", "[9,6,12]", "2"], ["[10,10,10,10]", "[1,2,3,4]", "3"], ["[5,10,15,20]", "[50,30,40,60]", "2"], ["[2,2,2,2,2]", "[3,3,3,3,10]", "4"], ["[1,2]", "[2,3]", "2"], ["[6,8,10]", "[12,16,20]", "1"], ["[9,8,7]", "[18,16,21]", "3"], ["[4,5,6,7]", "[8,10,12,14]", "2"], ["[100,200,300]", "[150,250,350]", "3"], ["[1,1,10]", "[2,3,20]", "2"], ["[5,5,5,5,5]", "[10,20,30,40,50]", "3"], ["[2,4,6,8]", "[4,8,12,16]", "4"], ["[3,6,9]", "[5,10,15]", "2"], ["[7,3,9,2]", "[21,9,27,6]", "3"], ["[10,20,30,40,50]", "[70,50,30,80,60]", "2"]], "expected": ["105.0", "30.666666666666664", "10.0", "30.0", "30.0", "30.0", "6.0", "25.0", "20000.0", "1.0", "12.0", "28.0", "220.0", "18.0", "9.0", "75.0", "12.0", "6.0", "12.0", "72.0", "18.0", "900.0", "6.0", "90.0", "40.0", "15.0", "36.0", "96.0"], "loose": false}
|