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": "890", "slug": "rle-iterator", "id": 890, "title": "RLE Iterator", "difficulty": "Medium", "category": "design", "link": "https://leetcode.com/problems/rle-iterator/", "examples": [{"input": "encoding = [3,8,0,9,2,5], operations = [\"next\",\"next\",\"next\",\"next\"], values = [2,1,1,2]", "output": "[8,8,5,-1]", "explanation": "Unfolds to [8,8,8,5,5]; consuming 2,1,1,2 gives 8,8,5,-1."}, {"input": "encoding = [1,5], operations = [\"next\",\"next\"], values = [1,1]", "output": "[5,-1]", "explanation": "One 5 then exhaustion."}, {"input": "encoding = [0,1,2,2], operations = [\"next\",\"next\"], values = [1,2]", "output": "[2,2]", "explanation": "Zero-count skipped."}], "hints": ["Keep an index into the pair list plus the remaining count of the current value; skip zero-count pairs eagerly.", "For next(n), subtract from the current remainder while n exceeds it, advancing the pair pointer until n fits or the pairs run out."], "statement": "Run-length encoding squeezes a repetition-heavy sequence into pairs: for every even index `i`, `encoding[i]` says how many copies of `encoding[i+1]` appear next. As an illustration, `[3,8,2,5]` unfolds to `[8,8,8,5,5]`, and zeros may appear when a value is skipped.\n\nAn iterator walks that unfolded stream. Each `next(n)` call consumes the following `n` entries and reports the value of the last one consumed; when the stream runs dry the call reports `-1` instead.\n\nTo keep every language on one footing, this task batches the calls into a single function `runRle(encoding, operations, values)`. The `encoding` array is the paired list above, `operations[i]` names the call (always `\"next\"` here), `values[i]` holds the `n` for that call, and the returned array holds each call's answer in order.\n\n**Constraints:**\n- `2 <= encoding.length <= 1000`\n- `encoding.length` is even.\n- `0 <= encoding[i] <= 10^9`\n- `1 <= n <= 10^9` for each `next` call.\n- At most `1000` calls are made.\n\n> **Adaptation note:** the original LeetCode shape is a class `RLEIterator` with a constructor plus `next(n)`. Here the constructor argument and the sequence of `next` arguments are supplied together to `runRle`, which returns the list of `next` results. Grading compares the integer arrays exactly.\n", "solution": "## Approach\n\nKeep a pointer to the current count/value pair plus how many copies of that value remain. Zero-count pairs are skipped without producing output. Each `next(n)` call repeatedly subtracts from the remainder: when `n` fits inside the remainder, deduct and report the current value; otherwise consume the whole remainder, remember its value, jump to the next pair, and continue. If the pairs run out before `n` reaches zero, the call reports `-1`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(p + q) where p is the number of pairs scanned and q the number of calls; each pair is visited at most once.\n- **Space Complexity:** O(1) besides the answer list.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runRle(self, encoding: List[int], operations: List[str], values: List[int]) -> List[int]:\n idx = 0\n rem = encoding[0] if len(encoding) >= 2 else 0\n while idx < len(encoding) and rem == 0:\n idx += 2\n if idx < len(encoding):\n rem = encoding[idx]\n ans = []\n for n in values:\n res = -1\n while n > 0 and idx < len(encoding):\n if rem == 0:\n idx += 2\n if idx < len(encoding):\n rem = encoding[idx]\n continue\n v = encoding[idx + 1]\n if n <= rem:\n rem -= n\n res = v\n n = 0\n if rem == 0:\n idx += 2\n if idx < len(encoding):\n rem = encoding[idx]\n else:\n n -= rem\n res = v\n idx += 2\n rem = encoding[idx] if idx < len(encoding) else 0\n if n > 0:\n res = -1\n ans.append(res)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunRle(encoding []int, operations []string, values []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runRle(self, encoding: List[int], operations: List[str], values: List[int]) -> List[int]:\n return []", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runRle(vector<int>& encoding, vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runRle", "params": [{"name": "encoding", "type": "int_array"}, {"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[3,8,0,9,2,5]", "[\"next\",\"next\",\"next\",\"next\"]", "[2,1,1,2]"], ["[1,5]", "[\"next\",\"next\"]", "[1,1]"], ["[0,1,2,2]", "[\"next\",\"next\"]", "[1,2]"], ["[3,8,2,5]", "[\"next\",\"next\",\"next\"]", "[2,1,2]"], ["[2,8,1,8,2,5]", "[\"next\",\"next\",\"next\"]", "[2,1,2]"], ["[1,1]", "[\"next\"]", "[1]"], ["[0,5,1,6]", "[\"next\"]", "[1]"], ["[5,3]", "[\"next\",\"next\"]", "[3,3]"], ["[1,2,1,3]", "[\"next\",\"next\",\"next\"]", "[1,1,1]"], ["[10,1]", "[\"next\"]", "[5]"], ["[10,1]", "[\"next\",\"next\"]", "[10,1]"], ["[2,1,2,2]", "[\"next\",\"next\",\"next\"]", "[1,1,3]"], ["[0,0,0,0]", "[\"next\"]", "[1]"], ["[1,9,2,8]", "[\"next\",\"next\",\"next\"]", "[1,2,1]"], ["[4,4]", "[\"next\",\"next\",\"next\",\"next\",\"next\"]", "[1,1,1,1,1]"], ["[2,5,3,6]", "[\"next\",\"next\"]", "[4,2]"], ["[1,7,0,9,1,8]", "[\"next\",\"next\",\"next\"]", "[1,1,1]"], ["[100,1]", "[\"next\"]", "[100]"], ["[100,1]", "[\"next\"]", "[101]"], ["[3,1,2,2,1,3]", "[\"next\",\"next\",\"next\",\"next\"]", "[1,2,2,2]"], ["[5,10]", "[\"next\"]", "[5]"], ["[5,10]", "[\"next\",\"next\"]", "[6,1]"], ["[1,2,3,4]", "[\"next\",\"next\"]", "[2,3]"], ["[2,3]", "[\"next\",\"next\",\"next\"]", "[1,1,1]"], ["[0,7,5,8]", "[\"next\",\"next\"]", "[3,3]"], ["[1,1,1,2,1,3]", "[\"next\",\"next\",\"next\",\"next\"]", "[1,1,1,1]"], ["[6,2]", "[\"next\",\"next\",\"next\"]", "[2,2,3]"], ["[4,9,4,8]", "[\"next\",\"next\",\"next\"]", "[4,4,1]"]], "expected": [[8, 8, 5, -1], [5, -1], [2, -1], [8, 8, 5], [8, 8, 5], [1], [6], [3, -1], [2, 3, -1], [1], [1, -1], [1, 1, -1], [-1], [9, 8, -1], [4, 4, 4, 4, -1], [6, -1], [7, 8, -1], [1], [-1], [1, 1, 2, -1], [10], [-1, -1], [4, -1], [3, 3, -1], [8, -1], [1, 2, 3, -1], [2, 2, -1], [9, 8, -1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "677", "slug": "robot-return-to-origin", "id": 677, "title": "Robot Return to Origin", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/robot-return-to-origin/", "examples": [{"input": "moves = \"UD\"", "output": "true", "explanation": "Up then down cancels out."}, {"input": "moves = \"LL\"", "output": "false", "explanation": "Two left steps end at (-2, 0)."}, {"input": "moves = \"URDL\"", "output": "true", "explanation": "Each direction appears once, so the robot is back home."}], "hints": ["Track horizontal and vertical offsets separately.", "U adds one to height, D subtracts one, R adds one to width, L subtracts one.", "The answer is true exactly when both offsets are zero."], "statement": "A robot starts at position (0, 0) on a grid. It follows a string `moves` made of the letters `U` (up), `D` (down), `L` (left) and `R` (right), each moving one step.\n\nReturn `true` when the robot finishes back at the origin, otherwise `false`.\n\n**Constraints:**\n- `1 <= moves.length <= 2 * 10^4`\n- `moves` contains only `U`, `D`, `L`, `R`.\n", "solution": "## Approach\n\nKeep a horizontal and a vertical counter. Each letter moves one counter up or down by one. After all steps the robot is home exactly when both counters are zero.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) over the move string.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def judgeCircle(self, moves: str) -> bool:\n x = y = 0\n for c in moves:\n if c == 'U':\n y += 1\n elif c == 'D':\n y -= 1\n elif c == 'L':\n x -= 1\n elif c == 'R':\n x += 1\n return x == 0 and y == 0\n```\n", "starter": {"go": "package main\n\nfunc JudgeCircle(moves string) bool {\n \n}", "python": "class Solution:\n def judgeCircle(self, moves: str) -> bool:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool judgeCircle(string moves) {\n return false;\n }\n};"}, "fn": "judgeCircle", "params": [{"name": "moves", "type": "string"}], "outputType": "boolean", "tests": [["UD"], ["LL"], ["URDL"], ["U"], ["D"], ["L"], ["R"], ["UDLR"], ["UUDD"], ["RRDDLLUU"], ["UUU"], ["DDD"], ["RRR"], ["LLL"], ["UDUDUD"], ["RLRLRL"], ["UUDDLLRR"], ["UUUDDD"], ["RRRUUULLLDDD"], ["UDL"], ["RDLU"], ["UUUUDDDD"], ["RLU"], ["DRUL"], ["UDD"], ["LRUDLR"], ["UUUUDDDDLRLR"], ["RRUULLDD"]], "expected": [true, false, true, false, false, false, false, true, true, true, false, false, false, false, true, true, true, true, true, false, true, true, false, true, false, true, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "553", "slug": "robot-room-cleaner", "id": 553, "title": "Robot Room Cleaner", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/robot-room-cleaner/", "examples": [{"input": "room = [[1,1,1,1,1,0,1,1],[1,1,1,1,1,0,1,1],[1,0,1,1,1,1,1,1],[0,0,0,1,0,0,0,0],[1,1,1,1,1,1,1,1]], row = 1, col = 3", "output": "33", "explanation": "Thirty-three free cells connect to the start; walls split off the rest."}, {"input": "room = [[1]], row = 0, col = 0", "output": "1", "explanation": "Only the starting cell is free and reachable."}], "hints": ["Run a flood fill (breadth-first or depth-first search) from the start through cells containing 1.", "Track visited cells so each free cell is counted once; walls (0) and out-of-bounds neighbors are skipped.", "Adaptation: you do not simulate turns or the Robot API \u2014 just return the size of the connected free region."], "statement": "A room is drawn as a grid of cells. A value of `1` marks a free cell the robot may enter, while `0` marks a wall or piece of furniture that blocks movement. The robot begins on a guaranteed free cell given by `row` and `col`, facing upward.\n\nIn the original interactive version the robot is blindfolded and may only use move, turn and clean operations. This offline adaptation hands you the whole layout at once: count how many distinct free cells are reachable from the start by moving up, down, left or right through free cells. That count equals the number of cells a perfect cleaning tour would visit.\n\nReturn that reachable free-cell count. A single isolated free cell therefore yields `1`.\n\n**Constraints:**\n- `1 <= room.length <= 20`\n- `1 <= room[i].length <= 20`\n- Each entry is `0` or `1`\n- `room[row][col] == 1`\n", "solution": "## Approach\n\nThe reachable region is exactly the connected component of free cells containing the start. A queue-based flood fill explores the four neighbors of each visited free cell, skipping walls and already seen positions, and counts every dequeued cell. The count is the number of cells a complete cleaning would cover.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n) where m and n are the room dimensions. Each cell is visited once.\n- **Space Complexity:** O(m * n) for the visited table and queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\nclass Solution:\n def cleanRoom(self, room: List[List[int]], row: int, col: int) -> int:\n m, n = len(room), len(room[0])\n vis = [[False] * n for _ in range(m)]\n dq = deque([(row, col)])\n vis[row][col] = True\n cnt = 0\n while dq:\n r, c = dq.popleft()\n cnt += 1\n for dr, dc in ((-1, 0), (1, 0), (0, -1), (0, 1)):\n nr, nc = r + dr, c + dc\n if 0 <= nr < m and 0 <= nc < n and not vis[nr][nc] and room[nr][nc] == 1:\n vis[nr][nc] = True\n dq.append((nr, nc))\n return cnt\n```\n", "starter": {"go": "package main\n\nfunc CleanRoom(room [][]int, row int, col int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def cleanRoom(self, room: List[List[int]], row: int, col: int) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int cleanRoom(vector<vector<int>>& room, int row, int col) {\n return 0;\n }\n};"}, "fn": "cleanRoom", "params": [{"name": "room", "type": "int_array_2d"}, {"name": "row", "type": "int"}, {"name": "col", "type": "int"}], "outputType": "int", "tests": [["[[1,1,1,1,1,0,1,1],[1,1,1,1,1,0,1,1],[1,0,1,1,1,1,1,1],[0,0,0,1,0,0,0,0],[1,1,1,1,1,1,1,1]]", "1", "3"], ["[[1]]", "0", "0"], ["[[1,1,1],[1,1,1],[1,1,1]]", "1", "1"], ["[[0,0,0],[0,1,0],[0,0,0]]", "1", "1"], ["[[1,0,1],[0,0,0],[1,0,1]]", "0", "0"], ["[[1,0,1],[0,0,0],[1,0,1]]", "0", "2"], ["[[1,1,0],[1,1,0],[0,0,1]]", "0", "0"], ["[[1,1,0],[1,1,0],[0,0,1]]", "2", "2"], ["[[1,1,1,1],[1,0,0,1],[1,1,1,1]]", "0", "0"], ["[[1,1,1,1],[1,0,0,1],[1,1,1,1]]", "1", "0"], ["[[1,0],[0,1]]", "0", "0"], ["[[1,0],[0,1]]", "1", "1"], ["[[1,1],[1,0]]", "0", "0"], ["[[1,1,1,1,1]]", "0", "2"], ["[[1],[1],[1],[0],[1]]", "0", "0"], ["[[1],[1],[1],[0],[1]]", "4", "0"], ["[[1,1,0,1,1],[1,1,0,1,1],[1,1,1,1,1]]", "0", "0"], ["[[0,1,0],[1,1,1],[0,1,0]]", "1", "1"], ["[[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1]]", "1", "1"], ["[[1,1],[1,1]]", "0", "1"], ["[[1,0,0],[1,1,0],[0,1,1]]", "0", "0"], ["[[1,1,1],[0,0,1],[0,0,1]]", "0", "0"], ["[[1,0,1],[1,1,1],[0,1,0]]", "1", "1"], ["[[1,1,1,0],[0,1,0,0],[1,1,1,1]]", "0", "1"], ["[[1]]", "0", "0"], ["[[1,1,0,0],[0,1,1,0],[0,0,1,1]]", "0", "0"], ["[[1,0],[1,1]]", "1", "1"], ["[[0,0,1,0,0],[0,1,1,1,0],[0,0,1,0,0]]", "1", "2"]], "expected": [30, 1, 9, 1, 1, 1, 4, 1, 10, 10, 1, 1, 3, 5, 3, 1, 13, 5, 1, 4, 5, 5, 6, 8, 1, 6, 3, 5], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "247", "slug": "roman-to-integer", "id": 247, "title": "Roman to Integer", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/roman-to-integer/", "examples": [{"input": "s = \"III\"", "output": "3", "explanation": "III = 3."}, {"input": "s = \"LVIII\"", "output": "58", "explanation": "L = 50, V = 5, III = 3."}, {"input": "s = \"MCMXCIV\"", "output": "1994", "explanation": "M = 1000, CM = 900, XC = 90 and IV = 4."}], "hints": ["Work the string from back to front so each numeral is either added or subtracted based on the symbol to its right.", "If a numeral is smaller than the one that follows it, subtract it; otherwise add it."], "statement": "Seven distinct glyphs encode Roman numerals: `I`, `V`, `X`, `L`, `C`, `D` and `M`.\n\n```\nSymbol Value\nI 1\nV 5\nX 10\nL 50\nC 100\nD 500\nM 1000\n```\n\nFor instance, `2` appears as `II` in Roman notation \u2014 two ones tallied together. `12` appears as `XII`, namely `X + II`. The value `27` appears as `XXVII`, namely `XX + V + II`.\n\nOrdinarily Roman glyphs run from the greatest value down to the least when read left to right. The value four breaks that pattern: rather than `IIII`, four is penned `IV`. Setting the one ahead of the five signals a subtraction that yields four. Nine follows the same device and is penned `IX`. Subtraction shows up in six pairings:\n\n- A leading `I` ahead of `V` (5) and `X` (10) produces 4 and 9.\n- A leading `X` ahead of `L` (50) and `C` (100) produces 40 and 90.\n- A leading `C` ahead of `D` (500) and `M` (1000) produces 400 and 900.\n\nTranslate a supplied Roman numeral into its integer value.\n\n**Constraints:**\n\n- `1 <= s.length <= 15`\n- `s` contains only the characters `('I', 'V', 'X', 'L', 'C', 'D', 'M')`.\n- It is guaranteed that `s` is a valid roman numeral in the range `[1, 3999]`.\n", "solution": "## Approach\n\nWalk the string from left to right while tracking each symbol's value. Whenever the current symbol is smaller than the symbol to its right (e.g. `I` before `V`), it contributes a negative value; otherwise it contributes positively.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where `n` is the length of `s`. Each symbol is examined once.\n- **Space Complexity:** O(1), aside from the fixed-size lookup table.\n\n## Implementation\n\n```python\nclass Solution:\n def romanToInt(self, s: str) -> int:\n values = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n total = 0\n for i, ch in enumerate(s):\n value = values[ch]\n if i + 1 < len(s) and value < values[s[i + 1]]:\n total -= value\n else:\n total += value\n return total\n```", "starter": {"go": "package main\n\nfunc RomanToInt(s string) int {\n \n}", "python": "class Solution:\n def romanToInt(self, s: str) -> int:\n ", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int romanToInt(string s) {\n \n }\n};"}, "fn": "romanToInt", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["III"], ["LVIII"], ["MCMXCIV"], ["I"], ["IV"], ["IX"], ["XL"], ["XC"], ["CD"], ["CM"], ["CDXLIV"], ["MMMCDXLIV"], ["MMMCMXCIX"], ["MMMCMXCVIII"], ["DCCLXXXIX"], ["II"], ["V"], ["VI"], ["X"], ["XIV"], ["XIX"], ["XXVII"], ["XXXIX"], ["XLIX"], ["L"], ["XCIX"], ["C"], ["CDXC"], ["D"], ["CMXCIX"], ["M"], ["MMXXVI"], ["MMMDCCCLXXXVIII"]], "expected": [3, 58, 1994, 1, 4, 9, 40, 90, 400, 900, 444, 3444, 3999, 3998, 789, 2, 5, 6, 10, 14, 19, 27, 39, 49, 50, 99, 100, 490, 500, 999, 1000, 2026, 3888], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "171", "slug": "rotate-array", "id": 171, "title": "Rotate Array", "difficulty": "Medium", "category": "two-pointer", "link": "https://leetcode.com/problems/rotate-array/", "examples": [{"input": "nums = [1,2,3,4,5,6,7], k = 3", "output": "[5,6,7,1,2,3,4]", "explanation": "Rotate 1 step: [7,1,2,3,4,5,6]. Rotate 2 steps: [6,7,1,2,3,4,5]. Rotate 3 steps: [5,6,7,1,2,3,4]."}, {"input": "nums = [-1,-100,3,99], k = 2", "output": "[3,99,-1,-100]", "explanation": "Rotate 1 step: [99,-1,-100,3]. Rotate 2 steps: [3,99,-1,-100]."}], "hints": ["Reduce k modulo n to handle k larger than the array length.", "Reverse the whole array, then reverse the first k elements and the remaining n-k elements."], "statement": "Your input is an integer array `nums` plus a non-negative integer `k`. Shift the array right by `k` places and return the shifted array.\n\n**Constraints:**\n\n- 1 \u2264 nums.length \u2264 10^5\n- -2^31 \u2264 nums[i] \u2264 2^31 - 1\n- 0 \u2264 k \u2264 10^5\n", "solution": "## Approach\n\nReduce `k` modulo `n` to handle rotations larger than the array. Then place each element at index `(i + k) % n` in a new array. An in-place alternative reverses the whole array, then reverses the first `k` elements and the remaining `n - k` elements.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of the array.\n- **Space Complexity:** O(n) for the returned array (O(1) extra if rotating in place with reversals).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def rotate(self, nums: List[int], k: int) -> List[int]:\n n = len(nums)\n if n == 0:\n return []\n k %= n\n return nums[n - k:] + nums[:n - k] if k else nums[:]\n```\n", "starter": {"go": "package main\n\nfunc Rotate(nums []int, k int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def rotate(self, nums: List[int], k: int) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> rotate(vector<int>& nums, int k) {\n return {};\n }\n};"}, "fn": "rotate", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int_array", "tests": [["[1,2,3,4,5,6,7]", "3"], ["[-1,-100,3,99]", "2"], ["[1,2]", "3"], ["[1]", "0"], ["[1,2,3]", "0"], ["[1,2,3,4]", "4"], ["[1,2,3,4,5]", "7"], ["[-1]", "2"], ["[1,2,3,4,5,6]", "1"], ["[1,2,3,4,5,6]", "5"], ["[0,-1,2,-3,4]", "2"], ["[1,2,3,4,5,6,7,8,9]", "4"], ["[0]", "100000"], ["[2147483647]", "1"], ["[-2147483648]", "99999"], ["[1,2]", "0"], ["[1,2]", "1"], ["[1,2]", "100000"], ["[1,2,3]", "1"], ["[1,2,3]", "2"], ["[1,2,3]", "100000"], ["[5,5,5,5]", "3"], ["[-2147483648,0,2147483647]", "2"], ["[9,8,7,6,5,4,3,2,1]", "8"], ["[10,20,30,40,50]", "10"], ["[10,20,30,40,50]", "11"], ["[1,-1,1,-1,1,-1]", "3"], ["[3,1,4,1,5,9,2,6]", "5"], ["[100,-100,200,-200,300,-300]", "100000"], ["[0,1,2,3,4,5,6,7,8,9]", "9"]], "expected": [[5, 6, 7, 1, 2, 3, 4], [3, 99, -1, -100], [2, 1], [1], [1, 2, 3], [1, 2, 3, 4], [4, 5, 1, 2, 3], [-1], [6, 1, 2, 3, 4, 5], [2, 3, 4, 5, 6, 1], [-3, 4, 0, -1, 2], [6, 7, 8, 9, 1, 2, 3, 4, 5], [0], [2147483647], [-2147483648], [1, 2], [2, 1], [1, 2], [3, 1, 2], [2, 3, 1], [3, 1, 2], [5, 5, 5, 5], [0, 2147483647, -2147483648], [8, 7, 6, 5, 4, 3, 2, 1, 9], [10, 20, 30, 40, 50], [50, 10, 20, 30, 40], [-1, 1, -1, 1, -1, 1], [1, 5, 9, 2, 6, 3, 1, 4], [200, -200, 300, -300, 100, -100], [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "471", "slug": "rotate-function", "id": 471, "title": "Rotate Function", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/rotate-function/", "examples": [{"explanation": "The four spins score 25, 16, 23 and 26; the best is 26.", "input": "nums = [4,3,2,6]", "output": "26"}, {"explanation": "A single entry always scores 0.", "input": "nums = [100]", "output": "0"}, {"explanation": "Scores are 8, 5 and 5; the best is 8.", "input": "nums = [1,2,3]", "output": "8"}], "hints": ["Write F(k) in terms of F(k-1): every entry shifts one slot up except the wrapped one.", "F(k) = F(k-1) + total - n * last_moved, where total is the array sum.", "Start from the directly computed F(0) and iterate."], "statement": "For an array `nums` of length `n`, imagine spinning it clockwise: the last entry moves to the front, and every other entry shifts one slot right. Repeating the spin produces `n` arrangements `arr0 ... arr(n-1)`, where `arr0` is the original. Score each arrangement by weighting positions: `F(k) = 0*arrk[0] + 1*arrk[1] + ... + (n-1)*arrk[n-1]`. Return the largest score among the `n` spins.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `-100 <= nums[i] <= 100`\n- The answer fits in a 32-bit signed integer.\n\nRecomputing each score from scratch costs quadratic time; derive each score from the previous one in constant time.\n", "solution": "## Approach\n\nCompute the score of the unrotated array and the plain sum in one pass. Each clockwise step moves every entry one slot forward (gaining the total sum) except the wrapped entry, which drops from weight `n - 1` to weight `0`. That gives the recurrence `F(k) = F(k-1) + total - n * moved`, so all scores follow in linear time while tracking the maximum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def maxRotateFunction(self, nums: List[int]) -> int:\n n = len(nums)\n total = sum(nums)\n cur = sum(i * v for i, v in enumerate(nums))\n best = cur\n for k in range(1, n):\n cur = cur + total - n * nums[n - k]\n best = max(best, cur)\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxRotateFunction(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxRotateFunction(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxRotateFunction(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "maxRotateFunction", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[4,3,2,6]"], ["[100]"], ["[1,2,3]"], ["[1]"], ["[0]"], ["[-100]"], ["[1,2]"], ["[2,1]"], ["[0,0,0]"], ["[1,1,1,1]"], ["[-1,-2,-3]"], ["[100,100,100]"], ["[-100,100]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[10,20,30,40]"], ["[0,1,2,3,4,5,6,7,8,9]"], ["[100,-100,100,-100]"], ["[1,100,1,100,1]"], ["[-5,0,5]"], ["[3,3,3,3,3,3]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[99,99]"], ["[0,100]"], ["[-100,0,100]"], ["[7,7,7,7,7,7,7]"], ["[4,3,2,6,1]"], ["[20,30,10]"], ["[-10,-20,30,40]"], ["[100,99,98,97]"]], "expected": [26, 0, 8, 0, 0, 0, 2, 2, 0, 6, -5, 300, 100, 40, 35, 200, 285, 200, 604, 10, 45, 330, 99, 100, 200, 147, 40, 80, 160, 594], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "48", "slug": "rotate-image", "id": 48, "title": "Rotate Image", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/rotate-image/", "examples": [{"input": "matrix = [[1,2,3],[4,5,6],[7,8,9]]", "output": "[[7,4,1],[8,5,2],[9,6,3]]", "explanation": "Rotating the matrix 90 degrees clockwise maps [1,2,3],[4,5,6],[7,8,9] to [[7,4,1],[8,5,2],[9,6,3]]."}, {"input": "matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]", "output": "[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]", "explanation": "Rotating the matrix 90 degrees clockwise maps [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] to [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]."}], "hints": ["Rotate the matrix layer by layer, starting from the outermost layer and working inward.", "Each layer can be rotated by moving groups of four cells at a time in a cycle."], "statement": "You receive an `n x n` 2D matrix standing in for a picture. Spin that picture 90 degrees clockwise.\n\nHand back the spun matrix.\n\n**Constraints:**\n- `n == matrix.length == matrix[i].length`\n- `1 <= n <= 20`\n- `-1000 <= matrix[i][j] <= 1000`\n", "solution": "## Approach\n\nTranspose the matrix by swapping elements across the diagonal, then reverse each row to achieve a 90-degree clockwise rotation.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n\u00b2)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def rotate(self, matrix: List[List[int]]) -> List[List[int]]:\n n = len(matrix)\n for i in range(n):\n for j in range(i + 1, n):\n matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]\n for i in range(n):\n matrix[i].reverse()\n return matrix\n```\n", "starter": {"go": "package main\n\nfunc Rotate(matrix [][]int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def rotate(self, matrix: List[List[int]]) -> List[List[int]]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> rotate(vector<vector<int>>& matrix) {\n return {};\n }\n};"}, "fn": "rotate", "params": [{"name": "matrix", "type": "int_array_2d", "visualizeType": "matrix"}], "outputType": "int_array_2d", "tests": [["[[1,2,3],[4,5,6],[7,8,9]]"], ["[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]"], ["[[1]]"], ["[[1,2],[3,4]]"], ["[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]]"], ["[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]"], ["[[10]]"], ["[[-1000]]"], ["[[1000]]"], ["[[0,1],[2,3]]"], ["[[-1,-2],[-3,-4]]"], ["[[-1000,1000],[1000,-1000]]"], ["[[1,0,-1],[2,0,-2],[3,0,-3]]"], ["[[9,8,7],[6,5,4],[3,2,1]]"], ["[[1,1,1],[2,2,2],[3,3,3]]"], ["[[0,0,0],[0,0,0],[0,0,0]]"], ["[[-4,-3,-2,-1],[0,1,2,3],[4,5,6,7],[8,9,10,11]]"], ["[[1,2,1,2],[3,4,3,4],[1,2,1,2],[3,4,3,4]]"], ["[[16,15,14,13],[12,11,10,9],[8,7,6,5],[4,3,2,1]]"], ["[[-1000,0,1000],[999,-999,1],[-1,500,-500]]"], ["[[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16,17,18],[19,20,21,22,23,24],[25,26,27,28,29,30],[31,32,33,34,35,36]]"], ["[[1,0,0,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]]"], ["[[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,0,0]]"], ["[[2,3,5,7,11],[13,17,19,23,29],[31,37,41,43,47],[53,59,61,67,71],[73,79,83,89,97]]"], ["[[-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,3,4,5,6,7],[8,9,10,11,12,13,14],[15,16,17,18,19,20,21],[22,23,24,25,26,27,28],[29,30,31,32,33,34,35],[36,37,38,39,40,41,42],[43,44,45,46,47,48,49]]"], ["[[7,7,7,7,7,7,7],[7,6,6,6,6,6,7],[7,6,5,5,5,6,7],[7,6,5,4,5,6,7],[7,6,5,5,5,6,7],[7,6,6,6,6,6,7],[7,7,7,7,7,7,7]]"], ["[[1000,-1000,1000,-1000],[-1000,1000,-1000,1000],[1000,-1000,1000,-1000],[-1000,1000,-1000,1000]]"], ["[[42,17,8],[99,-5,0],[3,14,15]]"], ["[[6,5,4,3,2,1],[12,11,10,9,8,7],[18,17,16,15,14,13],[24,23,22,21,20,19],[30,29,28,27,26,25],[36,35,34,33,32,31]]"]], "expected": [[[7, 4, 1], [8, 5, 2], [9, 6, 3]], [[15, 13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7, 10, 11]], [[1]], [[3, 1], [4, 2]], [[21, 16, 11, 6, 1], [22, 17, 12, 7, 2], [23, 18, 13, 8, 3], [24, 19, 14, 9, 4], [25, 20, 15, 10, 5]], [[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]], [[10]], [[-1000]], [[1000]], [[2, 0], [3, 1]], [[-3, -1], [-4, -2]], [[1000, -1000], [-1000, 1000]], [[3, 2, 1], [0, 0, 0], [-3, -2, -1]], [[3, 6, 9], [2, 5, 8], [1, 4, 7]], [[3, 2, 1], [3, 2, 1], [3, 2, 1]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[8, 4, 0, -4], [9, 5, 1, -3], [10, 6, 2, -2], [11, 7, 3, -1]], [[3, 1, 3, 1], [4, 2, 4, 2], [3, 1, 3, 1], [4, 2, 4, 2]], [[4, 8, 12, 16], [3, 7, 11, 15], [2, 6, 10, 14], [1, 5, 9, 13]], [[-1, 999, -1000], [500, -999, 0], [-500, 1, 1000]], [[31, 25, 19, 13, 7, 1], [32, 26, 20, 14, 8, 2], [33, 27, 21, 15, 9, 3], [34, 28, 22, 16, 10, 4], [35, 29, 23, 17, 11, 5], [36, 30, 24, 18, 12, 6]], [[0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 0, 0], [1, 0, 0, 0, 0]], [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]], [[73, 53, 31, 13, 2], [79, 59, 37, 17, 3], [83, 61, 41, 19, 5], [89, 67, 43, 23, 7], [97, 71, 47, 29, 11]], [[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]], [[43, 36, 29, 22, 15, 8, 1], [44, 37, 30, 23, 16, 9, 2], [45, 38, 31, 24, 17, 10, 3], [46, 39, 32, 25, 18, 11, 4], [47, 40, 33, 26, 19, 12, 5], [48, 41, 34, 27, 20, 13, 6], [49, 42, 35, 28, 21, 14, 7]], [[7, 7, 7, 7, 7, 7, 7], [7, 6, 6, 6, 6, 6, 7], [7, 6, 5, 5, 5, 6, 7], [7, 6, 5, 4, 5, 6, 7], [7, 6, 5, 5, 5, 6, 7], [7, 6, 6, 6, 6, 6, 7], [7, 7, 7, 7, 7, 7, 7]], [[-1000, 1000, -1000, 1000], [1000, -1000, 1000, -1000], [-1000, 1000, -1000, 1000], [1000, -1000, 1000, -1000]], [[3, 99, 42], [14, -5, 17], [15, 0, 8]], [[36, 30, 24, 18, 12, 6], [35, 29, 23, 17, 11, 5], [34, 28, 22, 16, 10, 4], [33, 27, 21, 15, 9, 3], [32, 26, 20, 14, 8, 2], [31, 25, 19, 13, 7, 1]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "269", "slug": "rotate-list", "id": 269, "title": "Rotate List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/rotate-list/", "examples": [{"input": "head = [1,2,3,4,5], k = 2", "output": "[4,5,1,2,3]", "explanation": "The last 2 nodes (4, 5) move to the front."}, {"input": "head = [0,1,2], k = 4", "output": "[2,0,1]", "explanation": "4 mod 3 is 1, so effectively rotate by 1."}, {"input": "head = [], k = 0", "output": "[]", "explanation": "An empty list stays empty."}], "hints": ["Compute the length first, then reduce k with k % length to handle large rotations.", "Link the tail to the head to form a ring, then break it at the new tail (length - k%length steps from the start)."], "statement": "Given the head of a singly linked list and a non-negative integer `k`, shift the list to the right by `k` places. Shifting means the last `k` nodes move to the front while preserving their internal order, and the remaining nodes follow behind them.\n\nIf `k` is larger than the list length, wrap around using `k` modulo the length. An empty list or a zero shift leaves the list unchanged.\n\n**Constraints:**\n- `0 <= number of nodes <= 500`\n- `-100 <= node value <= 100`\n- `0 <= k <= 2000000000`\n", "solution": "## Approach\n\nMeasure the list length and close it into a ring by pointing the tail at the head. Reducing the shift with modulo gives the effective rotation; walking length minus that many steps from the head finds the new tail. Cutting the ring there yields the rotated list.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one pass to measure and one to find the split.\n- **Space Complexity:** O(1), only pointer rewiring.\n\n## Implementation\n\n```python\nclass Solution:\n def rotateRight(self, head, k: int):\n if not head or not head.next or k == 0:\n return head\n length = 1\n tail = head\n while tail.next:\n tail = tail.next\n length += 1\n k %= length\n if k == 0:\n return head\n tail.next = head\n new_tail = head\n for _ in range(length - k - 1):\n new_tail = new_tail.next\n new_head = new_tail.next\n new_tail.next = None\n return new_head\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc RotateRight(head *ListNode, k int) *ListNode {\n \n}", "python": "# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def rotateRight(self, head, k: int):\n pass\n", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* rotateRight(ListNode* head, int k) {\n return nullptr;\n }\n};"}, "fn": "rotateRight", "params": [{"name": "head", "type": "list_node"}, {"name": "k", "type": "int"}], "outputType": "list_node", "tests": [["[1,2,3,4,5]", "2"], ["[0,1,2]", "4"], ["[]", "0"], ["[1]", "0"], ["[1]", "1"], ["[1]", "99"], ["[1,2]", "0"], ["[1,2]", "1"], ["[1,2]", "2"], ["[1,2]", "3"], ["[1,2,3]", "0"], ["[1,2,3]", "1"], ["[1,2,3]", "3"], ["[1,2,3]", "2000000000"], ["[1,2,3,4,5]", "0"], ["[1,2,3,4,5]", "5"], ["[1,2,3,4,5]", "10"], ["[-100,0,100]", "2"], ["[5,4,3,2,1]", "3"], ["[0,0,0,0]", "2"], ["[1,2,3,4,5,6,7]", "3"], ["[10,20,30,40]", "6"], ["[1,2,3,4,5,6,7,8,9,10]", "4"], ["[1,2,3,4,5,6,7,8,9,10]", "11"], ["[3,1,4,1,5,9,2,6]", "5"], ["[7,7,7,7,7]", "7"], ["[100,-100,50,-50,0]", "1000000000"], ["[2,1]", "100"], ["[]", "5"], ["[42]", "42"]], "expected": [[4, 5, 1, 2, 3], [2, 0, 1], null, [1], [1], [1], [1, 2], [2, 1], [1, 2], [2, 1], [1, 2, 3], [3, 1, 2], [1, 2, 3], [2, 3, 1], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [0, 100, -100], [3, 2, 1, 5, 4], [0, 0, 0, 0], [5, 6, 7, 1, 2, 3, 4], [30, 40, 10, 20], [7, 8, 9, 10, 1, 2, 3, 4, 5, 6], [10, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 9, 2, 6, 3, 1, 4], [7, 7, 7, 7, 7], [100, -100, 50, -50, 0], [2, 1], null, [42]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "794", "slug": "rotate-string", "id": 794, "title": "Rotate String", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/rotate-string/", "examples": [{"input": "s = \"abcde\", goal = \"cdeab\"", "output": "true", "explanation": "Two left moves produce the target."}, {"input": "s = \"abcde\", goal = \"abced\"", "output": "false", "explanation": "No rotation matches."}, {"input": "s = \"a\", goal = \"a\"", "output": "true", "explanation": "Zero moves already match."}], "hints": ["Lengths must agree first; different lengths can never match.", "Every rotation of s appears as a length-m substring of s + s.", "Checking whether goal occurs inside s + s settles the question."], "statement": "You are given two strings `s` and `goal`. One rotation step moves the leftmost character of the string to its far right end, preserving the order of all other characters.\n\nDecide whether any number of such steps (possibly zero) can turn `s` into `goal`.\n\n**Constraints:**\n- `1 <= s.length, goal.length <= 100`\n- Both strings contain only lowercase English letters\n", "solution": "## Approach\n\nDifferent lengths are rejected at once. Otherwise every rotation of `s` is a contiguous block of the doubled string `s + s`, so the task reduces to a single substring test for `goal`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) in the worst case with naive search, O(n) with an efficient matcher, where n is the string length.\n- **Space Complexity:** O(n) for the doubled string.\n\n## Implementation\n\n```python\nclass Solution:\n def rotateString(self, s: str, goal: str) -> bool:\n if len(s) != len(goal):\n return False\n return goal in (s + s)\n```\n", "starter": {"go": "package main\n\nfunc RotateString(s string, goal string) bool {\n return false\n}", "python": "class Solution:\n def rotateString(self, s: str, goal: str) -> bool:\n return False", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool rotateString(string s, string goal) {\n return false;\n }\n};"}, "fn": "rotateString", "params": [{"name": "s", "type": "string"}, {"name": "goal", "type": "string"}], "outputType": "boolean", "tests": [["abcde", "cdeab"], ["abcde", "abced"], ["a", "a"], ["a", "b"], ["ab", "ba"], ["ab", "ab"], ["aa", "aa"], ["abc", "bca"], ["abc", "cab"], ["abc", "acb"], ["waterbottle", "erbottlewat"], ["hello", "llohe"], ["hello", "ohell"], ["hello", "hello"], ["abcd", "abcd"], ["abcd", "bcda"], ["abcd", "dabc"], ["abcd", "abdc"], ["aaaaa", "aaaaa"], ["ababa", "baaab"], ["abcde", "eabcd"], ["xyz", "zxy"], ["xyz", "yxz"], ["abcabc", "bcabca"], ["aab", "aba"], ["aab", "baa"], ["abcde", "abcde"], ["abcdef", "defabc"]], "expected": [true, false, true, false, true, true, true, true, true, false, true, true, true, true, true, true, true, false, true, false, true, true, false, true, true, true, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "786", "slug": "rotated-digits", "id": 786, "title": "Rotated Digits", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/rotated-digits/", "examples": [{"input": "n = 10", "output": "4", "explanation": "Values 2, 5, 6, and 9 qualify."}, {"input": "n = 1", "output": "0", "explanation": "The number 1 spins to itself."}, {"input": "n = 20", "output": "9", "explanation": "Nine values up to 20 change under rotation."}], "hints": ["Check each number digit by digit: reject on 3, 4, or 7, and require at least one of 2, 5, 6, 9.", "A lookup table for the ten digits keeps the inner test tiny.", "With n capped at 10000, a straight scan from 1 to n is fast enough."], "statement": "Spin each decimal digit half a turn and see what it becomes. The digits\n`0`, `1`, and `8` look the same afterwards; `2` and `5` turn into each\nother; `6` and `9` turn into each other. The remaining digits (`3`, `4`,\n`7`) break, so any number containing one of them is unusable.\n\nCall a positive integer turning when every digit survives the spin and at\nleast one digit actually changes (that is, the number uses `2`, `5`, `6`,\nor `9` somewhere). Given `n`, count how many turning integers lie in the\nclosed interval from `1` to `n`.\n\n**Constraints:**\n- `1 <= n <= 10^4`\n", "solution": "## Approach\n\nInspect every integer from `1` to `n` one decimal digit at a time. Discard\nthe number if any digit is `3`, `4`, or `7`, since those have no rotated\nform. Otherwise mark the number good when at least one digit belongs to the\nchanging set `2, 5, 6, 9`. Counting the good numbers gives the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n), since each of the n values contributes its decimal digits.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def rotatedDigits(self, n: int) -> int:\n count = 0\n for x in range(1, n + 1):\n changed = False\n valid = True\n v = x\n while v > 0:\n d = v % 10\n if d in (3, 4, 7):\n valid = False\n break\n if d in (2, 5, 6, 9):\n changed = True\n v //= 10\n if valid and changed:\n count += 1\n return count\n```\n", "starter": {"go": "package main\n\nfunc RotatedDigits(n int) int {\n return 0\n}", "python": "class Solution:\n def rotatedDigits(self, n: int) -> int:\n return 0\n", "cpp": "class Solution {\npublic:\n int rotatedDigits(int n) {\n return 0;\n }\n};"}, "fn": "rotatedDigits", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["10"], ["1"], ["20"], ["2"], ["5"], ["6"], ["9"], ["11"], ["15"], ["25"], ["30"], ["50"], ["100"], ["200"], ["500"], ["1000"], ["3"], ["4"], ["7"], ["8"], ["12"], ["19"], ["21"], ["60"], ["101"], ["1000"], ["5000"], ["10000"]], "expected": [4, 0, 9, 1, 2, 3, 4, 4, 6, 12, 15, 16, 40, 81, 130, 316, 1, 1, 3, 3, 5, 8, 10, 23, 40, 316, 976, 2320], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "117", "slug": "rotting-oranges", "id": 117, "title": "Rotting Oranges", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/rotting-oranges/", "examples": [{"input": "grid = [[2,1,1],[1,1,0],[0,1,1]]", "output": "4", "explanation": "All fresh oranges rot after 4 minutes."}, {"input": "grid = [[2,1,1],[0,1,1],[1,0,1]]", "output": "-1", "explanation": "The fresh orange in the lower-left corner cannot be reached."}, {"input": "grid = [[0,2]]", "output": "0", "explanation": "There are no fresh oranges to rot."}], "hints": ["Use all initially rotten oranges as the first layer of a breadth-first search.", "Count fresh oranges and reduce the count whenever a BFS layer rots one."], "statement": "Picture a rectangular box of cells that is never empty. Each position stores one of three codes: `0` means the cell holds nothing, `1` means it holds a fresh orange, and `2` means it holds an already spoiled orange.\n\nSpoilage advances in rounds, one round per minute: every fresh orange that shares an edge \u2014 up, down, left, or right, but not diagonally \u2014 with a spoiled orange turns spoiled too, with all such changes in a round happening together.\n\nDetermine the smallest number of minutes needed before no fresh orange is left anywhere in the box. When some fresh orange can never be reached by the spread, answer `-1` instead.\n\n**Constraints:**\n- `1 <= grid.length <= 10`\n- `1 <= grid[r].length <= 10`\n- Every row has the same length.\n- Every cell is `0`, `1`, or `2`.\n", "solution": "## Approach\n\nCopy the grid, count all fresh oranges, and initialize a queue with every rotten orange. Each breadth-first-search layer represents one minute and rots all fresh neighbors simultaneously. Stop when no fresh oranges remain or the queue can no longer spread; the latter case is impossible and returns `-1`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), because every orange is processed at most once.\n- **Space Complexity:** O(m * n) for the copied state and breadth-first-search queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\n\nclass Solution:\n def orangesRotting(self, grid: List[List[int]]) -> int:\n state = [row.copy() for row in grid]\n rows, cols = len(state), len(state[0])\n queue = deque()\n fresh = 0\n for row in range(rows):\n for col in range(cols):\n if state[row][col] == 1:\n fresh += 1\n elif state[row][col] == 2:\n queue.append((row, col))\n\n minutes = 0\n while fresh > 0 and queue:\n for _ in range(len(queue)):\n row, col = queue.popleft()\n for row_step, col_step in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n next_row = row + row_step\n next_col = col + col_step\n if not (0 <= next_row < rows and 0 <= next_col < cols):\n continue\n if state[next_row][next_col] != 1:\n continue\n state[next_row][next_col] = 2\n fresh -= 1\n queue.append((next_row, next_col))\n minutes += 1\n return minutes if fresh == 0 else -1\n```\n", "starter": {"go": "package main\n\nfunc OrangesRotting(grid [][]int) int {\n return 0\n}\n", "python": "from typing import List\n\nclass Solution:\n def orangesRotting(self, grid: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int orangesRotting(vector<vector<int>>& grid) {\n return 0;\n }\n};"}, "fn": "orangesRotting", "params": [{"name": "grid", "type": "int_array_2d", "visualizeType": "matrix"}], "outputType": "int", "tests": [["[[0]]"], ["[[1]]"], ["[[2]]"], ["[[0,0]]"], ["[[1,1]]"], ["[[2,1]]"], ["[[1,2]]"], ["[[2,0,1]]"], ["[[2,1,1]]"], ["[[1,1,2]]"], ["[[2],[1],[1]]"], ["[[1],[0],[2]]"], ["[[2,1],[1,1]]"], ["[[1,1],[1,2]]"], ["[[2,0],[0,1]]"], ["[[0,0],[0,0]]"], ["[[2,2],[2,2]]"], ["[[1,1],[1,1]]"], ["[[2,1],[0,1]]"], ["[[2,0],[1,1]]"], ["[[2,1,1],[1,1,0],[0,1,1]]"], ["[[2,1,1],[0,1,1],[1,0,1]]"], ["[[0,2]]"], ["[[2,0,0],[0,0,0],[0,0,1]]"], ["[[2,1,0],[1,1,1],[0,1,2]]"], ["[[1,2,1],[1,1,1],[1,2,1]]"], ["[[2,0,2],[1,1,1],[0,1,0]]"], ["[[1,0,1],[0,2,0],[1,0,1]]"], ["[[2,1,2],[1,1,1],[2,1,2]]"], ["[[0,1,0],[1,2,1],[0,1,0]]"], ["[[2,1,1,1]]"], ["[[1,1,1,2]]"], ["[[2,1,0,1,2]]"], ["[[2],[1],[1],[1],[0]]"], ["[[1],[0],[1],[2]]"], ["[[2,1,1,0],[0,1,1,1]]"], ["[[1,1,0,2],[1,1,1,0]]"], ["[[2,0,1,1],[1,1,1,0]]"], ["[[0,1,1,2],[1,0,1,1]]"], ["[[2,1,1,1],[1,0,0,1],[1,1,1,1]]"], ["[[1,1,1,2],[1,0,0,1],[1,1,1,1]]"], ["[[2,0,1,0,2],[1,1,1,1,1],[0,1,0,1,0]]"], ["[[1,0,1,0,1],[1,2,1,2,1],[1,0,1,0,1]]"], ["[[2,1,0,1,1],[0,1,0,1,2],[1,1,1,1,0]]"], ["[[0,1,1,1],[2,1,0,1],[0,1,1,2],[1,1,0,0]]"], ["[[2,1,1,0],[1,0,1,1],[1,1,1,0],[0,1,1,1]]"], ["[[1,1,1,1],[1,0,0,1],[1,0,2,1],[1,1,1,1]]"], ["[[2,0,0,0,2],[1,1,1,1,1],[0,0,1,0,0],[1,1,1,1,1]]"], ["[[1,1,0,1,1],[1,2,0,2,1],[1,1,0,1,1],[0,1,1,1,0]]"], ["[[2,1,1,1,1],[0,0,0,0,1],[1,1,1,0,1],[1,0,1,1,1],[1,0,0,0,2]]"], ["[[1,1,1,1,1],[1,0,0,0,1],[1,0,2,0,1],[1,0,0,0,1],[1,1,1,1,1]]"], ["[[2,1,0,1,2,1],[1,1,0,1,1,1],[0,1,1,1,0,1],[1,1,0,1,1,1]]"], ["@javascript:JSON.stringify(Array.from({length:10},(_,r)=>Array.from({length:10},(_,c)=>r===0&&c===0?2:1)))"]], "expected": [0, -1, 0, 0, -1, 1, 1, -1, 2, 2, 2, -1, 2, 2, -1, 0, 0, -1, 2, 2, 4, -1, 0, -1, 2, 2, 3, -1, 2, 1, 3, 3, 1, 3, -1, 4, -1, 5, -1, 5, 5, 4, 2, 4, 4, 6, 6, 7, 3, 8, -1, 5, 18], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "434", "slug": "russian-doll-envelopes", "id": 434, "title": "Russian Doll Envelopes", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/russian-doll-envelopes/", "examples": [{"input": "envelopes = [[5,4],[6,4],[6,7],[2,3]]", "output": "3", "explanation": "The chain [2,3] -> [5,4] -> [6,7] nests three envelopes."}, {"input": "envelopes = [[1,1],[1,1],[1,1]]", "output": "1", "explanation": "Equal envelopes never fit inside each other."}], "hints": ["Sort by width ascending, and by height descending when widths tie, so equal widths can never form a chain.", "After sorting, the task becomes the longest strictly increasing subsequence of heights.", "Maintain pile tops with binary search for an O(n log n) solution."], "statement": "You are given envelopes described by `[width, height]` pairs. One envelope can\nhold another exactly when both its width and its height are strictly larger.\nTurning envelopes is not allowed.\n\nFind the largest number of envelopes that can be nested one inside another in a\nsingle chain.\n\n**Constraints:**\n- `1 <= envelopes.length <= 10^5`\n- `envelopes[i].length == 2`\n- `1 <= width, height <= 10^5`\n", "solution": "## Approach\n\nOrder envelopes by width ascending, breaking ties by height descending so that\nenvelopes sharing a width can never appear together in a height subsequence.\nThe nesting task then reduces to the longest strictly increasing subsequence\nof heights, solved by keeping pile-top values and placing each height with\nbinary search.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting plus the subsequence pass.\n- **Space Complexity:** O(n) for the pile tops.\n\n## Implementation\n\n```python\nimport bisect\nfrom typing import List\n\nclass Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n envelopes.sort(key=lambda e: (e[0], -e[1]))\n tails: List[int] = []\n for _, h in envelopes:\n i = bisect.bisect_left(tails, h)\n if i == len(tails):\n tails.append(h)\n else:\n tails[i] = h\n return len(tails)\n```\n", "starter": {"go": "package main\n\nfunc MaxEnvelopes(envelopes [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n return 0;\n }\n};"}, "fn": "maxEnvelopes", "params": [{"name": "envelopes", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[5, 4], [6, 4], [6, 7], [2, 3]]"], ["[[1, 1], [1, 1], [1, 1]]"], ["[[1, 1]]"], ["[[4, 5], [4, 6], [6, 7], [2, 3], [1, 1]]"], ["[[1, 2], [2, 3], [3, 4], [4, 5]]"], ["[[4, 5], [3, 4], [2, 3], [1, 2]]"], ["[[1, 3], [3, 5], [6, 7], [6, 8], [8, 4], [9, 5]]"], ["[[2, 100], [3, 200], [4, 300], [5, 500], [5, 400], [5, 250], [6, 370], [6, 360], [7, 380]]"], ["[[1, 1], [2, 2], [2, 3], [3, 4]]"], ["[[3, 3], [2, 2], [1, 1]]"], ["[[1, 10], [2, 9], [3, 8], [4, 7]]"], ["[[1, 2], [1, 2], [1, 2], [2, 3]]"], ["[[10, 10]]"], ["[[1, 5], [2, 4], [3, 3], [4, 2], [5, 1]]"], ["[[2, 3], [5, 4], [6, 7], [6, 4]]"], ["[[1, 2], [3, 4], [2, 5], [4, 6], [5, 7]]"], ["[[7, 8], [1, 2], [3, 4], [5, 6]]"], ["[[1, 100], [100, 1], [2, 3], [3, 4], [50, 50]]"], ["[[4, 4], [5, 5], [5, 6], [6, 5], [7, 8]]"], ["[[1, 2], [2, 1], [3, 5], [4, 3], [5, 6]]"], ["[[9, 9], [8, 8], [7, 7], [6, 6], [5, 5], [4, 4]]"], ["[[1, 2], [2, 3], [3, 1], [4, 5]]"], ["[[5, 5], [1, 1], [2, 2], [3, 3], [4, 4]]"], ["[[2, 2], [3, 1], [4, 5], [1, 4], [5, 6]]"], ["[[3, 5], [4, 4], [5, 6], [1, 2], [2, 1], [6, 7]]"]], "expected": [3, 1, 1, 4, 4, 4, 3, 5, 3, 3, 1, 2, 1, 1, 3, 4, 4, 3, 3, 3, 6, 3, 5, 3, 4], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "61", "slug": "same-tree", "id": 61, "title": "Same Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/same-tree/", "examples": [{"input": "p = [1,2,3], q = [1,2,3]", "output": "true", "explanation": "Both trees [1,2,3] and [1,2,3] have identical structure and node values at every position."}, {"input": "p = [1,2], q = [1,null,2]", "output": "false", "explanation": "Tree p has a left child 2, while tree q has a right child 2 \u2014 the structure differs."}, {"input": "p = [], q = []", "output": "true", "explanation": "Both trees are empty, so they are identical."}], "hints": ["Compare two binary trees recursively to verify identical structure and node values."], "statement": "You are handed the roots `p` and `q` of two binary trees. Decide whether the pair counts as the same tree.\n\nHere \"same\" carries a two-part meaning: the two trees share exactly the same branching layout, and each pair of nodes sitting in matching positions stores an equal value.\n\n**Constraints:**\n\n- The number of nodes in both trees is in the range [0, 100].\n- -10^4 \u2264 Node.val \u2264 10^4\n", "solution": "## Approach\n\nRecursively compare both trees: if both nodes are null they match; if one is null or values differ they don't; otherwise recurse on left and right children.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(h)\n\n## Implementation\n\n```python\nfrom typing import Optional\nclass Solution:\n def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:\n if not p and not q:\n return True\n if not p or not q or p.val != q.val:\n return False\n return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)\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 IsSameTree(p *TreeNode, q *TreeNode) bool {\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 isSameTree(self, p, q) -> bool:\n # TODO: return True if trees are identical\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 bool isSameTree(TreeNode* p, TreeNode* q) {\n \n }\n};\n"}, "fn": "isSameTree", "params": [{"name": "p", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "q", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "boolean", "tests": [["[1,2,3]", "[1,2,3]"], ["[1,2]", "[1,null,2]"], ["[]", "[]"], ["[1,2,1]", "[1,2,2]"], ["[0,-5,10]", "[0,-5,10]"], ["[5,4,6,3,null]", "[5,4,6,3,null]"], ["[1,null,2,null,3]", "[1,null,2,3]"], ["[]", "[0]"], ["[0]", "[]"], ["[0]", "[0]"], ["[-10000]", "[-10000]"], ["[10000]", "[-10000]"], ["[1,2,3]", "[1,3,2]"], ["[1,2,null]", "[1,2]"], ["[1,null,2]", "[1,null,2]"], ["[1,2,3,4,5,6,7]", "[1,2,3,4,5,6,7]"], ["[1,2,3,4,5,6,7]", "[1,2,3,4,5,6,8]"], ["[1,2,3,null,4]", "[1,2,3,4]"], ["[1,1,1,1,null,null,1]", "[1,1,1,1,null,null,1]"], ["[0,-1,1,-2,null,null,2]", "[0,-1,1,-2,null,null,2]"], ["[0,-1,1,-2,null,null,2]", "[0,-1,1,null,-2,2]"], ["[10,5,15,3,7,12,20]", "[10,5,15,3,7,12,20]"], ["[10,5,15,3,7,12,20]", "[10,5,15,3,7,12,19]"], ["[-10000,null,10000]", "[-10000,null,10000]"], ["[1,2,null,3,null,4]", "[1,2,null,3,null,4]"], ["[1,null,2,null,3,null,4]", "[1,null,2,null,3,null,5]"], ["[4,2,6,1,3,5,7,null,null,null,null,null,null,null,8]", "[4,2,6,1,3,5,7,null,null,null,null,null,null,null,8]"], ["[4,2,6,1,3,5,7]", "[4,2,6,1,3,null,7]"], ["[42,42,42,42,42]", "[42,42,42,42,42]"], ["[42,42,42,42,42]", "[42,42,42,null,42]"]], "expected": [true, false, true, false, true, true, false, false, false, true, true, false, false, true, true, true, false, false, true, true, false, true, false, true, true, false, true, false, true, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "973", "slug": "satisfiability-of-equality-equations", "id": 973, "title": "Satisfiability of Equality Equations", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/satisfiability-of-equality-equations/", "examples": [{"input": "equations = [\"a==b\",\"b!=a\"]", "output": "false", "explanation": "a and b cannot be equal and different simultaneously."}, {"input": "equations = [\"b==a\",\"a==b\"]", "output": "true", "explanation": "Setting both to the same value satisfies each equation."}, {"input": "equations = [\"a==b\",\"b!=c\",\"c==a\"]", "output": "false", "explanation": "The equalities force a, b and c together, contradicting b!=c."}], "hints": ["Handle all == equations first by merging the two sides into shared groups with a union-find structure.", "Then check every != equation: if both sides landed in the same group, the system is contradictory.", "Only 26 variables exist, so the union-find arrays stay tiny."], "statement": "You are given a list of equations over lowercase variables. Each equation has one\nof two shapes: `x==y`, meaning `x` and `y` must hold equal values, or `x!=y`,\nmeaning they must hold different values.\n\nReturn `true` if the variables can be assigned values so that every equation\nholds at the same time, and `false` otherwise.\n\n**Constraints:**\n- `1 <= equations.length <= 500`\n- Each equation is exactly 4 characters: a lowercase letter, `==` or `!=`, and a lowercase letter.\n", "solution": "## Approach\n\nEqualities are transitive, so they partition the variables into groups that\nmust share one value. Process every `==` equation with a union-find structure\nover the 26 letters, merging the two sides. Afterwards scan every `!=`\nequation: when both sides belong to the same group the requirements clash and\nthe answer is false; if no clash appears the grouping itself yields a valid\nassignment.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * \u03b1(26) + m), where n is the number of `==` equations and m the number of `!=` equations; union-find operations are effectively constant.\n- **Space Complexity:** O(1), just the 26-entry parent array.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def equationsPossible(self, equations: List[str]) -> bool:\n parent = list(range(26))\n\n def find(x):\n while parent[x] != x:\n parent[x] = parent[parent[x]]\n x = parent[x]\n return x\n\n for e in equations:\n if e[1] == '=':\n parent[find(ord(e[0]) - 97)] = find(ord(e[3]) - 97)\n for e in equations:\n if e[1] == '!' and find(ord(e[0]) - 97) == find(ord(e[3]) - 97):\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc EquationsPossible(equations []string) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def equationsPossible(self, equations: List[str]) -> bool:\n return False", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool equationsPossible(vector<string>& equations) {\n return false;\n }\n};"}, "fn": "equationsPossible", "params": [{"name": "equations", "type": "string_array"}], "outputType": "boolean", "tests": [["[\"a==b\",\"b!=a\"]"], ["[\"b==a\",\"a==b\"]"], ["[\"a==b\",\"b==c\",\"a==c\"]"], ["[\"a==b\",\"b!=c\",\"c==a\"]"], ["[\"c==c\",\"b==d\",\"x!=z\"]"], ["[\"a!=a\"]"], ["[\"a==a\"]"], ["[\"a==b\",\"b==c\",\"c==d\",\"d!=a\"]"], ["[\"a==b\",\"c==d\",\"e==f\",\"a!=c\"]"], ["[\"a!=b\",\"b!=c\",\"a!=c\"]"], ["[\"x==y\",\"y==z\",\"z==x\",\"x!=y\"]"], ["[\"p==q\",\"q!=r\",\"r==p\",\"s==t\"]"], ["[\"m==n\",\"n==o\",\"o==p\",\"p==m\"]"], ["[\"a==b\",\"b==c\",\"c==d\",\"d==e\",\"e!=a\"]"], ["[\"a==b\"]"], ["[\"a!=b\"]"], ["[\"z==z\"]"], ["[\"a==b\",\"a==c\",\"b!=c\"]"], ["[\"a==b\",\"c==d\",\"b==c\",\"a!=d\"]"], ["[\"a==b\",\"c==d\",\"e==f\",\"g==h\",\"a!=g\"]"], ["[\"a==b\",\"b==c\",\"d==e\",\"e==f\",\"c!=f\"]"], ["[\"a==b\",\"b==a\",\"c==c\",\"d!=d\"]"], ["[\"q==r\",\"r==s\",\"s==t\",\"u==v\",\"t!=u\"]"], ["[\"a==b\",\"c==b\",\"d==e\",\"a!=d\",\"c!=e\"]"], ["[\"a==b\",\"b==c\",\"c==a\",\"a!=b\"]"], ["[\"x==x\",\"y==y\",\"z==z\"]"], ["[\"a==z\",\"z==m\",\"m!=a\"]"], ["[\"a==b\",\"d==b\",\"c==d\",\"e!=a\",\"e==c\"]"]], "expected": [false, true, true, false, true, false, true, false, true, true, false, false, true, false, true, true, true, false, false, true, true, false, true, true, false, true, false, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "856", "slug": "score-after-flipping-matrix", "id": 856, "title": "Score After Flipping Matrix", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/score-after-flipping-matrix/", "examples": [{"input": "grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]", "output": "39", "explanation": "Rows become 1111, 1001 and 1011 after optimal flips, totaling 39."}, {"input": "grid = [[0]]", "output": "1", "explanation": "Flip the single cell to 1."}, {"input": "grid = [[0,1],[1,1]]", "output": "5", "explanation": "Rows become 10 and 11, scoring 2 + 3 = 5."}], "hints": ["The leftmost column carries the largest weight, so first make every entry there a 1 using row flips; that choice never harms optimality.", "Once the leading column is fixed, each remaining column can be decided independently by picking the majority value to maximize its contribution.", "A column with `c` ones among `m` rows contributes `max(c, m - c) * 2^(n-1-j)` after the optimal column flip."], "statement": "You are given a binary matrix `grid` with `m` rows and `n` columns. Each cell holds `0` or `1`, and each row is read as a binary number with the leftmost cell as the most significant bit.\n\nYou may perform two kinds of moves any number of times, in any order:\n\n- Choose a row and invert every bit in that row.\n- Choose a column and invert every bit in that column.\n\nAfter all moves, the score is the sum of the row values interpreted in binary. Rearrange the bits with allowed moves to make this total as large as possible, and return that maximum.\n\n**Constraints:**\n- `m == grid.length`\n- `n == grid[i].length`\n- `1 <= m <= 20`\n- `1 <= n <= 20`\n- `grid[i][j]` is `0` or `1`.\n", "solution": "## Approach\n\nThink of flipping a row as deciding its first cell becomes 1, since the leading bit dominates all others combined. Normalize every row that way without explicitly rewriting the grid. After that, each column is independent: either keep it or invert it, so take the larger of the one-count and zero-count times the column weight. Summing those maxima gives the best achievable total.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n) to count each column once.\n- **Space Complexity:** O(1) extra.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def matrixScore(self, grid: List[List[int]]) -> int:\n m, n = len(grid), len(grid[0])\n ans = 0\n for j in range(n):\n ones = 0\n for i in range(m):\n v = grid[i][j] ^ (1 if grid[i][0] == 0 else 0)\n if v == 1:\n ones += 1\n ans += max(ones, m - ones) * (1 << (n - 1 - j))\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MatrixScore(grid [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def matrixScore(self, grid: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int matrixScore(vector<vector<int>>& grid) {\n return 0;\n }\n};"}, "fn": "matrixScore", "params": [{"name": "grid", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0,0,1,1],[1,0,1,0],[1,1,0,0]]"], ["[[0]]"], ["[[0,1],[1,1]]"], ["[[1]]"], ["[[1,0],[0,1]]"], ["[[0,0],[0,0]]"], ["[[1,1],[1,1]]"], ["[[0,1,0],[1,0,1]]"], ["[[1,0,0],[0,1,0],[0,0,1]]"], ["[[0,0,0],[0,0,0],[0,0,0]]"], ["[[1,1,1],[1,1,1],[1,1,1]]"], ["[[0,1,1],[1,0,1],[1,1,0]]"], ["[[0,0,1]]"], ["[[1,0]]"], ["[[0],[1],[0]]"], ["[[1],[0],[1]]"], ["[[0,1,0,1],[1,0,1,0]]"], ["[[1,0,1,0,1],[0,1,0,1,0]]"], ["[[0,0,0,0],[1,1,1,1]]"], ["[[0,1],[0,1],[0,1]]"], ["[[1,0,0,1],[0,1,1,0],[1,1,0,1]]"], ["[[0,0],[1,0],[0,1],[1,1]]"], ["[[1,0,1],[0,1,0],[1,0,1],[0,1,0]]"], ["[[0,1,1,0,1],[1,0,0,1,0],[0,0,1,1,1]]"], ["[[1,1,0,0,1],[0,0,1,1,0]]"], ["[[0,0,1,1,0,1]]"], ["[[0],[0],[0],[0]]"], ["[[1,0,1,1,0],[1,1,0,0,1],[0,1,1,0,0],[1,0,0,1,1]]"]], "expected": [39, 1, 5, 1, 6, 6, 6, 14, 18, 21, 21, 18, 7, 3, 3, 3, 30, 62, 30, 9, 41, 10, 28, 83, 62, 63, 4, 109], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "852", "slug": "score-of-parentheses", "id": 852, "title": "Score of Parentheses", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/score-of-parentheses/", "examples": [{"input": "s = \"()\"", "output": "1", "explanation": "A single pair is worth one."}, {"input": "s = \"(())\"", "output": "2", "explanation": "The inner pair scores 1, and the outer layer doubles it."}, {"input": "s = \"()()\"", "output": "2", "explanation": "Two adjacent pairs each score 1, and 1 + 1 = 2."}], "hints": ["Track nesting depth: a pair `()` that closes at its own depth contributes a power of two determined by how deeply it sits.", "A stack holding the running total of each open level lets you add the inner score doubled into the outer level, or use a depth counter and add `1 << depth` for every primitive `()`."], "statement": "You are given a string `s` that contains only the characters `(` and `)`. The string is balanced, meaning every opening bracket is eventually closed in the correct order.\n\nA score is assigned to such strings using the following ideas, applied in your own reasoning:\n\n- The smallest balanced pair `()` is worth one point.\n- When two balanced blocks sit side by side, their values add up.\n- When one balanced block is wrapped inside an extra pair of brackets, its value doubles.\n\nCompute the total score of `s`.\n\n**Constraints:**\n- `1 <= s.length <= 50`\n- `s` holds only `(` and `)` and forms a balanced sequence.\n- `s.length` is even.\n", "solution": "## Approach\n\nWalk through the brackets while keeping a running total for each open level on a stack. Opening a bracket starts a fresh level with value zero. Closing a bracket finishes the inner total `v`: a bare pair contributes one, otherwise it contributes twice the inner total, and that amount is added to the enclosing level.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`. Each character is pushed and popped once.\n- **Space Complexity:** O(n) for the stack in the worst case of deep nesting.\n\n## Implementation\n\n```python\nclass Solution:\n def scoreOfParentheses(self, s: str) -> int:\n st = [0]\n for c in s:\n if c == '(':\n st.append(0)\n else:\n v = st.pop()\n st[-1] += max(2 * v, 1)\n return st[0]\n```\n", "starter": {"go": "package main\n\nfunc ScoreOfParentheses(s string) int {\n return 0\n}", "python": "class Solution:\n def scoreOfParentheses(self, s: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int scoreOfParentheses(string s) {\n return 0;\n }\n};"}, "fn": "scoreOfParentheses", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["()"], ["(())"], ["()()"], ["(()(()))"], ["((()))"], ["(()())"], ["(())()"], ["()(()())"], ["((()()))"], ["()(())"], ["((())())"], ["(()())()"], ["()((()))"], ["(((())))"], ["()()()"], ["(())(())"], ["(()((())))"], ["((()()()))"], ["()(())()"], ["((()))()"], ["()(()(()))"], ["(((())))()"], ["(()()())"], ["()((()()))"], ["((((()))))"], ["(()(()()))"], ["()()(()())"], ["((())(()))"]], "expected": [1, 2, 2, 6, 4, 4, 3, 5, 8, 3, 6, 5, 5, 8, 3, 4, 10, 12, 4, 5, 7, 9, 6, 9, 16, 10, 6, 8], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "277", "slug": "scramble-string", "id": 277, "title": "Scramble String", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/scramble-string/", "examples": [{"input": "s1 = \"great\", s2 = \"rgeat\"", "output": "true", "explanation": "Split into gr/eat, swap the first half to rg, then rejoin as rgeat."}, {"input": "s1 = \"abcde\", s2 = \"caebd\"", "output": "false", "explanation": "No sequence of recursive swaps turns abcde into caebd."}, {"input": "s1 = \"a\", s2 = \"a\"", "output": "true", "explanation": "Identical single characters match."}], "hints": ["Try every split point with both the straight and swapped matchings, memoizing (i, j, length) results.", "Prune with character counts: mismatched frequency means the pair cannot be scrambles.", "Equal substrings are an immediate true without further splitting."], "statement": "Two strings of equal length are called scrambles of each other when one can be turned into the other by recursively splitting into two non-empty halves and optionally swapping the halves at any split. A single character only matches itself.\n\nGiven `s1` and `s2`, decide whether `s2` is a scrambled version of `s1`. Equal strings always qualify; strings with different character counts never do.\n\n**Constraints:**\n- `1 <= s1.length <= 30`\n- `s1.length == s2.length`\n- Both strings consist of lowercase English letters.\n", "solution": "## Approach\n\nRecurse on substring pairs with memoization over start positions and length. Identical slices succeed immediately and mismatched letter counts fail fast. Otherwise try each split in both straight and crossed alignments; any fully matching decomposition proves the pair are scrambles.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^4) worst case over all states and splits, fine for n <= 30.\n- **Space Complexity:** O(n^3) memoized states plus recursion depth O(n).\n\n## Implementation\n\n```python\nclass Solution:\n def isScramble(self, s1: str, s2: str) -> bool:\n from functools import lru_cache\n if len(s1) != len(s2):\n return False\n @lru_cache(maxsize=None)\n def dfs(i: int, j: int, length: int) -> bool:\n sub1 = s1[i:i + length]\n sub2 = s2[j:j + length]\n if sub1 == sub2:\n return True\n if sorted(sub1) != sorted(sub2):\n return False\n for k in range(1, length):\n if dfs(i, j, k) and dfs(i + k, j + k, length - k):\n return True\n if dfs(i, j + length - k, k) and dfs(i + k, j, length - k):\n return True\n return False\n return dfs(0, 0, len(s1))\n```\n", "starter": {"go": "package main\n\nfunc IsScramble(s1 string, s2 string) bool {\n return false\n}", "python": "class Solution:\n def isScramble(self, s1: str, s2: str) -> bool:\n return False\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool isScramble(string s1, string s2) {\n return false;\n }\n};"}, "fn": "isScramble", "params": [{"name": "s1", "type": "string"}, {"name": "s2", "type": "string"}], "outputType": "boolean", "tests": [["great", "rgeat"], ["abcde", "caebd"], ["a", "a"], ["a", "b"], ["ab", "ba"], ["ab", "ab"], ["abc", "bca"], ["abc", "acb"], ["abcd", "bdac"], ["great", "great"], ["great", "rgtae"], ["great", "eatgr"], ["abcdbdacbdac", "bdcadbacbadc"], ["oat", "tao"], ["hob", "boh"], ["abb", "bab"], ["abb", "bba"], ["abcde", "edcba"], ["abcdefghij", "jihgfedcba"], ["eebaac", "aacbee"], ["x", "x"], ["xy", "yx"], ["xyz", "zyx"], ["abcd", "abcd"], ["abcd", "dcba"], ["aabb", "bbaa"], ["aabb", "abab"], ["abcdefgh", "efghabcd"], ["ccabbb", "bbccab"], ["bbbbab", "babbbb"]], "expected": [true, false, true, false, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "347", "slug": "search-a-2d-matrix-ii", "id": 347, "title": "Search a 2D Matrix II", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/search-a-2d-matrix-ii/", "examples": [{"input": "matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5", "output": "true", "explanation": "The value 5 sits at row 1, column 1."}, {"input": "matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20", "output": "false", "explanation": "No cell holds the value 20."}], "hints": ["Start at the top-right corner: moving left decreases the value, moving down increases it.", "Compare the current cell with the target and step left on overshoot, down on undershoot.", "Leaving the matrix bounds means the target is absent."], "statement": "Given an `m x n` integer matrix where each row is sorted in increasing order from left to right and each column is sorted in increasing order from top to bottom, decide whether a `target` value appears in the matrix.\n\nExploit the ordering rather than scanning every cell: values grow toward the bottom and the right, and shrink toward the top and the left.\n\nReturn `true` when `target` is present, otherwise return `false`.\n\n**Constraints:**\n- `m == matrix.length`, `n == matrix[i].length`\n- `1 <= m, n <= 300`\n- `-10^9 <= matrix[i][j] <= 10^9`\n- Each row and each column is sorted in ascending order.\n- `-10^9 <= target <= 10^9`\n", "solution": "## Approach\n\nBegin at the top-right cell, where moving left lowers the value and moving down raises it. Compare the current cell with the target: step left when the cell is too large and step down when it is too small. Either the target is found or the walk exits the matrix bounds.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m + n) for an m x n matrix. Each step discards one row or one column.\n- **Space Complexity:** O(1), only two indices.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n r, c = 0, len(matrix[0]) - 1\n while r < len(matrix) and c >= 0:\n if matrix[r][c] == target:\n return True\n if matrix[r][c] > target:\n c -= 1\n else:\n r += 1\n return False\n```\n", "starter": {"go": "package main\n\nfunc SearchMatrix(matrix [][]int, target int) bool {\n return false\n}", "python": "from typing import List\n\nclass Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n return False\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool searchMatrix(vector<vector<int>>& matrix, int target) {\n return false;\n }\n};"}, "fn": "searchMatrix", "params": [{"name": "matrix", "type": "int_array_2d"}, {"name": "target", "type": "int"}], "outputType": "boolean", "tests": [["[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]", "5"], ["[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]", "20"], ["[[-5]]", "-5"], ["[[-5]]", "5"], ["[[1,1]]", "2"], ["[[1,2],[3,4]]", "3"], ["[[1,2],[3,4]]", "0"], ["[[1,3,5]]", "3"], ["[[1],[2],[3]]", "2"], ["[[1,4],[2,5]]", "4"], ["[[1,4],[2,5]]", "6"], ["[[-1,3]]", "3"], ["[[1,2,3],[4,5,6],[7,8,9]]", "9"], ["[[1,2,3],[4,5,6],[7,8,9]]", "10"], ["[[5]]", "5"], ["[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]", "30"], ["[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]", "1"], ["[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]", "16"], ["[[1,4],[2,5]]", "1"], ["[[1,4],[2,5]]", "2"], ["[[1,4],[2,5]]", "5"], ["[[1,2,3],[4,5,6],[7,8,9]]", "5"], ["[[1,2,3],[4,5,6],[7,8,9]]", "1"], ["[[-10,-5,0],[1,5,10],[20,30,40]]", "-5"], ["[[-10,-5,0],[1,5,10],[20,30,40]]", "7"], ["[[2]]", "3"], ["[[1,2,3,4,5]]", "4"], ["[[1],[3],[5],[7]]", "5"], ["[[1],[3],[5],[7]]", "6"], ["[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]]", "19"]], "expected": [true, false, true, false, false, true, false, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false, false, true, true, false, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "88", "slug": "search-a-2d-matrix", "id": 88, "title": "Search a 2D Matrix", "difficulty": "Medium", "category": "binary-search", "link": "https://leetcode.com/problems/search-a-2d-matrix/", "examples": [{"input": "matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3", "output": "true", "explanation": "Target 3 is present in the matrix."}, {"input": "matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13", "output": "false", "explanation": "Target 13 is not present in the matrix."}, {"input": "matrix = [[1]], target = 1", "output": "true", "explanation": "Target 1 is present in the matrix."}], "hints": ["The ordering is the same as if all rows were concatenated into one sorted array.", "Binary-search a virtual one-dimensional index range from 0 to rows * columns - 1.", "Map a virtual index i to matrix[i / columns][i % columns]."], "statement": "You are handed a rectangular integer table that is never empty, together with an integer `target`. Report whether `target` occurs anywhere inside the table: answer `true` when it does and `false` when it does not.\n\nThe table obeys one strict global ordering:\n\n- each row runs left to right in nondecreasing order;\n- for every row past the first, its opening entry is strictly larger than the closing entry of the row directly above it.\n\nPut differently, reading the rows one after another starting from the top left produces a single fully sorted sequence.\n\n**Constraints:**\n\n- `1 <= matrix.length, matrix[i].length <= 100`\n- Every row has the same number of columns.\n- `-10^4 <= matrix[i][j], target <= 10^4`\n- The matrix satisfies the global ordering described above.\n\n**Judge adaptation:** Code `searchMatrix(matrix, target)` directly in this repository. The test harness in each language passes the rectangle using that language's usual nested integer-array type.\n", "solution": "## Approach\n\nThe global ordering makes the matrix equivalent to one sorted array in row-major order. Binary-search virtual indices from `0` through `rows * columns - 1`, mapping index `i` to `matrix[i // columns][i % columns]`. This avoids constructing a flattened copy.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log(m * n)), where `m` is the number of rows and `n` is the number of columns.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n columns = len(matrix[0])\n left, right = 0, len(matrix) * columns - 1\n while left <= right:\n middle = left + (right - left) // 2\n value = matrix[middle // columns][middle % columns]\n if value == target:\n return True\n if value < target:\n left = middle + 1\n else:\n right = middle - 1\n return False\n```\n", "starter": {"go": "package main\n\nfunc SearchMatrix(matrix [][]int, target int) bool {\n return false\n}", "python": "from typing import List\n\nclass Solution:\n def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n return False\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool searchMatrix(vector<vector<int>>& matrix, int target) {\n return false;\n }\n};"}, "fn": "searchMatrix", "params": [{"name": "matrix", "type": "int_array_2d"}, {"name": "target", "type": "int"}], "outputType": "boolean", "tests": [["[[1,3,5,7],[10,11,16,20],[23,30,34,60]]", "3"], ["[[1,3,5,7],[10,11,16,20],[23,30,34,60]]", "13"], ["[[1]]", "1"], ["[[1]]", "0"], ["[[-5,-2,0,4]]", "-2"], ["[[-5,-2,0,4]]", "3"], ["[[1],[3],[5],[7]]", "5"], ["[[1],[3],[5],[7]]", "6"], ["[[1,2],[3,4]]", "1"], ["[[1,2],[3,4]]", "4"], ["[[1,2],[3,4]]", "2"], ["[[1,2],[3,4]]", "5"], ["[[-10,-8,-6],[-3,-1,0],[2,4,9]]", "-10"], ["[[-10,-8,-6],[-3,-1,0],[2,4,9]]", "0"], ["[[-10,-8,-6],[-3,-1,0],[2,4,9]]", "9"], ["[[-10,-8,-6],[-3,-1,0],[2,4,9]]", "-2"], ["[[1,1,2],[4,4,5]]", "1"], ["[[1,1,2],[4,4,5]]", "4"], ["[[1,1,2],[4,4,5]]", "3"], ["[[0,2,4,6,8]]", "8"], ["[[0,2,4,6,8]]", "-1"], ["[[0],[2],[4],[6],[8]]", "0"], ["[[0],[2],[4],[6],[8]]", "9"], ["[[-10000,-100,0],[1,100,10000]]", "-10000"], ["[[-10000,-100,0],[1,100,10000]]", "10000"], ["[[-10000,-100,0],[1,100,10000]]", "50"], ["[[2,3,5],[7,11,13],[17,19,23],[29,31,37]]", "17"], ["[[2,3,5],[7,11,13],[17,19,23],[29,31,37]]", "37"], ["[[2,3,5],[7,11,13],[17,19,23],[29,31,37]]", "4"], ["[[10,20,30,40],[50,60,70,80]]", "10"], ["[[10,20,30,40],[50,60,70,80]]", "80"], ["[[10,20,30,40],[50,60,70,80]]", "45"], ["[[-9,-7],[-5,-3],[-1,1],[3,5]]", "-3"], ["[[-9,-7],[-5,-3],[-1,1],[3,5]]", "2"], ["[[5,6,7,8,9],[12,13,14,15,16],[20,21,22,23,24]]", "14"], ["[[5,6,7,8,9],[12,13,14,15,16],[20,21,22,23,24]]", "19"], ["[[42]]", "42"], ["[[-42]]", "42"], ["[[1,3,3,5],[8,8,9,10],[15,15,15,20]]", "15"], ["[[1,3,3,5],[8,8,9,10],[15,15,15,20]]", "7"], ["[[100,200],[300,400],[500,600],[700,800],[900,1000]]", "600"], ["[[100,200],[300,400],[500,600],[700,800],[900,1000]]", "650"], ["[[-1000,-500,-100],[-50,-10,-1],[0,10,50],[100,500,1000]]", "-1"], ["[[-1000,-500,-100],[-50,-10,-1],[0,10,50],[100,500,1000]]", "0"], ["[[-1000,-500,-100],[-50,-10,-1],[0,10,50],[100,500,1000]]", "99"], ["[[1,2,3,4,5,6,7,8,9,10]]", "6"], ["[[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]", "6"], ["[[11,22,33],[44,55,66],[77,88,99]]", "55"], ["[[11,22,33],[44,55,66],[77,88,99]]", "54"], ["[[-20,-15,-10,-5],[0,5,10,15],[20,25,30,35],[40,45,50,55]]", "45"], ["@javascript:JSON.stringify(Array.from({length:100},(_,r)=>Array.from({length:100},(_,c)=>r*100+c-5000)))", "4999"]], "expected": [true, false, true, false, true, false, true, false, true, true, true, false, true, true, true, false, true, true, false, true, false, true, false, true, true, false, true, true, false, true, true, false, true, false, true, false, true, false, true, false, true, false, true, true, false, true, true, true, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "713", "slug": "search-in-a-binary-search-tree", "id": 713, "title": "Search in a Binary Search Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/search-in-a-binary-search-tree/", "examples": [{"input": "root = [4,2,7,1,3], val = 2", "output": "[2,1,3]", "explanation": "Subtree rooted at 2."}, {"input": "root = [4,2,7,1,3], val = 5", "output": "[]", "explanation": "Missing value."}, {"input": "root = [1,null,2,null,3], val = 3", "output": "[3]", "explanation": "Deepest node."}], "hints": ["Use the ordering: go left when val is smaller, right when larger.", "Stop at the first node equal to val and return it directly.", "A loop or recursion both run in height time."], "statement": "You are given the root of a binary search tree and an integer `val`. In such a tree, every left descendant is smaller than its ancestor and every right descendant is larger.\n\nLocate the node whose value equals `val` and return the whole subtree starting there (encoded in level order). If no node holds `val`, return an empty tree `[]`.\n\n**Constraints:**\n- Node count lies in `[1, 5000]`.\n- `1 <= Node.val, val <= 10^7`\n- The input is a valid search tree.\n", "solution": "## Approach\n\nExploit the search-tree ordering instead of scanning everything. Starting at the root, compare the wanted value with the current node: equality returns the current subtree, a smaller value continues left, and a larger value continues right. Falling off the tree means the value is absent.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(h), where h is the tree height (O(log n) when balanced).\n- **Space Complexity:** O(1) iterative, O(h) recursive.\n\n## Implementation\n\n```python\nclass Solution:\n def searchBST(self, root, val: int):\n cur = root\n while cur:\n if val == cur.val:\n return cur\n cur = cur.left if val < cur.val else cur.right\n return None\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 SearchBST(root *TreeNode, val int) *TreeNode {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def searchBST(self, root, val: int):\n pass\n", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* searchBST(TreeNode* root, int val) {\n return nullptr;\n }\n};"}, "fn": "searchBST", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "val", "type": "int"}], "outputType": "tree_node", "tests": [["[4,2,7,1,3]", "2"], ["[4,2,7,1,3]", "5"], ["[1,null,2,null,3]", "3"], ["[4,2,7,1,3]", "4"], ["[4,2,7,1,3]", "7"], ["[4,2,7,1,3]", "1"], ["[4,2,7,1,3]", "3"], ["[1]", "1"], ["[1]", "2"], ["[2,1,3]", "3"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "6"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "14"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "5"], ["[5,3,8,2,4,7,9]", "9"], ["[5,3,8,2,4,7,9]", "2"], ["[10,5,15,2,7,12,20]", "12"], ["[10,5,15,2,7,12,20]", "11"], ["[1,null,2]", "2"], ["[3,1,5,null,2]", "2"], ["[50,30,70,20,40,60,80]", "60"], ["[50,30,70,20,40,60,80]", "100"], ["[100,50,150,25,75,125,175]", "25"], ["[2,null,3,null,4]", "4"], ["[4,2,null,1,3]", "3"], ["[7,4,9,2,6,8,10]", "4"], ["[7,4,9,2,6,8,10]", "10"], ["[1,2,3]", "2"], ["[6,2,8,0,4,7,9,null,null,3,5]", "5"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "702", "slug": "search-in-a-sorted-array-of-unknown-size", "id": 702, "title": "Search in a Sorted Array of Unknown Size", "difficulty": "Medium", "category": "binary-search", "link": "https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size/", "examples": [{"input": "secret = [-1,0,3,5,9,12], target = 9", "output": "4", "explanation": "9 at index 4."}, {"input": "secret = [-1,0,3,5,9,12], target = 2", "output": "-1", "explanation": "2 absent."}, {"input": "secret = [1,2,3,4,5], target = 1", "output": "0", "explanation": "First entry."}], "hints": ["The judge never reveals the array or its length; only reader.get(i) is available, returning 2147483647 past the end.", "Grow an index exponentially (1, 2, 4, 8, ...) until the value reaches target or the sentinel, then binary-search that window.", "A single binary search over the whole array is impossible here because the length is unknown."], "statement": "A sorted list of distinct integers is hidden behind a reader. Interact with the judge object `reader` \u2014 your code never receives the array or its length:\n\n- `get(index)` returns the element at `index`, or `2147483647` if `index` is out of bounds.\n\nImplement `search(reader, target)` returning the index of `target`, or `-1` when absent. Because the length is unknown, grow a window exponentially (`1, 2, 4, 8, ...`) until it covers `target`, then binary search inside it. The judge counts your `get` calls and reports Wrong Answer if you exceed **10000** calls on a test case.\n\nMethod names per language: Java `reader.get(index)`, Python `reader.get(index)`, C++ `reader.get(index)`, C# `reader.Get(index)`, Rust `reader.get(index)`, Go `reader.Get(index)`, TypeScript `reader.get(index)`, PHP `$reader->get($index)`.\n\n**Constraints:**\n\n- `1 <= secret.length <= 10^4`\n- `-10^4 <= secret[i], target <= 10^4`\n- Values in `secret` are strictly increasing.\n- At most 10000 `get` calls per test case.\n", "solution": "## Approach\n\nBecause the visible array is sorted, halving the search interval quickly homes in on the goal. Compare the middle entry with the target and discard the half that cannot contain it. An exponential probe to discover a tight window mirrors the original unknown-length technique, but a direct binary search over the whole supplied array meets the same bounds and is simpler.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n) comparisons.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def search(self, arr: List[int], target: int) -> int:\n lo, hi = 0, len(arr) - 1\n while lo <= hi:\n mid = (lo + hi) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n lo = mid + 1\n else:\n hi = mid - 1\n return -1\n```\n", "starter": {"go": "package main\n\n// This is the ArrayReader's API interface.\n// You should not implement it, or speculate about its implementation\n// type ArrayReader struct { }\n// func (r *ArrayReader) Get(index int) int\n// Get(index) returns the element at index, or 2147483647 if out of bounds.\n// The length is hidden: probe exponentially, then binary search.\n// The judge counts your calls: at most 10000 per test case.\nfunc Search(reader *ArrayReader, target int) int {\n return 0\n}", "python": "# The ArrayReader API is provided by the judge as `reader`.\n# You should not implement it, or speculate about its implementation\n# class ArrayReader:\n# def get(self, index: int) -> int:\n# ...\n# get(index) returns the element at index, or 2147483647 if out of bounds.\n# The length is hidden: probe exponentially, then binary search.\n# The judge counts your calls: at most 10000 per test case.\nfrom typing import List\nclass Solution:\n def search(self, reader: 'ArrayReader', target: int) -> int:\n return 0\n", "cpp": "/**\n * // This is the ArrayReader's API interface.\n * // You should not implement it, or speculate about its implementation\n * class ArrayReader {\n * public:\n * int get(int index);\n * };\n * // get(index) returns the element at index, or 2147483647 if out of bounds.\n * // The length is hidden: probe exponentially, then binary search.\n * // The judge counts your calls: at most 10000 per test case.\n */\nclass Solution {\npublic:\n int search(ArrayReader& reader, int target) {\n return 0;\n }\n};"}, "fn": "search", "params": [{"name": "secret", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[-1,0,3,5,9,12]", "9"], ["[-1,0,3,5,9,12]", "2"], ["[1,2,3,4,5]", "1"], ["[1]", "1"], ["[1]", "2"], ["[1,2]", "2"], ["[1,2]", "0"], ["[1,3,5,7,9]", "7"], ["[1,3,5,7,9]", "8"], ["[-5,-3,0,2,8]", "-3"], ["[-5,-3,0,2,8]", "8"], ["[-5,-3,0,2,8]", "-6"], ["[2,4,6,8,10,12,14]", "14"], ["[2,4,6,8,10,12,14]", "1"], ["[0,1,2,3,4,5,6,7,8,9]", "5"], ["[0,1,2,3,4,5,6,7,8,9]", "10"], ["[-10,-5,0,5,10]", "0"], ["[1,10,100,1000,10000]", "100"], ["[1,10,100,1000,10000]", "999"], ["[5,10,15,20,25,30]", "5"], ["[5,10,15,20,25,30]", "30"], ["[5,10,15,20,25,30]", "22"], ["[-100,-50,0,50,100]", "-100"], ["[-100,-50,0,50,100]", "100"], ["[1,2,3,4,5,6,7,8,9,10,11,12]", "6"], ["[1,2,3,4,5,6,7,8,9,10,11,12]", "13"], ["[0]", "0"], ["[0]", "1"], ["@javascript:JSON.stringify([...Array(10000).keys()].map(i=>i*2))", "19998"], ["@javascript:JSON.stringify([...Array(10000).keys()].map(i=>i*2+1))", "20000"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "188", "slug": "search-in-rotated-sorted-array-ii", "id": 188, "title": "Search in Rotated Sorted Array II", "difficulty": "Medium", "category": "binary-search", "link": "https://leetcode.com/problems/search-in-rotated-sorted-array-ii/", "examples": [{"input": "nums = [2,5,6,0,0,1,2], target = 0", "output": "true"}, {"input": "nums = [2,5,6,0,0,1,2], target = 3", "output": "false"}], "hints": ["Binary search with duplicate handling: when nums[lo]==nums[mid]==nums[hi], shrink both ends."], "statement": "Start from an integer list `nums` arranged in nondecreasing order; repeats are allowed.\n\nAhead of your call, the list is turned at some hidden cut point `k` (`0 <= k < nums.length`), yielding `[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]` (0-indexed). As an illustration, `[0,1,2,4,4,4,5,6,6,7]` cut at position `5` turns into `[4,5,6,6,7,0,1,2,4,4]`.\n\nTaking the turned list `nums` plus an integer `target`, state whether `target` shows up: answer `true` when it does and `false` otherwise.\n\nTry to hold the total number of operations down as far as you can.\n\n**Constraints:**\n- `1 <= nums.length <= 5000`\n- `-10^4 <= nums[i] <= 10^4`\n- `nums` is guaranteed to be rotated at some pivot\n- `-10^4 <= target <= 10^4`\n", "solution": "## Approach\n\nBinary search on a rotated array with duplicates. When `nums[lo] == nums[mid] == nums[hi]`, shrink both ends. Otherwise decide which half is sorted and narrow the search.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) worst case with many duplicates, O(log n) average\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def search(self, nums: List[int], target: int) -> bool:\n lo, hi = 0, len(nums) - 1\n while lo <= hi:\n mid = (lo + hi) // 2\n if nums[mid] == target:\n return True\n if nums[lo] == nums[mid] == nums[hi]:\n lo += 1\n hi -= 1\n continue\n if nums[lo] <= nums[mid]:\n if nums[lo] <= target < nums[mid]:\n hi = mid - 1\n else:\n lo = mid + 1\n else:\n if nums[mid] < target <= nums[hi]:\n lo = mid + 1\n else:\n hi = mid - 1\n return False\n```\n", "starter": {"go": "package main\n\nfunc Search(nums []int, target int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def search(self, nums: List[int], target: int) -> bool:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool search(vector<int>& nums, int target) {\n \n }\n};"}, "fn": "search", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "boolean", "tests": [["[2,5,6,0,0,1,2]", "0"], ["[2,5,6,0,0,1,2]", "3"], ["[1,0,1,1,1]", "0"], ["[1]", "0"], ["[1]", "1"], ["[1,1,1,1,1,1,1,1,1,13]", "13"], ["[1,3,1,1,1]", "3"], ["[3,1]", "1"], ["[1,1,3]", "3"], ["[2,2,2,0,2,2]", "0"], ["[1,1,1,1,1,1,1,1,1,1]", "2"], ["[-1]", "-1"], ["[0,0]", "0"], ["[0,0]", "1"], ["[2,3,3,1,1,2]", "3"], ["[2,3,3,1,1,2]", "4"], ["[4,4,5,6,1,2,4]", "1"], ["[4,4,5,6,1,2,4]", "5"], ["[4,4,5,6,1,2,4]", "3"], ["[0,1,1,1,0,0]", "1"], ["[0,1,1,1,0,0]", "-1"], ["[-2,-2,-1,0,-3,-3]", "-3"], ["[-2,-2,-1,0,-3,-3]", "0"], ["[-2,-2,-1,0,-3,-3]", "1"], ["[10000,-10000,-10000,0,10000]", "-10000"], ["[10000,-10000,-10000,0,10000]", "9999"], ["[7,7,7,8,9,7]", "9"], ["[7,7,7,8,9,7]", "6"], ["[5,1,2,2,3,4,5,5]", "4"], ["[5,1,2,2,3,4,5,5]", "6"]], "expected": [true, false, true, false, true, true, true, true, true, true, false, true, true, false, true, false, true, true, false, true, false, true, true, false, true, false, true, false, true, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "8", "slug": "search-in-rotated-sorted-array", "id": 8, "title": "Search in Rotated Sorted Array", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/search-in-rotated-sorted-array/", "examples": [{"input": "nums = [4,5,6,7,0,1,2], target = 0", "output": "4", "explanation": "Target 0 is at index 4 in the rotated array."}, {"input": "nums = [4,5,6,7,0,1,2], target = 3", "output": "-1", "explanation": "Target 3 is not present in the rotated array."}], "hints": ["Use modified binary search to determine which half is sorted and decide where to continue the search."], "statement": "You receive an integer list `nums` that started out sorted upward with no repeats and was then possibly turned at some pivot, plus an integer `target`.\n\nLocate `target` inside `nums` and give back its position. When `target` never appears, give back -1 instead.\n\n**Constraints:**\n\n- 1 \u2264 nums.length \u2264 5000\n- -10^4 \u2264 nums[i] \u2264 10^4\n- All values of nums are unique.\n- nums is an ascending array that is possibly rotated.\n- -10^4 \u2264 target \u2264 10^4\n", "solution": "## Approach\n\nModified binary search: determine which half of the array is sorted, then check if the target lies in that half to decide which side to search next.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def search(self, nums: List[int], target: int) -> int:\n l, r = 0, len(nums) - 1\n while l <= r:\n m = (l + r) // 2\n if nums[m] == target:\n return m\n if nums[l] <= nums[m]:\n if nums[l] <= target < nums[m]:\n r = m - 1\n else:\n l = m + 1\n else:\n if nums[m] < target <= nums[r]:\n l = m + 1\n else:\n r = m - 1\n return -1\n```\n", "starter": {"go": "package main\n\nfunc Search(nums []int, target int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def search(self, nums: List[int], target: int) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int search(vector<int>& nums, int target) {\n return -1;\n }\n};"}, "fn": "search", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[4,5,6,7,0,1,2]", "0"], ["[4,5,6,7,0,1,2]", "3"], ["[1]", "0"], ["[1,3]", "3"], ["[6,7,8,1,2,3,4,5]", "2"], ["[6,7,8,1,2,3,4,5]", "9"], ["[5,1,3]", "3"], ["[5,1,3]", "5"], ["[5,1,3]", "0"], ["[1,2,3,4,5,6,7]", "4"], ["@javascript:JSON.stringify(Array.from({length:5000},(_,i)=>(i+2500)%5000))", "2500"], ["[-1]", "-1"], ["[-10000]", "10000"], ["[3,1]", "3"], ["[3,1]", "2"], ["[2,3,4,5,1]", "1"], ["[2,3,4,5,1]", "4"], ["[2,3,4,5,1]", "-2"], ["[0,4,9,-8,-3]", "-8"], ["[0,4,9,-8,-3]", "9"], ["[-3,-1,2,8,-9,-7]", "-7"], ["[-3,-1,2,8,-9,-7]", "7"], ["[10000,-10000,-5000,0,5000]", "10000"], ["[10000,-10000,-5000,0,5000]", "-5000"], ["[7,9,12,15,18,2,4]", "18"], ["[7,9,12,15,18,2,4]", "2"], ["[-5,-2,1,6,11]", "-5"], ["[-5,-2,1,6,11]", "12"], ["[30,40,50,5,10,20]", "20"], ["[30,40,50,5,10,20]", "35"]], "expected": [4, -1, -1, 1, 4, -1, 2, 0, -1, 3, 0, 0, -1, 0, -1, 4, 2, -1, 3, 2, 5, -1, 0, 2, 4, 5, 0, -1, 5, -1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "184", "slug": "search-insert-position", "id": 184, "title": "Search Insert Position", "difficulty": "Easy", "category": "binary-search", "link": "https://leetcode.com/problems/search-insert-position/", "examples": [{"input": "nums = [1,3,5,6], target = 5", "output": "2", "explanation": "Target 5 is found at index 2."}, {"input": "nums = [1,3,5,6], target = 2", "output": "1", "explanation": "Target 2 is not present; inserting it keeps order at index 1."}, {"input": "nums = [1,3,5,6], target = 7", "output": "4", "explanation": "Target 7 is larger than all elements; it would be appended at index 4."}], "hints": ["Use binary search for the lower bound: the first index with nums[i] >= target.", "Keep an inclusive interval with left <= right and move left to mid+1 when nums[mid] < target.", "Compute the midpoint as left + (right - left) / 2 to avoid overflow."], "statement": "You are shown `nums`, a list of different integers already running from smallest to largest, plus a separate integer `target`.\n\nGive back the position of `target` when it is present. When it is absent, give back the position where `target` would sit so that the ordering stays intact.\n\nYour method must run in `O(log n)` time.\n\n**Constraints:**\n\n- `1 <= nums.length <= 10^4`\n- `-10^4 <= nums[i], target <= 10^4`\n- `nums` contains distinct values sorted in ascending order.\n", "solution": "## Approach\n\nBinary-search the lower bound: keep an inclusive interval and move past the middle whenever it is smaller than the target. When the loop ends, `left` is the first index with value `>= target`, which is either the target's index or its insertion position.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def searchInsert(self, nums: List[int], target: int) -> int:\n left, right = 0, len(nums) - 1\n while left <= right:\n middle = left + (right - left) // 2\n if nums[middle] == target:\n return middle\n if nums[middle] < target:\n left = middle + 1\n else:\n right = middle - 1\n return left\n```\n", "starter": {"go": "package main\n\nfunc SearchInsert(nums []int, target int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def searchInsert(self, nums: List[int], target: int) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int searchInsert(vector<int>& nums, int target) {\n return 0;\n }\n};"}, "fn": "searchInsert", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[1,3,5,6]", "5"], ["[1,3,5,6]", "2"], ["[1,3,5,6]", "7"], ["[1,3,5,6]", "0"], ["[1]", "1"], ["[1]", "0"], ["[1]", "2"], ["[1,3]", "2"], ["[-10,-5,0,5,10]", "-5"], ["[-10,-5,0,5,10]", "-7"], ["[-10,-5,0,5,10]", "11"], ["[-10,-5,0,5,10]", "-11"], ["[1,2,3,4,5,6,7,8,9,10]", "6"], ["[2,4,6,8,10]", "5"], ["[-10000,10000]", "0"], ["[1,3,5,6]", "3"], ["[-10000]", "-10000"], ["[-10000]", "10000"], ["[10000]", "-10000"], ["[-9,-3,4,12]", "-9"], ["[-9,-3,4,12]", "-6"], ["[-9,-3,4,12]", "4"], ["[-9,-3,4,12]", "10"], ["[-9,-3,4,12]", "12"], ["[-8,-4,-2,-1]", "0"], ["[0,2,4,6,8]", "0"], ["[0,2,4,6,8]", "1"], ["[0,2,4,6,8]", "8"], ["[0,2,4,6,8]", "9"], ["[-10000,-9999,9999,10000]", "9998"]], "expected": [2, 1, 4, 0, 0, 0, 1, 1, 1, 1, 5, 0, 5, 2, 1, 1, 0, 1, 0, 0, 1, 2, 3, 3, 4, 0, 1, 4, 5, 2], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "690", "slug": "second-minimum-node-in-a-binary-tree", "id": 690, "title": "Second Minimum Node in a Binary Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/second-minimum-node-in-a-binary-tree/", "examples": [{"input": "root = [2,2,5,null,null,5,7]", "output": "5", "explanation": "The smallest value is 2 and the next distinct value present is 5."}, {"input": "root = [2,2,2]", "output": "-1", "explanation": "Every node stores 2, so no second distinct value exists."}, {"input": "root = [5,8,5]", "output": "8", "explanation": "Values present are 5 and 8; the second minimum is 8."}], "hints": ["The root always carries the global minimum in this special tree.", "Walk the tree and track the smallest value strictly larger than the root value.", "Return -1 when every node equals the root value."], "statement": "Each node of the given binary tree holds an integer, has either zero or two children, and every child value is at least as large as its parent value.\n\nFind the second smallest distinct value appearing in the tree. If all nodes share the same value, return `-1`.\n\n**Constraints:**\n- The tree has between 1 and 25 nodes.\n- All values lie in `[1, 2^31 - 1]`.\n- Each interior node has exactly two children.\n", "solution": "## Approach\n\nThe root stores the minimum. Traverse the whole tree and keep the smallest value that is strictly greater than the root value. A stack or queue walk suffices; if no such value appears, answer `-1`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one visit per node.\n- **Space Complexity:** O(h) for the traversal stack.\n\n## Implementation\n\n```python\nclass Solution:\n def findSecondMinimumValue(self, root) -> int:\n first = root.val\n second = float(\"inf\")\n stack = [root]\n while stack:\n n = stack.pop()\n if not n:\n continue\n if first < n.val < second:\n second = n.val\n if n.left:\n stack.append(n.left)\n if n.right:\n stack.append(n.right)\n return -1 if second == float(\"inf\") else second\n```\n", "starter": {"go": "package main\n\n// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\n\nfunc FindSecondMinimumValue(root *TreeNode) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def findSecondMinimumValue(self, root) -> int:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findSecondMinimumValue(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "findSecondMinimumValue", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int", "tests": [["[2,2,5,null,null,5,7]"], ["[2,2,2]"], ["[5,8,5]"], ["[1,1,3,1,1,3,4,3,1,1,1,3,8,4,8,3,3,1,6,2,1]"], ["[1]"], ["[1,1,2]"], ["[1,2,3]"], ["[3,3,3,null,null,3,4]"], ["[5,8,5,null,null,5,9]"], ["[2,2,5,2,null,5,7]"], ["[1,1,1,1,1,1,1]"], ["[10,10,20]"], ["[10,20,10]"], ["[4,4,7,null,null,7,9]"], ["[6,6,6,6,6,8]"], ["[1,1,2,1,1,null,2]"], ["[2,2,2147483647]"], ["[1,2,null,3]"], ["[7,7,10,7,null,10,12]"], ["[5,5,6]"], ["[5,6,5]"], ["[9,9,10,9,9,10,11]"], ["[1,1,100]"], ["[3,5,3]"], ["[11,11,12,null,null,12,15]"], ["[2,3,2]"], ["[8,8,9,null,null,9,10]"], ["[4,4,5,4,null,5,6]"]], "expected": [5, -1, 8, 2, -1, 2, 2, 4, 8, 5, -1, 20, 20, 7, 8, 2, 2147483647, 2, 10, 6, 6, 10, 100, 5, 12, 3, 9, 5], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "420", "slug": "self-crossing", "id": 420, "title": "Self Crossing", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/self-crossing/", "examples": [{"input": "distance = [2,1,1,2]", "output": "true", "explanation": "The fourth leg lands back on the first leg's line."}, {"input": "distance = [1,2,3,4]", "output": "false", "explanation": "The spiral keeps widening, so no legs meet."}, {"input": "distance = [1,1,1,2,1]", "output": "true", "explanation": "A later leg slices through an earlier leg in the compact spiral."}], "hints": ["Only the last few legs can meet the current one, so check local patterns at i >= 3, 4, 5.", "Compare lengths: a leg crosses when it reaches past the line two steps back while the middle leg overlaps."], "statement": "Starting at the origin of a grid, you walk in a repeating cycle of directions: first upward (north), then left (west), then downward (south), then right (east), then upward again, and so on. The array `distance` tells how far each leg reaches: leg 0 goes up by `distance[0]`, leg 1 goes left by `distance[1]`, leg 2 goes down by `distance[2]`, and the pattern continues counter-clockwise.\n\nAs the path grows it may touch or cross its own earlier trail. Return `true` when any such contact happens and `false` when the whole walk stays clear of itself.\n\n**Constraints:**\n- `1 <= distance.length <= 10^5`\n- `1 <= distance[i] <= 10^5`\n", "solution": "## Approach\n\nA new leg can only collide with the few legs drawn just before it, because older legs lie too far away in the expanding spiral. Scanning once and testing three local shapes suffices: a direct crossing four legs back, a touching overlap five legs back when two parallel legs match, and a slanted overlap six legs back where the spiral tightens. If none of these patterns fires, the walk never meets itself.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one constant-time check per leg.\n- **Space Complexity:** O(1) extra space.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def isSelfCrossing(self, distance: List[int]) -> bool:\n d = distance\n n = len(d)\n for i in range(3, n):\n if d[i] >= d[i - 2] and d[i - 1] <= d[i - 3]:\n return True\n if i >= 4 and d[i - 1] == d[i - 3] and d[i] + d[i - 4] >= d[i - 2]:\n return True\n if (i >= 5 and d[i - 2] >= d[i - 4]\n and d[i] + d[i - 4] >= d[i - 2]\n and d[i - 1] + d[i - 5] >= d[i - 3]\n and d[i - 1] <= d[i - 3]\n and d[i - 3] <= d[i - 1] + d[i - 5]\n and d[i - 2] <= d[i] + d[i - 4]):\n return True\n return False\n```\n", "starter": {"go": "package main\n\nfunc IsSelfCrossing(distance []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def isSelfCrossing(self, distance: List[int]) -> bool:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isSelfCrossing(vector<int>& distance) {\n return false;\n }\n};"}, "fn": "isSelfCrossing", "params": [{"name": "distance", "type": "int_array"}], "outputType": "boolean", "tests": [["[2,1,1,2]"], ["[1,2,3,4]"], ["[1,1,1,2,1]"], ["[1]"], ["[1,1]"], ["[1,2,3]"], ["[1,1,1,1]"], ["[1,1,2,1,1]"], ["[2,2,2,2]"], ["[3,3,3,2,1,1]"], ["[1,2,3,4,5,6]"], ["[4,4,4,4,4]"], ["[1,1,1,1,1,1]"], ["[2,1,1,1]"], ["[1,2,4,4,2,1]"], ["[3,1,1,2,1,1]"], ["[1,2,3,4,5,4,3,2,1]"], ["[5,5,5,5,10]"], ["[1,3,2,2]"], ["[1,1,2,2,1,1]"], ["[10,1,1,10]"], ["[1,2,3,4,4,3,2,1]"], ["[6,5,4,3,2,1]"], ["[1,1,1,2,1,1]"], ["[2,3,1,1]"], ["[3,3,4,2,2]"], ["[1,2,2,1,1]"]], "expected": [true, false, true, false, false, false, true, true, true, false, false, true, true, true, false, true, true, true, false, true, true, true, false, true, false, false, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "735", "slug": "self-dividing-numbers", "id": 735, "title": "Self Dividing Numbers", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/self-dividing-numbers/", "examples": [{"input": "left = 1, right = 22", "output": "[1,2,3,4,5,6,7,8,9,11,12,15,22]", "explanation": "Values with a zero digit or a non-dividing digit are left out."}, {"input": "left = 47, right = 85", "output": "[48,55,66,77]"}, {"input": "left = 1, right = 1", "output": "[1]"}], "hints": ["Test each candidate by repeatedly taking x % 10 as the current digit and x / 10 as the remainder.", "Reject immediately on a zero digit; otherwise require num % digit == 0 for every digit.", "The interval holds at most 10000 values, so a direct scan is fast enough."], "statement": "A positive integer is called self-dividing when every one of its decimal digits is non-zero and the number is divisible by each of those digits. For example, 128 divides evenly by 1, 2 and 8.\n\nGiven two bounds `left` and `right` with `left <= right`, collect every self-dividing number in that closed interval and return them in increasing order.\n\n**Constraints:**\n- `1 <= left <= right <= 10000`\n", "solution": "## Approach\n\nIterate from `left` to `right` and keep the values whose digits all divide the value. Checking one value means peeling off decimal digits with modulo and division: a zero digit fails at once, and any digit that does not divide the original value fails too.\n\n## Complexity Analysis\n\n- **Time Complexity:** O((right - left + 1) * d), where d is the digit count (at most 5 here).\n- **Space Complexity:** O(1) besides the answer list.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def selfDividingNumbers(self, left: int, right: int) -> List[int]:\n ans = []\n for x in range(left, right + 1):\n t = x\n good = True\n while t > 0:\n d = t % 10\n if d == 0 or x % d != 0:\n good = False\n break\n t //= 10\n if good:\n ans.append(x)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SelfDividingNumbers(left int, right int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def selfDividingNumbers(self, left: int, right: int) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> selfDividingNumbers(int left, int right) {\n return {};\n }\n};"}, "fn": "selfDividingNumbers", "params": [{"name": "left", "type": "int"}, {"name": "right", "type": "int"}], "outputType": "int_list", "tests": [["1", "22"], ["47", "85"], ["1", "1"], ["2", "2"], ["10", "15"], ["1", "100"], ["100", "130"], ["1", "1000"], ["20", "30"], ["11", "13"], ["100", "120"], ["500", "550"], ["1", "10"], ["9", "9"], ["12", "12"], ["128", "128"], ["101", "122"], ["200", "220"], ["1", "50"], ["66", "77"], ["90", "100"], ["111", "120"], ["212", "222"], ["300", "330"], ["1000", "1010"], ["40", "60"], ["500", "520"], ["7", "21"]], "expected": [[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22], [48, 55, 66, 77], [1], [2], [11, 12, 15], [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22, 24, 33, 36, 44, 48, 55, 66, 77, 88, 99], [111, 112, 115, 122, 124, 126, 128], [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22, 24, 33, 36, 44, 48, 55, 66, 77, 88, 99, 111, 112, 115, 122, 124, 126, 128, 132, 135, 144, 155, 162, 168, 175, 184, 212, 216, 222, 224, 244, 248, 264, 288, 312, 315, 324, 333, 336, 366, 384, 396, 412, 424, 432, 444, 448, 488, 515, 555, 612, 624, 636, 648, 666, 672, 728, 735, 777, 784, 816, 824, 848, 864, 888, 936, 999], [22, 24], [11, 12], [111, 112, 115], [515], [1, 2, 3, 4, 5, 6, 7, 8, 9], [9], [12], [128], [111, 112, 115, 122], [212, 216], [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22, 24, 33, 36, 44, 48], [66, 77], [99], [111, 112, 115], [212, 216, 222], [312, 315, 324], [], [44, 48, 55], [515], [7, 8, 9, 11, 12, 15]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "489", "slug": "sentence-screen-fitting", "id": 489, "title": "Sentence Screen Fitting", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/sentence-screen-fitting/", "examples": [{"input": "sentence = [\"hello\",\"world\"], rows = 2, cols = 8", "output": "1", "explanation": "Each row holds one word plus trailing spaces, fitting the sentence once."}, {"input": "sentence = [\"a\",\"bcd\",\"e\"], rows = 3, cols = 6", "output": "2", "explanation": "Rows pack as a-bcd-e twice with the given width."}, {"input": "sentence = [\"i\",\"had\",\"apple\",\"pie\"], rows = 4, cols = 5", "output": "1", "explanation": "Four narrow rows together spell the sentence once."}], "hints": ["Join the sentence with single spaces plus a trailing space to form one repeating cycle.", "Advance a cursor by cols per row; when it lands mid-word, back up to the word start.", "Total fitted sentences equal the cursor position divided by the cycle length."], "statement": "A screen has `rows` rows and `cols` columns. Words from `sentence` are written left to right, top to bottom, in order, repeating the sentence as needed. A single space separates consecutive words, words never break across lines, and trailing spaces at a row end do not count against the width.\n\nFor example, with `cols = 8` the row `hello___` (hello plus three spaces) is fine, but `hello_w` would overflow.\n\nCount how many complete copies of `sentence` fit on the whole screen.\n\n**Constraints:**\n- `1 <= sentence.length <= 100`\n- `1 <= sentence[i].length <= 10`\n- Words hold lowercase letters.\n- `1 <= rows, cols <= 20000`\n- Every word fits alone in a row (`sentence[i].length <= cols`).\n", "solution": "## Approach\n\nGlue the words with single spaces and one trailing space into a single cycle string. A cursor counts how many characters of that infinite repetition have been consumed. Each row jumps forward by cols: landing on a space means the next word starts cleanly, while landing inside a word rewinds to its start. After all rows, dividing the cursor by the cycle length counts complete sentences.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(rows + total sentence characters).\n- **Space Complexity:** O(total sentence characters).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def wordsTyping(self, sentence: List[str], rows: int, cols: int) -> int:\n s = \" \".join(sentence) + \" \"\n L = len(s)\n pos = 0\n for _ in range(rows):\n pos += cols\n if s[pos % L] == \" \":\n pos += 1\n else:\n while pos > 0 and s[(pos - 1) % L] != \" \":\n pos -= 1\n return pos // L\n```\n", "starter": {"go": "package main\n\nfunc WordsTyping(sentence []string, rows int, cols int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def wordsTyping(self, sentence: List[str], rows: int, cols: int) -> int:\n return 0", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int wordsTyping(vector<string>& sentence, int rows, int cols) {\n return 0;\n }\n};"}, "fn": "wordsTyping", "params": [{"name": "sentence", "type": "string_array"}, {"name": "rows", "type": "int"}, {"name": "cols", "type": "int"}], "outputType": "int", "tests": [["['hello', 'world']", "2", "8"], ["['a', 'bcd', 'e']", "3", "6"], ["['i', 'had', 'apple', 'pie']", "4", "5"], ["['a']", "1", "1"], ["['a']", "2", "2"], ["['ab', 'cd']", "1", "5"], ["['ab', 'cd']", "2", "2"], ["['hello']", "10", "5"], ["['a', 'b', 'c']", "3", "3"], ["['a', 'b', 'c']", "5", "5"], ["['try', 'to', 'be', 'better']", "5", "6"], ["['fizz', 'buzz']", "10", "10"], ["['a', 'bb', 'ccc']", "4", "4"], ["['hello', 'world', 'foo']", "3", "11"], ["['a']", "100", "1"], ["['abc', 'de', 'f']", "7", "7"], ["['one']", "1", "3"], ["['one', 'two']", "2", "7"], ["['x', 'y', 'z']", "10", "1"], ["['longword']", "3", "8"], ["['a', 'b']", "100", "100"], ["['sentence', 'screen', 'fitting']", "5", "10"], ["['i', 'love', 'cojudge']", "6", "8"], ["['ab', 'cde', 'f']", "8", "6"], ["['hello', 'world']", "1", "11"], ["['a', 'bcd', 'e']", "4", "6"], ["['apple', 'pie']", "2", "9"], ["['aa', 'bb', 'cc']", "6", "6"], ["['q', 'w', 'e', 'r', 't']", "9", "4"], ["['fit', 'the', 'screen']", "10", "8"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "743", "slug": "sentence-similarity-ii", "id": 743, "title": "Sentence Similarity II", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/sentence-similarity-ii/", "examples": [{"input": "sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"good\"],[\"fine\",\"good\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]", "output": "true", "explanation": "great reaches fine via good; the other positions match directly."}, {"input": "sentence1 = [\"great\"], sentence2 = [\"fine\"], similarPairs = [[\"great\",\"good\"]]", "output": "false"}, {"input": "sentence1 = [\"a\",\"b\"], sentence2 = [\"a\",\"b\"], similarPairs = []", "output": "true"}], "hints": ["Model the pairs as an undirected graph (or union-find sets) over words.", "Union the two words of every listed pair first, then test each sentence position.", "Equal words pass at once; otherwise both words must land in the same connected set."], "statement": "Two sentences are lists of words. They are similar when they hold the same number of words and every pair of words at matching positions can be linked, where linkage now chains through the given pairs:\n\n- Every word links to itself.\n- Each listed pair links its two words in both directions.\n- Linkage is transitive: when `a` links to `b` and `b` links to `c`, then `a` links to `c`.\n\nGiven `sentence1`, `sentence2` and `similarPairs` (each entry holds two words), decide whether the sentences are similar under this chaining rule. Note that two words sharing a group match even if no direct pair names them together.\n\n**Constraints:**\n- `1 <= sentence1.length, sentence2.length <= 1000`\n- `0 <= similarPairs.length <= 2000`\n- Words hold lowercase letters.\n", "solution": "## Approach\n\nTreat every listed pair as an undirected link between two words and merge them with a disjoint-set (union-find) structure. After all unions, each word belongs to exactly one group. Sentences of different lengths fail at once; otherwise each position passes when the words match or their group representatives agree.\n\n## Complexity Analysis\n\n- **Time Complexity:** O((w + p) * a), where w is the sentence length, p the pair count, and a the near-constant union-find cost.\n- **Space Complexity:** O(v) for the distinct words v.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def areSentencesSimilarTwo(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:\n if len(sentence1) != len(sentence2):\n return False\n par = {}\n def find(x):\n par.setdefault(x, x)\n while par[x] != x:\n par[x] = par[par[x]]\n x = par[x]\n return x\n def union(a, b):\n par[find(a)] = find(b)\n for a, b in similarPairs:\n union(a, b)\n for a, b in zip(sentence1, sentence2):\n if a != b and find(a) != find(b):\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc AreSentencesSimilarTwo(sentence1 []string, sentence2 []string, similarPairs [][]string) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def areSentencesSimilarTwo(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:\n return False\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool areSentencesSimilarTwo(vector<string>& sentence1, vector<string>& sentence2, vector<vector<string>>& similarPairs) {\n return false;\n }\n};"}, "fn": "areSentencesSimilarTwo", "params": [{"name": "sentence1", "type": "string_array"}, {"name": "sentence2", "type": "string_array"}, {"name": "similarPairs", "type": "string_list_2d"}], "outputType": "boolean", "tests": [["[\"great\",\"acting\",\"skills\"]", "[\"fine\",\"drama\",\"talent\"]", "[[\"great\",\"good\"],[\"fine\",\"good\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]"], ["[\"great\"]", "[\"fine\"]", "[[\"great\",\"good\"]]"], ["[\"a\",\"b\"]", "[\"a\",\"b\"]", "[]"], ["[\"a\",\"b\",\"c\"]", "[\"a\",\"c\",\"b\"]", "[[\"b\",\"c\"]]"], ["[\"a\",\"b\",\"c\"]", "[\"x\",\"y\",\"z\"]", "[[\"a\",\"x\"],[\"x\",\"m\"],[\"m\",\"y\"],[\"y\",\"b\"]]"], ["[\"one\",\"two\"]", "[\"three\",\"four\"]", "[[\"one\",\"three\"],[\"two\",\"four\"]]"], ["[\"a\",\"b\"]", "[\"c\",\"d\"]", "[[\"a\",\"c\"],[\"b\",\"e\"]]"], ["[\"x\",\"y\"]", "[\"y\",\"x\"]", "[[\"x\",\"y\"]]"], ["[\"p\",\"q\",\"r\"]", "[\"p\",\"s\",\"r\"]", "[[\"q\",\"s\"],[\"s\",\"t\"],[\"t\",\"q\"]]"], ["[\"m\",\"n\",\"o\"]", "[\"m\",\"n\",\"p\"]", "[[\"o\",\"n\"]]"], ["[\"a\"]", "[\"z\"]", "[[\"a\",\"b\"],[\"b\",\"c\"],[\"c\",\"d\"],[\"d\",\"z\"]]"], ["[\"a\"]", "[\"z\"]", "[[\"a\",\"b\"],[\"c\",\"d\"]]"], ["[\"dog\",\"cat\",\"fish\"]", "[\"pup\",\"kit\",\"fish\"]", "[[\"dog\",\"pup\"],[\"cat\",\"kit\"]]"], ["[\"i\",\"like\",\"apples\"]", "[\"i\",\"love\",\"oranges\"]", "[[\"like\",\"love\"],[\"apples\",\"oranges\"]]"], ["[\"a\",\"b\"]", "[\"b\",\"a\"]", "[]"], ["[\"aa\",\"bb\",\"cc\"]", "[\"cc\",\"bb\",\"aa\"]", "[[\"aa\",\"cc\"]]"], ["[\"ab\",\"cd\",\"ef\"]", "[\"ab\",\"ef\",\"cd\"]", "[[\"cd\",\"ef\"]]"], ["[\"u\",\"v\",\"w\"]", "[\"u\",\"v\"]", "[[\"w\",\"v\"]]"], ["[\"k\",\"k\",\"k\"]", "[\"l\",\"l\",\"l\"]", "[[\"k\",\"m\"],[\"m\",\"l\"]]"], ["[\"k\",\"k\",\"k\"]", "[\"l\",\"l\",\"m\"]", "[[\"k\",\"l\"]]"], ["[\"an\",\"example\"]", "[\"a\",\"sample\"]", "[[\"an\",\"a\"],[\"example\",\"sample\"]]"], ["[\"a\",\"b\",\"c\",\"d\"]", "[\"e\",\"f\",\"g\",\"h\"]", "[[\"a\",\"e\"],[\"e\",\"b\"],[\"b\",\"f\"],[\"c\",\"g\"],[\"d\",\"h\"]]"], ["[\"x\"]", "[\"x\"]", "[[\"a\",\"b\"],[\"b\",\"c\"],[\"c\",\"a\"]]"], ["[\"sol\",\"luna\"]", "[\"sun\",\"moon\"]", "[[\"sol\",\"sun\"],[\"luna\",\"moon\"],[\"sun\",\"star\"]]"], ["[\"t1\",\"t2\"]", "[\"t3\",\"t4\"]", "[[\"t1\",\"t3\"],[\"t3\",\"t1\"]]"], ["[\"only\"]", "[\"lonely\"]", "[]"], ["[\"a\",\"b\",\"a\",\"b\"]", "[\"b\",\"a\",\"b\",\"a\"]", "[[\"a\",\"b\"]]"], ["[\"q\",\"w\",\"e\",\"r\"]", "[\"q\",\"w\",\"e\",\"t\"]", "[[\"r\",\"s\"],[\"s\",\"t\"],[\"q\",\"r\"]]"]], "expected": [true, false, true, true, false, true, false, true, true, false, true, false, true, true, false, true, true, false, true, false, true, true, true, true, false, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "741", "slug": "sentence-similarity", "id": 741, "title": "Sentence Similarity", "difficulty": "Easy", "category": "hash-table", "link": "https://leetcode.com/problems/sentence-similarity/", "examples": [{"input": "sentence1 = [\"great\",\"acting\",\"skills\"], sentence2 = [\"fine\",\"drama\",\"talent\"], similarPairs = [[\"great\",\"fine\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]", "output": "true", "explanation": "Each position is covered by a listed pair (one of them reversed)."}, {"input": "sentence1 = [\"great\"], sentence2 = [\"great\"], similarPairs = []", "output": "true"}, {"input": "sentence1 = [\"great\"], sentence2 = [\"fine\"], similarPairs = [[\"great\",\"good\"]]", "output": "false"}], "hints": ["Lengths must agree first; different word counts can never be similar.", "Store each listed pair in both directions in a hash set of joined keys.", "Identical words at a position pass without any lookup."], "statement": "Two sentences are lists of words. They are called similar when every pair of words at the same position can be matched, using these rules:\n\n- The sentences must hold the same number of words.\n- A word always matches itself.\n- Otherwise, words `a` and `b` match when the pair `(a, b)` or `(b, a)` appears in the given similarity list. Matching is symmetric but it does not chain: `a` matching `b` and `b` matching `c` does not make `a` match `c`.\n\nGiven `sentence1`, `sentence2` and the list `similarPairs` (each entry holds two words), decide whether the sentences are similar.\n\n**Constraints:**\n- `1 <= sentence1.length, sentence2.length <= 1000`\n- `0 <= similarPairs.length <= 2000`\n- Words hold lowercase letters; each pair holds two words.\n", "solution": "## Approach\n\nFirst reject sentences of different lengths. Then place every listed pair into a hash set twice, once per direction, so lookups treat similarity as symmetric. Finally walk the positions: identical words pass freely, and differing words must appear as a directed key in the set.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(w + p), where w is the sentence length and p the number of pairs.\n- **Space Complexity:** O(p) for the set.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def areSentencesSimilar(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:\n if len(sentence1) != len(sentence2):\n return False\n sim = set()\n for a, b in similarPairs:\n sim.add((a, b))\n sim.add((b, a))\n for a, b in zip(sentence1, sentence2):\n if a != b and (a, b) not in sim:\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc AreSentencesSimilar(sentence1 []string, sentence2 []string, similarPairs [][]string) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def areSentencesSimilar(self, sentence1: List[str], sentence2: List[str], similarPairs: List[List[str]]) -> bool:\n return False\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool areSentencesSimilar(vector<string>& sentence1, vector<string>& sentence2, vector<vector<string>>& similarPairs) {\n return false;\n }\n};"}, "fn": "areSentencesSimilar", "params": [{"name": "sentence1", "type": "string_array"}, {"name": "sentence2", "type": "string_array"}, {"name": "similarPairs", "type": "string_list_2d"}], "outputType": "boolean", "tests": [["[\"great\",\"acting\",\"skills\"]", "[\"fine\",\"drama\",\"talent\"]", "[[\"great\",\"fine\"],[\"drama\",\"acting\"],[\"skills\",\"talent\"]]"], ["[\"great\"]", "[\"great\"]", "[]"], ["[\"great\"]", "[\"fine\"]", "[[\"great\",\"good\"]]"], ["[\"a\",\"b\"]", "[\"a\",\"b\"]", "[]"], ["[\"a\",\"b\"]", "[\"a\",\"c\"]", "[[\"b\",\"c\"]]"], ["[\"a\",\"b\",\"c\"]", "[\"a\",\"b\"]", "[]"], ["[\"one\",\"two\"]", "[\"one\",\"too\"]", "[[\"two\",\"too\"]]"], ["[\"x\",\"y\"]", "[\"y\",\"x\"]", "[[\"x\",\"y\"]]"], ["[\"a\",\"b\",\"c\"]", "[\"d\",\"e\",\"f\"]", "[[\"a\",\"d\"],[\"b\",\"e\"]]"], ["[\"eat\",\"sleep\"]", "[\"dine\",\"rest\"]", "[[\"eat\",\"dine\"],[\"sleep\",\"rest\"]]"], ["[\"a\"]", "[\"b\"]", "[[\"b\",\"a\"]]"], ["[\"ab\",\"cd\"]", "[\"ab\",\"dc\"]", "[[\"cd\",\"dc\"],[\"dc\",\"cd\"]]"], ["[\"p\",\"q\",\"r\"]", "[\"p\",\"q\",\"r\"]", "[[\"a\",\"b\"]]"], ["[\"dog\",\"cat\"]", "[\"dog\",\"dog\"]", "[[\"cat\",\"dog\"]]"], ["[\"i\",\"love\",\"cats\"]", "[\"i\",\"adore\",\"cats\"]", "[[\"love\",\"adore\"]]"], ["[\"a\",\"a\",\"a\"]", "[\"b\",\"b\",\"b\"]", "[[\"a\",\"b\"]]"], ["[\"a\",\"a\",\"a\"]", "[\"b\",\"b\",\"c\"]", "[[\"a\",\"b\"]]"], ["[\"red\",\"blue\"]", "[\"rouge\",\"bleu\"]", "[[\"red\",\"rouge\"]]"], ["[\"same\",\"same\"]", "[\"same\",\"same\"]", "[[\"x\",\"y\"],[\"y\",\"z\"]]"], ["[\"m\",\"n\"]", "[\"n\",\"m\"]", "[]"], ["[\"aa\",\"bb\"]", "[\"bb\",\"aa\"]", "[[\"aa\",\"bb\"]]"], ["[\"hello\",\"world\"]", "[\"hello\",\"there\"]", "[[\"world\",\"there\"]]"], ["[\"a\",\"b\",\"c\",\"d\"]", "[\"w\",\"x\",\"y\",\"z\"]", "[[\"a\",\"w\"],[\"b\",\"x\"],[\"c\",\"y\"],[\"d\",\"z\"]]"], ["[\"a\",\"b\",\"c\",\"d\"]", "[\"w\",\"x\",\"y\",\"z\"]", "[[\"a\",\"w\"],[\"b\",\"x\"],[\"c\",\"y\"]]"], ["[\"sun\",\"moon\"]", "[\"star\",\"moon\"]", "[[\"sun\",\"star\"],[\"star\",\"sun\"]]"], ["[\"one\"]", "[\"one\",\"two\"]", "[[\"one\",\"one\"]]"], ["[\"k\",\"l\",\"m\"]", "[\"k\",\"l\",\"m\"]", "[]"], ["[\"alpha\",\"beta\"]", "[\"gamma\",\"delta\"]", "[[\"alpha\",\"gamma\"],[\"beta\",\"delta\"],[\"alpha\",\"beta\"]]"]], "expected": [true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, false, false, true, false, true, true, true, false, true, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "512", "slug": "sequence-reconstruction", "id": 512, "title": "Sequence Reconstruction", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/sequence-reconstruction/", "examples": [{"input": "nums = [1,2,3], sequences = [[1,2],[1,3]]", "output": "false", "explanation": "Both 1,2,3 and 1,3,2 fit, so the order is not unique."}, {"input": "nums = [1,2,3], sequences = [[1,2],[1,3],[2,3]]", "output": "true", "explanation": "The three pairs force 1 before 2 before 3."}, {"input": "nums = [4,1,5,2,6,3], sequences = [[5,2,6,3],[4,1,5,2]]", "output": "true", "explanation": "Chained pairs fix the full order."}], "hints": ["Turn each adjacent pair in every sequence into a directed edge.", "A breadth-first topological walk must always have exactly one ready node; two choices means not unique.", "The walk must emit exactly nums in order, and every value of nums must appear in sequences."], "statement": "You are given the intended order `nums`, which lists each number from `1` to `n` exactly once, plus a collection `sequences` where each entry is a shorter list that should appear as a subsequence of the true order.\n\nDecide whether `nums` is the only shortest ordering that contains every listed sequence as a subsequence. Return `true` when the reconstruction is uniquely forced to be `nums`, and `false` otherwise. In particular, return `false` when some value never appears, some listed value falls outside `1..n`, or the ordering constraints allow more than one candidate.\n\n**Constraints:**\n- `1 <= nums.length <= 10^4`\n- `nums` is a permutation of `1..n`.\n- `1 <= sequences.length <= 10^4`\n- `0 <= sequences[i].length <= 10^4`\n- Values in `sequences` lie in `1..n` for valid cases.\n", "solution": "## Approach\n\nBuild a directed graph from adjacent pairs inside every sequence, counting incoming edges per value. Then run a topological walk starting from zero-indegree values. If more than one value is ever ready, the order is not unique. If the walk emits values in a different order than `nums`, or some value never appeared in the input, the answer is false. Otherwise the reconstruction matches uniquely.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(V + E), where V is `n` and E is the total number of adjacent pairs across `sequences`.\n- **Space Complexity:** O(V + E) for the graph and indegree table.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import defaultdict, deque\nclass Solution:\n def sequenceReconstruction(self, nums: List[int], sequences: List[List[int]]) -> bool:\n n = len(nums)\n graph = defaultdict(set)\n indeg = defaultdict(int)\n for x in nums:\n indeg[x] = 0\n seen = set()\n for seq in sequences:\n for i, v in enumerate(seq):\n if v < 1 or v > n:\n return False\n seen.add(v)\n if i > 0:\n u = seq[i - 1]\n if u < 1 or u > n:\n return False\n if v not in graph[u]:\n graph[u].add(v)\n indeg[v] += 1\n for x in nums:\n if x not in seen:\n return False\n q = deque([x for x in nums if indeg[x] == 0])\n idx = 0\n while q:\n if len(q) > 1:\n return False\n u = q.popleft()\n if idx >= n or nums[idx] != u:\n return False\n idx += 1\n for v in graph.get(u, []):\n indeg[v] -= 1\n if indeg[v] == 0:\n q.append(v)\n return idx == n\n```\n", "starter": {"go": "package main\n\nfunc SequenceReconstruction(nums []int, sequences [][]int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def sequenceReconstruction(self, nums: List[int], sequences: List[List[int]]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool sequenceReconstruction(vector<int>& nums, vector<vector<int>>& sequences) {\n return false;\n }\n};"}, "fn": "sequenceReconstruction", "params": [{"name": "nums", "type": "int_array"}, {"name": "sequences", "type": "int_array_2d"}], "outputType": "boolean", "tests": [["[1,2,3]", "[[1,2],[1,3]]"], ["[1,2,3]", "[[1,2],[1,3],[2,3]]"], ["[4,1,5,2,6,3]", "[[5,2,6,3],[4,1,5,2]]"], ["[1,2,3]", "[[1,2]]"], ["[1]", "[[1]]"], ["[1]", "[[]]"], ["[1,2]", "[[1,2],[2,1]]"], ["[1,2,3,4]", "[[1,2],[2,3],[3,4]]"], ["[1,2,3,4]", "[[1,2],[3,4]]"], ["[2,1,3]", "[[1,2],[2,3]]"], ["[1,2,3]", "[[1,2],[1,3],[2,3],[1,2,3]]"], ["[1,2,3]", "[[3,2,1]]"], ["[5,3,2,4,1]", "[[5,3],[3,2],[2,4],[4,1]]"], ["[5,3,2,4,1]", "[[5,3],[2,4]]"], ["[1,2,3]", "[[1,2],[2,3],[1,3]]"], ["[1,2]", "[[1],[2]]"], ["[1,2,3]", "[[1,2,3]]"], ["[3,1,2]", "[[3,1],[1,2]]"], ["[1,2,3,4,5]", "[[1,2,3,4,5]]"], ["[3,2,1]", "[[3,2],[2,1]]"], ["[1,3,2]", "[[1,3],[1,2]]"], ["[2,3,1]", "[[2,3],[3,1]]"], ["[1,2]", "[[2,1]]"], ["[1,2,3]", "[[1],[2],[3]]"], ["[4,3,2,1]", "[[4,3],[3,2],[2,1]]"], ["[1,2,3,4]", "[[1,2,3],[2,3,4]]"], ["[1,2,3]", "[[1,2],[3]]"], ["[1,2]", "[[1,3]]"], ["[1,2,3,4,5]", "[[1,2],[2,3],[3,4],[4,5]]"], ["[2,1]", "[[2,1]]"]], "expected": [false, true, true, false, true, false, false, true, false, false, true, false, true, false, true, false, true, true, true, true, false, true, false, false, true, true, false, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "72", "slug": "serialize-and-deserialize-binary-tree", "id": 72, "title": "Serialize and Deserialize Binary Tree", "difficulty": "Hard", "category": "tree", "link": "https://leetcode.com/problems/serialize-and-deserialize-binary-tree/", "examples": [{"input": "root = [1,2,3,null,null,4,5]", "output": "[1,2,3,null,null,4,5]", "explanation": "The tree is serialized and then deserialized back to the original tree."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree serializes to an empty string and deserializes back to null."}], "hints": ["You can use level-order (BFS) traversal for serialization, similar to LeetCode's format.", "For deserialization, use two pointers or a queue to build nodes in level order.", "Alternatively, use preorder traversal with a sentinel marker for null nodes.", "A string like '1,2,#,#,3,4,#,#,5,#,#' using preorder with '#' for null can work well."], "statement": "Turning a data structure into a bit stream so it can be saved to a file or buffer, or sent over a link and rebuilt later on the same or another machine, is called serialization.\n\nBuild a pair of routines for a **binary tree**: one that flattens a tree into a string, and one that rebuilds the starting tree shape from that string. You may pick any string layout you like, as long as a round trip restores the original tree.\n\n**Note on the judge:** The harness reads and displays trees with the same level-order listing style that LeetCode uses. Your internal encoding does not have to copy that style \u2014 feel free to invent your own scheme.\n\n**Constraints:**\n- The number of nodes in the tree is in the range `[0, 10^4]`.\n- `-1000 <= Node.val <= 1000`\n", "solution": "## Approach\n\nUse BFS level-order traversal to serialize the tree into a string with null placeholders, then deserialize by rebuilding nodes level by level from the same format.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import Optional\nclass Codec:\n def serialize(self, root: Optional[TreeNode]) -> str:\n if not root:\n return '[]'\n res = []\n q = [root]\n while q:\n node = q.pop(0)\n if node:\n res.append(str(node.val))\n q.append(node.left)\n q.append(node.right)\n else:\n res.append('null')\n while res and res[-1] == 'null':\n res.pop()\n return '[' + ','.join(res) + ']'\n def deserialize(self, data: str) -> Optional[TreeNode]:\n if data == '[]':\n return None\n vals = data[1:-1].split(',')\n root = TreeNode(int(vals[0]))\n q = [root]\n i = 1\n while q and i < len(vals):\n node = q.pop(0)\n if vals[i] != 'null':\n node.left = TreeNode(int(vals[i]))\n q.append(node.left)\n i += 1\n if i < len(vals) and vals[i] != 'null':\n node.right = TreeNode(int(vals[i]))\n q.append(node.right)\n i += 1\n return root\nclass Solution:\n def solve(self, root: Optional[TreeNode]) -> Optional[TreeNode]:\n ser = Codec()\n deser = Codec()\n return deser.deserialize(ser.serialize(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\ntype Codec struct {\n \n}\n\nfunc (c *Codec) Serialize(root *TreeNode) string {\n \n}\n\nfunc (c *Codec) Deserialize(data string) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Codec:\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\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 Codec {\npublic:\n // Encodes a tree to a single string.\n string serialize(TreeNode* root) {\n \n }\n\n // Decodes your encoded data to tree.\n TreeNode* deserialize(string data) {\n \n }\n};"}, "fn": "solve", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "tree_node", "tests": [["[1,2,3,null,null,4,5]"], ["[]"], ["[1]"], ["[1,2]"], ["[1,null,2]"], ["[1,2,3,4,5,6,7]"], ["[5,4,7,3,null,2,null,-1,null,9]"], ["[1,null,2,null,3,null,4]"], ["[1,2,3,null,4,5,null,6,7]"], ["[1,2,3,null,null,4,5,6,7,8,9,10,11,12,13,14,15]"], ["[0]"], ["[-10,9,8,7,6,null,null,5,4,null,null,3,null,null,null,2,null,-1]"], ["[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]"], ["[1000,900,800,null,null,700,600,null,null,500,400]"], ["[-1000]"], ["[1000]"], ["[0,-1,1]"], ["[1,2,null,3,null,4]"], ["[1,null,2,3]"], ["[8,4,12,2,6,10,14,1,3,5,7,9,11,13,15]"], ["[-5,-10,0,null,-7,-2,3]"], ["[2,2,2,2,null,null,2]"], ["[10,null,-10,null,20,null,-20]"], ["[4,3,null,2,null,1]"], ["[4,null,5,null,6,null,7]"], ["[100,-50,250,-100,0,200,300]"], ["[1,0,2,null,null,null,3]"], ["[7,6,8,5,null,null,9,4,null,null,10]"], ["[-1000,null,1000]"], ["[42,17,42,null,23,42,null]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "517", "slug": "serialize-and-deserialize-bst", "id": 517, "title": "Serialize and Deserialize BST", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/serialize-and-deserialize-bst/", "examples": [{"input": "root = [2,1,3]", "output": "[2,1,3]", "explanation": "The tree is serialized and then deserialized back to the original tree."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree serializes to an empty string and deserializes back to null."}, {"input": "root = [1]", "output": "[1]", "explanation": "A single node round-trips through the codec unchanged."}], "hints": ["A BST's preorder listing alone rebuilds it: the first value is the root, smaller values go left, larger go right.", "Serialize with preorder and no null markers; deserialize by inserting the values back in order.", "Alternatively, any unambiguous scheme works \u2014 the judge only checks that the round trip restores the tree."], "statement": "Turning a data structure into a bit stream so it can be saved to a file or buffer, or sent over a link and rebuilt later on the same or another machine, is called serialization.\n\nBuild a pair of routines for a **binary search tree**: one that flattens a tree into a string, and one that rebuilds the starting tree shape from that string. Because a search tree's preorder listing alone determines its shape, a compact preorder string is sufficient \u2014 but any unambiguous scheme works, since the judge only checks that the round trip restores the original tree.\n\n**Note on the judge:** The harness reads and displays trees with the same level-order listing style that LeetCode uses. Your internal encoding does not have to copy that style \u2014 feel free to invent your own scheme.\n\n**Constraints:**\n- The number of nodes in the tree is in the range `[0, 10^4]`.\n- Values are unique and form a valid binary search tree.\n- `-10^4 <= Node.val <= 10^4`\n", "solution": "## Approach\n\nReuse the classic binary-tree codec: serialize with breadth-first order (or preorder \u2014 either round-trips), and rebuild with a queue. A search tree's preorder alone would also suffice, but the plain BFS scheme needs no ordering assumption and works for every test shape.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is queued once and visited once.\n- **Space Complexity:** O(n) for the queue and the output string.\n\n## Implementation\n\n```python\nfrom collections import deque\nclass Codec:\n def serialize(self, root):\n if not root:\n return \"[]\"\n out = []\n q = deque([root])\n while q:\n node = q.popleft()\n if node is None:\n out.append(\"null\")\n else:\n out.append(str(node.val))\n q.append(node.left)\n q.append(node.right)\n while out and out[-1] == \"null\":\n out.pop()\n return \"[\" + \",\".join(out) + \"]\"\n def deserialize(self, data):\n s = (data or \"\").strip()\n if s in (\"\", \"[]\"):\n return None\n inner = s[1:-1] if s.startswith(\"[\") else s\n toks = [t.strip() for t in inner.split(\",\") if t.strip() != \"\"]\n if not toks or toks[0] in (\"null\", \"None\"):\n return None\n class N:\n def __init__(self, v):\n self.val = int(v)\n self.left = None\n self.right = None\n root = N(toks[0])\n q = deque([root])\n i = 1\n while q and i < len(toks):\n node = q.popleft()\n if toks[i] not in (\"null\", \"None\"):\n node.left = N(toks[i])\n q.append(node.left)\n i += 1\n if i < len(toks) and toks[i] not in (\"null\", \"None\"):\n node.right = N(toks[i])\n q.append(node.right)\n i += 1\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\ntype Codec struct {\n \n}\n\nfunc (c *Codec) Serialize(root *TreeNode) string {\n return \"\"\n}\n\nfunc (c *Codec) Deserialize(data string) *TreeNode {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Codec:\n def serialize(self, root):\n \"\"\"Encodes a tree to a single string.\n \n :type root: TreeNode\n :rtype: str\n \"\"\"\n \n def deserialize(self, data):\n \"\"\"Decodes your encoded data to tree.\n \n :type data: str\n :rtype: TreeNode\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 Codec {\npublic:\n // Encodes a tree to a single string.\n string serialize(TreeNode* root) {\n return \"\";\n }\n\n // Decodes your encoded data to tree.\n TreeNode* deserialize(string data) {\n return nullptr;\n }\n};"}, "fn": "solve", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "tree_node", "tests": [["[2,1,3]"], ["[4,2,7,1,3]"], ["[]"], ["[1]"], ["[3,1,4,null,2]"], ["[5,3,7,2,4,6,8]"], ["[10,5,15]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[2,null,3]"], ["[4,2]"], ["[1,null,2]"], ["[7,3,9,1,5]"], ["[0,-1,1]"], ["[100]"], ["[6,2,8,0,4,7,9,null,null,3,5]"], ["[3,2,null,1]"], ["[5,1,7]"], ["[10,5,15,2,7,12,20]"], ["[1,null,3,null,5]"], ["[50,30,70,20,40,60,80]"], ["[3,1,5,0,2,4,6]"], ["[20,10,30,null,null,25,35]"], ["[5,3,null,2,null,1]"], ["[15,10,20,8,12]"], ["[0]"], ["[-10,-20,0]"], ["[100,50,150,25,75]"], ["[9,4,12,2,6]"], ["[2,1]"], ["[8,4,12,2,6,10,14]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "497", "slug": "serialize-and-deserialize-n-ary-tree", "id": 497, "title": "Serialize and Deserialize N-ary Tree", "difficulty": "Hard", "category": "tree", "link": "https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree/", "examples": [{"input": "data = \"[1,null,3,2,4,null,5,6]\"", "output": "\"[1,null,3,2,4,null,5,6]\"", "explanation": "Parsing and re-serializing preserves the grouping."}, {"input": "data = \"[]\"", "output": "\"[]\"", "explanation": "The empty tree round-trips to itself."}, {"input": "data = \"[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\"", "output": "\"[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]\"", "explanation": "A deeper tree survives the double round-trip unchanged."}], "hints": ["Parse the bracket string by splitting on commas and treating null as a group boundary.", "Rebuild with a queue: each group after a null belongs to the next queued node.", "Serializing is the mirror: emit root, then each node's children group separated by null."], "statement": "An N-ary tree gives every node any number of ordered children (unlike a binary tree, which caps at two). Your job in this adapted task is to round-trip such a tree through a string: take its level-order encoding, rebuild the tree in memory, serialize it again, and hand back the canonical encoding.\n\nThe encoding used here lists values in breadth order with `null` separating each group of siblings. For instance, `[1,null,3,2,4,null,5,6]` describes a root `1` whose children are `3, 2, 4`, where node `3` in turn has children `5, 6`. An empty tree is `[]`.\n\nWrite a function `codecRoundTrip` that accepts one such string `data`, parses it into an N-ary tree, serializes the tree back with the same grouping rule, parses once more and serializes again, then returns the final string. A correct implementation returns the canonical form of its input. Inputs are not guaranteed to be canonical \u2014 trailing empty groups, extra whitespace, or placeholders like `[null]` must all normalize to the same canonical output.\n\n**Constraints:**\n- The node count lies in `[0, 10^4]`.\n- Node values are integers.\n- The input string follows the grouping rule above or is `[]`.\n\nAdaptation: the source defines a `Codec` class over an N-ary `Node` type, which this judge cannot express (only binary `tree_node` exists). It is therefore modeled as `string` in and `string` out with parsing done inside the marker; implement the parse plus serialize logic yourself.\n", "solution": "## Approach\n\nSplit the bracket text on commas and treat `null` as the start of the next node's child group. Rebuild the tree breadth-first with a queue: each dequeued node consumes one group. To serialize, walk nodes in the same breadth order and emit each child group prefixed by `null`, dropping trailing empty groups. Parsing then serializing twice yields a stable canonical string.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the number of tokens in the encoding.\n- **Space Complexity:** O(m) for the token list and the rebuilt tree.\n\n## Implementation\n\n```python\nfrom collections import deque\nclass Solution:\n def codecRoundTrip(self, data: str) -> str:\n def tokens(s):\n s = s.strip()\n if s in ('', '[]'):\n return []\n inner = s[1:-1]\n return [t.strip() for t in inner.split(',') if t.strip() != '']\n def parse(s):\n toks = tokens(s)\n if not toks:\n return None\n if toks[0] in ('null', 'None'):\n return None\n class N:\n def __init__(self, v):\n self.val = int(v)\n self.children = []\n root = N(toks[0])\n q = deque([root])\n i = 1\n while q and i < len(toks):\n node = q.popleft()\n if i < len(toks) and toks[i] == 'null':\n i += 1\n kids = []\n while i < len(toks) and toks[i] != 'null':\n c = N(toks[i])\n kids.append(c)\n q.append(c)\n i += 1\n node.children = kids\n return root\n def serialize(root):\n if root is None:\n return '[]'\n order = []\n q = deque([root])\n while q:\n n = q.popleft()\n order.append(n.children)\n for c in n.children:\n q.append(c)\n last = len(order) - 1\n while last >= 0 and not order[last]:\n last -= 1\n parts = [str(root.val)]\n for g in range(last + 1):\n parts.append('null')\n for c in order[g]:\n parts.append(str(c.val))\n return '[' + ','.join(parts) + ']'\n r1 = parse(data)\n s1 = serialize(r1)\n return serialize(parse(s1))\n```\n", "starter": {"go": "package main\n\nfunc CodecRoundTrip(data string) string {\n \n}", "python": "class Solution:\n def codecRoundTrip(self, data: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string codecRoundTrip(string data) {\n return \"\";\n }\n};"}, "fn": "codecRoundTrip", "params": [{"name": "data", "type": "string"}], "outputType": "string", "tests": [["[1,null,3,2,4,null,5,6]"], ["[]"], ["[1]"], ["[1,null,2]"], ["[1,null,3,2,4,null,5,6]"], ["[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]"], ["[1,null,3,2,4,null,5,6,7]"], ["[5,null,1,2]"], ["[1,null,2,3]"], ["[10,null,1,2,3]"], ["[1,null,2,null,3]"], ["[2,null,1]"], ["[1,null,2,3,4]"], ["[1,null,2,null,3,null,4]"], ["[1,null,2,3,null,4,5,6]"], ["[1,null,2,3,4,5,6,7]"], ["[3,null,1,2]"], ["[1,null,4,5]"], ["[2,null,3,4]"], ["[1,null,5,6,7,null,8,9]"], ["[10]"], ["[0,null,1,2,null,3]"], ["[1,null,2,3,null,4,null,5]"], ["[7,null,3,7,3]"], ["[1,null,2,3,4,null,5,null,6,null,7]"], ["[5,null,6,null,7,null,8]"], ["[1,null,2,3,4,5,null,6]"], ["[9,null,1,2,3,4,5,6,7,8]"], ["[100,null,200,300]"], ["[1,null,2,null,3,null,4,null,5]"], ["[1,null,3,2,4,null,5,6,null]"], ["[1,null,2,null]"], ["[1, null, 3, 2, 4, null, 5, 6]"], ["[null]"], ["[1,null]"], ["[ 1 , null , 2 ]"], ["[1,null,2,3,null]"], ["[1,null,2,null,3,null]"]], "expected": ["[1,null,3,2,4,null,5,6]", "[]", "[1]", "[1,null,2]", "[1,null,3,2,4,null,5,6]", "[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]", "[1,null,3,2,4,null,5,6,7]", "[5,null,1,2]", "[1,null,2,3]", "[10,null,1,2,3]", "[1,null,2,null,3]", "[2,null,1]", "[1,null,2,3,4]", "[1,null,2,null,3,null,4]", "[1,null,2,3,null,4,5,6]", "[1,null,2,3,4,5,6,7]", "[3,null,1,2]", "[1,null,4,5]", "[2,null,3,4]", "[1,null,5,6,7,null,8,9]", "[10]", "[0,null,1,2,null,3]", "[1,null,2,3,null,4,null,5]", "[7,null,3,7,3]", "[1,null,2,3,4,null,5,null,6,null,7]", "[5,null,6,null,7,null,8]", "[1,null,2,3,4,5,null,6]", "[9,null,1,2,3,4,5,6,7,8]", "[100,null,200,300]", "[1,null,2,null,3,null,4,null,5]", "[1,null,3,2,4,null,5,6]", "[1,null,2]", "[1,null,3,2,4,null,5,6]", "[]", "[1]", "[1,null,2]", "[1,null,2,3]", "[1,null,2,null,3]"], "loose": false}
|