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": "334", "slug": "the-skyline-problem", "id": 334, "title": "The Skyline Problem", "difficulty": "Hard", "category": "heap", "link": "https://leetcode.com/problems/the-skyline-problem/", "examples": [{"explanation": "Overlapping blocks merge into one silhouette that dips to 0 at 12, resumes at 15 and ends at 24.", "input": "buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]", "output": "[[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]"}, {"explanation": "The blocks touch and share one height, so the outline is flat from 0 to 5.", "input": "buildings = [[0,2,3],[2,5,3]]", "output": "[[0,3],[5,0]]"}, {"explanation": "A single block rises to 1 between 1 and 2.", "input": "buildings = [[1,2,1]]", "output": "[[1,1],[2,0]]"}], "hints": ["Turn every building into two events (an opening and a closing) and sweep x from left to right.", "Keep the active heights in a structure that yields the current maximum and supports removals, such as a balanced tree of height counts.", "Emit a key point whenever the maximum changes; process all events sharing one x before deciding.", "Adaptation: the nested input maps to int_array_2d and the nested output maps to int_list_2d in this judge."], "statement": "A city skyline is described by a list of buildings, where each building is `[left, right, height]`: it spans the ground from `left` to `right` (exclusive of `right`) and rises to `height`. The skyline silhouette is the outline you see from afar.\n\nReturn the silhouette as a list of key points `[x, h]`, ordered by increasing `x`. Each key point marks where the visible height changes: consecutive points `[x1, h1], [x2, h2]` mean the height is `h1` on the stretch from `x1` to `x2`. The outline starts at the first edge where the height leaves 0 and must finish with a point whose height is 0. No two consecutive points share the same height.\n\n**Constraints:**\n- `1 <= buildings.length <= 10^4`\n- `0 <= left < right <= 2^31 - 1`\n- `1 <= height <= 2^31 - 1`\n- The buildings are given in non-decreasing order of `left`.\n", "solution": "## Approach\n\nConvert each building into an opening event (negative height, so openings sort first) and a closing event, then sweep x in order. Maintain the active heights in a max-heap with lazy deletion: push every opened height, count every closed one, and discard heap tops that have been fully closed. After applying every event at one x, the heap top is the visible height; whenever it differs from the previous height, record `[x, height]` as a key point.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting 2n events and heap updates.\n- **Space Complexity:** O(n) for the events and the heap.\n\n## Implementation\n\n```python\nimport heapq\nfrom collections import Counter\nfrom typing import List\n\nclass Solution:\n def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:\n events = []\n for l, r, h in buildings:\n events.append((l, -h))\n events.append((r, h))\n events.sort(key=lambda e: (e[0], e[1]))\n live = Counter()\n heap = [0]\n res: List[List[int]] = []\n prev = 0\n i = 0\n while i < len(events):\n x = events[i][0]\n while i < len(events) and events[i][0] == x:\n h = events[i][1]\n if h < 0:\n heapq.heappush(heap, h)\n else:\n live[h] += 1\n i += 1\n while heap and live[-heap[0]] > 0:\n live[-heap[0]] -= 1\n heapq.heappop(heap)\n cur = -heap[0]\n if cur != prev:\n res.append([x, cur])\n prev = cur\n return res\n```\n", "starter": {"go": "package main\n\nfunc GetSkyline(buildings [][]int) [][]int {\n return [][]int{}\n}", "python": "from typing import List\nclass Solution:\n def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {\n return {};\n }\n};"}, "fn": "getSkyline", "params": [{"name": "buildings", "type": "int_array_2d"}], "outputType": "int_list_2d", "tests": [["[[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]"], ["[[0,2,3],[2,5,3]]"], ["[[1,2,1]]"], ["[[1,5,3],[2,4,5]]"], ["[[1,3,2],[4,6,2]]"], ["[[0,1,1],[1,2,1],[2,3,1]]"], ["[[0,5,5],[0,5,3]]"], ["[[0,5,3],[0,5,5]]"], ["[[1,10,2],[2,9,4],[3,8,6],[4,7,8]]"], ["[[1,2,3],[3,4,3],[5,6,3]]"], ["[[2,4,7],[2,4,7]]"], ["[[0,2,3],[1,5,3],[4,6,2]]"], ["[[1,2,1],[1,2,2],[1,2,3]]"], ["[[3,6,4],[3,6,4],[3,6,5]]"], ["[[0,3,1],[1,4,2],[2,5,3],[3,6,4]]"], ["[[5,8,3],[2,6,4],[7,10,2]]"], ["[[1,4,2],[2,5,3],[6,9,1]]"], ["[[0,10,1],[1,2,5],[3,4,5],[5,6,5]]"], ["[[1,3,3],[2,4,4],[5,7,2],[6,8,5]]"], ["[[10,20,5],[12,18,9],[14,16,12]]"], ["[[0,2147483647,2147483647]]"], ["[[1,2,2],[2,3,1]]"], ["[[4,9,6],[4,9,6],[10,12,3]]"], ["[[2,3,5],[3,4,5],[4,5,5],[5,6,5]]"], ["[[0,4,2],[0,2,4],[2,6,1]]"], ["[[7,9,2],[7,8,4],[8,10,3]]"], ["[[1,5,1],[2,6,2],[3,7,3],[4,8,4],[5,9,5]]"]], "expected": [[[2, 10], [3, 15], [7, 12], [12, 0], [15, 10], [20, 8], [24, 0]], [[0, 3], [5, 0]], [[1, 1], [2, 0]], [[1, 3], [2, 5], [4, 3], [5, 0]], [[1, 2], [3, 0], [4, 2], [6, 0]], [[0, 1], [3, 0]], [[0, 5], [5, 0]], [[0, 5], [5, 0]], [[1, 2], [2, 4], [3, 6], [4, 8], [7, 6], [8, 4], [9, 2], [10, 0]], [[1, 3], [2, 0], [3, 3], [4, 0], [5, 3], [6, 0]], [[2, 7], [4, 0]], [[0, 3], [5, 2], [6, 0]], [[1, 3], [2, 0]], [[3, 5], [6, 0]], [[0, 1], [1, 2], [2, 3], [3, 4], [6, 0]], [[2, 4], [6, 3], [8, 2], [10, 0]], [[1, 2], [2, 3], [5, 0], [6, 1], [9, 0]], [[0, 1], [1, 5], [2, 1], [3, 5], [4, 1], [5, 5], [6, 1], [10, 0]], [[1, 3], [2, 4], [4, 0], [5, 2], [6, 5], [8, 0]], [[10, 5], [12, 9], [14, 12], [16, 9], [18, 5], [20, 0]], [[0, 2147483647], [2147483647, 0]], [[1, 2], [2, 1], [3, 0]], [[4, 6], [9, 0], [10, 3], [12, 0]], [[2, 5], [6, 0]], [[0, 4], [2, 2], [4, 1], [6, 0]], [[7, 4], [8, 3], [10, 0]], [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [9, 0]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "487", "slug": "third-maximum-number", "id": 487, "title": "Third Maximum Number", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/third-maximum-number/", "examples": [{"input": "nums = [3,2,1]", "output": "1", "explanation": "Distinct values sorted are 3, 2, 1; the third is 1."}, {"input": "nums = [1,2]", "output": "2", "explanation": "Only two distinct values exist, so the maximum 2 is returned."}, {"input": "nums = [2,2,3,1]", "output": "1", "explanation": "Distinct values are 3, 2, 1; duplicates do not create extra ranks."}], "hints": ["Rank distinct values only; repeats never advance the rank.", "Track the top three distinct values in one pass.", "If a third distinct value never appears, answer the overall maximum."], "statement": "From the array `nums`, consider its distinct values sorted from largest to smallest. Return the third one. When fewer than three distinct values exist, return the largest value instead.\n\nDuplicates are collapsed first: `[2,2,3,1]` behaves like `[3,2,1]`.\n\n**Constraints:**\n- `1 <= nums.length <= 10^4`\n- `-2^31 <= nums[i] <= 2^31 - 1`\n", "solution": "## Approach\n\nWalk the array once while keeping the three largest distinct values seen so far. Duplicates are skipped, and each new value cascades down the top-three slots when it beats them. After the scan, the third slot holds the answer, or the first slot does when fewer than three distinct values appeared.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def thirdMax(self, nums: List[int]) -> int:\n m1 = m2 = m3 = None\n for x in nums:\n if x == m1 or x == m2 or x == m3:\n continue\n if m1 is None or x > m1:\n m3, m2, m1 = m2, m1, x\n elif m2 is None or x > m2:\n m3, m2 = m2, x\n elif m3 is None or x > m3:\n m3 = x\n return m1 if m3 is None else m3\n```\n", "starter": {"go": "package main\n\nfunc ThirdMax(nums []int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def thirdMax(self, nums: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int thirdMax(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "thirdMax", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[3,2,1]"], ["[1,2]"], ["[2,2,3,1]"], ["[1]"], ["[1,1,1]"], ["[1,2,3]"], ["[5,2,4,1,3,6]"], ["[2147483647,-2147483648,0]"], ["[-2147483648,-2147483648,1]"], ["[1,2,2,5,3,5]"], ["[3,3,3,3]"], ["[2,1]"], ["[5,2,2]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[1,1,2,2,3,3]"], ["[0,0,1,1]"], ["[-1,-2,-3]"], ["[100,100,99,99,98]"], ["[1,2,3,3,3]"], ["[2,2,2,1]"], ["[7,7,6,6,5]"], ["[42]"], ["[0,1,-1]"], ["[3,2,2,2,1]"], ["[10,9,8,7,6,5]"], ["[1,3,2]"], ["[-2147483648,1,2]"], ["[5,5,4,4,3,3,2,2,1,1]"], ["[2,3,1,4]"]], "expected": [1, 2, 1, 1, 1, 1, 4, -2147483648, 1, 2, 3, 2, 5, 3, 3, 1, 1, -3, 98, 1, 2, 5, 42, -1, 1, 8, 1, -2147483648, 3, 2], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "914", "slug": "three-equal-parts", "id": 914, "title": "Three Equal Parts", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/three-equal-parts/", "examples": [{"input": "arr = [1,0,1,0,1]", "output": "[0,3]", "explanation": "Blocks [1], [0,1], [0,1] share value 1."}, {"input": "arr = [1,1,0,1,1]", "output": "[-1,-1]", "explanation": "Four ones cannot split into three equal counts."}, {"input": "arr = [1,0,0,1,0,0,1,0,0]", "output": "[2,6]", "explanation": "Three copies of [1,0,0]."}], "hints": ["If all entries are zero, any split with three non-empty parts is valid.", "Otherwise the number of ones must divide by three; find the first one of each third.", "The suffix after the third start (including trailing zeros) must repeat in the first two parts; overlapping tails mean impossible."], "statement": "You are given a binary array `arr`. Split it into three non-empty consecutive blocks so that each block represents the same binary value (leading zeros are ignored).\n\nReturn indices `[i, j]` where the first block is `arr[0..i]`, the second is `arr[i+1..j-1]`, and the third is `arr[j..n-1]`. When no such split exists, return `[-1, -1]`. When several splits work (for example an all-zero array), any valid one is accepted.\n\n**Constraints:**\n- `3 <= arr.length <= 30000`\n- Each entry is `0` or `1`.\n\nAdaptation: the returned pair uses `int_array`; the checker accepts any valid split, not only the reference one.\n", "solution": "## Approach\n\nCount the ones. All zeros can use the ends; a count not divisible by three is impossible. Otherwise locate the first one of each third and measure the trailing tail from the third start to the end. All three blocks must share that exact tail, and the tail must fit without overlapping. The cut points follow directly from the tail length.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `arr`. Counting, locating starts, and comparing tails are linear.\n- **Space Complexity:** O(1) besides the output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:\n n = len(arr)\n total = sum(arr)\n if total == 0:\n return [0, n - 1]\n if total % 3 != 0:\n return [-1, -1]\n k = total // 3\n i1 = i2 = i3 = -1\n cnt = 0\n for i, v in enumerate(arr):\n if v == 1:\n cnt += 1\n if cnt == 1:\n i1 = i\n elif cnt == k + 1:\n i2 = i\n elif cnt == 2 * k + 1:\n i3 = i\n length = n - i3\n for t in range(length):\n if arr[i1 + t] != arr[i2 + t] or arr[i2 + t] != arr[i3 + t]:\n return [-1, -1]\n end_first = i1 + length - 1\n start_third = i2 + length\n if end_first + 1 >= start_third or start_third >= n:\n return [-1, -1]\n return [end_first, start_third]\n```\n", "starter": {"go": "package main\n\nfunc ThreeEqualParts(arr []int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def threeEqualParts(self, arr: List[int]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> threeEqualParts(vector<int>& arr) {\n return {};\n }\n};"}, "fn": "threeEqualParts", "params": [{"name": "arr", "type": "int_array"}], "outputType": "int_array", "tests": [["[1, 0, 1, 0, 1]"], ["[1, 1, 0, 1, 1]"], ["[0, 0, 0, 0]"], ["[0, 0, 0]"], ["[1, 0, 0, 1, 0, 0, 1, 0, 0]"], ["[1, 1, 1]"], ["[0, 1, 0, 1, 0, 1]"], ["[1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]"], ["[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]"], ["[1, 0, 1, 0, 0]"], ["[0, 0, 1, 0, 1, 0, 1]"], ["[1, 0, 0, 1, 0, 1]"], ["[0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0]"], ["[1, 1, 1, 0, 0, 0]"], ["[0, 1, 1, 0, 1, 1, 0, 1, 1]"], ["[1, 0, 0, 0, 0]"], ["[0, 0, 0, 0, 0, 0, 0, 0]"], ["[1, 0, 1, 1, 0, 1]"], ["[0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1]"], ["[1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]"], ["[0, 1, 0]"], ["[1, 0, 0]"], ["[1, 1, 0, 1, 0, 1, 0]"], ["[0, 0, 1, 0, 0, 1, 0, 0, 1]"], ["[1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0]"], ["[1, 0, 1, 0, 1, 0, 1, 0, 1]"], ["[0, 0, 0, 1]"], ["[1, 1, 1, 1]"]], "expected": [[0, 3], [-1, -1], [0, 3], [0, 2], [2, 6], [0, 2], [1, 4], [3, 8], [3, 8], [-1, -1], [2, 5], [0, 4], [5, 10], [-1, -1], [2, 6], [-1, -1], [0, 7], [-1, -1], [3, 8], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [2, 6], [4, 10], [-1, -1], [-1, -1], [-1, -1]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "90", "slug": "time-based-key-value-store", "id": 90, "title": "Time Based Key-Value Store", "difficulty": "Medium", "category": "binary-search", "link": "https://leetcode.com/problems/time-based-key-value-store/", "examples": [{"input": "operations = [\"set\",\"get\",\"get\",\"set\",\"get\",\"get\"], keys = [\"foo\",\"foo\",\"foo\",\"foo\",\"foo\",\"foo\"], values = [\"bar\",\"\",\"\",\"bar2\",\"\",\"\"], timestamps = [1,1,3,4,4,5]", "output": "[\"bar\",\"bar\",\"bar2\",\"bar2\"]", "explanation": "For each key, timestamps are stored sorted. get() returns the value at the largest timestamp <= given timestamp."}, {"input": "operations = [\"set\",\"set\",\"get\",\"get\",\"get\"], keys = [\"love\",\"love\",\"love\",\"love\",\"love\"], values = [\"high\",\"low\",\"\",\"\",\"\"], timestamps = [10,20,5,10,15]", "output": "[\"\",\"high\",\"high\"]", "explanation": "For each key, timestamps are stored sorted. get() returns the value at the largest timestamp <= given timestamp."}, {"input": "operations = [\"get\",\"set\",\"get\"], keys = [\"a\",\"a\",\"a\"], values = [\"ignored\",\"first\",\"ignored\"], timestamps = [10,1,10]", "output": "[\"\",\"first\"]", "explanation": "Operations are processed in order, and values paired with get operations are ignored."}], "hints": ["Store a timestamped sequence independently for each key.", "The strictly increasing set timestamps mean each new pair can be appended.", "For get, binary-search for the rightmost timestamp that is less than or equal to the query timestamp."], "statement": "Implement a time-based key-value store. A key may have several values, each associated with the timestamp at which it was set. A `get` query returns the value with the greatest set timestamp that is less than or equal to the query timestamp. If no such value exists, it returns the empty string.\n\nThis version uses a portable function interface instead of requiring a language-specific `TimeMap` class. The four input arrays are aligned:\n\n- For `operations[i] == \"set\"`, store `values[i]` for `keys[i]` at `timestamps[i]`.\n- For `operations[i] == \"get\"`, ignore `values[i]` (which may be any placeholder, including the empty string), query `keys[i]` at `timestamps[i]`, and append the answer to the returned list.\n- Return results only for `get` operations. Do not return placeholders for `set` operations.\n- Each call starts with an empty store. Across the whole operation sequence, timestamps on `set` operations are strictly increasing.\n\n**Constraints:**\n\n- `1 <= operations.length <= 2 * 10^5`\n- All four arrays have the same length.\n- Every operation is either `\"set\"` or `\"get\"`.\n- `1 <= keys[i].length <= 100`, and every key contains only lowercase English letters and digits.\n- For `set` operations, `1 <= values[i].length <= 100`, and the value contains only lowercase English letters and digits. Values paired with `get` operations are ignored placeholders and are not subject to this requirement.\n- `1 <= timestamps[i] <= 10^7`\n- Timestamps on `set` operations are strictly increasing globally, in operation order.\n\n**Portable interface:** Implement `runTimeMap(operations, keys, values, timestamps)`. This is intentionally function-based and must not be implemented as a class problem.\n", "solution": "## Approach\n\nReplay the operations in order while storing a timestamped list for each key. The guaranteed increasing set timestamps allow each new pair to be appended. For each `get`, binary-search that key's list for the rightmost timestamp no greater than the query and append only that result to the returned list.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(S + sum(log s_k)) across all operations, where `S` is the number of `set` operations and `s_k` is the number of stored values for the key used by each `get`. The worst case is O(q log q) for `q` operations.\n- **Space Complexity:** O(S) auxiliary space for stored history, plus O(G) for the returned results from `G` get operations.\n\n## Implementation\n\n```python\nfrom typing import Dict, List, Tuple\n\n\nclass Solution:\n def runTimeMap(\n self,\n operations: List[str],\n keys: List[str],\n values: List[str],\n timestamps: List[int],\n ) -> List[str]:\n history: Dict[str, List[Tuple[int, str]]] = {}\n result = []\n\n for operation, key, value, timestamp in zip(\n operations, keys, values, timestamps\n ):\n if operation == \"set\":\n history.setdefault(key, []).append((timestamp, value))\n continue\n\n entries = history.get(key, [])\n left, right, best = 0, len(entries) - 1, -1\n while left <= right:\n middle = left + (right - left) // 2\n if entries[middle][0] <= timestamp:\n best = middle\n left = middle + 1\n else:\n right = middle - 1\n result.append(\"\" if best < 0 else entries[best][1])\n\n return result\n```\n", "starter": {"go": "package main\n\nfunc RunTimeMap(operations []string, keys []string, values []string, timestamps []int) []string {\n return []string{}\n}", "python": "from typing import List\n\nclass Solution:\n def runTimeMap(self, operations: List[str], keys: List[str], values: List[str], timestamps: List[int]) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> runTimeMap(vector<string>& operations, vector<string>& keys, vector<string>& values, vector<int>& timestamps) {\n return {};\n }\n};"}, "fn": "runTimeMap", "params": [{"name": "operations", "type": "string_array"}, {"name": "keys", "type": "string_array"}, {"name": "values", "type": "string_array"}, {"name": "timestamps", "type": "int_array"}], "outputType": "string_list", "tests": [["[\"set\",\"get\",\"get\",\"set\",\"get\",\"get\"]", "[\"foo\",\"foo\",\"foo\",\"foo\",\"foo\",\"foo\"]", "[\"bar\",\"\",\"\",\"bar2\",\"\",\"\"]", "[1,1,3,4,4,5]"], ["[\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"love\",\"love\",\"love\",\"love\",\"love\"]", "[\"high\",\"low\",\"\",\"\",\"\"]", "[10,20,5,10,15]"], ["[\"get\"]", "[\"missing\"]", "[\"ignored\"]", "[1]"], ["[\"set\",\"get\"]", "[\"a\",\"a\"]", "[\"first\",\"ignored\"]", "[1,1]"], ["[\"set\",\"get\"]", "[\"a\",\"a\"]", "[\"later\",\"ignored\"]", "[5,4]"], ["[\"set\",\"set\",\"get\"]", "[\"a\",\"a\",\"a\"]", "[\"one\",\"three\",\"\"]", "[1,3,2]"], ["[\"set\",\"set\",\"get\"]", "[\"a\",\"a\",\"a\"]", "[\"one\",\"three\",\"\"]", "[1,3,3]"], ["[\"set\",\"set\",\"get\"]", "[\"a\",\"a\",\"a\"]", "[\"one\",\"three\",\"\"]", "[1,3,100]"], ["[\"set\",\"set\",\"get\",\"get\"]", "[\"a\",\"b\",\"a\",\"b\"]", "[\"apple\",\"banana\",\"\",\"\"]", "[1,2,1,2]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\"]", "[\"a\",\"b\",\"a\",\"b\",\"a\"]", "[\"old\",\"bee\",\"new\",\"\",\"\"]", "[1,2,4,3,4]"], ["[\"set\",\"set\",\"set\"]", "[\"a\",\"b\",\"a\"]", "[\"x\",\"y\",\"z\"]", "[1,2,3]"], ["[\"get\",\"get\",\"get\"]", "[\"a\",\"a\",\"b\"]", "[\"x\",\"y\",\"z\"]", "[1,2,3]"], ["[\"set\",\"set\",\"get\",\"get\"]", "[\"a\",\"b\",\"a\",\"b\"]", "[\"x\",\"y\",\"\",\"\"]", "[5,6,5,6]"], ["[\"set\",\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"a\",\"a\",\"b\",\"b\",\"a\",\"b\",\"b\"]", "[\"a2\",\"a10\",\"b4\",\"b8\",\"\",\"\",\"\"]", "[2,10,14,18,9,17,19]"], ["[\"set\",\"set\",\"get\",\"get\"]", "[\"same\",\"same\",\"same\",\"same\"]", "[\"value\",\"value\",\"\",\"\"]", "[1,2,1,2]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"word\",\"word\",\"word\",\"word\",\"word\",\"word\"]", "[\"alpha\",\"beta\",\"gamma\",\"\",\"\",\"\"]", "[2,4,8,3,7,9]"], ["[\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"foo\",\"bar\",\"foo\",\"bar\",\"baz\"]", "[\"red\",\"blue\",\"\",\"\",\"\"]", "[3,6,100,100,100]"], ["[\"get\",\"set\",\"get\"]", "[\"a\",\"a\",\"a\"]", "[\"ignored\",\"first\",\"ignored\"]", "[10,1,10]"], ["[\"set\",\"get\",\"get\"]", "[\"future\",\"future\",\"future\"]", "[\"later\",\"\",\"\"]", "[100,1,100]"], ["[\"set\",\"get\",\"get\"]", "[\"a\",\"a\",\"a\"]", "[\"two\",\"\",\"\"]", "[2,1,2]"], ["[\"set\",\"get\",\"get\"]", "[\"large\",\"large\",\"large\"]", "[\"max\",\"\",\"\"]", "[10000000,9999999,10000000]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\",\"get\"]", "[\"k\",\"k\",\"k\",\"k\",\"k\",\"k\",\"k\"]", "[\"v1\",\"v5\",\"v9\",\"\",\"\",\"\",\"\"]", "[1,5,9,1,4,5,10]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\"]", "[\"x\",\"y\",\"x\",\"x\",\"y\"]", "[\"x1\",\"y2\",\"x3\",\"\",\"\"]", "[1,2,3,2,1]"], ["[\"set\",\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"x\",\"y\",\"x\",\"y\",\"x\",\"y\",\"z\"]", "[\"x2\",\"y3\",\"x8\",\"y9\",\"\",\"\",\"\"]", "[2,3,8,9,7,10,10]"], ["[\"set\",\"get\",\"set\",\"get\",\"set\",\"get\"]", "[\"a\",\"a\",\"a\",\"a\",\"a\",\"a\"]", "[\"one\",\"\",\"two\",\"\",\"three\",\"\"]", "[1,1,2,2,3,3]"], ["[\"set\",\"get\",\"set\",\"get\",\"get\"]", "[\"a\",\"a\",\"b\",\"a\",\"b\"]", "[\"aye\",\"\",\"bee\",\"\",\"\"]", "[10,20,15,9,16]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"n\",\"n\",\"n\",\"n\",\"n\",\"n\"]", "[\"ten\",\"twenty\",\"thirty\",\"\",\"\",\"\"]", "[10,20,30,15,25,35]"], ["[\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"case\",\"cases\",\"case\",\"cases\",\"cas\"]", "[\"singular\",\"plural\",\"\",\"\",\"\"]", "[1,2,2,2,2]"], ["[\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"aa\",\"a\",\"aa\",\"a\",\"aaa\"]", "[\"double\",\"single\",\"\",\"\",\"\"]", "[4,5,4,5,5]"], ["[\"set\",\"set\",\"set\",\"set\",\"get\",\"get\",\"get\",\"get\"]", "[\"p\",\"q\",\"r\",\"s\",\"p\",\"q\",\"r\",\"s\"]", "[\"one\",\"two\",\"three\",\"four\",\"\",\"\",\"\",\"\"]", "[1,2,3,4,10,10,10,10]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"a\",\"b\",\"c\",\"a\",\"b\",\"c\"]", "[\"red\",\"green\",\"blue\",\"ignored\",\"ignored\",\"ignored\"]", "[7,8,9,6,8,10]"], ["[\"set\",\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"a\",\"a\",\"a\",\"a\",\"a\",\"a\",\"a\"]", "[\"v2\",\"v4\",\"v6\",\"v8\",\"\",\"\",\"\"]", "[2,4,6,8,3,7,9]"], ["[\"set\",\"get\",\"get\",\"get\"]", "[\"zero\",\"zero\",\"zero\",\"zero\"]", "[\"start\",\"\",\"\",\"\"]", "[1,1,2,999]"], ["[\"set\",\"set\",\"get\",\"get\"]", "[\"edge\",\"edge\",\"edge\",\"edge\"]", "[\"low\",\"high\",\"\",\"\"]", "[1,10000000,9999999,10000000]"], ["[\"get\",\"set\",\"get\",\"set\",\"get\"]", "[\"seq\",\"seq\",\"seq\",\"seq\",\"seq\"]", "[\"\",\"a\",\"\",\"b\",\"\"]", "[1,2,2,5,4]"], ["[\"set\",\"get\",\"get\",\"get\"]", "[\"once\",\"once\",\"other\",\"once\"]", "[\"stored\",\"\",\"\",\"\"]", "[50,49,100,51]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"m\",\"m\",\"m\",\"m\",\"m\",\"m\"]", "[\"a\",\"b\",\"c\",\"\",\"\",\"\"]", "[100,200,300,99,200,301]"], ["[\"set\",\"set\",\"get\",\"set\",\"get\",\"get\"]", "[\"left\",\"right\",\"left\",\"left\",\"left\",\"right\"]", "[\"l1\",\"r1\",\"\",\"l2\",\"\",\"\"]", "[1,100,50,120,119,99]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\"]", "[\"odd\",\"odd\",\"odd\",\"odd\",\"odd\"]", "[\"one\",\"three\",\"five\",\"\",\"\"]", "[1,3,5,4,6]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\"]", "[\"even\",\"even\",\"even\",\"even\",\"even\"]", "[\"two\",\"four\",\"six\",\"\",\"\"]", "[2,4,6,1,5]"], ["[\"set\",\"set\",\"get\",\"get\",\"get\",\"get\"]", "[\"city\",\"city\",\"city\",\"city\",\"city\",\"city\"]", "[\"day\",\"night\",\"\",\"\",\"\",\"\"]", "[6,18,5,6,17,18]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"temp\",\"temp\",\"temp\",\"temp\",\"temp\",\"temp\"]", "[\"cold\",\"warm\",\"hot\",\"\",\"\",\"\"]", "[5,15,25,10,20,30]"], ["[\"set\",\"get\",\"set\",\"get\",\"set\",\"get\",\"get\"]", "[\"step\",\"step\",\"step\",\"step\",\"step\",\"step\",\"step\"]", "[\"a\",\"\",\"b\",\"\",\"c\",\"\",\"\"]", "[10,11,20,19,30,29,30]"], ["[\"set\",\"set\",\"get\",\"get\"]", "[\"key\",\"key\",\"key\",\"key\"]", "[\"short\",\"longervalue\",\"\",\"\"]", "[3,30,29,30]"], ["[\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"one\",\"two\",\"one\",\"two\",\"three\"]", "[\"first\",\"second\",\"\",\"\",\"\"]", "[1000,2000,1000,1999,3000]"], ["[\"set\",\"set\",\"set\",\"set\",\"get\",\"get\",\"get\",\"get\"]", "[\"a\",\"b\",\"a\",\"b\",\"a\",\"a\",\"b\",\"b\"]", "[\"a1\",\"b1\",\"a2\",\"b2\",\"\",\"\",\"\",\"\"]", "[1,2,100,200,50,100,150,200]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\",\"get\"]", "[\"prime\",\"prime\",\"prime\",\"prime\",\"prime\",\"prime\",\"prime\"]", "[\"two\",\"three\",\"five\",\"\",\"\",\"\",\"\"]", "[2,3,5,1,2,4,5]"], ["[\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"desc\",\"desc\",\"desc\",\"desc\",\"desc\",\"desc\"]", "[\"early\",\"middle\",\"late\",\"\",\"\",\"\"]", "[10,20,30,30,20,10]"], ["[\"set\",\"set\",\"set\",\"set\",\"get\",\"get\",\"get\"]", "[\"alpha\",\"beta\",\"alpha\",\"beta\",\"alpha\",\"beta\",\"gamma\"]", "[\"a1\",\"b1\",\"a9\",\"b9\",\"\",\"\",\"\"]", "[1,2,9,10,8,10,10]"], ["[\"set\",\"set\",\"set\",\"set\",\"set\",\"get\",\"get\",\"get\",\"get\",\"get\"]", "[\"k\",\"k\",\"k\",\"k\",\"k\",\"k\",\"k\",\"k\",\"k\",\"k\"]", "[\"a\",\"b\",\"c\",\"d\",\"e\",\"\",\"\",\"\",\"\",\"\"]", "[10,20,30,40,50,9,10,25,49,100]"], ["@javascript:JSON.stringify(Array.from({length:40000},(_,i)=>i===39999?'get':'set'))", "@javascript:JSON.stringify(Array(40000).fill('k'))", "@javascript:JSON.stringify(Array.from({length:40000},(_,i)=>i===39999?'':'v'))", "@javascript:JSON.stringify(Array.from({length:40000},(_,i)=>i===39999?10000000:i+1))"]], "expected": [["bar", "bar", "bar2", "bar2"], ["", "high", "high"], [""], ["first"], [""], ["one"], ["three"], ["three"], ["apple", "banana"], ["bee", "new"], [], ["", "", ""], ["x", "y"], ["a2", "b4", "b8"], ["value", "value"], ["alpha", "beta", "gamma"], ["red", "blue", ""], ["", "first"], ["", "later"], ["", "two"], ["", "max"], ["v1", "v1", "v5", "v9"], ["x1", ""], ["x2", "y9", ""], ["one", "two", "three"], ["aye", "", "bee"], ["ten", "twenty", "thirty"], ["singular", "plural", ""], ["double", "single", ""], ["one", "two", "three", "four"], ["", "green", "blue"], ["v2", "v6", "v8"], ["start", "start", "start"], ["low", "high"], ["", "a", "a"], ["", "", "stored"], ["", "b", "c"], ["l1", "l1", ""], ["three", "five"], ["", "four"], ["", "day", "day", "night"], ["cold", "warm", "hot"], ["a", "a", "b", "c"], ["short", "longervalue"], ["first", "", ""], ["a1", "a2", "b1", "b2"], ["", "two", "three", "five"], ["late", "middle", "early"], ["a1", "b9", ""], ["", "a", "b", "d", "e"], ["v"]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "717", "slug": "to-lower-case", "id": 717, "title": "To Lower Case", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/to-lower-case/", "examples": [{"input": "s = \"Hello\"", "output": "\"hello\"", "explanation": "Uppercase H becomes lowercase; the rest stay as they are."}, {"input": "s = \"LOVELY\"", "output": "\"lovely\"", "explanation": "Every uppercase letter shifts to its lowercase form."}, {"input": "s = \"a1B2!\"", "output": "\"a1b2!\"", "explanation": "Only the letter B changes; digits and symbols are untouched."}], "hints": ["Only characters in 'A' to 'Z' need changing; add 32 to their code or use a lookup.", "Leave lowercase letters, digits and symbols exactly as they appear.", "A single left-to-right pass building a new string is enough."], "statement": "Convert every uppercase English letter in `s` to its lowercase form and return the result.\n\nOnly characters from `A` to `Z` change. Lowercase letters, digits, spaces, punctuation and any other symbols stay exactly as they are. The transformation is done character by character from left to right.\n\n**Constraints:**\n- `1 <= s.length <= 100`\n- `s` consists of printable ASCII characters.\n", "solution": "## Approach\n\nScan the string once. Whenever a character lies between `A` and `Z`, shift it by 32 positions to reach its lowercase partner; otherwise copy it unchanged. Building a fresh buffer keeps the input untouched.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`.\n- **Space Complexity:** O(n) for the output string.\n\n## Implementation\n\n```python\nclass Solution:\n def toLowerCase(self, s: str) -> str:\n res = []\n for c in s:\n if 'A' <= c <= 'Z':\n res.append(chr(ord(c) + 32))\n else:\n res.append(c)\n return ''.join(res)\n```\n", "starter": {"go": "package main\n\nfunc ToLowerCase(s string) string {\n return \"\"\n}", "python": "class Solution:\n def toLowerCase(self, s: str) -> str:\n return \"\"", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string toLowerCase(string s) {\n return \"\";\n }\n};"}, "fn": "toLowerCase", "params": [{"name": "s", "type": "string"}], "outputType": "string", "tests": [["Hello"], ["LOVELY"], ["a1B2!"], ["hello"], ["ABC"], ["abc"], ["A"], ["z"], ["123"], ["!@#"], ["aBcDeF"], ["ZzZz"], ["HELLO WORLD"], ["MiXeD CaSe 123"], ["UPPER"], ["lower"], ["AaAaAa"], ["Z"], ["m"], ["Hello, World!"], ["PYTHON"], ["java"], ["C++"], ["123ABCdef!@#"], ["QWERTYUIOP"], ["asdfghjkl"], ["Test123Test"], ["ALLCAPS"]], "expected": ["hello", "lovely", "a1b2!", "hello", "abc", "abc", "a", "z", "123", "!@#", "abcdef", "zzzz", "hello world", "mixed case 123", "upper", "lower", "aaaaaa", "z", "m", "hello, world!", "python", "java", "c++", "123abcdef!@#", "qwertyuiop", "asdfghjkl", "test123test", "allcaps"], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "767", "slug": "toeplitz-matrix", "id": 767, "title": "Toeplitz Matrix", "difficulty": "Easy", "category": "matrix", "link": "https://leetcode.com/problems/toeplitz-matrix/", "examples": [{"input": "matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]", "output": "true", "explanation": "Every upper-left to lower-right diagonal is constant."}, {"input": "matrix = [[1,2],[2,2]]", "output": "false", "explanation": "The main diagonal mixes 1 and 2."}, {"input": "matrix = [[1]]", "output": "true"}], "hints": ["Compare each cell with its upper-left neighbor; any mismatch rejects the matrix.", "Only cells with both r > 0 and c > 0 need a check, so one nested loop suffices."], "statement": "Given an `m x n` integer grid `matrix`, decide whether it is Toeplitz: every diagonal running from the upper left toward the lower right must hold a single repeated value. Formally, each cell must equal its upper-left neighbor whenever that neighbor exists.\n\n**Constraints:**\n- `m == matrix.length`, `n == matrix[i].length`\n- `1 <= m, n <= 20`\n- `0 <= matrix[i][j] <= 99`\n", "solution": "## Approach\n\nScan every cell that has an upper-left neighbor and require equality with that neighbor. The first mismatch proves the grid is not Toeplitz; surviving the whole scan proves every diagonal is constant.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m*n) for one pass over the grid.\n- **Space Complexity:** O(1) besides the input.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:\n for r in range(1, len(matrix)):\n for c in range(1, len(matrix[r])):\n if matrix[r][c] != matrix[r - 1][c - 1]:\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc IsToeplitzMatrix(matrix [][]int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def isToeplitzMatrix(self, matrix: List[List[int]]) -> bool:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool isToeplitzMatrix(vector<vector<int>>& matrix) {\n return false;\n }\n};"}, "fn": "isToeplitzMatrix", "params": [{"name": "matrix", "type": "int_array_2d"}], "outputType": "boolean", "tests": [["[[1,2,3,4],[5,1,2,3],[9,5,1,2]]"], ["[[1,2],[2,2]]"], ["[[1]]"], ["[[1,2,3],[4,1,2],[7,4,1]]"], ["[[1,2,3],[4,5,6]]"], ["[[5]]"], ["[[1,1,1],[1,1,1],[1,1,1]]"], ["[[1,2],[3,1]]"], ["[[1,2],[3,4]]"], ["[[0,0],[0,0]]"], ["[[1,2,3,4,5]]"], ["[[1],[2],[3]]"], ["[[7,8],[9,7],[10,9]]"], ["[[7,8],[9,6],[10,9]]"], ["[[1,2,3],[2,1,2],[3,2,1]]"], ["[[1,2,3],[2,1,2],[3,2,2]]"], ["[[99,0],[1,99]]"], ["[[1,2,3,4],[5,1,2,3],[9,5,1,9]]"], ["[[4,3,2,1],[5,4,3,2],[6,5,4,3],[7,6,5,4]]"], ["[[4,3,2,1],[5,4,3,9],[6,5,4,3]]"], ["[[0]]"], ["[[1,2,3,4,5,6,7,8,9,10]]"], ["[[1],[1],[1],[1]]"], ["[[2,1],[1,2],[2,1]]"], ["[[5,1,2],[6,5,1],[7,6,5],[8,7,6]]"], ["[[5,1,9],[6,5,1],[7,6,5]]"], ["[[0,1,2],[3,0,1],[4,3,0],[5,4,3]]"], ["[[0,1,2],[3,0,9],[4,3,0]]"]], "expected": [true, false, true, true, false, true, true, true, false, true, true, true, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true, false], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "75", "slug": "top-k-frequent-elements", "id": 75, "title": "Top K Frequent Elements", "difficulty": "Medium", "category": "heap", "link": "https://leetcode.com/problems/top-k-frequent-elements/", "examples": [{"input": "nums = [1,1,1,2,2,3], k = 2", "output": "[1,2]", "explanation": "The frequency counts are {1:3, 2:2, 3:1}. The top 2 most frequent elements are [1, 2]."}, {"input": "nums = [1], k = 1", "output": "[1]", "explanation": "The frequency count is {1:1}. The top 1 most frequent element is [1]."}], "hints": ["Count frequencies with a hash map first.", "Use a min-heap of size k keyed by frequency to keep the top k elements in O(n log k).", "Or use bucket sort: build buckets by frequency and collect from highest frequency down in O(n).", "The answer order doesn't matter unless specified."], "statement": "From an integer list `nums` and an integer `k`, produce the `k` entries that show up most often.\n\n**Constraints:**\n\n- 1 \u2264 nums.length \u2264 10^5\n- -10^4 \u2264 nums[i] \u2264 10^4\n- k is in the range [1, the number of unique elements in the array].\n- It is guaranteed that the answer is unique.\n", "solution": "## Approach\n\nCount frequencies with a hash map, then place numbers into buckets indexed by their frequency. Iterate buckets from highest to lowest and collect the top k elements.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import Counter\nclass Solution:\n def topKFrequent(self, nums: List[int], k: int) -> List[int]:\n freq = Counter(nums)\n buckets = [[] for _ in range(len(nums) + 1)]\n for num, f in freq.items():\n buckets[f].append(num)\n res = []\n for i in range(len(buckets) - 1, -1, -1):\n for num in buckets[i]:\n res.append(num)\n if len(res) == k:\n return res\n return res\n```\n", "starter": {"go": "package main\n\nfunc TopKFrequent(nums []int, k int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def topKFrequent(self, nums: List[int], k: int) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> topKFrequent(vector<int>& nums, int k) {\n return {};\n }\n};"}, "fn": "topKFrequent", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int_array", "tests": [["[1,1,1,2,2,3]", "2"], ["[1]", "1"], ["[4,1,-1,2,-1,2,3]", "2"], ["[5,5,5,5,6,6,6,7,7,8]", "2"], ["[0,0,0,0,0]", "1"], ["[2,2,2,3,3,3]", "2"], ["[2,2,2,3,3,3,4,4,4,5,5]", "3"], ["[9,9,9,8,8,7,6,5,4,3]", "2"], ["[-1,-1,-2,-2,-3]", "2"], ["[1,2,3,4,5,6,7,8,9,9,9]", "1"], ["[1,2,2,3,3,3,4,4,4,4]", "4"], ["[3,3,3,1,2]", "1"], ["[1,2,2,3,3,3]", "1"], ["[7,7,7,7]", "1"], ["[1,2,3]", "3"], ["[-10000,10000,-10000]", "1"], ["[5,5,4,4,3]", "2"], ["[1,1,2,3,3,3,4]", "2"], ["[8,8,9,9,9]", "2"], ["[0,1,1,2,2,2]", "2"], ["[6,6,6,5,5,4]", "2"], ["[2,1,2,1,2,1,3]", "2"], ["[11,11,12,13,13,13]", "2"], ["[1,1,1,1,2,2,3]", "2"], ["[4,4,4,4,4,1]", "1"], ["[9,8,8,7,7,7]", "2"], ["[100,200,200,300,300,300]", "2"], ["[1,2,2,2,3,4,4]", "2"], ["[5,6,6,7,7,7,8]", "2"], ["[3,1,3,1,3,2]", "1"]], "expected": [[2, 1], [1], [2, -1], [6, 5], [0], [2, 3], [3, 4, 2], [8, 9], [-1, -2], [9], [1, 2, 3, 4], [3], [3], [7], [1, 3, 2], [-10000], [5, 4], [1, 3], [8, 9], [1, 2], [5, 6], [1, 2], [11, 13], [2, 1], [4], [8, 7], [200, 300], [4, 2], [6, 7], [3]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "707", "slug": "top-k-frequent-words", "id": 707, "title": "Top K Frequent Words", "difficulty": "Medium", "category": "heap", "link": "https://leetcode.com/problems/top-k-frequent-words/", "examples": [{"input": "words = [\"i\",\"love\",\"leetcode\",\"i\",\"love\",\"coding\"], k = 2", "output": "[\"i\",\"love\"]", "explanation": "\"i\" and \"love\" tie at 2 and are dictionary-ordered."}, {"input": "words = [\"the\",\"day\",\"is\",\"sunny\",\"the\",\"the\",\"the\",\"sunny\",\"is\",\"is\"], k = 4", "output": "[\"the\",\"is\",\"sunny\",\"day\"]", "explanation": "Frequencies 4, 3, 2, 1."}, {"input": "words = [\"a\",\"b\",\"c\",\"a\",\"b\",\"a\"], k = 1", "output": "[\"a\"]", "explanation": "\"a\" is most common."}], "hints": ["Count every word with a hash map first.", "Sort distinct words by falling frequency, using dictionary order to break ties, then take the first k.", "A heap can do this faster, but sorting is clear and easily fast enough for the limits."], "statement": "Given a word list `words` and a number `k`, return the `k` words that appear most often. Order the answer from highest frequency to lowest; when two words share the same count, the one that comes earlier in the dictionary goes first.\n\nAssume `k` is positive and never exceeds the number of distinct words.\n\n**Constraints:**\n- `1 <= words.length <= 500`\n- `1 <= words[i].length <= 10`\n- Words contain only lowercase letters.\n- `1 <= k <= distinct word count`\n", "solution": "## Approach\n\nTally each word's occurrences in a hash map. Collect the distinct words and sort them with a two-key comparison: higher frequency first, and dictionary order for equal frequencies. Returning the first `k` entries yields exactly the required ranking.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n), dominated by sorting the distinct words.\n- **Space Complexity:** O(n) for the frequency table.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import Counter\nclass Solution:\n def topKFrequent(self, words: List[str], k: int) -> List[str]:\n freq = Counter(words)\n ordered = sorted(freq.keys(), key=lambda w: (-freq[w], w))\n return ordered[:k]\n```\n", "starter": {"go": "package main\n\nfunc TopKFrequent(words []string, k int) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def topKFrequent(self, words: List[str], k: int) -> List[str]:\n return []\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> topKFrequent(vector<string>& words, int k) {\n return {};\n }\n};"}, "fn": "topKFrequent", "params": [{"name": "words", "type": "string_array"}, {"name": "k", "type": "int"}], "outputType": "string_list", "tests": [["['i', 'love', 'leetcode', 'i', 'love', 'coding']", "2"], ["['the', 'day', 'is', 'sunny', 'the', 'the', 'the', 'sunny', 'is', 'is']", "4"], ["['a', 'b', 'c', 'a', 'b', 'a']", "1"], ["['a']", "1"], ["['apple', 'banana', 'apple', 'banana', 'cherry']", "2"], ["['z', 'y', 'x', 'z', 'y', 'z']", "3"], ["['cat', 'dog', 'cat', 'bird', 'dog', 'cat']", "2"], ["['aa', 'bb', 'cc', 'dd']", "2"], ["['b', 'a', 'c', 'b', 'a', 'b']", "2"], ["['hello', 'hello', 'world']", "1"], ["['one', 'two', 'three', 'one', 'two', 'one']", "3"], ["['x', 'x', 'x', 'y', 'y', 'z']", "2"], ["['train', 'plane', 'train', 'car', 'plane', 'train']", "1"], ["['a', 'b', 'a', 'b', 'c', 'd']", "3"], ["['foo', 'bar', 'baz', 'foo', 'bar', 'foo']", "3"], ["['m', 'n', 'm', 'n', 'o', 'o']", "3"], ["['alpha', 'beta', 'gamma', 'alpha', 'beta', 'alpha']", "2"], ["['dog', 'cat', 'dog', 'cat', 'bird']", "1"], ["['a', 'a', 'b', 'b', 'c']", "2"], ["['word']", "1"], ["['aa', 'aa', 'ab', 'ab', 'ac']", "2"], ["['sun', 'moon', 'sun', 'star', 'moon', 'sun']", "2"], ["['p', 'q', 'r', 'p', 'q', 'p']", "3"], ["['red', 'blue', 'green', 'red', 'red', 'blue']", "2"], ["['a', 'b', 'c', 'd', 'e', 'a', 'b', 'a']", "3"], ["['test', 'test', 'quiz', 'quiz', 'exam']", "2"], ["['one', 'one', 'two']", "2"], ["['k', 'j', 'k', 'j', 'i']", "3"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "541", "slug": "total-hamming-distance", "id": 541, "title": "Total Hamming Distance", "difficulty": "Medium", "category": "binary", "link": "https://leetcode.com/problems/total-hamming-distance/", "examples": [{"input": "nums = [4,14,2]", "output": "6", "explanation": "Each pair differs in 2 bit slots, totalling 6."}, {"input": "nums = [4,14,4]", "output": "4", "explanation": "Equal entries contribute 0; each 4 vs 14 contributes 2."}, {"input": "nums = [1,2,3]", "output": "4", "explanation": "Pair gaps sum to 4."}], "hints": ["Handle each bit column on its own instead of each pair.", "If ones columns hold c ones among n numbers, that column adds c*(n-c).", "Thirty-one columns cover values up to 10^9."], "statement": "The *gap* between two integers is the number of bit slots where their binary forms differ. Given an array `nums`, add up that gap over every unordered pair of positions.\n\nReturn the total sum.\n\n**Constraints:**\n\n- `1 <= nums.length <= 10^4`\n- `0 <= nums[i] <= 10^9`\n- The total fits in a signed 32-bit integer.\n", "solution": "## Approach\n\nRather than comparing every pair, tally each binary column separately. For a fixed bit, suppose `c` of the `n` numbers have a 1 there; then exactly `c * (n - c)` pairs differ in that column. Adding this quantity over all 31 columns yields the total gap count.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(31 * n), linear in the array size.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def totalHammingDistance(self, nums: List[int]) -> int:\n n = len(nums)\n total = 0\n for bit in range(31):\n ones = sum(1 for v in nums if (v >> bit) & 1)\n total += ones * (n - ones)\n return total\n```\n", "starter": {"go": "package main\n\nfunc TotalHammingDistance(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def totalHammingDistance(self, nums: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int totalHammingDistance(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "totalHammingDistance", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[4,14,2]"], ["[4,14,4]"], ["[1,2,3]"], ["[0]"], ["[0,0,0]"], ["[1,1,1]"], ["[1,0]"], ["[0,1,2,3,4]"], ["[1000000000,0]"], ["[7,7,7,7]"], ["[1,2,4,8,16]"], ["[3,5,6]"], ["[10,20,30,40]"], ["[0,1000000000]"], ["[214748364,1073741823]"], ["[5,5,5,10,10]"], ["[1,3,5,7,9]"], ["[2,4,6,8]"], ["[0,0,1]"], ["[999999999,1000000000]"], ["[0,0,0,0]"], ["[1]"], ["[100,200,300]"], ["[7,0]"], ["[15,15,15,0]"], ["[8,8,8,8,8]"], ["[123456789,987654321]"], ["[0,1]"], ["[512,1024,2048]"], ["[999999999,999999999]"]], "expected": [6, 4, 4, 0, 0, 0, 1, 16, 13, 0, 20, 6, 18, 13, 16, 24, 16, 11, 2, 10, 0, 0, 12, 3, 12, 0, 15, 1, 6, 0], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "781", "slug": "transform-to-chessboard", "id": 781, "title": "Transform to Chessboard", "difficulty": "Hard", "category": "matrix", "link": "https://leetcode.com/problems/transform-to-chessboard/", "examples": [{"input": "board = [[\"0\",\"1\",\"1\",\"0\"],[\"0\",\"1\",\"1\",\"0\"],[\"1\",\"0\",\"0\",\"1\"],[\"1\",\"0\",\"0\",\"1\"]]", "output": "2", "explanation": "One row swap plus one column swap reaches an alternating board."}, {"input": "board = [[\"0\",\"1\"],[\"1\",\"0\"]]", "output": "0", "explanation": "Neighbors already alternate."}, {"input": "board = [[\"1\",\"0\"],[\"1\",\"0\"]]", "output": "-1", "explanation": "The first column cannot be made alternating."}], "hints": ["Every row must equal the first row or its exact opposite; the same holds for columns, otherwise return -1.", "Count ones in the first row and column: each must be n/2 or (n+1)/2.", "Mismatches against the two alternating edge patterns divided by two give row and column swaps; for odd n pick the pattern with an even mismatch count."], "statement": "You hold a square grid with `n` rows and `n` columns. Every cell shows one\nof two symbols, `0` or `1` (stored as single-character strings). In one step\nyou may exchange any two whole rows, or any two whole columns. The order of\ncells inside a row or column otherwise stays fixed.\n\nA finished board is called alternating when no two cells that touch\nsideways (up, down, left, right) hold the same symbol \u2014 the pattern must\nlook like a chessboard. Count the fewest row/column exchanges that turn the\ngiven board into an alternating one. When no sequence of swaps can do it,\nreport `-1`.\n\nNote on types: the grid arrives as characters `'0'` and `'1'`, not as\nnumbers, so compare symbols directly.\n\n**Constraints:**\n- `n == board.length`\n- `n == board[i].length`\n- `2 <= n <= 30`\n- `board[i][j]` is `\"0\"` or `\"1\"`.\n", "solution": "## Approach\n\nAn alternating board has only two distinct row shapes that oppose each\nother, and likewise for columns. First reject boards where any rectangle\ncorner breaks that rule or where the first row/column holds the wrong number\nof ones. Then compare the current first column and first row against the two\nideal alternating edges; each pair of misplaced lines costs one swap, so the\nmismatch count halved (taking the cheaper edge, or the parity-valid edge for\nodd sizes) gives the row and column moves.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) to scan the grid.\n- **Space Complexity:** O(1) besides the input.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def movesToChessboard(self, board: List[List[str]]) -> int:\n n = len(board)\n g = [[1 if c == '1' else 0 for c in row] for row in board]\n for i in range(n):\n for j in range(n):\n if (g[0][0] ^ g[i][0] ^ g[0][j] ^ g[i][j]) == 1:\n return -1\n row_ones = sum(g[0])\n col_ones = sum(g[i][0] for i in range(n))\n if row_ones not in (n // 2, (n + 1) // 2):\n return -1\n if col_ones not in (n // 2, (n + 1) // 2):\n return -1\n row_diff = sum(1 for i in range(n) if g[i][0] != i % 2)\n col_diff = sum(1 for j in range(n) if g[0][j] != j % 2)\n if n % 2 == 0:\n row_moves = min(row_diff, n - row_diff) // 2\n col_moves = min(col_diff, n - col_diff) // 2\n else:\n row_moves = (row_diff if row_diff % 2 == 0 else n - row_diff) // 2\n col_moves = (col_diff if col_diff % 2 == 0 else n - col_diff) // 2\n return row_moves + col_moves\n```\n", "starter": {"go": "package main\n\nfunc MovesToChessboard(board [][]byte) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def movesToChessboard(self, board: List[List[str]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int movesToChessboard(vector<vector<char>>& board) {\n return 0;\n }\n};"}, "fn": "movesToChessboard", "params": [{"name": "board", "type": "char_array_2d"}], "outputType": "int", "tests": [["[[\"0\",\"1\",\"1\",\"0\"],[\"0\",\"1\",\"1\",\"0\"],[\"1\",\"0\",\"0\",\"1\"],[\"1\",\"0\",\"0\",\"1\"]]"], ["[[\"0\",\"1\"],[\"1\",\"0\"]]"], ["[[\"1\",\"0\"],[\"1\",\"0\"]]"], ["[[\"1\",\"0\"],[\"0\",\"1\"]]"], ["[[\"0\",\"0\"],[\"0\",\"0\"]]"], ["[[\"1\",\"1\"],[\"1\",\"1\"]]"], ["[[\"0\",\"1\",\"0\"],[\"1\",\"0\",\"1\"],[\"0\",\"1\",\"0\"]]"], ["[[\"1\",\"0\",\"1\"],[\"0\",\"1\",\"0\"],[\"1\",\"0\",\"1\"]]"], ["[[\"0\",\"0\",\"0\"],[\"0\",\"0\",\"0\"],[\"0\",\"0\",\"0\"]]"], ["[[\"0\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"1\",\"0\"]]"], ["[[\"1\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"0\",\"1\"]]"], ["[[\"0\",\"1\",\"1\"],[\"1\",\"0\",\"0\"],[\"1\",\"0\",\"0\"]]"], ["[[\"1\",\"1\",\"0\"],[\"0\",\"0\",\"1\"],[\"1\",\"1\",\"0\"]]"], ["[[\"0\",\"1\",\"0\",\"1\",\"0\"],[\"1\",\"0\",\"1\",\"0\",\"1\"],[\"0\",\"1\",\"0\",\"1\",\"0\"],[\"1\",\"0\",\"1\",\"0\",\"1\"],[\"0\",\"1\",\"0\",\"1\",\"0\"]]"], ["[[\"0\",\"0\",\"1\",\"1\"],[\"0\",\"0\",\"1\",\"1\"],[\"1\",\"1\",\"0\",\"0\"],[\"1\",\"1\",\"0\",\"0\"]]"], ["[[\"1\",\"0\",\"0\"],[\"1\",\"0\",\"0\"],[\"0\",\"1\",\"1\"]]"], ["[[\"0\",\"1\"],[\"0\",\"1\"]]"], ["[[\"1\",\"1\",\"1\",\"0\"],[\"1\",\"1\",\"1\",\"0\"],[\"0\",\"0\",\"0\",\"1\"],[\"0\",\"0\",\"0\",\"1\"]]"], ["[[\"0\",\"0\",\"1\"],[\"1\",\"1\",\"0\"],[\"0\",\"0\",\"1\"]]"], ["[[\"1\",\"0\",\"1\",\"1\"],[\"1\",\"0\",\"1\",\"1\"],[\"0\",\"1\",\"0\",\"0\"],[\"0\",\"1\",\"0\",\"0\"]]"], ["[[\"0\",\"1\",\"0\"],[\"0\",\"1\",\"0\"],[\"1\",\"0\",\"1\"]]"], ["[[\"1\",\"1\",\"0\",\"0\",\"1\"],[\"1\",\"1\",\"0\",\"0\",\"1\"],[\"0\",\"0\",\"1\",\"1\",\"0\"],[\"0\",\"0\",\"1\",\"1\",\"0\"],[\"1\",\"1\",\"0\",\"0\",\"1\"]]"], ["[[\"0\",\"1\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"1\",\"0\",\"1\"]]"], ["[[\"1\",\"0\"],[\"0\",\"1\"]]"], ["[[\"0\",\"1\",\"0\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"1\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"0\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"1\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"0\",\"1\",\"0\",\"1\"],[\"1\",\"0\",\"1\",\"0\",\"1\",\"0\"]]"], ["[[\"1\",\"1\",\"0\"],[\"1\",\"1\",\"0\"],[\"1\",\"1\",\"0\"]]"], ["[[\"0\",\"0\"],[\"1\",\"1\"]]"], ["[[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"0\",\"1\",\"0\",\"1\",\"1\"],[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"0\",\"1\",\"0\",\"1\",\"1\"],[\"0\",\"1\",\"0\",\"1\",\"1\"]]"]], "expected": [2, 0, -1, 0, -1, -1, 0, 0, -1, 0, 0, 2, 1, 0, 2, 2, -1, -1, 1, -1, 1, 2, 1, 0, 0, -1, -1, 4], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "246", "slug": "transpose-matrix", "id": 246, "title": "Transpose Matrix", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/transpose-matrix/", "examples": [{"input": "matrix = [[1,2,3],[4,5,6],[7,8,9]]", "output": "[[1,4,7],[2,5,8],[3,6,9]]"}, {"input": "matrix = [[1,2,3],[4,5,6]]", "output": "[[1,4],[2,5],[3,6]]"}], "hints": ["The transpose of a matrix swaps rows and columns: result[j][i] = matrix[i][j].", "No special algorithm is needed; just build a result matrix with swapped dimensions."], "statement": "Take a 2D integer grid `matrix` and produce its mirrored form across the main diagonal.\n\nReflecting in this way exchanges the row and column positions of every entry.\n\n**Constraints:**\n\n- `m == matrix.length`\n- `n == matrix[i].length`\n- `1 <= m, n <= 1000`\n- `1 <= m * n <= 10^5`\n- `-10^9 <= matrix[i][j] <= 10^9`\n", "solution": "## Approach\n\nThe transpose of a matrix swaps its rows and columns. For an `m x n` matrix, the result is an `n x m` matrix where `result[j][i] = matrix[i][j]`. Create the result with swapped dimensions and fill it by iterating over every cell of the original matrix.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), where `m` is the number of rows and `n` is the number of columns. Every cell is visited once.\n- **Space Complexity:** O(m * n) for the output matrix (excluding the output, O(1) extra space).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def transpose(self, matrix: List[List[int]]) -> List[List[int]]:\n m, n = len(matrix), len(matrix[0])\n ans = [[0] * m for _ in range(n)]\n for i in range(m):\n for j in range(n):\n ans[j][i] = matrix[i][j]\n return ans\n```", "starter": {"go": "package main\n\nfunc Transpose(matrix [][]int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def transpose(self, matrix: List[List[int]]) -> List[List[int]]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> transpose(vector<vector<int>>& matrix) {\n \n }\n};"}, "fn": "transpose", "params": [{"name": "matrix", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[1,2,3],[4,5,6],[7,8,9]]"], ["[[1,2,3],[4,5,6]]"], ["[[5]]"], ["[[1,2],[3,4],[5,6]]"], ["[[1,2,3,4],[5,6,7,8]]"], ["[[1,2],[3,4]]"], ["[[9,8,7],[6,5,4]]"], ["[[1000000000,-1000000000],[1,-1]]"], ["[[1,2,3,4,5]]"], ["[[1],[2],[3]]"], ["[[1]]"], ["[[0]]"], ["[[-1000000000]]"], ["[[1,2,3,4,5,6]]"], ["[[1],[2],[3],[4]]"], ["[[2,2],[2,2]]"], ["[[0,0,0],[0,0,0]]"], ["[[-1,-2],[-3,-4],[-5,-6]]"], ["[[7,0],[0,7]]"], ["[[1,0,0],[0,1,0],[0,0,1]]"], ["[[3,1],[9,2],[5,5]]"], ["[[-5,10,15],[20,-25,30]]"], ["[[100,200],[300,400],[500,600]]"], ["[[1,2],[3,4],[5,6],[7,8]]"], ["[[9,9,9,9]]"], ["[[4],[3],[2],[1],[0]]"], ["[[0,1],[1,0]]"], ["[[-1000000000,1000000000]]"], ["[[6,7,8],[9,10,11]]"], ["[[13,14],[15,16],[17,18]]"]], "expected": [[[1, 4, 7], [2, 5, 8], [3, 6, 9]], [[1, 4], [2, 5], [3, 6]], [[5]], [[1, 3, 5], [2, 4, 6]], [[1, 5], [2, 6], [3, 7], [4, 8]], [[1, 3], [2, 4]], [[9, 6], [8, 5], [7, 4]], [[1000000000, 1], [-1000000000, -1]], [[1], [2], [3], [4], [5]], [[1, 2, 3]], [[1]], [[0]], [[-1000000000]], [[1], [2], [3], [4], [5], [6]], [[1, 2, 3, 4]], [[2, 2], [2, 2]], [[0, 0], [0, 0], [0, 0]], [[-1, -3, -5], [-2, -4, -6]], [[7, 0], [0, 7]], [[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[3, 9, 5], [1, 2, 5]], [[-5, 20], [10, -25], [15, 30]], [[100, 300, 500], [200, 400, 600]], [[1, 3, 5, 7], [2, 4, 6, 8]], [[9], [9], [9], [9]], [[4, 3, 2, 1, 0]], [[0, 1], [1, 0]], [[-1000000000], [1000000000]], [[6, 9], [7, 10], [8, 11]], [[13, 15, 17], [14, 16, 18]]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "481", "slug": "trapping-rain-water-ii", "id": 481, "title": "Trapping Rain Water II", "difficulty": "Hard", "category": "heap", "link": "https://leetcode.com/problems/trapping-rain-water-ii/", "examples": [{"input": "heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]", "output": "4", "explanation": "The central dip holds 4 units when water settles against the lowest rim."}, {"input": "heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]", "output": "10", "explanation": "The bowl interior traps 10 units below its rim of 3s."}, {"input": "heightMap = [[1,1,1],[1,1,1]]", "output": "0", "explanation": "A flat rim with no dip traps nothing."}], "hints": ["Think of water leaking out through the border: the lowest rim cell decides the level.", "Push every border cell into a min-heap and expand inward, always popping the lowest boundary first.", "When stepping to an inner cell, add max(0, boundary - its height) and push it back with the raised level."], "statement": "You are handed a grid `heightMap` where each entry gives the elevation of that cell. After rain, water pools in dips surrounded by higher ground and drains off any path that reaches the outer border.\n\nCompute the total volume of water that stays trapped once everything settles. Each cell holds water up to the lowest rim height reachable without crossing lower ground.\n\n**Constraints:**\n- `m == heightMap.length`, `n == heightMap[i].length`\n- `1 <= m, n <= 200`\n- `0 <= heightMap[i][j] <= 2 * 10^4`\n", "solution": "## Approach\n\nSeed a min-heap with every border cell and mark them visited; the heap always yields the lowest boundary seen so far. Repeatedly pop that boundary and inspect its four neighbours: any unvisited neighbour traps the gap between its height and the boundary, then joins the heap at the higher of the two levels. Because cells leave the heap in rising boundary order, each trapped amount is final.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(mn log(mn)) for heap operations over all cells.\n- **Space Complexity:** O(mn) for visited flags and the heap.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\n\nclass Solution:\n def trapRainWater(self, heightMap: List[List[int]]) -> int:\n if not heightMap or not heightMap[0]:\n return 0\n m, n = len(heightMap), len(heightMap[0])\n vis = [[False] * n for _ in range(m)]\n pq = []\n for i in range(m):\n heapq.heappush(pq, (heightMap[i][0], i, 0))\n vis[i][0] = True\n if n > 1:\n heapq.heappush(pq, (heightMap[i][n - 1], i, n - 1))\n vis[i][n - 1] = True\n for j in range(1, n - 1):\n heapq.heappush(pq, (heightMap[0][j], 0, j))\n vis[0][j] = True\n if m > 1:\n heapq.heappush(pq, (heightMap[m - 1][j], m - 1, j))\n vis[m - 1][j] = True\n water = 0\n while pq:\n h, x, y = heapq.heappop(pq)\n for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n nx, ny = x + dx, y + dy\n if nx < 0 or nx >= m or ny < 0 or ny >= n or vis[nx][ny]:\n continue\n vis[nx][ny] = True\n water += max(0, h - heightMap[nx][ny])\n heapq.heappush(pq, (max(h, heightMap[nx][ny]), nx, ny))\n return water\n```\n", "starter": {"go": "package main\n\nfunc TrapRainWater(heightMap [][]int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def trapRainWater(self, heightMap: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int trapRainWater(vector<vector<int>>& heightMap) {\n return 0;\n }\n};"}, "fn": "trapRainWater", "params": [{"name": "heightMap", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]"], ["[[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]"], ["[[1,1,1],[1,1,1]]"], ["[[5]]"], ["[[1]]"], ["[[0,0,0],[0,0,0],[0,0,0]]"], ["[[5,5,5],[5,1,5],[5,5,5]]"], ["[[5,5,5,5],[5,0,0,5],[5,0,0,5],[5,5,5,5]]"], ["[[3,3,3],[3,0,3],[3,3,3]]"], ["[[1,2,3],[4,5,6]]"], ["[[12,13,1,12],[13,4,13,12],[13,8,10,12],[12,13,12,12],[13,13,13,13]]"], ["[[2,2,2],[2,1,2],[2,2,2]]"], ["[[9,9,9,9],[9,0,0,9],[9,0,0,9],[9,9,9,9]]"], ["[[1,4,3],[3,2,1],[2,3,3]]"], ["[[5,8,7,7],[5,2,1,5],[7,1,7,1],[8,9,6,9],[9,8,9,9]]"], ["[[0,1,0,2,1,0],[1,0,1,0,1,0]]"], ["[[3,2,1],[1,0,1],[2,1,0]]"], ["[[4,4,4],[4,4,4],[4,4,4]]"], ["[[10,10,10],[10,0,10],[10,10,10]]"], ["[[1,2],[3,4]]"], ["[[7,7,7],[7,6,7],[7,7,7]]"], ["[[2,3,4],[7,6,5],[9,8,7]]"], ["[[5,5,5,5,5],[5,1,1,1,5],[5,1,0,1,5],[5,1,1,1,5],[5,5,5,5,5]]"], ["[[0,2,0],[2,0,2],[0,2,0]]"], ["[[8,8,8],[8,1,8]]"], ["[[1,3,2,4],[5,6,1,2],[4,2,3,1]]"]], "expected": [4, 10, 0, 0, 0, 0, 4, 20, 3, 0, 14, 1, 36, 0, 12, 0, 1, 0, 10, 0, 1, 0, 37, 2, 0, 1], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "78", "slug": "trapping-rain-water", "id": 78, "title": "Trapping Rain Water", "difficulty": "Hard", "category": "two-pointer", "link": "https://leetcode.com/problems/trapping-rain-water/", "examples": [{"input": "height = [0,1,0,2,1,0,1,3,2,1,2,1]", "output": "6", "explanation": "The total water trapped is 6 units."}, {"input": "height = [4,2,0,3,2,5]", "output": "9", "explanation": "The total water trapped is 9 units."}, {"input": "height = [1,2,3,4]", "output": "0", "explanation": "The total water trapped is 0 units."}], "hints": ["Water above a bar is limited by the smaller maximum boundary on its left and right.", "With two pointers, the side with the lower current boundary can be finalized immediately."], "statement": "Picture a skyline of `n` upright columns, each of width `1`, whose elevations are\nlisted in `height`. After a rainfall, liquid settles in the dips between columns.\nDetermine the total volume held in those dips.\n\n**Constraints:**\n\n- `1 <= height.length <= 20000`\n- `0 <= height[i] <= 100000`\n", "solution": "## Approach\n\nUse pointers at both ends while tracking the highest wall seen from each side.\nThe side with the lower current height has a known limiting boundary, so its\ntrapped water can be added before moving that pointer inward.\n\n## Complexity Analysis\n\n- **Time Complexity:** `O(n)`.\n- **Space Complexity:** `O(1)`.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def trap(self, height: List[int]) -> int:\n left, right = 0, len(height) - 1\n left_max = right_max = water = 0\n while left < right:\n if height[left] <= height[right]:\n left_max = max(left_max, height[left])\n water += left_max - height[left]\n left += 1\n else:\n right_max = max(right_max, height[right])\n water += right_max - height[right]\n right -= 1\n return water\n```\n", "starter": {"go": "package main\n\nfunc Trap(height []int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def trap(self, height: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int trap(vector<int>& height) {\n return 0;\n }\n};"}, "fn": "trap", "params": [{"name": "height", "type": "int_array"}], "outputType": "int", "tests": [["[0]"], ["[5]"], ["[0,0]"], ["[3,0,3]"], ["[0,1,0,2,1,0,1,3,2,1,2,1]"], ["[4,2,0,3,2,5]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[5,0,0,0,5]"], ["[5,5,5,5]"], ["[2,0,2,0,2]"], ["[100000,0,100000]"], ["[0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9]"], ["[100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]"], ["[23,30,10,2,9,23,9,3,18,2,7,9,26,7,5,17,16,17,12,13,8,1,17,21,3,26,10,1,21,11,21,3,18,29,25,20,21,12,27,4,7,15,22,13,21,12,13,23,30,17]"], ["[14,17,10,16,25,24,9,0,23,26,6,19,2,21,1]"], ["[20,26,22,9,27,2,6,24,18,12,15,29,18,17,30,13,20,27,7,22,13]"], ["[10,24,6,27,7,9,4,22,9,8,11,12,5,9,23,2,7,28,16,20,19,30,23,14,4,13,2,17,4,22,26,26,9,17,13,18]"], ["[14,1,6,27,3,17,9,27,15,9,14,14,15,15,25,19,10,26,22,19,26,23,28,26,15,20,12,12,28,15,2,18,17,22,19,3,2,22,24,12]"], ["[25,27,10,22,5,9,21,20,25,6,28,15,21,23,30,16,5,8,8,10,15,19,19,7,24,5,9,1,9,25,2,19,30,11,27,29,12,2,19,24,8,15,23,4,7,27,9,1,7,1,4,22,17,10,23,10]"], ["[0,25,23,7,30,17,22,14,26,18,17,16,5,30,19,12,4,20,1,18,3,12,9,13,10,2,16,30,22,11,4,23,23,4,28,1,22,9,14,29,5,16,23,18,5,20,20]"], ["[4,12,17,24,14,16,13,14,4,2,3,29,23,2,8,14,7,20,26,22,15,1,12,3,2,10,15,8,18,5,21,26,22,24,16,14,15,3,29,5,15,11,15,29]"], ["[11,16,17,23,4,26,30,15,10,2,27,21,7,13,16,27,20,18,15,25,23,4,26,3,23,19,8,6,7,0,11,22,25,1,3,25,0,25,0,12,8,17,2,17,1,15,11,1,22,21,25,29]"], ["[25,16,6,26,23,26,30,25,27,19,26,8,12,7,12,10,27,18,4,7,1,19,19,4,28,21,4,22,27,2]"], ["[20,10,28,13,3,23,27,9,25,4,9,4,8,11,4,9,13,8,26,8,13,11,18,18,7,29,17,28,7,27]"], ["[10,21,25,20,5,8,17,6,9,12,26,4,6,23,1,2,9,12,29,27,2,22,11,28,10,27,20,6,1,26,30,15,2,15,15,11,25,27,30,1,8,5,19,20,14,23,30,19,4,30,22,27,30,8,12,1,7]"], ["[27,27,19,7,28,15,25,22,2,27,15,28,22,19,23,18,30,16,8,28,24,1,27,9,0,4,23,28,25,24,14,24,8,23,6]"], ["[15,30,8,5,19,27,29,4,11,5,26,13,3,22,24,15,16,28,25,4,18,1,9,1,23,22,14,24,15,4,23,8,30,8,30,20,17,8,5,15,27,24,24,5,15,3,26,11,22,23,25]"], ["[6,25,8,18,6,28,25,21,16,12,28,10,25,4,14,27,8,28,12,30,27,2]"], ["[27,24,14,3,23,25,8,22,5,14,28,1,5,29,29,16,2,27,5,12,20,28,5,21,29,27,24,7,23,26,8,19,29,28,22,12,23,3,30,6,23,21,27]"], ["[21,15,4,30,18,3,23,26,30,11,4,22,18,19,29,20,20,20,30,15,18,7,7,26]"], ["[17,18,16,15,25,11,5]"], ["[4,29,14,22,5,26,10,8,22,23,18,6,29,13,23,6,25]"], ["[20,19,16,23,24,4,30,4,1,0,4,26,8,5,9,6,13,12]"], ["[6,30,19,22,24,20,21,24,15,11,10,26,27,10,1]"], ["[25,2,4,11,10,21,17,5,1,9,2,24,7,18,4,16,6,22,15,9,6,11,6,9,7,25,20,20,9,9,25,24,11,16,3,24,6,7,16,24,23,11]"], ["[20,0,25,5,10,28,9,21,3,1,4,29,4,30,25,6,16,25,10,7,19,23,27,25,0]"], ["[17,14,6,27,6,18,7,30,23,28,4,1,4,23,22,8,30,11,1,4,17,17,27,1,27,9,1,11,17,16,19,24,30,1,23,1,20,21,7,7,21,23,11,14,22,30,5]"], ["[18,21,3,3,30,7,20,30,12,14,8,23,20,3]"], ["[19,24,22,7,14,25,6,19,19,2,12,3,6,29,23,25,6,28,12,20,7,27,28,1,11,23,23,25,3,6,1,23,16]"], ["[14,25,25,8,21,27,30,27,8,7,6,1,18,10,9,10,23,19,3,29,25,11,10,10,28,15,9,9,13,13,18,20,23,27,16,26,7,19]"], ["[26,3,17,17,20,30,18,17,2,24,1,12,26,30,22,23,9,0]"], ["[26,14,22,10,7,15,18,1,14,23,19,18,26,27,15,16,12,11,16,1,8,10,16,9,23,19,30,29]"], ["[26,29,1,9,8]"], ["[20,21,27,23,16,30,5,1,5,17,4,14,20,0,17,29,2,20,4,5,0,24,17,21,12,26,29,25,7,11,26,4,13,11]"], ["[8,20,4,1,11,0,19,6,19,30,18,17,25,20,16,3,1,8,10,13,28,2,24,2,17,29,1,16,3,19,0,25,2,30,15,13,0,27,12,1,1,14,11,7]"], ["[2,3,25,7,8,10,0,19,30,6,0,21,17,3,1,1,16,28,14,11,12,5,27,29,2,7,20,15,7,30,12,16,25,2,21,7,21,17,29,22,7,3,24,5,27,15,10,6,27,25,30,3]"], ["[24,21,21]"], ["[15,17,10,10,22,28,6,21,5,30,13,17,0,11,16,19,8,22,17,0,1,23,10,19,8,2,24,17,20,4,9,19,16,21,7,22,1,2,23,25,29,12,14,0,20]"], ["[24,9,29,24,30,2,0,26,9,4,8,28,8,19,18,16,12,30,29,30,18,8,21,7,17,24,12,4,15,20,25,21,28,9,24,22,4]"], ["[9,18,25,4,11,27,10,29,3,15,8,12,7,28,19,8,5,13,15,7,2,18,18,10,12,6,0,9,9,28,2,4,7,8,22,8,17,2,27,2,25,25,19,26,0]"], ["[19,13,9,15,28,8]"], ["[7,29,11,24,25,14,11,8,1,28,11,5,10,6,0,24,5,22,20,17,0,22,13,4,3,22,19,24,6,24,13,13,8,20,5,6,0,18,17,10,5,26,3,3,21,29]"], ["[1,25,5,2,0,10,19,7,7,21,19,0,15,4,17,6,28,26,10,12,30,27]"], ["[14,8,12,28]"], ["[14,20,11,18,8,19,29,21,10,1,17,8,1,21,15,5,6,17,17,28,27,26,3,13,16,20,27,28,30,10,14,28,25,11,3,15,22,28,16,14,4,0,25,12,21,6,2,30,26,16]"], ["[17,6,30,15,19,11,5,1,4,11,27,21,20]"], ["[4,29,4,14,14,28,6,20,26,26,27,28,15,25,22,20,5,28,3,10,16,24,25,30,27,23,15,10,10,3,8,11,18,19,3]"], ["[16,15,14,25,13,24,15,26,2,19,22,19,9,10,10,12,0,20,25,25,11,6,30,1,0,29,0,19,12,23,21,1,21,9,0,24,26,13,4,15,27,26,26,24,8,30,14]"], ["[16,21,5,25,29,19,14,16,27,0,5,4,9,17,11,18,11]"], ["@javascript:JSON.stringify([100000,...Array(19998).fill(0),100000])"]], "expected": [0, 0, 0, 3, 6, 9, 0, 0, 15, 0, 4, 100000, 855, 10000, 750, 88, 165, 394, 350, 694, 576, 574, 696, 296, 386, 640, 285, 624, 177, 437, 237, 5, 169, 144, 78, 485, 267, 628, 104, 314, 402, 158, 293, 8, 396, 552, 718, 0, 574, 390, 595, 20, 700, 254, 8, 590, 134, 281, 531, 110, 1999800000], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "297", "slug": "triangle", "id": 297, "title": "Triangle", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/triangle/", "examples": [{"input": "triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]", "output": "11", "explanation": "One cheapest route is 2 -> 3 -> 5 -> 1, which sums to 11."}, {"input": "triangle = [[-10]]", "output": "-10", "explanation": "A single row forces that value."}], "hints": ["Work bottom-up: each cell adds its value to the smaller of its two children.", "You can reuse the bottom row as the DP array for O(n) extra space.", "A top-down memo on (row, index) also works."], "statement": "Given a triangular array `triangle` where `triangle[i]` holds `i + 1` numbers, start at the top element and move down one step at a time.\n\nFrom position `i` in the current row you may step to position `i` or position `i + 1` in the row below. Each visited cell contributes its value to the total.\n\nReturn the smallest possible total from the top to any bottom-row cell.\n\n**Constraints:**\n- `1 <= triangle.length <= 200`\n- `triangle[0].length == 1`\n- `triangle[i].length == triangle[i-1].length + 1`\n- `-10^4 <= triangle[i][j] <= 10^4`\n\n**Adaptation note:** The original LeetCode signature uses `List<List<Integer>>`. Here the input is `int[][]` (`int_array_2d`) with identical layout.\n", "solution": "## Approach\n\nCollapse the triangle from the bottom up. The cheapest cost of reaching the bottom from cell `(i, j)` equals its own value plus the smaller of the two reachable cells below it. Processing rows in reverse turns the bottom row into the initial DP state, then each higher row overwrites it in place.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), where n is the number of rows. Each cell is visited once.\n- **Space Complexity:** O(n) for the one-dimensional DP array.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minimumTotal(self, triangle: List[List[int]]) -> int:\n dp = [0] * (len(triangle) + 1)\n for i in range(len(triangle) - 1, -1, -1):\n for j in range(len(triangle[i])):\n dp[j] = triangle[i][j] + min(dp[j], dp[j + 1])\n return dp[0]\n```\n", "starter": {"go": "package main\n\nfunc MinimumTotal(triangle [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def minimumTotal(self, triangle: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n return 0;\n }\n};"}, "fn": "minimumTotal", "params": [{"name": "triangle", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]]"], ["[[-10]]"], ["[[1], [2, 3]]"], ["[[-1], [2, 3], [1, -1, -3]]"], ["[[5], [9, 6], [4, 6, 8], [0, 7, 1, 5]]"], ["[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]"], ["[[0], [0, 0], [0, 0, 0]]"], ["[[-1], [-2, -3]]"], ["[[10], [5, 15], [20, 1, 2]]"], ["[[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]]"], ["[[1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15]]"], ["[[-5], [-1, -2], [-3, -4, -5], [-9, -8, -7, -6]]"], ["[[10000], [10000, 10000], [10000, 10000, 10000]]"], ["[[-10000], [10000, -10000]]"], ["[[2], [3, 4]]"], ["[[0]]"], ["[[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]]"], ["[[1], [-2, 3], [4, -5, 6], [-7, 8, -9, 10]]"], ["[[4], [1, 2], [1, 1, 1], [1, 1, 1, 1], [2, 1, 1, 1, 1]]"], ["[[-2], [-3, -4], [-5, -6, -7], [-8, -9, -10, -11]]"], ["[[9], [8, 7], [6, 5, 4], [3, 2, 1, 0]]"], ["[[1], [10, 1], [1, 1, 10], [10, 1, 1, 1]]"], ["[[-3], [4, -2], [1, 8, -5], [2, 3, 4, 5], [9, 8, 7, 6, 5]]"], ["[[6], [2, 1], [3, 9, 4], [5, 2, 7, 8], [1, 3, 2, 4, 6], [7, 8, 9, 1, 2, 3]]"], ["[[1], [2, 3], [3, 2, 1]]"], ["[[-1], [0, 0], [0, 1, 0], [1, 0, 0, 1]]"], ["[[5], [4, 3], [2, 1, 0], [-1, -2, -3, -4]]"], ["[[8], [7, 6], [5, 4, 3], [2, 1, 0, -1], [-2, -3, -4, -5, -6]]"]], "expected": [11, -10, 3, -1, 18, 4, 0, -4, 16, 16, 25, -19, 30000, -20000, 5, 0, 17, -15, 8, -24, 20, 4, 0, 16, 5, -1, 4, 10], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "688", "slug": "trim-a-binary-search-tree", "id": 688, "title": "Trim a Binary Search Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/trim-a-binary-search-tree/", "examples": [{"input": "root = [1,0,2], low = 1, high = 2", "output": "[1,null,2]", "explanation": "The node 0 falls below the kept interval and is dropped; its parent links directly to the surviving right child."}, {"input": "root = [3,0,4,null,2,null,null,1], low = 1, high = 3", "output": "[3,2,null,1]", "explanation": "Values outside [1,3] are removed while the relative order of the survivors is preserved."}, {"input": "root = [], low = 1, high = 2", "output": "[]"}], "hints": ["Use the ordering guarantee: when the current value is too small the whole left subtree can be skipped.", "When the current value is too large the whole right subtree can be skipped.", "Otherwise trim both sides recursively and reattach them."], "statement": "You are given the root of a binary search tree plus two bounds `low` and `high`.\n\nWalk the tree and drop every node whose value lies outside the closed interval `[low, high]`. Keep the search-tree ordering among the survivors and return the root of the trimmed tree. An empty result is represented by an empty tree.\n\n**Constraints:**\n- The tree holds between 0 and 10000 nodes.\n- Node values and `low`/`high` fit in 32-bit signed integers, with `low <= high`.\n", "solution": "## Approach\n\nRecurse on the tree. An empty spot stays empty. If the current value is below `low`, the entire left subtree is also too small, so return the trimmed right child. Symmetrically, if it is above `high`, return the trimmed left child. Otherwise the node survives: trim both children and reattach them.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), each node is visited once.\n- **Space Complexity:** O(h) recursion depth, where h is the tree height.\n\n## Implementation\n\n```python\nclass Solution:\n def trimBST(self, root, low: int, high: int):\n if not root:\n return None\n if root.val < low:\n return self.trimBST(root.right, low, high)\n if root.val > high:\n return self.trimBST(root.left, low, high)\n root.left = self.trimBST(root.left, low, high)\n root.right = self.trimBST(root.right, low, high)\n return root\n```\n", "starter": {"go": "package main\n\n// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\n\nfunc TrimBST(root *TreeNode, low int, high int) *TreeNode {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def trimBST(self, root, low: int, high: int):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n TreeNode* trimBST(TreeNode* root, int low, int high) {\n return nullptr;\n }\n};"}, "fn": "trimBST", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "low", "type": "int"}, {"name": "high", "type": "int"}], "outputType": "tree_node", "tests": [["[1,0,2]", "1", "2"], ["[3,0,4,null,2,null,null,1]", "1", "3"], ["[]", "1", "2"], ["[1]", "1", "1"], ["[1,null,2]", "1", "2"], ["[1,null,2]", "2", "2"], ["[3,1,4,null,2]", "2", "4"], ["[5,3,6,2,4,null,7]", "3", "6"], ["[5,3,6,2,4,null,7]", "0", "10"], ["[5,3,6,2,4,null,7]", "5", "5"], ["[1,0,2]", "0", "0"], ["[1,0,2]", "3", "5"], ["[4,2,6,1,3,5,7]", "2", "6"], ["[4,2,6,1,3,5,7]", "4", "4"], ["[10,5,15,3,7,null,18]", "7", "15"], ["[10,5,15,3,7,null,18]", "6", "10"], ["[3,2,null,1]", "1", "3"], ["[3,2,null,1]", "2", "2"], ["[2,1,3]", "1", "1"], ["[2,1,3]", "3", "3"], ["[5,null,9,8,null,null,10]", "8", "10"], ["[1,null,2,null,3,null,4]", "2", "3"], ["[4,null,5,null,6]", "1", "4"], ["[0,-10,10,null,-5,null,20]", "-5", "10"], ["[100,50,150,25,75,125,175]", "60", "160"], ["[2,null,3,null,4,null,5]", "3", "5"], ["[5,4,null,3,null,2]", "2", "4"], ["[1,0,2,0,null,null,3]", "1", "3"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "965", "slug": "triples-with-bitwise-and-equal-to-zero", "id": 965, "title": "Triples With Bitwise AND Equal To Zero", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/triples-with-bitwise-and-equal-to-zero/", "examples": [{"input": "nums = [2,1,3]", "output": "12", "explanation": "Twelve ordered index triples have a combined bitwise AND of zero."}, {"input": "nums = [0,0,0]", "output": "27", "explanation": "Every one of the 3*3*3 triples qualifies because 0 AND 0 AND 0 is 0."}], "hints": ["Precompute frequencies of all pairwise AND results; there are at most 2^16 distinct values.", "For each pair value p and each element x, the triple qualifies exactly when (p AND x) == 0.", "Multiply pair frequencies by matching third elements instead of enumerating all n^3 triples."], "statement": "Given an integer array `nums`, count ordered triples of indices `(i, j, k)` with `0 <= i, j, k < nums.length` such that `nums[i] AND nums[j] AND nums[k] == 0`. The bitwise AND combines all three values. Indices may repeat, and different index orders count separately.\n\n**Constraints:**\n- `1 <= nums.length <= 500`\n- `0 <= nums[i] < 2^16`\n", "solution": "## Approach\n\nFirst tabulate how often each pairwise AND value occurs by combining every pair of entries. Then, for each distinct pair value p with frequency c and each array element x, the triples extending that pair qualify exactly when p AND x is zero, contributing c to the answer. This replaces the cubic enumeration with a quadratic plus distinct-times-linear pass.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2 + d*n), where n is the array length and d is the number of distinct pair ANDs (at most 2^16).\n- **Space Complexity:** O(d) for the pair frequency table.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import Counter\nclass Solution:\n def countTriplets(self, nums: List[int]) -> int:\n pair = Counter()\n for a in nums:\n for b in nums:\n pair[a & b] += 1\n ans = 0\n for p, c in pair.items():\n for x in nums:\n if p & x == 0:\n ans += c\n return ans\n```\n", "starter": {"go": "package main\n\nfunc CountTriplets(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def countTriplets(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\n#include <unordered_map>\nusing namespace std;\nclass Solution {\npublic:\n int countTriplets(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "countTriplets", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[2,1,3]"], ["[0,0,0]"], ["[1]"], ["[0]"], ["[1,1,1]"], ["[7,7,7]"], ["[1,2,4]"], ["[3,5,7]"], ["[0,1]"], ["[8,4,2,1]"], ["[15,15,0]"], ["[255,255]"], ["[1,2,3,4,5]"], ["[0,0,1]"], ["[6,5,4,3,2,1]"], ["[1023,512,256]"], ["[7,0,7]"], ["[2,4,8,16]"], ["[31,31,31]"], ["[1,3,5,7,9]"], ["[0,7,7]"], ["[12,5,9,3]"], ["[100,200,300]"], ["[65535]"], ["[0,65535]"], ["[1,2]"], ["[4,4,0]"], ["[9,8,7,6,5,4]"]], "expected": [12, 27, 0, 1, 0, 0, 24, 0, 7, 60, 19, 0, 84, 26, 138, 12, 19, 60, 0, 0, 19, 24, 6, 0, 7, 6, 19, 126], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "77", "slug": "two-sum-ii-input-array-is-sorted", "id": 77, "title": "Two Sum II - Input Array Is Sorted", "difficulty": "Medium", "category": "two-pointer", "link": "https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/", "examples": [{"input": "numbers = [2,7,11,15], target = 9", "output": "[1,2]", "explanation": "The values at 1-based indices 1 and 2 sum to 9."}, {"input": "numbers = [2,3,4], target = 6", "output": "[1,3]", "explanation": "numbers[0] + numbers[2] = 2 + 4 = 6. Return 1-indexed [1,3]."}, {"input": "numbers = [-1,0], target = -1", "output": "[1,2]", "explanation": "numbers[0] + numbers[1] = -1 + 0 = -1. Return 1-indexed [1,2]."}], "hints": ["Place one pointer at each end of the sorted array.", "Move the left pointer when the sum is too small and the right pointer when it is too large."], "statement": "You receive `numbers`, a 1-indexed integer list already arranged from smallest\nto largest, plus a `target` value. Identify two separate entries that add to\n`target`.\n\nGive back the pair as `[index1, index2]` with\n`1 <= index1 < index2 <= numbers.length`. Each test case contains exactly one\nvalid pair, and no entry may be paired with itself.\n\n**Constraints:**\n\n- `2 <= numbers.length <= 30000`\n- `-1000 <= numbers[i] <= 1000`\n- `-1000 <= target <= 1000`\n- `numbers` is sorted in non-decreasing order.\n- There is exactly one valid pair.\n", "solution": "## Approach\n\nPlace one pointer at each end of the sorted array. If their sum is too small,\nmove the left pointer right; if it is too large, move the right pointer left.\nReturn the required 1-based indices when the unique target pair is found.\n\n## Complexity Analysis\n\n- **Time Complexity:** `O(n)`.\n- **Space Complexity:** `O(1)` excluding the returned array.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:\n left, right = 0, len(numbers) - 1\n while left < right:\n total = numbers[left] + numbers[right]\n if total == target:\n return [left + 1, right + 1]\n if total < target:\n left += 1\n else:\n right -= 1\n return []\n```\n", "starter": {"go": "package main\n\nfunc TwoSum(numbers []int, target int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def twoSum(self, numbers: List[int], target: int) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> twoSum(vector<int>& numbers, int target) {\n return {};\n }\n};"}, "fn": "twoSum", "params": [{"name": "numbers", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int_array", "tests": [["[2,7,11,15]", "9"], ["[2,3,4]", "6"], ["[-1,0]", "-1"], ["[0,0,3,4]", "0"], ["[-500,-500,0]", "-1000"], ["[-1000,-500,0,500,1000]", "-1000"], ["[-500,-499,-498,-497,-496,-495,-494,-493,-492,-491,-490,-489,-488,-487,-486,-485,-484,-483,-482,-481,-480,-479,-478,-477,-476,-475,-474,-473,-472,-471,-470,-469,-468,-467,-466,-465,-464,-463,-462,-461,-460,-459,-458,-457,-456,-455,-454,-453,-452,-451,-450,-449,-448,-447,-446,-445,-444,-443,-442,-441,-440,-439,-438,-437,-436,-435,-434,-433,-432,-431,-430,-429,-428,-427,-426,-425,-424,-423,-422,-421,-420,-419,-418,-417,-416,-415,-414,-413,-412,-411,-410,-409,-408,-407,-406,-405,-404,-403,-402,-401,-400,-399,-398,-397,-396,-395,-394,-393,-392,-391,-390,-389,-388,-387,-386,-385,-384,-383,-382,-381,-380,-379,-378,-377,-376,-375,-374,-373,-372,-371,-370,-369,-368,-367,-366,-365,-364,-363,-362,-361,-360,-359,-358,-357,-356,-355,-354,-353,-352,-351,-350,-349,-348,-347,-346,-345,-344,-343,-342,-341,-340,-339,-338,-337,-336,-335,-334,-333,-332,-331,-330,-329,-328,-327,-326,-325,-324,-323,-322,-321,-320,-319,-318,-317,-316,-315,-314,-313,-312,-311,-310,-309,-308,-307,-306,-305,-304,-303,-302,-301,-300,-299,-298,-297,-296,-295,-294,-293,-292,-291,-290,-289,-288,-287,-286,-285,-284,-283,-282,-281,-280,-279,-278,-277,-276,-275,-274,-273,-272,-271,-270,-269,-268,-267,-266,-265,-264,-263,-262,-261,-260,-259,-258,-257,-256,-255,-254,-253,-252,-251,-250,-249,-248,-247,-246,-245,-244,-243,-242,-241,-240,-239,-238,-237,-236,-235,-234,-233,-232,-231,-230,-229,-228,-227,-226,-225,-224,-223,-222,-221,-220,-219,-218,-217,-216,-215,-214,-213,-212,-211,-210,-209,-208,-207,-206,-205,-204,-203,-202,-201,-200,-199,-198,-197,-196,-195,-194,-193,-192,-191,-190,-189,-188,-187,-186,-185,-184,-183,-182,-181,-180,-179,-178,-177,-176,-175,-174,-173,-172,-171,-170,-169,-168,-167,-166,-165,-164,-163,-162,-161,-160,-159,-158,-157,-156,-155,-154,-153,-152,-151,-150,-149,-148,-147,-146,-145,-144,-143,-142,-141,-140,-139,-138,-137,-136,-135,-134,-133,-132,-131,-130,-129,-128,-127,-126,-125,-124,-123,-122,-121,-120,-119,-118,-117,-116,-115,-114,-113,-112,-111,-110,-109,-108,-107,-106,-105,-104,-103,-102,-101,-100,-99,-98,-97,-96,-95,-94,-93,-92,-91,-90,-89,-88,-87,-86,-85,-84,-83,-82,-81,-80,-79,-78,-77,-76,-75,-74,-73,-72,-71,-70,-69,-68,-67,-66,-65,-64,-63,-62,-61,-60,-59,-58,-57,-56,-55,-54,-53,-52,-51,-50,-49,-48,-47,-46,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500]", "999"], ["[-462,-431,-413,-314,-244,-242,-179,-137,-113,-30,73,127,243,315,362,365,412,435]", "98"], ["[-487,-307,-139,-60,1,7,56,87,156,242,263,304,308]", "311"], ["[-431,-403,-384,128,395]", "-275"], ["[-370,-369,-279,-243,-183,-143,-59,72,110,122,194,252,313]", "435"], ["[-426,-287,-96,45,298]", "-242"], ["[-401,320,373,438,458]", "758"], ["[-481,-435,-374,-347,-176,-146,-42,8,59,130,180,184,266]", "-305"], ["[-493,-480,-461,-429,-253,-157,-25,25,137,206,255,323,453]", "98"], ["[-455,-360,-353,-347,-302,-211,-203,-176,-102,-66,-24,55,206,236,320,323,326,348,352,413,458]", "-414"], ["[-264,19,213,413,467]", "486"], ["[-416,-360,-281,-272,-118,-12,-2,18,76,94,150,219,241,249,279,307,349,361,451,453,489]", "610"], ["[-461,-421,-377,-294,-262,-194,-165,-139,-117,-75,74,81,195,205,215,255,257,372,409,456,499]", "297"], ["[-487,-445,-338,-316,-303,-139,-50,-4,113,131,247,279,395]", "-332"], ["[-463,-427,-337,-308,-269,-185,-145,-123,-121,-97,-50,-14,55,77,133,152,199,200,220,273,383]", "277"], ["[-470,-462,-405,-270,-251,108,116,141,204,393,413,465,470]", "501"], ["[-462,-385,-323,-295,-110,-77,-52,112,125,234,365,373,484]", "-260"], ["[-302,-198,-132,86,217]", "-112"], ["[-398,-380,-313,-17,466]", "86"], ["[-431,110,159,329,483]", "439"], ["[-387,-331,-195,265,375]", "-66"], ["[-492,-475,-428,-355,-350,-291,-263,-157,-156,-73,66,85,136,202,246,285,286,343,346,371,493]", "548"], ["[-426,-316,-200,-126,-37,208,252,254,354,440,457,479,500]", "854"], ["[-448,-436,-388,-298,-281,-280,-220,-189,-77,79,177,265,326,339,341,384]", "-266"], ["[-367,-163,157,207,244,275,368,460,463]", "44"], ["[-486,-440,-417,-366,-358,-339,-299,-156,-122,-96,11,408,481]", "-495"], ["[-478,-361,-360,-221,-198,-187,-125,-102,-96,-50,67,108,118,198,348,383,399,409,414,427,449]", "546"], ["[-426,-349,-248,-158,-140,-7,61,178,358,365,399,405,430]", "-597"], ["[-482,-472,-392,-385,-382,-93,-57,1,66,76,95,103,110,124,147,246,313,324,331,450,476]", "322"], ["[-474,-370,-337,-241,-18,125,180,182,274,293,307,366,433]", "726"], ["[-337,-234,-73,-13,9,24,65,86,160,347,376,425,434]", "781"], ["[-470,-441,-406,-348,-314,-248,-234,-202,0,15,41,335,409]", "-482"], ["[-356,-291,-22,71,280]", "-11"], ["[-270,-240,-210,-161,-119,-88,70,131,153,283,436,470,477]", "719"], ["[-473,-450,-421,-340,-313,-303,-244,-242,-184,-167,-157,-144,-102,-64,-38,-34,37,76,167,260,295]", "-227"], ["[-483,-373,-361,-294,-280,-272,-250,-184,-133,-56,-19,18,46,61,106,115,173,204,333,438,493]", "-392"], ["[-467,-72,-31,418,493]", "346"], ["[-437,79,346,393,453]", "425"], ["[-304,-114,36,53,260]", "-78"], ["[-474,-29,42,202,451]", "13"], ["[-313,-76,-21,49,240]", "-27"], ["[-483,-315,-300,-258,-192,-40,-19,32,50,316,345,373,455]", "276"], ["[-322,-62,10,149,184]", "122"], ["[-492,-471,-461,-415,-281,-235,-177,-47,32,125,215,306,443]", "-439"], ["[-346,-262,-124,-86,-82,-3,61,86,121,222,258,358,414]", "636"], ["[-500,-451,-310,-282,-225,-206,-170,-135,-104,-8,61,131,138,175,239,287,347,355,371,441,495]", "414"], ["[152,199,278,289,459]", "477"], ["[-499,-479,-469,-451,-391,-355,-318,-295,-191,-152,-146,-140,-65,-11,70,238,249,275,293,319,437]", "-42"], ["[-394,-315,-305,-296,-281,-258,-240,-126,-114,-65,120,134,135,170,172,197,213,279,289,415,463]", "205"], ["[-211,42,71,153,180]", "222"], ["[-445,-271,-151,-127,343]", "-398"], ["[-187,-20,183,203,233]", "163"], ["[-482,-461,-115,393,414]", "-576"], ["[-486,-438,-345,-164,-120,-3,53,138,163,164,181,206,437]", "-257"], ["[-1000,0]", "-1000"], ["@javascript:JSON.stringify([...Array(29998).fill(-1000),0,1000])", "1000"]], "expected": [[1, 2], [1, 3], [1, 2], [1, 2], [1, 2], [1, 3], [1000, 1001], [4, 17], [6, 12], [2, 4], [10, 13], [2, 4], [2, 4], [2, 10], [6, 11], [6, 7], [2, 5], [14, 18], [10, 18], [2, 9], [14, 18], [6, 10], [2, 9], [2, 4], [2, 5], [2, 4], [2, 4], [14, 19], [9, 13], [8, 9], [2, 4], [6, 8], [14, 15], [2, 3], [10, 16], [10, 13], [10, 13], [6, 7], [2, 5], [10, 11], [6, 18], [2, 11], [2, 4], [2, 3], [2, 3], [2, 3], [2, 4], [6, 10], [2, 5], [2, 9], [10, 13], [14, 15], [2, 3], [2, 21], [6, 21], [2, 5], [2, 4], [2, 3], [2, 3], [2, 11], [1, 2], [29999, 30000]], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "320", "slug": "two-sum-iii-data-structure-design", "id": 320, "title": "Two Sum III - Data Structure Design", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/two-sum-iii-data-structure-design/", "examples": [{"input": "operations = [\"TwoSum\",\"add\",\"add\",\"add\",\"find\",\"find\"], values = [[],[1],[3],[5],[4],[7]]", "output": "[null,null,null,null,true,false]", "explanation": "After storing 1, 3, 5: 4 equals 1 + 3 (true), while no pair sums to 7 (false)."}, {"input": "operations = [\"TwoSum\",\"add\",\"add\",\"find\"], values = [[],[0],[0],[0]]", "output": "[null,null,null,true]", "explanation": "The two stored zeros sum to 0."}, {"input": "operations = [\"TwoSum\",\"add\",\"find\",\"find\"], values = [[],[5],[5],[10]]", "output": "[null,null,false,false]", "explanation": "A single stored 5 cannot pair with itself; 10 also has no pair yet."}], "hints": ["Keep counts of each added number so duplicates are handled: finding 2*x requires two copies of x.", "For find(value), check whether value - x was seen for some stored x.", "Construction and add report \"null\"; each find reports \"true\" or \"false\"."], "statement": "Design a data structure that supports adding numbers and finding whether any pair of previously added numbers sums to a target value.\n\nImplement the `TwoSum` class:\n\n- `TwoSum()` Initializes the `TwoSum` object.\n- `void add(int number)` Adds `number` to the data structure.\n- `boolean find(int value)` Returns `true` if there exist two stored entries (two different additions) whose sum equals `value`, and `false` otherwise. A single stored copy cannot pair with itself: `find` needs two copies of `x` to report `true` for `value = 2 * x`.\n\nThe class keeps its LeetCode name `TwoSum` (the harness reserves `Solution` for the driver); the constructor and methods match the original.\n\n**Constraints:**\n- `-10^5 <= number, value <= 10^5`\n- At most `10^4` calls will be made to `add` and `find`.\n- Every trace begins with `TwoSum`; `add` and `find` each take one argument.\n", "solution": "## Approach\n\nKeep a frequency table of added numbers. Adding increments a count. Finding scans the stored keys for a complement that sums to the target, insisting on two copies when both addends are equal. Each `find` is reported as `\"true\"` or `\"false\"`, while construction and `add` report `\"null\"`; the full per-operation trace is compared exactly against the reference.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) per `add`, O(d) per `find` where d is the number of distinct stored values.\n- **Space Complexity:** O(d) for the frequency table.\n\n## Implementation\n\n```python\nclass TwoSum:\n def __init__(self):\n self.counts = {}\n\n def add(self, number: int) -> None:\n self.counts[number] = self.counts.get(number, 0) + 1\n\n def find(self, value: int) -> bool:\n for x, c in self.counts.items():\n need = value - x\n if need == x:\n if c >= 2:\n return True\n elif need in self.counts:\n return True\n return False\n```\n", "starter": {"go": "package main\n\ntype TwoSum struct {\n\n}\n\nfunc Constructor() TwoSum {\n return TwoSum{}\n}\n\nfunc (this *TwoSum) Add(number int) {\n\n}\n\nfunc (this *TwoSum) Find(value int) bool {\n return false\n}", "python": "class TwoSum:\n def __init__(self):\n pass\n\n def add(self, number: int) -> None:\n pass\n\n def find(self, value: int) -> bool:\n return False", "cpp": "class TwoSum {\npublic:\n TwoSum() {\n\n }\n\n void add(int number) {\n\n }\n\n bool find(int value) {\n return false;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"TwoSum\", \"add\", \"add\", \"add\", \"find\", \"find\"]", "[[], [1], [3], [5], [4], [7]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\"]", "[[], [0], [0], [0]]"], ["[\"TwoSum\", \"add\", \"find\", \"find\"]", "[[], [5], [5], [10]]"], ["[\"TwoSum\", \"find\"]", "[[], [0]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\"]", "[[], [1], [2], [3]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\"]", "[[], [1], [1], [2]]"], ["[\"TwoSum\", \"add\", \"add\", \"add\", \"find\"]", "[[], [-1], [-2], [-3], [-5]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\", \"find\"]", "[[], [3], [3], [6], [5]]"], ["[\"TwoSum\", \"add\", \"find\", \"add\", \"find\"]", "[[], [1], [2], [1], [2]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\"]", "[[], [-5], [5], [0]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\"]", "[[], [10000], [10000], [20000]]"], ["[\"TwoSum\", \"add\", \"add\", \"add\", \"find\", \"find\", \"find\"]", "[[], [2], [4], [6], [8], [10], [12]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\", \"find\"]", "[[], [1], [2], [3], [4]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\", \"find\"]", "[[], [-1], [1], [0], [2]]"], ["[\"TwoSum\", \"add\", \"find\", \"add\", \"find\"]", "[[], [0], [0], [0], [0]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\", \"find\"]", "[[], [5], [5], [10], [9]]"], ["[\"TwoSum\", \"find\", \"add\", \"find\", \"add\", \"find\"]", "[[], [100], [50], [100], [50], [100]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\", \"find\"]", "[[], [-5], [-3], [-8], [-7]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\"]", "[[], [1000000], [-1000000], [0]]"], ["[\"TwoSum\", \"add\", \"find\", \"find\", \"add\", \"find\"]", "[[], [7], [7], [14], [7], [14]]"], ["[\"TwoSum\", \"add\", \"add\", \"add\", \"add\", \"find\", \"find\", \"find\"]", "[[], [1], [3], [5], [7], [8], [12], [2]]"], ["[\"TwoSum\", \"add\", \"add\", \"add\", \"find\", \"find\"]", "[[], [2], [2], [2], [4], [6]]"], ["[\"TwoSum\", \"find\", \"find\"]", "[[], [0], [-1]]"], ["[\"TwoSum\", \"add\", \"add\", \"add\", \"find\", \"find\", \"find\"]", "[[], [10], [20], [30], [50], [40], [30]]"], ["[\"TwoSum\", \"add\", \"add\", \"find\", \"add\", \"find\", \"find\"]", "[[], [-2], [4], [2], [-4], [0], [-6]]"]], "expected": null, "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "673", "slug": "two-sum-iv-input-is-a-bst", "id": 673, "title": "Two Sum IV - Input Is a BST", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/two-sum-iv-input-is-a-bst/", "examples": [{"input": "root = [5,3,6,2,4,null,7], k = 9", "output": "true", "explanation": "Nodes 2 and 7 add to 9."}, {"input": "root = [5,3,6,2,4,null,7], k = 28", "output": "false", "explanation": "No pair in this tree reaches 28."}, {"input": "root = [2,1,3], k = 4", "output": "true", "explanation": "Nodes 1 and 3 add to 4."}], "hints": ["Visit each value once and remember what has been seen in a hash set.", "For the current value v, the partner must be k - v; check the set before inserting v.", "Any traversal order works because only the set of values matters."], "statement": "You are given the root of a binary search tree and an integer `k`.\n\nDecide whether the tree contains two different nodes whose values add up to `k`.\n\n**Constraints:**\n- `1 <= number of nodes <= 10^4`\n- `-10^4 <= node value <= 10^4`\n- The tree satisfies binary-search-tree ordering.\n- `-10^5 <= k <= 10^5`\n", "solution": "## Approach\n\nWalk the tree in any order while keeping every visited value in a hash set. For the current node holding `v`, a partner exists exactly when `k - v` was seen before. Insert `v` after the check so a node never pairs with itself.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for one visit per node with O(1) set work.\n- **Space Complexity:** O(n) for the set of values.\n\n## Implementation\n\n```python\nclass Solution:\n def findTarget(self, root, k: int) -> bool:\n seen = set()\n stack = [root] if root else []\n while stack:\n n = stack.pop()\n if k - n.val in seen:\n return True\n seen.add(n.val)\n if n.left:\n stack.append(n.left)\n if n.right:\n stack.append(n.right)\n return False\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc FindTarget(root *TreeNode, k int) bool {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def findTarget(self, root, k: int) -> bool:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool findTarget(TreeNode* root, int k) {\n return false;\n }\n};"}, "fn": "findTarget", "params": [{"name": "root", "type": "tree_node"}, {"name": "k", "type": "int"}], "outputType": "boolean", "tests": [["[5,3,6,2,4,null,7]", "9"], ["[5,3,6,2,4,null,7]", "28"], ["[2,1,3]", "4"], ["[2,1,3]", "1"], ["[1]", "2"], ["[1,0,3]", "4"], ["[0,-2,3,-1,null,null,5]", "-1"], ["[10,5,15,3,7,null,18]", "22"], ["[10,5,15,3,7,null,18]", "100"], ["[3,2,4,1,null,null,5]", "6"], ["[3,2,4,1,null,null,5]", "10"], ["[1,null,2,null,3]", "5"], ["[1,null,2,null,3]", "2"], ["[7,3,9,1,5,null,10]", "8"], ["[7,3,9,1,5,null,10]", "19"], ["[0]", "0"], ["[-5,-8,0,-6,null,-1,4]", "-9"], ["[-5,-8,0,-6,null,-1,4]", "3"], ["[100,50,150,25,75,125,175]", "200"], ["[100,50,150,25,75,125,175]", "201"], ["[2,0,3,-4,1,null,null]", "-1"], ["[2,0,3,-4,1,null,null]", "7"], ["[5,3,6,2,4,null,7]", "7"], ["[5,3,6,2,4,null,7]", "11"], ["[4,2,6,1,3,5,7]", "9"], ["[4,2,6,1,3,5,7]", "14"], ["[1,0,2]", "3"], ["[8,3,10,1,6,null,14,4,7,13,null]", "17"]], "expected": [true, false, true, false, false, true, true, true, false, true, false, true, false, true, true, false, true, true, true, false, true, false, true, true, true, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "1", "slug": "two-sum", "id": 1, "title": "Two Sum", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/two-sum/", "examples": [{"input": "nums = [2,7,11,15], target = 9", "output": "[0,1]", "explanation": "Because nums[0] + nums[1] == 9, we return [0, 1]."}, {"input": "nums = [3,2,4], target = 6", "output": "[1,2]", "explanation": "nums[1] + nums[2] = 2 + 4 = 6. Since nums[1] + nums[2] == target, we return [1,2]."}, {"input": "nums = [3,3], target = 6", "output": "[0,1]", "explanation": "nums[0] + nums[1] = 3 + 3 = 6. Since nums[0] + nums[1] == target, we return [0,1]."}], "hints": ["A naive `O(n^2)` solution will have a nested for loop to find (i,j) where `nums[i] + nums[j] == target`. Can you think of a better solution?", "Use HashMap. The key will be `nums[i]` while the value will be `i`."], "statement": "Given a list of integers `nums` and an integer `target`, locate two positions whose values total `target` and return those positions. When the list holds no such pair, return an empty list instead.\n\n**Constraints:**\n- 2 <= nums.length <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= target <= 10^9\n", "solution": "## Approach\n\nUse a hash map to store each element's value and its index while iterating through the array. For each element `nums[i]`, compute the complement `target - nums[i]`. If the complement exists in the hash map, return the current index `i` and the stored index of the complement. This avoids a nested loop, achieving a single pass through the array.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of the input array. Each element is visited once, and hash map lookups are O(1) on average.\n- **Space Complexity:** O(n). In the worst case, we store nearly all elements in the hash map before finding the pair.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:\n seen = {}\n for i, v in enumerate(nums):\n want = target - v\n if want in seen:\n return [seen[want], i]\n seen[v] = i\n return []\n```\n", "starter": {"go": "package main\n\nfunc TwoSum(nums []int, target int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def twoSum(self, nums: List[int], target: int) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> twoSum(vector<int>& nums, int target) {\n return {};\n }\n};"}, "fn": "twoSum", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int_array", "tests": [["[2,7,11,15]", "9"], ["[3,2,4]", "6"], ["[3,3]", "6"], ["[0,0]", "0"], ["[1,2,3,4,5]", "9"], ["[5,75,25]", "100"], ["[-3,4,3,90]", "0"], ["[-1,-2,-3,-4,-5]", "-8"], ["[2,5,5,11]", "10"], ["[1,3,4,2]", "6"], ["[3,3,4,7]", "6"], ["[1,4,5,6,7,8,9]", "13"], ["[1000000,500000,500000]", "1000000"], ["[2,14,18,22,30,46,50]", "32"], ["[1,1,1,1,1,1,1,1]", "2"], ["[1,2]", "3"], ["[9,9,9,9,9,9,9,9,9,9]", "18"], ["[2,4,3,1]", "7"], ["[0,4,3,0]", "0"], ["[1,2,3,4,4]", "8"], ["[2,5,7,11,15,20,3]", "22"], ["[-10,20,-10,5]", "10"], ["[1,2,3,4,5,6,7,8,9,10]", "19"], ["[3,1,4,2,5]", "6"], ["[6,2,3,4,1,5]", "11"], ["[1,5,3,3,3,2]", "6"], ["[1,100,200,300,400,500]", "700"], ["[0,1,2,3,4,5,6,7,8,9,10]", "17"], ["[1,1,2,3,5,8,13,21,34]", "55"], ["[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2]", "3"], ["@javascript:JSON.stringify([...Array(5000).fill(1), 2, 2])", "4"]], "expected": [[1, 0], [2, 1], [1, 0], [1, 0], [4, 3], [2, 1], [2, 0], [4, 2], [2, 1], [3, 2], [1, 0], [4, 3], [2, 1], [2, 1], [1, 0], [1, 0], [1, 0], [2, 1], [3, 0], [4, 3], [4, 2], [1, 0], [9, 8], [3, 2], [5, 0], [1, 0], [4, 3], [9, 8], [8, 7], [16, 15], [5001, 5000]], "loose": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "366", "slug": "ugly-number-ii", "id": 366, "title": "Ugly Number II", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/ugly-number-ii/", "examples": [{"input": "n = 10", "output": "12", "explanation": "The first ten ugly numbers are [1,2,3,4,5,6,8,9,10,12], so the tenth is 12."}, {"input": "n = 1", "output": "1", "explanation": "1 is the first ugly number."}, {"input": "n = 11", "output": "15", "explanation": "After 12 comes 15, since 11, 13 and 14 all contain other prime factors."}], "hints": ["Every ugly number after 1 is twice, three times or five times an earlier ugly number.", "Keep three pointers into the built list for multiples of 2, 3 and 5, and always take the smallest candidate next.", "Advance every pointer whose candidate equals the chosen value so duplicates appear only once."], "statement": "An ugly number is a positive integer whose prime factors are only 2, 3 and 5. The ordered list of ugly numbers starts 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 and continues without gaps.\n\nGiven `n`, return the `n`th ugly number, counting from 1.\n\n**Constraints:**\n- `1 <= n <= 1690`\n", "solution": "## Approach\n\nEvery ugly number after 1 is 2, 3 or 5 times an earlier ugly number. Build the sequence in order with three pointers marking the next unused multiple of 2, 3 and 5. Repeatedly take the smallest candidate as the next ugly number and advance every pointer that produced it, which keeps the list sorted and duplicate-free.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(n) for the generated list.\n\n## Implementation\n\n```python\nclass Solution:\n def nthUglyNumber(self, n: int) -> int:\n ugly = [1]\n i2 = i3 = i5 = 0\n for _ in range(1, n):\n nxt = min(ugly[i2] * 2, ugly[i3] * 3, ugly[i5] * 5)\n ugly.append(nxt)\n if nxt == ugly[i2] * 2:\n i2 += 1\n if nxt == ugly[i3] * 3:\n i3 += 1\n if nxt == ugly[i5] * 5:\n i5 += 1\n return ugly[-1]\n```\n", "starter": {"go": "package main\n\nfunc NthUglyNumber(n int) int {\n return 0\n}", "python": "class Solution:\n def nthUglyNumber(self, n: int) -> int:\n return 0\n", "cpp": "class Solution {\npublic:\n int nthUglyNumber(int n) {\n return 0;\n }\n};"}, "fn": "nthUglyNumber", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["10"], ["1"], ["11"], ["7"], ["2"], ["3"], ["4"], ["5"], ["6"], ["8"], ["9"], ["12"], ["15"], ["20"], ["50"], ["100"], ["200"], ["500"], ["1000"], ["1200"], ["1500"], ["1600"], ["1650"], ["1680"], ["1690"], ["13"]], "expected": [12, 1, 15, 8, 2, 3, 4, 5, 6, 9, 10, 16, 24, 36, 243, 1536, 16200, 937500, 51200000, 174960000, 859963392, 1399680000, 1769472000, 2025000000, 2123366400, 18], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "365", "slug": "ugly-number", "id": 365, "title": "Ugly Number", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/ugly-number/", "examples": [{"input": "n = 6", "output": "true", "explanation": "6 factors as 2 * 3, using only allowed primes."}, {"input": "n = 1", "output": "true", "explanation": "1 has no prime factors, so it is ugly by definition."}, {"input": "n = 14", "output": "false", "explanation": "14 includes the prime factor 7, which is not allowed."}], "hints": ["Non-positive values can never be ugly.", "Divide out factors 2, 3 and 5 completely; the value is ugly exactly when 1 remains."], "statement": "An ugly number is a positive integer whose prime factors are only 2, 3 and 5. By convention, 1 has no prime factors and counts as ugly.\n\nGiven an integer `n`, return `true` when `n` is ugly and `false` otherwise.\n\n**Constraints:**\n- `-2^31 <= n <= 2^31 - 1`\n", "solution": "## Approach\n\nReject non-positive inputs immediately. Repeatedly divide out 2, 3 and 5; if only allowed primes were present, nothing but 1 can remain. Any leftover above 1 must contain another prime factor.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n) divisions.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def isUgly(self, n: int) -> bool:\n if n <= 0:\n return False\n for p in (2, 3, 5):\n while n % p == 0:\n n //= p\n return n == 1\n```\n", "starter": {"go": "package main\n\nfunc IsUgly(n int) bool {\n return false\n}", "python": "class Solution:\n def isUgly(self, n: int) -> bool:\n return False\n", "cpp": "class Solution {\npublic:\n bool isUgly(int n) {\n return false;\n }\n};"}, "fn": "isUgly", "params": [{"name": "n", "type": "int"}], "outputType": "boolean", "tests": [["6"], ["1"], ["14"], ["8"], ["0"], ["-6"], ["2"], ["3"], ["5"], ["7"], ["10"], ["15"], ["30"], ["25"], ["27"], ["49"], ["100"], ["937351770"], ["2147483647"], ["-2147483648"], ["4"], ["9"], ["12"], ["11"], ["16"], ["18"]], "expected": [true, true, false, true, false, false, true, true, true, false, true, true, true, true, true, false, true, false, false, false, true, true, true, false, true, true], "loose": false}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basic": false, "label": "875", "slug": "uncommon-words-from-two-sentences", "id": 875, "title": "Uncommon Words from Two Sentences", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/uncommon-words-from-two-sentences/", "examples": [{"input": "s1 = \"this apple is sweet\", s2 = \"this apple is sour\"", "output": "[\"sweet\",\"sour\"]", "explanation": "\"this\", \"apple\" and \"is\" each appear twice, while \"sweet\" and \"sour\" appear once."}, {"input": "s1 = \"apple apple\", s2 = \"banana\"", "output": "[\"banana\"]", "explanation": "\"apple\" appears twice in total and \"banana\" appears once."}, {"input": "s1 = \"apple banana\", s2 = \"apple banana cherry\"", "output": "[\"cherry\"]", "explanation": "\"apple\" and \"banana\" each appear twice, and \"cherry\" appears once."}], "hints": ["Split both sentences into words and count every word with a frequency map.", "Collect the words whose total count is exactly one; any order is accepted."], "statement": "You are given two sentences, `s1` and `s2`, where words are separated by single spaces. A word is uncommon when it appears exactly once across both sentences put together.\n\nReturn the list of all uncommon words. The order of the returned words does not matter.\n\n**Constraints:**\n- `1 <= s1.length, s2.length <= 200`\n- Sentences hold lowercase English words joined by single spaces, with no leading or trailing spaces.\n", "solution": "## Approach\n\nJoin the two sentences, split them into words, and tally each word in a frequency map. A second pass keeps exactly those words whose total count equals one. Because the checker compares answers as sets, the kept words may be returned in any order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(w), where w is the total number of words across both sentences.\n- **Space Complexity:** O(w) for the frequency map and the result.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n count = {}\n for w in (s1 + \" \" + s2).split(\" \"):\n count[w] = count.get(w, 0) + 1\n return [w for w, c in count.items() if c == 1]\n```\n", "starter": {"go": "package main\n\nfunc UncommonFromSentences(s1 string, s2 string) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> uncommonFromSentences(string s1, string s2) {\n return {};\n }\n};"}, "fn": "uncommonFromSentences", "params": [{"name": "s1", "type": "string"}, {"name": "s2", "type": "string"}], "outputType": "string_list", "tests": [["this apple is sweet", "this apple is sour"], ["apple apple", "banana"], ["apple banana", "apple banana cherry"], ["a", "b"], ["a", "a"], ["apple apple apple", "apple"], ["one two three", "four five six"], ["same same", "same same"], ["x y z", "x y"], ["hello world", "world hello"], ["cat dog", "dog bird"], ["a b c d e", "f g h i j"], ["repeat repeat repeat", "unique"], ["sweet sweet sour", "sweet sour tart"], ["alpha beta gamma", "beta delta"], ["only", "lonely"], ["a a b", "b c c"], ["a a b", "b c d"], ["big bad wolf", "big bad pig"], ["one", "one two three"], ["sun moon stars", "sun comet moon"], ["red blue", "green yellow red"], ["up down", "down up left"], ["p q r s t", "p q r s t u"], ["eat sleep code", "sleep eat repeat"], ["a b", "c a b"], ["longer sentence with many words here", "another longer sentence with words"], ["zebra", "apple zebra mango"]], "expected": [["sweet", "sour"], ["banana"], ["cherry"], ["a", "b"], [], [], ["six", "four", "one", "two", "three", "five"], [], ["z"], [], ["cat", "bird"], ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"], ["unique"], ["tart"], ["alpha", "delta", "gamma"], ["only", "lonely"], [], ["c", "d"], ["wolf", "pig"], ["two", "three"], ["comet", "stars"], ["green", "blue", "yellow"], ["left"], ["u"], ["code", "repeat"], ["c"], ["here", "another", "many"], ["apple", "mango"]], "loose": true}
|