├── 0 - 1 Knapsack Problem - GFG ├── 0-1-knapsack-problem.java └── README.md ├── 1-two-sum ├── 1-two-sum.java ├── NOTES.md └── README.md ├── 10-regular-expression-matching ├── 10-regular-expression-matching.java ├── NOTES.md └── README.md ├── 100-same-tree ├── 100-same-tree.java ├── NOTES.md └── README.md ├── 1004-max-consecutive-ones-iii ├── 1004-max-consecutive-ones-iii.java ├── NOTES.md └── README.md ├── 1005-maximize-sum-of-array-after-k-negations ├── 1005-maximize-sum-of-array-after-k-negations.java ├── NOTES.md └── README.md ├── 1007-minimum-domino-rotations-for-equal-row ├── 1007-minimum-domino-rotations-for-equal-row.java ├── NOTES.md └── README.md ├── 1008-construct-binary-search-tree-from-preorder-traversal ├── 1008-construct-binary-search-tree-from-preorder-traversal.java ├── NOTES.md └── README.md ├── 101-symmetric-tree ├── 101-symmetric-tree.java ├── NOTES.md └── README.md ├── 1010-pairs-of-songs-with-total-durations-divisible-by-60 ├── 1010-pairs-of-songs-with-total-durations-divisible-by-60.java ├── NOTES.md └── README.md ├── 1011-capacity-to-ship-packages-within-d-days ├── 1011-capacity-to-ship-packages-within-d-days.java ├── NOTES.md └── README.md ├── 102-binary-tree-level-order-traversal ├── 102-binary-tree-level-order-traversal.java ├── NOTES.md ├── README.md └── solution1.java ├── 103-binary-tree-zigzag-level-order-traversal ├── 103-binary-tree-zigzag-level-order-traversal.java ├── NOTES.md └── README.md ├── 1035-uncrossed-lines ├── 1035-uncrossed-lines.java ├── NOTES.md └── README.md ├── 1038-binary-search-tree-to-greater-sum-tree ├── 1038-binary-search-tree-to-greater-sum-tree.java ├── NOTES.md └── README.md ├── 104-maximum-depth-of-binary-tree ├── 104-maximum-depth-of-binary-tree.java ├── NOTES.md └── README.md ├── 1042-flower-planting-with-no-adjacent ├── 1042-flower-planting-with-no-adjacent.java ├── NOTES.md └── README.md ├── 1043-partition-array-for-maximum-sum ├── 1043-partition-array-for-maximum-sum.java ├── NOTES.md └── README.md ├── 1049-last-stone-weight-ii ├── 1049-last-stone-weight-ii.java ├── NOTES.md └── README.md ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal.java ├── NOTES.md └── README.md ├── 1052-grumpy-bookstore-owner ├── 1052-grumpy-bookstore-owner.java ├── NOTES.md └── README.md ├── 106-construct-binary-tree-from-inorder-and-postorder-traversal ├── 106-construct-binary-tree-from-inorder-and-postorder-traversal.java ├── NOTES.md └── README.md ├── 107-binary-tree-level-order-traversal-ii ├── 107-binary-tree-level-order-traversal-ii.java ├── NOTES.md └── README.md ├── 108-convert-sorted-array-to-binary-search-tree ├── 108-convert-sorted-array-to-binary-search-tree.java ├── NOTES.md └── README.md ├── 1081-smallest-subsequence-of-distinct-characters ├── 1081-smallest-subsequence-of-distinct-characters.java ├── NOTES.md └── README.md ├── 109-convert-sorted-list-to-binary-search-tree ├── 109-convert-sorted-list-to-binary-search-tree.java ├── NOTES.md └── README.md ├── 1092-shortest-common-supersequence ├── 1092-shortest-common-supersequence.java └── README.md ├── 1094-car-pooling ├── 1094-car-pooling.java ├── NOTES.md └── README.md ├── 1095-find-in-mountain-array ├── 1095-find-in-mountain-array.java ├── NOTES.md └── README.md ├── 11-container-with-most-water ├── 11-container-with-most-water.java ├── NOTES.md └── README.md ├── 110-balanced-binary-tree ├── 110-balanced-binary-tree.java ├── NOTES.md └── README.md ├── 111-minimum-depth-of-binary-tree ├── 111-minimum-depth-of-binary-tree.java ├── NOTES.md └── README.md ├── 112-path-sum ├── 112-path-sum.java ├── NOTES.md └── README.md ├── 1123-lowest-common-ancestor-of-deepest-leaves ├── 1123-lowest-common-ancestor-of-deepest-leaves.java ├── NOTES.md └── README.md ├── 113-path-sum-ii ├── 113-path-sum-ii.java ├── NOTES.md └── README.md ├── 1137-n-th-tribonacci-number ├── 1137-n-th-tribonacci-number.java └── README.md ├── 114-flatten-binary-tree-to-linked-list ├── 114-flatten-binary-tree-to-linked-list.java ├── NOTES.md ├── README.md └── illustrations.md ├── 1143-longest-common-subsequence ├── 1143-longest-common-subsequence.java ├── NOTES.md ├── README.md └── solution1.java ├── 115-distinct-subsequences ├── 115-distinct-subsequences.java ├── NOTES.md ├── README.md └── solution1.java ├── 1155-number-of-dice-rolls-with-target-sum ├── 1155-number-of-dice-rolls-with-target-sum.java ├── NOTES.md └── README.md ├── 116-populating-next-right-pointers-in-each-node ├── 116-populating-next-right-pointers-in-each-node.java ├── NOTES.md └── README.md ├── 1160-find-words-that-can-be-formed-by-characters ├── 1160-find-words-that-can-be-formed-by-characters.java ├── NOTES.md └── README.md ├── 117-populating-next-right-pointers-in-each-node-ii ├── 117-populating-next-right-pointers-in-each-node-ii.java ├── NOTES.md └── README.md ├── 118-pascals-triangle ├── 118-pascals-triangle.java └── README.md ├── 119-pascals-triangle-ii ├── 119-pascals-triangle-ii.java ├── NOTES.md └── README.md ├── 12-integer-to-roman ├── 12-integer-to-roman.java ├── NOTES.md └── README.md ├── 120-triangle ├── 120-triangle.java ├── NOTES.md └── README.md ├── 1209-remove-all-adjacent-duplicates-in-string-ii ├── 1209-remove-all-adjacent-duplicates-in-string-ii.java ├── NOTES.md ├── README.md └── solution1.java ├── 121-best-time-to-buy-and-sell-stock ├── 121-best-time-to-buy-and-sell-stock.java ├── NOTES.md └── README.md ├── 1219-path-with-maximum-gold ├── 1219-path-with-maximum-gold.java ├── NOTES.md └── README.md ├── 122-best-time-to-buy-and-sell-stock-ii ├── 122-best-time-to-buy-and-sell-stock-ii.java ├── NOTES.md └── README.md ├── 1220-count-vowels-permutation ├── 1220-count-vowels-permutation.java ├── NOTES.md ├── README.md └── solution1.java ├── 123-best-time-to-buy-and-sell-stock-iii ├── 123-best-time-to-buy-and-sell-stock-iii.java ├── NOTES.md └── README.md ├── 1232-check-if-it-is-a-straight-line ├── 1232-check-if-it-is-a-straight-line.java ├── NOTES.md └── README.md ├── 1235-maximum-profit-in-job-scheduling ├── 1235-maximum-profit-in-job-scheduling.java └── README.md ├── 124-binary-tree-maximum-path-sum ├── 124-binary-tree-maximum-path-sum.java ├── NOTES.md └── README.md ├── 125-valid-palindrome ├── 125-valid-palindrome.java ├── NOTES.md └── README.md ├── 127-word-ladder ├── 127-word-ladder.java ├── NOTES.md └── README.md ├── 1277-count-square-submatrices-with-all-ones ├── 1277-count-square-submatrices-with-all-ones.java ├── NOTES.md └── README.md ├── 1278-palindrome-partitioning-iii ├── 1278-palindrome-partitioning-iii.java ├── NOTES.md └── README.md ├── 128-longest-consecutive-sequence ├── 128-longest-consecutive-sequence.java ├── NOTES.md └── README.md ├── 129-sum-root-to-leaf-numbers ├── 129-sum-root-to-leaf-numbers.java ├── NOTES.md └── README.md ├── 1291-sequential-digits ├── 1291-sequential-digits.java ├── NOTES.md └── README.md ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination.java ├── NOTES.md └── README.md ├── 13-roman-to-integer ├── 13-roman-to-integer.java ├── NOTES.md └── README.md ├── 130-surrounded-regions ├── 130-surrounded-regions.java ├── NOTES.md └── README.md ├── 1306-jump-game-iii ├── 1306-jump-game-iii.java └── README.md ├── 131-palindrome-partitioning ├── 131-palindrome-partitioning.java ├── NOTES.md └── README.md ├── 1312-minimum-insertion-steps-to-make-a-string-palindrome ├── 1312-minimum-insertion-steps-to-make-a-string-palindrome.java ├── NOTES.md └── README.md ├── 1319-number-of-operations-to-make-network-connected ├── 1319-number-of-operations-to-make-network-connected.java ├── NOTES.md ├── README.md └── solution1.java ├── 132-palindrome-partitioning-ii ├── 132-palindrome-partitioning-ii.java └── README.md ├── 1323-maximum-69-number ├── 1323-maximum-69-number.java ├── NOTES.md └── README.md ├── 1326-minimum-number-of-taps-to-open-to-water-a-garden ├── 1326-minimum-number-of-taps-to-open-to-water-a-garden.java ├── NOTES.md └── README.md ├── 133-clone-graph ├── 133-clone-graph.java ├── NOTES.md └── README.md ├── 1332-remove-palindromic-subsequences ├── 1332-remove-palindromic-subsequences.java ├── NOTES.md └── README.md ├── 1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance ├── 1334-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.java ├── NOTES.md └── README.md ├── 1338-reduce-array-size-to-the-half ├── 1338-reduce-array-size-to-the-half.java ├── NOTES.md └── README.md ├── 134-gas-station ├── 134-gas-station.java ├── NOTES.md └── README.md ├── 1340-jump-game-v ├── 1340-jump-game-v.java ├── NOTES.md └── README.md ├── 1345-jump-game-iv ├── 1345-jump-game-iv.java ├── NOTES.md └── README.md ├── 135-candy ├── 135-candy.java ├── NOTES.md └── README.md ├── 1353-maximum-number-of-events-that-can-be-attended ├── 1353-maximum-number-of-events-that-can-be-attended.java ├── NOTES.md └── README.md ├── 136-single-number ├── 136-single-number.java └── README.md ├── 1367-linked-list-in-binary-tree ├── 1367-linked-list-in-binary-tree.java ├── NOTES.md └── README.md ├── 137-single-number-ii ├── 137-single-number-ii.java ├── NOTES.md └── README.md ├── 1372-longest-zigzag-path-in-a-binary-tree ├── 1372-longest-zigzag-path-in-a-binary-tree.java ├── NOTES.md └── README.md ├── 1373-maximum-sum-bst-in-binary-tree ├── 1373-maximum-sum-bst-in-binary-tree.java ├── NOTES.md └── README.md ├── 1374-generate-a-string-with-characters-that-have-odd-counts ├── 1374-generate-a-string-with-characters-that-have-odd-counts.java ├── NOTES.md └── README.md ├── 1376-time-needed-to-inform-all-employees ├── 1376-time-needed-to-inform-all-employees.java ├── NOTES.md └── README.md ├── 1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree ├── 1379-find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree.java ├── NOTES.md └── README.md ├── 138-copy-list-with-random-pointer ├── 138-copy-list-with-random-pointer.java ├── NOTES.md └── README.md ├── 139-word-break ├── 139-word-break.java ├── NOTES.md └── README.md ├── 14-longest-common-prefix ├── 14-longest-common-prefix.java ├── NOTES.md └── README.md ├── 140-word-break-ii ├── 140-word-break-ii.java └── README.md ├── 141-linked-list-cycle ├── 141-linked-list-cycle.java ├── NOTES.md └── README.md ├── 1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k ├── 1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k.java ├── NOTES.md └── README.md ├── 142-linked-list-cycle-ii ├── 142-linked-list-cycle-ii.java ├── NOTES.md └── README.md ├── 1423-maximum-points-you-can-obtain-from-cards ├── 1423-maximum-points-you-can-obtain-from-cards.java ├── NOTES.md └── README.md ├── 1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit ├── 1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit.java ├── NOTES.md └── README.md ├── 144-binary-tree-preorder-traversal ├── 144-binary-tree-preorder-traversal.java ├── NOTES.md └── README.md ├── 145-binary-tree-postorder-traversal ├── 145-binary-tree-postorder-traversal.java ├── NOTES.md └── README.md ├── 146-lru-cache ├── 146-lru-cache.java ├── NOTES.md └── README.md ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.java ├── NOTES.md └── README.md ├── 148-sort-list ├── 148-sort-list.java ├── NOTES.md └── README.md ├── 1480-running-sum-of-1d-array ├── 1480-running-sum-of-1d-array.java ├── NOTES.md └── README.md ├── 1483-kth-ancestor-of-a-tree-node ├── 1483-kth-ancestor-of-a-tree-node.java ├── NOTES.md └── README.md ├── 149-max-points-on-a-line ├── 149-max-points-on-a-line.java ├── NOTES.md └── README.md ├── 1492-the-kth-factor-of-n ├── 1492-the-kth-factor-of-n.java ├── NOTES.md └── README.md ├── 1498-number-of-subsequences-that-satisfy-the-given-sum-condition ├── 1498-number-of-subsequences-that-satisfy-the-given-sum-condition.java ├── NOTES.md └── README.md ├── 15-3sum ├── 15-3sum.java ├── NOTES.md └── README.md ├── 150-evaluate-reverse-polish-notation ├── 150-evaluate-reverse-polish-notation.java ├── NOTES.md └── README.md ├── 1514-path-with-maximum-probability ├── 1514-path-with-maximum-probability.java ├── NOTES.md └── README.md ├── 152-maximum-product-subarray ├── 152-maximum-product-subarray.java ├── NOTES.md └── README.md ├── 153-find-minimum-in-rotated-sorted-array ├── 153-find-minimum-in-rotated-sorted-array.java ├── NOTES.md └── README.md ├── 1539-kth-missing-positive-number ├── 1539-kth-missing-positive-number.java ├── NOTES.md ├── README.md └── solution1.java ├── 154-find-minimum-in-rotated-sorted-array-ii ├── 154-find-minimum-in-rotated-sorted-array-ii.java ├── NOTES.md └── README.md ├── 155-min-stack ├── 155-min-stack.java └── README.md ├── 1559-detect-cycles-in-2d-grid ├── 1559-detect-cycles-in-2d-grid.java └── README.md ├── 16-3sum-closest ├── 16-3sum-closest.java ├── NOTES.md └── README.md ├── 160-intersection-of-two-linked-lists ├── 160-intersection-of-two-linked-lists.java └── README.md ├── 162-find-peak-element ├── 162-find-peak-element.java ├── NOTES.md └── README.md ├── 1631-path-with-minimum-effort ├── 1631-path-with-minimum-effort.java └── README.md ├── 1636-sort-array-by-increasing-frequency ├── 1636-sort-array-by-increasing-frequency.java ├── NOTES.md └── README.md ├── 1647-minimum-deletions-to-make-character-frequencies-unique ├── 1647-minimum-deletions-to-make-character-frequencies-unique.java ├── NOTES.md └── README.md ├── 1653-minimum-deletions-to-make-string-balanced ├── 1653-minimum-deletions-to-make-string-balanced.java └── README.md ├── 1654-minimum-jumps-to-reach-home ├── 1654-minimum-jumps-to-reach-home.java ├── NOTES.md └── README.md ├── 1658-minimum-operations-to-reduce-x-to-zero ├── 1658-minimum-operations-to-reduce-x-to-zero.java ├── NOTES.md └── README.md ├── 1669-merge-in-between-linked-lists ├── 1669-merge-in-between-linked-lists.java ├── NOTES.md └── README.md ├── 167-two-sum-ii-input-array-is-sorted ├── 167-two-sum-ii-input-array-is-sorted.java ├── NOTES.md └── README.md ├── 1671-minimum-number-of-removals-to-make-mountain-array ├── 1671-minimum-number-of-removals-to-make-mountain-array.java ├── NOTES.md └── README.md ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers ├── 1689-partitioning-into-minimum-number-of-deci-binary-numbers.java ├── NOTES.md └── README.md ├── 169-majority-element ├── 169-majority-element.java ├── NOTES.md └── README.md ├── 1695-maximum-erasure-value ├── 1695-maximum-erasure-value.java ├── NOTES.md └── README.md ├── 1696-jump-game-vi ├── 1696-jump-game-vi.java ├── NOTES.md └── README.md ├── 17-letter-combinations-of-a-phone-number ├── 17-letter-combinations-of-a-phone-number.java ├── NOTES.md ├── README.md └── solution1.java ├── 171-excel-sheet-column-number ├── 171-excel-sheet-column-number.java ├── NOTES.md └── README.md ├── 1710-maximum-units-on-a-truck ├── 1710-maximum-units-on-a-truck.java ├── NOTES.md └── README.md ├── 172-factorial-trailing-zeroes ├── 172-factorial-trailing-zeroes.java ├── NOTES.md └── README.md ├── 1723-find-minimum-time-to-finish-all-jobs ├── 1723-find-minimum-time-to-finish-all-jobs.java ├── NOTES.md └── README.md ├── 173-binary-search-tree-iterator ├── 173-binary-search-tree-iterator.java ├── NOTES.md └── README.md ├── 1745-palindrome-partitioning-iv ├── 1745-palindrome-partitioning-iv.java ├── NOTES.md └── README.md ├── 175-combine-two-tables ├── 175-combine-two-tables.sql ├── NOTES.md └── README.md ├── 1775-equal-sum-arrays-with-minimum-number-of-operations ├── 1775-equal-sum-arrays-with-minimum-number-of-operations.java ├── NOTES.md └── README.md ├── 179-largest-number ├── 179-largest-number.java ├── NOTES.md └── README.md ├── 18-4sum ├── 18-4sum.java ├── NOTES.md └── README.md ├── 1823-find-the-winner-of-the-circular-game ├── 1823-find-the-winner-of-the-circular-game.java ├── NOTES.md └── README.md ├── 1828-queries-on-number-of-points-inside-a-circle ├── 1828-queries-on-number-of-points-inside-a-circle.java ├── NOTES.md └── README.md ├── 1865-finding-pairs-with-a-certain-sum ├── 1865-finding-pairs-with-a-certain-sum.java ├── NOTES.md └── README.md ├── 1871-jump-game-vii ├── 1871-jump-game-vii.java ├── NOTES.md └── README.md ├── 188-best-time-to-buy-and-sell-stock-iv ├── 188-best-time-to-buy-and-sell-stock-iv.java ├── NOTES.md ├── README.md └── solution1.java ├── 1888-minimum-number-of-flips-to-make-the-binary-string-alternating ├── 1888-minimum-number-of-flips-to-make-the-binary-string-alternating.java ├── NOTES.md └── README.md ├── 189-rotate-array ├── 189-rotate-array.java ├── NOTES.md └── README.md ├── 19-remove-nth-node-from-end-of-list ├── 19-remove-nth-node-from-end-of-list.java ├── NOTES.md └── README.md ├── 190-reverse-bits ├── 190-reverse-bits.java ├── NOTES.md └── README.md ├── 191-number-of-1-bits ├── 191-number-of-1-bits.java ├── NOTES.md └── README.md ├── 1926-nearest-exit-from-entrance-in-maze ├── 1926-nearest-exit-from-entrance-in-maze.java ├── NOTES.md └── README.md ├── 1963-minimum-number-of-swaps-to-make-the-string-balanced ├── 1963-minimum-number-of-swaps-to-make-the-string-balanced.java └── README.md ├── 198-house-robber ├── 198-house-robber.java ├── NOTES.md └── README.md ├── 199-binary-tree-right-side-view ├── 199-binary-tree-right-side-view.java ├── NOTES.md └── README.md ├── 1991-find-the-middle-index-in-array ├── 1991-find-the-middle-index-in-array.java ├── NOTES.md └── README.md ├── 2-add-two-numbers ├── 2-add-two-numbers.java ├── NOTES.md └── README.md ├── 20-valid-parentheses ├── 20-valid-parentheses.java ├── NOTES.md └── README.md ├── 200-number-of-islands ├── 200-number-of-islands.java └── README.md ├── 2008-maximum-earnings-from-taxi ├── 2008-maximum-earnings-from-taxi.java ├── NOTES.md └── README.md ├── 201-bitwise-and-of-numbers-range ├── 201-bitwise-and-of-numbers-range.java └── README.md ├── 202-happy-number ├── 202-happy-number.java ├── NOTES.md └── README.md ├── 203-remove-linked-list-elements ├── 203-remove-linked-list-elements.java ├── NOTES.md └── README.md ├── 204-count-primes ├── 204-count-primes.java ├── NOTES.md └── README.md ├── 2057-smallest-index-with-equal-value ├── 2057-smallest-index-with-equal-value.java ├── NOTES.md └── README.md ├── 206-reverse-linked-list ├── 206-reverse-linked-list.java ├── NOTES.md └── README.md ├── 207-course-schedule ├── 207-course-schedule.java ├── NOTES.md └── README.md ├── 209-minimum-size-subarray-sum ├── 209-minimum-size-subarray-sum.java ├── NOTES.md └── README.md ├── 2091-removing-minimum-and-maximum-from-array ├── 2091-removing-minimum-and-maximum-from-array.java ├── NOTES.md └── README.md ├── 21-merge-two-sorted-lists ├── 21-merge-two-sorted-lists.java ├── NOTES.md └── README.md ├── 210-course-schedule-ii ├── 210-course-schedule-ii.java ├── NOTES.md └── README.md ├── 2101-detonate-the-maximum-bombs ├── 2101-detonate-the-maximum-bombs.java ├── NOTES.md └── README.md ├── 213-house-robber-ii ├── 213-house-robber-ii.java ├── NOTES.md └── README.md ├── 2139-minimum-moves-to-reach-target-score ├── 2139-minimum-moves-to-reach-target-score.java └── README.md ├── 2140-solving-questions-with-brainpower ├── 2140-solving-questions-with-brainpower.java ├── NOTES.md └── README.md ├── 2149-rearrange-array-elements-by-sign ├── 2149-rearrange-array-elements-by-sign.java ├── NOTES.md └── README.md ├── 215-kth-largest-element-in-an-array ├── 215-kth-largest-element-in-an-array.java ├── NOTES.md └── README.md ├── 216-combination-sum-iii ├── 216-combination-sum-iii.java ├── NOTES.md └── README.md ├── 217-contains-duplicate ├── 217-contains-duplicate.java ├── NOTES.md └── README.md ├── 2183-count-array-pairs-divisible-by-k ├── 2183-count-array-pairs-divisible-by-k.java ├── NOTES.md └── README.md ├── 219-contains-duplicate-ii ├── 219-contains-duplicate-ii.java ├── NOTES.md └── README.md ├── 22-generate-parentheses ├── 22-generate-parentheses.java ├── NOTES.md ├── README.md └── solution1.java ├── 2206-divide-array-into-equal-pairs ├── 2206-divide-array-into-equal-pairs.java └── README.md ├── 221-maximal-square ├── 221-maximal-square.java ├── NOTES.md ├── README.md ├── solution1.java └── solution2.java ├── 222-count-complete-tree-nodes ├── 222-count-complete-tree-nodes.java ├── NOTES.md └── README.md ├── 2236-root-equals-sum-of-children ├── 2236-root-equals-sum-of-children.java ├── NOTES.md └── README.md ├── 224-basic-calculator ├── 224-basic-calculator.java ├── NOTES.md └── README.md ├── 2248-intersection-of-multiple-arrays ├── 2248-intersection-of-multiple-arrays.java ├── NOTES.md └── README.md ├── 225-implement-stack-using-queues ├── 225-implement-stack-using-queues.java ├── NOTES.md ├── README.md └── solution1.java ├── 226-invert-binary-tree ├── 226-invert-binary-tree.java ├── NOTES.md └── README.md ├── 227-basic-calculator-ii ├── 227-basic-calculator-ii.java ├── NOTES.md └── README.md ├── 2276-count-integers-in-intervals ├── 2276-count-integers-in-intervals.java ├── NOTES.md └── README.md ├── 2288-apply-discount-to-prices ├── 2288-apply-discount-to-prices.java ├── NOTES.md └── README.md ├── 2289-steps-to-make-array-non-decreasing ├── 2289-steps-to-make-array-non-decreasing.java ├── NOTES.md └── README.md ├── 229-majority-element-ii ├── 229-majority-element-ii.java ├── NOTES.md └── README.md ├── 23-merge-k-sorted-lists ├── 23-merge-k-sorted-lists.java ├── NOTES.md ├── README.md └── solution1.java ├── 230-kth-smallest-element-in-a-bst ├── 230-kth-smallest-element-in-a-bst.java ├── NOTES.md └── README.md ├── 2300-successful-pairs-of-spells-and-potions ├── 2300-successful-pairs-of-spells-and-potions.java ├── NOTES.md └── README.md ├── 231-power-of-two ├── 231-power-of-two.java └── NOTES.md ├── 232-implement-queue-using-stacks ├── 232-implement-queue-using-stacks.java ├── NOTES.md ├── README.md └── solution1.java ├── 234-palindrome-linked-list ├── 234-palindrome-linked-list.java └── README.md ├── 235-lowest-common-ancestor-of-a-binary-search-tree ├── 235-lowest-common-ancestor-of-a-binary-search-tree.java ├── NOTES.md └── README.md ├── 236-lowest-common-ancestor-of-a-binary-tree ├── 236-lowest-common-ancestor-of-a-binary-tree.java ├── NOTES.md └── README.md ├── 237-delete-node-in-a-linked-list ├── 237-delete-node-in-a-linked-list.java ├── NOTES.md └── README.md ├── 2370-longest-ideal-subsequence ├── 2370-longest-ideal-subsequence.java ├── NOTES.md ├── README.md └── solution1.java ├── 238-product-of-array-except-self ├── 238-product-of-array-except-self.java ├── NOTES.md └── README.md ├── 239-sliding-window-maximum ├── 239-sliding-window-maximum.java ├── NOTES.md └── README.md ├── 24-swap-nodes-in-pairs ├── 24-swap-nodes-in-pairs.java ├── NOTES.md └── README.md ├── 240-search-a-2d-matrix-ii ├── 240-search-a-2d-matrix-ii.java └── README.md ├── 25-reverse-nodes-in-k-group ├── 25-reverse-nodes-in-k-group.java ├── NOTES.md └── README.md ├── 257-binary-tree-paths ├── 257-binary-tree-paths.java ├── NOTES.md └── README.md ├── 258-add-digits ├── 258-add-digits.java ├── NOTES.md └── README.md ├── 26-remove-duplicates-from-sorted-array ├── 26-remove-duplicates-from-sorted-array.java ├── NOTES.md └── README.md ├── 260-single-number-iii ├── 260-single-number-iii.java ├── NOTES.md └── README.md ├── 263-ugly-number ├── 263-ugly-number.java ├── NOTES.md └── README.md ├── 264-ugly-number-ii ├── 264-ugly-number-ii.java ├── NOTES.md └── README.md ├── 268-missing-number ├── 268-missing-number.java └── NOTES.md ├── 27-remove-element ├── 27-remove-element.java ├── NOTES.md └── README.md ├── 279-perfect-squares ├── 279-perfect-squares.java ├── NOTES.md └── README.md ├── 28-implement-strstr ├── 28-implement-strstr.java ├── NOTES.md └── README.md ├── 283-move-zeroes ├── 283-move-zeroes.java └── README.md ├── 287-find-the-duplicate-number ├── 287-find-the-duplicate-number.java ├── NOTES.md └── README.md ├── 29-divide-two-integers ├── 29-divide-two-integers.java ├── NOTES.md └── README.md ├── 297-serialize-and-deserialize-binary-tree ├── 297-serialize-and-deserialize-binary-tree.java ├── NOTES.md └── README.md ├── 3-longest-substring-without-repeating-characters ├── 3-longest-substring-without-repeating-characters.java ├── NOTES.md └── README.md ├── 30-substring-with-concatenation-of-all-words ├── 30-substring-with-concatenation-of-all-words.java ├── NOTES.md └── README.md ├── 300-longest-increasing-subsequence ├── 300-longest-increasing-subsequence.java ├── NOTES.md ├── README.md ├── solution1.java └── solution2.java ├── 309-best-time-to-buy-and-sell-stock-with-cooldown ├── 309-best-time-to-buy-and-sell-stock-with-cooldown.java ├── NOTES.md └── README.md ├── 31-next-permutation ├── 31-next-permutation.java ├── NOTES.md └── README.md ├── 310-minimum-height-trees ├── 310-minimum-height-trees.java ├── NOTES.md └── README.md ├── 312-burst-balloons ├── 312-burst-balloons.java ├── NOTES.md └── README.md ├── 316-remove-duplicate-letters ├── 316-remove-duplicate-letters.java ├── NOTES.md └── README.md ├── 32-longest-valid-parentheses ├── 32-longest-valid-parentheses.java ├── NOTES.md └── README.md ├── 322-coin-change ├── 322-coin-change.java ├── NOTES.md └── README.md ├── 328-odd-even-linked-list ├── 328-odd-even-linked-list.java ├── NOTES.md └── README.md ├── 329-longest-increasing-path-in-a-matrix ├── 329-longest-increasing-path-in-a-matrix.java └── README.md ├── 33-search-in-rotated-sorted-array ├── 33-search-in-rotated-sorted-array.java ├── NOTES.md └── README.md ├── 337-house-robber-iii ├── 337-house-robber-iii.java ├── NOTES.md └── README.md ├── 338-counting-bits ├── 338-counting-bits.java ├── NOTES.md ├── README.md └── solution1.java ├── 34-find-first-and-last-position-of-element-in-sorted-array ├── 34-find-first-and-last-position-of-element-in-sorted-array.java └── README.md ├── 343-integer-break ├── 343-integer-break.java ├── NOTES.md └── README.md ├── 344-reverse-string ├── 344-reverse-string.java ├── NOTES.md └── README.md ├── 347-top-k-frequent-elements ├── 347-top-k-frequent-elements.java ├── NOTES.md └── README.md ├── 349-intersection-of-two-arrays ├── 349-intersection-of-two-arrays.java ├── NOTES.md └── README.md ├── 35-search-insert-position ├── 35-search-insert-position.java ├── NOTES.md └── README.md ├── 350-intersection-of-two-arrays-ii ├── 350-intersection-of-two-arrays-ii.java ├── NOTES.md └── README.md ├── 357-count-numbers-with-unique-digits ├── 357-count-numbers-with-unique-digits.java ├── NOTES.md └── README.md ├── 36-valid-sudoku ├── 36-valid-sudoku.java ├── NOTES.md └── README.md ├── 365-water-and-jug-problem ├── 365-water-and-jug-problem.java ├── NOTES.md ├── README.md └── solution1.java ├── 367-valid-perfect-square ├── 367-valid-perfect-square.java └── NOTES.md ├── 37-sudoku-solver ├── 37-sudoku-solver.java ├── NOTES.md └── README.md ├── 372-super-pow ├── 372-super-pow.java ├── NOTES.md └── README.md ├── 373-find-k-pairs-with-smallest-sums ├── 373-find-k-pairs-with-smallest-sums.java └── README.md ├── 374-guess-number-higher-or-lower ├── 374-guess-number-higher-or-lower.java ├── NOTES.md └── README.md ├── 377-combination-sum-iv ├── 377-combination-sum-iv.java ├── NOTES.md └── README.md ├── 378-kth-smallest-element-in-a-sorted-matrix ├── 378-kth-smallest-element-in-a-sorted-matrix.java └── README.md ├── 38-count-and-say ├── 38-count-and-say.java ├── NOTES.md └── README.md ├── 386-lexicographical-numbers ├── 386-lexicographical-numbers.java ├── NOTES.md └── README.md ├── 389-find-the-difference ├── 389-find-the-difference.java └── NOTES.md ├── 39-combination-sum ├── 39-combination-sum.java └── README.md ├── 392-is-subsequence ├── 392-is-subsequence.java ├── NOTES.md └── README.md ├── 394-decode-string ├── 394-decode-string.java ├── NOTES.md └── README.md ├── 397-integer-replacement ├── 397-integer-replacement.java ├── NOTES.md ├── README.md └── solution1.java ├── 399-evaluate-division ├── 399-evaluate-division.java ├── NOTES.md └── README.md ├── 4-median-of-two-sorted-arrays ├── 4-median-of-two-sorted-arrays.java ├── NOTES.md ├── README.md └── solution1.java ├── 40-combination-sum-ii ├── 40-combination-sum-ii.java ├── NOTES.md └── README.md ├── 400-nth-digit ├── 400-nth-digit.java ├── NOTES.md └── README.md ├── 406-queue-reconstruction-by-height ├── 406-queue-reconstruction-by-height.java ├── NOTES.md └── README.md ├── 409-longest-palindrome ├── 409-longest-palindrome.java ├── NOTES.md └── README.md ├── 41-first-missing-positive ├── 41-first-missing-positive.java ├── NOTES.md └── README.md ├── 412-fizz-buzz ├── 412-fizz-buzz.java ├── NOTES.md └── README.md ├── 415-add-strings ├── 415-add-strings.java └── README.md ├── 416-partition-equal-subset-sum ├── 416-partition-equal-subset-sum.java ├── NOTES.md └── README.md ├── 42-trapping-rain-water ├── 42-trapping-rain-water.java ├── NOTES.md └── README.md ├── 421-maximum-xor-of-two-numbers-in-an-array ├── 421-maximum-xor-of-two-numbers-in-an-array.java ├── NOTES.md └── README.md ├── 429-n-ary-tree-level-order-traversal ├── 429-n-ary-tree-level-order-traversal.java └── README.md ├── 43-multiply-strings ├── 43-multiply-strings.java ├── NOTES.md ├── README.md └── solution1.java ├── 435-non-overlapping-intervals ├── 435-non-overlapping-intervals.java ├── NOTES.md └── README.md ├── 437-path-sum-iii ├── 437-path-sum-iii.java ├── NOTES.md ├── README.md └── solution1.java ├── 438-find-all-anagrams-in-a-string ├── 438-find-all-anagrams-in-a-string.java └── README.md ├── 44-wildcard-matching ├── 44-wildcard-matching.java ├── NOTES.md └── README.md ├── 442-find-all-duplicates-in-an-array ├── 442-find-all-duplicates-in-an-array.java ├── NOTES.md └── README.md ├── 445-add-two-numbers-ii ├── 445-add-two-numbers-ii.java ├── NOTES.md └── README.md ├── 45-jump-game-ii ├── 45-jump-game-ii.java ├── NOTES.md ├── README.md ├── solution1.java └── solution2.java ├── 450-delete-node-in-a-bst ├── 450-delete-node-in-a-bst.java ├── NOTES.md ├── README.md └── illustrations.md ├── 452-minimum-number-of-arrows-to-burst-balloons ├── 452-minimum-number-of-arrows-to-burst-balloons.java ├── NOTES.md └── README.md ├── 453-minimum-moves-to-equal-array-elements ├── 453-minimum-moves-to-equal-array-elements.java ├── NOTES.md └── README.md ├── 455-assign-cookies ├── 455-assign-cookies.java ├── NOTES.md └── README.md ├── 46-permutations ├── 46-permutations.java ├── NOTES.md └── README.md ├── 462-minimum-moves-to-equal-array-elements-ii ├── 462-minimum-moves-to-equal-array-elements-ii.java ├── NOTES.md └── README.md ├── 468-validate-ip-address ├── 468-validate-ip-address.java └── README.md ├── 47-permutations-ii ├── 47-permutations-ii.java ├── NOTES.md ├── README.md └── UniquePermutationsOfAStringInLexicograhicOrder.java ├── 474-ones-and-zeroes ├── 474-ones-and-zeroes.java ├── NOTES.md └── README.md ├── 48-rotate-image ├── 48-rotate-image.java └── README.md ├── 485-max-consecutive-ones ├── 485-max-consecutive-ones.java ├── NOTES.md └── README.md ├── 49-group-anagrams ├── 49-group-anagrams.java ├── NOTES.md └── README.md ├── 491-increasing-subsequences ├── 491-increasing-subsequences.java ├── NOTES.md └── README.md ├── 493-reverse-pairs ├── 493-reverse-pairs.java ├── NOTES.md └── README.md ├── 494-target-sum ├── 494-target-sum.java ├── NOTES.md └── README.md ├── 496-next-greater-element-i ├── 496-next-greater-element-i.java ├── NOTES.md └── README.md ├── 498-diagonal-traverse ├── 498-diagonal-traverse.java ├── NOTES.md ├── README.md └── solution1.java ├── 5-longest-palindromic-substring ├── 5-longest-palindromic-substring.java ├── NOTES.md └── README.md ├── 50-powx-n ├── 50-powx-n.java ├── NOTES.md └── README.md ├── 501-find-mode-in-binary-search-tree ├── 501-find-mode-in-binary-search-tree.java ├── NOTES.md └── README.md ├── 503-next-greater-element-ii ├── 503-next-greater-element-ii.java ├── NOTES.md └── README.md ├── 508-most-frequent-subtree-sum ├── 508-most-frequent-subtree-sum.java └── README.md ├── 509-fibonacci-number ├── 509-fibonacci-number.java └── README.md ├── 51-n-queens ├── 51-n-queens.java ├── NOTES.md ├── README.md └── solution1.java ├── 513-find-bottom-left-tree-value ├── 513-find-bottom-left-tree-value.java ├── NOTES.md └── README.md ├── 515-find-largest-value-in-each-tree-row ├── 515-find-largest-value-in-each-tree-row.java ├── NOTES.md └── README.md ├── 516-longest-palindromic-subsequence ├── 516-longest-palindromic-subsequence.java └── README.md ├── 518-coin-change-2 ├── 518-coin-change-2.java ├── NOTES.md └── README.md ├── 52-n-queens-ii ├── 52-n-queens-ii.java ├── NOTES.md └── README.md ├── 523-continuous-subarray-sum ├── 523-continuous-subarray-sum.java ├── NOTES.md └── README.md ├── 529-minesweeper ├── 529-minesweeper.java ├── NOTES.md └── README.md ├── 53-maximum-subarray ├── 53-maximum-subarray.java ├── NOTES.md └── README.md ├── 530-minimum-absolute-difference-in-bst ├── 530-minimum-absolute-difference-in-bst.java ├── NOTES.md └── README.md ├── 538-convert-bst-to-greater-tree ├── 538-convert-bst-to-greater-tree.java ├── NOTES.md └── README.md ├── 539-minimum-time-difference ├── 539-minimum-time-difference.java ├── NOTES.md ├── README.md └── solution1.java ├── 54-spiral-matrix ├── 54-spiral-matrix.java ├── NOTES.md └── README.md ├── 542-01-matrix ├── 542-01-matrix.java ├── NOTES.md └── README.md ├── 543-diameter-of-binary-tree ├── 543-diameter-of-binary-tree.java ├── NOTES.md ├── README.md └── solution1.java ├── 547-number-of-provinces ├── 547-number-of-provinces.java ├── NOTES.md └── README.md ├── 55-jump-game ├── 55-jump-game.java ├── NOTES.md ├── README.md ├── solution1.java └── solution2.java ├── 552-student-attendance-record-ii ├── 552-student-attendance-record-ii.java ├── NOTES.md └── README.md ├── 56-merge-intervals ├── 56-merge-intervals.java ├── NOTES.md └── README.md ├── 560-subarray-sum-equals-k ├── 560-subarray-sum-equals-k.java ├── NOTES.md └── README.md ├── 57-insert-interval ├── 57-insert-interval.java ├── NOTES.md └── README.md ├── 576-out-of-boundary-paths ├── 576-out-of-boundary-paths.java └── README.md ├── 58-length-of-last-word ├── 58-length-of-last-word.java ├── NOTES.md └── README.md ├── 581-shortest-unsorted-continuous-subarray ├── 581-shortest-unsorted-continuous-subarray.java ├── NOTES.md ├── README.md └── solution1.java ├── 583-delete-operation-for-two-strings ├── 583-delete-operation-for-two-strings.java ├── NOTES.md └── README.md ├── 589-n-ary-tree-preorder-traversal ├── 589-n-ary-tree-preorder-traversal.java ├── NOTES.md └── README.md ├── 59-spiral-matrix-ii ├── 59-spiral-matrix-ii.java ├── NOTES.md └── README.md ├── 590-n-ary-tree-postorder-traversal ├── 590-n-ary-tree-postorder-traversal.java ├── NOTES.md └── README.md ├── 6-zigzag-conversion ├── 6-zigzag-conversion.java ├── NOTES.md └── README.md ├── 60-permutation-sequence ├── 60-permutation-sequence.java ├── NOTES.md └── README.md ├── 61-rotate-list ├── 61-rotate-list.java ├── NOTES.md └── README.md ├── 611-valid-triangle-number ├── 611-valid-triangle-number.java ├── NOTES.md └── README.md ├── 617-merge-two-binary-trees ├── 617-merge-two-binary-trees.java ├── NOTES.md └── README.md ├── 62-unique-paths ├── 62-unique-paths.java ├── NOTES.md └── README.md ├── 63-unique-paths-ii ├── 63-unique-paths-ii.java ├── NOTES.md └── README.md ├── 633-sum-of-square-numbers ├── 633-sum-of-square-numbers.java └── README.md ├── 639-decode-ways-ii ├── 639-decode-ways-ii.java ├── NOTES.md └── README.md ├── 64-minimum-path-sum ├── 64-minimum-path-sum.java └── README.md ├── 646-maximum-length-of-pair-chain ├── 646-maximum-length-of-pair-chain.java ├── NOTES.md └── README.md ├── 647-palindromic-substrings ├── 647-palindromic-substrings.java ├── NOTES.md └── README.md ├── 65-valid-number ├── 65-valid-number.java └── README.md ├── 650-2-keys-keyboard ├── 650-2-keys-keyboard.java ├── NOTES.md └── README.md ├── 652-find-duplicate-subtrees ├── 652-find-duplicate-subtrees.java ├── NOTES.md └── README.md ├── 653-two-sum-iv-input-is-a-bst ├── 653-two-sum-iv-input-is-a-bst.java ├── NOTES.md └── README.md ├── 654-maximum-binary-tree ├── 654-maximum-binary-tree.java ├── NOTES.md └── README.md ├── 658-find-k-closest-elements ├── 658-find-k-closest-elements.java ├── NOTES.md └── README.md ├── 66-plus-one ├── 66-plus-one.java ├── NOTES.md └── README.md ├── 662-maximum-width-of-binary-tree ├── 662-maximum-width-of-binary-tree.java ├── NOTES.md └── README.md ├── 67-add-binary ├── 67-add-binary.java ├── NOTES.md └── README.md ├── 673-number-of-longest-increasing-subsequence ├── 673-number-of-longest-increasing-subsequence.java ├── NOTES.md └── README.md ├── 674-longest-continuous-increasing-subsequence ├── 674-longest-continuous-increasing-subsequence.java ├── NOTES.md └── README.md ├── 680-valid-palindrome-ii ├── 680-valid-palindrome-ii.java ├── NOTES.md └── README.md ├── 684-redundant-connection ├── 684-redundant-connection.java ├── NOTES.md └── README.md ├── 685-redundant-connection-ii ├── 685-redundant-connection-ii.java ├── NOTES.md └── README.md ├── 686-repeated-string-match ├── 686-repeated-string-match.java └── README.md ├── 688-knight-probability-in-chessboard ├── 688-knight-probability-in-chessboard.java └── README.md ├── 69-sqrtx ├── 69-sqrtx.java ├── NOTES.md └── README.md ├── 695-max-area-of-island ├── 695-max-area-of-island.java └── README.md ├── 7-reverse-integer ├── 7-reverse-integer.java ├── NOTES.md └── README.md ├── 70-climbing-stairs ├── 70-climbing-stairs.java ├── NOTES.md └── README.md ├── 700-search-in-a-binary-search-tree ├── 700-search-in-a-binary-search-tree.java └── README.md ├── 701-insert-into-a-binary-search-tree ├── 701-insert-into-a-binary-search-tree.java └── README.md ├── 704-binary-search ├── 704-binary-search.java ├── NOTES.md └── README.md ├── 709-to-lower-case ├── 709-to-lower-case.java ├── NOTES.md └── README.md ├── 71-simplify-path ├── 71-simplify-path.java └── README.md ├── 713-subarray-product-less-than-k ├── 713-subarray-product-less-than-k.java ├── NOTES.md └── README.md ├── 714-best-time-to-buy-and-sell-stock-with-transaction-fee ├── 714-best-time-to-buy-and-sell-stock-with-transaction-fee.java ├── NOTES.md └── README.md ├── 718-maximum-length-of-repeated-subarray ├── 718-maximum-length-of-repeated-subarray.java └── README.md ├── 72-edit-distance ├── 72-edit-distance.java ├── NOTES.md ├── README.md └── solution1.java ├── 724-find-pivot-index ├── 724-find-pivot-index.java ├── NOTES.md └── README.md ├── 725-split-linked-list-in-parts ├── 725-split-linked-list-in-parts.java ├── NOTES.md └── README.md ├── 729-my-calendar-i ├── 729-my-calendar-i.java ├── NOTES.md └── README.md ├── 73-set-matrix-zeroes ├── 73-set-matrix-zeroes.java ├── NOTES.md └── README.md ├── 730-count-different-palindromic-subsequences ├── 730-count-different-palindromic-subsequences.java ├── NOTES.md └── README.md ├── 733-flood-fill ├── 733-flood-fill.java └── README.md ├── 739-daily-temperatures ├── 739-daily-temperatures.java ├── NOTES.md └── README.md ├── 74-search-a-2d-matrix ├── 74-search-a-2d-matrix.java ├── NOTES.md └── README.md ├── 740-delete-and-earn ├── 740-delete-and-earn.java ├── NOTES.md └── README.md ├── 743-network-delay-time ├── 743-network-delay-time.java ├── NOTES.md └── README.md ├── 744-find-smallest-letter-greater-than-target ├── 744-find-smallest-letter-greater-than-target.java ├── NOTES.md └── README.md ├── 746-min-cost-climbing-stairs ├── 746-min-cost-climbing-stairs.java ├── NOTES.md └── README.md ├── 75-sort-colors ├── 75-sort-colors.java ├── NOTES.md └── README.md ├── 752-open-the-lock ├── 752-open-the-lock.java └── README.md ├── 76-minimum-window-substring ├── 76-minimum-window-substring.java ├── NOTES.md ├── README.md └── solution1.java ├── 767-reorganize-string ├── 767-reorganize-string.java ├── NOTES.md ├── README.md └── solution1.java ├── 77-combinations ├── 77-combinations.java ├── NOTES.md └── README.md ├── 775-global-and-local-inversions ├── 775-global-and-local-inversions.java ├── NOTES.md └── README.md ├── 78-subsets ├── 78-subsets.java ├── NOTES.md └── README.md ├── 781-rabbits-in-forest ├── 781-rabbits-in-forest.java ├── NOTES.md └── README.md ├── 783-minimum-distance-between-bst-nodes ├── 783-minimum-distance-between-bst-nodes.java ├── NOTES.md └── README.md ├── 785-is-graph-bipartite ├── 785-is-graph-bipartite.java ├── NOTES.md └── README.md ├── 787-cheapest-flights-within-k-stops ├── 787-cheapest-flights-within-k-stops.java └── README.md ├── 79-word-search ├── 79-word-search.java ├── NOTES.md └── README.md ├── 790-domino-and-tromino-tiling ├── 790-domino-and-tromino-tiling.java ├── NOTES.md └── README.md ├── 792-number-of-matching-subsequences ├── 792-number-of-matching-subsequences.java ├── NOTES.md └── README.md ├── 796-rotate-string ├── 796-rotate-string.java ├── NOTES.md └── README.md ├── 797-all-paths-from-source-to-target ├── 797-all-paths-from-source-to-target.java ├── NOTES.md └── README.md ├── 8-string-to-integer-atoi ├── 8-string-to-integer-atoi.java ├── NOTES.md └── README.md ├── 80-remove-duplicates-from-sorted-array-ii ├── 80-remove-duplicates-from-sorted-array-ii.java ├── NOTES.md └── README.md ├── 802-find-eventual-safe-states ├── 802-find-eventual-safe-states.java ├── NOTES.md └── README.md ├── 818-race-car ├── 818-race-car.java └── README.md ├── 821-shortest-distance-to-a-character ├── 821-shortest-distance-to-a-character.java └── README.md ├── 823-binary-trees-with-factors ├── 823-binary-trees-with-factors.java ├── NOTES.md └── README.md ├── 83-remove-duplicates-from-sorted-list ├── 83-remove-duplicates-from-sorted-list.java ├── NOTES.md └── README.md ├── 834-sum-of-distances-in-tree ├── 834-sum-of-distances-in-tree.java ├── NOTES.md └── README.md ├── 835-image-overlap ├── 835-image-overlap.java ├── NOTES.md └── README.md ├── 838-push-dominoes ├── 838-push-dominoes.java └── README.md ├── 84-largest-rectangle-in-histogram ├── 84-largest-rectangle-in-histogram.java ├── NOTES.md └── README.md ├── 841-keys-and-rooms ├── 841-keys-and-rooms.java ├── NOTES.md └── README.md ├── 85-maximal-rectangle ├── 85-maximal-rectangle.java ├── NOTES.md └── README.md ├── 852-peak-index-in-a-mountain-array ├── 852-peak-index-in-a-mountain-array.java ├── NOTES.md └── README.md ├── 858-mirror-reflection ├── 858-mirror-reflection.java ├── NOTES.md ├── README.md └── illustrations.md ├── 86-partition-list ├── 86-partition-list.java ├── NOTES.md └── README.md ├── 863-all-nodes-distance-k-in-binary-tree ├── 863-all-nodes-distance-k-in-binary-tree.java └── README.md ├── 865-smallest-subtree-with-all-the-deepest-nodes ├── 865-smallest-subtree-with-all-the-deepest-nodes.java ├── NOTES.md └── README.md ├── 87-scramble-string ├── 87-scramble-string.java ├── NOTES.md ├── README.md └── illustrations.md ├── 875-koko-eating-bananas ├── 875-koko-eating-bananas.java ├── NOTES.md └── README.md ├── 876-middle-of-the-linked-list ├── 876-middle-of-the-linked-list.java ├── NOTES.md └── README.md ├── 877-stone-game ├── 877-stone-game.java ├── NOTES.md └── README.md ├── 88-merge-sorted-array ├── 88-merge-sorted-array.java ├── NOTES.md └── README.md ├── 881-boats-to-save-people ├── 881-boats-to-save-people.java ├── NOTES.md └── README.md ├── 886-possible-bipartition ├── 886-possible-bipartition.java ├── NOTES.md └── README.md ├── 887-super-egg-drop ├── 887-super-egg-drop.java └── README.md ├── 89-gray-code ├── 89-gray-code.java ├── NOTES.md └── README.md ├── 890-find-and-replace-pattern ├── 890-find-and-replace-pattern.java ├── NOTES.md └── README.md ├── 9-palindrome-number ├── 9-palindrome-number.java ├── NOTES.md └── README.md ├── 90-subsets-ii ├── 90-subsets-ii.java ├── NOTES.md └── README.md ├── 901-online-stock-span ├── 901-online-stock-span.java ├── NOTES.md └── README.md ├── 904-fruit-into-baskets ├── 904-fruit-into-baskets.java ├── NOTES.md └── README.md ├── 91-decode-ways ├── 91-decode-ways.java ├── NOTES.md ├── README.md └── solution1.java ├── 910-smallest-range-ii ├── 910-smallest-range-ii.java ├── NOTES.md └── README.md ├── 912-sort-an-array ├── 912-sort-an-array.java ├── NOTES.md └── README.md ├── 916-word-subsets ├── 916-word-subsets.java └── README.md ├── 918-maximum-sum-circular-subarray ├── 918-maximum-sum-circular-subarray.java ├── NOTES.md └── README.md ├── 92-reverse-linked-list-ii ├── 92-reverse-linked-list-ii.java ├── NOTES.md └── README.md ├── 93-restore-ip-addresses ├── 93-restore-ip-addresses.java └── README.md ├── 934-shortest-bridge ├── 934-shortest-bridge.java ├── NOTES.md └── README.md ├── 935-knight-dialer ├── 935-knight-dialer.java ├── NOTES.md └── README.md ├── 94-binary-tree-inorder-traversal ├── 94-binary-tree-inorder-traversal.java ├── NOTES.md └── README.md ├── 940-distinct-subsequences-ii ├── 940-distinct-subsequences-ii.java ├── NOTES.md └── README.md ├── 946-validate-stack-sequences ├── 946-validate-stack-sequences.java ├── NOTES.md └── README.md ├── 95-unique-binary-search-trees-ii ├── 95-unique-binary-search-trees-ii.java ├── NOTES.md └── README.md ├── 96-unique-binary-search-trees ├── 96-unique-binary-search-trees.java ├── NOTES.md └── README.md ├── 968-binary-tree-cameras ├── 968-binary-tree-cameras.java ├── NOTES.md └── README.md ├── 969-pancake-sorting ├── 969-pancake-sorting.java ├── NOTES.md └── README.md ├── 973-k-closest-points-to-origin ├── 973-k-closest-points-to-origin.java ├── NOTES.md └── README.md ├── 974-subarray-sums-divisible-by-k ├── 974-subarray-sums-divisible-by-k.java ├── NOTES.md └── README.md ├── 977-squares-of-a-sorted-array ├── 977-squares-of-a-sorted-array.java └── README.md ├── 98-validate-binary-search-tree ├── 98-validate-binary-search-tree.java ├── NOTES.md └── README.md ├── 980-unique-paths-iii ├── 980-unique-paths-iii.java ├── NOTES.md └── README.md ├── 983-minimum-cost-for-tickets ├── 983-minimum-cost-for-tickets.java ├── NOTES.md └── README.md ├── 986-interval-list-intersections ├── 986-interval-list-intersections.java ├── NOTES.md └── README.md ├── 987-vertical-order-traversal-of-a-binary-tree ├── 987-vertical-order-traversal-of-a-binary-tree.java ├── NOTES.md └── README.md ├── 99-recover-binary-search-tree ├── 99-recover-binary-search-tree.java ├── NOTES.md └── README.md ├── 994-rotting-oranges ├── 994-rotting-oranges.java ├── NOTES.md └── README.md ├── 997-find-the-town-judge ├── 997-find-the-town-judge.java ├── NOTES.md └── README.md ├── Add 1 to a number represented as linked list - GFG ├── README.md └── add-1-to-a-number-represented-as-linked-list.java ├── Boolean Parenthesization - GFG ├── README.md └── boolean-parenthesization.java ├── Bottom View of Binary Tree - GFG ├── README.md └── bottom-view-of-binary-tree.java ├── Boundary Traversal of binary tree - GFG ├── README.md └── boundary-traversal-of-binary-tree.java ├── Children Sum Parent - GFG ├── README.md └── children-sum-parent.java ├── Closest Number - GFG ├── README.md └── closest-number.java ├── Common Subsequence - GFG ├── README.md └── common-subsequence.java ├── Count Palindromic Subsequences - GFG ├── README.md └── count-palindromic-subsequences.java ├── Detect cycle in a directed graph - GFG ├── README.md └── detect-cycle-in-a-directed-graph.java ├── Detect cycle in an undirected graph - GFG ├── README.md └── detect-cycle-in-an-undirected-graph.java ├── Diagonal Traversal of Binary Tree - GFG ├── README.md └── diagonal-traversal-of-binary-tree.java ├── Find length of longest subsequence - GFG ├── README.md └── find-length-of-longest-subsequence.java ├── First negative integer in every window of size k - GFG ├── README.md └── first-negative-integer-in-every-window-of-size-k.java ├── Fractional Knapsack - GFG ├── README.md └── fractional-knapsack.java ├── Killing Spree - GFG ├── README.md └── killing-spree.java ├── Knapsack with Duplicate Items - GFG ├── README.md └── knapsack-with-duplicate-items.java ├── Largest rectangular sub-matrix whose sum is 0 - GFG └── solution.java ├── Longest Common Substring - GFG ├── README.md └── longest-common-substring.java ├── Longest Repeating Subsequence - GFG ├── README.md └── longest-repeating-subsequence.java ├── Longest Sub-Array with Sum K - GFG ├── README.md └── longest-sub-array-with-sum-k.java ├── Matrix Chain Multiplication - GFG ├── README.md └── matrix-chain-multiplication.java ├── Max Sum Subarray of size K - GFG ├── README.md └── max-sum-subarray-of-size-k.java ├── Maximum Sum Rectangle - GFG ├── README.md └── solution.java ├── Maximum difference of zeros and ones in binary string - GFG └── solution.java ├── Min distance between two given nodes of a Binary Tree - GFG ├── README.md └── min-distance-between-two-given-nodes-of-a-binary-tree.java ├── Minimum number of deletions and insertions. - GFG ├── README.md └── minimum-number-of-deletions-and-insertions..java ├── Minimum number of deletions. - GFG ├── README.md └── minimum-number-of-deletions..java ├── Minimum steps to make product equal to one - GFG ├── README.md └── minimum-steps-to-make-product-equal-to-one.java ├── Minimum sum partition - GFG ├── README.md └── minimum-sum-partition.java ├── Mobile numeric keypad - GFG ├── README.md └── mobile-numeric-keypad.java ├── N meetings in one room └── solution.java ├── Nearly sorted - GFG ├── README.md └── nearly-sorted.java ├── Number of minimum picks to get 'k' pairs of socks from a drawer - GFG ├── README.md └── number-of-minimum-picks-to-get-k-pairs-of-socks-from-a-drawer.java ├── Number of occurrence - GFG ├── README.md └── number-of-occurrence.java ├── Possible groups - GFG ├── README.md └── possible-groups.java ├── Print Anagrams Together - GFG ├── README.md └── print-anagrams-together.java ├── README.md ├── Rat in a Maze Problem - I - GFG ├── README.md └── rat-in-a-maze-problem-i.java ├── Rearrange an array with O(1) extra space - GFG ├── README.md └── rearrange-an-array-with-o1-extra-space.java ├── Remove duplicates from an unsorted linked list - GFG ├── README.md └── remove-duplicates-from-an-unsorted-linked-list.java ├── Rod Cutting - GFG ├── README.md └── rod-cutting.java ├── Shortest Common Supersequence - GFG ├── README.md └── shortest-common-supersequence.java ├── Smallest number on left - GFG ├── README.md └── smallest-number-on-left.java ├── Sort a stack - GFG ├── README.md └── sort-a-stack.java ├── Split the binary string into substrings with equal number of 0s and 1s - GFG ├── README.md └── split-the-binary-string-into-substrings-with-equal-number-of-0s-and-1s.java ├── Steps by Knight - GFG ├── README.md └── steps-by-knight.java ├── String Subsequence - GFG ├── README.md └── string-subsequence.java ├── Subset Sum Problem - GFG ├── README.md └── subset-sum-problem.java ├── The Celebrity Problem - GFG ├── README.md └── the-celebrity-problem.java ├── Top View of Binary Tree - GFG ├── README.md └── top-view-of-binary-tree.java ├── Topological sort - GFG ├── README.md └── topological-sort.java └── Word Wrap - GFG ├── README.md └── word-wrap.java /1-two-sum/1-two-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] nums, int target) { 3 | Map map = new HashMap<>(); 4 | for (int i = 0; i < nums.length; i++) { 5 | int complement = target - nums[i]; 6 | if (map.containsKey(complement)) { 7 | return new int[] { map.get(complement), i }; 8 | } 9 | map.put(nums[i], i); 10 | } 11 | throw new IllegalArgumentException("No two sum solution"); 12 | } 13 | } -------------------------------------------------------------------------------- /1-two-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /10-regular-expression-matching/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /100-same-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1004-max-consecutive-ones-iii/1004-max-consecutive-ones-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestOnes(int[] nums, int k) { 3 | int n = nums.length; 4 | int max = 0; 5 | 6 | // Sliding window approach 7 | int start = 0; 8 | int count = 0; // Int zeroes count 9 | for (int end=0;end0) 7 | break; 8 | if (nums[i]<0) { 9 | nums[i]=-nums[i]; 10 | k--; 11 | } 12 | } 13 | 14 | int sum = 0; 15 | int min = Integer.MAX_VALUE; 16 | for (int num: nums) { 17 | sum += num; 18 | min = Math.min(min,num); 19 | } 20 | 21 | if (k%2!=0) 22 | sum -= 2*min; 23 | 24 | return sum; 25 | } 26 | } -------------------------------------------------------------------------------- /1005-maximize-sum-of-array-after-k-negations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1007-minimum-domino-rotations-for-equal-row/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1008-construct-binary-search-tree-from-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /101-symmetric-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1010-pairs-of-songs-with-total-durations-divisible-by-60/1010-pairs-of-songs-with-total-durations-divisible-by-60.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numPairsDivisibleBy60(int[] time) { 3 | HashMap map = new HashMap<>(); 4 | int count = 0; 5 | for (int t: time) { 6 | int rem = t%60; 7 | if (map.containsKey(60-rem)) { 8 | count += map.get(60-rem); 9 | } 10 | else if (rem==0 && map.containsKey(0)) { 11 | count += map.get(0); 12 | } 13 | map.put(rem,map.getOrDefault(rem,0)+1); 14 | } 15 | return count; 16 | } 17 | } -------------------------------------------------------------------------------- /1010-pairs-of-songs-with-total-durations-divisible-by-60/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1011-capacity-to-ship-packages-within-d-days/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /103-binary-tree-zigzag-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1035-uncrossed-lines/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1038-binary-search-tree-to-greater-sum-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/104-maximum-depth-of-binary-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public int maxDepth(TreeNode root) { 18 | if (root==null) 19 | return 0; 20 | return 1+Math.max(maxDepth(root.left), maxDepth(root.right)); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1042-flower-planting-with-no-adjacent/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1043-partition-array-for-maximum-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1049-last-stone-weight-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1052-grumpy-bookstore-owner/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /106-construct-binary-tree-from-inorder-and-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /107-binary-tree-level-order-traversal-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /108-convert-sorted-array-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1081-smallest-subsequence-of-distinct-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /109-convert-sorted-list-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1094-car-pooling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1095-find-in-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /11-container-with-most-water/11-container-with-most-water.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxArea(int[] height) { 3 | int start = 0,end = height.length-1; 4 | int max = -1; 5 | 6 | while (start> generate(int numRows) { 3 | List> ans = new ArrayList<>(); 4 | for (int i=1;i<=numRows;i++) { 5 | List row = new ArrayList<>(); 6 | if (i==1) 7 | row.add(1); 8 | else { 9 | for (int j=0;j getRow(int rowIndex) { 3 | List> temp = new ArrayList<>(); 4 | for (int i=0;i<=rowIndex;i++) { 5 | List row = new ArrayList<>(); 6 | if (i==0) 7 | row.add(1); 8 | else { 9 | List x = temp.get(i-1); 10 | for (int j=0;j<=i;j++) { 11 | if (j==0) 12 | row.add(x.get(0)); 13 | else if (j==i) 14 | row.add(x.get(j-1)); 15 | else 16 | row.add(x.get(j-1)+x.get(j)); 17 | } 18 | } 19 | temp.add(row); 20 | } 21 | 22 | return temp.get(rowIndex); 23 | } 24 | } -------------------------------------------------------------------------------- /119-pascals-triangle-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /12-integer-to-roman/12-integer-to-roman.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String intToRoman(int num) { 3 | String dictionary[] = 4 | {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; 5 | int value[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; 6 | 7 | String output = ""; 8 | int i=0; 9 | while (num>0) { 10 | while (num>=value[i]) { 11 | num -= value[i]; 12 | output = output + dictionary[i]; 13 | } 14 | i++; 15 | } 16 | 17 | return output; 18 | } 19 | } -------------------------------------------------------------------------------- /12-integer-to-roman/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /120-triangle/120-triangle.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minimumTotal(List> triangle) { 3 | int rows = triangle.size(); 4 | 5 | // Move from last second row to top 6 | for (int r=rows-2;r>=0;r--) { 7 | List curr = triangle.get(r); 8 | List next = triangle.get(r+1); 9 | 10 | int size = curr.size(); 11 | for (int i=0;i0 && copy[i-1]==copy[j]) { 11 | count[i] = count[i-1]+1; 12 | } 13 | 14 | if (count[i]==k) { 15 | i-=k; 16 | } 17 | } 18 | 19 | return new String(copy,0,i); 20 | } 21 | } -------------------------------------------------------------------------------- /1209-remove-all-adjacent-duplicates-in-string-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/121-best-time-to-buy-and-sell-stock.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxProfit(int[] prices) { 3 | int min = prices[0]; 4 | int maxProfit = 0; 5 | 6 | for (int i=0;iprices[i-1]) { 6 | // Buy at prices[i-1] 7 | // Sell at prices[i] 8 | maxProfit += prices[i]-prices[i-1]; 9 | } 10 | } 11 | return maxProfit; 12 | } 13 | } -------------------------------------------------------------------------------- /122-best-time-to-buy-and-sell-stock-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1220-count-vowels-permutation/1220-count-vowels-permutation.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int MOD = 1000000007; 3 | public int countVowelPermutation(int n) { 4 | int a=1; 5 | int e=1; 6 | int i=1; 7 | int o=1; 8 | int u=1; 9 | 10 | for (int p=2;p<=n;p++) { 11 | int newa = ((e+i)%MOD+u)%MOD; 12 | int newe = (a+i)%MOD; 13 | int newi = (e+o)%MOD; 14 | int newo = i; 15 | int newu = (i+o)%MOD; 16 | 17 | a = newa; 18 | e = newe; 19 | i = newi; 20 | o = newo; 21 | u = newu; 22 | } 23 | 24 | return (((((a+e)%MOD+i)%MOD)+o)%MOD+u)%MOD; 25 | } 26 | } -------------------------------------------------------------------------------- /1220-count-vowels-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /123-best-time-to-buy-and-sell-stock-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1232-check-if-it-is-a-straight-line/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /124-binary-tree-maximum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /125-valid-palindrome/125-valid-palindrome.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPalindrome(String s) { 3 | s=s.toLowerCase(); 4 | 5 | int n=s.length(); 6 | int start=0; 7 | int end=n-1; 8 | while (start<=end) { 9 | if (!Character.isLetterOrDigit(s.charAt(start))) 10 | start++; 11 | else if (!Character.isLetterOrDigit(s.charAt(end))) 12 | end--; 13 | 14 | else if (s.charAt(start)!=s.charAt(end)) 15 | return false; 16 | else { 17 | start++; 18 | end--; 19 | } 20 | } 21 | 22 | return true; 23 | } 24 | } -------------------------------------------------------------------------------- /125-valid-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /127-word-ladder/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1277-count-square-submatrices-with-all-ones/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1278-palindrome-partitioning-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /128-longest-consecutive-sequence/128-longest-consecutive-sequence.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestConsecutive(int[] nums) { 3 | HashSet set = new HashSet<>(); 4 | for (int num: nums) { 5 | set.add(num); 6 | } 7 | 8 | int maxLen = 0; 9 | for (int num: nums) { 10 | if (!set.contains(num-1)) { 11 | int currentlen = 1; 12 | 13 | int current = num; 14 | while (set.contains(current+1)) { 15 | currentlen++; 16 | current=current+1; 17 | } 18 | 19 | maxLen = Math.max(maxLen,currentlen); 20 | } 21 | } 22 | 23 | return maxLen; 24 | } 25 | } -------------------------------------------------------------------------------- /128-longest-consecutive-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /129-sum-root-to-leaf-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1291-sequential-digits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1291-sequential-digits/README.md: -------------------------------------------------------------------------------- 1 |

1291. Sequential Digits

Medium


An integer has sequential digits if and only if each digit in the number is one more than the previous digit.

2 | 3 |

Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.

4 | 5 |

 

6 |

Example 1:

7 |
Input: low = 100, high = 300
 8 | Output: [123,234]
 9 | 

Example 2:

10 |
Input: low = 1000, high = 13000
11 | Output: [1234,2345,3456,4567,5678,6789,12345]
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 10 <= low <= high <= 10^9
  • 18 |
19 |
20 | -------------------------------------------------------------------------------- /1293-shortest-path-in-a-grid-with-obstacles-elimination/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /13-roman-to-integer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /130-surrounded-regions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1306-jump-game-iii/1306-jump-game-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canReach(int[] arr, int start) { 3 | boolean visited[] = new boolean[arr.length]; 4 | return helper(arr,start,visited); 5 | } 6 | 7 | private boolean helper(int[] arr,int curr,boolean[] visited) { 8 | if (curr<0 || curr>=arr.length || visited[curr]) 9 | return false; 10 | 11 | if (arr[curr]==0) 12 | return true; 13 | 14 | visited[curr]=true; 15 | boolean x = helper(arr,curr+arr[curr],visited); 16 | boolean y = helper(arr,curr-arr[curr],visited); 17 | 18 | return x|y; 19 | } 20 | } -------------------------------------------------------------------------------- /131-palindrome-partitioning/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1312-minimum-insertion-steps-to-make-a-string-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1319-number-of-operations-to-make-network-connected/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1323-maximum-69-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1326-minimum-number-of-taps-to-open-to-water-a-garden/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /133-clone-graph/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1332-remove-palindromic-subsequences/1332-remove-palindromic-subsequences.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removePalindromeSub(String s) { 3 | return isPalindrome(s) ? 1 : 2; 4 | } 5 | 6 | public boolean isPalindrome(String s) { 7 | int n = s.length(); 8 | for (int i=0;i map = new HashMap<>(); 4 | for (int num: arr) { 5 | map.put(num,map.getOrDefault(num,0)+1); 6 | } 7 | 8 | List l=new ArrayList<>(); 9 | for (Map.Entry e: map.entrySet()) { 10 | l.add(e.getValue()); 11 | } 12 | 13 | Collections.sort(l,Collections.reverseOrder()); 14 | 15 | int count = 0; 16 | int target = arr.length/2; 17 | int i = 0; 18 | while (target>0 && !l.isEmpty()) { 19 | int curr = l.get(i++); 20 | count++; 21 | target -= curr; 22 | } 23 | 24 | return count; 25 | } 26 | } -------------------------------------------------------------------------------- /1338-reduce-array-size-to-the-half/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /134-gas-station/134-gas-station.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int canCompleteCircuit(int[] gas, int[] cost) { 3 | int currentFuel = 0; // fuel so far in car 4 | int ans = 0; 5 | int totalFuel = 0; // Total fuel required till now 6 | 7 | for (int i=0;iratings[i-1] && candy[i]<=candy[i-1]) { 9 | candy[i] = candy[i-1]+1; 10 | } 11 | } 12 | 13 | for (int i=n-2;i>=0;i--) { 14 | if (ratings[i]>ratings[i+1] && candy[i]<=candy[i+1]) { 15 | candy[i] = candy[i+1]+1; 16 | } 17 | } 18 | 19 | int candies=0; 20 | for (int c: candy) { 21 | candies += c; 22 | } 23 | 24 | return candies; 25 | } 26 | } -------------------------------------------------------------------------------- /135-candy/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1353-maximum-number-of-events-that-can-be-attended/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /136-single-number/136-single-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | int ans = 0; 4 | for (int i=0;i wordDict) { 3 | int n = s.length(); 4 | 5 | // DP array representing whether true or false upto that length 6 | boolean dp[] = new boolean[n+1]; 7 | 8 | dp[0]=true; 9 | 10 | for (int i=1;i<=n;i++) { 11 | for (int j=i-1;j>=0;j--) { 12 | if (dp[j] && wordDict.contains(s.substring(j,i))) { 13 | dp[i]=true; 14 | break; 15 | } 16 | } 17 | } 18 | return dp[n]; 19 | } 20 | } -------------------------------------------------------------------------------- /139-word-break/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /14-longest-common-prefix/14-longest-common-prefix.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String longestCommonPrefix(String[] strs) { 3 | String output = ""; 4 | 5 | for (int index=0,len=strs[0].length();index=temp.length()) 11 | return output; 12 | 13 | if (temp.charAt(index)!=ch) 14 | flag = false; 15 | } 16 | if (!flag) 17 | return output; 18 | output = output+ch; 19 | } 20 | return output; 21 | } 22 | } -------------------------------------------------------------------------------- /14-longest-common-prefix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /141-linked-list-cycle/141-linked-list-cycle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode(int x) { 7 | * val = x; 8 | * next = null; 9 | * } 10 | * } 11 | */ 12 | public class Solution { 13 | public boolean hasCycle(ListNode head) { 14 | if (head==null) 15 | return false; 16 | 17 | // Using floyd cycle detection algorithm 18 | ListNode slow = head; 19 | ListNode fast = head; 20 | 21 | while (fast!=null && fast.next!=null) { 22 | slow = slow.next; 23 | fast = fast.next.next; 24 | 25 | if (slow==fast) { 26 | return true; 27 | } 28 | } 29 | 30 | return false; 31 | } 32 | } -------------------------------------------------------------------------------- /141-linked-list-cycle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findMinFibonacciNumbers(int k) { 3 | TreeSet set = new TreeSet<>(); 4 | int a = 1; 5 | int b = 1; 6 | set.add(1); 7 | int c = a+b; 8 | while (c<=k) { 9 | set.add(c); 10 | a=b; 11 | b=c; 12 | c=a+b; 13 | } 14 | 15 | int count = 0; 16 | while (k!=0) { 17 | k -= set.floor(k); 18 | count++; 19 | } 20 | 21 | return count; 22 | } 23 | } -------------------------------------------------------------------------------- /1414-find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /142-linked-list-cycle-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1423-maximum-points-you-can-obtain-from-cards/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1438-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /144-binary-tree-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /145-binary-tree-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /146-lru-cache/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /148-sort-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1480-running-sum-of-1d-array/1480-running-sum-of-1d-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] runningSum(int[] nums) { 3 | int n = nums.length; 4 | int[] runningSums = new int[n]; 5 | int runningSum = 0; 6 | for (int i=0;itarget) 13 | high--; 14 | else 15 | low++; 16 | 17 | if (Math.abs(current_sum-target) null -> List B 18 | currB = currB==null ? headA : currB.next; // List B -> null -> List A 19 | } 20 | 21 | return currA; 22 | } 23 | } -------------------------------------------------------------------------------- /162-find-peak-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1636-sort-array-by-increasing-frequency/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1647-minimum-deletions-to-make-character-frequencies-unique/1647-minimum-deletions-to-make-character-frequencies-unique.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minDeletions(String s) { 3 | int freq[] = new int[26]; 4 | for (char ch: s.toCharArray()) { 5 | freq[ch-'a']++; 6 | } 7 | 8 | int ans=0; 9 | Set set = new HashSet<>(); // Store different frequencies 10 | for (int i=0;i<26;i++) { 11 | if (freq[i]==0) 12 | continue; 13 | 14 | if (!set.add(freq[i])) { 15 | while (freq[i]!=0 && !set.add(freq[i])) { 16 | freq[i]--; 17 | ans++; 18 | } 19 | } 20 | } 21 | 22 | return ans; 23 | } 24 | } -------------------------------------------------------------------------------- /1647-minimum-deletions-to-make-character-frequencies-unique/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1654-minimum-jumps-to-reach-home/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1658-minimum-operations-to-reduce-x-to-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1669-merge-in-between-linked-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /167-two-sum-ii-input-array-is-sorted/167-two-sum-ii-input-array-is-sorted.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] numbers, int target) { 3 | int[] ans = new int[2]; 4 | 5 | int left = 0; 6 | int right = numbers.length-1; 7 | 8 | while (lefttarget) { 16 | right--; 17 | } 18 | else { 19 | left++; 20 | } 21 | } 22 | 23 | return ans; 24 | } 25 | } -------------------------------------------------------------------------------- /167-two-sum-ii-input-array-is-sorted/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1671-minimum-number-of-removals-to-make-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/1689-partitioning-into-minimum-number-of-deci-binary-numbers.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minPartitions(String n) { 3 | int maxDigit = 0; 4 | for (char ch: n.toCharArray()) { 5 | int digit = ch-'0'; 6 | if (digit==9) 7 | return 9; 8 | maxDigit = Math.max(digit,maxDigit); 9 | } 10 | return maxDigit; 11 | } 12 | } -------------------------------------------------------------------------------- /1689-partitioning-into-minimum-number-of-deci-binary-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /169-majority-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1695-maximum-erasure-value/1695-maximum-erasure-value.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maximumUniqueSubarray(int[] nums) { 3 | // Map to store number and its last index in array 4 | HashMap hm = new HashMap<>(); 5 | 6 | int start=0; 7 | int score=0; 8 | int runningSum=0; 9 | for (int end=0,size=nums.length;end letterCombinations(String digits) { 5 | List ans = new ArrayList<>(); 6 | if (digits.length()!=0) 7 | helper(ans,digits,0,""); 8 | return ans; 9 | } 10 | 11 | //i is iterator for the string digits 12 | private void helper(List ans,String digits,int i,String temp) { 13 | if (i==digits.length()) { 14 | ans.add(temp); 15 | return; 16 | } 17 | 18 | int digit = digits.charAt(i)-'0'; 19 | String key = keys[digit]; 20 | 21 | for (int go=0;go=0;i--) { 8 | char ch = columnTitle.charAt(i); 9 | number = number + (ch-'A'+1)*k; 10 | k=k*26; 11 | } 12 | return number; 13 | } 14 | } -------------------------------------------------------------------------------- /171-excel-sheet-column-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /172-factorial-trailing-zeroes/172-factorial-trailing-zeroes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int trailingZeroes(int n) { 3 | int ans = 0; 4 | int x = 5; 5 | while (n/x>=1) { 6 | ans = ans+n/x; 7 | x=5*x; 8 | } 9 | 10 | return ans; 11 | } 12 | } -------------------------------------------------------------------------------- /172-factorial-trailing-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1723-find-minimum-time-to-finish-all-jobs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /173-binary-search-tree-iterator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1745-palindrome-partitioning-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /175-combine-two-tables/175-combine-two-tables.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT 3 | Person.firstName, 4 | Person.lastName, 5 | Address.city, 6 | Address.state 7 | FROM 8 | Person 9 | LEFT JOIN 10 | Address 11 | ON 12 | Person.personId=Address.personId; 13 | -------------------------------------------------------------------------------- /175-combine-two-tables/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1775-equal-sum-arrays-with-minimum-number-of-operations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /179-largest-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /179-largest-number/README.md: -------------------------------------------------------------------------------- 1 |

179. Largest Number

Medium


Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.

2 | 3 |

Since the result may be very large, so you need to return a string instead of an integer.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: nums = [10,2]
 9 | Output: "210"
10 | 
11 | 12 |

Example 2:

13 | 14 |
Input: nums = [3,30,34,5,9]
15 | Output: "9534330"
16 | 
17 | 18 |

 

19 |

Constraints:

20 | 21 |
    22 |
  • 1 <= nums.length <= 100
  • 23 |
  • 0 <= nums[i] <= 109
  • 24 |
25 |
-------------------------------------------------------------------------------- /18-4sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1823-find-the-winner-of-the-circular-game/1823-find-the-winner-of-the-circular-game.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | // Josephus problem 3 | public int findTheWinner(int n, int k) { 4 | if (n==1) 5 | return 1; 6 | 7 | return 1+(findTheWinner(n-1,k)+k-1)%n; 8 | } 9 | } -------------------------------------------------------------------------------- /1823-find-the-winner-of-the-circular-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1828-queries-on-number-of-points-inside-a-circle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1865-finding-pairs-with-a-certain-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1871-jump-game-vii/1871-jump-game-vii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canReach(String s, int minJump, int maxJump) { 3 | int n = s.length(); 4 | 5 | //BFS 6 | Queue q = new LinkedList<>(); 7 | q.add(0); 8 | int farthest=0; // Farthest index we reached till now 9 | 10 | while (!q.isEmpty()) { 11 | int curr = q.poll(); 12 | if (curr==n-1) 13 | return true; 14 | 15 | int start = Math.max(curr+minJump,farthest); 16 | int end = Math.min(curr+maxJump,n-1); 17 | for (int i=start;i<=end;i++) { 18 | if (s.charAt(i)=='0') 19 | q.add(i); 20 | } 21 | farthest=end+1; 22 | } 23 | 24 | return false; 25 | } 26 | } -------------------------------------------------------------------------------- /1871-jump-game-vii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /188-best-time-to-buy-and-sell-stock-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1888-minimum-number-of-flips-to-make-the-binary-string-alternating/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /189-rotate-array/189-rotate-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void rotate(int[] nums, int k) { 3 | k = k%(nums.length); // Reduce k if k>=length of array 4 | 5 | if (k==0) 6 | return; 7 | 8 | // Reverse the complete array 9 | reverseArray(nums,0,nums.length-1); 10 | 11 | // Reverse the first k elements and then reverse the remaining elements 12 | reverseArray(nums,0,k-1); 13 | reverseArray(nums,k,nums.length-1); 14 | } 15 | 16 | public void reverseArray(int[] nums,int startIndex,int endIndex) { 17 | while(startIndex>>1; 10 | } 11 | return ans; 12 | } 13 | } -------------------------------------------------------------------------------- /190-reverse-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /191-number-of-1-bits/191-number-of-1-bits.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | // you need to treat n as an unsigned value 3 | public int hammingWeight(int n) { 4 | int ans = 0; 5 | // Integer type in Java is signed and there is no unsigned int. 6 | // So the input 2147483648 is represented in Java as -2147483648 (in java int type has a // cyclic representation, that means Integer.MAX_VALUE+1==Integer.MIN_VALUE). 7 | // This force us to use n!=0 in the while condition and we cannot use n>0 8 | while (n!=0) { 9 | n = n&(n-1); // Removes the last set bit 10 | ans++; 11 | } 12 | return ans; 13 | } 14 | } -------------------------------------------------------------------------------- /191-number-of-1-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1926-nearest-exit-from-entrance-in-maze/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1963-minimum-number-of-swaps-to-make-the-string-balanced/1963-minimum-number-of-swaps-to-make-the-string-balanced.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minSwaps(String s) { 3 | int swaps = 0; 4 | int close = 0; // close brackets 5 | for (char ch: s.toCharArray()) { 6 | if (ch==']') 7 | close++; 8 | else if (ch=='[') 9 | close--; 10 | 11 | // Swaps stores the maximum no of close brackets at a time 12 | swaps = Math.max(swaps,close); 13 | } 14 | 15 | // By swapping one bracket, two close brackets are managed 16 | return (swaps+1)/2; 17 | } 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /198-house-robber/198-house-robber.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int rob(int[] nums) { 3 | int n=nums.length; 4 | 5 | // dp[i] represents maximum amount that can be robbed upto house i 6 | int dp[] = new int[n]; 7 | dp[0] = nums[0]; 8 | 9 | for (int i=1;i>1; 15 | right=right>>1; 16 | shift++; 17 | } 18 | 19 | return left< visited = new HashSet<>(); 7 | visited.add(n); 8 | 9 | int current = n; 10 | while(true) { 11 | current = getDigitSquareSum(current); 12 | if (current==1) 13 | return true; 14 | 15 | if (!visited.add(current)) 16 | break; 17 | } 18 | 19 | return false; 20 | } 21 | 22 | private int getDigitSquareSum(int n) { 23 | int result = 0; 24 | while (n!=0) { 25 | int rem = n%10; 26 | n = n/10; 27 | result += rem*rem; 28 | } 29 | return result; 30 | } 31 | } -------------------------------------------------------------------------------- /202-happy-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /203-remove-linked-list-elements/203-remove-linked-list-elements.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public ListNode removeElements(ListNode head, int val) { 13 | if (head==null) 14 | return head; 15 | 16 | if (head.val==val) 17 | return removeElements(head.next,val); 18 | 19 | head.next = removeElements(head.next,val); 20 | return head; 21 | } 22 | } -------------------------------------------------------------------------------- /203-remove-linked-list-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /204-count-primes/204-count-primes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countPrimes(int n) { 3 | // Using sieve of erastosthones 4 | boolean[] prime = new boolean[n]; 5 | Arrays.fill(prime,true); 6 | 7 | for (int i=2;i204. Count Primes

Medium


Given an integer n, return the number of prime numbers that are strictly less than n.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 10
 7 | Output: 4
 8 | Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: n = 0
14 | Output: 0
15 | 
16 | 17 |

Example 3:

18 | 19 |
Input: n = 1
20 | Output: 0
21 | 
22 | 23 |

 

24 |

Constraints:

25 | 26 |
    27 |
  • 0 <= n <= 5 * 106
  • 28 |
29 |
-------------------------------------------------------------------------------- /2057-smallest-index-with-equal-value/2057-smallest-index-with-equal-value.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int smallestEqual(int[] nums) { 3 | int ans = -1; 4 | for (int i=0;i=target) { 16 | while (start<=end && runningSum>=target) { 17 | minLen=Math.min(minLen,end-start+1); 18 | runningSum-=nums[start]; 19 | start++; 20 | } 21 | end++; 22 | } 23 | } 24 | 25 | return minLen==Integer.MAX_VALUE ? 0 : minLen; 26 | } 27 | } -------------------------------------------------------------------------------- /209-minimum-size-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2091-removing-minimum-and-maximum-from-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /21-merge-two-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /210-course-schedule-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2101-detonate-the-maximum-bombs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /213-house-robber-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2139-minimum-moves-to-reach-target-score/2139-minimum-moves-to-reach-target-score.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minMoves(int target, int maxDoubles) { 3 | int op = 0; 4 | while (target!=1) { 5 | if (target%2==0 && maxDoubles!=0) { 6 | target = target/2; 7 | maxDoubles--; 8 | } 9 | else if (target%2!=0) { 10 | target -= 1; 11 | } 12 | else { 13 | op += (target-1); 14 | break; 15 | } 16 | op++; 17 | } 18 | 19 | return op; 20 | } 21 | } -------------------------------------------------------------------------------- /2140-solving-questions-with-brainpower/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2149-rearrange-array-elements-by-sign/2149-rearrange-array-elements-by-sign.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] rearrangeArray(int[] nums) { 3 | int[] output = new int[nums.length]; 4 | int pos = 0; 5 | int neg = 1; 6 | for (int num:nums) { 7 | if (num<0) { 8 | output[neg]=num; 9 | neg+=2; 10 | } 11 | else { 12 | output[pos]=num; 13 | pos+=2; 14 | } 15 | } 16 | return output; 17 | } 18 | } -------------------------------------------------------------------------------- /2149-rearrange-array-elements-by-sign/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /216-combination-sum-iii/216-combination-sum-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> combinationSum3(int k, int n) { 3 | List> ans = new ArrayList<>(); 4 | helper(ans,k,n,1,new ArrayList<>()); 5 | return ans; 6 | } 7 | 8 | private void helper(List> ans,int k,int target, 9 | int start,List temp) { 10 | if (k==0 && target==0) { 11 | ans.add(temp); 12 | return; 13 | } 14 | 15 | if (k==0 || target==0) { 16 | return; 17 | } 18 | 19 | for (int i=start;i<=9;i++) { 20 | if (target-i>=0) { 21 | temp.add(i); 22 | helper(ans,k-1,target-i,i+1,new ArrayList<>(temp)); 23 | temp.remove(temp.size()-1); 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /216-combination-sum-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /217-contains-duplicate/217-contains-duplicate.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean containsDuplicate(int[] nums) { 3 | HashSet vals = new HashSet<>(); 4 | for (int i: nums) { 5 | if (!vals.add(i)) 6 | return true; 7 | } 8 | return false; 9 | } 10 | } -------------------------------------------------------------------------------- /217-contains-duplicate/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2183-count-array-pairs-divisible-by-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /219-contains-duplicate-ii/219-contains-duplicate-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean containsNearbyDuplicate(int[] nums, int k) { 3 | // Map stores value and its last index 4 | HashMap map = new HashMap<>(); 5 | 6 | for (int i=0;i generateParenthesis(int n) { 3 | List ans = new ArrayList<>(); 4 | helper(n,0,0,0,"",ans); 5 | return ans; 6 | } 7 | 8 | public void helper(int n,int i, int open,int close,String str,List ans) { 9 | if (i==2*n) { 10 | ans.add(str); 11 | return; 12 | } 13 | 14 | if (open22. Generate Parentheses

Medium


Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

2 | 3 |

 

4 |

Example 1:

5 |
Input: n = 3
 6 | Output: ["((()))","(()())","(())()","()(())","()()()"]
 7 | 

Example 2:

8 |
Input: n = 1
 9 | Output: ["()"]
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= n <= 8
  • 16 |
17 |
-------------------------------------------------------------------------------- /2206-divide-array-into-equal-pairs/2206-divide-array-into-equal-pairs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean divideArray(int[] nums) { 3 | HashMap hm = new HashMap<>(); 4 | for(int i=0;ie : hm.entrySet()) { 11 | if (e.getValue()%2!=0) 12 | return false; 13 | } 14 | return true; 15 | } 16 | } -------------------------------------------------------------------------------- /221-maximal-square/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /222-count-complete-tree-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2236-root-equals-sum-of-children/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /224-basic-calculator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2248-intersection-of-multiple-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /225-implement-stack-using-queues/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /226-invert-binary-tree/226-invert-binary-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public TreeNode invertTree(TreeNode root) { 18 | if (root==null) 19 | return null; 20 | 21 | TreeNode left = root.left; 22 | TreeNode right = root.right; 23 | 24 | root.left = invertTree(right); 25 | root.right = invertTree(left); 26 | 27 | return root; 28 | } 29 | } -------------------------------------------------------------------------------- /226-invert-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /227-basic-calculator-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2276-count-integers-in-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2288-apply-discount-to-prices/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2289-steps-to-make-array-non-decreasing/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /229-majority-element-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /23-merge-k-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /230-kth-smallest-element-in-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2300-successful-pairs-of-spells-and-potions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /231-power-of-two/231-power-of-two.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfTwo(int n) { 3 | if (n<=0) return false; 4 | return (n&(n-1))==0; 5 | } 6 | } -------------------------------------------------------------------------------- /231-power-of-two/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /232-implement-queue-using-stacks/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/235-lowest-common-ancestor-of-a-binary-search-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode(int x) { val = x; } 8 | * } 9 | */ 10 | 11 | class Solution { 12 | public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { 13 | // If both p and q small than root 14 | if (root.val>p.val && root.val>q.val) 15 | return lowestCommonAncestor(root.left,p,q); 16 | 17 | // If both p and q larger than root 18 | if(root.val=0;i--) { 18 | result[i]*=suffix; 19 | suffix*=nums[i]; 20 | } 21 | 22 | return result; 23 | } 24 | } -------------------------------------------------------------------------------- /238-product-of-array-except-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /239-sliding-window-maximum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /24-swap-nodes-in-pairs/24-swap-nodes-in-pairs.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public ListNode swapPairs(ListNode head) { 13 | if ((head == null)||(head.next == null)) 14 | return head; 15 | ListNode second = head.next; 16 | head.next = swapPairs(head.next.next); 17 | second.next = head; 18 | return second; 19 | } 20 | } -------------------------------------------------------------------------------- /24-swap-nodes-in-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/240-search-a-2d-matrix-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean searchMatrix(int[][] matrix, int target) { 3 | int m = matrix.length; 4 | int n = matrix[0].length; 5 | 6 | int start=0; 7 | int end=n-1; 8 | 9 | while (start-1) { 10 | if (matrix[start][end]==target) 11 | return true; 12 | else if (matrix[start][end]>target) 13 | end--; 14 | else 15 | start++; 16 | } 17 | 18 | return false; 19 | } 20 | } -------------------------------------------------------------------------------- /25-reverse-nodes-in-k-group/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /257-binary-tree-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /258-add-digits/258-add-digits.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int addDigits(int num) { 3 | int current = num; 4 | while (current/10!=0) { 5 | current=getNext(current); 6 | } 7 | return current; 8 | } 9 | 10 | private int getNext(int n) { 11 | int result = 0; 12 | while (n!=0) { 13 | int rem = n%10; 14 | n = n/10; 15 | result += rem; 16 | } 17 | return result; 18 | } 19 | } -------------------------------------------------------------------------------- /258-add-digits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /26-remove-duplicates-from-sorted-array/26-remove-duplicates-from-sorted-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeDuplicates(int[] nums) { 3 | int left=0,right=1; 4 | for (int i=1;i>1; 14 | pos++; 15 | } 16 | 17 | // Mask with pos bit set to 1 18 | int mask = 1<0) 22 | num1 = num1^nums[i]; 23 | } 24 | 25 | num2 = num1^xor; 26 | 27 | return new int[]{num1,num2}; 28 | } 29 | } -------------------------------------------------------------------------------- /260-single-number-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /263-ugly-number/263-ugly-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isUgly(int n) { 3 | if (n<=0) return false; 4 | while (n%2==0) n=n/2; 5 | while (n%3==0) n=n/3; 6 | while (n%5==0) n=n/5; 7 | return n==1; 8 | } 9 | } -------------------------------------------------------------------------------- /263-ugly-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /264-ugly-number-ii/264-ugly-number-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int nthUglyNumber(int n) { 3 | if(n==1) return 1; 4 | PriorityQueue q = new PriorityQueue(); 5 | q.add(1); 6 | 7 | for(int i=1;i=0) == (divisor>=0) ? 1:-1; 5 | 6 | if (dividend==Integer.MIN_VALUE && divisor==-1) 7 | return Integer.MAX_VALUE; 8 | 9 | dividend=Math.abs(dividend); 10 | divisor=Math.abs(divisor); 11 | 12 | while (dividend-divisor>=0) { 13 | int count=0; 14 | while (dividend - (divisor<<1<= 0) { 15 | count++; 16 | } 17 | quotient += 1<0 && nums[index]<=nums[index-1]) 6 | index--; 7 | index=index-1; //Index is -1 in case of descending order array 8 | 9 | if (index>=0) { 10 | int j=nums.length-1; 11 | while (nums[index]>=nums[j]) 12 | j--; 13 | swap(nums,index,j); 14 | } 15 | 16 | // Reverse array after index i.e index+1 17 | int start=index+1; 18 | int end=nums.length-1; 19 | while (start 1111 17 | lastBit -> 1 for odd numbers and 0 for even numbers 18 | Exclude last bit -> Number becomes 15/2 19 | 20 | i.e 21 | countSetBits[n] = lastBit(1 if set, 0 if unset) + countBits[n/2] 22 | 23 | */ 24 | -------------------------------------------------------------------------------- /338-counting-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /338-counting-bits/solution1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] countBits(int n) { 3 | int ans[] = new int[n+1]; 4 | for (int i=0;i<=n;i++) { 5 | ans[i]=count(i); 6 | } 7 | return ans; 8 | } 9 | 10 | public int count(int num) { 11 | int ans = 0; 12 | while (num>0) { 13 | num = num&(num-1); // Removes the last set bit 14 | ans++; 15 | } 16 | return ans; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /343-integer-break/343-integer-break.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int integerBreak(int n) { 3 | 4 | // dp[i] represnets the maximum product for integer i 5 | int dp[] = new int[n+1]; 6 | Arrays.fill(dp,Integer.MIN_VALUE); 7 | 8 | for (int i=2;i<=n;i++) { 9 | for (int j=1;j343. Integer Break

Medium


Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.

2 | 3 |

Return the maximum product you can get.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
Input: n = 2
 9 | Output: 1
10 | Explanation: 2 = 1 + 1, 1 × 1 = 1.
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: n = 10
16 | Output: 36
17 | Explanation: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36.
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • 2 <= n <= 58
  • 25 |
26 |
-------------------------------------------------------------------------------- /344-reverse-string/344-reverse-string.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void reverseString(char[] s) { 3 | int n = s.length; 4 | for (int i=0;i vals = new HashSet<>(); 6 | for (int i=0,len=nums2.length;i intersections = new HashSet<>(); 11 | for (int i=0,len=nums1.length;itarget) { 12 | high=mid-1; 13 | } 14 | else { 15 | low=mid+1; 16 | } 17 | } 18 | 19 | return low; 20 | } 21 | } -------------------------------------------------------------------------------- /35-search-insert-position/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /350-intersection-of-two-arrays-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /357-count-numbers-with-unique-digits/357-count-numbers-with-unique-digits.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countNumbersWithUniqueDigits(int n) { 3 | if (n==0) 4 | return 1; 5 | 6 | int ans = 0; 7 | for (int i=1;i<=n;i++) { 8 | ans += countUniqueNumbers(i); 9 | } 10 | 11 | return ans; 12 | } 13 | 14 | // Returns count of unique n digit numbers (Exactly length n) 15 | private int countUniqueNumbers(int n) { 16 | if (n==1) 17 | return 10; 18 | 19 | int count = 9; 20 | int curr = 9; 21 | for (int i=2;i<=n;i++) { 22 | count = count*curr; 23 | curr--; 24 | } 25 | return count; 26 | } 27 | } -------------------------------------------------------------------------------- /357-count-numbers-with-unique-digits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /357-count-numbers-with-unique-digits/README.md: -------------------------------------------------------------------------------- 1 |

357. Count Numbers with Unique Digits

Medium


Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 2
 7 | Output: 91
 8 | Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: n = 0
14 | Output: 1
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 0 <= n <= 8
  • 22 |
23 |
-------------------------------------------------------------------------------- /36-valid-sudoku/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /365-water-and-jug-problem/365-water-and-jug-problem.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canMeasureWater(int jug1, int jug2, int target) { 3 | if (jug1+jug2num) 11 | high=(int)mid-1; 12 | else 13 | low=(int)mid+1; 14 | } 15 | 16 | return false; 17 | } 18 | } -------------------------------------------------------------------------------- /367-valid-perfect-square/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /37-sudoku-solver/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /372-super-pow/372-super-pow.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int MOD = 1337; 3 | 4 | public int superPow(int a, int[] b) { 5 | a%=MOD; 6 | int result = 1; 7 | 8 | for (int digit: b) { 9 | result = (pow(result,10)*pow(a,digit))%MOD; 10 | } 11 | 12 | return result; 13 | } 14 | 15 | private int pow(int x,int n) { 16 | int ans = 1; 17 | while (n!=0) { 18 | int last_bit = (n&1); 19 | if (last_bit==1) 20 | ans = (ans*x)%MOD; 21 | x = (x*x)%MOD; 22 | n = n>>>1; 23 | } 24 | 25 | return ans; 26 | } 27 | } -------------------------------------------------------------------------------- /372-super-pow/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /374-guess-number-higher-or-lower/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /377-combination-sum-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /38-count-and-say/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /386-lexicographical-numbers/386-lexicographical-numbers.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List lexicalOrder(int n) { 3 | List res = new ArrayList<>(); 4 | getNums(res,0,n); 5 | return res; 6 | } 7 | 8 | public void getNums(List res,int i,int num) { 9 | //if (i>num) return; 10 | 11 | if (i!=0 && i<=num) 12 | res.add(i); 13 | 14 | for (int j= (i==0) ? 1:0;j<=9;j++) { 15 | int n = i*10+j; 16 | if (n<=num) { 17 | getNums(res,n,num); 18 | } 19 | else { 20 | return; 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /386-lexicographical-numbers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /386-lexicographical-numbers/README.md: -------------------------------------------------------------------------------- 1 |

386. Lexicographical Numbers

Medium


Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.

2 | 3 |

You must write an algorithm that runs in O(n) time and uses O(1) extra space. 

4 | 5 |

 

6 |

Example 1:

7 |
Input: n = 13
 8 | Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]
 9 | 

