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": "115", "slug": "max-area-of-island", "id": 115, "title": "Max Area of Island", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/max-area-of-island/", "examples": [{"input": "grid = [[0,0,1,0],[1,1,1,0],[0,1,0,1]]", "output": "5", "explanation": "The five connected land cells form the largest island."}, {"input": "grid = [[0,0],[0,0]]", "output": "0", "explanation": "The 2x2 grid contains no land cells, so the maximum island area is 0."}], "hints": ["Start a flood fill from each unvisited land cell.", "Count the cells reached by each flood fill and keep the largest count."], "statement": "Given a nonempty rectangular binary grid, return the largest area of an island.\n\nAn island is a group of `1` cells connected horizontally or vertically. Its area is the number of cells in the group. Return `0` when the grid contains no land.\n\n**Constraints:**\n- `1 <= grid.length <= 50`\n- `1 <= grid[r].length <= 50`\n- Every row has the same length.\n- Every cell is `0` or `1`.\n", "solution": "## Approach\n\nScan every cell and start a breadth-first search from each unvisited land cell. Mark land when it enters the queue so it is counted once, measure the component's area, and retain the largest area found. An explicit queue avoids recursion-depth problems on large connected islands.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), because every grid cell is processed at most once.\n- **Space Complexity:** O(m * n) for the visited matrix and breadth-first-search queue.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\n\nclass Solution:\n def maxAreaOfIsland(self, grid: List[List[int]]) -> int:\n rows, cols = len(grid), len(grid[0])\n visited = [[False] * cols for _ in range(rows)]\n largest = 0\n for row in range(rows):\n for col in range(cols):\n if grid[row][col] == 0 or visited[row][col]:\n continue\n area = 0\n queue = deque([(row, col)])\n visited[row][col] = True\n while queue:\n current_row, current_col = queue.popleft()\n area += 1\n for row_step, col_step in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n next_row = current_row + row_step\n next_col = current_col + col_step\n if not (0 <= next_row < rows and 0 <= next_col < cols):\n continue\n if grid[next_row][next_col] == 0 or visited[next_row][next_col]:\n continue\n visited[next_row][next_col] = True\n queue.append((next_row, next_col))\n largest = max(largest, area)\n return largest\n```\n", "starter": {"go": "package main\n\nfunc MaxAreaOfIsland(grid [][]int) int {\n return 0\n}\n", "python": "from typing import List\n\nclass Solution:\n def maxAreaOfIsland(self, grid: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxAreaOfIsland(vector<vector<int>>& grid) {\n return 0;\n }\n};"}, "fn": "maxAreaOfIsland", "params": [{"name": "grid", "type": "int_array_2d", "visualizeType": "matrix"}], "outputType": "int", "tests": [["[[0]]"], ["[[1]]"], ["[[0,0]]"], ["[[1,1]]"], ["[[1,0]]"], ["[[0,1]]"], ["[[0],[0]]"], ["[[1],[1]]"], ["[[1],[0]]"], ["[[0],[1]]"], ["[[1,0],[0,1]]"], ["[[1,1],[1,1]]"], ["[[0,0],[0,0]]"], ["[[1,1],[0,0]]"], ["[[1,0],[1,0]]"], ["[[0,1],[0,1]]"], ["[[1,0,1],[1,0,1]]"], ["[[1,1,0],[0,1,0],[0,0,1]]"], ["[[0,1,0],[1,1,1],[0,1,0]]"], ["[[1,0,1],[0,1,0],[1,0,1]]"], ["[[1,1,1],[1,1,1],[1,1,1]]"], ["[[0,0,0],[0,0,0],[0,0,0]]"], ["[[1,1,1,0,1]]"], ["[[0,1,0,1,1]]"], ["[[1],[1],[0],[1],[1]]"], ["[[0,0,1,0,0],[1,1,1,0,1],[0,1,0,0,1],[0,0,0,1,1]]"], ["[[1,1,0,0],[0,1,1,0]]"], ["[[1,0,0,1],[1,1,0,1]]"], ["[[0,1,1,0],[1,1,0,1]]"], ["[[1,0,1,0],[0,1,0,1]]"], ["[[1,1,0,1],[0,1,0,1],[0,1,1,1]]"], ["[[0,1,0,0],[1,1,1,0],[0,0,1,1]]"], ["[[1,0,0,0],[1,1,1,1],[0,0,0,1]]"], ["[[1,1,1,1],[0,0,0,0],[1,1,1,1]]"], ["[[0,1,1,0],[0,1,1,0],[1,0,0,1]]"], ["[[1,0,1],[1,1,1],[1,0,1],[1,0,1]]"], ["[[0,1,0],[1,1,0],[0,1,1],[0,0,1]]"], ["[[1,1,0],[1,0,0],[1,1,1],[0,0,1]]"], ["[[1,0,0,1,1],[1,1,0,0,1],[0,1,1,0,0]]"], ["[[0,0,1,1,0],[1,0,1,0,0],[1,1,1,0,1]]"], ["[[1,1,1,0,0],[0,0,1,1,0],[1,0,0,1,1]]"], ["[[0,1,0,1,0],[1,1,0,1,1],[0,1,0,0,1]]"], ["[[1,0,1,0,1],[1,0,1,0,1],[1,1,1,1,1]]"], ["[[1,1,0,0,1],[0,1,1,0,1],[0,0,1,1,1],[1,0,0,0,0]]"], ["[[0,1,1,1],[0,1,0,1],[1,1,0,1],[1,0,0,1]]"], ["[[1,0,0,1],[1,1,0,1],[0,1,1,1],[0,0,0,1]]"], ["[[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]"], ["[[0,0,0,0,0],[0,1,1,1,0],[0,1,0,1,0],[0,1,1,1,0],[0,0,0,0,0]]"], ["[[1,0,1,0,1,0],[0,1,0,1,0,1],[1,0,1,0,1,0]]"], ["[[1,1,0,0,1,1],[0,1,1,0,1,0],[0,0,1,1,1,0]]"], ["[[0,1,1,0,0,1],[1,1,0,0,1,1],[0,1,1,1,1,0],[0,0,0,1,0,0]]"], ["[[1,0,0,0,1],[1,1,1,0,1],[0,0,1,0,1],[1,1,1,1,1],[0,0,0,0,0]]"], ["@javascript:JSON.stringify(Array.from({length:50},()=>Array(50).fill(1)))"]], "expected": [0, 1, 0, 2, 1, 1, 0, 2, 1, 1, 1, 4, 0, 2, 2, 2, 2, 3, 5, 1, 9, 0, 3, 2, 2, 5, 4, 3, 4, 1, 8, 6, 6, 4, 4, 9, 6, 7, 5, 7, 7, 4, 11, 9, 10, 9, 16, 8, 1, 10, 12, 13, 2500], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "768", "slug": "max-chunks-to-make-sorted-ii", "id": 768, "title": "Max Chunks To Make Sorted II", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/max-chunks-to-make-sorted-ii/", "examples": [{"input": "arr = [5,4,3,2,1]", "output": "1", "explanation": "No split point keeps the sorted order, so only one chunk works."}, {"input": "arr = [2,1,3,4,4]", "output": "4", "explanation": "Chunks [2,1], [3], [4], [4] sort to [1,2,3,4,4]."}, {"input": "arr = [1,1,0,0,1]", "output": "2", "explanation": "Split into [1,1,0,0] and [1]."}], "hints": ["Sweep once while maintaining a stack of chunk maxima: each new value starts its own chunk.", "While the previous chunk maximum exceeds the new value, merge it into the current chunk keeping the larger maximum.", "The stack size at the end is the finest valid chunk count."], "statement": "You are given an integer array `arr` that may contain duplicates. Cut it into the greatest possible number of contiguous blocks (chunks) so that sorting each block separately and then gluing the blocks back together produces the fully sorted array.\n\nReturn how many blocks that finest valid split contains.\n\n**Constraints:**\n- `1 <= arr.length <= 2000`\n- `0 <= arr[i] <= 10^8`\n", "solution": "## Approach\n\nWalk the array while keeping a stack of chunk maxima. Each value begins a new chunk, but whenever the prior maximum is larger than the newcomer the two chunks must fuse (otherwise sorting separately would misplace values), carrying forward the larger maximum. Fusing repeatedly until the stack top fits preserves the finest valid partition.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) since each element is pushed and popped at most once.\n- **Space Complexity:** O(n) for the stack in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:\n st = []\n for x in arr:\n cur = x\n while st and st[-1] > x:\n cur = max(cur, st.pop())\n st.append(cur)\n return len(st)\n```\n", "starter": {"go": "package main\n\nfunc MaxChunksToSorted(arr []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxChunksToSorted(vector<int>& arr) {\n return 0;\n }\n};"}, "fn": "maxChunksToSorted", "params": [{"name": "arr", "type": "int_array"}], "outputType": "int", "tests": [["[5,4,3,2,1]"], ["[2,1,3,4,4]"], ["[1,1,0,0,1]"], ["[0]"], ["[1,0]"], ["[0,1]"], ["[1,1,1,1]"], ["[4,3,2,1,0]"], ["[0,0,1,1,1]"], ["[2,2,2,2]"], ["[1,0,2,3,4]"], ["[4,2,2,1,1,3,3]"], ["[0,2,1]"], ["[3,3,3,2,2,1]"], ["[1,2,0,3]"], ["[2,0,2,0,2]"], ["[5,1,1,1,1,5]"], ["[0,1,2,3,4,5]"], ["[5,4,3,2,1,0]"], ["[1,1,1,0,0,0]"], ["[0,0,0,0]"], ["[3,1,2,0]"], ["[100000000,0,100000000]"], ["[2,1,3,4,4,5,6]"], ["[1,3,2,2,2]"], ["[0,3,0,3,0,3]"], ["[7,7,7,7,7,7,7]"], ["[9,0,9,0,9,0]"]], "expected": [1, 4, 2, 1, 1, 2, 4, 1, 5, 4, 4, 1, 2, 1, 2, 2, 2, 6, 1, 1, 4, 1, 2, 6, 2, 3, 7, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "769", "slug": "max-chunks-to-make-sorted", "id": 769, "title": "Max Chunks To Make Sorted", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/max-chunks-to-make-sorted/", "examples": [{"input": "arr = [4,3,2,1,0]", "output": "1", "explanation": "No early cut keeps values in range."}, {"input": "arr = [1,0,2,3,4]", "output": "4", "explanation": "Chunks [1,0], [2], [3], [4] work."}, {"input": "arr = [0,1,2]", "output": "3", "explanation": "Sorted input splits into singletons."}], "hints": ["Because the values are 0..n-1, a prefix can stand alone exactly when its maximum equals its last index.", "Scan once tracking the running maximum; cut after every position where max == index.", "Count those cut points."], "statement": "You are given an array `arr` of length `n` holding each integer from `0` to `n - 1` exactly once (a permutation).\n\nSplit it into the most contiguous chunks possible so that sorting every chunk on its own and concatenating the results equals the fully sorted array `[0, 1, ..., n-1]`. Return that largest number of chunks.\n\n**Constraints:**\n- `n == arr.length`\n- `1 <= n <= 10`\n- `0 <= arr[i] < n`\n- All values are distinct\n", "solution": "## Approach\n\nSince the array is a permutation of 0 through n-1, the set {arr[0..i]} equals {0..i} exactly when the maximum of that prefix is i. Scanning once while remembering the running maximum lets us cut after every index satisfying that equality, which yields the finest feasible partition.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for a single pass.\n- **Space Complexity:** O(1) besides the input.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:\n chunks = 0\n mx = -1\n for i, x in enumerate(arr):\n mx = max(mx, x)\n if mx == i:\n chunks += 1\n return chunks\n```\n", "starter": {"go": "package main\n\nfunc MaxChunksToSorted(arr []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxChunksToSorted(self, arr: List[int]) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxChunksToSorted(vector<int>& arr) {\n return 0;\n }\n};"}, "fn": "maxChunksToSorted", "params": [{"name": "arr", "type": "int_array"}], "outputType": "int", "tests": [["[4,3,2,1,0]"], ["[1,0,2,3,4]"], ["[0,1,2]"], ["[0]"], ["[1,0]"], ["[0,1]"], ["[2,0,1]"], ["[1,2,0]"], ["[2,1,0]"], ["[0,2,1]"], ["[3,2,1,0]"], ["[0,1,2,3]"], ["[1,0,3,2]"], ["[2,3,0,1]"], ["[3,0,1,2]"], ["[4,0,1,2,3]"], ["[0,4,1,2,3]"], ["[5,4,3,2,1,0]"], ["[0,1,2,3,4,5]"], ["[2,0,3,1,5,4]"], ["[1,3,2,0,4]"], ["[6,0,1,2,3,4,5]"], ["[0,2,1,4,3,6,5]"], ["[7,0,1,2,3,4,5,6]"], ["[3,4,0,1,2]"], ["[9,0,1,2,3,4,5,6,7,8]"], ["[0,1,2,3,4,5,6,7,8,9]"], ["[5,1,0,4,2,3]"]], "expected": [1, 4, 3, 1, 1, 2, 1, 1, 1, 2, 1, 4, 2, 1, 1, 1, 2, 1, 6, 2, 2, 1, 4, 1, 1, 1, 10, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "551", "slug": "max-consecutive-ones-ii", "id": 551, "title": "Max Consecutive Ones II", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/max-consecutive-ones-ii/", "examples": [{"input": "nums = [1,0,1,1,0]", "output": "4", "explanation": "Flip index 1 to get four in a row."}, {"input": "nums = [1,0,1,1,0,1]", "output": "4", "explanation": "Either zero flip gives length 4."}, {"input": "nums = [1,1,1]", "output": "3", "explanation": "Already all ones."}], "hints": ["Slide a window that holds at most one zero.", "When a second zero enters, shift the left edge past the older zero.", "Only the window length matters, so it never needs to shrink by more than one step."], "statement": "You get a binary array. You may flip at most one `0` into a `1` (you can also flip nothing). After that single optional flip, how long can the longest block of consecutive `1`s become?\n\nReturn that maximum length.\n\n**Constraints:**\n\n- `1 <= nums.length <= 10^5`\n- Each `nums[i]` is `0` or `1`.\n", "solution": "## Approach\n\nExpand a window to the right while counting zeroes inside it. Whenever a second zero appears, advance the left edge until only one zero remains. Because only the longest length is needed, the window effectively tracks the best stretch that flips at most one zero. All-ones input naturally yields the full length.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), each index moves at most twice.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:\n best = 0\n left = 0\n zeros = 0\n for right, v in enumerate(nums):\n if v == 0:\n zeros += 1\n while zeros > 1:\n if nums[left] == 0:\n zeros -= 1\n left += 1\n best = max(best, right - left + 1)\n return best\n```\n", "starter": {"go": "package main\n\nfunc FindMaxConsecutiveOnes(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "findMaxConsecutiveOnes", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,0,1,1,0]"], ["[1,0,1,1,0,1]"], ["[1,1,1]"], ["[0]"], ["[1]"], ["[0,0]"], ["[1,0]"], ["[0,1]"], ["[1,0,0,1]"], ["[0,0,1,1,1]"], ["[1,1,1,0,0]"], ["[1,0,1,0,1,0,1]"], ["[0,1,1,1,0,1,1]"], ["[1,1,0,1,1,1,0,1]"], ["[0,0,0]"], ["[1,1,1,1]"], ["[1,0,1,1,1,0,1,1,1,1]"], ["[0,1,0,1,0,1,0]"], ["[1,1,0,0,1,1]"], ["[1,0,0,0,1]"], ["[0,0,0,0,1]"], ["[1,1,0,1,0,1,1,1]"], ["[0,1,0,0,1,1,0,1]"], ["[1,0,1,0,0,1,0,0,1,1]"], ["[0,0,0,0,0]"], ["[1,1,1,1,0,1,1,1,1,1]"], ["[1,0,0,1,1,1,0,0,0,1]"], ["[0,1,1,0,1,1,0,1,1,1,0,1]"]], "expected": [4, 4, 3, 1, 1, 1, 2, 2, 2, 4, 4, 3, 6, 6, 1, 4, 8, 3, 3, 2, 2, 5, 4, 3, 1, 10, 4, 6], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "549", "slug": "max-consecutive-ones", "id": 549, "title": "Max Consecutive Ones", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/max-consecutive-ones/", "examples": [{"input": "nums = [1,1,0,1,1,1]", "output": "3", "explanation": "Last three entries are the longest run."}, {"input": "nums = [1,0,1,1,0,1]", "output": "2", "explanation": "Middle pair is longest."}, {"input": "nums = [0,0,0]", "output": "0", "explanation": "No ones present."}], "hints": ["Walk once, counting the current run of 1s.", "Reset the counter on each 0 and track the maximum.", "No extra memory is needed."], "statement": "Scan a binary array (only `0`s and `1`s) and report the length of the longest contiguous run of `1`s.\n\n**Constraints:**\n\n- `1 <= nums.length <= 10^5`\n- Each `nums[i]` is `0` or `1`.\n", "solution": "## Approach\n\nSweep the array once while keeping the length of the ongoing run of ones. A `1` extends the run, a `0` resets it, and the best value seen so far is retained throughout.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:\n best = cur = 0\n for v in nums:\n if v == 1:\n cur += 1\n best = max(best, cur)\n else:\n cur = 0\n return best\n```\n", "starter": {"go": "package main\n\nfunc FindMaxConsecutiveOnes(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def findMaxConsecutiveOnes(self, nums: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int findMaxConsecutiveOnes(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "findMaxConsecutiveOnes", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,1,0,1,1,1]"], ["[1,0,1,1,0,1]"], ["[0,0,0]"], ["[1,1,1]"], ["[1]"], ["[0]"], ["[1,0,1,0,1,0,1]"], ["[0,1,1,1,0,1,1]"], ["[1,1,1,0,0,0,1,1]"], ["[1,1,0,0,1,1,1,1]"], ["[0,1]"], ["[1,0]"], ["[1,1,1,1,0,1,1,1,1,1]"], ["[0,0,1,1,1,0,0]"], ["[1,0,0,1,0,1,1,1,0,1]"], ["[1,1,0,1]"], ["[0,1,0,1,0,1,1]"], ["[1,1,1,1,1]"], ["[0,0,0,0,0,1]"], ["[1,0,0,0,0,0]"], ["[1,1,1,0,1,1]"], ["[0,1,0]"], ["[1,1,1,1,1,1]"], ["[0,0,0,0]"], ["[1,0,1,1,1,0,1,1,1,1]"], ["[0,1,1,0,1]"], ["[1,1]"], ["[0,0,1]"], ["[1,0,0,1,1]"], ["[1,1,0,1,1,0,1,1,1]"]], "expected": [3, 2, 0, 3, 1, 0, 1, 3, 3, 4, 1, 1, 5, 3, 3, 2, 2, 5, 1, 1, 3, 1, 6, 0, 4, 2, 2, 1, 2, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "805", "slug": "max-increase-to-keep-city-skyline", "id": 805, "title": "Max Increase to Keep City Skyline", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/max-increase-to-keep-city-skyline/", "examples": [{"input": "grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]", "output": "35", "explanation": "Each cell rises to min(row max, column max)."}, {"input": "grid = [[0,0,0],[0,0,0],[0,0,0]]", "output": "0", "explanation": "Nothing can be raised."}, {"input": "grid = [[5]]", "output": "0", "explanation": "Single cell already at its caps."}], "hints": ["Precompute each row maximum and each column maximum first.", "A cell at (i,j) can rise to min(rowMax[i], colMax[j]) without changing the skyline.", "Sum those caps minus the original heights for the answer."], "statement": "You receive a square `grid` where `grid[i][j]` is the height of the tower in row `i`, column `j`. Viewed from the sides, each row shows its tallest tower, and viewed from the front and back, each column shows its tallest tower. Together these maxima form the skyline.\n\nYou may raise any towers but never lower them, with the restriction that every row maximum and every column maximum stays exactly the same. Maximize the total added height across all cells and return that increase.\n\n**Constraints:**\n- `1 <= grid.length == grid[0].length <= 50`\n- `0 <= grid[i][j] <= 100`\n- Adaptation: the square input maps to int_array_2d in this judge.\n", "solution": "## Approach\n\nFirst record the tallest tower in every row and every column. Each cell can then be lifted up to the smaller of its two caps without altering any skyline, so summing those headrooms over the whole grid gives the greatest achievable increase.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * m) for an n by m grid, two passes.\n- **Space Complexity:** O(n + m) for the row and column maxima.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int:\n row_max = [max(row) for row in grid]\n col_max = [max(col) for col in zip(*grid)]\n ans = 0\n for i, row in enumerate(grid):\n for j, h in enumerate(row):\n ans += min(row_max[i], col_max[j]) - h\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MaxIncreaseKeepingSkyline(grid [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxIncreaseKeepingSkyline(vector<vector<int>>& grid) {\n return 0;\n }\n};"}, "fn": "maxIncreaseKeepingSkyline", "params": [{"name": "grid", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[3, 0, 8, 4], [2, 4, 5, 7], [9, 2, 6, 3], [0, 3, 1, 0]]"], ["[[0, 0, 0], [0, 0, 0], [0, 0, 0]]"], ["[[5]]"], ["[[1, 2], [3, 4]]"], ["[[5, 5], [5, 5]]"], ["[[0, 1], [1, 0]]"], ["[[1]]"], ["[[0]]"], ["[[100]]"], ["[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"], ["[[9, 8, 7], [6, 5, 4], [3, 2, 1]]"], ["[[3, 3, 3], [3, 3, 3], [3, 3, 3]]"], ["[[0, 0, 1], [0, 1, 0], [1, 0, 0]]"], ["[[5, 1, 2], [1, 5, 1], [2, 1, 5]]"], ["[[2, 2], [2, 2]]"], ["[[1, 0], [0, 1]]"], ["[[4, 0], [0, 4]]"], ["[[10, 20], [30, 40]]"], ["[[0, 10], [10, 0]]"], ["[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]"], ["[[16, 15, 14, 13], [12, 11, 10, 9], [8, 7, 6, 5], [4, 3, 2, 1]]"], ["[[50, 50], [50, 50]]"], ["[[0, 0, 0, 0], [0, 0, 0, 0]]"], ["[[1, 1, 1, 1, 1]]"], ["[[7]]"], ["[[3, 1], [1, 3]]"], ["[[8, 4], [4, 8]]"], ["[[2, 5], [5, 2], [2, 5]]"]], "expected": [35, 0, 0, 1, 0, 2, 0, 0, 0, 6, 6, 0, 6, 22, 0, 2, 8, 10, 20, 18, 18, 0, 0, 0, 0, 4, 8, 9], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "306", "slug": "max-points-on-a-line", "id": 306, "title": "Max Points on a Line", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/max-points-on-a-line/", "examples": [{"input": "points = [[1,1],[2,2],[3,3]]", "output": "3", "explanation": "All three lie on the diagonal y = x."}, {"input": "points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]", "output": "4", "explanation": "The line through [1,4], [2,3], [3,2], [4,1] holds four points, which is maximal."}], "hints": ["Fix one anchor point and count normalized slopes to every other point.", "Reduce (dx, dy) by their gcd and a canonical sign so identical lines share a key.", "Handle vertical lines (dx = 0) as their own slope bucket."], "statement": "You are given points `points[i] = [xi, yi]` on the plane. All points are distinct.\n\nA straight line can pass through any subset of them. Return the largest number of points that share one such line.\n\n**Constraints:**\n- `1 <= points.length <= 300`\n- `points[i].length == 2`\n- `-10^4 <= xi, yi <= 10^4`\n- All points are unique.\n", "solution": "## Approach\n\nAnchor each point in turn and group the remaining points by reduced slope. Dividing `(dx, dy)` by their gcd and fixing the sign gives a canonical key, with flat and vertical lines handled separately. The largest bucket plus the anchor is the best line through that anchor; the global maximum over anchors is the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), where n is the number of points. Each anchor scans all later points with gcd work.\n- **Space Complexity:** O(n) for the slope map of one anchor.\n\n## Implementation\n\n```python\nfrom typing import List\nimport math\nclass Solution:\n def maxPoints(self, points: List[List[int]]) -> int:\n n = len(points)\n if n <= 2:\n return n\n best = 0\n for i in range(n):\n slopes = {}\n cur_best = 0\n xi, yi = points[i]\n for j in range(i + 1, n):\n dx = points[j][0] - xi\n dy = points[j][1] - yi\n if dx == 0 and dy == 0:\n continue\n if dx == 0:\n key = (\"v\",)\n elif dy == 0:\n key = (\"h\",)\n else:\n g = math.gcd(abs(dx), abs(dy))\n dx //= g\n dy //= g\n if dx < 0:\n dx, dy = -dx, -dy\n key = (dx, dy)\n slopes[key] = slopes.get(key, 0) + 1\n cur_best = max(cur_best, slopes[key])\n best = max(best, cur_best + 1)\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxPoints(points [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxPoints(self, points: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n return 0;\n }\n};"}, "fn": "maxPoints", "params": [{"name": "points", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1, 1], [2, 2], [3, 3]]"], ["[[1, 1], [3, 2], [5, 3], [4, 1], [2, 3], [1, 4]]"], ["[[0, 0]]"], ["[[0, 0], [1, 1]]"], ["[[0, 0], [1, 0], [2, 0]]"], ["[[0, 0], [0, 1], [0, 2]]"], ["[[1, 1], [2, 1], [3, 1], [1, 2]]"], ["[[0, 0], [1, 1], [2, 2], [3, 4]]"], ["[[-1, -1], [0, 0], [1, 1], [2, 2]]"], ["[[1, 0], [2, 0], [3, 0], [4, 0], [5, 1]]"], ["[[0, 1], [0, 2], [0, 3], [1, 1]]"], ["[[2, 3], [3, 3], [5, 5], [1, 1]]"], ["[[0, 0], [10000, 10000], [-10000, -10000]]"], ["[[1, 2], [3, 6], [0, 0], [1, 3]]"], ["[[4, 5], [4, -1], [4, 0], [2, 3]]"], ["[[1, 1], [2, 2], [3, 3], [4, 4], [1, 2]]"], ["[[0, 0], [1, 2], [2, 4], [3, 6], [4, 5]]"], ["[[5, 5], [1, 1], [2, 2], [10, 10], [3, 4]]"], ["[[-5, 4], [-4, 3], [-3, 2], [0, 0]]"], ["[[1, 1], [1, 2], [1, 3], [2, 1], [3, 1]]"], ["[[7, 3], [19, 19], [9, 9], [1, 1]]"], ["[[0, 0], [2, 1], [4, 2], [6, 4]]"], ["[[3, 1], [3, 2], [3, 3], [4, 1]]"], ["[[1, 5], [2, 4], [3, 3], [5, 1], [0, 6]]"], ["[[-10000, 0], [10000, 0], [0, 0]]"], ["[[0, 5], [1, 4], [2, 3], [3, 2], [4, 1], [5, 0], [0, 0]]"], ["[[2, 2], [4, 4], [6, 6], [8, 9]]"], ["[[1, 0], [0, 1], [-1, 0], [0, -1], [0, 0]]"]], "expected": [3, 4, 1, 2, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 5, 3, 6, 3, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "724", "slug": "max-stack", "id": 724, "title": "Max Stack", "difficulty": "Easy", "category": "stack", "link": "https://leetcode.com/problems/max-stack/", "examples": [{"input": "operations = [\"MaxStack\",\"push\",\"push\",\"push\",\"top\",\"popMax\",\"top\",\"peekMax\",\"pop\",\"top\"], values = [[],[5],[1],[5],[],[],[],[],[],[]]", "output": "[null,null,null,null,5,5,1,5,1,5]", "explanation": "Push 5, 1, 5. Top is 5; popMax removes the upper 5; top is 1; peekMax is 5; pop removes 1; top is 5."}, {"input": "operations = [\"MaxStack\",\"push\",\"push\",\"popMax\",\"top\"], values = [[],[1],[2],[],[]]", "output": "[null,null,null,2,1]", "explanation": "Push 1 then 2; popMax removes 2; top is 1."}, {"input": "operations = [\"MaxStack\",\"push\",\"push\",\"peekMax\",\"pop\",\"peekMax\"], values = [[],[2],[7],[],[],[]]", "output": "[null,null,null,7,7,2]", "explanation": "Push 2 then 7; the max is 7; pop removes 7; the max becomes 2."}], "hints": ["Track the maximum alongside the values: a parallel max stack makes top and peekMax O(1).", "popMax must remove the topmost copy of the maximum; buffering the elements above it and pushing them back works.", "Construction and push report \"null\"; pop, top, peekMax and popMax report plain integers."], "statement": "Design a stack that can also report and remove its maximum in addition to the usual push, pop and top.\n\nImplement the `MaxStack` class:\n\n- `MaxStack()` Initializes the stack object.\n- `void push(int x)` Pushes `x` onto the stack.\n- `int pop()` Removes the element on top of the stack and returns it.\n- `int top()` Returns the element on top of the stack without removing it.\n- `int peekMax()` Returns the maximum element in the stack without removing it.\n- `int popMax()` Returns the maximum element in the stack and removes it. If there are multiple copies of the maximum, only the one closest to the top is removed.\n\nThe class keeps its LeetCode name `MaxStack` (the harness reserves `Solution` for the driver); the constructor and methods match the original.\n\n**Constraints:**\n- Values fit in a 32-bit signed integer.\n- At most `10^4` calls will be made to `push`, `pop`, `top`, `peekMax` and `popMax` in total.\n- Every `pop`, `top`, `peekMax` or `popMax` call has at least one element present; every trace begins with `MaxStack`.\n", "solution": "## Approach\n\nKeep two parallel stacks: a value stack and a max stack whose top always holds the maximum of everything below it. Pushing `x` appends `x` alongside `max(x, current max)`, so `top` and `peekMax` are O(1) reads and `pop` drops both tops. For `popMax`, move elements above the topmost maximum into a buffer, drop the maximum from both stacks, then push the buffered elements back (rebuilding their max entries). The full per-operation trace (`\"null\"` for construction and `push`, plain integers otherwise) is compared exactly against the reference.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) amortized per `push`, `pop`, `top` and `peekMax`; O(n) per `popMax` where n is the stack depth.\n- **Space Complexity:** O(n) for the two stacks.\n\n## Implementation\n\n```python\nclass MaxStack:\n def __init__(self):\n self.stack = []\n self.max_stack = []\n\n def push(self, x: int) -> None:\n self.stack.append(x)\n if not self.max_stack or x >= self.max_stack[-1]:\n self.max_stack.append(x)\n else:\n self.max_stack.append(self.max_stack[-1])\n\n def pop(self) -> int:\n self.max_stack.pop()\n return self.stack.pop()\n\n def top(self) -> int:\n return self.stack[-1]\n\n def peekMax(self) -> int:\n return self.max_stack[-1]\n\n def popMax(self) -> int:\n mx = self.max_stack[-1]\n buf = []\n while self.stack[-1] != mx:\n buf.append(self.stack.pop())\n self.max_stack.pop()\n self.stack.pop()\n self.max_stack.pop()\n while buf:\n self.push(buf.pop())\n return mx\n```\n", "starter": {"go": "package main\n\ntype MaxStack struct {\n\n}\n\nfunc Constructor() MaxStack {\n return MaxStack{}\n}\n\nfunc (this *MaxStack) Push(x int) {\n\n}\n\nfunc (this *MaxStack) Pop() int {\n return 0\n}\n\nfunc (this *MaxStack) Top() int {\n return 0\n}\n\nfunc (this *MaxStack) PeekMax() int {\n return 0\n}\n\nfunc (this *MaxStack) PopMax() int {\n return 0\n}", "python": "class MaxStack:\n def __init__(self):\n pass\n\n def push(self, x: int) -> None:\n pass\n\n def pop(self) -> int:\n return 0\n\n def top(self) -> int:\n return 0\n\n def peekMax(self) -> int:\n return 0\n\n def popMax(self) -> int:\n return 0", "cpp": "class MaxStack {\npublic:\n MaxStack() {\n\n }\n\n void push(int x) {\n\n }\n\n int pop() {\n return 0;\n }\n\n int top() {\n return 0;\n }\n\n int peekMax() {\n return 0;\n }\n\n int popMax() {\n return 0;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"MaxStack\", \"push\", \"push\", \"push\", \"top\", \"popMax\", \"top\", \"peekMax\", \"pop\", \"top\"]", "[[], [5], [1], [5], [], [], [], [], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"popMax\", \"top\"]", "[[], [1], [2], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"peekMax\", \"pop\", \"peekMax\"]", "[[], [2], [7], [], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"top\", \"pop\", \"top\"]", "[[], [4], [4], [], [], []]"], ["[\"MaxStack\", \"push\", \"top\", \"pop\", \"push\", \"top\"]", "[[], [9], [], [], [3], []]"], ["[\"MaxStack\", \"push\", \"push\", \"push\", \"popMax\", \"popMax\", \"popMax\"]", "[[], [3], [1], [2], [], [], []]"], ["[\"MaxStack\", \"push\", \"peekMax\", \"popMax\", \"push\", \"peekMax\"]", "[[], [5], [], [], [1], []]"], ["[\"MaxStack\", \"push\", \"push\", \"push\", \"peekMax\", \"popMax\", \"peekMax\"]", "[[], [1], [1], [1], [], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"peekMax\", \"popMax\", \"top\", \"pop\"]", "[[], [6], [6], [], [], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"top\", \"peekMax\", \"popMax\", \"top\"]", "[[], [-5], [-2], [], [], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"push\", \"popMax\", \"top\"]", "[[], [5], [1], [5], [], []]"], ["[\"MaxStack\", \"push\", \"peekMax\", \"push\", \"peekMax\", \"popMax\", \"peekMax\"]", "[[], [4], [], [9], [], [], []]"], ["[\"MaxStack\", \"push\", \"top\", \"peekMax\"]", "[[], [0], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"push\", \"popMax\", \"pop\", \"peekMax\"]", "[[], [7], [7], [7], [], [], []]"], ["[\"MaxStack\", \"push\", \"top\", \"peekMax\", \"top\", \"pop\", \"push\", \"push\", \"top\", \"pop\", \"peekMax\", \"pop\", \"push\", \"top\", \"popMax\"]", "[[], [-6], [], [], [], [], [7], [-3], [], [], [], [], [-4], [], []]"], ["[\"MaxStack\", \"push\", \"top\", \"top\", \"pop\", \"push\", \"pop\", \"push\"]", "[[], [-15], [], [], [], [5], [], [13]]"], ["[\"MaxStack\", \"push\", \"pop\", \"push\", \"pop\", \"push\", \"peekMax\", \"pop\", \"push\", \"peekMax\", \"popMax\", \"push\", \"peekMax\", \"peekMax\", \"peekMax\"]", "[[], [-14], [], [-14], [], [-2], [], [], [14], [], [], [19], [], [], []]"], ["[\"MaxStack\", \"push\", \"push\", \"popMax\", \"top\", \"peekMax\", \"peekMax\"]", "[[], [18], [12], [], [], [], []]"], ["[\"MaxStack\", \"push\", \"peekMax\", \"top\", \"pop\", \"push\", \"push\", \"top\", \"top\", \"peekMax\", \"peekMax\", \"peekMax\"]", "[[], [8], [], [], [], [14], [3], [], [], [], [], []]"], ["[\"MaxStack\", \"push\", \"peekMax\", \"popMax\", \"push\", \"push\", \"pop\", \"popMax\", \"push\", \"top\", \"top\", \"pop\", \"push\"]", "[[], [20], [], [], [-10], [7], [], [], [-4], [], [], [], [12]]"], ["[\"MaxStack\", \"push\", \"peekMax\", \"popMax\", \"push\", \"peekMax\", \"top\", \"push\", \"peekMax\", \"top\", \"push\", \"pop\", \"push\", \"pop\"]", "[[], [13], [], [], [-5], [], [], [16], [], [], [20], [], [-20], []]"], ["[\"MaxStack\", \"push\", \"top\", \"popMax\", \"push\", \"push\", \"pop\", \"pop\", \"push\", \"popMax\"]", "[[], [-15], [], [], [9], [-2], [], [], [-2], []]"], ["[\"MaxStack\", \"push\", \"top\", \"push\", \"peekMax\", \"pop\", \"popMax\", \"push\", \"popMax\", \"push\", \"top\"]", "[[], [18], [], [-20], [], [], [], [20], [], [-16], []]"], ["[\"MaxStack\", \"push\", \"popMax\", \"push\", \"push\", \"push\", \"peekMax\", \"pop\", \"popMax\", \"popMax\", \"push\"]", "[[], [-15], [], [9], [-7], [17], [], [], [], [], [8]]"], ["[\"MaxStack\", \"push\", \"popMax\", \"push\", \"popMax\", \"push\", \"peekMax\", \"peekMax\", \"pop\", \"push\", \"peekMax\", \"push\", \"popMax\", \"popMax\", \"push\"]", "[[], [3], [], [-14], [], [-17], [], [], [], [17], [], [-12], [], [], [-2]]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "442", "slug": "max-sum-of-rectangle-no-larger-than-k", "id": 442, "title": "Max Sum of Rectangle No Larger Than K", "difficulty": "Hard", "category": "matrix", "link": "https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k/", "examples": [{"input": "matrix = [[1,0,1],[0,-2,3]], k = 2", "output": "2", "explanation": "The single cell holding 2 is the best rectangle at or below k."}, {"input": "matrix = [[2,2,-1]], k = 3", "output": "3", "explanation": "The submatrix [[2,2,-1]] itself sums to 3."}], "hints": ["Fix left and right column borders and compress rows into 1D column sums.", "For the 1D problem, scan prefix sums while keeping them in an ordered set.", "For each prefix cur, the ceiling of (cur - k) in the set yields the best subarray ending here."], "statement": "Given an `m x n` integer matrix and an integer `k`, find the largest sum of\nany rectangular submatrix whose sum is no larger than `k`. The test data always\ncontains at least one such rectangle (a single small-enough cell suffices).\n\nBrute force over all rectangles is too slow for the upper limits. Fixing the\nleft and right borders collapses each row strip into a 1D array, turning the\ninner task into finding the best subarray sum bounded by `k`, which an ordered\nset of prefix sums answers in logarithmic time.\n\n**Constraints:**\n- `1 <= m, n <= 20` (judge cases stay small enough for verification)\n- `-100 <= matrix[i][j] <= 100`\n- `-10^5 <= k <= 10^5`\n- At least one rectangle sums to `k` or less.\n", "solution": "## Approach\n\nEnumerate every pair of left/right column borders and collapse the strip into\nrow sums, reducing the 2D task to a 1D bounded-subarray task. Scanning prefix\nsums while storing them in a sorted set lets each position find the smallest\nearlier prefix that keeps the subarray sum at or below k.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2 * m log m) for an m x n matrix.\n- **Space Complexity:** O(m) for the strip sums and the prefix set.\n\n## Implementation\n\n```python\nimport bisect\nfrom typing import List\n\nclass Solution:\n def maxSumSubmatrix(self, matrix: List[List[int]], k: int) -> int:\n m, n = len(matrix), len(matrix[0])\n best = float(\"-inf\")\n for l in range(n):\n sums = [0] * m\n for r in range(l, n):\n for i in range(m):\n sums[i] += matrix[i][r]\n cur = 0\n seen = [0]\n for x in sums:\n cur += x\n j = bisect.bisect_left(seen, cur - k)\n if j < len(seen):\n best = max(best, cur - seen[j])\n if best == k:\n return k\n bisect.insort(seen, cur)\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxSumSubmatrix(matrix [][]int, k int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxSumSubmatrix(self, matrix: List[List[int]], k: int) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxSumSubmatrix(vector<vector<int>>& matrix, int k) {\n return 0;\n }\n};"}, "fn": "maxSumSubmatrix", "params": [{"name": "matrix", "type": "int_array_2d"}, {"name": "k", "type": "int"}], "outputType": "int", "tests": [["[[1,0,1],[0,-2,3]]", "2"], ["[[2,2,-1]]", "3"], ["[[5]]", "5"], ["[[-1,-2],[-3,-4]]", "-2"], ["[[1]]", "1"], ["[[1]]", "2"], ["[[-5]]", "-5"], ["[[2,2],[2,2]]", "8"], ["[[2,2],[2,2]]", "7"], ["[[2,2],[2,2]]", "4"], ["[[1,2,3],[4,5,6]]", "21"], ["[[1,2,3],[4,5,6]]", "12"], ["[[-1,2],[-3,4]]", "3"], ["[[5,-4,-3,4],[-3,-4,4,5],[5,1,5,-4]]", "8"], ["[[0,0],[0,0]]", "0"], ["[[0,0],[0,0]]", "5"], ["[[-2]]", "-1"], ["[[3,-1,2]]", "4"], ["[[3,-1,2]]", "2"], ["[[1],[2],[3]]", "5"], ["[[1],[2],[3]]", "6"], ["[[-1],[5],[-2],[4]]", "6"], ["[[1,2],[3,4],[5,6]]", "10"], ["[[1,-1],[1,-1],[1,-1]]", "2"], ["[[4,-2,-1,3]]", "3"], ["[[10,-5,2]]", "7"]], "expected": [2, 3, 5, -2, 1, 1, -5, 8, 4, 4, 21, 12, 2, 8, 0, 0, -2, 4, 2, 5, 6, 6, 10, 2, 3, 7], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "275", "slug": "maximal-rectangle", "id": 275, "title": "Maximal Rectangle", "difficulty": "Hard", "category": "matrix", "link": "https://leetcode.com/problems/maximal-rectangle/", "examples": [{"input": "matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]", "output": "6", "explanation": "The 2x3 block of 1s in rows 2-3 (0-based rows 1-2), columns 1-3 has area 6."}, {"input": "matrix = [[\"0\"]]", "output": "0", "explanation": "With no 1s, no rectangle exists."}, {"input": "matrix = [[\"1\"]]", "output": "1", "explanation": "The single cell forms a 1x1 rectangle."}], "hints": ["Build histogram heights column by column: reset to 0 on '0', else increment by 1.", "Score each histogram with a monotone increasing stack, flushing with a sentinel 0 at the end.", "Width for a popped bar is the distance to the new stack top minus one."], "statement": "Given a binary grid written with the characters `'0'` and `'1'`, find the area of the largest axis-aligned rectangle that contains only `'1'` cells.\n\nTreat each row as the base of a histogram whose bar heights count consecutive `'1'`s above (including the current row), then measure the biggest rectangle inside that histogram. The best value across all rows is the answer.\n\n> **Adaptation note:** the original LeetCode signature uses `char[][]`. This problem uses the portable `char_array_2d` type, which carries rows of single-character strings such as `[[\"1\",\"0\"],[\"0\",\"1\"]]`. Values are still only `\"0\"` and `\"1\"`.\n\n**Constraints:**\n- `1 <= matrix.length <= 200`\n- `1 <= matrix[0].length <= 200`\n- Each entry is `\"0\"` or `\"1\"`.\n", "solution": "## Approach\n\nAccumulate column heights of consecutive 1s row by row, turning each row into a histogram. Evaluate every histogram with a monotone stack that pops taller bars and measures height times available width, keeping the maximum over all rows.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m*n), each cell pushed and popped at most once.\n- **Space Complexity:** O(n) for the heights and the stack.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maximalRectangle(self, matrix: List[List[str]]) -> int:\n if not matrix or not matrix[0]:\n return 0\n n = len(matrix[0])\n h = [0] * (n + 1)\n best = 0\n for row in matrix:\n for j in range(n):\n h[j] = h[j] + 1 if row[j] == \"1\" else 0\n st = []\n for j in range(n + 1):\n cur = 0 if j == n else h[j]\n while st and cur < h[st[-1]]:\n height = h[st.pop()]\n left = st[-1] if st else -1\n best = max(best, height * (j - left - 1))\n st.append(j)\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaximalRectangle(matrix [][]byte) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maximalRectangle(self, matrix: List[List[str]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maximalRectangle(vector<vector<char>>& matrix) {\n return 0;\n }\n};"}, "fn": "maximalRectangle", "params": [{"name": "matrix", "type": "char_array_2d"}], "outputType": "int", "tests": [["[[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]"], ["[[\"0\"]]"], ["[[\"1\"]]"], ["[[\"1\",\"1\"],[\"1\",\"1\"]]"], ["[[\"0\",\"0\"],[\"0\",\"0\"]]"], ["[[\"1\",\"0\"],[\"0\",\"1\"]]"], ["[[\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\"]]"], ["[[\"1\"],[\"1\"],[\"1\"]]"], ["[[\"1\",\"1\",\"1\"]]"], ["[[\"0\",\"1\",\"1\",\"0\"]]"], ["[[\"1\",\"0\",\"1\",\"1\",\"0\",\"1\"]]"], ["[[\"1\",\"1\",\"0\",\"1\"],[\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"0\",\"1\"],[\"1\",\"0\"]]"], ["[[\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"1\"],[\"0\"],[\"1\"],[\"1\"]]"], ["[[\"1\",\"0\",\"0\"],[\"0\",\"1\",\"1\"],[\"1\",\"1\",\"0\"]]"], ["[[\"1\",\"1\",\"0\",\"0\",\"1\"],[\"0\",\"1\",\"1\",\"1\",\"0\"],[\"1\",\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"0\",\"0\",\"0\"],[\"0\",\"0\",\"0\"]]"], ["[[\"1\",\"1\"],[\"0\",\"1\"],[\"1\",\"1\"]]"], ["[[\"1\",\"0\",\"1\"],[\"1\",\"1\",\"1\"],[\"0\",\"1\",\"0\"]]"], ["[[\"1\",\"1\",\"1\",\"0\",\"1\"]]"], ["[[\"0\",\"1\",\"0\",\"1\",\"0\"]]"], ["[[\"1\",\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"1\"],[\"1\"],[\"0\"],[\"1\"],[\"1\"]]"], ["[[\"0\",\"0\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\"],[\"0\",\"1\",\"1\",\"0\"]]"], ["[[\"1\",\"0\"],[\"1\",\"0\"],[\"1\",\"0\"],[\"1\",\"1\"]]"], ["[[\"0\",\"1\",\"1\",\"1\",\"0\",\"1\",\"1\"]]"], ["[[\"1\",\"1\",\"0\"],[\"1\",\"1\",\"0\"],[\"1\",\"1\",\"1\"]]"], ["[[\"1\",\"0\",\"1\",\"0\"],[\"0\",\"1\",\"0\",\"1\"]]"], ["[[\"1\",\"1\",\"1\"],[\"0\",\"0\",\"0\"],[\"1\",\"1\",\"1\"]]"]], "expected": [6, 0, 1, 4, 0, 1, 6, 3, 3, 2, 2, 4, 1, 4, 2, 2, 6, 0, 3, 3, 3, 1, 5, 2, 4, 4, 3, 6, 1, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "336", "slug": "maximal-square", "id": 336, "title": "Maximal Square", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/maximal-square/", "examples": [{"explanation": "The 2x2 block of 1s in rows 1-2, columns 2-3 (0-based) has area 4.", "input": "matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]", "output": "4"}, {"explanation": "No 2x2 all-1 square exists, but single 1s do, so the area is 1.", "input": "matrix = [[\"0\",\"1\"],[\"1\",\"0\"]]", "output": "1"}, {"explanation": "There is no 1 at all.", "input": "matrix = [[\"0\"]]", "output": "0"}], "hints": ["Let dp[i][j] be the side of the biggest all-1 square ending at (i, j): it extends the squares above, to the left, and diagonally above-left.", "On a '1', dp[i][j] = 1 + min of those three neighbours; on a '0' it is 0.", "Track the largest side seen and return its square; a single row of state suffices."], "statement": "You are given a grid `matrix` of `'0'` and `'1'` characters. Find the largest square that consists entirely of `'1'`s and return its area (side length squared).\n\n**Constraints:**\n- `1 <= matrix.length, matrix[0].length <= 300`\n- `matrix[i][j]` is `'0'` or `'1'`.\n", "solution": "## Approach\n\nTreat each cell as the bottom-right corner of a square: on a `'1'`, its side equals one plus the minimum of the squares ending above, to the left, and diagonally above-left, since all three must extend together. A `'0'` ends every square there. Keeping the largest side seen and squaring it gives the maximal area, using a single rolling row of state.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n) for one pass over the grid.\n- **Space Complexity:** O(n) for the rolling row.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def maximalSquare(self, matrix: List[List[str]]) -> int:\n if not matrix or not matrix[0]:\n return 0\n cols = len(matrix[0])\n dp = [0] * (cols + 1)\n best = 0\n for row in matrix:\n prev = 0\n for j, cell in enumerate(row, start=1):\n tmp = dp[j]\n if cell == \"1\":\n dp[j] = 1 + min(dp[j], dp[j - 1], prev)\n best = max(best, dp[j])\n else:\n dp[j] = 0\n prev = tmp\n return best * best\n```\n", "starter": {"go": "package main\n\nfunc MaximalSquare(matrix [][]byte) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maximalSquare(self, matrix: List[List[str]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maximalSquare(vector<vector<char>>& matrix) {\n return 0;\n }\n};"}, "fn": "maximalSquare", "params": [{"name": "matrix", "type": "char_array_2d"}], "outputType": "int", "tests": [["[[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]"], ["[[\"0\",\"1\"],[\"1\",\"0\"]]"], ["[[\"0\"]]"], ["[[\"1\"]]"], ["[[\"1\",\"1\"],[\"1\",\"1\"]]"], ["[[\"0\",\"0\"],[\"0\",\"0\"]]"], ["[[\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\"]]"], ["[[\"1\",\"0\",\"1\"],[\"0\",\"1\",\"0\"],[\"1\",\"0\",\"1\"]]"], ["[[\"1\",\"1\",\"0\",\"1\"]]"], ["[[\"1\"],[\"1\"],[\"0\"],[\"1\"]]"], ["[[\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"0\",\"1\",\"1\",\"0\"],[\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"1\",\"0\",\"1\",\"1\",\"1\"]]"], ["[[\"1\",\"1\"],[\"1\",\"0\"]]"], ["[[\"0\",\"1\"],[\"1\",\"1\"]]"], ["[[\"1\",\"1\",\"0\"],[\"1\",\"1\",\"0\"],[\"0\",\"0\",\"1\"]]"], ["[[\"1\",\"0\",\"0\",\"1\"],[\"1\",\"1\",\"1\",\"1\"],[\"0\",\"1\",\"1\",\"1\"]]"], ["[[\"0\",\"0\",\"0\"],[\"0\",\"1\",\"0\"],[\"0\",\"0\",\"0\"]]"], ["[[\"1\",\"1\",\"1\",\"0\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"1\",\"0\",\"1\",\"0\"],[\"1\",\"0\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\"],[\"0\",\"1\",\"1\",\"1\"]]"], ["[[\"1\",\"1\",\"1\"],[\"1\",\"0\",\"1\"],[\"1\",\"1\",\"1\"]]"], ["[[\"0\",\"0\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"1\",\"1\",\"0\",\"0\"],[\"0\",\"1\",\"1\",\"0\"],[\"0\",\"0\",\"1\",\"1\"]]"], ["[[\"1\",\"1\",\"1\",\"1\",\"1\"]]"], ["[[\"1\"],[\"0\"],[\"1\"],[\"1\"],[\"1\"]]"], ["[[\"0\",\"1\",\"0\"],[\"1\",\"1\",\"1\"],[\"0\",\"1\",\"0\"]]"], ["[[\"1\",\"0\",\"1\",\"1\",\"0\",\"1\"]]"]], "expected": [4, 1, 0, 1, 4, 0, 9, 1, 1, 1, 1, 4, 1, 1, 1, 4, 4, 1, 4, 4, 9, 1, 4, 1, 1, 1, 1, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "846", "slug": "maximize-distance-to-closest-person", "id": 846, "title": "Maximize Distance to Closest Person", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximize-distance-to-closest-person/", "examples": [{"input": "seats = [1,0,0,0,1,0,1]", "output": "2", "explanation": "Seat 2 is two away from both sides."}, {"input": "seats = [1,0,0,0]", "output": "3", "explanation": "Far end reaches distance 3."}, {"input": "seats = [0,1]", "output": "1", "explanation": "Only free chair is adjacent."}], "hints": ["Edge gaps count fully (leading or trailing zeros), while interior gaps split in half rounding up.", "Scan once remembering the previous occupied index to measure each empty stretch.", "Track the maximum over edge stretches and halved interior stretches."], "statement": "Choose an empty seat that stays farthest from anyone seated.\n\nThe array `seats` marks chairs with `1` for occupied and `0` for empty; at least one of each exists. You must sit in an empty chair. Your distance to the closest occupied chair should be as large as possible. Return that best achievable distance.\n\n**Constraints:**\n- `2 <= seats.length <= 20000`\n- `seats[i]` is `0` or `1`, with at least one of each.\n", "solution": "## Approach\n\nRemember the last occupied chair while scanning. A leading empty run scores its full length, each interior run between two people scores half its span rounded up (integer division of the gap), and the trailing run scores its full length. The maximum over these runs is the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the seat count, in a single pass.\n- **Space Complexity:** O(1) extra.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxDistToClosest(self, seats: List[int]) -> int:\n best, prev, n = 0, -1, len(seats)\n for i, v in enumerate(seats):\n if v == 1:\n if prev < 0:\n best = i\n else:\n best = max(best, (i - prev) // 2)\n prev = i\n best = max(best, n - 1 - prev)\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxDistToClosest(seats []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxDistToClosest(self, seats: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxDistToClosest(vector<int>& seats) {\n return 0;\n }\n};"}, "fn": "maxDistToClosest", "params": [{"name": "seats", "type": "int_array"}], "outputType": "int", "tests": [["[1,0,0,0,1,0,1]"], ["[1,0,0,0]"], ["[0,1]"], ["[1,0,1]"], ["[1,0,0,1]"], ["[0,0,1]"], ["[1,0,0]"], ["[0,0,0,1]"], ["[1,0,0,0,0,1]"], ["[1,1,1,0,1]"], ["[0,1,0]"], ["[1,0]"], ["[0,0,1,0,0]"], ["[1,0,0,0,0,0,1]"], ["[0,1,0,0,0,1,0]"], ["[1,0,1,0,1,0,1]"], ["[0,0,0,0,1]"], ["[1,0,0,0,0]"], ["[1,0,0,1,0,0,1]"], ["[0,1,0,1,0]"], ["[1,0,0,0,1,1,1]"], ["[0,0,1,1,0,0]"], ["[1,1,0,0,1,0,0,1]"], ["[0,1,1,1,0]"], ["[1,0,1,0,0,0,1,0,1]"], ["[0,0,1,0,1,0,0]"], ["[1,0,0,0,0,0,0,1]"], ["[0,1,0,0,1,0,1,0,0,1]"]], "expected": [2, 3, 1, 1, 1, 2, 2, 3, 2, 1, 1, 1, 2, 3, 2, 1, 4, 4, 1, 1, 2, 2, 1, 1, 2, 2, 3, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "665", "slug": "maximum-average-subarray-i", "id": 665, "title": "Maximum Average Subarray I", "difficulty": "Easy", "category": "sliding-window", "link": "https://leetcode.com/problems/maximum-average-subarray-i/", "examples": [{"input": "nums = [1,12,-5,-6,50,3], k = 4", "output": "\"12.75\"", "explanation": "The block [12,-5,-6,50] sums to 51, averaging 12.75, the best of the three windows."}, {"input": "nums = [5], k = 1", "output": "\"5.0\""}, {"input": "nums = [-1,-2,-3], k = 2", "output": "\"-1.5\""}], "hints": ["This is a portable adaptation: return the average as a finite, double-parseable decimal string.", "Sum the first window, then slide it by adding the newcomer and dropping the leaver while tracking the best sum.", "Divide the best sum by k only once, at the end."], "statement": "Given an integer array `nums` and a window length `k`, look at every contiguous block of exactly `k` elements and return the largest block average.\n\nBecause averages are fractional, this judge passes them as decimal strings: implement `findMaxAverage(nums, k)` returning a string parseable as a double. An answer is accepted when it sits within `1e-5` of the true maximum average.\n\n**Constraints:**\n- `1 <= k <= nums.length <= 10^5`\n- `-10^4 <= nums[i] <= 10^4`\n- The output must be a finite decimal string parseable as a double.\n", "solution": "## Approach\n\nAdd up the first window of length k, then slide the window across the array by adding each newcomer and subtracting the element that falls out. The largest window sum seen, divided once by k, is the maximum average, formatted as a decimal string.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the array length. Each element enters and leaves the window once.\n- **Space Complexity:** O(1) beyond the input.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> str:\n cur = sum(nums[:k])\n best = cur\n for i in range(k, len(nums)):\n cur += nums[i] - nums[i - k]\n best = max(best, cur)\n return str(best / k)\n```\n", "starter": {"go": "package main\n\nfunc FindMaxAverage(nums []int, k int) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> str:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string findMaxAverage(vector<int>& nums, int k) {\n return \"\";\n }\n};"}, "fn": "findMaxAverage", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "string", "tests": [["[1,12,-5,-6,50,3]", "4"], ["[5]", "1"], ["[-1,-2,-3]", "2"], ["[1,2,3,4,5]", "2"], ["[5,5,5,5]", "4"], ["[-10,10,-10,10]", "2"], ["[0,0,0,0]", "1"], ["[10000,-10000,10000,-10000]", "3"], ["[1,1,1,7,8,9]", "3"], ["[-5,-4,-3,-2,-1]", "3"], ["[3,3,3,3,3,3]", "2"], ["[1,12,-5,-6,50,3]", "1"], ["[1,12,-5,-6,50,3]", "6"], ["[4,2,1,3,3]", "2"], ["[0,1,1,3,3]", "4"], ["[-1]", "1"], ["[9,7,3,5,6,2,0,8]", "4"], ["[2,2,2,2,-10,2,2]", "3"], ["[-10000]", "1"], ["[1,2]", "2"], ["[10,-10,10,-10,10]", "2"], ["[7,4,5,8,8,3,9,8,4,5]", "5"], ["[0,-1,2,-3,4]", "3"], ["[100,200,300,400]", "2"], ["[-2,1,-3,4,-1,2,1,-5,4]", "3"], ["[6,6,6,0,0,0,6,6]", "4"], ["[1,3,2,6,-1,4,1,8,2]", "5"], ["@javascript:JSON.stringify(Array.from({length:20000},(_,i)=>(i*37)%20001-10000))", "5000"]], "expected": ["12.75", "5.0", "-1.5", "4.5", "5.0", "0.0", "0.0", "3333.3333333333335", "8.0", "-2.0", "3.0", "50.0", "9.166666666666666", "3.0", "2.0", "-1.0", "6.0", "2.0", "-10000.0", "1.5", "0.0", "7.2", "1.0", "350.0", "1.6666666666666667", "4.5", "3.6", "205.6352"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "666", "slug": "maximum-average-subarray-ii", "id": 666, "title": "Maximum Average Subarray II", "difficulty": "Hard", "category": "binary-search", "link": "https://leetcode.com/problems/maximum-average-subarray-ii/", "examples": [{"input": "nums = [1,12,-5,-6,50,3], k = 4", "output": "\"12.75\"", "explanation": "The length-4 block [12,-5,-6,50] averages 12.75, beating every longer block."}, {"input": "nums = [5], k = 1", "output": "\"5.0\""}, {"input": "nums = [1,2,3,4,5], k = 1", "output": "\"5.0\"", "explanation": "With minimum length 1 the best block is the single largest element."}], "hints": ["This is a portable adaptation: return the average as a finite, double-parseable decimal string.", "Binary-search the answer: for a candidate mid, check whether any block of length >= k in (nums[i] - mid) has a non-negative sum.", "The check uses prefix sums with the smallest prefix seen at least k steps back; about 50 iterations settle 1e-5 precision."], "statement": "Given an integer array `nums` and a minimum length `k`, look at every contiguous block of length at least `k` and return the largest block average.\n\nBecause averages are fractional, this judge passes them as decimal strings: implement `findMaxAverage(nums, k)` returning a string parseable as a double. An answer is accepted when it sits within `1e-5` of the true optimum.\n\n**Constraints:**\n- `1 <= k <= nums.length <= 10^4`\n- `-10^4 <= nums[i] <= 10^4`\n- The output must be a finite decimal string parseable as a double.\n", "solution": "## Approach\n\nBinary-search the best average value. For a guess `mid`, subtract it from every element and ask whether any block of length at least k sums to zero or more, which is true exactly when `mid` is achievable. The check runs in linear time with prefix sums that remember the smallest prefix at least k positions back. Sixty halvings pin the value far beyond the required tolerance.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log precision), with n the array length and about 60 probe rounds.\n- **Space Complexity:** O(n) for the prefix sums.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> str:\n def ok(mid):\n pre = [0.0]\n for v in nums:\n pre.append(pre[-1] + v - mid)\n best = 0.0\n for i in range(k, len(pre)):\n best = min(best, pre[i - k])\n if pre[i] - best >= 0:\n return True\n return False\n lo, hi = min(nums), max(nums)\n for _ in range(60):\n mid = (lo + hi) / 2\n if ok(mid):\n lo = mid\n else:\n hi = mid\n return str(lo)\n```\n", "starter": {"go": "package main\n\nfunc FindMaxAverage(nums []int, k int) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def findMaxAverage(self, nums: List[int], k: int) -> str:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string findMaxAverage(vector<int>& nums, int k) {\n return \"\";\n }\n};"}, "fn": "findMaxAverage", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "string", "tests": [["[1,12,-5,-6,50,3]", "4"], ["[5]", "1"], ["[1,2,3,4,5]", "1"], ["[1,2,3,4,5]", "3"], ["[-1,-2,-3,-4]", "2"], ["[4,2,1,3,3]", "2"], ["[0,0,0,0]", "1"], ["[8,0,8,0,8]", "2"], ["[1,12,-5,-6,50,3]", "6"], ["[1,12,-5,-6,50,3]", "2"], ["[-5,-4,-3,-2,-1]", "2"], ["[10,-10,10,-10,10]", "3"], ["[2,2,2,2,2]", "3"], ["[9,7,3,5,6,2,0,8]", "4"], ["[0,1,1,3,3]", "4"], ["[10000,-10000]", "1"], ["[3,-1,4,-1,5,-9,2,6]", "3"], ["[1,1,1,7,8,9]", "3"], ["[-10,10,-10,10,-10,10]", "4"], ["[5,4,3,2,1]", "2"], ["[1,3,2,6,-1,4,1,8,2]", "2"], ["[6,-2,3,-4,5,1]", "3"], ["[0,-1,2,-3,4,-5]", "2"], ["[7,4,5,8,8,3,9,8,4,5]", "5"], ["[1,2]", "1"], ["[1,2]", "2"], ["[-10000,10000,-10000,10000]", "2"], ["@javascript:JSON.stringify(Array.from({length:8000},(_,i)=>(i*53)%20001-10000))", "100"]], "expected": ["12.75", "4.999999999999988", "4.999999999999988", "3.9999999999999933", "-1.5000000000000084", "2.9999999999999996", "0.0", "5.333333333333318", "9.166666666666664", "26.499999999999996", "-1.5000000000000084", "3.333333333333331", "1.999999999999988", "5.999999999999999", "1.999999999999988", "10000.0", "2.6666666666666505", "7.999999999999987", "1.999999999999988", "4.499999999999989", "4.999999999999988", "2.333333333333319", "0.999999999999994", "7.199999999999984", "1.999999999999988", "1.4999999999999911", "3333.333333333334", "7376.500000001863"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "979", "slug": "maximum-binary-tree-ii", "id": 979, "title": "Maximum Binary Tree II", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/maximum-binary-tree-ii/", "examples": [{"input": "root = [4,1,3,null,null,2], val = 5", "output": "[5,4,null,1,3,null,null,2]", "explanation": "5 exceeds every existing value, so it becomes the new root with the old tree on its left."}, {"input": "root = [5,2,4,null,1], val = 3", "output": "[5,2,4,null,1,null,3]", "explanation": "3 settles as the right child of 4."}, {"input": "root = [5,2,3,null,1], val = 4", "output": "[5,2,4,null,1,3]", "explanation": "4 takes the place of 3, which slides down to become its left child."}], "hints": ["The appended value only disturbs the rightmost path, since everything left of the old maximum stays left of it.", "Walk down right children: if val beats the current node, splice a new node in and hang the current subtree left.", "Otherwise recurse into the right child; an empty right child simply receives the new leaf."], "statement": "A maximum binary tree is built from an array by a simple rule: the largest\nvalue becomes the root, the same rule applied to the part left of it builds\nthe left subtree, and the same rule applied to the part right of it builds the\nright subtree.\n\nYou are given the `root` of such a tree (constructed from some array `a`) and\na new integer `val` that is appended to `a`. Rebuild the tree for the extended\narray, returning its new root. The original tree must be reused rather than\nreconstructed from scratch: the change only affects nodes along one path.\n\n**Constraints:**\n- The number of nodes is between `1` and `100`.\n- `1 <= Node.val <= 100`\n- All node values are distinct.\n- `1 <= val <= 100`\n", "solution": "## Approach\n\nAppending `val` to the underlying array only affects the rightmost path of\nthe tree, because every element left of the old maximum keeps its relative\nposition. Compare `val` with the current node: if it is larger, the current\nsubtree becomes the left child of a fresh node holding `val`. Otherwise the\ncurrent node stays on top and the same step repeats on its right child, with\nan empty right child simply receiving the new leaf.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(h), where h is the height of the tree (at most n). Only the right spine is walked.\n- **Space Complexity:** O(h) for the recursion stack.\n\n## Implementation\n\n```python\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\nclass Solution:\n def insertIntoMaxTree(self, root, val: int):\n if root is None:\n return TreeNode(val)\n if val > root.val:\n return TreeNode(val, root, None)\n root.right = self.insertIntoMaxTree(root.right, val)\n return root\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc InsertIntoMaxTree(root *TreeNode, val int) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def insertIntoMaxTree(self, root, val: int):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* insertIntoMaxTree(TreeNode* root, int val) {\n \n }\n};"}, "fn": "insertIntoMaxTree", "params": [{"name": "root", "type": "tree_node"}, {"name": "val", "type": "int"}], "outputType": "tree_node", "tests": [["[4,1,3,null,null,2]", "5"], ["[5,2,4,null,1]", "3"], ["[5,2,3,null,1]", "4"], ["[1]", "2"], ["[2,1]", "3"], ["[3,2,1]", "4"], ["[3,null,2,null,1]", "0"], ["[5,null,4,null,3,null,2,null,1]", "6"], ["[5,null,4,null,3,null,2,null,1]", "0"], ["[7,3,9,1,5,null,10]", "8"], ["[7,3,9,1,5,null,10]", "11"], ["[7,3,9,1,5,null,10]", "0"], ["[4,1,3,null,null,2]", "1"], ["[4,1,3,null,null,2]", "6"], ["[10,5,15,2,7,12,20]", "13"], ["[10,5,15,2,7,12,20]", "25"], ["[10,5,15,2,7,12,20]", "1"], ["[2,null,3,null,4]", "1"], ["[2,null,3,null,4]", "5"], ["[9,5,null,3,null,1]", "7"], ["[9,5,null,3,null,1]", "10"], ["[9,5,null,3,null,1]", "0"], ["[6,2,8,1,4,7,9]", "5"], ["[6,2,8,1,4,7,9]", "3"], ["[6,2,8,1,4,7,9]", "10"], ["[1,null,2,null,3]", "4"], ["[1,null,2,null,3]", "0"], ["[8,3,null,1]", "5"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "674", "slug": "maximum-binary-tree", "id": 674, "title": "Maximum Binary Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/maximum-binary-tree/", "examples": [{"input": "nums = [3,2,1,6,0,5]", "output": "[6,3,5,null,2,0,null,null,1]", "explanation": "The largest entry 6 becomes the root; the left slice builds the left branch and the right slice builds the right branch."}, {"input": "nums = [3,2,1]", "output": "[3,null,2,null,1]", "explanation": "Each maximum sits at the top of its remaining slice, forming a right-leaning chain."}], "hints": ["The biggest entry of the current slice is the root of that branch.", "Everything left of the maximum builds the left child; everything right builds the right child.", "Recurse on each slice until it is empty."], "statement": "You are given an array `nums` with all distinct values.\n\nBuild the maximum binary tree as follows, applied recursively to each slice of the array:\n\n- Find the largest value in the slice; it becomes the root of this branch.\n- The part of the slice left of that maximum forms the left subtree by the same rule.\n- The part of the slice right of that maximum forms the right subtree by the same rule.\n\nReturn the root of the finished tree.\n\n**Constraints:**\n- `1 <= nums.length <= 1000`\n- `0 <= nums[i] <= 1000`\n- All values are distinct.\n", "solution": "## Approach\n\nScan the current slice for its maximum and make it the root. The entries left of it and right of it are independent slices, so build each side with the same procedure. An empty slice yields no child. Because values are distinct the result is unique.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) in the worst case from scanning each slice; O(n log n) average.\n- **Space Complexity:** O(n) for recursion depth and the tree itself.\n\n## Implementation\n\n```python\nfrom typing import List\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\nclass Solution:\n def constructMaximumBinaryTree(self, nums: List[int]):\n def build(l, r):\n if l > r:\n return None\n m = max(range(l, r + 1), key=lambda i: nums[i])\n node = TreeNode(nums[m])\n node.left = build(l, m - 1)\n node.right = build(m + 1, r)\n return node\n return build(0, len(nums) - 1)\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 ConstructMaximumBinaryTree(nums []int) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nfrom typing import List\nclass Solution:\n def constructMaximumBinaryTree(self, nums: List[int]):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n TreeNode* constructMaximumBinaryTree(vector<int>& nums) {\n return nullptr;\n }\n};"}, "fn": "constructMaximumBinaryTree", "params": [{"name": "nums", "type": "int_array"}], "outputType": "tree_node", "tests": [["[3,2,1,6,0,5]"], ["[3,2,1]"], ["[1]"], ["[1,2]"], ["[2,1]"], ["[1,2,3]"], ["[3,1,2]"], ["[5,4,3,2,1]"], ["[1,2,3,4,5]"], ["[6,1,7,2,8,3]"], ["[0,10,0,10,0]"], ["[4,1,3,2,5]"], ["[9,1,2,3,4,5]"], ["[1,9,2,8,3,7]"], ["[2,5,1,4,3]"], ["[7]"], ["[10,20,30,5,15]"], ["[3,6,1,5,2,4]"], ["[8,3,9,1,10,2]"], ["[1,4,2,5,3]"], ["[100,0,200,1,150]"], ["[2,3,1,5,4]"], ["[9,8,7,1,2,3]"], ["[1,3,2,6,4,5]"], ["[5,1,4,2,3]"], ["[0,1,0,2,0,3]"], ["[11,5,9,2,7,1,10]"], ["[6,5,4,3,2,1,7]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "60", "slug": "maximum-depth-of-binary-tree", "id": 60, "title": "Maximum Depth of Binary Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/maximum-depth-of-binary-tree/", "examples": [{"input": "root = [3,9,20,null,null,15,7]", "output": "3", "explanation": "The maximum depth (root-to-leaf longest path) is 3."}, {"input": "root = [1,null,2]", "output": "2", "explanation": "The maximum depth (root-to-leaf longest path) is 2."}, {"input": "root = []", "output": "0", "explanation": "The maximum depth (root-to-leaf longest path) is 0."}], "hints": ["Compute the maximum depth of a binary tree."], "statement": "You are handed the `root` of a binary tree. Compute how deep the tree is, where depth is measured as the count of nodes on the longest downward route that begins at `root` and finishes at a leaf farthest away.\n\n**Constraints:**\n\n- The number of nodes in the tree is in the range [0, 10^4].\n- -100 \u2264 Node.val \u2264 100\n", "solution": "## Approach\nRecursive DFS: the maximum depth of a node is 1 plus the maximum depth of its left and right children. Return 0 for a null node.\n\n## Complexity Analysis\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(h)\n\n## Implementation\n```python\nfrom typing import Optional\nclass Solution:\n def maxDepth(self, root: Optional[TreeNode]) -> int:\n if not root:\n return 0\n return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc MaxDepth(root *TreeNode) int {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def maxDepth(self, root):\n # TODO: return the maximum depth of the binary tree\n pass\n", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n int maxDepth(TreeNode* root) {\n \n }\n};\n"}, "fn": "maxDepth", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int", "tests": [["[3,9,20,null,null,15,7]"], ["[1,null,2]"], ["[]"], ["[1]"], ["[-1]"], ["[1,2,3,4,5,6,7]"], ["[1,2,3,null,4,null,5]"], ["[0,null,0,null,0,null,0]"], ["[1,2]"], ["[1,null,2,null,3]"], ["[1,2,3,4,null,null,5]"], ["[5,4,null,3,null,2]"], ["[1,2,3,4,5,6]"], ["[10,5,15]"], ["[-100,100,-100]"], ["[0]"], ["[100]"], ["[-100]"], ["[1,2,null,3,null,4]"], ["[1,null,2,null,3,null,4]"], ["[2,1,3]"], ["[50,25,75,10,30,60,90]"], ["[1,2,2,3,3,3,3]"], ["[7,7,7,7,7]"], ["[1,null,1,null,1]"], ["[9,8,null,7,null,6]"], ["[3,1,4,null,2]"], ["[0,0,0,0,0,0,0]"], ["[-5,-10,0,null,-7]"], ["[42]"], ["[1,2,3,null,null,4,5]"], ["[11,null,22,null,33]"]], "expected": [3, 2, 0, 1, 1, 3, 3, 4, 2, 3, 3, 4, 3, 2, 2, 1, 1, 1, 4, 4, 2, 3, 3, 3, 3, 4, 3, 3, 3, 1, 3, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "615", "slug": "maximum-depth-of-n-ary-tree", "id": 615, "title": "Maximum Depth of N-ary Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/maximum-depth-of-n-ary-tree/", "examples": [{"input": "data = \"[1,null,3,2,4,null,5,6]\"", "output": "3", "explanation": "The chain 1 -> 3 -> 5 uses three nodes."}, {"input": "data = \"[]\"", "output": "0", "explanation": "No nodes means depth zero."}, {"input": "data = \"[1]\"", "output": "1", "explanation": "The lone root is itself the longest path."}], "hints": ["Split the bracket string on commas; null tokens mark the end of each node's child group.", "Rebuild the tree with a queue: each group after a null belongs to the next queued node.", "Depth is one plus the deepest child subtree (a leaf contributes 1); a breadth-first level count works too."], "statement": "Given an N-ary tree, return the number of nodes on the longest path from the root down to any leaf. An empty tree has depth 0 and a single node has depth 1.\n\nInput encoding: the tree arrives as a single string `data` holding a bracketed, comma-separated token list. The first token is the root value; afterwards each node's children appear as a group terminated by `null`, in level order. For example `\"[1,null,3,2,4,null,5,6]\"` means root 1 with children 3, 2, 4, where node 3 parents 5 and 6. The empty tree is `\"[]\"`.\n\n**Constraints:**\n- The token count is at most 10^4.\n- Node values fit in a 32-bit signed integer.\n- The tree depth is at most 1000.\n", "solution": "## Approach\n\nTokenize the bracket string and reconstruct the N-ary tree level by level: after the root, every `null` token ends the current child group and the values that follow become the next queued node's children. A depth-first walk then returns one plus the deepest child depth, with leaves yielding one and a missing root yielding zero.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of tokens.\n- **Space Complexity:** O(n) for the rebuilt tree and the queue.\n\n## Implementation\n\n```python\nfrom collections import deque\n\nclass Solution:\n def maxDepth(self, data: str) -> int:\n t = data.strip()\n if t in (\"\", \"[]\"):\n return 0\n toks = [p.strip() for p in t[1:-1].split(\",\") if p.strip()]\n if not toks or toks[0] == \"null\":\n return 0\n nodes = [int(toks[0])]\n children_of = {0: []}\n q = deque([0])\n nodes = [int(toks[0])]\n i = 1\n while q and i < len(toks):\n u = q.popleft()\n if i < len(toks) and toks[i] == \"null\":\n i += 1\n while i < len(toks) and toks[i] != \"null\":\n nodes.append(int(toks[i]))\n v = len(nodes) - 1\n children_of.setdefault(u, []).append(v)\n children_of.setdefault(v, [])\n q.append(v)\n i += 1\n def depth(u):\n best = 0\n for v in children_of.get(u, []):\n best = max(best, depth(v))\n return 1 + best\n return depth(0)\n```\n", "starter": {"go": "package main\n\nfunc MaxDepth(data string) int {\n return 0\n}", "python": "class Solution:\n def maxDepth(self, data: str) -> int:\n return 0\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int maxDepth(string data) {\n return 0;\n }\n};"}, "fn": "maxDepth", "params": [{"name": "data", "type": "string"}], "outputType": "int", "tests": [["[1,null,3,2,4,null,5,6]"], ["[1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14]"], ["[]"], ["[1]"], ["[1,null,2,null,3,null,4]"], ["[1,null,2,3,4,5,6,7,8,9,10]"], ["[1,null,2,null,3]"], ["[5]"], ["[1,null,2,3]"], ["[1,2,3]"], ["[10,null,20,30,null,40]"], ["[1,null,2,null,3,null,4,null,5]"], ["[1,null,2,null,3,null,4,null,5,null,6]"], ["[2,null,1]"], ["[1,null,5,4,3,2,1]"], ["[7,null,7,7,7,null,7]"], ["[1,null,2,3,null,4,5,6]"], ["[3,null,1,2]"], ["[100,null,1,2,3,4,5]"], ["[1,null,2,null,4,null,8,null,16]"], ["[0]"], ["[1,null,2]"], ["[1,null,2,null,3,null,4,null,5,null,6,null,7]"], ["[4,null,1,3,2]"], ["[9,null,8,null,7,null,6]"], ["[1,null,2,3,4,null,5,null,6,7]"], ["[6,null,1,2,3,4,5,6,7,8]"], ["[8,null,1,null,2,null,3,null,4]"]], "expected": [3, 5, 0, 1, 4, 2, 3, 1, 2, 2, 3, 5, 6, 2, 2, 3, 3, 2, 2, 5, 1, 2, 7, 2, 4, 3, 2, 5], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "648", "slug": "maximum-distance-in-arrays", "id": 648, "title": "Maximum Distance in Arrays", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximum-distance-in-arrays/", "examples": [{"input": "arrays = [[1,2,3],[4,5],[1,2,3]]", "output": "4", "explanation": "Pick 1 from the first array and 5 from the second; |1-5| = 4 is best."}, {"input": "arrays = [[1],[1]]", "output": "0", "explanation": "Only 1 and 1 are available, so the gap is 0."}, {"input": "arrays = [[1,4],[2,5]]", "output": "4", "explanation": "Pair 1 from the first array with 5 from the second for a gap of 4."}], "hints": ["Each array is sorted, so only its first and last entries can matter for extremes.", "Track the smallest first-element and largest last-element seen so far while sweeping left to right.", "For the current array, test its last against the running minimum and its first against the running maximum before folding it in; this guarantees different arrays.", "Adaptation: the nested input maps to int_array_2d in this judge."], "statement": "You are given `m` arrays, each sorted in non-decreasing order. Choose two numbers coming from two different arrays and look at their absolute difference. Return the largest achievable difference.\n\nBecause every row is ordered, only row endpoints influence the optimum, but the two picks must never share a row.\n\n**Constraints:**\n- At least two arrays are present; total values are modest.\n- Each array has at least one number; values fit in [-10000, 10000].\n\n*Adaptation: the nested input maps to `int_array_2d` in this judge.*\n", "solution": "## Approach\n\nSweep the rows once while remembering the smallest seen opening value and the largest seen closing value. For each new row, its closing value against the running minimum and its opening value against the running maximum are the only candidates that can beat the answer while respecting the different-rows rule. Update the best, then fold the row endpoints into the running extremes. Sorted rows justify looking only at endpoints.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m), where m is the row count.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxDistance(self, arrays: List[List[int]]) -> int:\n min_v = arrays[0][0]\n max_v = arrays[0][-1]\n ans = 0\n for arr in arrays[1:]:\n first, last = arr[0], arr[-1]\n ans = max(ans, abs(last - min_v), abs(max_v - first))\n min_v = min(min_v, first)\n max_v = max(max_v, last)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MaxDistance(arrays [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxDistance(self, arrays: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxDistance(vector<vector<int>>& arrays) {\n return 0;\n }\n};"}, "fn": "maxDistance", "params": [{"name": "arrays", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,2,3],[4,5],[1,2,3]]"], ["[[1],[1]]"], ["[[1,4],[2,5]]"], ["[[1,2],[3,4]]"], ["[[5],[10]]"], ["[[-10,-5],[0,5]]"], ["[[1,5],[2,3],[4,6]]"], ["[[0,0],[0,0]]"], ["[[-10000],[10000]]"], ["[[1,2,3,4,5],[6,7,8,9,10]]"], ["[[3],[7],[2],[9]]"], ["[[1,10],[2,3],[4,5]]"], ["[[-5,-3,-1],[1,2,3]]"], ["[[1],[2],[3],[4],[5]]"], ["[[10,20],[1,2],[30,40]]"], ["[[1,100],[50,51]]"], ["[[2,2,2],[2,2,2]]"], ["[[-4,-2],[3,7],[1,9]]"], ["[[0,10],[5,6]]"], ["[[1,3,5],[2,4,6],[0,7]]"], ["[[100,200],[1,2]]"], ["[[1,2],[100,101],[50,60]]"], ["[[-1,0,1],[2,3],[4,5,6]]"], ["[[7,8,9],[1,2,3],[4,5,6]]"], ["[[1,9],[1,9],[1,9]]"], ["[[0],[5],[10],[15]]"], ["[[-3,8],[4,4],[1,2]]"], ["[[6,7],[1,100]]"]], "expected": [4, 0, 4, 3, 5, 15, 5, 0, 20000, 9, 7, 8, 8, 4, 39, 50, 0, 13, 6, 6, 199, 100, 7, 8, 8, 15, 7, 94], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "183", "slug": "maximum-frequency-stack", "id": 183, "title": "Maximum Frequency Stack", "difficulty": "Hard", "category": "stack", "link": "https://leetcode.com/problems/maximum-frequency-stack/", "examples": [{"input": "operations = [\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\",\"pop\"], values = [5,7,5,7,4,5,0,0,0,0]", "output": "[5,7,5,4]", "explanation": "Push 5, 7, 5, 7, 4, 5. Frequencies are 5:3, 7:2, 4:1. Pop returns 5 (most frequent), then 7 (tie between 7:2 and 5:2 broken by recency), then 5, then 4."}, {"input": "operations = [\"push\",\"push\",\"pop\",\"pop\"], values = [1,1,0,0]", "output": "[1,1]", "explanation": "Push 1 twice. Both pops return 1."}, {"input": "operations = [\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\"], values = [4,6,4,0,0,0]", "output": "[4,6,4]", "explanation": "Push 4, 6, 4. Pop returns 4 (freq 2), then 6 and 4 tie at freq 1 so recency pops 6 then 4."}], "hints": ["Track each value's frequency and group values by frequency in stacks.", "Keep the current maximum frequency; push appends to its frequency group and pop removes from the max group, decreasing max when empty."], "statement": "Build a container with stack behavior whose removal rule is frequency-based: each `pop` extracts the value that currently occurs most often.\n\nA test is encoded as two parallel arrays, `operations` and `values`: `operations[i]` states whether step `i` is a `push` or a `pop`. The companion entry `values[i]` supplies the argument for a `push` and carries no meaning for a `pop`. Collect the value yielded by every `pop`, preserving their order; a `push` contributes no entry to that output. If several values share the highest frequency, remove the one that was pushed most recently (nearest the top).\n\nEach sequence is guaranteed to be legal: `pop` never appears when the structure holds nothing.\n\n**Constraints:**\n\n- `0 <= values[i] <= 10^9` when `operations[i]` is `push`.\n- `1 <= operations.length == values.length <= 20000`\n- At most `2 * 10^4` calls are made in one trace.\n", "solution": "## Approach\n\nTrack each value's frequency in a hash map and keep one stack per frequency\nlevel. `maxFreq` records the current highest frequency. Pushing `v` increments\nits frequency `f`, updates `maxFreq`, and pushes `v` onto group `f`. Popping\nremoves the top of group `maxFreq` (the most recent among the most frequent),\ndecrements its frequency, and lowers `maxFreq` when that group becomes empty.\n\n## Complexity Analysis\n\n- **Time Complexity:** `O(m)` over `m` operations, `O(1)` per `push`/`pop`.\n- **Space Complexity:** `O(m)` for the frequency map and grouped stacks.\n\n## Implementation\n\n```python\nfrom collections import defaultdict\nfrom typing import List\n\n\nclass Solution:\n def runFreqStack(self, operations: List[str], values: List[int]) -> List[int]:\n freq: dict[int, int] = {}\n groups: dict[int, list[int]] = defaultdict(list)\n max_freq = 0\n answers: List[int] = []\n for operation, value in zip(operations, values):\n if operation == \"push\":\n f = freq.get(value, 0) + 1\n freq[value] = f\n max_freq = max(max_freq, f)\n groups[f].append(value)\n else:\n v = groups[max_freq].pop()\n freq[v] -= 1\n answers.append(v)\n if not groups[max_freq]:\n max_freq -= 1\n return answers\n```\n", "starter": {"go": "package main\n\nfunc RunFreqStack(operations []string, values []int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runFreqStack(self, operations: List[str], values: List[int]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runFreqStack(vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runFreqStack", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\",\"pop\"]", "[5,7,5,7,4,5,0,0,0,0]"], ["[\"push\",\"push\",\"pop\",\"pop\"]", "[1,1,0,0]"], ["[\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\"]", "[4,6,4,0,0,0]"], ["[\"push\",\"pop\"]", "[9,0]"], ["[\"push\",\"push\",\"push\",\"pop\",\"push\",\"pop\",\"pop\",\"pop\"]", "[1,2,1,0,2,0,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\",\"pop\"]", "[3,3,3,3,0,0,0,0]"], ["[\"push\",\"push\",\"pop\",\"push\",\"push\",\"pop\",\"pop\",\"pop\"]", "[5,5,0,7,7,0,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\"]", "[1,2,3,2,1,0,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"pop\",\"push\",\"pop\",\"pop\",\"pop\",\"pop\"]", "[8,8,9,9,0,8,0,0,0,0]"], ["[\"push\",\"pop\",\"push\",\"pop\",\"push\",\"pop\"]", "[1,0,2,0,3,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\",\"pop\",\"pop\"]", "[0,0,0,1000000000,0,5,5,0,0,0,0,0]"], ["[\"push\",\"push\",\"push\",\"pop\",\"pop\",\"push\",\"push\",\"pop\",\"pop\",\"pop\"]", "[7,7,7,0,0,5,5,0,0,0]"], ["@javascript:JSON.stringify([...Array(5000).fill('push'),...Array(2500).fill('pop')])", "@javascript:JSON.stringify([...Array.from({length:5000},(_,i)=>i%100),...Array(2500).fill(0)])"], ["@javascript:JSON.stringify([...Array(4000).fill('push'),'pop','pop','pop'])", "@javascript:JSON.stringify([...Array.from({length:4000},(_,i)=>i%50),0,0,0])"], ["[\"push\", \"pop\", \"push\", \"pop\"]", "[5, 0, 5, 0]"], ["[\"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\"]", "[2, 2, 2, 0, 0, 0]"], ["[\"push\", \"push\", \"pop\", \"push\", \"push\", \"pop\", \"pop\", \"pop\"]", "[1, 2, 0, 2, 2, 0, 0, 0]"], ["[\"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\"]", "[10, 20, 10, 0, 0, 0]"], ["[\"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\"]", "[1, 1, 2, 2, 0, 0]"], ["[\"push\", \"pop\"]", "[0, 0]"], ["[\"push\", \"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\", \"pop\", \"pop\"]", "[9, 9, 1, 9, 1, 0, 0, 0, 0, 0]"], ["[\"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\", \"push\", \"push\", \"pop\", \"pop\", \"pop\", \"pop\"]", "[4, 5, 4, 5, 0, 0, 4, 5, 0, 0, 0, 0]"], ["[\"push\", \"push\", \"pop\", \"pop\"]", "[1000000000, 1000000000, 0, 0]"], ["[\"push\", \"pop\", \"push\", \"push\", \"pop\", \"pop\"]", "[7, 0, 7, 8, 0, 0]"], ["[\"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\"]", "[1, 2, 3, 0, 0, 0]"], ["[\"push\", \"push\", \"push\", \"push\", \"pop\"]", "[6, 6, 6, 7, 0]"], ["[\"push\", \"push\", \"pop\", \"push\", \"pop\", \"pop\"]", "[3, 4, 0, 3, 0, 0]"], ["[\"push\", \"push\", \"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\", \"pop\", \"pop\", \"pop\"]", "[5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0]"], ["[\"push\", \"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\"]", "[1, 2, 1, 2, 1, 0, 0]"], ["[\"push\", \"push\", \"push\", \"pop\", \"push\", \"pop\", \"pop\", \"pop\"]", "[11, 22, 11, 0, 22, 0, 0, 0]"], ["[\"push\", \"pop\"]", "[1000000000, 0]"], ["[\"push\", \"push\", \"push\", \"push\", \"pop\", \"pop\", \"pop\"]", "[0, 1, 0, 1, 0, 0, 0]"]], "expected": [[5, 7, 5, 4], [1, 1], [4, 6, 4], [9], [1, 2, 2, 1], [3, 3, 3, 3], [5, 7, 7, 5], [1, 2, 3], [9, 8, 8, 9, 8], [1, 2, 3], [0, 0, 5, 0, 5], [7, 7, 5, 5, 7], [99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [49, 48, 47], [5, 5], [2, 2, 2], [2, 2, 2, 1], [10, 20, 10], [2, 1], [0], [9, 1, 9, 1, 9], [5, 4, 5, 4, 5, 4], [1000000000, 1000000000], [7, 8, 7], [3, 2, 1], [6], [4, 3, 3], [5, 5, 5, 5, 5, 5], [1, 2], [11, 22, 22, 11], [1000000000], [1, 0, 1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "317", "slug": "maximum-gap", "id": 317, "title": "Maximum Gap", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximum-gap/", "examples": [{"explanation": "Sorted, the array is [1,3,6,9]. The gaps are 2, 3, 3, so the largest is 3.", "input": "nums = [3,6,9,1]", "output": "3"}, {"explanation": "A single element has no neighbour gap.", "input": "nums = [10]", "output": "0"}, {"explanation": "Sorted, the array is [1,13,16,19]. The gaps are 12, 3, 3, so the largest is 12.", "input": "nums = [13,16,19,1]", "output": "12"}], "hints": ["Sorting first turns the task into a single scan of neighbours.", "Track the largest difference between consecutive sorted values."], "statement": "Given an unsorted integer array, look at the array in sorted order and measure the gaps between neighbours. Return the largest such gap.\n\nWhen the array holds fewer than two numbers there is no gap, so return 0.\n\n**Constraints:**\n- `0 <= nums.length <= 10^4`\n- `0 <= nums[i] <= 10^9`\n", "solution": "## Approach\n\nSort a copy of the array, then scan neighbouring pairs and keep the largest difference. Fewer than two elements yields zero. Sorting dominates the cost and keeps the logic simple and correct.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) from sorting, plus O(n) for the scan.\n- **Space Complexity:** O(n) for the sorted copy (O(1) extra if sorting in place).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maximumGap(self, nums: List[int]) -> int:\n if len(nums) < 2:\n return 0\n nums = sorted(nums)\n best = 0\n for i in range(1, len(nums)):\n best = max(best, nums[i] - nums[i - 1])\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaximumGap(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maximumGap(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maximumGap(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "maximumGap", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[3,6,9,1]"], ["[10]"], ["[13,16,19,1]"], ["[1,1000000]"], ["[]"], ["[1,1,1]"], ["[1,2]"], ["[5,4,3,2,1]"], ["[1,3,6,10,15]"], ["[100,3,2,1]"], ["[1,10,5]"], ["[0,0]"], ["[7,7,7,7]"], ["[1,2,4,8,16]"], ["[9,1,8,2,7,3]"], ["[0,1000000000]"], ["[5,15,25,35]"], ["[2,11,4,19]"], ["[1]"], ["[3,3,3,4]"], ["[10,20,30,100]"], ["[6,2,9,4,7]"], ["[0,1]"], ["[100,99,98,1]"], ["[13,13,13,20]"], ["[1,2,3,100]"]], "expected": [3, 0, 12, 999999, 0, 0, 1, 1, 5, 97, 5, 0, 0, 8, 4, 1000000000, 10, 8, 0, 1, 70, 2, 1, 97, 7, 97], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "668", "slug": "maximum-length-of-pair-chain", "id": 668, "title": "Maximum Length of Pair Chain", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/maximum-length-of-pair-chain/", "examples": [{"input": "pairs = [[1,2],[2,3],[3,4]]", "output": "2", "explanation": "[1,2] then [3,4] is valid, but [1,2] then [2,3] is not since 2 is not less than 2."}, {"input": "pairs = [[1,2],[7,8],[4,5]]", "output": "3", "explanation": "Ordering as [1,2], [4,5], [7,8] chains all three."}, {"input": "pairs = [[1,2]]", "output": "1"}], "hints": ["Sort all pairs by their second entry ascending.", "Greedily take each pair whose first entry exceeds the last taken second entry.", "Earliest finishers leave the most room, so this greedy pass is optimal."], "statement": "You are given `n` pairs `[a, b]` with `a < b`. A chain links pairs so that each pair's second entry is strictly smaller than the next pair's first entry (`b < c` for `[a,b]` followed by `[c,d]`). Pairs may be reordered freely and any subset may be used.\n\nImplement `findLongestChain(pairs)` returning the longest achievable chain length.\n\n**Constraints:**\n- `1 <= pairs.length <= 2500`\n- `pairs[i].length == 2`\n- `-1000 <= pairs[i][j] <= 1000`\n", "solution": "## Approach\n\nSort the pairs by right endpoint and sweep once, keeping the end of the last chosen pair. Any pair starting strictly after that end extends the chain and becomes the new benchmark. Earliest-ending pairs block the least future room, which makes this greedy order optimal.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) for sorting n pairs, plus O(n) for the sweep.\n- **Space Complexity:** O(1) beyond the sort.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findLongestChain(self, pairs: List[List[int]]) -> int:\n pairs = sorted(pairs, key=lambda p: p[1])\n count = 0\n end = None\n for a, b in pairs:\n if end is None or a > end:\n count += 1\n end = b\n return count\n```\n", "starter": {"go": "package main\n\nfunc FindLongestChain(pairs [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def findLongestChain(self, pairs: List[List[int]]) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int findLongestChain(vector<vector<int>>& pairs) {\n return 0;\n }\n};"}, "fn": "findLongestChain", "params": [{"name": "pairs", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,2],[2,3],[3,4]]"], ["[[1,2],[7,8],[4,5]]"], ["[[1,2]]"], ["[[1,2],[3,4],[5,6]]"], ["[[1,10],[2,3],[4,5]]"], ["[[-10,-8],[8,9],[-5,0]]"], ["[[1,2],[2,3]]"], ["[[3,4],[2,3],[1,2]]"], ["[[1,5],[2,3],[4,6]]"], ["[[-6,-5],[-4,-3],[-2,-1]]"], ["[[1,2],[1,2],[1,2]]"], ["[[1,100],[2,3],[4,5],[6,7]]"], ["[[5,6],[1,2],[3,4],[7,8],[2,3]]"], ["[[-1000,1000]]"], ["[[1,2],[4,5],[7,8],[10,11],[3,4]]"], ["[[2,5],[1,2],[3,4]]"], ["[[0,1],[1,2],[2,3],[3,4],[4,5]]"], ["[[-5,-4],[-3,-2],[-1,0],[1,2]]"], ["[[1,3],[2,4],[3,5],[4,6]]"], ["[[7,9],[4,5],[1,2],[6,8],[2,3]]"], ["[[1,2],[5,6],[3,4],[9,10],[7,8]]"], ["[[-2,-1],[0,1],[2,3],[4,5],[6,7],[8,9]]"], ["[[10,20],[1,2],[3,4],[5,6]]"], ["[[1,4],[2,3],[3,4],[4,5]]"], ["[[1,2],[3,5],[4,6],[7,9],[8,10]]"], ["[[0,1],[2,3],[4,5]]"], ["[[1,2],[2,4],[3,5],[6,8],[7,9],[10,12]]"], ["[[-10,-5],[-6,-1],[0,5],[4,10],[9,15]]"]], "expected": [2, 3, 1, 3, 2, 3, 1, 2, 2, 3, 1, 3, 4, 1, 4, 2, 3, 4, 2, 3, 5, 6, 4, 2, 3, 3, 4, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "726", "slug": "maximum-length-of-repeated-subarray", "id": 726, "title": "Maximum Length of Repeated Subarray", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/maximum-length-of-repeated-subarray/", "examples": [{"input": "nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]", "output": "3", "explanation": "The shared window [3,2,1] of length 3 is the longest."}, {"input": "nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]", "output": "5", "explanation": "Identical arrays share their full length."}, {"input": "nums1 = [1,2,3], nums2 = [4,5,6]", "output": "0", "explanation": "No value overlaps, so nothing repeats."}], "hints": ["Let dp[i][j] be the length of the shared suffix ending at nums1[i-1] and nums2[j-1].", "Equal endpoints extend the diagonal value by one; mismatches reset to zero.", "Track the maximum cell seen during the fill."], "statement": "Given two integer arrays, find the longest contiguous block that appears in both in the same order.\n\nThe block must occupy consecutive positions in each array, though the starting offsets may differ. An empty overlap scores zero.\n\nReturn that maximum length.\n\n**Constraints:**\n- `1 <= nums1.length, nums2.length <= 1000`\n- `0 <= nums1[i], nums2[i] <= 100`\n", "solution": "## Approach\n\nBuild a table where each cell extends the diagonal match by one when the two current values agree and resets to zero otherwise. The table entry therefore equals the length of the longest shared suffix ending at those positions, and the largest entry overall is the longest shared block.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m*n), where m and n are the array lengths.\n- **Space Complexity:** O(m*n), reducible to O(n) with one rolling row.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findLength(self, nums1: List[int], nums2: List[int]) -> int:\n m, n = len(nums1), len(nums2)\n dp = [0]*(n+1)\n best = 0\n for i in range(1, m+1):\n ndp = [0]*(n+1)\n for j in range(1, n+1):\n if nums1[i-1] == nums2[j-1]:\n ndp[j] = dp[j-1] + 1\n best = max(best, ndp[j])\n dp = ndp\n return best\n```\n", "starter": {"go": "package main\n\nfunc FindLength(nums1 []int, nums2 []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def findLength(self, nums1: List[int], nums2: List[int]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findLength(vector<int>& nums1, vector<int>& nums2) {\n return 0;\n }\n};"}, "fn": "findLength", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,3,2,1]", "[3,2,1,4,7]"], ["[0,0,0,0,0]", "[0,0,0,0,0]"], ["[1,2,3]", "[4,5,6]"], ["[1]", "[1]"], ["[1]", "[2]"], ["[1,2]", "[2,1]"], ["[1,2,3,4]", "[1,2,3,4]"], ["[1,2,3,4]", "[4,3,2,1]"], ["[0,1,1,1,1]", "[1,0,1,0,1]"], ["[1,2,3,2,1,2,3]", "[2,1,2,3,2,1]"], ["[5,5,5]", "[5,5]"], ["[1,2,3,4,5]", "[6,1,2,3]"], ["[7,8,9]", "[9,8,7]"], ["[1,1,1,1]", "[1,1]"], ["[2,2,2,3,2]", "[2,3,2,2,2]"], ["[0]", "[0,0,0]"], ["[1,2,3,4,5,6]", "[3,4,5]"], ["[4,5,6,7]", "[1,2,4,5]"], ["[1,0,1,0,1]", "[0,1,0,1,0]"], ["[100,100]", "[100]"], ["[1,2,3,4,1,2,3]", "[1,2,3]"], ["[9,9,9,9,9,1]", "[9,1,9,9,9]"], ["[1,3,2,4]", "[3,2]"], ["[0,0,1,0,0]", "[0,0,0,1,0]"], ["[2,1,3,2,1]", "[3,2,1,2]"], ["[1,2,3,4,5,6,7]", "[7,6,5,4,3,2,1]"], ["[1,1,2,2,3,3]", "[1,2,3,1,2,3]"], ["[5,4,3,2,1,5,4]", "[5,4,3,2,1]"]], "expected": [3, 5, 0, 1, 0, 1, 4, 1, 2, 5, 2, 3, 1, 2, 3, 1, 3, 2, 4, 1, 3, 3, 2, 4, 3, 1, 2, 5], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "650", "slug": "maximum-product-of-three-numbers", "id": 650, "title": "Maximum Product of Three Numbers", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/maximum-product-of-three-numbers/", "examples": [{"input": "nums = [1,2,3]", "output": "6", "explanation": "Only 1*2*3 = 6 exists."}, {"input": "nums = [1,2,3,4]", "output": "24", "explanation": "2*3*4 = 24 beats every other triple."}, {"input": "nums = [-1,-2,-3]", "output": "-6", "explanation": "The single triple multiplies to -6."}], "hints": ["Only two patterns can win: three largest values, or the largest value with the two smallest (most negative) values.", "One linear scan tracking the top three maxima and bottom two minima is enough."], "statement": "You are given an integer array with at least three entries. Choose any three distinct positions and multiply their values. Return the greatest product reachable.\n\nNegatives matter: two large-magnitude negatives can turn positive when paired with a big positive.\n\n**Constraints:**\n- Array length is between 3 and 10000.\n- Each value lies in [-1000, 1000]; the winning product fits in 32-bit signed range for the given tests.\n", "solution": "## Approach\n\nThe winner must use either the three biggest numbers or the biggest number plus the two most negative numbers (whose product is positive and large). Track those five extremes in one pass, then return the better of the two candidate products.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the single scan.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maximumProduct(self, nums: List[int]) -> int:\n max1 = max2 = max3 = float(\"-inf\")\n min1 = min2 = float(\"inf\")\n for x in nums:\n if x > max1:\n max1, max2, max3 = x, max1, max2\n elif x > max2:\n max2, max3 = x, max2\n elif x > max3:\n max3 = x\n if x < min1:\n min1, min2 = x, min1\n elif x < min2:\n min2 = x\n return max(max1 * max2 * max3, min1 * min2 * max1)\n```\n", "starter": {"go": "package main\n\nfunc MaximumProduct(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maximumProduct(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maximumProduct(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "maximumProduct", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,3]"], ["[1,2,3,4]"], ["[-1,-2,-3]"], ["[-4,-3,-2,-1]"], ["[-10,-10,1,2,3]"], ["[-5,-4,0,1,2]"], ["[0,0,0]"], ["[1,1,1]"], ["[-1,-2,1,2,3]"], ["[5,4,3,2,1]"], ["[-1000,-1000,1000]"], ["[1000,1000,1000]"], ["[-1,0,1]"], ["[-2,-1,0,1,2]"], ["[7,7,7,7]"], ["[-8,-7,1,2,3]"], ["[0,1,2,3]"], ["[-3,-2,-1,0]"], ["[2,2,2,2]"], ["[-10,10,-10,10]"], ["[1,2,3,4,5,6]"], ["[-100,-99,1,2,3]"], ["[0,0,5,6]"], ["[-9,-9,9,9]"], ["[4,4,4,-4]"], ["[1,10,2,9,3,8]"], ["[-2,3,-4,5,-6]"], ["[-4,-1,0,1,2]"]], "expected": [6, 24, -6, -6, 300, 40, 0, 1, 6, 60, 1000000000, 1000000000, 0, 4, 343, 168, 6, 0, 8, 1000, 120, 29700, 0, 729, 64, 720, 120, 8], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "407", "slug": "maximum-product-of-word-lengths", "id": 407, "title": "Maximum Product of Word Lengths", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximum-product-of-word-lengths/", "examples": [{"explanation": "\"abcw\" (length 4) and \"xtfn\" (length 4) use disjoint letters, giving 4 * 4 = 16, which is best possible.", "input": "words = [\"abcw\",\"baz\",\"foo\",\"bar\",\"xtfn\",\"abcdef\"]", "output": "16"}, {"explanation": "\"ab\" and \"cd\" share nothing and yield 2 * 2 = 4.", "input": "words = [\"a\",\"ab\",\"abc\",\"d\",\"cd\",\"bcd\",\"abcd\"]", "output": "4"}, {"explanation": "Every pair shares the letter 'a', so no valid pair exists.", "input": "words = [\"a\",\"aa\",\"aaa\",\"aaaa\"]", "output": "0"}], "hints": ["Encode each word as a 26-bit mask of its letters; disjoint pairs are those with (maskA & maskB) == 0.", "Compare all pairs of masks and keep the best length product.", "Duplicate masks can be compressed by keeping only the longest word per mask."], "statement": "You are given an array `words` of lowercase strings. Consider pairs of words that share no letter in common (no character appearing in both). For each such pair, multiply their lengths; return the largest product found. When no disjoint pair exists, return `0`.\n\n**Constraints:**\n- `2 <= words.length <= 1000`\n- `1 <= words[i].length <= 1000`\n- Each `words[i]` holds only lowercase English letters.\n", "solution": "## Approach\n\nConvert every word into a 26-bit mask recording which letters occur in it. Two words share no letter exactly when the bitwise AND of their masks is zero. Checking all pairs of masks and keeping the greatest length product yields the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2 + L), where n is the number of words and L is their total length for building masks.\n- **Space Complexity:** O(n) for the masks.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxProduct(self, words: List[str]) -> int:\n masks = []\n for w in words:\n m = 0\n for c in w:\n m |= 1 << (ord(c) - ord('a'))\n masks.append(m)\n best = 0\n for i in range(len(words)):\n for j in range(i + 1, len(words)):\n if masks[i] & masks[j] == 0:\n best = max(best, len(words[i]) * len(words[j]))\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxProduct(words []string) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxProduct(self, words: List[str]) -> int:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int maxProduct(vector<string>& words) {\n return 0;\n }\n};"}, "fn": "maxProduct", "params": [{"name": "words", "type": "string_array"}], "outputType": "int", "tests": [["['abcw', 'baz', 'foo', 'bar', 'xtfn', 'abcdef']"], ["['a', 'ab', 'abc', 'd', 'cd', 'bcd', 'abcd']"], ["['a', 'aa', 'aaa', 'aaaa']"], ["['ab', 'cd']"], ["['ab', 'ba']"], ["['abc', 'def']"], ["['a', 'b']"], ["['hello', 'world']"], ["['abcd', 'efgh', 'ijkl']"], ["['abc', 'bcd', 'cde']"], ["['x', 'y', 'z']"], ["['aaaa', 'bbbb', 'cccc']"], ["['abcde', 'fghij', 'klmno', 'pqrst', 'uvwxyz']"], ["['a', 'abc', 'abcd', 'abcde']"], ["['foo', 'bar', 'baz']"], ["['ab', 'cde', 'fgh', 'abc']"], ["['the', 'quick', 'brown', 'fox']"], ["['aa', 'bb', 'ab']"], ["['abcdxyz', 'abc', 'xyz']"], ["['mno', 'pqr', 'st', 'uvw']"], ["['a', 'b', 'c', 'd', 'e', 'f', 'g']"], ["['abcabc', 'defdef', 'ghighi']"], ["['qw', 'er', 'ty', 'qwerty']"], ["['ab', 'cd', 'ef', 'gh', 'ij']"], ["['longwordwithmanyletters', 'short', 'tiny']"], ["['zz', 'yy', 'xx', 'ww']"], ["['abc', 'defg', 'hijkl']"], ["['a', 'bb', 'ccc', 'dddd']"], ["['abcde', 'abcde']"], ["['python', 'java', 'rust', 'go']"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "6", "slug": "maximum-product-subarray", "id": 6, "title": "Maximum Product Subarray", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximum-product-subarray/", "examples": [{"input": "nums = [2,3,-2,4]", "output": "6", "explanation": "The subarray [2, 3] yields the maximum product 6."}, {"input": "nums = [-2,0,-1]", "output": "0", "explanation": "The subarray [0] yields the maximum product 0, since any non-zero product would be negative."}], "hints": ["Track the maximum and minimum product ending at each position (since a negative flips the sign). Swap when encountering negatives, update current max/min, and keep a global best."], "statement": "An integer array `nums` is supplied. Among all contiguous blocks inside it, determine the greatest achievable product, and output that product.\n\n**Constraints:**\n\n- 1 \u2264 nums.length \u2264 2 * 10^4\n- -10 \u2264 nums[i] \u2264 10\n- The product of any subarray of nums is guaranteed to fit in a 32-bit integer.\n", "solution": "## Approach\nTrack both the maximum and minimum product ending at each position, since a negative number can flip the minimum into the maximum. At each step, compute the new candidates and update the global result.\n\n## Complexity Analysis\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(1)\n\n## Implementation\n```python\nfrom typing import List\nclass Solution:\n def maxProduct(self, nums: List[int]) -> int:\n res = max(nums)\n cur_min = cur_max = 1\n for n in nums:\n tmp = cur_max * n\n cur_max = max(tmp, cur_min * n, n)\n cur_min = min(tmp, cur_min * n, n)\n res = max(res, cur_max)\n return res\n```\n", "starter": {"go": "package main\n\nfunc MaxProduct(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxProduct(self, nums: List[int]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxProduct(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "maxProduct", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[2,3,-2,4]"], ["[-2,0,-1]"], ["[0,2]"], ["[-2,3,-4]"], ["[6,-3,-10,0,2]"], ["[2,-5,-2,-4,3]"], ["[-1]"], ["[1]"], ["[0,0,0]"], ["[1,2,3,4]"], ["[-1, -2, -9, -6]"], ["[1,-2,3,-4,-3,2]"], ["[-1, -1]"], ["[2, -1, 1, 1]"], ["[0, -3, 1, 1]"], ["[2,3,-2,4,-1,2,1,-5,4]"], ["@javascript:JSON.stringify(Array(10000).fill(1))"], ["[3,-2]"], ["[-2,-3]"], ["[2,3,4]"], ["[-1,-2,-3]"], ["[0,-2,0]"], ["[-2]"], ["[5]"], ["[0,0,1]"], ["[-10,10]"], ["[10,10]"], ["[-10,-10]"], ["[2,-1,2]"], ["[1,0,-1,2]"], ["[-3,0,-2,0,-1]"], ["[4,-1,2,1]"]], "expected": [6, 0, 2, 24, 180, 24, -1, 1, 0, 24, 108, 72, 1, 2, 1, 160, 1, 3, 6, 24, 6, 0, -2, 5, 1, 10, 100, 100, 2, 2, 0, 4], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "412", "slug": "maximum-size-subarray-sum-equals-k", "id": 412, "title": "Maximum Size Subarray Sum Equals k", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/", "examples": [{"explanation": "The block [1,-1,5,-2] sums to 3 and has length 4, which is the longest achievable.", "input": "nums = [1,-1,5,-2,3], k = 3", "output": "4"}, {"explanation": "The block [-1,2] sums to 1 with length 2, beating every other qualifying block.", "input": "nums = [-2,-1,2,1], k = 1", "output": "2"}, {"explanation": "The block [1,2] sums to 3; the single element [3] also qualifies but is shorter.", "input": "nums = [1,2,3], k = 3", "output": "2"}], "hints": ["Build running prefix sums; a block (j+1..i) sums to k exactly when prefix[i] - prefix[j] == k.", "Remember only the first index where each prefix sum appears, since earlier starts give longer blocks.", "A single hash map pass computes the best length in linear time."], "statement": "You are given an integer array `nums` and an integer `k`. A *subarray* is a contiguous block of the array. Determine the greatest length among all subarrays whose elements add up to exactly `k`. If no such subarray exists, return `0`.\n\n**Constraints:**\n- `1 <= nums.length <= 2 * 10^5`\n- `-10^4 <= nums[i] <= 10^4`\n- `-10^9 <= k <= 10^9`\n", "solution": "## Approach\n\nScan the array while tracking the running prefix sum. A subarray ending at `i` sums to `k` exactly when an earlier prefix equals `prefix - k`. Storing each prefix sum's first occurrence in a hash map lets us measure the longest such subarray ending at every position in one pass.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `nums`.\n- **Space Complexity:** O(n) for the prefix map.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxSubArrayLen(self, nums: List[int], k: int) -> int:\n first = {0: -1}\n prefix = 0\n best = 0\n for i, v in enumerate(nums):\n prefix += v\n if prefix - k in first:\n best = max(best, i - first[prefix - k])\n if prefix not in first:\n first[prefix] = i\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxSubArrayLen(nums []int, k int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxSubArrayLen(self, nums: List[int], k: int) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxSubArrayLen(vector<int>& nums, int k) {\n return 0;\n }\n};"}, "fn": "maxSubArrayLen", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int", "tests": [["[1,-1,5,-2,3]", "3"], ["[-2,-1,2,1]", "1"], ["[1,2,3]", "3"], ["[1]", "1"], ["[1]", "2"], ["[1,-1,1,-1,1]", "0"], ["[1,2,3,4,5]", "9"], ["[1,2,3,4,5]", "15"], ["[1,2,3,4,5]", "100"], ["[-1,-2,-3]", "-3"], ["[0,0,0,0]", "0"], ["[5]", "5"], ["[-5,5,-5,5]", "0"], ["[1,0,-1]", "0"], ["[2,1,-2,-1,3,-3]", "0"], ["[1,2,-3,4,-1,2,1,-5,4]", "0"], ["[3,1,2,1]", "3"], ["[10,-10,10,-10,10]", "10"], ["[1,2,3,1,1,1,1]", "3"], ["[-2,5,-1,2,-3,4]", "3"], ["[1000000000]", "1000000000"], ["[1,2,3,4,5,6,7,8,9,10]", "55"], ["[1,2,3,4,5,6,7,8,9,10]", "10"], ["[-1,1,-1,1,-1,1,-1,1]", "0"], ["[7,7,7,7]", "14"], ["@javascript:JSON.stringify(Array(3000).fill(1))", "1500"], ["@javascript:JSON.stringify(Array.from({length:3000}, (_, i) => (i % 2 === 0 ? 1 : -1)))", "0"], ["[0]", "1"], ["[2,-2,2,-2,2]", "2"], ["[4,1,-1,2,-1,2,3]", "5"]], "expected": [4, 2, 2, 1, 0, 4, 3, 5, 0, 2, 4, 1, 4, 3, 6, 7, 2, 5, 3, 4, 1, 10, 4, 8, 2, 1500, 3000, 0, 5, 5], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "5", "slug": "maximum-subarray", "id": 5, "title": "Maximum Subarray", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximum-subarray/", "examples": [{"input": "nums = [-2,1,-3,4,-1,2,1,-5,4]", "output": "6", "explanation": "The subarray [4,-1,2,1] has the largest sum = 6."}, {"input": "nums = [1]", "output": "1", "explanation": "The array has only one element, so the maximum subarray sum is 1."}, {"input": "nums = [5,4,-1,7,8]", "output": "23", "explanation": "The sum of the entire array [5,4,-1,7,8] = 23, which is the maximum subarray sum."}], "hints": ["Find a contiguous subarray (one or more elements) that yields the highest possible total. A classic linear-time solution uses Kadane's algorithm by tracking a running sum and the best seen so far."], "statement": "An integer array `nums` is supplied. Look at every contiguous segment containing at least one element, compute its total, and output the largest such total.\n\n**Constraints:**\n\n- 1 \u2264 nums.length \u2264 10^5\n- -10^4 \u2264 nums[i] \u2264 10^4\n", "solution": "## Approach\nKadane's algorithm: maintain a running sum, resetting it to the current element if the running sum becomes smaller. Track the maximum running sum encountered.\n\n## Complexity Analysis\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(1)\n\n## Implementation\n```python\nfrom typing import List\nclass Solution:\n def maxSubArray(self, nums: List[int]) -> int:\n res = cur = nums[0]\n for n in nums[1:]:\n cur = max(n, cur + n)\n res = max(res, cur)\n return res\n```\n", "starter": {"go": "package main\n\nfunc MaxSubArray(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxSubArray(self, nums: List[int]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxSubArray(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "maxSubArray", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[-2,1,-3,4,-1,2,1,-5,4]"], ["[1]"], ["[5,4,-1,7,8]"], ["[-1]"], ["[0]"], ["[8,-19,5,-4,20]"], ["[-2,-3,-1,-5]"], ["[1,-2,3,10,-4,7,2,-5]"], ["[100,-90,80,-70,60,-50,40,-30,20,-10]"], ["[0,0,0,0]"], ["[2,-1,2,3,4,-5]"], ["[-2,1]"], ["[1,-1,1,-1,1,-1,1]"], ["@javascript:JSON.stringify(Array(100000).fill(1))"], ["[1,2,3,4,5]"], ["[-5,-4,-3]"], ["[3,-2,5,-1]"], ["[0,-1,0,-1,0]"], ["[10000]"], ["[-10000]"], ["[10000,-10000,10000]"], ["[7,-3,7,-3,7]"], ["[-1,2,-1,2,-1,2]"], ["[5,-1,5,-1,5,-1,5]"], ["[1,1,1,1,1,1]"], ["[-1,-2,3,4,-5,6]"], ["[4,-1,2,1]"], ["[-3,10,-2,8,-1]"], ["[2,-5,2,-5,2]"], ["[0,0,5,0,0]"], ["[-100,200,-50,300]"], ["[1,-2,1,-2,1]"]], "expected": [6, 1, 23, -1, 0, 21, -1, 18, 100, 0, 10, 1, 1, 100000, 15, -3, 6, 0, 10000, -10000, 10000, 15, 4, 17, 6, 8, 6, 16, 2, 5, 450, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "237", "slug": "maximum-sum-circular-subarray", "id": 237, "title": "Maximum Sum Circular Subarray", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/maximum-sum-circular-subarray/", "examples": [{"input": "nums = [1,-2,3,-2]", "output": "3", "explanation": "Subarray [3] has maximum sum 3."}, {"input": "nums = [5,-3,5]", "output": "10", "explanation": "Subarray [5,5] has maximum sum 5 + 5 = 10."}, {"input": "nums = [-3,-2,-3]", "output": "-2", "explanation": "Subarray [-2] has maximum sum -2."}], "hints": ["For those familiar with Kadane's algorithm, this problem is a twist on that idea: use Kadane's on a straight array first.", "There are two cases; the second maximizes the sum by wrapping around, which equals the total sum minus the minimum subarray sum.", "If every element is negative, the answer is simply the maximum element."], "statement": "Think of `nums` as a ring of length `n` rather than a line: positions after the final entry continue at the first entry. Report the largest total attainable by any **non-empty** contiguous block on that ring.\n\nIn ring terms, the successor of position `nums[i]` is `nums[(i + 1) % n]` and its predecessor is `nums[(i - 1 + n) % n]`.\n\nNo slot of the underlying storage `nums` may be reused within one block. In other words, for a block written `nums[i], nums[i + 1], ..., nums[j]`, there are no indices `i <= k1, k2 <= j` with `k1 % n == k2 % n` unless `k1 == k2`.\n\n**Constraints:**\n\n- `n == nums.length`\n- `1 <= n <= 3 * 10^4`\n- `-3 * 10^4 <= nums[i] <= 3 * 10^4`\n", "solution": "## Approach\n\nUse Kadane's algorithm in one pass to find the maximum subarray sum of the straight array and, in the same pass, the minimum subarray sum. The best circular subarray is either the straight maximum (case 1) or the total sum minus the minimum subarray (case 2, where the subarray wraps around). When every element is negative, the straight maximum is already the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where `n` is `nums.length`.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def maxSubarraySumCircular(self, nums: List[int]) -> int:\n total = 0\n max_end = 0\n max_sum = float(\"-inf\")\n min_end = 0\n min_sum = float(\"inf\")\n\n for x in nums:\n total += x\n max_end = max(x, max_end + x)\n max_sum = max(max_sum, max_end)\n min_end = min(x, min_end + x)\n min_sum = min(min_sum, min_end)\n\n if max_sum < 0:\n return max_sum\n return max(max_sum, total - min_sum)\n```", "starter": {"go": "package main\n\nfunc MaxSubarraySumCircular(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxSubarraySumCircular(self, nums: List[int]) -> int:\n ", "cpp": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxSubarraySumCircular(vector<int>& nums) {\n \n }\n};"}, "fn": "maxSubarraySumCircular", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,-2,3,-2]"], ["[5,-3,5]"], ["[-3,-2,-3]"], ["[1,2,3,4]"], ["[3,-1,2,-1]"], ["[7]"], ["[-5]"], ["[0]"], ["[1,-1,1,-1,1]"], ["[-2,-3,-1]"], ["[2,-1,2]"], ["[-1,-1,-1,-1]"], ["[6,9,-3]"], ["[5,5,-5,5,5]"], ["[1,2,3,-10,1,2,3]"], ["[-30000,30000,-30000,30000]"], ["[0,10,0,-10,0]"], ["[-2,1,-3,4,-1,2,1,-5,4]"], ["[10,20,-100,30,40]"], ["[1,2,3,-4,5]"], ["[5,-2,5,-2,5]"], ["[-1,2,-1,2,-1]"], ["[8,-1,-1,8]"], ["[-10,5,-10,5,-10]"], ["[3,3,3,-6,3]"], ["[0,0,0]"], ["[1,-2,3,-4,5,-6]"], ["[100,-50,100,-50,100]"], ["[-5,4,-5,4,-5,4]"], ["[2,3,-2,-3,4]"], ["[-7,-2,-9,-1]"], ["[4,-1,-1,4,-1,-1,4]"]], "expected": [3, 10, -2, 10, 4, 7, -5, 0, 2, -1, 4, -1, 15, 20, 12, 30000, 10, 6, 100, 11, 13, 3, 16, 5, 12, 0, 5, 250, 4, 9, -1, 10], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "704", "slug": "maximum-sum-of-3-non-overlapping-subarrays", "id": 704, "title": "Maximum Sum of 3 Non-Overlapping Subarrays", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/", "examples": [{"input": "nums = [1,2,1,2,6,7,5,1], k = 2", "output": "[0,3,5]", "explanation": "Blocks sum to 3 + 8 + 12 = 23."}, {"input": "nums = [1,2,1,2,1,2,1,2,1], k = 2", "output": "[0,2,4]", "explanation": "All windows tie, so the earliest triple wins."}, {"input": "nums = [4,5,10,6,11,17,4,8,1,20], k = 1", "output": "[4,5,9]", "explanation": "Best single spots 11, 17 and 20."}], "hints": ["Precompute every window sum of length k with one sliding pass.", "For each position remember the best window start on its left (smallest index on ties) and on its right.", "Try every middle window and join it with the best compatible left and right choices; keep the dictionary-smallest among maximal totals."], "statement": "You are given a list `nums` and a window length `k`. Choose three blocks, each covering exactly `k` consecutive positions, so that no two blocks overlap. The goal is to make the sum of all covered entries as large as possible.\n\nReturn the three starting indexes in increasing order. When several triples reach the same best total, return the one that is smallest in dictionary order (compare the first differing index).\n\n**Constraints:**\n- `3 * k <= nums.length <= 20000`\n- `1 <= k <= 250`\n- `1 <= nums[i] <= 1000`\n- The judge accepts any triple whose total equals the optimum and whose blocks are disjoint and ordered; the reference returns the dictionary-smallest.\n", "solution": "## Approach\n\nSlide once to obtain every length-`k` window sum. Build a left-best table where each entry remembers the highest-sum window start at or before it (keeping the smaller index on ties), and a right-best table where each entry remembers the best start at or after it (keeping the smaller index when scanning from the right with a non-strict comparison). Then treat each feasible position as the middle block and pair it with its best compatible left and right neighbours, retaining the greatest total and breaking ties toward the dictionary-smallest triple.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the slide plus O(n) for the middle scan.\n- **Space Complexity:** O(n) for window sums and best tables.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]:\n n = len(nums)\n m = n - k + 1\n w = [0]*m\n s = sum(nums[:k])\n w[0] = s\n for i in range(1, m):\n s += nums[i+k-1] - nums[i-1]\n w[i] = s\n left = [0]*m\n best = 0\n for i in range(m):\n if w[i] > w[best]:\n best = i\n left[i] = best\n right = [0]*m\n best = m-1\n for i in range(m-1, -1, -1):\n if w[i] >= w[best]:\n best = i\n right[i] = best\n ans = [-1,-1,-1]\n best_total = -1\n for j in range(k, m-k):\n i = left[j-k]\n l = right[j+k]\n tot = w[i]+w[j]+w[l]\n if tot > best_total or (tot == best_total and [i,j,l] < ans):\n best_total = tot\n ans = [i,j,l]\n return ans\n```\n", "starter": {"go": "package main\n\nfunc MaxSumOfThreeSubarrays(nums []int, k int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def maxSumOfThreeSubarrays(self, nums: List[int], k: int) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> maxSumOfThreeSubarrays(vector<int>& nums, int k) {\n return {};\n }\n};"}, "fn": "maxSumOfThreeSubarrays", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int_array", "tests": [["[1,2,1,2,6,7,5,1]", "2"], ["[1,2,1,2,1,2,1,2,1]", "2"], ["[4,5,10,6,11,17,4,8,1,20]", "1"], ["[1,1,1,1,1,1]", "1"], ["[7,13,20,19,19,2,10,1,1,19]", "3"], ["[1,2,3,4,5,6,7,8,9]", "1"], ["[9,8,7,6,5,4,3,2,1]", "2"], ["[5,5,5,5,5,5,5,5,5]", "3"], ["[1,100,1,100,1,100,1]", "1"], ["[10,1,1,1,1,1,1,1,10]", "2"], ["[2,2,2,2,2,2,2,2,2,2,2]", "2"], ["[1,2,3,1,2,3,1,2,3]", "3"], ["[1000,1,1,1000,1,1,1000,1,1]", "1"], ["[3,3,3,4,4,4,5,5,5]", "2"], ["[1,3,2,4,3,5,4,6,5]", "2"], ["[20,1,1,1,20,1,1,1,20]", "3"], ["[1,2,1,2,6,7,5,1,9,2]", "2"], ["[4,4,4,4,4,4,4,4,4]", "1"], ["[5,1,5,1,5,1,5,1,5]", "1"], ["[1,9,2,8,3,7,4,6,5]", "2"], ["[6,5,4,3,2,1,2,3,4,5,6]", "2"], ["[1,1,10,1,1,10,1,1,10]", "2"], ["[2,5,2,5,2,5,2,5,2]", "1"], ["[10,20,30,40,50,60,70,80,90]", "3"], ["[1,2,3,4,5,1,2,3,4,5,1,2]", "2"], ["[8,8,1,1,8,8,1,1,8]", "2"], ["[3,1,2,3,1,2,3,1,2,3,1]", "2"], ["[50,40,30,20,10,10,20,30,40,50]", "2"]], "expected": [[0, 3, 5], [0, 2, 4], [4, 5, 9], [0, 1, 2], [1, 4, 7], [6, 7, 8], [0, 2, 4], [0, 3, 6], [1, 3, 5], [0, 2, 7], [0, 2, 4], [0, 3, 6], [0, 3, 6], [3, 5, 7], [3, 5, 7], [0, 3, 6], [3, 5, 8], [0, 1, 2], [0, 2, 4], [1, 3, 5], [0, 2, 9], [1, 4, 7], [1, 3, 5], [0, 3, 6], [1, 3, 8], [0, 4, 7], [2, 5, 8], [0, 2, 8]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "689", "slug": "maximum-swap", "id": 689, "title": "Maximum Swap", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/maximum-swap/", "examples": [{"input": "num = 2736", "output": "7236", "explanation": "Exchanging the 2 with the 7 yields the largest reachable value 7236."}, {"input": "num = 9973", "output": "9973", "explanation": "The digits are already in the best order, so no exchange improves the value."}, {"input": "num = 98368", "output": "98863", "explanation": "Swapping the small 3 with the later 8 gives 98863."}], "hints": ["Record the last position of each digit 0-9.", "Scan from the most significant digit and look for a larger digit appearing later.", "Swap at most once: the earliest improvable position with the largest possible later digit."], "statement": "You are given a nonnegative integer `num`. You may exchange two of its decimal digits at most once.\n\nReturn the greatest value obtainable after zero or one such exchange. Keeping the number unchanged is allowed.\n\n**Constraints:**\n- `0 <= num <= 10^8`\n", "solution": "## Approach\n\nRemember the final index of every digit. Then walk the number from left to right: at the first position where a bigger digit occurs later, swap it with the rightmost occurrence of the biggest such digit. If no position qualifies, the number is already maximal.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the digit count (at most 9).\n- **Space Complexity:** O(1) besides the digit array.\n\n## Implementation\n\n```python\nclass Solution:\n def maximumSwap(self, num: int) -> int:\n d = list(str(num))\n last = {int(c): i for i, c in enumerate(d)}\n for i, c in enumerate(d):\n for v in range(9, int(c), -1):\n if last.get(v, -1) > i:\n j = last[v]\n d[i], d[j] = d[j], d[i]\n return int(\"\".join(d))\n return num\n```\n", "starter": {"go": "package main\n\nfunc MaximumSwap(num int) int {\n return 0\n}", "python": "class Solution:\n def maximumSwap(self, num: int) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maximumSwap(int num) {\n return 0;\n }\n};"}, "fn": "maximumSwap", "params": [{"name": "num", "type": "int"}], "outputType": "int", "tests": [["2736"], ["9973"], ["98368"], ["0"], ["9"], ["10"], ["11"], ["100"], ["1993"], ["1111"], ["12345"], ["54321"], ["115"], ["99099"], ["99901"], ["109090"], ["10000000"], ["99999999"], ["12"], ["21"], ["31"], ["101"], ["1001"], ["1203"], ["98765"], ["10200"], ["27361"], ["52631"]], "expected": [7236, 9973, 98863, 0, 9, 10, 11, 100, 9913, 1111, 52341, 54321, 511, 99990, 99910, 909010, 10000000, 99999999, 21, 21, 31, 110, 1100, 3201, 98765, 20100, 72361, 62531], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "622", "slug": "maximum-vacation-days", "id": 622, "title": "Maximum Vacation Days", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/maximum-vacation-days/", "examples": [{"input": "flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[1,3,1],[6,0,3],[3,3,3]]", "output": "12", "explanation": "Weeks in cities 1, 0, 2 give 6 + 3 + 3."}, {"input": "flights = [[0,0,0],[0,0,0],[0,0,0]], days = [[1,1,1],[7,7,7],[7,7,7]]", "output": "3", "explanation": "Stuck in city 0, collecting 1 per week."}, {"input": "flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[7,0,0],[0,7,0],[0,0,7]]", "output": "21", "explanation": "Hop 0 -> 1 -> 2 for 7 + 7 + 7."}], "hints": ["Roll a one-dimensional DP over weeks: dp[city] is the best total ending that week in that city.", "Week 0 is reachable from city 0 via a flight or by staying; later weeks transition from any city with a flight in.", "Unreachable states stay at negative infinity and the answer is the best value after the last week."], "statement": "There are `n` cities and `k` weeks of vacation. `flights[i][j]` is 1 when a direct flight from city `i` to city `j` exists (staying put is always allowed, regardless of the diagonal). `days[i][w]` says how many vacation days you earn by spending week `w` in city `i`.\n\nYou begin week 0 in city 0: each Monday you may take any available flight (or stay), then collect that week's days in the city where you land. Plan the `k` weeks to maximize the total days collected.\n\n**Constraints:**\n- `n == flights.length == days.length`, `1 <= n <= 100`\n- `k == days[0].length`, `1 <= k <= 100`\n- `flights` entries are `0` or `1`; `0 <= days[i][w] <= 7`.\n", "solution": "## Approach\n\nKeep one DP row across cities: after processing each week, `dp[j]` holds the best vacation total for being in city `j` that week. The first week is seeded from city 0 through flights or staying; every later week relaxes each destination over all origins that can reach it. Impossible states carry negative infinity, and the maximum over the final row is the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k * n^2) for k weeks over all origin-destination pairs.\n- **Space Complexity:** O(n) for the two rolling rows.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def maxVacationDays(self, flights: List[List[int]], days: List[List[int]]) -> int:\n n, k = len(flights), len(days[0])\n NEG = float(\"-inf\")\n dp = [NEG] * n\n for j in range(n):\n if j == 0 or flights[0][j] == 1:\n dp[j] = days[j][0]\n for week in range(1, k):\n nd = [NEG] * n\n for j in range(n):\n for i in range(n):\n if dp[i] != NEG and (i == j or flights[i][j] == 1):\n nd[j] = max(nd[j], dp[i] + days[j][week])\n dp = nd\n return max(dp)\n```\n", "starter": {"go": "package main\n\nfunc MaxVacationDays(flights [][]int, days [][]int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxVacationDays(self, flights: List[List[int]], days: List[List[int]]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxVacationDays(vector<vector<int>>& flights, vector<vector<int>>& days) {\n return 0;\n }\n};"}, "fn": "maxVacationDays", "params": [{"name": "flights", "type": "int_array_2d"}, {"name": "days", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[0,1,1],[1,0,1],[1,1,0]]", "[[1,3,1],[6,0,3],[3,3,3]]"], ["[[0,0,0],[0,0,0],[0,0,0]]", "[[1,1,1],[7,7,7],[7,7,7]]"], ["[[0,1,1],[1,0,1],[1,1,0]]", "[[7,0,0],[0,7,0],[0,0,7]]"], ["[[0]]", "[[5]]"], ["[[0]]", "[[1,2,3]]"], ["[[0,1],[1,0]]", "[[1,1],[10,10]]"], ["[[0,0],[0,0]]", "[[1,1],[10,10]]"], ["[[0,1],[0,0]]", "[[1,100],[1,1]]"], ["[[0,1,0],[0,0,1],[1,0,0]]", "[[5,1,1],[1,5,1],[1,1,5]]"], ["[[0]]", "[[7]]"], ["[[0, 0, 0], [1, 0, 1], [1, 1, 0]]", "[[5, 1, 6, 0], [0, 4, 2, 2], [7, 2, 3, 5]]"], ["[[0, 0], [0, 0]]", "[[2, 1, 7, 7], [0, 0, 6, 7]]"], ["[[0, 1, 0, 0], [1, 0, 0, 1], [1, 0, 0, 0], [0, 1, 1, 0]]", "[[3], [2], [0], [5]]"], ["[[0, 0, 0, 1], [0, 0, 0, 0], [1, 1, 0, 0], [0, 1, 1, 0]]", "[[0, 3], [7, 7], [6, 3], [7, 6]]"], ["[[0, 0, 0], [1, 0, 1], [1, 1, 0]]", "[[6], [1], [6]]"], ["[[0, 0, 1], [1, 0, 1], [0, 0, 0]]", "[[6, 5, 0, 7], [0, 3, 3, 0], [7, 0, 3, 4]]"], ["[[0]]", "[[1]]"], ["[[0, 1, 0], [0, 0, 0], [0, 0, 0]]", "[[2], [7], [0]]"], ["[[0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 0, 0], [1, 1, 0, 0]]", "[[5], [6], [4], [3]]"], ["[[0]]", "[[1]]"], ["[[0, 1, 1], [0, 0, 1], [0, 1, 0]]", "[[5], [5], [2]]"], ["[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [0, 1, 0, 0]]", "[[3], [7], [2], [4]]"], ["[[0, 1], [1, 0]]", "[[7], [3]]"], ["[[0, 1, 0, 0], [1, 0, 1, 1], [1, 0, 0, 0], [1, 1, 1, 0]]", "[[6], [3], [1], [6]]"], ["[[0, 0, 0, 1], [0, 0, 0, 0], [1, 1, 0, 1], [0, 1, 1, 0]]", "[[1, 5], [2, 6], [4, 3], [7, 0]]"], ["[[0, 1, 1], [0, 0, 1], [1, 1, 0]]", "[[2], [5], [7]]"], ["[[0]]", "[[6, 4, 3]]"], ["[[0, 0, 1, 1], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]", "[[5, 2], [4, 7], [5, 3], [1, 1]]"]], "expected": [12, 3, 21, 5, 6, 20, 2, 101, 15, 7, 12, 17, 3, 14, 6, 18, 1, 7, 5, 1, 5, 3, 7, 6, 13, 7, 13, 12], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "681", "slug": "maximum-width-of-binary-tree", "id": 681, "title": "Maximum Width of Binary Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/maximum-width-of-binary-tree/", "examples": [{"input": "root = [1,3,2,5,3,null,9]", "output": "4", "explanation": "Level 2 spans positions for 5,3,null,9 giving width 4."}, {"input": "root = [1,3,2,5,null,null,9,6,null,7]", "output": "7", "explanation": "The lowest level stretches across 7 slots including gaps."}, {"input": "root = [1,3,2,5]", "output": "2", "explanation": "The second level holds two adjacent nodes."}], "hints": ["Number nodes as in a heap: children of index i sit at 2*i and 2*i+1.", "Width of a level is last index minus first index plus one, counting empty slots between.", "Normalize indices per level (subtract the first) to keep numbers small."], "statement": "You are given the root of a binary tree.\n\nImagine numbering positions level by level as in a complete tree: the root is 1, and a node numbered `i` has children numbered `2*i` and `2*i+1`. Missing nodes still occupy numbers.\n\nThe width of a level is the distance between its leftmost and rightmost present nodes, inclusive of gaps: `last - first + 1`. Return the largest width over all levels.\n\n**Constraints:**\n- `1 <= number of nodes <= 3000`\n- `-100 <= node value <= 100`\n", "solution": "## Approach\n\nWalk level by level while carrying heap-style indices. Children of index `i` get `2*i` and `2*i+1`, so gaps are preserved. The width of a level is last minus first plus one. Subtracting the first index of each level before expanding keeps values small.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) visiting each node once.\n- **Space Complexity:** O(n) for the level queues.\n\n## Implementation\n\n```python\nfrom collections import deque\nclass Solution:\n def widthOfBinaryTree(self, root) -> int:\n if not root:\n return 0\n ans = 1\n q = deque([(root, 0)])\n while q:\n first = q[0][1]\n last = first\n for _ in range(len(q)):\n n, idx = q.popleft()\n idx -= first\n last = first + idx\n if n.left:\n q.append((n.left, idx * 2))\n if n.right:\n q.append((n.right, idx * 2 + 1))\n ans = max(ans, last - first + 1)\n return ans\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 WidthOfBinaryTree(root *TreeNode) int {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def widthOfBinaryTree(self, root) -> int:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int widthOfBinaryTree(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "widthOfBinaryTree", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int", "tests": [["[1,3,2,5,3,null,9]"], ["[1,3,2,5,null,null,9,6,null,7]"], ["[1,3,2,5]"], ["[1]"], ["[1,2]"], ["[1,null,2]"], ["[1,2,3,4,5,6,7]"], ["[1,2,3,4,null,null,7,8,null,null,null,null,15]"], ["[1,2,null,3,null,4,null]"], ["[1,null,2,null,3,null,4]"], ["[5,3,8,1,4,null,9,0,2]"], ["[1,3,2,5,null,null,9,6,null,null,7]"], ["[0,0,0,0,null,null,0,0,null,null,0]"], ["[1,2,3,null,4,null,5]"], ["[10,5,15,3,7,null,18,1,null,6,null]"], ["[1,2,3,4,5,null,6,null,null,7]"], ["[2,1,3,0,null,null,4]"], ["[1,2,null,3,4]"], ["[1,null,2,3,4]"], ["[7,3,9,1,5,null,10,0,2,4,6]"], ["[1,2,2,3,null,null,3,4,null,null,4]"], ["[100,50,150,25,75,125,175]"], ["[1,2,3,null,null,4,5,6,null,null,7]"], ["[3,1,4,null,2]"], ["[1,2,3,4,null,6,7,null,5]"], ["[9,7,11,6,8,10,12,5,null,null,null,null,null,null,13]"], ["[1,null,2,null,3]"], ["[4,2,6,1,3,5,7,0,null,null,null,null,null,null,8]"]], "expected": [4, 7, 2, 1, 1, 1, 4, 4, 1, 1, 4, 8, 8, 3, 4, 4, 4, 2, 2, 4, 8, 4, 4, 2, 4, 8, 1, 8], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "948", "slug": "maximum-width-ramp", "id": 948, "title": "Maximum Width Ramp", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/maximum-width-ramp/", "examples": [{"input": "nums = [6,0,8,2,1,5]", "output": "4", "explanation": "Pairing index 1 (value 0) with index 5 (value 5) spans 4 positions, wider than any other valid pair."}, {"input": "nums = [9,8,1,0,1,9,4,0,4,1]", "output": "7", "explanation": "Index 2 (value 1) to index 9 (value 1) gives width 7, the best possible here."}, {"input": "nums = [5,4,3,2,1]", "output": "0", "explanation": "Strictly falling values admit no pair with i < j and nums[i] <= nums[j], so the width is 0."}], "hints": ["Candidate left ends are exactly the positions holding new prefix minima.", "Keep those minima on a decreasing stack, then match each right end from the far right.", "Each index enters and leaves the stack once, giving linear time."], "statement": "A ramp is a pair of positions `i < j` with `nums[i] <= nums[j]`, and its width is the distance `j - i`. Find the greatest width among all ramps in the array, or return 0 when no ramp exists.\n\n**Constraints:**\n- `1 <= nums.length <= 5 * 10^4`\n- `0 <= nums[i] <= 5 * 10^4`\n", "solution": "## Approach\n\nCollect candidate left endpoints by scanning once and keeping indices with strictly decreasing values on a stack \u2014 any useful left end must be a new minimum. Then scan right endpoints from the far right, popping stack entries that the current right end can pair with; the first pop for each right end is its widest partner. Tracking the best distance yields the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) \u2014 each index is pushed and popped at most once.\n- **Space Complexity:** O(n) for the decreasing stack.\n\n## Implementation\n\n```python\nclass Solution:\n def maxWidthRamp(self, nums: list[int]) -> int:\n n = len(nums)\n st = []\n for i in range(n):\n if not st or nums[i] < nums[st[-1]]:\n st.append(i)\n best = 0\n for j in range(n - 1, -1, -1):\n while st and nums[st[-1]] <= nums[j]:\n best = max(best, j - st.pop())\n if not st:\n break\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxWidthRamp(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxWidthRamp(self, nums: List[int]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxWidthRamp(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "maxWidthRamp", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[6,0,8,2,1,5]"], ["[9,8,1,0,1,9,4,0,4,1]"], ["[5,4,3,2,1]"], ["[1,2,3,4,5]"], ["[5]"], ["[0,0,0,0]"], ["[3,1,2]"], ["[2,2,2,2,2]"], ["[10,1,2,3,4,5,6,7,8,9]"], ["[9,1,8,2,7,3,6,4,5]"], ["[1,0]"], ["[0,1]"], ["[4,3,2,1,5]"], ["[5,1,4,2,3]"], ["[2,1,5,4,3,6]"], ["[7,3,5,1,9,2,8,4,6]"], ["[100,50,200,25,300]"], ["[1,1,1,2,1,1]"], ["[8,7,6,5,9]"], ["[3,3,3,1,3,3]"], ["[12,11,10,1,2,13]"], ["[0,8,4,12,2,10,6,14,1,9]"], ["[6,5,4,3,2,1,7]"], ["[1,2]"], ["[2,1]"], ["[50000,0,50000]"], ["[1000,999,998,997,996,995,994,993,992,991,990,989,988,987,986,985,984,983,982,981,980,979,978,977,976,975,974,973,972,971,970,969,968,967,966,965,964,963,962,961,960,959,958,957,956,955,954,953,952,951,950,949,948,947,946,945,944,943,942,941,940,939,938,937,936,935,934,933,932,931,930,929,928,927,926,925,924,923,922,921,920,919,918,917,916,915,914,913,912,911,910,909,908,907,906,905,904,903,902,901,900,899,898,897,896,895,894,893,892,891,890,889,888,887,886,885,884,883,882,881,880,879,878,877,876,875,874,873,872,871,870,869,868,867,866,865,864,863,862,861,860,859,858,857,856,855,854,853,852,851,850,849,848,847,846,845,844,843,842,841,840,839,838,837,836,835,834,833,832,831,830,829,828,827,826,825,824,823,822,821,820,819,818,817,816,815,814,813,812,811,810,809,808,807,806,805,804,803,802,801,800,799,798,797,796,795,794,793,792,791,790,789,788,787,786,785,784,783,782,781,780,779,778,777,776,775,774,773,772,771,770,769,768,767,766,765,764,763,762,761,760,759,758,757,756,755,754,753,752,751,750,749,748,747,746,745,744,743,742,741,740,739,738,737,736,735,734,733,732,731,730,729,728,727,726,725,724,723,722,721,720,719,718,717,716,715,714,713,712,711,710,709,708,707,706,705,704,703,702,701,700,699,698,697,696,695,694,693,692,691,690,689,688,687,686,685,684,683,682,681,680,679,678,677,676,675,674,673,672,671,670,669,668,667,666,665,664,663,662,661,660,659,658,657,656,655,654,653,652,651,650,649,648,647,646,645,644,643,642,641,640,639,638,637,636,635,634,633,632,631,630,629,628,627,626,625,624,623,622,621,620,619,618,617,616,615,614,613,612,611,610,609,608,607,606,605,604,603,602,601,600,599,598,597,596,595,594,593,592,591,590,589,588,587,586,585,584,583,582,581,580,579,578,577,576,575,574,573,572,571,570,569,568,567,566,565,564,563,562,561,560,559,558,557,556,555,554,553,552,551,550,549,548,547,546,545,544,543,542,541,540,539,538,537,536,535,534,533,532,531,530,529,528,527,526,525,524,523,522,521,520,519,518,517,516,515,514,513,512,511,510,509,508,507,506,505,504,503,502,501,500,499,498,497,496,495,494,493,492,491,490,489,488,487,486,485,484,483,482,481,480,479,478,477,476,475,474,473,472,471,470,469,468,467,466,465,464,463,462,461,460,459,458,457,456,455,454,453,452,451,450,449,448,447,446,445,444,443,442,441,440,439,438,437,436,435,434,433,432,431,430,429,428,427,426,425,424,423,422,421,420,419,418,417,416,415,414,413,412,411,410,409,408,407,406,405,404,403,402,401,400,399,398,397,396,395,394,393,392,391,390,389,388,387,386,385,384,383,382,381,380,379,378,377,376,375,374,373,372,371,370,369,368,367,366,365,364,363,362,361,360,359,358,357,356,355,354,353,352,351,350,349,348,347,346,345,344,343,342,341,340,339,338,337,336,335,334,333,332,331,330,329,328,327,326,325,324,323,322,321,320,319,318,317,316,315,314,313,312,311,310,309,308,307,306,305,304,303,302,301,300,299,298,297,296,295,294,293,292,291,290,289,288,287,286,285,284,283,282,281,280,279,278,277,276,275,274,273,272,271,270,269,268,267,266,265,264,263,262,261,260,259,258,257,256,255,254,253,252,251,250,249,248,247,246,245,244,243,242,241,240,239,238,237,236,235,234,233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,218,217,216,215,214,213,212,211,210,209,208,207,206,205,204,203,202,201,200,199,198,197,196,195,194,193,192,191,190,189,188,187,186,185,184,183,182,181,180,179,178,177,176,175,174,173,172,171,170,169,168,167,166,165,164,163,162,161,160,159,158,157,156,155,154,153,152,151,150,149,148,147,146,145,144,143,142,141,140,139,138,137,136,135,134,133,132,131,130,129,128,127,126,125,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,1001]"], ["[42,42]"]], "expected": [4, 7, 0, 4, 0, 3, 1, 4, 8, 7, 0, 1, 4, 3, 5, 7, 4, 5, 4, 5, 5, 9, 6, 1, 0, 2, 1000, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "492", "slug": "maximum-xor-of-two-numbers-in-an-array", "id": 492, "title": "Maximum XOR of Two Numbers in an Array", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/", "examples": [{"input": "nums = [3,10,5,25,2,8]", "output": "28", "explanation": "5 XOR 25 equals 28, and no pair reaches a larger value."}, {"input": "nums = [14,70,53,83,49,91,36,80,92,51,66,70]", "output": "127", "explanation": "Some pair in the list XORs to 127, which is the best achievable score."}], "hints": ["Think bit by bit from the most significant position downward, keeping the set of prefixes seen so far.", "A binary trie of the numbers lets you greedily walk toward the opposite bit at each level.", "Trying to build the answer greedily works: check whether a candidate prefix pattern is attainable from pairs of number prefixes."], "statement": "You are given a list of non-negative integers called `nums`. Pick two positions `i` and `j` (they may be the same position) and look at the value `nums[i] XOR nums[j]`, where `XOR` is the bitwise exclusive-or operation.\n\nReturn the largest XOR value you can obtain from any such pair.\n\n**Constraints:**\n- `1 <= nums.length <= 2 * 10^4`\n- `0 <= nums[i] <= 2^31 - 1`\n", "solution": "## Approach\n\nBuild a binary trie holding every number's bits from high to low. For each value, walk the trie preferring the child with the opposite bit at every level, accumulating the XOR obtained along that greedy path. The best over all starting values is the optimum, because any bit that can be set while staying consistent with some stored number should be set.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(31 * n), where n is the length of `nums`. Each insert and each query touches a constant number of bit levels.\n- **Space Complexity:** O(31 * n) for trie nodes in the worst case.\n\n## Implementation\n\n```python\nclass Solution:\n def findMaximumXOR(self, nums):\n root = {}\n for v in nums:\n cur = root\n for b in range(30, -1, -1):\n bit = (v >> b) & 1\n cur = cur.setdefault(bit, {})\n best = 0\n for v in nums:\n cur = root\n cur_xor = 0\n for b in range(30, -1, -1):\n bit = (v >> b) & 1\n want = bit ^ 1\n if want in cur:\n cur_xor |= (1 << b)\n cur = cur[want]\n else:\n cur = cur[bit]\n best = max(best, cur_xor)\n return best\n```\n", "starter": {"go": "package main\n\nfunc FindMaximumXOR(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findMaximumXOR(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "findMaximumXOR", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[3,10,5,25,2,8]"], ["[14,70,53,83,49,91,36,80,92,51,66,70]"], ["[0]"], ["[1,1,1]"], ["[8,10,2]"], ["[0,0]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[2147483647,0]"], ["[16,32,48]"], ["[5]"], ["[2,4]"], ["[0,1]"], ["[1000000,999999,123456]"], ["[7,7,7,7]"], ["[3,3,10,10,5,5,25,25,2,2,8,8]"], ["[0,2147483647,1073741824]"], ["[1,2]"], ["[42,42]"], ["[10,15]"], ["[128,256,512,1024]"], ["[3,10,5,25,2,8,30,41]"], ["[0,0,0,0]"], ["[1,2147483647]"], ["[1024,2048,4096,8192]"], ["[15,15,15,15,15]"], ["[123,456,789,101112]"], ["[0,2,5,7,11,13]"], ["[2147483646,2147483645,2147483644]"]], "expected": [28, 127, 0, 0, 10, 0, 15, 2147483647, 48, 0, 6, 1, 958591, 0, 28, 2147483647, 3, 0, 5, 1536, 55, 0, 2147483646, 12288, 0, 101168, 15, 3], "loose": false}