offcode 0.0.0-stage → 0.1.1
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-DCYvZg7a.js +150 -0
- package/dist/web/assets/index-gSBueMfH.css +1 -0
- package/dist/web/index.html +13 -0
- package/package.json +44 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "604", "slug": "number-of-provinces", "id": 604, "title": "Number of Provinces", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/number-of-provinces/", "examples": [{"input": "isConnected = [[1,1,0],[1,1,0],[0,0,1]]", "output": "2", "explanation": "One pair plus one singleton."}, {"input": "isConnected = [[1,0,0],[0,1,0],[0,0,1]]", "output": "3", "explanation": "Three isolated cities."}, {"input": "isConnected = [[1,1,1],[1,1,1],[1,1,1]]", "output": "1"}], "hints": ["Treat the table as an adjacency matrix and run depth-first search from each unvisited city.", "Each fresh search discovers one whole province; count how many searches start.", "A union-find structure merging linked pairs is an equivalent alternative."], "statement": "There are `n` cities labelled `0` through `n-1`. A square table `isConnected` records direct links: entry `[i][j]` is `1` when city `i` connects straight to city `j`, else `0`. Links are mutual, and every city links to itself.\n\nCities belong to the same province when they connect directly or through a chain of intermediate cities. Count how many separate provinces exist.\n\n**Constraints:**\n- `1 <= n <= 200`\n- `n == isConnected.length == isConnected[i].length`\n- `isConnected[i][j]` is `0` or `1`\n- `isConnected[i][i] == 1` and the matrix is symmetric\n", "solution": "## Approach\n\nView the matrix as a graph and flood-fill each component with depth-first search. Iterate cities in order; every time an unvisited city appears, explore its whole reachable group and increment the province counter.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) to scan the matrix.\n- **Space Complexity:** O(n) for visited flags and recursion.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findCircleNum(self, isConnected: List[List[int]]) -> int:\n n = len(isConnected)\n vis = [False] * n\n def dfs(u: int):\n vis[u] = True\n for v in range(n):\n if isConnected[u][v] == 1 and not vis[v]:\n dfs(v)\n cnt = 0\n for i in range(n):\n if not vis[i]:\n cnt += 1\n dfs(i)\n return cnt\n```\n", "starter": {"go": "package main\n\nfunc FindCircleNum(isConnected [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findCircleNum(self, isConnected: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findCircleNum(vector<vector<int>>& isConnected) {\n return 0;\n }\n};"}, "fn": "findCircleNum", "params": [{"name": "isConnected", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,1,0],[1,1,0],[0,0,1]]"], ["[[1,0,0],[0,1,0],[0,0,1]]"], ["[[1,1,1],[1,1,1],[1,1,1]]"], ["[[1]]"], ["[[1,1],[1,1]]"], ["[[1,0],[0,1]]"], ["[[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]"], ["[[1,0,1],[0,1,0],[1,0,1]]"], ["[[1,1,1,0],[1,1,0,0],[1,0,1,1],[0,0,1,1]]"], ["[[1,0,0,1],[0,1,1,0],[0,1,1,0],[1,0,0,1]]"], ["[[1,1,0,0,0],[1,1,0,0,0],[0,0,1,0,0],[0,0,0,1,1],[0,0,0,1,1]]"], ["[[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,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,0,1],[1,1,1,0],[0,1,1,0],[1,0,0,1]]"], ["[[1,0,1,0],[0,1,0,1],[1,0,1,0],[0,1,0,1]]"], ["[[1,1],[1,1]]"], ["[[1,0,0],[0,1,1],[0,1,1]]"], ["[[1,1,0],[1,1,1],[0,1,1]]"], ["[[1,0,1,1],[0,1,0,0],[1,0,1,0],[1,0,0,1]]"], ["[[1,1,1,0,0],[1,1,0,0,0],[1,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]]"], ["[[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1]]"], ["[[1,1,0,0,0,0],[1,1,0,0,0,0],[0,0,1,1,0,0],[0,0,1,1,0,0],[0,0,0,0,1,0],[0,0,0,0,0,1]]"], ["[[1,0,1],[0,1,0],[1,0,1]]"], ["[[1,1,1],[1,1,0],[1,0,1]]"], ["[[1,0,0,0],[0,1,1,1],[0,1,1,1],[0,1,1,1]]"], ["[[1,1,0,0],[1,1,1,0],[0,1,1,1],[0,0,1,1]]"], ["[[1,0],[0,1]]"], ["[[1,1,0,1,0],[1,1,1,0,0],[0,1,1,0,1],[1,0,0,1,1],[0,0,1,1,1]]"]], "expected": [2, 3, 1, 1, 1, 2, 2, 2, 1, 2, 3, 5, 1, 1, 2, 1, 2, 1, 2, 3, 3, 4, 2, 1, 2, 1, 2, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "920", "slug": "number-of-recent-calls", "id": 920, "title": "Number of Recent Calls", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/number-of-recent-calls/", "examples": [{"input": "pings = [1,100,3001,3002]", "output": "[1,2,3,3]", "explanation": "The third call still sees the first one, the fourth drops it."}, {"input": "pings = [1,2,3,4]", "output": "[1,2,3,4]", "explanation": "All four fit inside one window."}, {"input": "pings = [1,4000,8000]", "output": "[1,1,1]", "explanation": "Gaps exceed the window."}], "hints": ["Adaptation: replay the trace with a queue instead of building a class; each entry answers one ping in order.", "Keep only times within [t-3000, t]; drop older front entries before recording the size.", "The queue size after cleanup is the answer for that call."], "statement": "A counter receives calls over time. Each call `ping(t)` reports how many calls arrived in the inclusive window `[t - 3000, t]`, counting the current call.\n\nInstead of building a class, implement a replay function: given the strictly increasing call times `pings`, return an array where entry `i` is the answer `ping(pings[i])` would have produced if the calls arrived in order.\n\n**Constraints:**\n- `1 <= pings.length <= 10000`\n- `1 <= pings[i] <= 10^9`, strictly increasing.\n\nAdaptation: the original design problem is replayed through `runRecentCalls` using `int_array` input and output.\n", "solution": "## Approach\n\nReplay the calls with a queue holding the window. For each new time, append it and discard front entries older than `t - 3000`. The queue size is the ping answer for that step.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of pings. Each time enters and leaves the queue once.\n- **Space Complexity:** O(w) for the window contents, at most O(n).\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def runRecentCalls(self, pings: List[int]) -> List[int]:\n q = deque()\n ans = []\n for t in pings:\n q.append(t)\n while q[0] < t - 3000:\n q.popleft()\n ans.append(len(q))\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunRecentCalls(pings []int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def runRecentCalls(self, pings: List[int]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runRecentCalls(vector<int>& pings) {\n return {};\n }\n};"}, "fn": "runRecentCalls", "params": [{"name": "pings", "type": "int_array"}], "outputType": "int_array", "tests": [["[1, 100, 3001, 3002]"], ["[1, 2, 3, 4]"], ["[1, 4000, 8000]"], ["[1]"], ["[100]"], ["[1, 2]"], ["[3000, 3001, 6000, 6001]"], ["[1, 3001, 3002, 6002]"], ["[642, 1849, 4921, 5936, 5957]"], ["[1, 2, 3, 3000, 3001, 3002]"], ["[10, 20, 30, 3010, 3020, 6030]"], ["[1, 3000, 3001, 6000, 6001, 9000]"], ["[5, 105, 205, 3205, 3305]"], ["[1000000, 1001000, 1002000, 1003000, 1003001]"], ["[1, 2, 3003, 3004, 6005]"], ["[7, 8, 9, 10, 4000, 4001]"], ["[2, 4, 6, 8, 10, 3010]"], ["[50, 51, 52, 3050, 3051, 6051]"], ["[100, 200, 300, 400, 500, 600]"], ["[1000, 2000, 3000, 4000, 5000, 6000, 7000]"], ["[1, 1000, 2000, 3000, 3001, 4000, 5000]"], ["[3, 3003, 3004, 6004]"], ["[999, 1999, 2999, 3999, 4999]"], ["[15, 3015, 3016, 6016]"], ["[200, 3200, 3201, 6201, 6202]"], ["[5000]"], ["[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"], ["[1, 3001, 6001, 9001, 12001]"]], "expected": [[1, 2, 3, 3], [1, 2, 3, 4], [1, 1, 1], [1], [1], [1, 2], [1, 2, 3, 3], [1, 2, 2, 2], [1, 2, 1, 2, 3], [1, 2, 3, 4, 5, 5], [1, 2, 3, 4, 4, 1], [1, 2, 3, 3, 3, 3], [1, 2, 3, 2, 2], [1, 2, 3, 4, 4], [1, 2, 1, 2, 1], [1, 2, 3, 4, 1, 2], [1, 2, 3, 4, 5, 2], [1, 2, 3, 4, 4, 2], [1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 4, 4, 4], [1, 2, 3, 4, 5, 5, 5], [1, 2, 2, 2], [1, 2, 3, 4, 4], [1, 2, 2, 2], [1, 2, 2, 2, 2], [1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 2, 2, 2]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "503", "slug": "number-of-segments-in-a-string", "id": 503, "title": "Number of Segments in a String", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/number-of-segments-in-a-string/", "examples": [{"input": "s = \"Hello, my name is John\"", "output": "5", "explanation": "Five runs of non-space characters."}, {"input": "s = \"Hello\"", "output": "1", "explanation": "A single word is one segment."}, {"input": "s = \" extra gaps \"", "output": "2", "explanation": "Only extra and gaps count."}], "hints": ["Scan once, counting positions where a non-space follows a space or the start.", "Multiple consecutive spaces start only one segment.", "An empty or all-space string yields zero."], "statement": "A segment is a maximal run of characters that contains no spaces: it starts after a space (or at the string start) and ends before the next space (or at the string end). Given a string `s`, count how many such segments it holds.\n\n**Constraints:**\n- `0 <= s.length <= 300`\n- `s` uses letters, digits, punctuation and the space character only.\n", "solution": "## Approach\n\nSweep the string once while remembering whether the previous character was inside a segment. Each transition from a space (or the start) to a non-space begins exactly one new segment, so counting those transitions gives the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def countSegments(self, s: str) -> int:\n count = 0\n in_seg = False\n for c in s:\n if c != ' ':\n if not in_seg:\n count += 1\n in_seg = True\n else:\n in_seg = False\n return count\n```\n", "starter": {"go": "package main\n\nfunc CountSegments(s string) int {\n \n}", "python": "class Solution:\n def countSegments(self, s: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int countSegments(string s) {\n return 0;\n }\n};"}, "fn": "countSegments", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["Hello, my name is John"], ["Hello"], [" extra gaps "], [""], [" "], ["a"], [" a"], ["a "], ["a b"], ["Hello, my name is John!"], ["a,b c@d e#f"], ["one two three four"], ["x"], [" a "], ["ab cd ef gh"], ["hello world"], ["a b c d e"], [" hello world "], ["test"], ["a,b,c"], [" leading"], ["trailing "], ["multiple spaces here"], ["123 456 789"], ["Hello World Foo Bar Baz"], [", , ,"], ["a b"], ["word1 word2 word3 word4 word5 word6"]], "expected": [5, 1, 2, 0, 0, 1, 1, 1, 2, 5, 3, 4, 1, 1, 4, 2, 5, 2, 1, 1, 1, 1, 3, 3, 5, 3, 2, 6], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "978", "slug": "number-of-squareful-arrays", "id": 978, "title": "Number of Squareful Arrays", "difficulty": "Hard", "category": "backtracking", "link": "https://leetcode.com/problems/number-of-squareful-arrays/", "examples": [{"input": "nums = [1,17,8]", "output": "2", "explanation": "The squareful orderings are [1,8,17] and [17,8,1]."}, {"input": "nums = [2,2,2]", "output": "1", "explanation": "Only [2,2,2] exists, and 2 + 2 = 4 is a perfect square."}], "hints": ["Build the permutation one slot at a time, only placing a value whose sum with the previous one is a perfect square.", "Sort first and skip a repeated value unless its previous twin is already used, so identical permutations are counted once.", "Adaptation: the input is a plain int_array and the answer is the count of distinct squareful orderings."], "statement": "A non-negative integer is a perfect square when some integer multiplied by\nitself equals it (for example, `1`, `4`, `9` and `16` are perfect squares).\n\nAn array is squareful when every pair of adjacent elements adds up to a\nperfect square.\n\nGiven an integer array `nums`, return how many distinct permutations of its\nelements are squareful. Permutations that look identical because of repeated\nvalues are counted once.\n\n**Constraints:**\n- `1 <= nums.length <= 12`\n- `0 <= nums[i] <= 10^9`\n", "solution": "## Approach\n\nSort the numbers so equal values sit together, then grow permutations one\nposition at a time with depth-first search. A candidate is only placed when it\nforms a perfect square with the previously placed value (checked via an\ninteger square root). To avoid counting the same ordering twice, a repeated\nvalue is skipped whenever its previous twin has not been used yet. Every\ncomplete placement is one distinct squareful permutation.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * n!) in the worst case, where n is the length of `nums` (at most 12). Pruning by the square condition cuts this down sharply in practice.\n- **Space Complexity:** O(n) for the recursion stack, the used flags, and the sorted copy.\n\n## Implementation\n\n```python\nfrom typing import List\nimport math\nclass Solution:\n def numSquarefulPerms(self, nums: List[int]) -> int:\n nums = sorted(nums)\n used = [False] * len(nums)\n\n def is_square(s):\n r = math.isqrt(s)\n return r * r == s\n\n def dfs(prev, placed):\n if placed == len(nums):\n return 1\n total = 0\n for i in range(len(nums)):\n if used[i]:\n continue\n if i > 0 and nums[i] == nums[i - 1] and not used[i - 1]:\n continue\n if prev != -1 and not is_square(prev + nums[i]):\n continue\n used[i] = True\n total += dfs(nums[i], placed + 1)\n used[i] = False\n return total\n\n return dfs(-1, 0)\n```\n", "starter": {"go": "package main\n\nfunc NumSquarefulPerms(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def numSquarefulPerms(self, nums: List[int]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int numSquarefulPerms(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "numSquarefulPerms", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,17,8]"], ["[2,2,2]"], ["[1,1,8,1,8]"], ["[1]"], ["[2]"], ["[1,2]"], ["[1,8]"], ["[8,8]"], ["[0,0]"], ["[1,1]"], ["[1,1,1]"], ["[0,0,0]"], ["[1,8,17]"], ["[2,2,3]"], ["[1,3,5]"], ["[1,3,6]"], ["[3,6,1]"], ["[4,4,4,4]"], ["[1,15,8]"], ["[7,7,2]"], ["[2,7,7]"], ["[0,1]"], ["[0,2]"], ["[3,1,8]"], ["[5,5,11]"], ["[1,24,25]"], ["[8,1,15]"], ["[2,2,2,2]"]], "expected": [2, 1, 1, 1, 1, 0, 2, 1, 1, 0, 0, 1, 2, 0, 0, 2, 2, 0, 2, 1, 1, 2, 0, 2, 1, 2, 2, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "793", "slug": "number-of-subarrays-with-bounded-maximum", "id": 793, "title": "Number of Subarrays with Bounded Maximum", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum/", "examples": [{"input": "nums = [2,1,4,3], left = 2, right = 3", "output": "3", "explanation": "Only [2], [2,1] and [3] have maximum in [2,3]."}, {"input": "nums = [2,9,2,5,6], left = 2, right = 8", "output": "7", "explanation": "Seven subarrays stay within the upper bound and reach at least 2."}, {"input": "nums = [1,1,1], left = 1, right = 1", "output": "6", "explanation": "All 6 subarrays qualify."}], "hints": ["Count subarrays whose maximum does not exceed a cap: scan once, extending the current run while values stay within the cap.", "The answer for [left,right] equals count(max <= right) minus count(max <= left - 1).", "Each position ending a valid run adds the length of that run to the total."], "statement": "You receive an integer array `nums` and two bounds `left` and `right` with `left <= right`. A contiguous segment of the array is called suitable when the largest value inside it lies between `left` and `right` inclusive.\n\nCount how many non-empty contiguous subarrays are suitable.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `0 <= nums[i] <= 10^9`\n- `0 <= left <= right <= 10^9`\n", "solution": "## Approach\n\nFor any cap, the number of subarrays with all values at most the cap is found in one pass by extending the current valid run. Subtracting the count for `left - 1` from the count for `right` leaves exactly those subarrays whose maximum reaches `left` yet never exceeds `right`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), two linear scans over `nums`.\n- **Space Complexity:** O(1), only counters are kept.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n def capped(cap: int) -> int:\n ans = cur = 0\n for v in nums:\n if v <= cap:\n cur += 1\n ans += cur\n else:\n cur = 0\n return ans\n return capped(right) - capped(left - 1)\n```\n", "starter": {"go": "package main\n\nfunc NumSubarrayBoundedMax(nums []int, left int, right int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def numSubarrayBoundedMax(self, nums: List[int], left: int, right: int) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int numSubarrayBoundedMax(vector<int>& nums, int left, int right) {\n return 0;\n }\n};"}, "fn": "numSubarrayBoundedMax", "params": [{"name": "nums", "type": "int_array"}, {"name": "left", "type": "int"}, {"name": "right", "type": "int"}], "outputType": "int", "tests": [["[2, 1, 4, 3]", "2", "3"], ["[2, 9, 2, 5, 6]", "2", "8"], ["[1, 1, 1]", "1", "1"], ["[1]", "1", "1"], ["[1]", "2", "3"], ["[5]", "1", "4"], ["[3, 3, 3]", "3", "3"], ["[1, 2, 3]", "2", "3"], ["[3, 2, 1]", "1", "2"], ["[0, 0, 0]", "0", "0"], ["[10, 20, 30]", "15", "25"], ["[2, 1, 4, 3, 5]", "2", "4"], ["[1, 2, 3, 4, 5]", "1", "5"], ["[5, 4, 3, 2, 1]", "5", "5"], ["[1, 3, 2, 4, 0]", "2", "3"], ["[1000000000]", "0", "1000000000"], ["[0]", "1", "2"], ["[2, 2, 2, 2]", "2", "2"], ["[1, 2, 1, 2, 1]", "2", "2"], ["[4, 1, 2, 3]", "2", "3"], ["[9, 9, 9]", "1", "8"], ["[1, 2, 3, 4]", "5", "10"], ["[7, 7, 7, 7, 7]", "7", "7"], ["[1, 2, 3, 2, 1]", "2", "2"], ["[0, 1, 0, 1, 0]", "1", "1"], ["[5, 1, 5, 1, 5]", "5", "5"], ["[2, 9, 2, 5, 6, 1, 3]", "2", "6"], ["[8, 7, 6, 5, 4, 3, 2, 1]", "3", "6"]], "expected": [3, 7, 6, 1, 0, 0, 6, 5, 3, 6, 2, 9, 15, 5, 5, 1, 0, 10, 12, 5, 0, 0, 15, 4, 12, 13, 15, 18], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "891", "slug": "numbers-at-most-n-given-digit-set", "id": 891, "title": "Numbers At Most N Given Digit Set", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/numbers-at-most-n-given-digit-set/", "examples": [{"input": "digits = [\"1\",\"3\",\"5\",\"7\"], n = 100", "output": "20", "explanation": "4 one-digit plus 16 two-digit builds."}, {"input": "digits = [\"1\",\"4\",\"9\"], n = 1000000000", "output": "29523", "explanation": "Counts builds by length then by prefix."}, {"input": "digits = [\"7\"], n = 8", "output": "1", "explanation": "Only 7 fits."}], "hints": ["First add every build whose digit count is strictly shorter than that of n: sum of D^len.", "Then walk the decimal writing of n left to right, at each spot counting choices with a smaller stamp digit times D^(remaining spots).", "If every digit of n belongs to the set, include n itself as one extra."], "statement": "You own a stamp set holding single non-zero digits, for instance `[\"1\",\"3\",\"5\"]`. By pressing stamps any number of times (repeats allowed) you can compose positive integers such as `13`, `551` or `1351315`; the order of stamps is the order of digits.\n\nGiven the sorted unique digit list `digits` and a ceiling `n`, tally how many distinct stamp-built numbers are less than or equal to `n`.\n\n**Constraints:**\n- `1 <= digits.length <= 9`\n- `digits[i].length == 1`\n- Each entry is a digit from `'1'` to `'9'`, all distinct, sorted increasingly.\n- `1 <= n <= 10^9`\n", "solution": "## Approach\n\nSplit the tally by length. Every length shorter than the ceiling contributes `D^len` builds. For the same length as `n`, scan its decimal digits left to right: at position `i`, each stamp smaller than the ceiling's digit opens `D^(remaining)` completions for the suffix. If the whole ceiling digit-string can be spelled with stamps, count the ceiling itself as well.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(L * D) with L at most 10 digits and D at most 9.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def atMostNGivenDigitSet(self, digits: List[str], n: int) -> int:\n s = str(n)\n L, D = len(s), len(digits)\n ans = sum(D ** k for k in range(1, L))\n for i, ch in enumerate(s):\n same = False\n for d in digits:\n if d < ch:\n ans += D ** (L - 1 - i)\n elif d == ch:\n same = True\n if not same:\n return ans\n return ans + 1\n```\n", "starter": {"go": "package main\n\nfunc AtMostNGivenDigitSet(digits []string, n int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def atMostNGivenDigitSet(self, digits: List[str], n: int) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int atMostNGivenDigitSet(vector<string>& digits, int n) {\n return 0;\n }\n};"}, "fn": "atMostNGivenDigitSet", "params": [{"name": "digits", "type": "string_array"}, {"name": "n", "type": "int"}], "outputType": "int", "tests": [["['1', '3', '5', '7']", "100"], ["['1', '4', '9']", "1000000000"], ["['7']", "8"], ["['1']", "1"], ["['1']", "2"], ["['2']", "1"], ["['1', '2', '3']", "10"], ["['1', '2', '3']", "100"], ["['5', '6', '7']", "55"], ["['1', '3', '5', '7', '9']", "1000"], ["['1', '2']", "100"], ["['3']", "30"], ["['1', '9']", "91"], ["['1', '2', '9']", "1000"], ["['1', '2', '3', '4', '5', '6', '7', '8', '9']", "100"], ["['1', '2', '3', '4', '5', '6', '7', '8', '9']", "1000000000"], ["['9']", "100"], ["['1']", "1000000000"], ["['2', '4', '6', '8']", "888"], ["['1', '5']", "55"], ["['3', '5', '7']", "75"], ["['1', '2', '5']", "521"], ["['4']", "3"], ["['1', '3']", "13"], ["['2', '3', '5', '7']", "100"], ["['1', '7']", "71"], ["['5']", "5"], ["['1', '2', '3']", "321"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "953", "slug": "numbers-with-same-consecutive-differences", "id": 953, "title": "Numbers With Same Consecutive Differences", "difficulty": "Medium", "category": "backtracking", "link": "https://leetcode.com/problems/numbers-with-same-consecutive-differences/", "examples": [{"input": "n = 3, k = 7", "output": "[181,292,707,818,929]", "explanation": "Only 181, 292, 707, 818 and 929 have every neighbouring digit pair differ by 7."}, {"input": "n = 2, k = 1", "output": "[10,12,21,23,32,34,43,45,54,56,65,67,76,78,87,89,98]", "explanation": "Sixteen two-digit numbers step by exactly 1 between their digits, from 10 up to 98."}, {"input": "n = 2, k = 0", "output": "[11,22,33,44,55,66,77,88,99]", "explanation": "Both digits must match, giving the nine repdigits 11 through 99."}], "hints": ["Extend each prefix only with last-digit plus/minus k, guarded to stay within 0..9.", "When k is 0 the two extensions coincide \u2014 deduplicate to avoid double counting.", "Handle single-digit answers (0 through 9) as a special case."], "statement": "List every non-negative integer with exactly `n` digits (no leading zeros, except that `0` itself counts as the single one-digit number) in which the absolute difference between every two consecutive digits equals `k`. Return the qualifying numbers in increasing order as an integer list.\n\n**Constraints:**\n- `1 <= n <= 9`\n- `0 <= k <= 9`\n- The answers form an integer list.\n", "solution": "## Approach\n\nGrow numbers digit by digit: from each prefix, the next digit is forced to be `last + k` or `last - k` whenever those stay inside 0..9 (a single choice when k is 0). Start from every leading digit 1..9 \u2014 plus all of 0..9 when n is 1 \u2014 and collect each completed length-n number, then sort. The digit graph is tiny, so plain depth-first search enumerates everything.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(9 * 2^n) bounded enumeration, at most a few thousand numbers.\n- **Space Complexity:** O(answer size) plus recursion depth n.\n\n## Implementation\n\n```python\nclass Solution:\n def numsSameConsecDiff(self, n: int, k: int) -> list[int]:\n if n == 1:\n return list(range(10))\n res = []\n\n def dfs(cur, length):\n if length == n:\n res.append(cur)\n return\n last = cur % 10\n nxt = set()\n if last + k <= 9:\n nxt.add(last + k)\n if last - k >= 0:\n nxt.add(last - k)\n for d in sorted(nxt):\n dfs(cur * 10 + d, length + 1)\n\n for start in range(1, 10):\n dfs(start, 1)\n return sorted(res)\n```\n", "starter": {"go": "package main\n\nfunc NumsSameConsecDiff(n int, k int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def numsSameConsecDiff(self, n: int, k: int) -> List[int]:\n return []", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> numsSameConsecDiff(int n, int k) {\n return {};\n }\n};"}, "fn": "numsSameConsecDiff", "params": [{"name": "n", "type": "int"}, {"name": "k", "type": "int"}], "outputType": "int_list", "tests": [["3", "7"], ["2", "1"], ["2", "0"], ["1", "0"], ["1", "5"], ["3", "0"], ["2", "9"], ["3", "1"], ["4", "2"], ["2", "2"], ["3", "3"], ["4", "0"], ["5", "1"], ["2", "3"], ["3", "2"], ["4", "5"], ["2", "4"], ["3", "4"], ["2", "5"], ["3", "5"], ["2", "6"], ["3", "6"], ["2", "7"], ["3", "8"], ["2", "8"], ["3", "9"], ["1", "9"], ["9", "1"]], "expected": [[181, 292, 707, 818, 929], [10, 12, 21, 23, 32, 34, 43, 45, 54, 56, 65, 67, 76, 78, 87, 89, 98], [11, 22, 33, 44, 55, 66, 77, 88, 99], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [111, 222, 333, 444, 555, 666, 777, 888, 999], [90], [101, 121, 123, 210, 212, 232, 234, 321, 323, 343, 345, 432, 434, 454, 456, 543, 545, 565, 567, 654, 656, 676, 678, 765, 767, 787, 789, 876, 878, 898, 987, 989], [1313, 1353, 1357, 2020, 2024, 2420, 2424, 2464, 2468, 3131, 3135, 3531, 3535, 3575, 3579, 4202, 4242, 4246, 4642, 4646, 4686, 5313, 5353, 5357, 5753, 5757, 5797, 6420, 6424, 6464, 6468, 6864, 6868, 7531, 7535, 7575, 7579, 7975, 7979, 8642, 8646, 8686, 9753, 9757, 9797], [13, 20, 24, 31, 35, 42, 46, 53, 57, 64, 68, 75, 79, 86, 97], [141, 147, 252, 258, 303, 363, 369, 414, 474, 525, 585, 630, 636, 696, 741, 747, 852, 858, 963, 969], [1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999], [10101, 10121, 10123, 12101, 12121, 12123, 12321, 12323, 12343, 12345, 21010, 21012, 21210, 21212, 21232, 21234, 23210, 23212, 23232, 23234, 23432, 23434, 23454, 23456, 32101, 32121, 32123, 32321, 32323, 32343, 32345, 34321, 34323, 34343, 34345, 34543, 34545, 34565, 34567, 43210, 43212, 43232, 43234, 43432, 43434, 43454, 43456, 45432, 45434, 45454, 45456, 45654, 45656, 45676, 45678, 54321, 54323, 54343, 54345, 54543, 54545, 54565, 54567, 56543, 56545, 56565, 56567, 56765, 56767, 56787, 56789, 65432, 65434, 65454, 65456, 65654, 65656, 65676, 65678, 67654, 67656, 67676, 67678, 67876, 67878, 67898, 76543, 76545, 76565, 76567, 76765, 76767, 76787, 76789, 78765, 78767, 78787, 78789, 78987, 78989, 87654, 87656, 87676, 87678, 87876, 87878, 87898, 89876, 89878, 89898, 98765, 98767, 98787, 98789, 98987, 98989], [14, 25, 30, 36, 41, 47, 52, 58, 63, 69, 74, 85, 96], [131, 135, 202, 242, 246, 313, 353, 357, 420, 424, 464, 468, 531, 535, 575, 579, 642, 646, 686, 753, 757, 797, 864, 868, 975, 979], [1616, 2727, 3838, 4949, 5050, 6161, 7272, 8383, 9494], [15, 26, 37, 40, 48, 51, 59, 62, 73, 84, 95], [151, 159, 262, 373, 404, 484, 515, 595, 626, 737, 840, 848, 951, 959], [16, 27, 38, 49, 50, 61, 72, 83, 94], [161, 272, 383, 494, 505, 616, 727, 838, 949], [17, 28, 39, 60, 71, 82, 93], [171, 282, 393, 606, 717, 828, 939], [18, 29, 70, 81, 92], [191, 808, 919], [19, 80, 91], [909], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [101010101, 101010121, 101010123, 101012101, 101012121, 101012123, 101012321, 101012323, 101012343, 101012345, 101210101, 101210121, 101210123, 101212101, 101212121, 101212123, 101212321, 101212323, 101212343, 101212345, 101232101, 101232121, 101232123, 101232321, 101232323, 101232343, 101232345, 101234321, 101234323, 101234343, 101234345, 101234543, 101234545, 101234565, 101234567, 121010101, 121010121, 121010123, 121012101, 121012121, 121012123, 121012321, 121012323, 121012343, 121012345, 121210101, 121210121, 121210123, 121212101, 121212121, 121212123, 121212321, 121212323, 121212343, 121212345, 121232101, 121232121, 121232123, 121232321, 121232323, 121232343, 121232345, 121234321, 121234323, 121234343, 121234345, 121234543, 121234545, 121234565, 121234567, 123210101, 123210121, 123210123, 123212101, 123212121, 123212123, 123212321, 123212323, 123212343, 123212345, 123232101, 123232121, 123232123, 123232321, 123232323, 123232343, 123232345, 123234321, 123234323, 123234343, 123234345, 123234543, 123234545, 123234565, 123234567, 123432101, 123432121, 123432123, 123432321, 123432323, 123432343, 123432345, 123434321, 123434323, 123434343, 123434345, 123434543, 123434545, 123434565, 123434567, 123454321, 123454323, 123454343, 123454345, 123454543, 123454545, 123454565, 123454567, 123456543, 123456545, 123456565, 123456567, 123456765, 123456767, 123456787, 123456789, 210101010, 210101012, 210101210, 210101212, 210101232, 210101234, 210121010, 210121012, 210121210, 210121212, 210121232, 210121234, 210123210, 210123212, 210123232, 210123234, 210123432, 210123434, 210123454, 210123456, 212101010, 212101012, 212101210, 212101212, 212101232, 212101234, 212121010, 212121012, 212121210, 212121212, 212121232, 212121234, 212123210, 212123212, 212123232, 212123234, 212123432, 212123434, 212123454, 212123456, 212321010, 212321012, 212321210, 212321212, 212321232, 212321234, 212323210, 212323212, 212323232, 212323234, 212323432, 212323434, 212323454, 212323456, 212343210, 212343212, 212343232, 212343234, 212343432, 212343434, 212343454, 212343456, 212345432, 212345434, 212345454, 212345456, 212345654, 212345656, 212345676, 212345678, 232101010, 232101012, 232101210, 232101212, 232101232, 232101234, 232121010, 232121012, 232121210, 232121212, 232121232, 232121234, 232123210, 232123212, 232123232, 232123234, 232123432, 232123434, 232123454, 232123456, 232321010, 232321012, 232321210, 232321212, 232321232, 232321234, 232323210, 232323212, 232323232, 232323234, 232323432, 232323434, 232323454, 232323456, 232343210, 232343212, 232343232, 232343234, 232343432, 232343434, 232343454, 232343456, 232345432, 232345434, 232345454, 232345456, 232345654, 232345656, 232345676, 232345678, 234321010, 234321012, 234321210, 234321212, 234321232, 234321234, 234323210, 234323212, 234323232, 234323234, 234323432, 234323434, 234323454, 234323456, 234343210, 234343212, 234343232, 234343234, 234343432, 234343434, 234343454, 234343456, 234345432, 234345434, 234345454, 234345456, 234345654, 234345656, 234345676, 234345678, 234543210, 234543212, 234543232, 234543234, 234543432, 234543434, 234543454, 234543456, 234545432, 234545434, 234545454, 234545456, 234545654, 234545656, 234545676, 234545678, 234565432, 234565434, 234565454, 234565456, 234565654, 234565656, 234565676, 234565678, 234567654, 234567656, 234567676, 234567678, 234567876, 234567878, 234567898, 321010101, 321010121, 321010123, 321012101, 321012121, 321012123, 321012321, 321012323, 321012343, 321012345, 321210101, 321210121, 321210123, 321212101, 321212121, 321212123, 321212321, 321212323, 321212343, 321212345, 321232101, 321232121, 321232123, 321232321, 321232323, 321232343, 321232345, 321234321, 321234323, 321234343, 321234345, 321234543, 321234545, 321234565, 321234567, 323210101, 323210121, 323210123, 323212101, 323212121, 323212123, 323212321, 323212323, 323212343, 323212345, 323232101, 323232121, 323232123, 323232321, 323232323, 323232343, 323232345, 323234321, 323234323, 323234343, 323234345, 323234543, 323234545, 323234565, 323234567, 323432101, 323432121, 323432123, 323432321, 323432323, 323432343, 323432345, 323434321, 323434323, 323434343, 323434345, 323434543, 323434545, 323434565, 323434567, 323454321, 323454323, 323454343, 323454345, 323454543, 323454545, 323454565, 323454567, 323456543, 323456545, 323456565, 323456567, 323456765, 323456767, 323456787, 323456789, 343210101, 343210121, 343210123, 343212101, 343212121, 343212123, 343212321, 343212323, 343212343, 343212345, 343232101, 343232121, 343232123, 343232321, 343232323, 343232343, 343232345, 343234321, 343234323, 343234343, 343234345, 343234543, 343234545, 343234565, 343234567, 343432101, 343432121, 343432123, 343432321, 343432323, 343432343, 343432345, 343434321, 343434323, 343434343, 343434345, 343434543, 343434545, 343434565, 343434567, 343454321, 343454323, 343454343, 343454345, 343454543, 343454545, 343454565, 343454567, 343456543, 343456545, 343456565, 343456567, 343456765, 343456767, 343456787, 343456789, 345432101, 345432121, 345432123, 345432321, 345432323, 345432343, 345432345, 345434321, 345434323, 345434343, 345434345, 345434543, 345434545, 345434565, 345434567, 345454321, 345454323, 345454343, 345454345, 345454543, 345454545, 345454565, 345454567, 345456543, 345456545, 345456565, 345456567, 345456765, 345456767, 345456787, 345456789, 345654321, 345654323, 345654343, 345654345, 345654543, 345654545, 345654565, 345654567, 345656543, 345656545, 345656565, 345656567, 345656765, 345656767, 345656787, 345656789, 345676543, 345676545, 345676565, 345676567, 345676765, 345676767, 345676787, 345676789, 345678765, 345678767, 345678787, 345678789, 345678987, 345678989, 432101010, 432101012, 432101210, 432101212, 432101232, 432101234, 432121010, 432121012, 432121210, 432121212, 432121232, 432121234, 432123210, 432123212, 432123232, 432123234, 432123432, 432123434, 432123454, 432123456, 432321010, 432321012, 432321210, 432321212, 432321232, 432321234, 432323210, 432323212, 432323232, 432323234, 432323432, 432323434, 432323454, 432323456, 432343210, 432343212, 432343232, 432343234, 432343432, 432343434, 432343454, 432343456, 432345432, 432345434, 432345454, 432345456, 432345654, 432345656, 432345676, 432345678, 434321010, 434321012, 434321210, 434321212, 434321232, 434321234, 434323210, 434323212, 434323232, 434323234, 434323432, 434323434, 434323454, 434323456, 434343210, 434343212, 434343232, 434343234, 434343432, 434343434, 434343454, 434343456, 434345432, 434345434, 434345454, 434345456, 434345654, 434345656, 434345676, 434345678, 434543210, 434543212, 434543232, 434543234, 434543432, 434543434, 434543454, 434543456, 434545432, 434545434, 434545454, 434545456, 434545654, 434545656, 434545676, 434545678, 434565432, 434565434, 434565454, 434565456, 434565654, 434565656, 434565676, 434565678, 434567654, 434567656, 434567676, 434567678, 434567876, 434567878, 434567898, 454321010, 454321012, 454321210, 454321212, 454321232, 454321234, 454323210, 454323212, 454323232, 454323234, 454323432, 454323434, 454323454, 454323456, 454343210, 454343212, 454343232, 454343234, 454343432, 454343434, 454343454, 454343456, 454345432, 454345434, 454345454, 454345456, 454345654, 454345656, 454345676, 454345678, 454543210, 454543212, 454543232, 454543234, 454543432, 454543434, 454543454, 454543456, 454545432, 454545434, 454545454, 454545456, 454545654, 454545656, 454545676, 454545678, 454565432, 454565434, 454565454, 454565456, 454565654, 454565656, 454565676, 454565678, 454567654, 454567656, 454567676, 454567678, 454567876, 454567878, 454567898, 456543210, 456543212, 456543232, 456543234, 456543432, 456543434, 456543454, 456543456, 456545432, 456545434, 456545454, 456545456, 456545654, 456545656, 456545676, 456545678, 456565432, 456565434, 456565454, 456565456, 456565654, 456565656, 456565676, 456565678, 456567654, 456567656, 456567676, 456567678, 456567876, 456567878, 456567898, 456765432, 456765434, 456765454, 456765456, 456765654, 456765656, 456765676, 456765678, 456767654, 456767656, 456767676, 456767678, 456767876, 456767878, 456767898, 456787654, 456787656, 456787676, 456787678, 456787876, 456787878, 456787898, 456789876, 456789878, 456789898, 543210101, 543210121, 543210123, 543212101, 543212121, 543212123, 543212321, 543212323, 543212343, 543212345, 543232101, 543232121, 543232123, 543232321, 543232323, 543232343, 543232345, 543234321, 543234323, 543234343, 543234345, 543234543, 543234545, 543234565, 543234567, 543432101, 543432121, 543432123, 543432321, 543432323, 543432343, 543432345, 543434321, 543434323, 543434343, 543434345, 543434543, 543434545, 543434565, 543434567, 543454321, 543454323, 543454343, 543454345, 543454543, 543454545, 543454565, 543454567, 543456543, 543456545, 543456565, 543456567, 543456765, 543456767, 543456787, 543456789, 545432101, 545432121, 545432123, 545432321, 545432323, 545432343, 545432345, 545434321, 545434323, 545434343, 545434345, 545434543, 545434545, 545434565, 545434567, 545454321, 545454323, 545454343, 545454345, 545454543, 545454545, 545454565, 545454567, 545456543, 545456545, 545456565, 545456567, 545456765, 545456767, 545456787, 545456789, 545654321, 545654323, 545654343, 545654345, 545654543, 545654545, 545654565, 545654567, 545656543, 545656545, 545656565, 545656567, 545656765, 545656767, 545656787, 545656789, 545676543, 545676545, 545676565, 545676567, 545676765, 545676767, 545676787, 545676789, 545678765, 545678767, 545678787, 545678789, 545678987, 545678989, 565432101, 565432121, 565432123, 565432321, 565432323, 565432343, 565432345, 565434321, 565434323, 565434343, 565434345, 565434543, 565434545, 565434565, 565434567, 565454321, 565454323, 565454343, 565454345, 565454543, 565454545, 565454565, 565454567, 565456543, 565456545, 565456565, 565456567, 565456765, 565456767, 565456787, 565456789, 565654321, 565654323, 565654343, 565654345, 565654543, 565654545, 565654565, 565654567, 565656543, 565656545, 565656565, 565656567, 565656765, 565656767, 565656787, 565656789, 565676543, 565676545, 565676565, 565676567, 565676765, 565676767, 565676787, 565676789, 565678765, 565678767, 565678787, 565678789, 565678987, 565678989, 567654321, 567654323, 567654343, 567654345, 567654543, 567654545, 567654565, 567654567, 567656543, 567656545, 567656565, 567656567, 567656765, 567656767, 567656787, 567656789, 567676543, 567676545, 567676565, 567676567, 567676765, 567676767, 567676787, 567676789, 567678765, 567678767, 567678787, 567678789, 567678987, 567678989, 567876543, 567876545, 567876565, 567876567, 567876765, 567876767, 567876787, 567876789, 567878765, 567878767, 567878787, 567878789, 567878987, 567878989, 567898765, 567898767, 567898787, 567898789, 567898987, 567898989, 654321010, 654321012, 654321210, 654321212, 654321232, 654321234, 654323210, 654323212, 654323232, 654323234, 654323432, 654323434, 654323454, 654323456, 654343210, 654343212, 654343232, 654343234, 654343432, 654343434, 654343454, 654343456, 654345432, 654345434, 654345454, 654345456, 654345654, 654345656, 654345676, 654345678, 654543210, 654543212, 654543232, 654543234, 654543432, 654543434, 654543454, 654543456, 654545432, 654545434, 654545454, 654545456, 654545654, 654545656, 654545676, 654545678, 654565432, 654565434, 654565454, 654565456, 654565654, 654565656, 654565676, 654565678, 654567654, 654567656, 654567676, 654567678, 654567876, 654567878, 654567898, 656543210, 656543212, 656543232, 656543234, 656543432, 656543434, 656543454, 656543456, 656545432, 656545434, 656545454, 656545456, 656545654, 656545656, 656545676, 656545678, 656565432, 656565434, 656565454, 656565456, 656565654, 656565656, 656565676, 656565678, 656567654, 656567656, 656567676, 656567678, 656567876, 656567878, 656567898, 656765432, 656765434, 656765454, 656765456, 656765654, 656765656, 656765676, 656765678, 656767654, 656767656, 656767676, 656767678, 656767876, 656767878, 656767898, 656787654, 656787656, 656787676, 656787678, 656787876, 656787878, 656787898, 656789876, 656789878, 656789898, 676543210, 676543212, 676543232, 676543234, 676543432, 676543434, 676543454, 676543456, 676545432, 676545434, 676545454, 676545456, 676545654, 676545656, 676545676, 676545678, 676565432, 676565434, 676565454, 676565456, 676565654, 676565656, 676565676, 676565678, 676567654, 676567656, 676567676, 676567678, 676567876, 676567878, 676567898, 676765432, 676765434, 676765454, 676765456, 676765654, 676765656, 676765676, 676765678, 676767654, 676767656, 676767676, 676767678, 676767876, 676767878, 676767898, 676787654, 676787656, 676787676, 676787678, 676787876, 676787878, 676787898, 676789876, 676789878, 676789898, 678765432, 678765434, 678765454, 678765456, 678765654, 678765656, 678765676, 678765678, 678767654, 678767656, 678767676, 678767678, 678767876, 678767878, 678767898, 678787654, 678787656, 678787676, 678787678, 678787876, 678787878, 678787898, 678789876, 678789878, 678789898, 678987654, 678987656, 678987676, 678987678, 678987876, 678987878, 678987898, 678989876, 678989878, 678989898, 765432101, 765432121, 765432123, 765432321, 765432323, 765432343, 765432345, 765434321, 765434323, 765434343, 765434345, 765434543, 765434545, 765434565, 765434567, 765454321, 765454323, 765454343, 765454345, 765454543, 765454545, 765454565, 765454567, 765456543, 765456545, 765456565, 765456567, 765456765, 765456767, 765456787, 765456789, 765654321, 765654323, 765654343, 765654345, 765654543, 765654545, 765654565, 765654567, 765656543, 765656545, 765656565, 765656567, 765656765, 765656767, 765656787, 765656789, 765676543, 765676545, 765676565, 765676567, 765676765, 765676767, 765676787, 765676789, 765678765, 765678767, 765678787, 765678789, 765678987, 765678989, 767654321, 767654323, 767654343, 767654345, 767654543, 767654545, 767654565, 767654567, 767656543, 767656545, 767656565, 767656567, 767656765, 767656767, 767656787, 767656789, 767676543, 767676545, 767676565, 767676567, 767676765, 767676767, 767676787, 767676789, 767678765, 767678767, 767678787, 767678789, 767678987, 767678989, 767876543, 767876545, 767876565, 767876567, 767876765, 767876767, 767876787, 767876789, 767878765, 767878767, 767878787, 767878789, 767878987, 767878989, 767898765, 767898767, 767898787, 767898789, 767898987, 767898989, 787654321, 787654323, 787654343, 787654345, 787654543, 787654545, 787654565, 787654567, 787656543, 787656545, 787656565, 787656567, 787656765, 787656767, 787656787, 787656789, 787676543, 787676545, 787676565, 787676567, 787676765, 787676767, 787676787, 787676789, 787678765, 787678767, 787678787, 787678789, 787678987, 787678989, 787876543, 787876545, 787876565, 787876567, 787876765, 787876767, 787876787, 787876789, 787878765, 787878767, 787878787, 787878789, 787878987, 787878989, 787898765, 787898767, 787898787, 787898789, 787898987, 787898989, 789876543, 789876545, 789876565, 789876567, 789876765, 789876767, 789876787, 789876789, 789878765, 789878767, 789878787, 789878789, 789878987, 789878989, 789898765, 789898767, 789898787, 789898789, 789898987, 789898989, 876543210, 876543212, 876543232, 876543234, 876543432, 876543434, 876543454, 876543456, 876545432, 876545434, 876545454, 876545456, 876545654, 876545656, 876545676, 876545678, 876565432, 876565434, 876565454, 876565456, 876565654, 876565656, 876565676, 876565678, 876567654, 876567656, 876567676, 876567678, 876567876, 876567878, 876567898, 876765432, 876765434, 876765454, 876765456, 876765654, 876765656, 876765676, 876765678, 876767654, 876767656, 876767676, 876767678, 876767876, 876767878, 876767898, 876787654, 876787656, 876787676, 876787678, 876787876, 876787878, 876787898, 876789876, 876789878, 876789898, 878765432, 878765434, 878765454, 878765456, 878765654, 878765656, 878765676, 878765678, 878767654, 878767656, 878767676, 878767678, 878767876, 878767878, 878767898, 878787654, 878787656, 878787676, 878787678, 878787876, 878787878, 878787898, 878789876, 878789878, 878789898, 878987654, 878987656, 878987676, 878987678, 878987876, 878987878, 878987898, 878989876, 878989878, 878989898, 898765432, 898765434, 898765454, 898765456, 898765654, 898765656, 898765676, 898765678, 898767654, 898767656, 898767676, 898767678, 898767876, 898767878, 898767898, 898787654, 898787656, 898787676, 898787678, 898787876, 898787878, 898787898, 898789876, 898789878, 898789898, 898987654, 898987656, 898987676, 898987678, 898987876, 898987878, 898987898, 898989876, 898989878, 898989898, 987654321, 987654323, 987654343, 987654345, 987654543, 987654545, 987654565, 987654567, 987656543, 987656545, 987656565, 987656567, 987656765, 987656767, 987656787, 987656789, 987676543, 987676545, 987676565, 987676567, 987676765, 987676767, 987676787, 987676789, 987678765, 987678767, 987678787, 987678789, 987678987, 987678989, 987876543, 987876545, 987876565, 987876567, 987876765, 987876767, 987876787, 987876789, 987878765, 987878767, 987878787, 987878789, 987878987, 987878989, 987898765, 987898767, 987898787, 987898789, 987898987, 987898989, 989876543, 989876545, 989876565, 989876567, 989876765, 989876767, 989876787, 989876789, 989878765, 989878767, 989878787, 989878789, 989878987, 989878989, 989898765, 989898767, 989898787, 989898789, 989898987, 989898989]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "960", "slug": "odd-even-jump", "id": 960, "title": "Odd Even Jump", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/odd-even-jump/", "examples": [{"input": "arr = [10,13,12,14,15]", "output": "2", "explanation": "Starting at values 13 and 15 reaches the final index through alternating smallest-larger and largest-smaller hops."}, {"input": "arr = [2,3,1,1,4]", "output": "3", "explanation": "Three start positions can hop to the end under the odd/even rules."}, {"input": "arr = [5,1,3,4,2]", "output": "3", "explanation": "Three starts succeed; the others get stuck."}], "hints": ["Process positions from right to left while keeping an ordered map from value to nearest index on the right.", "For each position, the odd hop target is the ceiling entry and the even hop target is the floor entry in that map.", "Track two boolean tables (can reach the end on an odd turn / on an even turn) and propagate them through the hop targets."], "statement": "You stand on an array `arr`. From index `i` you make numbered jumps: jump 1, 3, 5, ... are odd-numbered and jumps 2, 4, 6, ... are even-numbered. The next jump starts counting at 1 again for each new starting index.\n\n- On an odd-numbered jump from `i`, hop to the smallest index `j > i` whose value is the smallest value `>= arr[i]`. If several positions share that value, pick the smallest index. If no such `j` exists, the walk stops.\n- On an even-numbered jump from `i`, hop to the smallest index `j > i` whose value is the largest value `<= arr[i]`, again breaking ties by smallest index. If none exists, the walk stops.\n\nA start index is good when the walk beginning with an odd jump eventually lands exactly on the last array index. Count the good starting indices.\n\n**Constraints:**\n- `1 <= arr.length <= 20000`\n- `1 <= arr[i] <= 100000`\n", "solution": "## Approach\n\nScan from right to left while storing, in an ordered map, each value seen on the right together with its nearest index. For position i the odd-hop destination is the ceiling value and the even-hop destination is the floor value. Two boolean arrays record whether the end is reachable when it is our turn to make an odd hop or an even hop; they are filled using the destinations found in the map. The last cell is trivially reachable, and every other cell whose odd state is true contributes one good start.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for n ordered-map operations.\n- **Space Complexity:** O(n) for the map and the two boolean arrays.\n\n## Implementation\n\n```python\nfrom typing import List\nimport bisect\nclass Solution:\n def oddEvenJumps(self, arr: List[int]) -> int:\n n = len(arr)\n if n == 0:\n return 0\n odd = [False] * n\n even = [False] * n\n odd[-1] = even[-1] = True\n vals = sorted(set(arr))\n # map value -> nearest index to the right; maintain sorted values + dict\n pos = {arr[-1]: n - 1}\n import bisect\n sorted_vals = sorted(pos.keys())\n ans = 1\n for i in range(n - 2, -1, -1):\n # ceiling\n j = bisect.bisect_left(sorted_vals, arr[i])\n if j < len(sorted_vals):\n odd[i] = even[pos[sorted_vals[j]]]\n j2 = bisect.bisect_right(sorted_vals, arr[i]) - 1\n if j2 >= 0:\n even[i] = odd[pos[sorted_vals[j2]]]\n if odd[i]:\n ans += 1\n if arr[i] not in pos:\n bisect.insort(sorted_vals, arr[i])\n pos[arr[i]] = i\n return ans\n```\n", "starter": {"go": "package main\n\nfunc OddEvenJumps(arr []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def oddEvenJumps(self, arr: List[int]) -> int:\n pass", "cpp": "#include <vector>\n#include <map>\nusing namespace std;\nclass Solution {\npublic:\n int oddEvenJumps(vector<int>& arr) {\n return 0;\n }\n};"}, "fn": "oddEvenJumps", "params": [{"name": "arr", "type": "int_array"}], "outputType": "int", "tests": [["[10,13,12,14,15]"], ["[2,3,1,1,4]"], ["[5,1,3,4,2]"], ["[1]"], ["[1,2]"], ["[2,1]"], ["[1,1,1,1]"], ["[4,3,2,1]"], ["[1,2,3,4]"], ["[3,3,3,3,3]"], ["[1,3,2]"], ["[2,1,2]"], ["[5,4,3,2,1,6]"], ["[1,10000,1,10000,1]"], ["[7,7,7,8,8,8]"], ["[10,1,10,1,10]"], ["[6,5,4,3,2,1]"], ["[1,2,1,2,1,2]"], ["[3,1,4,1,5,9,2,6]"], ["[100000,1,100000]"], ["[2,2,2,1,1,1]"], ["[1,4,3,2,5]"], ["[9,8,7,6,5,4,3,2,1,10]"], ["[1,2,3,2,1]"], ["[4,4,4,4,5]"], ["[5,1,4,2,3]"], ["[2,3,5,4,1]"], ["[11,12,13,14,15,16]"]], "expected": [2, 3, 3, 1, 2, 1, 4, 1, 2, 5, 2, 3, 6, 4, 5, 4, 1, 5, 5, 3, 4, 4, 10, 3, 3, 2, 3, 2], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "415", "slug": "odd-even-linked-list", "id": 415, "title": "Odd Even Linked List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/odd-even-linked-list/", "examples": [{"explanation": "Odd positions hold 1, 3, 5 and even positions hold 2, 4.", "input": "head = [1,2,3,4,5]", "output": "[1,3,5,2,4]"}, {"explanation": "Odd positions hold 2, 3, 6, 7 and even positions hold 1, 5, 4.", "input": "head = [2,1,3,5,6,4,7]", "output": "[2,3,6,7,1,5,4]"}, {"explanation": "An empty list reorders to itself.", "input": "head = []", "output": "[]"}], "hints": ["Split the chain with two pointers, one following odd positions and one following even positions.", "Link the tail of the odd chain to the head of the even chain at the end.", "Handle empty and single-node lists as trivial cases."], "statement": "You are given the head of a singly linked list. Positions are numbered starting from 1, so the first node is odd, the second is even, and so on. Rearrange the list so that all odd-positioned nodes come first, followed by all even-positioned nodes, keeping the original relative order inside each group. Return the head of the reordered list.\n\nDo this in linear time using only a constant amount of extra space (apart from rewiring pointers).\n\n**Constraints:**\n- The number of nodes lies in `[0, 10^4]`.\n- `-10^6 <= Node.val <= 10^6`\n", "solution": "## Approach\n\nWalk the list with two cursors: one chaining the odd-positioned nodes and one chaining the even-positioned nodes. Each step links each cursor to the node after its successor. Finally attach the even chain behind the odd chain's tail.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited once.\n- **Space Complexity:** O(1) extra space; only pointers are rewired.\n\n## Implementation\n\n```python\nfrom typing import Optional\nclass Solution:\n def oddEvenList(self, head: Optional[ListNode]) -> Optional[ListNode]:\n if not head or not head.next:\n return head\n odd, even = head, head.next\n even_head = even\n while even and even.next:\n odd.next = even.next\n odd = odd.next\n even.next = odd.next\n even = even.next\n odd.next = even_head\n return head\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc OddEvenList(head *ListNode) *ListNode {\n \n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def oddEvenList(self, head):\n # TODO: regroup odd/even positions and return new head\n pass\n", "cpp": "/*\nDefinition for singly-linked list.\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* oddEvenList(ListNode* head) {\n \n }\n};"}, "fn": "oddEvenList", "params": [{"name": "head", "type": "list_node"}], "outputType": "list_node", "tests": [["[1,2,3,4,5]"], ["[2,1,3,5,6,4,7]"], ["[]"], ["[1]"], ["[1,2]"], ["[1,2,3]"], ["[1,2,3,4]"], ["[1,1,1,1]"], ["[5,4,3,2,1]"], ["[0]"], ["[-1,0,1]"], ["[1,2,3,4,5,6]"], ["[1,2,3,4,5,6,7,8]"], ["[10,20,30,40,50,60,70,80,90,100]"], ["[7,7,7,7,7,7,7]"], ["[1000000,-1000000,0,5,-5]"], ["[3,1,4,1,5,9,2,6]"], ["[9,8,7,6,5,4,3,2,1,0]"], ["[2,1]"], ["[1,3,2]"], ["[4,4,4,5,5,5]"], ["[1,2,3,4,5,6,7,8,9,10,11]"], ["[-5,-4,-3,-2,-1]"], ["[42]"], ["[1,-1,1,-1,1,-1]"], ["@javascript:JSON.stringify(Array.from({length:2000}, (_, i) => i + 1))"], ["@javascript:JSON.stringify(Array(1500).fill(7))"], ["[5,1,4,2,3]"], ["[6,5,4,3,2,1]"], ["[0,0,0,1,1,1]"]], "expected": [[1, 3, 5, 2, 4], [2, 3, 6, 7, 1, 5, 4], null, [1], [1, 2], [1, 3, 2], [1, 3, 2, 4], [1, 1, 1, 1], [5, 3, 1, 4, 2], [0], [-1, 1, 0], [1, 3, 5, 2, 4, 6], [1, 3, 5, 7, 2, 4, 6, 8], [10, 30, 50, 70, 90, 20, 40, 60, 80, 100], [7, 7, 7, 7, 7, 7, 7], [1000000, 0, -5, -1000000, 5], [3, 4, 5, 2, 1, 1, 9, 6], [9, 7, 5, 3, 1, 8, 6, 4, 2, 0], [2, 1], [1, 2, 3], [4, 4, 5, 4, 5, 5], [1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10], [-5, -3, -1, -4, -2], [42], [1, 1, 1, -1, -1, -1], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 285, 287, 289, 291, 293, 295, 297, 299, 301, 303, 305, 307, 309, 311, 313, 315, 317, 319, 321, 323, 325, 327, 329, 331, 333, 335, 337, 339, 341, 343, 345, 347, 349, 351, 353, 355, 357, 359, 361, 363, 365, 367, 369, 371, 373, 375, 377, 379, 381, 383, 385, 387, 389, 391, 393, 395, 397, 399, 401, 403, 405, 407, 409, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 469, 471, 473, 475, 477, 479, 481, 483, 485, 487, 489, 491, 493, 495, 497, 499, 501, 503, 505, 507, 509, 511, 513, 515, 517, 519, 521, 523, 525, 527, 529, 531, 533, 535, 537, 539, 541, 543, 545, 547, 549, 551, 553, 555, 557, 559, 561, 563, 565, 567, 569, 571, 573, 575, 577, 579, 581, 583, 585, 587, 589, 591, 593, 595, 597, 599, 601, 603, 605, 607, 609, 611, 613, 615, 617, 619, 621, 623, 625, 627, 629, 631, 633, 635, 637, 639, 641, 643, 645, 647, 649, 651, 653, 655, 657, 659, 661, 663, 665, 667, 669, 671, 673, 675, 677, 679, 681, 683, 685, 687, 689, 691, 693, 695, 697, 699, 701, 703, 705, 707, 709, 711, 713, 715, 717, 719, 721, 723, 725, 727, 729, 731, 733, 735, 737, 739, 741, 743, 745, 747, 749, 751, 753, 755, 757, 759, 761, 763, 765, 767, 769, 771, 773, 775, 777, 779, 781, 783, 785, 787, 789, 791, 793, 795, 797, 799, 801, 803, 805, 807, 809, 811, 813, 815, 817, 819, 821, 823, 825, 827, 829, 831, 833, 835, 837, 839, 841, 843, 845, 847, 849, 851, 853, 855, 857, 859, 861, 863, 865, 867, 869, 871, 873, 875, 877, 879, 881, 883, 885, 887, 889, 891, 893, 895, 897, 899, 901, 903, 905, 907, 909, 911, 913, 915, 917, 919, 921, 923, 925, 927, 929, 931, 933, 935, 937, 939, 941, 943, 945, 947, 949, 951, 953, 955, 957, 959, 961, 963, 965, 967, 969, 971, 973, 975, 977, 979, 981, 983, 985, 987, 989, 991, 993, 995, 997, 999, 1001, 1003, 1005, 1007, 1009, 1011, 1013, 1015, 1017, 1019, 1021, 1023, 1025, 1027, 1029, 1031, 1033, 1035, 1037, 1039, 1041, 1043, 1045, 1047, 1049, 1051, 1053, 1055, 1057, 1059, 1061, 1063, 1065, 1067, 1069, 1071, 1073, 1075, 1077, 1079, 1081, 1083, 1085, 1087, 1089, 1091, 1093, 1095, 1097, 1099, 1101, 1103, 1105, 1107, 1109, 1111, 1113, 1115, 1117, 1119, 1121, 1123, 1125, 1127, 1129, 1131, 1133, 1135, 1137, 1139, 1141, 1143, 1145, 1147, 1149, 1151, 1153, 1155, 1157, 1159, 1161, 1163, 1165, 1167, 1169, 1171, 1173, 1175, 1177, 1179, 1181, 1183, 1185, 1187, 1189, 1191, 1193, 1195, 1197, 1199, 1201, 1203, 1205, 1207, 1209, 1211, 1213, 1215, 1217, 1219, 1221, 1223, 1225, 1227, 1229, 1231, 1233, 1235, 1237, 1239, 1241, 1243, 1245, 1247, 1249, 1251, 1253, 1255, 1257, 1259, 1261, 1263, 1265, 1267, 1269, 1271, 1273, 1275, 1277, 1279, 1281, 1283, 1285, 1287, 1289, 1291, 1293, 1295, 1297, 1299, 1301, 1303, 1305, 1307, 1309, 1311, 1313, 1315, 1317, 1319, 1321, 1323, 1325, 1327, 1329, 1331, 1333, 1335, 1337, 1339, 1341, 1343, 1345, 1347, 1349, 1351, 1353, 1355, 1357, 1359, 1361, 1363, 1365, 1367, 1369, 1371, 1373, 1375, 1377, 1379, 1381, 1383, 1385, 1387, 1389, 1391, 1393, 1395, 1397, 1399, 1401, 1403, 1405, 1407, 1409, 1411, 1413, 1415, 1417, 1419, 1421, 1423, 1425, 1427, 1429, 1431, 1433, 1435, 1437, 1439, 1441, 1443, 1445, 1447, 1449, 1451, 1453, 1455, 1457, 1459, 1461, 1463, 1465, 1467, 1469, 1471, 1473, 1475, 1477, 1479, 1481, 1483, 1485, 1487, 1489, 1491, 1493, 1495, 1497, 1499, 1501, 1503, 1505, 1507, 1509, 1511, 1513, 1515, 1517, 1519, 1521, 1523, 1525, 1527, 1529, 1531, 1533, 1535, 1537, 1539, 1541, 1543, 1545, 1547, 1549, 1551, 1553, 1555, 1557, 1559, 1561, 1563, 1565, 1567, 1569, 1571, 1573, 1575, 1577, 1579, 1581, 1583, 1585, 1587, 1589, 1591, 1593, 1595, 1597, 1599, 1601, 1603, 1605, 1607, 1609, 1611, 1613, 1615, 1617, 1619, 1621, 1623, 1625, 1627, 1629, 1631, 1633, 1635, 1637, 1639, 1641, 1643, 1645, 1647, 1649, 1651, 1653, 1655, 1657, 1659, 1661, 1663, 1665, 1667, 1669, 1671, 1673, 1675, 1677, 1679, 1681, 1683, 1685, 1687, 1689, 1691, 1693, 1695, 1697, 1699, 1701, 1703, 1705, 1707, 1709, 1711, 1713, 1715, 1717, 1719, 1721, 1723, 1725, 1727, 1729, 1731, 1733, 1735, 1737, 1739, 1741, 1743, 1745, 1747, 1749, 1751, 1753, 1755, 1757, 1759, 1761, 1763, 1765, 1767, 1769, 1771, 1773, 1775, 1777, 1779, 1781, 1783, 1785, 1787, 1789, 1791, 1793, 1795, 1797, 1799, 1801, 1803, 1805, 1807, 1809, 1811, 1813, 1815, 1817, 1819, 1821, 1823, 1825, 1827, 1829, 1831, 1833, 1835, 1837, 1839, 1841, 1843, 1845, 1847, 1849, 1851, 1853, 1855, 1857, 1859, 1861, 1863, 1865, 1867, 1869, 1871, 1873, 1875, 1877, 1879, 1881, 1883, 1885, 1887, 1889, 1891, 1893, 1895, 1897, 1899, 1901, 1903, 1905, 1907, 1909, 1911, 1913, 1915, 1917, 1919, 1921, 1923, 1925, 1927, 1929, 1931, 1933, 1935, 1937, 1939, 1941, 1943, 1945, 1947, 1949, 1951, 1953, 1955, 1957, 1959, 1961, 1963, 1965, 1967, 1969, 1971, 1973, 1975, 1977, 1979, 1981, 1983, 1985, 1987, 1989, 1991, 1993, 1995, 1997, 1999, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520, 522, 524, 526, 528, 530, 532, 534, 536, 538, 540, 542, 544, 546, 548, 550, 552, 554, 556, 558, 560, 562, 564, 566, 568, 570, 572, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 634, 636, 638, 640, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 666, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 688, 690, 692, 694, 696, 698, 700, 702, 704, 706, 708, 710, 712, 714, 716, 718, 720, 722, 724, 726, 728, 730, 732, 734, 736, 738, 740, 742, 744, 746, 748, 750, 752, 754, 756, 758, 760, 762, 764, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 796, 798, 800, 802, 804, 806, 808, 810, 812, 814, 816, 818, 820, 822, 824, 826, 828, 830, 832, 834, 836, 838, 840, 842, 844, 846, 848, 850, 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 876, 878, 880, 882, 884, 886, 888, 890, 892, 894, 896, 898, 900, 902, 904, 906, 908, 910, 912, 914, 916, 918, 920, 922, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978, 980, 982, 984, 986, 988, 990, 992, 994, 996, 998, 1000, 1002, 1004, 1006, 1008, 1010, 1012, 1014, 1016, 1018, 1020, 1022, 1024, 1026, 1028, 1030, 1032, 1034, 1036, 1038, 1040, 1042, 1044, 1046, 1048, 1050, 1052, 1054, 1056, 1058, 1060, 1062, 1064, 1066, 1068, 1070, 1072, 1074, 1076, 1078, 1080, 1082, 1084, 1086, 1088, 1090, 1092, 1094, 1096, 1098, 1100, 1102, 1104, 1106, 1108, 1110, 1112, 1114, 1116, 1118, 1120, 1122, 1124, 1126, 1128, 1130, 1132, 1134, 1136, 1138, 1140, 1142, 1144, 1146, 1148, 1150, 1152, 1154, 1156, 1158, 1160, 1162, 1164, 1166, 1168, 1170, 1172, 1174, 1176, 1178, 1180, 1182, 1184, 1186, 1188, 1190, 1192, 1194, 1196, 1198, 1200, 1202, 1204, 1206, 1208, 1210, 1212, 1214, 1216, 1218, 1220, 1222, 1224, 1226, 1228, 1230, 1232, 1234, 1236, 1238, 1240, 1242, 1244, 1246, 1248, 1250, 1252, 1254, 1256, 1258, 1260, 1262, 1264, 1266, 1268, 1270, 1272, 1274, 1276, 1278, 1280, 1282, 1284, 1286, 1288, 1290, 1292, 1294, 1296, 1298, 1300, 1302, 1304, 1306, 1308, 1310, 1312, 1314, 1316, 1318, 1320, 1322, 1324, 1326, 1328, 1330, 1332, 1334, 1336, 1338, 1340, 1342, 1344, 1346, 1348, 1350, 1352, 1354, 1356, 1358, 1360, 1362, 1364, 1366, 1368, 1370, 1372, 1374, 1376, 1378, 1380, 1382, 1384, 1386, 1388, 1390, 1392, 1394, 1396, 1398, 1400, 1402, 1404, 1406, 1408, 1410, 1412, 1414, 1416, 1418, 1420, 1422, 1424, 1426, 1428, 1430, 1432, 1434, 1436, 1438, 1440, 1442, 1444, 1446, 1448, 1450, 1452, 1454, 1456, 1458, 1460, 1462, 1464, 1466, 1468, 1470, 1472, 1474, 1476, 1478, 1480, 1482, 1484, 1486, 1488, 1490, 1492, 1494, 1496, 1498, 1500, 1502, 1504, 1506, 1508, 1510, 1512, 1514, 1516, 1518, 1520, 1522, 1524, 1526, 1528, 1530, 1532, 1534, 1536, 1538, 1540, 1542, 1544, 1546, 1548, 1550, 1552, 1554, 1556, 1558, 1560, 1562, 1564, 1566, 1568, 1570, 1572, 1574, 1576, 1578, 1580, 1582, 1584, 1586, 1588, 1590, 1592, 1594, 1596, 1598, 1600, 1602, 1604, 1606, 1608, 1610, 1612, 1614, 1616, 1618, 1620, 1622, 1624, 1626, 1628, 1630, 1632, 1634, 1636, 1638, 1640, 1642, 1644, 1646, 1648, 1650, 1652, 1654, 1656, 1658, 1660, 1662, 1664, 1666, 1668, 1670, 1672, 1674, 1676, 1678, 1680, 1682, 1684, 1686, 1688, 1690, 1692, 1694, 1696, 1698, 1700, 1702, 1704, 1706, 1708, 1710, 1712, 1714, 1716, 1718, 1720, 1722, 1724, 1726, 1728, 1730, 1732, 1734, 1736, 1738, 1740, 1742, 1744, 1746, 1748, 1750, 1752, 1754, 1756, 1758, 1760, 1762, 1764, 1766, 1768, 1770, 1772, 1774, 1776, 1778, 1780, 1782, 1784, 1786, 1788, 1790, 1792, 1794, 1796, 1798, 1800, 1802, 1804, 1806, 1808, 1810, 1812, 1814, 1816, 1818, 1820, 1822, 1824, 1826, 1828, 1830, 1832, 1834, 1836, 1838, 1840, 1842, 1844, 1846, 1848, 1850, 1852, 1854, 1856, 1858, 1860, 1862, 1864, 1866, 1868, 1870, 1872, 1874, 1876, 1878, 1880, 1882, 1884, 1886, 1888, 1890, 1892, 1894, 1896, 1898, 1900, 1902, 1904, 1906, 1908, 1910, 1912, 1914, 1916, 1918, 1920, 1922, 1924, 1926, 1928, 1930, 1932, 1934, 1936, 1938, 1940, 1942, 1944, 1946, 1948, 1950, 1952, 1954, 1956, 1958, 1960, 1962, 1964, 1966, 1968, 1970, 1972, 1974, 1976, 1978, 1980, 1982, 1984, 1986, 1988, 1990, 1992, 1994, 1996, 1998, 2000], [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7], [5, 4, 3, 1, 2], [6, 4, 2, 5, 3, 1], [0, 0, 1, 0, 1, 1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "314", "slug": "one-edit-distance", "id": 314, "title": "One Edit Distance", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/one-edit-distance/", "examples": [{"explanation": "Inserting \"c\" between \"a\" and \"b\" turns \"ab\" into \"acb\".", "input": "s = \"ab\", t = \"acb\"", "output": "true"}, {"explanation": "More than one insertion, deletion, or replacement is needed.", "input": "s = \"cab\", t = \"ad\"", "output": "false"}, {"explanation": "Replacing \"0\" with \"1\" makes the strings equal.", "input": "s = \"1203\", t = \"1213\"", "output": "true"}], "hints": ["If the lengths differ by more than one, the answer is immediately false.", "When lengths match, count mismatches and require exactly one.", "When lengths differ by one, walk both strings allowing a single skip in the longer one."], "statement": "Decide whether two strings are exactly one edit apart. A single edit means inserting one character, deleting one character, or replacing one character.\n\nThe strings must differ by precisely one such step. Identical strings need zero edits, so they do not count; strings that need two or more steps also do not count.\n\n**Constraints:**\n- `0 <= s.length, t.length <= 10^4`\n- Strings consist of letters and digits.\n", "solution": "## Approach\n\nHandle the two possible length relationships separately. When the strings share the same length, scan once and require exactly one mismatched position (a replacement). When lengths differ by one, walk both strings together and allow a single skip in the longer string (an insertion or deletion). Any larger length gap is immediately false.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the longer string length. Each character is visited at most once.\n- **Space Complexity:** O(1) besides the inputs.\n\n## Implementation\n\n```python\nclass Solution:\n def isOneEditDistance(self, s: str, t: str) -> bool:\n m, n = len(s), len(t)\n if abs(m - n) > 1:\n return False\n if m == n:\n diff = sum(1 for a, b in zip(s, t) if a != b)\n return diff == 1\n longer, shorter = (s, t) if m > n else (t, s)\n i = j = 0\n skipped = False\n while i < len(longer) and j < len(shorter):\n if longer[i] == shorter[j]:\n i += 1\n j += 1\n else:\n if skipped:\n return False\n skipped = True\n i += 1\n return True\n```\n", "starter": {"go": "package main\n\nfunc IsOneEditDistance(s string, t string) bool {\n \n}", "python": "class Solution:\n def isOneEditDistance(self, s: str, t: str) -> bool:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool isOneEditDistance(string s, string t) {\n return false;\n }\n};"}, "fn": "isOneEditDistance", "params": [{"name": "s", "type": "string"}, {"name": "t", "type": "string"}], "outputType": "boolean", "tests": [["ab", "acb"], ["cab", "ad"], ["1203", "1213"], ["ab", "ab"], ["", ""], ["", "a"], ["a", ""], ["a", "b"], ["ab", "ba"], ["abc", "abc"], ["abc", "ab"], ["ab", "abc"], ["abc", "adc"], ["abc", "abcc"], ["abcc", "abc"], ["teacher", "bleacher"], ["is", "it"], ["hello", "hallo"], ["hello", "hell"], ["hell", "hello"], ["abcdef", "abccef"], ["xyz", "xy"], ["xy", "xyz"], ["a", "aa"], ["aa", "a"], ["ab", "cd"]], "expected": [true, false, true, false, false, true, true, true, false, false, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "538", "slug": "ones-and-zeroes", "id": 538, "title": "Ones and Zeroes", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/ones-and-zeroes/", "examples": [{"input": "strs = [\"10\",\"0001\",\"111001\",\"1\",\"0\"], m = 5, n = 3", "output": "4", "explanation": "\"10\",\"0001\",\"1\",\"0\" together consume 5 zeroes and 3 ones."}, {"input": "strs = [\"10\",\"0\",\"1\"], m = 1, n = 1", "output": "2", "explanation": "Choosing \"0\" and \"1\" exactly fills both budgets."}, {"input": "strs = [\"0\",\"0\",\"1\",\"1\"], m = 2, n = 1", "output": "3", "explanation": "Two zeroes plus one one is optimal."}], "hints": ["Count zeroes and ones in each string once up front.", "Treat the two budgets as a 2D 0/1 knapsack and update the table backwards.", "Each string is either skipped or taken if its counts fit."], "statement": "You receive a collection of strings that use only the characters `0` and `1`, plus two budgets: at most `m` zeroes and at most `n` ones. Choose as many strings as possible so that the total count of `0` characters across the chosen strings stays within `m` and the total count of `1` characters stays within `n`.\n\nReturn that largest achievable count of strings.\n\n**Constraints:**\n\n- `1 <= strs.length <= 600`\n- `1 <= strs[i].length <= 100`\n- Each `strs[i]` holds only `0` and `1`.\n- `1 <= m, n <= 100`\n", "solution": "## Approach\n\nPrecompute how many zeroes and ones each binary string needs. Then run a two-dimensional 0/1 knapsack over the budgets `m` and `n`: the table entry for `(i, j)` keeps the best count achievable with at most `i` zeroes and `j` ones. Process every string once, scanning the table backwards so each string is used at most once, and keep the better of skipping or taking it.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(S * m * n) where S is the number of strings.\n- **Space Complexity:** O(m * n) for the DP table.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findMaxForm(self, strs: List[str], m: int, n: int) -> int:\n dp = [[0] * (n + 1) for _ in range(m + 1)]\n for s in strs:\n zeros = s.count(\"0\")\n ones = len(s) - zeros\n for i in range(m, zeros - 1, -1):\n for j in range(n, ones - 1, -1):\n if dp[i - zeros][j - ones] + 1 > dp[i][j]:\n dp[i][j] = dp[i - zeros][j - ones] + 1\n return dp[m][n]\n```\n", "starter": {"go": "package main\n\nfunc FindMaxForm(strs []string, m int, n int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def findMaxForm(self, strs: List[str], m: int, n: int) -> int:\n return 0\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n return 0;\n }\n};"}, "fn": "findMaxForm", "params": [{"name": "strs", "type": "string_array"}, {"name": "m", "type": "int"}, {"name": "n", "type": "int"}], "outputType": "int", "tests": [["[\"10\",\"0001\",\"111001\",\"1\",\"0\"]", "5", "3"], ["[\"10\",\"0\",\"1\"]", "1", "1"], ["[\"0\",\"0\",\"1\",\"1\"]", "2", "1"], ["[\"0\"]", "1", "1"], ["[\"1\"]", "1", "1"], ["[\"00\",\"11\",\"01\",\"10\"]", "2", "2"], ["[\"000\",\"111\",\"000111\"]", "3", "3"], ["[\"0\",\"0\",\"0\",\"1\",\"1\",\"1\"]", "2", "2"], ["[\"10\",\"10\",\"10\"]", "3", "3"], ["[\"111\",\"000\",\"101\"]", "2", "2"], ["[\"0\",\"1\",\"01\",\"10\",\"0011\"]", "3", "3"], ["[\"1\",\"1\",\"1\",\"0\",\"0\"]", "1", "2"], ["[\"00\",\"00\",\"11\",\"11\"]", "4", "2"], ["[\"01\",\"01\",\"01\",\"10\",\"10\"]", "5", "5"], ["[\"0\",\"00\",\"000\",\"1\",\"11\"]", "3", "2"], ["[\"1111\",\"0000\",\"1010\",\"0101\"]", "4", "4"], ["[\"0\",\"1\"]", "1", "1"], ["[\"10\",\"0001\",\"111001\",\"1\",\"0\",\"01\",\"10\",\"001\"]", "6", "4"], ["[\"1\",\"0\",\"01\",\"10\",\"001\",\"110\"]", "4", "4"], ["[\"00000\",\"11111\",\"00011\",\"11100\"]", "5", "5"], ["[\"00\",\"11\"]", "2", "2"], ["[\"0\",\"0\",\"0\"]", "3", "1"], ["[\"11\",\"11\",\"00\",\"00\"]", "2", "2"], ["[\"01\",\"10\",\"01\",\"10\"]", "2", "2"], ["[\"0000\",\"1111\"]", "4", "4"], ["[\"1\",\"1\",\"0\",\"0\",\"01\"]", "2", "2"], ["[\"10\",\"01\",\"0011\",\"1100\"]", "4", "4"], ["[\"0\",\"1\",\"0\",\"1\",\"0\",\"1\"]", "3", "3"]], "expected": [4, 2, 3, 1, 1, 2, 2, 4, 3, 1, 4, 3, 3, 5, 3, 2, 2, 5, 4, 2, 2, 3, 2, 2, 2, 4, 3, 6], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "900", "slug": "online-election", "id": 900, "title": "Online Election", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/online-election/", "examples": [{"input": "persons = [0,1,1,0,0,1,0], times = [0,5,10,15,20,25,30], queries = [3,12,25,15,24,8]", "output": "[0,1,1,0,0,1]", "explanation": "The leader after each vote is [0,1,1,0,0,1,0]; each query picks the latest leader at or before its time."}, {"input": "persons = [0,0,0,1,1], times = [0,10,20,30,40], queries = [0,10,25,40]", "output": "[0,0,0,0]", "explanation": "Person 0 leads from the first vote onward."}, {"input": "persons = [1,2,2,1,2], times = [5,10,15,20,25], queries = [5,14,20,100]", "output": "[1,2,1,2]", "explanation": "Ties go to the most recently voted person: at time 10 the tie picks 2, at time 20 it picks 1."}], "hints": ["Precompute who leads right after every vote: track vote counts and let the newest vote win ties.", "Each query asks for the latest vote time at or before it, which is a binary search over the sorted times.", "Adaptation note: the original class interaction is flattened here into one batch call returning every query answer."], "statement": "Votes arrive over time: `persons[i]` receives one vote at moment `times[i]`, and `times` is strictly increasing. At any moment the leader is the person holding the most votes so far, with ties broken in favor of whoever was voted for most recently.\n\nInstead of building the usual query class, implement `runElection(persons, times, queries)`: it receives the whole vote record plus a batch of query moments and returns, for each query `t`, the leader among votes cast at or before `t`. Every query time is guaranteed to be at least `times[0]`.\n\n**Constraints:**\n- `1 <= persons.length == times.length <= 5000`\n- `times` is strictly increasing, `0 <= times[i] <= 10^9`\n- `0 <= persons[i] < persons.length`\n- `1 <= queries.length <= 10000`\n- `times[0] <= queries[j] <= 10^9`\n", "solution": "## Approach\n\nSweep once through the votes while counting per-person totals; after each vote record the current leader, awarding ties to the latest vote. The leader only changes at vote moments, so each query reduces to finding the rightmost vote time at or before it with binary search and reading the stored leader.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + q log n) for the sweep plus one binary search per query.\n- **Space Complexity:** O(n) for the leader table and counts.\n\n## Implementation\n\n```python\nfrom typing import List\nimport bisect\nclass Solution:\n def runElection(self, persons: List[int], times: List[int], queries: List[int]) -> List[int]:\n leaders = []\n count = {}\n best, best_count = -1, 0\n for p in persons:\n c = count.get(p, 0) + 1\n count[p] = c\n if c >= best_count:\n best_count, best = c, p\n leaders.append(best)\n ans = []\n for t in queries:\n idx = bisect.bisect_right(times, t) - 1\n ans.append(leaders[idx])\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunElection(persons []int, times []int, queries []int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runElection(self, persons: List[int], times: List[int], queries: List[int]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runElection(vector<int>& persons, vector<int>& times, vector<int>& queries) {\n return {};\n }\n};"}, "fn": "runElection", "params": [{"name": "persons", "type": "int_array"}, {"name": "times", "type": "int_array"}, {"name": "queries", "type": "int_array"}], "outputType": "int_array", "tests": [["[0,1,1,0,0,1,0]", "[0,5,10,15,20,25,30]", "[3,12,25,15,24,8]"], ["[0,0,0,1,1]", "[0,10,20,30,40]", "[0,10,25,40]"], ["[1,2,2,1,2]", "[5,10,15,20,25]", "[5,14,20,100]"], ["[0]", "[7]", "[7,100]"], ["[3, 3, 1, 1, 1, 3, 1, 0]", "[24, 28, 31, 32, 37, 38, 40, 47]", "[41, 39, 57]"], ["[0, 2, 1, 3, 0]", "[18, 26, 34, 37, 43]", "[48, 43, 54, 21, 35]"], ["[1, 3, 2]", "[8, 15, 20]", "[32, 25]"], ["[3, 0, 1, 3]", "[22, 24, 30, 37]", "[52, 39, 46, 34]"], ["[1]", "[11]", "[16, 27, 30, 24, 25]"], ["[0]", "[14]", "[17, 34, 23, 14, 16]"], ["[2, 3, 3, 2, 1]", "[14, 24, 28, 33, 34]", "[34, 22, 40]"], ["[2, 2, 2, 3, 0, 2, 0, 2]", "[16, 23, 29, 33, 39, 41, 51, 53]", "[49, 36, 25, 54]"], ["[2, 1, 1, 3, 3, 3]", "[21, 24, 31, 36, 40, 43]", "[26, 36, 51, 39, 59, 28]"], ["[0, 3, 0, 3]", "[13, 22, 29, 30]", "[16, 50, 33, 43, 16, 15]"], ["[0, 1, 2, 2]", "[14, 22, 28, 35]", "[40, 37, 55, 29, 46, 23]"], ["[0, 2]", "[30, 31]", "[30, 36, 46, 50, 45, 43]"], ["[0, 2, 0, 2, 3, 1, 3]", "[9, 18, 25, 26, 30, 32, 36]", "[56]"], ["[0, 3, 1, 1, 3, 3, 0]", "[11, 14, 16, 22, 23, 26, 33]", "[45, 37, 12]"], ["[0, 3]", "[15, 24]", "[42, 23, 22, 20, 28, 34]"], ["[0, 2, 3, 3, 0, 1, 3]", "[22, 32, 34, 42, 52, 59, 63]", "[47, 39, 76, 30]"], ["[1, 0, 0, 0]", "[19, 27, 37, 47]", "[50]"], ["[3, 1, 1, 0]", "[28, 30, 32, 38]", "[30, 31, 30, 53, 29]"], ["[2, 1, 3, 0, 1, 3, 0]", "[25, 35, 38, 47, 50, 51, 56]", "[49, 37, 46]"], ["[2, 2, 0, 2, 3]", "[5, 7, 12, 19, 29]", "[37, 16, 42, 13]"], ["[0, 0, 1, 2, 2, 0, 3, 2]", "[9, 14, 15, 16, 17, 27, 36, 39]", "[11]"], ["[1, 3, 1, 0, 2, 3, 3, 1]", "[5, 11, 21, 23, 28, 34, 40, 48]", "[36]"], ["[1, 1, 1]", "[23, 26, 29]", "[24, 39, 37, 38]"], ["[3, 2, 2, 1]", "[9, 18, 25, 28]", "[9, 16, 36, 17, 12]"]], "expected": [[0, 1, 1, 0, 0, 1], [0, 0, 0, 0], [1, 2, 1, 2], [0, 0], [1, 3, 1], [0, 0, 0, 0, 1], [2, 2], [3, 3, 3, 1], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0], [2, 2, 2], [2, 2, 2, 2], [1, 1, 3, 1, 3, 1], [0, 3, 3, 3, 0, 0], [2, 2, 2, 2, 2, 1], [0, 2, 2, 2, 2, 2], [3], [3, 3, 0], [3, 0, 0, 0, 3, 3], [3, 3, 3, 0], [0], [1, 1, 1, 1, 3], [0, 1, 3], [2, 2, 2, 2], [0], [3], [1, 1, 1, 1], [3, 3, 2, 3, 3]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "180", "slug": "online-stock-span", "id": 180, "title": "Online Stock Span", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/online-stock-span/", "examples": [{"explanation": "Each span counts consecutive days backwards with price at most today's: day 4 (70) covers 60 and 70 for 2; day 6 (75) covers 60, 70, 60, 75 for 4; day 7 (85) covers all except 100 for 6.", "input": "operations = [\"StockSpanner\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\"], values = [[],[100],[80],[60],[70],[60],[75],[85]]", "output": "[null,1,1,1,2,1,4,6]"}, {"explanation": "Spans are computed streaming: 5 covers 4 and 5, 90 covers all before it, 120 covers all before it, and 80 covers only itself.", "input": "operations = [\"StockSpanner\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\"], values = [[],[10],[4],[5],[90],[120],[80]]", "output": "[null,1,1,2,4,5,1]"}, {"explanation": "Strictly decreasing prices each have a span of 1.", "input": "operations = [\"StockSpanner\",\"next\",\"next\",\"next\"], values = [[],[30],[20],[10]]", "output": "[null,1,1,1]"}], "hints": ["Keep a monotonic decreasing stack of (price, span) pairs.", "For each price, accumulate spans while the stack top price is less than or equal to the current price, then push the combined span.", "Each next call emits a plain integer; only the constructor emits \"null\"."], "statement": "Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day.\n\nThe span of the stock's price in one day is the maximum number of consecutive days (starting from that day and going backward) for which the stock price was less than or equal to the price of that day.\n\nFor example, if the prices of the stock in the last four days are `[7,2,1,2]` and the price of the stock today is `2`, then the span of today is `4` because starting from today, the price of the stock was less than or equal to `2` for 4 consecutive days. Also, if the prices of the stock in the last four days are `[7,34,1,2]` and the price of the stock today is `8`, then the span of today is `3` because starting from today, the price of the stock was less than or equal to `8` for 3 consecutive days.\n\nImplement the `StockSpanner` class:\n\n- `StockSpanner()` Initializes the object.\n- `int next(int price)` Returns the span of the stock's price given that today's price is `price`.\n\nThe class keeps its LeetCode name `StockSpanner` here (instead of `Solution`) because the judge harness reserves `Solution` for its driver; the constructor and method match the original.\n\nGrading is deterministic: every `next` answer is compared exactly against a monotonic-stack reference model.\n\n**Constraints:**\n- `1 <= price <= 10^5`\n- At most `10^4` calls will be made to `next`.\n", "solution": "## Approach\n\nKeep a monotonic decreasing stack of `(price, span)` pairs. For each new price, start with span `1` and pop every stack top whose price is less than or equal to the current price, adding its span to the current one. Push the current pair and return its span. Each price is pushed and popped at most once.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) amortized per `next` call.\n- **Space Complexity:** O(n) for the monotonic stack in the worst case.\n\n## Implementation\n\n```python\nclass StockSpanner:\n def __init__(self):\n self.prices = []\n self.spans = []\n\n def next(self, price: int) -> int:\n span = 1\n while self.prices and self.prices[-1] <= price:\n self.prices.pop()\n span += self.spans.pop()\n self.prices.append(price)\n self.spans.append(span)\n return span\n```\n", "starter": {"go": "package main\n\ntype StockSpanner struct {\n\n}\n\nfunc Constructor() StockSpanner {\n return StockSpanner{}\n}\n\nfunc (this *StockSpanner) Next(price int) int {\n return 0\n}\n", "python": "class StockSpanner:\n def __init__(self):\n\n def next(self, price: int) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass StockSpanner {\npublic:\n StockSpanner() {\n \n }\n\n int next(int price) {\n return 0;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [100], [80], [60], [70], [60], [75], [85]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [10], [4], [5], [90], [120], [80]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\"]", "[[], [30], [20], [10]]"], ["[\"StockSpanner\", \"next\"]", "[[], [10]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\"]", "[[], [10], [10], [10], [10]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [1], [2], [3], [4], [5]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [5], [4], [3], [2], [1]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [31], [41], [59], [26], [53], [58], [97], [93], [23], [84]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [100], [100], [100], [90], [90], [100]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [73], [73], [73], [73], [73]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [1], [100000], [1], [100000], [1]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [1], [1], [2], [2], [3], [3]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [607], [776], [925], [574], [179], [460], [193], [794], [311], [168], [245], [198], [83], [572], [929], [586], [847], [528], [781], [942], [563], [76], [305], [954], [711], [808], [757], [646], [355], [76], [1], [754], [735], [784], [757], [790], [315], [108], [457], [930], [423], [552], [677], [110], [3], [20], [713], [42], [431], [328], [509], [758], [283], [228], [673], [706], [287], [624], [29], [358], [291], [276], [33], [98], [311], [80], [317], [198], [771], [588], [281], [58], [367], [192], [941], [318], [891], [412], [417], [458], [631], [176], [805], [606], [555], [364], [633], [802], [671], [376], [125], [862], [363], [996], [881], [386], [951], [624], [13], [278], [307], [244], [177], [282], [111], [384], [189], [702], [819], [676], [17], [882], [447], [792], [357], [446], [611], [676], [417], [618], [983], [352], [5], [638], [995], [836], [713], [58], [687], [600], [109], [174], [627], [764], [41], [546], [631], [296], [781], [750], [211], [732], [521], [146], [295], [120], [5], [902], [571], [756], [233], [666], [815], [304], [77], [886], [851], [740], [377], [338], [671], [64], [373], [342], [675], [940], [745], [282], [727], [24], [877], [614], [675], [548], [617], [274], [711], [680], [445], [262], [555], [892], [969], [946], [471], [264], [957], [710], [891], [52], [401], [290], [119], [296], [429], [846], [635], [260], [193], [2], [967], [832], [549], [406], [467], [844], [673], [666], [591], [864], [877], [70], [867], [68], [841], [186], [79], [136], [765], [230], [611], [164], [289], [114], [367], [800], [53], [62], [691], [556], [617], [410], [631], [264], [317], [550], [731], [36], [681], [618], [359], [584], [653], [534], [459], [372], [97], [10], [127], [696], [477], [470], [507], [868], [929], [90], [167], [600], [877], [30], [859], [468], [281], [642], [119], [384], [557], [78], [907], [292], [721], [506], [447], [32], [37], [470], [523], [588], [17], [770], [575], [648], [221], [174], [259], [356], [185], [394], [335], [1000], [389], [694], [155], [924], [425], [618], [247], [776], [853], [334]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78], [78]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [2], [6], [6], [7], [8], [8], [35], [38], [42], [44], [49], [49], [58], [61], [68], [72], [78], [84], [86], [87], [89], [96], [96]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [87], [82], [78], [65], [45], [42], [40], [36], [26], [18], [16], [14], [11]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [100], [95], [94], [94], [93], [91], [87], [87], [84], [83], [81], [80], [79], [75], [73], [71], [57], [54], [53], [53], [48], [48], [46], [42], [36], [34], [22], [20], [17], [15], [14], [13], [13], [11], [10], [9], [4], [2]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [74], [69], [66], [20], [20], [18]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90], [90]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [98], [97], [95], [95], [94], [94], [86], [80], [72], [71], [60], [58], [49], [47], [47], [40], [39], [22], [11], [8], [3]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [6], [11], [11], [21], [23], [30], [31], [32], [35], [37], [39], [40], [41], [48], [61], [61], [62], [63], [64], [64], [69], [72], [76], [83], [87], [92]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17], [17]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [93], [16], [30], [98], [95], [3], [17], [18], [33], [87], [99], [1], [52], [66], [55], [40], [55], [40], [5], [9], [22], [3], [67], [2], [54]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [98], [70], [69], [68], [53], [44], [39], [30], [21], [16]]"], ["[\"StockSpanner\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\", \"next\"]", "[[], [1], [6], [7], [11], [16], [19], [22], [29], [33], [39], [45], [46], [50], [52], [54], [58], [61], [65], [65], [67], [76], [79], [80], [85], [91], [97], [98], [98], [99]]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "218", "slug": "open-the-lock", "id": 218, "title": "Open the Lock", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/open-the-lock/", "examples": [{"input": "deadends = [\"0201\",\"0101\",\"0102\",\"1212\",\"2002\"], target = \"0202\"", "output": "6"}, {"input": "deadends = [\"8888\"], target = \"0009\"", "output": "1"}, {"input": "deadends = [\"8887\",\"8889\",\"8878\",\"8898\",\"8788\",\"8988\",\"7888\",\"9888\"], target = \"8888\"", "output": "-1"}], "hints": ["BFS from \"0000\". Each move turns one wheel up or down by one."], "statement": "Picture a combination lock with four round dials, each showing one of `'0'` through `'9'`. A dial turned past `'9'` wraps to `'0'`, and turned below `'0'` wraps to `'9'`. One move consists of rotating a single dial forward or backward by one position.\n\nThe lock begins at `'0000'`. A set `deadends` lists forbidden codes: stepping onto any of them jams the lock permanently. Starting from the initial state without counting it as a visit if it is blocked, find the fewest moves that reach `target`. Return `-1` when the target can never be reached safely.\n\n**Constraints:**\n- `1 <= deadends.length <= 500`\n- `deadends[i].length == 4`\n- `target.length == 4`\n- `target` will not be in the list `deadends`\n- `target` and `deadends[i]` consist of digits only\n", "solution": "## Approach\n\nBFS from `\"0000\"`. Each state has 8 neighbors (turn each of 4 wheels \u00b11). Skip dead ends and visited states.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(10^4) states\n- **Space Complexity:** O(10^4)\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def openLock(self, deadends: List[str], target: str) -> int:\n dead = set(deadends)\n if \"0000\" in dead:\n return -1\n if target == \"0000\":\n return 0\n q = deque([\"0000\"])\n seen = {\"0000\"}\n steps = 0\n while q:\n for _ in range(len(q)):\n cur = q.popleft()\n for i in range(4):\n for d in (-1, 1):\n chars = list(cur)\n chars[i] = str((int(chars[i]) + d) % 10)\n nxt = \"\".join(chars)\n if nxt in seen or nxt in dead:\n continue\n if nxt == target:\n return steps + 1\n seen.add(nxt)\n q.append(nxt)\n steps += 1\n return -1\n```\n", "starter": {"go": "package main\n\nfunc OpenLock(deadends []string, target string) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def openLock(self, deadends: List[str], target: str) -> int:\n ", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int openLock(vector<string>& deadends, string target) {\n return 0;\n }\n};"}, "fn": "openLock", "params": [{"name": "deadends", "type": "string_array"}, {"name": "target", "type": "string"}], "outputType": "int", "tests": [["[\"0201\",\"0101\",\"0102\",\"1212\",\"2002\"]", "0202"], ["[\"8888\"]", "0009"], ["[\"8887\",\"8889\",\"8878\",\"8898\",\"8788\",\"8988\",\"7888\",\"9888\"]", "8888"], ["[\"0000\"]", "8888"], ["[\"1337\"]", "0000"], ["[\"0201\",\"0101\",\"0102\",\"1212\",\"2002\"]", "0000"], ["[\"1111\"]", "0010"], ["[\"8888\",\"0001\"]", "0009"], ["[\"1000\",\"0100\",\"0010\",\"0001\",\"9000\",\"0900\",\"0090\",\"0009\"]", "8888"], ["[\"1234\"]", "4321"], ["[\"0001\"]", "0002"], ["[\"9999\"]", "0001"], ["[\"1111\",\"2222\"]", "3333"], ["[\"5555\"]", "5556"], ["[\"1357\",\"2468\"]", "1358"], ["[\"1111\"]", "2222"], ["[\"2222\"]", "1111"], ["[\"0001\",\"0002\",\"0003\"]", "0004"], ["[\"9998\",\"9999\"]", "9997"], ["[\"1234\",\"2345\",\"3456\"]", "0000"], ["[\"5678\"]", "8765"], ["[\"0009\",\"0019\",\"0029\"]", "0008"], ["[\"1000\"]", "9000"], ["[\"0100\"]", "0900"], ["[\"1110\",\"1112\"]", "1111"], ["[\"9999\",\"8888\"]", "0000"], ["[\"2468\",\"1357\",\"9753\"]", "0000"], ["[\"0000\"]", "0001"], ["[\"1212\"]", "2121"], ["[\"6969\"]", "9696"]], "expected": [6, 1, -1, -1, 0, 0, 1, 1, -1, 10, 4, 1, 12, 19, 11, 8, 4, 6, 6, 0, 14, 4, 1, 1, 4, 0, 0, -1, 6, 10], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "530", "slug": "optimal-account-balancing", "id": 530, "title": "Optimal Account Balancing", "difficulty": "Hard", "category": "backtracking", "link": "https://leetcode.com/problems/optimal-account-balancing/", "examples": [{"input": "transactions = [[0,1,10],[2,0,5]]", "output": "2", "explanation": "Net balances are -5 for person 0, +10 for person 1, and -5 for person 2, so two payments (one from each debtor to person 1) settle everything."}, {"input": "transactions = [[0,1,10],[1,0,1],[1,2,5],[2,0,5]]", "output": "1", "explanation": "Net balances are -4 for person 0, +4 for person 1, and 0 for person 2, so a single payment of 4 from person 0 to person 1 settles everyone."}], "hints": ["Only each person's net balance matters: collapse all transfers into one balance per person and drop the zeroes.", "Backtrack over pairs with opposite signs, settling one account per transfer and skipping symmetric dead ends."], "statement": "You are given money transfers between people. Each entry `transactions[i] = [from, to, amount]` means person `from` paid person `to` the amount `amount`.\n\nAfter all recorded transfers, the group wants to settle up with the fewest possible new payments (each new payment can be any positive amount between any two people). People not involved in any transfer are ignored.\n\nReturn the minimum number of settlement transfers required so that everyone ends with a net balance of zero.\n\n**Constraints:**\n- `1 <= transactions.length <= 8`\n- `0 <= from, to <= 20`, `from != to`\n- `1 <= amount <= 100`\n", "solution": "## Approach\n\nFirst compress every transfer into a single net balance per person and discard the zero balances; only these debts matter. Then backtrack: take the first unsettled account and try merging it into each later account of opposite sign, which models one settlement payment clearing the current account. Recurse, undo, and keep the smallest count, with a pruning break when a merge zeroes out its partner (symmetric alternatives cannot do better).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n!), with n the number of non-zero balances (at most a dozen here), for the pairing search.\n- **Space Complexity:** O(n) for the recursion stack and balance list.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def minTransfers(self, transactions: List[List[int]]) -> int:\n bal = {}\n for f, t, a in transactions:\n bal[f] = bal.get(f, 0) - a\n bal[t] = bal.get(t, 0) + a\n debts = [v for v in bal.values() if v != 0]\n\n def settle(start: int) -> int:\n while start < len(debts) and debts[start] == 0:\n start += 1\n if start == len(debts):\n return 0\n best = float(\"inf\")\n for i in range(start + 1, len(debts)):\n if debts[start] * debts[i] < 0:\n debts[i] += debts[start]\n best = min(best, 1 + settle(start + 1))\n debts[i] -= debts[start]\n if debts[i] + debts[start] == 0:\n break\n return best\n\n return settle(0)\n```\n", "starter": {"go": "package main\n\nfunc MinTransfers(transactions [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def minTransfers(self, transactions: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int minTransfers(vector<vector<int>>& transactions) {\n return 0;\n }\n};"}, "fn": "minTransfers", "params": [{"name": "transactions", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0,1,10],[2,0,5]]"], ["[[0,1,10],[1,0,1],[1,2,5],[2,0,5]]"], ["[[0,1,5],[1,2,5],[2,0,5]]"], ["[[0,1,10]]"], ["[[0,1,1],[1,2,1],[2,3,1],[3,4,1],[4,5,1],[5,0,1]]"], ["[[0,1,5],[0,2,5],[1,3,10],[2,3,10]]"], ["[[0,1,2],[1,2,2],[2,0,2]]"], ["[[0,1,10],[0,2,5],[1,2,5]]"], ["[[1,0,5],[2,0,5],[3,0,5],[0,4,15]]"], ["[[0,1,100],[1,2,50],[2,3,25]]"], ["[[0,2,5],[1,2,5]]"], ["[[0,1,5],[2,1,5]]"], ["[[0,1,10],[0,2,10],[3,0,20]]"], ["[[0,1,5],[1,0,5]]"], ["[[0,1,7],[1,2,7],[2,0,7]]"], ["[[0,1,20],[1,2,10]]"], ["[[0,1,10],[0,1,10]]"], ["[[1,2,10],[2,3,10],[3,1,10]]"], ["[[0,5,10],[1,5,10],[2,5,10],[3,5,10]]"], ["[[0,1,5],[1,2,10],[2,0,3]]"], ["[[4,5,100],[5,6,50],[6,4,25]]"], ["[[0,10,50],[10,20,25],[20,0,10]]"], ["[[2,3,1],[3,4,2],[4,2,1]]"], ["[[0,1,30],[2,3,30]]"], ["[[0,1,10],[2,3,10],[1,2,5]]"], ["[[5,6,15],[6,7,15],[7,5,15]]"], ["[[0,19,100],[19,20,100],[20,0,50]]"], ["[[1,2,3],[2,3,4],[3,1,5]]"]], "expected": [2, 1, 0, 1, 0, 3, 0, 2, 3, 3, 2, 2, 2, 0, 0, 2, 1, 0, 4, 2, 2, 2, 1, 2, 2, 0, 1, 2], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "609", "slug": "optimal-division", "id": 609, "title": "Optimal Division", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/optimal-division/", "examples": [{"input": "nums = [1000,100,10,2]", "output": "\"1000/(100/10/2)\"", "explanation": "Minimise the divisor tail."}, {"input": "nums = [2,3,4]", "output": "\"2/(3/4)\"", "explanation": "Parenthesise the tail."}, {"input": "nums = [2]", "output": "\"2\""}], "hints": ["The numerator should stay as nums[0] and the whole denominator should be as small as possible.", "Chaining divisions left to right already minimises a/b/c/..., so wrap everything after the first element in one pair.", "Handle lengths 1 and 2 separately to avoid useless parentheses."], "statement": "You are given an array `nums` of positive integers that will be divided in order, like `nums[0] / nums[1] / nums[2] / ...`. You may insert any number of parenthesis pairs to force evaluation order.\n\nParentheses change the result because division is not associative. Add them so the final value is as large as possible, then return the corresponding expression as a string. Do not include redundant parentheses: a single number needs none, two numbers need none, and longer inputs need exactly one outer pair around everything after the first number.\n\n**Constraints:**\n- `1 <= nums.length <= 10`\n- `2 <= nums[i] <= 1000`\n- The optimum is unique for every input\n", "solution": "## Approach\n\nKeep the first number as the numerator and make the divisor minimal. Dividing left to right already yields the smallest possible tail value, so the optimum is nums[0] divided by the parenthesised tail. Lengths one and two need no parentheses.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) to join the numbers.\n- **Space Complexity:** O(n) for the output string.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def optimalDivision(self, nums: List[int]) -> str:\n if len(nums) == 1:\n return str(nums[0])\n if len(nums) == 2:\n return f\"{nums[0]}/{nums[1]}\"\n return f\"{nums[0]}/({'/'.join(map(str, nums[1:]))})\"\n```\n", "starter": {"go": "package main\n\nfunc OptimalDivision(nums []int) string {\n \n}", "python": "from typing import List\nclass Solution:\n def optimalDivision(self, nums: List[int]) -> str:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string optimalDivision(vector<int>& nums) {\n return \"\";\n }\n};"}, "fn": "optimalDivision", "params": [{"name": "nums", "type": "int_array"}], "outputType": "string", "tests": [["[1000,100,10,2]"], ["[2,3,4]"], ["[2]"], ["[2,3]"], ["[6,2,3,4,5]"], ["[1000,100]"], ["[8,4,2]"], ["[2,3,4,5]"], ["[10,2]"], ["[5]"], ["[3,4,5]"], ["[100,10,2]"], ["[2,3,4,5,6]"], ["[1000,100,10]"], ["[4,2]"], ["[7,3,2]"], ["[9,9,9]"], ["[2,2,2,2]"], ["[1000,2,2,2,2]"], ["[3,2]"], ["[12,4,3]"], ["[500,50,5,2]"], ["[2,3,4,5,6,7]"], ["[1000,100,10,2,1]"], ["[6,3,2]"], ["[15,5,3]"], ["[100,2,2]"], ["[8,2]"]], "expected": ["1000/(100/10/2)", "2/(3/4)", "2", "2/3", "6/(2/3/4/5)", "1000/100", "8/(4/2)", "2/(3/4/5)", "10/2", "5", "3/(4/5)", "100/(10/2)", "2/(3/4/5/6)", "1000/(100/10)", "4/2", "7/(3/2)", "9/(9/9)", "2/(2/2/2)", "1000/(2/2/2/2)", "3/2", "12/(4/3)", "500/(50/5/2)", "2/(3/4/5/6/7)", "1000/(100/10/2/1)", "6/(3/2)", "15/(5/3)", "100/(2/2)", "8/2"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "889", "slug": "orderly-queue", "id": 889, "title": "Orderly Queue", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/orderly-queue/", "examples": [{"input": "s = \"cba\", k = 1", "output": "\"acb\"", "explanation": "Best of the three rotations."}, {"input": "s = \"baaca\", k = 3", "output": "\"aaabc\"", "explanation": "Sorting is reachable when k exceeds 1."}, {"input": "s = \"aabbcc\", k = 2", "output": "\"aabbcc\"", "explanation": "Already sorted."}], "hints": ["For k equal to 1, build every rotation s[i:]+s[:i] and keep the minimum.", "For k larger than 1, the process can simulate any swap, so returning the sorted characters is optimal."], "statement": "You hold a string `s` and a number `k`. One step lets you pick any of the first `k` characters and relocate it to the very end, preserving the order of everything else. Repeating steps can shuffle the string in restricted ways.\n\nDescribe the smallest string (in dictionary order) that can be reached.\n\nWhen `k` equals one, only rotations are possible, so examine each rotation. When `k` exceeds one, any rearrangement becomes reachable, so the sorted characters form the optimum.\n\n**Constraints:**\n- `1 <= k <= s.length <= 1000`\n- `s` holds only lowercase English letters.\n", "solution": "## Approach\n\nTwo regimes appear. With a single movable slot, the string can only spin, so every rotation is a candidate and the dictionary-minimum wins. With at least two movable slots, the operation is powerful enough to mimic bubble sorting (repeatedly ferrying the current minimum forward), hence any permutation is reachable and the fully sorted string is the optimum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) for k equal to 1 due to comparing n rotations; O(n log n) for k above 1 due to sorting.\n- **Space Complexity:** O(n) for the rotation copies and the sorted buffer.\n\n## Implementation\n\n```python\nclass Solution:\n def orderlyQueue(self, s: str, k: int) -> str:\n if k > 1:\n return \"\".join(sorted(s))\n best = s\n for i in range(1, len(s)):\n rot = s[i:] + s[:i]\n if rot < best:\n best = rot\n return best\n```\n", "starter": {"go": "package main\n\nfunc OrderlyQueue(s string, k int) string {\n \n}", "python": "class Solution:\n def orderlyQueue(self, s: str, k: int) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string orderlyQueue(string s, int k) {\n return \"\";\n }\n};"}, "fn": "orderlyQueue", "params": [{"name": "s", "type": "string"}, {"name": "k", "type": "int"}], "outputType": "string", "tests": [["cba", "1"], ["baaca", "3"], ["aabbcc", "2"], ["a", "1"], ["ab", "1"], ["ba", "1"], ["abc", "1"], ["cba", "2"], ["aaaa", "1"], ["abcd", "1"], ["dcba", "1"], ["aaabbb", "1"], ["bbaacca", "2"], ["zyx", "1"], ["hello", "1"], ["hello", "2"], ["leetcode", "1"], ["leetcode", "4"], ["abacaba", "1"], ["abacaba", "3"], ["x", "1"], ["cbacbacba", "1"], ["cbacbacba", "2"], ["aaaaabbbbb", "1"], ["bbbbbbaaaaa", "1"], ["qwerty", "1"], ["qwerty", "6"], ["mississippi", "1"]], "expected": ["acb", "aaabc", "aabbcc", "a", "ab", "ab", "abc", "abc", "aaaa", "abcd", "adcb", "aaabbb", "aaabbcc", "xzy", "elloh", "ehllo", "codeleet", "cdeeelot", "aabacab", "aaaabbc", "x", "acbacbacb", "aaabbbccc", "aaaaabbbbb", "aaaaabbbbbb", "ertyqw", "eqrtwy", "imississipp"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "625", "slug": "out-of-boundary-paths", "id": 625, "title": "Out of Boundary Paths", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/out-of-boundary-paths/", "examples": [{"input": "m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0", "output": "6", "explanation": "Six short sequences exit the corner in time."}, {"input": "m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1", "output": "12", "explanation": "Twelve sequences of up to three moves leave the row."}, {"input": "m = 1, n = 1, maxMove = 1, startRow = 0, startColumn = 0", "output": "4", "explanation": "Every first step exits the lone cell."}], "hints": ["Memoize on (row, column, moves left): leaving the grid scores 1, zero moves scores 0.", "Otherwise sum the four neighbors' counts modulo 1,000,000,007.", "An iterative DP layer per move works too and avoids deep recursion."], "statement": "A ball sits on an `m x n` grid at (`startRow`, `startColumn`). In one move it may step to any of the four neighboring cells; a step that leaves the grid scores one successful path and ends that ball's journey. Count how many move sequences of at most `maxMove` moves take the ball out of bounds, returning the total modulo 1,000,000,007.\n\nCount paths by dynamic programming over positions and remaining moves: from each cell, the four exits either leave immediately (when no neighbor exists) or continue from the neighboring cell with one fewer move.\n\n**Constraints:**\n- `1 <= m, n <= 50`\n- `0 <= maxMove <= 50`\n- `0 <= startRow < m`, `0 <= startColumn < n`\n", "solution": "## Approach\n\nDepth-first search with memoization on (row, column, moves remaining): stepping outside counts one, running out of moves counts zero, and any other state sums its four neighbors modulo 1,000,000,007. Each state is computed once, so the total work stays proportional to the grid times the move budget.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(maxMove * m * n), one computation per state with four transitions.\n- **Space Complexity:** O(maxMove * m * n) for the memo table.\n\n## Implementation\n\n```python\nclass Solution:\n def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:\n MOD = 1_000_000_007\n from functools import lru_cache\n\n @lru_cache(maxsize=None)\n def dfs(r, c, moves):\n if r < 0 or r >= m or c < 0 or c >= n:\n return 1\n if moves == 0:\n return 0\n return (dfs(r - 1, c, moves - 1) + dfs(r + 1, c, moves - 1)\n + dfs(r, c - 1, moves - 1) + dfs(r, c + 1, moves - 1)) % MOD\n\n return dfs(startRow, startColumn, maxMove)\n```\n", "starter": {"go": "package main\n\nfunc FindPaths(m int, n int, maxMove int, startRow int, startColumn int) int {\n return 0\n}", "python": "class Solution:\n def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:\n return 0\n", "cpp": "class Solution {\npublic:\n int findPaths(int m, int n, int maxMove, int startRow, int startColumn) {\n return 0;\n }\n};"}, "fn": "findPaths", "params": [{"name": "m", "type": "int"}, {"name": "n", "type": "int"}, {"name": "maxMove", "type": "int"}, {"name": "startRow", "type": "int"}, {"name": "startColumn", "type": "int"}], "outputType": "int", "tests": [["2", "2", "2", "0", "0"], ["1", "3", "3", "0", "1"], ["1", "1", "1", "0", "0"], ["1", "1", "0", "0", "0"], ["2", "2", "0", "1", "1"], ["3", "3", "1", "1", "1"], ["2", "3", "4", "0", "1"], ["3", "2", "3", "2", "0"], ["5", "5", "5", "2", "2"], ["5", "4", "3", "0", "2"], ["4", "5", "1", "1", "2"], ["4", "3", "2", "0", "1"], ["5", "3", "3", "2", "2"], ["4", "2", "2", "3", "1"], ["4", "3", "1", "1", "1"], ["3", "5", "6", "1", "2"], ["1", "5", "7", "0", "3"], ["5", "2", "4", "3", "1"], ["5", "2", "0", "1", "1"], ["1", "3", "4", "0", "1"], ["5", "1", "1", "1", "0"], ["5", "4", "4", "2", "1"], ["4", "4", "3", "3", "2"], ["2", "4", "5", "1", "1"], ["2", "4", "4", "0", "2"], ["1", "3", "4", "0", "1"], ["4", "2", "2", "1", "1"], ["5", "4", "1", "2", "1"]], "expected": [6, 12, 4, 0, 0, 0, 44, 13, 136, 11, 0, 5, 11, 5, 0, 590, 145, 43, 0, 24, 2, 40, 11, 121, 45, 24, 5, 0], "loose": false}
|