Example 2:

10 |
Input: n = 2
11 | Output: [1,2]
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= n <= 5 * 104
  • 18 |
19 |
-------------------------------------------------------------------------------- /389-find-the-difference/389-find-the-difference.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public char findTheDifference(String s, String t) { 3 | int[] freq=new int[26]; 4 | for(int i=0;i length*digits) { 7 | n -= length*digits; 8 | length++; 9 | first *= 10; 10 | digits *= 10; 11 | } 12 | 13 | 14 | 15 | // First now points to first kth digit number (1,10,100,1000....etc) 16 | // where nth digit lies in a k digit number 17 | 18 | first = first + (n-1)/length; 19 | 20 | // First now points to the number which contains the nth digit 21 | 22 | String num = Integer.toString(first); 23 | char digit = num.charAt((n-1)%length); 24 | 25 | return digit-'0'; 26 | } 27 | } -------------------------------------------------------------------------------- /400-nth-digit/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /400-nth-digit/README.md: -------------------------------------------------------------------------------- 1 |

400. Nth Digit

Medium


Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 3
 7 | Output: 3
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: n = 11
13 | Output: 0
14 | Explanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 1 <= n <= 231 - 1
  • 22 |
23 |
-------------------------------------------------------------------------------- /406-queue-reconstruction-by-height/406-queue-reconstruction-by-height.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] reconstructQueue(int[][] people) { 3 | // Sort people on descending order of height 4 | // and ascending order of k 5 | Arrays.sort(people, (a,b) -> a[0]==b[0] ? a[1]-b[1] : b[0]-a[0]); 6 | 7 | // Now take one element from array and add it at the kth position 8 | List ordered = new LinkedList<>(); 9 | for (int[] p: people) 10 | ordered.add(p[1], p); 11 | 12 | return ordered.toArray(new int[people.length][2]); 13 | } 14 | } -------------------------------------------------------------------------------- /406-queue-reconstruction-by-height/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /409-longest-palindrome/409-longest-palindrome.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestPalindrome(String s) { 3 | int freq[] = new int[52]; 4 | for (char ch : s.toCharArray()) { 5 | if (Character.isUpperCase(ch)) { 6 | freq[ch-'A']++; 7 | } 8 | else { 9 | freq[26+ch-'a']++; 10 | } 11 | } 12 | 13 | int ans = 0; 14 | boolean containsOdd = false; 15 | 16 | for (int i=0;i<52;i++) { 17 | if (freq[i]%2==0) { 18 | // Even 19 | ans = ans + freq[i]; 20 | } 21 | else { 22 | ans = ans + freq[i] - 1; 23 | containsOdd=true; 24 | } 25 | } 26 | 27 | ans = ans + (containsOdd ? 1 : 0); 28 | return ans; 29 | } 30 | } -------------------------------------------------------------------------------- /409-longest-palindrome/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /41-first-missing-positive/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /412-fizz-buzz/412-fizz-buzz.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List fizzBuzz(int n) { 3 | List ans = new ArrayList<>(); 4 | for (int i=1;i<=n;i++) { 5 | if (i%3==0 && i%5==0) 6 | ans.add("FizzBuzz"); 7 | else if (i%3==0) 8 | ans.add("Fizz"); 9 | else if (i%5==0) 10 | ans.add("Buzz"); 11 | else 12 | ans.add(Integer.toString(i)); 13 | } 14 | return ans; 15 | } 16 | } -------------------------------------------------------------------------------- /412-fizz-buzz/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /416-partition-equal-subset-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /42-trapping-rain-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /421-maximum-xor-of-two-numbers-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /43-multiply-strings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /435-non-overlapping-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /437-path-sum-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /44-wildcard-matching/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /445-add-two-numbers-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /45-jump-game-ii/45-jump-game-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int jump(int[] nums) { 3 | int jumps = 0; 4 | int current = 0; 5 | int farthest = 0; // Farthest index where you can reach 6 | 7 | for (int i=0;i=nums.length) 10 | return Integer.MAX_VALUE; 11 | 12 | if (index==nums.length-1) 13 | return 0; 14 | 15 | if (dp[index]!=-1) 16 | return dp[index]; 17 | 18 | int curr = nums[index]; 19 | int minMoves = Integer.MAX_VALUE; 20 | for (int i=1;i<=curr;i++) { 21 | int h = helper(nums,index+i,dp); 22 | if (h!=Integer.MAX_VALUE) 23 | minMoves = Math.min(minMoves,1+h); 24 | } 25 | 26 | return dp[index]=minMoves; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /45-jump-game-ii/solution2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int jump(int[] nums) { 3 | int n = nums.length; 4 | int dp[] = new int[n]; 5 | Arrays.fill(dp,Integer.MAX_VALUE); 6 | dp[n-1]=0; 7 | for (int i=n-2;i>=0;i--) { 8 | int curr = nums[i]; 9 | for (int j=1;j<=curr;j++) { 10 | if (i+jIllustrations 2 | 3 | When node to be deleted has only one child - 4 | ![image](https://user-images.githubusercontent.com/56895638/175042564-ceee9f5a-cfd2-4cc0-9dbb-f873a3fa41b7.png) 5 | 6 | 7 | When node to be deleted has both child, we find inorder succesor of node and replace its value and delete the successor node - 8 | ![image](https://user-images.githubusercontent.com/56895638/175042895-4d83e334-383e-4996-ace1-b7c10f078992.png) 9 | -------------------------------------------------------------------------------- /452-minimum-number-of-arrows-to-burst-balloons/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /453-minimum-moves-to-equal-array-elements/453-minimum-moves-to-equal-array-elements.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minMoves(int[] nums) { 3 | // Incrementing n-1 elements of array by 1 to make equal array elements 4 | // This is similar to 5 | // Decrementing 1 element of array by 1 to make all elements equal 6 | 7 | // Decrement each element to reach the smallest element in array 8 | // Moves required for each index will be (value-smallest) 9 | // Summing for all 10 | // (nums[0]-smallest) + (nums[1]-smallest) + (nums[2]-smallest) + ........... 11 | // Equivalent to (Sum of array - n*smallest) 12 | 13 | int min = nums[0]; 14 | int sum = 0; 15 | for (int num: nums) { 16 | min = Math.min(min,num); 17 | sum+=num; 18 | } 19 | 20 | return sum-nums.length*min; 21 | } 22 | } -------------------------------------------------------------------------------- /453-minimum-moves-to-equal-array-elements/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /455-assign-cookies/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /46-permutations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /462-minimum-moves-to-equal-array-elements-ii/462-minimum-moves-to-equal-array-elements-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minMoves2(int[] nums) { 3 | Arrays.sort(nums); 4 | int n = nums.length; 5 | 6 | int mid = n/2; 7 | 8 | int moves = 0; // Move complete array to equal to mid 9 | 10 | for (int i=0;i47. Permutations II

Medium


Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: nums = [1,1,2]
 7 | Output:
 8 | [[1,1,2],
 9 |  [1,2,1],
10 |  [2,1,1]]
11 | 
12 | 13 |

Example 2:

14 | 15 |
Input: nums = [1,2,3]
16 | Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= nums.length <= 8
  • 24 |
  • -10 <= nums[i] <= 10
  • 25 |
26 |
-------------------------------------------------------------------------------- /474-ones-and-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /48-rotate-image/48-rotate-image.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void rotate(int[][] matrix) { 3 | int n = matrix[0].length; 4 | 5 | // Finding tranpose of matrix 6 | for (int i=0;i> groupAnagrams(String[] strs) { 3 | List> list = new ArrayList<>(); 4 | HashMap> map = new HashMap<>(); 5 | 6 | for(String i : strs){ 7 | char[] ch = i.toCharArray(); 8 | Arrays.sort(ch); 9 | String s = new String(ch); 10 | 11 | if(map.containsKey(s)){ 12 | map.get(s).add(i); 13 | } 14 | else{ 15 | List temp = new ArrayList<>(); 16 | temp.add(i); 17 | map.put(s,temp); 18 | } 19 | } 20 | 21 | for(String i : map.keySet()){ 22 | list.add(map.get(i)); 23 | } 24 | return list; 25 | } 26 | } -------------------------------------------------------------------------------- /49-group-anagrams/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /491-increasing-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /493-reverse-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /493-reverse-pairs/README.md: -------------------------------------------------------------------------------- 1 |

493. Reverse Pairs

Hard


Given an integer array nums, return the number of reverse pairs in the array.

2 | 3 |

A reverse pair is a pair (i, j) where 0 <= i < j < nums.length and nums[i] > 2 * nums[j].

4 | 5 |

 

6 |

Example 1:

7 |
Input: nums = [1,3,2,3,1]
 8 | Output: 2
 9 | 

Example 2:

10 |
Input: nums = [2,4,3,5,1]
11 | Output: 3
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= nums.length <= 5 * 104
  • 18 |
  • -231 <= nums[i] <= 231 - 1
  • 19 |
20 |
-------------------------------------------------------------------------------- /494-target-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /496-next-greater-element-i/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /498-diagonal-traverse/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /5-longest-palindromic-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /5-longest-palindromic-substring/README.md: -------------------------------------------------------------------------------- 1 |

5. Longest Palindromic Substring

Medium


Given a string s, return the longest palindromic substring in s.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: s = "babad"
 7 | Output: "bab"
 8 | Explanation: "aba" is also a valid answer.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: s = "cbbd"
14 | Output: "bb"
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 1 <= s.length <= 1000
  • 22 |
  • s consist of only digits and English letters.
  • 23 |
24 |
-------------------------------------------------------------------------------- /50-powx-n/50-powx-n.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double myPow(double x, int n) { 3 | double ans = 1; 4 | if (n<0) { 5 | x = 1.0/x; 6 | n = -n; 7 | } 8 | 9 | 10 | while (n!=0) { 11 | int last_bit = (n&1); 12 | ans *= last_bit==1 ? x : 1; 13 | x = x*x; 14 | n = n>>>1; 15 | } 16 | 17 | return ans; 18 | } 19 | } -------------------------------------------------------------------------------- /50-powx-n/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /501-find-mode-in-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /503-next-greater-element-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /509-fibonacci-number/509-fibonacci-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int fib(int n) { 3 | int dp[] = new int[n+1]; 4 | 5 | for (int i=0;i<=n;i++) { 6 | if (i==0) 7 | dp[i]=0; 8 | else if (i==1) 9 | dp[i]=1; 10 | else 11 | dp[i]=dp[i-1]+dp[i-2]; 12 | } 13 | 14 | return dp[n]; 15 | } 16 | } -------------------------------------------------------------------------------- /51-n-queens/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /513-find-bottom-left-tree-value/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /515-find-largest-value-in-each-tree-row/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /518-coin-change-2/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /52-n-queens-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /523-continuous-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /529-minesweeper/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /53-maximum-subarray/53-maximum-subarray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxSubArray(int[] nums) { 3 | int maxSum = Integer.MIN_VALUE; 4 | int tempSum = 0; 5 | for (int i: nums) { 6 | tempSum = Math.max(tempSum+i,i); 7 | maxSum = Math.max(maxSum,tempSum); 8 | } 9 | return maxSum; 10 | } 11 | } -------------------------------------------------------------------------------- /53-maximum-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /530-minimum-absolute-difference-in-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /538-convert-bst-to-greater-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /539-minimum-time-difference/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /539-minimum-time-difference/README.md: -------------------------------------------------------------------------------- 1 |

