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": "909", "slug": "sort-array-by-parity-ii", "id": 909, "title": "Sort Array By Parity II", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/sort-array-by-parity-ii/", "examples": [{"input": "nums = [4,2,5,7]", "output": "[4,5,2,7]", "explanation": "Even indices hold even values and odd indices hold odd values; other valid orders are also accepted."}, {"input": "nums = [2,3]", "output": "[2,3]", "explanation": "Already satisfies the parity placement."}], "hints": ["Even positions need even values and odd positions need odd values; any arrangement meeting that is accepted.", "Collect evens and odds separately, then deal them into even and odd slots.", "Alternatively sweep two pointers (one on even slots, one on odd slots) swapping misplaced pairs."], "statement": "You are given an integer array `nums` of even length where exactly half the entries are odd and half are even. Rearrange it so that every even index holds an even number and every odd index holds an odd number.\n\nReturn any such arrangement.\n\n**Constraints:**\n- `2 <= nums.length <= 2 * 10^4`\n- `nums.length` is even\n- Half the entries are odd and half are even\n- `0 <= nums[i] <= 1000`\n", "solution": "## Approach\n\nSince the input is guaranteed to hold equally many evens and odds, deal each value into its own kind of slot: evens go to indices 0, 2, 4, ... and odds to 1, 3, 5, .... Every slot receives a matching value, so one linear pass builds a valid rearrangement.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(n) for the answer (O(1) extra with an in-place two-pointer swap variant).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sortArrayByParityII(self, nums: List[int]) -> List[int]:\n n = len(nums)\n ans = [0] * n\n e, o = 0, 1\n for v in nums:\n if v % 2 == 0:\n ans[e] = v\n e += 2\n else:\n ans[o] = v\n o += 2\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SortArrayByParityII(nums []int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def sortArrayByParityII(self, nums: List[int]) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> sortArrayByParityII(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "sortArrayByParityII", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_array", "tests": [["[4,2,5,7]"], ["[2,3]"], ["[3,2]"], ["[518, 949]"], ["[918, 755, 71, 210]"], ["[594, 129]"], ["[327, 224, 874, 443, 759, 964]"], ["[335, 205, 983, 916, 774, 266, 568, 155, 750, 417, 776, 207]"], ["[438, 839, 149, 668]"], ["[2, 815, 951, 455, 816, 548, 263, 12, 928, 742, 883, 691]"], ["[328, 331]"], ["[855, 104, 42, 370, 137, 739]"], ["[509, 128, 528, 649]"], ["[419, 948, 486, 271, 339, 184, 705, 846, 738, 99]"], ["[774, 962, 235, 521, 696, 172, 439, 659]"], ["[178, 35, 268, 297]"], ["[62, 401, 804, 509, 645, 620, 757, 744, 357, 446]"], ["[132, 432, 519, 223, 961, 805, 534, 280]"], ["[143, 732]"], ["[855, 700, 664, 899, 763, 645, 998, 41, 462, 929, 756, 54]"], ["[812, 243, 444, 199, 262, 967]"], ["[716, 891]"], ["[2, 529]"], ["[921, 877, 782, 492, 482, 733, 315, 878]"], ["[800, 511, 850, 404, 383, 337, 787, 478]"], ["[824, 462, 901, 634, 837, 150, 517, 893, 386, 863, 168, 841]"], ["[260, 273]"], ["[200, 175, 687, 234, 350, 335]"]], "expected": [[4, 5, 2, 7], [2, 3], [2, 3], [518, 949], [918, 755, 210, 71], [594, 129], [224, 327, 874, 443, 964, 759], [916, 335, 774, 205, 266, 983, 568, 155, 750, 417, 776, 207], [438, 839, 668, 149], [2, 815, 816, 951, 548, 455, 12, 263, 928, 883, 742, 691], [328, 331], [104, 855, 42, 137, 370, 739], [128, 509, 528, 649], [948, 419, 486, 271, 184, 339, 846, 705, 738, 99], [774, 235, 962, 521, 696, 439, 172, 659], [178, 35, 268, 297], [62, 401, 804, 509, 620, 645, 744, 757, 446, 357], [132, 519, 432, 223, 534, 961, 280, 805], [732, 143], [700, 855, 664, 899, 998, 763, 462, 645, 756, 41, 54, 929], [812, 243, 444, 199, 262, 967], [716, 891], [2, 529], [782, 921, 492, 877, 482, 733, 878, 315], [800, 511, 850, 383, 404, 337, 478, 787], [824, 901, 462, 837, 634, 517, 150, 893, 386, 863, 168, 841], [260, 273], [200, 175, 234, 687, 350, 335]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "894", "slug": "sort-array-by-parity", "id": 894, "title": "Sort Array By Parity", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/sort-array-by-parity/", "examples": [{"input": "nums = [3,1,2,4]", "output": "[2,4,3,1]", "explanation": "Evens first in any order."}, {"input": "nums = [0]", "output": "[0]", "explanation": "Single even."}, {"input": "nums = [1,3,5,2,4]", "output": "[2,4,1,3,5]", "explanation": "Evens ahead."}], "hints": ["Use two pointers: one seeking an odd from the front and one seeking an even from the back, then swap.", "Alternatively, collect evens and odds in two passes and concatenate them."], "statement": "Reorder `nums` so that every even entry comes before every odd entry. The relative order inside the even block and inside the odd block does not matter \u2014 any arrangement with all evens first is accepted.\n\n**Constraints:**\n- `1 <= nums.length <= 5000`\n- `0 <= nums[i] <= 5000`\n\n> **Grading note:** outputs are checked by multiset equality plus the evens-first property, not by exact sequence match.\n", "solution": "## Approach\n\nSweep the input twice: first copy every even value to the answer, then append every odd value. This keeps all evens ahead of all odds while preserving the multiset. A two-pointer in-place swap achieves the same with constant extra room.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the two linear passes.\n- **Space Complexity:** O(n) for the fresh output (O(1) extra with the two-pointer variant).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sortArrayByParity(self, nums: List[int]) -> List[int]:\n return [x for x in nums if x % 2 == 0] + [x for x in nums if x % 2 == 1]\n```\n", "starter": {"go": "package main\n\nfunc SortArrayByParity(nums []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def sortArrayByParity(self, nums: List[int]) -> List[int]:\n return []", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> sortArrayByParity(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "sortArrayByParity", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_array", "tests": [["[3,1,2,4]"], ["[0]"], ["[1,3,5,2,4]"], ["[1]"], ["[2]"], ["[1,2]"], ["[2,1]"], ["[2,4,6,8]"], ["[1,3,5,7]"], ["[0,0,0]"], ["[1,1,1]"], ["[4,2,1,3]"], ["[5,4,3,2,1]"], ["[1,2,3,4,5,6]"], ["[6,5,4,3,2,1]"], ["[0,1]"], ["[1,0]"], ["[2,3,4,5,6,7,8]"], ["[11,22,33,44]"], ["[100,1,100,1]"], ["[0,2,1,3,4,5]"], ["[7,6,5,4,3,2,1]"], ["[5000,4999]"], ["[0,1,2,3,4,5,6,7,8,9]"], ["[9,8,7,6,5,4,3,2,1,0]"], ["[2,2,2,1,1,1]"], ["[1,2,1,2,1,2]"], ["[3,3,2,2,1,1]"]], "expected": [[2, 4, 3, 1], [0], [2, 4, 1, 3, 5], [1], [2], [2, 1], [2, 1], [2, 4, 6, 8], [1, 3, 5, 7], [0, 0, 0], [1, 1, 1], [4, 2, 1, 3], [4, 2, 5, 3, 1], [2, 4, 6, 1, 3, 5], [6, 4, 2, 5, 3, 1], [0, 1], [0, 1], [2, 4, 6, 8, 3, 5, 7], [22, 44, 11, 33], [100, 100, 1, 1], [0, 2, 4, 1, 3, 5], [6, 4, 2, 7, 5, 3, 1], [5000, 4999], [0, 2, 4, 6, 8, 1, 3, 5, 7, 9], [8, 6, 4, 2, 0, 9, 7, 5, 3, 1], [2, 2, 2, 1, 1, 1], [2, 2, 2, 1, 1, 1], [2, 2, 3, 3, 1, 1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "518", "slug": "sort-characters-by-frequency", "id": 518, "title": "Sort Characters By Frequency", "difficulty": "Medium", "category": "heap", "link": "https://leetcode.com/problems/sort-characters-by-frequency/", "examples": [{"input": "s = \"tree\"", "output": "\"eert\"", "explanation": "e appears twice, t and r once each."}, {"input": "s = \"cccaaa\"", "output": "\"aaaccc\"", "explanation": "Equal frequencies allow either block order."}, {"input": "s = \"Aabb\"", "output": "\"bbAa\"", "explanation": "b appears twice, A and a once each."}], "hints": ["Count each character first; the rest is ordering by those counts.", "Sorting distinct characters by descending count then repeating each by its count is simplest.", "Bucketing by count gives linear time, but sorting distinct letters is fine for the given limits."], "statement": "You are given a string `s`. Count how often each character appears, then reorder the characters so that more frequent characters come first. Characters with the same frequency may appear in any order relative to each other.\n\nReturn any reordering that respects non-increasing frequency.\n\n**Constraints:**\n- `1 <= s.length <= 5 * 10^5`\n- `s` contains letters, digits and spaces.\n", "solution": "## Approach\n\nTally each character, sort the distinct characters by descending count, then repeat every character according to its count. Any order among equal counts is accepted, which matches the checker that only enforces non-increasing frequencies and identical multisets.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + k log k), where n is the length of `s` and k is the number of distinct characters.\n- **Space Complexity:** O(n) for the tally and the output.\n\n## Implementation\n\n```python\nfrom collections import Counter\nclass Solution:\n def frequencySort(self, s: str) -> str:\n freq = Counter(s)\n chars = sorted(freq.keys(), key=lambda c: -freq[c])\n return \"\".join(c * freq[c] for c in chars)\n```\n", "starter": {"go": "package main\n\nfunc FrequencySort(s string) string {\n return \"\"\n}", "python": "class Solution:\n def frequencySort(self, s: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string frequencySort(string s) {\n return \"\";\n }\n};"}, "fn": "frequencySort", "params": [{"name": "s", "type": "string"}], "outputType": "string", "tests": [["tree"], ["cccaaa"], ["Aabb"], ["a"], ["aaaa"], ["ab"], ["raaeaedere"], ["eeeee"], ["Aabbcc"], ["2a2a2a33"], ["hello world"], ["mississippi"], ["aAbBcC"], ["zzzzzyyyyxxxwwvvvuu"], ["abcabcabc"], ["112233"], ["eEeEeEee"], ["qwerty"], ["aabbccdd"], ["zzz"], ["abc"], ["aA1 "], ["hello"], ["aaabbbcccddd"], ["1122334455"], ["a b c"], ["abacaba"], ["xyxyxyxy"], ["AaAaBbBb"], ["123abc123"]], "expected": ["eert", "aaaccc", "bbAa", "a", "aaaa", "ab", "eeeeaaarrd", "eeeee", "bbccAa", "aaa22233", "llloo rdewh", "ssssiiiippm", "aAbBcC", "zzzzzyyyyvvvxxxuuww", "aaabbbccc", "112233", "eeeeeEEE", "qrtewy", "aabbccdd", "zzz", "abc", " aA1", "lleho", "aaabbbcccddd", "1122334455", " abc", "aaaabbc", "xxxxyyyy", "AAaaBBbb", "112233abc"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "159", "slug": "sort-colors", "id": 159, "title": "Sort Colors", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/sort-colors/", "examples": [{"input": "nums = [2,0,2,1,1,0]", "output": "[0,0,1,1,2,2]", "explanation": "Reds (0), then whites (1), then blues (2) are grouped in order."}, {"input": "nums = [2,0,1]", "output": "[0,1,2]", "explanation": "One of each color sorts to [0,1,2]."}, {"input": "nums = [0]", "output": "[0]", "explanation": "A single element is already sorted."}], "hints": ["Count 0s, 1s, and 2s in one pass, then overwrite the array (counting sort).", "Or use the Dutch national flag: three pointers (low, mid, high) for a single-pass O(1)-space sort."], "statement": "You receive a list `nums` holding `n` items painted red, white, or blue. Place equal colours side by side so that all reds come first, all whites come next, and all blues come last.\n\nRed is coded as `0`, white as `1`, and blue as `2`. Do not rely on the standard-library sort. In this judge's functional setup, hand back the arranged list.\n\n**Constraints:**\n\n- n == nums.length\n- 1 \u2264 n \u2264 300\n- nums[i] is either 0, 1, or 2.\n", "solution": "## Approach\n\nUse the Dutch national flag algorithm with three pointers `low`, `mid`, and `high`. Scan with `mid`: on `0` swap to `low` and advance both; on `1` advance `mid`; on `2` swap to `high` and shrink `high`. This sorts 0s, 1s, 2s in a single pass without a library sort.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), single pass over `nums`.\n- **Space Complexity:** O(1) extra (O(n) for the returned copy in this judge's functional form; in-place otherwise).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sortColors(self, nums: List[int]) -> List[int]:\n low = mid = 0\n high = len(nums) - 1\n while mid <= high:\n if nums[mid] == 0:\n nums[low], nums[mid] = nums[mid], nums[low]\n low += 1\n mid += 1\n elif nums[mid] == 1:\n mid += 1\n else:\n nums[mid], nums[high] = nums[high], nums[mid]\n high -= 1\n return nums\n```\n", "starter": {"go": "package main\n\nfunc SortColors(nums []int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def sortColors(self, nums: List[int]) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> sortColors(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "sortColors", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_array", "tests": [["[2,0,2,1,1,0]"], ["[2,0,1]"], ["[0]"], ["[1]"], ["[2]"], ["[1,2,0]"], ["[0,0,0]"], ["[2,2,2]"], ["[1,1,1]"], ["[2,1,0,2,1,0]"], ["[0,1,2,0,1,2]"], ["@javascript:JSON.stringify(Array.from({length:300},(_,i)=>i%3))"], ["[0,1]"], ["[1,0]"], ["[0,2]"], ["[2,0]"], ["[1,2]"], ["[2,1]"], ["[0,0,1]"], ["[0,0,2]"], ["[1,1,0]"], ["[1,1,2]"], ["[2,2,0]"], ["[2,2,1]"], ["[2,0,0,1,2]"], ["[1,2,1,0,1]"], ["[2,1,2,0,0,1,2]"], ["[0,2,0,2,0,2]"], ["[1,0,1,2,1,0,2,1]"], ["[2,2,1,1,0,0]"]], "expected": [[0, 0, 1, 1, 2, 2], [0, 1, 2], [0], [1], [2], [0, 1, 2], [0, 0, 0], [2, 2, 2], [1, 1, 1], [0, 0, 1, 1, 2, 2], [0, 0, 1, 1, 2, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [0, 1], [0, 1], [0, 2], [0, 2], [1, 2], [1, 2], [0, 0, 1], [0, 0, 2], [0, 1, 1], [1, 1, 2], [0, 2, 2], [1, 2, 2], [0, 0, 1, 2, 2], [0, 1, 1, 1, 2], [0, 0, 1, 1, 2, 2, 2], [0, 0, 0, 2, 2, 2], [0, 0, 1, 1, 1, 1, 2, 2], [0, 0, 1, 1, 2, 2]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "305", "slug": "sort-list", "id": 305, "title": "Sort List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/sort-list/", "examples": [{"input": "head = [4,2,1,3]", "output": "[1,2,3,4]", "explanation": "Sorting the values gives ascending order."}, {"input": "head = [-1,5,3,4,0]", "output": "[-1,0,3,4,5]", "explanation": "The same multiset of values appears in sorted order."}, {"input": "head = []", "output": "[]", "explanation": "An empty list stays empty."}], "hints": ["Split the list into halves with slow/fast pointers, sort each half, then merge.", "Merging two sorted lists is linear and needs only pointer rewiring.", "An iterative bottom-up merge pass can remove recursion depth."], "statement": "Given the head of a singly linked list, reorder its nodes in non-decreasing order and return the new head.\n\nAim for `O(n log n)` time with `O(1)` extra space (recursion stack aside), for example via merge sort on linked lists.\n\n**Constraints:**\n- The list holds between 0 and 5 * 10^4 nodes.\n- `-10^5 <= Node.val <= 10^5`\n", "solution": "## Approach\n\nApply merge sort directly on the links. Find the midpoint with slow/fast pointers, sever the list, recursively sort both halves, and stitch them with a linear merge that always takes the smaller front node.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n), where n is the list length. Each level processes all nodes once.\n- **Space Complexity:** O(log n) recursion stack for the top-down split (O(1) link space).\n\n## Implementation\n\n```python\nclass Solution:\n def sortList(self, head):\n if not head or not head.next:\n return head\n slow, fast = head, head.next\n while fast and fast.next:\n slow = slow.next\n fast = fast.next.next\n mid = slow.next\n slow.next = None\n a = self.sortList(head)\n b = self.sortList(mid)\n return self._merge(a, b)\n\n def _merge(self, a, b):\n dummy = ListNode(0)\n p = dummy\n while a and b:\n if a.val <= b.val:\n p.next, a = a, a.next\n else:\n p.next, b = b, b.next\n p = p.next\n p.next = a or b\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 SortList(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 sortList(self, head):\n pass", "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* sortList(ListNode* head) {\n \n }\n};"}, "fn": "sortList", "params": [{"name": "head", "type": "list_node"}], "outputType": "list_node", "tests": [["[4,2,1,3]"], ["[-1,5,3,4,0]"], ["[]"], ["[1]"], ["[2,1]"], ["[1,2,3]"], ["[3,2,1]"], ["[5,4,3,2,1]"], ["[1,1,1,1]"], ["[0,0,1,0]"], ["[10,-10,5,-5,0]"], ["[7,3,9,1,5,2,8]"], ["[100000,-100000,0]"], ["[4,2,1,3,5,6,7,8]"], ["[8,7,6,5,4,3,2,1]"], ["[1,3,2]"], ["[2,1,3,5,4]"], ["[9]"], ["[5,1,1,2,0,0]"], ["[-1,-2,-3,-4]"], ["[3,3,2,2,1,1]"], ["[42]"], ["[6,5,3,1,8,7,2,4]"], ["[1,2]"], ["[2,2,2,1,1]"], ["[50000,-50000,25000,-25000,0]"], ["[13,11,17,19,2,5,3]"], ["[0]"]], "expected": [[1, 2, 3, 4], [-1, 0, 3, 4, 5], null, [1], [1, 2], [1, 2, 3], [1, 2, 3], [1, 2, 3, 4, 5], [1, 1, 1, 1], [0, 0, 0, 1], [-10, -5, 0, 5, 10], [1, 2, 3, 5, 7, 8, 9], [-100000, 0, 100000], [1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3], [1, 2, 3, 4, 5], [9], [0, 0, 1, 1, 2, 5], [-4, -3, -2, -1], [1, 1, 2, 2, 3, 3], [42], [1, 2, 3, 4, 5, 6, 7, 8], [1, 2], [1, 1, 2, 2, 2], [-50000, -25000, 0, 25000, 50000], [2, 3, 5, 11, 13, 17, 19], [0]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "439", "slug": "sort-transformed-array", "id": 439, "title": "Sort Transformed Array", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/sort-transformed-array/", "examples": [{"input": "nums = [-4,-2,2,4], a = 1, b = 3, c = 5", "output": "[3,9,15,33]", "explanation": "The raw values are 9, 3, 15 and 33, which sort to [3,9,15,33]."}, {"input": "nums = [-4,-2,2,4], a = -1, b = 3, c = 5", "output": "[-23,-5,1,7]", "explanation": "The raw values are -23, 7, 1 and -5, which sort to [-23,-5,1,7]."}], "hints": ["Compare the transformed values at both ends of the sorted input.", "For a >= 0 fill the answer from the back with the larger end; for a < 0 fill from the front with the smaller end.", "Each step consumes one end, giving a linear two-pointer pass."], "statement": "You are given a sorted integer array `nums` plus three coefficients `a`, `b`\nand `c`. Apply the quadratic map `f(x) = a*x^2 + b*x + c` to every element,\nthen return the transformed values in non-decreasing order.\n\nA direct transform breaks the ordering, but the parabola shape lets you refill\nthe answer from one end: with `a >= 0` the largest values come from the outer\nends, while with `a < 0` the smallest values come from the outer ends.\n\n**Constraints:**\n- `1 <= nums.length <= 500`\n- `-100 <= nums[i] <= 100`, sorted in non-decreasing order\n- `-100 <= a, b, c <= 100`\n", "solution": "## Approach\n\nEvaluate the quadratic at both ends of the sorted input. The parabola opens\nupward when `a >= 0`, so the larger end value belongs at the back of the\nanswer; it opens downward when `a < 0`, so the smaller end value belongs at\nthe front. Consuming one end per step keeps the whole pass linear.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the array length.\n- **Space Complexity:** O(n) for the output (O(1) extra).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def sortTransformedArray(self, nums: List[int], a: int, b: int, c: int) -> List[int]:\n def f(x: int) -> int:\n return a * x * x + b * x + c\n n = len(nums)\n out = [0] * n\n l, r = 0, n - 1\n idx = n - 1 if a >= 0 else 0\n while l <= r:\n lv, rv = f(nums[l]), f(nums[r])\n if a >= 0:\n if lv >= rv:\n out[idx] = lv\n l += 1\n else:\n out[idx] = rv\n r -= 1\n idx -= 1\n else:\n if lv <= rv:\n out[idx] = lv\n l += 1\n else:\n out[idx] = rv\n r -= 1\n idx += 1\n return out\n```\n", "starter": {"go": "package main\n\nfunc SortTransformedArray(nums []int, a int, b int, c int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def sortTransformedArray(self, nums: List[int], a: int, b: int, c: int) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> sortTransformedArray(vector<int>& nums, int a, int b, int c) {\n return {};\n }\n};"}, "fn": "sortTransformedArray", "params": [{"name": "nums", "type": "int_array"}, {"name": "a", "type": "int"}, {"name": "b", "type": "int"}, {"name": "c", "type": "int"}], "outputType": "int_array", "tests": [["[-4,-2,2,4]", "1", "3", "5"], ["[-4,-2,2,4]", "-1", "3", "5"], ["[0]", "0", "0", "7"], ["[-3,-2,-1]", "0", "2", "1"], ["[1,2,3]", "0", "0", "0"], ["[-5,-4,-3,-2,-1]", "1", "0", "0"], ["[1,2,3,4,5]", "1", "0", "0"], ["[-2,-1,0,1,2]", "1", "0", "0"], ["[-2,-1,0,1,2]", "-1", "0", "0"], ["[-2,-1,0,1,2]", "0", "1", "0"], ["[-2,-1,0,1,2]", "0", "-1", "0"], ["[-100,100]", "1", "1", "1"], ["[-100,100]", "-1", "-1", "-1"], ["[3]", "2", "-3", "1"], ["[-5,5]", "0", "0", "-4"], ["[-3,0,3]", "2", "0", "-1"], ["[-3,0,3]", "-2", "0", "1"], ["[-10,-5,0,5,10]", "1", "-2", "1"], ["[-10,-5,0,5,10]", "-1", "2", "-1"], ["[0,1,2]", "0", "0", "5"], ["[-1,0,1]", "3", "-4", "2"], ["[-7,-3,2,8]", "1", "1", "1"], ["[-7,-3,2,8]", "-1", "-1", "-1"], ["[1,1,1,1]", "1", "2", "3"], ["[-2,-2,0,0]", "-2", "3", "0"], ["[5]", "-3", "7", "-2"]], "expected": [[3, 9, 15, 33], [-23, -5, 1, 7], [7], [-5, -3, -1], [0, 0, 0], [1, 4, 9, 16, 25], [1, 4, 9, 16, 25], [0, 1, 1, 4, 4], [-4, -4, -1, -1, 0], [-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2], [9901, 10101], [-10101, -9901], [10], [-4, -4], [-1, 17, 17], [-17, -17, 1], [1, 16, 36, 81, 121], [-121, -81, -36, -16, -1], [5, 5, 5], [1, 2, 9], [7, 7, 43, 73], [-73, -43, -7, -7], [6, 6, 6, 6], [-14, -14, 0, 0], [-42]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "806", "slug": "soup-servings", "id": 806, "title": "Soup Servings", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/soup-servings/", "examples": [{"input": "n = 50", "output": "\"0.625\"", "explanation": "Mixed paths give 0.625."}, {"input": "n = 100", "output": "\"0.71875\"", "explanation": "Larger start favours A."}, {"input": "n = 0", "output": "\"0.5\"", "explanation": "Both empty together counts half."}], "hints": ["This is a portable adaptation: return the probability as a finite decimal string; the checker allows 1e-9 absolute plus 1e-5 relative error.", "Scale by 25 ml units and memoize the recursion on remaining (a,b) pairs.", "Beyond about 4800 ml the answer is 1.0 for practical purposes, so shortcut large n."], "statement": "Two large pots hold `n` millilitres of soup A and soup B. In each turn, one of four serving pairs is chosen with equal chance: (100,0), (75,25), (50,50), or (25,75), where the first number is taken from A and the second from B. If less than the chosen amount remains, the pot is simply emptied.\n\nThe process stops as soon as at least one pot becomes empty. We want the chance that A empties first, counting the case where both empty together as half a success.\n\nReturn that probability as a decimal string (for example `\"0.625\"`). Answers within a tiny tolerance are accepted.\n\n**Constraints:**\n- `0 <= n <= 10^9`\n- This is a portable adaptation: the floating answer is exchanged as a decimal string with tolerance 1e-9 absolute plus 1e-5 relative.\n", "solution": "## Approach\n\nRescale millilitres into 25 ml units so the four moves become small integer steps. Memoized recursion over remaining (a,b) pairs returns 0.5 when both empty together, 1.0 when only A is empty, 0.0 when only B is empty, and otherwise the average of the four successors. Very large `n` is shortcut to 1.0.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m^2), where m is ceil(n / 25), capped by the 5000 shortcut.\n- **Space Complexity:** O(m^2) for the memo table.\n\n## Implementation\n\n```python\nclass Solution:\n def soupServings(self, n: int) -> str:\n if n >= 5000:\n return str(1.0)\n m = (n + 24) // 25\n memo = {}\n def dfs(a: int, b: int) -> float:\n if a <= 0 and b <= 0:\n return 0.5\n if a <= 0:\n return 1.0\n if b <= 0:\n return 0.0\n if (a, b) in memo:\n return memo[(a, b)]\n v = (dfs(a - 4, b) + dfs(a - 3, b - 1) + dfs(a - 2, b - 2) + dfs(a - 1, b - 3)) / 4.0\n memo[(a, b)] = v\n return v\n return str(dfs(m, m))\n```\n", "starter": {"go": "package main\n\nfunc SoupServings(n int) string {\n return \"\"\n}", "python": "class Solution:\n def soupServings(self, n: int) -> str:\n return \"\"", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string soupServings(int n) {\n return \"\";\n }\n};"}, "fn": "soupServings", "params": [{"name": "n", "type": "int"}], "outputType": "string", "tests": [["50"], ["100"], ["0"], ["1"], ["2"], ["10"], ["25"], ["26"], ["49"], ["51"], ["75"], ["125"], ["200"], ["500"], ["800"], ["1000"], ["1500"], ["2000"], ["2500"], ["3000"], ["4000"], ["4800"], ["5000"], ["6000"], ["10000"], ["100000"], ["1000000000"], ["30"]], "expected": ["0.625", "0.71875", "0.5", "0.625", "0.625", "0.625", "0.625", "0.625", "0.625", "0.65625", "0.65625", "0.7421875", "0.796875", "0.916344165802002", "0.961617625085637", "0.9765650521094358", "0.9928319024738018", "0.9977163163248763", "0.99925483400331", "0.9997529725570642", "0.9999719963014364", "0.999994994425816", "1.0", "1.0", "1.0", "1.0", "1.0", "0.625"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "401", "slug": "sparse-matrix-multiplication", "id": 401, "title": "Sparse Matrix Multiplication", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/sparse-matrix-multiplication/", "examples": [{"input": "mat1 = [[1,0,0],[-1,0,3]], mat2 = [[7,0,0],[0,0,0],[0,0,1]]", "output": "[[7,0,0],[-7,0,3]]", "explanation": "Zero entries contribute nothing to the dots."}, {"input": "mat1 = [[0]], mat2 = [[0]]", "output": "[[0]]", "explanation": "Zero times zero is zero."}, {"input": "mat1 = [[1,2],[3,4]], mat2 = [[5,6],[7,8]]", "output": "[[19,22],[43,50]]", "explanation": "Standard 2 x 2 product."}], "hints": ["Entry (i, j) of the answer sums mat1[i][p] * mat2[p][j] over the shared dimension p.", "Skip any mat1[i][p] that is zero: its whole inner contribution vanishes.", "Pre-collect the nonzero entries of each mat2 row to avoid scanning zeros repeatedly."], "statement": "Given two matrices `mat1` of size `m x k` and `mat2` of size `k x n`, return their product,\nan `m x n` matrix where each entry `(i, j)` is the dot product of row `i` of `mat1` with\ncolumn `j` of `mat2`. The inputs are called sparse because most entries are zero, so a good\nsolution skips zero entries instead of multiplying everything blindly.\n\n**Constraints:**\n- `1 <= m, k, n <= 100`\n- `-100 <= mat1[i][j], mat2[i][j] <= 100`.\n", "solution": "## Approach\n\nTriple loop over i, p, j but skip zero entries of mat1 so sparse rows cost almost nothing; accumulate into the answer matrix.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m x k x n)\n- **Space Complexity:** O(m x n)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]:\n m, k, n = len(mat1), len(mat1[0]), len(mat2[0])\n ans = [[0] * n for _ in range(m)]\n for i in range(m):\n for p in range(k):\n if mat1[i][p] == 0:\n continue\n for j in range(n):\n ans[i][j] += mat1[i][p] * mat2[p][j]\n return ans\n```\n", "starter": {"go": "package main\n\nfunc Multiply(mat1 [][]int, mat2 [][]int) [][]int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def multiply(self, mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> multiply(vector<vector<int>>& mat1, vector<vector<int>>& mat2) {\n return {};\n }\n};"}, "fn": "multiply", "params": [{"name": "mat1", "type": "int_array_2d"}, {"name": "mat2", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[1,0,0],[-1,0,3]]", "[[7,0,0],[0,0,0],[0,0,1]]"], ["[[0]]", "[[0]]"], ["[[1,2],[3,4]]", "[[5,6],[7,8]]"], ["[[1,0],[0,1]]", "[[1,2],[3,4]]"], ["[[0,0],[0,0]]", "[[1,2],[3,4]]"], ["[[2]]", "[[3]]"], ["[[1,2,3]]", "[[1],[2],[3]]"], ["[[2,-3,0],[0,0,-1],[0,0,0]]", "[[-1],[-4],[4]]"], ["[[0,0,-5],[0,0,-5],[4,2,0]]", "[[-5,-1,4],[-2,0,-2],[3,0,-1]]"], ["[[0,0,0]]", "[[4],[0],[0]]"], ["[[4],[3]]", "[[0]]"], ["[[0,-2],[0,0]]", "[[0,1,0],[-2,0,0]]"], ["[[0]]", "[[5,2,0]]"], ["[[-1],[0],[0],[0]]", "[[0,3,0]]"], ["[[-2],[0],[0]]", "[[-2,0,4]]"], ["[[0,0]]", "[[5,0,0,3],[0,-3,0,0]]"], ["[[0,-5,-1,0],[0,0,0,0],[1,0,0,0]]", "[[5],[0],[0],[-5]]"], ["[[1],[0],[0],[0]]", "[[0]]"], ["[[4,1],[0,2]]", "[[-4,0],[1,-2]]"], ["[[-5,0,0]]", "[[-5],[0],[0]]"], ["[[0]]", "[[3]]"], ["[[3,-1,-3,-4],[0,-3,-2,-1],[-3,-2,-1,4]]", "[[2,0,0],[-4,0,3],[-5,-1,1],[0,0,0]]"], ["[[0]]", "[[0]]"], ["[[-5,0,0,-1]]", "[[0,0,1,1],[0,0,1,-1],[0,0,-2,1],[0,2,-3,0]]"], ["[[3,0,0]]", "[[-3,0,0],[1,0,0],[0,0,0]]"], ["[[-5,4,0],[0,0,0],[3,0,0]]", "[[0,0,5],[0,0,0],[3,0,0]]"], ["[[-1,-4,-4,-1]]", "[[0,0,0],[0,0,1],[3,2,-3],[-4,1,1]]"], ["[[4],[0]]", "[[2,3]]"]], "expected": [[[7, 0, 0], [-7, 0, 3]], [[0]], [[19, 22], [43, 50]], [[1, 2], [3, 4]], [[0, 0], [0, 0]], [[6]], [[14]], [[10], [-4], [0]], [[-15, 0, 5], [-15, 0, 5], [-24, -4, 12]], [[0]], [[0], [0]], [[4, 0, 0], [0, 0, 0]], [[0, 0, 0]], [[0, -3, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], [[4, 0, -8], [0, 0, 0], [0, 0, 0]], [[0, 0, 0, 0]], [[0], [0], [5]], [[0], [0], [0], [0]], [[-15, -2], [2, -4]], [[25]], [[0]], [[25, 3, -6], [22, 2, -11], [7, 1, -7]], [[0]], [[0, -2, -2, -5]], [[-9, 0, 0]], [[0, 0, -25], [0, 0, 0], [0, 0, 15]], [[-8, -9, 7]], [[8, 12], [0, 0]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "763", "slug": "special-binary-string", "id": 763, "title": "Special Binary String", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/special-binary-string/", "examples": [{"input": "s = \"11011000\"", "output": "\"11100100\"", "explanation": "Neighboring balanced blocks are swapped recursively to maximize the order."}, {"input": "s = \"10\"", "output": "\"10\""}, {"input": "s = \"1010\"", "output": "\"1010\"", "explanation": "Identical primitives keep the string unchanged."}], "hints": ["Split s into primitives: scan with a balance counter and cut whenever it returns to zero.", "A primitive has the form 1 + inner + 0; recurse on the inner part, rewrap it, and collect all primitives.", "Sort the rewrapped primitives in descending order and concatenate them."], "statement": "A binary string is called *balanced* when it holds equally many `1`s and `0`s and every prefix contains at least as many `1`s as `0`s.\n\nYou are given a balanced string `s`. One move picks two neighboring non-empty balanced blocks that sit directly next to each other inside `s` and exchanges their order. After any number of such moves, return the lexicographically greatest string you can obtain (`1` sorts after `0`).\n\n**Constraints:**\n- `1 <= s.length <= 50`\n- `s[i]` is `'0'` or `'1'`\n- `s` is balanced\n", "solution": "## Approach\n\nCut the string into primitives by tracking the running balance of ones minus zeros; each time it returns to zero a primitive ends. Every primitive looks like 1 plus an inner balanced part plus 0, so recurse on the inner part and rewrap it. Sorting the rewrapped primitives from largest to smallest and joining them gives the best global order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) in the worst case from sorting at each level, with n at most 50.\n- **Space Complexity:** O(n^2) for recursion and intermediate strings.\n\n## Implementation\n\n```python\nclass Solution:\n def makeLargestSpecial(self, s: str) -> str:\n parts = []\n bal = 0\n start = 0\n for i, c in enumerate(s):\n bal += 1 if c == '1' else -1\n if bal == 0:\n inner = s[start + 1:i]\n parts.append(\"1\" + self.makeLargestSpecial(inner) + \"0\")\n start = i + 1\n parts.sort(reverse=True)\n return \"\".join(parts)\n```\n", "starter": {"go": "package main\n\nfunc MakeLargestSpecial(s string) string {\n return \"\"\n}", "python": "class Solution:\n def makeLargestSpecial(self, s: str) -> str:\n pass\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string makeLargestSpecial(string s) {\n return \"\";\n }\n};"}, "fn": "makeLargestSpecial", "params": [{"name": "s", "type": "string"}], "outputType": "string", "tests": [["11011000"], ["10"], ["1010"], ["1100"], ["111000"], ["11110000"], ["110110"], ["101010"], ["11101000"], ["11010100"], ["11100100"], ["101100"], ["11001010"], ["110010"], ["1110001010"], ["10101100"], ["11001100"], ["111100001010"], ["1010101010"], ["1110010010"], ["110100"], ["11100010"], ["1011001100"], ["1111010000"], ["110011001010"], ["10111000"], ["111000111000"], ["110110001010"]], "expected": ["11100100", "10", "1010", "1100", "111000", "11110000", "", "101010", "11101000", "11010100", "11100100", "110010", "11001010", "110010", "1110001010", "11001010", "11001100", "111100001010", "1010101010", "1110010010", "110100", "11100010", "1100110010", "1111010000", "110011001010", "11100010", "111000111000", "111001001010"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "267", "slug": "spiral-matrix-ii", "id": 267, "title": "Spiral Matrix II", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/spiral-matrix-ii/", "examples": [{"input": "n = 3", "output": "[[1,2,3],[8,9,4],[7,6,5]]", "explanation": "The outer ring is 1-8 clockwise and the center is 9."}, {"input": "n = 1", "output": "[[1]]", "explanation": "A 1x1 grid holds only the value 1."}, {"input": "n = 2", "output": "[[1,2],[4,3]]", "explanation": "Going right gives 1, 2, then down to 3 and left to 4."}], "hints": ["Maintain four boundaries (top, bottom, left, right) and fill one edge at a time, shrinking the boundary after each edge.", "Place numbers 1 to n*n in order; the loop ends when the top boundary passes the bottom or the left passes the right."], "statement": "Build an `n` by `n` grid filled with the numbers `1` through `n * n` in clockwise spiral order, starting at the top-left corner and initially moving right.\n\nWalk right along the top edge, down the right edge, left along the bottom edge, and up the left side, then continue inward layer by layer until every cell holds a value. The first number placed is `1` and each subsequent cell gets the next integer.\n\n**Constraints:**\n- `1 <= n <= 20`\n", "solution": "## Approach\n\nFill the grid layer by layer with four moving boundaries. Write the top row left to right, the right column top to bottom, the bottom row right to left, and the left column bottom to top, shrinking each boundary after its edge is done. Repeat until the boundaries cross.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), one write per cell.\n- **Space Complexity:** O(1), excluding the output matrix.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def generateMatrix(self, n: int) -> List[List[int]]:\n m = [[0] * n for _ in range(n)]\n top, bottom, left, right = 0, n - 1, 0, n - 1\n num = 1\n while top <= bottom and left <= right:\n for j in range(left, right + 1):\n m[top][j] = num\n num += 1\n top += 1\n for i in range(top, bottom + 1):\n m[i][right] = num\n num += 1\n right -= 1\n if top <= bottom:\n for j in range(right, left - 1, -1):\n m[bottom][j] = num\n num += 1\n bottom -= 1\n if left <= right:\n for i in range(bottom, top - 1, -1):\n m[i][left] = num\n num += 1\n left += 1\n return m\n```\n", "starter": {"go": "package main\n\nfunc GenerateMatrix(n int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def generateMatrix(self, n: int) -> List[List[int]]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> generateMatrix(int n) {\n return {};\n }\n};"}, "fn": "generateMatrix", "params": [{"name": "n", "type": "int"}], "outputType": "int_array_2d", "tests": [["3"], ["1"], ["2"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["11"], ["12"], ["13"], ["14"], ["15"], ["16"], ["17"], ["18"], ["19"], ["20"], ["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"], ["10"], ["15"], ["20"]], "expected": [[[1, 2, 3], [8, 9, 4], [7, 6, 5]], [[1]], [[1, 2], [4, 3]], [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]], [[1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9]], [[1, 2, 3, 4, 5, 6], [20, 21, 22, 23, 24, 7], [19, 32, 33, 34, 25, 8], [18, 31, 36, 35, 26, 9], [17, 30, 29, 28, 27, 10], [16, 15, 14, 13, 12, 11]], [[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19, 18, 17, 16, 15, 14, 13]], [[1, 2, 3, 4, 5, 6, 7, 8], [28, 29, 30, 31, 32, 33, 34, 9], [27, 48, 49, 50, 51, 52, 35, 10], [26, 47, 60, 61, 62, 53, 36, 11], [25, 46, 59, 64, 63, 54, 37, 12], [24, 45, 58, 57, 56, 55, 38, 13], [23, 44, 43, 42, 41, 40, 39, 14], [22, 21, 20, 19, 18, 17, 16, 15]], [[1, 2, 3, 4, 5, 6, 7, 8, 9], [32, 33, 34, 35, 36, 37, 38, 39, 10], [31, 56, 57, 58, 59, 60, 61, 40, 11], [30, 55, 72, 73, 74, 75, 62, 41, 12], [29, 54, 71, 80, 81, 76, 63, 42, 13], [28, 53, 70, 79, 78, 77, 64, 43, 14], [27, 52, 69, 68, 67, 66, 65, 44, 15], [26, 51, 50, 49, 48, 47, 46, 45, 16], [25, 24, 23, 22, 21, 20, 19, 18, 17]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [36, 37, 38, 39, 40, 41, 42, 43, 44, 11], [35, 64, 65, 66, 67, 68, 69, 70, 45, 12], [34, 63, 84, 85, 86, 87, 88, 71, 46, 13], [33, 62, 83, 96, 97, 98, 89, 72, 47, 14], [32, 61, 82, 95, 100, 99, 90, 73, 48, 15], [31, 60, 81, 94, 93, 92, 91, 74, 49, 16], [30, 59, 80, 79, 78, 77, 76, 75, 50, 17], [29, 58, 57, 56, 55, 54, 53, 52, 51, 18], [28, 27, 26, 25, 24, 23, 22, 21, 20, 19]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 12], [39, 72, 73, 74, 75, 76, 77, 78, 79, 50, 13], [38, 71, 96, 97, 98, 99, 100, 101, 80, 51, 14], [37, 70, 95, 112, 113, 114, 115, 102, 81, 52, 15], [36, 69, 94, 111, 120, 121, 116, 103, 82, 53, 16], [35, 68, 93, 110, 119, 118, 117, 104, 83, 54, 17], [34, 67, 92, 109, 108, 107, 106, 105, 84, 55, 18], [33, 66, 91, 90, 89, 88, 87, 86, 85, 56, 19], [32, 65, 64, 63, 62, 61, 60, 59, 58, 57, 20], [31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 13], [43, 80, 81, 82, 83, 84, 85, 86, 87, 88, 55, 14], [42, 79, 108, 109, 110, 111, 112, 113, 114, 89, 56, 15], [41, 78, 107, 128, 129, 130, 131, 132, 115, 90, 57, 16], [40, 77, 106, 127, 140, 141, 142, 133, 116, 91, 58, 17], [39, 76, 105, 126, 139, 144, 143, 134, 117, 92, 59, 18], [38, 75, 104, 125, 138, 137, 136, 135, 118, 93, 60, 19], [37, 74, 103, 124, 123, 122, 121, 120, 119, 94, 61, 20], [36, 73, 102, 101, 100, 99, 98, 97, 96, 95, 62, 21], [35, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 22], [34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 14], [47, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 60, 15], [46, 87, 120, 121, 122, 123, 124, 125, 126, 127, 98, 61, 16], [45, 86, 119, 144, 145, 146, 147, 148, 149, 128, 99, 62, 17], [44, 85, 118, 143, 160, 161, 162, 163, 150, 129, 100, 63, 18], [43, 84, 117, 142, 159, 168, 169, 164, 151, 130, 101, 64, 19], [42, 83, 116, 141, 158, 167, 166, 165, 152, 131, 102, 65, 20], [41, 82, 115, 140, 157, 156, 155, 154, 153, 132, 103, 66, 21], [40, 81, 114, 139, 138, 137, 136, 135, 134, 133, 104, 67, 22], [39, 80, 113, 112, 111, 110, 109, 108, 107, 106, 105, 68, 23], [38, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 24], [37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 15], [51, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 65, 16], [50, 95, 132, 133, 134, 135, 136, 137, 138, 139, 140, 107, 66, 17], [49, 94, 131, 160, 161, 162, 163, 164, 165, 166, 141, 108, 67, 18], [48, 93, 130, 159, 180, 181, 182, 183, 184, 167, 142, 109, 68, 19], [47, 92, 129, 158, 179, 192, 193, 194, 185, 168, 143, 110, 69, 20], [46, 91, 128, 157, 178, 191, 196, 195, 186, 169, 144, 111, 70, 21], [45, 90, 127, 156, 177, 190, 189, 188, 187, 170, 145, 112, 71, 22], [44, 89, 126, 155, 176, 175, 174, 173, 172, 171, 146, 113, 72, 23], [43, 88, 125, 154, 153, 152, 151, 150, 149, 148, 147, 114, 73, 24], [42, 87, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 74, 25], [41, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 26], [40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 16], [55, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 70, 17], [54, 103, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 116, 71, 18], [53, 102, 143, 176, 177, 178, 179, 180, 181, 182, 183, 154, 117, 72, 19], [52, 101, 142, 175, 200, 201, 202, 203, 204, 205, 184, 155, 118, 73, 20], [51, 100, 141, 174, 199, 216, 217, 218, 219, 206, 185, 156, 119, 74, 21], [50, 99, 140, 173, 198, 215, 224, 225, 220, 207, 186, 157, 120, 75, 22], [49, 98, 139, 172, 197, 214, 223, 222, 221, 208, 187, 158, 121, 76, 23], [48, 97, 138, 171, 196, 213, 212, 211, 210, 209, 188, 159, 122, 77, 24], [47, 96, 137, 170, 195, 194, 193, 192, 191, 190, 189, 160, 123, 78, 25], [46, 95, 136, 169, 168, 167, 166, 165, 164, 163, 162, 161, 124, 79, 26], [45, 94, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 80, 27], [44, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 28], [43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 17], [59, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 75, 18], [58, 111, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 125, 76, 19], [57, 110, 155, 192, 193, 194, 195, 196, 197, 198, 199, 200, 167, 126, 77, 20], [56, 109, 154, 191, 220, 221, 222, 223, 224, 225, 226, 201, 168, 127, 78, 21], [55, 108, 153, 190, 219, 240, 241, 242, 243, 244, 227, 202, 169, 128, 79, 22], [54, 107, 152, 189, 218, 239, 252, 253, 254, 245, 228, 203, 170, 129, 80, 23], [53, 106, 151, 188, 217, 238, 251, 256, 255, 246, 229, 204, 171, 130, 81, 24], [52, 105, 150, 187, 216, 237, 250, 249, 248, 247, 230, 205, 172, 131, 82, 25], [51, 104, 149, 186, 215, 236, 235, 234, 233, 232, 231, 206, 173, 132, 83, 26], [50, 103, 148, 185, 214, 213, 212, 211, 210, 209, 208, 207, 174, 133, 84, 27], [49, 102, 147, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 134, 85, 28], [48, 101, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 86, 29], [47, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 30], [46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 18], [63, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 80, 19], [62, 119, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 134, 81, 20], [61, 118, 167, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 180, 135, 82, 21], [60, 117, 166, 207, 240, 241, 242, 243, 244, 245, 246, 247, 218, 181, 136, 83, 22], [59, 116, 165, 206, 239, 264, 265, 266, 267, 268, 269, 248, 219, 182, 137, 84, 23], [58, 115, 164, 205, 238, 263, 280, 281, 282, 283, 270, 249, 220, 183, 138, 85, 24], [57, 114, 163, 204, 237, 262, 279, 288, 289, 284, 271, 250, 221, 184, 139, 86, 25], [56, 113, 162, 203, 236, 261, 278, 287, 286, 285, 272, 251, 222, 185, 140, 87, 26], [55, 112, 161, 202, 235, 260, 277, 276, 275, 274, 273, 252, 223, 186, 141, 88, 27], [54, 111, 160, 201, 234, 259, 258, 257, 256, 255, 254, 253, 224, 187, 142, 89, 28], [53, 110, 159, 200, 233, 232, 231, 230, 229, 228, 227, 226, 225, 188, 143, 90, 29], [52, 109, 158, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 144, 91, 30], [51, 108, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 92, 31], [50, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 32], [49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], [68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 19], [67, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 85, 20], [66, 127, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 143, 86, 21], [65, 126, 179, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 193, 144, 87, 22], [64, 125, 178, 223, 260, 261, 262, 263, 264, 265, 266, 267, 268, 235, 194, 145, 88, 23], [63, 124, 177, 222, 259, 288, 289, 290, 291, 292, 293, 294, 269, 236, 195, 146, 89, 24], [62, 123, 176, 221, 258, 287, 308, 309, 310, 311, 312, 295, 270, 237, 196, 147, 90, 25], [61, 122, 175, 220, 257, 286, 307, 320, 321, 322, 313, 296, 271, 238, 197, 148, 91, 26], [60, 121, 174, 219, 256, 285, 306, 319, 324, 323, 314, 297, 272, 239, 198, 149, 92, 27], [59, 120, 173, 218, 255, 284, 305, 318, 317, 316, 315, 298, 273, 240, 199, 150, 93, 28], [58, 119, 172, 217, 254, 283, 304, 303, 302, 301, 300, 299, 274, 241, 200, 151, 94, 29], [57, 118, 171, 216, 253, 282, 281, 280, 279, 278, 277, 276, 275, 242, 201, 152, 95, 30], [56, 117, 170, 215, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 202, 153, 96, 31], [55, 116, 169, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 154, 97, 32], [54, 115, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, 155, 98, 33], [53, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 34], [52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 20], [71, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 90, 21], [70, 135, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 152, 91, 22], [69, 134, 191, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 206, 153, 92, 23], [68, 133, 190, 239, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 252, 207, 154, 93, 24], [67, 132, 189, 238, 279, 312, 313, 314, 315, 316, 317, 318, 319, 290, 253, 208, 155, 94, 25], [66, 131, 188, 237, 278, 311, 336, 337, 338, 339, 340, 341, 320, 291, 254, 209, 156, 95, 26], [65, 130, 187, 236, 277, 310, 335, 352, 353, 354, 355, 342, 321, 292, 255, 210, 157, 96, 27], [64, 129, 186, 235, 276, 309, 334, 351, 360, 361, 356, 343, 322, 293, 256, 211, 158, 97, 28], [63, 128, 185, 234, 275, 308, 333, 350, 359, 358, 357, 344, 323, 294, 257, 212, 159, 98, 29], [62, 127, 184, 233, 274, 307, 332, 349, 348, 347, 346, 345, 324, 295, 258, 213, 160, 99, 30], [61, 126, 183, 232, 273, 306, 331, 330, 329, 328, 327, 326, 325, 296, 259, 214, 161, 100, 31], [60, 125, 182, 231, 272, 305, 304, 303, 302, 301, 300, 299, 298, 297, 260, 215, 162, 101, 32], [59, 124, 181, 230, 271, 270, 269, 268, 267, 266, 265, 264, 263, 262, 261, 216, 163, 102, 33], [58, 123, 180, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 164, 103, 34], [57, 122, 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 104, 35], [56, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 36], [55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 21], [75, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 95, 22], [74, 143, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 161, 96, 23], [73, 142, 203, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 219, 162, 97, 24], [72, 141, 202, 255, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 269, 220, 163, 98, 25], [71, 140, 201, 254, 299, 336, 337, 338, 339, 340, 341, 342, 343, 344, 311, 270, 221, 164, 99, 26], [70, 139, 200, 253, 298, 335, 364, 365, 366, 367, 368, 369, 370, 345, 312, 271, 222, 165, 100, 27], [69, 138, 199, 252, 297, 334, 363, 384, 385, 386, 387, 388, 371, 346, 313, 272, 223, 166, 101, 28], [68, 137, 198, 251, 296, 333, 362, 383, 396, 397, 398, 389, 372, 347, 314, 273, 224, 167, 102, 29], [67, 136, 197, 250, 295, 332, 361, 382, 395, 400, 399, 390, 373, 348, 315, 274, 225, 168, 103, 30], [66, 135, 196, 249, 294, 331, 360, 381, 394, 393, 392, 391, 374, 349, 316, 275, 226, 169, 104, 31], [65, 134, 195, 248, 293, 330, 359, 380, 379, 378, 377, 376, 375, 350, 317, 276, 227, 170, 105, 32], [64, 133, 194, 247, 292, 329, 358, 357, 356, 355, 354, 353, 352, 351, 318, 277, 228, 171, 106, 33], [63, 132, 193, 246, 291, 328, 327, 326, 325, 324, 323, 322, 321, 320, 319, 278, 229, 172, 107, 34], [62, 131, 192, 245, 290, 289, 288, 287, 286, 285, 284, 283, 282, 281, 280, 279, 230, 173, 108, 35], [61, 130, 191, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 174, 109, 36], [60, 129, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 110, 37], [59, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 38], [58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39]], [[1]], [[1, 2], [4, 3]], [[1, 2, 3], [8, 9, 4], [7, 6, 5]], [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]], [[1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], [13, 12, 11, 10, 9]], [[1, 2, 3, 4, 5, 6], [20, 21, 22, 23, 24, 7], [19, 32, 33, 34, 25, 8], [18, 31, 36, 35, 26, 9], [17, 30, 29, 28, 27, 10], [16, 15, 14, 13, 12, 11]], [[1, 2, 3, 4, 5, 6, 7], [24, 25, 26, 27, 28, 29, 8], [23, 40, 41, 42, 43, 30, 9], [22, 39, 48, 49, 44, 31, 10], [21, 38, 47, 46, 45, 32, 11], [20, 37, 36, 35, 34, 33, 12], [19, 18, 17, 16, 15, 14, 13]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [36, 37, 38, 39, 40, 41, 42, 43, 44, 11], [35, 64, 65, 66, 67, 68, 69, 70, 45, 12], [34, 63, 84, 85, 86, 87, 88, 71, 46, 13], [33, 62, 83, 96, 97, 98, 89, 72, 47, 14], [32, 61, 82, 95, 100, 99, 90, 73, 48, 15], [31, 60, 81, 94, 93, 92, 91, 74, 49, 16], [30, 59, 80, 79, 78, 77, 76, 75, 50, 17], [29, 58, 57, 56, 55, 54, 53, 52, 51, 18], [28, 27, 26, 25, 24, 23, 22, 21, 20, 19]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 16], [55, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 70, 17], [54, 103, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 116, 71, 18], [53, 102, 143, 176, 177, 178, 179, 180, 181, 182, 183, 154, 117, 72, 19], [52, 101, 142, 175, 200, 201, 202, 203, 204, 205, 184, 155, 118, 73, 20], [51, 100, 141, 174, 199, 216, 217, 218, 219, 206, 185, 156, 119, 74, 21], [50, 99, 140, 173, 198, 215, 224, 225, 220, 207, 186, 157, 120, 75, 22], [49, 98, 139, 172, 197, 214, 223, 222, 221, 208, 187, 158, 121, 76, 23], [48, 97, 138, 171, 196, 213, 212, 211, 210, 209, 188, 159, 122, 77, 24], [47, 96, 137, 170, 195, 194, 193, 192, 191, 190, 189, 160, 123, 78, 25], [46, 95, 136, 169, 168, 167, 166, 165, 164, 163, 162, 161, 124, 79, 26], [45, 94, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 80, 27], [44, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 28], [43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 21], [75, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 95, 22], [74, 143, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 161, 96, 23], [73, 142, 203, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 219, 162, 97, 24], [72, 141, 202, 255, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 269, 220, 163, 98, 25], [71, 140, 201, 254, 299, 336, 337, 338, 339, 340, 341, 342, 343, 344, 311, 270, 221, 164, 99, 26], [70, 139, 200, 253, 298, 335, 364, 365, 366, 367, 368, 369, 370, 345, 312, 271, 222, 165, 100, 27], [69, 138, 199, 252, 297, 334, 363, 384, 385, 386, 387, 388, 371, 346, 313, 272, 223, 166, 101, 28], [68, 137, 198, 251, 296, 333, 362, 383, 396, 397, 398, 389, 372, 347, 314, 273, 224, 167, 102, 29], [67, 136, 197, 250, 295, 332, 361, 382, 395, 400, 399, 390, 373, 348, 315, 274, 225, 168, 103, 30], [66, 135, 196, 249, 294, 331, 360, 381, 394, 393, 392, 391, 374, 349, 316, 275, 226, 169, 104, 31], [65, 134, 195, 248, 293, 330, 359, 380, 379, 378, 377, 376, 375, 350, 317, 276, 227, 170, 105, 32], [64, 133, 194, 247, 292, 329, 358, 357, 356, 355, 354, 353, 352, 351, 318, 277, 228, 171, 106, 33], [63, 132, 193, 246, 291, 328, 327, 326, 325, 324, 323, 322, 321, 320, 319, 278, 229, 172, 107, 34], [62, 131, 192, 245, 290, 289, 288, 287, 286, 285, 284, 283, 282, 281, 280, 279, 230, 173, 108, 35], [61, 130, 191, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 174, 109, 36], [60, 129, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 110, 37], [59, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 38], [58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "876", "slug": "spiral-matrix-iii", "id": 876, "title": "Spiral Matrix III", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/spiral-matrix-iii/", "examples": [{"input": "rows = 1, cols = 4, rStart = 0, cStart = 0", "output": "[[0,0],[0,1],[0,2],[0,3]]", "explanation": "The single row is swept from left to right."}, {"input": "rows = 3, cols = 3, rStart = 0, cStart = 0", "output": "[[0,0],[0,1],[1,1],[1,0],[0,2],[1,2],[2,2],[2,1],[2,0]]", "explanation": "The spiral first covers the top-left 2x2 block, then reaches out to the remaining border cells."}, {"input": "rows = 2, cols = 2, rStart = 1, cStart = 1", "output": "[[1,1],[1,0],[0,0],[0,1]]", "explanation": "Starting from the bottom-right corner, the spiral curls around the other three cells."}], "hints": ["Walk with directions east, south, west, north repeating, using step lengths 1, 1, 2, 2, 3, 3, ...", "Record a cell only when it lands inside the grid, and stop once rows * cols cells are recorded."], "statement": "A grid has `rows` rows and `cols` columns. You start on cell `(rStart, cStart)` and walk in an ever-widening rectangular spiral: one step east, one step south, two steps west, two steps north, three steps east, three steps south, and so on, adding one to the step length after every two turns. Some of these steps leave the grid; ignore those cells but keep walking.\n\nCollect the grid cells in the exact order first visited, stopping once every cell of the grid has been collected. Return that list of `[row, col]` pairs.\n\n**Constraints:**\n- `1 <= rows, cols <= 100`\n- `0 <= rStart < rows`\n- `0 <= cStart < cols`\n", "solution": "## Approach\n\nSimulate the expanding spiral directly. Cycle through the headings east, south, west, north while the stride grows as 1, 1, 2, 2, 3, 3, and so on. Each visited position that falls inside the grid is appended to the answer; positions outside are simply skipped. The walk ends as soon as `rows * cols` cells have been gathered.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(max(rows, cols)^2) steps in the worst case, since the spiral may wander outside before covering everything; each step is O(1).\n- **Space Complexity:** O(rows * cols) for the collected coordinates.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def spiralMatrixIII(self, rows: int, cols: int, rStart: int, cStart: int) -> List[List[int]]:\n dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)]\n res = [[rStart, cStart]]\n r, c, d, step = rStart, cStart, 0, 1\n while len(res) < rows * cols:\n for _ in range(2):\n for _ in range(step):\n r += dirs[d][0]\n c += dirs[d][1]\n if 0 <= r < rows and 0 <= c < cols:\n res.append([r, c])\n if len(res) >= rows * cols:\n break\n d = (d + 1) % 4\n if len(res) >= rows * cols:\n break\n step += 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc SpiralMatrixIII(rows int, cols int, rStart int, cStart int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def spiralMatrixIII(self, rows: int, cols: int, rStart: int, cStart: int) -> List[List[int]]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> spiralMatrixIII(int rows, int cols, int rStart, int cStart) {\n return {};\n }\n};"}, "fn": "spiralMatrixIII", "params": [{"name": "rows", "type": "int"}, {"name": "cols", "type": "int"}, {"name": "rStart", "type": "int"}, {"name": "cStart", "type": "int"}], "outputType": "int_array_2d", "tests": [["1", "4", "0", "0"], ["3", "3", "0", "0"], ["2", "2", "1", "1"], ["5", "6", "1", "4"], ["1", "1", "0", "0"], ["1", "5", "0", "2"], ["5", "1", "2", "0"], ["3", "3", "1", "1"], ["4", "4", "0", "0"], ["4", "4", "3", "3"], ["2", "3", "0", "2"], ["3", "2", "2", "0"], ["1", "10", "0", "0"], ["10", "1", "9", "0"], ["5", "5", "2", "2"], ["3", "5", "1", "2"], ["6", "3", "0", "1"], ["2", "2", "0", "0"], ["2", "2", "0", "1"], ["2", "2", "1", "0"], ["3", "4", "2", "3"], ["4", "3", "1", "1"], ["7", "7", "3", "3"], ["1", "3", "0", "1"], ["3", "1", "1", "0"], ["4", "5", "0", "4"], ["5", "4", "4", "0"], ["2", "5", "1", "2"]], "expected": [[[0, 0], [0, 1], [0, 2], [0, 3]], [[0, 0], [0, 1], [1, 1], [1, 0], [0, 2], [1, 2], [2, 2], [2, 1], [2, 0]], [[1, 1], [1, 0], [0, 0], [0, 1]], [[1, 4], [1, 5], [2, 5], [2, 4], [2, 3], [1, 3], [0, 3], [0, 4], [0, 5], [3, 5], [3, 4], [3, 3], [3, 2], [2, 2], [1, 2], [0, 2], [4, 5], [4, 4], [4, 3], [4, 2], [4, 1], [3, 1], [2, 1], [1, 1], [0, 1], [4, 0], [3, 0], [2, 0], [1, 0], [0, 0]], [[0, 0]], [[0, 2], [0, 3], [0, 1], [0, 4], [0, 0]], [[2, 0], [3, 0], [1, 0], [4, 0], [0, 0]], [[1, 1], [1, 2], [2, 2], [2, 1], [2, 0], [1, 0], [0, 0], [0, 1], [0, 2]], [[0, 0], [0, 1], [1, 1], [1, 0], [0, 2], [1, 2], [2, 2], [2, 1], [2, 0], [0, 3], [1, 3], [2, 3], [3, 3], [3, 2], [3, 1], [3, 0]], [[3, 3], [3, 2], [2, 2], [2, 3], [3, 1], [2, 1], [1, 1], [1, 2], [1, 3], [3, 0], [2, 0], [1, 0], [0, 0], [0, 1], [0, 2], [0, 3]], [[0, 2], [1, 2], [1, 1], [0, 1], [1, 0], [0, 0]], [[2, 0], [2, 1], [1, 0], [1, 1], [0, 0], [0, 1]], [[0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9]], [[9, 0], [8, 0], [7, 0], [6, 0], [5, 0], [4, 0], [3, 0], [2, 0], [1, 0], [0, 0]], [[2, 2], [2, 3], [3, 3], [3, 2], [3, 1], [2, 1], [1, 1], [1, 2], [1, 3], [1, 4], [2, 4], [3, 4], [4, 4], [4, 3], [4, 2], [4, 1], [4, 0], [3, 0], [2, 0], [1, 0], [0, 0], [0, 1], [0, 2], [0, 3], [0, 4]], [[1, 2], [1, 3], [2, 3], [2, 2], [2, 1], [1, 1], [0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [2, 4], [2, 0], [1, 0], [0, 0]], [[0, 1], [0, 2], [1, 2], [1, 1], [1, 0], [0, 0], [2, 2], [2, 1], [2, 0], [3, 2], [3, 1], [3, 0], [4, 2], [4, 1], [4, 0], [5, 2], [5, 1], [5, 0]], [[0, 0], [0, 1], [1, 1], [1, 0]], [[0, 1], [1, 1], [1, 0], [0, 0]], [[1, 0], [1, 1], [0, 0], [0, 1]], [[2, 3], [2, 2], [1, 2], [1, 3], [2, 1], [1, 1], [0, 1], [0, 2], [0, 3], [2, 0], [1, 0], [0, 0]], [[1, 1], [1, 2], [2, 2], [2, 1], [2, 0], [1, 0], [0, 0], [0, 1], [0, 2], [3, 2], [3, 1], [3, 0]], [[3, 3], [3, 4], [4, 4], [4, 3], [4, 2], [3, 2], [2, 2], [2, 3], [2, 4], [2, 5], [3, 5], [4, 5], [5, 5], [5, 4], [5, 3], [5, 2], [5, 1], [4, 1], [3, 1], [2, 1], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [6, 5], [6, 4], [6, 3], [6, 2], [6, 1], [6, 0], [5, 0], [4, 0], [3, 0], [2, 0], [1, 0], [0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6]], [[0, 1], [0, 2], [0, 0]], [[1, 0], [2, 0], [0, 0]], [[0, 4], [1, 4], [1, 3], [0, 3], [2, 4], [2, 3], [2, 2], [1, 2], [0, 2], [3, 4], [3, 3], [3, 2], [3, 1], [2, 1], [1, 1], [0, 1], [3, 0], [2, 0], [1, 0], [0, 0]], [[4, 0], [4, 1], [3, 0], [3, 1], [3, 2], [4, 2], [2, 0], [2, 1], [2, 2], [2, 3], [3, 3], [4, 3], [1, 0], [1, 1], [1, 2], [1, 3], [0, 0], [0, 1], [0, 2], [0, 3]], [[1, 2], [1, 3], [1, 1], [0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [1, 0], [0, 0]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "47", "slug": "spiral-matrix", "id": 47, "title": "Spiral Matrix", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/spiral-matrix/", "examples": [{"input": "matrix = [[1,2,3],[4,5,6],[7,8,9]]", "output": "[1,2,3,6,9,8,7,4,5]", "explanation": "Reading the 3\u00d73 matrix in clockwise spiral order gives [1,2,3,6,9,8,7,4,5]."}, {"input": "matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]", "output": "[1,2,3,4,8,12,11,10,9,5,6,7]", "explanation": "Reading the 3\u00d74 matrix in clockwise spiral order gives [1,2,3,4,8,12,11,10,9,5,6,7]."}], "hints": ["Peel the matrix layer by layer using four boundaries (top, bottom, left, right) and traverse in four directions, shrinking the bounds after each side."], "statement": "You receive a rectangular `m x n` table. Collect its entries by walking around the outside clockwise and spiralling inward, and hand back that visiting sequence.\n\n**Constraints:**\n\n- m == matrix.length\n- n == matrix[i].length\n- 1 \u2264 m, n \u2264 10\n- -100 \u2264 matrix[i][j] \u2264 100\n", "solution": "## Approach\n\nTraverse the matrix layer by layer using four boundaries (top, bottom, left, right), shrinking the bounds after each completed direction.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m\u00d7n)\n- **Space Complexity:** O(1) (excluding output)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def spiralOrder(self, matrix: List[List[int]]) -> List[int]:\n res = []\n top, bottom = 0, len(matrix) - 1\n left, right = 0, len(matrix[0]) - 1\n while top <= bottom and left <= right:\n for j in range(left, right + 1):\n res.append(matrix[top][j])\n top += 1\n for i in range(top, bottom + 1):\n res.append(matrix[i][right])\n right -= 1\n if top <= bottom:\n for j in range(right, left - 1, -1):\n res.append(matrix[bottom][j])\n bottom -= 1\n if left <= right:\n for i in range(bottom, top - 1, -1):\n res.append(matrix[i][left])\n left += 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc SpiralOrder(matrix [][]int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def spiralOrder(self, matrix: List[List[int]]) -> List[int]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> spiralOrder(vector<vector<int>>& matrix) {\n return {};\n }\n};"}, "fn": "spiralOrder", "params": [{"name": "matrix", "type": "int_array_2d", "visualizeType": "matrix"}], "outputType": "int_array", "tests": [["[[1,2,3],[4,5,6],[7,8,9]]"], ["[[1,2,3,4],[5,6,7,8],[9,10,11,12]]"], ["[[1]]"], ["[[1,2],[3,4]]"], ["[[2,5],[8,4],[0,-1]]"], ["[[-100]]"], ["[[100]]"], ["[[1,2]]"], ["[[1],[2]]"], ["[[1,2,3]]"], ["[[1],[2],[3]]"], ["[[1,2,3,4,5]]"], ["[[1],[2],[3],[4],[5]]"], ["[[1,2,3],[4,5,6]]"], ["[[1,2],[3,4],[5,6]]"], ["[[1,2,3,4],[5,6,7,8]]"], ["[[1,2],[3,4],[5,6],[7,8]]"], ["[[0,-1,-2],[-3,-4,-5],[-6,-7,-8]]"], ["[[100,99,98],[97,96,95]]"], ["[[-100,0,100],[50,-50,25]]"], ["[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]"], ["[[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]]"], ["[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]"], ["[[5,5,5],[5,5,5]]"], ["[[9,8],[7,6],[5,4],[3,2],[1,0]]"], ["[[1,0,-1,-2],[-3,-4,-5,-6],[-7,-8,-9,-10]]"], ["[[2,4,6],[8,10,12],[14,16,18],[20,22,24]]"], ["[[3,1,4,1],[5,9,2,6]]"], ["[[10,20],[30,40],[50,60],[70,80]]"], ["[[-1,-2,-3,-4],[-5,-6,-7,-8]]"]], "expected": [[1, 2, 3, 6, 9, 8, 7, 4, 5], [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7], [1], [1, 2, 4, 3], [2, 5, 4, -1, 0, 8], [-100], [100], [1, 2], [1, 2], [1, 2, 3], [1, 2, 3], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 6, 5, 4], [1, 2, 4, 6, 5, 3], [1, 2, 3, 4, 8, 7, 6, 5], [1, 2, 4, 6, 8, 7, 5, 3], [0, -1, -2, -5, -8, -7, -6, -3, -4], [100, 99, 98, 95, 96, 97], [-100, 0, 100, 25, -50, 50], [1, 2, 3, 4, 5, 10, 15, 14, 13, 12, 11, 6, 7, 8, 9], [1, 2, 3, 6, 9, 12, 15, 14, 13, 10, 7, 4, 5, 8, 11], [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10], [5, 5, 5, 5, 5, 5], [9, 8, 6, 4, 2, 0, 1, 3, 5, 7], [1, 0, -1, -2, -6, -10, -9, -8, -7, -3, -4, -5], [2, 4, 6, 12, 18, 24, 22, 20, 14, 8, 10, 16], [3, 1, 4, 1, 6, 2, 9, 5], [10, 20, 40, 60, 80, 70, 50, 30], [-1, -2, -3, -4, -8, -7, -6, -5]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "678", "slug": "split-array-into-consecutive-subsequences", "id": 678, "title": "Split Array into Consecutive Subsequences", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/split-array-into-consecutive-subsequences/", "examples": [{"input": "nums = [1,2,3,3,4,5]", "output": "true", "explanation": "Groups [1,2,3] and [3,4,5] each run consecutively with length 3."}, {"input": "nums = [1,2,3,3,4,4,5,5]", "output": "true", "explanation": "Groups [1,2,3,4,5] and [3,4,5] both qualify."}, {"input": "nums = [1,2,3,4,4,5]", "output": "false", "explanation": "The leftover 4 and 5 cannot form a triple without breaking another group."}], "hints": ["Count occurrences of each value first.", "Always try to extend an existing group waiting for the current value before starting a fresh triple.", "Starting a new triple consumes one copy each of v, v+1 and v+2; fail when any is missing."], "statement": "You are given a non-decreasing array `nums`.\n\nDecide whether it can be split into one or more groups such that every group holds at least three numbers and the numbers in each group are consecutive integers (for example [3,4,5]). Every array entry must belong to exactly one group.\n\n**Constraints:**\n- `1 <= nums.length <= 10^4`\n- `-1000 <= nums[i] <= 1000`\n- `nums` is sorted in non-decreasing order.\n", "solution": "## Approach\n\nCount each value. Sweep the sorted array: if some earlier group waits for the current value, extend it; otherwise start a new triple consuming `v`, `v+1`, `v+2`. Missing copies mean the split is impossible. Greedy extension is safe because using a value to continue a group never hurts future triples.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) with hash-table counts.\n- **Space Complexity:** O(n) for the frequency and need tables.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import Counter\nclass Solution:\n def isPossible(self, nums: List[int]) -> bool:\n freq = Counter(nums)\n need = Counter()\n for x in nums:\n if freq[x] == 0:\n continue\n if need[x] > 0:\n need[x] -= 1\n freq[x] -= 1\n need[x + 1] += 1\n else:\n if freq[x + 1] == 0 or freq[x + 2] == 0:\n return False\n freq[x] -= 1\n freq[x + 1] -= 1\n freq[x + 2] -= 1\n need[x + 3] += 1\n return True\n```\n", "starter": {"go": "package main\n\nfunc IsPossible(nums []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def isPossible(self, nums: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool isPossible(vector<int>& nums) {\n return false;\n }\n};"}, "fn": "isPossible", "params": [{"name": "nums", "type": "int_array"}], "outputType": "boolean", "tests": [["[1,2,3,3,4,5]"], ["[1,2,3,3,4,4,5,5]"], ["[1,2,3,4,4,5]"], ["[1,2,3]"], ["[1,2,3,4,5]"], ["[1,2,4,5,6]"], ["[1,1,2,2,3,3]"], ["[1,2,3,4,5,6]"], ["[1,2,3,5,6,7]"], ["[1,2,3,3,4,4,5,5,6,7]"], ["[1,2,3,4]"], ["[1,2]"], ["[1]"], ["[1,2,3,3,3,4,4,5,5]"], ["[2,2,3,3,4,4]"], ["[1,2,3,4,5,5,6,7]"], ["[1,2,3,4,6,7,8]"], ["[0,0,1,1,2,2,3,3,4,4]"], ["[1,2,3,4,5,6,7,8]"], ["[1,3,5]"], ["[1,2,3,4,5,6,7]"], ["[-2,-1,0,1,2]"], ["[1,2,3,3,4,5,6,7,8]"], ["[4,5,6,7,7,8,8,9,10]"], ["[1,2,3,5,5,6,7]"], ["[1,2,3,4,4,5,6,7]"], ["[10,11,12,13,14,15]"], ["[1,2,3,4,5,5,6,6,7,7]"]], "expected": [true, true, false, true, true, false, true, true, true, true, true, false, false, true, true, true, true, true, true, false, true, true, true, true, false, true, true, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "840", "slug": "split-array-into-fibonacci-sequence", "id": 840, "title": "Split Array into Fibonacci Sequence", "difficulty": "Medium", "category": "backtracking", "link": "https://leetcode.com/problems/split-array-into-fibonacci-sequence/", "examples": [{"input": "num = \"1101111\"", "output": "[11,0,11,11]", "explanation": "11+0=11 and 0+11=11."}, {"input": "num = \"11235813\"", "output": "[1,1,2,3,5,8,13]", "explanation": "Each value sums the prior two."}, {"input": "num = \"112358130\"", "output": "[]", "explanation": "No valid partition exists."}], "hints": ["Try every split for the first two numbers (at most 10 digits each given the 32-bit cap), then extend deterministically.", "Reject any piece with a leading zero unless it is exactly '0', and stop when a value exceeds 2147483647.", "Once the first pair is fixed, the rest of the sequence is forced: keep matching the expected sum as a prefix."], "statement": "Break a digit string into a Fibonacci-like list.\n\nA list is Fibonacci-like when it holds at least three numbers, every value fits in a signed 32-bit integer, and each number from the third onward equals the sum of the two before it. Additionally, no number may carry a leading zero unless the number itself is exactly zero.\n\nGiven a string `num` of digits, split it into such a list using every character exactly once in order. Return any valid split, or an empty list when no split works.\n\n**Constraints:**\n- `1 <= num.length <= 200`\n- `num` holds only digits.\n", "solution": "## Approach\n\nFix the first two numbers by trying all plausible lengths (capped by the 32-bit limit and the no-leading-zero rule). From the third value on the sequence is forced: each next entry must equal the sum of the prior two and must appear verbatim at the current position. Depth-first search over the short prefix therefore explores every candidate, backtracking when the forced tail mismatches.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) in the worst case for prefix choices, with linear extension per choice, where n is the digit count.\n- **Space Complexity:** O(n) for the recursion stack and the answer list.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def splitIntoFibonacci(self, num: str) -> List[int]:\n res: List[int] = []\n n = len(num)\n def dfs(pos, cur):\n if pos == n:\n return len(cur) >= 3\n for ln in range(1, 11):\n if pos + ln > n:\n break\n if ln > 1 and num[pos] == '0':\n break\n v = int(num[pos:pos+ln])\n if v > 2**31 - 1:\n break\n if len(cur) >= 2:\n want = cur[-1] + cur[-2]\n if v < want:\n continue\n if v > want:\n break\n cur.append(v)\n if dfs(pos + ln, cur):\n return True\n cur.pop()\n if len(cur) >= 2:\n break\n return False\n if dfs(0, res):\n return res\n return []\n```\n", "starter": {"go": "package main\n\nfunc SplitIntoFibonacci(num string) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def splitIntoFibonacci(self, num: str) -> List[int]:\n return []\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> splitIntoFibonacci(string num) {\n return {};\n }\n};"}, "fn": "splitIntoFibonacci", "params": [{"name": "num", "type": "string"}], "outputType": "int_list", "tests": [["1101111"], ["11235813"], ["112358130"], ["000"], ["0123"], ["101"], ["123456579"], ["1123581321345589144233377"], ["21474836472147483647"], ["0000"], ["10"], ["11"], ["123"], ["321"], ["11112233"], ["011112233"], ["112358"], ["123456789"], ["10112"], ["0123"], ["5511122334"], ["112"], ["100100200"], ["2147483647"], ["00000"], ["12122436"], ["4161416"], ["123581321"]], "expected": [[11, 0, 11, 11], [1, 1, 2, 3, 5, 8, 13], [], [0, 0, 0], [], [1, 0, 1], [123, 456, 579], [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], [], [0, 0, 0, 0], [], [], [1, 2, 3], [], [11, 11, 22, 33], [0, 11, 11, 22, 33], [1, 1, 2, 3, 5, 8], [], [1, 0, 1, 1, 2], [], [], [1, 1, 2], [100, 100, 200], [], [0, 0, 0, 0, 0], [12, 12, 24, 36], [], [1, 2, 3, 5, 8, 13, 21]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "189", "slug": "split-array-largest-sum", "id": 189, "title": "Split Array Largest Sum", "difficulty": "Hard", "category": "binary-search", "link": "https://leetcode.com/problems/split-array-largest-sum/", "examples": [{"input": "nums = [7,2,5,10,8], k = 2", "output": "18", "explanation": "Split into [7,2,5] and [10,8] with largest sum 18."}, {"input": "nums = [1,2,3,4,5], k = 2", "output": "9", "explanation": "Split into [1,2,3] and [4,5]."}], "hints": ["Binary search the answer. Check if you can split into at most k subarrays with sum <= mid."], "statement": "You receive an integer list `nums` and an integer `k`. Cut `nums` into `k` neighbouring blocks that are all non-empty, aiming to push the biggest block total down as far as possible.\n\nHand back that smallest achievable biggest-block total.\n\nA block here means a run of neighbours from the list with no gaps.\n\n**Constraints:**\n- `1 <= nums.length <= 1000`\n- `0 <= nums[i] <= 10^6`\n- `1 <= k <= min(50, nums.length)`\n", "solution": "## Approach\n\nBinary search the minimized largest sum. For a candidate limit, greedily count how many subarrays are needed. Feasible iff that count is at most `k`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log S) where S is the total sum\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def splitArray(self, nums: List[int], k: int) -> int:\n lo, hi = max(nums), sum(nums)\n while lo < hi:\n mid = (lo + hi) // 2\n parts = 1\n cur = 0\n for x in nums:\n if cur + x > mid:\n parts += 1\n cur = 0\n cur += x\n if parts <= k:\n hi = mid\n else:\n lo = mid + 1\n return lo\n```\n", "starter": {"go": "package main\n\nfunc SplitArray(nums []int, k int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def splitArray(self, nums: List[int], k: int) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int splitArray(vector<int>& nums, int k) {\n return 0;\n }\n};"}, "fn": "splitArray", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int", "tests": [["[7,2,5,10,8]", "2"], ["[1,2,3,4,5]", "2"], ["[1,4,4]", "3"], ["[1,2,3,4,5]", "1"], ["[1,2,3,4,5]", "5"], ["[10]", "1"], ["[5,5,5,5]", "2"], ["[1,2,3,4,5,6,7,8,9,10]", "5"], ["[0,0,0,0]", "2"], ["[1000000,1000000]", "1"], ["[0]", "1"], ["[1000000]", "1"], ["[1,1]", "1"], ["[1,1]", "2"], ["[0,1,0]", "2"], ["[0,1,0]", "3"], ["[9,1,1,1]", "2"], ["[1,1,1,9]", "2"], ["[2,3,1,2,4,3]", "3"], ["[10,20,30,40]", "2"], ["[10,20,30,40]", "3"], ["[10,20,30,40]", "4"], ["[5,0,5,0,5]", "2"], ["[5,0,5,0,5]", "4"], ["[1000000,0,1000000]", "2"], ["[8,7,6,5,4,3,2,1]", "4"], ["[1,2,1,2,1,2,1,2]", "3"], ["[50,1,1,1,1,50]", "2"], ["[3,6,7,2,8,1]", "5"], ["[0,0,1,0,0]", "1"]], "expected": [18, 9, 4, 15, 5, 10, 10, 15, 0, 2000000, 0, 1000000, 2, 1, 1, 1, 9, 9, 6, 60, 40, 40, 10, 5, 1000000, 11, 5, 52, 9, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "605", "slug": "split-array-with-equal-sum", "id": 605, "title": "Split Array with Equal Sum", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/split-array-with-equal-sum/", "examples": [{"input": "nums = [1,2,1,2,1,2,1]", "output": "true", "explanation": "Separators at 1,3,5 give four sums of 1."}, {"input": "nums = [1,2,1,2,1,2,1,2]", "output": "false", "explanation": "No valid triple exists."}, {"input": "nums = [0,0,0,0,0,0,0]", "output": "true", "explanation": "Zero blocks everywhere."}], "hints": ["Precompute prefix sums so any block sum is O(1).", "Fix the middle separator j, collect left equal-sum candidates in a set, then test right pairs against it.", "Arrays shorter than 7 can never satisfy the spacing rules."], "statement": "You are given an integer array `nums` of length `n`. Decide whether three separator positions `i < j < k` can carve the array into four blocks with identical totals.\n\nThe separators themselves are discarded: the blocks are `nums[0..i-1]`, `nums[i+1..j-1]`, `nums[j+1..k-1]`, and `nums[k+1..n-1]`. Valid separators must satisfy `0 < i`, `i+1 < j`, `j+1 < k`, and `k < n-1`, so every block holds at least one element.\n\nReturn `true` when such a triple exists, else `false`.\n\n**Constraints:**\n- `1 <= n <= 2000`\n- `-10^6 <= nums[i] <= 10^6`\n", "solution": "## Approach\n\nBuild prefix sums for O(1) interval totals. Try each middle cut j: gather sums where the first two blocks match into a set, then scan right cuts k and succeed when the last two blocks match a value already seen.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) over choices of j with inner scans.\n- **Space Complexity:** O(n) for prefix sums plus the candidate set.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def splitArray(self, nums: List[int]) -> bool:\n n = len(nums)\n if n < 7:\n return False\n s = [0] * (n + 1)\n for i, v in enumerate(nums):\n s[i + 1] = s[i] + v\n for j in range(3, n - 3):\n seen = set()\n for i in range(1, j - 1):\n if s[i] == s[j] - s[i + 1]:\n seen.add(s[i])\n for k in range(j + 2, n - 1):\n if s[n] - s[k + 1] == s[k] - s[j + 1] and (s[n] - s[k + 1]) in seen:\n return True\n return False\n```\n", "starter": {"go": "package main\n\nfunc SplitArray(nums []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def splitArray(self, nums: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool splitArray(vector<int>& nums) {\n return false;\n }\n};"}, "fn": "splitArray", "params": [{"name": "nums", "type": "int_array"}], "outputType": "boolean", "tests": [["[1,2,1,2,1,2,1]"], ["[1,2,1,2,1,2,1,2]"], ["[0,0,0,0,0,0,0]"], ["[1,2,3,4,5,6,7]"], ["[1,1,1,1,1,1,1]"], ["[2,2,2,2,2,2,2]"], ["[1,2,1,3,1,2,1]"], ["[0,1,0,1,0,1,0]"], ["[1,0,1,0,1,0,1]"], ["[3,3,3,3,3,3,3,3,3]"], ["[1,2,3,0,3,2,1]"], ["[4,1,1,1,1,1,4]"], ["[1]"], ["[1,2]"], ["[1,2,3]"], ["[0,0,0,0,0,0,0,0]"], ["[2,1,2,1,2,1,2,1,2]"], ["[5,5,5,0,5,5,5]"], ["[1,1,0,1,1,0,1,1]"], ["[-1,1,-1,1,-1,1,-1]"], ["[10,0,10,0,10,0,10]"], ["[1,2,1,2,1,2,1,2,1]"], ["[0,0,0,0,0,0]"], ["[7,7,7,7,7,7,7]"], ["[1,3,1,3,1,3,1]"], ["[2,0,2,0,2,0,2]"], ["[1,1,1,0,1,1,1,0,1]"], ["[4,4,0,4,4,0,4,4]"]], "expected": [true, false, true, false, true, true, true, true, true, false, false, false, false, false, false, true, false, true, false, true, true, false, false, true, true, true, true, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "803", "slug": "split-array-with-same-average", "id": 803, "title": "Split Array With Same Average", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/split-array-with-same-average/", "examples": [{"input": "nums = [1,2,3,4,5,6,7,8]", "output": "true", "explanation": "Two groups can share the same mean."}, {"input": "nums = [3,1]", "output": "false", "explanation": "No split equalizes the means."}, {"input": "nums = [5,5,5]", "output": "true", "explanation": "Equal values always split."}], "hints": ["Same average for both groups means some subset size k has sum total * k / n with an integer target.", "Track reachable subset sums per cardinality with a set for each k, updating backwards over the numbers.", "Only k up to n / 2 needs checking since complements mirror each other."], "statement": "You receive an integer array `nums`. Decide whether it can be divided into two non-empty groups `A` and `B` that together use every element exactly once and whose arithmetic means are equal.\n\nEqual means imply that some non-empty proper subset has sum `total * k / n`, where `k` is its size and `n` is the full length, so the divisibility condition must hold exactly with integers.\n\n**Constraints:**\n- `1 <= nums.length <= 30`\n- `0 <= nums[i] <= 10^4`\n", "solution": "## Approach\n\nTwo groups share a mean exactly when some proper subset of size `k` sums to `total * k / n`. Maintain for each cardinality the set of reachable sums by scanning numbers backwards, then test each `k` up to half the length for the divisibility condition and membership of the target sum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2 * S), where S is the total sum, bounded by small n (at most 30) and values.\n- **Space Complexity:** O(n * S) for the per-cardinality reachable sets.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def splitArraySameAverage(self, nums: List[int]) -> bool:\n n = len(nums)\n if n == 1:\n return False\n total = sum(nums)\n dp = [set() for _ in range(n // 2 + 1)]\n dp[0].add(0)\n for v in nums:\n for k in range(n // 2, 0, -1):\n for s in list(dp[k - 1]):\n dp[k].add(s + v)\n for k in range(1, n // 2 + 1):\n if (total * k) % n == 0 and (total * k // n) in dp[k]:\n return True\n return False\n```\n", "starter": {"go": "package main\n\nfunc SplitArraySameAverage(nums []int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def splitArraySameAverage(self, nums: List[int]) -> bool:\n return False", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool splitArraySameAverage(vector<int>& nums) {\n return false;\n }\n};"}, "fn": "splitArraySameAverage", "params": [{"name": "nums", "type": "int_array"}], "outputType": "boolean", "tests": [["[1, 2, 3, 4, 5, 6, 7, 8]"], ["[3, 1]"], ["[5, 5, 5]"], ["[1]"], ["[1, 1]"], ["[1, 2]"], ["[2, 2, 2, 2]"], ["[0, 0, 0, 0]"], ["[1, 2, 3, 4]"], ["[4, 4, 4, 4, 4]"], ["[1, 2, 3, 5]"], ["[6, 8, 18, 3, 16, 8, 21, 7, 16, 19]"], ["[5, 3, 11, 19, 2]"], ["[18, 0, 16, 2, 7, 2, 12, 10, 2, 10, 9, 11, 17, 17, 8, 19, 20]"], ["[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"], ["[10, 10, 10, 10]"], ["[1, 2, 3, 4, 5, 6]"], ["[1, 5, 7, 8, 9]"], ["[2, 0, 3, 3, 2, 3, 1, 3]"], ["[60, 30, 5, 9, 20, 30, 74, 25]"], ["[3, 3, 3, 3, 3, 3]"], ["[1, 2, 3, 4, 5, 6, 7]"], ["[10000, 0, 10000, 0]"], ["[1, 1, 1, 1, 1, 1, 1]"], ["[4, 1, 8, 7, 3, 9]"], ["[2, 4, 6, 8, 10]"], ["[0, 5, 5, 0]"], ["[7, 7, 7, 7, 7, 7, 7]"]], "expected": [true, false, true, false, true, false, true, true, true, true, false, true, true, false, true, true, true, true, false, false, true, true, true, true, true, true, true, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "776", "slug": "split-bst", "id": 776, "title": "Split BST", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/split-bst/", "examples": [{"input": "root = [4,2,6,1,3,5,7], target = 2", "output": "[\"[2,1]\",\"[4,3,6,null,null,5,7]\"]", "explanation": "Small keeps 2,1; large keeps 4 with 3 on the left."}, {"input": "root = [1], target = 1", "output": "[\"[1]\",\"[]\"]", "explanation": "Single node goes small."}, {"input": "root = [], target = 0", "output": "[\"[]\",\"[]\"]", "explanation": "Empty splits into two empties."}], "hints": ["Portable adaptation: the pair of trees is returned as two BFS strings [small, large], as in unique-bst-ii.", "Recurse: if root is null return two nulls; if root.val <= target, split the right side and reattach its small half; else split the left side and reattach its large half.", "Serialize each half with BFS (null placeholders, trim trailing nulls); empty trees become []."], "statement": "You are given the root of a binary search tree and an integer `target`. Divide the tree into two subtrees so that every value at most `target` lands in the first part and every larger value lands in the second part, keeping the original ancestor relations wherever possible.\n\nConcretely, split recursively: an empty tree splits into two empty trees; if the root value is at most `target`, its left subtree stays whole and its right subtree is split, reattaching the small half as the new right child; otherwise its right subtree stays whole and its left subtree is split, reattaching the large half as the new left child.\n\nBecause this judge has no pair-of-trees type, the two halves travel as BFS strings (portable adaptation following the unique-bst-ii precedent): return a two-element list `[small, large]` where each entry is the level-order serialization of that half (`[]` for an empty tree, `null` for missing children, trailing nulls trimmed).\n\n**Constraints:**\n- `0 <= nodes <= 50`\n- `-100 <= Node.val <= 100`, all values distinct, BST ordered\n- `-100 <= target <= 100`\n- Outputs are BFS strings parseable as trees\n", "solution": "## Approach\n\nSplit the search tree with recursion that respects the target bound. An empty tree yields two empties; when the root fits the small side, split its right child and graft the small half back as the new right child; otherwise split the left child and graft the large half back as the new left child. Both halves are then encoded with level-order serialization, trimming trailing nulls, so the answer is the pair of BFS strings.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) where n is the node count, visiting each node once plus serialization.\n- **Space Complexity:** O(h) recursion depth for height h, plus O(n) for the queues and strings.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def splitBST(self, root, target: int) -> List[str]:\n def split(node):\n if not node:\n return (None, None)\n if node.val <= target:\n small_r, large = split(node.right)\n node.right = small_r\n return (node, large)\n else:\n small, large_l = split(node.left)\n node.left = large_l\n return (small, node)\n def serialize(node):\n if not node:\n return \"[]\"\n out = []\n q = deque([node])\n while q:\n cur = q.popleft()\n if cur is None:\n out.append(\"null\")\n else:\n out.append(str(cur.val))\n q.append(cur.left)\n q.append(cur.right)\n while out and out[-1] == \"null\":\n out.pop()\n return \"[\" + \",\".join(out) + \"]\"\n small, large = split(root)\n return [serialize(small), serialize(large)]\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 SplitBST(root *TreeNode, target int) []string {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import List\nclass Solution:\n def splitBST(self, root, target: int) -> List[str]:\n return []\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};\n*/\n#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> splitBST(TreeNode* root, int target) {\n return {};\n }\n};"}, "fn": "splitBST", "params": [{"name": "root", "type": "tree_node"}, {"name": "target", "type": "int"}], "outputType": "string_list", "tests": [["[4,2,6,1,3,5,7]", "2"], ["[1]", "1"], ["[]", "0"], ["[4,2,6,1,3,5,7]", "4"], ["[4,2,6,1,3,5,7]", "1"], ["[4,2,6,1,3,5,7]", "7"], ["[4,2,6,1,3,5,7]", "0"], ["[2,1,3]", "2"], ["[5,3,7,2,4,6,8]", "5"], ["[5,3,7,2,4,6,8]", "3"], ["[10,5,15,3,7,null,18]", "7"], ["[10,5,15,3,7,null,18]", "15"], ["[1,null,2]", "1"], ["[1,null,2]", "2"], ["[3,1,4,null,2]", "2"], ["[50,30,70,20,40,60,80]", "40"], ["[50,30,70,20,40,60,80]", "20"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "6"], ["[1]", "0"], ["[1]", "2"], ["[2,1]", "1"], ["[2,1]", "2"], ["[4,2,6,1,3,5,7]", "3"], ["[4,2,6,1,3,5,7]", "5"], ["[4,2,6,1,3,5,7]", "6"], ["[20,10,30,5,15,25,35]", "15"], ["[20,10,30,5,15,25,35]", "25"], ["[6,2,8,0,4,7,9,null,null,3,5]", "4"]], "expected": [["[2,1]", "[4,3,6,null,null,5,7]"], ["[1]", "[]"], ["[]", "[]"], ["[4,2,null,1,3]", "[6,5,7]"], ["[1]", "[4,2,6,null,3,5,7]"], ["[4,2,6,1,3,5,7]", "[]"], ["[]", "[4,2,6,1,3,5,7]"], ["[2,1]", "[3]"], ["[5,3,null,2,4]", "[7,6,8]"], ["[3,2]", "[5,4,7,null,null,6,8]"], ["[5,3,7]", "[10,null,15,null,18]"], ["[10,5,15,3,7]", "[18]"], ["[1]", "[2]"], ["[1,null,2]", "[]"], ["[1,null,2]", "[3,null,4]"], ["[30,20,40]", "[50,null,70,60,80]"], ["[20]", "[50,30,70,null,40,60,80]"], ["[3,1,6,null,null,4]", "[8,7,10,null,null,null,14,13]"], ["[]", "[1]"], ["[1]", "[]"], ["[1]", "[2]"], ["[2,1]", "[]"], ["[2,1,3]", "[4,null,6,5,7]"], ["[4,2,5,1,3]", "[6,null,7]"], ["[4,2,6,1,3,5]", "[7]"], ["[10,5,15]", "[20,null,30,25,35]"], ["[20,10,25,5,15]", "[30,null,35]"], ["[2,0,4,null,null,3]", "[6,5,8,null,null,7,9]"]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "611", "slug": "split-concatenated-strings", "id": 611, "title": "Split Concatenated Strings", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/split-concatenated-strings/", "examples": [{"input": "strs = [\"abc\",\"xyz\"]", "output": "\"zyxcba\"", "explanation": "Reverse both then cut at z."}, {"input": "strs = [\"abc\"]", "output": "\"cba\"", "explanation": "Best rotation of the reversed loop."}, {"input": "strs = [\"ab\",\"cd\"]", "output": "\"dcba\""}], "hints": ["For every string except the one holding the cut, the better of it and its reversal is always optimal, so normalise those first.", "Fix which original string contains the cut, build the middle from the other normalised strings, then try every split of the cut string in both orientations.", "Compare all candidates and keep the lexicographic maximum."], "statement": "You are given an array of strings `strs`. You will build a circular loop by concatenating the strings in their given order, but before joining you may flip any individual string (write it backwards) or keep it as is.\n\nOnce the loop is fixed, choose any cut position inside it and straighten the circle into a linear string beginning at the cut. Among every choice of flips and every cut, return the lexicographically largest stringobtainable. (Compare strings character by character with usual alphabet order.)\n\n**Constraints:**\n- `1 <= strs.length <= 1000`\n- `1 <= strs[i].length <= 1000`\n- `strs[i]` holds lowercase English letters\n- Total characters across `strs` fit comfortably for quadratic scanning\n", "solution": "## Approach\n\nNormalise each string to the larger of itself and its reversal, since non-cut strings always prefer the larger orientation. Then treat each position i as the cut holder: join the remaining normalised strings as the middle, and try every rotation of strs[i] in both forward and reversed forms, keeping the lexicographic best.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(L^2) where L is total characters.\n- **Space Complexity:** O(L) for candidate strings.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def splitLoopedString(self, strs: List[str]) -> str:\n strs = [s[::-1] if s[::-1] > s else s for s in strs]\n ans = \"\".join(strs)\n for i, s in enumerate(strs):\n t = \"\".join(strs[i + 1:]) + \"\".join(strs[:i])\n for j in range(len(s)):\n a, b = s[j:], s[:j]\n ans = max(ans, a + t + b)\n ans = max(ans, b[::-1] + t + a[::-1])\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SplitLoopedString(strs []string) string {\n \n}", "python": "from typing import List\nclass Solution:\n def splitLoopedString(self, strs: List[str]) -> str:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string splitLoopedString(vector<string>& strs) {\n return \"\";\n }\n};"}, "fn": "splitLoopedString", "params": [{"name": "strs", "type": "string_array"}], "outputType": "string", "tests": [["[\"abc\",\"xyz\"]"], ["[\"abc\"]"], ["[\"ab\",\"cd\"]"], ["[\"a\"]"], ["[\"ab\",\"c\"]"], ["[\"xyz\",\"abc\"]"], ["[\"aaa\",\"aaa\"]"], ["[\"ab\",\"ba\"]"], ["[\"abc\",\"def\",\"ghi\"]"], ["[\"z\",\"a\",\"b\"]"], ["[\"hello\",\"world\"]"], ["[\"a\",\"b\",\"c\"]"], ["[\"cba\",\"abc\"]"], ["[\"ab\",\"cd\",\"ef\"]"], ["[\"qwerty\",\"abc\"]"], ["[\"zzz\",\"aaa\"]"], ["[\"ab\",\"xy\",\"cd\"]"], ["[\"mn\",\"op\",\"qr\"]"], ["[\"a\",\"bb\",\"ccc\"]"], ["[\"abcde\"]"], ["[\"edcba\",\"abcde\"]"], ["[\"ab\",\"bc\",\"cd\"]"], ["[\"zyx\",\"wvu\"]"], ["[\"foo\",\"bar\"]"], ["[\"ab\",\"cd\",\"ef\",\"gh\"]"], ["[\"x\",\"y\",\"z\"]"], ["[\"abac\",\"caba\"]"], ["[\"aaaa\",\"bbbb\"]"]], "expected": ["zyxcba", "cba", "dcba", "a", "cba", "zyxcba", "aaaaaa", "bbaa", "ihgcbafed", "zab", "worldolleh", "cab", "ccbaab", "febadc", "ytrewqcba", "zzzaaa", "yxdcba", "rqnmpo", "cccabb", "edcba", "eedcbaabcd", "dcbacb", "zyxwvu", "roofba", "hgbadcfe", "zxy", "ccabaaba", "bbbbaaaa"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "732", "slug": "split-linked-list-in-parts", "id": 732, "title": "Split Linked List in Parts", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/split-linked-list-in-parts/", "examples": [{"input": "head = [1,2,3], k = 5", "output": "[[1],[2],[3],[],[]]", "explanation": "Three values across five groups leave the last two groups empty."}, {"input": "head = [1,2,3,4,5,6,7,8,9,10], k = 3", "output": "[[1,2,3,4],[5,6,7],[8,9,10]]", "explanation": "Sizes are 4, 3, 3 with the extra value placed in the first group."}, {"input": "head = [1,2,3,4], k = 2", "output": "[[1,2],[3,4]]"}], "hints": ["Count the values first to get n, then each group holds either n / k or n / k + 1 values.", "The first n % k groups are the larger ones; walk the chain and cut each group by setting the tail's next pointer to null.", "When k exceeds n, emit one single-value group per value and empty groups for the remainder."], "statement": "You are given the head of a singly linked list holding `n` values and an integer `k`. Your task is to divide the list into `k` consecutive groups.\n\nFollow these rules when describing the groups:\n\n- Every value of the original list appears in exactly one group, and the groups preserve the original order.\n- The groups should be as close in size as possible: any two groups differ in length by at most one.\n- Groups at the front get the extra values. In other words, if `n` does not divide evenly, the first `n % k` groups each hold one additional node.\n- When there are more groups than values, the trailing groups are empty.\n\nReturn the `k` groups in order, where each group is represented by the head of its chain (an empty group is represented by an empty chain).\n\n**Constraints:**\n- `0 <= n <= 1000`\n- `1 <= k <= 50`\n- `0 <= Node.val <= 1000`\n", "solution": "## Approach\n\nCount the chain once to learn its length `n`. Every group receives `n / k` values, and the first `n % k` groups receive one additional value. Walk the chain a second time, cutting each group off by nulling the tail link. Positions beyond the values stay empty.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of values. Two linear passes cover counting and cutting.\n- **Space Complexity:** O(k) for the array of group heads, besides the output chains themselves.\n\n## Implementation\n\n```python\nfrom typing import List, Optional\nclass Solution:\n def splitListToParts(self, head, k: int):\n n = 0\n p = head\n while p:\n n += 1\n p = p.next\n base, extra = divmod(n, k)\n ans = []\n cur = head\n for i in range(k):\n size = base + (1 if i < extra else 0)\n ans.append(cur)\n for _ in range(size - 1 if size else 0):\n cur = cur.next\n if cur:\n nxt = cur.next\n cur.next = None\n cur = nxt\n return ans\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 SplitListToParts(head *ListNode, k int) []*ListNode {\n return nil\n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nfrom typing import List, Optional\nclass Solution:\n def splitListToParts(self, head, k: int):\n pass\n", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<ListNode*> splitListToParts(ListNode* head, int k) {\n return {};\n }\n};"}, "fn": "splitListToParts", "params": [{"name": "head", "type": "list_node"}, {"name": "k", "type": "int"}], "outputType": "list_node_array", "tests": [["[1,2,3]", "5"], ["[1,2,3,4,5,6,7,8,9,10]", "3"], ["[1,2,3,4]", "2"], ["[1]", "1"], ["[1]", "5"], ["[]", "3"], ["[1,2]", "2"], ["[1,2]", "5"], ["[1,2,3,4,5]", "1"], ["[1,2,3,4,5]", "2"], ["[1,2,3,4,5]", "5"], ["[1,2,3,4,5]", "6"], ["[1,2,3,4,5,6,7]", "3"], ["[5,5,5,5]", "3"], ["[0,1,2,3,4,5,6,7,8,9]", "4"], ["[1,2,3,4,5,6]", "4"], ["[1000,0,1000,0]", "3"], ["[1,2,3,4,5,6,7,8]", "3"], ["[1,2,3,4,5,6,7,8,9]", "4"], ["[42]", "50"], ["[1,2,3,4,5,6,7,8,9,10,11]", "5"], ["[9,8,7,6,5,4,3,2,1]", "2"], ["[1,1,1,1,1,1,1]", "7"], ["[1,1,1,1,1,1,1]", "8"], ["[3,1,4,1,5,9,2,6]", "5"], ["[10,20,30,40,50,60]", "3"], ["[7,7,7]", "1"], ["[2,4,6,8,10,12,14]", "6"]], "expected": [[[1], [2], [3], null, null], [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]], [[1, 2], [3, 4]], [[1]], [[1], null, null, null, null], [null, null, null], [[1], [2]], [[1], [2], null, null, null], [[1, 2, 3, 4, 5]], [[1, 2, 3], [4, 5]], [[1], [2], [3], [4], [5]], [[1], [2], [3], [4], [5], null], [[1, 2, 3], [4, 5], [6, 7]], [[5, 5], [5], [5]], [[0, 1, 2], [3, 4, 5], [6, 7], [8, 9]], [[1, 2], [3, 4], [5], [6]], [[1000, 0], [1000], [0]], [[1, 2, 3], [4, 5, 6], [7, 8]], [[1, 2, 3], [4, 5], [6, 7], [8, 9]], [[42], null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null], [[1, 2, 3], [4, 5], [6, 7], [8, 9], [10, 11]], [[9, 8, 7, 6, 5], [4, 3, 2, 1]], [[1], [1], [1], [1], [1], [1], [1]], [[1], [1], [1], [1], [1], [1], [1], null], [[3, 1], [4, 1], [5, 9], [2], [6]], [[10, 20], [30, 40], [50, 60]], [[7, 7, 7]], [[2, 4], [6], [8], [10], [12], [14]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "186", "slug": "sqrtx", "id": 186, "title": "Sqrt(x)", "difficulty": "Easy", "category": "binary-search", "link": "https://leetcode.com/problems/sqrtx/", "examples": [{"input": "x = 4", "output": "2", "explanation": "The square root of 4 is 2."}, {"input": "x = 8", "output": "2", "explanation": "The square root of 8 is 2.82842..., rounded down to 2."}, {"input": "x = 1", "output": "1", "explanation": "The square root of 1 is 1."}], "hints": ["Binary-search the answer in [0, x]: for mid, compare mid with x / mid instead of mid * mid to avoid overflow.", "When mid <= x / mid, mid is feasible and the answer is at least mid; otherwise it is smaller.", "Handle x = 0 and x = 1 as direct answers."], "statement": "You receive a non-negative integer `x`. Work out the integer portion of its square root \u2014 that is, the greatest non-negative whole number whose square stays at or below `x`.\n\nDo not call any power, exponent, or root helper supplied by the language.\n\n**Constraints:**\n\n- `0 <= x <= 2^31 - 1`\n", "solution": "## Approach\n\nBinary-search the square root in `[1, x/2]` (for `x >= 2`). For a candidate\n`mid`, compare `mid` with `x / mid` instead of `mid * mid` to avoid\noverflow. When `mid <= x / mid`, `mid` is feasible and we try larger values;\notherwise we try smaller ones.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log x)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nclass Solution:\n def mySqrt(self, x: int) -> int:\n if x < 2:\n return x\n left, right, ans = 1, x // 2, 1\n while left <= right:\n mid = left + (right - left) // 2\n if mid <= x // mid:\n ans = mid\n left = mid + 1\n else:\n right = mid - 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MySqrt(x int) int {\n return 0\n}", "python": "class Solution:\n def mySqrt(self, x: int) -> int:\n return 0\n", "cpp": "class Solution {\npublic:\n int mySqrt(int x) {\n return 0;\n }\n};"}, "fn": "mySqrt", "params": [{"name": "x", "type": "int"}], "outputType": "int", "tests": [["4"], ["8"], ["1"], ["0"], ["2"], ["3"], ["9"], ["15"], ["16"], ["2147395599"], ["2147483647"], ["1000000"], ["999999999"], ["101"], ["1002001"], ["25"], ["5"], ["10"], ["24"], ["26"], ["99"], ["100"], ["1024"], ["65535"], ["65536"], ["2147395600"], ["2147395601"], ["1073741824"], ["2000000000"], ["99980001"]], "expected": [2, 2, 1, 0, 1, 1, 3, 3, 4, 46339, 46340, 1000, 31622, 10, 1001, 5, 2, 3, 4, 5, 9, 10, 32, 255, 256, 46340, 46340, 32768, 44721, 9999], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "962", "slug": "squares-of-a-sorted-array", "id": 962, "title": "Squares of a Sorted Array", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/squares-of-a-sorted-array/", "examples": [{"input": "nums = [-4,-1,0,3,10]", "output": "[0,1,9,16,100]", "explanation": "Squaring gives [16,1,0,9,100]; sorting increasingly yields [0,1,9,16,100]."}, {"input": "nums = [-7,-3,2,3,11]", "output": "[4,9,9,49,121]", "explanation": "Squares [49,9,4,9,121] sorted give [4,9,9,49,121]."}], "hints": ["Squaring is symmetric around zero, so the largest square sits at one of the two ends.", "Use two pointers at both ends, repeatedly emitting the larger square into the answer from back to front."], "statement": "You are given an integer array `nums` already ordered from smallest to largest. It may contain negative values.\n\nSquare every entry and return the results ordered from smallest to largest.\n\n**Constraints:**\n- `1 <= nums.length <= 10000`\n- `-10000 <= nums[i] <= 10000`\n- `nums` is sorted in non-decreasing order.\n", "solution": "## Approach\n\nBecause the input is sorted, the largest square must come from one of the two ends: the most negative value or the most positive one. Place two pointers at both ends and repeatedly compare their squares, writing the larger one into the answer from back to front and advancing the winning pointer. This merges the two monotone square sequences without an extra sort.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of nums. Each position is visited once.\n- **Space Complexity:** O(n) for the output array (O(1) extra besides it).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def sortedSquares(self, nums: List[int]) -> List[int]:\n n = len(nums)\n ans = [0] * n\n lo, hi = 0, n - 1\n for p in range(n - 1, -1, -1):\n lq = nums[lo] * nums[lo]\n hq = nums[hi] * nums[hi]\n if lq > hq:\n ans[p] = lq\n lo += 1\n else:\n ans[p] = hq\n hi -= 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc SortedSquares(nums []int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def sortedSquares(self, nums: List[int]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> sortedSquares(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "sortedSquares", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_array", "tests": [["[-4,-1,0,3,10]"], ["[-7,-3,2,3,11]"], ["[-5,-3,-2,-1]"], ["[1,2,3,4,5]"], ["[0]"], ["[-1]"], ["[1]"], ["[-2,0]"], ["[0,2]"], ["[-10000,10000]"], ["[-3,-2,-1,0,1,2,3]"], ["[-10,-5,0,5,10]"], ["[-1,0,1]"], ["[-4,-4,-4]"], ["[4,4,4]"], ["[-6,-4,-1,2,5]"], ["[-9,-8,7,8]"], ["[-2,-1,1,2]"], ["[-100,-50,0,50,100]"], ["[0,1,2,3]"], ["[-3,0,3]"], ["[-2,2]"], ["[-5,4,3,2,1,0]"], ["[-8,-3,0,1,9]"], ["[2,3,5,7,11,13]"], ["[-11,-9,-7,1,4]"], ["[-1,2]"], ["[-10000,-9999,9999,10000]"]], "expected": [[0, 1, 9, 16, 100], [4, 9, 9, 49, 121], [1, 4, 9, 25], [1, 4, 9, 16, 25], [0], [1], [1], [0, 4], [0, 4], [100000000, 100000000], [0, 1, 1, 4, 4, 9, 9], [0, 25, 25, 100, 100], [0, 1, 1], [16, 16, 16], [16, 16, 16], [1, 4, 16, 25, 36], [49, 64, 64, 81], [1, 1, 4, 4], [0, 2500, 2500, 10000, 10000], [0, 1, 4, 9], [0, 9, 9], [4, 4], [0, 1, 4, 9, 16, 25], [0, 1, 9, 64, 81], [4, 9, 25, 49, 121, 169], [1, 16, 49, 81, 121], [1, 4], [99980001, 99980001, 100000000, 100000000]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "623", "slug": "squirrel-simulation", "id": 623, "title": "Squirrel Simulation", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/squirrel-simulation/", "examples": [{"input": "height = 5, width = 7, tree = [2,2], squirrel = [4,4], nuts = [[3,0],[2,5]]", "output": "12", "explanation": "Round trips cost 12 and no first pick saves extra."}, {"input": "height = 1, width = 3, tree = [0,1], squirrel = [0,0], nuts = [[0,2]]", "output": "3", "explanation": "Fetch over distance 2, carry home over distance 1."}, {"input": "height = 4, width = 4, tree = [0,0], squirrel = [3,3], nuts = [[1,1],[2,2]]", "output": "10", "explanation": "Round trips cost 12; fetching (2,2) first saves 2."}], "hints": ["Sum twice the tree-to-nut Manhattan distance over all nuts as the baseline.", "Choosing nut i first replaces one tree leg with a squirrel leg, changing the total by dist(squirrel,i) - dist(tree,i).", "Take the minimum such adjustment over all nuts and add it to the baseline."], "statement": "A squirrel must carry each nut back to its tree on a grid where movement costs the Manhattan distance. The tree stands at `tree`, the squirrel starts at `squirrel`, and the nuts lie at the positions in `nuts`. The grid size (`height` rows, `width` columns) only bounds the coordinates.\n\nCarrying one nut home is a round trip from the tree, except the very first nut, which the squirrel fetches starting from its own position instead of the tree. So the total equals twice every tree-to-nut distance, adjusted once by picking the first nut that saves the most: the one minimizing `dist(squirrel, nut) - dist(tree, nut)`.\n\n**Constraints:**\n- `1 <= height, width <= 100`\n- `1 <= nuts.length <= 3000`\n- All positions lie inside the grid.\n", "solution": "## Approach\n\nEvery nut except possibly the first costs a full round trip from the tree, giving a baseline of twice each tree-to-nut Manhattan distance. Fetching nut `i` first instead swaps one tree leg for the squirrel-to-nut leg, shifting the total by `dist(squirrel, i) - dist(tree, i)`. Evaluating that shift for every nut and keeping the smallest yields the optimal total.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(t), where t is the number of nuts.\n- **Space Complexity:** O(1) extra.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def minDistance(self, height: int, width: int, tree: List[int], squirrel: List[int], nuts: List[List[int]]) -> int:\n def dist(a, b):\n return abs(a[0] - b[0]) + abs(a[1] - b[1])\n total = 0\n best = float(\"inf\")\n for nut in nuts:\n d = dist(tree, nut)\n total += 2 * d\n best = min(best, dist(squirrel, nut) - d)\n return total + best\n```\n", "starter": {"go": "package main\n\nfunc MinDistance(height int, width int, tree []int, squirrel []int, nuts [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minDistance(self, height: int, width: int, tree: List[int], squirrel: List[int], nuts: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int minDistance(int height, int width, vector<int>& tree, vector<int>& squirrel, vector<vector<int>>& nuts) {\n return 0;\n }\n};"}, "fn": "minDistance", "params": [{"name": "height", "type": "int"}, {"name": "width", "type": "int"}, {"name": "tree", "type": "int_array"}, {"name": "squirrel", "type": "int_array"}, {"name": "nuts", "type": "int_array_2d"}], "outputType": "int", "tests": [["5", "7", "[2,2]", "[4,4]", "[[3,0],[2,5]]"], ["1", "3", "[0,1]", "[0,0]", "[[0,2]]"], ["4", "4", "[0,0]", "[3,3]", "[[1,1],[2,2]]"], ["5", "5", "[0,0]", "[0,0]", "[[4,4]]"], ["5", "5", "[2,2]", "[2,2]", "[[0,0],[4,4]]"], ["3", "3", "[1,1]", "[0,0]", "[[0,2],[2,0]]"], ["10", "10", "[5,5]", "[0,0]", "[[9,9]]"], ["2", "2", "[0,0]", "[1,1]", "[[0,1],[1,0]]"], ["6", "6", "[3,3]", "[0,5]", "[[1,1],[4,4],[2,5]]"], ["6", "5", "[0, 3]", "[4, 4]", "[[1, 4], [4, 0], [5, 3], [2, 3]]"], ["8", "9", "[5, 7]", "[5, 5]", "[[7, 0], [7, 5], [5, 3], [1, 0], [6, 4]]"], ["9", "7", "[7, 5]", "[5, 5]", "[[5, 4], [0, 6]]"], ["5", "7", "[1, 0]", "[2, 6]", "[[4, 2], [3, 6], [2, 1], [1, 1]]"], ["8", "10", "[5, 3]", "[2, 2]", "[[7, 3], [5, 2]]"], ["3", "7", "[1, 3]", "[2, 3]", "[[2, 2]]"], ["6", "9", "[2, 5]", "[1, 5]", "[[0, 0], [0, 1], [5, 4], [3, 7], [1, 0]]"], ["3", "10", "[0, 2]", "[0, 8]", "[[1, 1], [0, 9], [2, 8]]"], ["4", "10", "[0, 7]", "[1, 1]", "[[1, 8], [0, 8], [0, 2], [1, 9]]"], ["8", "3", "[7, 0]", "[5, 1]", "[[2, 1]]"], ["8", "9", "[0, 8]", "[6, 2]", "[[5, 3], [3, 3]]"], ["9", "5", "[3, 0]", "[7, 0]", "[[0, 3], [1, 4], [7, 4]]"], ["9", "8", "[2, 1]", "[0, 4]", "[[8, 6], [5, 5]]"], ["9", "3", "[8, 2]", "[8, 0]", "[[7, 1]]"], ["8", "9", "[0, 2]", "[6, 6]", "[[4, 2]]"], ["9", "2", "[8, 1]", "[5, 1]", "[[7, 1], [7, 0], [2, 1], [1, 0], [8, 0]]"], ["4", "2", "[1, 1]", "[1, 0]", "[[3, 1]]"], ["5", "8", "[4, 4]", "[0, 5]", "[[2, 6], [3, 7], [1, 5], [0, 7], [3, 5]]"], ["9", "7", "[7, 1]", "[4, 6]", "[[5, 4], [7, 5]]"]], "expected": [12, 3, 10, 16, 16, 8, 26, 4, 17, 29, 62, 20, 25, 8, 3, 51, 28, 19, 9, 28, 36, 35, 4, 10, 33, 5, 37, 16], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "923", "slug": "stamping-the-sequence", "id": 923, "title": "Stamping The Sequence", "difficulty": "Hard", "category": "string", "link": "https://leetcode.com/problems/stamping-the-sequence/", "examples": [{"input": "stamp = \"abc\", target = \"ababc\"", "output": "[0,2]", "explanation": "Stamp at 2 (\"??abc\"), then at 0 (\"ababc\")."}, {"input": "stamp = \"abca\", target = \"aabcaca\"", "output": "[3,0,1]", "explanation": "One valid build order."}, {"input": "stamp = \"abc\", target = \"acabc\"", "output": "[]", "explanation": "No order can create that middle character."}], "hints": ["Think in reverse: from the target, turn stamp-matching windows into wildcards.", "A window is erasable when every non-wildcard matches the stamp and at least one cell is still concrete.", "Reverse the erasure order to obtain a forward stamping sequence; failure to erase everything means impossible."], "statement": "You start from a blank row of `'?'` characters with the same length as `target`. Stamping with `stamp` at position `i` overwrites that segment with the stamp text. Repeating stamps in some order must produce `target`.\n\nReturn any stamp index sequence (at most `10 * target.length` moves) that builds `target`, or an empty array when impossible. The checker replays your moves rather than demanding one exact order.\n\n**Constraints:**\n- `1 <= stamp.length, target.length <= 100`\n- Both strings use lowercase English letters.\n\nAdaptation: the result uses `int_array`; an empty array signals impossibility, and any valid build is accepted.\n", "solution": "## Approach\n\nWork backwards from `target` to all question marks. A window can be erased when it matches the stamp except for already erased cells and contains at least one unerased cell. Repeatedly erase such windows, recording each position; if no window applies before everything is erased, the task is impossible. Reversing the recorded order gives a forward build.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * (n - m)) in the worst case, with n the target length and m the stamp length. Each pass scans all windows.\n- **Space Complexity:** O(n) for the mutable copy and bookkeeping.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def movesToStamp(self, stamp: str, target: str) -> List[int]:\n m, n = len(stamp), len(target)\n if m > n:\n return []\n t = list(target)\n res = []\n vis = [False] * n\n stars = 0\n while stars < n:\n changed = False\n for i in range(n - m + 1):\n if vis[i]:\n continue\n match = 0\n ok = True\n for k in range(m):\n if t[i + k] == '?':\n continue\n if t[i + k] != stamp[k]:\n ok = False\n break\n match += 1\n if not ok or match == 0:\n continue\n vis[i] = True\n changed = True\n res.append(i)\n for k in range(m):\n if t[i + k] != '?':\n t[i + k] = '?'\n stars += 1\n if stars == n:\n break\n if not changed:\n return []\n res.reverse()\n return res\n```\n", "starter": {"go": "package main\n\nfunc MovesToStamp(stamp string, target string) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def movesToStamp(self, stamp: str, target: str) -> List[int]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> movesToStamp(string stamp, string target) {\n return {};\n }\n};"}, "fn": "movesToStamp", "params": [{"name": "stamp", "type": "string"}, {"name": "target", "type": "string"}], "outputType": "int_array", "tests": [["abc", "ababc"], ["abca", "aabcaca"], ["abc", "acabc"], ["a", "a"], ["a", "aa"], ["a", "b"], ["ab", "abab"], ["ab", "ba"], ["abc", "abc"], ["abc", "ababcabc"], ["abca", "abca"], ["ffebb", "ffebb"], ["oz", "ozoz"], ["abc", "aabc"], ["ab", "aab"], ["a", "aaa"], ["aa", "aaa"], ["ab", "abb"], ["abcde", "abc"], ["abcdef", "abc"], ["xy", "xyxyxy"], ["de", "abcde"], ["l", "l"], ["ab", "ababab"], ["ab", "ababa"], ["abc", "abcabc"], ["abcd", "abcdbcd"], ["z", "zzzz"]], "expected": [[0, 2], [0, 3, 1], [], [0], [1, 0], [], [2, 0], [], [0], [0, 5, 2], [0], [0], [2, 0], [0, 1], [0, 1], [2, 1, 0], [1, 0], [1, 0], [], [], [4, 2, 0], [], [0], [4, 2, 0], [], [3, 0], [3, 0], [3, 2, 1, 0]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "706", "slug": "stickers-to-spell-word", "id": 706, "title": "Stickers to Spell Word", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/stickers-to-spell-word/", "examples": [{"input": "stickers = [\"with\",\"example\",\"science\"], target = \"thehat\"", "output": "3", "explanation": "Three sheets cover all letters."}, {"input": "stickers = [\"notice\",\"possible\"], target = \"basicbasic\"", "output": "-1", "explanation": "Letter 'c' never appears."}, {"input": "stickers = [\"these\",\"guess\",\"about\",\"garden\",\"him\"], target = \"atomher\"", "output": "3", "explanation": "Three sheets suffice."}], "hints": ["Count letters (26 slots) for every sticker and for the target; only the overlap matters.", "Search over subsets of target positions with memoization: always cover the first uncovered letter to prune the branching.", "If no sticker holds a needed letter, the answer is -1."], "statement": "You own endless copies of several sticker sheets. Each sheet carries a lowercase word; cutting a sheet yields its letters for reuse, and sheets may be reused any number of times. Given the list `stickers` and a goal word `target`, determine the smallest number of sheets needed to assemble `target`. Cutting extra unused letters is allowed, but every letter of `target` must be covered. Return `-1` when the goal cannot be formed.\n\n**Constraints:**\n- `1 <= stickers.length <= 50`\n- `1 <= stickers[i].length <= 10`\n- `1 <= target.length <= 15`\n- All words use lowercase English letters.\n", "solution": "## Approach\n\nTurn every sticker into a 26-letter frequency table and memoize the best cost for each subset of target positions (bitmask). The recursion always fixes the first uncovered position, then tries only stickers containing that letter, greedily consuming matching letters to reach a new mask. A quick alphabet check reports impossible goals early. The mask covering everything costs zero; other masks take one plus the best successor.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(2^m * S * m), where m is the target length (at most 15) and S the sticker count.\n- **Space Complexity:** O(2^m) memo states.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def minStickers(self, stickers: List[str], target: str) -> int:\n m = len(target)\n counts = [[0]*26 for _ in stickers]\n for i, s in enumerate(stickers):\n for c in s:\n counts[i][ord(c)-97] += 1\n has = [False]*26\n for co in counts:\n for j in range(26):\n if co[j]:\n has[j] = True\n for c in target:\n if not has[ord(c)-97]:\n return -1\n from functools import lru_cache\n INF = 10**9\n @lru_cache(None)\n def dfs(mask):\n if mask == (1 << m) - 1:\n return 0\n first = next(i for i in range(m) if not (mask >> i) & 1)\n best = INF\n for co in counts:\n if co[ord(target[first])-97] == 0:\n continue\n rem = co[:]\n nmask = mask\n for i in range(m):\n if (nmask >> i) & 1:\n continue\n c = ord(target[i])-97\n if rem[c] > 0:\n rem[c] -= 1\n nmask |= (1 << i)\n if nmask == mask:\n continue\n sub = dfs(nmask)\n if sub < INF:\n best = min(best, 1 + sub)\n return best\n ans = dfs(0)\n return -1 if ans >= INF else ans\n```\n", "starter": {"go": "package main\n\nfunc MinStickers(stickers []string, target string) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def minStickers(self, stickers: List[str], target: str) -> int:\n return 0\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int minStickers(vector<string>& stickers, string target) {\n return 0;\n }\n};"}, "fn": "minStickers", "params": [{"name": "stickers", "type": "string_array"}, {"name": "target", "type": "string"}], "outputType": "int", "tests": [["['with', 'example', 'science']", "thehat"], ["['notice', 'possible']", "basicbasic"], ["['these', 'guess', 'about', 'garden', 'him']", "atomher"], ["['a', 'b', 'c']", "abc"], ["['ab', 'bc']", "abc"], ["['ab', 'bc']", "abcd"], ["['aaaa', 'bbbb']", "aabb"], ["['aaaa', 'bbbb']", "aaabbb"], ["['hello', 'world']", "helloworld"], ["['one', 'two', 'three']", "onetwo"], ["['abc', 'def']", "abcdef"], ["['abc', 'def']", "abcabc"], ["['a']", "aaaaa"], ["['ab', 'ba']", "ababab"], ["['xyz']", "abc"], ["['fresh', 'cheese', 'sandwich']", "cheese"], ["['aaaaa', 'bbbbb', 'ccccc']", "abc"], ["['aaaaa', 'bbbbb']", "ababa"], ["['hat', 'that', 'the']", "thethehat"], ["['control', 'heart', 'three']", "thethe"], ["['a', 'aa', 'aaa']", "aaaaaa"], ["['word', 'world', 'hold']", "helloworld"], ["['cat', 'dog', 'bird']", "catdog"], ["['cat', 'dog']", "catcatdog"], ["['ab', 'cd', 'ef']", "abcdef"], ["['ab', 'cd']", "aabbccdd"], ["['solo']", "solo"], ["['solo']", "olos"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "235", "slug": "stone-game-ii", "id": 235, "title": "Stone Game II", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/stone-game-ii/", "examples": [{"input": "piles = [2,7,9,4,4]", "output": "10", "explanation": "If Alice takes one pile at the beginning, Bob takes two piles, then Alice takes 2 piles again. Alice can get 2 + 4 + 4 = 10 piles in total. If Alice takes two piles at the beginning, then Bob can take three piles, and Alice can get 2 + 7 = 9 piles in total. If Alice takes three piles at the beginning, then Bob takes all the four remaining piles, and Alice can get 9 piles in total. So the maximum Alice can get is 10."}, {"input": "piles = [1,2,3,4,5,100]", "output": "104", "explanation": ""}], "hints": ["Use dynamic programming: the states are (i, m) for the answer of piles[i:] given m.", "If 2*m >= n - i the current player can take all remaining piles. Otherwise try every X in 1..2*m and let the opponent start at i + X with M = max(m, X), keeping the take that maximizes suffix[i] - opponent's score."], "statement": "Alice and Bob play another take-away contest on a row of piles, where `piles[i]` gives the stone count of the `i`-th pile, a positive integer. Whoever gathers the most stones by the end wins.\n\nAlice opens and the two alternate moves.\n\nA move always consumes piles from the front of what is left. If `M` is the current limit, the player selects some `X` with `1 <= X <= 2M` and collects the first `X` piles. Afterwards the limit becomes `M = max(M, X)`. The limit starts at `M = 1`.\n\nRemoval continues until no pile remains.\n\nBoth competitors choose optimally. Return the largest total Alice can finish with.\n\n**Constraints:**\n- 1 \u2264 piles.length \u2264 100\n- 1 \u2264 piles[i] \u2264 10<sup>4</sup>\n", "solution": "## Approach\n\nUse dynamic programming over states `(i, m)` where `dp[i][m]` is the maximum number of stones the current player can collect from `piles[i:]` given the current `M = m`. If `2 * m >= n - i`, the current player can take every remaining pile, so `dp[i][m] = suffix[i]`. Otherwise, for every `X` from 1 to `2 * m`, the player takes the next `X` piles (`suffix[i] - suffix[i + X]`) and hands the game to the opponent at `i + X` with `M = max(m, X)`. The player's gain is `suffix[i] - dp[i + X][max(m, X)]`, and we keep the maximum over all `X`.\n\nThe answer is `dp[0][1]`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) states times O(n) moves each, i.e. O(n^3) (n <= 100, so this is fine).\n- **Space Complexity:** O(n^2) for the dp table.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def stoneGameII(self, piles: List[int]) -> int:\n n = len(piles)\n suffix = [0] * (n + 1)\n for i in range(n - 1, -1, -1):\n suffix[i] = suffix[i + 1] + piles[i]\n\n dp = [[0] * (n + 1) for _ in range(n + 1)]\n for i in range(n - 1, -1, -1):\n for m in range(1, n + 1):\n if 2 * m >= n - i:\n dp[i][m] = suffix[i]\n else:\n best = 0\n for x in range(1, 2 * m + 1):\n best = max(best, suffix[i] - dp[i + x][max(m, x)])\n dp[i][m] = best\n return dp[0][1]\n```", "starter": {"go": "package main\n\nfunc StoneGameII(piles []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def stoneGameII(self, piles: List[int]) -> int:\n ", "cpp": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n int stoneGameII(vector<int>& piles) {\n \n }\n};"}, "fn": "stoneGameII", "params": [{"name": "piles", "type": "int_array"}], "outputType": "int", "tests": [["[2,7,9,4,4]"], ["[1,2,3,4,5,100]"], ["[1]"], ["[2,2]"], ["[1,1,1]"], ["[5,4,3]"], ["[10000]"], ["[3,3,3,3,3]"], ["[1,2,3,4]"], ["[8,6,8,6,8,6]"], ["[10,20,30,40,50,60,70]"], ["[1,1,1,1,1,1,1,1,1,1]"], ["[9,8,7,6,5,4,3,2,1]"], ["[6,6,6,6,6,6,6,6,6,6,6,6]"], ["[1,3,5,7,9,11,13,15]"], ["[1,10000]"], ["[10000,1]"], ["[1,2]"], ["[4,1,7,3]"], ["[2,9,1,8,2]"], ["[100,1,1,1,1,1]"], ["[1,1,1,1,1,100]"], ["[5,10,15,20,25,30,35]"], ["[13,1,8,2,5,3,21,1]"], ["[10000,9999,9998,9997,9996,9995,9994,9993,9992]"], ["[2,7,1,8,2,8,1,8,2,8]"], ["[50,40,30,20,10,5,4,3,2,1,1]"], ["[1,4,9,16,25,36,49,64,81,100,121,144,169]"], ["[7,2,9,4,1,8,3,6,5,10,12,11,14,13,15]"], ["[1000,1,1000,1,1000,1,1000,1,1000,1,1000,1,1000,1,1000,1]"]], "expected": [10, 104, 1, 4, 2, 9, 10000, 9, 5, 22, 150, 6, 25, 36, 32, 10001, 10001, 3, 7, 11, 102, 102, 75, 36, 49979, 28, 101, 408, 62, 4004], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "230", "slug": "stone-game-iii", "id": 230, "title": "Stone Game III", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/stone-game-iii/", "examples": [{"input": "stoneValue = [1,2,3,7]", "output": "\"Bob\"", "explanation": "Alice will always lose. Her best move will be to take three piles and the score become 6. Now the score of Bob is 7 and Bob wins."}, {"input": "stoneValue = [1,2,3,-9]", "output": "\"Alice\"", "explanation": "Alice must choose all the three piles at the first move to win and leave Bob with negative score."}, {"input": "stoneValue = [1,2,3,6]", "output": "\"Tie\"", "explanation": "Alice cannot win this game. She can end the game in a draw if she decided to choose all the first three piles, otherwise she will lose."}], "hints": ["The game can be mapped to minmax game. Alice tries to maximize the total score and Bob tries to minimize it.", "Use dynamic programming to simulate the game. If the total score was 0 the game is \"Tie\", and if it has positive value then \"Alice\" wins, otherwise \"Bob\" wins."], "statement": "Alice and Bob play a further row-removal contest. A row of stones carries integer scores listed in `stoneValue`.\n\nAlice moves first, then the two alternate. Each move removes stones only from the front of the remaining row: the player picks up 1, 2, or 3 stones there.\n\nEvery stone a player picks up adds its value to that player's total. Both totals begin at 0.\n\nWhoever holds the larger total once the row is gone wins; equal totals mean a drawn game. Play runs until every stone is gone.\n\nBoth sides act optimally.\n\nReturn `\"Alice\"` when optimal play puts Alice in front, `\"Bob\"` when it puts Bob in front, and `\"Tie\"` when optimal play ends level.\n\n**Constraints:**\n- 1 \u2264 stoneValue.length \u2264 5 \u00d7 10<sup>4</sup>\n- -1000 \u2264 stoneValue[i] \u2264 1000\n", "solution": "## Approach\n\nThis is a minimax game. Let `dp[i]` be the maximum score difference the player whose turn it is at position `i` can achieve (their final score minus the opponent's final score). Instead of simulating both players, note that if the current player takes the next `k` stones, they gain their sum and the opponent starts at `i + k` with advantage `dp[i + k]`, so the player's advantage is `suffix[i] - dp[i + k]`. Iterate from right to left over the suffix sums, take `k in {1, 2, 3}`, and keep the best.\n\nAt the end, `dp[0] > 0` means Alice wins, `dp[0] < 0` means Bob wins, and `dp[0] == 0` is a tie.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), as each position considers at most 3 next moves.\n- **Space Complexity:** O(n) for the `dp` and suffix arrays (can be reduced to O(1) with a sliding window since only the last 3 values are needed).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def stoneGameIII(self, stoneValue: List[int]) -> str:\n n = len(stoneValue)\n dp = [0] * (n + 1)\n for i in range(n - 1, -1, -1):\n best = float('-inf')\n take = 0\n for k in range(3):\n if i + k >= n:\n break\n take += stoneValue[i + k]\n best = max(best, take - dp[i + k + 1])\n dp[i] = best\n\n if dp[0] > 0:\n return \"Alice\"\n if dp[0] < 0:\n return \"Bob\"\n return \"Tie\"\n```", "starter": {"go": "package main\n\nfunc StoneGameIII(stoneValue []int) string {\n \n}", "python": "from typing import List\nclass Solution:\n def stoneGameIII(self, stoneValue: List[int]) -> str:\n ", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string stoneGameIII(vector<int>& stoneValue) {\n \n }\n};"}, "fn": "stoneGameIII", "params": [{"name": "stoneValue", "type": "int_array"}], "outputType": "string", "tests": [["[1,2,3,7]"], ["[1,2,3,-9]"], ["[1,2,3,6]"], ["[1]"], ["[2]"], ["[-1]"], ["[1,2]"], ["[-2,-1,0]"], ["[5,-5,5,-5,5]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[1000,-1000,1000,-1000,1000,-1000]"], ["[-1,-2,-3]"], ["[0,0,0,0]"], ["[3,7,1,2,9,4]"], ["[-2,3,5,-1,2,4]"], ["[0]"], ["[1000]"], ["[-1000]"], ["[-1,1]"], ["[1000,-1000]"], ["[4,4,4]"], ["[1,-2,3,-4]"], ["[-5,-4,-3,-2,-1]"], ["[10,-20,30,-40,50,-60]"], ["[7,7,-7,-7,7,7,-7]"], ["[9,1,2,8,3,7,4,6]"], ["[-1000,1000,-999,999,-998,998,-997,997,-996]"], ["[1,1,1,1,1,1,1,1,1,1,1]"], ["[100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]"], ["[5,-9,4,-8,3,-7,2,-6,1,-5,0,-4,9]"]], "expected": ["Bob", "Alice", "Tie", "Alice", "Alice", "Bob", "Alice", "Bob", "Alice", "Bob", "Alice", "Tie", "Tie", "Alice", "Alice", "Tie", "Alice", "Bob", "Tie", "Alice", "Alice", "Alice", "Bob", "Alice", "Alice", "Alice", "Bob", "Alice", "Alice", "Alice"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "234", "slug": "stone-game", "id": 234, "title": "Stone Game", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/stone-game/", "examples": [{"input": "piles = [5,3,4,5]", "output": "true", "explanation": "Alice starts first, and can only take the first 5 or the last 5. Say she takes the first 5, so the row becomes [3, 4, 5]. If Bob takes 3, then the board is [4, 5], and Alice takes 5 and then she wins (10 vs 7). If Bob takes the last 5, then the board is [3, 4], and Alice takes 4 and she wins (9 vs 8)."}, {"input": "piles = [3,7,2,3]", "output": "true", "explanation": ""}], "hints": ["Let dp[i][j] be the largest score advantage the current player can achieve on the subarray piles[i..j]. dp[i][j] = max(piles[i] - dp[i+1][j], piles[j] - dp[i][j-1]).", "Alice wins if and only if dp[0][n-1] > 0. Solve dp over increasing interval lengths."], "statement": "Alice and Bob compete over a single row of stone piles. The row holds an even count of piles, and `piles[i]` records how many stones sit in the `i`-th pile, always a positive integer.\n\nThe combined stone count is odd, so the final totals cannot match.\n\nAlice moves first and the two alternate. On every move the player whose turn it is removes one whole pile, choosing freely between the leftmost remaining pile and the rightmost remaining pile. Play proceeds this way until the row is empty; whoever has collected more stones is the winner.\n\nBoth sides choose as well as possible. Return `true` when that optimal play leaves Alice ahead, and `false` when it leaves Bob ahead.\n\n**Constraints:**\n- 2 \u2264 piles.length \u2264 500\n- piles.length is even.\n- 1 \u2264 piles[i] \u2264 500\n- sum(piles[i]) is odd.\n", "solution": "## Approach\n\nUse interval dynamic programming (minimax). Let `dp[i][j]` be the maximum score difference the current player can achieve over the subarray `piles[i..j]` (their total minus the opponent's total at the end of that subgame). A player can take the left pile or the right pile, and the opponent then plays the remaining subarray optimally, so:\n\n```\ndp[i][j] = max(piles[i] - dp[i+1][j], piles[j] - dp[i][j-1])\n```\n\nwith base case `dp[i][i] = piles[i]`. Alice wins if and only if `dp[0][n-1] > 0`. Note that under the given constraints Alice always wins (even number of piles, odd total), but the DP computes the correct answer for any input.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), one state per interval.\n- **Space Complexity:** O(n^2) for the dp table.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def stoneGame(self, piles: List[int]) -> bool:\n n = len(piles)\n dp = [[0] * n for _ in range(n)]\n for i in range(n - 1, -1, -1):\n for j in range(i, n):\n if i == j:\n dp[i][j] = piles[i]\n else:\n dp[i][j] = max(piles[i] - dp[i + 1][j], piles[j] - dp[i][j - 1])\n return dp[0][n - 1] > 0\n```", "starter": {"go": "package main\n\nfunc StoneGame(piles []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def stoneGame(self, piles: List[int]) -> bool:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool stoneGame(vector<int>& piles) {\n \n }\n};"}, "fn": "stoneGame", "params": [{"name": "piles", "type": "int_array"}], "outputType": "boolean", "tests": [["[5,3,4,5]"], ["[3,7,2,3]"], ["[1,2]"], ["[2,3]"], ["[4,1,2,6]"], ["[1,1,1,2]"], ["[7,8,8,10]"], ["[5,5,5,5,5,2]"], ["[1,2,3,4,5,6]"], ["[6,6,6,6,6,7]"], ["[2,4,6,8,10,13]"], ["[3,1,4,1,5,9,2,6]"], ["[1,1,1,1,1,1,1,2]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[7,7,7,7,7,7,7,7,7,8]"], ["[500,499]"], ["[1,500]"], ["[10,1,1,1]"], ["[2,9,1,3]"], ["[500,500,500,499]"], ["[8,1,7,2,6,3]"], ["[11,22,33,44,55,67]"], ["[100,1,100,1,100,2]"], ["[9,1,8,2,7,3,6,5]"], ["[20,19,18,17,16,15,14,12]"], ["[1,500,1,500,1,500,1,499]"], ["[4,8,15,16,23,42,7,6,5,3]"], ["[50,40,30,20,10,1,2,3,4,5]"], ["[13,21,34,55,89,144,233,378,1,2,3,4]"], ["[500,1,499,2,498,3,497,4,496,5,495,7]"]], "expected": [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "683", "slug": "strange-printer", "id": 683, "title": "Strange Printer", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/strange-printer/", "examples": [{"input": "s = \"aaabbb\"", "output": "2", "explanation": "Print all a at once, then overwrite the tail with b."}, {"input": "s = \"aba\"", "output": "2", "explanation": "Print aaa first, then paint the middle b."}, {"input": "s = \"abc\"", "output": "3", "explanation": "All letters differ, so each needs its own turn."}], "hints": ["Squeeze out consecutive repeats first; they never cost extra.", "For interval [l, r], start with solving [l, r-1] plus one turn for s[r].", "When s[k] equals s[r], the turn painting s[r] can share the turn painting s[k]: try dp[l][k] + dp[k+1][r-1]."], "statement": "A printer paints a string one turn at a time. In a turn it chooses a group of positions (not necessarily adjacent after earlier paints) and overwrites them with a single letter. Later turns may overwrite earlier paint.\n\nGiven `s`, return the fewest turns needed to paint it starting from a blank page.\n\n**Constraints:**\n- `1 <= s.length <= 100`\n- `s` holds lowercase English letters.\n", "solution": "## Approach\n\nCollapse consecutive duplicates since they print together. On the shortened string, let `dp[l][r]` be the best cost for that interval. Paint `s[r]` separately for `dp[l][r-1] + 1`, then try sharing its turn with any equal letter `s[k]`: the cost becomes `dp[l][k] + dp[k+1][r-1]`. Fill intervals by growing length.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^3) over intervals and split points.\n- **Space Complexity:** O(n^2) for the table.\n\n## Implementation\n\n```python\nclass Solution:\n def strangePrinter(self, s: str) -> int:\n t = []\n for c in s:\n if not t or t[-1] != c:\n t.append(c)\n s = \"\".join(t)\n n = len(s)\n if n == 0:\n return 0\n dp = [[0] * n for _ in range(n)]\n for i in range(n):\n dp[i][i] = 1\n for ln in range(2, n + 1):\n for l in range(n - ln + 1):\n r = l + ln - 1\n dp[l][r] = dp[l][r - 1] + 1\n for k in range(l, r):\n if s[k] == s[r]:\n v = dp[l][k] + (dp[k + 1][r - 1] if k + 1 <= r - 1 else 0)\n if v < dp[l][r]:\n dp[l][r] = v\n return dp[0][n - 1]\n```\n", "starter": {"go": "package main\n\nfunc StrangePrinter(s string) int {\n \n}", "python": "class Solution:\n def strangePrinter(self, s: str) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int strangePrinter(string s) {\n return 0;\n }\n};"}, "fn": "strangePrinter", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["aaabbb"], ["aba"], ["abc"], ["a"], ["aa"], ["ab"], ["aaa"], ["abab"], ["abac"], ["abcabc"], ["aaabbbaa"], ["abcdef"], ["aaaaa"], ["abbbcc"], ["abcba"], ["aabbaa"], ["abcdabcd"], ["zzzzzz"], ["abcbab"], ["abcddcba"], ["aaabbbccc"], ["abccba"], ["aabbcc"], ["bacbac"], ["abca"], ["xyyx"], ["abaaba"], ["abcdefghij"]], "expected": [2, 2, 3, 1, 1, 2, 1, 3, 3, 5, 2, 6, 1, 3, 3, 2, 7, 1, 4, 4, 3, 3, 3, 5, 3, 2, 3, 10], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "511", "slug": "string-compression", "id": 511, "title": "String Compression", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/string-compression/", "examples": [{"input": "s = \"aabbccc\"", "output": "6", "explanation": "Blocks become a2b2c3 of length 6."}, {"input": "s = \"a\"", "output": "1", "explanation": "A single letter stays as a."}, {"input": "s = \"abbbbbbbbbbbb\"", "output": "4", "explanation": "The squeezed form is ab11 of length 4."}], "hints": ["Scan for maximal blocks of equal letters.", "A block of size 1 costs 1; a block of size c>1 costs 1 plus the digit count of c.", "Add the cost of every block; no need to build the squeezed text."], "statement": "You are given text `s` made of letters. Imagine squeezing each maximal block of equal letters: keep one copy of the letter, and if the block length is greater than one, write the block length right after it. For example `aaab` squeezes to `a3b`.\n\nReturn the length of the squeezed form. You do not need to build the squeezed text itself, only report how long it would be.\n\n> **Adaptation note:** the classic task rewrites a character array in place and returns its new length. Here the input arrives as a `string` `s` and you return the squeezed length as an `int`, using the same counting rule. A block of length `1` adds `1`, a block of length `c > 1` adds `1 + digits(c)`.\n\n**Constraints:**\n- `1 <= s.length <= 2000`\n- `s` contains only English letters.\n", "solution": "## Approach\n\nWalk the text block by block: extend a pointer while the letter stays the same to measure each run length. A run of `1` contributes one character; a run of `c > 1` contributes one plus the number of decimal digits in `c`. Summing over runs yields the squeezed length.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`. Each character is visited once.\n- **Space Complexity:** O(1) extra memory.\n\n## Implementation\n\n```python\nclass Solution:\n def compress(self, s: str) -> int:\n n = len(s)\n total = 0\n j = 0\n while j < n:\n k = j\n while k < n and s[k] == s[j]:\n k += 1\n c = k - j\n total += 1\n if c > 1:\n total += len(str(c))\n j = k\n return total\n```\n", "starter": {"go": "package main\n\nfunc Compress(s string) int {\n return 0\n}", "python": "class Solution:\n def compress(self, s: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int compress(string s) {\n return 0;\n }\n};"}, "fn": "compress", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["aabbccc"], ["a"], ["abbbbbbbbbbbb"], ["aa"], ["ab"], ["abc"], ["aaaaaaaaaa"], ["aaaaaaaaaaa"], ["aabbaa"], ["zzzzzzzzzzzzzzzzzzzz"], ["abcddddd"], ["aBcDee"], ["xxyyzz"], ["mmmmmmmmmmn"], ["q"], ["wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"], ["abcdefghijklmnopqrstuvwxyz"], ["aabbccddee"], ["zzzzyyyyxxxx"], ["aabbbcccc"], ["bbbbbbbbbb"], ["ccccc"], ["abcdabcd"], ["aaabbb"], ["zzzaaa"], ["abcdefghijklmnopqrstuvwxyzzzz"], ["qqqqqqqqqqqqqqqqqqqq"], ["lmnopqrst"], ["aabbbaaabbb"], ["MMMMMMMMMM"]], "expected": [6, 1, 4, 2, 2, 3, 3, 3, 6, 3, 5, 6, 6, 4, 1, 3, 26, 10, 6, 6, 3, 2, 8, 4, 4, 27, 3, 9, 8, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "252", "slug": "string-to-integer-atoi", "id": 252, "title": "String to Integer (atoi)", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/string-to-integer-atoi/", "examples": [{"input": "s = \"42\"", "output": "42", "explanation": "The string starts directly with digits, giving 42."}, {"input": "s = \" -042\"", "output": "-42", "explanation": "Spaces are skipped, the minus sign is applied, and 042 parses to 42."}, {"input": "s = \"1337c0d3\"", "output": "1337", "explanation": "Reading stops at the first non-digit, so the result is 1337."}], "hints": ["Walk the string with an index: first spaces, then an optional sign, then digits. Anything else ends the parse.", "Accumulate into a wider (64-bit) variable or check the bounds before each multiply-and-add so overflow clamps correctly."], "statement": "Convert the leading portion of a string `s` into a 32-bit signed integer, following these steps in order:\n\n1. Skip any blank spaces at the very start of the string.\n2. If the next character is `-` or `+`, record the sign (negative or positive) and move past it. When neither sign is present, treat the number as positive.\n3. Read consecutive decimal digits and build the numeric value, stopping at the first character that is not a digit (or at the end of the string). Leading zeros are simply part of the value.\n4. If no digits were found, the answer is `0`.\n5. Clamp the result into the signed 32-bit range `[-2^31, 2^31 - 1]`: values below the minimum become `-2147483648` and values above the maximum become `2147483647`.\n\nImportant: implement the digit parsing yourself rather than calling a built-in string-to-number routine.\n\n**Constraints:**\n- `0 <= s.length <= 200`\n- `s` consists of English letters (upper- and lower-case), decimal digits, `' '`, `'+'`, `'-'`, and `'.'`\n", "solution": "## Approach\n\nSkip leading blanks, then consume one optional sign character, then accumulate consecutive digits into a running total. Parsing halts at the first non-digit, and when no digits appear the result is zero. A 64-bit accumulator lets us detect when the magnitude passes the 32-bit limits so we can clamp to `INT_MAX` or `INT_MIN`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`. Each character is examined at most once.\n- **Space Complexity:** O(1) extra space.\n\n## Implementation\n\n```python\nclass Solution:\n def myAtoi(self, s: str) -> int:\n i, n = 0, len(s)\n while i < n and s[i] == ' ':\n i += 1\n sign = 1\n if i < n and s[i] in ('+', '-'):\n if s[i] == '-':\n sign = -1\n i += 1\n val = 0\n while i < n and s[i].isdigit():\n val = val * 10 + int(s[i])\n if sign == 1 and val > 2**31 - 1:\n return 2**31 - 1\n if sign == -1 and val > 2**31:\n return -(2**31)\n i += 1\n return sign * val\n```\n", "starter": {"go": "package main\n\nfunc MyAtoi(s string) int {\n \n}", "python": "class Solution:\n def myAtoi(self, s: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int myAtoi(string s) {\n return 0;\n }\n};"}, "fn": "myAtoi", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["42"], [" -042"], ["1337c0d3"], ["0-1"], ["words and 987"], ["-91283472332"], ["91283472332"], ["2147483647"], ["2147483648"], ["-2147483648"], ["-2147483649"], ["+1"], ["+-12"], ["-+2"], ["+0"], ["-0"], ["00000-42a1234"], [" +0042"], [" -0012a42"], ["3.14159"], [" 0000000000012345678"], ["0000"], [" "], [" + 123"], ["123-"], [".1"], ["00000000000000000001"]], "expected": [42, -42, 1337, 0, 0, -2147483648, 2147483647, 2147483647, 2147483647, -2147483648, -2147483648, 1, 0, 0, 0, 0, 0, 42, -12, 3, 12345678, 0, 0, 0, 123, 0, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "967", "slug": "string-without-aaa-or-bbb", "id": 967, "title": "String Without AAA or BBB", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/string-without-aaa-or-bbb/", "examples": [{"input": "a = 1, b = 2", "output": "\"abb\"", "explanation": "One valid arrangement is abb; it uses one a and two b's with no triple."}, {"input": "a = 4, b = 1", "output": "\"aabaa\"", "explanation": "aabaa uses four a's and one b while avoiding aaa and bbb."}], "hints": ["Always try to emit the currently more plentiful letter, unless doing so would create three in a row.", "When the last two emitted letters are equal, you are forced to emit the other letter next.", "This greedy choice keeps the construction feasible whenever max(a,b) <= 2*(min(a,b)+1)."], "statement": "Given counts `a` and `b`, build a string containing exactly `a` copies of `a` and `b` copies of `b` such that neither `aaa` nor `bbb` appears as a contiguous block.\n\nAll test inputs satisfy the feasibility condition `max(a, b) <= 2 * (min(a, b) + 1)`, so at least one valid arrangement exists. Any valid arrangement is accepted.\n\n**Constraints:**\n- `0 <= a, b <= 100`\n- `a + b > 0`\n- Inputs guarantee a valid string exists.\n", "solution": "## Approach\n\nGreedily emit the currently more abundant letter. The only exception is when the last two emitted letters are equal: then the next letter is forced to be the other kind to avoid a triple. Because feasible inputs satisfy max <= 2*(min+1), the forced letter is always still available. Repeating this rule consumes all letters without ever creating aaa or bbb.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(a + b) for emitting each character once.\n- **Space Complexity:** O(a + b) for the output string.\n\n## Implementation\n\n```python\nclass Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n res = []\n ca, cb = a, b\n while ca > 0 or cb > 0:\n if len(res) >= 2 and res[-1] == res[-2]:\n write_a = res[-1] == 'b'\n else:\n write_a = ca >= cb\n if write_a:\n if ca == 0:\n res.append('b'); cb -= 1\n else:\n res.append('a'); ca -= 1\n else:\n if cb == 0:\n res.append('a'); ca -= 1\n else:\n res.append('b'); cb -= 1\n return ''.join(res)\n```\n", "starter": {"go": "package main\n\nfunc StrWithout3a3b(a int, b int) string {\n \n}", "python": "class Solution:\n def strWithout3a3b(self, a: int, b: int) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string strWithout3a3b(int a, int b) {\n return \"\";\n }\n};"}, "fn": "strWithout3a3b", "params": [{"name": "a", "type": "int"}, {"name": "b", "type": "int"}], "outputType": "string", "tests": [["1", "2"], ["4", "1"], ["1", "1"], ["2", "2"], ["3", "3"], ["0", "2"], ["2", "0"], ["1", "0"], ["0", "1"], ["5", "3"], ["3", "5"], ["6", "3"], ["2", "5"], ["5", "2"], ["10", "5"], ["4", "4"], ["7", "4"], ["2", "1"], ["1", "4"], ["8", "4"], ["9", "5"], ["20", "10"], ["0", "2"], ["2", "6"], ["6", "2"], ["11", "6"], ["15", "8"], ["30", "15"]], "expected": ["bab", "aabaa", "ab", "abab", "ababab", "bb", "aa", "a", "b", "aabaabab", "bbababab", "aabaabaab", "bbabbab", "aabaaba", "aabaabaabaabaab", "abababab", "aabaabaabab", "aab", "bbabb", "aabaabaabaab", "aabaabaabaabab", "aabaabaabaabaabaabaabaabaabaab", "bb", "bbabbabb", "aabaabaa", "aabaabaabaabaabab", "aabaabaabaabaabaabaabab", "aabaabaabaabaabaabaabaabaabaabaabaabaabaabaab"], "loose": false}