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": "748", "slug": "find-smallest-letter-greater-than-target", "id": 748, "title": "Find Smallest Letter Greater Than Target", "difficulty": "Easy", "category": "binary-search", "link": "https://leetcode.com/problems/find-smallest-letter-greater-than-target/", "examples": [{"input": "letters = [\"c\",\"f\",\"j\"], target = \"a\"", "output": "\"c\"", "explanation": "The smallest entry after \"a\" is \"c\"."}, {"input": "letters = [\"c\",\"f\",\"j\"], target = \"c\"", "output": "\"f\"", "explanation": "The smallest entry after \"c\" is \"f\"."}, {"input": "letters = [\"x\",\"x\",\"y\",\"y\"], target = \"z\"", "output": "\"x\"", "explanation": "Nothing exceeds \"z\", so wrap to the front."}], "hints": ["Because the list is sorted, a binary search for the first entry above the target runs in logarithmic time.", "Remember the wrap rule: when the target is at or past the last distinct entry, the answer is letters[0].", "Compare only the first character of each one-letter string."], "statement": "You are handed a list of lowercase letters sorted from smallest to largest, holding at least two different letters, plus a single target letter.\n\nScan the list and pick the smallest entry that comes strictly after the target in alphabetical order. If every entry is at or before the target, wrap around and return the first entry of the list.\n\nAdaptation for this judge: the original statement uses a character array and single characters; here each letter is a one-character string, so `letters` is a string array and both `target` and the answer are strings.\n\n**Constraints:**\n- `2 <= letters.length <= 10^4`\n- Each entry of `letters` is a lowercase English letter.\n- `letters` is sorted in non-decreasing order.\n- `letters` holds at least two distinct letters.\n- `target` is a lowercase English letter.\n", "solution": "## Approach\n\nWalk the sorted list from left to right and return the first entry whose single character exceeds the target character. If the scan finishes without a hit, every entry is at or below the target, so the wrap rule gives the front entry. A binary search for the insertion point works too, but the linear pass is already fast enough for the limits.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of letters. Each entry is inspected at most once.\n- **Space Complexity:** O(1) besides the input and output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def nextGreatestLetter(self, letters: List[str], target: str) -> str:\n for ch in letters:\n if ch > target:\n return ch\n return letters[0]\n```\n", "starter": {"go": "package main\n\nfunc NextGreatestLetter(letters []string, target string) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def nextGreatestLetter(self, letters: List[str], target: str) -> str:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string nextGreatestLetter(vector<string>& letters, string target) {\n return \"\";\n }\n};"}, "fn": "nextGreatestLetter", "params": [{"name": "letters", "type": "string_array"}, {"name": "target", "type": "string"}], "outputType": "string", "tests": [["['c', 'f', 'j']", "a"], ["['c', 'f', 'j']", "c"], ["['x', 'x', 'y', 'y']", "z"], ["['a', 'b']", "a"], ["['a', 'b']", "b"], ["['a', 'b', 'c']", "b"], ["['a', 'a', 'b', 'b']", "a"], ["['e', 'e', 'e', 'n', 'n']", "e"], ["['c', 'f', 'j']", "d"], ["['c', 'f', 'j']", "g"], ["['c', 'f', 'j']", "j"], ["['a', 'c', 'f', 'j']", "b"], ["['m', 'm', 'm', 'z']", "m"], ["['a', 'z']", "y"], ["['a', 'z']", "z"], ["['b', 'd', 'f', 'h']", "a"], ["['b', 'd', 'f', 'h']", "e"], ["['k', 'k', 'k', 'k', 'p']", "k"], ["['c', 'd', 'e']", "a"], ["['a', 'b', 'c', 'd']", "d"], ["['j', 'j', 'k']", "j"], ["['a', 'e', 'i', 'o', 'u']", "b"], ["['a', 'e', 'i', 'o', 'u']", "u"], ["['f', 'm', 't']", "s"], ["['a', 'b']", "z"], ["['d', 'h', 'z']", "c"], ["['p', 'q', 'r']", "p"], ["['w', 'x', 'y', 'z']", "v"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "277", "slug": "find-the-celebrity", "id": 277, "title": "Find the Celebrity", "difficulty": "Medium", "category": "graph", "link": "https://leetcode.com/problems/find-the-celebrity/", "examples": [{"input": "graph = [[1,1,0],[0,1,0],[1,1,1]]", "output": "1", "explanation": "Person 1 is known by 0 and 2 while knowing nobody else."}, {"input": "graph = [[1,0,1],[1,1,0],[0,1,1]]", "output": "-1", "explanation": "No person satisfies both celebrity conditions."}, {"input": "graph = [[1,0],[1,1]]", "output": "0", "explanation": "Person 0 knows nobody else and person 1 knows 0."}], "hints": ["The judge never reveals the matrix; only relation.knows(a, b) is available (at most 10 + 5*n calls).", "Eliminate non-candidates: if candidate knows i, candidate cannot be the celebrity so move to i.", "Verify the survivor knows nobody else and is known by everybody; else return -1."], "statement": "There are `n` people labeled `0` to `n - 1`. A celebrity knows nobody but is known by everybody else. Interact with the judge object `relation` \u2014 your code never receives the adjacency matrix:\n\n- `knows(a, b)` returns whether person `a` knows person `b`.\n\nImplement `findCelebrity(n, relation)` returning the celebrity label, or `-1` when none exists. First eliminate candidates in `O(n)` calls (if the candidate knows `i`, it cannot be the celebrity, so move to `i`), then verify the survivor knows nobody and is known by everybody. The judge counts your `knows` calls and reports Wrong Answer if you exceed **10 + 5*n** calls on a test case (an `O(n)` solution uses about `3n`).\n\nMethod names per language: Java `relation.knows(a, b)`, Python `relation.knows(a, b)`, C++ `relation.knows(a, b)`, C# `relation.Knows(a, b)`, Rust `relation.knows(a, b)`, Go `relation.Knows(a, b)`, TypeScript `relation.knows(a, b)`, PHP `$relation->knows($a, $b)`.\n\n**Constraints:**\n\n- `1 <= n <= 100`\n- The hidden matrix is `n x n` with entries `0` or `1` (diagonal entries are ignored).\n- At most `10 + 5*n` `knows` calls per test case.\n", "solution": "## Approach\n\nPick a candidate by scanning people: whenever the current candidate knows i, discard the candidate and take i. Then verify the survivor is known by all others and knows none of them; otherwise no celebrity exists.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findCelebrity(self, graph: List[List[int]]) -> int:\n n = len(graph)\n if n == 0:\n return -1\n cand = 0\n for i in range(1, n):\n if graph[cand][i] == 1:\n cand = i\n for i in range(n):\n if i == cand:\n continue\n if graph[cand][i] == 1:\n return -1\n if graph[i][cand] == 0:\n return -1\n return cand\n```\n", "starter": {"go": "package main\n\n// This is the knows API interface.\n// You should not implement it, or speculate about its implementation\n// type Relation struct { }\n// func (r *Relation) Knows(a int, b int) bool\n// Knows(a, b) tells whether person a knows person b; n is the party size.\n// Eliminate in O(n) calls, then verify the survivor.\n// The judge counts your calls: at most 10 + 5*n per test case.\nfunc FindCelebrity(n int, relation *Relation) int {\n return -1\n}", "python": "# The knows API is provided by the judge as `relation`.\n# You should not implement it, or speculate about its implementation\n# class Relation:\n# def knows(self, a: int, b: int) -> bool:\n# ...\n# knows(a, b) tells whether person a knows person b; n is the party size.\n# Eliminate in O(n) calls, then verify the survivor.\n# The judge counts your calls: at most 10 + 5*n per test case.\nfrom typing import List\nclass Solution:\n def findCelebrity(self, n: int, relation: 'Relation') -> int:\n return -1", "cpp": "/**\n * // This is the knows API interface.\n * // You should not implement it, or speculate about its implementation\n * class Relation {\n * public:\n * bool knows(int a, int b);\n * };\n * // knows(a, b) tells whether person a knows person b; n is the party size.\n * // Eliminate in O(n) calls, then verify the survivor.\n * // The judge counts your calls: at most 10 + 5*n per test case.\n */\nclass Solution {\npublic:\n int findCelebrity(int n, Relation& relation) {\n return -1;\n }\n};"}, "fn": "findCelebrity", "params": [{"name": "graph", "type": "int_array_2d"}], "outputType": "int", "tests": [["[[1,1,0],[0,1,0],[1,1,1]]"], ["[[1,0,1],[1,1,0],[0,1,1]]"], ["[[1,0],[1,1]]"], ["[[1,1],[0,1]]"], ["[[1]]"], ["[[1,1,1],[1,1,1],[1,1,1]]"], ["[[1,0,0],[0,1,0],[0,0,1]]"], ["[[1,0,0,0],[1,1,0,0],[1,1,1,0],[1,1,1,1]]"], ["[[1,1,1,0],[0,1,1,0],[0,0,1,0],[1,1,1,1]]"], ["[[1,0],[0,1]]"], ["[[1,1,0,0],[0,1,0,0],[1,1,1,0],[1,1,1,1]]"], ["[[1,0,1],[0,1,1],[0,0,1]]"], ["[[1,1],[1,1]]"], ["[[1,0,0],[1,1,1],[0,0,1]]"], ["[[1,0,0,0,0],[1,1,1,1,1],[1,0,1,0,0],[1,1,1,1,0],[1,1,0,0,1]]"], ["[[1,0,0],[1,1,0],[1,1,1]]"], ["[[1,1,1],[0,1,0],[0,1,1]]"], ["[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]"], ["[[1,1,1,1],[0,1,0,0],[0,0,1,0],[0,0,0,1]]"], ["[[1,0,0],[1,1,0],[1,0,1]]"], ["[[1,0,0,0,1],[0,1,0,0,1],[0,0,1,0,1],[0,0,0,1,1],[0,0,0,0,1]]"], ["[[1,1,0],[0,1,1],[0,0,1]]"], ["[[1,0,1,0],[0,1,1,0],[0,0,1,0],[0,0,1,1]]"], ["[[1,0,1,0],[1,1,0,1],[1,0,1,1],[1,1,0,1]]"], ["[[1,0,0],[0,1,1],[1,1,1]]"], ["[[1,1,0,0,0],[0,1,0,0,0],[0,1,1,0,0],[0,1,1,1,0],[0,1,1,1,1]]"], ["[[1,0,0,0],[1,1,1,1],[1,0,1,0],[1,0,0,1]]"], ["[[1,0,1],[1,1,1],[0,0,1]]"], ["@javascript:(()=>{const n=100,c=73;const g=Array.from({length:n},(_,i)=>Array.from({length:n},(_,j)=>i===j?1:(j===c?1:(i===c?0:(((i*31+j*17)%3===0)?1:0)))));return JSON.stringify(g);})()"], ["@javascript:JSON.stringify(Array.from({length:100},(_,i)=>Array.from({length:100},(_,j)=>i===j?1:0)))"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "619", "slug": "find-the-closest-palindrome", "id": 619, "title": "Find the Closest Palindrome", "difficulty": "Hard", "category": "math", "link": "https://leetcode.com/problems/find-the-closest-palindrome/", "examples": [{"input": "n = \"123\"", "output": "\"121\"", "explanation": "121 and 131 tie at distance 2; the smaller wins."}, {"input": "n = \"1\"", "output": "\"0\"", "explanation": "The nearest palindrome besides 1 itself is 0."}, {"input": "n = \"99\"", "output": "\"101\"", "explanation": "101 (gap 2) beats 88 (gap 11)."}], "hints": ["Mirror the first half onto the second half; also try the prefix plus and minus one before mirroring.", "Add the length-change candidates 10^k + 1 and 10^(k-1) - 1 for inputs like 1000 or 999.", "Drop the input itself from the candidates, then keep the smallest gap, preferring the smaller value on ties."], "statement": "Given a decimal string `n` (no leading zeros except `\"0\"` itself), return the closest palindromic integer different from `n` itself, as a string. Closeness is measured by absolute numeric difference; when two palindromes tie, pick the smaller one.\n\nOnly the value matters, not the spelling: candidates are built by mirroring a prefix. Also consider the powers-of-ten neighbors (`99..9` and `100..01`), which cover length changes the mirroring may miss.\n\n**Constraints:**\n- `1 <= n.length <= 18`\n- `n` has no leading zeros.\n- `n` fits in a signed 64-bit integer.\n", "solution": "## Approach\n\nBuild a small candidate set: mirror the leading half for the prefixes `p-1`, `p`, and `p+1`, and add the two length-change neighbors `10^len + 1` and `10^(len-1) - 1`. Mirroring copies the first `len // 2` characters of the prefix string in reverse, which naturally handles prefixes that grew or shrank. Remove the input itself, then choose the candidate with the smallest absolute gap, breaking ties toward the smaller value.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(len), proportional to the digit count (at most 18).\n- **Space Complexity:** O(len) for the candidate strings.\n\n## Implementation\n\n```python\nclass Solution:\n def nearestPalindromic(self, n: str) -> str:\n ln = len(n)\n self_val = int(n)\n cands = set()\n cands.add(10 ** ln + 1)\n cands.add(10 ** (ln - 1) - 1 if ln > 1 else 0)\n half = (ln + 1) // 2\n prefix = int(n[:half])\n for p in (prefix - 1, prefix, prefix + 1):\n if p < 0:\n continue\n s = str(p)\n cands.add(int(s + s[:ln // 2][::-1]))\n cands.discard(self_val)\n return str(min(cands, key=lambda c: (abs(c - self_val), c)))\n```\n", "starter": {"go": "package main\n\nfunc NearestPalindromic(n string) string {\n return \"\"\n}", "python": "class Solution:\n def nearestPalindromic(self, n: str) -> str:\n return \"\"\n", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string nearestPalindromic(string n) {\n return \"\";\n }\n};"}, "fn": "nearestPalindromic", "params": [{"name": "n", "type": "string"}], "outputType": "string", "tests": [["123"], ["1"], ["9"], ["10"], ["99"], ["100"], ["1000"], ["999"], ["12321"], ["1221"], ["10001"], ["15"], ["19"], ["10010"], ["101"], ["110"], ["1001"], ["9999"], ["1234"], ["99999"], ["100000"], ["54321"], ["12932"], ["99800"], ["11"], ["22"], ["191"], ["1283"]], "expected": ["121", "0", "8", "9", "101", "99", "999", "1001", "12221", "1111", "9999", "11", "22", "10001", "99", "111", "999", "10001", "1221", "100001", "99999", "54345", "12921", "99799", "9", "11", "181", "1331"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "656", "slug": "find-the-derangement-of-an-array", "id": 656, "title": "Find the Derangement of An Array", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/find-the-derangement-of-an-array/", "examples": [{"input": "n = 3", "output": "2", "explanation": "The derangements of [1,2,3] are [2,3,1] and [3,1,2]."}, {"input": "n = 2", "output": "1", "explanation": "Only [2,1] avoids every original slot."}, {"input": "n = 1", "output": "0", "explanation": "One element cannot escape its own position."}], "hints": ["Let f[i] count derangements of i items with f[0] = 1 and f[1] = 0.", "Placing item 1 into slot j (i-1 choices) splits on where item j goes, giving f[i] = (i-1) * (f[i-1] + f[i-2]).", "Iterate bottom-up with two rolling values, reducing modulo 1000000007 each step."], "statement": "Start from the sorted array `[1, 2, ..., n]`. A derangement is a rearrangement where no value stays in its original slot (so 1 is not first, 2 is not second, and so on).\n\nCount how many derangements exist, returning the total modulo 1000000007.\n\n**Constraints:**\n- `1 <= n <= 10^6`\n", "solution": "## Approach\n\nUse the classic recurrence for derangements: with f[0]=1 and f[1]=0, each larger size satisfies f[i]=(i-1)*(f[i-1]+f[i-2]) because element 1 has i-1 destination choices and the displaced element either swaps back or joins a smaller derangement. Iterate upward keeping only the last two values under the modulus.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def findDerangement(self, n: int) -> int:\n MOD = 10 ** 9 + 7\n if n == 1:\n return 0\n a, b = 1, 0\n for i in range(2, n + 1):\n a, b = b, ((i - 1) * (a + b)) % MOD\n return b\n```\n", "starter": {"go": "package main\n\nfunc FindDerangement(n int) int {\n \n}", "python": "class Solution:\n def findDerangement(self, n: int) -> int:\n pass", "cpp": "class Solution {\npublic:\n int findDerangement(int n) {\n return 0;\n }\n};"}, "fn": "findDerangement", "params": [{"name": "n", "type": "int"}], "outputType": "int", "tests": [["3"], ["2"], ["1"], ["4"], ["5"], ["6"], ["7"], ["8"], ["9"], ["10"], ["11"], ["12"], ["20"], ["50"], ["100"], ["1000"], ["10000"], ["100000"], ["1000000"], ["13"], ["14"], ["15"], ["16"], ["17"], ["18"], ["19"], ["21"], ["30"]], "expected": [2, 1, 0, 9, 44, 265, 1854, 14833, 133496, 1334961, 14684570, 176214841, 927799753, 77829876, 944828409, 37043040, 381587473, 183389504, 102701088, 290792918, 71100825, 66512367, 64197866, 91363714, 644546846, 246389989, 483794679, 568643488], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "465", "slug": "find-the-difference", "id": 465, "title": "Find the Difference", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/find-the-difference/", "examples": [{"explanation": "Reordering \"abcd\" can produce \"abcd\"; the surplus letter is \"e\".", "input": "s = \"abcd\", t = \"abcde\"", "output": "\"e\""}, {"explanation": "The first string is empty, so the only letter of \"t\" is the extra one.", "input": "s = \"\", t = \"y\"", "output": "\"y\""}, {"explanation": "Three 'a' letters pair up; one 'a' is left over.", "input": "s = \"aaab\", t = \"aaaba\"", "output": "\"a\""}], "hints": ["Adding up character codes of both strings leaves a difference equal to the extra letter.", "XOR-ing all codes cancels paired letters and reveals the surplus one.", "A 26-slot frequency table also works: the letter whose count differs is the answer."], "statement": "Two lowercase strings are given. The second string is formed by shuffling the characters of the first one and then inserting exactly one additional lowercase letter at some position. Identify which letter was inserted.\n\n*Interface note:* the original statement returns a single character. In this repo every language models that answer as a one-character `string`, so return e.g. `\"e\"` rather than `'e'`.\n\n**Constraints:**\n- `0 <= s.length <= 1000`\n- `t.length == s.length + 1`\n- `s` and `t` contain only lowercase English letters.\n", "solution": "## Approach\n\nPairing each letter of the shorter string with an equal letter of the longer one leaves exactly one unpaired letter. XOR-ing all character codes cancels the pairs and exposes the leftover code, which is converted to a one-character string. (Summing codes and subtracting works equally well.)\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `t`.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def findTheDifference(self, s: str, t: str) -> str:\n x = 0\n for c in s:\n x ^= ord(c)\n for c in t:\n x ^= ord(c)\n return chr(x)\n```\n", "starter": {"go": "package main\n\nfunc FindTheDifference(s string, t string) string {\n return \"\"\n}", "python": "class Solution:\n def findTheDifference(self, s: str, t: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string findTheDifference(string s, string t) {\n return \"\";\n }\n};"}, "fn": "findTheDifference", "params": [{"name": "s", "type": "string"}, {"name": "t", "type": "string"}], "outputType": "string", "tests": [["abcd", "abcde"], ["", "y"], ["aaab", "aaaba"], ["a", "aa"], ["a", "ab"], ["ae", "aea"], ["xyz", "xyzz"], ["hello", "hellol"], ["abc", "cabd"], ["q", "qq"], ["qq", "qqq"], ["abcd", "abecd"], ["aabbcc", "aabbccd"], ["z", "zz"], ["m", "nm"], ["mn", "mnm"], ["aaaa", "aaaaa"], ["abcdefg", "abcdefgh"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz"], ["zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzyz"], ["abcde", "edcbaf"], ["xxyy", "xxyyx"], ["", "a"], ["", "z"], ["ab", "aab"], ["ab", "abb"], ["code", "coded"], ["test", "testt"], ["u", "vu"], ["pqrs", "pqrst"]], "expected": ["e", "y", "a", "a", "b", "a", "z", "l", "d", "q", "q", "e", "d", "z", "n", "m", "a", "h", "z", "y", "f", "x", "a", "z", "a", "b", "d", "t", "v", "t"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "94", "slug": "find-the-duplicate-number", "id": 94, "title": "Find the Duplicate Number", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/find-the-duplicate-number/", "examples": [{"input": "nums = [1,3,4,2,2]", "output": "2", "explanation": "The repeated number in [1, 3, 4, 2, 2] is 2."}, {"input": "nums = [3,1,3,4,2]", "output": "3", "explanation": "The repeated number in [3, 1, 3, 4, 2] is 3."}, {"input": "nums = [3,3,3,3,3]", "output": "3", "explanation": "The number 3 is the duplicate, appearing 5 times."}], "hints": ["Interpret each array value as the next index in a linked structure; a duplicate creates a cycle.", "Use slow and fast pointers to find a meeting point inside that cycle.", "Reset one pointer to `nums[0]` and advance both one step at a time; their next meeting point is the duplicate."], "statement": "You receive an integer array `nums` holding `n + 1` entries, each drawn from the interval `[1, n]`. One value occurs repeatedly; identify and return it.\n\nA single distinct value is duplicated, though it may show up more than twice. Leave `nums` untouched and rely on only a constant amount of additional memory.\n\n**Constraints:**\n\n- `2 <= nums.length <= 100001`\n- `1 <= nums[i] < nums.length`\n- Precisely one distinct integer in `nums` shows up more than once.\n- That duplicated integer may occur more than twice.\n\n**Follow-up:** Is an `O(n)`-time approach achievable while keeping the input read-only and the extra memory at `O(1)`?\n", "solution": "## Approach\n\nTreat each value as a pointer to another index. Because there are `n + 1` entries whose values are in `[1, n]`, this pointer graph contains a cycle, and the cycle entrance is the duplicate value. First use slow and fast pointers to meet inside the cycle, then reset one pointer to `nums[0]` and advance both one step until they meet at the entrance.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def findDuplicate(self, nums: List[int]) -> int:\n slow = nums[0]\n fast = nums[0]\n\n while True:\n slow = nums[slow]\n fast = nums[nums[fast]]\n if slow == fast:\n break\n\n slow = nums[0]\n while slow != fast:\n slow = nums[slow]\n fast = nums[fast]\n return slow\n```\n", "starter": {"go": "package main\n\nfunc FindDuplicate(nums []int) int {\n return 0\n}", "python": "from typing import List\n\nclass Solution:\n def findDuplicate(self, nums: List[int]) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int findDuplicate(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "findDuplicate", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,1]"], ["[1,3,4,2,2]"], ["[3,1,3,4,2]"], ["[3,3,3,3,3]"], ["[2,1,2]"], ["[1,2,1]"], ["[2,2,1]"], ["[1,2,2]"], ["[1,1,2]"], ["[2,1,1]"], ["[1,2,3,1]"], ["[1,2,3,2]"], ["[1,2,3,3]"], ["[3,2,1,3]"], ["[2,3,2,1]"], ["[1,1,1,2]"], ["[2,2,3,2]"], ["[3,1,3,3]"], ["[4,1,2,3,4]"], ["[1,4,2,3,1]"], ["[2,4,2,1,3]"], ["[3,4,1,3,2]"], ["[4,2,1,3,2]"], ["[2,2,2,1,3]"], ["[4,4,1,4,2]"], ["[1,5,3,4,2,5]"], ["[6,1,2,3,4,5,6]"], ["[2,1,4,3,2,5]"], ["[3,5,1,4,2,3]"], ["[4,2,5,1,3,4]"], ["[1,1,1,1,2,3]"], ["[5,5,2,5,3,1]"], ["[1,6,2,5,3,4,6]"], ["[7,1,2,3,4,5,6,7]"], ["[2,6,4,1,3,5,2]"], ["[3,1,6,4,2,5,3]"], ["[4,2,6,1,5,3,4]"], ["[5,3,1,6,2,4,5]"], ["[6,4,2,5,3,1,6]"], ["[2,2,2,2,1,3,4]"], ["[7,7,1,7,2,3,4,5]"], ["[8,1,2,3,4,5,6,7,8]"], ["[1,7,3,5,2,8,4,6,7]"], ["[4,1,8,3,6,2,7,5,4]"], ["[2,8,6,4,1,7,3,5,2]"], ["[6,3,8,1,5,2,7,4,6]"], ["[1,1,1,1,1,2,3,4,5]"], ["[8,8,8,1,2,3,4,5,6]"], ["[9,1,2,3,4,5,6,7,8,9]"], ["[5,9,1,8,2,7,3,6,4,5]"], ["[2,4,6,8,1,3,5,7,9,2]"], ["[10,1,2,3,4,5,6,7,8,9,10]"], ["[7,2,10,4,1,9,3,8,5,6,7]"], ["[11,1,2,3,4,5,6,7,8,9,10,11]"], ["[6,11,2,10,3,9,4,8,5,7,1,6]"], ["@javascript:JSON.stringify(Array.from({length:19998},(_,i)=>19998-i).concat(1))"], ["@javascript:JSON.stringify(Array.from({length:19999},(_,i)=>i+1).concat(5432))"]], "expected": [1, 2, 3, 3, 2, 1, 2, 2, 1, 1, 1, 2, 3, 3, 2, 1, 2, 3, 4, 1, 2, 3, 2, 2, 4, 5, 6, 2, 3, 4, 1, 5, 6, 7, 2, 3, 4, 5, 6, 2, 7, 8, 7, 4, 2, 6, 1, 8, 9, 5, 2, 10, 7, 11, 6, 1, 5432], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "257", "slug": "find-the-index-of-the-first-occurrence-in-a-string", "id": 257, "title": "Find the Index of the First Occurrence in a String", "difficulty": "Easy", "category": "two-pointers", "link": "https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/", "examples": [{"input": "haystack = \"sadbutsad\", needle = \"sad\"", "output": "0", "explanation": "The pattern appears at index 0 and again at 6; the first occurrence wins."}, {"input": "haystack = \"leetcode\", needle = \"leeto\"", "output": "-1", "explanation": "No substring of the text equals the pattern."}], "hints": ["Try every start position from 0 up to len(haystack) - len(needle) and compare character by character.", "For a faster scan, precompute the longest-prefix-suffix table (KMP) so a mismatch never re-examines text characters."], "statement": "You are given two strings: a longer text `haystack` and a shorter pattern `needle`. Locate the first position in `haystack` where the whole `needle` appears as a contiguous block, and return that starting index.\n\nReturn `-1` when `needle` never occurs inside `haystack`.\n\n**Constraints:**\n- `1 <= haystack.length, needle.length <= 10^4`\n- Both strings consist of lowercase English letters.\n", "solution": "## Approach\n\nSlide a window over the text: for each start position that still leaves room for the pattern, compare the pattern character by character. The first position with a full match is the answer, and exhausting all starts without success yields -1.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n * m) in the worst case, where n and m are the lengths of the text and pattern.\n- **Space Complexity:** O(1) extra space.\n\n## Implementation\n\n```python\nclass Solution:\n def strStr(self, haystack: str, needle: str) -> int:\n n, m = len(haystack), len(needle)\n for i in range(n - m + 1):\n if haystack[i:i + m] == needle:\n return i\n return -1\n```\n", "starter": {"go": "package main\n\nfunc StrStr(haystack string, needle string) int {\n \n}", "python": "class Solution:\n def strStr(self, haystack: str, needle: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int strStr(string haystack, string needle) {\n return 0;\n }\n};"}, "fn": "strStr", "params": [{"name": "haystack", "type": "string"}, {"name": "needle", "type": "string"}], "outputType": "int", "tests": [["sadbutsad", "sad"], ["leetcode", "leeto"], ["hello", "ll"], ["aaaaa", "bba"], ["mississippi", "issip"], ["a", "a"], ["a", "b"], ["abc", "c"], ["abc", "abc"], ["abc", "abcd"], ["aaa", "aaaa"], ["mississippi", "pi"], ["abababab", "abab"], ["bacbababa", "baba"], ["aaaab", "aaab"], ["abcdef", "def"], ["abcdef", "abc"], ["xyzxyzxyz", "yzx"], ["aaaaaaaaaab", "aaab"], ["ab", "b"], ["ba", "a"], ["qwerty", "y"], ["qwerty", "q"], ["abcabcabc", "cab"], ["aaaaaa", "aaa"], ["z", "zz"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"], ["thequickbrownfox", "brown"]], "expected": [0, -1, 2, -1, 4, 0, -1, 2, 0, -1, -1, 9, 0, 3, 1, 3, 0, 1, 7, 1, 1, 5, 0, 2, 0, -1, 150, 8], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "930", "slug": "find-the-shortest-superstring", "id": 930, "title": "Find the Shortest Superstring", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/find-the-shortest-superstring/", "examples": [{"input": "words = [\"alex\",\"loves\",\"leetcode\"]", "output": "\"alexlovesleetcode\"", "explanation": "No overlaps, so concatenation in any order is best."}, {"input": "words = [\"catg\",\"ctaagt\",\"gcta\",\"ttca\",\"atgcatc\"]", "output": "\"gctaagttcatgcatc\"", "explanation": "Best overlaps chain all words into 16 characters."}], "hints": ["Precompute for every ordered pair how many trailing characters of the first equal the leading characters of the second.", "Run a travelling-salesman style dynamic program over subsets: the state is (used set, last word) holding the best string so far.", "Extend each state with every unused word using the precomputed overlap, keeping the shortest candidate (ties broken arbitrarily)."], "statement": "Stitch every word into one short string that holds each of them as a contiguous block.\n\nGiven distinct words, arrange them in some order and glue neighbours together with the largest possible overlap (the tail of one matching the head of the next). The result must contain every word somewhere inside it. Among all shortest results, any one is accepted. Assume no word appears inside another word.\n\n**Constraints:**\n- `1 <= words.length <= 12`\n- `1 <= words[i].length <= 20`\n- Words hold lowercase English letters and are pairwise different.\n- No word is a substring of another word.\n", "solution": "## Approach\n\nFirst measure every ordered overlap: the longest tail of word `i` that equals the head of word `j`. Then run dynamic programming over subsets where each state stores the best superstring covering a given set of words and ending with a given word. Extending a state appends an unused word trimmed by the overlap, keeping the shortest candidate. The answer is the best full-set state.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2 * 2^n * L) for n words of length up to L (n <= 12).\n- **Space Complexity:** O(n * 2^n * L) for the table of partial superstrings.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def shortestSuperstring(self, words: List[str]) -> str:\n n = len(words)\n if n == 1:\n return words[0]\n ov = [[0] * n for _ in range(n)]\n for i in range(n):\n for j in range(n):\n if i == j:\n continue\n m = min(len(words[i]), len(words[j]))\n for k in range(m, 0, -1):\n if words[i][-k:] == words[j][:k]:\n ov[i][j] = k\n break\n size = 1 << n\n dp = [[None] * n for _ in range(size)]\n for i in range(n):\n dp[1 << i][i] = words[i]\n for mask in range(size):\n for last in range(n):\n if not (mask & (1 << last)) or dp[mask][last] is None:\n continue\n for nxt in range(n):\n if mask & (1 << nxt):\n continue\n cand = dp[mask][last] + words[nxt][ov[last][nxt]:]\n nm = mask | (1 << nxt)\n cur = dp[nm][nxt]\n if cur is None or len(cand) < len(cur) or (len(cand) == len(cur) and cand < cur):\n dp[nm][nxt] = cand\n full = size - 1\n best = None\n for i in range(n):\n cur = dp[full][i]\n if cur is None:\n continue\n if best is None or len(cur) < len(best) or (len(cur) == len(best) and cur < best):\n best = cur\n return best\n```\n", "starter": {"go": "package main\n\nfunc ShortestSuperstring(words []string) string {\n return \"\"\n}", "python": "from typing import List\nclass Solution:\n def shortestSuperstring(self, words: List[str]) -> str:\n pass", "cpp": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string shortestSuperstring(vector<string>& words) {\n return \"\";\n }\n};"}, "fn": "shortestSuperstring", "params": [{"name": "words", "type": "string_array"}], "outputType": "string", "tests": [["['alex', 'loves', 'leetcode']"], ["['catg', 'ctaagt', 'gcta', 'ttca', 'atgcatc']"], ["['abc', 'bcd', 'cde']"], ["['abcd', 'cdef', 'efgh']"], ["['a', 'b', 'c']"], ["['abc', 'def', 'ghi']"], ["['ab', 'bc', 'cd', 'de']"], ["['gta', 'agt', 'tag']"], ["['cat', 'atc', 'tca']"], ["['abcde', 'cdefg', 'efghi']"], ["['word', 'ordw', 'rdwo']"], ["['ab', 'cd', 'ef', 'gh']"], ["['abc', 'cde', 'efg', 'ghi']"], ["['aab', 'abb', 'bba', 'baa']"], ["['xyz', 'yzx', 'zxy']"], ["['qwe', 'wer', 'ert', 'rty']"], ["['abcd', 'bcde', 'cdef', 'defg', 'efgh']"], ["['hello', 'llohe', 'ohell']"], ["['abca', 'bcab', 'cabc']"], ["['taco', 'acot', 'cota']"], ["['abcdef', 'defghi', 'ghijkl']"], ["['ab', 'ba']"], ["['abc', 'bca', 'cab']"], ["['mno', 'nop', 'opq', 'pqr']"], ["['aaaaab', 'aaaaba', 'aaabaa']"], ["['cat', 'dog', 'bird']"], ["['abca', 'cabc', 'bcab', 'cabb']"], ["['ef', 'fg', 'gh', 'he']"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "217", "slug": "find-the-town-judge", "id": 217, "title": "Find the Town Judge", "difficulty": "Easy", "category": "graph", "link": "https://leetcode.com/problems/find-the-town-judge/", "examples": [{"input": "n = 2, trust = [[1,2]]", "output": "2"}, {"input": "n = 3, trust = [[1,3],[2,3]]", "output": "3"}, {"input": "n = 3, trust = [[1,3],[2,3],[3,1]]", "output": "-1"}], "hints": ["The judge is trusted by everyone else and trusts nobody. Track in/out degree."], "statement": "A settlement holds `n` residents numbered `1` through `n`. Rumor says one of them covertly serves as the town judge.\n\nWhenever a judge is present, the following all hold:\n\n1. The town judge places trust in no one.\n2. Every other resident places trust in the town judge.\n3. Exactly one resident meets both conditions above.\n\nYou receive a list `trust` in which `trust[i] = [ai, bi]` means resident `ai` trusts resident `bi`. Any pair missing from `trust` indicates no trust flows there.\n\nIdentify the judge by number when such a uniquely determinable person exists; otherwise return `-1`.\n\n**Constraints:**\n- `1 <= n <= 1000`\n- `0 <= trust.length <= 10^4`\n- `trust[i].length == 2`\n- Every trust pair is different from the others.\n- `ai != bi`\n- `1 <= ai, bi <= n`\n", "solution": "## Approach\n\nMaintain a score for each person: +1 when trusted, -1 when trusting. The judge ends with score `n-1`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + trust.length)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def findJudge(self, n: int, trust: List[List[int]]) -> int:\n score = [0] * (n + 1)\n for a, b in trust:\n score[a] -= 1\n score[b] += 1\n for i in range(1, n + 1):\n if score[i] == n - 1:\n return i\n return -1\n```\n", "starter": {"go": "package main\n\nfunc FindJudge(n int, trust [][]int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def findJudge(self, n: int, trust: List[List[int]]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int findJudge(int n, vector<vector<int>>& trust) {\n \n }\n};"}, "fn": "findJudge", "params": [{"name": "n", "type": "int"}, {"name": "trust", "type": "int_array_2d"}], "outputType": "int", "tests": [["2", "[[1,2]]"], ["3", "[[1,3],[2,3]]"], ["3", "[[1,3],[2,3],[3,1]]"], ["1", "[]"], ["4", "[[1,3],[1,4],[2,3],[2,4],[4,3]]"], ["3", "[[1,2],[2,3]]"], ["4", "[[1,2],[2,3],[3,4],[4,1]]"], ["2", "[]"], ["3", "[[1,2],[2,1]]"], ["5", "[[1,5],[2,5],[3,5],[4,5]]"], ["4", "[[1,4],[2,4],[3,4]]"], ["4", "[[1,3],[2,3],[4,3],[3,1]]"], ["5", "[[1,2],[2,3],[3,4],[4,5]]"], ["5", "[]"], ["6", "[[1,6],[2,6],[3,6],[4,6],[5,6]]"], ["6", "[[1,6],[2,6],[3,6],[4,6]]"], ["3", "[[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]"], ["4", "[[2,1],[3,1],[4,1]]"], ["4", "[[2,1],[3,1],[4,1],[1,2]]"], ["5", "[[1,3],[2,3],[4,3],[5,3]]"], ["5", "[[2,1],[3,1],[4,1],[5,1],[1,3]]"], ["2", "[[2,1]]"], ["2", "[[1,2],[2,1]]"], ["7", "[[1,7],[2,7],[3,7],[4,7],[5,7],[6,7]]"], ["7", "[[1,2],[2,3],[3,1]]"], ["3", "[[1,3]]"], ["4", "[[1,2],[3,2],[4,2]]"], ["8", "[[1,5],[2,5],[3,5],[4,5],[6,5],[7,5],[8,5]]"], ["8", "[[1,5],[2,5],[3,5],[4,5],[6,5],[7,5],[8,5],[5,1]]"], ["10", "[[1,10],[2,10],[3,10],[4,10],[5,10],[6,10],[7,10],[8,10],[9,10]]"], ["3", "[[2,3],[3,2]]"], ["6", "[[1,2],[1,3],[2,4],[3,4],[4,5],[5,6]]"]], "expected": [2, 3, -1, 1, 3, -1, -1, -1, -1, 5, 4, -1, -1, -1, 6, -1, -1, 1, -1, 3, -1, 1, -1, 7, -1, -1, 2, 5, -1, 10, -1, -1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "278", "slug": "first-bad-version", "id": 278, "title": "First Bad Version", "difficulty": "Easy", "category": "binary-search", "link": "https://leetcode.com/problems/first-bad-version/", "examples": [{"input": "n = 5, bad = 4", "output": "4", "explanation": "Versions 4 and 5 are bad; 4 is first."}, {"input": "n = 1, bad = 1", "output": "1", "explanation": "The only version is bad."}, {"input": "n = 10, bad = 7", "output": "7", "explanation": "Versions 7..10 are bad; 7 is first."}], "hints": ["The judge never reveals bad; call the isBadVersion API to test a version, and minimize the number of calls.", "Binary-search [1, n] for the first v with v >= bad.", "Use mid = left + (right - left) / 2 to avoid overflow."], "statement": "Versions `1..n` turn bad starting at some hidden threshold: every version from the first bad one onward is bad. Interact with the judge object `vc` \u2014 your code never receives `bad` directly:\n\n- `isBadVersion(version)` returns whether that version is bad.\n\nImplement `firstBadVersion(n, vc)` returning the first bad version while minimizing the number of API calls. Binary search needs `O(log n)` calls; the judge counts your calls and reports Wrong Answer if you exceed **100** calls on a test case.\n\nMethod names per language: Java `vc.isBadVersion(version)`, Python `vc.is_bad_version(version)`, C++ `vc.isBadVersion(version)`, C# `vc.IsBadVersion(version)`, Rust `vc.is_bad_version(version)`, Go `vc.IsBadVersion(version)`, TypeScript `vc.isBadVersion(version)`, PHP `$vc->isBadVersion($version)`.\n\n**Constraints:**\n\n- `1 <= bad <= n <= 2^31 - 1`\n- At most 100 API calls per test case.\n", "solution": "## Approach\n\nTreat isBadVersion(v) as v >= bad and binary-search the inclusive range [1, n]. When mid is bad, record it and search left; otherwise search right.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(log n)\n- **Space Complexity:** O(1)\n\n## Implementation\n\n```python\nclass Solution:\n def firstBadVersion(self, n: int, bad: int) -> int:\n def isBad(v: int) -> bool:\n return v >= bad\n lo, hi, ans = 1, n, n\n while lo <= hi:\n mid = lo + (hi - lo) // 2\n if isBad(mid):\n ans = mid\n hi = mid - 1\n else:\n lo = mid + 1\n return ans\n```\n", "starter": {"go": "package main\n\n// This is the version-control API interface.\n// You should not implement it, or speculate about its implementation\n// type VersionControl struct { }\n// func (v *VersionControl) IsBadVersion(version int) bool\n// The judge counts your calls: at most 100 per test case.\nfunc FirstBadVersion(n int, vc *VersionControl) int {\n return 0\n}", "python": "# The version-control API is provided by the judge as `vc`.\n# You should not implement it, or speculate about its implementation\n# class VersionControl:\n# def is_bad_version(self, version: int) -> bool:\n# ...\n# The judge counts your calls: at most 100 per test case.\nclass Solution:\n def firstBadVersion(self, n: int, vc: 'VersionControl') -> int:\n return 0", "cpp": "// This is the version-control API interface.\n// You should not implement it, or speculate about its implementation\n// class VersionControl {\n// public:\n// bool isBadVersion(int version);\n// };\n// The judge counts your calls: at most 100 per test case.\nclass Solution {\npublic:\n int firstBadVersion(int n, VersionControl& vc) {\n return 0;\n }\n};"}, "fn": "firstBadVersion", "params": [{"name": "n", "type": "int"}, {"name": "bad", "type": "int"}], "outputType": "int", "tests": [["5", "4"], ["1", "1"], ["10", "1"], ["10", "10"], ["100", "50"], ["1000", "1"], ["1000", "1000"], ["2147483647", "1"], ["2147483647", "2147483647"], ["100", "42"], ["2", "1"], ["2", "2"], ["3", "2"], ["7", "4"], ["50", "25"], ["100", "99"], ["500", "1"], ["500", "500"], ["8", "8"], ["9", "5"], ["100", "100"], ["100", "1"], ["1000", "500"], ["10000", "9999"], ["10000", "5000"], ["3", "3"], ["3", "1"], ["2147483647", "1073741823"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "164", "slug": "first-missing-positive", "id": 164, "title": "First Missing Positive", "difficulty": "Hard", "category": "array", "link": "https://leetcode.com/problems/first-missing-positive/", "examples": [{"input": "nums = [1,2,0]", "output": "3", "explanation": "The numbers in the range [1,2] are all in the array."}, {"input": "nums = [3,4,-1,1]", "output": "2", "explanation": "1 is in the array but 2 is missing."}, {"input": "nums = [7,8,9,11,12]", "output": "1", "explanation": "The smallest positive integer 1 is missing."}], "hints": ["Place each value v with 1 <= v <= n at index v-1 by swapping (cyclic sort), ignoring others.", "Then the first index i with nums[i] != i+1 gives answer i+1; otherwise n+1."], "statement": "You receive an integer array `nums` with no particular order. Report the least positive integer (1, 2, 3, ...) absent from `nums`.\n\nYour method should complete in `O(n)` time while consuming only `O(1)` extra memory.\n\n**Constraints:**\n\n- `1 <= nums.length <= 10^5`\n- `-2^31 <= nums[i] <= 2^31 - 1`\n", "solution": "## Approach\n\nUse cyclic sort in place: for each index `i`, while `nums[i]` is in `[1, n]` and not already at its target `nums[v-1]`, swap it to position `v-1`. After this pass, every placeable value sits at its correct index. Scan for the first `i` with `nums[i] != i+1` and return `i+1`; if all match, return `n+1`.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), each element is swapped at most once into place plus one scan.\n- **Space Complexity:** O(1) extra.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def firstMissingPositive(self, nums: List[int]) -> int:\n n = len(nums)\n i = 0\n while i < n:\n v = nums[i]\n if 1 <= v <= n and nums[v - 1] != v:\n nums[i], nums[v - 1] = nums[v - 1], nums[i]\n else:\n i += 1\n for i, v in enumerate(nums):\n if v != i + 1:\n return i + 1\n return n + 1\n```\n", "starter": {"go": "package main\n\nfunc FirstMissingPositive(nums []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def firstMissingPositive(self, nums: List[int]) -> int:\n ", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int firstMissingPositive(vector<int>& nums) {\n return 0;\n }\n};"}, "fn": "firstMissingPositive", "params": [{"name": "nums", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,0]"], ["[3,4,-1,1]"], ["[7,8,9,11,12]"], ["[1]"], ["[0]"], ["[2]"], ["[1,2,3,4,5]"], ["[2,2,2]"], ["[-5,-1,0]"], ["[1,1000000]"], ["[2,1]"], ["@javascript:JSON.stringify(Array.from({length:100000},(_,i)=>i+1))"], ["[1,2,3]"], ["[2,3,4]"], ["[0,0,0]"], ["[-1,-2,-3]"], ["[1,1,1]"], ["[5,4,3,2,1]"], ["[1,3,5,7]"], ["[2,4,6,8]"], ["[0,2,2,1,1]"], ["[100,101,102]"], ["[-10,0,1,2]"], ["[2147483647,-2147483648]"], ["[3,1,2]"], ["[4,3,2,1]"], ["[1,2,4]"], ["[0,1]"], ["[2,0,1]"], ["[5,3,1,2,4]"], ["[1,2,3,5,6]"], ["[0,-1,3,1]"]], "expected": [3, 2, 1, 2, 1, 1, 6, 1, 1, 2, 3, 100001, 4, 1, 1, 1, 2, 6, 2, 1, 3, 1, 3, 1, 4, 5, 3, 2, 3, 6, 4, 2], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "463", "slug": "first-unique-character-in-a-string", "id": 463, "title": "First Unique Character in a String", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/first-unique-character-in-a-string/", "examples": [{"explanation": "'l' occurs once at index 0; 'e' repeats.", "input": "s = \"leetcode\"", "output": "0"}, {"explanation": "'l', 'o' and 'e' repeat; the first singleton is 'v' at index 2.", "input": "s = \"loveleetcode\"", "output": "2"}, {"explanation": "Both letters appear twice, so there is no singleton.", "input": "s = \"aabb\"", "output": "-1"}], "hints": ["Count how many times each of the 26 letters occurs in one pass.", "Make a second left-to-right pass and stop at the first letter whose count is 1.", "Two linear passes beat checking every pair of positions."], "statement": "Scan a lowercase word and locate the earliest position whose letter appears nowhere else in the word. Return that zero-based position. When every letter repeats, return `-1`.\n\nThe scan must distinguish the *first* singleton by its left-to-right order, not the smallest letter alphabetically.\n\n**Constraints:**\n- `1 <= s.length <= 10^5`\n- `s` contains only lowercase English letters.\n", "solution": "## Approach\n\nCount occurrences of each letter in a first pass over the string, then walk the string a second time and return the first index whose letter has count one. If the second walk finishes without a hit, no letter is unique. Two linear scans with a 26-slot table keep the work proportional to the string length.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`.\n- **Space Complexity:** O(1), a fixed 26-entry frequency table.\n\n## Implementation\n\n```python\nclass Solution:\n def firstUniqChar(self, s: str) -> int:\n cnt = [0] * 26\n for c in s:\n cnt[ord(c) - ord('a')] += 1\n for i, c in enumerate(s):\n if cnt[ord(c) - ord('a')] == 1:\n return i\n return -1\n```\n", "starter": {"go": "package main\n\nfunc FirstUniqChar(s string) int {\n return 0\n}", "python": "class Solution:\n def firstUniqChar(self, s: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int firstUniqChar(string s) {\n return 0;\n }\n};"}, "fn": "firstUniqChar", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["leetcode"], ["loveleetcode"], ["aabb"], ["a"], ["z"], ["ab"], ["aa"], ["abcabc"], ["dddccdbba"], ["aadadaad"], ["abcdefghijklmnopqrstuvwxyz"], ["zyxwvutsrqponmlkjihgfedcba"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"], ["abacabad"], ["aabbcdd"], ["xxyyzzabc"], ["aabbccddeeffg"], ["leetcodeleetcode"], ["oontt"], ["abcddcbaef"], ["aabbcceeddffg"], ["qwertyuiopasdfghjklzxcvbnm"], ["mmnnooppqq"], ["abcdabcdabce"], ["zzzzzzzzzzzzzzzzzzzzzzzzzy"], ["aab"], ["abb"], ["abc"], ["aabcbc"]], "expected": [0, 2, -1, 0, 0, 0, -1, -1, 8, -1, 0, 0, -1, 50, 3, 4, 6, 12, -1, 2, 8, 12, 0, -1, 11, 25, 2, 0, 0, -1], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "485", "slug": "fizz-buzz", "id": 485, "title": "Fizz Buzz", "difficulty": "Easy", "category": "math", "link": "https://leetcode.com/problems/fizz-buzz/", "examples": [{"input": "n = 3", "output": "[\"1\",\"2\",\"Fizz\"]", "explanation": "Multiples of 3 become Fizz."}, {"input": "n = 5", "output": "[\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]", "explanation": "Multiples of 5 become Buzz."}, {"input": "n = 15", "output": "[\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]", "explanation": "Multiples of both 3 and 5 become FizzBuzz."}], "hints": ["Check divisibility by 3 and 5 first for the combined case.", "Otherwise emit Fizz for multiples of 3 and Buzz for multiples of 5.", "All other positions hold the decimal form of the index."], "statement": "Count from `1` to `n`, writing a label for each position. Positions divisible by both `3` and `5` become `\"FizzBuzz\"`, those divisible only by `3` become `\"Fizz\"`, those divisible only by `5` become `\"Buzz\"`, and every other position becomes its own number as a string.\n\nReturn the labels in order as a list.\n\n**Constraints:**\n- `1 <= n <= 10^4`\n\n**Adaptation note:** The original return type is a list of strings; here it maps to `string_list` with identical contents.\n", "solution": "## Approach\n\nWalk i from 1 through n and pick the label by divisibility: the both-divisible case first, then the single-divisor cases, then the numeric fallback. Collecting labels in order directly yields the required list.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n).\n- **Space Complexity:** O(n) for the answer.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def fizzBuzz(self, n: int) -> List[str]:\n ans = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n ans.append(\"FizzBuzz\")\n elif i % 3 == 0:\n ans.append(\"Fizz\")\n elif i % 5 == 0:\n ans.append(\"Buzz\")\n else:\n ans.append(str(i))\n return ans\n```\n", "starter": {"go": "package main\n\nfunc FizzBuzz(n int) []string {\n return []string{}\n}", "python": "from typing import List\n\nclass Solution:\n def fizzBuzz(self, n: int) -> List[str]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<string> fizzBuzz(int n) {\n return {};\n }\n};"}, "fn": "fizzBuzz", "params": [{"name": "n", "type": "int"}], "outputType": "string_list", "tests": [["3"], ["5"], ["15"], ["1"], ["2"], ["4"], ["6"], ["7"], ["8"], ["9"], ["10"], ["11"], ["12"], ["13"], ["14"], ["16"], ["20"], ["30"], ["50"], ["100"], ["25"], ["45"], ["60"], ["75"], ["90"], ["33"], ["99"], ["17"], ["19"], ["21"]], "expected": [["1", "2", "Fizz"], ["1", "2", "Fizz", "4", "Buzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"], ["1"], ["1", "2"], ["1", "2", "Fizz", "4"], ["1", "2", "Fizz", "4", "Buzz", "Fizz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", "71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz", "Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz", "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", "41", "Fizz", "43", "44", "FizzBuzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", "71", "Fizz", "73", "74", "FizzBuzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", "71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz", "Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", "71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz", "Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz", "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19"], ["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", "Fizz"]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "357", "slug": "flatten-2d-vector", "id": 357, "title": "Flatten 2D Vector", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/flatten-2d-vector/", "examples": [{"input": "vec = [[1,2],[3],[4]], operations = [\"next\",\"next\",\"next\",\"hasNext\",\"hasNext\",\"next\",\"hasNext\"]", "output": "[1,2,3,1,1,4,0]", "explanation": "Flattened order is [1,2,3,4]. The first three calls give 1, 2 and 3; values remain so both checks are 1; the next call gives 4; nothing remains so the last check is 0."}, {"input": "vec = [[],[1],[],[2,3]], operations = [\"hasNext\",\"next\",\"next\",\"next\",\"hasNext\"]", "output": "[1,1,2,3,0]", "explanation": "Empty rows are skipped, so flattened order is [1,2,3]."}, {"input": "vec = [[],[]], operations = [\"hasNext\",\"hasNext\"]", "output": "[0,0]", "explanation": "Both rows are empty, so no value ever becomes available."}], "hints": ["Flatten the input once into a single list, skipping empty rows, then serve operations with an index pointer.", "Alternatively keep a row and column cursor and advance it past empty rows before answering each operation."], "statement": "This is an offline adaptation of a design task. Instead of writing a class, you write one function that replays a whole session:\n\n```\nrunVector2D(vec, operations)\n```\n\n`vec` is a 2D integer array such as `[[1,2],[3],[4]]`, and `operations` holds only `\"next\"` or `\"hasNext\"`, in the order they are called. The flattened view visits every integer row by row from left to right, skipping empty rows:\n\n- `\"next\"` returns the next integer in flattened order and moves forward.\n- `\"hasNext\"` returns `1` when integers remain and `0` otherwise.\n\nReturn the answers for every operation in order, encoding `\"hasNext\"` as `1` or `0`.\n\n**Constraints:**\n- `0 <= vec.length <= 100`\n- `0 <= vec[i].length <= 100`\n- `-10^4 <= vec[i][j] <= 10^4`\n- `1 <= operations.length <= 10^4`\n- Each operation is `\"next\"` or `\"hasNext\"`.\n- `\"next\"` is only called when `\"hasNext\"` would be true.\n", "solution": "## Approach\n\nFlatten the 2D input once into a single list, skipping empty rows. Keep an index pointing at the next unconsumed value. A `next` operation returns the value at the index and advances it, while a `hasNext` operation reports whether the index is still inside the list. This replays the iterator behavior without storing per-row cursors.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m + q), where m is the total number of integers and q is the number of operations.\n- **Space Complexity:** O(m) for the flattened list and the output.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def runVector2D(self, vec: List[List[int]], operations: List[str]) -> List[int]:\n flat = [v for row in vec for v in row]\n ans = []\n idx = 0\n for op in operations:\n if op == \"next\":\n ans.append(flat[idx])\n idx += 1\n else:\n ans.append(1 if idx < len(flat) else 0)\n return ans\n```\n", "starter": {"go": "package main\n\nfunc RunVector2D(vec [][]int, operations []string) []int {\n return []int{}\n}", "python": "from typing import List\n\nclass Solution:\n def runVector2D(self, vec: List[List[int]], operations: List[str]) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> runVector2D(vector<vector<int>>& vec, vector<string>& operations) {\n return {};\n }\n};"}, "fn": "runVector2D", "params": [{"name": "vec", "type": "int_array_2d"}, {"name": "operations", "type": "string_array"}], "outputType": "int_array", "tests": [["[[1,2],[3],[4]]", "[\"next\",\"next\",\"next\",\"hasNext\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[],[1],[],[2,3]]", "[\"hasNext\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[],[]]", "[\"hasNext\",\"hasNext\"]"], ["[[5]]", "[\"hasNext\",\"next\",\"hasNext\"]"], ["[[1]]", "[\"next\",\"hasNext\"]"], ["[[1,2,3]]", "[\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[1],[2],[3],[4],[5]]", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[],[],[7,8]]", "[\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[0,-1],[100]]", "[\"next\",\"next\",\"next\",\"hasNext\"]"], ["[]", "[\"hasNext\"]"], ["[[1,2],[3,4],[5,6]]", "[\"next\",\"next\",\"hasNext\",\"next\",\"next\",\"hasNext\",\"next\",\"next\",\"hasNext\"]"], ["[[10,20,30,40]]", "[\"hasNext\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[1],[],[2]]", "[\"next\",\"next\",\"hasNext\"]"], ["[[-5,0,5],[],[-10,10]]", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[3,3,3],[3]]", "[\"hasNext\",\"hasNext\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[10000],[-10000]]", "[\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[1,2],[],[],[3]]", "[\"next\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[9]]", "[\"hasNext\"]"], ["[[1,2,3,4,5,6,7,8,9,10]]", "[\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[1],[2,3,4],[5]]", "[\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[0],[0],[0]]", "[\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[42,43],[44]]", "[\"next\",\"hasNext\",\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[],[],[],[]]", "[\"hasNext\",\"hasNext\",\"hasNext\"]"], ["[[-10000,10000]]", "[\"next\",\"hasNext\",\"next\",\"hasNext\"]"], ["[[1,2,3],[],[]]", "[\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[],[0],[]]", "[\"hasNext\",\"hasNext\",\"next\",\"hasNext\",\"hasNext\"]"], ["[[6],[7],[8],[9]]", "[\"hasNext\",\"next\",\"next\",\"next\",\"next\",\"hasNext\"]"], ["[[-1,0],[],[1],[],[2,-2]]", "[\"next\",\"hasNext\",\"next\",\"next\",\"hasNext\",\"next\",\"next\",\"hasNext\"]"]], "expected": [[1, 2, 3, 1, 1, 4, 0], [1, 1, 2, 3, 0], [0, 0], [1, 5, 0], [1, 0], [1, 1, 2, 1, 3, 0], [1, 2, 3, 4, 5, 0], [1, 7, 1, 8, 0], [0, -1, 100, 0], [0], [1, 2, 1, 3, 4, 1, 5, 6, 0], [1, 10, 20, 30, 40, 0], [1, 2, 0], [-5, 0, 5, -10, 10, 0], [1, 1, 3, 3, 3, 3, 0], [10000, 1, -10000, 0], [1, 2, 1, 3, 0], [1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0], [1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 0], [0, 0, 0, 0], [42, 1, 43, 1, 44, 0], [0, 0, 0], [-10000, 1, 10000, 0], [1, 2, 3, 0], [1, 1, 0, 0, 0], [1, 6, 7, 8, 9, 0], [-1, 1, 0, 1, 1, 2, -2, 0]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "499", "slug": "flatten-a-multilevel-doubly-linked-list", "id": 499, "title": "Flatten a Multilevel Doubly Linked List", "difficulty": "Medium", "category": "linked-list", "link": "https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list/", "examples": [{"input": "head = [1,2,3,4,5,6]", "output": "[1,2,3,4,5,6]", "explanation": "A single-level list is already flat."}, {"input": "head = [1,2,3]", "output": "[1,2,3]", "explanation": "Nothing to unfold; order is preserved."}, {"input": "head = []", "output": "[]", "explanation": "Empty input gives empty output."}], "hints": ["Walk the chain once and collect values, then rebuild a fresh chain in that order.", "Adaptation: child and prev links are omitted, so flattening keeps the value order.", "An empty input returns null."], "statement": "You receive the head of a linked list and must return the head of its flattened form: the same values in the same order, with every node linked through `next`.\n\n**Constraints:**\n- Node count lies in `[0, 1000]`.\n- `1 <= Node.val <= 10^5`.\n\nAdaptation: the source uses a multilevel doubly node with `prev`, `next` and `child` links, which this judge cannot express (only singly `list_node` exists). Child and previous links are therefore omitted: input is a single-level chain modeled as `list_node`, and flattening preserves its order. Implement a faithful copy that keeps the value sequence.\n", "solution": "## Approach\n\nBecause the adapted input has no child levels, flattening means preserving the value order. Traverse once to gather values, then stitch a new singly chain from them. The fresh chain matches the input sequence exactly.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the list length. One pass to read plus one to rebuild.\n- **Space Complexity:** O(n) for the new nodes.\n\n## Implementation\n\n```python\nclass Solution:\n def flatten(self, head):\n if not head:\n return None\n dummy = ListNode(0)\n tail = dummy\n cur = head\n while cur:\n tail.next = ListNode(cur.val)\n tail = tail.next\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 Flatten(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 flatten(self, head):\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* flatten(ListNode* head) {\n \n }\n};"}, "fn": "flatten", "params": [{"name": "head", "type": "list_node"}], "outputType": "list_node", "tests": [["[1,2,3,4,5,6]"], ["[1,2,3]"], ["[]"], ["[1]"], ["[1,2]"], ["[7,8,9,10]"], ["[5]"], ["[1,2,3,4,5]"], ["[10,20,30]"], ["[4,4,4]"], ["[100,200]"], ["[1,2,3,4,5,6,7,8,9,10]"], ["[2]"], ["[3]"], ["[1,1,1]"], ["[9,8,7,6,5]"], ["[100]"], ["[1,3,5,7,9]"], ["[2,4,6,8,10]"], ["[11,22,33]"], ["[5,5,5,5,5]"], ["[42]"], ["[999,1000]"], ["[1,2,3,4,5,6,7]"], ["[50,40,30,20,10]"], ["[6,6,6,6]"], ["[123]"], ["[7,7,8,8,9,9]"], ["[100000]"], ["[1,100000]"]], "expected": [[1, 2, 3, 4, 5, 6], [1, 2, 3], null, [1], [1, 2], [7, 8, 9, 10], [5], [1, 2, 3, 4, 5], [10, 20, 30], [4, 4, 4], [100, 200], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [2], [3], [1, 1, 1], [9, 8, 7, 6, 5], [100], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 22, 33], [5, 5, 5, 5, 5], [42], [999, 1000], [1, 2, 3, 4, 5, 6, 7], [50, 40, 30, 20, 10], [6, 6, 6, 6], [123], [7, 7, 8, 8, 9, 9], [100000], [1, 100000]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "292", "slug": "flatten-binary-tree-to-linked-list", "id": 292, "title": "Flatten Binary Tree to Linked List", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/flatten-binary-tree-to-linked-list/", "examples": [{"input": "root = [1,2,5,3,4,null,6]", "output": "[1,null,2,null,3,null,4,null,5,null,6]", "explanation": "Preorder visits 1,2,3,4,5,6; the flattened chain links them via right pointers with all left pointers empty."}, {"input": "root = []", "output": "[]", "explanation": "Nothing to flatten."}, {"input": "root = [0]", "output": "[0]", "explanation": "A lone node is already flat."}], "hints": ["The final right-leaning chain follows preorder: root, left subtree, then right subtree.", "One simple route gathers preorder values first, then rebuilds a chain of right-only nodes.", "An in-place alternative rewires each node by splicing its left subtree between itself and its right subtree.", "Adaptation: the original edits in place with no return; here return the flattened root for checking."], "statement": "Reshape a binary tree into a right-leaning chain that follows preorder visiting order.\n\nAfter flattening, every node's left pointer must be empty and each right pointer must lead to the next node in a preorder walk (root, then left subtree, then right subtree). The node values stay the same; only the links change.\n\nReturn the root of the reshaped tree.\n\n**Constraints:**\n- `0 <= number of nodes <= 2000`\n- `-100 <= Node.val <= 100`\n\n**Adaptation note:** The classic task rewrites the tree in place and returns nothing. This version returns the flattened root so the result can be serialized and graded.\n", "solution": "## Approach\n\nA preorder walk lists the exact order the final chain must follow. Rebuilding a chain of right-only nodes from that list is straightforward: each new node takes the next preorder value with an empty left pointer. This uses extra nodes but keeps the logic clear; an in-place splice achieves the same order without allocation.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), one preorder pass plus one chain build.\n- **Space Complexity:** O(n) for the value list (O(h) with an in-place splice).\n\n## Implementation\n\n```python\nclass Solution:\n def flatten(self, root):\n if not root:\n return None\n vals = []\n def pre(n):\n if not n:\n return\n vals.append(n.val)\n pre(n.left)\n pre(n.right)\n pre(root)\n root.val = vals[0]\n root.left = None\n cur = root\n for v in vals[1:]:\n cur.right = TreeNode(v)\n cur = cur.right\n cur.left = None\n return root\n```\n", "starter": {"go": "// Definition for a binary tree node.\n// type TreeNode struct {\n// Val int\n// Left *TreeNode\n// Right *TreeNode\n// }\npackage main\n\nfunc Flatten(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 flatten(self, root):\n pass\n", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\nclass Solution {\npublic:\n TreeNode* flatten(TreeNode* root) {\n \n }\n};"}, "fn": "flatten", "params": [{"name": "root", "type": "tree_node", "visualizeType": "tree_node"}], "outputType": "tree_node", "tests": [["[1,2,5,3,4,null,6]"], ["[]"], ["[0]"], ["[1,2,3]"], ["[1,null,2,3,4]"], ["[1,2,null,3]"], ["[1,2,3,4,5]"], ["[2,1,3]"], ["[3,1,4,null,2]"], ["[1,2,3,4,5,6,7]"], ["[5,4,6,3,null,null,7]"], ["[10,5,15,2,7]"], ["[1,null,2,null,3,null,4]"], ["[4,2,6,1,3,5,7]"], ["[0,0,0]"], ["[-5,-10,0]"], ["[100,50,150,25,75]"], ["[1,2,3,null,4,5,6]"], ["[7,3,10,2,5,null,12]"], ["[6,3,9,1,4,8,10]"], ["[2,null,3,null,4,null,5]"], ["[8,3,10,1,6,null,14]"], ["[5,null,4,null,3,null,2]"], ["[1,2,3,4,null,null,5]"], ["[9,5,12,3,7,10,15]"], ["[15,10,20,8,12,17,25]"]], "expected": null, "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "424", "slug": "flatten-nested-list-iterator", "id": 424, "title": "Flatten Nested List Iterator", "difficulty": "Medium", "category": "stack", "link": "https://leetcode.com/problems/flatten-nested-list-iterator/", "examples": [{"input": "nestedList = \"[[1,1],2,[1,1]]\"", "output": "[1,1,2,1,1]", "explanation": "Left-to-right depth-first reading yields 1,1,2,1,1."}, {"input": "nestedList = \"[1,[4,[6]]]\"", "output": "[1,4,6]", "explanation": "Descending level by level gives 1, then 4, then 6."}, {"input": "nestedList = \"[]\"", "output": "[]", "explanation": "Nothing is stored, so the result is empty."}], "hints": ["Adaptation: simulate what repeated next calls would produce and return it as one array.", "Parse recursively (a list) or iteratively with a stack, appending integers in encounter order."], "statement": "This is an offline adaptation of an iterator task. Instead of writing a class with `next` and `hasNext`, you write one function that returns the whole flattened order at once:\n\n```\nflattenNestedList(nestedList)\n```\n\n`nestedList` arrives serialized as text, e.g. `\"[[1,1],2,[1,1]]\"`: brackets delimit lists, bare numbers (possibly negative) are integers, commas separate elements. Flattening means reading all integers in left-to-right order, descending into every nested list. Return them as an array in that order.\n\n**Constraints:**\n- `1 <= nestedList.length <= 500`\n- Integers lie in `[-10^6, 10^6]`.\n- The text is always a valid nested list.\n\n**Adaptation note:** The classic version exposes a `NestedIterator` class over `NestedInteger` objects. Here the structure is passed as a serialized `string` and you return the full flattened `int_array`.\n", "solution": "## Approach\n\nParse the serialization with a small recursive reader: on `[` consume elements until the matching `]`, skipping commas; on a digit or minus sign read the full integer and append it. Because elements are visited strictly left to right and sublists are expanded in place, appended integers already appear in flattened order, matching exactly what successive iterator steps would emit.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the text length. Each character is consumed once.\n- **Space Complexity:** O(d + m), with d nesting depth for recursion and m integers of output.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def flattenNestedList(self, nestedList: str) -> List[int]:\n self.s = nestedList\n self.i = 0\n out = []\n def parse():\n if self.i >= len(self.s):\n return\n if self.s[self.i] == '[':\n self.i += 1\n while self.i < len(self.s) and self.s[self.i] != ']':\n if self.s[self.i] == ',':\n self.i += 1\n else:\n parse()\n self.i += 1\n else:\n sign = 1\n if self.s[self.i] == '-':\n sign = -1\n self.i += 1\n num = 0\n while self.i < len(self.s) and self.s[self.i].isdigit():\n num = num * 10 + int(self.s[self.i])\n self.i += 1\n out.append(sign * num)\n parse()\n return out\n```\n", "starter": {"go": "package main\n\nfunc FlattenNestedList(nestedList string) []int {\n return []int{}\n}", "python": "from typing import List\nclass Solution:\n def flattenNestedList(self, nestedList: str) -> List[int]:\n return []\n", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> flattenNestedList(string nestedList) {\n return {};\n }\n};"}, "fn": "flattenNestedList", "params": [{"name": "nestedList", "type": "string"}], "outputType": "int_array", "tests": [["[[1,1],2,[1,1]]"], ["[1,[4,[6]]]"], ["[]"], ["[1]"], ["[1,2,3]"], ["[[1],[2],[3]]"], ["[[1,2],[3,4]]"], ["[[-1],[-2]]"], ["[[[1]]]"], ["[[[]]]"], ["[[],[1],[],[2,3]]"], ["[10,20,30]"], ["[[10,20],30]"], ["[1,[2,[3,[4]]]]"], ["[[0,0],0]"], ["[5]"], ["[-5]"], ["[[1],[2,[3]]]"], ["[[100]]"], ["[1,[1,[1,[1]]]]"], ["[[2],3,[4,[5]]]"], ["[[-1,2],[-3,4]]"], ["[[1,1],2,[1,1],3]"], ["[7,[7,[7,[7]]]]"], ["[[1,2,3],[4,5]]"], ["[0]"], ["[[1,1],[1,1]]"]], "expected": [[1, 1, 2, 1, 1], [1, 4, 6], [], [1], [1, 2, 3], [1, 2, 3], [1, 2, 3, 4], [-1, -2], [1], [], [1, 2, 3], [10, 20, 30], [10, 20, 30], [1, 2, 3, 4], [0, 0, 0], [5], [-5], [1, 2, 3], [100], [1, 1, 1, 1], [2, 3, 4, 5], [-1, 2, -3, 4], [1, 1, 2, 1, 1, 3], [7, 7, 7, 7], [1, 2, 3, 4, 5], [0], [1, 1, 1, 1]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "957", "slug": "flip-binary-tree-to-match-preorder-traversal", "id": 957, "title": "Flip Binary Tree To Match Preorder Traversal", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/flip-binary-tree-to-match-preorder-traversal/", "examples": [{"input": "root = [1,2], voyage = [2,1]", "output": "[-1]", "explanation": "Flipping never changes the root value, so a voyage starting with 2 cannot be produced from a tree rooted at 1."}, {"input": "root = [1,2,3], voyage = [1,3,2]", "output": "[1]", "explanation": "Swapping the two children of node 1 makes the preorder visit 1, then 3, then 2."}, {"input": "root = [1,2,3], voyage = [1,2,3]", "output": "[]", "explanation": "The tree already visits nodes in the requested order, so nothing is flipped."}], "hints": ["Walk the tree in preorder while consuming the voyage array with a shared index pointer.", "When a node has a left child whose value is not the next voyage entry, you must flip that node (if possible) and visit the right subtree first.", "If any node value mismatches the expected voyage entry, or a needed child is missing, the answer is [-1]."], "statement": "You are given the root of a binary tree and an integer array `voyage` that lists node values in some desired preorder order.\n\nA flip operation swaps the left and right child of a chosen node. Performing any number of flips (each node flipped at most once conceptually) changes the preorder visit order of the tree.\n\nReturn the values of the flipped nodes in the order they are flipped. When several answers exist the preorder walk described below yields the canonical one. When the voyage cannot be achieved, return `[-1]`. When no flip is needed, return an empty list.\n\nTo determine the flips, traverse the tree in preorder while reading `voyage` from left to right with a single position pointer:\n\n- Each visited node must equal the current voyage entry; otherwise the task is impossible.\n- If the node has a left child and that child does not equal the next voyage entry, flip the node (record its value) and traverse the right child before the left child.\n- Otherwise traverse left before right as usual.\n\n**Constraints:**\n- `1 <= number of nodes <= 100`\n- `1 <= node values, voyage[i] <= 100`\n- `voyage.length == number of nodes`\n- Values in the tree are unique.\n", "solution": "## Approach\n\nKeep a position pointer into the voyage array and walk the tree in preorder. Each visited node must match the current voyage entry, otherwise the voyage is unreachable. When the left child exists but its value differs from the next voyage entry, record a flip at the current node and visit the right subtree first; otherwise visit left first. A single depth-first pass implements this rule.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the number of nodes. Each node is visited once.\n- **Space Complexity:** O(h) for recursion depth, where h is the tree height, plus O(n) for the flip list in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def flipMatchVoyage(self, root, voyage: List[int]) -> List[int]:\n self.i = 0\n self.flips = []\n def dfs(node):\n if not node:\n return True\n if self.i >= len(voyage) or node.val != voyage[self.i]:\n return False\n self.i += 1\n left = node.left\n if left is not None and self.i < len(voyage) and left.val != voyage[self.i]:\n self.flips.append(node.val)\n if not dfs(node.right):\n return False\n if not dfs(node.left):\n return False\n else:\n if not dfs(node.left):\n return False\n if not dfs(node.right):\n return False\n return True\n if not dfs(root):\n return [-1]\n return self.flips\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 FlipMatchVoyage(root *TreeNode, voyage []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\nfrom typing import List\nclass Solution:\n def flipMatchVoyage(self, root, voyage: List[int]) -> List[int]:\n pass", "cpp": "/*\nDefinition for a binary tree node.\nstruct TreeNode {\n int val;\n TreeNode *left;\n TreeNode *right;\n TreeNode(): val(0), left(nullptr), right(nullptr) {}\n TreeNode(int x): val(x), left(nullptr), right(nullptr) {}\n TreeNode(int x, TreeNode* left, TreeNode* right): val(x), left(left), right(right) {}\n};\n*/\n#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> flipMatchVoyage(TreeNode* root, vector<int>& voyage) {\n return {};\n }\n};"}, "fn": "flipMatchVoyage", "params": [{"name": "root", "type": "tree_node"}, {"name": "voyage", "type": "int_array"}], "outputType": "int_list", "tests": [["[1,2]", "[2,1]"], ["[1,2,3]", "[1,3,2]"], ["[1,2,3]", "[1,2,3]"], ["[1,null,2]", "[1,2]"], ["[1,null,2]", "[1,2]"], ["[1,2,null,3]", "[1,2,3]"], ["[1,2,null,3]", "[1,3,2]"], ["[1,2,3,4,5,6,7]", "[1,2,4,5,3,6,7]"], ["[1,2,3,4,5,6,7]", "[1,3,7,6,2,5,4]"], ["[1,2,3,4,5,6,7]", "[1,2,4,5,3,7,6]"], ["[1,2,3]", "[1,3,4]"], ["[1]", "[1]"], ["[1]", "[2]"], ["[2,1,3]", "[2,3,1]"], ["[4,2,7,1,3,6,9]", "[4,2,1,3,7,6,9]"], ["[4,2,7,1,3,6,9]", "[4,7,9,6,2,3,1]"], ["[1,2,3,null,null,4,5]", "[1,2,3,4,5]"], ["[1,2,3,null,null,4,5]", "[1,3,5,4,2]"], ["[1,2,3,4,null,null,5]", "[1,2,4,3,5]"], ["[1,2,3,4,null,null,5]", "[1,3,5,2,4]"], ["[1,2,null,3,null,4]", "[1,2,3,4]"], ["[1,null,2,null,3]", "[1,2,3]"], ["[1,null,2,null,3]", "[1,3,2]"], ["[3,1,4,null,2]", "[3,1,2,4]"], ["[3,1,4,null,2]", "[3,4,1,2]"], ["[5,3,8,1,4,7,9]", "[5,3,1,4,8,7,9]"], ["[5,3,8,1,4,7,9]", "[5,8,9,7,3,4,1]"], ["[1,2,3,4,5]", "[1,2,5,4,3]"]], "expected": [[-1], [1], [], [], [], [], [-1], [], [1, 3, 2], [3], [-1], [], [-1], [2], [], [4, 7, 2], [], [1, 3], [], [1], [], [], [-1], [], [3], [], [5, 8, 3], [2]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "938", "slug": "flip-equivalent-binary-trees", "id": 938, "title": "Flip Equivalent Binary Trees", "difficulty": "Medium", "category": "tree", "link": "https://leetcode.com/problems/flip-equivalent-binary-trees/", "examples": [{"input": "root1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]", "output": "true", "explanation": "Flips at a few nodes align both trees."}, {"input": "root1 = [], root2 = []", "output": "true", "explanation": "Empty trees match."}, {"input": "root1 = [], root2 = [1]", "output": "false", "explanation": "A missing node cannot appear."}], "hints": ["Matching roots must hold equal values; empty trees match only each other.", "For non-empty roots, try both alignments: straight (left-left, right-right) and crossed (left-right, right-left); one of them must fully match."], "statement": "Test whether two binary trees can be made identical by swapping child pairs.\n\nOne flip picks any node and exchanges its left and right subtrees. Applying flips anywhere, any number of times, reshapes a tree without changing its values.\n\nGiven the roots `root1` and `root2`, return `true` when the first tree can be turned into the second through flips, else `false`. An empty tree is written `[]`.\n\n**Constraints:**\n- Each tree holds between 0 and 100 nodes.\n- Node values lie in `0..99` and are unique within a tree.\n", "solution": "## Approach\n\nCompare the two trees recursively. Empty pairs match, half-empty pairs fail, and differing root values fail. Otherwise the answer is true when either the straight pairing (left with left, right with right) or the crossed pairing (left with right, right with left) fully matches, which models using or skipping a flip at the current node.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) in practice for these sizes; each node pair is examined a small number of times.\n- **Space Complexity:** O(h) call stack for trees of height h.\n\n## Implementation\n\n```python\nclass Solution:\n def flipEquiv(self, root1, root2) -> bool:\n if root1 is None and root2 is None:\n return True\n if root1 is None or root2 is None:\n return False\n if root1.val != root2.val:\n return False\n straight = self.flipEquiv(root1.left, root2.left) and self.flipEquiv(root1.right, root2.right)\n crossed = self.flipEquiv(root1.left, root2.right) and self.flipEquiv(root1.right, root2.left)\n return straight or crossed\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 FlipEquiv(root1 *TreeNode, root2 *TreeNode) bool {\n return false\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 flipEquiv(self, root1, root2) -> bool:\n pass", "cpp": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n return false;\n }\n};"}, "fn": "flipEquiv", "params": [{"name": "root1", "type": "tree_node"}, {"name": "root2", "type": "tree_node"}], "outputType": "boolean", "tests": [["[1,2,3,4,5,6,null,null,null,7,8]", "[1,3,2,null,6,4,5,null,null,null,null,8,7]"], ["[]", "[]"], ["[]", "[1]"], ["[1]", "[1]"], ["[1]", "[2]"], ["[1,2,3]", "[1,3,2]"], ["[1,2,3]", "[1,2,3]"], ["[0,1,2]", "[0,2,1]"], ["[1,2]", "[1,null,2]"], ["[1,2,null,3]", "[1,2,null,null,3]"], ["[1,2,3,4]", "[1,2,3,4]"], ["[1,2,3,4,5]", "[1,2,3,4,6]"], ["[5,3,8,1,4,7,9]", "[5,8,3,9,7,4,1]"], ["[1,2,3,null,4]", "[1,3,2,4]"], ["[2,1,3]", "[2,3,1]"], ["[0]", "[0]"], ["[0]", "[1]"], ["[1,2,3,4,5,6,7]", "[1,3,2,7,6,5,4]"], ["[1,2,3,4,5,6,7]", "[1,2,3,4,5,6,8]"], ["[4,2,7,1,3,6,9]", "[4,7,2,9,6,3,1]"], ["[1,null,2,null,3]", "[1,2,null,3]"], ["[1,2,3,null,null,4,5]", "[1,3,2,5,4]"], ["[10,5,15]", "[10,15,5]"], ["[10,5,15]", "[10,5,15]"], ["[3,1,4,null,2]", "[3,4,1,2]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "[8,3,10,1,6,null,14,null,null,4,7,13]"], ["[8,3,10,1,6,null,14,null,null,4,7,13]", "[8,10,3,14,null,6,1,13,null,7,4]"], ["[1,2,3]", "[4,5,6]"]], "expected": [true, true, false, true, false, true, true, true, true, true, true, false, true, false, true, true, false, true, false, true, true, true, true, true, false, true, true, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "390", "slug": "flip-game-ii", "id": 390, "title": "Flip Game II", "difficulty": "Medium", "category": "dp", "link": "https://leetcode.com/problems/flip-game-ii/", "examples": [{"input": "currentState = \"++++\"", "output": "true", "explanation": "Flipping the middle pair leaves \"+--+\" with no reply."}, {"input": "currentState = \"+\"", "output": "false", "explanation": "No move exists for the first player."}, {"input": "currentState = \"+++++\"", "output": "false", "explanation": "Each possible first flip hands the opponent a winning board."}], "hints": ["A board is winning when some legal flip leads to a board that is losing for the player to move.", "Boards with no flippable pair are losing; build up from there with memoised search.", "Flipping splits the board into independent left and right parts, so identical substrings share results through memoisation."], "statement": "Consider the same board and move as in Flip Game: a move flips one occurrence of `\"++\"`\ninto `\"--\"`. Two players now alternate moves, and the player that cannot move loses. Both\nplay perfectly. Given the starting board `currentState`, decide whether the player to move\nhas a forced win.\n\n**Constraints:**\n- `1 <= currentState.length <= 60`\n- `currentState` contains only `'+'` and `'-'`.\n", "solution": "## Approach\n\nDepth-first game search with memoisation: try every flip, and win if any reply position is losing for the opponent. Boards without moves lose.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(2^n)\n- **Space Complexity:** O(2^n)\n\n## Implementation\n\n```python\nclass Solution:\n def canWin(self, currentState: str) -> bool:\n from functools import lru_cache\n @lru_cache(maxsize=None)\n def win(s: str) -> bool:\n c = list(s)\n for i in range(len(c) - 1):\n if c[i] == '+' and c[i + 1] == '+':\n c[i] = c[i + 1] = '-'\n nxt = ''.join(c)\n c[i] = c[i + 1] = '+'\n if not win(nxt):\n return True\n return False\n return win(currentState)\n```\n", "starter": {"go": "package main\n\nfunc CanWin(currentState string) bool {\n return false\n}", "python": "class Solution:\n def canWin(self, currentState: str) -> bool:\n ", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n bool canWin(string currentState) {\n return false;\n }\n};"}, "fn": "canWin", "params": [{"name": "currentState", "type": "string"}], "outputType": "boolean", "tests": [["++++"], ["+"], ["+++++"], ["-"], ["--"], ["++"], ["---"], ["+++"], ["------"], ["++++++"], ["+++++++"], ["++++++++"], ["+-"], ["-+"], ["+--+"], ["++--"], ["--++"], ["-++-"], ["++-++"], ["+-++-"], ["--++--"], ["++--++"], ["+-+-+-"], ["++++++++++++"], ["+++-+++"], ["-++-++-"], ["++-----++"], ["+++++++++"]], "expected": [true, false, false, false, false, true, false, true, false, true, true, true, false, false, false, true, true, true, false, true, true, false, false, true, false, false, false, false], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "389", "slug": "flip-game", "id": 389, "title": "Flip Game", "difficulty": "Easy", "category": "string", "link": "https://leetcode.com/problems/flip-game/", "examples": [{"input": "currentState = \"++++\"", "output": "[\"--++\",\"+--+\",\"++--\"]", "explanation": "Each of the three adjacent pairs flips once."}, {"input": "currentState = \"--++\"", "output": "[\"----\"]", "explanation": "Only the trailing pair can flip."}, {"input": "currentState = \"-+-\"", "output": "[]", "explanation": "No \"++\" exists, so no move is possible."}], "hints": ["Scan every adjacent pair of positions once and test whether both hold '+'..., hide the literal: say both hold a plus sign.", "Build each answer by copying the board and flipping just the chosen pair.", "Boards with no flippable pair produce an empty result list."], "statement": "You are given a string holding only `'+'` and `'-'` characters. A single move picks an\noccurrence of `\"++\"` and flips both characters to `\"--\"`. Return every distinct board that\ncan be reached with exactly one move. The order of the returned boards does not matter.\n\n**Constraints:**\n- `1 <= currentState.length <= 100`\n- `currentState` contains only `'+'` and `'-'`.\n", "solution": "## Approach\n\nSlide a window of width two across the board; whenever both cells show '+', emit a copy with that pair flipped to '-'.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2)\n- **Space Complexity:** O(n)\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n res = []\n for i in range(len(currentState) - 1):\n if currentState[i] == '+' and currentState[i + 1] == '+':\n res.append(currentState[:i] + '--' + currentState[i + 2:])\n return res\n```\n", "starter": {"go": "package main\n\nfunc GeneratePossibleNextMoves(currentState string) []string {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n ", "cpp": "#include <string>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<string> generatePossibleNextMoves(string currentState) {\n return {};\n }\n};"}, "fn": "generatePossibleNextMoves", "params": [{"name": "currentState", "type": "string"}], "outputType": "string_list", "tests": [["++++"], ["--++"], ["-+-"], ["+"], ["-"], ["++"], ["--"], ["+-"], ["-+"], ["+++"], ["---"], ["+--+"], ["++--"], ["--++"], ["-++-"], ["+++++"], ["-----"], ["++-++"], ["+-+-"], ["-+-+"], ["+++-++"], ["-++"], ["++-"], ["+-++-+"], ["++++++++"], ["--+--+"], ["+-+++"], ["++--++"]], "expected": [["--++", "+--+", "++--"], ["----"], [], [], [], ["--"], [], [], [], ["--+", "+--"], [], [], ["----"], ["----"], ["----"], ["--+++", "+--++", "++--+", "+++--"], [], ["---++", "++---"], [], [], ["--+-++", "+---++", "+++---"], ["---"], ["---"], ["+----+"], ["--++++++", "+--+++++", "++--++++", "+++--+++", "++++--++", "+++++--+", "++++++--"], [], ["+---+", "+-+--"], ["----++", "++----"]], "loose": true}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "913", "slug": "flip-string-to-monotone-increasing", "id": 913, "title": "Flip String to Monotone Increasing", "difficulty": "Medium", "category": "string", "link": "https://leetcode.com/problems/flip-string-to-monotone-increasing/", "examples": [{"input": "s = \"00110\"", "output": "1", "explanation": "Flip the last '0' to '1'."}, {"input": "s = \"010110\"", "output": "2", "explanation": "Two flips reach a block of zeros then ones."}, {"input": "s = \"00011000\"", "output": "2", "explanation": "Clearing the two ones leaves all zeros."}], "hints": ["Every monotone string is zeros then ones, so the split point is the only choice.", "While scanning, remember how many ones have appeared; they are the cost of forcing all zeros.", "For each zero, compare flipping it versus flipping all prior ones."], "statement": "You are given a binary string `s` containing only `'0'` and `'1'`. In one move you may flip any single character (`'0'` to `'1'` or `'1'` to `'0'`).\n\nA string is monotone increasing when it consists of some number of `'0'`s followed by some number of `'1'`s (either part may be empty). Return the smallest number of flips needed to make `s` monotone increasing.\n\n**Constraints:**\n- `1 <= s.length <= 100000`\n- `s` contains only `'0'` and `'1'`.\n", "solution": "## Approach\n\nScan once while counting how many `'1'`s have been seen. Keep `flips`, the cheapest cost for the prefix so far. On `'1'` increment the ones count; on `'0'` we either flip this zero to one (`flips + 1`) or flip all previous ones to zero (`ones`), taking the cheaper option.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), where n is the length of `s`. One left-to-right pass.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nclass Solution:\n def minFlipsMonoIncr(self, s: str) -> int:\n ones = 0\n flips = 0\n for c in s:\n if c == '1':\n ones += 1\n else:\n flips = min(flips + 1, ones)\n return flips\n```\n", "starter": {"go": "package main\n\nfunc MinFlipsMonoIncr(s string) int {\n return 0\n}", "python": "class Solution:\n def minFlipsMonoIncr(self, s: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int minFlipsMonoIncr(string s) {\n return 0;\n }\n};"}, "fn": "minFlipsMonoIncr", "params": [{"name": "s", "type": "string"}], "outputType": "int", "tests": [["00110"], ["010110"], ["00011000"], ["0"], ["1"], ["00"], ["11"], ["01"], ["10"], ["00000"], ["11111"], ["010101"], ["101010"], ["00110011"], ["11001100"], ["000111"], ["111000"], ["01000"], ["10111"], ["00100"], ["10011"], ["0110"], ["0101"], ["1010"], ["0001"], ["1110"], ["01111"], ["00001"]], "expected": [1, 2, 2, 0, 0, 0, 0, 0, 1, 0, 0, 2, 3, 2, 4, 0, 3, 1, 1, 1, 1, 1, 1, 2, 0, 1, 0, 0], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "830", "slug": "flipping-an-image", "id": 830, "title": "Flipping an Image", "difficulty": "Easy", "category": "matrix", "link": "https://leetcode.com/problems/flipping-an-image/", "examples": [{"input": "image = [[1,1,0],[1,0,1],[0,0,0]]", "output": "[[1,0,0],[0,1,0],[1,1,1]]", "explanation": "Mirror each row, then invert every bit."}, {"input": "image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]", "output": "[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]"}], "hints": ["Mirroring plus inverting can be done in one pass by reading each row from the far end while flipping the bit.", "Handle odd-length rows carefully so the middle cell is only inverted, not swapped with itself twice.", "XOR with 1 is a compact way to invert a binary cell."], "statement": "You are given a binary matrix `image` where each cell is `0` or `1`. Transform it in two steps: first mirror every row horizontally (the leftmost cell swaps with the rightmost, and so on), then flip every bit (`0` becomes `1` and `1` becomes `0`). Return the resulting matrix.\n\n**Constraints:**\n- `1 <= image.length <= 20`\n- `1 <= image[i].length <= 20`\n- `image[i][j]` is `0` or `1`\n", "solution": "## Approach\n\nBuild a fresh matrix where each output cell copies the horizontally mirrored input cell with its bit flipped. Reading row i from right to left while writing left to right combines the mirror and the inversion in a single pass, and XOR with 1 performs the bit flip.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n*m) for an n by m matrix.\n- **Space Complexity:** O(n*m) for the result matrix.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]:\n return [[cell ^ 1 for cell in row[::-1]] for row in image]\n```\n", "starter": {"go": "package main\n\nfunc FlipAndInvertImage(image [][]int) [][]int {\n return nil\n}", "python": "from typing import List\nclass Solution:\n def flipAndInvertImage(self, image: List[List[int]]) -> List[List[int]]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image) {\n return {};\n }\n};"}, "fn": "flipAndInvertImage", "params": [{"name": "image", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[1, 1, 0], [1, 0, 1], [0, 0, 0]]"], ["[[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]]"], ["[[0]]"], ["[[1]]"], ["[[0, 1], [1, 0]]"], ["[[1, 1], [0, 0]]"], ["[[0, 0, 0], [1, 1, 1]]"], ["[[1, 0, 1], [0, 1, 0]]"], ["[[1, 0]]"], ["[[0, 1, 0, 1, 0]]"], ["[[1, 1, 1, 1, 1]]"], ["[[0, 0, 0, 0, 0]]"], ["[[1, 0, 0], [0, 1, 0], [0, 0, 1]]"], ["[[0, 1, 1], [1, 0, 0], [1, 1, 0]]"], ["[[1, 1, 0, 1], [0, 0, 1, 0]]"], ["[[1, 0, 1, 0, 1], [0, 1, 0, 1, 0], [1, 1, 1, 0, 0]]"], ["[[0, 0], [0, 0], [1, 1]]"], ["[[1]]"], ["[[1, 1, 1], [1, 1, 1], [1, 1, 1]]"], ["[[0, 0, 0], [0, 0, 0], [0, 0, 0]]"], ["[[1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 1]]"], ["[[0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1]]"], ["[[1, 0, 0, 0, 1]]"], ["[[0, 1, 1, 1, 0, 0]]"], ["[[1, 0, 1]]"], ["[[0, 1, 0, 1], [1, 0, 1, 0], [0, 0, 0, 0]]"], ["[[1, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0]]"], ["[[0, 1], [1, 1], [0, 0], [1, 0]]"]], "expected": [[[1, 0, 0], [0, 1, 0], [1, 1, 1]], [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0]], [[1]], [[0]], [[0, 1], [1, 0]], [[0, 0], [1, 1]], [[1, 1, 1], [0, 0, 0]], [[0, 1, 0], [1, 0, 1]], [[1, 0]], [[1, 0, 1, 0, 1]], [[0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1]], [[1, 1, 0], [1, 0, 1], [0, 1, 1]], [[0, 0, 1], [1, 1, 0], [1, 0, 0]], [[0, 1, 0, 0], [1, 0, 1, 1]], [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1], [1, 1, 0, 0, 0]], [[1, 1], [1, 1], [0, 0]], [[0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 0, 1, 0], [0, 1, 0, 1], [1, 1, 0, 0], [0, 0, 1, 1]], [[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]], [[0, 1, 1, 1, 0]], [[1, 1, 0, 0, 0, 1]], [[0, 1, 0]], [[0, 1, 0, 1], [1, 0, 1, 0], [1, 1, 1, 1]], [[0, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 1]], [[0, 1], [0, 0], [1, 1], [1, 0]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "740", "slug": "flood-fill", "id": 740, "title": "Flood Fill", "difficulty": "Easy", "category": "matrix", "link": "https://leetcode.com/problems/flood-fill/", "examples": [{"input": "image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, color = 2", "output": "[[2,2,2],[2,2,0],[2,0,1]]", "explanation": "The 4-connected block of 1s is repainted to 2."}, {"input": "image = [[0,0,0],[0,0,0]], sr = 0, sc = 0, color = 0", "output": "[[0,0,0],[0,0,0]]"}, {"input": "image = [[1,2,1],[2,1,2],[1,2,1]], sr = 1, sc = 1, color = 9", "output": "[[1,2,1],[2,9,2],[1,2,1]]"}], "hints": ["Remember the starting cell's original color first; if it already equals the new color, return immediately.", "Explore with depth-first or breadth-first search, stepping only to in-bounds neighbours holding the original color.", "Recolor on visit so cells are never processed twice."], "statement": "You are given a picture as a grid of color numbers, a starting cell `(sr, sc)`, and a new color value. Recolor the starting cell plus every cell connected to it through shared sides (up, down, left, right) that currently holds the same original color, painting all of them with the new color.\n\nCells joined only diagonally do not count as connected. When the new color already equals the starting cell's color, the picture stays unchanged.\n\nReturn the picture after the recoloring.\n\n**Constraints:**\n- `1 <= image.length, image[i].length <= 50`\n- `0 <= image[i][j], color < 65536`\n- `0 <= sr < image.length`, `0 <= sc < image[i].length`\n", "solution": "## Approach\n\nSnapshot the color of the start cell. If it already matches the target, there is nothing to do. Otherwise run an explicit stack (depth-first search) from the start: pop a cell, paint its four orthogonal neighbours when they still hold the old color, and push them. Painting on discovery guarantees each cell is handled once.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n) for an m-by-n picture, each cell visited at most once.\n- **Space Complexity:** O(m * n) worst case for the stack.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:\n old = image[sr][sc]\n if old == color:\n return image\n m, n = len(image), len(image[0])\n stack = [(sr, sc)]\n image[sr][sc] = color\n while stack:\n r, c = stack.pop()\n for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):\n nr, nc = r + dr, c + dc\n if 0 <= nr < m and 0 <= nc < n and image[nr][nc] == old:\n image[nr][nc] = color\n stack.append((nr, nc))\n return image\n```\n", "starter": {"go": "package main\n\nfunc FloodFill(image [][]int, sr int, sc int, color int) [][]int {\n return image\n}", "python": "from typing import List\nclass Solution:\n def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:\n return image\n", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {\n return image;\n }\n};"}, "fn": "floodFill", "params": [{"name": "image", "type": "int_array_2d"}, {"name": "sr", "type": "int"}, {"name": "sc", "type": "int"}, {"name": "color", "type": "int"}], "outputType": "int_array_2d", "tests": [["[[1,1,1],[1,1,0],[1,0,1]]", "1", "1", "2"], ["[[0,0,0],[0,0,0]]", "0", "0", "0"], ["[[1,2,1],[2,1,2],[1,2,1]]", "1", "1", "9"], ["[[0]]", "0", "0", "1"], ["[[1]]", "0", "0", "1"], ["[[1,1],[1,1]]", "0", "0", "2"], ["[[1,2],[3,4]]", "0", "0", "9"], ["[[1,2],[3,4]]", "1", "1", "0"], ["[[3,3,3],[3,3,3],[3,3,3]]", "1", "1", "5"], ["[[1,1,2],[1,0,2],[0,0,2]]", "0", "0", "3"], ["[[5,5,5,5],[5,4,4,5],[5,4,4,5],[5,5,5,5]]", "1", "1", "7"], ["[[1,2,3],[4,5,6],[7,8,9]]", "2", "2", "0"], ["[[0,1,0],[1,1,1],[0,1,0]]", "1", "1", "2"], ["[[2,2,2],[2,0,2],[2,2,2]]", "1", "1", "1"], ["[[1,0,1],[0,1,0],[1,0,1]]", "0", "0", "8"], ["[[4,4],[4,4],[4,4]]", "2", "1", "4"], ["[[1,2,1,2],[2,1,2,1]]", "0", "1", "3"], ["[[0,0,1],[0,1,1],[1,1,0]]", "2", "2", "5"], ["[[7]]", "0", "0", "7"], ["[[1,1,1,1],[1,0,0,1],[1,0,0,1],[1,1,1,1]]", "1", "1", "2"], ["[[9,9],[9,8]]", "0", "0", "8"], ["[[1,3,1],[1,1,1],[3,1,3]]", "1", "0", "6"], ["[[0,2,0,2],[2,0,2,0],[0,2,0,2]]", "0", "0", "1"], ["[[5,1,5],[1,1,1],[5,1,5]]", "1", "1", "5"], ["[[100,100],[100,200]]", "0", "1", "300"], ["[[1,2,3,4],[5,1,1,4],[9,1,1,4]]", "1", "1", "0"], ["[[6,6,6],[6,1,6],[6,6,6]]", "1", "1", "2"], ["[[0,0,0,0],[0,1,1,0],[0,1,1,0],[0,0,0,0]]", "0", "0", "9"]], "expected": [[[2, 2, 2], [2, 2, 0], [2, 0, 1]], [[0, 0, 0], [0, 0, 0]], [[1, 2, 1], [2, 9, 2], [1, 2, 1]], [[1]], [[1]], [[2, 2], [2, 2]], [[9, 2], [3, 4]], [[1, 2], [3, 0]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[3, 3, 2], [3, 0, 2], [0, 0, 2]], [[5, 5, 5, 5], [5, 7, 7, 5], [5, 7, 7, 5], [5, 5, 5, 5]], [[1, 2, 3], [4, 5, 6], [7, 8, 0]], [[0, 2, 0], [2, 2, 2], [0, 2, 0]], [[2, 2, 2], [2, 1, 2], [2, 2, 2]], [[8, 0, 1], [0, 1, 0], [1, 0, 1]], [[4, 4], [4, 4], [4, 4]], [[1, 3, 1, 2], [2, 1, 2, 1]], [[0, 0, 1], [0, 1, 1], [1, 1, 5]], [[7]], [[1, 1, 1, 1], [1, 2, 2, 1], [1, 2, 2, 1], [1, 1, 1, 1]], [[8, 8], [8, 8]], [[6, 3, 6], [6, 6, 6], [3, 6, 3]], [[1, 2, 0, 2], [2, 0, 2, 0], [0, 2, 0, 2]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[300, 300], [300, 200]], [[1, 2, 3, 4], [5, 0, 0, 4], [9, 0, 0, 4]], [[6, 6, 6], [6, 2, 6], [6, 6, 6]], [[9, 9, 9, 9], [9, 1, 1, 9], [9, 1, 1, 9], [9, 9, 9, 9]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "634", "slug": "fraction-addition-and-subtraction", "id": 634, "title": "Fraction Addition and Subtraction", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/fraction-addition-and-subtraction/", "examples": [{"input": "expression = \"-1/2+1/2\"", "output": "\"0/1\"", "explanation": "Opposites cancel to zero."}, {"input": "expression = \"-1/2+1/2+1/3\"", "output": "\"1/3\"", "explanation": "The first two cancel, leaving one third."}, {"input": "expression = \"1/3-1/2\"", "output": "\"-1/6\"", "explanation": "A common denominator of 6 gives 2/6 - 3/6."}], "hints": ["Parse optional sign, numerator, slash, denominator repeatedly.", "Keep a running total as numerator/denominator and reduce by gcd after each step.", "Return zero as 0/1 with a positive denominator."], "statement": "An expression strings together fractions with `+` and `-`, for example `\"-1/2+1/2+1/3\"`. Each fraction has a possibly signed numerator and a positive denominator. Evaluate the sum and return it as one reduced fraction `\"num/den\"` with a positive denominator and greatest-common-divisor 1; zero is written `\"0/1\"`.\n\n**Constraints:**\n- Length is at most 500; numerators and denominators are small positive integers.\n- The first fraction may carry a leading sign.\n", "solution": "## Approach\n\nWalk the string pulling optional signs and numerator/denominator pairs. Merge each term into a running total with cross multiplication and divide by the gcd each time so numbers stay small.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k log C) for k fractions.\n- **Space Complexity:** O(1).\n\n## Implementation\n\n```python\nimport math\nclass Solution:\n def fractionAddition(self, expression: str) -> str:\n rn, rd, i, n = 0, 1, 0, len(expression)\n while i < n:\n sign = 1\n if expression[i] in '+-':\n sign = -1 if expression[i] == '-' else 1\n i += 1\n j = i\n while j < n and expression[j].isdigit():\n j += 1\n a = int(expression[i:j]) * sign\n i = j + 1\n j = i\n while j < n and expression[j].isdigit():\n j += 1\n b = int(expression[i:j])\n i = j\n rn = rn * b + a * rd\n rd = rd * b\n g = math.gcd(abs(rn), rd)\n rn //= g; rd //= g\n return f\"{rn}/{rd}\"\n```\n", "starter": {"go": "package main\n\nfunc FractionAddition(expression string) string {\n return \"\"\n}", "python": "class Solution:\n def fractionAddition(self, expression: str) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string fractionAddition(string expression) {\n return \"\";\n }\n};"}, "fn": "fractionAddition", "params": [{"name": "expression", "type": "string"}], "outputType": "string", "tests": [["-1/2+1/2"], ["-1/2+1/2+1/3"], ["1/3-1/2"], ["5/3+1/3"], ["1/2-1/2"], ["1/10+2/10"], ["7/2+2/3-3/4"], ["-5/2+10/3+7/9"], ["1/1+1/1"], ["2/4"], ["4/6-1/6"], ["1/6+1/6"], ["3/7-2/7+1/7"], ["10/3-5/3+1/3"], ["1/2+1/3+1/6"], ["1/2-1/3-1/6"], ["-1/3-1/3"], ["0/5+0/7"], ["9/10-1/10-2/10"], ["100/200+100/200"], ["1/7+1/7+1/7+1/7"], ["5/6-1/6-1/6"], ["11/12-1/12"], ["2/3-1/3"], ["-3/4+1/4"], ["7/8-3/8+1/8"], ["1/5+2/5+2/5"], ["12/8-4/8"]], "expected": ["0/1", "1/3", "-1/6", "2/1", "0/1", "3/10", "41/12", "29/18", "2/1", "1/2", "1/2", "1/3", "2/7", "2/1", "1/1", "0/1", "-2/3", "0/1", "3/5", "1/1", "4/7", "1/2", "5/6", "1/3", "-1/2", "5/8", "1/1", "1/1"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "319", "slug": "fraction-to-recurring-decimal", "id": 319, "title": "Fraction to Recurring Decimal", "difficulty": "Medium", "category": "math", "link": "https://leetcode.com/problems/fraction-to-recurring-decimal/", "examples": [{"explanation": "One half is exactly 0.5.", "input": "numerator = 1, denominator = 2", "output": "\"0.5\""}, {"explanation": "The division is exact, so no decimal point appears.", "input": "numerator = 2, denominator = 1", "output": "\"2\""}, {"explanation": "The digits 012 repeat forever.", "input": "numerator = 4, denominator = 333", "output": "\"0.(012)\""}], "hints": ["Track each remainder in a map from remainder value to its position in the output.", "When a remainder repeats, the digits since its first visit form the repeating block."], "statement": "Divide `numerator` by `denominator` and write the result as a decimal string. When the fractional part repeats forever, wrap the repeating block in parentheses.\n\nFor example, `1 / 2` is `\"0.5\"`, while `4 / 333` repeats `\"012\"` and becomes `\"0.(012)\"`. A negative result carries a single leading minus sign, and an exact division shows no decimal point.\n\n**Constraints:**\n- `-2^31 <= numerator, denominator <= 2^31 - 1`\n- `denominator != 0`\n", "solution": "## Approach\n\nSeparate the sign, then do long division digit by digit. Remember where each remainder first appeared: when a remainder repeats, everything produced since its first visit repeats forever, so wrap that block in parentheses. A zero remainder ends the decimal. Wide integers protect the edge case of the smallest 32-bit value.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(d), where d is the number of digits before the decimal terminates or repeats (bounded by the denominator).\n- **Space Complexity:** O(d) for the remainder positions and the output.\n\n## Implementation\n\n```python\nclass Solution:\n def fractionToDecimal(self, numerator: int, denominator: int) -> str:\n if numerator == 0:\n return \"0\"\n res = []\n if (numerator < 0) ^ (denominator < 0):\n res.append(\"-\")\n num, den = abs(numerator), abs(denominator)\n res.append(str(num // den))\n rem = num % den\n if rem == 0:\n return \"\".join(res)\n res.append(\".\")\n pos = {}\n while rem != 0:\n if rem in pos:\n at = pos[rem]\n res.insert(at, \"(\")\n res.append(\")\")\n break\n pos[rem] = len(res)\n rem *= 10\n res.append(str(rem // den))\n rem %= den\n return \"\".join(res)\n```\n", "starter": {"go": "package main\n\nfunc FractionToDecimal(numerator int, denominator int) string {\n return \"\"\n}", "python": "class Solution:\n def fractionToDecimal(self, numerator: int, denominator: int) -> str:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n string fractionToDecimal(int numerator, int denominator) {\n return \"\";\n }\n};"}, "fn": "fractionToDecimal", "params": [{"name": "numerator", "type": "int"}, {"name": "denominator", "type": "int"}], "outputType": "string", "tests": [["1", "2"], ["2", "1"], ["4", "333"], ["1", "3"], ["1", "6"], ["-50", "8"], ["0", "3"], ["-1", "2"], ["1", "-2"], ["7", "4"], ["1", "9"], ["2", "7"], ["1", "11"], ["-1", "6"], ["0", "1"], ["3", "5"], ["22", "90"], ["1", "12"], ["1", "200"], ["-22", "4"], ["-7", "7"], ["5", "2"], ["5", "13"], ["1", "81"], ["1", "7"], ["-2147483648", "-1"]], "expected": ["0.5", "2", "0.(012)", "0.(3)", "0.1(6)", "-6.25", "0", "-0.5", "-0.5", "1.75", "0.(1)", "0.(285714)", "0.(09)", "-0.1(6)", "0", "0.6", "0.2(4)", "0.08(3)", "0.005", "-5.5", "-1", "2.5", "0.(384615)", "0.(012345679)", "0.(142857)", "2147483648"], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "574", "slug": "freedom-trail", "id": 574, "title": "Freedom Trail", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/freedom-trail/", "examples": [{"input": "ring = \"godding\", key = \"gd\"", "output": "4", "explanation": "Keep the dial still and press 'g' (1), rotate two places to a 'd' (2), then press it (1), for 4 total."}, {"input": "ring = \"godding\", key = \"godding\"", "output": "13", "explanation": "Spelling the full word in order needs 6 rotations plus 7 presses."}, {"input": "ring = \"ab\", key = \"b\"", "output": "2", "explanation": "Rotate one step to 'b' (1) and press it (1)."}], "hints": ["Precompute, for each letter, the list of dial positions holding it so transitions only consider relevant stops.", "Memoize over (key index, dial position): try every occurrence of the next character and add the circular distance plus one press.", "Circular distance between i and j on a dial of length m is min(|i-j|, m-|i-j|)."], "statement": "A circular dial carries the characters of `ring` around its rim, with position 0 initially pointing at 12 o'clock. One step rotates the dial a single place clockwise or counterclockwise, and pressing a button spells the character currently at the top (costing one extra move per character). The dial starts aligned so `ring[0]` is at the top.\n\nGiven the dial layout `ring` and a word `key` to spell in order, compute the smallest total number of moves (rotations plus one press per character) that spells the whole word. Every character of `key` appears somewhere in `ring`.\n\n**Constraints:**\n- `1 <= ring.length, key.length <= 100`\n- `ring` and `key` contain only lowercase English letters\n- Every character of `key` occurs in `ring`\n", "solution": "## Approach\n\nGroup dial positions by their letter so each key character only considers stops that can actually spell it. Then run a memoized search over states `(key index, current dial position)`: for the next needed letter, try every matching stop, pay the shorter circular walk plus one press, and continue from there. Taking the minimum over those choices yields the optimal total.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(k * m^2) in the worst case, where k is the key length and m the ring length (each state scans matching stops).\n- **Space Complexity:** O(k * m) for the memo table plus the position groups.\n\n## Implementation\n\n```python\nclass Solution:\n def findRotateSteps(self, ring: str, key: str) -> int:\n from functools import lru_cache\n m = len(ring)\n pos_map = {}\n for i, c in enumerate(ring):\n pos_map.setdefault(c, []).append(i)\n\n @lru_cache(maxsize=None)\n def dp(ki, pos):\n if ki == len(key):\n return 0\n best = 10 ** 9\n for np in pos_map[key[ki]]:\n diff = abs(pos - np)\n step = min(diff, m - diff)\n best = min(best, step + 1 + dp(ki + 1, np))\n return best\n\n return dp(0, 0)\n```\n", "starter": {"go": "package main\n\nfunc FindRotateSteps(ring string, key string) int {\n \n}", "python": "class Solution:\n def findRotateSteps(self, ring: str, key: str) -> int:\n pass", "cpp": "#include <string>\nusing namespace std;\nclass Solution {\npublic:\n int findRotateSteps(string ring, string key) {\n return 0;\n }\n};"}, "fn": "findRotateSteps", "params": [{"name": "ring", "type": "string"}, {"name": "key", "type": "string"}], "outputType": "int", "tests": [["godding", "gd"], ["godding", "godding"], ["ab", "b"], ["abcde", "ade"], ["a", "a"], ["a", "aaaa"], ["ab", "a"], ["ab", "aba"], ["abc", "abc"], ["abc", "cba"], ["aaaaa", "aaa"], ["abcdef", "fedcba"], ["godding", "g"], ["godding", "ding"], ["xyz", "zyx"], ["abacaba", "abc"], ["caotmcaataijjxi", "oatjiioicitatajtijciocjcaaxaaatmctxamacaamjjx"], ["abcdefghij", "jihgfedcba"], ["abccba", "abcba"], ["zzzzzz", "zzzz"], ["pqrst", "qqqq"], ["helloworld", "hold"], ["ab", "bbbb"], ["abcde", "edcba"], ["aabbaa", "aba"], ["abcdefghijklmnopqrst", "tsrqponmlkjihgfedcba"], ["niwaxk", "kankin"], ["abcabc", "cbaabc"]], "expected": [4, 13, 2, 6, 1, 4, 1, 5, 5, 6, 3, 12, 1, 10, 6, 6, 137, 20, 9, 4, 5, 11, 5, 10, 6, 40, 16, 11], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "823", "slug": "friends-of-appropriate-ages", "id": 823, "title": "Friends Of Appropriate Ages", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/friends-of-appropriate-ages/", "examples": [{"input": "ages = [16,16]", "output": "2", "explanation": "Both ordered pairs pass every rule."}, {"input": "ages = [16,17,18]", "output": "2", "explanation": "Only the pairs (17,16) and (18,17) survive."}, {"input": "ages = [20,30,100,110,120]", "output": "3"}], "hints": ["Ages are bounded by 120, so count how many people have each age and evaluate pairs of distinct age values once.", "For equal ages, multiply the count by one less than itself since nobody sends to themselves.", "Check the three blocking rules in order and skip the pair as soon as any rule fires."], "statement": "You are given an array `ages` where each entry is one person's age. Person `x` sends a request to a different person `y` exactly when all of the following hold:\n\n- `y`'s age is more than half of `x`'s age plus seven (that is, the request is blocked when `ages[y] <= ages[x] / 2 + 7` using real division).\n- `y`'s age is not greater than `x`'s age.\n- It is not the case that `y` is over 100 while `x` is under 100.\n\nEvery ordered pair of distinct people is considered. Return the total number of requests sent.\n\n**Constraints:**\n- `1 <= ages.length <= 20000`\n- `1 <= ages[i] <= 120`\n", "solution": "## Approach\n\nBecause ages only range from 1 to 120, tally the frequency of each age instead of comparing every pair of people. For each ordered pair of distinct age values with nonzero counts, test the three blocking rules directly and add the product of the frequencies (subtracting the self-pair for equal ages). Summing over at most 120 by 120 age pairs is easily fast enough.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n + A^2) where n is the number of people and A = 120 is the age range.\n- **Space Complexity:** O(A) for the frequency table.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def numFriendRequests(self, ages: List[int]) -> int:\n cnt = [0] * 121\n for a in ages:\n cnt[a] += 1\n ans = 0\n for a in range(1, 121):\n if cnt[a] == 0:\n continue\n for b in range(1, 121):\n if cnt[b] == 0:\n continue\n if b <= a // 2 + 7:\n continue\n if b > a:\n continue\n if b > 100 and a < 100:\n continue\n ans += cnt[a] * (cnt[b] - (1 if a == b else 0))\n return ans\n```\n", "starter": {"go": "package main\n\nfunc NumFriendRequests(ages []int) int {\n return 0\n}", "python": "from typing import List\nclass Solution:\n def numFriendRequests(self, ages: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int numFriendRequests(vector<int>& ages) {\n return 0;\n }\n};"}, "fn": "numFriendRequests", "params": [{"name": "ages", "type": "int_array"}], "outputType": "int", "tests": [["[16, 16]"], ["[16, 17, 18]"], ["[20, 30, 100, 110, 120]"], ["[1]"], ["[120]"], ["[1, 1, 1, 1]"], ["[120, 120, 120]"], ["[100, 100, 100]"], ["[99, 100, 101]"], ["[100, 99]"], ["[99, 100]"], ["[14, 15, 16]"], ["[15, 15, 15, 15]"], ["[16, 16, 16, 16]"], ["[18, 18, 18]"], ["[20, 20, 20, 20, 20]"], ["[8, 8, 8, 8]"], ["[73, 80, 84, 100, 101, 115]"], ["[54, 23, 102, 102, 44, 16, 88, 11, 24, 23]"], ["[110, 110, 110, 99, 99]"], ["[101, 99, 101, 99]"], ["[1, 120]"], ["[120, 1]"], ["[30, 30, 30, 30, 30, 30]"], ["[17, 18, 19, 20, 21, 22]"], ["[50, 60, 70, 80, 90, 100, 110, 120]"], ["[40, 40, 60, 60, 60]"], ["[109, 98, 91, 3, 39, 92, 113, 102, 56, 66, 60, 34, 63, 97, 30, 57, 68, 29, 44, 78]"]], "expected": [2, 2, 3, 0, 0, 0, 6, 6, 3, 1, 1, 0, 12, 12, 6, 20, 0, 15, 10, 14, 8, 0, 0, 30, 11, 22, 14, 100], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "477", "slug": "frog-jump", "id": 477, "title": "Frog Jump", "difficulty": "Hard", "category": "dp", "link": "https://leetcode.com/problems/frog-jump/", "examples": [{"input": "stones = [0,1,3,5,6,8,12,17]", "output": "true", "explanation": "Hop sizes 1,2,2,3,4,5 walk the frog from the first stone to the last."}, {"input": "stones = [0,1,2,3,4,8,9,11]", "output": "false", "explanation": "The wide water gap after stone 4 cannot be crossed with any allowed step."}, {"input": "stones = [0,1]", "output": "true", "explanation": "A single hop of length 1 reaches the final stone."}], "hints": ["Track, for each stone, the set of jump lengths that can land on it; the first hop must be 1.", "From a stone reached with step k, only k-1, k and k+1 (when positive) can continue forward.", "Stop early when a gap exceeds the largest reachable step, and memoize visited (index, step) pairs."], "statement": "A frog sits on stones placed at distinct positions along a river, starting at position `0`. The positions are given in strictly increasing order in `stones`, and the frog wants to finish on the final stone.\n\nThe opening hop must cover exactly `1` unit. Suppose the previous hop covered `k` units; the next hop may cover `k - 1`, `k`, or `k + 1` units, and it must land on a stone ahead (jumps are always forward, and a hop of length zero or less is never allowed).\n\nDecide whether the last stone is reachable under these rules.\n\n**Constraints:**\n- `2 <= stones.length <= 2000`\n- `0 <= stones[i] <= 2^31 - 1`\n- `stones[0] == 0`\n- Positions are strictly increasing.\n", "solution": "## Approach\n\nKeep, for every stone, the collection of hop sizes that can arrive there. The start stone holds hop size 0, and the second stone must be at distance 1 or the answer is immediately false. Each reachable state (stone, k) tries onward hops of k-1, k and k+1 to later stones recorded in a position map. The final stone is reachable exactly when its set is non-empty.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n^2) in the worst case, where n is the stone count.\n- **Space Complexity:** O(n^2) for the stored hop sets in the worst case.\n\n## Implementation\n\n```python\nfrom typing import List\n\nclass Solution:\n def canCross(self, stones: List[int]) -> bool:\n n = len(stones)\n if n <= 1:\n return True\n if stones[1] != 1:\n return False\n index_of = {x: i for i, x in enumerate(stones)}\n reach = [set() for _ in range(n)]\n reach[0].add(0)\n for i in range(n):\n for k in list(reach[i]):\n for nk in (k - 1, k, k + 1):\n if nk <= 0:\n continue\n j = index_of.get(stones[i] + nk)\n if j is not None:\n reach[j].add(nk)\n return len(reach[n - 1]) > 0\n```\n", "starter": {"go": "package main\n\nfunc CanCross(stones []int) bool {\n \n}", "python": "from typing import List\n\nclass Solution:\n def canCross(self, stones: List[int]) -> bool:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n bool canCross(vector<int>& stones) {\n return false;\n }\n};"}, "fn": "canCross", "params": [{"name": "stones", "type": "int_array"}], "outputType": "boolean", "tests": [["[0,1,3,5,6,8,12,17]"], ["[0,1,2,3,4,8,9,11]"], ["[0,1]"], ["[0,2]"], ["[0,1,3,6]"], ["[0,1,3,6,10,15,21]"], ["[0,1,3,6,10,15,21,28]"], ["[0,1,2,3,4,5,6,7,8,9,10,11,12]"], ["[0,1,3,5,6,8,12,17,20]"], ["[0,1,3,5,6,8,12,17,22]"], ["[0,1,2,4,7,11,16,22]"], ["[0,1,2,4,7,11,16,22,29]"], ["[0,1,3,6,10,14,19,25]"], ["[0,2,3,5,8,12,17]"], ["[0,1,4,9,16,25]"], ["[0,1,2,3,4,5,100]"], ["[0,1,3,4,5,7,9,10,12]"], ["[0,1,3,6,9,13,18,24]"], ["[0,1,3,6,9,13,18,24,31]"], ["[0,1,2,5,9,14,20,27]"], ["[0,1,3,7,12,18,25,33]"], ["[0,1,2,3,5,8,12,17,23]"], ["[0,1,3,5,8,12,17,23,30]"], ["[0,1,2,3,4,6,9,13,18]"], ["[0,1,3,5,7,10,14,19,25]"], ["[0,1,2,4,8,13,19,26,34]"], ["[0,1,3,6,11,17,24,32,41]"], ["[0,1,2,6,11,17,24,32]"], ["[0,1,3,4,6,9,13,18,24,31]"], ["[0,1,2,3,4,5,6,7,8,9,10,20]"], ["[0,1,3,6,10,15,16,21]"]], "expected": [true, false, true, false, true, true, true, true, false, true, true, true, true, false, false, false, true, true, true, false, false, true, true, true, true, false, false, false, true, false, true], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "893", "slug": "fruit-into-baskets", "id": 893, "title": "Fruit Into Baskets", "difficulty": "Medium", "category": "array", "link": "https://leetcode.com/problems/fruit-into-baskets/", "examples": [{"input": "fruits = [1,2,1]", "output": "3", "explanation": "Whole row uses two kinds."}, {"input": "fruits = [0,1,2,2]", "output": "3", "explanation": "Best stretch is [1,2,2]."}, {"input": "fruits = [1,2,3,2,2]", "output": "4", "explanation": "Best stretch is [2,3,2,2]."}], "hints": ["Slide a window with left and right ends, keeping counts of each kind inside.", "When a third distinct kind enters, move the left end forward until only two kinds remain; record the largest window seen."], "statement": "A row of trees holds fruit kinds recorded in `fruits`, where each entry names the kind on that tree. You carry two baskets, each dedicated to a single kind (the two kinds may end up the same only if you never use the second basket). Starting at any tree and stepping rightward, you must take exactly one fruit per tree while the kinds fit into your two baskets, and you halt before the first tree whose kind would demand a third basket.\n\nFind the greatest number of fruits obtainable under those rules \u2014 equivalently, the length of the longest contiguous segment using at most two distinct values.\n\n**Constraints:**\n- `1 <= fruits.length <= 10^5`\n- `0 <= fruits[i] < fruits.length`\n", "solution": "## Approach\n\nMaintain a sliding window that never holds more than two fruit kinds. Expand the right edge one tree at a time while tallying kinds in a map; whenever a third kind appears, shift the left edge forward, decrementing counts until the window is legal again. The maximum window length encountered is the answer.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n) since each index moves at most once.\n- **Space Complexity:** O(1) for the at-most-two-entry map.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def totalFruit(self, fruits: List[int]) -> int:\n cnt = {}\n left = best = 0\n for right, v in enumerate(fruits):\n cnt[v] = cnt.get(v, 0) + 1\n while len(cnt) > 2:\n u = fruits[left]\n cnt[u] -= 1\n if cnt[u] == 0:\n del cnt[u]\n left += 1\n best = max(best, right - left + 1)\n return best\n```\n", "starter": {"go": "package main\n\nfunc TotalFruit(fruits []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def totalFruit(self, fruits: List[int]) -> int:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n int totalFruit(vector<int>& fruits) {\n return 0;\n }\n};"}, "fn": "totalFruit", "params": [{"name": "fruits", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,1]"], ["[0,1,2,2]"], ["[1,2,3,2,2]"], ["[1]"], ["[0,0,0]"], ["[1,2,3,4,5]"], ["[1,1,1,2,2]"], ["[3,3,3,1,2,1,1,2,3,3,4]"], ["[0,1,1,1,2,3,4]"], ["[1,2,1,2,1,2]"], ["[5,5,5,5]"], ["[1,0,1,4,1,4,1,2,3]"], ["[2,2,2,2,2]"], ["[0,1,0,1,0,1]"], ["[1,2,3,2,2,3,3,1]"], ["[0]"], ["[1,2]"], ["[1,2,3]"], ["[4,4,1,2,1]"], ["[0,0,1,1]"], ["[1,1,2,3,2,1]"], ["[2,1,2,3,2,1,1]"], ["[0,1,6,6,4,4,6]"], ["[1,2,3,4,3,2,1]"], ["[9,9,9,9,8]"], ["[1,0,3,3,3,3]"], ["[2,3,1,2,3,2,2]"], ["[0,2,1,2,2,0,1]"]], "expected": [3, 3, 4, 1, 3, 2, 5, 5, 4, 6, 4, 5, 5, 6, 6, 1, 2, 2, 3, 4, 3, 3, 5, 3, 5, 5, 4, 4], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "385", "slug": "game-of-life", "id": 385, "title": "Game of Life", "difficulty": "Medium", "category": "matrix", "link": "https://leetcode.com/problems/game-of-life/", "examples": [{"input": "board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]", "output": "[[0,0,0],[1,0,1],[0,1,1],[0,1,0]]", "explanation": "Standard glider step computed simultaneously from live-neighbor counts."}, {"input": "board = [[1,1],[1,0]]", "output": "[[1,1],[1,1]]", "explanation": "Three live cells around the dead corner bring it to life."}, {"input": "board = [[0]]", "output": "[[0]]", "explanation": "A lone dead cell stays dead."}], "hints": ["Adaptation: the original updates in place with void; here return the next board.", "Count the eight neighbors for each cell from a snapshot before writing any change.", "Live survives with 2-3 neighbors; dead becomes live with exactly 3."], "statement": "Compute one step of Conway's Game of Life.\n\nEach cell is live (`1`) or dead (`0`). Count its eight neighbors, then apply\nsimultaneously: a live cell with fewer than two or more than three live\nneighbors dies; a live cell with two or three lives on; a dead cell with\nexactly three becomes live.\n\n**Adaptation:** instead of a void in-place update, implement\n`gameOfLife(board)` returning the next-state board.\n\n**Constraints:**\n- `1 <= m, n <= 25`\n- `board[i][j]` is `0` or `1`.\n", "solution": "## Approach\n\nCopy neighbor counts from the original board, then decide each cell's next state with the four rules. Reading from the snapshot guarantees simultaneity.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(m * n) with constant neighbor work.\n- **Space Complexity:** O(m * n) for the next board.\n\n## Implementation\n\n```python\nfrom typing import List\nclass Solution:\n def gameOfLife(self, board: List[List[int]]) -> List[List[int]]:\n m, n = len(board), len(board[0])\n nxt = [[0] * n for _ in range(m)]\n for r in range(m):\n for c in range(n):\n live = 0\n for dr in (-1, 0, 1):\n for dc in (-1, 0, 1):\n if dr == 0 and dc == 0:\n continue\n nr, nc = r + dr, c + dc\n if 0 <= nr < m and 0 <= nc < n and board[nr][nc] == 1:\n live += 1\n if board[r][c] == 1:\n nxt[r][c] = 1 if live in (2, 3) else 0\n else:\n nxt[r][c] = 1 if live == 3 else 0\n return nxt\n```\n", "starter": {"go": "package main\n\nfunc GameOfLife(board [][]int) [][]int {\n \n}", "python": "from typing import List\nclass Solution:\n def gameOfLife(self, board: List[List[int]]) -> List[List[int]]:\n pass", "cpp": "#include <vector>\nusing namespace std;\nclass Solution {\npublic:\n vector<vector<int>> gameOfLife(vector<vector<int>>& board) {\n return {};\n }\n};"}, "fn": "gameOfLife", "params": [{"name": "board", "type": "int_array_2d"}], "outputType": "int_array_2d", "tests": [["[[0,1,0],[0,0,1],[1,1,1],[0,0,0]]"], ["[[1,1],[1,0]]"], ["[[0]]"], ["[[1]]"], ["[[0,0],[0,0]]"], ["[[1,1],[1,1]]"], ["[[0,1,0],[0,1,0],[0,1,0]]"], ["[[1,0,1],[0,1,0],[1,0,1]]"], ["[[0,0,0],[0,1,0],[0,0,0]]"], ["[[1,1,1],[1,1,1],[1,1,1]]"], ["[[0,1,0,0],[1,0,1,0],[0,1,0,0],[0,0,0,0]]"], ["[[1,0],[0,1]]"], ["[[1,0,0],[0,0,0],[0,0,1]]"], ["[[0,1],[1,1]]"], ["[[1,1,0],[1,0,1],[0,1,0]]"], ["[[1,1,1,1],[1,1,1,1],[1,1,1,1]]"], ["[[0,0,0],[0,0,0],[0,0,0]]"], ["[[0,0,0,0],[0,0,0,0]]"], ["[[1,0,1,0],[0,1,0,1],[1,0,1,0],[0,1,0,1]]"], ["[[1,1,0,0],[1,1,0,0],[0,0,1,1],[0,0,1,1]]"], ["[[0,1,0],[1,1,1],[0,1,0]]"], ["[[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[1,0,0,0,1]]"], ["[[1,1,1,1,1]]"], ["[[1],[0],[1],[0],[1]]"], ["[[0,1],[0,1],[0,1]]"], ["[[1,0,0],[1,0,0],[1,0,0]]"], ["[[1,1],[0,0]]"], ["[[0,0],[1,1]]"]], "expected": [[[0, 0, 0], [1, 0, 1], [0, 1, 1], [0, 1, 0]], [[1, 1], [1, 1]], [[0]], [[0]], [[0, 0], [0, 0]], [[1, 1], [1, 1]], [[0, 0, 0], [1, 1, 1], [0, 0, 0]], [[0, 1, 0], [1, 0, 1], [0, 1, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[1, 0, 1], [0, 0, 0], [1, 0, 1]], [[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]], [[0, 0], [0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[1, 1], [1, 1]], [[1, 1, 0], [1, 0, 1], [0, 1, 0]], [[1, 0, 0, 1], [0, 0, 0, 0], [1, 0, 0, 1]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0]], [[0, 1, 1, 0], [1, 0, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]], [[1, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 1]], [[1, 1, 1], [1, 0, 1], [1, 1, 1]], [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], [[0, 1, 1, 1, 0]], [[0], [0], [0], [0], [0]], [[0, 0], [1, 1], [0, 0]], [[0, 0, 0], [1, 1, 0], [0, 0, 0]], [[0, 0], [0, 0]], [[0, 0], [0, 0]]], "loose": false}
@@ -0,0 +1 @@
1
+ {"basic": false, "label": "140", "slug": "gas-station", "id": 140, "title": "Gas Station", "difficulty": "Medium", "category": "greedy", "link": "https://leetcode.com/problems/gas-station/", "examples": [{"input": "gas = [1,2,3,4,5], cost = [3,4,5,1,2]", "output": "3", "explanation": "Starting at station 3 allows a complete circuit without running out of fuel."}, {"input": "gas = [2,3,4], cost = [3,4,3]", "output": "-1", "explanation": "No starting station can complete the circuit (total gas < total cost)."}, {"input": "gas = [5], cost = [4]", "output": "0", "explanation": "Starting at station 0, there is enough gas (5) to cover the cost (4) and complete the circuit."}], "hints": ["A circuit is impossible when total gas is less than total cost.", "Track the running fuel balance from a candidate start while scanning the stations once.", "If the balance becomes negative at station i, no station from the current candidate through i can be a valid start, so try i + 1."], "statement": "There are `n` gas stations arranged in a circle. `gas[i]` is the fuel available at station `i`, and `cost[i]` is the fuel needed to drive from station `i` to station `(i + 1) mod n`.\n\nYou begin with an empty tank. Return the index from which you can complete one clockwise circuit without the tank becoming negative. If no such station exists, return `-1`. If a valid starting station exists, it is guaranteed to be unique.\n\n**Constraints:**\n\n- `gas.length == cost.length`\n- `1 <= gas.length <= 100000`\n- `0 <= gas[i], cost[i] <= 10000`\n- If a valid starting station exists, it is unique.\n", "solution": "## Approach\n\nTrack both the total fuel balance and the balance from the current candidate start. If the candidate balance becomes negative at station `i`, no station from the current candidate through `i` can be a valid start, so reset the candidate to `i + 1`. A negative total means no circuit exists; otherwise, the final candidate completes the circuit.\n\n## Complexity Analysis\n\n- **Time Complexity:** O(n), with one pass over the stations.\n- **Space Complexity:** O(1) auxiliary space.\n\n## Implementation\n\n```python\nfrom typing import List\n\n\nclass Solution:\n def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:\n total = 0\n tank = 0\n start = 0\n for index, (available, required) in enumerate(zip(gas, cost)):\n difference = available - required\n total += difference\n tank += difference\n if tank < 0:\n start = index + 1\n tank = 0\n return -1 if total < 0 else start % len(gas)\n```\n", "starter": {"go": "package main\n\nfunc CanCompleteCircuit(gas []int, cost []int) int {\n \n}", "python": "from typing import List\nclass Solution:\n def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int:\n pass\n", "cpp": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n int canCompleteCircuit(vector<int>& gas, vector<int>& cost) {\n return -1;\n }\n};"}, "fn": "canCompleteCircuit", "params": [{"name": "gas", "type": "int_array"}, {"name": "cost", "type": "int_array"}], "outputType": "int", "tests": [["[1,2,3,4,5]", "[3,4,5,1,2]"], ["[2,3,4]", "[3,4,3]"], ["[5]", "[4]"], ["[4]", "[5]"], ["[0]", "[0]"], ["[1,2]", "[2,1]"], ["[2,1]", "[1,2]"], ["[0,1]", "[1,0]"], ["[1,0]", "[0,1]"], ["[3,3,4]", "[3,4,4]"], ["[4,6,7,4]", "[6,5,5,5]"], ["[5,1,2,3,4]", "[4,4,1,5,1]"], ["[2,0,1]", "[1,2,0]"], ["[0,2,0]", "[1,0,1]"], ["[10,0,0]", "[3,3,3]"], ["[0,0,10]", "[3,3,3]"], ["[3,1,1]", "[1,2,2]"], ["[1,1,3]", "[2,2,1]"], ["[2,2,2]", "[1,2,3]"], ["[1,2,3]", "[2,3,1]"], ["[6,1,4,3,5]", "[3,8,2,4,2]"], ["[1,5,3,3,5,3,1,3,4,5]", "[5,2,2,8,2,4,2,5,1,2]"], ["[1,1,1,1]", "[2,2,2,2]"], ["[5,5,5,5]", "[6,6,6,2]"], ["[1,2,3,4]", "[4,3,2,1]"], ["[0,0,1,0]", "[0,1,0,0]"], ["[7,0,0,0]", "[2,2,2,1]"], ["[0,0,0,7]", "[2,2,1,2]"], ["[2,4,1,3]", "[3,1,2,4]"], ["[8,1,1,1,1]", "[2,2,2,2,4]"], ["[1,1,1,1,8]", "[2,2,2,4,2]"], ["[3,4,5,1,2]", "[4,5,1,2,3]"], ["[2,3,1,4]", "[3,1,4,2]"], ["[9,0,2,0,1]", "[3,3,3,1,2]"], ["[0,2,0,9,1]", "[3,1,3,2,3]"], ["[4,0,4,0]", "[2,3,1,2]"], ["[2,0,2,0]", "[1,2,0,1]"], ["[100,0,0]", "[30,30,40]"], ["[0,0,100]", "[30,40,30]"], ["[5,2,1,4,3]", "[4,3,2,3,3]"], ["[2,7,1,0,5]", "[3,2,4,1,5]"], ["[0,5,0,5,0]", "[2,1,3,1,3]"], ["[6,0,1,2]", "[2,3,3,1]"], ["[1,2,0,6]", "[2,2,3,1]"], ["[3,0,0,3]", "[1,2,1,2]"], ["[1,0,3,0]", "[2,1,0,1]"], ["[4,1,0,2,5]", "[3,2,1,4,2]"], ["[2,5,0,1,4]", "[3,1,3,1,4]"], ["[1,4,2,0,6]", "[2,2,3,3,3]"], ["[3,3,0,0,4]", "[2,4,1,2,1]"], ["[1,10,1]", "[5,1,6]"], ["[10,1,1]", "[1,6,5]"], ["[1,1,10]", "[6,5,1]"], ["[2,8,2,8]", "[5,3,8,4]"], ["[8,2,8,2]", "[3,8,2,7]"], ["[10000]", "[10000]"], ["@javascript:Array.from({length:50000},(_,i)=>i<5?10000:0)", "@javascript:Array.from({length:50000},(_,i)=>i<5?0:1)"]], "expected": [3, -1, 0, -1, 0, 1, 0, 1, 0, -1, 1, 4, 2, 1, 0, 2, 0, 2, 0, 2, 2, 8, -1, 3, 2, 2, 0, 3, 1, 0, 4, 2, 3, 0, 3, 2, 2, 0, 2, 3, 1, 1, 3, 3, 3, 2, 4, 1, 4, 4, 1, 0, 2, 3, 2, 0, 0], "loose": false}