539. Minimum Time Difference

Medium


Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list. 2 |

 

3 |

Example 1:

4 |
Input: timePoints = ["23:59","00:00"]
 5 | Output: 1
 6 | 

Example 2:

7 |
Input: timePoints = ["00:00","23:59","00:00"]
 8 | Output: 0
 9 | 
10 |

 

11 |

Constraints:

12 | 13 |
    14 |
  • 2 <= timePoints.length <= 2 * 104
  • 15 |
  • timePoints[i] is in the format "HH:MM".
  • 16 |
17 |
-------------------------------------------------------------------------------- /54-spiral-matrix/54-spiral-matrix.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List spiralOrder(int[][] matrix) { 3 | int rows = matrix.length; 4 | int cols = matrix[0].length; 5 | List ans = new ArrayList<>(); 6 | 7 | int rowBegin=0,rowEnd=rows-1; 8 | int colBegin=0,colEnd=cols-1; 9 | 10 | while (rowBegin<=rowEnd && colBegin<=colEnd) { 11 | for (int c=colBegin;c<=colEnd;c++) 12 | ans.add(matrix[rowBegin][c]); 13 | for (int r=++rowBegin;r<=rowEnd;r++) 14 | ans.add(matrix[r][colEnd]); 15 | for (int c=--colEnd;c>=colBegin && rowBegin<=rowEnd;c--) 16 | ans.add(matrix[rowEnd][c]); 17 | for (int r=--rowEnd;r>=rowBegin && colBegin<=colEnd;r--) 18 | ans.add(matrix[r][colBegin]); 19 | colBegin++; 20 | } 21 | return ans; 22 | } 23 | } -------------------------------------------------------------------------------- /54-spiral-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /542-01-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /543-diameter-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /547-number-of-provinces/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /55-jump-game/55-jump-game.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int n = nums.length; 4 | 5 | // Determines the last index through which we can reach 6 | // last index of array 7 | int lastGoodIndex = n-1; 8 | for (int i=n-2;i>=0;i--) { 9 | int curr = nums[i]; 10 | if (i+nums[i]>=lastGoodIndex) { 11 | lastGoodIndex=i; 12 | } 13 | } 14 | 15 | return lastGoodIndex==0; 16 | } 17 | } -------------------------------------------------------------------------------- /55-jump-game/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /55-jump-game/solution1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int dp[] = new int[nums.length]; 4 | Arrays.fill(dp,-1); 5 | return helper(nums,0,dp); 6 | } 7 | 8 | private boolean helper(int[] nums,int index,int[] dp) { 9 | if (index>=nums.length) 10 | return false; 11 | 12 | if (index==nums.length-1) 13 | return true; 14 | 15 | if (dp[index]!=-1) { 16 | return dp[index]==1; 17 | } 18 | 19 | for (int i=1;i<=nums[index];i++) { 20 | if (helper(nums,index+i,dp)) { 21 | dp[index]=1; 22 | return true; 23 | } 24 | } 25 | 26 | dp[index]=0; 27 | return false; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /55-jump-game/solution2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int n = nums.length; 4 | boolean dp[] = new boolean[n]; 5 | dp[n-1]=true; 6 | for (int i=n-2;i>=0;i--) { 7 | int curr = nums[i]; 8 | for (int j=1;j<=curr;j++) { 9 | if (i+j prefixSum = new HashMap<>(); 6 | prefixSum.put(0,1); // Prefix sum 0 - subarray with no elements 7 | 8 | int sum = 0; 9 | for (int i=0;i59. Spiral Matrix II

