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": "328", "slug": "best-time-to-buy-and-sell-stock-iv", "id": 328, "title": "Best Time to Buy and Sell Stock IV", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/", "examples": [{"explanation": "Buy at 2, sell at 4 for profit 2; no second profitable trade exists.", "input": "k = 2, prices = [2,4,1]", "output": "2"}, {"explanation": "Trade 2->6 (profit 4) and 0->3 (profit 3) for a total of 7.", "input": "k = 2, prices = [3,2,6,5,0,3]", "output": "7"}, {"explanation": "With one trade allowed, buy at 1 and sell at 5.", "input": "k = 1, prices = [1,2,3,4,5]", "output": "4"}], "hints": ["When k is at least half the number of days, every upward step can be taken: sum all positive day-to-day differences.", "Otherwise track, for each trade count j, the best balance while holding (buy[j]) and while free (sell[j]), updating both as each price arrives.", "A buy on day i uses sell[j-1] - price; a sell uses buy[j] + price. The answer is sell[k]."], "statement": "You are handed the daily prices of one stock as an array `prices`, where `prices[i]` is the price on day `i`. You may complete at most `k` round-trip trades: each trade means buying one share on some day and selling it on a later day. You cannot hold more than one share at a time (sell before buying again).\n\nCompute the greatest total profit achievable. If no profitable trade exists, the answer is 0.\n\n**Constraints:**\n- `1 <= k <= 100`\n- `0 <= prices.length <= 1000`\n- `0 <= prices[i] <= 1000`\n", "solution": "## Approach\n\nWhen `k` covers half the days, any profitable day-to-day step can be banked, so the answer is the sum of positive differences. Otherwise keep two small tables over the trade count: the best balance while holding a share and while holding nothing. Each price either improves a buy (`sell[j-1] - price`) or a sell (`buy[j] + price`), which captures the optimal set of at most `k` round trips in one pass.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * k), one update per day per allowed trade.\n- **Space Complexity:** O(k) for the buy/sell tables.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:\n n = len(prices)\n if n <= 1 or k <= 0:\n return 0\n if k >= n // 2:\n return sum(max(0, prices[i] - prices[i - 1]) for i in range(1, n))\n buy = [float(\"-inf\")] * (k + 1)\n sell = [0] * (k + 1)\n for p in prices:\n for j in range(1, k + 1):\n buy[j] = max(buy[j], sell[j - 1] - p)\n sell[j] = max(sell[j], buy[j] + p)\n return sell[k]\n```\n", "starter": {"go": "package main\n\nfunc MaxProfit(k int, prices []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxProfit(self, k: int, prices: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxProfit(int k, vector<int>& prices) {\n return 0;\n }\n};"}, "fn": "maxProfit", "params": [{"name": "k", "type": "int"}, {"name": "prices", "type": "int_array"}], "outputType": "int", "tests": [["2", "[2,4,1]"], ["2", "[3,2,6,5,0,3]"], ["1", "[1,2,3,4,5]"], ["1", "[7,6,4,3,1]"], ["2", "[1,2,4,2,5,7,2,4,9,0]"], ["2", "[]"], ["5", "[5]"], ["1", "[1,2]"], ["2", "[2,1,2,0,1]"], ["3", "[3,3,5,0,0,3,1,4]"], ["2", "[1,2,3,4,5,6,7]"], ["2", "[7,6,5,4,3,2,1]"], ["4", "[1,3,2,8,4,9]"], ["2", "[5,5,5,5,5]"], ["3", "[1,2]"], ["10", "[1,2,4,2,5,7,2,4,9,0]"], ["100", "[3,2,6,5,0,3]"], ["2", "[0,0,0,1,0,2]"], ["3", "[8,6,4,3,3,2,3,5,2,1]"], ["2", "[6,1,3,2,4,7]"], ["1", "[2,4,1,5,3]"], ["5", "[9,1,2,3,4,5,0,8]"], ["2", "[1,100,101,0,50,60]"], ["3", "[5,1,5,1,5,1,5]"], ["2", "[1000,0,1000,0,1000]"], ["50", "[1,3,2,8,4,9,0,5,7,6,8,2]"]], "expected": [2, 7, 4, 0, 13, 0, 0, 1, 2, 8, 6, 0, 13, 0, 1, 15, 7, 3, 3, 7, 4, 12, 160, 12, 2000, 22], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "129", "slug": "best-time-to-buy-and-sell-stock-with-cooldown", "id": 129, "title": "Best Time to Buy and Sell Stock with Cooldown", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/", "examples": [{"input": "prices = [1,2,3,0,2]", "output": "3", "explanation": "Buy on day 0, sell on day 1, cooldown, then buy on day 3 and sell on day 4."}, {"input": "prices = [1]", "output": "0", "explanation": "With only one price, no transaction can be made, so the maximum profit is 0."}], "hints": ["Track the best value after each day in three states: holding, just sold, and resting.", "A buy transition can only come from a resting state, not from the previous day's sold state."], "statement": "The array `prices` lists one stock's daily quote, where `prices[i]` is what the share costs on day `i`. Chain together as many buy-then-sell round trips as you find worthwhile and report the best total profit they can yield.\n\nTwo trading rules apply throughout: your hand may carry at most one share at any moment, and the day directly after any sale is a mandatory rest day on which buying is forbidden.\n\n**Constraints:**\n- `1 <= prices.length <= 5000`\n- `0 <= prices[i] <= 1000`\n", "solution": "## Approach\n\nMaintain the best profit after each day in three states: holding a share, having just\nsold a share, and resting without a share. Buying is allowed only from the resting\nstate, which enforces the one-day cooldown after a sale.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where `n` is the number of days.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def maxProfit(self, prices: List[int]) -> int:\n hold = -prices[0]\n sold = rest = 0\n for i in range(1, len(prices)):\n previous_sold = sold\n sold = hold + prices[i]\n hold = max(hold, rest - prices[i])\n rest = max(rest, previous_sold)\n return max(sold, rest)\n```\n", "starter": {"go": "package main\n\nfunc MaxProfit(prices []int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def maxProfit(self, prices: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n return 0;\n }\n};"}, "fn": "maxProfit", "params": [{"name": "prices", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,3,0,2]"], ["[1]"], ["[0]"], ["[1,2]"], ["[2,1]"], ["[2,2]"], ["[0,1]"], ["[1,0]"], ["[2,1,4]"], ["[1,2,3]"], ["[3,2,1]"], ["[1,3,2]"], ["[3,1,2]"], ["[0,0,0,0]"], ["[1,1,1,1]"], ["[1,2,1,2]"], ["[1,2,1,2,1,2]"], ["[2,1,2,1,2,1]"], ["[6,1,3,2,4,7]"], ["[7,6,4,3,1]"], ["[1,2,4]"], ["[2,1,4,5,2,9,7]"], ["[3,3,5,0,0,3,1,4]"], ["[1,4,2,7]"], ["[1,4,2,7,0,5]"], ["[5,4,3,2,1,2,3,4,5]"], ["[0,5,0,5,0,5]"], ["[5,0,5,0,5,0]"], ["[1,10,0,10]"], ["[10,1,10,1,10]"], ["[1,10,1,10,1,10]"], ["[4,1,2,10,1,2]"], ["[2,4,1,7,5,3,6,4]"], ["[8,6,7,5,3,10,2,9]"], ["[1,3,7,5,10,3]"], ["[3,2,6,5,0,3]"], ["[2,5,7,1,4,3,1,3]"], ["[9,8,7,1,2,3,0,4]"], ["[1000,0,1000]"], ["[0,1000,0,1000]"], ["[1000,999,998,997,996]"], ["[996,997,998,999,1000]"], ["[1,100,2,99,3,98,4,97]"], ["[100,1,99,2,98,3,97,4]"], ["[31,41,59,26,53,58,97,93]"], ["[5,10,15,20,5,10,15,20]"], ["[20,15,10,5,20,15,10,5]"], ["[4,9,0,4,10]"], ["[0,4,9,0,4,10]"], ["[2,8,1,9,0,10]"], ["[10,0,9,1,8,2,7,3]"], ["[3,8,2,5,7,1,6,4,9]"], ["[12,11,15,3,10,8,20,1,7]"], ["[1,2,3,4,5,0,1,2,3,4,5]"], ["[5,4,3,2,1,0,1,2,3,4,5]"], ["[0,2,4,6,1,3,5,7,0,8]"], ["@javascript:JSON.stringify(Array.from({length:5000},(_,i)=>i%3===1?1000:0))"]], "expected": [3, 0, 0, 1, 0, 0, 1, 0, 3, 2, 0, 2, 1, 0, 0, 1, 2, 1, 6, 0, 3, 10, 6, 6, 8, 4, 10, 5, 10, 9, 18, 9, 9, 8, 9, 7, 8, 5, 1000, 1000, 0, 4, 194, 192, 81, 25, 15, 11, 15, 16, 14, 13, 17, 8, 5, 16, 1667000], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "722", "slug": "best-time-to-buy-and-sell-stock-with-transaction-fee", "id": 722, "title": "Best Time to Buy and Sell Stock with Transaction Fee", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/", "examples": [{"input": "prices = [1,3,2,8,4,9], fee = 2", "output": "8", "explanation": "Buy at 1, sell at 8 (profit 5), then buy at 4 and sell at 9 (profit 3) for 8 total."}, {"input": "prices = [1,3,7,5,10,3], fee = 3", "output": "6", "explanation": "One round trip from 1 to 10 nets 9 minus the 3 fee."}, {"input": "prices = [5,4,3,2,1], fee = 1", "output": "0", "explanation": "Prices only fall, so skipping every trade is best."}], "hints": ["Track two states per day: the best balance holding a share and the best balance holding cash.", "Holding updates from yesterday's hold or today's cash minus the price; cash updates from yesterday's cash or today's hold plus price minus fee.", "Start holding at -prices[0] and cash at 0; the cash state at the end is the answer."], "statement": "You are given daily share prices and a fixed fee charged on every sale. You may complete any number of buys and sells, but you can hold at most one share at a time.\n\nBuying costs the listed price; selling gains the price minus the fee. Passing on quiet days is always allowed.\n\nReturn the greatest profit achievable, or zero when no trade helps.\n\n**Constraints:**\n- `1 <= prices.length <= 50000`\n- `0 <= prices[i] < 50000`\n- `0 <= fee < 50000`\n", "solution": "## Approach\n\nKeep two running balances: `hold` for ending the day with a share and `cash` for ending with no share. Each new price lets hold improve by buying from cash, and lets cash improve by selling from hold minus the fee. Both start from day zero and roll forward.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of prices.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def maxProfit(self, prices: List[int], fee: int) -> int:\n hold = -prices[0]\n cash = 0\n for p in prices[1:]:\n hold = max(hold, cash - p)\n cash = max(cash, hold + p - fee)\n return cash\n```\n", "starter": {"go": "package main\n\nfunc MaxProfit(prices []int, fee int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def maxProfit(self, prices: List[int], fee: int) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxProfit(vector<int>& prices, int fee) {\n return 0;\n }\n};"}, "fn": "maxProfit", "params": [{"name": "prices", "type": "int_array"}, {"name": "fee", "type": "int"}], "outputType": "int", "tests": [["[1,3,2,8,4,9]", "2"], ["[1,3,7,5,10,3]", "3"], ["[5,4,3,2,1]", "1"], ["[1]", "0"], ["[1]", "5"], ["[1,2]", "0"], ["[2,1]", "0"], ["[1,5]", "4"], ["[1,5]", "5"], ["[1,10,1,10,1,10]", "2"], ["[3,3,3,3]", "0"], ["[1,2,3,4,5]", "0"], ["[5,4,3,2,10]", "1"], ["[1,2,3,0,2]", "1"], ["[4,5,2,4,3,3,1,2,5,5]", "1"], ["[1,100]", "50"], ["[10,1,10,1,10]", "3"], ["[2,4,1,5,3,6]", "2"], ["[1,2,4,2,5,7,2,4,9,0]", "2"], ["[6,1,3,2,4,7]", "2"], ["[1,3,2,8]", "2"], ["[9,8,7,1,2,5]", "2"], ["[1,4,6,2,8,3,10]", "3"], ["[2,2,2,5,5,1,7]", "1"], ["[0,0,0]", "0"], ["[100,90,80,120]", "5"], ["[3,8,1,9,2,10]", "2"], ["[1,2,3,4,10]", "9"]], "expected": [8, 6, 0, 0, 0, 1, 0, 0, 0, 21, 0, 4, 7, 2, 4, 49, 12, 3, 9, 4, 5, 2, 9, 7, 0, 35, 15, 0], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "2", "slug": "best-time-to-buy-and-sell-stock", "id": 2, "title": "Best Time to Buy and Sell Stock", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/best-time-to-buy-and-sell-stock/", "examples": [{"input": "prices = [7,1,5,3,6,4]", "output": 5, "explanation": "Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell."}, {"input": "prices = [7,6,4,3,1]", "output": 0, "explanation": "In this case no transaction is done and the max profit = 0."}, {"input": "prices = [1,2]", "output": 1, "explanation": "Buy at 1 and sell at 2 for a profit of 2 - 1 = 1."}], "hints": ["This problem asks for the maximum difference prices[j] - prices[i] where j > i. The optimal O(n) solution keeps track of the minimum price seen so far and the maximum profit obtainable at each step."], "statement": "The array `prices` quotes one stock across successive days, with `prices[i]` being its quote on day `i`. You are allowed a single round trip at most: purchase one share on some day and, if you wish, unload it on a later day. Report the largest profit such a trip can lock in; when every possible trip would lose money, settle for `0` by trading nothing.\n\n**Constraints:**\n\n- 1 \u2264 prices.length \u2264 10^5\n- 0 \u2264 prices[i] \u2264 10^4\n", "solution": "## Approach\n\nTrack the minimum price seen so far and compute the maximum profit by checking each price as a potential sell point.\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\nclass Solution:\n def maxProfit(self, prices: List[int]) -> int:\n min_price = float('inf')\n max_profit = 0\n for p in prices:\n if p < min_price:\n min_price = p\n elif p - min_price > max_profit:\n max_profit = p - min_price\n return max_profit\n```\n", "starter": {"go": "package main\n\nfunc MaxProfit(prices []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxProfit(self, prices: List[int]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int maxProfit(vector<int>& prices) {\n return 0;\n }\n};"}, "fn": "maxProfit", "params": [{"name": "prices", "type": "int_array"}], "outputType": "int", "tests": [["[7,1,5,3,6,4]"], ["[7,6,4,3,1]"], ["[1,2]"], ["[1]"], ["[0]"], ["[0,1]"], ["[0,1,2,3,4,5,5,6,7,8,8,1,2,3,4,5,4,4,3]"], ["[0,1,6,7,8,8,1,2,3,4,5,4,4,3]"], ["[0,4,3]"], ["[152,3]"], ["@javascript:JSON.stringify([...Array(99998).fill(1), 2, 2])"], ["[2,1]"], ["[1,1]"], ["[1,1,1,1]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[3,3,5,0,0,3,1,4]"], ["[2,4,1]"], ["[1,2,3,0,2]"], ["[5,1,5]"], ["[1,5,1,5]"], ["[0,0,0,1]"], ["[10,0,10]"], ["[1,10,2,9,3,8]"], ["[100,1,100]"], ["[0,100]"], ["[100,0]"], ["[1,3,2,8,4,9]"], ["[2,2,2,3,1,4]"], ["[7,1,5,3,6,4,0,8]"]], "expected": [5, 0, 1, 0, 0, 1, 8, 8, 4, 0, 1, 0, 0, 0, 4, 0, 4, 2, 2, 4, 4, 1, 10, 9, 99, 100, 0, 8, 3, 8], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "862", "slug": "binary-gap", "id": 862, "title": "Binary Gap", "difficulty": "Easy", "category": "bit-manipulation", "link": "https://leetcode.com/problems/binary-gap/", "examples": [{"input": "n = 22", "output": "2", "explanation": "Binary 10110 has gaps 2 and 2."}, {"input": "n = 8", "output": "0", "explanation": "Binary 1000 has a single one."}, {"input": "n = 5", "output": "2", "explanation": "Binary 101 has one gap of 2."}], "hints": ["Scan bits from least significant to most, remembering the index of the previous `1`.", "Update the best gap each time another `1` appears; trailing zeros after the last one never form a gap.", "Shifting the number right one bit at a time visits every position exactly once."], "statement": "You are given a positive integer `n`. Look at its binary representation without leading zeros.\n\nWhenever the representation holds at least two `1` bits, measure the distance between every pair of neighboring `1` bits, where distance means the difference of their bit positions (equivalently, the number of steps between them). Return the largest such distance. If fewer than two `1` bits appear, return `0`.\n\n**Constraints:**\n- `1 <= n <= 10^9`\n", "solution": "## Approach\n\nWalk through the bits from right to left, counting positions. Remember where the previous `1` was seen; each new `1` forms a gap with it, and the maximum over all such gaps is the answer. Numbers with zero or one `1` naturally yield zero.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n), one step per binary digit.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def binaryGap(self, n: int) -> int:\n prev = -1\n best = 0\n idx = 0\n while n > 0:\n if n & 1:\n if prev != -1:\n best = max(best, idx - prev)\n prev = idx\n n >>= 1\n idx += 1\n return best\n```\n", "starter": {"go": "package main\n\nfunc BinaryGap(n int) int {\n return 0\n}", "python": "class Solution:\n def binaryGap(self, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int binaryGap(int n) {\n return 0;\n }\n};"}, "fn": "binaryGap", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["22"], ["8"], ["5"], ["1"], ["2"], ["3"], ["6"], ["7"], ["9"], ["13"], ["15"], ["16"], ["17"], ["21"], ["32"], ["100"], ["255"], ["256"], ["1000"], ["1023"], ["1024"], ["1000000"], ["1000000000"], ["999999999"], ["512"], ["1025"], ["41"], ["18"]], "expected": [2, 0, 2, 0, 0, 1, 1, 1, 3, 2, 1, 0, 4, 2, 0, 3, 1, 0, 2, 1, 0, 5, 3, 3, 0, 10, 3, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "708", "slug": "binary-number-with-alternating-bits", "id": 708, "title": "Binary Number with Alternating Bits", "difficulty": "Easy", "category": "bit-manipulation", "link": "https://leetcode.com/problems/binary-number-with-alternating-bits/", "examples": [{"input": "n = 5", "output": "true", "explanation": "101 alternates."}, {"input": "n = 7", "output": "false", "explanation": "111 does not."}, {"input": "n = 10", "output": "true", "explanation": "1010 alternates."}], "hints": ["Compare each bit with the previous one while shifting right.", "Alternatively, n ^ (n >> 1) should be of the form 0b111...1 for alternating values."], "statement": "Given a positive integer `n`, look at its binary writing without leading zeros. Decide whether every pair of neighbouring bits differs (the pattern must alternate between `0` and `1`).\n\nReturn `true` for alternating numbers and `false` otherwise.\n\n**Constraints:**\n- `1 <= n <= 2^31 - 1`\n", "solution": "## Approach\n\nPeel off bits from the right. Remember the lowest bit, shift once, and require every new lowest bit to differ from the remembered one. A single repeated adjacent pair disproves the property; surviving the whole scan proves alternation.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n), one step per bit.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def hasAlternatingBits(self, n: int) -> bool:\n prev = n & 1\n n >>= 1\n while n:\n cur = n & 1\n if cur == prev:\n return False\n prev = cur\n n >>= 1\n return True\n```\n", "starter": {"go": "package main\n\nfunc HasAlternatingBits(n int) bool {\n return false\n}", "python": "class Solution:\n def hasAlternatingBits(self, n: int) -> bool:\n return False\n", "cpp": "class Solution {\npublic:\n bool hasAlternatingBits(int n) {\n return false;\n }\n};"}, "fn": "hasAlternatingBits", "params": [{"name": "n", "type": "int"}], "outputType": "boolean", "tests": [["5"], ["7"], ["10"], ["1"], ["2"], ["3"], ["4"], ["11"], ["21"], ["42"], ["85"], ["170"], ["341"], ["682"], ["8"], ["12"], ["15"], ["16"], ["31"], ["32"], ["63"], ["64"], ["100"], ["1000"], ["1000000"], ["1073741824"], ["2147483647"], ["1365"]], "expected": [true, false, true, true, true, false, false, false, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "323", "slug": "binary-search-tree-iterator", "id": 323, "title": "Binary Search Tree Iterator", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-search-tree-iterator/", "examples": [{"explanation": "Ascending order is [3,7,9,15,20]. The first two next calls give 3 and 7; values remain so hasNext is 1; next gives 9; values remain so 1; next gives 15; one value (20) remains so 1.", "input": "root = [7,3,15,null,null,9,20], operations = [\"next\",\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\"]", "output": "[3,7,1,9,1,15,1]"}, {"explanation": "One value remains (1), next returns 1, then nothing remains (0).", "input": "root = [1], operations = [\"hasNext\",\"next\",\"hasNext\"]", "output": "[1,1,0]"}, {"explanation": "An empty tree has no next value.", "input": "root = [], operations = [\"hasNext\"]", "output": "[0]"}], "hints": ["Flatten the tree once with an inorder walk to get ascending values, then serve operations with an index pointer.", "Alternatively push left children onto a stack and expand right subtrees lazily for O(h) memory."], "statement": "This is an offline adaptation of a design task. Instead of writing a class, you write one function that replays a whole session:\n\n```\nrunBstIterator(root, operations)\n```\n\n`root` is the binary search tree to walk (level-order form such as `[7,3,15,null,null,9,20]`), and `operations` holds only `\"next\"` or `\"hasNext\"`, in the order they are called. The iterator visits values in ascending order:\n\n- `\"next\"` returns the next smallest value and moves forward.\n- `\"hasNext\"` returns `1` when values remain and `0` otherwise.\n\nReturn the answers for every operation in order, encoding `\"hasNext\"` as `1` or `0`.\n\n**Constraints:**\n- `0 <= number of nodes <= 10^4`\n- `-10^5 <= Node.val <= 10^5`\n- `\"next\"` is only called when `\"hasNext\"` would be true.\n", "solution": "## Approach\n\nWalk the tree once in inorder order to collect values from smallest to largest, then serve the operation list with a position pointer. A next step returns the value at the pointer and advances it; a hasNext step reports 1 while the pointer is inside the list and 0 otherwise. This mirrors a controlled inorder iterator without lazy stack handling.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the one inorder walk, plus O(1) per operation.\n- **Space Complexity:** O(n) for the flattened values.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def runBstIterator(self, root, operations: List[str]) -> List[int]:\n order = []\n def dfs(node):\n if not node:\n return\n dfs(node.left)\n order.append(node.val)\n dfs(node.right)\n dfs(root)\n ans = []\n idx = 0\n for op in operations:\n if op == \"next\":\n ans.append(order[idx])\n idx += 1\n elif op == \"hasNext\":\n ans.append(1 if idx < len(order) else 0)\n return ans\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc RunBstIterator(root *TreeNode, operations []string) []int {\n return []int{}\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import List\n\nclass Solution:\n def runBstIterator(self, root, operations: List[str]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n/*\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 vector<int> runBstIterator(TreeNode* root, vector<string>& operations) {\n return {};\n }\n};"}, "fn": "runBstIterator", "params": [{"name": "root", "type": "tree_node"}, {"name": "operations", "type": "string_array"}], "outputType": "int_array", "tests": [["[7,3,15,null,null,9,20]", "[\"next\",\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[1]", "[\"hasNext\",\"next\",\"hasNext\"]"], ["[]", "[\"hasNext\"]"], ["[2,1,3]", "[\"next\",\"hasNext\"]"], ["[5,3,6,2,4,null,null,1]", "[\"hasNext\",\"next\",\"next\",\"hasNext\"]"], ["[3,1,4,null,2]", "[\"next\",\"next\",\"next\",\"hasNext\"]"], ["[]", "[\"hasNext\",\"hasNext\"]"], ["[10,5,15,3,7,12,20]", "[\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[42]", "[\"next\"]"], ["[2,null,3]", "[\"hasNext\",\"next\"]"], ["[4,2,6,1,3,5,7]", "[\"next\",\"next\",\"hasNext\"]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "[\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[5,1,7,0,2,6,8]", "[\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[1,2,3]", "[\"hasNext\"]"], ["[0,-10,10]", "[\"next\",\"hasNext\"]"], ["[6,4,8,2,5,7,9]", "[\"next\",\"next\",\"hasNext\",\"hasNext\"]"], ["[3,null,5,null,7]", "[\"hasNext\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[100]", "[\"next\",\"hasNext\"]"], ["[9,5,12,3,7,10,15]", "[\"next\",\"next\",\"hasNext\",\"next\"]"], ["[2,1]", "[\"hasNext\",\"next\",\"hasNext\"]"], ["[1,null,2]", "[\"next\",\"hasNext\",\"hasNext\"]"], ["[7,4,9,2,5,8,10]", "[\"next\",\"next\",\"next\",\"hasNext\",\"hasNext\"]"], ["[3,1,2]", "[\"hasNext\",\"hasNext\",\"next\"]"], ["[-5,-10,0]", "[\"next\",\"hasNext\"]"], ["[10,5,15,2,7,12,20,1,3]", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[]", "[\"hasNext\",\"hasNext\"]"]], "expected": [[3, 7, 1, 9, 1, 15, 1], [1, 1, 0], [0], [1, 1], [1, 1, 2, 1], [1, 2, 3, 1], [0, 0], [3, 1, 5, 1], [42], [1, 2], [1, 2, 1], [1, 1, 1, 3, 1], [0, 1, 2, 5, 1], [1], [-10, 1], [2, 4, 1, 1], [1, 3, 5, 7, 0], [100, 0], [3, 5, 1, 7], [1, 1, 1], [1, 1, 1], [2, 4, 5, 1, 1], [1, 1, 1], [-10, 1], [1, 2, 3, 5, 7, 1], [0, 0]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "87", "slug": "binary-search", "id": 87, "title": "Binary Search", "difficulty": "Easy", "category": "binary-search", "link": "https://leetcode.com/problems/binary-search/", "examples": [{"input": "nums = [-1,0,3,5,9,12], target = 9", "output": "4", "explanation": "Target 9 is found at index 4 in the sorted array."}, {"input": "nums = [-1,0,3,5,9,12], target = 2", "output": "-1", "explanation": "Target 2 is not present in the array."}, {"input": "nums = [5], target = 5", "output": "0", "explanation": "Target 5 is found at index 0 in the sorted array."}], "hints": ["Compare target with the middle element and discard the half that cannot contain it.", "Track an inclusive search interval with left <= right.", "Compute the midpoint as left + (right - left) / 2."], "statement": "Given an array of integers `nums` sorted in strictly increasing order and an integer `target`, return the index of `target`. Return `-1` if `target` is not present.\n\nYour algorithm should run in `O(log n)` time.\n\n**Constraints:**\n\n- `1 <= nums.length <= 10^4`\n- `-10^4 < nums[i], target < 10^4`\n- `nums` is sorted in strictly increasing order.\n\n**Portable interface:** Implement `search(nums, target)` directly. The returned index is zero-based, and no input parsing is required.\n", "solution": "## Approach\n\nKeep an inclusive interval containing every index where `target` could still appear. Compare the middle value with `target`, returning its index on equality and otherwise discarding the impossible half. If the interval becomes empty, the target is absent.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n), where `n` is the length of `nums`.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def search(self, nums: List[int], target: int) -> int:\n left, right = 0, len(nums) - 1\n while left <= right:\n middle = left + (right - left) // 2\n if nums[middle] == target:\n return middle\n if nums[middle] < target:\n left = middle + 1\n else:\n right = middle - 1\n return -1\n```\n", "starter": {"go": "package main\n\nfunc Search(nums []int, target int) int {\n return -1\n}", "python": "from typing import List\n\nclass Solution:\n def search(self, nums: List[int], target: int) -> int:\n return -1\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int search(vector<int>& nums, int target) {\n return -1;\n }\n};"}, "fn": "search", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[-1,0,3,5,9,12]", "9"], ["[-1,0,3,5,9,12]", "2"], ["[5]", "5"], ["[5]", "-5"], ["[1,2]", "1"], ["[1,2]", "2"], ["[1,2]", "0"], ["[1,2]", "3"], ["[-10,-8,-6,-4,-2]", "-10"], ["[-10,-8,-6,-4,-2]", "-2"], ["[-10,-8,-6,-4,-2]", "-5"], ["[0,2,4,6,8,10]", "0"], ["[0,2,4,6,8,10]", "10"], ["[0,2,4,6,8,10]", "5"], ["[-5,-1,0,4,11,19]", "-1"], ["[-5,-1,0,4,11,19]", "4"], ["[-5,-1,0,4,11,19]", "20"], ["[-9999,0,9999]", "-9999"], ["[-9999,0,9999]", "9999"], ["[-9999,0,9999]", "1"], ["[1,3,5,7,9,11,13,15]", "7"], ["[1,3,5,7,9,11,13,15]", "8"], ["[2,4,6,8,10,12,14]", "8"], ["[2,4,6,8,10,12,14]", "1"], ["[2,4,6,8,10,12,14]", "15"], ["[-9,-7,-3,1,6,12,20]", "-3"], ["[-9,-7,-3,1,6,12,20]", "6"], ["[-9,-7,-3,1,6,12,20]", "-8"], ["[42]", "41"], ["[-42]", "-42"], ["[-9998,-1,0,1,9998]", "-9998"], ["[-9998,-1,0,1,9998]", "9998"], ["[-9998,-1,0,1,9998]", "2"], ["[10,20,30,40,50,60,70,80,90]", "50"], ["[10,20,30,40,50,60,70,80,90]", "10"], ["[10,20,30,40,50,60,70,80,90]", "90"], ["[10,20,30,40,50,60,70,80,90]", "55"], ["[-30,-20,-10,0,10,20,30]", "0"], ["[-30,-20,-10,0,10,20,30]", "-30"], ["[-30,-20,-10,0,10,20,30]", "31"], ["[3,14,27,38,49,60,71,82,93]", "71"], ["[3,14,27,38,49,60,71,82,93]", "72"], ["[-99,-50,-25,-12,-6,-3]", "-99"], ["[-99,-50,-25,-12,-6,-3]", "-3"], ["[-99,-50,-25,-12,-6,-3]", "-4"], ["[1,10,100,1000,5000,9999]", "1000"], ["[1,10,100,1000,5000,9999]", "9998"], ["[-8,-4,-2,-1]", "-1"], ["[-8,-4,-2,-1]", "-9"], ["[-50,-40,-30,-20,-10,0,10,20,30,40,50]", "20"], ["@javascript:JSON.stringify(Array.from({length:10000},(_,i)=>-9999+i*2))", "9999"]], "expected": [4, -1, 0, -1, 0, 1, -1, -1, 0, 4, -1, 0, 5, -1, 1, 3, -1, 0, 2, -1, 3, -1, 3, -1, -1, 2, 4, -1, -1, 0, 0, 4, -1, 4, 0, 8, -1, 3, 0, -1, 6, -1, 0, 5, -1, 3, -1, 3, -1, 7, 9999], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "917", "slug": "binary-subarrays-with-sum", "id": 917, "title": "Binary Subarrays With Sum", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/binary-subarrays-with-sum/", "examples": [{"input": "nums = [1,0,1,0,1], goal = 2", "output": "4", "explanation": "Four slices contain exactly two ones."}, {"input": "nums = [0,0,0,0,0], goal = 0", "output": "15", "explanation": "All 15 slices sum to zero."}, {"input": "nums = [1,1,1,1,1], goal = 3", "output": "3"}], "hints": ["Convert the task to counting prefix sums: a subarray sums to goal when two prefixes differ by goal.", "Keep how many times each running total has appeared.", "Initialize the empty prefix count to one so slices from the start are included."], "statement": "You are given a binary array `nums` (only `0`s and `1`s) and an integer `goal`. A subarray is a consecutive slice of the array. Return how many subarrays have a sum exactly equal to `goal`.\n\n**Constraints:**\n- `1 <= nums.length <= 30000`\n- Each entry is `0` or `1`.\n- `0 <= goal <= nums.length`\n", "solution": "## Approach\n\nUse prefix sums with a frequency table. As we extend the running total, the number of earlier prefixes equal to `sum - goal` tells how many subarrays ending here hit the target. Seed the table with one empty prefix so subarrays starting at zero are counted.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `nums`. Single pass with hash lookups.\n- **Space Complexity:** O(n) for the prefix frequency table.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import defaultdict\nclass Solution:\n def numSubarraysWithSum(self, nums: List[int], goal: int) -> int:\n freq = defaultdict(int)\n freq[0] = 1\n s = 0\n ans = 0\n for v in nums:\n s += v\n ans += freq[s - goal]\n freq[s] += 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc NumSubarraysWithSum(nums []int, goal int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def numSubarraysWithSum(self, nums: List[int], goal: int) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int numSubarraysWithSum(vector<int>& nums, int goal) {\n return 0;\n }\n};"}, "fn": "numSubarraysWithSum", "params": [{"name": "nums", "type": "int_array"}, {"name": "goal", "type": "int"}], "outputType": "int", "tests": [["[1,0,1,0,1]", "2"], ["[0,0,0,0,0]", "0"], ["[1,1,1,1,1]", "3"], ["[0]", "0"], ["[1]", "1"], ["[1]", "0"], ["[0]", "1"], ["[0,1]", "1"], ["[1,0]", "1"], ["[0,1,0]", "0"], ["[1,0,0,1]", "1"], ["[1,0,1]", "1"], ["[0,0,1,0,0]", "1"], ["[1,1,0,0,1]", "2"], ["[0,0,0,1,0]", "0"], ["[1,0,0,0,1,0,1]", "2"], ["[0,1,1,0,1,0,0]", "2"], ["[1,1,1,0,1,1]", "4"], ["[0,0,0,0,0,0]", "0"], ["[1,0,1,0,1,0,1]", "2"], ["[1,1,1,1]", "0"], ["[0,1,0,1,0,1,0]", "3"], ["[1,0,0,1,1,0,1]", "3"], ["[0,0,1,1,0,0,1]", "2"], ["[1,1,0,1,0,0,1,0,1]", "3"], ["[0,0,0,0,1]", "1"], ["[1,0,0,0,0,0,1]", "1"], ["[0,1,0,0,1,0,1,1]", "2"]], "expected": [4, 15, 3, 1, 1, 0, 0, 2, 2, 2, 6, 4, 9, 4, 7, 6, 7, 2, 21, 8, 0, 4, 5, 10, 7, 5, 12, 9], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "954", "slug": "binary-tree-cameras", "id": 954, "title": "Binary Tree Cameras", "difficulty": "Hard", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-cameras/", "examples": [{"input": "root = [0,0,null,0,0]", "output": "1", "explanation": "One camera on the left child watches the root and both grandchildren, covering everything."}, {"input": "root = [0,0,null,0,null,0,null,null,0]", "output": "2", "explanation": "The long chain forces two cameras; a single device always leaves one end unwatched."}, {"input": "root = [0]", "output": "1", "explanation": "A lone node must host its own camera."}], "hints": ["Let each subtree report: 0 = needs its parent, 1 = covered, 2 = hosts a camera.", "A node with an uncovered child must take a camera; a node beside a camera is covered.", "After the walk, the root still uncovered means one extra camera on top."], "statement": "A camera placed on a tree node watches its parent, itself, and its immediate children. Find the smallest number of cameras that together watch every node of the tree described by the level-order serialization `root`. (Node values are irrelevant; only the shape matters.) An empty tree needs no cameras.\n\n**Constraints:**\n- The tree holds between 0 and 1000 nodes.\n- Node values are integers fitting in a 32-bit signed range.\n", "solution": "## Approach\n\nRoot the decisions greedily from the leaves upward. Each subtree reports one of three states: needs coverage from its parent, is already covered, or hosts a camera. A node with an uncovered child must host a camera; a node with a camera-child is covered; otherwise it asks its parent for coverage. The root gets a camera if it still needs one. Placing cameras as low as possible never harms optimality.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for n nodes in one post-order pass.\n- **Space Complexity:** O(h) recursion depth for height h.\n\n## Implementation\n\n```python\nclass Solution:\n def minCameraCover(self, root) -> int:\n ans = 0\n\n def dfs(nd):\n nonlocal ans\n if nd is None:\n return 1\n l, r = dfs(nd.left), dfs(nd.right)\n if l == 0 or r == 0:\n ans += 1\n return 2\n if l == 2 or r == 2:\n return 1\n return 0\n\n if dfs(root) == 0:\n ans += 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 MinCameraCover(root *TreeNode) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def minCameraCover(self, root) -> int:\n return 0", "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;\n\nclass Solution {\npublic:\n int minCameraCover(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "minCameraCover", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int", "tests": [["[0,0,null,0,0]"], ["[0,0,null,0,null,0,null,null,0]"], ["[0]"], ["[]"], ["[0,0,0,0,0,0,0]"], ["[0,0,null,0]"], ["[0,null,0,null,0,null,0]"], ["[0,0,0,null,null,0,0]"], ["[1,2,3,4,5,6,7]"], ["[0,0,0,0,null,null,0]"], ["[0,null,0,0]"], ["[0,0,0,0,0,null,0]"], ["[5]"], ["[1,2,null,3,4]"], ["[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]"], ["[0,0,null,null,0]"], ["[3,1,2]"], ["[0,0,0,null,0,null,0]"], ["[4,2,6,1,3,5,7]"], ["[0,null,0]"], ["[1,2,3,null,4,null,5]"], ["[0,0,0,0,0,0,0,0]"], ["[9,8,7,6,5,4,3]"], ["[0,0,null,0,0,0,0]"], ["[1,null,2,null,3,null,4]"], ["[0,0,0]"], ["[2,1,3,null,null,4]"], ["[0,0,0,0,0,0,0,0,0]"]], "expected": [1, 2, 1, 0, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 5, 1, 1, 2, 2, 1, 2, 3, 2, 2, 2, 1, 2, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "194", "slug": "binary-tree-inorder-traversal", "id": 194, "title": "Binary Tree Inorder Traversal", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-inorder-traversal/", "examples": [{"input": "root = [1,null,2,3]", "output": "[1,3,2]", "explanation": "The inorder traversal visits the left subtree, then the root, then the right subtree, giving [1,3,2]."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree has an empty traversal."}, {"input": "root = [1]", "output": "[1]", "explanation": "A single-node tree traverses to [1]."}], "hints": ["Recursively traverse left subtree, visit the root, then traverse the right subtree.", "An iterative version can use a stack: push left children, pop, record, then move right."], "statement": "Take the `root` of a binary tree and list its node values in inorder sequence: for every subtree, first enumerate everything in its left branch, then record the subtree's own root value, and finally enumerate everything in its right branch.\n\n**Constraints:**\n\n- The number of nodes in the tree is in the range `[0, 100]`.\n- `-100 <= Node.val <= 100`\n", "solution": "## Approach\n\nDo a depth-first traversal that visits the left subtree first, then the current node, then the right subtree. Collect values in a list as you visit. This can be written recursively or with an explicit stack that pushes left children before processing each node.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited once.\n- **Space Complexity:** O(h) for the recursion stack (O(n) worst case), plus O(n) for the output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def inorderTraversal(self, root) -> List[int]:\n out = []\n def dfs(node):\n if node is None:\n return\n dfs(node.left)\n out.append(node.val)\n dfs(node.right)\n dfs(root)\n return out\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 InorderTraversal(root *TreeNode) []int {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import List\nclass Solution:\n def inorderTraversal(self, root) -> List[int]:\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> inorderTraversal(TreeNode* root) {\n return {};\n }\n};"}, "fn": "inorderTraversal", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_array", "tests": [["[1,null,2,3]"], ["[]"], ["[1]"], ["[1,2,3,4,5,null,8,null,null,6,7,9]"], ["[3,1,4,null,2]"], ["[1,2,3]"], ["[1,null,2]"], ["[2,1,3]"], ["[5,3,6,2,4,null,7,1]"], ["[1,2,null,3]"], ["[1,null,2,null,3]"], ["[-100,100]"], ["[4,2,6,1,3,5,7]"], ["[1,2,3,4,5,6,7,8]"], ["[1,2]"], ["[1,null,3]"], ["[3,2,null,1]"], ["[1,null,2,null,3,null,4]"], ["[-1,-2,-3]"], ["[0]"], ["[10,5,15,3,7,12,20]"], ["[1,2,3,null,4,null,5]"], ["[2,null,3,null,4,null,5]"], ["[-100]"], ["[1,-2,-3,1,3,-2,null,-1]"], ["[5,null,4,null,3,null,2,null,1]"], ["[1,2,3,4,null,null,5]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[1,2,3,4,5,6,7]"], ["[-5,4,6]"], ["[0,-1,1]"]], "expected": [[1, 3, 2], [], [1], [4, 2, 6, 5, 7, 1, 3, 9, 8], [1, 2, 3, 4], [2, 1, 3], [1, 2], [1, 2, 3], [1, 2, 3, 4, 5, 6, 7], [3, 2, 1], [1, 2, 3], [100, -100], [1, 2, 3, 4, 5, 6, 7], [8, 4, 2, 5, 1, 6, 3, 7], [2, 1], [1, 3], [1, 2, 3], [1, 2, 3, 4], [-2, -1, -3], [0], [3, 5, 7, 10, 12, 15, 20], [2, 4, 1, 3, 5], [2, 3, 4, 5], [-100], [-1, 1, -2, 3, 1, -2, -3], [5, 4, 3, 2, 1], [4, 2, 1, 3, 5], [1, 3, 4, 6, 7, 8, 10, 13, 14], [4, 2, 5, 1, 6, 3, 7], [4, -5, 6], [-1, 0, 1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "286", "slug": "binary-tree-level-order-traversal-ii", "id": 286, "title": "Binary Tree Level Order Traversal II", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-level-order-traversal-ii/", "examples": [{"input": "root = [3,9,20,null,null,15,7]", "output": "[[15,7],[9,20],[3]]", "explanation": "Top-down rows are [[3],[9,20],[15,7]]; flipping them bottom-up gives [[15,7],[9,20],[3]]."}, {"input": "root = [1]", "output": "[[1]]", "explanation": "One row stays the same reversed."}, {"input": "root = []", "output": "[]", "explanation": "No rows to flip."}], "hints": ["Collect rows with ordinary breadth-first search first.", "Reverse the list of rows at the end (or prepend each row) to go bottom-up.", "Adaptation: the nested list maps to int_list_2d in this judge."], "statement": "List the values of a binary tree starting from the lowest level and ending at the root. Within each level keep left-to-right order.\n\nFor example, rows collected top-down as `[[3],[9,20],[15,7]]` should be returned as `[[15,7],[9,20],[3]]`.\n\n**Constraints:**\n- `0 <= number of nodes <= 2000`\n- `-1000 <= Node.val <= 1000`\n\n**Adaptation note:** The nested value list is represented as `int_list_2d` in this judge.\n", "solution": "## Approach\n\nStandard breadth-first search gathers one list per depth from top to bottom. Reversing the outer list converts that order to bottom-up while preserving left-to-right order inside each row. An empty tree short-circuits to an empty answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), each node enqueued once plus a linear reversal.\n- **Space Complexity:** O(n) for the queue and stored rows.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def levelOrderBottom(self, root) -> List[List[int]]:\n if not root:\n return []\n ans = []\n q = deque([root])\n while q:\n level = []\n for _ in range(len(q)):\n n = q.popleft()\n level.append(n.val)\n if n.left:\n q.append(n.left)\n if n.right:\n q.append(n.right)\n ans.append(level)\n ans.reverse()\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 LevelOrderBottom(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\nfrom typing import List\nclass Solution:\n def levelOrderBottom(self, root) -> List[List[int]]:\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> levelOrderBottom(TreeNode* root) {\n \n }\n};"}, "fn": "levelOrderBottom", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_list_2d", "tests": [["[3,9,20,null,null,15,7]"], ["[1]"], ["[]"], ["[1,2,3,4,5]"], ["[1,null,2,3,4]"], ["[1,2,null,3,null,4]"], ["[2,1,3]"], ["[1,2,3,4,5,6,7]"], ["[5,4,6,3,null,null,7]"], ["[10,5,15,2,7,12,20]"], ["[1,null,2,null,3,null,4]"], ["[4,2,6,1,3,5,7]"], ["[0]"], ["[-5,-10,0]"], ["[100,50,150,25,75]"], ["[1,2,3,null,4,5,6]"], ["[7,3,10,2,5,null,12]"], ["[3,9,20,15,7]"], ["[2,null,3,null,4,null,5]"], ["[6,3,9,1,4,8,10]"], ["[1,2,3,4,null,null,5]"], ["[8,3,10,1,6,null,14]"], ["[5,null,4,null,3,null,2]"], ["[1,2,3,4,5,6,7,8]"], ["[9,5,12,3,7,10,15]"], ["[15,10,20,8,12,17,25]"]], "expected": [[[15, 7], [9, 20], [3]], [[1]], [], [[4, 5], [2, 3], [1]], [[3, 4], [2], [1]], [[4], [3], [2], [1]], [[1, 3], [2]], [[4, 5, 6, 7], [2, 3], [1]], [[3, 7], [4, 6], [5]], [[2, 7, 12, 20], [5, 15], [10]], [[4], [3], [2], [1]], [[1, 3, 5, 7], [2, 6], [4]], [[0]], [[-10, 0], [-5]], [[25, 75], [50, 150], [100]], [[4, 5, 6], [2, 3], [1]], [[2, 5, 12], [3, 10], [7]], [[15, 7], [9, 20], [3]], [[5], [4], [3], [2]], [[1, 4, 8, 10], [3, 9], [6]], [[4, 5], [2, 3], [1]], [[1, 6, 14], [3, 10], [8]], [[2], [3], [4], [5]], [[8], [4, 5, 6, 7], [2, 3], [1]], [[3, 7, 10, 15], [5, 12], [9]], [[8, 12, 17, 25], [10, 20], [15]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "64", "slug": "binary-tree-level-order-traversal", "id": 64, "title": "Binary Tree Level Order Traversal", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-level-order-traversal/", "examples": [{"input": "root = [3,9,20,null,null,15,7]", "output": "[[3],[9,20],[15,7]]", "explanation": "The level-order traversal groups are [[3],[9,20],[15,7]]."}, {"input": "root = [1]", "output": "[[1]]", "explanation": "The level-order traversal groups are [[1]]."}, {"input": "root = []", "output": "[]", "explanation": "The level-order traversal groups are []."}], "hints": ["Perform a breadth-first search (BFS), collecting node values level by level."], "statement": "Starting from the `root` of a binary tree, collect the node values one horizontal layer at a time: the root layer first, then its children left to right, then the next depth left to right, and so on. Return those layers as nested lists.\n\n**Constraints:**\n\n- The number of nodes in the tree is in the range [0, 2000].\n- -1000 \u2264 Node.val \u2264 1000\n", "solution": "## Approach\n\nBFS using a queue, processing one level at a time by iterating over the current queue size.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import List, Optional\nfrom collections import deque\nclass Solution:\n def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:\n if not root:\n return []\n res = []\n q = deque([root])\n while q:\n level = []\n for _ in range(len(q)):\n node = q.popleft()\n level.append(node.val)\n if node.left:\n q.append(node.left)\n if node.right:\n q.append(node.right)\n res.append(level)\n return res\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 LevelOrder(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\nfrom typing import List\nclass Solution:\n def levelOrder(self, root) -> List[List[int]]:\n # TODO: return level order traversal values\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> levelOrder(TreeNode* root) {\n \n }\n};\n"}, "fn": "levelOrder", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_list_2d", "tests": [["[3,9,20,null,null,15,7]"], ["[1]"], ["[]"], ["[1,2,3,4,5]"], ["[1,null,2,3,4]"], ["[5,3,8,1,4,7,9]"], ["[1,null,2,3]"], ["[1,2,3]"], ["[1,null,2]"], ["[2,1,3]"], ["[1,2]"], ["[1,null,3]"], ["[3,2,null,1]"], ["[1,null,2,null,3,null,4]"], ["[-1,-2,-3]"], ["[0]"], ["[10,5,15,3,7,12,20]"], ["[1,2,3,null,4,null,5]"], ["[2,null,3,null,4,null,5]"], ["[-100]"], ["[1,-2,-3,1,3,-2,null,-1]"], ["[5,null,4,null,3,null,2,null,1]"], ["[1,2,3,4,null,null,5]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[1,2,3,4,5,6,7]"], ["[-5,4,6]"], ["[0,-1,1]"], ["[4,2,6,1,3,5,7]"], ["[1,2,null,3]"], ["[1,null,2,null,3]"], ["[-100,100]"]], "expected": [[[3], [9, 20], [15, 7]], [[1]], [], [[1], [2, 3], [4, 5]], [[1], [2], [3, 4]], [[5], [3, 8], [1, 4, 7, 9]], [[1], [2], [3]], [[1], [2, 3]], [[1], [2]], [[2], [1, 3]], [[1], [2]], [[1], [3]], [[3], [2], [1]], [[1], [2], [3], [4]], [[-1], [-2, -3]], [[0]], [[10], [5, 15], [3, 7, 12, 20]], [[1], [2, 3], [4, 5]], [[2], [3], [4], [5]], [[-100]], [[1], [-2, -3], [1, 3, -2], [-1]], [[5], [4], [3], [2], [1]], [[1], [2, 3], [4, 5]], [[8], [3, 10], [1, 6, 14], [4, 7, 13]], [[1], [2, 3], [4, 5, 6, 7]], [[-5], [4, 6]], [[0], [-1, 1]], [[4], [2, 6], [1, 3, 5, 7]], [[1], [2], [3]], [[1], [2], [3]], [[-100], [100]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "606", "slug": "binary-tree-longest-consecutive-sequence-ii", "id": 606, "title": "Binary Tree Longest Consecutive Sequence II", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-longest-consecutive-sequence-ii/", "examples": [{"input": "root = [1,2,3]", "output": "2", "explanation": "Best pair is 1-2."}, {"input": "root = [2,1,3]", "output": "3", "explanation": "Path 1-2-3 through the root."}, {"input": "root = [1]", "output": "1"}], "hints": ["For each node return the longest increasing run and longest decreasing run starting there.", "A child extends the increasing run when child value equals parent + 1, and the decreasing run when it equals parent - 1.", "A trail through a node can join one increasing and one decreasing arm, giving inc + dec - 1."], "statement": "You are given the root of a binary tree. A consecutive trail is a sequence of nodes where each neighbouring pair differs by exactly one. The trail may climb upward and then descend (child-parent-child), and it may run either increasingly or decreasingly.\n\nFind the number of nodes in the longest such trail anywhere in the tree. A lone node counts as length one.\n\n**Constraints:**\n- `1 <= number of nodes <= 3 * 10^4`\n- `-3 * 10^4 <= Node.val <= 3 * 10^4`\n", "solution": "## Approach\n\nPost-order DFS returns two numbers per node: the longest increasing consecutive chain and the longest decreasing chain beginning at that node. Each child can extend one of them when its value is exactly one more or one less. The best trail passing through the node joins both arms minus the double-counted node.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(h) recursion depth.\n\n## Implementation\n\n```python\nclass Solution:\n def longestConsecutive(self, root) -> int:\n self.best = 0\n def dfs(node):\n if not node:\n return (0, 0)\n inc = dec = 1\n if node.left:\n li, ld = dfs(node.left)\n if node.left.val == node.val + 1:\n inc = max(inc, li + 1)\n if node.left.val == node.val - 1:\n dec = max(dec, ld + 1)\n if node.right:\n ri, rd = dfs(node.right)\n if node.right.val == node.val + 1:\n inc = max(inc, ri + 1)\n if node.right.val == node.val - 1:\n dec = max(dec, rd + 1)\n self.best = max(self.best, inc + dec - 1)\n return (inc, dec)\n dfs(root)\n return self.best\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 LongestConsecutive(root *TreeNode) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def longestConsecutive(self, root) -> int:\n pass\n", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n int longestConsecutive(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "longestConsecutive", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int", "tests": [["[1,2,3]"], ["[2,1,3]"], ["[1]"], ["[1,2]"], ["[2,1]"], ["[3,2,1]"], ["[1,2,3,4]"], ["[4,3,2,1]"], ["[1,3,2]"], ["[2,3,1]"], ["[1,2,null,3]"], ["[3,2,null,1]"], ["[1,null,2,null,3]"], ["[3,null,2,null,1]"], ["[2,null,3,null,4,null,5]"], ["[5,4,null,3,null,2]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[10,5,15,3,7,null,18]"], ["[1,2,3,null,4,null,5]"], ["[2,1,3,null,null,null,4]"], ["[4,2,5,1,3]"], ["[1,2,4,3]"], ["[0,-1,1]"], ["[1,0,2,-1,null,3]"], ["[3,1,4,0,2]"], ["[2,1,3,0,null,null,4]"], ["[1,2,3,4,null,null,5]"]], "expected": [2, 3, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 2, 2, 1, 2, 4, 3, 3, 3, 5, 3, 5, 2], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "392", "slug": "binary-tree-longest-consecutive-sequence", "id": 392, "title": "Binary Tree Longest Consecutive Sequence", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/", "examples": [{"input": "root = [1,null,3,2,4,null,null,null,5]", "output": "3", "explanation": "The downward path 3 -> 4 -> 5 is the longest consecutive run."}, {"input": "root = [2,null,3,2,null,1]", "output": "2", "explanation": "Both 2 -> 3 and 1 -> 2 reach length 2."}, {"input": "root = []", "output": "0", "explanation": "An empty tree has no path."}], "hints": ["Carry the current run length down the recursion: extend it when the child equals parent + 1, else restart at 1.", "A path may start at any node, so track the best run seen anywhere, not just runs through the root.", "Only parent-to-child direction counts; a run cannot turn around at a node."], "statement": "Given the root of a binary tree (serialised level by level, with `null` for missing\nchildren), find the length, in nodes, of the longest downward path whose values rise by\nexactly 1 at every step. The path must follow parent-to-child links. An empty tree scores 0.\n\n**Constraints:**\n- The tree holds between 0 and 2000 nodes.\n- `-10^9 <= node values <= 10^9`.\n", "solution": "## Approach\n\nOne DFS pass carries the length of the consecutive run ending at each node (extended when child == parent + 1, else restarted) and records the global maximum.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(h)\n\n## Implementation\n\n```python\n# 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\nclass Solution:\n def longestConsecutive(self, root) -> int:\n self.best = 0\n def dfs(node, parent_val, length):\n if not node:\n return\n cur = length + 1 if parent_val is not None and node.val == parent_val + 1 else 1\n self.best = max(self.best, cur)\n dfs(node.left, node.val, cur)\n dfs(node.right, node.val, cur)\n dfs(root, None, 0)\n return self.best\n```\n", "starter": {"go": "package main\n\nfunc LongestConsecutive(root *TreeNode) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def longestConsecutive(self, root) -> int:\n pass\n", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n};\n*/\nclass Solution {\npublic:\n int longestConsecutive(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "longestConsecutive", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int", "tests": [["[1,null,3,2,4,null,null,null,5]"], ["[2,null,3,2,null,1]"], ["[]"], ["[1]"], ["[1,2]"], ["[2,1]"], ["[1,2,3]"], ["[1,null,2,null,3]"], ["[3,2,null,1]"], ["[1,2,null,3]"], ["[5,4,null,3,null,2]"], ["[1,3,2,4,null,null,5]"], ["[1,2,3,4,5,6,7]"], ["[7,6,5,4,3,2,1]"], ["[1,null,2,null,3,null,4,null,5]"], ["[5,null,4,null,3,null,2,null,1]"], ["[1,2,null,3,null,4,null,5]"], ["[10,5,15,3,7,null,18]"], ["[1,2,3,null,4,null,5]"], ["[4,3,null,2,null,1]"], ["[-1,0,null,1]"], ["[0,-1,1,null,null,-2,2]"], ["[1,1,1,1,1]"], ["[1,2,null,2,null,3,null,4]"], ["[9,null,10,null,11,10]"], ["[3,1,4,null,2,null,5]"], ["[2,2,2,null,null,2]"], ["[100,null,101,null,102,103]"]], "expected": [3, 2, 0, 1, 2, 1, 2, 3, 1, 3, 1, 2, 2, 1, 5, 1, 5, 1, 2, 1, 3, 3, 1, 3, 3, 3, 1, 4], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "63", "slug": "binary-tree-maximum-path-sum", "id": 63, "title": "Binary Tree Maximum Path Sum", "difficulty": "Hard", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-maximum-path-sum/", "examples": [{"input": "root = [1,2,3]", "output": "6", "explanation": "The path 2 \u2192 1 \u2192 3 has sum 2 + 1 + 3 = 6."}, {"input": "root = [-10,9,20,null,null,15,7]", "output": "42", "explanation": "The path 15 \u2192 20 \u2192 7 has sum 15 + 20 + 7 = 42."}, {"input": "root = [2,-1]", "output": "2", "explanation": "Including the child (-1) would give a path sum of 1, so the best path is the root node alone with sum 2."}], "hints": ["Use DFS to compute the maximum gain from each node and track the best split path passing through each node."], "statement": "Starting from the `root` of a binary tree, examine every route that links a non-empty chain of nodes through parent-child edges. Score each route by totalling the values of the nodes it passes through, and return the highest such score.\n\n**Constraints:**\n\n- The number of nodes in the tree is in the range [1, 3 * 10^4].\n- -1000 \u2264 Node.val \u2264 1000\n", "solution": "## Approach\n\nDFS post-order traversal where each node returns the max gain of a path ending at that node, while tracking the best path sum that goes through any node.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(h) where h is tree height\n\n## Implementation\n\n```python\nfrom typing import Optional\nclass Solution:\n def maxPathSum(self, root: Optional[TreeNode]) -> int:\n res = float('-inf')\n def dfs(node):\n nonlocal res\n if not node:\n return 0\n left = max(dfs(node.left), 0)\n right = max(dfs(node.right), 0)\n res = max(res, left + right + node.val)\n return node.val + max(left, right)\n dfs(root)\n return res\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 MaxPathSum(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 maxPathSum(self, root) -> int:\n # TODO: return the maximum path sum\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 maxPathSum(TreeNode* root) {\n \n }\n};\n"}, "fn": "maxPathSum", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int", "tests": [["[1,2,3]"], ["[-10,9,20,null,null,15,7]"], ["[2,-1]"], ["[-3]"], ["[1,-2,3]"], ["[9,6,-3,null,null,-6,2,null,null,2,null,-6,-6,-6]"], ["[5]"], ["[-5]"], ["[1,2]"], ["[1,null,3]"], ["[-1,-2,-3]"], ["[-2,1]"], ["[5,4,11,7,2,null,null,null,1]"], ["[1,-2,-3,1,3,-2,null,-1]"], ["[-3,9,-20,null,null,15,7]"], ["[2,-1,-2]"], ["[10,5,15,3,7,12,20]"], ["[1,2,3,4,5]"], ["[0]"], ["[0,-1,1]"], ["[-100,100]"], ["[100,-50,-60]"], ["[-1,1,1]"], ["[5,-1,6]"], ["[3,2,null,1]"], ["[1,null,2,null,3,null,4]"], ["[4,2,6,1,3,5,7]"], ["[1,2,3,null,4,null,5]"], ["[2,null,3,null,4,null,5]"], ["[5,4,null,3,null,2,null,1]"], ["[1000,-1000,1000]"]], "expected": [6, 42, 2, -3, 4, 16, 5, -5, 3, 4, -1, 1, 28, 3, 15, 2, 57, 11, 0, 1, 100, 100, 1, 11, 6, 10, 22, 15, 14, 15, 2000], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "361", "slug": "binary-tree-paths", "id": 361, "title": "Binary Tree Paths", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-paths/", "examples": [{"input": "root = [1,2,3,null,5]", "output": "[\"1->2->5\",\"1->3\"]", "explanation": "The two leaves are 5 and 3, reached by 1 -> 2 -> 5 and 1 -> 3."}, {"input": "root = [1]", "output": "[\"1\"]", "explanation": "The root is itself a leaf, so the only path is \"1\"."}, {"input": "root = [1,2,null,3,null,4]", "output": "[\"1->2->3->4\"]", "explanation": "The single chain from the root to the deepest leaf forms one path."}], "hints": ["Walk depth-first, carrying the path string built so far.", "When a leaf is reached, store the accumulated path; otherwise extend it with the child value and keep going."], "statement": "Given the root of a binary tree, list every path from the root down to a leaf. A leaf is a node with no children. Each path is written as node values joined by `\"->\"`, for example `\"1->2->5\"`.\n\nReturn all such paths in any order.\n\n**Constraints:**\n- `1 <= number of nodes <= 100`\n- `-100 <= Node.val <= 100`\n", "solution": "## Approach\n\nDo a depth-first walk carrying the path string built from the root to the current node. When a leaf is reached, store a copy of the accumulated path. Otherwise extend the path with `\"->\"` plus the child value and recurse into each existing child, backtracking afterward so sibling branches start from the right prefix.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * h), where n is the number of nodes and h is the tree height, for building each root-to-leaf string.\n- **Space Complexity:** O(h) recursion depth plus the output.\n\n## Implementation\n\n```python\nclass Solution:\n def binaryTreePaths(self, root) -> list[str]:\n res: list[str] = []\n def dfs(node, path: str) -> None:\n if node is None:\n return\n cur = f\"{path}->{node.val}\" if path else str(node.val)\n if node.left is None and node.right is None:\n res.append(cur)\n else:\n dfs(node.left, cur)\n dfs(node.right, cur)\n dfs(root, \"\")\n return res\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc BinaryTreePaths(root *TreeNode) []string {\n return []string{}\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import List\n\nclass Solution:\n def binaryTreePaths(self, root) -> List[str]:\n return []\n", "cpp": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}\n * };\n */\n#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> binaryTreePaths(TreeNode* root) {\n return {};\n }\n};"}, "fn": "binaryTreePaths", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "string_list", "tests": [["[1,2,3,null,5]"], ["[1]"], ["[1,2,null,3,null,4]"], ["[3,1,4,null,2]"], ["[1,2,3,4,5,6,7]"], ["[1,null,2,null,3]"], ["[5,4,8,11,null,13,4,7,2,null,null,5,1]"], ["[0]"], ["[1,2]"], ["[1,null,3]"], ["[-1,-2,-3]"], ["[10,5,15,3,7,12,20]"], ["[1,2,3,null,null,4,5]"], ["[100,50,150,25,75,125,175]"], ["[1,2,2,3,3,null,null,4,4]"], ["[2,1,3]"], ["[7,3,9,1,5,null,12]"], ["[1,2,null,3,null,4,null,5]"], ["[0,-10,10,-5,5]"], ["[4,2,6,1,3,5,7]"], ["[1,2,3,4,null,null,5]"], ["[9,8,7,6,5]"], ["[5,null,4,null,3,null,2]"], ["[2,null,3,null,4,null,5,null,6]"], ["[11,7,15,3,9,13,20]"], ["[1,2,3,4,5,null,6]"]], "expected": [["1->2->5", "1->3"], ["1"], ["1->2->3->4"], ["3->1->2", "3->4"], ["1->2->4", "1->2->5", "1->3->6", "1->3->7"], ["1->2->3"], ["5->4->11->7", "5->4->11->2", "5->8->13", "5->8->4->5", "5->8->4->1"], ["0"], ["1->2"], ["1->3"], ["-1->-2", "-1->-3"], ["10->5->3", "10->5->7", "10->15->12", "10->15->20"], ["1->2", "1->3->4", "1->3->5"], ["100->50->25", "100->50->75", "100->150->125", "100->150->175"], ["1->2->3->4", "1->2->3->4", "1->2->3", "1->2"], ["2->1", "2->3"], ["7->3->1", "7->3->5", "7->9->12"], ["1->2->3->4->5"], ["0->-10->-5", "0->-10->5", "0->10"], ["4->2->1", "4->2->3", "4->6->5", "4->6->7"], ["1->2->4", "1->3->5"], ["9->8->6", "9->8->5", "9->7"], ["5->4->3->2"], ["2->3->4->5->6"], ["11->7->3", "11->7->9", "11->15->13", "11->15->20"], ["1->2->4", "1->2->5", "1->3->6"]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "196", "slug": "binary-tree-postorder-traversal", "id": 196, "title": "Binary Tree Postorder Traversal", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-postorder-traversal/", "examples": [{"input": "root = [1,null,2,3]", "output": "[3,2,1]", "explanation": "Postorder visits left, right, then root."}, {"input": "root = []", "output": "[]"}, {"input": "root = [1]", "output": "[1]"}], "hints": ["Recursively traverse left, then right, then visit the root."], "statement": "Take the `root` of a binary tree and list its node values in postorder sequence: for every subtree, first enumerate its entire left branch, then its entire right branch, and only afterwards record the subtree's own root value.\n\n**Constraints:**\n- The number of nodes in the tree is in the range `[0, 100]`\n- `-100 <= Node.val <= 100`\n", "solution": "## Approach\n\nRecursively visit the left subtree, then the right subtree, then the root.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(h) recursion stack\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def postorderTraversal(self, root) -> List[int]:\n res = []\n def go(node):\n if not node:\n return\n go(node.left)\n go(node.right)\n res.append(node.val)\n go(root)\n return res\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 PostorderTraversal(root *TreeNode) []int {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import List\nclass Solution:\n def postorderTraversal(self, root) -> List[int]:\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> postorderTraversal(TreeNode* root) {\n return {};\n }\n};"}, "fn": "postorderTraversal", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_array", "tests": [["[1,null,2,3]"], ["[]"], ["[1]"], ["[1,2,3,4,5,null,8,null,null,6,7,9]"], ["[3,1,4,null,2]"], ["[1,2]"], ["[1,null,2]"], ["[5,3,6,2,4,null,null,1]"], ["[2,1,3]"], ["[1,2,3,4,5,6,7]"], ["[1,2,3]"], ["[1,null,3]"], ["[3,2,null,1]"], ["[1,null,2,null,3,null,4]"], ["[-1,-2,-3]"], ["[0]"], ["[10,5,15,3,7,12,20]"], ["[1,2,3,null,4,null,5]"], ["[2,null,3,null,4,null,5]"], ["[-100]"], ["[1,-2,-3,1,3,-2,null,-1]"], ["[5,null,4,null,3,null,2,null,1]"], ["[1,2,3,4,null,null,5]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[-5,4,6]"], ["[0,-1,1]"], ["[4,2,6,1,3,5,7]"], ["[1,2,null,3]"], ["[1,null,2,null,3]"], ["[-100,100]"], ["[5,3,6,2,4,null,7,1]"]], "expected": [[3, 2, 1], [], [1], [4, 6, 7, 5, 2, 9, 8, 3, 1], [2, 1, 4, 3], [2, 1], [2, 1], [1, 2, 4, 3, 6, 5], [1, 3, 2], [4, 5, 2, 6, 7, 3, 1], [2, 3, 1], [3, 1], [1, 2, 3], [4, 3, 2, 1], [-2, -3, -1], [0], [3, 7, 5, 12, 20, 15, 10], [4, 2, 5, 3, 1], [5, 4, 3, 2], [-100], [-1, 1, 3, -2, -2, -3, 1], [1, 2, 3, 4, 5], [4, 2, 5, 3, 1], [1, 4, 7, 6, 3, 13, 14, 10, 8], [4, 6, -5], [-1, 1, 0], [1, 3, 2, 5, 7, 6, 4], [3, 2, 1], [3, 2, 1], [100, -100], [1, 2, 4, 3, 7, 6, 5]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "195", "slug": "binary-tree-preorder-traversal", "id": 195, "title": "Binary Tree Preorder Traversal", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-preorder-traversal/", "examples": [{"input": "root = [1,null,2,3]", "output": "[1,2,3]", "explanation": "The preorder traversal visits the root, then the left subtree, then the right subtree, giving [1,2,3]."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree has an empty traversal."}, {"input": "root = [1]", "output": "[1]", "explanation": "A single-node tree traverses to [1]."}], "hints": ["Recursively visit the root, then traverse the left subtree, then the right subtree.", "An iterative version can use a stack: push the root, pop, record, then push right before left."], "statement": "Take the `root` of a binary tree and list its node values in preorder sequence: for every subtree, record the subtree's own root value first, then enumerate everything in its left branch, and finally enumerate everything in its right branch.\n\n**Constraints:**\n\n- The number of nodes in the tree is in the range `[0, 100]`.\n- `-100 <= Node.val <= 100`\n", "solution": "## Approach\n\nDo a depth-first traversal that visits the current node first, then the left subtree, then the right subtree. Collect values in a list as you visit. This can be written recursively or with an explicit stack that processes the root before pushing right then left children.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited once.\n- **Space Complexity:** O(h) for the recursion stack (O(n) worst case), plus O(n) for the output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def preorderTraversal(self, root) -> List[int]:\n out = []\n def dfs(node):\n if node is None:\n return\n out.append(node.val)\n dfs(node.left)\n dfs(node.right)\n dfs(root)\n return out\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 PreorderTraversal(root *TreeNode) []int {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nfrom typing import List\nclass Solution:\n def preorderTraversal(self, root) -> List[int]:\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> preorderTraversal(TreeNode* root) {\n return {};\n }\n};"}, "fn": "preorderTraversal", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_array", "tests": [["[1,null,2,3]"], ["[]"], ["[1]"], ["[1,2,3,4,5,null,8,null,null,6,7,9]"], ["[3,1,4,null,2]"], ["[1,2,3]"], ["[1,null,2]"], ["[2,1,3]"], ["[5,3,6,2,4,null,7,1]"], ["[1,2,null,3]"], ["[1,null,2,null,3]"], ["[-100,100]"], ["[4,2,6,1,3,5,7]"], ["[1,2,3,4,5,6,7,8]"], ["[1,2]"], ["[1,null,3]"], ["[3,2,null,1]"], ["[1,null,2,null,3,null,4]"], ["[-1,-2,-3]"], ["[0]"], ["[10,5,15,3,7,12,20]"], ["[1,2,3,null,4,null,5]"], ["[2,null,3,null,4,null,5]"], ["[-100]"], ["[1,-2,-3,1,3,-2,null,-1]"], ["[5,null,4,null,3,null,2,null,1]"], ["[1,2,3,4,null,null,5]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[1,2,3,4,5,6,7]"], ["[-5,4,6]"], ["[0,-1,1]"]], "expected": [[1, 2, 3], [], [1], [1, 2, 4, 5, 6, 7, 3, 8, 9], [3, 1, 2, 4], [1, 2, 3], [1, 2], [2, 1, 3], [5, 3, 2, 1, 4, 6, 7], [1, 2, 3], [1, 2, 3], [-100, 100], [4, 2, 1, 3, 6, 5, 7], [1, 2, 4, 8, 5, 3, 6, 7], [1, 2], [1, 3], [3, 2, 1], [1, 2, 3, 4], [-1, -2, -3], [0], [10, 5, 3, 7, 15, 12, 20], [1, 2, 4, 3, 5], [2, 3, 4, 5], [-100], [1, -2, 1, -1, 3, -3, -2], [5, 4, 3, 2, 1], [1, 2, 4, 3, 5], [8, 3, 1, 6, 4, 7, 10, 14, 13], [1, 2, 4, 5, 3, 6, 7], [-5, 4, 6], [0, -1, 1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "812", "slug": "binary-tree-pruning", "id": 812, "title": "Binary Tree Pruning", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-pruning/", "examples": [{"input": "root = [1,null,0,0,1]", "output": "[1,null,0,null,1]", "explanation": "The left-zero leaf with no 1 below it is removed, while the right branch survives because it holds a 1."}, {"input": "root = [1,0,1,0,0,0,1]", "output": "[1,null,1,null,1]", "explanation": "Zero-only subtrees on the left vanish; branches containing a 1 are kept."}, {"input": "root = [0,0,0]", "output": "[]", "explanation": "No 1 appears anywhere, so the whole tree is pruned away."}], "hints": ["Work bottom-up: prune the children before deciding about the current node.", "A subtree survives exactly when it contains at least one 1; otherwise return null."], "statement": "You are given the root of a binary tree whose nodes hold only `0` or `1`. Remove every subtree that contains no `1` anywhere inside it.\n\nConcretely, process the tree from the leaves upward: if a node's entire subtree (itself plus all descendants) holds only zeros, delete that subtree. A node with value `1` always survives, and a zero node survives only when at least one descendant kept for the same reason exists.\n\nReturn the root of the trimmed tree, or null when nothing remains.\n\n**Constraints:**\n- The tree has at most 200 nodes.\n- Each node value is `0` or `1`.\n", "solution": "## Approach\n\nRecurse post-order: first prune the left and right children, then look at the current node. If it stores 0 and both pruned children are null, the whole subtree is zero-only and the node is dropped by returning null. Otherwise the (possibly updated) node is returned. This keeps exactly the subtrees that contain a 1.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for n nodes, each visited once.\n- **Space Complexity:** O(h) recursion depth for height h.\n\n## Implementation\n\n```python\nclass Solution:\n def pruneTree(self, root):\n if root is None:\n return None\n root.left = self.pruneTree(root.left)\n root.right = self.pruneTree(root.right)\n if root.val == 0 and root.left is None and root.right is None:\n return None\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 PruneTree(root *TreeNode) *TreeNode {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def pruneTree(self, root):\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 TreeNode* pruneTree(TreeNode* root) {\n return nullptr;\n }\n};"}, "fn": "pruneTree", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "tree_node", "tests": [["[1,null,0,0,1]"], ["[1,0,1,0,0,0,1]"], ["[0,0,0]"], ["[1]"], ["[0]"], ["[1,1,1]"], ["[0,1,0]"], ["[1,0,0]"], ["[0,0,1]"], ["[1,0,1,null,null,0,1]"], ["[0,null,0,null,0,null,1]"], ["[1,0,null,0,null,0,null,1]"], ["[0,1,1,null,null,null,0]"], ["[1,1,0,0,null,null,1]"], ["[0]"], ["[1,null,1]"], ["[0,0,null,0]"], ["[1,0,0,0,1]"], ["[0,1,0,1,0]"], ["[1,1,1,0,0,0,0]"], ["[0,0,1,0,0]"], ["[1,null,0,1,0]"], ["[0,1,null,0,1]"], ["[1,0,1,1,0]"], ["[0,0,0,0,1]"], ["[1,1,0,null,null,0,1]"], ["[0,1,0,null,1,null,0]"], ["[1,0,null,1,0,0,1]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "99", "slug": "binary-tree-right-side-view", "id": 99, "title": "Binary Tree Right Side View", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-right-side-view/", "examples": [{"input": "root = [1,2,3,null,5,null,4]", "output": "[1,3,4]", "explanation": "From the right side, you see the root (1), then the rightmost node at level 2 (3), then the rightmost node at level 3 (4)."}, {"input": "root = [1,2,3,4,null,null,null,5]", "output": "[1,3,4,5]", "explanation": "From the right side, you see the root (1), then 3 at level 2, then 4 at level 3, then 5 at level 4."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree has no visible nodes."}], "hints": ["A breadth-first traversal exposes all nodes one level at a time; record the final node processed on each level.", "Alternatively, traverse right children before left children and record the first node reached at each depth.", "A left child can still be visible when no node farther right exists at that depth."], "statement": "Consider the binary tree whose entry point is `root`, observed from a vantage point far to its east.\nList, from the highest row to the lowest row, the value that can still be seen on each row.\n\nFor every row, exactly one value is recorded: the easternmost occupied slot of that row.\nThat slot need not lie on the all-rightward path; a left descendant is recorded whenever nothing stands to its east on the same row.\n\n**Constraints:**\n\n- The tree contains between `0` and `100` nodes.\n- `-100 <= node.val <= 100`\n", "solution": "## Approach\n\nTraverse the tree one level at a time. Visit right children before left children, so the first node removed at each level is the one visible from the right side. Record that first value and enqueue the next level.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(w), where `w` is the maximum tree width, excluding the output.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\nclass Solution:\n def rightSideView(self, root) -> List[int]:\n if root is None:\n return []\n\n queue = deque([root])\n visible = []\n while queue:\n for index in range(len(queue)):\n node = queue.popleft()\n if index == 0:\n visible.append(node.val)\n if node.right is not None:\n queue.append(node.right)\n if node.left is not None:\n queue.append(node.left)\n return visible\n```\n", "starter": {"go": "package main\n\nfunc RightSideView(root *TreeNode) []int {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nfrom typing import List\n\nclass Solution:\n def rightSideView(self, root) -> List[int]:\n pass\n", "cpp": "/*\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n};\n*/\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> rightSideView(TreeNode* root) {\n return {};\n }\n};"}, "fn": "rightSideView", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_array", "tests": [["[]"], ["[1]"], ["[1,2]"], ["[1,null,2]"], ["[1,2,3]"], ["[1,2,3,null,5,null,4]"], ["[1,2,3,4,null,null,null,5]"], ["[1,2,null,3]"], ["[1,null,2,3]"], ["[1,2,null,null,3]"], ["[1,null,2,null,3]"], ["[1,2,null,3,null,4,null,5]"], ["[1,null,2,null,3,null,4,null,5]"], ["[1,2,null,null,3,4,null,null,5]"], ["[1,null,2,3,null,null,4,5]"], ["[1,2,3,4,5,6,7]"], ["[0,0,0,0,0,0,0]"], ["[-1,-2,-3,-4,-5,-6,-7]"], ["[1,2,3,4,5,null,null,6,7]"], ["[1,2,3,null,null,4,5,null,null,6,7]"], ["[1,2,3,4,null,null,5,6,null,null,7]"], ["[1,2,3,4,null,5,null,6,null,7]"], ["[1,2,3,null,4,null,5,6,null,null,7]"], ["[5,4,6,3,null,null,7,2,null,null,8,1,null,null,9]"], ["[5,4,6,null,3,7,null,null,2,null,8,null,1,9]"], ["[10,5,15,3,7,12,18,1,4,6,8,11,13,17,20]"], ["[10,5,15,3,7,null,18,1,null,6,8,17,20]"], ["[10,5,15,null,7,12,null,6,8,11,13]"], ["[1,2,3,4,5,6,7,8]"], ["[1,2,3,4,5,6,7,null,null,null,null,null,null,null,8]"], ["[1,2,3,4,null,null,5,6,null,null,7,8,null,null,9]"], ["[1,2,3,null,4,5,null,null,6,7,null,null,8]"], ["[1,2,3,4,5,null,6,null,7,8,null,null,9]"], ["[2,2,2,2,null,null,2,2,null,null,2]"], ["[100,-100,99,-99,null,null,98,-98,null,null,97]"], ["[8,4,12,2,6,10,14,1,3,5,7,9,11,13,15]"], ["[8,4,12,2,6,10,14,1,null,null,7,9,null,null,15]"], ["[8,4,12,null,6,10,null,5,7,9,11]"], ["[3,1,4,null,2,null,5,null,null,null,6]"], ["[3,1,5,null,2,4,6,null,null,null,null,null,7]"], ["[0,-1,1,-2,null,null,2,-3,null,null,3,-4,null,null,4]"], ["[0,-1,1,null,-2,2,null,null,-3,null,3,null,-4,4]"], ["[1,2,3,4,null,null,5,6,7,8,9]"], ["[1,2,3,null,4,5,null,6,7,8,9]"], ["[1,2,3,4,5,null,null,6,null,null,7,8,null,null,9]"], ["[50,25,75,12,37,62,87,6,18,31,43,56,68,81,93]"], ["[50,25,75,12,null,62,87,6,18,56,68,null,93]"], ["[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]"], ["[1,2,3,4,5,6,7,8,null,null,11,12,null,null,15]"], ["[9,8,7,6,null,null,5,4,null,null,3,2,null,null,1]"], ["[1,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9,null,10]"], ["[1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9,null,10]"], ["[1,2,null,null,3,4,null,null,5,6,null,null,7,8,null,null,9]"], ["[1,null,2,3,null,null,4,5,null,null,6,7,null,null,8,9]"], ["[4,2,6,1,3,5,7,null,null,null,null,null,null,null,8,null,9]"], ["@javascript:JSON.stringify(Array.from({length:99},(_,i)=>100-(i%201)))"], ["@javascript:JSON.stringify(Array.from({length:100},(_,i)=>(i%201)-100))"]], "expected": [[], [1], [1, 2], [1, 2], [1, 3], [1, 3, 4], [1, 3, 4, 5], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 3, 7], [0, 0, 0], [-1, -3, -7], [1, 3, 5, 7], [1, 3, 5, 7], [1, 3, 5, 7], [1, 3, 5, 7], [1, 3, 5, 7], [5, 6, 7, 8, 9], [5, 6, 7, 8, 9], [10, 15, 18, 20], [10, 15, 18, 20], [10, 15, 12, 13], [1, 3, 7, 8], [1, 3, 7, 8], [1, 3, 5, 7, 9], [1, 3, 5, 7, 8], [1, 3, 6, 9], [2, 2, 2, 2], [100, 99, 98, 97], [8, 12, 14, 15], [8, 12, 14, 15], [8, 12, 10, 11], [3, 4, 5, 6], [3, 5, 6, 7], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [1, 3, 5, 9], [1, 3, 5, 9], [1, 3, 5, 7, 9], [50, 75, 87, 93], [50, 75, 87, 93], [1, 3, 7, 15], [1, 3, 7, 15], [9, 7, 5, 3, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 6, 7, 8, 9], [100, 98, 94, 86, 70, 38, 2], [-100, -98, -94, -86, -70, -38, -1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "618", "slug": "binary-tree-tilt", "id": 618, "title": "Binary Tree Tilt", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-tilt/", "examples": [{"input": "root = [1,2,3]", "output": "1", "explanation": "Leaves tilt 0; the root contributes |2 - 3|."}, {"input": "root = [4,2,9,3,5,null,7]", "output": "15", "explanation": "Node tilts 2, 7, and 6 sum to 15."}, {"input": "root = []", "output": "0", "explanation": "An empty tree has tilt 0."}], "hints": ["A post-order walk returns each subtree's total while accumulating tilts on the side.", "At every node add |leftSum - rightSum| to a running answer, then return val + leftSum + rightSum.", "Leaves need no special case: both sums are 0 so their tilt is 0."], "statement": "Given the root of a binary tree, compute its total tilt. The tilt of a single node is the absolute difference between the sum of all values in its left subtree and the sum of all values in its right subtree. The tilt of the whole tree is the sum of every node's tilt.\n\nEmpty subtrees contribute 0 to the sums. A leaf therefore always has tilt 0, while its value still counts toward its ancestors' sums.\n\n**Constraints:**\n- The node count is in `[0, 10^4]`.\n- `-1000 <= Node.val <= 1000`\n", "solution": "## Approach\n\nRun a post-order traversal that returns the sum of each subtree. At every node, the absolute gap between the left and right sums is that node's tilt and is added to a running total; the node then reports its own value plus both subtree sums upward. One walk therefore collects every tilt and every sum together.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for n nodes, each visited once.\n- **Space Complexity:** O(h) for the recursion stack, where h is the tree height.\n\n## Implementation\n\n```python\nclass Solution:\n def findTilt(self, root) -> int:\n self.total = 0\n def dfs(n):\n if n is None:\n return 0\n l = dfs(n.left)\n r = dfs(n.right)\n self.total += abs(l - r)\n return n.val + l + r\n dfs(root)\n return self.total\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 FindTilt(root *TreeNode) int {\n return 0\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def findTilt(self, root) -> int:\n return 0\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 findTilt(TreeNode* root) {\n return 0;\n }\n};"}, "fn": "findTilt", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int", "tests": [["[1,2,3]"], ["[4,2,9,3,5,null,7]"], ["[]"], ["[1]"], ["[1,2]"], ["[1,null,2]"], ["[2,1,3]"], ["[1,2,3,4,5]"], ["[5,3,8,1,4,7,9]"], ["[0]"], ["[-1,-2,-3]"], ["[10,5,15,3,7,null,18]"], ["[1,2,3,4,null,null,5]"], ["[3,9,20,null,null,15,7]"], ["[1,null,2,null,3]"], ["[4,2,6,1,3,5,7]"], ["[100,50,150,25,75,125,175]"], ["[1,1,1,1,1]"], ["[2,null,3,null,4]"], ["[7,3,9,1,5,8,10]"], ["[0,0,0]"], ["[1,2,null,3]"], ["[9,6,12,3,7,10,15]"], ["[1,2,3,null,4,null,5]"], ["[5]"], ["[4,1]"], ["[6,2,8,0,4,7,9]"], ["[3,1,2]"]], "expected": [1, 15, 0, 0, 2, 2, 2, 9, 21, 0, 1, 40, 11, 41, 8, 16, 400, 2, 11, 24, 0, 8, 30, 11, 0, 1, 24, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "309", "slug": "binary-tree-upside-down", "id": 309, "title": "Binary Tree Upside Down", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-upside-down/", "examples": [{"input": "root = [1,2,3,4,5]", "output": "[4,5,2,null,null,3,1]", "explanation": "The leftmost leaf 4 becomes the new root; 5 becomes its left child and 2 (with its right subtree 3 and parent 1) becomes its right child."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree stays empty."}, {"input": "root = [1]", "output": "[1]", "explanation": "A single node is already upside down."}], "hints": ["Walk down the left spine while remembering each node's right sibling.", "For each step set left.left = old right and left.right = parent.", "The leftmost node has no left child, so it becomes the new root."], "statement": "You are given the root of a binary tree in which every node either has no right child or its right child is a leaf, and every left child (when present) is an internal node with its own children. Turn the whole tree upside down and return the new root.\n\nRewiring follows one rule applied bottom-up along the left spine: for each node `p` with left child `l` and right child `r`, after the flip `l` takes `p`'s position, with `l.left = r` and `l.right = p`. The original root becomes a leaf.\n\n**Constraints:**\n- The tree holds between 0 and 1000 nodes.\n- `0 <= Node.val <= 100`\n- The input always satisfies the structural rule above (right children are leaves or absent).\n", "solution": "## Approach\n\nWalk down the left spine keeping the parent and the parent's right sibling. At each node, save its left and right children, then point its left to the previous right sibling and its right to the parent. Advance all pointers one step left; the last visited node is the new root.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each spine node is rewired once.\n- **Space Complexity:** O(1) extra for the iterative walk (O(h) if done recursively).\n\n## Implementation\n\n```python\nclass Solution:\n def upsideDownBinaryTree(self, root):\n curr, prev, prev_right = root, None, None\n while curr:\n nxt = curr.left\n right = curr.right\n curr.left = prev_right\n curr.right = prev\n prev = curr\n prev_right = right\n curr = nxt\n return prev\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 UpsideDownBinaryTree(root *TreeNode) *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 upsideDownBinaryTree(self, root):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* upsideDownBinaryTree(TreeNode* root) {\n return nullptr;\n }\n};"}, "fn": "upsideDownBinaryTree", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "tree_node", "tests": [["[1,2,3,4,5]"], ["[]"], ["[1]"], ["[1,2]"], ["[1,2,3]"], ["[1,2,null,3,null,4]"], ["[2,3,null]"], ["[1,2,3,4,null,null,null,5]"], ["[5,4,null,3,null,2]"], ["[1,2,null]"], ["[10,20,30,40,50]"], ["[1,2,3,4,5,null,null,6,7]"], ["[3,2,null,1]"], ["[7,8,null,9]"], ["[1,2,null,3,null,4,null,5]"], ["[9,8,7,6,null,null,null,5]"], ["[4,5,null,6]"], ["[1,2,3,4,null]"], ["[6,7,null,8,9]"], ["[11,22,33,44,55]"], ["[1,2]"], ["[2,3]"], ["[5,6,null,7,8]"], ["[100,50,null,25]"], ["[1,2,null,3]"], ["[8,9,10,11,12]"], ["[3,1,null,2]"], ["[15,10,null,5]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "403", "slug": "binary-tree-vertical-order-traversal", "id": 403, "title": "Binary Tree Vertical Order Traversal", "difficulty": "Medium", "category": "hash-table", "link": "https://leetcode.com/problems/binary-tree-vertical-order-traversal/", "examples": [{"explanation": "Column -1 holds 9; column 0 holds 3 then 15; column 1 holds 20; column 2 holds 7.", "input": "root = [3,9,20,null,null,15,7]", "output": "[[9],[3,15],[20],[7]]"}, {"explanation": "Node 4 alone fills column -2, node 9 fills column -1, nodes 3, 0 and 1 share column 0 from top to bottom, node 8 fills column 1, and node 7 fills column 2.", "input": "root = [3,9,8,4,0,1,7]", "output": "[[4],[9],[3,0,1],[8],[7]]"}, {"explanation": "The deeper nodes 5 and 2 join columns -1 and 1 respectively, after the nodes above them.", "input": "root = [3,9,8,4,0,1,7,null,null,null,2,5]", "output": "[[4],[9,5],[3,0,1],[8,2],[7]]"}], "hints": ["Run a breadth-first scan carrying each node's column next to it in the queue.", "Append every visited value to the bucket for its column; BFS order automatically gives top-to-bottom, left-to-right placement.", "Sort the column keys (or track the min/max) before emitting the buckets left to right."], "statement": "You are given the root of a binary tree. Picture each node sitting in a vertical column: the root starts at column `0`, a left child moves one column left, and a right child moves one column right.\n\nCollect the node values column by column, ordering the columns from leftmost to rightmost. Inside a single column, list values from top to bottom; when several nodes share the same row and column, keep their left-to-right visiting order (as produced by a level-by-level scan that always visits a left child before its right sibling). Return the resulting list of columns.\n\n**Constraints:**\n- The tree holds between `0` and `100` nodes.\n- `-100 <= Node.val <= 100`\n", "solution": "## Approach\n\nBreadth-first search carries each node's column alongside it in the queue, starting the root at column 0. Values are appended to per-column buckets, so BFS visit order naturally yields top-to-bottom, left-to-right placement within a column. Emitting the buckets sorted by column gives the final ordering.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n), where n is the number of nodes, due to sorting the column keys (O(n) with min/max tracking).\n- **Space Complexity:** O(n) for the queue and the buckets.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import defaultdict, deque\nclass Solution:\n def verticalOrder(self, root) -> List[List[int]]:\n if not root:\n return []\n cols = defaultdict(list)\n q = deque([(root, 0)])\n while q:\n node, c = q.popleft()\n cols[c].append(node.val)\n if node.left:\n q.append((node.left, c - 1))\n if node.right:\n q.append((node.right, c + 1))\n return [cols[c] for c in sorted(cols)]\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for a binary tree node.\ntype TreeNode struct {\n Val int\n Left *TreeNode\n Right *TreeNode\n}\n*/\n\nfunc VerticalOrder(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\nfrom typing import List\nclass Solution:\n def verticalOrder(self, root) -> List[List[int]]:\n # TODO: return values grouped by column, left to right\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> verticalOrder(TreeNode* root) {\n \n }\n};"}, "fn": "verticalOrder", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int_list_2d", "tests": [["[3,9,20,null,null,15,7]"], ["[3,9,8,4,0,1,7]"], ["[3,9,8,4,0,1,7,null,null,null,2,5]"], ["[]"], ["[1]"], ["[1,2,3]"], ["[1,2,3,4,5]"], ["[1,null,2,3]"], ["[1,null,2]"], ["[2,1,3]"], ["[1,2]"], ["[5,3,8,1,4,7,9]"], ["[1,null,2,null,3,null,4]"], ["[-1,-2,-3]"], ["[0]"], ["[10,5,15,3,7,12,20]"], ["[1,2,3,null,4,null,5]"], ["[2,null,3,null,4,null,5]"], ["[-100]"], ["[1,-2,-3,1,3,-2,null,-1]"], ["[5,null,4,null,3,null,2,null,1]"], ["[1,2,3,4,null,null,5]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[1,2,3,4,5,6,7]"], ["[-5,4,6]"], ["[0,-1,1]"], ["[4,2,6,1,3,5,7]"], ["[1,2,null,3]"], ["[100,-100,100]"], ["[3,1,4,1,5,9,2,6]"]], "expected": [[[9], [3, 15], [20], [7]], [[4], [9], [3, 0, 1], [8], [7]], [[4], [9, 5], [3, 0, 1], [8, 2], [7]], [], [[1]], [[2], [1], [3]], [[4], [2], [1, 5], [3]], [[1, 3], [2]], [[1], [2]], [[1], [2], [3]], [[2], [1]], [[1], [3], [5, 4, 7], [8], [9]], [[1], [2], [3], [4]], [[-2], [-1], [-3]], [[0]], [[3], [5], [10, 7, 12], [15], [20]], [[2], [1, 4], [3], [5]], [[2], [3], [4], [5]], [[-100]], [[-1], [1], [-2], [1, 3, -2], [-3]], [[5], [4], [3], [2], [1]], [[4], [2], [1], [3], [5]], [[1], [3, 4], [8, 6], [10, 7, 13], [14]], [[4], [2], [1, 5, 6], [3], [7]], [[4], [-5], [6]], [[-1], [0], [1]], [[1], [2], [4, 3, 5], [6], [7]], [[3], [2], [1]], [[-100], [100], [100]], [[6], [1], [1], [3, 5, 9], [4], [2]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "284", "slug": "binary-tree-zigzag-level-order-traversal", "id": 284, "title": "Binary Tree Zigzag Level Order Traversal", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/", "examples": [{"input": "root = [3,9,20,null,null,15,7]", "output": "[[3],[20,9],[15,7]]", "explanation": "Level 0 goes left-to-right ([3]), level 1 goes right-to-left ([20,9]), level 2 goes left-to-right ([15,7])."}, {"input": "root = [1]", "output": "[[1]]", "explanation": "A single level contains just [1]."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree yields no levels."}], "hints": ["Run a standard breadth-first walk but track the depth so you know when to flip a level.", "Collect each level left-to-right, then reverse every odd-indexed level (or fill it backwards).", "Adaptation: the nested list maps to int_list_2d in this judge."], "statement": "Walk a binary tree level by level, but alternate the reading direction on each row: the first row goes left to right, the next goes right to left, then left to right again, and so on.\n\nGather the node values at each depth in visit order, flip the rows that fall on odd depths, and return all rows from top to bottom.\n\n**Constraints:**\n- `0 <= number of nodes <= 2000`\n- `-100 <= Node.val <= 100`\n\n**Adaptation note:** The nested value list is represented as `int_list_2d` in this judge.\n", "solution": "## Approach\n\nBreadth-first search visits one depth at a time. Keep a flag that flips after every row: rows on even depths are kept as collected, rows on odd depths are reversed. Each node enters and leaves the queue once, and children are enqueued in natural left-to-right order so reversal alone produces the zigzag.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), each node processed once plus linear reversals.\n- **Space Complexity:** O(n) for the queue and the answer.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\nclass Solution:\n def zigzagLevelOrder(self, root) -> List[List[int]]:\n if not root:\n return []\n ans = []\n q = deque([root])\n ltr = True\n while q:\n level = []\n for _ in range(len(q)):\n n = q.popleft()\n level.append(n.val)\n if n.left:\n q.append(n.left)\n if n.right:\n q.append(n.right)\n if not ltr:\n level.reverse()\n ans.append(level)\n ltr = not ltr\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 ZigzagLevelOrder(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\nfrom typing import List\nclass Solution:\n def zigzagLevelOrder(self, root) -> List[List[int]]:\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*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n \n }\n};"}, "fn": "zigzagLevelOrder", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_list_2d", "tests": [["[3,9,20,null,null,15,7]"], ["[1]"], ["[]"], ["[1,2,3,4,5,6,7]"], ["[1,2,null,3,null,4]"], ["[1,null,2,null,3]"], ["[1,2,3,4,null,null,5]"], ["[3,9,20,15,7]"], ["[1,2,3,4,5]"], ["[5,4,6,3,null,null,7]"], ["[1,2,3,null,4,5,6]"], ["[10,5,15,2,7,12,20]"], ["[1,null,2,3,4]"], ["[2,1,3]"], ["[0,-1,1]"], ["[100,50,150,25,75,125,175,10,30]"], ["[1,2,3,4,5,6,7,8]"], ["[1,2,3,null,null,4,5]"], ["[7,3,10,2,5,null,12,1]"], ["[1,2,null,3,null,4,null,5]"], ["[5,null,4,null,3,null,2,null,1]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[-10,-5,0,5,10]"], ["[3,1,4,null,2,null,5]"], ["[6,3,9,1,4,8,10,0,2]"], ["[2,null,3,null,4,null,5,null,6]"]], "expected": [[[3], [20, 9], [15, 7]], [[1]], [], [[1], [3, 2], [4, 5, 6, 7]], [[1], [2], [3], [4]], [[1], [2], [3]], [[1], [3, 2], [4, 5]], [[3], [20, 9], [15, 7]], [[1], [3, 2], [4, 5]], [[5], [6, 4], [3, 7]], [[1], [3, 2], [4, 5, 6]], [[10], [15, 5], [2, 7, 12, 20]], [[1], [2], [3, 4]], [[2], [3, 1]], [[0], [1, -1]], [[100], [150, 50], [25, 75, 125, 175], [30, 10]], [[1], [3, 2], [4, 5, 6, 7], [8]], [[1], [3, 2], [4, 5]], [[7], [10, 3], [2, 5, 12], [1]], [[1], [2], [3], [4], [5]], [[5], [4], [3], [2], [1]], [[1], [3, 2], [4, 5, 6, 7], [10, 9, 8]], [[-10], [0, -5], [5, 10]], [[3], [4, 1], [2, 5]], [[6], [9, 3], [1, 4, 8, 10], [2, 0]], [[2], [3], [4], [5], [6]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "821", "slug": "binary-trees-with-factors", "id": 821, "title": "Binary Trees With Factors", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/binary-trees-with-factors/", "examples": [{"input": "arr = [2,4]", "output": "3", "explanation": "Trees are the single nodes 2 and 4 plus the tree with root 4 and children 2,2."}, {"input": "arr = [2,4,5,10]", "output": "7", "explanation": "Four singletons plus trees rooted at 4 (2,2), at 10 (2,5) and at 10 (5,2)."}, {"input": "arr = [2,3]", "output": "2", "explanation": "No product of two entries lands back in the set, so only singletons exist."}], "hints": ["Sort the values so every factor pair of a root has already been counted.", "For each root, add dp[left] * dp[right] over all factor pairs left*right == root, starting from 1 for the singleton."], "statement": "You are given distinct integers `arr`. A factored binary tree is a binary tree where every node value belongs to `arr`, and each non-leaf node's value equals the product of its two children.\n\nCount all such trees (order of the two children matters, so swapping left and right creates a different tree). Return the count modulo 1,000,000,007.\n\n**Constraints:**\n- `1 <= arr.length <= 1000`\n- `2 <= arr[i] <= 10^9`\n- All values are distinct.\n", "solution": "## Approach\n\nSort the array so that when a value is processed, all of its potential factors are already solved. Keep dp[v] as the number of trees rooted at v, starting at 1 for the singleton. For each pair of earlier values whose product equals the current root, multiply their tree counts and add the ordered contribution (iterating over all left factors automatically counts both orders). Sum all dp entries modulo 1e9+7.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) for n values, one divisibility check per pair.\n- **Space Complexity:** O(n) for the DP table and index map.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def numFactoredBinaryTrees(self, arr: List[int]) -> int:\n MOD = 10 ** 9 + 7\n arr = sorted(arr)\n pos = {v: i for i, v in enumerate(arr)}\n dp = [1] * len(arr)\n for i, root in enumerate(arr):\n for j in range(i):\n if root % arr[j] != 0:\n continue\n other = root // arr[j]\n k = pos.get(other)\n if k is not None:\n dp[i] = (dp[i] + dp[j] * dp[k]) % MOD\n return sum(dp) % MOD\n```\n", "starter": {"go": "package main\n\nfunc NumFactoredBinaryTrees(arr []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def numFactoredBinaryTrees(self, arr: List[int]) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int numFactoredBinaryTrees(vector<int>& arr) {\n return 0;\n }\n};"}, "fn": "numFactoredBinaryTrees", "params": [{"name": "arr", "type": "int_array"}], "outputType": "int", "tests": [["[2,4]"], ["[2,4,5,10]"], ["[2,3]"], ["[2]"], ["[2,4,8]"], ["[2,4,8,16]"], ["[3,9,27]"], ["[2,3,6]"], ["[2,3,6,12]"], ["[5,10,25]"], ["[2,5,10,25,50]"], ["[3,5,15]"], ["[4,16,2,8]"], ["[10,20,40]"], ["[2,7,14,28]"], ["[6,12,3,2]"], ["[100,10,2,5]"], ["[2,4,16,256]"], ["[3,6,18]"], ["[7,11]"], ["[2,3,5,30]"], ["[2,8,32]"], ["[45,15,5,3]"], ["[2,4,5,20]"], ["[6,10,15,30]"], ["[2,6,18,54]"], ["[1000000000,1000,1000000]"], ["[2,3,7,42]"]], "expected": [3, 7, 2, 1, 8, 23, 8, 5, 12, 4, 18, 5, 23, 3, 12, 12, 15, 34, 5, 2, 4, 3, 12, 9, 4, 4, 8, 4], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "475", "slug": "binary-watch", "id": 475, "title": "Binary Watch", "difficulty": "Easy", "category": "binary", "link": "https://leetcode.com/problems/binary-watch/", "examples": [{"explanation": "One lit lamp sets either one minute bit or one hour bit.", "input": "turnedOn = 1", "output": "[\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]"}, {"explanation": "At most 8 lamps can ever be lit, so 9 has no reading.", "input": "turnedOn = 9", "output": "[]"}, {"explanation": "With nothing lit the watch reads 0:00.", "input": "turnedOn = 0", "output": "[\"0:00\"]"}], "hints": ["Try every hour 0..11 and minute 0..59 and count set bits.", "A pair fits when the two popcounts add up to turnedOn.", "Format minutes with two digits via %02d-style padding."], "statement": "A novelty watch shows the time with ten tiny lamps: four lamps encode the hour (`0` to `11`) in binary and six lamps encode the minute (`0` to `59`) in binary, each lamp worth a power of two with the smallest values on the right. Exactly `turnedOn` lamps are lit. List every time the watch could be displaying.\n\nFormat each answer as `h:mm`: the hour has no leading zero, while the minute always uses two digits (for instance `\"1:00\"`, never `\"01:00\"` or `\"10:2\"`). The order of the returned list does not matter.\n\n**Constraints:**\n- `0 <= turnedOn <= 10`\n", "solution": "## Approach\n\nBrute force over the tiny search space: for each hour 0..11 and minute 0..59, add the binary popcounts of the two values. Keep the pair when the sum equals `turnedOn`, formatting minutes with a leading zero when needed. Exhausting 720 pairs is trivial and cannot miss a reading.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1), a fixed 12 * 60 enumeration.\n- **Space Complexity:** O(1) besides the output.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def readBinaryWatch(self, turnedOn: int) -> List[str]:\n res = []\n for h in range(12):\n for m in range(60):\n if bin(h).count('1') + bin(m).count('1') == turnedOn:\n res.append(f\"{h}:{m:02d}\")\n return res\n```\n", "starter": {"go": "package main\n\nfunc ReadBinaryWatch(turnedOn int) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def readBinaryWatch(self, turnedOn: int) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> readBinaryWatch(int turnedOn) {\n return {};\n }\n};"}, "fn": "readBinaryWatch", "params": [{"name": "turnedOn", "type": "int"}], "outputType": "string_list", "tests": [["1"], ["9"], ["0"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["10"], ["1"], ["2"], ["0"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["0"], ["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"]], "expected": [["0:01", "0:02", "0:04", "0:08", "0:16", "0:32", "1:00", "2:00", "4:00", "8:00"], [], ["0:00"], ["0:03", "0:05", "0:06", "0:09", "0:10", "0:12", "0:17", "0:18", "0:20", "0:24", "0:33", "0:34", "0:36", "0:40", "0:48", "1:01", "1:02", "1:04", "1:08", "1:16", "1:32", "2:01", "2:02", "2:04", "2:08", "2:16", "2:32", "3:00", "4:01", "4:02", "4:04", "4:08", "4:16", "4:32", "5:00", "6:00", "8:01", "8:02", "8:04", "8:08", "8:16", "8:32", "9:00", "10:00"], ["0:07", "0:11", "0:13", "0:14", "0:19", "0:21", "0:22", "0:25", "0:26", "0:28", "0:35", "0:37", "0:38", "0:41", "0:42", "0:44", "0:49", "0:50", "0:52", "0:56", "1:03", "1:05", "1:06", "1:09", "1:10", "1:12", "1:17", "1:18", "1:20", "1:24", "1:33", "1:34", "1:36", "1:40", "1:48", "2:03", "2:05", "2:06", "2:09", "2:10", "2:12", "2:17", "2:18", "2:20", "2:24", "2:33", "2:34", "2:36", "2:40", "2:48", "3:01", "3:02", "3:04", "3:08", "3:16", "3:32", "4:03", "4:05", "4:06", "4:09", "4:10", "4:12", "4:17", "4:18", "4:20", "4:24", "4:33", "4:34", "4:36", "4:40", "4:48", "5:01", "5:02", "5:04", "5:08", "5:16", "5:32", "6:01", "6:02", "6:04", "6:08", "6:16", "6:32", "7:00", "8:03", "8:05", "8:06", "8:09", "8:10", "8:12", "8:17", "8:18", "8:20", "8:24", "8:33", "8:34", "8:36", "8:40", "8:48", "9:01", "9:02", "9:04", "9:08", "9:16", "9:32", "10:01", "10:02", "10:04", "10:08", "10:16", "10:32", "11:00"], ["0:15", "0:23", "0:27", "0:29", "0:30", "0:39", "0:43", "0:45", "0:46", "0:51", "0:53", "0:54", "0:57", "0:58", "1:07", "1:11", "1:13", "1:14", "1:19", "1:21", "1:22", "1:25", "1:26", "1:28", "1:35", "1:37", "1:38", "1:41", "1:42", "1:44", "1:49", "1:50", "1:52", "1:56", "2:07", "2:11", "2:13", "2:14", "2:19", "2:21", "2:22", "2:25", "2:26", "2:28", "2:35", "2:37", "2:38", "2:41", "2:42", "2:44", "2:49", "2:50", "2:52", "2:56", "3:03", "3:05", "3:06", "3:09", "3:10", "3:12", "3:17", "3:18", "3:20", "3:24", "3:33", "3:34", "3:36", "3:40", "3:48", "4:07", "4:11", "4:13", "4:14", "4:19", "4:21", "4:22", "4:25", "4:26", "4:28", "4:35", "4:37", "4:38", "4:41", "4:42", "4:44", "4:49", "4:50", "4:52", "4:56", "5:03", "5:05", "5:06", "5:09", "5:10", "5:12", "5:17", "5:18", "5:20", "5:24", "5:33", "5:34", "5:36", "5:40", "5:48", "6:03", "6:05", "6:06", "6:09", "6:10", "6:12", "6:17", "6:18", "6:20", "6:24", "6:33", "6:34", "6:36", "6:40", "6:48", "7:01", "7:02", "7:04", "7:08", "7:16", "7:32", "8:07", "8:11", "8:13", "8:14", "8:19", "8:21", "8:22", "8:25", "8:26", "8:28", "8:35", "8:37", "8:38", "8:41", "8:42", "8:44", "8:49", "8:50", "8:52", "8:56", "9:03", "9:05", "9:06", "9:09", "9:10", "9:12", "9:17", "9:18", "9:20", "9:24", "9:33", "9:34", "9:36", "9:40", "9:48", "10:03", "10:05", "10:06", "10:09", "10:10", "10:12", "10:17", "10:18", "10:20", "10:24", "10:33", "10:34", "10:36", "10:40", "10:48", "11:01", "11:02", "11:04", "11:08", "11:16", "11:32"], ["0:31", "0:47", "0:55", "0:59", "1:15", "1:23", "1:27", "1:29", "1:30", "1:39", "1:43", "1:45", "1:46", "1:51", "1:53", "1:54", "1:57", "1:58", "2:15", "2:23", "2:27", "2:29", "2:30", "2:39", "2:43", "2:45", "2:46", "2:51", "2:53", "2:54", "2:57", "2:58", "3:07", "3:11", "3:13", "3:14", "3:19", "3:21", "3:22", "3:25", "3:26", "3:28", "3:35", "3:37", "3:38", "3:41", "3:42", "3:44", "3:49", "3:50", "3:52", "3:56", "4:15", "4:23", "4:27", "4:29", "4:30", "4:39", "4:43", "4:45", "4:46", "4:51", "4:53", "4:54", "4:57", "4:58", "5:07", "5:11", "5:13", "5:14", "5:19", "5:21", "5:22", "5:25", "5:26", "5:28", "5:35", "5:37", "5:38", "5:41", "5:42", "5:44", "5:49", "5:50", "5:52", "5:56", "6:07", "6:11", "6:13", "6:14", "6:19", "6:21", "6:22", "6:25", "6:26", "6:28", "6:35", "6:37", "6:38", "6:41", "6:42", "6:44", "6:49", "6:50", "6:52", "6:56", "7:03", "7:05", "7:06", "7:09", "7:10", "7:12", "7:17", "7:18", "7:20", "7:24", "7:33", "7:34", "7:36", "7:40", "7:48", "8:15", "8:23", "8:27", "8:29", "8:30", "8:39", "8:43", "8:45", "8:46", "8:51", "8:53", "8:54", "8:57", "8:58", "9:07", "9:11", "9:13", "9:14", "9:19", "9:21", "9:22", "9:25", "9:26", "9:28", "9:35", "9:37", "9:38", "9:41", "9:42", "9:44", "9:49", "9:50", "9:52", "9:56", "10:07", "10:11", "10:13", "10:14", "10:19", "10:21", "10:22", "10:25", "10:26", "10:28", "10:35", "10:37", "10:38", "10:41", "10:42", "10:44", "10:49", "10:50", "10:52", "10:56", "11:03", "11:05", "11:06", "11:09", "11:10", "11:12", "11:17", "11:18", "11:20", "11:24", "11:33", "11:34", "11:36", "11:40", "11:48"], ["1:31", "1:47", "1:55", "1:59", "2:31", "2:47", "2:55", "2:59", "3:15", "3:23", "3:27", "3:29", "3:30", "3:39", "3:43", "3:45", "3:46", "3:51", "3:53", "3:54", "3:57", "3:58", "4:31", "4:47", "4:55", "4:59", "5:15", "5:23", "5:27", "5:29", "5:30", "5:39", "5:43", "5:45", "5:46", "5:51", "5:53", "5:54", "5:57", "5:58", "6:15", "6:23", "6:27", "6:29", "6:30", "6:39", "6:43", "6:45", "6:46", "6:51", "6:53", "6:54", "6:57", "6:58", "7:07", "7:11", "7:13", "7:14", "7:19", "7:21", "7:22", "7:25", "7:26", "7:28", "7:35", "7:37", "7:38", "7:41", "7:42", "7:44", "7:49", "7:50", "7:52", "7:56", "8:31", "8:47", "8:55", "8:59", "9:15", "9:23", "9:27", "9:29", "9:30", "9:39", "9:43", "9:45", "9:46", "9:51", "9:53", "9:54", "9:57", "9:58", "10:15", "10:23", "10:27", "10:29", "10:30", "10:39", "10:43", "10:45", "10:46", "10:51", "10:53", "10:54", "10:57", "10:58", "11:07", "11:11", "11:13", "11:14", "11:19", "11:21", "11:22", "11:25", "11:26", "11:28", "11:35", "11:37", "11:38", "11:41", "11:42", "11:44", "11:49", "11:50", "11:52", "11:56"], ["3:31", "3:47", "3:55", "3:59", "5:31", "5:47", "5:55", "5:59", "6:31", "6:47", "6:55", "6:59", "7:15", "7:23", "7:27", "7:29", "7:30", "7:39", "7:43", "7:45", "7:46", "7:51", "7:53", "7:54", "7:57", "7:58", "9:31", "9:47", "9:55", "9:59", "10:31", "10:47", "10:55", "10:59", "11:15", "11:23", "11:27", "11:29", "11:30", "11:39", "11:43", "11:45", "11:46", "11:51", "11:53", "11:54", "11:57", "11:58"], ["7:31", "7:47", "7:55", "7:59", "11:31", "11:47", "11:55", "11:59"], [], ["0:01", "0:02", "0:04", "0:08", "0:16", "0:32", "1:00", "2:00", "4:00", "8:00"], ["0:03", "0:05", "0:06", "0:09", "0:10", "0:12", "0:17", "0:18", "0:20", "0:24", "0:33", "0:34", "0:36", "0:40", "0:48", "1:01", "1:02", "1:04", "1:08", "1:16", "1:32", "2:01", "2:02", "2:04", "2:08", "2:16", "2:32", "3:00", "4:01", "4:02", "4:04", "4:08", "4:16", "4:32", "5:00", "6:00", "8:01", "8:02", "8:04", "8:08", "8:16", "8:32", "9:00", "10:00"], ["0:00"], ["0:07", "0:11", "0:13", "0:14", "0:19", "0:21", "0:22", "0:25", "0:26", "0:28", "0:35", "0:37", "0:38", "0:41", "0:42", "0:44", "0:49", "0:50", "0:52", "0:56", "1:03", "1:05", "1:06", "1:09", "1:10", "1:12", "1:17", "1:18", "1:20", "1:24", "1:33", "1:34", "1:36", "1:40", "1:48", "2:03", "2:05", "2:06", "2:09", "2:10", "2:12", "2:17", "2:18", "2:20", "2:24", "2:33", "2:34", "2:36", "2:40", "2:48", "3:01", "3:02", "3:04", "3:08", "3:16", "3:32", "4:03", "4:05", "4:06", "4:09", "4:10", "4:12", "4:17", "4:18", "4:20", "4:24", "4:33", "4:34", "4:36", "4:40", "4:48", "5:01", "5:02", "5:04", "5:08", "5:16", "5:32", "6:01", "6:02", "6:04", "6:08", "6:16", "6:32", "7:00", "8:03", "8:05", "8:06", "8:09", "8:10", "8:12", "8:17", "8:18", "8:20", "8:24", "8:33", "8:34", "8:36", "8:40", "8:48", "9:01", "9:02", "9:04", "9:08", "9:16", "9:32", "10:01", "10:02", "10:04", "10:08", "10:16", "10:32", "11:00"], ["0:15", "0:23", "0:27", "0:29", "0:30", "0:39", "0:43", "0:45", "0:46", "0:51", "0:53", "0:54", "0:57", "0:58", "1:07", "1:11", "1:13", "1:14", "1:19", "1:21", "1:22", "1:25", "1:26", "1:28", "1:35", "1:37", "1:38", "1:41", "1:42", "1:44", "1:49", "1:50", "1:52", "1:56", "2:07", "2:11", "2:13", "2:14", "2:19", "2:21", "2:22", "2:25", "2:26", "2:28", "2:35", "2:37", "2:38", "2:41", "2:42", "2:44", "2:49", "2:50", "2:52", "2:56", "3:03", "3:05", "3:06", "3:09", "3:10", "3:12", "3:17", "3:18", "3:20", "3:24", "3:33", "3:34", "3:36", "3:40", "3:48", "4:07", "4:11", "4:13", "4:14", "4:19", "4:21", "4:22", "4:25", "4:26", "4:28", "4:35", "4:37", "4:38", "4:41", "4:42", "4:44", "4:49", "4:50", "4:52", "4:56", "5:03", "5:05", "5:06", "5:09", "5:10", "5:12", "5:17", "5:18", "5:20", "5:24", "5:33", "5:34", "5:36", "5:40", "5:48", "6:03", "6:05", "6:06", "6:09", "6:10", "6:12", "6:17", "6:18", "6:20", "6:24", "6:33", "6:34", "6:36", "6:40", "6:48", "7:01", "7:02", "7:04", "7:08", "7:16", "7:32", "8:07", "8:11", "8:13", "8:14", "8:19", "8:21", "8:22", "8:25", "8:26", "8:28", "8:35", "8:37", "8:38", "8:41", "8:42", "8:44", "8:49", "8:50", "8:52", "8:56", "9:03", "9:05", "9:06", "9:09", "9:10", "9:12", "9:17", "9:18", "9:20", "9:24", "9:33", "9:34", "9:36", "9:40", "9:48", "10:03", "10:05", "10:06", "10:09", "10:10", "10:12", "10:17", "10:18", "10:20", "10:24", "10:33", "10:34", "10:36", "10:40", "10:48", "11:01", "11:02", "11:04", "11:08", "11:16", "11:32"], ["0:31", "0:47", "0:55", "0:59", "1:15", "1:23", "1:27", "1:29", "1:30", "1:39", "1:43", "1:45", "1:46", "1:51", "1:53", "1:54", "1:57", "1:58", "2:15", "2:23", "2:27", "2:29", "2:30", "2:39", "2:43", "2:45", "2:46", "2:51", "2:53", "2:54", "2:57", "2:58", "3:07", "3:11", "3:13", "3:14", "3:19", "3:21", "3:22", "3:25", "3:26", "3:28", "3:35", "3:37", "3:38", "3:41", "3:42", "3:44", "3:49", "3:50", "3:52", "3:56", "4:15", "4:23", "4:27", "4:29", "4:30", "4:39", "4:43", "4:45", "4:46", "4:51", "4:53", "4:54", "4:57", "4:58", "5:07", "5:11", "5:13", "5:14", "5:19", "5:21", "5:22", "5:25", "5:26", "5:28", "5:35", "5:37", "5:38", "5:41", "5:42", "5:44", "5:49", "5:50", "5:52", "5:56", "6:07", "6:11", "6:13", "6:14", "6:19", "6:21", "6:22", "6:25", "6:26", "6:28", "6:35", "6:37", "6:38", "6:41", "6:42", "6:44", "6:49", "6:50", "6:52", "6:56", "7:03", "7:05", "7:06", "7:09", "7:10", "7:12", "7:17", "7:18", "7:20", "7:24", "7:33", "7:34", "7:36", "7:40", "7:48", "8:15", "8:23", "8:27", "8:29", "8:30", "8:39", "8:43", "8:45", "8:46", "8:51", "8:53", "8:54", "8:57", "8:58", "9:07", "9:11", "9:13", "9:14", "9:19", "9:21", "9:22", "9:25", "9:26", "9:28", "9:35", "9:37", "9:38", "9:41", "9:42", "9:44", "9:49", "9:50", "9:52", "9:56", "10:07", "10:11", "10:13", "10:14", "10:19", "10:21", "10:22", "10:25", "10:26", "10:28", "10:35", "10:37", "10:38", "10:41", "10:42", "10:44", "10:49", "10:50", "10:52", "10:56", "11:03", "11:05", "11:06", "11:09", "11:10", "11:12", "11:17", "11:18", "11:20", "11:24", "11:33", "11:34", "11:36", "11:40", "11:48"], ["1:31", "1:47", "1:55", "1:59", "2:31", "2:47", "2:55", "2:59", "3:15", "3:23", "3:27", "3:29", "3:30", "3:39", "3:43", "3:45", "3:46", "3:51", "3:53", "3:54", "3:57", "3:58", "4:31", "4:47", "4:55", "4:59", "5:15", "5:23", "5:27", "5:29", "5:30", "5:39", "5:43", "5:45", "5:46", "5:51", "5:53", "5:54", "5:57", "5:58", "6:15", "6:23", "6:27", "6:29", "6:30", "6:39", "6:43", "6:45", "6:46", "6:51", "6:53", "6:54", "6:57", "6:58", "7:07", "7:11", "7:13", "7:14", "7:19", "7:21", "7:22", "7:25", "7:26", "7:28", "7:35", "7:37", "7:38", "7:41", "7:42", "7:44", "7:49", "7:50", "7:52", "7:56", "8:31", "8:47", "8:55", "8:59", "9:15", "9:23", "9:27", "9:29", "9:30", "9:39", "9:43", "9:45", "9:46", "9:51", "9:53", "9:54", "9:57", "9:58", "10:15", "10:23", "10:27", "10:29", "10:30", "10:39", "10:43", "10:45", "10:46", "10:51", "10:53", "10:54", "10:57", "10:58", "11:07", "11:11", "11:13", "11:14", "11:19", "11:21", "11:22", "11:25", "11:26", "11:28", "11:35", "11:37", "11:38", "11:41", "11:42", "11:44", "11:49", "11:50", "11:52", "11:56"], ["3:31", "3:47", "3:55", "3:59", "5:31", "5:47", "5:55", "5:59", "6:31", "6:47", "6:55", "6:59", "7:15", "7:23", "7:27", "7:29", "7:30", "7:39", "7:43", "7:45", "7:46", "7:51", "7:53", "7:54", "7:57", "7:58", "9:31", "9:47", "9:55", "9:59", "10:31", "10:47", "10:55", "10:59", "11:15", "11:23", "11:27", "11:29", "11:30", "11:39", "11:43", "11:45", "11:46", "11:51", "11:53", "11:54", "11:57", "11:58"], ["7:31", "7:47", "7:55", "7:59", "11:31", "11:47", "11:55", "11:59"], [], [], ["0:00"], ["0:01", "0:02", "0:04", "0:08", "0:16", "0:32", "1:00", "2:00", "4:00", "8:00"], ["0:03", "0:05", "0:06", "0:09", "0:10", "0:12", "0:17", "0:18", "0:20", "0:24", "0:33", "0:34", "0:36", "0:40", "0:48", "1:01", "1:02", "1:04", "1:08", "1:16", "1:32", "2:01", "2:02", "2:04", "2:08", "2:16", "2:32", "3:00", "4:01", "4:02", "4:04", "4:08", "4:16", "4:32", "5:00", "6:00", "8:01", "8:02", "8:04", "8:08", "8:16", "8:32", "9:00", "10:00"], ["0:07", "0:11", "0:13", "0:14", "0:19", "0:21", "0:22", "0:25", "0:26", "0:28", "0:35", "0:37", "0:38", "0:41", "0:42", "0:44", "0:49", "0:50", "0:52", "0:56", "1:03", "1:05", "1:06", "1:09", "1:10", "1:12", "1:17", "1:18", "1:20", "1:24", "1:33", "1:34", "1:36", "1:40", "1:48", "2:03", "2:05", "2:06", "2:09", "2:10", "2:12", "2:17", "2:18", "2:20", "2:24", "2:33", "2:34", "2:36", "2:40", "2:48", "3:01", "3:02", "3:04", "3:08", "3:16", "3:32", "4:03", "4:05", "4:06", "4:09", "4:10", "4:12", "4:17", "4:18", "4:20", "4:24", "4:33", "4:34", "4:36", "4:40", "4:48", "5:01", "5:02", "5:04", "5:08", "5:16", "5:32", "6:01", "6:02", "6:04", "6:08", "6:16", "6:32", "7:00", "8:03", "8:05", "8:06", "8:09", "8:10", "8:12", "8:17", "8:18", "8:20", "8:24", "8:33", "8:34", "8:36", "8:40", "8:48", "9:01", "9:02", "9:04", "9:08", "9:16", "9:32", "10:01", "10:02", "10:04", "10:08", "10:16", "10:32", "11:00"], ["0:15", "0:23", "0:27", "0:29", "0:30", "0:39", "0:43", "0:45", "0:46", "0:51", "0:53", "0:54", "0:57", "0:58", "1:07", "1:11", "1:13", "1:14", "1:19", "1:21", "1:22", "1:25", "1:26", "1:28", "1:35", "1:37", "1:38", "1:41", "1:42", "1:44", "1:49", "1:50", "1:52", "1:56", "2:07", "2:11", "2:13", "2:14", "2:19", "2:21", "2:22", "2:25", "2:26", "2:28", "2:35", "2:37", "2:38", "2:41", "2:42", "2:44", "2:49", "2:50", "2:52", "2:56", "3:03", "3:05", "3:06", "3:09", "3:10", "3:12", "3:17", "3:18", "3:20", "3:24", "3:33", "3:34", "3:36", "3:40", "3:48", "4:07", "4:11", "4:13", "4:14", "4:19", "4:21", "4:22", "4:25", "4:26", "4:28", "4:35", "4:37", "4:38", "4:41", "4:42", "4:44", "4:49", "4:50", "4:52", "4:56", "5:03", "5:05", "5:06", "5:09", "5:10", "5:12", "5:17", "5:18", "5:20", "5:24", "5:33", "5:34", "5:36", "5:40", "5:48", "6:03", "6:05", "6:06", "6:09", "6:10", "6:12", "6:17", "6:18", "6:20", "6:24", "6:33", "6:34", "6:36", "6:40", "6:48", "7:01", "7:02", "7:04", "7:08", "7:16", "7:32", "8:07", "8:11", "8:13", "8:14", "8:19", "8:21", "8:22", "8:25", "8:26", "8:28", "8:35", "8:37", "8:38", "8:41", "8:42", "8:44", "8:49", "8:50", "8:52", "8:56", "9:03", "9:05", "9:06", "9:09", "9:10", "9:12", "9:17", "9:18", "9:20", "9:24", "9:33", "9:34", "9:36", "9:40", "9:48", "10:03", "10:05", "10:06", "10:09", "10:10", "10:12", "10:17", "10:18", "10:20", "10:24", "10:33", "10:34", "10:36", "10:40", "10:48", "11:01", "11:02", "11:04", "11:08", "11:16", "11:32"], ["0:31", "0:47", "0:55", "0:59", "1:15", "1:23", "1:27", "1:29", "1:30", "1:39", "1:43", "1:45", "1:46", "1:51", "1:53", "1:54", "1:57", "1:58", "2:15", "2:23", "2:27", "2:29", "2:30", "2:39", "2:43", "2:45", "2:46", "2:51", "2:53", "2:54", "2:57", "2:58", "3:07", "3:11", "3:13", "3:14", "3:19", "3:21", "3:22", "3:25", "3:26", "3:28", "3:35", "3:37", "3:38", "3:41", "3:42", "3:44", "3:49", "3:50", "3:52", "3:56", "4:15", "4:23", "4:27", "4:29", "4:30", "4:39", "4:43", "4:45", "4:46", "4:51", "4:53", "4:54", "4:57", "4:58", "5:07", "5:11", "5:13", "5:14", "5:19", "5:21", "5:22", "5:25", "5:26", "5:28", "5:35", "5:37", "5:38", "5:41", "5:42", "5:44", "5:49", "5:50", "5:52", "5:56", "6:07", "6:11", "6:13", "6:14", "6:19", "6:21", "6:22", "6:25", "6:26", "6:28", "6:35", "6:37", "6:38", "6:41", "6:42", "6:44", "6:49", "6:50", "6:52", "6:56", "7:03", "7:05", "7:06", "7:09", "7:10", "7:12", "7:17", "7:18", "7:20", "7:24", "7:33", "7:34", "7:36", "7:40", "7:48", "8:15", "8:23", "8:27", "8:29", "8:30", "8:39", "8:43", "8:45", "8:46", "8:51", "8:53", "8:54", "8:57", "8:58", "9:07", "9:11", "9:13", "9:14", "9:19", "9:21", "9:22", "9:25", "9:26", "9:28", "9:35", "9:37", "9:38", "9:41", "9:42", "9:44", "9:49", "9:50", "9:52", "9:56", "10:07", "10:11", "10:13", "10:14", "10:19", "10:21", "10:22", "10:25", "10:26", "10:28", "10:35", "10:37", "10:38", "10:41", "10:42", "10:44", "10:49", "10:50", "10:52", "10:56", "11:03", "11:05", "11:06", "11:09", "11:10", "11:12", "11:17", "11:18", "11:20", "11:24", "11:33", "11:34", "11:36", "11:40", "11:48"], ["1:31", "1:47", "1:55", "1:59", "2:31", "2:47", "2:55", "2:59", "3:15", "3:23", "3:27", "3:29", "3:30", "3:39", "3:43", "3:45", "3:46", "3:51", "3:53", "3:54", "3:57", "3:58", "4:31", "4:47", "4:55", "4:59", "5:15", "5:23", "5:27", "5:29", "5:30", "5:39", "5:43", "5:45", "5:46", "5:51", "5:53", "5:54", "5:57", "5:58", "6:15", "6:23", "6:27", "6:29", "6:30", "6:39", "6:43", "6:45", "6:46", "6:51", "6:53", "6:54", "6:57", "6:58", "7:07", "7:11", "7:13", "7:14", "7:19", "7:21", "7:22", "7:25", "7:26", "7:28", "7:35", "7:37", "7:38", "7:41", "7:42", "7:44", "7:49", "7:50", "7:52", "7:56", "8:31", "8:47", "8:55", "8:59", "9:15", "9:23", "9:27", "9:29", "9:30", "9:39", "9:43", "9:45", "9:46", "9:51", "9:53", "9:54", "9:57", "9:58", "10:15", "10:23", "10:27", "10:29", "10:30", "10:39", "10:43", "10:45", "10:46", "10:51", "10:53", "10:54", "10:57", "10:58", "11:07", "11:11", "11:13", "11:14", "11:19", "11:21", "11:22", "11:25", "11:26", "11:28", "11:35", "11:37", "11:38", "11:41", "11:42", "11:44", "11:49", "11:50", "11:52", "11:56"], ["3:31", "3:47", "3:55", "3:59", "5:31", "5:47", "5:55", "5:59", "6:31", "6:47", "6:55", "6:59", "7:15", "7:23", "7:27", "7:29", "7:30", "7:39", "7:43", "7:45", "7:46", "7:51", "7:53", "7:54", "7:57", "7:58", "9:31", "9:47", "9:55", "9:59", "10:31", "10:47", "10:55", "10:59", "11:15", "11:23", "11:27", "11:29", "11:30", "11:39", "11:43", "11:45", "11:46", "11:51", "11:53", "11:54", "11:57", "11:58"]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "249", "slug": "bitwise-and-of-numbers-range", "id": 249, "title": "Bitwise AND of Numbers Range", "difficulty": "Medium", "category": "bit-manipulation", "link": "https://leetcode.com/problems/bitwise-and-of-numbers-range/", "examples": [{"input": "left = 5, right = 7", "output": "4", "explanation": "5 (101) & 6 (110) & 7 (111) = 4 (100)."}, {"input": "left = 0, right = 0", "output": "0"}, {"input": "left = 1, right = 2147483647", "output": "0"}], "hints": ["The bitwise AND of the range has the common prefix of left and right in their binary forms, with all lower bits set to 0.", "Shift both left and right right until they become equal; shift the result back left by the same count."], "statement": "You receive the endpoints `left` and `right` of a closed interval `[left, right]`.\nCompute the cumulative `AND` formed by combining every integer inside those bounds.\n\n**Constraints:**\n\n- `0 <= left <= right <= 2^31 - 1`\n", "solution": "## Approach\n\nFor any two numbers `left <= right`, the AND of the whole range equals the common prefix of their binary representations with all trailing bits zeroed. Any differing low bit flips at least once inside the range, so those bits AND to 0. Shift both numbers right until they become equal, counting the shifts, then shift the surviving common prefix back left by that count.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1), at most 32 iterations for 32-bit integers.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def rangeBitwiseAnd(self, left: int, right: int) -> int:\n shift = 0\n while left < right:\n left >>= 1\n right >>= 1\n shift += 1\n return left << shift\n```", "starter": {"go": "package main\n\nfunc RangeBitwiseAnd(left int, right int) int {\n \n}", "python": "class Solution:\n def rangeBitwiseAnd(self, left: int, right: int) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int rangeBitwiseAnd(int left, int right) {\n \n }\n};"}, "fn": "rangeBitwiseAnd", "params": [{"name": "left", "type": "int"}, {"name": "right", "type": "int"}], "outputType": "int", "tests": [["5", "7"], ["0", "0"], ["1", "2147483647"], ["0", "1"], ["1", "1"], ["8", "15"], ["16", "31"], ["2", "2"], ["100", "100"], ["2147483646", "2147483647"], ["1073741824", "2147483647"], ["1", "3"], ["0", "2"], ["3", "3"], ["4", "4"], ["6", "7"], ["8", "8"], ["9", "12"], ["12", "15"], ["10", "11"], ["17", "23"], ["32", "63"], ["64", "127"], ["100", "101"], ["200", "214"], ["1000", "1001"], ["1024", "2047"], ["4096", "4097"], ["12345", "12345"], ["600000", "600005"], ["2147483647", "2147483647"]], "expected": [4, 0, 0, 0, 1, 8, 16, 2, 100, 2147483646, 1073741824, 0, 0, 3, 4, 6, 8, 8, 12, 10, 16, 32, 64, 100, 192, 1000, 1024, 4096, 12345, 600000, 2147483647], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "888", "slug": "bitwise-ors-of-subarrays", "id": 888, "title": "Bitwise ORs of Subarrays", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/bitwise-ors-of-subarrays/", "examples": [{"input": "arr = [0]", "output": "1", "explanation": "Only 0 is reachable."}, {"input": "arr = [1,1,2]", "output": "3", "explanation": "Reachable ORs are 1, 2, 3."}, {"input": "arr = [1,2,4]", "output": "6", "explanation": "Reachable ORs are 1, 2, 3, 4, 6, 7."}], "hints": ["Keep the set of ORs for blocks ending at the previous position; each new element extends them.", "That set stays tiny (at most ~30 values) because ORs can only gain bits, so the total work is linear."], "statement": "Look at every contiguous block inside `arr` (a block must keep neighbours together and cannot be empty). For each block compute the bitwise OR of its entries \u2014 the OR of a lone entry is the entry itself.\n\nHow many different OR values appear across all blocks?\n\n**Constraints:**\n- `1 <= arr.length <= 5 * 10^4`\n- `0 <= arr[i] <= 10^9`\n", "solution": "## Approach\n\nTrack two collections while sweeping left to right: all distinct ORs seen so far, and the ORs of blocks that finish at the current index. Each new value `x` starts a fresh singleton plus `y | x` for every previous ending value `y`. Because an OR can only turn zero bits to one, the ending set never grows beyond about thirty entries, keeping the whole pass fast.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * B) where B <= 30 is the bounded ending-set size, effectively O(n).\n- **Space Complexity:** O(B) for the rolling sets plus O(D) for the distinct answers.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def subarrayBitwiseORs(self, arr: List[int]) -> int:\n seen = set()\n cur = set()\n for x in arr:\n cur = {x} | {y | x for y in cur}\n seen |= cur\n return len(seen)\n```\n", "starter": {"go": "package main\n\nfunc SubarrayBitwiseORs(arr []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def subarrayBitwiseORs(self, arr: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int subarrayBitwiseORs(vector<int>& arr) {\n return 0;\n }\n};"}, "fn": "subarrayBitwiseORs", "params": [{"name": "arr", "type": "int_array"}], "outputType": "int", "tests": [["[0]"], ["[1,1,2]"], ["[1,2,4]"], ["[1]"], ["[2]"], ["[1,2]"], ["[2,1]"], ["[1,1,1]"], ["[0,0,0]"], ["[8,8,8]"], ["[1,2,3]"], ["[3,2,1]"], ["[4,4,4,4]"], ["[7,7,7]"], ["[1,2,4,8]"], ["[8,4,2,1]"], ["[5,1,9]"], ["[1000000000]"], ["[0,1,2,3]"], ["[2,2,2,3,3]"], ["[1,3,5,7]"], ["[10,20,30]"], ["[1,2,4,8,16]"], ["[0,0,1]"], ["[6,5,4]"], ["[3,5,7,9]"], ["[12,9,7]"], ["[1,2,3,4,5]"]], "expected": [1, 3, 6, 1, 1, 3, 3, 1, 1, 1, 3, 3, 1, 1, 10, 10, 4, 1, 4, 2, 4, 3, 15, 2, 4, 5, 5, 6], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "172", "slug": "boats-to-save-people", "id": 172, "title": "Boats to Save People", "difficulty": "Medium", "category": "two-pointer", "link": "https://leetcode.com/problems/boats-to-save-people/", "examples": [{"input": "people = [1,2], limit = 3", "output": "1", "explanation": "1 boat (1, 2)."}, {"input": "people = [3,2,2,1], limit = 3", "output": "3", "explanation": "3 boats (1, 2), (2) and (3)."}, {"input": "people = [3,5,3,4], limit = 5", "output": "4", "explanation": "4 boats (3), (3), (4), (5)."}], "hints": ["Sort the array and use two pointers at opposite ends.", "Pair the lightest remaining person with the heaviest when possible; otherwise the heaviest goes alone."], "statement": "An array `people` records body masses, with `people[i]` belonging to traveller `i`.\nAn unbounded fleet of dinghies is available; no dinghy tolerates a combined load above `limit`.\nNo dinghy accepts more than a pair of travellers simultaneously, and any pair aboard must jointly weigh no more than `limit`.\n\nDetermine the smallest fleet size capable of ferrying the whole group.\n\n**Constraints:**\n\n- 1 \u2264 people.length \u2264 5 * 10^4\n- 1 \u2264 people[i] \u2264 limit \u2264 3 * 10^4\n", "solution": "## Approach\n\nSort `people`, then use two pointers: `i` at the lightest and `j` at the heaviest. If the lightest and heaviest fit together (`people[i] + people[j] <= limit`), pair them and move both pointers; otherwise the heaviest goes alone and only `j` moves. Each step uses one boat.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n) due to sorting, where n is the number of people. The two-pointer sweep is O(n).\n- **Space Complexity:** O(1) extra besides sorting (O(n) if sorting needs auxiliary space).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def numRescueBoats(self, people: List[int], limit: int) -> int:\n people.sort()\n i, j = 0, len(people) - 1\n boats = 0\n while i <= j:\n if people[i] + people[j] <= limit:\n i += 1\n j -= 1\n boats += 1\n return boats\n```\n", "starter": {"go": "package main\n\nfunc NumRescueBoats(people []int, limit int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def numRescueBoats(self, people: List[int], limit: int) -> int:\n return 0\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int numRescueBoats(vector<int>& people, int limit) {\n return 0;\n }\n};"}, "fn": "numRescueBoats", "params": [{"name": "people", "type": "int_array"}, {"name": "limit", "type": "int"}], "outputType": "int", "tests": [["[1,2]", "3"], ["[3,2,2,1]", "3"], ["[3,5,3,4]", "5"], ["[1]", "1"], ["[2,2,2,2]", "4"], ["[1,2,3,4,5]", "5"], ["[5,5,5,5]", "5"], ["[1,1,1,1,1]", "2"], ["[3,2,3,2,2]", "6"], ["[2,49,10,7,11,41,47,2,22,6,13,12,33,18,10,26,2,6,50,10]", "50"], ["[1,2,3,4]", "4"], ["[4,4,4,4,4]", "8"], ["[3,1,2]", "3"], ["[2,3,2,3]", "5"], ["[1,1]", "1"], ["[1,1]", "2"], ["[2,3,5]", "5"], ["[4,2,3,5]", "6"], ["[3,4,5,6]", "7"], ["[5,1,4,2,3]", "6"], ["[10,10,10]", "10"], ["[1,2,3]", "6"], ["[4,5,6,7]", "10"], ["[2,2,3,3]", "5"], ["[1,3,5,7,9]", "10"], ["[6,6,6,6,6]", "12"], ["[3,3,3,3,3]", "6"], ["[7,3,2,8,1]", "9"], ["[9,9,1,1,9]", "10"], ["[30,30,30]", "30"], ["[5,4,3,2,1]", "5"]], "expected": [1, 3, 4, 1, 2, 3, 4, 3, 3, 11, 3, 3, 2, 2, 2, 1, 2, 3, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "760", "slug": "bold-words-in-string", "id": 760, "title": "Bold Words in String", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/bold-words-in-string/", "examples": [{"input": "words = [\"ab\",\"bc\"], s = \"aabcd\"", "output": "\"a<b>abc</b>d\"", "explanation": "Spans at 1 and 2 merge into 1-3."}, {"input": "words = [\"ab\",\"cb\"], s = \"aabcd\"", "output": "\"a<b>ab</b>cd\"", "explanation": "Only span 1-2 is bold."}], "hints": ["First build a boolean mask marking every character covered by any keyword occurrence, scanning all start positions.", "Two marked blocks belong together when they overlap or sit directly adjacent with no gap.", "Emit <b> at each group start and </b> at each group end while copying the original characters."], "statement": "You are given keyword list `words` and a text string `s`, both using lowercase letters.\n\nMark every occurrence of any keyword inside `s`, including overlaps. Then merge all marked spans that overlap or touch edge to edge into the fewest possible groups. Wrap each group with an opening tag `<b>` and a closing tag `</b>`, leaving unmarked parts untouched.\n\nReturn the tagged string.\n\n**Constraints:**\n- `1 <= s.length <= 500`\n- `0 <= words.length <= 50`\n- `1 <= words[i].length <= 10`\n- `s` and each word hold lowercase English letters.\n", "solution": "## Approach\n\nCreate a mask over the text and flag every position covered by any keyword occurrence, advancing the search by one after each hit so overlaps are found. Then walk the text once, opening a bold tag at the start of each maximal run of flagged characters and closing it at the run end, merging overlapping and touching spans automatically.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(W * S * L), where W is the word count, S is the text length, and L is the average word length for matching.\n- **Space Complexity:** O(S) for the mask plus the output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def boldWords(self, words: List[str], s: str) -> str:\n n = len(s)\n bold = [False] * n\n for w in words:\n start = 0\n while True:\n idx = s.find(w, start)\n if idx < 0:\n break\n for i in range(idx, idx + len(w)):\n bold[i] = True\n start = idx + 1\n res = []\n for i, ch in enumerate(s):\n if bold[i] and (i == 0 or not bold[i - 1]):\n res.append('<b>')\n res.append(ch)\n if bold[i] and (i == n - 1 or not bold[i + 1]):\n res.append('</b>')\n return ''.join(res)\n```\n", "starter": {"go": "package main\n\nfunc BoldWords(words []string, s string) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def boldWords(self, words: List[str], s: str) -> str:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string boldWords(vector<string>& words, string s) {\n return \"\";\n }\n};"}, "fn": "boldWords", "params": [{"name": "words", "type": "string_array"}, {"name": "s", "type": "string"}], "outputType": "string", "tests": [["['ab', 'bc']", "aabcd"], ["['ab', 'cb']", "aabcd"], ["[]", "abc"], ["['a']", "a"], ["['ab']", "ab"], ["['aa', 'bb']", "aabb"], ["['aaa', 'aab', 'bc']", "aaabbcc"], ["['abc']", "abcabc"], ["['ab', 'bc', 'cd']", "abcd"], ["['a', 'b', 'c']", "abc"], ["['xyz']", "abc"], ["['ab']", "aabbaa"], ["['aa']", "aaaa"], ["['ab', 'ba']", "abababa"], ["['hello']", "hellohello"], ["['a', 'aa', 'aaa']", "aaaaa"], ["['abc', 'bcd', 'cde']", "abcde"], ["['ab', 'cd']", "abcd"], ["['ab', 'cd']", "abxcd"], ["['e']", "eeee"], ["['long']", "short"], ["['s']", "mississippi"], ["['is', 'si']", "mississippi"], ["['ab']", "c"], ["['a']", "bbbb"], ["['abc', 'def']", "abcdef"], ["['abc', 'def']", "abcxdef"], ["['aa', 'aaa']", "aaaaaa"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "440", "slug": "bomb-enemy", "id": 440, "title": "Bomb Enemy", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/bomb-enemy/", "examples": [{"input": "grid = [[\"0\",\"E\",\"0\",\"0\"],[\"E\",\"0\",\"W\",\"E\"],[\"0\",\"E\",\"0\",\"0\"]]", "output": "3", "explanation": "A bomb on the middle of the first row sees two enemies downward and one to the side."}, {"input": "grid = [[\"W\",\"W\",\"W\"],[\"0\",\"0\",\"0\"],[\"E\",\"E\",\"E\"]]", "output": "1", "explanation": "Walls block every column, so each empty cell sees exactly one enemy below it."}], "hints": ["Split each row and each column into wall-separated segments and count the enemies per segment.", "An empty cell scores the sum of its row-segment count and its column-segment count.", "Recomputing the blast per cell from scratch is O((mn)^2); the segment tables give O(mn)."], "statement": "You are given a rectangular board whose cells hold `'W'` (wall), `'E'`\n(enemy) or `'0'` (empty ground). Dropping a bomb on an empty cell destroys\nevery enemy standing in the same row and column, with the blast stopped in\neach direction by the first wall (or the board edge).\n\nReport the largest number of enemies any single bomb placement can destroy.\nWhen the board has no empty cell, the answer is zero.\n\n**Type note:** the board arrives as a 2D char array; in Rust it is passed as\none string holding the JSON-encoded board.\n\n**Constraints:**\n- `1 <= grid.length, grid[i].length <= 50`\n- Each cell is one of `'W'`, `'E'`, `'0'`\n", "solution": "## Approach\n\nCut every row and column at walls into segments, count enemies inside each\nsegment, and record those counts in two tables. An empty cell then scores its\nrow count plus its column count; the maximum over all empty cells is the\nanswer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(mn) for an m x n board.\n- **Space Complexity:** O(mn) for the two count tables.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def maxKilledEnemies(self, grid: List[List[str]]) -> int:\n if not grid or not grid[0]:\n return 0\n m, n = len(grid), len(grid[0])\n rh = [[0] * n for _ in range(m)]\n ch = [[0] * n for _ in range(m)]\n for i in range(m):\n j = 0\n while j < n:\n if grid[i][j] == \"W\":\n j += 1\n continue\n k, c = j, 0\n while k < n and grid[i][k] != \"W\":\n if grid[i][k] == \"E\":\n c += 1\n k += 1\n for t in range(j, k):\n rh[i][t] = c\n j = k\n for j in range(n):\n i = 0\n while i < m:\n if grid[i][j] == \"W\":\n i += 1\n continue\n k, c = i, 0\n while k < m and grid[k][j] != \"W\":\n if grid[k][j] == \"E\":\n c += 1\n k += 1\n for t in range(i, k):\n ch[t][j] = c\n i = k\n best = 0\n for i in range(m):\n for j in range(n):\n if grid[i][j] == \"0\":\n best = max(best, rh[i][j] + ch[i][j])\n return best\n```\n", "starter": {"go": "package main\n\nfunc MaxKilledEnemies(grid [][]byte) int {\n \n}", "python": "from typing import List\nclass Solution:\n def maxKilledEnemies(self, grid: List[List[str]]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int maxKilledEnemies(vector<vector<char>>& grid) {\n return 0;\n }\n};"}, "fn": "maxKilledEnemies", "params": [{"name": "grid", "type": "char_array_2d"}], "outputType": "int", "tests": [["[[\"0\", \"E\", \"0\", \"0\"], [\"E\", \"0\", \"W\", \"E\"], [\"0\", \"E\", \"0\", \"0\"]]"], ["[[\"W\", \"W\", \"W\"], [\"0\", \"0\", \"0\"], [\"E\", \"E\", \"E\"]]"], ["[[\"0\"]]"], ["[[\"E\"]]"], ["[[\"W\"]]"], ["[[\"0\", \"0\"], [\"0\", \"0\"]]"], ["[[\"E\", \"E\"], [\"E\", \"E\"]]"], ["[[\"0\", \"E\"], [\"E\", \"0\"]]"], ["[[\"W\", \"E\", \"0\"], [\"0\", \"0\", \"0\"], [\"E\", \"0\", \"W\"]]"], ["[[\"0\", \"E\", \"E\", \"0\"], [\"E\", \"W\", \"E\", \"0\"], [\"0\", \"E\", \"0\", \"E\"]]"], ["[[\"0\", \"W\", \"0\"], [\"W\", \"W\", \"W\"], [\"0\", \"W\", \"0\"]]"], ["[[\"E\", \"0\", \"E\"], [\"0\", \"W\", \"0\"], [\"E\", \"0\", \"E\"]]"], ["[[\"0\", \"0\", \"0\", \"0\"], [\"0\", \"W\", \"W\", \"0\"], [\"0\", \"0\", \"0\", \"0\"]]"], ["[[\"E\", \"E\", \"E\"], [\"E\", \"0\", \"E\"], [\"E\", \"E\", \"E\"]]"], ["[[\"W\", \"0\", \"W\"], [\"0\", \"0\", \"0\"], [\"W\", \"0\", \"W\"]]"], ["[[\"0\", \"E\", \"0\"], [\"E\", \"E\", \"E\"], [\"0\", \"E\", \"0\"]]"], ["[[\"0\", \"0\", \"E\"], [\"0\", \"W\", \"0\"], [\"E\", \"0\", \"0\"]]"], ["[[\"E\"]]"], ["[[\"0\", \"W\", \"E\", \"0\", \"E\"]]"], ["[[\"0\"], [\"W\"], [\"E\"], [\"0\"], [\"E\"]]"], ["[[\"0\", \"E\", \"W\", \"E\", \"0\"], [\"E\", \"0\", \"0\", \"0\", \"E\"], [\"0\", \"E\", \"W\", \"E\", \"0\"]]"], ["[[\"W\", \"W\", \"0\", \"W\"], [\"0\", \"E\", \"E\", \"0\"], [\"W\", \"0\", \"W\", \"W\"]]"], ["[[\"0\", \"0\"], [\"W\", \"E\"], [\"0\", \"E\"]]"], ["[[\"E\", \"W\"], [\"W\", \"E\"]]"], ["[[\"0\", \"E\", \"0\", \"E\", \"0\"]]"], ["[[\"0\", \"0\", \"0\"], [\"0\", \"E\", \"0\"], [\"0\", \"0\", \"0\"]]"]], "expected": [3, 1, 0, 0, 0, 0, 0, 2, 2, 4, 0, 2, 0, 4, 0, 2, 2, 0, 2, 2, 4, 2, 2, 0, 2, 1], "loose": false}