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": "520", "slug": "minimum-moves-to-equal-array-elements", "id": 520, "title": "Minimum Moves to Equal Array Elements", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/minimum-moves-to-equal-array-elements/", "examples": [{"input": "nums = [1,2,3]", "output": "3", "explanation": "Three moves raise everything to 4."}, {"input": "nums = [1,1,1]", "output": "0", "explanation": "Already equal."}], "hints": ["Adding 1 to n-1 entries is the same as subtracting 1 from the one left out.", "So every entry must drop to the current minimum, costing nums[i]-min each.", "The answer is the sum minus min times n."], "statement": "You are given an integer list `nums`. In one move you may pick any `n-1` entries and add `1` to each of them, where `n` is the list length.\n\nFind the smallest number of moves that makes all entries equal.\n\nRaising `n-1` entries by one has the same effect as lowering the single untouched entry by one, so the task equals dragging every value down to the minimum.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `-10^9 <= nums[i] <= 10^9`\n- The answer fits in a 32-bit signed integer.\n", "solution": "## Approach\n\nIncrementing `n-1` entries is equivalent to decrementing the single skipped entry. Hence each value must fall to the current minimum, needing `nums[i]-min` steps. Adding over all positions gives `sum - min*n`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one pass for the minimum and sum.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minMoves(self, nums: List[int]) -> int:\n m = min(nums)\n return sum(nums) - m * len(nums)\n```\n", "starter": {"go": "package main\n\nfunc MinMoves(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minMoves(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minMoves(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "minMoves", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,3]"], ["[1,1,1]"], ["[1,2]"], ["[5]"], ["[1,1000000000]"], ["[1,2,3,4]"], ["[5,5,5,6]"], ["[-1,0,1]"], ["[0,0,0]"], ["[3,3,3,3,4]"], ["[1,2147483647]"], ["[-1000000000,1000000000]"], ["[4,4,4,4]"], ["[2,3,5,7]"], ["[2,2,2,2,2]"], ["[1,2,3,4,5]"], ["[0,1]"], ["[10,20]"], ["[7,7,8,8]"], ["[100,1]"], ["[0,0,1]"], ["[-5,-5,-5]"], ["[3,1,2]"], ["[9,1,1,1]"], ["[5,10,15]"], ["[0,5,5,5]"], ["[2,4,6,8]"], ["[100,100,101]"]], "expected": [3, 0, 1, 0, 999999999, 6, 1, 3, 0, 1, 2147483646, 2000000000, 0, 9, 0, 10, 1, 10, 2, 99, 1, 0, 3, 8, 15, 15, 12, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "519", "slug": "minimum-number-of-arrows-to-burst-balloons", "id": 519, "title": "Minimum Number of Arrows to Burst Balloons", "difficulty": "Medium", "category": "interval", "link": "https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/", "examples": [{"input": "points = [[10,16],[2,8],[1,6],[7,12]]", "output": "2", "explanation": "Arrows at 6 and 12 pop all."}, {"input": "points = [[1,2],[3,4],[5,6],[7,8]]", "output": "4", "explanation": "Disjoint spans need separate arrows."}, {"input": "points = [[1,2],[2,3],[3,4],[4,5]]", "output": "2", "explanation": "Touching endpoints share an arrow."}], "hints": ["Order balloons by right endpoint; the earliest finishing balloon dictates the first arrow.", "Place an arrow at that endpoint, skip every balloon it hits, then repeat.", "Touching endpoints overlap, so only a strictly greater start needs a new arrow."], "statement": "You are given balloons as segments `points`, where each entry `[xstart, xend]` spans that closed interval on a line. One arrow shot straight up at position `x` pops every balloon whose span contains `x`.\n\nFind the smallest number of arrows that pop all balloons.\n\n**Constraints:**\n- `1 <= points.length <= 10^5`\n- Each entry has two values with `-2^31 <= xstart <= xend <= 2^31 - 1`.\n", "solution": "## Approach\n\nSort all spans by right endpoint. Shoot the first arrow at the earliest finishing end, which hits every balloon starting at or before it. Move to the first unhit balloon and repeat. This greedy choice leaves maximal room for the rest, so it uses the fewest arrows.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting, plus O(n) scanning.\n- **Space Complexity:** O(1) extra beyond sorting.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findMinArrowShots(self, points: List[List[int]]) -> int:\n if not points:\n return 0\n points = sorted(points, key=lambda p: p[1])\n arrows = 1\n end = points[0][1]\n for s, e in points[1:]:\n if s > end:\n arrows += 1\n end = e\n return arrows\n```\n", "starter": {"go": "package main\n\nfunc FindMinArrowShots(points [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def findMinArrowShots(self, points: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findMinArrowShots(vector<vector<int>>& points) {\n return 0;\n }\n};"}, "fn": "findMinArrowShots", "params": [{"name": "points", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[10,16],[2,8],[1,6],[7,12]]"], ["[[1,2],[3,4],[5,6],[7,8]]"], ["[[1,2],[2,3],[3,4],[4,5]]"], ["[[1,2]]"], ["[[1,2],[2,3]]"], ["[[3,9],[7,12],[3,8],[6,8],[9,10],[2,9],[0,9],[3,9],[0,6],[2,8]]"], ["[[1,9],[7,16],[2,5],[7,12]]"], ["[[-2147483648,2147483647]]"], ["[[1,10],[2,3],[4,5]]"], ["[[1,5],[2,6],[3,7],[4,8]]"], ["[[9,12],[1,10],[4,11],[8,12],[3,9],[6,9],[6,7]]"], ["[[2,3],[4,5],[6,7]]"], ["[[1,10]]"], ["[[1,3],[2,4],[3,5]]"], ["[[0,1],[0,1],[0,1]]"], ["[[-5,-1],[1,5]]"], ["[[1,2],[1,2],[3,4]]"], ["[[5,10],[1,6],[2,8]]"], ["[[0,10],[5,15],[10,20]]"], ["[[-10,10]]"], ["[[1,4],[2,3],[4,6],[5,7]]"], ["[[2,2],[2,2],[2,2]]"], ["[[1,5],[6,10],[11,15],[16,20]]"], ["[[3,5],[3,5],[4,6]]"], ["[[0,2],[1,3],[2,4],[3,5],[4,6]]"], ["[[-2147483648,-1000000],[1000000,2147483647]]"], ["[[1,100],[2,50],[3,40],[4,30]]"], ["[[7,10],[1,2],[3,4],[5,6]]"]], "expected": [2, 4, 2, 1, 1, 2, 2, 1, 2, 1, 2, 3, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1, 4, 1, 2, 2, 1, 4], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "977", "slug": "minimum-number-of-k-consecutive-bit-flips", "id": 977, "title": "Minimum Number of K Consecutive Bit Flips", "difficulty": "Hard", "category": "greedy", "link": "https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/", "examples": [{"input": "nums = [0,1,0], k = 1", "output": "2", "explanation": "Flip index 0, then flip index 2."}, {"input": "nums = [1,1,0], k = 2", "output": "-1", "explanation": "No sequence of length-2 flips can fix the last zero."}, {"input": "nums = [0,0,0,1,0,1,1,0], k = 3", "output": "3", "explanation": "Flip starting at 0, then at 4, then at 5."}], "hints": ["Scan left to right: when position i is effectively 0, the only move that can still fix it starts at i, so flip there.", "Track active flips with a running count plus a marker array (or queue) instead of flipping k cells each time.", "If a zero is needed but fewer than k cells remain, the answer is -1."], "statement": "You are given a binary array `nums` and an integer `k`. In one move you may pick\nany `k` consecutive elements and flip every bit in that window (`0` becomes\n`1` and `1` becomes `0`).\n\nReturn the smallest number of moves that turns every element into `1`. If it\nis impossible, return `-1`.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `nums[i]` is `0` or `1`.\n- `1 <= k <= nums.length`\n", "solution": "## Approach\n\nDecide the flips greedily from left to right. When position `i` is reached,\nevery flip that could still cover it except one starting at `i` has already\nbeen fixed, so if the current effective bit is `0` there is no choice but to\nstart a flip at `i`. Maintain the number of currently active flips with a\nrunning counter: a flip started at `i` stops affecting positions `k` steps\nlater, which a marker array records. If a needed flip would run past the end\nof the array, the task is impossible.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `nums`. Each position is handled once.\n- **Space Complexity:** O(n) for the flip-start markers.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minKBitFlips(self, nums: List[int], k: int) -> int:\n n = len(nums)\n started = [0] * n\n active = 0\n ans = 0\n for i in range(n):\n if i >= k:\n active -= started[i - k]\n if (nums[i] + active) % 2 == 0:\n if i + k > n:\n return -1\n started[i] = 1\n active += 1\n ans += 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MinKBitFlips(nums []int, k int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minKBitFlips(self, nums: List[int], k: int) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minKBitFlips(vector<int>& nums, int k) {\n return 0;\n }\n};"}, "fn": "minKBitFlips", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int", "tests": [["[0,1,0]", "1"], ["[1,1,0]", "2"], ["[0,0,0,1,0,1,1,0]", "3"], ["[1,1,1]", "2"], ["[0,0,0]", "3"], ["[0,0,0]", "1"], ["[0]", "1"], ["[1]", "1"], ["[1,0,0,1]", "2"], ["[0,1,1,0,1]", "2"], ["[1,0,1,0,1,0]", "2"], ["[0,0,1,0,0]", "2"], ["[1,1,0,0,1,1]", "3"], ["[0,1,0,1,0,1,0]", "2"], ["[0,0,0,0]", "2"], ["[1,0,0,0,1]", "3"], ["[0,0,0,0,0]", "5"], ["[1,0,0,0,0]", "5"], ["[0,1]", "2"], ["[1,1]", "2"], ["[0,0]", "2"], ["[1,0,1]", "3"], ["[0,0,1]", "3"], ["[0,0,0,1,1]", "2"], ["[1,1,1,0,0,0]", "3"], ["[0,1,0,0,1,0,1,1]", "4"], ["[1,0,0,1,0,0,1,0]", "3"], ["[0,0,1,1,0,1,0,0,1]", "3"]], "expected": [2, -1, 3, 0, 1, 3, 1, 0, 1, 3, -1, 2, -1, 4, 2, 1, 1, -1, -1, 0, 1, -1, -1, -1, 1, 3, -1, -1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "865", "slug": "minimum-number-of-refueling-stops", "id": 865, "title": "Minimum Number of Refueling Stops", "difficulty": "Hard", "category": "heap", "link": "https://leetcode.com/problems/minimum-number-of-refueling-stops/", "examples": [{"input": "target = 1, startFuel = 1, stations = []", "output": "0", "explanation": "Reached without stopping."}, {"input": "target = 100, startFuel = 1, stations = [[10,100]]", "output": "-1", "explanation": "Run out before the station."}, {"input": "target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]", "output": "2", "explanation": "Two well-chosen stops suffice."}], "hints": ["Think of fuel as reach: always drive as far as current fuel allows, refueling only when stuck.", "Keep every passed station's fuel in a max-heap; when you cannot reach the next point, pop the largest past offer.", "Each pop corresponds to one optimal stop, and empty heap with insufficient reach means impossibility."], "statement": "You start with `startFuel` units of fuel and must travel to a destination `target` units away along a straight road. Your car consumes one unit of fuel per unit of distance.\n\nAlong the way there are gas stations described by `stations`, where `stations[i] = [position, fuel]` means at distance `position` from the start you may stop once to gain `fuel` units. Each station can be used at most once, and you may skip stations.\n\nReturn the smallest number of stops needed to reach the destination. If the trip is impossible, return `-1`. Starting fuel counts as zero stops.\n\n**Constraints:**\n- `1 <= target, startFuel <= 10^9`\n- `0 <= stations.length <= 500`\n- `0 <= position <= target`\n- `1 <= fuel <= 10^5`\n- Positions are strictly increasing.\n", "solution": "## Approach\n\nDrive with current fuel while collecting every passed station's offer in a max-heap. When the destination is still beyond reach, redeem the largest collected offer; that greedy replacement is always safe because any solution must use some past station to get this far, and the largest one dominates. Count redemptions until the reach covers the target or the heap empties.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n), where n is the station count, for heap operations.\n- **Space Complexity:** O(n) for the heap.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\n\nclass Solution:\n def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:\n heap = []\n stops = 0\n i = 0\n fuel = startFuel\n n = len(stations)\n while fuel < target:\n while i < n and stations[i][0] <= fuel:\n heapq.heappush(heap, -stations[i][1])\n i += 1\n if not heap:\n return -1\n fuel += -heapq.heappop(heap)\n stops += 1\n return stops\n```\n", "starter": {"go": "package main\n\nfunc MinRefuelStops(target int, startFuel int, stations [][]int) int {\n return -1\n}", "python": "from typing import List\nclass Solution:\n def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minRefuelStops(int target, int startFuel, vector<vector<int>>& stations) {\n return -1;\n }\n};"}, "fn": "minRefuelStops", "params": [{"name": "target", "type": "int"}, {"name": "startFuel", "type": "int"}, {"name": "stations", "type": "int_array_2d"}], "outputType": "int", "tests": [["1", "1", "[]"], ["100", "1", "[[10,100]]"], ["100", "10", "[[10,60],[20,30],[30,30],[60,40]]"], ["10", "10", "[]"], ["10", "5", "[[5,5]]"], ["20", "5", "[[5,5],[10,5],[15,5]]"], ["100", "50", "[[25,25],[50,50]]"], ["100", "25", "[[25,25],[50,25],[75,25]]"], ["50", "10", "[[10,10],[20,10],[30,10],[40,10]]"], ["1000", "100", "[[100,100],[200,100],[300,100],[400,100],[500,100],[600,100]]"], ["100", "10", "[[10,10],[20,10],[30,10],[40,10],[50,10],[60,10]]"], ["15", "3", "[[3,5],[6,5],[9,5]]"], ["200", "50", "[[50,50],[100,50],[150,50]]"], ["120", "10", "[[10,90],[20,10],[90,10]]"], ["500", "100", "[[100,200],[200,100],[300,100]]"], ["60", "30", "[[30,30]]"], ["60", "20", "[[20,20],[40,20]]"], ["100", "1", "[]"], ["2", "1", "[[1,1]]"], ["100", "99", "[[1,1],[50,1]]"], ["100", "10", "[[10,90]]"], ["100", "10", "[[20,20],[40,40],[60,20]]"], ["1000", "1000", "[]"], ["100", "50", "[[10,10],[20,10],[30,10]]"], ["30", "10", "[[10,10],[15,10],[25,10]]"], ["40", "10", "[[10,30],[20,10],[30,10]]"], ["90", "10", "[[10,10],[20,10],[30,80]]"], ["150", "30", "[[30,30],[60,30],[90,30],[120,30]]"]], "expected": [0, -1, 2, 0, 1, 3, 1, 3, 4, -1, -1, 3, 3, 3, 3, 1, 2, -1, 1, 1, 1, -1, 0, -1, 2, 1, 3, 4], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "232", "slug": "minimum-path-sum", "id": 232, "title": "Minimum Path Sum", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/minimum-path-sum/", "examples": [{"input": "grid = [[1,3,1],[1,5,1],[4,2,1]]", "output": "7", "explanation": "Because the path 1 -> 3 -> 1 -> 1 -> 1 minimizes the sum."}, {"input": "grid = [[1,2,3],[4,5,6]]", "output": "12", "explanation": ""}], "hints": ["Use dynamic programming. dp[i][j] is the minimum sum reaching (i, j), computed as grid[i][j] plus the smaller of the sums from above and left.", "Initialize the first row and first column cumulatively since only one move direction is available along the borders."], "statement": "You are given an `m x n` table `grid` whose entries are all zero or positive. Starting in the upper-left corner, you must reach the lower-right corner, stepping only one cell downward or one cell rightward at a time. Among all such monotone routes, find the one whose visited cells add up to the smallest total, and return that total.\n\n**Constraints:**\n- m == grid.length\n- n == grid[i].length\n- 1 \u2264 m, n \u2264 200\n- 0 \u2264 grid[i][j] \u2264 200\n", "solution": "## Approach\n\nUse 2D dynamic programming. Let `dp[i][j]` be the minimum path sum to reach cell `(i, j)`. Because movement is only down or right, `dp[i][j] = grid[i][j] + min(dp[i - 1][j], dp[i][j - 1])`. Initialize the first row and first column with cumulative sums since only one direction is possible along the borders, then fill the rest in row-major order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), visiting each cell once.\n- **Space Complexity:** O(m * n) for the dp table (can be reduced to O(n) by updating in place).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minPathSum(self, grid: List[List[int]]) -> int:\n m, n = len(grid), len(grid[0])\n dp = [[0] * n for _ in range(m)]\n dp[0][0] = grid[0][0]\n for j in range(1, n):\n dp[0][j] = dp[0][j - 1] + grid[0][j]\n for i in range(1, m):\n dp[i][0] = dp[i - 1][0] + grid[i][0]\n for i in range(1, m):\n for j in range(1, n):\n dp[i][j] = grid[i][j] + min(dp[i - 1][j], dp[i][j - 1])\n return dp[m - 1][n - 1]\n```", "starter": {"go": "package main\n\nfunc MinPathSum(grid [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def minPathSum(self, grid: List[List[int]]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int minPathSum(vector<vector<int>>& grid) {\n \n }\n};"}, "fn": "minPathSum", "params": [{"name": "grid", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,3,1],[1,5,1],[4,2,1]]"], ["[[1,2,3],[4,5,6]]"], ["[[1]]"], ["[[0]]"], ["[[1,2]]"], ["[[5],[4]]"], ["[[0,0,0],[0,0,0],[0,0,0]]"], ["[[2,1,1],[1,1,1],[1,1,1]]"], ["[[1,1,1],[1,0,1],[1,1,1]]"], ["[[3,8,6,0,5,9,9,6]]"], ["[[7],[2],[5],[1],[8],[3]]"], ["[[1,2,3,4],[5,6,7,8],[9,10,11,12]]"], ["[[5,5,5],[5,5,5],[5,5,5],[5,5,5]]"], ["[[200,200],[200,200]]"], ["[[1,2,3],[1,2,3],[1,2,3],[1,2,3]]"], ["[[1,1,1,1],[1,1,1,1]]"], ["[[9,9,9],[9,9,9],[9,9,9]]"], ["[[1,2,3,4,5]]"], ["[[1],[2],[3],[4],[5]]"], ["[[5,1,5],[1,5,1],[5,1,5]]"], ["[[10,20],[30,40]]"], ["[[3,1,2],[4,5,6],[7,8,9]]"], ["[[1,100],[1,1]]"], ["[[2,2],[2,2],[2,2],[2,2]]"], ["[[4,4,4,4,4,4]]"], ["[[6],[6],[6]]"], ["[[13,7,5],[2,8,10],[11,3,6]]"], ["[[1,2],[3,4],[5,6],[7,8]]"], ["[[8,6,4],[2,3,1]]"], ["[[5,9,3,7],[2,6,4,8]]"]], "expected": [7, 12, 1, 0, 3, 9, 0, 6, 4, 46, 26, 30, 30, 600, 9, 5, 45, 15, 15, 17, 70, 21, 3, 10, 24, 18, 32, 21, 14, 25], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "174", "slug": "minimum-size-subarray-sum", "id": 174, "title": "Minimum Size Subarray Sum", "difficulty": "Medium", "category": "sliding-window", "link": "https://leetcode.com/problems/minimum-size-subarray-sum/", "examples": [{"input": "target = 7, nums = [2,3,1,2,4,3]", "output": "2", "explanation": "The subarray [4,3] has the minimal length 2."}, {"input": "target = 4, nums = [1,4,4]", "output": "1", "explanation": "The subarray [4] has the minimal length 1."}, {"input": "target = 11, nums = [1,1,1,1,1,1,1,1]", "output": "0", "explanation": "There is no subarray with sum >= 11."}], "hints": ["Use a sliding window with left and right pointers and a running sum.", "Expand right to reach the target, then shrink left to minimize the length while staying >= target."], "statement": "You are given an array `nums` containing only positive values and a positive threshold `target`. Look at all contiguous blocks inside `nums`. Determine the shortest block length whose elements add up to at least `target`. When no block reaches the threshold, return 0.\n\n**Constraints:**\n\n- 1 \u2264 target \u2264 10^9\n- 1 \u2264 nums.length \u2264 10^5\n- 1 \u2264 nums[i] \u2264 10^4\n", "solution": "## Approach\n\nUse a sliding window with `left` and `right` pointers and a running `sum`. Expand `right` to include new elements; whenever `sum >= target`, record the window length and shrink `left` to try a shorter valid window. Track the minimum length seen.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `nums`. Each element enters and leaves the window once.\n- **Space Complexity:** O(1). Only pointers and a running sum are used.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minSubArrayLen(self, target: int, nums: List[int]) -> int:\n best = float(\"inf\")\n left = 0\n s = 0\n for right, v in enumerate(nums):\n s += v\n while s >= target:\n best = min(best, right - left + 1)\n s -= nums[left]\n left += 1\n return 0 if best == float(\"inf\") else best\n```\n", "starter": {"go": "package main\n\nfunc MinSubArrayLen(target int, nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minSubArrayLen(self, target: int, nums: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minSubArrayLen(int target, vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "minSubArrayLen", "params": [{"name": "target", "type": "int"}, {"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["7", "[2,3,1,2,4,3]"], ["4", "[1,4,4]"], ["11", "[1,1,1,1,1,1,1,1]"], ["11", "[1,2,3,4,5]"], ["15", "[1,2,3,4,5]"], ["1", "[1]"], ["2", "[1]"], ["100", "[1,2,3,4,5,6,7,8,9,10]"], ["7", "[1,1,1,1,7]"], ["5", "[2,3,1,2,4,3]"], ["6", "[10,2,3]"], ["3", "[1,1,1]"], ["10", "[1,2,3,4,5,6]"], ["3", "[3]"], ["5", "[1,2,3]"], ["8", "[2,2,2,2]"], ["20", "[5,5,5,5]"], ["2", "[2]"], ["100", "[10,10,10,10,10,10,10,10,10,10]"], ["7", "[3,1,2,1,4]"], ["12", "[1,2,3,4,5,6]"], ["9", "[1,1,1,1,1,1,1,1,1,1]"], ["4", "[2,2,2]"], ["6", "[1,1,1,1,1,1]"], ["14", "[2,4,6,8]"], ["5", "[1,1,1,1,1]"], ["25", "[5,10,15]"], ["30", "[10,20,30]"], ["16", "[8,8,8]"], ["1", "[2,3,4]"]], "expected": [2, 1, 0, 3, 5, 1, 0, 0, 1, 2, 1, 3, 2, 1, 2, 4, 4, 1, 10, 3, 3, 9, 2, 6, 2, 5, 2, 1, 2, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "799", "slug": "minimum-swaps-to-make-sequences-increasing", "id": 799, "title": "Minimum Swaps To Make Sequences Increasing", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/", "examples": [{"input": "nums1 = [1,3,5,4], nums2 = [1,2,3,7]", "output": "1", "explanation": "One swap at the end fixes both arrays."}, {"input": "nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]", "output": "1", "explanation": "Swapping index 1 makes both strictly increasing."}, {"input": "nums1 = [1], nums2 = [2]", "output": "0", "explanation": "No swap is needed."}], "hints": ["Track two costs at each index: cheapest cost with no swap here versus with a swap here.", "From the previous pair, transition only when the order constraints allow keeping or crossing the two arrangements.", "Take the minimum of the two states at the final index."], "statement": "You are given two arrays `nums1` and `nums2` of equal length. At any index `i` you may exchange `nums1[i]` with `nums2[i]` at a cost of one swap; each position is decided independently.\n\nAfter all choices, both arrays must be strictly increasing from left to right. It is guaranteed that at least one pattern of swaps achieves this.\n\nReturn the smallest possible number of swaps.\n\n**Constraints:**\n- `1 <= nums1.length == nums2.length <= 1000`\n- `0 <= nums1[i], nums2[i] <= 2000`\n- A valid swap pattern always exists\n", "solution": "## Approach\n\nMaintain two running costs: the cheapest swaps so far with the current index left as-is, and with it swapped. For each new position, extend the prior states only when the increasing condition holds naturally (both arrays keep order) or crosswise (each current value exceeds the opposite previous value). The smaller of the two final states is optimal.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), a single pass with constant work per index.\n- **Space Complexity:** O(1), only two integers are carried forward.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n INF = 10 ** 9\n no_swap, swap = 0, 1\n for i in range(1, len(nums1)):\n new_no, new_swap = INF, INF\n if nums1[i] > nums1[i - 1] and nums2[i] > nums2[i - 1]:\n new_no = min(new_no, no_swap)\n new_swap = min(new_swap, swap + 1)\n if nums1[i] > nums2[i - 1] and nums2[i] > nums1[i - 1]:\n new_no = min(new_no, swap)\n new_swap = min(new_swap, no_swap + 1)\n no_swap, swap = new_no, new_swap\n return min(no_swap, swap)\n```\n", "starter": {"go": "package main\n\nfunc MinSwap(nums1 []int, nums2 []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minSwap(self, nums1: List[int], nums2: List[int]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minSwap(vector<int>& nums1, vector<int>& nums2) {\n return 0;\n }\n};"}, "fn": "minSwap", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}], "outputType": "int", "tests": [["[1, 3, 5, 4]", "[1, 2, 3, 7]"], ["[0, 3, 5, 8, 9]", "[2, 1, 4, 6, 9]"], ["[1]", "[2]"], ["[1, 2]", "[3, 4]"], ["[2, 1]", "[1, 2]"], ["[1, 3, 5]", "[1, 2, 3]"], ["[1, 2, 3]", "[1, 2, 3]"], ["[3, 4, 5]", "[1, 2, 3]"], ["[0, 4, 4, 5]", "[1, 2, 3, 6]"], ["[1, 5, 3, 4]", "[1, 2, 6, 7]"], ["[0, 1, 2]", "[0, 1, 2]"], ["[1, 2, 5, 6]", "[0, 3, 4, 7]"], ["[2, 3, 4]", "[1, 2, 3]"], ["[1, 4, 6]", "[2, 3, 5]"], ["[0, 2, 4, 6, 8]", "[1, 3, 5, 7, 9]"], ["[1, 3, 2, 4]", "[0, 2, 3, 5]"], ["[5, 6, 7]", "[1, 2, 10]"], ["[0, 7, 8]", "[1, 2, 9]"], ["[1, 2, 3, 4, 5]", "[6, 7, 8, 9, 10]"], ["[1, 3, 5, 7, 9]", "[2, 4, 6, 8, 10]"], ["[0, 3, 6, 9]", "[1, 2, 7, 10]"], ["[1, 2]", "[2, 3]"], ["[4, 5]", "[1, 6]"], ["[0, 1]", "[2, 3]"], ["[3, 5, 7, 9]", "[1, 4, 6, 10]"], ["[2, 4, 8]", "[1, 5, 6]"], ["[0, 5, 10]", "[1, 6, 11]"], ["[1, 4, 4, 9]", "[2, 3, 5, 10]"]], "expected": [1, 1, 0, 0, 1000000, 0, 0, 0, 1000000, 1, 0, 0, 0, 0, 0, 1000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "597", "slug": "minimum-time-difference", "id": 597, "title": "Minimum Time Difference", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/minimum-time-difference/", "examples": [{"input": "timePoints = [\"23:59\",\"00:00\"]", "output": "1", "explanation": "One minute apart across midnight."}, {"input": "timePoints = [\"00:00\",\"23:59\",\"00:00\"]", "output": "0", "explanation": "A repeated moment gives gap zero."}, {"input": "timePoints = [\"12:30\",\"15:45\",\"12:35\"]", "output": "5", "explanation": "12:30 and 12:35 are closest."}], "hints": ["Turn every \"HH:MM\" entry into minutes since midnight, then sort the numbers.", "The answer is the minimum of adjacent differences in sorted order plus the wrap-around gap (first + 1440 - last).", "A duplicate minute forces the answer to zero; with more than 1440 entries the answer is always zero."], "statement": "You are given a list of clock readings, each written as a five-character string `\"HH:MM\"` in 24-hour format (for example `\"05:30\"` or `\"23:59\"`).\n\nThink of the readings as points on a circular 24-hour dial with 1440 minutes. The gap between two readings is the smaller of the clockwise and counter-clockwise distances along the dial.\n\nReturn the smallest gap, in minutes, among every pair of readings. If two readings show the same moment, the answer is zero.\n\n**Constraints:**\n- `2 <= timePoints.length <= 2 * 10^4`\n- Each entry matches `\"HH:MM\"` with `00 <= HH <= 23` and `00 <= MM <= 59`\n\nAdaptation note: the original signature takes a list of strings; here it is modelled as `String[] timePoints` (`string_array`) with identical semantics.\n", "solution": "## Approach\n\nConvert each clock reading to minutes since midnight and sort the values. After sorting, the closest pair on a circle must either be neighbours in the sorted order or the wrap-around pair (last and first across midnight), so scan those gaps and keep the minimum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting n readings.\n- **Space Complexity:** O(n) for the minute values (O(1) extra besides the copy).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findMinDifference(self, timePoints: List[str]) -> int:\n mins = sorted(int(t[:2]) * 60 + int(t[3:]) for t in timePoints)\n best = 1440 - mins[-1] + mins[0]\n for i in range(1, len(mins)):\n best = min(best, mins[i] - mins[i - 1])\n return best\n```\n", "starter": {"go": "package main\n\nfunc FindMinDifference(timePoints []string) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findMinDifference(self, timePoints: List[str]) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int findMinDifference(vector<string>& timePoints) {\n return 0;\n }\n};"}, "fn": "findMinDifference", "params": [{"name": "timePoints", "type": "string_array"}], "outputType": "int", "tests": [["[\"23:59\",\"00:00\"]"], ["[\"00:00\",\"23:59\",\"00:00\"]"], ["[\"12:30\",\"15:45\",\"12:35\"]"], ["[\"00:00\",\"12:00\"]"], ["[\"01:01\",\"02:02\",\"03:03\"]"], ["[\"00:00\",\"00:01\"]"], ["[\"23:59\",\"00:01\",\"00:00\"]"], ["[\"05:30\",\"05:31\",\"05:33\"]"], ["[\"11:59\",\"12:00\",\"12:01\"]"], ["[\"00:00\",\"00:00\"]"], ["[\"13:14\",\"13:15\"]"], ["[\"22:00\",\"02:00\",\"06:00\",\"10:00\"]"], ["[\"07:07\",\"07:07\",\"07:07\"]"], ["[\"00:10\",\"00:20\",\"00:30\",\"23:55\"]"], ["[\"18:00\",\"06:00\"]"], ["[\"01:00\",\"01:30\",\"02:00\",\"02:30\",\"03:00\"]"], ["[\"10:00\",\"10:05\",\"10:10\",\"10:15\",\"10:20\"]"], ["[\"00:00\",\"06:00\",\"12:00\",\"18:00\"]"], ["[\"23:00\",\"23:30\",\"00:30\",\"01:00\"]"], ["[\"09:00\",\"09:01\",\"09:02\",\"09:03\",\"09:04\",\"09:05\"]"], ["[\"15:00\",\"15:00\",\"16:00\"]"], ["[\"04:45\",\"05:00\",\"05:15\"]"], ["[\"20:20\",\"21:21\",\"22:22\"]"], ["[\"00:05\",\"23:55\"]"], ["[\"12:00\",\"12:01\",\"12:02\",\"23:59\"]"], ["[\"08:15\",\"08:45\",\"09:15\"]"], ["[\"00:00\",\"23:58\"]"], ["[\"03:00\",\"09:00\",\"15:00\",\"21:00\"]"]], "expected": [1, 0, 5, 720, 61, 1, 1, 1, 1, 0, 1, 240, 0, 10, 720, 30, 5, 360, 30, 1, 0, 15, 61, 10, 1, 30, 2, 360], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "484", "slug": "minimum-unique-word-abbreviation", "id": 484, "title": "Minimum Unique Word Abbreviation", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/minimum-unique-word-abbreviation/", "examples": [{"input": "target = \"apple\", dictionary = [\"blade\"]", "output": "\"a4\"", "explanation": "a4 keeps the leading a and skips four letters; blade starts with b so it cannot match."}, {"input": "target = \"apple\", dictionary = [\"plain\",\"amber\",\"blade\"]", "output": "\"1p3\"", "explanation": "1p3 is the shortest shorthand of apple avoided by all three dictionary words."}, {"input": "target = \"a\", dictionary = []", "output": "\"1\"", "explanation": "With no rivals, the whole word compresses to its length."}], "hints": ["An abbreviation matches a word when its letters line up and its numbers skip the right counts; leading zeros are illegal.", "Only dictionary words with the same length as the target can collide.", "Enumerate every abbreviation pattern by bitmask and keep the shortest one avoiding all rivals."], "statement": "An abbreviation of a word keeps some letters and replaces consecutive skipped blocks with their counts: `a4` means `a` followed by four hidden letters, and `1p3` means one hidden letter, then `p`, then three hidden letters. Numbers never have leading zeros. Such a shorthand matches a word of the same length when its kept letters equal the word's letters at those spots.\n\nGiven a `target` word and a `dictionary` list, find the shortest abbreviation of `target` that matches none of the dictionary words having the same length. Words of different lengths can never collide and are ignored. When several shorthands tie for shortest, any one of them is acceptable, but the judge used here expects the length to be minimal and the shorthand to be valid and unique.\n\nReturn that shortest unique shorthand.\n\n**Constraints:**\n- `1 <= target.length <= 21`\n- `0 <= dictionary.length <= 100`\n- Words hold lowercase letters; only same-length entries matter.\n- At least one valid abbreviation always exists.\n\n**Adaptation note:** Grading accepts any valid unique abbreviation whose length equals the true minimum.\n", "solution": "## Approach\n\nEvery abbreviation pattern corresponds to a bitmask choosing which positions to hide. Building the shorthand for each mask and testing it against same-length dictionary words (via the standard abbreviation matcher that rejects leading zeros) reveals all unique candidates. The shortest such candidate \u2014 breaking ties lexicographically for determinism \u2014 is the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(2^n * (n + d)), where n is the target length and d the filtered dictionary size.\n- **Space Complexity:** O(n + d).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def minAbbreviation(self, target: str, dictionary: List[str]) -> str:\n n = len(target)\n filt = [w for w in dictionary if len(w) == n]\n if not filt:\n return str(n)\n\n def to_abbr(mask: int) -> str:\n out = []\n cnt = 0\n for i, ch in enumerate(target):\n if (mask >> i) & 1:\n cnt += 1\n else:\n if cnt:\n out.append(str(cnt))\n cnt = 0\n out.append(ch)\n if cnt:\n out.append(str(cnt))\n return \"\".join(out)\n\n def matches(abbr: str, word: str) -> bool:\n i = j = 0\n while j < len(abbr):\n c = abbr[j]\n if c.isdigit():\n if c == \"0\":\n return False\n num = 0\n while j < len(abbr) and abbr[j].isdigit():\n num = num * 10 + int(abbr[j])\n j += 1\n i += num\n if i > len(word):\n return False\n else:\n if i >= len(word) or word[i] != c:\n return False\n i += 1\n j += 1\n return i == len(word) and j == len(abbr)\n\n best = target\n for mask in range(1 << n):\n ab = to_abbr(mask)\n if len(ab) >= len(best):\n continue\n if any(matches(ab, w) for w in filt):\n continue\n if len(ab) < len(best) or (len(ab) == len(best) and ab < best):\n best = ab\n return best\n```\n", "starter": {"go": "package main\n\nfunc MinAbbreviation(target string, dictionary []string) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def minAbbreviation(self, target: str, dictionary: List[str]) -> str:\n return \"\"", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n string minAbbreviation(string target, vector<string>& dictionary) {\n return \"\";\n }\n};"}, "fn": "minAbbreviation", "params": [{"name": "target", "type": "string"}, {"name": "dictionary", "type": "string_array"}], "outputType": "string", "tests": [["apple", "['blade']"], ["apple", "['plain', 'amber', 'blade']"], ["a", "[]"], ["abc", "['def']"], ["abc", "['abd']"], ["ab", "['aa', 'bb']"], ["word", "['wore']"], ["word", "['wore', 'work']"], ["hello", "['hella']"], ["hello", "['hallo', 'hollo']"], ["abcde", "[]"], ["abcde", "['abcdf']"], ["abcdef", "['abcdeg', 'abcdeh']"], ["test", "['tent', 'text']"], ["abcd", "['abce', 'abcf']"], ["aaaa", "['aaab']"], ["abcd", "[]"], ["ab", "[]"], ["abc", "[]"], ["abcd", "['wxyz']"], ["apple", "['apply']"], ["apple", "['apply', 'amply']"], ["dog", "['dig', 'dug']"], ["binary", "['binarz']"], ["love", "['live', 'lave']"], ["code", "['codd']"], ["abcd", "['abce']"], ["abc", "['abd', 'abe']"], ["plain", "['plane', 'plank']"], ["abcdefg", "['abcdefh']"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "734", "slug": "minimum-window-subsequence", "id": 734, "title": "Minimum Window Subsequence", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/minimum-window-subsequence/", "examples": [{"input": "s1 = \"abcdebdde\", s2 = \"bde\"", "output": "\"bcde\"", "explanation": "Indices 1 through 4 give the shortest block holding b, d, e in order."}, {"input": "s1 = \"abc\", s2 = \"ac\"", "output": "\"abc\""}, {"input": "s1 = \"abc\", s2 = \"d\"", "output": "\"\"", "explanation": "No block contains d, so the answer is empty."}], "hints": ["Scan s1 forward to find where s2 finishes as a subsequence, then walk backwards to find the earliest start of that match.", "Keep the best (shortest, then earliest) window across all forward matches.", "This two-pointer pass runs in O(n * m) worst case but only O(1) extra memory."], "statement": "You are given two strings `s1` and `s2`. Find the shortest contiguous block of `s1` that contains `s2` as a subsequence \u2014 meaning the characters of `s2` appear in order inside the block, possibly with other characters in between.\n\nIf several blocks share the same minimal length, return the one that starts earliest. When no block of `s1` contains `s2` as a subsequence, return the empty string.\n\n**Constraints:**\n- `1 <= s1.length <= 20000`\n- `1 <= s2.length <= 100`\n- Both strings hold lowercase English letters.\n", "solution": "## Approach\n\nMove a forward pointer through `s1`, advancing through `s2` on matches until one full copy of `s2` is consumed. From that end position, walk backwards through `s1` matching `s2` in reverse to locate the earliest start of this particular match. Record the window when it beats the best length seen so far, then resume the forward scan just after that start.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * m) in the worst case, where n and m are the lengths of `s1` and `s2`.\n- **Space Complexity:** O(1) besides the output.\n\n## Implementation\n\n```python\nclass Solution:\n def minWindow(self, s1: str, s2: str) -> str:\n n, m = len(s1), len(s2)\n best, best_start = 10 ** 9, -1\n i = 0\n while i < n:\n j, k = 0, i\n while k < n and j < m:\n if s1[k] == s2[j]:\n j += 1\n k += 1\n if j < m:\n break\n end = k - 1\n j, k = m - 1, end\n while k >= i and j >= 0:\n if s1[k] == s2[j]:\n j -= 1\n k -= 1\n start = k + 1\n if end - start + 1 < best:\n best, best_start = end - start + 1, start\n i = start + 1\n return \"\" if best_start == -1 else s1[best_start:best_start + best]\n```\n", "starter": {"go": "package main\n\nfunc MinWindow(s1 string, s2 string) string {\n return \"\"\n}", "python": "class Solution:\n def minWindow(self, s1: str, s2: str) -> str:\n return \"\"\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string minWindow(string s1, string s2) {\n return \"\";\n }\n};"}, "fn": "minWindow", "params": [{"name": "s1", "type": "string"}, {"name": "s2", "type": "string"}], "outputType": "string", "tests": [["abcdebdde", "bde"], ["abc", "ac"], ["abc", "d"], ["a", "a"], ["a", "b"], ["ab", "b"], ["ab", "a"], ["abcdbd", "bd"], ["fgrqsqsnodwmxzkzxwqegkndaa", "kzed"], ["abcde", "ace"], ["abcde", "aec"], ["aaaaa", "aa"], ["ababa", "aba"], ["cnhczmccqouqadqtmjjzl", "mm"], ["xyzbca", "abc"], ["bdebd", "bde"], ["abcdebdde", "abcdebdde"], ["abcdebdde", "e"], ["aabcbc", "abc"], ["mnoabcpqr", "abc"], ["aabcc", "abc"], ["zzzbde", "bde"], ["bdebde", "bde"], ["abcdef", "abcdef"], ["abcdef", "fed"], ["qwerty", "qy"], ["mississippi", "issi"], ["abcbcbcbca", "abca"]], "expected": ["bcde", "abc", "", "a", "", "b", "a", "bd", "kzxwqegknd", "abcde", "", "aa", "aba", "mccqouqadqtm", "", "bde", "abcdebdde", "e", "abc", "abc", "abc", "bde", "bde", "abcdef", "", "qwerty", "issi", "abcbcbcbca"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "52", "slug": "minimum-window-substring", "id": 52, "title": "Minimum Window Substring", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/minimum-window-substring/", "examples": [{"input": "s=\"ADOBECODEBANC\", t=\"ABC\"", "output": "\"BANC\"", "explanation": "The minimum window in \"ADOBECODEBANC\" containing all chars of \"ABC\" is \"BANC\"."}, {"input": "s=\"a\", t=\"a\"", "output": "\"a\"", "explanation": "The minimum window in \"a\" containing all chars of \"a\" is \"a\"."}], "hints": ["Sliding window with a frequency map. Expand right to satisfy all requirements, then contract left to find the minimum window while maintaining validity."], "statement": "You are given two strings `s` and `t`. Find the shortest contiguous portion of `s` that contains every character of `t`, counting repeated letters separately. In other words, the chosen portion must supply at least as many copies of each distinct character as appear in `t`. Return that shortest portion, or the empty string `\"\"` when no portion satisfies the requirement.\n\n**Constraints:**\n\n- m == s.length\n- n == t.length\n- 1 \u2264 m, n \u2264 10^5\n- s and t consist of uppercase and lowercase English letters.\n", "solution": "## Approach\n\nUse a sliding window with a character counter. Expand the right pointer while decrementing needed counts; when all characters are matched, shrink the left pointer while tracking the minimal valid window.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(k) where k is the character set size\n\n## Implementation\n\n```python\nfrom collections import Counter\nclass Solution:\n def minWindow(self, s: str, t: str) -> str:\n need = Counter(t)\n missing = len(t)\n l = 0\n res = ''\n for r, c in enumerate(s):\n if need[c] > 0:\n missing -= 1\n need[c] -= 1\n while missing == 0:\n if not res or r - l + 1 < len(res):\n res = s[l:r+1]\n need[s[l]] += 1\n if need[s[l]] > 0:\n missing += 1\n l += 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc MinWindow(s string, t string) string {\n \n}", "python": "class Solution:\n def minWindow(self, s: str, t: str) -> str:\n pass\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string minWindow(string s, string t) {\n return \"\";\n }\n};"}, "fn": "minWindow", "params": [{"name": "s", "type": "string"}, {"name": "t", "type": "string"}], "outputType": "string", "tests": [["ADOBECODEBANC", "ABC"], ["a", "a"], ["a", "aa"], ["bba", "ab"], ["aa", "aa"], ["aa", "aaa"], ["abc", "cba"], ["ab", "b"], ["ab", "a"], ["abc", "ab"], ["abc", "bc"], ["aab", "ab"], ["ADOBECODEBANC", "A"], ["ADOBECODEBANC", "BAN"], ["xyzABCxyz", "ABC"], ["aaabbbccc", "abc"], ["abccba", "abc"], ["HelloWorld", "llo"], ["abcdef", "z"], ["aaaaa", "aa"], ["ababa", "aba"], ["BANC", "BANC"], ["timetotime", "tim"], ["aBcDeF", "cD"], ["Mississippi", "iss"], ["abcde", "e"], ["abcde", "a"], ["aabbcc", "aab"], ["xyyzyzyx", "xyz"], ["AaAaAa", "Aa"]], "expected": ["BANC", "a", "", "ba", "aa", "", "abc", "b", "a", "ab", "bc", "ab", "A", "BAN", "ABC", "abbbc", "abc", "llo", "", "aa", "aba", "BANC", "tim", "cD", "iss", "e", "a", "aab", "zyx", "Aa"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "854", "slug": "mirror-reflection", "id": 854, "title": "Mirror Reflection", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/mirror-reflection/", "examples": [{"input": "p = 2, q = 1", "output": "2", "explanation": "After one bounce the ray arrives at sensor 2."}, {"input": "p = 3, q = 1", "output": "1", "explanation": "The ray reaches sensor 1."}, {"input": "p = 3, q = 2", "output": "0", "explanation": "Parity puts the first hit on sensor 0."}], "hints": ["Unfold the bounces into a straight ray through tiled copies of the room; the hit happens when both coordinates are multiples of `p`.", "Divide out common factors of two from `p` and `q`, then look at parity: an even unfolded `p` means sensor 2, else an even unfolded `q` means sensor 0, otherwise sensor 1.", "The least common multiple of `p` and `q` tells how far the straight ray travels before aligning with corners."], "statement": "A square room has side length `p`. Its corners hold light sensors numbered so that the starting corner (where the laser sits) has no sensor, one neighbor corner holds sensor 1, the opposite diagonal area relates to sensor 2, and the remaining corner holds sensor 0. A laser beam leaves the starting corner heading diagonally into the room.\n\nWhenever the beam meets a wall it reflects like a mirror, keeping its progress toward the far side. It keeps bouncing until it lands exactly on one of the three sensor corners. The beam's first horizontal wall contact is determined by the integer `q`: think of the ray as advancing `q` units vertically for each `p` units of mirrored extension.\n\nGiven `p` and `q`, report which sensor (`0`, `1`, or `2`) the beam reaches first.\n\n**Constraints:**\n- `1 <= q <= 1000`\n- `1 <= p <= 1000`\n", "solution": "## Approach\n\nImagine mirroring the room instead of bouncing the ray, so the beam travels straight through a grid of copies. The first corner hit occurs at the least common multiple of `p` and `q`. Removing shared factors of two reveals whether the number of room widths or heights crossed is even or odd, which directly identifies sensor 2, 0, or 1.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log(min(p, q))) for the factor-removal loop.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def mirrorReflection(self, p: int, q: int) -> int:\n while p % 2 == 0 and q % 2 == 0:\n p //= 2\n q //= 2\n if p % 2 == 0:\n return 2\n if q % 2 == 0:\n return 0\n return 1\n```\n", "starter": {"go": "package main\n\nfunc MirrorReflection(p int, q int) int {\n return 0\n}", "python": "class Solution:\n def mirrorReflection(self, p: int, q: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int mirrorReflection(int p, int q) {\n return 0;\n }\n};"}, "fn": "mirrorReflection", "params": [{"name": "p", "type": "int"}, {"name": "q", "type": "int"}], "outputType": "int", "tests": [["2", "1"], ["3", "1"], ["3", "2"], ["1", "1"], ["4", "3"], ["5", "2"], ["5", "3"], ["2", "2"], ["4", "2"], ["6", "4"], ["6", "3"], ["8", "4"], ["7", "5"], ["10", "6"], ["9", "6"], ["1000", "1"], ["1000", "999"], ["1", "1"], ["2", "1"], ["3", "1"], ["4", "1"], ["5", "1"], ["6", "1"], ["7", "2"], ["8", "6"], ["9", "3"], ["12", "8"], ["15", "10"]], "expected": [2, 1, 0, 1, 2, 0, 1, 1, 2, 0, 2, 2, 1, 1, 0, 2, 2, 1, 2, 1, 2, 1, 2, 0, 2, 1, 0, 0], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "14", "slug": "missing-number", "id": 14, "title": "Missing Number", "difficulty": "Easy", "category": "binary", "link": "https://leetcode.com/problems/missing-number/", "examples": [{"input": "nums = [3,0,1]", "output": "2", "explanation": "The expected sum of [0,3] is 6, but the given numbers sum to 4. The missing number is 6 - 4 = 2."}, {"input": "nums = [0,1]", "output": "2", "explanation": "The expected sum of [0,2] is 3, but the given numbers sum to 1. The missing number is 3 - 1 = 2."}, {"input": "nums = [9,6,4,2,3,5,7,0,1]", "output": "8", "explanation": "The expected sum of [0,9] is 45, but the given numbers sum to 37. The missing number is 45 - 37 = 8."}], "hints": ["Use XOR: XOR all indices and values to cancel pairs, the result is the missing number. Alternatively use sum formula."], "statement": "You are given an array `nums` of length `n` holding distinct integers drawn from `0` through `n` inclusive. Exactly one value in that full range does not appear in the array. Identify and return the absent value.\n\n**Constraints:**\n\n- n == nums.length\n- 1 \u2264 n \u2264 10^4\n- 0 \u2264 nums[i] \u2264 n\n- All the numbers of nums are unique.\n", "solution": "## Approach\n\nCompute the expected sum of numbers from 0 to n using the formula `n*(n+1)/2` and subtract the actual sum of the array to find the missing number.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def missingNumber(self, nums: List[int]) -> int:\n n = len(nums)\n return (n * (n + 1) // 2) - sum(nums)\n```\n", "starter": {"go": "package main\n\nfunc MissingNumber(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def missingNumber(self, nums: List[int]) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int missingNumber(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "missingNumber", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[3,0,1]"], ["[0,1]"], ["[9,6,4,2,3,5,7,0,1]"], ["[0]"], ["[1]"], ["[0,2]"], ["[1,2,3,4,5,6,7,8,9,10,0]"], ["[0,1,3]"], ["[0,1,2,4]"], ["[1,0]"], ["[2,1]"], ["[2,0]"], ["[0,1,2]"], ["[3,2,1]"], ["[0,2,3]"], ["[4,3,2,1]"], ["[0,1,2,3]"], ["[4,0,1,2]"], ["[5,4,3,2,1]"], ["[0,1,2,3,5]"], ["[1,3,4,5,0]"], ["[6,5,4,3,2,1]"], ["[0,2,3,4,5,6]"], ["[1,0,3,2,5,4,6]"], ["[7,6,5,4,3,2,1]"], ["[0,1,2,3,4,6,7,8]"], ["[8,7,6,5,4,3,2,0]"], ["[1,2,3,4,5,6,7,8,9]"], ["[0,1,2,3,4,5,6,7,9]"], ["[9,8,7,6,5,4,3,2,0]"]], "expected": [2, 2, 8, 1, 0, 1, 11, 2, 3, 2, 0, 1, 3, 0, 1, 0, 4, 3, 0, 4, 2, 0, 1, 7, 0, 5, 1, 0, 8, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "316", "slug": "missing-ranges", "id": 316, "title": "Missing Ranges", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/missing-ranges/", "examples": [{"explanation": "2 is missing alone; 4 through 49, 51 through 74, and 76 through 99 are missing runs.", "input": "nums = [0,1,3,50,75], lower = 0, upper = 99", "output": "[\"2\",\"4->49\",\"51->74\",\"76->99\"]"}, {"explanation": "The only value in range is missing.", "input": "nums = [], lower = 1, upper = 1", "output": "[\"1\"]"}, {"explanation": "The single value in range is present, so nothing is missing.", "input": "nums = [-1], lower = -1, upper = -1", "output": "[]"}], "hints": ["Imagine lower - 1 placed before the array and upper + 1 after it, then look at gaps between consecutive covered values.", "A gap from a to b with a + 1 == b - 1 is a single number; a wider gap is a start->end range."], "statement": "You are given a sorted array `nums` with no duplicates, plus bounds `lower` and `upper`. Every integer from `lower` to `upper` should appear, but the ones already in `nums` are covered.\n\nReturn the missing pieces as strings. A lone missing number becomes just that number (for example `\"2\"`), while a run of consecutive missing numbers becomes `\"start->end\"` (for example `\"4->49\"`). List the pieces in increasing order. When nothing is missing, return an empty list.\n\n**Constraints:**\n- `-10^9 <= lower <= upper <= 10^9`\n- `0 <= nums.length <= 10^4`\n- `nums` is sorted in strictly increasing order and every element lies within `[lower, upper]`.\n", "solution": "## Approach\n\nPlace a virtual guard just below `lower` and another just above `upper`, then scan the array in order. The gap between each pair of consecutive covered values tells what is missing: a gap of exactly one yields a single number, while a wider gap yields a start->end range. Using wider integer arithmetic avoids overflow at the bounds.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `nums`.\n- **Space Complexity:** O(1) besides the output list.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findMissingRanges(self, nums: List[int], lower: int, upper: int) -> List[str]:\n res = []\n prev = lower - 1\n for i in range(len(nums) + 1):\n cur = nums[i] if i < len(nums) else upper + 1\n if cur - prev >= 2:\n a, b = prev + 1, cur - 1\n if a == b:\n res.append(str(a))\n else:\n res.append(f\"{a}->{b}\")\n prev = cur\n return res\n```\n", "starter": {"go": "package main\n\nfunc FindMissingRanges(nums []int, lower int, upper int) []string {\n return []string{}\n}", "python": "from typing import List\n\nclass Solution:\n def findMissingRanges(self, nums: List[int], lower: int, upper: int) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> findMissingRanges(vector<int>& nums, int lower, int upper) {\n return {};\n }\n};"}, "fn": "findMissingRanges", "params": [{"name": "nums", "type": "int_array"}, {"name": "lower", "type": "int"}, {"name": "upper", "type": "int"}], "outputType": "string_list", "tests": [["[0,1,3,50,75]", "0", "99"], ["[]", "1", "1"], ["[-1]", "-1", "-1"], ["[]", "0", "3"], ["[0]", "0", "0"], ["[1,2,3]", "1", "3"], ["[1,2,3]", "0", "5"], ["[]", "-3", "-1"], ["[0,1,2,3,4]", "0", "4"], ["[5]", "0", "5"], ["[2]", "2", "5"], ["[2]", "1", "3"], ["[0,2,4]", "0", "4"], ["[-3,-1,1]", "-5", "3"], ["[10,11,15]", "10", "20"], ["[1]", "0", "1"], ["[0,1]", "0", "2"], ["[5,6,7,10]", "5", "10"], ["[-10]", "-10", "-5"], ["[1,3,5,7]", "1", "7"], ["[0,1,2,4,5,7]", "0", "7"], ["[]", "100", "102"], ["[-2,-1,0,1,2]", "-2", "2"], ["[3,4,9,10]", "3", "12"], ["[2]", "0", "2"], ["[7]", "7", "7"]], "expected": [["2", "4->49", "51->74", "76->99"], ["1"], [], ["0->3"], [], [], ["0", "4->5"], ["-3->-1"], [], ["0->4"], ["3->5"], ["1", "3"], ["1", "3"], ["-5->-4", "-2", "0", "2->3"], ["12->14", "16->20"], ["0"], ["2"], ["8->9"], ["-9->-5"], ["2", "4", "6"], ["3", "6"], ["100->102"], [], ["5->8", "11->12"], ["0->1"], []], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "744", "slug": "monotone-increasing-digits", "id": 744, "title": "Monotone Increasing Digits", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/monotone-increasing-digits/", "examples": [{"input": "n = 10", "output": "9", "explanation": "10 dips at the last digit, so 9 is the answer."}, {"input": "n = 1234", "output": "1234"}, {"input": "n = 332", "output": "299", "explanation": "Borrow at the first dip, then set the tail to 9."}], "hints": ["Work on the digit array from right to left, marking the first position (from the left) where a dip occurs.", "When digits[i] > digits[i+1], lower digits[i] by one and remember that the tail from i+1 onward must become 9s.", "Scanning right to left propagates the borrow through runs like 332 -> 322 -> 299."], "statement": "A non-negative integer has monotone digits when each digit (read left to right) is greater than or equal to the previous one \u2014 for instance `123`, `1123` and `7` qualify, while `132` and `1000` do not.\n\nGiven `n`, return the largest integer that is less than or equal to `n` and has monotone digits.\n\n**Constraints:**\n- `0 <= n <= 10^9`\n", "solution": "## Approach\n\nWrite `n` as digits and scan from right to left. Whenever a digit exceeds its right neighbour, decrement it and note that everything from the next position onward must turn into `9`. The right-to-left order lets a borrow cascade leftwards through equal runs. Filling the noted tail with `9`s yields the greatest valid value.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(d), where d is the digit count (at most 10).\n- **Space Complexity:** O(d) for the digit array.\n\n## Implementation\n\n```python\nclass Solution:\n def monotoneIncreasingDigits(self, n: int) -> int:\n d = list(str(n))\n mark = len(d)\n for i in range(len(d) - 1, 0, -1):\n if d[i] < d[i - 1]:\n d[i - 1] = str(int(d[i - 1]) - 1)\n mark = i\n for i in range(mark, len(d)):\n d[i] = '9'\n return int(\"\".join(d))\n```\n", "starter": {"go": "package main\n\nfunc MonotoneIncreasingDigits(n int) int {\n return 0\n}", "python": "class Solution:\n def monotoneIncreasingDigits(self, n: int) -> int:\n return 0\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int monotoneIncreasingDigits(int n) {\n return 0;\n }\n};"}, "fn": "monotoneIncreasingDigits", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["10"], ["1234"], ["332"], ["1000"], ["1111"], ["120"], ["100"], ["7"], ["0"], ["999"], ["1000000000"], ["123456789"], ["987654321"], ["54321"], ["1024"], ["101"], ["110"], ["1000000"], ["214748364"], ["999999999"], ["12340"], ["4321"], ["1001"], ["1200"], ["10000000"], ["100000"], ["99999"], ["100000000"]], "expected": [9, 1234, 299, 999, 1111, 119, 99, 7, 0, 999, 999999999, 123456789, 899999999, 49999, 999, 99, 99, 999999, 199999999, 999999999, 12339, 3999, 999, 1199, 9999999, 99999, 99999, 99999999], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "886", "slug": "monotonic-array", "id": 886, "title": "Monotonic Array", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/monotonic-array/", "examples": [{"input": "nums = [1,2,2,3]", "output": "true", "explanation": "Non-decreasing so monotone."}, {"input": "nums = [6,5,4,4]", "output": "true", "explanation": "Non-increasing so monotone."}, {"input": "nums = [1,3,2]", "output": "false", "explanation": "Rises then falls."}], "hints": ["Walk once while remembering whether you have seen an upward step and whether you have seen a downward step.", "If both directions appear, the answer is false; otherwise it is true. A single element or all-equal list is true."], "statement": "Call a list steadily rising when every later entry is at least as large as every earlier one, and steadily falling when every later entry is at most as large as every earlier one. A list that satisfies either pattern (including flat lists where all entries tie) counts as monotone.\n\nGiven `nums`, decide whether it is monotone in either direction.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `-10^5 <= nums[i] <= 10^5`\n", "solution": "## Approach\n\nScan neighbours once, tracking two flags: one stays true while no drop has been seen (rising candidate) and the other while no climb has been seen (falling candidate). A climb clears the falling flag and a drop clears the rising flag. If at least one flag survives, the list is monotone.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for a single pass.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def isMonotonic(self, nums: List[int]) -> bool:\n inc = True\n dec = True\n for i in range(1, len(nums)):\n if nums[i] > nums[i - 1]:\n dec = False\n if nums[i] < nums[i - 1]:\n inc = False\n return inc or dec\n```\n", "starter": {"go": "package main\n\nfunc IsMonotonic(nums []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def isMonotonic(self, nums: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool isMonotonic(vector<int>& nums) {\n return false;\n }\n};"}, "fn": "isMonotonic", "params": [{"name": "nums", "type": "int_array"}], "outputType": "boolean", "tests": [["[1,2,2,3]"], ["[6,5,4,4]"], ["[1,3,2]"], ["[1]"], ["[1,1,1,1]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[1,1,2]"], ["[2,2,1]"], ["[1,3,3,2]"], ["[1,2,3,2]"], ["[3,2,1,2]"], ["[0,0,0]"], ["[-1,0,1]"], ["[1,0,-1]"], ["[1,2]"], ["[2,1]"], ["[1,1]"], ["[1,2,2,2,3]"], ["[5,5,5,4,4]"], ["[1,2,3,4,3]"], ["[4,3,2,2,2]"], ["[100000,-100000]"], ["[-100000,100000]"], ["[1,2,3,3,4,5]"], ["[5,4,4,3,1]"], ["[2,2,2,1,1]"], ["[1,1,1,2,2]"]], "expected": [true, true, false, true, true, true, true, true, true, false, false, false, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "817", "slug": "most-common-word", "id": 817, "title": "Most Common Word", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/most-common-word/", "examples": [{"input": "paragraph = \"Bob hit a ball, the hit BALL flew far after it was hit.\", banned = [\"hit\"]", "output": "\"ball\"", "explanation": "After lowercasing and stripping punctuation, ball appears twice while every other kept word appears once."}, {"input": "paragraph = \"a.\", banned = []", "output": "\"a\"", "explanation": "The only word is the answer."}, {"input": "paragraph = \"a, a, a, b,b,b,c, c\", banned = [\"a\"]", "output": "\"b\"", "explanation": "Banned words are ignored, leaving b as the most frequent."}], "hints": ["Lowercase the paragraph and treat every non-letter as a separator before splitting into words.", "Count with a hash map while skipping banned words, then return the word with the highest count."], "statement": "Given a paragraph and a list of banned words, return the most frequent word that is not banned. Compare words case-insensitively and treat punctuation as separators: `Bob`, `bob!` and `BOB` are the same word `bob`.\n\nSplit the paragraph into lowercase letter sequences, discard any word appearing in `banned`, and pick the remaining word with the largest frequency. Exactly one such word has the top count in every test.\n\n**Constraints:**\n- `1 <= paragraph.length <= 1000`\n- Paragraph holds letters, spaces and punctuation `!?',;.`\n- `0 <= banned.length <= 100`\n- Each banned word is lowercase letters, all distinct.\n- At least one non-banned word exists and the answer is unique.\n", "solution": "## Approach\n\nLowercase the paragraph and scan it, accumulating letter runs as words and treating anything else as a boundary. Look up each word in the banned set; survivors increment a frequency map that also remembers first-seen order for deterministic ties. A final pass picks the highest count (earliest on ties), which matches the unique-answer guarantee.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + m) for paragraph length n and banned size m.\n- **Space Complexity:** O(n) for the word counts in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:\n ban = set(w.lower() for w in banned)\n counts: dict[str, int] = {}\n cur: list[str] = []\n best, best_c = \"\", 0\n def flush():\n nonlocal best, best_c\n if cur:\n w = \"\".join(cur)\n del cur[:]\n if w not in ban:\n counts[w] = counts.get(w, 0) + 1\n if counts[w] > best_c:\n best_c = counts[w]\n best = w\n for ch in paragraph.lower() + \" \":\n if 'a' <= ch <= 'z':\n cur.append(ch)\n else:\n flush()\n return best\n```\n", "starter": {"go": "package main\n\nfunc MostCommonWord(paragraph string, banned []string) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n string mostCommonWord(string paragraph, vector<string>& banned) {\n return \"\";\n }\n};"}, "fn": "mostCommonWord", "params": [{"name": "paragraph", "type": "string"}, {"name": "banned", "type": "string_array"}], "outputType": "string", "tests": [["Bob hit a ball, the hit BALL flew far after it was hit.", "['hit']"], ["a.", "[]"], ["a, a, a, b,b,b,c, c", "['a']"], ["Bob!", "[]"], ["a b c d e", "['a', 'b']"], ["Hello hello HELLO world!", "['world']"], ["dog cat dog dog cat bird", "['cat']"], ["a!b?c;d:e,f'g", "[]"], ["one two two three three three", "[]"], ["x y z x y x", "['y']"], ["Apple apple banana!", "['banana']"], ["it was the best of times it was the worst of times", "['it', 'was', 'the', 'of']"], ["a a b b c c c", "[]"], ["Testing, testing: 1 2 3 testing!", "[]"], ["sun moon sun stars moon sun", "['moon']"], ["aa bb aa bb cc", "['cc']"], ["Bob bob BOB bobby!", "['bobby']"], ["w!w!w!x!x!y", "[]"], ["The quick brown fox jumps over the lazy dog", "['the']"], ["a...b...a...c...a", "['b', 'c']"], ["hit hit hit ball ball", "[]"], ["Practice makes perfect practice!", "['makes']"], ["one!two?three,one;two:one.", "[]"], ["abc def abc ghi abc", "['def', 'ghi']"], ["Zz zz ZZ z", "[]"], ["lorem ipsum lorem dolor ipsum lorem", "['ipsum']"], ["a b a c a d a e", "['e']"], ["Ends with word test", "['with']"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "570", "slug": "most-frequent-subtree-sum", "id": 570, "title": "Most Frequent Subtree Sum", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/most-frequent-subtree-sum/", "examples": [{"input": "root = [5,2,-3]", "output": "[2,-3,4]", "explanation": "The three subtree totals are 2 (left leaf), -3 (right leaf) and 4 (whole tree); each occurs once, so all are returned."}, {"input": "root = [5,2,-5]", "output": "[2]", "explanation": "The subtree totals are 2, -5 and 2; the value 2 occurs twice, more than any other total."}, {"input": "root = [1]", "output": "[1]", "explanation": "The only subtree total is 1."}], "hints": ["A post-order walk computes each subtree total from its children before counting it.", "Keep a frequency table of totals plus the best frequency seen; collect every total matching it (order is free)."], "statement": "For every node of a binary tree, consider the sum of all values in the subtree rooted at that node (the node itself plus everything below it). Collect one such total per node, count how many times each distinct total appears, and return every total that attains the highest frequency. The order of the returned totals does not matter.\n\n**Constraints:**\n- The number of nodes is in the range `[0, 10^4]`\n- `-10^5 <= Node.val <= 10^5`\n", "solution": "## Approach\n\nCompute every subtree total with a post-order traversal: a leaf contributes its own value, and an inner node adds its value to the totals of both children. Record each total in a frequency map while tracking the highest count. A second pass over the map keeps exactly the totals whose count equals that maximum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one visit per node plus one pass over distinct totals.\n- **Space Complexity:** O(n) for recursion depth and the frequency map in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findFrequentTreeSum(self, root) -> List[int]:\n from collections import Counter\n freq = Counter()\n\n def dfs(node):\n if node is None:\n return 0\n s = node.val + dfs(node.left) + dfs(node.right)\n freq[s] += 1\n return s\n\n if root is None:\n return []\n dfs(root)\n best = max(freq.values())\n return [s for s, c in freq.items() if c == best]\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 FindFrequentTreeSum(root *TreeNode) []int {\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\nfrom typing import List\nclass Solution:\n def findFrequentTreeSum(self, root) -> List[int]:\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findFrequentTreeSum(TreeNode* root) {\n return {};\n }\n};"}, "fn": "findFrequentTreeSum", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int_array", "tests": [["[5,2,-3]"], ["[5,2,-5]"], ["[1]"], ["[]"], ["[0]"], ["[2,1,3]"], ["[1,2,3,4,5,6,7]"], ["[3,1,5,0,2,4,6]"], ["[-1,-2,-3]"], ["[5,2,-5,1,3]"], ["[1,null,2,null,3]"], ["[1,2,null,3]"], ["[4,2,6,1,3,5,7]"], ["[10,5,-3,3,2,null,11,3,-2,null,1]"], ["[0,0,0]"], ["[1,1,1,1,1]"], ["[2,2,2]"], ["[100000,-100000,50000]"], ["[1,null,-1]"], ["[3,3,3,3]"], ["[5,4,6,3,null,null,7]"], ["[-5,2,3]"], ["[7]"], ["[1,2,2,3,3,3,3]"], ["[9,6,-2,null,null,2,-3]"], ["[4,null,5,null,6]"], ["[2,-1,-1]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"]], "expected": [[2, -3, 4], [2], [1], [], [0], [1, 3, 6], [16, 4, 5, 6, 7, 11, 28], [0, 2, 3, 4, 21, 6, 15], [-2, -3, -6], [6], [3, 5, 6], [3, 5, 6], [1, 18, 3, 5, 6, 7, 28], [3], [0], [1], [2], [50000], [-1, 0], [3], [7], [0, 2, 3], [7], [3], [-3], [6, 11, 15], [-1], [1, 17, 66, 4, 21, 37, 7, 27, 13]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "824", "slug": "most-profit-assigning-work", "id": 824, "title": "Most Profit Assigning Work", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/most-profit-assigning-work/", "examples": [{"input": "difficulty = [2,4,6,8,10], profit = [10,20,30,40,50], worker = [4,5,6,7]", "output": "100", "explanation": "Workers earn 20 + 20 + 30 + 30."}, {"input": "difficulty = [85,47,57], profit = [24,66,99], worker = [40,25,25]", "output": "0", "explanation": "No worker qualifies for any job."}], "hints": ["Sort jobs by difficulty and record, for each position, the best pay seen so far.", "For each worker, binary-search the hardest job they still qualify for and add its prefix-best pay.", "A harder job that pays less than an easier one never changes the answer after the prefix maximum."], "statement": "You are given three arrays. `difficulty[i]` is how hard job `i` is, `profit[i]` is what job `i` pays, and `worker[j]` is the skill level of worker `j`. A worker can only take a job whose difficulty does not exceed their skill, and each worker takes at most the single best-paying job available to them (workers may also take nothing if every job is too hard). Every worker chooses independently, so the same job can be taken by many workers.\n\nReturn the greatest total pay all workers can earn together.\n\n**Constraints:**\n- `1 <= difficulty.length == profit.length <= 10^4`\n- `1 <= difficulty[i], profit[i] <= 10^5`\n- `1 <= worker.length <= 10^4`\n- `1 <= worker[i] <= 10^5`\n", "solution": "## Approach\n\nPair each difficulty with its profit and sort the pairs by difficulty, then sweep once to remember the highest pay reachable at or before every position. Each worker independently takes the prefix-best pay of the hardest qualifying job, found with binary search, and the individual earnings are summed.\n\n## Complexity Analysis\n\n- **Time Complexity:** O((n + m) log n) for sorting n jobs and binary-searching per each of the m workers.\n- **Space Complexity:** O(n) for the sorted job pairs and prefix maxima.\n\n## Implementation\n\n```python\nfrom typing import List\nimport bisect\n\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n jobs = sorted(zip(difficulty, profit))\n diffs = []\n best = []\n mx = 0\n for d, p in jobs:\n mx = max(mx, p)\n diffs.append(d)\n best.append(mx)\n ans = 0\n for w in worker:\n i = bisect.bisect_right(diffs, w) - 1\n if i >= 0:\n ans += best[i]\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MaxProfitAssignment(difficulty []int, profit []int, worker []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxProfitAssignment(self, difficulty: List[int], profit: List[int], worker: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker) {\n return 0;\n }\n};"}, "fn": "maxProfitAssignment", "params": [{"name": "difficulty", "type": "int_array"}, {"name": "profit", "type": "int_array"}, {"name": "worker", "type": "int_array"}], "outputType": "int", "tests": [["[2, 4, 6, 8, 10]", "[10, 20, 30, 40, 50]", "[4, 5, 6, 7]"], ["[85, 47, 57]", "[24, 66, 99]", "[40, 25, 25]"], ["[1]", "[100]", "[1]"], ["[1]", "[100]", "[0]"], ["[5, 5, 5]", "[10, 20, 15]", "[5, 5, 5]"], ["[1, 2, 3, 4, 5]", "[5, 4, 3, 2, 1]", "[1, 2, 3, 4, 5]"], ["[1, 2, 3, 4, 5]", "[1, 2, 3, 4, 5]", "[5, 5, 5, 5, 5]"], ["[10, 20, 30]", "[100, 200, 300]", "[5, 15, 25, 35]"], ["[3, 3, 3]", "[0, 0, 0]", "[3, 3]"], ["[68, 35, 52, 47, 86]", "[67, 17, 1, 81, 3]", "[92, 10, 85, 84, 82]"], ["[2, 4]", "[100, 1]", "[4, 4, 4]"], ["[4, 2]", "[1, 100]", "[2, 3, 4]"], ["[100000]", "[100000]", "[100000]"], ["[100000]", "[100000]", "[99999]"], ["[1, 100000]", "[1, 100000]", "[50000, 100000, 1]"], ["[13, 37, 58]", "[4, 90, 3]", "[4, 32, 67, 29, 56]"], ["[23, 30, 35, 35, 43, 47]", "[95, 27, 9, 27, 87, 100]", "[21, 24, 43, 44, 45, 56, 57]"], ["[1, 2]", "[50, 60]", "[1, 1, 1, 2, 2]"], ["[7]", "[42]", "[7, 7, 7, 7, 7, 7]"], ["[9, 9, 9, 9]", "[1, 2, 3, 4]", "[8, 9, 10]"], ["[5, 10, 15, 20]", "[20, 40, 60, 80]", "[1, 5, 10, 15, 20, 25]"], ["[2, 2, 3, 4]", "[10, 5, 30, 20]", "[2, 3, 4, 5]"], ["[1, 3, 5, 7, 9]", "[2, 4, 6, 8, 10]", "[2, 4, 6, 8, 10]"], ["[50]", "[70]", "[40, 50, 60]"], ["[4, 8, 12]", "[10, 10, 10]", "[4, 8, 12, 16]"], ["[6, 27, 38, 45]", "[75, 61, 70, 58]", "[37, 13, 21, 36, 27, 36, 49, 26]"], ["[1, 1, 1, 1, 1]", "[1, 2, 3, 4, 5]", "[1]"], ["[10, 20]", "[5, 15]", "[30, 30, 30, 30]"]], "expected": [100, 0, 100, 0, 60, 25, 25, 600, 0, 324, 300, 300, 100000, 0, 100002, 188, 580, 270, 252, 8, 280, 100, 30, 140, 40, 600, 5, 60], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "934", "slug": "most-stones-removed-with-same-row-or-column", "id": 934, "title": "Most Stones Removed with Same Row or Column", "difficulty": "Medium", "category": "hash-table", "link": "https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/", "examples": [{"input": "stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]", "output": "5", "explanation": "One linked group of six keeps a single survivor."}, {"input": "stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]", "output": "3", "explanation": "A group of four plus an isolated stone."}, {"input": "stones = [[0,0]]", "output": "0", "explanation": "No partner exists."}], "hints": ["Link stones sharing a row or a column; each linked group of k stones can lose k - 1 of them.", "A disjoint-set union over pairs (or a graph flood fill) finds the groups; the answer is stones minus group count."], "statement": "Remove as many stones as possible when each removal needs a row or column partner.\n\nStones sit on integer grid points with at most one stone per point. A stone may be taken away only while some other remaining stone shares its row or its column. Plan the removals to clear the maximum count.\n\nGiven `stones` where each entry is `[x, y]`, return the largest number of stones that can disappear.\n\n**Constraints:**\n- `1 <= stones.length <= 1000`\n- `0 <= xi, yi <= 10^4`\n- No two stones share a coordinate.\n", "solution": "## Approach\n\nView stones as nodes joined when they share a row or a column. Inside one connected group the stones can be cleared down to a single survivor, so a group of size k contributes k - 1 removals. Merging all pairs with a disjoint-set union (quadratic pairing is fast enough for n up to 1000) gives the group count, and the answer is stones minus groups.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) for checking every pair, with near-constant union cost.\n- **Space Complexity:** O(n) for the parent array.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def removeStones(self, stones: List[List[int]]) -> int:\n n = len(stones)\n parent = list(range(n))\n\n def find(x):\n while parent[x] != x:\n parent[x] = parent[parent[x]]\n x = parent[x]\n return x\n\n comps = n\n for i in range(n):\n for j in range(i + 1, n):\n if stones[i][0] == stones[j][0] or stones[i][1] == stones[j][1]:\n ri, rj = find(i), find(j)\n if ri != rj:\n parent[ri] = rj\n comps -= 1\n return n - comps\n```\n", "starter": {"go": "package main\n\nfunc RemoveStones(stones [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def removeStones(self, stones: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int removeStones(vector<vector<int>>& stones) {\n return 0;\n }\n};"}, "fn": "removeStones", "params": [{"name": "stones", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0, 0], [0, 1], [1, 0], [1, 2], [2, 1], [2, 2]]"], ["[[0, 0], [0, 2], [1, 1], [2, 0], [2, 2]]"], ["[[0, 0]]"], ["[[0, 0], [1, 1]]"], ["[[0, 0], [0, 1]]"], ["[[0, 0], [1, 0], [2, 0]]"], ["[[0, 0], [0, 5], [0, 9]]"], ["[[3, 3], [3, 7], [7, 3], [7, 7]]"], ["[[0, 0], [2, 2], [3, 1], [1, 3]]"], ["[[0, 0], [0, 2], [2, 0], [2, 2], [1, 1]]"], ["[[0, 0], [1, 1], [2, 2]]"], ["[[0, 1], [1, 0], [1, 2], [2, 1]]"], ["[[5, 5]]"], ["[[0, 0], [0, 1], [0, 2], [0, 3]]"], ["[[1, 1], [2, 2], [3, 3], [1, 3], [3, 1]]"], ["[[0, 0], [0, 1], [1, 0], [1, 1]]"], ["[[10, 20], [20, 10], [10, 10], [20, 20]]"], ["[[0, 0], [0, 3], [3, 0], [3, 3], [1, 1], [1, 2], [2, 1]]"], ["[[10000, 10000], [10000, 0], [0, 10000]]"], ["[[1, 2]]"], ["[[0, 0], [2, 0], [4, 0], [1, 1]]"], ["[[0, 5], [5, 0], [5, 5], [0, 0]]"], ["[[1, 1], [1, 4], [4, 1], [4, 4], [2, 2]]"], ["[[0, 0], [1, 2], [2, 1], [3, 3]]"], ["[[6, 6], [6, 8], [8, 6], [9, 9], [9, 6]]"], ["[[2, 3], [3, 2], [3, 5], [5, 3], [5, 5]]"], ["[[0, 0], [0, 4], [4, 0], [4, 4], [2, 2], [2, 6], [6, 2]]"], ["[[7, 7], [7, 1], [1, 7], [1, 1], [3, 3]]"]], "expected": [5, 3, 0, 0, 1, 2, 2, 3, 0, 3, 0, 2, 0, 3, 3, 3, 3, 5, 2, 0, 2, 3, 3, 0, 4, 4, 5, 3], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "381", "slug": "move-zeroes", "id": 381, "title": "Move Zeroes", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/move-zeroes/", "examples": [{"input": "nums = [0,1,0,3,12]", "output": "[1,3,12,0,0]", "explanation": "Non-zeros keep order [1,3,12]; zeros shift to the end."}, {"input": "nums = [0]", "output": "[0]", "explanation": "Single zero stays."}, {"input": "nums = [1,0,1]", "output": "[1,1,0]", "explanation": "The zero moves past the trailing 1."}], "hints": ["Adaptation: the original moves zeros in place with void; here return the rearranged array.", "Two pointers: write each non-zero to the next free slot, then fill the tail with zeros.", "Relative order of non-zeros is preserved."], "statement": "Move all zeros to the end while keeping the relative order of non-zero values.\n\n**Adaptation:** the original requires an in-place void update; here implement\n`moveZeroes(nums)` returning the rearranged array.\n\n**Constraints:**\n- `1 <= nums.length <= 10^4`\n- `-2^31 <= nums[i] <= 2^31 - 1`\n", "solution": "## Approach\n\nCompact non-zero values forward with a write pointer, then fill the remaining tail with zeros. This keeps non-zero order and uses one pass.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(1) extra besides the returned copy.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def moveZeroes(self, nums: List[int]) -> List[int]:\n a = list(nums)\n w = 0\n for x in a:\n if x != 0:\n a[w] = x\n w += 1\n while w < len(a):\n a[w] = 0\n w += 1\n return a\n```\n", "starter": {"go": "package main\n\nfunc MoveZeroes(nums []int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def moveZeroes(self, nums: List[int]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> moveZeroes(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "moveZeroes", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_array", "tests": [["[0,1,0,3,12]"], ["[0]"], ["[1]"], ["[0,0,1]"], ["[1,0,1]"], ["[0,0,0]"], ["[1,2,3]"], ["[4,2,4,0,0,3,0,5,1,0]"], ["[0,0,0,1]"], ["[1,0,0,0]"], ["[0,1]"], ["[1,0]"], ["[2,1]"], ["[0,0]"], ["[1,0,2,0,3,0]"], ["[0,0,1,0,0,2]"], ["[5,0,0,5]"], ["[-1,0,1]"], ["[0,-1,0,-2]"], ["[1,2,0,0,3]"], ["[0,0,0,0,1]"], ["[1,2,3,0]"], ["[0,1,2,3]"], ["[5,5,0,5,5]"], ["[100,0,100,0,100]"], ["[-5,0,-3,0,2]"], ["[0,0,1,1,0,0,2,2]"], ["[7,0,8,0,9,0,10]"]], "expected": [[1, 3, 12, 0, 0], [0], [1], [1, 0, 0], [1, 1, 0], [0, 0, 0], [1, 2, 3], [4, 2, 4, 3, 5, 1, 0, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0], [1, 0], [2, 1], [0, 0], [1, 2, 3, 0, 0, 0], [1, 2, 0, 0, 0, 0], [5, 5, 0, 0], [-1, 1, 0], [-1, -2, 0, 0], [1, 2, 3, 0, 0], [1, 0, 0, 0, 0], [1, 2, 3, 0], [1, 2, 3, 0], [5, 5, 5, 5, 0], [100, 100, 100, 0, 0], [-5, -3, 2, 0, 0], [1, 1, 2, 2, 0, 0, 0, 0], [7, 8, 9, 10, 0, 0, 0]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "427", "slug": "moving-average-from-data-stream", "id": 427, "title": "Moving Average from Data Stream", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/moving-average-from-data-stream/", "examples": [{"input": "operations = [\"MovingAverage\",\"next\",\"next\",\"next\",\"next\"], args = [[3],[1],[10],[3],[5]]", "output": "[\"1.0\",\"5.5\",\"4.666666666666667\",\"6.0\"]", "explanation": "Sliding windows of width 3 give means 1.0, 5.5, 14/3, 6.0."}, {"input": "operations = [\"MovingAverage\",\"next\",\"next\"], args = [[1],[4],[5]]", "output": "[\"4.0\",\"5.0\"]", "explanation": "Width 1 always averages the single newest value."}, {"input": "operations = [\"MovingAverage\",\"next\",\"next\",\"next\"], args = [[2],[-1],[3],[5]]", "output": "[\"-1.0\",\"1.0\",\"4.0\"]", "explanation": "Width-2 windows give -1.0, then 1.0, then 4.0."}], "hints": ["Adaptation: replay the trace with a queue and a running sum instead of building a class.", "Subtract the evicted value when the window is full so each mean is O(1).", "Format each mean with the language default double-to-string conversion; checking allows small tolerance."], "statement": "This is an offline adaptation of a streaming task. Instead of writing a class, you write one function that replays a whole session:\n\n```\nrunMovingAverage(operations, args)\n```\n\n`operations[i]` is either `\"MovingAverage\"` (build the averager) or `\"next\"` (feed a value). `args[i]` holds the constructor or call argument: `args[0]` is `[size]` (the window width), and each later entry is `[value]` for that `next` call. Both arrays share the same length, and the first operation is always `\"MovingAverage\"`.\n\nThe averager remembers at most the newest `size` fed values. Each `next` appends its value (dropping the oldest when full) and yields the mean of the stored window as a decimal string (for example `\"1.0\"`, `\"5.5\"`).\n\nReturn the list of those decimal strings, one per `next` call, in order. Constructor steps contribute nothing to the output.\n\n**Constraints:**\n- `1 <= size <= 1000`\n- `-10^5 <= value <= 10^5`\n- At most `10^4` `next` calls per session.\n\n**Adaptation note:** The classic formulation uses a `MovingAverage` class with a `next` method returning `double`. Here averages are transported as decimal `string` values (compared with tolerance), and only `next` results are returned.\n", "solution": "## Approach\n\nReplay the session with a FIFO queue plus a running total. The first argument fixes the window width; each `next` appends its value, evicts the oldest entry when the queue overflows, and records the quotient of the sum over the current queue length. Queue operations keep every step constant time while preserving exact window contents.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the number of `next` calls.\n- **Space Complexity:** O(size) for the stored window.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def runMovingAverage(self, operations: List[str], args: List[List[int]]) -> List[str]:\n size = args[0][0]\n q = deque()\n total = 0\n out = []\n for op, a in zip(operations[1:], args[1:]):\n if op == \"next\":\n q.append(a[0])\n total += a[0]\n if len(q) > size:\n total -= q.popleft()\n out.append(str(total / len(q)))\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunMovingAverage(operations []string, args [][]int) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def runMovingAverage(self, operations: List[str], args: List[List[int]]) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> runMovingAverage(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runMovingAverage", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\"]", "[[3],[1],[10],[3],[5]]"], ["[\"MovingAverage\",\"next\",\"next\"]", "[[1],[4],[5]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[2],[-1],[3],[5]]"], ["[\"MovingAverage\",\"next\"]", "[[3],[7]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[1],[1],[2],[3]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\",\"next\"]", "[[2],[1],[2],[3],[4],[5]]"], ["[\"MovingAverage\",\"next\",\"next\"]", "[[5],[0],[0]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[3],[0],[0],[0]]"], ["[\"MovingAverage\",\"next\",\"next\"]", "[[2],[100000],[100000]]"], ["[\"MovingAverage\",\"next\",\"next\"]", "[[2],[-100000],[-100000]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\"]", "[[4],[1],[2],[3],[4]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[10],[5],[5],[5]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\"]", "[[2],[3],[1],[4],[1]]"], ["[\"MovingAverage\",\"next\"]", "[[1],[-5]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[3],[2],[2],[2]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\"]", "[[3],[1],[2],[3],[4],[5],[6]]"], ["[\"MovingAverage\",\"next\",\"next\"]", "[[1000],[1],[2]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[2],[0],[10],[0]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[5],[1],[1],[1]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\"]", "[[1],[10],[20],[30],[40]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[4],[-2],[4],[-2]]"], ["[\"MovingAverage\",\"next\",\"next\"]", "[[3],[-3],[3]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\",\"next\"]", "[[5],[2],[4],[6],[8],[10]]"], ["[\"MovingAverage\",\"next\"]", "[[100],[42]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\"]", "[[2],[7],[7],[7]]"], ["[\"MovingAverage\",\"next\",\"next\",\"next\",\"next\"]", "[[3],[5],[5],[5],[5]]"]], "expected": [["1.0", "5.5", "4.666666666666667", "6.0"], ["4.0", "5.0"], ["-1.0", "1.0", "4.0"], ["7.0"], ["1.0", "2.0", "3.0"], ["1.0", "1.5", "2.5", "3.5", "4.5"], ["0.0", "0.0"], ["0.0", "0.0", "0.0"], ["100000.0", "100000.0"], ["-100000.0", "-100000.0"], ["1.0", "1.5", "2.0", "2.5"], ["5.0", "5.0", "5.0"], ["3.0", "2.0", "2.5", "2.5"], ["-5.0"], ["2.0", "2.0", "2.0"], ["1.0", "1.5", "2.0", "3.0", "4.0", "5.0"], ["1.0", "1.5"], ["0.0", "5.0", "5.0"], ["1.0", "1.0", "1.0"], ["10.0", "20.0", "30.0", "40.0"], ["-2.0", "1.0", "0.0"], ["-3.0", "0.0"], ["2.0", "3.0", "4.0", "5.0", "6.0"], ["42.0"], ["7.0", "7.0", "7.0"], ["5.0", "5.0", "5.0", "5.0"]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "148", "slug": "multiply-strings", "id": 148, "title": "Multiply Strings", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/multiply-strings/", "examples": [{"input": "num1 = \"2\", num2 = \"3\"", "output": "\"6\"", "explanation": "\"2\" * \"3\" = \"6\"."}, {"input": "num1 = \"123\", num2 = \"456\"", "output": "\"56088\"", "explanation": "\"123\" * \"456\" = \"56088\"."}, {"input": "num1 = \"0\", num2 = \"987654321\"", "output": "\"0\"", "explanation": "\"0\" * \"987654321\" = \"0\"."}], "hints": ["Allocate an integer array with num1.length + num2.length positions for the product digits.", "The product of digits at indices i and j contributes to positions i + j and i + j + 1.", "Propagate each carry while accumulating products, then skip at most one leading zero when building the result."], "statement": "Given two canonical decimal strings `num1` and `num2`, return their product as a canonical decimal string.\n\nBoth inputs represent nonnegative integers. Do not use arbitrary-precision integer libraries, and do not convert either complete input into a built-in integer type.\n\n**Constraints:**\n- `1 <= num1.length, num2.length <= 200`\n- `num1` and `num2` contain only decimal digits\n- Each input has no leading zero unless it is exactly `\"0\"`\n- The returned string must also have no leading zero unless it is `\"0\"`\n", "solution": "## Approach\n\nApply grade-school multiplication directly to the input digits. Store each single-digit product and its carry in an array of length `len(num1) + len(num2)`, where digits at indices `i` and `j` contribute to positions `i + j` and `i + j + 1`. Convert the normalized digit array to a canonical string after removing leading zeroes.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), where m and n are the two string lengths.\n- **Space Complexity:** O(m + n) for the product digits and returned string.\n\n## Implementation\n\n```python\nclass Solution:\n def multiply(self, num1: str, num2: str) -> str:\n if num1 == \"0\" or num2 == \"0\":\n return \"0\"\n\n digits = [0] * (len(num1) + len(num2))\n for i in range(len(num1) - 1, -1, -1):\n for j in range(len(num2) - 1, -1, -1):\n position = i + j + 1\n value = int(num1[i]) * int(num2[j]) + digits[position]\n digits[position] = value % 10\n digits[position - 1] += value // 10\n\n return \"\".join(str(digit) for digit in digits).lstrip(\"0\") or \"0\"\n```\n", "starter": {"go": "package main\n\nfunc Multiply(num1 string, num2 string) string {\n return \"\"\n}", "python": "class Solution:\n def multiply(self, num1: str, num2: str) -> str:\n return \"\"\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string multiply(string num1, string num2) {\n return \"\";\n }\n};"}, "fn": "multiply", "params": [{"name": "num1", "type": "string"}, {"name": "num2", "type": "string"}], "outputType": "string", "tests": [["0", "0"], ["0", "1"], ["1", "0"], ["1", "1"], ["2", "3"], ["9", "9"], ["10", "10"], ["10", "99"], ["99", "10"], ["12", "34"], ["123", "456"], ["999", "999"], ["1000", "1000"], ["1001", "1001"], ["5000", "20"], ["11111", "11111"], ["12345", "67890"], ["99999", "1"], ["1", "99999"], ["314159", "271828"], ["123456789", "987654321"], ["999999999", "999999999"], ["1000000000", "1000000000"], ["4294967295", "4294967295"], ["9223372036854775807", "2"], ["18446744073709551615", "18446744073709551615"], ["100000000000000000000", "100000000000000000000"], ["999999999999999999999", "9"], ["9", "999999999999999999999"], ["12345678901234567890", "98765432109876543210"], ["10101010101010101010", "10101010101010101010"], ["55555555555555555555", "55555555555555555555"], ["99999999999999999999", "99999999999999999999"], ["10000000000000000001", "99999999999999999999"], ["314159265358979323846", "271828182845904523536"], ["123456789123456789123456789", "1"], ["1", "123456789123456789123456789"], ["100000000000000000000000000", "37"], ["37", "100000000000000000000000000"], ["999999999999999999999999999", "999999999999999999999999999"], ["808080808080808080808080808", "707070707070707070707070707"], ["123000000000000000000000321", "456000000000000000000000654"], ["100000000000000000000000001", "100000000000000000000000001"], ["987654321987654321987654321", "123456789123456789123456789"], ["222222222222222222222222222222", "333333333333333333333333333333"], ["999999999999999999999999999999", "10"], ["10", "999999999999999999999999999999"], ["1000000000000000000000000000000", "1000000000000000000000000000000"], ["135791357913579135791357913579", "246802468024680246802468024680"], ["9999999999999999999999999999999999999999", "9999999999999999999999999999999999999999"], ["1000000000000000000000000000000000000001", "9"], ["9090909090909090909090909090909090909090", "1010101010101010101010101010101010101010"], ["1234567890123456789012345678901234567890", "9876543210987654321098765432109876543210"], ["3141592653589793238462643383279502884197", "2718281828459045235360287471352662497757"], ["7777777777777777777777777777777777777777", "13"], ["13", "7777777777777777777777777777777777777777"], ["100000000000000000000000000000000000000000000000001", "100000000000000000000000000000000000000000000000001"], ["999999999999999999999999999999999999999999999999999", "999999999999999999999999999999999999999999999999999"], ["123456789012345678901234567890123456789012345678901", "987654321098765432109876543210987654321098765432109"], ["111111111111111111111111111111111111111111111111111111111111", "9"], ["909999999999999999999999999999999999999999999999999999999999", "100000000000000000000000000000000000000000000000000000000001"], ["314159265358979323846264338327950288419716939937510582097494", "271828182845904523536028747135266249775724709369995957496696"], ["999999999999999999999999999999999999999999999999999999999999999999999999999999", "999999999999999999999999999999999999999999999999999999999999999999999999999999"], ["100000000000000000000000000000000000000000000000000000000000000000000000000001", "100000000000000000000000000000000000000000000000000000000000000000000000000001"], ["12345678901234567890123456789012345678901234567890123456789012345678901234567890", "98765432109876543210987654321098765432109876543210987654321098765432109876543210"], ["@javascript:'1' + '0'.repeat(198)", "@javascript:'7'.repeat(200)"], ["@javascript:'1' + '0'.repeat(199)", "@javascript:'8'.repeat(200)"], ["@javascript:'9'.repeat(200)", "@javascript:'9'.repeat(200)"]], "expected": ["0", "0", "0", "1", "6", "81", "100", "990", "990", "408", "56088", "998001", "1000000", "1002001", "100000", "123454321", "838102050", "99999", "99999", "85397212652", "121932631112635269", "999999998000000001", "1000000000000000000", "18446744065119617025", "18446744073709551614", "340282366920938463426481119284349108225", "10000000000000000000000000000000000000000", "8999999999999999999991", "8999999999999999999991", "1219326311370217952237463801111263526900", "102030405060708091009080706050403020100", "3086419753086419753024691358024691358025", "9999999999999999999800000000000000000001", "1000000000000000000089999999999999999999", "85397342226735670654554622909226073039456", "123456789123456789123456789", "123456789123456789123456789", "3700000000000000000000000000", "3700000000000000000000000000", "999999999999999999999999998000000000000000000000000001", "571370268339965309662279359134782165085195388225691256", "56088000000000000000000226818000000000000000000209934", "10000000000000000000000000200000000000000000000000001", "121932631356500531591068431581771069347203169112635269", "74074074074074074074074074073925925925925925925925925925926", "9999999999999999999999999999990", "9999999999999999999999999999990", "1000000000000000000000000000000000000000000000000000000000000", "33513642269494025653563668707950766200528933958626279129720", "99999999999999999999999999999999999999980000000000000000000000000000000000000001", "9000000000000000000000000000000000000009", "9182736455463728191000918273645546372817263544536271808999081726354453627180900", "12193263113702179522618503273386678859448712086533622923332237463801111263526900", "8539734222673567065463550869546574495033651792769471169863641572989199543246129", "101111111111111111111111111111111111111101", "101111111111111111111111111111111111111101", "10000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000001", "999999999999999999999999999999999999999999999999998000000000000000000000000000000000000000000000000001", "121932631137021795226185032733866788594511507391563293705167081085195583279987445845145533336229232209", "999999999999999999999999999999999999999999999999999999999999", "91000000000000000000000000000000000000000000000000000000000809999999999999999999999999999999999999999999999999999999999", "85397342226735670654635508695465744950348885357651149618795646837904178316044543195967223480215615999237115917254879824", "999999999999999999999999999999999999999999999999999999999999999999999999999998000000000000000000000000000000000000000000000000000000000000000000000000000001", "10000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000001", "1219326311370217952261850327338667885945115073915636335923676116445578859929878986434993786160646167367779295611949397448712086533622923332237463801111263526900", "77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888880000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "736", "slug": "my-calendar-i", "id": 736, "title": "My Calendar I", "difficulty": "Medium", "category": "design", "link": "https://leetcode.com/problems/my-calendar-i/", "examples": [{"input": "operations = [\"MyCalendar\",\"book\",\"book\",\"book\"]\nargs = [[],[10,20],[15,25],[20,30]]", "output": "[1,0,1]", "explanation": "The middle booking overlaps [10,20) and fails; touching at 20 is fine."}, {"input": "operations = [\"MyCalendar\",\"book\",\"book\"]\nargs = [[],[5,10],[10,15]]", "output": "[1,1]"}, {"input": "operations = [\"MyCalendar\",\"book\",\"book\"]\nargs = [[],[0,5],[3,7]]", "output": "[1,0]"}], "hints": ["Keep accepted slots sorted by start (for example in an ordered map) so each booking only checks its neighbours.", "A booking [s,e) clashes with a stored [a,b) exactly when max(s,a) < min(e,b).", "Touching endpoints are fine: [10,20) and [20,30) do not overlap."], "statement": "Imagine a booking service that stores half-open time slots `[start, end)`: the slot covers `start` but stops just before `end`, so two slots that only touch at an endpoint do not clash.\n\nYou receive a sequence of calls. The first entry always creates the calendar; every later entry asks to book one interval. Process the calls in order:\n\n- Creation entries carry no interval.\n- Each booking entry carries `[start, end)` with `start < end` and answers whether the booking succeeds: it succeeds exactly when it overlaps none of the previously accepted bookings, in which case it is stored.\n\nRather than building a class, implement `runCalendar(operations, args)`:\n\n- `operations[i]` is either `\"MyCalendar\"` (create, first entry) or `\"book\"`.\n- `args[i]` is the argument list for that call: `[]` for creation and `[start, end]` for a booking.\n- Return one integer per booking call (skipping the creation entry): `1` when the booking is accepted and `0` when it is rejected.\n\n**Constraints:**\n- `1 <= operations.length <= 1000`\n- `0 <= start < end <= 10^9`\n- At most 1000 bookings.\n", "solution": "## Approach\n\nStore the accepted half-open slots in a structure ordered by start time. For a new request `[s, e)`, only the stored slot starting just before (or at) `s` and the one starting just after `s` can possibly overlap it, because everything else is farther away. The request clashes exactly when the previous slot ends after `s` or the next slot starts before `e`. Otherwise record it and report success.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(b log b) for b bookings, one ordered-map step each.\n- **Space Complexity:** O(b) for the stored slots.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runCalendar(self, operations: List[str], args: List[List[int]]) -> List[int]:\n booked = []\n out = []\n for i in range(1, len(operations)):\n s, e = args[i]\n clash = any(max(s, a) < min(e, b) for a, b in booked)\n if clash:\n out.append(0)\n else:\n booked.append((s, e))\n out.append(1)\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunCalendar(operations []string, args [][]int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runCalendar(self, operations: List[str], args: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runCalendar(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runCalendar", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[10,20],[15,25],[20,30]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[5,10],[10,15]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[0,5],[3,7]]"], ["[\"MyCalendar\",\"book\"]", "[[],[0,100]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[10,20],[20,30]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[10,20],[5,10]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[10,20],[5,15]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[10,20],[10,20]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,2],[3,4],[5,6],[2,3]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,5],[2,3],[6,9],[5,6]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[0,10],[10,20],[5,15]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[47,50],[33,41],[39,45],[33,42],[26,35]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[0,1],[1,2],[2,3]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[0,5],[5,10],[10,15]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[0,1000000000],[500000000,600000000]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\"]", "[[],[5,8],[1,3],[4,6],[7,9]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[20,30],[0,10],[10,20]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,4],[2,5],[6,8],[4,6]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[100,200],[50,100]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,2],[2,3],[3,4],[4,5],[1,5],[6,7]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[3,9],[1,2],[2,3]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,30],[20,40],[5,10],[30,50]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[0,2],[2,4],[1,3]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\"]", "[[],[97,100],[33,51],[89,100],[83,100]]"], ["[\"MyCalendar\",\"book\",\"book\"]", "[[],[0,5],[0,5]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,10],[2,3],[4,5],[6,7],[11,20]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\"]", "[[],[5,6],[1,5],[6,10]]"], ["[\"MyCalendar\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,20],[30,40],[20,30],[15,25],[40,50]]"]], "expected": [[1, 0, 1], [1, 1], [1, 0], [1], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0], [1, 1, 0, 0, 0], [1, 1, 1], [1, 1, 1], [1, 0], [1, 1, 0, 0], [1, 1, 1], [1, 0, 1, 1], [1, 1], [1, 1, 1, 1, 0, 1], [1, 1, 1], [1, 0, 1, 1], [1, 1, 0], [1, 1, 0, 0], [1, 0], [1, 0, 0, 0, 1], [1, 1, 1], [1, 1, 1, 0, 1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "738", "slug": "my-calendar-ii", "id": 738, "title": "My Calendar II", "difficulty": "Medium", "category": "design", "link": "https://leetcode.com/problems/my-calendar-ii/", "examples": [{"input": "operations = [\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\",\"book\",\"book\"]\nargs = [[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]", "output": "[1,1,1,0,1,1]", "explanation": "Only the [5,15) request would pile three bookings over [10,15)."}, {"input": "operations = [\"MyCalendarTwo\",\"book\",\"book\",\"book\"]\nargs = [[],[0,10],[10,20],[5,15]]", "output": "[1,1,1]"}, {"input": "operations = [\"MyCalendarTwo\",\"book\",\"book\",\"book\"]\nargs = [[],[0,10],[5,15],[5,10]]", "output": "[1,1,0]"}], "hints": ["Alongside the stored bookings, keep every pairwise-overlapped (double-covered) segment.", "A new request fails when it overlaps any double-covered segment; otherwise append its overlaps with existing bookings to that list.", "Overlap of [s,e) with [a,b) is [max(s,a), min(e,b)) whenever max < min."], "statement": "Consider a booking service for half-open slots `[start, end)` that tolerates overlaps of up to two bookings but refuses any booking that would create a triple overlap.\n\nYou receive an ordered call sequence. The first entry creates the calendar; each later entry books one interval `[start, end)` with `start < end`. A booking succeeds exactly when adding it keeps every point in time covered by at most two stored slots; successful bookings are stored.\n\nImplement `runCalendarTwo(operations, args)` instead of a class:\n\n- `operations[i]` is `\"MyCalendarTwo\"` for the creation entry, then `\"book\"` for each request.\n- `args[i]` is `[]` for creation and `[start, end]` for a booking.\n- Return one integer per booking call (creation excluded): `1` for accepted, `0` for refused.\n\n**Constraints:**\n- `1 <= operations.length <= 1000`\n- `0 <= start < end <= 10^9`\n", "solution": "## Approach\n\nTrack two lists: confirmed bookings and the pairwise overlaps between them (the double-booked zones). A fresh request is refused when it touches any double-booked zone, because that would stack three bookings. Otherwise compute its overlap with every confirmed booking, append those slices to the double-booked list, and store the booking itself.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(b^2) for b bookings, comparing each request against stored lists.\n- **Space Complexity:** O(b^2) worst case for overlap slices, O(b) typically.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runCalendarTwo(self, operations: List[str], args: List[List[int]]) -> List[int]:\n booked, overlaps, out = [], [], []\n for i in range(1, len(operations)):\n s, e = args[i]\n if any(max(s, a) < min(e, b) for a, b in overlaps):\n out.append(0)\n continue\n for a, b in booked:\n ns, ne = max(s, a), min(e, b)\n if ns < ne:\n overlaps.append((ns, ne))\n booked.append((s, e))\n out.append(1)\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunCalendarTwo(operations []string, args [][]int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runCalendarTwo(self, operations: List[str], args: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runCalendarTwo(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runCalendarTwo", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[0,10],[10,20],[5,15]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[0,10],[5,15],[5,10]]"], ["[\"MyCalendarTwo\",\"book\",\"book\"]", "[[],[10,20],[20,30]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[10,20],[10,20],[10,20]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,5],[2,6],[3,7],[4,8]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[0,5],[5,10],[10,15]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[24,40],[43,50],[27,43],[5,21]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,3],[3,5],[5,7],[2,4],[4,6]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[0,100],[50,150],[100,200]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[0,10],[0,10],[0,10],[0,10]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[5,10],[15,20],[10,15]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,20],[20,30],[30,40],[15,25],[25,35]]"], ["[\"MyCalendarTwo\",\"book\",\"book\"]", "[[],[0,1],[0,1]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[0,2],[1,3],[2,4]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,10],[2,5],[6,9],[3,7]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[100,200],[150,250],[175,225]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[0,3],[1,4],[2,5],[6,9]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[20,27],[11,16],[19,23]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,2],[2,3],[3,4],[4,5],[1,5],[2,4]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[0,10],[10,20],[20,30]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[5,15],[5,15],[5,15],[5,15]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[1,100],[2,3],[4,5]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,30],[5,15],[25,35],[20,28]]"], ["[\"MyCalendarTwo\",\"book\",\"book\"]", "[[],[0,1000000000],[0,1000000000]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\"]", "[[],[3,8],[8,13],[1,5],[4,9]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[20,40],[10,25],[30,50],[15,35],[40,60]]"], ["[\"MyCalendarTwo\",\"book\",\"book\",\"book\"]", "[[],[7,10],[2,5],[4,8]]"]], "expected": [[1, 1, 1, 0, 1, 1], [1, 1, 1], [1, 1, 0], [1, 1], [1, 1, 0], [1, 1, 0, 0], [1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1], [1, 1, 0, 0], [1, 1, 1], [1, 1, 1, 1, 1], [1, 1], [1, 1, 1], [1, 1, 1, 0], [1, 1, 0], [1, 1, 0, 1], [1, 1, 1], [1, 1, 1, 1, 1, 0], [1, 1, 1], [1, 1, 0, 0], [1, 1, 1], [1, 1, 1, 0], [1, 1], [1, 1, 1, 0], [1, 1, 1, 0, 1], [1, 1, 1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "739", "slug": "my-calendar-iii", "id": 739, "title": "My Calendar III", "difficulty": "Hard", "category": "design", "link": "https://leetcode.com/problems/my-calendar-iii/", "examples": [{"input": "operations = [\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\",\"book\",\"book\"]\nargs = [[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]", "output": "[1,1,2,3,3,3]", "explanation": "Peak overlap climbs to 3 at the fourth booking and stays there."}, {"input": "operations = [\"MyCalendarThree\",\"book\",\"book\",\"book\"]\nargs = [[],[0,10],[10,20],[5,15]]", "output": "[1,1,2]"}, {"input": "operations = [\"MyCalendarThree\",\"book\"]\nargs = [[],[1,2]]", "output": "[1]"}], "hints": ["Record +1 at each start and -1 at each end in an ordered map of time deltas.", "After each booking, sweep the deltas in time order with a running total; the maximum is the current peak.", "Half-open slots mean an ending at t frees the point before a slot starting at t begins, which the ordered sweep handles naturally."], "statement": "Consider a booking service for half-open slots `[start, end)` with no refusal rule: every requested slot is stored. After each booking, the service reports the largest number of stored slots covering any single point in time (the peak overlap so far).\n\nYou get an ordered call sequence. The first entry creates the calendar; each later entry books `[start, end)` with `start < end` and always succeeds.\n\nImplement `runCalendarThree(operations, args)`:\n\n- `operations[i]` is `\"MyCalendarThree\"` for the creation entry, then `\"book\"` afterwards.\n- `args[i]` is `[]` for creation and `[start, end]` for a booking.\n- Return one integer per booking (creation excluded): the peak overlap after that booking is stored.\n\n**Constraints:**\n- `1 <= operations.length <= 400`\n- `0 <= start < end <= 10^9`\n", "solution": "## Approach\n\nKeep an ordered timeline of changes: add one at every start and subtract one at every end. Because slots are half-open, processing these changes in time order with a running count reproduces the true overlap at every point. The highest running count after each booking is the requested peak.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(b^2) for b bookings in the simple sweep version (each query scans all distinct endpoints).\n- **Space Complexity:** O(b) for the timeline entries.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runCalendarThree(self, operations: List[str], args: List[List[int]]) -> List[int]:\n from collections import defaultdict\n delta = defaultdict(int)\n out = []\n for i in range(1, len(operations)):\n s, e = args[i]\n delta[s] += 1\n delta[e] -= 1\n cur = best = 0\n for t in sorted(delta):\n cur += delta[t]\n best = max(best, cur)\n out.append(best)\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunCalendarThree(operations []string, args [][]int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runCalendarThree(self, operations: List[str], args: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runCalendarThree(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runCalendarThree", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[0,10],[10,20],[5,15]]"], ["[\"MyCalendarThree\",\"book\"]", "[[],[1,2]]"], ["[\"MyCalendarThree\",\"book\",\"book\"]", "[[],[10,20],[20,30]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[10,20],[10,20],[10,20]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,5],[2,6],[3,7],[4,8]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[0,5],[5,10],[10,15]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,3],[3,5],[5,7],[2,4],[4,6]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[0,100],[50,150],[100,200]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[0,10],[0,10],[0,10],[0,10]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[5,10],[15,20],[10,15]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,20],[20,30],[30,40],[15,25],[25,35]]"], ["[\"MyCalendarThree\",\"book\",\"book\"]", "[[],[0,1],[0,1]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[0,2],[1,3],[2,4]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,10],[2,5],[6,9],[3,7]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[100,200],[150,250],[175,225]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[0,3],[1,4],[2,5],[6,9]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[24,40],[43,50],[27,43],[5,21]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[1,2],[2,3],[3,4],[4,5],[1,5],[2,4]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[0,10],[10,20],[20,30]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[5,15],[5,15],[5,15],[5,15]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[1,100],[2,3],[4,5]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[10,30],[5,15],[25,35],[20,28]]"], ["[\"MyCalendarThree\",\"book\",\"book\"]", "[[],[0,1000000000],[500000000,1000000000]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[3,8],[8,13],[1,5],[4,9]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\",\"book\"]", "[[],[20,40],[10,25],[30,50],[15,35],[40,60]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\"]", "[[],[7,10],[2,5],[4,8]]"], ["[\"MyCalendarThree\",\"book\",\"book\",\"book\",\"book\"]", "[[],[26,35],[26,32],[25,32],[18,26]]"]], "expected": [[1, 1, 2, 3, 3, 3], [1, 1, 2], [1], [1, 1], [1, 2, 3], [1, 2, 3, 4], [1, 1, 1], [1, 1, 1, 2, 2], [1, 2, 2], [1, 2, 3, 4], [1, 1, 1], [1, 1, 1, 2, 2], [1, 2], [1, 2, 2], [1, 2, 2, 3], [1, 2, 3], [1, 2, 3, 3], [1, 1, 2, 2], [1, 1, 1, 1, 2, 3], [1, 1, 1], [1, 2, 3, 4], [1, 2, 2], [1, 2, 2, 3], [1, 2], [1, 1, 2, 3], [1, 2, 2, 3, 3], [1, 1, 2], [1, 2, 3, 3]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "498", "slug": "n-ary-tree-level-order-traversal", "id": 498, "title": "N-ary Tree Level Order Traversal", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/n-ary-tree-level-order-traversal/", "examples": [{"input": "data = \"[1,null,3,2,4,null,5,6]\"", "output": "[[1],[3,2,4],[5,6]]", "explanation": "Depth 0 holds 1, depth 1 its children, depth 2 the grandchildren."}, {"input": "data = \"[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\"", "output": "[[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]]", "explanation": "Each depth collects the nodes at that distance from the root."}, {"input": "data = \"[]\"", "output": "[]", "explanation": "No nodes means no levels."}], "hints": ["Parse the bracket string into tokens and rebuild the N-ary tree with a queue.", "Then run a standard breadth-first walk, slicing the queue per level.", "An empty input yields an empty list of levels."], "statement": "An N-ary tree lets each node carry any number of ordered children. Here the tree arrives as a single string `data` using breadth order with `null` marking each new sibling group: `[1,null,3,2,4,null,5,6]` means root `1` with children `3, 2, 4`, and `3` with children `5, 6`. The empty tree is `[]`.\n\nReturn the level-order grouping of values: a list where entry `k` holds all node values at depth `k`, starting with the root alone.\n\n**Constraints:**\n- Node count lies in `[0, 10^4]`.\n- Node values are integers; height is at most 1000.\n\nAdaptation: the source takes an N-ary `Node` object, which this judge cannot express. Input is therefore the level-order string described above, and output is `int_list_2d`; parsing happens inside the reference.\n", "solution": "## Approach\n\nDecode the string into an N-ary tree by scanning comma-separated tokens and assigning each `null`-delimited group to the next queued node. Then traverse breadth-first, cutting the queue into levels so each depth's values land together.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the token count plus node count.\n- **Space Complexity:** O(m) for tokens, the tree, and the queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nclass Solution:\n def levelOrder(self, data: str):\n s = data.strip()\n if s in ('', '[]'):\n return []\n toks = [t.strip() for t in s[1:-1].split(',') if t.strip() != '']\n if not toks or toks[0] == 'null':\n return []\n class N:\n def __init__(self, v):\n self.val = int(v)\n self.children = []\n root = N(toks[0])\n q = deque([root])\n i = 1\n while q and i < len(toks):\n node = q.popleft()\n if i < len(toks) and toks[i] == 'null':\n i += 1\n kids = []\n while i < len(toks) and toks[i] != 'null':\n c = N(toks[i])\n kids.append(c)\n q.append(c)\n i += 1\n node.children = kids\n ans = []\n q = deque([root])\n while q:\n level = []\n for _ in range(len(q)):\n n = q.popleft()\n level.append(n.val)\n q.extend(n.children)\n ans.append(level)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc LevelOrder(data string) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def levelOrder(self, data: str) -> List[List[int]]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> levelOrder(string data) {\n return {};\n }\n};"}, "fn": "levelOrder", "params": [{"name": "data", "type": "string"}], "outputType": "int_list_2d", "tests": [["[1,null,3,2,4,null,5,6]"], ["[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]"], ["[]"], ["[1]"], ["[1,null,2]"], ["[1,null,3,2,4,null,5,6,7]"], ["[5,null,1,2]"], ["[1,null,2,3]"], ["[1,null,2,null,3]"], ["[2,null,1]"], ["[1,null,2,3,4]"], ["[10,null,1,2,3]"], ["[1,null,2,3,4,5]"], ["[1,null,2,null,3,null,4,null,5]"], ["[7]"], ["[1,null,2,3,null,4,5]"], ["[9,null,5,6,7,null,1,2,3]"], ["[0,null,1,2]"], ["[2,null,3,4]"], ["[100,null,200,300]"], ["[1,null,2,3,4,null,5,null,6]"], ["[-1,null,-2,-3]"], ["[1,null,10,20,30,40,50]"], ["[3,null,1,2,null,4,5,6]"], ["[1,null,2,null,3,null,4]"], ["[5,null,6,null,7,null,8]"], ["[1,null,2,3,4,5,6,7,8]"], ["[42]"]], "expected": [[[1], [3, 2, 4], [5, 6]], [[1], [2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13], [14]], [], [[1]], [[1], [2]], [[1], [3, 2, 4], [5, 6, 7]], [[5], [1, 2]], [[1], [2, 3]], [[1], [2], [3]], [[2], [1]], [[1], [2, 3, 4]], [[10], [1, 2, 3]], [[1], [2, 3, 4, 5]], [[1], [2], [3], [4], [5]], [[7]], [[1], [2, 3], [4, 5]], [[9], [5, 6, 7], [1, 2, 3]], [[0], [1, 2]], [[2], [3, 4]], [[100], [200, 300]], [[1], [2, 3, 4], [5, 6]], [[-1], [-2, -3]], [[1], [10, 20, 30, 40, 50]], [[3], [1, 2], [4, 5, 6]], [[1], [2], [3], [4]], [[5], [6], [7], [8]], [[1], [2, 3, 4, 5, 6, 7, 8]], [[42]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "632", "slug": "n-ary-tree-postorder-traversal", "id": 632, "title": "N-ary Tree Postorder Traversal", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/n-ary-tree-postorder-traversal/", "examples": [{"input": "data = \"[1,null,3,2,4,null,5,6]\"", "output": "[5,6,3,2,4,1]", "explanation": "Children come before their parent, left to right."}, {"input": "data = \"[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\"", "output": "[6,11,7,2,12,8,3,13,9,4,14,10,5,1]", "explanation": "Every subtree is fully listed before its root."}, {"input": "data = \"[]\"", "output": "[]", "explanation": "No nodes means no visits."}], "hints": ["Rebuild the tree from the bracket string with a queue first.", "Walk depth-first, emitting a node only after all its children.", "An empty input yields an empty list.", "Adaptation: the N-ary Node input is encoded as a level-order string; output maps to int_list."], "statement": "Each node in an N-ary tree may have any number of ordered children. The tree arrives as a single string `data` holding a bracketed token list in level order, where `null` ends each node's child group. For instance `\"[1,null,3,2,4,null,5,6]\"` means root 1 with children 3, 2, 4, and node 3 with children 5, 6. The empty tree is `\"[]\"`.\n\nReturn the postorder visit order: each node's children left to right first, then the node itself.\n\n**Constraints:**\n- Token count is at most `10^4`.\n- Values fit in 32-bit signed integers.\n\nAdaptation: the source takes an N-ary `Node` object, which this judge cannot express. Input is therefore the level-order string described above, and output is `int_list`; parsing happens inside the reference.\n", "solution": "## Approach\n\nDecode the bracket string into linked N-ary nodes with a queue, then walk depth-first emitting each node only after all of its children have been listed.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m) for m tokens plus nodes.\n- **Space Complexity:** O(m) for the tree and recursion stack.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def postorder(self, data: str) -> List[int]:\n s = data.strip()\n if s in ('', '[]'):\n return []\n toks = [t.strip() for t in s[1:-1].split(',') if t.strip() != '']\n if not toks or toks[0] == 'null':\n return []\n class N:\n def __init__(self, v):\n self.val = int(v); self.children = []\n root = N(toks[0])\n q = deque([root])\n i = 1\n while q and i < len(toks):\n node = q.popleft()\n if i < len(toks) and toks[i] == 'null':\n i += 1\n kids = []\n while i < len(toks) and toks[i] != 'null':\n c = N(toks[i]); kids.append(c); q.append(c); i += 1\n node.children = kids\n ans = []\n def dfs(n):\n for c in n.children:\n dfs(c)\n ans.append(n.val)\n dfs(root)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc Postorder(data string) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def postorder(self, data: str) -> List[int]:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> postorder(string data) {\n return {};\n }\n};"}, "fn": "postorder", "params": [{"name": "data", "type": "string"}], "outputType": "int_list", "tests": [["[1,null,3,2,4,null,5,6]"], ["[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]"], ["[]"], ["[1]"], ["[1,null,2]"], ["[1,null,2,3]"], ["[1,null,3,2,4,null,5,6,null,null,null,7]"], ["[5,null,1,2,null,3,null,4]"], ["[1,null,2,null,3,null,4]"], ["[1,null,2,3,4,null,5,null,6,null,7]"], ["[10,null,20,30,null,40,50,null,60]"], ["[1,null,2,3,4,5,6]"], ["[2,null,0,null,1]"], ["[1,null,2,null,3,4,null,5,6]"], ["[7,null,3,7,8,null,1,2]"], ["[1,null,5,4,3,null,2]"], ["[9,null,1,2,3,null,4,5,6]"], ["[1,null,2,null,3,null,4,null,5]"], ["[4,null,1,2,3,4]"], ["[1,null,2,3,null,4,5,6,7]"], ["[100]"], ["[1,null,10,20,null,30,40,null,50,60,70]"], ["[3,null,1,2]"], ["[6,null,1,2,3,4,5]"], ["[1,null,2,3,4,null,null,5,6,null,7]"], ["[8,null,4,5,null,6,null,7,8]"], ["[1,null,3,2,4,null,5,6,null,7,8,null,9]"], ["[2,null,3,4,null,5]"]], "expected": [[5, 6, 3, 2, 4, 1], [2, 6, 14, 11, 7, 3, 12, 8, 4, 13, 9, 10, 5, 1], [], [1], [2, 1], [2, 3, 1], [7, 5, 6, 3, 2, 4, 1], [3, 1, 4, 2, 5], [4, 3, 2, 1], [5, 2, 6, 3, 7, 4, 1], [40, 50, 20, 60, 30, 10], [2, 3, 4, 5, 6, 1], [1, 0, 2], [5, 6, 3, 4, 2, 1], [1, 2, 3, 7, 8, 7], [2, 5, 4, 3, 1], [4, 5, 6, 1, 2, 3, 9], [5, 4, 3, 2, 1], [1, 2, 3, 4, 4], [4, 5, 6, 7, 2, 3, 1], [100], [30, 40, 10, 50, 60, 70, 20, 1], [1, 2, 3], [1, 2, 3, 4, 5, 6], [2, 5, 6, 3, 7, 4, 1], [6, 4, 7, 8, 5, 8], [5, 6, 3, 7, 8, 2, 9, 4, 1], [5, 3, 4, 2]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "631", "slug": "n-ary-tree-preorder-traversal", "id": 631, "title": "N-ary Tree Preorder Traversal", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/n-ary-tree-preorder-traversal/", "examples": [{"input": "data = \"[1,null,3,2,4,null,5,6]\"", "output": "[1,3,5,6,2,4]", "explanation": "Visit the root, then each child subtree left to right."}, {"input": "data = \"[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\"", "output": "[1,2,6,7,11,3,8,12,4,9,13,5,10,14]", "explanation": "Depth-first order follows child order at every node."}, {"input": "data = \"[]\"", "output": "[]", "explanation": "No nodes means no visits."}], "hints": ["Rebuild the tree from the bracket string: each null-terminated group belongs to the next queued node.", "Walk depth-first, emitting a node before its children.", "An empty input yields an empty list.", "Adaptation: the N-ary Node input is encoded as a level-order string; output maps to int_list."], "statement": "Each node in an N-ary tree may have any number of ordered children. The tree arrives as a single string `data` holding a bracketed token list in level order, where `null` ends each node's child group. For instance `\"[1,null,3,2,4,null,5,6]\"` means root 1 with children 3, 2, 4, and node 3 with children 5, 6. The empty tree is `\"[]\"`.\n\nReturn the preorder visit order: each node before its children, with children handled left to right.\n\n**Constraints:**\n- Token count is at most `10^4`.\n- Values fit in 32-bit signed integers.\n\nAdaptation: the source takes an N-ary `Node` object, which this judge cannot express. Input is therefore the level-order string described above, and output is `int_list`; parsing happens inside the reference.\n", "solution": "## Approach\n\nDecode the bracket string into linked N-ary nodes with a queue, then walk depth-first emitting each node before recursing into its children in order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m) for m tokens plus nodes.\n- **Space Complexity:** O(m) for the tree and recursion stack.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def preorder(self, data: str) -> List[int]:\n s = data.strip()\n if s in ('', '[]'):\n return []\n toks = [t.strip() for t in s[1:-1].split(',') if t.strip() != '']\n if not toks or toks[0] == 'null':\n return []\n class N:\n def __init__(self, v):\n self.val = int(v); self.children = []\n root = N(toks[0])\n q = deque([root])\n i = 1\n while q and i < len(toks):\n node = q.popleft()\n if i < len(toks) and toks[i] == 'null':\n i += 1\n kids = []\n while i < len(toks) and toks[i] != 'null':\n c = N(toks[i]); kids.append(c); q.append(c); i += 1\n node.children = kids\n ans = []\n def dfs(n):\n ans.append(n.val)\n for c in n.children:\n dfs(c)\n dfs(root)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc Preorder(data string) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def preorder(self, data: str) -> List[int]:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> preorder(string data) {\n return {};\n }\n};"}, "fn": "preorder", "params": [{"name": "data", "type": "string"}], "outputType": "int_list", "tests": [["[1,null,3,2,4,null,5,6]"], ["[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]"], ["[]"], ["[1]"], ["[1,null,2]"], ["[1,null,2,3]"], ["[1,null,3,2,4,null,5,6,null,null,null,7]"], ["[5,null,1,2,null,3,null,4]"], ["[1,null,2,null,3,null,4]"], ["[1,null,2,3,4,null,5,null,6,null,7]"], ["[10,null,20,30,null,40,50,null,60]"], ["[1,null,2,3,4,5,6]"], ["[2,null,0,null,1]"], ["[1,null,2,null,3,4,null,5,6]"], ["[7,null,3,7,8,null,1,2]"], ["[1,null,5,4,3,null,2]"], ["[9,null,1,2,3,null,4,5,6]"], ["[1,null,2,null,3,null,4,null,5]"], ["[4,null,1,2,3,4]"], ["[1,null,2,3,null,4,5,6,7]"], ["[100]"], ["[1,null,10,20,null,30,40,null,50,60,70]"], ["[3,null,1,2]"], ["[6,null,1,2,3,4,5]"], ["[1,null,2,3,4,null,null,5,6,null,7]"], ["[8,null,4,5,null,6,null,7,8]"], ["[1,null,3,2,4,null,5,6,null,7,8,null,9]"], ["[2,null,3,4,null,5]"]], "expected": [[1, 3, 5, 6, 2, 4], [1, 2, 3, 6, 7, 11, 14, 4, 8, 12, 5, 9, 13, 10], [], [1], [1, 2], [1, 2, 3], [1, 3, 5, 7, 6, 2, 4], [5, 1, 3, 2, 4], [1, 2, 3, 4], [1, 2, 5, 3, 6, 4, 7], [10, 20, 40, 50, 30, 60], [1, 2, 3, 4, 5, 6], [2, 0, 1], [1, 2, 3, 5, 6, 4], [7, 3, 1, 2, 7, 8], [1, 5, 2, 4, 3], [9, 1, 4, 5, 6, 2, 3], [1, 2, 3, 4, 5], [4, 1, 2, 3, 4], [1, 2, 4, 5, 6, 7, 3], [100], [1, 10, 30, 40, 20, 50, 60, 70], [3, 1, 2], [6, 1, 2, 3, 4, 5], [1, 2, 3, 5, 6, 4, 7], [8, 4, 6, 5, 7, 8], [1, 3, 5, 6, 2, 7, 8, 4, 9], [2, 3, 5, 4]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "212", "slug": "n-queens-ii", "id": 212, "title": "N-Queens II", "difficulty": "Hard", "category": "backtracking", "link": "https://leetcode.com/problems/n-queens-ii/", "examples": [{"input": "n = 4", "output": "2", "explanation": "There are two distinct solutions to the 4-queens puzzle."}, {"input": "n = 1", "output": "1", "explanation": "There is one distinct solution to the 1-queens puzzle."}], "hints": ["Place one queen per row: a new queen is valid only when its column, diagonal, and anti-diagonal are all free.", "Columns are tracked by index, diagonals by `row - col` (shifted), and anti-diagonals by `row + col`; when all n rows are filled, the placement is a solution."], "statement": "Place `n` queens on an `n x n` board so that no two queens share a row, column, or diagonal \u2014 this is the classic **n-queens** arrangement.\n\nFor a given board size `n`, count how many different valid arrangements exist. Two arrangements differ when at least one queen occupies a different square.\n\n**Constraints:**\n\n- `1 <= n <= 9`\n", "solution": "## Approach\n\nClassic backtracking over rows. Because no two queens may share a column, we place exactly one queen per row and only need to check columns, main diagonals (`row - col`), and anti-diagonals (`row + col`). Mark all three families when a queen is placed, recurse to the next row, then unmark them when backtracking. Each time the last row is reached successfully, increment the count.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n!), the number of placements to explore; pruning by column and diagonal collisions reduces the branching factor sharply.\n- **Space Complexity:** O(n) for the recursion stack and the three boolean arrays.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def totalNQueens(self, n: int) -> int:\n cols = [False] * n\n diags = [False] * (2 * n - 1)\n anti_diags = [False] * (2 * n - 1)\n\n def place(row: int) -> int:\n if row == n:\n return 1\n count = 0\n for col in range(n):\n diag = row - col + n - 1\n anti_diag = row + col\n if cols[col] or diags[diag] or anti_diags[anti_diag]:\n continue\n cols[col] = diags[diag] = anti_diags[anti_diag] = True\n count += place(row + 1)\n cols[col] = diags[diag] = anti_diags[anti_diag] = False\n return count\n\n return place(0)\n```", "starter": {"go": "package main\n\nfunc TotalNQueens(n int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def totalNQueens(self, n: int) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int totalNQueens(int n) {\n \n }\n};"}, "fn": "totalNQueens", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"]], "expected": [1, 0, 0, 2, 10, 4, 40, 92, 352], "loose": false}
|