├── 0001-two-sum ├── 0001-two-sum.java └── README.md ├── 0004-median-of-two-sorted-arrays ├── 0004-median-of-two-sorted-arrays.java └── README.md ├── 0005-longest-palindromic-substring ├── 0005-longest-palindromic-substring.cpp ├── 0005-longest-palindromic-substring.java ├── NOTES.md └── README.md ├── 0010-regular-expression-matching ├── 0010-regular-expression-matching.cpp ├── 0010-regular-expression-matching.java └── README.md ├── 0033-search-in-rotated-sorted-array ├── 0033-search-in-rotated-sorted-array.cpp └── README.md ├── 0038-count-and-say ├── 0038-count-and-say.cpp └── README.md ├── 0040-combination-sum-ii ├── 0040-combination-sum-ii.cpp └── README.md ├── 0042-trapping-rain-water ├── 0042-trapping-rain-water.cpp └── README.md ├── 0045-jump-game-ii ├── 0045-jump-game-ii.cpp ├── 0045-jump-game-ii.java └── README.md ├── 0049-group-anagrams ├── 0049-group-anagrams.cpp └── README.md ├── 0053-maximum-subarray ├── 0053-maximum-subarray.cpp ├── 0053-maximum-subarray.java └── README.md ├── 0055-jump-game ├── 0055-jump-game.cpp ├── 0055-jump-game.java └── README.md ├── 0062-unique-paths ├── 0062-unique-paths.cpp ├── 0062-unique-paths.java └── README.md ├── 0063-unique-paths-ii ├── 0063-unique-paths-ii.cpp ├── 0063-unique-paths-ii.java └── README.md ├── 0073-set-matrix-zeroes ├── 0073-set-matrix-zeroes.cpp └── README.md ├── 0075-sort-colors ├── 0075-sort-colors.cpp └── README.md ├── 0091-decode-ways ├── 0091-decode-ways.cpp └── README.md ├── 0128-longest-consecutive-sequence ├── 0128-longest-consecutive-sequence.cpp └── README.md ├── 0133-clone-graph ├── 0133-clone-graph.cpp └── README.md ├── 0135-candy ├── 0135-candy.cpp └── README.md ├── 0139-word-break ├── 0139-word-break.cpp └── README.md ├── 0145-binary-tree-postorder-traversal ├── 0145-binary-tree-postorder-traversal.cpp └── README.md ├── 0152-maximum-product-subarray ├── 0152-maximum-product-subarray.cpp └── README.md ├── 0153-find-minimum-in-rotated-sorted-array └── README.md ├── 0179-largest-number ├── 0179-largest-number.cpp └── README.md ├── 0198-house-robber ├── 0198-house-robber.cpp └── README.md ├── 0213-house-robber-ii ├── 0213-house-robber-ii.cpp └── README.md ├── 0214-shortest-palindrome ├── 0214-shortest-palindrome.cpp ├── 0214-shortest-palindrome.java └── README.md ├── 0217-contains-duplicate ├── 0217-contains-duplicate.cpp └── README.md ├── 0236-lowest-common-ancestor-of-a-binary-tree ├── 0236-lowest-common-ancestor-of-a-binary-tree.cpp └── README.md ├── 0238-product-of-array-except-self ├── 0238-product-of-array-except-self.cpp └── README.md ├── 0241-different-ways-to-add-parentheses ├── 0241-different-ways-to-add-parentheses.cpp └── README.md ├── 0264-ugly-number-ii ├── 0264-ugly-number-ii.cpp └── README.md ├── 0268-missing-number ├── 0268-missing-number.cpp └── README.md ├── 0273-integer-to-english-words ├── 0273-integer-to-english-words.cpp ├── 0273-integer-to-english-words.java └── README.md ├── 0300-longest-increasing-subsequence ├── 0300-longest-increasing-subsequence.cpp └── README.md ├── 0307-range-sum-query-mutable ├── 0307-range-sum-query-mutable.cpp └── README.md ├── 0322-coin-change ├── 0322-coin-change.cpp └── README.md ├── 0338-counting-bits ├── 0338-counting-bits.cpp └── README.md ├── 0350-intersection-of-two-arrays-ii ├── 0350-intersection-of-two-arrays-ii.cpp └── README.md ├── 0368-largest-divisible-subset ├── 0368-largest-divisible-subset.cpp └── README.md ├── 0371-sum-of-two-integers ├── 0371-sum-of-two-integers.cpp └── README.md ├── 0377-combination-sum-iv ├── 0377-combination-sum-iv.cpp └── README.md ├── 0386-lexicographical-numbers ├── 0386-lexicographical-numbers.cpp └── README.md ├── 0407-trapping-rain-water-ii ├── 0407-trapping-rain-water-ii.cpp └── README.md ├── 0416-partition-equal-subset-sum ├── 0416-partition-equal-subset-sum.cpp └── README.md ├── 0432-all-oone-data-structure ├── 0432-all-oone-data-structure.java └── README.md ├── 0440-k-th-smallest-in-lexicographical-order ├── 0440-k-th-smallest-in-lexicographical-order.cpp ├── 0440-k-th-smallest-in-lexicographical-order.java └── README.md ├── 0453-minimum-moves-to-equal-array-elements ├── 0453-minimum-moves-to-equal-array-elements.cpp └── README.md ├── 0462-minimum-moves-to-equal-array-elements-ii ├── 0462-minimum-moves-to-equal-array-elements-ii.cpp └── README.md ├── 0476-number-complement └── README.md ├── 0494-target-sum ├── 0494-target-sum.cpp └── README.md ├── 0515-find-largest-value-in-each-tree-row ├── 0515-find-largest-value-in-each-tree-row.cpp └── README.md ├── 0516-longest-palindromic-subsequence ├── 0516-longest-palindromic-subsequence.java └── README.md ├── 0539-minimum-time-difference ├── 0539-minimum-time-difference.cpp └── README.md ├── 0564-find-the-closest-palindrome ├── 0564-find-the-closest-palindrome.cpp └── README.md ├── 0567-permutation-in-string ├── 0567-permutation-in-string.cpp └── README.md ├── 0576-out-of-boundary-paths ├── 0576-out-of-boundary-paths.cpp ├── NOTES.md └── README.md ├── 0592-fraction-addition-and-subtraction ├── 0592-fraction-addition-and-subtraction.cpp └── README.md ├── 0600-non-negative-integers-without-consecutive-ones ├── 0600-non-negative-integers-without-consecutive-ones.cpp └── README.md ├── 0624-maximum-distance-in-arrays ├── 0624-maximum-distance-in-arrays.cpp └── README.md ├── 0632-smallest-range-covering-elements-from-k-lists ├── 0632-smallest-range-covering-elements-from-k-lists.cpp └── README.md ├── 0647-palindromic-substrings ├── 0647-palindromic-substrings.java └── README.md ├── 0650-2-keys-keyboard ├── 0650-2-keys-keyboard.cpp └── README.md ├── 0664-strange-printer ├── 0664-strange-printer.cpp └── README.md ├── 0670-maximum-swap ├── 0670-maximum-swap.cpp └── README.md ├── 0684-redundant-connection ├── 0684-redundant-connection.cpp └── README.md ├── 0689-maximum-sum-of-3-non-overlapping-subarrays ├── 0689-maximum-sum-of-3-non-overlapping-subarrays.cpp └── README.md ├── 0719-find-k-th-smallest-pair-distance ├── 0719-find-k-th-smallest-pair-distance.cpp └── README.md ├── 0725-split-linked-list-in-parts ├── 0725-split-linked-list-in-parts.cpp └── README.md ├── 0726-number-of-atoms ├── 0726-number-of-atoms.cpp └── README.md ├── 0729-my-calendar-i ├── 0729-my-calendar-i.cpp └── README.md ├── 0731-my-calendar-ii └── README.md ├── 0768-partition-labels ├── 0768-partition-labels.cpp └── README.md ├── 0776-n-ary-tree-postorder-traversal ├── 0776-n-ary-tree-postorder-traversal.cpp └── README.md ├── 0780-max-chunks-to-make-sorted ├── 0780-max-chunks-to-make-sorted.cpp └── README.md ├── 0787-sliding-puzzle ├── 0787-sliding-puzzle.cpp └── README.md ├── 0789-kth-largest-element-in-a-stream ├── 0789-kth-largest-element-in-a-stream.cpp └── README.md ├── 0797-rabbits-in-forest ├── 0797-rabbits-in-forest.cpp └── README.md ├── 0806-domino-and-tromino-tiling ├── 0806-domino-and-tromino-tiling.cpp └── README.md ├── 0812-rotate-string ├── 0812-rotate-string.cpp └── README.md ├── 0820-find-eventual-safe-states ├── 0820-find-eventual-safe-states.cpp └── README.md ├── 0854-making-a-large-island ├── 0854-making-a-large-island.cpp └── README.md ├── 0859-design-circular-deque ├── 0859-design-circular-deque.cpp └── README.md ├── 0868-push-dominoes ├── 0868-push-dominoes.cpp └── README.md ├── 0870-magic-squares-in-grid ├── 0870-magic-squares-in-grid.cpp └── README.md ├── 0890-lemonade-change ├── 0890-lemonade-change.cpp └── README.md ├── 0892-shortest-subarray-with-sum-at-least-k ├── 0892-shortest-subarray-with-sum-at-least-k.cpp └── README.md ├── 0905-length-of-longest-fibonacci-subsequence ├── 0905-length-of-longest-fibonacci-subsequence.cpp └── README.md ├── 0906-walking-robot-simulation ├── 0906-walking-robot-simulation.cpp └── README.md ├── 0920-uncommon-words-from-two-sentences ├── 0920-uncommon-words-from-two-sentences.java └── README.md ├── 0921-spiral-matrix-iii ├── 0921-spiral-matrix-iii.cpp └── README.md ├── 0925-construct-binary-tree-from-preorder-and-postorder-traversal ├── 0925-construct-binary-tree-from-preorder-and-postorder-traversal.cpp └── README.md ├── 0945-snakes-and-ladders ├── 0945-snakes-and-ladders.cpp └── README.md ├── 0948-sort-an-array ├── 0948-sort-an-array.cpp └── README.md ├── 0952-word-subsets ├── 0952-word-subsets.cpp └── README.md ├── 0957-minimum-add-to-make-parentheses-valid ├── 0957-minimum-add-to-make-parentheses-valid.cpp └── README.md ├── 0984-most-stones-removed-with-same-row-or-column ├── 0984-most-stones-removed-with-same-row-or-column.cpp └── README.md ├── 0988-flip-equivalent-binary-trees ├── 0988-flip-equivalent-binary-trees.cpp └── README.md ├── 0999-regions-cut-by-slashes ├── 0999-regions-cut-by-slashes.cpp └── README.md ├── 1002-maximum-width-ramp ├── 1002-maximum-width-ramp.cpp └── README.md ├── 1025-minimum-cost-for-tickets ├── 1025-minimum-cost-for-tickets.cpp └── README.md ├── 1049-minimum-domino-rotations-for-equal-row ├── 1049-minimum-domino-rotations-for-equal-row.cpp └── README.md ├── 1057-numbers-with-repeated-digits ├── 1057-numbers-with-repeated-digits.cpp └── README.md ├── 1058-lexicographically-smallest-equivalent-string ├── 1058-lexicographically-smallest-equivalent-string.cpp └── README.md ├── 1063-best-sightseeing-pair ├── 1063-best-sightseeing-pair.cpp └── README.md ├── 1093-recover-a-tree-from-preorder-traversal ├── 1093-recover-a-tree-from-preorder-traversal.cpp └── README.md ├── 1143-longest-common-subsequence ├── 1143-longest-common-subsequence.cpp └── NOTES.md ├── 1147-flip-columns-for-maximum-number-of-equal-rows ├── 1147-flip-columns-for-maximum-number-of-equal-rows.cpp └── README.md ├── 1160-letter-tile-possibilities ├── 1160-letter-tile-possibilities.cpp └── README.md ├── 1170-shortest-common-supersequence ├── 1170-shortest-common-supersequence.cpp └── README.md ├── 1197-parsing-a-boolean-expression ├── 1197-parsing-a-boolean-expression.cpp └── README.md ├── 1207-delete-nodes-and-return-forest ├── 1207-delete-nodes-and-return-forest.cpp └── README.md ├── 1218-lowest-common-ancestor-of-deepest-leaves ├── 1218-lowest-common-ancestor-of-deepest-leaves.cpp └── README.md ├── 1227-number-of-equivalent-domino-pairs ├── 1227-number-of-equivalent-domino-pairs.cpp └── README.md ├── 1240-stone-game-ii ├── 1240-stone-game-ii.cpp └── README.md ├── 1250-longest-common-subsequence ├── 1250-longest-common-subsequence.cpp └── README.md ├── 1256-rank-transform-of-an-array ├── 1256-rank-transform-of-an-array.cpp └── README.md ├── 1285-balance-a-binary-search-tree ├── 1285-balance-a-binary-search-tree.cpp ├── 1285-balance-a-binary-search-tree.java └── README.md ├── 1293-three-consecutive-odds ├── 1293-three-consecutive-odds.cpp └── README.md ├── 1298-reverse-substrings-between-each-pair-of-parentheses ├── 1298-reverse-substrings-between-each-pair-of-parentheses.cpp └── README.md ├── 1302-delete-characters-to-make-fancy-string ├── 1302-delete-characters-to-make-fancy-string.cpp └── README.md ├── 1304-longest-happy-string ├── 1304-longest-happy-string.cpp └── README.md ├── 1325-path-with-maximum-probability ├── 1325-path-with-maximum-probability.cpp └── README.md ├── 1333-sort-the-jumbled-numbers ├── 1333-sort-the-jumbled-numbers.cpp └── README.md ├── 1334-sum-of-numbers-with-units-digit-k ├── 1334-sum-of-numbers-with-units-digit-k.cpp └── README.md ├── 1335-maximum-candies-allocated-to-k-children ├── 1335-maximum-candies-allocated-to-k-children.cpp └── README.md ├── 1350-remove-sub-folders-from-the-filesystem ├── 1350-remove-sub-folders-from-the-filesystem.cpp └── README.md ├── 1364-tuple-with-same-product ├── 1364-tuple-with-same-product.cpp └── README.md ├── 1387-find-elements-in-a-contaminated-binary-tree ├── 1387-find-elements-in-a-contaminated-binary-tree.cpp └── README.md ├── 1396-count-servers-that-communicate ├── 1396-count-servers-that-communicate.cpp └── README.md ├── 1402-count-square-submatrices-with-all-ones ├── 1402-count-square-submatrices-with-all-ones.cpp └── README.md ├── 1407-group-the-people-given-the-group-size-they-belong-to ├── 1407-group-the-people-given-the-group-size-they-belong-to.cpp └── README.md ├── 1421-find-numbers-with-even-number-of-digits ├── 1421-find-numbers-with-even-number-of-digits.cpp └── README.md ├── 1424-maximum-candies-you-can-get-from-boxes ├── 1424-maximum-candies-you-can-get-from-boxes.cpp └── README.md ├── 1431-all-ancestors-of-a-node-in-a-directed-acyclic-graph ├── 1431-all-ancestors-of-a-node-in-a-directed-acyclic-graph.cpp └── README.md ├── 1435-xor-queries-of-a-subarray ├── 1435-xor-queries-of-a-subarray.cpp └── README.md ├── 1456-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance ├── 1456-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance.cpp └── README.md ├── 1460-number-of-substrings-containing-all-three-characters ├── 1460-number-of-substrings-containing-all-three-characters.cpp └── README.md ├── 1468-check-if-n-and-its-double-exist ├── 1468-check-if-n-and-its-double-exist.cpp └── README.md ├── 1473-find-the-longest-substring-containing-vowels-in-even-counts ├── 1473-find-the-longest-substring-containing-vowels-in-even-counts.cpp └── README.md ├── 1477-product-of-the-last-k-numbers ├── 1477-product-of-the-last-k-numbers.cpp └── README.md ├── 1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid ├── 1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid.cpp └── README.md ├── 1496-lucky-numbers-in-a-matrix ├── 1496-lucky-numbers-in-a-matrix.cpp └── README.md ├── 1497-design-a-stack-with-increment-operation ├── 1497-design-a-stack-with-increment-operation.cpp └── README.md ├── 1500-count-largest-group ├── 1500-count-largest-group.cpp └── README.md ├── 1502-construct-k-palindrome-strings ├── 1502-construct-k-palindrome-strings.cpp └── README.md ├── 1508-longest-happy-prefix ├── 1508-longest-happy-prefix.cpp └── README.md ├── 1511-count-number-of-teams ├── 1511-count-number-of-teams.cpp └── README.md ├── 1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n ├── 1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n.cpp └── README.md ├── 1524-string-matching-in-an-array ├── 1524-string-matching-in-an-array.cpp └── README.md ├── 1537-maximum-score-after-splitting-a-string ├── 1537-maximum-score-after-splitting-a-string.cpp └── README.md ├── 1556-make-two-arrays-equal-by-reversing-subarrays ├── 1556-make-two-arrays-equal-by-reversing-subarrays.cpp └── README.md ├── 1558-course-schedule-iv ├── 1558-course-schedule-iv.cpp └── README.md ├── 1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence ├── 1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.cpp └── README.md ├── 1570-final-prices-with-a-special-discount-in-a-shop ├── 1570-final-prices-with-a-special-discount-in-a-shop.cpp └── README.md ├── 1615-range-sum-of-sorted-subarray-sums ├── 1615-range-sum-of-sorted-subarray-sums.cpp └── README.md ├── 1616-minimum-difference-between-largest-and-smallest-value-in-three-moves ├── 1616-minimum-difference-between-largest-and-smallest-value-in-three-moves.cpp └── README.md ├── 1620-check-if-array-pairs-are-divisible-by-k ├── 1620-check-if-array-pairs-are-divisible-by-k.cpp └── README.md ├── 1631-number-of-sub-arrays-with-odd-sum ├── 1631-number-of-sub-arrays-with-odd-sum.cpp └── README.md ├── 1642-water-bottles ├── 1642-water-bottles.cpp └── README.md ├── 1656-count-good-triplets ├── 1656-count-good-triplets.cpp └── README.md ├── 1667-find-kth-bit-in-nth-binary-string ├── 1667-find-kth-bit-in-nth-binary-string.cpp └── README.md ├── 1679-shortest-subarray-to-be-removed-to-make-array-sorted ├── 1679-shortest-subarray-to-be-removed-to-make-array-sorted.cpp └── README.md ├── 1691-minimum-number-of-days-to-disconnect-island ├── 1691-minimum-number-of-days-to-disconnect-island.cpp └── README.md ├── 1694-make-sum-divisible-by-p ├── 1694-make-sum-divisible-by-p.cpp └── README.md ├── 1701-remove-max-number-of-edges-to-keep-graph-fully-traversable ├── 1701-remove-max-number-of-edges-to-keep-graph-fully-traversable.cpp └── README.md ├── 1711-find-valid-matrix-given-row-and-column-sums ├── 1711-find-valid-matrix-given-row-and-column-sums.cpp └── README.md ├── 1715-split-a-string-into-the-max-number-of-unique-substrings ├── 1715-split-a-string-into-the-max-number-of-unique-substrings.cpp └── README.md ├── 1720-crawler-log-folder ├── 1720-crawler-log-folder.cpp └── README.md ├── 1741-sort-array-by-increasing-frequency ├── 1741-sort-array-by-increasing-frequency.cpp └── README.md ├── 1744-number-of-ways-to-form-a-target-string-given-a-dictionary ├── 1744-number-of-ways-to-form-a-target-string-given-a-dictionary.cpp └── README.md ├── 1755-defuse-the-bomb ├── 1755-defuse-the-bomb.cpp └── README.md ├── 1766-minimum-number-of-removals-to-make-mountain-array ├── 1766-minimum-number-of-removals-to-make-mountain-array.cpp └── README.md ├── 1786-count-the-number-of-consistent-strings ├── 1786-count-the-number-of-consistent-strings.cpp └── README.md ├── 1803-average-waiting-time ├── 1803-average-waiting-time.cpp └── README.md ├── 1818-maximum-score-from-removing-substrings ├── 1818-maximum-score-from-removing-substrings.cpp └── README.md ├── 1819-construct-the-lexicographically-largest-valid-sequence ├── 1819-construct-the-lexicographically-largest-valid-sequence.cpp └── README.md ├── 1849-maximum-absolute-sum-of-any-subarray ├── 1849-maximum-absolute-sum-of-any-subarray.cpp └── README.md ├── 1876-map-of-highest-peak ├── 1876-map-of-highest-peak.cpp └── README.md ├── 1878-check-if-array-is-sorted-and-rotated ├── 1878-check-if-array-is-sorted-and-rotated.cpp └── README.md ├── 1886-minimum-limit-of-balls-in-a-bag ├── 1886-minimum-limit-of-balls-in-a-bag.cpp └── README.md ├── 1889-check-if-number-is-a-sum-of-powers-of-three ├── 1889-check-if-number-is-a-sum-of-powers-of-three.cpp └── README.md ├── 1895-minimum-number-of-operations-to-move-all-balls-to-each-box ├── 1895-minimum-number-of-operations-to-move-all-balls-to-each-box.cpp └── README.md ├── 1915-check-if-one-string-swap-can-make-strings-equal ├── 1915-check-if-one-string-swap-can-make-strings-equal.cpp └── README.md ├── 1916-find-center-of-star-graph ├── 1916-find-center-of-star-graph.cpp └── README.md ├── 1917-maximum-average-pass-ratio ├── 1917-maximum-average-pass-ratio.cpp └── README.md ├── 1923-sentence-similarity-iii ├── 1923-sentence-similarity-iii.cpp └── README.md ├── 1927-maximum-ascending-subarray-sum ├── 1927-maximum-ascending-subarray-sum.cpp └── README.md ├── 1940-maximum-xor-for-each-query ├── 1940-maximum-xor-for-each-query.cpp └── README.md ├── 1951-find-the-winner-of-the-circular-game ├── 1951-find-the-winner-of-the-circular-game.cpp └── README.md ├── 1972-rotating-the-box ├── 1972-rotating-the-box.cpp └── README.md ├── 1986-largest-color-value-in-a-directed-graph ├── 1986-largest-color-value-in-a-directed-graph.cpp └── README.md ├── 1993-sum-of-all-subset-xor-totals ├── 1993-sum-of-all-subset-xor-totals.cpp └── README.md ├── 2006-find-the-student-that-will-replace-the-chalk ├── 2006-find-the-student-that-will-replace-the-chalk.cpp └── README.md ├── 2021-remove-all-occurrences-of-a-substring ├── 2021-remove-all-occurrences-of-a-substring.cpp └── README.md ├── 2035-count-sub-islands ├── 2035-count-sub-islands.cpp └── README.md ├── 2048-build-array-from-permutation ├── 2048-build-array-from-permutation.cpp └── README.md ├── 2050-count-good-numbers ├── 2050-count-good-numbers.cpp └── README.md ├── 2054-the-number-of-the-smallest-unoccupied-chair ├── 2054-the-number-of-the-smallest-unoccupied-chair.cpp └── README.md ├── 2059-unique-length-3-palindromic-subsequences ├── 2059-unique-length-3-palindromic-subsequences.cpp └── README.md ├── 2061-painting-a-grid-with-three-different-colors ├── 2061-painting-a-grid-with-three-different-colors.cpp └── README.md ├── 2067-maximum-number-of-points-with-cost ├── 2067-maximum-number-of-points-with-cost.cpp └── README.md ├── 2076-sum-of-digits-of-string-after-convert ├── 2076-sum-of-digits-of-string-after-convert.cpp └── README.md ├── 2089-maximum-matrix-sum ├── 2089-maximum-matrix-sum.cpp └── README.md ├── 2090-number-of-ways-to-arrive-at-destination ├── 2090-number-of-ways-to-arrive-at-destination.cpp └── README.md ├── 2095-minimum-number-of-swaps-to-make-the-string-balanced ├── 2095-minimum-number-of-swaps-to-make-the-string-balanced.cpp ├── 2095-minimum-number-of-swaps-to-make-the-string-balanced.rs ├── 2095-minimum-number-of-swaps-to-make-the-string-balanced.swift └── README.md ├── 2107-find-unique-binary-string ├── 2107-find-unique-binary-string.cpp └── README.md ├── 2132-convert-1d-array-into-2d-array ├── 2132-convert-1d-array-into-2d-array.cpp └── README.md ├── 2145-grid-game ├── 2145-grid-game.cpp └── README.md ├── 2155-find-missing-observations ├── 2155-find-missing-observations.cpp └── README.md ├── 2160-minimum-operations-to-make-a-uni-value-grid ├── 2160-minimum-operations-to-make-a-uni-value-grid.cpp └── README.md ├── 2163-kth-distinct-string-in-an-array ├── 2163-kth-distinct-string-in-an-array.cpp └── README.md ├── 2164-two-best-non-overlapping-events ├── 2164-two-best-non-overlapping-events.cpp └── README.md ├── 2170-count-number-of-maximum-bitwise-or-subsets ├── 2170-count-number-of-maximum-bitwise-or-subsets.cpp └── README.md ├── 2171-second-minimum-time-to-reach-destination ├── 2171-second-minimum-time-to-reach-destination.cpp └── README.md ├── 2179-most-beautiful-item-for-each-query ├── 2179-most-beautiful-item-for-each-query.cpp └── README.md ├── 2180-maximum-number-of-tasks-you-can-assign ├── 2180-maximum-number-of-tasks-you-can-assign.cpp └── README.md ├── 2182-find-the-minimum-and-maximum-number-of-nodes-between-critical-points ├── 2182-find-the-minimum-and-maximum-number-of-nodes-between-critical-points.cpp └── README.md ├── 2188-minimized-maximum-of-products-distributed-to-any-store ├── 2188-minimized-maximum-of-products-distributed-to-any-store.cpp └── README.md ├── 2201-valid-arrangement-of-pairs ├── 2201-valid-arrangement-of-pairs.cpp └── README.md ├── 2215-finding-3-digit-even-numbers ├── 2215-finding-3-digit-even-numbers.cpp └── README.md ├── 2217-step-by-step-directions-from-a-binary-tree-node-to-another ├── 2217-step-by-step-directions-from-a-binary-tree-node-to-another.cpp ├── 2217-step-by-step-directions-from-a-binary-tree-node-to-another.java └── README.md ├── 2220-find-all-possible-recipes-from-given-supplies ├── 2220-find-all-possible-recipes-from-given-supplies.cpp └── README.md ├── 2221-check-if-a-parentheses-string-can-be-valid ├── 2221-check-if-a-parentheses-string-can-be-valid.cpp └── README.md ├── 2232-adding-spaces-to-a-string ├── 2232-adding-spaces-to-a-string.cpp └── README.md ├── 2237-longest-palindrome-by-concatenating-two-letter-words ├── 2237-longest-palindrome-by-concatenating-two-letter-words.cpp └── README.md ├── 2246-maximum-employees-to-be-invited-to-a-meeting ├── 2246-maximum-employees-to-be-invited-to-a-meeting.cpp └── README.md ├── 2249-count-the-hidden-sequences ├── 2249-count-the-hidden-sequences.cpp └── README.md ├── 2255-minimum-swaps-to-group-all-1s-together-ii ├── 2255-minimum-swaps-to-group-all-1s-together-ii.cpp └── README.md ├── 2262-solving-questions-with-brainpower ├── 2262-solving-questions-with-brainpower.cpp └── README.md ├── 2265-partition-array-according-to-given-pivot ├── 2265-partition-array-according-to-given-pivot.cpp └── README.md ├── 2277-count-equal-and-divisible-pairs-in-an-array ├── 2277-count-equal-and-divisible-pairs-in-an-array.cpp └── README.md ├── 2280-count-good-triplets-in-an-array ├── 2280-count-good-triplets-in-an-array.cpp └── README.md ├── 2292-counting-words-with-a-given-prefix ├── 2292-counting-words-with-a-given-prefix.cpp └── README.md ├── 2299-merge-nodes-in-between-zeros ├── 2299-merge-nodes-in-between-zeros.cpp ├── 2299-merge-nodes-in-between-zeros.java └── README.md ├── 2300-construct-string-with-repeat-limit ├── 2300-construct-string-with-repeat-limit.cpp └── README.md ├── 2306-create-binary-tree-from-descriptions ├── 2306-create-binary-tree-from-descriptions.cpp └── README.md ├── 2308-divide-array-into-equal-pairs ├── 2308-divide-array-into-equal-pairs.cpp └── README.md ├── 2323-minimum-bit-flips-to-convert-number ├── 2323-minimum-bit-flips-to-convert-number.cpp └── README.md ├── 2343-count-unguarded-cells-in-the-grid ├── 2343-count-unguarded-cells-in-the-grid.cpp └── README.md ├── 2356-largest-combination-with-bitwise-and-greater-than-zero ├── 2356-largest-combination-with-bitwise-and-greater-than-zero.cpp └── README.md ├── 2358-number-of-ways-to-split-array ├── 2358-number-of-ways-to-split-array.cpp └── README.md ├── 2375-minimum-obstacle-removal-to-reach-corner ├── 2375-minimum-obstacle-removal-to-reach-corner.cpp └── README.md ├── 2379-maximum-total-importance-of-roads ├── 2379-maximum-total-importance-of-roads.cpp └── README.md ├── 2394-count-subarrays-with-score-less-than-k ├── 2394-count-subarrays-with-score-less-than-k.cpp └── README.md ├── 2411-spiral-matrix-iv ├── 2411-spiral-matrix-iv.cpp └── README.md ├── 2414-move-pieces-to-obtain-a-string ├── 2414-move-pieces-to-obtain-a-string.cpp └── README.md ├── 2415-count-the-number-of-ideal-arrays ├── 2415-count-the-number-of-ideal-arrays.cpp └── README.md ├── 2434-design-a-number-container-system ├── 2434-design-a-number-container-system.cpp └── README.md ├── 2438-find-closest-node-to-given-two-nodes ├── 2438-find-closest-node-to-given-two-nodes.cpp └── README.md ├── 2448-count-number-of-bad-pairs ├── 2448-count-number-of-bad-pairs.cpp └── README.md ├── 2456-construct-smallest-number-from-di-string ├── 2456-construct-smallest-number-from-di-string.cpp └── README.md ├── 2463-minimum-recolors-to-get-k-consecutive-black-blocks ├── 2463-minimum-recolors-to-get-k-consecutive-black-blocks.cpp └── README.md ├── 2465-shifting-letters-ii ├── 2465-shifting-letters-ii.cpp └── README.md ├── 2472-build-a-matrix-with-conditions ├── 2472-build-a-matrix-with-conditions.cpp └── README.md ├── 2473-max-sum-of-a-pair-with-equal-sum-of-digits ├── 2473-max-sum-of-a-pair-with-equal-sum-of-digits.cpp └── README.md ├── 2478-longest-nice-subarray ├── 2478-longest-nice-subarray.cpp └── README.md ├── 2488-divide-intervals-into-minimum-number-of-groups ├── 2488-divide-intervals-into-minimum-number-of-groups.cpp └── README.md ├── 2493-reverse-odd-levels-of-binary-tree ├── 2493-reverse-odd-levels-of-binary-tree.cpp └── README.md ├── 2494-sum-of-prefix-scores-of-strings ├── 2494-sum-of-prefix-scores-of-strings.cpp └── README.md ├── 2502-sort-the-people ├── 2502-sort-the-people.cpp └── README.md ├── 2503-longest-subarray-with-maximum-bitwise-and ├── 2503-longest-subarray-with-maximum-bitwise-and.cpp └── README.md ├── 2509-minimize-xor ├── 2509-minimize-xor.cpp └── README.md ├── 2520-using-a-robot-to-print-the-lexicographically-smallest-string ├── 2520-using-a-robot-to-print-the-lexicographically-smallest-string.cpp └── README.md ├── 2527-count-subarrays-with-fixed-bounds ├── 2527-count-subarrays-with-fixed-bounds.cpp └── README.md ├── 2533-bitwise-xor-of-all-pairings ├── 2533-bitwise-xor-of-all-pairings.cpp └── README.md ├── 2538-minimum-cost-to-make-array-equal ├── 2538-minimum-cost-to-make-array-equal.cpp └── README.md ├── 2545-height-of-binary-tree-after-subtree-removal-queries ├── 2545-height-of-binary-tree-after-subtree-removal-queries.cpp └── README.md ├── 2551-apply-operations-to-an-array ├── 2551-apply-operations-to-an-array.cpp └── README.md ├── 2552-maximum-sum-of-distinct-subarrays-with-length-k ├── 2552-maximum-sum-of-distinct-subarrays-with-length-k.cpp └── README.md ├── 2554-minimum-total-distance-traveled ├── 2554-minimum-total-distance-traveled.cpp └── README.md ├── 2558-minimum-number-of-operations-to-sort-a-binary-tree-by-level ├── 2558-minimum-number-of-operations-to-sort-a-binary-tree-by-level.cpp └── README.md ├── 2562-count-ways-to-build-good-strings ├── 2562-count-ways-to-build-good-strings.cpp └── README.md ├── 2564-most-profitable-path-in-a-tree ├── 2564-most-profitable-path-in-a-tree.cpp └── README.md ├── 2580-circular-sentence ├── 2580-circular-sentence.cpp └── README.md ├── 2581-divide-players-into-teams-of-equal-skill ├── 2581-divide-players-into-teams-of-equal-skill.cpp └── README.md ├── 2583-divide-nodes-into-the-maximum-number-of-groups ├── 2583-divide-nodes-into-the-maximum-number-of-groups.cpp └── README.md ├── 2586-longest-square-streak-in-an-array ├── 2586-longest-square-streak-in-an-array.cpp └── README.md ├── 2588-maximum-number-of-points-from-grid-queries ├── 2588-maximum-number-of-points-from-grid-queries.cpp └── README.md ├── 2599-take-k-of-each-character-from-left-and-right ├── 2599-take-k-of-each-character-from-left-and-right.cpp └── README.md ├── 2610-closest-prime-numbers-in-range ├── 2610-closest-prime-numbers-in-range.cpp └── README.md ├── 2614-maximum-count-of-positive-integer-and-negative-integer ├── 2614-maximum-count-of-positive-integer-and-negative-integer.cpp └── README.md ├── 2616-maximal-score-after-applying-k-operations ├── 2616-maximal-score-after-applying-k-operations.cpp └── README.md ├── 2626-count-the-number-of-good-subarrays ├── 2626-count-the-number-of-good-subarrays.cpp └── README.md ├── 2640-maximum-number-of-integers-to-choose-from-a-range-i ├── 2640-maximum-number-of-integers-to-choose-from-a-range-i.cpp └── README.md ├── 2645-pass-the-pillow ├── 2645-pass-the-pillow.cpp └── README.md ├── 2646-kth-largest-sum-in-a-binary-tree ├── 2646-kth-largest-sum-in-a-binary-tree.cpp └── README.md ├── 2649-count-total-number-of-colored-cells ├── 2649-count-total-number-of-colored-cells.cpp └── README.md ├── 2665-minimum-time-to-repair-cars ├── 2665-minimum-time-to-repair-cars.cpp └── README.md ├── 2677-cousins-in-binary-tree-ii ├── 2677-cousins-in-binary-tree-ii.cpp └── README.md ├── 2681-put-marbles-in-bags ├── 2681-put-marbles-in-bags.cpp └── README.md ├── 2685-first-completely-painted-row-or-column ├── 2685-first-completely-painted-row-or-column.cpp └── README.md ├── 2690-house-robber-iv ├── 2690-house-robber-iv.cpp └── README.md ├── 2691-count-vowel-strings-in-ranges ├── 2691-count-vowel-strings-in-ranges.cpp └── README.md ├── 2692-take-gifts-from-the-richest-pile ├── 2692-take-gifts-from-the-richest-pile.cpp └── README.md ├── 2695-find-score-of-an-array-after-marking-all-elements ├── 2695-find-score-of-an-array-after-marking-all-elements.cpp └── README.md ├── 2699-count-the-number-of-fair-pairs ├── 2699-count-the-number-of-fair-pairs.cpp └── README.md ├── 2707-merge-two-2d-arrays-by-summing-values ├── 2707-merge-two-2d-arrays-by-summing-values.cpp └── README.md ├── 2711-minimum-time-to-visit-a-cell-in-a-grid ├── 2711-minimum-time-to-visit-a-cell-in-a-grid.cpp └── README.md ├── 2716-prime-subtraction-operation ├── 2716-prime-subtraction-operation.cpp └── README.md ├── 2718-minimum-operations-to-make-all-array-elements-equal ├── 2718-minimum-operations-to-make-all-array-elements-equal.cpp └── README.md ├── 2727-number-of-senior-citizens ├── 2727-number-of-senior-citizens.cpp └── README.md ├── 2755-extra-characters-in-a-string ├── 2755-extra-characters-in-a-string.cpp └── README.md ├── 2757-count-of-integers ├── 2757-count-of-integers.cpp └── README.md ├── 2764-maximum-number-of-fish-in-a-grid ├── 2764-maximum-number-of-fish-in-a-grid.cpp └── README.md ├── 2766-find-the-prefix-common-array-of-two-arrays ├── 2766-find-the-prefix-common-array-of-two-arrays.cpp └── README.md ├── 2792-neighboring-bitwise-xor ├── 2792-neighboring-bitwise-xor.cpp └── README.md ├── 2793-count-the-number-of-complete-components ├── 2793-count-the-number-of-complete-components.cpp └── README.md ├── 2794-maximum-number-of-moves-in-a-grid ├── 2794-maximum-number-of-moves-in-a-grid.cpp └── README.md ├── 2800-minimum-string-length-after-removing-substrings ├── 2800-minimum-string-length-after-removing-substrings.cpp ├── 2800-minimum-string-length-after-removing-substrings.rs ├── 2800-minimum-string-length-after-removing-substrings.swift └── README.md ├── 2802-find-the-punishment-number-of-an-integer ├── 2802-find-the-punishment-number-of-an-integer.cpp └── README.md ├── 2803-modify-graph-edge-weights ├── 2803-modify-graph-edge-weights.cpp └── README.md ├── 2846-robot-collisions ├── 2846-robot-collisions.cpp └── README.md ├── 2856-count-complete-subarrays-in-an-array ├── 2856-count-complete-subarrays-in-an-array.cpp └── README.md ├── 2868-continuous-subarrays ├── 2868-continuous-subarrays.cpp └── README.md ├── 2888-minimum-index-of-a-valid-split ├── 2888-minimum-index-of-a-valid-split.cpp └── README.md ├── 2891-maximum-beauty-of-an-array-after-applying-operation ├── 2891-maximum-beauty-of-an-array-after-applying-operation.cpp └── README.md ├── 2903-insert-greatest-common-divisors-in-linked-list ├── 2903-insert-greatest-common-divisors-in-linked-list.cpp └── README.md ├── 2915-count-of-interesting-subarrays ├── 2915-count-of-interesting-subarrays.cpp └── README.md ├── 2998-count-symmetric-integers ├── 2998-count-symmetric-integers.cpp └── README.md ├── 3001-apply-operations-to-maximize-score ├── 3001-apply-operations-to-maximize-score.cpp └── README.md ├── 3018-make-string-a-subsequence-using-cyclic-increments ├── 3018-make-string-a-subsequence-using-cyclic-increments.cpp └── README.md ├── 3058-maximum-number-of-k-divisible-components ├── 3058-maximum-number-of-k-divisible-components.cpp └── README.md ├── 3142-longest-unequal-adjacent-groups-subsequence-ii ├── 3142-longest-unequal-adjacent-groups-subsequence-ii.cpp └── README.md ├── 3143-longest-unequal-adjacent-groups-subsequence-i ├── 3143-longest-unequal-adjacent-groups-subsequence-i.cpp └── README.md ├── 3152-maximum-value-of-an-ordered-triplet-ii ├── 3152-maximum-value-of-an-ordered-triplet-ii.cpp └── README.md ├── 3154-maximum-value-of-an-ordered-triplet-i ├── 3154-maximum-value-of-an-ordered-triplet-i.cpp └── README.md ├── 3171-minimum-equal-sum-of-two-arrays-after-replacing-zeros ├── 3171-minimum-equal-sum-of-two-arrays-after-replacing-zeros.cpp └── README.md ├── 3172-divisible-and-non-divisible-sums-difference ├── 3172-divisible-and-non-divisible-sums-difference.cpp └── README.md ├── 3174-minimum-number-of-changes-to-make-binary-string-beautiful ├── 3174-minimum-number-of-changes-to-make-binary-string-beautiful.cpp └── README.md ├── 3181-find-building-where-alice-and-bob-can-meet ├── 3181-find-building-where-alice-and-bob-can-meet.cpp └── README.md ├── 3189-find-champion-ii ├── 3189-find-champion-ii.cpp └── README.md ├── 3194-find-words-containing-character ├── 3194-find-words-containing-character.cpp └── README.md ├── 3195-separate-black-and-white-balls ├── 3195-separate-black-and-white-balls.cpp └── README.md ├── 3201-distribute-candies-among-children-ii ├── 3201-distribute-candies-among-children-ii.cpp └── README.md ├── 3213-count-subarrays-where-max-element-appears-at-least-k-times ├── 3213-count-subarrays-where-max-element-appears-at-least-k-times.cpp └── README.md ├── 3219-make-lexicographically-smallest-array-by-swapping-elements ├── 3219-make-lexicographically-smallest-array-by-swapping-elements.cpp └── README.md ├── 3227-find-missing-and-repeated-values ├── 3227-find-missing-and-repeated-values.cpp └── README.md ├── 3229-minimum-cost-to-make-array-equalindromic └── README.md ├── 3235-minimum-cost-to-convert-string-i ├── 3235-minimum-cost-to-convert-string-i.cpp └── README.md ├── 3243-count-the-number-of-powerful-integers ├── 3243-count-the-number-of-powerful-integers.cpp └── README.md ├── 3267-find-longest-special-substring-that-occurs-thrice-i ├── 3267-find-longest-special-substring-that-occurs-thrice-i.cpp └── README.md ├── 3271-count-the-number-of-houses-at-a-certain-distance-i ├── 3271-count-the-number-of-houses-at-a-certain-distance-i.cpp └── README.md ├── 3276-minimum-number-of-pushes-to-type-word-ii ├── 3276-minimum-number-of-pushes-to-type-word-ii.cpp └── README.md ├── 3291-find-if-array-can-be-sorted ├── 3291-find-if-array-can-be-sorted.cpp └── README.md ├── 3305-count-prefix-and-suffix-pairs-ii ├── 3305-count-prefix-and-suffix-pairs-ii.cpp └── README.md ├── 3307-find-the-maximum-sum-of-node-values ├── 3307-find-the-maximum-sum-of-node-values.cpp └── README.md ├── 3309-count-prefix-and-suffix-pairs-i ├── 3309-count-prefix-and-suffix-pairs-i.cpp └── README.md ├── 3321-type-of-triangle ├── 3321-type-of-triangle.cpp └── README.md ├── 3329-find-the-length-of-the-longest-common-prefix ├── 3329-find-the-length-of-the-longest-common-prefix.cpp └── README.md ├── 3332-minimum-operations-to-exceed-threshold-value-ii ├── 3332-minimum-operations-to-exceed-threshold-value-ii.cpp └── README.md ├── 3348-minimum-cost-walk-in-weighted-graph ├── 3348-minimum-cost-walk-in-weighted-graph.cpp └── README.md ├── 3372-longest-strictly-increasing-or-strictly-decreasing-subarray ├── 3372-longest-strictly-increasing-or-strictly-decreasing-subarray.cpp └── README.md ├── 3380-shortest-subarray-with-or-at-least-k-ii ├── 3380-shortest-subarray-with-or-at-least-k-ii.cpp └── README.md ├── 3386-find-edges-in-shortest-paths ├── 3386-find-edges-in-shortest-paths.cpp ├── 3386-find-edges-in-shortest-paths.java └── README.md ├── 3394-minimum-array-end ├── 3394-minimum-array-end.cpp └── README.md ├── 3427-special-array-ii ├── 3427-special-array-ii.cpp └── README.md ├── 3429-special-array-i ├── 3429-special-array-i.cpp └── README.md ├── 3430-count-days-without-meetings ├── 3430-count-days-without-meetings.cpp └── README.md ├── 3434-find-the-number-of-distinct-colors-among-the-balls ├── 3434-find-the-number-of-distinct-colors-among-the-balls.cpp └── README.md ├── 3439-find-minimum-diameter-after-merging-two-trees ├── 3439-find-minimum-diameter-after-merging-two-trees.cpp └── README.md ├── 3445-lexicographically-minimum-string-after-removing-stars ├── 3445-lexicographically-minimum-string-after-removing-stars.cpp └── README.md ├── 3447-clear-digits ├── 3447-clear-digits.cpp └── README.md ├── 3451-string-compression-iii ├── 3451-string-compression-iii.cpp └── README.md ├── 3455-minimum-length-of-string-after-operations ├── 3455-minimum-length-of-string-after-operations.cpp └── README.md ├── 3463-alternating-groups-i ├── 3463-alternating-groups-i.cpp └── README.md ├── 3469-maximum-height-of-a-triangle ├── 3469-maximum-height-of-a-triangle.cpp ├── 3469-maximum-height-of-a-triangle.java └── README.md ├── 3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i ├── 3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i.cpp └── README.md ├── 3479-count-the-number-of-substrings-with-dominant-ones ├── 3479-count-the-number-of-substrings-with-dominant-ones.cpp └── README.md ├── 3483-alternating-groups-ii ├── 3483-alternating-groups-ii.cpp └── README.md ├── 3501-delete-nodes-from-linked-list-present-in-array ├── 3501-delete-nodes-from-linked-list-present-in-array.cpp └── README.md ├── 3507-find-the-count-of-numbers-which-are-not-special ├── 3507-find-the-count-of-numbers-which-are-not-special.cpp └── README.md ├── 3515-find-if-digit-game-can-be-won ├── 3515-find-if-digit-game-can-be-won.cpp └── README.md ├── 3517-shortest-distance-after-road-addition-queries-i ├── 3517-shortest-distance-after-road-addition-queries-i.cpp └── README.md ├── 3522-find-the-power-of-k-size-subarrays-i ├── 3522-find-the-power-of-k-size-subarrays-i.cpp └── README.md ├── 3523-find-the-power-of-k-size-subarrays-ii ├── 3523-find-the-power-of-k-size-subarrays-ii.cpp └── README.md ├── 3548-find-the-count-of-good-integers ├── 3548-find-the-count-of-good-integers.cpp └── README.md ├── 3555-final-array-state-after-k-multiplication-operations-i ├── 3555-final-array-state-after-k-multiplication-operations-i.cpp └── README.md ├── 3569-count-of-substrings-containing-every-vowel-and-k-consonants-ii ├── 3569-count-of-substrings-containing-every-vowel-and-k-consonants-ii.cpp └── README.md ├── 3621-minimum-operations-to-make-array-values-equal-to-k ├── 3621-minimum-operations-to-make-array-values-equal-to-k.cpp └── README.md ├── 3627-find-minimum-time-to-reach-last-room-i ├── 3627-find-minimum-time-to-reach-last-room-i.cpp └── README.md ├── 3628-find-minimum-time-to-reach-last-room-ii ├── 3628-find-minimum-time-to-reach-last-room-ii.cpp └── README.md ├── 3629-total-characters-in-string-after-transformations-i ├── 3629-total-characters-in-string-after-transformations-i.cpp └── README.md ├── 3630-total-characters-in-string-after-transformations-ii ├── 3630-total-characters-in-string-after-transformations-ii.cpp └── README.md ├── 3633-maximize-the-number-of-target-nodes-after-connecting-trees-i ├── 3633-maximize-the-number-of-target-nodes-after-connecting-trees-i.cpp └── README.md ├── 3637-count-number-of-balanced-permutations ├── 3637-count-number-of-balanced-permutations.cpp └── README.md ├── 3639-zero-array-transformation-i ├── 3639-zero-array-transformation-i.cpp └── README.md ├── 3643-zero-array-transformation-ii ├── 3643-zero-array-transformation-ii.cpp └── README.md ├── 3645-maximize-the-number-of-target-nodes-after-connecting-trees-ii ├── 3645-maximize-the-number-of-target-nodes-after-connecting-trees-ii.cpp └── README.md ├── 3647-zero-array-transformation-iii ├── 3647-zero-array-transformation-iii.cpp └── README.md ├── 3656-minimum-number-of-operations-to-make-elements-in-array-distinct ├── 3656-minimum-number-of-operations-to-make-elements-in-array-distinct.cpp └── README.md ├── 3657-check-if-grid-can-be-cut-into-sections ├── 3657-check-if-grid-can-be-cut-into-sections.cpp └── README.md ├── 3683-find-the-lexicographically-largest-string-from-the-box-i ├── 3683-find-the-lexicographically-largest-string-from-the-box-i.cpp └── README.md ├── 3685-count-subarrays-of-length-three-with-a-condition ├── 3685-count-subarrays-of-length-three-with-a-condition.cpp └── README.md ├── 3747-maximum-difference-between-adjacent-elements-in-a-circular-array ├── 3747-maximum-difference-between-adjacent-elements-in-a-circular-array.cpp └── README.md ├── 3753-maximum-difference-between-even-and-odd-frequency-i ├── 3753-maximum-difference-between-even-and-odd-frequency-i.cpp └── README.md ├── 3761-maximum-difference-between-even-and-odd-frequency-ii ├── 3761-maximum-difference-between-even-and-odd-frequency-ii.cpp └── README.md ├── CODE_OF_CONDUCT.md ├── Daily-LeetCode-Challenge-Solution in C++ && JAVA ├── 100. Same Tree.cpp ├── 101. Symmetric Tree.java ├── 1011. Capacity To Ship Packages Within D Days.cpp ├── 1020. Number of Enclaves.cpp ├── 1026. Maximum Difference Between Node and Ancestor ├── 103. Binary Tree Zigzag Level Order Traversal ├── 1035. Uncrossed Lines.java ├── 104. Maximum Depth of Binary Tree.java ├── 1046. Last Stone Weight.java ├── 106. Construct Binary Tree from Inorder and Postorder Traversal ├── 1061. Lexicographically Smallest Equivalent String ├── 1071. Greatest Common Divisor of Strings ├── 109. Convert Sorted List to Binary Search Tree ├── 1129. Shortest Path with Alternating Colors ├── 1137. N-th Tribonacci Number.cpp ├── 1155. Number of Dice Rolls With Target Sum ├── 1160. Find Words That Can Be Formed by Characters ├── 1162. As Far from Land as Possible ├── 1207. Unique Number of Occurrences ├── 121. Best Time to Buy and Sell Stock ├── 1235. Maximum Profit in Job Scheduling ├── 1254. Number of Closed Islands ├── 1266. Minimum Time Visiting All Points ├── 129. Sum Root to Leaf Numbers.c ├── 131. Palindrome Partitioning.cpp ├── 1319. Number of Operations to Make Network Connected ├── 1326. Minimum Number of Taps to Open to Water a Garden ├── 1338. Reduce Array Size to The Half ├── 1345. Jump Game IV.cpp ├── 1347. Minimum Number of Steps to Make Two Strings Anagram ├── 1356. Sort Integers by The Number of 1 Bits ├── 1359. Count All Valid Pickup and Delivery Options ├── 137. Single Number II.cpp ├── 1372. Longest ZigZag Path in a Binary Tree ├── 138. Copy List with Random Pointer ├── 1402. Reducing Dishes.cpp ├── 142. Linked List Cycle II.js ├── 1424. Diagonal Traverse II ├── 1436. Destination City ├── 144. Binary Tree Preorder Traversal ├── 1443. Minimum Time to Collect All Apples in a Tree ├── 1444. Number of Ways of Cutting a Pizza ├── 1456. Maximum Number of Vowels in a Substring of Given Length ├── 1466. Reorder Routes to Make All Paths Lead to the City Zero ├── 1470. Shuffle the Array.cs ├── 1472. Design Browser History.swift ├── 1491. Average Salary Excluding the Minimum and Maximum Salary ├── 1493. Longest Subarray of 1's After Deleting One Element ├── 1496. Path Crossing ├── 1498. Number of Subsequences That Satisfy the Given Sum Condition ├── 1519. Number of Nodes in the Sub-Tree With the Same Label ├── 1523. Count Odd Numbers in an Interval Range ├── 1539. Kth Missing Positive Number ├── 1561. Maximum Number of Coins You Can Get ├── 1572. Matrix Diagonal Sum ├── 1579. Remove Max Number of Edges to Keep Graph Fully Traversable ├── 1582. Special Positions in a Binary Matrix ├── 1603. Design Parking System ├── 1626. Best Team With No Conflicts ├── 1630. Arithmetic Subarrays ├── 1669. Merge In Between Linked Lists ├── 1675. Minimize Deviation in Array ├── 1685. Sum of Absolute Differences in a Sorted Array ├── 1697. Checking Existence of Edge Length Limited Paths ├── 1700. Number of Students Unable to Eat Lunch ├── 1704. Determine if String Halves Are Alike ├── 1768. Merge Strings Alternately ├── 1799. Maximize Score After N Operations ├── 1814. Count Nice Pairs in an Array ├── 1822. Sign of the Product of an Array ├── 1964. Find the Longest Valid Obstacle Course at Each Position ├── 208. Implement Trie (Prefix Tree) ├── 209. Minimum Size Subarray Sum ├── 211. Design Add and Search Words Data Structure ├── 2140. Solving Questions With Brainpower ├── 215. Kth Largest Element in an Array ├── 2187. Minimum Time to Complete Trips ├── 2215. Find the Difference of Two Arrays ├── 2246. Longest Path With Different Adjacent Characters ├── 226. Invert Binary Tree ├── 2264. Largest 3-Same-Digit Number in String ├── 23. Merge k Sorted Lists ├── 2300. Successful Pairs of Spells and Potions ├── 2306. Naming a Company ├── 2316. Count Unreachable Pairs of Nodes in an Undirected Graph ├── 2336. Smallest Number in Infinite Set ├── 2348. Number of Zero-Filled Subarrays ├── 2359. Find Closest Node to Given Two Nodes ├── 2360. Longest Cycle in a Graph ├── 2369. Check if There is a Valid Partition For The Array.dart ├── 2385. Amount of Time for Binary Tree to Be Infected ├── 239. Sliding Window Maximum ├── 2405. Optimal Partition of String ├── 242. Valid Anagram ├── 2421. Number of Good Paths ├── 2444. Count Subarrays With Fixed Bounds ├── 2462. Total Cost to Hire K Workers.cpp ├── 2466. Count Ways To Build Good Strings ├── 2477. Minimum Fuel Cost to Report to the Capital ├── 2482. Difference Between Ones and Zeros in Row and Column ├── 2483. Minimum Penalty for a Shop ├── 2492. Minimum Score of a Path Between Two Cities ├── 258. Add Digits.swift ├── 2610. Convert an Array Into a 2D Array With Conditions ├── 28. Find the Index of the First Occurrence in a String ├── 2958. Length of Longest Subarray With at Most K Frequency ├── 2962. Count Subarrays Where Max Element Appears at Least K Times ├── 338. Counting Bits ├── 35. Search Insert Position ├── 352. Data Stream as Disjoint Intervals ├── 382. Linked List Random Node ├── 399. Evaluate Division ├── 403. Frog Jump ├── 427. Construct Quad Tree ├── 438. Find All Anagrams in a String ├── 443. String Compression ├── 446. Arithmetic Slices II - Subsequence ├── 45. Jump Game II.py ├── 455. Assign Cookies ├── 456. 132 Pattern ├── 459. Repeated Substring Pattern ├── 460. LFU Cache ├── 472. Concatenated Words ├── 491. Non-decreasing Subsequences ├── 502. IPO ├── 523. Continuous Subarray Sum ├── 54. Spiral Matrix ├── 540. Single Element in a Sorted Array ├── 567. Permutation in String ├── 57. Insert Interval ├── 59. Spiral Matrix II.dart ├── 6. Zigzag Conversion ├── 605. Can Place Flowers ├── 64. Minimum Path Sum ├── 646. Maximum Length of Pair Chain ├── 649. Dota2 Senate ├── 652. Find Duplicate Subtrees ├── 67. Add Binary ├── 678. Valid Parenthesis String ├── 704. Binary Search ├── 705. Design HashSet ├── 72. Edit Distance ├── 725. Split Linked List in Parts ├── 783. Minimum Distance Between BST Nodes ├── 785. Is Graph Bipartite? ├── 787. Cheapest Flights Within K Stops ├── 837. New 21 Game ├── 87. Scramble String ├── 872. Leaf-Similar Trees ├── 875. Koko Eating Bananas ├── 881. Boats to Save People ├── 9. Palindrome Number.cpp ├── 904. Fruit Into Baskets ├── 909. Snakes and Ladders ├── 912. Sort an Array ├── 918. Maximum Sum Circular Subarray ├── 92. Reverse Linked List II ├── 926. Flip String to Monotone Increasing ├── 93. Restore IP Addresses ├── 934. Shortest Bridge ├── 938. Range Sum of BST ├── 946. Validate Stack Sequences ├── 95. Unique Binary Search Trees II.py ├── 953. Verifying an Alien Dictionary ├── 958. Check Completeness of a Binary Tree ├── 974. Subarray Sums Divisible by K ├── 983. Minimum Cost For Tickets ├── 989. Add to Array-Form of Integer └── 997. Find the Town Judge ├── LICENSE ├── README.md ├── SECURITY.md └── stats.json /0001-two-sum/0001-two-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] nums, int target) { 3 | int n= nums.length; 4 | HashMap m = new HashMap<>(); 5 | for(int i=0; i0 && r len){ 16 | len = r-l+1; 17 | start = l; 18 | } 19 | } 20 | return s.substr(start , len); 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /0005-longest-palindromic-substring/0005-longest-palindromic-substring.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String longestPalindrome(String s) { 3 | String t = "#"+ String.join("#" , s.split("")) + "#"; 4 | int n = t.length(); 5 | int C = 0, R =0; 6 | int[] p = new int[n]; 7 | 8 | for(int i=1; i=0 && t.charAt(i-p[i]-1) == t.charAt(i+p[i] + 1) ){ 14 | p[i]++; 15 | } 16 | if(i+p[i] > R){ 17 | C = i; 18 | R = i+p[i]; 19 | 20 | } 21 | } 22 | 23 | int maxLen = 0 , centerIdx = 0; 24 | for(int i=1; i maxLen){ 26 | centerIdx = i; 27 | maxLen = p[i]; 28 | } 29 | } 30 | int start = (centerIdx - maxLen)/2; 31 | return s.substring(start , start + maxLen); 32 | } 33 | } -------------------------------------------------------------------------------- /0005-longest-palindromic-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0005-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 |
 7 | Input: s = "babad"
 8 | Output: "bab"
 9 | Explanation: "aba" is also a valid answer.
