offcode 0.0.0-stage → 0.1.1

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-DCYvZg7a.js +150 -0
  1036. package/dist/web/assets/index-gSBueMfH.css +1 -0
  1037. package/dist/web/index.html +13 -0
  1038. package/package.json +44 -4
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "263", "slug": "sudoku-solver", "id": 263, "title": "Sudoku Solver", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/sudoku-solver/", "examples": [{"input": "board = [\"53..7....\",\"6..195...\",\".98....6.\",\"8...6...3\",\"4..8.3..1\",\"7...2...6\",\".6....28.\",\"...419..5\",\"....8..79\"]", "output": "[\"534678912\",\"672195348\",\"198342567\",\"859761423\",\"426853791\",\"713924856\",\"961537284\",\"287419635\",\"345286179\"]", "explanation": "The completed grid meets the row, column, and box rules while keeping all given digits."}, {"input": "board = [\"5.4.7.9.2\",\"6.2.9.3.8\",\"1.8.4.5.7\",\"8.9.6.4.3\",\"4.6.5.7.1\",\"7.3.2.8.6\",\"9.1.3.2.4\",\"2.7.1.6.5\",\"3.5.8.1.9\"]", "output": "[\"534678912\",\"672195348\",\"198342567\",\"859761423\",\"426853791\",\"713924856\",\"961537284\",\"287419635\",\"345286179\"]", "explanation": "With every other cell blanked, the givens still determine the same full solution."}], "hints": ["Try digits cell by cell with depth-first search, undoing (backtracking) whenever a cell has no legal digit left.", "Track used digits per row, column, and box as bit masks, and always branch on the empty cell with the fewest candidates."], "statement": "Fill a 9x9 Sudoku grid so that every row, every column, and each of the nine 3x3 sub-boxes contains the digits `1` through `9` exactly once. Empty cells are written as `'.'`; the pre-filled digits must stay untouched.\n\nEach board is passed as nine strings of nine characters, and you must return the completed board in the same shape: nine strings with every `'.'` replaced by the correct digit.\n\n**Constraints:**\n- `board.length == 9`\n- `board[i].length == 9`\n- Each cell holds a digit `'1'`-`'9'` or `'.'`.\n- Every test board admits at least one valid completion.\n\n*Adaptation note:* the classic statement edits a `char[][]` in place with no return value. Because this judge compares returned values, each row is encoded as a string and you return the nine completed row-strings instead. Any fully valid completion is accepted.\n", "solution": "## Approach\n\nRecord the digits already used in each row, column, and 3x3 box as bit masks, and collect the empty cells. Repeatedly pick the empty cell with the fewest legal candidates, try each one while updating the masks, and recurse; restore the masks when a branch dead-ends. Bit operations make candidate checks and updates constant time.\n\n## Complexity Analysis\n\n- **Time Complexity:** Worst-case exponential in the number of blanks, but mask pruning plus fewest-candidates-first keeps real puzzles fast.\n- **Space Complexity:** O(1) extra space besides the recursion stack and the board itself.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def solveSudoku(self, board: List[str]) -> List[str]:\n g = [list(row) for row in board]\n rows, cols, boxes = [0] * 9, [0] * 9, [0] * 9\n empties = []\n for r in range(9):\n for c in range(9):\n if g[r][c] == '.':\n empties.append((r, c))\n else:\n b = 1 << (ord(g[r][c]) - ord('1'))\n rows[r] |= b\n cols[c] |= b\n boxes[(r // 3) * 3 + c // 3] |= b\n\n def cands(r, c):\n return (~(rows[r] | cols[c] | boxes[(r // 3) * 3 + c // 3])) & 0x1FF\n\n def dfs(k):\n if k == len(empties):\n return True\n best = min(range(k, len(empties)),\n key=lambda i: bin(cands(*empties[i])).count('1'))\n empties[k], empties[best] = empties[best], empties[k]\n r, c = empties[k]\n b = (r // 3) * 3 + c // 3\n m = cands(r, c)\n d = 1\n while m:\n if m & 1:\n bit = 1 << (d - 1)\n g[r][c] = str(d)\n rows[r] |= bit\n cols[c] |= bit\n boxes[b] |= bit\n if dfs(k + 1):\n return True\n rows[r] &= ~bit\n cols[c] &= ~bit\n boxes[b] &= ~bit\n d += 1\n m >>= 1\n g[r][c] = '.'\n empties[k], empties[best] = empties[best], empties[k]\n return False\n\n dfs(0)\n return [''.join(row) for row in g]\n```\n", "starter": {"go": "package main\n\nfunc SolveSudoku(board []string) []string {\n return []string{}\n}", "python": "from typing import List\n\nclass Solution:\n def solveSudoku(self, board: List[str]) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> solveSudoku(vector<string>& board) {\n return {};\n }\n};"}, "fn": "solveSudoku", "params": [{"name": "board", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"53..7....\", \"6..195...\", \".98....6.\", \"8...6...3\", \"4..8.3..1\", \"7...2...6\", \".6....28.\", \"...419..5\", \"....8..79\"]"], ["[\"5.4.7.9.2\", \".7.1.5.4.\", \"1.8.4.5.7\", \".5.7.1.2.\", \"4.6.5.7.1\", \".1.9.4.5.\", \"9.1.3.2.4\", \".8.4.9.3.\", \"3.5.8.1.9\"]"], ["[\".34.78.12\", \"67.19.34.\", \"1.83.25.7\", \".59.61.23\", \"42.85.79.\", \"7.39.48.6\", \".61.37.84\", \"28.41.63.\", \"3.52.61.9\"]"], ["[\"534678912\", \".........\", \"198342567\", \".........\", \"426853791\", \".........\", \"961537284\", \".........\", \"345286179\"]"], ["[\"5.4.7.9.2\", \"6.2.9.3.8\", \"1.8.4.5.7\", \"8.9.6.4.3\", \"4.6.5.7.1\", \"7.3.2.8.6\", \"9.1.3.2.4\", \"2.7.1.6.5\", \"3.5.8.1.9\"]"], ["[\".346.891.\", \"672.953.8\", \"19.342.67\", \"8.976.423\", \".268.379.\", \"713.248.6\", \"96.537.84\", \"2.741.635\", \".452.617.\"]"], ["[\".3467.912\", \"6.2195.48\", \"19.3425.7\", \"859.6142.\", \"4268.3791\", \".1392.856\", \"9.1537.84\", \"28.4196.5\", \"345.8617.\"]"], ["[\"534678912\", \"672195348\", \"198342567\", \"859761423\", \"426853791\", \"713924856\", \".........\", \".........\", \".........\"]"], ["[\"534678912\", \"6..1..3..\", \"1..3..5..\", \"859761423\", \"4..8..7..\", \"7..9..8..\", \"961537284\", \"2..4..6..\", \"3..2..1..\"]"], ["[\"53.67.91.\", \"67.19.34.\", \"19.34.56.\", \"85.76.42.\", \"42.85.79.\", \"71.92.85.\", \"96.53.28.\", \"28.41.63.\", \"34.28.17.\"]"], ["[\"534678...\", \"672195...\", \"198342...\", \"859761...\", \"426853...\", \"713924...\", \"961537...\", \"287419...\", \"345286...\"]"], ["[\"53.67.91.\", \".72.95.48\", \"1.83.25.7\", \"85.76.42.\", \".26.53.91\", \"7.39.48.6\", \"96.53.28.\", \".87.19.35\", \"3.52.61.9\"]"], ["[\"534678912\", \"672195348\", \"198342567\", \"859761423\", \"4.6.5.7.1\", \"713924856\", \"961537284\", \"287419635\", \"345286179\"]"], ["[\"1.3.5.7.9\", \".5.7.9.2.\", \"7.9.2.4.6\", \".1.3.5.9.\", \"3.5.9.2.4\", \".9.2.4.6.\", \"5.1.3.9.8\", \".3.9.8.4.\", \"9.8.4.6.2\"]"], ["[\".23.56.89\", \"45.78.12.\", \"7.91.34.6\", \".14.65.97\", \"36.89.21.\", \"8.72.43.5\", \".41.32.78\", \"63.97.54.\", \"9.85.16.2\"]"], ["[\".........\", \"456789123\", \".........\", \"214365897\", \".........\", \"897214365\", \".........\", \"632978541\", \".........\"]"], ["[\".2.4.6.8.\", \".5.7.9.2.\", \".8.1.3.5.\", \".1.3.5.9.\", \".6.8.7.1.\", \".9.2.4.6.\", \".4.6.2.7.\", \".3.9.8.4.\", \".7.5.1.3.\"]"], ["[\"1.345.789\", \".567.912.\", \"789.234.6\", \"21.365.97\", \"3.589.214\", \".972.436.\", \"541.329.8\", \"63.978.41\", \"9.854.632\"]"], ["[\"123456789\", \"456789123\", \"789123456\", \"214365897\", \"365897214\", \"897214365\", \"541632978\", \".........\", \".........\"]"], ["[\"1234567..\", \"4567891..\", \"7891234..\", \"2143658..\", \"3658972..\", \"8972143..\", \"5416329..\", \"6329785..\", \"9785416..\"]"], ["[\".23.56.89\", \".56.89.23\", \".89.23.56\", \".14.65.97\", \".65.97.14\", \".97.14.65\", \".41.32.78\", \".32.78.41\", \".78.41.32\"]"], ["[\"12.45.78.\", \".56.89.23\", \"7.91.34.6\", \"21.36.89.\", \".65.97.14\", \"8.72.43.5\", \"54.63.97.\", \".32.78.41\", \"9.85.16.2\"]"], ["[\"123456789\", \"456789123\", \"789123456\", \"214365897\", \"365897214\", \"897214365\", \"541632978\", \"632978541\", \".7.5.1.3.\"]"], ["[\"123.567.9\", \"45.789.23\", \"7.912.456\", \".143.589.\", \"365.972.4\", \"89.214.65\", \"5.163.978\", \".329.854.\", \"978.416.2\"]"], ["[\"534.78912\", \"6.219534.\", \"198342.67\", \"8597.1423\", \"42.853791\", \".139248.6\", \"96153.284\", \"287.19635\", \"3.528617.\"]"]], "expected": [["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["534678912", "672195438", "198342567", "819764325", "426853791", "753921846", "961537284", "287419653", "345286179"], ["534678912", "672591348", "198342567", "859167423", "426853791", "713429856", "961735284", "287914635", "345286179"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "265437189", "341289675", "987516234"], ["534678912", "682195347", "197342568", "859761423", "426853791", "713924856", "961537284", "278419635", "345286179"], ["534672918", "678195342", "192348567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["534678129", "672195348", "198342675", "859761234", "426853791", "713924856", "961537482", "287419563", "345286917"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"], ["123456789", "456789321", "789123456", "214365897", "365897214", "897214563", "541632978", "632978145", "978541632"], ["123456789", "456789123", "789123456", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["783126459", "456789123", "129453786", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["129456387", "356789421", "487123659", "812365794", "564897213", "793214865", "941632578", "235978146", "678541932"], ["123456789", "456789123", "789123456", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["123456789", "456789123", "789123456", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["123456789", "456789132", "789123465", "214365897", "365897241", "897214356", "541632978", "632978514", "978541623"], ["123456789", "456789123", "789123456", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["123456789", "456789123", "789123456", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["123456789", "456789123", "789123456", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["123456789", "456789123", "789123456", "214365897", "365897214", "897214365", "541632978", "632978541", "978541632"], ["534678912", "672195348", "198342567", "859761423", "426853791", "713924856", "961537284", "287419635", "345286179"]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "207", "slug": "sum-of-all-subset-xor-totals", "id": 207, "title": "Sum of All Subset XOR Totals", "difficulty": "Easy", "category": "backtracking", "link": "https://leetcode.com/problems/sum-of-all-subset-xor-totals/", "examples": [{"input": "nums = [1,3]", "output": "6", "explanation": "The 4 subsets of [1,3] are: [], [1], [3], [1,3]. Their XOR totals are 0, 1, 3, and 1 XOR 3 = 2, and 0 + 1 + 3 + 2 = 6."}, {"input": "nums = [5,1,6]", "output": "28", "explanation": "The 8 subsets of [5,1,6] are: [], [5], [1], [6], [5,1], [5,6], [1,6], [5,1,6]. The sum of their XOR totals is 28."}, {"input": "nums = [3,4,5,6,7,8]", "output": "480", "explanation": "The sum of all XOR totals for every subset is 480."}], "hints": ["Is there a way to iterate through all the subsets of the array?", "Use recursion to explore include/exclude choices and accumulate the running XOR total."], "statement": "Call the XOR-combination of a list the result of XOR-ing all of its entries together, with the empty list assigned `0`.\n\n- As an illustration, the XOR-combination of `[2,5,6]` is `2 XOR 5 XOR 6 = 1`.\n\nStarting from an input list `nums`, consider each of its subsets and compute that subset's XOR-combination. Return the total obtained by adding all of those values together.\n\n**Note:** Selections that look alike but arise from different positions count separately.\n\nHere a subset means any collection obtainable from `b` by discarding zero or more entries, keeping the rest, when written as `a` drawn from `b`.\n\n**Constraints:**\n\n- `1 <= nums.length <= 12`\n- `1 <= nums[i] <= 20`\n", "solution": "## Approach\n\nEnumerate every subset with a recursive include/exclude search. At each position we branch into two choices: leave `nums[i]` out of the subset (keeping the current XOR total unchanged) or include it (XOR-ing `nums[i]` into the current total). When the end of the array is reached, the accumulated XOR total of that subset is added to the result.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(2^n), where n is the length of `nums`, since every subset is visited exactly once.\n- **Space Complexity:** O(n) for the recursion stack (excluding the implicit output of the aggregate sum).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def subsetXORSum(self, nums: List[int]) -> int:\n def collect(index: int, current: int) -> int:\n if index == len(nums):\n return current\n skip = collect(index + 1, current)\n take = collect(index + 1, current ^ nums[index])\n return skip + take\n\n return collect(0, 0)\n```", "starter": {"go": "package main\n\nfunc SubsetXORSum(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def subsetXORSum(self, nums: List[int]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n \n }\n};"}, "fn": "subsetXORSum", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1]"], ["[1,3]"], ["[5,1,6]"], ["[3,4,5,6,7,8]"], ["[2]"], ["[1,1]"], ["[20]"], ["[1,2,3]"], ["[1,1,1,1]"], ["[1,2,4,8]"], ["[10,11,12]"], ["[1,2,3,4,5]"], ["[3]"], ["[1,2]"], ["[4,4]"], ["[7,7,7]"], ["[1,20]"], ["[20,20]"], ["[2,5,8]"], ["[9,10]"], ["[1,1,2]"], ["[6,6,6,6]"], ["[15,3,7]"], ["[1,2,3,4]"], ["[11,13,17]"], ["[19,20,1]"], ["[5,5,5,5,5]"], ["[2,4,6,8,10]"], ["[12,14,16]"], ["[18,19,20]"]], "expected": [1, 6, 28, 480, 2, 2, 20, 12, 8, 120, 60, 112, 3, 6, 8, 28, 42, 40, 60, 22, 12, 48, 60, 56, 124, 92, 80, 224, 120, 92], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "832", "slug": "sum-of-distances-in-tree", "id": 832, "title": "Sum of Distances in Tree", "difficulty": "Hard", "category": "tree", "link": "https://leetcode.com/problems/sum-of-distances-in-tree/", "examples": [{"input": "n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]", "output": "[8,12,6,10,10,10]", "explanation": "Node 2 is the most central with total 6."}, {"input": "n = 1, edges = []", "output": "[0]"}, {"input": "n = 2, edges = [[1,0]]", "output": "[1,1]"}], "hints": ["Root the tree at 0: a bottom-up pass counts subtree sizes and the distance sums inside each subtree.", "Reroot with the relation childAnswer = parentAnswer - subtreeSize[child] + (n - subtreeSize[child]), since moving the root across one edge shortens paths into the child subtree and lengthens all others.", "A second top-down pass propagates the root answer to every node in linear time."], "statement": "You are given an undirected tree with `n` nodes labelled `0` to `n - 1` and an edge list `edges`, where each entry connects two nodes. For every node `i`, compute the sum of the distances (number of edges on the shortest path) from `i` to all other nodes. Return these sums as an array `answer` where `answer[i]` belongs to node `i`.\n\n**Constraints:**\n- `1 <= n <= 3 * 10^4`\n- `edges.length == n - 1`\n- `0 <= edges[i][0], edges[i][1] < n`\n- The edges form a valid tree\n", "solution": "## Approach\n\nRoot the tree at node 0 and run a post-order pass that counts each subtree's size and sums distances inside it: a parent's total is the children's totals plus one extra edge per descendant. Then run a pre-order pass that reroots across each edge \u2014 moving the root from parent to child shortens every path into the child's subtree by one and lengthens every other path by one, giving childAnswer = parentAnswer - size[child] + (n - size[child]). Both passes are linear.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) where n is the node count; each edge is traversed twice.\n- **Space Complexity:** O(n) for the adjacency list, counts, and answers (plus recursion depth).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def sumOfDistancesInTree(self, n: int, edges: List[List[int]]) -> List[int]:\n import sys\n sys.setrecursionlimit(100000)\n g = [[] for _ in range(n)]\n for a, b in edges:\n g[a].append(b)\n g[b].append(a)\n cnt = [0] * n\n ans = [0] * n\n\n def dfs1(u, p):\n cnt[u] = 1\n for v in g[u]:\n if v == p:\n continue\n dfs1(v, u)\n cnt[u] += cnt[v]\n ans[u] += ans[v] + cnt[v]\n\n def dfs2(u, p):\n for v in g[u]:\n if v == p:\n continue\n ans[v] = ans[u] - cnt[v] + (n - cnt[v])\n dfs2(v, u)\n\n dfs1(0, -1)\n dfs2(0, -1)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SumOfDistancesInTree(n int, edges [][]int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def sumOfDistancesInTree(self, n: int, edges: List[List[int]]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> sumOfDistancesInTree(int n, vector<vector<int>>& edges) {\n return {};\n }\n};"}, "fn": "sumOfDistancesInTree", "params": [{"name": "n", "type": "int"}, {"name": "edges", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["6", "[[0, 1], [0, 2], [2, 3], [2, 4], [2, 5]]"], ["1", "[]"], ["2", "[[1, 0]]"], ["3", "[[0, 1], [1, 2]]"], ["3", "[[0, 1], [0, 2]]"], ["4", "[[0, 1], [1, 2], [2, 3]]"], ["4", "[[0, 1], [0, 2], [0, 3]]"], ["5", "[[0, 1], [0, 2], [0, 3], [0, 4]]"], ["5", "[[0, 1], [1, 2], [2, 3], [3, 4]]"], ["5", "[[4, 0], [3, 0], [2, 0], [1, 0]]"], ["7", "[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6]]"], ["7", "[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]"], ["8", "[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]"], ["6", "[[0, 1], [1, 2], [1, 3], [3, 4], [3, 5]]"], ["9", "[[0, 1], [0, 2], [0, 3], [1, 4], [1, 5], [2, 6], [3, 7], [3, 8]]"], ["10", "[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9]]"], ["10", "[[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]]"], ["6", "[[5, 4], [4, 3], [3, 2], [2, 1], [1, 0]]"], ["11", "[[0, 1], [0, 2], [1, 3], [1, 4], [2, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10]]"], ["4", "[[2, 0], [2, 1], [2, 3]]"], ["12", "[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11]]"], ["5", "[[1, 0], [2, 1], [3, 2], [4, 3]]"], ["13", "[[0, 1], [0, 2], [1, 3], [1, 4], [4, 5], [5, 6], [2, 7], [7, 8], [8, 9], [2, 10], [10, 11], [11, 12]]"], ["15", "[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14]]"], ["15", "[[0, 1], [0, 2], [0, 3], [0, 4], [1, 5], [1, 6], [2, 7], [2, 8], [3, 9], [3, 10], [4, 11], [4, 12], [5, 13], [5, 14]]"], ["2", "[[0, 1]]"], ["20", "[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19]]"], ["9", "[[8, 0], [7, 1], [6, 2], [5, 3], [4, 0], [3, 0], [2, 0], [1, 0]]"]], "expected": [[8, 12, 6, 10, 10, 10], [0], [1, 1], [3, 2, 3], [2, 3, 3], [6, 4, 4, 6], [3, 5, 5, 5], [4, 7, 7, 7, 7], [10, 7, 6, 7, 10], [4, 7, 7, 7, 7], [10, 11, 11, 16, 16, 16, 16], [21, 16, 13, 12, 13, 16, 21], [28, 22, 18, 16, 16, 18, 22, 28], [11, 7, 11, 7, 11, 11], [13, 16, 18, 16, 23, 23, 25, 23, 23], [45, 37, 31, 27, 25, 25, 27, 31, 37, 45], [9, 17, 17, 17, 17, 17, 17, 17, 17, 17], [15, 11, 9, 9, 11, 15], [22, 23, 23, 30, 30, 30, 30, 39, 39, 39, 39], [5, 5, 3, 5], [66, 56, 48, 42, 38, 36, 36, 38, 42, 48, 56, 66], [10, 7, 6, 7, 10], [31, 34, 30, 45, 41, 50, 61, 37, 46, 57, 37, 46, 57], [105, 92, 81, 72, 65, 60, 57, 56, 57, 60, 65, 72, 81, 92, 105], [26, 31, 35, 35, 35, 40, 44, 48, 48, 48, 48, 48, 48, 53, 53], [1, 1], [190, 172, 156, 142, 130, 120, 112, 106, 102, 100, 100, 102, 106, 112, 120, 130, 142, 156, 172, 190], [11, 16, 16, 16, 18, 23, 23, 23, 18]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "968", "slug": "sum-of-even-numbers-after-queries", "id": 968, "title": "Sum of Even Numbers After Queries", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/sum-of-even-numbers-after-queries/", "examples": [{"input": "nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]", "output": "[8,6,2,4]", "explanation": "After each addition the even total becomes 8, then 6, then 2, then 4."}, {"input": "nums = [1], queries = [[4,0]]", "output": "[0]", "explanation": "The single entry becomes 5 (odd), so the even total is 0."}], "hints": ["Maintain the sum of currently even entries instead of rescanning the array per query.", "Before applying queries[i] = [val, idx], subtract nums[idx] from the total if it is even.", "After the update, add nums[idx] back if it is even, and record the total."], "statement": "You are given an integer array `nums` and a list of `queries`, where each query is a pair `[val, index]` meaning add `val` to `nums[index]`.\n\nAfter applying each query in order, compute the sum of all even-valued entries in the array. Collect these sums into an answer array of the same length as `queries` and return it.\n\n**Constraints:**\n- `1 <= nums.length <= 10000`\n- `-10000 <= nums[i] <= 10000`\n- `1 <= queries.length <= 10000`\n- `queries[i] = [val, index]`, `-10000 <= val <= 10000`, `0 <= index < nums.length`.\n", "solution": "## Approach\n\nKeep the sum of the currently even entries. For each query [val, idx], remove nums[idx] from that sum if it is even, apply the addition, then add it back if it is now even. Recording the running sum after every query yields the answer without rescanning the array.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + q), where n is the array length and q is the number of queries.\n- **Space Complexity:** O(q) for the answer array (O(1) extra).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sumEvenAfterQueries(self, nums: List[int], queries: List[List[int]]) -> List[int]:\n even = sum(x for x in nums if x % 2 == 0)\n ans = []\n for v, i in queries:\n if nums[i] % 2 == 0:\n even -= nums[i]\n nums[i] += v\n if nums[i] % 2 == 0:\n even += nums[i]\n ans.append(even)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SumEvenAfterQueries(nums []int, queries [][]int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def sumEvenAfterQueries(self, nums: List[int], queries: List[List[int]]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> sumEvenAfterQueries(vector<int>& nums, vector<vector<int>>& queries) {\n return {};\n }\n};"}, "fn": "sumEvenAfterQueries", "params": [{"name": "nums", "type": "int_array"}, {"name": "queries", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[1,2,3,4]", "[[1,0],[-3,1],[-4,0],[2,3]]"], ["[1]", "[[4,0]]"], ["[2,2,2]", "[[1,0],[1,1],[1,2]]"], ["[1,3,5]", "[[1,0],[1,1],[1,2]]"], ["[0,0,0]", "[[0,0],[0,1],[0,2]]"], ["[2,4,6]", "[[-2,0],[-4,1],[-6,2]]"], ["[1,2]", "[[3,0],[3,1]]"], ["[-1,-2,-3]", "[[1,0],[2,1],[3,2]]"], ["[5,5,5,5]", "[[5,0],[5,1],[5,2],[5,3]]"], ["[0]", "[[1,0],[-1,0],[2,0]]"], ["[10,-10,10,-10]", "[[10,1],[-10,0],[5,2]]"], ["[3,1,2]", "[[0,0],[0,1],[0,2]]"], ["[4,4]", "[[1,0],[1,0],[1,0]]"], ["[1,1,1,1,1]", "[[1,0],[1,1],[1,2],[1,3],[1,4]]"], ["[2,0]", "[[1,1],[1,1],[1,1]]"], ["[10000,-10000]", "[[10000,0],[-10000,1]]"], ["[7,8,9]", "[[-7,0],[-8,1],[-9,2]]"], ["[1,2,3]", "[[2,2],[2,2],[2,2]]"], ["[6,6,6]", "[[3,0],[3,1],[3,2]]"], ["[0,1,2,3,4,5]", "[[1,0],[1,1],[1,2],[1,3],[1,4],[1,5]]"], ["[-4,-2,0,2,4]", "[[2,0],[2,2],[2,4]]"], ["[11,13,17]", "[[1,0],[2,1],[3,2]]"], ["[2,4]", "[[0,0],[0,1]]"], ["[8]", "[[1,0],[2,0],[3,0]]"], ["[3,3,3]", "[[-1,0],[-1,1],[-1,2]]"], ["[1,4,6,8]", "[[1,0],[1,0],[1,0],[1,0]]"], ["[5,6,7,8,9]", "[[5,4],[-5,0],[3,2]]"], ["[0,2,4,6,8]", "[[-1,0],[-1,1],[-1,2],[-1,3],[-1,4]]"]], "expected": [[8, 6, 2, 4], [0], [4, 2, 0], [2, 6, 12], [0, 0, 0], [10, 6, 0], [6, 4], [-2, 0, 0], [10, 20, 30, 40], [0, 0, 2], [10, 0, -10], [2, 2, 2], [4, 10, 4], [2, 4, 6, 8, 10], [2, 4, 2], [10000, 0], [8, 0, 0], [2, 2, 2], [12, 6, 0], [6, 8, 6, 10, 6, 12], [2, 4, 6], [12, 12, 32], [6, 6], [0, 0, 14], [2, 4, 6], [20, 18, 22, 18], [28, 28, 38], [20, 18, 14, 8, 0]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "478", "slug": "sum-of-left-leaves", "id": 478, "title": "Sum of Left Leaves", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/sum-of-left-leaves/", "examples": [{"input": "root = [3,9,20,null,null,15,7]", "output": "24", "explanation": "Left leaves are 9 and 15, summing to 24."}, {"input": "root = [1]", "output": "0", "explanation": "The single node has no children, so there is no left leaf."}, {"input": "root = [1,2,3,4,5]", "output": "4", "explanation": "Only node 4 is a leaf reached as a left child."}], "hints": ["A left leaf is a node without children that hangs off the left side of its parent.", "Walk depth-first, carrying whether the current node is a left child.", "Add the value only when both conditions hold: left-child status and leaf status."], "statement": "You receive the root of a binary tree. Add up the values of certain special nodes: those that are leaves and sit as the left child of their parent.\n\nA leaf means a node with neither a left nor a right child. The root itself never counts, because it has no parent. Any leaf reached via a right edge is ignored.\n\nReturn the total of all qualifying left-leaf values.\n\n**Constraints:**\n- `1 <= number of nodes <= 1000`\n- `-1000 <= Node.val <= 1000`\n", "solution": "## Approach\n\nDepth-first search carries one extra flag telling whether the current node arrived as a left child. An empty child contributes nothing; a leaf contributes its value only when the flag is set; an inner node sums both sides with updated flags. Starting the walk at the root with the flag cleared counts exactly the left leaves.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the node count.\n- **Space Complexity:** O(h) recursion depth, O(n) worst case.\n\n## Implementation\n\n```python\nclass Solution:\n def sumOfLeftLeaves(self, root) -> int:\n def dfs(node, is_left: bool) -> int:\n if node is None:\n return 0\n if node.left is None and node.right is None:\n return node.val if is_left else 0\n return dfs(node.left, True) + dfs(node.right, False)\n return dfs(root, False)\n```\n", "starter": {"go": "package main\n\nfunc SumOfLeftLeaves(root *TreeNode) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def sumOfLeftLeaves(self, root) -> int:\n pass\n", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode *left, TreeNode *right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n int sumOfLeftLeaves(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "sumOfLeftLeaves", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int", "tests": [["[3,9,20,null,null,15,7]"], ["[1]"], ["[1,2,3,4,5]"], ["[1,2,null,3]"], ["[1,null,2]"], ["[1,2,3]"], ["[0]"], ["[1,2,3,4,null,null,5]"], ["[1,2,3,null,4,5,null]"], ["[5,4,6,3,null,null,7]"], ["[-1,-2,-3]"], ["[1,2,3,4,5,6,7]"], ["[1,null,2,3]"], ["[1,2,null,null,3]"], ["[2,1,3]"], ["[10,5,15,3,7,12,18]"], ["[1,2,3,4,null,5,null]"], ["[0,0,0,0,0]"], ["[1000,-1000,1000]"], ["[1,2,null,3,null,4]"], ["[1,null,2,null,3]"], ["[3,9,20,4,5,15,7]"], ["[1,2,2,3,4,4,3]"], ["[1,null,2,null,3,null,4]"], ["[2,null,3,null,4,null,5]"], ["[1,2,3,null,null,4,5]"], ["[7,3,9,1,5]"], ["[4,2,6,1,3,5,7]"], ["[1,2,3,4,5,null,null,6]"], ["[9,8,7,6,5]"]], "expected": [24, 0, 4, 3, 0, 2, 0, 4, 5, 3, -2, 10, 3, 0, 1, 15, 9, 0, -1000, 4, 0, 19, 7, 0, 0, 6, 1, 6, 6, 6], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "655", "slug": "sum-of-square-numbers", "id": 655, "title": "Sum of Square Numbers", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/sum-of-square-numbers/", "examples": [{"input": "c = 5", "output": "true", "explanation": "1^2 + 2^2 = 5."}, {"input": "c = 3", "output": "false", "explanation": "No pair of squares sums to 3."}, {"input": "c = 4", "output": "true", "explanation": "0^2 + 2^2 = 4."}], "hints": ["Think of a at 0 and b at floor(sqrt(c)) as two ends of the search.", "Compare a*a + b*b with c: too small moves a up, too large moves b down.", "Squares can reuse the same root (e.g. 2 = 1^2 + 1^2)."], "statement": "Given a non-negative integer `c`, decide whether two integer squares add up to it. That is, do there exist integers `a >= 0` and `b >= 0` with `a*a + b*b = c`?\n\nReturn true when such a pair exists and false otherwise.\n\n**Constraints:**\n- `0 <= c <= 2^31 - 1`\n", "solution": "## Approach\n\nPin one root at 0 and the other at the integer square root of c, then squeeze inward: the square sum grows when the low end rises and shrinks when the high end falls, so step the side indicated by the comparison with c. Meeting in the middle without a hit proves impossibility.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(sqrt(c)) steps.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nimport math\nclass Solution:\n def judgeSquareSum(self, c: int) -> bool:\n l, r = 0, math.isqrt(c)\n while l <= r:\n s = l * l + r * r\n if s == c:\n return True\n if s < c:\n l += 1\n else:\n r -= 1\n return False\n```\n", "starter": {"go": "package main\n\nfunc JudgeSquareSum(c int) bool {\n \n}", "python": "class Solution:\n def judgeSquareSum(self, c: int) -> bool:\n pass", "cpp": "class Solution {\npublic:\n bool judgeSquareSum(int c) {\n return false;\n }\n};"}, "fn": "judgeSquareSum", "params": [{"name": "c", "type": "int"}], "outputType": "boolean", "tests": [["5"], ["3"], ["4"], ["0"], ["1"], ["2"], ["6"], ["7"], ["8"], ["9"], ["10"], ["13"], ["16"], ["25"], ["50"], ["65"], ["100"], ["1000"], ["1000000"], ["2147483647"], ["18"], ["20"], ["26"], ["29"], ["41"], ["45"], ["72"], ["122"]], "expected": [true, false, true, true, true, true, false, false, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "896", "slug": "sum-of-subarray-minimums", "id": 896, "title": "Sum of Subarray Minimums", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/sum-of-subarray-minimums/", "examples": [{"input": "arr = [3,1,2,4]", "output": "17", "explanation": "Ten slice minima sum to 17."}, {"input": "arr = [11,81,94,43,3]", "output": "444", "explanation": "All slice minima sum to 444."}, {"input": "arr = [1,2,3]", "output": "10", "explanation": "Minima 1,2,3,1,2,1 total 10."}], "hints": ["Each position serves as the minimum for a rectangle of subarrays bounded by the previous strictly smaller element and the next smaller-or-equal element.", "Use a monotone increasing stack to find those borders in linear time, then add arr[i] * leftCount * rightCount."], "statement": "For every contiguous slice of `arr` (the slice must be non-empty and keep neighbours together), note its tiniest entry. Add those minima together and report the sum modulo `10^9 + 7`.\n\n**Constraints:**\n- `1 <= arr.length <= 3 * 10^4`\n- `1 <= arr[i] <= 3 * 10^4`\n", "solution": "## Approach\n\nEvery index dominates exactly those subarrays where it is the chosen minimum. Scanning with an increasing stack finds for each slot how far it stretches left until a strictly smaller value and right until a smaller-or-equal value; the asymmetric tie-break guarantees each subarray is credited once. Multiplying the value by the two stretch lengths and summing modulo `1_000_000_007` yields the total.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the two stack passes plus the final accumulation.\n- **Space Complexity:** O(n) for the border arrays and the stack.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sumSubarrayMins(self, arr: List[int]) -> int:\n MOD = 10 ** 9 + 7\n n = len(arr)\n left = [0] * n\n right = [0] * n\n st = []\n for i in range(n):\n while st and arr[st[-1]] > arr[i]:\n st.pop()\n left[i] = i + 1 if not st else i - st[-1]\n st.append(i)\n st.clear()\n for i in range(n - 1, -1, -1):\n while st and arr[st[-1]] >= arr[i]:\n st.pop()\n right[i] = n - i if not st else st[-1] - i\n st.append(i)\n return sum(a * l * r for a, l, r in zip(arr, left, right)) % MOD\n```\n", "starter": {"go": "package main\n\nfunc SumSubarrayMins(arr []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def sumSubarrayMins(self, arr: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int sumSubarrayMins(vector<int>& arr) {\n return 0;\n }\n};"}, "fn": "sumSubarrayMins", "params": [{"name": "arr", "type": "int_array"}], "outputType": "int", "tests": [["[3,1,2,4]"], ["[11,81,94,43,3]"], ["[1,2,3]"], ["[1]"], ["[2,2,2]"], ["[3,3,3,3]"], ["[4,3,2,1]"], ["[1,2,3,4]"], ["[5,4,3,2,1]"], ["[1,1,1,1]"], ["[2,1]"], ["[1,2]"], ["[3,1,2]"], ["[2,3,1]"], ["[7,5,7,5]"], ["[10,5,10]"], ["[1,3,2,4,5]"], ["[5,1,4,2,3]"], ["[30000,30000]"], ["[1,2,3,4,5,6]"], ["[6,5,4,3,2,1]"], ["[3,2,1,2,3]"], ["[4,4,1,4,4]"], ["[2,5,1,5,2]"], ["[11,11,11]"], ["[100,1,100]"], ["[3,1,2,4,5]"], ["[2,9,7,8,3,4,6,1]"]], "expected": [17, 444, 10, 1, 12, 30, 20, 20, 35, 10, 4, 4, 9, 10, 54, 40, 33, 28, 90000, 56, 56, 23, 33, 27, 66, 204, 30, 117], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "882", "slug": "sum-of-subsequence-widths", "id": 882, "title": "Sum of Subsequence Widths", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/sum-of-subsequence-widths/", "examples": [{"input": "nums = [2,1,3]", "output": "6", "explanation": "Singletons give 0; pairs give 1+1+2 and the triple gives 2."}, {"input": "nums = [2]", "output": "0", "explanation": "Only one subsequence with gap 0."}, {"input": "nums = [1,2,3,4]", "output": "23", "explanation": "Sorted contributions of maxima minus minima total 23."}], "hints": ["Sort a copy of the array first; the original order does not affect the collection of subsequence value-sets.", "In sorted order, the element at index i is the largest in exactly 2^i subsequences and the smallest in exactly 2^(n-1-i) of them.", "Precompute powers of two modulo 1000000007 and accumulate a[i] * (2^i - 2^(n-1-i))."], "statement": "For any non-empty collection of numbers, look at the gap between its biggest entry and its tiniest entry. A lone element therefore has a gap of zero.\n\nYou are handed an integer array `nums`. Think about every subsequence you can build by keeping some elements and dropping the rest while preserving their relative order (the kept elements need not sit next to each other). Add up the gap of each such subsequence, then give the total modulo `10^9 + 7`.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `1 <= nums[i] <= 10^5`\n", "solution": "## Approach\n\nSort the numbers so that order no longer matters for counting value-sets. In the sorted line-up, the element at position `i` serves as the biggest entry in precisely `2^i` subsequences (choose any subset of the `i` smaller items to join it) and as the tiniest entry in precisely `2^(n-1-i)` subsequences. Its net contribution is therefore `a[i] * (2^i - 2^(n-1-i))`. Adding those terms with powers of two prepared modulo `1_000_000_007` gives the wanted total.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for the sort plus O(n) for the sweep.\n- **Space Complexity:** O(n) for the sorted copy and the power table (O(1) extra besides sorting if done in place).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sumSubseqWidths(self, nums: List[int]) -> int:\n MOD = 10 ** 9 + 7\n a = sorted(nums)\n n = len(a)\n pw = [1] * n\n for i in range(1, n):\n pw[i] = (pw[i - 1] * 2) % MOD\n ans = 0\n for i, v in enumerate(a):\n ans = (ans + v * (pw[i] - pw[n - 1 - i])) % MOD\n return ans % MOD\n```\n", "starter": {"go": "package main\n\nfunc SumSubseqWidths(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def sumSubseqWidths(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int sumSubseqWidths(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "sumSubseqWidths", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[2,1,3]"], ["[2]"], ["[1,2,3,4]"], ["[1,1,1]"], ["[1,2]"], ["[5,4,3,2,1]"], ["[1,100000]"], ["[100000,1]"], ["[3,3,3,3]"], ["[1,2,3]"], ["[10,20,30]"], ["[5]"], ["[2,2,1]"], ["[1,3,2]"], ["[7,7,7,7,7,7]"], ["[1,2,3,4,5]"], ["[5,1,4,2,3]"], ["[10000,20000,30000]"], ["[1,1,2,2,3,3]"], ["[9,8,7,6,5,4,3,2,1]"], ["[1]"], ["[100000,100000]"], ["[2,1]"], ["[4,3,2,1]"], ["[6,1,5,2,4,3]"], ["[10,1,10,1,10]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[3,1,2,4,5]"]], "expected": [6, 0, 23, 0, 1, 72, 99999, 99999, 0, 6, 60, 0, 3, 6, 0, 72, 72, 60000, 90, 3084, 0, 0, 1, 23, 201, 189, 7181, 72], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "11", "slug": "sum-of-two-integers", "id": 11, "title": "Sum of Two Integers", "difficulty": "Medium", "category": "binary", "link": "https://leetcode.com/problems/sum-of-two-integers/", "examples": [{"input": "a = 1, b = 2", "output": "3", "explanation": "1 + 2 = 3."}, {"input": "a = 2, b = 3", "output": "5", "explanation": "2 + 3 = 5."}], "hints": ["Use bitwise operations: the partial sum is `a ^ b` and the carry is `(a & b) << 1`. Iterate until the carry is zero."], "statement": "You are given two integers `a` and `b`. Compute their combined total while steering clear of the `+` and `-` operators.\n\n**Constraints:**\n\n- -1000 \u2264 a, b \u2264 1000\n", "solution": "## Approach\n\nAddition without `+` or `-` can be done entirely with bitwise operations:\n\n- **XOR** (`a ^ b`) computes the sum of each bit *without* considering carries \u2014 it's like adding binary digits where `1+1 = 0` with a carry of `1` that gets lost.\n- **AND with left shift** (`(a & b) << 1`) computes the *carry* \u2014 bits where both operands are `1` produce a carry that must be added to the next higher bit.\n\nThe process repeats, adding the carry back to the sum, until no carry remains (`b == 0`). This naturally bottoms out because each iteration shifts the carry left, eventually making it zero.\n\nIn languages with fixed-width integers (e.g., Go's `int`, Java's `int`), a recursive version is clean and intuitive: the base case `b == 0` returns `a`, and the recursive call adds the carry to the sum.\n\nPython's unbounded integers require an extra 32-bit mask to simulate fixed-width overflow, which obscures the core idea.\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 getSum(self, a: int, b: int) -> int:\n mask = 0xFFFFFFFF\n while b:\n a, b = (a ^ b) & mask, ((a & b) << 1) & mask\n return a if a < 0x80000000 else ~(a ^ mask)\n```\n\n```go\nfunc GetSum(a int, b int) int {\n if b == 0 {\n return a\n }\n sum := a ^ b\n carry := (a & b) << 1\n return GetSum(sum, carry)\n}\n```\n", "starter": {"go": "package main\n\nfunc GetSum(a int, b int) int {\n \n}", "python": "class Solution:\n def getSum(self, a: int, b: int) -> int:\n pass\n", "cpp": "class Solution {\npublic:\n int getSum(int a, int b) {\n return 0;\n }\n};"}, "fn": "getSum", "params": [{"name": "a", "type": "int"}, {"name": "b", "type": "int"}], "outputType": "int", "tests": [["1", "2"], ["2", "3"], ["-1", "1"], ["-5", "-7"], ["0", "0"], ["-1000", "1000"], ["1000", "0"], ["-500", "-500"], ["777", "222"], ["0", "1"], ["-1", "-1"], ["1000", "1000"], ["-1000", "-1000"], ["500", "500"], ["-999", "999"], ["1", "-1"], ["123", "456"], ["-123", "-456"], ["0", "-1000"], ["1000", "-1000"], ["42", "-42"], ["17", "83"], ["-300", "700"], ["999", "1"], ["-1", "0"], ["11", "22"], ["-15", "40"], ["600", "-200"], ["321", "123"], ["-700", "-100"]], "expected": [3, 5, 0, -12, 0, 0, 1000, -1000, 999, 1, -2, 2000, -2000, 1000, 0, 0, 579, -579, -1000, 0, 0, 100, 400, 1000, -1, 33, 25, 400, 444, -800], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "300", "slug": "sum-root-to-leaf-numbers", "id": 300, "title": "Sum Root to Leaf Numbers", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/sum-root-to-leaf-numbers/", "examples": [{"input": "root = [1,2,3]", "output": "25", "explanation": "Paths 1->2 (12) and 1->3 (13) sum to 25."}, {"input": "root = [4,9,0,5,1]", "output": "1026", "explanation": "Paths give 495 + 491 + 40 = 1026."}], "hints": ["Carry the prefix value down: child prefix = parent prefix * 10 + child digit.", "Add the prefix to the answer only at leaves.", "Both DFS and BFS with the running number work."], "statement": "You are given the root of a binary tree whose nodes hold digits `0` through `9`. Every path from the root down to a leaf spells a decimal number by concatenating the digits along the way.\n\nFor instance, the path `1 -> 2 -> 3` stands for `123`.\n\nAdd up the numbers spelled by all root-to-leaf paths and return the total. The answer fits in a 32-bit integer. A leaf is a node with no children.\n\n**Constraints:**\n- The tree holds between 1 and 1000 nodes.\n- `0 <= Node.val <= 9`\n- Tree depth is at most 10.\n", "solution": "## Approach\n\nDo a depth-first walk that carries the number formed so far. Entering a child multiplies the prefix by ten and adds the child's digit; reaching a leaf returns the completed number, while internal nodes return the sum of both subtrees.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited once.\n- **Space Complexity:** O(h) for the recursion stack, where h is the tree height.\n\n## Implementation\n\n```python\nclass Solution:\n def sumNumbers(self, root) -> int:\n def dfs(node, cur):\n if not node:\n return 0\n v = cur * 10 + node.val\n if not node.left and not node.right:\n return v\n return dfs(node.left, v) + dfs(node.right, v)\n return dfs(root, 0)\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 SumNumbers(root *TreeNode) int {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def sumNumbers(self, root):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n int sumNumbers(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "sumNumbers", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int", "tests": [["[1,2,3]"], ["[4,9,0,5,1]"], ["[0]"], ["[1]"], ["[9]"], ["[1,0]"], ["[1,null,2]"], ["[1,2,null,3]"], ["[0,0,0]"], ["[9,9,9]"], ["[2,null,3,null,4]"], ["[5,4,8,1,null,3,null]"], ["[1,2,3,4,5]"], ["[4,9,5,1,null,2]"], ["[0,1,0]"], ["[3,5,1,6,2,9,8,null,null,7,4]"], ["[1,2,3,4,null,null,5]"], ["[8,3,null,1,6]"], ["[7,null,8,null,9]"], ["[2,2,2,2,2,2,2]"], ["[1,0,1,0,1]"], ["[6,1,9,0,2]"], ["[3,null,4,null,5,null,6]"], ["[9,1,0]"], ["[4,0,0]"], ["[5,3,null,2,null,1]"], ["[1,2,3,null,4,null,5]"], ["[0,null,0,null,0]"]], "expected": [25, 1026, 0, 1, 9, 10, 12, 123, 0, 198, 234, 1124, 262, 943, 1, 8044, 259, 1667, 789, 888, 212, 1291, 3456, 181, 80, 5321, 259, 0], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "341", "slug": "summary-ranges", "id": 341, "title": "Summary Ranges", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/summary-ranges/", "examples": [{"explanation": "0,1,2 form one run (\"0->2\"), 4,5 form another (\"4->5\"), and 7 stands alone.", "input": "nums = [0,1,2,4,5,7]", "output": "[\"0->2\",\"4->5\",\"7\"]"}, {"explanation": "0 and 6 are solitary; 2,3,4 collapse to \"2->4\" and 8,9 to \"8->9\".", "input": "nums = [0,2,3,4,6,8,9]", "output": "[\"0\",\"2->4\",\"6\",\"8->9\"]"}, {"explanation": "There are no runs at all.", "input": "nums = []", "output": "[]"}], "hints": ["Walk the array tracking where the current consecutive run started.", "A run ends where the next value is not exactly one more; emit \"start\" for a lone value and \"start->end\" otherwise.", "Compare with nums[i] + 1 using long arithmetic to stay safe at the integer extremes."], "statement": "You are given a sorted array `nums` of distinct integers. Compress every maximal run of consecutive numbers into a short label: a lone value `a` becomes `\"a\"`, while a run from `a` to `b` (with `b > a`) becomes `\"a->b\"`.\n\nReturn the labels in the order the runs appear.\n\n**Constraints:**\n- `0 <= nums.length <= 20`\n- `-2^31 <= nums[i] <= 2^31 - 1`\n- `nums` is sorted in strictly increasing order.\n", "solution": "## Approach\n\nSweep the sorted array while remembering where the current consecutive run began. Extend the run while each next value is exactly one more than the previous; when the run breaks, emit the start alone for a single value or `start->end` for a longer run. Widening to 64-bit arithmetic before adding one keeps the extreme 32-bit values safe.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), a single pass.\n- **Space Complexity:** O(1) besides the output labels.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def summaryRanges(self, nums: List[int]) -> List[str]:\n res: List[str] = []\n i = 0\n while i < len(nums):\n start = nums[i]\n while i + 1 < len(nums) and nums[i + 1] == nums[i] + 1:\n i += 1\n end = nums[i]\n if start == end:\n res.append(str(start))\n else:\n res.append(f\"{start}->{end}\")\n i += 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc SummaryRanges(nums []int) []string {\n return []string{}\n}", "python": "from typing import List\n\nclass Solution:\n def summaryRanges(self, nums: List[int]) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> summaryRanges(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "summaryRanges", "params": [{"name": "nums", "type": "int_array"}], "outputType": "string_list", "tests": [["[0,1,2,4,5,7]"], ["[0,2,3,4,6,8,9]"], ["[]"], ["[1]"], ["[-1]"], ["[0]"], ["[1,2]"], ["[1,3]"], ["[-3,-2,-1,0,1]"], ["[-5,-3,-1,1,3]"], ["[1,2,3,4,5]"], ["[-5,-4,-3,0,2,3,4]"], ["[0,1,2,3,4,5,6,7,8,9]"], ["[10,20,30]"], ["[-2147483648,-2147483647,2147483646,2147483647]"], ["[2147483647]"], ["[-2147483648]"], ["[1,3,5,6,7,9]"], ["[0,2,4,6,8]"], ["[-2,-1,0,2,3,5]"], ["[100]"], ["[1,2,3,5,6,8,9,10,12]"], ["[-10,-9,-8,-5,-4,0]"], ["[7,8,9,11,12,14,15,16]"], ["[0,1,3,4,5,7,8,9,11]"], ["[-1,0,1,3,5,6,7]"], ["[2]"], ["[1,2,3,4,6,7,9,10,11,13,14,15,16]"]], "expected": [["0->2", "4->5", "7"], ["0", "2->4", "6", "8->9"], [], ["1"], ["-1"], ["0"], ["1->2"], ["1", "3"], ["-3->1"], ["-5", "-3", "-1", "1", "3"], ["1->5"], ["-5->-3", "0", "2->4"], ["0->9"], ["10", "20", "30"], ["-2147483648->-2147483647", "2147483646->2147483647"], ["2147483647"], ["-2147483648"], ["1", "3", "5->7", "9"], ["0", "2", "4", "6", "8"], ["-2->0", "2->3", "5"], ["100"], ["1->3", "5->6", "8->10", "12"], ["-10->-8", "-5->-4", "0"], ["7->9", "11->12", "14->16"], ["0->1", "3->5", "7->9", "11"], ["-1->1", "3", "5->7"], ["2"], ["1->4", "6->7", "9->11", "13->16"]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "878", "slug": "super-egg-drop", "id": 878, "title": "Super Egg Drop", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/super-egg-drop/", "examples": [{"input": "k = 1, n = 2", "output": "2", "explanation": "With one egg there is no room for risk, so both floors must be tried from the bottom up."}, {"input": "k = 2, n = 6", "output": "3", "explanation": "Three drops always suffice (for instance, first try floor 3), and two drops cannot cover 6 floors."}, {"input": "k = 3, n = 14", "output": "4", "explanation": "Four drops cover up to 4 + 6 + 4 = 14 floors with three eggs, and three drops fall short."}], "hints": ["Flip the question: with m drops and e eggs, the tallest tower you can resolve is dp[m][e] = dp[m-1][e-1] + dp[m-1][e] + 1.", "Grow the drop count until the coverage reaches n; a one-dimensional table updated from high eggs to low eggs is enough."], "statement": "You have `k` identical eggs and a tower with `n` floors. An egg dropped from floor `f` either breaks (then the critical floor is below `f`) or survives (then it is at or above `f`). Find the smallest number of drops that guarantees locating the critical floor in the worst case, no matter where it is.\n\nReturn that minimum number of drops.\n\n**Constraints:**\n- `1 <= k <= 100`\n- `1 <= n <= 10^4`\n", "solution": "## Approach\n\nInstead of asking how many drops a tower needs, ask how tall a tower `m` drops can resolve: one more drop lets you test a floor, then handle the `dp[m-1][e-1]` floors below it if the egg breaks or the `dp[m-1][e]` floors above it if it survives, giving `dp[m][e] = dp[m-1][e-1] + dp[m-1][e] + 1`. Increase `m` until the coverage reaches `n`, keeping a single array swept from high egg counts downward.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k * m), where m is the answer (at most n). Each round updates k entries.\n- **Space Complexity:** O(k) for the coverage array.\n\n## Implementation\n\n```python\nclass Solution:\n def superEggDrop(self, k: int, n: int) -> int:\n dp = [0] * (k + 1)\n moves = 0\n while dp[k] < n:\n moves += 1\n for e in range(k, 0, -1):\n dp[e] = dp[e] + dp[e - 1] + 1\n return moves\n```\n", "starter": {"go": "package main\n\nfunc SuperEggDrop(k int, n int) int {\n \n}", "python": "class Solution:\n def superEggDrop(self, k: int, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int superEggDrop(int k, int n) {\n return 0;\n }\n};"}, "fn": "superEggDrop", "params": [{"name": "k", "type": "int"}, {"name": "n", "type": "int"}], "outputType": "int", "tests": [["1", "2"], ["2", "6"], ["3", "14"], ["1", "1"], ["2", "1"], ["2", "2"], ["2", "3"], ["2", "4"], ["2", "100"], ["3", "100"], ["4", "100"], ["100", "10000"], ["2", "1000"], ["3", "1000"], ["5", "1000"], ["1", "100"], ["1", "10000"], ["10", "1"], ["10", "2"], ["3", "25"], ["4", "50"], ["2", "10"], ["3", "7"], ["4", "15"], ["5", "31"], ["7", "1000"], ["100", "1"], ["6", "500"]], "expected": [2, 3, 4, 1, 1, 2, 2, 3, 14, 9, 8, 14, 45, 19, 11, 100, 10000, 1, 2, 5, 6, 4, 3, 4, 5, 11, 1, 10], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "895", "slug": "super-palindromes", "id": 895, "title": "Super Palindromes", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/super-palindromes/", "examples": [{"input": "left = \"4\", right = \"1000\"", "output": "4", "explanation": "4, 9, 121 and 484 qualify."}, {"input": "left = \"1\", right = \"2\"", "output": "1", "explanation": "Only 1 qualifies."}, {"input": "left = \"1\", right = \"100000\"", "output": "10", "explanation": "Ten qualify below 100000."}], "hints": ["Square roots of candidates stay below 1e9 and must themselves be palindromes, so only about 1e5 halves need trying.", "Mirror each half i into odd and even palindromes, square them, and keep those whose square is a palindrome inside the interval."], "statement": "A palindrome reads identically forward and backward, like `121`. Call a positive integer a super-palindrome when it is itself a palindrome and it equals the square of another palindrome (for instance `121` is `11 * 11`).\n\nYou are given interval ends `left` and `right` as decimal strings (they may be far too large for casual handling, yet they always denote values below `10^18`). Count the super-palindromes lying inside the inclusive interval.\n\n**Constraints:**\n- `1 <= left.length, right.length <= 18`\n- Both strings hold only digits with no leading zeros.\n- They denote integers in `[1, 10^18 - 1]` with `left <= right`.\n", "solution": "## Approach\n\nAny super-palindrome below `10^18` has a palindromic root below `10^9`. Such roots are fully described by their left half: mirroring the half yields both odd-length and even-length candidates. Trying halves from `1` to `100000` (covering all roots up to `10^9` when mirrored) produces every possible square; keeping those whose square reads as a palindrome builds the complete catalogue once. Each query then counts catalogue entries inside `[left, right]`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(H * L) with H = 1e5 halves and L digits for palindrome checks, once; each query scans the small catalogue.\n- **Space Complexity:** O(1) besides the catalogue of a few dozen values.\n\n## Implementation\n\n```python\nclass Solution:\n def superpalindromesInRange(self, left: str, right: str) -> int:\n def is_pal(x: int) -> bool:\n s = str(x)\n return s == s[::-1]\n cands = set()\n for half in range(1, 100000):\n h = str(half)\n r = h[::-1]\n for root in (int(h + r[1:]), int(h + r)):\n sq = root * root\n if sq < 10 ** 18 and is_pal(sq):\n cands.add(sq)\n L, R = int(left), int(right)\n return sum(1 for v in cands if L <= v <= R)\n```\n", "starter": {"go": "package main\n\nfunc SuperpalindromesInRange(left string, right string) int {\n \n}", "python": "class Solution:\n def superpalindromesInRange(self, left: str, right: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int superpalindromesInRange(string left, string right) {\n return 0;\n }\n};"}, "fn": "superpalindromesInRange", "params": [{"name": "left", "type": "string"}, {"name": "right", "type": "string"}], "outputType": "int", "tests": [["4", "1000"], ["1", "2"], ["1", "100000"], ["1", "1"], ["2", "2"], ["9", "9"], ["10", "100"], ["121", "121"], ["1", "1000"], ["100", "10000"], ["1", "100000000000000000"], ["4", "4"], ["5", "8"], ["11", "22"], ["100", "121"], ["484", "484"], ["1", "10"], ["1000", "100000"], ["10000000000000000", "99999999999999999"], ["1", "999"], ["10000", "1000000"], ["14641", "14641"], ["10201", "10201"], ["1000000", "10000000"], ["2", "100"], ["1000000000", "10000000000"], ["942345", "1294828"], ["1", "1000000000"]], "expected": [4, 1, 10, 1, 0, 1, 0, 1, 5, 2, 70, 1, 0, 0, 1, 1, 3, 5, 22, 5, 5, 1, 1, 3, 2, 0, 2, 21], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "450", "slug": "super-pow", "id": 450, "title": "Super Pow", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/super-pow/", "examples": [{"input": "a = 2, b = [3]", "output": "8", "explanation": "Exponent 3 gives 2^3 = 8."}, {"input": "a = 2, b = [1,0]", "output": "1024", "explanation": "Exponent 10 gives 1024."}, {"input": "a = 1, b = [4,3,3,8,5,2]", "output": "1", "explanation": "Powers of 1 stay 1."}], "hints": ["Fold digits with result = result^10 * a^digit (mod 1337) at each step.", "Write a small modular power helper using binary exponentiation.", "Reduce the base modulo 1337 first; large exponents never fit in one integer."], "statement": "Raise a base to an enormous exponent given digit by digit, then reduce modulo 1337.\n\nYou receive an integer `a` and an array `b` whose entries are the decimal digits of a huge exponent (most significant first, no leading zeros). Compute `a` raised to that exponent, modulo `1337`. The exponent can have up to 2000 digits, so it must never be rebuilt as one machine integer; instead fold the digits in one at a time with modular arithmetic.\n\n**Constraints:**\n- `1 <= a <= 2^31 - 1`\n- `1 <= b.length <= 2000`\n- `0 <= b[i] <= 9`\n- `b` has no leading zeros.\n", "solution": "## Approach\n\nProcess the exponent digits left to right while keeping everything modulo 1337. Appending a digit `d` multiplies the previous exponent by ten and adds `d`, so update the answer as `ans = ans^10 * a^d`. Both powers use fast binary exponentiation after reducing the base.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m log 1337), where m is the number of digits in `b`; each digit needs two small modular powers.\n- **Space Complexity:** O(1) extra.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def superPow(self, a: int, b: List[int]) -> int:\n MOD = 1337\n def pow_mod(x, e):\n r = 1 % MOD\n x %= MOD\n while e:\n if e & 1:\n r = (r * x) % MOD\n x = (x * x) % MOD\n e >>= 1\n return r\n res = 1\n for d in b:\n res = pow_mod(res, 10)\n res = (res * pow_mod(a, d)) % MOD\n return res\n```\n", "starter": {"go": "package main\n\nfunc SuperPow(a int, b []int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def superPow(self, a: int, b: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int superPow(int a, vector<int>& b) {\n return 0;\n }\n};"}, "fn": "superPow", "params": [{"name": "a", "type": "int"}, {"name": "b", "type": "int_array"}], "outputType": "int", "tests": [["2", "[3]"], ["2", "[1,0]"], ["1", "[4,3,3,8,5,2]"], ["2147483647", "[1]"], ["2", "[0]"], ["3", "[1]"], ["3", "[2]"], ["10", "[2]"], ["1337", "[5]"], ["1338", "[1]"], ["2", "[1,1]"], ["2", "[2,0]"], ["5", "[3]"], ["7", "[1,2]"], ["100", "[1,0,0]"], ["3", "[9,9]"], ["4", "[5,0]"], ["9", "[9]"], ["2", "[1,0,0,0]"], ["6", "[2,5]"], ["11", "[7]"], ["12", "[1,3]"], ["1000", "[9,9,9]"], ["2147483647", "[9,9,9,9]"], ["1", "[0]"], ["2", "[5]"], ["3", "[1,0,0]"], ["8", "[4]"], ["15", "[2,0]"], ["100", "[5]"], ["1000000", "[1,2,3,4,5]"]], "expected": [8, 1024, 1, 932, 1, 3, 9, 100, 0, 1, 711, 368, 125, 49, 562, 272, 1178, 673, 345, 1007, 396, 40, 20, 939, 1, 32, 816, 85, 680, 753, 414], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "402", "slug": "super-ugly-number", "id": 402, "title": "Super Ugly Number", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/super-ugly-number/", "examples": [{"explanation": "The ordered sequence starts [1,2,4,7,8,13,14,16,19,26,28,32], whose 12th entry is 32.", "input": "n = 12, primes = [2,7,13,19]", "output": "32"}, {"explanation": "The first super ugly number is always 1, which has no prime factors.", "input": "n = 1, primes = [2,3,5]", "output": "1"}, {"explanation": "The ordered sequence starts [1,2,3,4,5,6,8,9,10,12,15], whose 11th entry is 15.", "input": "n = 11, primes = [2,3,5]", "output": "15"}], "hints": ["Maintain one index per prime pointing into the ugly sequence; the next candidate from prime p is ugly[idx] * p.", "Always take the smallest candidate, then advance every index that produced it (duplicates must all move).", "Use 64-bit arithmetic for the products and cast back, since intermediate values can exceed 32 bits."], "statement": "A positive integer is called a *super ugly number* when every prime divisor it has appears in a given list `primes`. By convention, `1` counts as a super ugly number since it has no prime divisors at all.\n\nYou are given an integer `n` and a strictly increasing array `primes` of prime numbers. Consider all super ugly numbers built from `primes`, sorted from smallest to largest, and return the `n`-th value in that ordering (counting from 1). The answer always fits into a 32-bit signed integer.\n\n**Constraints:**\n- `1 <= n <= 10^5`\n- `1 <= primes.length <= 100`\n- `2 <= primes[i] <= 1000`\n- Each `primes[i]` is prime, and the values are distinct and sorted increasingly.\n", "solution": "## Approach\n\nKeep one pointer per prime into the ugly sequence built so far. Each prime proposes a candidate equal to its prime times the ugly number at its pointer. Repeatedly append the smallest candidate and advance every pointer that produced it, which merges the multiples in order while skipping duplicates.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * k), where n is the requested position and k is the number of primes.\n- **Space Complexity:** O(n + k) for the sequence and the pointers.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int:\n ugly = [1] * n\n idx = [0] * len(primes)\n nxt = list(primes)\n for i in range(1, n):\n m = min(nxt)\n ugly[i] = m\n for j, p in enumerate(primes):\n if nxt[j] == m:\n idx[j] += 1\n nxt[j] = ugly[idx[j]] * p\n return ugly[n - 1]\n```\n", "starter": {"go": "package main\n\nfunc NthSuperUglyNumber(n int, primes []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def nthSuperUglyNumber(self, n: int, primes: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int nthSuperUglyNumber(int n, vector<int>& primes) {\n return 0;\n }\n};"}, "fn": "nthSuperUglyNumber", "params": [{"name": "n", "type": "int"}, {"name": "primes", "type": "int_array"}], "outputType": "int", "tests": [["12", "[2,7,13,19]"], ["1", "[2,3,5]"], ["11", "[2,3,5]"], ["2", "[2,3,5]"], ["15", "[2,3,5]"], ["10", "[2,3,5]"], ["100", "[2,3,5]"], ["1000", "[2,3,5]"], ["5", "[2]"], ["1", "[2]"], ["10", "[2]"], ["7", "[3,5,7,11]"], ["20", "[3,5,7,11]"], ["50", "[2,7,13,19]"], ["100", "[2,7,13,19]"], ["3", "[5,7,11]"], ["25", "[5,7,11]"], ["30", "[2,3,7,43]"], ["2", "[1000]"], ["4", "[2,3]"], ["40", "[2,3]"], ["60", "[2,3,5,7,11,13]"], ["200", "[2,3,5,7,11,13]"], ["500", "[2,3,5]"], ["1500", "[2,3,5]"], ["8", "[7,13,19]"], ["16", "[7,13,19]"], ["100", "[11,13,17,19,23]"], ["6", "[2,5]"], ["9", "[2,5]"]], "expected": [32, 1, 15, 2, 24, 12, 1536, 51200000, 16, 1, 512, 15, 99, 728, 5408, 7, 1715, 86, 1000, 4, 972, 98, 700, 937500, 859963392, 169, 2197, 83521, 10, 25], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "577", "slug": "super-washing-machines", "id": 577, "title": "Super Washing Machines", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/super-washing-machines/", "examples": [{"input": "machines = [1,0,5]", "output": "3", "explanation": "The average is 2. The left machine needs 1 more and the right one must give 3 away; balancing takes 3 moves."}, {"input": "machines = [0,3,0]", "output": "2", "explanation": "The average is 1. Both outer machines pull one garment from the middle, finishing in 2 moves."}, {"input": "machines = [0,2,0]", "output": "-1", "explanation": "The total 2 cannot be split evenly across 3 machines."}], "hints": ["If the total is not divisible by n, answer -1; otherwise each machine targets total / n garments.", "Scan left to right tracking the running imbalance; a machine's bottleneck is the larger of its own surplus/deficit and the flow passing through it."], "statement": "A row of `n` washing machines holds `machines[i]` garments each. In one move, any number of machines may each hand a single garment to a neighboring machine (left or right). The goal is an even split where every machine ends with the same count.\n\nReturn the smallest number of moves that achieves the split, or `-1` when the total garment count is not divisible by `n` and sharing is therefore impossible.\n\n**Constraints:**\n- `1 <= machines.length <= 10^4`\n- `0 <= machines[i] <= 10^5`\n", "solution": "## Approach\n\nWhen the total is not divisible by the machine count, equal sharing is impossible. Otherwise each machine aims for the average load. Sweeping left to right, keep the cumulative surplus or deficit that must flow across the current boundary; each position's bottleneck is the larger of its own gap to the average and the absolute flow passing through. The overall answer is the worst bottleneck encountered.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the total plus one sweep.\n- **Space Complexity:** O(1) extra memory.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findMinMoves(self, machines: List[int]) -> int:\n n = len(machines)\n total = sum(machines)\n if total % n != 0:\n return -1\n avg = total // n\n ans = 0\n balance = 0\n for x in machines:\n diff = x - avg\n balance += diff\n ans = max(ans, abs(balance), diff)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FindMinMoves(machines []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findMinMoves(self, machines: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findMinMoves(vector<int>& machines) {\n return -1;\n }\n};"}, "fn": "findMinMoves", "params": [{"name": "machines", "type": "int_array"}], "outputType": "int", "tests": [["[1,0,5]"], ["[0,3,0]"], ["[0,2,0]"], ["[1,1,1]"], ["[0,0,0]"], ["[5]"], ["[4,0,0,4]"], ["[9,1,8,8,9]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[0,0,11,5]"], ["[2,2,2,2]"], ["[10,0,0,0,0,0,0,0,0,0]"], ["[0,0,0,0,0,0,0,0,0,10]"], ["[3,3,3]"], ["[7,0,7,0,7,0,7]"], ["[100000,0,0,0]"], ["[1,0,0,0,0,0,0,0,0,0,0,2]"], ["[4,4,4,0]"], ["[8,4,12]"], ["[0,4,0,4,0,4]"], ["[6,0,6]"], ["[2,4,6,8]"], ["[5,5,0,0,5]"], ["[1,10,1,10,1]"], ["[0,1,0,1,0,1]"], ["[12,0,0,0]"], ["[3,1,4,1,5,9,2,6]"]], "expected": [3, 2, -1, 0, 0, 0, 2, 4, 3, 3, 8, 0, 9, 9, 0, 3, 75000, -1, 3, 4, 2, 2, 4, 4, -1, -1, 9, -1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "883", "slug": "surface-area-of-3d-shapes", "id": 883, "title": "Surface Area of 3D Shapes", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/surface-area-of-3d-shapes/", "examples": [{"input": "grid = [[1,2],[3,4]]", "output": "34", "explanation": "Sum of lone-tower areas minus shared sides gives 34."}, {"input": "grid = [[1,1,1],[1,0,1],[1,1,1]]", "output": "32", "explanation": "Ring of eight cubes around a hole shows 32 faces."}, {"input": "grid = [[2,2,2],[2,1,2],[2,2,2]]", "output": "46", "explanation": "Border towers of height 2 plus centre of height 1 total 46."}], "hints": ["A lone tower of height v shows 4*v+2 faces when v is positive and 0 otherwise.", "Each pair of side-adjacent cells hides 2*min(v1,v2) faces; count each pair once by looking only right and down."], "statement": "Picture an `n` by `n` board. On the cell in row `i`, column `j` you pile up `grid[i][j]` unit cubes, one on top of another, forming a small tower (a zero means the cell stays empty). Towers that touch side-by-side hide the faces where they meet, and cubes stacked vertically hide the faces between them.\n\nCount every square that remains visible from the outside, counting the underside that rests on the table as well.\n\n**Constraints:**\n- `n == grid.length == grid[i].length`\n- `1 <= n <= 50`\n- `0 <= grid[i][j] <= 50`\n", "solution": "## Approach\n\nTreat every cell on its own: a tower of height `v > 0` exposes `4*v + 2` unit squares (four sides per cube plus a top and a bottom). Adding those overcounts only where two towers stand shoulder to shoulder. A neighbouring pair of heights `a` and `b` conceals `min(a, b)` squares on each of the two touching walls, so subtract `2*min(a,b)` once per adjacent pair by scanning right and down neighbours only.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) for an n by n board, one pass for towers and one for adjacencies.\n- **Space Complexity:** O(1) besides the input.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n n = len(grid)\n ans = 0\n for i in range(n):\n for j in range(len(grid[i])):\n v = grid[i][j]\n if v > 0:\n ans += 4 * v + 2\n for i in range(n):\n for j in range(len(grid[i])):\n if j + 1 < len(grid[i]):\n ans -= 2 * min(grid[i][j], grid[i][j + 1])\n if i + 1 < n and j < len(grid[i + 1]):\n ans -= 2 * min(grid[i][j], grid[i + 1][j])\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SurfaceArea(grid [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def surfaceArea(self, grid: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int surfaceArea(vector<vector<int>>& grid) {\n return 0;\n }\n};"}, "fn": "surfaceArea", "params": [{"name": "grid", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,2],[3,4]]"], ["[[1,1,1],[1,0,1],[1,1,1]]"], ["[[2,2,2],[2,1,2],[2,2,2]]"], ["[[1]]"], ["[[0]]"], ["[[2]]"], ["[[1,2]]"], ["[[1],[2]]"], ["[[0,0],[0,0]]"], ["[[1,0],[0,2]]"], ["[[2,2],[2,2]]"], ["[[1,3,1],[1,2,1],[1,3,1]]"], ["[[0,1,0],[1,1,1],[0,1,0]]"], ["[[3]]"], ["[[50]]"], ["[[1,1],[1,1]]"], ["[[2,1],[1,2]]"], ["[[0,0,0],[0,1,0],[0,0,0]]"], ["[[5,5,5],[5,5,5],[5,5,5]]"], ["[[1,2,3],[4,5,6]]"], ["[[4]]"], ["[[1,0,1],[0,1,0],[1,0,1]]"], ["[[3,2],[1,4]]"], ["[[10,10],[10,10]]"], ["[[0,2,0],[2,0,2],[0,2,0]]"], ["[[1,2,3,4]]"], ["[[1],[2],[3],[4]]"], ["[[2,0,2],[0,0,0],[2,0,2]]"]], "expected": [34, 32, 46, 6, 0, 10, 14, 14, 0, 16, 24, 46, 22, 14, 202, 16, 24, 6, 78, 60, 18, 30, 36, 88, 40, 36, 36, 40], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "118", "slug": "surrounded-regions", "id": 118, "title": "Surrounded Regions", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/surrounded-regions/", "examples": [{"input": "board = [\"XXXX\",\"XOOX\",\"XXOX\",\"XOXX\"]", "output": "[\"XXXX\",\"XXXX\",\"XXXX\",\"XOXX\"]", "explanation": "The lower-left `O` touches the boundary; the other `O` cells are captured."}, {"input": "board = [\"X\"]", "output": "[\"X\"]", "explanation": "There are no 'O's to flip, so the board remains [\"X\"]."}], "hints": ["Start from boundary `O` cells and mark every `O` reachable from them.", "After the traversal, capture only unmarked `O` cells and restore the marked cells."], "statement": "Given a nonempty rectangular board represented by an array of equal-width strings, capture every region of `O` cells that is completely surrounded by `X` cells.\n\nCells connect horizontally and vertically. An `O` connected to any boundary `O` is not surrounded and must remain unchanged. Replace every other `O` with `X` and return the transformed rows.\n\nThis version adapts the usual in-place character-grid operation to `solve(board: string_array) -> string_list`.\n\n**Constraints:**\n- `1 <= board.length <= 200`\n- `1 <= board[r].length <= 200`\n- Every row has the same length.\n- Every character is `X` or `O`.\n", "solution": "## Approach\n\nConvert the immutable input strings into a character grid and mark every `O` connected to the boundary with a breadth-first search. These marked cells cannot be captured. After the traversal, replace unmarked `O` cells with `X`, restore marked cells to `O`, and join each row for the adapted return value.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), because every board cell is examined a constant number of times.\n- **Space Complexity:** O(m * n) for the mutable character grid and breadth-first-search queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\n\nclass Solution:\n def solve(self, board: List[str]) -> List[str]:\n cells = [list(row) for row in board]\n rows, cols = len(cells), len(cells[0])\n queue = deque()\n\n def mark(row: int, col: int) -> None:\n if cells[row][col] != \"O\":\n return\n cells[row][col] = \"#\"\n queue.append((row, col))\n\n for row in range(rows):\n mark(row, 0)\n mark(row, cols - 1)\n for col in range(cols):\n mark(0, col)\n mark(rows - 1, col)\n while queue:\n row, col = queue.popleft()\n for row_step, col_step in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n next_row = row + row_step\n next_col = col + col_step\n if 0 <= next_row < rows and 0 <= next_col < cols:\n mark(next_row, next_col)\n\n result = []\n for row in cells:\n result.append(\"\".join(\"O\" if cell == \"#\" else \"X\" for cell in row))\n return result\n```\n", "starter": {"go": "package main\n\nfunc Solve(board []string) []string {\n return []string{}\n}\n", "python": "from typing import List\n\nclass Solution:\n def solve(self, board: List[str]) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> solve(vector<string>& board) {\n return {};\n }\n};"}, "fn": "solve", "params": [{"name": "board", "type": "string_array", "visualizeType": "matrix"}], "outputType": "string_list", "tests": [["[\"X\"]"], ["[\"O\"]"], ["[\"XX\"]"], ["[\"OO\"]"], ["[\"XO\"]"], ["[\"OX\"]"], ["[\"XOX\"]"], ["[\"OOO\"]"], ["[\"XXX\"]"], ["[\"OXO\"]"], ["[\"X\",\"O\"]"], ["[\"O\",\"X\"]"], ["[\"O\",\"O\",\"X\"]"], ["[\"X\",\"O\",\"X\"]"], ["[\"XX\",\"XX\"]"], ["[\"OO\",\"OO\"]"], ["[\"XO\",\"OX\"]"], ["[\"OX\",\"XO\"]"], ["[\"XX\",\"XO\"]"], ["[\"XO\",\"XX\"]"], ["[\"XXX\",\"XOX\",\"XXX\"]"], ["[\"OOO\",\"OOO\",\"OOO\"]"], ["[\"XOX\",\"OOO\",\"XOX\"]"], ["[\"OXO\",\"XXX\",\"OXO\"]"], ["[\"XXX\",\"XOO\",\"XXX\"]"], ["[\"XXX\",\"OOX\",\"XXX\"]"], ["[\"OXX\",\"XOX\",\"XXO\"]"], ["[\"XXXX\",\"XOOX\",\"XXOX\",\"XOXX\"]"], ["[\"XXXX\",\"XOOX\",\"XOOX\",\"XXXX\"]"], ["[\"OOOO\",\"OXXO\",\"OXXO\",\"OOOO\"]"], ["[\"XOOX\",\"OXXO\",\"OXXO\",\"XOOX\"]"], ["[\"XXXX\",\"XOXO\",\"XOXX\",\"XXXX\"]"], ["[\"OXXX\",\"OXOX\",\"OOOX\",\"XXXX\"]"], ["[\"XXXX\",\"XOOX\",\"XOXO\",\"XXXX\"]"], ["[\"XXXXX\",\"XOOOX\",\"XOXXX\",\"XOOOX\",\"XXXXX\"]"], ["[\"OOOOO\",\"OXXXO\",\"OXOXO\",\"OXXXO\",\"OOOOO\"]"], ["[\"XXXXX\",\"XOXOX\",\"XXOXX\",\"XOXOX\",\"XXXXX\"]"], ["[\"OXXXX\",\"OOOXX\",\"XXOXX\",\"XXOOO\",\"XXXXO\"]"], ["[\"XXXXX\",\"XOOOX\",\"XXXXX\",\"XOOOX\",\"XXXXX\"]"], ["[\"OXOXO\",\"XOXOX\",\"OXOXO\",\"XOXOX\"]"], ["[\"XXXXXX\",\"XOOOOX\",\"XOXXOX\",\"XOOOOX\",\"XXXXXX\"]"], ["[\"OOOOOO\",\"OXXXXO\",\"OXOOXO\",\"OXXXXO\",\"OOOOOO\"]"], ["[\"XXXXXX\",\"XOXOOX\",\"XOXXOX\",\"XOOXOX\",\"XXXXXX\"]"], ["[\"OXXXXX\",\"OXOOOX\",\"OXOXOX\",\"OXOOOX\",\"OXXXXX\"]"], ["[\"XXXXXX\",\"XOOOOO\",\"XXXXXO\",\"XOOOOO\",\"XXXXXX\"]"], ["[\"XXXXXXX\",\"XOOOOOX\",\"XOXXXOX\",\"XOXOXOX\",\"XOXXXOX\",\"XOOOOOX\",\"XXXXXXX\"]"], ["[\"OOOOOOO\",\"OXXXXXO\",\"OXOOOXO\",\"OXOXOXO\",\"OXOOOXO\",\"OXXXXXO\",\"OOOOOOO\"]"], ["[\"XXXXXXX\",\"XOXOXOX\",\"XXOXOXX\",\"XOXOXOX\",\"XXXXXXX\"]"], ["[\"OXXXXXX\",\"OOOXXXX\",\"XXOXXXX\",\"XXOOOOX\",\"XXXXOOO\"]"], ["[\"XXXXXXXX\",\"XOOOOOOX\",\"XOXXXXOX\",\"XOXOOXOX\",\"XOXXXXOX\",\"XOOOOOOX\",\"XXXXXXXX\"]"], ["[\"OXOXOXOX\",\"XOXOXOXO\",\"OXOXOXOX\",\"XOXOXOXO\",\"OXOXOXOX\"]"], ["[\"XXXXXXXX\",\"XOOXXOOX\",\"XOXXXXOX\",\"XOOOOOOX\",\"XXXXXXXX\"]"], ["@javascript:JSON.stringify(Array.from({length:50},(_,r)=>r===0||r===49?'X'.repeat(200):'X'+'O'.repeat(198)+'X'))"]], "expected": [["X"], ["O"], ["XX"], ["OO"], ["XO"], ["OX"], ["XOX"], ["OOO"], ["XXX"], ["OXO"], ["X", "O"], ["O", "X"], ["O", "O", "X"], ["X", "O", "X"], ["XX", "XX"], ["OO", "OO"], ["XO", "OX"], ["OX", "XO"], ["XX", "XO"], ["XO", "XX"], ["XXX", "XXX", "XXX"], ["OOO", "OOO", "OOO"], ["XOX", "OOO", "XOX"], ["OXO", "XXX", "OXO"], ["XXX", "XOO", "XXX"], ["XXX", "OOX", "XXX"], ["OXX", "XXX", "XXO"], ["XXXX", "XXXX", "XXXX", "XOXX"], ["XXXX", "XXXX", "XXXX", "XXXX"], ["OOOO", "OXXO", "OXXO", "OOOO"], ["XOOX", "OXXO", "OXXO", "XOOX"], ["XXXX", "XXXO", "XXXX", "XXXX"], ["OXXX", "OXOX", "OOOX", "XXXX"], ["XXXX", "XXXX", "XXXO", "XXXX"], ["XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"], ["OOOOO", "OXXXO", "OXXXO", "OXXXO", "OOOOO"], ["XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"], ["OXXXX", "OOOXX", "XXOXX", "XXOOO", "XXXXO"], ["XXXXX", "XXXXX", "XXXXX", "XXXXX", "XXXXX"], ["OXOXO", "XXXXX", "OXXXO", "XOXOX"], ["XXXXXX", "XXXXXX", "XXXXXX", "XXXXXX", "XXXXXX"], ["OOOOOO", "OXXXXO", "OXXXXO", "OXXXXO", "OOOOOO"], ["XXXXXX", "XXXXXX", "XXXXXX", "XXXXXX", "XXXXXX"], ["OXXXXX", "OXXXXX", "OXXXXX", "OXXXXX", "OXXXXX"], ["XXXXXX", "XOOOOO", "XXXXXO", "XOOOOO", "XXXXXX"], ["XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX"], ["OOOOOOO", "OXXXXXO", "OXXXXXO", "OXXXXXO", "OXXXXXO", "OXXXXXO", "OOOOOOO"], ["XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX"], ["OXXXXXX", "OOOXXXX", "XXOXXXX", "XXOOOOX", "XXXXOOO"], ["XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX"], ["OXOXOXOX", "XXXXXXXO", "OXXXXXXX", "XXXXXXXO", "OXOXOXOX"], ["XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXX"], ["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "777", "slug": "swap-adjacent-in-lr-string", "id": 777, "title": "Swap Adjacent in LR String", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/swap-adjacent-in-lr-string/", "examples": [{"input": "start = \"RXXLRXRXL\", end = \"XRLXXRRLX\"", "output": "true", "explanation": "A sequence of allowed slides reshapes the first row into the second one."}, {"input": "start = \"X\", end = \"L\"", "output": "false", "explanation": "An empty slot cannot become a token."}, {"input": "start = \"XL\", end = \"LX\"", "output": "true", "explanation": "The L steps one slot left into the empty cell."}], "hints": ["Ignore the empty slots first: after deleting every X, the remaining L/R order must match exactly.", "Track positions of the remaining tokens: each L in the start must not sit to the right of its counterpart in the target, and each R must not sit to the left.", "Scan both strings with two pointers that skip over X characters and compare token by token."], "statement": "In a row of slots, each slot holds one of three symbols: `L`, `R`, or `X`.\nAn `X` means the slot is empty. The other two symbols behave like tokens\nthat slide into neighboring empty slots, but only in one direction each.\n\nIn a single step you may pick one of these patterns and flip it:\n\n- `XL` may become `LX` (the `L` token steps one slot to the left).\n- `RX` may become `XR` (the `R` token steps one slot to the right).\n\nNo other change is allowed. In particular an `L` never steps right, an `R`\nnever steps left, and two non-empty tokens never jump over each other.\n\nYou are given two strings `start` and `end` of equal length that describe\nthe starting row and a desired target row. Decide whether `start` can be\nturned into `end` by applying any number of the steps above.\n\n**Constraints:**\n- `1 <= start.length <= 10^4`\n- `start.length == end.length`\n- `start` and `end` contain only characters `L`, `R`, and `X`.\n", "solution": "## Approach\n\nDrop every `X` from both rows and require the remaining token sequences to\nagree. Tokens keep their relative order because an `L` only drifts left\nthrough empty cells and an `R` only drifts right, so they can never overtake\neach other. While scanning past the empty cells, also enforce the direction\nrule: an `L` in the start must begin at or to the right of its target slot,\nand an `R` must begin at or to the left of its target slot.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the row length. Each pointer advances once.\n- **Space Complexity:** O(1) besides the inputs.\n\n## Implementation\n\n```python\nclass Solution:\n def canTransform(self, start: str, end: str) -> bool:\n n = len(start)\n if len(end) != n:\n return False\n i = j = 0\n while i < n and j < n:\n while i < n and start[i] == 'X':\n i += 1\n while j < n and end[j] == 'X':\n j += 1\n if i == n and j == n:\n return True\n if i == n or j == n:\n return False\n if start[i] != end[j]:\n return False\n if start[i] == 'L' and i < j:\n return False\n if start[i] == 'R' and i > j:\n return False\n i += 1\n j += 1\n while i < n:\n if start[i] != 'X':\n return False\n i += 1\n while j < n:\n if end[j] != 'X':\n return False\n j += 1\n return True\n```\n", "starter": {"go": "package main\n\nfunc CanTransform(start string, end string) bool {\n return false\n}", "python": "class Solution:\n def canTransform(self, start: str, end: str) -> bool:\n return False\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n bool canTransform(string start, string end) {\n return false;\n }\n};"}, "fn": "canTransform", "params": [{"name": "start", "type": "string"}, {"name": "end", "type": "string"}], "outputType": "boolean", "tests": [["RXXLRXRXL", "XRLXXRRLX"], ["X", "L"], ["XL", "LX"], ["RX", "XR"], ["LX", "XL"], ["XR", "RX"], ["RXX", "XXR"], ["XXL", "LXX"], ["XXR", "RXX"], ["LXX", "XXL"], ["XXX", "XXX"], ["RRR", "RRR"], ["LLL", "LLL"], ["RLX", "RLX"], ["RXXL", "XRXL"], ["RXXL", "XRLX"], ["RLX", "XRL"], ["XRL", "RLX"], ["RXLX", "XRXL"], ["XLXR", "LXXR"], ["RXLXRX", "XRLXXR"], ["LLRXXR", "LLXRXR"], ["RXL", "LRX"], ["XXRXXLXX", "XXRXXLXX"], ["RXLXLX", "LRXXXL"], ["XLXXRXXL", "LXXXRXLX"], ["RXRXRXLXLX", "XXRRRXLXLX"], ["XXXXXXXXXX", "XXXXXXXXXX"]], "expected": [true, false, true, true, false, false, true, true, false, false, true, true, true, true, true, true, false, false, false, true, true, true, false, true, false, true, true, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "256", "slug": "swap-nodes-in-pairs", "id": 256, "title": "Swap Nodes in Pairs", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/swap-nodes-in-pairs/", "examples": [{"input": "head = [1,2,3,4]", "output": "[2,1,4,3]", "explanation": "Nodes 1 and 2 trade places, and nodes 3 and 4 trade places."}, {"input": "head = []", "output": "[]", "explanation": "An empty list has nothing to swap."}, {"input": "head = [1]", "output": "[1]", "explanation": "A single node has no partner, so the list is unchanged."}], "hints": ["Place a dummy node before the head so the first pair is handled exactly like every other pair.", "For each pair (a, b), point the previous node to b, b back to a, and a forward to the rest; then advance two steps."], "statement": "You are given the head of a singly linked list. Exchange every pair of neighboring nodes (positions 1-2, 3-4, and so on) and return the head of the rearranged list.\n\nWhen the list holds an odd number of nodes, the final node has no partner and stays where it is. You must relink the existing nodes themselves; just overwriting their values is not allowed.\n\n**Constraints:**\n- The number of nodes in the list is in the range `[0, 100]`.\n- `0 <= Node.val <= 100`\n", "solution": "## Approach\n\nAnchor a dummy node ahead of the head so every pair, including the first, has a predecessor to rewire. Repeatedly take the next two nodes `a` and `b`, splice them in as `prev -> b -> a`, reconnect `a` to the remainder, and step `prev` forward past the swapped pair. A leftover single node is simply never touched.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one pass over the list.\n- **Space Complexity:** O(1) extra space besides a few pointers.\n\n## Implementation\n\n```python\nclass Solution:\n def swapPairs(self, head):\n dummy = ListNode(0, head)\n prev = dummy\n while prev.next and prev.next.next:\n a = prev.next\n b = a.next\n a.next = b.next\n b.next = a\n prev.next = b\n prev = a\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 SwapPairs(head *ListNode) *ListNode {\n \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 swapPairs(self, head):\n pass\n", "cpp": "/*\nDefinition for singly-linked list.\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* swapPairs(ListNode* head) {\n return nullptr;\n }\n};"}, "fn": "swapPairs", "params": [{"name": "head", "type": "list_node"}], "outputType": "list_node", "tests": [["[1,2,3,4]"], ["[]"], ["[1]"], ["[1,2]"], ["[1,2,3]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[1,1,1,1]"], ["[0]"], ["[100]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[10,9,8,7,6,5,4,3,2,1]"], ["[2,2,1]"], ["[0,0,0,0,0]"], ["[7]"], ["[3,1]"], ["[99,100]"], ["[1,2,3,4,5,6]"], ["[6,5,4,3,2,1]"], ["[50,50,50]"], ["[1,3,5,7,9,11]"], ["[2,4,6,8]"], ["[100,0,100,0]"], ["[42]"], ["[1,2,3,4,5,6,7]"]], "expected": [[2, 1, 4, 3], null, [1], [2, 1], [2, 1, 3], [2, 1, 4, 3, 5], [4, 5, 2, 3, 1], [1, 1, 1, 1], [0], [100], [2, 1, 4, 3, 6, 5, 8, 7, 10, 9], [9, 10, 7, 8, 5, 6, 3, 4, 1, 2], [2, 2, 1], [0, 0, 0, 0, 0], [7], [1, 3], [100, 99], [2, 1, 4, 3, 6, 5], [5, 6, 3, 4, 1, 2], [50, 50, 50], [3, 1, 7, 5, 11, 9], [4, 2, 8, 6], [0, 100, 0, 100], [42], [2, 1, 4, 3, 6, 5, 7]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "125", "slug": "swim-in-rising-water", "id": 125, "title": "Swim in Rising Water", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/swim-in-rising-water/", "examples": [{"input": "grid = [[0,2],[1,3]]", "output": "3", "explanation": "Both routes from (0,0) to (1,1) have a maximum elevation of 3, making 3 the minimum time needed."}, {"input": "grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]", "output": "16", "explanation": "Every path from (0,0) to (4,4) must cross a cell with elevation at least 16, and there exists a path whose highest elevation is 16."}], "hints": ["A path's required time is the maximum elevation on that path; minimize that maximum.", "Use Dijkstra's algorithm where entering a neighbor changes the path cost to max(currentCost, neighborElevation).", "An alternative is binary search on time and a flood-fill reachability check."], "statement": "You are given an `n x n` grid where `grid[row][col]` is the elevation of a\ncell. At time `t`, you may enter cells whose elevation is at most `t`. From a\ncell, you may move up, down, left, or right.\n\nReturn the minimum time at which it is possible to travel from the top-left\ncell to the bottom-right cell.\n\n**Constraints:**\n\n- `1 <= n <= 50`\n- `grid.length == n`\n- `grid[i].length == n`\n- The grid contains every elevation from `0` through `n^2 - 1` exactly once.\n", "solution": "## Approach\n\nA path's required time is the maximum elevation visited along it. Run Dijkstra's algorithm where a state's cost is that maximum, and entering a neighbor changes the cost to `max(current_time, neighbor_elevation)`. The first time the bottom-right cell leaves the min-heap, its cost is the smallest possible path maximum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(N^2 log(N^2)) for an `N x N` grid.\n- **Space Complexity:** O(N^2) for best costs and the heap.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\n\n\nclass Solution:\n def swimInWater(self, grid: List[List[int]]) -> int:\n n = len(grid)\n best = [[float(\"inf\")] * n for _ in range(n)]\n best[0][0] = grid[0][0]\n queue = [(grid[0][0], 0, 0)]\n\n while queue:\n time, row, col = heapq.heappop(queue)\n if time != best[row][col]:\n continue\n if row == n - 1 and col == n - 1:\n return time\n\n for row_step, col_step in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n next_row = row + row_step\n next_col = col + col_step\n if 0 <= next_row < n and 0 <= next_col < n:\n next_time = max(time, grid[next_row][next_col])\n if next_time < best[next_row][next_col]:\n best[next_row][next_col] = next_time\n heapq.heappush(queue, (next_time, next_row, next_col))\n\n return -1\n```\n", "starter": {"go": "package main\n\nfunc SwimInWater(grid [][]int) int {\n return 0\n}\n", "python": "from typing import List\n\nclass Solution:\n def swimInWater(self, grid: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int swimInWater(vector<vector<int>>& grid) {\n return 0;\n }\n};"}, "fn": "swimInWater", "params": [{"name": "grid", "type": "int_array_2d", "visualizeType": "matrix"}], "outputType": "int", "tests": [["[[0]]"], ["[[0,1],[2,3]]"], ["[[0,1],[3,2]]"], ["[[0,2],[1,3]]"], ["[[0,2],[3,1]]"], ["[[0,3],[1,2]]"], ["[[0,3],[2,1]]"], ["[[1,0],[2,3]]"], ["[[1,0],[3,2]]"], ["[[1,2],[0,3]]"], ["[[1,2],[3,0]]"], ["[[1,3],[0,2]]"], ["[[1,3],[2,0]]"], ["[[2,0],[1,3]]"], ["[[2,0],[3,1]]"], ["[[2,1],[0,3]]"], ["[[2,1],[3,0]]"], ["[[2,3],[0,1]]"], ["[[2,3],[1,0]]"], ["[[3,0],[1,2]]"], ["[[3,0],[2,1]]"], ["[[3,1],[0,2]]"], ["[[3,1],[2,0]]"], ["[[3,2],[0,1]]"], ["[[3,2],[1,0]]"], ["[[0,1,2],[3,4,5],[6,7,8]]"], ["[[8,7,6],[5,4,3],[2,1,0]]"], ["[[0,3,6],[1,4,7],[2,5,8]]"], ["[[2,1,0],[5,4,3],[8,7,6]]"], ["[[0,1,2],[7,8,3],[6,5,4]]"], ["[[8,7,6],[1,0,5],[2,3,4]]"], ["[[0,2,4],[6,8,1],[3,5,7]]"], ["[[8,6,4],[2,0,7],[5,3,1]]"], ["[[1,2,3],[4,5,6],[7,8,0]]"], ["[[2,3,4],[5,6,7],[8,0,1]]"], ["[[3,4,5],[6,7,8],[0,1,2]]"], ["[[4,5,6],[7,8,0],[1,2,3]]"], ["[[5,6,7],[8,0,1],[2,3,4]]"], ["[[6,7,8],[0,1,2],[3,4,5]]"], ["[[7,8,0],[1,2,3],[4,5,6]]"], ["[[8,0,1],[2,3,4],[5,6,7]]"], ["[[0,8,1],[7,2,6],[3,5,4]]"], ["[[4,3,5],[2,0,6],[1,8,7]]"], ["[[8,1,6],[3,5,7],[4,0,2]]"], ["[[2,7,1],[6,0,5],[3,8,4]]"], ["[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]"], ["[[15,14,13,12],[11,10,9,8],[7,6,5,4],[3,2,1,0]]"], ["[[0,4,8,12],[1,5,9,13],[2,6,10,14],[3,7,11,15]]"], ["[[3,2,1,0],[7,6,5,4],[11,10,9,8],[15,14,13,12]]"], ["[[0,1,2,3],[7,6,5,4],[8,9,10,11],[15,14,13,12]]"], ["[[0,1,2,3],[11,12,13,4],[10,15,14,5],[9,8,7,6]]"], ["[[5,6,7,8],[9,10,11,12],[13,14,15,0],[1,2,3,4]]"], ["[[0,2,4,6],[8,10,12,14],[1,3,5,7],[9,11,13,15]]"], ["@javascript:JSON.stringify(Array.from({length:50},(_,row)=>Array.from({length:50},(_,col)=>row*50+col)))"]], "expected": [0, 3, 2, 3, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 2, 3, 2, 2, 2, 3, 3, 3, 3, 3, 3, 8, 8, 8, 6, 4, 8, 7, 8, 6, 6, 6, 6, 6, 6, 7, 8, 7, 7, 8, 6, 15, 15, 15, 12, 12, 6, 12, 15, 2499], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "283", "slug": "symmetric-tree", "id": 283, "title": "Symmetric Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/symmetric-tree/", "examples": [{"input": "root = [1,2,2,3,4,4,3]", "output": "true", "explanation": "Left and right subtrees mirror each other at every level."}, {"input": "root = [1,2,2,null,3,null,3]", "output": "false", "explanation": "The right side has a 3 where the mirrored left side is empty, so the tree is not mirrored."}, {"input": "root = [1]", "output": "true", "explanation": "A single node is trivially symmetric."}], "hints": ["Compare the left and right subtrees as mirror images: left.left pairs with right.right and left.right pairs with right.left.", "A recursive helper on node pairs handles empty cases: two empties match, one empty does not.", "An iterative queue holding paired nodes works too and uses O(n) time."], "statement": "Decide whether a binary tree reads the same on both sides \u2014 that is, whether it is a mirror image of itself around its center.\n\nTwo trees are mirrors when their roots hold equal values and each left branch of one matches the corresponding right branch of the other, recursively. Check the root's left subtree against its right subtree in this mirrored fashion.\n\nReturn `true` when the whole structure is mirrored, otherwise `false`.\n\n**Constraints:**\n- `0 <= number of nodes <= 1000`\n- `-100 <= Node.val <= 100`\n", "solution": "## Approach\n\nMirror-check the two halves of the tree. A helper receives a pair of nodes that should be reflections of each other: both empty means success, exactly one empty means failure, and otherwise their values must match with cross-paired children (left-left against right-right and left-right against right-left). Starting the helper on the root's children determines symmetry.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), every node is visited once.\n- **Space Complexity:** O(h) recursion depth, O(n) in the worst skewed case.\n\n## Implementation\n\n```python\nclass Solution:\n def isSymmetric(self, root) -> bool:\n def mirror(a, b):\n if not a and not b:\n return True\n if not a or not b:\n return False\n return a.val == b.val and mirror(a.left, b.right) and mirror(a.right, b.left)\n if not root:\n return True\n return mirror(root.left, root.right)\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc IsSymmetric(root *TreeNode) bool {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def isSymmetric(self, root) -> bool:\n pass\n", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n bool isSymmetric(TreeNode* root) {\n \n }\n};"}, "fn": "isSymmetric", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "boolean", "tests": [["[1,2,2,3,4,4,3]"], ["[1,2,2,null,3,null,3]"], ["[1]"], ["[]"], ["[1,2,2,3,null,null,3]"], ["[1,2,2,null,3,3,null]"], ["[1,2,3]"], ["[1,0]"], ["[1,2,2,3,4,4,3,5,6,7,8,8,7,6,5]"], ["[1,2,2,3,4,4,3,5,null,null,null,null,null,null,5]"], ["[2,3,3,4,5,5,4,null,null,8,9,9,8]"], ["[2,3,3,4,5,null,4]"], ["[1,2,2,3,4,4,3,null,null,null,null,null,null,null,null]"], ["[5,4,1,null,1,null,4,2,null,2]"], ["[1,2,2,null,null,2,2]"], ["[1,null,2]"], ["[1,2,null]"], ["[3,3,3]"], ["[0]"], ["[-100,100,100]"], ["[1,2,2,3,4,4,3,6,7,7,6,6,7,7,6]"], ["[1,2,2,3,4,4,3,6,null,7,null,null,7,null,6]"], ["[1,2,3,4,5,6,7]"], ["[7,7,7,7,7,7,7]"], ["[1,2,2,null,3,null,3,null,null,null,3]"], ["[9,25,25,null,-95,-95]"]], "expected": [true, false, true, true, true, true, false, false, true, true, true, false, true, false, false, false, false, true, true, true, true, true, false, true, false, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "633", "slug": "tag-validator", "id": 633, "title": "Tag Validator", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/tag-validator/", "examples": [{"input": "code = \"<DIV>This is the first line <![CDATA[<div>]]></DIV>\"", "output": "true", "explanation": "One outer block wraps text plus a CDATA chunk."}, {"input": "code = \"<DIV>>> ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>\"", "output": "true", "explanation": "Nested-looking symbols inside CDATA do not break parsing."}, {"input": "code = \"<A> <B> </A> </B>\"", "output": "false", "explanation": "Closing order does not match opening order."}], "hints": ["The whole string must be exactly one outer tag pair with nothing outside it.", "Track open tags on a stack; CDATA sections only count when the stack is non-empty.", "Tag names use 1-9 uppercase letters; CDATA opens with <![CDATA[ and closes with ]]> ."], "statement": "A snippet is valid when it consists of exactly one outer element with matched tags, optional text, and optional CDATA blocks. Tag names hold 1 to 9 uppercase letters. An opening tag looks like `<NAME>`, its closer like `</NAME>`, and a CDATA block looks like `<![CDATA[anything]]>` where the inside is taken literally.\n\nRules in plain terms: the snippet must start with an opening tag and end with its matching closer, with nothing before or after. Inside, plain text may appear only within some open tag, `<` must begin a valid tag or a well-formed CDATA, nested tags must close in reverse order, and every CDATA must terminate.\n\n**Constraints:**\n- `1 <= code.length <= 500`\n- Code uses printable ASCII plus `<`, `>`, `/`, `!`, `[`, `]`.\n", "solution": "## Approach\n\nScan left to right with a stack of open tag names. CDATA jumps to its terminator, closers must match the stack top, openers push, and plain text is legal only inside some tag. When the stack empties the scan must be exactly at the end, which enforces a single outer element.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) worst case with naive search, O(n) with an index scan.\n- **Space Complexity:** O(n) for the stack.\n\n## Implementation\n\n```python\nclass Solution:\n def isValid(self, code: str) -> bool:\n n = len(code)\n st = []\n i = 0\n def good(t):\n return 1 <= len(t) <= 9 and all('A' <= c <= 'Z' for c in t)\n while i < n:\n if code.startswith('<![CDATA[', i):\n j = code.find(']]>', i + 9)\n if j < 0 or not st:\n return False\n i = j + 3\n elif code.startswith('</', i):\n j = code.find('>', i)\n if j < 0:\n return False\n tag = code[i+2:j]\n if not good(tag) or not st or st.pop() != tag:\n return False\n i = j + 1\n if not st and i != n:\n return False\n elif code[i] == '<':\n j = code.find('>', i)\n if j < 0:\n return False\n tag = code[i+1:j]\n if not good(tag):\n return False\n st.append(tag)\n i = j + 1\n else:\n if not st:\n return False\n i += 1\n return not st\n```\n", "starter": {"go": "package main\n\nfunc IsValid(code string) bool {\n return false\n}", "python": "class Solution:\n def isValid(self, code: str) -> bool:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n bool isValid(string code) {\n return false;\n }\n};"}, "fn": "isValid", "params": [{"name": "code", "type": "string"}], "outputType": "boolean", "tests": [["<DIV>This is the first line <![CDATA[<div>]]></DIV>"], ["<DIV>>> ![cdata[]] <![CDATA[<div>]>]]>]]>>]</DIV>"], ["<A> <B> </A> </B>"], ["<B><![CDATA[test]]></B>"], ["<A></A>"], ["<A>hello</A>"], ["<A><B></B></A>"], ["<A><B><C></C></B></A>"], ["<A><![CDATA[<>]]> </A>"], ["plain"], ["<A>"], ["</A>"], ["<A></B>"], ["<A></A><B></B>"], ["text<A></A>"], ["<A></A>text"], ["<a></a>"], ["<ABCDEFGHIJ></ABCDEFGHIJ>"], ["<A><![CDATA[x]]"], ["<A><![CDATA[x]]></A>"], ["<A><![CDATA[reserve]]></A>"], ["<A> <B>hi<![CDATA[<br>]]></B> </A>"], ["<X><Y></Y><Z></Z></X>"], ["<T><![CDATA[depth <><> ]]></T>"], ["<>"], ["<A>unclosed<B></A>"], ["<LONGTAGNAME></LONGTAGNAME>"], ["<A></A >"]], "expected": [true, true, false, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, true, true, true, true, true, false, false, false, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "942", "slug": "tallest-billboard", "id": 942, "title": "Tallest Billboard", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/tallest-billboard/", "examples": [{"input": "rods = [1,2,3,6]", "output": "6", "explanation": "Splitting into [1,2,3] and [6] gives two supports of height 6, which is the best achievable balance."}, {"input": "rods = [1,2,3,4,5,6]", "output": "10", "explanation": "Grouping [2,3,5] against [4,6] (or [1,4,5] against [2,3,... ]) reaches height 10; nothing taller balances."}, {"input": "rods = [1,2]", "output": "0", "explanation": "No two disjoint non-empty groups share a total, so the answer is 0."}], "hints": ["Track the height difference between the two supports instead of both heights.", "Let dp[d] be the tallest higher-support height reachable with difference d, and update it rod by rod.", "Adding a rod to the shorter support only raises the taller height when the rod overtakes the gap."], "statement": "You are given rods of various integer lengths and want to mount a billboard on two supports of exactly equal height. Each rod can be assigned to the left support, to the right support, or left unused, and the height of a support is the total length of the rods assigned to it.\n\nChoose the assignments so that both supports end up with the same height, and make that shared height as large as possible. Return the tallest balanced height you can build, or 0 when no balanced pair of supports exists.\n\n**Constraints:**\n- `1 <= rods.length <= 20`\n- `1 <= rods[i] <= 20`\n", "solution": "## Approach\n\nTrack the difference between the two supports. Let `dp[d]` be the tallest height of the higher support reachable with the two supports differing by `d`. Each new rod either joins the taller side (difference grows, height grows), joins the shorter side (difference shrinks or flips, height grows only if the rod overtakes), or is skipped. Copying the table per rod keeps every rod used at most once, and `dp[0]` at the end is the best balanced height.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * S), where n is the rod count and S the total length.\n- **Space Complexity:** O(S) for the difference table.\n\n## Implementation\n\n```python\nclass Solution:\n def tallestBillboard(self, rods: list[int]) -> int:\n s = sum(rods)\n NEG = -10 ** 9\n dp = [NEG] * (s + 1)\n dp[0] = 0\n for x in rods:\n nxt = list(dp)\n for d in range(s + 1):\n if dp[d] < 0:\n continue\n if d + x <= s:\n nxt[d + x] = max(nxt[d + x], dp[d] + x)\n nd = abs(d - x)\n nxt[nd] = max(nxt[nd], dp[d] + max(0, x - d))\n dp = nxt\n return dp[0]\n```\n", "starter": {"go": "package main\n\nfunc TallestBillboard(rods []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def tallestBillboard(self, rods: List[int]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int tallestBillboard(vector<int>& rods) {\n return 0;\n }\n};"}, "fn": "tallestBillboard", "params": [{"name": "rods", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,3,6]"], ["[1,2,3,4,5,6]"], ["[1,2]"], ["[1,2,4,8,16]"], ["[3,3,3,3]"], ["[5,5,5,5,5]"], ["[2,4,5,9]"], ["[10,10]"], ["[7]"], ["[1,1,1,1,1,1]"], ["[20,20,20,20]"], ["[1,2,3,4,5]"], ["[8,3,5,2,7]"], ["[4,4,6,6,8]"], ["[11,12,13,14]"], ["[1,3,5,7,9]"], ["[2,2,3,5]"], ["[6,7,8,9,10]"], ["[1,4,6,8,10]"], ["[15,15,10,10,5,5]"], ["[9,9,9]"], ["[1,2,3,7]"], ["[5,3,2,8,8]"], ["[12,5,7,6,10]"], ["[1,1,2,3,5,8]"], ["[19,20,1,2,3]"], ["[4,8,15,16,19,20]"], ["[10,5,5,10]"]], "expected": [6, 10, 0, 0, 6, 10, 9, 10, 0, 3, 40, 7, 10, 14, 25, 12, 5, 17, 14, 30, 9, 3, 13, 17, 10, 22, 39, 15], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "131", "slug": "target-sum", "id": 131, "title": "Target Sum", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/target-sum/", "examples": [{"input": "nums = [1,1,1,1,1], target = 3", "output": "5", "explanation": "Exactly five sign assignments evaluate to 3."}, {"input": "nums = [1], target = 1", "output": "1", "explanation": "There is 1 way to assign +/- to [1] such that the sum equals 1."}], "hints": ["After each number, track how many assignments reach every sum from -sum(nums) to sum(nums).", "A zero still has two sign choices, so both transitions must be counted."], "statement": "Take an integer list `nums` and an integer `target`. Imagine tagging every entry of\n`nums` with either `+` or `-`, leaving the entries in their original sequence,\nwhich yields a signed expression.\n\nCount how many distinct taggings make that expression come out to `target`.\nThe result is known to fit inside a signed 32-bit integer.\n\n**Constraints:**\n- `1 <= nums.length <= 20`\n- `0 <= nums[i] <= 1000`\n- `0 <= sum(nums) <= 1000`\n- `-1000 <= target <= 1000`\n", "solution": "## Approach\n\nSplit the numbers into a positive subset with sum `P` and a negative subset with sum\n`N`. Since `P + N` is the array sum and `P - N` is the target, `P` must equal\n`(sum(nums) + target) / 2`. Count subsets with that sum using backward one-dimensional\ndynamic programming. Zero values naturally double every existing count.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * S), where `S` is `sum(nums)`.\n- **Space Complexity:** O(S).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def findTargetSumWays(self, nums: List[int], target: int) -> int:\n total = sum(nums)\n if target < -total or target > total or (total + target) % 2:\n return 0\n\n subset = (total + target) // 2\n ways = [0] * (subset + 1)\n ways[0] = 1\n for num in nums:\n for value in range(subset, num - 1, -1):\n ways[value] += ways[value - num]\n return ways[subset]\n```\n", "starter": {"go": "package main\n\nfunc FindTargetSumWays(nums []int, target int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def findTargetSumWays(self, nums: List[int], target: int) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int findTargetSumWays(vector<int>& nums, int target) {\n return 0;\n }\n};"}, "fn": "findTargetSumWays", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[1,1,1,1,1]", "3"], ["[1]", "1"], ["[1]", "-1"], ["[1]", "0"], ["[1]", "2"], ["[0]", "0"], ["[0,0]", "0"], ["[0,0,1]", "1"], ["[0,0,1]", "-1"], ["[0,0,1]", "0"], ["[1,2]", "3"], ["[1,2]", "1"], ["[1,2]", "-1"], ["[1,2]", "0"], ["[1,2,3]", "0"], ["[1,2,3]", "2"], ["[1,2,3]", "7"], ["[2,2,2]", "2"], ["[2,2,2]", "0"], ["[5,5,5,5]", "0"], ["[5,5,5,5]", "10"], ["[1,1,1,1,1]", "-3"], ["[1,1,1,1,1]", "5"], ["[1,1,1,1,1]", "4"], ["[2,3,5,7]", "3"], ["[2,3,5,7]", "-3"], ["[2,3,5,7]", "17"], ["[2,3,5,7]", "16"], ["[10,20,30]", "0"], ["[10,20,30]", "20"], ["[10,20,30]", "60"], ["[1000]", "1000"], ["[1000]", "-1000"], ["[1000]", "999"], ["[100,200,300,400]", "0"], ["[100,200,300,400]", "200"], ["[100,200,300,400]", "-200"], ["[0,0,0,0,0,0,0,0,0,0]", "0"], ["[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", "0"], ["[0,0,0,0,0,1,2,3]", "0"], ["[0,0,0,0,0,1,2,3]", "2"], ["[1,2,1]", "0"], ["[1,2,1]", "2"], ["[1,2,1]", "-2"], ["[7,1,3,9]", "4"], ["[7,1,3,9]", "-4"], ["[7,1,3,9]", "20"], ["[50,50,50,50,50,50]", "0"], ["[50,50,50,50,50,50]", "100"], ["[1,2,4,8,16,32]", "63"], ["[1,2,4,8,16,32]", "1"], ["[1,2,4,8,16,32]", "0"], ["[3,3,3,3,3,3,3,3]", "0"], ["[3,3,3,3,3,3,3,3]", "6"], ["[9,8,7,6,5,4,3,2,1]", "5"], ["[9,8,7,6,5,4,3,2,1]", "-5"], ["@javascript:JSON.stringify([1000,...Array(19).fill(0)])", "1000"]], "expected": [5, 1, 1, 0, 0, 2, 4, 4, 4, 0, 1, 1, 1, 0, 2, 1, 0, 3, 0, 6, 4, 5, 1, 0, 2, 2, 1, 0, 2, 1, 1, 1, 1, 0, 2, 2, 2, 1024, 1048576, 64, 32, 2, 2, 2, 1, 1, 1, 20, 15, 1, 1, 0, 70, 56, 22, 22, 524288], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "105", "slug": "task-scheduler", "id": 105, "title": "Task Scheduler", "difficulty": "Medium", "category": "heap", "link": "https://leetcode.com/problems/task-scheduler/", "examples": [{"input": "tasks = \"AAABBB\", n = 2", "output": "8", "explanation": "A, B, idle, A, B, idle, A, B is optimal."}, {"input": "tasks = \"AAABBB\", n = 0", "output": "6", "explanation": "No idle time is required when the cooldown is zero."}], "hints": ["Count the frequency of each of the 26 task types.", "Arrange the most frequent task into blocks separated by n slots.", "If the maximum frequency is `f` and `m` task types have that frequency, compare `tasks.length` with `(f - 1) * (n + 1) + m`."], "statement": "You are given a string `tasks` whose uppercase letters represent CPU tasks and a nonnegative integer `n`. Each task takes one unit of time. Tasks may be executed in any order, but two executions of the same letter must be separated by at least `n` time units during which the CPU executes other tasks or is idle.\n\nReturn the minimum number of time units needed to execute every task.\n\nThis portable API adapts the original character-array input to a string. Each character of `tasks` is one task.\n\n**Constraints:**\n\n- `1 <= tasks.length <= 10^4`\n- Every character in `tasks` is an uppercase English letter from `A` through `Z`.\n- `0 <= n <= 100`\n", "solution": "## Approach\n\nCount the 26 task frequencies and let `maximum` be the largest frequency and `maximum_count` the number of task types with that frequency. Those tasks define a minimum block schedule of `(maximum - 1) * (n + 1) + maximum_count`; the answer is the larger of that value and the number of tasks.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(t), where `t` is `tasks.length`.\n- **Space Complexity:** O(1), because the frequency array always has 26 entries.\n\n## Implementation\n\n```python\nclass Solution:\n def leastInterval(self, tasks: str, n: int) -> int:\n frequencies = [0] * 26\n for task in tasks:\n frequencies[ord(task) - ord(\"A\")] += 1\n maximum = max(frequencies)\n maximum_count = sum(frequency == maximum for frequency in frequencies)\n return max(len(tasks), (maximum - 1) * (n + 1) + maximum_count)\n```\n", "starter": {"go": "package main\n\nfunc LeastInterval(tasks string, n int) int {\n panic(\"TODO\")\n}", "python": "class Solution:\n def leastInterval(self, tasks: str, n: int) -> int:\n raise NotImplementedError\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int leastInterval(string tasks, int n) {\n return 0;\n }\n};"}, "fn": "leastInterval", "params": [{"name": "tasks", "type": "string"}, {"name": "n", "type": "int"}], "outputType": "int", "tests": [["AAABBB", "2"], ["AAABBB", "0"], ["AAAAAABCDEFG", "2"], ["A", "10"], ["ABCDE", "4"], ["AAAA", "3"], ["AAB", "2"], ["AABB", "2"], ["AAABBC", "2"], ["AAABC", "1"], ["ABCABC", "2"], ["ABCABC", "3"], ["AAAAABBBBB", "4"], ["AAAAABBBBBCCCCC", "2"], ["ZZZZ", "1"], ["AZAZAZ", "2"], ["ABCDEFGHIJKLMNOP", "100"], ["AABCDEF", "5"], ["AAAABCDEFGH", "3"], ["BBBBCCCCDD", "2"], ["AAABBBCCC", "2"], ["AAABBBCCC", "4"], ["ABACADA", "2"], ["ABCDEFGA", "6"], ["AAAAAAAAAA", "0"], ["AAAAAAAAAA", "100"], ["AABBCCDDEEFF", "1"], ["AABBCCDDEEFF", "5"], ["AAABBBC", "3"], ["AAAABCD", "2"], ["QQQWWWEEERRR", "3"], ["MNMNMNMN", "1"], ["MNMNMNMN", "3"], ["ABCDEABCDE", "4"], ["ABCDEABCDE", "6"], ["AAAZZZYYY", "2"], ["AAAAZZZYY", "2"], ["AABBC", "10"], ["ABCDABCDABCD", "3"], ["ABCDABCDABCD", "0"], ["XXXYZZ", "2"], ["PPPPQQR", "3"], ["AABBCCD", "2"], ["ABCDEFGHHA", "7"], ["CCCCBBBBAA", "1"], ["CCCCBBBBAA", "4"], ["ABCXYZABCXYZ", "5"], ["AAABBBBCCCCC", "2"], ["VVVVVWWWWWX", "5"], ["ABCDEFGHIJKLMNOPQRSTUVWXYZ", "25"], ["A", "0"], ["Z", "100"], ["@javascript:'A'.repeat(5000)+'Z'.repeat(5000)", "100"]], "expected": [8, 6, 16, 1, 5, 13, 4, 5, 7, 5, 6, 7, 22, 15, 7, 8, 16, 7, 13, 11, 9, 13, 10, 8, 10, 910, 12, 12, 10, 10, 12, 8, 14, 10, 12, 9, 10, 13, 12, 12, 7, 13, 7, 10, 10, 17, 12, 13, 26, 26, 1, 1, 504901], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "558", "slug": "teemo-attacking", "id": 558, "title": "Teemo Attacking", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/teemo-attacking/", "examples": [{"input": "timeSeries = [1,4], duration = 2", "output": "4", "explanation": "Spans [1,2] and [4,5] are disjoint, giving 2 + 2 seconds."}, {"input": "timeSeries = [1,2], duration = 2", "output": "3", "explanation": "Spans [1,2] and [2,3] overlap at second 2, giving 3 distinct seconds."}], "hints": ["Only neighboring attacks can overlap because the list is sorted.", "Each gap contributes min(duration, next - current); the final attack always adds a full duration.", "A duration of zero means no poisoned seconds at all."], "statement": "A hero poisons an enemy on each attack. An attack launched at second `t` keeps the enemy poisoned over the inclusive span from `t` through `t + duration - 1`. If a fresh attack lands while poison is still active, the clock restarts and the effect now lasts `duration` seconds beyond the new attack.\n\nYou are handed the non-decreasing attack moments in `timeSeries` and the fixed `duration`. Compute the total number of integer seconds during which the enemy suffers poison, merging all overlapping spans.\n\n**Constraints:**\n- `1 <= timeSeries.length <= 10^4`\n- `0 <= timeSeries[i], duration <= 10^7`\n- Attack times appear in non-decreasing order\n", "solution": "## Approach\n\nBecause attacks are ordered, poison intervals can only overlap with their immediate neighbor. Walking once through the list adds the overlap-capped gap `min(duration, next - current)` for every adjacent pair, plus a full `duration` for the last attack. A zero duration short-circuits to zero.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for a single pass over the attacks.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:\n if not timeSeries or duration <= 0:\n return 0\n total = 0\n for i in range(len(timeSeries) - 1):\n total += min(duration, timeSeries[i + 1] - timeSeries[i])\n return total + duration\n```\n", "starter": {"go": "package main\n\nfunc FindPoisonedDuration(timeSeries []int, duration int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n return 0;\n }\n};"}, "fn": "findPoisonedDuration", "params": [{"name": "timeSeries", "type": "int_array"}, {"name": "duration", "type": "int"}], "outputType": "int", "tests": [["[1,4]", "2"], ["[1,2]", "2"], ["[1]", "5"], ["[1]", "0"], ["[0]", "1"], ["[1,2,3,4,5]", "1"], ["[1,2,3,4,5]", "5"], ["[1,1,1]", "2"], ["[1,3,5,7]", "2"], ["[1,3,5,7]", "3"], ["[0,10000000]", "10000000"], ["[1,2]", "0"], ["[5,5,5,5]", "1"], ["[1,5,9]", "4"], ["[1,5,9]", "5"], ["[0,1,2,3]", "10"], ["[10,20,30]", "10"], ["[10,20,30]", "11"], ["[1,100,101,102]", "2"], ["[2,2]", "100"], ["[0,0]", "0"], ["[0,5,10]", "5"], ["[3,7,11]", "4"], ["[1,4,7,10]", "3"], ["[100]", "10000000"], ["[1,2,3]", "100"], ["[0,2,4,6,8]", "2"], ["[0,2,4,6,8]", "3"]], "expected": [4, 3, 5, 0, 1, 5, 9, 2, 8, 9, 20000000, 0, 1, 12, 13, 13, 30, 31, 6, 100, 0, 15, 12, 12, 10000000, 102, 10, 11], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "507", "slug": "ternary-expression-parser", "id": 507, "title": "Ternary Expression Parser", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/ternary-expression-parser/", "examples": [{"input": "expression = \"T?2:3\"", "output": "\"2\"", "explanation": "The condition is true, so the true branch 2 is picked."}, {"input": "expression = \"F?1:T?4:5\"", "output": "\"4\"", "explanation": "The outer condition is false, so the inner true choice T?4:5 gives 4."}, {"input": "expression = \"T?T?F:5:3\"", "output": "\"F\"", "explanation": "The inner T?F:5 is F, leaving T?F:3 which is F."}], "hints": ["Choices group from the right, so scanning from right to left turns nesting into a simple stack process.", "Push plain values and colons; when you meet '?', pop the true value, the colon, and the false value, then push back the picked one.", "The character just before '?' is the condition: 'T' keeps the first value, 'F' keeps the second."], "statement": "You are given a short program written with nested choices. The text `expression` uses `T` for true, `F` for false, single digits `0` to `9` as plain values, and the symbols `?` and `:` to form choices shaped like `condition ? valueIfTrue : valueIfFalse`.\n\nChoices can nest on either side, and nesting groups from the right. To find the answer, decide the rightmost choice first, replace it with its picked branch, then keep working leftward until one value remains.\n\nReturn that final value as a one-character string.\n\n**Constraints:**\n- `1 <= expression.length <= 10000`\n- `expression` contains only `T`, `F`, `0`-`9`, `?` and `:`.\n- `expression` is always a valid nested choice expression.\n- The answer is always a single character (`T`, `F`, or a digit).\n", "solution": "## Approach\n\nScan the choice text from right to left while keeping a stack. Plain values and colons are pushed. When a question mark is seen, pop the true branch, discard the colon, pop the false branch, and push back whichever branch the condition character selects. Because nesting groups from the right, this single pass collapses every level.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `expression`. Each character 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 parseTernary(self, expression: str) -> str:\n st = []\n i = len(expression) - 1\n while i >= 0:\n c = expression[i]\n if c == '?':\n cond = expression[i - 1]\n i -= 1\n t = st.pop()\n st.pop()\n f = st.pop()\n st.append(t if cond == 'T' else f)\n elif c == ':':\n st.append(c)\n else:\n st.append(c)\n i -= 1\n return st.pop()\n```\n", "starter": {"go": "package main\n\nfunc ParseTernary(expression string) string {\n return \"\"\n}", "python": "class Solution:\n def parseTernary(self, expression: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string parseTernary(string expression) {\n return \"\";\n }\n};"}, "fn": "parseTernary", "params": [{"name": "expression", "type": "string"}], "outputType": "string", "tests": [["T?2:3"], ["F?1:T?4:5"], ["T?T?F:5:3"], ["F"], ["T"], ["F?T:F"], ["T?F:T"], ["T?1:F?2:3"], ["F?1:F?2:3"], ["T?T?T?1:2:3:4"], ["F?T?1:2:F?3:4"], ["T?9:0"], ["F?9:0"], ["T?F?1:2:T?3:4"], ["F?F?1:2:T?3:4"], ["T?T?F?1:2:3:4"], ["5"], ["T?T:F"], ["F?T?F?1:2:3:4"], ["T?F?F?1:2:3:T?4:5"], ["T?T?1:2:3"], ["F?T?1:2:3"], ["T?F?1:2:F?3:4"], ["F?F?1:2:F?3:4"], ["T?0:1"], ["F?0:1"], ["T?T?T?T?1:2:3:4:5"], ["F?1:2"], ["T?1:2"], ["T?F:F"]], "expected": ["2", "4", "F", "F", "T", "F", "F", "1", "3", "1", "4", "9", "0", "2", "3", "2", "5", "T", "4", "3", "1", "3", "2", "4", "0", "1", "1", "2", "1", "F"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "271", "slug": "text-justification", "id": 271, "title": "Text Justification", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/text-justification/", "examples": [{"input": "words = [\"This\",\"is\",\"an\",\"example\",\"of\",\"text\",\"justification.\"], maxWidth = 16", "output": "[\"This is an\",\"example of text\",\"justification. \"]", "explanation": "The first two lines spread extra blanks across gaps; the last line is left-aligned."}, {"input": "words = [\"What\",\"must\",\"be\",\"acknowledgment\",\"shall\",\"be\"], maxWidth = 16", "output": "[\"What must be\",\"acknowledgment \",\"shall be \"]", "explanation": "The long word fills its own line with trailing blanks."}], "hints": ["Greedily pack words: keep adding while the total letters plus minimum single spaces fits maxWidth.", "For justified lines, compute total blanks and share them as (blanks / gaps) with the first (blanks % gaps) gaps getting one extra.", "Left-align the last line and any single-word line: join with single spaces then pad the end."], "statement": "Spread a list of words across fully justified lines of exactly `maxWidth` characters. Pack as many words as possible into each line, then distribute blanks so the line reaches the required width.\n\nFor every line except the last, pad the gaps between words as evenly as possible, giving leftover single spaces to the leftmost gaps first. A line holding only one word is left-aligned with trailing blanks. The final line is left-aligned with single spaces between words and trailing blanks to fill the width.\n\n**Constraints:**\n- `1 <= words.length <= 300`\n- `1 <= words[i].length <= 20`\n- `1 <= maxWidth <= 100`\n- Each word contains letters and symbols without spaces.\n", "solution": "## Approach\n\nScan words greedily, extending each line while letters plus one blank per gap still fit. For middle lines with several words, divide the leftover blanks evenly among gaps and hand the remainder to the leftmost gaps. Single-word lines and the final line are left-aligned with single gaps and trailing padding.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(total characters), each word and blank written once.\n- **Space Complexity:** O(total characters) for the output lines.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:\n res = []\n i = 0\n while i < len(words):\n j = i\n line_len = 0\n while j < len(words) and line_len + len(words[j]) + (j - i) <= maxWidth:\n line_len += len(words[j])\n j += 1\n num = j - i\n is_last = (j == len(words))\n if num == 1 or is_last:\n line = \" \".join(words[i:j])\n line += \" \" * (maxWidth - len(line))\n res.append(line)\n else:\n total = maxWidth - line_len\n gaps = num - 1\n base, extra = divmod(total, gaps)\n parts = []\n for k in range(i, j):\n parts.append(words[k])\n if k < j - 1:\n spaces = base + (1 if k - i < extra else 0)\n parts.append(\" \" * spaces)\n res.append(\"\".join(parts))\n i = j\n return res\n```\n", "starter": {"go": "package main\n\nfunc FullJustify(words []string, maxWidth int) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> fullJustify(vector<string>& words, int maxWidth) {\n return {};\n }\n};"}, "fn": "fullJustify", "params": [{"name": "words", "type": "string_array"}, {"name": "maxWidth", "type": "int"}], "outputType": "string_list", "tests": [["['This', 'is', 'an', 'example', 'of', 'text', 'justification.']", "16"], ["['What', 'must', 'be', 'acknowledgment', 'shall', 'be']", "16"], ["['Science', 'is', 'what', 'we', 'understand', 'well', 'enough', 'to', 'explain', 'to', 'a', 'computer.', 'Art', 'is', 'everything', 'else', 'we', 'do']", "20"], ["['a']", "1"], ["['a']", "5"], ["['ab', 'cd', 'ef']", "5"], ["['hello', 'world']", "11"], ["['hello', 'world']", "12"], ["['a', 'b', 'c', 'd', 'e']", "3"], ["['a', 'b', 'c', 'd', 'e']", "5"], ["['word']", "4"], ["['word', 'word', 'word']", "10"], ["['listen', 'to', 'many,', 'speak', 'to', 'a', 'few.']", "6"], ["['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']", "16"], ["['a', 'b']", "2"], ["['ab', 'cde', 'f']", "6"], ["['x']", "10"], ["['a', 'bb', 'ccc', 'dddd']", "7"], ["['hello']", "5"], ["['hi', 'there', 'everyone']", "10"], ["['one', 'two', 'three', 'four', 'five']", "8"], ["['a', 'b', 'c']", "1"], ["['longword', 'a', 'b', 'c']", "8"], ["['I', 'am', 'a', 'test']", "6"], ["['ab', 'cd']", "3"], ["['a', 'b', 'c', 'd']", "4"], ["['aa', 'bb', 'cc', 'dd']", "9"], ["['w1', 'w2', 'w3', 'w4', 'w5', 'w6']", "7"], ["['a!b', 'c?d', 'e.f']", "8"], ["['Ends', 'with', 'spaces', 'test']", "10"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "567", "slug": "the-maze-ii", "id": 567, "title": "The Maze II", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/the-maze-ii/", "examples": [{"input": "maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]", "output": "12", "explanation": "One shortest rolling route covers 12 steps before stopping on the target."}, {"input": "maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]", "output": "-1", "explanation": "The ball can never come to rest on that cell, so the answer is -1."}, {"input": "maze = [[0,0,0],[0,0,0],[0,0,0]], start = [0,0], destination = [2,2]", "output": "4", "explanation": "Roll right across the top row (2 steps), then down the last column (2 steps)."}], "hints": ["Rolling turns stopping cells into graph nodes; edge weights are the roll lengths, so Dijkstra over stopping points gives the optimum.", "From each settled cell, simulate all four rolls to their stopping cells and relax longer known distances.", "Starting on the destination needs zero travel, and unreachable targets stay at -1."], "statement": "A ball rolls through a rectangular grid. Cells holding `0` are open floor and cells holding `1` are walls. From any open cell the ball can be launched in one of the four straight directions (up, down, left, right). Once moving it keeps rolling until a wall or the outer border stops it; it cannot halt partway. Each step onto a neighboring open cell adds one to the travelled length.\n\nGiven the grid `maze`, a `start` cell `[row, col]` and a `destination` cell `[row, col]`, compute the smallest total travel length that carries the ball from `start` to `destination` while obeying the rolling rule. The ball must come to rest exactly on `destination`. Return `-1` when the destination cannot be reached this way.\n\n**Constraints:**\n- `1 <= maze.length, maze[0].length <= 100`\n- `maze[i][j]` is `0` (open) or `1` (wall)\n- `start.length == 2` and `destination.length == 2`\n- `0 <= start[0], destination[0] < maze.length`\n- `0 <= start[1], destination[1] < maze[0].length`\n- Both `start` and `destination` are open cells\n", "solution": "## Approach\n\nTreat every cell where the ball can rest as a graph vertex. Rolling from one resting cell in a straight line until a wall yields an edge whose weight is the number of cells crossed. Because all weights are positive, Dijkstra's algorithm starting at `start` finds the cheapest travel length to every reachable resting cell. Simulate each of the four rolls directly, relax improved distances through a priority queue, and read off the destination distance (or `-1` when it stays unsettled).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n * max(m, n) * log(m * n)) for rolling simulation plus heap operations.\n- **Space Complexity:** O(m * n) for the distance table and the queue.\n\n## Implementation\n\n```python\nfrom typing import List\nimport heapq\n\nclass Solution:\n def shortestDistance(self, maze: List[List[int]], start: List[int], destination: List[int]) -> int:\n m, n = len(maze), len(maze[0])\n INF = 10 ** 9\n dist = [[INF] * n for _ in range(m)]\n dist[start[0]][start[1]] = 0\n pq = [(0, start[0], start[1])]\n dirs = [(-1, 0), (1, 0), (0, -1), (0, 1)]\n while pq:\n d, r, c = heapq.heappop(pq)\n if d != dist[r][c]:\n continue\n if r == destination[0] and c == destination[1]:\n return d\n for dr, dc in dirs:\n nr, nc, steps = r, c, 0\n while 0 <= nr + dr < m and 0 <= nc + dc < n and maze[nr + dr][nc + dc] == 0:\n nr += dr\n nc += dc\n steps += 1\n if dist[nr][nc] > d + steps:\n dist[nr][nc] = d + steps\n heapq.heappush(pq, (d + steps, nr, nc))\n ans = dist[destination[0]][destination[1]]\n return -1 if ans == INF else ans\n```\n", "starter": {"go": "package main\n\nfunc ShortestDistance(maze [][]int, start []int, destination []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def shortestDistance(self, maze: List[List[int]], start: List[int], destination: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int shortestDistance(vector<vector<int>>& maze, vector<int>& start, vector<int>& destination) {\n return -1;\n }\n};"}, "fn": "shortestDistance", "params": [{"name": "maze", "type": "int_array_2d"}, {"name": "start", "type": "int_array"}, {"name": "destination", "type": "int_array"}], "outputType": "int", "tests": [["[[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]", "[0,4]", "[4,4]"], ["[[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]", "[0,4]", "[3,2]"], ["[[0,0,0],[0,0,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0],[0,0,0],[0,0,0]]", "[0,0]", "[0,0]"], ["[[0,1],[0,0]]", "[0,0]", "[1,1]"], ["[[0,1],[0,0]]", "[0,0]", "[0,0]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0]]", "[0,0]", "[2,3]"], ["[[0,0,0,0],[0,1,1,0],[0,0,0,0]]", "[0,0]", "[2,3]"], ["[[1,0],[0,0]]", "[0,1]", "[1,1]"], ["[[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0]]", "[0,0]", "[3,4]"], ["[[0,0,0,0,0],[0,1,0,1,0],[0,0,0,0,0]]", "[0,0]", "[2,4]"], ["[[0,0],[0,0]]", "[0,0]", "[1,1]"], ["[[0,0],[0,0]]", "[0,0]", "[0,1]"], ["[[0,0,0],[0,1,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0],[0,1,0],[0,0,0]]", "[0,0]", "[1,1]"], ["[[0,0,0,1,0],[0,0,0,0,0],[0,1,0,1,0],[0,0,0,0,0]]", "[3,0]", "[0,4]"], ["[[0]]", "[0,0]", "[0,0]"], ["[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]]", "[0,0]", "[2,5]"], ["[[0,0,1],[0,1,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0,0],[1,1,0,0],[0,0,0,1],[0,1,0,0]]", "[0,0]", "[3,3]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]", "[1,1]", "[1,1]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]", "[0,3]", "[3,0]"], ["[[0,1,0],[0,1,0],[0,0,0]]", "[0,0]", "[0,2]"], ["[[0,0,0,0,0],[1,1,1,1,0],[0,0,0,0,0]]", "[0,0]", "[2,4]"], ["[[0,0],[1,0]]", "[0,0]", "[1,1]"], ["[[0,0,0],[1,1,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0,0,0,0,0],[0,1,1,1,1,1,0],[0,0,0,0,0,0,0]]", "[0,0]", "[2,6]"], ["[[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]", "[0,4]", "[1,2]"]], "expected": [12, -1, 4, 0, 2, 0, 5, 5, 1, 7, 6, 2, 1, 4, -1, 7, 0, 7, 4, 8, 0, 6, 6, 6, 2, 4, 8, 9], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "562", "slug": "the-maze-iii", "id": 562, "title": "The Maze III", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/the-maze-iii/", "examples": [{"input": "maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], ball = [4,3], hole = [0,1]", "output": "\"lul\"", "explanation": "Rolling left, up and left in three segments reaches the hole with minimal distance."}, {"input": "maze = [[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]], ball = [4,3], hole = [3,0]", "output": "\"impossible\"", "explanation": "The hole sits in a pocket no rolling path can stop in."}], "hints": ["Treat stopping cells as nodes and rolling segments as weighted edges; Dijkstra over (distance, path) finds the optimum.", "Stop a roll early as soon as the hole is entered, counting only steps up to the hole.", "Order the priority queue by distance first and direction string second to get the lexicographically smallest shortest path."], "statement": "A ball rolls on a grid where `0` means open and `1` means wall. From a resting spot it may roll up (`u`), down (`d`), left (`l`) or right (`r`). It slides straight until the next step would hit a wall or leave the grid. There is one exception: if the rolling path crosses the hole cell, the ball drops in immediately and stops, even in open space.\n\nStarting from `ball`, find the shortest rolling route that ends in the hole. Distance is the number of open cells traveled. If several shortest routes exist, return the lexicographically smallest direction string (`d` < `l` < `r` < `u` in character order). When the hole cannot be reached, return the word `impossible`.\n\n**Constraints:**\n- `1 <= maze.length, maze[i].length <= 100`\n- Entries are `0` or `1`; ball and hole lie on open cells\n- Ball and hole positions differ\n", "solution": "## Approach\n\nModel each resting cell as a node and each maximal roll as a weighted edge, with the special rule that a roll halts early upon entering the hole. Dijkstra's algorithm over states ordered by (distance, path string) yields the shortest route, breaking ties toward the lexicographically smallest direction sequence. Distances and best paths are relaxed whenever a strictly shorter or equally short but smaller string is found.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n * (m + n) log(m * n)) for rolling from each cell with a heap.\n- **Space Complexity:** O(m * n) for distance, path and heap storage.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\n\nclass Solution:\n def findShortestWay(self, maze: List[List[int]], ball: List[int], hole: List[int]) -> str:\n m, n = len(maze), len(maze[0])\n INF = 10 ** 9\n dist = [[INF] * n for _ in range(m)]\n best = [[None] * n for _ in range(m)]\n dr = [1, 0, 0, -1]\n dc = [0, -1, 1, 0]\n ds = ['d', 'l', 'r', 'u']\n dist[ball[0]][ball[1]] = 0\n best[ball[0]][ball[1]] = \"\"\n pq = [(0, \"\", ball[0], ball[1])]\n while pq:\n d, p, r, c = heapq.heappop(pq)\n if d != dist[r][c] or p != best[r][c]:\n continue\n if r == hole[0] and c == hole[1]:\n return p\n for k in range(4):\n nr, nc, steps = r, c, d\n np = p + ds[k]\n while True:\n tr, tc = nr + dr[k], nc + dc[k]\n if not (0 <= tr < m and 0 <= tc < n and maze[tr][tc] == 0):\n break\n nr, nc = tr, tc\n steps += 1\n if nr == hole[0] and nc == hole[1]:\n break\n if nr == r and nc == c:\n continue\n if steps < dist[nr][nc] or (steps == dist[nr][nc] and (best[nr][nc] is None or np < best[nr][nc])):\n dist[nr][nc] = steps\n best[nr][nc] = np\n heapq.heappush(pq, (steps, np, nr, nc))\n return \"impossible\"\n```\n", "starter": {"go": "package main\n\nfunc FindShortestWay(maze [][]int, ball []int, hole []int) string {\n \n}", "python": "from typing import List\nclass Solution:\n def findShortestWay(self, maze: List[List[int]], ball: List[int], hole: List[int]) -> str:\n pass\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string findShortestWay(vector<vector<int>>& maze, vector<int>& ball, vector<int>& hole) {\n return \"\";\n }\n};"}, "fn": "findShortestWay", "params": [{"name": "maze", "type": "int_array_2d"}, {"name": "ball", "type": "int_array"}, {"name": "hole", "type": "int_array"}], "outputType": "string", "tests": [["[[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]]", "[4,3]", "[0,1]"], ["[[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]]", "[4,3]", "[3,0]"], ["[[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]]", "[0,0]", "[4,4]"], ["[[0,0,0],[0,0,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0],[0,0,0],[0,0,0]]", "[2,2]", "[0,0]"], ["[[0,0,0],[0,1,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0],[0,1,0],[0,0,0]]", "[0,0]", "[1,1]"], ["[[0,1,0],[0,1,0],[0,0,0]]", "[0,0]", "[0,2]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0]]", "[0,0]", "[0,3]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,1],[0,0,0],[1,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0,0,0],[0,0,0,0,0]]", "[0,0]", "[1,4]"], ["[[0,0],[0,0]]", "[0,0]", "[1,1]"], ["[[0,0],[0,0]]", "[0,0]", "[0,1]"], ["[[0,1],[0,0]]", "[0,0]", "[1,1]"], ["[[0,0,0],[1,1,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0,0,0,0,0],[0,0,1,0,0,1,0],[0,0,0,0,1,0,0],[0,0,0,0,0,0,1]]", "[0,4]", "[3,5]"], ["[[0,0,0],[0,0,0]]", "[0,0]", "[0,2]"], ["[[0,0,0],[0,0,0]]", "[0,2]", "[0,0]"], ["[[0,0,0,1],[0,1,0,0],[0,1,0,0]]", "[0,0]", "[1,3]"], ["[[0,0,0],[0,0,1],[0,1,0]]", "[0,0]", "[0,2]"], ["[[0,0,0,0],[1,1,1,0],[0,0,0,0]]", "[0,0]", "[2,3]"], ["[[0,0,1,0],[0,0,0,0],[0,0,0,0]]", "[2,0]", "[0,3]"], ["[[0,0,0,0,0],[0,1,1,1,0],[0,0,0,0,0]]", "[0,0]", "[2,4]"], ["[[0,0,0],[0,0,0],[1,1,0]]", "[2,2]", "[0,0]"], ["[[0,1,0,0],[0,1,0,1],[0,0,0,1],[1,1,0,0]]", "[0,0]", "[3,3]"], ["[[0,0,0,1,0],[0,0,0,1,0],[0,0,0,0,0]]", "[0,0]", "[0,4]"], ["[[0,0,0],[1,0,1],[0,0,0]]", "[0,1]", "[2,1]"]], "expected": ["lul", "impossible", "impossible", "dr", "lu", "dr", "impossible", "dru", "r", "dr", "drd", "dr", "dr", "r", "dr", "rd", "dldr", "r", "l", "rdru", "r", "rd", "ru", "dr", "ul", "drdr", "dru", "d"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "554", "slug": "the-maze", "id": 554, "title": "The Maze", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/the-maze/", "examples": [{"input": "maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]", "output": "true", "explanation": "Rolling left, down and around the walls lets the ball halt on the target cell."}, {"input": "maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [3,2]", "output": "false", "explanation": "Every rolling path stops on cells other than the requested destination."}], "hints": ["Model stopping positions as graph nodes; rolling to the wall in each direction gives the edges.", "Breadth-first or depth-first search over stopping positions avoids revisiting the same halt.", "Simulate each roll step by step until the cell before a wall, then enqueue that halt if unseen."], "statement": "A ball rests on an empty cell of a grid maze. Cells holding `0` are open; cells holding `1` are walls. From any stopping position the ball may roll in one of the four straight directions. Once moving it keeps sliding through open cells and only halts when the next step would hit a wall or leave the grid. At each halt it may pick a new direction.\n\nGiven the maze plus a start coordinate and a destination coordinate, decide whether the ball can come to rest exactly on the destination. Passing over the destination without stopping does not count.\n\nReturn `true` when such a rolling route exists and `false` otherwise.\n\n**Constraints:**\n- `1 <= maze.length, maze[i].length <= 100`\n- Entries are `0` (open) or `1` (wall)\n- Start and destination lie on open cells and differ\n- At least two open cells exist\n", "solution": "## Approach\n\nSearch only over cells where the ball can halt. From each halted cell simulate rolling in the four directions until the step before a wall or border, and treat that stopping cell as a neighbor. Breadth-first search marks halts visited so each is expanded once; reaching the destination halt means success.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n * (m + n)) in the worst case, since each of the m*n halts rolls up to m+n steps.\n- **Space Complexity:** O(m * n) for the visited table and queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\nclass Solution:\n def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool:\n m, n = len(maze), len(maze[0])\n vis = [[False] * n for _ in range(m)]\n q = deque([(start[0], start[1])])\n vis[start[0]][start[1]] = True\n while q:\n x, y = q.popleft()\n if x == destination[0] and y == destination[1]:\n return True\n for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):\n nx, ny = x, y\n while 0 <= nx + dx < m and 0 <= ny + dy < n and maze[nx + dx][ny + dy] == 0:\n nx += dx\n ny += dy\n if not vis[nx][ny]:\n vis[nx][ny] = True\n q.append((nx, ny))\n return False\n```\n", "starter": {"go": "package main\n\nfunc HasPath(maze [][]int, start []int, destination []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool hasPath(vector<vector<int>>& maze, vector<int>& start, vector<int>& destination) {\n return false;\n }\n};"}, "fn": "hasPath", "params": [{"name": "maze", "type": "int_array_2d"}, {"name": "start", "type": "int_array"}, {"name": "destination", "type": "int_array"}], "outputType": "boolean", "tests": [["[[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]", "[0,4]", "[4,4]"], ["[[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]]", "[0,4]", "[3,2]"], ["[[0,0,0,0,0],[1,1,0,0,1],[0,0,0,0,0],[0,1,0,0,1],[0,1,0,0,0]]", "[4,3]", "[0,1]"], ["[[0,0],[0,0]]", "[0,0]", "[1,1]"], ["[[0,1],[0,0]]", "[0,0]", "[1,1]"], ["[[0,0,0],[0,1,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0],[1,1,0],[0,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,1],[0,0,1],[1,0,0]]", "[0,0]", "[2,2]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0]]", "[0,0]", "[0,3]"], ["[[0,0,0,0],[0,0,0,0],[0,0,0,0]]", "[0,0]", "[2,2]"], ["[[0,1,0],[0,1,0],[0,0,0]]", "[0,0]", "[0,2]"], ["[[0,0,0],[0,0,0],[1,1,0]]", "[2,2]", "[0,0]"], ["[[0,0,0,1,0],[0,0,0,1,0],[0,0,0,0,0]]", "[0,0]", "[0,4]"], ["[[0]]", "[0,0]", "[0,0]"], ["[[0,0,0],[0,0,0]]", "[0,0]", "[1,2]"], ["[[1,1,0],[0,0,0],[0,0,0]]", "[0,2]", "[2,0]"], ["[[0,0,0],[0,1,1],[0,0,0]]", "[0,0]", "[2,0]"], ["[[0,0,1,0],[0,0,0,0],[0,0,0,0]]", "[2,0]", "[0,3]"], ["[[0,0,0,0,0],[0,1,1,1,0],[0,0,0,0,0]]", "[0,0]", "[2,4]"], ["[[0,1,0,0],[0,1,0,1],[0,0,0,1],[1,1,0,0]]", "[0,0]", "[3,3]"], ["[[0,0],[1,0]]", "[0,0]", "[1,1]"], ["[[0,0,0],[1,0,1],[0,0,0]]", "[0,1]", "[2,1]"], ["[[0,0,0,0,0],[1,1,1,1,0],[0,0,0,0,0]]", "[0,0]", "[2,4]"], ["[[0,0,1],[1,0,0],[0,0,0]]", "[0,0]", "[1,1]"], ["[[0,0,0,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]]", "[0,0]", "[3,3]"], ["[[0,1],[0,1],[0,0]]", "[0,0]", "[2,1]"], ["[[0,0,0,1],[0,1,0,0],[0,1,0,0]]", "[0,0]", "[1,3]"], ["[[0,0,0],[0,0,1],[0,1,0]]", "[0,0]", "[0,2]"]], "expected": [true, false, false, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], "loose": false}