Medium


Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: n = 3
 7 | Output: [[1,2,3],[8,9,4],[7,6,5]]
 8 | 
9 | 10 |

Example 2:

11 | 12 |
Input: n = 1
13 | Output: [[1]]
14 | 
15 | 16 |

 

17 |

Constraints:

18 | 19 |
    20 |
  • 1 <= n <= 20
  • 21 |
22 |
-------------------------------------------------------------------------------- /590-n-ary-tree-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /6-zigzag-conversion/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /60-permutation-sequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /61-rotate-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /611-valid-triangle-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /617-merge-two-binary-trees/617-merge-two-binary-trees.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public TreeNode mergeTrees(TreeNode root1, TreeNode root2) { 18 | if (root1==null) 19 | return root2; 20 | 21 | if (root2==null) 22 | return root1; 23 | 24 | root1.val = root1.val+root2.val; 25 | root1.left = mergeTrees(root1.left,root2.left); 26 | root1.right = mergeTrees(root1.right,root2.right); 27 | 28 | return root1; 29 | } 30 | } -------------------------------------------------------------------------------- /617-merge-two-binary-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /62-unique-paths/62-unique-paths.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int uniquePaths(int m, int n) { 3 | // Dp array representing no of paths starting from that point (i,j) to finish 4 | int dp[][] = new int[m][n]; 5 | 6 | for (int i=m-1;i>=0;i--) { 7 | for(int j=n-1;j>=0;j--) { 8 | if (i==m-1 && j==n-1) { 9 | dp[i][j] = 1; 10 | } 11 | else { 12 | int t1 = (i+1)n) 20 | high=(int)mid-1; 21 | else 22 | low=(int)mid+1; 23 | } 24 | return false; 25 | } 26 | } -------------------------------------------------------------------------------- /633-sum-of-square-numbers/README.md: -------------------------------------------------------------------------------- 1 |

633. Sum of Square Numbers

Medium


Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: c = 5
 7 | Output: true
 8 | Explanation: 1 * 1 + 2 * 2 = 5
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: c = 3
14 | Output: false
15 | 
16 | 17 |

 

18 |

Constraints:

19 | 20 |
    21 |
  • 0 <= c <= 231 - 1
  • 22 |
23 |
-------------------------------------------------------------------------------- /639-decode-ways-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /64-minimum-path-sum/64-minimum-path-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minPathSum(int[][] grid) { 3 | int m = grid.length; 4 | int n = grid[0].length; 5 | 6 | // Update grid to store maximum values- dp 7 | for (int i=0;i=0;i--) { 6 | if (digits[i]!=9 && carry==1) { 7 | ans[i]=digits[i]+carry; 8 | carry=0; 9 | } 10 | else if (carry==0) { 11 | ans[i]=digits[i]; 12 | } 13 | else { 14 | ans[i]=0; 15 | } 16 | } 17 | 18 | if (carry==1) { 19 | ans = new int[digits.length+1]; 20 | ans[0]=1; 21 | } 22 | 23 | return ans; 24 | } 25 | } -------------------------------------------------------------------------------- /66-plus-one/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /662-maximum-width-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /67-add-binary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /67-add-binary/README.md: -------------------------------------------------------------------------------- 1 |

67. Add Binary

Easy


Given two binary strings a and b, return their sum as a binary string.

2 | 3 |

 

4 |

Example 1:

5 |
Input: a = "11", b = "1"
 6 | Output: "100"
 7 | 

Example 2:

8 |
Input: a = "1010", b = "1011"
 9 | Output: "10101"
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= a.length, b.length <= 104
  • 16 |
  • a and b consist only of '0' or '1' characters.
  • 17 |
  • Each string does not contain leading zeros except for the zero itself.
  • 18 |
19 |
-------------------------------------------------------------------------------- /673-number-of-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /674-longest-continuous-increasing-subsequence/674-longest-continuous-increasing-subsequence.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findLengthOfLCIS(int[] nums) { 3 | int n=nums.length; 4 | int i=1; 5 | int LCIS=1; 6 | 7 | int currlen=1; 8 | while (inums[i-1]) { 10 | currlen++; 11 | } 12 | else { 13 | currlen=1; 14 | } 15 | LCIS=Math.max(LCIS,currlen); 16 | i++; 17 | } 18 | 19 | return LCIS; 20 | } 21 | } -------------------------------------------------------------------------------- /674-longest-continuous-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /680-valid-palindrome-ii/680-valid-palindrome-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean validPalindrome(String s) { 3 | return isPalindrome(s,0,s.length()-1,false); 4 | } 5 | 6 | private boolean isPalindrome(String s,int i,int j,boolean delete) { 7 | if (i>=j) 8 | return true; 9 | 10 | if (s.charAt(i)==s.charAt(j)) 11 | return isPalindrome(s,i+1,j-1,delete); 12 | 13 | if (!delete) // Not deleted any character yet 14 | return isPalindrome(s,i+1,j,true) || isPalindrome(s,i,j-1,true); 15 | 16 | return false; 17 | } 18 | } -------------------------------------------------------------------------------- /680-valid-palindrome-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /684-redundant-connection/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /685-redundant-connection-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /686-repeated-string-match/686-repeated-string-match.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int repeatedStringMatch(String a, String b) { 3 | int aLen = a.length(); 4 | int bLen = b.length(); 5 | 6 | int repeat = (int)Math.ceil(bLen*1.0/aLen); 7 | 8 | String temp=""; 9 | for (int i=0;ix) 13 | high=(int)mid-1; 14 | else 15 | low=(int)mid+1; 16 | } 17 | return high; 18 | } 19 | } -------------------------------------------------------------------------------- /69-sqrtx/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /7-reverse-integer/7-reverse-integer.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int reverse(int x) { 3 | int reverse=0; 4 | int rem; 5 | 6 | /* 7 | 2^31 = 2147483648 (ends in 8) 8 | 2^31-1 = 2147483647 (ends in 7) 9 | */ 10 | 11 | while (x!=0) 12 | { 13 | rem=x%10; 14 | x=x/10; 15 | 16 | if (reverse>Integer.MAX_VALUE/10 || 17 | (reverse==Integer.MAX_VALUE/10 && rem>7)) 18 | return 0; 19 | if (reverseval) 22 | return searchBST(root.left,val); 23 | else 24 | return searchBST(root.right,val); 25 | } 26 | } -------------------------------------------------------------------------------- /701-insert-into-a-binary-search-tree/701-insert-into-a-binary-search-tree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * public class TreeNode { 4 | * int val; 5 | * TreeNode left; 6 | * TreeNode right; 7 | * TreeNode() {} 8 | * TreeNode(int val) { this.val = val; } 9 | * TreeNode(int val, TreeNode left, TreeNode right) { 10 | * this.val = val; 11 | * this.left = left; 12 | * this.right = right; 13 | * } 14 | * } 15 | */ 16 | class Solution { 17 | public TreeNode insertIntoBST(TreeNode root, int val) { 18 | if (root==null) 19 | return new TreeNode(val); 20 | 21 | if (root.val>val) 22 | root.left = insertIntoBST(root.left,val); 23 | else 24 | root.right = insertIntoBST(root.right,val); 25 | 26 | return root; 27 | } 28 | } -------------------------------------------------------------------------------- /704-binary-search/704-binary-search.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int search(int[] nums, int target) { 3 | return binarySearch(nums,target,0,nums.length-1); 4 | } 5 | 6 | private int binarySearch(int nums[],int target,int low,int high) { 7 | if (low>high) { 8 | return -1; 9 | } 10 | 11 | int mid = (low+high)/2; 12 | if (nums[mid]==target) 13 | return mid; 14 | else if (nums[mid]>target) 15 | return binarySearch(nums,target,low,mid-1); 16 | else 17 | return binarySearch(nums,target,mid+1,high); 18 | } 19 | } -------------------------------------------------------------------------------- /704-binary-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /709-to-lower-case/709-to-lower-case.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String toLowerCase(String s) { 3 | String ans = ""; 4 | for (char ch: s.toCharArray()) { 5 | if (Character.isUpperCase(ch)) 6 | ans += (char)(ch+32); 7 | else 8 | ans += ch; 9 | } 10 | return ans; 11 | } 12 | } -------------------------------------------------------------------------------- /709-to-lower-case/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /71-simplify-path/71-simplify-path.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String simplifyPath(String path) { 3 | String[] tokens = path.split("/"); 4 | Stack s = new Stack<>(); 5 | 6 | for (int i=0;i map = new TreeMap<>(); 3 | 4 | public MyCalendar() { 5 | 6 | } 7 | 8 | public boolean book(int start, int end) { 9 | Integer floor = map.floorKey(start); 10 | Integer ceil = map.ceilingKey(start); 11 | if (floor!=null) { 12 | if (map.get(floor)>end || map.get(floor)>start) 13 | return false; 14 | } 15 | if (ceil!=null) { 16 | if (end>ceil) 17 | return false; 18 | } 19 | map.put(start,end); 20 | return true; 21 | } 22 | } 23 | 24 | /** 25 | * Your MyCalendar object will be instantiated and called as such: 26 | * MyCalendar obj = new MyCalendar(); 27 | * boolean param_1 = obj.book(start,end); 28 | */ -------------------------------------------------------------------------------- /729-my-calendar-i/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /73-set-matrix-zeroes/73-set-matrix-zeroes.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void setZeroes(int[][] matrix) { 3 | int m = matrix.length; 4 | int n = matrix[0].length; 5 | 6 | // Determine which rows and columns to update 7 | boolean[] rows = new boolean[m]; 8 | boolean[] cols = new boolean[n]; 9 | 10 | for (int i=0;i s = new Stack<>(); 8 | s.push(0); // Push Index 0 9 | 10 | for (int i=1;i points = new HashMap<>(); 4 | int maxNum = 0; 5 | for (int i: nums) { 6 | points.put(i,points.getOrDefault(i,0)+i); 7 | maxNum=Math.max(maxNum,i); 8 | } 9 | 10 | // dp[i] stores max points that can be achieved using 0 to i 11 | int dp[] = new int[maxNum+1]; 12 | dp[0] = 0; 13 | dp[1] = points.getOrDefault(1,0); // Count of occurences of 1 14 | 15 | for (int i=2;itarget) 11 | high=mid-1; 12 | else 13 | low=mid+1; 14 | } 15 | 16 | return letters[low%letters.length]; 17 | } 18 | } -------------------------------------------------------------------------------- /744-find-smallest-letter-greater-than-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/746-min-cost-climbing-stairs.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minCostClimbingStairs(int[] cost) { 3 | int n = cost.length; 4 | 5 | // dp[i] represents min cost from step i to reach top of the floor 6 | int dp[] = new int[n+1]; 7 | dp[n] = 0; 8 | 9 | for (int i=n-1;i>=0;i--) { 10 | if (i==n-1) 11 | dp[i] = cost[i]+dp[i+1]; 12 | else 13 | dp[i] = cost[i]+Math.min(dp[i+1],dp[i+2]); 14 | } 15 | 16 | return Math.min(dp[0],dp[1]); 17 | } 18 | } -------------------------------------------------------------------------------- /746-min-cost-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /75-sort-colors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /76-minimum-window-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /767-reorganize-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /767-reorganize-string/README.md: -------------------------------------------------------------------------------- 1 |

767. Reorganize String

Medium


Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.

2 | 3 |

Return any possible rearrangement of s or return "" if not possible.

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = "aab"
 8 | Output: "aba"
 9 | 

Example 2:

10 |
Input: s = "aaab"
11 | Output: ""
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= s.length <= 500
  • 18 |
  • s consists of lowercase English letters.
  • 19 |
20 |
-------------------------------------------------------------------------------- /77-combinations/77-combinations.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> combine(int n, int k) { 3 | List> ans = new ArrayList<>(); 4 | getCombinations(ans,n,1,k,new ArrayList<>()); 5 | return ans; 6 | } 7 | 8 | private void getCombinations(List> ans,int n, 9 | int index,int k,List temp) { 10 | if (k==0) { 11 | ans.add(temp); 12 | return; 13 | } 14 | 15 | for (int i=index;i<=n-k+1;i++) { 16 | temp.add(i); 17 | getCombinations(ans,n,i+1,k-1,new ArrayList<>(temp)); 18 | temp.remove(temp.size()-1); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /77-combinations/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /775-global-and-local-inversions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /78-subsets/78-subsets.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> subsets(int[] nums) { 3 | List> list= new ArrayList<>(); 4 | 5 | // No of subsets possible: 2^N where N is size of array 6 | int n = nums.length; 7 | 8 | int subsets = 1< getSubset(int i,int nums[]) { 17 | List a = new ArrayList<>(); 18 | 19 | int j=0; 20 | while (i>0) { 21 | int lastBit = (i&1); 22 | if (lastBit==1) { 23 | a.add(nums[j]); 24 | } 25 | j++; 26 | i = i>>1; 27 | } 28 | 29 | return a; 30 | } 31 | } -------------------------------------------------------------------------------- /78-subsets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /781-rabbits-in-forest/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /783-minimum-distance-between-bst-nodes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /785-is-graph-bipartite/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /79-word-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /790-domino-and-tromino-tiling/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /792-number-of-matching-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /796-rotate-string/796-rotate-string.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean rotateString(String s, String goal) { 3 | s=s+s; 4 | return s.contains(goal) && s.length()==2*goal.length(); 5 | } 6 | } -------------------------------------------------------------------------------- /796-rotate-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /797-all-paths-from-source-to-target/797-all-paths-from-source-to-target.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> allPathsSourceTarget(int[][] graph) { 3 | int n = graph.length; 4 | List> ans = new ArrayList<>(); 5 | List path = new ArrayList<>(); 6 | path.add(0); 7 | dfs(graph,ans,0,n-1,path); 8 | return ans; 9 | } 10 | 11 | private void dfs(int[][] graph,List> ans,int src, 12 | int dst,List path) { 13 | if (src==dst) { 14 | ans.add(new ArrayList<>(path)); 15 | return; 16 | } 17 | 18 | for (int neighbor: graph[src]) { 19 | path.add(neighbor); 20 | dfs(graph,ans,neighbor,dst,path); 21 | path.remove(path.size()-1); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /797-all-paths-from-source-to-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /8-string-to-integer-atoi/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /80-remove-duplicates-from-sorted-array-ii/80-remove-duplicates-from-sorted-array-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeDuplicates(int[] nums) { 3 | int i=0; 4 | for (int n:nums) 5 | if (i<2 || n>nums[i-2]) 6 | nums[i++]=n; 7 | 8 | return i; 9 | } 10 | } -------------------------------------------------------------------------------- /80-remove-duplicates-from-sorted-array-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /802-find-eventual-safe-states/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /823-binary-trees-with-factors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public ListNode deleteDuplicates(ListNode head) { 13 | if (head==null || head.next==null) 14 | return head; 15 | 16 | ListNode curr = head; 17 | while (curr.next!=null) { 18 | if (curr.next.val==curr.val) { 19 | curr.next=curr.next.next; 20 | } 21 | else { 22 | curr=curr.next; 23 | } 24 | } 25 | 26 | return head; 27 | } 28 | } -------------------------------------------------------------------------------- /83-remove-duplicates-from-sorted-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /834-sum-of-distances-in-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /835-image-overlap/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /84-largest-rectangle-in-histogram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /841-keys-and-rooms/841-keys-and-rooms.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canVisitAllRooms(List> rooms) { 3 | int n = rooms.size(); // No of rooms 4 | boolean[] visited = new boolean[n]; 5 | 6 | //DFS 7 | dfs(rooms,visited,0); 8 | 9 | for (int i=0;i> rooms,boolean[] visited,int currRoom) { 18 | visited[currRoom]=true; 19 | for (Integer r: rooms.get(currRoom)) { 20 | if (!visited[r]) 21 | dfs(rooms,visited,r); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /841-keys-and-rooms/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /85-maximal-rectangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /852-peak-index-in-a-mountain-array/852-peak-index-in-a-mountain-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int peakIndexInMountainArray(int[] arr) { 3 | int low = 0; 4 | int high = arr.length-1; 5 | 6 | while (low<=high) { 7 | int mid = low + (high-low)/2; 8 | 9 | if (arr[mid]>arr[mid+1]) { 10 | high=mid-1; 11 | } 12 | else if (arr[mid] grayCode(int n) { 3 | List ans = new ArrayList<>(); 4 | 5 | int[] dp = new int[(int)Math.pow(2,n)]; 6 | dp[0]=0; 7 | dp[1]=1; 8 | for (int i=2;i<=n;i++) { 9 | int start = (int)Math.pow(2,i-1); 10 | int end = (int)Math.pow(2,i); 11 | int curr = 0; 12 | for (int k=end-1;k>=start;k--) { 13 | dp[k] = dp[curr]+start; 14 | curr++; 15 | } 16 | } 17 | 18 | for (int i=0;i=0 && x==y) 5 | return true; 6 | return false; 7 | } 8 | 9 | private int reverse(int x) 10 | { 11 | int reverse=0; 12 | int rem; 13 | 14 | while (x!=0) 15 | { 16 | rem=x%10; 17 | x=x/10; 18 | reverse=reverse*10+rem; 19 | } 20 | return reverse; 21 | } 22 | } -------------------------------------------------------------------------------- /9-palindrome-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /90-subsets-ii/90-subsets-ii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List> subsetsWithDup(int[] nums) { 3 | // No of subsets possible: 2^N where N is size of array 4 | int n = nums.length; 5 | 6 | int subsets = 1<> res = new HashSet<>(); 8 | 9 | for (int i=0;i(res); 13 | } 14 | 15 | public List getSubset(int i,int nums[]) { 16 | List a = new ArrayList<>(); 17 | 18 | int j=0; 19 | while (i>0) { 20 | int lastBit = (i&1); 21 | if (lastBit==1) { 22 | a.add(nums[j]); 23 | } 24 | j++; 25 | i = i>>1; 26 | } 27 | Collections.sort(a); 28 | return a; 29 | } 30 | } -------------------------------------------------------------------------------- /90-subsets-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /90-subsets-ii/README.md: -------------------------------------------------------------------------------- 1 |

90. Subsets II

Medium


Given an integer array nums that may contain duplicates, return all possible subsets (the power set).

2 | 3 |

The solution set must not contain duplicate subsets. Return the solution in any order.

4 | 5 |

 

6 |

Example 1:

7 |
Input: nums = [1,2,2]
 8 | Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
 9 | 

Example 2:

10 |
Input: nums = [0]
11 | Output: [[],[0]]
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= nums.length <= 10
  • 18 |
  • -10 <= nums[i] <= 10
  • 19 |
20 |
-------------------------------------------------------------------------------- /901-online-stock-span/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /904-fruit-into-baskets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /91-decode-ways/91-decode-ways.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numDecodings(String s) { 3 | int n = s.length(); 4 | 5 | if (s.charAt(0)=='0') 6 | return 0; 7 | 8 | // dp[i] represents no of encodings upto length i 9 | int dp[] = new int[n+1]; 10 | dp[0] = 1; // 1 encoding upto no length 11 | dp[1] = 1; // 1 encoding upto 1 length as now that num>0 12 | 13 | for (int i=2;i<=n;i++) { 14 | if (s.charAt(i-1)>'0'){ 15 | dp[i] = dp[i-1]; 16 | } 17 | 18 | if(s.charAt(i-2)=='1' || s.charAt(i-2)=='2' && s.charAt(i-1)<'7') { 19 | dp[i] += dp[i-2]; 20 | } 21 | } 22 | 23 | return dp[n]; 24 | } 25 | } -------------------------------------------------------------------------------- /91-decode-ways/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /910-smallest-range-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /912-sort-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /912-sort-an-array/README.md: -------------------------------------------------------------------------------- 1 |

912. Sort an Array

Medium


Given an array of integers nums, sort the array in ascending order.

2 | 3 |

 

4 |

Example 1:

5 |
Input: nums = [5,2,3,1]
 6 | Output: [1,2,3,5]
 7 | 

Example 2:

8 |
Input: nums = [5,1,1,2,0,0]
 9 | Output: [0,0,1,1,2,5]
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= nums.length <= 5 * 104
  • 16 |
  • -5 * 104 <= nums[i] <= 5 * 104
  • 17 |
18 |
-------------------------------------------------------------------------------- /918-maximum-sum-circular-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /92-reverse-linked-list-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /934-shortest-bridge/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /935-knight-dialer/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /94-binary-tree-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /940-distinct-subsequences-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /946-validate-stack-sequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /95-unique-binary-search-trees-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /96-unique-binary-search-trees/96-unique-binary-search-trees.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numTrees(int n) { 3 | 4 | // dp[i] represents the number of unique binary search trees consisting of i nodes 5 | int dp[] = new int[n+1]; 6 | 7 | dp[0]=1; 8 | dp[1]=1; 9 | 10 | for (int i=2;i<=n;i++) { 11 | // Determining no of unique bst for tree with i nodes 12 | // Consider each number as root once from 1 to i 13 | for (int j=1;j<=i;j++) { 14 | // If j is root 15 | // Left subtree can only contain nodes with value less than j i.e (j-1) nodes 16 | // Right subtree can only contain nodes with value more than j i.e (i-j) nodes 17 | dp[i] = dp[i] + dp[j-1] * dp[i-j]; 18 | } 19 | } 20 | 21 | return dp[n]; 22 | } 23 | } -------------------------------------------------------------------------------- /96-unique-binary-search-trees/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /968-binary-tree-cameras/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /969-pancake-sorting/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /973-k-closest-points-to-origin/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /974-subarray-sums-divisible-by-k/974-subarray-sums-divisible-by-k.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int subarraysDivByK(int[] nums, int k) { 3 | // Stores remainder of prefix sum with k in array 4 | HashMap map = new HashMap<>(); 5 | 6 | int sum = 0; 7 | int count = 0; 8 | map.put(0,1); // remainder of sum 0 with k is 0 9 | for (int num: nums) { 10 | sum = sum+num; 11 | int rem = sum%k<0 ? sum%k+k : sum%k; 12 | if (map.containsKey(rem)) { 13 | count += map.get(rem); 14 | } 15 | map.put(rem,map.getOrDefault(rem,0)+1); 16 | } 17 | 18 | return count; 19 | } 20 | } -------------------------------------------------------------------------------- /974-subarray-sums-divisible-by-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /98-validate-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /980-unique-paths-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /983-minimum-cost-for-tickets/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /986-interval-list-intersections/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /987-vertical-order-traversal-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /99-recover-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /994-rotting-oranges/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /997-find-the-town-judge/997-find-the-town-judge.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findJudge(int n, int[][] trust) { 3 | int indegree[] = new int[n+1]; // No of people who trust you 4 | int outdegree[] = new int[n+1]; // No of people you trust 5 | 6 | for (int[] t: trust) { 7 | indegree[t[1]]++; 8 | outdegree[t[0]]++; 9 | } 10 | 11 | for (int i=1;i<=n;i++) { 12 | if (indegree[i]==n-1 && outdegree[i]==0) 13 | return i; 14 | } 15 | 16 | return -1; 17 | } 18 | } -------------------------------------------------------------------------------- /997-find-the-town-judge/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /Maximum difference of zeros and ones in binary string - GFG/solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int maxSubstring(String S) { 3 | // Understand 0 as 1 4 | // and 1 as -1 5 | // Find maximum subarray sum in array 6 | // Kadane algorithm 7 | 8 | int maxDiff = -1; 9 | 10 | int runningSum = 0; 11 | for (int i=0;i0) 19 | runningSum += val; 20 | else 21 | runningSum = val; 22 | 23 | maxDiff = Math.max(runningSum,maxDiff); 24 | } 25 | 26 | return maxDiff; 27 | } 28 | } 29 | --------------------------------------------------------------------------------