10 | 
11 | 12 |

Example 2:

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

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= s.length <= 1000
  • 24 |
  • s consist of only digits and English letters.
  • 25 |
26 | -------------------------------------------------------------------------------- /0010-regular-expression-matching/0010-regular-expression-matching.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isMatch(string s, string p) { 4 | int m = s.size(); 5 | int n = p.size(); 6 | vector> dp(m+1 , vector(n+1 , false)); 7 | dp[0][0] = true; 8 | for(int i=1; i<=n; i++){ 9 | if(p[i-1] == '*'){ 10 | dp[0][i] = dp[0][i-2]; 11 | } 12 | } 13 | 14 | for(int i=1; i<=m; i++){ 15 | for(int j=1; j<=n; j++){ 16 | if(p[j-1] == '.' || p[j-1] == s[i-1]){ 17 | dp[i][j] = dp[i-1][j-1]; 18 | } 19 | else if(p[j-1] == '*'){ 20 | dp[i][j] = dp[i][j-2]; 21 | if(p[j-2] == '.' || p[j-2] == s[i-1]){ 22 | dp[i][j] = dp[i][j] || dp[i-1][j]; 23 | } 24 | } 25 | } 26 | } 27 | return dp[m][n]; 28 | } 29 | }; -------------------------------------------------------------------------------- /0033-search-in-rotated-sorted-array/0033-search-in-rotated-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& nums, int target) { 4 | int n = nums.size(); 5 | int low = 0 , high = n-1; 6 | while(low <= high){ 7 | int mid = low + (high - low) / 2; 8 | if(nums[mid] == target) return mid; 9 | else if(nums[mid] >= nums[low]){ 10 | if(target >= nums[low] && target < nums[mid]) high = mid-1; 11 | else low = mid + 1; 12 | } 13 | else{ 14 | if(target <= nums[high] && target > nums[mid]) low = mid+1; 15 | else high = mid-1; 16 | } 17 | } 18 | return -1; 19 | } 20 | }; -------------------------------------------------------------------------------- /0038-count-and-say/0038-count-and-say.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string countAndSay(int n) { 4 | // if n == 1 reutn 11 simple and if we go to n we n-1 operation to a string just we nned to cnt the frequeny of element from the start oje meaintin the cnt and thier is no of that string just add the cnt no of that no like 3322251 -> 23321511 5 | if(n==1) return "1"; 6 | // now we need to get the n number start with from the start of 1 to n and perform operation of this one rle of no like for n = 4 sart with 1 we know its 1 and for 2 we know its 11 and for 3 its 21 and for 4 its 1211 we know we print cnt first then no and then cnt then no so one ok but how like u know we itrate thorugh a no or use string methid to get the char of each string cnt ok 7 | string ans = ""; 8 | int cnt = 1; 9 | string s = countAndSay(n-1); 10 | for(int i=0; i> res; 4 | vector> combinationSum2(vector& candidates, int target) { 5 | int n = candidates.size(); 6 | sort(candidates.begin() , candidates.end()); 7 | vector temp; 8 | helper(temp , candidates , target , 0); 9 | return res; 10 | } 11 | void helper(vector& temp , vector& candidates, int target , int idx){ 12 | if(target == 0){ 13 | res.push_back(temp); 14 | return; 15 | } 16 | if(target < 0) return; 17 | for(int i=idx; i idx && candidates[i] == candidates[i-1]) continue; 19 | temp.push_back(candidates[i]); 20 | helper(temp , candidates , target - candidates[i] , i + 1); 21 | temp.pop_back(); 22 | } 23 | } 24 | 25 | }; -------------------------------------------------------------------------------- /0042-trapping-rain-water/0042-trapping-rain-water.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int trap(vector& height) { 4 | int n = height.size(); 5 | int left = 0 , right = n-1 , leftMax = 0 , rightMax = 0 , res = 0; 6 | while(left <= right){ 7 | if(height[left] <= height[right]){ 8 | if(height[left] >= leftMax) leftMax = height[left]; 9 | else res += leftMax - height[left]; 10 | left++; 11 | } 12 | else{ 13 | if(height[right] >= rightMax) rightMax = height[right]; 14 | else res += rightMax - height[right]; 15 | right--; 16 | } 17 | } 18 | return res; 19 | } 20 | }; -------------------------------------------------------------------------------- /0045-jump-game-ii/0045-jump-game-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int jump(vector& nums) { 4 | int n = nums.size() , maxIndex = 0 , curr = 0 , jump = 0; 5 | // int i=0 , j = 0 , res = 0; 6 | // while(j> groupAnagrams(vector& strs) { 4 | // vector> res; 5 | // unordered_map> mp; 6 | // for(string s : strs){ 7 | // string temp = s; 8 | // sort(temp.begin() , temp.end()); 9 | // mp[temp].push_back(s); 10 | // } 11 | // for(auto m : mp) res.push_back(m.second); 12 | // return res; 13 | vector> res; 14 | unordered_map> mp; 15 | for(auto s1 : strs){ 16 | string s = s1; 17 | sort(s.begin() , s.end()); 18 | mp[s].push_back(s1); 19 | } 20 | for(auto it : mp) res.push_back(it.second); 21 | return res; 22 | } 23 | }; -------------------------------------------------------------------------------- /0053-maximum-subarray/0053-maximum-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSubArray(vector& nums) { 4 | int n = nums.size(); 5 | int res = nums[0] , sum = nums[0]; 6 | for(int i=1; i& nums) { 4 | int n = nums.size(); 5 | int maxReach = 0; 6 | for(int i=0; imaxReach) return false; 8 | maxReach = max(maxReach , i+nums[i]); 9 | } 10 | return true; 11 | } 12 | }; -------------------------------------------------------------------------------- /0055-jump-game/0055-jump-game.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canJump(int[] nums) { 3 | int n = nums.length; 4 | int maxReach = 0; 5 | for(int i=0; imaxReach) return false; 7 | maxReach = Math.max(maxReach , i+nums[i]); 8 | } 9 | return true; 10 | } 11 | } -------------------------------------------------------------------------------- /0062-unique-paths/0062-unique-paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[101][101]{}; 4 | int uniquePaths(int m, int n , int i=0 , int j = 0) { 5 | if(i>=m || j>=n) return 0; 6 | if(i == m-1 && j == n-1) return 1; 7 | if(dp[i][j]) return dp[i][j]; 8 | return dp[i][j] = uniquePaths(m , n , i+1, j) + uniquePaths(m , n , i , j+1); 9 | } 10 | }; -------------------------------------------------------------------------------- /0062-unique-paths/0062-unique-paths.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int uniquePaths(int m, int n) { 3 | int[][] dp = new int[m][n]; 4 | for(int i=0; i>& obstacleGrid) { 4 | int m = obstacleGrid.size(); 5 | int n = obstacleGrid[0].size(); 6 | vector> dp(m , vector(n)); 7 | for(int i=0; i>& matrix) { 4 | int m = matrix.size() , n = matrix[0].size(); 5 | // isRow and isCol two thing used when we find 0 means acc to zero we need to this isRow to 0 and isCol to 0 ok 6 | bool isRow = false , isCol = false; 7 | for(int i=0; i& nums) { 4 | // DNF Dutch National Flag algorithm , three pointer uses , also called One-Pass Algo 5 | int n = nums.size(); 6 | int low = 0 , mid = 0 , high = n-1; 7 | while(mid<=high){ 8 | if(nums[mid] == 0){ 9 | swap(nums[low] , nums[mid]); 10 | low++; 11 | mid++; 12 | } 13 | else if(nums[mid] == 1) mid++; 14 | else{ 15 | swap(nums[mid] , nums[high]); 16 | high--; 17 | } 18 | } 19 | } 20 | }; -------------------------------------------------------------------------------- /0091-decode-ways/0091-decode-ways.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numDecodings(string s) { 4 | vector dp(s.size()+1 , 0); 5 | dp[0] = 1; 6 | dp[1] = (s[0] == '0') ? 0 : 1; 7 | for(int i=2; i<=s.size(); i++){ 8 | int first = s[i-1] - '0'; 9 | int second = (s[i-2] - '0')*10 + (s[i-1] - '0'); 10 | if(first >= 1 && first <= 9) dp[i] += dp[i-1]; 11 | if(second >=10 && second <= 26) dp[i] += dp[i-2]; 12 | } 13 | return dp[s.size()]; 14 | } 15 | }; -------------------------------------------------------------------------------- /0128-longest-consecutive-sequence/0128-longest-consecutive-sequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestConsecutive(vector& nums) { 4 | int n = nums.size(); 5 | unordered_set mp(nums.begin() , nums.end()); 6 | int curr = 0 , currLen = 0 , maxLen = 0; 7 | for(auto num : nums){ 8 | if(mp.find(num-1) == mp.end()){ 9 | curr = num; 10 | currLen = 1; 11 | while(mp.find(curr+1) != mp.end()){ 12 | curr++; 13 | currLen++; 14 | } 15 | maxLen = max(maxLen , currLen); 16 | } 17 | } 18 | return maxLen; 19 | } 20 | }; -------------------------------------------------------------------------------- /0128-longest-consecutive-sequence/README.md: -------------------------------------------------------------------------------- 1 |

128. Longest Consecutive Sequence

Medium


Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.

2 | 3 |

You must write an algorithm that runs in O(n) time.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: nums = [100,4,200,1,3,2]
10 | Output: 4
11 | Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: nums = [0,3,7,2,5,8,4,6,0,1]
18 | Output: 9
19 | 
20 | 21 |

 

22 |

Constraints:

23 | 24 |
    25 |
  • 0 <= nums.length <= 105
  • 26 |
  • -109 <= nums[i] <= 109
  • 27 |
28 | -------------------------------------------------------------------------------- /0135-candy/0135-candy.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int candy(vector& ratings) { 4 | int n = ratings.size(); 5 | int candies = 0; 6 | if(n<=1) return n; 7 | vector num(n , 1); 8 | for(int i=1; i ratings[i-1]) num[i] = num[i-1]+1; 10 | } 11 | for(int i=n-1; i>0; i--){ 12 | if(ratings[i-1] > ratings[i]) num[i-1] = max(num[i-1] , num[i]+1); 13 | } 14 | for(int i=0; i& wordDict) { 4 | int n = s.size(); 5 | vector dp(n+1 , false); 6 | dp[0] = true; 7 | for(int i=1; i<=n; i++){ 8 | for(int j=0; j postorderTraversal(TreeNode* root) { 15 | vector res; 16 | postorderHelper(root, res); 17 | return res; 18 | } 19 | 20 | private: 21 | void postorderHelper(TreeNode* node, vector& res) { 22 | if (node == NULL) return; 23 | postorderHelper(node->left, res); // Traverse left subtree 24 | postorderHelper(node->right, res); // Traverse right subtree 25 | res.push_back(node->val); // Visit root node 26 | } 27 | }; -------------------------------------------------------------------------------- /0152-maximum-product-subarray/0152-maximum-product-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProduct(vector& nums) { 4 | int n = nums.size(); 5 | double ans = INT_MIN; 6 | double pr = 1, su = 1; 7 | for (int i=0; i 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | static bool compare(const std::string &a, const std::string &b) { 8 | return a + b > b + a; 9 | } 10 | 11 | std::string largestNumber(std::vector& nums) { 12 | // Convert numbers to strings 13 | std::vector numStrs; 14 | for (int num : nums) { 15 | numStrs.push_back(std::to_string(num)); 16 | } 17 | 18 | // Sort the strings using the custom comparator 19 | std::sort(numStrs.begin(), numStrs.end(), compare); 20 | 21 | // Handle the case where the largest number is "0" 22 | if (numStrs[0] == "0") { 23 | return "0"; 24 | } 25 | 26 | // Concatenate the sorted strings 27 | std::string result; 28 | for (const std::string &numStr : numStrs) { 29 | result += numStr; 30 | } 31 | 32 | return result; 33 | } 34 | }; -------------------------------------------------------------------------------- /0179-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 |
 9 | Input: nums = [10,2]
10 | Output: "210"
11 | 
12 | 13 |

Example 2:

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

 

21 |

Constraints:

22 | 23 |
    24 |
  • 1 <= nums.length <= 100
  • 25 |
  • 0 <= nums[i] <= 109
  • 26 |
27 | -------------------------------------------------------------------------------- /0198-house-robber/0198-house-robber.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int rob(vector& nums) { 4 | int n = nums.size(); 5 | // vector dp(n , 0); 6 | // dp[0] = nums[0]; 7 | // for(int i=1; i1) 10 | // take += dp[i-2]; 11 | // int nottake = 0+dp[i-1]; 12 | // dp[i] = max(take , nottake); 13 | // } 14 | // return dp[n-1]; 15 | int p1 = 0 , p2 = 0; 16 | for(auto n : nums){ 17 | int tmp = p1; 18 | p1 = max(p1 , n + p2); 19 | p2 =tmp; 20 | } 21 | return p1; 22 | } 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /0213-house-robber-ii/0213-house-robber-ii.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int rob(vector& nums, int lo, int hi) { 8 | int inc = 0, exc = 0; 9 | for (int i = lo; i <= hi; i++) { 10 | int new_inc = exc + nums[i]; 11 | exc = max(exc, inc); 12 | inc = new_inc; 13 | } 14 | return max(inc, exc); 15 | } 16 | 17 | int rob(vector& nums) { 18 | int n = nums.size(); 19 | if (n == 0) return 0; 20 | if (n == 1) return nums[0]; 21 | return max(rob(nums, 0, n - 2), rob(nums, 1, n - 1)); 22 | } 23 | }; -------------------------------------------------------------------------------- /0214-shortest-palindrome/0214-shortest-palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String shortestPalindrome(String s) { 3 | // 1.) Using KMP Algorithm 4 | String r = new StringBuilder(s).reverse().toString(); 5 | String t = s + "#" + r; 6 | int n = t.length(); 7 | int[] p = new int[n]; 8 | for (int i = 1; i < n; i++) { 9 | int j = p[i - 1]; 10 | while (j > 0 && t.charAt(i) != t.charAt(j)) j = p[j - 1]; 11 | if (t.charAt(i) == t.charAt(j)) j++; 12 | p[i] = j; 13 | } 14 | return new StringBuilder(r.substring(0, s.length() - p[n - 1])).append(s).toString(); 15 | } 16 | } -------------------------------------------------------------------------------- /0214-shortest-palindrome/0214-shortest-palindrome.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String shortestPalindrome(String s) { 3 | String r = new StringBuilder(s).reverse().toString(); 4 | String t = s + "#" + r; 5 | int n = t.length(); 6 | int[] p = new int[n]; 7 | for(int i=1; i0 && t.charAt(i) != t.charAt(j)) j = p[j-1]; 10 | if(t.charAt(i) == t.charAt(j)) j++; 11 | p[i] = j; 12 | } 13 | return new StringBuilder(r.substring(0 , s.length() - p[n-1])).append(s).toString(); 14 | } 15 | } -------------------------------------------------------------------------------- /0214-shortest-palindrome/README.md: -------------------------------------------------------------------------------- 1 |

214. Shortest Palindrome

Hard


You are given a string s. You can convert s to a palindrome by adding characters in front of it.

2 | 3 |

Return the shortest palindrome you can find by performing this transformation.

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = "aacecaaa"
 8 | Output: "aaacecaaa"
 9 | 

Example 2:

10 |
Input: s = "abcd"
11 | Output: "dcbabcd"
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 0 <= s.length <= 5 * 104
  • 18 |
  • s consists of lowercase English letters only.
  • 19 |
20 | -------------------------------------------------------------------------------- /0217-contains-duplicate/0217-contains-duplicate.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool containsDuplicate(vector& nums) { 4 | unordered_map mp; 5 | for(auto num : nums) mp[num]++; 6 | for(auto it : mp){ 7 | if(it.second >= 2) return true; 8 | } 9 | return false; 10 | } 11 | }; -------------------------------------------------------------------------------- /0217-contains-duplicate/README.md: -------------------------------------------------------------------------------- 1 |

217. Contains Duplicate

Easy


Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

2 | 3 |

 

4 |

Example 1:

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

Example 2:

8 |
Input: nums = [1,2,3,4]
 9 | Output: false
10 | 

Example 3:

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

 

15 |

Constraints:

16 | 17 |
    18 |
  • 1 <= nums.length <= 105
  • 19 |
  • -109 <= nums[i] <= 109
  • 20 |
21 | -------------------------------------------------------------------------------- /0236-lowest-common-ancestor-of-a-binary-tree/0236-lowest-common-ancestor-of-a-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * struct TreeNode { 4 | * int val; 5 | * TreeNode *left; 6 | * TreeNode *right; 7 | * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 | * }; 9 | */ 10 | class Solution { 11 | public: 12 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { 13 | if (!root || root == p || root == q) return root; 14 | TreeNode* left = lowestCommonAncestor(root->left, p, q); 15 | TreeNode* right = lowestCommonAncestor(root->right, p, q); 16 | return !left ? right : !right ? left : root; 17 | } 18 | }; -------------------------------------------------------------------------------- /0238-product-of-array-except-self/0238-product-of-array-except-self.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector productExceptSelf(vector& nums) { 4 | int n = nums.size(); 5 | vector res(n , 1); 6 | int left = 1; 7 | for(int i=0; i=0; i--){ 14 | res[i] *= right; 15 | right *= nums[i]; 16 | } 17 | return res; 18 | } 19 | }; -------------------------------------------------------------------------------- /0264-ugly-number-ii/0264-ugly-number-ii.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC optimize("Ofast","inline","fast-math","unroll-loops","no-stack-protector") 2 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native","f16c") 3 | static const auto fast = []() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; } (); 4 | 5 | class Solution { 6 | public: 7 | int nthUglyNumber(int n) { 8 | vector dp(n); 9 | dp[0] = 1; 10 | int t2 = 0 , t3 = 0 , t5 = 0; 11 | for(int i =1; i264. Ugly Number II

Medium


An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.

2 | 3 |

Given an integer n, return the nth ugly number.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: n = 10
10 | Output: 12
11 | Explanation: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12] is the sequence of the first 10 ugly numbers.
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: n = 1
18 | Output: 1
19 | Explanation: 1 has no prime factors, therefore all of its prime factors are limited to 2, 3, and 5.
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • 1 <= n <= 1690
  • 27 |
28 | -------------------------------------------------------------------------------- /0268-missing-number/0268-missing-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int missingNumber(vector& nums) { 4 | int ans = nums.size(); 5 | 6 | for (int i = 0; i < nums.size(); ++i) 7 | ans ^= i ^ nums[i]; 8 | 9 | return ans; 10 | } 11 | }; -------------------------------------------------------------------------------- /0273-integer-to-english-words/README.md: -------------------------------------------------------------------------------- 1 |

273. Integer to English Words

Hard


Convert a non-negative integer num to its English words representation.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: num = 123
 8 | Output: "One Hundred Twenty Three"
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: num = 12345
15 | Output: "Twelve Thousand Three Hundred Forty Five"
16 | 
17 | 18 |

Example 3:

19 | 20 |
21 | Input: num = 1234567
22 | Output: "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 |
    29 |
  • 0 <= num <= 231 - 1
  • 30 |
31 | -------------------------------------------------------------------------------- /0300-longest-increasing-subsequence/0300-longest-increasing-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLIS(vector& nums) { 4 | int n = nums.size(); 5 | vector dp(n , 1); 6 | dp[0] = 1; 7 | for(int i=1; i nums[j]) dp[i] = max(dp[i] , dp[j] + 1); 10 | } 11 | } 12 | int maxi = 1; 13 | for(auto val : dp) maxi = max(maxi , val); 14 | return maxi; 15 | } 16 | }; -------------------------------------------------------------------------------- /0322-coin-change/0322-coin-change.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int coinChange(vector& coins, int amount) { 4 | // vector dp(amount+1 , 1e9); 5 | // dp[0] = 0; 6 | // for(int coin : coins){ 7 | // for(int i=coin; i<=amount; i++){ 8 | // dp[i] = min(dp[i] , dp[i-coin] + 1); 9 | // } 10 | // } 11 | // return dp[amount]== 1e9 ? -1 : dp[amount]; 12 | vector dp(amount+1 , 1e9); 13 | dp[0] = 0; 14 | for(auto c : coins){ 15 | for(int i=c; i<=amount; i++){ 16 | dp[i] = min(dp[i] , dp[i-c] + 1); 17 | } 18 | } 19 | return dp[amount] == 1e9 ? -1 : dp[amount]; 20 | } 21 | }; -------------------------------------------------------------------------------- /0338-counting-bits/0338-counting-bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector countBits(int n) { 4 | vector dp(n+1); 5 | for(int i=1; i<=n; i++) dp[i] = dp[i/2] + i%2; 6 | return dp; 7 | } 8 | }; -------------------------------------------------------------------------------- /0350-intersection-of-two-arrays-ii/0350-intersection-of-two-arrays-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution {// Using Map & without sort 2 | public: 3 | vector intersect(vector& nums1, vector& nums2) { 4 | mapfreq; 5 | vectorans; 6 | for(int i = 0;i 0){ 11 | freq[nums2[i]]--; 12 | ans.push_back(nums2[i]); 13 | } 14 | } 15 | return ans; 16 | } 17 | }; -------------------------------------------------------------------------------- /0368-largest-divisible-subset/0368-largest-divisible-subset.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector largestDivisibleSubset(vector& nums) { 4 | sort(nums.begin(), nums.end()); 5 | int n = nums.size(); 6 | vector dp(n, 0), parent(n, 0), res; 7 | int mx = 0, mx_idx = 0; 8 | 9 | for(int i=n-1; i>=0; i--) { 10 | for(int j=i; j371. Sum of Two Integers

Medium


Given two integers a and b, return the sum of the two integers without using the operators + and -.

2 | 3 |

 

4 |

Example 1:

5 |
Input: a = 1, b = 2
 6 | Output: 3
 7 | 

Example 2:

8 |
Input: a = 2, b = 3
 9 | Output: 5
10 | 
11 |

 

12 |

Constraints:

13 | 14 |
    15 |
  • -1000 <= a, b <= 1000
  • 16 |
17 | -------------------------------------------------------------------------------- /0377-combination-sum-iv/0377-combination-sum-iv.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int combinationSum4(vector& nums, int target) { 4 | sort(nums.begin() , nums.end()); 5 | vector dp(target +1); dp[0] = 1; 6 | for(int i=1; i<=target; i++){ 7 | for(auto num : nums){ 8 | if(num <= i) dp[i] += dp[i-num]; 9 | else break; 10 | } 11 | } 12 | return dp[target]; 13 | } 14 | }; -------------------------------------------------------------------------------- /0386-lexicographical-numbers/0386-lexicographical-numbers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector lexicalOrder(int n) { 4 | int curr = 1; 5 | vector res; 6 | for(int i=0; i=n) curr /= 10; 11 | curr++; 12 | while(curr%10 == 0) curr /= 10; 13 | } 14 | } 15 | return res; 16 | } 17 | }; -------------------------------------------------------------------------------- /0386-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 | -------------------------------------------------------------------------------- /0416-partition-equal-subset-sum/README.md: -------------------------------------------------------------------------------- 1 |

