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": "149", "slug": "detect-squares", "id": 149, "title": "Detect Squares", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/detect-squares/", "examples": [{"input": "operations = [\"DetectSquares\",\"add\",\"add\",\"add\",\"count\",\"count\"]\npoints = [[0,0],[3,10],[11,2],[3,2],[11,10],[14,8]]", "output": "[1,0]", "explanation": "Only count operations contribute entries to the returned array."}, {"input": "operations = [\"DetectSquares\",\"add\",\"add\",\"add\",\"count\",\"add\",\"count\"]\npoints = [[0,0],[3,10],[11,2],[3,2],[11,10],[11,2],[11,10]]", "output": "[1,2]", "explanation": "The duplicate [11,2] is a distinct choice and doubles the second count."}, {"input": "operations = [\"DetectSquares\",\"count\"]\npoints = [[0,0],[5,5]]", "output": "[0]", "explanation": "The count of squares for the query is [0]."}], "hints": ["This is a function adaptation, not a class problem: skip the first constructor row and append results only for count operations.", "Store the multiplicity of every added point; duplicate points must multiply the number of square choices.", "For a query [x,y], enumerate stored points [otherX,y] on the same row. Their horizontal distance determines the only two possible opposite rows.", "Multiply the frequencies of the three required stored corners for each possible square."], "statement": "Process a stream of point operations and report how many axis-aligned squares can be formed for each query.\n\nAn `add` operation stores one copy of its point. Duplicate points are allowed and are counted as distinct choices. For a `count` operation at `[x, y]`, count all ways to choose three stored points that, together with the query point, form an axis-aligned square with positive side length.\n\n**Portable function adaptation:** Implement `runDetectSquares(operations, points)`. The arrays are aligned by index. The first operation is always `\"DetectSquares\"` with the ignored placeholder point `[0,0]`. Every later operation is `\"add\"` or `\"count\"`, with its point in the same row of `points`. Return an integer array containing one value for each `count` operation, in order. Do not return entries for the constructor or `add` operations, and do not implement a separate design-problem class.\n\n**Constraints:**\n- `operations.length == points.length`\n- `1 <= operations.length <= 3001`\n- `points[i]` contains exactly two integers in the range `0..1000`\n- `operations[0] == \"DetectSquares\"` and `points[0] == [0,0]`\n- Every later operation is `\"add\"` or `\"count\"`\n- Each count result fits in a signed 32-bit integer\n", "solution": "## Approach\n\nStore point multiplicities in maps grouped by y-coordinate. For each `count` query `[x, y]`, enumerate every stored point `[other_x, y]` on the same row; its horizontal distance determines the two possible opposite rows. Multiply the frequencies of the three required stored corners, and append results only for `count` operations as required by the portable function adaptation.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) average for each `add` and O(k) for each `count`, where k is the number of distinct x-coordinates stored on the query row.\n- **Space Complexity:** O(p + q), where p is the number of distinct stored points and q is the number of count results.\n\n## Implementation\n\n```python\nfrom typing import Dict, List\n\n\nclass Solution:\n def runDetectSquares(\n self, operations: List[str], points: List[List[int]]\n ) -> List[int]:\n rows: Dict[int, Dict[int, int]] = {}\n result: List[int] = []\n\n def frequency(y: int, x: int) -> int:\n return rows.get(y, {}).get(x, 0)\n\n for index in range(1, len(operations)):\n x, y = points[index]\n if operations[index] == \"add\":\n row = rows.setdefault(y, {})\n row[x] = row.get(x, 0) + 1\n continue\n\n total = 0\n for other_x, same_row_count in rows.get(y, {}).items():\n if other_x == x:\n continue\n side = other_x - x\n total += (\n same_row_count\n * frequency(y + side, x)\n * frequency(y + side, other_x)\n )\n total += (\n same_row_count\n * frequency(y - side, x)\n * frequency(y - side, other_x)\n )\n result.append(total)\n return result\n```\n", "starter": {"go": "package main\n\nfunc RunDetectSquares(operations []string, points [][]int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runDetectSquares(self, operations: List[str], points: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runDetectSquares(vector<string>& operations, vector<vector<int>>& points) {\n return {};\n }\n};"}, "fn": "runDetectSquares", "params": [{"name": "operations", "type": "string_array"}, {"name": "points", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\",\"count\"]", "[[0,0],[3,10],[11,2],[3,2],[11,10],[14,8]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\",\"add\",\"count\"]", "[[0,0],[3,10],[11,2],[3,2],[11,10],[11,2],[11,10]]"], ["[\"DetectSquares\",\"count\"]", "[[0,0],[5,5]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[0,0],[1,0],[0,1],[1,1]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[5,5],[7,5],[5,3],[7,3]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[8,8],[5,8],[8,5],[5,5]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[1,1],[4,1],[1,3],[4,3]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[2,2],[4,2],[6,2],[8,2]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[1,0],[1,0],[0,1],[0,1],[1,1],[1,1],[0,0]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[6,5],[5,6],[6,6],[7,5],[5,7],[7,7],[5,5]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[12,10],[10,12],[12,12],[10,8],[12,8],[10,10]]"], ["[\"DetectSquares\",\"count\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[3,3],[4,3],[3,4],[4,4],[3,3]]"], ["[\"DetectSquares\",\"add\",\"add\",\"count\"]", "[[0,0],[2,4],[7,4],[2,4]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[2,1],[2,1],[1,2],[2,2],[1,1]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[6,5],[5,6],[5,6],[6,6],[5,5]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[11,10],[10,11],[11,11],[11,11],[10,10]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[100,100],[101,100],[100,101],[50,70],[999,1],[1,999],[101,101]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[0,0],[2,0],[0,2],[2,2]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[999,1000],[1000,999],[999,999],[1000,1000]]"], ["[\"DetectSquares\",\"count\",\"add\",\"add\",\"add\",\"count\",\"count\"]", "[[0,0],[20,20],[21,20],[20,21],[21,21],[20,20],[21,21]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[11,10],[10,11],[11,11],[10,10]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[22,20],[20,22],[22,22],[20,20]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[33,30],[30,33],[33,33],[30,30]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[44,40],[40,44],[44,44],[40,40]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[55,50],[50,55],[55,55],[50,50]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[66,60],[60,66],[66,66],[60,60]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[77,70],[70,77],[77,77],[70,70]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[88,80],[80,88],[88,88],[80,80]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[99,90],[90,99],[99,99],[90,90]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[110,100],[100,110],[110,110],[100,100]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[125,120],[120,115],[125,115],[120,120]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[136,130],[130,124],[136,124],[130,130]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[147,140],[140,133],[147,133],[140,140]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[158,150],[150,142],[158,142],[150,150]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[169,160],[160,151],[169,151],[160,160]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[180,170],[170,160],[180,160],[170,170]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[191,180],[180,169],[191,169],[180,180]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[202,190],[190,178],[202,178],[190,190]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[213,200],[200,187],[213,187],[200,200]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[224,210],[210,196],[224,196],[210,210]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[235,220],[220,205],[235,205],[220,220]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[246,230],[230,214],[246,214],[230,230]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[257,240],[240,223],[257,223],[240,240]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[268,250],[250,232],[268,232],[250,250]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[279,260],[260,241],[279,241],[260,260]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[290,270],[270,250],[290,250],[270,270]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[301,280],[280,259],[301,259],[280,280]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[312,290],[290,268],[312,268],[290,290]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[323,300],[300,277],[323,277],[300,300]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[334,310],[310,286],[334,286],[310,310]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[345,320],[320,295],[345,295],[320,320]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[356,330],[330,304],[356,304],[330,330]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[367,340],[340,313],[367,313],[340,340]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[378,350],[350,322],[378,322],[350,350]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[389,360],[360,331],[389,331],[360,360]]"], ["[\"DetectSquares\"]", "[[0,0]]"], ["[\"DetectSquares\",\"add\",\"add\",\"add\",\"count\"]", "[[0,0],[0,0],[1000,0],[0,1000],[1000,1000]]"], ["@javascript:JSON.stringify([\"DetectSquares\",...Array(497).fill(\"add\"),\"count\"])", "@javascript:JSON.stringify([[0,0],...Array.from({length:497},(_,i)=>[i%1001,Math.floor(i/1001)]),[1000,1000]])"], ["@javascript:JSON.stringify([\"DetectSquares\",...Array(499).fill(\"count\")])", "@javascript:JSON.stringify([[0,0],...Array.from({length:499},()=>[1000,1000])])"]], "expected": [[1, 0], [1, 2], [0], [1], [1], [1], [0], [0], [8], [2], [2], [0, 1], [0], [2], [2], [2], [1], [1], [1], [0, 1, 0], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [1], [], [1], [0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "929", "slug": "di-string-match", "id": 929, "title": "DI String Match", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/di-string-match/", "examples": [{"input": "s = \"IDID\"", "output": "[0,4,1,3,2]", "explanation": "Steps rise, fall, rise, fall as required."}, {"input": "s = \"III\"", "output": "[0,1,2,3]", "explanation": "All steps rise."}, {"input": "s = \"DDI\"", "output": "[3,2,0,1]", "explanation": "Two falls then a rise."}], "hints": ["Keep two pools: the smallest unused number and the largest unused number.", "Hand out the smallest remaining value on every I and the largest remaining value on every D; the final leftover fills the last slot.", "Any valid ordering is accepted, so this greedy choice never needs backtracking."], "statement": "Rebuild a permutation from its up/down pattern.\n\nYou are given a pattern string `s` whose characters are `I` (the next number goes up) and `D` (the next number goes down). Build any ordering `perm` of the integers `0` through `n` (where `n` is the pattern length) such that each neighbouring pair obeys the pattern: `perm[i] < perm[i+1]` wherever `s[i]` is `I`, and `perm[i] > perm[i+1]` wherever it is `D`. Many orderings may qualify; return any one of them.\n\n**Constraints:**\n- `1 <= s.length <= 10^5`\n- Each character of `s` is `I` or `D`.\n", "solution": "## Approach\n\nMaintain the smallest and largest numbers not used yet. Scanning the pattern left to right, place the current minimum on an `I` (leaving room above for the rise) and the current maximum on a `D` (leaving room below for the fall). After the scan one number remains and it completes the permutation.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), a single pass with constant work per character.\n- **Space Complexity:** O(n) for the answer array.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def diStringMatch(self, s: str) -> List[int]:\n lo, hi = 0, len(s)\n ans = []\n for c in s:\n if c == 'I':\n ans.append(lo)\n lo += 1\n else:\n ans.append(hi)\n hi -= 1\n ans.append(lo)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc DiStringMatch(s string) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def diStringMatch(self, s: str) -> List[int]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> diStringMatch(string s) {\n return {};\n }\n};"}, "fn": "diStringMatch", "params": [{"name": "s", "type": "string"}], "outputType": "int_array", "tests": [["IDID"], ["III"], ["DDI"], ["I"], ["D"], ["ID"], ["DI"], ["IIII"], ["DDDD"], ["IDIDID"], ["DIDI"], ["IIDD"], ["DDII"], ["IDDI"], ["DIID"], ["IIIIIIII"], ["DDDDDDDD"], ["IDIDIDID"], ["DIDIDI"], ["IIDDIID"], ["DDIIDI"], ["IIIDD"], ["DDDII"], ["IID"], ["DII"], ["IDDIDDIID"], ["DIIIDDD"], ["DIDIDIDI"]], "expected": [[0, 4, 1, 3, 2], [0, 1, 2, 3], [3, 2, 0, 1], [0, 1], [1, 0], [0, 2, 1], [2, 0, 1], [0, 1, 2, 3, 4], [4, 3, 2, 1, 0], [0, 6, 1, 5, 2, 4, 3], [4, 0, 3, 1, 2], [0, 1, 4, 3, 2], [4, 3, 0, 1, 2], [0, 4, 3, 1, 2], [4, 0, 1, 3, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 8, 1, 7, 2, 6, 3, 5, 4], [6, 0, 5, 1, 4, 2, 3], [0, 1, 7, 6, 2, 3, 5, 4], [6, 5, 0, 1, 4, 2, 3], [0, 1, 2, 5, 4, 3], [5, 4, 3, 0, 1, 2], [0, 1, 3, 2], [3, 0, 1, 2], [0, 9, 8, 1, 7, 6, 2, 3, 5, 4], [7, 0, 1, 2, 6, 5, 4, 3], [8, 0, 7, 1, 6, 2, 5, 3, 4]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "561", "slug": "diagonal-traverse", "id": 561, "title": "Diagonal Traverse", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/diagonal-traverse/", "examples": [{"input": "mat = [[1,2,3],[4,5,6],[7,8,9]]", "output": "[1,2,4,7,5,3,6,8,9]", "explanation": "Diagonals are visited as [1], [2,4], [7,5,3], [6,8], [9] with alternating directions."}, {"input": "mat = [[1,2],[3,4]]", "output": "[1,2,3,4]", "explanation": "The two middle cells form one diagonal visited bottom-up after the start."}], "hints": ["Simulate position plus a direction flag instead of precomputing diagonals.", "Hitting the right or top border while moving up-right means stepping right or down and flipping to down-left (mirror for the other direction).", "Single-row and single-column grids are just linear walks; the same border rules handle them."], "statement": "Given a rectangular grid of numbers, list its entries in diagonal zigzag order. Start at the top-left corner heading up-and-right, then alternate between down-and-left and up-and-right each time a border is reached. When a border blocks the diagonal step, sidestep along the border to the next row or column and flip direction.\n\nContinue until every cell has been emitted once, and return the resulting flat list.\n\n**Constraints:**\n- `1 <= mat.length * mat[i].length <= 10^4`\n- Each row has the same length\n- `-10^5 <= mat[i][j] <= 10^5`\n", "solution": "## Approach\n\nWalk the grid with a row, column and upward flag. Emit the current cell, then compute the next step: moving up-right increases column and decreases row, moving down-left does the opposite. Border checks for the last row/column or first row/column trigger a sidestep and direction flip. This visits each cell exactly once.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n) for the single walk.\n- **Space Complexity:** O(1) besides the output array.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:\n if not mat or not mat[0]:\n return []\n m, n = len(mat), len(mat[0])\n ans: List[int] = []\n r = c = 0\n up = True\n while len(ans) < m * n:\n ans.append(mat[r][c])\n if up:\n if c == n - 1:\n r += 1\n up = False\n elif r == 0:\n c += 1\n up = False\n else:\n r -= 1\n c += 1\n else:\n if r == m - 1:\n c += 1\n up = True\n elif c == 0:\n r += 1\n up = True\n else:\n r += 1\n c -= 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FindDiagonalOrder(mat [][]int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findDiagonalOrder(vector<vector<int>>& mat) {\n return {};\n }\n};"}, "fn": "findDiagonalOrder", "params": [{"name": "mat", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[[1,2,3],[4,5,6],[7,8,9]]"], ["[[1,2],[3,4]]"], ["[[5]]"], ["[[1,2,3,4]]"], ["[[1],[2],[3]]"], ["[[1,2,3],[4,5,6]]"], ["[[1,2],[3,4],[5,6]]"], ["[[1,2,3,4,5],[6,7,8,9,10]]"], ["[[1]]"], ["[[0,0],[0,0]]"], ["[[-1,-2],[-3,-4]]"], ["[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]"], ["[[1,2,3,4],[5,6,7,8],[9,10,11,12]]"], ["[[100000,-100000]]"], ["[[1,2],[3,4],[5,6],[7,8]]"], ["[[9,8,7],[6,5,4]]"], ["[[1,2,3,4,5]]"], ["[[1],[2],[3],[4],[5]]"], ["[[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]]"], ["[[2,3],[5,7],[11,13]]"], ["[[0]]"], ["[[1,2,3]]"], ["[[1],[2]]"], ["[[1,2,3,4],[5,6,7,8]]"], ["[[4,3,2,1],[8,7,6,5]]"], ["[[1,2],[3,4],[5,6],[7,8],[9,10]]"], ["[[5,1,3],[9,2,8]]"], ["[[1,2,3,4,5,6]]"]], "expected": [[1, 2, 4, 7, 5, 3, 6, 8, 9], [1, 2, 3, 4], [5], [1, 2, 3, 4], [1, 2, 3], [1, 2, 4, 5, 3, 6], [1, 2, 3, 5, 4, 6], [1, 2, 6, 7, 3, 4, 8, 9, 5, 10], [1], [0, 0, 0, 0], [-1, -2, -3, -4], [1, 2, 4, 7, 5, 3, 6, 8, 10, 11, 9, 12], [1, 2, 5, 9, 6, 3, 4, 7, 10, 11, 8, 12], [100000, -100000], [1, 2, 3, 5, 4, 6, 7, 8], [9, 8, 6, 5, 7, 4], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 4, 7, 5, 3, 6, 8, 10, 13, 11, 9, 12, 14, 15], [2, 3, 5, 11, 7, 13], [0], [1, 2, 3], [1, 2], [1, 2, 5, 6, 3, 4, 7, 8], [4, 3, 8, 7, 2, 1, 6, 5], [1, 2, 3, 5, 4, 6, 7, 9, 8, 10], [5, 1, 9, 2, 3, 8], [1, 2, 3, 4, 5, 6]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "97", "slug": "diameter-of-binary-tree", "id": 97, "title": "Diameter of Binary Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/diameter-of-binary-tree/", "examples": [{"input": "root = [1,2,3,4,5]", "output": "3", "explanation": "A longest path uses three edges, for example 4-2-1-3."}, {"input": "root = [1,2]", "output": "1", "explanation": "The diameter (longest path between any two nodes) has length 1."}, {"input": "root = [1]", "output": "0", "explanation": "The diameter (longest path between any two nodes) has length 0."}], "hints": ["For each node, a path passing through it uses the deepest path in its left subtree plus the deepest path in its right subtree.", "Compute subtree heights in postorder and track the largest sum of child heights.", "Return the diameter in edges, not the number of nodes on the path."], "statement": "You are handed the `root` of a binary tree. Compute how wide the tree stretches, reported as its diameter.\n\nHere the diameter means the greatest number of edges found on any route joining two nodes of the tree. That route does not have to include the root; what matters is only the count of edges from one endpoint to the other.\n\n**Constraints:**\n\n- The count of nodes in the tree is between `1` and `10000` inclusive.\n- Every node's stored value satisfies `-100 <= node.val <= 100`.\n", "solution": "## Approach\n\nCompute node heights in postorder without recursion. First collect nodes with an explicit stack, then process that order backward so both child heights are known. The longest path through a node is its left height plus its right height; track the largest such value.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(n) for the traversal order and height table.\n\n## Implementation\n\n```python\nclass Solution:\n def diameterOfBinaryTree(self, root) -> int:\n if root is None:\n return 0\n\n order = []\n stack = [root]\n while stack:\n node = stack.pop()\n order.append(node)\n if node.left is not None:\n stack.append(node.left)\n if node.right is not None:\n stack.append(node.right)\n\n heights = {}\n diameter = 0\n for node in reversed(order):\n left = heights.get(node.left, 0)\n right = heights.get(node.right, 0)\n diameter = max(diameter, left + right)\n heights[node] = 1 + max(left, right)\n return diameter\n```\n", "starter": {"go": "package main\n\nfunc DiameterOfBinaryTree(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 diameterOfBinaryTree(self, root) -> int:\n pass\n", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n};\n*/\nclass Solution {\npublic:\n int diameterOfBinaryTree(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "diameterOfBinaryTree", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int", "tests": [["[1]"], ["[1,2]"], ["[1,null,2]"], ["[1,2,3]"], ["[1,2,3,4,5]"], ["[1,2,3,4,null,null,5]"], ["[1,2,3,null,4,5,null]"], ["[1,2,null,3]"], ["[1,null,2,3]"], ["[1,2,null,null,3]"], ["[1,null,2,null,3]"], ["[1,2,null,3,null,4,null,5]"], ["[1,null,2,null,3,null,4,null,5]"], ["[1,2,null,null,3,4,null,null,5]"], ["[1,null,2,3,null,null,4,5]"], ["[1,2,3,4,5,6,7]"], ["[0,0,0,0,0,0,0]"], ["[-1,-2,-3,-4,-5,-6,-7]"], ["[1,2,3,4,5,null,null,6,7]"], ["[1,2,3,null,null,4,5,null,null,6,7]"], ["[1,2,3,4,null,null,5,6,null,null,7]"], ["[1,2,3,4,null,5,null,6,null,7]"], ["[1,2,3,null,4,null,5,6,null,null,7]"], ["[5,4,6,3,null,null,7,2,null,null,8,1,null,null,9]"], ["[5,4,6,null,3,7,null,null,2,null,8,null,1,9]"], ["[10,5,15,3,7,12,18,1,4,6,8,11,13,17,20]"], ["[10,5,15,3,7,null,18,1,null,6,8,17,20]"], ["[10,5,15,null,7,12,null,6,8,11,13]"], ["[1,2,3,4,5,6,7,8]"], ["[1,2,3,4,5,6,7,null,null,null,null,null,null,null,8]"], ["[1,2,3,4,null,null,5,6,null,null,7,8,null,null,9]"], ["[1,2,3,null,4,5,null,null,6,7,null,null,8]"], ["[1,2,3,4,5,null,6,null,7,8,null,null,9]"], ["[2,2,2,2,null,null,2,2,null,null,2]"], ["[100,-100,99,-99,null,null,98,-98,null,null,97]"], ["[8,4,12,2,6,10,14,1,3,5,7,9,11,13,15]"], ["[8,4,12,2,6,10,14,1,null,null,7,9,null,null,15]"], ["[8,4,12,null,6,10,null,5,7,9,11]"], ["[3,1,4,null,2,null,5,null,null,null,6]"], ["[3,1,5,null,2,4,6,null,null,null,null,null,7]"], ["[0,-1,1,-2,null,null,2,-3,null,null,3,-4,null,null,4]"], ["[0,-1,1,null,-2,2,null,null,-3,null,3,null,-4,4]"], ["[1,2,3,4,null,null,5,6,7,8,9]"], ["[1,2,3,null,4,5,null,6,7,8,9]"], ["[1,2,3,4,5,null,null,6,null,null,7,8,null,null,9]"], ["[50,25,75,12,37,62,87,6,18,31,43,56,68,81,93]"], ["[50,25,75,12,null,62,87,6,18,56,68,null,93]"], ["[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]"], ["[1,2,3,4,5,6,7,8,null,null,11,12,null,null,15]"], ["[9,8,7,6,null,null,5,4,null,null,3,2,null,null,1]"], ["[1,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9,null,10]"], ["[1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9,null,10]"], ["[1,2,null,null,3,4,null,null,5,6,null,null,7,8,null,null,9]"], ["[1,null,2,3,null,null,4,5,null,null,6,7,null,null,8,9]"], ["[4,2,6,1,3,5,7,null,null,null,null,null,null,null,8,null,9]"], ["@javascript:(()=>{const n=9999,a=[100];let made=1,active=1;while(made<n){active--;if(active<63&&made+1<n){a.push(100-(made%201),100-((made+1)%201));made+=2;active+=2}else{a.push(100-(made%201),null);made++;active++}}while(a[a.length-1]===null)a.pop();return JSON.stringify(a)})()"], ["@javascript:(()=>{const n=10000,a=[-100];let made=1,active=1;while(made<n){active--;if(active<63&&made+1<n){a.push((made%201)-100,((made+1)%201)-100);made+=2;active+=2}else{a.push((made%201)-100,null);made++;active++}}while(a[a.length-1]===null)a.pop();return JSON.stringify(a)})()"]], "expected": [0, 1, 1, 2, 3, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 8, 6, 6, 6, 5, 5, 8, 7, 6, 6, 6, 6, 6, 6, 5, 5, 8, 8, 6, 6, 6, 6, 6, 6, 6, 8, 9, 9, 8, 8, 6, 321, 321], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "348", "slug": "different-ways-to-add-parentheses", "id": 348, "title": "Different Ways to Add Parentheses", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/different-ways-to-add-parentheses/", "examples": [{"input": "expression = \"2-1-1\"", "output": "[0,2]", "explanation": "(2-1)-1 gives 0, while 2-(1-1) gives 2."}, {"input": "expression = \"2*3-4*5\"", "output": "[-34,-14,-10,-10,10]", "explanation": "Parenthesizing as 2*(3-(4*5)) gives -34, and the other groupings give -14, -10, -10, and 10."}], "hints": ["Treat every operator as a possible last evaluation step and recurse on both sides.", "Combine each left value with each right value through the current operator.", "Memoize results per substring to avoid recomputation."], "statement": "Given a string `expression` made of non-negative integers and the operators `+`, `-`, and `*`, compute every distinct value obtainable by parenthesizing the expression in all possible ways.\n\nEach operator can serve as the final operation to evaluate: split the string there, solve both sides recursively, and combine each left result with each right result using that operator. A string with no operator is just the number itself.\n\nReturn all possible results in any order.\n\n*Type note:* the original signature returns a list of integers; here it maps to `int_list`.\n\n**Constraints:**\n- `1 <= expression.length <= 20`\n- The expression holds digits and the operators `+`, `-`, `*`.\n- Each number in the expression is in the range `[0, 99]` with no sign prefix.\n", "solution": "## Approach\n\nTry every operator as the last one evaluated: split the expression at that position, recursively compute all values of the left and right parts, and pair every left value with every right value through the operator. A segment without operators contributes its plain numeric value. Order of results does not matter.\n\n## Complexity Analysis\n\n- **Time Complexity:** Exponential in the number of operators (Catalan growth), each split combining both sides.\n- **Space Complexity:** O(n) recursion depth plus the stored partial results.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def diffWaysToCompute(self, expression: str) -> List[int]:\n res = []\n for i, c in enumerate(expression):\n if c in \"+-*\":\n for a in self.diffWaysToCompute(expression[:i]):\n for b in self.diffWaysToCompute(expression[i + 1:]):\n if c == \"+\":\n res.append(a + b)\n elif c == \"-\":\n res.append(a - b)\n else:\n res.append(a * b)\n if not res:\n res.append(int(expression))\n return res\n```\n", "starter": {"go": "package main\n\nfunc DiffWaysToCompute(expression string) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def diffWaysToCompute(self, expression: str) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> diffWaysToCompute(string expression) {\n return {};\n }\n};"}, "fn": "diffWaysToCompute", "params": [{"name": "expression", "type": "string"}], "outputType": "int_list", "tests": [["2-1-1"], ["2*3-4*5"], ["5"], ["0"], ["2+3"], ["2*3"], ["2-1"], ["11"], ["10+5"], ["2+3*4"], ["2*3-4"], ["1+1+1"], ["2*2*2"], ["9-9-9"], ["1+2+3+4"], ["3+2*2"], ["99*99"], ["0+0"], ["15-10+5"], ["3+5*2"], ["10-5*2"], ["1*2+3*4"], ["4-2*3"], ["6+6-6"], ["12*3-4"], ["5*5+5*5"], ["8-3+2"], ["7*7-7+7"]], "expected": [[2, 0], [-34, -10, -14, -10, 10], [5], [0], [5], [6], [1], [11], [15], [14, 20], [-2, 2], [3, 3], [8, 8], [9, -9], [10, 10, 10, 10, 10], [7, 10], [9801], [0], [0, 10], [13, 16], [0, 10], [14, 20, 14, 20, 20], [-2, 6], [6, 6], [-12, 32], [150, 250, 50, 250, 150], [3, 7], [-49, 49, 35, 7, 49]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "927", "slug": "distinct-subsequences-ii", "id": 927, "title": "Distinct Subsequences II", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/distinct-subsequences-ii/", "examples": [{"input": "s = \"abc\"", "output": "7", "explanation": "All 7 non-empty picks differ."}, {"input": "s = \"aba\"", "output": "6", "explanation": "Texts are a, b, ab, aa, ba, aba."}, {"input": "s = \"aaa\"", "output": "3", "explanation": "Only a, aa, aaa."}], "hints": ["Track all subsequences including the empty one, then subtract it at the end.", "Appending a new character doubles the count, but texts already created at its previous appearance must be subtracted once to avoid double counting.", "Keep the running total before each first-seen letter so repeats can be corrected with modular arithmetic."], "statement": "Count how many different non-empty subsequences a string has.\n\nA subsequence is formed by erasing zero or more characters while keeping the order of the survivors. Two subsequences count as the same whenever their final texts match exactly, even if they were built from different positions. For instance, the two single `a` characters inside `\"aba\"` yield just one distinct subsequence `\"a\"`.\n\nGiven a string `s` of lowercase letters, return the number of distinct non-empty subsequences, modulo `10^9 + 7`.\n\n**Constraints:**\n- `1 <= s.length <= 2000`\n- `s` holds lowercase English letters.\n", "solution": "## Approach\n\nKeep a running total of distinct subsequences including the empty one. Each new character doubles the total, because every old subsequence can either skip or take it. When the character appeared before, the doubling recreates exactly the batch added at its previous appearance, so subtract that stored value. All steps use a modulus, and one is removed at the end for the empty subsequence.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one pass over the string.\n- **Space Complexity:** O(1) besides the last-seen table of at most 26 letters.\n\n## Implementation\n\n```python\nclass Solution:\n def distinctSubseqII(self, s: str) -> int:\n MOD = 10 ** 9 + 7\n total = 1\n last = {}\n for c in s:\n prev = total\n total = (total * 2 - last.get(c, 0)) % MOD\n last[c] = prev\n return (total - 1) % MOD\n```\n", "starter": {"go": "package main\n\nfunc DistinctSubseqII(s string) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def distinctSubseqII(self, s: str) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int distinctSubseqII(string s) {\n return 0;\n }\n};"}, "fn": "distinctSubseqII", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["abc"], ["aba"], ["aaa"], ["a"], ["z"], ["ab"], ["aa"], ["abcdef"], ["aaaa"], ["abab"], ["abcabc"], ["leetcode"], ["aaaaa"], ["ababa"], ["xyzzy"], ["abcdefg"], ["aab"], ["abb"], ["abcdabcd"], ["zzzzz"], ["abcde"], ["aabbcc"], ["abccba"], ["hello"], ["banana"], ["mississippi"], ["abcdefghij"], ["aabbccddee"]], "expected": [7, 6, 3, 1, 1, 3, 2, 63, 4, 11, 51, 187, 5, 19, 21, 127, 5, 5, 223, 5, 31, 26, 42, 23, 39, 477, 1023, 242], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "134", "slug": "distinct-subsequences", "id": 134, "title": "Distinct Subsequences", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/distinct-subsequences/", "examples": [{"input": "s = \"rabbbit\", t = \"rabbit\"", "output": "3", "explanation": "The number of distinct subsequences of \"rabbbit\" equalling \"rabbit\" is 3."}, {"input": "s = \"babgbag\", t = \"bag\"", "output": "5", "explanation": "The number of distinct subsequences of \"babgbag\" equalling \"bag\" is 5."}], "hints": ["For each source character, either skip it or use it to match the next target character.", "Update target-prefix counts from right to left so one source character is not reused."], "statement": "Consider two strings `s` and `t`. Count how many different ways `t` can be obtained from `s` by removing characters.\n\nOnly deletions are allowed: keep a subsequence of `s` in its original order, discarding zero or more characters, and check whether what remains matches `t` exactly. Each distinct set of kept positions that spells `t` counts separately. The final count is known to fit inside a signed 32-bit integer.\n\n**Constraints:**\n- Both lengths satisfy `1 <= s.length, t.length <= 1000`.\n- `s` and `t` consist solely of uppercase and lowercase English letters.\n", "solution": "## Approach\n\nLet `counts[j]` be the number of ways the processed source prefix forms the first `j`\ncharacters of `t`. Process target positions from right to left so one source character\ncannot be reused. States that no longer have enough source characters remaining to\nfinish `t` are skipped.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * m), where `n = len(s)` and `m = len(t)`.\n- **Space Complexity:** O(m).\n\n## Implementation\n\n```python\nclass Solution:\n def numDistinct(self, s: str, t: str) -> int:\n source_length, target_length = len(s), len(t)\n if target_length > source_length:\n return 0\n\n counts = [0] * (target_length + 1)\n counts[0] = 1\n for i in range(1, source_length + 1):\n upper = min(i, target_length)\n lower = max(1, target_length - (source_length - i))\n for j in range(upper, lower - 1, -1):\n if s[i - 1] == t[j - 1]:\n counts[j] += counts[j - 1]\n return counts[target_length]\n```\n", "starter": {"go": "package main\n\nfunc NumDistinct(s string, t string) int {\n return 0\n}", "python": "class Solution:\n def numDistinct(self, s: str, t: str) -> int:\n return 0\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int numDistinct(string s, string t) {\n return 0;\n }\n};"}, "fn": "numDistinct", "params": [{"name": "s", "type": "string"}, {"name": "t", "type": "string"}], "outputType": "int", "tests": [["rabbbit", "rabbit"], ["babgbag", "bag"], ["a", "a"], ["a", "b"], ["a", "aa"], ["AaAaA", "AaA"], ["abc", "abc"], ["abc", "abcd"], ["abc", "ac"], ["abc", "ca"], ["aaa", "a"], ["aaa", "aa"], ["aaa", "aaa"], ["aaa", "aaaa"], ["aaaaa", "aa"], ["aaaaa", "aaa"], ["abab", "ab"], ["abab", "ba"], ["abab", "abab"], ["abab", "aabb"], ["banana", "ban"], ["banana", "ana"], ["banana", "aaa"], ["mississippi", "misp"], ["mississippi", "issi"], ["mississippi", "sip"], ["leetcode", "code"], ["leetcode", "leet"], ["leetcode", "etc"], ["abcdefghij", "acegi"], ["abcdefghij", "jih"], ["abcabcabc", "abc"], ["abcabcabc", "acb"], ["abcabcabc", "aaa"], ["zzzzzzzzzz", "zzzzz"], ["aaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaa"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaa"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaa"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaa"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaa"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], ["abababababababababab", "abab"], ["abababababababababab", "baba"], ["abcabcabcabcabc", "abcabc"], ["abcabcabcabcabc", "acbacb"], ["thequickbrownfox", "quick"], ["thequickbrownfox", "tqbf"], ["thequickbrownfox", "wolf"], ["dynamicprogramming", "dpg"], ["dynamicprogramming", "program"], ["subsequencessubsequences", "subsequence"], ["ccccaaaabbbbcccc", "cabc"], ["xyzxyzxyzxyz", "xyzxyz"], ["qwertyqwerty", "qwerty"], ["abcdeabcdeabcde", "edc"], ["longsourcestring", "shorttarget"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"], ["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]], "expected": [3, 5, 1, 0, 0, 4, 1, 0, 1, 0, 3, 3, 1, 0, 10, 10, 3, 1, 1, 0, 3, 4, 1, 12, 15, 12, 1, 1, 2, 1, 0, 10, 4, 1, 252, 184756, 155117520, 300540195, 601080390, 1166803110, 40, 1, 495, 330, 84, 7, 1, 1, 0, 2, 2, 26, 256, 28, 7, 1, 0, 0, 0], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "624", "slug": "distribute-candies", "id": 624, "title": "Distribute Candies", "difficulty": "Easy", "category": "hash-table", "link": "https://leetcode.com/problems/distribute-candies/", "examples": [{"input": "candyType = [1,1,2,2,3,3]", "output": "3", "explanation": "Three takes cover all three types."}, {"input": "candyType = [1,1,2,3]", "output": "2", "explanation": "Two takes cover at most two types."}, {"input": "candyType = [6,6,6,6]", "output": "1", "explanation": "Only one type exists."}], "hints": ["Count the distinct candy types with a set.", "Alice's share size is exactly half the array length.", "The answer is the smaller of the distinct count and the share size."], "statement": "Given an array `candyType` where each entry records the type of one candy, Alice may take exactly half of the candies. She wants as many distinct types as possible. Return the greatest number of different types she can hold.\n\nShe cannot exceed half the pile, and she cannot exceed the number of distinct types present \u2014 the answer is simply the smaller of those two numbers.\n\n**Constraints:**\n- `2 <= candyType.length <= 10^4`, even length.\n- `-10^5 <= candyType[i] <= 10^5`\n", "solution": "## Approach\n\nCollect the distinct candy types into a set. Alice takes exactly half the pile, so she can cover at most that many types, and at most the number of distinct types available. The minimum of the two bounds is always achievable by picking one candy from distinct types first.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for a single pass into the set.\n- **Space Complexity:** O(n) for the distinct values.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def distributeCandies(self, candyType: List[int]) -> int:\n return min(len(set(candyType)), len(candyType) // 2)\n```\n", "starter": {"go": "package main\n\nfunc DistributeCandies(candyType []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def distributeCandies(self, candyType: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int distributeCandies(vector<int>& candyType) {\n return 0;\n }\n};"}, "fn": "distributeCandies", "params": [{"name": "candyType", "type": "int_array"}], "outputType": "int", "tests": [["[1,1,2,2,3,3]"], ["[1,1,2,3]"], ["[6,6,6,6]"], ["[1,2]"], ["[1,1,1,2,2,2]"], ["[1,2,3,4,5,6]"], ["[0,0,-1,-1]"], ["[100000,-100000,0,5]"], ["[1,1,1,1,2,3]"], ["[3,3,3,3,3,3,4,4]"], ["[1,2,3,1,2,3]"], ["[5,5]"], ["[1,3,5,7]"], ["[2,2,4,4,6,6,8,8]"], ["[9,9,9,8,8,7]"], ["[1,1,2,2,3,4]"], ["[5,-5,1,-4,1,2]"], ["[5,4,5,0,-4,-1,2,-3]"], ["[-1,4,-5,1,-2,-5]"], ["[5,0,1,0]"], ["[2,5,4,-3]"], ["[-5,-4,-3,0,-4,-2,-4,-4]"], ["[-5,2,-1,5,-3,-4]"], ["[-3,0,1,5,-4,1]"], ["[0,-3,1,-1]"], ["[-5,-4,-1,5,-2,3,1,-1,4,-4]"], ["[-3,-4,1,-4,-2,3,1,3]"], ["[3,-5]"]], "expected": [3, 2, 1, 1, 2, 3, 2, 2, 3, 2, 3, 1, 2, 4, 3, 3, 3, 4, 3, 2, 2, 4, 3, 3, 2, 5, 4, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "963", "slug": "distribute-coins-in-binary-tree", "id": 963, "title": "Distribute Coins in Binary Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/distribute-coins-in-binary-tree/", "examples": [{"input": "root = [3,0,0]", "output": "2", "explanation": "The root holds 3 coins but needs 1; moving one coin to each child costs 2 moves."}, {"input": "root = [0,3,0]", "output": "3", "explanation": "Three single-step coin moves balance the three nodes."}, {"input": "root = [1,0,2]", "output": "2", "explanation": "One coin travels from the right child to the middle child in two steps via the root."}], "hints": ["Think bottom-up: each subtree reports its surplus (positive) or deficit (negative) of coins relative to one-per-node.", "The coins crossing an edge equal the absolute surplus of the child subtree; add those crossings across all edges.", "A post-order traversal computes both the balance and the accumulated moves in one pass."], "statement": "Each node of a binary tree holds some number of coins, and the total number of coins equals the number of nodes. In one move you may shift a single coin from a node to one of its directly connected neighbors (parent or child).\n\nRearrange the coins so that every node ends with exactly one coin. Return the smallest possible number of moves.\n\n**Constraints:**\n- `1 <= number of nodes <= 100`\n- `0 <= node value <= number of nodes`\n- The sum of all node values equals the number of nodes.\n", "solution": "## Approach\n\nDo a post-order walk. For each node compute the net surplus of its subtree: coins present minus nodes present, i.e. node.val - 1 plus the surpluses of both children. The absolute surplus of each child must cross the connecting edge, so add those absolute values to the move counter. The root surplus is zero by the problem guarantee, and the counter holds the optimal total because every edge is crossed the minimum necessary times.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited once.\n- **Space Complexity:** O(h) for recursion depth, where h is the tree height.\n\n## Implementation\n\n```python\nclass Solution:\n def distributeCoins(self, root) -> int:\n self.moves = 0\n def bal(node):\n if not node:\n return 0\n l = bal(node.left)\n r = bal(node.right)\n self.moves += abs(l) + abs(r)\n return node.val - 1 + l + r\n bal(root)\n return self.moves\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 DistributeCoins(root *TreeNode) int {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def distributeCoins(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*/\nclass Solution {\npublic:\n int distributeCoins(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "distributeCoins", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int", "tests": [["[3,0,0]"], ["[0,3,0]"], ["[1,0,2]"], ["[1,0,0,null,3]"], ["[1]"], ["[2,0]"], ["[0,2]"], ["[1,1,1]"], ["[4,0,0,0,0]"], ["[0,0,4,0,0]"], ["[2,2,0]"], ["[0,0,3]"], ["[1,2,0]"], ["[5,0,0,0,0,0]"], ["[1,0,0,0,4]"], ["[2,0,1]"], ["[0,1,2]"], ["[3,0,1,null,0]"], ["[1,0,3]"], ["[0,4,0,0,0]"], ["[2,3,0,null,null,0,0]"], ["[1,0,0,0,0,0,6]"], ["[0,0,0,0,7,null,null,0,0]"], ["[6,0,0,0,0,0,0]"], ["[1,2,3,0,0,0,0]"], ["[0,0,0,4]"], ["[2,0,0,1]"], ["[3,1,0,0,0]"]], "expected": [2, 3, 2, 4, 0, 1, 1, 0, 6, 8, 2, 3, 2, 8, 6, 1, 1, 3, 3, 4, 7, 14, 14, 10, 5, 6, 2, 5], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "258", "slug": "divide-two-integers", "id": 258, "title": "Divide Two Integers", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/divide-two-integers/", "examples": [{"input": "dividend = 10, divisor = 3", "output": "3", "explanation": "10/3 = 3.333..., which truncates to 3."}, {"input": "dividend = 7, divisor = -3", "output": "-2", "explanation": "7/-3 = -2.333..., which truncates toward zero to -2."}], "hints": ["Work with the absolute values as 64-bit numbers, then apply the sign at the end; handle MIN_VALUE / -1 as a special case.", "Repeatedly subtract the largest doubled chunk of the divisor that still fits (exponential search with bit shifts) instead of subtracting one at a time."], "statement": "Given a dividend and a divisor, compute the integer quotient of the division, discarding any fractional part (truncation toward zero: `8.345` becomes `8` and `-2.7335` becomes `-2`).\n\nYou may not use the multiplication, division, or modulo operators anywhere in your logic.\n\nBecause the environment stores only 32-bit signed integers, clamp the result: a quotient above `2^31 - 1` becomes `2147483647`. (This happens only for `-2147483648 / -1`; a quotient below `-2^31` cannot occur.)\n\n**Constraints:**\n- `-2^31 <= dividend, divisor <= 2^31 - 1`\n- `divisor != 0`\n", "solution": "## Approach\n\nTreat the single overflowing case (`MIN_VALUE / -1`) separately by returning `MAX_VALUE`. Otherwise work with non-negative 64-bit copies, repeatedly carving off the biggest doubled multiple of the divisor that still fits into the remainder. Each carve adds the matching power of two to the quotient, and the sign is applied once at the end.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log^2 n) in the worst case, effectively O(log n) doublings per subtraction round.\n- **Space Complexity:** O(1) extra space.\n\n## Implementation\n\n```python\nclass Solution:\n def divide(self, dividend: int, divisor: int) -> int:\n if dividend == -(2**31) and divisor == -1:\n return 2**31 - 1\n neg = (dividend < 0) != (divisor < 0)\n a, b = abs(dividend), abs(divisor)\n q = 0\n while a >= b:\n chunk, mult = b, 1\n while a >= (chunk << 1):\n chunk <<= 1\n mult <<= 1\n a -= chunk\n q += mult\n return -q if neg else q\n```\n", "starter": {"go": "package main\n\nfunc Divide(dividend int, divisor int) int {\n \n}", "python": "class Solution:\n def divide(self, dividend: int, divisor: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int divide(int dividend, int divisor) {\n return 0;\n }\n};"}, "fn": "divide", "params": [{"name": "dividend", "type": "int"}, {"name": "divisor", "type": "int"}], "outputType": "int", "tests": [["10", "3"], ["7", "-3"], ["0", "1"], ["1", "1"], ["-1", "1"], ["-1", "-1"], ["2147483647", "1"], ["2147483647", "2"], ["-2147483648", "1"], ["-2147483648", "-1"], ["-2147483648", "2"], ["-2147483648", "-2"], ["2147483647", "-1"], ["-2147483647", "-1"], ["100", "10"], ["-100", "10"], ["100", "-10"], ["-100", "-10"], ["1", "2"], ["2", "3"], ["-2147483648", "3"], ["2147483647", "3"], ["5", "5"], ["-5", "-5"], ["12345", "1"], ["12345", "-12345"], ["2", "-2"], ["-2147483648", "-2147483648"], ["2147483647", "2147483647"]], "expected": [3, -2, 0, 1, -1, 1, 2147483647, 1073741823, -2147483648, 2147483647, -1073741824, 1073741824, -2147483647, 2147483647, 10, -10, -10, 10, 0, 0, -715827882, 715827882, 1, 1, 12345, -1, -1, 1, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "788", "slug": "domino-and-tromino-tiling", "id": 788, "title": "Domino and Tromino Tiling", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/domino-and-tromino-tiling/", "examples": [{"input": "n = 3", "output": "5", "explanation": "Five tilings fill a 2x3 board."}, {"input": "n = 1", "output": "1", "explanation": "One vertical domino fits."}, {"input": "n = 2", "output": "2", "explanation": "Two vertical or two horizontal dominoes."}], "hints": ["Let dp[n] be the number of full tilings of width n; consider how the rightmost column can be closed.", "A recurrence dp[n] = 2*dp[n-1] + dp[n-3] captures domino and tromino completions.", "Seed dp[0]=1, dp[1]=1, dp[2]=2 and apply the modulus at every step."], "statement": "Picture a board with 2 rows and `n` columns. You own two kinds of tiles\nthat may be turned around:\n\n- a straight domino covering a `2 x 1` (or `1 x 2`) strip,\n- an L-shaped tromino covering three cells of a `2 x 2` square.\n\nCover the whole board exactly, without gaps or overlaps. Two coverings\ncount as different when some pair of side-touching cells is joined inside\none tile in one covering but split across two tiles in the other.\n\nGiven `n`, count all valid coverings. The total can be huge, so report it\nmodulo `1_000_000_007`.\n\n**Constraints:**\n- `1 <= n <= 1000`\n", "solution": "## Approach\n\nLet `dp[i]` count the full tilings of a `2 x i` board. The rightmost strip\ncan end with a vertical domino, two horizontal dominoes, or one of the two\ntromino pairs, which together yield `dp[i] = 2 * dp[i-1] + dp[i-3]`. Start\nfrom `dp[0]=1, dp[1]=1, dp[2]=2` and iterate upward, reducing modulo\n`1_000_000_007` at each step.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the linear pass.\n- **Space Complexity:** O(n), reducible to O(1) by keeping only the last three values.\n\n## Implementation\n\n```python\nclass Solution:\n def numTilings(self, n: int) -> int:\n MOD = 1_000_000_007\n if n == 0:\n return 1\n if n == 1:\n return 1\n if n == 2:\n return 2\n dp = [0] * (n + 1)\n dp[0], dp[1], dp[2] = 1, 1, 2\n for i in range(3, n + 1):\n dp[i] = (2 * dp[i - 1] + dp[i - 3]) % MOD\n return dp[n]\n```\n", "starter": {"go": "package main\n\nfunc NumTilings(n int) int {\n return 0\n}", "python": "class Solution:\n def numTilings(self, n: int) -> int:\n return 0\n", "cpp": "class Solution {\npublic:\n int numTilings(int n) {\n return 0;\n }\n};"}, "fn": "numTilings", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["3"], ["1"], ["2"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["15"], ["20"], ["30"], ["50"], ["100"], ["200"], ["500"], ["1000"], ["11"], ["12"], ["13"], ["25"], ["40"], ["60"], ["80"], ["300"], ["700"], ["999"]], "expected": [5, 1, 2, 11, 24, 53, 117, 258, 569, 1255, 65501, 3418626, 312342182, 451995198, 190242381, 627399438, 603582422, 979232805, 2768, 6105, 13465, 178424817, 833773577, 882347204, 621192477, 768506587, 637136622, 326038248], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "240", "slug": "dota2-senate", "id": 240, "title": "Dota2 Senate", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/dota2-senate/", "examples": [{"input": "senate = \"RD\"", "output": "\"Radiant\"", "explanation": "The first senator comes from Radiant and he can just ban the next senator's right in round 1."}, {"input": "senate = \"RDD\"", "output": "\"Dire\"", "explanation": "The first senator comes from Radiant and he can just ban the next senator's right in round 1."}], "hints": ["A senator should always ban the closest opposite-party senator that comes after them.", "Use two queues holding the indices of each party's senators.", "The smaller index gets to act first, bans the other senator, and re-queues itself at the end with its index increased by senate.length to model the next round."], "statement": "Two factions, Radiant and Dire, each hold seats in a Dota2 council.\n\nThe council votes in turns on a proposed game change. Senators act one after another in the order they appear in the string, skipping anyone already stripped of voting power, and the cycle repeats until a decision is reached. On a senator's turn, that senator has two possible moves:\n\n- **Silence another senator:** pick a senator from the opposing side and remove every voting right of that senator for the present round and every later round.\n- **Declare the outcome:** when every senator who can still vote belongs to the speaker's own faction, that senator proclaims its faction the winner and settles the game change.\n\nYou receive a string `senate` whose `i`-th character records the faction of the `i`-th senator: `'R'` stands for Radiant and `'D'` stands for Dire. When the string holds `n` characters, there are `n` senators in total.\n\nAssume every senator votes with full foresight and always chooses the line most favorable to their own faction. Determine which faction ends up declaring the outcome. Respond with `\"Radiant\"` or `\"Dire\"`.\n\n**Constraints:**\n\n- `n == senate.length`\n- `1 <= n <= 10^4`\n- `senate[i]` is either `'R'` or `'D'`.\n", "solution": "## Approach\n\nEach senator's optimal move is to ban the closest opposite-party senator appearing later in the voting order. Keep two queues holding the indices of the Radiant and Dire senators still holding rights. In each round compare the heads: the earlier senator bans the later one (removing it) and re-queues at its own position plus `n` to re-enter future rounds. The party whose queue empties first loses.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where `n` is `senate.length`.\n- **Space Complexity:** O(n) for the two queues.\n\n## Implementation\n\n```python\nfrom collections import deque\n\nclass Solution:\n def predictPartyVictory(self, senate: str) -> str:\n n = len(senate)\n radiant = deque(i for i, ch in enumerate(senate) if ch == \"R\")\n dire = deque(i for i, ch in enumerate(senate) if ch == \"D\")\n\n while radiant and dire:\n r = radiant.popleft()\n d = dire.popleft()\n if r < d:\n radiant.append(r + n)\n else:\n dire.append(d + n)\n return \"Radiant\" if radiant else \"Dire\"\n```", "starter": {"go": "package main\n\nfunc PredictPartyVictory(senate string) string {\n \n}", "python": "class Solution:\n def predictPartyVictory(self, senate: str) -> str:\n ", "cpp": "#include <string>\n#include <queue>\nusing namespace std;\n\nclass Solution {\npublic:\n string predictPartyVictory(string senate) {\n \n }\n};"}, "fn": "predictPartyVictory", "params": [{"name": "senate", "type": "string"}], "outputType": "string", "tests": [["RD"], ["RDD"], ["RRDDD"], ["DDRRR"], ["R"], ["D"], ["RRR"], ["DDD"], ["RDDR"], ["DRRD"], ["RRDR"], ["DDDR"], ["RDRDRD"], ["DRDRDR"], ["RRRRDDD"], ["RDDDR"], ["RDRDD"], ["DRRDRD"], ["RR"], ["DD"], ["RDR"], ["DRD"], ["RRD"], ["DDR"], ["RRDD"], ["DRRR"], ["RDDD"], ["RRRDDD"], ["DDDRRR"], ["RDRDDR"], ["DDRDRR"], ["RRDRDD"]], "expected": ["Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Radiant", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Radiant", "Dire", "Radiant", "Dire", "Radiant", "Dire", "Radiant"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "324", "slug": "dungeon-game", "id": 324, "title": "Dungeon Game", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/dungeon-game/", "examples": [{"explanation": "One best path goes right, right, down, down. Starting with 7 keeps health above zero throughout.", "input": "dungeon = [[-2,-3,3],[-5,-10,1],[10,30,-5]]", "output": "7"}, {"explanation": "No damage occurs, so 1 health suffices.", "input": "dungeon = [[0]]", "output": "1"}, {"explanation": "Entering a cell with -3 from 4 health leaves 1.", "input": "dungeon = [[-3]]", "output": "4"}], "hints": ["Work backwards from the goal: each cell needs enough health to survive itself plus the cheaper of the right and down neighbours.", "A cell needing x health means max(1, need(next) - dungeon[i][j])."], "statement": "A hero crosses a grid from the top-left corner to the bottom-right corner, moving only right or down. Each cell holds an integer: a negative number drains health, a positive number restores it, and zero leaves it unchanged.\n\nHealth must never drop to zero or below; it must stay at least 1 after every step, including the starting cell. Find the smallest starting health that lets the hero reach the goal along some path.\n\n**Constraints:**\n- `1 <= m, n <= 100`\n- `-1000 <= dungeon[i][j] <= 1000`\n", "solution": "## Approach\n\nCompute backwards from the goal. For each cell, look at the health needed upon entering the right and down neighbours and take the cheaper one; the current cell must then supply enough to survive its own value plus that future need, but never less than 1. Filling the table from bottom-right to top-left yields the starting requirement.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n) for the grid size.\n- **Space Complexity:** O(m * n) for the table (reducible to O(n) with one row).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:\n m, n = len(dungeon), len(dungeon[0])\n INF = float(\"inf\")\n dp = [[INF] * (n + 1) for _ in range(m + 1)]\n dp[m][n - 1] = 1\n dp[m - 1][n] = 1\n for i in range(m - 1, -1, -1):\n for j in range(n - 1, -1, -1):\n need = min(dp[i + 1][j], dp[i][j + 1]) - dungeon[i][j]\n dp[i][j] = max(1, need)\n return dp[0][0]\n```\n", "starter": {"go": "package main\n\nfunc CalculateMinimumHP(dungeon [][]int) int {\n return 1\n}", "python": "from typing import List\nclass Solution:\n def calculateMinimumHP(self, dungeon: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int calculateMinimumHP(vector<vector<int>>& dungeon) {\n return 1;\n }\n};"}, "fn": "calculateMinimumHP", "params": [{"name": "dungeon", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[-2,-3,3],[-5,-10,1],[10,30,-5]]"], ["[[0]]"], ["[[-3]]"], ["[[5]]"], ["[[1,2],[3,4]]"], ["[[-5]]"], ["[[0,-3]]"], ["[[1,-3,3],[0,-2,0],[-3,-3,-3]]"], ["[[-1,-1],[-1,-1]]"], ["[[2,1],[-3,-3]]"], ["[[0,0,0],[0,0,0]]"], ["[[-10]]"], ["[[100]]"], ["[[1,-2,3],[2,-2,-2]]"], ["[[-2,-3]]"], ["[[3,-20,30],[-3,4,0]]"], ["[[0,-5,0],[0,0,0]]"], ["[[-1,1],[-1,1]]"], ["[[1,1,1],[1,-5,1],[1,1,1]]"], ["[[0,5],[-5,0]]"], ["[[-3,5]]"], ["[[2],[1]]"], ["[[-2],[3]]"], ["[[1,2,3],[2,3,4],[3,4,5]]"], ["[[-5,-10],[-20,-30]]"], ["[[1,-1,1],[-1,1,-1]]"]], "expected": [7, 1, 4, 1, 1, 6, 4, 3, 4, 1, 1, 11, 1, 2, 6, 1, 1, 2, 1, 1, 4, 1, 3, 1, 46, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "135", "slug": "edit-distance", "id": 135, "title": "Edit Distance", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/edit-distance/", "examples": [{"input": "word1 = \"horse\", word2 = \"ros\"", "output": "3", "explanation": "One optimal sequence uses one replacement and two deletions."}, {"input": "word1 = \"intention\", word2 = \"execution\"", "output": "5", "explanation": "One optimal sequence replaces the first five characters ('i','n','t','e','n') with ('e','x','e','c','u'), using five replacements."}], "hints": ["Define a state for converting a prefix of word1 into a prefix of word2.", "When the final characters differ, take one plus the best of insert, delete, and replace."], "statement": "Take two strings `word1` and `word2`. Determine the smallest count of single-character edits that turns `word1` into `word2`.\n\nEach edit must be one of the following: add a single character at any position, remove a single character, or swap one character for a different one.\n\n**Constraints:**\n- Lengths obey `0 <= word1.length, word2.length <= 500`.\n- `word1` and `word2` use only lowercase English letters.\n", "solution": "## Approach\n\nUse dynamic programming over prefixes of the two words. Matching characters carry the\ndiagonal value forward; differing characters take one plus the best of replacement,\ndeletion, and insertion. Keep only the previous and current rows, using the shorter\nword for the row width.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), where `m` and `n` are the word lengths.\n- **Space Complexity:** O(min(m, n)).\n\n## Implementation\n\n```python\nclass Solution:\n def minDistance(self, word1: str, word2: str) -> int:\n if len(word1) < len(word2):\n word1, word2 = word2, word1\n\n previous = list(range(len(word2) + 1))\n for i, first in enumerate(word1, 1):\n current = [i] + [0] * len(word2)\n for j, second in enumerate(word2, 1):\n if first == second:\n current[j] = previous[j - 1]\n else:\n current[j] = 1 + min(\n previous[j - 1], previous[j], current[j - 1]\n )\n previous = current\n return previous[-1]\n```\n", "starter": {"go": "package main\n\nfunc MinDistance(word1 string, word2 string) int {\n return 0\n}", "python": "class Solution:\n def minDistance(self, word1: str, word2: str) -> int:\n return 0\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int minDistance(string word1, string word2) {\n return 0;\n }\n};"}, "fn": "minDistance", "params": [{"name": "word1", "type": "string"}, {"name": "word2", "type": "string"}], "outputType": "int", "tests": [["horse", "ros"], ["intention", "execution"], ["", ""], ["", "a"], ["a", ""], ["", "abc"], ["abc", ""], ["a", "a"], ["a", "b"], ["ab", "ba"], ["abc", "abc"], ["abc", "ab"], ["ab", "abc"], ["abc", "acb"], ["kitten", "sitting"], ["saturday", "sunday"], ["flaw", "lawn"], ["gumbo", "gambol"], ["book", "back"], ["same", "same"], ["abcdef", "fedcba"], ["abcdef", "ace"], ["ace", "abcdef"], ["aaaa", "bbbb"], ["aaaa", "aaa"], ["aaa", "aaaa"], ["abababab", "babababa"], ["mississippi", "misisipi"], ["algorithm", "altruistic"], ["distance", "editing"], ["leetcode", "etco"], ["mart", "karma"], ["dinitrophenylhydrazine", "benzalphenylhydrazone"], ["abcabc", "acbacb"], ["qwerty", "asdfgh"], ["thequickbrownfox", "quickfox"], ["quickfox", "thequickbrownfox"], ["programming", "gaming"], ["dynamic", "programming"], ["subsequence", "subsequent"], ["transformation", "transportation"], ["abcdefghij", "jihgfedcba"], ["aaaaaaaaaa", "bbbbbbbbbb"], ["aaaaaaaaaa", "aaaaabaaaa"], ["zzzzzyyyyy", "yyyyyzzzzz"], ["pneumonoultramicroscopicsilicovolcanoconiosis", "ultramicroscopic"], ["responsibility", "possibility"], ["internationalization", "localization"], ["characteristic", "architecture"], ["one", "three"], ["three", "one"], ["insertions", "deletions"], ["replacement", "displacement"], ["abcdefghijklmnopqrstuvwxyz", "acegikmoqsuwy"], ["acegikmoqsuwy", "abcdefghijklmnopqrstuvwxyz"], ["aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaa"], ["@javascript:'a'.repeat(500)", "@javascript:'z'.repeat(500)"]], "expected": [3, 5, 0, 1, 1, 3, 3, 0, 1, 2, 0, 1, 1, 2, 3, 3, 2, 2, 2, 0, 6, 3, 3, 4, 1, 1, 2, 3, 6, 5, 4, 3, 7, 4, 6, 8, 8, 5, 8, 2, 2, 10, 10, 1, 10, 29, 4, 10, 11, 4, 4, 4, 3, 13, 13, 40, 500], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "466", "slug": "elimination-game", "id": 466, "title": "Elimination Game", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/elimination-game/", "examples": [{"explanation": "[1..9] -> [2,4,6,8] -> [2,6] -> [6].", "input": "n = 9", "output": "6"}, {"explanation": "A single entry is already the survivor.", "input": "n = 1", "output": "1"}, {"explanation": "[1,2,3,4] -> [2,4] -> [2].", "input": "n = 4", "output": "2"}], "hints": ["Track the first surviving value, the gap between survivors, and how many remain.", "A leftward sweep always moves the head forward by the gap; a rightward sweep moves it only when the count is odd.", "After each sweep halve the count and double the gap, then flip direction."], "statement": "Write the integers `1` through `n` in a row. Then repeatedly thin the row as follows: first sweep from left to right, deleting the first remaining value and then every second value after it; next sweep from right to left, deleting the last remaining value and then every second value before it. Keep alternating the sweep direction until a single value survives, and report it.\n\n**Constraints:**\n- `1 <= n <= 10^9`\n\nSimulating the deletions directly is far too slow for large `n`; track how the leading survivor and the step size evolve instead.\n", "solution": "## Approach\n\nInstead of deleting entries, follow three numbers: the current head value, the spacing between consecutive survivors, and how many values remain. A left-to-right pass always advances the head by the spacing; a right-to-left pass advances it only when the remaining count is odd. Each pass halves the count and doubles the spacing while flipping direction, so the head converges to the survivor in logarithmic time.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n), one iteration per halving of the row.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def lastRemaining(self, n: int) -> int:\n head = 1\n step = 1\n remaining = n\n left = True\n while remaining > 1:\n if left or remaining % 2 == 1:\n head += step\n remaining //= 2\n step *= 2\n left = not left\n return head\n```\n", "starter": {"go": "package main\n\nfunc LastRemaining(n int) int {\n return 0\n}", "python": "class Solution:\n def lastRemaining(self, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int lastRemaining(int n) {\n return 0;\n }\n};"}, "fn": "lastRemaining", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["9"], ["1"], ["4"], ["2"], ["3"], ["5"], ["6"], ["7"], ["8"], ["10"], ["11"], ["12"], ["16"], ["20"], ["50"], ["100"], ["1000"], ["10000"], ["100000"], ["1000000"], ["10000000"], ["100000000"], ["1000000000"], ["999999999"], ["123456789"], ["64"], ["1024"], ["15"], ["21"], ["30"]], "expected": [6, 1, 2, 2, 2, 2, 4, 4, 6, 8, 8, 6, 6, 6, 24, 54, 510, 5974, 55286, 481110, 6150102, 32896342, 534765398, 534765056, 56614230, 22, 342, 8, 6, 16], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "761", "slug": "employee-free-time", "id": 761, "title": "Employee Free Time", "difficulty": "Hard", "category": "interval", "link": "https://leetcode.com/problems/employee-free-time/", "examples": [{"input": "schedule = [[1,2,5,6],[1,3],[4,10]]", "output": "[[3,4]]", "explanation": "Merged busy [1,3],[4,10]; gap 3-4."}, {"input": "schedule = [[1,3,6,7],[2,4],[2,5,9,12]]", "output": "[[5,6],[7,9]]", "explanation": "Merged busy [1,5],[6,7],[9,12]; gaps 5-6,7-9."}], "hints": ["Unflatten each row into [start,end] pairs, pool all pairs, and sort by start time.", "Sweep once keeping the farthest busy end seen; a gap opens whenever the next start exceeds it.", "Record [prevEnd, start] for each gap and extend prevEnd by the max end otherwise."], "statement": "You are given every employee's busy periods in `schedule`. Because the judge has no interval objects, each employee's timetable is flattened into one integer row: `[start0, end0, start1, end1, ...]` holding consecutive `[start, end]` pairs in increasing order with no overlaps.\n\nFor example, an employee busy during `[1,2]` and `[5,6]` appears as `[1,2,5,6]`, so the whole input `[[[1,2],[5,6]],[[1,3]],[[4,10]]]` is encoded as `[[1,2,5,6],[1,3],[4,10]]`.\n\nCombine all busy blocks, merge overlaps, and return the finite gaps where everyone is free, ordered by start time. Zero-length touching points do not count, and the endless stretches before the first meeting and after the last one are ignored.\n\nAdaptation for this judge: the original signature uses nested interval objects; here both the input rows and the output use plain integer arrays, with the output type `int_list_2d` (a list of `[start, end]` pairs).\n\n**Constraints:**\n- `1 <= schedule.length <= 50`\n- Each row holds an even count of entries forming `[start, end]` pairs.\n- `0 <= start < end <= 10^8`\n- Pairs inside one row are sorted and non-overlapping.\n", "solution": "## Approach\n\nDecode each flattened row into its [start,end] pairs and pool everything into one list. Sort by start time, then sweep while tracking the farthest busy end. Whenever the next start lies strictly past that end, the stretch between them is shared free time; otherwise extend the busy cover. This yields gaps in order with no extra merging pass.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(T log T), where T is the total number of busy pairs, dominated by sorting.\n- **Space Complexity:** O(T) for the pooled intervals plus the output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def employeeFreeTime(self, schedule: List[List[int]]) -> List[List[int]]:\n alls = []\n for emp in schedule:\n for i in range(0, len(emp) - 1, 2):\n alls.append([emp[i], emp[i + 1]])\n alls.sort()\n res = []\n if not alls:\n return res\n prev = alls[0][1]\n for s, e in alls[1:]:\n if s > prev:\n res.append([prev, s])\n prev = e\n else:\n prev = max(prev, e)\n return res\n```\n", "starter": {"go": "package main\n\nfunc EmployeeFreeTime(schedule [][]int) [][]int {\n return [][]int{}\n}", "python": "from typing import List\nclass Solution:\n def employeeFreeTime(self, schedule: List[List[int]]) -> List[List[int]]:\n return []", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> employeeFreeTime(vector<vector<int>>& schedule) {\n return {};\n }\n};"}, "fn": "employeeFreeTime", "params": [{"name": "schedule", "type": "int_array_2d"}], "outputType": "int_list_2d", "tests": [["[[1,2,5,6],[1,3],[4,10]]"], ["[[1,3,6,7],[2,4],[2,5,9,12]]"], ["[[1,2,3,4]]"], ["[[1,2]]"], ["[[1,2],[3,4]]"], ["[[1,5],[2,6]]"], ["[[2,4,7,10],[1,5],[6,9]]"], ["[[1,2],[2,3],[3,4]]"], ["[[1,10],[2,3],[4,5],[6,7]]"], ["[[0,5,10,15],[3,7]]"], ["[[1,3],[5,6],[4,10]]"], ["[[1,2,5,6,9,10],[3,4],[7,8]]"], ["[[0,1],[0,1],[0,1]]"], ["[[0,100],[10,20],[30,40]]"], ["[[1,5]]"], ["[[1,2,4,5,7,8]]"], ["[[1,4],[2,3],[5,8],[6,7]]"], ["[[10,20,30,40],[15,25]]"], ["[[0,2],[3,5],[6,8],[9,11]]"], ["[[1,100],[2,3],[4,5]]"], ["[[5,10],[0,3]]"], ["[[1,2,3,4,5,6]]"], ["[[0,5],[6,10],[11,15]]"], ["[[2,3],[4,5],[6,7],[8,9],[10,11]]"], ["[[1,9],[2,4],[6,8]]"], ["[[100,200],[50,60],[70,80]]"], ["[[0,10,20,30],[5,15],[25,35]]"], ["[[3,5,8,10],[1,2],[6,7]]"]], "expected": [[[3, 4]], [[5, 6], [7, 9]], [[2, 3]], [], [[2, 3]], [], [[5, 6]], [], [], [[7, 10]], [[3, 4]], [[2, 3], [4, 5], [6, 7], [8, 9]], [], [], [], [[2, 4], [5, 7]], [[4, 5]], [[25, 30]], [[2, 3], [5, 6], [8, 9]], [], [[3, 5]], [[2, 3], [4, 5]], [[5, 6], [10, 11]], [[3, 4], [5, 6], [7, 8], [9, 10]], [], [[60, 70], [80, 100]], [[15, 20]], [[2, 3], [5, 6], [7, 8]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "705", "slug": "employee-importance", "id": 705, "title": "Employee Importance", "difficulty": "Medium", "category": "hash-table", "link": "https://leetcode.com/problems/employee-importance/", "examples": [{"input": "employees = [[1,5,2,3],[2,3],[3,3]], id = 1", "output": "11", "explanation": "5 + 3 + 3 = 11."}, {"input": "employees = [[1,2,2],[2,3]], id = 2", "output": "3", "explanation": "No reports, so 3."}, {"input": "employees = [[10,4,20,30],[20,2],[30,6,40],[40,1]], id = 10", "output": "13", "explanation": "4 + 2 + 6 + 1 = 13."}], "hints": ["Adaptation: each employee is one integer row [id, importance, sub1, sub2, ...]; build a map from id to its row.", "Walk from the queried id with a stack or queue, adding importance and pushing all listed subordinates.", "A visited set guards against accidental repeats."], "statement": "A company stores its staff as a table. Each row describes one person as `[id, importance, sub1, sub2, ...]`, where `id` is the unique number of the employee, `importance` is their personal score, and any remaining entries list the ids of their direct reports. A row with only two entries has no direct reports.\n\nGiven the whole table `employees` and a starting `id`, add up the importance of that person together with everyone reachable below them through direct and indirect reporting lines.\n\nThis is a portable adaptation: the original object list is flattened into integer rows so that only `int_array_2d` plus `int` are needed. Ids are positive and distinct; every subordinate id appears as some row's id.\n\n**Constraints:**\n- `1 <= employees.length <= 2000`\n- Each row has at least two numbers; `1 <= id <= 2000`\n- `-100 <= importance <= 100`\n- Each employee has at most `100` direct reports.\n", "solution": "## Approach\n\nTranslate each integer row into a lookup from employee id to its importance and subordinate list. Starting from the queried id, perform a stack-based traversal: pop an id, add its importance, and push every unvisited subordinate. Each reachable person is counted once, which naturally includes indirect reports.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + e), where n is the employee count and e the total reporting edges.\n- **Space Complexity:** O(n + e) for the map plus the traversal stack.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def getImportance(self, employees: List[List[int]], id: int) -> int:\n by_id = {r[0]: r for r in employees}\n total = 0\n stack = [id]\n seen = {id}\n while stack:\n cur = stack.pop()\n row = by_id.get(cur)\n if not row:\n continue\n total += row[1]\n for s in row[2:]:\n if s not in seen:\n seen.add(s)\n stack.append(s)\n return total\n```\n", "starter": {"go": "package main\n\nfunc GetImportance(employees [][]int, id int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def getImportance(self, employees: List[List[int]], id: int) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int getImportance(vector<vector<int>>& employees, int id) {\n return 0;\n }\n};"}, "fn": "getImportance", "params": [{"name": "employees", "type": "int_array_2d"}, {"name": "id", "type": "int"}], "outputType": "int", "tests": [["[[1,5,2,3],[2,3],[3,3]]", "1"], ["[[1,2,2],[2,3]]", "2"], ["[[10,4,20,30],[20,2],[30,6,40],[40,1]]", "10"], ["[[1,10]]", "1"], ["[[1,5,2],[2,3,3],[3,4]]", "1"], ["[[1,5,2],[2,3,3],[3,4]]", "2"], ["[[1,1,2,3,4],[2,2],[3,3],[4,4]]", "1"], ["[[5,10,1,2],[1,1],[2,2]]", "5"], ["[[1,-5,2],[2,-3]]", "1"], ["[[1,0,2],[2,0,3],[3,0]]", "1"], ["[[100,1,200],[200,2,300],[300,3]]", "100"], ["[[1,7,2,3],[2,5,4],[3,6],[4,1]]", "1"], ["[[1,7,2,3],[2,5,4],[3,6],[4,1]]", "3"], ["[[2,100,1],[1,1]]", "2"], ["[[1,3,2,3,4,5],[2,1],[3,1],[4,1],[5,1]]", "1"], ["[[1,2],[2,3],[3,4]]", "1"], ["[[1,2,2],[2,3,3],[3,4,4],[4,5]]", "1"], ["[[50,5,51,52],[51,6],[52,7,53],[53,8]]", "50"], ["[[1,100,2,3],[2,1,4],[3,1,4],[4,50]]", "1"], ["[[7,3]]", "7"], ["[[1,4,2],[2,4,3],[3,4,4],[4,4]]", "1"], ["[[9,9,8,7],[8,8,6],[7,7],[6,6]]", "9"], ["[[3,10,1,2],[1,5],[2,6]]", "1"], ["[[3,10,1,2],[1,5],[2,6]]", "3"], ["[[1,1,2],[2,2,3],[3,3,4],[4,4,5],[5,5]]", "1"], ["[[2000,100,1999],[1999,50]]", "2000"], ["[[1,5,2,3,4],[2,10],[3,10],[4,10]]", "1"], ["[[11,2,12],[12,3,13,14],[13,4],[14,5]]", "11"]], "expected": [11, 3, 13, 10, 12, 7, 10, 13, -8, 0, 6, 19, 6, 101, 7, 2, 14, 26, 152, 3, 16, 30, 5, 21, 15, 150, 35, 14], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "59", "slug": "encode-and-decode-strings", "id": 59, "title": "Encode and Decode Strings", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/encode-and-decode-strings/", "examples": [{"input": "strs = [\"hello\",\"world\"]", "output": "[\"hello\",\"world\"]", "explanation": "The encoded string is decoded back to the original list."}, {"input": "strs = [\"\"]", "output": "[\"\"]", "explanation": "A list containing an empty string is preserved."}, {"input": "strs = []", "output": "[]", "explanation": "An empty list remains empty after encoding and decoding."}], "hints": ["Think of a way to delimit each string so that decoding is unambiguous.", "A common approach is to prefix each string with its length followed by a delimiter like '#'.", "During decoding, read the length until the delimiter, then read that many characters as the next string."], "statement": "Design an algorithm to encode **a list of strings** to **a string**. The encoded string is then sent over the network and is decoded back to the original list of strings.\n\nImplement the `Codec` class:\n\n- `String encode(String[] strs)` \u2014 Encodes a list of strings to a single string.\n- `List<String> decode(String s)` \u2014 Decodes a single string back to a list of strings.\n\n**Constraints:**\n- `0 <= strs.length <= 100`\n- `0 <= strs[i].length <= 200`\n- `strs[i]` contains any possible characters (including non-ASCII characters and delimiters).\n", "solution": "## Approach\n\nEncode each string as `length#content` and concatenate. Decode by reading the length prefix delimited by `#`, then extracting that many characters.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the total length of all strings.\n- **Space Complexity:** O(n) for the encoded/decoded output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Codec:\n def encode(self, strs: List[str]) -> str:\n return ''.join(f'{len(s)}#{s}' for s in strs)\n def decode(self, s: str) -> List[str]:\n res, i = [], 0\n while i < len(s):\n j = s.find('#', i)\n l = int(s[i:j])\n i = j + 1\n res.append(s[i:i+l])\n i += l\n return res\nclass Solution:\n def solve(self, strs: List[str]) -> List[str]:\n codec = Codec()\n return codec.decode(codec.encode(strs))\n```\n", "starter": {"go": "package main\n\ntype Codec struct {\n \n}\n\nfunc (c *Codec) Encode(strs []string) string {\n return \"\"\n}\n\nfunc (c *Codec) Decode(s string) []string {\n return []string{}\n}", "python": "from typing import List\n\nclass Codec:\n def encode(self, strs: List[str]) -> str:\n \n\n def decode(self, s: str) -> List[str]:\n ", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Codec {\npublic:\n string encode(vector<string>& strs) {\n \n }\n\n vector<string> decode(string s) {\n \n }\n};"}, "fn": "solve", "params": [{"name": "strs", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"hello\",\"world\"]"], ["[\"\"]"], ["[]"], ["[\"a\",\"b\",\"c\"]"], ["[\"leet\",\"code\",\"love\",\"you\"]"], ["[\"\",\"\",\"\"]"], ["[\" \",\" \",\" \"]"], ["[\"\\\\#\",\"##\",\"#\\\\#\"]"], ["@javascript:JSON.stringify([\"verylongstring\"+\"x\".repeat(186),\"short\"])"], ["[\"special\\ncharacters\\there\",\"unicode\u2713\u2713\u2713\"]"], ["[\"a\"]"], ["[\"\u4f60\u597d\",\"\u4e16\u754c\"]"], ["[\"a/b\", \"c#d\", \"123\", \"\"]"], ["[\"#\", \"##\", \"###\"]"], ["[\"12345\", \"67890\"]"], ["[\"hello#world\", \"foo#bar\"]"], ["[\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"]"], ["[\"ab\", \"ab\", \"ab\"]"], ["[\" \", \" hello \"]"], ["[\"Python\", \"is\", \"fun\"]"], ["[\"x\"]"], ["[\"AaBbCc\", \"123Xyz\"]"], ["[\"!@#$\", \"%^&*\"]"], ["[\"line1\", \"line2\", \"line3\"]"], ["[\"0\", \"00\", \"000\"]"], ["[\"test#123#test\", \"#end\"]"], ["[\"a\", \"aa\", \"aaa\", \"aaaa\"]"], ["[\" hello\", \"world \"]"], ["[\"#0#\", \"#1#\", \"#2#\"]"], ["[\"abcabcabcabcabcabcabcabcabcabc\"]"], ["[\"qwerty\", \"asdf\", \"zxcv\"]"], ["[\"thequickbrownfox\", \"jumps\", \"over\"]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "535", "slug": "encode-and-decode-tinyurl", "id": 535, "title": "Encode and Decode TinyURL", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/encode-and-decode-tinyurl/", "examples": [{"input": "urls = [\"https://leetcode.com/problems/design-tinyurl\"]", "output": "[\"https://leetcode.com/problems/design-tinyurl\"]", "explanation": "decode(encode(url)) returns the original URL. The judge also checks that the short URL starts with http://tinyurl.com/, is stable across repeated encodes, and differs per distinct URL."}, {"input": "urls = [\"https://example.com/a/long/path?q=1\", \"http://x.co\"]", "output": "[\"https://example.com/a/long/path?q=1\", \"http://x.co\"]", "explanation": "One shared Codec handles every URL in the test case: each encodes to its own short link and decodes back."}, {"input": "urls = [\"https://a.com\", \"https://a.com\"]", "output": "[\"https://a.com\", \"https://a.com\"]", "explanation": "Encoding is idempotent: repeats of the same URL reuse the existing short link."}], "hints": ["Keep two maps on the Codec: long URL to code and code back to long URL, plus a counter that mints a fresh code for each unseen address.", "Encode must be idempotent: an already-seen URL gets its existing short link instead of a new one.", "Decode by stripping the http://tinyurl.com/ prefix and looking the code up in the reverse map."], "statement": "Design a URL shortening service by implementing a `Codec` class with two methods:\n\n- `encode(longUrl)` turns a long URL into a short URL that starts with `http://tinyurl.com/` followed by a non-empty code. Encoding must be idempotent: encoding an already-seen URL returns its existing short link. Distinct URLs must map to distinct short links, and a short link must never equal its long URL.\n- `decode(shortUrl)` strips the prefix, looks the code up, and returns the original long URL.\n\nThe judge creates a single `Codec` per test case, encodes every URL twice, decodes the first short link, and checks that both encodes agree, the decoded value equals the input, and the short-link contract above holds for all URLs.\n\n**Constraints:**\n\n- `0 <= urls.length <= 30`\n- `1 <= url.length <= 500`\n- `url` holds printable ASCII characters without spaces or commas (letters, digits, and symbols such as `:/?&=+.-_~@%#`).\n", "solution": "## Approach\n\nBuild a tiny `Codec` with two dictionaries: long URL to code and code back to long URL, plus a counter that mints a fresh code (base-36 of the counter) for each unseen address. Encoding reuses the stored code for repeats so it stays idempotent, and distinct addresses get distinct codes. Decoding strips the `http://tinyurl.com/` prefix before the reverse lookup. The judge drives one shared `Codec` per test case: it encodes every URL twice and decodes the short link, so the maps must persist across calls.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(L) per URL, where L is the URL length, for hashing and string handling.\n- **Space Complexity:** O(L) for the stored entries.\n\n## Implementation\n\n```python\nclass Codec:\n PREFIX = \"http://tinyurl.com/\"\n def __init__(self):\n self.long_to_short = {}\n self.short_to_long = {}\n self.counter = 0\n def encode(self, longUrl):\n if longUrl in self.long_to_short:\n return self.PREFIX + self.long_to_short[longUrl]\n key = self._base36(self.counter)\n self.counter += 1\n self.long_to_short[longUrl] = key\n self.short_to_long[key] = longUrl\n return self.PREFIX + key\n def decode(self, shortUrl):\n key = shortUrl.rsplit('/', 1)[-1]\n return self.short_to_long.get(key, \"\")\n def _base36(self, v):\n digits = \"0123456789abcdefghijklmnopqrstuvwxyz\"\n if v == 0:\n return \"0\"\n out = \"\"\n while v > 0:\n out = digits[v % 36] + out\n v //= 36\n return out\n```\n", "starter": {"go": "package main\n\ntype Codec struct {\n longToShort map[string]string\n shortToLong map[string]string\n counter int\n}\n\n// Encodes a URL to a shortened URL.\nfunc (c *Codec) Encode(longUrl string) string {\n return \"\"\n}\n\n// Decodes a shortened URL to its original URL.\nfunc (c *Codec) Decode(shortUrl string) string {\n return \"\"\n}", "python": "class Codec:\n def encode(self, longUrl: str) -> str:\n # Encodes a URL to a shortened URL.\n pass\n\n def decode(self, shortUrl: str) -> str:\n # Decodes a shortened URL to its original URL.\n pass", "cpp": "#include <string>\n#include <unordered_map>\nusing namespace std;\n\nclass Codec {\npublic:\n // Encodes a URL to a shortened URL.\n string encode(string longUrl) {\n return \"\";\n }\n\n // Decodes a shortened URL to its original URL.\n string decode(string shortUrl) {\n return \"\";\n }\n};"}, "fn": "solve", "params": [{"name": "urls", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"https://leetcode.com/problems/design-tinyurl\"]"], ["[\"https://example.com/a/long/path?q=1\"]"], ["[\"http://x.co\"]"], ["[\"https://a.com\"]"], ["[\"http://example.org/index.html\"]"], ["[\"https://leetcode.com/problems/design-tinyurl\", \"https://example.com/a/long/path?q=1\"]"], ["[\"http://x.co\", \"https://a.com\", \"http://example.org/index.html\"]"], ["[\"https://mysite.io/p1/p2/p3/p4\", \"ftp://files.example.net/pub/data.txt\"]"], ["[\"https://search.test/?q=hello+world&lang=en\", \"http://localhost:8080/api/v1/items\"]"], ["[\"https://en.wikipedia.org/wiki/TinyURL\", \"http://a.b/c?d=e&f=g#h\"]"], ["[\"https://x.io/UPPER/lower/123\", \"https://dots...and---dashes__here.com/x\"]"], ["[\"http://192.168.0.1:3000/status\", \"https://shop.example.com/cart?item=42&qty=3\"]"], ["[\"http://blog.test/2024/05/31/my-post\", \"https://a.io/b?c=d\"]"], ["[\"https://long.sub.domain.example.com/deep/nested/page\", \"http://t.co/abcXYZ012\"]"], ["[\"https://e.com/~user/profile\", \"https://files.test/a+b/c%20d\"]"], ["[\"http://plain-old-http.com/\", \"https://trailing-slash.example.com/path/\"]"], ["[\"https://port.example.com:8443/secure\", \"http://u:p@host.example.com/\"]"], ["[\"https://example.com/emoji-free-zone\", \"https://n1.n2.n3.n4.example.com/\"]"], ["[\"https://query.example.com/?a=1&b=2&c=3&d=4\", \"https://a.com\"]"], ["[\"https://a.com\", \"https://a.com\"]"], ["[\"http://x.co\", \"http://x.co\", \"http://x.co\"]"], ["[\"https://dup.test/1\", \"https://other.test/2\", \"https://dup.test/1\"]"], ["[\"https://s1.test/\", \"https://s2.test/\", \"https://s3.test/\", \"https://s4.test/\", \"https://s5.test/\"]"], ["[\"http://m1.test/a\", \"http://m2.test/b\", \"http://m3.test/c\", \"http://m4.test/d\", \"http://m5.test/e\", \"http://m6.test/f\"]"], ["[\"https://tiny.test/0\", \"https://tiny.test/1\", \"https://tiny.test/2\", \"https://tiny.test/3\", \"https://tiny.test/4\", \"https://tiny.test/5\", \"https://tiny.test/6\", \"https://tiny.test/7\", \"https://tiny.test/8\", \"https://tiny.test/9\"]"], ["[\"https://w0.test/x\", \"https://w1.test/x\", \"https://w2.test/x\", \"https://w3.test/x\", \"https://w4.test/x\", \"https://w5.test/x\", \"https://w6.test/x\", \"https://w7.test/x\", \"https://w8.test/x\", \"https://w9.test/x\", \"https://w10.test/x\", \"https://w11.test/x\", \"https://w12.test/x\", \"https://w13.test/x\", \"https://w14.test/x\", \"https://w15.test/x\", \"https://w16.test/x\", \"https://w17.test/x\", \"https://w18.test/x\", \"https://w19.test/x\"]"], ["[\"https://z0.test/deep/path?q=0&r=0\", \"https://z1.test/deep/path?q=1&r=1\", \"https://z2.test/deep/path?q=2&r=2\", \"https://z3.test/deep/path?q=3&r=3\", \"https://z4.test/deep/path?q=4&r=4\", \"https://z5.test/deep/path?q=5&r=5\", \"https://z6.test/deep/path?q=6&r=6\", \"https://z7.test/deep/path?q=7&r=7\", \"https://z8.test/deep/path?q=8&r=8\", \"https://z9.test/deep/path?q=9&r=9\", \"https://z10.test/deep/path?q=10&r=10\", \"https://z11.test/deep/path?q=11&r=11\", \"https://z12.test/deep/path?q=12&r=12\", \"https://z13.test/deep/path?q=13&r=13\", \"https://z14.test/deep/path?q=14&r=14\", \"https://z15.test/deep/path?q=15&r=15\", \"https://z16.test/deep/path?q=16&r=16\", \"https://z17.test/deep/path?q=17&r=17\", \"https://z18.test/deep/path?q=18&r=18\", \"https://z19.test/deep/path?q=19&r=19\", \"https://z20.test/deep/path?q=20&r=20\", \"https://z21.test/deep/path?q=21&r=21\", \"https://z22.test/deep/path?q=22&r=22\", \"https://z23.test/deep/path?q=23&r=23\", \"https://z24.test/deep/path?q=24&r=24\", \"https://z25.test/deep/path?q=25&r=25\", \"https://z26.test/deep/path?q=26&r=26\", \"https://z27.test/deep/path?q=27&r=27\", \"https://z28.test/deep/path?q=28&r=28\", \"https://z29.test/deep/path?q=29&r=29\"]"], ["[]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "500", "slug": "encode-n-ary-tree-to-binary-tree", "id": 500, "title": "Encode N-ary Tree to Binary Tree", "difficulty": "Hard", "category": "tree", "link": "https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree/", "examples": [{"input": "data = \"[1,null,3,2,4,null,5,6]\"", "output": "\"[1,null,3,2,4,null,5,6]\"", "explanation": "The N-ary tree encodes to binary as [1,3,null,5,2,null,6,null,4] (first child left, siblings right) and decodes back to the canonical N-ary form."}, {"input": "data = \"[]\"", "output": "\"[]\"", "explanation": "Empty trees round-trip to themselves."}, {"input": "data = \"[1]\"", "output": "\"[1]\"", "explanation": "A single node has no children, so the binary form is just [1]."}], "hints": ["Parse the N-ary text breadth-first: each null starts the child group of the next queued node.", "Encode with the left-child right-sibling rule: first child becomes the left link, later siblings chain through right links.", "Decode by walking left once for the first child, then right repeatedly for the remaining siblings.", "Emit the binary tree in level order with null placeholders and trailing nulls trimmed, e.g. [1,3,null,5,2,null,6,null,4]."], "statement": "An N-ary tree and a binary tree can stand in for each other through the left-child right-sibling encoding: a node's first child becomes its left link, and each sibling becomes the previous sibling's right link.\n\nImplement a `Codec` class with two methods that work on level-order text:\n\n- `encode(naryData)` parses an N-ary tree from breadth-first text (`null` separates sibling groups, e.g. `[1,null,3,2,4,null,5,6]`) and returns the converted binary tree as level-order text with `null` placeholders for missing children and trailing nulls trimmed (e.g. `[1,3,null,5,2,null,6,null,4]`). An empty tree encodes to `[]`.\n- `decode(binaryData)` parses that binary level-order text and returns the canonical N-ary breadth-first text (trailing empty groups dropped, `[]` for empty).\n\nThe judge creates one `Codec` per test case, encodes the input twice, decodes the first binary string, and checks that both encodes agree, the decoded text equals the canonical N-ary form, and the binary text parses to exactly the left-child right-sibling structure of the input. Inputs are already canonical; your binary text must still earn its structure \u2014 echoing the input fails the structural check.\n\n**Constraints:**\n- Node count lies in `[0, 10^4]`.\n- Values are integers.\n", "solution": "## Approach\n\nParse the N-ary string breadth-first, then apply left-child right-sibling encoding to reach binary form: the first child becomes the left link and later siblings chain through right links. Emit the binary tree in level order with `null` placeholders (trailing nulls trimmed). Decoding parses that binary text, walks left once then right repeatedly to rebuild each child list, and serializes the restored N-ary tree canonically.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the token and node count across parse, encode, decode, and serialize.\n- **Space Complexity:** O(m) for the intermediate trees.\n\n## Implementation\n\n```python\nfrom collections import deque\nclass Codec:\n def _toks(self, s):\n s = (s or \"\").strip()\n if s in (\"\", \"[]\"):\n return []\n inner = s[1:-1] if s.startswith(\"[\") else s\n return [t.strip() for t in inner.split(\",\") if t.strip() != \"\"]\n def _parse_nary(self, data):\n toks = self._toks(data)\n if not toks or toks[0] == \"null\":\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 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 _parse_binary(self, data):\n toks = self._toks(data)\n if not toks or toks[0] == \"null\":\n return None\n class B:\n def __init__(self, v):\n self.val = int(v)\n self.left = None\n self.right = None\n root = B(toks[0])\n q = deque([root])\n i = 1\n while q and i < len(toks):\n node = q.popleft()\n if toks[i] != \"null\":\n node.left = B(toks[i])\n q.append(node.left)\n i += 1\n if i < len(toks) and toks[i] != \"null\":\n node.right = B(toks[i])\n q.append(node.right)\n i += 1\n return root\n def _encode(self, n):\n if n is None:\n return None\n class B:\n def __init__(self, v):\n self.val = v\n self.left = None\n self.right = None\n b = B(n.val)\n if n.children:\n b.left = self._encode(n.children[0])\n cur = b.left\n for ch in n.children[1:]:\n cur.right = self._encode(ch)\n cur = cur.right\n return b\n def _decode(self, b):\n if b is None:\n return None\n class N:\n def __init__(self, v):\n self.val = v\n self.children = []\n n = N(b.val)\n c = b.left\n while c is not None:\n n.children.append(self._decode(c))\n c = c.right\n return n\n def _ser_binary(self, root):\n if root is None:\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 _ser_nary(self, 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 q.extend(n.children)\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 parts.extend(str(c.val) for c in order[g])\n return \"[\" + \",\".join(parts) + \"]\"\n def encode(self, naryData):\n return self._ser_binary(self._encode(self._parse_nary(naryData)))\n def decode(self, binaryData):\n return self._ser_nary(self._decode(self._parse_binary(binaryData)))\n```\n", "starter": {"go": "package main\n\ntype Codec struct {\n}\n\n// Encodes an N-ary tree (level-order text) to a binary tree (level-order text).\nfunc (c *Codec) Encode(naryData string) string {\n return \"\"\n}\n\n// Decodes a binary tree (level-order text) back to canonical N-ary level-order text.\nfunc (c *Codec) Decode(binaryData string) string {\n return \"\"\n}", "python": "class Codec:\n def encode(self, naryData: str) -> str:\n # Encodes an N-ary tree (level-order text) to a binary tree (level-order text).\n pass\n\n def decode(self, binaryData: str) -> str:\n # Decodes a binary tree (level-order text) back to canonical N-ary level-order text.\n pass", "cpp": "#include <string>\nusing namespace std;\n\nclass Codec {\npublic:\n // Encodes an N-ary tree (level-order text) to a binary tree (level-order text).\n string encode(string naryData) {\n return \"\";\n }\n\n // Decodes a binary tree (level-order text) back to canonical N-ary level-order text.\n string decode(string binaryData) {\n return \"\";\n }\n};"}, "fn": "solve", "params": [{"name": "data", "type": "string"}], "outputType": "string_list", "tests": [["[1,null,3,2,4,null,5,6]"], ["[]"], ["[1]"], ["[1,null,2]"], ["[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]"], ["[1,null,2,null,3]"], ["[2,null,1]"], ["[1,null,2,3,4]"], ["[1,null,5]"], ["[3,null,1,2]"], ["[1,null,2,null,3,4]"], ["[1,null,2,3,null,4,5]"], ["[2,null,3,4]"], ["[1,null,2,null,3,null,4]"], ["[4,null,1,2,3,4]"], ["[1,null,2,3,4,5,6]"], ["[7,null,1]"], ["[1,null,2,null,4,5,null,6]"], ["[10,null,20,30]"], ["[1,null,2,3,null,4,null,5]"], ["[5,null,6,7,8,null,9]"], ["[1,null,3,null,5,6,null,7,8]"], ["[2,null,1,null,3,null,4,null,5]"], ["[100,null,200]"], ["[1,null,2,3,4,null,5,null,6,7]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "536", "slug": "encode-string-with-shortest-length", "id": 536, "title": "Encode String with Shortest Length", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/encode-string-with-shortest-length/", "examples": [{"input": "s = \"aaa\"", "output": "\"aaa\"", "explanation": "Encoding as \"3[a]\" would be longer (4 vs 3), so the original string stays."}, {"input": "s = \"aaaaa\"", "output": "\"5[a]\"", "explanation": "Five copies of \"a\" compress to \"5[a]\"."}, {"input": "s = \"ababab\"", "output": "\"3[ab]\"", "explanation": "Three copies of \"ab\" compress to \"3[ab]\"."}, {"input": "s = \"abbbabbbcabbbabbbc\"", "output": "\"2[2[abbb]c]\"", "explanation": "The inner block \"abbbabbbc\" first compresses to \"2[abbb]c\", and doubling it gives the shortest form."}], "hints": ["Let dp[i][j] be the shortest encoding of the slice s[i..j]: split it at every k and keep the best concatenation.", "Also test whether the whole slice is a repetition of a smaller block, using the doubled-string trick to find the period."], "statement": "You are given a string `s` of lowercase letters. Encode it with the shortest possible length using the form `k[pattern]`, where `pattern` is an encoded string and `k` is a positive integer meaning the pattern repeats `k` times. Encodings may nest, e.g. `2[a3[b]]` expands to `\"abbbabbb\"`.\n\nEncoding a slice is worthwhile only when the `k[...]` form is strictly shorter than the slice itself; otherwise keep the slice as is. If several encodings tie for the shortest length, any of them is acceptable.\n\nReturn an encoding of the whole string with the minimum possible length.\n\n**Constraints:**\n- `1 <= s.length <= 150`\n- `s` consists of lowercase English letters.\n", "solution": "## Approach\n\nBuild a table where `dp[i][j]` holds the shortest encoding of the slice `s[i..j]`, growing the slices from short to long. For each slice, first try every split point and keep the best concatenation of the two halves, then check whether the whole slice repeats a smaller block: the doubled-string search reveals the shortest period, and the candidate `rep[best-encoding-of-period]` replaces the entry when shorter. Nesting comes for free because periods use their own optimal encodings.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^3), from the O(n^2) slices times the split scan.\n- **Space Complexity:** O(n^2) for the encoding table.\n\n## Implementation\n\n```python\nclass Solution:\n def encode(self, s: str) -> str:\n n = len(s)\n dp = [[\"\"] * n for _ in range(n)]\n for ln in range(1, n + 1):\n for i in range(n - ln + 1):\n j = i + ln - 1\n dp[i][j] = s[i:j + 1]\n for k in range(i, j):\n if len(dp[i][k]) + len(dp[k + 1][j]) < len(dp[i][j]):\n dp[i][j] = dp[i][k] + dp[k + 1][j]\n sub = s[i:j + 1]\n idx = (sub + sub).find(sub, 1)\n if idx < len(sub):\n rep = len(sub) // idx\n cand = f\"{rep}[{dp[i][i + idx - 1]}]\"\n if len(cand) < len(dp[i][j]):\n dp[i][j] = cand\n return dp[0][n - 1]\n```\n", "starter": {"go": "package main\n\nfunc Encode(s string) string {\n \n}", "python": "class Solution:\n def encode(self, s: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string encode(string s) {\n return \"\";\n }\n};"}, "fn": "encode", "params": [{"name": "s", "type": "string"}], "outputType": "string", "tests": [["aaa"], ["aaaaa"], ["ababab"], ["abbbabbbcabbbabbbc"], ["a"], ["ab"], ["abcd"], ["aaaaaaaaaa"], ["abcabcabc"], ["aabcaabcd"], ["ababcdababcd"], ["xyzxyzxyzxyz"], ["aaaaaaaaaab"], ["aabbaa"], ["abababababababababababababababababababababababababababababab"], ["abcde"], ["aaaa"], ["abab"], ["abcabcab"], ["aaaaaaaa"], ["xyzxyz"], ["ababa"], ["aabbcc"], ["abcabcdabcabcd"], ["zzzzzzzzzzz"], ["abcdefghij"], ["abababab"], ["aaabaaab"]], "expected": ["aaa", "5[a]", "3[ab]", "2[2[abbb]c]", "a", "ab", "abcd", "a9[a]", "3[abc]", "2[aabc]d", "2[ababcd]", "4[xyz]", "a9[a]b", "aabbaa", "30[ab]", "abcde", "aaaa", "abab", "abcabcab", "8[a]", "xyzxyz", "ababa", "aabbcc", "2[abcabcd]", "11[z]", "abcdefghij", "4[ab]", "2[aaab]"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "958", "slug": "equal-rational-numbers", "id": 958, "title": "Equal Rational Numbers", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/equal-rational-numbers/", "examples": [{"input": "s = \"0.(52)\", t = \"0.5(25)\"", "output": "true", "explanation": "Both spellings expand to 0.525252..., so they name the same value."}, {"input": "s = \"0.1666(6)\", t = \"0.166(66)\"", "output": "true", "explanation": "Both spellings expand to 0.166666..., so they match."}, {"input": "s = \"0.9(9)\", t = \"1.\"", "output": "true", "explanation": "A trailing infinite run of 9s carries over, giving 0.999... which equals 1."}], "hints": ["Split each spelling into integer part, non-repeating decimals, and parenthesized repeating block.", "Convert each spelling to an exact fraction: with a non-repeat length a and repeat length b, the denominator involves 10^a * (10^b - 1).", "Compare the two fractions by cross multiplication instead of floating point."], "statement": "Two strings `s` and `t` each describe a decimal number. The format is an integer part, optionally followed by a dot and decimals, where a trailing block in parentheses repeats forever. For instance, `0.(52)` means `0.525252...` and `0.955(72)` means `0.9557272...`. A spelling such as `1.` has no fractional digits.\n\nDecide whether the two spellings name the same numeric value. Note that different spellings can coincide: trailing repeating `9`s round up (`0.9(9)` equals `1.`), and the split between repeating and non-repeating digits is not unique (`0.1666(6)` equals `0.166(66)`).\n\nReturn `true` when the values are equal and `false` otherwise.\n\n**Constraints:**\n- Each spelling contains digits, at most one `.`, and at most one `(...)` block at the end.\n- The repeating block, when present, holds 1 to 4 digits.\n- The integer part holds 1 to 3 digits.\n", "solution": "## Approach\n\nParse each spelling into integer part, non-repeating decimals, and the parenthesized repeating block. With a non-repeat of length a and a repeat of length b, the value equals integer plus nonRepeat / 10^a plus repeat / (10^a * (10^b - 1)). Scaling everything to the common denominator 10^a * (10^b - 1) gives an exact numerator using integers only. Comparing the two fractions by cross multiplication avoids any floating-point error and naturally handles cases like repeating 9s.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the spelling length. Parsing and the power computations touch only a few digits.\n- **Space Complexity:** O(n) for the parsed substrings and big integers.\n\n## Implementation\n\n```python\nclass Solution:\n def isRationalEqual(self, s: str, t: str) -> bool:\n def parse(sp):\n dot = sp.find('.')\n if dot < 0:\n p = sp.find('(')\n int_part = sp if p < 0 else sp[:p]\n frac = ''\n else:\n int_part = sp[:dot] or '0'\n frac = sp[dot + 1:]\n o = frac.find('(')\n if o >= 0:\n non = frac[:o]\n rep = frac[o + 1:frac.find(')', o)]\n else:\n non, rep = frac, ''\n ip = int(int_part)\n a, b = len(non), len(rep)\n pa = 10 ** a\n if b == 0:\n num = ip if a == 0 else ip * pa + (int(non) if non else 0)\n return (num, max(pa, 1))\n pb = 10 ** b\n bm1 = pb - 1\n den = pa * bm1\n nr = int(non) if non else 0\n r = int(rep) if rep else 0\n num = ip * den + nr * bm1 + r\n return (num, den)\n n1, d1 = parse(s)\n n2, d2 = parse(t)\n return n1 * d2 == n2 * d1\n```\n", "starter": {"go": "package main\n\nfunc IsRationalEqual(s string, t string) bool {\n \n}", "python": "class Solution:\n def isRationalEqual(self, s: str, t: str) -> bool:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool isRationalEqual(string s, string t) {\n return false;\n }\n};"}, "fn": "isRationalEqual", "params": [{"name": "s", "type": "string"}, {"name": "t", "type": "string"}], "outputType": "boolean", "tests": [["0.(52)", "0.5(25)"], ["0.1666(6)", "0.166(66)"], ["0.9(9)", "1."], ["0.5", "0.5(0)"], ["0.5", "0.4(9)"], ["1.0", "1."], ["0.(9)", "1."], ["0.8(9)", "0.9"], ["0.1(6)", "0.1666(6)"], ["0.12", "0.12(0)"], ["0.12", "0.119(9)"], ["0.0(0)", "0."], ["1.5(0)", "1.5"], ["2.3(4)", "2.3(5)"], ["0.99(9)", "1."], ["0.00(1)", "0.001(1)"], ["123.45(67)", "123.45(67)"], ["0.(1)", "0.111(1)"], ["0.(01)", "0.0(101)"], ["0.2(5)", "0.25(5)"], ["0.58(3)", "0.583(3)"], ["0.83(3)", "0.8(3)"], ["1.9(9)", "2."], ["0.(0)", "0.0"], ["10.5(25)", "10.52(5)"], ["0.123(456)", "0.123(457)"], ["0.12(34)", "0.123(43)"], ["0.7", "0.8"]], "expected": [true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, false, true, true, true, true, true, false, false, true, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "682", "slug": "equal-tree-partition", "id": 682, "title": "Equal Tree Partition", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/equal-tree-partition/", "examples": [{"input": "root = [5,10,10,null,null,2,3]", "output": "true", "explanation": "Cutting the edge to the right child splits 25 into 10 + 15? Actually left 10 plus right 15? The right branch sums to 15 and the remainder 15? Total 30 halves into 15 and 15."}, {"input": "root = [1,2,10,null,null,2,20]", "output": "false", "explanation": "Total 35 is odd, so no single cut can halve it."}], "hints": ["Add up the whole tree first; a valid cut needs total to be even.", "A cut works exactly when some proper branch sums to total / 2.", "Collect branch sums with one post-order walk, excluding the full tree itself."], "statement": "You are given the root of a binary tree.\n\nDecide whether cutting exactly one edge can divide the tree into two trees with equal sums.\n\n**Constraints:**\n- `1 <= number of nodes <= 10^4`\n- `-1000 <= node value <= 1000`\n", "solution": "## Approach\n\nTotal the tree. A single cut can only work when the total is even, splitting into two halves of `total / 2`. A post-order walk computes every branch sum; if any proper branch (anything but the whole tree) hits the half value, the answer is true.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) across two walks.\n- **Space Complexity:** O(h) recursion depth.\n\n## Implementation\n\n```python\nclass Solution:\n def checkEqualTree(self, root) -> bool:\n def total(n):\n if not n:\n return 0\n return n.val + total(n.left) + total(n.right)\n s = total(root)\n if s % 2 != 0:\n return False\n self.ok = False\n def dfs(n):\n if not n:\n return 0\n cur = n.val + dfs(n.left) + dfs(n.right)\n if n is not root and cur == s // 2:\n self.ok = True\n return cur\n dfs(root)\n return self.ok\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 CheckEqualTree(root *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 checkEqualTree(self, root) -> bool:\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 bool checkEqualTree(TreeNode* root) {\n return false;\n }\n};"}, "fn": "checkEqualTree", "params": [{"name": "root", "type": "tree_node"}], "outputType": "boolean", "tests": [["[5,10,10,null,null,2,3]"], ["[1,2,10,null,null,2,20]"], ["[0]"], ["[1,1]"], ["[2,2,2,2,2]"], ["[1,2,3]"], ["[0,0,0]"], ["[5,5]"], ["[10,5,5]"], ["[1,null,1,null,1]"], ["[4,2,6,1,3,5,7]"], ["[0,1,-1]"], ["[2,3,5,4,null,null,1]"], ["[1,2,3,4,5,6,7]"], ["[6,3,9,1,4,8,10]"], ["[-5,3,2]"], ["[1,1,1,1]"], ["[10,10,null,10,null,10]"], ["[3,3,3,3]"], ["[0,0]"], ["[7,3,9,1,5,null,10]"], ["[2,2,2]"], ["[8,4,12,2,6,10,14]"], ["[1,2,null,3,null,4]"], ["[5,-2,7]"], ["[100,50,50]"], ["[1,2,10,4,null,null,8]"], ["[0,2,2]"]], "expected": [true, false, false, true, false, true, true, true, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, false, false, false, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "629", "slug": "erect-the-fence", "id": 629, "title": "Erect the Fence", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/erect-the-fence/", "examples": [{"input": "trees = [[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]", "output": "[[1,1],[2,0],[4,2],[3,3],[2,4]]", "explanation": "These five points wrap all trees; interior points stay inside."}, {"input": "trees = [[1,2],[2,2],[4,2]]", "output": "[[1,2],[2,2],[4,2]]", "explanation": "All three lie on one line, so all belong to the boundary."}, {"input": "trees = [[0,0],[1,0],[2,0]]", "output": "[[0,0],[1,0],[2,0]]", "explanation": "Collinear points are all kept."}], "hints": ["Sort points and build the convex hull; points lying on hull edges count as boundary too.", "After finding hull corners, scan every input point for collinearity with each hull edge and keep those between the endpoints.", "Compare squared distances to avoid floating point; order of the answer does not matter.", "Adaptation: the nested output maps to int_list_2d in this judge."], "statement": "A set of trees stands at integer coordinates. Imagine stretching a rope around the whole set so it touches the outermost trees; every tree that the rope touches or that lies exactly on a rope segment belongs to the fence.\n\nGiven `trees` as points, return the points on the fence boundary, including collinear points along the edges. The order does not matter.\n\n**Constraints:**\n- `1 <= trees.length <= 100`\n- `-100 <= trees[i][j] <= 100`\n- Points are distinct in the tests.\n\nAdaptation: the nested input maps to int_array_2d and the nested output maps to int_list_2d in this judge.\n", "solution": "## Approach\n\nSort the points and build the extreme corners with a monotone chain that drops clockwise turns. Those corners alone miss trees lying flat on an edge, so each hull segment is rescanned and every collinear input point between its endpoints is added as well.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting plus O(h*n) edge scans.\n- **Space Complexity:** O(n) for sorted points and the hull.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def outerTrees(self, trees: List[List[int]]) -> List[List[int]]:\n pts = sorted(map(tuple, trees))\n if len(pts) <= 3:\n return [list(p) for p in pts]\n def cross(a, b, c):\n return (b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0])\n lower = []\n for p in pts:\n while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 0:\n lower.pop()\n lower.append(p)\n upper = []\n for p in reversed(pts):\n while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:\n upper.pop()\n upper.append(p)\n hull = lower[:-1] + upper[:-1]\n seen = set(hull)\n for i in range(len(hull)):\n a, b = hull[i], hull[(i+1) % len(hull)]\n for p in pts:\n if cross(a, b, p) == 0 and min(a[0],b[0]) <= p[0] <= max(a[0],b[0]) and min(a[1],b[1]) <= p[1] <= max(a[1],b[1]):\n seen.add(p)\n return [list(p) for p in seen]\n```\n", "starter": {"go": "package main\n\nfunc OuterTrees(trees [][]int) [][]int {\n return [][]int{}\n}", "python": "from typing import List\nclass Solution:\n def outerTrees(self, trees: List[List[int]]) -> List[List[int]]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> outerTrees(vector<vector<int>>& trees) {\n return {};\n }\n};"}, "fn": "outerTrees", "params": [{"name": "trees", "type": "int_array_2d"}], "outputType": "int_list_2d", "tests": [["[[1,1],[2,2],[2,0],[2,4],[3,3],[4,2]]"], ["[[1,2],[2,2],[4,2]]"], ["[[0,0],[1,0],[2,0]]"], ["[[0,0]]"], ["[[0,0],[1,1]]"], ["[[0,0],[0,1],[1,0],[1,1]]"], ["[[0,0],[0,2],[2,0],[2,2],[1,1]]"], ["[[0,0],[0,4],[4,0],[4,4],[2,0],[0,2]]"], ["[[1,1],[2,2],[3,3],[3,1],[2,0]]"], ["[[3,0],[4,0],[5,0],[3,1],[3,2]]"], ["[[0,0],[1,0],[2,0],[0,1],[0,2]]"], ["[[0,0],[2,0],[1,1],[0,2],[2,2]]"], ["[[1,0],[2,0],[3,0],[2,1]]"], ["[[0,0],[1,1],[2,2],[3,3]]"], ["[[5,5],[6,6],[5,6],[6,5]]"], ["[[0,0],[3,0],[0,3],[1,1],[2,2],[3,3]]"], ["[[0,0],[4,0],[4,4],[0,4],[1,0],[2,0],[3,0]]"], ["[[0,0],[4,0],[4,4],[0,4],[4,1],[4,2],[4,3]]"], ["[[2,2],[4,2],[3,3],[2,4],[4,4]]"], ["[[0,1],[1,0],[1,2],[2,1],[1,1]]"], ["[[0,0],[10,0],[10,10],[0,10],[5,0]]"], ["[[1,1],[1,3],[3,1],[3,3],[2,2]]"], ["[[0,0],[2,1],[1,2],[3,3],[4,0]]"], ["[[6,8],[4,8],[8,6],[8,10],[2,6]]"], ["[[0,0],[1,0],[0,1],[1,1],[0,2],[2,0]]"], ["[[7,7],[7,8],[8,7],[8,8],[7,9]]"], ["[[0,0],[5,0],[0,5],[2,0],[0,2]]"], ["[[3,3],[5,5],[7,7],[3,7],[7,3]]"]], "expected": [[[1, 1], [2, 0], [4, 2], [2, 4], [3, 3]], [[1, 2], [2, 2], [4, 2]], [[0, 0], [1, 0], [2, 0]], [[0, 0]], [[0, 0], [1, 1]], [[0, 0], [1, 0], [1, 1], [0, 1]], [[0, 0], [2, 0], [2, 2], [0, 2]], [[0, 0], [4, 0], [4, 4], [0, 4], [2, 0], [0, 2]], [[1, 1], [2, 0], [3, 1], [3, 3], [2, 2]], [[3, 0], [5, 0], [3, 2], [4, 0], [3, 1]], [[0, 0], [2, 0], [0, 2], [1, 0], [0, 1]], [[0, 0], [2, 0], [2, 2], [0, 2]], [[1, 0], [3, 0], [2, 1], [2, 0]], [[0, 0], [3, 3], [1, 1], [2, 2]], [[5, 5], [6, 5], [6, 6], [5, 6]], [[0, 0], [3, 0], [3, 3], [0, 3]], [[0, 0], [4, 0], [4, 4], [0, 4], [1, 0], [2, 0], [3, 0]], [[0, 0], [4, 0], [4, 4], [0, 4], [4, 1], [4, 2], [4, 3]], [[2, 2], [4, 2], [4, 4], [2, 4]], [[0, 1], [1, 0], [2, 1], [1, 2]], [[0, 0], [10, 0], [10, 10], [0, 10], [5, 0]], [[1, 1], [3, 1], [3, 3], [1, 3]], [[0, 0], [4, 0], [3, 3], [1, 2]], [[2, 6], [8, 6], [8, 10], [4, 8]], [[0, 0], [2, 0], [0, 2], [1, 0], [1, 1], [0, 1]], [[7, 7], [8, 7], [8, 8], [7, 9], [7, 8]], [[0, 0], [5, 0], [0, 5], [2, 0], [0, 2]], [[3, 3], [7, 3], [7, 7], [3, 7]]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "787", "slug": "escape-the-ghosts", "id": 787, "title": "Escape The Ghosts", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/escape-the-ghosts/", "examples": [{"input": "ghosts = [[1,0],[0,3]], target = [0,1]", "output": "true", "explanation": "You need 1 step while the closest ghost needs at least 2."}, {"input": "ghosts = [[1,0]], target = [2,0]", "output": "false", "explanation": "The ghost sits on the way and arrives first."}, {"input": "ghosts = [[2,0]], target = [1,0]", "output": "false", "explanation": "A tie still counts as a capture."}], "hints": ["On an open grid the shortest route length is the Manhattan distance.", "Compute your distance from the origin and each ghost's distance to the target.", "You escape exactly when your distance is strictly smaller than every ghost distance."], "statement": "You begin at the origin `(0, 0)` of an endless grid and want to reach a\ndestination cell `target = [xt, yt]`. Several ghosts start from the cells\nlisted in `ghosts`, where each entry is `[xg, yg]`. Every turn, you and each\nghost may independently stay put or step one cell north, south, east, or\nwest, all moving at once.\n\nYou succeed exactly when you can step onto the destination strictly before\nany ghost could get there (ghosts play optimally to intercept). If a ghost\ncan arrive at the same time as you or earlier \u2014 even by heading straight\nfor the target \u2014 the escape fails. Because the grid is open, only the\nshortest-path distances matter, measured with Manhattan steps.\n\n**Constraints:**\n- `1 <= ghosts.length <= 100`\n- `ghosts[i].length == 2`\n- `-10^4 <= xg, yg <= 10^4`\n- `-10^4 <= xt, yt <= 10^4`\n- Several ghosts may share a cell.\n", "solution": "## Approach\n\nWithout obstacles the fastest route between two cells uses exactly the\nManhattan distance. Measure how far you must walk from the origin to the\ndestination and how far each ghost must walk to that same cell. You win when\nyour distance is strictly less than every ghost distance; otherwise a ghost\ncan arrive first or at the same moment and block you.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(g), where g is the ghost count.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool:\n me = abs(target[0]) + abs(target[1])\n for x, y in ghosts:\n if abs(x - target[0]) + abs(y - target[1]) <= me:\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc EscapeGhosts(ghosts [][]int, target []int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def escapeGhosts(self, ghosts: List[List[int]], target: List[int]) -> bool:\n return False\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool escapeGhosts(vector<vector<int>>& ghosts, vector<int>& target) {\n return false;\n }\n};"}, "fn": "escapeGhosts", "params": [{"name": "ghosts", "type": "int_array_2d"}, {"name": "target", "type": "int_array"}], "outputType": "boolean", "tests": [["[[1,0],[0,3]]", "[0,1]"], ["[[1,0]]", "[2,0]"], ["[[2,0]]", "[1,0]"], ["[[5,0],[-10,-2],[0,-5],[-2,-2],[-7,1]]", "[7,7]"], ["[[-1,0],[0,1],[-1,0],[0,1],[-1,0]]", "[0,0]"], ["[[0,0]]", "[1,1]"], ["[[10,10]]", "[1,1]"], ["[[0,3],[1,0]]", "[0,1]"], ["[[1,9],[2,-5],[3,8],[4,3],[5,-4]]", "[8,-9]"], ["[[0,0],[0,0]]", "[0,0]"], ["[[10000,10000]]", "[10000,10000]"], ["[[-10000,-10000]]", "[10000,10000]"], ["[[2,2],[3,3]]", "[1,1]"], ["[[0,1]]", "[0,2]"], ["[[0,5]]", "[0,2]"], ["[[3,0]]", "[0,0]"], ["[[1,1],[2,2],[3,3]]", "[0,0]"], ["[[4,4]]", "[2,2]"], ["[[0,0]]", "[5,5]"], ["[[6,6]]", "[5,5]"], ["[[1,0],[2,0],[3,0]]", "[5,0]"], ["[[10,0]]", "[5,0]"], ["[[-5,-5],[5,5]]", "[0,1]"], ["[[0,-3]]", "[0,3]"], ["[[1,1]]", "[3,3]"], ["[[7,7]]", "[3,3]"], ["[[0,2],[2,0]]", "[1,1]"], ["[[5,5],[5,5],[5,5]]", "[1,1]"]], "expected": [true, false, false, false, true, false, true, true, false, false, false, true, false, false, true, true, true, false, false, false, false, false, true, true, false, true, false, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "221", "slug": "evaluate-division", "id": 221, "title": "Evaluate Division", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/evaluate-division/", "examples": [{"input": "equations = [[\"a\",\"b\"],[\"b\",\"c\"]], values = [2.0,3.0], queries = [[\"a\",\"c\"],[\"b\",\"a\"],[\"a\",\"e\"],[\"a\",\"a\"],[\"x\",\"x\"]]", "output": "[6.00000,0.50000,-1.00000,1.00000,-1.00000]"}, {"input": "equations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"bc\",\"cd\"]], values = [1.5,2.5,5.0], queries = [[\"a\",\"c\"],[\"c\",\"b\"],[\"bc\",\"cd\"],[\"cd\",\"bc\"]]", "output": "[3.75000,0.40000,5.00000,0.20000]"}], "hints": ["Build a weighted graph of variables. For each query BFS/DFS to compute the product of edge weights.", "Note: values and answers are decimal strings (e.g. \"2.0\", \"-1.0\") because Cojudge has no double type."], "statement": "You obtain a list of variable pairs `equations` together with a list of real numbers `values`, where `equations[i] = [Ai, Bi]` paired with `values[i]` states the relation `Ai / Bi = values[i]`. Every `Ai` or `Bi` denotes one variable by name.\n\nYou also obtain a batch of `queries`, where `queries[j] = [Cj, Dj]` poses the `j`-th request for the value of `Cj / Dj = ?`.\n\nCompute a response for every query in order. Whenever a requested ratio cannot be deduced from the supplied relations, answer `-1.0` for that position.\n\n**Note:** Every supplied input is consistent: no query forces division by zero and the relations contain no conflicts. Because decimal handling differs here, Cojudge passes `values` and expected answers around as decimal strings (for instance `\"2.0\"`, `\"-1.00000\"`).\n\n**Constraints:**\n- `1 <= equations.length <= 20`\n- `equations[i].length == 2`\n- `1 <= Ai.length, Bi.length <= 5`\n- `values.length == equations.length`\n- `0.0 < values[i] <= 20.0`\n- `1 <= queries.length <= 20`\n- `queries[i].length == 2`\n- `1 <= Cj.length, Dj.length <= 5`\n- `Ai, Bi, Cj, Dj` consist of lower case English letters and digits\n", "solution": "## Approach\n\nBuild a weighted bidirectional graph. For each query DFS/BFS from the source, multiplying edge weights until the destination is reached.\n\n## Complexity Analysis\n\n- **Time Complexity:** O((N+Q) * V) where V is number of variables\n- **Space Complexity:** O(V^2)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def calcEquation(self, equations: List[List[str]], values: List[str], queries: List[List[str]]) -> List[str]:\n from collections import defaultdict\n g = defaultdict(dict)\n for i, eq in enumerate(equations):\n a, b = eq[0], eq[1]\n v = float(values[i])\n g[a][b] = v\n g[b][a] = 1.0 / v\n def dfs(src, dst, seen):\n if src not in g or dst not in g:\n return -1.0\n if src == dst:\n return 1.0\n seen.add(src)\n for nb, w in g[src].items():\n if nb in seen:\n continue\n sub = dfs(nb, dst, seen)\n if sub != -1.0:\n return w * sub\n return -1.0\n def fmt(x):\n if x < 0:\n return \"-1.00000\"\n return f\"{x:.5f}\"\n return [fmt(dfs(q[0], q[1], set())) for q in queries]\n```\n", "starter": {"go": "package main\n\nfunc CalcEquation(equations [][]string, values []string, queries [][]string) []string {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def calcEquation(self, equations: List[List[str]], values: List[str], queries: List[List[str]]) -> List[str]:\n ", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> calcEquation(vector<vector<string>>& equations, vector<string>& values, vector<vector<string>>& queries) {\n return {};\n }\n};"}, "fn": "calcEquation", "params": [{"name": "equations", "type": "string_list_2d"}, {"name": "values", "type": "string_array"}, {"name": "queries", "type": "string_list_2d"}], "outputType": "string_list", "tests": [["[[\"a\",\"b\"],[\"b\",\"c\"]]", "[\"2.0\",\"3.0\"]", "[[\"a\",\"c\"],[\"b\",\"a\"],[\"a\",\"e\"],[\"a\",\"a\"],[\"x\",\"x\"]]"], ["[[\"a\",\"b\"],[\"b\",\"c\"],[\"bc\",\"cd\"]]", "[\"1.5\",\"2.5\",\"5.0\"]", "[[\"a\",\"c\"],[\"c\",\"b\"],[\"bc\",\"cd\"],[\"cd\",\"bc\"]]"], ["[[\"a\",\"b\"]]", "[\"0.5\"]", "[[\"a\",\"b\"],[\"b\",\"a\"],[\"a\",\"c\"],[\"x\",\"y\"]]"], ["[[\"x1\",\"x2\"],[\"x2\",\"x3\"],[\"x3\",\"x4\"],[\"x4\",\"x5\"]]", "[\"3.0\",\"4.0\",\"5.0\",\"6.0\"]", "[[\"x1\",\"x5\"],[\"x5\",\"x2\"],[\"x2\",\"x4\"],[\"x2\",\"x2\"],[\"x2\",\"x9\"],[\"x9\",\"x9\"]]"], ["[[\"a\", \"b\"]]", "[\"2.0\"]", "[[\"a\", \"a\"], [\"b\", \"b\"], [\"a\", \"b\"], [\"b\", \"a\"]]"], ["[[\"a\", \"b\"], [\"c\", \"d\"]]", "[\"2.0\", \"3.0\"]", "[[\"a\", \"b\"], [\"c\", \"d\"], [\"a\", \"c\"], [\"a\", \"a\"]]"], ["[[\"a\", \"b\"], [\"b\", \"c\"], [\"c\", \"d\"]]", "[\"2.0\", \"2.0\", \"2.0\"]", "[[\"a\", \"d\"], [\"d\", \"a\"], [\"b\", \"d\"], [\"a\", \"z\"]]"], ["[[\"x\", \"y\"]]", "[\"0.5\"]", "[[\"x\", \"y\"], [\"y\", \"x\"], [\"x\", \"x\"], [\"z\", \"z\"]]"], ["[[\"a1\", \"b2\"], [\"b2\", \"c3\"]]", "[\"4.0\", \"5.0\"]", "[[\"a1\", \"c3\"], [\"c3\", \"a1\"], [\"a1\", \"a1\"], [\"q9\", \"q9\"]]"], ["[[\"m\", \"n\"]]", "[\"20.0\"]", "[[\"m\", \"n\"], [\"n\", \"m\"], [\"m\", \"m\"], [\"p\", \"q\"]]"], ["[[\"p\", \"q\"]]", "[\"0.1\"]", "[[\"p\", \"q\"], [\"q\", \"p\"], [\"p\", \"p\"]]"], ["[[\"a\", \"b\"], [\"b\", \"c\"], [\"a\", \"c\"]]", "[\"2.0\", \"3.0\", \"6.0\"]", "[[\"a\", \"c\"], [\"c\", \"a\"], [\"b\", \"c\"]]"], ["[[\"u\", \"v\"], [\"v\", \"w\"]]", "[\"1.0\", \"1.0\"]", "[[\"u\", \"w\"], [\"w\", \"u\"], [\"u\", \"v\"]]"], ["[[\"k1\", \"k2\"], [\"k3\", \"k4\"]]", "[\"7.5\", \"2.5\"]", "[[\"k1\", \"k2\"], [\"k3\", \"k4\"], [\"k1\", \"k3\"], [\"k2\", \"k2\"]]"], ["[[\"aa\", \"bb\"], [\"bb\", \"cc\"], [\"cc\", \"dd\"], [\"dd\", \"ee\"]]", "[\"2.0\", \"3.0\", \"4.0\", \"5.0\"]", "[[\"aa\", \"ee\"], [\"ee\", \"aa\"], [\"bb\", \"dd\"]]"], ["[[\"s\", \"t\"]]", "[\"3.5\"]", "[[\"s\", \"t\"], [\"t\", \"s\"], [\"s\", \"s\"], [\"t\", \"t\"], [\"x\", \"s\"]]"], ["[[\"ab1\", \"cd2\"]]", "[\"9.0\"]", "[[\"ab1\", \"cd2\"], [\"cd2\", \"ab1\"], [\"ab1\", \"ab1\"], [\"zz9\", \"zz9\"]]"], ["[[\"e1\", \"e2\"], [\"e2\", \"e3\"], [\"e1\", \"e3\"]]", "[\"2.0\", \"4.0\", \"8.0\"]", "[[\"e1\", \"e3\"], [\"e3\", \"e1\"], [\"e2\", \"e1\"]]"], ["[[\"foo\", \"bar\"], [\"bar\", \"baz\"]]", "[\"1.5\", \"2.0\"]", "[[\"foo\", \"baz\"], [\"baz\", \"foo\"], [\"foo\", \"qux\"]]"], ["[[\"v1\", \"v2\"]]", "[\"19.99\"]", "[[\"v1\", \"v2\"], [\"v2\", \"v1\"], [\"v1\", \"v1\"]]"], ["[[\"a\", \"b\"], [\"c\", \"b\"]]", "[\"2.0\", \"3.0\"]", "[[\"a\", \"c\"], [\"c\", \"a\"], [\"a\", \"b\"], [\"b\", \"c\"]]"], ["[[\"n1\", \"n2\"], [\"n2\", \"n3\"]]", "[\"0.25\", \"0.5\"]", "[[\"n1\", \"n3\"], [\"n3\", \"n1\"], [\"n2\", \"n2\"]]"], ["[[\"g\", \"h\"], [\"h\", \"i\"], [\"i\", \"j\"]]", "[\"10.0\", \"0.5\", \"2.0\"]", "[[\"g\", \"j\"], [\"j\", \"g\"], [\"h\", \"j\"]]"], ["[[\"t1\", \"t2\"], [\"t1\", \"t3\"]]", "[\"3.0\", \"2.0\"]", "[[\"t1\", \"t2\"], [\"t2\", \"t1\"], [\"t2\", \"t3\"]]"], ["[[\"w\", \"x\"], [\"y\", \"z\"]]", "[\"6.0\", \"8.0\"]", "[[\"w\", \"x\"], [\"y\", \"z\"], [\"w\", \"y\"], [\"x\", \"x\"]]"], ["[[\"d1\", \"d2\"], [\"d2\", \"d3\"], [\"d3\", \"d4\"]]", "[\"1.2\", \"3.4\", \"5.6\"]", "[[\"d1\", \"d4\"], [\"d4\", \"d1\"], [\"d2\", \"d3\"]]"], ["[[\"q\", \"r\"]]", "[\"13.0\"]", "[[\"q\", \"r\"], [\"r\", \"q\"], [\"q\", \"q\"], [\"s\", \"s\"]]"], ["[[\"a12\", \"b34\"], [\"b34\", \"c56\"]]", "[\"2.5\", \"4.0\"]", "[[\"a12\", \"c56\"], [\"c56\", \"a12\"], [\"a12\", \"zz\"]]"], ["[[\"h1\", \"h2\"], [\"h2\", \"h3\"], [\"h3\", \"h4\"], [\"h4\", \"h5\"]]", "[\"2.0\", \"2.0\", \"2.0\", \"2.0\"]", "[[\"h1\", \"h5\"], [\"h5\", \"h1\"], [\"h3\", \"h3\"]]"], ["[[\"solo\", \"pair\"]]", "[\"11.0\"]", "[[\"solo\", \"solo\"], [\"pair\", \"pair\"], [\"solo\", \"pair\"], [\"pair\", \"solo\"], [\"other\", \"other\"]]"]], "expected": [["6.00000", "0.50000", "-1.00000", "1.00000", "-1.00000"], ["3.75000", "0.40000", "5.00000", "0.20000"], ["0.50000", "2.00000", "-1.00000", "-1.00000"], ["360.00000", "0.00833", "20.00000", "1.00000", "-1.00000", "-1.00000"], ["1.00000", "1.00000", "2.00000", "0.50000"], ["2.00000", "3.00000", "-1.00000", "1.00000"], ["8.00000", "0.12500", "4.00000", "-1.00000"], ["0.50000", "2.00000", "1.00000", "-1.00000"], ["20.00000", "0.05000", "1.00000", "-1.00000"], ["20.00000", "0.05000", "1.00000", "-1.00000"], ["0.10000", "10.00000", "1.00000"], ["6.00000", "0.16667", "3.00000"], ["1.00000", "1.00000", "1.00000"], ["7.50000", "2.50000", "-1.00000", "1.00000"], ["120.00000", "0.00833", "12.00000"], ["3.50000", "0.28571", "1.00000", "1.00000", "-1.00000"], ["9.00000", "0.11111", "1.00000", "-1.00000"], ["8.00000", "0.12500", "0.50000"], ["3.00000", "0.33333", "-1.00000"], ["19.99000", "0.05003", "1.00000"], ["0.66667", "1.50000", "2.00000", "0.33333"], ["0.12500", "8.00000", "1.00000"], ["10.00000", "0.10000", "1.00000"], ["3.00000", "0.33333", "0.66667"], ["6.00000", "8.00000", "-1.00000", "1.00000"], ["22.84800", "0.04377", "3.40000"], ["13.00000", "0.07692", "1.00000", "-1.00000"], ["10.00000", "0.10000", "-1.00000"], ["16.00000", "0.06250", "1.00000"], ["1.00000", "1.00000", "11.00000", "0.09091", "-1.00000"]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "80", "slug": "evaluate-reverse-polish-notation", "id": 80, "title": "Evaluate Reverse Polish Notation", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/evaluate-reverse-polish-notation/", "examples": [{"input": "tokens = [\"2\",\"1\",\"+\",\"3\",\"*\"]", "output": "9", "explanation": "(2 + 1) * 3 = 9."}, {"input": "tokens = [\"4\",\"13\",\"5\",\"/\",\"+\"]", "output": "6", "explanation": "13 / 5 = 2, then 4 + 2 = 6."}, {"input": "tokens = [\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]", "output": "22", "explanation": "9 + 3 = 12, 12 * -11 = -132, 6 / -132 = 0, 10 * 0 = 0, 0 + 17 + 5 = 22."}], "hints": ["Push numbers onto a stack; an operator consumes the top two values and pushes its result.", "For subtraction and division, preserve operand order: the second popped value is the left operand."], "statement": "Evaluate an arithmetic expression written in Reverse Polish Notation and return\nits integer value.\n\nEach token is either an integer or one of the operators `+`, `-`, `*`, and `/`.\nDivision between two integers truncates toward zero. The expression is always\nvalid, and no division by zero occurs.\n\n**Constraints:**\n\n- `1 <= tokens.length <= 10000`\n- Every numeric token represents an integer in the range `[-200, 200]`.\n- Every intermediate result and the final answer fit in a signed 32-bit integer.\n", "solution": "## Approach\n\nPush numeric tokens onto a stack. For an operator, pop the right operand and\nthen the left operand, apply the operation, and push the result. Division uses\nabsolute integer division followed by the correct sign so it truncates toward\nzero without relying on floating-point arithmetic.\n\n## Complexity Analysis\n\n- **Time Complexity:** `O(t)` for `t` tokens.\n- **Space Complexity:** `O(t)` in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def evalRpn(self, tokens: List[str]) -> int:\n stack: List[int] = []\n for token in tokens:\n if token not in {\"+\", \"-\", \"*\", \"/\"}:\n stack.append(int(token))\n continue\n right = stack.pop()\n left = stack.pop()\n if token == \"+\":\n stack.append(left + right)\n elif token == \"-\":\n stack.append(left - right)\n elif token == \"*\":\n stack.append(left * right)\n else:\n quotient = abs(left) // abs(right)\n stack.append(-quotient if (left < 0) != (right < 0) else quotient)\n return stack[-1]\n```\n", "starter": {"go": "package main\n\nfunc EvalRpn(tokens []string) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def evalRpn(self, tokens: List[str]) -> int:\n return 0\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int evalRpn(vector<string>& tokens) {\n return 0;\n }\n};"}, "fn": "evalRpn", "params": [{"name": "tokens", "type": "string_array"}], "outputType": "int", "tests": [["[\"2\",\"1\",\"+\",\"3\",\"*\"]"], ["[\"4\",\"13\",\"5\",\"/\",\"+\"]"], ["[\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]"], ["[\"7\",\"-3\",\"/\"]"], ["[\"-7\",\"3\",\"/\"]"], ["[\"-7\",\"-3\",\"/\"]"], ["[\"0\"]"], ["[\"-200\"]"], ["[\"5\",\"1\",\"2\",\"+\",\"4\",\"*\",\"+\",\"3\",\"-\"]"], ["[\"3\",\"4\",\"+\",\"2\",\"*\",\"7\",\"/\"]"], ["[\"-1\",\"-13\",\"+\",\"-1\",\"*\",\"4\",\"+\",\"2\",\"*\",\"15\",\"+\",\"14\",\"*\",\"-19\",\"+\"]"], ["[\"17\",\"6\",\"+\",\"0\",\"*\",\"-17\",\"+\",\"13\",\"*\",\"5\",\"+\",\"10\",\"*\",\"-10\",\"+\",\"-15\",\"*\",\"8\",\"+\"]"], ["[\"-17\",\"5\",\"+\",\"12\",\"*\",\"3\",\"+\",\"-5\",\"*\",\"11\",\"+\",\"-18\",\"*\",\"14\",\"+\",\"-9\",\"*\"]"], ["[\"2\",\"-2\",\"*\",\"-3\",\"+\",\"-1\",\"*\",\"5\",\"+\",\"20\",\"*\",\"-9\",\"+\"]"], ["[\"-7\",\"-17\",\"+\",\"-4\",\"*\",\"9\",\"+\",\"12\",\"*\",\"1\",\"+\"]"], ["[\"0\",\"12\",\"+\",\"18\",\"*\",\"-20\",\"+\",\"-11\",\"*\",\"13\",\"+\"]"], ["[\"-14\",\"-2\",\"+\",\"18\",\"*\",\"-7\",\"+\",\"0\",\"*\"]"], ["[\"11\",\"-15\",\"*\",\"-12\",\"+\",\"1\",\"*\",\"-11\",\"+\",\"-3\",\"*\",\"-12\",\"+\",\"6\",\"*\"]"], ["[\"6\",\"-5\",\"*\",\"-17\",\"+\",\"16\",\"*\",\"6\",\"+\",\"1\",\"*\",\"-8\",\"+\",\"8\",\"*\",\"-17\",\"+\",\"-3\",\"*\"]"], ["[\"-14\",\"7\",\"*\",\"13\",\"+\",\"7\",\"*\",\"-14\",\"+\",\"20\",\"*\",\"7\",\"+\",\"-4\",\"*\",\"18\",\"+\"]"], ["[\"5\",\"-16\",\"+\",\"5\",\"*\",\"2\",\"+\",\"-15\",\"*\",\"-20\",\"+\",\"-16\",\"*\"]"], ["[\"-3\",\"8\",\"*\",\"-20\",\"+\",\"4\",\"*\",\"4\",\"+\",\"-14\",\"*\",\"-10\",\"+\",\"8\",\"*\"]"], ["[\"9\",\"3\",\"*\",\"10\",\"+\",\"-15\",\"*\",\"15\",\"+\",\"18\",\"*\",\"15\",\"+\",\"20\",\"*\",\"20\",\"+\"]"], ["[\"13\",\"-19\",\"+\",\"-20\",\"*\",\"6\",\"+\",\"-18\",\"*\",\"5\",\"+\",\"18\",\"*\"]"], ["[\"-13\",\"17\",\"*\",\"10\",\"+\"]"], ["[\"-20\",\"2\",\"+\",\"2\",\"*\",\"-20\",\"+\",\"11\",\"*\",\"-11\",\"+\",\"9\",\"*\",\"13\",\"+\"]"], ["[\"-6\",\"-4\",\"+\",\"17\",\"*\",\"-15\",\"+\",\"0\",\"*\",\"9\",\"+\",\"12\",\"*\",\"-20\",\"+\",\"-19\",\"*\",\"2\",\"+\"]"], ["[\"-8\",\"7\",\"+\"]"], ["[\"-3\",\"-17\",\"+\",\"6\",\"*\",\"3\",\"+\",\"12\",\"*\"]"], ["[\"-15\",\"10\",\"*\",\"-8\",\"+\",\"-11\",\"*\",\"-7\",\"+\"]"], ["[\"4\",\"18\",\"+\",\"5\",\"*\",\"-4\",\"+\",\"7\",\"*\",\"-4\",\"+\",\"18\",\"*\",\"20\",\"+\",\"0\",\"*\",\"-3\",\"+\"]"], ["[\"18\",\"20\",\"+\",\"20\",\"*\",\"-4\",\"+\"]"], ["[\"11\",\"6\",\"+\",\"8\",\"*\"]"], ["[\"1\",\"5\",\"*\",\"-20\",\"+\",\"-16\",\"*\",\"5\",\"+\",\"-18\",\"*\"]"], ["[\"-16\",\"2\",\"*\",\"8\",\"+\",\"10\",\"*\",\"-5\",\"+\",\"4\",\"*\",\"-19\",\"+\",\"-15\",\"*\"]"], ["[\"5\",\"-4\",\"*\",\"-14\",\"+\",\"-3\",\"*\",\"-14\",\"+\",\"-8\",\"*\",\"20\",\"+\"]"], ["[\"-7\",\"14\",\"+\"]"], ["[\"17\",\"12\",\"+\",\"-17\",\"*\",\"8\",\"+\"]"], ["[\"-7\",\"11\",\"+\"]"], ["[\"10\",\"-19\",\"+\",\"-4\",\"*\",\"-11\",\"+\",\"19\",\"*\",\"16\",\"+\"]"], ["[\"6\",\"-20\",\"+\",\"-5\",\"*\",\"12\",\"+\",\"20\",\"*\"]"], ["[\"14\",\"-13\",\"*\",\"-4\",\"+\",\"-14\",\"*\",\"-8\",\"+\",\"20\",\"*\",\"16\",\"+\"]"], ["[\"18\",\"-11\",\"+\",\"16\",\"*\",\"-19\",\"+\",\"-19\",\"*\",\"-6\",\"+\",\"13\",\"*\",\"-12\",\"+\"]"], ["[\"17\",\"2\",\"+\",\"16\",\"*\",\"18\",\"+\"]"], ["[\"19\",\"-4\",\"+\",\"2\",\"*\",\"-12\",\"+\"]"], ["[\"-20\",\"-6\",\"+\"]"], ["[\"-8\",\"12\",\"+\",\"-13\",\"*\",\"13\",\"+\",\"6\",\"*\",\"18\",\"+\",\"-8\",\"*\",\"-7\",\"+\"]"], ["[\"4\",\"-20\",\"+\",\"18\",\"*\",\"7\",\"+\",\"4\",\"*\",\"-11\",\"+\",\"20\",\"*\"]"], ["[\"-1\",\"18\",\"*\",\"-11\",\"+\",\"17\",\"*\",\"-10\",\"+\",\"-6\",\"*\",\"-9\",\"+\",\"-3\",\"*\",\"8\",\"+\"]"], ["[\"-11\",\"-12\",\"+\",\"20\",\"*\",\"-18\",\"+\",\"-13\",\"*\",\"18\",\"+\",\"12\",\"*\",\"16\",\"+\",\"19\",\"*\",\"-4\",\"+\"]"], ["[\"19\",\"-1\",\"+\",\"-16\",\"*\",\"-11\",\"+\",\"-20\",\"*\",\"-6\",\"+\",\"-2\",\"*\"]"], ["[\"-13\",\"1\",\"*\",\"-1\",\"+\",\"2\",\"*\",\"1\",\"+\"]"], ["[\"-16\",\"-1\",\"+\",\"-9\",\"*\",\"9\",\"+\"]"], ["[\"-1\",\"-3\",\"+\",\"7\",\"*\",\"-7\",\"+\"]"], ["[\"-6\",\"17\",\"+\",\"-10\",\"*\"]"], ["[\"7\",\"-5\",\"*\",\"11\",\"+\",\"9\",\"*\"]"], ["[\"0\",\"16\",\"*\",\"17\",\"+\"]"], ["[\"-15\",\"-9\",\"+\",\"-8\",\"*\"]"], ["[\"-20\",\"-9\",\"*\",\"1\",\"+\",\"-4\",\"*\",\"-13\",\"+\",\"-9\",\"*\",\"7\",\"+\",\"-9\",\"*\",\"-15\",\"+\",\"-8\",\"*\"]"], ["[\"17\",\"18\",\"*\",\"20\",\"+\",\"0\",\"*\",\"6\",\"+\",\"9\",\"*\",\"-1\",\"+\",\"11\",\"*\",\"4\",\"+\"]"], ["[\"200\",\"200\",\"*\",\"200\",\"*\",\"200\",\"*\"]"], ["@javascript:JSON.stringify(['200','200','*','200','*','200','*',...Array.from({length:4996},()=>['0','+']).flat()])"]], "expected": [9, 6, 22, -2, -2, 2, 0, -200, 14, 2, 695, 32558, 115866, 231, 1261, -2143, 0, 3312, 18147, 48710, -12400, 19184, -194080, -40734, -211, -5630, -1670, -1, -1404, 1731, -3, 756, 136, -4410, 14985, -684, 7, -485, 4, 491, 1640, 51936, -23061, 322, 18, -26, 1721, -22700, -9019, 1421196, -11948, -27, 162, -35, -110, -216, 17, 192, 478200, 587, 1600000000, 1600000000], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "851", "slug": "exam-room", "id": 851, "title": "Exam Room", "difficulty": "Medium", "category": "design", "link": "https://leetcode.com/problems/exam-room/", "examples": [{"input": "operations = [\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\"]\nvalues = [10,0,0,0,4,0]", "output": "[0,9,4,4]", "explanation": "Seats spread to ends then middle; freed 4 is retaken."}, {"input": "operations = [\"ExamRoom\",\"seat\",\"seat\",\"leave\",\"seat\"]\nvalues = [4,0,0,0,0]", "output": "[0,3,0]", "explanation": "Take 0 and 3, free 0, then retake 0."}, {"input": "operations = [\"ExamRoom\",\"seat\"]\nvalues = [1,0]", "output": "[0]", "explanation": "Only seat available."}], "hints": ["Keep occupied seats in an ordered set; the best seat always lies at an end or midway between two neighbours.", "For an interior gap (a,b) the candidate is (a+b)//2 with distance (b-a)//2; for edges use 0 or N-1 directly.", "Scan all gaps per seat() call: with few operations this linear scan is simplest and fast enough."], "statement": "Simulate a socially distanced waiting room (function-style adaptation).\n\nA room holds numbered seats `0` to `N-1`. Operation `seat()` picks the free seat maximizing the distance to the nearest occupied seat, breaking ties by the smallest index (with the special cases: first student takes seat 0, and an empty-ended interval picks its end). Operation `leave(p)` frees seat `p`, which is guaranteed occupied.\n\nThe classic design asks for an `ExamRoom` class, which this judge cannot express with the supported types. The portable adaptation is `runExamRoom(operations, values)`: both arrays run in parallel, `operations[i]` is one of `\"ExamRoom\"`, `\"seat\"`, `\"leave\"`, and `values[i]` carries the argument (`N` for construction, the seat number for `leave`, ignored `0` for `seat`). Return the list of `seat()` results in call order. Example: operations `[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\"]` with values `[10,0,0,0,4,0]` seats 0, 9, 4, frees 4, then seats 4 again, yielding `[0,9,4,4]`.\n\n**Constraints:**\n- `1 <= N <= 10^9` (tests use small N for speed).\n- `1 <= operations.length <= 200`\n- `leave(p)` always names an occupied seat.\n", "solution": "## Approach\n\nStore taken seats in a sorted set. To seat, examine every gap: the leading edge offers seat 0 at distance first, each interior pair (a,b) offers midpoint (a+b)//2 at distance (b-a)//2, and the trailing edge offers N-1. Pick the largest distance, breaking ties by smaller index. Leaving just deletes from the set. The wrapper replays the operation log and collects seat answers.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k * m), where k is the seat call count and m the occupancy size, for gap scans.\n- **Space Complexity:** O(m) for the ordered set.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runExamRoom(self, operations: List[str], values: List[int]) -> List[int]:\n N = values[0]\n occ = []\n ans = []\n import bisect\n for op, v in zip(operations[1:], values[1:]):\n if op == 'seat':\n if not occ:\n occ = [0]\n ans.append(0)\n continue\n best, best_d = -1, -1\n if occ[0] != 0:\n best, best_d = 0, occ[0]\n for a, b in zip(occ, occ[1:]):\n cand = (a + b) // 2\n d = (b - a) // 2\n if d > best_d:\n best, best_d = cand, d\n if occ[-1] != N - 1:\n d = N - 1 - occ[-1]\n if d > best_d:\n best, best_d = N - 1, d\n bisect.insort(occ, best)\n ans.append(best)\n elif op == 'leave':\n occ.remove(v)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunExamRoom(operations []string, values []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runExamRoom(self, operations: List[str], values: List[int]) -> List[int]:\n return []\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runExamRoom(vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runExamRoom", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\"]", "[10,0,0,0,4,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"leave\",\"seat\"]", "[4,0,0,0,0]"], ["[\"ExamRoom\",\"seat\"]", "[1,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\"]", "[10,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\"]", "[10,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"leave\",\"seat\"]", "[5,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"leave\",\"leave\",\"seat\",\"seat\"]", "[4,0,0,0,3,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\"]", "[8,0,0,0,0,3,0]"], ["[\"ExamRoom\",\"seat\"]", "[10,0]"], ["[\"ExamRoom\",\"seat\",\"seat\"]", "[2,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\",\"seat\"]", "[5,0,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"leave\",\"seat\",\"seat\"]", "[6,0,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"leave\",\"leave\",\"seat\"]", "[10,0,0,0,9,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\",\"leave\",\"leave\",\"seat\"]", "[10,0,0,0,0,4,9,0]"], ["[\"ExamRoom\",\"seat\",\"seat\"]", "[1,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\"]", "[4,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\"]", "[4,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"leave\",\"seat\"]", "[10,0,0,9,0]"], ["[\"ExamRoom\",\"seat\",\"leave\",\"seat\",\"seat\"]", "[3,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\",\"seat\"]", "[7,0,0,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\",\"seat\",\"seat\"]", "[10,0,0,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"leave\",\"seat\",\"leave\",\"seat\"]", "[5,0,0,0,0,4,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\"]", "[3,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\"]", "[6,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"leave\",\"seat\",\"leave\",\"seat\"]", "[2,0,0,0,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\"]", "[8,0,0,0,7,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\",\"seat\"]", "[9,0,0,0,0,4,0,0]"], ["[\"ExamRoom\",\"seat\",\"seat\",\"seat\",\"seat\",\"seat\",\"leave\",\"seat\"]", "[12,0,0,0,0,0,5,0]"]], "expected": [[0, 9, 4, 4], [0, 3, 0], [0], [0, 9, 4], [0, 9, 4, 2], [0, 0], [0, 3, 0, 3], [0, 7, 3, 5, 2], [0], [0, 1], [0, 4, 2, 1, 3], [0, 5, 0, 2], [0, 9, 4, 9], [0, 9, 4, 2, 9], [0, -1], [0, 3, 1], [0, 3, 1, 2], [0, 9, 9], [0, 0, 2], [0, 6, 3, 0, 1], [0, 9, 4, 2, 6, 1], [0, 4, 0, 4], [0, 2, 1], [0, 5, 2, 1], [0, 0, 0], [0, 7, 3, 7], [0, 8, 4, 2, 5, 1], [0, 11, 5, 8, 2, 5]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "321", "slug": "excel-sheet-column-number", "id": 321, "title": "Excel Sheet Column Number", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/excel-sheet-column-number/", "examples": [{"explanation": "The first column is numbered 1.", "input": "columnTitle = \"A\"", "output": "1"}, {"explanation": "A contributes 1 * 26 plus B contributes 2, giving 28.", "input": "columnTitle = \"AB\"", "output": "28"}, {"explanation": "Z contributes 26 * 26 plus Y contributes 25, giving 701.", "input": "columnTitle = \"ZY\"", "output": "701"}], "hints": ["Process letters left to right, multiplying the running total by 26 before adding the next digit.", "Map A to 1, B to 2, and so on up to Z as 26."], "statement": "Spreadsheet columns are labelled A through Z, then AA, AB, and so on, like base-26 numbers but with digits 1-26 instead of 0-25. Given a column label, return its number: A is 1, Z is 26, AA is 27, AB is 28.\n\n**Constraints:**\n- `1 <= columnTitle.length <= 7`\n- `columnTitle` holds only uppercase English letters.\n", "solution": "## Approach\n\nRead the label left to right like a base-26 number with digits 1 through 26. Start at zero; for each letter, multiply the running total by 26 and add the letter value (A as 1 through Z as 26).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the label length.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n res = 0\n for c in columnTitle:\n res = res * 26 + (ord(c) - ord(\"A\") + 1)\n return res\n```\n", "starter": {"go": "package main\n\nfunc TitleToNumber(columnTitle string) int {\n \n}", "python": "class Solution:\n def titleToNumber(self, columnTitle: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int titleToNumber(string columnTitle) {\n return 0;\n }\n};"}, "fn": "titleToNumber", "params": [{"name": "columnTitle", "type": "string"}], "outputType": "int", "tests": [["A"], ["AB"], ["ZY"], ["Z"], ["AA"], ["AZ"], ["BA"], ["ZZ"], ["AAA"], ["ABC"], ["FXSHRXW"], ["B"], ["Y"], ["C"], ["AD"], ["ZZZ"], ["AAB"], ["ZYX"], ["HELLO"], ["WORLD"], ["AAZ"], ["ABA"], ["CAT"], ["DOG"], ["M"], ["FX"]], "expected": [1, 28, 701, 26, 27, 52, 53, 702, 703, 731, 2147483647, 2, 25, 3, 30, 18278, 704, 18250, 3752127, 10786572, 728, 729, 2074, 3101, 13, 180], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "243", "slug": "excel-sheet-column-title", "id": 243, "title": "Excel Sheet Column Title", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/excel-sheet-column-title/", "examples": [{"input": "columnNumber = 1", "output": "\"A\""}, {"input": "columnNumber = 28", "output": "\"AB\""}, {"input": "columnNumber = 701", "output": "\"ZY\""}], "hints": ["Repeatedly reduce columnNumber by taking (columnNumber - 1) % 26 to find each letter from the right.", "Divide columnNumber by 26 after removing the offset so 1-based indexing maps to 'A' through 'Z'."], "statement": "You get an integer `columnNumber`. Produce the label that a spreadsheet assigns to that column.\n\nColumns are named with capital letters in sequence: `A` through `Z` cover the first 26 columns, then two-letter names take over (`AA`, `AB`, and so on), mirroring a 1-based base-26 scheme without a zero digit.\n\nFor reference, the numbering runs as follows:\n\n```\nA -> 1\nB -> 2\nC -> 3\n...\nZ -> 26\nAA -> 27\nAB -> 28\n...\n```\n\n**Constraints:**\n\n- `1 <= columnNumber <= 2^31 - 1`\n", "solution": "## Approach\n\nRepeatedly peel off the least-significant letter of the title using `(columnNumber - 1) % 26`, since the alphabet is 1-based (`A` = 1 ... `Z` = 26). Pre-decrementing `columnNumber` avoids an off-by-one where `26` would otherwise map outside the alphabet. Build the result from right to left and reverse it at the end.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log_26(columnNumber)), since `columnNumber` is divided by 26 each iteration.\n- **Space Complexity:** O(log_26(columnNumber)) for the output string.\n\n## Implementation\n\n```python\nclass Solution:\n def convertToTitle(self, columnNumber: int) -> str:\n result = []\n while columnNumber > 0:\n columnNumber -= 1\n result.append(chr(ord('A') + columnNumber % 26))\n columnNumber //= 26\n return ''.join(reversed(result))\n```", "starter": {"go": "package main\n\nfunc ConvertToTitle(columnNumber int) string {\n return \"\"\n}", "python": "class Solution:\n def convertToTitle(self, columnNumber: int) -> str:\n return \"\"\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string convertToTitle(int columnNumber) {\n return \"\";\n }\n};"}, "fn": "convertToTitle", "params": [{"name": "columnNumber", "type": "int"}], "outputType": "string", "tests": [["1"], ["28"], ["701"], ["26"], ["27"], ["52"], ["53"], ["702"], ["703"], ["18278"], ["2147483647"], ["475254"], ["2"], ["3"], ["4"], ["25"], ["51"], ["54"], ["78"], ["79"], ["677"], ["678"], ["704"], ["18279"], ["1000"], ["10000"], ["100000"], ["1000000"], ["1234567"], ["2147483646"], ["16384"]], "expected": ["A", "AB", "ZY", "Z", "AA", "AZ", "BA", "ZZ", "AAA", "ZZZ", "FXSHRXW", "ZZZZ", "B", "C", "D", "Y", "AY", "BB", "BZ", "CA", "ZA", "ZB", "AAB", "AAAA", "ALL", "NTP", "EQXD", "BDWGN", "BRFGI", "FXSHRXV", "XFD"], "loose": false}
|