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": "628", "slug": "delete-operation-for-two-strings", "id": 628, "title": "Delete Operation for Two Strings", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/delete-operation-for-two-strings/", "examples": [{"input": "word1 = \"sea\", word2 = \"eat\"", "output": "2", "explanation": "Remove s from the first and t from the second to get ea in both."}, {"input": "word1 = \"a\", word2 = \"b\"", "output": "2", "explanation": "Nothing matches, so both characters must go."}, {"input": "word1 = \"abc\", word2 = \"abc\"", "output": "0", "explanation": "The strings already match."}], "hints": ["Only deletions are allowed, so the kept characters must appear in order in both strings.", "The longest keepable part is the longest common subsequence of the two words.", "Answer equals len(word1) + len(word2) - 2 * LCS length."], "statement": "Two words can only be changed by deleting characters. Find the smallest number of single-character deletions that makes the two words identical.\n\nIn other words, keep a subsequence shared by both words and delete everything else; maximizing the kept part minimizes the deletions.\n\n**Constraints:**\n- `1 <= word1.length, word2.length <= 500`\n- Words contain lowercase English letters.\n", "solution": "## Approach\n\nThe characters that survive must form a common subsequence, so keeping the longest one is optimal. A classic two-row dynamic program finds the longest common subsequence length, and the deletions are whatever remains in both words.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m*n) for the table.\n- **Space Complexity:** O(m*n), easily reduced to O(min(m,n)).\n\n## Implementation\n\n```python\nclass Solution:\n def minDistance(self, word1: str, word2: str) -> int:\n m, n = len(word1), len(word2)\n dp = [[0] * (n + 1) for _ in range(m + 1)]\n for i in range(1, m + 1):\n for j in range(1, n + 1):\n if word1[i - 1] == word2[j - 1]:\n dp[i][j] = dp[i - 1][j - 1] + 1\n else:\n dp[i][j] = dp[i - 1][j] if dp[i - 1][j] > dp[i][j - 1] else dp[i][j - 1]\n return m + n - 2 * dp[m][n]\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 pass", "cpp": "#include <string>\nusing namespace std;\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": [["sea", "eat"], ["a", "b"], ["abc", "abc"], ["leetcode", "etco"], ["abc", "def"], ["a", "a"], ["ab", "ba"], ["park", "spake"], ["dinitrophenylhydrazine", "acetylphenylhydrazine"], ["x", "x"], ["x", "y"], ["ab", "ab"], ["abcd", "efgh"], ["eat", "sea"], ["horse", "ros"], ["intention", "execution"], ["a", "ab"], ["ab", "a"], ["abcde", "ace"], ["mart", "karma"], ["kitten", "sitting"], ["abcdef", "azced"], ["plasma", "altruism"], ["q", "qq"], ["qq", "q"], ["abcd", "abcd"], ["zzzz", "zzzzzzzz"], ["abcxyz", "xyzabc"]], "expected": [2, 2, 0, 4, 6, 0, 2, 3, 11, 0, 2, 0, 8, 2, 4, 8, 1, 1, 2, 5, 5, 5, 8, 1, 1, 0, 4, 6], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "71", "slug": "design-add-and-search-words-data-structure", "id": 71, "title": "Design Add and Search Words Data Structure", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/design-add-and-search-words-data-structure/", "examples": [{"input": "operations = [\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]\nvalues = [\"\",\"bad\",\"dad\",\"mad\",\"pad\",\"bad\",\".ad\",\"b..\"]", "output": "[null,null,null,null,false,true,true,true]", "explanation": "After adding 'bad', 'dad', and 'mad', searching 'pad' returns false, 'bad' returns true, '.ad' matches 'bad'/'dad'/'mad', 'b..' matches 'bad'."}, {"input": "operations = [\"WordDictionary\",\"addWord\",\"search\",\"search\",\"search\"]\nvalues = [\"\",\"a\",\".\",\"a\",\"aa\"]", "output": "[null,null,true,true,false]", "explanation": "After adding 'a', searching '.' matches 'a', searching 'a' matches 'a', searching 'aa' returns false."}], "hints": ["Use a Trie (prefix tree) as the underlying data structure for efficient prefix matching.", "For the search method with '.', use DFS/backtracking to try all 26 possible child nodes when a dot is encountered."], "statement": "Build a container that records inserted words and can later test query strings against them.\n\nProvide the `WordDictionary` type with these members:\n\n- `WordDictionary()` Creates an empty container.\n- `void addWord(word)` Stores `word` so that later queries may match it.\n- `bool search(word)` Reports `true` when some stored entry matches `word`, else `false`. A dot `'.'` inside the query stands for an arbitrary single letter.\n\n**Constraints:**\n- `1 <= word.length <= 25`\n- `word` in `addWord` consists of lowercase English letters.\n- `word` in `search` consist of `'.'` or lowercase English letters.\n- There will be at most `10^4` calls to `addWord` and `search`.\n", "solution": "## Approach\n\nUse a trie where each node stores children characters and an end-of-word flag. The search method handles `.` wildcards by recursively trying all child nodes at that position.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for addWord, O(26^m) worst-case for search with wildcards where m is word length and n is word length.\n- **Space Complexity:** O(total characters stored across all words)\n\n## Implementation\n\n```python\nfrom typing import List\nclass WordDictionary:\n def __init__(self):\n self.children = {}\n self.is_end = False\n def addWord(self, word: str) -> None:\n node = self\n for c in word:\n if c not in node.children:\n node.children[c] = WordDictionary()\n node = node.children[c]\n node.is_end = True\n def search(self, word: str) -> bool:\n return self._search(word, 0)\n def _search(self, word: str, i: int) -> bool:\n node = self\n for j in range(i, len(word)):\n c = word[j]\n if c == '.':\n for child in node.children.values():\n if child._search(word, j + 1):\n return True\n return False\n if c not in node.children:\n return False\n node = node.children[c]\n return node.is_end\nclass Solution:\n def solve(self, operations: List[str], values: List[str]) -> List[str]:\n result = []\n obj = None\n for i, op in enumerate(operations):\n if op == \"WordDictionary\":\n obj = WordDictionary()\n result.append(\"null\")\n elif op == \"addWord\":\n obj.addWord(values[i])\n result.append(\"null\")\n elif op == \"search\":\n result.append(str(obj.search(values[i])).lower())\n return result\n```\n", "starter": {"go": "package main\n\ntype WordDictionary struct {\n \n}\n\nfunc Constructor() WordDictionary {\n return WordDictionary{}\n}\n\nfunc (this *WordDictionary) AddWord(word string) {\n \n}\n\nfunc (this *WordDictionary) Search(word string) bool {\n return false\n}", "python": "class WordDictionary:\n def __init__(self):\n \n def addWord(self, word: str) -> None:\n \n def search(self, word: str) -> bool:\n return False", "cpp": "#include <string>\nusing namespace std;\n\nclass WordDictionary {\npublic:\n WordDictionary() {\n \n }\n \n void addWord(string word) {\n \n }\n \n bool search(string word) {\n return false;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"bad\",\"dad\",\"mad\",\"pad\",\"bad\",\".ad\",\"b..\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"a\",\".\",\"a\",\"aa\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"at\",\"and\",\"an\",\"an\",\"a.\",\".\",\"...\"]"], ["[\"WordDictionary\",\"search\",\"search\",\"addWord\",\"search\"]", "[\"\",\"a\",\".\",\"a\",\"a\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"cat\",\"car\",\"card\",\"cart\",\"cat\",\"c.t\",\"c..\",\"ca.\",\"c.r.\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"leetcode\",\"leet\",\"code\",\"leet\",\"leetcod.\",\"le.tcode\",\".....\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\"]", "[\"\",\"a\",\"ab\",\"abc\",\"abcd\",\"a.c\",\"a..d\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"hello\",\"world\",\"hello\",\"world\",\"h.llo\",\"w.r..\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\"]", "[\"\",\"xyz\",\"x.z\",\"x..\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"search\",\"search\"]", "[\"\",\"abcdefghij\",\"klmnopqrst\",\"abcdefghij\",\"klmnopqrst\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\"]", "[\"\",\"a\",\".\",\"..\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\"]", "[\"\",\"aa\",\"ab\",\"ba\",\"bb\",\"..\",\".a\"]"], ["[\"WordDictionary\"]", "[\"\"]"], ["[\"WordDictionary\",\"search\",\"addWord\",\"search\"]", "[\"\",\"word\",\"word\",\"word\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"dog\",\"dog\",\"d.g\",\"cat\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"a\",\"b\",\".\",\"..\",\"c\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"apple\",\"app\",\"app\",\"appl\",\"app.\",\"....\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"test\",\"test\",\"test\",\"tes.\",\"....\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"abcdefghijklmnopqrstuvwxy\",\"abcdefghijklmnopqrstuvwxy\",\".........................\",\"........................\"]"], ["[\"WordDictionary\",\"search\",\"addWord\",\"search\",\"search\"]", "[\"\",\"abc\",\"abc\",\"abc\",\"ab.\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"car\",\"cat\",\"cap\",\"can\",\"ca.\",\"c..\",\"cab\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"abcd\",\"....\",\"...\",\".....\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"a\",\"ab\",\"abc\",\".\",\"..\",\"...\",\"....\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"hello\",\"hell\",\"helloo\",\"h....\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"aaa\",\"aab\",\"aba\",\"a..\",\".a.\",\"..b\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"word\",\"world\",\"work\",\"wor.\",\"w.r.d\",\"word.\"]"], ["[\"WordDictionary\",\"search\"]", "[\"\",\"a\"]"], ["[\"WordDictionary\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"z\",\".\",\"z\",\"zz\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\",\"search\"]", "[\"\",\"trie\",\"trigger\",\"try\",\"tr.\",\"t..\",\"try\",\"trigge.\"]"], ["[\"WordDictionary\",\"addWord\",\"addWord\",\"search\",\"search\",\"search\"]", "[\"\",\"aaaaa\",\"bbbbb\",\".....\",\"aaa..\",\"bb...\"]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "663", "slug": "design-circular-deque", "id": 663, "title": "Design Circular Deque", "difficulty": "Medium", "category": "design", "link": "https://leetcode.com/problems/design-circular-deque/", "examples": [{"input": "operations = [\"MyCircularDeque\",\"insertLast\",\"insertLast\",\"insertFront\",\"insertFront\",\"getRear\",\"isFull\",\"deleteLast\",\"insertFront\",\"getFront\"], values = [3,1,2,3,4,0,0,0,4,0]", "output": "[1,1,1,0,2,1,1,1,4]", "explanation": "Capacity 3 fills with [3,1,2]; the second insertFront fails; rear is 2 and the deque is full; after deleting the rear, inserting 4 at the front gives [4,3,1]."}, {"input": "operations = [\"MyCircularDeque\",\"getFront\",\"getRear\",\"isEmpty\",\"insertFront\",\"isFull\",\"deleteFront\",\"isEmpty\"], values = [2,0,0,0,9,0,0,0]", "output": "[-1,-1,1,1,0,1,1]", "explanation": "An empty deque reads -1 at both ends; after inserting 9 it is neither full nor empty."}], "hints": ["Hold a fixed buffer with a head index and a count; every end maps to (head + offset) mod k.", "insertFront moves head backward first, insertLast writes at head + count; both fail when count equals k.", "Deletes move head forward or shrink count, and getters answer -1 only when count is zero."], "statement": "Build a fixed-capacity double-ended queue that supports insertion and removal at both ends in constant time.\n\nThis task uses a portable function adaptation instead of a class. Implement:\n\n```\nrunCircularDeque(operations, values)\n```\n\nThe two arrays are parallel. `operations[i]` is one of `\"MyCircularDeque\"`, `\"insertFront\"`, `\"insertLast\"`, `\"deleteFront\"`, `\"deleteLast\"`, `\"getFront\"`, `\"getRear\"`, `\"isEmpty\"`, `\"isFull\"`, and `values[i]` carries that call's integer argument:\n\n- `\"MyCircularDeque\"` with `k` creates a deque of capacity `k` and is always first.\n- `\"insertFront\"` / `\"insertLast\"` with `v` insert `v` at that end; answer `1` on success, `0` when full.\n- `\"deleteFront\"` / `\"deleteLast\"` with `0` remove that end; answer `1` on success, `0` when empty.\n- `\"getFront\"` / `\"getRear\"` with `0` answer the end value, or `-1` when empty.\n- `\"isEmpty\"` / `\"isFull\"` with `0` answer `1` for true and `0` for false.\n\nReturn one integer per operation after the constructor, in call order. There is intentionally no class wrapper.\n\n**Constraints:**\n- `1 <= operations.length == values.length <= 3000`\n- The first operation is `\"MyCircularDeque\"` with `1 <= k <= 1000`.\n- Inserted values satisfy `0 <= v <= 1000`; other calls carry `0`.\n", "solution": "## Approach\n\nStore the deque in a fixed ring buffer with a head pointer at the front element and a count of live entries. Front insertion steps the head backward modulo the capacity before writing, while rear insertion writes at head plus count. Deletions slide the head forward or shrink the count, and all getters first check for emptiness so they can answer -1 or the boolean encoding.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) per operation.\n- **Space Complexity:** O(k) for the ring buffer of capacity k.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def runCircularDeque(self, operations: List[str], values: List[int]) -> List[int]:\n k = values[0]\n buf = [0] * k\n head = count = 0\n ans = []\n for op, v in zip(operations[1:], values[1:]):\n if op == \"insertFront\":\n if count == k:\n ans.append(0)\n else:\n head = (head - 1) % k\n buf[head] = v\n count += 1\n ans.append(1)\n elif op == \"insertLast\":\n if count == k:\n ans.append(0)\n else:\n buf[(head + count) % k] = v\n count += 1\n ans.append(1)\n elif op == \"deleteFront\":\n if count == 0:\n ans.append(0)\n else:\n head = (head + 1) % k\n count -= 1\n ans.append(1)\n elif op == \"deleteLast\":\n if count == 0:\n ans.append(0)\n else:\n count -= 1\n ans.append(1)\n elif op == \"getFront\":\n ans.append(-1 if count == 0 else buf[head])\n elif op == \"getRear\":\n ans.append(-1 if count == 0 else buf[(head + count - 1) % k])\n elif op == \"isEmpty\":\n ans.append(1 if count == 0 else 0)\n elif op == \"isFull\":\n ans.append(1 if count == k else 0)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunCircularDeque(operations []string, values []int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def runCircularDeque(self, operations: List[str], values: List[int]) -> List[int]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runCircularDeque(vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runCircularDeque", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"insertFront\", \"insertFront\", \"getRear\", \"isFull\", \"deleteLast\", \"insertFront\", \"getFront\"]", "[3,1,2,3,4,0,0,0,4,0]"], ["[\"MyCircularDeque\", \"getFront\", \"getRear\", \"isEmpty\", \"insertFront\", \"isFull\", \"deleteFront\", \"isEmpty\"]", "[2,0,0,0,9,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"getFront\", \"deleteFront\", \"isEmpty\"]", "[1,5,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"insertLast\", \"getFront\", \"getRear\", \"deleteFront\", \"getFront\", \"deleteLast\", \"isEmpty\"]", "[2,1,2,0,0,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"isFull\", \"insertLast\", \"getRear\", \"deleteFront\", \"insertFront\", \"getFront\"]", "[2,1,2,0,3,0,0,4,0]"], ["[\"MyCircularDeque\", \"deleteFront\", \"deleteLast\", \"getFront\", \"getRear\"]", "[3,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"insertFront\", \"insertFront\", \"isFull\", \"getFront\", \"getRear\"]", "[3,1,2,3,0,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"deleteLast\", \"deleteLast\", \"isEmpty\", \"insertFront\", \"getRear\"]", "[1,7,0,0,0,8,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"deleteLast\", \"insertLast\", \"deleteFront\", \"isEmpty\", \"isFull\"]", "[2,5,0,6,0,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"insertFront\", \"insertLast\", \"getFront\", \"getRear\", \"isFull\", \"deleteFront\", \"deleteLast\", \"getFront\", \"getRear\"]", "[3,1,2,3,0,0,0,0,0,0,0]"], ["[\"MyCircularDeque\", \"isEmpty\", \"isFull\", \"getFront\", \"getRear\"]", "[5,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"getRear\", \"insertLast\", \"getFront\", \"isFull\"]", "[1,10,0,20,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"insertLast\", \"deleteFront\", \"deleteFront\", \"insertFront\", \"insertFront\", \"getFront\", \"getRear\"]", "[4,1,2,3,0,0,4,5,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"insertLast\", \"deleteFront\", \"deleteLast\", \"insertFront\", \"insertLast\", \"isEmpty\", \"isFull\"]", "[2,1,2,0,0,3,4,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"getFront\", \"getRear\", \"deleteLast\", \"getFront\", \"isEmpty\"]", "[3,9,0,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"insertFront\", \"deleteLast\", \"getRear\", \"insertLast\", \"getFront\"]", "[2,1,2,0,0,3,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"deleteFront\", \"insertFront\", \"getRear\", \"getFront\", \"isFull\"]", "[3,5,6,0,7,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"isEmpty\", \"isFull\", \"getFront\", \"deleteFront\", \"getFront\"]", "[1,4,0,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"insertLast\", \"insertLast\", \"isFull\", \"getFront\", \"getRear\", \"deleteLast\", \"deleteFront\", \"getFront\"]", "[3,1,2,3,4,0,0,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"deleteFront\", \"insertFront\", \"deleteFront\", \"insertFront\", \"getFront\", \"getRear\"]", "[1,1,0,2,0,3,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"insertFront\", \"getFront\", \"getRear\", \"deleteLast\", \"deleteFront\", \"isEmpty\", \"isFull\"]", "[2,10,20,0,0,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"insertFront\", \"insertFront\", \"deleteLast\", \"deleteLast\", \"deleteLast\", \"deleteLast\", \"isEmpty\"]", "[2,1,2,3,0,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"getRear\", \"deleteFront\", \"getFront\", \"insertFront\", \"getRear\", \"isFull\"]", "[5,100,0,0,0,200,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"insertLast\", \"insertFront\", \"insertLast\", \"getFront\", \"getRear\", \"isFull\", \"isEmpty\"]", "[4,1,2,3,4,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"deleteFront\", \"isEmpty\", \"insertFront\", \"getFront\", \"getRear\", \"isFull\", \"deleteLast\"]", "[1,42,0,0,7,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertFront\", \"insertFront\", \"deleteFront\", \"insertLast\", \"getFront\", \"getRear\", \"isFull\", \"isEmpty\"]", "[3,0,1000,0,500,0,0,0,0]"], ["[\"MyCircularDeque\", \"insertLast\", \"insertLast\", \"insertLast\", \"isFull\", \"deleteFront\", \"insertLast\", \"isFull\", \"getRear\"]", "[2,1,2,3,0,0,3,0,0]"], ["@javascript:JSON.stringify(['MyCircularDeque',...Array(1200).fill('insertLast'),...Array(800).fill('deleteFront'),...Array(400).fill('insertFront'),'getFront','getRear','isFull','isEmpty'])", "@javascript:JSON.stringify([1000,...Array.from({length:1200},(_,i)=>i%1001),...Array(800).fill(0),...Array.from({length:400},(_,i)=>(i*7)%1001),0,0,0,0])"]], "expected": [[1, 1, 1, 0, 2, 1, 1, 1, 4], [-1, -1, 1, 1, 0, 1, 1], [1, 5, 1, 1], [1, 1, 1, 2, 1, 2, 1, 1], [1, 1, 1, 0, 2, 1, 1, 4], [0, 0, -1, -1], [1, 1, 1, 1, 3, 1], [1, 1, 0, 1, 1, 8], [1, 1, 1, 1, 1, 0], [1, 1, 1, 2, 3, 1, 1, 1, 1, 1], [1, 0, -1, -1], [1, 10, 0, 10, 1], [1, 1, 1, 1, 1, 1, 1, 5, 3], [1, 1, 1, 1, 1, 1, 0, 1], [1, 9, 9, 1, -1, 1], [1, 1, 1, 2, 1, 2], [1, 1, 1, 1, 6, 7, 0], [1, 0, 1, 4, 1, -1], [1, 1, 1, 0, 1, 1, 3, 1, 1, 2], [1, 1, 1, 1, 1, 3, 3], [1, 1, 20, 10, 1, 1, 1, 0], [1, 1, 0, 1, 1, 0, 0, 1], [1, 100, 1, -1, 1, 200, 0], [1, 1, 1, 1, 3, 4, 1, 0], [1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 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, 791, 999, 0, 0]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "192", "slug": "design-circular-queue", "id": 192, "title": "Design Circular Queue", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/design-circular-queue/", "examples": [{"input": "operations = [\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"Rear\",\"isFull\",\"deQueue\",\"enQueue\",\"Rear\"], values = [3,1,2,3,4,0,0,0,4,0]", "output": "[1,1,1,0,3,1,1,1,4]", "explanation": "Capacity 3. EnQueue 1, 2, 3 succeed; enQueue 4 fails (full). Rear is 3, isFull is true (1), deQueue succeeds, enQueue 4 succeeds, Rear is 4."}, {"input": "operations = [\"MyCircularQueue\",\"enQueue\",\"Rear\",\"Front\",\"deQueue\",\"isEmpty\"], values = [2,7,0,0,0,0]", "output": "[1,7,7,1,1]", "explanation": "Capacity 2. EnQueue 7 succeeds, Rear and Front are 7, deQueue succeeds, then isEmpty is true (1)."}, {"input": "operations = [\"MyCircularQueue\",\"Front\",\"Rear\",\"isEmpty\",\"enQueue\",\"isFull\"], values = [1,0,0,0,5,0]", "output": "[-1,-1,1,1,1]", "explanation": "Capacity 1 starts empty so Front/Rear are -1 and isEmpty is true (1). EnQueue 5 succeeds, then isFull is true (1)."}], "hints": ["Keep a fixed-size array with head and count pointers; indices wrap with modulo k.", "enQueue fails when full, deQueue fails when empty; Front/Rear return -1 when empty and booleans are encoded as 1/0."], "statement": "Design a circular queue (ring buffer) with a fixed capacity.\n\n`operations[0]` is always `MyCircularQueue` and `values[0]` is the capacity\n`k`. For `i >= 1`, `operations[i]` is one of `enQueue`, `deQueue`, `Front`,\n`Rear`, `isEmpty`, or `isFull`. `values[i]` is used only by `enQueue`;\notherwise it is ignored. Return an array with one entry per operation after\nthe constructor: `enQueue`/`deQueue`/`isEmpty`/`isFull` return `1` for true\nand `0` for false, while `Front`/`Rear` return the element or `-1` when the\nqueue is empty.\n\n**Constraints:**\n\n- `1 <= k <= 1000`\n- `0 <= value <= 1000`\n- At most 3000 calls are made in one trace.\n", "solution": "## Approach\n\nStore elements in a fixed array of size `k` with a `head` index and a `count`.\nThe tail is `(head + count) % k`. `enQueue` writes at the tail unless full,\n`deQueue` advances `head` unless empty, `Front`/`Rear` read the ends (or `-1`\nwhen empty), and `isEmpty`/`isFull` compare `count` against `0`/`k`. Booleans\nare encoded as `1`/`0`.\n\n## Complexity Analysis\n\n- **Time Complexity:** `O(m)` over `m` operations, `O(1)` per operation.\n- **Space Complexity:** `O(k)` for the ring buffer.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def runCircularQueue(self, operations: List[str], values: List[int]) -> List[int]:\n k = values[0]\n buf = [0] * k\n head = 0\n count = 0\n answers: List[int] = []\n for operation, value in zip(operations[1:], values[1:]):\n if operation == \"enQueue\":\n if count == k:\n answers.append(0)\n else:\n buf[(head + count) % k] = value\n count += 1\n answers.append(1)\n elif operation == \"deQueue\":\n if count == 0:\n answers.append(0)\n else:\n head = (head + 1) % k\n count -= 1\n answers.append(1)\n elif operation == \"Front\":\n answers.append(-1 if count == 0 else buf[head])\n elif operation == \"Rear\":\n answers.append(-1 if count == 0 else buf[(head + count - 1) % k])\n elif operation == \"isEmpty\":\n answers.append(1 if count == 0 else 0)\n else:\n answers.append(1 if count == k else 0)\n return answers\n```\n", "starter": {"go": "package main\n\nfunc RunCircularQueue(operations []string, values []int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runCircularQueue(self, operations: List[str], values: List[int]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runCircularQueue(vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runCircularQueue", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"Rear\",\"isFull\",\"deQueue\",\"enQueue\",\"Rear\"]", "[3,1,2,3,4,0,0,0,4,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"Rear\",\"Front\",\"deQueue\",\"isEmpty\"]", "[2,7,0,0,0,0]"], ["[\"MyCircularQueue\",\"Front\",\"Rear\",\"isEmpty\",\"enQueue\",\"isFull\"]", "[1,0,0,0,5,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"Front\",\"Rear\",\"deQueue\",\"Front\"]", "[2,1,2,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"isFull\",\"enQueue\",\"isFull\",\"deQueue\",\"enQueue\",\"Rear\"]", "[1,10,0,20,0,0,20,0]"], ["[\"MyCircularQueue\",\"deQueue\",\"Front\",\"enQueue\",\"Front\",\"Rear\",\"isEmpty\"]", "[2,0,0,3,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"deQueue\",\"deQueue\",\"enQueue\",\"enQueue\",\"Front\",\"Rear\"]", "[3,1,2,3,0,0,4,5,0,0]"], ["[\"MyCircularQueue\",\"isEmpty\",\"isFull\",\"enQueue\",\"isEmpty\",\"isFull\",\"Front\",\"Rear\"]", "[5,0,0,0,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"isFull\",\"deQueue\",\"enQueue\",\"isFull\",\"Rear\"]", "[2,1,2,3,0,0,3,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"Front\",\"Rear\"]", "[1,1,0,2,0,3,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"Rear\",\"Front\",\"deQueue\",\"deQueue\",\"isEmpty\"]", "[3,0,1000,0,500,0,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"isFull\",\"Rear\",\"deQueue\",\"deQueue\",\"enQueue\",\"Front\"]", "[3,1,1,1,1,1,0,0,0,0,2,0]"], ["@javascript:JSON.stringify(['MyCircularQueue',...Array(1200).fill('enQueue'),...Array(800).fill('deQueue'),...Array(400).fill('enQueue'),'Front','Rear','isFull','isEmpty'])", "@javascript:JSON.stringify([1000,...Array.from({length:1200},(_,i)=>i%1001),...Array(800).fill(0),...Array.from({length:400},(_,i)=>(i*7)%1001),0,0,0,0])"], ["[\"MyCircularQueue\",\"enQueue\",\"deQueue\",\"isEmpty\",\"enQueue\",\"Front\",\"Rear\",\"isFull\"]", "[1,42,0,0,7,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"Front\",\"Rear\",\"isFull\",\"isEmpty\"]", "[2,1,2,0,3,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"isFull\",\"deQueue\",\"deQueue\",\"deQueue\",\"isEmpty\"]", "[3,5,6,7,0,0,0,0,0]"], ["[\"MyCircularQueue\",\"Front\",\"Rear\",\"isEmpty\",\"enQueue\",\"Front\",\"Rear\"]", "[5,0,0,0,9,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"deQueue\",\"deQueue\",\"deQueue\"]", "[2,0,0,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"Front\",\"Rear\",\"deQueue\",\"Front\"]", "[4,0,1000,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"Front\",\"Rear\"]", "[3,1,2,0,3,0,4,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"isFull\",\"enQueue\",\"deQueue\",\"isEmpty\",\"deQueue\"]", "[1,5,0,6,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"deQueue\",\"Front\",\"Rear\",\"isFull\"]", "[6,10,20,30,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"deQueue\",\"enQueue\",\"Front\",\"Rear\",\"isEmpty\",\"isFull\"]", "[2,1,0,2,0,3,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"Front\",\"Rear\",\"isEmpty\",\"isFull\"]", "[10,100,200,0,0,0,0]"], ["[\"MyCircularQueue\",\"deQueue\",\"deQueue\",\"enQueue\",\"Front\",\"deQueue\",\"isEmpty\"]", "[3,0,0,8,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"isFull\",\"deQueue\",\"enQueue\",\"Rear\",\"Front\"]", "[4,1,2,3,4,0,0,5,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"Front\",\"Rear\",\"isFull\",\"isEmpty\"]", "[1000,1000,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"Front\",\"Rear\",\"deQueue\",\"Front\",\"Rear\"]", "[2,0,1,0,0,0,0,0]"], ["[\"MyCircularQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"enQueue\",\"deQueue\",\"deQueue\",\"enQueue\",\"Front\",\"Rear\"]", "[5,1,2,3,4,5,0,0,6,0,0]"], ["[\"MyCircularQueue\",\"isEmpty\",\"enQueue\",\"isEmpty\",\"isFull\",\"enQueue\",\"enQueue\",\"isFull\"]", "[3,0,1,0,0,2,3,0]"]], "expected": [[1, 1, 1, 0, 3, 1, 1, 1, 4], [1, 7, 7, 1, 1], [-1, -1, 1, 1, 1], [1, 1, 1, 2, 1, 2], [1, 1, 0, 1, 1, 1, 20], [0, -1, 1, 3, 3, 0], [1, 1, 1, 1, 1, 1, 1, 3, 5], [1, 0, 1, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 800, 791, 0, 0], [1, 1, 1, 1, 7, 7, 1], [1, 1, 1, 1, 2, 3, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1], [-1, -1, 1, 1, 9, 9], [1, 1, 0, 1, 1, 0], [1, 1, 0, 1000, 1, 1000], [1, 1, 1, 1, 1, 1, 3, 4], [1, 1, 0, 1, 1, 0], [1, 1, 1, 1, 20, 30, 0], [1, 1, 1, 1, 1, 3, 3, 0, 0], [1, 1, 100, 200, 0, 0], [0, 0, 1, 8, 1, 1], [1, 1, 1, 1, 1, 1, 1, 5, 2], [1, 1000, 1000, 0, 0], [1, 1, 0, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 3, 6], [1, 1, 0, 0, 1, 1, 1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "640", "slug": "design-compressed-string-iterator", "id": 640, "title": "Design Compressed String Iterator", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/design-compressed-string-iterator/", "examples": [{"input": "compressed = \"L1e2t1C1o1d1e1\", operations = [\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\",\"next\",\"hasNext\"]", "output": "[\"L\",\"e\",\"e\",\"t\",\"C\",\"true\",\"o\",\"true\"]", "explanation": "Letters expand to L,e,e,t,C,o,d,e; queries consume them in order."}, {"input": "compressed = \"x3\", operations = [\"next\",\"next\",\"next\",\"next\",\"hasNext\"]", "output": "[\"x\",\"x\",\"x\",\"\",\"false\"]", "explanation": "After three x values the stream is empty, so next gives an empty string."}, {"input": "compressed = \"a10\", operations = [\"hasNext\",\"next\",\"hasNext\"]", "output": "[\"true\",\"a\",\"true\"]", "explanation": "Ten copies remain; one next still leaves more."}], "hints": ["Parse letter-plus-count runs once into queues.", "Keep a pointer plus remaining count for the current run.", "next emits the current letter or an empty string when empty; hasNext emits true/false strings.", "Adaptation: implement runCompressedIterator(compressed, operations) returning one string per operation."], "statement": "A compressed string stores each run as a letter followed by its repeat count, such as `\"x3\"` for `\"xxx\"` or `\"a10\"` for ten a's.\n\n**Adaptation note:** instead of a stateful iterator class, implement `runCompressedIterator(compressed, operations)`. Each entry of `operations` is `\"next\"` or `\"hasNext\"`. Return one string per operation in order: `next` gives the next letter as a one-character string, or `\"\"` (empty string) when nothing remains; `hasNext` gives `\"true\"` or `\"false\"`.\n\n**Constraints:**\n- Compressed length is at most 1000; counts are at least 1.\n- At most 500 operations.\n", "solution": "## Approach\n\nDecode the letter-count pairs once, then serve operations with an index plus remaining count. Next returns the current letter or blank when past the end; hasNext reports whether any characters remain.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(C+Q) for compressed length C and Q operations.\n- **Space Complexity:** O(C+Q).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runCompressedIterator(self, compressed: str, operations: List[str]) -> List[str]:\n chs, cnts = [], []\n i, n = 0, len(compressed)\n while i < n:\n c = compressed[i]; i += 1\n j = i\n while j < n and compressed[j].isdigit():\n j += 1\n chs.append(c); cnts.append(int(compressed[i:j]) if j > i else 1)\n i = j\n ans, p, rem = [], 0, cnts[0] if cnts else 0\n for op in operations:\n if op == 'next':\n if p >= len(chs):\n ans.append('')\n else:\n ans.append(chs[p])\n rem -= 1\n if rem == 0:\n p += 1\n if p < len(cnts):\n rem = cnts[p]\n elif op == 'hasNext':\n ans.append('true' if p < len(chs) else 'false')\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunCompressedIterator(compressed string, operations []string) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def runCompressedIterator(self, compressed: str, operations: List[str]) -> List[str]:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> runCompressedIterator(string compressed, vector<string>& operations) {\n return {};\n }\n};"}, "fn": "runCompressedIterator", "params": [{"name": "compressed", "type": "string"}, {"name": "operations", "type": "string_array"}], "outputType": "string_list", "tests": [["L1e2t1C1o1d1e1", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["x3", "[\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["a10", "[\"hasNext\",\"next\",\"hasNext\"]"], ["a1", "[\"next\",\"hasNext\",\"next\"]"], ["b2c3", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["z1", "[\"hasNext\",\"hasNext\"]"], ["m5", "[\"next\",\"next\",\"hasNext\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["a2b2", "[\"hasNext\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["q12", "[\"next\",\"next\",\"hasNext\"]"], ["a1b1", "[\"next\",\"next\",\"next\",\"hasNext\"]"], ["A1B1C1", "[\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["k1", "[\"next\",\"next\"]"], ["t4", "[\"hasNext\",\"hasNext\",\"next\",\"next\",\"next\",\"next\",\"next\"]"], ["w10", "[\"next\",\"next\",\"next\",\"hasNext\"]"], ["p3q1", "[\"next\",\"next\",\"next\",\"next\",\"hasNext\",\"next\"]"], ["e1", "[\"hasNext\",\"next\",\"hasNext\",\"next\"]"], ["r2s2t2", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["c100", "[\"hasNext\",\"next\",\"hasNext\"]"], ["d2e1", "[\"next\",\"next\",\"next\",\"next\"]"], ["f1g10", "[\"next\",\"next\",\"hasNext\",\"next\"]"], ["h7", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["i1j1k1l1", "[\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["n20", "[\"hasNext\",\"next\",\"next\",\"hasNext\"]"], ["o2", "[\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\"]"], ["s1t2u3", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["v5w5", "[\"hasNext\",\"next\",\"next\",\"hasNext\",\"next\"]"], ["y9", "[\"next\",\"next\",\"hasNext\",\"next\"]"], ["L2o2p2", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\",\"next\"]"]], "expected": [["L", "e", "e", "t", "C", "true", "o", "true"], ["x", "x", "x", "", "false"], ["true", "a", "true"], ["a", "false", ""], ["b", "b", "c", "c", "c", "false"], ["true", "true"], ["m", "m", "true", "m", "m", "m", "false"], ["true", "a", "a", "b", "true"], ["q", "q", "true"], ["a", "b", "", "false"], ["A", "B", "C", "", "false"], ["k", ""], ["true", "true", "t", "t", "t", "t", ""], ["w", "w", "w", "true"], ["p", "p", "p", "q", "false", ""], ["true", "e", "false", ""], ["r", "r", "s", "s", "t", "t", "false"], ["true", "c", "true"], ["d", "d", "e", ""], ["f", "g", "true", "g"], ["h", "h", "h", "h", "h", "h", "h", "", "false"], ["i", "j", "k", "l", "false"], ["true", "n", "n", "true"], ["o", "true", "o", "false", ""], ["s", "t", "t", "u", "u", "u", "false"], ["true", "v", "v", "true", "v"], ["y", "y", "true", "y"], ["L", "L", "o", "o", "p", "p", "false", ""]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "653", "slug": "design-excel-sum-formula", "id": 653, "title": "Design Excel Sum Formula", "difficulty": "Hard", "category": "design", "link": "https://leetcode.com/problems/design-excel-sum-formula/", "examples": [{"input": "operations = [\"Excel\",\"set\",\"get\",\"sum\",\"get\"], args = [[[\"3\",\"3\"]],[\"1\",\"1\",\"2\"],[\"1\",\"1\"],[\"1\",\"2\",\"A1\",\"A2\"],[\"1\",\"2\"]]", "output": "[2,4]", "explanation": "Build a 3x3 sheet; set A1 to 2; get A1 is 2; sum A1+A2 into B1 gives 4 (A2 is 0); get B1 is 4."}, {"input": "operations = [\"Excel\",\"set\",\"set\",\"sum\",\"get\"], args = [[[\"2\",\"2\"]],[\"1\",\"1\",\"5\"],[\"1\",\"2\",\"7\"],[\"2\",\"1\",\"A1\",\"B1\"],[\"2\",\"1\"]]", "output": "[12]", "explanation": "A1=5 and B1=7, so the formula A1+B1 stored at A2 evaluates to 12."}], "hints": ["Model columns as 1-based numbers (A=1, B=2, ...); keep a value grid plus a formula map keyed by cell.", "set writes the value and clears any formula on that cell; get evaluates live (following formulas recursively).", "sum stores the token list as the cell formula (each token is a cell like B2 or a rectangle like A1:B2) and returns the evaluated total.", "Only get and sum produce outputs, collected in call order into the int_array result.", "Adaptation: this judge drives the sheet through runExcel(operations, args) with all arguments stringified; the constructor takes [height, widthCount] and set/get/sum take 1-based [row, col] plus values or formula tokens."], "statement": "You must simulate a tiny spreadsheet with `height` rows and a fixed column count (column 1 is A, 2 is B, and so on). All cells start at 0 and rows/columns are 1-based.\n\nSupported actions, issued as parallel operation/argument lists:\n\n- `Excel [height, widthCount]`: create the sheet.\n- `set [r, c, v]`: write value `v` into cell (r, c), discarding any formula previously stored there.\n- `get [r, c]`: return the current value of cell (r, c), evaluating its formula first when one exists (formulas chain, so changes propagate on read).\n- `sum [r, c, t1, t2, ...]`: store a formula on (r, c) equal to the total of the listed tokens, then return that total. Each token is either one cell such as `B2` or a rectangle such as `A1:B2` covering every cell in the inclusive rectangle.\n\nCollect the answers of every `get` and `sum` call in order and return them as an array.\n\n**Constraints:**\n- Sheet dimensions are small (single digits in tests).\n- Values and totals fit in 32-bit signed integers.\n- Formula chains contain no cycles in the tests.\n\n*Adaptation: this judge drives the sheet through `runExcel(operations, args)` with every argument stringified. The constructor takes `[height, widthCount]`; cell coordinates are 1-based `[row, col]` numbers; formula tokens keep letter-number form like `A1` or `A1:B2`.*\n", "solution": "## Approach\n\nKeep a value grid plus a formula table keyed by cell. Setting writes the value and drops any formula; getting evaluates the stored token list on demand (recursing through chains); summing records the token list then evaluates it. Each token is either a single cell reference decoded from letters-plus-digits or a colon rectangle expanded into its inclusive rows and columns. Because evaluation is lazy, later writes are automatically reflected on the next read.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(q * R * C) in the worst case, where q is the operation count and R*C bounds rectangle expansion.\n- **Space Complexity:** O(H * W + F) for the grid plus stored formulas.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runExcel(self, operations: List[str], args: List[List[str]]) -> List[int]:\n vals = {}\n formulas = {}\n H = W = 0\n def parse(cell):\n i = 0\n while i < len(cell) and cell[i].isalpha():\n i += 1\n col_s, row_s = cell[:i].upper(), cell[i:]\n c = 0\n for ch in col_s:\n c = c * 26 + (ord(ch) - ord('A') + 1)\n return int(row_s), c\n def get(r, c):\n key = (r, c)\n if key not in formulas:\n return vals.get(key, 0)\n s = 0\n for t in formulas[key]:\n s += ev(t)\n return s\n def ev(t):\n if \":\" in t:\n a, b = t.split(\":\")\n r1, c1 = parse(a)\n r2, c2 = parse(b)\n s = 0\n for r in range(min(r1, r2), max(r1, r2) + 1):\n for c in range(min(c1, c2), max(c1, c2) + 1):\n s += get(r, c)\n return s\n r, c = parse(t)\n return get(r, c)\n out = []\n for op, a in zip(operations, args):\n if op == \"Excel\":\n H, W = int(a[0]), int(a[1])\n vals, formulas = {}, {}\n elif op == \"set\":\n r, c, v = int(a[0]), int(a[1]), int(a[2])\n formulas.pop((r, c), None)\n vals[(r, c)] = v\n elif op == \"get\":\n out.append(get(int(a[0]), int(a[1])))\n elif op == \"sum\":\n r, c = int(a[0]), int(a[1])\n formulas[(r, c)] = list(a[2:])\n out.append(get(r, c))\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunExcel(operations []string, args [][]string) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runExcel(self, operations: List[str], args: List[List[str]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runExcel(vector<string>& operations, vector<vector<string>>& args) {\n return {};\n }\n};"}, "fn": "runExcel", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "string_list_2d"}], "outputType": "int_array", "tests": [["[\"Excel\",\"set\",\"get\",\"sum\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"2\"],[\"1\",\"1\"],[\"1\",\"2\",\"A1\",\"A2\"],[\"1\",\"2\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"2\",\"2\"],[\"1\",\"1\",\"5\"],[\"1\",\"2\",\"7\"],[\"2\",\"1\",\"A1\",\"B1\"],[\"2\",\"1\"]]"], ["[\"Excel\",\"get\"]", "[[\"1\",\"1\"],[\"1\",\"1\"]]"], ["[\"Excel\",\"set\",\"get\"]", "[[\"2\",\"3\"],[\"2\",\"3\",\"10\"],[\"2\",\"3\"]]"], ["[\"Excel\",\"set\",\"sum\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"1\"],[\"3\",\"3\",\"A1\",\"A1\",\"A1\"],[\"3\",\"3\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"2\"],[\"2\",\"1\",\"3\"],[\"3\",\"1\",\"A1:A2\"],[\"3\",\"1\"],[\"1\",\"1\"]]"], ["[\"Excel\",\"set\",\"sum\",\"set\",\"get\",\"get\"]", "[[\"2\",\"2\"],[\"1\",\"1\",\"4\"],[\"2\",\"2\",\"A1\"],[\"1\",\"1\",\"9\"],[\"2\",\"2\"],[\"1\",\"1\"]]"], ["[\"Excel\",\"set\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"1\"],[\"1\",\"2\",\"2\"],[\"1\",\"3\",\"3\"],[\"2\",\"2\",\"A1:C1\"],[\"2\",\"2\"]]"], ["[\"Excel\",\"set\",\"get\",\"get\"]", "[[\"2\",\"2\"],[\"1\",\"1\",\"7\"],[\"1\",\"1\"],[\"2\",\"2\"]]"], ["[\"Excel\",\"sum\",\"get\"]", "[[\"2\",\"2\"],[\"1\",\"1\",\"A2\"],[\"1\",\"1\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"sum\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"1\"],[\"2\",\"2\",\"2\"],[\"3\",\"3\",\"A1\",\"B2\"],[\"3\",\"3\",\"A1:B2\"],[\"3\",\"3\"]]"], ["[\"Excel\",\"set\",\"set\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"2\",\"4\"],[\"1\",\"1\",\"1\"],[\"1\",\"2\",\"2\"],[\"1\",\"3\",\"3\"],[\"1\",\"4\",\"4\"],[\"2\",\"1\",\"A1:D1\"],[\"2\",\"1\"]]"], ["[\"Excel\",\"set\",\"sum\",\"get\",\"set\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"5\"],[\"1\",\"2\",\"A1\"],[\"1\",\"2\"],[\"1\",\"1\",\"1\"],[\"1\",\"2\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"5\",\"5\"],[\"3\",\"3\",\"8\"],[\"4\",\"4\",\"2\"],[\"5\",\"5\",\"C3:D4\"],[\"5\",\"5\"]]"], ["[\"Excel\",\"set\",\"get\"]", "[[\"1\",\"26\"],[\"1\",\"26\",\"42\"],[\"1\",\"26\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\",\"set\",\"get\"]", "[[\"4\",\"4\"],[\"2\",\"2\",\"3\"],[\"2\",\"3\",\"4\"],[\"4\",\"4\",\"B2:C2\"],[\"4\",\"4\"],[\"2\",\"2\",\"10\"],[\"4\",\"4\"]]"], ["[\"Excel\",\"set\",\"sum\",\"get\"]", "[[\"2\",\"2\"],[\"1\",\"1\",\"6\"],[\"1\",\"2\",\"A1:A1\"],[\"1\",\"2\"]]"], ["[\"Excel\",\"set\",\"set\",\"get\",\"get\"]", "[[\"3\",\"2\"],[\"3\",\"1\",\"-5\"],[\"2\",\"2\",\"-3\"],[\"3\",\"1\"],[\"2\",\"2\"]]"], ["[\"Excel\",\"set\",\"sum\",\"sum\",\"get\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"2\"],[\"2\",\"1\",\"A1\"],[\"3\",\"1\",\"A2\"],[\"2\",\"1\"],[\"3\",\"1\"]]"], ["[\"Excel\",\"set\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"2\",\"2\"],[\"1\",\"1\",\"1\"],[\"1\",\"2\",\"1\"],[\"2\",\"1\",\"1\"],[\"2\",\"2\",\"A1:B1\"],[\"2\",\"2\"]]"], ["[\"Excel\",\"get\",\"get\"]", "[[\"3\",\"3\"],[\"3\",\"3\"],[\"1\",\"1\"]]"], ["[\"Excel\",\"set\",\"sum\",\"get\"]", "[[\"4\",\"4\"],[\"4\",\"4\",\"100\"],[\"1\",\"1\",\"D4\"],[\"1\",\"1\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"2\",\"3\"],[\"2\",\"1\",\"3\"],[\"2\",\"2\",\"4\"],[\"2\",\"3\",\"A2:B2\"],[\"2\",\"3\"]]"], ["[\"Excel\",\"set\",\"sum\",\"get\",\"get\"]", "[[\"2\",\"2\"],[\"1\",\"2\",\"5\"],[\"2\",\"1\",\"B1\"],[\"2\",\"1\"],[\"1\",\"2\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"3\",\"1\"],[\"1\",\"1\",\"1\"],[\"2\",\"1\",\"2\"],[\"3\",\"1\",\"A1\",\"A2\"],[\"3\",\"1\"]]"], ["[\"Excel\",\"set\",\"sum\",\"get\"]", "[[\"5\",\"2\"],[\"5\",\"2\",\"9\"],[\"1\",\"1\",\"B5\"],[\"1\",\"1\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\"]", "[[\"3\",\"3\"],[\"1\",\"1\",\"1\"],[\"3\",\"3\",\"2\"],[\"2\",\"2\",\"A1:C1\"],[\"2\",\"2\"]]"], ["[\"Excel\",\"set\",\"set\",\"sum\",\"get\",\"get\"]", "[[\"2\",\"5\"],[\"1\",\"5\",\"11\"],[\"1\",\"1\",\"1\"],[\"2\",\"1\",\"A1:E1\"],[\"2\",\"1\"],[\"1\",\"5\"]]"]], "expected": [[2, 2, 2], [12, 12], [0], [10], [3, 3], [5, 5, 2], [4, 9, 9], [6, 6], [7, 0], [0, 0], [3, 3, 3], [10, 10], [5, 5, 1], [10, 10], [42], [7, 7, 14], [6, 6], [-5, -3], [2, 2, 2, 2], [2, 2], [0, 0], [100, 100], [7, 7], [5, 5, 5], [3, 3], [9, 9], [1, 1], [12, 12, 11]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "157", "slug": "design-hashmap", "id": 157, "title": "Design HashMap", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/design-hashmap/", "examples": [{"input": "operations = [\"MyHashMap\",\"put\",\"put\",\"get\",\"get\",\"put\",\"get\",\"remove\",\"get\"], values = [[],[1,1],[2,2],[1],[3],[2,1],[2],[2],[2]]", "output": "[null,null,null,1,-1,null,1,null,-1]", "explanation": "put(1,1), put(2,2); get(1) is 1, get(3) is -1. After put(2,1) updates key 2, get(2) is 1; after remove(2), get(2) is -1."}, {"input": "operations = [\"MyHashMap\",\"get\",\"put\",\"get\",\"remove\",\"get\"], values = [[],[5],[5,7],[5],[5],[5]]", "output": "[null,-1,null,7,null,-1]", "explanation": "Initially get(5) is -1. After put(5,7), get(5) is 7; after remove(5), get(5) is -1."}, {"input": "operations = [\"MyHashMap\",\"put\",\"remove\"], values = [[],[3,9],[3]]", "output": "[null,null,null]", "explanation": "No get calls, so every entry is null."}], "hints": ["Store the entries in a hash map: put inserts or updates, remove deletes, get looks up with a -1 default.", "A direct array of size 1000001 with a -1 sentinel also works since keys are bounded.", "Construction, put and remove report \"null\"; each get reports the plain integer result."], "statement": "Design a HashMap without using any built-in hash table libraries.\n\nImplement the `MyHashMap` class:\n\n- `MyHashMap()` Initializes the `MyHashMap` object.\n- `void put(int key, int value)` Inserts or updates the mapping from `key` to `value`.\n- `int get(int key)` Returns the value mapped to `key`, or `-1` if there is no mapping.\n- `void remove(int key)` Removes `key` and its mapped value. If there is no mapping, do nothing.\n\nThe class keeps its LeetCode name `MyHashMap` (the harness reserves `Solution` for the driver); the constructor and methods match the original. Construction, `put` and `remove` report `\"null\"`; each `get` reports the plain integer result.\n\n**Constraints:**\n- `0 <= key, value <= 10^6`\n- At most `10^4` calls will be made to `put`, `get` and `remove` in total.\n- Every trace begins with `MyHashMap`.\n", "solution": "## Approach\n\nSimulate the map over the trace with a hash map: construction starts empty, `put` inserts or overwrites, `remove` deletes (a no-op when absent), and `get` looks up with a `-1` default. Construction, `put` and `remove` report `\"null\"` while each `get` reports the plain integer result; the full per-operation trace is compared exactly against the reference.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) average per `put`, `get` and `remove`.\n- **Space Complexity:** O(k) where k is the number of stored keys.\n\n## Implementation\n\n```python\nclass MyHashMap:\n def __init__(self):\n self.m = {}\n\n def put(self, key: int, value: int) -> None:\n self.m[key] = value\n\n def get(self, key: int) -> int:\n return self.m.get(key, -1)\n\n def remove(self, key: int) -> None:\n self.m.pop(key, None)\n```\n", "starter": {"go": "package main\n\ntype MyHashMap struct {\n\n}\n\nfunc Constructor() MyHashMap {\n return MyHashMap{}\n}\n\nfunc (this *MyHashMap) Put(key int, value int) {\n\n}\n\nfunc (this *MyHashMap) Get(key int) int {\n return -1\n}\n\nfunc (this *MyHashMap) Remove(key int) {\n\n}", "python": "class MyHashMap:\n def __init__(self):\n pass\n\n def put(self, key: int, value: int) -> None:\n pass\n\n def get(self, key: int) -> int:\n return -1\n\n def remove(self, key: int) -> None:\n pass", "cpp": "class MyHashMap {\npublic:\n MyHashMap() {\n\n }\n\n void put(int key, int value) {\n\n }\n\n int get(int key) {\n return -1;\n }\n\n void remove(int key) {\n\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"MyHashMap\", \"put\", \"put\", \"get\", \"get\", \"put\", \"get\", \"remove\", \"get\"]", "[[], [1, 1], [2, 2], [1], [3], [2, 1], [2], [2], [2]]"], ["[\"MyHashMap\", \"get\", \"put\", \"get\", \"remove\", \"get\"]", "[[], [5], [5, 7], [5], [5], [5]]"], ["[\"MyHashMap\", \"put\", \"remove\"]", "[[], [3, 9], [3]]"], ["[\"MyHashMap\", \"put\", \"get\", \"put\", \"get\"]", "[[], [0, 0], [0], [0, 5], [0]]"], ["[\"MyHashMap\", \"put\", \"put\", \"get\", \"remove\", \"get\"]", "[[], [1000000, 5], [1000000, 6], [1000000], [1000000], [1000000]]"], ["[\"MyHashMap\", \"remove\", \"get\", \"put\", \"get\"]", "[[], [42], [42], [42, 1], [42]]"], ["[\"MyHashMap\", \"put\", \"put\", \"put\", \"get\", \"get\", \"get\"]", "[[], [1, 10], [2, 20], [3, 30], [1], [2], [4]]"], ["[\"MyHashMap\", \"put\", \"get\", \"remove\", \"get\", \"put\", \"get\"]", "[[], [7, 3], [7], [7], [7], [7, 4], [7]]"], ["[\"MyHashMap\", \"put\", \"put\", \"remove\", \"get\", \"get\"]", "[[], [1, 1], [1, 2], [1], [1], [2]]"], ["[\"MyHashMap\", \"get\", \"get\"]", "[[], [0], [1000000]]"], ["[\"MyHashMap\", \"put\", \"remove\", \"put\", \"get\"]", "[[], [9, 9], [9], [9, 10], [9]]"], ["[\"MyHashMap\", \"put\", \"put\", \"put\", \"put\", \"put\", \"get\", \"get\", \"get\", \"get\", \"get\"]", "[[], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [1], [3], [5], [7], [11]]"], ["[\"MyHashMap\", \"remove\", \"get\", \"put\", \"put\", \"put\", \"remove\", \"get\", \"get\"]", "[[], [23], [25], [-5, -36], [13, 8], [2, 16], [29], [8], [-18]]"], ["[\"MyHashMap\", \"remove\", \"remove\", \"put\", \"put\", \"put\", \"remove\", \"put\", \"remove\", \"put\", \"get\", \"get\", \"put\"]", "[[], [13], [21], [-27, -90], [26, -13], [-9, 39], [23], [25, 71], [16], [-11, -100], [5], [-24], [-3, 70]]"], ["[\"MyHashMap\", \"get\", \"put\", \"put\", \"get\", \"get\"]", "[[], [21], [-1, -75], [24, 12], [-16], [-30]]"], ["[\"MyHashMap\", \"put\", \"remove\", \"get\", \"put\", \"remove\", \"remove\", \"remove\", \"remove\", \"get\", \"put\", \"get\", \"get\"]", "[[], [-16, -99], [8], [-17], [18, 36], [12], [-9], [-2], [4], [4], [-8, -80], [-11], [-1]]"], ["[\"MyHashMap\", \"put\", \"remove\", \"get\", \"remove\", \"get\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\"]", "[[], [-25, 9], [2], [-5], [-19], [16], [-24], [-3], [19], [16], [-12], [6]]"], ["[\"MyHashMap\", \"put\", \"get\", \"get\", \"get\", \"get\", \"get\", \"get\", \"put\"]", "[[], [-18, -31], [-16], [-4], [28], [29], [23], [-7], [-12, 85]]"], ["[\"MyHashMap\", \"get\", \"get\", \"get\", \"put\", \"get\", \"put\", \"get\", \"put\", \"get\", \"remove\"]", "[[], [-11], [-26], [29], [-29, 36], [17], [7, 38], [18], [-5, -18], [-7], [16]]"], ["[\"MyHashMap\", \"put\", \"put\", \"put\", \"get\", \"remove\", \"get\", \"put\", \"put\", \"put\", \"remove\", \"remove\", \"get\"]", "[[], [-6, -35], [-5, -30], [6, 76], [-9], [-13], [-4], [7, 3], [-17, -77], [10, 37], [-2], [0], [-1]]"], ["[\"MyHashMap\", \"put\", \"get\", \"remove\", \"get\", \"get\", \"get\", \"remove\", \"get\", \"get\", \"get\"]", "[[], [24, -26], [-13], [19], [19], [-22], [-5], [-24], [-29], [15], [29]]"], ["[\"MyHashMap\", \"get\", \"get\", \"put\", \"remove\", \"get\", \"remove\", \"get\", \"get\", \"remove\"]", "[[], [13], [19], [-17, 70], [14], [-9], [-27], [-5], [-8], [20]]"], ["[\"MyHashMap\", \"get\", \"put\", \"get\", \"get\", \"remove\"]", "[[], [-17], [8, -88], [14], [-21], [22]]"], ["[\"MyHashMap\", \"put\", \"get\", \"get\", \"get\", \"get\"]", "[[], [17, 54], [2], [5], [12], [7]]"], ["[\"MyHashMap\", \"put\", \"get\", \"put\", \"put\", \"get\", \"put\", \"put\", \"get\", \"put\", \"put\", \"remove\", \"remove\"]", "[[], [-21, 99], [-17], [-30, -42], [-30, -16], [28], [-18, -68], [-20, 22], [-22], [13, -60], [-18, 33], [-5], [-1]]"], ["[\"MyHashMap\", \"put\", \"put\", \"get\", \"remove\", \"get\"]", "[[], [1, 1], [1, 2], [1], [1], [1]]"], ["[\"MyHashMap\", \"get\", \"remove\", \"get\"]", "[[], [-5], [-5], [-5]]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "156", "slug": "design-hashset", "id": 156, "title": "Design HashSet", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/design-hashset/", "examples": [{"input": "operations = [\"MyHashSet\",\"add\",\"add\",\"contains\",\"contains\",\"remove\",\"contains\"], values = [[],[1],[2],[1],[3],[2],[2]]", "output": "[null,null,null,true,false,null,false]", "explanation": "add(1), add(2); contains(1) is true, contains(3) is false; after remove(2), contains(2) is false."}, {"input": "operations = [\"MyHashSet\",\"contains\",\"add\",\"contains\",\"remove\",\"contains\"], values = [[],[5],[5],[5],[5],[5]]", "output": "[null,false,null,true,null,false]", "explanation": "Initially contains(5) is false. After add(5) it is true; after remove(5) it is false again."}, {"input": "operations = [\"MyHashSet\",\"add\",\"remove\"], values = [[],[7],[7]]", "output": "[null,null,null]", "explanation": "No contains calls, so every entry is null."}], "hints": ["Store the keys in a hash set: add inserts, remove deletes, contains checks membership.", "A boolean array of size 1000001 also works since keys are bounded, giving O(1) operations.", "Construction, add and remove report \"null\"; each contains reports \"true\" or \"false\"."], "statement": "Design a HashSet without using any built-in hash table libraries.\n\nImplement the `MyHashSet` class:\n\n- `MyHashSet()` Initializes the `MyHashSet` object.\n- `void add(int key)` Inserts the value `key` into the HashSet.\n- `bool contains(int key)` Returns whether the value `key` exists in the HashSet or not.\n- `void remove(int key)` Removes the value `key` from the HashSet. If `key` does not exist, do nothing.\n\nThe class keeps its LeetCode name `MyHashSet` (the harness reserves `Solution` for the driver); the constructor and methods match the original. Construction, `add` and `remove` report `\"null\"`; each `contains` reports `\"true\"` or `\"false\"`.\n\n**Constraints:**\n- `0 <= key <= 10^6`\n- At most `10^4` calls will be made to `add`, `remove` and `contains` in total.\n- Every trace begins with `MyHashSet`.\n", "solution": "## Approach\n\nSimulate the set over the trace with a hash set: construction starts empty, `add` inserts, `remove` deletes (a no-op when absent), and `contains` checks membership. Construction, `add` and `remove` report `\"null\"` while each `contains` reports `\"true\"` or `\"false\"`; the full per-operation trace is compared exactly against the reference.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) average per `add`, `remove` and `contains`.\n- **Space Complexity:** O(k) where k is the number of stored keys.\n\n## Implementation\n\n```python\nclass MyHashSet:\n def __init__(self):\n self.s = set()\n\n def add(self, key: int) -> None:\n self.s.add(key)\n\n def remove(self, key: int) -> None:\n self.s.discard(key)\n\n def contains(self, key: int) -> bool:\n return key in self.s\n```\n", "starter": {"go": "package main\n\ntype MyHashSet struct {\n\n}\n\nfunc Constructor() MyHashSet {\n return MyHashSet{}\n}\n\nfunc (this *MyHashSet) Add(key int) {\n\n}\n\nfunc (this *MyHashSet) Remove(key int) {\n\n}\n\nfunc (this *MyHashSet) Contains(key int) bool {\n return false\n}", "python": "class MyHashSet:\n def __init__(self):\n pass\n\n def add(self, key: int) -> None:\n pass\n\n def remove(self, key: int) -> None:\n pass\n\n def contains(self, key: int) -> bool:\n return False", "cpp": "class MyHashSet {\npublic:\n MyHashSet() {\n\n }\n\n void add(int key) {\n\n }\n\n void remove(int key) {\n\n }\n\n bool contains(int key) {\n return false;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"MyHashSet\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\"]", "[[], [1], [2], [1], [3], [2], [2], [2], [2]]"], ["[\"MyHashSet\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\"]", "[[], [5], [5], [5], [5], [5]]"], ["[\"MyHashSet\", \"add\", \"remove\"]", "[[], [7], [7]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"remove\", \"contains\"]", "[[], [0], [0], [0], [0]]"], ["[\"MyHashSet\", \"add\", \"add\", \"contains\", \"remove\", \"contains\", \"contains\"]", "[[], [1000000], [0], [1000000], [1000000], [1000000], [0]]"], ["[\"MyHashSet\", \"add\", \"add\", \"add\", \"contains\", \"contains\", \"remove\", \"contains\"]", "[[], [1], [1], [1], [1], [2], [1], [1]]"], ["[\"MyHashSet\", \"remove\", \"contains\", \"add\", \"contains\"]", "[[], [42], [42], [42], [42]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\", \"add\", \"contains\"]", "[[], [10], [10], [20], [20], [10], [10], [10], [10]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"contains\", \"contains\"]", "[[], [5], [5], [6], [5]]"], ["[\"MyHashSet\", \"add\", \"add\", \"add\", \"add\", \"contains\", \"contains\", \"contains\", \"contains\"]", "[[], [1], [2], [3], [4], [1], [2], [5], [4]]"], ["[\"MyHashSet\", \"add\", \"remove\", \"add\", \"contains\"]", "[[], [9], [9], [9], [9]]"], ["[\"MyHashSet\"]", "[[]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"contains\", \"add\"]", "[[], [40], [30], [-29], [-35], [16], [30], [39], [-16], [30]]"], ["[\"MyHashSet\", \"add\", \"add\", \"add\", \"contains\", \"add\"]", "[[], [21], [-40], [-49], [40], [-1]]"], ["[\"MyHashSet\", \"add\", \"add\", \"add\", \"add\", \"add\", \"contains\", \"add\", \"add\", \"remove\"]", "[[], [-6], [15], [24], [28], [-50], [-43], [2], [-18], [45]]"], ["[\"MyHashSet\", \"add\", \"add\", \"contains\", \"remove\", \"remove\"]", "[[], [-33], [6], [0], [0], [20]]"], ["[\"MyHashSet\", \"add\", \"remove\", \"contains\", \"remove\", \"remove\", \"add\", \"add\"]", "[[], [35], [-37], [-12], [-37], [22], [-2], [40]]"], ["[\"MyHashSet\", \"remove\", \"add\", \"contains\", \"remove\", \"add\", \"contains\", \"add\", \"add\", \"remove\", \"add\", \"contains\", \"contains\"]", "[[], [44], [35], [49], [7], [13], [19], [-15], [-8], [41], [-13], [11], [-6]]"], ["[\"MyHashSet\", \"remove\", \"remove\", \"add\", \"add\", \"contains\", \"add\", \"remove\", \"remove\", \"contains\", \"add\", \"add\"]", "[[], [0], [-24], [-10], [21], [22], [-20], [31], [34], [4], [-27], [49]]"], ["[\"MyHashSet\", \"contains\", \"remove\", \"remove\", \"contains\", \"remove\"]", "[[], [17], [-36], [-4], [-3], [13]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"contains\", \"add\", \"remove\", \"contains\"]", "[[], [-19], [27], [-1], [18], [20], [17]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"add\", \"remove\", \"remove\", \"add\", \"add\"]", "[[], [-27], [30], [-41], [19], [36], [36], [39]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"add\", \"contains\", \"add\", \"add\", \"contains\", \"add\", \"contains\", \"remove\", \"contains\", \"add\"]", "[[], [38], [30], [35], [38], [18], [-21], [23], [-19], [31], [30], [10], [-22]]"], ["[\"MyHashSet\", \"remove\", \"contains\", \"remove\", \"contains\", \"contains\", \"contains\", \"add\", \"contains\", \"add\"]", "[[], [6], [32], [3], [7], [33], [13], [4], [-20], [-50]]"], ["[\"MyHashSet\", \"contains\", \"remove\", \"add\", \"add\", \"add\", \"contains\", \"contains\", \"add\", \"add\"]", "[[], [-48], [-37], [12], [-38], [50], [48], [-7], [-9], [-26]]"], ["[\"MyHashSet\", \"add\", \"contains\", \"remove\", \"contains\"]", "[[], [0], [0], [0], [0]]"], ["[\"MyHashSet\", \"add\", \"add\", \"contains\", \"contains\"]", "[[], [1000000], [-1000000], [1000000], [-1000000]]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "441", "slug": "design-hit-counter", "id": 441, "title": "Design Hit Counter", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/design-hit-counter/", "examples": [{"explanation": "Hits at 1, 2 and 3 are all inside the window (4-300, 4], so getHits(4) returns 3.", "input": "operations = [\"HitCounter\",\"hit\",\"hit\",\"hit\",\"getHits\"], values = [[],[1],[2],[3],[4]]", "output": "[null,null,null,null,3]"}, {"explanation": "At time 301 the window is (1, 301]: the hit at 1 has expired (1 <= 301 - 300) but the hit at 2 still counts. At 302 the window is (2, 302] and both hits have expired.", "input": "operations = [\"HitCounter\",\"hit\",\"hit\",\"getHits\",\"getHits\"], values = [[],[1],[2],[301],[302]]", "output": "[null,null,null,1,0]"}, {"explanation": "With no hits recorded, the query returns 0.", "input": "operations = [\"HitCounter\",\"getHits\"], values = [[],[100]]", "output": "[null,0]"}], "hints": ["Keep hits in a queue in arrival order; timestamps are non-decreasing so the queue stays sorted.", "Before each getHits(T), drop every hit at or below T - 300.", "The queue size after cleanup is the answer; hit and the constructor produce \"null\"."], "statement": "Design a hit counter that records hits at given timestamps (in seconds) and answers how many hits happened during the 5 minutes (300 seconds) ending now. A hit at time `t` counts for a query at time `T` exactly when `T - 300 < t <= T`.\n\nImplement the `HitCounter` class:\n\n- `HitCounter()` Initializes the object.\n- `void hit(int timestamp)` Records a hit at `timestamp`.\n- `int getHits(int timestamp)` Returns the number of hits in the past 5 minutes ending at `timestamp`.\n\nAll calls are made with non-decreasing `timestamp`.\n\nThe class keeps its LeetCode name `HitCounter` here (instead of `Solution`) because the judge harness reserves `Solution` for its driver; the constructor and methods match the original.\n\nGrading is deterministic: every `getHits` answer is compared exactly against a queue-based reference model.\n\n**Constraints:**\n- `1 <= timestamp <= 2 * 10^9`\n- All calls are made with non-decreasing `timestamp`.\n- At most `300` calls will be made to `hit` and `getHits`.\n", "solution": "## Approach\n\nBecause timestamps arrive in non-decreasing order, a queue of hit times stays sorted. Each query first discards every hit at or below `T - 300`, then reports the queue size as the number of hits inside the open-closed window `(T - 300, T]`. `hit` appends in O(1) amortized time.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) amortized per call \u2014 each hit enters and leaves the queue once.\n- **Space Complexity:** O(w) for the hits inside the current window.\n\n## Implementation\n\n```python\nfrom collections import deque\n\nclass HitCounter:\n def __init__(self):\n self.q = deque()\n\n def hit(self, timestamp: int) -> None:\n self.q.append(timestamp)\n\n def getHits(self, timestamp: int) -> int:\n while self.q and self.q[0] <= timestamp - 300:\n self.q.popleft()\n return len(self.q)\n```\n", "starter": {"go": "package main\n\ntype HitCounter struct {\n\n}\n\nfunc Constructor() HitCounter {\n return HitCounter{}\n}\n\nfunc (this *HitCounter) Hit(timestamp int) {\n\n}\n\nfunc (this *HitCounter) GetHits(timestamp int) int {\n return 0\n}\n", "python": "from collections import deque\n\nclass HitCounter:\n def __init__(self):\n\n def hit(self, timestamp: int) -> None:\n\n def getHits(self, timestamp: int) -> int:\n return 0\n", "cpp": "#include <queue>\nusing namespace std;\n\nclass HitCounter {\npublic:\n HitCounter() {\n \n }\n\n void hit(int timestamp) {\n \n }\n\n int getHits(int timestamp) {\n return 0;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"HitCounter\", \"hit\", \"hit\", \"hit\", \"getHits\", \"hit\", \"getHits\", \"getHits\"]", "[[], [1], [2], [3], [4], [300], [300], [301]]"], ["[\"HitCounter\", \"hit\", \"getHits\", \"getHits\"]", "[[], [5], [5], [305]]"], ["[\"HitCounter\", \"getHits\"]", "[[], [100]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"getHits\"]", "[[], [1], [1], [301]]"], ["[\"HitCounter\", \"hit\", \"getHits\"]", "[[], [1], [302]]"], ["[\"HitCounter\", \"getHits\", \"getHits\"]", "[[], [0], [500]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"getHits\", \"getHits\"]", "[[], [1], [300], [300], [301]]"], ["[\"HitCounter\", \"hit\", \"getHits\", \"getHits\", \"getHits\"]", "[[], [299], [300], [599], [600]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"getHits\"]", "[[], [0], [0], [299]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"getHits\"]", "[[], [0], [0], [300]]"], ["[\"HitCounter\", \"hit\", \"getHits\"]", "[[], [0], [300]]"], ["[\"HitCounter\", \"hit\", \"getHits\"]", "[[], [0], [301]]"], ["[\"HitCounter\", \"getHits\"]", "[[], [0]]"], ["[\"HitCounter\", \"hit\", \"getHits\"]", "[[], [1000000], [1000000]]"], ["[\"HitCounter\", \"getHits\", \"getHits\", \"hit\", \"hit\", \"getHits\", \"hit\", \"hit\", \"hit\", \"hit\"]", "[[], [73], [94], [126], [130], [175], [188], [203], [234], [255]]"], ["[\"HitCounter\", \"hit\", \"getHits\", \"getHits\", \"getHits\", \"hit\", \"getHits\"]", "[[], [61], [108], [111], [152], [158], [205]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"hit\", \"hit\", \"getHits\"]", "[[], [48], [64], [79], [101], [148]]"], ["[\"HitCounter\", \"getHits\", \"hit\", \"hit\", \"hit\", \"getHits\"]", "[[], [50], [76], [100], [127], [147]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"hit\", \"hit\", \"getHits\", \"hit\", \"getHits\", \"hit\", \"getHits\", \"getHits\", \"getHits\"]", "[[], [65], [76], [115], [153], [188], [221], [258], [276], [335], [376], [424]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"hit\", \"getHits\", \"hit\", \"hit\", \"getHits\", \"hit\"]", "[[], [62], [92], [112], [147], [174], [203], [260], [270]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"hit\", \"hit\", \"getHits\"]", "[[], [20], [54], [65], [82], [118]]"], ["[\"HitCounter\", \"getHits\", \"getHits\", \"hit\", \"hit\", \"hit\"]", "[[], [6], [34], [66], [69], [72]]"], ["[\"HitCounter\", \"hit\", \"getHits\", \"hit\", \"hit\", \"getHits\", \"hit\", \"hit\"]", "[[], [83], [104], [137], [176], [184], [198], [224]]"], ["[\"HitCounter\", \"hit\", \"hit\", \"hit\", \"getHits\", \"hit\"]", "[[], [51], [80], [98], [156], [188]]"], ["[\"HitCounter\", \"hit\", \"getHits\", \"hit\", \"getHits\", \"hit\", \"hit\", \"hit\", \"hit\", \"hit\", \"hit\", \"getHits\"]", "[[], [3], [44], [54], [92], [103], [109], [125], [134], [142], [159], [203]]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "630", "slug": "design-in-memory-file-system", "id": 630, "title": "Design In-Memory File System", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/design-in-memory-file-system/", "examples": [{"input": "operations = [\"FileSystem\",\"mkdir\",\"ls\",\"addContentToFile\",\"readContentFromFile\",\"ls\"], paths = [\"/\",\"/a/b/c\",\"/\",\"/a/b/c/d\",\"/a/b/c/d\",\"/a/b/c\"], contents = [\"\",\"\",\"\",\"hello\",\"\",\"\"]", "output": "[[\"a\"],[\"hello\"],[\"d\"]]", "explanation": "Listing root shows a; reading the file gives hello; listing its folder shows d."}, {"input": "operations = [\"FileSystem\",\"mkdir\",\"ls\",\"addContentToFile\",\"ls\",\"readContentFromFile\"], paths = [\"/\",\"/x/y\",\"/\",\"/x/y/f\",\"/x/y\",\"/x/y/f\"], contents = [\"\",\"\",\"\",\"data\",\"\",\"\"]", "output": "[[\"x\"],[\"f\"],[\"data\"]]", "explanation": "Root holds x; the folder holds f; the file holds data."}, {"input": "operations = [\"FileSystem\",\"ls\"], paths = [\"/\"], contents = [\"\"]", "output": "[[]]", "explanation": "An empty tree lists nothing."}], "hints": ["Keep a set of directory paths plus a map from file path to its text.", "mkdir adds every missing prefix; adding content creates parent dirs first and appends.", "ls on a file returns its name; ls on a directory returns sorted immediate children.", "Adaptation: implement runFileSystem(operations, paths, contents); void calls produce no rows, while ls and read each append one row."], "statement": "Model a tiny file tree that starts with only the root `/`. Four calls exist: list a path, make directories, append text to a file (creating it when needed), and read a file.\n\n**Adaptation note:** instead of a stateful class, implement `runFileSystem(operations, paths, contents)`. The three arrays share one index per call: `operations[i]` names the call, `paths[i]` is its path, and `contents[i]` carries the extra text for append calls (empty otherwise). The constructor entry `\"FileSystem\"` is ignored. Directory and append calls produce no output rows; each `ls` appends the sorted entry list and each `readContentFromFile` appends a single-element row with the file text. Return those rows in order.\n\n- `ls(path)`: when the path is a file, return its file name; when it is a directory, return the sorted names directly inside it.\n- `mkdir(path)`: create the directory and any missing parents.\n- `addContentToFile(filePath, text)`: create parents when needed, then append `text`.\n- `readContentFromFile(filePath)`: return the stored text.\n\n**Constraints:**\n- `1 <= operations.length <= 500`, all three arrays share that length.\n- Paths use `/`-separated lowercase names; content is lowercase text.\n- Every read or list targets an existing path.\n", "solution": "## Approach\n\nTrack every directory path in a set and every file path in a map to its text. Creating a directory adds all missing prefixes, appending creates parents then extends the stored text, listing a file returns its name while listing a directory gathers sorted immediate children, and reading returns the stored text.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(q*L) for q calls with path length L.\n- **Space Complexity:** O(total stored paths plus content).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runFileSystem(self, operations: List[str], paths: List[str], contents: List[str]) -> List[List[str]]:\n dirs = {'/'}\n files = {}\n def parent(p):\n if p == '/':\n return None\n k = p.rfind('/')\n return '/' if k == 0 else p[:k]\n def base(p):\n return p[p.rfind('/') + 1:]\n def ensure(d):\n if d == '/':\n dirs.add('/'); return\n cur = ''\n for part in d.split('/'):\n if not part:\n continue\n cur += '/' + part\n dirs.add(cur)\n ans = []\n for op, pa, co in zip(operations, paths, contents):\n if op == 'FileSystem':\n continue\n elif op == 'mkdir':\n ensure(pa)\n elif op == 'addContentToFile':\n pr = parent(pa)\n if pr is not None:\n ensure(pr)\n files[pa] = files.get(pa, '') + (co or '')\n elif op == 'ls':\n if pa in files:\n ans.append([base(pa)])\n else:\n kids = set()\n for d in dirs:\n if d != pa and parent(d) == pa:\n kids.add(base(d))\n for f in files:\n if parent(f) == pa:\n kids.add(base(f))\n ans.append(sorted(kids))\n elif op == 'readContentFromFile':\n ans.append([files[pa]])\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunFileSystem(operations []string, paths []string, contents []string) [][]string {\n return [][]string{}\n}", "python": "from typing import List\nclass Solution:\n def runFileSystem(self, operations: List[str], paths: List[str], contents: List[str]) -> List[List[str]]:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<string>> runFileSystem(vector<string>& operations, vector<string>& paths, vector<string>& contents) {\n return {};\n }\n};"}, "fn": "runFileSystem", "params": [{"name": "operations", "type": "string_array"}, {"name": "paths", "type": "string_array"}, {"name": "contents", "type": "string_array"}], "outputType": "string_list_2d", "tests": [["[\"FileSystem\", \"mkdir\", \"ls\", \"addContentToFile\", \"readContentFromFile\", \"ls\"]", "[\"/\", \"/a/b/c\", \"/\", \"/a/b/c/d\", \"/a/b/c/d\", \"/a/b/c\"]", "[\"\", \"\", \"\", \"hello\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"ls\", \"addContentToFile\", \"ls\", \"readContentFromFile\"]", "[\"/\", \"/x/y\", \"/\", \"/x/y/f\", \"/x/y\", \"/x/y/f\"]", "[\"\", \"\", \"\", \"data\", \"\", \"\"]"], ["[\"FileSystem\", \"ls\"]", "[\"/\"]", "[\"\"]"], ["[\"FileSystem\", \"mkdir\", \"ls\"]", "[\"/\", \"/a\", \"/\"]", "[\"\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"mkdir\", \"ls\"]", "[\"/\", \"/a/b\", \"/a/c\", \"/a\"]", "[\"\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"addContentToFile\", \"readContentFromFile\"]", "[\"/\", \"/f\", \"/f\"]", "[\"\", \"hello\", \"\"]"], ["[\"FileSystem\", \"addContentToFile\", \"addContentToFile\", \"readContentFromFile\"]", "[\"/\", \"/f\", \"/f\", \"/f\"]", "[\"\", \"ab\", \"cd\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"ls\", \"ls\"]", "[\"/\", \"/a\", \"/a/f\", \"/a\", \"/a/f\"]", "[\"\", \"\", \"hi\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"readContentFromFile\", \"addContentToFile\", \"readContentFromFile\"]", "[\"/\", \"/d\", \"/d/f\", \"/d/f\", \"/d/f\", \"/d/f\"]", "[\"\", \"\", \"x\", \"\", \"y\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"ls\", \"ls\"]", "[\"/\", \"/a/b/c\", \"/a\", \"/a/b\"]", "[\"\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"addContentToFile\", \"ls\", \"ls\"]", "[\"/\", \"/a\", \"/\", \"/a\"]", "[\"\", \"x\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"addContentToFile\", \"ls\"]", "[\"/\", \"/m\", \"/m/a\", \"/m/b\", \"/m\"]", "[\"\", \"\", \"1\", \"2\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"readContentFromFile\"]", "[\"/\", \"/p/q\", \"/p/q/r\", \"/p/q/r\"]", "[\"\", \"\", \"zzz\", \"\"]"], ["[\"FileSystem\", \"ls\", \"mkdir\", \"ls\"]", "[\"/\", \"/\", \"/z\", \"/\"]", "[\"\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"mkdir\", \"mkdir\", \"ls\"]", "[\"/\", \"/b\", \"/a\", \"/c\", \"/\"]", "[\"\", \"\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"addContentToFile\", \"addContentToFile\", \"ls\", \"readContentFromFile\"]", "[\"/\", \"/d/f1\", \"/d/f2\", \"/d\", \"/d/f1\"]", "[\"\", \"aa\", \"bb\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"ls\", \"addContentToFile\", \"ls\"]", "[\"/\", \"/k\", \"/k\", \"/k/file\", \"/k\"]", "[\"\", \"\", \"\", \"v\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"ls\"]", "[\"/\", \"/a/a/a\", \"/a/a/a/f\", \"/a/a\"]", "[\"\", \"\", \"q\", \"\"]"], ["[\"FileSystem\", \"addContentToFile\", \"readContentFromFile\", \"ls\"]", "[\"/\", \"/x\", \"/x\", \"/\"]", "[\"\", \"hey\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"mkdir\", \"ls\", \"ls\"]", "[\"/\", \"/a/b\", \"/a/b/c\", \"/a/b\", \"/\"]", "[\"\", \"\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"ls\", \"readContentFromFile\"]", "[\"/\", \"/w\", \"/w/f\", \"/\", \"/w/f\"]", "[\"\", \"\", \"abc\", \"\", \"\"]"], ["[\"FileSystem\", \"addContentToFile\", \"ls\", \"readContentFromFile\"]", "[\"/\", \"/m/n/o\", \"/m/n\", \"/m/n/o\"]", "[\"\", \"t\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"mkdir\", \"addContentToFile\", \"ls\", \"ls\"]", "[\"/\", \"/d1\", \"/d2\", \"/d1/f\", \"/\", \"/d1\"]", "[\"\", \"\", \"\", \"c\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"ls\", \"mkdir\", \"ls\"]", "[\"/\", \"/a\", \"/\", \"/a/b\", \"/a\"]", "[\"\", \"\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"addContentToFile\", \"addContentToFile\", \"addContentToFile\", \"readContentFromFile\"]", "[\"/\", \"/f\", \"/f\", \"/f\", \"/f\"]", "[\"\", \"a\", \"b\", \"c\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"ls\", \"ls\", \"readContentFromFile\"]", "[\"/\", \"/s\", \"/s/a\", \"/s\", \"/s/a\", \"/s/a\"]", "[\"\", \"\", \"x\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"ls\", \"ls\", \"mkdir\", \"ls\"]", "[\"/\", \"/\", \"/\", \"/q\", \"/\"]", "[\"\", \"\", \"\", \"\", \"\"]"], ["[\"FileSystem\", \"mkdir\", \"addContentToFile\", \"readContentFromFile\", \"ls\", \"ls\"]", "[\"/\", \"/u/v\", \"/u/v/w\", \"/u/v/w\", \"/u/v\", \"/\"]", "[\"\", \"\", \"k\", \"\", \"\", \"\"]"]], "expected": [[["a"], ["hello"], ["d"]], [["x"], ["f"], ["data"]], [], [["a"]], [["b", "c"]], [["hello"]], [["abcd"]], [["f"], ["f"]], [["x"], ["xy"]], [["b"], ["c"]], [["a"], ["a"]], [["a", "b"]], [["zzz"]], [[], ["z"]], [["a", "b", "c"]], [["f1", "f2"], ["aa"]], [[], ["file"]], [["a"]], [["hey"], ["x"]], [["c"], ["a"]], [["w"], ["abc"]], [["o"], ["t"]], [["d1", "d2"], ["f"]], [["a"], ["b"]], [["abc"]], [["a"], ["a"], ["x"]], [[], [], ["q"]], [["k"], ["w"], ["u"]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "715", "slug": "design-linked-list", "id": 715, "title": "Design Linked List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/design-linked-list/", "examples": [{"input": "operations = [\"MyLinkedList\",\"addAtHead\",\"addAtTail\",\"addAtIndex\",\"get\",\"deleteAtIndex\",\"get\"], args = [[],[1],[3],[1,2],[1],[1],[1]]", "output": "[2,3]", "explanation": "List becomes [1,2,3]; reads give 2 then 3."}, {"input": "operations = [\"MyLinkedList\",\"addAtHead\",\"get\"], args = [[],[5],[0]]", "output": "[5]", "explanation": "Single insert then read."}, {"input": "operations = [\"MyLinkedList\",\"get\",\"addAtIndex\",\"get\"], args = [[],[0],[5,10],[0]]", "output": "[-1,-1]", "explanation": "Empty read and ignored insert."}], "hints": ["Adaptation: implement runLinkedList that replays operations and returns only the get results in order.", "Keep an array-backed list: get checks bounds, addAtIndex handles head/append/ignore cases, delete removes when valid.", "Reset the list whenever MyLinkedList appears."], "statement": "Build a singly linked list that supports indexed access and edits. Instead of submitting a class, you write one runner function `runLinkedList(operations, args)` that replays a script and returns every `get` result in order.\n\nThe script uses parallel arrays: `operations[i]` names the action and `args[i]` holds its numbers.\n- `\"MyLinkedList\"` with `[]` restarts with an empty list.\n- `\"get\"` with `[index]` reads the value at `index`, or `-1` when invalid.\n- `\"addAtHead\"` with `[val]` inserts before the first element.\n- `\"addAtTail\"` with `[val]` appends at the end.\n- `\"addAtIndex\"` with `[index,val]` inserts before position `index`; if `index` equals the length it appends; if `index` is larger than the length nothing happens; a non-positive index inserts at the head.\n- `\"deleteAtIndex\"` with `[index]` removes the element there when valid.\n\nReturn an array containing the `get` answers in the order they were issued.\n\nThis is a portable adaptation: the original class with five methods becomes a single `runXxx` function, mirroring other design adaptations in this judge.\n\n**Constraints:**\n- `1 <= operations.length <= 2000`\n- `0 <= index, val <= 1000`\n- `args[i]` lengths match the operation arities above.\n", "solution": "## Approach\n\nReplay the script with a plain array-backed sequence. A `MyLinkedList` entry clears the sequence. Reads check bounds and emit either the stored value or `-1`. Head and tail inserts map to front and back pushes, indexed inserts respect the append-or-ignore rules (non-positive means front), and deletions remove only valid positions. Collecting read results in order produces the required output.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) worst case due to indexed inserts/deletes shifting elements.\n- **Space Complexity:** O(n) for the stored values.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runLinkedList(self, operations: List[str], args: List[List[int]]) -> List[int]:\n lst = []\n out = []\n for op, a in zip(operations, args):\n if op == \"MyLinkedList\":\n lst = []\n elif op == \"get\":\n idx = a[0] if a else -1\n out.append(lst[idx] if 0 <= idx < len(lst) else -1)\n elif op == \"addAtHead\":\n lst.insert(0, a[0])\n elif op == \"addAtTail\":\n lst.append(a[0])\n elif op == \"addAtIndex\":\n idx, val = a[0], a[1]\n if idx <= 0:\n lst.insert(0, val)\n elif idx == len(lst):\n lst.append(val)\n elif idx < len(lst):\n lst.insert(idx, val)\n elif op == \"deleteAtIndex\":\n idx = a[0] if a else -1\n if 0 <= idx < len(lst):\n lst.pop(idx)\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunLinkedList(operations []string, args [][]int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runLinkedList(self, operations: List[str], args: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runLinkedList(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runLinkedList", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"MyLinkedList\",\"addAtHead\",\"addAtTail\",\"addAtIndex\",\"get\",\"deleteAtIndex\",\"get\"]", "[[],[1],[3],[1,2],[1],[1],[1]]"], ["[\"MyLinkedList\",\"addAtHead\",\"get\"]", "[[],[5],[0]]"], ["[\"MyLinkedList\",\"get\",\"addAtIndex\",\"get\"]", "[[],[0],[5,10],[0]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtHead\",\"get\",\"get\"]", "[[],[2],[1],[0],[1]]"], ["[\"MyLinkedList\",\"addAtTail\",\"addAtTail\",\"get\"]", "[[],[1],[2],[1]]"], ["[\"MyLinkedList\",\"addAtHead\",\"deleteAtIndex\",\"get\"]", "[[],[1],[0],[0]]"], ["[\"MyLinkedList\",\"addAtIndex\",\"addAtIndex\",\"get\",\"get\"]", "[[],[0,10],[1,20],[0],[1]]"], ["[\"MyLinkedList\",\"addAtTail\",\"addAtIndex\",\"get\"]", "[[],[1],[5,2],[2]]"], ["[\"MyLinkedList\",\"get\"]", "[[],[0]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtHead\",\"addAtHead\",\"get\",\"get\",\"get\"]", "[[],[3],[2],[1],[0],[1],[2]]"], ["[\"MyLinkedList\",\"addAtTail\",\"deleteAtIndex\",\"deleteAtIndex\",\"get\"]", "[[],[1],[0],[0],[0]]"], ["[\"MyLinkedList\",\"addAtIndex\",\"get\"]", "[[],[-1,5],[0]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtTail\",\"deleteAtIndex\",\"get\",\"get\"]", "[[],[1],[2],[5],[0],[1]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtIndex\",\"get\"]", "[[],[10],[0,20],[0]]"], ["[\"MyLinkedList\",\"addAtTail\",\"addAtTail\",\"addAtTail\",\"deleteAtIndex\",\"get\"]", "[[],[1],[2],[3],[1],[1]]"], ["[\"MyLinkedList\",\"addAtHead\",\"get\",\"get\"]", "[[],[7],[0],[1]]"], ["[\"MyLinkedList\",\"addAtIndex\",\"addAtIndex\",\"addAtIndex\",\"get\"]", "[[],[0,1],[1,2],[2,3],[2]]"], ["[\"MyLinkedList\",\"addAtTail\",\"get\",\"deleteAtIndex\",\"get\",\"addAtHead\",\"get\"]", "[[],[5],[0],[0],[0],[9],[0]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtHead\",\"deleteAtIndex\",\"get\"]", "[[],[1],[2],[1],[0]]"], ["[\"MyLinkedList\",\"addAtTail\",\"addAtTail\",\"addAtIndex\",\"get\",\"get\",\"get\"]", "[[],[10],[20],[1,15],[0],[1],[2]]"], ["[\"MyLinkedList\",\"addAtHead\",\"deleteAtIndex\",\"deleteAtIndex\",\"get\"]", "[[],[1],[0],[0],[0]]"], ["[\"MyLinkedList\",\"addAtIndex\",\"get\",\"addAtTail\",\"get\"]", "[[],[2,100],[0],[50],[1]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtTail\",\"addAtTail\",\"get\",\"deleteAtIndex\",\"get\",\"get\"]", "[[],[1],[2],[3],[2],[0],[0],[1]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtHead\",\"addAtHead\",\"addAtHead\",\"get\"]", "[[],[4],[3],[2],[1],[3]]"], ["[\"MyLinkedList\",\"deleteAtIndex\",\"get\"]", "[[],[0],[0]]"], ["[\"MyLinkedList\",\"addAtTail\",\"addAtIndex\",\"deleteAtIndex\",\"get\",\"get\"]", "[[],[0],[0,1],[1],[0],[1]]"], ["[\"MyLinkedList\",\"addAtHead\",\"addAtTail\",\"get\",\"get\",\"deleteAtIndex\",\"get\"]", "[[],[100],[200],[0],[1],[1],[1]]"], ["[\"MyLinkedList\",\"addAtIndex\",\"addAtIndex\",\"get\",\"deleteAtIndex\",\"get\"]", "[[],[0,5],[0,6],[0],[0],[0]]"]], "expected": [[2, 3], [5], [-1, -1], [1, 2], [2], [-1], [10, 20], [-1], [-1], [1, 2, 3], [-1], [5], [1, 2], [20], [3], [7, -1], [3], [5, -1, 9], [2], [10, 15, 20], [-1], [-1, -1], [3, 2, 3], [4], [-1], [1, -1], [100, 200, -1], [6, 5]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "657", "slug": "design-log-storage-system", "id": 657, "title": "Design Log Storage System", "difficulty": "Medium", "category": "design", "link": "https://leetcode.com/problems/design-log-storage-system/", "examples": [{"input": "operations = [\"LogSystem\",\"put\",\"put\",\"put\",\"retrieve\"], values = [\"\",\"1|2017:01:01:23:59:59\",\"2|2017:01:01:22:59:59\",\"3|2016:01:01:00:00:00\",\"2016:01:01:01:01:01|2017:01:01:23:00:00|Year\"]", "output": "[[1,2,3]]", "explanation": "At year precision all three records sit in 2016..2017."}, {"input": "operations = [\"LogSystem\",\"put\",\"put\",\"put\",\"retrieve\"], values = [\"\",\"1|2017:01:01:23:59:59\",\"2|2017:01:01:22:59:59\",\"3|2016:01:01:00:00:00\",\"2016:01:01:01:01:01|2017:01:01:23:00:00|Hour\"]", "output": "[[1,2]]", "explanation": "At hour precision only the two 2017 records land inside the window."}], "hints": ["Split every timestamp on ':' and keep only the leading parts dictated by the granularity (Year=1 ... Second=6).", "A record matches when its truncated stamp sorts no earlier than the truncated start and no later than the truncated end.", "Collect one output row per retrieve call in call order; put and constructor calls add no rows."], "statement": "You maintain an append-only log store. Each record has an integer `id` and a timestamp string shaped `Year:Month:Day:Hour:Minute:Second` (for example `\"2017:01:01:23:59:59\"`). Every component is zero-padded, so plain string order matches chronological order.\n\nTwo behaviors are needed:\n\n- `put(id, timestamp)` stores one record.\n- `retrieve(start, end, granularity)` lists the `id` values whose timestamps fall inside `[start, end]` once both bounds and the record are cut down to the requested `granularity`. The granularity is one of `Year`, `Month`, `Day`, `Hour`, `Minute`, or `Second`. Cutting down means keeping only the leading components: `Year` keeps 1 part, `Month` keeps 2, and so on up to `Second` which keeps all 6.\n\nThis task uses a portable function adaptation instead of a class. Implement:\n\n```\nrunLogStorage(operations, values)\n```\n\nThe two arrays are parallel. `operations[i]` is one of `\"LogSystem\"`, `\"put\"`, or `\"retrieve\"`, and `values[i]` packs that call's arguments with `|` separators:\n\n- `\"LogSystem\"` with `\"\"` resets the store and is always first.\n- `\"put\"` with `\"id|timestamp\"`, e.g. `\"1|2017:01:01:23:59:59\"`.\n- `\"retrieve\"` with `\"start|end|granularity\"`, e.g. `\"2016:01:01:01:01:01|2017:01:01:23:00:00|Year\"`.\n\nReturn one integer row per `retrieve` call (in call order), each row listing matching `id` values in insertion order. Constructor and `put` calls produce no rows. There is intentionally no class wrapper.\n\n**Constraints:**\n- `1 <= operations.length == values.length <= 500`\n- The first operation is `\"LogSystem\"` with `\"\"`.\n- Each `id` is in `1..10^9`; timestamps match the fixed 6-part shape with valid calendar ranges.\n- Granularity is exactly one of `Year`, `Month`, `Day`, `Hour`, `Minute`, `Second`.\n- `start` is never later than `end` at the requested granularity.\n", "solution": "## Approach\n\nKeep every stored record as an id plus its six timestamp parts. For a retrieve call, cut the stored stamp and both bounds down to the leading components chosen by the granularity, then keep records whose truncated stamp lies between the truncated bounds. Rows are emitted in call order and preserve insertion order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(P * R) where P is the number of stored records and R the number of retrieve calls.\n- **Space Complexity:** O(P + output) for the stored records and answer rows.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def runLogStorage(self, operations: List[str], values: List[str]) -> List[List[int]]:\n gra = {\"Year\": 1, \"Month\": 2, \"Day\": 3, \"Hour\": 4, \"Minute\": 5, \"Second\": 6}\n logs = []\n out = []\n for op, v in zip(operations, values):\n if op == \"LogSystem\":\n logs = []\n elif op == \"put\":\n mid = v.index(\"|\")\n logs.append((int(v[:mid]), [int(x) for x in v[mid+1:].split(\":\")]))\n elif op == \"retrieve\":\n s, e, g = v.split(\"|\")\n k = gra[g]\n sp = [int(x) for x in s.split(\":\")][:k]\n ep = [int(x) for x in e.split(\":\")][:k]\n row = [i for i, t in logs if sp <= t[:k] <= ep]\n out.append(row)\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunLogStorage(operations []string, values []string) [][]int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def runLogStorage(self, operations: List[str], values: List[str]) -> List[List[int]]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> runLogStorage(vector<string>& operations, vector<string>& values) {\n return {};\n }\n};"}, "fn": "runLogStorage", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "string_array"}], "outputType": "int_array_2d", "tests": [["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2017:01:01:23:59:59\", \"2|2017:01:01:22:59:59\", \"3|2016:01:01:00:00:00\", \"2016:01:01:01:01:01|2017:01:01:23:00:00|Year\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2017:01:01:23:59:59\", \"2|2017:01:01:22:59:59\", \"3|2016:01:01:00:00:00\", \"2016:01:01:01:01:01|2017:01:01:23:00:00|Hour\"]"], ["[\"LogSystem\", \"put\", \"retrieve\"]", "[\"\", \"7|2020:05:05:05:05:05\", \"2020:05:05:05:05:05|2020:05:05:05:05:05|Second\"]"], ["[\"LogSystem\", \"retrieve\"]", "[\"\", \"2017:01:01:00:00:00|2017:12:31:23:59:59|Year\"]"], ["[\"LogSystem\", \"put\", \"retrieve\", \"retrieve\"]", "[\"\", \"5|2017:06:15:12:30:00\", \"2017:01:01:00:00:00|2017:12:31:23:59:59|Month\", \"2017:06:15:12:30:00|2017:06:15:12:30:00|Minute\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2017:01:01:00:00:00\", \"2|2017:01:02:00:00:00\", \"2017:01:01:00:00:00|2017:01:01:23:59:59|Day\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2017:01:01:10:00:00\", \"2|2017:01:01:11:00:00\", \"2017:01:01:10:30:00|2017:01:01:11:30:00|Hour\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2016:12:31:23:59:59\", \"2|2017:01:01:00:00:00\", \"3|2018:01:01:00:00:00\", \"2017:01:01:00:00:00|2017:12:31:23:59:59|Year\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"9|2000:01:01:00:00:00\", \"9|2000:01:01:00:00:01\", \"2000:01:01:00:00:00|2000:01:01:00:00:00|Second\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"4|2019:03:03:03:03:03\", \"5|2019:03:03:03:04:00\", \"2019:03:03:03:03:00|2019:03:03:03:04:00|Minute\"]"], ["[\"LogSystem\", \"put\", \"retrieve\", \"put\", \"retrieve\"]", "[\"\", \"1|2015:05:05:05:05:05\", \"2015:01:01:00:00:00|2015:12:31:23:59:59|Month\", \"2|2015:06:06:06:06:06\", \"2015:06:01:00:00:00|2015:06:30:23:59:59|Day\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\", \"retrieve\"]", "[\"\", \"1|2017:01:01:01:01:01\", \"2|2017:01:01:01:01:02\", \"3|2017:01:01:01:02:00\", \"2017:01:01:01:01:01|2017:01:01:01:01:02|Second\", \"2017:01:01:01:01:00|2017:01:01:01:02:00|Minute\"]"], ["[\"LogSystem\", \"put\", \"retrieve\"]", "[\"\", \"100|1999:12:31:23:59:59\", \"1999:01:01:00:00:00|1999:12:31:23:59:59|Day\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2021:02:28:00:00:00\", \"2|2021:03:01:00:00:00\", \"2021:02:01:00:00:00|2021:02:28:23:59:59|Month\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"10|2010:10:10:10:10:10\", \"20|2010:10:10:10:10:11\", \"30|2010:10:11:10:10:10\", \"2010:10:10:10:10:10|2010:10:10:10:10:11|Second\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2017:01:01:23:59:58\", \"2|2017:01:01:23:59:59\", \"2017:01:01:23:00:00|2017:01:01:23:59:00|Minute\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2018:06:01:08:00:00\", \"2|2018:06:01:09:00:00\", \"3|2018:06:02:08:00:00\", \"2018:06:01:00:00:00|2018:06:01:23:59:59|Day\"]"], ["[\"LogSystem\", \"put\", \"retrieve\"]", "[\"\", \"42|2017:07:07:07:07:07\", \"2018:01:01:00:00:00|2019:01:01:00:00:00|Year\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\", \"retrieve\"]", "[\"\", \"1|2016:01:01:00:00:00\", \"2|2016:01:01:00:00:00\", \"2016:01:01:00:00:00|2016:01:01:00:00:00|Second\", \"2015:01:01:00:00:00|2017:01:01:00:00:00|Year\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"3|2022:11:11:11:11:11\", \"1|2022:11:11:11:11:12\", \"2|2022:11:11:11:11:13\", \"2022:11:11:11:11:11|2022:11:11:11:11:13|Second\"]"], ["[\"LogSystem\", \"put\", \"retrieve\"]", "[\"\", \"8|2001:09:09:09:09:09\", \"2001:09:09:09:09:08|2001:09:09:09:09:09|Second\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"6|2012:02:29:12:00:00\", \"7|2012:03:01:12:00:00\", \"2012:02:01:00:00:00|2012:02:29:23:59:59|Day\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2017:12:31:23:00:00\", \"2|2018:01:01:00:00:00\", \"2017:01:01:00:00:00|2018:12:31:23:59:59|Month\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2019:01:01:00:00:10\", \"2|2019:01:01:00:01:00\", \"3|2019:01:01:00:01:30\", \"4|2019:01:01:01:00:00\", \"2019:01:01:00:01:00|2019:01:01:00:01:59|Minute\"]"], ["[\"LogSystem\", \"put\", \"retrieve\"]", "[\"\", \"999|2030:12:31:23:59:59\", \"2000:01:01:00:00:00|2030:12:31:23:59:59|Year\"]"], ["[\"LogSystem\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"11|2014:04:04:04:04:04\", \"22|2014:04:04:05:04:04\", \"2014:04:04:04:00:00|2014:04:04:05:00:00|Hour\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"retrieve\", \"retrieve\"]", "[\"\", \"1|2023:01:15:10:20:30\", \"2|2023:01:15:10:20:31\", \"3|2023:02:15:10:20:30\", \"2023:01:01:00:00:00|2023:01:31:23:59:59|Month\", \"2023:01:15:10:20:30|2023:01:15:10:20:31|Second\"]"], ["[\"LogSystem\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"put\", \"retrieve\"]", "[\"\", \"1|2017:01:02:10:00:00\", \"2|2017:01:03:10:00:00\", \"3|2017:01:04:10:00:00\", \"4|2017:01:05:10:00:00\", \"5|2017:01:06:10:00:00\", \"6|2017:01:07:10:00:00\", \"7|2017:01:08:10:00:00\", \"8|2017:01:09:10:00:00\", \"9|2017:01:10:10:00:00\", \"10|2017:01:11:10:00:00\", \"11|2017:01:12:10:00:00\", \"12|2017:01:13:10:00:00\", \"13|2017:01:14:10:00:00\", \"14|2017:01:15:10:00:00\", \"15|2017:01:16:10:00:00\", \"16|2017:01:17:10:00:00\", \"17|2017:01:18:10:00:00\", \"18|2017:01:19:10:00:00\", \"19|2017:01:20:10:00:00\", \"20|2017:01:21:10:00:00\", \"2017:01:01:00:00:00|2017:01:31:23:59:59|Day\"]"]], "expected": [[[1, 2, 3]], [[1, 2]], [[7]], [[]], [[5], [5]], [[1]], [[1, 2]], [[2]], [[9]], [[4, 5]], [[1], [2]], [[1, 2], [1, 2, 3]], [[100]], [[1]], [[10, 20]], [[1, 2]], [[1, 2]], [[]], [[1, 2], [1, 2]], [[3, 1, 2]], [[8]], [[6]], [[1, 2]], [[2, 3]], [[999]], [[11, 22]], [[1, 2], [1, 2]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "455", "slug": "design-phone-directory", "id": 455, "title": "Design Phone Directory", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/design-phone-directory/", "examples": [{"input": "operations = [\"PhoneDirectory\",\"get\",\"get\",\"check\",\"get\",\"check\",\"release\",\"check\"], args = [[3],[],[],[2],[],[2],[2],[2]]", "output": "[0,1,1,2,0,1]", "explanation": "Smallest-free gets with check/release interleaved."}, {"input": "operations = [\"PhoneDirectory\",\"get\",\"check\",\"release\",\"get\"], args = [[1],[],[0],[0],[]]", "output": "[0,0,0]", "explanation": "Single number handed out, checked, released, handed out again."}, {"input": "operations = [\"PhoneDirectory\",\"get\",\"get\",\"get\"], args = [[2],[],[],[]]", "output": "[0,1,-1]", "explanation": "Third get finds the pool empty."}], "hints": ["Keep a boolean taken/free array plus the count of free numbers.", "get scans from 0 upward for the first free entry; record -1 when the scan fails.", "check maps free to 1 and taken to 0; release only clears a taken entry."], "statement": "Replay a phone-number pool through one portable batch function.\n\nThis is a function adaptation of the classic directory-design task: instead of writing a class, implement `runPhoneDirectory(operations, args)`. The two arrays are parallel. The first operation is always `\"PhoneDirectory\"` with a single argument `[maxNumbers]`, creating pool numbers `0` through `maxNumbers - 1`, all free at first. Each later operation is one of:\n\n- `\"get\"` with `[]`: hand out the smallest free number, or `-1` when none is free. Its result is recorded.\n- `\"check\"` with `[number]`: record `1` when that number is currently free, else `0`.\n- `\"release\"` with `[number]`: return the number to the pool when it is currently taken; otherwise do nothing. It records nothing.\n\nReturn the recorded results from `get` and `check` calls only, in order. Fixing `get` to the smallest free number keeps every test deterministic.\n\n**Constraints:**\n- `1 <= operations.length == args.length <= 10^4`\n- `operations[0] == \"PhoneDirectory\"` and `args[0] == [maxNumbers]` with `1 <= maxNumbers <= 10^4`.\n- Later operations are `get` with `[]`, `check` with `[number]`, or `release` with `[number]`.\n- `0 <= number < maxNumbers`\n", "solution": "## Approach\n\nModel the pool with a taken/free flag per number. The constructor marks everything free. `get` linearly scans for the first free slot (recording `-1` when full), `check` reads one flag as `1`/`0`, and `release` clears a taken flag. Only `get` and `check` append to the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * maxNumbers) worst case for m operations due to the linear `get` scan.\n- **Space Complexity:** O(maxNumbers) for the flags plus O(m) for the collected answers.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runPhoneDirectory(self, operations: List[str], args: List[List[int]]) -> List[int]:\n max_n = args[0][0]\n taken = [False] * max_n\n out = []\n for i in range(1, len(operations)):\n op = operations[i]\n if op == \"get\":\n idx = -1\n for j in range(max_n):\n if not taken[j]:\n idx = j\n break\n if idx != -1:\n taken[idx] = True\n out.append(idx)\n elif op == \"check\":\n out.append(0 if taken[args[i][0]] else 1)\n elif op == \"release\":\n if taken[args[i][0]]:\n taken[args[i][0]] = False\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunPhoneDirectory(operations []string, args [][]int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runPhoneDirectory(self, operations: List[str], args: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runPhoneDirectory(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runPhoneDirectory", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"PhoneDirectory\",\"get\",\"get\",\"check\",\"get\",\"check\",\"release\",\"check\"]", "[[3],[],[],[2],[],[2],[2],[2]]"], ["[\"PhoneDirectory\",\"get\",\"check\",\"release\",\"get\"]", "[[1],[],[0],[0],[]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"get\"]", "[[2],[],[],[]]"], ["[\"PhoneDirectory\",\"check\",\"release\"]", "[[2],[1],[1]]"], ["[\"PhoneDirectory\"]", "[[5]]"], ["[\"PhoneDirectory\",\"get\"]", "[[1],[]]"], ["[\"PhoneDirectory\",\"check\"]", "[[3],[0]]"], ["[\"PhoneDirectory\",\"release\",\"check\"]", "[[2],[0],[0]]"], ["[\"PhoneDirectory\",\"get\",\"release\",\"get\",\"get\"]", "[[2],[],[0],[],[]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"release\",\"get\"]", "[[3],[],[],[0],[]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"get\",\"get\"]", "[[3],[],[],[],[]]"], ["[\"PhoneDirectory\",\"check\",\"check\",\"check\"]", "[[3],[0],[1],[2]]"], ["[\"PhoneDirectory\",\"release\",\"release\",\"get\"]", "[[2],[0],[1],[]]"], ["[\"PhoneDirectory\",\"get\",\"release\",\"check\",\"get\"]", "[[4],[],[1],[1],[]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"release\",\"release\",\"get\",\"get\"]", "[[4],[],[],[0],[1],[],[]]"], ["[\"PhoneDirectory\",\"get\",\"check\",\"check\",\"release\",\"check\"]", "[[5],[],[4],[4],[4],[4]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"get\",\"release\",\"check\",\"get\"]", "[[2],[],[],[],[1],[1],[]]"], ["[\"PhoneDirectory\",\"check\",\"get\",\"release\",\"check\",\"get\"]", "[[1],[0],[],[0],[0],[]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"get\",\"get\",\"get\"]", "[[5],[],[],[],[],[]]"], ["[\"PhoneDirectory\",\"get\",\"release\",\"get\",\"release\",\"get\"]", "[[1],[],[0],[],[0],[]]"], ["[\"PhoneDirectory\",\"check\",\"check\",\"get\",\"get\",\"release\",\"check\"]", "[[4],[3],[3],[],[],[0],[0]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"check\",\"release\",\"check\",\"get\"]", "[[10],[],[],[5],[5],[5],[]]"], ["[\"PhoneDirectory\",\"release\",\"get\",\"get\",\"check\"]", "[[3],[2],[],[],[2]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"get\",\"release\",\"release\",\"release\",\"get\",\"get\",\"get\"]", "[[3],[],[],[],[0],[1],[2],[],[],[]]"], ["[\"PhoneDirectory\",\"check\",\"release\",\"get\",\"check\",\"release\",\"get\"]", "[[2],[0],[0],[],[0],[0],[]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"release\",\"check\",\"check\",\"get\"]", "[[6],[],[],[3],[3],[4],[]]"], ["[\"PhoneDirectory\",\"get\",\"check\",\"get\",\"check\",\"release\",\"release\",\"check\"]", "[[4],[],[2],[],[2],[0],[1],[1]]"], ["[\"PhoneDirectory\",\"get\",\"get\",\"get\",\"get\",\"release\",\"get\"]", "[[4],[],[],[],[],[2],[]]"], ["[\"PhoneDirectory\",\"check\",\"get\",\"get\",\"release\",\"get\",\"check\"]", "[[5],[4],[],[],[0],[],[0]]"], ["[\"PhoneDirectory\",\"get\",\"release\",\"release\",\"check\",\"get\"]", "[[3],[],[1],[1],[1],[]]"]], "expected": [[0, 1, 1, 2, 0, 1], [0, 0, 0], [0, 1, -1], [1], [], [0], [1], [1], [0, 0, 1], [0, 1, 0], [0, 1, 2, -1], [1, 1, 1], [0], [0, 1, 1], [0, 1, 0, 1], [0, 1, 1, 1], [0, 1, -1, 1, 1], [1, 0, 1, 0], [0, 1, 2, 3, 4], [0, 0, 0], [1, 1, 0, 1, 1], [0, 1, 1, 1, 2], [0, 1, 1], [0, 1, 2, 0, 1, 2], [1, 0, 0, 0], [0, 1, 1, 1, 2], [0, 1, 1, 1, 1], [0, 1, 2, 3, 2], [1, 0, 1, 0, 0], [0, 1, 1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "664", "slug": "design-search-autocomplete-system", "id": 664, "title": "Design Search Autocomplete System", "difficulty": "Hard", "category": "trie", "link": "https://leetcode.com/problems/design-search-autocomplete-system/", "examples": [{"input": "operations = [\"AutocompleteSystem\",\"input\",\"input\",\"input\",\"input\"], values = [\"i love you:5;island:3;ironman:2;i love leetcode:2\", \"i\", \" \", \"a\", \"#\"]", "output": "[[\"i love you\",\"island\",\"i love leetcode\"],[\"i love you\",\"i love leetcode\"],[],[]]", "explanation": "Prefix \"i\" matches three sentences by heat; \"i \" narrows to two; \"i a\" matches nothing; \"#\" stores \"i a\"."}, {"input": "operations = [\"AutocompleteSystem\",\"input\",\"input\"], values = [\"abc:2;abd:2;abe:2\", \"a\", \"b\"]", "output": "[[\"abc\",\"abd\",\"abe\"],[\"abc\",\"abd\",\"abe\"]]", "explanation": "Tied heats fall back to ASCII order."}], "hints": ["Keep a map from sentence to heat plus a live prefix buffer; preload parses on ':' and ';'.", "For a normal character, extend the prefix and collect every stored sentence starting with it.", "Sort candidates by heat descending then ASCII ascending, keep three; '#' commits the prefix and resets it."], "statement": "Maintain a sentence store where each sentence has a heat (usage count). Typing builds a prefix character by character; after every keystroke the system proposes up to three stored sentences starting with the current prefix, ordered by higher heat first and ASCII order for ties. Typing `#` ends the current query: the finished prefix is stored (heat 1) or bumped by 1, and the prefix resets.\n\nThis task uses a portable function adaptation instead of a class. Implement:\n\n```\nrunAutocomplete(operations, values)\n```\n\nThe two arrays are parallel. `operations[i]` is `\"AutocompleteSystem\"` or `\"input\"`, and `values[i]` packs arguments as plain strings:\n\n- `\"AutocompleteSystem\"` with `\"s1:t1;s2:t2;...\"` preloads sentences and heats (`:` splits sentence from heat, `;` splits entries), e.g. `\"i love you:5;island:3\"`. An empty string preloads nothing.\n- `\"input\"` with a single character `c` (a lowercase letter, a space, or `\"#\"`).\n\nReturn one string row per `input` call: the suggested sentences in order (possibly empty). Ending with `#` contributes an empty row. There is intentionally no class wrapper.\n\n**Constraints:**\n- `1 <= operations.length == values.length <= 500`\n- The first operation is `\"AutocompleteSystem\"`.\n- Preloaded sentences hold lowercase letters and spaces, length `1..100`; heats are `1..1000`.\n- `input` values are single characters: `a-z`, `' '`, or `'#'`.\n- At most 100 distinct sentences are stored per test.\n", "solution": "## Approach\n\nStore sentence heats in a hash map and accumulate the live prefix in a buffer. Preloading splits the init string on `;` and each entry on the last `:` to recover sentences that may hold spaces. Each keystroke either commits the buffer on `#` (bumping its heat and clearing) or extends the prefix, gathers all stored sentences with that prefix, and orders them by heat descending with ASCII tie-breaks, keeping the first three.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(K * S log S) over K keystrokes and S stored sentences for the per-keystroke gather and sort.\n- **Space Complexity:** O(S * L) for the stored sentences of length up to L.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def runAutocomplete(self, operations: List[str], values: List[str]) -> List[List[str]]:\n hot = {}\n init = values[0]\n if init:\n for entry in init.split(\";\"):\n if not entry:\n continue\n p = entry.rfind(\":\")\n hot[entry[:p]] = int(entry[p+1:])\n cur = \"\"\n out = []\n for c in values[1:]:\n if c == \"#\":\n hot[cur] = hot.get(cur, 0) + 1\n cur = \"\"\n out.append([])\n else:\n cur += c\n cand = [s for s in hot if s.startswith(cur)]\n cand.sort(key=lambda s: (-hot[s], s))\n out.append(cand[:3])\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunAutocomplete(operations []string, values []string) [][]string {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def runAutocomplete(self, operations: List[str], values: List[str]) -> List[List[str]]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<string>> runAutocomplete(vector<string>& operations, vector<string>& values) {\n return {};\n }\n};"}, "fn": "runAutocomplete", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "string_array"}], "outputType": "string_list_2d", "tests": [["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\"]", "[\"i love you:5;island:3;ironman:2;i love leetcode:2\", \"i\", \" \", \"a\", \"#\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\"]", "[\"abc:2;abd:2;abe:2\", \"a\", \"b\"]"], ["[\"AutocompleteSystem\", \"input\"]", "[\"\", \"z\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"i love you:5\", \"i\", \" \", \"#\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\", \"input\"]", "[\"a:1;b:1\", \"a\", \"#\", \"b\", \"#\", \"a\"]"], ["[\"AutocompleteSystem\", \"input\"]", "[\"hello:3;hell:2;heaven:2\", \"h\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\"]", "[\"hello:3;hell:2;heaven:2\", \"h\", \"e\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"ab:1;ac:1;ad:1;ae:1\", \"a\", \"b\", \"#\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\"]", "[\"x:5;xy:4;xyz:3\", \"x\", \"y\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\"]", "[\"code:2\", \"c\", \"o\", \"d\", \"e\"]"], ["[\"AutocompleteSystem\", \"input\"]", "[\"b:2;a:2;c:2\", \"a\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"aa:1\", \"a\", \"a\", \"#\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\"]", "[\"i love coding:3;i love coffee:3\", \"i\", \" \"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\", \"input\", \"input\"]", "[\"t:1\", \"t\", \"e\", \"s\", \"t\", \"#\", \"t\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\"]", "[\"ab c:2;ab d:2\", \"a\", \"b\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"ab c:2;ab d:2\", \"a\", \"b\", \" \"]"], ["[\"AutocompleteSystem\", \"input\"]", "[\"z:1;za:1;zz:1;zb:1\", \"z\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"p:3;q:2\", \"p\", \"#\", \"p\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\"]", "[\"one:1;two:1\", \"o\", \"n\", \"e\", \"#\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\"]", "[\"apple:5;app:3;application:2\", \"a\", \"p\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"apple:5;app:3;application:2\", \"a\", \"p\", \"p\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\", \"input\"]", "[\"hi:1\", \"h\", \"i\", \"#\", \"h\", \"i\"]"], ["[\"AutocompleteSystem\", \"input\"]", "[\"m:2;n:2;o:2;p:2\", \"m\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"ab:3;abc:2;abcd:1\", \"a\", \"b\", \"c\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\"]", "[\"same:1;same hot:1\", \"s\", \"a\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\"]", "[\"k:1\", \"k\", \"#\", \"k\", \" \"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\"]", "[\"dog:4;deer:2;deal:2\", \"d\", \"e\", \"a\"]"], ["[\"AutocompleteSystem\", \"input\", \"input\", \"input\", \"input\", \"input\", \"input\", \"input\"]", "[\"a:2;ab:1\", \"a\", \"b\", \"#\", \"a\", \"b\", \"#\", \"a\"]"]], "expected": [[["i love you", "island", "i love leetcode"], ["i love you", "i love leetcode"], [], []], [["abc", "abd", "abe"], ["abc", "abd", "abe"]], [[]], [["i love you"], ["i love you"], []], [["a"], [], ["b"], [], ["a"]], [["hello", "heaven", "hell"]], [["hello", "heaven", "hell"], ["hello", "heaven", "hell"]], [["ab", "ac", "ad"], ["ab"], []], [["x", "xy", "xyz"], ["xy", "xyz"]], [["code"], ["code"], ["code"], ["code"]], [["a"]], [["aa"], ["aa"], []], [["i love coding", "i love coffee"], ["i love coding", "i love coffee"]], [["t"], [], [], [], [], ["t", "test"]], [["ab c", "ab d"], ["ab c", "ab d"]], [["ab c", "ab d"], ["ab c", "ab d"], ["ab c", "ab d"]], [["z", "za", "zb"]], [["p"], [], ["p"]], [["one"], ["one"], ["one"], []], [["apple", "app", "application"], ["apple", "app", "application"]], [["apple", "app", "application"], ["apple", "app", "application"], ["apple", "app", "application"]], [["hi"], ["hi"], [], ["hi"], ["hi"]], [["m"]], [["ab", "abc", "abcd"], ["ab", "abc", "abcd"], ["abc", "abcd"]], [["same", "same hot"], ["same", "same hot"]], [["k"], [], ["k"], []], [["dog", "deal", "deer"], ["deal", "deer"], ["deal"]], [["a", "ab"], ["ab"], [], ["a", "ab"], ["ab"], [], ["ab", "a"]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "433", "slug": "design-snake-game", "id": 433, "title": "Design Snake Game", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/design-snake-game/", "examples": [{"input": "width = 3, height = 2, food = [[1,2],[0,1]], moves = [\"R\",\"D\",\"R\",\"U\",\"L\",\"U\"]", "output": "[0,0,1,1,2,-1]", "explanation": "The snake eats at (1,2) on the third move and at (0,1) on the fifth move, then crashes into itself on the last move."}, {"input": "width = 2, height = 2, food = [], moves = [\"R\",\"D\",\"L\"]", "output": "[0,0,0]", "explanation": "With no food the score stays zero while the snake loops safely."}], "hints": ["Store the body in a queue (head at front) plus a hash set of occupied cells for O(1) collision checks.", "When the step does not eat, remove the tail before testing self-collision so moving into the vacated cell is legal.", "Once the game ends, every remaining move reports -1."], "statement": "A snake moves on a `height x width` board, starting as a single cell at the\ntop-left corner `(0, 0)`. A list of food cells is given in the order they\nappear: there is always at most one food cell on the board, and the next one\nshows up only after the current one is eaten.\n\nFor each step you receive one direction: `U` (up), `D` (down), `L` (left) or\n`R` (right). The snake advances its head one cell that way:\n\n- When the new head leaves the board, the game ends.\n- When the new head hits the snake's own body (excluding the tail cell that is\n vacated in the same step, unless the step eats food and the tail stays), the\n game ends.\n- When the new head reaches the current food cell, the snake grows by one (the\n tail does not move) and the score increases by one.\n- Otherwise the head advances and the tail vacates its cell; the score is\n unchanged.\n\nEach move reports the current score, or `-1` once the game is over (every later\nmove also reports `-1`).\n\n**Adaptation note:** instead of a stateful class, implement\n`runSnakeGame(width, height, food, moves)`, which replays the move list and\nreturns one score per move.\n\n**Constraints:**\n- `1 <= width, height <= 20`\n- `0 <= food.length <= 50`, each `food[i] = [r, c]` with `0 <= r < height`, `0 <= c < width`\n- `0 <= moves.length <= 200`, each move is one of `\"U\"`, `\"D\"`, `\"L\"`, `\"R\"`\n", "solution": "## Approach\n\nReplay the game with a queue holding the body from head to tail and a hash set\nof occupied cells. For each move, compute the new head, drop the tail unless\nfood is eaten there, then test walls and self-collision. Eating advances the\nfood pointer and raises the score; after a crash every later answer is -1.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the number of moves.\n- **Space Complexity:** O(f + m) for the body and the food list, with f eaten cells.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\n\nclass Solution:\n def runSnakeGame(self, width: int, height: int, food: List[List[int]], moves: List[str]) -> List[int]:\n body = deque([(0, 0)])\n occ = {(0, 0)}\n fi = 0\n score = 0\n ans = []\n over = False\n for mv in moves:\n if over:\n ans.append(-1)\n continue\n r, c = body[0]\n if mv == \"U\":\n r -= 1\n elif mv == \"D\":\n r += 1\n elif mv == \"L\":\n c -= 1\n elif mv == \"R\":\n c += 1\n else:\n ans.append(-1)\n over = True\n continue\n if r < 0 or r >= height or c < 0 or c >= width:\n ans.append(-1)\n over = True\n continue\n eat = fi < len(food) and food[fi][0] == r and food[fi][1] == c\n if not eat:\n occ.remove(body.pop())\n if (r, c) in occ:\n ans.append(-1)\n over = True\n continue\n body.appendleft((r, c))\n occ.add((r, c))\n if eat:\n fi += 1\n score += 1\n ans.append(score)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunSnakeGame(width int, height int, food [][]int, moves []string) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def runSnakeGame(self, width: int, height: int, food: List[List[int]], moves: List[str]) -> List[int]:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> runSnakeGame(int width, int height, vector<vector<int>>& food, vector<string>& moves) {\n return {};\n }\n};"}, "fn": "runSnakeGame", "params": [{"name": "width", "type": "int"}, {"name": "height", "type": "int"}, {"name": "food", "type": "int_array_2d"}, {"name": "moves", "type": "string_array"}], "outputType": "int_array", "tests": [["3", "2", "[[1,2],[0,1]]", "[\"R\",\"D\",\"R\",\"U\",\"L\",\"U\"]"], ["2", "2", "[]", "[\"R\",\"D\",\"L\"]"], ["1", "1", "[]", "[\"R\"]"], ["3", "3", "[[0,1],[0,2],[1,2]]", "[\"R\",\"R\",\"D\"]"], ["3", "3", "[[2,0],[0,0],[0,2],[2,2]]", "[\"D\",\"D\",\"R\",\"R\",\"U\",\"U\",\"L\",\"L\"]"], ["2", "1", "[[0,1]]", "[\"R\",\"L\"]"], ["2", "1", "[[0,1]]", "[\"L\"]"], ["4", "4", "[]", "[\"R\",\"R\",\"R\",\"R\"]"], ["4", "4", "[]", "[\"R\",\"R\",\"R\"]"], ["1", "3", "[[1,0],[2,0]]", "[\"D\",\"D\",\"U\",\"U\"]"], ["3", "1", "[[0,1],[0,2]]", "[\"R\",\"R\",\"L\",\"L\"]"], ["2", "2", "[[0,1],[1,1],[1,0]]", "[\"R\",\"D\",\"L\",\"U\"]"], ["2", "2", "[[0,1],[1,1],[1,0]]", "[\"R\",\"D\",\"L\",\"U\",\"R\"]"], ["5", "5", "[[0,4]]", "[\"R\",\"R\",\"R\",\"R\"]"], ["5", "5", "[]", "[]"], ["3", "3", "[[1,1]]", "[\"D\",\"R\",\"U\",\"L\"]"], ["3", "3", "[[1,1]]", "[\"R\",\"D\",\"L\",\"U\"]"], ["2", "3", "[[2,1]]", "[\"D\",\"D\",\"R\"]"], ["2", "3", "[[2,1]]", "[\"D\",\"D\",\"R\",\"L\",\"U\",\"U\"]"], ["3", "2", "[]", "[\"U\"]"], ["3", "2", "[]", "[\"L\"]"], ["3", "2", "[]", "[\"D\"]"], ["4", "1", "[[0,1],[0,2],[0,3]]", "[\"R\",\"R\",\"R\",\"L\"]"], ["4", "1", "[[0,1],[0,2],[0,3]]", "[\"R\",\"R\",\"R\"]"], ["2", "2", "[[1,0]]", "[\"D\",\"U\",\"R\"]"], ["3", "3", "[[0,2],[2,2],[2,0],[0,0]]", "[\"R\",\"R\",\"D\",\"D\",\"L\",\"L\",\"U\",\"U\"]"]], "expected": [[0, 0, 1, 1, 2, -1], [0, 0, 0], [-1], [1, 2, 3], [0, 1, 1, 1, 1, 1, 1, 2], [1, 1], [-1], [0, 0, 0, -1], [0, 0, 0], [1, 2, -1, -1], [1, 2, -1, -1], [1, 2, 3, 3], [1, 2, 3, 3, 3], [0, 0, 0, 1], [], [0, 1, 1, 1], [0, 1, 1, 1], [0, 0, 1], [0, 0, 1, 1, 1, 1], [-1], [-1], [0], [1, 2, 3, -1], [1, 2, 3], [1, 1, 1], [0, 1, 1, 2, 2, 3, 3, 4]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "428", "slug": "design-tic-tac-toe", "id": 428, "title": "Design Tic-Tac-Toe", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/design-tic-tac-toe/", "examples": [{"input": "operations = [\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\"], args = [[3],[0,0,1],[0,2,2],[2,2,1],[1,1,2],[2,0,1],[1,0,2],[2,1,1]]", "output": "[0,0,0,0,0,0,1]", "explanation": "Player 1 seals the bottom row on the last placement."}, {"input": "operations = [\"TicTacToe\",\"move\",\"move\",\"move\"], args = [[2],[0,0,1],[1,1,2],[0,1,1]]", "output": "[0,0,1]", "explanation": "Player 1 completes the top row of the small board."}, {"input": "operations = [\"TicTacToe\",\"move\",\"move\",\"move\"], args = [[3],[0,0,1],[1,1,1],[2,2,1]]", "output": "[0,0,1]", "explanation": "Player 1 completes the main diagonal."}], "hints": ["Adaptation: replay the trace with counters rather than building a class.", "Score player 1 as +1 and player 2 as -1 across per-row, per-column, and two diagonal tallies.", "A tally reaching +n or -n means that player owns the whole line."], "statement": "This is an offline adaptation of a game task. Instead of writing a class, you write one function that replays a whole match:\n\n```\nrunTicTacToe(operations, args)\n```\n\n`operations[i]` is either `\"TicTacToe\"` (create a board) or `\"move\"`. `args[i]` carries the matching argument: `args[0]` is `[n]` (board is `n x n`), and each later entry is `[row, col, player]` describing a placement by player 1 or 2. Both arrays share the same length, and every placement targets an empty cell.\n\nAfter each placement, determine the game state: return `1` when player 1 has just completed a full row, column, or diagonal; `2` when player 2 has done so; otherwise `0`. Moves never undo a decided win in the test data beyond reporting it.\n\nReturn the list of those results, one per `move`, in order. The constructor contributes nothing.\n\n**Constraints:**\n- `2 <= n <= 100`\n- `0 <= row, col < n`\n- `player` is `1` or `2`.\n- Each cell is used at most once.\n\n**Adaptation note:** The classic version exposes a `TicTacToe` class with a `move` method. Here moves are replayed by `runTicTacToe` returning all `move` outcomes.\n", "solution": "## Approach\n\nKeep one counter per row, one per column, and one for each diagonal, adding +1 for player 1 and -1 for player 2 on every placement. After updating the affected row, column, and possibly diagonals, a counter whose absolute value equals the board size proves its owner fills that entire line. Each move therefore resolves in constant time and memory grows linearly with board size.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the number of moves (O(1) each).\n- **Space Complexity:** O(n) for the row and column tallies.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runTicTacToe(self, operations: List[str], args: List[List[int]]) -> List[int]:\n n = args[0][0]\n rows = [0] * n\n cols = [0] * n\n diag = anti = 0\n out = []\n for op, a in zip(operations[1:], args[1:]):\n if op == \"move\":\n r, c, p = a\n d = 1 if p == 1 else -1\n rows[r] += d\n cols[c] += d\n if r == c:\n diag += d\n if r + c == n - 1:\n anti += d\n if abs(rows[r]) == n or abs(cols[c]) == n or abs(diag) == n or abs(anti) == n:\n out.append(p)\n else:\n out.append(0)\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunTicTacToe(operations []string, args [][]int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def runTicTacToe(self, operations: List[str], args: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runTicTacToe(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runTicTacToe", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,1],[0,2,2],[2,2,1],[1,1,2],[2,0,1],[1,0,2],[2,1,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\"]", "[[2],[0,0,1],[1,1,2],[0,1,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\"]", "[[3],[0,0,1],[1,1,1],[2,2,1]]"], ["[\"TicTacToe\",\"move\"]", "[[3],[0,0,1]]"], ["[\"TicTacToe\",\"move\",\"move\"]", "[[3],[0,0,1],[0,1,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,1],[1,0,1],[2,0,1],[0,1,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,2],[0,1,2],[0,2,2],[1,1,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\"]", "[[3],[0,2,1],[1,1,1],[2,0,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[2],[0,0,2],[0,1,2],[1,0,1],[1,1,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,1],[1,0,2],[0,1,1],[1,1,2],[0,2,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[1,1,2],[0,0,2],[2,2,2],[0,2,2]]"], ["[\"TicTacToe\",\"move\",\"move\"]", "[[2],[1,1,1],[0,0,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[4],[0,0,1],[1,1,1],[2,2,1],[3,3,1],[0,1,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[4],[0,3,2],[1,2,2],[2,1,2],[3,0,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\"]", "[[5],[2,0,1],[2,1,1],[2,2,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,1],[1,0,2],[0,1,1],[1,1,2],[0,2,2],[2,2,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,2],[2,2,1],[0,1,2],[1,1,1],[0,2,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,1,1],[1,1,2],[2,1,1],[0,0,2]]"], ["[\"TicTacToe\",\"move\",\"move\"]", "[[3],[2,2,2],[1,1,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,1],[0,1,2],[0,2,1],[1,1,2],[1,0,1],[1,2,2],[2,1,1],[2,0,2],[2,2,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[2],[0,0,1],[0,1,1],[1,0,2],[1,1,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\"]", "[[4],[1,1,1],[2,2,2],[3,3,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[5],[0,0,2],[0,1,2],[0,2,2],[0,3,2],[0,4,2]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\",\"move\"]", "[[5],[0,4,1],[1,4,1],[2,4,1],[3,4,1],[4,4,1]]"], ["[\"TicTacToe\",\"move\",\"move\"]", "[[10],[5,5,1],[5,6,1]]"], ["[\"TicTacToe\",\"move\",\"move\",\"move\",\"move\"]", "[[3],[0,0,1],[1,1,2],[0,2,1],[2,0,2]]"]], "expected": [[0, 0, 0, 0, 0, 0, 1], [0, 0, 1], [0, 0, 1], [0], [0, 0], [0, 0, 1, 0], [0, 0, 2, 0], [0, 0, 1], [0, 2, 0, 1], [0, 0, 0, 0, 1], [0, 0, 2, 2], [0, 0], [0, 0, 0, 1, 2], [0, 0, 0, 2], [0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 2], [0, 0, 0, 0], [0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2], [0, 0, 0], [0, 0, 0, 0, 2], [0, 0, 0, 0, 1], [0, 0], [0, 0, 0, 0]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "106", "slug": "design-twitter", "id": 106, "title": "Design Twitter", "difficulty": "Medium", "category": "heap", "link": "https://leetcode.com/problems/design-twitter/", "examples": [{"input": "operations = [\"Twitter\",\"postTweet\",\"getNewsFeed\",\"follow\",\"postTweet\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"], args = [[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]", "output": "[[5],[6,5],[5]]", "explanation": "Only news-feed calls contribute rows to the result."}, {"input": "operations = [\"Twitter\",\"postTweet\",\"postTweet\",\"getNewsFeed\"], args = [[],[1,10],[1,11],[1]]", "output": "[[11,10]]", "explanation": "Feeds are ordered from newest to oldest."}], "hints": ["Assign each posted tweet an increasing timestamp and store tweets by author.", "For a feed, consider the user's own tweet list together with each followed user's list.", "Use a max-heap to merge those already time-ordered lists and stop after 10 tweets."], "statement": "Implement the behavior of a simplified Twitter service through the portable function `runTwitter(operations, args)`.\n\nThe arrays are parallel. `operations[i]` names an operation and `args[i]` contains its integer arguments:\n\n- `\"Twitter\"` with `[]` initializes the service and is always the first operation.\n- `\"postTweet\"` with `[userId, tweetId]` posts a new tweet.\n- `\"getNewsFeed\"` with `[userId]` requests up to the 10 most recent tweet IDs posted by that user or by users they follow.\n- `\"follow\"` with `[followerId, followeeId]` starts following a user.\n- `\"unfollow\"` with `[followerId, followeeId]` stops following a user; unfollowing a user who is not followed has no effect.\n\nReturn one row for each `getNewsFeed` operation and no row for constructors or mutating operations. Every feed row must be in exact reverse chronological order and contain at most 10 tweet IDs.\n\nThis is a function adaptation of the original class-design problem. There is intentionally no `classProblem` wrapper.\n\n**Constraints:**\n\n- `1 <= operations.length == args.length <= 30001`\n- The first operation is `\"Twitter\"` with an empty argument row.\n- Every later operation is one of `postTweet`, `getNewsFeed`, `follow`, or `unfollow` and has the argument count described above.\n- `1 <= userId, followerId, followeeId <= 500`\n- `0 <= tweetId <= 10000`, and all posted tweet IDs in one test are unique.\n- `followerId != followeeId`.\n", "solution": "## Approach\n\nStore tweets in one chronological list and maintain a set of followees for each user. For a news-feed request, scan tweets from newest to oldest, collecting tweets from the user or a followed author until the feed contains 10 entries.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(Q * T) in the worst case, where `Q` is the number of operations and `T` is the number of posted tweets; since `T <= Q`, this is O(Q^2).\n- **Space Complexity:** O(T + F + Q), where `F` is the number of active follow relationships and the O(Q) term accounts for returned feed rows.\n\n## Implementation\n\n```python\nfrom typing import Dict, List, Set, Tuple\n\n\nclass Solution:\n def runTwitter(self, operations: List[str], args: List[List[int]]) -> List[List[int]]:\n tweets: List[Tuple[int, int]] = []\n following: Dict[int, Set[int]] = {}\n feeds: List[List[int]] = []\n\n for operation, values in zip(operations, args):\n if operation == \"postTweet\":\n tweets.append((values[0], values[1]))\n elif operation == \"follow\":\n following.setdefault(values[0], set()).add(values[1])\n elif operation == \"unfollow\":\n following.get(values[0], set()).discard(values[1])\n elif operation == \"getNewsFeed\":\n user_id = values[0]\n followees = following.get(user_id, set())\n feed = []\n for author, tweet_id in reversed(tweets):\n if author == user_id or author in followees:\n feed.append(tweet_id)\n if len(feed) == 10:\n break\n feeds.append(feed)\n return feeds\n```\n", "starter": {"go": "package main\n\nfunc RunTwitter(operations []string, args [][]int) [][]int {\n panic(\"TODO\")\n}", "python": "from typing import List\n\nclass Solution:\n def runTwitter(self, operations: List[str], args: List[List[int]]) -> List[List[int]]:\n raise NotImplementedError\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> runTwitter(vector<string>& operations, vector<vector<int>>& args) {\n return {};\n }\n};"}, "fn": "runTwitter", "params": [{"name": "operations", "type": "string_array"}, {"name": "args", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[\"Twitter\",\"postTweet\",\"getNewsFeed\",\"follow\",\"postTweet\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,5],[1],[1,2],[2,6],[1],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,10],[1,11],[1]]"], ["[\"Twitter\",\"getNewsFeed\",\"follow\",\"getNewsFeed\"]", "[[],[3],[3,4],[3]]"], ["[\"Twitter\",\"getNewsFeed\"]", "[[],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"getNewsFeed\"]", "[[],[2,20],[1,2],[1]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,2],[2,21],[1]]"], ["[\"Twitter\",\"postTweet\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,30],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,31],[2,32],[1,2],[1],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,40],[1,41],[1,42],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"follow\",\"follow\",\"getNewsFeed\"]", "[[],[1,50],[2,51],[3,52],[1,2],[1,3],[1]]"], ["[\"Twitter\",\"follow\",\"follow\",\"unfollow\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,2],[1,3],[1,2],[2,60],[3,61],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"follow\",\"getNewsFeed\"]", "[[],[4,70],[1,4],[1,4],[1]]"], ["[\"Twitter\",\"unfollow\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,2],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"postTweet\",\"getNewsFeed\"]", "[[],[2,80],[1,81],[1,2],[2,82],[1]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"unfollow\",\"postTweet\",\"getNewsFeed\"]", "[[],[5,6],[6,90],[5,6],[6,91],[5]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"postTweet\",\"follow\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,100],[1,2],[2,101],[2,3],[3,102],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"postTweet\",\"follow\",\"getNewsFeed\"]", "[[],[3,110],[2,3],[2,111],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"getNewsFeed\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,120],[2,121],[1,2],[1],[1,122],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"getNewsFeed\",\"unfollow\",\"follow\",\"getNewsFeed\"]", "[[],[2,130],[1,2],[1],[1,2],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"follow\",\"follow\",\"getNewsFeed\"]", "[[],[2,140],[3,141],[1,142],[1,2],[1,3],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[7,150],[7,151],[7,152],[7,153],[7]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"unfollow\",\"getNewsFeed\"]", "[[],[8,160],[9,161],[8,9],[8,9],[8]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,2],[2,170],[1],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"getNewsFeed\",\"postTweet\",\"getNewsFeed\"]", "[[],[2,180],[1,2],[1],[2,181],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"follow\",\"unfollow\",\"getNewsFeed\"]", "[[],[2,190],[3,191],[1,2],[1,3],[1,3],[1]]"], ["[\"Twitter\",\"postTweet\",\"getNewsFeed\",\"getNewsFeed\"]", "[[],[1,200],[1],[2]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"getNewsFeed\",\"getNewsFeed\"]", "[[],[5,210],[4,5],[4],[5]]"], ["[\"Twitter\",\"follow\",\"follow\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,2],[2,3],[2,220],[3,221],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"postTweet\",\"unfollow\",\"getNewsFeed\"]", "[[],[2,230],[1,2],[1,231],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"follow\",\"getNewsFeed\"]", "[[],[2,240],[2,241],[1,242],[1,2],[1]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"postTweet\",\"unfollow\",\"follow\",\"getNewsFeed\"]", "[[],[1,2],[2,250],[3,251],[1,2],[1,3],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"follow\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,260],[1,2],[1,3],[2,261],[3,262],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"getNewsFeed\",\"unfollow\",\"postTweet\",\"getNewsFeed\"]", "[[],[2,270],[1,271],[1,2],[1],[1,2],[2,272],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"postTweet\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,280],[2,1],[2,281],[2],[2,1],[2]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"follow\",\"follow\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"]", "[[],[2,290],[3,291],[1,292],[1,2],[1,3],[1],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,300],[1,301],[1,302],[1,303],[1,304],[1]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"follow\",\"postTweet\",\"unfollow\",\"getNewsFeed\"]", "[[],[4,5],[5,310],[4,6],[6,311],[4,5],[4]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\",\"follow\",\"getNewsFeed\"]", "[[],[9,320],[8,9],[8],[8,9],[8],[8,9],[8]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"getNewsFeed\",\"postTweet\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,330],[2,331],[1,2],[1],[2,332],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"postTweet\",\"getNewsFeed\",\"follow\",\"postTweet\",\"getNewsFeed\"]", "[[],[2,340],[1,2],[3,341],[1],[1,3],[3,342],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"postTweet\",\"unfollow\",\"postTweet\",\"getNewsFeed\"]", "[[],[2,350],[1,2],[2,351],[1,2],[2,352],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"getNewsFeed\",\"follow\",\"getNewsFeed\"]", "[[],[2,360],[3,361],[1,2],[1],[1,3],[1]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"getNewsFeed\",\"postTweet\",\"getNewsFeed\"]", "[[],[10,11],[11,370],[10],[10,371],[10]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"follow\",\"unfollow\",\"follow\",\"getNewsFeed\"]", "[[],[2,380],[3,381],[4,382],[1,2],[1,2],[1,4],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,400],[1,401],[1,402],[1,403],[1,404],[1,405],[1,406],[1,407],[1,408],[1,409],[1,410],[1,411],[1]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"postTweet\",\"postTweet\",\"getNewsFeed\"]", "[[],[1,2],[1,420],[2,421],[1,422],[1]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"follow\",\"postTweet\",\"postTweet\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,430],[1,2],[1,3],[2,431],[3,432],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"getNewsFeed\",\"follow\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"]", "[[],[2,440],[1],[1,2],[1],[1,2],[1]]"], ["[\"Twitter\",\"follow\",\"postTweet\",\"getNewsFeed\",\"unfollow\",\"postTweet\",\"follow\",\"getNewsFeed\"]", "[[],[1,2],[2,450],[1],[1,2],[2,451],[1,2],[1]]"], ["[\"Twitter\",\"postTweet\",\"postTweet\",\"follow\",\"postTweet\",\"getNewsFeed\",\"unfollow\",\"getNewsFeed\"]", "[[],[1,460],[2,461],[1,2],[1,462],[1],[1,2],[1]]"], ["[\"Twitter\"]", "[[]]"], ["[\"Twitter\",\"postTweet\",\"follow\",\"getNewsFeed\",\"unfollow\",\"postTweet\",\"getNewsFeed\"]", "[[],[500,10000],[1,500],[1],[1,500],[1,0],[1]]"], ["@javascript:JSON.stringify(['Twitter',...Array(498).fill('postTweet'),'getNewsFeed'])", "@javascript:JSON.stringify([[],...Array.from({length:498},(_,i)=>[i%2===0?1:500,10000-i]),[1]])"]], "expected": [[[5], [6, 5], [5]], [[11, 10]], [[], []], [[]], [[20]], [[21]], [[30]], [[32, 31], [31]], [[42, 41, 40]], [[52, 51, 50]], [[61]], [[70]], [[]], [[82, 81, 80]], [[]], [[101, 100]], [[111]], [[121, 120], [122, 121, 120]], [[130], [130]], [[142, 141, 140]], [[153, 152, 151, 150]], [[160]], [[170], []], [[180], [181, 180]], [[190]], [[200], []], [[210], [210]], [[220]], [[231]], [[242, 241, 240]], [[251]], [[262, 261, 260]], [[271, 270], [271]], [[281, 280], [281]], [[292, 291, 290], [292, 291]], [[304, 303, 302, 301, 300]], [[311]], [[320], [], [320]], [[331, 330], [330]], [[340], [342, 341, 340]], [[]], [[360], [361, 360]], [[370], [371, 370]], [[382]], [[411, 410, 409, 408, 407, 406, 405, 404, 403, 402]], [[422, 421, 420]], [[432, 430]], [[], [440], []], [[450], [451, 450]], [[462, 461, 460], [462, 460]], [], [[10000], [0]], [[9504, 9506, 9508, 9510, 9512, 9514, 9516, 9518, 9520, 9522]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "579", "slug": "detect-capital", "id": 579, "title": "Detect Capital", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/detect-capital/", "examples": [{"input": "word = \"USA\"", "output": "true", "explanation": "All letters are uppercase."}, {"input": "word = \"leetcode\"", "output": "true", "explanation": "All letters are lowercase."}, {"input": "word = \"Google\"", "output": "true", "explanation": "Only the leading letter is uppercase."}, {"input": "word = \"FlaG\"", "output": "false", "explanation": "Uppercase letters appear in the tail without covering the whole word."}], "hints": ["Count uppercase letters: zero means all-lowercase and length-many means all-uppercase.", "Otherwise exactly one uppercase letter is allowed, and it must sit at index 0."], "statement": "A word uses capitals correctly when one of three patterns holds: every letter is uppercase (e.g. `\"USA\"`), every letter is lowercase (e.g. `\"leetcode\"`), or only the first letter is uppercase and the rest are lowercase (e.g. `\"Google\"`).\n\nGiven `word`, return `true` when its capitalization follows one of these patterns and `false` otherwise.\n\n**Constraints:**\n- `1 <= word.length <= 100`\n- `word` consists of English letters\n", "solution": "## Approach\n\nTally the uppercase letters in a single pass. Zero tallies accept the all-lowercase shape and a full-length tally accepts the all-uppercase shape. Any other total is valid only when the single uppercase letter leads the word, which covers the capitalized shape and rejects everything else.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) to scan the word once.\n- **Space Complexity:** O(1) extra memory.\n\n## Implementation\n\n```python\nclass Solution:\n def detectCapitalUse(self, word: str) -> bool:\n upper = sum(1 for c in word if c.isupper())\n if upper == 0 or upper == len(word):\n return True\n return upper == 1 and word[0].isupper()\n```\n", "starter": {"go": "package main\n\nfunc DetectCapitalUse(word string) bool {\n \n}", "python": "class Solution:\n def detectCapitalUse(self, word: str) -> bool:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool detectCapitalUse(string word) {\n return false;\n }\n};"}, "fn": "detectCapitalUse", "params": [{"name": "word", "type": "string"}], "outputType": "boolean", "tests": [["USA"], ["leetcode"], ["Google"], ["FlaG"], ["A"], ["a"], ["AB"], ["Ab"], ["aB"], ["ab"], ["ABCDEF"], ["abcdef"], ["Abcdef"], ["aBcdef"], ["ABcdef"], ["AbcdeF"], ["Z"], ["zZ"], ["Zz"], ["ZZ"], ["zz"], ["mL"], ["Ml"], ["ML"], ["ml"], ["HelloWorld"], ["HELLOWORLD"], ["helloworld"]], "expected": [true, true, true, false, true, true, true, true, false, true, true, true, true, false, false, false, true, false, true, true, true, false, true, true, true, false, true, true], "loose": false}
|