offcode 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1038) hide show
  1. package/README.md +38 -2
  2. package/data/index.json +1 -0
  3. package/data/problems/01-matrix.json +1 -0
  4. package/data/problems/1-bit-and-2-bit-characters.json +1 -0
  5. package/data/problems/132-pattern.json +1 -0
  6. package/data/problems/2-keys-keyboard.json +1 -0
  7. package/data/problems/24-game.json +1 -0
  8. package/data/problems/3sum-closest.json +1 -0
  9. package/data/problems/3sum-smaller.json +1 -0
  10. package/data/problems/3sum-with-multiplicity.json +1 -0
  11. package/data/problems/3sum.json +1 -0
  12. package/data/problems/4-keys-keyboard.json +1 -0
  13. package/data/problems/4sum-ii.json +1 -0
  14. package/data/problems/4sum.json +1 -0
  15. package/data/problems/accounts-merge.json +1 -0
  16. package/data/problems/add-binary.json +1 -0
  17. package/data/problems/add-bold-tag-in-string.json +1 -0
  18. package/data/problems/add-digits.json +1 -0
  19. package/data/problems/add-one-row-to-tree.json +1 -0
  20. package/data/problems/add-strings.json +1 -0
  21. package/data/problems/add-to-array-form-of-integer.json +1 -0
  22. package/data/problems/add-two-numbers-ii.json +1 -0
  23. package/data/problems/add-two-numbers.json +1 -0
  24. package/data/problems/additive-number.json +1 -0
  25. package/data/problems/advantage-shuffle.json +1 -0
  26. package/data/problems/alien-dictionary.json +1 -0
  27. package/data/problems/all-nodes-distance-k-in-binary-tree.json +1 -0
  28. package/data/problems/all-oone-data-structure.json +1 -0
  29. package/data/problems/all-paths-from-source-to-target.json +1 -0
  30. package/data/problems/all-possible-full-binary-trees.json +1 -0
  31. package/data/problems/ambiguous-coordinates.json +1 -0
  32. package/data/problems/android-unlock-patterns.json +1 -0
  33. package/data/problems/arithmetic-slices-ii-subsequence.json +1 -0
  34. package/data/problems/arithmetic-slices.json +1 -0
  35. package/data/problems/arranging-coins.json +1 -0
  36. package/data/problems/array-nesting.json +1 -0
  37. package/data/problems/array-of-doubled-pairs.json +1 -0
  38. package/data/problems/array-partition.json +1 -0
  39. package/data/problems/assign-cookies.json +1 -0
  40. package/data/problems/asteroid-collision.json +1 -0
  41. package/data/problems/available-captures-for-rook.json +1 -0
  42. package/data/problems/average-of-levels-in-binary-tree.json +1 -0
  43. package/data/problems/backspace-string-compare.json +1 -0
  44. package/data/problems/bag-of-tokens.json +1 -0
  45. package/data/problems/balanced-binary-tree.json +1 -0
  46. package/data/problems/base-7.json +1 -0
  47. package/data/problems/baseball-game.json +1 -0
  48. package/data/problems/basic-absolute-value.json +1 -0
  49. package/data/problems/basic-array-max.json +1 -0
  50. package/data/problems/basic-array-min.json +1 -0
  51. package/data/problems/basic-array-sum-rec.json +1 -0
  52. package/data/problems/basic-array-sum.json +1 -0
  53. package/data/problems/basic-average-floor.json +1 -0
  54. package/data/problems/basic-bubble-sort.json +1 -0
  55. package/data/problems/basic-calculator-ii.json +1 -0
  56. package/data/problems/basic-calculator-iii.json +1 -0
  57. package/data/problems/basic-calculator-iv.json +1 -0
  58. package/data/problems/basic-calculator.json +1 -0
  59. package/data/problems/basic-collatz-steps.json +1 -0
  60. package/data/problems/basic-contains-value.json +1 -0
  61. package/data/problems/basic-count-above.json +1 -0
  62. package/data/problems/basic-count-char.json +1 -0
  63. package/data/problems/basic-count-digits.json +1 -0
  64. package/data/problems/basic-count-evens.json +1 -0
  65. package/data/problems/basic-count-pairs.json +1 -0
  66. package/data/problems/basic-count-vowels.json +1 -0
  67. package/data/problems/basic-count-words.json +1 -0
  68. package/data/problems/basic-countdown.json +1 -0
  69. package/data/problems/basic-double-array.json +1 -0
  70. package/data/problems/basic-factorial-rec.json +1 -0
  71. package/data/problems/basic-factorial.json +1 -0
  72. package/data/problems/basic-fibonacci.json +1 -0
  73. package/data/problems/basic-find-index.json +1 -0
  74. package/data/problems/basic-gcd.json +1 -0
  75. package/data/problems/basic-grade-letter.json +1 -0
  76. package/data/problems/basic-has-duplicate.json +1 -0
  77. package/data/problems/basic-is-even.json +1 -0
  78. package/data/problems/basic-is-leap-year.json +1 -0
  79. package/data/problems/basic-is-sorted.json +1 -0
  80. package/data/problems/basic-max-frequency.json +1 -0
  81. package/data/problems/basic-max-of-three.json +1 -0
  82. package/data/problems/basic-max-of-two.json +1 -0
  83. package/data/problems/basic-palindrome-text.json +1 -0
  84. package/data/problems/basic-power-rec.json +1 -0
  85. package/data/problems/basic-power.json +1 -0
  86. package/data/problems/basic-repeat-string.json +1 -0
  87. package/data/problems/basic-reverse-array.json +1 -0
  88. package/data/problems/basic-reverse-number.json +1 -0
  89. package/data/problems/basic-reverse-text-rec.json +1 -0
  90. package/data/problems/basic-reverse-text.json +1 -0
  91. package/data/problems/basic-second-largest.json +1 -0
  92. package/data/problems/basic-sort-two.json +1 -0
  93. package/data/problems/basic-staircase.json +1 -0
  94. package/data/problems/basic-string-length.json +1 -0
  95. package/data/problems/basic-sum-1-to-n.json +1 -0
  96. package/data/problems/basic-sum-digits-rec.json +1 -0
  97. package/data/problems/basic-sum-multiples.json +1 -0
  98. package/data/problems/basic-sum-of-digits.json +1 -0
  99. package/data/problems/basic-temperature-advice.json +1 -0
  100. package/data/problems/basic-to-upper.json +1 -0
  101. package/data/problems/basic-triangle-sum.json +1 -0
  102. package/data/problems/battleships-in-a-board.json +1 -0
  103. package/data/problems/beautiful-arrangement-ii.json +1 -0
  104. package/data/problems/beautiful-arrangement.json +1 -0
  105. package/data/problems/beautiful-array.json +1 -0
  106. package/data/problems/best-meeting-point.json +1 -0
  107. package/data/problems/best-time-to-buy-and-sell-stock-ii.json +1 -0
  108. package/data/problems/best-time-to-buy-and-sell-stock-iii.json +1 -0
  109. package/data/problems/best-time-to-buy-and-sell-stock-iv.json +1 -0
  110. package/data/problems/best-time-to-buy-and-sell-stock-with-cooldown.json +1 -0
  111. package/data/problems/best-time-to-buy-and-sell-stock-with-transaction-fee.json +1 -0
  112. package/data/problems/best-time-to-buy-and-sell-stock.json +1 -0
  113. package/data/problems/binary-gap.json +1 -0
  114. package/data/problems/binary-number-with-alternating-bits.json +1 -0
  115. package/data/problems/binary-search-tree-iterator.json +1 -0
  116. package/data/problems/binary-search.json +1 -0
  117. package/data/problems/binary-subarrays-with-sum.json +1 -0
  118. package/data/problems/binary-tree-cameras.json +1 -0
  119. package/data/problems/binary-tree-inorder-traversal.json +1 -0
  120. package/data/problems/binary-tree-level-order-traversal-ii.json +1 -0
  121. package/data/problems/binary-tree-level-order-traversal.json +1 -0
  122. package/data/problems/binary-tree-longest-consecutive-sequence-ii.json +1 -0
  123. package/data/problems/binary-tree-longest-consecutive-sequence.json +1 -0
  124. package/data/problems/binary-tree-maximum-path-sum.json +1 -0
  125. package/data/problems/binary-tree-paths.json +1 -0
  126. package/data/problems/binary-tree-postorder-traversal.json +1 -0
  127. package/data/problems/binary-tree-preorder-traversal.json +1 -0
  128. package/data/problems/binary-tree-pruning.json +1 -0
  129. package/data/problems/binary-tree-right-side-view.json +1 -0
  130. package/data/problems/binary-tree-tilt.json +1 -0
  131. package/data/problems/binary-tree-upside-down.json +1 -0
  132. package/data/problems/binary-tree-vertical-order-traversal.json +1 -0
  133. package/data/problems/binary-tree-zigzag-level-order-traversal.json +1 -0
  134. package/data/problems/binary-trees-with-factors.json +1 -0
  135. package/data/problems/binary-watch.json +1 -0
  136. package/data/problems/bitwise-and-of-numbers-range.json +1 -0
  137. package/data/problems/bitwise-ors-of-subarrays.json +1 -0
  138. package/data/problems/boats-to-save-people.json +1 -0
  139. package/data/problems/bold-words-in-string.json +1 -0
  140. package/data/problems/bomb-enemy.json +1 -0
  141. package/data/problems/boundary-of-binary-tree.json +1 -0
  142. package/data/problems/brick-wall.json +1 -0
  143. package/data/problems/bricks-falling-when-hit.json +1 -0
  144. package/data/problems/broken-calculator.json +1 -0
  145. package/data/problems/buddy-strings.json +1 -0
  146. package/data/problems/build-a-matrix-with-conditions.json +1 -0
  147. package/data/problems/bulb-switcher-ii.json +1 -0
  148. package/data/problems/bulb-switcher.json +1 -0
  149. package/data/problems/bulls-and-cows.json +1 -0
  150. package/data/problems/burst-balloons.json +1 -0
  151. package/data/problems/bus-routes.json +1 -0
  152. package/data/problems/can-i-win.json +1 -0
  153. package/data/problems/can-place-flowers.json +1 -0
  154. package/data/problems/candy-crush.json +1 -0
  155. package/data/problems/candy.json +1 -0
  156. package/data/problems/capacity-to-ship-packages-within-d-days.json +1 -0
  157. package/data/problems/car-fleet.json +1 -0
  158. package/data/problems/car-pooling.json +1 -0
  159. package/data/problems/card-flipping-game.json +1 -0
  160. package/data/problems/cat-and-mouse.json +1 -0
  161. package/data/problems/chalkboard-xor-game.json +1 -0
  162. package/data/problems/champagne-tower.json +1 -0
  163. package/data/problems/cheapest-flights-within-k-stops.json +1 -0
  164. package/data/problems/check-completeness-of-a-binary-tree.json +1 -0
  165. package/data/problems/cherry-pickup.json +1 -0
  166. package/data/problems/circular-array-loop.json +1 -0
  167. package/data/problems/climbing-stairs.json +1 -0
  168. package/data/problems/clone-graph.json +1 -0
  169. package/data/problems/closest-binary-search-tree-value-ii.json +1 -0
  170. package/data/problems/closest-binary-search-tree-value.json +1 -0
  171. package/data/problems/closest-leaf-in-a-binary-tree.json +1 -0
  172. package/data/problems/coin-change-ii.json +1 -0
  173. package/data/problems/coin-change.json +1 -0
  174. package/data/problems/coin-path.json +1 -0
  175. package/data/problems/combination-sum-ii.json +1 -0
  176. package/data/problems/combination-sum-iii.json +1 -0
  177. package/data/problems/combination-sum-iv.json +1 -0
  178. package/data/problems/combination-sum.json +1 -0
  179. package/data/problems/combinations.json +1 -0
  180. package/data/problems/compare-version-numbers.json +1 -0
  181. package/data/problems/complete-binary-tree-inserter.json +1 -0
  182. package/data/problems/complex-number-multiplication.json +1 -0
  183. package/data/problems/concatenated-words.json +1 -0
  184. package/data/problems/concatenation-of-array.json +1 -0
  185. package/data/problems/consecutive-numbers-sum.json +1 -0
  186. package/data/problems/construct-binary-tree-from-inorder-and-postorder-traversal.json +1 -0
  187. package/data/problems/construct-binary-tree-from-preorder-and-inorder-traversal.json +1 -0
  188. package/data/problems/construct-binary-tree-from-preorder-and-postorder-traversal.json +1 -0
  189. package/data/problems/construct-binary-tree-from-string.json +1 -0
  190. package/data/problems/construct-quad-tree.json +1 -0
  191. package/data/problems/construct-string-from-binary-tree.json +1 -0
  192. package/data/problems/construct-the-rectangle.json +1 -0
  193. package/data/problems/contain-virus.json +1 -0
  194. package/data/problems/container-with-most-water.json +1 -0
  195. package/data/problems/contains-duplicate-ii.json +1 -0
  196. package/data/problems/contains-duplicate-iii.json +1 -0
  197. package/data/problems/contains-duplicate.json +1 -0
  198. package/data/problems/contiguous-array.json +1 -0
  199. package/data/problems/continuous-subarray-sum.json +1 -0
  200. package/data/problems/convert-a-number-to-hexadecimal.json +1 -0
  201. package/data/problems/convert-binary-search-tree-to-sorted-doubly-linked-list.json +1 -0
  202. package/data/problems/convert-bst-to-greater-tree.json +1 -0
  203. package/data/problems/convert-sorted-array-to-binary-search-tree.json +1 -0
  204. package/data/problems/convert-sorted-list-to-binary-search-tree.json +1 -0
  205. package/data/problems/convex-polygon.json +1 -0
  206. package/data/problems/copy-list-with-random-pointer.json +1 -0
  207. package/data/problems/count-and-say.json +1 -0
  208. package/data/problems/count-binary-substrings.json +1 -0
  209. package/data/problems/count-complete-tree-nodes.json +1 -0
  210. package/data/problems/count-different-palindromic-subsequences.json +1 -0
  211. package/data/problems/count-good-nodes-in-binary-tree.json +1 -0
  212. package/data/problems/count-numbers-with-unique-digits.json +1 -0
  213. package/data/problems/count-of-range-sum.json +1 -0
  214. package/data/problems/count-of-smaller-numbers-after-self.json +1 -0
  215. package/data/problems/count-primes.json +1 -0
  216. package/data/problems/count-the-repetitions.json +1 -0
  217. package/data/problems/count-unique-characters-of-all-substrings-of-a-given-string.json +1 -0
  218. package/data/problems/count-univalue-subtrees.json +1 -0
  219. package/data/problems/counting-bits.json +1 -0
  220. package/data/problems/couples-holding-hands.json +1 -0
  221. package/data/problems/course-schedule-ii.json +1 -0
  222. package/data/problems/course-schedule-iii.json +1 -0
  223. package/data/problems/course-schedule-iv.json +1 -0
  224. package/data/problems/course-schedule.json +1 -0
  225. package/data/problems/cousins-in-binary-tree.json +1 -0
  226. package/data/problems/cracking-the-safe.json +1 -0
  227. package/data/problems/create-maximum-number.json +1 -0
  228. package/data/problems/custom-sort-string.json +1 -0
  229. package/data/problems/cut-off-trees-for-golf-event.json +1 -0
  230. package/data/problems/daily-temperatures.json +1 -0
  231. package/data/problems/data-stream-as-disjoint-intervals.json +1 -0
  232. package/data/problems/decode-string.json +1 -0
  233. package/data/problems/decode-ways-ii.json +1 -0
  234. package/data/problems/decode-ways.json +1 -0
  235. package/data/problems/decoded-string-at-index.json +1 -0
  236. package/data/problems/degree-of-an-array.json +1 -0
  237. package/data/problems/delete-and-earn.json +1 -0
  238. package/data/problems/delete-columns-to-make-sorted-ii.json +1 -0
  239. package/data/problems/delete-columns-to-make-sorted-iii.json +1 -0
  240. package/data/problems/delete-columns-to-make-sorted.json +1 -0
  241. package/data/problems/delete-leaves-with-a-given-value.json +1 -0
  242. package/data/problems/delete-node-in-a-bst.json +1 -0
  243. package/data/problems/delete-node-in-a-linked-list.json +1 -0
  244. package/data/problems/delete-operation-for-two-strings.json +1 -0
  245. package/data/problems/design-add-and-search-words-data-structure.json +1 -0
  246. package/data/problems/design-circular-deque.json +1 -0
  247. package/data/problems/design-circular-queue.json +1 -0
  248. package/data/problems/design-compressed-string-iterator.json +1 -0
  249. package/data/problems/design-excel-sum-formula.json +1 -0
  250. package/data/problems/design-hashmap.json +1 -0
  251. package/data/problems/design-hashset.json +1 -0
  252. package/data/problems/design-hit-counter.json +1 -0
  253. package/data/problems/design-in-memory-file-system.json +1 -0
  254. package/data/problems/design-linked-list.json +1 -0
  255. package/data/problems/design-log-storage-system.json +1 -0
  256. package/data/problems/design-phone-directory.json +1 -0
  257. package/data/problems/design-search-autocomplete-system.json +1 -0
  258. package/data/problems/design-snake-game.json +1 -0
  259. package/data/problems/design-tic-tac-toe.json +1 -0
  260. package/data/problems/design-twitter.json +1 -0
  261. package/data/problems/detect-capital.json +1 -0
  262. package/data/problems/detect-squares.json +1 -0
  263. package/data/problems/di-string-match.json +1 -0
  264. package/data/problems/diagonal-traverse.json +1 -0
  265. package/data/problems/diameter-of-binary-tree.json +1 -0
  266. package/data/problems/different-ways-to-add-parentheses.json +1 -0
  267. package/data/problems/distinct-subsequences-ii.json +1 -0
  268. package/data/problems/distinct-subsequences.json +1 -0
  269. package/data/problems/distribute-candies.json +1 -0
  270. package/data/problems/distribute-coins-in-binary-tree.json +1 -0
  271. package/data/problems/divide-two-integers.json +1 -0
  272. package/data/problems/domino-and-tromino-tiling.json +1 -0
  273. package/data/problems/dota2-senate.json +1 -0
  274. package/data/problems/dungeon-game.json +1 -0
  275. package/data/problems/edit-distance.json +1 -0
  276. package/data/problems/elimination-game.json +1 -0
  277. package/data/problems/employee-free-time.json +1 -0
  278. package/data/problems/employee-importance.json +1 -0
  279. package/data/problems/encode-and-decode-strings.json +1 -0
  280. package/data/problems/encode-and-decode-tinyurl.json +1 -0
  281. package/data/problems/encode-n-ary-tree-to-binary-tree.json +1 -0
  282. package/data/problems/encode-string-with-shortest-length.json +1 -0
  283. package/data/problems/equal-rational-numbers.json +1 -0
  284. package/data/problems/equal-tree-partition.json +1 -0
  285. package/data/problems/erect-the-fence.json +1 -0
  286. package/data/problems/escape-the-ghosts.json +1 -0
  287. package/data/problems/evaluate-division.json +1 -0
  288. package/data/problems/evaluate-reverse-polish-notation.json +1 -0
  289. package/data/problems/exam-room.json +1 -0
  290. package/data/problems/excel-sheet-column-number.json +1 -0
  291. package/data/problems/excel-sheet-column-title.json +1 -0
  292. package/data/problems/exclusive-time-of-functions.json +1 -0
  293. package/data/problems/expression-add-operators.json +1 -0
  294. package/data/problems/expressive-words.json +1 -0
  295. package/data/problems/extra-characters-in-a-string.json +1 -0
  296. package/data/problems/factor-combinations.json +1 -0
  297. package/data/problems/factorial-trailing-zeroes.json +1 -0
  298. package/data/problems/fair-candy-swap.json +1 -0
  299. package/data/problems/falling-squares.json +1 -0
  300. package/data/problems/fibonacci-number.json +1 -0
  301. package/data/problems/find-all-anagrams-in-a-string.json +1 -0
  302. package/data/problems/find-all-duplicates-in-an-array.json +1 -0
  303. package/data/problems/find-all-numbers-disappeared-in-an-array.json +1 -0
  304. package/data/problems/find-anagram-mappings.json +1 -0
  305. package/data/problems/find-and-replace-in-string.json +1 -0
  306. package/data/problems/find-and-replace-pattern.json +1 -0
  307. package/data/problems/find-bottom-left-tree-value.json +1 -0
  308. package/data/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree.json +1 -0
  309. package/data/problems/find-duplicate-file-in-system.json +1 -0
  310. package/data/problems/find-duplicate-subtrees.json +1 -0
  311. package/data/problems/find-eventual-safe-states.json +1 -0
  312. package/data/problems/find-first-and-last-position-of-element-in-sorted-array.json +1 -0
  313. package/data/problems/find-in-mountain-array.json +1 -0
  314. package/data/problems/find-k-closest-elements.json +1 -0
  315. package/data/problems/find-k-pairs-with-smallest-sums.json +1 -0
  316. package/data/problems/find-k-th-smallest-pair-distance.json +1 -0
  317. package/data/problems/find-largest-value-in-each-tree-row.json +1 -0
  318. package/data/problems/find-leaves-of-binary-tree.json +1 -0
  319. package/data/problems/find-median-from-data-stream.json +1 -0
  320. package/data/problems/find-minimum-in-rotated-sorted-array-ii.json +1 -0
  321. package/data/problems/find-minimum-in-rotated-sorted-array.json +1 -0
  322. package/data/problems/find-mode-in-binary-search-tree.json +1 -0
  323. package/data/problems/find-peak-element.json +1 -0
  324. package/data/problems/find-permutation.json +1 -0
  325. package/data/problems/find-pivot-index.json +1 -0
  326. package/data/problems/find-right-interval.json +1 -0
  327. package/data/problems/find-smallest-letter-greater-than-target.json +1 -0
  328. package/data/problems/find-the-celebrity.json +1 -0
  329. package/data/problems/find-the-closest-palindrome.json +1 -0
  330. package/data/problems/find-the-derangement-of-an-array.json +1 -0
  331. package/data/problems/find-the-difference.json +1 -0
  332. package/data/problems/find-the-duplicate-number.json +1 -0
  333. package/data/problems/find-the-index-of-the-first-occurrence-in-a-string.json +1 -0
  334. package/data/problems/find-the-shortest-superstring.json +1 -0
  335. package/data/problems/find-the-town-judge.json +1 -0
  336. package/data/problems/first-bad-version.json +1 -0
  337. package/data/problems/first-missing-positive.json +1 -0
  338. package/data/problems/first-unique-character-in-a-string.json +1 -0
  339. package/data/problems/fizz-buzz.json +1 -0
  340. package/data/problems/flatten-2d-vector.json +1 -0
  341. package/data/problems/flatten-a-multilevel-doubly-linked-list.json +1 -0
  342. package/data/problems/flatten-binary-tree-to-linked-list.json +1 -0
  343. package/data/problems/flatten-nested-list-iterator.json +1 -0
  344. package/data/problems/flip-binary-tree-to-match-preorder-traversal.json +1 -0
  345. package/data/problems/flip-equivalent-binary-trees.json +1 -0
  346. package/data/problems/flip-game-ii.json +1 -0
  347. package/data/problems/flip-game.json +1 -0
  348. package/data/problems/flip-string-to-monotone-increasing.json +1 -0
  349. package/data/problems/flipping-an-image.json +1 -0
  350. package/data/problems/flood-fill.json +1 -0
  351. package/data/problems/fraction-addition-and-subtraction.json +1 -0
  352. package/data/problems/fraction-to-recurring-decimal.json +1 -0
  353. package/data/problems/freedom-trail.json +1 -0
  354. package/data/problems/friends-of-appropriate-ages.json +1 -0
  355. package/data/problems/frog-jump.json +1 -0
  356. package/data/problems/fruit-into-baskets.json +1 -0
  357. package/data/problems/game-of-life.json +1 -0
  358. package/data/problems/gas-station.json +1 -0
  359. package/data/problems/generalized-abbreviation.json +1 -0
  360. package/data/problems/generate-parentheses.json +1 -0
  361. package/data/problems/generate-random-point-in-a-circle.json +1 -0
  362. package/data/problems/global-and-local-inversions.json +1 -0
  363. package/data/problems/goat-latin.json +1 -0
  364. package/data/problems/graph-valid-tree.json +1 -0
  365. package/data/problems/gray-code.json +1 -0
  366. package/data/problems/greatest-common-divisor-of-strings.json +1 -0
  367. package/data/problems/greatest-common-divisor-traversal.json +1 -0
  368. package/data/problems/group-anagrams.json +1 -0
  369. package/data/problems/group-shifted-strings.json +1 -0
  370. package/data/problems/groups-of-special-equivalent-strings.json +1 -0
  371. package/data/problems/guess-number-higher-or-lower-ii.json +1 -0
  372. package/data/problems/guess-number-higher-or-lower.json +1 -0
  373. package/data/problems/guess-the-word.json +1 -0
  374. package/data/problems/h-index-ii.json +1 -0
  375. package/data/problems/h-index.json +1 -0
  376. package/data/problems/hamming-distance.json +1 -0
  377. package/data/problems/hand-of-straights.json +1 -0
  378. package/data/problems/happy-number.json +1 -0
  379. package/data/problems/heaters.json +1 -0
  380. package/data/problems/house-robber-ii.json +1 -0
  381. package/data/problems/house-robber-iii.json +1 -0
  382. package/data/problems/house-robber.json +1 -0
  383. package/data/problems/image-overlap.json +1 -0
  384. package/data/problems/image-smoother.json +1 -0
  385. package/data/problems/implement-magic-dictionary.json +1 -0
  386. package/data/problems/implement-queue-using-stacks.json +1 -0
  387. package/data/problems/implement-rand10-using-rand7.json +1 -0
  388. package/data/problems/implement-stack-using-queues.json +1 -0
  389. package/data/problems/implement-trie-prefix-tree.json +1 -0
  390. package/data/problems/increasing-order-search-tree.json +1 -0
  391. package/data/problems/increasing-triplet-subsequence.json +1 -0
  392. package/data/problems/inorder-successor-in-bst-ii.json +1 -0
  393. package/data/problems/inorder-successor-in-bst.json +1 -0
  394. package/data/problems/insert-delete-getrandom-o1-duplicates-allowed.json +1 -0
  395. package/data/problems/insert-delete-getrandom-o1.json +1 -0
  396. package/data/problems/insert-greatest-common-divisors-in-linked-list.json +1 -0
  397. package/data/problems/insert-interval.json +1 -0
  398. package/data/problems/insert-into-a-binary-search-tree.json +1 -0
  399. package/data/problems/insert-into-a-sorted-circular-linked-list.json +1 -0
  400. package/data/problems/insertion-sort-list.json +1 -0
  401. package/data/problems/integer-break.json +1 -0
  402. package/data/problems/integer-replacement.json +1 -0
  403. package/data/problems/integer-to-english-words.json +1 -0
  404. package/data/problems/integer-to-roman.json +1 -0
  405. package/data/problems/interleaving-string.json +1 -0
  406. package/data/problems/intersection-of-two-arrays-ii.json +1 -0
  407. package/data/problems/intersection-of-two-arrays.json +1 -0
  408. package/data/problems/intersection-of-two-linked-lists.json +1 -0
  409. package/data/problems/interval-list-intersections.json +1 -0
  410. package/data/problems/invert-binary-tree.json +1 -0
  411. package/data/problems/ip-to-cidr.json +1 -0
  412. package/data/problems/ipo.json +1 -0
  413. package/data/problems/is-graph-bipartite.json +1 -0
  414. package/data/problems/is-subsequence.json +1 -0
  415. package/data/problems/island-perimeter.json +1 -0
  416. package/data/problems/isomorphic-strings.json +1 -0
  417. package/data/problems/jewels-and-stones.json +1 -0
  418. package/data/problems/jump-game-ii.json +1 -0
  419. package/data/problems/jump-game-vii.json +1 -0
  420. package/data/problems/jump-game.json +1 -0
  421. package/data/problems/k-closest-points-to-origin.json +1 -0
  422. package/data/problems/k-diff-pairs-in-an-array.json +1 -0
  423. package/data/problems/k-empty-slots.json +1 -0
  424. package/data/problems/k-inverse-pairs-array.json +1 -0
  425. package/data/problems/k-similar-strings.json +1 -0
  426. package/data/problems/k-th-smallest-in-lexicographical-order.json +1 -0
  427. package/data/problems/k-th-smallest-prime-fraction.json +1 -0
  428. package/data/problems/k-th-symbol-in-grammar.json +1 -0
  429. package/data/problems/keyboard-row.json +1 -0
  430. package/data/problems/keys-and-rooms.json +1 -0
  431. package/data/problems/kill-process.json +1 -0
  432. package/data/problems/knight-dialer.json +1 -0
  433. package/data/problems/knight-probability-in-chessboard.json +1 -0
  434. package/data/problems/koko-eating-bananas.json +1 -0
  435. package/data/problems/kth-largest-element-in-a-stream.json +1 -0
  436. package/data/problems/kth-largest-element-in-an-array.json +1 -0
  437. package/data/problems/kth-smallest-element-in-a-bst.json +1 -0
  438. package/data/problems/kth-smallest-element-in-a-sorted-matrix.json +1 -0
  439. package/data/problems/kth-smallest-number-in-multiplication-table.json +1 -0
  440. package/data/problems/largest-bst-subtree.json +1 -0
  441. package/data/problems/largest-component-size-by-common-factor.json +1 -0
  442. package/data/problems/largest-divisible-subset.json +1 -0
  443. package/data/problems/largest-number-at-least-twice-of-others.json +1 -0
  444. package/data/problems/largest-number.json +1 -0
  445. package/data/problems/largest-palindrome-product.json +1 -0
  446. package/data/problems/largest-perimeter-triangle.json +1 -0
  447. package/data/problems/largest-plus-sign.json +1 -0
  448. package/data/problems/largest-rectangle-in-histogram.json +1 -0
  449. package/data/problems/largest-sum-of-averages.json +1 -0
  450. package/data/problems/largest-time-for-given-digits.json +1 -0
  451. package/data/problems/largest-triangle-area.json +1 -0
  452. package/data/problems/last-stone-weight-ii.json +1 -0
  453. package/data/problems/last-stone-weight.json +1 -0
  454. package/data/problems/leaf-similar-trees.json +1 -0
  455. package/data/problems/least-operators-to-express-number.json +1 -0
  456. package/data/problems/lemonade-change.json +1 -0
  457. package/data/problems/length-of-last-word.json +1 -0
  458. package/data/problems/length-of-longest-fibonacci-subsequence.json +1 -0
  459. package/data/problems/letter-case-permutation.json +1 -0
  460. package/data/problems/letter-combinations-of-a-phone-number.json +1 -0
  461. package/data/problems/lexicographical-numbers.json +1 -0
  462. package/data/problems/lfu-cache.json +1 -0
  463. package/data/problems/license-key-formatting.json +1 -0
  464. package/data/problems/line-reflection.json +1 -0
  465. package/data/problems/linked-list-components.json +1 -0
  466. package/data/problems/linked-list-cycle-ii.json +1 -0
  467. package/data/problems/linked-list-cycle.json +1 -0
  468. package/data/problems/linked-list-random-node.json +1 -0
  469. package/data/problems/logger-rate-limiter.json +1 -0
  470. package/data/problems/logical-or-of-two-binary-grids-represented-as-quad-trees.json +1 -0
  471. package/data/problems/lonely-pixel-i.json +1 -0
  472. package/data/problems/lonely-pixel-ii.json +1 -0
  473. package/data/problems/long-pressed-name.json +1 -0
  474. package/data/problems/longest-absolute-file-path.json +1 -0
  475. package/data/problems/longest-common-prefix.json +1 -0
  476. package/data/problems/longest-common-subsequence.json +1 -0
  477. package/data/problems/longest-consecutive-sequence.json +1 -0
  478. package/data/problems/longest-continuous-increasing-subsequence.json +1 -0
  479. package/data/problems/longest-happy-string.json +1 -0
  480. package/data/problems/longest-harmonious-subsequence.json +1 -0
  481. package/data/problems/longest-increasing-path-in-a-matrix.json +1 -0
  482. package/data/problems/longest-increasing-subsequence.json +1 -0
  483. package/data/problems/longest-line-of-consecutive-one-in-matrix.json +1 -0
  484. package/data/problems/longest-mountain-in-array.json +1 -0
  485. package/data/problems/longest-palindrome.json +1 -0
  486. package/data/problems/longest-palindromic-subsequence.json +1 -0
  487. package/data/problems/longest-palindromic-substring.json +1 -0
  488. package/data/problems/longest-repeating-character-replacement.json +1 -0
  489. package/data/problems/longest-substring-with-at-least-k-repeating-characters.json +1 -0
  490. package/data/problems/longest-substring-with-at-most-k-distinct-characters.json +1 -0
  491. package/data/problems/longest-substring-with-at-most-two-distinct-characters.json +1 -0
  492. package/data/problems/longest-substring-without-repeating-characters.json +1 -0
  493. package/data/problems/longest-turbulent-subarray.json +1 -0
  494. package/data/problems/longest-uncommon-subsequence-i.json +1 -0
  495. package/data/problems/longest-uncommon-subsequence-ii.json +1 -0
  496. package/data/problems/longest-univalue-path.json +1 -0
  497. package/data/problems/longest-valid-parentheses.json +1 -0
  498. package/data/problems/longest-word-in-dictionary-through-deleting.json +1 -0
  499. package/data/problems/longest-word-in-dictionary.json +1 -0
  500. package/data/problems/loud-and-rich.json +1 -0
  501. package/data/problems/lowest-common-ancestor-of-a-binary-search-tree.json +1 -0
  502. package/data/problems/lowest-common-ancestor-of-a-binary-tree.json +1 -0
  503. package/data/problems/lru-cache.json +1 -0
  504. package/data/problems/magic-squares-in-grid.json +1 -0
  505. package/data/problems/magical-string.json +1 -0
  506. package/data/problems/majority-element-ii.json +1 -0
  507. package/data/problems/majority-element.json +1 -0
  508. package/data/problems/making-a-large-island.json +1 -0
  509. package/data/problems/map-sum-pairs.json +1 -0
  510. package/data/problems/masking-personal-information.json +1 -0
  511. package/data/problems/matchsticks-to-square.json +1 -0
  512. package/data/problems/max-area-of-island.json +1 -0
  513. package/data/problems/max-chunks-to-make-sorted-ii.json +1 -0
  514. package/data/problems/max-chunks-to-make-sorted.json +1 -0
  515. package/data/problems/max-consecutive-ones-ii.json +1 -0
  516. package/data/problems/max-consecutive-ones.json +1 -0
  517. package/data/problems/max-increase-to-keep-city-skyline.json +1 -0
  518. package/data/problems/max-points-on-a-line.json +1 -0
  519. package/data/problems/max-stack.json +1 -0
  520. package/data/problems/max-sum-of-rectangle-no-larger-than-k.json +1 -0
  521. package/data/problems/maximal-rectangle.json +1 -0
  522. package/data/problems/maximal-square.json +1 -0
  523. package/data/problems/maximize-distance-to-closest-person.json +1 -0
  524. package/data/problems/maximum-average-subarray-i.json +1 -0
  525. package/data/problems/maximum-average-subarray-ii.json +1 -0
  526. package/data/problems/maximum-binary-tree-ii.json +1 -0
  527. package/data/problems/maximum-binary-tree.json +1 -0
  528. package/data/problems/maximum-depth-of-binary-tree.json +1 -0
  529. package/data/problems/maximum-depth-of-n-ary-tree.json +1 -0
  530. package/data/problems/maximum-distance-in-arrays.json +1 -0
  531. package/data/problems/maximum-frequency-stack.json +1 -0
  532. package/data/problems/maximum-gap.json +1 -0
  533. package/data/problems/maximum-length-of-pair-chain.json +1 -0
  534. package/data/problems/maximum-length-of-repeated-subarray.json +1 -0
  535. package/data/problems/maximum-product-of-three-numbers.json +1 -0
  536. package/data/problems/maximum-product-of-word-lengths.json +1 -0
  537. package/data/problems/maximum-product-subarray.json +1 -0
  538. package/data/problems/maximum-size-subarray-sum-equals-k.json +1 -0
  539. package/data/problems/maximum-subarray.json +1 -0
  540. package/data/problems/maximum-sum-circular-subarray.json +1 -0
  541. package/data/problems/maximum-sum-of-3-non-overlapping-subarrays.json +1 -0
  542. package/data/problems/maximum-swap.json +1 -0
  543. package/data/problems/maximum-vacation-days.json +1 -0
  544. package/data/problems/maximum-width-of-binary-tree.json +1 -0
  545. package/data/problems/maximum-width-ramp.json +1 -0
  546. package/data/problems/maximum-xor-of-two-numbers-in-an-array.json +1 -0
  547. package/data/problems/median-of-two-sorted-arrays.json +1 -0
  548. package/data/problems/meeting-rooms-ii.json +1 -0
  549. package/data/problems/meeting-rooms-iii.json +1 -0
  550. package/data/problems/meeting-rooms.json +1 -0
  551. package/data/problems/merge-intervals.json +1 -0
  552. package/data/problems/merge-k-sorted-lists.json +1 -0
  553. package/data/problems/merge-sorted-array.json +1 -0
  554. package/data/problems/merge-strings-alternately.json +1 -0
  555. package/data/problems/merge-triplets-to-form-target-triplet.json +1 -0
  556. package/data/problems/merge-two-binary-trees.json +1 -0
  557. package/data/problems/merge-two-sorted-lists.json +1 -0
  558. package/data/problems/middle-of-the-linked-list.json +1 -0
  559. package/data/problems/min-cost-climbing-stairs.json +1 -0
  560. package/data/problems/min-cost-to-connect-all-points.json +1 -0
  561. package/data/problems/min-stack.json +1 -0
  562. package/data/problems/minesweeper.json +1 -0
  563. package/data/problems/mini-parser.json +1 -0
  564. package/data/problems/minimize-malware-spread-ii.json +1 -0
  565. package/data/problems/minimize-malware-spread.json +1 -0
  566. package/data/problems/minimize-max-distance-to-gas-station.json +1 -0
  567. package/data/problems/minimum-absolute-difference-in-bst.json +1 -0
  568. package/data/problems/minimum-add-to-make-parentheses-valid.json +1 -0
  569. package/data/problems/minimum-area-rectangle-ii.json +1 -0
  570. package/data/problems/minimum-area-rectangle.json +1 -0
  571. package/data/problems/minimum-array-end.json +1 -0
  572. package/data/problems/minimum-ascii-delete-sum-for-two-strings.json +1 -0
  573. package/data/problems/minimum-cost-for-tickets.json +1 -0
  574. package/data/problems/minimum-cost-to-hire-k-workers.json +1 -0
  575. package/data/problems/minimum-cost-to-merge-stones.json +1 -0
  576. package/data/problems/minimum-depth-of-binary-tree.json +1 -0
  577. package/data/problems/minimum-distance-between-bst-nodes.json +1 -0
  578. package/data/problems/minimum-factorization.json +1 -0
  579. package/data/problems/minimum-falling-path-sum.json +1 -0
  580. package/data/problems/minimum-genetic-mutation.json +1 -0
  581. package/data/problems/minimum-height-trees.json +1 -0
  582. package/data/problems/minimum-increment-to-make-array-unique.json +1 -0
  583. package/data/problems/minimum-index-sum-of-two-lists.json +1 -0
  584. package/data/problems/minimum-interval-to-include-each-query.json +1 -0
  585. package/data/problems/minimum-moves-to-equal-array-elements-ii.json +1 -0
  586. package/data/problems/minimum-moves-to-equal-array-elements.json +1 -0
  587. package/data/problems/minimum-number-of-arrows-to-burst-balloons.json +1 -0
  588. package/data/problems/minimum-number-of-k-consecutive-bit-flips.json +1 -0
  589. package/data/problems/minimum-number-of-refueling-stops.json +1 -0
  590. package/data/problems/minimum-path-sum.json +1 -0
  591. package/data/problems/minimum-size-subarray-sum.json +1 -0
  592. package/data/problems/minimum-swaps-to-make-sequences-increasing.json +1 -0
  593. package/data/problems/minimum-time-difference.json +1 -0
  594. package/data/problems/minimum-unique-word-abbreviation.json +1 -0
  595. package/data/problems/minimum-window-subsequence.json +1 -0
  596. package/data/problems/minimum-window-substring.json +1 -0
  597. package/data/problems/mirror-reflection.json +1 -0
  598. package/data/problems/missing-number.json +1 -0
  599. package/data/problems/missing-ranges.json +1 -0
  600. package/data/problems/monotone-increasing-digits.json +1 -0
  601. package/data/problems/monotonic-array.json +1 -0
  602. package/data/problems/most-common-word.json +1 -0
  603. package/data/problems/most-frequent-subtree-sum.json +1 -0
  604. package/data/problems/most-profit-assigning-work.json +1 -0
  605. package/data/problems/most-stones-removed-with-same-row-or-column.json +1 -0
  606. package/data/problems/move-zeroes.json +1 -0
  607. package/data/problems/moving-average-from-data-stream.json +1 -0
  608. package/data/problems/multiply-strings.json +1 -0
  609. package/data/problems/my-calendar-i.json +1 -0
  610. package/data/problems/my-calendar-ii.json +1 -0
  611. package/data/problems/my-calendar-iii.json +1 -0
  612. package/data/problems/n-ary-tree-level-order-traversal.json +1 -0
  613. package/data/problems/n-ary-tree-postorder-traversal.json +1 -0
  614. package/data/problems/n-ary-tree-preorder-traversal.json +1 -0
  615. package/data/problems/n-queens-ii.json +1 -0
  616. package/data/problems/n-queens.json +1 -0
  617. package/data/problems/n-repeated-element-in-size-2n-array.json +1 -0
  618. package/data/problems/n-th-tribonacci-number.json +1 -0
  619. package/data/problems/nested-list-weight-sum-ii.json +1 -0
  620. package/data/problems/nested-list-weight-sum.json +1 -0
  621. package/data/problems/network-delay-time.json +1 -0
  622. package/data/problems/new-21-game.json +1 -0
  623. package/data/problems/next-closest-time.json +1 -0
  624. package/data/problems/next-greater-element-i.json +1 -0
  625. package/data/problems/next-greater-element-ii.json +1 -0
  626. package/data/problems/next-greater-element-iii.json +1 -0
  627. package/data/problems/next-permutation.json +1 -0
  628. package/data/problems/nim-game.json +1 -0
  629. package/data/problems/non-decreasing-array.json +1 -0
  630. package/data/problems/non-decreasing-subsequences.json +1 -0
  631. package/data/problems/non-negative-integers-without-consecutive-ones.json +1 -0
  632. package/data/problems/non-overlapping-intervals.json +1 -0
  633. package/data/problems/nth-digit.json +1 -0
  634. package/data/problems/nth-magical-number.json +1 -0
  635. package/data/problems/number-complement.json +1 -0
  636. package/data/problems/number-of-1-bits.json +1 -0
  637. package/data/problems/number-of-atoms.json +1 -0
  638. package/data/problems/number-of-boomerangs.json +1 -0
  639. package/data/problems/number-of-connected-components-in-an-undirected-graph.json +1 -0
  640. package/data/problems/number-of-corner-rectangles.json +1 -0
  641. package/data/problems/number-of-digit-one.json +1 -0
  642. package/data/problems/number-of-distinct-islands-ii.json +1 -0
  643. package/data/problems/number-of-distinct-islands.json +1 -0
  644. package/data/problems/number-of-islands-ii.json +1 -0
  645. package/data/problems/number-of-islands.json +1 -0
  646. package/data/problems/number-of-lines-to-write-string.json +1 -0
  647. package/data/problems/number-of-longest-increasing-subsequence.json +1 -0
  648. package/data/problems/number-of-matching-subsequences.json +1 -0
  649. package/data/problems/number-of-music-playlists.json +1 -0
  650. package/data/problems/number-of-provinces.json +1 -0
  651. package/data/problems/number-of-recent-calls.json +1 -0
  652. package/data/problems/number-of-segments-in-a-string.json +1 -0
  653. package/data/problems/number-of-squareful-arrays.json +1 -0
  654. package/data/problems/number-of-subarrays-with-bounded-maximum.json +1 -0
  655. package/data/problems/numbers-at-most-n-given-digit-set.json +1 -0
  656. package/data/problems/numbers-with-same-consecutive-differences.json +1 -0
  657. package/data/problems/odd-even-jump.json +1 -0
  658. package/data/problems/odd-even-linked-list.json +1 -0
  659. package/data/problems/one-edit-distance.json +1 -0
  660. package/data/problems/ones-and-zeroes.json +1 -0
  661. package/data/problems/online-election.json +1 -0
  662. package/data/problems/online-stock-span.json +1 -0
  663. package/data/problems/open-the-lock.json +1 -0
  664. package/data/problems/optimal-account-balancing.json +1 -0
  665. package/data/problems/optimal-division.json +1 -0
  666. package/data/problems/orderly-queue.json +1 -0
  667. package/data/problems/out-of-boundary-paths.json +1 -0
  668. package/data/problems/output-contest-matches.json +1 -0
  669. package/data/problems/pacific-atlantic-water-flow.json +1 -0
  670. package/data/problems/paint-fence.json +1 -0
  671. package/data/problems/paint-house-ii.json +1 -0
  672. package/data/problems/paint-house.json +1 -0
  673. package/data/problems/palindrome-linked-list.json +1 -0
  674. package/data/problems/palindrome-number.json +1 -0
  675. package/data/problems/palindrome-pairs.json +1 -0
  676. package/data/problems/palindrome-partitioning-ii.json +1 -0
  677. package/data/problems/palindrome-partitioning.json +1 -0
  678. package/data/problems/palindrome-permutation-ii.json +1 -0
  679. package/data/problems/palindrome-permutation.json +1 -0
  680. package/data/problems/palindromic-substrings.json +1 -0
  681. package/data/problems/pancake-sorting.json +1 -0
  682. package/data/problems/parse-lisp-expression.json +1 -0
  683. package/data/problems/partition-array-into-disjoint-intervals.json +1 -0
  684. package/data/problems/partition-equal-subset-sum.json +1 -0
  685. package/data/problems/partition-labels.json +1 -0
  686. package/data/problems/partition-list.json +1 -0
  687. package/data/problems/partition-to-k-equal-sum-subsets.json +1 -0
  688. package/data/problems/pascals-triangle-ii.json +1 -0
  689. package/data/problems/pascals-triangle.json +1 -0
  690. package/data/problems/patching-array.json +1 -0
  691. package/data/problems/path-sum-ii.json +1 -0
  692. package/data/problems/path-sum-iii.json +1 -0
  693. package/data/problems/path-sum-iv.json +1 -0
  694. package/data/problems/path-sum.json +1 -0
  695. package/data/problems/path-with-minimum-effort.json +1 -0
  696. package/data/problems/peak-index-in-a-mountain-array.json +1 -0
  697. package/data/problems/peeking-iterator.json +1 -0
  698. package/data/problems/perfect-number.json +1 -0
  699. package/data/problems/perfect-rectangle.json +1 -0
  700. package/data/problems/perfect-squares.json +1 -0
  701. package/data/problems/permutation-in-string.json +1 -0
  702. package/data/problems/permutation-sequence.json +1 -0
  703. package/data/problems/permutations-ii.json +1 -0
  704. package/data/problems/permutations.json +1 -0
  705. package/data/problems/plus-one-linked-list.json +1 -0
  706. package/data/problems/plus-one.json +1 -0
  707. package/data/problems/poor-pigs.json +1 -0
  708. package/data/problems/populating-next-right-pointers-in-each-node-ii.json +1 -0
  709. package/data/problems/populating-next-right-pointers-in-each-node.json +1 -0
  710. package/data/problems/positions-of-large-groups.json +1 -0
  711. package/data/problems/possible-bipartition.json +1 -0
  712. package/data/problems/pour-water.json +1 -0
  713. package/data/problems/power-of-four.json +1 -0
  714. package/data/problems/power-of-three.json +1 -0
  715. package/data/problems/power-of-two.json +1 -0
  716. package/data/problems/powerful-integers.json +1 -0
  717. package/data/problems/powx-n.json +1 -0
  718. package/data/problems/predict-the-winner.json +1 -0
  719. package/data/problems/prefix-and-suffix-search.json +1 -0
  720. package/data/problems/preimage-size-of-factorial-zeroes-function.json +1 -0
  721. package/data/problems/prime-number-of-set-bits-in-binary-representation.json +1 -0
  722. package/data/problems/prime-palindrome.json +1 -0
  723. package/data/problems/print-binary-tree.json +1 -0
  724. package/data/problems/prison-cells-after-n-days.json +1 -0
  725. package/data/problems/product-of-array-except-self.json +1 -0
  726. package/data/problems/profitable-schemes.json +1 -0
  727. package/data/problems/projection-area-of-3d-shapes.json +1 -0
  728. package/data/problems/push-dominoes.json +1 -0
  729. package/data/problems/pyramid-transition-matrix.json +1 -0
  730. package/data/problems/queue-reconstruction-by-height.json +1 -0
  731. package/data/problems/rabbits-in-forest.json +1 -0
  732. package/data/problems/race-car.json +1 -0
  733. package/data/problems/random-flip-matrix.json +1 -0
  734. package/data/problems/random-pick-index.json +1 -0
  735. package/data/problems/random-pick-with-blacklist.json +1 -0
  736. package/data/problems/random-pick-with-weight.json +1 -0
  737. package/data/problems/random-point-in-non-overlapping-rectangles.json +1 -0
  738. package/data/problems/range-addition-ii.json +1 -0
  739. package/data/problems/range-addition.json +1 -0
  740. package/data/problems/range-module.json +1 -0
  741. package/data/problems/range-sum-of-bst.json +1 -0
  742. package/data/problems/range-sum-query-2d-immutable.json +1 -0
  743. package/data/problems/range-sum-query-2d-mutable.json +1 -0
  744. package/data/problems/range-sum-query-immutable.json +1 -0
  745. package/data/problems/range-sum-query-mutable.json +1 -0
  746. package/data/problems/ransom-note.json +1 -0
  747. package/data/problems/reach-a-number.json +1 -0
  748. package/data/problems/reachable-nodes-in-subdivided-graph.json +1 -0
  749. package/data/problems/reaching-points.json +1 -0
  750. package/data/problems/read-n-characters-given-read4-ii-call-multiple-times.json +1 -0
  751. package/data/problems/read-n-characters-given-read4.json +1 -0
  752. package/data/problems/rearrange-string-k-distance-apart.json +1 -0
  753. package/data/problems/reconstruct-itinerary.json +1 -0
  754. package/data/problems/reconstruct-original-digits-from-english.json +1 -0
  755. package/data/problems/recover-binary-search-tree.json +1 -0
  756. package/data/problems/rectangle-area-ii.json +1 -0
  757. package/data/problems/rectangle-area.json +1 -0
  758. package/data/problems/rectangle-overlap.json +1 -0
  759. package/data/problems/redundant-connection-ii.json +1 -0
  760. package/data/problems/redundant-connection.json +1 -0
  761. package/data/problems/regions-cut-by-slashes.json +1 -0
  762. package/data/problems/regular-expression-matching.json +1 -0
  763. package/data/problems/relative-ranks.json +1 -0
  764. package/data/problems/remove-9.json +1 -0
  765. package/data/problems/remove-boxes.json +1 -0
  766. package/data/problems/remove-comments.json +1 -0
  767. package/data/problems/remove-duplicate-letters.json +1 -0
  768. package/data/problems/remove-duplicates-from-sorted-array-ii.json +1 -0
  769. package/data/problems/remove-duplicates-from-sorted-array.json +1 -0
  770. package/data/problems/remove-duplicates-from-sorted-list-ii.json +1 -0
  771. package/data/problems/remove-duplicates-from-sorted-list.json +1 -0
  772. package/data/problems/remove-element.json +1 -0
  773. package/data/problems/remove-invalid-parentheses.json +1 -0
  774. package/data/problems/remove-k-digits.json +1 -0
  775. package/data/problems/remove-linked-list-elements.json +1 -0
  776. package/data/problems/remove-nth-node-from-end-of-list.json +1 -0
  777. package/data/problems/reorder-data-in-log-files.json +1 -0
  778. package/data/problems/reorder-list.json +1 -0
  779. package/data/problems/reordered-power-of-2.json +1 -0
  780. package/data/problems/reorganize-string.json +1 -0
  781. package/data/problems/repeated-dna-sequences.json +1 -0
  782. package/data/problems/repeated-string-match.json +1 -0
  783. package/data/problems/repeated-substring-pattern.json +1 -0
  784. package/data/problems/replace-words.json +1 -0
  785. package/data/problems/reshape-the-matrix.json +1 -0
  786. package/data/problems/restore-ip-addresses.json +1 -0
  787. package/data/problems/reveal-cards-in-increasing-order.json +1 -0
  788. package/data/problems/reverse-bits.json +1 -0
  789. package/data/problems/reverse-integer.json +1 -0
  790. package/data/problems/reverse-linked-list-ii.json +1 -0
  791. package/data/problems/reverse-linked-list.json +1 -0
  792. package/data/problems/reverse-nodes-in-k-group.json +1 -0
  793. package/data/problems/reverse-only-letters.json +1 -0
  794. package/data/problems/reverse-pairs.json +1 -0
  795. package/data/problems/reverse-string-ii.json +1 -0
  796. package/data/problems/reverse-string.json +1 -0
  797. package/data/problems/reverse-vowels-of-a-string.json +1 -0
  798. package/data/problems/reverse-words-in-a-string-ii.json +1 -0
  799. package/data/problems/reverse-words-in-a-string-iii.json +1 -0
  800. package/data/problems/reverse-words-in-a-string.json +1 -0
  801. package/data/problems/rle-iterator.json +1 -0
  802. package/data/problems/robot-return-to-origin.json +1 -0
  803. package/data/problems/robot-room-cleaner.json +1 -0
  804. package/data/problems/roman-to-integer.json +1 -0
  805. package/data/problems/rotate-array.json +1 -0
  806. package/data/problems/rotate-function.json +1 -0
  807. package/data/problems/rotate-image.json +1 -0
  808. package/data/problems/rotate-list.json +1 -0
  809. package/data/problems/rotate-string.json +1 -0
  810. package/data/problems/rotated-digits.json +1 -0
  811. package/data/problems/rotting-oranges.json +1 -0
  812. package/data/problems/russian-doll-envelopes.json +1 -0
  813. package/data/problems/same-tree.json +1 -0
  814. package/data/problems/satisfiability-of-equality-equations.json +1 -0
  815. package/data/problems/score-after-flipping-matrix.json +1 -0
  816. package/data/problems/score-of-parentheses.json +1 -0
  817. package/data/problems/scramble-string.json +1 -0
  818. package/data/problems/search-a-2d-matrix-ii.json +1 -0
  819. package/data/problems/search-a-2d-matrix.json +1 -0
  820. package/data/problems/search-in-a-binary-search-tree.json +1 -0
  821. package/data/problems/search-in-a-sorted-array-of-unknown-size.json +1 -0
  822. package/data/problems/search-in-rotated-sorted-array-ii.json +1 -0
  823. package/data/problems/search-in-rotated-sorted-array.json +1 -0
  824. package/data/problems/search-insert-position.json +1 -0
  825. package/data/problems/second-minimum-node-in-a-binary-tree.json +1 -0
  826. package/data/problems/self-crossing.json +1 -0
  827. package/data/problems/self-dividing-numbers.json +1 -0
  828. package/data/problems/sentence-screen-fitting.json +1 -0
  829. package/data/problems/sentence-similarity-ii.json +1 -0
  830. package/data/problems/sentence-similarity.json +1 -0
  831. package/data/problems/sequence-reconstruction.json +1 -0
  832. package/data/problems/serialize-and-deserialize-binary-tree.json +1 -0
  833. package/data/problems/serialize-and-deserialize-bst.json +1 -0
  834. package/data/problems/serialize-and-deserialize-n-ary-tree.json +1 -0
  835. package/data/problems/set-intersection-size-at-least-two.json +1 -0
  836. package/data/problems/set-matrix-zeroes.json +1 -0
  837. package/data/problems/set-mismatch.json +1 -0
  838. package/data/problems/shifting-letters.json +1 -0
  839. package/data/problems/shopping-offers.json +1 -0
  840. package/data/problems/short-encoding-of-words.json +1 -0
  841. package/data/problems/shortest-bridge.json +1 -0
  842. package/data/problems/shortest-completing-word.json +1 -0
  843. package/data/problems/shortest-distance-from-all-buildings.json +1 -0
  844. package/data/problems/shortest-distance-to-a-character.json +1 -0
  845. package/data/problems/shortest-palindrome.json +1 -0
  846. package/data/problems/shortest-path-to-get-all-keys.json +1 -0
  847. package/data/problems/shortest-path-visiting-all-nodes.json +1 -0
  848. package/data/problems/shortest-subarray-with-sum-at-least-k.json +1 -0
  849. package/data/problems/shortest-unsorted-continuous-subarray.json +1 -0
  850. package/data/problems/shortest-word-distance-ii.json +1 -0
  851. package/data/problems/shortest-word-distance-iii.json +1 -0
  852. package/data/problems/shortest-word-distance.json +1 -0
  853. package/data/problems/shuffle-an-array.json +1 -0
  854. package/data/problems/similar-rgb-color.json +1 -0
  855. package/data/problems/similar-string-groups.json +1 -0
  856. package/data/problems/simplify-path.json +1 -0
  857. package/data/problems/single-element-in-a-sorted-array.json +1 -0
  858. package/data/problems/single-number-ii.json +1 -0
  859. package/data/problems/single-number-iii.json +1 -0
  860. package/data/problems/single-number.json +1 -0
  861. package/data/problems/single-threaded-cpu.json +1 -0
  862. package/data/problems/sliding-puzzle.json +1 -0
  863. package/data/problems/sliding-window-maximum.json +1 -0
  864. package/data/problems/sliding-window-median.json +1 -0
  865. package/data/problems/smallest-good-base.json +1 -0
  866. package/data/problems/smallest-range-covering-elements-from-k-lists.json +1 -0
  867. package/data/problems/smallest-range-i.json +1 -0
  868. package/data/problems/smallest-range-ii.json +1 -0
  869. package/data/problems/smallest-rectangle-enclosing-black-pixels.json +1 -0
  870. package/data/problems/smallest-rotation-with-highest-score.json +1 -0
  871. package/data/problems/smallest-string-starting-from-leaf.json +1 -0
  872. package/data/problems/smallest-subtree-with-all-the-deepest-nodes.json +1 -0
  873. package/data/problems/snakes-and-ladders.json +1 -0
  874. package/data/problems/solve-the-equation.json +1 -0
  875. package/data/problems/sort-an-array.json +1 -0
  876. package/data/problems/sort-array-by-parity-ii.json +1 -0
  877. package/data/problems/sort-array-by-parity.json +1 -0
  878. package/data/problems/sort-characters-by-frequency.json +1 -0
  879. package/data/problems/sort-colors.json +1 -0
  880. package/data/problems/sort-list.json +1 -0
  881. package/data/problems/sort-transformed-array.json +1 -0
  882. package/data/problems/soup-servings.json +1 -0
  883. package/data/problems/sparse-matrix-multiplication.json +1 -0
  884. package/data/problems/special-binary-string.json +1 -0
  885. package/data/problems/spiral-matrix-ii.json +1 -0
  886. package/data/problems/spiral-matrix-iii.json +1 -0
  887. package/data/problems/spiral-matrix.json +1 -0
  888. package/data/problems/split-array-into-consecutive-subsequences.json +1 -0
  889. package/data/problems/split-array-into-fibonacci-sequence.json +1 -0
  890. package/data/problems/split-array-largest-sum.json +1 -0
  891. package/data/problems/split-array-with-equal-sum.json +1 -0
  892. package/data/problems/split-array-with-same-average.json +1 -0
  893. package/data/problems/split-bst.json +1 -0
  894. package/data/problems/split-concatenated-strings.json +1 -0
  895. package/data/problems/split-linked-list-in-parts.json +1 -0
  896. package/data/problems/sqrtx.json +1 -0
  897. package/data/problems/squares-of-a-sorted-array.json +1 -0
  898. package/data/problems/squirrel-simulation.json +1 -0
  899. package/data/problems/stamping-the-sequence.json +1 -0
  900. package/data/problems/stickers-to-spell-word.json +1 -0
  901. package/data/problems/stone-game-ii.json +1 -0
  902. package/data/problems/stone-game-iii.json +1 -0
  903. package/data/problems/stone-game.json +1 -0
  904. package/data/problems/strange-printer.json +1 -0
  905. package/data/problems/string-compression.json +1 -0
  906. package/data/problems/string-to-integer-atoi.json +1 -0
  907. package/data/problems/string-without-aaa-or-bbb.json +1 -0
  908. package/data/problems/strobogrammatic-number-ii.json +1 -0
  909. package/data/problems/strobogrammatic-number-iii.json +1 -0
  910. package/data/problems/strobogrammatic-number.json +1 -0
  911. package/data/problems/strong-password-checker.json +1 -0
  912. package/data/problems/student-attendance-record-i.json +1 -0
  913. package/data/problems/student-attendance-record-ii.json +1 -0
  914. package/data/problems/subarray-product-less-than-k.json +1 -0
  915. package/data/problems/subarray-sum-equals-k.json +1 -0
  916. package/data/problems/subarray-sums-divisible-by-k.json +1 -0
  917. package/data/problems/subarrays-with-k-different-integers.json +1 -0
  918. package/data/problems/subdomain-visit-count.json +1 -0
  919. package/data/problems/subsets-ii.json +1 -0
  920. package/data/problems/subsets.json +1 -0
  921. package/data/problems/substring-with-concatenation-of-all-words.json +1 -0
  922. package/data/problems/subtree-of-another-tree.json +1 -0
  923. package/data/problems/sudoku-solver.json +1 -0
  924. package/data/problems/sum-of-all-subset-xor-totals.json +1 -0
  925. package/data/problems/sum-of-distances-in-tree.json +1 -0
  926. package/data/problems/sum-of-even-numbers-after-queries.json +1 -0
  927. package/data/problems/sum-of-left-leaves.json +1 -0
  928. package/data/problems/sum-of-square-numbers.json +1 -0
  929. package/data/problems/sum-of-subarray-minimums.json +1 -0
  930. package/data/problems/sum-of-subsequence-widths.json +1 -0
  931. package/data/problems/sum-of-two-integers.json +1 -0
  932. package/data/problems/sum-root-to-leaf-numbers.json +1 -0
  933. package/data/problems/summary-ranges.json +1 -0
  934. package/data/problems/super-egg-drop.json +1 -0
  935. package/data/problems/super-palindromes.json +1 -0
  936. package/data/problems/super-pow.json +1 -0
  937. package/data/problems/super-ugly-number.json +1 -0
  938. package/data/problems/super-washing-machines.json +1 -0
  939. package/data/problems/surface-area-of-3d-shapes.json +1 -0
  940. package/data/problems/surrounded-regions.json +1 -0
  941. package/data/problems/swap-adjacent-in-lr-string.json +1 -0
  942. package/data/problems/swap-nodes-in-pairs.json +1 -0
  943. package/data/problems/swim-in-rising-water.json +1 -0
  944. package/data/problems/symmetric-tree.json +1 -0
  945. package/data/problems/tag-validator.json +1 -0
  946. package/data/problems/tallest-billboard.json +1 -0
  947. package/data/problems/target-sum.json +1 -0
  948. package/data/problems/task-scheduler.json +1 -0
  949. package/data/problems/teemo-attacking.json +1 -0
  950. package/data/problems/ternary-expression-parser.json +1 -0
  951. package/data/problems/text-justification.json +1 -0
  952. package/data/problems/the-maze-ii.json +1 -0
  953. package/data/problems/the-maze-iii.json +1 -0
  954. package/data/problems/the-maze.json +1 -0
  955. package/data/problems/the-skyline-problem.json +1 -0
  956. package/data/problems/third-maximum-number.json +1 -0
  957. package/data/problems/three-equal-parts.json +1 -0
  958. package/data/problems/time-based-key-value-store.json +1 -0
  959. package/data/problems/to-lower-case.json +1 -0
  960. package/data/problems/toeplitz-matrix.json +1 -0
  961. package/data/problems/top-k-frequent-elements.json +1 -0
  962. package/data/problems/top-k-frequent-words.json +1 -0
  963. package/data/problems/total-hamming-distance.json +1 -0
  964. package/data/problems/transform-to-chessboard.json +1 -0
  965. package/data/problems/transpose-matrix.json +1 -0
  966. package/data/problems/trapping-rain-water-ii.json +1 -0
  967. package/data/problems/trapping-rain-water.json +1 -0
  968. package/data/problems/triangle.json +1 -0
  969. package/data/problems/trim-a-binary-search-tree.json +1 -0
  970. package/data/problems/triples-with-bitwise-and-equal-to-zero.json +1 -0
  971. package/data/problems/two-sum-ii-input-array-is-sorted.json +1 -0
  972. package/data/problems/two-sum-iii-data-structure-design.json +1 -0
  973. package/data/problems/two-sum-iv-input-is-a-bst.json +1 -0
  974. package/data/problems/two-sum.json +1 -0
  975. package/data/problems/ugly-number-ii.json +1 -0
  976. package/data/problems/ugly-number.json +1 -0
  977. package/data/problems/uncommon-words-from-two-sentences.json +1 -0
  978. package/data/problems/unique-binary-search-trees-ii.json +1 -0
  979. package/data/problems/unique-binary-search-trees.json +1 -0
  980. package/data/problems/unique-email-addresses.json +1 -0
  981. package/data/problems/unique-morse-code-words.json +1 -0
  982. package/data/problems/unique-paths-ii.json +1 -0
  983. package/data/problems/unique-paths-iii.json +1 -0
  984. package/data/problems/unique-paths.json +1 -0
  985. package/data/problems/unique-substrings-in-wraparound-string.json +1 -0
  986. package/data/problems/unique-word-abbreviation.json +1 -0
  987. package/data/problems/univalued-binary-tree.json +1 -0
  988. package/data/problems/utf-8-validation.json +1 -0
  989. package/data/problems/valid-anagram.json +1 -0
  990. package/data/problems/valid-mountain-array.json +1 -0
  991. package/data/problems/valid-number.json +1 -0
  992. package/data/problems/valid-palindrome-ii.json +1 -0
  993. package/data/problems/valid-palindrome.json +1 -0
  994. package/data/problems/valid-parentheses.json +1 -0
  995. package/data/problems/valid-parenthesis-string.json +1 -0
  996. package/data/problems/valid-perfect-square.json +1 -0
  997. package/data/problems/valid-permutations-for-di-sequence.json +1 -0
  998. package/data/problems/valid-square.json +1 -0
  999. package/data/problems/valid-sudoku.json +1 -0
  1000. package/data/problems/valid-tic-tac-toe-state.json +1 -0
  1001. package/data/problems/valid-triangle-number.json +1 -0
  1002. package/data/problems/valid-word-abbreviation.json +1 -0
  1003. package/data/problems/valid-word-square.json +1 -0
  1004. package/data/problems/validate-binary-search-tree.json +1 -0
  1005. package/data/problems/validate-ip-address.json +1 -0
  1006. package/data/problems/validate-stack-sequences.json +1 -0
  1007. package/data/problems/verify-preorder-sequence-in-binary-search-tree.json +1 -0
  1008. package/data/problems/verify-preorder-serialization-of-a-binary-tree.json +1 -0
  1009. package/data/problems/verifying-an-alien-dictionary.json +1 -0
  1010. package/data/problems/vertical-order-traversal-of-a-binary-tree.json +1 -0
  1011. package/data/problems/vowel-spellchecker.json +1 -0
  1012. package/data/problems/walking-robot-simulation.json +1 -0
  1013. package/data/problems/walls-and-gates.json +1 -0
  1014. package/data/problems/water-and-jug-problem.json +1 -0
  1015. package/data/problems/wiggle-sort-ii.json +1 -0
  1016. package/data/problems/wiggle-sort.json +1 -0
  1017. package/data/problems/wiggle-subsequence.json +1 -0
  1018. package/data/problems/wildcard-matching.json +1 -0
  1019. package/data/problems/word-abbreviation.json +1 -0
  1020. package/data/problems/word-break-ii.json +1 -0
  1021. package/data/problems/word-break.json +1 -0
  1022. package/data/problems/word-ladder-ii.json +1 -0
  1023. package/data/problems/word-ladder.json +1 -0
  1024. package/data/problems/word-pattern-ii.json +1 -0
  1025. package/data/problems/word-pattern.json +1 -0
  1026. package/data/problems/word-search-ii.json +1 -0
  1027. package/data/problems/word-search.json +1 -0
  1028. package/data/problems/word-squares.json +1 -0
  1029. package/data/problems/word-subsets.json +1 -0
  1030. package/data/problems/x-of-a-kind-in-a-deck-of-cards.json +1 -0
  1031. package/data/problems/zigzag-conversion.json +1 -0
  1032. package/data/problems/zigzag-iterator.json +1 -0
  1033. package/data/problems/zuma-game.json +1 -0
  1034. package/dist/cli.js +793 -0
  1035. package/dist/web/assets/index-DCYvZg7a.js +150 -0
  1036. package/dist/web/assets/index-gSBueMfH.css +1 -0
  1037. package/dist/web/index.html +13 -0
  1038. package/package.json +44 -4
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "535", "slug": "implement-rand10-using-rand7", "id": 535, "title": "Implement Rand10() Using Rand7()", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/implement-rand10-using-rand7/", "examples": [{"input": "calls = 1", "output": "[4]", "explanation": "Any single value from 1 to 10 is acceptable; the judge only checks the range."}, {"input": "calls = 3", "output": "[7,2,9]", "explanation": "Return one independent uniform draw per requested call."}], "hints": ["Two rand7 draws combine into 49 equally likely pairs; map them to the numbers 1-40 and retry on 41-49.", "Each accepted value `r` in 1..40 converts with `(r - 1) % 10 + 1`."], "statement": "In the original form of this task you are given a uniform generator `rand7()` producing integers 1 through 7, and you must build a uniform `rand10()` producing integers 1 through 10 from it.\n\n**Offline adaptation used here:** implement `runRand10(calls)`, which returns an array of length `calls` where each entry is an integer from 1 to 10. Inside your solution you may write your own `rand7` helper (a uniform 1..7 source) and derive each draw with rejection sampling: combine two `rand7` results into a uniform value `r` in 1..49 via `r = (rand7() - 1) * 7 + rand7()`, keep it when `r <= 40` as `(r - 1) % 10 + 1`, and retry otherwise. The reference judge simulates `rand7` with a fixed seed internally.\n\nGrading checks that the returned array has exactly `calls` entries and that every entry lies in 1..10. On longer runs (`calls >= 100`) every face 1..10 must also appear at least once \u2014 a constant array passes the range check but fails coverage, so the draws must genuinely vary (distribution uniformity beyond coverage is not measured).\n\n**Constraints:**\n- `1 <= calls <= 1000`\n", "solution": "## Approach\n\nSimulate the classic rejection sampler: a private `rand7` helper draws uniform values 1..7 from a fixed-seed generator, and each `rand10` draw combines two of them into a uniform 1..49 number. Values 1..40 map evenly onto 1..10 with `(r - 1) % 10 + 1`, while 41..49 are discarded and retried, which keeps every output uniform. Repeat once per requested call.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(calls) expected time, since each draw succeeds with probability 40/49.\n- **Space Complexity:** O(calls) for the output array.\n\n## Implementation\n\n```python\nimport random\nfrom typing import List\n\nclass Solution:\n def runRand10(self, calls: int) -> List[int]:\n rng = random.Random(42)\n\n def rand7() -> int:\n return rng.randint(1, 7)\n\n out = []\n for _ in range(calls):\n while True:\n r = (rand7() - 1) * 7 + rand7()\n if r <= 40:\n out.append((r - 1) % 10 + 1)\n break\n return out\n```\n", "starter": {"go": "package main\n\nfunc RunRand10(calls int) []int {\n \n}", "python": "from typing import List\nclass Solution:\n def runRand10(self, calls: int) -> List[int]:\n pass", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runRand10(int calls) {\n return {};\n }\n};"}, "fn": "runRand10", "params": [{"name": "calls", "type": "int"}], "outputType": "int_array", "tests": [["1"], ["2"], ["10"], ["50"], ["200"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["11"], ["12"], ["15"], ["20"], ["25"], ["30"], ["40"], ["60"], ["75"], ["100"], ["150"], ["300"], ["500"], ["1000"], ["13"], ["17"], ["22"], ["33"]], "expected": [[3], [10, 1], [6, 1, 1, 6, 3, 7, 10, 3, 4, 4], [8, 6, 7, 1, 2, 6, 6, 5, 1, 1, 6, 1, 10, 3, 9, 3, 6, 2, 6, 5, 9, 1, 6, 6, 7, 3, 10, 1, 9, 3, 6, 9, 10, 4, 3, 4, 10, 5, 1, 8, 4, 7, 2, 9, 5, 3, 1, 4, 1, 9], [9, 4, 1, 5, 3, 4, 6, 7, 9, 8, 8, 10, 5, 8, 2, 7, 5, 1, 7, 8, 3, 5, 9, 8, 2, 4, 1, 6, 7, 8, 10, 6, 3, 7, 2, 6, 9, 5, 2, 5, 10, 4, 6, 6, 9, 3, 8, 3, 2, 10, 7, 5, 8, 5, 3, 3, 10, 3, 9, 5, 1, 4, 3, 7, 4, 2, 4, 6, 4, 6, 5, 8, 1, 2, 5, 5, 7, 9, 9, 9, 4, 3, 10, 2, 8, 7, 2, 4, 4, 9, 8, 6, 7, 8, 9, 2, 4, 4, 7, 10, 8, 3, 10, 9, 6, 2, 5, 10, 6, 10, 3, 5, 1, 7, 1, 9, 4, 3, 9, 9, 1, 10, 8, 6, 1, 4, 5, 8, 6, 5, 6, 9, 7, 5, 9, 5, 7, 1, 1, 6, 2, 3, 1, 8, 1, 2, 10, 8, 9, 5, 1, 6, 9, 3, 1, 7, 1, 4, 3, 2, 3, 10, 9, 5, 10, 5, 1, 3, 9, 4, 5, 1, 9, 1, 9, 6, 5, 1, 6, 3, 3, 8, 1, 9, 2, 1, 6, 8, 3, 8, 6, 2, 7, 10, 7, 3, 9, 8, 1, 4], [8, 9, 2], [7, 8, 1, 2], [3, 8, 4, 3, 2], [1, 4, 8, 9, 6, 9], [6, 10, 3, 2, 7, 7, 1], [3, 8, 7, 9, 10, 3, 2, 2], [5, 3, 2, 3, 10, 2, 8, 6, 2], [2, 8, 8, 9, 6, 10, 10, 5, 4, 6, 1], [7, 2, 4, 3, 4, 6, 10, 7, 3, 1, 5, 2], [6, 9, 7, 5, 10, 6, 4, 1, 2, 1, 5, 8, 4, 4, 2], [8, 1, 1, 3, 10, 2, 10, 4, 8, 3, 5, 10, 7, 6, 1, 3, 9, 4, 10, 8], [8, 4, 1, 9, 8, 10, 9, 10, 5, 3, 1, 5, 9, 9, 2, 10, 6, 8, 10, 3, 9, 6, 9, 10, 10], [5, 9, 8, 2, 5, 7, 4, 4, 2, 6, 10, 4, 2, 8, 8, 9, 9, 7, 9, 5, 1, 6, 5, 1, 9, 6, 7, 4, 10, 9], [9, 5, 10, 4, 8, 5, 4, 3, 9, 9, 7, 7, 4, 9, 10, 8, 7, 2, 1, 8, 3, 8, 10, 4, 10, 4, 1, 5, 7, 7, 3, 9, 8, 8, 8, 5, 8, 10, 1, 7], [7, 8, 1, 2, 1, 2, 5, 9, 2, 10, 6, 9, 7, 2, 9, 5, 6, 10, 6, 6, 1, 10, 3, 1, 3, 1, 9, 2, 5, 5, 3, 7, 9, 1, 1, 5, 3, 3, 6, 1, 4, 9, 3, 1, 10, 2, 2, 10, 5, 10, 10, 2, 7, 4, 9, 5, 7, 6, 1, 3], [7, 2, 6, 10, 2, 6, 1, 2, 1, 2, 6, 10, 8, 4, 6, 2, 8, 5, 9, 2, 7, 3, 4, 6, 4, 3, 5, 3, 1, 5, 1, 7, 5, 2, 10, 7, 8, 10, 3, 10, 10, 8, 4, 6, 8, 3, 1, 7, 9, 5, 7, 10, 7, 9, 10, 6, 9, 6, 1, 2, 4, 2, 2, 10, 3, 7, 5, 9, 8, 5, 10, 3, 8, 4, 5], [8, 8, 3, 9, 4, 7, 4, 1, 10, 9, 9, 8, 5, 4, 10, 5, 5, 4, 7, 1, 9, 2, 2, 4, 9, 9, 5, 7, 5, 4, 8, 8, 8, 3, 3, 7, 8, 5, 4, 6, 8, 1, 7, 7, 4, 2, 3, 4, 6, 3, 4, 8, 2, 10, 3, 5, 10, 10, 1, 9, 10, 3, 8, 4, 7, 8, 2, 5, 2, 6, 4, 5, 8, 1, 10, 7, 5, 6, 1, 8, 10, 1, 7, 2, 3, 6, 7, 1, 1, 3, 10, 2, 8, 1, 5, 9, 10, 10, 6, 7], [9, 10, 9, 9, 7, 3, 2, 7, 6, 1, 5, 8, 4, 4, 3, 10, 3, 5, 8, 2, 8, 9, 5, 9, 6, 3, 2, 4, 1, 6, 9, 4, 4, 7, 9, 3, 1, 1, 2, 6, 6, 4, 10, 10, 5, 5, 1, 10, 3, 10, 5, 1, 10, 3, 6, 10, 9, 2, 5, 4, 7, 2, 7, 8, 9, 4, 3, 1, 7, 6, 1, 10, 8, 2, 7, 1, 5, 5, 3, 4, 8, 3, 5, 7, 6, 6, 1, 1, 9, 6, 9, 5, 5, 4, 7, 4, 1, 2, 6, 9, 9, 5, 1, 6, 1, 5, 4, 10, 5, 10, 5, 3, 2, 1, 5, 4, 9, 9, 8, 9, 2, 8, 6, 6, 7, 5, 2, 10, 2, 7, 1, 10, 9, 7, 6, 4, 10, 10, 5, 6, 10, 5, 5, 4, 4, 6, 2, 7, 4, 9], [6, 5, 7, 3, 2, 5, 1, 10, 8, 2, 2, 4, 8, 6, 6, 10, 2, 10, 4, 1, 9, 3, 8, 7, 10, 3, 6, 10, 1, 10, 9, 6, 3, 10, 3, 3, 2, 4, 6, 7, 4, 8, 3, 9, 4, 1, 6, 10, 2, 6, 2, 3, 7, 10, 4, 2, 3, 9, 4, 1, 6, 2, 7, 1, 5, 9, 1, 8, 10, 9, 6, 4, 10, 10, 9, 3, 5, 2, 7, 5, 9, 8, 5, 10, 5, 10, 10, 2, 3, 5, 9, 1, 6, 2, 2, 5, 9, 7, 9, 4, 5, 10, 3, 9, 3, 6, 9, 6, 2, 1, 9, 8, 2, 1, 3, 1, 7, 5, 9, 3, 2, 1, 3, 7, 8, 10, 5, 3, 3, 5, 3, 8, 3, 4, 6, 2, 8, 10, 5, 10, 5, 1, 9, 6, 2, 3, 10, 10, 7, 7, 10, 4, 8, 5, 10, 6, 6, 5, 4, 3, 10, 10, 7, 5, 9, 1, 10, 4, 1, 5, 9, 9, 9, 5, 10, 1, 10, 9, 9, 10, 4, 7, 6, 7, 6, 10, 10, 4, 4, 8, 6, 5, 9, 2, 9, 9, 1, 2, 10, 7, 2, 10, 6, 9, 5, 6, 3, 3, 5, 6, 4, 5, 4, 5, 10, 8, 2, 1, 10, 1, 9, 3, 10, 5, 5, 6, 3, 3, 3, 10, 10, 2, 6, 2, 1, 7, 8, 1, 5, 8, 3, 3, 2, 9, 2, 10, 7, 5, 6, 4, 7, 7, 8, 7, 5, 5, 4, 7, 2, 5, 1, 8, 10, 4, 4, 4, 9, 3, 9, 3, 5, 4, 1, 9, 7, 3, 7, 7, 7, 4, 8, 9, 1, 9, 7, 6, 5, 8, 10, 8, 5, 10, 2, 1, 6, 5, 3, 4, 1, 7], [2, 8, 7, 1, 3, 3, 2, 4, 2, 5, 1, 10, 5, 9, 5, 2, 2, 3, 6, 4, 2, 3, 2, 4, 6, 2, 2, 2, 5, 2, 4, 9, 9, 3, 10, 8, 6, 6, 2, 5, 5, 8, 10, 4, 4, 9, 1, 7, 9, 8, 4, 4, 2, 3, 1, 6, 4, 3, 6, 8, 6, 6, 3, 2, 4, 10, 3, 2, 3, 5, 9, 7, 1, 1, 7, 1, 1, 1, 2, 2, 2, 8, 4, 5, 7, 1, 10, 7, 8, 2, 7, 1, 4, 5, 9, 5, 5, 5, 7, 1, 7, 7, 10, 2, 8, 10, 9, 8, 6, 10, 8, 10, 7, 7, 3, 2, 3, 2, 8, 10, 5, 7, 6, 9, 3, 7, 8, 1, 4, 2, 8, 10, 7, 3, 9, 3, 2, 3, 10, 5, 10, 4, 9, 6, 4, 9, 3, 6, 1, 1, 4, 10, 3, 8, 7, 5, 10, 2, 9, 4, 6, 1, 9, 4, 1, 9, 10, 9, 5, 7, 8, 6, 8, 2, 7, 1, 3, 4, 3, 1, 9, 6, 5, 5, 6, 9, 1, 3, 4, 8, 7, 7, 9, 4, 9, 5, 2, 8, 7, 6, 6, 8, 9, 1, 2, 2, 5, 7, 8, 3, 5, 5, 7, 2, 1, 6, 2, 8, 7, 7, 9, 7, 10, 2, 5, 5, 5, 4, 1, 6, 10, 2, 10, 8, 3, 1, 5, 10, 1, 6, 1, 1, 9, 6, 7, 6, 5, 8, 4, 2, 4, 10, 2, 5, 3, 7, 8, 3, 9, 2, 1, 8, 4, 10, 1, 4, 8, 1, 3, 3, 1, 10, 1, 3, 2, 2, 1, 4, 4, 3, 7, 1, 9, 7, 10, 3, 8, 9, 3, 1, 10, 4, 8, 10, 4, 8, 10, 1, 5, 3, 4, 2, 4, 6, 8, 6, 10, 2, 6, 10, 8, 10, 2, 7, 10, 4, 6, 8, 2, 6, 8, 7, 3, 10, 5, 8, 6, 10, 9, 6, 2, 10, 5, 5, 1, 4, 1, 1, 8, 2, 2, 10, 9, 8, 9, 2, 6, 5, 10, 3, 7, 3, 5, 7, 2, 9, 3, 6, 5, 5, 5, 6, 1, 4, 8, 5, 8, 4, 7, 10, 3, 8, 3, 9, 8, 9, 10, 6, 2, 7, 3, 5, 9, 3, 2, 6, 10, 1, 9, 6, 7, 4, 10, 2, 2, 10, 2, 7, 7, 9, 9, 5, 6, 7, 3, 8, 1, 3, 3, 6, 6, 6, 10, 5, 1, 2, 3, 9, 1, 4, 6, 2, 3, 8, 5, 1, 10, 8, 6, 1, 4, 2, 3, 3, 5, 10, 9, 4, 7, 6, 10, 5, 8, 10, 8, 5, 2, 9, 6, 6, 6, 6, 7, 2, 3, 4, 8, 2, 8, 6, 5, 4, 9, 5, 1, 5, 2, 9, 6, 10, 10, 7, 7, 7, 7, 9, 9, 1, 7, 7, 3, 1, 1, 1, 4, 2, 10, 6, 8, 10, 4, 10, 7, 8, 2, 7, 10, 1, 3, 5], [6, 7, 6, 6, 10, 3, 7, 9, 10, 8, 6, 7, 10, 7, 8, 1, 2, 8, 8, 4, 1, 5, 9, 5, 2, 7, 2, 3, 6, 2, 8, 8, 3, 10, 10, 5, 8, 2, 2, 6, 3, 1, 10, 4, 4, 4, 6, 2, 4, 4, 4, 1, 4, 3, 1, 7, 7, 5, 7, 9, 2, 10, 2, 9, 2, 5, 3, 5, 7, 7, 4, 4, 2, 5, 8, 1, 6, 7, 8, 4, 2, 1, 5, 4, 8, 8, 1, 3, 9, 8, 9, 10, 1, 10, 4, 8, 10, 10, 3, 3, 4, 8, 6, 8, 2, 7, 2, 9, 5, 7, 7, 1, 2, 6, 4, 6, 7, 9, 10, 7, 5, 7, 5, 7, 3, 10, 2, 3, 9, 3, 5, 5, 4, 2, 7, 2, 3, 5, 1, 5, 2, 1, 2, 3, 10, 7, 10, 6, 3, 5, 10, 2, 3, 9, 6, 6, 1, 7, 8, 6, 7, 2, 1, 3, 1, 4, 3, 1, 7, 1, 1, 10, 5, 2, 10, 7, 5, 6, 10, 4, 7, 5, 7, 7, 4, 7, 7, 5, 1, 4, 1, 8, 6, 1, 5, 9, 7, 2, 9, 7, 5, 2, 6, 5, 5, 4, 8, 9, 4, 3, 4, 1, 1, 2, 6, 8, 2, 1, 5, 5, 4, 6, 6, 3, 7, 7, 4, 6, 7, 8, 10, 2, 2, 1, 2, 5, 5, 1, 5, 2, 4, 9, 2, 9, 7, 1, 5, 1, 4, 10, 1, 6, 3, 1, 6, 5, 3, 8, 8, 6, 1, 2, 3, 5, 8, 2, 5, 9, 6, 4, 6, 2, 10, 4, 5, 6, 9, 6, 8, 6, 9, 3, 3, 6, 7, 9, 6, 9, 1, 2, 3, 6, 6, 1, 7, 3, 4, 5, 1, 1, 3, 6, 8, 4, 2, 1, 10, 9, 6, 1, 6, 7, 7, 3, 10, 1, 1, 7, 10, 1, 2, 7, 6, 8, 5, 6, 3, 7, 8, 8, 7, 10, 4, 1, 6, 7, 5, 6, 5, 9, 3, 8, 6, 8, 1, 3, 8, 5, 3, 6, 10, 3, 10, 7, 7, 10, 10, 10, 5, 7, 7, 10, 9, 3, 7, 2, 8, 4, 6, 10, 6, 6, 7, 1, 8, 10, 6, 7, 9, 5, 1, 4, 7, 9, 8, 7, 4, 2, 2, 10, 1, 6, 8, 6, 3, 5, 1, 7, 6, 4, 2, 4, 4, 2, 5, 9, 8, 6, 9, 10, 9, 9, 6, 3, 3, 6, 10, 4, 3, 8, 2, 4, 3, 3, 1, 1, 1, 4, 9, 6, 6, 10, 6, 6, 9, 7, 1, 2, 2, 5, 2, 4, 5, 1, 2, 8, 2, 9, 4, 9, 3, 3, 10, 1, 9, 9, 4, 4, 6, 4, 5, 6, 6, 5, 8, 4, 4, 7, 6, 7, 1, 10, 3, 6, 10, 3, 8, 3, 9, 6, 9, 3, 6, 4, 2, 4, 4, 3, 10, 3, 10, 9, 7, 7, 5, 6, 1, 1, 2, 10, 2, 3, 4, 9, 3, 6, 6, 3, 10, 6, 1, 4, 2, 2, 3, 1, 2, 8, 6, 10, 5, 7, 7, 2, 8, 8, 4, 6, 8, 1, 8, 5, 7, 7, 2, 6, 6, 4, 4, 10, 9, 4, 9, 8, 2, 3, 9, 5, 10, 10, 9, 3, 10, 8, 8, 7, 7, 4, 6, 9, 7, 8, 8, 4, 6, 5, 1, 4, 4, 3, 1, 1, 9, 7, 2, 10, 7, 4, 3, 8, 7, 6, 5, 5, 6, 3, 2, 6, 1, 9, 2, 5, 1, 4, 8, 2, 5, 8, 9, 8, 7, 6, 4, 7, 1, 6, 1, 10, 2, 6, 4, 8, 5, 5, 7, 2, 7, 3, 10, 1, 2, 4, 10, 10, 5, 4, 4, 4, 6, 3, 4, 5, 2, 6, 5, 2, 5, 9, 2, 5, 4, 4, 2, 1, 7, 5, 9, 4, 10, 4, 2, 3, 5, 8, 3, 6, 10, 6, 5, 3, 4, 6, 1, 1, 10, 9, 5, 1, 9, 7, 9, 8, 7, 4, 6, 10, 4, 9, 6, 2, 10, 4, 6, 9, 7, 4, 4, 3, 4, 2, 6, 10, 5, 7, 10, 5, 3, 2, 6, 3, 3, 6, 6, 9, 3, 4, 8, 4, 5, 2, 9, 8, 8, 4, 6, 2, 8, 8, 10, 4, 4, 3, 3, 7, 10, 2, 5, 2, 6, 10, 9, 4, 3, 6, 5, 6, 2, 9, 7, 6, 9, 6, 9, 5, 10, 10, 2, 4, 3, 6, 2, 8, 9, 3, 9, 10, 3, 2, 8, 5, 6, 2, 5, 2, 3, 1, 4, 8, 7, 5, 6, 5, 1, 2, 7, 6, 8, 4, 5, 1, 10, 2, 5, 10, 1, 7, 10, 1, 10, 4, 2, 4, 6, 3, 4, 4, 7, 7, 10, 4, 6, 4, 1, 1, 9, 10, 3, 7, 8, 9, 1, 10, 1, 1, 10, 5, 2, 9, 9, 7, 7, 10, 4, 9, 3, 10, 10, 2, 3, 3, 8, 10, 6, 4, 5, 5, 4, 10, 6, 8, 6, 2, 9, 1, 6, 3, 10, 9, 7, 8, 2, 5, 9, 8, 10, 4, 1, 10, 9, 5, 9, 3, 3, 8, 1, 5, 3, 10, 3, 6, 2, 3, 10, 2, 4, 2, 6, 4, 7, 10, 6, 1, 2, 7, 4, 7, 5, 7, 8, 7, 7, 4, 2, 10, 9, 6, 6, 1, 7, 10, 8, 1, 2, 4, 3, 10, 8, 6, 4, 10, 8, 2, 3, 3, 2, 10, 3, 2, 10, 8, 6, 3, 10, 7, 1, 4, 9, 5, 8, 8, 4, 6, 4, 8, 5, 1, 4, 4, 7, 1, 9, 3, 10, 8, 6, 4, 7, 8, 7, 5, 3, 5, 2, 4, 5, 9, 3, 4, 6, 8, 1, 3, 5, 6, 9, 2, 10, 5, 7, 5, 6, 4, 8, 9, 3, 5, 8, 8, 7, 6, 5, 10, 6, 10, 5, 8, 3, 3, 6, 3, 1, 3, 1, 1, 4, 5, 2, 8, 4, 6], [1, 8, 4, 8, 8, 2, 4, 3, 9, 8, 6, 4, 2], [4, 9, 7, 3, 6, 9, 4, 10, 10, 4, 7, 3, 6, 8, 7, 1, 7], [2, 4, 7, 3, 2, 9, 9, 6, 7, 1, 4, 4, 9, 8, 9, 9, 9, 4, 7, 2, 8, 10], [9, 7, 3, 2, 1, 3, 5, 3, 2, 2, 3, 4, 9, 1, 1, 3, 10, 5, 6, 3, 9, 5, 8, 10, 4, 10, 8, 6, 8, 7, 9, 5, 4]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "177", "slug": "implement-stack-using-queues", "id": 177, "title": "Implement Stack using Queues", "difficulty": "Easy", "category": "stack", "link": "https://leetcode.com/problems/implement-stack-using-queues/", "examples": [{"input": "operations = [\"push\",\"push\",\"top\",\"pop\",\"empty\"], values = [1,2,0,0,0]", "output": "[2,2,0]", "explanation": "Push 1 then push 2. Top returns 2, pop removes and returns 2, then empty returns false (encoded as 0)."}, {"input": "operations = [\"push\",\"top\",\"pop\",\"empty\"], values = [1,0,0,0]", "output": "[1,1,1]", "explanation": "Push 1. Top returns 1, pop returns 1, then the stack is empty so empty returns true (encoded as 1)."}, {"input": "operations = [\"push\",\"push\",\"push\",\"pop\",\"pop\",\"top\",\"empty\"], values = [1,2,3,0,0,0,0]", "output": "[3,2,1,0]", "explanation": "Push 1, 2, 3. Pop returns 3, pop returns 2, top returns 1, and empty returns false (0) because 1 remains."}], "hints": ["Simulate a stack with two queues: on push, move all elements so the newest element is always at the front.", "Pop and top read from the front of the primary queue; empty checks whether it has no elements. Encode empty as 1 for true and 0 for false."], "statement": "Implement a last-in-first-out (LIFO) stack using only standard queue operations.\n\n`operations[i]` is one of `push`, `pop`, `top`, or `empty`. The aligned value\n`values[i]` is used only by `push`; it is ignored for every other operation.\nReturn an array containing the result of each `pop`, `top`, and `empty`\noperation, in the order those queries occur. `push` does not add anything to\nthe returned array. Encode `empty` as `1` for true and `0` for false.\n\nEvery trace is valid: `pop` and `top` are never called on an empty stack.\n\n**Constraints:**\n\n- `1 <= operations.length == values.length <= 100`\n- `operations[i]` is `push`, `pop`, `top`, or `empty`.\n- `1 <= values[i] <= 9` when `operations[i]` is `push`.\n- At most 100 calls are made in one trace.\n", "solution": "## Approach\n\nSimulate a LIFO stack with two FIFO queues. Keep all elements in `q1` with the\nmost recently pushed element at the front. To push `x`, offer `x` to the empty\n`q2`, drain every element of `q1` into `q2`, then swap the two queues. `pop`\npolls the front, `top` peeks at the front, and `empty` checks whether `q1` is\nempty (encoded as `1`/`0`). Collect outputs only for `pop`, `top`, and\n`empty`.\n\n## Complexity Analysis\n\n- **Time Complexity:** `O(m)` amortized per trace with `O(n)` work for each `push` where `n` is the current size, `O(1)` for `pop`/`top`/`empty`.\n- **Space Complexity:** `O(m)` for the two queues in the worst case.\n\n## Implementation\n\n```python\nfrom collections import deque\nfrom typing import List\n\n\nclass Solution:\n def runStackUsingQueues(self, operations: List[str], values: List[int]) -> List[int]:\n q1: deque[int] = deque()\n q2: deque[int] = deque()\n answers: List[int] = []\n for operation, value in zip(operations, values):\n if operation == \"push\":\n q2.append(value)\n while q1:\n q2.append(q1.popleft())\n q1, q2 = q2, q1\n elif operation == \"pop\":\n answers.append(q1.popleft())\n elif operation == \"top\":\n answers.append(q1[0])\n else:\n answers.append(1 if not q1 else 0)\n return answers\n```\n", "starter": {"go": "package main\n\nfunc RunStackUsingQueues(operations []string, values []int) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runStackUsingQueues(self, operations: List[str], values: List[int]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runStackUsingQueues(vector<string>& operations, vector<int>& values) {\n return {};\n }\n};"}, "fn": "runStackUsingQueues", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array"}], "outputType": "int_array", "tests": [["[\"push\",\"push\",\"top\",\"pop\",\"empty\"]", "[1,2,0,0,0]"], ["[\"push\",\"top\",\"pop\",\"empty\"]", "[1,0,0,0]"], ["[\"push\",\"push\",\"push\",\"pop\",\"pop\",\"top\",\"empty\"]", "[1,2,3,0,0,0,0]"], ["[\"push\",\"empty\",\"top\",\"pop\",\"empty\"]", "[5,0,0,0,0]"], ["[\"push\",\"pop\",\"empty\"]", "[9,0,0]"], ["[\"push\",\"push\",\"pop\",\"top\",\"pop\",\"empty\"]", "[3,7,0,0,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"top\",\"pop\",\"top\",\"pop\",\"empty\"]", "[1,2,3,4,0,0,0,0,0]"], ["[\"push\",\"push\",\"empty\",\"pop\",\"empty\",\"push\",\"top\",\"empty\"]", "[4,5,0,0,0,6,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\",\"pop\",\"pop\",\"empty\"]", "[9,8,7,6,5,0,0,0,0,0,0]"], ["[\"push\",\"top\",\"top\",\"pop\",\"empty\",\"push\",\"top\",\"empty\"]", "[2,0,0,0,0,8,0,0]"], ["[\"push\",\"push\",\"pop\",\"push\",\"pop\",\"pop\",\"empty\"]", "[1,9,0,2,0,0,0]"], ["[\"push\",\"push\",\"push\",\"top\",\"top\",\"pop\",\"empty\",\"pop\",\"top\",\"empty\"]", "[5,1,9,0,0,0,0,0,0,0]"], ["@javascript:JSON.stringify(Array(50).fill('push').flatMap((_,i)=>i%5===4?['push','top','pop']:['push']))", "@javascript:JSON.stringify(Array.from({length:50},(_,i)=>(i%9)+1).flatMap((v,i)=>i%5===4?[v,0,0]:[v]))"], ["@javascript:JSON.stringify([...Array(60).fill('push'),...Array(30).fill('pop'),'top','empty'])", "@javascript:JSON.stringify([...Array.from({length:60},(_,i)=>(i%9)+1),...Array(32).fill(0)])"], ["[\"push\",\"push\",\"push\",\"pop\",\"pop\",\"pop\",\"empty\"]", "[1,2,3,0,0,0,0]"], ["[\"push\",\"empty\",\"empty\",\"pop\",\"empty\"]", "[7,0,0,0,0]"], ["[\"push\",\"push\",\"top\",\"top\",\"pop\",\"top\",\"empty\"]", "[4,6,0,0,0,0,0]"], ["[\"push\",\"pop\",\"push\",\"pop\",\"empty\"]", "[3,0,5,0,0]"], ["[\"push\",\"push\",\"pop\",\"push\",\"top\",\"pop\",\"pop\",\"empty\"]", "[8,1,0,9,0,0,0,0]"], ["[\"empty\",\"push\",\"top\",\"empty\"]", "[0,2,0,0]"], ["[\"push\",\"push\",\"push\",\"empty\",\"top\",\"pop\",\"empty\"]", "[2,4,6,0,0,0,0]"], ["[\"push\",\"top\",\"push\",\"top\",\"pop\",\"pop\",\"empty\"]", "[1,0,2,0,0,0,0]"], ["[\"push\",\"push\",\"pop\",\"pop\",\"push\",\"top\",\"empty\"]", "[5,5,0,0,5,0,0]"], ["[\"push\",\"push\",\"push\",\"push\",\"pop\",\"empty\",\"pop\",\"top\",\"empty\"]", "[3,3,3,3,0,0,0,0,0]"], ["[\"push\",\"empty\",\"push\",\"empty\",\"pop\",\"top\",\"empty\"]", "[1,0,2,0,0,0,0]"], ["[\"push\",\"pop\",\"push\",\"top\",\"pop\",\"empty\",\"push\",\"empty\"]", "[6,0,4,0,0,0,7,0]"], ["[\"push\",\"push\",\"top\",\"pop\",\"push\",\"top\",\"pop\",\"pop\",\"empty\"]", "[9,1,0,0,2,0,0,0,0]"], ["[\"push\",\"push\",\"push\",\"pop\",\"push\",\"pop\",\"pop\",\"pop\",\"empty\"]", "[4,4,4,0,4,0,0,0,0]"], ["[\"empty\",\"empty\",\"push\",\"pop\",\"empty\"]", "[0,0,9,0,0]"], ["[\"push\",\"top\",\"empty\",\"pop\",\"empty\"]", "[8,0,0,0,0]"], ["[\"push\",\"push\",\"empty\",\"top\",\"pop\",\"push\",\"empty\"]", "[7,3,0,0,0,8,0]"], ["[\"push\",\"push\",\"pop\",\"empty\",\"push\",\"pop\",\"top\",\"empty\"]", "[2,8,0,0,5,0,0,0]"]], "expected": [[2, 2, 0], [1, 1, 1], [3, 2, 1, 0], [0, 5, 5, 1], [9, 1], [7, 3, 3, 1], [4, 4, 3, 3, 0], [0, 5, 0, 6, 0], [5, 6, 7, 8, 9, 1], [2, 2, 2, 1, 8, 0], [9, 2, 1, 1], [9, 9, 9, 0, 1, 5, 0], [5, 5, 1, 1, 6, 6, 2, 2, 7, 7, 3, 3, 8, 8, 4, 4, 9, 9, 5, 5], [6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8, 7, 6, 5, 4, 3, 0], [3, 2, 1, 1], [0, 0, 7, 1], [6, 6, 6, 4, 0], [3, 5, 1], [1, 9, 9, 8, 1], [1, 2, 0], [0, 6, 6, 0], [1, 2, 2, 1, 1], [5, 5, 5, 0], [3, 0, 3, 3, 0], [0, 0, 2, 1, 0], [6, 4, 4, 1, 0], [1, 1, 2, 2, 9, 1], [4, 4, 4, 4, 1], [1, 1, 9, 1], [8, 0, 8, 1], [0, 3, 3, 0], [8, 0, 5, 2, 0]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "65", "slug": "implement-trie-prefix-tree", "id": 65, "title": "Implement Trie (Prefix Tree)", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/implement-trie-prefix-tree/", "examples": [{"input": "operations = [\"Trie\",\"insert\",\"search\",\"search\",\"startsWith\",\"insert\",\"search\"]\nvalues = [\"\",\"apple\",\"apple\",\"app\",\"app\",\"app\",\"app\"]", "output": "[null,null,true,false,true,null,true]", "explanation": "After inserting 'apple', searching 'apple' returns true, searching 'app' returns false, startsWith('app') returns true. After inserting 'app', searching 'app' returns true."}, {"input": "operations = [\"Trie\",\"insert\",\"search\",\"startsWith\"]\nvalues = [\"\",\"hello\",\"hello\",\"hell\"]", "output": "[null,null,true,true]", "explanation": "After inserting 'hello', both search('hello') and startsWith('hell') return true."}], "hints": ["A Trie (prefix tree) is a tree data structure used for efficient retrieval of keys in a dataset of strings.", "Each node contains an array of child pointers (one for each character) and a boolean flag indicating whether the node marks the end of a word.", "For insert: traverse character by character, creating nodes as needed, and mark the final node as end of word.", "For search: traverse character by character; if a character is missing, return false; check the end-of-word flag at the final node.", "For startsWith: same as search but return true if the path exists, regardless of the end-of-word flag."], "statement": "A prefix tree, spoken like \"try\" and often called a trie, organizes a collection of strings so that entries sharing a beginning share structure. Typical uses include predictive text and spelling assistance.\n\nBuild a class named `Trie` supporting:\n\n- `Trie()` Creates a fresh empty structure.\n- `void insert(String word)` Adds the string `word` to the stored collection.\n- `boolean search(String word)` Reports `true` when `word` was added earlier as a complete entry, and `false` otherwise.\n- `boolean startsWith(String prefix)` Reports `true` when some previously added `word` begins with `prefix`, and `false` otherwise.\n\n**Constraints:**\n\n- `1 <= word.length, prefix.length <= 2000`\n- Both `word` and `prefix` use only lowercase English letters.\n- No more than `3 * 10^4` invocations of `insert`, `search`, and `startsWith` occur in total.\n", "solution": "## Approach\n\nA trie (prefix tree) where each node holds a map of child characters and a boolean end-of-word flag. Insert traverses character by character, creating nodes as needed. Search and startsWith traverse similarly, checking existence.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) per operation, where n is the word length.\n- **Space Complexity:** O(total number of characters inserted across all words).\n\n## Implementation\n\n```python\nfrom typing import List\nclass Trie:\n def __init__(self):\n self.children = {}\n self.is_end = False\n def insert(self, word: str) -> None:\n node = self\n for c in word:\n if c not in node.children:\n node.children[c] = Trie()\n node = node.children[c]\n node.is_end = True\n def search(self, word: str) -> bool:\n node = self\n for c in word:\n if c not in node.children:\n return False\n node = node.children[c]\n return node.is_end\n def startsWith(self, prefix: str) -> bool:\n node = self\n for c in prefix:\n if c not in node.children:\n return False\n node = node.children[c]\n return True\nclass Solution:\n def solve(self, operations: List[str], values: List[str]) -> List[str]:\n result = []\n obj = None\n for i, op in enumerate(operations):\n if op == \"Trie\":\n obj = Trie()\n result.append(\"null\")\n elif op == \"insert\":\n obj.insert(values[i])\n result.append(\"null\")\n elif op == \"search\":\n result.append(str(obj.search(values[i])).lower())\n elif op == \"startsWith\":\n result.append(str(obj.startsWith(values[i])).lower())\n return result\n```\n", "starter": {"go": "package main\n\ntype Trie struct {\n \n}\n\nfunc Constructor() Trie {\n return Trie{}\n}\n\nfunc (this *Trie) Insert(word string) {\n \n}\n\nfunc (this *Trie) Search(word string) bool {\n return false\n}\n\nfunc (this *Trie) StartsWith(prefix string) bool {\n return false\n}", "python": "class Trie:\n def __init__(self):\n \n def insert(self, word: str) -> None:\n \n def search(self, word: str) -> bool:\n return False\n def startsWith(self, prefix: str) -> bool:\n return False", "cpp": "#include <string>\nusing namespace std;\n\nclass Trie {\npublic:\n Trie() {\n \n }\n \n void insert(string word) {\n \n }\n \n bool search(string word) {\n return false;\n }\n \n bool startsWith(string prefix) {\n return false;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "string_array"}], "outputType": "string_list", "tests": [["[\"Trie\",\"insert\",\"search\",\"search\",\"startsWith\",\"insert\",\"search\"]", "[\"\",\"apple\",\"apple\",\"app\",\"app\",\"app\",\"app\"]"], ["[\"Trie\",\"insert\",\"search\",\"startsWith\"]", "[\"\",\"hello\",\"hello\",\"hell\"]"], ["[\"Trie\",\"insert\",\"search\",\"search\",\"startsWith\",\"startsWith\"]", "[\"\",\"abc\",\"abc\",\"ab\",\"a\",\"abc\"]"], ["[\"Trie\",\"search\",\"startsWith\",\"insert\",\"search\"]", "[\"\",\"key\",\"ke\",\"key\",\"key\"]"], ["[\"Trie\",\"insert\",\"search\",\"search\",\"search\",\"startsWith\"]", "[\"\",\"a\",\"a\",\"aa\",\"aaa\",\"a\"]"], ["[\"Trie\",\"insert\",\"insert\",\"insert\",\"search\",\"search\",\"search\",\"startsWith\",\"startsWith\",\"startsWith\"]", "[\"\",\"cat\",\"car\",\"card\",\"cat\",\"car\",\"card\",\"ca\",\"car\",\"dog\"]"], ["[\"Trie\",\"insert\",\"startsWith\",\"startsWith\"]", "[\"\",\"leet\",\"lee\",\"leetc\"]"], ["[\"Trie\",\"insert\",\"insert\",\"search\",\"search\",\"startsWith\"]", "[\"\",\"code\",\"cojudge\",\"code\",\"cojudge\",\"coj\"]"], ["[\"Trie\",\"insert\",\"search\"]", "[\"\",\"zebra\",\"zebra\"]"], ["[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"dog\", \"dog\", \"do\", \"do\", \"doggy\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"a\", \"ab\", \"abc\", \"a\", \"ab\", \"abc\", \"ab\", \"abcd\"]"], ["[\"Trie\", \"search\", \"startsWith\", \"insert\", \"search\"]", "[\"\", \"nothing\", \"pre\", \"pre\", \"pre\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"banana\", \"band\", \"bandana\", \"band\", \"banda\", \"band\", \"banana\"]"], ["[\"Trie\", \"insert\", \"insert\", \"search\", \"startsWith\"]", "[\"\", \"test\", \"test\", \"test\", \"tes\"]"], ["[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\", \"startsWith\"]", "[\"\", \"xyz\", \"xy\", \"xyz\", \"x\", \"xyz\", \"xyzz\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"up\", \"down\", \"left\", \"right\", \"up\", \"down\", \"l\", \"r\"]"], ["[\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"algorithm\", \"algo\", \"algorithm\", \"algo\", \"algo\", \"algorithmx\"]"], ["[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"m\", \"m\", \"n\", \"m\", \"n\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"s\", \"str\", \"string\", \"st\", \"str\", \"stri\", \"stringy\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"foo\", \"bar\", \"baz\", \"foo\", \"ba\", \"ba\", \"baz\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\"]", "[\"\", \"trie\", \"tried\", \"tries\", \"trie\", \"tried\", \"tri\"]"], ["[\"Trie\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"aaabbb\", \"aaabbb\", \"aaab\", \"aaa\", \"bbb\"]"], ["[\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"qwerty\", \"qwert\", \"qwerty\", \"qwert\", \"qwer\", \"qwertyuiop\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"data\", \"database\", \"datum\", \"data\", \"dat\", \"dat\", \"data\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\", \"startsWith\"]", "[\"\", \"sun\", \"moon\", \"star\", \"sun\", \"moo\", \"s\", \"mo\", \"star\"]"], ["[\"Trie\", \"insert\", \"search\", \"startsWith\", \"search\"]", "[\"\", \"supercalifragilistic\", \"supercalifragilistic\", \"super\", \"supercali\"]"], ["[\"Trie\", \"insert\", \"search\", \"startsWith\", \"search\", \"startsWith\"]", "[\"\", \"abcdef\", \"abc\", \"abc\", \"abcdef\", \"abcdefg\"]"], ["[\"Trie\", \"insert\", \"insert\", \"search\", \"startsWith\", \"search\"]", "[\"\", \"applepie\", \"applet\", \"apple\", \"apple\", \"applepie\"]"], ["[\"Trie\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"go\", \"golang\", \"go\", \"golan\", \"gol\", \"golangx\"]"], ["[\"Trie\", \"insert\", \"insert\", \"insert\", \"search\", \"search\", \"startsWith\", \"startsWith\"]", "[\"\", \"alpha\", \"beta\", \"gamma\", \"alpha\", \"alph\", \"gam\", \"bet\"]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "887", "slug": "increasing-order-search-tree", "id": 887, "title": "Increasing Order Search Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/increasing-order-search-tree/", "examples": [{"input": "root = [5,3,6,2,4,null,8,1,null,null,null,7,9]", "output": "[1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]", "explanation": "Sorted values 1..9 relinked right-only."}, {"input": "root = [5,1,7]", "output": "[1,null,5,null,7]", "explanation": "Chain of [1,5,7]."}, {"input": "root = [1]", "output": "[1]", "explanation": "Single node unchanged."}], "hints": ["Collect values with an in-order walk, which visits a search tree in sorted order.", "Then create fresh nodes in that order, linking each as the right child of the previous one with no left children."], "statement": "Start from the root of a binary search tree. Gather its values from smallest to largest and rebuild them as a spine that leans only to the right: the tiniest value becomes the new root, each node keeps an empty left hand and points rightward to the next larger value.\n\nReturn the head of that right-leaning chain.\n\n**Constraints:**\n- `1 <= nodes in tree <= 100`\n- `0 <= Node.val <= 1000`\n", "solution": "## Approach\n\nAn in-order traversal of a search tree yields its keys from smallest to largest. Storing that order and then stitching brand-new nodes together so each node has only a right link produces exactly the requested spine. Building fresh nodes keeps the original tree untouched for the checker.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) to visit each node once and O(n) to relink.\n- **Space Complexity:** O(n) for the value list and the new chain (plus recursion depth).\n\n## Implementation\n\n```python\nclass Solution:\n def increasingBST(self, root):\n vals = []\n def dfs(nd):\n if not nd:\n return\n dfs(nd.left)\n vals.append(nd.val)\n dfs(nd.right)\n dfs(root)\n dummy = TreeNode(0)\n cur = dummy\n for v in vals:\n cur.right = TreeNode(v)\n cur = cur.right\n return dummy.right\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc IncreasingBST(root *TreeNode) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def increasingBST(self, root):\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* increasingBST(TreeNode* root) {\n \n }\n};"}, "fn": "increasingBST", "params": [{"name": "root", "type": "tree_node"}], "outputType": "tree_node", "tests": [["[5,3,6,2,4,null,8,1,null,null,null,7,9]"], ["[5,1,7]"], ["[1]"], ["[2,1,3]"], ["[3,2,4,1]"], ["[10,5,15,3,7,12,20]"], ["[1,null,2]"], ["[2,null,3]"], ["[4,2,6,1,3,5,7]"], ["[5,3,8,1,4,7,9]"], ["[1,null,2,null,3]"], ["[3,null,4,null,5]"], ["[7,3,10,1,5,null,12]"], ["[2,1]"], ["[1,0]"], ["[0]"], ["[1000]"], ["[50,30,70,20,40,60,80]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[5,4,null,3,null,2,null,1]"], ["[1,null,3,2]"], ["[6,2,8,0,4,7,9,null,null,3,5]"], ["[10,1,20]"], ["[15,10,20,8,12,17,25]"], ["[3,1,4,null,2]"], ["[9,5,12,3,7,11,15]"], ["[2,null,5,4,7]"], ["[11,6,15,3,8,13,17]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "419", "slug": "increasing-triplet-subsequence", "id": 419, "title": "Increasing Triplet Subsequence", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/increasing-triplet-subsequence/", "examples": [{"input": "nums = [1,2,3,4,5]", "output": "true", "explanation": "The whole list climbs, so any three positions qualify."}, {"input": "nums = [5,4,3,2,1]", "output": "false", "explanation": "Every later value is smaller, blocking any climb."}, {"input": "nums = [2,1,5,0,4,6]", "output": "true", "explanation": "Values 1, 4, 6 appear in order and rise strictly."}], "hints": ["Keep the smallest value seen and the smallest valid middle value above it.", "A new value larger than the middle completes a triple; otherwise shrink the tracked pair."], "statement": "You are handed a list of integers `nums`. Determine whether it hides three positions `i < j < k` whose values climb strictly, i.e. `nums[i] < nums[j] < nums[k]`.\n\nThe three entries need not sit next to each other \u2014 only their order and values matter. Return `true` when such a triple exists and `false` otherwise.\n\n**Constraints:**\n- `1 <= nums.length <= 5 * 10^5`\n- `-2^31 <= nums[i] <= 2^31 - 1`\n", "solution": "## Approach\n\nSweep once while remembering two thresholds: the lowest value observed and the lowest second-step value above it. Each new number either lowers the first threshold, sets or lowers the second threshold, or exceeds both \u2014 the last case proves a rising triple ends here. This keeps only constant state yet detects any valid pattern.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), a single pass over the list.\n- **Space Complexity:** O(1) extra space.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def increasingTriplet(self, nums: List[int]) -> bool:\n first = second = float(\"inf\")\n for x in nums:\n if x <= first:\n first = x\n elif x <= second:\n second = x\n else:\n return True\n return False\n```\n", "starter": {"go": "package main\n\nfunc IncreasingTriplet(nums []int) bool {\n \n}", "python": "from typing import List\nclass Solution:\n def increasingTriplet(self, nums: List[int]) -> bool:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool increasingTriplet(vector<int>& nums) {\n return false;\n }\n};"}, "fn": "increasingTriplet", "params": [{"name": "nums", "type": "int_array"}], "outputType": "boolean", "tests": [["[1,2,3,4,5]"], ["[5,4,3,2,1]"], ["[2,1,5,0,4,6]"], ["[1]"], ["[1,2]"], ["[1,2,3]"], ["[3,2,1,0]"], ["[1,1,1,1]"], ["[1,2,1,2,1,2]"], ["[20,100,10,12,5,13]"], ["[5,1,5,5,2,5,4]"], ["[0,4,2,1,0,-1,-3]"], ["[-1,0,1]"], ["[1,0,0,0,10,0,0,0,100]"], ["[2,1,5,0,3]"], ["[1,5,0,4,1,3]"], ["[10,9,8,7,6,5,11]"], ["[1,2,2147483647]"], ["[-2147483648,0,2147483647]"], ["[3,1,2]"], ["[1,3,2,4]"], ["[5,4,5,4,5,4,5]"], ["[0,0,1]"], ["[1,0,2,0,3]"], ["[9,8,7,6,5,4,3,2,1,10]"], ["[1,2,3,1,2,3]"], ["[6,7,1,2,8]"]], "expected": [true, false, true, false, false, true, false, false, false, true, true, false, true, true, false, true, false, true, true, false, true, false, false, true, false, true, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "572", "slug": "inorder-successor-in-bst-ii", "id": 572, "title": "Inorder Successor in BST II", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/inorder-successor-in-bst-ii/", "examples": [{"input": "root = [2,1,3], parents = [null,2,2], p = 1", "output": "2", "explanation": "Inorder visits 1, 2, 3, so the node after 1 holds 2."}, {"input": "root = [2,1,3], parents = [null,2,2], p = 3", "output": "-1", "explanation": "3 is the largest value, hence has no successor."}, {"input": "root = [5,3,6,2,4,null,null,1], parents = [null,5,5,3,3,2], p = 3", "output": "4", "explanation": "The inorder order is 1, 2, 3, 4, 5, 6, so 4 follows 3."}], "hints": ["Adaptation: the original Node carries left/right/parent links and the answer is a Node (or null); here links arrive as the parents string and the answer is the successor value (-1 when absent).", "Rebuild val -> parent-val links by zipping the non-null values of root with the parents entries.", "From the target: if it has a right subtree the answer is that subtree's minimum, otherwise climb parents until stepping up from a left child."], "statement": "A binary search tree stores pairwise different values with the usual ordering: everything in the left subtree is smaller than the node, everything in the right subtree is larger. In the classic follow-up each node also knows its parent, so the successor can be found from the target node alone by walking down and up.\n\n**Adaptation used here.** Parent references cannot travel through this judge's value-based interface, so the tree is passed explicitly together with its parent links: `root` is the level-order serialization (with `null` gaps, e.g. `\"[2,1,3]\"`), `parents` encodes one parent value per non-`null` entry of `root` in the same left-to-right order (`null` for the tree root), and `p` is the value of the target node. For example, `root = [2,1,3]` pairs with `parents = [null,2,2]` because nodes 1 and 3 both have parent 2. Rebuild the parent links from that pair, then answer exactly as the parent-pointer version would.\n\nGiven this encoding and a target value `p` present in the tree, return the value of the node visited straight after `p` in inorder order. Return `-1` when `p` is the largest value (or when the tree is empty / `p` is absent).\n\n**Constraints:**\n- `0 <= number of nodes <= 10^4`\n- `-10^5 <= Node.val <= 10^5`\n- All values are unique; the tree is a valid binary search tree\n- `parents` has one entry per non-null value of `root`, in matching order\n", "solution": "## Approach\n\nRebuild the parent-pointer view first: walk the tree breadth-first to list nodes in serialization order, then zip that list with the `parents` entries to obtain each node's parent value (falling back to structural parents if the encoding ever disagrees). From the target node, apply the textbook parent-pointer rule: with a right subtree the successor is its leftmost node, otherwise climb through parent links until moving up from a left child. A missing target, an empty tree, or climbing past the root all yield `-1`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for the breadth-first rebuild plus O(h) for the successor walk, where h is the tree height.\n- **Space Complexity:** O(n) for the node and parent tables.\n\n## Implementation\n\n```python\nfrom collections import deque\n\nclass Solution:\n def inorderSuccessor(self, root, parents: str, p: int) -> int:\n if root is None:\n return -1\n bfs, by_val, structural = [], {}, {}\n q = deque([root])\n structural[root.val] = None\n while q:\n cur = q.popleft()\n bfs.append(cur)\n by_val[cur.val] = cur\n if cur.left is not None:\n structural[cur.left.val] = cur.val\n q.append(cur.left)\n if cur.right is not None:\n structural[cur.right.val] = cur.val\n q.append(cur.right)\n if p not in by_val:\n return -1\n inner = parents.strip()[1:-1].strip()\n toks = [] if not inner else [t.strip() for t in inner.split(\",\")]\n parent_of = dict(structural)\n if len(toks) == len(bfs):\n parent_of = {}\n for node, tok in zip(bfs, toks):\n parent_of[node.val] = None if tok == \"null\" else int(tok)\n target = by_val[p]\n if target.right is not None:\n cur = target.right\n while cur.left is not None:\n cur = cur.left\n return cur.val\n cur = target\n while True:\n pv = parent_of.get(cur.val)\n if pv is None:\n return -1\n parent = by_val.get(pv)\n if parent is None:\n return -1\n if parent.left is cur:\n return parent.val\n cur = parent\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 InorderSuccessor(root *TreeNode, parents string, p int) 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 inorderSuccessor(self, root, parents: str, p: int) -> 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 <string>\nusing namespace std;\nclass Solution {\npublic:\n int inorderSuccessor(TreeNode* root, string parents, int p) {\n \n }\n};"}, "fn": "inorderSuccessor", "params": [{"name": "root", "type": "tree_node"}, {"name": "parents", "type": "string"}, {"name": "p", "type": "int"}], "outputType": "int", "tests": [["[2,1,3]", "[null,2,2]", "1"], ["[2,1,3]", "[null,2,2]", "2"], ["[2,1,3]", "[null,2,2]", "3"], ["[5,3,6,2,4,null,null,1]", "[null,5,5,3,3,2]", "3"], ["[5,3,6,2,4,null,null,1]", "[null,5,5,3,3,2]", "1"], ["[5,3,6,2,4,null,null,1]", "[null,5,5,3,3,2]", "6"], ["[1]", "[null]", "1"], ["[]", "[]", "1"], ["[4,2,6,1,3,5,7]", "[null,4,4,2,2,6,6]", "4"], ["[4,2,6,1,3,5,7]", "[null,4,4,2,2,6,6]", "5"], ["[4,2,6,1,3,5,7]", "[null,4,4,2,2,6,6]", "7"], ["[4,2,6,1,3,5,7]", "[null,4,4,2,2,6,6]", "1"], ["[15,10,20,8,12,16,25]", "[null,15,15,10,10,20,20]", "12"], ["[15,10,20,8,12,16,25]", "[null,15,15,10,10,20,20]", "15"], ["[15,10,20,8,12,16,25]", "[null,15,15,10,10,20,20]", "25"], ["[3,1,4,null,2]", "[null,3,3,1]", "2"], ["[3,1,4,null,2]", "[null,3,3,1]", "1"], ["[3,1,4,null,2]", "[null,3,3,1]", "4"], ["[1,null,2,null,3]", "[null,1,2]", "1"], ["[1,null,2,null,3]", "[null,1,2]", "2"], ["[1,null,2,null,3]", "[null,1,2]", "3"], ["[3,null,4,null,5]", "[null,3,4]", "4"], ["[10,5,15,2,7,null,20]", "[null,10,10,5,5,15]", "7"], ["[10,5,15,2,7,null,20]", "[null,10,10,5,5,15]", "10"], ["[10,5,15,2,7,null,20]", "[null,10,10,5,5,15]", "2"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "[null,8,8,3,3,10,6,6,14]", "7"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "[null,8,8,3,3,10,6,6,14]", "13"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "[null,8,8,3,3,10,6,6,14]", "14"]], "expected": [2, 3, -1, 4, 2, -1, -1, -1, 5, 6, -1, 2, 15, 16, -1, 3, 2, -1, 2, 3, -1, 5, 10, 15, 5, 8, 14, -1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "383", "slug": "inorder-successor-in-bst", "id": 383, "title": "Inorder Successor in BST", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/inorder-successor-in-bst/", "examples": [{"input": "root = [2,1,3], p = 1", "output": "2", "explanation": "Inorder is [1,2,3]; after 1 comes 2."}, {"input": "root = [2,1,3], p = 2", "output": "3", "explanation": "After 2 comes 3."}, {"input": "root = [2,1,3], p = 3", "output": "-1", "explanation": "3 is largest, so no successor."}], "hints": ["Adaptation: p is given as a value and the answer is the successor value, or -1 when p is largest (instead of a node/null).", "Walk down using BST order, remembering the last ancestor greater than p.", "Inorder successor is the smallest value larger than p."], "statement": "In a binary search tree, find the inorder successor of the node with value `p`.\n\n**Adaptation:** instead of node references, `p` is given as an integer value\npresent in the tree and you return the successor's value, or `-1` when `p`\nis the maximum (the original would return null). Implement\n`inorderSuccessor(root, p)`.\n\n**Constraints:**\n- `1 <= nodes <= 10^4`\n- Tree is a valid BST; `p` exists in the tree.\n", "solution": "## Approach\n\nSearch the BST for p while tracking the best successor candidate: whenever the current node exceeds p, it could be the answer so record it and go left; otherwise go right. The last recorded value is the smallest key larger than p.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(h) where h is tree height.\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nclass Solution:\n def inorderSuccessor(self, root, p: int) -> int:\n succ = -1\n cur = root\n while cur:\n if p < cur.val:\n succ = cur.val\n cur = cur.left\n else:\n cur = cur.right\n return succ\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 InorderSuccessor(root *TreeNode, p int) 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 inorderSuccessor(self, root, p: int) -> 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 inorderSuccessor(TreeNode* root, int p) {\n \n }\n};"}, "fn": "inorderSuccessor", "params": [{"name": "root", "type": "tree_node"}, {"name": "p", "type": "int"}], "outputType": "int", "tests": [["[2,1,3]", "1"], ["[2,1,3]", "2"], ["[2,1,3]", "3"], ["[5,3,6,2,4,null,null,1]", "1"], ["[5,3,6,2,4,null,null,1]", "2"], ["[5,3,6,2,4,null,null,1]", "3"], ["[5,3,6,2,4,null,null,1]", "4"], ["[5,3,6,2,4,null,null,1]", "5"], ["[5,3,6,2,4,null,null,1]", "6"], ["[1]", "1"], ["[2,1]", "1"], ["[2,1]", "2"], ["[3,1,4,null,2]", "2"], ["[3,1,4,null,2]", "1"], ["[4,2,6,1,3,5,7]", "3"], ["[4,2,6,1,3,5,7]", "7"], ["[10,5,15,3,7,12,20]", "7"], ["[10,5,15,3,7,12,20]", "15"], ["[2,null,3]", "2"], ["[5,3,6,2,4]", "4"], ["[4,2,6,1,3,5,7]", "4"], ["[4,2,6,1,3,5,7]", "5"], ["[4,2,6,1,3,5,7]", "6"], ["[15,10,20,8,12,17,25]", "10"], ["[15,10,20,8,12,17,25]", "12"], ["[15,10,20,8,12,17,25]", "25"], ["[1,null,2,null,3,null,4]", "3"], ["[5,3,8,1,4,7,9]", "8"]], "expected": [2, 3, -1, 2, 3, 4, 5, 6, -1, -1, 2, -1, 3, 2, 4, -1, 10, 20, 3, 5, 5, 6, 7, 12, 15, -1, 4, 9], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "457", "slug": "insert-delete-getrandom-o1-duplicates-allowed", "id": 457, "title": "Insert Delete GetRandom O(1) - Duplicates Allowed", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/", "examples": [{"explanation": "The first insert of 1 is new (true); the second insert of 1 finds a copy (false); inserting 2 is new (true).", "input": "operations = [\"RandomizedCollection\",\"insert\",\"insert\",\"insert\"], values = [[],[1],[1],[2]]", "output": "[null,true,false,true]"}, {"explanation": "After two inserts of 2, each remove deletes one copy; one copy remains.", "input": "operations = [\"RandomizedCollection\",\"insert\",\"insert\",\"remove\",\"remove\"], values = [[],[2],[2],[2],[2]]", "output": "[null,true,false,true,true]"}, {"explanation": "With only 9 held, getRandom must return 9.", "input": "operations = [\"RandomizedCollection\",\"insert\",\"getRandom\"], values = [[],[9],[]]", "output": "[null,true,9]"}], "hints": ["Keep a list of values plus, per value, the set of list positions holding it.", "Insertion appends and records the new index; removal swaps the chosen index with the tail and fixes both index sets.", "Sampling draws a uniform list position; the judge accepts any held value."], "statement": "`RandomizedCollection` is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing specific elements and also reporting a random element.\n\nImplement the `RandomizedCollection` class:\n\n- `RandomizedCollection()` Initializes the empty object.\n- `bool insert(int val)` Inserts an item `val` into the multiset, even if the item is already present. Returns `true` if the item is not present, `false` otherwise.\n- `bool remove(int val)` Removes an item `val` from the multiset if present. Returns `true` if the item is present, `false` otherwise. Note that if `val` has multiple occurrences, only one of them is removed.\n- `int getRandom()` Returns a random element from the current multiset. The probability of each element being returned is linearly related to the number of same values it contains (it is guaranteed that at least one element exists when this method is called).\n\nYou must implement the functions of the class such that each function works in average O(1) time complexity.\n\nThe class keeps its LeetCode name `RandomizedCollection` here (instead of `Solution`) because the judge harness reserves `Solution` for its driver; the constructor and methods match the original.\n\nGrading: `insert`/`remove` booleans are compared exactly against a reference model tracking per-value counts, and each `getRandom` output must have a remaining copy at that point. Only validity is checked \u2014 the sampling distribution is not statistically tested.\n\n**Constraints:**\n- `-2^31 <= val <= 2^31 - 1`\n- At most `2 * 10^5` calls will be made to `insert`, `remove`, and `getRandom`.\n- `getRandom` will only be called when at least one copy is held.\n", "solution": "## Approach\n\nKeep a list of values plus, per value, the set of list positions holding it. `insert` appends the value and records the new index, reporting whether no copy existed before. `remove` takes an arbitrary recorded index for the value, swaps that slot with the tail, fixes both values' index sets, and pops \u2014 deleting exactly one copy. `getRandom` draws a uniform list position, so multiplicity is respected automatically.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) average per operation.\n- **Space Complexity:** O(n) for the list plus the per-value index sets.\n\n## Implementation\n\n```python\nimport random\nfrom collections import defaultdict\n\nclass RandomizedCollection:\n def __init__(self):\n self.a = []\n self.pos = defaultdict(set)\n\n def insert(self, val: int) -> bool:\n fresh = len(self.pos[val]) == 0\n self.pos[val].add(len(self.a))\n self.a.append(val)\n return fresh\n\n def remove(self, val: int) -> bool:\n if not self.pos[val]:\n return False\n i = next(iter(self.pos[val]))\n self.pos[val].discard(i)\n last = self.a[-1]\n if i != len(self.a) - 1:\n self.a[i] = last\n self.pos[last].discard(len(self.a) - 1)\n self.pos[last].add(i)\n self.a.pop()\n if not self.pos[val]:\n del self.pos[val]\n return True\n\n def getRandom(self) -> int:\n return random.choice(self.a)\n```\n", "starter": {"go": "package main\n\ntype RandomizedCollection struct {\n\n}\n\nfunc Constructor() RandomizedCollection {\n return RandomizedCollection{}\n}\n\nfunc (this *RandomizedCollection) Insert(val int) bool {\n return false\n}\n\nfunc (this *RandomizedCollection) Remove(val int) bool {\n return false\n}\n\nfunc (this *RandomizedCollection) GetRandom() int {\n return 0\n}\n", "python": "import random\nfrom collections import defaultdict\n\nclass RandomizedCollection:\n def __init__(self):\n\n def insert(self, val: int) -> bool:\n return False\n\n def remove(self, val: int) -> bool:\n return False\n\n def getRandom(self) -> int:\n return 0\n", "cpp": "#include <vector>\n#include <unordered_map>\n#include <unordered_set>\nusing namespace std;\n\nclass RandomizedCollection {\npublic:\n RandomizedCollection() {\n \n }\n\n bool insert(int val) {\n return false;\n }\n\n bool remove(int val) {\n return false;\n }\n\n int getRandom() {\n return 0;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"remove\", \"getRandom\"]", "[[], [1], [1], [2], [], [1], []]"], ["[\"RandomizedCollection\", \"insert\", \"remove\", \"remove\"]", "[[], [4], [4], [4]]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"remove\"]", "[[], [2], [2], [2]]"], ["[\"RandomizedCollection\", \"insert\", \"getRandom\"]", "[[], [9], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"getRandom\"]", "[[], [5], [5], [5], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"remove\", \"getRandom\"]", "[[], [3], [3], [3], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"remove\", \"insert\", \"getRandom\"]", "[[], [1], [2], [1], [3], []]"], ["[\"RandomizedCollection\", \"remove\", \"insert\", \"getRandom\"]", "[[], [10], [10], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"getRandom\", \"remove\", \"getRandom\"]", "[[], [6], [7], [], [6], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"remove\", \"insert\", \"getRandom\"]", "[[], [-3], [-3], [-3], [5], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"remove\", \"remove\", \"getRandom\"]", "[[], [8], [8], [9], [8], [8], []]"], ["[\"RandomizedCollection\", \"remove\", \"remove\", \"insert\", \"getRandom\"]", "[[], [1], [2], [3], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"getRandom\"]", "[[], [7], [7], [7], [8], [8], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"remove\", \"remove\", \"insert\", \"getRandom\"]", "[[], [0], [0], [1], [1], [2], [2], [3], [3], [4], [4], [5], [5], [6], [6], [7], [7], [8], [8], [9], [9], [10], [10], [11], [11], [12], [12], [13], [13], [14], [14], [15], [15], [16], [16], [17], [17], [18], [18], [19], [19], [20], [20], [21], [21], [22], [22], [23], [23], [24], [24], [25], [25], [26], [26], [27], [27], [28], [28], [29], [29], [], [], [], [], [], [], [], [], [], [], [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [], [], [], [], [], [], [], [], [], [], [0], [999], [0], []]"], ["[\"RandomizedCollection\", \"remove\", \"insert\", \"getRandom\", \"insert\", \"remove\", \"getRandom\"]", "[[], [4], [0], [], [0], [6], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"remove\", \"insert\", \"insert\", \"getRandom\"]", "[[], [0], [0], [], [4], [1], [3], [5], [4], []]"], ["[\"RandomizedCollection\", \"insert\", \"remove\", \"getRandom\", \"getRandom\", \"remove\", \"getRandom\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\", \"insert\", \"insert\"]", "[[], [5], [1], [], [], [4], [], [0], [3], [], [], [], [5], [0]]"], ["[\"RandomizedCollection\", \"insert\", \"getRandom\", \"remove\", \"getRandom\", \"getRandom\", \"getRandom\", \"insert\", \"insert\"]", "[[], [1], [], [4], [], [], [], [1], [2]]"], ["[\"RandomizedCollection\", \"insert\", \"remove\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"insert\", \"getRandom\", \"getRandom\"]", "[[], [1], [6], [1], [1], [], [0], [0], [0], [], [6], [], []]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"insert\", \"insert\", \"getRandom\", \"insert\", \"getRandom\", \"insert\"]", "[[], [2], [1], [1], [], [0], [0], [2], [3], [3], [], [4], [6], [], [0], [], [0]]"], ["[\"RandomizedCollection\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"insert\", \"getRandom\", \"remove\", \"remove\", \"getRandom\", \"insert\", \"remove\", \"getRandom\", \"getRandom\"]", "[[], [5], [6], [], [], [3], [], [5], [2], [], [2], [4], [], []]"], ["[\"RandomizedCollection\", \"remove\", \"insert\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\"]", "[[], [1], [4], [2], [0], [], [1], [], [0], [5], [5], [3], [0], [4], [0]]"], ["[\"RandomizedCollection\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"remove\", \"remove\", \"remove\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\"]", "[[], [2], [], [2], [5], [5], [5], [1], [2], [], [], []]"], ["[\"RandomizedCollection\", \"insert\", \"getRandom\", \"insert\", \"remove\", \"getRandom\", \"getRandom\", \"getRandom\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\"]", "[[], [1], [], [5], [4], [], [], [], [5], [2], [], [1], [], [], [], []]"], ["[\"RandomizedCollection\", \"insert\", \"getRandom\", \"insert\", \"getRandom\", \"getRandom\", \"insert\", \"insert\", \"remove\", \"remove\", \"remove\", \"insert\", \"getRandom\"]", "[[], [1], [], [0], [], [], [1], [6], [2], [5], [3], [1], []]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "456", "slug": "insert-delete-getrandom-o1", "id": 456, "title": "Insert Delete GetRandom O(1)", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/insert-delete-getrandom-o1/", "examples": [{"explanation": "Insert 1 and 2 (both new), then remove 1.", "input": "operations = [\"RandomizedSet\",\"insert\",\"insert\",\"remove\"], values = [[],[1],[2],[1]]", "output": "[null,true,true,true]"}, {"explanation": "Inserting 0 twice records true then false; removing the absent 1 records false.", "input": "operations = [\"RandomizedSet\",\"insert\",\"insert\",\"remove\"], values = [[],[0],[0],[1]]", "output": "[null,true,false,false]"}, {"explanation": "With only 5 in the set, getRandom must return 5; removing 5 then succeeds.", "input": "operations = [\"RandomizedSet\",\"insert\",\"getRandom\",\"remove\"], values = [[],[5],[],[5]]", "output": "[null,true,5,true]"}], "hints": ["Pair a value-to-index map with a dense list of values.", "Insert appends at the end; removal swaps the target with the last entry and pops.", "getRandom picks a uniform index; the judge accepts any current member."], "statement": "Implement the `RandomizedSet` class:\n\n- `RandomizedSet()` Initializes the `RandomizedSet` object.\n- `bool insert(int val)` Inserts an item `val` into the set if not present. Returns `true` if the item was not present, `false` otherwise.\n- `bool remove(int val)` Removes an item `val` from the set if present. Returns `true` if the item was present, `false` otherwise.\n- `int getRandom()` Returns a random element from the current set of elements (it is guaranteed that at least one element exists when this method is called). Each element must have the same probability of being returned.\n\nYou must implement the functions of the class such that each function works in average O(1) time complexity.\n\nThe class keeps its LeetCode name `RandomizedSet` here (instead of `Solution`) because the judge harness reserves `Solution` for its driver; the constructor and methods match the original.\n\nGrading: `insert`/`remove` booleans are compared exactly against a reference model, and each `getRandom` output must be a member of the live set at that point. Only validity is checked \u2014 uniformity over the set is not statistically tested.\n\n**Constraints:**\n- `-2^31 <= val <= 2^31 - 1`\n- At most `2 * 10^5` calls will be made to `insert`, `remove`, and `getRandom`.\n- `getRandom` will only be called when the set holds at least one element.\n", "solution": "## Approach\n\nPair a value-to-index map with a dense list of values. `insert` appends a new value at the end and records its index; `remove` swaps the target with the last entry, updates the moved entry's index, and pops the tail \u2014 all average O(1). `getRandom` draws a uniform list index.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) average per operation.\n- **Space Complexity:** O(n) for the list plus the index map.\n\n## Implementation\n\n```python\nimport random\n\nclass RandomizedSet:\n def __init__(self):\n self.a = []\n self.pos = {}\n\n def insert(self, val: int) -> bool:\n if val in self.pos:\n return False\n self.pos[val] = len(self.a)\n self.a.append(val)\n return True\n\n def remove(self, val: int) -> bool:\n if val not in self.pos:\n return False\n i = self.pos[val]\n last = self.a[-1]\n self.a[i] = last\n self.pos[last] = i\n self.a.pop()\n del self.pos[val]\n return True\n\n def getRandom(self) -> int:\n return random.choice(self.a)\n```\n", "starter": {"go": "package main\n\ntype RandomizedSet struct {\n\n}\n\nfunc Constructor() RandomizedSet {\n return RandomizedSet{}\n}\n\nfunc (this *RandomizedSet) Insert(val int) bool {\n return false\n}\n\nfunc (this *RandomizedSet) Remove(val int) bool {\n return false\n}\n\nfunc (this *RandomizedSet) GetRandom() int {\n return 0\n}\n", "python": "import random\n\nclass RandomizedSet:\n def __init__(self):\n\n def insert(self, val: int) -> bool:\n return False\n\n def remove(self, val: int) -> bool:\n return False\n\n def getRandom(self) -> int:\n return 0\n", "cpp": "#include <vector>\n#include <unordered_map>\nusing namespace std;\n\nclass RandomizedSet {\npublic:\n RandomizedSet() {\n \n }\n\n bool insert(int val) {\n return false;\n }\n\n bool remove(int val) {\n return false;\n }\n\n int getRandom() {\n return 0;\n }\n};"}, "fn": "solve", "params": [{"name": "operations", "type": "string_array"}, {"name": "values", "type": "int_array_2d"}], "outputType": "string_list", "tests": [["[\"RandomizedSet\", \"insert\", \"remove\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"getRandom\"]", "[[], [1], [2], [2], [], [1], [2], []]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"getRandom\"]", "[[], [5], [5], []]"], ["[\"RandomizedSet\", \"insert\", \"remove\", \"remove\"]", "[[], [3], [3], [3]]"], ["[\"RandomizedSet\", \"insert\", \"getRandom\"]", "[[], [7], []]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"remove\", \"getRandom\"]", "[[], [1], [2], [1], []]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"insert\", \"getRandom\"]", "[[], [-1], [0], [1], []]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"remove\", \"remove\", \"insert\"]", "[[], [4], [5], [4], [5], [6]]"], ["[\"RandomizedSet\", \"insert\", \"getRandom\", \"getRandom\", \"remove\"]", "[[], [9], [], [], [9]]"], ["[\"RandomizedSet\", \"remove\", \"insert\", \"getRandom\"]", "[[], [100], [100], []]"], ["[\"RandomizedSet\", \"insert\", \"remove\", \"insert\", \"remove\", \"insert\", \"getRandom\"]", "[[], [6], [6], [6], [6], [6], []]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"getRandom\", \"getRandom\"]", "[[], [2147483647], [-2147483648], [], []]"], ["[\"RandomizedSet\", \"insert\", \"getRandom\", \"insert\", \"getRandom\", \"remove\", \"getRandom\"]", "[[], [1], [], [2], [], [1], []]"], ["[\"RandomizedSet\", \"remove\", \"remove\", \"insert\", \"getRandom\"]", "[[], [1], [2], [3], []]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"remove\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"insert\", \"insert\", \"remove\", \"getRandom\"]", "[[], [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31], [32], [33], [34], [35], [36], [37], [38], [39], [40], [41], [42], [43], [44], [45], [46], [47], [48], [49], [], [], [], [], [], [], [], [], [], [], [0], [2], [4], [6], [8], [10], [12], [14], [16], [18], [20], [22], [24], [26], [28], [30], [32], [34], [36], [38], [40], [42], [44], [46], [48], [], [], [], [], [], [], [], [], [], [], [1], [1], [999], []]"], ["[\"RandomizedSet\", \"insert\", \"getRandom\", \"getRandom\", \"remove\", \"insert\", \"insert\", \"getRandom\", \"insert\", \"getRandom\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\"]", "[[], [1], [], [], [8], [2], [4], [], [2], [], [8], [], [], [], [], []]"], ["[\"RandomizedSet\", \"remove\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"insert\", \"remove\", \"getRandom\"]", "[[], [4], [4], [2], [], [7], [8], [6], []]"], ["[\"RandomizedSet\", \"remove\", \"insert\", \"insert\", \"getRandom\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"insert\"]", "[[], [1], [1], [1], [], [0], [4], [], [], [], [], [3]]"], ["[\"RandomizedSet\", \"insert\", \"remove\", \"insert\", \"insert\", \"insert\", \"insert\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\"]", "[[], [0], [4], [9], [7], [7], [1], [9], [6], [], [5], [1], [6], [], [], [], []]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"insert\", \"insert\", \"insert\", \"insert\", \"remove\"]", "[[], [1], [3], [7], [0], [], [], [3], [2], [4], [0], [0]]"], ["[\"RandomizedSet\", \"insert\", \"getRandom\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"insert\", \"remove\", \"insert\", \"insert\", \"getRandom\"]", "[[], [4], [], [4], [3], [5], [], [], [6], [2], [7], [6], []]"], ["[\"RandomizedSet\", \"insert\", \"remove\", \"insert\", \"insert\", \"insert\", \"insert\", \"getRandom\"]", "[[], [9], [3], [2], [5], [1], [5], []]"], ["[\"RandomizedSet\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"remove\", \"remove\", \"getRandom\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"insert\"]", "[[], [2], [4], [], [6], [8], [9], [], [4], [2], [8], [], [0]]"], ["[\"RandomizedSet\", \"insert\", \"insert\", \"getRandom\", \"insert\", \"remove\", \"insert\", \"insert\", \"remove\", \"getRandom\", \"insert\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"insert\", \"getRandom\"]", "[[], [5], [7], [], [9], [6], [3], [1], [3], [], [0], [9], [], [5], [7], [8], []]"], ["[\"RandomizedSet\", \"remove\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"insert\", \"insert\", \"getRandom\", \"getRandom\", \"remove\", \"insert\", \"getRandom\", \"insert\", \"getRandom\", \"insert\"]", "[[], [3], [3], [7], [], [], [7], [4], [], [], [5], [7], [], [5], [], [1]]"], ["[\"RandomizedSet\", \"insert\", \"remove\", \"getRandom\", \"remove\", \"insert\", \"insert\"]", "[[], [4], [1], [], [7], [0], [1]]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "245", "slug": "insert-greatest-common-divisors-in-linked-list", "id": 245, "title": "Insert Greatest Common Divisors in Linked List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/insert-greatest-common-divisors-in-linked-list/", "examples": [{"input": "head = [18,6,10,3]", "output": "[18,6,6,2,10,1,3]", "explanation": "gcd(18,6)=6, gcd(6,10)=2, gcd(10,3)=1 are inserted between adjacent nodes."}, {"input": "head = [7]", "output": "[7]"}], "hints": ["Walk the list while keeping a pointer to the current node; while the node has a next, insert a node with value gcd(current.val, next.val) in between.", "After inserting, advance past the newly inserted node so each original adjacent pair is visited exactly once."], "statement": "You are given the first node `head` of a singly linked list whose nodes each store an integer.\n\nFor every neighboring pair in the current chain, splice in a fresh node positioned between them whose stored value equals the greatest common divisor of the two neighbors' values.\n\nHand back the head of the chain once all insertions are complete.\n\nRecall that the greatest common divisor of a pair is the biggest positive integer dividing both values without remainder.\n\n**Constraints:**\n\n- The number of nodes in the list is in the range `[1, 5000]`.\n- `1 <= Node.val <= 1000`\n", "solution": "## Approach\n\nWalk the list with a pointer `cur`. While `cur` has a next node, create a new node whose value is `gcd(cur.val, cur.next.val)`, link it between `cur` and `cur.next`, then advance `cur` past the inserted node so each original adjacent pair is processed exactly once. A list with a single node is returned unchanged.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where `n` is the number of nodes, since each pair's gcd is computed once and each gcd is O(log(max value)).\n- **Space Complexity:** O(1) besides the output nodes created.\n\n## Implementation\n\n```python\nfrom typing import Optional\nfrom math import gcd\n\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:\n cur = head\n while cur and cur.next:\n gcd_node = ListNode(gcd(cur.val, cur.next.val), cur.next)\n cur.next = gcd_node\n cur = gcd_node.next\n return head\n```", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc InsertGreatestCommonDivisors(head *ListNode) *ListNode {\n return nil\n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nfrom typing import Optional\nclass Solution:\n def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:\n ", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* insertGreatestCommonDivisors(ListNode* head) {\n return nullptr;\n }\n};"}, "fn": "insertGreatestCommonDivisors", "params": [{"name": "head", "type": "list_node"}], "outputType": "list_node", "tests": [["[18,6,10,3]"], ["[7]"], ["[1,1]"], ["[2,4,8,16]"], ["[1000,500,250,125]"], ["[3,5,7,9,11]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[999]"], ["[12,18,24,36,48]"], ["[7,14,21,35,49,98]"], ["[1]"], ["[997,991,983,977]"], ["[2,3,5,8,13,21,34,55,89,144]"], ["[6, 12, 18]"], ["[5, 10]"], ["[1000, 1]"], ["[8, 12]"], ["[9, 27, 81]"], ["[4, 6]"], ["[15, 25, 35]"], ["[100, 75, 50, 25]"], ["[990, 945, 900]"], ["[11, 13]"], ["[16, 24]"], ["[30, 42, 70]"], ["[500, 750]"], ["[2, 2, 2, 2]"], ["[7, 7, 7]"], ["[36, 48, 60, 72]"], ["[101, 202, 303]"]], "expected": [[18, 6, 6, 2, 10, 1, 3], [7], [1, 1, 1], [2, 2, 4, 4, 8, 8, 16], [1000, 500, 500, 250, 250, 125, 125], [3, 1, 5, 1, 7, 1, 9, 1, 11], [1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10], [999], [12, 6, 18, 6, 24, 12, 36, 12, 48], [7, 7, 14, 7, 21, 7, 35, 7, 49, 49, 98], [1], [997, 1, 991, 1, 983, 1, 977], [2, 1, 3, 1, 5, 1, 8, 1, 13, 1, 21, 1, 34, 1, 55, 1, 89, 1, 144], [6, 6, 12, 6, 18], [5, 5, 10], [1000, 1, 1], [8, 4, 12], [9, 9, 27, 27, 81], [4, 2, 6], [15, 5, 25, 5, 35], [100, 25, 75, 25, 50, 25, 25], [990, 45, 945, 45, 900], [11, 1, 13], [16, 8, 24], [30, 6, 42, 14, 70], [500, 250, 750], [2, 2, 2, 2, 2, 2, 2], [7, 7, 7, 7, 7], [36, 12, 48, 12, 60, 12, 72], [101, 101, 202, 101, 303]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "35", "slug": "insert-interval", "id": 35, "title": "Insert Interval", "difficulty": "Medium", "category": "interval", "link": "https://leetcode.com/problems/insert-interval/", "examples": [{"input": "intervals = [[1,3],[6,9]], newInterval = [2,5]", "output": "[[1,5],[6,9]]", "explanation": "[2,5] overlaps with [1,3], so they merge into [1,5]. [6,9] is unchanged."}, {"input": "intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]", "output": "[[1,2],[3,10],[12,16]]", "explanation": "[4,8] overlaps with [3,5], [6,7], and [8,10], merging into [3,10]. [1,2] and [12,16] are unchanged."}, {"input": "intervals = [], newInterval = [5,7]", "output": "[[5,7]]", "explanation": "The interval list is empty, so the result is just [[5,7]]."}], "hints": ["Walk through intervals in order: add all intervals ending before newInterval starts.", "For overlapping intervals, merge by expanding newInterval to [min(start), max(end)] until overlaps end.", "After merging, append the merged newInterval, then append the remaining intervals.", "You don't need to sort if the input is already sorted and non-overlapping."], "statement": "Insert a new interval into a list of non-overlapping, start-sorted intervals and merge if necessary.\n\n**Constraints:**\n\n- 0 \u2264 intervals.length \u2264 10^4\n- intervals[i].length == 2\n- 0 \u2264 starti \u2264 endi \u2264 10^5\n- intervals is sorted by starti in ascending order.\n- newInterval.length == 2\n- 0 \u2264 start \u2264 end \u2264 10^5\n", "solution": "## Approach\n\nLinear scan through the sorted intervals: add all intervals ending before the new interval starts, merge overlapping intervals by extending the new interval bounds, then append the merged interval and remaining intervals.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of intervals.\n- **Space Complexity:** O(n) for the output list.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:\n res = []\n i, n = 0, len(intervals)\n while i < n and intervals[i][1] < newInterval[0]:\n res.append(intervals[i])\n i += 1\n while i < n and intervals[i][0] <= newInterval[1]:\n newInterval[0] = min(newInterval[0], intervals[i][0])\n newInterval[1] = max(newInterval[1], intervals[i][1])\n i += 1\n res.append(newInterval)\n while i < n:\n res.append(intervals[i])\n i += 1\n return res\n```\n", "starter": {"go": "package main\n\nfunc Insert(intervals [][]int, newInterval []int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n return {};\n }\n};"}, "fn": "insert", "params": [{"name": "intervals", "type": "int_array_2d"}, {"name": "newInterval", "type": "int_array"}], "outputType": "int_array_2d", "tests": [["[[1,3],[6,9]]", "[2,5]"], ["[[1,2],[3,5],[6,7],[8,10],[12,16]]", "[4,8]"], ["[]", "[5,7]"], ["[[1,5]]", "[2,3]"], ["[[1,5]]", "[2,7]"], ["[[1,5]]", "[6,8]"], ["[[1,2],[3,4]]", "[0,0]"], ["[[1,2],[3,4]]", "[5,6]"], ["[[1,2],[3,4]]", "[2,3]"], ["[[1,4],[5,7],[8,10]]", "[2,9]"], ["[[3, 5], [7, 9]]", "[1, 2]"], ["[[3, 5], [7, 9]]", "[10, 12]"], ["[[1, 2], [5, 6], [9, 10]]", "[3, 4]"], ["[[1, 2], [5, 6], [9, 10]]", "[3, 8]"], ["[[2, 4]]", "[0, 1]"], ["[[2, 4]]", "[4, 6]"], ["[[1, 10]]", "[3, 4]"], ["[[1, 10]]", "[0, 11]"], ["[]", "[0, 0]"], ["[[5, 5]]", "[5, 5]"], ["[[1, 2], [4, 5]]", "[2, 4]"], ["[[0, 5], [10, 15], [20, 25]]", "[6, 9]"], ["[[0, 5], [10, 15], [20, 25]]", "[6, 22]"], ["[[1, 3], [4, 6], [7, 9], [10, 12]]", "[0, 13]"], ["[[10, 20]]", "[0, 5]"], ["[[10, 20]]", "[25, 30]"], ["[[1, 2], [3, 4], [5, 6]]", "[7, 8]"], ["[[100, 200], [300, 400]]", "[150, 350]"], ["[[0, 100000]]", "[50000, 60000]"], ["[[5, 10], [15, 20]]", "[11, 14]"]], "expected": [[[1, 5], [6, 9]], [[1, 2], [3, 10], [12, 16]], [[5, 7]], [[1, 5]], [[1, 7]], [[1, 5], [6, 8]], [[0, 0], [1, 2], [3, 4]], [[1, 2], [3, 4], [5, 6]], [[1, 4]], [[1, 10]], [[1, 2], [3, 5], [7, 9]], [[3, 5], [7, 9], [10, 12]], [[1, 2], [3, 4], [5, 6], [9, 10]], [[1, 2], [3, 8], [9, 10]], [[0, 1], [2, 4]], [[2, 6]], [[1, 10]], [[0, 11]], [[0, 0]], [[5, 5]], [[1, 5]], [[0, 5], [6, 9], [10, 15], [20, 25]], [[0, 5], [6, 25]], [[0, 13]], [[0, 5], [10, 20]], [[10, 20], [25, 30]], [[1, 2], [3, 4], [5, 6], [7, 8]], [[100, 400]], [[0, 100000]], [[5, 10], [11, 14], [15, 20]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "197", "slug": "insert-into-a-binary-search-tree", "id": 197, "title": "Insert into a Binary Search Tree", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/insert-into-a-binary-search-tree/", "examples": [{"input": "root = [4,2,7,1,3], val = 5", "output": "[4,2,7,1,3,5]", "explanation": "Insert 5 as left child of 7."}, {"input": "root = [40,20,60,10,30,50,70], val = 25", "output": "[40,20,60,10,30,50,70,null,null,25]"}], "hints": ["Walk down the BST until you find a null child to attach the new node."], "statement": "You receive the `root` of a binary search tree (BST) along with an integer `val` that must be added to the structure. Produce the `root` of the tree once the addition is done. The incoming value is guaranteed absent from the starting tree.\n\nSeveral placements can preserve BST ordering; returning any tree that is a valid BST containing all old values plus the new one is acceptable.\n\n**Constraints:**\n- The number of nodes in the tree is in the range `[0, 10^4]`\n- `-10^8 <= Node.val <= 10^8`\n- All the values `Node.val` are unique\n- `-10^8 <= val <= 10^8`\n- It's guaranteed that `val` does not exist in the original BST\n", "solution": "## Approach\n\nWalk from the root: go left if `val` is smaller, right if larger, until a null child is found, then attach the new node.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(h)\n- **Space Complexity:** O(h) recursion\n\n## Implementation\n\n```python\nclass Solution:\n def insertIntoBST(self, root, val: int):\n if root is None:\n return TreeNode(val)\n if val < root.val:\n root.left = self.insertIntoBST(root.left, val)\n else:\n root.right = self.insertIntoBST(root.right, val)\n return root\n```\n", "starter": {"go": "package main\n\nfunc InsertIntoBST(root *TreeNode, val int) *TreeNode {\n return nil\n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def insertIntoBST(self, root, val: 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*/\nclass Solution {\npublic:\n TreeNode* insertIntoBST(TreeNode* root, int val) {\n return nullptr;\n }\n};"}, "fn": "insertIntoBST", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}, {"name": "val", "type": "int"}], "outputType": "tree_node", "tests": [["[4,2,7,1,3]", "5"], ["[40,20,60,10,30,50,70]", "25"], ["[]", "1"], ["[4,2,7,1,3]", "0"], ["[4,2,7,1,3]", "8"], ["[5]", "3"], ["[5]", "7"], ["[2,1,3]", "4"], ["[10,5,15,3,7,null,18]", "12"], ["[1,null,2,null,3]", "0"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "5"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "2"], ["[1,null,2,null,3,null,4]", "5"], ["[5,3,7,2,4,6,8]", "1"], ["[5,3,7,2,4,6,8]", "9"], ["[10,5,null,3,7]", "6"], ["[10,5,null,3,7]", "12"], ["[50,30,70,20,40,60,80]", "35"], ["[50,30,70,20,40,60,80]", "90"], ["[3,1,4,null,2]", "5"], ["[3,1,4,null,2]", "0"], ["[100,50,150]", "75"], ["[100,50,150]", "25"], ["[20,10,30,null,null,null,40]", "35"], ["[20,10,30,null,null,null,40]", "5"], ["[6,2,8,0,4,7,9,null,null,3,5]", "1"], ["[15,10,20,8,12,17,25]", "13"], ["[7,3,null,1,5]", "4"], ["[7,3,null,1,5]", "6"], ["[9,4,null,2,6]", "7"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "716", "slug": "insert-into-a-sorted-circular-linked-list", "id": 716, "title": "Insert into a Sorted Circular Linked List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list/", "examples": [{"input": "head = [3,4,1], insertVal = 2", "output": "[3,4,1,2]", "explanation": "2 fits between 1 and 3."}, {"input": "head = [], insertVal = 1", "output": "[1]", "explanation": "Single self-loop."}, {"input": "head = [1], insertVal = 0", "output": "[1,0]", "explanation": "Ring 1 -> 0 -> 1."}], "hints": ["Adaptation: the circular ring is encoded linearly from the head; the output must start from the same head (new node only when empty).", "Walk the ring once: insert between cur and next when cur.val <= insertVal <= next.val, or at the max-to-min drop when insertVal lies outside the current span.", "If no spot matches (all values equal), insert directly after the head."], "statement": "A circular linked list is sorted when its values increase around the ring except for one drop from the maximum back to the minimum. The list is given as a linear encoding `head` that lists values in circular order starting from the current head node (for example `[3,4,1]` means `3 -> 4 -> 1 -> 3`). An empty list is `[]`.\n\nInsert a new value `insertVal` so the ring stays sorted, and return the linear encoding that starts from the original head (or the single new value when the input was empty). The head itself never changes unless the list was empty.\n\n**Constraints:**\n- `0 <= head.length <= 1000`\n- `-1000 <= Node.val, insertVal <= 1000`\n- The input ring is sorted in the circular sense.\n- The judge checks that the output starts from the same head, holds all old values plus the new one, and is circularly sorted.\n", "solution": "## Approach\n\nRebuild the ring from the linear encoding and walk it once from the given head. A new value belongs between two neighbours when it lies inside their interval, or at the single high-to-low turnover when it extends beyond the current span. Falling through the whole loop (possible only with uniform values) inserts right after the head. The resulting ring is then unwrapped into a linear chain that starts at the original head, preserving the required representation.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) for one ring traversal.\n- **Space Complexity:** O(n) for the rebuilt chain.\n\n## Implementation\n\n```python\nclass Solution:\n def insert(self, head, insertVal: int):\n vals = []\n p = head\n while p:\n vals.append(p.val)\n p = p.next\n if not vals:\n return ListNode(insertVal)\n n = len(vals)\n idx = None\n for i in range(n):\n cur = vals[i]\n nxt = vals[(i + 1) % n]\n if cur <= insertVal <= nxt:\n idx = i + 1\n break\n if cur > nxt and (insertVal >= cur or insertVal <= nxt):\n idx = i + 1\n break\n if idx is None:\n idx = 1\n new_vals = vals[:idx] + [insertVal] + vals[idx:]\n dummy = ListNode(0)\n cur = dummy\n for v in new_vals:\n cur.next = ListNode(v)\n cur = cur.next\n return dummy.next\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc Insert(head *ListNode, insertVal int) *ListNode {\n return nil\n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def insert(self, head, insertVal: int):\n pass\n", "cpp": "/*\nDefinition for singly-linked list.\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* insert(ListNode* head, int insertVal) {\n return nullptr;\n }\n};"}, "fn": "insert", "params": [{"name": "head", "type": "list_node"}, {"name": "insertVal", "type": "int"}], "outputType": "list_node", "tests": [["[3,4,1]", "2"], ["[]", "1"], ["[1]", "0"], ["[1]", "2"], ["[3,3,3]", "0"], ["[3,3,3]", "3"], ["[1,2,3,4,5]", "0"], ["[1,2,3,4,5]", "6"], ["[1,2,3,4,5]", "3"], ["[5,1,2,3,4]", "0"], ["[5,1,2,3,4]", "6"], ["[2,2,2,1,2]", "2"], ["[1,3,5]", "4"], ["[1,3,5]", "0"], ["[1,3,5]", "6"], ["[3,5,1]", "4"], ["[3,5,1]", "2"], ["[1,1,1,1]", "1"], ["[2,3,4,1]", "1"], ["[2,3,4,1]", "5"], ["[10,5,6,7,8,9]", "4"], ["[10,5,6,7,8,9]", "11"], ["[-5,-3,0,2]", "-4"], ["[-5,-3,0,2]", "3"], ["[1,2]", "1"], ["[4,1,2,3]", "0"], ["[4,1,2,3]", "4"], ["[7,7,7,8,9,1,2]", "7"]], "expected": [[3, 4, 1, 2], [1], [1, 0], [1, 2], [3, 0, 3, 3], [3, 3, 3, 3], [1, 2, 3, 4, 5, 0], [1, 2, 3, 4, 5, 6], [1, 2, 3, 3, 4, 5], [5, 0, 1, 2, 3, 4], [5, 6, 1, 2, 3, 4], [2, 2, 2, 2, 1, 2], [1, 3, 4, 5], [1, 3, 5, 0], [1, 3, 5, 6], [3, 4, 5, 1], [3, 5, 1, 2], [1, 1, 1, 1, 1], [2, 3, 4, 1, 1], [2, 3, 4, 5, 1], [10, 4, 5, 6, 7, 8, 9], [10, 11, 5, 6, 7, 8, 9], [-5, -4, -3, 0, 2], [-5, -3, 0, 2, 3], [1, 1, 2], [4, 0, 1, 2, 3], [4, 4, 1, 2, 3], [7, 7, 7, 7, 8, 9, 1, 2]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "304", "slug": "insertion-sort-list", "id": 304, "title": "Insertion Sort List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/insertion-sort-list/", "examples": [{"input": "head = [4,2,1,3]", "output": "[1,2,3,4]", "explanation": "Inserting 2 before 4, then 1 at the front, then 3 before 4 gives sorted order."}, {"input": "head = [-1,5,3,4,0]", "output": "[-1,0,3,4,5]", "explanation": "Each value is relocated into the growing sorted prefix."}], "hints": ["Keep a dummy head for the sorted prefix so front insertions need no special case.", "For each input node, scan from the dummy until the next value exceeds it.", "Splice the node in; because the prefix is sorted, the scan can stop early."], "statement": "Sort a singly linked list using insertion sort and return the head of the ordered list.\n\nInsertion sort builds the answer one element at a time: take the next input node, find where it belongs among the already sorted prefix, and splice it in. Repeat until no input nodes remain.\n\n**Constraints:**\n- The list holds between 1 and 5000 nodes.\n- `-5000 <= Node.val <= 5000`\n", "solution": "## Approach\n\nMaintain a dummy-headed sorted prefix. Repeatedly detach the next input node and walk the prefix until the following value would exceed it, then splice the node there. Because the prefix stays sorted, each insertion lands in the correct spot.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) in the worst case, where n is the list length. Each insertion scans the sorted prefix.\n- **Space Complexity:** O(1) extra, rewiring nodes in place.\n\n## Implementation\n\n```python\nclass Solution:\n def insertionSortList(self, head):\n dummy = ListNode(-1)\n cur = head\n while cur:\n nxt = cur.next\n p = dummy\n while p.next and p.next.val < cur.val:\n p = p.next\n cur.next = p.next\n p.next = cur\n cur = nxt\n return dummy.next\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc InsertionSortList(head *ListNode) *ListNode {\n \n}", "python": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def insertionSortList(self, head):\n pass", "cpp": "/*\nDefinition for singly-linked list.\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* insertionSortList(ListNode* head) {\n \n }\n};"}, "fn": "insertionSortList", "params": [{"name": "head", "type": "list_node"}], "outputType": "list_node", "tests": [["[4,2,1,3]"], ["[-1,5,3,4,0]"], ["[1]"], ["[2,1]"], ["[1,2,3]"], ["[3,2,1]"], ["[1,1,1]"], ["[5,4,3,2,1]"], ["[1,2,3,4,5]"], ["[0]"], ["[-1,-2,-3]"], ["[3,1,2]"], ["[2,3,1]"], ["[4,2,1,3,5,0]"], ["[10,9,8,7,6,5,4,3,2,1]"], ["[1,3,2,4,5]"], ["[5,1,4,2,3]"], ["[0,0,0,1]"], ["[1,0,0,0]"], ["[-5000,5000,0]"], ["[2,2,1,1]"], ["[7,3,9,1,5]"], ["[100,50,75,25]"], ["[1,5,3,4,2,6]"], ["[9,8]"], ["[4,4,4,4]"], ["[6,5,3,1,8,7,2,4]"], ["[-3,0,3,-2,2]"]], "expected": [[1, 2, 3, 4], [-1, 0, 3, 4, 5], [1], [1, 2], [1, 2, 3], [1, 2, 3], [1, 1, 1], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [0], [-3, -2, -1], [1, 2, 3], [1, 2, 3], [0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [0, 0, 0, 1], [0, 0, 0, 1], [-5000, 0, 5000], [1, 1, 2, 2], [1, 3, 5, 7, 9], [25, 50, 75, 100], [1, 2, 3, 4, 5, 6], [8, 9], [4, 4, 4, 4], [1, 2, 3, 4, 5, 6, 7, 8], [-3, -2, 0, 2, 3]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "229", "slug": "integer-break", "id": 229, "title": "Integer Break", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/integer-break/", "examples": [{"input": "n = 2", "output": "1", "explanation": "2 = 1 + 1, 1 \u00d7 1 = 1."}, {"input": "n = 10", "output": "36", "explanation": "10 = 3 + 3 + 4, 3 \u00d7 3 \u00d7 4 = 36."}], "hints": ["There is a simple O(n) solution to this problem.", "You may check the breaking results of n ranging from 7 to 10 to discover the regularities."], "statement": "Take an integer `n` and express it as a sum of `k` positive integers with `k >= 2`. Among all such decompositions, make the product of the parts as large as possible.\n\nReturn that largest attainable product.\n\n**Constraints:**\n- 2 \u2264 n \u2264 58\n", "solution": "## Approach\n\nUse 1D dynamic programming. Let `dp[i]` be the maximum product obtainable by breaking `i` into a sum of at least two positive integers. Base case: `dp[1] = 1`. For each `i` from 2 to `n`, pick a first part `j` (1 <= j < i). The remaining value `i - j` can either be kept whole or broken further, so the best product using part `j` is `max(j, dp[j]) * (i - j)`. Take the maximum over all `j`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2), as for each of the n values we try up to n candidate first parts.\n- **Space Complexity:** O(n) for the dp array.\n\n## Implementation\n\n```python\nclass Solution:\n def integerBreak(self, n: int) -> int:\n dp = [0] * (n + 1)\n dp[1] = 1\n for i in range(2, n + 1):\n for j in range(1, i):\n dp[i] = max(dp[i], max(j, dp[j]) * (i - j))\n return dp[n]\n```", "starter": {"go": "package main\n\nfunc IntegerBreak(n int) int {\n \n}", "python": "class Solution:\n def integerBreak(self, n: int) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int integerBreak(int n) {\n \n }\n};"}, "fn": "integerBreak", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["2"], ["10"], ["3"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["11"], ["12"], ["20"], ["50"], ["57"], ["58"], ["13"], ["14"], ["15"], ["16"], ["17"], ["18"], ["19"], ["21"], ["22"], ["25"], ["30"], ["35"], ["40"], ["45"], ["55"]], "expected": [1, 36, 2, 4, 6, 9, 12, 18, 27, 54, 81, 1458, 86093442, 1162261467, 1549681956, 108, 162, 243, 324, 486, 729, 972, 2187, 2916, 8748, 59049, 354294, 2125764, 14348907, 516560652], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "472", "slug": "integer-replacement", "id": 472, "title": "Integer Replacement", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/integer-replacement/", "examples": [{"explanation": "8 -> 4 -> 2 -> 1 uses three halvings.", "input": "n = 8", "output": "3"}, {"explanation": "7 -> 8 -> 4 -> 2 -> 1 beats going down first.", "input": "n = 7", "output": "4"}, {"explanation": "4 -> 2 -> 1.", "input": "n = 4", "output": "2"}], "hints": ["Halve every even value immediately.", "For odd values above 3, look at the lowest two bits: ...01 prefers decrement, ...11 prefers increment.", "Treat 3 as a special case where decrementing wins."], "statement": "Starting from a positive integer `n`, you may apply these moves: when the current value is even, halve it; when it is odd, either increment or decrement it by one. Count the fewest moves that reduce `n` to `1`.\n\nThe choice on odd values matters: sometimes going up first beats going down first, and the best local move depends on the lower bits.\n\n**Constraints:**\n- `1 <= n <= 2^31 - 1`\n\nCare is needed near the upper bound, where incrementing temporarily exceeds 32-bit range.\n", "solution": "## Approach\n\nHalve evens without choice. For an odd value, the two lowest bits decide: ending in `01` (or the special value 3) is best decreased so the result has more trailing zeros, while ending in `11` is best increased for the same reason. More trailing zeros mean more free halvings afterwards. Use a 64-bit variable so incrementing the maximum input does not overflow.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n) steps.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def integerReplacement(self, n: int) -> int:\n x = n\n steps = 0\n while x != 1:\n if x % 2 == 0:\n x //= 2\n elif x == 3 or x % 4 == 1:\n x -= 1\n else:\n x += 1\n steps += 1\n return steps\n```\n", "starter": {"go": "package main\n\nfunc IntegerReplacement(n int) int {\n return 0\n}", "python": "class Solution:\n def integerReplacement(self, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int integerReplacement(int n) {\n return 0;\n }\n};"}, "fn": "integerReplacement", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["8"], ["7"], ["4"], ["1"], ["2"], ["3"], ["5"], ["6"], ["9"], ["10"], ["11"], ["12"], ["15"], ["16"], ["17"], ["31"], ["32"], ["33"], ["100"], ["1000"], ["10000"], ["100000"], ["1000000"], ["2147483647"], ["2147483646"], ["2000000000"], ["123456789"], ["65535"], ["65536"], ["27"]], "expected": [3, 4, 2, 0, 1, 2, 3, 3, 4, 4, 5, 4, 5, 4, 5, 6, 5, 6, 8, 12, 16, 21, 24, 32, 32, 39, 37, 17, 16, 7], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "372", "slug": "integer-to-english-words", "id": 372, "title": "Integer to English Words", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/integer-to-english-words/", "examples": [{"input": "num = 123", "output": "\"One Hundred Twenty Three\"", "explanation": "123 reads as one hundred twenty three."}, {"input": "num = 12345", "output": "\"Twelve Thousand Three Hundred Forty Five\"", "explanation": "Split into 12 thousand and 345."}, {"input": "num = 0", "output": "\"Zero\"", "explanation": "Zero is a special case."}], "hints": ["Split the number into groups of three digits (thousands, millions, billions) and convert each group under 1000 separately.", "Handle zero alone as \"Zero\"; skip any three-digit group that equals zero so no extra scale word appears.", "Use word lists for 0-19 and tens (Twenty, Thirty, ...) plus \"Hundred\" for the sub-thousand helper."], "statement": "Convert a non-negative integer into its English words form.\n\nWrite `numberToWords(num)` that spells out `num` using words for each\nthree-digit block combined with scale names `Thousand`, `Million`, and\n`Billion`. A block that is zero is skipped (except when the whole number\nis zero, which is `\"Zero\"`). Separate words with single spaces and use no\nleading or trailing spaces.\n\n**Constraints:**\n- `0 <= num <= 2^31 - 1`\n", "solution": "## Approach\n\nBreak the number into billions, millions, thousands, and remainder blocks of three digits. Convert each non-zero block under 1000 with a helper that handles hundreds plus tens/units via lookup tables, then join the block with its scale word.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1) \u2014 at most 4 blocks of constant work.\n- **Space Complexity:** O(1) extra besides the output string.\n\n## Implementation\n\n```python\nclass Solution:\n def numberToWords(self, num: int) -> str:\n if num == 0:\n return \"Zero\"\n below20 = [\"\", \"One\", \"Two\", \"Three\", \"Four\", \"Five\", \"Six\", \"Seven\", \"Eight\", \"Nine\", \"Ten\", \"Eleven\", \"Twelve\", \"Thirteen\", \"Fourteen\", \"Fifteen\", \"Sixteen\", \"Seventeen\", \"Eighteen\", \"Nineteen\"]\n tens = [\"\", \"\", \"Twenty\", \"Thirty\", \"Forty\", \"Fifty\", \"Sixty\", \"Seventy\", \"Eighty\", \"Ninety\"]\n\n def helper(n: int) -> str:\n parts = []\n if n >= 100:\n parts.append(below20[n // 100] + \" Hundred\")\n n %= 100\n if n >= 20:\n parts.append(tens[n // 10] + (\"\" if n % 10 == 0 else \" \" + below20[n % 10]))\n elif n > 0:\n parts.append(below20[n])\n return \" \".join(parts)\n\n out = []\n for chunk, scale in ((num // 1000000000, \"Billion\"), ((num // 1000000) % 1000, \"Million\"), ((num // 1000) % 1000, \"Thousand\")):\n if chunk:\n out.append(helper(chunk) + \" \" + scale)\n if num % 1000:\n out.append(helper(num % 1000))\n return \" \".join(out)\n```\n", "starter": {"go": "package main\n\nfunc NumberToWords(num int) string {\n \n}", "python": "class Solution:\n def numberToWords(self, num: int) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string numberToWords(int num) {\n return \"\";\n }\n};"}, "fn": "numberToWords", "params": [{"name": "num", "type": "int"}], "outputType": "string", "tests": [["0"], ["5"], ["13"], ["20"], ["21"], ["58"], ["99"], ["100"], ["101"], ["110"], ["115"], ["123"], ["1000"], ["1001"], ["1010"], ["1100"], ["1234"], ["12345"], ["100000"], ["1000010"], ["1234567"], ["1000000"], ["10000000"], ["1000000000"], ["1234567891"], ["2147483647"], ["20"], ["10000"]], "expected": ["Zero", "Five", "Thirteen", "Twenty", "Twenty One", "Fifty Eight", "Ninety Nine", "One Hundred", "One Hundred One", "One Hundred Ten", "One Hundred Fifteen", "One Hundred Twenty Three", "One Thousand", "One Thousand One", "One Thousand Ten", "One Thousand One Hundred", "One Thousand Two Hundred Thirty Four", "Twelve Thousand Three Hundred Forty Five", "One Hundred Thousand", "One Million Ten", "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven", "One Million", "Ten Million", "One Billion", "One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One", "Two Billion One Hundred Forty Seven Million Four Hundred Eighty Three Thousand Six Hundred Forty Seven", "Twenty", "Ten Thousand"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "254", "slug": "integer-to-roman", "id": 254, "title": "Integer to Roman", "difficulty": "Medium", "category": "hash-table", "link": "https://leetcode.com/problems/integer-to-roman/", "examples": [{"input": "num = 3749", "output": "\"MMMDCCXLIX\"", "explanation": "3000 = MMM, 700 = DCC, 40 = XL, and 9 = IX."}, {"input": "num = 58", "output": "\"LVIII\"", "explanation": "50 = L, 5 = V, and 3 = III."}, {"input": "num = 1994", "output": "\"MCMXCIV\"", "explanation": "1000 = M, 900 = CM, 90 = XC, and 4 = IV."}], "hints": ["List the 13 values (including the six subtractive pairs) from largest to smallest and greedily take each while it fits.", "Because the table is fixed and tiny, the whole conversion is effectively constant time."], "statement": "Seven symbols form the basis of Roman numerals: `I` (1), `V` (5), `X` (10), `L` (50), `C` (100), `D` (500), and `M` (1000). Larger values are written from the biggest place value down to the smallest, using these composition rules:\n\n- Otherwise, repeatedly take the largest symbol value that fits into what remains, append its symbol, and subtract.\n- The amounts 4, 9, 40, 90, 400, and 900 use subtractive pairs instead: `IV`, `IX`, `XL`, `XC`, `CD`, and `CM`.\n- The symbols `I`, `X`, `C`, and `M` may repeat at most three times in a row; `V`, `L`, and `D` are never repeated.\n\nGiven an integer `num`, produce its Roman numeral string.\n\n**Constraints:**\n- `1 <= num <= 3999`\n", "solution": "## Approach\n\nPair each of the 13 usable values (the seven symbols plus the six subtractive forms) with its text, ordered from largest to smallest. Repeatedly append the biggest value that still fits and subtract it from the remainder until nothing is left. Greedy works here because every Roman value is a canonical building block of the ones below it.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(1), since `num <= 3999` bounds the output to at most 15 characters.\n- **Space Complexity:** O(1) besides the output string.\n\n## Implementation\n\n```python\nclass Solution:\n def intToRoman(self, num: int) -> str:\n table = [(1000, \"M\"), (900, \"CM\"), (500, \"D\"), (400, \"CD\"),\n (100, \"C\"), (90, \"XC\"), (50, \"L\"), (40, \"XL\"),\n (10, \"X\"), (9, \"IX\"), (5, \"V\"), (4, \"IV\"), (1, \"I\")]\n out = []\n for value, sym in table:\n while num >= value:\n out.append(sym)\n num -= value\n return \"\".join(out)\n```\n", "starter": {"go": "package main\n\nfunc IntToRoman(num int) string {\n \n}", "python": "class Solution:\n def intToRoman(self, num: int) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string intToRoman(int num) {\n return \"\";\n }\n};"}, "fn": "intToRoman", "params": [{"name": "num", "type": "int"}], "outputType": "string", "tests": [["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["9"], ["10"], ["11"], ["14"], ["19"], ["40"], ["44"], ["49"], ["50"], ["58"], ["90"], ["94"], ["99"], ["100"], ["400"], ["444"], ["500"], ["900"], ["999"], ["1000"], ["1994"], ["2026"], ["3000"], ["3749"], ["3999"]], "expected": ["I", "II", "III", "IV", "V", "VI", "IX", "X", "XI", "XIV", "XIX", "XL", "XLIV", "XLIX", "L", "LVIII", "XC", "XCIV", "XCIX", "C", "CD", "CDXLIV", "D", "CM", "CMXCIX", "M", "MCMXCIV", "MMXXVI", "MMM", "MMMDCCXLIX", "MMMCMXCIX"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "132", "slug": "interleaving-string", "id": 132, "title": "Interleaving String", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/interleaving-string/", "examples": [{"input": "s1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbcbcac\"", "output": "true", "explanation": "\"aadbbcbcac\" can be formed by interleaving the characters of \"aabcc\" and \"dbbca\" in order."}, {"input": "s1 = \"aabcc\", s2 = \"dbbca\", s3 = \"aadbbbaccc\"", "output": "false", "explanation": "\"aadbbbaccc\" cannot be formed by interleaving \"aabcc\" and \"dbbca\"."}, {"input": "s1 = \"\", s2 = \"\", s3 = \"\"", "output": "true", "explanation": "Empty strings can always be interleaved to form an empty string."}], "hints": ["First reject inputs whose lengths do not add up.", "Use dp[j] to represent whether prefixes of s1 and s2 can form the corresponding prefix of s3."], "statement": "Given strings `s1`, `s2`, and `s3`, return `true` if `s3` is formed by interleaving\n`s1` and `s2`, or `false` otherwise.\n\nAn interleaving uses every character from `s1` and `s2` exactly once while preserving\nthe left-to-right order of characters from each source string.\n\n**Constraints:**\n- `0 <= s1.length, s2.length <= 100`\n- `0 <= s3.length <= 200`\n- All strings contain only lowercase English letters.\n", "solution": "## Approach\n\nFirst reject any input whose lengths cannot add up. Let `possible[j]` indicate whether\nthe current prefix of `s1` together with the first `j` characters of `s2` forms the\ncorresponding prefix of `s3`. Each state can consume its next character from either\nsource while preserving both source orders.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n), where `m = len(s1)` and `n = len(s2)`.\n- **Space Complexity:** O(n).\n\n## Implementation\n\n```python\nclass Solution:\n def isInterleave(self, s1: str, s2: str, s3: str) -> bool:\n if len(s1) + len(s2) != len(s3):\n return False\n\n possible = [False] * (len(s2) + 1)\n possible[0] = True\n for j in range(1, len(s2) + 1):\n possible[j] = possible[j - 1] and s2[j - 1] == s3[j - 1]\n for i in range(1, len(s1) + 1):\n possible[0] = possible[0] and s1[i - 1] == s3[i - 1]\n for j in range(1, len(s2) + 1):\n next_char = s3[i + j - 1]\n possible[j] = (\n possible[j] and s1[i - 1] == next_char\n ) or (\n possible[j - 1] and s2[j - 1] == next_char\n )\n return possible[-1]\n```\n", "starter": {"go": "package main\n\nfunc IsInterleave(s1 string, s2 string, s3 string) bool {\n return false\n}", "python": "class Solution:\n def isInterleave(self, s1: str, s2: str, s3: str) -> bool:\n return False\n", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isInterleave(string s1, string s2, string s3) {\n return false;\n }\n};"}, "fn": "isInterleave", "params": [{"name": "s1", "type": "string"}, {"name": "s2", "type": "string"}, {"name": "s3", "type": "string"}], "outputType": "boolean", "tests": [["aabcc", "dbbca", "aadbbcbcac"], ["aabcc", "dbbca", "aadbbbaccc"], ["", "", ""], ["", "a", "a"], ["a", "", "a"], ["", "a", "b"], ["a", "b", "ab"], ["a", "b", "ba"], ["a", "b", "aa"], ["a", "b", "a"], ["ab", "cd", "acbd"], ["ab", "cd", "cadb"], ["ab", "cd", "adbc"], ["ab", "cd", "abcd"], ["ab", "cd", "cdab"], ["abc", "def", "adbcef"], ["abc", "def", "abcdef"], ["abc", "def", "defabc"], ["abc", "def", "abdfec"], ["abc", "def", "abcdefg"], ["aa", "aa", "aaaa"], ["aa", "ab", "aaba"], ["aa", "ab", "abaa"], ["aa", "ab", "abba"], ["aaaa", "bbbb", "abababab"], ["aaaa", "bbbb", "bbbbaaaa"], ["aaaa", "bbbb", "aaaabbbb"], ["aaaa", "bbbb", "aaabbbba"], ["abcabc", "xyzxyz", "axbyczaxbycz"], ["abcabc", "xyzxyz", "xyzxyzabcabc"], ["abcabc", "xyzxyz", "axbyczaxybcz"], ["ace", "bdf", "abcdef"], ["ace", "bdf", "abcedf"], ["ace", "bdf", "abcfde"], ["cat", "dog", "cdaotg"], ["cat", "dog", "dogcat"], ["cat", "dog", "coatdg"], ["xxy", "xxz", "xxxxyz"], ["xxy", "xxz", "xxxxzy"], ["xxy", "xxz", "xxxyxz"], ["aacaac", "aacaaeaac", "aacaaeaaeaacaac"], ["aacaac", "aacaaeaac", "aacaaeaaaacaac"], ["abcde", "fghij", "afbgchdiej"], ["abcde", "fghij", "fghijabcde"], ["abcde", "fghij", "afbgchdije"], ["mnop", "qrst", "mqnropstu"], ["mnop", "qrst", "mqnrospt"], ["mnop", "qrst", "qrstmnop"], ["hello", "world", "hweolrllod"], ["hello", "world", "worldhello"], ["hello", "world", "hweolrldlo"], ["aaaaab", "aaaaac", "aaaaaaaaaabc"], ["aaaaab", "aaaaac", "aaaaaaaaaacb"], ["qwerty", "asdfgh", "qawsedrftgyhx"], ["qwerty", "asdfgh", "qawsedrftgyh"], ["qwerty", "asdfgh", "asdfghqwerty"], ["@javascript:'a'.repeat(100)", "@javascript:'b'.repeat(100)", "@javascript:'ab'.repeat(100)"], ["@javascript:'a'.repeat(100)", "@javascript:'b'.repeat(100)", "@javascript:'ab'.repeat(99)+'a'"]], "expected": [true, false, true, true, true, false, true, true, false, false, true, true, false, true, true, true, true, true, false, false, true, true, true, false, true, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, false, false, true, true, true, false, true, true, true, true, true, true, true, false, true, true, true, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "430", "slug": "intersection-of-two-arrays-ii", "id": 430, "title": "Intersection of Two Arrays II", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/intersection-of-two-arrays-ii/", "examples": [{"input": "nums1 = [1,2,2,1], nums2 = [2,2]", "output": "[2,2]", "explanation": "Two copies of 2 exist on both sides, so both are kept."}, {"input": "nums1 = [4,9,5], nums2 = [9,4,9,8,4]", "output": "[4,9]", "explanation": "One shared copy of 4 and one of 9 survive; order is free."}], "hints": ["Count occurrences of the first list in a frequency map.", "Walk the second list, emitting a value while its remaining count is positive and decrementing."], "statement": "You receive two integer lists `nums1` and `nums2`. Return the values they share, respecting repetition counts: each distinct value should appear in the answer as many times as it appears in both lists simultaneously (the minimum of its two frequencies).\n\nThe order of the answer carries no meaning.\n\n**Constraints:**\n- `1 <= nums1.length, nums2.length <= 1000`\n- `0 <= nums1[i], nums2[i] <= 1000`\n\n**Follow up:** Sort both lists first and walk them with two pointers to use less extra memory; for already-sorted inputs this needs only output space.\n", "solution": "## Approach\n\nTally the first list's frequencies in a map. Then stream through the second list: whenever the current value still has a positive remaining count, append it to the answer and decrement the count. This keeps exactly the shared multiplicity of every value while preserving linear time.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + m), where n and m are the list lengths.\n- **Space Complexity:** O(min(n, m)) for the frequency table (count the shorter list in practice).\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import Counter\nclass Solution:\n def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:\n count = Counter(nums1)\n out = []\n for x in nums2:\n if count.get(x, 0) > 0:\n out.append(x)\n count[x] -= 1\n return out\n```\n", "starter": {"go": "package main\n\nfunc Intersect(nums1 []int, nums2 []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {\n return {};\n }\n};"}, "fn": "intersect", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}], "outputType": "int_array", "tests": [["[1,2,2,1]", "[2,2]"], ["[4,9,5]", "[9,4,9,8,4]"], ["[1]", "[1]"], ["[1]", "[2]"], ["[1,2,3]", "[4,5,6]"], ["[1,2,3]", "[1,2,3]"], ["[0,0,0]", "[0,0]"], ["[3,1,2]", "[1,1]"], ["[1,1,1,2,2]", "[1,1,2]"], ["[5,5,5]", "[5,5,5,5]"], ["[1,2,2,3,3,3]", "[2,2,3,3]"], ["[0]", "[0]"], ["[7,7,7]", "[7]"], ["[1,2,3,4]", "[3,4,5,6]"], ["[100,200,300]", "[300,300]"], ["[2,2,2]", "[2,2,2]"], ["[1,2,3,4,5]", "[6,7,8,9,10]"], ["[8,6,4,2]", "[2,4,6,8,10]"], ["[0,1000]", "[1000,0,0]"], ["[1,1,2,2,3,3]", "[1,2,3]"], ["[9,9,8,8]", "[9,8,9,8,9]"], ["[4,4,4,4]", "[4,4]"], ["[1,3,5]", "[2,4,6,1,3]"], ["[10,20,30,20,10]", "[20,20,10]"], ["[1,2]", "[1,2,1,2]"], ["[0,1,0,1]", "[0,0,1,1,1]"]], "expected": [[2, 2], [4, 9], [1], [], [], [1, 2, 3], [0, 0], [1], [1, 1, 2], [5, 5, 5], [2, 2, 3, 3], [0], [7], [3, 4], [300], [2, 2, 2], [], [2, 4, 6, 8], [0, 1000], [1, 2, 3], [8, 8, 9, 9], [4, 4], [1, 3], [10, 20, 20], [1, 2], [0, 0, 1, 1]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "429", "slug": "intersection-of-two-arrays", "id": 429, "title": "Intersection of Two Arrays", "difficulty": "Easy", "category": "array", "link": "https://leetcode.com/problems/intersection-of-two-arrays/", "examples": [{"input": "nums1 = [1,2,2,1], nums2 = [2,2]", "output": "[2]", "explanation": "2 is the only value present on both sides."}, {"input": "nums1 = [4,9,5], nums2 = [9,4,9,8,4]", "output": "[9,4]", "explanation": "4 and 9 are shared; any order of them is accepted."}], "hints": ["Load one list into a hash set for O(1) membership tests.", "Insert matches into a second set to suppress duplicates, then return them."], "statement": "You receive two integer lists `nums1` and `nums2`. Collect every value that occurs in both lists, keeping each shared value exactly once.\n\nThe order of the answer carries no meaning \u2014 any arrangement of the shared values is accepted.\n\n**Constraints:**\n- `1 <= nums1.length, nums2.length <= 1000`\n- `0 <= nums1[i], nums2[i] <= 1000`\n", "solution": "## Approach\n\nPlace all values of the first list into a hash set, then scan the second list and collect hits into another set that automatically drops repeats. Converting the survivor set to an array finishes the task. Set lookups keep the total work linear in the combined input size.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + m), where n and m are the list lengths.\n- **Space Complexity:** O(n) for the lookup set.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:\n have = set(nums1)\n return list({x for x in nums2 if x in have})\n```\n", "starter": {"go": "package main\n\nfunc Intersection(nums1 []int, nums2 []int) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:\n return []\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {\n return {};\n }\n};"}, "fn": "intersection", "params": [{"name": "nums1", "type": "int_array"}, {"name": "nums2", "type": "int_array"}], "outputType": "int_array", "tests": [["[1,2,2,1]", "[2,2]"], ["[4,9,5]", "[9,4,9,8,4]"], ["[1]", "[1]"], ["[1]", "[2]"], ["[1,2,3]", "[4,5,6]"], ["[1,2,3]", "[1,2,3]"], ["[0,0,0]", "[0]"], ["[1000]", "[1000]"], ["[1,2]", "[2,1]"], ["[3,1,2]", "[1,1]"], ["[5,5,5,5]", "[5,5]"], ["[1,3,5,7]", "[2,4,6,8]"], ["[0,1,2,3,4,5]", "[5,4,3]"], ["[9,8,7]", "[7,8,9,10]"], ["[1,2,3,4,5,6,7,8,9,10]", "[10,9,8]"], ["[42]", "[42,42,42]"], ["[1,2,2,3,3,3]", "[2,3,4]"], ["[0]", "[1]"], ["[7,7,7]", "[8,8,8]"], ["[1,2,3,4]", "[3,4,5,6]"], ["[100,200,300]", "[300,400]"], ["[2,2,2]", "[2,2,2]"], ["[1,2,3,4,5]", "[6,7,8,9,10]"], ["[8,6,4,2]", "[2,4,6,8,10]"], ["[0,1000]", "[1000,0]"], ["[11,22,33]", "[33,44]"]], "expected": [[2], [4, 9], [1], [], [], [1, 2, 3], [0], [1000], [1, 2], [1], [5], [], [3, 4, 5], [7, 8, 9], [8, 9, 10], [42], [2, 3], [], [], [3, 4], [300], [2], [], [2, 4, 6, 8], [0, 1000], [33]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "313", "slug": "intersection-of-two-linked-lists", "id": 313, "title": "Intersection of Two Linked Lists", "difficulty": "Easy", "category": "linked-list", "link": "https://leetcode.com/problems/intersection-of-two-linked-lists/", "examples": [{"explanation": "Both lists end with 8 -> 4 -> 5, so the intersecting tail is [8,4,5].", "input": "headA = [4,1,8,4,5], headB = [5,6,1,8,4,5]", "output": "[8,4,5]"}, {"explanation": "Both lists end with 2 -> 4.", "input": "headA = [1,9,1,2,4], headB = [3,2,4]", "output": "[2,4]"}, {"explanation": "The endings differ, so there is no intersection (null, shown as []).", "input": "headA = [2,6,4], headB = [1,5]", "output": "[]"}], "hints": ["Walk to the end of each list to learn their lengths, then advance the longer one so both have the same remaining distance.", "Compare the remaining tails value by value; the first position where the rest matches is the start of the shared suffix."], "statement": "You are given the heads of two singly linked lists, `headA` and `headB`.\n\nIn the original setting the two lists join at some shared node. Because this offline judge builds each list separately, intersection is defined by values instead: the lists intersect when they end with the same non-empty run of values. That is, there are positions `i` in the first list and `j` in the second list such that the remaining tails are equal element by element.\n\nReturn the intersecting tail (the suffix starting at its first shared value), or null when the lists share no common ending values. Test data avoids coincidental single-value matches for non-intersecting cases, so a shared ending genuinely represents a meeting point.\n\n**Constraints:**\n- `0 <= number of nodes <= 10^4`\n- `0 <= Node.val <= 100`\n- Each list is acyclic.\n", "solution": "## Approach\n\nCollect both lists into arrays and walk backwards from the tails while the values agree. The number of matching steps is the length of the shared ending; rebuilding that suffix gives the intersecting tail. If nothing matches, the answer is null. Comparing from the back directly yields the longest common ending without extra alignment work.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m + n), where m and n are the list lengths.\n- **Space Complexity:** O(m + n) for the collected values and the rebuilt suffix.\n\n## Implementation\n\n```python\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def getIntersectionNode(self, headA, headB):\n a, b = [], []\n p = headA\n while p:\n a.append(p.val)\n p = p.next\n p = headB\n while p:\n b.append(p.val)\n p = p.next\n i, j = len(a) - 1, len(b) - 1\n match = 0\n while i >= 0 and j >= 0 and a[i] == b[j]:\n match += 1\n i -= 1\n j -= 1\n if match == 0:\n return None\n dummy = ListNode(0)\n cur = dummy\n for v in a[len(a) - match:]:\n cur.next = ListNode(v)\n cur = cur.next\n return dummy.next\n```\n", "starter": {"go": "package main\n\n/*\nDefinition for singly-linked list.\ntype ListNode struct {\n Val int\n Next *ListNode\n}\n*/\n\nfunc GetIntersectionNode(headA *ListNode, headB *ListNode) *ListNode {\n return nil\n}", "python": "# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\n\nclass Solution:\n def getIntersectionNode(self, headA, headB):\n pass\n", "cpp": "/*\nstruct ListNode {\n int val;\n ListNode *next;\n ListNode(): val(0), next(nullptr) {}\n ListNode(int x): val(x), next(nullptr) {}\n ListNode(int x, ListNode* next): val(x), next(next) {}\n};\n*/\nclass Solution {\npublic:\n ListNode* getIntersectionNode(ListNode* headA, ListNode* headB) {\n return nullptr;\n }\n};"}, "fn": "getIntersectionNode", "params": [{"name": "headA", "type": "list_node"}, {"name": "headB", "type": "list_node"}], "outputType": "list_node", "tests": [["[4,1,8,4,5]", "[5,6,1,8,4,5]"], ["[1,9,1,2,4]", "[3,2,4]"], ["[2,6,4]", "[1,5]"], ["[0,9,1,2,4]", "[3,2,4]"], ["[]", "[]"], ["[]", "[1,2]"], ["[1,2]", "[]"], ["[1]", "[1]"], ["[1]", "[2]"], ["[1,2,3]", "[1,2,3]"], ["[5,4,3,2,1]", "[9,8,2,1]"], ["[1,3,5,7,9]", "[2,4,5,7,9]"], ["[10,20,30]", "[40,50]"], ["[7,7,7]", "[7,7,7,7]"], ["[1,2]", "[3,4,5,1,2]"], ["[9,8,7,6]", "[1,8,7,6]"], ["[100]", "[0,100]"], ["[1,2,3,4]", "[5,6]"], ["[4,4,4]", "[4,4]"], ["[1,5,9]", "[2,5,9]"], ["[0]", "[1]"], ["[11,22]", "[33,44]"], ["[1,2,3,4,5]", "[6,7,4,5]"], ["[8,4,5]", "[5,6,1,8,4,5]"], ["[2,4]", "[1,9,1,2,4]"], ["[3,1,5,9]", "[7,1,5,9]"]], "expected": [[1, 8, 4, 5], [2, 4], null, [2, 4], null, null, null, [1], null, [1, 2, 3], [2, 1], [5, 7, 9], null, [7, 7, 7], [1, 2], [8, 7, 6], [100], null, [4, 4], [5, 9], null, null, [4, 5], [8, 4, 5], [2, 4], [1, 5, 9]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "969", "slug": "interval-list-intersections", "id": 969, "title": "Interval List Intersections", "difficulty": "Medium", "category": "interval", "link": "https://leetcode.com/problems/interval-list-intersections/", "examples": [{"input": "firstList = [[0,2],[5,10],[13,23],[24,25]], secondList = [[1,5],[8,12],[15,24],[25,26]]", "output": "[[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]", "explanation": "Each overlapping pair contributes its shared segment; touching endpoints count as length-zero intersections."}, {"input": "firstList = [[1,3],[5,9]], secondList = []", "output": "[]", "explanation": "With one list empty there are no overlaps."}], "hints": ["Walk both sorted lists with two pointers, always advancing the interval that ends first.", "Two intervals [a,b] and [c,d] overlap exactly when max(a,c) <= min(b,d); that pair of extremes is the intersection.", "Each step emits at most one intersection, giving linear time."], "statement": "You are given two lists of closed intervals, `firstList` and `secondList`. Within each list the intervals are pairwise disjoint and sorted by start. Compute all pairwise intersections: for every `I` in the first list and `J` in the second list, if they share at least one point, include their overlap `[max(starts), min(ends)]` in the answer. Return the intersections sorted by start (the two-pointer scan naturally produces this order).\n\n**Constraints:**\n- `0 <= firstList.length, secondList.length <= 1000`\n- `firstList[i], secondList[i]` each hold `[start, end]` with `0 <= start <= end <= 10^9`.\n- Intervals inside each list are disjoint and sorted.\n", "solution": "## Approach\n\nSweep both sorted lists with indices i and j. For the current pair, the overlap candidate is [max of starts, min of ends]; keep it when the start does not pass the end. Then advance the interval finishing first, since it cannot overlap anything later in the other list. Each interval is consumed once.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m + n), where m and n are the list lengths.\n- **Space Complexity:** O(m + n) for the output in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:\n out = []\n i = j = 0\n while i < len(firstList) and j < len(secondList):\n lo = max(firstList[i][0], secondList[j][0])\n hi = min(firstList[i][1], secondList[j][1])\n if lo <= hi:\n out.append([lo, hi])\n if firstList[i][1] < secondList[j][1]:\n i += 1\n else:\n j += 1\n return out\n```\n", "starter": {"go": "package main\n\nfunc IntervalIntersection(firstList [][]int, secondList [][]int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> intervalIntersection(vector<vector<int>>& firstList, vector<vector<int>>& secondList) {\n return {};\n }\n};"}, "fn": "intervalIntersection", "params": [{"name": "firstList", "type": "int_array_2d"}, {"name": "secondList", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[0,2],[5,10],[13,23],[24,25]]", "[[1,5],[8,12],[15,24],[25,26]]"], ["[[1,3],[5,9]]", "[]"], ["[]", "[[1,3]]"], ["[]", "[]"], ["[[0,5]]", "[[0,5]]"], ["[[1,2]]", "[[3,4]]"], ["[[1,5]]", "[[2,3]]"], ["[[1,10]]", "[[2,3],[4,5],[6,7]]"], ["[[0,2],[3,5]]", "[[1,4]]"], ["[[1,3],[5,7]]", "[[2,6]]"], ["[[1,1],[3,3]]", "[[1,3]]"], ["[[0,10]]", "[[10,10]]"], ["[[5,10]]", "[[0,5]]"], ["[[1,4],[6,8]]", "[[0,2],[3,5],[7,9]]"], ["[[0,1],[2,3],[4,5]]", "[[1,2],[3,4]]"], ["[[1,7]]", "[[3,10]]"], ["[[0,2],[5,10]]", "[[1,1],[8,8]]"], ["[[3,5],[9,20]]", "[[1,3],[4,6],[15,25]]"], ["[[1,2],[3,4],[5,6]]", "[[2,3],[4,5]]"], ["[[0,100]]", "[[10,20],[30,40],[50,60]]"], ["[[1,5],[10,15]]", "[[5,10]]"], ["[[2,4]]", "[[0,10]]"], ["[[1,3]]", "[[1,3]]"], ["[[0,2]]", "[[2,4]]"], ["[[8,15]]", "[[2,6],[14,20]]"], ["[[1,2],[5,6],[9,10]]", "[[0,11]]"], ["[[0,5],[10,15],[20,25]]", "[[3,12],[18,22]]"], ["[[1,4]]", "[[2,3]]"]], "expected": [[[1, 2], [5, 5], [8, 10], [15, 23], [24, 24], [25, 25]], [], [], [], [[0, 5]], [], [[2, 3]], [[2, 3], [4, 5], [6, 7]], [[1, 2], [3, 4]], [[2, 3], [5, 6]], [[1, 1], [3, 3]], [[10, 10]], [[5, 5]], [[1, 2], [3, 4], [7, 8]], [[1, 1], [2, 2], [3, 3], [4, 4]], [[3, 7]], [[1, 1], [8, 8]], [[3, 3], [4, 5], [15, 20]], [[2, 2], [3, 3], [4, 4], [5, 5]], [[10, 20], [30, 40], [50, 60]], [[5, 5], [10, 10]], [[2, 4]], [[1, 3]], [[2, 2]], [[14, 15]], [[1, 2], [5, 6], [9, 10]], [[3, 5], [10, 12], [20, 22]], [[2, 3]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "62", "slug": "invert-binary-tree", "id": 62, "title": "Invert/Flip Binary Tree", "difficulty": "Easy", "category": "tree", "link": "https://leetcode.com/problems/invert-binary-tree/", "examples": [{"input": "root = [4,2,7,1,3,6,9]", "output": "[4,7,2,9,6,3,1]", "explanation": "Inverting [4,2,7,1,3,6,9] produces [4,7,2,9,6,3,1].\n\n![Invert binary tree example](/api/problems/invert-binary-tree/asset/explanation1.png)"}, {"input": "root = [2,1,3]", "output": "[2,3,1]", "explanation": "Inverting [2,1,3] produces [2,3,1].\n\n![Invert binary tree example 2](/api/problems/invert-binary-tree/asset/explanation2.png)"}, {"input": "root = []", "output": "[]", "explanation": "Inverting an empty tree produces an empty tree."}], "hints": ["Swap left and right children for every node (mirror the tree) using recursion or BFS."], "statement": "Starting from the `root` of a binary tree, exchange every left and right child throughout the structure to create its mirror image, then return the `root` of the mirrored tree.\n\n**Constraints:**\n\n- The number of nodes in the tree is in the range [0, 100].\n- -100 \u2264 Node.val \u2264 100\n", "solution": "## Approach\n\nRecursively traverse the tree swapping the left and right children of each node. A null node returns null as the base case.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes in the tree.\n- **Space Complexity:** O(h), where h is the height of the tree (recursion stack depth).\n\n## Implementation\n\n```python\nfrom typing import Optional\nclass Solution:\n def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:\n if not root:\n return None\n root.left, root.right = root.right, root.left\n self.invertTree(root.left)\n self.invertTree(root.right)\n return root\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc InvertTree(root *TreeNode) *TreeNode {\n \n}", "python": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\n\nclass Solution:\n def invertTree(self, root):\n # TODO: return the root of the inverted tree\n pass\n", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* invertTree(TreeNode* root) {\n \n }\n};\n"}, "fn": "invertTree", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "tree_node", "tests": [["[4,2,7,1,3,6,9]"], ["[2,1,3]"], ["[]"], ["[1,null,2,null,3]"], ["[1,2,null,3]"], ["[0]"], ["[5,3,8,1,4,7,9]"], ["[1]"], ["[1,2]"], ["[1,null,2]"], ["[3,9,20,null,null,15,7]"], ["[1,2,3,4,5,6,7]"], ["[1,2,3,4,5]"], ["[10,5,-3,3,2,null,11,3,-2,null,1]"], ["[0,0,0]"], ["[-100,100]"], ["[100,-100]"], ["[2,null,3,null,4]"], ["[4,null,2,null,1]"], ["[7,7,7]"], ["[1,2,2,3,4,4,3]"], ["[10,5,15]"], ["[10,15,5]"], ["[8,4,12,2,6,10,14]"], ["[1,2,3,null,4,null,5]"], ["[-5,-3,-8,0,2]"], ["[50,null,60,null,70]"], ["[9,6,null,3,null,1]"], ["[2,1]"], ["[5,null,9,8,null,7]"], ["[3,1,2]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "754", "slug": "ip-to-cidr", "id": 754, "title": "IP to CIDR", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/ip-to-cidr/", "examples": [{"input": "ip = \"255.0.0.7\", n = 10", "output": "[\"255.0.0.7/32\",\"255.0.0.8/29\",\"255.0.0.16/32\"]", "explanation": "Sizes 1, 8, 1 cover ten addresses minimally."}, {"input": "ip = \"117.145.102.62\", n = 8", "output": "[\"117.145.102.62/31\",\"117.145.102.64/30\",\"117.145.102.68/31\"]", "explanation": "Sizes 2, 4, 2 cover eight addresses."}], "hints": ["Translate the dotted address into a 32-bit integer so alignment becomes arithmetic.", "From the current start, the biggest usable block is limited both by the lowest set bit of start and by the largest power of two fitting in the remainder.", "Emit that block, advance start by its size, and repeat until n reaches zero."], "statement": "An IPv4 address writes a 32-bit number as four decimal groups joined by dots. A CIDR block adds a slash and a prefix length, such as `255.0.0.8/29`, meaning all addresses sharing the first 29 bits with the base.\n\nYou are given a starting address `ip` and a count `n`. Cover exactly the `n` consecutive addresses from `ip` upward with as few CIDR blocks as possible, using no address outside the range.\n\nReturn the blocks as strings in increasing address order.\n\n**Constraints:**\n- `ip` is a valid IPv4 address.\n- Every address from `ip` through `ip + n - 1` is valid.\n- `1 <= n <= 1000`\n", "solution": "## Approach\n\nConvert the dotted address to a 32-bit integer. While addresses remain, compute two limits: the alignment limit from the lowest set bit of the current start, and the size limit from the largest power of two not exceeding the remainder. Take the smaller as the next block size, translate it to a prefix length, emit the block, and advance. Both limits guarantee validity and greediness yields the fewest blocks.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) in the worst case, but at most O(log MaxIP + number of blocks) steps since each block at least halves alignment or remainder effects; with n <= 1000 it is tiny.\n- **Space Complexity:** O(1) besides the output list.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def ipToCIDR(self, ip: str, n: int) -> List[str]:\n parts = list(map(int, ip.split('.')))\n start = (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]\n ans = []\n def to_ip(v):\n return f\"{(v >> 24) & 255}.{(v >> 16) & 255}.{(v >> 8) & 255}.{v & 255}\"\n while n > 0:\n low = start & -start if start != 0 else 1 << 32\n mx = 1 << (n.bit_length() - 1)\n step = low if low < mx else mx\n import math\n prefix = 32 - (step.bit_length() - 1)\n ans.append(f\"{to_ip(start)}/{prefix}\")\n start += step\n n -= step\n return ans\n```\n", "starter": {"go": "package main\n\nfunc IpToCIDR(ip string, n int) []string {\n return []string{}\n}", "python": "from typing import List\nclass Solution:\n def ipToCIDR(self, ip: str, n: int) -> List[str]:\n return []", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> ipToCIDR(string ip, int n) {\n return {};\n }\n};"}, "fn": "ipToCIDR", "params": [{"name": "ip", "type": "string"}, {"name": "n", "type": "int"}], "outputType": "string_list", "tests": [["255.0.0.7", "10"], ["117.145.102.62", "8"], ["0.0.0.0", "1"], ["0.0.0.0", "2"], ["0.0.0.0", "4"], ["0.0.0.0", "8"], ["192.168.1.0", "16"], ["10.0.0.1", "1"], ["10.0.0.1", "2"], ["10.0.0.0", "4"], ["1.1.1.1", "5"], ["255.255.255.255", "1"], ["0.0.0.1", "3"], ["192.168.0.0", "32"], ["10.10.10.10", "6"], ["172.16.0.5", "11"], ["8.8.8.8", "8"], ["1.2.3.4", "100"], ["100.64.0.0", "64"], ["0.0.0.0", "1000"], ["192.0.2.1", "7"], ["203.0.113.0", "24"], ["10.1.2.3", "13"], ["11.22.33.44", "9"], ["5.6.7.8", "16"], ["127.0.0.1", "4"], ["192.168.100.200", "20"], ["9.9.9.0", "256"]], "expected": [["255.0.0.7/32", "255.0.0.8/29", "255.0.0.16/32"], ["117.145.102.62/31", "117.145.102.64/30", "117.145.102.68/31"], ["0.0.0.0/32"], ["0.0.0.0/31"], ["0.0.0.0/30"], ["0.0.0.0/29"], ["192.168.1.0/28"], ["10.0.0.1/32"], ["10.0.0.1/32", "10.0.0.2/32"], ["10.0.0.0/30"], ["1.1.1.1/32", "1.1.1.2/31", "1.1.1.4/31"], ["255.255.255.255/32"], ["0.0.0.1/32", "0.0.0.2/31"], ["192.168.0.0/27"], ["10.10.10.10/31", "10.10.10.12/30"], ["172.16.0.5/32", "172.16.0.6/31", "172.16.0.8/29"], ["8.8.8.8/29"], ["1.2.3.4/30", "1.2.3.8/29", "1.2.3.16/28", "1.2.3.32/27", "1.2.3.64/27", "1.2.3.96/29"], ["100.64.0.0/26"], ["0.0.0.0/23", "0.0.2.0/24", "0.0.3.0/25", "0.0.3.128/26", "0.0.3.192/27", "0.0.3.224/29"], ["192.0.2.1/32", "192.0.2.2/31", "192.0.2.4/30"], ["203.0.113.0/28", "203.0.113.16/29"], ["10.1.2.3/32", "10.1.2.4/30", "10.1.2.8/29"], ["11.22.33.44/30", "11.22.33.48/30", "11.22.33.52/32"], ["5.6.7.8/29", "5.6.7.16/29"], ["127.0.0.1/32", "127.0.0.2/31", "127.0.0.4/32"], ["192.168.100.200/29", "192.168.100.208/29", "192.168.100.216/30"], ["9.9.9.0/24"]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "206", "slug": "ipo", "id": 206, "title": "IPO", "difficulty": "Hard", "category": "heap", "link": "https://leetcode.com/problems/ipo/", "examples": [{"input": "k = 2, w = 0, profits = [1,2,3], capital = [0,1,1]", "output": "4", "explanation": "Since your initial capital is 0, you can only start the project indexed 0."}, {"input": "k = 3, w = 0, profits = [1,2,3], capital = [0,1,2]", "output": "6"}], "hints": ["At each step you may only start the affordable project with the largest profit.", "Sort projects by required capital and sweep affordable ones into a max-heap of profits.", "Reach into the heap up to k times; stop early when nothing is affordable."], "statement": "A firm wants to grow its funds before going public by completing selected ventures. It can complete no more than `k` different ventures.\n\nThere are `n` candidate ventures, where venture `i` yields a net gain of `profits[i]` and requires holding at least `capital[i]` before it may begin.\n\nYou begin with `w` in capital. Completing a venture adds its gain to your holdings.\n\nChoose up to `k` different ventures in a feasible sequence to leave your holdings as large as possible, and return that final holding amount.\n\nThe result is guaranteed to fit in a 32-bit signed integer.\n\n**Constraints:**\n\n- `1 <= k <= 10^5`\n- `0 <= w <= 10^9`\n- `n == profits.length`\n- `n == capital.length`\n- `1 <= n <= 10^5`\n- `0 <= profits[i] <= 10^4`\n- `0 <= capital[i] <= 10^9`\n", "solution": "## Approach\n\nSort projects by required capital and use a max-heap of profits. Do up to `k` rounds: push every affordable project into the heap, then take the most profitable one and add it to the current capital. Stop early if no project is affordable.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n log n + k log n), where n is the number of projects. Sorting costs O(n log n) and each heap operation costs O(log n).\n- **Space Complexity:** O(n) for the sorted indices and the heap.\n\n## Implementation\n\n```python\nimport heapq\nclass Solution:\n def findMaximizedCapital(self, k: int, w: int, profits: list[int], capital: list[int]) -> int:\n order = sorted(range(len(profits)), key=lambda i: capital[i])\n heap = []\n i = 0\n cur = w\n for _ in range(k):\n while i < len(order) and capital[order[i]] <= cur:\n heapq.heappush(heap, -profits[order[i]])\n i += 1\n if not heap:\n break\n cur += -heapq.heappop(heap)\n return cur\n```\n", "starter": {"go": "package main\n\nfunc FindMaximizedCapital(k int, w int, profits []int, capital []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findMaximizedCapital(self, k: int, w: int, profits: List[int], capital: List[int]) -> int:\n ", "cpp": "#include <vector>\n#include <queue>\nusing namespace std;\n\nclass Solution {\npublic:\n int findMaximizedCapital(int k, int w, vector<int>& profits, vector<int>& capital) {\n \n }\n};"}, "fn": "findMaximizedCapital", "params": [{"name": "k", "type": "int"}, {"name": "w", "type": "int"}, {"name": "profits", "type": "int_array"}, {"name": "capital", "type": "int_array"}], "outputType": "int", "tests": [["2", "0", "[1,2,3]", "[0,1,1]"], ["3", "0", "[1,2,3]", "[0,1,2]"], ["1", "2", "[1,2,3]", "[1,1,2]"], ["2", "0", "[1,2,3]", "[0,9,9]"], ["1", "0", "[5]", "[0]"], ["1", "0", "[5]", "[1]"], ["1", "100", "[1,2,3]", "[0,0,0]"], ["3", "0", "[1,2,3]", "[3,3,3]"], ["5", "1", "[2,4,6,8,10]", "[0,1,2,3,4]"], ["4", "1", "[1,1,1,1]", "[100,100,100,100]"], ["20", "10", "[5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]", "[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]"], ["3", "5", "[10,20,30,40]", "[1,2,3,4]"], ["4", "5", "[10,20,30,40]", "[1,2,3,4]"], ["2", "5", "[1,3,5,7]", "[0,100,1000,10000]"], ["10", "0", "[1,1,1,1,1,1,1,1,1,1]", "[0,0,0,0,0,0,0,0,0,0]"], ["10", "0", "[1,1,1,1,1,1,1,1,1,1]", "[5,5,5,5,5,5,5,5,5,5]"], ["5", "1000000000", "[1,2,3,4,5]", "[1000000000,1000000000,1000000000,1000000000,1000000000]"], ["6", "0", "[6,5,4,3,2,1]", "[0,1,2,3,4,5]"], ["1", "0", "[0]", "[0]"], ["2", "1", "[5, 10]", "[0, 1]"], ["3", "0", "[4, 5, 6]", "[0, 0, 0]"], ["1", "0", "[10000]", "[1000000000]"], ["100", "0", "[1, 2]", "[0, 0]"], ["2", "3", "[2, 2, 2]", "[3, 3, 3]"], ["4", "0", "[0, 0, 5, 10]", "[0, 0, 0, 5]"], ["3", "10", "[1, 1, 100]", "[5, 10, 10]"], ["5", "0", "[3, 1, 2]", "[0, 0, 0]"], ["2", "100", "[10, 20]", "[0, 50]"], ["3", "7", "[6, 7, 8, 9]", "[7, 8, 9, 10]"], ["10", "5", "[100, 1, 1, 1, 1]", "[5, 5, 5, 5, 105]"]], "expected": [4, 6, 5, 1, 5, 0, 103, 0, 31, 1, 110, 95, 105, 6, 10, 0, 1000000015, 21, 0, 16, 15, 0, 3, 7, 15, 112, 6, 130, 30, 109], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "784", "slug": "is-graph-bipartite", "id": 784, "title": "Is Graph Bipartite?", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/is-graph-bipartite/", "examples": [{"input": "graph = [[1,2,3],[0,2],[0,1,3],[0,2]]", "output": "false", "explanation": "Three mutually linked vertices form a triangle."}, {"input": "graph = [[1,3],[0,2],[1,3],[0,2]]", "output": "true", "explanation": "Even and odd vertices can take opposite colors."}, {"input": "graph = [[1],[0]]", "output": "true", "explanation": "A single edge is two-colorable."}], "hints": ["Paint vertices with two colors using breadth-first search from every unvisited start.", "When you cross an edge, the neighbor must take the opposite color; a clash means failure.", "Disconnected pieces are handled by restarting the search at each uncolored vertex."], "statement": "An undirected network has `n` vertices numbered `0` through `n-1`. For each\nvertex `u`, the list `graph[u]` names all vertices directly linked to `u`\nby an edge. The network has no loops, no duplicate edges, and every link is\nlisted in both directions. It may split into several disconnected pieces.\n\nThe network is called two-colorable when every vertex can be painted with\none of two colors so that no edge joins two vertices of the same color.\nEquivalently, the vertices split into two groups with all edges crossing\nbetween the groups.\n\nGiven the adjacency lists, decide whether the network has this property.\n\n**Constraints:**\n- `graph.length == n`\n- `1 <= n <= 100`\n- `0 <= graph[u].length < n`\n- `0 <= graph[u][i] <= n - 1`\n- `graph[u]` holds no `u` itself and no repeats.\n- Whenever `v` appears in `graph[u]`, `u` appears in `graph[v]`.\n", "solution": "## Approach\n\nColor the network with two labels using breadth-first search. Start each\nunvisited component with label zero, then force every neighbor to carry the\nopposite label. If an edge ever connects two equally labeled vertices, the\ngraph cannot be split as required. Surviving all components without a clash\nconfirms two-colorability.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + e), where n is the vertex count and e the edge count.\n- **Space Complexity:** O(n) for colors and the queue.\n\n## Implementation\n\n```python\nfrom typing import List\nfrom collections import deque\n\n\nclass Solution:\n def isBipartite(self, graph: List[List[int]]) -> bool:\n n = len(graph)\n color = [-1] * n\n for start in range(n):\n if color[start] != -1:\n continue\n color[start] = 0\n queue = deque([start])\n while queue:\n u = queue.popleft()\n for v in graph[u]:\n if color[v] == -1:\n color[v] = 1 - color[u]\n queue.append(v)\n elif color[v] == color[u]:\n return False\n return True\n```\n", "starter": {"go": "package main\n\nfunc IsBipartite(graph [][]int) bool {\n return false\n}", "python": "from typing import List\nclass Solution:\n def isBipartite(self, graph: List[List[int]]) -> bool:\n return False\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isBipartite(vector<vector<int>>& graph) {\n return false;\n }\n};"}, "fn": "isBipartite", "params": [{"name": "graph", "type": "int_array_2d"}], "outputType": "boolean", "tests": [["[[1,2,3],[0,2],[0,1,3],[0,2]]"], ["[[1,3],[0,2],[1,3],[0,2]]"], ["[[1],[0]]"], ["[[]]"], ["[[1,2],[0,2],[0,1]]"], ["[[1],[0],[3],[2]]"], ["[[1,2],[0],[0]]"], ["[[1],[0],[3],[2],[5],[4]]"], ["[[1,2,3],[0],[0],[0]]"], ["[[1],[0],[3],[2],[5],[4],[7],[6]]"], ["[[2],[2],[0,1]]"], ["[[1,2],[0,2],[0,1],[4],[3]]"], ["[[1],[0],[3],[2],[6],[7],[4],[5]]"], ["[[3],[3],[3],[0,1,2]]"], ["[[1,4],[0,2],[1,3],[2,4],[0,3]]"], ["[[1,4],[0,2],[1,3],[2],[0]]"], ["[[1],[0,2],[1,3],[2]]"], ["[[2,3],[2,3],[0,1],[0,1]]"], ["[[1,2],[0,3],[0,3],[1,2]]"], ["[[1,2,4],[0,3],[0,3],[1,2],[0]]"], ["[[2],[3],[0],[1],[5],[4]]"], ["[[1],[0],[3],[2],[5],[4],[8],[8],[6,7]]"], ["[[4],[4],[4],[4],[0,1,2,3]]"], ["[[1],[0,2],[1,3],[2,4],[3,5],[4]]"], ["[[1,2],[0,2],[0,1],[4,5],[3,5],[3,4]]"], ["[[2,5],[2],[0,1],[4],[3],[0]]"], ["[[1],[0],[3,4],[2],[2]]"], ["[[3,4],[5],[5],[0],[0],[1,2]]"]], "expected": [false, true, true, true, false, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, false, true, true, true], "loose": false}