416. Partition Equal Subset Sum

Medium


Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: nums = [1,5,11,5]
 8 | Output: true
 9 | Explanation: The array can be partitioned as [1, 5, 5] and [11].
10 | 
11 | 12 |

Example 2:

13 | 14 |
15 | Input: nums = [1,2,3,5]
16 | Output: false
17 | Explanation: The array cannot be partitioned into equal sum subsets.
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • 1 <= nums.length <= 200
  • 25 |
  • 1 <= nums[i] <= 100
  • 26 |
27 | -------------------------------------------------------------------------------- /0440-k-th-smallest-in-lexicographical-order/0440-k-th-smallest-in-lexicographical-order.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findKthNumber(int n, int k) { 4 | int curr = 1; 5 | k--; 6 | while(k>0){ 7 | long long steps = count(n , curr , curr+1); 8 | if(steps<=k){ 9 | curr++; 10 | k -= steps; 11 | } 12 | else{ 13 | curr *= 10; 14 | k--; 15 | } 16 | } 17 | return curr; 18 | } 19 | long count(int n , long long curr , long long next){ 20 | long long steps = 0; 21 | while(curr <= n){ 22 | steps += min((long long)n + 1 , next) - curr; 23 | curr *= 10; 24 | next *= 10; 25 | } 26 | return steps; 27 | } 28 | }; -------------------------------------------------------------------------------- /0440-k-th-smallest-in-lexicographical-order/0440-k-th-smallest-in-lexicographical-order.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findKthNumber(int n, int k) { 3 | int curr = 1; 4 | k--; 5 | while(k >0){ 6 | long steps = count(n , curr , curr + 1); 7 | if(steps <= k){ 8 | curr++; 9 | k -= steps; 10 | } 11 | else{ 12 | curr *= 10; 13 | k--; 14 | } 15 | } 16 | return curr; 17 | } 18 | long count(int n, long curr , long next){ 19 | long steps = 0; 20 | while(curr <= n){ 21 | steps += Math.min((long) n + 1 , next) - curr; 22 | curr *= 10; 23 | next *= 10; 24 | } 25 | return steps; 26 | } 27 | } -------------------------------------------------------------------------------- /0440-k-th-smallest-in-lexicographical-order/README.md: -------------------------------------------------------------------------------- 1 |

