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.
Files changed (1038) hide show
  1. package/README.md +38 -2
  2. package/data/index.json +1 -0
  3. package/data/problems/01-matrix.json +1 -0
  4. package/data/problems/1-bit-and-2-bit-characters.json +1 -0
  5. package/data/problems/132-pattern.json +1 -0
  6. package/data/problems/2-keys-keyboard.json +1 -0
  7. package/data/problems/24-game.json +1 -0
  8. package/data/problems/3sum-closest.json +1 -0
  9. package/data/problems/3sum-smaller.json +1 -0
  10. package/data/problems/3sum-with-multiplicity.json +1 -0
  11. package/data/problems/3sum.json +1 -0
  12. package/data/problems/4-keys-keyboard.json +1 -0
  13. package/data/problems/4sum-ii.json +1 -0
  14. package/data/problems/4sum.json +1 -0
  15. package/data/problems/accounts-merge.json +1 -0
  16. package/data/problems/add-binary.json +1 -0
  17. package/data/problems/add-bold-tag-in-string.json +1 -0
  18. package/data/problems/add-digits.json +1 -0
  19. package/data/problems/add-one-row-to-tree.json +1 -0
  20. package/data/problems/add-strings.json +1 -0
  21. package/data/problems/add-to-array-form-of-integer.json +1 -0
  22. package/data/problems/add-two-numbers-ii.json +1 -0
  23. package/data/problems/add-two-numbers.json +1 -0
  24. package/data/problems/additive-number.json +1 -0
  25. package/data/problems/advantage-shuffle.json +1 -0
  26. package/data/problems/alien-dictionary.json +1 -0
  27. package/data/problems/all-nodes-distance-k-in-binary-tree.json +1 -0
  28. package/data/problems/all-oone-data-structure.json +1 -0
  29. package/data/problems/all-paths-from-source-to-target.json +1 -0
  30. package/data/problems/all-possible-full-binary-trees.json +1 -0
  31. package/data/problems/ambiguous-coordinates.json +1 -0
  32. package/data/problems/android-unlock-patterns.json +1 -0
  33. package/data/problems/arithmetic-slices-ii-subsequence.json +1 -0
  34. package/data/problems/arithmetic-slices.json +1 -0
  35. package/data/problems/arranging-coins.json +1 -0
  36. package/data/problems/array-nesting.json +1 -0
  37. package/data/problems/array-of-doubled-pairs.json +1 -0
  38. package/data/problems/array-partition.json +1 -0
  39. package/data/problems/assign-cookies.json +1 -0
  40. package/data/problems/asteroid-collision.json +1 -0
  41. package/data/problems/available-captures-for-rook.json +1 -0
  42. package/data/problems/average-of-levels-in-binary-tree.json +1 -0
  43. package/data/problems/backspace-string-compare.json +1 -0
  44. package/data/problems/bag-of-tokens.json +1 -0
  45. package/data/problems/balanced-binary-tree.json +1 -0
  46. package/data/problems/base-7.json +1 -0
  47. package/data/problems/baseball-game.json +1 -0
  48. package/data/problems/basic-absolute-value.json +1 -0
  49. package/data/problems/basic-array-max.json +1 -0
  50. package/data/problems/basic-array-min.json +1 -0
  51. package/data/problems/basic-array-sum-rec.json +1 -0
  52. package/data/problems/basic-array-sum.json +1 -0
  53. package/data/problems/basic-average-floor.json +1 -0
  54. package/data/problems/basic-bubble-sort.json +1 -0
  55. package/data/problems/basic-calculator-ii.json +1 -0
  56. package/data/problems/basic-calculator-iii.json +1 -0
  57. package/data/problems/basic-calculator-iv.json +1 -0
  58. package/data/problems/basic-calculator.json +1 -0
  59. package/data/problems/basic-collatz-steps.json +1 -0
  60. package/data/problems/basic-contains-value.json +1 -0
  61. package/data/problems/basic-count-above.json +1 -0
  62. package/data/problems/basic-count-char.json +1 -0
  63. package/data/problems/basic-count-digits.json +1 -0
  64. package/data/problems/basic-count-evens.json +1 -0
  65. package/data/problems/basic-count-pairs.json +1 -0
  66. package/data/problems/basic-count-vowels.json +1 -0
  67. package/data/problems/basic-count-words.json +1 -0
  68. package/data/problems/basic-countdown.json +1 -0
  69. package/data/problems/basic-double-array.json +1 -0
  70. package/data/problems/basic-factorial-rec.json +1 -0
  71. package/data/problems/basic-factorial.json +1 -0
  72. package/data/problems/basic-fibonacci.json +1 -0
  73. package/data/problems/basic-find-index.json +1 -0
  74. package/data/problems/basic-gcd.json +1 -0
  75. package/data/problems/basic-grade-letter.json +1 -0
  76. package/data/problems/basic-has-duplicate.json +1 -0
  77. package/data/problems/basic-is-even.json +1 -0
  78. package/data/problems/basic-is-leap-year.json +1 -0
  79. package/data/problems/basic-is-sorted.json +1 -0
  80. package/data/problems/basic-max-frequency.json +1 -0
  81. package/data/problems/basic-max-of-three.json +1 -0
  82. package/data/problems/basic-max-of-two.json +1 -0
  83. package/data/problems/basic-palindrome-text.json +1 -0
  84. package/data/problems/basic-power-rec.json +1 -0
  85. package/data/problems/basic-power.json +1 -0
  86. package/data/problems/basic-repeat-string.json +1 -0
  87. package/data/problems/basic-reverse-array.json +1 -0
  88. package/data/problems/basic-reverse-number.json +1 -0
  89. package/data/problems/basic-reverse-text-rec.json +1 -0
  90. package/data/problems/basic-reverse-text.json +1 -0
  91. package/data/problems/basic-second-largest.json +1 -0
  92. package/data/problems/basic-sort-two.json +1 -0
  93. package/data/problems/basic-staircase.json +1 -0
  94. package/data/problems/basic-string-length.json +1 -0
  95. package/data/problems/basic-sum-1-to-n.json +1 -0
  96. package/data/problems/basic-sum-digits-rec.json +1 -0
  97. package/data/problems/basic-sum-multiples.json +1 -0
  98. package/data/problems/basic-sum-of-digits.json +1 -0
  99. package/data/problems/basic-temperature-advice.json +1 -0
  100. package/data/problems/basic-to-upper.json +1 -0
  101. package/data/problems/basic-triangle-sum.json +1 -0
  102. package/data/problems/battleships-in-a-board.json +1 -0
  103. package/data/problems/beautiful-arrangement-ii.json +1 -0
  104. package/data/problems/beautiful-arrangement.json +1 -0
  105. package/data/problems/beautiful-array.json +1 -0
  106. package/data/problems/best-meeting-point.json +1 -0
  107. package/data/problems/best-time-to-buy-and-sell-stock-ii.json +1 -0
  108. package/data/problems/best-time-to-buy-and-sell-stock-iii.json +1 -0
  109. package/data/problems/best-time-to-buy-and-sell-stock-iv.json +1 -0
  110. package/data/problems/best-time-to-buy-and-sell-stock-with-cooldown.json +1 -0
  111. package/data/problems/best-time-to-buy-and-sell-stock-with-transaction-fee.json +1 -0
  112. package/data/problems/best-time-to-buy-and-sell-stock.json +1 -0
  113. package/data/problems/binary-gap.json +1 -0
  114. package/data/problems/binary-number-with-alternating-bits.json +1 -0
  115. package/data/problems/binary-search-tree-iterator.json +1 -0
  116. package/data/problems/binary-search.json +1 -0
  117. package/data/problems/binary-subarrays-with-sum.json +1 -0
  118. package/data/problems/binary-tree-cameras.json +1 -0
  119. package/data/problems/binary-tree-inorder-traversal.json +1 -0
  120. package/data/problems/binary-tree-level-order-traversal-ii.json +1 -0
  121. package/data/problems/binary-tree-level-order-traversal.json +1 -0
  122. package/data/problems/binary-tree-longest-consecutive-sequence-ii.json +1 -0
  123. package/data/problems/binary-tree-longest-consecutive-sequence.json +1 -0
  124. package/data/problems/binary-tree-maximum-path-sum.json +1 -0
  125. package/data/problems/binary-tree-paths.json +1 -0
  126. package/data/problems/binary-tree-postorder-traversal.json +1 -0
  127. package/data/problems/binary-tree-preorder-traversal.json +1 -0
  128. package/data/problems/binary-tree-pruning.json +1 -0
  129. package/data/problems/binary-tree-right-side-view.json +1 -0
  130. package/data/problems/binary-tree-tilt.json +1 -0
  131. package/data/problems/binary-tree-upside-down.json +1 -0
  132. package/data/problems/binary-tree-vertical-order-traversal.json +1 -0
  133. package/data/problems/binary-tree-zigzag-level-order-traversal.json +1 -0
  134. package/data/problems/binary-trees-with-factors.json +1 -0
  135. package/data/problems/binary-watch.json +1 -0
  136. package/data/problems/bitwise-and-of-numbers-range.json +1 -0
  137. package/data/problems/bitwise-ors-of-subarrays.json +1 -0
  138. package/data/problems/boats-to-save-people.json +1 -0
  139. package/data/problems/bold-words-in-string.json +1 -0
  140. package/data/problems/bomb-enemy.json +1 -0
  141. package/data/problems/boundary-of-binary-tree.json +1 -0
  142. package/data/problems/brick-wall.json +1 -0
  143. package/data/problems/bricks-falling-when-hit.json +1 -0
  144. package/data/problems/broken-calculator.json +1 -0
  145. package/data/problems/buddy-strings.json +1 -0
  146. package/data/problems/build-a-matrix-with-conditions.json +1 -0
  147. package/data/problems/bulb-switcher-ii.json +1 -0
  148. package/data/problems/bulb-switcher.json +1 -0
  149. package/data/problems/bulls-and-cows.json +1 -0
  150. package/data/problems/burst-balloons.json +1 -0
  151. package/data/problems/bus-routes.json +1 -0
  152. package/data/problems/can-i-win.json +1 -0
  153. package/data/problems/can-place-flowers.json +1 -0
  154. package/data/problems/candy-crush.json +1 -0
  155. package/data/problems/candy.json +1 -0
  156. package/data/problems/capacity-to-ship-packages-within-d-days.json +1 -0
  157. package/data/problems/car-fleet.json +1 -0
  158. package/data/problems/car-pooling.json +1 -0
  159. package/data/problems/card-flipping-game.json +1 -0
  160. package/data/problems/cat-and-mouse.json +1 -0
  161. package/data/problems/chalkboard-xor-game.json +1 -0
  162. package/data/problems/champagne-tower.json +1 -0
  163. package/data/problems/cheapest-flights-within-k-stops.json +1 -0
  164. package/data/problems/check-completeness-of-a-binary-tree.json +1 -0
  165. package/data/problems/cherry-pickup.json +1 -0
  166. package/data/problems/circular-array-loop.json +1 -0
  167. package/data/problems/climbing-stairs.json +1 -0
  168. package/data/problems/clone-graph.json +1 -0
  169. package/data/problems/closest-binary-search-tree-value-ii.json +1 -0
  170. package/data/problems/closest-binary-search-tree-value.json +1 -0
  171. package/data/problems/closest-leaf-in-a-binary-tree.json +1 -0
  172. package/data/problems/coin-change-ii.json +1 -0
  173. package/data/problems/coin-change.json +1 -0
  174. package/data/problems/coin-path.json +1 -0
  175. package/data/problems/combination-sum-ii.json +1 -0
  176. package/data/problems/combination-sum-iii.json +1 -0
  177. package/data/problems/combination-sum-iv.json +1 -0
  178. package/data/problems/combination-sum.json +1 -0
  179. package/data/problems/combinations.json +1 -0
  180. package/data/problems/compare-version-numbers.json +1 -0
  181. package/data/problems/complete-binary-tree-inserter.json +1 -0
  182. package/data/problems/complex-number-multiplication.json +1 -0
  183. package/data/problems/concatenated-words.json +1 -0
  184. package/data/problems/concatenation-of-array.json +1 -0
  185. package/data/problems/consecutive-numbers-sum.json +1 -0
  186. package/data/problems/construct-binary-tree-from-inorder-and-postorder-traversal.json +1 -0
  187. package/data/problems/construct-binary-tree-from-preorder-and-inorder-traversal.json +1 -0
  188. package/data/problems/construct-binary-tree-from-preorder-and-postorder-traversal.json +1 -0
  189. package/data/problems/construct-binary-tree-from-string.json +1 -0
  190. package/data/problems/construct-quad-tree.json +1 -0
  191. package/data/problems/construct-string-from-binary-tree.json +1 -0
  192. package/data/problems/construct-the-rectangle.json +1 -0
  193. package/data/problems/contain-virus.json +1 -0
  194. package/data/problems/container-with-most-water.json +1 -0
  195. package/data/problems/contains-duplicate-ii.json +1 -0
  196. package/data/problems/contains-duplicate-iii.json +1 -0
  197. package/data/problems/contains-duplicate.json +1 -0
  198. package/data/problems/contiguous-array.json +1 -0
  199. package/data/problems/continuous-subarray-sum.json +1 -0
  200. package/data/problems/convert-a-number-to-hexadecimal.json +1 -0
  201. package/data/problems/convert-binary-search-tree-to-sorted-doubly-linked-list.json +1 -0
  202. package/data/problems/convert-bst-to-greater-tree.json +1 -0
  203. package/data/problems/convert-sorted-array-to-binary-search-tree.json +1 -0
  204. package/data/problems/convert-sorted-list-to-binary-search-tree.json +1 -0
  205. package/data/problems/convex-polygon.json +1 -0
  206. package/data/problems/copy-list-with-random-pointer.json +1 -0
  207. package/data/problems/count-and-say.json +1 -0
  208. package/data/problems/count-binary-substrings.json +1 -0
  209. package/data/problems/count-complete-tree-nodes.json +1 -0
  210. package/data/problems/count-different-palindromic-subsequences.json +1 -0
  211. package/data/problems/count-good-nodes-in-binary-tree.json +1 -0
  212. package/data/problems/count-numbers-with-unique-digits.json +1 -0
  213. package/data/problems/count-of-range-sum.json +1 -0
  214. package/data/problems/count-of-smaller-numbers-after-self.json +1 -0
  215. package/data/problems/count-primes.json +1 -0
  216. package/data/problems/count-the-repetitions.json +1 -0
  217. package/data/problems/count-unique-characters-of-all-substrings-of-a-given-string.json +1 -0
  218. package/data/problems/count-univalue-subtrees.json +1 -0
  219. package/data/problems/counting-bits.json +1 -0
  220. package/data/problems/couples-holding-hands.json +1 -0
  221. package/data/problems/course-schedule-ii.json +1 -0
  222. package/data/problems/course-schedule-iii.json +1 -0
  223. package/data/problems/course-schedule-iv.json +1 -0
  224. package/data/problems/course-schedule.json +1 -0
  225. package/data/problems/cousins-in-binary-tree.json +1 -0
  226. package/data/problems/cracking-the-safe.json +1 -0
  227. package/data/problems/create-maximum-number.json +1 -0
  228. package/data/problems/custom-sort-string.json +1 -0
  229. package/data/problems/cut-off-trees-for-golf-event.json +1 -0
  230. package/data/problems/daily-temperatures.json +1 -0
  231. package/data/problems/data-stream-as-disjoint-intervals.json +1 -0
  232. package/data/problems/decode-string.json +1 -0
  233. package/data/problems/decode-ways-ii.json +1 -0
  234. package/data/problems/decode-ways.json +1 -0
  235. package/data/problems/decoded-string-at-index.json +1 -0
  236. package/data/problems/degree-of-an-array.json +1 -0
  237. package/data/problems/delete-and-earn.json +1 -0
  238. package/data/problems/delete-columns-to-make-sorted-ii.json +1 -0
  239. package/data/problems/delete-columns-to-make-sorted-iii.json +1 -0
  240. package/data/problems/delete-columns-to-make-sorted.json +1 -0
  241. package/data/problems/delete-leaves-with-a-given-value.json +1 -0
  242. package/data/problems/delete-node-in-a-bst.json +1 -0
  243. package/data/problems/delete-node-in-a-linked-list.json +1 -0
  244. package/data/problems/delete-operation-for-two-strings.json +1 -0
  245. package/data/problems/design-add-and-search-words-data-structure.json +1 -0
  246. package/data/problems/design-circular-deque.json +1 -0
  247. package/data/problems/design-circular-queue.json +1 -0
  248. package/data/problems/design-compressed-string-iterator.json +1 -0
  249. package/data/problems/design-excel-sum-formula.json +1 -0
  250. package/data/problems/design-hashmap.json +1 -0
  251. package/data/problems/design-hashset.json +1 -0
  252. package/data/problems/design-hit-counter.json +1 -0
  253. package/data/problems/design-in-memory-file-system.json +1 -0
  254. package/data/problems/design-linked-list.json +1 -0
  255. package/data/problems/design-log-storage-system.json +1 -0
  256. package/data/problems/design-phone-directory.json +1 -0
  257. package/data/problems/design-search-autocomplete-system.json +1 -0
  258. package/data/problems/design-snake-game.json +1 -0
  259. package/data/problems/design-tic-tac-toe.json +1 -0
  260. package/data/problems/design-twitter.json +1 -0
  261. package/data/problems/detect-capital.json +1 -0
  262. package/data/problems/detect-squares.json +1 -0
  263. package/data/problems/di-string-match.json +1 -0
  264. package/data/problems/diagonal-traverse.json +1 -0
  265. package/data/problems/diameter-of-binary-tree.json +1 -0
  266. package/data/problems/different-ways-to-add-parentheses.json +1 -0
  267. package/data/problems/distinct-subsequences-ii.json +1 -0
  268. package/data/problems/distinct-subsequences.json +1 -0
  269. package/data/problems/distribute-candies.json +1 -0
  270. package/data/problems/distribute-coins-in-binary-tree.json +1 -0
  271. package/data/problems/divide-two-integers.json +1 -0
  272. package/data/problems/domino-and-tromino-tiling.json +1 -0
  273. package/data/problems/dota2-senate.json +1 -0
  274. package/data/problems/dungeon-game.json +1 -0
  275. package/data/problems/edit-distance.json +1 -0
  276. package/data/problems/elimination-game.json +1 -0
  277. package/data/problems/employee-free-time.json +1 -0
  278. package/data/problems/employee-importance.json +1 -0
  279. package/data/problems/encode-and-decode-strings.json +1 -0
  280. package/data/problems/encode-and-decode-tinyurl.json +1 -0
  281. package/data/problems/encode-n-ary-tree-to-binary-tree.json +1 -0
  282. package/data/problems/encode-string-with-shortest-length.json +1 -0
  283. package/data/problems/equal-rational-numbers.json +1 -0
  284. package/data/problems/equal-tree-partition.json +1 -0
  285. package/data/problems/erect-the-fence.json +1 -0
  286. package/data/problems/escape-the-ghosts.json +1 -0
  287. package/data/problems/evaluate-division.json +1 -0
  288. package/data/problems/evaluate-reverse-polish-notation.json +1 -0
  289. package/data/problems/exam-room.json +1 -0
  290. package/data/problems/excel-sheet-column-number.json +1 -0
  291. package/data/problems/excel-sheet-column-title.json +1 -0
  292. package/data/problems/exclusive-time-of-functions.json +1 -0
  293. package/data/problems/expression-add-operators.json +1 -0
  294. package/data/problems/expressive-words.json +1 -0
  295. package/data/problems/extra-characters-in-a-string.json +1 -0
  296. package/data/problems/factor-combinations.json +1 -0
  297. package/data/problems/factorial-trailing-zeroes.json +1 -0
  298. package/data/problems/fair-candy-swap.json +1 -0
  299. package/data/problems/falling-squares.json +1 -0
  300. package/data/problems/fibonacci-number.json +1 -0
  301. package/data/problems/find-all-anagrams-in-a-string.json +1 -0
  302. package/data/problems/find-all-duplicates-in-an-array.json +1 -0
  303. package/data/problems/find-all-numbers-disappeared-in-an-array.json +1 -0
  304. package/data/problems/find-anagram-mappings.json +1 -0
  305. package/data/problems/find-and-replace-in-string.json +1 -0
  306. package/data/problems/find-and-replace-pattern.json +1 -0
  307. package/data/problems/find-bottom-left-tree-value.json +1 -0
  308. package/data/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.json +1 -0
  309. package/data/problems/find-duplicate-file-in-system.json +1 -0
  310. package/data/problems/find-duplicate-subtrees.json +1 -0
  311. package/data/problems/find-eventual-safe-states.json +1 -0
  312. package/data/problems/find-first-and-last-position-of-element-in-sorted-array.json +1 -0
  313. package/data/problems/find-in-mountain-array.json +1 -0
  314. package/data/problems/find-k-closest-elements.json +1 -0
  315. package/data/problems/find-k-pairs-with-smallest-sums.json +1 -0
  316. package/data/problems/find-k-th-smallest-pair-distance.json +1 -0
  317. package/data/problems/find-largest-value-in-each-tree-row.json +1 -0
  318. package/data/problems/find-leaves-of-binary-tree.json +1 -0
  319. package/data/problems/find-median-from-data-stream.json +1 -0
  320. package/data/problems/find-minimum-in-rotated-sorted-array-ii.json +1 -0
  321. package/data/problems/find-minimum-in-rotated-sorted-array.json +1 -0
  322. package/data/problems/find-mode-in-binary-search-tree.json +1 -0
  323. package/data/problems/find-peak-element.json +1 -0
  324. package/data/problems/find-permutation.json +1 -0
  325. package/data/problems/find-pivot-index.json +1 -0
  326. package/data/problems/find-right-interval.json +1 -0
  327. package/data/problems/find-smallest-letter-greater-than-target.json +1 -0
  328. package/data/problems/find-the-celebrity.json +1 -0
  329. package/data/problems/find-the-closest-palindrome.json +1 -0
  330. package/data/problems/find-the-derangement-of-an-array.json +1 -0
  331. package/data/problems/find-the-difference.json +1 -0
  332. package/data/problems/find-the-duplicate-number.json +1 -0
  333. package/data/problems/find-the-index-of-the-first-occurrence-in-a-string.json +1 -0
  334. package/data/problems/find-the-shortest-superstring.json +1 -0
  335. package/data/problems/find-the-town-judge.json +1 -0
  336. package/data/problems/first-bad-version.json +1 -0
  337. package/data/problems/first-missing-positive.json +1 -0
  338. package/data/problems/first-unique-character-in-a-string.json +1 -0
  339. package/data/problems/fizz-buzz.json +1 -0
  340. package/data/problems/flatten-2d-vector.json +1 -0
  341. package/data/problems/flatten-a-multilevel-doubly-linked-list.json +1 -0
  342. package/data/problems/flatten-binary-tree-to-linked-list.json +1 -0
  343. package/data/problems/flatten-nested-list-iterator.json +1 -0
  344. package/data/problems/flip-binary-tree-to-match-preorder-traversal.json +1 -0
  345. package/data/problems/flip-equivalent-binary-trees.json +1 -0
  346. package/data/problems/flip-game-ii.json +1 -0
  347. package/data/problems/flip-game.json +1 -0
  348. package/data/problems/flip-string-to-monotone-increasing.json +1 -0
  349. package/data/problems/flipping-an-image.json +1 -0
  350. package/data/problems/flood-fill.json +1 -0
  351. package/data/problems/fraction-addition-and-subtraction.json +1 -0
  352. package/data/problems/fraction-to-recurring-decimal.json +1 -0
  353. package/data/problems/freedom-trail.json +1 -0
  354. package/data/problems/friends-of-appropriate-ages.json +1 -0
  355. package/data/problems/frog-jump.json +1 -0
  356. package/data/problems/fruit-into-baskets.json +1 -0
  357. package/data/problems/game-of-life.json +1 -0
  358. package/data/problems/gas-station.json +1 -0
  359. package/data/problems/generalized-abbreviation.json +1 -0
  360. package/data/problems/generate-parentheses.json +1 -0
  361. package/data/problems/generate-random-point-in-a-circle.json +1 -0
  362. package/data/problems/global-and-local-inversions.json +1 -0
  363. package/data/problems/goat-latin.json +1 -0
  364. package/data/problems/graph-valid-tree.json +1 -0
  365. package/data/problems/gray-code.json +1 -0
  366. package/data/problems/greatest-common-divisor-of-strings.json +1 -0
  367. package/data/problems/greatest-common-divisor-traversal.json +1 -0
  368. package/data/problems/group-anagrams.json +1 -0
  369. package/data/problems/group-shifted-strings.json +1 -0
  370. package/data/problems/groups-of-special-equivalent-strings.json +1 -0
  371. package/data/problems/guess-number-higher-or-lower-ii.json +1 -0
  372. package/data/problems/guess-number-higher-or-lower.json +1 -0
  373. package/data/problems/guess-the-word.json +1 -0
  374. package/data/problems/h-index-ii.json +1 -0
  375. package/data/problems/h-index.json +1 -0
  376. package/data/problems/hamming-distance.json +1 -0
  377. package/data/problems/hand-of-straights.json +1 -0
  378. package/data/problems/happy-number.json +1 -0
  379. package/data/problems/heaters.json +1 -0
  380. package/data/problems/house-robber-ii.json +1 -0
  381. package/data/problems/house-robber-iii.json +1 -0
  382. package/data/problems/house-robber.json +1 -0
  383. package/data/problems/image-overlap.json +1 -0
  384. package/data/problems/image-smoother.json +1 -0
  385. package/data/problems/implement-magic-dictionary.json +1 -0
  386. package/data/problems/implement-queue-using-stacks.json +1 -0
  387. package/data/problems/implement-rand10-using-rand7.json +1 -0
  388. package/data/problems/implement-stack-using-queues.json +1 -0
  389. package/data/problems/implement-trie-prefix-tree.json +1 -0
  390. package/data/problems/increasing-order-search-tree.json +1 -0
  391. package/data/problems/increasing-triplet-subsequence.json +1 -0
  392. package/data/problems/inorder-successor-in-bst-ii.json +1 -0
  393. package/data/problems/inorder-successor-in-bst.json +1 -0
  394. package/data/problems/insert-delete-getrandom-o1-duplicates-allowed.json +1 -0
  395. package/data/problems/insert-delete-getrandom-o1.json +1 -0
  396. package/data/problems/insert-greatest-common-divisors-in-linked-list.json +1 -0
  397. package/data/problems/insert-interval.json +1 -0
  398. package/data/problems/insert-into-a-binary-search-tree.json +1 -0
  399. package/data/problems/insert-into-a-sorted-circular-linked-list.json +1 -0
  400. package/data/problems/insertion-sort-list.json +1 -0
  401. package/data/problems/integer-break.json +1 -0
  402. package/data/problems/integer-replacement.json +1 -0
  403. package/data/problems/integer-to-english-words.json +1 -0
  404. package/data/problems/integer-to-roman.json +1 -0
  405. package/data/problems/interleaving-string.json +1 -0
  406. package/data/problems/intersection-of-two-arrays-ii.json +1 -0
  407. package/data/problems/intersection-of-two-arrays.json +1 -0
  408. package/data/problems/intersection-of-two-linked-lists.json +1 -0
  409. package/data/problems/interval-list-intersections.json +1 -0
  410. package/data/problems/invert-binary-tree.json +1 -0
  411. package/data/problems/ip-to-cidr.json +1 -0
  412. package/data/problems/ipo.json +1 -0
  413. package/data/problems/is-graph-bipartite.json +1 -0
  414. package/data/problems/is-subsequence.json +1 -0
  415. package/data/problems/island-perimeter.json +1 -0
  416. package/data/problems/isomorphic-strings.json +1 -0
  417. package/data/problems/jewels-and-stones.json +1 -0
  418. package/data/problems/jump-game-ii.json +1 -0
  419. package/data/problems/jump-game-vii.json +1 -0
  420. package/data/problems/jump-game.json +1 -0
  421. package/data/problems/k-closest-points-to-origin.json +1 -0
  422. package/data/problems/k-diff-pairs-in-an-array.json +1 -0
  423. package/data/problems/k-empty-slots.json +1 -0
  424. package/data/problems/k-inverse-pairs-array.json +1 -0
  425. package/data/problems/k-similar-strings.json +1 -0
  426. package/data/problems/k-th-smallest-in-lexicographical-order.json +1 -0
  427. package/data/problems/k-th-smallest-prime-fraction.json +1 -0
  428. package/data/problems/k-th-symbol-in-grammar.json +1 -0
  429. package/data/problems/keyboard-row.json +1 -0
  430. package/data/problems/keys-and-rooms.json +1 -0
  431. package/data/problems/kill-process.json +1 -0
  432. package/data/problems/knight-dialer.json +1 -0
  433. package/data/problems/knight-probability-in-chessboard.json +1 -0
  434. package/data/problems/koko-eating-bananas.json +1 -0
  435. package/data/problems/kth-largest-element-in-a-stream.json +1 -0
  436. package/data/problems/kth-largest-element-in-an-array.json +1 -0
  437. package/data/problems/kth-smallest-element-in-a-bst.json +1 -0
  438. package/data/problems/kth-smallest-element-in-a-sorted-matrix.json +1 -0
  439. package/data/problems/kth-smallest-number-in-multiplication-table.json +1 -0
  440. package/data/problems/largest-bst-subtree.json +1 -0
  441. package/data/problems/largest-component-size-by-common-factor.json +1 -0
  442. package/data/problems/largest-divisible-subset.json +1 -0
  443. package/data/problems/largest-number-at-least-twice-of-others.json +1 -0
  444. package/data/problems/largest-number.json +1 -0
  445. package/data/problems/largest-palindrome-product.json +1 -0
  446. package/data/problems/largest-perimeter-triangle.json +1 -0
  447. package/data/problems/largest-plus-sign.json +1 -0
  448. package/data/problems/largest-rectangle-in-histogram.json +1 -0
  449. package/data/problems/largest-sum-of-averages.json +1 -0
  450. package/data/problems/largest-time-for-given-digits.json +1 -0
  451. package/data/problems/largest-triangle-area.json +1 -0
  452. package/data/problems/last-stone-weight-ii.json +1 -0
  453. package/data/problems/last-stone-weight.json +1 -0
  454. package/data/problems/leaf-similar-trees.json +1 -0
  455. package/data/problems/least-operators-to-express-number.json +1 -0
  456. package/data/problems/lemonade-change.json +1 -0
  457. package/data/problems/length-of-last-word.json +1 -0
  458. package/data/problems/length-of-longest-fibonacci-subsequence.json +1 -0
  459. package/data/problems/letter-case-permutation.json +1 -0
  460. package/data/problems/letter-combinations-of-a-phone-number.json +1 -0
  461. package/data/problems/lexicographical-numbers.json +1 -0
  462. package/data/problems/lfu-cache.json +1 -0
  463. package/data/problems/license-key-formatting.json +1 -0
  464. package/data/problems/line-reflection.json +1 -0
  465. package/data/problems/linked-list-components.json +1 -0
  466. package/data/problems/linked-list-cycle-ii.json +1 -0
  467. package/data/problems/linked-list-cycle.json +1 -0
  468. package/data/problems/linked-list-random-node.json +1 -0
  469. package/data/problems/logger-rate-limiter.json +1 -0
  470. package/data/problems/logical-or-of-two-binary-grids-represented-as-quad-trees.json +1 -0
  471. package/data/problems/lonely-pixel-i.json +1 -0
  472. package/data/problems/lonely-pixel-ii.json +1 -0
  473. package/data/problems/long-pressed-name.json +1 -0
  474. package/data/problems/longest-absolute-file-path.json +1 -0
  475. package/data/problems/longest-common-prefix.json +1 -0
  476. package/data/problems/longest-common-subsequence.json +1 -0
  477. package/data/problems/longest-consecutive-sequence.json +1 -0
  478. package/data/problems/longest-continuous-increasing-subsequence.json +1 -0
  479. package/data/problems/longest-happy-string.json +1 -0
  480. package/data/problems/longest-harmonious-subsequence.json +1 -0
  481. package/data/problems/longest-increasing-path-in-a-matrix.json +1 -0
  482. package/data/problems/longest-increasing-subsequence.json +1 -0
  483. package/data/problems/longest-line-of-consecutive-one-in-matrix.json +1 -0
  484. package/data/problems/longest-mountain-in-array.json +1 -0
  485. package/data/problems/longest-palindrome.json +1 -0
  486. package/data/problems/longest-palindromic-subsequence.json +1 -0
  487. package/data/problems/longest-palindromic-substring.json +1 -0
  488. package/data/problems/longest-repeating-character-replacement.json +1 -0
  489. package/data/problems/longest-substring-with-at-least-k-repeating-characters.json +1 -0
  490. package/data/problems/longest-substring-with-at-most-k-distinct-characters.json +1 -0
  491. package/data/problems/longest-substring-with-at-most-two-distinct-characters.json +1 -0
  492. package/data/problems/longest-substring-without-repeating-characters.json +1 -0
  493. package/data/problems/longest-turbulent-subarray.json +1 -0
  494. package/data/problems/longest-uncommon-subsequence-i.json +1 -0
  495. package/data/problems/longest-uncommon-subsequence-ii.json +1 -0
  496. package/data/problems/longest-univalue-path.json +1 -0
  497. package/data/problems/longest-valid-parentheses.json +1 -0
  498. package/data/problems/longest-word-in-dictionary-through-deleting.json +1 -0
  499. package/data/problems/longest-word-in-dictionary.json +1 -0
  500. package/data/problems/loud-and-rich.json +1 -0
  501. package/data/problems/lowest-common-ancestor-of-a-binary-search-tree.json +1 -0
  502. package/data/problems/lowest-common-ancestor-of-a-binary-tree.json +1 -0
  503. package/data/problems/lru-cache.json +1 -0
  504. package/data/problems/magic-squares-in-grid.json +1 -0
  505. package/data/problems/magical-string.json +1 -0
  506. package/data/problems/majority-element-ii.json +1 -0
  507. package/data/problems/majority-element.json +1 -0
  508. package/data/problems/making-a-large-island.json +1 -0
  509. package/data/problems/map-sum-pairs.json +1 -0
  510. package/data/problems/masking-personal-information.json +1 -0
  511. package/data/problems/matchsticks-to-square.json +1 -0
  512. package/data/problems/max-area-of-island.json +1 -0
  513. package/data/problems/max-chunks-to-make-sorted-ii.json +1 -0
  514. package/data/problems/max-chunks-to-make-sorted.json +1 -0
  515. package/data/problems/max-consecutive-ones-ii.json +1 -0
  516. package/data/problems/max-consecutive-ones.json +1 -0
  517. package/data/problems/max-increase-to-keep-city-skyline.json +1 -0
  518. package/data/problems/max-points-on-a-line.json +1 -0
  519. package/data/problems/max-stack.json +1 -0
  520. package/data/problems/max-sum-of-rectangle-no-larger-than-k.json +1 -0
  521. package/data/problems/maximal-rectangle.json +1 -0
  522. package/data/problems/maximal-square.json +1 -0
  523. package/data/problems/maximize-distance-to-closest-person.json +1 -0
  524. package/data/problems/maximum-average-subarray-i.json +1 -0
  525. package/data/problems/maximum-average-subarray-ii.json +1 -0
  526. package/data/problems/maximum-binary-tree-ii.json +1 -0
  527. package/data/problems/maximum-binary-tree.json +1 -0
  528. package/data/problems/maximum-depth-of-binary-tree.json +1 -0
  529. package/data/problems/maximum-depth-of-n-ary-tree.json +1 -0
  530. package/data/problems/maximum-distance-in-arrays.json +1 -0
  531. package/data/problems/maximum-frequency-stack.json +1 -0
  532. package/data/problems/maximum-gap.json +1 -0
  533. package/data/problems/maximum-length-of-pair-chain.json +1 -0
  534. package/data/problems/maximum-length-of-repeated-subarray.json +1 -0
  535. package/data/problems/maximum-product-of-three-numbers.json +1 -0
  536. package/data/problems/maximum-product-of-word-lengths.json +1 -0
  537. package/data/problems/maximum-product-subarray.json +1 -0
  538. package/data/problems/maximum-size-subarray-sum-equals-k.json +1 -0
  539. package/data/problems/maximum-subarray.json +1 -0
  540. package/data/problems/maximum-sum-circular-subarray.json +1 -0
  541. package/data/problems/maximum-sum-of-3-non-overlapping-subarrays.json +1 -0
  542. package/data/problems/maximum-swap.json +1 -0
  543. package/data/problems/maximum-vacation-days.json +1 -0
  544. package/data/problems/maximum-width-of-binary-tree.json +1 -0
  545. package/data/problems/maximum-width-ramp.json +1 -0
  546. package/data/problems/maximum-xor-of-two-numbers-in-an-array.json +1 -0
  547. package/data/problems/median-of-two-sorted-arrays.json +1 -0
  548. package/data/problems/meeting-rooms-ii.json +1 -0
  549. package/data/problems/meeting-rooms-iii.json +1 -0
  550. package/data/problems/meeting-rooms.json +1 -0
  551. package/data/problems/merge-intervals.json +1 -0
  552. package/data/problems/merge-k-sorted-lists.json +1 -0
  553. package/data/problems/merge-sorted-array.json +1 -0
  554. package/data/problems/merge-strings-alternately.json +1 -0
  555. package/data/problems/merge-triplets-to-form-target-triplet.json +1 -0
  556. package/data/problems/merge-two-binary-trees.json +1 -0
  557. package/data/problems/merge-two-sorted-lists.json +1 -0
  558. package/data/problems/middle-of-the-linked-list.json +1 -0
  559. package/data/problems/min-cost-climbing-stairs.json +1 -0
  560. package/data/problems/min-cost-to-connect-all-points.json +1 -0
  561. package/data/problems/min-stack.json +1 -0
  562. package/data/problems/minesweeper.json +1 -0
  563. package/data/problems/mini-parser.json +1 -0
  564. package/data/problems/minimize-malware-spread-ii.json +1 -0
  565. package/data/problems/minimize-malware-spread.json +1 -0
  566. package/data/problems/minimize-max-distance-to-gas-station.json +1 -0
  567. package/data/problems/minimum-absolute-difference-in-bst.json +1 -0
  568. package/data/problems/minimum-add-to-make-parentheses-valid.json +1 -0
  569. package/data/problems/minimum-area-rectangle-ii.json +1 -0
  570. package/data/problems/minimum-area-rectangle.json +1 -0
  571. package/data/problems/minimum-array-end.json +1 -0
  572. package/data/problems/minimum-ascii-delete-sum-for-two-strings.json +1 -0
  573. package/data/problems/minimum-cost-for-tickets.json +1 -0
  574. package/data/problems/minimum-cost-to-hire-k-workers.json +1 -0
  575. package/data/problems/minimum-cost-to-merge-stones.json +1 -0
  576. package/data/problems/minimum-depth-of-binary-tree.json +1 -0
  577. package/data/problems/minimum-distance-between-bst-nodes.json +1 -0
  578. package/data/problems/minimum-factorization.json +1 -0
  579. package/data/problems/minimum-falling-path-sum.json +1 -0
  580. package/data/problems/minimum-genetic-mutation.json +1 -0
  581. package/data/problems/minimum-height-trees.json +1 -0
  582. package/data/problems/minimum-increment-to-make-array-unique.json +1 -0
  583. package/data/problems/minimum-index-sum-of-two-lists.json +1 -0
  584. package/data/problems/minimum-interval-to-include-each-query.json +1 -0
  585. package/data/problems/minimum-moves-to-equal-array-elements-ii.json +1 -0
  586. package/data/problems/minimum-moves-to-equal-array-elements.json +1 -0
  587. package/data/problems/minimum-number-of-arrows-to-burst-balloons.json +1 -0
  588. package/data/problems/minimum-number-of-k-consecutive-bit-flips.json +1 -0
  589. package/data/problems/minimum-number-of-refueling-stops.json +1 -0
  590. package/data/problems/minimum-path-sum.json +1 -0
  591. package/data/problems/minimum-size-subarray-sum.json +1 -0
  592. package/data/problems/minimum-swaps-to-make-sequences-increasing.json +1 -0
  593. package/data/problems/minimum-time-difference.json +1 -0
  594. package/data/problems/minimum-unique-word-abbreviation.json +1 -0
  595. package/data/problems/minimum-window-subsequence.json +1 -0
  596. package/data/problems/minimum-window-substring.json +1 -0
  597. package/data/problems/mirror-reflection.json +1 -0
  598. package/data/problems/missing-number.json +1 -0
  599. package/data/problems/missing-ranges.json +1 -0
  600. package/data/problems/monotone-increasing-digits.json +1 -0
  601. package/data/problems/monotonic-array.json +1 -0
  602. package/data/problems/most-common-word.json +1 -0
  603. package/data/problems/most-frequent-subtree-sum.json +1 -0
  604. package/data/problems/most-profit-assigning-work.json +1 -0
  605. package/data/problems/most-stones-removed-with-same-row-or-column.json +1 -0
  606. package/data/problems/move-zeroes.json +1 -0
  607. package/data/problems/moving-average-from-data-stream.json +1 -0
  608. package/data/problems/multiply-strings.json +1 -0
  609. package/data/problems/my-calendar-i.json +1 -0
  610. package/data/problems/my-calendar-ii.json +1 -0
  611. package/data/problems/my-calendar-iii.json +1 -0
  612. package/data/problems/n-ary-tree-level-order-traversal.json +1 -0
  613. package/data/problems/n-ary-tree-postorder-traversal.json +1 -0
  614. package/data/problems/n-ary-tree-preorder-traversal.json +1 -0
  615. package/data/problems/n-queens-ii.json +1 -0
  616. package/data/problems/n-queens.json +1 -0
  617. package/data/problems/n-repeated-element-in-size-2n-array.json +1 -0
  618. package/data/problems/n-th-tribonacci-number.json +1 -0
  619. package/data/problems/nested-list-weight-sum-ii.json +1 -0
  620. package/data/problems/nested-list-weight-sum.json +1 -0
  621. package/data/problems/network-delay-time.json +1 -0
  622. package/data/problems/new-21-game.json +1 -0
  623. package/data/problems/next-closest-time.json +1 -0
  624. package/data/problems/next-greater-element-i.json +1 -0
  625. package/data/problems/next-greater-element-ii.json +1 -0
  626. package/data/problems/next-greater-element-iii.json +1 -0
  627. package/data/problems/next-permutation.json +1 -0
  628. package/data/problems/nim-game.json +1 -0
  629. package/data/problems/non-decreasing-array.json +1 -0
  630. package/data/problems/non-decreasing-subsequences.json +1 -0
  631. package/data/problems/non-negative-integers-without-consecutive-ones.json +1 -0
  632. package/data/problems/non-overlapping-intervals.json +1 -0
  633. package/data/problems/nth-digit.json +1 -0
  634. package/data/problems/nth-magical-number.json +1 -0
  635. package/data/problems/number-complement.json +1 -0
  636. package/data/problems/number-of-1-bits.json +1 -0
  637. package/data/problems/number-of-atoms.json +1 -0
  638. package/data/problems/number-of-boomerangs.json +1 -0
  639. package/data/problems/number-of-connected-components-in-an-undirected-graph.json +1 -0
  640. package/data/problems/number-of-corner-rectangles.json +1 -0
  641. package/data/problems/number-of-digit-one.json +1 -0
  642. package/data/problems/number-of-distinct-islands-ii.json +1 -0
  643. package/data/problems/number-of-distinct-islands.json +1 -0
  644. package/data/problems/number-of-islands-ii.json +1 -0
  645. package/data/problems/number-of-islands.json +1 -0
  646. package/data/problems/number-of-lines-to-write-string.json +1 -0
  647. package/data/problems/number-of-longest-increasing-subsequence.json +1 -0
  648. package/data/problems/number-of-matching-subsequences.json +1 -0
  649. package/data/problems/number-of-music-playlists.json +1 -0
  650. package/data/problems/number-of-provinces.json +1 -0
  651. package/data/problems/number-of-recent-calls.json +1 -0
  652. package/data/problems/number-of-segments-in-a-string.json +1 -0
  653. package/data/problems/number-of-squareful-arrays.json +1 -0
  654. package/data/problems/number-of-subarrays-with-bounded-maximum.json +1 -0
  655. package/data/problems/numbers-at-most-n-given-digit-set.json +1 -0
  656. package/data/problems/numbers-with-same-consecutive-differences.json +1 -0
  657. package/data/problems/odd-even-jump.json +1 -0
  658. package/data/problems/odd-even-linked-list.json +1 -0
  659. package/data/problems/one-edit-distance.json +1 -0
  660. package/data/problems/ones-and-zeroes.json +1 -0
  661. package/data/problems/online-election.json +1 -0
  662. package/data/problems/online-stock-span.json +1 -0
  663. package/data/problems/open-the-lock.json +1 -0
  664. package/data/problems/optimal-account-balancing.json +1 -0
  665. package/data/problems/optimal-division.json +1 -0
  666. package/data/problems/orderly-queue.json +1 -0
  667. package/data/problems/out-of-boundary-paths.json +1 -0
  668. package/data/problems/output-contest-matches.json +1 -0
  669. package/data/problems/pacific-atlantic-water-flow.json +1 -0
  670. package/data/problems/paint-fence.json +1 -0
  671. package/data/problems/paint-house-ii.json +1 -0
  672. package/data/problems/paint-house.json +1 -0
  673. package/data/problems/palindrome-linked-list.json +1 -0
  674. package/data/problems/palindrome-number.json +1 -0
  675. package/data/problems/palindrome-pairs.json +1 -0
  676. package/data/problems/palindrome-partitioning-ii.json +1 -0
  677. package/data/problems/palindrome-partitioning.json +1 -0
  678. package/data/problems/palindrome-permutation-ii.json +1 -0
  679. package/data/problems/palindrome-permutation.json +1 -0
  680. package/data/problems/palindromic-substrings.json +1 -0
  681. package/data/problems/pancake-sorting.json +1 -0
  682. package/data/problems/parse-lisp-expression.json +1 -0
  683. package/data/problems/partition-array-into-disjoint-intervals.json +1 -0
  684. package/data/problems/partition-equal-subset-sum.json +1 -0
  685. package/data/problems/partition-labels.json +1 -0
  686. package/data/problems/partition-list.json +1 -0
  687. package/data/problems/partition-to-k-equal-sum-subsets.json +1 -0
  688. package/data/problems/pascals-triangle-ii.json +1 -0
  689. package/data/problems/pascals-triangle.json +1 -0
  690. package/data/problems/patching-array.json +1 -0
  691. package/data/problems/path-sum-ii.json +1 -0
  692. package/data/problems/path-sum-iii.json +1 -0
  693. package/data/problems/path-sum-iv.json +1 -0
  694. package/data/problems/path-sum.json +1 -0
  695. package/data/problems/path-with-minimum-effort.json +1 -0
  696. package/data/problems/peak-index-in-a-mountain-array.json +1 -0
  697. package/data/problems/peeking-iterator.json +1 -0
  698. package/data/problems/perfect-number.json +1 -0
  699. package/data/problems/perfect-rectangle.json +1 -0
  700. package/data/problems/perfect-squares.json +1 -0
  701. package/data/problems/permutation-in-string.json +1 -0
  702. package/data/problems/permutation-sequence.json +1 -0
  703. package/data/problems/permutations-ii.json +1 -0
  704. package/data/problems/permutations.json +1 -0
  705. package/data/problems/plus-one-linked-list.json +1 -0
  706. package/data/problems/plus-one.json +1 -0
  707. package/data/problems/poor-pigs.json +1 -0
  708. package/data/problems/populating-next-right-pointers-in-each-node-ii.json +1 -0
  709. package/data/problems/populating-next-right-pointers-in-each-node.json +1 -0
  710. package/data/problems/positions-of-large-groups.json +1 -0
  711. package/data/problems/possible-bipartition.json +1 -0
  712. package/data/problems/pour-water.json +1 -0
  713. package/data/problems/power-of-four.json +1 -0
  714. package/data/problems/power-of-three.json +1 -0
  715. package/data/problems/power-of-two.json +1 -0
  716. package/data/problems/powerful-integers.json +1 -0
  717. package/data/problems/powx-n.json +1 -0
  718. package/data/problems/predict-the-winner.json +1 -0
  719. package/data/problems/prefix-and-suffix-search.json +1 -0
  720. package/data/problems/preimage-size-of-factorial-zeroes-function.json +1 -0
  721. package/data/problems/prime-number-of-set-bits-in-binary-representation.json +1 -0
  722. package/data/problems/prime-palindrome.json +1 -0
  723. package/data/problems/print-binary-tree.json +1 -0
  724. package/data/problems/prison-cells-after-n-days.json +1 -0
  725. package/data/problems/product-of-array-except-self.json +1 -0
  726. package/data/problems/profitable-schemes.json +1 -0
  727. package/data/problems/projection-area-of-3d-shapes.json +1 -0
  728. package/data/problems/push-dominoes.json +1 -0
  729. package/data/problems/pyramid-transition-matrix.json +1 -0
  730. package/data/problems/queue-reconstruction-by-height.json +1 -0
  731. package/data/problems/rabbits-in-forest.json +1 -0
  732. package/data/problems/race-car.json +1 -0
  733. package/data/problems/random-flip-matrix.json +1 -0
  734. package/data/problems/random-pick-index.json +1 -0
  735. package/data/problems/random-pick-with-blacklist.json +1 -0
  736. package/data/problems/random-pick-with-weight.json +1 -0
  737. package/data/problems/random-point-in-non-overlapping-rectangles.json +1 -0
  738. package/data/problems/range-addition-ii.json +1 -0
  739. package/data/problems/range-addition.json +1 -0
  740. package/data/problems/range-module.json +1 -0
  741. package/data/problems/range-sum-of-bst.json +1 -0
  742. package/data/problems/range-sum-query-2d-immutable.json +1 -0
  743. package/data/problems/range-sum-query-2d-mutable.json +1 -0
  744. package/data/problems/range-sum-query-immutable.json +1 -0
  745. package/data/problems/range-sum-query-mutable.json +1 -0
  746. package/data/problems/ransom-note.json +1 -0
  747. package/data/problems/reach-a-number.json +1 -0
  748. package/data/problems/reachable-nodes-in-subdivided-graph.json +1 -0
  749. package/data/problems/reaching-points.json +1 -0
  750. package/data/problems/read-n-characters-given-read4-ii-call-multiple-times.json +1 -0
  751. package/data/problems/read-n-characters-given-read4.json +1 -0
  752. package/data/problems/rearrange-string-k-distance-apart.json +1 -0
  753. package/data/problems/reconstruct-itinerary.json +1 -0
  754. package/data/problems/reconstruct-original-digits-from-english.json +1 -0
  755. package/data/problems/recover-binary-search-tree.json +1 -0
  756. package/data/problems/rectangle-area-ii.json +1 -0
  757. package/data/problems/rectangle-area.json +1 -0
  758. package/data/problems/rectangle-overlap.json +1 -0
  759. package/data/problems/redundant-connection-ii.json +1 -0
  760. package/data/problems/redundant-connection.json +1 -0
  761. package/data/problems/regions-cut-by-slashes.json +1 -0
  762. package/data/problems/regular-expression-matching.json +1 -0
  763. package/data/problems/relative-ranks.json +1 -0
  764. package/data/problems/remove-9.json +1 -0
  765. package/data/problems/remove-boxes.json +1 -0
  766. package/data/problems/remove-comments.json +1 -0
  767. package/data/problems/remove-duplicate-letters.json +1 -0
  768. package/data/problems/remove-duplicates-from-sorted-array-ii.json +1 -0
  769. package/data/problems/remove-duplicates-from-sorted-array.json +1 -0
  770. package/data/problems/remove-duplicates-from-sorted-list-ii.json +1 -0
  771. package/data/problems/remove-duplicates-from-sorted-list.json +1 -0
  772. package/data/problems/remove-element.json +1 -0
  773. package/data/problems/remove-invalid-parentheses.json +1 -0
  774. package/data/problems/remove-k-digits.json +1 -0
  775. package/data/problems/remove-linked-list-elements.json +1 -0
  776. package/data/problems/remove-nth-node-from-end-of-list.json +1 -0
  777. package/data/problems/reorder-data-in-log-files.json +1 -0
  778. package/data/problems/reorder-list.json +1 -0
  779. package/data/problems/reordered-power-of-2.json +1 -0
  780. package/data/problems/reorganize-string.json +1 -0
  781. package/data/problems/repeated-dna-sequences.json +1 -0
  782. package/data/problems/repeated-string-match.json +1 -0
  783. package/data/problems/repeated-substring-pattern.json +1 -0
  784. package/data/problems/replace-words.json +1 -0
  785. package/data/problems/reshape-the-matrix.json +1 -0
  786. package/data/problems/restore-ip-addresses.json +1 -0
  787. package/data/problems/reveal-cards-in-increasing-order.json +1 -0
  788. package/data/problems/reverse-bits.json +1 -0
  789. package/data/problems/reverse-integer.json +1 -0
  790. package/data/problems/reverse-linked-list-ii.json +1 -0
  791. package/data/problems/reverse-linked-list.json +1 -0
  792. package/data/problems/reverse-nodes-in-k-group.json +1 -0
  793. package/data/problems/reverse-only-letters.json +1 -0
  794. package/data/problems/reverse-pairs.json +1 -0
  795. package/data/problems/reverse-string-ii.json +1 -0
  796. package/data/problems/reverse-string.json +1 -0
  797. package/data/problems/reverse-vowels-of-a-string.json +1 -0
  798. package/data/problems/reverse-words-in-a-string-ii.json +1 -0
  799. package/data/problems/reverse-words-in-a-string-iii.json +1 -0
  800. package/data/problems/reverse-words-in-a-string.json +1 -0
  801. package/data/problems/rle-iterator.json +1 -0
  802. package/data/problems/robot-return-to-origin.json +1 -0
  803. package/data/problems/robot-room-cleaner.json +1 -0
  804. package/data/problems/roman-to-integer.json +1 -0
  805. package/data/problems/rotate-array.json +1 -0
  806. package/data/problems/rotate-function.json +1 -0
  807. package/data/problems/rotate-image.json +1 -0
  808. package/data/problems/rotate-list.json +1 -0
  809. package/data/problems/rotate-string.json +1 -0
  810. package/data/problems/rotated-digits.json +1 -0
  811. package/data/problems/rotting-oranges.json +1 -0
  812. package/data/problems/russian-doll-envelopes.json +1 -0
  813. package/data/problems/same-tree.json +1 -0
  814. package/data/problems/satisfiability-of-equality-equations.json +1 -0
  815. package/data/problems/score-after-flipping-matrix.json +1 -0
  816. package/data/problems/score-of-parentheses.json +1 -0
  817. package/data/problems/scramble-string.json +1 -0
  818. package/data/problems/search-a-2d-matrix-ii.json +1 -0
  819. package/data/problems/search-a-2d-matrix.json +1 -0
  820. package/data/problems/search-in-a-binary-search-tree.json +1 -0
  821. package/data/problems/search-in-a-sorted-array-of-unknown-size.json +1 -0
  822. package/data/problems/search-in-rotated-sorted-array-ii.json +1 -0
  823. package/data/problems/search-in-rotated-sorted-array.json +1 -0
  824. package/data/problems/search-insert-position.json +1 -0
  825. package/data/problems/second-minimum-node-in-a-binary-tree.json +1 -0
  826. package/data/problems/self-crossing.json +1 -0
  827. package/data/problems/self-dividing-numbers.json +1 -0
  828. package/data/problems/sentence-screen-fitting.json +1 -0
  829. package/data/problems/sentence-similarity-ii.json +1 -0
  830. package/data/problems/sentence-similarity.json +1 -0
  831. package/data/problems/sequence-reconstruction.json +1 -0
  832. package/data/problems/serialize-and-deserialize-binary-tree.json +1 -0
  833. package/data/problems/serialize-and-deserialize-bst.json +1 -0
  834. package/data/problems/serialize-and-deserialize-n-ary-tree.json +1 -0
  835. package/data/problems/set-intersection-size-at-least-two.json +1 -0
  836. package/data/problems/set-matrix-zeroes.json +1 -0
  837. package/data/problems/set-mismatch.json +1 -0
  838. package/data/problems/shifting-letters.json +1 -0
  839. package/data/problems/shopping-offers.json +1 -0
  840. package/data/problems/short-encoding-of-words.json +1 -0
  841. package/data/problems/shortest-bridge.json +1 -0
  842. package/data/problems/shortest-completing-word.json +1 -0
  843. package/data/problems/shortest-distance-from-all-buildings.json +1 -0
  844. package/data/problems/shortest-distance-to-a-character.json +1 -0
  845. package/data/problems/shortest-palindrome.json +1 -0
  846. package/data/problems/shortest-path-to-get-all-keys.json +1 -0
  847. package/data/problems/shortest-path-visiting-all-nodes.json +1 -0
  848. package/data/problems/shortest-subarray-with-sum-at-least-k.json +1 -0
  849. package/data/problems/shortest-unsorted-continuous-subarray.json +1 -0
  850. package/data/problems/shortest-word-distance-ii.json +1 -0
  851. package/data/problems/shortest-word-distance-iii.json +1 -0
  852. package/data/problems/shortest-word-distance.json +1 -0
  853. package/data/problems/shuffle-an-array.json +1 -0
  854. package/data/problems/similar-rgb-color.json +1 -0
  855. package/data/problems/similar-string-groups.json +1 -0
  856. package/data/problems/simplify-path.json +1 -0
  857. package/data/problems/single-element-in-a-sorted-array.json +1 -0
  858. package/data/problems/single-number-ii.json +1 -0
  859. package/data/problems/single-number-iii.json +1 -0
  860. package/data/problems/single-number.json +1 -0
  861. package/data/problems/single-threaded-cpu.json +1 -0
  862. package/data/problems/sliding-puzzle.json +1 -0
  863. package/data/problems/sliding-window-maximum.json +1 -0
  864. package/data/problems/sliding-window-median.json +1 -0
  865. package/data/problems/smallest-good-base.json +1 -0
  866. package/data/problems/smallest-range-covering-elements-from-k-lists.json +1 -0
  867. package/data/problems/smallest-range-i.json +1 -0
  868. package/data/problems/smallest-range-ii.json +1 -0
  869. package/data/problems/smallest-rectangle-enclosing-black-pixels.json +1 -0
  870. package/data/problems/smallest-rotation-with-highest-score.json +1 -0
  871. package/data/problems/smallest-string-starting-from-leaf.json +1 -0
  872. package/data/problems/smallest-subtree-with-all-the-deepest-nodes.json +1 -0
  873. package/data/problems/snakes-and-ladders.json +1 -0
  874. package/data/problems/solve-the-equation.json +1 -0
  875. package/data/problems/sort-an-array.json +1 -0
  876. package/data/problems/sort-array-by-parity-ii.json +1 -0
  877. package/data/problems/sort-array-by-parity.json +1 -0
  878. package/data/problems/sort-characters-by-frequency.json +1 -0
  879. package/data/problems/sort-colors.json +1 -0
  880. package/data/problems/sort-list.json +1 -0
  881. package/data/problems/sort-transformed-array.json +1 -0
  882. package/data/problems/soup-servings.json +1 -0
  883. package/data/problems/sparse-matrix-multiplication.json +1 -0
  884. package/data/problems/special-binary-string.json +1 -0
  885. package/data/problems/spiral-matrix-ii.json +1 -0
  886. package/data/problems/spiral-matrix-iii.json +1 -0
  887. package/data/problems/spiral-matrix.json +1 -0
  888. package/data/problems/split-array-into-consecutive-subsequences.json +1 -0
  889. package/data/problems/split-array-into-fibonacci-sequence.json +1 -0
  890. package/data/problems/split-array-largest-sum.json +1 -0
  891. package/data/problems/split-array-with-equal-sum.json +1 -0
  892. package/data/problems/split-array-with-same-average.json +1 -0
  893. package/data/problems/split-bst.json +1 -0
  894. package/data/problems/split-concatenated-strings.json +1 -0
  895. package/data/problems/split-linked-list-in-parts.json +1 -0
  896. package/data/problems/sqrtx.json +1 -0
  897. package/data/problems/squares-of-a-sorted-array.json +1 -0
  898. package/data/problems/squirrel-simulation.json +1 -0
  899. package/data/problems/stamping-the-sequence.json +1 -0
  900. package/data/problems/stickers-to-spell-word.json +1 -0
  901. package/data/problems/stone-game-ii.json +1 -0
  902. package/data/problems/stone-game-iii.json +1 -0
  903. package/data/problems/stone-game.json +1 -0
  904. package/data/problems/strange-printer.json +1 -0
  905. package/data/problems/string-compression.json +1 -0
  906. package/data/problems/string-to-integer-atoi.json +1 -0
  907. package/data/problems/string-without-aaa-or-bbb.json +1 -0
  908. package/data/problems/strobogrammatic-number-ii.json +1 -0
  909. package/data/problems/strobogrammatic-number-iii.json +1 -0
  910. package/data/problems/strobogrammatic-number.json +1 -0
  911. package/data/problems/strong-password-checker.json +1 -0
  912. package/data/problems/student-attendance-record-i.json +1 -0
  913. package/data/problems/student-attendance-record-ii.json +1 -0
  914. package/data/problems/subarray-product-less-than-k.json +1 -0
  915. package/data/problems/subarray-sum-equals-k.json +1 -0
  916. package/data/problems/subarray-sums-divisible-by-k.json +1 -0
  917. package/data/problems/subarrays-with-k-different-integers.json +1 -0
  918. package/data/problems/subdomain-visit-count.json +1 -0
  919. package/data/problems/subsets-ii.json +1 -0
  920. package/data/problems/subsets.json +1 -0
  921. package/data/problems/substring-with-concatenation-of-all-words.json +1 -0
  922. package/data/problems/subtree-of-another-tree.json +1 -0
  923. package/data/problems/sudoku-solver.json +1 -0
  924. package/data/problems/sum-of-all-subset-xor-totals.json +1 -0
  925. package/data/problems/sum-of-distances-in-tree.json +1 -0
  926. package/data/problems/sum-of-even-numbers-after-queries.json +1 -0
  927. package/data/problems/sum-of-left-leaves.json +1 -0
  928. package/data/problems/sum-of-square-numbers.json +1 -0
  929. package/data/problems/sum-of-subarray-minimums.json +1 -0
  930. package/data/problems/sum-of-subsequence-widths.json +1 -0
  931. package/data/problems/sum-of-two-integers.json +1 -0
  932. package/data/problems/sum-root-to-leaf-numbers.json +1 -0
  933. package/data/problems/summary-ranges.json +1 -0
  934. package/data/problems/super-egg-drop.json +1 -0
  935. package/data/problems/super-palindromes.json +1 -0
  936. package/data/problems/super-pow.json +1 -0
  937. package/data/problems/super-ugly-number.json +1 -0
  938. package/data/problems/super-washing-machines.json +1 -0
  939. package/data/problems/surface-area-of-3d-shapes.json +1 -0
  940. package/data/problems/surrounded-regions.json +1 -0
  941. package/data/problems/swap-adjacent-in-lr-string.json +1 -0
  942. package/data/problems/swap-nodes-in-pairs.json +1 -0
  943. package/data/problems/swim-in-rising-water.json +1 -0
  944. package/data/problems/symmetric-tree.json +1 -0
  945. package/data/problems/tag-validator.json +1 -0
  946. package/data/problems/tallest-billboard.json +1 -0
  947. package/data/problems/target-sum.json +1 -0
  948. package/data/problems/task-scheduler.json +1 -0
  949. package/data/problems/teemo-attacking.json +1 -0
  950. package/data/problems/ternary-expression-parser.json +1 -0
  951. package/data/problems/text-justification.json +1 -0
  952. package/data/problems/the-maze-ii.json +1 -0
  953. package/data/problems/the-maze-iii.json +1 -0
  954. package/data/problems/the-maze.json +1 -0
  955. package/data/problems/the-skyline-problem.json +1 -0
  956. package/data/problems/third-maximum-number.json +1 -0
  957. package/data/problems/three-equal-parts.json +1 -0
  958. package/data/problems/time-based-key-value-store.json +1 -0
  959. package/data/problems/to-lower-case.json +1 -0
  960. package/data/problems/toeplitz-matrix.json +1 -0
  961. package/data/problems/top-k-frequent-elements.json +1 -0
  962. package/data/problems/top-k-frequent-words.json +1 -0
  963. package/data/problems/total-hamming-distance.json +1 -0
  964. package/data/problems/transform-to-chessboard.json +1 -0
  965. package/data/problems/transpose-matrix.json +1 -0
  966. package/data/problems/trapping-rain-water-ii.json +1 -0
  967. package/data/problems/trapping-rain-water.json +1 -0
  968. package/data/problems/triangle.json +1 -0
  969. package/data/problems/trim-a-binary-search-tree.json +1 -0
  970. package/data/problems/triples-with-bitwise-and-equal-to-zero.json +1 -0
  971. package/data/problems/two-sum-ii-input-array-is-sorted.json +1 -0
  972. package/data/problems/two-sum-iii-data-structure-design.json +1 -0
  973. package/data/problems/two-sum-iv-input-is-a-bst.json +1 -0
  974. package/data/problems/two-sum.json +1 -0
  975. package/data/problems/ugly-number-ii.json +1 -0
  976. package/data/problems/ugly-number.json +1 -0
  977. package/data/problems/uncommon-words-from-two-sentences.json +1 -0
  978. package/data/problems/unique-binary-search-trees-ii.json +1 -0
  979. package/data/problems/unique-binary-search-trees.json +1 -0
  980. package/data/problems/unique-email-addresses.json +1 -0
  981. package/data/problems/unique-morse-code-words.json +1 -0
  982. package/data/problems/unique-paths-ii.json +1 -0
  983. package/data/problems/unique-paths-iii.json +1 -0
  984. package/data/problems/unique-paths.json +1 -0
  985. package/data/problems/unique-substrings-in-wraparound-string.json +1 -0
  986. package/data/problems/unique-word-abbreviation.json +1 -0
  987. package/data/problems/univalued-binary-tree.json +1 -0
  988. package/data/problems/utf-8-validation.json +1 -0
  989. package/data/problems/valid-anagram.json +1 -0
  990. package/data/problems/valid-mountain-array.json +1 -0
  991. package/data/problems/valid-number.json +1 -0
  992. package/data/problems/valid-palindrome-ii.json +1 -0
  993. package/data/problems/valid-palindrome.json +1 -0
  994. package/data/problems/valid-parentheses.json +1 -0
  995. package/data/problems/valid-parenthesis-string.json +1 -0
  996. package/data/problems/valid-perfect-square.json +1 -0
  997. package/data/problems/valid-permutations-for-di-sequence.json +1 -0
  998. package/data/problems/valid-square.json +1 -0
  999. package/data/problems/valid-sudoku.json +1 -0
  1000. package/data/problems/valid-tic-tac-toe-state.json +1 -0
  1001. package/data/problems/valid-triangle-number.json +1 -0
  1002. package/data/problems/valid-word-abbreviation.json +1 -0
  1003. package/data/problems/valid-word-square.json +1 -0
  1004. package/data/problems/validate-binary-search-tree.json +1 -0
  1005. package/data/problems/validate-ip-address.json +1 -0
  1006. package/data/problems/validate-stack-sequences.json +1 -0
  1007. package/data/problems/verify-preorder-sequence-in-binary-search-tree.json +1 -0
  1008. package/data/problems/verify-preorder-serialization-of-a-binary-tree.json +1 -0
  1009. package/data/problems/verifying-an-alien-dictionary.json +1 -0
  1010. package/data/problems/vertical-order-traversal-of-a-binary-tree.json +1 -0
  1011. package/data/problems/vowel-spellchecker.json +1 -0
  1012. package/data/problems/walking-robot-simulation.json +1 -0
  1013. package/data/problems/walls-and-gates.json +1 -0
  1014. package/data/problems/water-and-jug-problem.json +1 -0
  1015. package/data/problems/wiggle-sort-ii.json +1 -0
  1016. package/data/problems/wiggle-sort.json +1 -0
  1017. package/data/problems/wiggle-subsequence.json +1 -0
  1018. package/data/problems/wildcard-matching.json +1 -0
  1019. package/data/problems/word-abbreviation.json +1 -0
  1020. package/data/problems/word-break-ii.json +1 -0
  1021. package/data/problems/word-break.json +1 -0
  1022. package/data/problems/word-ladder-ii.json +1 -0
  1023. package/data/problems/word-ladder.json +1 -0
  1024. package/data/problems/word-pattern-ii.json +1 -0
  1025. package/data/problems/word-pattern.json +1 -0
  1026. package/data/problems/word-search-ii.json +1 -0
  1027. package/data/problems/word-search.json +1 -0
  1028. package/data/problems/word-squares.json +1 -0
  1029. package/data/problems/word-subsets.json +1 -0
  1030. package/data/problems/x-of-a-kind-in-a-deck-of-cards.json +1 -0
  1031. package/data/problems/zigzag-conversion.json +1 -0
  1032. package/data/problems/zigzag-iterator.json +1 -0
  1033. package/data/problems/zuma-game.json +1 -0
  1034. package/dist/cli.js +793 -0
  1035. package/dist/web/assets/index-7tyR3Zsa.js +147 -0
  1036. package/dist/web/assets/index-oer4U46K.css +1 -0
  1037. package/dist/web/index.html +13 -0
  1038. package/package.json +42 -3
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "600", "slug": "01-matrix", "id": 600, "title": "01 Matrix", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/01-matrix/", "examples": [{"input": "mat = [[0,0,0],[0,1,0],[0,0,0]]", "output": "[[0,0,0],[0,1,0],[0,0,0]]", "explanation": "Centre cell is one step from zero."}, {"input": "mat = [[0,0,0],[0,1,0],[1,1,1]]", "output": "[[0,0,0],[0,1,0],[1,2,1]]", "explanation": "Bottom row distances grow with depth."}, {"input": "mat = [[0]]", "output": "[[0]]"}], "hints": ["Start a breadth-first search from all zero cells at once; the first visit to a cell gives its nearest distance.", "Initialise ones as unvisited (-1) and expand level by level in the four directions."], "statement": "You are given a rectangular binary grid `mat` containing only zeros and ones. At least one cell holds zero.\n\nFor every cell, compute how many steps it takes to reach the closest zero when you may move up, down, left, or right to a neighbouring cell. Each move costs one.\n\nReturn a grid of the same shape where each entry holds that distance.\n\n**Constraints:**\n- `m == mat.length`, `n == mat[i].length`\n- `1 <= m, n <= 100`\n- `1 <= m * n <= 10^4`\n- `mat[i][j]` is `0` or `1`\n- At least one `0` exists\n", "solution": "## Approach\n\nSeed a queue with every zero cell at distance zero and mark all ones as unseen. Repeatedly pop a cell and relax its four neighbours: the first time a neighbour is reached its distance is final because the search expands in increasing distance order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), each cell enqueued once.\n- **Space Complexity:** O(m * n) for distances and the queue.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]:\n m, n = len(mat), len(mat[0])\n dist = [[-1] * n for _ in range(m)]\n q = deque()\n for i in range(m):\n for j in range(n):\n if mat[i][j] == 0:\n dist[i][j] = 0\n q.append((i, j))\n while q:\n i, j = q.popleft()\n for di, dj in ((1,0),(-1,0),(0,1),(0,-1)):\n ni, nj = i + di, j + dj\n if 0 <= ni < m and 0 <= nj < n and dist[ni][nj] == -1:\n dist[ni][nj] = dist[i][j] + 1\n q.append((ni, nj))\n return dist\n```\n", "starter": {"go": "package main\n\nfunc UpdateMatrix(mat [][]int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> updateMatrix(vector<vector<int>>& mat) {\n return {};\n }\n};"}, "fn": "updateMatrix", "params": [{"name": "mat", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[0,0,0],[0,1,0],[0,0,0]]"], ["[[0,0,0],[0,1,0],[1,1,1]]"], ["[[0]]"], ["[[1,1,1],[1,1,1],[1,1,0]]"], ["[[0,1],[1,1]]"], ["[[1,0],[0,1]]"], ["[[1,1],[1,0]]"], ["[[0,1,1],[1,1,1],[1,1,1]]"], ["[[1,0]]"], ["[[0,1,0],[1,1,1],[0,1,0]]"], ["[[1,1,0],[1,1,1],[0,0,0]]"], ["[[0,0],[0,0]]"], ["[[1,1],[1,1],[1,0]]"], ["[[0,1,1,1],[1,1,1,1],[1,1,1,0]]"], ["[[1,0,1],[0,0,0],[1,0,1]]"], ["[[0,0,0,0],[0,1,1,0],[0,1,1,0],[0,0,0,0]]"], ["[[1,1,1,1],[1,1,1,1],[1,1,1,0]]"], ["[[0,1,1],[1,1,0],[0,0,0]]"], ["[[1,1],[0,0]]"], ["[[0,0],[1,1]]"], ["[[1,0,0],[0,0,0],[0,0,1]]"], ["[[1,1,1],[1,0,1],[1,1,1]]"], ["[[0,1],[1,0],[1,1]]"], ["[[1,1,0,0],[0,1,1,0],[0,0,0,1]]"], ["[[0,0,1],[0,1,1],[1,1,1]]"], ["[[1,1,1,0],[0,0,0,0]]"], ["[[0,1,0,1,0]]"], ["[[0],[1],[1],[0]]"]], "expected": [[[0, 0, 0], [0, 1, 0], [0, 0, 0]], [[0, 0, 0], [0, 1, 0], [1, 2, 1]], [[0]], [[4, 3, 2], [3, 2, 1], [2, 1, 0]], [[0, 1], [1, 2]], [[1, 0], [0, 1]], [[2, 1], [1, 0]], [[0, 1, 2], [1, 2, 3], [2, 3, 4]], [[1, 0]], [[0, 1, 0], [1, 2, 1], [0, 1, 0]], [[2, 1, 0], [1, 1, 1], [0, 0, 0]], [[0, 0], [0, 0]], [[3, 2], [2, 1], [1, 0]], [[0, 1, 2, 2], [1, 2, 2, 1], [2, 2, 1, 0]], [[1, 0, 1], [0, 0, 0], [1, 0, 1]], [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]], [[5, 4, 3, 2], [4, 3, 2, 1], [3, 2, 1, 0]], [[0, 1, 1], [1, 1, 0], [0, 0, 0]], [[1, 1], [0, 0]], [[0, 0], [1, 1]], [[1, 0, 0], [0, 0, 0], [0, 0, 1]], [[2, 1, 2], [1, 0, 1], [2, 1, 2]], [[0, 1], [1, 0], [2, 1]], [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1]], [[0, 0, 1], [0, 1, 2], [1, 2, 3]], [[1, 1, 1, 0], [0, 0, 0, 0]], [[0, 1, 0, 1, 0]], [[0], [1], [1], [0]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "725", "slug": "1-bit-and-2-bit-characters", "id": 725, "title": "1-bit and 2-bit Characters", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/1-bit-and-2-bit-characters/", "examples": [{"input": "bits = [1,0,0]", "output": "true", "explanation": "The encoding splits as 10 then 0, so the final symbol uses one bit."}, {"input": "bits = [1,1,1,0]", "output": "false", "explanation": "The only split is 11 then 10, leaving a two-bit tail."}, {"input": "bits = [0]", "output": "true", "explanation": "A lone zero is a one-bit symbol."}], "hints": ["A 1 always starts a two-bit symbol and consumes the next bit; a 0 stands alone.", "Walk from the front jumping 1 or 2 steps and see where you land relative to the last index.", "The answer is true exactly when the walk ends on the final position, not before it."], "statement": "An encoded message uses two symbol widths: `0` alone means a one-bit symbol, while `10` and `11` each mean a two-bit symbol. The given array `bits` is a valid encoding of at least one symbol.\n\nDecide whether the very last symbol occupies a single bit. In other words, walk the encoding greedily from the start \u2014 a `1` always consumes its follower, a `0` consumes only itself \u2014 and check whether the final `0` is read alone.\n\nReturn `true` when the tail symbol is one bit long, else `false`.\n\n**Constraints:**\n- `1 <= bits.length <= 1000`\n- Each entry is `0` or `1`, and the last entry is `0`.\n", "solution": "## Approach\n\nStep through the array with an index. A `1` jumps two places because it must pair with its follower; a `0` advances one place. Stop before the last cell: landing exactly on it means it was read alone.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the array length.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def isOneBitCharacter(self, bits: List[int]) -> bool:\n i = 0\n n = len(bits)\n while i < n - 1:\n i += 2 if bits[i] == 1 else 1\n return i == n - 1\n```\n", "starter": {"go": "package main\n\nfunc IsOneBitCharacter(bits []int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def isOneBitCharacter(self, bits: List[int]) -> bool:\n return False", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool isOneBitCharacter(vector<int>& bits) {\n return false;\n }\n};"}, "fn": "isOneBitCharacter", "params": [{"name": "bits", "type": "int_array"}], "outputType": "boolean", "tests": [["[1,0,0]"], ["[1,1,1,0]"], ["[0]"], ["[1,0]"], ["[0,0]"], ["[1,1,0]"], ["[1,0,1,0]"], ["[0,1,0]"], ["[1,1,1,1,0]"], ["[0,0,0]"], ["[1,0,0,0]"], ["[1,1,0,0]"], ["[0,1,1,0]"], ["[1,0,1,1,0]"], ["[1,1,1,1,1,0]"], ["[0,0,0,0]"], ["[1,0,0,1,0]"], ["[1,1,0,1,0]"], ["[0,1,0,0]"], ["[1,0,1,0,0]"], ["[1,1,1,0,0]"], ["[0,0,1,0]"], ["[1,1,0,0,0]"], ["[1,0,0,0,0]"], ["[0,1,1,1,0]"], ["[1,1,1,1,0,0]"], ["[0,0,0,0,0]"], ["[1,0,1,1,1,0]"]], "expected": [true, false, true, false, true, true, false, false, true, true, true, true, true, true, false, true, false, false, true, true, true, false, true, true, false, true, true, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "523", "slug": "132-pattern", "id": 523, "title": "132 Pattern", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/132-pattern/", "examples": [{"input": "nums = [1,2,3,4]", "output": "false", "explanation": "Every triple is increasing, so no middle value sits strictly between a smaller earlier value and a larger middle value."}, {"input": "nums = [3,1,4,2]", "output": "true", "explanation": "Indices 1, 2, 3 hold values 1, 4, 2, and 1 < 2 < 4."}, {"input": "nums = [-1,3,2,0]", "output": "true", "explanation": "The values -1, 3, 2 at indices 0, 1, 2 satisfy -1 < 2 < 3."}], "hints": ["Scan from right to left while keeping candidates for the middle value on a decreasing stack.", "Track the largest value popped so far as the best achievable `nums[k]`; any earlier smaller value completes the pattern."], "statement": "You are given an array `nums`. A `132 pattern` is a triple of positions `i < j < k` whose values sit in small-large-middle order:\n\n```\nnums[i] < nums[k] < nums[j]\n```\n\nReturn `true` if such a triple exists, and `false` otherwise.\n\n**Constraints:**\n- `1 <= nums.length <= 2 * 10^5`\n- `-10^9 <= nums[i] <= 10^9`\n", "solution": "## Approach\n\nWalk the array from right to left while maintaining a decreasing stack of candidates for the large middle position `nums[j]`. Whenever the current value exceeds the stack top, pop it and remember the biggest popped value as the best achievable `nums[k]` seen so far. If the current value is smaller than that remembered `nums[k]`, the three positions form the required small-large-middle ordering.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), since each element is pushed and popped at most once.\n- **Space Complexity:** O(n) for the stack in the worst case.\n\n## Implementation\n\n```python\nclass Solution:\n def find132pattern(self, nums: list) -> bool:\n st = []\n third = float(\"-inf\")\n for v in reversed(nums):\n if v < third:\n return True\n while st and v > st[-1]:\n third = st.pop()\n st.append(v)\n return False\n```\n", "starter": {"go": "package main\n\nfunc Find132pattern(nums []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def find132pattern(self, nums: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool find132pattern(vector<int>& nums) {\n return false;\n }\n};"}, "fn": "find132pattern", "params": [{"name": "nums", "type": "int_array"}], "outputType": "boolean", "tests": [["[1,2,3,4]"], ["[3,1,4,2]"], ["[-1,3,2,0]"], ["[3,5,0,3,4]"], ["[1,2,3,2,1]"], ["[1]"], ["[1,2]"], ["[2,1]"], ["[1,1,1]"], ["[1,3,2]"], ["[3,1,2]"], ["[2,4,3,1]"], ["[4,3,2,1]"], ["[1,0,1,-4,-3]"], ["[6,7,1,2,3,4,5]"], ["[-1,-2,-3,1,2]"], ["@javascript:JSON.stringify(Array.from({length:20000},(_,i)=>20000-i))"], ["[1,3,2,4]"], ["[3,2,1,0]"], ["[1,4,2,3]"], ["[5,4,3,2,1,0]"], ["[-5,-4,-3,-2,-1]"], ["[2,1,5,0,4,6]"], ["[0,1000000000,-1000000000,500000000]"], ["[1,0,1,0,1]"], ["[3,3,3,2,2,1]"], ["[1,5,2,4,3]"], ["[-2,-1,0,-3,-4,2]"]], "expected": [false, true, true, true, true, false, false, false, false, true, false, true, false, false, false, false, false, true, false, true, false, false, true, true, false, false, true, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "670", "slug": "2-keys-keyboard", "id": 670, "title": "2 Keys Keyboard", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/2-keys-keyboard/", "examples": [{"input": "n = 3", "output": "3", "explanation": "Copy (1) then paste twice: 1 -> 2 -> 3."}, {"input": "n = 1", "output": "0", "explanation": "The single A is already there."}, {"input": "n = 6", "output": "5", "explanation": "Copy, paste to 2, copy, paste to 4, paste to 6."}], "hints": ["A paste run from size a to a multiple m*a costs one copy plus (m - 1) pastes, i.e. m steps for the factor m.", "Hence the optimum equals the sum of the prime factors of n with multiplicity.", "Peel off the smallest divisor repeatedly; whatever prime remains counts itself."], "statement": "You start with one `A` on screen and two operations: copy everything currently shown, and paste the clipboard's contents to the end. The clipboard starts empty; a copy overwrites it, and a paste does not change it.\n\nImplement `minSteps(n)` returning the fewest operations that leave exactly `n` characters on screen.\n\n**Constraints:**\n- `1 <= n <= 1000`\n", "solution": "## Approach\n\nGrowing from length 1, each copy-plus-pastes block multiplies the current size by some factor m at a cost of m steps (one copy, m-1 pastes). Building n therefore costs the sum of the multiplied factors, which is minimized by splitting n into primes. Factoring n and adding the prime factors with multiplicity gives the optimum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(sqrt(n)) for trial division.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def minSteps(self, n: int) -> int:\n if n <= 1:\n return 0\n ans, x, d = 0, n, 2\n while d * d <= x:\n while x % d == 0:\n ans += d\n x //= d\n d += 1\n if x > 1:\n ans += x\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MinSteps(n int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minSteps(self, n: int) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int minSteps(int n) {\n return 0;\n }\n};"}, "fn": "minSteps", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["3"], ["1"], ["6"], ["2"], ["4"], ["5"], ["7"], ["8"], ["9"], ["10"], ["12"], ["15"], ["18"], ["20"], ["25"], ["27"], ["30"], ["36"], ["48"], ["50"], ["64"], ["72"], ["81"], ["100"], ["128"], ["256"], ["512"], ["1000"]], "expected": [3, 0, 5, 2, 4, 5, 7, 6, 6, 7, 7, 8, 8, 9, 10, 9, 10, 10, 11, 12, 12, 12, 12, 14, 14, 16, 18, 21], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "697", "slug": "24-game", "id": 697, "title": "24 Game", "difficulty": "Hard", "category": "backtracking", "link": "https://leetcode.com/problems/24-game/", "examples": [{"input": "cards = [4,1,8,7]", "output": "true", "explanation": "(8 - 4) * (7 - 1) equals 24."}, {"input": "cards = [1,2,1,2]", "output": "false", "explanation": "No arrangement of the four values reaches 24."}, {"input": "cards = [3,3,8,8]", "output": "true", "explanation": "8 divided by (3 - 8/3) equals 24."}], "hints": ["Try every order of combining pairs with +, -, *, / in a depth-first search.", "Floating comparisons need a small tolerance (1e-6); document that divisions use doubles.", "Prune symmetric branches but keep both subtraction and division orders."], "statement": "You receive four cards, each showing an integer. Using the four arithmetic operators `+`, `-`, `*`, `/` and any placement of parentheses, decide whether an expression using every card exactly once can evaluate to 24.\n\nDivision is real division (not integer division). Two values that differ by less than `1e-6` are treated as equal when checking for 24; this tolerance rule is part of the task because intermediate results are doubles.\n\nReturn `true` when such an expression exists, otherwise `false`.\n\n**Constraints:**\n- `cards.length == 4`\n- `1 <= cards[i] <= 9`\n", "solution": "## Approach\n\nTreat the cards as doubles and repeatedly pick an ordered pair, replace it by one of its possible results (+, -, *, / when legal), and recurse. With one value left, succeed when it is within 1e-6 of 24. Trying all pairs and orders covers every parenthesization.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) \u2014 only four numbers, bounded search tree.\n- **Space Complexity:** O(1) recursion depth.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def judgePoint24(self, cards: List[int]) -> bool:\n vals = [float(c) for c in cards]\n def dfs(arr):\n if len(arr) == 1:\n return abs(arr[0] - 24.0) < 1e-6\n for i in range(len(arr)):\n for j in range(len(arr)):\n if i == j:\n continue\n rest = [arr[k] for k in range(len(arr)) if k != i and k != j]\n a, b = arr[i], arr[j]\n cands = [a + b, a - b, a * b]\n if abs(b) > 1e-9:\n cands.append(a / b)\n for v in cands:\n if dfs(rest + [v]):\n return True\n return False\n return dfs(vals)\n```\n", "starter": {"go": "package main\n\nfunc JudgePoint24(cards []int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def judgePoint24(self, cards: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool judgePoint24(vector<int>& cards) {\n return false;\n }\n};"}, "fn": "judgePoint24", "params": [{"name": "cards", "type": "int_array"}], "outputType": "boolean", "tests": [["[4,1,8,7]"], ["[1,2,1,2]"], ["[3,3,8,8]"], ["[1,1,1,1]"], ["[6,6,6,6]"], ["[1,5,5,5]"], ["[2,2,2,2]"], ["[3,3,3,3]"], ["[4,4,4,4]"], ["[5,5,5,5]"], ["[6,1,2,3]"], ["[1,1,2,6]"], ["[1,3,4,6]"], ["[2,3,4,6]"], ["[7,7,7,7]"], ["[8,8,8,8]"], ["[9,9,9,9]"], ["[1,9,9,9]"], ["[2,7,8,9]"], ["[3,4,5,6]"], ["[4,5,6,7]"], ["[1,2,3,4]"], ["[2,5,5,10]"], ["[1,4,5,6]"], ["[3,5,7,9]"], ["[6,7,8,9]"], ["[1,1,1,2]"], ["[4,4,10,10]"]], "expected": [true, false, true, false, true, true, false, true, true, true, true, true, true, true, false, false, false, false, true, true, true, true, true, true, true, true, false, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "255", "slug": "3sum-closest", "id": 255, "title": "3Sum Closest", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/3sum-closest/", "examples": [{"input": "nums = [-1,2,1,-4], target = 1", "output": "2", "explanation": "The triple (-1, 2, 1) sums to 2, the closest achievable total to 1."}, {"input": "nums = [0,0,0], target = 1", "output": "0", "explanation": "The only triple sums to 0."}], "hints": ["Sort the array first; then for each fixed first element, sweep the other two with inward-moving pointers.", "Track the best total seen so far and move the left pointer up when the sum is below target, else move the right pointer down."], "statement": "You are given an array `nums` of `n` integers and a target value `target`. Pick three entries at pairwise different positions so that their total is as near as possible to `target`, then return that total.\n\nEvery test case is constructed so that exactly one such closest total exists.\n\n**Constraints:**\n- `3 <= nums.length <= 500`\n- `-1000 <= nums[i] <= 1000`\n- `-10^4 <= target <= 10^4`\n", "solution": "## Approach\n\nSort a copy of the array so the two-pointer sweep applies. Fix each index in turn as the first element of the triple and move two pointers inward, keeping whichever total lands nearest the target. Whenever the current sum falls short of the target the left pointer advances, otherwise the right pointer retreats; an exact hit ends the search immediately.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) from sorting plus one linear sweep per fixed index.\n- **Space Complexity:** O(n) for the sorted copy (O(1) besides input storage with in-place sort).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def threeSumClosest(self, nums: List[int], target: int) -> int:\n a = sorted(nums)\n best = a[0] + a[1] + a[2]\n for i in range(len(a) - 2):\n l, r = i + 1, len(a) - 1\n while l < r:\n s = a[i] + a[l] + a[r]\n if abs(s - target) < abs(best - target):\n best = s\n if s < target:\n l += 1\n elif s > target:\n r -= 1\n else:\n return target\n return best\n```\n", "starter": {"go": "package main\n\nfunc ThreeSumClosest(nums []int, target int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def threeSumClosest(self, nums: List[int], target: int) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int threeSumClosest(vector<int>& nums, int target) {\n return 0;\n }\n};"}, "fn": "threeSumClosest", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[-1,2,1,-4]", "1"], ["[0,0,0]", "1"], ["[1,1,1,0]", "-100"], ["[1,2,3,4,5]", "10"], ["[-5,-4,-3,-2,-1]", "-8"], ["[0,1,2]", "3"], ["[0,1,2]", "0"], ["[1,1,-1,-1,3]", "-1"], ["[1000,1000,1000]", "0"], ["[-1000,-1000,-1000]", "1000"], ["[4,0,5,-5,3,3,0,0,-5]", "-2"], ["[1,2,4,8,16,32,64,128]", "82"], ["[-1,0,1,0]", "100"], ["[5,5,5,5,5]", "14"], ["[5,5,5,5,5]", "16"], ["[-2,0,1,3]", "2"], ["[0,0,0,0,1]", "1"], ["[1,-1,2,-2,3,-3]", "0"], ["[999,998,997]", "2994"], ["[1,2,4]", "5"], ["[10,20,30]", "65"], ["[-10,-20,15,25,-5]", "12"], ["[3,7,1,9,2,8]", "20"], ["[-4,-1,1,2,5,8]", "0"], ["[6,-6,6,-6,0]", "1"], ["[100,-100,50,-50,25]", "30"], ["[1,1,1,1,1,1,1]", "3"]], "expected": [2, 0, 2, 10, -8, 3, 3, -1, 3000, -3000, -2, 82, 1, 15, 15, 2, 1, 0, 2994, 7, 60, 10, 20, 0, 0, 25, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "363", "slug": "3sum-smaller", "id": 363, "title": "3Sum Smaller", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/3sum-smaller/", "examples": [{"input": "nums = [-2,0,1,3], target = 2", "output": "2", "explanation": "The triples ([-2,0,1]) and ([-2,0,3]) sum to -1 and 1, both below 2."}, {"input": "nums = [], target = 0", "output": "0", "explanation": "Fewer than three values means no triple exists."}, {"input": "nums = [3,1,0,-2], target = 4", "output": "3", "explanation": "Three of the four possible triples fall below 4."}], "hints": ["Sort the array so the two-pointer technique applies to each fixed first index.", "When the current triple is below target, every index between the pointers pairs with the fixed index, adding that many triples at once."], "statement": "Given an integer array `nums` and an integer `target`, count the index triples `(i, j, k)` with `i < j < k` whose values sum to less than `target`.\n\n**Constraints:**\n- `0 <= nums.length <= 10^4`\n- `-10^4 <= nums[i] <= 10^4`\n- `-10^4 <= target <= 10^4`\n", "solution": "## Approach\n\nSort the array and fix each first index in turn. With two pointers on the remaining suffix, a triple below the target means every index between the pointers also works with the fixed index, so add that whole block at once and move the left pointer forward. Otherwise move the right pointer inward. Each index is processed once as the fixed choice.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), where n is the length of `nums`, for sorting plus the nested two-pointer scan.\n- **Space Complexity:** O(1) besides sorting.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def threeSumSmaller(self, nums: List[int], target: int) -> int:\n a = sorted(nums)\n count = 0\n for i in range(len(a) - 2):\n lo, hi = i + 1, len(a) - 1\n while lo < hi:\n if a[i] + a[lo] + a[hi] < target:\n count += hi - lo\n lo += 1\n else:\n hi -= 1\n return count\n```\n", "starter": {"go": "package main\n\nfunc ThreeSumSmaller(nums []int, target int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def threeSumSmaller(self, nums: List[int], target: int) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int threeSumSmaller(vector<int>& nums, int target) {\n return 0;\n }\n};"}, "fn": "threeSumSmaller", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[-2,0,1,3]", "2"], ["[]", "0"], ["[0]", "0"], ["[3,1,0,-2]", "4"], ["[1,1,1]", "4"], ["[1,1,1]", "3"], ["[0,0,0]", "1"], ["[5,1,3,4,7]", "12"], ["[-2,0,-1,3]", "2"], ["[3,2,-2,6,2,-2,6,-2,-4,2,3,0,4,4,1]", "3"], ["[1,2,3,4,5]", "8"], ["[1,2,3,4,5]", "100"], ["[-4,-3,-2,-1,0]", "-5"], ["[0,0,0,0]", "1"], ["[10,-10,10,-10]", "0"], ["[1,0,-1]", "1"], ["[2,2,2,2]", "7"], ["[2,2,2,2]", "6"], ["[-1,1,-1,1]", "1"], ["[100,200,300]", "50"], ["[7,7,7,7,7,7]", "22"], ["[-100,100,-50,50,0]", "10"], ["[1,2]", "10"], ["[4,0,5,-5,3,3,0,-4,-5]", "-2"], ["[0,1,2,3,4,5,6,7,8,9]", "10"], ["[-2,-2,-2,-2]", "-5"]], "expected": [2, 0, 0, 3, 1, 0, 1, 4, 3, 151, 2, 10, 6, 4, 2, 1, 4, 0, 2, 0, 20, 6, 0, 22, 23, 4], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "910", "slug": "3sum-with-multiplicity", "id": 910, "title": "3Sum With Multiplicity", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/3sum-with-multiplicity/", "examples": [{"input": "arr = [1,1,2,2,3,3,4,4,5,5], target = 8", "output": "20", "explanation": "Twenty index triplets (i < j < k) have values summing to 8."}, {"input": "arr = [1,1,2,2,2,2], target = 5", "output": "12", "explanation": "Each choice of one of the two 1s, one of the four 2s... triplets of values (1,2,2) give 2 * 6 = 12."}, {"input": "arr = [2,1,3], target = 6", "output": "1", "explanation": "Only the triplet using all three positions sums to 6."}], "hints": ["Values are bounded (0 to 100), so counting frequencies beats enumerating triplets.", "For each value combination i <= j <= k with i + j + k == target, multiply the available choices (using nC2 / nC3 when values repeat).", "Accumulate the total modulo 1,000,000,007."], "statement": "You are given an integer array `arr` and an integer `target`. Count the triplets of positions `(i, j, k)` with `i < j < k` whose values add up to `target`.\n\nReturn that count modulo `10^9 + 7`.\n\n**Constraints:**\n- `3 <= arr.length <= 3000`\n- `0 <= arr[i] <= 100`\n- `0 <= target <= 300`\n", "solution": "## Approach\n\nBecause values are confined to 0..100, tally frequencies once and iterate over value triples `i <= j <= k` summing to the target. Each triple contributes the product of available picks, using combinations (nC2, nC3) when values coincide, all reduced modulo 1,000,000,007.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + V^2) with V = 101 distinct values.\n- **Space Complexity:** O(V) for the frequency table.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def threeSumMulti(self, arr: List[int], target: int) -> int:\n mod = 10 ** 9 + 7\n c = [0] * 101\n for v in arr:\n c[v] += 1\n ans = 0\n for i in range(101):\n if c[i] == 0:\n continue\n for j in range(i, 101):\n if c[j] == 0:\n continue\n k = target - i - j\n if k < j or k > 100 or c[k] == 0:\n continue\n if i == j == k:\n ans += c[i] * (c[i] - 1) * (c[i] - 2) // 6\n elif i == j:\n ans += c[i] * (c[i] - 1) // 2 * c[k]\n elif j == k:\n ans += c[i] * c[j] * (c[j] - 1) // 2\n else:\n ans += c[i] * c[j] * c[k]\n return ans % mod\n```\n", "starter": {"go": "package main\n\nfunc ThreeSumMulti(arr []int, target int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def threeSumMulti(self, arr: List[int], target: int) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int threeSumMulti(vector<int>& arr, int target) {\n return 0;\n }\n};"}, "fn": "threeSumMulti", "params": [{"name": "arr", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[1,1,2,2,3,3,4,4,5,5]", "8"], ["[1,1,2,2,2,2]", "5"], ["[2,1,3]", "6"], ["[0,0,0]", "0"], ["[4, 2, 4, 5, 4, 5, 0, 5, 3, 0, 0, 5, 3, 3, 1, 3, 5, 1, 4, 0]", "12"], ["[14, 1, 16, 0, 2, 17, 18, 6, 2, 14, 20, 1, 18, 4, 4, 9, 1, 9, 14, 5]", "28"], ["[2, 1, 0, 0, 1, 2, 2, 2]", "6"], ["[23, 6, 42, 3, 21, 1, 49, 42, 3, 22, 22, 29, 47, 49, 35, 39, 32, 2, 25, 4, 6, 4, 38, 18, 10, 34, 6, 5, 28, 40, 35, 30, 18, 18, 28, 37, 46, 30, 16, 15, 3, 45, 16, 20, 3, 34, 35, 29, 23, 4, 40, 8, 4, 49, 22, 5, 7, 23, 43, 29, 39, 29, 24, 36, 47, 5, 33, 10, 32, 35, 10, 43, 11, 46, 47, 12, 0, 3, 21, 9]", "136"], ["[9, 2, 7, 10]", "9"], ["[36, 47, 8, 44]", "11"], ["[3, 3, 7]", "4"], ["[2, 3, 2]", "3"], ["[24, 41, 29, 1, 3, 37, 35, 50, 43, 9]", "130"], ["[3, 18, 18, 10, 10, 19, 10, 13, 0, 17, 20, 3, 17, 13, 9, 3, 6, 17, 16, 17, 15, 14, 12, 2, 9, 4, 17, 4, 8, 19, 7, 3, 12, 6, 11, 10, 6, 5, 10, 8]", "9"], ["[2, 8, 11, 15, 10, 12, 20, 13, 9, 3, 0, 3, 18, 19, 17, 0, 0, 20, 15, 7, 5, 16, 11, 12, 6, 18, 6, 2, 20, 0, 19, 18, 4, 15, 4, 18, 17, 3, 20, 2, 3, 13, 12, 15, 5, 2, 1, 19, 13, 11, 14, 14, 9, 11, 12, 12, 18, 8, 5, 18, 11, 3, 10, 3, 1, 16, 8, 7, 19, 16, 18, 5, 1, 4, 12, 4, 10, 20, 19, 12]", "31"], ["[1, 0, 4, 0, 3, 3, 0, 0, 0, 4, 3, 2, 1, 2, 3, 0, 4, 1, 1, 4, 1, 5, 2, 5, 3, 2, 5, 4, 5, 2, 1, 1, 5, 0, 4, 1, 0, 2, 1, 2, 4, 2, 2, 0, 4, 2, 1, 2, 2, 5, 0, 4, 1, 3, 4, 1, 5, 0, 1, 4, 3, 1, 0, 2, 2, 5, 2, 2, 4, 5, 0, 4, 1, 1, 5, 4, 0, 2, 5, 3]", "14"], ["[17, 2, 18, 20]", "26"], ["[49, 5, 28, 21, 38, 8, 39, 6, 38, 23, 9, 40, 44, 40, 14, 36, 20, 10, 17, 41]", "92"], ["[10, 8, 6, 4, 3, 10, 8, 1, 1, 1]", "20"], ["[82, 46, 16]", "162"], ["[20, 83, 92, 85, 82, 66, 15, 100, 49, 23, 50, 0, 44, 61, 78]", "116"], ["[17, 18, 16, 11, 2, 16, 7, 16, 12, 14, 5, 0, 16, 10, 1, 20, 20, 15, 8, 11, 12, 20, 18, 3, 17, 9, 20, 2, 6, 16, 8, 4, 11, 6, 1, 11, 7, 2, 1, 14, 18, 5, 7, 20, 19, 18, 15, 2, 1, 4, 2, 10, 4, 9, 20, 9, 5, 19, 0, 11, 1, 10, 20, 1, 9, 9, 12, 12, 2, 8, 11, 15, 4, 9, 16, 19, 6, 11, 16, 2]", "56"], ["[2, 3, 8, 6]", "8"], ["[42, 25, 45, 37, 43, 42]", "144"], ["[5, 5, 2, 4, 3, 1, 1, 3, 1, 2, 4, 1, 1, 1, 2, 4, 1, 3, 4, 4]", "1"], ["[6, 5, 7, 4, 7]", "20"], ["[31, 38, 33, 26]", "141"], ["[6, 4, 4, 0, 2, 17, 18, 11, 14, 13, 13, 8, 16, 4, 10]", "50"]], "expected": [20, 12, 1, 1, 94, 33, 4, 45, 0, 0, 0, 0, 1, 27, 2852, 770, 0, 15, 3, 0, 3, 243, 0, 0, 0, 1, 0, 0], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "9", "slug": "3sum", "id": 9, "title": "3Sum", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/3sum/", "examples": [{"input": "nums = [-1,0,1,2,-1,-4]", "output": "[[-1,-1,2],[-1,0,1]]", "explanation": "The triplets [-1,-1,2] and [-1,0,1] each sum to 0."}, {"input": "nums = [0,1,1]", "output": "[]", "explanation": "No three numbers sum to 0. The only possible triplets are (0,1,1) which sums to 2."}, {"input": "nums = [0,0,0]", "output": "[[0,0,0]]", "explanation": "All three zeros sum to 0: [[0,0,0]]."}], "hints": ["Sort the array and use a two-pointer sweep for each fixed i, skipping duplicates to avoid repeated triplets. Output can be in any order; duplicates are not allowed."], "statement": "Your input is an integer array `nums`. Collect every triple of entries sitting at three pairwise-different positions `i`, `j`, `k` whose values cancel out, i.e. `nums[i] + nums[j] + nums[k] == 0`, and return each hit as the value triple `[nums[i], nums[j], nums[k]]`.\n\n**Constraints:**\n\n- 3 \u2264 nums.length \u2264 3000\n- -10^5 \u2264 nums[i] \u2264 10^5\n", "solution": "## Approach\n\nSort the array and use a fixed pointer i with two pointers l and r to find triplets that sum to zero. Skip duplicates to avoid duplicate triplets.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n\u00b2)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def threeSum(self, nums: List[int]) -> List[List[int]]:\n nums.sort()\n n = len(nums)\n res = []\n for i in range(n - 2):\n if i > 0 and nums[i] == nums[i - 1]:\n continue\n l, r = i + 1, n - 1\n while l < r:\n s = nums[i] + nums[l] + nums[r]\n if s < 0:\n l += 1\n elif s > 0:\n r -= 1\n else:\n res.append([nums[i], nums[l], nums[r]])\n l += 1\n r -= 1\n while l < r and nums[l] == nums[l - 1]:\n l += 1\n while l < r and nums[r] == nums[r + 1]:\n r -= 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc ThreeSum(nums []int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def threeSum(self, nums: List[int]) -> List[List[int]]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> threeSum(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "threeSum", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_array_2d", "tests": [["[-1,0,1,2,-1,-4]"], ["[0,1,1]"], ["[0,0,0]"], ["[1,-1,-1,0]"], ["[3,-2,1,0,-1,2,-1,-4]"], ["[-2,0,1,1,2]"], ["[4, -2, -2, -2, 0, 2, 2]"], ["[0,0,0,0]"], ["[0,1,2]"], ["[-100000,0,100000]"], ["[1,1,1]"], ["[-1,0,1]"], ["[-1,-1,2]"], ["[0,0,0,0,0]"], ["[1,2,3]"], ["[-3,-2,-1]"], ["[-3,1,2]"], ["[-2,-1,0,1,2,3]"], ["[-1,0,0,1]"], ["[-5,0,5]"], ["[-4,1,3]"], ["[-2,-1,3]"], ["[-10,0,10]"], ["[-1,-1,-1,2,2]"], ["[-3,0,1,2]"], ["[2,1,0,-1,-2]"], ["[-10,0,0,5,5]"], ["[-100,50,50]"], ["[-2,0,1,1]"], ["[-2,0,0,2,2]"]], "expected": [[[-1, -1, 2], [-1, 0, 1]], [], [[0, 0, 0]], [[-1, 0, 1]], [[-4, 1, 3], [-2, -1, 3], [-2, 0, 2], [-1, -1, 2], [-1, 0, 1]], [[-2, 0, 2], [-2, 1, 1]], [[-2, -2, 4], [-2, 0, 2]], [[0, 0, 0]], [], [[-100000, 0, 100000]], [], [[-1, 0, 1]], [[-1, -1, 2]], [[0, 0, 0]], [], [], [[-3, 1, 2]], [[-2, -1, 3], [-2, 0, 2], [-1, 0, 1]], [[-1, 0, 1]], [[-5, 0, 5]], [[-4, 1, 3]], [[-2, -1, 3]], [[-10, 0, 10]], [[-1, -1, 2]], [[-3, 1, 2]], [[-2, 0, 2], [-1, 0, 1]], [[-10, 5, 5]], [[-100, 50, 50]], [[-2, 1, 1]], [[-2, 0, 2]]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "671", "slug": "4-keys-keyboard", "id": 671, "title": "4 Keys Keyboard", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/4-keys-keyboard/", "examples": [{"input": "n = 3", "output": "3", "explanation": "Type three times."}, {"input": "n = 7", "output": "9", "explanation": "Type, type, type, select, copy, paste, paste: 3 -> 6 -> 9."}, {"input": "n = 1", "output": "1"}], "hints": ["Let dp[i] be the best screen size with i presses; typing once more always gives dp[i-1] + 1.", "Alternatively stop typing at some j, spend 2 presses on select+copy, then paste (i - j - 2) times to reach dp[j] * (i - j - 1).", "Take the best j with at least one paste (j <= i - 3)."], "statement": "You start with one `A` on screen and four operations: type one more `A`, copy everything shown, paste the clipboard, or select everything (select must precede a useful copy). With exactly `n` key presses, how many `A` characters can be on screen at most?\n\nImplement `maxA(n)` returning that maximum.\n\n**Constraints:**\n- `1 <= n <= 50`\n", "solution": "## Approach\n\nDefine dp[i] as the most characters reachable in i presses. Pressing plain A extends the previous best by one. Otherwise pick a breakpoint j where typing stops: two presses select and copy dp[j], and the remaining i-j-2 presses paste, multiplying to dp[j]*(i-j-1). Maximizing over valid breakpoints fills the table bottom-up.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) for n up to 50.\n- **Space Complexity:** O(n) for the table.\n\n## Implementation\n\n```python\nclass Solution:\n def maxA(self, n: int) -> int:\n dp = [0] * (n + 1)\n for i in range(1, n + 1):\n dp[i] = dp[i - 1] + 1\n for j in range(1, i - 2):\n dp[i] = max(dp[i], dp[j] * (i - j - 1))\n return dp[n]\n```\n", "starter": {"go": "package main\n\nfunc MaxA(n int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxA(self, n: int) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxA(int n) {\n return 0;\n }\n};"}, "fn": "maxA", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["3"], ["7"], ["1"], ["2"], ["4"], ["5"], ["6"], ["8"], ["9"], ["10"], ["11"], ["12"], ["13"], ["14"], ["15"], ["16"], ["17"], ["18"], ["19"], ["20"], ["21"], ["25"], ["30"], ["35"], ["40"], ["45"], ["49"], ["50"]], "expected": [3, 9, 1, 2, 4, 5, 6, 12, 16, 20, 27, 36, 48, 64, 81, 108, 144, 192, 256, 324, 432, 1296, 5184, 20736, 82944, 331776, 1048576, 1327104], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "521", "slug": "4sum-ii", "id": 521, "title": "4Sum II", "difficulty": "Medium", "category": "hash-table", "link": "https://leetcode.com/problems/4sum-ii/", "examples": [{"input": "nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]", "output": "2", "explanation": "Two index tuples sum to zero."}, {"input": "nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]", "output": "1", "explanation": "The only tuple sums to zero."}], "hints": ["Split into two pair sums: every nums1+nums2 and every nums3+nums4.", "Store frequencies of the first half in a hash map.", "For each second-half sum, look up its negation in the map."], "statement": "You are given four integer lists `nums1`, `nums2`, `nums3` and `nums4`, each of length `n`. Count the tuples `(i, j, k, l)` with one index from each list such that `nums1[i] + nums2[j] + nums3[k] + nums4[l]` equals zero.\n\nIndices may repeat across lists but each tuple position comes from its own list.\n\n**Constraints:**\n- `1 <= n <= 500`\n- `-2^28 <= nums1[i], nums2[i], nums3[i], nums4[i] <= 2^28`\n", "solution": "## Approach\n\nPair the first two lists and record how often each pair sum occurs in a hash map. Then pair the last two lists; for each sum `s`, the needed complement `-s` in the map tells how many first-half pairs complete a zero total. Summing over all second-half pairs counts every tuple.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), one step per pair in each half.\n- **Space Complexity:** O(n^2) for the pair-sum frequencies.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import defaultdict\nclass Solution:\n def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:\n freq = defaultdict(int)\n for a in nums1:\n for b in nums2:\n freq[a + b] += 1\n ans = 0\n for c in nums3:\n for d in nums4:\n ans += freq.get(-(c + d), 0)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {\n return 0;\n }\n};"}, "fn": "fourSumCount", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}, {"name": "nums3", "type": "int_array"}, {"name": "nums4", "type": "int_array"}], "outputType": "int", "tests": [["[1,2]", "[-2,-1]", "[-1,2]", "[0,2]"], ["[0]", "[0]", "[0]", "[0]"], ["[1,1]", "[1,1]", "[-1,-1]", "[-1,-1]"], ["[0,1]", "[0,-1]", "[0,1]", "[0,-1]"], ["[-1,-1]", "[-1,1]", "[-1,1]", "[1,-1]"], ["[1,2,3]", "[4,5,6]", "[-7,-8,-9]", "[0,0,0]"], ["[0,0,0]", "[0,0,0]", "[0,0,0]", "[0,0,0]"], ["[1]", "[1]", "[-1]", "[-1]"], ["[1,2]", "[-1,-2]", "[0,0]", "[0,0]"], ["[2,2]", "[2,2]", "[-2,-2]", "[-2,-2]"], ["[0,0]", "[1,-1]", "[0,0]", "[0,0]"], ["[-1,0,1]", "[-1,0,1]", "[-1,0,1]", "[-1,0,1]"], ["[5]", "[-5]", "[5]", "[-5]"], ["[10,20]", "[-10,-20]", "[0,0]", "[0,0]"], ["[1,2,3,4]", "[-4,-3,-2,-1]", "[0,0,0,0]", "[0,0,0,0]"], ["[0,0,0,0]", "[0,0,0,0]", "[0,0,0,0]", "[0,0,0,0]"], ["[100,200]", "[-100,-200]", "[50,-50]", "[-50,50]"], ["[-5,-4,-3]", "[-1,-2,-3]", "[1,2,3]", "[5,4,3]"], ["[7]", "[3]", "[-5]", "[-5]"], ["[1,1,1]", "[-1,-1,-1]", "[0,0,0]", "[0,0,0]"], ["[2]", "[-2]", "[1]", "[-1]"], ["[0,1,2]", "[-2,-1,0]", "[1,1,1]", "[-1,-1,-1]"], ["[3,3,3]", "[3,3,3]", "[-3,-3,-3]", "[-3,-3,-3]"], ["[1000000]", "[-1000000]", "[0]", "[0]"], ["[-100,100]", "[-100,100]", "[100,-100]", "[100,-100]"], ["[1,2]", "[3,4]", "[-3,-4]", "[-1,-2]"], ["[0]", "[1]", "[-1]", "[0]"], ["[5,5,5,5]", "[-5,-5,-5,-5]", "[5,5,5,5]", "[-5,-5,-5,-5]"]], "expected": [2, 1, 16, 6, 6, 18, 81, 1, 8, 16, 0, 19, 1, 8, 64, 256, 6, 19, 1, 81, 1, 27, 81, 1, 6, 6, 1, 256], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "170", "slug": "4sum", "id": 170, "title": "4Sum", "difficulty": "Medium", "category": "two-pointer", "link": "https://leetcode.com/problems/4sum/", "examples": [{"input": "nums = [1,0,-1,0,-2,2], target = 0", "output": "[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]", "explanation": "The quadruplets [-2,-1,1,2], [-2,0,0,2] and [-1,0,0,1] each sum to 0."}, {"input": "nums = [2,2,2,2,2], target = 8", "output": "[[2,2,2,2]]", "explanation": "The only quadruplet [2,2,2,2] sums to 8."}], "hints": ["Sort the array and fix two indices, then use two pointers for the remaining pair.", "Skip duplicates at every level to avoid repeated quadruplets. Output order does not matter."], "statement": "You receive an array `nums` of `n` integers plus an integer `target`. Gather every quadruplet of values `[nums[a], nums[b], nums[c], nums[d]]` picked from four pairwise-distinct positions:\n\n- each index satisfies 0 \u2264 a, b, c, d < n\n- the four indices are all different from one another\n- the four chosen elements add up to exactly `target`: nums[a] + nums[b] + nums[c] + nums[d] == target\n\nThe collected quadruplets may come back in any order.\n\n**Constraints:**\n\n- 1 \u2264 nums.length \u2264 200\n- -10^9 \u2264 nums[i] \u2264 10^9\n- -10^9 \u2264 target \u2264 10^9\n", "solution": "## Approach\n\nSort the array, then fix two indices `i` and `j` and use two pointers `l` and `r` for the remaining pair. When the four sum equals the target, record the quadruplet and skip duplicates. Skipping duplicates at every level guarantees unique quadruplets, and the output order does not matter.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n\u00b3), where n is the length of the array. Sorting is O(n log n) and the triple nested sweep dominates.\n- **Space Complexity:** O(1) extra besides the output (O(n) for sorting depending on the implementation).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n nums.sort()\n n = len(nums)\n res = []\n for i in range(n - 3):\n if i > 0 and nums[i] == nums[i - 1]:\n continue\n for j in range(i + 1, n - 2):\n if j > i + 1 and nums[j] == nums[j - 1]:\n continue\n l, r = j + 1, n - 1\n while l < r:\n s = nums[i] + nums[j] + nums[l] + nums[r]\n if s == target:\n res.append([nums[i], nums[j], nums[l], nums[r]])\n lv, rv = nums[l], nums[r]\n while l < r and nums[l] == lv:\n l += 1\n while l < r and nums[r] == rv:\n r -= 1\n elif s < target:\n l += 1\n else:\n r -= 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc FourSum(nums []int, target int) [][]int {\n return [][]int{}\n}", "python": "from typing import List\nclass Solution:\n def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> fourSum(vector<int>& nums, int target) {\n return {};\n }\n};"}, "fn": "fourSum", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int_array_2d", "tests": [["[1,0,-1,0,-2,2]", "0"], ["[2,2,2,2,2]", "8"], ["[0,0,0,0]", "0"], ["[1,-2,-5,-4,-3,3,3,5]", "-11"], ["[-3,-2,-1,0,0,1,2,3]", "0"], ["[0,0,0,1000000000,1000000000,1000000000,1000000000]", "1000000000"], ["[-2,-1,-1,1,1,2,2]", "0"], ["[1,0,-1]", "0"], ["[1000000000,1000000000,1000000000,1000000000]", "-294967296"], ["[-1,0,1,2,-1,-4]", "-1"], ["[2,2,2,2,2,2,2]", "8"], ["[-5,5,4,-3,0,0,4,-2]", "4"], ["[0,1]", "0"], ["[0]", "0"], ["[1,2,3]", "5"], ["[1,2,3,4]", "10"], ["[1,2,3,4]", "100"], ["[0,0,0,0,0]", "0"], ["[-1,0,1,0]", "0"], ["[-3,-1,0,2,4,5]", "6"], ["[5,5,5,5,5]", "20"], ["[-5,-4,-3,-2,-1]", "-14"], ["[10,20,30,40,50]", "100"], ["[1,1,1,1]", "4"], ["[-2,-1,0,1]", "-2"], ["[0,1,2,3,4,5]", "6"], ["[-1,-1,-1,-1,2,2]", "0"], ["[100,200,-100,-200,0,50]", "50"], ["[-1000000000,-1000000000,1000000000,1000000000,0]", "0"], ["[5,4,3,2,1]", "10"]], "expected": [[[-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]], [[2, 2, 2, 2]], [[0, 0, 0, 0]], [[-5, -4, -3, 1]], [[-3, -2, 2, 3], [-3, -1, 1, 3], [-3, 0, 0, 3], [-3, 0, 1, 2], [-2, -1, 0, 3], [-2, -1, 1, 2], [-2, 0, 0, 2], [-1, 0, 0, 1]], [[0, 0, 0, 1000000000]], [[-2, -1, 1, 2], [-1, -1, 1, 1]], [], [], [[-4, 0, 1, 2], [-1, -1, 0, 1]], [[2, 2, 2, 2]], [[-5, 0, 4, 5], [-3, -2, 4, 5]], [], [], [], [[1, 2, 3, 4]], [], [[0, 0, 0, 0]], [[-1, 0, 0, 1]], [[-3, 0, 4, 5], [-1, 0, 2, 5]], [[5, 5, 5, 5]], [[-5, -4, -3, -2]], [[10, 20, 30, 40]], [[1, 1, 1, 1]], [[-2, -1, 0, 1]], [[0, 1, 2, 3]], [], [[-200, 0, 50, 200], [-100, 0, 50, 100]], [[-1000000000, -1000000000, 1000000000, 1000000000]], [[1, 2, 3, 4]]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "220", "slug": "accounts-merge", "id": 220, "title": "Accounts Merge", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/accounts-merge/", "examples": [{"input": "accounts = [[\"John\",\"johnsmith@mail.com\",\"john_newyork@mail.com\"],[\"John\",\"johnsmith@mail.com\",\"john00@mail.com\"],[\"Mary\",\"mary@mail.com\"],[\"John\",\"johnnybravo@mail.com\"]]", "output": "[[\"John\",\"john00@mail.com\",\"john_newyork@mail.com\",\"johnsmith@mail.com\"],[\"Mary\",\"mary@mail.com\"],[\"John\",\"johnnybravo@mail.com\"]]"}], "hints": ["Union emails that share an account. Then group by root and sort emails."], "statement": "Each entry `accounts[i]` opens with a holder name in `accounts[i][0]`, followed by one or more email addresses attached to that entry.\n\nEntries that share at least one email address must be fused, since that overlap proves they describe the same individual. People may happen to share a name while remaining different individuals, so a matching name alone never justifies a fusion. One person may start out with arbitrarily many entries, but every entry of theirs carries an identical name.\n\nOnce fusing is finished, emit each merged person as a single list: the shared name first, then all of their distinct emails arranged in sorted order. The merged people themselves may appear in any order.\n\n**Constraints:**\n- `1 <= accounts.length <= 1000`\n- `2 <= accounts[i].length <= 10`\n- `1 <= accounts[i][j].length <= 30`\n- `accounts[i][0]` consists of English letters\n- `accounts[i][j] (j > 0)` is a valid email\n", "solution": "## Approach\n\nUnion-find over emails. Emails in the same account are united. Group by root, sort emails, attach the name.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(A log A) where A is total emails\n- **Space Complexity:** O(A)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]:\n parent = {}\n email_name = {}\n def find(x):\n parent.setdefault(x, x)\n if parent[x] != x:\n parent[x] = find(parent[x])\n return parent[x]\n def union(a, b):\n parent[find(a)] = find(b)\n for acc in accounts:\n name = acc[0]\n for email in acc[1:]:\n email_name[email] = name\n union(acc[1], email)\n groups = {}\n for email in email_name:\n root = find(email)\n groups.setdefault(root, []).append(email)\n res = []\n for root, emails in groups.items():\n res.append([email_name[root]] + sorted(emails))\n return res\n```\n", "starter": {"go": "package main\n\nfunc AccountsMerge(accounts [][]string) [][]string {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def accountsMerge(self, accounts: List[List[str]]) -> List[List[str]]:\n ", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<string>> accountsMerge(vector<vector<string>>& accounts) {\n return {};\n }\n};"}, "fn": "accountsMerge", "params": [{"name": "accounts", "type": "string_list_2d"}], "outputType": "string_list_2d", "tests": [["[[\"John\",\"johnsmith@mail.com\",\"john_newyork@mail.com\"],[\"John\",\"johnsmith@mail.com\",\"john00@mail.com\"],[\"Mary\",\"mary@mail.com\"],[\"John\",\"johnnybravo@mail.com\"]]"], ["[[\"Gabe\",\"Gabe0@m.co\",\"Gabe3@m.co\",\"Gabe1@m.co\"],[\"Kevin\",\"Kevin3@m.co\",\"Kevin5@m.co\",\"Kevin0@m.co\"],[\"Ethan\",\"Ethan5@m.co\",\"Ethan4@m.co\",\"Ethan0@m.co\"],[\"Hanzo\",\"Hanzo3@m.co\",\"Hanzo1@m.co\",\"Hanzo0@m.co\"],[\"Fern\",\"Fern5@m.co\",\"Fern1@m.co\",\"Fern0@m.co\"]]"], ["[[\"Alex\",\"Alex5@m.co\",\"Alex4@m.co\",\"Alex0@m.co\"],[\"Ethan\",\"Ethan3@m.co\",\"Ethan3@m.co\",\"Ethan0@m.co\"],[\"Kevin\",\"Kevin4@m.co\",\"Kevin2@m.co\",\"Kevin2@m.co\"],[\"Gabe\",\"Gabe0@m.co\",\"Gabe3@m.co\",\"Gabe2@m.co\"],[\"Gabe\",\"Gabe3@m.co\",\"Gabe4@m.co\",\"Gabe2@m.co\"]]"], ["[[\"David\",\"David0@m.co\",\"David1@m.co\"],[\"David\",\"David3@m.co\",\"David4@m.co\"],[\"David\",\"David4@m.co\",\"David5@m.co\"],[\"David\",\"David2@m.co\",\"David3@m.co\"],[\"David\",\"David1@m.co\",\"David2@m.co\"]]"], ["[[\"A\",\"a@x.com\"],[\"B\",\"b@x.com\"]]"], ["[[\"Solo\",\"solo@mail.com\"]]"], ["[[\"Zoe\",\"z3@mail.com\",\"z1@mail.com\",\"z2@mail.com\"]]"], ["[[\"John\",\"a@mail.com\",\"b@mail.com\"],[\"John\",\"b@mail.com\",\"c@mail.com\"]]"], ["[[\"John\",\"a@mail.com\"],[\"John\",\"b@mail.com\"]]"], ["[[\"Alice\",\"shared@mail.com\"],[\"Alice\",\"shared@mail.com\"]]"], ["[[\"A\",\"a1@x.com\",\"a2@x.com\"],[\"A\",\"a2@x.com\",\"a3@x.com\"],[\"A\",\"a3@x.com\",\"a4@x.com\"]]"], ["[[\"Dup\",\"x@mail.com\",\"x@mail.com\",\"y@mail.com\"]]"], ["[[\"A\",\"a@x.com\"],[\"B\",\"b@x.com\"],[\"C\",\"c@x.com\"],[\"D\",\"d@x.com\"]]"], ["[[\"Star\",\"center@mail.com\",\"s1@mail.com\"],[\"Star\",\"center@mail.com\",\"s2@mail.com\"],[\"Star\",\"center@mail.com\",\"s3@mail.com\"]]"], ["[[\"Bob\",\"bob@mail.com\"],[\"Bob\",\"bob@mail.com\"]]"], ["[[\"Ann\",\"ann2@mail.com\",\"ann1@mail.com\"],[\"Ann\",\"ann3@mail.com\"],[\"Ann\",\"bob@mail.com\",\"ann1@mail.com\"]]"], ["[[\"Mike\",\"m1@mail.com\",\"m2@mail.com\",\"m3@mail.com\",\"m4@mail.com\",\"m5@mail.com\"]]"], ["[[\"K\",\"k1@mail.com\"],[\"K\",\"k1@mail.com\",\"k2@mail.com\"],[\"K\",\"k2@mail.com\",\"k3@mail.com\"],[\"L\",\"l1@mail.com\"]]"], ["[[\"Eve\",\"e1@mail.com\",\"e2@mail.com\"],[\"Adam\",\"a1@mail.com\"],[\"Eve\",\"e2@mail.com\",\"e3@mail.com\"],[\"Adam\",\"a1@mail.com\",\"a2@mail.com\"]]"], ["[[\"Tom\",\"t2@mail.com\",\"t1@mail.com\"],[\"Tom\",\"t1@mail.com\",\"t0@mail.com\"],[\"Jerry\",\"j@mail.com\"]]"], ["[[\"A\",\"a@mail.com\",\"b@mail.com\",\"c@mail.com\"],[\"A\",\"d@mail.com\",\"e@mail.com\"],[\"A\",\"c@mail.com\",\"d@mail.com\"]]"], ["[[\"X\",\"x@mail.com\"],[\"X\",\"y@mail.com\"],[\"Z\",\"z@mail.com\"],[\"X\",\"x@mail.com\",\"y@mail.com\"]]"], ["[[\"Paul\",\"p@mail.com\"],[\"Paul\",\"p@mail.com\"],[\"Paul\",\"p@mail.com\"],[\"Paige\",\"q@mail.com\"]]"], ["[[\"LongName\",\"a1@mail.com\",\"a2@mail.com\"],[\"LongName\",\"a3@mail.com\"],[\"LongName\",\"a2@mail.com\",\"a3@mail.com\"]]"], ["[[\"A\",\"m@mail.com\",\"a@mail.com\",\"z@mail.com\"]]"], ["[[\"Ben\",\"b@mail.com\"],[\"Ben\",\"c@mail.com\"],[\"Ben\",\"d@mail.com\"],[\"Ben\",\"b@mail.com\",\"c@mail.com\",\"d@mail.com\"]]"], ["[[\"Cara\",\"c1@mail.com\",\"c2@mail.com\"],[\"Cara\",\"c3@mail.com\",\"c4@mail.com\"],[\"Cara\",\"c2@mail.com\",\"c3@mail.com\"]]"], ["[[\"Nina\",\"n@mail.com\"],[\"Noah\",\"m@mail.com\"],[\"Nina\",\"n2@mail.com\"],[\"Nina\",\"n@mail.com\",\"n2@mail.com\"]]"], ["[[\"Q\",\"q1@mail.com\",\"q2@mail.com\"],[\"Q\",\"q3@mail.com\",\"q4@mail.com\"],[\"Q\",\"q5@mail.com\"]]"], ["[[\"W\",\"w1@mail.com\",\"w2@mail.com\"],[\"W\",\"w2@mail.com\",\"w1@mail.com\"]]"]], "expected": [[["John", "john00@mail.com", "john_newyork@mail.com", "johnsmith@mail.com"], ["John", "johnnybravo@mail.com"], ["Mary", "mary@mail.com"]], [["Ethan", "Ethan0@m.co", "Ethan4@m.co", "Ethan5@m.co"], ["Fern", "Fern0@m.co", "Fern1@m.co", "Fern5@m.co"], ["Gabe", "Gabe0@m.co", "Gabe1@m.co", "Gabe3@m.co"], ["Hanzo", "Hanzo0@m.co", "Hanzo1@m.co", "Hanzo3@m.co"], ["Kevin", "Kevin0@m.co", "Kevin3@m.co", "Kevin5@m.co"]], [["Alex", "Alex0@m.co", "Alex4@m.co", "Alex5@m.co"], ["Ethan", "Ethan0@m.co", "Ethan3@m.co"], ["Gabe", "Gabe0@m.co", "Gabe2@m.co", "Gabe3@m.co", "Gabe4@m.co"], ["Kevin", "Kevin2@m.co", "Kevin4@m.co"]], [["David", "David0@m.co", "David1@m.co", "David2@m.co", "David3@m.co", "David4@m.co", "David5@m.co"]], [["A", "a@x.com"], ["B", "b@x.com"]], [["Solo", "solo@mail.com"]], [["Zoe", "z1@mail.com", "z2@mail.com", "z3@mail.com"]], [["John", "a@mail.com", "b@mail.com", "c@mail.com"]], [["John", "a@mail.com"], ["John", "b@mail.com"]], [["Alice", "shared@mail.com"]], [["A", "a1@x.com", "a2@x.com", "a3@x.com", "a4@x.com"]], [["Dup", "x@mail.com", "y@mail.com"]], [["A", "a@x.com"], ["B", "b@x.com"], ["C", "c@x.com"], ["D", "d@x.com"]], [["Star", "center@mail.com", "s1@mail.com", "s2@mail.com", "s3@mail.com"]], [["Bob", "bob@mail.com"]], [["Ann", "ann1@mail.com", "ann2@mail.com", "bob@mail.com"], ["Ann", "ann3@mail.com"]], [["Mike", "m1@mail.com", "m2@mail.com", "m3@mail.com", "m4@mail.com", "m5@mail.com"]], [["K", "k1@mail.com", "k2@mail.com", "k3@mail.com"], ["L", "l1@mail.com"]], [["Adam", "a1@mail.com", "a2@mail.com"], ["Eve", "e1@mail.com", "e2@mail.com", "e3@mail.com"]], [["Jerry", "j@mail.com"], ["Tom", "t0@mail.com", "t1@mail.com", "t2@mail.com"]], [["A", "a@mail.com", "b@mail.com", "c@mail.com", "d@mail.com", "e@mail.com"]], [["X", "x@mail.com", "y@mail.com"], ["Z", "z@mail.com"]], [["Paige", "q@mail.com"], ["Paul", "p@mail.com"]], [["LongName", "a1@mail.com", "a2@mail.com", "a3@mail.com"]], [["A", "a@mail.com", "m@mail.com", "z@mail.com"]], [["Ben", "b@mail.com", "c@mail.com", "d@mail.com"]], [["Cara", "c1@mail.com", "c2@mail.com", "c3@mail.com", "c4@mail.com"]], [["Nina", "n2@mail.com", "n@mail.com"], ["Noah", "m@mail.com"]], [["Q", "q1@mail.com", "q2@mail.com"], ["Q", "q3@mail.com", "q4@mail.com"], ["Q", "q5@mail.com"]], [["W", "w1@mail.com", "w2@mail.com"]]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "248", "slug": "add-binary", "id": 248, "title": "Add Binary", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/add-binary/", "examples": [{"input": "a = \"11\", b = \"1\"", "output": "\"100\""}, {"input": "a = \"1010\", b = \"1011\"", "output": "\"10101\""}], "hints": ["Add the two strings bit by bit from the least significant digit (rightmost), carrying a 1 into the next position when a column sums to 2.", "Pad the shorter string with leading zeros, or stop once both are consumed and the carry is zero."], "statement": "Two binary numerals arrive as strings `a` and `b`. Add them together arithmetically and emit the total, again written as a binary string.\n\n**Constraints:**\n\n- `1 <= a.length, b.length <= 10^4`\n- `a` and `b` consist only of `'0'` or `'1'` characters.\n- Each string does not contain leading zeros except for the zero itself.\n", "solution": "## Approach\n\nProcess the two strings from the least significant (rightmost) digit toward the most significant, column by column. At each step add the two bits and the incoming carry: the resulting bit is `sum % 2` and the new carry is `sum / 2`. Keep going until both strings are exhausted and the carry is cleared, then reverse the accumulated result.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(max(a.length, b.length)).\n- **Space Complexity:** O(max(a.length, b.length)) for the output string.\n\n## Implementation\n\n```python\nclass Solution:\n def addBinary(self, a: str, b: str) -> str:\n i, j = len(a) - 1, len(b) - 1\n carry = 0\n result = []\n while i >= 0 or j >= 0 or carry:\n total = carry\n if i >= 0:\n total += int(a[i])\n i -= 1\n if j >= 0:\n total += int(b[j])\n j -= 1\n result.append(str(total % 2))\n carry = total // 2\n return ''.join(reversed(result))\n```", "starter": {"go": "package main\n\nfunc AddBinary(a string, b string) string {\n return \"\"\n}", "python": "class Solution:\n def addBinary(self, a: str, b: str) -> str:\n return \"\"\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string addBinary(string a, string b) {\n return \"\";\n }\n};"}, "fn": "addBinary", "params": [{"name": "a", "type": "string"}, {"name": "b", "type": "string"}], "outputType": "string", "tests": [["11", "1"], ["1010", "1011"], ["0", "0"], ["1", "1"], ["101", "0"], ["0", "101"], ["111", "111"], ["1001", "111"], ["11111111", "1"], ["1", "11111111"], ["1010101010101010", "101010101010101"], ["111111111111111111111111111111111111111111111111111111111111", "1"], ["0", "1"], ["1", "0"], ["1", "10"], ["10", "10"], ["100", "1"], ["1111", "1"], ["1111", "1111"], ["1000", "1000"], ["1110", "1"], ["10101", "10101"], ["1100", "1010"], ["10000000", "1"], ["11110000", "1111"], ["10101010", "1010101"], ["110110", "101"], ["1001", "1001"], ["11101011", "11010"], ["1000000000000000000000000000000", "111"]], "expected": ["100", "10101", "0", "10", "101", "101", "1110", "10000", "100000000", "100000000", "1111111111111111", "1000000000000000000000000000000000000000000000000000000000000", "1", "1", "11", "100", "101", "10000", "11110", "10000", "1111", "101010", "10110", "10000001", "11111111", "11111111", "111011", "10010", "100000101", "1000000000000000000000000000111"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "645", "slug": "add-bold-tag-in-string", "id": 645, "title": "Add Bold Tag in String", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/add-bold-tag-in-string/", "examples": [{"input": "s = \"abcxyz123\", dict = [\"abc\",\"123\"]", "output": "\"<b>abc</b>xyz<b>123</b>\"", "explanation": "The two words cover disjoint spans, so each gets its own tag pair."}, {"input": "s = \"aaabbcc\", dict = [\"aaa\",\"aab\",\"bc\"]", "output": "\"<b>aaabbc</b>c\"", "explanation": "Matches overlap and touch, merging into one bold run from 0 to 5."}, {"input": "s = \"abc\", dict = [\"xyz\"]", "output": "\"abc\"", "explanation": "With no hit, the string is unchanged."}], "hints": ["Mark a boolean array: for every dictionary word, flag all characters of each occurrence in s.", "Find occurrences with repeated substring search from each next start so overlaps are not skipped.", "Emit <b> when entering a flagged run and </b> when leaving one; touching runs merge automatically.", "Adaptation: the word list maps to string_array in this judge."], "statement": "You are given a text `s` and a list of keywords `dict`. Every slice of `s` that equals one of the keywords must appear bold in the answer.\n\nMarking works character by character: a character is bold when it belongs to at least one keyword occurrence (overlapping occurrences all count, and searching continues from each next index so overlaps are found). Neighboring or overlapping bold characters fuse into a single run. Wrap each maximal bold run with an opening `<b>` and a closing `</b>` tag, leaving other characters untouched.\n\nReturn the tagged string. If no keyword occurs, return `s` unchanged.\n\n**Constraints:**\n- `s` and each keyword hold lowercase letters (and digits in tests here).\n- Lengths are small enough for direct scanning.\n\n*Adaptation: the keyword list maps to `string_array` in this judge.*\n", "solution": "## Approach\n\nFlag each character covered by any keyword hit. For every word, repeatedly search forward from the previous hit plus one so overlapping copies are caught, marking the whole span. Then walk the text once, opening a tag at the start of each flagged run and closing it at the run end; adjacent flagged cells naturally join into one pair.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), where m is total keyword characters scanned against text length n with naive search.\n- **Space Complexity:** O(n) for the flag array and output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def addBoldTag(self, s: str, dict: List[str]) -> str:\n n = len(s)\n bold = [False] * n\n for w in dict:\n if not w:\n continue\n start = s.find(w, 0)\n while start != -1:\n for k in range(start, start + len(w)):\n bold[k] = True\n start = s.find(w, start + 1)\n out = []\n for i, ch in enumerate(s):\n if bold[i] and (i == 0 or not bold[i - 1]):\n out.append(\"<b>\")\n out.append(ch)\n if bold[i] and (i == n - 1 or not bold[i + 1]):\n out.append(\"</b>\")\n return \"\".join(out)\n```\n", "starter": {"go": "package main\n\nfunc AddBoldTag(s string, dict []string) string {\n \n}", "python": "from typing import List\nclass Solution:\n def addBoldTag(self, s: str, dict: List[str]) -> str:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n string addBoldTag(string s, vector<string>& dict) {\n return \"\";\n }\n};"}, "fn": "addBoldTag", "params": [{"name": "s", "type": "string"}, {"name": "dict", "type": "string_array"}], "outputType": "string", "tests": [["abcxyz123", "['abc', '123']"], ["aaabbcc", "['aaa', 'aab', 'bc']"], ["abc", "['xyz']"], ["a", "['a']"], ["aa", "['a']"], ["aa", "['aa']"], ["abc", "['abc']"], ["abcdef", "['bcd']"], ["abcdef", "['ab', 'cd', 'ef']"], ["abcdef", "['ab', 'bc', 'cd']"], ["aaaa", "['aa']"], ["abcabc", "['abc']"], ["xyz", "['x', 'y', 'z']"], ["hello", "['hell', 'ello']"], ["mississippi", "['is', 'si']"], ["abc", "['a', 'b', 'c']"], ["abcde", "['cde', 'abc']"], ["qwerty", "['qw', 'erty']"], ["ababa", "['aba']"], ["testtest", "['test']"], ["a", "['b']"], ["abc", "['abcd']"], ["aaabbb", "['aa', 'bb']"], ["abcd", "['ab', 'cd']"], ["abcd", "['bc']"], ["zzzz", "['zz', 'zzz']"], ["helloworld", "['low', 'owo']"], ["abcxyz", "['abcxyz']"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "362", "slug": "add-digits", "id": 362, "title": "Add Digits", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/add-digits/", "examples": [{"input": "num = 38", "output": "2", "explanation": "3 + 8 = 11, then 1 + 1 = 2."}, {"input": "num = 0", "output": "0", "explanation": "0 already has one digit."}, {"input": "num = 123", "output": "6", "explanation": "1 + 2 + 3 = 6, which is a single digit."}], "hints": ["Add the digits in a loop until the value is below 10.", "Alternatively use the digit-root pattern: 0 stays 0, otherwise the answer is 1 plus the remainder of num - 1 divided by 9."], "statement": "Given a non-negative integer `num`, repeatedly replace it by the sum of its decimal digits until only one digit remains. Return that final digit.\n\n**Constraints:**\n- `0 <= num <= 2^31 - 1`\n", "solution": "## Approach\n\nRepeated digit sums settle into a cycle of length 9. Zero stays zero, and every positive number reduces to 1 plus the remainder of the number minus 1 divided by 9. This computes the digit root directly without simulating each round.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def addDigits(self, num: int) -> int:\n if num == 0:\n return 0\n return 1 + (num - 1) % 9\n```\n", "starter": {"go": "package main\n\nfunc AddDigits(num int) int {\n return 0\n}", "python": "class Solution:\n def addDigits(self, num: int) -> int:\n return 0\n", "cpp": "class Solution {\npublic:\n int addDigits(int num) {\n return 0;\n }\n};"}, "fn": "addDigits", "params": [{"name": "num", "type": "int"}], "outputType": "int", "tests": [["38"], ["0"], ["123"], ["9"], ["10"], ["19"], ["99"], ["100"], ["199"], ["1000"], ["9999"], ["12345"], ["18"], ["27"], ["36"], ["777"], ["1000000"], ["2147483647"], ["11"], ["101"], ["999"], ["1000000000"], ["5"], ["999999999"], ["123456789"], ["987654321"]], "expected": [2, 0, 6, 9, 1, 1, 9, 1, 1, 1, 9, 6, 9, 9, 9, 3, 1, 1, 2, 2, 9, 1, 5, 9, 9, 9], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "647", "slug": "add-one-row-to-tree", "id": 647, "title": "Add One Row to Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/add-one-row-to-tree/", "examples": [{"input": "root = [4,2,6,3,1,5], val = 1, depth = 2", "output": "[4,1,1,2,null,null,6,3,1,5,null]", "explanation": "Every depth-1 node gains a new val-1 child on each side; old subtrees hang below the new row."}, {"input": "root = [4,2,null,3,1], val = 1, depth = 3", "output": "[4,2,null,1,1,3,null,null,1]", "explanation": "Nodes at depth 2 each receive the new row; node 2 keeps 3 under its new left child and 1 under its new right child."}, {"input": "root = [1], val = 5, depth = 1", "output": "[5,1]", "explanation": "Depth 1 replaces the root with a new node holding 5."}], "hints": ["Depth 1 is special: build a new root holding val with the old tree as its left child.", "Otherwise walk to depth-1 (breadth-first or recursion) and splice a new left and right node under each host.", "The old left subtree becomes the left child of the new left node; the old right subtree becomes the right child of the new right node."], "statement": "You are given a binary tree root, an integer `val`, and a 1-based target `depth`. Insert a full row of new nodes holding `val` at that depth.\n\n- When `depth` is 1, create a fresh root with value `val`; the previous tree becomes its left subtree.\n- Otherwise, every node currently at depth `depth-1` receives two fresh children both holding `val`. The node's former left subtree is reattached as the left child of the new left node, and its former right subtree as the right child of the new right node. Nodes already deeper simply shift one level down.\n\nReturn the (possibly new) root.\n\n**Constraints:**\n- Tree size is between 0 and 10000 nodes.\n- Depth is at least 1 and at most one past the current height plus one.\n- Values fit in 32-bit signed integers.\n", "solution": "## Approach\n\nTreat depth 1 as a special case that wraps the old tree. For deeper targets, walk down to the parents at depth-1 with a queue, then splice two fresh nodes under each parent while preserving the displaced subtrees (old left under new left, old right under new right). Every host is handled independently, so one level-order pass suffices.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), visiting each node at most once.\n- **Space Complexity:** O(w) for the queue, where w is the widest level, plus O(n) for the added row.\n\n## Implementation\n\n```python\nfrom collections import deque\nclass Solution:\n def addOneRow(self, root, val: int, depth: int):\n if depth == 1:\n node = TreeNode(val)\n node.left = root\n return node\n q = deque([root] if root else [])\n cur = 1\n while q and cur < depth - 1:\n for _ in range(len(q)):\n n = q.popleft()\n if n.left:\n q.append(n.left)\n if n.right:\n q.append(n.right)\n cur += 1\n while q:\n n = q.popleft()\n old_l, old_r = n.left, n.right\n nl = type(n)(val)\n nr = type(n)(val)\n nl.left = old_l\n nr.right = old_r\n n.left, n.right = nl, nr\n return root\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc AddOneRow(root *TreeNode, val int, depth int) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def addOneRow(self, root, val: int, depth: int):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* addOneRow(TreeNode* root, int val, int depth) {\n \n }\n};"}, "fn": "addOneRow", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "val", "type": "int"}, {"name": "depth", "type": "int"}], "outputType": "tree_node", "tests": [["[4,2,6,3,1,5]", "1", "2"], ["[4,2,null,3,1]", "1", "3"], ["[1]", "5", "1"], ["[1,2,3]", "9", "2"], ["[1,2,3]", "9", "3"], ["[1,2,3]", "9", "4"], ["[]", "1", "1"], ["[1,null,2]", "3", "2"], ["[1,2,null,3]", "7", "3"], ["[5,4,9,1,10]", "6", "2"], ["[1,2,3,4,5,6,7]", "0", "3"], ["[1]", "2", "2"], ["[2,1,3]", "4", "2"], ["[1,2,null,null,3]", "8", "3"], ["[10,5,15]", "12", "2"], ["[1,2,3,4]", "5", "4"], ["[3,1,4,null,2]", "9", "2"], ["[1,2]", "3", "2"], ["[1,null,3]", "2", "3"], ["[7]", "7", "2"], ["[1,2,3,null,4]", "6", "3"], ["[4,2,6,3,1,5]", "1", "3"], ["[4,2,6,3,1,5]", "1", "4"], ["[1,2,3,4,5]", "11", "2"], ["[100,50]", "25", "2"], ["[1,null,2,null,3]", "9", "2"], ["[8,3,10,1,6]", "2", "3"], ["[1,2,3]", "5", "1"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "488", "slug": "add-strings", "id": 488, "title": "Add Strings", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/add-strings/", "examples": [{"input": "num1 = \"11\", num2 = \"123\"", "output": "\"134\"", "explanation": "11 plus 123 is 134."}, {"input": "num1 = \"456\", num2 = \"77\"", "output": "\"533\"", "explanation": "Column addition with carries gives 533."}, {"input": "num1 = \"0\", num2 = \"0\"", "output": "\"0\""}], "hints": ["Add from the least significant digit toward the front, keeping a carry.", "Each column sums two digits plus the carry; the digit is the remainder mod 10.", "A leftover carry after the front-most column becomes a new leading digit."], "statement": "Two non-negative integers arrive as decimal strings `num1` and `num2`. They may be long, so converting the whole strings to integers (or relying on big-integer helpers) is not allowed.\n\nAdd them digit by digit and return the total, also as a decimal string without extra leading zeros (except `\"0\"` itself).\n\n**Constraints:**\n- `1 <= num1.length, num2.length <= 10^4`\n- Strings hold only digits `0-9` with no leading zeros except for `\"0\"` itself.\n", "solution": "## Approach\n\nAlign the strings at their right ends and add column by column with a carry. Each step combines the two current digits plus the incoming carry, emits the units digit, and forwards the tens digit. When both strings and the carry are exhausted, reversing the collected digits gives the sum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(max(n, m)), where n and m are the input lengths.\n- **Space Complexity:** O(max(n, m)) for the output.\n\n## Implementation\n\n```python\nclass Solution:\n def addStrings(self, num1: str, num2: str) -> str:\n i, j = len(num1) - 1, len(num2) - 1\n carry = 0\n out = []\n while i >= 0 or j >= 0 or carry:\n a = ord(num1[i]) - 48 if i >= 0 else 0\n b = ord(num2[j]) - 48 if j >= 0 else 0\n s = a + b + carry\n out.append(chr(48 + s % 10))\n carry = s // 10\n i -= 1\n j -= 1\n return \"\".join(reversed(out))\n```\n", "starter": {"go": "package main\n\nfunc AddStrings(num1 string, num2 string) string {\n return \"\"\n}", "python": "class Solution:\n def addStrings(self, num1: str, num2: str) -> str:\n return \"\"", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string addStrings(string num1, string num2) {\n return \"\";\n }\n};"}, "fn": "addStrings", "params": [{"name": "num1", "type": "string"}, {"name": "num2", "type": "string"}], "outputType": "string", "tests": [["11", "123"], ["456", "77"], ["0", "0"], ["9", "9"], ["1", "999"], ["999", "1"], ["100", "900"], ["123456789", "987654321"], ["9999999999", "1"], ["1", "1"], ["10", "10"], ["99", "1"], ["500", "500"], ["123", "877"], ["0", "12345"], ["12345", "0"], ["99999", "99999"], ["19", "19"], ["12345678901234567890", "98765432109876543210"], ["5", "5"], ["1000000", "1"], ["888", "222"], ["1010", "1011"], ["999", "999"], ["1234", "8766"], ["7", "13"], ["29", "71"], ["1009", "991"], ["55", "55"], ["123456789123456789", "111111111111111111"]], "expected": ["134", "533", "0", "18", "1000", "1000", "1000", "1111111110", "10000000000", "2", "20", "100", "1000", "1000", "12345", "12345", "199998", "38", "111111111011111111100", "10", "1000001", "1110", "2021", "1998", "10000", "20", "100", "2000", "110", "234567900234567900"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "972", "slug": "add-to-array-form-of-integer", "id": 972, "title": "Add to Array-Form of Integer", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/add-to-array-form-of-integer/", "examples": [{"input": "num = [1,2,0,0], k = 34", "output": "[1,2,3,4]", "explanation": "1200 + 34 = 1234."}, {"input": "num = [2,7,4], k = 181", "output": "[4,5,5]", "explanation": "274 + 181 = 455."}, {"input": "num = [2,1,5], k = 806", "output": "[1,0,2,1]", "explanation": "215 + 806 = 1021."}], "hints": ["Add from the least significant digit, carrying the value of k along as you move left.", "Keep emitting digits while digits of num or a nonzero carry remain; a leftover carry may add a new leading digit.", "Collect the digits backwards and reverse them at the end."], "statement": "The array form of a non-negative integer lists its decimal digits from the most\nsignificant digit to the least significant digit. For example, the array form\nof `1200` is `[1,2,0,0]`.\n\nYou are given the array form `num` of an integer together with a non-negative\ninteger `k`. Add the two values and return the array form of the result.\n\n**Constraints:**\n- `1 <= num.length <= 10^4`\n- `0 <= num[i] <= 9`\n- `0 <= k <= 10^4`\n", "solution": "## Approach\n\nWalk the digits from right to left while folding `k` into a running carry.\nAt each position add the current digit to the carry, record `carry % 10`, and\nkeep `carry / 10` for the next step. The loop continues while digits or a\nnonzero carry remain, so an overflowing carry naturally produces an extra\nleading digit. Digits are collected backwards and reversed once at the end.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(max(n, log k)), where n is the length of `num`. Each digit is visited once.\n- **Space Complexity:** O(n) for the answer list.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def addToArrayForm(self, num: List[int], k: int) -> List[int]:\n ans = []\n i = len(num) - 1\n carry = k\n while i >= 0 or carry > 0:\n if i >= 0:\n carry += num[i]\n i -= 1\n ans.append(carry % 10)\n carry //= 10\n ans.reverse()\n return ans\n```\n", "starter": {"go": "package main\n\nfunc AddToArrayForm(num []int, k int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def addToArrayForm(self, num: List[int], k: int) -> List[int]:\n return []", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> addToArrayForm(vector<int>& num, int k) {\n return {};\n }\n};"}, "fn": "addToArrayForm", "params": [{"name": "num", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int_list", "tests": [["[1,2,0,0]", "34"], ["[2,7,4]", "181"], ["[2,1,5]", "806"], ["[9,9,9,9,9,9,9,9,9,9]", "1"], ["[0]", "0"], ["[0]", "10000"], ["[1]", "9999"], ["[9]", "9"], ["[1,0]", "0"], ["[5]", "5"], ["[1,2,3]", "999"], ["[9,8,7,6,5]", "2345"], ["[1,9,9]", "1"], ["[9,9]", "11"], ["[1,1,1,1]", "8888"], ["[7]", "0"], ["[1,2,3,4,5,6,7,8,9]", "8765"], ["[4,5,6]", "44"], ["[2,4,9]", "2001"], ["[9,9,9]", "9991"], ["[1,0,0,0,0]", "1"], ["[3]", "10000"], ["[6,5,4,3,2,1]", "10000"], ["[8,8]", "88"], ["[1,2]", "9000"], ["[9,0,9,0]", "1010"], ["[5,5,5,5,5]", "5555"], ["[1,0,0,0,0,0,0,0,0,0]", "9999"]], "expected": [[1, 2, 3, 4], [4, 5, 5], [1, 0, 2, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 8], [1, 0], [1, 0], [1, 1, 2, 2], [1, 0, 1, 1, 1, 0], [2, 0, 0], [1, 1, 0], [9, 9, 9, 9], [7], [1, 2, 3, 4, 6, 5, 5, 5, 4], [5, 0, 0], [2, 2, 5, 0], [1, 0, 9, 9, 0], [1, 0, 0, 0, 1], [1, 0, 0, 0, 3], [6, 6, 4, 3, 2, 1], [1, 7, 6], [9, 0, 1, 2], [1, 0, 1, 0, 0], [6, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 9, 9, 9, 9]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "513", "slug": "add-two-numbers-ii", "id": 513, "title": "Add Two Numbers II", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/add-two-numbers-ii/", "examples": [{"input": "l1 = [7,2,4,3], l2 = [5,6,4]", "output": "[7,8,0,7]", "explanation": "7243 + 564 = 7807."}, {"input": "l1 = [2,4,3], l2 = [5,6,4]", "output": "[8,0,7]", "explanation": "243 + 564 = 807."}, {"input": "l1 = [0], l2 = [0]", "output": "[0]", "explanation": "0 + 0 = 0."}], "hints": ["Forward order means the least significant digits are at the tails; stacks expose them in addition order.", "Push both lists, then pop pairs with a carry, prepending each new digit.", "A leftover carry becomes a new leading node."], "statement": "Two non-negative numbers are stored as linked lists with the most significant digit first. Each node holds one digit, and there are no leading zeros except for the number zero itself.\n\nGiven the heads `l1` and `l2`, add the two numbers and return the sum in the same forward layout, again without leading zeros.\n\n**Constraints:**\n- Each list has `1` to `100` nodes.\n- Each node value lies in `0..9`.\n", "solution": "## Approach\n\nBecause the heads hold the most significant digits, push both lists onto stacks to reach the ones place first. Repeatedly pop one digit from each stack plus the carry, create the result digit, and prepend it to the answer. Continue until both stacks and the carry are empty.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m + n), where m and n are the two list lengths.\n- **Space Complexity:** O(m + n) for the two stacks.\n\n## Implementation\n\n```python\nclass Solution:\n def addTwoNumbers(self, l1, l2):\n s1, s2 = [], []\n p = l1\n while p:\n s1.append(p.val)\n p = p.next\n p = l2\n while p:\n s2.append(p.val)\n p = p.next\n carry = 0\n head = None\n while s1 or s2 or carry:\n total = carry\n if s1:\n total += s1.pop()\n if s2:\n total += s2.pop()\n node = ListNode(total % 10)\n node.next = head\n head = node\n carry = total // 10\n return head\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc AddTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {\n return nil\n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def addTwoNumbers(self, l1, l2):\n pass\n", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\n return nullptr;\n }\n};"}, "fn": "addTwoNumbers", "params": [{"name": "l1", "type": "list_node"}, {"name": "l2", "type": "list_node"}], "outputType": "list_node", "tests": [["[7,2,4,3]", "[5,6,4]"], ["[2,4,3]", "[5,6,4]"], ["[0]", "[0]"], ["[1]", "[9,9,9]"], ["[9,9,9]", "[1]"], ["[5]", "[5]"], ["[9,9]", "[9,9]"], ["[1,0,0]", "[9,9]"], ["[9,9,9,9]", "[9,9,9,9]"], ["[3,9,9]", "[7]"], ["[8,9]", "[2]"], ["[1,2,3,4]", "[5,6,7,8]"], ["[9]", "[9]"], ["[1,0]", "[9,9]"], ["[4,5,6]", "[7,8,9]"], ["[1,0,0,0]", "[1]"], ["[9,9,9,9,9]", "[1]"], ["[1,2,3]", "[9,9,9]"], ["[9,8,7]", "[1,2,3]"], ["[1,0,1]", "[9,9,9]"], ["[5,0,0]", "[5,0,0]"], ["[9,0,9]", "[1,1,1]"], ["[2,0,0,0,0]", "[8,0,0,0,0]"], ["[4]", "[6]"], ["[7,7,7]", "[3,3,3]"], ["[1,9,9]", "[8,0,1]"], ["[6,2,8]", "[3,7,2]"], ["[9,9,0]", "[1,0]"]], "expected": [[7, 8, 0, 7], [8, 0, 7], [0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0], [1, 9, 8], [1, 9, 9], [1, 9, 9, 9, 8], [4, 0, 6], [9, 1], [6, 9, 1, 2], [1, 8], [1, 0, 9], [1, 2, 4, 5], [1, 0, 0, 1], [1, 0, 0, 0, 0, 0], [1, 1, 2, 2], [1, 1, 1, 0], [1, 1, 0, 0], [1, 0, 0, 0], [1, 0, 2, 0], [1, 0, 0, 0, 0, 0], [1, 0], [1, 1, 1, 0], [1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "93", "slug": "add-two-numbers", "id": 93, "title": "Add Two Numbers", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/add-two-numbers/", "examples": [{"input": "l1 = [2,4,3], l2 = [5,6,4]", "output": "[7,0,8]", "explanation": "342 + 465 = 807."}, {"input": "l1 = [0], l2 = [0]", "output": "[0]", "explanation": "0 + 0 = 0. Stored in reversed order as [0]."}, {"input": "l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]", "output": "[8,9,9,9,0,0,0,1]", "explanation": "9999999 + 9999 = 10009998. Stored in reversed order as [8, 9, 9, 9, 0, 0, 0, 1]."}], "hints": ["Walk through both lists together and add corresponding digits plus a carry.", "Create a result node for `sum % 10` and carry `sum / 10` into the next position.", "After both lists end, append one more node if a carry remains."], "statement": "Two non-negative integers are handed to you, each encoded as a non-empty linked list with the least significant digit first: every node stores a single decimal digit, so the head holds the ones place, the next node the tens place, and so on. Compute the arithmetic total of the two encoded integers and hand it back encoded the same way, least significant digit first.\n\nWritten out normally, neither input carries a leading zero, apart from the value zero itself, which is written as the lone digit zero.\n\n**Constraints:**\n\n- Each list contains between `1` and `100` nodes.\n- `0 <= node.val <= 9`\n- Each list represents a number without leading zeros, except the single-node\n list `[0]`.\n", "solution": "## Approach\n\nWalk through both reverse-order digit lists together. Add the available digits and the carry, append a node containing the ones digit, and carry the tens digit into the next position. Continue until both inputs and the final carry are exhausted.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(max(m, n)), where `m` and `n` are the input lengths.\n- **Space Complexity:** O(max(m, n)) for the returned list; the auxiliary pointer state is O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def addTwoNumbers(self, l1, l2):\n dummy = ListNode(0)\n tail = dummy\n carry = 0\n\n while l1 is not None or l2 is not None or carry:\n total = carry\n if l1 is not None:\n total += l1.val\n l1 = l1.next\n if l2 is not None:\n total += l2.val\n l2 = l2.next\n\n tail.next = ListNode(total % 10)\n tail = tail.next\n carry = total // 10\n\n return dummy.next\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc AddTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {\n return nil\n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def addTwoNumbers(self, l1, l2):\n pass\n", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {\n return nullptr;\n }\n};"}, "fn": "addTwoNumbers", "params": [{"name": "l1", "type": "list_node"}, {"name": "l2", "type": "list_node"}], "outputType": "list_node", "tests": [["[2,4,3]", "[5,6,4]"], ["[0]", "[0]"], ["[9,9,9,9,9,9,9]", "[9,9,9,9]"], ["[1]", "[9]"], ["[9]", "[1]"], ["[5]", "[5]"], ["[1]", "[0]"], ["[0]", "[7]"], ["[3,2]", "[4,5]"], ["[9,9]", "[1]"], ["[1]", "[9,9]"], ["[5,4]", "[5,5]"], ["[8,1]", "[1,8]"], ["[0,1]", "[0,9]"], ["[7,3]", "[8,6]"], ["[1,2,3]", "[4,5,6]"], ["[9,8,7]", "[1,1,2]"], ["[9,9,9]", "[1]"], ["[1]", "[9,9,9]"], ["[5,5,5]", "[5,5,5]"], ["[6,7,8]", "[4,2,1]"], ["[0,0,1]", "[0,0,9]"], ["[4,6,5]", "[6,3,4]"], ["[2,4,3]", "[5]"], ["[5]", "[2,4,3]"], ["[9,0,1]", "[1,9]"], ["[1,9]", "[9,0,1]"], ["[8,9,9,9]", "[2]"], ["[2]", "[8,9,9,9]"], ["[3,1,4,1]", "[5,9,2,6]"], ["[7,7,7,7]", "[2,2,2,2]"], ["[9,9,9,9]", "[9,9,9,9]"], ["[0,0,0,1]", "[9,9,9]"], ["[4,3,2,1]", "[6,6,7,8]"], ["[1,0,0,0,1]", "[9,9,9,9]"], ["[9,9,9,9]", "[1,0,0,0,1]"], ["[2,7,1,8,2]", "[8,2,8,1,7]"], ["[9,0,9,0,9]", "[1,9,0,9,1]"], ["[5,0,0,0,5]", "[5,9,9,9,4]"], ["[1,2,3,4,5]", "[5,4,3,2,1]"], ["[9,9,9,9,9]", "[1]"], ["[1]", "[9,9,9,9,9]"], ["[9,8,7,6,5,4]", "[1,2,3]"], ["[1,2,3]", "[9,8,7,6,5,4]"], ["[6,5,4,3,2,1]", "[4,4,5,6,7,8]"], ["[0,0,0,0,0,1]", "[0,0,0,0,0,9]"], ["[9,9,0,0,9,9]", "[1,0,9,9,0,1]"], ["[3,1,4,1,5,9]", "[2,6,5,3,5,8]"], ["[8,8,8,8,8,8,8]", "[1,1,1,1,1,1,1]"], ["[9,9,9,9,9,9,9,9]", "[9,9,9,9,9,9,9,9]"], ["[1,0,1,0,1,0,1,0,1]", "[9,9,8,9,8,9,8,9,8]"], ["[7,6,5,4,3,2,1,9,8,7]", "[3,3,4,5,6,7,8,0,1,2]"], ["@javascript:JSON.stringify([...Array(98).fill(0),1])", "@javascript:JSON.stringify([...Array(98).fill(9),8])"], ["@javascript:JSON.stringify(Array(100).fill(9))", "@javascript:JSON.stringify(Array(100).fill(9))"]], "expected": [[7, 0, 8], [0], [8, 9, 9, 9, 0, 0, 0, 1], [0, 1], [0, 1], [0, 1], [1], [7], [7, 7], [0, 0, 1], [0, 0, 1], [0, 0, 1], [9, 9], [0, 0, 1], [5, 0, 1], [5, 7, 9], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [0, 1, 1, 1], [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [7, 4, 3], [7, 4, 3], [0, 0, 2], [0, 0, 2], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [8, 0, 7, 7], [9, 9, 9, 9], [8, 9, 9, 9, 1], [9, 9, 9, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 2], [0, 0, 0, 0, 2], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 1], [6, 6, 6, 6, 6], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1], [0, 1, 1, 7, 5, 4], [0, 1, 1, 7, 5, 4], [0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 1, 1], [5, 7, 9, 4, 0, 8, 1], [9, 9, 9, 9, 9, 9, 9], [8, 9, 9, 9, 9, 9, 9, 9, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9], [8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "398", "slug": "additive-number", "id": 398, "title": "Additive Number", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/additive-number/", "examples": [{"input": "num = \"112358\"", "output": "true", "explanation": "Splits as 1, 1, 2, 3, 5."}, {"input": "num = \"199100199\"", "output": "true", "explanation": "Splits as 1, 99, 100, 199."}, {"input": "num = \"1023\"", "output": "false", "explanation": "No valid additive split exists."}], "hints": ["Only the first two numbers are free choices; everything after is forced by the sum rule.", "Reject any candidate first or second number with a leading zero and length above one.", "Add with digit strings (or big integers) since values can outgrow fixed-size types."], "statement": "A string of digits is additive when it can be split into at least three numbers where every\nnumber from the third on equals the sum of the previous two (like 1, 1, 2, 3, 5). Numbers\nmay not carry leading zeros unless the number itself is exactly `\"0\"`. Decide whether the\ngiven digit string `num` is additive.\n\n**Constraints:**\n- `1 <= num.length <= 35`\n- `num` contains only digits.\n", "solution": "## Approach\n\nEnumerate the lengths of the first two numbers (respecting the no-leading-zero rule), then verify the forced sums match the rest of the string using string addition.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^3)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nclass Solution:\n def isAdditiveNumber(self, num: str) -> bool:\n n = len(num)\n def add_str(x: str, y: str) -> str:\n i, j, carry, out = len(x) - 1, len(y) - 1, 0, []\n while i >= 0 or j >= 0 or carry:\n s = carry\n if i >= 0:\n s += ord(x[i]) - 48\n i -= 1\n if j >= 0:\n s += ord(y[j]) - 48\n j -= 1\n out.append(chr(48 + s % 10))\n carry = s // 10\n return ''.join(reversed(out))\n for i in range(1, n):\n if i > 1 and num[0] == '0':\n break\n for j in range(1, n - i):\n if j > 1 and num[i] == '0':\n break\n x, y, k = num[:i], num[i:i + j], i + j\n while k < n:\n z = add_str(x, y)\n if not num.startswith(z, k):\n break\n k += len(z)\n x, y = y, z\n else:\n return True\n return False\n```\n", "starter": {"go": "package main\n\nfunc IsAdditiveNumber(num string) bool {\n return false\n}", "python": "class Solution:\n def isAdditiveNumber(self, num: str) -> bool:\n ", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isAdditiveNumber(string num) {\n return false;\n }\n};"}, "fn": "isAdditiveNumber", "params": [{"name": "num", "type": "string"}], "outputType": "boolean", "tests": [["112358"], ["199100199"], ["1023"], ["123"], ["000"], ["101"], ["011235813"], ["112"], ["111"], ["1235"], ["121224"], ["11235813"], ["199100200"], ["0000"], ["1010"], ["123456789"], ["9999999999"], ["1357924680"], ["11235813213455"], ["100100200"], ["123581321"], ["10101"], ["999"], ["1000"], ["1000000000000000"], ["144233377610987"], ["1235813"], ["1020305"]], "expected": [true, true, false, true, true, true, true, true, false, true, true, true, false, true, false, false, false, false, true, true, true, false, false, false, false, true, true, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "864", "slug": "advantage-shuffle", "id": 864, "title": "Advantage Shuffle", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/advantage-shuffle/", "examples": [{"input": "nums1 = [2,7,11,15], nums2 = [1,10,4,11]", "output": "[2,11,7,15]", "explanation": "All four positions beat the opponent."}, {"input": "nums1 = [12,24,8,32], nums2 = [13,25,32,11]", "output": "[24,32,8,12]", "explanation": "Three positions beat the opponent, optimal."}, {"input": "nums1 = [1,1], nums2 = [1,1]", "output": "[1,1]", "explanation": "No position can beat."}], "hints": ["Sort one copy of `nums1` and pair each `nums2` value with its original index, then handle the opponent's values from smallest to largest.", "For each opponent value in order, play the smallest remaining card that beats it; if none beats it, sacrifice the smallest remaining card.", "A balanced multiset with lower-bound search, or two pointers over sorted arrays with a deque assignment, implements this greedy choice."], "statement": "You are given two arrays `nums1` and `nums2` of equal length `n`. You may reorder `nums1` arbitrarily; call the reordered version `ans`.\n\nThe advantage of `ans` over `nums2` is the count of positions `i` where `ans[i] > nums2[i]`. Arrange `ans` to make this count as large as possible.\n\nReturn any rearrangement of `nums1` achieving the maximum advantage. The checker verifies that your output uses exactly the same multiset as `nums1` and reaches the best achievable count, not that it matches one particular ordering.\n\n**Constraints:**\n- `1 <= nums1.length == nums2.length <= 10^5`\n- `0 <= nums1[i], nums2[i] <= 10^9`\n", "solution": "## Approach\n\nSort the opponent's positions from weakest to strongest while keeping the cards in a counted multiset. For the strongest remaining opponent, spend the smallest card that still beats it; if no such card exists, sacrifice the weakest card. Working from large to small guarantees every winnable slot is won with minimal waste, which maximizes the total count.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting and multiset operations.\n- **Space Complexity:** O(n) for the ordering and answer.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom bisect import bisect_right\n\nclass Solution:\n def advantageCount(self, nums1: List[int], nums2: List[int]) -> List[int]:\n import bisect\n n = len(nums1)\n order = sorted(range(n), key=lambda i: nums2[i])\n pool = sorted(nums1)\n ans = [0] * n\n # two-pointer assignment using sorted pool\n for idx in reversed(order):\n opp = nums2[idx]\n pos = bisect.bisect_right(pool, opp)\n if pos < len(pool):\n ans[idx] = pool.pop(pos)\n else:\n ans[idx] = pool.pop(0)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc AdvantageCount(nums1 []int, nums2 []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def advantageCount(self, nums1: List[int], nums2: List[int]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> advantageCount(vector<int>& nums1, vector<int>& nums2) {\n return {};\n }\n};"}, "fn": "advantageCount", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}], "outputType": "int_array", "tests": [["[2,7,11,15]", "[1,10,4,11]"], ["[12,24,8,32]", "[13,25,32,11]"], ["[1,1]", "[1,1]"], ["[2,0,4,1,2]", "[1,3,0,0,2]"], ["[0]", "[0]"], ["[5]", "[3]"], ["[3]", "[5]"], ["[1,2,3,4,5]", "[1,2,3,4,5]"], ["[5,4,3,2,1]", "[1,2,3,4,5]"], ["[10,10,10]", "[9,9,9]"], ["[1,10,4,2]", "[5,6,7,8]"], ["[8,2,4,4,5,6,6,7]", "[0,1,2,3,4,5,6,7]"], ["[100,200,300]", "[150,150,150]"], ["[7,7,7,7]", "[7,7,7,7]"], ["[1,3,5,7,9]", "[2,4,6,8,10]"], ["[2,4,6,8,10]", "[1,3,5,7,9]"], ["[0,0,10,10]", "[5,5,5,5]"], ["[6,5,4,3,2,1]", "[1,1,1,1,1,1]"], ["[1,2]", "[3,4]"], ["[4,3]", "[1,2]"], ["[9,8,7,6,5,4]", "[0,0,0,9,9,9]"], ["[11,22,33]", "[33,22,11]"], ["[5,15,20,25]", "[10,10,10,30]"], ["[1000,0,1000,0]", "[500,500,500,500]"], ["[1,2,3]", "[2,3,1]"], ["[7,1,5,3]", "[6,2,4,8]"], ["[13,25,32,11]", "[12,24,8,32]"], ["[0,1,2,3,4,5,6,7,8,9]", "[9,8,7,6,5,4,3,2,1,0]"]], "expected": [[2, 11, 7, 15], [24, 32, 8, 12], [1, 1], [2, 4, 2, 1, 0], [0], [5], [3], [2, 3, 4, 5, 1], [2, 3, 4, 5, 1], [10, 10, 10], [4, 2, 1, 10], [6, 2, 4, 4, 5, 6, 7, 8], [100, 300, 200], [7, 7, 7, 7], [3, 5, 7, 9, 1], [2, 4, 6, 8, 10], [0, 0, 10, 10], [1, 6, 5, 4, 3, 2], [2, 1], [4, 3], [9, 8, 7, 6, 5, 4], [11, 33, 22], [25, 20, 15, 5], [0, 0, 1000, 1000], [3, 1, 2], [7, 3, 5, 1], [13, 25, 32, 11], [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "32", "slug": "alien-dictionary", "id": 32, "title": "Alien Dictionary", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/alien-dictionary/", "examples": [{"input": "words = [\"wrt\",\"wrf\",\"er\",\"ett\",\"rftt\"]", "output": "\"wertf\" (one valid order)", "explanation": "The valid character order derived from the given words is \"wertf\"."}, {"input": "words = [\"z\",\"x\"]", "output": "\"zx\"", "explanation": "The valid character order derived from the given words is \"zx\"."}], "hints": ["Build a graph of precedence constraints from adjacent words and perform topological sort. If a cycle exists or an invalid prefix condition occurs, return an empty string."], "statement": "There is a new alien language that uses the English alphabet (lowercase letters a-z). However, the order of the letters is unknown to you.\n\nYou are given a list of strings `words` from the alien language's dictionary, where the strings are **sorted lexicographically** by the rules of this new language.\n\nDerive the order of characters in this alien language and return it as a string. If the given arrangement of words cannot correspond to any valid order of letters (e.g., due to a cycle in the character dependencies, or a longer word appearing before its prefix), return `\"\"`. If there are multiple valid orders, return **any** of them.\n\n**Constraints:**\n\n- 1 <= words.length <= 100\n- 1 <= words[i].length <= 100\n- words[i] consists of only lowercase English letters.\n", "solution": "## Approach\n\nBuild a directed graph containing every character in the input. For each adjacent pair of words, the first differing characters give an ordering constraint. Store each edge only once so that indegrees count distinct dependencies. If no characters differ and the first word is longer, the dictionary is invalid because a word cannot precede its own prefix.\n\nPerform topological sort using Kahn's algorithm: repeatedly remove a character with zero indegree and release its outgoing dependencies. If not all characters are processed, the graph contains a cycle, so return `\"\"`.\n\n## Complexity Analysis\n\n- **Time Complexity:** **O(N \u00d7 L)**, where N = `words.length` and L is the maximum length of a word in `words`. Initializing the graph scans at most N \u00d7 L characters. Each of the N \u2212 1 adjacent-word comparisons examines at most L characters. The topological sort takes constant time relative to the input size because the input contains only 26 possible lowercase English letters and each directed edge is stored only once.\n- **Auxiliary Space Complexity:** **O(1)**. The graph has at most 26 characters and 26\u00b2 distinct directed edges. The indegrees, queue, and result each hold at most 26 characters. The prefix check does not create string slices.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\n\nclass Solution:\n def alienOrder(self, words: List[str]) -> str:\n adj = {c: set() for w in words for c in w}\n indeg = {c: 0 for c in adj}\n for i in range(len(words) - 1):\n w1, w2 = words[i], words[i + 1]\n for j in range(min(len(w1), len(w2))):\n if w1[j] != w2[j]:\n if w2[j] not in adj[w1[j]]:\n adj[w1[j]].add(w2[j])\n indeg[w2[j]] += 1\n break\n else:\n if len(w1) > len(w2):\n return \"\"\n\n q = deque(c for c in indeg if indeg[c] == 0)\n res = []\n while q:\n c = q.popleft()\n res.append(c)\n for nb in adj[c]:\n indeg[nb] -= 1\n if indeg[nb] == 0:\n q.append(nb)\n return \"\".join(res) if len(res) == len(adj) else \"\"\n```\n", "starter": {"go": "package main\n\nfunc AlienOrder(words []string) string {\n \n}", "python": "from typing import List\nclass Solution:\n def alienOrder(self, words: List[str]) -> str:\n pass\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string alienOrder(vector<string>& words) {\n return \"\";\n }\n};"}, "fn": "alienOrder", "params": [{"name": "words", "type": "string_array"}], "outputType": "string", "tests": [["[\"wrt\",\"wrf\",\"er\",\"ett\",\"rftt\"]"], ["[\"z\",\"x\"]"], ["[\"z\",\"x\",\"z\"]"], ["[\"abc\",\"ab\"]"], ["[\"a\"]"], ["[\"abcdefghijklmnopqrstuvwxyz\"]"], ["[\"abc\",\"abc\",\"abc\"]"], ["[\"a\",\"aa\",\"aaa\",\"aaaa\"]"], ["[\"aaa\",\"aab\",\"aba\",\"abb\",\"baa\",\"bab\",\"bba\",\"bbb\"]"], ["[\"za\",\"zb\",\"ca\",\"cb\"]"], ["[\"za\",\"zb\"]"], ["[\"aa\",\"ab\",\"ba\",\"bc\",\"ca\",\"cb\"]"], ["[\"aa\",\"ab\",\"ac\",\"ba\",\"bd\"]"], ["[\"a\",\"b\",\"c\",\"a\"]"], ["[\"za\",\"zb\",\"zc\",\"za\"]"], ["[\"a\",\"abc\",\"ab\"]"], ["[\"ab\",\"abc\",\"b\"]"], ["[\"ab\",\"ba\",\"bb\"]"], ["[\"z\",\"y\",\"x\",\"w\",\"v\",\"u\",\"t\",\"s\",\"r\",\"q\",\"p\",\"o\",\"n\",\"m\",\"l\",\"k\",\"j\",\"i\",\"h\",\"g\",\"f\",\"e\",\"d\",\"c\",\"b\",\"a\"]"], ["[\"aaaaaaaaaaaaaaaaaaaaaaaaab\",\"aaaaaaaaaaaaaaaaaaaaaaaaac\"]"], ["[\"b\",\"a\"]"], ["[\"a\",\"b\",\"c\"]"], ["[\"c\",\"b\",\"a\"]"], ["[\"ab\",\"bc\",\"cd\",\"de\"]"], ["[\"aaa\",\"aa\"]"], ["[\"aa\",\"aaa\"]"], ["[\"abc\",\"abd\",\"bcd\"]"], ["[\"x\",\"z\"]"], ["[\"ac\",\"ab\",\"bc\"]"], ["[\"ab\",\"adc\"]"]], "expected": ["wertf", "zx", "", "", "a", "abcdefghijklmnopqrstuvwxyz", "abc", "a", "ab", "azbc", "azb", "abc", "abdc", "", "", "", "acb", "ab", "zyxwvutsrqponmlkjihgfedcba", "abc", "ba", "abc", "cba", "aebcd", "", "a", "acbd", "xz", "acb", "abcd"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "858", "slug": "all-nodes-distance-k-in-binary-tree", "id": 858, "title": "All Nodes Distance K in Binary Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/", "examples": [{"input": "root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2", "output": "[1,4,7]", "explanation": "Nodes 7, 4 and 1 are two steps from 5."}, {"input": "root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 0", "output": "[5]", "explanation": "Distance zero means the target itself."}, {"input": "root = [1], target = 1, k = 3", "output": "[]", "explanation": "No node is three steps away."}], "hints": ["Record each node's parent with a traversal so the tree can be walked upward as well as downward.", "Run a breadth-first search outward from the target node, tracking visited nodes to avoid going back.", "Collect nodes seen at depth `k` and sort them before returning."], "statement": "You are given the root of a binary tree in level-order form, an integer `target` identifying a node by its value, and an integer `k`. All node values in the tree are unique.\n\nTreat the tree as an undirected graph where each parent-child link can be walked in either direction. The distance between two nodes is the number of edges on the shortest such walk.\n\nReturn the values of all nodes that sit exactly `k` edges away from the node holding `target`, sorted in ascending order.\n\nAdaptation note: the original task passes a node reference and accepts any order; here the target is given by value (values are unique) and the answer is required sorted so every language can be checked deterministically.\n\n**Constraints:**\n- The tree holds `1 <= n <= 500` nodes.\n- `0 <= node.val <= 500`\n- All values are unique.\n- `0 <= k <= 1000`\n- `target` appears exactly once in the tree.\n", "solution": "## Approach\n\nFirst walk the tree to remember each node's parent, turning it into a graph that can be climbed upward. Locate the node whose value equals the target. Then run a breadth-first search from there across child and parent edges, level by level, until depth `k` is reached. Sorting the collected values gives a stable order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited a constant number of times.\n- **Space Complexity:** O(n) for the parent map and search queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\nclass Solution:\n def distanceK(self, root, target: int, k: int) -> List[int]:\n pmap = {}\n tgt = None\n stack = [(root, None)]\n while stack:\n n, p = stack.pop()\n if not n:\n continue\n pmap[id(n)] = p\n if n.val == target:\n tgt = n\n stack.append((n.left, n))\n stack.append((n.right, n))\n if tgt is None:\n return []\n q = deque([tgt])\n seen = {id(tgt)}\n d = 0\n while q:\n if d == k:\n return sorted([n.val for n in q])\n for _ in range(len(q)):\n cur = q.popleft()\n for nb in (cur.left, cur.right, pmap.get(id(cur))):\n if nb is not None and id(nb) not in seen:\n seen.add(id(nb))\n q.append(nb)\n d += 1\n return []\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 DistanceK(root *TreeNode, target int, k int) []int {\n return []int{}\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\nfrom typing import List\nclass Solution:\n def distanceK(self, root, target: int, k: int) -> List[int]:\n pass", "cpp": "/**\n * Definition for a binary tree node.\n * struct 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 vector<int> distanceK(TreeNode* root, int target, int k) {\n return {};\n }\n};"}, "fn": "distanceK", "params": [{"name": "root", "type": "tree_node"}, {"name": "target", "type": "int"}, {"name": "k", "type": "int"}], "outputType": "int_list", "tests": [["[3,5,1,6,2,0,8,null,null,7,4]", "5", "2"], ["[3,5,1,6,2,0,8,null,null,7,4]", "5", "0"], ["[1]", "1", "3"], ["[3,5,1,6,2,0,8,null,null,7,4]", "5", "1"], ["[3,5,1,6,2,0,8,null,null,7,4]", "3", "1"], ["[3,5,1,6,2,0,8,null,null,7,4]", "2", "1"], ["[0,1,null,3,4]", "3", "2"], ["[1,2,3,4,5,6,7]", "4", "2"], ["[1,2,3,null,4]", "2", "1"], ["[1,null,2,null,3]", "3", "2"], ["[1,2,null,3]", "3", "1"], ["[0]", "0", "0"], ["[0]", "0", "1"], ["[1,2,3]", "1", "1"], ["[1,2,3]", "2", "2"], ["[5,1,2,3,4]", "1", "2"], ["[10,5,15,3,7,12,20]", "5", "2"], ["[10,5,15,3,7,12,20]", "10", "2"], ["[1,2,3,4,null,null,5]", "4", "3"], ["[0,2,1,null,null,3]", "3", "3"], ["[1,2,3,4,5]", "1", "2"], ["[1,2,3,4,5]", "2", "0"], ["[7,3,9,1,5]", "3", "1"], ["[7,3,9,1,5]", "9", "2"], ["[1,2,null,3,null,4]", "4", "3"], ["[2,1,3]", "3", "1"], ["[0,1,2,3,4,5,6]", "0", "2"], ["[100,50,150,25,75]", "75", "2"]], "expected": [[1, 4, 7], [5], [], [2, 3, 6], [1, 5], [4, 5, 7], [0, 4], [1, 5], [1, 4], [1], [2], [0], [], [2, 3], [3], [2], [15], [3, 7, 12, 20], [3], [2], [4, 5], [2], [1, 5, 7], [3], [1], [2], [3, 4, 5, 6], [25, 100]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "501", "slug": "all-oone-data-structure", "id": 501, "title": "All Oone Data Structure", "difficulty": "Hard", "category": "design", "link": "https://leetcode.com/problems/all-oone-data-structure/", "examples": [{"input": "operations = [\"AllOne\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"inc\",\"getMaxKey\",\"getMinKey\"]\nvalues = [\"\",\"hello\",\"hello\",\"\",\"\",\"leet\",\"\",\"\"]", "output": "[\"null\",\"null\",\"null\",\"hello\",\"hello\",\"null\",\"hello\",\"hello\"]", "explanation": "hello reaches 2, then leet joins at 1; extremes are tie-checked."}, {"input": "operations = [\"AllOne\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"getMaxKey\",\"getMinKey\"]\nvalues = [\"\",\"a\",\"b\",\"b\",\"\",\"\",\"b\",\"\",\"\"]", "output": "[\"null\",\"null\",\"null\",\"null\",\"b\",\"a\",\"null\",\"b\",\"a\"]", "explanation": "Counts a:1, b:2 give max b and min a; after decrement both tie."}], "hints": ["Keep a map from key to count plus a map from count to the set of keys at that count.", "Track the current min and max counts incrementally, or derive them from the ordered count map.", "Ties may return any key at the extreme count; empty structures answer with an empty string."], "statement": "Maintain counts for a dynamic set of lowercase keys. You receive two parallel arrays describing a script: `operations` names the action at each step and `values` carries its argument (an empty string when the action takes none).\n\nThe script always starts with `\"AllOne\"` (create the structure, answer `\"null\"`). Later steps use:\n- `\"inc\"` with a key: raise that key's count by one, inserting at 1 when new; answer `\"null\"`.\n- `\"dec\"` with a key: lower that key's count by one, removing keys that reach zero; the key is guaranteed present; answer `\"null\"`.\n- `\"getMaxKey\"`: return any key currently holding the largest count, or `\"\"` when empty.\n- `\"getMinKey\"`: return any key currently holding the smallest count, or `\"\"` when empty.\n\nWrite `runAllOne`, which replays the whole script and returns the per-step answers (`\"null\"` for mutating or constructing steps, the requested key otherwise). When several keys tie for max or min, any tied key is accepted by the checker.\n\n**Constraints:**\n- Key length lies in `[1, 10]`, lowercase letters only.\n- At most `5 * 10^4` calls in one script.\n- Every `dec` targets an existing key.\n\nAdaptation: the source is a stateful `AllOne` class; here it is modeled as the `runAllOne(operations, values)` replay function with `string_array` inputs and `string_list` output so all runners can drive it. Average O(1) per action is intended but only answer correctness is checked.\n", "solution": "## Approach\n\nReplay the script against a count table plus buckets from count to key set. Insertion and removal update both structures; extremes come from the smallest and largest occupied buckets. Because any tied extreme is valid, the checker compares counts rather than exact keys.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log m) with an ordered bucket map, where n is the step count and m the distinct counts (O(1) average with a doubly-linked bucket list).\n- **Space Complexity:** O(k) for k distinct keys.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runAllOne(self, operations: List[str], values: List[str]) -> List[str]:\n from collections import defaultdict\n cnt = {}\n buckets = defaultdict(set)\n res = []\n for op, v in zip(operations, values):\n if op == 'AllOne':\n cnt.clear()\n buckets.clear()\n res.append('null')\n elif op == 'inc':\n c = cnt.get(v, 0)\n if c:\n buckets[c].discard(v)\n cnt[v] = c + 1\n buckets[c + 1].add(v)\n res.append('null')\n elif op == 'dec':\n c = cnt[v]\n buckets[c].discard(v)\n if c == 1:\n del cnt[v]\n else:\n cnt[v] = c - 1\n buckets[c - 1].add(v)\n res.append('null')\n elif op == 'getMaxKey':\n if not cnt:\n res.append('')\n else:\n mx = max(cnt.values())\n res.append(next(k for k, c in cnt.items() if c == mx))\n elif op == 'getMinKey':\n if not cnt:\n res.append('')\n else:\n mn = min(cnt.values())\n res.append(next(k for k, c in cnt.items() if c == mn))\n return res\n```\n", "starter": {"go": "package main\n\nfunc RunAllOne(operations []string, values []string) []string {\n \n}", "python": "from typing import List\nclass Solution:\n def runAllOne(self, operations: List[str], values: List[str]) -> List[str]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> runAllOne(vector<string>& operations, vector<string>& values) {\n return {};\n }\n};"}, "fn": "runAllOne", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"AllOne\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"hello\",\"hello\",\"\",\"\",\"leet\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"b\",\"b\",\"\",\"\",\"b\",\"\",\"\"]"], ["[\"AllOne\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"x\",\"\",\"\",\"x\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"a\",\"b\",\"c\",\"\",\"\",\"b\",\"c\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"hello\",\"world\",\"hello\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"getMinKey\",\"dec\",\"getMinKey\"]", "[\"\",\"a\",\"b\",\"c\",\"\",\"a\",\"\"]"], ["[\"AllOne\",\"inc\",\"getMaxKey\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"k\",\"\",\"k\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"p\",\"q\",\"p\",\"q\",\"p\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"solo\",\"solo\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"a\",\"\",\"\",\"a\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"getMaxKey\"]", "[\"\",\"x\",\"y\",\"y\",\"z\",\"\",\"\",\"y\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"dec\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"b\",\"c\",\"\",\"\",\"a\",\"b\",\"c\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"inc\",\"getMinKey\",\"dec\",\"getMaxKey\"]", "[\"\",\"k\",\"k\",\"k\",\"\",\"m\",\"\",\"k\",\"\"]"], ["[\"AllOne\",\"inc\",\"getMaxKey\",\"dec\",\"getMaxKey\",\"inc\",\"getMinKey\"]", "[\"\",\"a\",\"\",\"a\",\"\",\"b\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"aa\",\"bb\",\"aa\",\"bb\",\"cc\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"foo\",\"bar\",\"foo\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"a\",\"a\",\"b\",\"\",\"\",\"a\",\"a\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"getMinKey\",\"getMaxKey\",\"inc\",\"getMaxKey\",\"dec\",\"getMinKey\"]", "[\"\",\"z\",\"\",\"\",\"z\",\"\",\"z\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"m\",\"n\",\"o\",\"m\",\"n\",\"m\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"dec\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"b\",\"b\",\"c\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"a\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"dec\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"ab\",\"ab\",\"ab\",\"cd\",\"cd\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"dec\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"x\",\"y\",\"z\",\"x\",\"y\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"key\",\"key\",\"other\",\"other\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"getMaxKey\"]", "[\"\",\"a\",\"b\",\"b\",\"c\",\"c\",\"c\",\"\",\"\",\"c\",\"\"]"], ["[\"AllOne\",\"inc\",\"inc\",\"inc\",\"inc\",\"getMaxKey\",\"getMinKey\",\"dec\",\"dec\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"q\",\"w\",\"e\",\"r\",\"\",\"\",\"q\",\"w\",\"\",\"\"]"], ["[\"AllOne\",\"inc\",\"dec\",\"inc\",\"dec\",\"inc\",\"getMaxKey\",\"getMinKey\"]", "[\"\",\"a\",\"a\",\"b\",\"b\",\"c\",\"\",\"\"]"]], "expected": [["null", "null", "null", "hello", "hello", "null", "hello", "leet"], ["null", "null", "null", "null", "b", "a", "null", "a", "a"], ["null", "", ""], ["null", "null", "x", "x", "null", "", ""], ["null", "null", "null", "null", "null", "a", "b", "null", "null", "a", "a"], ["null", "null", "null", "null", "world", "world"], ["null", "null", "null", "null", "a", "null", "b"], ["null", "null", "k", "null", "k", "k"], ["null", "null", "null", "null", "null", "null", "p", "q"], ["null", "null", "null", "", ""], ["null", "null", "null", "a", "a", "null", "a", "a"], ["null", "null", "null", "null", "null", "y", "x", "null", "x"], ["null", "null", "null", "null", "a", "a", "null", "null", "null", "", ""], ["null", "null", "null", "null", "k", "null", "m", "null", "k"], ["null", "null", "a", "null", "", "null", "b"], ["null", "null", "null", "null", "null", "null", "aa", "cc"], ["null", "null", "null", "null", "bar", "bar"], ["null", "null", "null", "null", "null", "a", "b", "null", "null", "b", "b"], ["null", "null", "z", "z", "null", "z", "null", "z"], ["null", "null", "null", "null", "null", "null", "null", "m", "o"], ["null", "null", "null", "null", "null", "a", "a"], ["null", "null", "null", "", ""], ["null", "null", "null", "null", "null", "null", "cd", "ab"], ["null", "null", "null", "null", "null", "null", "z", "z"], ["null", "null", "null", "null", "null", "key", "key"], ["null", "null", "null", "null", "null", "null", "null", "c", "a", "null", "b"], ["null", "null", "null", "null", "null", "q", "q", "null", "null", "e", "e"], ["null", "null", "null", "null", "null", "null", "c", "c"]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "795", "slug": "all-paths-from-source-to-target", "id": 795, "title": "All Paths From Source to Target", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/all-paths-from-source-to-target/", "examples": [{"input": "graph = [[1,2],[3],[3],[]]", "output": "[[0,1,3],[0,2,3]]", "explanation": "Two ways reach the final vertex."}, {"input": "graph = [[4,3,1],[3,2,4],[3],[4],[]]", "output": "[[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]", "explanation": "Five routes connect start to finish."}, {"input": "graph = [[1],[]]", "output": "[[0,1]]", "explanation": "The lone edge is the answer."}], "hints": ["Depth-first search from 0 carrying the current path naturally enumerates every route.", "Append a copy of the path once the final vertex is reached, then backtrack.", "Adaptation: the nested input maps to int_array_2d and the nested output maps to int_list_2d in this judge."], "statement": "You receive a directed acyclic graph with `n` vertices numbered `0` through `n - 1`. It is stored as an adjacency list `graph`, where `graph[i]` lists every vertex reachable by one directed edge from `i`. Every edge points from a smaller index to a larger one, so no cycles exist.\n\nList every directed route that starts at vertex `0` and finishes at vertex `n - 1`. The order of the routes in your answer does not matter, but each individual route must list vertices from start to finish.\n\n**Constraints:**\n- `2 <= n <= 15`\n- `graph[i]` contains distinct vertices larger than `i`\n- At least the structure is acyclic; the target may be unreachable\n- Adaptation: the nested input maps to int_array_2d and the nested output maps to int_list_2d in this judge.\n", "solution": "## Approach\n\nRun a depth-first search that carries the path from the start vertex. Each time the final vertex is reached, store a copy of the current path; otherwise extend the path with each outgoing neighbour and backtrack after the recursive call.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(2^n * n) in the worst case, proportional to the number of paths times path length.\n- **Space Complexity:** O(n) for the recursion stack plus the output storage.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:\n res = []\n path = [0]\n def dfs(u: int):\n if u == len(graph) - 1:\n res.append(list(path))\n return\n for v in graph[u]:\n path.append(v)\n dfs(v)\n path.pop()\n dfs(0)\n return res\n```\n", "starter": {"go": "package main\n\nfunc AllPathsSourceTarget(graph [][]int) [][]int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:\n return []", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {\n return {};\n }\n};"}, "fn": "allPathsSourceTarget", "params": [{"name": "graph", "type": "int_array_2d"}], "outputType": "int_list_2d", "tests": [["[[1, 2], [3], [3], []]"], ["[[4, 3, 1], [3, 2, 4], [3], [4], []]"], ["[[1], []]"], ["[[1, 2, 3], [], [], []]"], ["[[1], [2], [3], []]"], ["[[1, 2], [3], [3], [4], []]"], ["[[1], [3], [3], []]"], ["[[2], [2], [3], []]"], ["[[1, 2], [2, 3], [3], []]"], ["[[1, 2], [3], [], []]"], ["[[1], [2], []]"], ["[[1, 2], [2], []]"], ["[[1, 2, 3], [3], [3], [4], []]"], ["[[1], [2], [3], [4], []]"], ["[[1, 2], [3, 4], [4], [4], []]"], ["[[], []]"], ["[[1, 2], [3], [4], [5], [], []]"], ["[[1], [2], [3], [4], [5], []]"], ["[[2, 3], [4], [4], [4], []]"], ["[[1, 3], [2], [3], []]"], ["[[1, 2, 3, 4], [5], [5], [5], [5], []]"], ["[[2], [3], [4], [4], []]"], ["[[1, 2], [4], [3], [4], []]"], ["[[3], [3], [3], []]"], ["[[1, 2], [3], [3], [4, 5], [6], [6], []]"], ["[[1], [2], [3], [4], [5], [6], []]"], ["[[1, 2], [3], [4], [], []]"], ["[[1, 2], [3], [3], [4], [5], []]"]], "expected": [[[0, 1, 3], [0, 2, 3]], [[0, 4], [0, 3, 4], [0, 1, 3, 4], [0, 1, 2, 3, 4], [0, 1, 4]], [[0, 1]], [[0, 3]], [[0, 1, 2, 3]], [[0, 1, 3, 4], [0, 2, 3, 4]], [[0, 1, 3]], [[0, 2, 3]], [[0, 1, 2, 3], [0, 1, 3], [0, 2, 3]], [[0, 1, 3]], [[0, 1, 2]], [[0, 1, 2], [0, 2]], [[0, 1, 3, 4], [0, 2, 3, 4], [0, 3, 4]], [[0, 1, 2, 3, 4]], [[0, 1, 3, 4], [0, 1, 4], [0, 2, 4]], [], [[0, 1, 3, 5]], [[0, 1, 2, 3, 4, 5]], [[0, 2, 4], [0, 3, 4]], [[0, 1, 2, 3], [0, 3]], [[0, 1, 5], [0, 2, 5], [0, 3, 5], [0, 4, 5]], [[0, 2, 4]], [[0, 1, 4], [0, 2, 3, 4]], [[0, 3]], [[0, 1, 3, 4, 6], [0, 1, 3, 5, 6], [0, 2, 3, 4, 6], [0, 2, 3, 5, 6]], [[0, 1, 2, 3, 4, 5, 6]], [[0, 2, 4]], [[0, 1, 3, 4, 5], [0, 2, 3, 4, 5]]], "loose": true}