offcode 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1038) hide show
  1. package/README.md +38 -2
  2. package/data/index.json +1 -0
  3. package/data/problems/01-matrix.json +1 -0
  4. package/data/problems/1-bit-and-2-bit-characters.json +1 -0
  5. package/data/problems/132-pattern.json +1 -0
  6. package/data/problems/2-keys-keyboard.json +1 -0
  7. package/data/problems/24-game.json +1 -0
  8. package/data/problems/3sum-closest.json +1 -0
  9. package/data/problems/3sum-smaller.json +1 -0
  10. package/data/problems/3sum-with-multiplicity.json +1 -0
  11. package/data/problems/3sum.json +1 -0
  12. package/data/problems/4-keys-keyboard.json +1 -0
  13. package/data/problems/4sum-ii.json +1 -0
  14. package/data/problems/4sum.json +1 -0
  15. package/data/problems/accounts-merge.json +1 -0
  16. package/data/problems/add-binary.json +1 -0
  17. package/data/problems/add-bold-tag-in-string.json +1 -0
  18. package/data/problems/add-digits.json +1 -0
  19. package/data/problems/add-one-row-to-tree.json +1 -0
  20. package/data/problems/add-strings.json +1 -0
  21. package/data/problems/add-to-array-form-of-integer.json +1 -0
  22. package/data/problems/add-two-numbers-ii.json +1 -0
  23. package/data/problems/add-two-numbers.json +1 -0
  24. package/data/problems/additive-number.json +1 -0
  25. package/data/problems/advantage-shuffle.json +1 -0
  26. package/data/problems/alien-dictionary.json +1 -0
  27. package/data/problems/all-nodes-distance-k-in-binary-tree.json +1 -0
  28. package/data/problems/all-oone-data-structure.json +1 -0
  29. package/data/problems/all-paths-from-source-to-target.json +1 -0
  30. package/data/problems/all-possible-full-binary-trees.json +1 -0
  31. package/data/problems/ambiguous-coordinates.json +1 -0
  32. package/data/problems/android-unlock-patterns.json +1 -0
  33. package/data/problems/arithmetic-slices-ii-subsequence.json +1 -0
  34. package/data/problems/arithmetic-slices.json +1 -0
  35. package/data/problems/arranging-coins.json +1 -0
  36. package/data/problems/array-nesting.json +1 -0
  37. package/data/problems/array-of-doubled-pairs.json +1 -0
  38. package/data/problems/array-partition.json +1 -0
  39. package/data/problems/assign-cookies.json +1 -0
  40. package/data/problems/asteroid-collision.json +1 -0
  41. package/data/problems/available-captures-for-rook.json +1 -0
  42. package/data/problems/average-of-levels-in-binary-tree.json +1 -0
  43. package/data/problems/backspace-string-compare.json +1 -0
  44. package/data/problems/bag-of-tokens.json +1 -0
  45. package/data/problems/balanced-binary-tree.json +1 -0
  46. package/data/problems/base-7.json +1 -0
  47. package/data/problems/baseball-game.json +1 -0
  48. package/data/problems/basic-absolute-value.json +1 -0
  49. package/data/problems/basic-array-max.json +1 -0
  50. package/data/problems/basic-array-min.json +1 -0
  51. package/data/problems/basic-array-sum-rec.json +1 -0
  52. package/data/problems/basic-array-sum.json +1 -0
  53. package/data/problems/basic-average-floor.json +1 -0
  54. package/data/problems/basic-bubble-sort.json +1 -0
  55. package/data/problems/basic-calculator-ii.json +1 -0
  56. package/data/problems/basic-calculator-iii.json +1 -0
  57. package/data/problems/basic-calculator-iv.json +1 -0
  58. package/data/problems/basic-calculator.json +1 -0
  59. package/data/problems/basic-collatz-steps.json +1 -0
  60. package/data/problems/basic-contains-value.json +1 -0
  61. package/data/problems/basic-count-above.json +1 -0
  62. package/data/problems/basic-count-char.json +1 -0
  63. package/data/problems/basic-count-digits.json +1 -0
  64. package/data/problems/basic-count-evens.json +1 -0
  65. package/data/problems/basic-count-pairs.json +1 -0
  66. package/data/problems/basic-count-vowels.json +1 -0
  67. package/data/problems/basic-count-words.json +1 -0
  68. package/data/problems/basic-countdown.json +1 -0
  69. package/data/problems/basic-double-array.json +1 -0
  70. package/data/problems/basic-factorial-rec.json +1 -0
  71. package/data/problems/basic-factorial.json +1 -0
  72. package/data/problems/basic-fibonacci.json +1 -0
  73. package/data/problems/basic-find-index.json +1 -0
  74. package/data/problems/basic-gcd.json +1 -0
  75. package/data/problems/basic-grade-letter.json +1 -0
  76. package/data/problems/basic-has-duplicate.json +1 -0
  77. package/data/problems/basic-is-even.json +1 -0
  78. package/data/problems/basic-is-leap-year.json +1 -0
  79. package/data/problems/basic-is-sorted.json +1 -0
  80. package/data/problems/basic-max-frequency.json +1 -0
  81. package/data/problems/basic-max-of-three.json +1 -0
  82. package/data/problems/basic-max-of-two.json +1 -0
  83. package/data/problems/basic-palindrome-text.json +1 -0
  84. package/data/problems/basic-power-rec.json +1 -0
  85. package/data/problems/basic-power.json +1 -0
  86. package/data/problems/basic-repeat-string.json +1 -0
  87. package/data/problems/basic-reverse-array.json +1 -0
  88. package/data/problems/basic-reverse-number.json +1 -0
  89. package/data/problems/basic-reverse-text-rec.json +1 -0
  90. package/data/problems/basic-reverse-text.json +1 -0
  91. package/data/problems/basic-second-largest.json +1 -0
  92. package/data/problems/basic-sort-two.json +1 -0
  93. package/data/problems/basic-staircase.json +1 -0
  94. package/data/problems/basic-string-length.json +1 -0
  95. package/data/problems/basic-sum-1-to-n.json +1 -0
  96. package/data/problems/basic-sum-digits-rec.json +1 -0
  97. package/data/problems/basic-sum-multiples.json +1 -0
  98. package/data/problems/basic-sum-of-digits.json +1 -0
  99. package/data/problems/basic-temperature-advice.json +1 -0
  100. package/data/problems/basic-to-upper.json +1 -0
  101. package/data/problems/basic-triangle-sum.json +1 -0
  102. package/data/problems/battleships-in-a-board.json +1 -0
  103. package/data/problems/beautiful-arrangement-ii.json +1 -0
  104. package/data/problems/beautiful-arrangement.json +1 -0
  105. package/data/problems/beautiful-array.json +1 -0
  106. package/data/problems/best-meeting-point.json +1 -0
  107. package/data/problems/best-time-to-buy-and-sell-stock-ii.json +1 -0
  108. package/data/problems/best-time-to-buy-and-sell-stock-iii.json +1 -0
  109. package/data/problems/best-time-to-buy-and-sell-stock-iv.json +1 -0
  110. package/data/problems/best-time-to-buy-and-sell-stock-with-cooldown.json +1 -0
  111. package/data/problems/best-time-to-buy-and-sell-stock-with-transaction-fee.json +1 -0
  112. package/data/problems/best-time-to-buy-and-sell-stock.json +1 -0
  113. package/data/problems/binary-gap.json +1 -0
  114. package/data/problems/binary-number-with-alternating-bits.json +1 -0
  115. package/data/problems/binary-search-tree-iterator.json +1 -0
  116. package/data/problems/binary-search.json +1 -0
  117. package/data/problems/binary-subarrays-with-sum.json +1 -0
  118. package/data/problems/binary-tree-cameras.json +1 -0
  119. package/data/problems/binary-tree-inorder-traversal.json +1 -0
  120. package/data/problems/binary-tree-level-order-traversal-ii.json +1 -0
  121. package/data/problems/binary-tree-level-order-traversal.json +1 -0
  122. package/data/problems/binary-tree-longest-consecutive-sequence-ii.json +1 -0
  123. package/data/problems/binary-tree-longest-consecutive-sequence.json +1 -0
  124. package/data/problems/binary-tree-maximum-path-sum.json +1 -0
  125. package/data/problems/binary-tree-paths.json +1 -0
  126. package/data/problems/binary-tree-postorder-traversal.json +1 -0
  127. package/data/problems/binary-tree-preorder-traversal.json +1 -0
  128. package/data/problems/binary-tree-pruning.json +1 -0
  129. package/data/problems/binary-tree-right-side-view.json +1 -0
  130. package/data/problems/binary-tree-tilt.json +1 -0
  131. package/data/problems/binary-tree-upside-down.json +1 -0
  132. package/data/problems/binary-tree-vertical-order-traversal.json +1 -0
  133. package/data/problems/binary-tree-zigzag-level-order-traversal.json +1 -0
  134. package/data/problems/binary-trees-with-factors.json +1 -0
  135. package/data/problems/binary-watch.json +1 -0
  136. package/data/problems/bitwise-and-of-numbers-range.json +1 -0
  137. package/data/problems/bitwise-ors-of-subarrays.json +1 -0
  138. package/data/problems/boats-to-save-people.json +1 -0
  139. package/data/problems/bold-words-in-string.json +1 -0
  140. package/data/problems/bomb-enemy.json +1 -0
  141. package/data/problems/boundary-of-binary-tree.json +1 -0
  142. package/data/problems/brick-wall.json +1 -0
  143. package/data/problems/bricks-falling-when-hit.json +1 -0
  144. package/data/problems/broken-calculator.json +1 -0
  145. package/data/problems/buddy-strings.json +1 -0
  146. package/data/problems/build-a-matrix-with-conditions.json +1 -0
  147. package/data/problems/bulb-switcher-ii.json +1 -0
  148. package/data/problems/bulb-switcher.json +1 -0
  149. package/data/problems/bulls-and-cows.json +1 -0
  150. package/data/problems/burst-balloons.json +1 -0
  151. package/data/problems/bus-routes.json +1 -0
  152. package/data/problems/can-i-win.json +1 -0
  153. package/data/problems/can-place-flowers.json +1 -0
  154. package/data/problems/candy-crush.json +1 -0
  155. package/data/problems/candy.json +1 -0
  156. package/data/problems/capacity-to-ship-packages-within-d-days.json +1 -0
  157. package/data/problems/car-fleet.json +1 -0
  158. package/data/problems/car-pooling.json +1 -0
  159. package/data/problems/card-flipping-game.json +1 -0
  160. package/data/problems/cat-and-mouse.json +1 -0
  161. package/data/problems/chalkboard-xor-game.json +1 -0
  162. package/data/problems/champagne-tower.json +1 -0
  163. package/data/problems/cheapest-flights-within-k-stops.json +1 -0
  164. package/data/problems/check-completeness-of-a-binary-tree.json +1 -0
  165. package/data/problems/cherry-pickup.json +1 -0
  166. package/data/problems/circular-array-loop.json +1 -0
  167. package/data/problems/climbing-stairs.json +1 -0
  168. package/data/problems/clone-graph.json +1 -0
  169. package/data/problems/closest-binary-search-tree-value-ii.json +1 -0
  170. package/data/problems/closest-binary-search-tree-value.json +1 -0
  171. package/data/problems/closest-leaf-in-a-binary-tree.json +1 -0
  172. package/data/problems/coin-change-ii.json +1 -0
  173. package/data/problems/coin-change.json +1 -0
  174. package/data/problems/coin-path.json +1 -0
  175. package/data/problems/combination-sum-ii.json +1 -0
  176. package/data/problems/combination-sum-iii.json +1 -0
  177. package/data/problems/combination-sum-iv.json +1 -0
  178. package/data/problems/combination-sum.json +1 -0
  179. package/data/problems/combinations.json +1 -0
  180. package/data/problems/compare-version-numbers.json +1 -0
  181. package/data/problems/complete-binary-tree-inserter.json +1 -0
  182. package/data/problems/complex-number-multiplication.json +1 -0
  183. package/data/problems/concatenated-words.json +1 -0
  184. package/data/problems/concatenation-of-array.json +1 -0
  185. package/data/problems/consecutive-numbers-sum.json +1 -0
  186. package/data/problems/construct-binary-tree-from-inorder-and-postorder-traversal.json +1 -0
  187. package/data/problems/construct-binary-tree-from-preorder-and-inorder-traversal.json +1 -0
  188. package/data/problems/construct-binary-tree-from-preorder-and-postorder-traversal.json +1 -0
  189. package/data/problems/construct-binary-tree-from-string.json +1 -0
  190. package/data/problems/construct-quad-tree.json +1 -0
  191. package/data/problems/construct-string-from-binary-tree.json +1 -0
  192. package/data/problems/construct-the-rectangle.json +1 -0
  193. package/data/problems/contain-virus.json +1 -0
  194. package/data/problems/container-with-most-water.json +1 -0
  195. package/data/problems/contains-duplicate-ii.json +1 -0
  196. package/data/problems/contains-duplicate-iii.json +1 -0
  197. package/data/problems/contains-duplicate.json +1 -0
  198. package/data/problems/contiguous-array.json +1 -0
  199. package/data/problems/continuous-subarray-sum.json +1 -0
  200. package/data/problems/convert-a-number-to-hexadecimal.json +1 -0
  201. package/data/problems/convert-binary-search-tree-to-sorted-doubly-linked-list.json +1 -0
  202. package/data/problems/convert-bst-to-greater-tree.json +1 -0
  203. package/data/problems/convert-sorted-array-to-binary-search-tree.json +1 -0
  204. package/data/problems/convert-sorted-list-to-binary-search-tree.json +1 -0
  205. package/data/problems/convex-polygon.json +1 -0
  206. package/data/problems/copy-list-with-random-pointer.json +1 -0
  207. package/data/problems/count-and-say.json +1 -0
  208. package/data/problems/count-binary-substrings.json +1 -0
  209. package/data/problems/count-complete-tree-nodes.json +1 -0
  210. package/data/problems/count-different-palindromic-subsequences.json +1 -0
  211. package/data/problems/count-good-nodes-in-binary-tree.json +1 -0
  212. package/data/problems/count-numbers-with-unique-digits.json +1 -0
  213. package/data/problems/count-of-range-sum.json +1 -0
  214. package/data/problems/count-of-smaller-numbers-after-self.json +1 -0
  215. package/data/problems/count-primes.json +1 -0
  216. package/data/problems/count-the-repetitions.json +1 -0
  217. package/data/problems/count-unique-characters-of-all-substrings-of-a-given-string.json +1 -0
  218. package/data/problems/count-univalue-subtrees.json +1 -0
  219. package/data/problems/counting-bits.json +1 -0
  220. package/data/problems/couples-holding-hands.json +1 -0
  221. package/data/problems/course-schedule-ii.json +1 -0
  222. package/data/problems/course-schedule-iii.json +1 -0
  223. package/data/problems/course-schedule-iv.json +1 -0
  224. package/data/problems/course-schedule.json +1 -0
  225. package/data/problems/cousins-in-binary-tree.json +1 -0
  226. package/data/problems/cracking-the-safe.json +1 -0
  227. package/data/problems/create-maximum-number.json +1 -0
  228. package/data/problems/custom-sort-string.json +1 -0
  229. package/data/problems/cut-off-trees-for-golf-event.json +1 -0
  230. package/data/problems/daily-temperatures.json +1 -0
  231. package/data/problems/data-stream-as-disjoint-intervals.json +1 -0
  232. package/data/problems/decode-string.json +1 -0
  233. package/data/problems/decode-ways-ii.json +1 -0
  234. package/data/problems/decode-ways.json +1 -0
  235. package/data/problems/decoded-string-at-index.json +1 -0
  236. package/data/problems/degree-of-an-array.json +1 -0
  237. package/data/problems/delete-and-earn.json +1 -0
  238. package/data/problems/delete-columns-to-make-sorted-ii.json +1 -0
  239. package/data/problems/delete-columns-to-make-sorted-iii.json +1 -0
  240. package/data/problems/delete-columns-to-make-sorted.json +1 -0
  241. package/data/problems/delete-leaves-with-a-given-value.json +1 -0
  242. package/data/problems/delete-node-in-a-bst.json +1 -0
  243. package/data/problems/delete-node-in-a-linked-list.json +1 -0
  244. package/data/problems/delete-operation-for-two-strings.json +1 -0
  245. package/data/problems/design-add-and-search-words-data-structure.json +1 -0
  246. package/data/problems/design-circular-deque.json +1 -0
  247. package/data/problems/design-circular-queue.json +1 -0
  248. package/data/problems/design-compressed-string-iterator.json +1 -0
  249. package/data/problems/design-excel-sum-formula.json +1 -0
  250. package/data/problems/design-hashmap.json +1 -0
  251. package/data/problems/design-hashset.json +1 -0
  252. package/data/problems/design-hit-counter.json +1 -0
  253. package/data/problems/design-in-memory-file-system.json +1 -0
  254. package/data/problems/design-linked-list.json +1 -0
  255. package/data/problems/design-log-storage-system.json +1 -0
  256. package/data/problems/design-phone-directory.json +1 -0
  257. package/data/problems/design-search-autocomplete-system.json +1 -0
  258. package/data/problems/design-snake-game.json +1 -0
  259. package/data/problems/design-tic-tac-toe.json +1 -0
  260. package/data/problems/design-twitter.json +1 -0
  261. package/data/problems/detect-capital.json +1 -0
  262. package/data/problems/detect-squares.json +1 -0
  263. package/data/problems/di-string-match.json +1 -0
  264. package/data/problems/diagonal-traverse.json +1 -0
  265. package/data/problems/diameter-of-binary-tree.json +1 -0
  266. package/data/problems/different-ways-to-add-parentheses.json +1 -0
  267. package/data/problems/distinct-subsequences-ii.json +1 -0
  268. package/data/problems/distinct-subsequences.json +1 -0
  269. package/data/problems/distribute-candies.json +1 -0
  270. package/data/problems/distribute-coins-in-binary-tree.json +1 -0
  271. package/data/problems/divide-two-integers.json +1 -0
  272. package/data/problems/domino-and-tromino-tiling.json +1 -0
  273. package/data/problems/dota2-senate.json +1 -0
  274. package/data/problems/dungeon-game.json +1 -0
  275. package/data/problems/edit-distance.json +1 -0
  276. package/data/problems/elimination-game.json +1 -0
  277. package/data/problems/employee-free-time.json +1 -0
  278. package/data/problems/employee-importance.json +1 -0
  279. package/data/problems/encode-and-decode-strings.json +1 -0
  280. package/data/problems/encode-and-decode-tinyurl.json +1 -0
  281. package/data/problems/encode-n-ary-tree-to-binary-tree.json +1 -0
  282. package/data/problems/encode-string-with-shortest-length.json +1 -0
  283. package/data/problems/equal-rational-numbers.json +1 -0
  284. package/data/problems/equal-tree-partition.json +1 -0
  285. package/data/problems/erect-the-fence.json +1 -0
  286. package/data/problems/escape-the-ghosts.json +1 -0
  287. package/data/problems/evaluate-division.json +1 -0
  288. package/data/problems/evaluate-reverse-polish-notation.json +1 -0
  289. package/data/problems/exam-room.json +1 -0
  290. package/data/problems/excel-sheet-column-number.json +1 -0
  291. package/data/problems/excel-sheet-column-title.json +1 -0
  292. package/data/problems/exclusive-time-of-functions.json +1 -0
  293. package/data/problems/expression-add-operators.json +1 -0
  294. package/data/problems/expressive-words.json +1 -0
  295. package/data/problems/extra-characters-in-a-string.json +1 -0
  296. package/data/problems/factor-combinations.json +1 -0
  297. package/data/problems/factorial-trailing-zeroes.json +1 -0
  298. package/data/problems/fair-candy-swap.json +1 -0
  299. package/data/problems/falling-squares.json +1 -0
  300. package/data/problems/fibonacci-number.json +1 -0
  301. package/data/problems/find-all-anagrams-in-a-string.json +1 -0
  302. package/data/problems/find-all-duplicates-in-an-array.json +1 -0
  303. package/data/problems/find-all-numbers-disappeared-in-an-array.json +1 -0
  304. package/data/problems/find-anagram-mappings.json +1 -0
  305. package/data/problems/find-and-replace-in-string.json +1 -0
  306. package/data/problems/find-and-replace-pattern.json +1 -0
  307. package/data/problems/find-bottom-left-tree-value.json +1 -0
  308. package/data/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.json +1 -0
  309. package/data/problems/find-duplicate-file-in-system.json +1 -0
  310. package/data/problems/find-duplicate-subtrees.json +1 -0
  311. package/data/problems/find-eventual-safe-states.json +1 -0
  312. package/data/problems/find-first-and-last-position-of-element-in-sorted-array.json +1 -0
  313. package/data/problems/find-in-mountain-array.json +1 -0
  314. package/data/problems/find-k-closest-elements.json +1 -0
  315. package/data/problems/find-k-pairs-with-smallest-sums.json +1 -0
  316. package/data/problems/find-k-th-smallest-pair-distance.json +1 -0
  317. package/data/problems/find-largest-value-in-each-tree-row.json +1 -0
  318. package/data/problems/find-leaves-of-binary-tree.json +1 -0
  319. package/data/problems/find-median-from-data-stream.json +1 -0
  320. package/data/problems/find-minimum-in-rotated-sorted-array-ii.json +1 -0
  321. package/data/problems/find-minimum-in-rotated-sorted-array.json +1 -0
  322. package/data/problems/find-mode-in-binary-search-tree.json +1 -0
  323. package/data/problems/find-peak-element.json +1 -0
  324. package/data/problems/find-permutation.json +1 -0
  325. package/data/problems/find-pivot-index.json +1 -0
  326. package/data/problems/find-right-interval.json +1 -0
  327. package/data/problems/find-smallest-letter-greater-than-target.json +1 -0
  328. package/data/problems/find-the-celebrity.json +1 -0
  329. package/data/problems/find-the-closest-palindrome.json +1 -0
  330. package/data/problems/find-the-derangement-of-an-array.json +1 -0
  331. package/data/problems/find-the-difference.json +1 -0
  332. package/data/problems/find-the-duplicate-number.json +1 -0
  333. package/data/problems/find-the-index-of-the-first-occurrence-in-a-string.json +1 -0
  334. package/data/problems/find-the-shortest-superstring.json +1 -0
  335. package/data/problems/find-the-town-judge.json +1 -0
  336. package/data/problems/first-bad-version.json +1 -0
  337. package/data/problems/first-missing-positive.json +1 -0
  338. package/data/problems/first-unique-character-in-a-string.json +1 -0
  339. package/data/problems/fizz-buzz.json +1 -0
  340. package/data/problems/flatten-2d-vector.json +1 -0
  341. package/data/problems/flatten-a-multilevel-doubly-linked-list.json +1 -0
  342. package/data/problems/flatten-binary-tree-to-linked-list.json +1 -0
  343. package/data/problems/flatten-nested-list-iterator.json +1 -0
  344. package/data/problems/flip-binary-tree-to-match-preorder-traversal.json +1 -0
  345. package/data/problems/flip-equivalent-binary-trees.json +1 -0
  346. package/data/problems/flip-game-ii.json +1 -0
  347. package/data/problems/flip-game.json +1 -0
  348. package/data/problems/flip-string-to-monotone-increasing.json +1 -0
  349. package/data/problems/flipping-an-image.json +1 -0
  350. package/data/problems/flood-fill.json +1 -0
  351. package/data/problems/fraction-addition-and-subtraction.json +1 -0
  352. package/data/problems/fraction-to-recurring-decimal.json +1 -0
  353. package/data/problems/freedom-trail.json +1 -0
  354. package/data/problems/friends-of-appropriate-ages.json +1 -0
  355. package/data/problems/frog-jump.json +1 -0
  356. package/data/problems/fruit-into-baskets.json +1 -0
  357. package/data/problems/game-of-life.json +1 -0
  358. package/data/problems/gas-station.json +1 -0
  359. package/data/problems/generalized-abbreviation.json +1 -0
  360. package/data/problems/generate-parentheses.json +1 -0
  361. package/data/problems/generate-random-point-in-a-circle.json +1 -0
  362. package/data/problems/global-and-local-inversions.json +1 -0
  363. package/data/problems/goat-latin.json +1 -0
  364. package/data/problems/graph-valid-tree.json +1 -0
  365. package/data/problems/gray-code.json +1 -0
  366. package/data/problems/greatest-common-divisor-of-strings.json +1 -0
  367. package/data/problems/greatest-common-divisor-traversal.json +1 -0
  368. package/data/problems/group-anagrams.json +1 -0
  369. package/data/problems/group-shifted-strings.json +1 -0
  370. package/data/problems/groups-of-special-equivalent-strings.json +1 -0
  371. package/data/problems/guess-number-higher-or-lower-ii.json +1 -0
  372. package/data/problems/guess-number-higher-or-lower.json +1 -0
  373. package/data/problems/guess-the-word.json +1 -0
  374. package/data/problems/h-index-ii.json +1 -0
  375. package/data/problems/h-index.json +1 -0
  376. package/data/problems/hamming-distance.json +1 -0
  377. package/data/problems/hand-of-straights.json +1 -0
  378. package/data/problems/happy-number.json +1 -0
  379. package/data/problems/heaters.json +1 -0
  380. package/data/problems/house-robber-ii.json +1 -0
  381. package/data/problems/house-robber-iii.json +1 -0
  382. package/data/problems/house-robber.json +1 -0
  383. package/data/problems/image-overlap.json +1 -0
  384. package/data/problems/image-smoother.json +1 -0
  385. package/data/problems/implement-magic-dictionary.json +1 -0
  386. package/data/problems/implement-queue-using-stacks.json +1 -0
  387. package/data/problems/implement-rand10-using-rand7.json +1 -0
  388. package/data/problems/implement-stack-using-queues.json +1 -0
  389. package/data/problems/implement-trie-prefix-tree.json +1 -0
  390. package/data/problems/increasing-order-search-tree.json +1 -0
  391. package/data/problems/increasing-triplet-subsequence.json +1 -0
  392. package/data/problems/inorder-successor-in-bst-ii.json +1 -0
  393. package/data/problems/inorder-successor-in-bst.json +1 -0
  394. package/data/problems/insert-delete-getrandom-o1-duplicates-allowed.json +1 -0
  395. package/data/problems/insert-delete-getrandom-o1.json +1 -0
  396. package/data/problems/insert-greatest-common-divisors-in-linked-list.json +1 -0
  397. package/data/problems/insert-interval.json +1 -0
  398. package/data/problems/insert-into-a-binary-search-tree.json +1 -0
  399. package/data/problems/insert-into-a-sorted-circular-linked-list.json +1 -0
  400. package/data/problems/insertion-sort-list.json +1 -0
  401. package/data/problems/integer-break.json +1 -0
  402. package/data/problems/integer-replacement.json +1 -0
  403. package/data/problems/integer-to-english-words.json +1 -0
  404. package/data/problems/integer-to-roman.json +1 -0
  405. package/data/problems/interleaving-string.json +1 -0
  406. package/data/problems/intersection-of-two-arrays-ii.json +1 -0
  407. package/data/problems/intersection-of-two-arrays.json +1 -0
  408. package/data/problems/intersection-of-two-linked-lists.json +1 -0
  409. package/data/problems/interval-list-intersections.json +1 -0
  410. package/data/problems/invert-binary-tree.json +1 -0
  411. package/data/problems/ip-to-cidr.json +1 -0
  412. package/data/problems/ipo.json +1 -0
  413. package/data/problems/is-graph-bipartite.json +1 -0
  414. package/data/problems/is-subsequence.json +1 -0
  415. package/data/problems/island-perimeter.json +1 -0
  416. package/data/problems/isomorphic-strings.json +1 -0
  417. package/data/problems/jewels-and-stones.json +1 -0
  418. package/data/problems/jump-game-ii.json +1 -0
  419. package/data/problems/jump-game-vii.json +1 -0
  420. package/data/problems/jump-game.json +1 -0
  421. package/data/problems/k-closest-points-to-origin.json +1 -0
  422. package/data/problems/k-diff-pairs-in-an-array.json +1 -0
  423. package/data/problems/k-empty-slots.json +1 -0
  424. package/data/problems/k-inverse-pairs-array.json +1 -0
  425. package/data/problems/k-similar-strings.json +1 -0
  426. package/data/problems/k-th-smallest-in-lexicographical-order.json +1 -0
  427. package/data/problems/k-th-smallest-prime-fraction.json +1 -0
  428. package/data/problems/k-th-symbol-in-grammar.json +1 -0
  429. package/data/problems/keyboard-row.json +1 -0
  430. package/data/problems/keys-and-rooms.json +1 -0
  431. package/data/problems/kill-process.json +1 -0
  432. package/data/problems/knight-dialer.json +1 -0
  433. package/data/problems/knight-probability-in-chessboard.json +1 -0
  434. package/data/problems/koko-eating-bananas.json +1 -0
  435. package/data/problems/kth-largest-element-in-a-stream.json +1 -0
  436. package/data/problems/kth-largest-element-in-an-array.json +1 -0
  437. package/data/problems/kth-smallest-element-in-a-bst.json +1 -0
  438. package/data/problems/kth-smallest-element-in-a-sorted-matrix.json +1 -0
  439. package/data/problems/kth-smallest-number-in-multiplication-table.json +1 -0
  440. package/data/problems/largest-bst-subtree.json +1 -0
  441. package/data/problems/largest-component-size-by-common-factor.json +1 -0
  442. package/data/problems/largest-divisible-subset.json +1 -0
  443. package/data/problems/largest-number-at-least-twice-of-others.json +1 -0
  444. package/data/problems/largest-number.json +1 -0
  445. package/data/problems/largest-palindrome-product.json +1 -0
  446. package/data/problems/largest-perimeter-triangle.json +1 -0
  447. package/data/problems/largest-plus-sign.json +1 -0
  448. package/data/problems/largest-rectangle-in-histogram.json +1 -0
  449. package/data/problems/largest-sum-of-averages.json +1 -0
  450. package/data/problems/largest-time-for-given-digits.json +1 -0
  451. package/data/problems/largest-triangle-area.json +1 -0
  452. package/data/problems/last-stone-weight-ii.json +1 -0
  453. package/data/problems/last-stone-weight.json +1 -0
  454. package/data/problems/leaf-similar-trees.json +1 -0
  455. package/data/problems/least-operators-to-express-number.json +1 -0
  456. package/data/problems/lemonade-change.json +1 -0
  457. package/data/problems/length-of-last-word.json +1 -0
  458. package/data/problems/length-of-longest-fibonacci-subsequence.json +1 -0
  459. package/data/problems/letter-case-permutation.json +1 -0
  460. package/data/problems/letter-combinations-of-a-phone-number.json +1 -0
  461. package/data/problems/lexicographical-numbers.json +1 -0
  462. package/data/problems/lfu-cache.json +1 -0
  463. package/data/problems/license-key-formatting.json +1 -0
  464. package/data/problems/line-reflection.json +1 -0
  465. package/data/problems/linked-list-components.json +1 -0
  466. package/data/problems/linked-list-cycle-ii.json +1 -0
  467. package/data/problems/linked-list-cycle.json +1 -0
  468. package/data/problems/linked-list-random-node.json +1 -0
  469. package/data/problems/logger-rate-limiter.json +1 -0
  470. package/data/problems/logical-or-of-two-binary-grids-represented-as-quad-trees.json +1 -0
  471. package/data/problems/lonely-pixel-i.json +1 -0
  472. package/data/problems/lonely-pixel-ii.json +1 -0
  473. package/data/problems/long-pressed-name.json +1 -0
  474. package/data/problems/longest-absolute-file-path.json +1 -0
  475. package/data/problems/longest-common-prefix.json +1 -0
  476. package/data/problems/longest-common-subsequence.json +1 -0
  477. package/data/problems/longest-consecutive-sequence.json +1 -0
  478. package/data/problems/longest-continuous-increasing-subsequence.json +1 -0
  479. package/data/problems/longest-happy-string.json +1 -0
  480. package/data/problems/longest-harmonious-subsequence.json +1 -0
  481. package/data/problems/longest-increasing-path-in-a-matrix.json +1 -0
  482. package/data/problems/longest-increasing-subsequence.json +1 -0
  483. package/data/problems/longest-line-of-consecutive-one-in-matrix.json +1 -0
  484. package/data/problems/longest-mountain-in-array.json +1 -0
  485. package/data/problems/longest-palindrome.json +1 -0
  486. package/data/problems/longest-palindromic-subsequence.json +1 -0
  487. package/data/problems/longest-palindromic-substring.json +1 -0
  488. package/data/problems/longest-repeating-character-replacement.json +1 -0
  489. package/data/problems/longest-substring-with-at-least-k-repeating-characters.json +1 -0
  490. package/data/problems/longest-substring-with-at-most-k-distinct-characters.json +1 -0
  491. package/data/problems/longest-substring-with-at-most-two-distinct-characters.json +1 -0
  492. package/data/problems/longest-substring-without-repeating-characters.json +1 -0
  493. package/data/problems/longest-turbulent-subarray.json +1 -0
  494. package/data/problems/longest-uncommon-subsequence-i.json +1 -0
  495. package/data/problems/longest-uncommon-subsequence-ii.json +1 -0
  496. package/data/problems/longest-univalue-path.json +1 -0
  497. package/data/problems/longest-valid-parentheses.json +1 -0
  498. package/data/problems/longest-word-in-dictionary-through-deleting.json +1 -0
  499. package/data/problems/longest-word-in-dictionary.json +1 -0
  500. package/data/problems/loud-and-rich.json +1 -0
  501. package/data/problems/lowest-common-ancestor-of-a-binary-search-tree.json +1 -0
  502. package/data/problems/lowest-common-ancestor-of-a-binary-tree.json +1 -0
  503. package/data/problems/lru-cache.json +1 -0
  504. package/data/problems/magic-squares-in-grid.json +1 -0
  505. package/data/problems/magical-string.json +1 -0
  506. package/data/problems/majority-element-ii.json +1 -0
  507. package/data/problems/majority-element.json +1 -0
  508. package/data/problems/making-a-large-island.json +1 -0
  509. package/data/problems/map-sum-pairs.json +1 -0
  510. package/data/problems/masking-personal-information.json +1 -0
  511. package/data/problems/matchsticks-to-square.json +1 -0
  512. package/data/problems/max-area-of-island.json +1 -0
  513. package/data/problems/max-chunks-to-make-sorted-ii.json +1 -0
  514. package/data/problems/max-chunks-to-make-sorted.json +1 -0
  515. package/data/problems/max-consecutive-ones-ii.json +1 -0
  516. package/data/problems/max-consecutive-ones.json +1 -0
  517. package/data/problems/max-increase-to-keep-city-skyline.json +1 -0
  518. package/data/problems/max-points-on-a-line.json +1 -0
  519. package/data/problems/max-stack.json +1 -0
  520. package/data/problems/max-sum-of-rectangle-no-larger-than-k.json +1 -0
  521. package/data/problems/maximal-rectangle.json +1 -0
  522. package/data/problems/maximal-square.json +1 -0
  523. package/data/problems/maximize-distance-to-closest-person.json +1 -0
  524. package/data/problems/maximum-average-subarray-i.json +1 -0
  525. package/data/problems/maximum-average-subarray-ii.json +1 -0
  526. package/data/problems/maximum-binary-tree-ii.json +1 -0
  527. package/data/problems/maximum-binary-tree.json +1 -0
  528. package/data/problems/maximum-depth-of-binary-tree.json +1 -0
  529. package/data/problems/maximum-depth-of-n-ary-tree.json +1 -0
  530. package/data/problems/maximum-distance-in-arrays.json +1 -0
  531. package/data/problems/maximum-frequency-stack.json +1 -0
  532. package/data/problems/maximum-gap.json +1 -0
  533. package/data/problems/maximum-length-of-pair-chain.json +1 -0
  534. package/data/problems/maximum-length-of-repeated-subarray.json +1 -0
  535. package/data/problems/maximum-product-of-three-numbers.json +1 -0
  536. package/data/problems/maximum-product-of-word-lengths.json +1 -0
  537. package/data/problems/maximum-product-subarray.json +1 -0
  538. package/data/problems/maximum-size-subarray-sum-equals-k.json +1 -0
  539. package/data/problems/maximum-subarray.json +1 -0
  540. package/data/problems/maximum-sum-circular-subarray.json +1 -0
  541. package/data/problems/maximum-sum-of-3-non-overlapping-subarrays.json +1 -0
  542. package/data/problems/maximum-swap.json +1 -0
  543. package/data/problems/maximum-vacation-days.json +1 -0
  544. package/data/problems/maximum-width-of-binary-tree.json +1 -0
  545. package/data/problems/maximum-width-ramp.json +1 -0
  546. package/data/problems/maximum-xor-of-two-numbers-in-an-array.json +1 -0
  547. package/data/problems/median-of-two-sorted-arrays.json +1 -0
  548. package/data/problems/meeting-rooms-ii.json +1 -0
  549. package/data/problems/meeting-rooms-iii.json +1 -0
  550. package/data/problems/meeting-rooms.json +1 -0
  551. package/data/problems/merge-intervals.json +1 -0
  552. package/data/problems/merge-k-sorted-lists.json +1 -0
  553. package/data/problems/merge-sorted-array.json +1 -0
  554. package/data/problems/merge-strings-alternately.json +1 -0
  555. package/data/problems/merge-triplets-to-form-target-triplet.json +1 -0
  556. package/data/problems/merge-two-binary-trees.json +1 -0
  557. package/data/problems/merge-two-sorted-lists.json +1 -0
  558. package/data/problems/middle-of-the-linked-list.json +1 -0
  559. package/data/problems/min-cost-climbing-stairs.json +1 -0
  560. package/data/problems/min-cost-to-connect-all-points.json +1 -0
  561. package/data/problems/min-stack.json +1 -0
  562. package/data/problems/minesweeper.json +1 -0
  563. package/data/problems/mini-parser.json +1 -0
  564. package/data/problems/minimize-malware-spread-ii.json +1 -0
  565. package/data/problems/minimize-malware-spread.json +1 -0
  566. package/data/problems/minimize-max-distance-to-gas-station.json +1 -0
  567. package/data/problems/minimum-absolute-difference-in-bst.json +1 -0
  568. package/data/problems/minimum-add-to-make-parentheses-valid.json +1 -0
  569. package/data/problems/minimum-area-rectangle-ii.json +1 -0
  570. package/data/problems/minimum-area-rectangle.json +1 -0
  571. package/data/problems/minimum-array-end.json +1 -0
  572. package/data/problems/minimum-ascii-delete-sum-for-two-strings.json +1 -0
  573. package/data/problems/minimum-cost-for-tickets.json +1 -0
  574. package/data/problems/minimum-cost-to-hire-k-workers.json +1 -0
  575. package/data/problems/minimum-cost-to-merge-stones.json +1 -0
  576. package/data/problems/minimum-depth-of-binary-tree.json +1 -0
  577. package/data/problems/minimum-distance-between-bst-nodes.json +1 -0
  578. package/data/problems/minimum-factorization.json +1 -0
  579. package/data/problems/minimum-falling-path-sum.json +1 -0
  580. package/data/problems/minimum-genetic-mutation.json +1 -0
  581. package/data/problems/minimum-height-trees.json +1 -0
  582. package/data/problems/minimum-increment-to-make-array-unique.json +1 -0
  583. package/data/problems/minimum-index-sum-of-two-lists.json +1 -0
  584. package/data/problems/minimum-interval-to-include-each-query.json +1 -0
  585. package/data/problems/minimum-moves-to-equal-array-elements-ii.json +1 -0
  586. package/data/problems/minimum-moves-to-equal-array-elements.json +1 -0
  587. package/data/problems/minimum-number-of-arrows-to-burst-balloons.json +1 -0
  588. package/data/problems/minimum-number-of-k-consecutive-bit-flips.json +1 -0
  589. package/data/problems/minimum-number-of-refueling-stops.json +1 -0
  590. package/data/problems/minimum-path-sum.json +1 -0
  591. package/data/problems/minimum-size-subarray-sum.json +1 -0
  592. package/data/problems/minimum-swaps-to-make-sequences-increasing.json +1 -0
  593. package/data/problems/minimum-time-difference.json +1 -0
  594. package/data/problems/minimum-unique-word-abbreviation.json +1 -0
  595. package/data/problems/minimum-window-subsequence.json +1 -0
  596. package/data/problems/minimum-window-substring.json +1 -0
  597. package/data/problems/mirror-reflection.json +1 -0
  598. package/data/problems/missing-number.json +1 -0
  599. package/data/problems/missing-ranges.json +1 -0
  600. package/data/problems/monotone-increasing-digits.json +1 -0
  601. package/data/problems/monotonic-array.json +1 -0
  602. package/data/problems/most-common-word.json +1 -0
  603. package/data/problems/most-frequent-subtree-sum.json +1 -0
  604. package/data/problems/most-profit-assigning-work.json +1 -0
  605. package/data/problems/most-stones-removed-with-same-row-or-column.json +1 -0
  606. package/data/problems/move-zeroes.json +1 -0
  607. package/data/problems/moving-average-from-data-stream.json +1 -0
  608. package/data/problems/multiply-strings.json +1 -0
  609. package/data/problems/my-calendar-i.json +1 -0
  610. package/data/problems/my-calendar-ii.json +1 -0
  611. package/data/problems/my-calendar-iii.json +1 -0
  612. package/data/problems/n-ary-tree-level-order-traversal.json +1 -0
  613. package/data/problems/n-ary-tree-postorder-traversal.json +1 -0
  614. package/data/problems/n-ary-tree-preorder-traversal.json +1 -0
  615. package/data/problems/n-queens-ii.json +1 -0
  616. package/data/problems/n-queens.json +1 -0
  617. package/data/problems/n-repeated-element-in-size-2n-array.json +1 -0
  618. package/data/problems/n-th-tribonacci-number.json +1 -0
  619. package/data/problems/nested-list-weight-sum-ii.json +1 -0
  620. package/data/problems/nested-list-weight-sum.json +1 -0
  621. package/data/problems/network-delay-time.json +1 -0
  622. package/data/problems/new-21-game.json +1 -0
  623. package/data/problems/next-closest-time.json +1 -0
  624. package/data/problems/next-greater-element-i.json +1 -0
  625. package/data/problems/next-greater-element-ii.json +1 -0
  626. package/data/problems/next-greater-element-iii.json +1 -0
  627. package/data/problems/next-permutation.json +1 -0
  628. package/data/problems/nim-game.json +1 -0
  629. package/data/problems/non-decreasing-array.json +1 -0
  630. package/data/problems/non-decreasing-subsequences.json +1 -0
  631. package/data/problems/non-negative-integers-without-consecutive-ones.json +1 -0
  632. package/data/problems/non-overlapping-intervals.json +1 -0
  633. package/data/problems/nth-digit.json +1 -0
  634. package/data/problems/nth-magical-number.json +1 -0
  635. package/data/problems/number-complement.json +1 -0
  636. package/data/problems/number-of-1-bits.json +1 -0
  637. package/data/problems/number-of-atoms.json +1 -0
  638. package/data/problems/number-of-boomerangs.json +1 -0
  639. package/data/problems/number-of-connected-components-in-an-undirected-graph.json +1 -0
  640. package/data/problems/number-of-corner-rectangles.json +1 -0
  641. package/data/problems/number-of-digit-one.json +1 -0
  642. package/data/problems/number-of-distinct-islands-ii.json +1 -0
  643. package/data/problems/number-of-distinct-islands.json +1 -0
  644. package/data/problems/number-of-islands-ii.json +1 -0
  645. package/data/problems/number-of-islands.json +1 -0
  646. package/data/problems/number-of-lines-to-write-string.json +1 -0
  647. package/data/problems/number-of-longest-increasing-subsequence.json +1 -0
  648. package/data/problems/number-of-matching-subsequences.json +1 -0
  649. package/data/problems/number-of-music-playlists.json +1 -0
  650. package/data/problems/number-of-provinces.json +1 -0
  651. package/data/problems/number-of-recent-calls.json +1 -0
  652. package/data/problems/number-of-segments-in-a-string.json +1 -0
  653. package/data/problems/number-of-squareful-arrays.json +1 -0
  654. package/data/problems/number-of-subarrays-with-bounded-maximum.json +1 -0
  655. package/data/problems/numbers-at-most-n-given-digit-set.json +1 -0
  656. package/data/problems/numbers-with-same-consecutive-differences.json +1 -0
  657. package/data/problems/odd-even-jump.json +1 -0
  658. package/data/problems/odd-even-linked-list.json +1 -0
  659. package/data/problems/one-edit-distance.json +1 -0
  660. package/data/problems/ones-and-zeroes.json +1 -0
  661. package/data/problems/online-election.json +1 -0
  662. package/data/problems/online-stock-span.json +1 -0
  663. package/data/problems/open-the-lock.json +1 -0
  664. package/data/problems/optimal-account-balancing.json +1 -0
  665. package/data/problems/optimal-division.json +1 -0
  666. package/data/problems/orderly-queue.json +1 -0
  667. package/data/problems/out-of-boundary-paths.json +1 -0
  668. package/data/problems/output-contest-matches.json +1 -0
  669. package/data/problems/pacific-atlantic-water-flow.json +1 -0
  670. package/data/problems/paint-fence.json +1 -0
  671. package/data/problems/paint-house-ii.json +1 -0
  672. package/data/problems/paint-house.json +1 -0
  673. package/data/problems/palindrome-linked-list.json +1 -0
  674. package/data/problems/palindrome-number.json +1 -0
  675. package/data/problems/palindrome-pairs.json +1 -0
  676. package/data/problems/palindrome-partitioning-ii.json +1 -0
  677. package/data/problems/palindrome-partitioning.json +1 -0
  678. package/data/problems/palindrome-permutation-ii.json +1 -0
  679. package/data/problems/palindrome-permutation.json +1 -0
  680. package/data/problems/palindromic-substrings.json +1 -0
  681. package/data/problems/pancake-sorting.json +1 -0
  682. package/data/problems/parse-lisp-expression.json +1 -0
  683. package/data/problems/partition-array-into-disjoint-intervals.json +1 -0
  684. package/data/problems/partition-equal-subset-sum.json +1 -0
  685. package/data/problems/partition-labels.json +1 -0
  686. package/data/problems/partition-list.json +1 -0
  687. package/data/problems/partition-to-k-equal-sum-subsets.json +1 -0
  688. package/data/problems/pascals-triangle-ii.json +1 -0
  689. package/data/problems/pascals-triangle.json +1 -0
  690. package/data/problems/patching-array.json +1 -0
  691. package/data/problems/path-sum-ii.json +1 -0
  692. package/data/problems/path-sum-iii.json +1 -0
  693. package/data/problems/path-sum-iv.json +1 -0
  694. package/data/problems/path-sum.json +1 -0
  695. package/data/problems/path-with-minimum-effort.json +1 -0
  696. package/data/problems/peak-index-in-a-mountain-array.json +1 -0
  697. package/data/problems/peeking-iterator.json +1 -0
  698. package/data/problems/perfect-number.json +1 -0
  699. package/data/problems/perfect-rectangle.json +1 -0
  700. package/data/problems/perfect-squares.json +1 -0
  701. package/data/problems/permutation-in-string.json +1 -0
  702. package/data/problems/permutation-sequence.json +1 -0
  703. package/data/problems/permutations-ii.json +1 -0
  704. package/data/problems/permutations.json +1 -0
  705. package/data/problems/plus-one-linked-list.json +1 -0
  706. package/data/problems/plus-one.json +1 -0
  707. package/data/problems/poor-pigs.json +1 -0
  708. package/data/problems/populating-next-right-pointers-in-each-node-ii.json +1 -0
  709. package/data/problems/populating-next-right-pointers-in-each-node.json +1 -0
  710. package/data/problems/positions-of-large-groups.json +1 -0
  711. package/data/problems/possible-bipartition.json +1 -0
  712. package/data/problems/pour-water.json +1 -0
  713. package/data/problems/power-of-four.json +1 -0
  714. package/data/problems/power-of-three.json +1 -0
  715. package/data/problems/power-of-two.json +1 -0
  716. package/data/problems/powerful-integers.json +1 -0
  717. package/data/problems/powx-n.json +1 -0
  718. package/data/problems/predict-the-winner.json +1 -0
  719. package/data/problems/prefix-and-suffix-search.json +1 -0
  720. package/data/problems/preimage-size-of-factorial-zeroes-function.json +1 -0
  721. package/data/problems/prime-number-of-set-bits-in-binary-representation.json +1 -0
  722. package/data/problems/prime-palindrome.json +1 -0
  723. package/data/problems/print-binary-tree.json +1 -0
  724. package/data/problems/prison-cells-after-n-days.json +1 -0
  725. package/data/problems/product-of-array-except-self.json +1 -0
  726. package/data/problems/profitable-schemes.json +1 -0
  727. package/data/problems/projection-area-of-3d-shapes.json +1 -0
  728. package/data/problems/push-dominoes.json +1 -0
  729. package/data/problems/pyramid-transition-matrix.json +1 -0
  730. package/data/problems/queue-reconstruction-by-height.json +1 -0
  731. package/data/problems/rabbits-in-forest.json +1 -0
  732. package/data/problems/race-car.json +1 -0
  733. package/data/problems/random-flip-matrix.json +1 -0
  734. package/data/problems/random-pick-index.json +1 -0
  735. package/data/problems/random-pick-with-blacklist.json +1 -0
  736. package/data/problems/random-pick-with-weight.json +1 -0
  737. package/data/problems/random-point-in-non-overlapping-rectangles.json +1 -0
  738. package/data/problems/range-addition-ii.json +1 -0
  739. package/data/problems/range-addition.json +1 -0
  740. package/data/problems/range-module.json +1 -0
  741. package/data/problems/range-sum-of-bst.json +1 -0
  742. package/data/problems/range-sum-query-2d-immutable.json +1 -0
  743. package/data/problems/range-sum-query-2d-mutable.json +1 -0
  744. package/data/problems/range-sum-query-immutable.json +1 -0
  745. package/data/problems/range-sum-query-mutable.json +1 -0
  746. package/data/problems/ransom-note.json +1 -0
  747. package/data/problems/reach-a-number.json +1 -0
  748. package/data/problems/reachable-nodes-in-subdivided-graph.json +1 -0
  749. package/data/problems/reaching-points.json +1 -0
  750. package/data/problems/read-n-characters-given-read4-ii-call-multiple-times.json +1 -0
  751. package/data/problems/read-n-characters-given-read4.json +1 -0
  752. package/data/problems/rearrange-string-k-distance-apart.json +1 -0
  753. package/data/problems/reconstruct-itinerary.json +1 -0
  754. package/data/problems/reconstruct-original-digits-from-english.json +1 -0
  755. package/data/problems/recover-binary-search-tree.json +1 -0
  756. package/data/problems/rectangle-area-ii.json +1 -0
  757. package/data/problems/rectangle-area.json +1 -0
  758. package/data/problems/rectangle-overlap.json +1 -0
  759. package/data/problems/redundant-connection-ii.json +1 -0
  760. package/data/problems/redundant-connection.json +1 -0
  761. package/data/problems/regions-cut-by-slashes.json +1 -0
  762. package/data/problems/regular-expression-matching.json +1 -0
  763. package/data/problems/relative-ranks.json +1 -0
  764. package/data/problems/remove-9.json +1 -0
  765. package/data/problems/remove-boxes.json +1 -0
  766. package/data/problems/remove-comments.json +1 -0
  767. package/data/problems/remove-duplicate-letters.json +1 -0
  768. package/data/problems/remove-duplicates-from-sorted-array-ii.json +1 -0
  769. package/data/problems/remove-duplicates-from-sorted-array.json +1 -0
  770. package/data/problems/remove-duplicates-from-sorted-list-ii.json +1 -0
  771. package/data/problems/remove-duplicates-from-sorted-list.json +1 -0
  772. package/data/problems/remove-element.json +1 -0
  773. package/data/problems/remove-invalid-parentheses.json +1 -0
  774. package/data/problems/remove-k-digits.json +1 -0
  775. package/data/problems/remove-linked-list-elements.json +1 -0
  776. package/data/problems/remove-nth-node-from-end-of-list.json +1 -0
  777. package/data/problems/reorder-data-in-log-files.json +1 -0
  778. package/data/problems/reorder-list.json +1 -0
  779. package/data/problems/reordered-power-of-2.json +1 -0
  780. package/data/problems/reorganize-string.json +1 -0
  781. package/data/problems/repeated-dna-sequences.json +1 -0
  782. package/data/problems/repeated-string-match.json +1 -0
  783. package/data/problems/repeated-substring-pattern.json +1 -0
  784. package/data/problems/replace-words.json +1 -0
  785. package/data/problems/reshape-the-matrix.json +1 -0
  786. package/data/problems/restore-ip-addresses.json +1 -0
  787. package/data/problems/reveal-cards-in-increasing-order.json +1 -0
  788. package/data/problems/reverse-bits.json +1 -0
  789. package/data/problems/reverse-integer.json +1 -0
  790. package/data/problems/reverse-linked-list-ii.json +1 -0
  791. package/data/problems/reverse-linked-list.json +1 -0
  792. package/data/problems/reverse-nodes-in-k-group.json +1 -0
  793. package/data/problems/reverse-only-letters.json +1 -0
  794. package/data/problems/reverse-pairs.json +1 -0
  795. package/data/problems/reverse-string-ii.json +1 -0
  796. package/data/problems/reverse-string.json +1 -0
  797. package/data/problems/reverse-vowels-of-a-string.json +1 -0
  798. package/data/problems/reverse-words-in-a-string-ii.json +1 -0
  799. package/data/problems/reverse-words-in-a-string-iii.json +1 -0
  800. package/data/problems/reverse-words-in-a-string.json +1 -0
  801. package/data/problems/rle-iterator.json +1 -0
  802. package/data/problems/robot-return-to-origin.json +1 -0
  803. package/data/problems/robot-room-cleaner.json +1 -0
  804. package/data/problems/roman-to-integer.json +1 -0
  805. package/data/problems/rotate-array.json +1 -0
  806. package/data/problems/rotate-function.json +1 -0
  807. package/data/problems/rotate-image.json +1 -0
  808. package/data/problems/rotate-list.json +1 -0
  809. package/data/problems/rotate-string.json +1 -0
  810. package/data/problems/rotated-digits.json +1 -0
  811. package/data/problems/rotting-oranges.json +1 -0
  812. package/data/problems/russian-doll-envelopes.json +1 -0
  813. package/data/problems/same-tree.json +1 -0
  814. package/data/problems/satisfiability-of-equality-equations.json +1 -0
  815. package/data/problems/score-after-flipping-matrix.json +1 -0
  816. package/data/problems/score-of-parentheses.json +1 -0
  817. package/data/problems/scramble-string.json +1 -0
  818. package/data/problems/search-a-2d-matrix-ii.json +1 -0
  819. package/data/problems/search-a-2d-matrix.json +1 -0
  820. package/data/problems/search-in-a-binary-search-tree.json +1 -0
  821. package/data/problems/search-in-a-sorted-array-of-unknown-size.json +1 -0
  822. package/data/problems/search-in-rotated-sorted-array-ii.json +1 -0
  823. package/data/problems/search-in-rotated-sorted-array.json +1 -0
  824. package/data/problems/search-insert-position.json +1 -0
  825. package/data/problems/second-minimum-node-in-a-binary-tree.json +1 -0
  826. package/data/problems/self-crossing.json +1 -0
  827. package/data/problems/self-dividing-numbers.json +1 -0
  828. package/data/problems/sentence-screen-fitting.json +1 -0
  829. package/data/problems/sentence-similarity-ii.json +1 -0
  830. package/data/problems/sentence-similarity.json +1 -0
  831. package/data/problems/sequence-reconstruction.json +1 -0
  832. package/data/problems/serialize-and-deserialize-binary-tree.json +1 -0
  833. package/data/problems/serialize-and-deserialize-bst.json +1 -0
  834. package/data/problems/serialize-and-deserialize-n-ary-tree.json +1 -0
  835. package/data/problems/set-intersection-size-at-least-two.json +1 -0
  836. package/data/problems/set-matrix-zeroes.json +1 -0
  837. package/data/problems/set-mismatch.json +1 -0
  838. package/data/problems/shifting-letters.json +1 -0
  839. package/data/problems/shopping-offers.json +1 -0
  840. package/data/problems/short-encoding-of-words.json +1 -0
  841. package/data/problems/shortest-bridge.json +1 -0
  842. package/data/problems/shortest-completing-word.json +1 -0
  843. package/data/problems/shortest-distance-from-all-buildings.json +1 -0
  844. package/data/problems/shortest-distance-to-a-character.json +1 -0
  845. package/data/problems/shortest-palindrome.json +1 -0
  846. package/data/problems/shortest-path-to-get-all-keys.json +1 -0
  847. package/data/problems/shortest-path-visiting-all-nodes.json +1 -0
  848. package/data/problems/shortest-subarray-with-sum-at-least-k.json +1 -0
  849. package/data/problems/shortest-unsorted-continuous-subarray.json +1 -0
  850. package/data/problems/shortest-word-distance-ii.json +1 -0
  851. package/data/problems/shortest-word-distance-iii.json +1 -0
  852. package/data/problems/shortest-word-distance.json +1 -0
  853. package/data/problems/shuffle-an-array.json +1 -0
  854. package/data/problems/similar-rgb-color.json +1 -0
  855. package/data/problems/similar-string-groups.json +1 -0
  856. package/data/problems/simplify-path.json +1 -0
  857. package/data/problems/single-element-in-a-sorted-array.json +1 -0
  858. package/data/problems/single-number-ii.json +1 -0
  859. package/data/problems/single-number-iii.json +1 -0
  860. package/data/problems/single-number.json +1 -0
  861. package/data/problems/single-threaded-cpu.json +1 -0
  862. package/data/problems/sliding-puzzle.json +1 -0
  863. package/data/problems/sliding-window-maximum.json +1 -0
  864. package/data/problems/sliding-window-median.json +1 -0
  865. package/data/problems/smallest-good-base.json +1 -0
  866. package/data/problems/smallest-range-covering-elements-from-k-lists.json +1 -0
  867. package/data/problems/smallest-range-i.json +1 -0
  868. package/data/problems/smallest-range-ii.json +1 -0
  869. package/data/problems/smallest-rectangle-enclosing-black-pixels.json +1 -0
  870. package/data/problems/smallest-rotation-with-highest-score.json +1 -0
  871. package/data/problems/smallest-string-starting-from-leaf.json +1 -0
  872. package/data/problems/smallest-subtree-with-all-the-deepest-nodes.json +1 -0
  873. package/data/problems/snakes-and-ladders.json +1 -0
  874. package/data/problems/solve-the-equation.json +1 -0
  875. package/data/problems/sort-an-array.json +1 -0
  876. package/data/problems/sort-array-by-parity-ii.json +1 -0
  877. package/data/problems/sort-array-by-parity.json +1 -0
  878. package/data/problems/sort-characters-by-frequency.json +1 -0
  879. package/data/problems/sort-colors.json +1 -0
  880. package/data/problems/sort-list.json +1 -0
  881. package/data/problems/sort-transformed-array.json +1 -0
  882. package/data/problems/soup-servings.json +1 -0
  883. package/data/problems/sparse-matrix-multiplication.json +1 -0
  884. package/data/problems/special-binary-string.json +1 -0
  885. package/data/problems/spiral-matrix-ii.json +1 -0
  886. package/data/problems/spiral-matrix-iii.json +1 -0
  887. package/data/problems/spiral-matrix.json +1 -0
  888. package/data/problems/split-array-into-consecutive-subsequences.json +1 -0
  889. package/data/problems/split-array-into-fibonacci-sequence.json +1 -0
  890. package/data/problems/split-array-largest-sum.json +1 -0
  891. package/data/problems/split-array-with-equal-sum.json +1 -0
  892. package/data/problems/split-array-with-same-average.json +1 -0
  893. package/data/problems/split-bst.json +1 -0
  894. package/data/problems/split-concatenated-strings.json +1 -0
  895. package/data/problems/split-linked-list-in-parts.json +1 -0
  896. package/data/problems/sqrtx.json +1 -0
  897. package/data/problems/squares-of-a-sorted-array.json +1 -0
  898. package/data/problems/squirrel-simulation.json +1 -0
  899. package/data/problems/stamping-the-sequence.json +1 -0
  900. package/data/problems/stickers-to-spell-word.json +1 -0
  901. package/data/problems/stone-game-ii.json +1 -0
  902. package/data/problems/stone-game-iii.json +1 -0
  903. package/data/problems/stone-game.json +1 -0
  904. package/data/problems/strange-printer.json +1 -0
  905. package/data/problems/string-compression.json +1 -0
  906. package/data/problems/string-to-integer-atoi.json +1 -0
  907. package/data/problems/string-without-aaa-or-bbb.json +1 -0
  908. package/data/problems/strobogrammatic-number-ii.json +1 -0
  909. package/data/problems/strobogrammatic-number-iii.json +1 -0
  910. package/data/problems/strobogrammatic-number.json +1 -0
  911. package/data/problems/strong-password-checker.json +1 -0
  912. package/data/problems/student-attendance-record-i.json +1 -0
  913. package/data/problems/student-attendance-record-ii.json +1 -0
  914. package/data/problems/subarray-product-less-than-k.json +1 -0
  915. package/data/problems/subarray-sum-equals-k.json +1 -0
  916. package/data/problems/subarray-sums-divisible-by-k.json +1 -0
  917. package/data/problems/subarrays-with-k-different-integers.json +1 -0
  918. package/data/problems/subdomain-visit-count.json +1 -0
  919. package/data/problems/subsets-ii.json +1 -0
  920. package/data/problems/subsets.json +1 -0
  921. package/data/problems/substring-with-concatenation-of-all-words.json +1 -0
  922. package/data/problems/subtree-of-another-tree.json +1 -0
  923. package/data/problems/sudoku-solver.json +1 -0
  924. package/data/problems/sum-of-all-subset-xor-totals.json +1 -0
  925. package/data/problems/sum-of-distances-in-tree.json +1 -0
  926. package/data/problems/sum-of-even-numbers-after-queries.json +1 -0
  927. package/data/problems/sum-of-left-leaves.json +1 -0
  928. package/data/problems/sum-of-square-numbers.json +1 -0
  929. package/data/problems/sum-of-subarray-minimums.json +1 -0
  930. package/data/problems/sum-of-subsequence-widths.json +1 -0
  931. package/data/problems/sum-of-two-integers.json +1 -0
  932. package/data/problems/sum-root-to-leaf-numbers.json +1 -0
  933. package/data/problems/summary-ranges.json +1 -0
  934. package/data/problems/super-egg-drop.json +1 -0
  935. package/data/problems/super-palindromes.json +1 -0
  936. package/data/problems/super-pow.json +1 -0
  937. package/data/problems/super-ugly-number.json +1 -0
  938. package/data/problems/super-washing-machines.json +1 -0
  939. package/data/problems/surface-area-of-3d-shapes.json +1 -0
  940. package/data/problems/surrounded-regions.json +1 -0
  941. package/data/problems/swap-adjacent-in-lr-string.json +1 -0
  942. package/data/problems/swap-nodes-in-pairs.json +1 -0
  943. package/data/problems/swim-in-rising-water.json +1 -0
  944. package/data/problems/symmetric-tree.json +1 -0
  945. package/data/problems/tag-validator.json +1 -0
  946. package/data/problems/tallest-billboard.json +1 -0
  947. package/data/problems/target-sum.json +1 -0
  948. package/data/problems/task-scheduler.json +1 -0
  949. package/data/problems/teemo-attacking.json +1 -0
  950. package/data/problems/ternary-expression-parser.json +1 -0
  951. package/data/problems/text-justification.json +1 -0
  952. package/data/problems/the-maze-ii.json +1 -0
  953. package/data/problems/the-maze-iii.json +1 -0
  954. package/data/problems/the-maze.json +1 -0
  955. package/data/problems/the-skyline-problem.json +1 -0
  956. package/data/problems/third-maximum-number.json +1 -0
  957. package/data/problems/three-equal-parts.json +1 -0
  958. package/data/problems/time-based-key-value-store.json +1 -0
  959. package/data/problems/to-lower-case.json +1 -0
  960. package/data/problems/toeplitz-matrix.json +1 -0
  961. package/data/problems/top-k-frequent-elements.json +1 -0
  962. package/data/problems/top-k-frequent-words.json +1 -0
  963. package/data/problems/total-hamming-distance.json +1 -0
  964. package/data/problems/transform-to-chessboard.json +1 -0
  965. package/data/problems/transpose-matrix.json +1 -0
  966. package/data/problems/trapping-rain-water-ii.json +1 -0
  967. package/data/problems/trapping-rain-water.json +1 -0
  968. package/data/problems/triangle.json +1 -0
  969. package/data/problems/trim-a-binary-search-tree.json +1 -0
  970. package/data/problems/triples-with-bitwise-and-equal-to-zero.json +1 -0
  971. package/data/problems/two-sum-ii-input-array-is-sorted.json +1 -0
  972. package/data/problems/two-sum-iii-data-structure-design.json +1 -0
  973. package/data/problems/two-sum-iv-input-is-a-bst.json +1 -0
  974. package/data/problems/two-sum.json +1 -0
  975. package/data/problems/ugly-number-ii.json +1 -0
  976. package/data/problems/ugly-number.json +1 -0
  977. package/data/problems/uncommon-words-from-two-sentences.json +1 -0
  978. package/data/problems/unique-binary-search-trees-ii.json +1 -0
  979. package/data/problems/unique-binary-search-trees.json +1 -0
  980. package/data/problems/unique-email-addresses.json +1 -0
  981. package/data/problems/unique-morse-code-words.json +1 -0
  982. package/data/problems/unique-paths-ii.json +1 -0
  983. package/data/problems/unique-paths-iii.json +1 -0
  984. package/data/problems/unique-paths.json +1 -0
  985. package/data/problems/unique-substrings-in-wraparound-string.json +1 -0
  986. package/data/problems/unique-word-abbreviation.json +1 -0
  987. package/data/problems/univalued-binary-tree.json +1 -0
  988. package/data/problems/utf-8-validation.json +1 -0
  989. package/data/problems/valid-anagram.json +1 -0
  990. package/data/problems/valid-mountain-array.json +1 -0
  991. package/data/problems/valid-number.json +1 -0
  992. package/data/problems/valid-palindrome-ii.json +1 -0
  993. package/data/problems/valid-palindrome.json +1 -0
  994. package/data/problems/valid-parentheses.json +1 -0
  995. package/data/problems/valid-parenthesis-string.json +1 -0
  996. package/data/problems/valid-perfect-square.json +1 -0
  997. package/data/problems/valid-permutations-for-di-sequence.json +1 -0
  998. package/data/problems/valid-square.json +1 -0
  999. package/data/problems/valid-sudoku.json +1 -0
  1000. package/data/problems/valid-tic-tac-toe-state.json +1 -0
  1001. package/data/problems/valid-triangle-number.json +1 -0
  1002. package/data/problems/valid-word-abbreviation.json +1 -0
  1003. package/data/problems/valid-word-square.json +1 -0
  1004. package/data/problems/validate-binary-search-tree.json +1 -0
  1005. package/data/problems/validate-ip-address.json +1 -0
  1006. package/data/problems/validate-stack-sequences.json +1 -0
  1007. package/data/problems/verify-preorder-sequence-in-binary-search-tree.json +1 -0
  1008. package/data/problems/verify-preorder-serialization-of-a-binary-tree.json +1 -0
  1009. package/data/problems/verifying-an-alien-dictionary.json +1 -0
  1010. package/data/problems/vertical-order-traversal-of-a-binary-tree.json +1 -0
  1011. package/data/problems/vowel-spellchecker.json +1 -0
  1012. package/data/problems/walking-robot-simulation.json +1 -0
  1013. package/data/problems/walls-and-gates.json +1 -0
  1014. package/data/problems/water-and-jug-problem.json +1 -0
  1015. package/data/problems/wiggle-sort-ii.json +1 -0
  1016. package/data/problems/wiggle-sort.json +1 -0
  1017. package/data/problems/wiggle-subsequence.json +1 -0
  1018. package/data/problems/wildcard-matching.json +1 -0
  1019. package/data/problems/word-abbreviation.json +1 -0
  1020. package/data/problems/word-break-ii.json +1 -0
  1021. package/data/problems/word-break.json +1 -0
  1022. package/data/problems/word-ladder-ii.json +1 -0
  1023. package/data/problems/word-ladder.json +1 -0
  1024. package/data/problems/word-pattern-ii.json +1 -0
  1025. package/data/problems/word-pattern.json +1 -0
  1026. package/data/problems/word-search-ii.json +1 -0
  1027. package/data/problems/word-search.json +1 -0
  1028. package/data/problems/word-squares.json +1 -0
  1029. package/data/problems/word-subsets.json +1 -0
  1030. package/data/problems/x-of-a-kind-in-a-deck-of-cards.json +1 -0
  1031. package/data/problems/zigzag-conversion.json +1 -0
  1032. package/data/problems/zigzag-iterator.json +1 -0
  1033. package/data/problems/zuma-game.json +1 -0
  1034. package/dist/cli.js +793 -0
  1035. package/dist/web/assets/index-7tyR3Zsa.js +147 -0
  1036. package/dist/web/assets/index-oer4U46K.css +1 -0
  1037. package/dist/web/index.html +13 -0
  1038. package/package.json +42 -3
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "658", "slug": "exclusive-time-of-functions", "id": 658, "title": "Exclusive Time of Functions", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/exclusive-time-of-functions/", "examples": [{"input": "n = 2, logs = [\"0:start:0\",\"1:start:2\",\"1:end:5\",\"0:end:6\"]", "output": "[3,4]", "explanation": "Function 0 runs during [0,1] and [6,6] (3 units); function 1 runs during [2,5] (4 units)."}, {"input": "n = 1, logs = [\"0:start:0\",\"0:start:2\",\"0:end:5\",\"0:start:6\",\"0:end:6\",\"0:end:7\"]", "output": "[8]", "explanation": "Nested and sequential self-calls merge to 8 units over [0,7]."}, {"input": "n = 2, logs = [\"0:start:0\",\"0:end:0\",\"1:start:1\",\"1:end:1\"]", "output": "[1,1]"}], "hints": ["Push each started function onto a stack and remember the timestamp of the previous log.", "On a start event, credit the gap since the previous stamp to the function on top, then push the new id.", "On an end event, credit the inclusive gap (stamp - previous + 1) to the popped id and move the cursor past the stamp."], "statement": "You are given `n` single-threaded functions labeled `0` through `n - 1`, plus a log list describing when each function starts and ends. Every entry looks like `\"id:start|end:timestamp\"` with an integer timestamp, for example `\"0:start:0\"`. Exactly one function runs at any moment; a running function pauses while a nested function executes.\n\nFor every function, add up only the time slices during which that function itself is on top of the call stack. An `end` stamp covers the whole time unit, so a call from `2` to `5` occupies 4 units (`5 - 2 + 1`).\n\nImplement `exclusiveTime(n, logs)` returning an array where position `i` holds the exclusive total for function `i`. Logs arrive in timestamp order and always form valid nesting.\n\n**Constraints:**\n- `1 <= n <= 100`\n- `1 <= logs.length <= 500`\n- Each log is `\"id:start|end:timestamp\"`, `0 <= id < n`, `0 <= timestamp <= 10^9`.\n- Logs are sorted by timestamp and describe properly nested, non-crossing calls.\n", "solution": "## Approach\n\nReplay the log stream with a stack of active function ids and a cursor marking the last processed timestamp. A start event first bills the idle gap to the function on top of the stack, then pushes the new call. An end event bills the inclusive span to the popped call and advances the cursor past that stamp, which naturally pauses outer frames while inner ones run.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(L), where L is the number of log entries.\n- **Space Complexity:** O(D) for the nesting stack of depth D.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:\n res = [0] * n\n st = []\n prev = 0\n for log in logs:\n sid, typ, ts = log.split(\":\")\n i, t = int(sid), int(ts)\n if typ == \"start\":\n if st:\n res[st[-1]] += t - prev\n st.append(i)\n prev = t\n else:\n res[st.pop()] += t - prev + 1\n prev = t + 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc ExclusiveTime(n int, logs []string) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def exclusiveTime(self, n: int, logs: List[str]) -> List[int]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> exclusiveTime(int n, vector<string>& logs) {\n return {};\n }\n};"}, "fn": "exclusiveTime", "params": [{"name": "n", "type": "int"}, {"name": "logs", "type": "string_array"}], "outputType": "int_array", "tests": [["2", "[\"0:start:0\", \"1:start:2\", \"1:end:5\", \"0:end:6\"]"], ["1", "[\"0:start:0\", \"0:start:2\", \"0:end:5\", \"0:start:6\", \"0:end:6\", \"0:end:7\"]"], ["2", "[\"0:start:0\", \"0:end:0\", \"1:start:1\", \"1:end:1\"]"], ["1", "[\"0:start:0\", \"0:end:0\"]"], ["2", "[\"0:start:0\", \"0:start:2\", \"0:end:5\", \"1:start:6\", \"1:end:6\", \"0:end:7\"]"], ["3", "[\"0:start:0\", \"1:start:1\", \"2:start:2\", \"2:end:3\", \"1:end:4\", \"0:end:5\"]"], ["2", "[\"0:start:0\", \"1:start:1\", \"1:end:1\", \"0:end:2\"]"], ["3", "[\"0:start:0\", \"0:end:2\", \"1:start:3\", \"1:end:3\", \"2:start:4\", \"2:end:10\"]"], ["2", "[\"0:start:0\", \"0:end:5\", \"1:start:6\", \"1:end:10\"]"], ["1", "[\"0:start:0\", \"0:end:100\"]"], ["2", "[\"0:start:0\", \"1:start:0\", \"1:end:0\", \"0:end:1\"]"], ["3", "[\"2:start:0\", \"2:end:0\", \"0:start:1\", \"0:end:1\", \"1:start:2\", \"1:end:2\"]"], ["2", "[\"0:start:0\", \"0:start:1\", \"0:start:2\", \"0:end:3\", \"0:end:4\", \"0:end:5\"]"], ["4", "[\"0:start:0\", \"1:start:1\", \"2:start:2\", \"3:start:3\", \"3:end:3\", \"2:end:4\", \"1:end:5\", \"0:end:6\"]"], ["2", "[\"0:start:0\", \"1:start:5\", \"1:end:5\", \"1:start:6\", \"1:end:10\", \"0:end:11\"]"], ["1", "[\"0:start:5\", \"0:end:5\"]"], ["2", "[\"0:start:0\", \"0:end:1\", \"0:start:2\", \"0:end:3\", \"1:start:4\", \"1:end:9\"]"], ["3", "[\"0:start:0\", \"1:start:2\", \"1:end:2\", \"2:start:3\", \"2:end:4\", \"0:end:5\"]"], ["2", "[\"1:start:0\", \"1:end:2\", \"0:start:3\", \"0:end:7\"]"], ["5", "[\"0:start:0\", \"0:end:0\", \"1:start:1\", \"1:end:1\", \"2:start:2\", \"2:end:2\", \"3:start:3\", \"3:end:3\", \"4:start:4\", \"4:end:4\"]"], ["2", "[\"0:start:0\", \"1:start:1\", \"1:end:2\", \"1:start:3\", \"1:end:4\", \"0:end:5\"]"], ["3", "[\"0:start:0\", \"0:start:1\", \"1:start:2\", \"1:end:3\", \"0:end:4\", \"2:start:5\", \"2:end:6\"]"], ["1", "[\"0:start:0\", \"0:start:1\", \"0:end:1\", \"0:end:2\"]"], ["2", "[\"0:start:10\", \"1:start:12\", \"1:end:14\", \"0:end:20\"]"], ["3", "[\"1:start:0\", \"2:start:1\", \"2:end:5\", \"1:end:6\", \"0:start:7\", \"0:end:7\"]"], ["2", "[\"0:start:0\", \"0:end:3\", \"0:start:4\", \"0:end:4\", \"1:start:5\", \"1:end:5\"]"], ["2", "[\"0:start:0\", \"1:start:1\", \"1:end:3\", \"1:start:4\", \"1:end:4\", \"0:end:6\"]"], ["3", "[\"0:start:0\", \"1:start:1\", \"2:start:2\", \"2:end:2\", \"2:start:3\", \"2:end:3\", \"1:end:4\", \"0:end:5\"]"]], "expected": [[3, 4], [8], [1, 1], [1], [7, 1], [2, 2, 2], [2, 1], [3, 1, 7], [6, 5], [101], [1, 1], [1, 1, 1], [6, 0], [2, 2, 2, 1], [6, 6], [1], [4, 6], [3, 1, 2], [5, 3], [1, 1, 1, 1, 1], [2, 4], [3, 2, 2], [3], [8, 3], [1, 2, 5], [5, 1], [3, 4], [2, 2, 2]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "380", "slug": "expression-add-operators", "id": 380, "title": "Expression Add Operators", "difficulty": "Hard", "category": "backtracking", "link": "https://leetcode.com/problems/expression-add-operators/", "examples": [{"input": "num = \"123\", target = 6", "output": "[\"1+2+3\",\"1*2*3\"]", "explanation": "Both expressions evaluate to 6 (order may vary)."}, {"input": "num = \"232\", target = 8", "output": "[\"2+3*2\",\"2*3+2\"]", "explanation": "Multiplication binds tighter than addition."}, {"input": "num = \"3456237490\", target = 9191", "output": "[]", "explanation": "No insertion reaches the target."}], "hints": ["Backtrack over split positions, carrying the running value plus the last operand to handle * precedence.", "Skip any multi-digit chunk with a leading zero.", "Use long arithmetic since intermediate products can exceed int range."], "statement": "Insert binary operators `+`, `-`, `*` between the digits of `num` so the expression evaluates to `target`. Return every valid expression.\n\nOperands must not have leading zeros (a lone `0` is fine). Multiplication\nhas the usual higher precedence. Implement `addOperators(num, target)`\nreturning the list of strings in any order.\n\n**Constraints:**\n- `1 <= num.length <= 10`, digits only.\n- `-2^31 <= target <= 2^31 - 1`\n", "solution": "## Approach\n\nDepth-first search over every split of the digit string. Keep the evaluated total plus the last operand so a following * can undo the last addition/subtraction and apply the product, preserving precedence. Prune chunks with leading zeros.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(4^n) in the worst case (three operators per gap).\n- **Space Complexity:** O(n) recursion depth plus output storage.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def addOperators(self, num: str, target: int) -> List[str]:\n res: List[str] = []\n def dfs(pos: int, value: int, last: int, expr: str) -> None:\n if pos == len(num):\n if value == target:\n res.append(expr)\n return\n for i in range(pos, len(num)):\n if i != pos and num[pos] == '0':\n break\n cur = int(num[pos:i + 1])\n if pos == 0:\n dfs(i + 1, cur, cur, num[pos:i + 1])\n else:\n dfs(i + 1, value + cur, cur, expr + \"+\" + num[pos:i + 1])\n dfs(i + 1, value - cur, -cur, expr + \"-\" + num[pos:i + 1])\n dfs(i + 1, value - last + last * cur, last * cur, expr + \"*\" + num[pos:i + 1])\n dfs(0, 0, 0, \"\")\n return res\n```\n", "starter": {"go": "package main\n\nfunc AddOperators(num string, target int) []string {\n return []string{}\n}", "python": "from typing import List\n\nclass Solution:\n def addOperators(self, num: str, target: int) -> List[str]:\n return []", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> addOperators(string num, int target) {\n return {};\n }\n};"}, "fn": "addOperators", "params": [{"name": "num", "type": "string"}, {"name": "target", "type": "int"}], "outputType": "string_list", "tests": [["123", "6"], ["232", "8"], ["105", "5"], ["00", "0"], ["0", "0"], ["1", "1"], ["12", "12"], ["3456237490", "9191"], ["1234", "10"], ["123", "15"], ["2147483647", "2147483647"], ["101", "2"], ["222", "6"], ["123456", "21"], ["000", "0"], ["00", "1"], ["12345", "15"], ["999", "27"], ["1010", "10"], ["111", "3"], ["12", "3"], ["100", "1"], ["321", "6"], ["212", "5"], ["1000", "1"], ["234", "9"], ["567", "18"], ["11", "2"]], "expected": [["1+2+3", "1*2*3"], ["2+3*2", "2*3+2"], ["1*0+5", "10-5"], ["0+0", "0-0", "0*0"], ["0"], ["1"], ["12"], [], ["1+2+3+4", "1*2*3+4"], ["12+3"], ["2147483647"], ["1+0+1", "1-0+1"], ["2+2+2", "2+2*2", "2*2+2"], ["1+2+3+4+5+6", "1+2-3*4+5*6", "1+2*3+4*5-6", "1-2*3+4*5+6", "1-2*3-4+5*6", "1-2-34+56", "1*2*3+4+5+6", "1+23-4-5+6", "12*3-4-5-6"], ["0+0+0", "0+0-0", "0+0*0", "0-0+0", "0-0-0", "0-0*0", "0*0+0", "0*0-0", "0*0*0"], [], ["1+2+3+4+5", "1-2*3+4*5", "1*2*3+4+5", "1+23-4-5"], ["9+9+9"], ["1*0+10", "10+1*0", "10-1*0", "10*1+0", "10*1-0"], ["1+1+1"], ["1+2"], ["1+0+0", "1+0-0", "1+0*0", "1-0+0", "1-0-0", "1-0*0"], ["3+2+1", "3*2*1"], ["2+1+2"], ["1+0+0+0", "1+0+0-0", "1+0+0*0", "1+0-0+0", "1+0-0-0", "1+0-0*0", "1+0*0+0", "1+0*0-0", "1+0*0*0", "1-0+0+0", "1-0+0-0", "1-0+0*0", "1-0-0+0", "1-0-0-0", "1-0-0*0", "1-0*0+0", "1-0*0-0", "1-0*0*0"], ["2+3+4"], ["5+6+7"], ["1+1"]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "807", "slug": "expressive-words", "id": 807, "title": "Expressive Words", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/expressive-words/", "examples": [{"input": "s = \"heeellooo\", words = [\"hello\", \"hi\", \"helo\"]", "output": "1", "explanation": "Only \"hello\" can be stretched into \"heeellooo\": the e-group and o-group of s are long enough, while the other words fail on group counts."}, {"input": "s = \"zzzzzyyyy\", words = [\"zzyy\", \"zy\", \"zyyy\"]", "output": "3", "explanation": "Each listed word uses the same two groups as s, and every group of s has length at least 3, so all three stretch."}, {"input": "s = \"abcd\", words = [\"abc\"]", "output": "0", "explanation": "The group structure differs (4 groups versus 3), so nothing stretches."}], "hints": ["Compress both s and each word into (character, run-length) groups and compare group by group.", "A word group may expand to the s group only when lengths match or when the s run has length at least 3 and is not shorter."], "statement": "You are given a stretched string `s` and a list of candidate `words`. A word is called stretchy when it can be expanded into `s` by lengthening some of its character groups.\n\nPicture both strings as blocks of repeated letters: for example `heeellooo` becomes (h,1), (e,2), (l,2), (o,3). A word matches when it has exactly the same block letters in the same order, and for every block either the two lengths are equal, or the `s` block has length at least 3 and is at least as long as the word block.\n\nReturn how many entries of `words` are stretchy.\n\n**Constraints:**\n- `1 <= s.length <= 100`\n- `1 <= words.length <= 100`\n- `1 <= words[i].length <= 100`\n- `s` and each word consist of lowercase English letters.\n", "solution": "## Approach\n\nRun-length encode the stretched string and each candidate into blocks of (letter, count). A candidate is stretchy when the block letters line up exactly and every count pair is either equal or the stretched count is at least 3 and at least as large. Scanning both strings with two pointers builds these blocks on the fly without extra storage. Counting the candidates that pass gives the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + total word length), where n is the length of `s`. Each character is visited once per comparison.\n- **Space Complexity:** O(1) besides the input.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def expressiveWords(self, s: str, words: List[str]) -> int:\n def stretchy(w: str) -> bool:\n i = j = 0\n n, m = len(s), len(w)\n while i < n and j < m:\n if s[i] != w[j]:\n return False\n cs = s[i]\n ni = i\n while ni < n and s[ni] == cs:\n ni += 1\n nj = j\n while nj < m and w[nj] == cs:\n nj += 1\n ls, lw = ni - i, nj - j\n if ls != lw and (ls < 3 or ls < lw):\n return False\n i, j = ni, nj\n return i == n and j == m\n return sum(1 for w in words if stretchy(w))\n```\n", "starter": {"go": "package main\n\nfunc ExpressiveWords(s string, words []string) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def expressiveWords(self, s: str, words: List[str]) -> int:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int expressiveWords(string s, vector<string>& words) {\n return 0;\n }\n};"}, "fn": "expressiveWords", "params": [{"name": "s", "type": "string"}, {"name": "words", "type": "string_array"}], "outputType": "int", "tests": [["heeellooo", "['hello', 'hi', 'helo']"], ["zzzzzyyyy", "['zzyy', 'zy', 'zyyy']"], ["abcd", "['abc']"], ["heeellooo", "['heeellooo']"], ["a", "['a']"], ["a", "['b']"], ["aaa", "['a', 'aa', 'aaa', 'aaaa']"], ["aaabbb", "['ab', 'aabb', 'aaabbb', 'aaabb']"], ["abcd", "['abcd', 'abce', 'abcdd']"], ["hello", "['hello', 'helloo', 'helllo']"], ["ieeii", "['ieii', 'ieeii', 'ii']"], ["zzzz", "['z', 'zz', 'zzz', 'zzzz', 'zzzzz']"], ["abbbcc", "['abc', 'abbc', 'abbbcc', 'abbcc']"], ["xy", "['xy', 'xxy', 'xyy', 'xxyy']"], ["eeelleee", "['ele', 'ellee', 'eeelleee']"], ["aabbaaa", "['aba', 'aabbaaa', 'aaabaaa']"], ["dddiii", "['di', 'ddii', 'dddiii', 'dddi']"], ["op", "['op', 'opp', 'oop']"], ["qwerty", "['qwerty', 'qwertyy']"], ["mmmmnnn", "['mn', 'mmnn', 'mmmnnn', 'mmmmnnn']"], ["ab", "['a', 'b', 'ab', 'ba']"], ["aaabaaa", "['aaabaaa', 'aabaa', 'abaa']"], ["tttttt", "['t', 'tt', 'ttt', 'tttttt']"], ["abcde", "['abcde', 'abcdef', 'abcd']"], ["hii", "['hi', 'hii', 'hiii']"], ["leel", "['leel', 'lel', 'leeel']"], ["uuuvvv", "['uv', 'uuvv', 'uuuvvv', 'uuvvv']"], ["k", "['k', 'kk', 'kkk']"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "214", "slug": "extra-characters-in-a-string", "id": 214, "title": "Extra Characters in a String", "difficulty": "Medium", "category": "trie", "link": "https://leetcode.com/problems/extra-characters-in-a-string/", "examples": [{"input": "s = \"leetscode\", dictionary = [\"leet\",\"code\",\"leetcode\"]", "output": "1", "explanation": "We can break s in two substrings: \"leet\" from index 0 to 3 and \"code\" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1."}, {"input": "s = \"sayhelloworld\", dictionary = [\"hello\",\"world\"]", "output": "3", "explanation": "We can break s in two substrings: \"hello\" from index 3 to 7 and \"world\" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3."}], "hints": ["Can we use Dynamic Programming here?", "Define dp[i] as the minimum number of extra characters if breaking up s[i:] optimally: either s[i] is unused (one extra character plus dp[i+1]) or it starts a dictionary word of some length len, giving dp[i + len].", "A trie of the dictionary lets every word starting at the same position be found in one pass instead of re-scanning all dictionary entries at every index."], "statement": "You are handed a string `s` indexed from `0` alongside a word list `dictionary`. Split `s` into one or more chunks that do not overlap, where every kept chunk must show up verbatim in `dictionary`. Characters of `s` that fall outside all kept chunks count as leftover.\n\nArrange the split so that the total count of leftover characters is as small as possible, and report that minimum.\n\n**Constraints:**\n\n- `1 <= s.length <= 50`\n- `1 <= dictionary.length <= 50`\n- `1 <= dictionary[i].length <= 50`\n- `dictionary[i]` and `s` consist of only lowercase English letters.\n- `dictionary` holds distinct words.\n", "solution": "## Approach\n\nDynamic programming from the end of the string. Let `dp[i]` be the minimum number of extra characters left over after optimally breaking the suffix `s[i:]`. Either `s[i]` is left unused, costing one extra character plus `dp[i + 1]`, or it begins a dictionary word `w` (so `s[i:i + len(w)] == w`), in which case the cost is `dp[i + len(w)]`. Taking the minimum over all cases fills `dp[0]`, the answer. A dictionary set (or a trie) makes word lookups fast.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * D), where n is `s.length` and D is the number of dictionary words \u2014 we scan every dictionary word at every index.\n- **Space Complexity:** O(n) for the DP table.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def minExtraChar(self, s: str, dictionary: List[str]) -> int:\n n = len(s)\n words = set(dictionary)\n dp = [n - i for i in range(n + 1)]\n for i in range(n - 1, -1, -1):\n dp[i] = dp[i + 1] + 1\n for word in words:\n if s.startswith(word, i):\n dp[i] = min(dp[i], dp[i + len(word)])\n return dp[0]\n```", "starter": {"go": "package main\n\nfunc MinExtraChar(s string, dictionary []string) int {\n \n}", "python": "from typing import List\nclass Solution:\n def minExtraChar(self, s: str, dictionary: List[str]) -> int:\n ", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int minExtraChar(string s, vector<string>& dictionary) {\n \n }\n};"}, "fn": "minExtraChar", "params": [{"name": "s", "type": "string"}, {"name": "dictionary", "type": "string_array"}], "outputType": "int", "tests": [["abc", "[\"a\",\"b\",\"c\"]"], ["leetscode", "[\"leet\",\"code\",\"leetcode\"]"], ["sayhelloworld", "[\"hello\",\"world\"]"], ["abcd", "[\"ab\",\"cd\"]"], ["aaa", "[\"a\"]"], ["zzz", "[\"c\",\"d\"]"], ["xab", "[\"ab\"]"], ["short", "[\"s\",\"hort\",\"sh\",\"or\",\"t\"]"], ["dynamicprogramming", "[\"dynamic\",\"programming\",\"pro\",\"gramming\"]"], ["abcdefgh", "[\"ab\",\"cd\",\"ef\"]"], ["ilovecoding", "[\"i\",\"love\",\"coding\"]"], ["cojudgeiscool", "[\"co\",\"judge\",\"is\",\"cool\"]"], ["aaaaaaaa", "[\"aaa\",\"aa\",\"a\"]"], ["hello", "[\"world\",\"hell\",\"o\"]"], ["a", "[\"a\"]"], ["b", "[\"a\"]"], ["abcde", "[\"abc\", \"de\"]"], ["abcdef", "[\"ab\", \"cd\", \"ef\"]"], ["aaaaab", "[\"a\", \"aa\"]"], ["xyzxyz", "[\"xyz\"]"], ["helloworld", "[\"hello\", \"world\", \"hell\", \"low\"]"], ["qwerty", "[\"abc\", \"def\"]"], ["mississippi", "[\"is\", \"si\", \"miss\"]"], ["abcdefghij", "[\"abc\", \"def\", \"ghi\"]"], ["zzzzzzzzzz", "[\"z\", \"zz\", \"zzz\"]"], ["thequickbrownfox", "[\"the\", \"quick\", \"brown\", \"fox\"]"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "[\"a\", \"aa\", \"aaa\"]"], ["abcdxyz", "[\"abc\", \"xyz\"]"], ["onetwothreefour", "[\"one\", \"two\", \"three\", \"four\"]"], ["nomatchhere", "[\"aaa\", \"bbb\", \"ccc\"]"], ["ababa", "[\"aba\", \"bab\"]"], ["programming", "[\"pro\", \"gram\", \"ming\", \"program\"]"]], "expected": [0, 1, 3, 0, 0, 3, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 6, 3, 1, 0, 0, 0, 1, 0, 11, 2, 0], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "358", "slug": "factor-combinations", "id": 358, "title": "Factor Combinations", "difficulty": "Medium", "category": "backtracking", "link": "https://leetcode.com/problems/factor-combinations/", "examples": [{"input": "n = 12", "output": "[[2,6],[3,4],[2,2,3]]", "explanation": "12 equals 2 * 6, 3 * 4 and 2 * 2 * 3."}, {"input": "n = 37", "output": "[]", "explanation": "37 is prime, so it cannot be split into smaller factors above 1."}, {"input": "n = 1", "output": "[]", "explanation": "1 has no factor above 1 to build a combination from."}], "hints": ["Search depth-first, only trying divisors from the last chosen factor upward so each row stays non-decreasing.", "When the remaining value is at least the current start, record current factors plus the remainder as one valid row."], "statement": "Given a positive integer `n`, return every way to write it as a product of integers greater than 1. Each way is a list of at least two factors in non-decreasing order whose product equals `n`. Return the collection of ways in any order.\n\nA single factor such as `[12]` alone is not counted, and factor `1` is never used.\n\n**Constraints:**\n- `1 <= n <= 10^7`\n", "solution": "## Approach\n\nBuild factor rows depth-first. At each step only try divisors from the last chosen factor upward, which keeps every row non-decreasing and avoids duplicate orderings. When a divisor splits the remainder, the current path plus the quotient forms one valid row, and the search continues on the quotient to find longer rows.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^(1/2) branching) in practice; bounded by the number of divisor chains of `n`.\n- **Space Complexity:** O(log n) recursion depth plus the output.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def getFactors(self, n: int) -> List[List[int]]:\n res: List[List[int]] = []\n def search(remaining: int, start: int, cur: List[int]) -> None:\n f = start\n while f * f <= remaining:\n if remaining % f == 0:\n cur.append(f)\n res.append(cur + [remaining // f])\n search(remaining // f, f, cur)\n cur.pop()\n f += 1\n search(n, 2, [])\n return res\n```\n", "starter": {"go": "package main\n\nfunc GetFactors(n int) [][]int {\n return [][]int{}\n}", "python": "from typing import List\n\nclass Solution:\n def getFactors(self, n: int) -> List[List[int]]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> getFactors(int n) {\n return {};\n }\n};"}, "fn": "getFactors", "params": [{"name": "n", "type": "int"}], "outputType": "int_list_2d", "tests": [["12"], ["37"], ["1"], ["32"], ["2"], ["4"], ["6"], ["8"], ["9"], ["16"], ["24"], ["36"], ["48"], ["100"], ["7"], ["15"], ["20"], ["25"], ["27"], ["30"], ["64"], ["72"], ["81"], ["128"], ["1000"], ["10000"]], "expected": [[[2, 6], [2, 2, 3], [3, 4]], [], [], [[2, 16], [2, 2, 8], [2, 2, 2, 4], [2, 2, 2, 2, 2], [2, 4, 4], [4, 8]], [], [[2, 2]], [[2, 3]], [[2, 4], [2, 2, 2]], [[3, 3]], [[2, 8], [2, 2, 4], [2, 2, 2, 2], [4, 4]], [[2, 12], [2, 2, 6], [2, 2, 2, 3], [2, 3, 4], [3, 8], [4, 6]], [[2, 18], [2, 2, 9], [2, 2, 3, 3], [2, 3, 6], [3, 12], [3, 3, 4], [4, 9], [6, 6]], [[2, 24], [2, 2, 12], [2, 2, 2, 6], [2, 2, 2, 2, 3], [2, 2, 3, 4], [2, 3, 8], [2, 4, 6], [3, 16], [3, 4, 4], [4, 12], [6, 8]], [[2, 50], [2, 2, 25], [2, 2, 5, 5], [2, 5, 10], [4, 25], [4, 5, 5], [5, 20], [10, 10]], [], [[3, 5]], [[2, 10], [2, 2, 5], [4, 5]], [[5, 5]], [[3, 9], [3, 3, 3]], [[2, 15], [2, 3, 5], [3, 10], [5, 6]], [[2, 32], [2, 2, 16], [2, 2, 2, 8], [2, 2, 2, 2, 4], [2, 2, 2, 2, 2, 2], [2, 2, 4, 4], [2, 4, 8], [4, 16], [4, 4, 4], [8, 8]], [[2, 36], [2, 2, 18], [2, 2, 2, 9], [2, 2, 2, 3, 3], [2, 2, 3, 6], [2, 3, 12], [2, 3, 3, 4], [2, 4, 9], [2, 6, 6], [3, 24], [3, 3, 8], [3, 4, 6], [4, 18], [6, 12], [8, 9]], [[3, 27], [3, 3, 9], [3, 3, 3, 3], [9, 9]], [[2, 64], [2, 2, 32], [2, 2, 2, 16], [2, 2, 2, 2, 8], [2, 2, 2, 2, 2, 4], [2, 2, 2, 2, 2, 2, 2], [2, 2, 2, 4, 4], [2, 2, 4, 8], [2, 4, 16], [2, 4, 4, 4], [2, 8, 8], [4, 32], [4, 4, 8], [8, 16]], [[2, 500], [2, 2, 250], [2, 2, 2, 125], [2, 2, 2, 5, 25], [2, 2, 2, 5, 5, 5], [2, 2, 5, 50], [2, 2, 5, 5, 10], [2, 2, 10, 25], [2, 4, 125], [2, 4, 5, 25], [2, 4, 5, 5, 5], [2, 5, 100], [2, 5, 5, 20], [2, 5, 10, 10], [2, 10, 50], [2, 20, 25], [4, 250], [4, 5, 50], [4, 5, 5, 10], [4, 10, 25], [5, 200], [5, 5, 40], [5, 5, 5, 8], [5, 8, 25], [5, 10, 20], [8, 125], [10, 100], [10, 10, 10], [20, 50], [25, 40]], [[2, 5000], [2, 2, 2500], [2, 2, 2, 1250], [2, 2, 2, 2, 625], [2, 2, 2, 2, 5, 125], [2, 2, 2, 2, 5, 5, 25], [2, 2, 2, 2, 5, 5, 5, 5], [2, 2, 2, 2, 25, 25], [2, 2, 2, 5, 250], [2, 2, 2, 5, 5, 50], [2, 2, 2, 5, 5, 5, 10], [2, 2, 2, 5, 10, 25], [2, 2, 2, 10, 125], [2, 2, 2, 25, 50], [2, 2, 4, 625], [2, 2, 4, 5, 125], [2, 2, 4, 5, 5, 25], [2, 2, 4, 5, 5, 5, 5], [2, 2, 4, 25, 25], [2, 2, 5, 500], [2, 2, 5, 5, 100], [2, 2, 5, 5, 5, 20], [2, 2, 5, 5, 10, 10], [2, 2, 5, 10, 50], [2, 2, 5, 20, 25], [2, 2, 10, 250], [2, 2, 10, 10, 25], [2, 2, 20, 125], [2, 2, 25, 100], [2, 2, 50, 50], [2, 4, 1250], [2, 4, 5, 250], [2, 4, 5, 5, 50], [2, 4, 5, 5, 5, 10], [2, 4, 5, 10, 25], [2, 4, 10, 125], [2, 4, 25, 50], [2, 5, 1000], [2, 5, 5, 200], [2, 5, 5, 5, 40], [2, 5, 5, 5, 5, 8], [2, 5, 5, 8, 25], [2, 5, 5, 10, 20], [2, 5, 8, 125], [2, 5, 10, 100], [2, 5, 10, 10, 10], [2, 5, 20, 50], [2, 5, 25, 40], [2, 8, 625], [2, 8, 25, 25], [2, 10, 500], [2, 10, 10, 50], [2, 10, 20, 25], [2, 20, 250], [2, 25, 200], [2, 40, 125], [2, 50, 100], [4, 2500], [4, 4, 625], [4, 4, 5, 125], [4, 4, 5, 5, 25], [4, 4, 5, 5, 5, 5], [4, 4, 25, 25], [4, 5, 500], [4, 5, 5, 100], [4, 5, 5, 5, 20], [4, 5, 5, 10, 10], [4, 5, 10, 50], [4, 5, 20, 25], [4, 10, 250], [4, 10, 10, 25], [4, 20, 125], [4, 25, 100], [4, 50, 50], [5, 2000], [5, 5, 400], [5, 5, 5, 80], [5, 5, 5, 5, 16], [5, 5, 5, 8, 10], [5, 5, 8, 50], [5, 5, 10, 40], [5, 5, 16, 25], [5, 5, 20, 20], [5, 8, 250], [5, 8, 10, 25], [5, 10, 200], [5, 10, 10, 20], [5, 16, 125], [5, 20, 100], [5, 25, 80], [5, 40, 50], [8, 1250], [8, 10, 125], [8, 25, 50], [10, 1000], [10, 10, 100], [10, 10, 10, 10], [10, 20, 50], [10, 25, 40], [16, 625], [16, 25, 25], [20, 500], [20, 20, 25], [25, 400], [40, 250], [50, 200], [80, 125], [100, 100]]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "322", "slug": "factorial-trailing-zeroes", "id": 322, "title": "Factorial Trailing Zeroes", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/factorial-trailing-zeroes/", "examples": [{"explanation": "3! is 6, which has no trailing zero.", "input": "n = 3", "output": "0"}, {"explanation": "5! is 120, which ends with one zero.", "input": "n = 5", "output": "1"}, {"explanation": "0! is 1, which has no trailing zero.", "input": "n = 0", "output": "0"}], "hints": ["Count factors of 5: n / 5 + n / 25 + n / 125 and so on.", "Do not compute the factorial itself; it overflows quickly."], "statement": "Given a non-negative integer `n`, count how many trailing zeros appear in `n!` (n factorial).\n\nTrailing zeros come from factors of 10, and there are always more factors of 2 than of 5, so the answer is the number of factors of 5 inside `1 * 2 * ... * n`.\n\n**Constraints:**\n- `0 <= n <= 10^4`\n", "solution": "## Approach\n\nCount how many multiples of 5, 25, 125, and so on lie at or below `n`. Each multiple contributes one factor of 5 per power dividing it, and those factors pair with abundant factors of 2 to make trailing zeros. Repeated integer division by 5 accumulates exactly this count.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n), dividing by 5 each step.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def trailingZeroes(self, n: int) -> int:\n res = 0\n while n > 0:\n n //= 5\n res += n\n return res\n```\n", "starter": {"go": "package main\n\nfunc TrailingZeroes(n int) int {\n \n}", "python": "class Solution:\n def trailingZeroes(self, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int trailingZeroes(int n) {\n return 0;\n }\n};"}, "fn": "trailingZeroes", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["3"], ["5"], ["0"], ["10"], ["1"], ["4"], ["6"], ["25"], ["30"], ["100"], ["7"], ["15"], ["20"], ["50"], ["125"], ["1000"], ["10000"], ["2"], ["8"], ["12"], ["24"], ["26"], ["49"], ["75"], ["200"], ["625"]], "expected": [0, 1, 0, 2, 0, 0, 1, 6, 7, 24, 1, 3, 4, 12, 31, 249, 2499, 0, 1, 2, 4, 6, 10, 18, 49, 156], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "879", "slug": "fair-candy-swap", "id": 879, "title": "Fair Candy Swap", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/fair-candy-swap/", "examples": [{"input": "aliceSizes = [1,1], bobSizes = [2,2]", "output": "[1,2]", "explanation": "After swapping a 1 for a 2, both totals equal 3."}, {"input": "aliceSizes = [1,2], bobSizes = [2,3]", "output": "[1,2]", "explanation": "After swapping a 1 for a 2, both totals equal 4."}, {"input": "aliceSizes = [2], bobSizes = [1,3]", "output": "[2,3]", "explanation": "After swapping the 2 for the 3, both totals equal 3."}], "hints": ["If Alice leads by D in total, her box must exceed Bob's box by exactly D / 2.", "Put Bob's sizes in a hash set and test each of Alice's boxes against the needed partner."], "statement": "Alice and Bob hold boxes of candy of various sizes. Alice's boxes have sizes `aliceSizes` and Bob's have sizes `bobSizes`. They agree to swap exactly one box each so that afterward both own the same total amount of candy.\n\nReturn any pair `[a, b]` where `a` is a size from Alice and `b` is a size from Bob that achieves this fair trade. The inputs guarantee at least one such pair exists.\n\n**Constraints:**\n- `1 <= aliceSizes.length, bobSizes.length <= 10^4`\n- `1 <= aliceSizes[i], bobSizes[i] <= 10^5`\n- The two totals differ by an even amount, and at least one fair swap exists.\n", "solution": "## Approach\n\nEqualizing the totals means Alice's given box must exceed Bob's returned box by half the difference of the two sums. With that target gap known, load Bob's sizes into a set and scan Alice's boxes for one whose ideal partner exists. The first match forms a fair swap.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(a + b), where a and b are the numbers of boxes each person holds.\n- **Space Complexity:** O(b) for Bob's size set.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def fairCandySwap(self, aliceSizes: List[int], bobSizes: List[int]) -> List[int]:\n diff = (sum(aliceSizes) - sum(bobSizes)) // 2\n bob = set(bobSizes)\n for a in aliceSizes:\n if a - diff in bob:\n return [a, a - diff]\n return []\n```\n", "starter": {"go": "package main\n\nfunc FairCandySwap(aliceSizes []int, bobSizes []int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def fairCandySwap(self, aliceSizes: List[int], bobSizes: List[int]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> fairCandySwap(vector<int>& aliceSizes, vector<int>& bobSizes) {\n return {};\n }\n};"}, "fn": "fairCandySwap", "params": [{"name": "aliceSizes", "type": "int_array"}, {"name": "bobSizes", "type": "int_array"}], "outputType": "int_array", "tests": [["[1,1]", "[2,2]"], ["[1,2]", "[2,3]"], ["[2]", "[1,3]"], ["[1,2,5]", "[2,4]"], ["[1,1,1]", "[1,1,1]"], ["[3,4]", "[1,2,4]"], ["[1,2,3,4]", "[1,2,3,4]"], ["[1,2,3]", "[3,4,5]"], ["[10,20]", "[5,15,10]"], ["[7,9]", "[7,9]"], ["[1,2,3,4,5]", "[5,5,5]"], ["[4,1,2]", "[2,3,6]"], ["[2,6]", "[4]"], ["[3,5,4]", "[1,3]"], ["[25000,25000,50000]", "[25000,75000]"], ["[1,2,3,4,5,6]", "[6,7,8]"], ["[11,22,33]", "[11,22,33]"], ["[9,1,3,5]", "[2,4,6,4]"], ["[8,8,8]", "[8,8,8]"], ["[2,7,4,3]", "[3,5,6]"], ["[100,200,300]", "[150,250,200]"], ["[5,5,5,5]", "[1,9,5,5]"], ["[30,10]", "[26,6]"], ["[5]", "[5]"], ["[2,2,2,2,2]", "[2,2,2,4]"], ["[9,9,2]", "[9,11]"], ["[4,5,6,9]", "[2,4,8,10]"], ["[13,19]", "[11,17]"]], "expected": [[1, 2], [1, 2], [2, 3], [5, 4], [1, 1], [4, 4], [1, 1], [1, 4], [10, 10], [7, 7], [5, 5], [4, 6], [6, 4], [5, 1], [25000, 25000], [6, 6], [11, 11], [3, 2], [8, 8], [7, 6], [200, 200], [5, 5], [30, 26], [5, 5], [2, 2], [9, 9], [4, 4], [13, 11]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "712", "slug": "falling-squares", "id": 712, "title": "Falling Squares", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/falling-squares/", "examples": [{"input": "positions = [[1,2],[2,3],[6,1]]", "output": "[2,5,5]", "explanation": "Heights evolve 2 then 5 then stay 5."}, {"input": "positions = [[100,100],[200,100]]", "output": "[100,100]", "explanation": "Disjoint squares keep height 100."}, {"input": "positions = [[0,2],[1,2],[3,1]]", "output": "[2,4,4]", "explanation": "Second square stacks to 4."}], "hints": ["Remember each placed square as [left, right, top] and compare intervals for overlap.", "A new square of side s sits on the highest top among overlapping squares (or 0), reaching base + s.", "Track the running global maximum after every drop."], "statement": "Squares fall one by one onto a flat baseline. Each entry `positions[i] = [left, size]` describes a square whose side length equals `size` and whose left edge starts at coordinate `left`. A square drops straight down until it rests on the baseline or on top of a previously placed square. Touching only at a vertical edge does not count as support.\n\nAfter every drop, record how tall the tallest stack has become. Return those maxima in order.\n\n**Constraints:**\n- `1 <= positions.length <= 1000`\n- `0 <= left <= 10^8`\n- `1 <= size <= 10^6`\n", "solution": "## Approach\n\nKeep every landed square as a triple of left edge, right edge, and top height. For each newcomer, scan earlier squares and keep the greatest top among those whose horizontal ranges strictly overlap; the newcomer then rises from that base by its own side length. Append its top to the placed list and update the running global maximum, which is recorded after each drop.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) pairwise overlap checks.\n- **Space Complexity:** O(n) for placed squares.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n placed = []\n ans = []\n cur_max = 0\n for l, s in positions:\n r = l + s\n base = 0\n for pl, pr, top in placed:\n if l < pr and r > pl:\n base = max(base, top)\n top = base + s\n placed.append((l, r, top))\n cur_max = max(cur_max, top)\n ans.append(cur_max)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FallingSquares(positions [][]int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def fallingSquares(self, positions: List[List[int]]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> fallingSquares(vector<vector<int>>& positions) {\n return {};\n }\n};"}, "fn": "fallingSquares", "params": [{"name": "positions", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[[1,2],[2,3],[6,1]]"], ["[[100,100],[200,100]]"], ["[[0,2],[1,2],[3,1]]"], ["[[0,1]]"], ["[[0,2],[0,2]]"], ["[[0,1],[1,1]]"], ["[[0,3],[1,1],[2,1]]"], ["[[1,1],[2,1],[3,1],[4,1]]"], ["[[0,10],[5,5],[2,3]]"], ["[[0,2],[3,2],[1,4]]"], ["[[5,5],[5,5],[5,5]]"], ["[[0,1],[0,2],[0,3]]"], ["[[10,2],[11,2],[12,2]]"], ["[[0,5],[1,1],[2,1],[3,1]]"], ["[[2,1],[2,2],[2,3]]"], ["[[0,4],[4,4],[8,4]]"], ["[[0,4],[2,4],[4,4]]"], ["[[1,5],[3,2],[6,1],[2,4]]"], ["[[0,2],[2,2],[4,2],[6,2]]"], ["[[0,3],[3,3],[6,3]]"], ["[[0,1],[10,1],[20,1],[30,1]]"], ["[[0,100],[0,10],[0,5]]"], ["[[50,10],[55,10],[60,10]]"], ["[[1,2],[3,4],[5,1],[2,3]]"], ["[[0,2],[1,1],[1,1],[1,1]]"], ["[[1000000,5],[1000002,5]]"], ["[[0,1],[0,1],[2,1],[2,1]]"], ["[[3,3],[1,2],[2,5]]"]], "expected": [[2, 5, 5], [100, 100], [2, 4, 4], [1], [2, 4], [1, 1], [3, 4, 4], [1, 1, 1, 1], [10, 15, 15], [2, 2, 6], [5, 10, 15], [1, 3, 6], [2, 4, 6], [5, 6, 6, 6], [1, 3, 6], [4, 4, 4], [4, 8, 12], [5, 7, 7, 11], [2, 2, 2, 2], [3, 3, 3], [1, 1, 1, 1], [100, 110, 115], [10, 20, 30], [2, 4, 5, 7], [2, 3, 4, 5], [5, 10], [1, 2, 2, 2], [3, 3, 8]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "571", "slug": "fibonacci-number", "id": 571, "title": "Fibonacci Number", "difficulty": "Easy", "category": "dp", "link": "https://leetcode.com/problems/fibonacci-number/", "examples": [{"input": "n = 2", "output": "1", "explanation": "F(2) = F(1) + F(0) = 1 + 0."}, {"input": "n = 3", "output": "2", "explanation": "F(3) = F(2) + F(1) = 1 + 1."}, {"input": "n = 4", "output": "3", "explanation": "F(4) = F(3) + F(2) = 2 + 1."}], "hints": ["Only the previous two values are needed to build the next one, so two rolling variables suffice.", "Seed them with F(0) = 0 and F(1) = 1 and iterate upward to n."], "statement": "The Fibonacci progression starts with 0 and 1, and every later term is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, and so on. Formally, F(0) = 0, F(1) = 1, and F(n) = F(n-1) + F(n-2) for n above 1.\n\nGiven `n`, return F(n).\n\n**Constraints:**\n- `0 <= n <= 30`\n", "solution": "## Approach\n\nBuild the sequence from the bottom up while holding only two consecutive values. Start with 0 and 1, then repeatedly replace the pair `(a, b)` with `(b, a + b)` until reaching index `n`. The second component is exactly F(n).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) additions.\n- **Space Complexity:** O(1) extra memory.\n\n## Implementation\n\n```python\nclass Solution:\n def fib(self, n: int) -> int:\n if n <= 1:\n return n\n a, b = 0, 1\n for _ in range(2, n + 1):\n a, b = b, a + b\n return b\n```\n", "starter": {"go": "package main\n\nfunc Fib(n int) int {\n \n}", "python": "class Solution:\n def fib(self, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int fib(int n) {\n return 0;\n }\n};"}, "fn": "fib", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["2"], ["3"], ["4"], ["0"], ["1"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["11"], ["12"], ["13"], ["14"], ["15"], ["16"], ["17"], ["18"], ["19"], ["20"], ["21"], ["22"], ["23"], ["24"], ["25"], ["29"], ["30"]], "expected": [1, 2, 3, 0, 1, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 514229, 832040], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "506", "slug": "find-all-anagrams-in-a-string", "id": 506, "title": "Find All Anagrams in a String", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/find-all-anagrams-in-a-string/", "examples": [{"input": "s = \"cbaebabacd\", p = \"abc\"", "output": "[0,6]", "explanation": "Windows at 0 and 6 rearrange to abc."}, {"input": "s = \"abab\", p = \"ab\"", "output": "[0,1,2]", "explanation": "Every length-2 window qualifies."}], "hints": ["Compare 26-count signatures of p against each sliding window of s.", "Update the window in O(1) by dropping the leftmost letter and adding the new rightmost one.", "Track how many letter counts currently match to test windows in O(1)."], "statement": "You receive two lowercase strings `s` and `p`. Slide a window of length `p.length` across `s` and note every starting index where the window holds exactly the same multiset of letters as `p` (that is, some rearrangement of `p`). Return all such starts in any order.\n\n**Constraints:**\n- `1 <= s.length, p.length <= 3 * 10^4`\n- Both strings use only lowercase English letters.\n\nAdaptation: the source returns a list of integers; here it maps to `int_list`.\n", "solution": "## Approach\n\nCount letters of `p` once, then slide a fixed-size window over `s` while maintaining its 26 counts. Adding the entering character and removing the leaving one keeps the update constant time; whenever the two count tables agree, the window's start index is recorded.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + m), where n is the length of `s` and m of `p`. Each character enters and leaves the window once.\n- **Space Complexity:** O(1) for the two fixed alphabets plus output.\n\n## Implementation\n\n```python\nclass Solution:\n def findAnagrams(self, s: str, p: str):\n m, n = len(p), len(s)\n if m > n:\n return []\n from collections import Counter\n need = [0] * 26\n win = [0] * 26\n for c in p:\n need[ord(c) - 97] += 1\n ans = []\n for i, c in enumerate(s):\n win[ord(c) - 97] += 1\n if i >= m:\n win[ord(s[i - m]) - 97] -= 1\n if i >= m - 1 and win == need:\n ans.append(i - m + 1)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FindAnagrams(s string, p string) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def findAnagrams(self, s: str, p: str) -> List[int]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findAnagrams(string s, string p) {\n return {};\n }\n};"}, "fn": "findAnagrams", "params": [{"name": "s", "type": "string"}, {"name": "p", "type": "string"}], "outputType": "int_list", "tests": [["cbaebabacd", "abc"], ["abab", "ab"], ["aaaa", "aa"], ["abc", "abcd"], ["a", "a"], ["ab", "a"], ["baa", "aa"], ["abababab", "ab"], ["zzzzzz", "abc"], ["abcabcabc", "abc"], ["aabbaa", "aba"], ["aaaaaaaaaa", "aaa"], ["abcdefg", "gfedcba"], ["xyzzxy", "xyz"], ["abacbabc", "abc"], ["aaaaaaaaaa", "a"], ["abc", "abc"], ["abc", "cba"], ["ab", "abc"], ["mississippi", "issi"], ["abcde", "e"], ["abababababababababab", "aba"], ["aaaaabaaaaa", "aaab"], ["xyzxyzxyz", "zyx"], ["abcdefabcdef", "fed"], ["aabbccddaabbccdd", "abcd"], ["qwertyuiopasdfghjklzxcvbnm", "xyz"], ["bbbbbbbbbb", "bbbbb"], ["cbaebabacd", "cbaebabacd"], ["aaabbbcccdddeee", "abcde"]], "expected": [[0, 6], [0, 1, 2], [0, 1, 2], [], [0], [0], [1], [0, 1, 2, 3, 4, 5, 6], [], [0, 1, 2, 3, 4, 5, 6], [0, 3], [0, 1, 2, 3, 4, 5, 6, 7], [0], [0, 3], [1, 2, 3, 5], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0], [0], [], [1, 4], [4], [0, 2, 4, 6, 8, 10, 12, 14, 16], [2, 3, 4, 5], [0, 1, 2, 3, 4, 5, 6], [3, 9], [], [], [0, 1, 2, 3, 4, 5], [0], []], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "510", "slug": "find-all-duplicates-in-an-array", "id": 510, "title": "Find All Duplicates in an Array", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/find-all-duplicates-in-an-array/", "examples": [{"input": "nums = [4,3,2,7,8,2,3,1]", "output": "[2,3]", "explanation": "Values 2 and 3 each occur twice."}, {"input": "nums = [1,1,2]", "output": "[1]", "explanation": "Only 1 repeats."}, {"input": "nums = [1]", "output": "[]", "explanation": "Nothing repeats."}], "hints": ["Track which values have been seen; the second sighting of a value means it is a duplicate.", "Because values lie in 1..n, a boolean table of size n+1 gives O(1) lookups.", "Report each repeated value once even if the input guarantees at most two copies."], "statement": "You are given a list `nums` with `n` entries. Every value lies between `1` and `n`. Each number shows up once or twice; some values show up twice and the rest show up once.\n\nCollect every value that shows up twice and return them.\n\nThe order of the returned values does not matter.\n\n> **Adaptation note:** the original LeetCode return type is `List<Integer>`; this problem uses the portable `int_list` output type with the same values.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `1 <= nums[i] <= nums.length`\n", "solution": "## Approach\n\nWalk the array once while remembering seen values in a boolean table sized `n+1`, which is possible because every entry lies in `1..n`. The first time a value appears mark it seen; the second time append it to the answer and mark it reported so it is emitted once.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one pass over `nums`.\n- **Space Complexity:** O(n) for the seen and reported tables.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findDuplicates(self, nums: List[int]) -> List[int]:\n seen = [False] * (len(nums) + 1)\n added = [False] * (len(nums) + 1)\n res = []\n for x in nums:\n if 1 <= x <= len(nums):\n if seen[x] and not added[x]:\n res.append(x)\n added[x] = True\n seen[x] = True\n return res\n```\n", "starter": {"go": "package main\n\nfunc FindDuplicates(nums []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def findDuplicates(self, nums: List[int]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findDuplicates(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "findDuplicates", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_list", "tests": [["[4,3,2,7,8,2,3,1]"], ["[1,1,2]"], ["[1]"], ["[1,1]"], ["[2,2]"], ["[1,2,3,4,5]"], ["[5,4,3,2,1,1,2]"], ["[3,3,3,3]"], ["[1,2,1,2]"], ["[10,2,5,10,9,1,1,4,3,7]"], ["[1,2,3,1,2,3]"], ["[8,7,6,5,4,3,2,1,1,2]"], ["[1,1,2,2,3,3]"], ["[2,1,2,1]"], ["[4,3,2,7,8,2,3,1,1]"], ["[1,2,3,4]"], ["[2,2,2,2]"], ["[1,2,3,4,5,6,7,8]"], ["[1,1,2,2,3,4,5,6]"], ["[6,5,4,3,2,1,6,5]"], ["[1,2,3,4,5,1,2,3]"], ["[2,3,1,2,3,1]"], ["[1,2]"], ["[2,1,2,1,2,1]"], ["[5,5,4,4,3,3,2,2,1,1]"], ["[7,3,1,5,2,6,4,7]"], ["[9,1,2,3,4,5,6,7,8,9]"], ["[1,3,5,2,4,6,1]"], ["[4,1,2,3,4,5,6]"], ["[2,5,1,4,3,2,5]"]], "expected": [[2, 3], [1], [], [1], [2], [], [1, 2], [3], [1, 2], [10, 1], [1, 2, 3], [1, 2], [1, 2, 3], [2, 1], [2, 3, 1], [], [2], [], [1, 2], [6, 5], [1, 2, 3], [2, 3, 1], [], [2, 1], [5, 4, 3, 2, 1], [7], [9], [1], [4], [2, 5]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "516", "slug": "find-all-numbers-disappeared-in-an-array", "id": 516, "title": "Find All Numbers Disappeared in an Array", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/", "examples": [{"input": "nums = [4,3,2,7,8,2,3,1]", "output": "[5,6]", "explanation": "Values 5 and 6 from 1..8 are absent."}, {"input": "nums = [1,1]", "output": "[2]", "explanation": "With n = 2, value 2 never shows up."}], "hints": ["Mark every value you see in a boolean table indexed by value.", "A second pass from 1 to n collects the unmarked entries in order.", "Both passes are linear; the table costs O(n) extra memory."], "statement": "You are given a list `nums` with `n` entries where each value lies between `1` and `n`. Some numbers in that range appear twice while others never appear.\n\nReturn every number between `1` and `n` that never appears in `nums`, in increasing order.\n\n> **Adaptation note:** the original LeetCode return type is `List<Integer>`; this problem uses the portable `int_list` output type with the same values in the same order.\n\n**Constraints:**\n- `1 <= nums.length <= 10^5`\n- `1 <= nums[i] <= nums.length`\n", "solution": "## Approach\n\nFlag each seen value in a boolean table of size `n+1`, which is valid because inputs lie in `1..n`. Then walk `1` through `n` and gather every index that stayed unflagged. The walk is already increasing, so the answer arrives sorted.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), two linear passes.\n- **Space Complexity:** O(n) for the presence table.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findDisappearedNumbers(self, nums: List[int]) -> List[int]:\n n = len(nums)\n present = [False] * (n + 1)\n for x in nums:\n if 1 <= x <= n:\n present[x] = True\n return [i for i in range(1, n + 1) if not present[i]]\n```\n", "starter": {"go": "package main\n\nfunc FindDisappearedNumbers(nums []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def findDisappearedNumbers(self, nums: List[int]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findDisappearedNumbers(vector<int>& nums) {\n return {};\n }\n};"}, "fn": "findDisappearedNumbers", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int_list", "tests": [["[4,3,2,7,8,2,3,1]"], ["[1,1]"], ["[1]"], ["[2,2]"], ["[1,2,3,4,5]"], ["[2,2,2,2]"], ["[3,3,3,3]"], ["[1,1,1,1]"], ["[5,4,3,2,1]"], ["[1,2,1,2]"], ["[4,3,2,7,8,2,3,1,1]"], ["[10,2,5,10,9,1,1,4,3,7]"], ["[1,2,3,1,2,3]"], ["[2,1]"], ["[1,2,3,4]"], ["[2,2,2,2,2]"], ["[1,1,1,1,1]"], ["[3,1,2]"], ["[2,3,1,5,5]"], ["[6,5,4,3,2,1]"], ["[1,3,3,3,3]"], ["[4,4,4,1,2]"], ["[7,7,7,7,7,7,7]"], ["[5,5,5,5,1]"], ["[2,1,3,1,2,3]"], ["[8,8,7,7,6,6,5,5]"], ["[3,2,1]"], ["[1,2,4,4]"], ["[6,1,2,3,4,5,6]"], ["[9,8,7,6,5,4,3,2,1]"]], "expected": [[5, 6], [2], [], [1], [], [1, 3, 4], [1, 2, 4], [2, 3, 4], [], [3, 4], [5, 6, 9], [6, 8], [4, 5, 6], [], [], [1, 3, 4, 5], [2, 3, 4, 5], [], [4], [], [2, 4, 5], [3, 5], [1, 2, 3, 4, 5, 6], [2, 3, 4], [4, 5, 6], [1, 2, 3, 4], [], [3], [7], []], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "762", "slug": "find-anagram-mappings", "id": 762, "title": "Find Anagram Mappings", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/find-anagram-mappings/", "examples": [{"input": "nums1 = [12,28,46,32,50], nums2 = [50,12,32,46,28]", "output": "[1,4,3,2,0]", "explanation": "Each value in nums1 is paired with an equal value in nums2; repeated values may use any matching slot."}, {"input": "nums1 = [84,46], nums2 = [84,46]", "output": "[0,1]"}, {"input": "nums1 = [1,1,2], nums2 = [2,1,1]", "output": "[1,2,0]", "explanation": "The two 1s share nums2 slots 1 and 2 in either order."}], "hints": ["Record every position of each value in the second array, for example with a map from value to a queue of indices.", "Then walk the first array once, popping one stored index for each value.", "The checker accepts any pairing of equal values, so duplicates need no special ordering."], "statement": "Given two integer arrays `nums1` and `nums2` that hold exactly the same multiset of values (the second is a rearrangement of the first), build an index map for the first array into the second.\n\nFor every position `i` in `nums1`, pick a position `P[i]` in `nums2` so that the values match: `nums1[i] == nums2[P[i]]`. When a value occurs several times, its copies may be matched to the repeated positions in any order. Return the array `P`.\n\nMore than one answer can be valid; any mapping that pairs equal values is accepted.\n\n**Constraints:**\n- `1 <= nums1.length == nums2.length <= 100`\n- `0 <= nums1[i], nums2[i] <= 10^5`\n- `nums2` is a permutation of `nums1`\n", "solution": "## Approach\n\nCollect the positions of every value in the second array with a dictionary from value to a list of indices. Then scan the first array once, popping one stored index for each value to form the answer. Duplicates naturally consume distinct slots in order.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the array length. Each element is visited a constant number of times.\n- **Space Complexity:** O(n) for the value-to-indices table and the output.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import defaultdict\nclass Solution:\n def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]:\n pos = defaultdict(list)\n for j, v in enumerate(nums2):\n pos[v].append(j)\n ans = []\n for v in nums1:\n ans.append(pos[v].pop())\n return ans\n```\n", "starter": {"go": "package main\n\nfunc AnagramMappings(nums1 []int, nums2 []int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def anagramMappings(self, nums1: List[int], nums2: List[int]) -> List[int]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> anagramMappings(vector<int>& nums1, vector<int>& nums2) {\n return {};\n }\n};"}, "fn": "anagramMappings", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}], "outputType": "int_array", "tests": [["[12,28,46,32,50]", "[50,12,32,46,28]"], ["[84,46]", "[84,46]"], ["[1,1,2]", "[2,1,1]"], ["[0]", "[0]"], ["[5,5,5]", "[5,5,5]"], ["[1,2,3]", "[3,2,1]"], ["[10,20,30,40]", "[40,30,20,10]"], ["[7,7,8,8]", "[8,7,8,7]"], ["[100000,0,50000]", "[0,50000,100000]"], ["[1]", "[1]"], ["[2,2,2,3,3]", "[3,2,3,2,2]"], ["[9,8,7,6,5,4]", "[4,5,6,7,8,9]"], ["[0,0,1]", "[1,0,0]"], ["[42,42]", "[42,42]"], ["[3,1,2,1,3]", "[1,3,1,2,3]"], ["[99999,100000]", "[100000,99999]"], ["[4,3,2,1,0]", "[0,1,2,3,4]"], ["[11,22,11,22]", "[22,11,22,11]"], ["[6,5,4,3,2,1,0]", "[0,1,2,3,4,5,6]"], ["[13]", "[13]"], ["[1,2,1,2,1,2]", "[2,1,2,1,2,1]"], ["[0,1,2,3,4,5,6,7,8,9]", "[9,8,7,6,5,4,3,2,1,0]"], ["[77,77,77,77]", "[77,77,77,77]"], ["[25,50,75]", "[75,25,50]"], ["[8,6,7,5,3,0,9]", "[0,3,5,6,7,8,9]"], ["[100,200,100,200,300]", "[300,200,100,200,100]"], ["[1,3,5,7,9,2,4,6,8,0]", "[0,1,2,3,4,5,6,7,8,9]"], ["[33,44,55,33,44]", "[44,33,44,55,33]"]], "expected": [[1, 4, 3, 2, 0], [0, 1], [1, 2, 0], [0], [0, 1, 2], [2, 1, 0], [3, 2, 1, 0], [1, 3, 0, 2], [2, 0, 1], [0], [1, 3, 4, 0, 2], [5, 4, 3, 2, 1, 0], [1, 2, 0], [0, 1], [1, 0, 3, 2, 4], [1, 0], [4, 3, 2, 1, 0], [1, 0, 3, 2], [6, 5, 4, 3, 2, 1, 0], [0], [1, 0, 3, 2, 5, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3], [1, 2, 0], [5, 3, 4, 2, 1, 0, 6], [2, 1, 4, 3, 0], [1, 3, 5, 7, 9, 2, 4, 6, 8, 0], [1, 0, 3, 4, 2]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "831", "slug": "find-and-replace-in-string", "id": 831, "title": "Find And Replace in String", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/find-and-replace-in-string/", "examples": [{"input": "s = \"abcd\", indices = [0,2], sources = [\"a\",\"cd\"], targets = [\"eee\",\"ffff\"]", "output": "\"eeebffff\"", "explanation": "Both sources match, so both replacements fire."}, {"input": "s = \"abcd\", indices = [0,2], sources = [\"ab\",\"ec\"], targets = [\"eee\",\"ffff\"]", "output": "\"eeecd\"", "explanation": "Only the first source matches."}, {"input": "s = \"vmokgggqzp\", indices = [3,5,1], sources = [\"kg\",\"nnn\",\"mo\"], targets = [\"s\",\"asa\",\"b\"]", "output": "\"vbsggqzp\"", "explanation": "Both \"mo\" and \"kg\" match; \"nnn\" does not."}], "hints": ["Reorder the edits by index first; the input order carries no meaning.", "Compare each source against the original string (never against partially replaced text).", "Advance a single cursor over the original string so matches emit targets and mismatches emit the raw character."], "statement": "You are given a base string `s` plus three parallel arrays describing candidate edits: `indices[i]` is a start position in `s`, `sources[i]` is the text expected at that position, and `targets[i]` is its replacement. Process all edits simultaneously against the original string:\n\n- Sort the edits by their start index.\n- Walk the original string from left to right. When you reach an edit whose source text exactly matches the substring of `s` beginning at its index, emit the replacement and skip past the matched source.\n- If the source does not match there, leave that original character in place and continue (later edits still apply).\n- Overlapping edits never both fire, because the walk only advances forward.\n\nReturn the final string.\n\n**Constraints:**\n- `1 <= s.length <= 1000`\n- `1 <= indices.length <= 100`\n- `0 <= indices[i] < s.length`\n- `1 <= sources[i].length, targets[i].length <= 50`\n- All `indices` values are distinct\n", "solution": "## Approach\n\nSort the edit indices so they are visited left to right, then sweep a single cursor over the original string. Before each edit, copy any untouched gap characters directly to the answer; when the source matches the original at that index, emit the target and jump past the source, otherwise leave the cursor so the raw text flows through. A trailing copy drains the remainder after the last edit.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m log m + n * L) where m is the edit count, n the string length, and L the longest source.\n- **Space Complexity:** O(n + total target length) for the output.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findReplaceString(self, s: str, indices: List[int], sources: List[str], targets: List[str]) -> str:\n order = sorted(range(len(indices)), key=lambda i: indices[i])\n ans = []\n pos = 0\n for oi in order:\n idx = indices[oi]\n if idx < pos:\n continue\n while pos < idx:\n ans.append(s[pos])\n pos += 1\n if s.startswith(sources[oi], idx):\n ans.append(targets[oi])\n pos = idx + len(sources[oi])\n ans.append(s[pos:])\n return \"\".join(ans)\n```\n", "starter": {"go": "package main\n\nfunc FindReplaceString(s string, indices []int, sources []string, targets []string) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def findReplaceString(self, s: str, indices: List[int], sources: List[str], targets: List[str]) -> str:\n return \"\"\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string findReplaceString(string s, vector<int>& indices, vector<string>& sources, vector<string>& targets) {\n return \"\";\n }\n};"}, "fn": "findReplaceString", "params": [{"name": "s", "type": "string"}, {"name": "indices", "type": "int_array"}, {"name": "sources", "type": "string_array"}, {"name": "targets", "type": "string_array"}], "outputType": "string", "tests": [["abcd", "[0, 2]", "['a', 'cd']", "['eee', 'ffff']"], ["abcd", "[0, 2]", "['ab', 'ec']", "['eee', 'ffff']"], ["vmokgggqzp", "[3, 5, 1]", "['kg', 'nnn', 'mo']", "['s', 'asa', 'b']"], ["abcd", "[0]", "['a']", "['eee']"], ["abcd", "[0]", "['b']", "['eee']"], ["abcd", "[3]", "['d']", "['x']"], ["abcd", "[3]", "['c']", "['x']"], ["abcde", "[2, 0]", "['c', 'a']", "['X', 'Y']"], ["aaaa", "[0, 1, 2, 3]", "['a', 'a', 'a', 'a']", "['b', 'b', 'b', 'b']"], ["hello", "[1]", "['ell']", "['ELL']"], ["hello", "[0, 1]", "['he', 'el']", "['HE', 'EL']"], ["abcdef", "[1, 3]", "['bc', 'de']", "['X', 'Y']"], ["abcdef", "[3, 1]", "['de', 'bc']", "['Y', 'X']"], ["abc", "[0, 1, 2]", "['a', 'b', 'c']", "['x', 'y', 'z']"], ["abc", "[0, 1, 2]", "['x', 'y', 'z']", "['1', '2', '3']"], ["abcdefg", "[2]", "['cde']", "['XYZ']"], ["abcdefg", "[2]", "['cdf']", "['XYZ']"], ["x", "[0]", "['x']", "['longer replacement']"], ["longer replacement", "[0]", "['longer replacement']", "['x']"], ["aaaaabaaaaa", "[5, 0]", "['b', 'a']", "['B', 'A']"], ["abcd", "[1, 2]", "['bcd', 'cd']", "['X', 'Y']"], ["the quick fox", "[4, 10]", "['quick', 'fox']", "['slow', 'dog']"], ["foo bar baz", "[8, 0, 4]", "['baz', 'foo', 'bar']", "['1', '2', '3']"], ["abcabc", "[0, 3]", "['abc', 'abc']", "['x', 'y']"], ["abcabc", "[0, 3]", "['abd', 'abc']", "['x', 'y']"], ["zzz", "[0, 1]", "['zz', 'zz']", "['a', 'b']"], ["onetwo", "[3, 0]", "['two', 'one']", "['2', '1']"], ["mississippi", "[0, 4, 7]", "['miss', 'issi', 'ppi']", "['M', 'I', 'P']"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "881", "slug": "find-and-replace-pattern", "id": 881, "title": "Find and Replace Pattern", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/find-and-replace-pattern/", "examples": [{"input": "words = [\"abc\",\"deq\",\"mee\",\"aqq\",\"dkd\",\"ccc\"], pattern = \"abb\"", "output": "[\"mee\",\"aqq\"]", "explanation": "\"mee\" and \"aqq\" repeat their last two letters exactly like \"abb\" does. \"abc\" and \"deq\" use three distinct letters, \"dkd\" repeats the first and last, and \"ccc\" repeats everything."}, {"input": "words = [\"a\",\"b\",\"c\"], pattern = \"a\"", "output": "[\"a\",\"b\",\"c\"]", "explanation": "Every single-letter word trivially shares the shape of a one-letter pattern."}], "hints": ["Reduce each word to its repetition shape by replacing every letter with the index of its first appearance.", "A word fits exactly when its shape equals the pattern's shape; compare the two encodings."], "statement": "You are given a list of lowercase `words` and a lowercase `pattern`. A word fits the pattern when its letters follow the same repetition shape: the first distinct letter of the word lines up with the first distinct letter of the pattern, the second distinct with the second distinct, and so on, consistently in both directions.\n\nReturn every word that fits, keeping their original order.\n\n**Constraints:**\n- `1 <= words.length <= 50`\n- `1 <= words[i].length, pattern.length <= 20`\n- All strings hold lowercase English letters.\n", "solution": "## Approach\n\nEncode every string by its repetition shape: scan left to right, numbering each new distinct letter 0, 1, 2, ... in order of first appearance, and record the number sequence. Two strings share the same letter-pattern exactly when their encodings match, so encode the pattern once and keep every word whose encoding equals it.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(W * L), where W is the number of words and L is their maximum length.\n- **Space Complexity:** O(L) for the encoding buffers besides the output.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:\n def shape(w):\n seen = {}\n code = []\n for c in w:\n if c not in seen:\n seen[c] = len(seen)\n code.append(seen[c])\n return code\n\n target = shape(pattern)\n return [w for w in words if shape(w) == target]\n```\n", "starter": {"go": "package main\n\nfunc FindAndReplacePattern(words []string, pattern string) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def findAndReplacePattern(self, words: List[str], pattern: str) -> List[str]:\n pass", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> findAndReplacePattern(vector<string>& words, string pattern) {\n return {};\n }\n};"}, "fn": "findAndReplacePattern", "params": [{"name": "words", "type": "string_array"}, {"name": "pattern", "type": "string"}], "outputType": "string_list", "tests": [["[\"abc\",\"deq\",\"mee\",\"aqq\",\"dkd\",\"ccc\"]", "abb"], ["[\"a\",\"b\",\"c\"]", "a"], ["[\"aa\",\"bb\",\"ab\"]", "aa"], ["[\"ab\",\"ba\",\"cc\"]", "ab"], ["[\"xyz\",\"abc\",\"def\"]", "abc"], ["[\"aaa\",\"bbb\",\"aba\"]", "abc"], ["[\"abcd\",\"efgh\"]", "wxyz"], ["[\"abca\",\"zbxz\",\"aaaa\"]", "abca"], ["[\"qqq\",\"www\",\"ewe\"]", "abc"], ["[\"hello\",\"world\"]", "abcde"], ["[\"cat\",\"dog\",\"pig\"]", "zzz"], ["[\"abc\",\"def\",\"ghi\"]", "xxx"], ["[\"abab\",\"cdcd\",\"efef\",\"aaaa\"]", "abab"], ["[\"abcde\",\"fghij\",\"klmno\"]", "abcde"], ["[\"aab\",\"xxy\",\"xyz\",\"xyx\"]", "aab"], ["[\"bad\",\"dad\",\"mad\"]", "aba"], ["[\"one\",\"two\",\"six\",\"ten\"]", "abc"], ["[\"foo\",\"bar\",\"baz\"]", "abb"], ["[\"abcabc\",\"defdef\",\"abcdef\"]", "abcabc"], ["[\"qwerty\",\"asdfgh\"]", "abcdef"], ["[\"aaaaab\",\"bbbbbz\"]", "aaaaab"], ["[\"ab\",\"aa\",\"bb\"]", "cc"], ["[\"abcd\",\"abce\",\"abcc\"]", "abca"], ["[\"mnop\",\"qrst\",\"mnpm\"]", "abac"], ["[\"a\"]", "b"], ["[\"ababa\",\"bcbcb\",\"abcab\"]", "ababa"], ["[\"test\",\"best\",\"rest\",\"zest\"]", "abca"], ["[\"cookie\",\"biscuit\",\"cake\"]", "abccde"]], "expected": [["mee", "aqq"], ["a", "b", "c"], ["aa", "bb"], ["ab", "ba"], ["xyz", "abc", "def"], [], ["abcd", "efgh"], ["abca", "zbxz"], [], ["world"], [], [], ["abab", "cdcd", "efef"], ["abcde", "fghij", "klmno"], ["aab", "xxy"], ["dad"], ["one", "two", "six", "ten"], ["foo"], ["abcabc", "defdef"], ["qwerty", "asdfgh"], ["aaaaab", "bbbbbz"], ["aa", "bb"], [], [], ["a"], ["ababa", "bcbcb"], ["test"], []], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "573", "slug": "find-bottom-left-tree-value", "id": 573, "title": "Find Bottom Left Tree Value", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/find-bottom-left-tree-value/", "examples": [{"input": "root = [2,1,3]", "output": "1", "explanation": "The deepest level holds 1 and 3; the leftmost of the two is 1."}, {"input": "root = [1,2,3,4,null,5,6,null,null,7]", "output": "7", "explanation": "Level by level the tree has [1], [2,3], [4,5,6], [7]; the bottom row's only entry is 7."}, {"input": "root = [1]", "output": "1", "explanation": "A single node is both the top and the bottom-left choice."}], "hints": ["Breadth-first search visits rows top to bottom; the first node of the last row visited is the answer.", "Enqueue right children before left ones and the final node dequeued is the bottom-left value."], "statement": "In a binary tree, look at the deepest level that contains any node and pick the leftmost node sitting on that level. Return its value.\n\n**Constraints:**\n- The number of nodes is in the range `[1, 10^4]`\n- `-2^31 <= Node.val <= 2^31 - 1`\n", "solution": "## Approach\n\nScan the tree breadth-first, one row at a time, and remember the first value seen in each row. Because rows are processed from top to bottom, the stored value after the final row is exactly the leftmost entry of the deepest level.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), each node enters and leaves the queue once.\n- **Space Complexity:** O(w), where w is the widest row held in the queue.\n\n## Implementation\n\n```python\nfrom collections import deque\n\nclass Solution:\n def findBottomLeftValue(self, root) -> int:\n q = deque([root])\n ans = root.val\n while q:\n ans = q[0].val\n for _ in range(len(q)):\n cur = q.popleft()\n if cur.left is not None:\n q.append(cur.left)\n if cur.right is not None:\n q.append(cur.right)\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 FindBottomLeftValue(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\nclass Solution:\n def findBottomLeftValue(self, root) -> int:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n int findBottomLeftValue(TreeNode* root) {\n \n }\n};"}, "fn": "findBottomLeftValue", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int", "tests": [["[2,1,3]"], ["[1,2,3,4,null,5,6,null,null,7]"], ["[1]"], ["[1,2,3]"], ["[1,null,2,null,3]"], ["[3,1,5,0,2,4,6]"], ["[1,2,null,3,null,4]"], ["[5,4,6,3,null,null,7]"], ["[0,-1,-2]"], ["[10,5,15,3,7,null,18]"], ["[1,2,3,4,5,6,7,8]"], ["[7,6,5,4,3,2,1]"], ["[2,null,3,null,4,null,5]"], ["[1,2,2,3,3,null,null,4,4]"], ["[100]"], ["[-10,9,20,null,null,15,7]"], ["[1,2,3,null,4,null,5]"], ["[4,2,6,1,3,5,7,0]"], ["[1,null,3,2]"], ["[6,4,8,3,5,7,9,2]"], ["[1,2,null,null,3]"], ["[5,null,6,null,7]"], ["[9,7,null,5,null,3]"], ["[1,2,3,4,null,null,5]"], ["[2147483647]"], ["[-2147483648,1,2]"], ["[0,0,0,0,0]"], ["[4,1,null,2,null,3]"]], "expected": [1, 7, 1, 2, 3, 0, 4, 3, -1, 3, 8, 4, 5, 4, 100, 15, 4, 0, 2, 2, 3, 7, 3, 4, 2147483647, 1, 0, 3], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "224", "slug": "find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree", "id": 224, "title": "Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree", "difficulty": "Hard", "category": "graph", "link": "https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/", "examples": [{"input": "n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]", "output": "[[0,1],[2,3,4,5]]"}, {"input": "n = 4, edges = [[0,1,1],[1,2,1],[2,3,1],[0,3,1]]", "output": "[[],[0,1,2,3]]"}], "hints": ["Compute MST weight. An edge is critical if excluding it raises the weight. Pseudo-critical if forcing it still achieves MST weight."], "statement": "Consider a connected, undirected, weighted graph holding `n` vertices labeled `0` through `n - 1`. Its edges arrive as an array `edges`, where `edges[i] = [ai, bi, weighti]` describes a two-way link between `ai` and `bi` carrying weight `weighti`. A minimum spanning tree (MST) is a cycle-free collection of edges that still links every vertex while keeping the summed weight as low as achievable.\n\nClassify the edges of this graph's MSTs into two groups: an MST edge is critical when removing it from the graph forces every spanning tree to become strictly heavier than the optimum; it is pseudo-critical when it is absent from at least one MST yet present in a different MST of the same optimal weight.\n\nReport the original positions of these edges as two lists. Either ordering of the indices is acceptable.\n\n**Constraints:**\n- `2 <= n <= 100`\n- `1 <= edges.length <= min(200, n * (n - 1) / 2)`\n- `edges[i].length == 3`\n- `0 <= ai < bi < n`\n- `1 <= weighti <= 1000`\n- Every pair `(ai, bi)` appears at most once.\n", "solution": "## Approach\n\nSort edges and compute the base MST weight with Kruskal. An edge is critical if MST without it is heavier. It is pseudo-critical if forcing it still yields the base weight (and it is not critical).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(E^2 \u03b1(n))\n- **Space Complexity:** O(E)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n m = len(edges)\n es = [edges[i] + [i] for i in range(m)]\n es.sort(key=lambda e: e[2])\n def mst(exclude=-1, force=-1):\n parent = list(range(n))\n def find(x):\n while parent[x] != x:\n parent[x] = parent[parent[x]]\n x = parent[x]\n return x\n def union(a, b):\n a, b = find(a), find(b)\n if a == b:\n return False\n parent[a] = b\n return True\n w = used = 0\n if force != -1:\n for u, v, wt, i in es:\n if i == force:\n union(u, v)\n w += wt\n used += 1\n break\n for u, v, wt, i in es:\n if i == exclude or i == force:\n continue\n if union(u, v):\n w += wt\n used += 1\n return w if used == n - 1 else 10**18\n base = mst()\n crit, pseudo = [], []\n for u, v, wt, i in es:\n if mst(exclude=i) > base:\n crit.append(i)\n elif mst(force=i) == base:\n pseudo.append(i)\n return [crit, pseudo]\n```\n", "starter": {"go": "package main\n\nfunc FindCriticalAndPseudoCriticalEdges(n int, edges [][]int) [][]int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> findCriticalAndPseudoCriticalEdges(int n, vector<vector<int>>& edges) {\n return {};\n }\n};"}, "fn": "findCriticalAndPseudoCriticalEdges", "params": [{"name": "n", "type": "int"}, {"name": "edges", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["5", "[[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]"], ["4", "[[0,1,1],[1,2,1],[2,3,1],[0,3,1]]"], ["3", "[[0,1,1],[1,2,1],[0,2,1]]"], ["2", "[[0,1,5]]"], ["6", "[[0,1,1],[1,2,1],[0,2,1],[2,3,4],[3,4,2],[3,5,2],[4,5,2]]"], ["2", "[[0, 1, 10]]"], ["3", "[[0, 1, 2], [1, 2, 3], [0, 2, 4]]"], ["3", "[[0, 1, 1], [1, 2, 2], [0, 2, 10]]"], ["4", "[[0, 1, 1], [1, 2, 2], [2, 3, 3], [0, 3, 4], [0, 2, 5]]"], ["4", "[[0, 1, 1], [0, 2, 1], [0, 3, 1], [1, 2, 1], [1, 3, 1], [2, 3, 1]]"], ["4", "[[0, 1, 5], [1, 2, 6], [2, 3, 7], [0, 3, 20]]"], ["5", "[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4]]"], ["5", "[[0, 1, 1], [0, 2, 1], [0, 3, 1], [0, 4, 1], [1, 2, 1], [3, 4, 1]]"], ["5", "[[0, 1, 4], [1, 2, 3], [2, 3, 2], [3, 4, 1], [0, 4, 10], [1, 3, 5]]"], ["6", "[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [0, 5, 15]]"], ["6", "[[0, 1, 2], [0, 2, 2], [1, 2, 2], [2, 3, 1], [3, 4, 1], [4, 5, 1], [3, 5, 1]]"], ["3", "[[0, 1, 5], [1, 2, 5], [0, 2, 6]]"], ["4", "[[0, 1, 2], [1, 2, 2], [2, 3, 2], [0, 2, 2], [1, 3, 2]]"], ["5", "[[0, 1, 1], [1, 2, 1], [2, 3, 1], [3, 4, 1], [0, 4, 1]]"], ["5", "[[0, 1, 7], [1, 2, 8], [2, 3, 9], [3, 4, 10], [0, 2, 20], [1, 4, 30]]"], ["6", "[[0, 1, 3], [1, 2, 1], [0, 2, 2], [3, 4, 1], [4, 5, 2], [3, 5, 3], [1, 3, 4]]"], ["4", "[[0, 1, 10], [1, 2, 1], [2, 3, 1], [0, 3, 1], [0, 2, 5]]"], ["3", "[[0, 1, 1000], [1, 2, 1], [0, 2, 500]]"], ["7", "[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [0, 6, 50]]"], ["5", "[[0, 1, 2], [0, 2, 3], [1, 2, 1], [1, 3, 4], [2, 3, 5], [3, 4, 6], [2, 4, 7]]"], ["6", "[[0, 1, 1], [2, 3, 1], [4, 5, 1], [0, 2, 2], [1, 3, 2], [3, 5, 2], [0, 5, 3]]"], ["4", "[[0, 1, 3], [0, 2, 1], [0, 3, 2], [1, 2, 4], [1, 3, 5], [2, 3, 6]]"], ["8", "[[0, 1, 1], [1, 2, 2], [2, 3, 3], [3, 4, 4], [4, 5, 5], [5, 6, 6], [6, 7, 7], [0, 7, 100]]"], ["5", "[[0, 1, 1], [1, 2, 5], [2, 3, 5], [3, 4, 1], [0, 4, 5], [1, 4, 5], [0, 3, 5]]"], ["6", "[[0, 1, 4], [0, 2, 3], [0, 3, 2], [0, 4, 5], [0, 5, 1], [1, 2, 6], [4, 5, 7]]"]], "expected": [[[0, 1], [2, 3, 4, 5]], [[], [0, 1, 2, 3]], [[], [0, 1, 2]], [[0], []], [[3], [0, 1, 2, 4, 5, 6]], [[0], []], [[0, 1], []], [[0, 1], []], [[0, 1, 2], []], [[], [0, 1, 2, 3, 4, 5]], [[0, 1, 2], []], [[0, 1, 2, 3], []], [[], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3], []], [[0, 1, 2, 3, 4], []], [[3], [0, 1, 2, 4, 5, 6]], [[0, 1], []], [[], [0, 1, 2, 3, 4]], [[], [0, 1, 2, 3, 4]], [[0, 1, 2, 3], []], [[1, 2, 3, 4, 6], []], [[1, 2, 3], []], [[1, 2], []], [[0, 1, 2, 3, 4, 5], []], [[0, 2, 3, 5], []], [[0, 1, 2, 5], [3, 4]], [[0, 1, 2], []], [[0, 1, 2, 3, 4, 5, 6], []], [[0, 3], [1, 2, 4, 5, 6]], [[0, 1, 2, 3, 4], []]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "643", "slug": "find-duplicate-file-in-system", "id": 643, "title": "Find Duplicate File in System", "difficulty": "Medium", "category": "hash-table", "link": "https://leetcode.com/problems/find-duplicate-file-in-system/", "examples": [{"input": "paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd)\",\"root/c/d 4.txt(efgh)\",\"root 4.txt(efgh)\"]", "output": "[[\"root/a/2.txt\",\"root/c/d/4.txt\",\"root/4.txt\"],[\"root/a/1.txt\",\"root/c/3.txt\"]] (order may vary)", "explanation": "Files holding abcd form one group; files holding efgh form another."}, {"input": "paths = [\"root/a 1.txt(abcd) 2.txt(efgh)\",\"root/c 3.txt(abcd) 4.txt(efgh)\"]", "output": "[[\"root/a/1.txt\",\"root/c/3.txt\"],[\"root/a/2.txt\",\"root/c/4.txt\"]] (order may vary)", "explanation": "Each content value appears twice, so two groups are reported."}, {"input": "paths = [\"root/a 1.txt(abcd)\"]", "output": "[]", "explanation": "A single file has no partner, so nothing is reported."}], "hints": ["Split each entry on spaces: the first token is the folder, later tokens look like name(content).", "Key a hash map by the content text and push dir + '/' + name into that bucket.", "Return only buckets holding two or more paths; lone files are not duplicates.", "Adaptation: the input list maps to string_array and the grouped output maps to string_list_2d in this judge."], "statement": "You receive a list of folder descriptions. Each description names one folder followed by the files directly inside it, where every file token carries its stored text in trailing parentheses.\n\nFor instance, the description `root/a 1.txt(abcd) 2.txt(efgh)` means folder `root/a` contains `1.txt` holding `abcd` and `2.txt` holding `efgh`.\n\nTwo files count as duplicates exactly when their stored texts match character for character, no matter how their names or folders differ. Collect every maximal set of files sharing one text, but only keep sets with at least two members. Return those sets as lists of full paths built with a slash between folder and file name, such as `root/a/1.txt`.\n\nThe order of the groups and the order inside each group do not matter.\n\n**Constraints:**\n- Each folder description holds at least one file.\n- Folder names, file names, and stored texts use only letters and digits.\n- Stored text length is between 1 and 50 characters.\n- Total file count is modest (fits easily in memory).\n\n*Adaptation: the input list maps to `string_array` and the grouped output maps to `string_list_2d` in this judge.*\n", "solution": "## Approach\n\nParse every folder line into its directory plus file tokens. For each token, cut at the opening parenthesis to separate the file name from the stored text (dropping the final closing parenthesis), then join directory and name into a full path. File the path in a hash bucket keyed by the stored text. After all lines are scanned, emit only buckets with two or more entries, since singletons have no duplicate partner.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(S), where S is the total character count across all descriptions. Each character is scanned once.\n- **Space Complexity:** O(S) for the buckets holding every full path.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findDuplicate(self, paths: List[str]) -> List[List[str]]:\n groups = {}\n for entry in paths:\n parts = entry.split(\" \")\n d = parts[0]\n for token in parts[1:]:\n lp = token.index(\"(\")\n name = token[:lp]\n content = token[lp + 1:-1]\n groups.setdefault(content, []).append(d + \"/\" + name)\n return [g for g in groups.values() if len(g) >= 2]\n```\n", "starter": {"go": "package main\n\nfunc FindDuplicate(paths []string) [][]string {\n \n}", "python": "from typing import List\nclass Solution:\n def findDuplicate(self, paths: List[str]) -> List[List[str]]:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<string>> findDuplicate(vector<string>& paths) {\n return {};\n }\n};"}, "fn": "findDuplicate", "params": [{"name": "paths", "type": "string_array"}], "outputType": "string_list_2d", "tests": [["['root/a 1.txt(abcd) 2.txt(efgh)', 'root/c 3.txt(abcd)', 'root/c/d 4.txt(efgh)', 'root 4.txt(efgh)']"], ["['root/a 1.txt(abcd) 2.txt(efgh)', 'root/c 3.txt(abcd) 4.txt(efgh)']"], ["['root/a 1.txt(abcd)']"], ["['root/a 1.txt(x)']"], ["['a 1.txt(a) 2.txt(a)', 'b 3.txt(a)']"], ["['root/a 1.txt(abc) 2.txt(def)', 'root/b 3.txt(ghi)']"], ["['d 1.txt(aa) 2.txt(bb) 3.txt(aa)']"], ["['x 1.txt(p)', 'y 2.txt(q)', 'z 3.txt(p)']"], ["['root 1.txt(a) 2.txt(a) 3.txt(a)']"], ["['r 1.txt(1) 2.txt(2) 3.txt(1) 4.txt(2)']"], ["['a 1.txt(content1)', 'a 2.txt(content1)']"], ["['dir f1.txt(zzz) f2.txt(zzz) f3.txt(yyy)']"], ["['r/a 1.txt(ab12) 2.txt(cd34)', 'r/b 3.txt(ab12)']"], ["['root 1.txt(A) 2.txt(B)', 'root/sub 3.txt(A) 4.txt(C)']"], ["['m 1.txt(longcontent123) 2.txt(longcontent123)']"], ["['a 1.txt(q)', 'b 2.txt(q)', 'c 3.txt(q)', 'd 4.txt(r)']"], ["['root 1.txt(1)', 'root 2.txt(1)']"], ["['d1 a.txt(x) b.txt(y)', 'd2 c.txt(x) d.txt(y)', 'd3 e.txt(x)']"], ["['top 1.txt(same) 2.txt(same) 3.txt(diff) 4.txt(same)']"], ["['a 1.txt(v1) 2.txt(v2) 3.txt(v3) 4.txt(v1) 5.txt(v2)']"], ["['r 1.txt(abc123)']"], ["['dir1 1.txt(a1) 2.txt(b2)', 'dir2 3.txt(a1) 4.txt(b2) 5.txt(c3)']"], ["['x y.txt(hello) z.txt(world)', 'w y.txt(hello)']"], ["['root/a/b/c 1.txt(k) 2.txt(k)']"], ["['a 1.txt(1)', 'b 2.txt(2)', 'c 3.txt(3)']"], ["['deep/a/b 1.txt(dup) 2.txt(one)', 'deep/a/c 3.txt(dup)']"], ["['r 1.txt(abcdefghijklmnopqrstuvwxyz0123456789) 2.txt(abcdefghijklmnopqrstuvwxyz0123456789)']"], ["['s 1.txt(mix1) 2.txt(mix2) 3.txt(mix1) 4.txt(mix2) 5.txt(mix3)']"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "672", "slug": "find-duplicate-subtrees", "id": 672, "title": "Find Duplicate Subtrees", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/find-duplicate-subtrees/", "examples": [{"input": "root = [1,2,3,4,null,2,4,null,null,4]", "output": "[\"4,#,#\",\"2,4,#,#,#\"]", "explanation": "The leaf 4 occurs three times and the branch 2 -> 4 occurs twice; each repeated shape is reported once using preorder codes where # marks a missing child."}, {"input": "root = [2,1,1]", "output": "[\"1,#,#\"]", "explanation": "Both leaves hold 1, so the single-leaf code is the only repeat."}, {"input": "root = [2,2,2,3,null,3,null]", "output": "[\"3,#,#\",\"2,3,#,#,#\"]", "explanation": "Leaf 3 repeats and so does the parent branch holding it."}], "hints": ["Encode every branch as value + left code + right code with a marker for empty children, so equal shapes map to equal strings.", "Count how often each code appears with a hash table and emit a code the second time it is seen.", "Sort the collected codes before returning so the order is stable."], "statement": "You are given the root of a binary tree whose nodes hold integer values.\n\nTwo branches are considered the same shape when they have equal values placed in equal positions: either both are empty, or both roots share the value and their left sides match and their right sides match.\n\nA shape is repeated when two or more distinct nodes start that same shape. Collect each repeated shape exactly once.\n\n**Adaptation:** instead of handing back tree nodes, return each repeated shape as a preorder code. Write a node as its value, then its left code, then its right code, separated by commas; write `#` for a missing child. A leaf holding 4 therefore becomes `4,#,#`.\n\nReturn the codes in any order (the checker sorts them).\n\n**Constraints:**\n- `0 <= number of nodes <= 3000`\n- `-200 <= node value <= 200`\n", "solution": "## Approach\n\nGive every branch a preorder code made of its value plus the codes of its children, using `#` for empty spots. Equal branches produce equal codes. Walk the tree bottom-up, count each code in a hash table, and record a code the second time it appears. Sorting the recorded codes makes the answer stable.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) in the worst case from string building over n nodes, O(n) average with short codes.\n- **Space Complexity:** O(n^2) for the stored codes in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findDuplicateSubtrees(self, root) -> List[str]:\n from collections import defaultdict\n count = defaultdict(int)\n ans = []\n def code(n):\n if not n:\n return \"#\"\n key = f\"{n.val},{code(n.left)},{code(n.right)}\"\n count[key] += 1\n if count[key] == 2:\n ans.append(key)\n return key\n code(root)\n return sorted(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 FindDuplicateSubtrees(root *TreeNode) []string {\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 findDuplicateSubtrees(self, root) -> List[str]:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> findDuplicateSubtrees(TreeNode* root) {\n return {};\n }\n};"}, "fn": "findDuplicateSubtrees", "params": [{"name": "root", "type": "tree_node"}], "outputType": "string_list", "tests": [["[1,2,3,4,null,2,4,null,null,4]"], ["[2,1,1]"], ["[2,2,2,3,null,3,null]"], ["[]"], ["[1]"], ["[1,2,3]"], ["[1,2,3,null,null,4,5]"], ["[0,0,0,0,null,null,0]"], ["[1,1,1,1,null,null,1]"], ["[5,4,4,3,null,3,null]"], ["[1,2,2,3,4,4,3]"], ["[1,2,2,null,3,null,3]"], ["[3,2,2,1,null,1,null]"], ["[10,5,15,5,null,null,15]"], ["[1,null,2,null,3,null,4]"], ["[4,2,6,1,3,5,7]"], ["[2,2,2,2,null,null,2]"], ["[1,2,3,4,5,6,7,8,null,null,null,null,null,null,null]"], ["[0,-1,-1,2,null,2,null]"], ["[7,7,7,7,7,7,7]"], ["[1,2,null,3,null,4,null]"], ["[9,6,6,4,null,4,null]"], ["[1,2,3,2,null,null,3]"], ["[5,3,6,2,4,null,null,1,null,null,null]"], ["[2,1,1,null,null,null,1]"], ["[1,2,3,4,null,null,4]"], ["[100,50,150,25,75,125,175,12,null,null,null,null,null,null,null]"], ["[1,2,2,3,null,null,3,4,null,null,4]"]], "expected": [["2,4,#,#,#", "4,#,#"], ["1,#,#"], ["2,3,#,#,#", "3,#,#"], [], [], [], [], ["0,#,#"], ["1,#,#"], ["3,#,#", "4,3,#,#,#"], ["3,#,#", "4,#,#"], ["2,#,3,#,#", "3,#,#"], ["1,#,#", "2,1,#,#,#"], [], [], [], ["2,#,#"], [], ["-1,2,#,#,#", "2,#,#"], ["7,#,#", "7,7,#,#,7,#,#"], [], ["4,#,#", "6,4,#,#,#"], [], [], ["1,#,#"], ["4,#,#"], [], ["4,#,#"]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "800", "slug": "find-eventual-safe-states", "id": 800, "title": "Find Eventual Safe States", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/find-eventual-safe-states/", "examples": [{"input": "graph = [[1,2],[2,3],[5],[0],[5],[],[]]", "output": "[2,4,5,6]", "explanation": "Cycle-free tails are safe."}, {"input": "graph = [[1,2,3,4],[1,2],[3,4],[0,4],[]]", "output": "[4]", "explanation": "Only the terminal survives."}, {"input": "graph = [[],[0,2,3],[3],[4],[]]", "output": "[0,1,2,3,4]", "explanation": "Acyclic graph, all nodes safe."}], "hints": ["Colour vertices during depth-first search: visiting versus fully explored distinguishes cycles from safe tails.", "A node is safe exactly when all of its successors are safe.", "Adaptation: the nested input maps to int_array_2d and the flat output maps to int_list in this judge."], "statement": "You receive a directed graph as an adjacency list `graph`, where `graph[i]` lists the neighbours reached by outgoing edges from node `i`. A node is called safe when every directed walk starting there must eventually arrive at a terminal node (one with no outgoing edges) and therefore can never loop forever.\n\nReturn all safe nodes in increasing numerical order.\n\n**Constraints:**\n- `1 <= graph.length <= 10^4`\n- `0 <= graph[i].length <= graph.length`\n- Values in `graph[i]` are distinct and lie in range\n- Adaptation: the nested input maps to int_array_2d and the flat output maps to int_list in this judge.\n", "solution": "## Approach\n\nDepth-first search colours each vertex as unvisited, currently on the stack, or proven safe. A vertex whose exploration meets a stack vertex lies on or leads to a cycle and is unsafe; otherwise, once all successors are safe, it becomes safe itself. Collecting safe vertices in index order gives the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(V + E), each vertex and edge is processed once.\n- **Space Complexity:** O(V) for colours and recursion plus the output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]:\n n = len(graph)\n color = [0] * n\n def safe(u: int) -> bool:\n if color[u] != 0:\n return color[u] == 2\n color[u] = 1\n for v in graph[u]:\n if not safe(v):\n return False\n color[u] = 2\n return True\n return [i for i in range(n) if safe(i)]\n```\n", "starter": {"go": "package main\n\nfunc EventualSafeNodes(graph [][]int) []int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def eventualSafeNodes(self, graph: List[List[int]]) -> List[int]:\n return []", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> eventualSafeNodes(vector<vector<int>>& graph) {\n return {};\n }\n};"}, "fn": "eventualSafeNodes", "params": [{"name": "graph", "type": "int_array_2d"}], "outputType": "int_list", "tests": [["[[1, 2], [2, 3], [5], [0], [5], [], []]"], ["[[1, 2, 3, 4], [1, 2], [3, 4], [0, 4], []]"], ["[[], [0, 2, 3], [3], [4], []]"], ["[[]]"], ["[[1], [2], [3], []]"], ["[[1], [0]]"], ["[[1, 2], [2], [0]]"], ["[[], [], []]"], ["[[1], [2], []]"], ["[[2], [2], [3], []]"], ["[[1], [2], [0, 3], []]"], ["[[1, 2, 3], [], [], []]"], ["[[1], [2], [3], [1]]"], ["[[0]]"], ["[[], []]"], ["[[1], []]"], ["[[1, 2], [3], [3], []]"], ["[[2, 3], [3], [0], []]"], ["[[1, 2], [0], [0]]"], ["[[], [0]]"], ["[[1, 2], [2, 3], [3, 4], [4], []]"], ["[[1], [1], [1], []]"], ["[[3], [0], [1], [2]]"], ["[[1, 2, 3, 4, 5], [], [], [], [], []]"], ["[[1], [2], [3], [4], []]"], ["[[2], [0], [1]]"], ["[[1, 2], [3, 4], [4, 5], [6], [6], [], []]"], ["[[0, 1], [2], [3], []]"]], "expected": [[2, 4, 5, 6], [4], [0, 1, 2, 3, 4], [0], [0, 1, 2, 3], [], [], [0, 1, 2], [0, 1, 2], [0, 1, 2, 3], [3], [0, 1, 2, 3], [], [], [0, 1], [0, 1], [0, 1, 2, 3], [1, 3], [], [0, 1], [0, 1, 2, 3, 4], [3], [], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4], [], [0, 1, 2, 3, 4, 5, 6], [1, 2, 3]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "262", "slug": "find-first-and-last-position-of-element-in-sorted-array", "id": 262, "title": "Find First and Last Position of Element in Sorted Array", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/", "examples": [{"input": "nums = [5,7,7,8,8,10], target = 8", "output": "[3,4]", "explanation": "The value 8 occupies indices 3 and 4."}, {"input": "nums = [5,7,7,8,8,10], target = 6", "output": "[-1,-1]", "explanation": "No entry equals 6."}, {"input": "nums = [], target = 0", "output": "[-1,-1]", "explanation": "An empty array contains nothing."}], "hints": ["Run binary search twice: once biased to the leftmost hit and once biased to the rightmost hit.", "When the midpoint equals the target, record it but keep searching the appropriate half instead of stopping."], "statement": "You receive an integer array `nums` sorted in non-decreasing order and an integer `target`. Find the first and last positions where `target` appears, and return them as a two-element array `[first, last]`.\n\nWhen `target` does not occur at all, return `[-1, -1]`. Your method should run in logarithmic time rather than scanning the whole array.\n\n**Constraints:**\n- `0 <= nums.length <= 10^5`\n- `-10^9 <= nums[i] <= 10^9`\n- `nums` is sorted in non-decreasing order.\n- `-10^9 <= target <= 10^9`\n", "solution": "## Approach\n\nBinary-search twice over the sorted array: one pass keeps going left after a hit to pin down the first occurrence, and the other keeps going right to pin down the last. Missing targets naturally leave the answer at -1 on both passes.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n) for the two binary searches.\n- **Space Complexity:** O(1) extra space.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def searchRange(self, nums: List[int], target: int) -> List[int]:\n def bound(first: bool) -> int:\n lo, hi, ans = 0, len(nums) - 1, -1\n while lo <= hi:\n m = (lo + hi) // 2\n if nums[m] == target:\n ans = m\n if first:\n hi = m - 1\n else:\n lo = m + 1\n elif nums[m] < target:\n lo = m + 1\n else:\n hi = m - 1\n return ans\n return [bound(True), bound(False)]\n```\n", "starter": {"go": "package main\n\nfunc SearchRange(nums []int, target int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def searchRange(self, nums: List[int], target: int) -> List[int]:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> searchRange(vector<int>& nums, int target) {\n return {};\n }\n};"}, "fn": "searchRange", "params": [{"name": "nums", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int_array", "tests": [["[5,7,7,8,8,10]", "8"], ["[5,7,7,8,8,10]", "6"], ["[]", "0"], ["[1]", "1"], ["[1]", "0"], ["[2,2]", "2"], ["[1,2,3,4,5]", "3"], ["[1,2,3,4,5]", "1"], ["[1,2,3,4,5]", "5"], ["[1,1,1,1,1]", "1"], ["[1,2,2,2,3]", "2"], ["[0,0,1,1,1,2,2,3,3]", "1"], ["[-1000000000,1000000000]", "1000000000"], ["[1,3]", "3"], ["[3,3,3]", "3"], ["[1,4]", "4"], ["[1,4]", "2"], ["[5,7,7,8,8,10]", "10"], ["[5,7,7,8,8,10]", "5"], ["[1,2,3]", "3"], ["[8,8,8,8]", "8"], ["[1]", "-1"], ["[-5,-3,-1,0,2]", "-3"], ["[0,1,2,3,4,4,4,5]", "4"], ["[9]", "9"], ["[1,2,3,4,5,6,7,8,9,10]", "7"], ["[1,1,2,2,2,3,3]", "2"]], "expected": [[3, 4], [-1, -1], [-1, -1], [0, 0], [-1, -1], [0, 1], [2, 2], [0, 0], [4, 4], [0, 4], [1, 3], [2, 4], [1, 1], [1, 1], [0, 2], [1, 1], [-1, -1], [5, 5], [0, 0], [2, 2], [0, 3], [-1, -1], [1, 1], [4, 6], [0, 0], [6, 6], [2, 4]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "1095", "slug": "find-in-mountain-array", "id": 1095, "title": "Find in Mountain Array", "difficulty": "Hard", "category": "binary-search", "link": "https://leetcode.com/problems/find-in-mountain-array/", "examples": [{"input": "mountainArr = [1,2,3,4,5,3,1], target = 3", "output": "2", "explanation": "3 occurs at indices 2 and 5; the minimum index is 2."}, {"input": "mountainArr = [0,1,2,4,2,1], target = 3", "output": "-1", "explanation": "3 does not occur in the array."}, {"input": "mountainArr = [1,5,2], target = 5", "output": "1", "explanation": "5 is the peak at index 1."}], "hints": ["The judge never reveals the array; only mountainArr.get(i) and mountainArr.length() are available, with at most 100 get calls.", "Binary-search the peak: arr[mid] < arr[mid+1] means the peak is to the right.", "Binary-search the increasing left side for the target with the usual ascending order, then the decreasing right side with reversed comparisons, and return the left-side hit first to get the minimum index."], "statement": "A mountain array satisfies `arr.length >= 3` with values strictly increasing to a peak then strictly decreasing. You cannot access it directly \u2014 interact with the judge object `mountainArr`:\n\n- `get(index)` returns the element at `index`,\n- `length()` returns the array length.\n\nImplement `findInMountainArray(target, mountainArr)` returning the minimum index `k` with `get(k) == target`, or `-1` if `target` never occurs. Binary search the peak first, then each side; the judge counts your `get` calls and reports Wrong Answer if you exceed **100** calls on a test case.\n\nMethod names per language: Java `mountainArr.get(i)` / `mountainArr.length()`, Python `mountainArr.get(i)` / `mountainArr.length()`, C++ `mountainArr.get(i)` / `mountainArr.length()`, C# `mountainArr.Get(i)` / `mountainArr.Length()`, Rust `mountain_arr.get(i)` / `mountain_arr.length()`, Go `mountainArr.Get(i)` / `mountainArr.Length()`, TypeScript `mountainArr.get(i)` / `mountainArr.length()`, PHP `$mountainArr->get($i)` / `$mountainArr->length()`.\n\n**Constraints:**\n\n- `3 <= mountainArr.length() <= 10^4`\n- `0 <= target <= 10^9`\n- `0 <= get(index) <= 10^9`\n- The hidden array is a valid mountain array.\n- At most 100 `get` calls per test case.\n", "solution": "## Approach\n\nFind the peak with binary search (`arr[mid] < arr[mid+1]` means the peak is\nto the right). Then binary-search the increasing left part normally and the\ndecreasing right part with reversed comparisons. Check the left side first\nso the returned index is minimal.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def findInMountainArray(self, arr: List[int], target: int) -> int:\n left, right = 0, len(arr) - 1\n while left < right:\n mid = left + (right - left) // 2\n if arr[mid] < arr[mid + 1]:\n left = mid + 1\n else:\n right = mid\n peak = left\n\n def search_asc(lo: int, hi: int) -> int:\n while lo <= hi:\n mid = lo + (hi - lo) // 2\n if arr[mid] == target:\n return mid\n if arr[mid] < target:\n lo = mid + 1\n else:\n hi = mid - 1\n return -1\n\n def search_desc(lo: int, hi: int) -> int:\n while lo <= hi:\n mid = lo + (hi - lo) // 2\n if arr[mid] == target:\n return mid\n if arr[mid] > target:\n lo = mid + 1\n else:\n hi = mid - 1\n return -1\n\n hit = search_asc(0, peak)\n if hit != -1:\n return hit\n return search_desc(peak + 1, len(arr) - 1)\n```\n", "starter": {"go": "package main\n\n// This is the MountainArray's API interface.\n// You should not implement it, or speculate about its implementation\n// type MountainArray struct { }\n// func (m *MountainArray) Get(index int) int\n// func (m *MountainArray) Length() int\n// You cannot access the mountain array directly; use Get/Length only.\n// The judge counts your Get calls: at most 100 per test case.\nfunc FindInMountainArray(target int, mountainArr *MountainArray) int {\n return -1\n}", "python": "# \"\"\"\n# This is the MountainArray's API interface.\n# You should not implement it, or speculate about its implementation\n# \"\"\"\n# class MountainArray:\n# def get(self, index: int) -> int:\n# def length(self) -> int:\n# You cannot access the mountain array directly; use get/length only.\n# The judge counts your get calls: at most 100 per test case.\nfrom typing import List\n\nclass Solution:\n def findInMountainArray(self, target: int, mountainArr: 'MountainArray') -> int:\n return -1\n", "cpp": "/**\n * // This is the MountainArray's API interface.\n * // You should not implement it, or speculate about its implementation\n * class MountainArray {\n * public:\n * int get(int index);\n * int length();\n * };\n * // You cannot access the mountain array directly; use get/length only.\n * // The judge counts your get calls: at most 100 per test case.\n */\nclass Solution {\npublic:\n int findInMountainArray(int target, MountainArray &mountainArr) {\n return -1;\n }\n};"}, "fn": "findInMountainArray", "params": [{"name": "mountainArr", "type": "int_array"}, {"name": "target", "type": "int"}], "outputType": "int", "tests": [["[1,2,3,4,5,3,1]", "3"], ["[0,1,2,4,2,1]", "3"], ["[1,5,2]", "5"], ["[1,2,3,5,3,1]", "1"], ["[1,3,5,7,6,4,2]", "6"], ["[1,3,5,7,6,4,2]", "1"], ["[1,3,5,7,6,4,2]", "2"], ["[1,3,5,7,6,4,2]", "8"], ["[0,2,5,9,12,8,3]", "12"], ["[0,2,5,9,12,8,3]", "0"], ["[1,2,3,4,5,4,3,2,1]", "4"], ["[1,2,3,4,5,4,3,2,1]", "2"], ["[1,2,3,4,5,4,3,2,1]", "9"], ["[1,2,3,4,5,4,3,2,1]", "5"], ["[1,4,7,10,8,5,2]", "10"], ["[1,4,7,10,8,5,2]", "2"], ["[1,4,7,10,8,5,2]", "11"], ["[3,5,4]", "3"], ["[3,5,4]", "4"], ["[3,5,4]", "5"], ["[0,1,0]", "0"], ["[0,1,0]", "1"], ["[1,2,4,8,16,15,7,3]", "16"], ["[1,2,4,8,16,15,7,3]", "3"], ["[1,2,4,8,16,15,7,3]", "7"], ["[2,5,9,14,20,18,12,6,1]", "20"], ["[2,5,9,14,20,18,12,6,1]", "1"], ["[10,20,30,25,15,5]", "25"], ["[10,20,30,25,15,5]", "5"], ["[1,2,5,3,2,1]", "2"], ["[1,2,5,3,2,1]", "6"], ["[0,1,2,3,2,1]", "0"], ["[0,1,2,3,2,1]", "3"], ["@javascript:(()=>{const up=Array.from({length:5000},(_,i)=>i);const down=Array.from({length:4999},(_,i)=>4998-i);return JSON.stringify([...up,5000,...down]);})()", "4998"], ["@javascript:(()=>{const up=Array.from({length:5000},(_,i)=>i);const down=Array.from({length:4999},(_,i)=>4998-i);return JSON.stringify([...up,5000,...down]);})()", "10001"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "175", "slug": "find-k-closest-elements", "id": 175, "title": "Find K Closest Elements", "difficulty": "Medium", "category": "sliding-window", "link": "https://leetcode.com/problems/find-k-closest-elements/", "examples": [{"input": "arr = [1,2,3,4,5], k = 4, x = 3", "output": "[1,2,3,4]", "explanation": "The 4 closest elements to 3 are 1, 2, 3 and 4."}, {"input": "arr = [1,2,3,4,5], k = 4, x = -1", "output": "[1,2,3,4]", "explanation": "The 4 closest elements to -1 are 1, 2, 3 and 4."}], "hints": ["Use two pointers shrinking from both ends until k elements remain, discarding the farther end each time.", "Equivalently, binary-search the left bound of the size-k window."], "statement": "You receive an integer array `arr` already ordered from smallest to largest, plus two integers `k` and `x`. Select the `k` entries of `arr` that lie nearest to `x`, and return them likewise ordered from smallest to largest.\n\nCloseness is judged as follows: a value `a` ranks ahead of a value `b` when\n\n- `|a - x| < |b - x|`, or\n- `|a - x| == |b - x|` and `a < b`.\n\n**Constraints:**\n\n- `1 <= k <= arr.length`\n- `1 <= arr.length <= 10^4`\n- `arr` is ordered in ascending order.\n- `-10^4 <= arr[i], x <= 10^4`\n", "solution": "## Approach\n\nUse two pointers at both ends of the sorted array and shrink the window until `k` elements remain. At each step compare `|arr[left] - x|` and `|arr[right] - x|`; discard the farther end. On ties discard the right end to prefer the smaller value. The remaining window is already sorted.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `arr`. Each step removes one element (O(log n + k) with binary search for the window start).\n- **Space Complexity:** O(k) for the returned window, O(1) extra.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n left, right = 0, len(arr) - 1\n while right - left + 1 > k:\n if abs(arr[left] - x) > abs(arr[right] - x):\n left += 1\n else:\n right -= 1\n return arr[left:left + k]\n```\n", "starter": {"go": "package main\n\nfunc FindClosestElements(arr []int, k int, x int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def findClosestElements(self, arr: List[int], k: int, x: int) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findClosestElements(vector<int>& arr, int k, int x) {\n return {};\n }\n};"}, "fn": "findClosestElements", "params": [{"name": "arr", "type": "int_array"}, {"name": "k", "type": "int"}, {"name": "x", "type": "int"}], "outputType": "int_array", "tests": [["[1,2,3,4,5]", "4", "3"], ["[1,2,3,4,5]", "4", "-1"], ["[1,1,2,3,4,5]", "4", "-1"], ["[1,2,3,4,5]", "4", "10"], ["[0,0,1,2,3,3,4,7,7,8]", "3", "5"], ["[1,1,1,10,10,10]", "1", "9"], ["[0,1,2,2,2,3,6,8,8,9]", "5", "9"], ["[1]", "1", "1"], ["[1,2]", "1", "1"], ["[1,3,5,7]", "2", "4"], ["[-2,-1,1,2,3,4,5]", "7", "3"], ["[1,2,3,4,5,6,7]", "3", "5"], ["[1,2,3,4,5]", "1", "3"], ["[1,2,3,4,5]", "5", "3"], ["[1,2,3,4,5]", "2", "3"], ["[-10,-5,0,5,10]", "2", "0"], ["[-10,-5,0,5,10]", "3", "7"], ["[1,2,3,4,5]", "1", "100"], ["[1,2,3,4,5]", "1", "-100"], ["[-4,-3,-2,-1,0]", "2", "-2"], ["[0,1,2,3,4]", "4", "2"], ["[1,2,5,6,8]", "2", "4"], ["[1,2,5,6,8]", "2", "7"], ["[-100,100]", "1", "0"], ["[-5,-4,-3,-2,-1]", "5", "-3"], ["[5,5,5,5,5]", "3", "5"], ["[1,10,20,30,40,50]", "2", "25"], ["[-7,-5,-3,-1,1,3,5]", "4", "0"], ["[2,4,6,8,10]", "3", "1"], ["[2,4,6,8,10]", "3", "11"], ["[0,2,4,6,8,10,12]", "4", "6"], ["[1,3]", "2", "2"]], "expected": [[1, 2, 3, 4], [1, 2, 3, 4], [1, 1, 2, 3], [2, 3, 4, 5], [3, 3, 4], [10], [3, 6, 8, 8, 9], [1], [1], [3, 5], [-2, -1, 1, 2, 3, 4, 5], [4, 5, 6], [3], [1, 2, 3, 4, 5], [2, 3], [-5, 0], [0, 5, 10], [5], [1], [-3, -2], [0, 1, 2, 3], [2, 5], [6, 8], [-100], [-5, -4, -3, -2, -1], [5, 5, 5], [20, 30], [-3, -1, 1, 3], [2, 4, 6], [6, 8, 10], [2, 4, 6, 8], [1, 3]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "451", "slug": "find-k-pairs-with-smallest-sums", "id": 451, "title": "Find K Pairs with Smallest Sums", "difficulty": "Medium", "category": "heap", "link": "https://leetcode.com/problems/find-k-pairs-with-smallest-sums/", "examples": [{"input": "nums1 = [1,7,11], nums2 = [2,4,6], k = 3", "output": "[[1,2],[1,4],[1,6]]", "explanation": "Smallest sums are 3, 5, 7."}, {"input": "nums1 = [1,1,2], nums2 = [1,2,3], k = 2", "output": "[[1,1],[1,1]]", "explanation": "Two pairs tie at sum 2."}, {"input": "nums1 = [1,2], nums2 = [3], k = 2", "output": "[[1,3],[2,3]]", "explanation": "Both pairs ordered by sum."}], "hints": ["Push one entry per nums1 row for column zero, then repeatedly pop the smallest sum.", "After popping (i, j), push (i, j+1) when the next column exists.", "Track visited index pairs so the same cell is never queued twice."], "statement": "List the `k` pairs with the tiniest sums across two sorted arrays.\n\nBoth `nums1` and `nums2` arrive sorted from small to large. A pair takes one entry from each array, and its cost is the sum of the two entries. Return exactly `min(k, nums1.length * nums2.length)` pairs with the smallest costs, each written as a two-element row `[u, v]`. Pairs are compared by their sums; when several pairs share the same sum, any order among them is fine.\n\n*Portable adaptation:* the classic version returns a list of boxed lists; here return a plain 2D integer array with the same rows.\n\n**Constraints:**\n- `1 <= nums1.length, nums2.length <= 1000` for this portable version (the classic allows larger).\n- `-10^9 <= nums1[i], nums2[i] <= 10^9`\n- Both arrays are sorted in non-decreasing order.\n- `1 <= k <= 10^4`\n- `k <= nums1.length * nums2.length`\n", "solution": "## Approach\n\nSeed a min-heap with the first column of every first-array row, then pop the smallest sum `want` times. Each pop of cell `(i, j)` queues its right neighbor `(i, j+1)` and its lower neighbor `(i+1, j)` when unseen, so the heap always holds the current frontier of candidate sums.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k log k), with one heap step per returned pair.\n- **Space Complexity:** O(k) for the heap and the visited index set.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\nclass Solution:\n def kSmallestPairs(self, nums1: List[int], nums2: List[int], k: int) -> List[List[int]]:\n want = min(k, len(nums1) * len(nums2))\n pq = [(nums1[0] + nums2[0], 0, 0)]\n seen = {(0, 0)}\n out = []\n while len(out) < want and pq:\n _, i, j = heapq.heappop(pq)\n out.append([nums1[i], nums2[j]])\n if i + 1 < len(nums1) and (i + 1, j) not in seen:\n seen.add((i + 1, j))\n heapq.heappush(pq, (nums1[i + 1] + nums2[j], i + 1, j))\n if j + 1 < len(nums2) and (i, j + 1) not in seen:\n seen.add((i, j + 1))\n heapq.heappush(pq, (nums1[i] + nums2[j + 1], i, j + 1))\n return out\n```\n", "starter": {"go": "package main\n\nfunc KSmallestPairs(nums1 []int, nums2 []int, k int) [][]int {\n return nil\n}", "python": "from typing import List\n\nclass Solution:\n def kSmallestPairs(self, nums1: List[int], nums2: List[int], k: int) -> List[List[int]]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> kSmallestPairs(vector<int>& nums1, vector<int>& nums2, int k) {\n return {};\n }\n};"}, "fn": "kSmallestPairs", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int_array_2d", "tests": [["[1,7,11]", "[2,4,6]", "3"], ["[1,1,2]", "[1,2,3]", "2"], ["[1,2]", "[3]", "2"], ["[1,2,3]", "[1,2,3]", "4"], ["[1]", "[1]", "1"], ["[1,2,3]", "[4,5,6]", "9"], ["[0,0,0]", "[0,0,0]", "5"], ["[-5,-2,0]", "[-3,1,4]", "4"], ["[1,3,5]", "[2,4]", "4"], ["[1,10,100]", "[1,10,100]", "5"], ["[2,2,2]", "[3,3]", "6"], ["[1,2,3,4]", "[1]", "4"], ["[5]", "[1,2,3,4,5]", "3"], ["[-10,0,10]", "[-10,0,10]", "6"], ["[1,1,1]", "[1,1,1]", "9"], ["[1,2,3]", "[2,4,6]", "3"], ["[1,7]", "[3,5,9]", "4"], ["[0,1,2]", "[0,1,2]", "7"], ["[100,200]", "[1,2]", "4"], ["[-2,-1]", "[-2,-1]", "3"], ["[1,2,3,4,5]", "[6,7,8,9,10]", "5"], ["[4,4,4]", "[4,4,4]", "4"], ["[1,5,9,13]", "[2,6,10]", "6"], ["[0]", "[-5,5]", "2"], ["[7,8,9]", "[1,2]", "5"], ["[1,2]", "[1,2]", "4"], ["[10,20,30]", "[1,2,3]", "3"], ["[-1,0,1]", "[-1,0,1]", "5"], ["[2,4,6,8]", "[1,3,5,7]", "8"], ["[5,6,7]", "[5,6,7]", "1"]], "expected": [[[1, 2], [1, 4], [1, 6]], [[1, 1], [1, 1]], [[1, 3], [2, 3]], [[1, 1], [2, 1], [1, 2], [2, 2]], [[1, 1]], [[1, 4], [2, 4], [1, 5], [2, 5], [1, 6], [3, 4], [3, 5], [2, 6], [3, 6]], [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], [[-5, -3], [-2, -3], [-5, 1], [0, -3]], [[1, 2], [3, 2], [1, 4], [3, 4]], [[1, 1], [10, 1], [1, 10], [10, 10], [1, 100]], [[2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]], [[1, 1], [2, 1], [3, 1], [4, 1]], [[5, 1], [5, 2], [5, 3]], [[-10, -10], [0, -10], [-10, 0], [0, 0], [-10, 10], [10, -10]], [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]], [[1, 2], [2, 2], [1, 4]], [[1, 3], [1, 5], [7, 3], [1, 9]], [[0, 0], [1, 0], [0, 1], [1, 1], [0, 2], [2, 0], [2, 1]], [[100, 1], [100, 2], [200, 1], [200, 2]], [[-2, -2], [-1, -2], [-2, -1]], [[1, 6], [2, 6], [1, 7], [2, 7], [1, 8]], [[4, 4], [4, 4], [4, 4], [4, 4]], [[1, 2], [5, 2], [1, 6], [5, 6], [1, 10], [9, 2]], [[0, -5], [0, 5]], [[7, 1], [8, 1], [7, 2], [8, 2], [9, 1]], [[1, 1], [2, 1], [1, 2], [2, 2]], [[10, 1], [10, 2], [10, 3]], [[-1, -1], [0, -1], [-1, 0], [0, 0], [-1, 1]], [[2, 1], [4, 1], [2, 3], [4, 3], [2, 5], [6, 1], [2, 7], [8, 1]], [[5, 5]]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "727", "slug": "find-k-th-smallest-pair-distance", "id": 727, "title": "Find K-th Smallest Pair Distance", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/find-k-th-smallest-pair-distance/", "examples": [{"input": "nums = [1,3,1], k = 1", "output": "0", "explanation": "Pairs give distances 0, 2 and 2; the smallest is 0."}, {"input": "nums = [1,1,1], k = 2", "output": "0", "explanation": "Every pair distance is 0."}, {"input": "nums = [1,6,1], k = 3", "output": "5", "explanation": "Distances are 0, 5 and 5, so the third smallest is 5."}], "hints": ["Sort first; counting pairs within a distance limit is then a linear two-pointer sweep.", "The count grows monotonically with the limit, so binary-search the smallest limit with at least k pairs.", "For a fixed right endpoint, all left positions from the low pointer onward form valid pairs."], "statement": "Consider every unordered pair of positions in `nums` and record the absolute difference of the two values. Sort those distances increasingly and pick the `k`-th entry (1-based).\n\nReturn that distance. For example, `[1,3,1]` yields distances `0, 2, 2`, whose first entry is `0`.\n\n**Constraints:**\n- `2 <= nums.length <= 10^4`\n- `0 <= nums[i] <= 10^6`\n- `1 <= k <= n*(n-1)/2`\n", "solution": "## Approach\n\nSort the values, then binary-search the distance. For a trial limit, a sliding window counts how many pairs fit inside it in linear time; that count rises with the limit, so the smallest limit covering at least `k` pairs is the desired k-th distance.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n + n log W), where n is the length and W the value range.\n- **Space Complexity:** O(1) besides sorting.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def smallestDistancePair(self, nums: List[int], k: int) -> int:\n nums = sorted(nums)\n lo, hi = 0, nums[-1] - nums[0]\n def count(limit: int) -> int:\n cnt = left = 0\n for right in range(len(nums)):\n while nums[right] - nums[left] > limit:\n left += 1\n cnt += right - left\n return cnt\n while lo < hi:\n mid = (lo + hi) // 2\n if count(mid) >= k:\n hi = mid\n else:\n lo = mid + 1\n return lo\n```\n", "starter": {"go": "package main\n\nfunc SmallestDistancePair(nums []int, k int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def smallestDistancePair(self, nums: List[int], k: int) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int smallestDistancePair(vector<int>& nums, int k) {\n return 0;\n }\n};"}, "fn": "smallestDistancePair", "params": [{"name": "nums", "type": "int_array"}, {"name": "k", "type": "int"}], "outputType": "int", "tests": [["[1,3,1]", "1"], ["[1,1,1]", "2"], ["[1,6,1]", "3"], ["[1,2]", "1"], ["[1,10]", "1"], ["[1,2,3]", "1"], ["[1,2,3]", "2"], ["[1,2,3]", "3"], ["[62,100,4]", "2"], ["[1,1,1,1]", "6"], ["[1,5,9,13]", "4"], ["[9,10,7,10,6,1,5,4,9,8]", "18"], ["[1,100,1,100,1]", "5"], ["[38,33,57,65,13,9,30,49,91]", "17"], ["[0,0,1,1]", "3"], ["[2,4,6,8,10]", "7"], ["[1,3,5,7,9]", "10"], ["[10,20,30]", "3"], ["[5,5,5,10,10]", "8"], ["[1,2,3,4,5,6]", "15"], ["[1000000,0]", "1"], ["[1,2,3,4]", "5"], ["[4,4,4,4,5]", "4"], ["[1,6,2,7,3,8]", "9"], ["[0,1,2,100]", "6"], ["[3,3,6,6,9]", "6"], ["[1,4,9,16,25]", "7"], ["[2,2,3,3,4,4]", "11"]], "expected": [0, 0, 5, 1, 9, 1, 1, 2, 58, 0, 8, 2, 99, 25, 1, 4, 8, 20, 5, 5, 1000000, 2, 0, 4, 100, 3, 15, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "575", "slug": "find-largest-value-in-each-tree-row", "id": 575, "title": "Find Largest Value in Each Tree Row", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/find-largest-value-in-each-tree-row/", "examples": [{"input": "root = [1,3,2,5,3,null,9]", "output": "[1,3,9]", "explanation": "Row 0 holds [1], row 1 holds [3,2], row 2 holds [5,3,9]; the maxima are 1, 3 and 9."}, {"input": "root = [1,2,3]", "output": "[1,3]", "explanation": "The rows are [1] and [2,3], giving maxima 1 and 3."}, {"input": "root = []", "output": "[]", "explanation": "An empty tree has no rows."}], "hints": ["Process the tree breadth-first so nodes are grouped by depth.", "Track the running maximum inside each row and append it before moving to the next row."], "statement": "Walk a binary tree row by row from the top down and record, for every depth level, the greatest value appearing on that level. Return those maxima from the shallowest row to the deepest one.\n\n**Constraints:**\n- The number of nodes is in the range `[0, 10^4]`\n- `-2^31 <= Node.val <= 2^31 - 1`\n", "solution": "## Approach\n\nTraverse level by level with a queue. For each row, scan all its nodes to find the largest value, append that maximum to the answer, and enqueue the children for the next round. An empty tree skips the loop and returns an empty list.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one visit per node.\n- **Space Complexity:** O(w), where w is the maximum row width.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\nclass Solution:\n def largestValues(self, root) -> List[int]:\n if root is None:\n return []\n ans = []\n q = deque([root])\n while q:\n mx = max(node.val for node in q)\n ans.append(mx)\n for _ in range(len(q)):\n cur = q.popleft()\n if cur.left is not None:\n q.append(cur.left)\n if cur.right is not None:\n q.append(cur.right)\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 LargestValues(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 largestValues(self, root) -> List[int]:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> largestValues(TreeNode* root) {\n return {};\n }\n};"}, "fn": "largestValues", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int_list", "tests": [["[1,3,2,5,3,null,9]"], ["[1,2,3]"], ["[]"], ["[1]"], ["[1,2]"], ["[5,4,6,3,null,null,7]"], ["[-1,-2,-3]"], ["[3,1,5,0,2,4,6]"], ["[1,null,2,null,3]"], ["[10,5,-3,3,2,null,11,3,-2,null,1]"], ["[0,0,0]"], ["[2147483647,-2147483648,0]"], ["[2,1,3,0,7,9,1,2,null,1,0,null,null,8,8]"], ["[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]"], ["[-5,null,-3,null,-1]"], ["[100,50,150,25,75,125,175]"], ["[1,2,null,3]"], ["[9,6,-2,null,null,2,-3]"], ["[4,null,9,null,0,null,5]"], ["[7,3,9,1,5,null,12]"], ["[0]"], ["[-100,50]"], ["[6,2,8,0,4,7,9,null,null,3,5]"], ["[1,3,2,5,null,null,9,6,null,7]"], ["[5]"], ["[3,null,2,null,1]"], ["[8,8,8,8,8]"], ["[1,2,3,4,null,null,5,6]"]], "expected": [[1, 3, 9], [1, 3], [], [1], [1, 2], [5, 6, 7], [-1, -2], [3, 5, 6], [1, 2, 3], [10, 5, 11, 3], [0, 0], [2147483647, 0], [2, 3, 9, 8], [1, 3, 7, 15], [-5, -3, -1], [100, 150, 175], [1, 2, 3], [9, 6, 2], [4, 9, 0, 5], [7, 9, 12], [0], [-100, 50], [6, 8, 9, 5], [1, 3, 9, 7], [5], [3, 2, 1], [8, 8, 8], [1, 3, 5, 6]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "445", "slug": "find-leaves-of-binary-tree", "id": 445, "title": "Find Leaves of Binary Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/find-leaves-of-binary-tree/", "examples": [{"input": "root = [1,2,3,4,5]", "output": "[[4,5,3],[2],[1]]", "explanation": "Leaves [4,5,3] fall first, then [2], then [1]."}, {"input": "root = [1]", "output": "[[1]]"}, {"input": "root = []", "output": "[]"}], "hints": ["A node's removal round equals one plus the largest round of its children.", "Compute heights bottom-up with depth-first search.", "Append each value to the group indexed by its height minus one."], "statement": "Repeatedly strip all current leaves from a binary tree: in round one remove\nevery leaf, in round two remove the leaves of what remains, and so on until\nthe tree is empty. Collect the removed values round by round.\n\nFor the tree `[1,2,3,4,5]` (root 1, children 2 and 3, with 2 parenting 4 and\n5), round one takes `[4,5,3]`, round two takes `[2]`, and round three takes\n`[1]`.\n\n**Adaptation note:** the leaf groups are returned as a 2D integer list; values\ninside one round may appear in any order, but rounds stay ordered from the\nouter leaves inward.\n\n**Constraints:**\n- The tree holds between 0 and 100 nodes, with values in `[-100, 100]`.\n", "solution": "## Approach\n\nThe round in which a node falls equals its height: leaves have height 1 and\neach parent sits one level above its tallest child. A bottom-up search\ncomputes every height and drops each value into the matching round group.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the node count.\n- **Space Complexity:** O(n) for the groups plus recursion depth.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findLeaves(self, root) -> List[List[int]]:\n ans: List[List[int]] = []\n\n def height(node) -> int:\n if node is None:\n return 0\n h = max(height(node.left), height(node.right)) + 1\n if len(ans) < h:\n ans.append([])\n ans[h - 1].append(node.val)\n return h\n\n height(root)\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 FindLeaves(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 findLeaves(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>> findLeaves(TreeNode* root) {\n \n }\n};"}, "fn": "findLeaves", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "int_list_2d", "tests": [["[1,2,3,4,5]"], ["[1]"], ["[]"], ["[1,2,3]"], ["[1,2,3,4,5,6,7]"], ["[1,null,2,3,4]"], ["[3,1,4,null,2]"], ["[1,2,null,3,null,4]"], ["[5,4,6,3,null,null,7]"], ["[2,1,3]"], ["[1,null,2]"], ["[1,2]"], ["[4,2,6,1,3,5,7]"], ["[1,2,3,4,null,null,5]"], ["[10,5,15,3,7,null,18]"], ["[1,2,3,null,4,null,5]"], ["[0]"], ["[0,0,0]"], ["[-1,-2,-3]"], ["[1,null,2,null,3]"], ["[3,2,1]"], ["[1,2,3,4,5,6]"], ["[7,3,9,1,5]"], ["[2,null,3,null,4,null,5]"], ["[1,2,null,null,3]"]], "expected": [[[4, 5, 3], [2], [1]], [[1]], [], [[2, 3], [1]], [[4, 5, 6, 7], [2, 3], [1]], [[3, 4], [2], [1]], [[2, 4], [1], [3]], [[4], [3], [2], [1]], [[3, 7], [4, 6], [5]], [[1, 3], [2]], [[2], [1]], [[2], [1]], [[1, 3, 5, 7], [2, 6], [4]], [[4, 5], [2, 3], [1]], [[3, 7, 18], [5, 15], [10]], [[4, 5], [2, 3], [1]], [[0]], [[0, 0], [0]], [[-2, -3], [-1]], [[3], [2], [1]], [[2, 1], [3]], [[4, 5, 6], [2, 3], [1]], [[1, 5, 9], [3], [7]], [[5], [4], [3], [2]], [[3], [2], [1]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "74", "slug": "find-median-from-data-stream", "id": 74, "title": "Find Median from Data Stream", "difficulty": "Hard", "category": "heap", "link": "https://leetcode.com/problems/find-median-from-data-stream/", "examples": [{"input": "operations = [\"MedianFinder\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]\nvalues = [[],[1],[],[2],[]]", "output": "[null,null,1.0,null,1.5]", "explanation": "After adding 1, the median is 1.0. After adding 2, the median is 1.5."}, {"input": "operations = [\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]\nvalues = [[],[1],[2],[3],[4],[]]", "output": "[null,null,null,null,null,2.5]", "explanation": "After adding [1,2,3,4], the median is (2+3)/2 = 2.5."}], "hints": ["Use two heaps: a max-heap for the smaller half and a min-heap for the larger half.", "When adding a number, add to the max-heap first, then balance by moving the largest from max-heap to min-heap. If the min-heap has more elements, move the smallest back to the max-heap.", "The median is the top of the max-heap if sizes differ, or the average of both tops if sizes are equal."], "statement": "The **median** of a sorted integer collection is its central entry. When the collection holds an even count, the median becomes the average of the two central entries.\n\nBuild a structure that tracks this value as numbers arrive one by one:\n\n- `MedianFinder()` creates a fresh `MedianFinder` tracker.\n- `void addNum(int num)` feeds one integer `num` from the stream into the tracker.\n- `double findMedian()` reports the median of everything fed in so far. Outputs landing within `10^-5` of the true median count as correct.\n\n**Constraints:**\n- `-10^5 <= num <= 10^5`\n- The tracker will hold at least one entry whenever `findMedian` is invoked.\n- No more than `5 * 10^4` invocations of `addNum` and `findMedian` combined will occur.\n", "solution": "## Approach\n\nMaintain two heaps: a max-heap for the smaller half of numbers and a min-heap for the larger half. By keeping the heaps balanced (sizes differ by at most 1), the median is either the max of the small heap or the average of both tops.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n) for addNum, O(1) for findMedian.\n- **Space Complexity:** O(n) to store all numbers.\n\n## Implementation\n\n```python\nimport heapq\nfrom typing import List\nclass MedianFinder:\n def __init__(self):\n self.small = []\n self.large = []\n def addNum(self, num: int) -> None:\n heapq.heappush(self.small, -num)\n heapq.heappush(self.large, -heapq.heappop(self.small))\n if len(self.small) < len(self.large):\n heapq.heappush(self.small, -heapq.heappop(self.large))\n def findMedian(self) -> float:\n if len(self.small) > len(self.large):\n return -self.small[0]\n return (-self.small[0] + self.large[0]) / 2.0\nclass Solution:\n def solve(self, operations: List[str], values: List[List[int]]) -> List[str]:\n result = []\n obj = None\n for i, op in enumerate(operations):\n if op == \"MedianFinder\":\n obj = MedianFinder()\n result.append(\"null\")\n elif op == \"addNum\":\n obj.addNum(values[i][0])\n result.append(\"null\")\n elif op == \"findMedian\":\n med = obj.findMedian()\n if med == int(med):\n result.append(str(int(med)) + \".0\")\n else:\n result.append(str(med))\n return result\n```\n", "starter": {"go": "package main\n\ntype MedianFinder struct {\n \n}\n\nfunc Constructor() MedianFinder {\n return MedianFinder{}\n}\n\nfunc (this *MedianFinder) AddNum(num int) {\n \n}\n\nfunc (this *MedianFinder) FindMedian() float64 {\n return 0.0\n}", "python": "class MedianFinder:\n def __init__(self):\n \n def addNum(self, num: int) -> None:\n \n def findMedian(self) -> float:\n return 0.0", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass MedianFinder {\npublic:\n MedianFinder() {\n \n }\n \n void addNum(int num) {\n \n }\n \n double findMedian() {\n return 0.0;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"MedianFinder\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[1],[],[2],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[1],[2],[3],[4],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\"]", "[[],[-1],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[-1],[-2],[],[-3],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[10],[20],[30],[40],[],[50],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[0],[],[1],[],[2],[],[3],[],[4],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[100000],[0],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[5],[5],[5],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"findMedian\",\"addNum\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[3],[1],[],[4],[2],[],[5],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[-5],[],[-10],[],[-15],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[2],[4],[6],[8],[10],[12],[14],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[-10000],[],[10000],[],[-5000],[],[5000],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\"]", "[[],[5],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\"]", "[[],[0],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[1],[2],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[7],[7],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[-100000],[100000],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[5],[4],[3],[2],[1],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[-3],[-2],[-1],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[1],[1],[1],[1],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[1],[],[100],[],[2],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[100000],[99999],[99998],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[1],[2],[3],[5],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\",\"addNum\",\"findMedian\"]", "[[],[6],[],[10],[],[2],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[-5],[10],[-3],[8],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[4],[4],[5],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[1],[4],[2],[5],[]]"], ["[\"MedianFinder\",\"addNum\",\"findMedian\"]", "[[],[-100000],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[2],[3],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[0],[0],[0],[1],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[10],[-10],[5],[-5],[0],[]]"], ["[\"MedianFinder\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"addNum\",\"findMedian\"]", "[[],[100],[1],[50],[25],[75],[]]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "308", "slug": "find-minimum-in-rotated-sorted-array-ii", "id": 308, "title": "Find Minimum in Rotated Sorted Array II", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/", "examples": [{"input": "nums = [1,3,5]", "output": "1", "explanation": "The array is already sorted, so the first element is minimal."}, {"input": "nums = [2,2,2,0,1]", "output": "0", "explanation": "Rotation moved the minimum 0 into the middle."}], "hints": ["Compare the middle element with the right end to decide which half holds the minimum.", "When they are equal, shrink the right end by one since duplicates give no information.", "Otherwise the classic rotated-array binary search choice applies."], "statement": "Imagine an ascending array rotated between 1 and n times, where duplicates are allowed. For example, `[0,1,4,4,5,6,7]` rotated 4 times can become `[4,5,6,7,0,1,4]`.\n\nGiven such a rotated array `nums`, return its smallest element. Try to reduce the number of steps as much as possible, even though duplicates prevent a pure logarithmic guarantee.\n\n**Constraints:**\n- `n == nums.length`\n- `1 <= n <= 5000`\n- `-5000 <= nums[i] <= 5000`\n- `nums` is a sorted array rotated between 1 and n times.\n", "solution": "## Approach\n\nBinary search between the ends. If the middle value exceeds the right value, the minimum lies to the right; if it is smaller, it lies at or left of middle. On equality the right end is a duplicate that reveals nothing, so shrink it by one and continue.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n) on average, O(n) worst case when many duplicates force linear shrinking.\n- **Space Complexity:** O(1), using two indices.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findMin(self, nums: List[int]) -> int:\n l, r = 0, len(nums) - 1\n while l < r:\n m = (l + r) // 2\n if nums[m] > nums[r]:\n l = m + 1\n elif nums[m] < nums[r]:\n r = m\n else:\n r -= 1\n return nums[l]\n```\n", "starter": {"go": "package main\n\nfunc FindMin(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findMin(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findMin(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "findMin", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,3,5]"], ["[2,2,2,0,1]"], ["[1]"], ["[2,1]"], ["[1,2]"], ["[3,3,1,3]"], ["[1,3,3]"], ["[3,1,3]"], ["[10,1,10,10,10]"], ["[4,5,6,7,0,1,4]"], ["[0,1,4,4,5,6,7]"], ["[1,1,1,1,1]"], ["[2,2,2,2,0]"], ["[5,5,5,1,2,3,4]"], ["[1,2,3,4,5]"], ["[2,3,4,5,1]"], ["[-1,0,1,-1,-1]"], ["[2,2,2,0,2]"], ["[1,10,10,10]"], ["[10,10,10,1]"], ["[-5000,5000,-5000,-5000]"], ["[0,0,1,0]"], ["[1,0,1,1,1]"], ["[3,3,3,4,5,1,2]"], ["[2,0,1,2,2]"], ["[4,4,4,0,1,2]"], ["[1,2,2,2,0]"], ["[5,1,2,3,4]"]], "expected": [1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, -1, 0, 1, 1, -5000, 0, 0, 1, 0, 0, 0, 1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "7", "slug": "find-minimum-in-rotated-sorted-array", "id": 7, "title": "Find Minimum in Rotated Sorted Array", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/", "examples": [{"input": "nums = [3,4,5,1,2]", "output": "1", "explanation": "The array was rotated at index 3. The minimum element 1 is located at the rotation point."}, {"input": "nums = [4,5,6,7,0,1,2]", "output": "0", "explanation": "The array was rotated at index 4. The minimum element 0 is located at the rotation point."}], "hints": ["Use binary search on the rotation pivot: if left half is sorted, the min is on the right; otherwise it's on the left. O(log n) time."], "statement": "You receive an array `nums` that began in ascending order with all distinct entries and was then spun around a pivot. Locate and return its least element.\n\n**Constraints:**\n\n- `n == nums.length`\n- `1 <= n <= 5000`\n- `-5000 <= nums[i] <= 5000`\n- Every entry of `nums` is different from the others.\n- `nums` started sorted and was rotated between `1` and `n` positions.\n", "solution": "## Approach\n\nBinary search on the rotated array. Compare the middle element with the rightmost element to decide which half contains the minimum (pivot point).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n), where n is the length of the array.\n- **Space Complexity:** O(1), using only constant extra space.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findMin(self, nums: List[int]) -> int:\n l, r = 0, len(nums) - 1\n while l < r:\n m = (l + r) // 2\n if nums[m] > nums[r]:\n l = m + 1\n else:\n r = m\n return nums[l]\n```\n", "starter": {"go": "package main\n\nfunc FindMin(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findMin(self, nums: List[int]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int findMin(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "findMin", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[3,4,5,1,2]"], ["[4,5,6,7,0,1,2]"], ["[15,17,11,13]"], ["[2,1]"], ["[1]"], ["[5,1,2,3,4]"], ["[2,3,4,5,6,7,8,1]"], ["[4,5,6,7,1,2,3]"], ["[10,20,30,40,5]"], ["[2,3,4,5,6,7,0,1]"], ["@javascript:JSON.stringify(Array.from({length:5000},(_,i)=>(i+2500)%5000+1))"], ["[2,3,4,5,1]"], ["[4,5,1,2,3]"], ["[1,2]"], ["[3,1,2]"], ["[6,7,8,9,10,1,2,3,4,5]"], ["[30,40,50,10,20]"], ["[0,1,2,3,4,5,-5,-4,-3,-2,-1]"], ["[-1,0,1,-5,-4,-3,-2]"], ["[5,6,7,8,9,0,1,2,3,4]"], ["[-7]"], ["[100,200,300,50,75]"], ["[7,8,1,2,3,4,5,6]"], ["[9,1,2,3,4,5,6,7,8]"], ["[12,13,14,15,2,4,6,8,10]"], ["[-10,-5,0,5,-20,-15]"], ["[2,3,1]"], ["[5,6,1,2,3,4]"], ["[1000,2000,-2000,-1000,0]"], ["[8,9,10,2,4,6]"], ["[3,4,5,6,7,8,9,1,2]"], ["[500,600,700,100,200,300,400]"]], "expected": [1, 0, 11, 1, 1, 1, 1, 1, 5, 0, 1, 1, 1, 1, 1, 1, 10, -5, -5, 0, -7, 50, 1, 1, 2, -20, 1, 1, -2000, 2, 1, 100], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "564", "slug": "find-mode-in-binary-search-tree", "id": 564, "title": "Find Mode in Binary Search Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/find-mode-in-binary-search-tree/", "examples": [{"input": "root = [1,null,2,2]", "output": "[2]", "explanation": "The value 2 appears twice while 1 appears once."}, {"input": "root = [0]", "output": "[0]", "explanation": "A single node is trivially the most frequent."}], "hints": ["An inorder walk visits keys in sorted order, so equal values become adjacent.", "Count frequencies with a hash table (or track runs in sorted order) and remember the maximum.", "Return all keys whose count equals the maximum; order does not matter for the checker."], "statement": "You are given the root of a binary search tree that may hold duplicate keys. Its ordering rule allows equality on either side: left subtree keys are less than or equal to the node, right subtree keys are greater than or equal to the node.\n\nA mode is a value occurring more often than any other value in the tree. Collect every mode and return them in any order.\n\n**Constraints:**\n- The tree holds between 1 and 10^4 nodes\n- `-10^5 <= Node.val <= 10^5`\n", "solution": "## Approach\n\nTraverse the whole tree and tally each value in a dictionary, tracking the highest frequency seen. A second pass collects every key reaching that maximum. Sorting is only for deterministic output; the judge compares as sets so any order passes.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) to visit all nodes plus O(k log k) to sort k modes.\n- **Space Complexity:** O(n) for the frequency table.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findMode(self, root) -> List[int]:\n if not root:\n return []\n freq = {}\n\n def dfs(n):\n if not n:\n return\n freq[n.val] = freq.get(n.val, 0) + 1\n dfs(n.left)\n dfs(n.right)\n\n dfs(root)\n mx = max(freq.values())\n return sorted([v for v, c in freq.items() if c == mx])\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 FindMode(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 findMode(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> findMode(TreeNode* root) {\n return {};\n }\n};"}, "fn": "findMode", "params": [{"name": "root", "type": "tree_node"}], "outputType": "int_array", "tests": [["[1,null,2,2]"], ["[0]"], ["[1,1,2]"], ["[1,2,2,1,1]"], ["[5,3,8,3,4,8,8]"], ["[1]"], ["[]"], ["[2,2,2]"], ["[1,1,1,2,2,3]"], ["[3,2,4,1,2]"], ["[0,0]"], ["[1,null,1,null,1]"], ["[2,null,2,null,2,null,2]"], ["[1,0,2,0,1,1,2]"], ["[5]"], ["[-1,-2,-2]"], ["[10,5,15,5,7,15,15]"], ["[1,2,3,4,5,5,5]"], ["[4,2,6,1,3,5,7]"], ["[1,1,2,2,3,3]"], ["[2,1,2]"], ["[2147483647]"], ["[-2147483648,-2147483648,0]"], ["[1,null,2,null,3,null,3]"], ["[6,4,8,2,5,7,9,2,2]"], ["[0,null,0,null,0]"], ["[3,3,3,1,2]"], ["[100,50,150,25,75,125,175,75]"]], "expected": [[2], [0], [1], [1], [8], [1], [], [2], [1], [2], [0], [1], [2], [1], [5], [-2], [15], [5], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3], [2], [2147483647], [-2147483648], [3], [2], [0], [3], [75]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "315", "slug": "find-peak-element", "id": 315, "title": "Find Peak Element", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/find-peak-element/", "examples": [{"explanation": "The value 3 at index 2 is larger than 2 and 1.", "input": "nums = [1,2,3,1]", "output": "2"}, {"explanation": "Either index 1 (value 2 beats 1 and 1) or index 5 (value 6 beats 5 and 4) is accepted; one of them is 5.", "input": "nums = [1,2,1,3,5,6,4]", "output": "5"}, {"explanation": "A lone element has no neighbours to beat.", "input": "nums = [1]", "output": "0"}], "hints": ["A peak can be found with binary search: if nums[mid] is smaller than its right neighbour, a peak must lie to the right.", "Otherwise a peak lies at mid or to its left.", "The judge accepts any valid peak index, so there is no need to find a specific one."], "statement": "A peak is an element that is strictly larger than its neighbours. The first and last elements each have a single neighbour to beat. Every non-empty array has at least one peak, and you may return the index of any of them.\n\nYour answer is checked by position, not by exact index: any index whose element beats its neighbours is accepted.\n\n**Constraints:**\n- `1 <= nums.length <= 10^4`\n- `-2^31 <= nums[i] <= 2^31 - 1`\n- Adjacent elements differ (`nums[i] != nums[i+1]`).\n", "solution": "## Approach\n\nUse binary search on the slope. Compare the middle element with its right neighbour: when it climbs upward, a peak must exist on the right side, so discard the left half; otherwise a peak sits at the middle or to its left, so discard the right half. The remaining index is a peak because the array edges only need one neighbour.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n), halving the search range each step.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findPeakElement(self, nums: List[int]) -> int:\n lo, hi = 0, len(nums) - 1\n while lo < hi:\n mid = (lo + hi) // 2\n if nums[mid] < nums[mid + 1]:\n lo = mid + 1\n else:\n hi = mid\n return lo\n```\n", "starter": {"go": "package main\n\nfunc FindPeakElement(nums []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findPeakElement(self, nums: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "findPeakElement", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,3,1]"], ["[1,2,1,3,5,6,4]"], ["[1]"], ["[1,2]"], ["[2,1]"], ["[1,3,2]"], ["[3,2,1]"], ["[1,2,3]"], ["[5,4,3,2,1]"], ["[1,2,3,4,5]"], ["[1,3,5,4,2]"], ["[10,20,15,2,23,90,67]"], ["[1,2,3,4,3,2,1]"], ["[100]"], ["[-5,-3,-1]"], ["[-1,-3,-5]"], ["[1,2,3,5,4]"], ["[4,3,2,1,5]"], ["[1,5,2,4,3]"], ["[2,4,6,8,10,9]"], ["[9,7,5,3,1,2]"], ["[1,4,3,2,5,6,0]"], ["[6,5,4,3,2,1,0]"], ["[0,1,2,3,4,5,6]"], ["[3,1,2]"], ["[2,1,3]"]], "expected": [2, 5, 0, 1, 0, 1, 0, 2, 0, 4, 2, 5, 3, 0, 2, 0, 3, 0, 3, 4, 0, 5, 0, 6, 2, 2], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "548", "slug": "find-permutation", "id": 548, "title": "Find Permutation", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/find-permutation/", "examples": [{"input": "s = \"I\"", "output": "[1,2]", "explanation": "Only [1,2] rises."}, {"input": "s = \"DI\"", "output": "[2,1,3]", "explanation": "[2,1,3] is the smallest of the two matches."}, {"input": "s = \"DDI\"", "output": "[3,2,1,4]", "explanation": "Descending run reverses the first three slots."}], "hints": ["Start from 1..n+1, which is already the smallest ordering.", "Each maximal D-block must appear reversed; I slots need no change.", "Scan with two pointers and reverse each D-segment in place."], "statement": "A pattern string `s` of length `n` uses only the letters `I` (rising) and `D` (falling). It sketches a permutation of the numbers `1..n+1`: for each slot `i`, `I` demands `perm[i] < perm[i+1]` while `D` demands `perm[i] > perm[i+1]`.\n\nMany permutations can fit the same sketch. Build the smallest one in dictionary order.\n\n**Constraints:**\n\n- `1 <= s.length <= 10^5`\n- Each `s[i]` is `I` or `D`.\n", "solution": "## Approach\n\nBegin with the identity ordering `1..n+1`, the smallest possible arrangement. Rising slots already match, so only falling runs need work: locate each maximal block of consecutive `D`s and reverse the corresponding slice (one element longer than the block). Reversing turns that slice into a descent using the smallest numbers that can do so, preserving minimality elsewhere.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) \u2014 each position is scanned once and reversed at most once.\n- **Space Complexity:** O(n) for the answer.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findPermutation(self, s: str) -> List[int]:\n n = len(s)\n ans = list(range(1, n + 2))\n i = 0\n while i < n:\n if s[i] == \"D\":\n j = i\n while j < n and s[j] == \"D\":\n j += 1\n ans[i:j + 1] = ans[i:j + 1][::-1]\n i = j\n else:\n i += 1\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FindPermutation(s string) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def findPermutation(self, s: str) -> List[int]:\n return []\n", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> findPermutation(string s) {\n return {};\n }\n};"}, "fn": "findPermutation", "params": [{"name": "s", "type": "string"}], "outputType": "int_array", "tests": [["I"], ["DI"], ["DDI"], ["D"], ["II"], ["DD"], ["IDID"], ["DDDD"], ["IIII"], ["DDID"], ["IDDI"], ["DIDI"], ["IIDD"], ["DDII"], ["IDDDI"], ["DDDDD"], ["IIIII"], ["DIDIDI"], ["IIIDD"], ["DDDIII"], ["IID"], ["DDIID"], ["IDIDID"], ["DDDDDD"], ["IIIIII"], ["DIDDI"], ["IIDIID"], ["DDIDD"], ["IDDDDI"], ["DIDIID"]], "expected": [[1, 2], [2, 1, 3], [3, 2, 1, 4], [2, 1], [1, 2, 3], [3, 2, 1], [1, 3, 2, 5, 4], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [3, 2, 1, 5, 4], [1, 4, 3, 2, 5], [2, 1, 4, 3, 5], [1, 2, 5, 4, 3], [3, 2, 1, 4, 5], [1, 5, 4, 3, 2, 6], [6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 6, 5, 7], [1, 2, 3, 6, 5, 4], [4, 3, 2, 1, 5, 6, 7], [1, 2, 4, 3], [3, 2, 1, 4, 6, 5], [1, 3, 2, 5, 4, 7, 6], [7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7], [2, 1, 5, 4, 3, 6], [1, 2, 4, 3, 5, 7, 6], [3, 2, 1, 6, 5, 4], [1, 6, 5, 4, 3, 2, 7], [2, 1, 4, 3, 5, 7, 6]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "731", "slug": "find-pivot-index", "id": 731, "title": "Find Pivot Index", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/find-pivot-index/", "examples": [{"input": "nums = [1,7,3,6,5,6]", "output": "3", "explanation": "Left of index 3 sums to 11 and right also sums to 11."}, {"input": "nums = [1,2,3]", "output": "-1", "explanation": "No position balances both sides."}, {"input": "nums = [2,1,-1]", "output": "0", "explanation": "Left of index 0 is 0 and right (1 + -1) is also 0."}], "hints": ["The right sum at i equals total minus left sum minus nums[i].", "Sweep once keeping the left sum and compare against the implied right sum.", "Return the first index that balances; return -1 when none does."], "statement": "Find the leftmost position where the sum of elements strictly to its left equals the sum strictly to its right.\n\nTreat a missing side as zero. For `[1,7,3,6,5,6]`, index `3` works because `1+7+3 = 11` and `5+6 = 11`.\n\nReturn that index, or `-1` when every position is unbalanced.\n\n**Constraints:**\n- `1 <= nums.length <= 10^4`\n- `-1000 <= nums[i] <= 1000`\n", "solution": "## Approach\n\nAdd the whole array once. Then walk left to right keeping the sum seen so far; the right sum is total minus left minus the current value. The first index where both sides match is the answer, otherwise -1.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the array length.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def pivotIndex(self, nums: List[int]) -> int:\n total = sum(nums)\n left = 0\n for i, v in enumerate(nums):\n if left == total - left - v:\n return i\n left += v\n return -1\n```\n", "starter": {"go": "package main\n\nfunc PivotIndex(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def pivotIndex(self, nums: List[int]) -> int:\n return 0", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int pivotIndex(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "pivotIndex", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,7,3,6,5,6]"], ["[1,2,3]"], ["[2,1,-1]"], ["[1]"], ["[0]"], ["[0,0]"], ["[1,0]"], ["[0,1]"], ["[-1,-1,-1,-1,-1,0]"], ["[1,2,3,4,6]"], ["[2,3,5,1,4]"], ["[0,0,0,0]"], ["[1,-1,1,-1,1]"], ["[10,10,10,10,40]"], ["[5]"], ["[-1,1,0]"], ["[3,3,3]"], ["[1,1,1,1,1,6]"], ["[6,1,1,1,1,1]"], ["[2,2,2,2,8]"], ["[8,2,2,2,2]"], ["[1,2,3,4,5,15]"], ["[15,1,2,3,4,5]"], ["[0,1,-1]"], ["[1000,-1000,1000,-1000]"], ["[1,7,3,6,5,6,0]"], ["[0,1,7,3,6,5,6]"], ["[-1000,1000,0]"]], "expected": [3, -1, 0, 0, 0, 0, 0, 1, 2, 3, 2, 0, 0, -1, 0, 2, 1, -1, -1, -1, -1, -1, -1, 0, -1, 3, 4, 2], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "504", "slug": "find-right-interval", "id": 504, "title": "Find Right Interval", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/find-right-interval/", "examples": [{"input": "intervals = [[1,2]]", "output": "[-1]", "explanation": "No start reaches 2."}, {"input": "intervals = [[3,4],[2,3],[1,2]]", "output": "[-1,0,1]", "explanation": "Each end maps to the smallest sufficient start."}, {"input": "intervals = [[1,4],[2,3],[3,4]]", "output": "[-1,2,-1]", "explanation": "Only the middle interval finds a neighbor."}], "hints": ["Sort interval indices by start value once.", "For each end, binary-search the sorted starts for the first start at or beyond it.", "Translate the found position back to the original index, or -1 when absent."], "statement": "You receive `intervals`, where each entry holds `[start, end]` and every start value is unique. For each position `i`, locate its right neighbor: the index `j` whose start is at least `intervals[i][1]` (the end of `i`) and as small as possible. An interval may be its own neighbor. When no start reaches far enough, record `-1` for that position.\n\nReturn the list of neighbor indices, one per input interval, in the original order.\n\n**Constraints:**\n- `1 <= intervals.length <= 2 * 10^4`\n- Each inner pair has length 2 with `-10^6 <= start <= end <= 10^6`.\n- Starts are pairwise distinct.\n", "solution": "## Approach\n\nOrder interval indices by their start coordinate once. For each interval's end, binary-search that sorted start list for the leftmost start reaching at least the end, then map back to the original index (or `-1` when the search runs past the end).\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n), dominated by sorting plus one binary search per interval.\n- **Space Complexity:** O(n) for the ordering and answer arrays.\n\n## Implementation\n\n```python\nfrom bisect import bisect_left\nclass Solution:\n def findRightInterval(self, intervals):\n n = len(intervals)\n order = sorted(range(n), key=lambda i: intervals[i][0])\n starts = [intervals[i][0] for i in order]\n ans = []\n for s, e in intervals:\n pos = bisect_left(starts, e)\n ans.append(order[pos] if pos < n else -1)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FindRightInterval(intervals [][]int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def findRightInterval(self, intervals: List[List[int]]) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> findRightInterval(vector<vector<int>>& intervals) {\n return {};\n }\n};"}, "fn": "findRightInterval", "params": [{"name": "intervals", "type": "int_array_2d"}], "outputType": "int_array", "tests": [["[[1,2]]"], ["[[3,4],[2,3],[1,2]]"], ["[[1,4],[2,3],[3,4]]"], ["[[1,4]]"], ["[[1,2],[2,3],[3,4]]"], ["[[1,12],[2,9],[3,10],[4,11],[5,6]]"], ["[[-1000000,1000000]]"], ["[[0,0],[1,1],[2,2]]"], ["[[5,6],[1,2],[3,4]]"], ["[[1,3],[2,4],[3,5],[4,6]]"], ["[[2,3],[1,2]]"], ["[[10,20],[0,5],[5,10]]"], ["[[1,2],[3,4],[5,6]]"], ["[[4,5],[1,2],[2,3]]"], ["[[1,5],[2,3],[4,6]]"], ["[[0,10],[1,2],[3,4]]"], ["[[-5,-1],[-10,-6],[0,5]]"], ["[[1,1],[2,2],[3,3]]"], ["[[3,5],[1,10],[6,8]]"], ["[[100,200],[50,60],[10,20]]"], ["[[1,10],[11,20],[21,30]]"], ["[[5,5]]"], ["[[2,5],[5,10],[10,15]]"], ["[[-100,-50],[0,0],[50,100]]"], ["[[7,10],[1,3],[4,6]]"], ["[[1,100],[2,3],[4,5]]"], ["[[8,9],[3,4],[1,2],[5,6]]"], ["[[20,25],[10,15],[0,5]]"], ["[[1,2],[4,5],[3,6]]"], ["[[6,7],[2,8],[1,3]]"]], "expected": [[-1], [-1, 0, 1], [-1, 2, -1], [-1], [1, 2, -1], [-1, -1, -1, -1, -1], [-1], [0, 1, 2], [-1, 2, 0], [2, 3, -1, -1], [-1, 0], [-1, 2, 0], [1, 2, -1], [-1, 2, 0], [-1, 2, -1], [-1, 2, -1], [2, 0, -1], [0, 1, 2], [2, -1, -1], [-1, 0, 1], [1, 2, -1], [0], [1, 2, -1], [1, 1, -1], [-1, 2, 0], [-1, 2, -1], [-1, 3, 1, 0], [-1, 0, 1], [2, -1, -1], [-1, -1, 0]], "loose": false}