offcode 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -2
- package/data/index.json +1 -0
- package/data/problems/01-matrix.json +1 -0
- package/data/problems/1-bit-and-2-bit-characters.json +1 -0
- package/data/problems/132-pattern.json +1 -0
- package/data/problems/2-keys-keyboard.json +1 -0
- package/data/problems/24-game.json +1 -0
- package/data/problems/3sum-closest.json +1 -0
- package/data/problems/3sum-smaller.json +1 -0
- package/data/problems/3sum-with-multiplicity.json +1 -0
- package/data/problems/3sum.json +1 -0
- package/data/problems/4-keys-keyboard.json +1 -0
- package/data/problems/4sum-ii.json +1 -0
- package/data/problems/4sum.json +1 -0
- package/data/problems/accounts-merge.json +1 -0
- package/data/problems/add-binary.json +1 -0
- package/data/problems/add-bold-tag-in-string.json +1 -0
- package/data/problems/add-digits.json +1 -0
- package/data/problems/add-one-row-to-tree.json +1 -0
- package/data/problems/add-strings.json +1 -0
- package/data/problems/add-to-array-form-of-integer.json +1 -0
- package/data/problems/add-two-numbers-ii.json +1 -0
- package/data/problems/add-two-numbers.json +1 -0
- package/data/problems/additive-number.json +1 -0
- package/data/problems/advantage-shuffle.json +1 -0
- package/data/problems/alien-dictionary.json +1 -0
- package/data/problems/all-nodes-distance-k-in-binary-tree.json +1 -0
- package/data/problems/all-oone-data-structure.json +1 -0
- package/data/problems/all-paths-from-source-to-target.json +1 -0
- package/data/problems/all-possible-full-binary-trees.json +1 -0
- package/data/problems/ambiguous-coordinates.json +1 -0
- package/data/problems/android-unlock-patterns.json +1 -0
- package/data/problems/arithmetic-slices-ii-subsequence.json +1 -0
- package/data/problems/arithmetic-slices.json +1 -0
- package/data/problems/arranging-coins.json +1 -0
- package/data/problems/array-nesting.json +1 -0
- package/data/problems/array-of-doubled-pairs.json +1 -0
- package/data/problems/array-partition.json +1 -0
- package/data/problems/assign-cookies.json +1 -0
- package/data/problems/asteroid-collision.json +1 -0
- package/data/problems/available-captures-for-rook.json +1 -0
- package/data/problems/average-of-levels-in-binary-tree.json +1 -0
- package/data/problems/backspace-string-compare.json +1 -0
- package/data/problems/bag-of-tokens.json +1 -0
- package/data/problems/balanced-binary-tree.json +1 -0
- package/data/problems/base-7.json +1 -0
- package/data/problems/baseball-game.json +1 -0
- package/data/problems/basic-absolute-value.json +1 -0
- package/data/problems/basic-array-max.json +1 -0
- package/data/problems/basic-array-min.json +1 -0
- package/data/problems/basic-array-sum-rec.json +1 -0
- package/data/problems/basic-array-sum.json +1 -0
- package/data/problems/basic-average-floor.json +1 -0
- package/data/problems/basic-bubble-sort.json +1 -0
- package/data/problems/basic-calculator-ii.json +1 -0
- package/data/problems/basic-calculator-iii.json +1 -0
- package/data/problems/basic-calculator-iv.json +1 -0
- package/data/problems/basic-calculator.json +1 -0
- package/data/problems/basic-collatz-steps.json +1 -0
- package/data/problems/basic-contains-value.json +1 -0
- package/data/problems/basic-count-above.json +1 -0
- package/data/problems/basic-count-char.json +1 -0
- package/data/problems/basic-count-digits.json +1 -0
- package/data/problems/basic-count-evens.json +1 -0
- package/data/problems/basic-count-pairs.json +1 -0
- package/data/problems/basic-count-vowels.json +1 -0
- package/data/problems/basic-count-words.json +1 -0
- package/data/problems/basic-countdown.json +1 -0
- package/data/problems/basic-double-array.json +1 -0
- package/data/problems/basic-factorial-rec.json +1 -0
- package/data/problems/basic-factorial.json +1 -0
- package/data/problems/basic-fibonacci.json +1 -0
- package/data/problems/basic-find-index.json +1 -0
- package/data/problems/basic-gcd.json +1 -0
- package/data/problems/basic-grade-letter.json +1 -0
- package/data/problems/basic-has-duplicate.json +1 -0
- package/data/problems/basic-is-even.json +1 -0
- package/data/problems/basic-is-leap-year.json +1 -0
- package/data/problems/basic-is-sorted.json +1 -0
- package/data/problems/basic-max-frequency.json +1 -0
- package/data/problems/basic-max-of-three.json +1 -0
- package/data/problems/basic-max-of-two.json +1 -0
- package/data/problems/basic-palindrome-text.json +1 -0
- package/data/problems/basic-power-rec.json +1 -0
- package/data/problems/basic-power.json +1 -0
- package/data/problems/basic-repeat-string.json +1 -0
- package/data/problems/basic-reverse-array.json +1 -0
- package/data/problems/basic-reverse-number.json +1 -0
- package/data/problems/basic-reverse-text-rec.json +1 -0
- package/data/problems/basic-reverse-text.json +1 -0
- package/data/problems/basic-second-largest.json +1 -0
- package/data/problems/basic-sort-two.json +1 -0
- package/data/problems/basic-staircase.json +1 -0
- package/data/problems/basic-string-length.json +1 -0
- package/data/problems/basic-sum-1-to-n.json +1 -0
- package/data/problems/basic-sum-digits-rec.json +1 -0
- package/data/problems/basic-sum-multiples.json +1 -0
- package/data/problems/basic-sum-of-digits.json +1 -0
- package/data/problems/basic-temperature-advice.json +1 -0
- package/data/problems/basic-to-upper.json +1 -0
- package/data/problems/basic-triangle-sum.json +1 -0
- package/data/problems/battleships-in-a-board.json +1 -0
- package/data/problems/beautiful-arrangement-ii.json +1 -0
- package/data/problems/beautiful-arrangement.json +1 -0
- package/data/problems/beautiful-array.json +1 -0
- package/data/problems/best-meeting-point.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-ii.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-iii.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-iv.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-with-cooldown.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock-with-transaction-fee.json +1 -0
- package/data/problems/best-time-to-buy-and-sell-stock.json +1 -0
- package/data/problems/binary-gap.json +1 -0
- package/data/problems/binary-number-with-alternating-bits.json +1 -0
- package/data/problems/binary-search-tree-iterator.json +1 -0
- package/data/problems/binary-search.json +1 -0
- package/data/problems/binary-subarrays-with-sum.json +1 -0
- package/data/problems/binary-tree-cameras.json +1 -0
- package/data/problems/binary-tree-inorder-traversal.json +1 -0
- package/data/problems/binary-tree-level-order-traversal-ii.json +1 -0
- package/data/problems/binary-tree-level-order-traversal.json +1 -0
- package/data/problems/binary-tree-longest-consecutive-sequence-ii.json +1 -0
- package/data/problems/binary-tree-longest-consecutive-sequence.json +1 -0
- package/data/problems/binary-tree-maximum-path-sum.json +1 -0
- package/data/problems/binary-tree-paths.json +1 -0
- package/data/problems/binary-tree-postorder-traversal.json +1 -0
- package/data/problems/binary-tree-preorder-traversal.json +1 -0
- package/data/problems/binary-tree-pruning.json +1 -0
- package/data/problems/binary-tree-right-side-view.json +1 -0
- package/data/problems/binary-tree-tilt.json +1 -0
- package/data/problems/binary-tree-upside-down.json +1 -0
- package/data/problems/binary-tree-vertical-order-traversal.json +1 -0
- package/data/problems/binary-tree-zigzag-level-order-traversal.json +1 -0
- package/data/problems/binary-trees-with-factors.json +1 -0
- package/data/problems/binary-watch.json +1 -0
- package/data/problems/bitwise-and-of-numbers-range.json +1 -0
- package/data/problems/bitwise-ors-of-subarrays.json +1 -0
- package/data/problems/boats-to-save-people.json +1 -0
- package/data/problems/bold-words-in-string.json +1 -0
- package/data/problems/bomb-enemy.json +1 -0
- package/data/problems/boundary-of-binary-tree.json +1 -0
- package/data/problems/brick-wall.json +1 -0
- package/data/problems/bricks-falling-when-hit.json +1 -0
- package/data/problems/broken-calculator.json +1 -0
- package/data/problems/buddy-strings.json +1 -0
- package/data/problems/build-a-matrix-with-conditions.json +1 -0
- package/data/problems/bulb-switcher-ii.json +1 -0
- package/data/problems/bulb-switcher.json +1 -0
- package/data/problems/bulls-and-cows.json +1 -0
- package/data/problems/burst-balloons.json +1 -0
- package/data/problems/bus-routes.json +1 -0
- package/data/problems/can-i-win.json +1 -0
- package/data/problems/can-place-flowers.json +1 -0
- package/data/problems/candy-crush.json +1 -0
- package/data/problems/candy.json +1 -0
- package/data/problems/capacity-to-ship-packages-within-d-days.json +1 -0
- package/data/problems/car-fleet.json +1 -0
- package/data/problems/car-pooling.json +1 -0
- package/data/problems/card-flipping-game.json +1 -0
- package/data/problems/cat-and-mouse.json +1 -0
- package/data/problems/chalkboard-xor-game.json +1 -0
- package/data/problems/champagne-tower.json +1 -0
- package/data/problems/cheapest-flights-within-k-stops.json +1 -0
- package/data/problems/check-completeness-of-a-binary-tree.json +1 -0
- package/data/problems/cherry-pickup.json +1 -0
- package/data/problems/circular-array-loop.json +1 -0
- package/data/problems/climbing-stairs.json +1 -0
- package/data/problems/clone-graph.json +1 -0
- package/data/problems/closest-binary-search-tree-value-ii.json +1 -0
- package/data/problems/closest-binary-search-tree-value.json +1 -0
- package/data/problems/closest-leaf-in-a-binary-tree.json +1 -0
- package/data/problems/coin-change-ii.json +1 -0
- package/data/problems/coin-change.json +1 -0
- package/data/problems/coin-path.json +1 -0
- package/data/problems/combination-sum-ii.json +1 -0
- package/data/problems/combination-sum-iii.json +1 -0
- package/data/problems/combination-sum-iv.json +1 -0
- package/data/problems/combination-sum.json +1 -0
- package/data/problems/combinations.json +1 -0
- package/data/problems/compare-version-numbers.json +1 -0
- package/data/problems/complete-binary-tree-inserter.json +1 -0
- package/data/problems/complex-number-multiplication.json +1 -0
- package/data/problems/concatenated-words.json +1 -0
- package/data/problems/concatenation-of-array.json +1 -0
- package/data/problems/consecutive-numbers-sum.json +1 -0
- package/data/problems/construct-binary-tree-from-inorder-and-postorder-traversal.json +1 -0
- package/data/problems/construct-binary-tree-from-preorder-and-inorder-traversal.json +1 -0
- package/data/problems/construct-binary-tree-from-preorder-and-postorder-traversal.json +1 -0
- package/data/problems/construct-binary-tree-from-string.json +1 -0
- package/data/problems/construct-quad-tree.json +1 -0
- package/data/problems/construct-string-from-binary-tree.json +1 -0
- package/data/problems/construct-the-rectangle.json +1 -0
- package/data/problems/contain-virus.json +1 -0
- package/data/problems/container-with-most-water.json +1 -0
- package/data/problems/contains-duplicate-ii.json +1 -0
- package/data/problems/contains-duplicate-iii.json +1 -0
- package/data/problems/contains-duplicate.json +1 -0
- package/data/problems/contiguous-array.json +1 -0
- package/data/problems/continuous-subarray-sum.json +1 -0
- package/data/problems/convert-a-number-to-hexadecimal.json +1 -0
- package/data/problems/convert-binary-search-tree-to-sorted-doubly-linked-list.json +1 -0
- package/data/problems/convert-bst-to-greater-tree.json +1 -0
- package/data/problems/convert-sorted-array-to-binary-search-tree.json +1 -0
- package/data/problems/convert-sorted-list-to-binary-search-tree.json +1 -0
- package/data/problems/convex-polygon.json +1 -0
- package/data/problems/copy-list-with-random-pointer.json +1 -0
- package/data/problems/count-and-say.json +1 -0
- package/data/problems/count-binary-substrings.json +1 -0
- package/data/problems/count-complete-tree-nodes.json +1 -0
- package/data/problems/count-different-palindromic-subsequences.json +1 -0
- package/data/problems/count-good-nodes-in-binary-tree.json +1 -0
- package/data/problems/count-numbers-with-unique-digits.json +1 -0
- package/data/problems/count-of-range-sum.json +1 -0
- package/data/problems/count-of-smaller-numbers-after-self.json +1 -0
- package/data/problems/count-primes.json +1 -0
- package/data/problems/count-the-repetitions.json +1 -0
- package/data/problems/count-unique-characters-of-all-substrings-of-a-given-string.json +1 -0
- package/data/problems/count-univalue-subtrees.json +1 -0
- package/data/problems/counting-bits.json +1 -0
- package/data/problems/couples-holding-hands.json +1 -0
- package/data/problems/course-schedule-ii.json +1 -0
- package/data/problems/course-schedule-iii.json +1 -0
- package/data/problems/course-schedule-iv.json +1 -0
- package/data/problems/course-schedule.json +1 -0
- package/data/problems/cousins-in-binary-tree.json +1 -0
- package/data/problems/cracking-the-safe.json +1 -0
- package/data/problems/create-maximum-number.json +1 -0
- package/data/problems/custom-sort-string.json +1 -0
- package/data/problems/cut-off-trees-for-golf-event.json +1 -0
- package/data/problems/daily-temperatures.json +1 -0
- package/data/problems/data-stream-as-disjoint-intervals.json +1 -0
- package/data/problems/decode-string.json +1 -0
- package/data/problems/decode-ways-ii.json +1 -0
- package/data/problems/decode-ways.json +1 -0
- package/data/problems/decoded-string-at-index.json +1 -0
- package/data/problems/degree-of-an-array.json +1 -0
- package/data/problems/delete-and-earn.json +1 -0
- package/data/problems/delete-columns-to-make-sorted-ii.json +1 -0
- package/data/problems/delete-columns-to-make-sorted-iii.json +1 -0
- package/data/problems/delete-columns-to-make-sorted.json +1 -0
- package/data/problems/delete-leaves-with-a-given-value.json +1 -0
- package/data/problems/delete-node-in-a-bst.json +1 -0
- package/data/problems/delete-node-in-a-linked-list.json +1 -0
- package/data/problems/delete-operation-for-two-strings.json +1 -0
- package/data/problems/design-add-and-search-words-data-structure.json +1 -0
- package/data/problems/design-circular-deque.json +1 -0
- package/data/problems/design-circular-queue.json +1 -0
- package/data/problems/design-compressed-string-iterator.json +1 -0
- package/data/problems/design-excel-sum-formula.json +1 -0
- package/data/problems/design-hashmap.json +1 -0
- package/data/problems/design-hashset.json +1 -0
- package/data/problems/design-hit-counter.json +1 -0
- package/data/problems/design-in-memory-file-system.json +1 -0
- package/data/problems/design-linked-list.json +1 -0
- package/data/problems/design-log-storage-system.json +1 -0
- package/data/problems/design-phone-directory.json +1 -0
- package/data/problems/design-search-autocomplete-system.json +1 -0
- package/data/problems/design-snake-game.json +1 -0
- package/data/problems/design-tic-tac-toe.json +1 -0
- package/data/problems/design-twitter.json +1 -0
- package/data/problems/detect-capital.json +1 -0
- package/data/problems/detect-squares.json +1 -0
- package/data/problems/di-string-match.json +1 -0
- package/data/problems/diagonal-traverse.json +1 -0
- package/data/problems/diameter-of-binary-tree.json +1 -0
- package/data/problems/different-ways-to-add-parentheses.json +1 -0
- package/data/problems/distinct-subsequences-ii.json +1 -0
- package/data/problems/distinct-subsequences.json +1 -0
- package/data/problems/distribute-candies.json +1 -0
- package/data/problems/distribute-coins-in-binary-tree.json +1 -0
- package/data/problems/divide-two-integers.json +1 -0
- package/data/problems/domino-and-tromino-tiling.json +1 -0
- package/data/problems/dota2-senate.json +1 -0
- package/data/problems/dungeon-game.json +1 -0
- package/data/problems/edit-distance.json +1 -0
- package/data/problems/elimination-game.json +1 -0
- package/data/problems/employee-free-time.json +1 -0
- package/data/problems/employee-importance.json +1 -0
- package/data/problems/encode-and-decode-strings.json +1 -0
- package/data/problems/encode-and-decode-tinyurl.json +1 -0
- package/data/problems/encode-n-ary-tree-to-binary-tree.json +1 -0
- package/data/problems/encode-string-with-shortest-length.json +1 -0
- package/data/problems/equal-rational-numbers.json +1 -0
- package/data/problems/equal-tree-partition.json +1 -0
- package/data/problems/erect-the-fence.json +1 -0
- package/data/problems/escape-the-ghosts.json +1 -0
- package/data/problems/evaluate-division.json +1 -0
- package/data/problems/evaluate-reverse-polish-notation.json +1 -0
- package/data/problems/exam-room.json +1 -0
- package/data/problems/excel-sheet-column-number.json +1 -0
- package/data/problems/excel-sheet-column-title.json +1 -0
- package/data/problems/exclusive-time-of-functions.json +1 -0
- package/data/problems/expression-add-operators.json +1 -0
- package/data/problems/expressive-words.json +1 -0
- package/data/problems/extra-characters-in-a-string.json +1 -0
- package/data/problems/factor-combinations.json +1 -0
- package/data/problems/factorial-trailing-zeroes.json +1 -0
- package/data/problems/fair-candy-swap.json +1 -0
- package/data/problems/falling-squares.json +1 -0
- package/data/problems/fibonacci-number.json +1 -0
- package/data/problems/find-all-anagrams-in-a-string.json +1 -0
- package/data/problems/find-all-duplicates-in-an-array.json +1 -0
- package/data/problems/find-all-numbers-disappeared-in-an-array.json +1 -0
- package/data/problems/find-anagram-mappings.json +1 -0
- package/data/problems/find-and-replace-in-string.json +1 -0
- package/data/problems/find-and-replace-pattern.json +1 -0
- package/data/problems/find-bottom-left-tree-value.json +1 -0
- package/data/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.json +1 -0
- package/data/problems/find-duplicate-file-in-system.json +1 -0
- package/data/problems/find-duplicate-subtrees.json +1 -0
- package/data/problems/find-eventual-safe-states.json +1 -0
- package/data/problems/find-first-and-last-position-of-element-in-sorted-array.json +1 -0
- package/data/problems/find-in-mountain-array.json +1 -0
- package/data/problems/find-k-closest-elements.json +1 -0
- package/data/problems/find-k-pairs-with-smallest-sums.json +1 -0
- package/data/problems/find-k-th-smallest-pair-distance.json +1 -0
- package/data/problems/find-largest-value-in-each-tree-row.json +1 -0
- package/data/problems/find-leaves-of-binary-tree.json +1 -0
- package/data/problems/find-median-from-data-stream.json +1 -0
- package/data/problems/find-minimum-in-rotated-sorted-array-ii.json +1 -0
- package/data/problems/find-minimum-in-rotated-sorted-array.json +1 -0
- package/data/problems/find-mode-in-binary-search-tree.json +1 -0
- package/data/problems/find-peak-element.json +1 -0
- package/data/problems/find-permutation.json +1 -0
- package/data/problems/find-pivot-index.json +1 -0
- package/data/problems/find-right-interval.json +1 -0
- package/data/problems/find-smallest-letter-greater-than-target.json +1 -0
- package/data/problems/find-the-celebrity.json +1 -0
- package/data/problems/find-the-closest-palindrome.json +1 -0
- package/data/problems/find-the-derangement-of-an-array.json +1 -0
- package/data/problems/find-the-difference.json +1 -0
- package/data/problems/find-the-duplicate-number.json +1 -0
- package/data/problems/find-the-index-of-the-first-occurrence-in-a-string.json +1 -0
- package/data/problems/find-the-shortest-superstring.json +1 -0
- package/data/problems/find-the-town-judge.json +1 -0
- package/data/problems/first-bad-version.json +1 -0
- package/data/problems/first-missing-positive.json +1 -0
- package/data/problems/first-unique-character-in-a-string.json +1 -0
- package/data/problems/fizz-buzz.json +1 -0
- package/data/problems/flatten-2d-vector.json +1 -0
- package/data/problems/flatten-a-multilevel-doubly-linked-list.json +1 -0
- package/data/problems/flatten-binary-tree-to-linked-list.json +1 -0
- package/data/problems/flatten-nested-list-iterator.json +1 -0
- package/data/problems/flip-binary-tree-to-match-preorder-traversal.json +1 -0
- package/data/problems/flip-equivalent-binary-trees.json +1 -0
- package/data/problems/flip-game-ii.json +1 -0
- package/data/problems/flip-game.json +1 -0
- package/data/problems/flip-string-to-monotone-increasing.json +1 -0
- package/data/problems/flipping-an-image.json +1 -0
- package/data/problems/flood-fill.json +1 -0
- package/data/problems/fraction-addition-and-subtraction.json +1 -0
- package/data/problems/fraction-to-recurring-decimal.json +1 -0
- package/data/problems/freedom-trail.json +1 -0
- package/data/problems/friends-of-appropriate-ages.json +1 -0
- package/data/problems/frog-jump.json +1 -0
- package/data/problems/fruit-into-baskets.json +1 -0
- package/data/problems/game-of-life.json +1 -0
- package/data/problems/gas-station.json +1 -0
- package/data/problems/generalized-abbreviation.json +1 -0
- package/data/problems/generate-parentheses.json +1 -0
- package/data/problems/generate-random-point-in-a-circle.json +1 -0
- package/data/problems/global-and-local-inversions.json +1 -0
- package/data/problems/goat-latin.json +1 -0
- package/data/problems/graph-valid-tree.json +1 -0
- package/data/problems/gray-code.json +1 -0
- package/data/problems/greatest-common-divisor-of-strings.json +1 -0
- package/data/problems/greatest-common-divisor-traversal.json +1 -0
- package/data/problems/group-anagrams.json +1 -0
- package/data/problems/group-shifted-strings.json +1 -0
- package/data/problems/groups-of-special-equivalent-strings.json +1 -0
- package/data/problems/guess-number-higher-or-lower-ii.json +1 -0
- package/data/problems/guess-number-higher-or-lower.json +1 -0
- package/data/problems/guess-the-word.json +1 -0
- package/data/problems/h-index-ii.json +1 -0
- package/data/problems/h-index.json +1 -0
- package/data/problems/hamming-distance.json +1 -0
- package/data/problems/hand-of-straights.json +1 -0
- package/data/problems/happy-number.json +1 -0
- package/data/problems/heaters.json +1 -0
- package/data/problems/house-robber-ii.json +1 -0
- package/data/problems/house-robber-iii.json +1 -0
- package/data/problems/house-robber.json +1 -0
- package/data/problems/image-overlap.json +1 -0
- package/data/problems/image-smoother.json +1 -0
- package/data/problems/implement-magic-dictionary.json +1 -0
- package/data/problems/implement-queue-using-stacks.json +1 -0
- package/data/problems/implement-rand10-using-rand7.json +1 -0
- package/data/problems/implement-stack-using-queues.json +1 -0
- package/data/problems/implement-trie-prefix-tree.json +1 -0
- package/data/problems/increasing-order-search-tree.json +1 -0
- package/data/problems/increasing-triplet-subsequence.json +1 -0
- package/data/problems/inorder-successor-in-bst-ii.json +1 -0
- package/data/problems/inorder-successor-in-bst.json +1 -0
- package/data/problems/insert-delete-getrandom-o1-duplicates-allowed.json +1 -0
- package/data/problems/insert-delete-getrandom-o1.json +1 -0
- package/data/problems/insert-greatest-common-divisors-in-linked-list.json +1 -0
- package/data/problems/insert-interval.json +1 -0
- package/data/problems/insert-into-a-binary-search-tree.json +1 -0
- package/data/problems/insert-into-a-sorted-circular-linked-list.json +1 -0
- package/data/problems/insertion-sort-list.json +1 -0
- package/data/problems/integer-break.json +1 -0
- package/data/problems/integer-replacement.json +1 -0
- package/data/problems/integer-to-english-words.json +1 -0
- package/data/problems/integer-to-roman.json +1 -0
- package/data/problems/interleaving-string.json +1 -0
- package/data/problems/intersection-of-two-arrays-ii.json +1 -0
- package/data/problems/intersection-of-two-arrays.json +1 -0
- package/data/problems/intersection-of-two-linked-lists.json +1 -0
- package/data/problems/interval-list-intersections.json +1 -0
- package/data/problems/invert-binary-tree.json +1 -0
- package/data/problems/ip-to-cidr.json +1 -0
- package/data/problems/ipo.json +1 -0
- package/data/problems/is-graph-bipartite.json +1 -0
- package/data/problems/is-subsequence.json +1 -0
- package/data/problems/island-perimeter.json +1 -0
- package/data/problems/isomorphic-strings.json +1 -0
- package/data/problems/jewels-and-stones.json +1 -0
- package/data/problems/jump-game-ii.json +1 -0
- package/data/problems/jump-game-vii.json +1 -0
- package/data/problems/jump-game.json +1 -0
- package/data/problems/k-closest-points-to-origin.json +1 -0
- package/data/problems/k-diff-pairs-in-an-array.json +1 -0
- package/data/problems/k-empty-slots.json +1 -0
- package/data/problems/k-inverse-pairs-array.json +1 -0
- package/data/problems/k-similar-strings.json +1 -0
- package/data/problems/k-th-smallest-in-lexicographical-order.json +1 -0
- package/data/problems/k-th-smallest-prime-fraction.json +1 -0
- package/data/problems/k-th-symbol-in-grammar.json +1 -0
- package/data/problems/keyboard-row.json +1 -0
- package/data/problems/keys-and-rooms.json +1 -0
- package/data/problems/kill-process.json +1 -0
- package/data/problems/knight-dialer.json +1 -0
- package/data/problems/knight-probability-in-chessboard.json +1 -0
- package/data/problems/koko-eating-bananas.json +1 -0
- package/data/problems/kth-largest-element-in-a-stream.json +1 -0
- package/data/problems/kth-largest-element-in-an-array.json +1 -0
- package/data/problems/kth-smallest-element-in-a-bst.json +1 -0
- package/data/problems/kth-smallest-element-in-a-sorted-matrix.json +1 -0
- package/data/problems/kth-smallest-number-in-multiplication-table.json +1 -0
- package/data/problems/largest-bst-subtree.json +1 -0
- package/data/problems/largest-component-size-by-common-factor.json +1 -0
- package/data/problems/largest-divisible-subset.json +1 -0
- package/data/problems/largest-number-at-least-twice-of-others.json +1 -0
- package/data/problems/largest-number.json +1 -0
- package/data/problems/largest-palindrome-product.json +1 -0
- package/data/problems/largest-perimeter-triangle.json +1 -0
- package/data/problems/largest-plus-sign.json +1 -0
- package/data/problems/largest-rectangle-in-histogram.json +1 -0
- package/data/problems/largest-sum-of-averages.json +1 -0
- package/data/problems/largest-time-for-given-digits.json +1 -0
- package/data/problems/largest-triangle-area.json +1 -0
- package/data/problems/last-stone-weight-ii.json +1 -0
- package/data/problems/last-stone-weight.json +1 -0
- package/data/problems/leaf-similar-trees.json +1 -0
- package/data/problems/least-operators-to-express-number.json +1 -0
- package/data/problems/lemonade-change.json +1 -0
- package/data/problems/length-of-last-word.json +1 -0
- package/data/problems/length-of-longest-fibonacci-subsequence.json +1 -0
- package/data/problems/letter-case-permutation.json +1 -0
- package/data/problems/letter-combinations-of-a-phone-number.json +1 -0
- package/data/problems/lexicographical-numbers.json +1 -0
- package/data/problems/lfu-cache.json +1 -0
- package/data/problems/license-key-formatting.json +1 -0
- package/data/problems/line-reflection.json +1 -0
- package/data/problems/linked-list-components.json +1 -0
- package/data/problems/linked-list-cycle-ii.json +1 -0
- package/data/problems/linked-list-cycle.json +1 -0
- package/data/problems/linked-list-random-node.json +1 -0
- package/data/problems/logger-rate-limiter.json +1 -0
- package/data/problems/logical-or-of-two-binary-grids-represented-as-quad-trees.json +1 -0
- package/data/problems/lonely-pixel-i.json +1 -0
- package/data/problems/lonely-pixel-ii.json +1 -0
- package/data/problems/long-pressed-name.json +1 -0
- package/data/problems/longest-absolute-file-path.json +1 -0
- package/data/problems/longest-common-prefix.json +1 -0
- package/data/problems/longest-common-subsequence.json +1 -0
- package/data/problems/longest-consecutive-sequence.json +1 -0
- package/data/problems/longest-continuous-increasing-subsequence.json +1 -0
- package/data/problems/longest-happy-string.json +1 -0
- package/data/problems/longest-harmonious-subsequence.json +1 -0
- package/data/problems/longest-increasing-path-in-a-matrix.json +1 -0
- package/data/problems/longest-increasing-subsequence.json +1 -0
- package/data/problems/longest-line-of-consecutive-one-in-matrix.json +1 -0
- package/data/problems/longest-mountain-in-array.json +1 -0
- package/data/problems/longest-palindrome.json +1 -0
- package/data/problems/longest-palindromic-subsequence.json +1 -0
- package/data/problems/longest-palindromic-substring.json +1 -0
- package/data/problems/longest-repeating-character-replacement.json +1 -0
- package/data/problems/longest-substring-with-at-least-k-repeating-characters.json +1 -0
- package/data/problems/longest-substring-with-at-most-k-distinct-characters.json +1 -0
- package/data/problems/longest-substring-with-at-most-two-distinct-characters.json +1 -0
- package/data/problems/longest-substring-without-repeating-characters.json +1 -0
- package/data/problems/longest-turbulent-subarray.json +1 -0
- package/data/problems/longest-uncommon-subsequence-i.json +1 -0
- package/data/problems/longest-uncommon-subsequence-ii.json +1 -0
- package/data/problems/longest-univalue-path.json +1 -0
- package/data/problems/longest-valid-parentheses.json +1 -0
- package/data/problems/longest-word-in-dictionary-through-deleting.json +1 -0
- package/data/problems/longest-word-in-dictionary.json +1 -0
- package/data/problems/loud-and-rich.json +1 -0
- package/data/problems/lowest-common-ancestor-of-a-binary-search-tree.json +1 -0
- package/data/problems/lowest-common-ancestor-of-a-binary-tree.json +1 -0
- package/data/problems/lru-cache.json +1 -0
- package/data/problems/magic-squares-in-grid.json +1 -0
- package/data/problems/magical-string.json +1 -0
- package/data/problems/majority-element-ii.json +1 -0
- package/data/problems/majority-element.json +1 -0
- package/data/problems/making-a-large-island.json +1 -0
- package/data/problems/map-sum-pairs.json +1 -0
- package/data/problems/masking-personal-information.json +1 -0
- package/data/problems/matchsticks-to-square.json +1 -0
- package/data/problems/max-area-of-island.json +1 -0
- package/data/problems/max-chunks-to-make-sorted-ii.json +1 -0
- package/data/problems/max-chunks-to-make-sorted.json +1 -0
- package/data/problems/max-consecutive-ones-ii.json +1 -0
- package/data/problems/max-consecutive-ones.json +1 -0
- package/data/problems/max-increase-to-keep-city-skyline.json +1 -0
- package/data/problems/max-points-on-a-line.json +1 -0
- package/data/problems/max-stack.json +1 -0
- package/data/problems/max-sum-of-rectangle-no-larger-than-k.json +1 -0
- package/data/problems/maximal-rectangle.json +1 -0
- package/data/problems/maximal-square.json +1 -0
- package/data/problems/maximize-distance-to-closest-person.json +1 -0
- package/data/problems/maximum-average-subarray-i.json +1 -0
- package/data/problems/maximum-average-subarray-ii.json +1 -0
- package/data/problems/maximum-binary-tree-ii.json +1 -0
- package/data/problems/maximum-binary-tree.json +1 -0
- package/data/problems/maximum-depth-of-binary-tree.json +1 -0
- package/data/problems/maximum-depth-of-n-ary-tree.json +1 -0
- package/data/problems/maximum-distance-in-arrays.json +1 -0
- package/data/problems/maximum-frequency-stack.json +1 -0
- package/data/problems/maximum-gap.json +1 -0
- package/data/problems/maximum-length-of-pair-chain.json +1 -0
- package/data/problems/maximum-length-of-repeated-subarray.json +1 -0
- package/data/problems/maximum-product-of-three-numbers.json +1 -0
- package/data/problems/maximum-product-of-word-lengths.json +1 -0
- package/data/problems/maximum-product-subarray.json +1 -0
- package/data/problems/maximum-size-subarray-sum-equals-k.json +1 -0
- package/data/problems/maximum-subarray.json +1 -0
- package/data/problems/maximum-sum-circular-subarray.json +1 -0
- package/data/problems/maximum-sum-of-3-non-overlapping-subarrays.json +1 -0
- package/data/problems/maximum-swap.json +1 -0
- package/data/problems/maximum-vacation-days.json +1 -0
- package/data/problems/maximum-width-of-binary-tree.json +1 -0
- package/data/problems/maximum-width-ramp.json +1 -0
- package/data/problems/maximum-xor-of-two-numbers-in-an-array.json +1 -0
- package/data/problems/median-of-two-sorted-arrays.json +1 -0
- package/data/problems/meeting-rooms-ii.json +1 -0
- package/data/problems/meeting-rooms-iii.json +1 -0
- package/data/problems/meeting-rooms.json +1 -0
- package/data/problems/merge-intervals.json +1 -0
- package/data/problems/merge-k-sorted-lists.json +1 -0
- package/data/problems/merge-sorted-array.json +1 -0
- package/data/problems/merge-strings-alternately.json +1 -0
- package/data/problems/merge-triplets-to-form-target-triplet.json +1 -0
- package/data/problems/merge-two-binary-trees.json +1 -0
- package/data/problems/merge-two-sorted-lists.json +1 -0
- package/data/problems/middle-of-the-linked-list.json +1 -0
- package/data/problems/min-cost-climbing-stairs.json +1 -0
- package/data/problems/min-cost-to-connect-all-points.json +1 -0
- package/data/problems/min-stack.json +1 -0
- package/data/problems/minesweeper.json +1 -0
- package/data/problems/mini-parser.json +1 -0
- package/data/problems/minimize-malware-spread-ii.json +1 -0
- package/data/problems/minimize-malware-spread.json +1 -0
- package/data/problems/minimize-max-distance-to-gas-station.json +1 -0
- package/data/problems/minimum-absolute-difference-in-bst.json +1 -0
- package/data/problems/minimum-add-to-make-parentheses-valid.json +1 -0
- package/data/problems/minimum-area-rectangle-ii.json +1 -0
- package/data/problems/minimum-area-rectangle.json +1 -0
- package/data/problems/minimum-array-end.json +1 -0
- package/data/problems/minimum-ascii-delete-sum-for-two-strings.json +1 -0
- package/data/problems/minimum-cost-for-tickets.json +1 -0
- package/data/problems/minimum-cost-to-hire-k-workers.json +1 -0
- package/data/problems/minimum-cost-to-merge-stones.json +1 -0
- package/data/problems/minimum-depth-of-binary-tree.json +1 -0
- package/data/problems/minimum-distance-between-bst-nodes.json +1 -0
- package/data/problems/minimum-factorization.json +1 -0
- package/data/problems/minimum-falling-path-sum.json +1 -0
- package/data/problems/minimum-genetic-mutation.json +1 -0
- package/data/problems/minimum-height-trees.json +1 -0
- package/data/problems/minimum-increment-to-make-array-unique.json +1 -0
- package/data/problems/minimum-index-sum-of-two-lists.json +1 -0
- package/data/problems/minimum-interval-to-include-each-query.json +1 -0
- package/data/problems/minimum-moves-to-equal-array-elements-ii.json +1 -0
- package/data/problems/minimum-moves-to-equal-array-elements.json +1 -0
- package/data/problems/minimum-number-of-arrows-to-burst-balloons.json +1 -0
- package/data/problems/minimum-number-of-k-consecutive-bit-flips.json +1 -0
- package/data/problems/minimum-number-of-refueling-stops.json +1 -0
- package/data/problems/minimum-path-sum.json +1 -0
- package/data/problems/minimum-size-subarray-sum.json +1 -0
- package/data/problems/minimum-swaps-to-make-sequences-increasing.json +1 -0
- package/data/problems/minimum-time-difference.json +1 -0
- package/data/problems/minimum-unique-word-abbreviation.json +1 -0
- package/data/problems/minimum-window-subsequence.json +1 -0
- package/data/problems/minimum-window-substring.json +1 -0
- package/data/problems/mirror-reflection.json +1 -0
- package/data/problems/missing-number.json +1 -0
- package/data/problems/missing-ranges.json +1 -0
- package/data/problems/monotone-increasing-digits.json +1 -0
- package/data/problems/monotonic-array.json +1 -0
- package/data/problems/most-common-word.json +1 -0
- package/data/problems/most-frequent-subtree-sum.json +1 -0
- package/data/problems/most-profit-assigning-work.json +1 -0
- package/data/problems/most-stones-removed-with-same-row-or-column.json +1 -0
- package/data/problems/move-zeroes.json +1 -0
- package/data/problems/moving-average-from-data-stream.json +1 -0
- package/data/problems/multiply-strings.json +1 -0
- package/data/problems/my-calendar-i.json +1 -0
- package/data/problems/my-calendar-ii.json +1 -0
- package/data/problems/my-calendar-iii.json +1 -0
- package/data/problems/n-ary-tree-level-order-traversal.json +1 -0
- package/data/problems/n-ary-tree-postorder-traversal.json +1 -0
- package/data/problems/n-ary-tree-preorder-traversal.json +1 -0
- package/data/problems/n-queens-ii.json +1 -0
- package/data/problems/n-queens.json +1 -0
- package/data/problems/n-repeated-element-in-size-2n-array.json +1 -0
- package/data/problems/n-th-tribonacci-number.json +1 -0
- package/data/problems/nested-list-weight-sum-ii.json +1 -0
- package/data/problems/nested-list-weight-sum.json +1 -0
- package/data/problems/network-delay-time.json +1 -0
- package/data/problems/new-21-game.json +1 -0
- package/data/problems/next-closest-time.json +1 -0
- package/data/problems/next-greater-element-i.json +1 -0
- package/data/problems/next-greater-element-ii.json +1 -0
- package/data/problems/next-greater-element-iii.json +1 -0
- package/data/problems/next-permutation.json +1 -0
- package/data/problems/nim-game.json +1 -0
- package/data/problems/non-decreasing-array.json +1 -0
- package/data/problems/non-decreasing-subsequences.json +1 -0
- package/data/problems/non-negative-integers-without-consecutive-ones.json +1 -0
- package/data/problems/non-overlapping-intervals.json +1 -0
- package/data/problems/nth-digit.json +1 -0
- package/data/problems/nth-magical-number.json +1 -0
- package/data/problems/number-complement.json +1 -0
- package/data/problems/number-of-1-bits.json +1 -0
- package/data/problems/number-of-atoms.json +1 -0
- package/data/problems/number-of-boomerangs.json +1 -0
- package/data/problems/number-of-connected-components-in-an-undirected-graph.json +1 -0
- package/data/problems/number-of-corner-rectangles.json +1 -0
- package/data/problems/number-of-digit-one.json +1 -0
- package/data/problems/number-of-distinct-islands-ii.json +1 -0
- package/data/problems/number-of-distinct-islands.json +1 -0
- package/data/problems/number-of-islands-ii.json +1 -0
- package/data/problems/number-of-islands.json +1 -0
- package/data/problems/number-of-lines-to-write-string.json +1 -0
- package/data/problems/number-of-longest-increasing-subsequence.json +1 -0
- package/data/problems/number-of-matching-subsequences.json +1 -0
- package/data/problems/number-of-music-playlists.json +1 -0
- package/data/problems/number-of-provinces.json +1 -0
- package/data/problems/number-of-recent-calls.json +1 -0
- package/data/problems/number-of-segments-in-a-string.json +1 -0
- package/data/problems/number-of-squareful-arrays.json +1 -0
- package/data/problems/number-of-subarrays-with-bounded-maximum.json +1 -0
- package/data/problems/numbers-at-most-n-given-digit-set.json +1 -0
- package/data/problems/numbers-with-same-consecutive-differences.json +1 -0
- package/data/problems/odd-even-jump.json +1 -0
- package/data/problems/odd-even-linked-list.json +1 -0
- package/data/problems/one-edit-distance.json +1 -0
- package/data/problems/ones-and-zeroes.json +1 -0
- package/data/problems/online-election.json +1 -0
- package/data/problems/online-stock-span.json +1 -0
- package/data/problems/open-the-lock.json +1 -0
- package/data/problems/optimal-account-balancing.json +1 -0
- package/data/problems/optimal-division.json +1 -0
- package/data/problems/orderly-queue.json +1 -0
- package/data/problems/out-of-boundary-paths.json +1 -0
- package/data/problems/output-contest-matches.json +1 -0
- package/data/problems/pacific-atlantic-water-flow.json +1 -0
- package/data/problems/paint-fence.json +1 -0
- package/data/problems/paint-house-ii.json +1 -0
- package/data/problems/paint-house.json +1 -0
- package/data/problems/palindrome-linked-list.json +1 -0
- package/data/problems/palindrome-number.json +1 -0
- package/data/problems/palindrome-pairs.json +1 -0
- package/data/problems/palindrome-partitioning-ii.json +1 -0
- package/data/problems/palindrome-partitioning.json +1 -0
- package/data/problems/palindrome-permutation-ii.json +1 -0
- package/data/problems/palindrome-permutation.json +1 -0
- package/data/problems/palindromic-substrings.json +1 -0
- package/data/problems/pancake-sorting.json +1 -0
- package/data/problems/parse-lisp-expression.json +1 -0
- package/data/problems/partition-array-into-disjoint-intervals.json +1 -0
- package/data/problems/partition-equal-subset-sum.json +1 -0
- package/data/problems/partition-labels.json +1 -0
- package/data/problems/partition-list.json +1 -0
- package/data/problems/partition-to-k-equal-sum-subsets.json +1 -0
- package/data/problems/pascals-triangle-ii.json +1 -0
- package/data/problems/pascals-triangle.json +1 -0
- package/data/problems/patching-array.json +1 -0
- package/data/problems/path-sum-ii.json +1 -0
- package/data/problems/path-sum-iii.json +1 -0
- package/data/problems/path-sum-iv.json +1 -0
- package/data/problems/path-sum.json +1 -0
- package/data/problems/path-with-minimum-effort.json +1 -0
- package/data/problems/peak-index-in-a-mountain-array.json +1 -0
- package/data/problems/peeking-iterator.json +1 -0
- package/data/problems/perfect-number.json +1 -0
- package/data/problems/perfect-rectangle.json +1 -0
- package/data/problems/perfect-squares.json +1 -0
- package/data/problems/permutation-in-string.json +1 -0
- package/data/problems/permutation-sequence.json +1 -0
- package/data/problems/permutations-ii.json +1 -0
- package/data/problems/permutations.json +1 -0
- package/data/problems/plus-one-linked-list.json +1 -0
- package/data/problems/plus-one.json +1 -0
- package/data/problems/poor-pigs.json +1 -0
- package/data/problems/populating-next-right-pointers-in-each-node-ii.json +1 -0
- package/data/problems/populating-next-right-pointers-in-each-node.json +1 -0
- package/data/problems/positions-of-large-groups.json +1 -0
- package/data/problems/possible-bipartition.json +1 -0
- package/data/problems/pour-water.json +1 -0
- package/data/problems/power-of-four.json +1 -0
- package/data/problems/power-of-three.json +1 -0
- package/data/problems/power-of-two.json +1 -0
- package/data/problems/powerful-integers.json +1 -0
- package/data/problems/powx-n.json +1 -0
- package/data/problems/predict-the-winner.json +1 -0
- package/data/problems/prefix-and-suffix-search.json +1 -0
- package/data/problems/preimage-size-of-factorial-zeroes-function.json +1 -0
- package/data/problems/prime-number-of-set-bits-in-binary-representation.json +1 -0
- package/data/problems/prime-palindrome.json +1 -0
- package/data/problems/print-binary-tree.json +1 -0
- package/data/problems/prison-cells-after-n-days.json +1 -0
- package/data/problems/product-of-array-except-self.json +1 -0
- package/data/problems/profitable-schemes.json +1 -0
- package/data/problems/projection-area-of-3d-shapes.json +1 -0
- package/data/problems/push-dominoes.json +1 -0
- package/data/problems/pyramid-transition-matrix.json +1 -0
- package/data/problems/queue-reconstruction-by-height.json +1 -0
- package/data/problems/rabbits-in-forest.json +1 -0
- package/data/problems/race-car.json +1 -0
- package/data/problems/random-flip-matrix.json +1 -0
- package/data/problems/random-pick-index.json +1 -0
- package/data/problems/random-pick-with-blacklist.json +1 -0
- package/data/problems/random-pick-with-weight.json +1 -0
- package/data/problems/random-point-in-non-overlapping-rectangles.json +1 -0
- package/data/problems/range-addition-ii.json +1 -0
- package/data/problems/range-addition.json +1 -0
- package/data/problems/range-module.json +1 -0
- package/data/problems/range-sum-of-bst.json +1 -0
- package/data/problems/range-sum-query-2d-immutable.json +1 -0
- package/data/problems/range-sum-query-2d-mutable.json +1 -0
- package/data/problems/range-sum-query-immutable.json +1 -0
- package/data/problems/range-sum-query-mutable.json +1 -0
- package/data/problems/ransom-note.json +1 -0
- package/data/problems/reach-a-number.json +1 -0
- package/data/problems/reachable-nodes-in-subdivided-graph.json +1 -0
- package/data/problems/reaching-points.json +1 -0
- package/data/problems/read-n-characters-given-read4-ii-call-multiple-times.json +1 -0
- package/data/problems/read-n-characters-given-read4.json +1 -0
- package/data/problems/rearrange-string-k-distance-apart.json +1 -0
- package/data/problems/reconstruct-itinerary.json +1 -0
- package/data/problems/reconstruct-original-digits-from-english.json +1 -0
- package/data/problems/recover-binary-search-tree.json +1 -0
- package/data/problems/rectangle-area-ii.json +1 -0
- package/data/problems/rectangle-area.json +1 -0
- package/data/problems/rectangle-overlap.json +1 -0
- package/data/problems/redundant-connection-ii.json +1 -0
- package/data/problems/redundant-connection.json +1 -0
- package/data/problems/regions-cut-by-slashes.json +1 -0
- package/data/problems/regular-expression-matching.json +1 -0
- package/data/problems/relative-ranks.json +1 -0
- package/data/problems/remove-9.json +1 -0
- package/data/problems/remove-boxes.json +1 -0
- package/data/problems/remove-comments.json +1 -0
- package/data/problems/remove-duplicate-letters.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-array-ii.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-array.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-list-ii.json +1 -0
- package/data/problems/remove-duplicates-from-sorted-list.json +1 -0
- package/data/problems/remove-element.json +1 -0
- package/data/problems/remove-invalid-parentheses.json +1 -0
- package/data/problems/remove-k-digits.json +1 -0
- package/data/problems/remove-linked-list-elements.json +1 -0
- package/data/problems/remove-nth-node-from-end-of-list.json +1 -0
- package/data/problems/reorder-data-in-log-files.json +1 -0
- package/data/problems/reorder-list.json +1 -0
- package/data/problems/reordered-power-of-2.json +1 -0
- package/data/problems/reorganize-string.json +1 -0
- package/data/problems/repeated-dna-sequences.json +1 -0
- package/data/problems/repeated-string-match.json +1 -0
- package/data/problems/repeated-substring-pattern.json +1 -0
- package/data/problems/replace-words.json +1 -0
- package/data/problems/reshape-the-matrix.json +1 -0
- package/data/problems/restore-ip-addresses.json +1 -0
- package/data/problems/reveal-cards-in-increasing-order.json +1 -0
- package/data/problems/reverse-bits.json +1 -0
- package/data/problems/reverse-integer.json +1 -0
- package/data/problems/reverse-linked-list-ii.json +1 -0
- package/data/problems/reverse-linked-list.json +1 -0
- package/data/problems/reverse-nodes-in-k-group.json +1 -0
- package/data/problems/reverse-only-letters.json +1 -0
- package/data/problems/reverse-pairs.json +1 -0
- package/data/problems/reverse-string-ii.json +1 -0
- package/data/problems/reverse-string.json +1 -0
- package/data/problems/reverse-vowels-of-a-string.json +1 -0
- package/data/problems/reverse-words-in-a-string-ii.json +1 -0
- package/data/problems/reverse-words-in-a-string-iii.json +1 -0
- package/data/problems/reverse-words-in-a-string.json +1 -0
- package/data/problems/rle-iterator.json +1 -0
- package/data/problems/robot-return-to-origin.json +1 -0
- package/data/problems/robot-room-cleaner.json +1 -0
- package/data/problems/roman-to-integer.json +1 -0
- package/data/problems/rotate-array.json +1 -0
- package/data/problems/rotate-function.json +1 -0
- package/data/problems/rotate-image.json +1 -0
- package/data/problems/rotate-list.json +1 -0
- package/data/problems/rotate-string.json +1 -0
- package/data/problems/rotated-digits.json +1 -0
- package/data/problems/rotting-oranges.json +1 -0
- package/data/problems/russian-doll-envelopes.json +1 -0
- package/data/problems/same-tree.json +1 -0
- package/data/problems/satisfiability-of-equality-equations.json +1 -0
- package/data/problems/score-after-flipping-matrix.json +1 -0
- package/data/problems/score-of-parentheses.json +1 -0
- package/data/problems/scramble-string.json +1 -0
- package/data/problems/search-a-2d-matrix-ii.json +1 -0
- package/data/problems/search-a-2d-matrix.json +1 -0
- package/data/problems/search-in-a-binary-search-tree.json +1 -0
- package/data/problems/search-in-a-sorted-array-of-unknown-size.json +1 -0
- package/data/problems/search-in-rotated-sorted-array-ii.json +1 -0
- package/data/problems/search-in-rotated-sorted-array.json +1 -0
- package/data/problems/search-insert-position.json +1 -0
- package/data/problems/second-minimum-node-in-a-binary-tree.json +1 -0
- package/data/problems/self-crossing.json +1 -0
- package/data/problems/self-dividing-numbers.json +1 -0
- package/data/problems/sentence-screen-fitting.json +1 -0
- package/data/problems/sentence-similarity-ii.json +1 -0
- package/data/problems/sentence-similarity.json +1 -0
- package/data/problems/sequence-reconstruction.json +1 -0
- package/data/problems/serialize-and-deserialize-binary-tree.json +1 -0
- package/data/problems/serialize-and-deserialize-bst.json +1 -0
- package/data/problems/serialize-and-deserialize-n-ary-tree.json +1 -0
- package/data/problems/set-intersection-size-at-least-two.json +1 -0
- package/data/problems/set-matrix-zeroes.json +1 -0
- package/data/problems/set-mismatch.json +1 -0
- package/data/problems/shifting-letters.json +1 -0
- package/data/problems/shopping-offers.json +1 -0
- package/data/problems/short-encoding-of-words.json +1 -0
- package/data/problems/shortest-bridge.json +1 -0
- package/data/problems/shortest-completing-word.json +1 -0
- package/data/problems/shortest-distance-from-all-buildings.json +1 -0
- package/data/problems/shortest-distance-to-a-character.json +1 -0
- package/data/problems/shortest-palindrome.json +1 -0
- package/data/problems/shortest-path-to-get-all-keys.json +1 -0
- package/data/problems/shortest-path-visiting-all-nodes.json +1 -0
- package/data/problems/shortest-subarray-with-sum-at-least-k.json +1 -0
- package/data/problems/shortest-unsorted-continuous-subarray.json +1 -0
- package/data/problems/shortest-word-distance-ii.json +1 -0
- package/data/problems/shortest-word-distance-iii.json +1 -0
- package/data/problems/shortest-word-distance.json +1 -0
- package/data/problems/shuffle-an-array.json +1 -0
- package/data/problems/similar-rgb-color.json +1 -0
- package/data/problems/similar-string-groups.json +1 -0
- package/data/problems/simplify-path.json +1 -0
- package/data/problems/single-element-in-a-sorted-array.json +1 -0
- package/data/problems/single-number-ii.json +1 -0
- package/data/problems/single-number-iii.json +1 -0
- package/data/problems/single-number.json +1 -0
- package/data/problems/single-threaded-cpu.json +1 -0
- package/data/problems/sliding-puzzle.json +1 -0
- package/data/problems/sliding-window-maximum.json +1 -0
- package/data/problems/sliding-window-median.json +1 -0
- package/data/problems/smallest-good-base.json +1 -0
- package/data/problems/smallest-range-covering-elements-from-k-lists.json +1 -0
- package/data/problems/smallest-range-i.json +1 -0
- package/data/problems/smallest-range-ii.json +1 -0
- package/data/problems/smallest-rectangle-enclosing-black-pixels.json +1 -0
- package/data/problems/smallest-rotation-with-highest-score.json +1 -0
- package/data/problems/smallest-string-starting-from-leaf.json +1 -0
- package/data/problems/smallest-subtree-with-all-the-deepest-nodes.json +1 -0
- package/data/problems/snakes-and-ladders.json +1 -0
- package/data/problems/solve-the-equation.json +1 -0
- package/data/problems/sort-an-array.json +1 -0
- package/data/problems/sort-array-by-parity-ii.json +1 -0
- package/data/problems/sort-array-by-parity.json +1 -0
- package/data/problems/sort-characters-by-frequency.json +1 -0
- package/data/problems/sort-colors.json +1 -0
- package/data/problems/sort-list.json +1 -0
- package/data/problems/sort-transformed-array.json +1 -0
- package/data/problems/soup-servings.json +1 -0
- package/data/problems/sparse-matrix-multiplication.json +1 -0
- package/data/problems/special-binary-string.json +1 -0
- package/data/problems/spiral-matrix-ii.json +1 -0
- package/data/problems/spiral-matrix-iii.json +1 -0
- package/data/problems/spiral-matrix.json +1 -0
- package/data/problems/split-array-into-consecutive-subsequences.json +1 -0
- package/data/problems/split-array-into-fibonacci-sequence.json +1 -0
- package/data/problems/split-array-largest-sum.json +1 -0
- package/data/problems/split-array-with-equal-sum.json +1 -0
- package/data/problems/split-array-with-same-average.json +1 -0
- package/data/problems/split-bst.json +1 -0
- package/data/problems/split-concatenated-strings.json +1 -0
- package/data/problems/split-linked-list-in-parts.json +1 -0
- package/data/problems/sqrtx.json +1 -0
- package/data/problems/squares-of-a-sorted-array.json +1 -0
- package/data/problems/squirrel-simulation.json +1 -0
- package/data/problems/stamping-the-sequence.json +1 -0
- package/data/problems/stickers-to-spell-word.json +1 -0
- package/data/problems/stone-game-ii.json +1 -0
- package/data/problems/stone-game-iii.json +1 -0
- package/data/problems/stone-game.json +1 -0
- package/data/problems/strange-printer.json +1 -0
- package/data/problems/string-compression.json +1 -0
- package/data/problems/string-to-integer-atoi.json +1 -0
- package/data/problems/string-without-aaa-or-bbb.json +1 -0
- package/data/problems/strobogrammatic-number-ii.json +1 -0
- package/data/problems/strobogrammatic-number-iii.json +1 -0
- package/data/problems/strobogrammatic-number.json +1 -0
- package/data/problems/strong-password-checker.json +1 -0
- package/data/problems/student-attendance-record-i.json +1 -0
- package/data/problems/student-attendance-record-ii.json +1 -0
- package/data/problems/subarray-product-less-than-k.json +1 -0
- package/data/problems/subarray-sum-equals-k.json +1 -0
- package/data/problems/subarray-sums-divisible-by-k.json +1 -0
- package/data/problems/subarrays-with-k-different-integers.json +1 -0
- package/data/problems/subdomain-visit-count.json +1 -0
- package/data/problems/subsets-ii.json +1 -0
- package/data/problems/subsets.json +1 -0
- package/data/problems/substring-with-concatenation-of-all-words.json +1 -0
- package/data/problems/subtree-of-another-tree.json +1 -0
- package/data/problems/sudoku-solver.json +1 -0
- package/data/problems/sum-of-all-subset-xor-totals.json +1 -0
- package/data/problems/sum-of-distances-in-tree.json +1 -0
- package/data/problems/sum-of-even-numbers-after-queries.json +1 -0
- package/data/problems/sum-of-left-leaves.json +1 -0
- package/data/problems/sum-of-square-numbers.json +1 -0
- package/data/problems/sum-of-subarray-minimums.json +1 -0
- package/data/problems/sum-of-subsequence-widths.json +1 -0
- package/data/problems/sum-of-two-integers.json +1 -0
- package/data/problems/sum-root-to-leaf-numbers.json +1 -0
- package/data/problems/summary-ranges.json +1 -0
- package/data/problems/super-egg-drop.json +1 -0
- package/data/problems/super-palindromes.json +1 -0
- package/data/problems/super-pow.json +1 -0
- package/data/problems/super-ugly-number.json +1 -0
- package/data/problems/super-washing-machines.json +1 -0
- package/data/problems/surface-area-of-3d-shapes.json +1 -0
- package/data/problems/surrounded-regions.json +1 -0
- package/data/problems/swap-adjacent-in-lr-string.json +1 -0
- package/data/problems/swap-nodes-in-pairs.json +1 -0
- package/data/problems/swim-in-rising-water.json +1 -0
- package/data/problems/symmetric-tree.json +1 -0
- package/data/problems/tag-validator.json +1 -0
- package/data/problems/tallest-billboard.json +1 -0
- package/data/problems/target-sum.json +1 -0
- package/data/problems/task-scheduler.json +1 -0
- package/data/problems/teemo-attacking.json +1 -0
- package/data/problems/ternary-expression-parser.json +1 -0
- package/data/problems/text-justification.json +1 -0
- package/data/problems/the-maze-ii.json +1 -0
- package/data/problems/the-maze-iii.json +1 -0
- package/data/problems/the-maze.json +1 -0
- package/data/problems/the-skyline-problem.json +1 -0
- package/data/problems/third-maximum-number.json +1 -0
- package/data/problems/three-equal-parts.json +1 -0
- package/data/problems/time-based-key-value-store.json +1 -0
- package/data/problems/to-lower-case.json +1 -0
- package/data/problems/toeplitz-matrix.json +1 -0
- package/data/problems/top-k-frequent-elements.json +1 -0
- package/data/problems/top-k-frequent-words.json +1 -0
- package/data/problems/total-hamming-distance.json +1 -0
- package/data/problems/transform-to-chessboard.json +1 -0
- package/data/problems/transpose-matrix.json +1 -0
- package/data/problems/trapping-rain-water-ii.json +1 -0
- package/data/problems/trapping-rain-water.json +1 -0
- package/data/problems/triangle.json +1 -0
- package/data/problems/trim-a-binary-search-tree.json +1 -0
- package/data/problems/triples-with-bitwise-and-equal-to-zero.json +1 -0
- package/data/problems/two-sum-ii-input-array-is-sorted.json +1 -0
- package/data/problems/two-sum-iii-data-structure-design.json +1 -0
- package/data/problems/two-sum-iv-input-is-a-bst.json +1 -0
- package/data/problems/two-sum.json +1 -0
- package/data/problems/ugly-number-ii.json +1 -0
- package/data/problems/ugly-number.json +1 -0
- package/data/problems/uncommon-words-from-two-sentences.json +1 -0
- package/data/problems/unique-binary-search-trees-ii.json +1 -0
- package/data/problems/unique-binary-search-trees.json +1 -0
- package/data/problems/unique-email-addresses.json +1 -0
- package/data/problems/unique-morse-code-words.json +1 -0
- package/data/problems/unique-paths-ii.json +1 -0
- package/data/problems/unique-paths-iii.json +1 -0
- package/data/problems/unique-paths.json +1 -0
- package/data/problems/unique-substrings-in-wraparound-string.json +1 -0
- package/data/problems/unique-word-abbreviation.json +1 -0
- package/data/problems/univalued-binary-tree.json +1 -0
- package/data/problems/utf-8-validation.json +1 -0
- package/data/problems/valid-anagram.json +1 -0
- package/data/problems/valid-mountain-array.json +1 -0
- package/data/problems/valid-number.json +1 -0
- package/data/problems/valid-palindrome-ii.json +1 -0
- package/data/problems/valid-palindrome.json +1 -0
- package/data/problems/valid-parentheses.json +1 -0
- package/data/problems/valid-parenthesis-string.json +1 -0
- package/data/problems/valid-perfect-square.json +1 -0
- package/data/problems/valid-permutations-for-di-sequence.json +1 -0
- package/data/problems/valid-square.json +1 -0
- package/data/problems/valid-sudoku.json +1 -0
- package/data/problems/valid-tic-tac-toe-state.json +1 -0
- package/data/problems/valid-triangle-number.json +1 -0
- package/data/problems/valid-word-abbreviation.json +1 -0
- package/data/problems/valid-word-square.json +1 -0
- package/data/problems/validate-binary-search-tree.json +1 -0
- package/data/problems/validate-ip-address.json +1 -0
- package/data/problems/validate-stack-sequences.json +1 -0
- package/data/problems/verify-preorder-sequence-in-binary-search-tree.json +1 -0
- package/data/problems/verify-preorder-serialization-of-a-binary-tree.json +1 -0
- package/data/problems/verifying-an-alien-dictionary.json +1 -0
- package/data/problems/vertical-order-traversal-of-a-binary-tree.json +1 -0
- package/data/problems/vowel-spellchecker.json +1 -0
- package/data/problems/walking-robot-simulation.json +1 -0
- package/data/problems/walls-and-gates.json +1 -0
- package/data/problems/water-and-jug-problem.json +1 -0
- package/data/problems/wiggle-sort-ii.json +1 -0
- package/data/problems/wiggle-sort.json +1 -0
- package/data/problems/wiggle-subsequence.json +1 -0
- package/data/problems/wildcard-matching.json +1 -0
- package/data/problems/word-abbreviation.json +1 -0
- package/data/problems/word-break-ii.json +1 -0
- package/data/problems/word-break.json +1 -0
- package/data/problems/word-ladder-ii.json +1 -0
- package/data/problems/word-ladder.json +1 -0
- package/data/problems/word-pattern-ii.json +1 -0
- package/data/problems/word-pattern.json +1 -0
- package/data/problems/word-search-ii.json +1 -0
- package/data/problems/word-search.json +1 -0
- package/data/problems/word-squares.json +1 -0
- package/data/problems/word-subsets.json +1 -0
- package/data/problems/x-of-a-kind-in-a-deck-of-cards.json +1 -0
- package/data/problems/zigzag-conversion.json +1 -0
- package/data/problems/zigzag-iterator.json +1 -0
- package/data/problems/zuma-game.json +1 -0
- package/dist/cli.js +793 -0
- package/dist/web/assets/index-7tyR3Zsa.js +147 -0
- package/dist/web/assets/index-oer4U46K.css +1 -0
- package/dist/web/index.html +13 -0
- package/package.json +42 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "560", "slug": "random-point-in-non-overlapping-rectangles", "id": 560, "title": "Random Point in Non-overlapping Rectangles", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/random-point-in-non-overlapping-rectangles/", "examples": [{"input": "rects = [[-2,-2,1,1],[2,2,4,6]]", "output": "[0,0]", "explanation": "Both [0,0] (first rectangle) and [3,3] (second rectangle) are valid answers."}, {"input": "rects = [[0,0,0,0]]", "output": "[0,0]", "explanation": "The single-cell rectangle covers exactly one point."}], "hints": ["Adaptation: return any covered integer point; the judge only checks that it falls inside some rectangle.", "The bottom-left corner of the first rectangle is always a valid answer.", "A fully random solution would weight rectangles by their point counts, but determinism also passes here."], "statement": "You are given several axis-aligned rectangles that never overlap. Each rectangle is written as `[a, b, x, y]`, where `(a, b)` is its bottom-left corner and `(x, y)` is its top-right corner. Every integer coordinate point on the border or inside counts as covered.\n\nThe original challenge asks for a class that returns a uniformly random covered integer point on each `pick` call. This offline adaptation simplifies the task: implement a function that returns any single integer point `[u, v]` lying inside at least one of the rectangles.\n\nThe checker does not test randomness or distribution \u2014 it only verifies containment. Hence returning a corner of the first rectangle is accepted, as is any other covered point.\n\n**Constraints:**\n- `1 <= rects.length <= 100`\n- Each rectangle has 4 entries with `a < x` or `a == x` allowed only for degenerate single points; generally `a <= x` and `b <= y`\n- Coordinates fit in 32-bit signed range\n- Rectangles do not overlap\n", "solution": "## Approach\n\nContainment is the only checked property, so a deterministic corner suffices. Returning the bottom-left corner of the first rectangle is guaranteed to lie on its border and therefore inside the covered set. A truly uniform sampler would weight by area, but it is unnecessary for this adapted checker.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) to return the corner.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def pickPoint(self, rects: List[List[int]]) -> List[int]:\n return [rects[0][0], rects[0][1]]\n```\n", "starter": {"go": "package main\n\nfunc PickPoint(rects [][]int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def pickPoint(self, rects: List[List[int]]) -> List[int]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> pickPoint(vector<vector<int>>& rects) {\n return {};\n }\n};"}, "fn": "pickPoint", "params": [{"name": "rects", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[[-2,-2,1,1],[2,2,4,6]]"], ["[[0,0,0,0]]"], ["[[1,1,2,2]]"], ["[[0,0,1,1]]"], ["[[5,5,5,5]]"], ["[[-10,-10,10,10]]"], ["[[0,0,2,2],[3,3,5,5]]"], ["[[1,1,1,1],[2,2,2,2],[3,3,3,3]]"], ["[[-5,0,0,5]]"], ["[[0,0,10,0]]"], ["[[0,0,0,10]]"], ["[[100,100,200,200]]"], ["[[-1000000,-1000000,1000000,1000000]]"], ["[[0,0,1,0],[0,2,1,2]]"], ["[[1,2,3,4]]"], ["[[0,0,5,5],[10,10,15,15],[20,0,25,5]]"], ["[[-2,-2,-1,-1]]"], ["[[0,0,0,1]]"], ["[[0,0,1,0]]"], ["[[-3,-3,3,3],[10,10,11,11]]"], ["[[7,7,9,9]]"], ["[[0,5,5,10]]"], ["[[-1,-1,0,0],[1,1,2,2]]"], ["[[2,2,4,6]]"], ["[[0,0,3,1]]"], ["[[10,0,10,10]]"], ["[[0,10,10,10]]"], ["[[-5,-5,-5,5]]"]], "expected": [[-2, -2], [0, 0], [1, 1], [0, 0], [5, 5], [-10, -10], [0, 0], [1, 1], [-5, 0], [0, 0], [0, 0], [100, 100], [-1000000, -1000000], [0, 0], [1, 2], [0, 0], [-2, -2], [0, 0], [0, 0], [-3, -3], [7, 7], [0, 5], [-1, -1], [2, 2], [0, 0], [10, 0], [0, 10], [-5, -5]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "637", "slug": "range-addition-ii", "id": 637, "title": "Range Addition II", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/range-addition-ii/", "examples": [{"input": "m = 3, n = 3, ops = [[2,2],[3,3]]", "output": "4", "explanation": "The overlap of both rectangles is 2 by 2."}, {"input": "m = 3, n = 3, ops = [[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]", "output": "4", "explanation": "The smallest operation still limits the overlap to 2 by 2."}, {"input": "m = 3, n = 3, ops = []", "output": "9", "explanation": "With no steps every cell stays maximal."}], "hints": ["Each step adds one to the rectangle from the origin to (a,b).", "Only the intersection of all rectangles reaches the highest count.", "Track the minimum a and minimum b; an empty list means m*n."], "statement": "Start with an `m` by `n` grid of zeros. Each entry `[a,b]` in `ops` adds one to every cell with row below `a` and column below `b`. After all steps, count how many cells hold the largest value.\n\nBecause every step starts at the origin, the most-incremented cells are exactly the overlap of all requested rectangles.\n\n**Constraints:**\n- `1 <= m, n <= 40000`\n- `0 <= ops.length <= 10000`, each `[a,b]` with `1 <= a <= m`, `1 <= b <= n`.\n", "solution": "## Approach\n\nAll updates cover the origin, so the cells incremented every time are the rectangle bounded by the smallest a and smallest b. Its area is the number of maxima; with no operations the whole grid ties.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k) for k operations.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n if not ops:\n return m * n\n return min(a for a, _ in ops) * min(b for _, b in ops)\n```\n", "starter": {"go": "package main\n\nfunc MaxCount(m int, n int, ops [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxCount(self, m: int, n: int, ops: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxCount(int m, int n, vector<vector<int>>& ops) {\n return 0;\n }\n};"}, "fn": "maxCount", "params": [{"name": "m", "type": "int"}, {"name": "n", "type": "int"}, {"name": "ops", "type": "int_array_2d"}], "outputType": "int", "tests": [["3", "3", "[[2,2],[3,3]]"], ["3", "3", "[[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3],[2,2],[3,3],[3,3],[3,3]]"], ["3", "3", "[]"], ["1", "1", "[]"], ["1", "1", "[[1,1]]"], ["5", "5", "[[5,5]]"], ["4", "4", "[[1,1]]"], ["40000", "40000", "[]"], ["10", "20", "[[3,5],[2,10],[5,4]]"], ["2", "2", "[[2,2],[1,1]]"], ["3", "5", "[[3,2]]"], ["7", "3", "[[7,3],[4,2],[7,1]]"], ["100", "100", "[[50,50],[25,75]]"], ["3", "3", "[[3,3]]"], ["3", "3", "[[1,3],[3,1]]"], ["6", "6", "[[6,1],[6,2],[6,3]]"], ["8", "8", "[[8,8],[8,8],[8,8]]"], ["2", "3", "[]"], ["9", "9", "[[9,9],[8,8],[7,7]]"], ["5", "4", "[[1,4],[5,1]]"], ["12", "12", "[[12,12]]"], ["3", "7", "[[2,5]]"], ["4", "6", "[[4,6],[3,5],[2,4]]"], ["15", "15", "[[10,10],[10,5],[5,10]]"], ["1", "10", "[[1,5]]"], ["10", "1", "[[5,1]]"], ["20", "20", "[[20,1],[1,20]]"], ["30", "30", "[[15,15],[30,30]]"]], "expected": [4, 4, 9, 1, 1, 25, 1, 1600000000, 8, 1, 6, 4, 1250, 9, 1, 6, 64, 6, 49, 1, 144, 10, 8, 25, 5, 5, 1, 225], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "449", "slug": "range-addition", "id": 449, "title": "Range Addition", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/range-addition/", "examples": [{"input": "length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]]", "output": "[-2,0,3,5,3]", "explanation": "Apply each triple in order to the zero array."}, {"input": "length = 3, updates = []", "output": "[0,0,0]", "explanation": "No triples leave all zeros."}, {"input": "length = 1, updates = [[0,0,5]]", "output": "[5]", "explanation": "One entry grows by 5."}], "hints": ["Record only the boundaries: add inc at start and subtract it just after end.", "One prefix pass over the boundary array rebuilds every final value.", "This reaches O(k + n) time with O(n) memory."], "statement": "Rebuild the final array after many interval increments.\n\nStart with an array of `length` zeros. Each entry of `updates` is a triple `[start, end, inc]` meaning add `inc` to every position from `start` through `end` inclusive. Apply all triples in order and return the resulting array. When `updates` is empty the answer is all zeros; when `length` is zero the answer is the empty array.\n\n**Constraints:**\n- `0 <= length <= 10^4`\n- `0 <= updates.length <= 10^4`\n- Each triple has the form `[start, end, inc]` with `0 <= start <= end < length` when `length > 0`.\n- `-1000 <= inc <= 1000`\n", "solution": "## Approach\n\nKeep a difference array: add each increment at its start index and subtract it just past its end index. A single left-to-right running total then reconstructs the value at every position, since each range contributes exactly while the scan is inside it.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k + n), where k is the number of triples and n is `length`.\n- **Space Complexity:** O(n) for the difference buffer and the answer.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def getModifiedArray(self, length: int, updates: List[List[int]]) -> List[int]:\n diff = [0] * (length + 1)\n for s, e, v in updates:\n diff[s] += v\n if e + 1 < len(diff):\n diff[e + 1] -= v\n ans = [0] * length\n cur = 0\n for i in range(length):\n cur += diff[i]\n ans[i] = cur\n return ans\n```\n", "starter": {"go": "package main\n\nfunc GetModifiedArray(length int, updates [][]int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def getModifiedArray(self, length: int, updates: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> getModifiedArray(int length, vector<vector<int>>& updates) {\n return {};\n }\n};"}, "fn": "getModifiedArray", "params": [{"name": "length", "type": "int"}, {"name": "updates", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["5", "[[1,3,2],[2,4,3],[0,2,-2]]"], ["3", "[]"], ["1", "[[0,0,5]]"], ["0", "[]"], ["2", "[[0,1,1]]"], ["4", "[[0,3,1],[0,3,-1]]"], ["5", "[[0,4,10]]"], ["5", "[[0,0,1],[1,1,2],[2,2,3],[3,3,4],[4,4,5]]"], ["6", "[[2,4,6],[5,5,8],[1,5,-4]]"], ["3", "[[0,2,100],[1,1,-50]]"], ["10", "[[2,4,6],[5,6,8],[1,9,-4]]"], ["1", "[[0,0,0]]"], ["7", "[[0,6,1],[0,6,2],[0,6,3]]"], ["8", "[[3,5,-5]]"], ["5", "[[4,4,7]]"], ["9", "[[0,8,-1000]]"], ["4", "[[1,2,5],[0,0,3],[3,3,9]]"], ["6", "[[0,5,1],[1,4,1],[2,3,1]]"], ["100", "[[0,99,1]]"], ["100", "[[10,20,5],[30,40,-3],[0,99,2]]"], ["2", "[[0,0,-1000],[1,1,1000]]"], ["5", "[[0,4,0]]"], ["3", "[[2,2,9],[2,2,9],[2,2,9]]"], ["10", "[]"], ["1", "[[0,0,1],[0,0,1],[0,0,1]]"], ["12", "[[0,11,3],[5,7,-2]]"], ["15", "[[3,9,4]]"], ["20", "[[0,19,1],[5,15,2],[10,10,-5]]"], ["50", "[[0,49,7],[25,49,-7]]"], ["4", "[[0,1,-5],[2,3,5]]"], ["6", "[[0,0,100],[5,5,-100]]"]], "expected": [[-2, 0, 3, 5, 3], [0, 0, 0], [5], [], [1, 1], [0, 0, 0, 0], [10, 10, 10, 10, 10], [1, 2, 3, 4, 5], [0, -4, 2, 2, 2, 4], [100, 50, 100], [0, -4, 2, 2, 2, 4, 4, -4, -4, -4], [0], [6, 6, 6, 6, 6, 6, 6], [0, 0, 0, -5, -5, -5, 0, 0], [0, 0, 0, 0, 7], [-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000], [3, 5, 5, 9], [1, 2, 3, 3, 2, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [-1000, 1000], [0, 0, 0, 0, 0], [0, 0, 27], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [3], [3, 3, 3, 3, 3, 1, 1, 1, 3, 3, 3, 3], [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 3, 3, 3, 3, 3, -2, 3, 3, 3, 3, 3, 1, 1, 1, 1], [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-5, -5, 5, 5], [100, 0, 0, 0, 0, -100]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "723", "slug": "range-module", "id": 723, "title": "Range Module", "difficulty": "Hard", "category": "interval", "link": "https://leetcode.com/problems/range-module/", "examples": [{"input": "operations = [\"RangeModule\",\"addRange\",\"queryRange\",\"removeRange\",\"queryRange\"], args = [[],[10,20],[10,14],[14,16],[10,14]]", "output": "[1,1]", "explanation": "After tracking 10-20, the query 10-14 is fully covered. Removing 14-16 leaves 10-14 still covered."}, {"input": "operations = [\"RangeModule\",\"addRange\",\"addRange\",\"queryRange\"], args = [[],[10,15],[15,20],[10,20]]", "output": "[1]", "explanation": "Two touching ranges merge into 10-20, so the full query succeeds."}, {"input": "operations = [\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\"], args = [[],[5,10],[5,10],[5,10]]", "output": "[0]", "explanation": "Adding then fully removing the same span leaves nothing covered."}], "hints": ["Store disjoint half-open intervals in an ordered map from start to end; merging and splitting stay local to neighbors.", "For addRange, widen the new span over every overlapped entry before inserting once.", "For queryRange, only the interval starting at or before left matters; removal may trim one interval into two pieces. Adaptation: operations and args run in parallel and only queryRange emits output (1 for true, 0 for false)."], "statement": "Maintain a set of half-open number ranges `[left, right)` supporting three actions:\n\n- `addRange(left, right)`: start tracking every number from `left` up to but not including `right`.\n- `queryRange(left, right)`: report whether every number in that span is currently tracked.\n- `removeRange(left, right)`: stop tracking numbers in that span.\n\nBecause the judge works with plain functions, calls are encoded as two parallel lists: `operations` names each step (starting with `RangeModule`) and `args` gives its `[left, right]` pair (`[]` for construction). Only `queryRange` produces an answer, recorded as `1` for covered and `0` otherwise, in call order.\n\n*Adaptation note:* the entry point is `runRangeModule(operations, args)` returning the list of query answers.\n\n**Constraints:**\n- `1 <= operations.length <= 2000`\n- Each `args[i]` has length 0 or 2 with `0 <= left < right <= 10^9`.\n", "solution": "## Approach\n\nKeep disjoint half-open intervals ordered by start in a balanced tree. Adding widens the new span across every overlapped neighbor and inserts once. Querying checks only the interval starting at or before `left`. Removing trims overlapped intervals and possibly splits one survivor into two. Only queries append to the answer list.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m log k) over m calls with k disjoint intervals.\n- **Space Complexity:** O(k).\n\n## Implementation\n\n```python\nfrom typing import List\nimport bisect\nclass Solution:\n def runRangeModule(self, operations: List[str], args: List[List[int]]) -> List[int]:\n ivs: list[list[int]] = []\n ans = []\n for op, a in zip(operations, args):\n if op == \"RangeModule\":\n continue\n l, r = a[0], a[1]\n if op == \"addRange\":\n nl, nr = l, r\n nxt = []\n for s, e in ivs:\n if e < l or s > r:\n nxt.append([s, e])\n else:\n nl = min(nl, s); nr = max(nr, e)\n nxt.append([nl, nr])\n nxt.sort()\n ivs = nxt\n elif op == \"removeRange\":\n nxt = []\n for s, e in ivs:\n if e <= l or s >= r:\n nxt.append([s, e])\n else:\n if s < l:\n nxt.append([s, l])\n if e > r:\n nxt.append([r, e])\n ivs = nxt\n elif op == \"queryRange\":\n ok = any(s <= l and e >= r for s, e in ivs)\n ans.append(1 if ok else 0)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunRangeModule(operations []string, args [][]int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runRangeModule(self, operations: List[str], args: List[List[int]]) -> List[int]:\n return []", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runRangeModule(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runRangeModule", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"RangeModule\",\"addRange\",\"queryRange\",\"removeRange\",\"queryRange\"]", "[[],[10,20],[10,14],[14,16],[10,14]]"], ["[\"RangeModule\",\"addRange\",\"addRange\",\"queryRange\"]", "[[],[10,15],[15,20],[10,20]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[5,10],[5,10],[5,10]]"], ["[\"RangeModule\",\"queryRange\"]", "[[],[1,2]]"], ["[\"RangeModule\",\"addRange\",\"queryRange\"]", "[[],[1,5],[1,5]]"], ["[\"RangeModule\",\"addRange\",\"queryRange\"]", "[[],[1,5],[2,3]]"], ["[\"RangeModule\",\"addRange\",\"queryRange\"]", "[[],[1,5],[5,6]]"], ["[\"RangeModule\",\"addRange\",\"addRange\",\"queryRange\"]", "[[],[1,3],[5,7],[1,7]]"], ["[\"RangeModule\",\"addRange\",\"addRange\",\"queryRange\"]", "[[],[1,4],[2,5],[1,5]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\",\"queryRange\"]", "[[],[1,10],[3,5],[1,3],[3,5]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[1,10],[1,10],[1,10]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[10,20],[10,11],[10,11]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[10,20],[19,20],[10,20]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\",\"queryRange\",\"queryRange\"]", "[[],[1,10],[2,4],[1,2],[4,10],[2,4]]"], ["[\"RangeModule\",\"addRange\",\"queryRange\",\"queryRange\"]", "[[],[5,8],[4,6],[6,9]]"], ["[\"RangeModule\",\"addRange\",\"addRange\",\"addRange\",\"queryRange\"]", "[[],[1,2],[3,4],[5,6],[1,6]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"addRange\",\"queryRange\"]", "[[],[1,5],[2,3],[2,3],[1,5]]"], ["[\"RangeModule\",\"addRange\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[1,10],[20,30],[5,25],[1,10]]"], ["[\"RangeModule\",\"addRange\",\"queryRange\",\"addRange\",\"queryRange\"]", "[[],[1,3],[1,3],[2,4],[1,4]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[1,100],[50,60],[40,70]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\",\"queryRange\"]", "[[],[1,100],[10,90],[1,10],[90,100]]"], ["[\"RangeModule\",\"addRange\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[1,5],[6,10],[4,7],[1,10]]"], ["[\"RangeModule\",\"queryRange\",\"queryRange\"]", "[[],[0,1],[100,200]]"], ["[\"RangeModule\",\"addRange\",\"queryRange\"]", "[[],[0,1000000000],[0,1000000000]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"queryRange\"]", "[[],[0,100],[25,75],[0,100]]"], ["[\"RangeModule\",\"addRange\",\"addRange\",\"queryRange\",\"removeRange\",\"queryRange\"]", "[[],[5,10],[10,15],[5,15],[7,12],[5,15]]"], ["[\"RangeModule\",\"addRange\",\"queryRange\",\"removeRange\",\"queryRange\",\"addRange\",\"queryRange\"]", "[[],[1,9],[1,9],[3,6],[1,9],[3,6],[1,9]]"], ["[\"RangeModule\",\"addRange\",\"removeRange\",\"addRange\",\"queryRange\",\"queryRange\"]", "[[],[10,30],[15,25],[15,25],[10,30],[15,25]]"]], "expected": [[1, 1], [1], [0], [0], [1], [1], [0], [0], [1], [1, 0], [0], [0], [0], [1, 1, 0], [0, 0], [0], [1], [0], [1, 1], [0], [1, 1], [0], [0, 0], [1], [0], [1, 0], [1, 0, 1], [1, 1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "925", "slug": "range-sum-of-bst", "id": 925, "title": "Range Sum of BST", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/range-sum-of-bst/", "examples": [{"input": "root = [10,5,15,3,7,null,18], low = 7, high = 15", "output": "32", "explanation": "Nodes 7, 10, and 15 sum to 32."}, {"input": "root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10", "output": "23", "explanation": "Nodes 6, 7, and 10 sum to 23."}, {"input": "root = [5,3,8,1,4,7,9], low = 1, high = 9", "output": "37", "explanation": "Every node falls inside."}], "hints": ["In a BST, values left of a node are smaller and right are larger, so whole subtrees can be skipped.", "Only add the node when low <= val <= high.", "Recurse left when val > low and right when val < high."], "statement": "You are given the root of a binary search tree and two bounds `low` and `high`. Add up every node value that lies inside the inclusive interval `[low, high]`.\n\n**Constraints:**\n- The tree holds `1` to `10000` nodes with values `1..100000` and respects BST order.\n- `1 <= low <= high <= 100000`\n", "solution": "## Approach\n\nDo a pruned depth-first walk. Add the node value when it sits inside `[low, high]`; recurse left only when the node exceeds `low` and right only when it is below `high`. BST ordering guarantees skipped subtrees cannot contain answers.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) worst case, O(k + log n) on balanced trees where k is the number of hits.\n- **Space Complexity:** O(h) for recursion depth, where h is the tree height.\n\n## Implementation\n\n```python\nclass Solution:\n def rangeSumBST(self, root, low: int, high: int) -> int:\n if not root:\n return 0\n s = root.val if low <= root.val <= high else 0\n if root.val > low:\n s += self.rangeSumBST(root.left, low, high)\n if root.val < high:\n s += self.rangeSumBST(root.right, low, high)\n return s\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc RangeSumBST(root *TreeNode, low int, high int) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def rangeSumBST(self, root, low: int, high: int) -> int:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n\nclass Solution {\npublic:\n int rangeSumBST(TreeNode* root, int low, int high) {\n return 0;\n }\n};"}, "fn": "rangeSumBST", "params": [{"name": "root", "type": "tree_node"}, {"name": "low", "type": "int"}, {"name": "high", "type": "int"}], "outputType": "int", "tests": [["[10,5,15,3,7,null,18]", "7", "15"], ["[10,5,15,3,7,13,18,1,null,6]", "6", "10"], ["[5,3,8,1,4,7,9]", "1", "9"], ["[1]", "1", "1"], ["[1]", "2", "3"], ["[5]", "1", "10"], ["[10,5,15]", "5", "5"], ["[10,5,15]", "15", "15"], ["[10,5,15]", "6", "14"], ["[10,5,15,3,7]", "3", "7"], ["[20,10,30,5,15,25,35]", "10", "30"], ["[20,10,30,5,15,25,35]", "6", "14"], ["[20,10,30,5,15,25,35]", "26", "40"], ["[5,3,6,2,4,null,7]", "2", "4"], ["[5,3,6,2,4,null,7]", "6", "7"], ["[8,3,10,1,6,null,14,4,7,13]", "4", "10"], ["[8,3,10,1,6,null,14,4,7,13]", "1", "14"], ["[2,1,3]", "1", "3"], ["[2,1,3]", "2", "2"], ["[50,30,70,20,40,60,80]", "30", "70"], ["[50,30,70,20,40,60,80]", "20", "20"], ["[50,30,70,20,40,60,80]", "81", "100"], ["[10,5,15,3,7,null,18]", "3", "18"], ["[10,5,15,3,7,null,18]", "18", "18"], ["[4,2,6,1,3,5,7]", "1", "7"], ["[4,2,6,1,3,5,7]", "3", "5"], ["[100,50,150,25,75,125,175]", "50", "150"], ["[10,null,20,null,30]", "15", "25"]], "expected": [32, 23, 37, 1, 0, 5, 5, 15, 10, 15, 100, 10, 65, 9, 13, 24, 62, 6, 2, 250, 20, 0, 58, 18, 28, 12, 500, 20], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "160", "slug": "range-sum-query-2d-immutable", "id": 160, "title": "Range Sum Query 2D - Immutable", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/range-sum-query-2d-immutable/", "examples": [{"input": "matrix = [[3,0,1,4,2],[5,6,3,2,1],[1,2,0,1,5],[4,1,0,1,7],[1,0,3,0,5]], queries = [[2,1,4,3],[1,1,2,2],[1,2,2,4]]", "output": "[8,11,12]", "explanation": "sumRegion(2,1,4,3) = 8; sumRegion(1,1,2,2) = 11; sumRegion(1,2,2,4) = 12 via 2D prefix sums."}, {"input": "matrix = [[1]], queries = [[0,0,0,0]]", "output": "[1]", "explanation": "A single cell query returns the cell itself."}, {"input": "matrix = [[1,2],[3,4]], queries = [[0,0,1,1],[0,0,0,0],[1,1,1,1]]", "output": "[10,1,4]", "explanation": "Whole matrix sums to 10; corners are 1 and 4."}], "hints": ["Precompute a (m+1)x(n+1) prefix sum where pref[i+1][j+1] is the sum of matrix[0..i][0..j].", "Answer each query as pref[r2+1][c2+1]-pref[r1][c2+1]-pref[r2+1][c1]+pref[r1][c1]."], "statement": "Given a 2D matrix `matrix`, handle multiple queries asking for the sum of elements inside the rectangle defined by its upper left corner `(row1, col1)` and lower right corner `(row2, col2)`.\n\nFor this judge, you are given the full `matrix` and a list of `queries`, where each query is `[row1, col1, row2, col2]`. Return an array with the sum for each query in order. An efficient solution precomputes a 2D prefix sum so each query runs in `O(1)`.\n\n**Constraints:**\n\n- m == matrix.length, n == matrix[i].length\n- 1 \u2264 m, n \u2264 200\n- -10^4 \u2264 matrix[i][j] \u2264 10^4\n- 0 \u2264 row1 \u2264 row2 < m, 0 \u2264 col1 \u2264 col2 < n\n- At most 10^4 queries.\n", "solution": "## Approach\n\nBuild a `(m+1) x (n+1)` 2D prefix sum where `pref[i+1][j+1]` is the sum of `matrix[0..i][0..j]`. Each cell is `pref[i][j+1] + pref[i+1][j] - pref[i][j] + matrix[i][j]`. Then each query `[r1,c1,r2,c2]` is answered in `O(1)` by inclusion-exclusion: `pref[r2+1][c2+1] - pref[r1][c2+1] - pref[r2+1][c1] + pref[r1][c1]`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m*n + q) for `m x n` matrix and `q` queries (O(1) per query after preprocessing).\n- **Space Complexity:** O(m*n) for the prefix table.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sumRegion(self, matrix: List[List[int]], queries: List[List[int]]) -> List[int]:\n m, n = len(matrix), len(matrix[0])\n pref = [[0] * (n + 1) for _ in range(m + 1)]\n for i in range(m):\n for j in range(n):\n pref[i + 1][j + 1] = pref[i][j + 1] + pref[i + 1][j] - pref[i][j] + matrix[i][j]\n ans = []\n for r1, c1, r2, c2 in queries:\n ans.append(pref[r2 + 1][c2 + 1] - pref[r1][c2 + 1] - pref[r2 + 1][c1] + pref[r1][c1])\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SumRegion(matrix [][]int, queries [][]int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def sumRegion(self, matrix: List[List[int]], queries: List[List[int]]) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> sumRegion(vector<vector<int>>& matrix, vector<vector<int>>& queries) {\n return {};\n }\n};"}, "fn": "sumRegion", "params": [{"name": "matrix", "type": "int_array_2d"}, {"name": "queries", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[[3,0,1,4,2],[5,6,3,2,1],[1,2,0,1,5],[4,1,0,1,7],[1,0,3,0,5]]", "[[2,1,4,3],[1,1,2,2],[1,2,2,4]]"], ["[[1]]", "[[0,0,0,0]]"], ["[[1,2],[3,4]]", "[[0,0,1,1],[0,0,0,0],[1,1,1,1]]"], ["[[-1,-2],[-3,-4]]", "[[0,0,1,1],[0,0,0,1],[1,0,1,1]]"], ["[[5]]", "[[0,0,0,0],[0,0,0,0]]"], ["[[1,2,3],[4,5,6],[7,8,9]]", "[[0,0,2,2],[1,1,2,2],[0,0,0,2]]"], ["[[0,0,0],[0,0,0]]", "[[0,0,1,2],[0,1,0,1]]"], ["[[10000,-10000],[10000,-10000]]", "[[0,0,1,1],[0,0,0,0]]"], ["[[1,2,3,4,5]]", "[[0,0,0,4],[0,1,0,3]]"], ["[[1],[2],[3],[4]]", "[[0,0,3,0],[1,0,2,0]]"], ["[[2,0,-1],[0,3,1],[1,0,2]]", "[[0,0,2,2],[1,1,2,2],[0,1,1,2]]"], ["[[2]]", "[[0,0,0,0]]"], ["[[1,2,3,4]]", "[[0,0,0,1],[0,2,0,3]]"], ["[[1],[2]]", "[[0,0,1,0],[0,0,0,0]]"], ["[[0]]", "[[0,0,0,0]]"], ["[[-5,5],[-5,5]]", "[[0,0,1,1],[0,0,0,0],[1,1,1,1]]"], ["[[1,0],[0,1]]", "[[0,0,1,1],[0,1,1,1]]"], ["[[3,3,3],[3,3,3]]", "[[0,0,1,2],[0,1,1,1]]"], ["[[-1,0,1],[2,-2,3]]", "[[0,0,1,2],[0,0,0,2]]"], ["[[4,5,6,7],[8,9,10,11]]", "[[0,0,1,3],[0,1,1,2]]"], ["[[1,2],[3,4],[5,6]]", "[[0,0,2,1],[1,0,2,0]]"], ["[[7,8,9],[10,11,12],[13,14,15]]", "[[0,0,2,2],[0,0,1,1]]"], ["[[100,-50,25],[-25,50,-100]]", "[[0,0,1,2],[0,0,0,2]]"], ["[[0,1,0],[1,0,1],[0,1,0]]", "[[0,0,2,2],[1,1,1,1]]"], ["[[5,5,5,5,5]]", "[[0,0,0,4],[0,2,0,2]]"], ["[[2],[2],[2]]", "[[0,0,2,0],[1,0,1,0]]"], ["[[-10000,10000],[-10000,10000],[0,0]]", "[[0,0,2,1],[2,0,2,1]]"], ["[[1,1,1],[2,2,2],[3,3,3],[4,4,4]]", "[[0,0,3,2],[1,1,2,2]]"], ["[[9,8,7],[6,5,4],[3,2,1]]", "[[0,0,2,2],[2,0,2,2],[0,2,0,2]]"], ["@javascript:JSON.stringify(Array.from({length:200},()=>Array.from({length:200},()=>1)))", "@javascript:JSON.stringify(Array.from({length:100},()=> [0,0,199,199]))"]], "expected": [[8, 11, 12], [1], [10, 1, 4], [-10, -3, -7], [5, 5], [45, 28, 6], [0, 0], [0, 10000], [15, 9], [10, 5], [8, 6, 3], [2], [3, 7], [3, 1], [0], [0, -5, 5], [2, 1], [18, 6], [3, 0], [60, 30], [21, 8], [99, 36], [0, 75], [4, 0], [25, 5], [6, 2], [0, 0], [30, 10], [45, 6, 7], [40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000, 40000]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "400", "slug": "range-sum-query-2d-mutable", "id": 400, "title": "Range Sum Query 2D - Mutable", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/range-sum-query-2d-mutable/", "examples": [{"input": "matrix = [[3,0,1,4,2],[5,6,3,2,1],[1,2,0,1,5],[4,1,0,1,7],[1,0,3,0,5]], operations = [\"sumRegion\",\"update\",\"sumRegion\"], values = [[2,1,4,3],[3,2,2],[2,1,4,3]]", "output": "[8,10]", "explanation": "Rectangle sums 8, then 10 after the point update."}, {"input": "matrix = [[1]], operations = [\"sumRegion\",\"update\",\"sumRegion\"], values = [[0,0,0,0],[0,0,5],[0,0,0,0]]", "output": "[1,5]", "explanation": "Single cell read, rewritten, re-read."}, {"input": "matrix = [[1,2],[3,4]], operations = [\"sumRegion\",\"update\",\"sumRegion\"], values = [[0,0,1,1],[0,0,10],[0,0,0,0]]", "output": "[10,10]", "explanation": "Full-frame sum, then the updated corner alone."}], "hints": ["Replay the script on a copy of the matrix, summing each requested rectangle cell by cell for a simple baseline.", "For full speed, back the matrix with a 2D binary indexed tree or 2D segment tree.", "Only \"sumRegion\" steps append to the answer; updates just change stored state."], "statement": "You are given a changeable `matrix` plus a script of operations to replay in order. Each\noperation is either `\"sumRegion\"` with values `[row1, col1, row2, col2]`, asking for the sum\nof the rectangle from `(row1, col1)` to `(row2, col2)` inclusive, or `\"update\"` with values\n`[row, col, value]`, assigning `matrix[row][col] = value`. Return the answers of the\n`\"sumRegion\"` operations in order. (This is the function-style view of the classic mutable\n2D-range-sum design task usually solved with a 2D binary indexed tree.)\n\n**Constraints:**\n- `1 <= rows, cols <= 200`\n- `-1000 <= matrix[i][j], value <= 1000`\n- Indices in every operation are valid; at least one `\"sumRegion\"` appears.\n", "solution": "## Approach\n\nSimulate the script on a matrix copy with direct rectangle sums (a 2D binary indexed tree gives the optimal version); collect each region sum in order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(q x m x n) naive\n- **Space Complexity:** O(m x n)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runNumMatrix(self, matrix: List[List[int]], operations: List[str], values: List[List[int]]) -> List[int]:\n a = [row[:] for row in matrix]\n ans = []\n for op, v in zip(operations, values):\n if op == 'update':\n a[v[0]][v[1]] = v[2]\n else:\n s = 0\n for i in range(v[0], v[2] + 1):\n for j in range(v[1], v[3] + 1):\n s += a[i][j]\n ans.append(s)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunNumMatrix(matrix [][]int, operations []string, values [][]int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def runNumMatrix(self, matrix: List[List[int]], operations: List[str], values: List[List[int]]) -> List[int]:\n ", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runNumMatrix(vector<vector<int>>& matrix, vector<string>& operations, vector<vector<int>>& values) {\n return {};\n }\n};"}, "fn": "runNumMatrix", "params": [{"name": "matrix", "type": "int_array_2d"}, {"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[[3,0,1,4,2],[5,6,3,2,1],[1,2,0,1,5],[4,1,0,1,7],[1,0,3,0,5]]", "[\"sumRegion\",\"update\",\"sumRegion\"]", "[[2,1,4,3],[3,2,2],[2,1,4,3]]"], ["[[1]]", "[\"sumRegion\",\"update\",\"sumRegion\"]", "[[0,0,0,0],[0,0,5],[0,0,0,0]]"], ["[[1,2],[3,4]]", "[\"sumRegion\",\"update\",\"sumRegion\"]", "[[0,0,1,1],[0,0,10],[0,0,0,0]]"], ["[[5,2],[3,12]]", "[\"sumRegion\",\"sumRegion\",\"sumRegion\",\"sumRegion\"]", "[[1,1,1,1],[0,0,0,0],[1,0,1,1],[1,1,1,1]]"], ["[[5,12,13],[-3,-8,-7],[8,-6,1],[12,12,-11]]", "[\"sumRegion\",\"update\",\"update\",\"sumRegion\",\"update\",\"sumRegion\",\"sumRegion\"]", "[[2,1,2,1],[2,1,-10],[1,1,13],[2,2,3,2],[2,2,4],[0,2,2,2],[0,1,3,1]]"], ["[[-10,-3],[17,0],[-4,-5],[18,8]]", "[\"sumRegion\",\"sumRegion\",\"sumRegion\",\"sumRegion\"]", "[[0,1,1,1],[0,1,2,1],[2,1,2,1],[3,0,3,1]]"], ["[[-1],[-9],[-12],[-8]]", "[\"sumRegion\",\"sumRegion\",\"sumRegion\",\"sumRegion\",\"sumRegion\",\"update\"]", "[[1,0,3,0],[2,0,2,0],[2,0,3,0],[0,0,0,0],[2,0,2,0],[0,0,13]]"], ["[[-15,0],[8,17]]", "[\"sumRegion\",\"sumRegion\"]", "[[1,1,1,1],[0,1,0,1]]"], ["[[14,10,-7,-8]]", "[\"sumRegion\",\"update\"]", "[[0,1,0,3],[0,2,16]]"], ["[[6,-19],[-11,1],[-3,3]]", "[\"sumRegion\",\"update\",\"update\",\"sumRegion\",\"sumRegion\",\"sumRegion\",\"update\"]", "[[2,1,2,1],[0,0,20],[0,1,-7],[1,0,2,1],[1,1,1,1],[1,1,2,1],[2,1,-9]]"], ["[[9,-17,8],[0,17,5],[-16,10,1]]", "[\"sumRegion\",\"update\",\"update\",\"sumRegion\",\"update\"]", "[[1,0,2,1],[1,1,10],[2,2,-20],[2,2,2,2],[0,0,19]]"], ["[[7,-18],[-3,3],[-7,-11],[17,4]]", "[\"sumRegion\",\"update\",\"sumRegion\",\"sumRegion\",\"sumRegion\"]", "[[1,1,1,1],[0,1,-3],[0,0,2,1],[1,0,1,1],[1,1,1,1]]"], ["[[-14,3,3,7],[-7,8,12,13]]", "[\"sumRegion\",\"sumRegion\",\"sumRegion\",\"update\",\"sumRegion\",\"update\",\"update\"]", "[[1,0,1,0],[0,1,0,3],[1,3,1,3],[1,1,-11],[1,1,1,3],[1,3,20],[1,2,2]]"], ["[[-13]]", "[\"sumRegion\",\"update\",\"update\",\"update\",\"update\"]", "[[0,0,0,0],[0,0,15],[0,0,-5],[0,0,19],[0,0,-13]]"], ["[[9,0,-19,-12],[-16,-18,-16,3],[16,16,17,-18],[-11,-1,-7,-8]]", "[\"sumRegion\",\"sumRegion\"]", "[[1,3,2,3],[1,0,1,1]]"], ["[[-6,14,18],[-8,4,-14]]", "[\"sumRegion\",\"sumRegion\",\"sumRegion\"]", "[[1,1,1,1],[1,1,1,1],[0,0,1,1]]"], ["[[8,20],[11,-15]]", "[\"sumRegion\",\"update\"]", "[[0,1,1,1],[0,1,4]]"], ["[[18,18],[-6,-10],[6,14]]", "[\"sumRegion\",\"sumRegion\"]", "[[1,1,1,1],[1,1,1,1]]"], ["[[12,15,18,-13],[19,20,14,-13],[0,-1,-9,4],[-3,-2,15,4]]", "[\"sumRegion\",\"sumRegion\",\"update\",\"sumRegion\"]", "[[2,1,2,2],[3,0,3,2],[3,1,11],[1,2,2,2]]"], ["[[13],[-15],[-6]]", "[\"sumRegion\",\"sumRegion\",\"update\",\"sumRegion\",\"sumRegion\"]", "[[2,0,2,0],[1,0,1,0],[1,0,5],[0,0,2,0],[0,0,0,0]]"], ["[[-3,6,-15],[2,18,4]]", "[\"sumRegion\",\"update\",\"sumRegion\",\"sumRegion\",\"sumRegion\",\"sumRegion\",\"sumRegion\"]", "[[0,2,0,2],[1,0,13],[0,1,1,2],[1,2,1,2],[0,2,0,2],[0,2,0,2],[1,2,1,2]]"], ["[[3,-2,9],[8,2,17],[1,-16,16],[-18,11,8]]", "[\"sumRegion\",\"sumRegion\",\"sumRegion\"]", "[[0,1,1,1],[0,2,3,2],[1,0,2,0]]"], ["[[1,-13],[-4,-1]]", "[\"sumRegion\",\"sumRegion\",\"update\",\"update\",\"sumRegion\",\"update\",\"sumRegion\"]", "[[0,0,1,1],[0,0,0,1],[1,0,19],[1,0,-15],[1,0,1,0],[0,1,18],[1,0,1,0]]"], ["[[-15],[-8]]", "[\"sumRegion\",\"update\",\"update\",\"update\",\"update\"]", "[[0,0,1,0],[0,0,19],[1,0,1],[1,0,-9],[1,0,7]]"], ["[[-19],[-4],[-20]]", "[\"sumRegion\",\"sumRegion\",\"sumRegion\",\"sumRegion\",\"update\",\"update\"]", "[[2,0,2,0],[2,0,2,0],[1,0,2,0],[2,0,2,0],[1,0,-10],[2,0,9]]"], ["[[-17,3,18],[8,16,12],[10,-3,-11]]", "[\"sumRegion\",\"sumRegion\",\"update\",\"sumRegion\"]", "[[1,0,2,0],[0,0,1,0],[2,1,-9],[0,0,2,0]]"], ["[[-7,-9],[13,13],[-18,-2],[-5,-5]]", "[\"sumRegion\",\"update\",\"sumRegion\",\"sumRegion\",\"sumRegion\",\"update\"]", "[[3,0,3,0],[2,1,3],[3,0,3,0],[3,1,3,1],[3,1,3,1],[3,1,-16]]"], ["[[-15,16,19],[-17,8,20]]", "[\"sumRegion\",\"update\",\"sumRegion\",\"update\",\"sumRegion\",\"update\",\"update\"]", "[[1,2,1,2],[0,1,-10],[1,0,1,0],[0,1,-11],[0,0,1,1],[0,2,-16],[1,2,-19]]"]], "expected": [[8, 10], [1, 5], [10, 10], [12, 5, 15, 12], [-6, -10, 10, 27], [-3, -8, -5, 26], [-29, -12, -20, -1, -12], [17, 0], [-5], [3, -10, 1, 4], [11, -20], [3, -14, 0, 3], [-7, 13, 13, 14], [-13], [-15, -34], [4, 4, 4], [5], [-10, -10], [-10, 10, 5], [-6, -15, 12, 13], [-15, 13, 4, -15, -15, 4], [0, 50, 9], [-17, -12, -15, -15], [-23], [-20, -20, -24, -20], [18, -9, 1], [-5, -5, -5, -5], [20, -17, -35]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "396", "slug": "range-sum-query-immutable", "id": 396, "title": "Range Sum Query - Immutable", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/range-sum-query-immutable/", "examples": [{"input": "nums = [-2,0,3,-5,2,-1], queries = [[0,2],[2,5],[0,5]]", "output": "[1,-1,-3]", "explanation": "Prefix sums answer 1, -1, and -3."}, {"input": "nums = [1], queries = [[0,0]]", "output": "[1]", "explanation": "The only range holds the single value."}, {"input": "nums = [1,2,3], queries = [[0,2],[1,1]]", "output": "[6,2]", "explanation": "Full sum 6 and middle-cell sum 2."}], "hints": ["Precompute prefix sums pref where pref[k] totals the first k entries.", "Each range answer is then pref[right+1] - pref[left], in O(1).", "Building the table once keeps every query constant-time no matter how many arrive."], "statement": "You are handed a fixed array `nums` plus a batch of `queries`, where each query is a pair\n`[left, right]` with `0 <= left <= right`. For every query, report the sum of\n`nums[left] + ... + nums[right]`. (This is the function-style view of the classic\nimmutable prefix-sum design task: precompute once, then answer each query fast.)\n\n**Constraints:**\n- `1 <= nums.length <= 10^4`\n- `-10^5 <= nums[i] <= 10^5`\n- `1 <= queries.length <= 10^4`, each query holds exactly two indices.\n", "solution": "## Approach\n\nBuild one prefix-sum array up front; every [left, right] query is then answered by a single subtraction.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + q)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runNumArray(self, nums: List[int], queries: List[List[int]]) -> List[int]:\n pref = [0]\n for v in nums:\n pref.append(pref[-1] + v)\n return [pref[r + 1] - pref[l] for l, r in queries]\n```\n", "starter": {"go": "package main\n\nfunc RunNumArray(nums []int, queries [][]int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def runNumArray(self, nums: List[int], queries: List[List[int]]) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runNumArray(vector<int>& nums, vector<vector<int>>& queries) {\n return {};\n }\n};"}, "fn": "runNumArray", "params": [{"name": "nums", "type": "int_array"}, {"name": "queries", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[-2,0,3,-5,2,-1]", "[[0,2],[2,5],[0,5]]"], ["[1]", "[[0,0]]"], ["[1,2,3]", "[[0,2],[1,1]]"], ["[0,0,0]", "[[0,2],[1,2]]"], ["[-1]", "[[0,0],[0,0]]"], ["[-39]", "[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]"], ["[26,-26,-99]", "[[2,2],[1,1],[0,0],[1,1],[0,0]]"], ["[-25,-73,79,-37,82,79,34,67,-36,34]", "[[0,4],[4,9]]"], ["[-68,86,-10,-82,64,26,-57,-31,41,-65,-69]", "[[10,10],[7,7],[2,8],[0,5],[9,9],[2,3]]"], ["[10,-100,-73,-18,-66,-57,-36,-51,67,74,-94,59]", "[[10,10],[4,4],[1,5],[3,11],[11,11]]"], ["[-4,-90,26,28,-61,47,-53,66,47,-84,-82]", "[[6,7],[3,10],[10,10],[8,9]]"], ["[-13,-91,22,68,19,7,-94,35,-25,1,10,-81,-49,17]", "[[11,11],[5,13],[8,11],[8,13],[1,5]]"], ["[-61,-62,-13,-31,64,-15,66,77,-40,-8,18]", "[[0,9],[4,5],[5,10]]"], ["[30,-61,41,72,-18]", "[[3,3],[1,1],[0,2]]"], ["[-31,53,-94,7,-1,-51,-90,-23,-59,-32,33]", "[[6,8],[1,3]]"], ["[88,21,83,66,-30,29,-8,86,-56,82,8]", "[[8,8],[9,10],[1,1]]"], ["[-40]", "[[0,0],[0,0],[0,0],[0,0]]"], ["[1,91,94]", "[[1,1],[2,2],[2,2],[0,2]]"], ["[91,-75,26,-55,-71,-72,16,-5,45,70,7,-14,-99,-81]", "[[4,11]]"], ["[-80,3,94]", "[[2,2],[0,2],[2,2],[0,1]]"], ["[25,-13,64,-82,59,84,-95,-83,-69,-17,-64]", "[[9,9]]"], ["[59,60,-45,-48,-76,-80,-29,-31,59,56,44]", "[[6,10],[6,7],[3,8]]"], ["[-3,95,62,-65,13,3,-7,57]", "[[3,5],[4,6],[7,7]]"], ["[-45,31,64,-8,72,-10,-3,47,-26,-91,-12,-32,56,36,1]", "[[2,11],[10,13],[0,7],[14,14],[13,13],[0,5]]"], ["[-73,95,80,8,-65,72,-21,-77]", "[[1,2],[0,3],[5,5],[4,7],[1,2],[7,7]]"], ["[87,-56,47,17,-31]", "[[1,1],[2,3],[0,3],[2,3],[1,3],[1,1]]"], ["[87,-100,30,11,62,-91,-16,7,13]", "[[0,1]]"], ["[-70,-98,70,92,26,-36,-33,-80,-78,-93,-48,10,43,15]", "[[6,9],[4,7]]"], ["[-46,-10,90,59,60,7]", "[[5,5],[5,5],[2,2],[3,4],[5,5]]"], ["[96,96,-86,-23,-5,-4,35,-35,-28,79,-99]", "[[7,7],[1,9],[9,9]]"]], "expected": [[1, -1, -3], [1], [6, 2], [0, 0], [-1, -1], [-39, -39, -39, -39, -39, -39], [-99, -26, 26, -26, 26], [26, 260], [-69, -31, -49, 16, -65, -92], [-94, -66, -314, -122, 59], [13, -92, -82, -37], [-81, -179, -95, -127, 25], [-23, 49, 98], [72, -61, 10], [-172, -34], [-56, 90, 21], [-40, -40, -40, -40], [91, 94, 94, 186], [-24], [94, 17, 94, -77], [-17], [99, -60, -205], [-49, 9, 57], [1, 48, 148, 1, 36, 104], [175, 110, 72, -91, 175, -77], [-56, 64, 95, 64, 8, -56], [-13], [-284, -123], [7, 7, 90, 119, 7], [-35, 29, 79]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "399", "slug": "range-sum-query-mutable", "id": 399, "title": "Range Sum Query - Mutable", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/range-sum-query-mutable/", "examples": [{"input": "nums = [1,3,5], operations = [\"sumRange\",\"update\",\"sumRange\"], values = [[0,2],[1,2],[0,2]]", "output": "[9,8]", "explanation": "Range sums 9, then 8 after the point update."}, {"input": "nums = [7], operations = [\"sumRange\",\"update\",\"sumRange\"], values = [[0,0],[0,4],[0,0]]", "output": "[7,4]", "explanation": "Single cell read, rewritten, re-read."}, {"input": "nums = [0,0], operations = [\"update\",\"update\",\"sumRange\"], values = [[0,5],[1,3],[0,1]]", "output": "[8]", "explanation": "Two updates precede the only query."}], "hints": ["Replay the script on a plain copy of the array to get a simple (if slower) baseline.", "For full speed, back the array with a segment tree or binary indexed tree for logarithmic updates and queries.", "Only \"sumRange\" steps append to the answer; updates just change stored state."], "statement": "You are given a changeable array `nums` plus a script of operations to replay in order.\nEach operation is either `\"sumRange\"` with values `[left, right]`, asking for the sum of\n`nums[left] + ... + nums[right]`, or `\"update\"` with values `[index, value]`, assigning\n`nums[index] = value`. Return the answers of the `\"sumRange\"` operations in order.\n(This is the function-style view of the classic mutable-array design task usually solved\nwith a segment tree or binary indexed tree.)\n\n**Constraints:**\n- `1 <= nums.length <= 3 * 10^4`\n- `-100 <= nums[i], value <= 100`\n- Indices in every operation are valid; at least one `\"sumRange\"` appears.\n", "solution": "## Approach\n\nSimulate the script directly on a copy of the array (a segment tree gives the optimal logarithmic version); collect each range sum in order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(q x n) naive, O(q log n) with a segment tree\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runNumArray(self, nums: List[int], operations: List[str], values: List[List[int]]) -> List[int]:\n a, ans = list(nums), []\n for op, v in zip(operations, values):\n if op == 'update':\n a[v[0]] = v[1]\n else:\n ans.append(sum(a[v[0]:v[1] + 1]))\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunNumArray(nums []int, operations []string, values [][]int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def runNumArray(self, nums: List[int], operations: List[str], values: List[List[int]]) -> List[int]:\n ", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runNumArray(vector<int>& nums, vector<string>& operations, vector<vector<int>>& values) {\n return {};\n }\n};"}, "fn": "runNumArray", "params": [{"name": "nums", "type": "int_array"}, {"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[1,3,5]", "[\"sumRange\",\"update\",\"sumRange\"]", "[[0,2],[1,2],[0,2]]"], ["[7]", "[\"sumRange\",\"update\",\"sumRange\"]", "[[0,0],[0,4],[0,0]]"], ["[0,0]", "[\"update\",\"update\",\"sumRange\"]", "[[0,5],[1,3],[0,1]]"], ["[47,38,-13,16,11]", "[\"sumRange\",\"update\",\"update\",\"sumRange\",\"sumRange\"]", "[[3,3],[0,-24],[3,45],[3,3],[1,2]]"], ["[0,-29,15]", "[\"sumRange\",\"sumRange\"]", "[[1,2],[0,0]]"], ["[-18]", "[\"sumRange\",\"update\"]", "[[0,0],[0,36]]"], ["[-32]", "[\"sumRange\",\"sumRange\",\"sumRange\"]", "[[0,0],[0,0],[0,0]]"], ["[-41,42]", "[\"sumRange\",\"update\",\"sumRange\",\"sumRange\",\"sumRange\",\"sumRange\",\"sumRange\"]", "[[0,0],[0,-7],[1,1],[1,1],[1,1],[0,1],[1,1]]"], ["[17,33]", "[\"sumRange\",\"update\",\"sumRange\",\"sumRange\",\"sumRange\",\"update\"]", "[[1,1],[1,-26],[0,0],[1,1],[0,1],[1,42]]"], ["[14,0,-39,-22]", "[\"sumRange\",\"sumRange\",\"update\",\"update\",\"sumRange\",\"update\",\"update\"]", "[[1,2],[3,3],[3,-11],[0,-9],[2,3],[2,-10],[1,22]]"], ["[-4,13]", "[\"sumRange\",\"sumRange\",\"sumRange\",\"update\"]", "[[0,1],[0,0],[1,1],[1,-7]]"], ["[-22,-50,37,-27]", "[\"sumRange\",\"sumRange\",\"update\"]", "[[2,2],[2,2],[3,-6]]"], ["[24,-43,14,3,9,49,28,-37]", "[\"sumRange\",\"update\",\"sumRange\",\"sumRange\",\"sumRange\",\"sumRange\",\"update\",\"update\"]", "[[7,7],[6,-13],[3,7],[7,7],[4,6],[4,4],[7,-41],[5,-13]]"], ["[19,21,-23,-50,9,27]", "[\"sumRange\",\"update\",\"update\",\"update\",\"update\"]", "[[1,5],[4,-39],[4,32],[5,47],[1,9]]"], ["[-36,-38,41,-7,-47,-49,48,-46]", "[\"sumRange\",\"sumRange\",\"sumRange\",\"update\",\"sumRange\",\"sumRange\"]", "[[3,7],[2,6],[5,7],[2,14],[2,2],[3,5]]"], ["[-38,-39,3,-1,-44,-18,24,-6]", "[\"sumRange\",\"update\",\"sumRange\",\"sumRange\"]", "[[6,6],[2,-30],[3,6],[3,7]]"], ["[-12,4,-5,28,31]", "[\"sumRange\",\"sumRange\",\"update\"]", "[[3,3],[2,2],[0,4]]"], ["[37]", "[\"sumRange\",\"update\",\"sumRange\",\"sumRange\"]", "[[0,0],[0,-44],[0,0],[0,0]]"], ["[45,-7,-46,-21,24]", "[\"sumRange\",\"sumRange\",\"sumRange\"]", "[[3,3],[2,3],[0,3]]"], ["[17,-30,-47,-21,33]", "[\"sumRange\",\"update\",\"sumRange\",\"sumRange\",\"update\",\"update\",\"sumRange\"]", "[[0,2],[1,44],[2,3],[0,1],[4,47],[2,1],[1,1]]"], ["[-16,-5,-15]", "[\"sumRange\",\"sumRange\",\"sumRange\",\"sumRange\",\"update\",\"sumRange\",\"update\"]", "[[1,2],[0,0],[2,2],[1,1],[0,-25],[1,1],[0,-7]]"], ["[33,-26,-11,-44,-48,-24]", "[\"sumRange\",\"update\",\"sumRange\",\"update\",\"sumRange\",\"sumRange\",\"sumRange\"]", "[[4,5],[2,-17],[2,5],[3,25],[1,3],[1,4],[3,5]]"], ["[10,14,-30,13,43,26,-37]", "[\"sumRange\",\"sumRange\",\"update\",\"sumRange\",\"sumRange\",\"sumRange\"]", "[[2,6],[5,6],[0,-50],[1,6],[6,6],[1,2]]"], ["[35,6,21,15,-8,16,-30]", "[\"sumRange\",\"update\",\"update\"]", "[[0,3],[2,-16],[1,21]]"], ["[7,-5,29,-22,-47,-1,40,8]", "[\"sumRange\",\"sumRange\",\"update\",\"update\"]", "[[5,5],[5,5],[3,49],[7,-18]]"], ["[-15,2,-7]", "[\"sumRange\",\"sumRange\",\"sumRange\",\"update\",\"update\",\"sumRange\",\"update\"]", "[[0,0],[2,2],[1,2],[1,43],[1,-20],[1,2],[2,29]]"], ["[-47,-26,45,12,40,-19,-9]", "[\"sumRange\",\"sumRange\",\"sumRange\",\"update\"]", "[[3,4],[4,4],[5,6],[2,0]]"], ["[-13,30,-2,-10,11]", "[\"sumRange\",\"sumRange\",\"update\",\"update\"]", "[[1,4],[0,1],[2,1],[0,-6]]"]], "expected": [[9, 8], [7, 4], [8], [16, 45, 25], [-14, 0], [-18], [-32, -32, -32], [-41, 42, 42, 42, 35, 42], [33, 17, -26, -9], [-39, -22, -50], [9, -4, 13], [37, 37], [-37, 11, -37, 45, 9], [-16], [-101, -14, -47, 14, -103], [24, -39, -45], [28, -5], [37, -44, -44], [-21, -67, -29], [-60, -68, 61, 44], [-20, -16, -15, -5, -5], [-72, -133, -18, -66, -47], [15, -11, 29, -37, -16], [77], [-1, -1], [-15, -7, -5, -27], [52, 40, -28], [29, 17]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "459", "slug": "ransom-note", "id": 459, "title": "Ransom Note", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/ransom-note/", "examples": [{"input": "ransomNote = \"a\", magazine = \"b\"", "output": "false", "explanation": "Letter a is missing."}, {"input": "ransomNote = \"aa\", magazine = \"ab\"", "output": "false", "explanation": "Only one a for two needed."}, {"input": "ransomNote = \"aa\", magazine = \"aab\"", "output": "true", "explanation": "Two a copies cover the request."}], "hints": ["Count how many times each letter appears in the magazine.", "Walk the ransom note, spending one copy per letter and failing on shortage.", "A fixed array of 26 counters is enough for lowercase letters."], "statement": "Decide whether one string can be assembled from the letters of another.\n\nGiven a target text `ransomNote` and a source text `magazine`, both made of lowercase English letters, determine whether the target can be built by taking letters from the source. Each source character may be used at most once, so the source must contain every needed letter at least as many times as the target asks for it. Return `true` when construction is possible and `false` otherwise.\n\n**Constraints:**\n- `1 <= ransomNote.length, magazine.length <= 10^5`\n- Both strings consist of lowercase English letters.\n", "solution": "## Approach\n\nTally the magazine's letters into 26 counters. Then consume one counter per ransom-note letter; running below zero means the source is short, while surviving the whole scan means construction works.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + m), where n and m are the two string lengths.\n- **Space Complexity:** O(1) for the fixed alphabet table.\n\n## Implementation\n\n```python\nclass Solution:\n def canConstruct(self, ransomNote: str, magazine: str) -> bool:\n cnt = [0] * 26\n for c in magazine:\n cnt[ord(c) - 97] += 1\n for c in ransomNote:\n cnt[ord(c) - 97] -= 1\n if cnt[ord(c) - 97] < 0:\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc CanConstruct(ransomNote string, magazine string) bool {\n return false\n}", "python": "class Solution:\n def canConstruct(self, ransomNote: str, magazine: str) -> bool:\n return False\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool canConstruct(string ransomNote, string magazine) {\n return false;\n }\n};"}, "fn": "canConstruct", "params": [{"name": "ransomNote", "type": "string"}, {"name": "magazine", "type": "string"}], "outputType": "boolean", "tests": [["a", "b"], ["aa", "ab"], ["aa", "aab"], ["abc", "cba"], ["a", "a"], ["ab", "ba"], ["abc", "ab"], ["hello", "helloworld"], ["helloworldx", "helloworld"], ["zzzz", "zzzzzzzz"], ["abcde", "edcba"], ["aabbcc", "abcabc"], ["aaabbb", "aabbb"], ["xyz", "xyyzz"], ["mississippi", "mississippii"], ["mississippii", "mississippi"], ["qwerty", "ytrewq"], ["aaaa", "aaa"], ["b", "a"], ["abc", "def"], ["aab", "aba"], ["abcd", "abcde"], ["abcde", "abcd"], ["note", "tonex"], ["python", "typhon"], ["leetcode", "codeleet"], ["aa", "aa"], ["ab", "a"], ["abcabc", "aabbcc"], ["z", "abcdefghijklmnopqrstuvwxyz"]], "expected": [false, false, true, true, true, true, false, true, false, true, true, true, false, true, true, false, true, false, false, false, true, true, false, true, true, true, true, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "756", "slug": "reach-a-number", "id": 756, "title": "Reach a Number", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/reach-a-number/", "examples": [{"input": "target = 2", "output": "3", "explanation": "1 right, 2 left, 3 right lands on 2."}, {"input": "target = 3", "output": "2", "explanation": "1 right then 2 right lands on 3."}, {"input": "target = 4", "output": "3", "explanation": "Left 1, right 2, right 3 gives 4."}], "hints": ["Only the distance from zero matters, so replace target by its absolute value.", "Grow n until the triangular sum n*(n+1)/2 reaches the distance; any smaller n cannot cover it.", "Flipping a step of size x changes the total by 2*x, so the overshoot must be even; add one or two more moves otherwise."], "statement": "You start at position `0` on an endless number line and want to reach `target`, which is never zero.\n\nOn move number `i` (counting from 1), you must walk exactly `i` steps either to the left or to the right. Moves accumulate: after three moves you have walked 1 + 2 + 3 steps split by direction choices.\n\nReturn the smallest number of moves that can land exactly on `target`.\n\n**Constraints:**\n- `-10^9 <= target <= 10^9`\n- `target != 0`\n", "solution": "## Approach\n\nReplace the target by its absolute value since left-right symmetry makes the sign irrelevant. Accumulate triangular sums 1, 3, 6, 10, ... until reaching at least the distance. Reversing a step of size x shifts the reachable total by 2*x, so the gap between the sum and the distance must be even; otherwise extend by one or two moves until parity matches.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(sqrt(|target|)), for growing n until the triangular sum covers the distance.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def reachNumber(self, target: int) -> int:\n t = abs(target)\n n = 0\n while True:\n n += 1\n s = n * (n + 1) // 2\n if s >= t and (s - t) % 2 == 0:\n return n\n```\n", "starter": {"go": "package main\n\nfunc ReachNumber(target int) int {\n return 0\n}", "python": "class Solution:\n def reachNumber(self, target: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int reachNumber(int target) {\n return 0;\n }\n};"}, "fn": "reachNumber", "params": [{"name": "target", "type": "int"}], "outputType": "int", "tests": [["2"], ["3"], ["1"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["-1"], ["-2"], ["-3"], ["100"], ["1000"], ["1000000"], ["1000000000"], ["-1000000000"], ["11"], ["12"], ["13"], ["14"], ["15"], ["21"], ["100000"], ["-99999"], ["999999999"], ["-2147483647"]], "expected": [3, 2, 1, 3, 5, 3, 5, 4, 5, 4, 1, 3, 2, 15, 47, 1415, 44723, 44723, 5, 7, 5, 7, 5, 6, 447, 449, 44721, 65537], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "873", "slug": "reachable-nodes-in-subdivided-graph", "id": 873, "title": "Reachable Nodes In Subdivided Graph", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/reachable-nodes-in-subdivided-graph/", "examples": [{"input": "edges = [[0,1,10],[0,2,1],[1,2,2]], maxMoves = 6, n = 3", "output": "13", "explanation": "All 3 original nodes are within reach. The three links contribute 7, 1 and 2 reachable middle nodes, for 3 + 7 + 1 + 2 = 13."}, {"input": "edges = [[0,1,4],[1,2,6],[0,2,8],[1,3,1]], maxMoves = 10, n = 4", "output": "23", "explanation": "All 4 original nodes are within reach, and the four links contribute 4, 6, 8 and 1 middle nodes, for 4 + 4 + 6 + 8 + 1 = 23."}, {"input": "edges = [[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]], maxMoves = 17, n = 5", "output": "1", "explanation": "Node 0 is isolated, so with no way to leave it only node 0 itself is reachable."}], "hints": ["Run Dijkstra from node 0 where crossing edge [u,v,cnt] costs cnt + 1; every original node with distance at most maxMoves is reachable.", "For each subdivided link, the leftover moves at its two ends cover min(cnt, leftU + leftV) middle nodes."], "statement": "An undirected graph has `n` original nodes numbered `0` to `n - 1`. Each entry `edges[i] = [u, v, cnt]` means the direct link between `u` and `v` is split by `cnt` brand-new middle nodes in a row, so traveling from `u` to `v` costs `cnt + 1` moves.\n\nStarting from node `0` with at most `maxMoves` moves, you may walk along these chains in any way. Count every node you can reach: original nodes plus any subdivision nodes stepped on. Return that total.\n\n**Constraints:**\n- `0 <= edges.length <= 10^4`\n- `edges[i] = [u, v, cnt]` with `0 <= u, v < n` and `u != v`\n- `0 <= cnt <= 10^4`\n- `0 <= maxMoves <= 10^9`\n- `1 <= n <= 10`\n", "solution": "## Approach\n\nModel each subdivided link as a weighted edge of cost `cnt + 1` and run Dijkstra from node 0 to learn the cheapest arrival distance for every original node. Original nodes whose distance fits inside `maxMoves` are directly counted. For each link, the unused moves remaining at its two endpoints (`maxMoves - dist`) can sweep inward over middle nodes from both sides, covering up to `min(cnt, leftoverU + leftoverV)` of them.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(E log n), where E is the number of links, for Dijkstra plus a linear pass over the links.\n- **Space Complexity:** O(n + E) for the adjacency lists and distance array.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\n\nclass Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int:\n g = [[] for _ in range(n)]\n for u, v, c in edges:\n g[u].append((v, c + 1))\n g[v].append((u, c + 1))\n INF = float(\"inf\")\n dist = [INF] * n\n dist[0] = 0\n pq = [(0, 0)]\n while pq:\n d, u = heapq.heappop(pq)\n if d != dist[u]:\n continue\n for v, w in g[u]:\n if dist[v] > d + w:\n dist[v] = d + w\n heapq.heappush(pq, (dist[v], v))\n ans = sum(1 for d in dist if d <= maxMoves)\n for u, v, c in edges:\n left_u = 0 if dist[u] > maxMoves else maxMoves - dist[u]\n left_v = 0 if dist[v] > maxMoves else maxMoves - dist[v]\n ans += min(c, left_u + left_v)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc ReachableNodes(edges [][]int, maxMoves int, n int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def reachableNodes(self, edges: List[List[int]], maxMoves: int, n: int) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int reachableNodes(vector<vector<int>>& edges, int maxMoves, int n) {\n return 0;\n }\n};"}, "fn": "reachableNodes", "params": [{"name": "edges", "type": "int_array_2d"}, {"name": "maxMoves", "type": "int"}, {"name": "n", "type": "int"}], "outputType": "int", "tests": [["[[0,1,10],[0,2,1],[1,2,2]]", "6", "3"], ["[[0,1,4],[1,2,6],[0,2,8],[1,3,1]]", "10", "4"], ["[[1,2,4],[1,4,5],[1,3,1],[2,3,4],[3,4,5]]", "17", "5"], ["[]", "0", "1"], ["[[0,1,5]]", "0", "2"], ["[[0,1,5]]", "3", "2"], ["[[0,1,5]]", "11", "2"], ["[[0,1,0]]", "0", "2"], ["[[0,1,0]]", "1", "2"], ["[[0,1,2],[1,2,2]]", "4", "3"], ["[[0,1,2],[1,2,2]]", "9", "3"], ["[[0,2,10]]", "5", "3"], ["[[0,1,1],[0,2,1],[0,3,1]]", "1", "4"], ["[[0,1,1],[0,2,1],[0,3,1]]", "2", "4"], ["[[0,1,3],[0,2,3],[1,2,3]]", "4", "3"], ["[[0,1,1],[1,2,1],[2,3,1],[3,4,1]]", "3", "5"], ["[[0,1,1],[1,2,1],[2,3,1],[3,4,1]]", "8", "5"], ["[[0,1,10],[1,2,10],[2,3,10],[0,3,10]]", "5", "4"], ["[[0,1,0],[1,2,0],[2,3,0],[0,3,0]]", "2", "4"], ["[[0,1,0],[1,2,0],[0,2,0]]", "1", "3"], ["[[0,1,2],[0,2,2],[0,3,2],[0,4,2]]", "2", "5"], ["[[0,1,2],[0,2,2],[0,3,2],[0,4,2]]", "3", "5"], ["[[0,1,10000]]", "10000", "3"], ["[[0,1,10000]]", "10001", "3"], ["[[0,1,1],[2,3,1],[4,5,1]]", "10", "6"], ["[[0,1,3],[1,2,3],[2,0,3],[2,3,1]]", "5", "4"], ["[]", "5", "2"], ["[[0,4,8],[4,1,8],[1,2,8],[2,3,8]]", "9", "5"]], "expected": [13, 23, 1, 1, 1, 4, 7, 1, 2, 5, 7, 6, 4, 7, 9, 4, 9, 11, 4, 3, 9, 13, 10001, 10002, 3, 12, 1, 10], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "779", "slug": "reaching-points", "id": 779, "title": "Reaching Points", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/reaching-points/", "examples": [{"input": "sx = 1, sy = 1, tx = 3, ty = 5", "output": "true", "explanation": "A forward chain such as (1,1) -> (1,2) -> (3,2) -> (3,5) reaches the goal."}, {"input": "sx = 1, sy = 1, tx = 2, ty = 2", "output": "false", "explanation": "No sequence of allowed jumps produces (2,2) from (1,1)."}, {"input": "sx = 1, sy = 1, tx = 1, ty = 1", "output": "true", "explanation": "Start equals target, so no move is needed."}], "hints": ["Work backwards from the target: the larger coordinate must have come from subtracting the smaller one.", "When one coordinate already matches the start, check divisibility: the gap on the other axis must be a multiple of the fixed coordinate.", "Use remainders instead of single subtractions so huge coordinates shrink in logarithmic steps."], "statement": "Starting from a lattice point, you may repeatedly replace `(x, y)` with\neither `(x + y, y)` or `(x, x + y)`. Both coordinates only grow, since all\nvalues stay positive. Given a launch point `(sx, sy)` and a destination\n`(tx, ty)`, determine whether the destination can ever be reached by a\nsequence of such jumps.\n\nThink backwards: from the target, the previous step must have subtracted\nthe smaller coordinate from the larger one. Repeating that reduction with\ndivision (rather than one subtraction at a time) keeps the process fast\neven for coordinates up to a billion.\n\n**Constraints:**\n- `1 <= sx, sy, tx, ty <= 10^9`\n", "solution": "## Approach\n\nSimulate the process in reverse. While both target coordinates stay at or\nabove the start, the larger one must have been produced by adding the\nsmaller one some number of times, so subtract a whole batch at once with a\nremainder operation. When one axis already equals its start value, the other\naxis only needs a divisibility check. If a remainder becomes zero or a\ncoordinate drops below its start value, the target is unreachable.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log(min(tx, ty))) due to the remainder-style shrinking.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:\n while tx >= sx and ty >= sy:\n if tx == sx and ty == sy:\n return True\n if tx == sx:\n return (ty - sy) % tx == 0\n if ty == sy:\n return (tx - sx) % ty == 0\n if tx > ty:\n tx %= ty\n else:\n ty %= tx\n return False\n```\n", "starter": {"go": "package main\n\nfunc ReachingPoints(sx int, sy int, tx int, ty int) bool {\n return false\n}", "python": "class Solution:\n def reachingPoints(self, sx: int, sy: int, tx: int, ty: int) -> bool:\n return False\n", "cpp": "class Solution {\npublic:\n bool reachingPoints(int sx, int sy, int tx, int ty) {\n return false;\n }\n};"}, "fn": "reachingPoints", "params": [{"name": "sx", "type": "int"}, {"name": "sy", "type": "int"}, {"name": "tx", "type": "int"}, {"name": "ty", "type": "int"}], "outputType": "boolean", "tests": [["1", "1", "3", "5"], ["1", "1", "2", "2"], ["1", "1", "1", "1"], ["1", "1", "5", "3"], ["2", "3", "7", "10"], ["2", "3", "7", "11"], ["3", "5", "9", "14"], ["1", "2", "1", "1000000000"], ["2", "1", "1000000000", "1"], ["1", "1", "1000000000", "1"], ["1", "1", "1", "1000000000"], ["5", "5", "5", "5"], ["5", "5", "10", "5"], ["5", "5", "5", "10"], ["5", "5", "15", "10"], ["9", "5", "12", "8"], ["9", "10", "9", "19"], ["3", "3", "12", "9"], ["1", "4", "5", "9"], ["4", "1", "9", "5"], ["10", "20", "10", "20"], ["10", "20", "30", "20"], ["7", "7", "21", "28"], ["35", "122", "157", "279"], ["1000000000", "1000000000", "1000000000", "1000000000"], ["1", "1", "1000000000", "1000000000"], ["2", "4", "6", "10"], ["6", "10", "16", "10"]], "expected": [true, false, true, true, false, false, false, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "311", "slug": "read-n-characters-given-read4-ii-call-multiple-times", "id": 311, "title": "Read N Characters Given Read4 II - Call Multiple Times", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/read-n-characters-given-read4-ii-call-multiple-times/", "examples": [{"input": "file = \"abc\", queries = [1,2,1]", "output": "[\"a\",\"bc\",\"\"]", "explanation": "First call takes \"a\", second takes \"bc\", and the third finds nothing left."}, {"input": "file = \"abc\", queries = [4,1]", "output": "[\"abc\",\"\"]", "explanation": "The first call drains the file; the second returns empty."}], "hints": ["Keep one position pointer shared across all queries.", "Each query takes file[pos:pos+q] and advances pos by the taken amount.", "Once pos reaches the end, all later queries return empty strings."], "statement": "You are given a file's full text `file` and a sequence of request sizes `queries`. Imagine calling a `read(n)` routine several times in a row, where each call uses `read4` internally, keeps any leftover characters buffered between calls, and continues from where the previous call stopped.\n\nSimulate all calls at once: for each `queries[i]`, collect up to that many characters from the current file position (using leftover buffered data first), advance the position, and store the chunk.\n\nReturn the list of collected chunks, one per query.\n\n**Constraints:**\n- `0 <= file.length <= 10^4`\n- `file` holds letters and digits (no spaces, to keep chunk boundaries unambiguous).\n- `1 <= queries.length <= 100`\n- `0 <= queries[i] <= 10^4`\n\n**Adaptation note:** The original LeetCode task is a stateful class (`Reader4.read` keeps an internal buffer across calls). To fit the judge's stateless-function model, the batch of call sizes is passed as `queries` (`int_array`) and the per-call results are returned together as `string_list`. The chunking behavior, including leftovers carried between calls, is identical to sequential calls.\n", "solution": "## Approach\n\nShare one file pointer across the query batch, with a small leftover buffer that mimics `read4` fetching four characters at a time. For each requested size, first drain the leftover, then pull fresh four-character blocks as needed, moving exactly the consumed characters into the current chunk. Exhaustion yields empty strings for the remaining queries.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(F + Q), where F is the file length scanned once and Q is the number of queries.\n- **Space Complexity:** O(F) for the output chunks plus O(1) buffer state.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def read(self, file: str, queries: List[int]) -> List[str]:\n ans = []\n pos = 0\n leftover = \"\"\n for q in queries:\n need = max(q, 0)\n chunk = []\n while need > 0:\n if not leftover:\n if pos >= len(file):\n break\n take = min(4, len(file) - pos)\n leftover = file[pos:pos + take]\n pos += take\n use = min(need, len(leftover))\n chunk.append(leftover[:use])\n leftover = leftover[use:]\n need -= use\n ans.append(\"\".join(chunk))\n return ans\n```\n", "starter": {"go": "package main\n\nfunc Read(file string, queries []int) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def read(self, file: str, queries: List[int]) -> List[str]:\n return []", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> read(string file, vector<int>& queries) {\n return {};\n }\n};"}, "fn": "read", "params": [{"name": "file", "type": "string"}, {"name": "queries", "type": "int_array"}], "outputType": "string_list", "tests": [["abc", "[1,2,1]"], ["abc", "[4,1]"], ["abcde", "[5]"], ["", "[1,2]"], ["a", "[1]"], ["a", "[2]"], ["ab", "[1,1,1]"], ["abcd", "[4]"], ["abcde", "[2,2,2]"], ["abcdefgh", "[3,3,3]"], ["helloworld", "[5,6]"], ["helloworld", "[10,1]"], ["1234567890", "[4,4,4]"], ["abcd", "[0,4]"], ["", "[0]"], ["x", "[0,1]"], ["Thequickbrownfox", "[10,9,5]"], ["aaaaaaaaaa", "[3,3,3,3]"], ["abcdEFGH", "[1,1,1,1,1,1,1,1,1]"], ["1234", "[10]"], ["12345", "[4,4]"], ["qwertyuiop", "[5,5,5]"], ["abcdABCD1234", "[12]"], ["abcdABCD1234", "[4,4,4,4]"], ["ab", "[5]"], ["hello", "[1,1,1,1,1,1]"], ["filecontent", "[2,0,3]"], ["abcdefg", "[7,7]"]], "expected": [["a", "bc", ""], ["abc", ""], ["abcde"], ["", ""], ["a"], ["a"], ["a", "b", ""], ["abcd"], ["ab", "cd", "e"], ["abc", "def", "gh"], ["hello", "world"], ["helloworld", ""], ["1234", "5678", "90"], ["", "abcd"], [""], ["", "x"], ["Thequickbr", "ownfox", ""], ["aaa", "aaa", "aaa", "a"], ["a", "b", "c", "d", "E", "F", "G", "H", ""], ["1234"], ["1234", "5"], ["qwert", "yuiop", ""], ["abcdABCD1234"], ["abcd", "ABCD", "1234", ""], ["ab"], ["h", "e", "l", "l", "o", ""], ["fi", "", "lec"], ["abcdefg", ""]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "310", "slug": "read-n-characters-given-read4", "id": 310, "title": "Read N Characters Given Read4", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/read-n-characters-given-read4/", "examples": [{"input": "file = \"abc\", n = 4", "output": "\"abc\"", "explanation": "Only three characters exist, so the reader stops early."}, {"input": "file = \"abcde\", n = 5", "output": "\"abcde\"", "explanation": "Exactly the whole file is requested."}, {"input": "file = \"abcdABCD1234\", n = 12", "output": "\"abcdABCD1234\"", "explanation": "Twelve characters fill three read4 calls exactly."}], "hints": ["The answer is simply the file prefix of length min(n, file length).", "Think in read4 chunks: full groups of four plus one final partial group.", "An empty file or n = 0 both yield an empty string."], "statement": "You are given a file's full text `file` and a request size `n`. Imagine a reader that can only fetch four characters at a time (`read4`), called repeatedly until `n` characters are gathered or the file ends.\n\nReturn the characters that such a reader would collect: the first `n` characters of `file`, or the whole file when it is shorter than `n`.\n\n**Constraints:**\n- `0 <= file.length <= 10^4`\n- `file` holds printable ASCII characters.\n- `0 <= n <= 10^4`\n\n**Adaptation note:** The original LeetCode API exposes `read4` and asks you to fill a buffer. To fit the judge's plain-function model, the file content is passed directly as `file` and the answer is returned as a string instead of a count plus buffer. The observable behavior (first `min(n, len)` characters) is identical.\n", "solution": "## Approach\n\nSimulating `read4` still amounts to taking a prefix: copy at most four characters per step until `n` characters are collected or the file is exhausted. The result is the first `min(n, length)` characters.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of characters returned.\n- **Space Complexity:** O(n) for the output string.\n\n## Implementation\n\n```python\nclass Solution:\n def read(self, file: str, n: int) -> str:\n return file[:max(n, 0)]\n```\n", "starter": {"go": "package main\n\nfunc Read(file string, n int) string {\n return \"\"\n}", "python": "class Solution:\n def read(self, file: str, n: int) -> str:\n return \"\"", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string read(string file, int n) {\n return \"\";\n }\n};"}, "fn": "read", "params": [{"name": "file", "type": "string"}, {"name": "n", "type": "int"}], "outputType": "string", "tests": [["abc", "4"], ["abcde", "5"], ["abcdABCD1234", "12"], ["", "4"], ["a", "1"], ["a", "5"], ["ab", "1"], ["abcd", "4"], ["abcde", "1"], ["abcde", "2"], ["abcde", "3"], ["abcde", "4"], ["abcdefgh", "8"], ["abcdefgh", "5"], ["hello world", "5"], ["hello world", "11"], ["hello world", "20"], ["1234567890", "7"], ["abcd", "0"], ["", "0"], ["x", "0"], ["The quick brown fox", "10"], ["The quick brown fox", "19"], ["aaaaaaaaaa", "3"], ["abcdEFGH", "6"], ["1234", "10"], ["12345", "4"], ["qwertyuiopasdfgh", "16"]], "expected": ["abc", "abcde", "abcdABCD1234", "", "a", "a", "a", "abcd", "a", "ab", "abc", "abcd", "abcdefgh", "abcde", "hello", "hello world", "hello world", "1234567", "", "", "", "The quick ", "The quick brown fox", "aaa", "abcdEF", "1234", "1234", "qwertyuiopasdfgh"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "437", "slug": "rearrange-string-k-distance-apart", "id": 437, "title": "Rearrange String K Distance Apart", "difficulty": "Hard", "category": "heap", "link": "https://leetcode.com/problems/rearrange-string-k-distance-apart/", "examples": [{"input": "s = \"aabbcc\", k = 3", "output": "\"abcabc\"", "explanation": "Equal letters sit 3 apart, so the spacing rule holds."}, {"input": "s = \"aaabc\", k = 3", "output": "\"\"", "explanation": "The three copies of 'a' cannot all be kept far enough apart."}, {"input": "s = \"aaadbbcc\", k = 2", "output": "\"abacabcd\"", "explanation": "One valid layout; every repeated letter has a gap of at least 2."}], "hints": ["Always emit the currently most frequent remaining letter using a max-heap.", "Hold the last k-1 emitted letters in a waiting queue before their counts re-enter the heap.", "When k is 0 or 1, the original string is already valid."], "statement": "You are given a lowercase string `s` and an integer `k`. Reorder its\ncharacters into a new string where any two equal letters are separated by at\nleast `k` positions (there must be `k - 1` other characters between them).\nWhen no such ordering exists, return the empty string.\n\nFor example, `\"aabbcc\"` with `k = 3` can become `\"abcabc\"`, while `\"aaabc\"`\nwith `k = 3` is impossible because three `a` letters need at least\n`3 + 2 * (3 - 1) = 7` slots but only 5 characters exist.\n\nNote that many orderings may be valid; any correct one is accepted.\n\n**Constraints:**\n- `1 <= s.length <= 500`\n- `s` consists of lowercase English letters\n- `1 <= k <= s.length`\n", "solution": "## Approach\n\nRepeatedly emit the most frequent remaining letter with a max-heap, parking\neach used letter in a waiting queue of length k - 1 so copies resurface only\nwhen the spacing rule allows. If the heap empties before every character is\nplaced, the task is impossible and the answer is empty.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log a), where n is the string length and a the alphabet size.\n- **Space Complexity:** O(a) for the heap and the waiting queue.\n\n## Implementation\n\n```python\nimport heapq\nfrom collections import Counter, deque\n\nclass Solution:\n def rearrangeString(self, s: str, k: int) -> str:\n if not s or k <= 1:\n return s\n counts = Counter(s)\n heap = [(-c, ch) for ch, c in counts.items()]\n heapq.heapify(heap)\n wait: deque = deque()\n out = []\n while heap:\n c, ch = heapq.heappop(heap)\n out.append(ch)\n c += 1\n wait.append((c, ch))\n if len(wait) == k:\n rc, rch = wait.popleft()\n if rc < 0:\n heapq.heappush(heap, (rc, rch))\n return \"\".join(out) if len(out) == len(s) else \"\"\n```\n", "starter": {"go": "package main\n\nfunc RearrangeString(s string, k int) string {\n \n}", "python": "class Solution:\n def rearrangeString(self, s: str, k: int) -> str:\n pass", "cpp": "#include <string>\n#include <queue>\nusing namespace std;\nclass Solution {\npublic:\n string rearrangeString(string s, int k) {\n return \"\";\n }\n};"}, "fn": "rearrangeString", "params": [{"name": "s", "type": "string"}, {"name": "k", "type": "int"}], "outputType": "string", "tests": [["aabbcc", "3"], ["aaabc", "3"], ["aaadbbcc", "2"], ["a", "1"], ["aa", "1"], ["aa", "2"], ["ab", "2"], ["aabb", "2"], ["aab", "2"], ["aaab", "2"], ["abcdef", "3"], ["aaaa", "1"], ["aaaa", "4"], ["abcabc", "3"], ["xxyyzz", "2"], ["aaabbbccc", "3"], ["aaabbbccc", "2"], ["leetcode", "2"], ["abbabbaaab", "3"], ["a", "5"], ["abccab", "2"], ["zzzxxx", "3"], ["abcde", "5"], ["aabbbcc", "2"], ["aaabbb", "3"], ["abcdabcd", "4"], ["qwerty", "1"]], "expected": ["acbacb", "", "abcabcad", "a", "aa", "", "ab", "abab", "aba", "", "afedcb", "aaaa", "", "acbacb", "xzyxzy", "acbacbacb", "acbacbacb", "eoectedl", "", "a", "acbacb", "", "aedcb", "bcabcab", "", "adcbadcb", "qwerty"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "122", "slug": "reconstruct-itinerary", "id": 122, "title": "Reconstruct Itinerary", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/reconstruct-itinerary/", "examples": [{"input": "from = [\"MUC\",\"JFK\",\"SFO\",\"LHR\"], to = [\"LHR\",\"MUC\",\"SJC\",\"SFO\"]", "output": "[\"JFK\",\"MUC\",\"LHR\",\"SFO\",\"SJC\"]", "explanation": "Starting from JFK, the itinerary travels to MUC, then LHR, then SFO, and finally SJC, using each ticket exactly once."}, {"input": "from = [\"JFK\",\"JFK\",\"SFO\",\"ATL\",\"ATL\"], to = [\"SFO\",\"ATL\",\"ATL\",\"JFK\",\"SFO\"]", "output": "[\"JFK\",\"ATL\",\"JFK\",\"SFO\",\"ATL\",\"SFO\"]", "explanation": "Starting from JFK, the itinerary travels to ATL, back to JFK, then to SFO, to ATL, and finally to SFO, using each ticket exactly once."}], "hints": ["View tickets as directed edges and the requested itinerary as an Eulerian trail from JFK.", "Always consume the smallest available destination, but append an airport only after all of its outgoing tickets have been consumed.", "Hierholzer's algorithm with a min-heap per departure airport produces the lexical minimum in O(E log E) time."], "statement": "You are given airline tickets as two parallel arrays. Ticket `i` travels from\n`from[i]` to `to[i]`. Reconstruct an itinerary that begins at `\"JFK\"` and uses\nevery ticket exactly once.\n\nIf several valid itineraries exist, return the lexicographically smallest one\nwhen the airport sequence is compared from left to right. The input is\nguaranteed to admit at least one itinerary from `\"JFK\"`.\n\n**Constraints:**\n\n- `1 <= from.length == to.length <= 300`\n- Every airport code consists of three uppercase English letters.\n- `from[i] != to[i]`\n- Duplicate tickets are allowed and must each be used once.\n- At least one itinerary uses every ticket and starts at `\"JFK\"`.\n", "solution": "## Approach\n\nView tickets as directed edges and the itinerary as an Eulerian trail beginning at `JFK`. Sort each departure's destinations in reverse lexical order so the smallest remaining destination can be removed from the end. Hierholzer's algorithm appends an airport only after consuming all of its outgoing tickets, then reverses that postorder route.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(E log E) in the worst case for sorting destinations, followed by O(E) traversal.\n- **Space Complexity:** O(E) for the adjacency lists, recursion stack, and route.\n\n## Implementation\n\n```python\nfrom collections import defaultdict\nfrom typing import List\n\n\nclass Solution:\n def findItinerary(self, from_: List[str], to: List[str]) -> List[str]:\n graph = defaultdict(list)\n for origin, destination in zip(from_, to):\n graph[origin].append(destination)\n for destinations in graph.values():\n destinations.sort(reverse=True)\n\n route = []\n\n def visit(airport: str) -> None:\n while graph[airport]:\n visit(graph[airport].pop())\n route.append(airport)\n\n visit(\"JFK\")\n return route[::-1]\n```\n", "starter": {"go": "package main\n\nfunc FindItinerary(from []string, to []string) []string {\n return nil\n}\n", "python": "from typing import List\n\nclass Solution:\n def findItinerary(self, from_: List[str], to: List[str]) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> findItinerary(vector<string>& from, vector<string>& to) {\n return {};\n }\n};"}, "fn": "findItinerary", "params": [{"name": "from", "type": "string_array"}, {"name": "to", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"JFK\"]", "[\"SFO\"]"], ["[\"JFK\",\"SFO\"]", "[\"SFO\",\"LAX\"]"], ["[\"SFO\",\"JFK\"]", "[\"LAX\",\"SFO\"]"], ["[\"JFK\",\"ATL\"]", "[\"ATL\",\"JFK\"]"], ["[\"JFK\",\"ATL\",\"JFK\"]", "[\"ATL\",\"JFK\",\"SFO\"]"], ["[\"MUC\",\"JFK\",\"SFO\",\"LHR\"]", "[\"LHR\",\"MUC\",\"SJC\",\"SFO\"]"], ["[\"JFK\",\"JFK\",\"SFO\",\"ATL\",\"ATL\"]", "[\"SFO\",\"ATL\",\"ATL\",\"JFK\",\"SFO\"]"], ["[\"JFK\",\"JFK\",\"NRT\"]", "[\"KUL\",\"NRT\",\"JFK\"]"], ["[\"JFK\",\"AAA\",\"JFK\"]", "[\"AAA\",\"JFK\",\"BBB\"]"], ["[\"JFK\",\"JFK\",\"AAA\"]", "[\"BBB\",\"AAA\",\"JFK\"]"], ["[\"JFK\",\"AAA\",\"JFK\",\"BBB\"]", "[\"AAA\",\"JFK\",\"BBB\",\"JFK\"]"], ["[\"BBB\",\"JFK\",\"AAA\",\"JFK\",\"JFK\"]", "[\"JFK\",\"AAA\",\"JFK\",\"BBB\",\"CCC\"]"], ["[\"JFK\",\"AAA\",\"BBB\",\"AAA\"]", "[\"AAA\",\"BBB\",\"AAA\",\"CCC\"]"], ["[\"BBB\",\"JFK\",\"AAA\",\"BBB\"]", "[\"AAA\",\"BBB\",\"BBB\",\"CCC\"]"], ["[\"JFK\",\"AAA\",\"JFK\"]", "[\"AAA\",\"JFK\",\"AAA\"]"], ["[\"JFK\",\"AAA\",\"BBB\"]", "[\"AAA\",\"BBB\",\"CCC\"]"], ["[\"AAA\",\"JFK\",\"BBB\",\"AAA\"]", "[\"BBB\",\"AAA\",\"AAA\",\"CCC\"]"], ["[\"JFK\",\"AAA\",\"JFK\",\"BBB\",\"JFK\"]", "[\"AAA\",\"JFK\",\"BBB\",\"JFK\",\"CCC\"]"], ["[\"JFK\",\"CCC\",\"BBB\",\"AAA\"]", "[\"AAA\",\"DDD\",\"CCC\",\"BBB\"]"], ["[\"CCC\",\"JFK\",\"AAA\",\"BBB\"]", "[\"DDD\",\"AAA\",\"BBB\",\"CCC\"]"], ["[\"JFK\",\"DFW\",\"ORD\",\"DEN\"]", "[\"DFW\",\"ORD\",\"DEN\",\"SEA\"]"], ["[\"ORD\",\"JFK\",\"DEN\",\"DFW\"]", "[\"DEN\",\"DFW\",\"SEA\",\"ORD\"]"], ["[\"JFK\",\"DFW\",\"ORD\",\"DEN\",\"SEA\"]", "[\"DFW\",\"ORD\",\"DEN\",\"SEA\",\"JFK\"]"], ["[\"SEA\",\"JFK\",\"DFW\",\"ORD\",\"DEN\",\"JFK\"]", "[\"JFK\",\"DFW\",\"ORD\",\"DEN\",\"SEA\",\"LAX\"]"], ["[\"JFK\",\"LAX\",\"JFK\",\"SFO\"]", "[\"LAX\",\"JFK\",\"SFO\",\"JFK\"]"], ["[\"JFK\",\"SFO\",\"JFK\",\"LAX\",\"JFK\"]", "[\"SFO\",\"JFK\",\"LAX\",\"JFK\",\"SEA\"]"], ["[\"JFK\",\"LAX\",\"SEA\",\"JFK\"]", "[\"LAX\",\"SEA\",\"JFK\",\"SFO\"]"], ["[\"SEA\",\"JFK\",\"LAX\",\"JFK\"]", "[\"JFK\",\"LAX\",\"SEA\",\"SFO\"]"], ["[\"JFK\",\"AMS\",\"CDG\",\"FRA\"]", "[\"AMS\",\"CDG\",\"FRA\",\"JFK\"]"], ["[\"CDG\",\"JFK\",\"FRA\",\"AMS\",\"JFK\"]", "[\"FRA\",\"AMS\",\"JFK\",\"CDG\",\"LHR\"]"], ["[\"JFK\",\"AMS\",\"JFK\",\"CDG\",\"JFK\"]", "[\"AMS\",\"JFK\",\"CDG\",\"JFK\",\"FRA\"]"], ["[\"JFK\",\"FRA\",\"JFK\",\"AMS\",\"JFK\",\"CDG\"]", "[\"FRA\",\"JFK\",\"AMS\",\"JFK\",\"CDG\",\"LHR\"]"], ["[\"JFK\",\"AAA\",\"AAB\",\"AAC\",\"AAD\"]", "[\"AAA\",\"AAB\",\"AAC\",\"AAD\",\"AAE\"]"], ["[\"AAC\",\"AAA\",\"JFK\",\"AAD\",\"AAB\"]", "[\"AAD\",\"AAB\",\"AAA\",\"AAE\",\"AAC\"]"], ["[\"JFK\",\"AAA\",\"AAB\",\"AAC\",\"AAD\",\"AAE\"]", "[\"AAA\",\"AAB\",\"AAC\",\"AAD\",\"AAE\",\"JFK\"]"], ["[\"JFK\",\"AAA\",\"JFK\",\"AAB\",\"JFK\",\"AAC\"]", "[\"AAA\",\"JFK\",\"AAB\",\"JFK\",\"AAC\",\"AAD\"]"], ["[\"AAC\",\"JFK\",\"AAA\",\"JFK\",\"AAB\",\"JFK\"]", "[\"JFK\",\"AAA\",\"JFK\",\"AAB\",\"JFK\",\"AAC\"]"], ["[\"JFK\",\"AAA\",\"AAB\",\"JFK\",\"AAC\",\"AAD\"]", "[\"AAA\",\"AAB\",\"JFK\",\"AAC\",\"AAD\",\"AAE\"]"], ["[\"JFK\",\"AAA\",\"AAB\",\"JFK\",\"AAC\",\"AAD\",\"AAE\"]", "[\"AAA\",\"AAB\",\"JFK\",\"AAC\",\"AAD\",\"AAE\",\"JFK\"]"], ["[\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\"]", "[\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"BBB\"]"], ["[\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"JFK\"]", "[\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"BBB\"]"], ["[\"JFK\",\"AAA\",\"AAA\",\"JFK\",\"BBB\"]", "[\"AAA\",\"JFK\",\"BBB\",\"AAA\",\"CCC\"]"], ["[\"AAA\",\"BBB\",\"JFK\",\"AAA\",\"BBB\"]", "[\"BBB\",\"AAA\",\"AAA\",\"BBB\",\"CCC\"]"], ["[\"JFK\",\"AAA\",\"BBB\",\"CCC\",\"AAA\"]", "[\"AAA\",\"BBB\",\"CCC\",\"AAA\",\"DDD\"]"], ["[\"CCC\",\"AAA\",\"JFK\",\"BBB\",\"AAA\"]", "[\"AAA\",\"BBB\",\"AAA\",\"CCC\",\"DDD\"]"], ["[\"JFK\",\"AAA\",\"BBB\",\"CCC\",\"DDD\",\"AAA\"]", "[\"AAA\",\"BBB\",\"CCC\",\"DDD\",\"AAA\",\"EEE\"]"], ["[\"JFK\",\"AAA\",\"BBB\",\"CCC\",\"DDD\",\"EEE\"]", "[\"AAA\",\"BBB\",\"CCC\",\"DDD\",\"EEE\",\"JFK\"]"], ["[\"JFK\",\"AAA\",\"JFK\",\"BBB\",\"JFK\",\"CCC\",\"JFK\"]", "[\"AAA\",\"JFK\",\"BBB\",\"JFK\",\"CCC\",\"JFK\",\"DDD\"]"], ["[\"CCC\",\"JFK\",\"AAA\",\"JFK\",\"BBB\",\"JFK\",\"JFK\"]", "[\"JFK\",\"AAA\",\"JFK\",\"BBB\",\"JFK\",\"CCC\",\"DDD\"]"], ["[\"JFK\",\"ATL\",\"JFK\",\"BOS\",\"JFK\",\"MIA\",\"JFK\",\"SEA\"]", "[\"ATL\",\"JFK\",\"BOS\",\"JFK\",\"MIA\",\"JFK\",\"SEA\",\"SFO\"]"], ["[\"JFK\",\"ATL\",\"BOS\",\"JFK\",\"MIA\",\"SEA\",\"JFK\",\"SFO\"]", "[\"ATL\",\"BOS\",\"JFK\",\"MIA\",\"SEA\",\"JFK\",\"SFO\",\"LAX\"]"], ["[\"SEA\",\"MIA\",\"JFK\",\"SFO\",\"ATL\",\"JFK\",\"BOS\",\"JFK\"]", "[\"JFK\",\"SEA\",\"ATL\",\"LAX\",\"BOS\",\"MIA\",\"JFK\",\"SFO\"]"], ["[\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\"]", "[\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\",\"AAA\",\"JFK\"]"]], "expected": [["JFK", "SFO"], ["JFK", "SFO", "LAX"], ["JFK", "SFO", "LAX"], ["JFK", "ATL", "JFK"], ["JFK", "ATL", "JFK", "SFO"], ["JFK", "MUC", "LHR", "SFO", "SJC"], ["JFK", "ATL", "JFK", "SFO", "ATL", "SFO"], ["JFK", "NRT", "JFK", "KUL"], ["JFK", "AAA", "JFK", "BBB"], ["JFK", "AAA", "JFK", "BBB"], ["JFK", "AAA", "JFK", "BBB", "JFK"], ["JFK", "AAA", "JFK", "BBB", "JFK", "CCC"], ["JFK", "AAA", "BBB", "AAA", "CCC"], ["JFK", "BBB", "AAA", "BBB", "CCC"], ["JFK", "AAA", "JFK", "AAA"], ["JFK", "AAA", "BBB", "CCC"], ["JFK", "AAA", "BBB", "AAA", "CCC"], ["JFK", "AAA", "JFK", "BBB", "JFK", "CCC"], ["JFK", "AAA", "BBB", "CCC", "DDD"], ["JFK", "AAA", "BBB", "CCC", "DDD"], ["JFK", "DFW", "ORD", "DEN", "SEA"], ["JFK", "DFW", "ORD", "DEN", "SEA"], ["JFK", "DFW", "ORD", "DEN", "SEA", "JFK"], ["JFK", "DFW", "ORD", "DEN", "SEA", "JFK", "LAX"], ["JFK", "LAX", "JFK", "SFO", "JFK"], ["JFK", "LAX", "JFK", "SFO", "JFK", "SEA"], ["JFK", "LAX", "SEA", "JFK", "SFO"], ["JFK", "LAX", "SEA", "JFK", "SFO"], ["JFK", "AMS", "CDG", "FRA", "JFK"], ["JFK", "AMS", "CDG", "FRA", "JFK", "LHR"], ["JFK", "AMS", "JFK", "CDG", "JFK", "FRA"], ["JFK", "AMS", "JFK", "FRA", "JFK", "CDG", "LHR"], ["JFK", "AAA", "AAB", "AAC", "AAD", "AAE"], ["JFK", "AAA", "AAB", "AAC", "AAD", "AAE"], ["JFK", "AAA", "AAB", "AAC", "AAD", "AAE", "JFK"], ["JFK", "AAA", "JFK", "AAB", "JFK", "AAC", "AAD"], ["JFK", "AAA", "JFK", "AAB", "JFK", "AAC", "JFK"], ["JFK", "AAA", "AAB", "JFK", "AAC", "AAD", "AAE"], ["JFK", "AAA", "AAB", "JFK", "AAC", "AAD", "AAE", "JFK"], ["JFK", "AAA", "JFK", "AAA", "JFK", "BBB"], ["JFK", "AAA", "JFK", "AAA", "JFK", "BBB"], ["JFK", "AAA", "JFK", "AAA", "BBB", "CCC"], ["JFK", "AAA", "BBB", "AAA", "BBB", "CCC"], ["JFK", "AAA", "BBB", "CCC", "AAA", "DDD"], ["JFK", "AAA", "BBB", "CCC", "AAA", "DDD"], ["JFK", "AAA", "BBB", "CCC", "DDD", "AAA", "EEE"], ["JFK", "AAA", "BBB", "CCC", "DDD", "EEE", "JFK"], ["JFK", "AAA", "JFK", "BBB", "JFK", "CCC", "JFK", "DDD"], ["JFK", "AAA", "JFK", "BBB", "JFK", "CCC", "JFK", "DDD"], ["JFK", "ATL", "JFK", "BOS", "JFK", "MIA", "JFK", "SEA", "SFO"], ["JFK", "ATL", "BOS", "JFK", "MIA", "SEA", "JFK", "SFO", "LAX"], ["JFK", "ATL", "BOS", "JFK", "MIA", "SEA", "JFK", "SFO", "LAX"], ["JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK", "AAA", "JFK"]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "494", "slug": "reconstruct-original-digits-from-english", "id": 494, "title": "Reconstruct Original Digits from English", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/reconstruct-original-digits-from-english/", "examples": [{"input": "s = \"owoztneoer\"", "output": "\"012\"", "explanation": "The letters form zero, one and two."}, {"input": "s = \"fviefuro\"", "output": "\"45\"", "explanation": "The bundle splits into four and five."}], "hints": ["Some letters appear in only one digit name; count those first to pin down certain digits.", "Subtract the letters of identified digits before resolving the remaining ones.", "Process distinctive letters in an order where each step reveals a new digit."], "statement": "A shuffled bundle `s` holds the letters of several English digit names (`zero` through `nine`) rangled together with their letters out of order. Every letter in `s` belongs to exactly one of those hidden names, and the bundle is guaranteed to be splittable this way.\n\nRecover the hidden digits and return them as a string with the digits arranged from smallest to largest.\n\n**Constraints:**\n- `1 <= s.length <= 10^5`\n- `s` uses only the letters appearing in English digit names.\n- `s` is guaranteed to decompose into full digit names.\n", "solution": "## Approach\n\nCount every letter, then pull out digits that own a unique letter: `z` only appears in zero, `w` in two, `u` in four, `x` in six, `g` in eight. Subtract those contributions and continue with letters that become unique afterwards (`h` for three, `f` for five, `s` for seven, then `o` for one and `i` for nine). Emit each digit its counted number of times in increasing order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`. Counting is linear and the rest is constant work.\n- **Space Complexity:** O(1) for the fixed-size frequency tables.\n\n## Implementation\n\n```python\nclass Solution:\n def originalDigits(self, s: str) -> str:\n from collections import Counter\n cnt = Counter(s)\n d = [0] * 10\n d[0] = cnt['z']\n d[2] = cnt['w']\n d[4] = cnt['u']\n d[6] = cnt['x']\n d[8] = cnt['g']\n d[3] = cnt['h'] - d[8]\n d[5] = cnt['f'] - d[4]\n d[7] = cnt['s'] - d[6]\n d[1] = cnt['o'] - d[0] - d[2] - d[4]\n d[9] = cnt['i'] - d[5] - d[6] - d[8]\n return ''.join(str(i) * d[i] for i in range(10))\n```\n", "starter": {"go": "package main\n\nfunc OriginalDigits(s string) string {\n \n}", "python": "class Solution:\n def originalDigits(self, s: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string originalDigits(string s) {\n return \"\";\n }\n};"}, "fn": "originalDigits", "params": [{"name": "s", "type": "string"}], "outputType": "string", "tests": [["owoztneoer"], ["fviefuro"], ["zerozero"], ["zeroone"], ["one"], ["two"], ["three"], ["four"], ["five"], ["six"], ["seven"], ["eight"], ["nine"], ["zeroonetwothreefourfivesixseveneightnine"], ["nieseven"], ["eerht"], ["xiss"], ["zero"], ["enin"], ["owt"], ["sixsix"], ["sevenseveneight"], ["zerozerozero"], ["oneoneone"], ["twotwo"], ["fourfour"], ["fivethree"], ["eightseven"], ["ninenine"], ["onetwothree"]], "expected": ["012", "45", "00", "01", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0123456789", "79", "3", "67", "0", "9", "2", "66", "778", "000", "111", "22", "44", "35", "78", "99", "123"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "282", "slug": "recover-binary-search-tree", "id": 282, "title": "Recover Binary Search Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/recover-binary-search-tree/", "examples": [{"input": "root = [1,3,null,null,2]", "output": "[3,1,null,null,2]", "explanation": "Swapping the values 1 and 3 restores sorted inorder order, giving [3,1,null,null,2]."}, {"input": "root = [3,1,4,null,null,2]", "output": "[2,1,4,null,null,3]", "explanation": "Swapping the values 3 and 2 restores the search-tree ordering, giving [2,1,4,null,null,3]."}], "hints": ["An inorder walk of a search tree visits values in ascending order; the two misplaced entries break that order.", "Scan the inorder sequence once to locate the first and second out-of-place nodes, then exchange their values.", "Only the node values move \u2014 the shape of the tree stays exactly the same.", "Adaptation: the original task edits the tree in place and returns nothing; here return the repaired root so the judge can compare it."], "statement": "Two entries of a binary search tree have had their values exchanged by accident. Restore the tree so it satisfies the search-tree ordering again, without altering its shape.\n\nIn a valid search tree, every node's left descendants hold smaller values and right descendants hold larger values. Equivalently, an inorder walk visits values in strictly ascending order. Exactly two nodes violate this order; find them and swap their values back.\n\nReturn the root of the repaired tree.\n\n**Constraints:**\n- `2 <= number of nodes <= 1000`\n- `-2^31 <= Node.val <= 2^31 - 1`\n- The input tree is guaranteed to become a valid search tree after swapping exactly two node values.\n\n**Adaptation note:** The classic formulation modifies the tree in place with no return value. This version returns the repaired `TreeNode` root so outputs can be serialized and checked.\n", "solution": "## Approach\n\nCollect the inorder sequence, which should be sorted in a correct search tree. Comparing it against its sorted copy exposes exactly the two swapped values (the mismatched positions). A second inorder walk exchanges those two values wherever they occur, restoring order without touching the shape.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) with sorting, or O(n) with a direct violation scan.\n- **Space Complexity:** O(n) for the collected values.\n\n## Implementation\n\n```python\nclass Solution:\n def recoverTree(self, root):\n vals = []\n def collect(n):\n if not n:\n return\n collect(n.left)\n vals.append(n.val)\n collect(n.right)\n collect(root)\n s = sorted(vals)\n x = y = None\n for v, w in zip(vals, s):\n if v != w:\n if x is None:\n x = v\n else:\n y = v\n break\n # adjacent swap still yields exactly two mismatches, so x,y suffice\n def fix(n):\n if not n:\n return\n fix(n.left)\n if n.val == x:\n n.val = y\n elif n.val == y:\n n.val = x\n fix(n.right)\n fix(root)\n return root\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc RecoverTree(root *TreeNode) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def recoverTree(self, root):\n pass\n", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* recoverTree(TreeNode* root) {\n \n }\n};"}, "fn": "recoverTree", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "tree_node", "tests": [["[1,3,null,null,2]"], ["[3,1,4,null,null,2]"], ["[2,3,1]"], ["[3,1,2]"], ["[3,4,5,1,null,2]"], ["[2,3,5,1,null,4]"], ["[4,2,6,5,3,1,7]"], ["[4,2,3,1,6,5,7]"], ["[5,-3,9,-10,null,0]"], ["[0,-3,5,-10,null,9]"], ["[3,5,2,1,null,4]"], ["[30,10,40,20]"], ["[20,30,40,10]"], ["[5,3,9,1,7,4,10]"], ["[5,9,3,1,4,7,10]"], ["[0]"], ["[1,2]"], ["[1,2,3]"], ["[7,3,9,2,5,8,10,1,null,4,null,6]"], ["[6,3,1,2,5,8,10,9,null,4,null,7]"], ["[0,-3,3,-4,-1,2,5,-5,null,1,null,-2,null,4]"], ["[0,2,3,-4,-1,-3,5,-5,null,-2,null,1,null,4]"], ["[300,400,500,100,null,200]"], ["[300,200,400,100,null,500]"], ["[2,3,12,7,5,10]"], ["[7,10,12,2,5,3]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "847", "slug": "rectangle-area-ii", "id": 847, "title": "Rectangle Area II", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/rectangle-area-ii/", "examples": [{"input": "rectangles = [[0,0,2,2],[1,0,2,3],[1,0,3,1]]", "output": "6", "explanation": "Union covers six squares."}, {"input": "rectangles = [[0,0,1000000000,1000000000]]", "output": "49", "explanation": "10^18 mod 1e9+7 is 49."}, {"input": "rectangles = [[0,0,1,1],[0,0,1,1]]", "output": "1", "explanation": "Full overlap counts once."}], "hints": ["Compress coordinates: collect every distinct x and y border, sort them, and work on the small grid of cells between neighbours.", "A compressed cell is covered when some rectangle fully contains it; add (dx * dy) modulo 1e9+7.", "With at most 200 rectangles the compressed grid is at most 400x400."], "statement": "Measure the ground covered by a set of rectangles.\n\nEach entry of `rectangles` is `[x1, y1, x2, y2]` with `x1 < x2` and `y1 < y2`, describing an axis-aligned rectangle including its interior. Rectangles may overlap. Return the total area covered by at least one rectangle, modulo 1,000,000,007.\n\n**Constraints:**\n- `1 <= rectangles.length <= 200`\n- Each rectangle holds four integers with `0 <= x1 < x2 <= 10^9` and `0 <= y1 < y2 <= 10^9`.\n", "solution": "## Approach\n\nGather every rectangle border into sorted unique x and y lists. These borders split the plane into small cells where coverage is uniform: a cell counts exactly when some input rectangle spans it fully. Summing cell areas modulo 1e9+7 yields the union size.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^3), where n <= 200, for cells times rectangle checks (at most 400x400 cells).\n- **Space Complexity:** O(n) for the compressed coordinate lists.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def rectangleArea(self, rectangles: List[List[int]]) -> int:\n MOD = 10**9 + 7\n xs = sorted({x for r in rectangles for x in (r[0], r[2])})\n ys = sorted({y for r in rectangles for y in (r[1], r[3])})\n ans = 0\n for i in range(len(xs) - 1):\n for j in range(len(ys) - 1):\n x1, x2, y1, y2 = xs[i], xs[i+1], ys[j], ys[j+1]\n for r in rectangles:\n if r[0] <= x1 and x2 <= r[2] and r[1] <= y1 and y2 <= r[3]:\n ans = (ans + (x2 - x1) * (y2 - y1)) % MOD\n break\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RectangleArea(rectangles [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def rectangleArea(self, rectangles: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int rectangleArea(vector<vector<int>>& rectangles) {\n return 0;\n }\n};"}, "fn": "rectangleArea", "params": [{"name": "rectangles", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0,0,2,2],[1,0,2,3],[1,0,3,1]]"], ["[[0,0,1000000000,1000000000]]"], ["[[0,0,1,1],[0,0,1,1]]"], ["[[0,0,1,1],[2,2,3,3]]"], ["[[0,0,3,3],[1,1,2,2]]"], ["[[0,0,2,2],[2,2,4,4]]"], ["[[0,0,4,1],[1,0,2,4]]"], ["[[0,0,5,5],[1,1,4,4],[2,2,3,3]]"], ["[[0,0,1,2],[1,0,2,2],[0,1,2,2]]"], ["[[0,0,10,10]]"], ["[[0,0,2,1],[1,0,3,1],[0,0,3,1]]"], ["[[3,0,5,2],[0,1,2,3]]"], ["[[0,0,1,1],[1,1,2,2],[2,2,3,3]]"], ["[[0,0,100,100],[50,50,150,150]]"], ["[[0,0,2,2],[1,1,3,3],[2,2,4,4]]"], ["[[0,1,1,2],[1,0,2,1],[1,1,2,2]]"], ["[[0,0,3,1],[0,1,3,2],[0,2,3,3]]"], ["[[1,1,3,3],[3,1,5,3],[1,3,3,5],[3,3,5,5]]"], ["[[0,0,1000000,1],[0,0,1,1000000]]"], ["[[0,0,2,2],[0,0,2,2],[0,0,2,2]]"], ["[[5,5,10,10],[0,0,6,6]]"], ["[[0,0,4,4],[2,0,6,4],[0,2,4,6],[2,2,6,6]]"], ["[[0,0,1,10],[0,0,10,1]]"], ["[[2,2,5,5],[3,3,6,6]]"], ["[[0,0,7,7],[1,1,2,2]]"], ["[[0,0,3,3],[0,0,3,3],[1,1,2,2]]"], ["[[10,10,20,20],[15,15,25,25],[0,0,5,5]]"], ["[[0,0,9,9],[1,1,8,8],[2,2,7,7],[3,3,6,6]]"]], "expected": [6, 49, 1, 2, 9, 8, 7, 25, 4, 100, 3, 8, 3, 17500, 10, 3, 9, 16, 1999999, 4, 60, 36, 19, 14, 49, 9, 200, 81], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "338", "slug": "rectangle-area", "id": 338, "title": "Rectangle Area", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/rectangle-area/", "examples": [{"explanation": "Areas 24 and 27 with an overlap of 6 give 24 + 27 - 6 = 45.", "input": "ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2", "output": "45"}, {"explanation": "Both rectangles are identical, so the union is just 16.", "input": "ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2", "output": "16"}, {"explanation": "The rectangles do not touch, so the answer is 1 + 1 = 2.", "input": "ax1 = 0, ay1 = 0, ax2 = 1, ay2 = 1, bx1 = 2, by1 = 2, bx2 = 3, by2 = 3", "output": "2"}], "hints": ["Area is additive except for the overlap: total = areaA + areaB - overlap.", "The overlap is itself a rectangle spanned by max of the lefts/bottoms and min of the rights/tops.", "Clamp negative overlap width or height to 0 for disjoint or merely touching rectangles."], "statement": "Two rectangles sit on a grid with sides parallel to the axes. The first has corners `(ax1, ay1)` (bottom-left) and `(ax2, ay2)` (top-right); the second has corners `(bx1, by1)` and `(bx2, by2)`.\n\nReturn the total area covered by at least one of the rectangles, counting any overlap only once.\n\n**Constraints:**\n- `-10^4 <= ax1 < ax2 <= 10^4`\n- `-10^4 <= ay1 < ay2 <= 10^4`\n- `-10^4 <= bx1 < bx2 <= 10^4`\n- `-10^4 <= by1 < by2 <= 10^4`\n", "solution": "## Approach\n\nAdd the two individual areas and subtract the overlap once. The overlap is the rectangle between the rightmost left edge and the leftmost right edge (likewise bottom/top); if either dimension is non-positive the rectangles are disjoint and the overlap is zero.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:\n area_a = (ax2 - ax1) * (ay2 - ay1)\n area_b = (bx2 - bx1) * (by2 - by1)\n overlap_w = min(ax2, bx2) - max(ax1, bx1)\n overlap_h = min(ay2, by2) - max(ay1, by1)\n overlap = overlap_w * overlap_h if overlap_w > 0 and overlap_h > 0 else 0\n return area_a + area_b - overlap\n```\n", "starter": {"go": "package main\n\nfunc ComputeArea(ax1 int, ay1 int, ax2 int, ay2 int, bx1 int, by1 int, bx2 int, by2 int) int {\n return 0\n}", "python": "class Solution:\n def computeArea(self, ax1: int, ay1: int, ax2: int, ay2: int, bx1: int, by1: int, bx2: int, by2: int) -> int:\n return 0\n", "cpp": "class Solution {\npublic:\n int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {\n return 0;\n }\n};"}, "fn": "computeArea", "params": [{"name": "ax1", "type": "int"}, {"name": "ay1", "type": "int"}, {"name": "ax2", "type": "int"}, {"name": "ay2", "type": "int"}, {"name": "bx1", "type": "int"}, {"name": "by1", "type": "int"}, {"name": "bx2", "type": "int"}, {"name": "by2", "type": "int"}], "outputType": "int", "tests": [["-3", "0", "3", "4", "0", "-1", "9", "2"], ["-2", "-2", "2", "2", "-2", "-2", "2", "2"], ["0", "0", "1", "1", "2", "2", "3", "3"], ["0", "0", "2", "2", "1", "1", "3", "3"], ["0", "0", "1", "1", "1", "0", "2", "1"], ["0", "0", "5", "5", "1", "1", "2", "2"], ["-10000", "-10000", "10000", "10000", "-10000", "-10000", "10000", "10000"], ["-5", "-5", "5", "5", "-10", "-10", "10", "10"], ["0", "0", "10", "1", "0", "0", "1", "10"], ["-4", "-3", "-1", "2", "-2", "-1", "3", "4"], ["1", "1", "4", "5", "2", "3", "6", "7"], ["0", "0", "3", "3", "3", "3", "6", "6"], ["-7", "-2", "-3", "6", "-5", "0", "0", "4"], ["2", "2", "5", "5", "3", "0", "4", "10"], ["-1", "-1", "1", "1", "0", "0", "2", "2"], ["0", "0", "10000", "10000", "5000", "5000", "10000", "10000"], ["-10", "0", "0", "10", "-5", "5", "5", "15"], ["1", "2", "3", "4", "5", "6", "7", "8"], ["-3", "-3", "3", "-1", "-3", "1", "3", "3"], ["0", "0", "4", "4", "2", "2", "6", "3"], ["-2", "0", "2", "5", "-1", "3", "1", "8"], ["5", "5", "10", "10", "0", "0", "6", "6"], ["-8", "-8", "-4", "-4", "-6", "-6", "-2", "-2"], ["0", "0", "1", "10", "0", "5", "1", "15"], ["3", "0", "5", "2", "0", "1", "4", "3"], ["-10000", "0", "0", "10000", "0", "-10000", "10000", "0"]], "expected": [45, 16, 2, 7, 2, 25, 400000000, 400, 19, 37, 24, 18, 44, 16, 7, 100000000, 175, 8, 24, 18, 26, 60, 28, 15, 11, 200000000], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "834", "slug": "rectangle-overlap", "id": 834, "title": "Rectangle Overlap", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/rectangle-overlap/", "examples": [{"input": "rec1 = [0,0,2,2], rec2 = [1,1,3,3]", "output": "true", "explanation": "The shared square [1,2]x[1,2] has area 1."}, {"input": "rec1 = [0,0,1,1], rec2 = [1,0,2,1]", "output": "false", "explanation": "Edge contact is not an overlap."}, {"input": "rec1 = [0,0,1,1], rec2 = [2,2,3,3]", "output": "false"}], "hints": ["Project both rectangles onto the x-axis and the y-axis; a real overlap needs a positive-length intersection on both axes.", "Strict inequalities matter: use < rather than <= so edge and corner touches return false.", "No geometry beyond four comparisons is required."], "statement": "Each rectangle is given as `[x1, y1, x2, y2]`, where `(x1, y1)` is the bottom-left corner and `(x2, y2)` is the top-right corner, with `x1 < x2` and `y1 < y2`. Two rectangles overlap when their intersection has positive area \u2014 touching only at an edge or a corner does not count. Return `true` when `rec1` and `rec2` overlap and `false` otherwise.\n\n**Constraints:**\n- `rec1.length == rec2.length == 4`\n- `-10^9 <= rec1[i], rec2[i] <= 10^9`\n- `rec1[0] < rec1[2]`, `rec1[1] < rec1[3]`, `rec2[0] < rec2[2]`, `rec2[1] < rec2[3]`\n", "solution": "## Approach\n\nTwo rectangles share area exactly when their x-intervals overlap with positive length and their y-intervals do too. That is four strict inequalities: each rectangle's left edge must sit left of the other's right edge on both axes. Edge or corner contact fails a strict check, which is precisely the required behaviour.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3]\n```\n", "starter": {"go": "package main\n\nfunc IsRectangleOverlap(rec1 []int, rec2 []int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def isRectangleOverlap(self, rec1: List[int], rec2: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {\n return false;\n }\n};"}, "fn": "isRectangleOverlap", "params": [{"name": "rec1", "type": "int_array"}, {"name": "rec2", "type": "int_array"}], "outputType": "boolean", "tests": [["[0, 0, 2, 2]", "[1, 1, 3, 3]"], ["[0, 0, 1, 1]", "[1, 0, 2, 1]"], ["[0, 0, 1, 1]", "[2, 2, 3, 3]"], ["[0, 0, 1, 1]", "[1, 1, 2, 2]"], ["[0, 0, 2, 2]", "[2, 2, 3, 3]"], ["[0, 0, 3, 3]", "[1, 1, 2, 2]"], ["[1, 1, 2, 2]", "[0, 0, 3, 3]"], ["[0, 0, 1, 2]", "[0, 1, 1, 3]"], ["[0, 0, 1, 1]", "[0, 1, 1, 2]"], ["[-2, -2, 2, 2]", "[-1, -1, 1, 1]"], ["[-3, 0, 3, 1]", "[0, -1, 1, 2]"], ["[0, 0, 1, 1]", "[-1, -1, 0, 0]"], ["[4, 4, 14, 7]", "[4, 3, 8, 8]"], ["[4, 4, 14, 7]", "[14, 4, 20, 7]"], ["[-1000000000, -1000000000, 1000000000, 1000000000]", "[0, 0, 1, 1]"], ["[0, 0, 1000000000, 1]", "[0, 0, 1000000000, 1]"], ["[0, 0, 5, 5]", "[5, 5, 10, 10]"], ["[0, 0, 5, 5]", "[4, 4, 10, 10]"], ["[2, 2, 5, 5]", "[0, 0, 3, 3]"], ["[0, 2, 2, 5]", "[1, 0, 3, 3]"], ["[0, 2, 2, 5]", "[1, 5, 3, 8]"], ["[-5, -5, -1, -1]", "[-3, -3, 2, 2]"], ["[-5, -5, -1, -1]", "[-1, -1, 2, 2]"], ["[7, 8, 13, 15]", "[10, 11, 12, 13]"], ["[7, 8, 13, 15]", "[13, 15, 20, 21]"], ["[0, 0, 10, 10]", "[2, 2, 8, 8]"], ["[0, 0, 2, 10]", "[1, 1, 3, 2]"], ["[5, 5, 8, 8]", "[3, 3, 9, 6]"]], "expected": [true, false, false, false, false, true, true, true, false, true, true, false, true, false, true, true, false, true, true, true, false, true, false, true, false, true, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "700", "slug": "redundant-connection-ii", "id": 700, "title": "Redundant Connection II", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/redundant-connection-ii/", "examples": [{"input": "edges = [[1,2],[1,3],[2,3]]", "output": "[2,3]", "explanation": "Removing [2,3] leaves every node with one parent and no cycle."}, {"input": "edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]", "output": "[4,1]", "explanation": "Removing [4,1] breaks the directed cycle while keeping the tree rooted."}, {"input": "edges = [[2,1],[3,1],[4,2],[1,4]]", "output": "[2,1]", "explanation": "Node 1 has two parents; dropping the earlier of the conflicting edges fixes both issues."}], "hints": ["A valid rooted tree gives every node exactly one parent; find a node with two parents if it exists.", "Try removing each of the two conflicting edges and check whether the rest is acyclic with union-find.", "With no double parent, the answer is the edge that closes a cycle, i.e. the last edge joining already-connected nodes."], "statement": "You are given directed edges that start from a rooted tree (each node except the root has exactly one parent, the root has none) plus one extra directed edge.\n\nReturn the extra edge whose removal restores a rooted tree. When several candidates work, return the one appearing last in the input.\n\n**Constraints:**\n- The graph has `n` nodes labeled `1..n` and `n` edges.\n- Edge endpoints lie in `[1, n]`.\n", "solution": "## Approach\n\nLook for a node with two incoming edges. If none exists, the extra edge is the one that closes an undirected cycle, found with union-find. If a conflict exists, test the two candidate edges by skipping each and checking for a cycle; prefer the later edge when it also resolves the cycle.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n alpha(n)) with path compression.\n- **Space Complexity:** O(n).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findRedundantDirectedConnection(self, edges: List[List[int]]) -> List[int]:\n n = len(edges)\n parent = {}\n candA = candB = -1\n for i, (u, v) in enumerate(edges):\n if v not in parent:\n parent[v] = i\n else:\n candA, candB = parent[v], i\n break\n def find(ds, x):\n while ds[x] != x:\n ds[x] = ds[ds[x]]\n x = ds[x]\n return x\n def has_cycle(skip):\n ds = list(range(n + 1))\n for i, (u, v) in enumerate(edges):\n if i == skip:\n continue\n pu, pv = find(ds, u), find(ds, v)\n if pu == pv:\n return True\n ds[pu] = pv\n return False\n if candA == -1:\n ds = list(range(n + 1))\n for u, v in edges:\n pu, pv = find(ds, u), find(ds, v)\n if pu == pv:\n return [u, v]\n ds[pu] = pv\n else:\n if not has_cycle(candB):\n return edges[candB]\n return edges[candA]\n return []\n```\n", "starter": {"go": "package main\n\nfunc FindRedundantDirectedConnection(edges [][]int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def findRedundantDirectedConnection(self, edges: List[List[int]]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findRedundantDirectedConnection(vector<vector<int>>& edges) {\n return {};\n }\n};"}, "fn": "findRedundantDirectedConnection", "params": [{"name": "edges", "type": "int_array_2d", "visualizeType": "undirected_edges"}], "outputType": "int_array", "tests": [["[[1,2],[1,3],[2,3]]"], ["[[1,2],[2,3],[3,4],[4,1],[1,5]]"], ["[[2,1],[3,1],[4,2],[1,4]]"], ["[[1,2],[2,3],[1,3]]"], ["[[1,2],[1,3],[3,1]]"], ["[[3,1],[2,1],[4,2],[1,4]]"], ["[[1,2],[3,1],[2,3]]"], ["[[1,2],[2,3],[3,1]]"], ["[[1,2],[2,1]]"], ["[[1,2],[3,2],[2,3]]"], ["[[4,1],[1,2],[2,3],[3,4]]"], ["[[1,2],[2,3],[3,4],[1,4]]"], ["[[1,3],[2,1],[3,2]]"], ["[[5,1],[4,1],[3,4],[2,3],[1,2]]"], ["[[1,2],[2,3],[3,4],[5,1],[1,5]]"], ["[[2,3],[3,4],[4,1],[1,2]]"], ["[[1,2],[2,4],[4,3],[3,1]]"], ["[[3,4],[4,1],[1,2],[2,3]]"], ["[[1,5],[2,1],[3,2],[4,3],[5,4]]"], ["[[1,2],[3,4],[2,3],[4,1]]"], ["[[2,1],[1,3],[3,2]]"], ["[[4,2],[1,5],[5,2],[5,3],[2,4]]"], ["[[1,2],[2,3],[4,1],[1,4]]"], ["[[3,1],[1,2],[2,3]]"], ["[[1,4],[2,1],[3,2],[4,3]]"], ["[[5,2],[5,1],[3,1],[3,4],[4,5]]"], ["[[1,2],[2,3],[3,5],[5,1],[1,4]]"], ["[[2,1],[3,2],[1,3]]"]], "expected": [[2, 3], [4, 1], [2, 1], [1, 3], [3, 1], [2, 1], [2, 3], [3, 1], [2, 1], [3, 2], [3, 4], [1, 4], [3, 2], [4, 1], [1, 5], [1, 2], [3, 1], [2, 3], [5, 4], [4, 1], [3, 2], [4, 2], [1, 4], [2, 3], [4, 3], [3, 1], [5, 1], [1, 3]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "120", "slug": "redundant-connection", "id": 120, "title": "Redundant Connection", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/redundant-connection/", "examples": [{"input": "edges = [[1,2],[1,3],[2,3]]", "output": "[2,3]", "explanation": "After adding [1,2], [1,3], the edge [2,3] connects two nodes already connected by the path 2-1-3."}, {"input": "edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]", "output": "[1,4]", "explanation": "After adding [1,2], [2,3], [3,4], the edge [1,4] connects two nodes already connected by the path 1-2-3-4."}], "hints": ["Process edges in input order while maintaining connected components with Union-Find.", "An edge is redundant exactly when its endpoints already have the same representative.", "Union by size or rank together with path compression makes each operation nearly constant time."], "statement": "Start from a tree whose vertices carry the labels `1` through `n`. A single\nextra link is then inserted joining two distinct vertices that were not\nalready joined directly.\n\nFrom the resulting edge listing, pick out one edge whose deletion turns the\ngraph back into a tree. When the cycle offers several deletable candidates,\nhand back the candidate listed last in the input.\n\n**Constraints:**\n\n- `3 <= edges.length <= 1000`\n- `edges[i].length == 2`\n- `1 <= edges[i][0] < edges[i][1] <= edges.length`\n- The graph is connected and consists of a tree plus one additional edge.\n- There are no duplicate undirected edges or self-loops.\n", "solution": "## Approach\n\nProcess the edges in input order with a disjoint-set union structure. If an edge's endpoints already have the same representative, that edge closes the cycle and is the last cycle edge encountered in the input, so it is the required answer. Path compression and union by size keep component operations efficient.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(E alpha(V)), where `alpha` is the inverse Ackermann function.\n- **Space Complexity:** O(V) for the disjoint-set arrays.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:\n parent = list(range(len(edges) + 1))\n size = [1] * (len(edges) + 1)\n\n def find(node: int) -> int:\n while node != parent[node]:\n parent[node] = parent[parent[node]]\n node = parent[node]\n return node\n\n for first, second in edges:\n root_a = find(first)\n root_b = find(second)\n if root_a == root_b:\n return [first, second]\n if size[root_a] < size[root_b]:\n root_a, root_b = root_b, root_a\n parent[root_b] = root_a\n size[root_a] += size[root_b]\n\n return []\n```\n", "starter": {"go": "package main\n\nfunc FindRedundantConnection(edges [][]int) []int {\n return nil\n}\n", "python": "from typing import List\n\nclass Solution:\n def findRedundantConnection(self, edges: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> findRedundantConnection(vector<vector<int>>& edges) {\n return {};\n }\n};"}, "fn": "findRedundantConnection", "params": [{"name": "edges", "type": "int_array_2d", "visualizeType": "undirected_edges"}], "outputType": "int_array", "tests": [["[[1,2],[1,3],[2,3]]"], ["[[1,2],[2,3],[1,3]]"], ["[[2,3],[1,2],[1,3]]"], ["[[1,3],[2,3],[1,2]]"], ["[[1,3],[1,2],[2,3]]"], ["[[1,2],[2,3],[3,4],[1,4]]"], ["[[1,4],[1,2],[2,3],[3,4]]"], ["[[1,2],[1,3],[1,4],[2,3]]"], ["[[2,3],[1,2],[3,4],[1,4]]"], ["[[1,2],[3,4],[2,3],[1,4]]"], ["[[1,2],[2,4],[3,4],[1,3]]"], ["[[1,4],[2,4],[2,3],[1,3]]"], ["[[1,3],[2,3],[2,4],[1,4]]"], ["[[1,2],[1,3],[3,4],[2,4]]"], ["[[1,2],[1,3],[1,4],[2,4]]"], ["[[1,2],[2,3],[3,4],[4,5],[1,5]]"], ["[[1,5],[1,2],[2,3],[3,4],[4,5]]"], ["[[1,2],[1,3],[1,4],[1,5],[2,5]]"], ["[[1,2],[2,3],[2,4],[4,5],[1,5]]"], ["[[2,4],[1,2],[4,5],[2,3],[3,5]]"], ["[[1,3],[3,5],[2,5],[2,4],[1,4]]"], ["[[1,2],[3,4],[2,3],[4,5],[1,5]]"], ["[[1,5],[4,5],[3,4],[2,3],[1,2]]"], ["[[1,4],[2,4],[2,5],[3,5],[1,3]]"], ["[[2,5],[1,2],[3,5],[3,4],[1,4]]"], ["[[1,2],[2,3],[3,4],[4,5],[5,6],[1,6]]"], ["[[1,6],[1,2],[2,3],[3,4],[4,5],[5,6]]"], ["[[1,2],[1,3],[1,4],[1,5],[1,6],[2,6]]"], ["[[1,2],[2,3],[2,4],[4,5],[4,6],[3,6]]"], ["[[3,6],[2,3],[1,2],[4,5],[5,6],[1,4]]"], ["[[1,3],[3,5],[2,5],[2,4],[4,6],[1,6]]"], ["[[1,2],[3,4],[5,6],[2,3],[4,5],[1,6]]"], ["[[1,6],[5,6],[4,5],[3,4],[2,3],[1,2]]"], ["[[1,4],[2,4],[2,6],[3,6],[3,5],[1,5]]"], ["[[2,5],[1,2],[3,5],[3,6],[4,6],[1,4]]"], ["[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[1,7]]"], ["[[1,7],[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]"], ["[[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[3,7]]"], ["[[1,2],[2,3],[2,4],[4,5],[4,6],[6,7],[3,7]]"], ["[[3,7],[2,3],[1,2],[4,5],[5,6],[6,7],[1,4]]"], ["[[1,3],[3,5],[5,7],[2,7],[2,4],[4,6],[1,6]]"], ["[[1,2],[3,4],[5,6],[2,3],[4,5],[6,7],[1,7]]"], ["[[1,7],[6,7],[5,6],[4,5],[3,4],[2,3],[1,2]]"], ["[[1,4],[2,4],[2,6],[3,6],[3,7],[5,7],[1,5]]"], ["[[2,5],[1,2],[3,5],[3,7],[4,7],[4,6],[1,6]]"], ["[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[1,8]]"], ["[[1,8],[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8]]"], ["[[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[4,8]]"], ["[[1,2],[2,3],[2,4],[4,5],[4,6],[6,7],[6,8],[3,8]]"], ["[[1,2],[3,4],[5,6],[7,8],[2,3],[4,5],[6,7],[1,8]]"], ["[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[1,10]]"], ["[[1,5],[2,5],[2,7],[3,7],[3,9],[4,9],[4,10],[6,10],[6,8],[1,8]]"], ["[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,8],[8,9],[9,10],[10,11],[11,12],[12,13],[13,14],[14,15],[15,16],[16,17],[17,18],[18,19],[19,20],[20,21],[21,22],[22,23],[23,24],[24,25],[25,26],[26,27],[27,28],[28,29],[29,30],[30,31],[31,32],[32,33],[33,34],[34,35],[35,36],[36,37],[37,38],[38,39],[39,40],[40,41],[41,42],[42,43],[43,44],[44,45],[45,46],[46,47],[47,48],[48,49],[49,50],[50,51],[51,52],[52,53],[53,54],[54,55],[55,56],[56,57],[57,58],[58,59],[59,60],[60,61],[61,62],[62,63],[63,64],[64,65],[65,66],[66,67],[67,68],[68,69],[69,70],[70,71],[71,72],[72,73],[73,74],[74,75],[75,76],[76,77],[77,78],[78,79],[79,80],[80,81],[81,82],[82,83],[83,84],[84,85],[85,86],[86,87],[87,88],[88,89],[89,90],[90,91],[91,92],[92,93],[93,94],[94,95],[95,96],[96,97],[97,98],[98,99],[99,100],[100,101],[101,102],[102,103],[103,104],[104,105],[105,106],[106,107],[107,108],[108,109],[109,110],[110,111],[111,112],[112,113],[113,114],[114,115],[115,116],[116,117],[117,118],[118,119],[119,120],[120,121],[121,122],[122,123],[123,124],[124,125],[125,126],[126,127],[127,128],[128,129],[129,130],[130,131],[131,132],[132,133],[133,134],[134,135],[135,136],[136,137],[137,138],[138,139],[139,140],[140,141],[141,142],[142,143],[143,144],[144,145],[145,146],[146,147],[147,148],[148,149],[149,150],[150,151],[151,152],[152,153],[153,154],[154,155],[155,156],[156,157],[157,158],[158,159],[159,160],[160,161],[161,162],[162,163],[163,164],[164,165],[165,166],[166,167],[167,168],[168,169],[169,170],[170,171],[171,172],[172,173],[173,174],[174,175],[175,176],[176,177],[177,178],[178,179],[179,180],[180,181],[181,182],[182,183],[183,184],[184,185],[185,186],[186,187],[187,188],[188,189],[189,190],[190,191],[191,192],[192,193],[193,194],[194,195],[195,196],[196,197],[197,198],[198,199],[199,200],[200,201],[201,202],[202,203],[203,204],[204,205],[205,206],[206,207],[207,208],[208,209],[209,210],[210,211],[211,212],[212,213],[213,214],[214,215],[215,216],[216,217],[217,218],[218,219],[219,220],[220,221],[221,222],[222,223],[223,224],[224,225],[225,226],[226,227],[227,228],[228,229],[229,230],[230,231],[231,232],[232,233],[233,234],[234,235],[235,236],[236,237],[237,238],[238,239],[239,240],[240,241],[241,242],[242,243],[243,244],[244,245],[245,246],[246,247],[247,248],[248,249],[249,250],[250,251],[251,252],[252,253],[253,254],[254,255],[255,256],[256,257],[257,258],[258,259],[259,260],[260,261],[261,262],[262,263],[263,264],[264,265],[265,266],[266,267],[267,268],[268,269],[269,270],[270,271],[271,272],[272,273],[273,274],[274,275],[275,276],[276,277],[277,278],[278,279],[279,280],[280,281],[281,282],[282,283],[283,284],[284,285],[285,286],[286,287],[287,288],[288,289],[289,290],[290,291],[291,292],[292,293],[293,294],[294,295],[295,296],[296,297],[297,298],[298,299],[299,300],[300,301],[301,302],[302,303],[303,304],[304,305],[305,306],[306,307],[307,308],[308,309],[309,310],[310,311],[311,312],[312,313],[313,314],[314,315],[315,316],[316,317],[317,318],[318,319],[319,320],[320,321],[321,322],[322,323],[323,324],[324,325],[325,326],[326,327],[327,328],[328,329],[329,330],[330,331],[331,332],[332,333],[333,334],[334,335],[335,336],[336,337],[337,338],[338,339],[339,340],[340,341],[341,342],[342,343],[343,344],[344,345],[345,346],[346,347],[347,348],[348,349],[349,350],[350,351],[351,352],[352,353],[353,354],[354,355],[355,356],[356,357],[357,358],[358,359],[359,360],[360,361],[361,362],[362,363],[363,364],[364,365],[365,366],[366,367],[367,368],[368,369],[369,370],[370,371],[371,372],[372,373],[373,374],[374,375],[375,376],[376,377],[377,378],[378,379],[379,380],[380,381],[381,382],[382,383],[383,384],[384,385],[385,386],[386,387],[387,388],[388,389],[389,390],[390,391],[391,392],[392,393],[393,394],[394,395],[395,396],[396,397],[397,398],[398,399],[399,400],[400,401],[401,402],[402,403],[403,404],[404,405],[405,406],[406,407],[407,408],[408,409],[409,410],[410,411],[411,412],[412,413],[413,414],[414,415],[415,416],[416,417],[417,418],[418,419],[419,420],[420,421],[421,422],[422,423],[423,424],[424,425],[425,426],[426,427],[427,428],[428,429],[429,430],[430,431],[431,432],[432,433],[433,434],[434,435],[435,436],[436,437],[437,438],[438,439],[439,440],[440,441],[441,442],[442,443],[443,444],[444,445],[445,446],[446,447],[447,448],[448,449],[449,450],[450,451],[451,452],[452,453],[453,454],[454,455],[455,456],[456,457],[457,458],[458,459],[459,460],[460,461],[461,462],[462,463],[463,464],[464,465],[465,466],[466,467],[467,468],[468,469],[469,470],[470,471],[471,472],[472,473],[473,474],[474,475],[475,476],[476,477],[477,478],[478,479],[479,480],[480,481],[481,482],[482,483],[483,484],[484,485],[485,486],[486,487],[487,488],[488,489],[489,490],[490,491],[491,492],[492,493],[493,494],[494,495],[495,496],[496,497],[497,498],[498,499],[499,500],[500,501],[501,502],[502,503],[503,504],[504,505],[505,506],[506,507],[507,508],[508,509],[509,510],[510,511],[511,512],[512,513],[513,514],[514,515],[515,516],[516,517],[517,518],[518,519],[519,520],[520,521],[521,522],[522,523],[523,524],[524,525],[525,526],[526,527],[527,528],[528,529],[529,530],[530,531],[531,532],[532,533],[533,534],[534,535],[535,536],[536,537],[537,538],[538,539],[539,540],[540,541],[541,542],[542,543],[543,544],[544,545],[545,546],[546,547],[547,548],[548,549],[549,550],[550,551],[551,552],[552,553],[553,554],[554,555],[555,556],[556,557],[557,558],[558,559],[559,560],[560,561],[561,562],[562,563],[563,564],[564,565],[565,566],[566,567],[567,568],[568,569],[569,570],[570,571],[571,572],[572,573],[573,574],[574,575],[575,576],[576,577],[577,578],[578,579],[579,580],[580,581],[581,582],[582,583],[583,584],[584,585],[585,586],[586,587],[587,588],[588,589],[589,590],[590,591],[591,592],[592,593],[593,594],[594,595],[595,596],[596,597],[597,598],[598,599],[599,600],[600,601],[601,602],[602,603],[603,604],[604,605],[605,606],[606,607],[607,608],[608,609],[609,610],[610,611],[611,612],[612,613],[613,614],[614,615],[615,616],[616,617],[617,618],[618,619],[619,620],[620,621],[621,622],[622,623],[623,624],[624,625],[625,626],[626,627],[627,628],[628,629],[629,630],[630,631],[631,632],[632,633],[633,634],[634,635],[635,636],[636,637],[637,638],[638,639],[639,640],[640,641],[641,642],[642,643],[643,644],[644,645],[645,646],[646,647],[647,648],[648,649],[649,650],[650,651],[651,652],[652,653],[653,654],[654,655],[655,656],[656,657],[657,658],[658,659],[659,660],[660,661],[661,662],[662,663],[663,664],[664,665],[665,666],[666,667],[667,668],[668,669],[669,670],[670,671],[671,672],[672,673],[673,674],[674,675],[675,676],[676,677],[677,678],[678,679],[679,680],[680,681],[681,682],[682,683],[683,684],[684,685],[685,686],[686,687],[687,688],[688,689],[689,690],[690,691],[691,692],[692,693],[693,694],[694,695],[695,696],[696,697],[697,698],[698,699],[699,700],[700,701],[701,702],[702,703],[703,704],[704,705],[705,706],[706,707],[707,708],[708,709],[709,710],[710,711],[711,712],[712,713],[713,714],[714,715],[715,716],[716,717],[717,718],[718,719],[719,720],[720,721],[721,722],[722,723],[723,724],[724,725],[725,726],[726,727],[727,728],[728,729],[729,730],[730,731],[731,732],[732,733],[733,734],[734,735],[735,736],[736,737],[737,738],[738,739],[739,740],[740,741],[741,742],[742,743],[743,744],[744,745],[745,746],[746,747],[747,748],[748,749],[749,750],[750,751],[751,752],[752,753],[753,754],[754,755],[755,756],[756,757],[757,758],[758,759],[759,760],[760,761],[761,762],[762,763],[763,764],[764,765],[765,766],[766,767],[767,768],[768,769],[769,770],[770,771],[771,772],[772,773],[773,774],[774,775],[775,776],[776,777],[777,778],[778,779],[779,780],[780,781],[781,782],[782,783],[783,784],[784,785],[785,786],[786,787],[787,788],[788,789],[789,790],[790,791],[791,792],[792,793],[793,794],[794,795],[795,796],[796,797],[797,798],[798,799],[799,800],[800,801],[801,802],[802,803],[803,804],[804,805],[805,806],[806,807],[807,808],[808,809],[809,810],[810,811],[811,812],[812,813],[813,814],[814,815],[815,816],[816,817],[817,818],[818,819],[819,820],[820,821],[821,822],[822,823],[823,824],[824,825],[825,826],[826,827],[827,828],[828,829],[829,830],[830,831],[831,832],[832,833],[833,834],[834,835],[835,836],[836,837],[837,838],[838,839],[839,840],[840,841],[841,842],[842,843],[843,844],[844,845],[845,846],[846,847],[847,848],[848,849],[849,850],[850,851],[851,852],[852,853],[853,854],[854,855],[855,856],[856,857],[857,858],[858,859],[859,860],[860,861],[861,862],[862,863],[863,864],[864,865],[865,866],[866,867],[867,868],[868,869],[869,870],[870,871],[871,872],[872,873],[873,874],[874,875],[875,876],[876,877],[877,878],[878,879],[879,880],[880,881],[881,882],[882,883],[883,884],[884,885],[885,886],[886,887],[887,888],[888,889],[889,890],[890,891],[891,892],[892,893],[893,894],[894,895],[895,896],[896,897],[897,898],[898,899],[899,900],[900,901],[901,902],[902,903],[903,904],[904,905],[905,906],[906,907],[907,908],[908,909],[909,910],[910,911],[911,912],[912,913],[913,914],[914,915],[915,916],[916,917],[917,918],[918,919],[919,920],[920,921],[921,922],[922,923],[923,924],[924,925],[925,926],[926,927],[927,928],[928,929],[929,930],[930,931],[931,932],[932,933],[933,934],[934,935],[935,936],[936,937],[937,938],[938,939],[939,940],[940,941],[941,942],[942,943],[943,944],[944,945],[945,946],[946,947],[947,948],[948,949],[949,950],[950,951],[951,952],[952,953],[953,954],[954,955],[955,956],[956,957],[957,958],[958,959],[959,960],[960,961],[961,962],[962,963],[963,964],[964,965],[965,966],[966,967],[967,968],[968,969],[969,970],[970,971],[971,972],[972,973],[973,974],[974,975],[975,976],[976,977],[977,978],[978,979],[979,980],[980,981],[981,982],[982,983],[983,984],[984,985],[985,986],[986,987],[987,988],[988,989],[989,990],[990,991],[991,992],[992,993],[993,994],[994,995],[995,996],[996,997],[997,998],[998,999],[999,1000],[1,1000]]"]], "expected": [[2, 3], [1, 3], [1, 3], [1, 2], [2, 3], [1, 4], [3, 4], [2, 3], [1, 4], [1, 4], [1, 3], [1, 3], [1, 4], [2, 4], [2, 4], [1, 5], [4, 5], [2, 5], [1, 5], [3, 5], [1, 4], [1, 5], [1, 2], [1, 3], [1, 4], [1, 6], [5, 6], [2, 6], [3, 6], [1, 4], [1, 6], [1, 6], [1, 2], [1, 5], [1, 4], [1, 7], [6, 7], [3, 7], [3, 7], [1, 4], [1, 6], [1, 7], [1, 2], [1, 5], [1, 6], [1, 8], [7, 8], [4, 8], [3, 8], [1, 8], [1, 10], [1, 8], [1, 1000]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "945", "slug": "regions-cut-by-slashes", "id": 945, "title": "Regions Cut by Slashes", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/regions-cut-by-slashes/", "examples": [{"input": "grid = \" /|/ \"", "output": "2", "explanation": "The two strokes join into one diagonal wall that splits the square into 2 zones."}, {"input": "grid = \" /| \"", "output": "1", "explanation": "A lone stroke touching the border fails to enclose anything, leaving 1 zone."}, {"input": "grid = \"/\\|\\/\"", "output": "5", "explanation": "The crossing strokes carve the square into 5 separate pockets."}], "hints": ["Expand every cell into a 3x3 pixel block so diagonal walls become axis-aligned barriers.", "A '/' blocks the anti-diagonal pixels and a backslash blocks the main diagonal pixels.", "Count connected components of the remaining open pixels with flood fill."], "statement": "A square board of `n x n` cells is described by `n` text rows. Each cell holds one mark: `' '` (empty), `'/'` (a wall joining the top-right and bottom-left corners), or `'\\\\'` (a wall joining the top-left and bottom-right corners). The walls split the board into connected zones; empty space touching across cell edges belongs to one zone.\n\nCount how many distinct zones the walls create.\n\nInput encoding: because blank cells are significant, the rows are passed as a single string with rows joined by `'|'` (for example `\" /|/ \"` means the two rows `\" /\"` and `\"/ \"`). The `'|'` character never appears inside a row.\n\n**Constraints:**\n- The board is `n x n` with `1 <= n <= 30`, and every row has exactly `n` characters.\n- Each character is `' '`, `'/'`, or `'\\\\'`.\n- Rows are joined with `'|'` into one string.\n", "solution": "## Approach\n\nSplit the joined string into rows on '|', then blow each cell up into a 3x3 block so that diagonal walls become blocked pixels: '/' blocks the anti-diagonal and '\\\\' blocks the main diagonal, while spaces stay open. On this pixel picture the walls are axis-aligned, so counting zones reduces to counting connected components of open pixels with a flood fill. Every original zone maps to exactly one pixel component.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) on the n x n board (a constant 9x pixels per cell).\n- **Space Complexity:** O(n^2) for the enlarged picture.\n\n## Implementation\n\n```python\nclass Solution:\n def regionsBySlashes(self, grid: str) -> int:\n rows = grid.split(\"|\")\n n = len(rows)\n m = 3 * n\n pic = [[0] * m for _ in range(m)]\n for i, row in enumerate(rows):\n for j, ch in enumerate(row):\n bi, bj = 3 * i, 3 * j\n if ch == \"/\":\n pic[bi][bj + 2] = pic[bi + 1][bj + 1] = pic[bi + 2][bj] = 1\n elif ch == \"\\\\\":\n pic[bi][bj] = pic[bi + 1][bj + 1] = pic[bi + 2][bj + 2] = 1\n regions = 0\n for i in range(m):\n for j in range(m):\n if pic[i][j] != 0:\n continue\n regions += 1\n stack = [(i, j)]\n pic[i][j] = 2\n while stack:\n x, y = stack.pop()\n for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n nx, ny = x + dx, y + dy\n if 0 <= nx < m and 0 <= ny < m and pic[nx][ny] == 0:\n pic[nx][ny] = 2\n stack.append((nx, ny))\n return regions\n```\n", "starter": {"go": "package main\n\nfunc RegionsBySlashes(grid string) int {\n return 0\n}", "python": "class Solution:\n def regionsBySlashes(self, grid: str) -> int:\n return 0", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int regionsBySlashes(string grid) {\n return 0;\n }\n};"}, "fn": "regionsBySlashes", "params": [{"name": "grid", "type": "string"}], "outputType": "int", "tests": [[" /|/ "], [" /| "], ["/\\|\\/"], ["\\/|/\\"], [" "], ["\\"], ["/"], ["//|//"], ["\\\\|\\\\"], [" | "], ["/ | /"], ["\\/ | /\\|\\/ "], [" | / | "], ["\\/|\\/"], ["//|\\\\"], [" | | "], ["/\\/|\\//|/\\/"], ["\\/|//"], ["\\ | \\"], ["/\\|/\\"], [" /|\\ "], [" /| / |/ "], ["\\\\\\|\\\\\\|\\\\\\"], ["///|///|///"], [" /\\|\\/ | /\\"], [" |/\\"], ["\\/| "], [" / |/ \\| / "]], "expected": [2, 1, 5, 4, 1, 2, 2, 4, 4, 1, 3, 3, 1, 4, 4, 1, 7, 4, 2, 4, 2, 2, 6, 6, 3, 2, 2, 2], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "137", "slug": "regular-expression-matching", "id": 137, "title": "Regular Expression Matching", "difficulty": "Hard", "category": "dp-2d", "link": "https://leetcode.com/problems/regular-expression-matching/", "examples": [{"input": "s = \"aa\", p = \"a\"", "output": "false", "explanation": "The pattern \"a\" does not match the string \"aa\"."}, {"input": "s = \"aa\", p = \"a*\"", "output": "true", "explanation": "The pattern \"a*\" means zero or more 'a' characters, so it matches \"aa\"."}, {"input": "s = \"aab\", p = \"c*a*b\"", "output": "true", "explanation": "c* matches zero characters, a* matches both a characters, and b matches the final character."}], "hints": ["Let dp[i][j] indicate whether the first i characters of s match the first j characters of p.", "A normal character or '.' extends a match from dp[i - 1][j - 1].", "For x*, either skip both pattern characters or consume one matching character while staying at the same pattern position."], "statement": "Given a string `s` and a pattern `p`, implement regular expression matching for the entire string. The pattern supports these special characters:\n\n- `.` matches any single character.\n- `*` matches zero or more occurrences of the immediately preceding element.\n\nThe match must consume all of `s`, not merely a substring.\n\n**Constraints:**\n\n- `1 <= s.length <= 20`\n- `1 <= p.length <= 20`\n- `s` contains only lowercase English letters.\n- `p` contains only lowercase English letters, `.` and `*`.\n- Every `*` has a valid preceding element; patterns never begin with `*` or contain consecutive `*` characters.\n", "solution": "## Approach\n\nUse dynamic programming where `dp[i][j]` records whether the first `i` characters of `s` match the first `j` characters of `p`. A literal or `.` extends `dp[i - 1][j - 1]`. For `x*`, either skip `x*` using `dp[i][j - 2]`, or consume one matching character and remain at the same pattern position using `dp[i - 1][j]`. Initialize the empty-string row for patterns that can reduce to empty.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), where `m` and `n` are the string and pattern lengths.\n- **Space Complexity:** O(m * n) for the dynamic programming table.\n\n## Implementation\n\n```python\nclass Solution:\n def isMatch(self, s: str, p: str) -> bool:\n m, n = len(s), len(p)\n dp = [[False] * (n + 1) for _ in range(m + 1)]\n dp[0][0] = True\n\n for j in range(2, n + 1):\n if p[j - 1] == \"*\":\n dp[0][j] = dp[0][j - 2]\n\n for i in range(1, m + 1):\n for j in range(1, n + 1):\n pattern = p[j - 1]\n if pattern == \".\" or pattern == s[i - 1]:\n dp[i][j] = dp[i - 1][j - 1]\n elif pattern == \"*\":\n dp[i][j] = dp[i][j - 2]\n repeated = p[j - 2]\n if repeated == \".\" or repeated == s[i - 1]:\n dp[i][j] = dp[i][j] or dp[i - 1][j]\n return dp[m][n]\n```\n", "starter": {"go": "package main\n\nfunc IsMatch(s string, p string) bool {\n \n}", "python": "class Solution:\n def isMatch(self, s: str, p: str) -> bool:\n pass\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isMatch(string s, string p) {\n return false;\n }\n};"}, "fn": "isMatch", "params": [{"name": "s", "type": "string"}, {"name": "p", "type": "string"}], "outputType": "boolean", "tests": [["aa", "a"], ["aa", "a*"], ["abcd", ".*"], ["aab", "c*a*b"], ["mississippi", "mis*is*p*."], ["ab", ".*c"], ["aaa", "a*a"], ["aaa", "ab*a*c*a"], ["a", "ab*"], ["bbb", "b*"], ["abcd", "d*"], ["abc", "abc"], ["abc", "a.c"], ["abc", "..."], ["abc", ".."], ["a", "."], ["ab", ".*"], ["ab", ".*b"], ["ab", "a.*"], ["ab", "a*b"], ["b", "a*b"], ["bbb", "b*b*"], ["ccc", "a*c*"], ["cab", "c.b"], ["cab", ".*ab"], ["cab", "c.*"], ["ac", "ab*c"], ["abb", "ab*"], ["abbb", "ab*"], ["acb", "a.*b"], ["axxb", "a.*b"], ["axxc", "a.*b"], ["aaa", "a*"], ["aaa", "aa*"], ["aaa", "a*a*"], ["aaaa", "a*a"], ["baab", "b.*b"], ["baac", "b.*c"], ["xy", "z*x."], ["xyz", "x.*z"], ["xyz", ".*y."], ["xyz", "x.y"], ["xyz", "x.*"], ["p", "p*q*"], ["q", "p*q"], ["qq", "p*q*"], ["abab", "a*b*a*b*"], ["aaaa", "b*a*"], ["bbba", "ab*a"], ["banana", "b.*a"], ["banana", "ba.*na"], ["banana", "b.n.n."], ["abcdef", "a.*f"], ["abcdef", ".*def"], ["abcdef", "abc.*"], ["abcdef", "ab.*ef"], ["abccccc", "ab.c*"], ["acccc", "ab*c*"], ["ddd", "cd*"], ["ddd", "c*d*"], ["abc", "a*b*c*"], ["cab", "c*a*b*"], ["aaabbb", "a*b*"], ["aaaccc", "a*b*c*"], ["abcabc", ".*abc"], ["aaaaaaaaaaaaaaaaaaaa", "a*a*a*a*a*a*a*a*a*a*"]], "expected": [false, true, true, true, false, false, true, true, true, true, false, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "568", "slug": "relative-ranks", "id": 568, "title": "Relative Ranks", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/relative-ranks/", "examples": [{"input": "score = [5,4,3,2,1]", "output": "[\"Gold Medal\",\"Silver Medal\",\"Bronze Medal\",\"4\",\"5\"]", "explanation": "The best score 5 earns gold, then 4 silver, 3 bronze, and the rest keep their numeric ranks."}, {"input": "score = [10,3,8,9,4]", "output": "[\"Gold Medal\",\"5\",\"Bronze Medal\",\"Silver Medal\",\"4\"]", "explanation": "Sorted best-first the scores are 10, 9, 8, 4, 3, giving ranks 1..5 mapped back to the input order."}, {"input": "score = [1]", "output": "[\"Gold Medal\"]", "explanation": "A single competitor wins gold."}], "hints": ["Sort competitor indices by score from high to low; the position in that order is the rank.", "Translate ranks 1, 2, 3 to the three medal names and format all other ranks as decimal strings."], "statement": "Competitors finish a race with pairwise different scores, where a larger score means a better placement. Rank the competitors from best (rank 1) to worst (rank n) and label each original position: rank 1 becomes `\"Gold Medal\"`, rank 2 becomes `\"Silver Medal\"`, rank 3 becomes `\"Bronze Medal\"`, and every later rank `k` becomes the plain number `\"k\"`.\n\nGiven the scores in starting order, return the label for each competitor in that same order.\n\n**Constraints:**\n- `1 <= score.length <= 10^4`\n- `0 <= score[i] <= 10^6`\n- All values in `score` are distinct\n", "solution": "## Approach\n\nOrder the indices by score from largest to smallest; the order position is exactly the rank. Walk that ordering once, writing `\"Gold Medal\"`, `\"Silver Medal\"`, `\"Bronze Medal\"` for the first three places and the decimal rank for everything after. Mapping back through the sorted indices restores the original input order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting the n indices.\n- **Space Complexity:** O(n) for the index array and the answer.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findRelativeRanks(self, score: List[int]) -> List[str]:\n order = sorted(range(len(score)), key=lambda i: -score[i])\n ans = [\"\"] * len(score)\n for rank, i in enumerate(order, start=1):\n if rank == 1:\n ans[i] = \"Gold Medal\"\n elif rank == 2:\n ans[i] = \"Silver Medal\"\n elif rank == 3:\n ans[i] = \"Bronze Medal\"\n else:\n ans[i] = str(rank)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FindRelativeRanks(score []int) []string {\n \n}", "python": "from typing import List\nclass Solution:\n def findRelativeRanks(self, score: List[int]) -> List[str]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> findRelativeRanks(vector<int>& score) {\n return {};\n }\n};"}, "fn": "findRelativeRanks", "params": [{"name": "score", "type": "int_array"}], "outputType": "string_list", "tests": [["[5,4,3,2,1]"], ["[10,3,8,9,4]"], ["[1]"], ["[1,2]"], ["[2,1]"], ["[3,1,2]"], ["[100,50,75,25]"], ["[0]"], ["[0,1]"], ["[1000000,0,500000]"], ["[7,6,8]"], ["[1,2,3,4,5,6,7]"], ["[7,6,5,4,3,2,1]"], ["[42,17,93,8,55]"], ["[9,8,7,1,2,3]"], ["[5,3,4,6,1,2]"], ["[100,90,80]"], ["[80,90,100]"], ["[1,3,2,5,4]"], ["[999999,1000000,0,1]"], ["[4,2]"], ["[11,22,33,44,55,66]"], ["[66,55,44,33,22,11]"], ["[5,10,15,20,25,30,1,2,3]"], ["[123456,654321,111111,222222]"], ["[1,2,3]"], ["[3,2,1]"], ["[10,20,30,40]"]], "expected": [["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"], ["Gold Medal", "5", "Bronze Medal", "Silver Medal", "4"], ["Gold Medal"], ["Silver Medal", "Gold Medal"], ["Gold Medal", "Silver Medal"], ["Gold Medal", "Bronze Medal", "Silver Medal"], ["Gold Medal", "Bronze Medal", "Silver Medal", "4"], ["Gold Medal"], ["Silver Medal", "Gold Medal"], ["Gold Medal", "Bronze Medal", "Silver Medal"], ["Silver Medal", "Bronze Medal", "Gold Medal"], ["7", "6", "5", "4", "Bronze Medal", "Silver Medal", "Gold Medal"], ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5", "6", "7"], ["Bronze Medal", "4", "Gold Medal", "5", "Silver Medal"], ["Gold Medal", "Silver Medal", "Bronze Medal", "6", "5", "4"], ["Silver Medal", "4", "Bronze Medal", "Gold Medal", "6", "5"], ["Gold Medal", "Silver Medal", "Bronze Medal"], ["Bronze Medal", "Silver Medal", "Gold Medal"], ["5", "Bronze Medal", "4", "Gold Medal", "Silver Medal"], ["Silver Medal", "Gold Medal", "4", "Bronze Medal"], ["Gold Medal", "Silver Medal"], ["6", "5", "4", "Bronze Medal", "Silver Medal", "Gold Medal"], ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5", "6"], ["6", "5", "4", "Bronze Medal", "Silver Medal", "Gold Medal", "9", "8", "7"], ["Bronze Medal", "Gold Medal", "4", "Silver Medal"], ["Bronze Medal", "Silver Medal", "Gold Medal"], ["Gold Medal", "Silver Medal", "Bronze Medal"], ["4", "Bronze Medal", "Silver Medal", "Gold Medal"]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "679", "slug": "remove-9", "id": 679, "title": "Remove 9", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/remove-9/", "examples": [{"input": "n = 9", "output": "10", "explanation": "Counting 1,2,3,4,5,6,7,8,10 shows the 9th kept number is 10."}, {"input": "n = 10", "output": "11", "explanation": "The next kept number after 10 is 11."}, {"input": "n = 1", "output": "1", "explanation": "The first kept number is 1."}], "hints": ["Write down the kept numbers: skipping anything containing digit 9 leaves exactly the base-9 counting sequence read as decimal.", "Convert n to base 9, then read those digits as an ordinary decimal number.", "Build the answer digit by digit with repeated division by 9."], "statement": "Start from the positive integers 1, 2, 3, ... and delete every number whose decimal writing contains the digit 9. The survivors begin 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...\n\nGiven `n`, return the n-th survivor (counting from 1).\n\n**Constraints:**\n- `1 <= n <= 8 * 10^8`\n", "solution": "## Approach\n\nAfter deleting 9s, the survivors line up exactly like base-9 counting read as decimal digits. So convert `n` into base 9 and interpret the resulting digits as a decimal number: repeatedly take `n % 9` as the next digit and multiply the place value by 10.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n) divisions by 9.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def newInteger(self, n: int) -> int:\n ans = 0\n base = 1\n while n > 0:\n ans += (n % 9) * base\n n //= 9\n base *= 10\n return ans\n```\n", "starter": {"go": "package main\n\nfunc NewInteger(n int) int {\n \n}", "python": "class Solution:\n def newInteger(self, n: int) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int newInteger(int n) {\n return 0;\n }\n};"}, "fn": "newInteger", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["9"], ["10"], ["1"], ["2"], ["8"], ["11"], ["18"], ["19"], ["81"], ["82"], ["100"], ["200"], ["729"], ["730"], ["1000"], ["10000"], ["100000"], ["5"], ["7"], ["17"], ["27"], ["80"], ["90"], ["162"], ["6561"], ["12345"], ["99999"], ["800000000"]], "expected": [10, 11, 1, 2, 8, 12, 20, 21, 100, 101, 121, 242, 1000, 1001, 1331, 14641, 162151, 5, 7, 18, 30, 88, 110, 200, 10000, 17836, 162150, 2052305618], "loose": false}
|