440. K-th Smallest in Lexicographical Order

Hard


Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: n = 13, k = 2
 8 | Output: 10
 9 | Explanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so the second smallest number is 10.
10 | 
11 | 12 |

Example 2:

13 | 14 |
15 | Input: n = 1, k = 1
16 | Output: 1
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= k <= n <= 109
  • 24 |
25 | -------------------------------------------------------------------------------- /0453-minimum-moves-to-equal-array-elements/0453-minimum-moves-to-equal-array-elements.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minMoves(vector& nums) { 4 | int n = nums.size() , diff = 0; 5 | sort(nums.begin() , nums.end()); 6 | for(int i=0; i& nums) { 4 | int n = nums.size() , diff = 0; 5 | sort(nums.begin() , nums.end()); 6 | int median = nums[nums.size()/2]; 7 | for(int i=0; i515. Find Largest Value in Each Tree Row

Medium


Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: root = [1,3,2,5,3,null,9]
 8 | Output: [1,3,9]
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: root = [1,2,3]
15 | Output: [1,3]
16 | 
17 | 18 |

 

19 |

Constraints:

20 | 21 |
    22 |
  • The number of nodes in the tree will be in the range [0, 104].
  • 23 |
  • -231 <= Node.val <= 231 - 1
  • 24 |
25 | -------------------------------------------------------------------------------- /0516-longest-palindromic-subsequence/0516-longest-palindromic-subsequence.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestPalindromeSubseq(String s) { 3 | // dp problem 4 | int n = s.length(); 5 | int[][] dp = new int[n][n]; 6 | for(int i=n-1; i>=0; i--){ 7 | dp[i][i] = 1; 8 | for(int j=i+1; j& timePoints) { 4 | // Convert input to minutes 5 | vector minutes(timePoints.size()); 6 | for (int i = 0; i < timePoints.size(); i++) { 7 | string time = timePoints[i]; 8 | int h = stoi(time.substr(0, 2)); 9 | int m = stoi(time.substr(3)); 10 | minutes[i] = h * 60 + m; 11 | } 12 | 13 | // Sort times in ascending order 14 | sort(minutes.begin(), minutes.end()); 15 | 16 | // Find minimum difference across adjacent elements 17 | int ans = INT_MAX; 18 | for (int i = 0; i < minutes.size() - 1; i++) { 19 | ans = min(ans, minutes[i + 1] - minutes[i]); 20 | } 21 | 22 | // Consider difference between last and first element 23 | return min(ans, 24 * 60 - minutes[minutes.size() - 1] + minutes[0]); 24 | } 25 | }; -------------------------------------------------------------------------------- /0539-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 | -------------------------------------------------------------------------------- /0564-find-the-closest-palindrome/0564-find-the-closest-palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string nearestPalindromic(string n) { 4 | int len = n.size(); 5 | if(len == 1) return to_string(stoi(n)-1); 6 | vector candidates; 7 | long num = stol(n); 8 | candidates.push_back((long)pow(10 , len -1) -1); 9 | candidates.push_back((long)pow(10 , len) + 1); 10 | long pre = stol(n.substr( 0 , (len+1) / 2)); 11 | for(int i=-1; i<=1; i++){ 12 | string p = to_string(pre + i); 13 | string candidate = p + string(p.rbegin() + (len & 1), p.rend()); 14 | candidates.push_back(stol(candidate)); 15 | } 16 | long close = -1; 17 | for(auto candidate : candidates){ 18 | if(candidate != num){ 19 | if(close == -1 || abs(candidate - num) < abs(close - num) || abs(candidate - num) == abs(close - num) && candidate < close){ 20 | close = candidate; 21 | } 22 | } 23 | } 24 | return to_string(close); 25 | } 26 | }; -------------------------------------------------------------------------------- /0567-permutation-in-string/0567-permutation-in-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkInclusion(string s1, string s2) { 4 | vector v1(26); 5 | vector v2(26); 6 | for(int i=0; i=s1.size()){ 12 | v2[s2[i-s1.size()]-'a']--; 13 | } 14 | if(v1 == v2) return true; 15 | } 16 | return false; 17 | 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /0576-out-of-boundary-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0624-maximum-distance-in-arrays/0624-maximum-distance-in-arrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDistance(vector>& arrays) { 4 | int minVal = arrays[0][0]; 5 | int maxVal = arrays[0].back(); 6 | int maxD = 0; 7 | for(int i=1; i1){ 7 | while(n%i == 0){ 8 | ans += i; 9 | n /= i; 10 | } 11 | i++; 12 | } 13 | return ans; 14 | } 15 | }; -------------------------------------------------------------------------------- /0670-maximum-swap/0670-maximum-swap.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumSwap(int num) { 4 | string numStr = 5 | to_string(num); // Convert num to string for easy manipulation 6 | int n = numStr.size(); 7 | int maxNum = num; // Track the maximum number found 8 | 9 | // Try all possible swaps 10 | for (int i = 0; i < n; ++i) { 11 | for (int j = i + 1; j < n; ++j) { 12 | swap(numStr[i], numStr[j]); // Swap digits at index i and j 13 | maxNum = max( 14 | maxNum, 15 | stoi(numStr)); // Update maxNum if the new number is larger 16 | swap(numStr[i], 17 | numStr[j]); // Swap back to restore the original string 18 | } 19 | } 20 | 21 | return maxNum; // Return the largest number after all possible swaps 22 | } 23 | }; -------------------------------------------------------------------------------- /0670-maximum-swap/README.md: -------------------------------------------------------------------------------- 1 |

670. Maximum Swap

Medium


You are given an integer num. You can swap two digits at most once to get the maximum valued number.

2 | 3 |

Return the maximum valued number you can get.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: num = 2736
10 | Output: 7236
11 | Explanation: Swap the number 2 and the number 7.
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: num = 9973
18 | Output: 9973
19 | Explanation: No swap.
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • 0 <= num <= 108
  • 27 |
28 | -------------------------------------------------------------------------------- /0729-my-calendar-i/0729-my-calendar-i.cpp: -------------------------------------------------------------------------------- 1 | class MyCalendar { 2 | public: 3 | set> st; 4 | bool book(int start, int end) { 5 | auto slot = st.lower_bound({start , end}); 6 | if(slot != st.end() && !(slot->first >= end) || slot != st.begin() && !(prev(slot)->second <= start)) return false; 7 | st.insert({start , end}); 8 | return true; 9 | } 10 | }; 11 | 12 | /** 13 | * Your MyCalendar object will be instantiated and called as such: 14 | * MyCalendar* obj = new MyCalendar(); 15 | * bool param_1 = obj->book(start,end); 16 | */ -------------------------------------------------------------------------------- /0768-partition-labels/0768-partition-labels.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector partitionLabels(string s) { 4 | // we want to partition the string so each string coming at most once means only 1 time or not just do one thing use map or set we solve this one but how lets start we want to return size of that string which is possible and return their len just check the first their freq use 2 pointer for what just check that if that elel is present on that or not reutn the res with size of that all possible string ok 5 | unordered_map lastOccurence; 6 | for(int i=0; i res; 10 | int start = 0 , end = 0; 11 | for(int i=0; i& arr) { 4 | int n = arr.size() , chunk = 0 , max_so_far = 0; 5 | for(int i=0; i dp(n+1); 9 | int mod = 1e9+7; 10 | dp[0] = 0; 11 | dp[1] = 1; 12 | dp[2] = 2; 13 | dp[3] = 5; 14 | for(int i=4; i<=n; i++){ 15 | dp[i] = (dp[i-1] * 2 + dp[i-3]) % mod; 16 | } 17 | return dp[n]; 18 | } 19 | }; -------------------------------------------------------------------------------- /0812-rotate-string/0812-rotate-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool rotateString(string s, string goal) { 4 | // Check if the lengths are different 5 | if (s.length() != goal.length()) return false; 6 | 7 | // Create a new string by concatenating 's' with itself 8 | string doubledString = s + s; 9 | 10 | // Use find to search for 'goal' in 'doubledString' 11 | // If find returns an index that is less than the 12 | // length of doubledString, 'goal' is a substring 13 | return doubledString.find(goal) < doubledString.length(); 14 | } 15 | }; -------------------------------------------------------------------------------- /0890-lemonade-change/0890-lemonade-change.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool lemonadeChange(vector& bills) { 4 | int five = 0, ten = 0; 5 | 6 | for (int bill : bills) { 7 | if (bill == 5) { 8 | five++; 9 | } else if (bill == 10) { 10 | if (five == 0) return false; 11 | five--; 12 | ten++; 13 | } else { // bill == 20 14 | if (ten > 0 && five > 0) { 15 | ten--; 16 | five--; 17 | } else if (five >= 3) { 18 | five -= 3; 19 | } else { 20 | return false; 21 | } 22 | } 23 | } 24 | 25 | return true; 26 | } 27 | }; -------------------------------------------------------------------------------- /0920-uncommon-words-from-two-sentences/0920-uncommon-words-from-two-sentences.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String[] uncommonFromSentences(String A, String B) { 3 | Map count = new HashMap(); 4 | for (String word: A.split(" ")) 5 | count.put(word, count.getOrDefault(word, 0) + 1); 6 | for (String word: B.split(" ")) 7 | count.put(word, count.getOrDefault(word, 0) + 1); 8 | 9 | List ans = new LinkedList(); 10 | for (String word: count.keySet()) 11 | if (count.get(word) == 1) 12 | ans.add(word); 13 | 14 | return ans.toArray(new String[ans.size()]); 15 | } 16 | } -------------------------------------------------------------------------------- /0948-sort-an-array/0948-sort-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sortArray(vector& nums) { 4 | sort(nums.begin() , nums.end()); 5 | vector res; 6 | for(int i=0; i 0) open --; 11 | else close++; 12 | } 13 | } 14 | return open + close; 15 | } 16 | }; -------------------------------------------------------------------------------- /0988-flip-equivalent-binary-trees/0988-flip-equivalent-binary-trees.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * struct TreeNode { 4 | * int val; 5 | * TreeNode *left; 6 | * TreeNode *right; 7 | * TreeNode() : val(0), left(nullptr), right(nullptr) {} 8 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} 9 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} 10 | * }; 11 | */ 12 | class Solution { 13 | public: 14 | bool flipEquiv(TreeNode* root1, TreeNode* root2) { 15 | if(root1 == NULL && root2 == NULL) return true; 16 | if(root1 == NULL || root2 == NULL) return false; 17 | if(root1->val != root2->val) return false; 18 | return (flipEquiv(root1->left , root2->left) && flipEquiv(root1->right , root2->right)) || (flipEquiv(root1->left , root2->right) && flipEquiv(root1->right , root2->left)); 19 | } 20 | }; -------------------------------------------------------------------------------- /1002-maximum-width-ramp/1002-maximum-width-ramp.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxWidthRamp(vector& nums) { 4 | int n = nums.size() , maxW = 0; 5 | stack st; 6 | for(int i=0; i nums[i]) st.push(i); 8 | } 9 | for(int j=n-1; j>=0; j--){ 10 | while(!st.empty() && nums[st.top()] <= nums[j]){ 11 | maxW = max(maxW , j - st.top()); 12 | st.pop(); 13 | } 14 | } 15 | return maxW; 16 | } 17 | }; -------------------------------------------------------------------------------- /1025-minimum-cost-for-tickets/1025-minimum-cost-for-tickets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mincostTickets(vector& days, vector& costs) { 4 | int n = days.size(); 5 | vector dp(n+1 , INT_MAX); 6 | dp[0] = 0; 7 | for(int i=1; i<=n; i++){ 8 | dp[i] = min(dp[i] , dp[i-1]) + costs[0]; 9 | int j = i-1; 10 | while(j>=0 && days[i-1] - days[j] < 7){ 11 | dp[i] = min(dp[i] , dp[j] + costs[1]); 12 | j--; 13 | } 14 | j = i-1; 15 | while(j>=0 && days[i-1] - days[j] < 30){ 16 | dp[i] = min(dp[i] , dp[j] + costs[2]); 17 | j--; 18 | } 19 | } 20 | return dp[n]; 21 | } 22 | }; -------------------------------------------------------------------------------- /1049-minimum-domino-rotations-for-equal-row/1049-minimum-domino-rotations-for-equal-row.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minDominoRotations(vector& A, vector& B) { 4 | vector countA(7), countB(7), same(7); 5 | int n = A.size(); 6 | for (int i = 0; i < n; ++i) { 7 | countA[A[i]]++; 8 | countB[B[i]]++; 9 | if (A[i] == B[i]) 10 | same[A[i]]++; 11 | } 12 | for (int i = 1; i < 7; ++i) 13 | if (countA[i] + countB[i] - same[i] == n) 14 | return n - max(countA[i], countB[i]); 15 | return -1; 16 | } 17 | }; -------------------------------------------------------------------------------- /1058-lexicographically-smallest-equivalent-string/1058-lexicographically-smallest-equivalent-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int find(vector& parent , int x){ 4 | if(parent[x] != x) parent[x] = find(parent , parent[x]); 5 | return parent[x]; 6 | } 7 | string smallestEquivalentString(string s1, string s2, string baseStr) { 8 | vector parent(26); 9 | for(int i=0; i<26; i++){ 10 | parent[i] = i; 11 | } 12 | 13 | for(int i=0; i& values) { 4 | // given arr val[i] represent to ith sighseeing spot two sight seeing spots i and j dis j-i them The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i - j: the sum of the values of the sightseeing spots, minus the distance between them. maximum score of a pair of sightseeing spots. return ok simple fund max 2 ele. and sub index of that ok 5 | int max_i = values[0] + 0; 6 | int maxS = INT_MIN; 7 | for(int j=1; j> dp(n+1 , vector(m+1 , 0)); 6 | for(int i=1; i<=n; i++){ 7 | for(int j=1; j<=m; j++){ 8 | if(text1[i-1] == text2[j-1]) dp[i][j] = 1 + dp[i-1][j-1]; 9 | else{ 10 | dp[i][j] = max(dp[i-1][j] , dp[i][j-1]); 11 | } 12 | } 13 | } 14 | return dp[n][m]; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /1143-longest-common-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1147-flip-columns-for-maximum-number-of-equal-rows/1147-flip-columns-for-maximum-number-of-equal-rows.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxEqualRowsAfterFlips(vector>& matrix) { 4 | unordered_map rowCount; 5 | int maxRows = 0; 6 | for(auto row : matrix){ 7 | string normalizeRows; 8 | for(auto val : row){ 9 | normalizeRows += (val == row[0]) ? '0' : '1'; 10 | } 11 | rowCount[normalizeRows]++; 12 | maxRows = max(maxRows , rowCount[normalizeRows]); 13 | } 14 | return maxRows; 15 | } 16 | }; -------------------------------------------------------------------------------- /1218-lowest-common-ancestor-of-deepest-leaves/1218-lowest-common-ancestor-of-deepest-leaves.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * struct TreeNode { 4 | * int val; 5 | * TreeNode *left; 6 | * TreeNode *right; 7 | * TreeNode() : val(0), left(nullptr), right(nullptr) {} 8 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} 9 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} 10 | * }; 11 | */ 12 | class Solution { 13 | public: 14 | pair dfs(TreeNode* root) { 15 | if (!root) { 16 | return {nullptr, 0}; 17 | } 18 | 19 | auto left = dfs(root->left); 20 | auto right = dfs(root->right); 21 | 22 | if (left.second > right.second) { 23 | return {left.first, left.second + 1}; 24 | } 25 | if (left.second < right.second) { 26 | return {right.first, right.second + 1}; 27 | } 28 | return {root, left.second + 1}; 29 | } 30 | 31 | TreeNode* lcaDeepestLeaves(TreeNode* root) { return dfs(root).first; } 32 | }; -------------------------------------------------------------------------------- /1250-longest-common-subsequence/1250-longest-common-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestCommonSubsequence(string t1, string t2) { 4 | int n = t1.size() , m = t2.size(); 5 | vector> dp(n+1 , vector(m+1 , 0)); 6 | for(int i=1; i<=n; i++){ 7 | for(int j=1; j<=m; j++){ 8 | if(t1[i-1] == t2[j-1]) dp[i][j] = 1+dp[i-1][j-1]; 9 | else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]); 10 | } 11 | } 12 | return dp[n][m]; 13 | } 14 | }; -------------------------------------------------------------------------------- /1256-rank-transform-of-an-array/1256-rank-transform-of-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector arrayRankTransform(vector& arr) { 4 | // Store the rank for each number in arr 5 | map numToRank; 6 | vector sortedArr(arr); 7 | sort(sortedArr.begin(), sortedArr.end()); 8 | int rank = 1; 9 | for (int i = 0; i < sortedArr.size(); i++) { 10 | if (i > 0 && sortedArr[i] > sortedArr[i - 1]) { 11 | rank++; 12 | } 13 | numToRank[sortedArr[i]] = rank; 14 | } 15 | for (int i = 0; i < arr.size(); i++) { 16 | arr[i] = numToRank[arr[i]]; 17 | } 18 | return arr; 19 | } 20 | }; -------------------------------------------------------------------------------- /1293-three-consecutive-odds/1293-three-consecutive-odds.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool threeConsecutiveOdds(vector& arr) { 4 | if(arr.size() < 3) return false; 5 | for(int i=0; i1293. Three Consecutive Odds

Easy


Given an integer array arr, return true if there are three consecutive odd numbers in the array. Otherwise, return false. 2 |

 

3 |

Example 1:

4 | 5 |
 6 | Input: arr = [2,6,4,1]
 7 | Output: false
 8 | Explanation: There are no three consecutive odds.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: arr = [1,2,34,3,4,5,7,23,12]
15 | Output: true
16 | Explanation: [5,7,23] are three consecutive odds.
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= arr.length <= 1000
  • 24 |
  • 1 <= arr[i] <= 1000
  • 25 |
26 | -------------------------------------------------------------------------------- /1302-delete-characters-to-make-fancy-string/1302-delete-characters-to-make-fancy-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string makeFancyString(string s) { 4 | char prev = s[0]; 5 | int frequency = 1; 6 | string ans = ""; 7 | ans.push_back(s[0]); 8 | 9 | for (int i = 1; i < s.size(); i++) { 10 | if (s[i] == prev) { 11 | frequency++; 12 | } else { 13 | prev = s[i]; 14 | frequency = 1; 15 | } 16 | 17 | if (frequency < 3) ans.push_back(s[i]); 18 | } 19 | 20 | return ans; 21 | } 22 | }; -------------------------------------------------------------------------------- /1325-path-with-maximum-probability/1325-path-with-maximum-probability.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double maxProbability(int n, vector>& edges, vector& succProb, int start, int end) { 4 | vector maxProb(n); 5 | maxProb[start] = 1.0; 6 | for(int i=0; i maxProb[v]){ 13 | maxProb[v] = maxProb[u] * pathProb; 14 | hasUpdate = true; 15 | } 16 | if(maxProb[v] * pathProb > maxProb[u]){ 17 | maxProb[u] = maxProb[v] * pathProb; 18 | hasUpdate = true; 19 | } 20 | } 21 | if(!hasUpdate) break; 22 | } 23 | return maxProb[end]; 24 | } 25 | }; -------------------------------------------------------------------------------- /1335-maximum-candies-allocated-to-k-children/1335-maximum-candies-allocated-to-k-children.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPossible(vector& candies , long long k , long long target){ 4 | if(target == 0) return true; 5 | long long piles = 0; 6 | for(auto c : candies){ 7 | piles+= c/target; 8 | } 9 | return piles>=k; 10 | } 11 | int maximumCandies(vector& candies, long long k) { 12 | int n = candies.size(); 13 | long long maxi = 0; 14 | for(auto c : candies){ 15 | maxi = max(maxi , (long long)c); 16 | } 17 | long long left = 0 ,right = maxi; 18 | while(left < right){ 19 | long long mid = left + (right-left+1)/2; 20 | if(isPossible(candies , k , mid)){ 21 | left = mid; 22 | } 23 | else{ 24 | right = mid-1; 25 | } 26 | } 27 | return left; 28 | } 29 | }; -------------------------------------------------------------------------------- /1350-remove-sub-folders-from-the-filesystem/1350-remove-sub-folders-from-the-filesystem.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector removeSubfolders(vector& folder) { 4 | sort(folder.begin() , folder.end()); 5 | string prev = ""; 6 | vector res; 7 | for(auto f : folder){ 8 | if(prev.empty() || f.find(prev + '/')){ 9 | res.push_back(f); 10 | prev = f; 11 | } 12 | } 13 | return res; 14 | } 15 | }; -------------------------------------------------------------------------------- /1396-count-servers-that-communicate/1396-count-servers-that-communicate.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countServers(vector>& grid) { 4 | int m = grid.size() , n = grid[0].size() , cnt = 0; 5 | vector rowCnt(m , 0); 6 | vector colCnt(n , 0); 7 | for(int i=0; i 1 || colCnt[j] > 1)) cnt++; 18 | } 19 | } 20 | return cnt; 21 | } 22 | }; -------------------------------------------------------------------------------- /1407-group-the-people-given-the-group-size-they-belong-to/1407-group-the-people-given-the-group-size-they-belong-to.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> groupThePeople(vector& groupSizes) { 4 | // in given arr = [3,3,3,3,3,1,3] you see one thing the idces first we give 3 comes in index = [0,1,2,3,4,6] , and 1 comes in index = [5] ok lets go with first 3 total len of the array which these indices have 6/3 = 2 ok [0,1,2] and [3,4,6] for 1 its 1/1 = 1 so [5] we retun those arr ok. 5 | int n = groupSizes.size(); 6 | vector> res; 7 | unordered_map> mp; 8 | for(int i=0; i& nums) { 4 | int n = nums.size(); 5 | int res = 0; 6 | for(auto num : nums){ 7 | int cnt = 0; 8 | if(num == 0) cnt = 1; 9 | else{ 10 | while(num > 0){ 11 | cnt++; 12 | num /= 10; 13 | } 14 | } 15 | if(cnt % 2 == 0) res++; 16 | } 17 | return res; 18 | } 19 | }; -------------------------------------------------------------------------------- /1435-xor-queries-of-a-subarray/1435-xor-queries-of-a-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector xorQueries(vector& arr, vector>& queries) { 4 | vector result; 5 | // Process each query 6 | for (const auto& q : queries) { 7 | int xorSum = 0; 8 | // Calculate XOR for the range [q[0], q[1]] 9 | for (int i = q[0]; i <= q[1]; i++) { 10 | xorSum ^= arr[i]; 11 | } 12 | result.push_back(xorSum); 13 | } 14 | return result; 15 | } 16 | }; -------------------------------------------------------------------------------- /1460-number-of-substrings-containing-all-three-characters/1460-number-of-substrings-containing-all-three-characters.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfSubstrings(string s) { 4 | // now we want to find the sub strings containg al 3 chars ok we means we need to find usbstrs using sliding window means using 2 pointer and ahsh tbale to freq in each substr we maintin only 1 atleast a bc in sub str we iterate through a str and fund the freq first and then use sliding window to ierate and fund the substr contain these things or not 5 | int n = s.size() , i = 0; 6 | vector cnt(3 , 0); 7 | int res = 0; 8 | for(int j = 0; j 0 && cnt[1] > 0 && cnt[2] > 0){ 11 | res += n - j; 12 | cnt[s[i] - 'a']--; 13 | i++; 14 | } 15 | } 16 | return res; 17 | } 18 | }; -------------------------------------------------------------------------------- /1468-check-if-n-and-its-double-exist/1468-check-if-n-and-its-double-exist.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkIfExist(vector& arr) { 4 | for(int i=0;i luckyNumbers (vector>& matrix) { 4 | int N = matrix.size(), M = matrix[0].size(); 5 | 6 | int rMinMax = INT_MIN; 7 | for (int i = 0; i < N; i++) { 8 | 9 | int rMin = INT_MAX; 10 | for (int j = 0; j < M; j++) { 11 | rMin = min(rMin, matrix[i][j]); 12 | } 13 | rMinMax = max(rMinMax, rMin); 14 | } 15 | 16 | int cMaxMin = INT_MAX; 17 | for (int i = 0; i < M; i++) { 18 | 19 | int cMax = INT_MIN; 20 | for (int j = 0; j < N; j++) { 21 | cMax = max(cMax, matrix[j][i]); 22 | } 23 | cMaxMin = min(cMaxMin, cMax); 24 | } 25 | 26 | if (rMinMax == cMaxMin) { 27 | return {rMinMax}; 28 | } 29 | 30 | return {}; 31 | } 32 | }; -------------------------------------------------------------------------------- /1497-design-a-stack-with-increment-operation/1497-design-a-stack-with-increment-operation.cpp: -------------------------------------------------------------------------------- 1 | class CustomStack { 2 | public: 3 | stack stk; 4 | vector inc; 5 | int maxSize; 6 | CustomStack(int maxSize): maxSize(maxSize) { 7 | inc.resize(maxSize); 8 | } 9 | void push(int x) { 10 | if(stk.size() < maxSize) stk.push(x); 11 | } 12 | 13 | int pop() { 14 | if(stk.empty()) return -1; 15 | int idx = stk.size() - 1; 16 | int res= stk.top() + inc[idx]; 17 | stk.pop(); 18 | if(idx > 0){ 19 | inc[idx - 1] += inc[idx]; 20 | } 21 | inc[idx] = 0; 22 | return res; 23 | } 24 | 25 | void increment(int k, int val) { 26 | int limit = std::min(k, (int)stk.size()); 27 | if (limit > 0) { 28 | inc[limit - 1] += val; 29 | } 30 | } 31 | }; 32 | 33 | /** 34 | * Your CustomStack object will be instantiated and called as such: 35 | * CustomStack* obj = new CustomStack(maxSize); 36 | * obj->push(x); 37 | * int param_2 = obj->pop(); 38 | * obj->increment(k,val); 39 | */ -------------------------------------------------------------------------------- /1500-count-largest-group/1500-count-largest-group.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countLargestGroup(int n) { 4 | unordered_map mp; 5 | for(int i=1; i<=n; i++){ 6 | int num = i; 7 | int sum = 0; 8 | while(num > 0){ 9 | sum += num%10; 10 | num /= 10; 11 | } 12 | mp[sum]++; 13 | } 14 | int maxFreq = 0; 15 | for(auto it : mp){ 16 | maxFreq = max(maxFreq , it.second); 17 | } 18 | int cnt = 0; 19 | for(auto it : mp){ 20 | if(maxFreq == it.second) cnt++; 21 | } 22 | return cnt; 23 | } 24 | }; -------------------------------------------------------------------------------- /1502-construct-k-palindrome-strings/1502-construct-k-palindrome-strings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canConstruct(string s, int k) { 4 | // given s and an k return truw use all char in s to constrcu k palindorme so waht si the simple apporoach frsit chekc if string constrcut palindrome if ues count if its qual to k or greater than return true else false for plaindrome check we use manacher if not simpler isPalindrome and hash table to check it ok fuction to check substrings and cnt it if greater than k return it we check only odd count ok not need to check palindrome ok 5 | if(s.size() < k) return false; 6 | vector f(26 , 0); 7 | int oddCnt = 0; 8 | for(auto c : s) f[c-'a']++; 9 | for(auto cnt : f){ 10 | if(cnt % 2 != 0) oddCnt++; 11 | } 12 | return oddCnt <= k; 13 | } 14 | }; -------------------------------------------------------------------------------- /1508-longest-happy-prefix/1508-longest-happy-prefix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string longestPrefix(string s) { 4 | int n = s.size(); 5 | int p = 0; 6 | vector lps(n , 0); 7 | for(int i = 1; i < n; i++) { 8 | while(p > 0 && s[i] != s[p]) 9 | p = lps[p - 1]; 10 | if(s[i] == s[p]) 11 | p++; 12 | lps[i] = p; 13 | } 14 | return s.substr(0, p); 15 | } 16 | }; -------------------------------------------------------------------------------- /1537-maximum-score-after-splitting-a-string/1537-maximum-score-after-splitting-a-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxScore(string s) { 4 | int ones = 0 , zeros = 0 , best = INT_MIN; 5 | for(int i=0; i 2 | #include 3 | 4 | class Solution { 5 | public: 6 | bool canBeEqual(std::vector& target, std::vector& arr) { 7 | if (target.size() != arr.size()) return false; 8 | std::sort(target.begin(), target.end()); 9 | std::sort(arr.begin(), arr.end()); 10 | return target == arr; 11 | } 12 | }; -------------------------------------------------------------------------------- /1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int isPrefixOfWord(string s, string w) { 4 | int c = 0, curWord = 1; 5 | for (int i = 0; i < s.size(); ++i){ 6 | if (c != -1 && s[i] == w[c]) ++c; 7 | else if (s[i] == ' ') c = 0, ++curWord; 8 | else c = -1; 9 | if (c == w.size()) return curWord; 10 | } 11 | return -1; 12 | } 13 | }; -------------------------------------------------------------------------------- /1570-final-prices-with-a-special-discount-in-a-shop/1570-final-prices-with-a-special-discount-in-a-shop.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector finalPrices(vector& prices) { 4 | int n = prices.size(); 5 | vector res(prices); 6 | stack st; 7 | for(int i=0; i= prices[i]){ 9 | res[st.top()] -= prices[i]; 10 | st.pop(); 11 | } 12 | st.push(i); 13 | } 14 | return res; 15 | } 16 | }; -------------------------------------------------------------------------------- /1616-minimum-difference-between-largest-and-smallest-value-in-three-moves/1616-minimum-difference-between-largest-and-smallest-value-in-three-moves.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minDifference(vector& nums) { 4 | int numsSize = nums.size(); 5 | 6 | // If the array has 4 or fewer elements, return 0 7 | if (numsSize <= 4) return 0; 8 | 9 | sort(nums.begin(), nums.end()); 10 | 11 | int minDiff = INT_MAX; 12 | 13 | // Four scenarios to compute the minimum difference 14 | for (int left = 0, right = numsSize - 4; left < 4; left++, right++) { 15 | minDiff = min(minDiff, nums[right] - nums[left]); 16 | } 17 | 18 | return minDiff; 19 | } 20 | }; -------------------------------------------------------------------------------- /1620-check-if-array-pairs-are-divisible-by-k/1620-check-if-array-pairs-are-divisible-by-k.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canArrange(vector& arr, int k) { 4 | unordered_map mp; 5 | for(auto a : arr) mp[(a%k + k) % k]++; 6 | for(auto a : arr){ 7 | int rem = (a%k+ k) % k; 8 | if(rem == 0){ 9 | if(mp[rem] % 2 == 1) return false; 10 | } 11 | else if(mp[rem] != mp[k-rem]) return false; 12 | 13 | } 14 | return true; 15 | } 16 | }; -------------------------------------------------------------------------------- /1631-number-of-sub-arrays-with-odd-sum/1631-number-of-sub-arrays-with-odd-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numOfSubarrays(vector& arr) { 4 | // we for sum w use prefix sum ok only one thing that mf works so what we do now we want to create prefix sum using odd and even concept ok 5 | const int MOD = 1e9+7; 6 | int odd = 0 ,even = 1; 7 | int pre = 0, res = 0; 8 | for(auto i : arr){ 9 | pre +=i; 10 | if(pre % 2 == 0){ 11 | res = (res + odd) % MOD; 12 | even++; 13 | } 14 | else{ 15 | res = (res + even) % MOD; 16 | odd++; 17 | } 18 | } 19 | return res; 20 | } 21 | }; -------------------------------------------------------------------------------- /1642-water-bottles/1642-water-bottles.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numWaterBottles(int numBottles, int numExchange) { 4 | int consumedBottles = 0; 5 | 6 | while (numBottles >= numExchange) { 7 | // Maximum number of times we can consume numExchange 8 | // number of bottles using numBottles. 9 | int K = numBottles / numExchange; 10 | 11 | consumedBottles += numExchange * K; 12 | numBottles -= numExchange * K; 13 | 14 | numBottles += K; 15 | } 16 | 17 | return consumedBottles + numBottles; 18 | } 19 | }; -------------------------------------------------------------------------------- /1656-count-good-triplets/1656-count-good-triplets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countGoodTriplets(vector& arr, int a, int b, int c) { 4 | int res = 0, n = arr.size(); 5 | for (int i = 0; i < n - 2; i++) { 6 | for (int j = i + 1; j < n - 1; j++) { 7 | if (abs(arr[i] - arr[j]) <= a) { 8 | for (int k = j + 1; k < n; k++) { 9 | if (abs(arr[j] - arr[k]) <= b && 10 | abs(arr[i] - arr[k]) <= c) { 11 | res++; 12 | } 13 | } 14 | } 15 | } 16 | } 17 | return res; 18 | } 19 | }; -------------------------------------------------------------------------------- /1667-find-kth-bit-in-nth-binary-string/1667-find-kth-bit-in-nth-binary-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | char findKthBit(int n, int k) { 4 | // Base case: for S1, return '0' 5 | if (n == 1) return '0'; 6 | 7 | // Calculate the length of Sn 8 | int len = 1 << n; // Equivalent to 2^n 9 | 10 | // If k is in the first half of the string, recurse with n-1 11 | if (k < len / 2) { 12 | return findKthBit(n - 1, k); 13 | } 14 | // If k is exactly in the middle, return '1' 15 | else if (k == len / 2) { 16 | return '1'; 17 | } 18 | // If k is in the second half of the string 19 | else { 20 | // Find the corresponding bit in the first half and invert it 21 | char correspondingBit = findKthBit(n - 1, len - k); 22 | return (correspondingBit == '0') ? '1' : '0'; 23 | } 24 | } 25 | }; -------------------------------------------------------------------------------- /1679-shortest-subarray-to-be-removed-to-make-array-sorted/1679-shortest-subarray-to-be-removed-to-make-array-sorted.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findLengthOfShortestSubarray(vector& arr) { 4 | int n = arr.size(); 5 | int left =0 , right = n-1; 6 | while(left < n-1 && arr[left] <= arr[left+1]) left++; 7 | if(left == n-1) return 0; 8 | while(right > 0 && arr[right] >= arr[right-1]) right--; 9 | int res = min(n-left-1 , right); 10 | int i=0 ,j = right; 11 | while(i<=left && j& nums, int p) { 4 | int n = nums.size(); 5 | int totalSum = 0; 6 | for(auto num : nums){ 7 | totalSum = (totalSum + num) % p; 8 | } 9 | if(totalSum == 0) return 0; 10 | unordered_map mp; 11 | mp[0] = -1; 12 | int prefixSum = 0 , minLen = n; 13 | for(int i=0; i 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector> restoreMatrix(vector& rowSum, vector& colSum) { 8 | int n = rowSum.size(); 9 | int m = colSum.size(); 10 | vector> res(n, vector(m, 0)); 11 | for(int i = 0; i < n; i++) { 12 | for(int j = 0; j < m; j++) { 13 | int mini = min(rowSum[i], colSum[j]); 14 | res[i][j] = mini; 15 | rowSum[i] -= mini; 16 | colSum[j] -= mini; 17 | } 18 | } 19 | return res; 20 | } 21 | }; -------------------------------------------------------------------------------- /1715-split-a-string-into-the-max-number-of-unique-substrings/1715-split-a-string-into-the-max-number-of-unique-substrings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxUniqueSplit(string s) { 4 | unordered_set st; 5 | return helper(s , 0 , st ); 6 | } 7 | int helper(string &s , int start , unordered_set &st){ 8 | if(start == s.size()){ 9 | return st.size(); 10 | } 11 | int cnt = 0; 12 | for(int i=start+1 ; i<=s.size(); i++){ 13 | string sub = s.substr(start , i - start); 14 | if(st.find(sub) == st.end()){ 15 | st.insert(sub); 16 | cnt = max(cnt , helper(s , i , st)); 17 | st.erase(sub); 18 | } 19 | } 20 | return cnt; 21 | } 22 | }; -------------------------------------------------------------------------------- /1720-crawler-log-folder/1720-crawler-log-folder.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minOperations(vector& logs) { 4 | stack folderStack; 5 | 6 | for (const string& currentOperation : logs) { 7 | if (currentOperation == "../") { 8 | // Move up to parent directory if not already at main folder 9 | if (!folderStack.empty()) { 10 | folderStack.pop(); 11 | } 12 | } else if (currentOperation != "./") { 13 | // Enter a new folder 14 | folderStack.push(currentOperation); 15 | } 16 | // Ignore "./" operations as they don't change the current folder 17 | } 18 | 19 | // The stack size represents the number of folders deep we are 20 | return folderStack.size(); 21 | } 22 | }; -------------------------------------------------------------------------------- /1741-sort-array-by-increasing-frequency/1741-sort-array-by-increasing-frequency.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector frequencySort(vector& nums) { 4 | unordered_map freq; 5 | for (int num : nums) { 6 | freq[num]++; 7 | } 8 | 9 | sort(nums.begin(), nums.end(), [&](int a, int b) { 10 | if (freq[a] == freq[b]) { 11 | return a > b; 12 | } 13 | return freq[a] < freq[b]; 14 | }); 15 | 16 | return nums; 17 | } 18 | }; -------------------------------------------------------------------------------- /1744-number-of-ways-to-form-a-target-string-given-a-dictionary/1744-number-of-ways-to-form-a-target-string-given-a-dictionary.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numWays(vector& words, string target) { 4 | const int alpha = 26 ; 5 | const int mod = 1000000007; 6 | int m = target.size() , k = words[0].size(); 7 | vector cnt(alpha , vector(k)); 8 | for(int j=0; j(k + 1)); 14 | dp[0][0] = 1; 15 | for (int i = 0; i <= m; i++) { 16 | for (int j = 0; j < k; j++) { 17 | if (i < m) { 18 | (dp[i + 1][j + 1] += cnt[target[i] - 'a'][j] * dp[i][j]) %= mod; 19 | } 20 | (dp[i][j + 1] += dp[i][j]) %= mod; 21 | } 22 | } 23 | return dp[m][k]; 24 | } 25 | }; -------------------------------------------------------------------------------- /1755-defuse-the-bomb/1755-defuse-the-bomb.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector decrypt(vector& code, int k) { 4 | vector result(code.size(), 0); 5 | if (k == 0) return result; 6 | // Define the initial window and initial sum 7 | int start = 1, end = k, sum = 0; 8 | // If k < 0, the starting point will be end of the array. 9 | if (k < 0) { 10 | start = code.size() - abs(k); 11 | end = code.size() - 1; 12 | } 13 | for (int i = start; i <= end; i++) sum += code[i]; 14 | // Scan through the code array as i moving to the right, update the 15 | // window sum. 16 | for (int i = 0; i < code.size(); i++) { 17 | result[i] = sum; 18 | sum -= code[start % code.size()]; 19 | sum += code[(end + 1) % code.size()]; 20 | start++; 21 | end++; 22 | } 23 | return result; 24 | } 25 | }; -------------------------------------------------------------------------------- /1786-count-the-number-of-consistent-strings/1786-count-the-number-of-consistent-strings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countConsistentStrings(string allowed, vector& words) { 4 | int cnt = 0; 5 | unordered_set set(allowed.begin() , allowed.end()); 6 | for(auto word : words){ 7 | bool isConsis = true; 8 | for(auto ch : word){ 9 | if(set.find(ch) == set.end()){ 10 | isConsis = false; 11 | break; 12 | } 13 | } 14 | if(isConsis) cnt++; 15 | } 16 | return cnt; 17 | } 18 | }; -------------------------------------------------------------------------------- /1803-average-waiting-time/1803-average-waiting-time.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | double averageWaitingTime(vector>& customers) { 7 | long long totalWaitingTime = 0; // Use long long to avoid overflow 8 | int currentTime = 0; // Tracks the current time 9 | 10 | for (auto& customer : customers) { 11 | int arrival = customer[0]; 12 | int time = customer[1]; 13 | 14 | // If the chef is idle or waiting for the customer, start at the customer's arrival time 15 | currentTime = max(currentTime, arrival); 16 | 17 | // Add the preparation time to the current time 18 | currentTime += time; 19 | 20 | // Calculate the waiting time for this customer 21 | totalWaitingTime += currentTime - arrival; 22 | } 23 | 24 | // Calculate the average waiting time. Cast to double for floating point division. 25 | return (double)totalWaitingTime / customers.size(); 26 | } 27 | }; -------------------------------------------------------------------------------- /1849-maximum-absolute-sum-of-any-subarray/1849-maximum-absolute-sum-of-any-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxAbsoluteSum(vector& nums) { 4 | int maxSum = INT_MIN, currMaxSum = 0 , currMinSum = 0 , minSum = INT_MAX; 5 | 6 | for (int num : nums) { 7 | currMaxSum += num; 8 | maxSum = max(maxSum, currMaxSum); 9 | if (currMaxSum < 0) currMaxSum = 0; 10 | currMinSum += num; 11 | minSum = min(minSum , currMinSum); 12 | if(currMinSum > 0) currMinSum = 0; 13 | } 14 | return max(abs(maxSum) , abs(minSum)); 15 | 16 | } 17 | }; -------------------------------------------------------------------------------- /1878-check-if-array-is-sorted-and-rotated/1878-check-if-array-is-sorted-and-rotated.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool check(vector& nums) { 4 | int n = nums.size() , dropCnt = 0; 5 | for(int i=0; i nums[(i+1)%n]) dropCnt++; 7 | if(dropCnt > 1) return false; 8 | } 9 | return true; 10 | } 11 | }; -------------------------------------------------------------------------------- /1889-check-if-number-is-a-sum-of-powers-of-three/1889-check-if-number-is-a-sum-of-powers-of-three.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkPowersOfThree(int n) { 4 | // we need to chekc if n is div by 3 or not first if it then we check that no if its is div means then waht we do we check the sum of thrii powers in distinct using the loop and check the power of 3 one by if in any time sum is equal to n then true else false ok 5 | while(n > 0){ 6 | if(n%3 == 2) return false; 7 | n /= 3; 8 | } 9 | return true; 10 | } 11 | }; -------------------------------------------------------------------------------- /1895-minimum-number-of-operations-to-move-all-balls-to-each-box/1895-minimum-number-of-operations-to-move-all-balls-to-each-box.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector minOperations(string boxes) { 4 | int n = boxes.size(); 5 | vector res(n , 0); 6 | int op = 0 , balls = 0; 7 | for(int i=0; i=0; i--){ 14 | res[i] += op; 15 | if(boxes[i] == '1') balls++; 16 | op += balls; 17 | } 18 | return res; 19 | } 20 | }; -------------------------------------------------------------------------------- /1915-check-if-one-string-swap-can-make-strings-equal/1915-check-if-one-string-swap-can-make-strings-equal.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool areAlmostEqual(string s1, string s2) { 4 | if(s1.size() != s2.size()) return false; 5 | vector diff; 6 | for(int i=0; i>& edges) { 4 | int u1 = edges[0][0], v1 = edges[0][1]; 5 | int u2 = edges[1][0], v2 = edges[1][1]; 6 | if (v1 == v2 || v1 == u2) return v1; 7 | return u1; 8 | } 9 | }; -------------------------------------------------------------------------------- /1927-maximum-ascending-subarray-sum/1927-maximum-ascending-subarray-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxAscendingSum(vector& nums) { 4 | int n = nums.size(); 5 | int maxi = nums[0] , curSum = nums[0]; 6 | for(int i=1; i nums[i-1]) curSum += nums[i]; 8 | else { 9 | maxi = max(maxi , curSum); 10 | curSum = nums[i]; 11 | } 12 | } 13 | maxi = max(maxi , curSum); 14 | return maxi; 15 | } 16 | }; -------------------------------------------------------------------------------- /1940-maximum-xor-for-each-query/1940-maximum-xor-for-each-query.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector getMaximumXor(vector& nums, int maximumBit) { 4 | int n = nums.size(); 5 | 6 | vector prefixXOR(n); 7 | prefixXOR[0] = nums[0]; 8 | 9 | for (int i = 1; i < n; i++) { 10 | prefixXOR[i] = prefixXOR[i - 1] ^ nums[i]; 11 | } 12 | 13 | vector ans(n); 14 | int mask = (1 << maximumBit) - 1; 15 | 16 | for (int i = 0; i < n; i++) { 17 | // find k to maximize value 18 | int currentXOR = prefixXOR[n - 1 - i]; 19 | ans[i] = currentXOR ^ mask; 20 | } 21 | 22 | return ans; 23 | } 24 | }; -------------------------------------------------------------------------------- /1951-find-the-winner-of-the-circular-game/1951-find-the-winner-of-the-circular-game.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findTheWinner(int n, int k) { 4 | int ans = 0; 5 | for (int i = 2; i <= n; i++) { 6 | ans = (ans + k) % i; 7 | } 8 | // add 1 to convert back to 1 indexing 9 | return ans + 1; 10 | } 11 | }; -------------------------------------------------------------------------------- /1993-sum-of-all-subset-xor-totals/1993-sum-of-all-subset-xor-totals.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int subsetXORSum(vector& nums) { 4 | return XORSum(nums, 0, 0); 5 | } 6 | 7 | private: 8 | int XORSum(vector& nums, int index, int currentXOR) { 9 | // Return currentXOR when all elements in nums are already considered 10 | if (index == nums.size()) return currentXOR; 11 | 12 | // Calculate sum of subset xor with current element 13 | int withElement = XORSum(nums, index + 1, currentXOR ^ nums[index]); 14 | 15 | // Calculate sum of subset xor without current element 16 | int withoutElement = XORSum(nums, index + 1, currentXOR); 17 | 18 | // Return sum of xor totals 19 | return withElement + withoutElement; 20 | } 21 | }; -------------------------------------------------------------------------------- /2006-find-the-student-that-will-replace-the-chalk/2006-find-the-student-that-will-replace-the-chalk.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int chalkReplacer(vector& chalk, int k) { 4 | // Find the sum of all elements. 5 | int sum = 0; 6 | for (int i = 0; i < chalk.size(); i++) { 7 | sum += chalk[i]; 8 | if (sum > k) { 9 | break; 10 | } 11 | } 12 | // Find modulo of k with sum. 13 | k = k % sum; 14 | for (int i = 0; i < chalk.size(); i++) { 15 | if (k < chalk[i]) { 16 | return i; 17 | } 18 | k = k - chalk[i]; 19 | } 20 | return 0; 21 | } 22 | }; -------------------------------------------------------------------------------- /2021-remove-all-occurrences-of-a-substring/2021-remove-all-occurrences-of-a-substring.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string removeOccurrences(string s, string part) { 4 | string res; 5 | int n = part.size(); 6 | for(auto c : s){ 7 | res.push_back(c); 8 | if(res.size() >= n && res.substr(res.size() - n) == part){ 9 | res.erase(res.size() - n , n); 10 | } 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /2048-build-array-from-permutation/2048-build-array-from-permutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector buildArray(vector& nums) { 4 | int n = nums.size(); 5 | vector res(n); 6 | for(int i=0; i0){ 10 | if(y&1) res = (res*x) % mod; 11 | y = y>>1; 12 | x = (x*x)%mod; 13 | } 14 | return res; 15 | } 16 | int countGoodNumbers(long long n) { 17 | ll count_of_4s = n/2; 18 | ll count_of_5s = n - count_of_4s; 19 | ll ans = ((power(4LL , count_of_4s) % mod * power(5LL , count_of_5s)%mod)%mod); 20 | return (int)ans; 21 | } 22 | }; -------------------------------------------------------------------------------- /2054-the-number-of-the-smallest-unoccupied-chair/2054-the-number-of-the-smallest-unoccupied-chair.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int smallestChair(vector>& times, int targetFriend) { 4 | vector targetTime = times[targetFriend]; 5 | sort(times.begin(), times.end()); 6 | 7 | int n = times.size(); 8 | vector chairTime(n); 9 | 10 | for (auto time : times) { 11 | for (int i = 0; i < n; i++) { 12 | if (chairTime[i] <= time[0]) { 13 | chairTime[i] = time[1]; 14 | if (time == targetTime) return i; 15 | break; 16 | } 17 | } 18 | } 19 | return 0; 20 | } 21 | }; -------------------------------------------------------------------------------- /2059-unique-length-3-palindromic-subsequences/2059-unique-length-3-palindromic-subsequences.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countPalindromicSubsequence(string s) { 4 | ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0); 5 | int n = s.size(); 6 | vector first(26 , -1); 7 | vector last(26 , -1); 8 | for(int i=0;i st; 16 | for(int j=first[i]+1; j 0) { 12 | int digitSum = 0; 13 | for (char digit : numericString) { 14 | digitSum += digit - '0'; 15 | } 16 | numericString = to_string(digitSum); 17 | } 18 | 19 | // Convert the final string to integer and return 20 | return stoi(numericString); 21 | } 22 | }; -------------------------------------------------------------------------------- /2089-maximum-matrix-sum/2089-maximum-matrix-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long maxMatrixSum(vector>& matrix) { 4 | long long totalSum = 0; 5 | int minAbsVal = INT_MAX; 6 | int negativeCount = 0; 7 | 8 | for (auto& row : matrix) { 9 | for (int val : row) { 10 | totalSum += abs(val); 11 | if (val < 0) { 12 | negativeCount++; 13 | } 14 | minAbsVal = min(minAbsVal, abs(val)); 15 | } 16 | } 17 | 18 | // Adjust if the count of negative numbers is odd 19 | if (negativeCount % 2 != 0) { 20 | totalSum -= 2 * minAbsVal; 21 | } 22 | 23 | return totalSum; 24 | } 25 | }; -------------------------------------------------------------------------------- /2095-minimum-number-of-swaps-to-make-the-string-balanced/2095-minimum-number-of-swaps-to-make-the-string-balanced.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minSwaps(string s) { 4 | int stackSize = 0; 5 | int n = s.size(); 6 | 7 | for (int i = 0; i < n; i++) { 8 | char ch = s[i]; 9 | // If character is opening bracket, increment the stack size. 10 | if (ch == '[') 11 | stackSize++; 12 | else { 13 | // If the character is closing bracket, and we have an opening 14 | // bracket, decrease the stack size. 15 | if (stackSize > 0) stackSize--; 16 | } 17 | } 18 | return (stackSize + 1) / 2; 19 | } 20 | }; -------------------------------------------------------------------------------- /2095-minimum-number-of-swaps-to-make-the-string-balanced/2095-minimum-number-of-swaps-to-make-the-string-balanced.rs: -------------------------------------------------------------------------------- 1 | impl Solution { 2 | pub fn min_swaps(s: String) -> i32 { 3 | let mut stack_size = 0; 4 | let n = s.len(); 5 | 6 | for ch in s.chars() { 7 | if ch == '[' { 8 | stack_size += 1; 9 | } 10 | else { 11 | if stack_size > 0 { 12 | stack_size -= 1; 13 | } 14 | } 15 | } 16 | (stack_size + 1) / 2 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /2095-minimum-number-of-swaps-to-make-the-string-balanced/2095-minimum-number-of-swaps-to-make-the-string-balanced.swift: -------------------------------------------------------------------------------- 1 | class Solution { 2 | func minSwaps(_ s: String) -> Int { 3 | var stackSize = 0; 4 | let n = s.count; 5 | 6 | for ch in s{ 7 | if ch == "["{ 8 | stackSize += 1; 9 | } else{ 10 | if stackSize > 0{ 11 | stackSize -= 1; 12 | } 13 | } 14 | } 15 | return (stackSize + 1)/2 16 | } 17 | } -------------------------------------------------------------------------------- /2107-find-unique-binary-string/2107-find-unique-binary-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string findDifferentBinaryString(vector& nums) { 4 | int n = nums.size(); 5 | string res(n , '0'); 6 | for(int i=0; i> construct2DArray(vector& original, int m, int n) { 4 | if (original.size() != m * n) { 5 | return {}; 6 | } 7 | vector> res(m , vector(n, 0)); 8 | // for(int i=0; i missingRolls(vector& rolls, int mean, int n) { 4 | int sum = 0; 5 | for (int i = 0; i < rolls.size(); i++) { 6 | sum = sum + rolls[i]; 7 | } 8 | // Find the remaining sum. 9 | int remainingSum = mean * (n + rolls.size()) - sum; 10 | // Check if sum is valid or not. 11 | if (remainingSum > 6 * n or remainingSum < n) { 12 | return {}; 13 | } 14 | int distributeMean = remainingSum / n; 15 | int mod = remainingSum % n; 16 | // Distribute the remaining mod elements in nElements array. 17 | vector nElements(n, distributeMean); 18 | for (int i = 0; i < mod; i++) { 19 | nElements[i]++; 20 | } 21 | return nElements; 22 | } 23 | }; -------------------------------------------------------------------------------- /2163-kth-distinct-string-in-an-array/2163-kth-distinct-string-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string kthDistinct(vector& arr, int k) { 4 | unordered_map mp; 5 | for(auto a : arr) mp[a]++; 6 | for(auto a : arr){ 7 | if(mp[a] == 1){ 8 | k--; 9 | if(k == 0) return a; 10 | } 11 | } 12 | return ""; 13 | } 14 | }; -------------------------------------------------------------------------------- /2164-two-best-non-overlapping-events/2164-two-best-non-overlapping-events.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxTwoEvents(vector>& events) { 4 | priority_queue, vector> , greater>> pq; 5 | sort(events.begin() , events.end()); 6 | int maxVal = 0 , maxSum = 0; 7 | for(auto e : events){ 8 | while(pq.size() && pq.top().first < e[0]){ 9 | maxVal = max(maxVal , pq.top().second); 10 | pq.pop(); 11 | } 12 | maxSum = max(maxSum , maxVal + e[2]); 13 | pq.push({e[1] , e[2]}); 14 | } 15 | return maxSum; 16 | } 17 | }; -------------------------------------------------------------------------------- /2170-count-number-of-maximum-bitwise-or-subsets/2170-count-number-of-maximum-bitwise-or-subsets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countMaxOrSubsets(vector& nums) { 4 | int maxOrValue = 0; 5 | for (int num : nums) { 6 | maxOrValue |= num; 7 | } 8 | return countSubsets(nums, 0, 0, maxOrValue); 9 | } 10 | 11 | private: 12 | int countSubsets(vector& nums, int index, int currentOr, 13 | int targetOr) { 14 | // Base case: reached the end of the array 15 | if (index == nums.size()) { 16 | return (currentOr == targetOr) ? 1 : 0; 17 | } 18 | 19 | // Don't include the current number 20 | int countWithout = countSubsets(nums, index + 1, currentOr, targetOr); 21 | 22 | // Include the current number 23 | int countWith = 24 | countSubsets(nums, index + 1, currentOr | nums[index], targetOr); 25 | 26 | // Return the sum of both cases 27 | return countWithout + countWith; 28 | } 29 | }; -------------------------------------------------------------------------------- /2188-minimized-maximum-of-products-distributed-to-any-store/2188-minimized-maximum-of-products-distributed-to-any-store.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimizedMaximum(int n, vector& quantities) { 4 | int left = 1 , right = *max_element(quantities.begin() , quantities.end()); 5 | int res = 0; 6 | while(left <= right){ 7 | int mid = left + (right - left)/2; 8 | if(isPossible(n , quantities , mid)) { 9 | res = mid; 10 | right = mid - 1; 11 | } 12 | else left = mid + 1; 13 | } 14 | return res; 15 | } 16 | private: 17 | bool isPossible(int n ,vector& quantities, int maxProduct){ 18 | int storeNeeded = 0; 19 | for(auto q : quantities){ 20 | storeNeeded += (q + maxProduct - 1) / maxProduct; 21 | } 22 | return storeNeeded<=n; 23 | } 24 | }; -------------------------------------------------------------------------------- /2215-finding-3-digit-even-numbers/2215-finding-3-digit-even-numbers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findEvenNumbers(vector& digits) { 4 | int n = digits.size(); 5 | set st; 6 | for(int i=0; i res(st.begin() , st.end()); 20 | return res; 21 | } 22 | }; -------------------------------------------------------------------------------- /2232-adding-spaces-to-a-string/2232-adding-spaces-to-a-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string addSpaces(string s, vector& spaces) { 4 | // simple iterate through a spaces and then check string s and then add space done make it optimal using the map i think is best or not i think 2 pointer woking here one pointer itrate string one is checking the spaces by spaces array i think its work 5 | int n = s.size() , m = spaces.size(); 6 | int j=0; 7 | string res; 8 | for(int i=0; i>& questions) { 4 | // gievn 0 indexed 2d int array ok questions points and brainpower ok / simple we want to perfomr the optimal approach to find the maimum points either greedy or dp in which we nned do using int skip and take we say and we move next +2 quesiton if its is that way to check we want to pass the maxi points ok 5 | int n = questions.size(); 6 | vector dp(n+1 , 0); 7 | for(int i=n-1; i>=0; i--){ 8 | int points = questions[i][0]; 9 | int brainPower = questions[i][1]; 10 | int nextIdx = min(n , i+brainPower+1); 11 | dp[i] = max(points + dp[nextIdx] , dp[i+1]); 12 | } 13 | return dp[0]; 14 | } 15 | }; -------------------------------------------------------------------------------- /2277-count-equal-and-divisible-pairs-in-an-array/2277-count-equal-and-divisible-pairs-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countPairs(vector& nums, int k) { 4 | int n = nums.size(); 5 | int res = 0; 6 | for(int i=0; i& words, string pref) { 4 | int count = 0; 5 | for (string& word : words) { 6 | count += hasPrefix(word, pref); 7 | } 8 | return count; 9 | } 10 | 11 | private: 12 | // Returns 1 if str has pref as prefix, 0 otherwise 13 | int hasPrefix(string& str, string& pref) { 14 | int itr; 15 | // Compare characters until we reach the end of either string 16 | for (itr = 0; itr < str.length() && itr < pref.length(); itr++) { 17 | if (str[itr] != pref[itr]) { 18 | return 0; // Mismatch found 19 | } 20 | } 21 | 22 | // Check if we've matched the entire prefix 23 | if (itr != pref.length()) { 24 | return 0; // str is shorter than pref 25 | } 26 | return 1; 27 | } 28 | }; -------------------------------------------------------------------------------- /2299-merge-nodes-in-between-zeros/2299-merge-nodes-in-between-zeros.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 mergeNodes(ListNode head) { 13 | ListNode dummy = new ListNode(0); 14 | ListNode tail = dummy; 15 | ListNode curr = head.next; 16 | int sum = 0; 17 | while(curr != null){ 18 | if(curr.val != 0) sum += curr.val; 19 | else{ 20 | tail.next = new ListNode(sum); 21 | tail = tail.next; 22 | sum = 0; 23 | } 24 | curr = curr.next; 25 | } 26 | return dummy.next; 27 | } 28 | } -------------------------------------------------------------------------------- /2308-divide-array-into-equal-pairs/2308-divide-array-into-equal-pairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool divideArray(vector& nums) { 4 | int n = nums.size(); 5 | // nums consisting of 2 * n integers 6 | unordered_map mp; 7 | for(auto n : nums) mp[n]++; 8 | for(auto it : mp){ 9 | if(it.second % 2 != 0) return false; 10 | } 11 | return true; 12 | // if(n/2 % 2 != 0) return true; 13 | // else return false; 14 | } 15 | }; -------------------------------------------------------------------------------- /2323-minimum-bit-flips-to-convert-number/2323-minimum-bit-flips-to-convert-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minBitFlips(int start, int goal) { 4 | // XOR start and goal to find differing bits 5 | int xorResult = start ^ goal; 6 | 7 | // Count the number of set bits (1s) in xorResult 8 | int count = 0; 9 | while (xorResult > 0) { 10 | count += xorResult & 1; // Increment count if the least significant bit is 1 11 | xorResult >>= 1; // Right shift to check the next bit 12 | } 13 | 14 | return count; 15 | } 16 | }; -------------------------------------------------------------------------------- /2356-largest-combination-with-bitwise-and-greater-than-zero/2356-largest-combination-with-bitwise-and-greater-than-zero.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestCombination(vector& candidates) { 4 | vector bitCount(32 , 0); 5 | for(auto num : candidates){ 6 | for(int i=0; i<32; i++){ 7 | if(num & (1<& nums) { 4 | // arr of nums we valid split at idx i sum of first i +1 is >= sum of last n - i -1 ele and atleast 1 ele to the right of i retunr no of valid splits in nums this one simple we use prefix we create an vector pre and in for loop tkae pre[i+1] for += pre[i] and itearte nums and split fomr starting then check the sum ok in prefix sum ok 5 | int n = nums.size() , cnt = 0; 6 | vector pre(n+1 , 0); 7 | for(int i=0; i= rSum) cnt++; 11 | } 12 | return cnt; 13 | } 14 | }; -------------------------------------------------------------------------------- /2448-count-number-of-bad-pairs/2448-count-number-of-bad-pairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long countBadPairs(vector& nums) { 4 | // just a simple problme using the hasmap ohw we nned to pair for indices and nums ok and accrding to that we use pair of indices and numss if mp.find != mp.end means we go the contions accrding to we check first iterate through indices in pair like 0 1 and we j - i != nums[j] - nums[i]. only if i < j and then cnt it and return and we are done ok 5 | unordered_map diffCnt; 6 | long long totalPair = 0 , goodPair = 0; 7 | for(int i=0; i st; 8 | for(int i=0; i<=n; i++){ 9 | st.push(cnt++); 10 | if(i == n || pattern[i] == 'I'){ 11 | while(!st.empty()){ 12 | res += to_string(st.top()); 13 | st.pop(); 14 | } 15 | } 16 | } 17 | return res; 18 | } 19 | }; -------------------------------------------------------------------------------- /2463-minimum-recolors-to-get-k-consecutive-black-blocks/2463-minimum-recolors-to-get-k-consecutive-black-blocks.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumRecolors(string blocks, int k) { 4 | //acc to question k we need to check that in we need to check len of str ok k and then in that we nned return min op to convert W to B string ok simple 5 | int n = blocks.size(); 6 | int whiteCount = 0; 7 | for(int i=0; i& nums) { 4 | // given 0 ind arr nums consisting +ve int choose i and j , such i != j 5 | // now we use the hasp map herre to check the pair and use mp.find and check through end with num to nums end if yes we return the max val of that ok 6 | unordered_mapmp; 7 | int maxSum = -1; 8 | auto digitSum = [](int num){ 9 | int sum = 0; 10 | while(num > 0){ 11 | sum += num%10; 12 | num /= 10; 13 | } 14 | return sum; 15 | }; 16 | for(auto num : nums){ 17 | int digNum = digitSum(num); 18 | if(mp.find(digNum) != mp.end()){ 19 | maxSum = max(maxSum , mp[digNum] + num); 20 | } 21 | mp[digNum] = max(mp[digNum] , num); 22 | } 23 | return maxSum; 24 | } 25 | }; -------------------------------------------------------------------------------- /2478-longest-nice-subarray/2478-longest-nice-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestNiceSubarray(vector& nums) { 4 | int n = nums.size(); 5 | int left = 0 , maxLen = 1 , usedBits = 0; 6 | for(int right = 0; right < n ; right++){ 7 | while(usedBits & nums[right]){ 8 | usedBits ^= nums[left]; 9 | left++; 10 | } 11 | usedBits |= nums[right]; 12 | maxLen = max(maxLen , right-left+1); 13 | } 14 | return maxLen; 15 | } 16 | }; -------------------------------------------------------------------------------- /2502-sort-the-people/2502-sort-the-people.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include // For std::sort 4 | 5 | class Solution { 6 | public: 7 | vector sortPeople(vector& names, vector& heights) { 8 | int n = names.size(); 9 | vector> heightNamePairs; 10 | 11 | // Pair each height with the corresponding name 12 | for (int i = 0; i < n; ++i) { 13 | heightNamePairs.push_back({heights[i], names[i]}); 14 | } 15 | 16 | // Sort the pairs in descending order of height 17 | sort(heightNamePairs.begin(), heightNamePairs.end(), [](const pair& a, const pair& b) { 18 | return a.first > b.first; // Descending order 19 | }); 20 | 21 | // Extract the names from the sorted pairs 22 | vector sortedNames; 23 | for (auto& pair : heightNamePairs) { 24 | sortedNames.push_back(pair.second); 25 | } 26 | 27 | return sortedNames; 28 | } 29 | }; -------------------------------------------------------------------------------- /2503-longest-subarray-with-maximum-bitwise-and/2503-longest-subarray-with-maximum-bitwise-and.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int longestSubarray(std::vector& arr) { 7 | if (arr.empty()) return 0; // Handle empty array case 8 | 9 | // Find the maximum element 10 | int maxElement = *std::max_element(arr.begin(), arr.end()); 11 | 12 | // Find the longest contiguous subarray of the maximum element 13 | int maxLength = 0; 14 | int currentLength = 0; 15 | 16 | for (int num : arr) { 17 | if (num == maxElement) { 18 | currentLength++; 19 | maxLength = std::max(maxLength, currentLength); 20 | } else { 21 | currentLength = 0; 22 | } 23 | } 24 | 25 | return maxLength; 26 | } 27 | }; -------------------------------------------------------------------------------- /2509-minimize-xor/2509-minimize-xor.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimizeXor(int num1, int num2) { 4 | // we nned to first convert num1 and num2 in binary and then check the xor operation between an int which xor operation is minimal ok means that int xor with num1 and same set bits in nums2 ok done we convert first and find and check xor and saem set bits as num2 ok done 5 | int setN2 = cntBits(num2); 6 | int setN1 = cntBits(num1); 7 | 8 | if(setN1 > setN2) return reduce(num1 , setN2); 9 | else if(setN1 < setN2) return inc(num1 , setN2); 10 | else return num1; 11 | } 12 | int cntBits(int num){ 13 | return bitset<32>(num).count(); 14 | } 15 | int reduce(int num , int target){ 16 | for(int i=0; i<32 && cntBits(num) > target; i++){ 17 | if(num & (1<< i)) num &= ~(1< applyOperations(vector& nums) { 4 | int n = nums.size(); 5 | int writeIndex = 0; // Pointer to place non-zero elements 6 | 7 | for (int index = 0; index < n; index++) { 8 | // Step 1: Merge adjacent equal elements if they are non-zero 9 | if (index < n - 1 && nums[index] == nums[index + 1] && 10 | nums[index] != 0) { 11 | nums[index] *= 2; 12 | nums[index + 1] = 0; 13 | } 14 | 15 | // Step 2: Shift non-zero elements to the front 16 | if (nums[index] != 0) { 17 | if (index != writeIndex) { 18 | swap(nums[index], nums[writeIndex]); 19 | } 20 | writeIndex++; 21 | } 22 | } 23 | 24 | return nums; 25 | } 26 | }; -------------------------------------------------------------------------------- /2552-maximum-sum-of-distinct-subarrays-with-length-k/2552-maximum-sum-of-distinct-subarrays-with-length-k.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long maximumSubarraySum(vector& nums, int k) { 4 | unordered_set st; 5 | long long currSum = 0 , maxSum = 0; 6 | int i = 0; 7 | for(int j=0; j k){ 16 | st.erase(nums[i]); 17 | currSum -= nums[i]; 18 | i++; 19 | } 20 | if(j-i+1 == k) maxSum = max(maxSum , currSum); 21 | } 22 | return maxSum; 23 | } 24 | }; -------------------------------------------------------------------------------- /2562-count-ways-to-build-good-strings/2562-count-ways-to-build-good-strings.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countGoodStrings(int low, int high, int zero, int one) { 4 | vector dp(1+high); 5 | dp[0] = 1; 6 | int ans = 0 , mod = 1e9+7; 7 | for(int i=0; i<=high; i++){ 8 | if(i>=zero) dp[i] = (dp[i] + dp[i-zero]) % mod; 9 | if(i>=one) dp[i] = (dp[i] + dp[i-one]) % mod; 10 | if(i>=low) ans = (ans + dp[i]) % mod; 11 | } 12 | return ans; 13 | } 14 | }; -------------------------------------------------------------------------------- /2580-circular-sentence/2580-circular-sentence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isCircularSentence(string sentence) { 4 | // Use the split function to store the words in a vector. 5 | stringstream ss(sentence); 6 | string word; 7 | vector words; 8 | while (ss >> word) { 9 | words.push_back(word); 10 | } 11 | int n = words.size(); 12 | 13 | // Start comparing from the last character of the last word. 14 | char last = words[n - 1].back(); 15 | 16 | for (int i = 0; i < n; i++) { 17 | // If this character is not equal to the first character of current 18 | // word, return false. 19 | if (words[i].front() != last) return false; 20 | last = words[i].back(); 21 | } 22 | 23 | return true; 24 | } 25 | }; -------------------------------------------------------------------------------- /2581-divide-players-into-teams-of-equal-skill/2581-divide-players-into-teams-of-equal-skill.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long dividePlayers(vector& skill) { 4 | sort(skill.begin(), skill.end()); 5 | 6 | int n = skill.size(); 7 | long long totalChemistry = 0; 8 | 9 | // Calculate the target sum 10 | int targetTeamSkill = skill[0] + skill[n - 1]; 11 | 12 | // Iterate through half of the array, pairing players from both ends 13 | for (int i = 0; i < n / 2; i++) { 14 | int currentTeamSkill = skill[i] + skill[n - i - 1]; 15 | 16 | // If any team's skill doesn't match the target, return -1 17 | if (currentTeamSkill != targetTeamSkill) { 18 | return -1; 19 | } 20 | 21 | // Calculate and add the chemistry of the current team 22 | totalChemistry += (long long)skill[i] * (long long)skill[n - i - 1]; 23 | } 24 | 25 | return totalChemistry; 26 | } 27 | }; -------------------------------------------------------------------------------- /2599-take-k-of-each-character-from-left-and-right/2599-take-k-of-each-character-from-left-and-right.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int takeCharacters(string s, int k) { 4 | vector cnt(3 , 0); 5 | for(auto c:s) cnt[c-'a']++; 6 | if(cnt[0] < k || cnt[1] < k || cnt[2] < k ) return -1; 7 | int n = s.size(); 8 | int maxLen = 0; 9 | int left = 0; 10 | vector mp(3 , 0); 11 | for(int right = 0; right cnt[0] - k || mp[1] > cnt[1] - k || mp[2] > cnt[2] - k){ 14 | mp[s[left] - 'a']--; 15 | left++; 16 | } 17 | maxLen = max(maxLen , right-left+1); 18 | } 19 | return n-maxLen;; 20 | } 21 | }; -------------------------------------------------------------------------------- /2614-maximum-count-of-positive-integer-and-negative-integer/2614-maximum-count-of-positive-integer-and-negative-integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumCount(vector& nums) { 4 | int n = nums.size(); 5 | int cnt1=0 , cnt2=0; 6 | for(int i=0; i 0) cnt1++; 8 | if(nums[i] < 0) cnt2++; 9 | } 10 | return max(cnt1 , cnt2); 11 | } 12 | }; -------------------------------------------------------------------------------- /2616-maximal-score-after-applying-k-operations/2616-maximal-score-after-applying-k-operations.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long maxKelements(vector& nums, int k) { 4 | priority_queue pq(nums.begin() , nums.end()); 5 | long long score = 0; 6 | while(k>0 && !pq.empty()){ 7 | int maxEle = pq.top(); 8 | pq.pop(); 9 | score += maxEle; 10 | int newEle = ceil(maxEle / 3.0); 11 | pq.push(newEle); 12 | k--; 13 | } 14 | return score; 15 | } 16 | }; -------------------------------------------------------------------------------- /2626-count-the-number-of-good-subarrays/2626-count-the-number-of-good-subarrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long countGood(vector& nums, int k) { 4 | long long res = 0 , pairs = 0; 5 | unordered_map mp; 6 | int n = nums.size() , left = 0; 7 | for(int right=0; right = k && left < right){ 11 | res += n-right; 12 | mp[nums[left]]--; 13 | pairs -= mp[nums[left]]; 14 | left++; 15 | } 16 | 17 | } 18 | return res; 19 | } 20 | }; -------------------------------------------------------------------------------- /2640-maximum-number-of-integers-to-choose-from-a-range-i/2640-maximum-number-of-integers-to-choose-from-a-range-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxCount(vector& banned, int n, int maxSum) { 4 | // banned array 2 intgers n and max sum chosse int b/w 1 to n ok each integer atmost once ok duplicate not allowed choose int ok not in banned array and sum not exceed max sum simple apporach just using set take i < n and j to banned and check consiton s done 5 | unordered_set bannedSet(banned.begin() , banned.end()); 6 | int currSum = 0 , cnt = 0; 7 | for(int i=1; i<=n ; i++){ 8 | if(bannedSet.find(i) == bannedSet.end() && currSum + i <= maxSum){ 9 | currSum += i; 10 | cnt++; 11 | } 12 | } 13 | return cnt; 14 | } 15 | }; -------------------------------------------------------------------------------- /2645-pass-the-pillow/2645-pass-the-pillow.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int passThePillow(int n, int time) { 4 | return n - abs(n-1-time % (2*n - 2)); 5 | } 6 | }; -------------------------------------------------------------------------------- /2649-count-total-number-of-colored-cells/2649-count-total-number-of-colored-cells.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long coloredCells(int n) { 4 | // we are given 2d grid uncolored unit cell given positive int n and isee one pattern like when. n == 1 return mesns base contion and for 2 is 5 and you see a aottern like 3 is 13 means the if i add 1 + 2 + 5 *2 = 13 and in another form 3 is n and recent for 2 si alrady 5 just double it or mutiply 2 u see a pattern 5 | if (n == 1) return 1; 6 | long long n_long = n; // Convert n to long long 7 | return 1 + 4 * (n_long * (n_long - 1) / 2); 8 | } 9 | }; -------------------------------------------------------------------------------- /2665-minimum-time-to-repair-cars/2665-minimum-time-to-repair-cars.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPossible(vector& ranks, int cars , long long time){ 4 | long long totalCars = 0; 5 | for(auto r : ranks){ 6 | totalCars += sqrt(time/r); 7 | if(totalCars >= cars) return true; 8 | } 9 | return false; 10 | } 11 | long long repairCars(vector& ranks, int cars) { 12 | int minRank = *min_element(ranks.begin() , ranks.end()); 13 | int n = ranks.size(); 14 | long long left = 0 , right = (long long) minRank*cars*cars; 15 | while(left < right){ 16 | // now here why we do sort just do one thing take cars as target means in possible and we nned to return min time also 17 | long long mid = left + (right - left ) / 2; 18 | if(isPossible(ranks , cars , mid)){ 19 | right = mid; 20 | }else{ 21 | left = mid+1; 22 | } 23 | } 24 | return left; 25 | } 26 | }; -------------------------------------------------------------------------------- /2692-take-gifts-from-the-richest-pile/2692-take-gifts-from-the-richest-pile.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long pickGifts(vector& gifts, int k) { 4 | priority_queue pq(gifts.begin() , gifts.end()); 5 | for(int i=0; i& nums) { 4 | int n = nums.size(); 5 | long long score = 0; 6 | priority_queue, vector> , greater>> pq; 7 | unordered_set st; 8 | for(int i=0 ; i 0) st.insert(idx - 1); 17 | if(idx < n-1) st.insert(idx + 1); 18 | } 19 | return score; 20 | } 21 | }; -------------------------------------------------------------------------------- /2699-count-the-number-of-fair-pairs/2699-count-the-number-of-fair-pairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long countFairPairs(vector& nums, int lower, int upper) { 4 | sort(nums.begin() , nums.end()); 5 | int n = nums.size(); 6 | long long res = 0; 7 | int low = n-1 , high = n-1; 8 | for(int i=0; i=0 && nums[i] + nums[high] > upper) high--; 10 | while(low>=0 && nums[i] + nums[low] >= lower) low--; 11 | res += high - low; 12 | if(low > mergeArrays(vector>& nums1, vector>& nums2) { 4 | unordered_map mp; 5 | for(auto n1 : nums1) mp[n1[0]]+=n1[1]; 6 | for(auto n2 : nums2) mp[n2[0]]+=n2[1]; 7 | vector> res; 8 | for(auto entry : mp){ 9 | res.push_back({entry.first , entry.second}); 10 | } 11 | sort(res.begin() ,res.end() , [](const vector& a , vector& b){ 12 | return a[0] < b[0]; 13 | }); 14 | return res; 15 | } 16 | }; -------------------------------------------------------------------------------- /2716-prime-subtraction-operation/2716-prime-subtraction-operation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool primeSubOperation(vector& nums) { 4 | int maxEle = *max_element(nums.begin() , nums.end()); 5 | vector sieve(maxEle + 1 , 1); 6 | sieve[1] = 0; 7 | for(int i=2; i<=sqrt(maxEle +1); i++){ 8 | if(sieve[i] == 1){ 9 | for(int j=i*i ; j<=maxEle; j+=i) sieve[j] = 0; 10 | } 11 | } 12 | int currVal = 1 , i = 0; 13 | while(i minOperations(vector& nums, vector& queries) { 4 | int n = nums.size() , m = queries.size(); 5 | sort(nums.begin() , nums.end()); 6 | vector psum(n+1 , 0) , res(m , 0); 7 | for(int i=1; i<=nums.size(); i++) { 8 | psum[i] = psum[i-1] + nums[i-1]; 9 | // cout<& details) { 4 | int seniorCount = 0; 5 | 6 | // Iterate through each passenger's details 7 | for (string& passengerInfo : details) { 8 | // Extract the digits of age 9 | int ageTens = passengerInfo[11] - '0'; 10 | int ageOnes = passengerInfo[12] - '0'; 11 | 12 | // Calculate the full age 13 | int age = ageTens * 10 + ageOnes; 14 | 15 | // Check if the passenger is a senior (strictly over 60 years old) 16 | if (age > 60) { 17 | seniorCount++; 18 | } 19 | } 20 | 21 | return seniorCount; 22 | } 23 | }; -------------------------------------------------------------------------------- /2755-extra-characters-in-a-string/2755-extra-characters-in-a-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minExtraChar(string s, vector dictionary) { 4 | int n = s.length(); 5 | unordered_set dictionarySet(dictionary.begin(), dictionary.end()); 6 | unordered_map memo; 7 | 8 | function dp = [&](int start) { 9 | if (start == n) { 10 | return 0; 11 | } 12 | if (memo.count(start)) { 13 | return memo[start]; 14 | } 15 | // To count this character as a left over character 16 | // move to index 'start + 1' 17 | int ans = dp(start + 1) + 1; 18 | for (int end = start; end < n; end++) { 19 | auto curr = s.substr(start, end - start + 1); 20 | if (dictionarySet.count(curr)) { 21 | ans = min(ans, dp(end + 1)); 22 | } 23 | } 24 | 25 | return memo[start] = ans; 26 | }; 27 | 28 | return dp(0); 29 | } 30 | }; -------------------------------------------------------------------------------- /2757-count-of-integers/2757-count-of-integers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int count(string num1, string num2, int min_sum, int max_sum) { 4 | // Convert string numbers to integers (be careful about constraints) 5 | long long low = stoll(num1); 6 | long long high = stoll(num2); 7 | 8 | // Mod value as required 9 | const int MOD = 1e9 + 7; 10 | 11 | // Counter for valid numbers 12 | int count = 0; 13 | 14 | // Iterate through every number in the range 15 | for (long long i = low; i <= high; i++) { 16 | // Calculate digit sum for current number 17 | long long current = i; 18 | int digitSum = 0; 19 | 20 | while (current > 0) { 21 | digitSum += current % 10; 22 | current /= 10; 23 | } 24 | 25 | // Check if sum is in the required range 26 | if (digitSum >= min_sum && digitSum <= max_sum) { 27 | count = (count + 1) % MOD; 28 | } 29 | } 30 | 31 | return count; 32 | } 33 | }; -------------------------------------------------------------------------------- /2766-find-the-prefix-common-array-of-two-arrays/2766-find-the-prefix-common-array-of-two-arrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findThePrefixCommonArray(vector& A, vector& B) { 4 | int n = A.size() , cnt = 0; 5 | vector f(n+1 , 0) , res(n); 6 | for(int i=0; i& derived) { 4 | // we need to find valid array ok and find we need to compute xor of adjacent values in a binary array original of length n.If i = n - 1, then derived[i] = original[i] ⊕ original[0]. 5 | // Otherwise, derived[i] = original[i] ⊕ original[i + 1]. nust follow the contion and perform xor we done it 6 | int xorSum = 0; 7 | for(auto n : derived) xorSum ^= n; 8 | return xorSum == 0; 9 | } 10 | }; -------------------------------------------------------------------------------- /2794-maximum-number-of-moves-in-a-grid/2794-maximum-number-of-moves-in-a-grid.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxMoves(vector>& grid) { 4 | int m = grid.size(); 5 | int n = grid[0].size(); 6 | vector> dp(m , vector(n , 0)); 7 | for(int j=n-2; j>=0; j--){ 8 | for(int i=0;i0 && grid[i][j] < grid[i-1][j+1]) dp[i][j] = max(dp[i][j], dp[i - 1][j + 1] + 1); 11 | if(i i32 { 3 | while s.contains("AB") || s.contains("CD"){ 4 | if let Some(pos) = s.find("AB"){ 5 | s.replace_range(pos..pos + 2 , ""); 6 | } else if let Some(pos) = s.find("CD"){ 7 | s.replace_range(pos..pos + 2 , ""); 8 | } 9 | } 10 | s.len() as i32 11 | } 12 | } -------------------------------------------------------------------------------- /2800-minimum-string-length-after-removing-substrings/2800-minimum-string-length-after-removing-substrings.swift: -------------------------------------------------------------------------------- 1 | class Solution { 2 | func minLength(_ s: String) -> Int { 3 | var s = s; 4 | while s.contains("AB") || s.contains("CD") { 5 | if let range = s.range(of: "AB") { 6 | s.removeSubrange(range); 7 | } else if let range = s.range(of: "CD") { 8 | s.removeSubrange(range); 9 | } 10 | } 11 | return s.count; 12 | } 13 | } -------------------------------------------------------------------------------- /2868-continuous-subarrays/2868-continuous-subarrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long continuousSubarrays(vector& nums) { 4 | // given 0 index nums a subarray cnotinuius if nums[i1] - nums[i2] <= 2 return total no of continuous subarray 5 | // nums = 5,4,2,4 -> continuos subarray we find we use simple dp 2 pointer easily we find it and use map or set also lets implemmnt the approach for 2 pointer hust using left and right using thes 2 pointer we dinf that the conditon operation to check the continuos ok and cnt and return it 6 | int n = nums.size() , i = 0; 7 | long long cnt = 0; 8 | multiset st; 9 | for(int j=0; j 2){ 12 | st.erase(st.find(nums[i])); 13 | i++; 14 | } 15 | cnt += j-i+1; 16 | } 17 | return cnt; 18 | } 19 | }; -------------------------------------------------------------------------------- /2891-maximum-beauty-of-an-array-after-applying-operation/2891-maximum-beauty-of-an-array-after-applying-operation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumBeauty(vector& nums, int k) { 4 | // maximize the beauty after applying operation ok given nums arr and non int k in one operation chosse indix i hasnt been choosen before ok form 0 to nums.len -1 and replase with any int from range nums[i] - k , nums[i] + k 5 | // sort the array ok use bonary seach adn sliding for like take an ele make its range by using k and apply operation find max subsewunce len or cnt ok of smae no make in that array 6 | sort(nums.begin() , nums.end()); 7 | int n = nums.size() , maxLen = 0 , i= 0; 8 | for(int j=0; j 2*k) i++; 10 | maxLen = max(maxLen , j-i+1); 11 | } 12 | return maxLen; 13 | } 14 | }; -------------------------------------------------------------------------------- /2998-count-symmetric-integers/2998-count-symmetric-integers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countSymmetricIntegers(int low, int high) { 4 | int cnt = 0; 5 | for(int i=low; i<=high; i++){ 6 | if(isSym(i)) cnt++; 7 | } 8 | return cnt; 9 | } 10 | bool isSym(int num){ 11 | string s = to_string(num); 12 | int n = s.size(); 13 | if(n % 2 == 1) return false; 14 | int left = 0 , right = 0; 15 | for(int i=0; i getLongestSubsequence(vector& words, vector& groups) { 4 | int n = words.size(); 5 | vector res; 6 | for(int i=0; i& nums) { 4 | int n = nums.size(); 5 | long long maxi = 0; 6 | vectorlMax(n) , rMax(n); 7 | for(int i=1; i>& edges) { 4 | vector indegree(n , 0); 5 | for(auto e : edges){ 6 | indegree[e[1]]++; 7 | } 8 | int ans = -1; 9 | for(int i=0; i findWordsContaining(vector& words, char x) { 4 | vector res; 5 | // for(int i=0; i& nums, int k) { 4 | // Brute Force TLE 622 / 633 testcases passed 5 | int n = nums.size(); 6 | long long count = 0; 7 | int max_ele = *max_element(nums.begin() , nums.end()); 8 | int start = 0; 9 | int maxCount = 0; 10 | // for(int i=0; i= k) count++; 15 | // } 16 | // } 17 | for(int end = 0; end= k){ 20 | count += n-end; 21 | if(nums[start] == max_ele){ 22 | maxCount--; 23 | } 24 | start++; 25 | } 26 | 27 | } 28 | return count; 29 | } 30 | }; -------------------------------------------------------------------------------- /3227-find-missing-and-repeated-values/3227-find-missing-and-repeated-values.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findMissingAndRepeatedValues(vector>& grid) { 4 | int n = grid.size(); 5 | vector res(n*n + 1 , 0); 6 | for(int i=0; i mp; 6 | for(int i=0; i= 3 && str.size() > ans ) ans = str.size(); 21 | } 22 | if(ans == 0) return -1; 23 | return ans; 24 | } 25 | }; -------------------------------------------------------------------------------- /3271-count-the-number-of-houses-at-a-certain-distance-i/3271-count-the-number-of-houses-at-a-certain-distance-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector countOfPairs(int n, int x, int y) { 4 | // floyd algo 5 | vector> dist(n+1 , vector(n+1 , 1e9)); 6 | for(int i=1; i res(n); 23 | for(int i=1; i<=n; i++){ 24 | for(int j=1; j<=n; j++){ 25 | if(i != j) 26 | res[dist[i][j]-1]++; 27 | } 28 | } 29 | return res; 30 | } 31 | }; -------------------------------------------------------------------------------- /3276-minimum-number-of-pushes-to-type-word-ii/3276-minimum-number-of-pushes-to-type-word-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumPushes(string word) { 4 | // Frequency map to store count of each letter 5 | unordered_map frequencyMap; 6 | 7 | // Count occurrences of each letter 8 | for (char& c : word) { 9 | ++frequencyMap[c]; 10 | } 11 | 12 | // Priority queue to store frequencies in descending order 13 | priority_queue frequencyQueue; 14 | 15 | // Push all frequencies into the priority queue 16 | for (const auto& entry : frequencyMap) { 17 | frequencyQueue.push(entry.second); 18 | } 19 | 20 | int totalPushes = 0; 21 | int index = 0; 22 | 23 | // Calculate total number of presses 24 | while (!frequencyQueue.empty()) { 25 | totalPushes += (1 + (index / 8)) * frequencyQueue.top(); 26 | frequencyQueue.pop(); 27 | index++; 28 | } 29 | 30 | return totalPushes; 31 | } 32 | }; -------------------------------------------------------------------------------- /3291-find-if-array-can-be-sorted/3291-find-if-array-can-be-sorted.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canSortArray(vector& nums) { 4 | int maxS = nums[0] , minS = nums[0]; 5 | int numB = __builtin_popcount(nums[0]); 6 | int maxPS = INT_MIN; 7 | for(int i=1; i 2 | #include 3 | 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int countPrefixSuffixPairs(vector& words) { 9 | int count = 0; 10 | for (int i = 0; i < words.size(); i++) { 11 | for (int j = i + 1; j < words.size(); j++) { 12 | if (isPrefixAndSuffix(words[i], words[j])) { 13 | count++; 14 | } 15 | } 16 | } 17 | return count; 18 | } 19 | 20 | private: 21 | bool isPrefixAndSuffix(string& prefix, string& word) { 22 | if (word.size() < prefix.size()) { 23 | return false; 24 | } 25 | return word.substr(0, prefix.size()) == prefix && word.substr(word.size() - prefix.size()) == prefix; 26 | } 27 | }; -------------------------------------------------------------------------------- /3321-type-of-triangle/3321-type-of-triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string triangleType(vector& nums) { 4 | int n = nums.size(); 5 | int a = nums[0] , b = nums[1] , c = nums[2]; 6 | if(a+b>c && b+c > a && a+c > b){ 7 | if(a == b && b == c && a == c) return "equilateral"; 8 | else if(a==b || b == c || a == c) return "isosceles"; 9 | return "scalene"; 10 | } 11 | return "none"; 12 | } 13 | }; -------------------------------------------------------------------------------- /3332-minimum-operations-to-exceed-threshold-value-ii/3332-minimum-operations-to-exceed-threshold-value-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minOperations(vector& nums, int k) { 4 | priority_queue, greater> pq(nums.begin() , nums.end()); 5 | int operations = 0; 6 | while(pq.top() < k){ 7 | long long x = pq.top(); pq.pop(); 8 | long long y = pq.top(); pq.pop(); 9 | pq.push(min(x,y)*2 + max(x,y)); 10 | operations++; 11 | } 12 | return operations; 13 | } 14 | }; -------------------------------------------------------------------------------- /3372-longest-strictly-increasing-or-strictly-decreasing-subarray/3372-longest-strictly-increasing-or-strictly-decreasing-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int longestMonotonicSubarray(vector& arr) { 4 | int n = arr.size(); 5 | int maxi = 1 , inc = 1 , dec = 1; 6 | for(int i=1; i arr[i-1]){ 12 | dec++; 13 | inc = 1; 14 | } 15 | else dec = inc = 1; 16 | maxi = max(maxi , max(inc , dec)); 17 | } 18 | return maxi; 19 | } 20 | }; -------------------------------------------------------------------------------- /3394-minimum-array-end/3394-minimum-array-end.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long minEnd(int n, int x) { 4 | long long result = x; 5 | 6 | // Step 1: Iterate n-1 times (since we already initialized result with 7 | // x) 8 | while (--n) { 9 | // Step 2: Increment result and perform bitwise OR with x 10 | result = (result + 1) | x; 11 | } 12 | 13 | return result; 14 | } 15 | }; -------------------------------------------------------------------------------- /3427-special-array-ii/3427-special-array-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector isArraySpecial(vector& nums, vector>& queries) { 4 | vector ans(queries.size() , false); 5 | vector pre(nums.size() , 0); 6 | pre[0]= 1; 7 | for(int i=1; i q = queries[i]; 13 | int st = q[0] , end = q[1]; 14 | ans[i] = pre[end] - pre[st] == 0; 15 | } 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /3429-special-array-i/3429-special-array-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isArraySpecial(vector& nums) { 4 | int n = nums.size(); 5 | for(int i=0; i> cnt(26); 5 | for(int i=0; i res; 5 | for(char c : s){ 6 | if(c >= '0' && c<='9' && res.size() > 0) res.pop_back(); 7 | else res.push_back(c); 8 | } 9 | return string(res.begin() , res.end()); 10 | } 11 | }; -------------------------------------------------------------------------------- /3451-string-compression-iii/3451-string-compression-iii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string compressedString(string word) { 4 | if (word.empty()) return ""; 5 | 6 | string result; 7 | int n = word.size(); 8 | int count = 1; 9 | 10 | for (int i = 1; i < n; ++i) { 11 | if (word[i] == word[i - 1]) { 12 | count++; 13 | if (count == 10) { 14 | result += "9"; 15 | result += word[i - 1]; 16 | count = 1; 17 | } 18 | } else { 19 | result += to_string(count); 20 | result += word[i - 1]; 21 | count = 1; 22 | } 23 | } 24 | 25 | // Append the last character and its count 26 | result += to_string(count); 27 | result += word[n - 1]; 28 | 29 | return result; 30 | } 31 | }; -------------------------------------------------------------------------------- /3455-minimum-length-of-string-after-operations/3455-minimum-length-of-string-after-operations.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumLength(string s) { 4 | int n = s.size() , del = 0; 5 | unordered_map mp; 6 | for(auto c : s) mp[c]++; 7 | for(auto it : mp){ 8 | del += (it.second%2) ? it.second - 1 : it.second - 2; 9 | } 10 | return n - del; 11 | } 12 | }; -------------------------------------------------------------------------------- /3463-alternating-groups-i/3463-alternating-groups-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfAlternatingGroups(vector& colors) { 4 | int count = 0; 5 | colors.push_back(colors[0]); 6 | colors.push_back(colors[1]); 7 | int n = colors.size(); 8 | for(int i=2; i= level) startColorBalls -= level; 7 | else break; 8 | } 9 | else{ 10 | if(otherColorBalls >= level) otherColorBalls -= level; 11 | else break; 12 | } 13 | maxHeight = level; 14 | level++; 15 | } 16 | return maxHeight; 17 | } 18 | public int maxHeightOfTriangle(int red, int blue) { 19 | int maxHeightStartingWithRed = calcMaxHeight(red , blue); 20 | int maxHeightStartingWithBlue = calcMaxHeight(blue , red); 21 | return Math.max(maxHeightStartingWithRed , maxHeightStartingWithBlue); 22 | } 23 | } -------------------------------------------------------------------------------- /3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i/3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minOperations(vector& nums) { 4 | int n = nums.size() , res = 0; 5 | for(int i=0; i& colors, int k) { 4 | // color i = 0 means red and 1 is blue ok given int k now what we need to count alternative using means modulo in circle and count that how many is different ok we to first iterate to arr of colors adn check 1 and 0 and acc to k we nned to make that colors ok inthat pos means form 1 color on another k side the color is alternate ok 5 | for(int i=0; i=k) res++; 11 | } 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /3501-delete-nodes-from-linked-list-present-in-array/3501-delete-nodes-from-linked-list-present-in-array.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | class Solution { 12 | public: 13 | ListNode* modifiedList(vector& nums, ListNode* head) { 14 | unordered_set numSet(nums.begin() , nums.end()); 15 | ListNode* dummy = new ListNode(0); 16 | dummy->next = head; 17 | ListNode* curr = dummy; 18 | while(curr->next != NULL){ 19 | if(numSet.find(curr->next->val) != numSet.end()){ 20 | ListNode *temp = curr->next; 21 | curr->next = curr->next->next; 22 | delete temp; 23 | } 24 | else curr = curr->next; 25 | } 26 | ListNode *modified = dummy->next; 27 | delete dummy; 28 | return modified; 29 | } 30 | }; -------------------------------------------------------------------------------- /3507-find-the-count-of-numbers-which-are-not-special/3507-find-the-count-of-numbers-which-are-not-special.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector generate(int limit){ 4 | vector isPrime(limit+1 , true); 5 | isPrime[0] = isPrime[1] = false; 6 | for(int i=2; i*i<=limit; i++){ 7 | if(isPrime[i]){ 8 | for(int j= i*i; j<=limit; j+=i){ 9 | isPrime[j] = false; 10 | } 11 | } 12 | } 13 | vector prime; 14 | for(int i=2; i<=limit; i++) { 15 | if(isPrime[i]) prime.push_back(i); 16 | } 17 | return prime; 18 | } 19 | int nonSpecialCount(int l, int r) { 20 | int total = r-l+1 , limit = sqrt(r) , specialCnt = 0; 21 | vector primes = generate(limit); 22 | for(auto prime : primes){ 23 | int special = prime*prime; 24 | if(special >= l && special <= r) specialCnt++; 25 | } 26 | return total - specialCnt; 27 | } 28 | }; -------------------------------------------------------------------------------- /3522-find-the-power-of-k-size-subarrays-i/3522-find-the-power-of-k-size-subarrays-i.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class Solution { 5 | public: 6 | std::vector resultsArray(std::vector& nums, int k) { 7 | std::vector results; 8 | int n = nums.size(); 9 | 10 | for (int i = 0; i <= n - k; ++i) { 11 | bool is_sorted_and_consecutive = true; 12 | for (int j = i + 1; j < i + k; ++j) { 13 | if (nums[j] != nums[j - 1] + 1) { 14 | is_sorted_and_consecutive = false; 15 | break; 16 | } 17 | } 18 | if (is_sorted_and_consecutive) { 19 | results.push_back(*std::max_element(nums.begin() + i, nums.begin() + i + k)); 20 | } else { 21 | results.push_back(-1); 22 | } 23 | } 24 | 25 | return results; 26 | } 27 | }; -------------------------------------------------------------------------------- /3555-final-array-state-after-k-multiplication-operations-i/3555-final-array-state-after-k-multiplication-operations-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector getFinalState(vector& nums, int k, int multiplier) { 4 | int n = nums.size(); 5 | while(k--){ 6 | int minIdx = 0; 7 | for(int i=0; i& nums, int k) { 4 | int n = nums.size(); 5 | unordered_set st; 6 | for(int i=0; i k) st.insert(nums[i]); 9 | } 10 | return st.size(); 11 | } 12 | }; -------------------------------------------------------------------------------- /3639-zero-array-transformation-i/3639-zero-array-transformation-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isZeroArray(vector& nums, vector>& queries) { 4 | int n = nums.size(); 5 | vector diff(n+1 , 0); 6 | for(auto q : queries ){ 7 | int l = q[0] , r = q[1]; 8 | diff[l] +=1; 9 | diff[r+1] -=1; 10 | } 11 | int cnt = 0; 12 | for(int i=0; i cnt) return false; 15 | } 16 | return true; 17 | } 18 | }; -------------------------------------------------------------------------------- /3647-zero-array-transformation-iii/3647-zero-array-transformation-iii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxRemoval(vector& nums, vector>& queries) { 4 | sort(queries.begin(), queries.end(), 5 | [](const vector& a, const vector& b) { 6 | return a[0] < b[0]; 7 | }); 8 | priority_queue heap; 9 | int n = nums.size(); 10 | int op = 0; // op -> operations 11 | vector diff(nums.size() + 1, 0); 12 | for (int i = 0, j = 0; i < n; i++) { 13 | op += diff[i]; 14 | while (j < queries.size() && queries[j][0] == i) { 15 | heap.push(queries[j][1]); 16 | j++; 17 | } 18 | while (op < nums[i] && !heap.empty() && heap.top() >= i) { 19 | op += 1; 20 | diff[heap.top() + 1] -= 1; 21 | heap.pop(); 22 | } 23 | if (op < nums[i]) 24 | return -1; 25 | } 26 | return heap.size(); 27 | } 28 | }; -------------------------------------------------------------------------------- /3656-minimum-number-of-operations-to-make-elements-in-array-distinct/3656-minimum-number-of-operations-to-make-elements-in-array-distinct.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumOperations(vector& nums) { 4 | int n = nums.size(); 5 | int cnt = 0; 6 | 7 | while(true){ 8 | unordered_set st; 9 | bool allDis = true; 10 | for(int i=3*cnt; i& nums) { 4 | int n = nums.size(); 5 | int cnt = 0; 6 | if(n<3) return 0; 7 | for(int i=0; i<=n-3; i++){ 8 | if(nums[i] + nums[i+2] == nums[i+1] / 2.0) cnt++; 9 | } 10 | return cnt; 11 | } 12 | }; -------------------------------------------------------------------------------- /3747-maximum-difference-between-adjacent-elements-in-a-circular-array/3747-maximum-difference-between-adjacent-elements-in-a-circular-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxAdjacentDistance(vector& nums) { 4 | int n = nums.size(); 5 | int res = abs(nums[0] - nums[n - 1]); 6 | for (int i = 0; i < n - 1; ++i) { 7 | res = max(res, abs(nums[i] - nums[i + 1])); 8 | } 9 | return res; 10 | } 11 | }; -------------------------------------------------------------------------------- /3753-maximum-difference-between-even-and-odd-frequency-i/3753-maximum-difference-between-even-and-odd-frequency-i.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDifference(string s) { 4 | unordered_map mp; 5 | int maxOdd = INT_MIN , minEven = INT_MAX; 6 | for(auto c : s) mp[c]++; 7 | for(auto it : mp){ 8 | if(it.second % 2 == 1) maxOdd = max(maxOdd , it.second); 9 | if(it.second % 2 == 0 && it.second > 0) minEven = min(minEven , it.second); 10 | 11 | } 12 | return maxOdd - minEven; 13 | } 14 | }; -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/104. Maximum Depth of Binary Tree.java: -------------------------------------------------------------------------------- 1 | 104. Maximum Depth of Binary Tree 2 | 3 | 4 | 5 | 16 Feb 2023 6 | 7 | 8 | 9 | 10 | Easy 11 | 12 | 13 | 14 | C++: 15 | 16 | // Time Complexity : O(n) where n is the length of the string and space complexity is O(n) 17 | 18 | 19 | class Solution { 20 | public: 21 | int maxDepth(TreeNode* root) { 22 | if(!root) return 0; // if condition is true 23 | return 1 + max(maxDepth(root->left), maxDepth(root->right)); // return 1+max(maxDepth(root->left),maxDepth(root->right)) 24 | } 25 | }; 26 | 27 | 28 | 29 | Java: 30 | 31 | 32 | // Time Complexity : O(n) where n is the length of the string and space complexity is O(n) 33 | 34 | 35 | class Solution { 36 | public int maxDepth(TreeNode root) { 37 | if(root == null) return 0; // if condition is true 38 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); // return 1+Math.max(maxDepth(root.left),maxDepth(root.right)) 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/1207. Unique Number of Occurrences: -------------------------------------------------------------------------------- 1 | 1207. Unique Number of Occurrences 2 | 3 | 4 | 5 | 17 Jan 2023 6 | 7 | 8 | 9 | 10 | 11 | Easy 12 | 13 | 14 | 15 | C++: 16 | 17 | 18 | class Solution { 19 | public: 20 | bool uniqueOccurrences(vector& arr) { 21 | unordered_map mp; 22 | for(auto n : arr)mp[n]++; 23 | unordered_set s; 24 | for(auto x : mp){ 25 | if (!s.insert(x.second).second) return false; 26 | } 27 | return true; 28 | } 29 | }; 30 | 31 | 32 | OR 33 | 34 | class Solution { 35 | public: 36 | bool uniqueOccurrences(vector& arr) { 37 | unordered_map mp; 38 | for(auto n : arr)mp[n]++; 39 | unordered_set s; 40 | for(auto x : mp){ 41 | int frq = x.second; 42 | if(s.find(frq) != s.end()) return false; 43 | else s.insert(frq); 44 | } 45 | return true; 46 | } 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/1266. Minimum Time Visiting All Points: -------------------------------------------------------------------------------- 1 | 1266. Minimum Time Visiting All Points 2 | 3 | 4 | 3 Dec 2023 5 | 6 | 7 | 8 | Easy 9 | 10 | 11 | 12 | C++: 13 | 14 | class Solution { 15 | public: 16 | int minTimeToVisitAllPoints(vector>& points) { 17 | int ans = 0; 18 | for(int i=1; i freq; 23 | 24 | // Count the frequency of characters in both strings 25 | for (auto it : s) freq[it]++; 26 | for (auto p : t) freq[p]--; 27 | 28 | int ans = 0; 29 | 30 | // Calculate the number of steps needed to make t an anagram of s 31 | for (auto& pair : freq) { 32 | ans += std::abs(pair.second); // Absolute value of frequency difference 33 | } 34 | 35 | return ans / 2; // Divide by 2 since each step involves changing two characters 36 | } 37 | }; 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/1436. Destination City: -------------------------------------------------------------------------------- 1 | 1436. Destination City 2 | 3 | 4 | 5 | 15 Dec 2023 6 | 7 | 8 | 9 | 10 | Easy 11 | 12 | 13 | 14 | C++: 15 | 16 | 17 | #include 18 | #include 19 | 20 | class Solution { 21 | public: 22 | std::string destCity(std::vector>& paths) { 23 | std::string ans = ""; 24 | 25 | // Create a set to store the cities that are not destinations 26 | std::unordered_set sourceCities; 27 | 28 | // Populate the set with source cities 29 | for (const auto& path : paths) { 30 | sourceCities.insert(path[0]); 31 | } 32 | 33 | // Find the destination city 34 | for (const auto& path : paths) { 35 | if (sourceCities.find(path[1]) == sourceCities.end()) { 36 | // If the second city is not in the set of source cities, it is the destination 37 | ans = path[1]; 38 | break; 39 | } 40 | } 41 | 42 | return ans; 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/1496. Path Crossing: -------------------------------------------------------------------------------- 1 | 1496. Path Crossing 2 | 3 | 4 | 5 | 6 | 7 | 23 Dec 2023 8 | 9 | 10 | 11 | Easy 12 | 13 | 14 | 15 | 16 | C++: 17 | 18 | 19 | class Solution { 20 | public: 21 | bool isPathCrossing(string path) { 22 | set> vis; 23 | int x = 0 , y = 0; 24 | vis.insert({x, y}); 25 | for(char p : path){ 26 | if(p == 'N') y++; 27 | else if(p == 'S') y--; 28 | else if(p == 'E') x++; 29 | else if(p == 'W') x--; 30 | if(vis.count({x,y})) return true; 31 | vis.insert({x,y}); 32 | } 33 | return false; 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/1561. Maximum Number of Coins You Can Get: -------------------------------------------------------------------------------- 1 | 1561. Maximum Number of Coins You Can Get 2 | 3 | 4 | 24 Nov 2023 5 | 6 | 7 | Medium 8 | 9 | 10 | C++: 11 | 12 | 13 | class Solution { 14 | public: 15 | int maxCoins(vector& piles) { 16 | ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0); 17 | int n = piles.size(); 18 | sort(piles.begin() , piles.end()); 19 | int sum = 0; 20 | for(int i=n/3; i>& mat) { 20 | int res = 0; 21 | int n = mat.size(); 22 | int m = mat[0].size(); 23 | vector rowCount(n); 24 | vector colCount(m); 25 | for(int i=0; i& students, vector& sandwiches) { 16 | int ccnt = 0 , scnt = 0; 17 | for(int student : students){ 18 | if(student == 0) ccnt++; 19 | else scnt++; 20 | } 21 | for(int sandwich : sandwiches){ 22 | if(sandwich == 0 && ccnt == 0) return scnt; 23 | if(sandwich == 1 && scnt == 0) return ccnt; 24 | if(sandwich == 0) ccnt--; 25 | else scnt--; 26 | } 27 | return 0; 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/1704. Determine if String Halves Are Alike: -------------------------------------------------------------------------------- 1 | 1704. Determine if String Halves Are Alike 2 | 3 | 4 | 5 | 12 Jan 2024 6 | 7 | 8 | Easy 9 | 10 | 11 | 12 | C++: 13 | 14 | 15 | class Solution { 16 | public: 17 | bool halvesAreAlike(string s) { 18 | int n = s.size(); 19 | int count = 0; 20 | 21 | for (int i = 0; i < n / 2; i++) { 22 | if (hasVowel(s[i])) count++; 23 | } 24 | 25 | int count1 = 0; 26 | for (int i = n / 2; i < n; i++) { 27 | if (hasVowel(s[i])) count1++; 28 | } 29 | 30 | return count == count1; 31 | } 32 | 33 | bool hasVowel(char c) { 34 | return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || 35 | c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'; 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/2140. Solving Questions With Brainpower: -------------------------------------------------------------------------------- 1 | 2140. Solving Questions With Brainpower 2 | 3 | 4 | 5 | 12 May 2023 6 | 7 | 8 | 9 | Medium 10 | 11 | 12 | 13 | 14 | C++: 15 | 16 | 17 | 18 | // Time Complexity : O(n) and space complexity is O(n) 19 | 20 | 21 | 22 | class Solution { 23 | public: 24 | long long mostPoints(vector>& q) { 25 | int n = q.size(); 26 | long long dp[200001] = {}; 27 | 28 | for(int i = n-1; i>=0; i--) 29 | dp[i] = max(q[i][0] + dp[q[i][1] + i + 1] ,dp[i+1]); 30 | 31 | return dp[0]; 32 | 33 | } 34 | }; 35 | 36 | 37 | Java: 38 | 39 | // Time Complexity : O(n) and space complexity is O(n) 40 | 41 | 42 | 43 | class Solution { 44 | public long mostPoints(int[][] q) { 45 | int n = q.length; 46 | long[] dp = new long[200001]; 47 | for(int i=n-1; i>=0; i--) 48 | dp[i] = Math.max(q[i][0] + dp[q[i][1] + i + 1 ] , dp[i+1]); 49 | return dp[0]; 50 | } 51 | } 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/2264. Largest 3-Same-Digit Number in String: -------------------------------------------------------------------------------- 1 | 2264. Largest 3-Same-Digit Number in String 2 | 3 | 4 | 4 Dec 2023 5 | 6 | 7 | Easy 8 | 9 | 10 | 11 | C++: 12 | 13 | 14 | class Solution { 15 | public: 16 | string largestGoodInteger(string num) { 17 | string maxGoodInteger = ""; 18 | 19 | for (int i = 0; i < num.size() - 2; i++) { 20 | // Check if the substring is a good integer 21 | if (num[i] == num[i + 1] && num[i + 1] == num[i + 2]) { 22 | string currentGoodInteger = num.substr(i, 3); 23 | 24 | // Compare and update the maximum good integer 25 | if (currentGoodInteger > maxGoodInteger) { 26 | maxGoodInteger = currentGoodInteger; 27 | } 28 | } 29 | } 30 | 31 | return maxGoodInteger; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/242. Valid Anagram: -------------------------------------------------------------------------------- 1 | 242. Valid Anagram 2 | 3 | 4 | 5 | 6 | 16 Dec 2023 7 | 8 | 9 | 10 | 11 | Easy 12 | 13 | 14 | 15 | 16 | C++: 17 | 18 | 19 | #pragma GCC optimize("Ofast","inline","fast-math","unroll-loops","no-stack-protector") 20 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native","f16c") 21 | static const auto fast = []() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; } (); 22 | class Solution { 23 | public: 24 | bool isAnagram(string s, string t) { 25 | vector count(26,0); 26 | for(int i=0;i> findMatrix(vector& nums) { 18 | unordered_map mp; 19 | for (int num : nums) mp[num]++; 20 | 21 | vector> ans; 22 | while (!mp.empty()) { 23 | vector row; 24 | for (auto it = mp.begin(); it != mp.end();) { 25 | row.push_back(it->first); 26 | if (--it->second == 0) { 27 | it = mp.erase(it); 28 | } else { 29 | ++it; 30 | } 31 | } 32 | ans.push_back(row); 33 | } 34 | return ans; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/2958. Length of Longest Subarray With at Most K Frequency: -------------------------------------------------------------------------------- 1 | 2958. Length of Longest Subarray With at Most K Frequency 2 | 3 | 4 | 5 | 6 | 28 Mar 2023 7 | 8 | 9 | 10 | 11 | Medium 12 | 13 | 14 | 15 | C++: 16 | 17 | 18 | class Solution { 19 | public: 20 | int maxSubarrayLength(vector& nums, int k) { 21 | unordered_map mp; 22 | int n = nums.size(); 23 | int left = 0, right= 0; 24 | int maxi = 0; 25 | while(right k) { 28 | mp[nums[left]]--; 29 | left++; 30 | } 31 | maxi = max(maxi , right - left + 1); 32 | right++; 33 | } 34 | return maxi; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/2962. Count Subarrays Where Max Element Appears at Least K Times: -------------------------------------------------------------------------------- 1 | 2962. Count Subarrays Where Max Element Appears at Least K Times 2 | 3 | 4 | 5 | 29 March 2023 6 | 7 | 8 | 9 | Medium 10 | 11 | 12 | C++: 13 | 14 | 15 | 16 | class Solution { 17 | public: 18 | long long countSubarrays(vector& nums, int k) { 19 | int max_ele = *max_element(nums.begin() , nums.end()) , curr= 0 , j = 0 ; 20 | long long res = 0; 21 | for(int i=0; i= k) 24 | curr -= nums[j++] == max_ele; 25 | 26 | res += j; 27 | } 28 | return res; 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/446. Arithmetic Slices II - Subsequence: -------------------------------------------------------------------------------- 1 | 446. Arithmetic Slices II - Subsequence 2 | 3 | 4 | 5 | 7 Jan 2023 6 | 7 | 8 | 9 | Hard 10 | 11 | 12 | 13 | 14 | C++: 15 | 16 | 17 | 18 | #pragma GCC optimize("Ofast","inline","fast-math","unroll-loops","no-stack-protector") 19 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native","f16c") 20 | static const auto fast = []() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; } (); 21 | class Solution { 22 | public: 23 | int numberOfArithmeticSlices(vector& nums) { 24 | int n = nums.size(); 25 | int ans = 0; 26 | vector> dp(n); 27 | for(int i=1; i& g, vector& s) { 18 | sort(g.begin(), g.end()); 19 | sort(s.begin(), s.end()); 20 | int i = 0, j = 0; 21 | while (i < g.size() && j < s.size()) { 22 | if (g[i] <= s[j]) { 23 | ++i; 24 | } 25 | ++j; 26 | } 27 | return i; 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/678. Valid Parenthesis String: -------------------------------------------------------------------------------- 1 | 678. Valid Parenthesis String 2 | 3 | 4 | 5 | 7 April 2024 6 | 7 | 8 | 9 | 10 | Medium 11 | 12 | 13 | 14 | C++: 15 | 16 | 17 | 18 | class Solution { 19 | public: 20 | bool checkValidString(string s) { 21 | int cmin = 0 ,cmax = 0; 22 | for(char c : s){ 23 | if(c == '(') { 24 | cmax++; 25 | cmin++; 26 | } 27 | else if(c == ')'){ 28 | cmax--; cmin--; 29 | } 30 | else if(c == '*'){ 31 | cmax++ ; cmin--; 32 | } 33 | if(cmax < 0) return false; 34 | cmin = max(cmin , 0); 35 | } 36 | return cmin == 0; 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /Daily-LeetCode-Challenge-Solution in C++ && JAVA/912. Sort an Array: -------------------------------------------------------------------------------- 1 | 912. Sort an Array 2 | 3 | 4 | 1 March 2023 5 | 6 | 7 | Medium 8 | 9 | 10 | C++: 11 | 12 | 13 | // Time Complexity : O(nlogn) where n is the length of the array and space complexity is O(n) 14 | 15 | 16 | 17 | class Solution { 18 | public: 19 | vector sortArray(vector& nums) { 20 | sort(nums.begin(), nums.end()); // sort the array 21 | return nums; // return the sorted array 22 | } 23 | }; 24 | 25 | 26 | 27 | 28 | Java: 29 | 30 | 31 | 32 | // Time Complexity : O(nlogn) where n is the length of the array and space complexity is O(n) 33 | 34 | 35 | 36 | class Solution { 37 | public int[] sortArray(int[] nums) { 38 | Arrays.sort(nums); // sort the array 39 | return nums; // return the sorted array 40 | } 41 | } 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | --------------------------------------------------------------------------------