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": "746", "slug": "cherry-pickup", "id": 746, "title": "Cherry Pickup", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/cherry-pickup/", "examples": [{"input": "grid = [[0,1,-1],[1,0,-1],[1,1,1]]", "output": "5", "explanation": "Two coordinated forward paths gather five cherries around the thorns."}, {"input": "grid = [[1,1,-1],[1,-1,1],[-1,1,1]]", "output": "0", "explanation": "No pair of thorn-free routes reaches the goal."}, {"input": "grid = [[1]]", "output": "1"}], "hints": ["Treat the round trip as two walkers stepping from (0,0) to (n-1,n-1) in lockstep, so both take the same number of steps.", "State (r1, c1, r2) fixes c2 by steps: c2 = r1 + c1 - r2; keep the best cherries for each reachable triple.", "A shared cell contributes its cherry once; unreachable or thorn states stay at negative infinity, and a negative best means answer 0."], "statement": "You are given a square grid where each cell holds `0` (empty), `1` (a cherry), or `-1` (a thorn that blocks passage).\n\nOne trip starts at the top-left corner, moves only right or down to the bottom-right corner, then returns from the bottom-right back to the top-left moving only left or up. A cherry on a visited cell is collected once: stepping on the same cell during both legs still yields just one cherry, and thorn cells can never be entered.\n\nBecause the return path mirrors a second forward path, think of two walkers moving from the top-left to the bottom-right together. Return the greatest number of cherries collectible over such a round trip, or `0` when no valid round trip exists.\n\n**Constraints:**\n- `1 <= grid.length <= 50`\n- `grid[i].length == grid.length`\n- Cells hold only `-1`, `0` or `1`.\n", "solution": "## Approach\n\nView the round trip as two walkers advancing from the start to the goal together, one step each per round, moving only right or down. After `t` rounds both walkers satisfy row + column = t, so a state needs only `(r1, c1, r2)` with `c2` derived. Transitions try the four arrival pairs; thorn cells and unreachable states are skipped. Walkers on the same cell score its cherry once, otherwise both cherries count. The goal state holds the optimum, or stays unreachable.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^3), where n is the grid side: O(n) steps times O(n^2) walker pairs.\n- **Space Complexity:** O(n^3) for the step-indexed table (compressible to O(n^2)).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def cherryPickup(self, grid: List[List[int]]) -> int:\n n = len(grid)\n N = 2 * n - 1\n NEG = -10 ** 9\n dp = [[[-10 ** 9] * n for _ in range(n)] for _ in range(N)]\n if grid[0][0] == -1:\n return 0\n dp[0][0][0] = grid[0][0]\n for t in range(1, N):\n for r1 in range(n):\n for r2 in range(n):\n c1, c2 = t - r1, t - r2\n if not (0 <= c1 < n and 0 <= c2 < n):\n continue\n if grid[r1][c1] == -1 or grid[r2][c2] == -1:\n continue\n best = NEG\n for pr1 in (r1 - 1, r1):\n for pr2 in (r2 - 1, r2):\n if pr1 < 0 or pr2 < 0:\n continue\n best = max(best, dp[t - 1][pr1][pr2])\n if best == NEG:\n continue\n add = grid[r1][c1] + (grid[r2][c2] if r1 != r2 else 0)\n dp[t][r1][r2] = best + add\n return max(dp[N - 1][n - 1][n - 1], 0)\n```\n", "starter": {"go": "package main\n\nfunc CherryPickup(grid [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def cherryPickup(self, grid: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int cherryPickup(vector<vector<int>>& grid) {\n return 0;\n }\n};"}, "fn": "cherryPickup", "params": [{"name": "grid", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0,1,-1],[1,0,-1],[1,1,1]]"], ["[[1,1,-1],[1,-1,1],[-1,1,1]]"], ["[[1]]"], ["[[0]]"], ["[[1,1],[1,1]]"], ["[[1,-1],[1,1]]"], ["[[0,0],[0,0]]"], ["[[1,0,1],[0,1,0],[1,0,1]]"], ["[[1,1,1],[1,1,1],[1,1,1]]"], ["[[0,-1],[1,1]]"], ["[[1,0],[0,1]]"], ["[[1,1,0],[1,1,0],[0,0,1]]"], ["[[1,-1,-1],[1,1,1],[1,1,1]]"], ["[[0,1,1],[1,0,1],[1,1,0]]"], ["[[1,0,-1],[0,1,-1],[-1,-1,1]]"], ["[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]"], ["[[0,0,0],[0,0,0],[0,0,0]]"], ["[[1,0],[1,-1]]"], ["[[-1]]"], ["[[1,1],[1,-1]]"], ["[[0,1],[1,0]]"], ["[[1,0,0],[0,-1,0],[0,0,1]]"], ["[[1,1,-1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]"], ["[[0,1,-1,0],[1,0,1,0],[0,1,0,1],[1,0,1,0]]"], ["[[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1]]"], ["[[1,1,1],[0,0,0],[1,1,1]]"], ["[[0,0,1],[0,0,1],[1,1,1]]"], ["[[1,-1,1],[1,1,1],[1,1,1]]"]], "expected": [5, 0, 1, 0, 4, 3, 0, 4, 8, 2, 2, 5, 7, 6, 0, 12, 0, 0, 0, 0, 2, 2, 12, 6, 8, 6, 5, 7], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "524", "slug": "circular-array-loop", "id": 524, "title": "Circular Array Loop", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/circular-array-loop/", "examples": [{"input": "nums = [2,-1,1,2,2]", "output": "true", "explanation": "Starting at index 0, the jumps visit 0 -> 2 -> 3 -> 0, a loop of length 3 where every jump is forward."}, {"input": "nums = [-1,2]", "output": "false", "explanation": "From index 0 the jump goes backward to index 1, but from index 1 the jump goes forward to index 0, so the directions mix and no valid loop exists."}, {"input": "nums = [-2,1,-1,-2,-2]", "output": "false", "explanation": "Every walk either changes direction or collapses onto a single index, so there is no loop of length greater than 1."}], "hints": ["From each start index, walk forward following the jumps while every step keeps the starting direction.", "A walk that revisits one of its own indices (with a real move, not a self-loop) proves a valid cycle exists."], "statement": "You are given a circular array `nums` of length `n`. From index `i` you jump to index `(i + nums[i]) mod n`, wrapping around the ends: a positive value moves forward and a negative value moves backward.\n\nA valid loop is a cycle of indices with length greater than 1 such that every jump in the cycle points the same way (all forward or all backward). A jump that lands back on its own index does not count, since that cycle has length 1.\n\nReturn `true` if such a loop exists, and `false` otherwise.\n\n**Constraints:**\n- `1 <= n <= 5000`\n- `-1000 <= nums[i] <= 1000`\n- `nums[i] != 0`\n", "solution": "## Approach\n\nTry every index as a possible loop entry. From a start, follow the jumps while each visited value keeps the starting direction, remembering every index seen on the current walk. Landing on an index already in the walk (through a genuine move to a different index) reveals a same-direction cycle, so return true. If the walk changes direction, stalls on one index, or runs out of steps, move on to the next start.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), since each of the n walks takes at most n steps.\n- **Space Complexity:** O(n) for the set of visited indices on one walk.\n\n## Implementation\n\n```python\nclass Solution:\n def circularArrayLoop(self, nums: list) -> bool:\n n = len(nums)\n for start in range(n):\n fwd = nums[start] > 0\n seen = {start}\n cur = start\n for _ in range(n):\n if (nums[cur] > 0) != fwd:\n break\n nxt = (cur + nums[cur]) % n\n if nxt == cur:\n break\n if nxt in seen:\n return True\n seen.add(nxt)\n cur = nxt\n return False\n```\n", "starter": {"go": "package main\n\nfunc CircularArrayLoop(nums []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def circularArrayLoop(self, nums: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool circularArrayLoop(vector<int>& nums) {\n return false;\n }\n};"}, "fn": "circularArrayLoop", "params": [{"name": "nums", "type": "int_array"}], "outputType": "boolean", "tests": [["[2,-1,1,2,2]"], ["[-1,2]"], ["[-2,1,-1,-2,-2]"], ["[1,1]"], ["[1]"], ["[-1]"], ["[2,2,2,2]"], ["[1,-1]"], ["[3,1,2]"], ["[-1,-1,-1]"], ["[1,2,3,4,5]"], ["[-2,-3,-9]"], ["[2,-1,1,-2,-2]"], ["[5,1,1,1,1]"], ["@javascript:JSON.stringify(Array(5000).fill(1))"], ["[2,2]"], ["[-2,-2]"], ["[1,2,3]"], ["[-1,-2,-3]"], ["[2,1,1,1,1]"], ["[1,1,1,1]"], ["[-1,-1,-1,-1]"], ["[3,3,3]"], ["[2,-2]"], ["[1,2,-3]"], ["[4,1,1,1,1]"], ["[-3,-1,-2]"], ["[1,3,2,4]"]], "expected": [true, false, false, true, false, false, true, false, true, true, true, false, false, false, true, false, false, true, false, true, true, true, false, false, true, true, false, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "16", "slug": "climbing-stairs", "id": 16, "title": "Climbing Stairs", "difficulty": "Easy", "category": "dp", "link": "https://leetcode.com/problems/climbing-stairs/", "examples": [{"input": "n = 2", "output": "2", "explanation": "There are 2 ways: 1 step + 1 step, or 2 steps."}, {"input": "n = 3", "output": "3", "explanation": "There are 3 ways: 1+1+1, 1+2, 2+1."}], "hints": ["Classic DP: ways[n] = ways[n-1] + ways[n-2]. With O(1) space we can keep just the last two values."], "statement": "A stairway rises `n` treads to its summit.\nFrom any tread you may advance upward by either a single tread or a pair of treads.\nTally how many separate step patterns reach the summit.\n\n**Constraints:**\n\n- 1 \u2264 n \u2264 45\n", "solution": "## Approach\n\nClassic DP where the number of ways to reach step i is the sum of ways to reach steps i-1 and i-2 (fibonacci pattern).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nclass Solution:\n def climbStairs(self, n: int) -> int:\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b\n```\n", "starter": {"go": "package main\n\nfunc ClimbStairs(n int) int {\n \n}", "python": "class Solution:\n def climbStairs(self, n: int) -> int:\n pass\n", "cpp": "class Solution {\npublic:\n int climbStairs(int n) {\n return 0;\n }\n};"}, "fn": "climbStairs", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["1"], ["2"], ["3"], ["4"], ["5"], ["10"], ["20"], ["45"], ["6"], ["7"], ["8"], ["9"], ["11"], ["12"], ["13"], ["14"], ["15"], ["16"], ["17"], ["18"], ["19"], ["21"], ["22"], ["23"], ["24"], ["25"], ["26"], ["27"], ["28"], ["30"], ["35"], ["40"]], "expected": [1, 2, 3, 5, 8, 89, 10946, 1836311903, 13, 21, 34, 55, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 1346269, 14930352, 165580141], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "27", "slug": "clone-graph", "id": 27, "title": "Clone Graph", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/clone-graph/", "examples": [{"input": "adjList = [[2,4],[1,3],[2,4],[1,3]]", "output": "[[2,4],[1,3],[2,4],[1,3]]", "explanation": "A graph with 4 nodes connected as a cycle."}, {"input": "adjList = [[]]", "output": "[[]]", "explanation": "A graph with 1 node and no neighbors."}, {"input": "adjList = []", "output": "[]", "explanation": "An empty graph."}, {"input": "adjList = [[2],[1]]", "output": "[[2],[1]]", "explanation": "Two nodes connected by a single edge."}], "hints": ["Use a HashMap to map original nodes to their clones.", "Traverse the graph using DFS or BFS. For each node visited, create a clone if not already created, then recursively/breadth-first clone its neighbors.", "Be careful to avoid infinite loops due to cycles in the graph."], "statement": "A pointer to one vertex of a **linked undirected** network is supplied.\n\nProduce an independent duplicate (**thorough replica**) of the whole network.\n\nEvery vertex stores an integer payload (`int`) together with its adjacency catalogue.\n\n```java\nclass Node {\n public int val;\n public List<Node> neighbors;\n}\n```\n\n**Evaluation layout:**\n\nTo keep cases compact, vertex payloads coincide with vertex ordinals (1-based).\nThe supplied `adjList` is a two-dimensional listing in which `adjList[i]` enumerates every neighbour of the `i`-th vertex (1-based).\nNo `adjList[i]` arrives in any guaranteed ordering.\n\nThe routine accepts a pointer to the opening vertex of the network (the `Node` whose `val = 1`).\nIt must hand back a pointer to the counterpart of that opening vertex inside the duplicated network.\n\n**Constraints:**\n- The number of nodes in the graph is in the range `[0, 100]`.\n- `1 <= Node.val <= 100`\n- `Node.val` is unique for each node.\n- There are no repeated edges and no self-loops in the graph.\n- The graph is connected and all nodes can be visited starting from the given node.\n", "solution": "## Approach\n\nBFS traversal using a hashmap from original to cloned nodes to avoid cycles and ensure each node is cloned exactly once.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(V+E)\n- **Space Complexity:** O(V)\n\n## Implementation\n\n```python\nfrom typing import Optional\nfrom collections import deque\nclass Solution:\n def cloneGraph(self, node: Optional['GraphNode']) -> Optional['GraphNode']:\n if not node:\n return None\n m = {}\n q = deque([node])\n m[node] = GraphNode(node.val)\n while q:\n cur = q.popleft()\n for nb in cur.neighbors:\n if nb not in m:\n m[nb] = GraphNode(nb.val)\n q.append(nb)\n m[cur].neighbors.append(m[nb])\n return m[node]\n```\n", "starter": {"go": "// Definition for a GraphNode.\n// type GraphNode struct {\n// Val int\n// Neighbors []*GraphNode\n// }\n\npackage main\n\nfunc CloneGraph(adjList *GraphNode) *GraphNode {\n \n}", "python": "# Definition for a GraphNode.\n# class GraphNode:\n# def __init__(self, val=0, neighbors=None):\n# self.val = val\n# self.neighbors = neighbors if neighbors is not None else []\n\nfrom typing import Optional, List\nclass Solution:\n def cloneGraph(self, node: Optional['GraphNode']) -> Optional['GraphNode']:\n ", "cpp": "/*\n// Definition for a GraphNode.\nclass GraphNode {\npublic:\n int val;\n vector<GraphNode*> neighbors;\n GraphNode() {\n val = 0;\n neighbors = vector<GraphNode*>();\n }\n GraphNode(int _val) {\n val = _val;\n neighbors = vector<GraphNode*>();\n }\n GraphNode(int _val, vector<GraphNode*> _neighbors) {\n val = _val;\n neighbors = _neighbors;\n }\n};\n*/\n#include <vector>\n#include <unordered_map>\nusing namespace std;\n\nclass Solution {\npublic:\n GraphNode* cloneGraph(GraphNode* node) {\n return nullptr;\n }\n};"}, "fn": "cloneGraph", "params": [{"name": "adjList", "type": "graph_node", "visualizeType": "adjacency_list"}], "outputType": "graph_node", "tests": [["[[2,4],[1,3],[2,4],[1,3]]"], ["[[]]"], ["[]"], ["[[2],[1]]"], ["[[2],[1,3],[2,4],[3,5],[4,6],[5,7],[6,8],[7,9],[8,10],[9]]"], ["[[2],[1,3],[2]]"], ["[[2,3,4,5],[1,3,4,5],[1,2,4,5],[1,2,3,5],[1,2,3,4]]"], ["[[2,3],[1],[1]]"], ["[[2,5],[1,3],[2,4],[3,5],[1,4]]"], ["[[2,3,4],[1,3,4],[1,2,4],[1,2,3]]"], ["[[2,3],[1,3],[1,2]]"], ["[[2,3,4],[1],[1],[1]]"], ["[[2,3,4,5],[1],[1],[1],[1]]"], ["[[2],[1,3],[2,4],[3]]"], ["[[2],[1,3],[2,4],[3,5],[4]]"], ["[[2,3],[1,3],[1,2,4],[3,5],[4]]"], ["[[2,4,3],[1,3],[1,2],[1]]"], ["[[2],[1,3],[2,4],[3,5],[4,6],[5]]"], ["[[2,3],[1,4],[1,4],[2,3,5],[4]]"], ["[[2,3],[1,3,4],[1,2,4],[2,3]]"], ["[[2,3,4],[1,4],[1,4],[1,2,3]]"], ["[[2],[1,3],[2,4],[3,5],[4,6],[5,7],[6]]"], ["[[2,5],[1,3],[2,4],[3],[1]]"], ["[[2,3],[1,4],[1,5],[2],[3]]"], ["[[2,3,4],[1,3],[1,2],[1]]"], ["[[2,6],[1,3],[2,4],[3,5],[4,6],[1,5]]"], ["[[2,3],[1,3],[1,2,4],[3,5],[4,6],[5]]"], ["[[2,3,4,5,6],[1],[1],[1],[1],[1]]"], ["[[2],[1,3],[2,4],[3,5],[4,6],[5,7],[6,8],[7]]"], ["[[2,3,4],[1,3],[1,2],[1,5],[4,6],[5]]"], ["[[2,4],[1,3],[2,4,5],[1,3],[3]]"], ["[[2,3,5],[1,3],[1,2],[5],[1,4]]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "371", "slug": "closest-binary-search-tree-value-ii", "id": 371, "title": "Closest Binary Search Tree Value II", "difficulty": "Hard", "category": "tree", "link": "https://leetcode.com/problems/closest-binary-search-tree-value-ii/", "examples": [{"input": "root = [4,2,5,1,3], target = \"3.714286\", k = 2", "output": "[4,3]", "explanation": "Distances grow as 4 (0.286), 3 (0.714), 5 (1.286), 2 (1.714), 1 (2.714), so the two closest are 4 and 3 in any order."}, {"input": "root = [1], target = \"0.000000\", k = 1", "output": "[1]", "explanation": "The single value is the only candidate."}, {"input": "root = [5,3,8,1,4,7,9], target = \"6.0\", k = 3", "output": "[5,7,4]", "explanation": "The closest distances are 5 and 7 (1.0 each) and then 4 (2.0)."}], "hints": ["This is a portable adaptation: parse the target string as a double and compare absolute differences.", "Collect values with an inorder walk, sort them by distance to the target (breaking ties by smaller value), and take the first k.", "Any order of those k values is accepted by the checker."], "statement": "Given the root of a binary search tree, a decimal `target` passed as a string (for example `\"3.714286\"`) and an integer `k`, return the `k` tree values numerically closest to `target`. Return them in any order.\n\nThis is a portable adaptation: parse `target` as a double and compare distances numerically. A checker accepts any set of `k` values whose largest distance does not exceed the smallest distance outside the set.\n\n**Constraints:**\n- `1 <= number of nodes <= 10^4`\n- `1 <= k <= number of nodes`\n- `-10^4 <= Node.val <= 10^4`\n- The tree is a valid binary search tree.\n- `target` is a decimal string parseable by a double.\n", "solution": "## Approach\n\nParse the decimal target string into a double and collect all tree values with an inorder walk. Sort the values by absolute distance to the target, breaking ties by the smaller value, and return the first k. The checker accepts any order of a valid k-set by comparing the largest distance inside the answer against the smallest distance outside it.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n), where n is the number of nodes, for sorting by distance.\n- **Space Complexity:** O(n) for the collected values.\n\n## Implementation\n\n```python\nclass Solution:\n def closestKValues(self, root, target: str, k: int) -> list[int]:\n t = float(target)\n vals: list[int] = []\n def inorder(node) -> None:\n if node is None:\n return\n inorder(node.left)\n vals.append(node.val)\n inorder(node.right)\n inorder(root)\n vals.sort(key=lambda v: (abs(v - t), v))\n return vals[:k]\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc ClosestKValues(root *TreeNode, target string, k int) []int {\n return []int{}\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\n\nclass Solution:\n def closestKValues(self, root, target: str, k: int) -> List[int]:\n return []\n", "cpp": "/**\n * Definition for a binary tree node.\n * struct 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 <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> closestKValues(TreeNode* root, string target, int k) {\n return {};\n }\n};"}, "fn": "closestKValues", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "target", "type": "string"}, {"name": "k", "type": "int"}], "outputType": "int_list", "tests": [["[4,2,5,1,3]", "3.714286", "2"], ["[1]", "0.000000", "1"], ["[5,3,8,1,4,7,9]", "6.0", "3"], ["[9,4,15,2,6,12,20]", "10.0", "2"], ["[4,2,5,1,3]", "3.5", "2"], ["[4,2,5,1,3]", "3.5", "5"], ["[10,5,15,3,7,12,20]", "13.7", "3"], ["[10,5,15,3,7,12,20]", "1.0", "2"], ["[2,1,3]", "2.1", "1"], ["[2,1,3]", "2.1", "3"], ["[5,3,8,1,4,7,9]", "6.5", "2"], ["[100,50,150,25,75,125,175]", "100.4", "4"], ["[1,2,3]", "2.5", "2"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "5.5", "3"], ["[42]", "42.0", "1"], ["[4,2,6,1,3,5,7]", "4.5", "3"], ["[20,10,30,5,15,25,35]", "17.333", "2"], ["[9,4,15,2,6,12,20]", "0.0", "3"], ["[9,4,15,2,6,12,20]", "30.0", "2"], ["[5,1,9]", "7.0", "1"], ["[-10,-20,0,-30,-5]", "-7.5", "2"], ["[3,null,5,null,7]", "6.0", "2"], ["[1,null,2,null,3]", "1.6", "2"], ["[7,3,11,1,5,9,13]", "8.0", "4"], ["[6,2,8,0,4,7,9]", "5.0", "3"], ["[15,10,20,8,12,17,25]", "13.0", "5"]], "expected": [[4, 3], [1], [5, 7, 4], [9, 12], [3, 4], [3, 4, 2, 5, 1], [15, 12, 10], [3, 5], [2], [2, 3, 1], [7, 5], [100, 125, 75, 150], [2, 3], [6, 4, 7], [42], [4, 5, 3], [15, 20], [2, 4, 6], [20, 15], [5], [-10, -5], [5, 7], [2, 1], [7, 9, 5, 11], [4, 6, 7], [12, 15, 10, 17, 8]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "370", "slug": "closest-binary-search-tree-value", "id": 370, "title": "Closest Binary Search Tree Value", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/closest-binary-search-tree-value/", "examples": [{"input": "root = [4,2,5,1,3], target = \"3.714286\"", "output": "4", "explanation": "4 is 0.285714 away, closer than 3 at 0.714286 and all other values."}, {"input": "root = [1], target = \"4.428571\"", "output": "1", "explanation": "The only value 1 is trivially the closest."}, {"input": "root = [4,2,5,1,3], target = \"3.5\"", "output": "3", "explanation": "3 and 4 tie at distance 0.5, and the tie goes to the smaller value 3."}], "hints": ["This is a portable adaptation: parse the target string as a double and compare absolute differences.", "Walk down the search tree, moving left or right by comparing the target with each node, tracking the best value seen.", "On an exact distance tie, keep the smaller value."], "statement": "Given the root of a binary search tree and a decimal `target` passed as a string (for example `\"3.714286\"`), return the tree value numerically closest to `target`.\n\nThis is a portable adaptation: parse `target` as a double and compare distances numerically. When two values are equally close, return the smaller one.\n\n**Constraints:**\n- `1 <= number of nodes <= 10^4`\n- `-10^4 <= Node.val <= 10^4`\n- The tree is a valid binary search tree.\n- `\"-10^5\" <= target <= \"10^5\"` as a decimal string parseable by a double.\n", "solution": "## Approach\n\nParse the decimal target string into a double, then walk down the search tree from the root. At each node compare its distance to the target with the best distance seen so far, keeping the smaller value on ties. Move left when the target is smaller and right when it is larger, which visits only one path from root to leaf.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(h), where h is the tree height.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def closestValue(self, root, target: str) -> int:\n t = float(target)\n best = root.val\n best_diff = abs(root.val - t)\n node = root\n while node is not None:\n diff = abs(node.val - t)\n if diff < best_diff - 1e-12 or (abs(diff - best_diff) <= 1e-12 and node.val < best):\n best, best_diff = node.val, diff\n if t < node.val:\n node = node.left\n elif t > node.val:\n node = node.right\n else:\n break\n return best\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc ClosestValue(root *TreeNode, target string) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def closestValue(self, root, target: str) -> int:\n return 0\n", "cpp": "/**\n * Definition for a binary tree node.\n * struct 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 <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int closestValue(TreeNode* root, string target) {\n return 0;\n }\n};"}, "fn": "closestValue", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "target", "type": "string"}], "outputType": "int", "tests": [["[4,2,5,1,3]", "3.714286"], ["[1]", "4.428571"], ["[4,2,5,1,3]", "3.5"], ["[9,4,15,2,6,12,20]", "10.0"], ["[1,2,3]", "2.1"], ["[5,3,8,1,4,7,9]", "6.0"], ["[5,3,8,1,4,7,9]", "6.5"], ["[10,5,15,3,7,12,20]", "13.7"], ["[10,5,15,3,7,12,20]", "1.0"], ["[10,5,15,3,7,12,20]", "25.0"], ["[2,1,3]", "0.1"], ["[2,1,3]", "3.9"], ["[100,50,150,25,75,125,175]", "100.4"], ["[100,50,150,25,75,125,175]", "62.5"], ["[1,null,2,null,3]", "2.6"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "5.5"], ["[42]", "42.0"], ["[42]", "0.0"], ["[5,1,9]", "7.0"], ["[5,1,9]", "3.0"], ["[-10,-20,0,-30,-5]", "-7.5"], ["[-10,-20,0,-30,-5]", "-25.0"], ["[4,2,6,1,3,5,7]", "4.5"], ["[4,2,6,1,3,5,7]", "2.5"], ["[20,10,30,5,15,25,35]", "17.333"], ["[3,null,5,null,7]", "6.0"]], "expected": [4, 1, 3, 9, 3, 5, 7, 15, 3, 20, 1, 3, 100, 50, 3, 6, 42, 42, 5, 1, -10, -30, 4, 2, 15, 5], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "747", "slug": "closest-leaf-in-a-binary-tree", "id": 747, "title": "Closest Leaf in a Binary Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/closest-leaf-in-a-binary-tree/", "examples": [{"input": "root = [1,3,2], k = 1", "output": "2", "explanation": "Leaves 3 and 2 are both one edge from 1; either counts."}, {"input": "root = [1], k = 1", "output": "1", "explanation": "The root itself is a leaf."}, {"input": "root = [1,2,3,4,null,null,null,5,null,6], k = 2", "output": "3", "explanation": "Leaf 3 is one edge away from node 2; leaf 6 is farther."}], "hints": ["View the tree as an undirected graph by remembering each node's parent, then search outward from the target.", "A breadth-first search from the node holding k reaches leaves in order of increasing distance; the first leaf found is an answer.", "The root counts as a leaf when it has no children."], "statement": "You are given the root of a binary tree in which every node holds a distinct integer, plus a target value `k` that appears somewhere in the tree.\n\nA leaf is a node with no children at all. You may travel along parent-child links in either direction, and the length of a route is the number of edges used.\n\nReturn the value stored in a leaf that is as close as possible to the node holding `k`. When several leaves tie for the shortest distance, any one of them is accepted.\n\n**Constraints:**\n- `1 <= number of nodes <= 1000`\n- `1 <= Node.val <= 1000`\n- Every value in the tree is unique.\n- Some node holds the value `k`.\n", "solution": "## Approach\n\nRecord each node's parent with one depth-first walk while locating the node that holds `k`. Then run a breadth-first search starting from that target, stepping to parents and children alike. The first node dequeued without children is the nearest leaf, because BFS expands in order of edge distance.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited a constant number of times.\n- **Space Complexity:** O(n) for the parent table and the BFS queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nclass Solution:\n def findClosestLeaf(self, root, k: int) -> int:\n parent = {}\n target = None\n stack = [(root, None)]\n while stack:\n node, par = stack.pop()\n if node is None:\n continue\n parent[id(node)] = par\n if node.val == k:\n target = node\n stack.append((node.left, node))\n stack.append((node.right, node))\n q = deque([target])\n seen = {id(target)}\n while q:\n cur = q.popleft()\n if cur.left is None and cur.right is None:\n return cur.val\n for nb in (parent.get(id(cur)), cur.left, cur.right):\n if nb is not None and id(nb) not in seen:\n seen.add(id(nb))\n q.append(nb)\n return -1\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc FindClosestLeaf(root *TreeNode, k int) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import Optional\nclass Solution:\n def findClosestLeaf(self, root, k: int) -> int:\n pass", "cpp": "/**\n * Definition for a binary tree node.\n * struct 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 int findClosestLeaf(TreeNode* root, int k) {\n return 0;\n }\n};"}, "fn": "findClosestLeaf", "params": [{"name": "root", "type": "tree_node"}, {"name": "k", "type": "int"}], "outputType": "int", "tests": [["[1,3,2]", "1"], ["[1]", "1"], ["[1,2,3,4,null,null,null,5,null,6]", "2"], ["[1,2,3]", "2"], ["[1,2,3]", "1"], ["[4,2,6,1,3,5,7]", "4"], ["[1,2,null,3,null,4,null,5]", "5"], ["[1,2,null,3,null,4,null,5]", "1"], ["[1,2,null,3]", "3"], ["[1,2,3,4,5,6,7]", "4"], ["[1,2,3,4,5,null,6]", "5"], ["[10,5,15,3,7,null,20]", "7"], ["[10,5,15,3,7,null,20]", "5"], ["[1,2,null,4,5]", "4"], ["[1,null,2,null,3]", "3"], ["[5,3,8,2,4,7,9]", "2"], ["[5,3,8,2,4,7,9]", "3"], ["[100,50,150,25,75,null,null]", "25"], ["[1,2,3,4,null,5,6,null,null,7]", "7"], ["[2,1]", "1"], ["[2,1]", "2"], ["[1,null,2]", "2"], ["[1,null,2]", "1"], ["[3,1,4,null,2]", "2"], ["[7,3,9,1,5,null,11]", "5"], ["[7,3,9,1,5,null,11]", "3"], ["[1,2,3,null,4,null,5]", "4"], ["[50]", "50"]], "expected": [3, 1, 3, 2, 2, 1, 5, 5, 3, 4, 5, 7, 3, 4, 3, 2, 2, 25, 7, 1, 1, 2, 2, 2, 5, 1, 4, 50], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "130", "slug": "coin-change-ii", "id": 130, "title": "Coin Change II", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/coin-change-ii/", "examples": [{"input": "amount = 5, coins = [1,2,5]", "output": "4", "explanation": "There are four order-independent combinations."}, {"input": "amount = 3, coins = [2]", "output": "0", "explanation": "The number of combinations to make 3 is 0."}, {"input": "amount = 10, coins = [10]", "output": "1", "explanation": "The number of combinations to make 10 is 1."}], "hints": ["Use one-dimensional dynamic programming where dp[value] counts combinations for that value.", "Process coins in the outer loop so permutations of one combination are not counted again."], "statement": "An integer `amount` plus an array `coins` holding mutually different token face values are provided.\nEvery face value may be reused without bound.\nCount how many unordered selections total exactly `amount`.\nPermutations of an identical multiset merge into a single tally.\nThe tally is promised to remain representable by a signed 32-bit integer.\n\n**Constraints:**\n- `0 <= amount <= 5000`\n- `1 <= coins.length <= 300`\n- `1 <= coins[i] <= 5000`\n- All values in `coins` are distinct.\n", "solution": "## Approach\n\nLet `combinations[value]` be the number of ways to form `value` using the coins seen so\nfar. Initialize the empty combination for amount zero, then process each coin in the\nouter loop. This ordering counts combinations without counting different permutations\nof the same coins.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * amount), where `n` is the number of denominations.\n- **Space Complexity:** O(amount).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def change(self, amount: int, coins: List[int]) -> int:\n combinations = [0] * (amount + 1)\n combinations[0] = 1\n for coin in coins:\n for value in range(coin, amount + 1):\n combinations[value] += combinations[value - coin]\n return combinations[amount]\n```\n", "starter": {"go": "package main\n\nfunc Change(amount int, coins []int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def change(self, amount: int, coins: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int change(int amount, vector<int>& coins) {\n return 0;\n }\n};"}, "fn": "change", "params": [{"name": "amount", "type": "int"}, {"name": "coins", "type": "int_array"}], "outputType": "int", "tests": [["5", "[1,2,5]"], ["3", "[2]"], ["10", "[10]"], ["0", "[1]"], ["0", "[2,3]"], ["1", "[1]"], ["1", "[2]"], ["2", "[1,2]"], ["4", "[1,2,3]"], ["5", "[5,2,1]"], ["6", "[1,3,4]"], ["7", "[2,3,6]"], ["8", "[2,4]"], ["9", "[2,4]"], ["10", "[2,5,3,6]"], ["11", "[1,5,7]"], ["12", "[2,3,7]"], ["13", "[3,5,7]"], ["20", "[1,2,5,10]"], ["25", "[1,5,10,25]"], ["30", "[2,3,5]"], ["50", "[1,2,5,10,20,50]"], ["100", "[1,5,10,25,50]"], ["100", "[1,2,3,4,5,6,7,8,9,10]"], ["99", "[2,3,7,11]"], ["37", "[4,6,9]"], ["36", "[4,6,9]"], ["17", "[2,4,8,16]"], ["16", "[2,4,8,16]"], ["31", "[3,10,25]"], ["32", "[3,10,25]"], ["41", "[6,9,20]"], ["40", "[6,9,20]"], ["75", "[7,11,13]"], ["84", "[7,11,13]"], ["120", "[1,7,13,29]"], ["150", "[2,5,10,20,50]"], ["200", "[1,20,50,100]"], ["250", "[1,3,11,37]"], ["63", "[1,2,4,8,16,32]"], ["64", "[1,2,4,8,16,32,64]"], ["73", "[5,10,25]"], ["75", "[5,10,25]"], ["18", "[20,1,7]"], ["19", "[20,1,7]"], ["5000", "[5000]"], ["5000", "[4999]"], ["5000", "[4999,5000]"], ["4999", "[4999,5000]"], ["97", "[97,89,83]"], ["178", "[97,89,83]"], ["42", "[1,6,14,21]"], ["101", "[2,7,15,31]"], ["80", "[3,8,19,40]"], ["100", "[6,10,15]"], ["29", "[30,31,32]"], ["5000", "@javascript:JSON.stringify(Array.from({length:300},(_,i)=>4701+i))"]], "expected": [4, 0, 1, 1, 1, 1, 0, 2, 4, 4, 4, 1, 3, 0, 5, 4, 4, 2, 40, 13, 21, 451, 292, 6292069, 485, 4, 7, 0, 10, 2, 1, 1, 1, 4, 5, 191, 640, 40, 2856, 1626, 1828, 0, 18, 3, 3, 1, 0, 1, 1, 1, 1, 24, 53, 13, 10, 0, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "17", "slug": "coin-change", "id": 17, "title": "Coin Change", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/coin-change/", "examples": [{"input": "coins = [1,2,5], amount = 11", "output": "3", "explanation": "11 = 5 + 5 + 1"}, {"input": "coins = [2], amount = 3", "output": "-1", "explanation": "Amount 3 cannot be formed by any combination of [2], so -1 is returned."}], "hints": ["Unbounded knapsack DP: dp[a] = min over coins c (dp[a-c] + 1). Initialize dp[0]=0 and others to INF."], "statement": "An integer array `coins` enumerates available token face values, while an integer `amount` states a monetary total to assemble.\nSelect a multiset drawn from `coins` (reuse permitted) whose sum equals `amount`, employing as few tokens as possible.\nWhen no multiset reaches `amount`, report `-1`.\n\n**Constraints:**\n\n- 1 \u2264 coins.length \u2264 12\n- 1 \u2264 coins[i] \u2264 2^31 - 1\n- 0 \u2264 amount \u2264 10^4\n", "solution": "## Approach\n\nBottom-up DP where dp[i] is the minimum coins needed for amount i, iterating over each coin for each amount.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(amount * len(coins))\n- **Space Complexity:** O(amount)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def coinChange(self, coins: List[int], amount: int) -> int:\n dp = [float('inf')] * (amount + 1)\n dp[0] = 0\n for i in range(1, amount + 1):\n for c in coins:\n if i >= c:\n dp[i] = min(dp[i], dp[i - c] + 1)\n return dp[amount] if dp[amount] != float('inf') else -1\n```\n", "starter": {"go": "package main\n\nfunc CoinChange(coins []int, amount int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def coinChange(self, coins: List[int], amount: int) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n return -1;\n }\n};"}, "fn": "coinChange", "params": [{"name": "coins", "type": "int_array"}, {"name": "amount", "type": "int"}], "outputType": "int", "tests": [["[1,2,5]", "11"], ["[2]", "3"], ["[1]", "0"], ["[2,5,10,1]", "27"], ["[1,3,4]", "9999"], ["[1,2,5]", "0"], ["[1,2,5]", "1"], ["[1,2,5]", "2"], ["[1,2,5]", "6"], ["[1]", "1"], ["[1]", "5"], ["[2]", "4"], ["[2]", "1"], ["[3,7]", "11"], ["[3,7]", "5"], ["[5,10,25]", "30"], ["[5,10,25]", "35"], ["[5,10,25]", "3"], ["[1,3,4]", "6"], ["[1,3,4]", "7"], ["[2,3,5]", "11"], ["[2,3,5]", "1"], ["[10,25,50]", "100"], ["[10,25,50]", "65"], ["[7,13,29]", "100"], ["[1,5,10,25]", "63"], ["[1,5,10,25]", "100"], ["[4,5,6]", "11"], ["[4,5,6]", "7"], ["[186,419,83,408]", "6249"], ["[2,5,10]", "50"], ["[1,2,5,10,20,50,100]", "99"]], "expected": [3, -1, 0, 4, 2500, 0, 1, 1, 2, 1, 5, 2, -1, -1, -1, 2, 2, -1, 2, 2, 3, -1, 2, 5, 4, 6, 4, 2, -1, 20, 5, 6], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "676", "slug": "coin-path", "id": 676, "title": "Coin Path", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/coin-path/", "examples": [{"input": "coins = [1,2,4,-1,2], maxJump = 2", "output": "[1,3,5]", "explanation": "Hop 1 -> 3 -> 5 with total 1+4+2 = 7, the cheapest reachable route; jumps never exceed 2."}, {"input": "coins = [1,2,4,-1,2], maxJump = 1", "output": "[]", "explanation": "The blocked cell at index 4 cannot be skipped with steps of 1, so the end is unreachable."}, {"input": "coins = [1,-1,2], maxJump = 2", "output": "[1,3]", "explanation": "Jump directly over the blocked middle cell."}], "hints": ["Work backwards: the best cost from i is coins[i] plus the best reachable cost within i+1..i+maxJump.", "Blocked cells (-1) are never landable; the destination must also be landable.", "On cost ties keep the lexicographically smaller full path, comparing suffixes element by element."], "statement": "You are given an array `coins` where `coins[i]` is the price of standing on cell `i+1` (cells are numbered from 1). A value of `-1` means the cell is blocked and can never be used.\n\nStart on cell 1 paying `coins[0]`. From cell `i` you may jump forward between 1 and `maxJump` cells. Each visited cell adds its price. Reach cell `n` (the last cell) as cheaply as possible.\n\nReturn the visited cell numbers in order, from 1 to `n`. When several cheapest routes exist, return the lexicographically smallest list. When the last cell cannot be reached, return an empty list.\n\n**Constraints:**\n- `1 <= coins.length <= 1000`\n- `-1 <= coins[i] <= 100`\n- `1 <= maxJump <= 100`\n", "solution": "## Approach\n\nProcess cells from right to left. The cheapest price from `i` equals `coins[i]` plus the best price among the next `maxJump` landable cells. Blocked cells stay unreachable. When two successors tie, compare the full paths starting at each successor and keep the lexicographically smaller one. Finally walk the successor links from cell 0.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * maxJump + n^2) with lexicographic tie checks.\n- **Space Complexity:** O(n) for costs and successor links.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def cheapestJump(self, coins: List[int], maxJump: int) -> List[int]:\n n = len(coins)\n if n == 0 or coins[0] == -1 or coins[-1] == -1:\n return []\n INF = 10 ** 18\n dp = [INF] * n\n nxt = [-1] * n\n dp[n - 1] = coins[n - 1]\n def path_from(s):\n p = []\n while s != -1:\n p.append(s)\n if s == n - 1:\n break\n s = nxt[s]\n return p\n for i in range(n - 2, -1, -1):\n if coins[i] == -1:\n continue\n for j in range(i + 1, min(n, i + maxJump + 1)):\n if coins[j] == -1 or dp[j] == INF:\n continue\n cand = coins[i] + dp[j]\n if cand < dp[i]:\n dp[i] = cand\n nxt[i] = j\n elif cand == dp[i]:\n if path_from(j) < path_from(nxt[i]):\n nxt[i] = j\n if dp[0] == INF:\n return []\n return [x + 1 for x in path_from(0)]\n```\n", "starter": {"go": "package main\n\nfunc CheapestJump(coins []int, maxJump int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def cheapestJump(self, coins: List[int], maxJump: int) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> cheapestJump(vector<int>& coins, int maxJump) {\n return {};\n }\n};"}, "fn": "cheapestJump", "params": [{"name": "coins", "type": "int_array"}, {"name": "maxJump", "type": "int"}], "outputType": "int_list", "tests": [["[1,2,4,-1,2]", "2"], ["[1,2,4,-1,2]", "1"], ["[0,0,0,0,0]", "2"], ["[1]", "1"], ["[1,-1]", "1"], ["[-1,1,1]", "2"], ["[1,2,3]", "2"], ["[1,100,1,1,1,100,1,1,100,1]", "2"], ["[1,2,4,-1,2]", "3"], ["[0,0,-1,0,0]", "2"], ["[5,4,3,2,1]", "4"], ["[1,1,1,1,1]", "1"], ["[2,-1,0,-1,3]", "2"], ["[0,-1,-1,0]", "2"], ["[3,2,1]", "1"], ["[1,2,3,4,5]", "5"], ["[4,3,2,1,0]", "2"], ["[1,-1,1,-1,1]", "2"], ["[2,1,-1,1,2]", "2"], ["[0,1,2,3,4,5]", "3"], ["[1,0,1,0,1,0,1]", "2"], ["[10,-1,10,-1,10]", "2"], ["[1,2,-1,2,-1,2,1]", "3"], ["[5]", "5"], ["[0,0,0,-1,0,0,0]", "3"], ["[1,3,2,4,6,5]", "2"], ["[2,2,2,2,2]", "3"], ["[1,-1,-1,1]", "2"]], "expected": [[1, 3, 5], [], [1, 2, 3, 4, 5], [1], [], [], [1, 3], [1, 3, 5, 7, 8, 10], [1, 2, 5], [1, 2, 4, 5], [1, 5], [1, 2, 3, 4, 5], [1, 3, 5], [], [1, 2, 3], [1, 5], [1, 3, 5], [1, 3, 5], [1, 2, 4, 5], [1, 3, 6], [1, 2, 4, 6, 7], [1, 3, 5], [1, 4, 7], [1], [1, 2, 3, 5, 6, 7], [1, 3, 4, 6], [1, 2, 5], []], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "109", "slug": "combination-sum-ii", "id": 109, "title": "Combination Sum II", "difficulty": "Medium", "category": "backtracking", "link": "https://leetcode.com/problems/combination-sum-ii/", "examples": [{"input": "candidates = [10,1,2,7,6,1,5], target = 8", "output": "[[1,1,6],[1,2,5],[1,7],[2,6]]", "explanation": "All unique combinations from [10, 1, 2, 7, 6, 1, 5] summing to 8 are [[1,1,6],[1,2,5],[1,7],[2,6]]."}, {"input": "candidates = [2,5,2,1,2], target = 5", "output": "[[1,2,2],[5]]", "explanation": "Each array position can be used once, and duplicate combinations are removed."}], "hints": ["Sort the candidates before backtracking.", "After choosing position i, recurse from i + 1 so that input element cannot be reused.", "At one recursion depth, skip a value when it equals the previous candidate considered at that same depth."], "statement": "Given an array of positive integers `candidates` and a positive integer `target`, return all unique combinations whose values sum to `target`.\n\nEach input element may be used at most once. The input may contain duplicate values, but the output must not contain duplicate combinations. The judge canonicalizes each combination and the outer result, so values and combinations may be returned in any order.\n\n**Constraints:**\n\n- `1 <= candidates.length <= 100`\n- `1 <= candidates[i] <= 50`\n- `1 <= target <= 30`\n", "solution": "## Approach\n\nSort the candidates and backtrack from left to right, advancing to `i + 1` after each choice so every input position is used at most once. At each recursion depth, skip equal values after the first to prevent duplicate combinations, and stop when the next value exceeds the remaining target.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n + S + R * L), where `S` is the number of visited backtracking states, `R` is the number of returned combinations, and `L` is their maximum length; `S` is at most O(2^n).\n- **Space Complexity:** O(n + R * L) for the recursion path, sorted candidates, and output.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:\n candidates = sorted(candidates)\n result: List[List[int]] = []\n current: List[int] = []\n\n def search(start: int, remaining: int) -> None:\n if remaining == 0:\n result.append(current[:])\n return\n for i in range(start, len(candidates)):\n if i > start and candidates[i] == candidates[i - 1]:\n continue\n value = candidates[i]\n if value > remaining:\n break\n current.append(value)\n search(i + 1, remaining - value)\n current.pop()\n\n search(0, target)\n return result\n```\n", "starter": {"go": "package main\n\nfunc CombinationSum2(candidates []int, target int) [][]int {\n panic(\"TODO\")\n}", "python": "from typing import List\n\nclass Solution:\n def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:\n raise NotImplementedError\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {\n return {};\n }\n};"}, "fn": "combinationSum2", "params": [{"name": "candidates", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int_array_2d", "tests": [["[10,1,2,7,6,1,5]", "8"], ["[2,5,2,1,2]", "5"], ["[1,1,1,2,2]", "4"], ["[1]", "1"], ["[2]", "1"], ["[1,2,3]", "6"], ["[1,1,2,3]", "3"], ["[3,3,3,3]", "6"], ["[5,10,12,13,15,18]", "30"], ["[2,2,2,2,2]", "8"], ["[4,4,5,6]", "9"], ["[7,1,7,1,7]", "8"], ["[8,6,4,2]", "10"], ["[9,9,1,1,2,2]", "11"], ["[10,10,10]", "20"], ["[1,2,2,3,3,4]", "6"], ["[2,3,5,7,11]", "10"], ["[1,1,1,1,1]", "3"], ["[6,5,4,3,2,1]", "7"], ["[2,4,6,8,10]", "12"], ["[3,3,6,6,9]", "12"], ["[1,4,4,4,5]", "9"], ["[2,2,3,3,4,4]", "8"], ["[11,12,13]", "10"], ["[1,5,5,10,10]", "15"], ["[7,7,14,14]", "21"], ["[2,6,2,6,2,6]", "14"], ["[8,1,8,1,8,1]", "17"], ["[3,4,5,6,7]", "15"], ["[1,2,3,4,5,6]", "10"], ["[10,2,10,2,10,2]", "12"], ["[5,5,5,5,5,5]", "25"], ["[1,3,3,5,5,7,7]", "11"], ["[2,4,4,8,8,16]", "16"], ["[9,1,9,1,9,1]", "19"], ["[6,6,6,7,7,7]", "20"], ["[2,3,3,5,5,8]", "13"], ["[4,4,4,6,6,10]", "14"], ["[1,2,2,2,5,5,10]", "12"], ["[3,3,3,9,9,12]", "18"], ["[7,2,5,2,7,5]", "14"], ["[1,6,6,11,11,16]", "17"], ["[2,7,7,12,12,17]", "19"], ["[3,8,8,13,13,18]", "21"], ["[4,9,9,14,14,19]", "23"], ["[5,10,10,15,15,20]", "25"], ["[1,1,2,2,3,3,4,4]", "8"], ["[2,2,4,4,6,6,8,8]", "16"], ["[3,3,5,5,7,7,9,9]", "18"], ["[1,2,2,3,5,5,8,13]", "13"], ["[50]", "30"], ["@javascript:JSON.stringify([30,...Array(99).fill(50)])", "30"]], "expected": [[[1, 1, 6], [1, 2, 5], [1, 7], [2, 6]], [[1, 2, 2], [5]], [[1, 1, 2], [2, 2]], [[1]], [], [[1, 2, 3]], [[1, 2], [3]], [[3, 3]], [[5, 10, 15], [5, 12, 13], [12, 18]], [[2, 2, 2, 2]], [[4, 5]], [[1, 7]], [[2, 8], [4, 6]], [[1, 1, 9], [2, 9]], [[10, 10]], [[1, 2, 3], [2, 4], [3, 3]], [[2, 3, 5], [3, 7]], [[1, 1, 1]], [[1, 2, 4], [1, 6], [2, 5], [3, 4]], [[2, 4, 6], [2, 10], [4, 8]], [[3, 3, 6], [3, 9], [6, 6]], [[1, 4, 4], [4, 5]], [[2, 2, 4], [2, 3, 3], [4, 4]], [], [[5, 10]], [[7, 14]], [[2, 6, 6]], [[1, 8, 8]], [[3, 5, 7], [4, 5, 6]], [[1, 2, 3, 4], [1, 3, 6], [1, 4, 5], [2, 3, 5], [4, 6]], [[2, 10]], [[5, 5, 5, 5, 5]], [[1, 3, 7], [1, 5, 5], [3, 3, 5]], [[4, 4, 8], [8, 8], [16]], [[1, 9, 9]], [[6, 7, 7]], [[2, 3, 3, 5], [2, 3, 8], [3, 5, 5], [5, 8]], [[4, 4, 6], [4, 10]], [[1, 2, 2, 2, 5], [2, 5, 5], [2, 10]], [[3, 3, 3, 9], [3, 3, 12], [9, 9]], [[2, 2, 5, 5], [2, 5, 7], [7, 7]], [[1, 16], [6, 11]], [[2, 17], [7, 12]], [[3, 18], [8, 13]], [[4, 19], [9, 14]], [[5, 10, 10], [5, 20], [10, 15]], [[1, 1, 2, 4], [1, 1, 3, 3], [1, 2, 2, 3], [1, 3, 4], [2, 2, 4], [2, 3, 3], [4, 4]], [[2, 2, 4, 8], [2, 2, 6, 6], [2, 4, 4, 6], [2, 6, 8], [4, 4, 8], [4, 6, 6], [8, 8]], [[3, 3, 5, 7], [9, 9]], [[1, 2, 2, 3, 5], [1, 2, 2, 8], [1, 2, 5, 5], [2, 3, 8], [3, 5, 5], [5, 8], [13]], [], [[30]]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "333", "slug": "combination-sum-iii", "id": 333, "title": "Combination Sum III", "difficulty": "Medium", "category": "backtracking", "link": "https://leetcode.com/problems/combination-sum-iii/", "examples": [{"explanation": "1 + 2 + 4 = 7 is the only valid triple.", "input": "k = 3, n = 7", "output": "[[1,2,4]]"}, {"explanation": "The three triples of distinct digits 1-9 summing to 9.", "input": "k = 3, n = 9", "output": "[[1,2,6],[1,3,5],[2,3,4]]"}, {"explanation": "The smallest sum of four distinct digits is 10, so nothing qualifies.", "input": "k = 4, n = 1", "output": "[]"}], "hints": ["Grow each candidate one digit at a time, only choosing digits larger than the last one to keep selections ordered.", "Abandon a branch once the running sum exceeds n or too few digits remain to reach size k.", "Record a copy of the current pick as soon as its size is k and its sum is n."], "statement": "From the digits 1 through 9, pick exactly `k` different digits whose values add up to `n`. Return every such selection; each selection is listed in increasing order and the order of the selections does not matter.\n\n**Constraints:**\n- `2 <= k <= 9`\n- `1 <= n <= 60`\n", "solution": "## Approach\n\nBacktrack over the digits 1 to 9, always extending the current pick with a larger digit so every combination is built in increasing order exactly once. Cut a branch when the running sum already exceeds `n` or when fewer digits remain than needed. When the pick holds `k` digits summing to `n`, store a copy of it.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(C(9, k)), bounded by the number of k-subsets of nine digits.\n- **Space Complexity:** O(k) for the recursion stack plus the output.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def combinationSum3(self, k: int, n: int) -> List[List[int]]:\n res: List[List[int]] = []\n\n def build(start: int, total: int, cur: List[int]) -> None:\n if len(cur) == k:\n if total == n:\n res.append(list(cur))\n return\n for d in range(start, 10):\n if total + d > n:\n break\n cur.append(d)\n build(d + 1, total + d, cur)\n cur.pop()\n\n build(1, 0, [])\n return res\n```\n", "starter": {"go": "package main\n\nfunc CombinationSum3(k int, n int) [][]int {\n return [][]int{}\n}", "python": "from typing import List\nclass Solution:\n def combinationSum3(self, k: int, n: int) -> List[List[int]]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> combinationSum3(int k, int n) {\n return {};\n }\n};"}, "fn": "combinationSum3", "params": [{"name": "k", "type": "int"}, {"name": "n", "type": "int"}], "outputType": "int_list_2d", "tests": [["3", "7"], ["3", "9"], ["4", "1"], ["2", "3"], ["2", "17"], ["2", "18"], ["3", "6"], ["3", "8"], ["3", "10"], ["3", "15"], ["3", "24"], ["4", "10"], ["4", "15"], ["4", "24"], ["4", "30"], ["5", "15"], ["5", "25"], ["5", "35"], ["6", "21"], ["6", "30"], ["7", "28"], ["7", "35"], ["8", "36"], ["8", "44"], ["9", "45"], ["9", "44"], ["2", "5"], ["9", "46"]], "expected": [[[1, 2, 4]], [[1, 2, 6], [1, 3, 5], [2, 3, 4]], [], [[1, 2]], [[8, 9]], [], [[1, 2, 3]], [[1, 2, 5], [1, 3, 4]], [[1, 2, 7], [1, 3, 6], [1, 4, 5], [2, 3, 5]], [[1, 5, 9], [1, 6, 8], [2, 4, 9], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6]], [[7, 8, 9]], [[1, 2, 3, 4]], [[1, 2, 3, 9], [1, 2, 4, 8], [1, 2, 5, 7], [1, 3, 4, 7], [1, 3, 5, 6], [2, 3, 4, 6]], [[1, 6, 8, 9], [2, 5, 8, 9], [2, 6, 7, 9], [3, 4, 8, 9], [3, 5, 7, 9], [3, 6, 7, 8], [4, 5, 6, 9], [4, 5, 7, 8]], [[6, 7, 8, 9]], [[1, 2, 3, 4, 5]], [[1, 2, 5, 8, 9], [1, 2, 6, 7, 9], [1, 3, 4, 8, 9], [1, 3, 5, 7, 9], [1, 3, 6, 7, 8], [1, 4, 5, 6, 9], [1, 4, 5, 7, 8], [2, 3, 4, 7, 9], [2, 3, 5, 6, 9], [2, 3, 5, 7, 8], [2, 4, 5, 6, 8], [3, 4, 5, 6, 7]], [[5, 6, 7, 8, 9]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 7, 8, 9], [1, 2, 4, 6, 8, 9], [1, 2, 5, 6, 7, 9], [1, 3, 4, 5, 8, 9], [1, 3, 4, 6, 7, 9], [1, 3, 5, 6, 7, 8], [2, 3, 4, 5, 7, 9], [2, 3, 4, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7]], [[1, 2, 3, 5, 7, 8, 9], [1, 2, 4, 5, 6, 8, 9], [1, 3, 4, 5, 6, 7, 9], [2, 3, 4, 5, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7, 8]], [[2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [], [[1, 4], [2, 3]], []], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "21", "slug": "combination-sum-iv", "id": 21, "title": "Combination Sum IV", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/combination-sum-iv/", "examples": [{"input": "nums=[1,2,3], target=4", "output": "7", "explanation": "The number of ways to form 4 is 7."}], "hints": ["DP over target values: dp[t] = sum(dp[t - x]) for all x in nums with t-x >= 0."], "statement": "Supplied with an array `nums` of pairwise different integers and an integer goal `target`, enumerate every ordered chain whose entries sum to `target`, then report that tally reduced modulo 10^9+7.\nTwo chains sharing an identical multiset but arranged differently contribute separately.\n\n**Constraints:**\n\n- 1 \u2264 nums.length \u2264 200\n- 1 \u2264 nums[i] \u2264 1000\n- All the elements of nums are unique.\n- 1 \u2264 target \u2264 1000\n", "solution": "## Approach\n\nBottom-up DP where dp[i] counts the number of combinations summing to i, considering each number as the last element added. Use modulo 1e9+7 to handle large results.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(target * len(nums))\n- **Space Complexity:** O(target)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def combinationSum4(self, nums: List[int], target: int) -> int:\n dp = [0] * (target + 1)\n dp[0] = 1\n MOD = 1000000007\n for i in range(1, target + 1):\n for n in nums:\n if i >= n:\n dp[i] = (dp[i] + dp[i - n]) % MOD\n return dp[target]\n```\n", "starter": {"go": "package main\n\nfunc CombinationSum4(nums []int, target int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def combinationSum4(self, nums: List[int], target: int) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int combinationSum4(vector<int>& nums, int target) {\n return 0;\n }\n};"}, "fn": "combinationSum4", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[1,2,3]", "4"], ["[9]", "3"], ["[1]", "5"], ["[3]", "5"], ["[2]", "4"], ["[1,2]", "5"], ["[3,5]", "7"], ["[1,2,5]", "5"], ["[10,20,30]", "50"], ["[1,2,3]", "10"], ["[1,5,10]", "6"], ["[1,2,3,4]", "100"], ["[1,2,3,4]", "1000"], ["[1,2,3]", "1"], ["[1,2,3]", "2"], ["[1,2,3]", "3"], ["[2,3,5]", "8"], ["[1,2]", "3"], ["[1,2]", "10"], ["[4,5,6]", "12"], ["[3,4,5]", "9"], ["[1,3,5]", "8"], ["[2,4,6]", "7"], ["[1,2,3,4]", "5"], ["[1,2,3,4]", "8"], ["[5,10,15]", "20"], ["[2,3]", "7"], ["[1,4,5]", "9"], ["[7,3]", "11"], ["[1,2,5]", "10"], ["[3,5,7]", "12"], ["[1]", "1"], ["[2]", "6"]], "expected": [7, 0, 1, 0, 1, 8, 0, 9, 13, 274, 3, 500369454, 449856021, 1, 2, 4, 6, 3, 89, 2, 3, 19, 0, 15, 108, 7, 3, 17, 0, 128, 3, 1, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "108", "slug": "combination-sum", "id": 108, "title": "Combination Sum", "difficulty": "Medium", "category": "backtracking", "link": "https://leetcode.com/problems/combination-sum/", "examples": [{"input": "candidates = [2,3,6,7], target = 7", "output": "[[2,2,3],[7]]", "explanation": "All combinations from [2, 3, 6, 7] that sum to 7 are [[2,2,3],[7]]."}, {"input": "candidates = [2,3,5], target = 8", "output": "[[2,2,2,2],[2,3,3],[3,5]]", "explanation": "Candidates may be reused any number of times."}], "hints": ["Sort the candidates so a branch can stop once the next value exceeds the remaining target.", "Backtrack with a start index to avoid generating permutations of the same combination.", "When choosing a candidate, recurse with the same index because that value may be reused."], "statement": "Given an array of distinct positive integers `candidates` and a positive integer `target`, return all unique combinations whose values sum to `target`.\n\nYou may use each candidate an unlimited number of times. Two combinations are different if the frequency of at least one chosen value differs. The judge canonicalizes each combination and the outer result, so values and combinations may be returned in any order. Duplicate combinations are not allowed.\n\n**Constraints:**\n\n- `1 <= candidates.length <= 30`\n- `2 <= candidates[i] <= 40`\n- All values in `candidates` are distinct.\n- `1 <= target <= 40`\n", "solution": "## Approach\n\nSort the candidates so a branch can stop as soon as the next value exceeds the remaining target. Backtrack with a nondecreasing start index, and recurse from the same index after a choice so that each candidate may be reused without generating permutations of one combination.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n + S + R * L), where `S` is the number of backtracking states, `R` is the number of returned combinations, and `L` is their maximum length.\n- **Space Complexity:** O(n + L + R * L) for the sorted candidates, recursion path, and output.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:\n candidates = sorted(candidates)\n result: List[List[int]] = []\n current: List[int] = []\n\n def search(start: int, remaining: int) -> None:\n if remaining == 0:\n result.append(current[:])\n return\n for i in range(start, len(candidates)):\n value = candidates[i]\n if value > remaining:\n break\n current.append(value)\n search(i, remaining - value)\n current.pop()\n\n search(0, target)\n return result\n```\n", "starter": {"go": "package main\n\nfunc CombinationSum(candidates []int, target int) [][]int {\n panic(\"TODO\")\n}", "python": "from typing import List\n\nclass Solution:\n def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:\n raise NotImplementedError\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> combinationSum(vector<int>& candidates, int target) {\n return {};\n }\n};"}, "fn": "combinationSum", "params": [{"name": "candidates", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int_array_2d", "tests": [["[2,3,6,7]", "7"], ["[2,3,5]", "8"], ["[2,4]", "7"], ["[2,3]", "1"], ["[2]", "4"], ["[3,5]", "15"], ["[4,6,8]", "12"], ["[7,3,2]", "18"], ["[5,10]", "20"], ["[6,9,12]", "18"], ["[2,7,11]", "14"], ["[8,3,4]", "11"], ["[9,10]", "8"], ["[2,5,10]", "10"], ["[2,5,9]", "19"], ["[3,4,7]", "21"], ["[6,7]", "13"], ["[2,8,10]", "16"], ["[5,7,9]", "23"], ["[4,5,6]", "8"], ["[11,13]", "26"], ["[2,3,7]", "12"], ["[2,3,4]", "6"], ["[7,14,21]", "28"], ["[10,20,30]", "40"], ["[2,15,20]", "30"], ["[3,8,13]", "24"], ["[4,9,14]", "27"], ["[5,6,13]", "17"], ["[2,4,6,8]", "10"], ["[3,6,9,12]", "18"], ["[2,7,8]", "15"], ["[5,11,17]", "22"], ["[6,10,15]", "30"], ["[2,9,16]", "25"], ["[4,7,10]", "18"], ["[3,11,20]", "33"], ["[8,12,20]", "32"], ["[7,9,10]", "27"], ["[2,13,17]", "39"], ["[5,8,12]", "36"], ["[2,9,10]", "20"], ["[6,14,22]", "28"], ["[3,5,16]", "31"], ["[4,11,18]", "33"], ["[2,5,7,10]", "14"], ["[3,4,8,12]", "16"], ["[5,9,13,17]", "26"], ["[6,7,8,9]", "24"], ["[2,3,5,7,11]", "40"], ["[2,40]", "1"], ["[39,40]", "40"], ["@javascript:JSON.stringify(Array.from({length:30},(_,i)=>i+2))", "1"]], "expected": [[[2, 2, 3], [7]], [[2, 2, 2, 2], [2, 3, 3], [3, 5]], [], [], [[2, 2]], [[3, 3, 3, 3, 3], [5, 5, 5]], [[4, 4, 4], [4, 8], [6, 6]], [[2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 3, 3], [2, 2, 2, 2, 3, 7], [2, 2, 2, 3, 3, 3, 3], [2, 2, 7, 7], [2, 3, 3, 3, 7], [3, 3, 3, 3, 3, 3]], [[5, 5, 5, 5], [5, 5, 10], [10, 10]], [[6, 6, 6], [6, 12], [9, 9]], [[2, 2, 2, 2, 2, 2, 2], [7, 7]], [[3, 4, 4], [3, 8]], [], [[2, 2, 2, 2, 2], [5, 5], [10]], [[2, 2, 2, 2, 2, 2, 2, 5], [2, 2, 2, 2, 2, 9], [2, 2, 5, 5, 5], [5, 5, 9]], [[3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 4, 4, 4], [3, 3, 4, 4, 7], [3, 4, 7, 7], [7, 7, 7]], [[6, 7]], [[2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 8], [2, 2, 2, 10], [8, 8]], [[5, 9, 9], [7, 7, 9]], [[4, 4]], [[13, 13]], [[2, 2, 2, 2, 2, 2], [2, 2, 2, 3, 3], [2, 3, 7], [3, 3, 3, 3]], [[2, 2, 2], [2, 4], [3, 3]], [[7, 7, 7, 7], [7, 7, 14], [7, 21], [14, 14]], [[10, 10, 10, 10], [10, 10, 20], [10, 30], [20, 20]], [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 20], [15, 15]], [[3, 3, 3, 3, 3, 3, 3, 3], [3, 8, 13], [8, 8, 8]], [[4, 9, 14], [9, 9, 9]], [[5, 6, 6]], [[2, 2, 2, 2, 2], [2, 2, 2, 4], [2, 2, 6], [2, 4, 4], [2, 8], [4, 6]], [[3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 6], [3, 3, 3, 9], [3, 3, 6, 6], [3, 3, 12], [3, 6, 9], [6, 6, 6], [6, 12], [9, 9]], [[2, 2, 2, 2, 7], [7, 8]], [[5, 17], [11, 11]], [[6, 6, 6, 6, 6], [10, 10, 10], [15, 15]], [[2, 2, 2, 2, 2, 2, 2, 2, 9], [9, 16]], [[4, 4, 10], [4, 7, 7]], [[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [11, 11, 11]], [[8, 8, 8, 8], [8, 12, 12], [12, 20]], [[7, 10, 10], [9, 9, 9]], [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 13], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 17], [13, 13, 13]], [[5, 5, 5, 5, 8, 8], [8, 8, 8, 12], [12, 12, 12]], [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 10], [2, 9, 9], [10, 10]], [[6, 22], [14, 14]], [[3, 3, 3, 3, 3, 3, 3, 5, 5], [3, 3, 3, 3, 3, 16], [3, 3, 5, 5, 5, 5, 5], [5, 5, 5, 16]], [[4, 11, 18], [11, 11, 11]], [[2, 2, 2, 2, 2, 2, 2], [2, 2, 5, 5], [2, 2, 10], [2, 5, 7], [7, 7]], [[3, 3, 3, 3, 4], [4, 4, 4, 4], [4, 4, 8], [4, 12], [8, 8]], [[9, 17], [13, 13]], [[6, 6, 6, 6], [6, 9, 9], [7, 8, 9], [8, 8, 8]], [[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 11], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 5, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 11], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 5, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 5, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 11], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 11], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 7, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 5, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 5, 5], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 5, 11], [2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 7, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 7], [2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 11], [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3], [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 5, 7], [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 5, 5, 5], [2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 7, 11], [2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 5, 11], [2, 2, 2, 2, 2, 2, 2, 2, 3, 7, 7, 7], [2, 2, 2, 2, 2, 2, 2, 2, 5, 5, 7, 7], [2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 5], [2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 11], [2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 7, 7], [2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 5, 5, 7], [2, 2, 2, 2, 2, 2, 2, 3, 3, 5, 5, 5, 5], [2, 2, 2, 2, 2, 2, 2, 3, 5, 7, 11], [2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 11], [2, 2, 2, 2, 2, 2, 2, 5, 7, 7, 7], [2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 7], [2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 5, 5], [2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 5, 11], [2, 2, 2, 2, 2, 2, 3, 3, 3, 5, 7, 7], [2, 2, 2, 2, 2, 2, 3, 3, 5, 5, 5, 7], [2, 2, 2, 2, 2, 2, 3, 3, 11, 11], [2, 2, 2, 2, 2, 2, 3, 5, 5, 5, 5, 5], [2, 2, 2, 2, 2, 2, 3, 7, 7, 11], [2, 2, 2, 2, 2, 2, 5, 5, 7, 11], [2, 2, 2, 2, 2, 2, 7, 7, 7, 7], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 5, 7], [2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 5, 5, 5], [2, 2, 2, 2, 2, 3, 3, 3, 3, 7, 11], [2, 2, 2, 2, 2, 3, 3, 3, 5, 5, 11], [2, 2, 2, 2, 2, 3, 3, 3, 7, 7, 7], [2, 2, 2, 2, 2, 3, 3, 5, 5, 7, 7], [2, 2, 2, 2, 2, 3, 5, 5, 5, 5, 7], [2, 2, 2, 2, 2, 3, 5, 11, 11], [2, 2, 2, 2, 2, 5, 5, 5, 5, 5, 5], [2, 2, 2, 2, 2, 5, 7, 7, 11], [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5], [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 11], [2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 7, 7], [2, 2, 2, 2, 3, 3, 3, 3, 3, 5, 5, 7], [2, 2, 2, 2, 3, 3, 3, 3, 5, 5, 5, 5], [2, 2, 2, 2, 3, 3, 3, 5, 7, 11], [2, 2, 2, 2, 3, 3, 5, 5, 5, 11], [2, 2, 2, 2, 3, 3, 5, 7, 7, 7], [2, 2, 2, 2, 3, 5, 5, 5, 7, 7], [2, 2, 2, 2, 3, 7, 11, 11], [2, 2, 2, 2, 5, 5, 5, 5, 5, 7], [2, 2, 2, 2, 5, 5, 11, 11], [2, 2, 2, 2, 7, 7, 7, 11], [2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7], [2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5], [2, 2, 2, 3, 3, 3, 3, 3, 3, 5, 11], [2, 2, 2, 3, 3, 3, 3, 3, 5, 7, 7], [2, 2, 2, 3, 3, 3, 3, 5, 5, 5, 7], [2, 2, 2, 3, 3, 3, 3, 11, 11], [2, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5], [2, 2, 2, 3, 3, 3, 7, 7, 11], [2, 2, 2, 3, 3, 5, 5, 7, 11], [2, 2, 2, 3, 3, 7, 7, 7, 7], [2, 2, 2, 3, 5, 5, 5, 5, 11], [2, 2, 2, 3, 5, 5, 7, 7, 7], [2, 2, 2, 5, 5, 5, 5, 7, 7], [2, 2, 2, 5, 7, 11, 11], [2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], [2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 5, 7], [2, 2, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5], [2, 2, 3, 3, 3, 3, 3, 3, 7, 11], [2, 2, 3, 3, 3, 3, 3, 5, 5, 11], [2, 2, 3, 3, 3, 3, 3, 7, 7, 7], [2, 2, 3, 3, 3, 3, 5, 5, 7, 7], [2, 2, 3, 3, 3, 5, 5, 5, 5, 7], [2, 2, 3, 3, 3, 5, 11, 11], [2, 2, 3, 3, 5, 5, 5, 5, 5, 5], [2, 2, 3, 3, 5, 7, 7, 11], [2, 2, 3, 5, 5, 5, 7, 11], [2, 2, 3, 5, 7, 7, 7, 7], [2, 2, 3, 11, 11, 11], [2, 2, 5, 5, 5, 5, 5, 11], [2, 2, 5, 5, 5, 7, 7, 7], [2, 2, 7, 7, 11, 11], [2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5], [2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 11], [2, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7], [2, 3, 3, 3, 3, 3, 3, 3, 5, 5, 7], [2, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5], [2, 3, 3, 3, 3, 3, 5, 7, 11], [2, 3, 3, 3, 3, 5, 5, 5, 11], [2, 3, 3, 3, 3, 5, 7, 7, 7], [2, 3, 3, 3, 5, 5, 5, 7, 7], [2, 3, 3, 3, 7, 11, 11], [2, 3, 3, 5, 5, 5, 5, 5, 7], [2, 3, 3, 5, 5, 11, 11], [2, 3, 3, 7, 7, 7, 11], [2, 3, 5, 5, 5, 5, 5, 5, 5], [2, 3, 5, 5, 7, 7, 11], [2, 3, 7, 7, 7, 7, 7], [2, 5, 5, 5, 5, 7, 11], [2, 5, 5, 7, 7, 7, 7], [2, 5, 11, 11, 11], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7], [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5], [3, 3, 3, 3, 3, 3, 3, 3, 5, 11], [3, 3, 3, 3, 3, 3, 3, 5, 7, 7], [3, 3, 3, 3, 3, 3, 5, 5, 5, 7], [3, 3, 3, 3, 3, 3, 11, 11], [3, 3, 3, 3, 3, 5, 5, 5, 5, 5], [3, 3, 3, 3, 3, 7, 7, 11], [3, 3, 3, 3, 5, 5, 7, 11], [3, 3, 3, 3, 7, 7, 7, 7], [3, 3, 3, 5, 5, 5, 5, 11], [3, 3, 3, 5, 5, 7, 7, 7], [3, 3, 5, 5, 5, 5, 7, 7], [3, 3, 5, 7, 11, 11], [3, 5, 5, 5, 5, 5, 5, 7], [3, 5, 5, 5, 11, 11], [3, 5, 7, 7, 7, 11], [5, 5, 5, 5, 5, 5, 5, 5], [5, 5, 5, 7, 7, 11], [5, 7, 7, 7, 7, 7], [7, 11, 11, 11]], [], [[40]], []], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "208", "slug": "combinations", "id": 208, "title": "Combinations", "difficulty": "Medium", "category": "backtracking", "link": "https://leetcode.com/problems/combinations/", "examples": [{"input": "n = 4, k = 2", "output": "[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]", "explanation": "There are 4 choose 2 = 6 total combinations."}, {"input": "n = 1, k = 1", "output": "[[1]]", "explanation": "There is 1 choose 1 = 1 total combination."}], "hints": ["Build each combination one position at a time, always picking the next value from the values that come after the last chosen one.", "Stop a branch as soon as enough values have been picked (current size == k) or not enough values remain to reach k."], "statement": "Supplied with two integers `n` and `k`, assemble every `k`-element subset drawn from the interval `[1, n]`.\n\nThe collection may be emitted in whatever sequence is convenient.\n\n**Constraints:**\n\n- `1 <= n <= 20`\n- `1 <= k <= n`\n", "solution": "## Approach\n\nBacktracking. Build a combination one element at a time. At each step the next chosen value must be strictly greater than the last one chosen, which guarantees each combination is generated exactly once and in increasing order. Start the search from 1 and only consider candidates up to the point where enough values remain to fill the combination (`n - remaining + 1`). When `current` has size `k`, record a copy of it. Removing the last element after exploring a branch undoes the choice (backtracking).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(C(n, k) * k) \u2014 there are `n choose k` combinations, each costing O(k) to copy.\n- **Space Complexity:** O(k) for the recursion stack and current list, excluding the O(C(n, k) * k) output.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def combine(self, n: int, k: int) -> List[List[int]]:\n result: List[List[int]] = []\n current: List[int] = []\n\n def backtrack(start: int) -> None:\n if len(current) == k:\n result.append(current.copy())\n return\n remaining = k - len(current)\n for i in range(start, n - remaining + 2):\n current.append(i)\n backtrack(i + 1)\n current.pop()\n\n backtrack(1)\n return result\n```", "starter": {"go": "package main\n\nfunc Combine(n int, k int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def combine(self, n: int, k: int) -> List[List[int]]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> combine(int n, int k) {\n \n }\n};"}, "fn": "combine", "params": [{"name": "n", "type": "int"}, {"name": "k", "type": "int"}], "outputType": "int_list_2d", "tests": [["4", "2"], ["1", "1"], ["5", "3"], ["2", "1"], ["3", "2"], ["6", "6"], ["4", "4"], ["6", "1"], ["6", "5"], ["8", "2"], ["7", "3"], ["10", "4"], ["2", "2"], ["3", "1"], ["3", "3"], ["4", "1"], ["4", "3"], ["5", "1"], ["5", "2"], ["5", "4"], ["5", "5"], ["6", "2"], ["6", "3"], ["6", "4"], ["7", "1"], ["7", "2"], ["7", "7"], ["8", "1"], ["8", "3"], ["9", "1"], ["9", "2"], ["12", "2"]], "expected": [[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]], [[1]], [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5], [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5]], [[1], [2]], [[1, 2], [1, 3], [2, 3]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4]], [[1], [2], [3], [4], [5], [6]], [[1, 2, 3, 4, 5], [1, 2, 3, 4, 6], [1, 2, 3, 5, 6], [1, 2, 4, 5, 6], [1, 3, 4, 5, 6], [2, 3, 4, 5, 6]], [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]], [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 2, 7], [1, 3, 4], [1, 3, 5], [1, 3, 6], [1, 3, 7], [1, 4, 5], [1, 4, 6], [1, 4, 7], [1, 5, 6], [1, 5, 7], [1, 6, 7], [2, 3, 4], [2, 3, 5], [2, 3, 6], [2, 3, 7], [2, 4, 5], [2, 4, 6], [2, 4, 7], [2, 5, 6], [2, 5, 7], [2, 6, 7], [3, 4, 5], [3, 4, 6], [3, 4, 7], [3, 5, 6], [3, 5, 7], [3, 6, 7], [4, 5, 6], [4, 5, 7], [4, 6, 7], [5, 6, 7]], [[1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 3, 6], [1, 2, 3, 7], [1, 2, 3, 8], [1, 2, 3, 9], [1, 2, 3, 10], [1, 2, 4, 5], [1, 2, 4, 6], [1, 2, 4, 7], [1, 2, 4, 8], [1, 2, 4, 9], [1, 2, 4, 10], [1, 2, 5, 6], [1, 2, 5, 7], [1, 2, 5, 8], [1, 2, 5, 9], [1, 2, 5, 10], [1, 2, 6, 7], [1, 2, 6, 8], [1, 2, 6, 9], [1, 2, 6, 10], [1, 2, 7, 8], [1, 2, 7, 9], [1, 2, 7, 10], [1, 2, 8, 9], [1, 2, 8, 10], [1, 2, 9, 10], [1, 3, 4, 5], [1, 3, 4, 6], [1, 3, 4, 7], [1, 3, 4, 8], [1, 3, 4, 9], [1, 3, 4, 10], [1, 3, 5, 6], [1, 3, 5, 7], [1, 3, 5, 8], [1, 3, 5, 9], [1, 3, 5, 10], [1, 3, 6, 7], [1, 3, 6, 8], [1, 3, 6, 9], [1, 3, 6, 10], [1, 3, 7, 8], [1, 3, 7, 9], [1, 3, 7, 10], [1, 3, 8, 9], [1, 3, 8, 10], [1, 3, 9, 10], [1, 4, 5, 6], [1, 4, 5, 7], [1, 4, 5, 8], [1, 4, 5, 9], [1, 4, 5, 10], [1, 4, 6, 7], [1, 4, 6, 8], [1, 4, 6, 9], [1, 4, 6, 10], [1, 4, 7, 8], [1, 4, 7, 9], [1, 4, 7, 10], [1, 4, 8, 9], [1, 4, 8, 10], [1, 4, 9, 10], [1, 5, 6, 7], [1, 5, 6, 8], [1, 5, 6, 9], [1, 5, 6, 10], [1, 5, 7, 8], [1, 5, 7, 9], [1, 5, 7, 10], [1, 5, 8, 9], [1, 5, 8, 10], [1, 5, 9, 10], [1, 6, 7, 8], [1, 6, 7, 9], [1, 6, 7, 10], [1, 6, 8, 9], [1, 6, 8, 10], [1, 6, 9, 10], [1, 7, 8, 9], [1, 7, 8, 10], [1, 7, 9, 10], [1, 8, 9, 10], [2, 3, 4, 5], [2, 3, 4, 6], [2, 3, 4, 7], [2, 3, 4, 8], [2, 3, 4, 9], [2, 3, 4, 10], [2, 3, 5, 6], [2, 3, 5, 7], [2, 3, 5, 8], [2, 3, 5, 9], [2, 3, 5, 10], [2, 3, 6, 7], [2, 3, 6, 8], [2, 3, 6, 9], [2, 3, 6, 10], [2, 3, 7, 8], [2, 3, 7, 9], [2, 3, 7, 10], [2, 3, 8, 9], [2, 3, 8, 10], [2, 3, 9, 10], [2, 4, 5, 6], [2, 4, 5, 7], [2, 4, 5, 8], [2, 4, 5, 9], [2, 4, 5, 10], [2, 4, 6, 7], [2, 4, 6, 8], [2, 4, 6, 9], [2, 4, 6, 10], [2, 4, 7, 8], [2, 4, 7, 9], [2, 4, 7, 10], [2, 4, 8, 9], [2, 4, 8, 10], [2, 4, 9, 10], [2, 5, 6, 7], [2, 5, 6, 8], [2, 5, 6, 9], [2, 5, 6, 10], [2, 5, 7, 8], [2, 5, 7, 9], [2, 5, 7, 10], [2, 5, 8, 9], [2, 5, 8, 10], [2, 5, 9, 10], [2, 6, 7, 8], [2, 6, 7, 9], [2, 6, 7, 10], [2, 6, 8, 9], [2, 6, 8, 10], [2, 6, 9, 10], [2, 7, 8, 9], [2, 7, 8, 10], [2, 7, 9, 10], [2, 8, 9, 10], [3, 4, 5, 6], [3, 4, 5, 7], [3, 4, 5, 8], [3, 4, 5, 9], [3, 4, 5, 10], [3, 4, 6, 7], [3, 4, 6, 8], [3, 4, 6, 9], [3, 4, 6, 10], [3, 4, 7, 8], [3, 4, 7, 9], [3, 4, 7, 10], [3, 4, 8, 9], [3, 4, 8, 10], [3, 4, 9, 10], [3, 5, 6, 7], [3, 5, 6, 8], [3, 5, 6, 9], [3, 5, 6, 10], [3, 5, 7, 8], [3, 5, 7, 9], [3, 5, 7, 10], [3, 5, 8, 9], [3, 5, 8, 10], [3, 5, 9, 10], [3, 6, 7, 8], [3, 6, 7, 9], [3, 6, 7, 10], [3, 6, 8, 9], [3, 6, 8, 10], [3, 6, 9, 10], [3, 7, 8, 9], [3, 7, 8, 10], [3, 7, 9, 10], [3, 8, 9, 10], [4, 5, 6, 7], [4, 5, 6, 8], [4, 5, 6, 9], [4, 5, 6, 10], [4, 5, 7, 8], [4, 5, 7, 9], [4, 5, 7, 10], [4, 5, 8, 9], [4, 5, 8, 10], [4, 5, 9, 10], [4, 6, 7, 8], [4, 6, 7, 9], [4, 6, 7, 10], [4, 6, 8, 9], [4, 6, 8, 10], [4, 6, 9, 10], [4, 7, 8, 9], [4, 7, 8, 10], [4, 7, 9, 10], [4, 8, 9, 10], [5, 6, 7, 8], [5, 6, 7, 9], [5, 6, 7, 10], [5, 6, 8, 9], [5, 6, 8, 10], [5, 6, 9, 10], [5, 7, 8, 9], [5, 7, 8, 10], [5, 7, 9, 10], [5, 8, 9, 10], [6, 7, 8, 9], [6, 7, 8, 10], [6, 7, 9, 10], [6, 8, 9, 10], [7, 8, 9, 10]], [[1, 2]], [[1], [2], [3]], [[1, 2, 3]], [[1], [2], [3], [4]], [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]], [[1], [2], [3], [4], [5]], [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5]], [[1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 4, 5], [1, 3, 4, 5], [2, 3, 4, 5]], [[1, 2, 3, 4, 5]], [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6]], [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 3, 4], [1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [1, 5, 6], [2, 3, 4], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6], [2, 5, 6], [3, 4, 5], [3, 4, 6], [3, 5, 6], [4, 5, 6]], [[1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 3, 6], [1, 2, 4, 5], [1, 2, 4, 6], [1, 2, 5, 6], [1, 3, 4, 5], [1, 3, 4, 6], [1, 3, 5, 6], [1, 4, 5, 6], [2, 3, 4, 5], [2, 3, 4, 6], [2, 3, 5, 6], [2, 4, 5, 6], [3, 4, 5, 6]], [[1], [2], [3], [4], [5], [6], [7]], [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7]], [[1, 2, 3, 4, 5, 6, 7]], [[1], [2], [3], [4], [5], [6], [7], [8]], [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 6], [1, 2, 7], [1, 2, 8], [1, 3, 4], [1, 3, 5], [1, 3, 6], [1, 3, 7], [1, 3, 8], [1, 4, 5], [1, 4, 6], [1, 4, 7], [1, 4, 8], [1, 5, 6], [1, 5, 7], [1, 5, 8], [1, 6, 7], [1, 6, 8], [1, 7, 8], [2, 3, 4], [2, 3, 5], [2, 3, 6], [2, 3, 7], [2, 3, 8], [2, 4, 5], [2, 4, 6], [2, 4, 7], [2, 4, 8], [2, 5, 6], [2, 5, 7], [2, 5, 8], [2, 6, 7], [2, 6, 8], [2, 7, 8], [3, 4, 5], [3, 4, 6], [3, 4, 7], [3, 4, 8], [3, 5, 6], [3, 5, 7], [3, 5, 8], [3, 6, 7], [3, 6, 8], [3, 7, 8], [4, 5, 6], [4, 5, 7], [4, 5, 8], [4, 6, 7], [4, 6, 8], [4, 7, 8], [5, 6, 7], [5, 6, 8], [5, 7, 8], [6, 7, 8]], [[1], [2], [3], [4], [5], [6], [7], [8], [9]], [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]], [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12]]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "318", "slug": "compare-version-numbers", "id": 318, "title": "Compare Version Numbers", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/compare-version-numbers/", "examples": [{"explanation": "The first revisions match (1 == 1), but 2 is smaller than 10.", "input": "version1 = \"1.2\", version2 = \"1.10\"", "output": "-1"}, {"explanation": "Both revisions mean 1, so the versions are equal.", "input": "version1 = \"1.01\", version2 = \"1.001\"", "output": "0"}, {"explanation": "Missing revisions count as zero, so both versions match.", "input": "version1 = \"1.0\", version2 = \"1.0.0.0\"", "output": "0"}], "hints": ["Split each version on dots and compare revision by revision as integers.", "Treat a missing revision beyond the shorter version as zero."], "statement": "Version strings hold dot-separated revision numbers, such as `\"1.2\"` or `\"1.10\"`. Compare them from left to right as integers: leading zeros do not matter, and a missing revision counts as zero (so `\"1.0\"` equals `\"1.0.0.0\"`).\n\nReturn `1` when the first version is larger, `-1` when the second is larger, and `0` when they match.\n\n**Constraints:**\n- `1 <= version1.length, version2.length <= 200`\n- Versions contain digits and dots, never start or end with a dot, and never hold empty revisions.\n- Each revision fits in a 32-bit integer.\n", "solution": "## Approach\n\nSplit both versions on dots and walk the revisions pairwise, treating a missing revision as zero. Parse each piece as an integer so leading zeros vanish, then return the first non-equal comparison. When every pair matches, the versions are equal.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m + n), where m and n are the version string lengths.\n- **Space Complexity:** O(m + n) for the split pieces.\n\n## Implementation\n\n```python\nclass Solution:\n def compareVersion(self, version1: str, version2: str) -> int:\n a = version1.split(\".\")\n b = version2.split(\".\")\n n = max(len(a), len(b))\n for i in range(n):\n x = int(a[i]) if i < len(a) else 0\n y = int(b[i]) if i < len(b) else 0\n if x < y:\n return -1\n if x > y:\n return 1\n return 0\n```\n", "starter": {"go": "package main\n\nfunc CompareVersion(version1 string, version2 string) int {\n \n}", "python": "class Solution:\n def compareVersion(self, version1: str, version2: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int compareVersion(string version1, string version2) {\n return 0;\n }\n};"}, "fn": "compareVersion", "params": [{"name": "version1", "type": "string"}, {"name": "version2", "type": "string"}], "outputType": "int", "tests": [["1.2", "1.10"], ["1.01", "1.001"], ["1.0", "1.0.0.0"], ["2.0", "1.9"], ["1.0.1", "1"], ["1", "1.0.1"], ["0.1", "1.1"], ["1.0.0", "1"], ["7.5.2.4", "7.5.3"], ["1.2.3", "1.2.3"], ["10.0", "9.99"], ["1.00.00", "1.0"], ["3.1", "3.1.0.0.0"], ["0.0.1", "0.0.0"], ["1.2", "1.2.0.0.1"], ["4.08", "4.8.0"], ["1", "2"], ["2", "1"], ["1.10.2", "1.9.9"], ["0.9", "0.10"], ["1.0.0.1", "1.0.0.0"], ["100.1", "100.0.9"], ["1.01.1", "1.1.1"], ["2.1", "2.0.9"], ["0.0.0", "0"], ["5", "5.0.0"]], "expected": [-1, 0, 0, 1, 1, -1, -1, 0, -1, 0, 1, 0, 0, 1, -1, 0, -1, 1, 1, -1, 1, 1, 0, 1, 0, 0], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "906", "slug": "complete-binary-tree-inserter", "id": 906, "title": "Complete Binary Tree Inserter", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/complete-binary-tree-inserter/", "examples": [{"input": "root = [1,2], operations = [\"insert\",\"insert\",\"getRoot\"], values = [3,4,0]", "output": "[1,2,1]", "explanation": "Inserting 3 under parent 1 and 4 under parent 2 keeps the tree complete; getRoot reports 1."}, {"input": "root = [1], operations = [\"insert\",\"getRoot\",\"insert\"], values = [2,0,3]", "output": "[1,1,1]", "explanation": "Both insertions attach to the root, whose value stays 1."}, {"input": "root = [1,2,3,4,5,6], operations = [\"insert\",\"insert\",\"getRoot\"], values = [7,8,0]", "output": "[3,4,1]", "explanation": "Node 7 fills the right child of 3 and node 8 the left child of 4."}], "hints": ["A complete tree fills level by level, so insertions always target the earliest node (in level order) missing a child.", "Keep a queue of such candidate parents: use the head for each insert, drop it once both children exist, and append every new node.", "Adaptation note: the original class interaction is flattened here into one batch call over operation traces."], "statement": "You start with a complete binary tree (every level full except possibly the last, filled left to right), given as `root`.\n\nInstead of building the usual inserter class, implement `runCbtInserter(root, operations, values)`, which replays a trace: each entry of `operations` is `\"insert\"` or `\"getRoot\"`, with the aligned entry of `values` holding the value for `\"insert\"` (ignored for `\"getRoot\"`). For `\"insert\"`, add the new node so the tree stays complete and report the parent's value; for `\"getRoot\"`, report the current root's value. Return all reported values in order.\n\n**Constraints:**\n- The node count starts at `>= 1` and stays `<= 10^4`\n- Node values fit in a 32-bit signed integer\n- `1 <= operations.length <= 10^4`, each entry is `\"insert\"` or `\"getRoot\"`\n", "solution": "## Approach\n\nWalk the starting tree in level order and collect every node missing a child; the first of these is always the next insertion parent for a complete tree. Each insert attaches left first, retires the parent once it has both children, and enqueues the newcomer as a future parent. Recording parent values (and the root value on demand) replays the trace exactly.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + m) for the initial walk over n nodes plus O(1) per traced operation.\n- **Space Complexity:** O(n) for the candidate queue and the walk.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def runCbtInserter(self, root, operations: List[str], values: List[int]) -> List[int]:\n cand = deque()\n bfs = deque([root])\n while bfs:\n node = bfs.popleft()\n if node.left is None or node.right is None:\n cand.append(node)\n if node.left is not None:\n bfs.append(node.left)\n if node.right is not None:\n bfs.append(node.right)\n ans = []\n for op, v in zip(operations, values):\n if op == \"insert\":\n parent = cand[0]\n node = TreeNode(v)\n if parent.left is None:\n parent.left = node\n else:\n parent.right = node\n cand.popleft()\n cand.append(node)\n ans.append(parent.val)\n else:\n ans.append(root.val)\n return ans\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 RunCbtInserter(root *TreeNode, operations []string, values []int) []int {\n return []int{}\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\n\nclass Solution:\n def runCbtInserter(self, root, operations: List[str], values: List[int]) -> List[int]:\n return []\n", "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 <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runCbtInserter(TreeNode* root, vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runCbtInserter", "params": [{"name": "root", "type": "tree_node"}, {"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[1,2]", "[\"insert\", \"insert\", \"getRoot\"]", "[3,4,0]"], ["[1]", "[\"insert\", \"getRoot\", \"insert\"]", "[2,0,3]"], ["[1,2,3,4,5,6]", "[\"insert\", \"insert\", \"getRoot\"]", "[7,8,0]"], ["[4, 3, 1, 6, 7, 8, 2, 9, 5]", "[\"insert\", \"getRoot\", \"insert\", \"insert\"]", "[20, 20, 7, 20]"], ["[1]", "[\"insert\", \"insert\", \"getRoot\"]", "[7, 20, 7]"], ["[2, 1]", "[\"getRoot\", \"getRoot\", \"getRoot\", \"insert\"]", "[12, 7, 16, 4]"], ["[1, 2]", "[\"getRoot\", \"getRoot\", \"insert\", \"getRoot\", \"getRoot\"]", "[6, 5, 3, 11, 11]"], ["[1]", "[\"getRoot\", \"insert\", \"getRoot\"]", "[16, 4, 12]"], ["[2, 3, 6, 4, 5, 1]", "[\"insert\", \"getRoot\", \"insert\", \"insert\", \"insert\"]", "[19, 10, 4, 9, 15]"], ["[4, 5, 7, 6, 3, 2, 1]", "[\"insert\", \"getRoot\"]", "[19, 17]"], ["[3, 5, 1, 4, 2]", "[\"getRoot\", \"insert\", \"insert\", \"getRoot\", \"insert\"]", "[14, 13, 0, 13, 7]"], ["[1, 2]", "[\"getRoot\", \"getRoot\", \"insert\"]", "[9, 17, 0]"], ["[1]", "[\"insert\", \"getRoot\", \"insert\"]", "[20, 5, 6]"], ["[2, 1, 3]", "[\"insert\", \"getRoot\"]", "[14, 8]"], ["[1, 7, 5, 4, 6, 2, 3]", "[\"insert\"]", "[17]"], ["[5, 1, 2, 4, 3]", "[\"insert\", \"getRoot\", \"insert\"]", "[3, 0, 0]"], ["[4, 1, 2, 3]", "[\"getRoot\", \"getRoot\", \"getRoot\", \"getRoot\", \"insert\", \"getRoot\"]", "[10, 20, 3, 14, 20, 11]"], ["[1]", "[\"getRoot\", \"getRoot\", \"insert\", \"insert\", \"insert\"]", "[16, 2, 9, 0, 14]"], ["[1, 3, 2]", "[\"insert\", \"getRoot\", \"getRoot\", \"insert\", \"getRoot\"]", "[14, 3, 12, 4, 9]"], ["[2, 1, 3]", "[\"insert\"]", "[7]"], ["[1]", "[\"insert\"]", "[0]"], ["[2, 4, 1, 3]", "[\"insert\", \"getRoot\"]", "[13, 19]"], ["[6, 3, 5, 2, 1, 4]", "[\"insert\", \"getRoot\"]", "[14, 6]"], ["[1]", "[\"getRoot\", \"insert\", \"getRoot\", \"insert\", \"insert\"]", "[20, 4, 13, 10, 12]"], ["[4, 2, 3, 1, 5]", "[\"getRoot\", \"getRoot\", \"insert\", \"getRoot\", \"getRoot\"]", "[4, 7, 20, 5, 4]"], ["[3, 2, 5, 1, 4]", "[\"insert\", \"getRoot\", \"getRoot\"]", "[4, 19, 6]"], ["[2, 4, 3, 5, 1]", "[\"insert\"]", "[11]"], ["[2, 1]", "[\"getRoot\", \"getRoot\", \"insert\", \"getRoot\", \"getRoot\"]", "[11, 20, 19, 4, 10]"]], "expected": [[1, 2, 1], [1, 1, 1], [3, 4, 1], [7, 4, 7, 8], [1, 1, 1], [2, 2, 2, 2], [1, 1, 1, 1, 1], [1, 1, 1], [6, 2, 4, 4, 5], [6, 4], [3, 1, 1, 3, 4], [1, 1, 1], [1, 1, 1], [1, 2], [4], [2, 5, 2], [4, 4, 4, 4, 1, 4], [1, 1, 1, 1, 9], [3, 1, 1, 3, 1], [1], [1], [4, 2], [5, 6], [1, 1, 1, 1, 4], [4, 4, 3, 4, 4], [5, 3, 3], [3], [2, 2, 2, 2, 2]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "595", "slug": "complex-number-multiplication", "id": 595, "title": "Complex Number Multiplication", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/complex-number-multiplication/", "examples": [{"input": "num1 = \"1+1i\", num2 = \"1+1i\"", "output": "\"0+2i\"", "explanation": "(1+i) times (1+i) is 1 + 2i + i^2 = 0 + 2i."}, {"input": "num1 = \"1+-1i\", num2 = \"1+-1i\"", "output": "\"0+-2i\"", "explanation": "(1-i) times (1-i) is 1 - 2i + i^2 = 0 - 2i."}, {"input": "num1 = \"2+3i\", num2 = \"4+5i\"", "output": "\"-7+22i\"", "explanation": "Real part 2*4-3*5 = -7; imaginary part 2*5+3*4 = 22."}], "hints": ["Split each input at the '+' into real and imaginary text (dropping the trailing 'i'), then parse both as integers.", "Apply the product rule: real = a*c-b*d, imaginary = a*d+b*c.", "Format the answer with the same pattern, keeping the '+' separator even for negative parts."], "statement": "You are given two complex numbers written as strings in the form `real+imaginaryi`, where both parts are integers (either part may be negative, e.g. `1+-1i`). Multiply the two numbers and return the product in the same `a+bi` format.\n\nRecall that `i` squared equals `-1`, so `(a+bi) * (c+di)` equals `(a*c - b*d) + (a*d + b*c)i`.\n\n**Constraints:**\n- Each input matches `-?\\d+\\+-?\\d+i` (an integer, `+`, an integer, `i`).\n- `-100 <= real part, imaginary part <= 100`\n", "solution": "## Approach\n\nSplit each operand at the `+` separator: the text before it is the real part and the text after it (minus the trailing `i`) is the imaginary part. Parse both to integers, combine them with the complex product rule (real `a*c-b*d`, imaginary `a*d+b*c`), and format the result with the same `+` separator.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(L), where L is the input length, for splitting and parsing.\n- **Space Complexity:** O(L) for the intermediate strings.\n\n## Implementation\n\n```python\nclass Solution:\n def complexNumberMultiply(self, num1: str, num2: str) -> str:\n def parse(s):\n plus = s.index('+')\n return int(s[:plus]), int(s[plus+1:-1])\n a, b = parse(num1)\n c, d = parse(num2)\n return f\"{a*c-b*d}+{a*d+b*c}i\"\n```\n", "starter": {"go": "package main\n\nfunc ComplexNumberMultiply(num1 string, num2 string) string {\n \n}", "python": "class Solution:\n def complexNumberMultiply(self, num1: str, num2: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string complexNumberMultiply(string num1, string num2) {\n return \"\";\n }\n};"}, "fn": "complexNumberMultiply", "params": [{"name": "num1", "type": "string"}, {"name": "num2", "type": "string"}], "outputType": "string", "tests": [["1+1i", "1+1i"], ["1+-1i", "1+-1i"], ["2+3i", "4+5i"], ["0+0i", "5+5i"], ["1+0i", "0+1i"], ["0+1i", "0+1i"], ["3+2i", "1+7i"], ["-1+-1i", "-1+-1i"], ["-2+3i", "4+-5i"], ["10+10i", "10+10i"], ["1+2i", "3+4i"], ["5+0i", "0+5i"], ["7+7i", "0+0i"], ["-3+-4i", "3+4i"], ["100+100i", "100+100i"], ["2+0i", "3+0i"], ["0+2i", "0+3i"], ["6+-7i", "-8+9i"], ["1+1i", "2+0i"], ["9+4i", "9+4i"], ["-5+5i", "5+-5i"], ["11+2i", "3+8i"], ["0+-1i", "0+-1i"], ["13+0i", "0+13i"], ["-100+-100i", "100+-100i"], ["4+9i", "-4+-9i"], ["25+17i", "8+3i"], ["-1+0i", "-1+0i"]], "expected": ["0+2i", "0+-2i", "-7+22i", "0+0i", "0+1i", "-1+0i", "-11+23i", "0+2i", "7+22i", "0+200i", "-5+10i", "0+25i", "0+0i", "7+-24i", "0+20000i", "6+0i", "-6+0i", "15+110i", "2+2i", "65+72i", "0+50i", "17+94i", "-1+0i", "0+169i", "-20000+0i", "65+-72i", "149+211i", "1+0i"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "537", "slug": "concatenated-words", "id": 537, "title": "Concatenated Words", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/concatenated-words/", "examples": [{"input": "words = [\"cat\",\"cats\",\"catsdogcats\",\"dog\",\"dogcatsdog\",\"hippopotamuses\",\"rat\",\"ratcatdogcat\"]", "output": "[\"catsdogcats\",\"dogcatsdog\",\"ratcatdogcat\"]", "explanation": "\"catsdogcats\" is \"cats\"+\"dog\"+\"cats\"; \"dogcatsdog\" is \"dog\"+\"cats\"+\"dog\"; \"ratcatdogcat\" is \"rat\"+\"cat\"+\"dog\"+\"cat\"."}, {"input": "words = [\"cat\",\"dog\",\"catdog\"]", "output": "[\"catdog\"]", "explanation": "Only \"catdog\" breaks into listed pieces \"cat\" and \"dog\"."}, {"input": "words = [\"hello\",\"world\"]", "output": "[]", "explanation": "No word can be assembled from other entries."}], "hints": ["Sort words by length and only build from strictly shorter words seen so far.", "Each candidate is a word-break check against the shorter-word set.", "Compare outputs as sets: order does not matter."], "statement": "You are handed a list of different lowercase words with no repeats. A word from the list counts as *joined* when it can be built by gluing together at least two other entries from the same list, where each piece must be strictly shorter than the whole and pieces may be reused.\n\nReturn every joined word. The order of the returned words does not matter for grading.\n\n**Constraints:**\n\n- `1 <= words.length <= 10^4`\n- `1 <= words[i].length <= 30`\n- Each `words[i]` holds only lowercase English letters.\n- All entries in `words` are distinct.\n- The total of all word lengths is at most `10^5`.\n", "solution": "## Approach\n\nSort all words by length and scan length groups in order. Keep a set of every strictly shorter word seen so far. For each candidate, run a word-break dynamic program that asks whether the candidate splits into pieces from that set. Grouping equal lengths together guarantees no word ever uses itself or another word of the same length. Collect every candidate that splits successfully.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(T * L^2) where T is the number of words and L is the longest word length (each split check is quadratic in word length).\n- **Space Complexity:** O(S) for the dictionary set plus O(L) per DP check, where S is the total input size.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n ordered = sorted(words, key=len)\n seen = set()\n out = []\n i = 0\n while i < len(ordered):\n j = i\n while j < len(ordered) and len(ordered[j]) == len(ordered[i]):\n j += 1\n for k in range(i, j):\n w = ordered[k]\n if seen and self._can_form(w, seen):\n out.append(w)\n for k in range(i, j):\n seen.add(ordered[k])\n i = j\n return out\n\n def _can_form(self, s: str, vocab: set) -> bool:\n n = len(s)\n dp = [False] * (n + 1)\n dp[0] = True\n for end in range(1, n + 1):\n for start in range(end):\n if dp[start] and s[start:end] in vocab:\n dp[end] = True\n break\n return dp[n]\n```\n", "starter": {"go": "package main\n\nfunc FindAllConcatenatedWordsInADict(words []string) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:\n return []\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> findAllConcatenatedWordsInADict(vector<string>& words) {\n return {};\n }\n};"}, "fn": "findAllConcatenatedWordsInADict", "params": [{"name": "words", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"cat\",\"cats\",\"catsdogcats\",\"dog\",\"dogcatsdog\",\"hippopotamuses\",\"rat\",\"ratcatdogcat\"]"], ["[\"cat\",\"dog\",\"catdog\"]"], ["[\"hello\",\"world\"]"], ["[\"a\",\"b\",\"ab\",\"abc\",\"abcd\"]"], ["[\"a\"]"], ["[\"ab\",\"a\",\"b\"]"], ["[\"tech\",\"techtech\"]"], ["[\"a\",\"aa\",\"aaa\",\"aaaa\"]"], ["[\"cat\",\"cats\",\"dog\",\"catsdog\"]"], ["[\"x\",\"y\",\"z\"]"], ["[\"ab\",\"cd\",\"abcd\",\"cdab\",\"abab\"]"], ["[\"one\",\"two\",\"onetwo\",\"twotwo\",\"onetwotwo\"]"], ["[\"a\",\"b\",\"c\",\"abc\",\"bc\",\"ab\"]"], ["[\"red\",\"blue\",\"redblue\",\"bluered\",\"redbluered\"]"], ["[\"q\"]"], ["[\"aa\",\"bb\",\"aabb\",\"bbaa\",\"aabbaa\"]"], ["[\"go\",\"goal\",\"goals\",\"goalsgoals\"]"], ["[\"t\",\"te\",\"tes\",\"test\",\"testtest\"]"], ["[\"m\",\"n\",\"mn\",\"mnmn\",\"mnmnmn\"]"], ["[\"abc\",\"def\",\"abcdef\",\"defabc\",\"abcdefdef\"]"], ["[\"a\",\"aa\",\"ab\",\"aba\",\"abab\"]"], ["[\"word\",\"words\",\"wordsword\",\"sword\"]"], ["[\"p\",\"q\",\"pq\",\"pqq\",\"pqqp\"]"], ["[\"longwordhere\",\"long\",\"word\",\"here\",\"longword\",\"wordhere\"]"], ["[\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"]"], ["[\"hello\",\"hell\",\"o\",\"hellohello\"]"], ["[\"ab\",\"bc\",\"cd\",\"abcd\",\"bcd\"]"], ["[\"cat\",\"dog\",\"bird\",\"catdogbird\",\"dogbird\"]"]], "expected": [["dogcatsdog", "catsdogcats", "ratcatdogcat"], ["catdog"], [], ["ab"], [], ["ab"], ["techtech"], ["aa", "aaa", "aaaa"], ["catsdog"], [], ["abcd", "cdab", "abab"], ["onetwo", "twotwo", "onetwotwo"], ["bc", "ab", "abc"], ["redblue", "bluered", "redbluered"], [], ["aabb", "bbaa", "aabbaa"], ["goalsgoals"], ["test", "testtest"], ["mn", "mnmn", "mnmnmn"], ["abcdef", "defabc", "abcdefdef"], ["aa", "aba", "abab"], ["wordsword"], ["pq", "pqq", "pqqp"], ["longword", "wordhere", "longwordhere"], ["ab", "bc", "abc"], ["hello", "hellohello"], ["abcd"], ["dogbird", "catdogbird"]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "152", "slug": "concatenation-of-array", "id": 152, "title": "Concatenation of Array", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/concatenation-of-array/", "examples": [{"input": "nums = [1,2,1]", "output": "[1,2,1,1,2,1]", "explanation": "The array ans is formed as follows: ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]] = [1,2,1,1,2,1]."}, {"input": "nums = [1,3,2,1]", "output": "[1,3,2,1,1,3,2,1]", "explanation": "The array ans is formed as follows: ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]] = [1,3,2,1,1,3,2,1]."}], "hints": ["Build an array of size 2 * n and assign nums[i] to ans[i] and ans[i + n]."], "statement": "An integer array `nums` holding `n` entries is supplied.\nFabricate an array `ans` twice as long (`2n`), defined (using 0-based positions) by `ans[i] == nums[i]` together with `ans[i + n] == nums[i]` for each `0 <= i < n`.\n\nPut differently, `ans` places two successive copies of `nums` back to back.\n\nHand back `ans`.\n\n**Constraints:**\n\n- n == nums.length\n- 1 \u2264 n \u2264 1000\n- 1 \u2264 nums[i] \u2264 1000\n", "solution": "## Approach\n\nAllocate an answer array of length `2 * n`. Copy each element `nums[i]` to positions `i` and `i + n`. Equivalently, return `nums` concatenated with itself.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `nums`. Each element is copied twice.\n- **Space Complexity:** O(n) for the output array of length `2n` (excluding output, O(1) extra).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def getConcatenation(self, nums: List[int]) -> List[int]:\n n = len(nums)\n ans = [0] * (2 * n)\n for i, v in enumerate(nums):\n ans[i] = v\n ans[i + n] = v\n return ans\n```\n", "starter": {"go": "package main\n\nfunc GetConcatenation(nums []int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def getConcatenation(self, nums: List[int]) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> getConcatenation(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "getConcatenation", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_array", "tests": [["[1,2,1]"], ["[1,3,2,1]"], ["[1]"], ["[1,2]"], ["[1000]"], ["[1,1,1,1]"], ["[5,4,3,2,1]"], ["[1,1000,1,1000]"], ["[7,7,7,7,7,7]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[1000,999,998,997,996]"], ["@javascript:JSON.stringify(Array.from({length:1000},(_,i)=>(i%1000)+1))"], ["[2]"], ["[999]"], ["[42]"], ["[2,1]"], ["[3,3]"], ["[1,2,3]"], ["[3,2,1]"], ["[2,2,2]"], ["[10,20,30]"], ["[100,200,300,400]"], ["[9,8,7,6,5,4,3,2,1]"], ["[1,2,3,4,5]"], ["[5,5,4,4,3,3]"], ["[500,500]"], ["[1,1000]"], ["[1000,1]"], ["[8,6,7,5,3,1]"], ["[11,22,33,44,55,66,77]"], ["[2,4,6,8,10,12]"], ["[13,13,13]"]], "expected": [[1, 2, 1, 1, 2, 1], [1, 3, 2, 1, 1, 3, 2, 1], [1, 1], [1, 2, 1, 2], [1000, 1000], [1, 1, 1, 1, 1, 1, 1, 1], [5, 4, 3, 2, 1, 5, 4, 3, 2, 1], [1, 1000, 1, 1000, 1, 1000, 1, 1000], [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1000, 999, 998, 997, 996, 1000, 999, 998, 997, 996], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000], [2, 2], [999, 999], [42, 42], [2, 1, 2, 1], [3, 3, 3, 3], [1, 2, 3, 1, 2, 3], [3, 2, 1, 3, 2, 1], [2, 2, 2, 2, 2, 2], [10, 20, 30, 10, 20, 30], [100, 200, 300, 400, 100, 200, 300, 400], [9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 1, 2, 3, 4, 5], [5, 5, 4, 4, 3, 3, 5, 5, 4, 4, 3, 3], [500, 500, 500, 500], [1, 1000, 1, 1000], [1000, 1, 1000, 1], [8, 6, 7, 5, 3, 1, 8, 6, 7, 5, 3, 1], [11, 22, 33, 44, 55, 66, 77, 11, 22, 33, 44, 55, 66, 77], [2, 4, 6, 8, 10, 12, 2, 4, 6, 8, 10, 12], [13, 13, 13, 13, 13, 13]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "827", "slug": "consecutive-numbers-sum", "id": 827, "title": "Consecutive Numbers Sum", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/consecutive-numbers-sum/", "examples": [{"input": "n = 5", "output": "2", "explanation": "Writings are [5] and [2,3]."}, {"input": "n = 9", "output": "3", "explanation": "Writings are [9], [4,5], and [2,3,4]."}, {"input": "n = 15", "output": "4", "explanation": "Writings are [15], [7,8], [4,5,6], and [1,2,3,4,5]."}], "hints": ["A block of k consecutive numbers starting at x sums to k*x + k*(k-1)/2, so x must be a positive integer.", "For each possible length k, check whether n minus k*(k-1)/2 is a positive multiple of k.", "Only lengths with k*(k-1)/2 < n can work, which bounds the loop near sqrt(2n)."], "statement": "A positive integer `n` can be written as a sum of one or more consecutive positive integers in several ways (for example, `5 = 5 = 2 + 3`). Count how many such writings exist, where the single-term writing `n = n` always counts.\n\n**Constraints:**\n- `1 <= n <= 10^9`\n", "solution": "## Approach\n\nA run of k consecutive integers starting at x totals k*x + k*(k-1)/2, so for a fixed length k the value n - k*(k-1)/2 must be a positive multiple of k. Trying every length k with k*(k-1)/2 < n covers all feasible block sizes, and each passing k yields exactly one valid start. Counting those lengths gives the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(sqrt(n)) since k only ranges up to about sqrt(2n).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def consecutiveNumbersSum(self, n: int) -> int:\n ans = 0\n k = 1\n while k * (k - 1) // 2 < n:\n if (n - k * (k - 1) // 2) % k == 0:\n ans += 1\n k += 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc ConsecutiveNumbersSum(n int) int {\n return 0\n}", "python": "class Solution:\n def consecutiveNumbersSum(self, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int consecutiveNumbersSum(int n) {\n return 0;\n }\n};"}, "fn": "consecutiveNumbersSum", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["5"], ["9"], ["15"], ["1"], ["2"], ["3"], ["4"], ["6"], ["7"], ["8"], ["10"], ["12"], ["21"], ["28"], ["45"], ["100"], ["1000"], ["1000000"], ["1000000000"], ["999999999"], ["16"], ["32"], ["64"], ["1024"], ["99999"], ["123456"], ["123456789"], ["987654321"]], "expected": [2, 3, 4, 1, 1, 2, 1, 2, 2, 1, 2, 2, 4, 2, 6, 3, 4, 7, 10, 20, 1, 1, 1, 1, 12, 4, 12, 18], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "285", "slug": "construct-binary-tree-from-inorder-and-postorder-traversal", "id": 285, "title": "Construct Binary Tree from Inorder and Postorder Traversal", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/", "examples": [{"input": "inorder = [9,3,15,20,7], postorder = [9,15,7,20,3]", "output": "[3,9,20,null,null,15,7]", "explanation": "The last postorder entry (3) is the root; it splits inorder into left [9] and right [15,20,7], then recursion finishes both sides."}, {"input": "inorder = [-1], postorder = [-1]", "output": "[-1]", "explanation": "A single entry in both walks describes a lone node."}], "hints": ["The final entry of the postorder walk is always the current subtree root.", "Look that root value up in the inorder walk: everything left of it forms the left subtree, everything right forms the right subtree.", "Build the right subtree before the left one when consuming postorder from the end, using an index map for O(1) splits."], "statement": "Rebuild a binary tree when you are given its inorder and postorder visit orders.\n\nThe inorder walk lists each subtree as left, root, right. The postorder walk lists each subtree as left, right, root \u2014 so the last postorder entry is the overall root. Find that root value inside the inorder list: entries to its left belong to the left subtree and entries to its right belong to the right subtree. Apply the same reasoning recursively to each side.\n\nAll values are unique, and both lists describe the same tree. Return its root.\n\n**Constraints:**\n- `1 <= inorder.length <= 3000`\n- `postorder.length == inorder.length`\n- `-3000 <= inorder[i], postorder[i] <= 3000`\n- Both lists contain distinct values, and every postorder value appears in inorder.\n", "solution": "## Approach\n\nThe tail of the postorder list is the root. A hash map from value to inorder position splits the inorder range into left and right parts in constant time. Because postorder is consumed backwards (root, then right, then left), the recursion builds the right subtree first and then the left one, each step shrinking both ranges until they are empty.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) with the index map; each node is created once.\n- **Space Complexity:** O(n) for the map plus O(h) recursion depth.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def buildTree(self, inorder: List[int], postorder: List[int]):\n pos = {v: i for i, v in enumerate(inorder)}\n self.pi = len(postorder) - 1\n def helper(l, r):\n if l > r:\n return None\n rv = postorder[self.pi]\n self.pi -= 1\n root = TreeNode(rv)\n m = pos[rv]\n root.right = helper(m + 1, r)\n root.left = helper(l, m - 1)\n return root\n return helper(0, len(inorder) - 1)\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 BuildTree(inorder []int, postorder []int) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nfrom typing import List\nclass Solution:\n def buildTree(self, inorder: List[int], postorder: List[int]):\n pass\n", "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 TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) {\n \n }\n};"}, "fn": "buildTree", "params": [{"name": "inorder", "type": "int_array"}, {"name": "postorder", "type": "int_array"}], "outputType": "tree_node", "tests": [["[9,3,15,20,7]", "[9,15,7,20,3]"], ["[-1]", "[-1]"], ["[2,1,3]", "[2,3,1]"], ["[1,2,3]", "[1,3,2]"], ["[4,2,1,3]", "[4,2,3,1]"], ["[1,2,6,4,3,5,7]", "[1,6,2,3,7,5,4]"], ["[2,1]", "[2,1]"], ["[1,2]", "[1,2]"], ["[1,2,3]", "[3,2,1]"], ["[3,2,1]", "[1,2,3]"], ["[3,10,7,4,9,5,8,1,2,6]", "[3,7,10,9,5,4,1,6,2,8]"], ["[4,2,5,1,3]", "[4,5,2,3,1]"], ["[2,4,1,5,3]", "[2,1,4,3,5]"], ["[20,10,30]", "[20,30,10]"], ["[2,-1,5,-3,0]", "[2,5,-1,0,-3]"], ["[1,3,5,7,9]", "[1,5,3,9,7]"], ["[3,4,2,1]", "[3,4,1,2]"], ["[1,2,4,6,3,8]", "[1,4,2,3,8,6]"], ["[3,1,2]", "[3,2,1]"], ["[20,10,25,5,15]", "[20,25,10,15,5]"], ["[400,200,100,300]", "[400,200,300,100]"], ["[44,22,55,11,66,33]", "[44,55,22,66,33,11]"], ["[0]", "[0]"], ["[4,2,5,1,6,3,7]", "[4,5,2,6,7,3,1]"], ["[10,7,12,3,8]", "[10,12,7,8,3]"], ["[1,3,4,5,7,8,9]", "[1,4,3,7,9,8,5]"], ["[3,1,5,2,4]", "[3,5,1,4,2]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "67", "slug": "construct-binary-tree-from-preorder-and-inorder-traversal", "id": 67, "title": "Construct Binary Tree from Preorder and Inorder Traversal", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/", "examples": [{"input": "preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]", "output": "[3,9,20,null,null,15,7]", "explanation": "The first element of preorder (3) is the root. It splits inorder into left ([9]) and right ([15, 20, 7]) subtrees. Repeating recursively builds the tree [3,9,20,null,null,15,7].\n\n"}, {"input": "preorder = [-1], inorder = [-1]", "output": "[-1]", "explanation": "The first element of preorder (-1) is the root. It splits inorder into left ([]) and right ([]) subtrees. Repeating recursively builds the tree [-1]."}], "hints": ["Use recursion with a hashmap of inorder indices to split left and right subtrees."], "statement": "Two integer arrays `preorder` and `inorder` capture traversals of a common binary tree: `preorder` lists vertices in root-left-right order, while `inorder` lists them in left-root-right order.\nRebuild the underlying tree and hand back its root.\n\n**Constraints:**\n\n- 1 \u2264 preorder.length \u2264 3000\n- inorder.length == preorder.length\n- -3000 \u2264 preorder[i], inorder[i] \u2264 3000\n- preorder and inorder consist of unique values.\n- Each value of inorder also appears in preorder.\n- preorder is guaranteed to be the preorder traversal of the tree.\n- inorder is guaranteed to be the inorder traversal of the tree.\n", "solution": "## Approach\n\nThe first element of preorder is the root; find its index in inorder to split left and right subtrees recursively.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import List, Optional\nclass Solution:\n def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]:\n idx_map = {v: i for i, v in enumerate(inorder)}\n self.pre_idx = 0\n def build(l, r):\n if l > r:\n return None\n val = preorder[self.pre_idx]\n self.pre_idx += 1\n node = TreeNode(val)\n mid = idx_map[val]\n node.left = build(l, mid - 1)\n node.right = build(mid + 1, r)\n return node\n return build(0, len(inorder) - 1)\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 BuildTree(preorder []int, inorder []int) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import List\nclass Solution:\n def buildTree(self, preorder: List[int], inorder: List[int]):\n # TODO: reconstruct and return the tree root\n pass\n", "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 TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {\n \n }\n};\n"}, "fn": "buildTree", "params": [{"name": "preorder", "type": "int_array"}, {"name": "inorder", "type": "int_array"}], "outputType": "tree_node", "tests": [["[3,9,20,15,7]", "[9,3,15,20,7]"], ["[1,2]", "[2,1]"], ["[1,2,3]", "[2,1,3]"], ["[5,3,2,4,7,6,8]", "[2,3,4,5,6,7,8]"], ["[-1]", "[-1]"], ["[1]", "[1]"], ["[0]", "[0]"], ["[100]", "[100]"], ["[1,2]", "[1,2]"], ["[3,2]", "[2,3]"], ["[2,3]", "[2,3]"], ["[3,2,1]", "[1,2,3]"], ["[1,2,3]", "[1,2,3]"], ["[2,1,3]", "[1,2,3]"], ["[8,3,1,6,4,7,10,14,13]", "[1,3,4,6,7,8,10,13,14]"], ["[10,5,3,1,7,6,15,18]", "[1,3,5,6,7,10,15,18]"], ["[20,10,5,2,7,15,30,25,35]", "[2,5,7,10,15,20,25,30,35]"], ["[50,30,20,10,25,40,35,45,70,60,80]", "[10,20,25,30,35,40,45,50,60,70,80]"], ["[9,5,4,3,2,1]", "[1,2,3,4,5,9]"], ["[1,2,3,4,5,6]", "[1,2,3,4,5,6]"], ["[6,4,2,1,3,5,8,7,9]", "[1,2,3,4,5,6,7,8,9]"], ["[15,10,8,6,12,11,20,18,25]", "[6,8,10,11,12,15,18,20,25]"], ["[100,50,25,10,30,75,150,125,175]", "[10,25,30,50,75,100,125,150,175]"], ["[7,3,1,0,2,5,4,6,9,8,10]", "[0,1,2,3,4,5,6,7,8,9,10]"], ["[-5,-10,-15,-7,0,5,10]", "[-15,-10,-7,-5,0,5,10]"], ["[-1,-2,0,1,2]", "[-2,-1,0,1,2]"], ["[42,21,10,30,63,55,70]", "[10,21,30,42,55,63,70]"], ["[11,7,5,3,6,9,15,13,17]", "[3,5,6,7,9,11,13,15,17]"], ["[4,2,1,3,6,5,7,8]", "[1,2,3,4,5,6,7,8]"], ["[12,6,3,1,4,9,8,18,15,21]", "[1,3,4,6,8,9,12,15,18,21]"], ["[-3000]", "[-3000]"], ["[3000]", "[3000]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "880", "slug": "construct-binary-tree-from-preorder-and-postorder-traversal", "id": 880, "title": "Construct Binary Tree from Preorder and Postorder Traversal", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/", "examples": [{"input": "preorder = [1,2,4,5,3,6,7], postorder = [4,5,2,6,7,3,1]", "output": "[1,2,3,4,5,6,7]", "explanation": "The root is 1. Its left child 2 parents 4 and 5, and its right child 3 parents 6 and 7."}, {"input": "preorder = [1], postorder = [1]", "output": "[1]", "explanation": "A single node forms the whole tree."}, {"input": "preorder = [1,2,3], postorder = [2,3,1]", "output": "[1,2,3]", "explanation": "Both children hang directly under the root 1."}], "hints": ["The first preorder value is the root and the last postorder value is the same root.", "The value right after the root in preorder starts the left subtree; find it in postorder to learn where the left subtree ends and the right one begins, then recurse.", "A lone child may be attached on either side, so any placement that reproduces both traversals counts."], "statement": "You are given two arrays, `preorder` and `postorder`, holding the preorder and postorder traversals of one binary tree whose values are all distinct. Rebuild the tree and return its root.\n\nWhen several different trees fit the two traversals, any one of them is accepted.\n\n**Constraints:**\n- `1 <= preorder.length <= 30`\n- `1 <= preorder[i], postorder[i] <= 30`\n- All values in each array are distinct.\n- `preorder` and `postorder` describe the same binary tree.\n", "solution": "## Approach\n\nThe head of the preorder list is always the current root. The next preorder value opens the left subtree, and its position in the postorder list marks exactly where that left subtree ends \u2014 everything before it (within the current span) belongs to the left child, and the remainder before the closing root belongs to the right child. Recursing on both spans rebuilds the whole tree; a lone child can go on either side, and any placement reproducing both traversals is accepted.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is created once with O(1) index lookups.\n- **Space Complexity:** O(n) for the index map plus O(n) recursion depth in the worst case.\n\n## Implementation\n\n```python\nclass Solution:\n def constructFromPrePost(self, preorder, postorder):\n post_idx = {v: i for i, v in enumerate(postorder)}\n self.pos = 0\n\n def build(l, r):\n if l > r:\n return None\n root = TreeNode(preorder[self.pos])\n self.pos += 1\n if l == r:\n return root\n m = post_idx[preorder[self.pos]]\n root.left = build(l, m)\n root.right = build(m + 1, r - 1)\n return root\n\n return build(0, len(postorder) - 1)\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc ConstructFromPrePost(preorder []int, postorder []int) *TreeNode {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def constructFromPrePost(self, preorder, postorder):\n # TODO: rebuild and return the tree root\n pass", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* constructFromPrePost(vector<int>& preorder, vector<int>& postorder) {\n \n }\n};"}, "fn": "constructFromPrePost", "params": [{"name": "preorder", "type": "int_array"}, {"name": "postorder", "type": "int_array"}], "outputType": "tree_node", "tests": [["[1]", "[1]"], ["[1,2]", "[2,1]"], ["[1,3]", "[3,1]"], ["[1,2,3]", "[2,3,1]"], ["[1,2,3]", "[3,2,1]"], ["[4,5,6]", "[6,5,4]"], ["[1,2,4,5,3]", "[4,5,2,3,1]"], ["[1,2,3,6,7]", "[2,6,7,3,1]"], ["[1,2,4,5,3,6,7]", "[4,5,2,6,7,3,1]"], ["[5,3,2,4,7,6,8]", "[2,4,3,6,8,7,5]"], ["[1,2,4,8,5,3]", "[8,4,5,2,3,1]"], ["[10,5,3,7,15,12,20]", "[3,7,5,12,20,15,10]"], ["[1,3,2,4]", "[2,4,3,1]"], ["[2,1,3]", "[1,3,2]"], ["[3,1,2]", "[2,1,3]"], ["[1,2,4,8,9,5,10,11,3,6,12,13,7,14,15]", "[8,9,4,10,11,5,2,12,13,6,14,15,7,3,1]"], ["[1,2,3,4]", "[4,3,2,1]"], ["[5,4,3,2]", "[2,3,4,5]"], ["[8,3,1,6,4,7,10,14,13]", "[1,4,7,6,3,13,14,10,8]"], ["[1,2,4,5,3,6]", "[4,5,2,6,3,1]"], ["[7,3,1,5,9,8,10]", "[1,5,3,8,10,9,7]"], ["[1,3,2,4]", "[2,4,3,1]"], ["[6,2,1,4,3,5,8,7,9]", "[1,3,5,4,2,7,9,8,6]"], ["[4,2,1,3,6,5,7]", "[1,3,2,5,7,6,4]"], ["[9,5,3,2,4,7,8]", "[2,4,3,7,5,8,9]"], ["[12,7,3,9,18,15,20]", "[3,9,7,15,20,18,12]"], ["[20,10,5,15,30]", "[5,15,10,30,20]"], ["[2,3,4,5]", "[5,4,3,2]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "594", "slug": "construct-binary-tree-from-string", "id": 594, "title": "Construct Binary Tree from String", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/construct-binary-tree-from-string/", "examples": [{"input": "s = \"4(2(3)(1))(6(5))\"", "output": "[4,2,6,3,1,5]", "explanation": "Root 4 has left subtree 2 (children 3 and 1) and right child 6 (left child 5)."}, {"input": "s = \"4(2(3)(1))(6(5)(7))\"", "output": "[4,2,6,3,1,5,7]", "explanation": "As above, plus 6 gains right child 7."}, {"input": "s = \"-4(2(3)(1))(6(5)(7))\"", "output": "[-4,2,6,3,1,5,7]", "explanation": "Node values may be negative; the shape is unchanged."}], "hints": ["Parse recursively with a shared position cursor: read the integer, then parse up to two parenthesized children.", "A '(' starts a child subtree; its matching ')' ends it. Absent parentheses mean an absent child.", "An empty input string yields a null tree."], "statement": "You are given a string that encodes a binary tree. The encoding works like this: a node's integer value comes first (possibly negative, possibly several digits), then its left subtree wrapped in parentheses, then its right subtree wrapped in parentheses. A missing child is simply omitted (never written as empty parentheses). For example, `1(2)(3)` is a root `1` with left child `2` and right child `3`, while `1(2)` has only a left child.\n\nBuild the tree described by the string and return its root. An empty string means there is no tree, so return null.\n\n**Constraints:**\n- `0 <= s.length <= 3 * 10^4`\n- `s` is either empty or a valid encoding: integers (with optional leading `-`), parentheses balanced, no empty `()` pairs.\n- Node values fit in a 32-bit signed integer.\n", "solution": "## Approach\n\nParse the string with a single left-to-right cursor shared by recursive calls. Each call reads an optional minus sign followed by digits to form the node value, then looks for parenthesized groups: the first group becomes the left child and the second becomes the right child, each parsed recursively. A missing group means a missing child, and an empty input produces a null tree.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the string length. Each character is consumed once.\n- **Space Complexity:** O(h) for the recursion stack, where h is the tree height (plus O(n) for the rebuilt tree).\n\n## Implementation\n\n```python\nclass Solution:\n def str2tree(self, s: str):\n if not s:\n return None\n self.pos = 0\n def parse():\n start = self.pos\n if s[self.pos] == '-':\n self.pos += 1\n while self.pos < len(s) and s[self.pos].isdigit():\n self.pos += 1\n node = TreeNode(int(s[start:self.pos]))\n if self.pos < len(s) and s[self.pos] == '(':\n self.pos += 1\n node.left = parse()\n self.pos += 1\n if self.pos < len(s) and s[self.pos] == '(':\n self.pos += 1\n node.right = parse()\n self.pos += 1\n return node\n return parse()\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc Str2tree(s string) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def str2tree(self, s: str):\n pass\n", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* str2tree(string s) {\n return nullptr;\n }\n};"}, "fn": "str2tree", "params": [{"name": "s", "type": "string"}], "outputType": "tree_node", "tests": [["4(2(3)(1))(6(5))"], ["4(2(3)(1))(6(5)(7))"], ["-4(2(3)(1))(6(5)(7))"], ["4"], [""], ["1(2)"], ["1(2(3(4)))"], ["-1"], ["10(20)(30)"], ["1(2)(3)"], ["5(4(3(2(1))))"], ["100"], ["-10(-20)(-30)"], ["1(-2)(-3)"], ["12(34(56)(78))(90)"], ["0"], ["7(3)(9)"], ["-5(-3)(-8)"], ["2(1)(3)"], ["42(17)(99)"], ["8(4(2)(6))(12(10)(14))"], ["-100(50)(-25)"], ["3(1)(4(2))"], ["6(2(0)(4))(8(7)(9))"], ["123"], ["-7(-14)"], ["9(8(7(6)))"], ["15(10(5)(12))(20(17)(25))"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "199", "slug": "construct-quad-tree", "id": 199, "title": "Construct Quad Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/construct-quad-tree/", "examples": [{"input": "grid = [[0,1],[1,0]]", "output": "[[0,1],[1,0],[1,1],[1,1],[1,0]]", "explanation": "Serialized as BFS list of [isLeaf,val] (1/0). null children of leaves omitted via structure."}, {"input": "grid = [[1,1],[1,1]]", "output": "[[1,1]]"}], "hints": ["Recursively build the quad tree. If a subgrid is uniform, return a leaf.", "Serialize the tree as a BFS list of [isLeaf, val] pairs (1/0). For internal nodes, four children follow in order TL,TR,BL,BR. Leaves have no children in the serialization (standard LeetCode display)."], "statement": "You are handed a square binary matrix `grid` of size `n * n` containing only `0` and `1`. Build the quad tree that represents it and return its root. In this judge the tree is submitted as a breadth-first encoding: a list of `[isLeaf, val]` pairs written with integers `1`/`0`. Leaf entries carry no children in the encoding, while each internal entry is followed by its four children in the sequence topLeft, topRight, bottomLeft, bottomRight.\n\nA quad tree is a tree in which every branch node owns exactly four children. Each node is described by `isLeaf` together with `val`.\n\nForm the tree for a square region with this recursive rule:\n1. When every cell of the region stores one shared value (entirely `1` or entirely `0`), emit a leaf holding that value, with all four children Null.\n2. When the region mixes values, emit a branch node (its `val` may be either value) and split the region into its four equal quadrants.\n3. Apply the same procedure to each of the four quadrants.\n\n**Constraints:**\n- `n == grid.length == grid[i].length`\n- `n == 2^x` where `0 <= x <= 6`\n", "solution": "## Approach\n\nRecursively build the quad tree on subgrids. If all four children are identical leaves, collapse into one leaf.\n\nSerialize with BFS: each node becomes `[isLeaf, val]`; only internal nodes enqueue four children.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2 log n)\n- **Space Complexity:** O(n^2)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def construct(self, grid: List[List[int]]) -> List[List[int]]:\n class Node:\n def __init__(self, val, isLeaf, tl=None, tr=None, bl=None, br=None):\n self.val = val\n self.isLeaf = isLeaf\n self.topLeft = tl\n self.topRight = tr\n self.bottomLeft = bl\n self.bottomRight = br\n def build(r, c, length):\n if length == 1:\n return Node(grid[r][c] == 1, True)\n h = length // 2\n tl, tr = build(r, c, h), build(r, c + h, h)\n bl, br = build(r + h, c, h), build(r + h, c + h, h)\n if tl.isLeaf and tr.isLeaf and bl.isLeaf and br.isLeaf and tl.val == tr.val == bl.val == br.val:\n return Node(tl.val, True)\n return Node(True, False, tl, tr, bl, br)\n root = build(0, 0, len(grid))\n out = []\n from collections import deque\n q = deque([root])\n while q:\n n = q.popleft()\n out.append([1 if n.isLeaf else 0, 1 if n.val else 0])\n if not n.isLeaf:\n q.extend([n.topLeft, n.topRight, n.bottomLeft, n.bottomRight])\n return out\n```\n", "starter": {"go": "package main\n\nfunc Construct(grid [][]int) [][]int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def construct(self, grid: List[List[int]]) -> List[List[int]]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> construct(vector<vector<int>>& grid) {\n return {};\n }\n};"}, "fn": "construct", "params": [{"name": "grid", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[0,1],[1,0]]"], ["[[1,1],[1,1]]"], ["[[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]"], ["[[1]]"], ["[[0]]"], ["[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]"], ["[[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[0,0,0,0,1,1,1,1],[0,0,0,0,1,1,1,1],[0,0,0,0,1,1,1,1],[0,0,0,0,1,1,1,1]]"], ["[[0,0],[0,0]]"], ["[[0,0],[0,1]]"], ["[[1,1],[1,0]]"], ["[[0,0],[1,1]]"], ["[[1,0],[1,0]]"], ["[[0,1],[0,1]]"], ["[[1,0],[0,1]]"], ["[[0,1,0,1],[1,0,1,0],[0,1,0,1],[1,0,1,0]]"], ["[[1,1,1,1],[1,0,0,1],[1,0,0,1],[1,1,1,1]]"], ["[[0,0,1,1],[0,0,1,1],[1,1,0,0],[1,1,0,0]]"], ["[[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]"], ["[[0,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]"], ["[[1,1,0,0],[1,1,0,0],[0,0,0,0],[0,0,0,0]]"], ["[[0,0,0,0],[0,1,1,0],[0,1,1,0],[0,0,0,0]]"], ["[[1,1,1,1],[1,1,1,1],[0,0,0,0],[0,0,0,0]]"], ["[[1,1,0,0],[1,1,0,0],[1,1,0,0],[1,1,0,0]]"], ["[[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]]"], ["[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]]"], ["[[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]]"], ["[[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0]]"], ["[[1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0]]"], ["[[0,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]]"]], "expected": [[[0, 1], [1, 0], [1, 1], [1, 1], [1, 0]], [[1, 1]], [[0, 1], [1, 1], [1, 0], [1, 0], [1, 1]], [[1, 1]], [[1, 0]], [[1, 1]], [[1, 0]], [[0, 1], [1, 1], [1, 0], [1, 0], [1, 1]], [[1, 0]], [[0, 1], [1, 0], [1, 0], [1, 0], [1, 1]], [[0, 1], [1, 1], [1, 1], [1, 1], [1, 0]], [[0, 1], [1, 0], [1, 0], [1, 1], [1, 1]], [[0, 1], [1, 1], [1, 0], [1, 1], [1, 0]], [[0, 1], [1, 0], [1, 1], [1, 0], [1, 1]], [[0, 1], [1, 1], [1, 0], [1, 0], [1, 1]], [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0]], [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [1, 1], [1, 1], [1, 1], [1, 0], [1, 1], [1, 1], [1, 0], [1, 1], [1, 1], [1, 0], [1, 1], [1, 1], [1, 0], [1, 1], [1, 1], [1, 1]], [[0, 1], [1, 0], [1, 1], [1, 1], [1, 0]], [[0, 1], [0, 1], [1, 0], [1, 0], [1, 0], [1, 1], [1, 0], [1, 0], [1, 0]], [[0, 1], [0, 1], [1, 1], [1, 1], [1, 1], [1, 0], [1, 1], [1, 1], [1, 1]], [[0, 1], [1, 1], [1, 0], [1, 0], [1, 0]], [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [1, 0], [1, 0], [1, 0], [1, 1], [1, 0], [1, 0], [1, 1], [1, 0], [1, 0], [1, 1], [1, 0], [1, 0], [1, 1], [1, 0], [1, 0], [1, 0]], [[0, 1], [1, 1], [1, 1], [1, 0], [1, 0]], [[0, 1], [1, 1], [1, 0], [1, 1], [1, 0]], [[1, 1]], [[1, 0]], [[0, 1], [1, 1], [1, 0], [1, 0], [1, 0]], [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0], [1, 1], [1, 1], [1, 0], [1, 0]], [[0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [0, 1], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0], [1, 1], [1, 0]], [[0, 1], [0, 1], [1, 1], [1, 1], [1, 1], [0, 1], [1, 1], [1, 1], [1, 1], [1, 0], [1, 1], [1, 1], [1, 1]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "642", "slug": "construct-string-from-binary-tree", "id": 642, "title": "Construct String from Binary Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/construct-string-from-binary-tree/", "examples": [{"input": "root = [1,2,3,4]", "output": "\"1(2(4))(3)\"", "explanation": "Node 1 has left subtree 2 (which itself has left child 4) and right child 3, so the parenthesized preorder form is 1(2(4))(3)."}, {"input": "root = [1,2,3,null,4]", "output": "\"1(2()(4))(3)\"", "explanation": "Node 2 has no left child but has right child 4, so an empty pair marks the missing left side to keep the mapping unambiguous."}, {"input": "root = [1]", "output": "\"1\"", "explanation": "A lone node needs no parentheses."}], "hints": ["Walk the tree in root-left-right order and emit the node value first.", "Append the left part in parentheses whenever any child exists; append the right part only when a right child exists.", "When the left child is missing but the right child is present, keep an empty pair for the left side so the shape stays recoverable."], "statement": "You are given the root of a binary tree. Build a compact text form of the tree by visiting nodes in root-first order (node, then left part, then right part).\n\nRules for each visited node with value `v`, left rendering `L` and right rendering `R`:\n\n- When the node has no children, write just `v`.\n- When only a left child exists, write `v(L)`.\n- When both children exist, write `v(L)(R)`.\n- When the left child is absent but the right child is present, write `v()(R)` so the empty left slot is still visible. A missing right child with no right content contributes nothing.\n\nApply the same rules recursively to every subtree and return the full string for the whole tree. An empty tree yields an empty string.\n\n**Constraints:**\n- The tree holds between 0 and 10000 nodes.\n- Each node value lies between -1000 and 1000.\n", "solution": "## Approach\n\nDo a preorder walk that writes the node value first. Whenever a node owns at least one child, wrap the left rendering in parentheses; whenever a right child exists, wrap the right rendering too. The only subtle case is a missing left child paired with a present right child, where an empty pair preserves the structure. A shared recursive helper carrying a string buffer keeps every value conversion in one place.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the node count. Each node is visited once.\n- **Space Complexity:** O(n) for the output plus recursion depth (worst case O(n) on a chain, O(log n) on a balanced tree).\n\n## Implementation\n\n```python\nclass Solution:\n def tree2str(self, root) -> str:\n parts = []\n def build(t):\n if t is None:\n return\n parts.append(str(t.val))\n if t.left is not None or t.right is not None:\n parts.append(\"(\")\n build(t.left)\n parts.append(\")\")\n if t.right is not None:\n parts.append(\"(\")\n build(t.right)\n parts.append(\")\")\n build(root)\n return \"\".join(parts)\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 Tree2str(root *TreeNode) string {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def tree2str(self, root) -> str:\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 <string>\nusing namespace std;\nclass Solution {\npublic:\n string tree2str(TreeNode* root) {\n return \"\";\n }\n};"}, "fn": "tree2str", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "string", "tests": [["[1,2,3,4]"], ["[1,2,3,null,4]"], ["[1]"], ["[]"], ["[1,2]"], ["[1,null,2]"], ["[1,2,3]"], ["[1,2,null,3]"], ["[1,null,2,null,3]"], ["[5]"], ["[-1,-2,-3]"], ["[0]"], ["[1,2,3,4,5]"], ["[1,2,3,4,null,null,5]"], ["[10,20,null,30]"], ["[1,null,2,3]"], ["[1000,-1000,1000]"], ["[1,2,3,null,null,4,5]"], ["[2,1,3]"], ["[1,2,null,null,3]"], ["[3,1,4,null,2]"], ["[1,2,3,4,5,6,7]"], ["[1,null,null]"], ["[7,6,5,4,3]"], ["[1,2,null,3,null,4]"], ["[9,8,null,7,null,6]"], ["[4,2,6,1,3,5,7]"], ["[1,2,3,null,4,5,6]"]], "expected": ["1(2(4))(3)", "1(2()(4))(3)", "1", "", "1(2)", "1()(2)", "1(2)(3)", "1(2(3))", "1()(2()(3))", "5", "-1(-2)(-3)", "0", "1(2(4)(5))(3)", "1(2(4))(3()(5))", "10(20(30))", "1()(2(3))", "1000(-1000)(1000)", "1(2)(3(4)(5))", "2(1)(3)", "1(2()(3))", "3(1()(2))(4)", "1(2(4)(5))(3(6)(7))", "1", "7(6(4)(3))(5)", "1(2(3(4)))", "9(8(7(6)))", "4(2(1)(3))(6(5)(7))", "1(2()(4))(3(5)(6))"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "556", "slug": "construct-the-rectangle", "id": 556, "title": "Construct the Rectangle", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/construct-the-rectangle/", "examples": [{"input": "area = 4", "output": "[2,2]", "explanation": "Among [1,4] and [2,2], the square has the smallest side gap."}, {"input": "area = 37", "output": "[37,1]", "explanation": "A prime area only factors as 37 by 1."}, {"input": "area = 122122", "output": "[427,286]", "explanation": "This factor pair is the closest to a square."}], "hints": ["The width can never exceed the square root of the area.", "Scan downward from the integer square root until a divisor is found; the first hit is the answer."], "statement": "A web page needs a rectangular shape whose area equals a given positive integer. Call its sides length `L` and width `W`. The design must satisfy two rules: the length is never shorter than the width (`L >= W`), and the gap between the sides (`L - W`) is as small as possible.\n\nReturn the chosen pair as `[L, W]`.\n\n**Constraints:**\n- `1 <= area <= 10^7`\n", "solution": "## Approach\n\nBecause the width is the smaller factor, it lies at or below the square root of the area. Starting from the floored square root and stepping downward, the first divisor encountered gives the largest feasible width, hence the closest-to-square pair. Dividing yields the matching length.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(sqrt(area)) in the worst case, often much faster.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nimport math\nfrom typing import List\n\nclass Solution:\n def constructRectangle(self, area: int) -> List[int]:\n w = int(math.isqrt(area))\n while area % w != 0:\n w -= 1\n return [area // w, w]\n```\n", "starter": {"go": "package main\n\nfunc ConstructRectangle(area int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def constructRectangle(self, area: int) -> List[int]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> constructRectangle(int area) {\n return {};\n }\n};"}, "fn": "constructRectangle", "params": [{"name": "area", "type": "int"}], "outputType": "int_array", "tests": [["4"], ["37"], ["122122"], ["1"], ["2"], ["3"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["15"], ["16"], ["25"], ["26"], ["48"], ["100"], ["101"], ["999"], ["1000"], ["10000"], ["9999"], ["17"], ["36"], ["49"], ["10000000"], ["9999991"]], "expected": [[2, 2], [37, 1], [427, 286], [1, 1], [2, 1], [3, 1], [5, 1], [3, 2], [7, 1], [4, 2], [3, 3], [5, 2], [5, 3], [4, 4], [5, 5], [13, 2], [8, 6], [10, 10], [101, 1], [37, 27], [40, 25], [100, 100], [101, 99], [17, 1], [6, 6], [7, 7], [3200, 3125], [9999991, 1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "752", "slug": "contain-virus", "id": 752, "title": "Contain Virus", "difficulty": "Hard", "category": "matrix", "link": "https://leetcode.com/problems/contain-virus/", "examples": [{"input": "isInfected = [[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]]", "output": "10", "explanation": "Seal left with 5 walls, let right spread, seal right with 5."}, {"input": "isInfected = [[1,1,1],[1,0,1],[1,1,1]]", "output": "4", "explanation": "Four walls close the single ring."}, {"input": "isInfected = [[1,1,1,0,0,0,0,0,0],[1,0,1,0,1,1,1,1,1],[1,1,1,0,0,0,0,0,0]]", "output": "13", "explanation": "Left ring sealed first, then the right mass."}], "hints": ["Each day, flood-fill every connected block of 1s, collecting both its cells and the set of neighboring 0s plus the wall count.", "Seal the block with the biggest threatened set, add its wall count to the answer, freeze its cells, and infect the threatened cells of all other blocks.", "Repeat until no block touches a healthy cell; frozen cells behave as permanent barriers."], "statement": "A laboratory floor is modeled as a binary grid `isInfected`, where `0` means a healthy cell and `1` means an infected cell. One wall can be raised on the shared edge between two neighboring cells that touch up, down, left, or right.\n\nTime advances in days. Each morning you pick exactly one connected block of infected cells and seal it completely: every edge touching a healthy cell gets a wall, and that block never spreads again. Each night every unsealed infected block copies itself into all four neighbors unless a wall or the grid border stops it.\n\nOn each day you must pick the block that endangers the most distinct healthy cells for the coming night; the task guarantees this choice is never tied while spreading is still possible. Sealed cells are frozen and healthy cells that get touched become infected for the next day.\n\nReturn the total number of walls raised until no unsealed infection can reach a healthy cell. If the whole floor ends up infected, return the walls raised along the way.\n\n**Constraints:**\n- `m == isInfected.length`, `n == isInfected[i].length`\n- `1 <= m, n <= 50`\n- Each entry is `0` or `1`.\n- While spreading continues, one block always threatens strictly more healthy cells than any other.\n", "solution": "## Approach\n\nSimulate day by day. On each day flood-fill all connected groups of infected cells, recording for every group its cells, the distinct healthy neighbours it threatens, and how many wall segments touch healthy cells. Quarantine the group with the largest threatened set by adding its wall count to the total and freezing its cells, then turn every other group's threatened cells infected overnight. Stop when no group touches a healthy cell.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(D * m * n), where D is the number of days simulated and m * n is the floor size, since each day scans the whole grid.\n- **Space Complexity:** O(m * n) for the visited flags and the per-group cell lists.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n m, n = len(isInfected), len(isInfected[0])\n g = [row[:] for row in isInfected]\n ans = 0\n dirs = [(1,0),(-1,0),(0,1),(0,-1)]\n while True:\n vis = [[False]*n for _ in range(m)]\n areas, bounds, walls = [], [], []\n for i in range(m):\n for j in range(n):\n if g[i][j] == 1 and not vis[i][j]:\n area, bound, w = [], set(), 0\n q = deque([(i,j)])\n vis[i][j] = True\n while q:\n x, y = q.popleft()\n area.append((x,y))\n for dx, dy in dirs:\n nx, ny = x+dx, y+dy\n if not (0 <= nx < m and 0 <= ny < n) or g[nx][ny] == -1:\n continue\n if g[nx][ny] == 0:\n w += 1\n bound.add(nx*n+ny)\n elif g[nx][ny] == 1 and not vis[nx][ny]:\n vis[nx][ny] = True\n q.append((nx,ny))\n areas.append(area); bounds.append(bound); walls.append(w)\n if not areas:\n break\n idx = max(range(len(bounds)), key=lambda k: len(bounds[k]))\n if not bounds[idx]:\n break\n ans += walls[idx]\n for k in range(len(areas)):\n if k == idx:\n for x, y in areas[k]:\n g[x][y] = -1\n else:\n for code in bounds[k]:\n g[code//n][code%n] = 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc ContainVirus(isInfected [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def containVirus(self, isInfected: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int containVirus(vector<vector<int>>& isInfected) {\n return 0;\n }\n};"}, "fn": "containVirus", "params": [{"name": "isInfected", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0,1,0,0,0,0,0,1],[0,1,0,0,0,0,0,1],[0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0]]"], ["[[1,1,1],[1,0,1],[1,1,1]]"], ["[[1,1,1,0,0,0,0,0,0],[1,0,1,0,1,1,1,1,1],[1,1,1,0,0,0,0,0,0]]"], ["[[0]]"], ["[[1]]"], ["[[0,0],[0,0]]"], ["[[1,0],[0,0]]"], ["[[1,1],[0,0]]"], ["[[1,0,0],[0,0,0],[0,0,0]]"], ["[[0,0,0],[0,1,0],[0,0,0]]"], ["[[1,1,0],[1,0,0],[0,0,0]]"], ["[[1,0,1],[0,0,0],[1,0,1]]"], ["[[0,0,0,0],[0,1,1,0],[0,1,1,0],[0,0,0,0]]"], ["[[1,1,1,1],[1,0,0,1],[1,0,0,1],[1,1,1,1]]"], ["[[0,1,0],[1,1,1],[0,1,0]]"], ["[[1,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]"], ["[[0,0,0],[0,0,0],[0,0,1]]"], ["[[1,1,0,0],[1,1,0,0],[0,0,0,0],[0,0,0,0]]"], ["[[0,0,0,0,0],[0,1,0,1,0],[0,0,0,0,0]]"], ["[[1,0],[1,0],[0,0]]"], ["[[1,1,1,0],[1,0,1,0],[1,1,1,0],[0,0,0,0]]"], ["[[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]]"], ["[[1,0,0],[1,1,0],[0,1,0]]"], ["[[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]]"], ["[[1,1],[1,1]]"], ["[[0,0],[1,1]]"], ["[[1,0,0,1],[0,0,0,0],[0,0,0,0]]"], ["[[0,0,0,1,1],[0,0,0,1,1],[0,0,0,0,0]]"]], "expected": [10, 4, 13, 0, 0, 0, 2, 2, 2, 4, 4, 6, 8, 8, 8, 2, 2, 4, 12, 3, 10, 6, 6, 7, 0, 2, 6, 4], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "10", "slug": "container-with-most-water", "id": 10, "title": "Container With Most Water", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/container-with-most-water/", "examples": [{"input": "height = [1,8,6,2,5,4,8,3,7]", "output": "49", "explanation": "The maximum area is 49."}, {"input": "height = [1,1]", "output": "1", "explanation": "The maximum area is 1."}], "hints": ["Use a two-pointer approach starting at both ends, moving the shorter side inward each step. This guarantees O(n) time."], "statement": "You are given an integer array `height`, where the value at index `i` denotes the height of a vertical wall standing at that position. Select two positions to serve as the sides of a vessel (the base being the x-axis) and determine the greatest quantity of water such a vessel could retain. Return that maximum.\n\nThe retained quantity for a pair of positions is the gap between them multiplied by the shorter of the two walls.\n\n**Constraints:**\n- `n == height.length`\n- `2 <= n <= 10^5`\n- `0 <= height[i] <= 10^4`\n", "solution": "## Approach\n\nTwo-pointer technique starting from the ends, always moving the shorter line inward since that is the limiting factor for the area.\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 maxArea(self, height: List[int]) -> int:\n l, r = 0, len(height) - 1\n res = 0\n while l < r:\n area = min(height[l], height[r]) * (r - l)\n res = max(res, area)\n if height[l] < height[r]:\n l += 1\n else:\n r -= 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc MaxArea(height []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxArea(self, height: List[int]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxArea(vector<int>& height) {\n return 0;\n }\n};"}, "fn": "maxArea", "params": [{"name": "height", "type": "int_array"}], "outputType": "int", "tests": [["[1,8,6,2,5,4,8,3,7]"], ["[1,1]"], ["[4,3,2,1,4]"], ["[1,2,1]"], ["[1,3,2,5,25,24,5]"], ["[2,3,4,5,18,17,6]"], ["[0,0,0,0,0]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[10,9,8,7,6,5,4,3,2,1]"], ["@javascript:JSON.stringify(Array(100000).fill(10000))"], ["[0,1]"], ["[1,0]"], ["[2,1]"], ["[1,2]"], ["[3,3]"], ["[5,5,5,5]"], ["[0,2]"], ["[2,0]"], ["[1,2,4,3]"], ["[5,1,2,3,4]"], ["[4,1,2,3,5]"], ["[10000,10000]"], ["[0,10000]"], ["[10000,0]"], ["[1,2,3]"], ["[3,2,1]"], ["[2,3,10,5,7,8,9]"], ["[1,10000,1,10000,1]"], ["[10,1,10]"], ["[7,3,9,4,5,6,2,8]"], ["[6,6,6,6,6,6]"], ["[4,8,1,2,3,9,4,5]"]], "expected": [49, 1, 16, 2, 24, 17, 0, 25, 25, 999990000, 0, 0, 1, 1, 3, 15, 0, 0, 4, 16, 16, 10000, 0, 0, 2, 2, 36, 20000, 20, 49, 30, 32], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "173", "slug": "contains-duplicate-ii", "id": 173, "title": "Contains Duplicate II", "difficulty": "Easy", "category": "sliding-window", "link": "https://leetcode.com/problems/contains-duplicate-ii/", "examples": [{"input": "nums = [1,2,3,1], k = 3", "output": "true", "explanation": "nums[0] == nums[3] and abs(0 - 3) = 3 <= 3."}, {"input": "nums = [1,0,1,1], k = 1", "output": "true", "explanation": "nums[2] == nums[3] and abs(2 - 3) = 1 <= 1."}, {"input": "nums = [1,2,3,1,2,3], k = 2", "output": "false", "explanation": "No two equal values are within distance 2."}], "hints": ["Keep a sliding window of the last k elements in a hash set.", "For each element, if it is already in the set return true; otherwise insert it and evict the element falling out of the window."], "statement": "You receive an integer array `nums` together with an integer `k`. Determine whether two separate positions `i` and `j` exist with matching values (`nums[i] == nums[j]`) whose separation satisfies `abs(i - j) <= k`. Return `true` when such a close repeated pair exists, and `false` otherwise.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `-10^9 <= nums[i] <= 10^9`\n- `0 <= k <= 10^5`\n", "solution": "## Approach\n\nMaintain a sliding window of the last `k` elements in a hash set. For each `nums[i]`, if it is already in the set there are two equal values within distance `k`, so return true. Otherwise insert it and, when the window grows beyond `k`, evict `nums[i-k]`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of the array. Each element is inserted and removed at most once.\n- **Space Complexity:** O(min(n, k)). The set holds at most `k` recent elements.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:\n seen = set()\n for i, v in enumerate(nums):\n if v in seen:\n return True\n seen.add(v)\n if len(seen) > k:\n seen.remove(nums[i - k])\n return False\n```\n", "starter": {"go": "package main\n\nfunc ContainsNearbyDuplicate(nums []int, k int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:\n return False\n", "cpp": "#include <vector>\n#include <unordered_set>\nusing namespace std;\nclass Solution {\npublic:\n bool containsNearbyDuplicate(vector<int>& nums, int k) {\n return false;\n }\n};"}, "fn": "containsNearbyDuplicate", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "boolean", "tests": [["[1,2,3,1]", "3"], ["[1,0,1,1]", "1"], ["[1,2,3,1,2,3]", "2"], ["[1,2,3,4,5]", "1"], ["[1,1]", "1"], ["[1,1]", "0"], ["[99,99]", "2"], ["[1,2,3,4,1]", "3"], ["[1,2,3,4,1]", "4"], ["[0,1,2,3,4,0,0,7,8,9,9]", "1"], ["[-1,-1]", "1"], ["[1,2,1,2,1,2]", "2"], ["[1]", "0"], ["[1]", "1"], ["[1,2]", "1"], ["[1,1]", "3"], ["[1,2,3]", "0"], ["[1,2,3,1]", "0"], ["[1,2,3,1]", "4"], ["[2,2]", "1"], ["[5,6,7,8,5]", "4"], ["[5,6,7,8,5]", "3"], ["[1,2,3,4,5,6,7,1]", "7"], ["[1,2,3,4,5,6,7,1]", "6"], ["[0]", "0"], ["[1,2,3,2,1]", "2"], ["[1,2,3,2,1]", "1"], ["[3,3,3,3]", "1"], ["[1,2,3,4,5,1]", "5"], ["[1,2,3,4,5,1]", "4"], ["[4,1,2,3,1,4]", "2"], ["[2,1,2,3,1]", "2"]], "expected": [true, true, false, false, true, false, true, false, true, true, true, true, false, false, false, true, false, false, true, true, true, false, true, false, false, true, false, true, true, false, false, true], "loose": false}
|