├── 0049-group-anagrams ├── 0049-group-anagrams.cpp ├── NOTES.md └── README.md ├── 0523-continuous-subarray-sum ├── 0523-continuous-subarray-sum.cpp ├── NOTES.md └── README.md ├── 0645-set-mismatch ├── 0645-set-mismatch.cpp ├── NOTES.md └── README.md ├── 0835-image-overlap ├── 0835-image-overlap.cpp ├── NOTES.md └── README.md ├── 100-same-tree ├── 100-same-tree.cpp ├── NOTES.md └── README.md ├── 1008-construct-binary-search-tree-from-preorder-traversal ├── 1008-construct-binary-search-tree-from-preorder-traversal.cpp ├── NOTES.md └── README.md ├── 101-symmetric-tree ├── 101-symmetric-tree.cpp └── NOTES.md ├── 102-binary-tree-level-order-traversal ├── 102-binary-tree-level-order-traversal.cpp ├── NOTES.md └── README.md ├── 103-binary-tree-zigzag-level-order-traversal ├── NOTES.md └── README.md ├── 104-maximum-depth-of-binary-tree ├── NOTES.md └── README.md ├── 1048-longest-string-chain ├── 1048-longest-string-chain.cpp ├── NOTES.md └── README.md ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal.cpp ├── NOTES.md └── README.md ├── 106-construct-binary-tree-from-inorder-and-postorder-traversal ├── NOTES.md └── README.md ├── 1074-number-of-submatrices-that-sum-to-target ├── 1074-number-of-submatrices-that-sum-to-target.cpp ├── NOTES.md └── README.md ├── 108-convert-sorted-array-to-binary-search-tree ├── NOTES.md └── README.md ├── 110-balanced-binary-tree ├── 110-balanced-binary-tree.cpp ├── NOTES.md └── README.md ├── 1108-defanging-an-ip-address ├── 1108-defanging-an-ip-address.cpp ├── NOTES.md └── README.md ├── 1137-n-th-tribonacci-number ├── 1137-n-th-tribonacci-number.cpp ├── NOTES.md └── README.md ├── 114-flatten-binary-tree-to-linked-list ├── 114-flatten-binary-tree-to-linked-list.cpp ├── NOTES.md └── README.md ├── 1143-longest-common-subsequence ├── 1143-longest-common-subsequence.cpp ├── NOTES.md └── README.md ├── 1154-day-of-the-year ├── 1154-day-of-the-year.cpp ├── NOTES.md └── README.md ├── 116-populating-next-right-pointers-in-each-node ├── 116-populating-next-right-pointers-in-each-node.cpp ├── NOTES.md └── README.md ├── 118-pascals-triangle ├── 118-pascals-triangle.cpp ├── NOTES.md └── README.md ├── 121-best-time-to-buy-and-sell-stock ├── 121-best-time-to-buy-and-sell-stock.cpp ├── NOTES.md └── README.md ├── 1239-maximum-length-of-a-concatenated-string-with-unique-characters ├── 1239-maximum-length-of-a-concatenated-string-with-unique-characters.cpp ├── NOTES.md └── README.md ├── 124-binary-tree-maximum-path-sum ├── 124-binary-tree-maximum-path-sum.cpp ├── NOTES.md └── README.md ├── 1287-element-appearing-more-than-25-in-sorted-array ├── 1287-element-appearing-more-than-25-in-sorted-array.cpp ├── NOTES.md └── README.md ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination.cpp ├── NOTES.md └── README.md ├── 1313-decompress-run-length-encoded-list ├── 1313-decompress-run-length-encoded-list.cpp ├── NOTES.md └── README.md ├── 1329-sort-the-matrix-diagonally ├── NOTES.md └── README.md ├── 1332-remove-palindromic-subsequences ├── 1332-remove-palindromic-subsequences.cpp ├── NOTES.md └── README.md ├── 1337-the-k-weakest-rows-in-a-matrix ├── 1337-the-k-weakest-rows-in-a-matrix.cpp ├── NOTES.md └── README.md ├── 1342-number-of-steps-to-reduce-a-number-to-zero ├── 1342-number-of-steps-to-reduce-a-number-to-zero.cpp ├── NOTES.md └── README.md ├── 1354-construct-target-array-with-multiple-sums ├── 1354-construct-target-array-with-multiple-sums.cpp ├── NOTES.md └── README.md ├── 136-single-number ├── 136-single-number.cpp ├── NOTES.md └── README.md ├── 1373-maximum-sum-bst-in-binary-tree ├── 1373-maximum-sum-bst-in-binary-tree.cpp ├── NOTES.md └── README.md ├── 1383-maximum-performance-of-a-team ├── 1383-maximum-performance-of-a-team.cpp └── NOTES.md ├── 1399-count-largest-group ├── 1399-count-largest-group.cpp ├── NOTES.md └── README.md ├── 1423-maximum-points-you-can-obtain-from-cards ├── 1423-maximum-points-you-can-obtain-from-cards.cpp ├── NOTES.md └── README.md ├── 144-binary-tree-preorder-traversal ├── 144-binary-tree-preorder-traversal.cpp ├── NOTES.md └── README.md ├── 1448-count-good-nodes-in-binary-tree ├── 1448-count-good-nodes-in-binary-tree.cpp ├── NOTES.md └── README.md ├── 145-binary-tree-postorder-traversal ├── 145-binary-tree-postorder-traversal.cpp ├── NOTES.md └── README.md ├── 1457-pseudo-palindromic-paths-in-a-binary-tree ├── 1457-pseudo-palindromic-paths-in-a-binary-tree.cpp └── README.md ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.cpp ├── NOTES.md └── README.md ├── 1470-shuffle-the-array ├── 1470-shuffle-the-array.cpp ├── NOTES.md └── README.md ├── 1480-running-sum-of-1d-array ├── 1480-running-sum-of-1d-array.cpp ├── NOTES.md └── README.md ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary.cpp ├── NOTES.md └── README.md ├── 1512-number-of-good-pairs ├── 1512-number-of-good-pairs.cpp ├── NOTES.md └── README.md ├── 152-maximum-product-subarray ├── 152-maximum-product-subarray.cpp ├── NOTES.md └── README.md ├── 1523-count-odd-numbers-in-an-interval-range ├── 1523-count-odd-numbers-in-an-interval-range.cpp ├── NOTES.md └── README.md ├── 1528-shuffle-string ├── 1528-shuffle-string.cpp ├── NOTES.md └── README.md ├── 1547-minimum-cost-to-cut-a-stick ├── 1547-minimum-cost-to-cut-a-stick.cpp ├── NOTES.md └── README.md ├── 1581-customer-who-visited-but-did-not-make-any-transactions ├── 1581-customer-who-visited-but-did-not-make-any-transactions.sql ├── NOTES.md └── README.md ├── 16-3sum-closest ├── 16-3sum-closest.cpp ├── NOTES.md └── README.md ├── 1662-check-if-two-string-arrays-are-equivalent ├── 1662-check-if-two-string-arrays-are-equivalent.cpp ├── NOTES.md └── README.md ├── 167-two-sum-ii-input-array-is-sorted ├── 167-two-sum-ii-input-array-is-sorted.cpp ├── NOTES.md └── README.md ├── 1672-richest-customer-wealth ├── 1672-richest-customer-wealth.cpp ├── NOTES.md └── README.md ├── 1678-goal-parser-interpretation ├── 1678-goal-parser-interpretation.cpp ├── NOTES.md └── README.md ├── 168-excel-sheet-column-title ├── 168-excel-sheet-column-title.cpp ├── NOTES.md └── README.md ├── 169-majority-element ├── 169-majority-element.cpp ├── NOTES.md └── README.md ├── 1693-daily-leads-and-partners ├── 1693-daily-leads-and-partners.sql ├── NOTES.md └── README.md ├── 171-excel-sheet-column-number ├── 171-excel-sheet-column-number.cpp ├── NOTES.md └── README.md ├── 1710-maximum-units-on-a-truck ├── 1710-maximum-units-on-a-truck.cpp ├── NOTES.md └── README.md ├── 1720-decode-xored-array ├── 1720-decode-xored-array.cpp ├── NOTES.md └── README.md ├── 173-binary-search-tree-iterator ├── 173-binary-search-tree-iterator.cpp ├── NOTES.md └── README.md ├── 1741-find-total-time-spent-by-each-employee ├── 1741-find-total-time-spent-by-each-employee.sql ├── NOTES.md └── README.md ├── 175-combine-two-tables ├── 175-combine-two-tables.sql ├── NOTES.md └── README.md ├── 1757-recyclable-and-low-fat-products ├── 1757-recyclable-and-low-fat-products.sql ├── NOTES.md └── README.md ├── 1795-rearrange-products-table ├── 1795-rearrange-products-table.sql ├── NOTES.md └── README.md ├── 1863-sum-of-all-subset-xor-totals ├── 1863-sum-of-all-subset-xor-totals.cpp ├── NOTES.md └── README.md ├── 189-rotate-array ├── 189-rotate-array.cpp └── NOTES.md ├── 19-remove-nth-node-from-end-of-list ├── 19-remove-nth-node-from-end-of-list.cpp └── NOTES.md ├── 190-reverse-bits ├── 190-reverse-bits.cpp ├── NOTES.md └── README.md ├── 191-number-of-1-bits ├── 191-number-of-1-bits.cpp ├── NOTES.md └── README.md ├── 199-binary-tree-right-side-view ├── 199-binary-tree-right-side-view.cpp ├── NOTES.md └── README.md ├── 200-number-of-islands ├── 200-number-of-islands.cpp ├── NOTES.md └── README.md ├── 202-happy-number ├── 202-happy-number.cpp ├── NOTES.md └── README.md ├── 206-reverse-linked-list ├── 206-reverse-linked-list.cpp ├── NOTES.md └── README.md ├── 2095-delete-the-middle-node-of-a-linked-list ├── 2095-delete-the-middle-node-of-a-linked-list.cpp ├── NOTES.md └── README.md ├── 21-merge-two-sorted-lists ├── 21-merge-two-sorted-lists.cpp ├── NOTES.md └── README.md ├── 2114-maximum-number-of-words-found-in-sentences ├── 2114-maximum-number-of-words-found-in-sentences.cpp ├── NOTES.md └── README.md ├── 2131-longest-palindrome-by-concatenating-two-letter-words ├── NOTES.md └── README.md ├── 215-kth-largest-element-in-an-array ├── 215-kth-largest-element-in-an-array.cpp ├── NOTES.md └── README.md ├── 2169-count-operations-to-obtain-zero ├── 2169-count-operations-to-obtain-zero.cpp ├── NOTES.md └── README.md ├── 217-contains-duplicate ├── 217-contains-duplicate.cpp ├── NOTES.md └── README.md ├── 2235-add-two-integers ├── 2235-add-two-integers.cpp ├── NOTES.md └── README.md ├── 2236-root-equals-sum-of-children ├── 2236-root-equals-sum-of-children.cpp ├── NOTES.md └── README.md ├── 2259-remove-digit-from-number-to-maximize-result ├── 2259-remove-digit-from-number-to-maximize-result.cpp ├── NOTES.md └── README.md ├── 226-invert-binary-tree ├── 226-invert-binary-tree.cpp ├── NOTES.md └── README.md ├── 230-kth-smallest-element-in-a-bst ├── 230-kth-smallest-element-in-a-bst.cpp ├── NOTES.md └── README.md ├── 231-power-of-two ├── 231-power-of-two.cpp ├── NOTES.md └── README.md ├── 234-palindrome-linked-list ├── 234-palindrome-linked-list.cpp ├── NOTES.md └── README.md ├── 235-lowest-common-ancestor-of-a-binary-search-tree ├── 235-lowest-common-ancestor-of-a-binary-search-tree.cpp ├── NOTES.md └── README.md ├── 236-lowest-common-ancestor-of-a-binary-tree ├── 236-lowest-common-ancestor-of-a-binary-tree.cpp ├── NOTES.md └── README.md ├── 237-delete-node-in-a-linked-list ├── 237-delete-node-in-a-linked-list.cpp ├── NOTES.md └── README.md ├── 238-product-of-array-except-self ├── 238-product-of-array-except-self.cpp ├── NOTES.md └── README.md ├── 240-search-a-2d-matrix-ii ├── 240-search-a-2d-matrix-ii.cpp ├── NOTES.md └── README.md ├── 242-valid-anagram ├── 242-valid-anagram.cpp ├── NOTES.md └── README.md ├── 278-first-bad-version ├── 278-first-bad-version.cpp ├── NOTES.md └── README.md ├── 283-move-zeroes ├── 283-move-zeroes.cpp ├── NOTES.md └── README.md ├── 287-find-the-duplicate-number └── NOTES.md ├── 295-find-median-from-data-stream ├── 295-find-median-from-data-stream.cpp ├── NOTES.md └── README.md ├── 297-serialize-and-deserialize-binary-tree ├── 297-serialize-and-deserialize-binary-tree.cpp ├── NOTES.md └── README.md ├── 2D Hopscotch - GFG ├── 2d-hopscotch.cpp └── README.md ├── 3 Divisors - GFG ├── 3-divisors.cpp └── README.md ├── 3-longest-substring-without-repeating-characters ├── 3-longest-substring-without-repeating-characters.cpp ├── NOTES.md └── README.md ├── 300-longest-increasing-subsequence ├── 300-longest-increasing-subsequence.cpp ├── NOTES.md └── README.md ├── 31-next-permutation ├── 31-next-permutation.cpp ├── NOTES.md └── README.md ├── 315-count-of-smaller-numbers-after-self ├── 315-count-of-smaller-numbers-after-self.cpp ├── NOTES.md └── README.md ├── 322-coin-change ├── 322-coin-change.cpp ├── NOTES.md └── README.md ├── 326-power-of-three ├── 326-power-of-three.cpp ├── NOTES.md └── README.md ├── 336-palindrome-pairs ├── 336-palindrome-pairs.cpp └── NOTES.md ├── 342-power-of-four ├── 342-power-of-four.cpp ├── NOTES.md └── README.md ├── 344-reverse-string ├── 344-reverse-string.cpp ├── NOTES.md └── README.md ├── 35-search-insert-position ├── 35-search-insert-position.cpp ├── NOTES.md └── README.md ├── 363-max-sum-of-rectangle-no-larger-than-k ├── 363-max-sum-of-rectangle-no-larger-than-k.cpp ├── NOTES.md └── README.md ├── 377-combination-sum-iv ├── 377-combination-sum-iv.cpp ├── NOTES.md └── README.md ├── 383-ransom-note ├── 383-ransom-note.cpp ├── NOTES.md └── README.md ├── 384-shuffle-an-array ├── 384-shuffle-an-array.cpp ├── NOTES.md └── README.md ├── 393-utf-8-validation ├── 393-utf-8-validation.cpp ├── NOTES.md └── README.md ├── 3sum ├── 3sum.cpp └── README.md ├── 4-median-of-two-sorted-arrays ├── 4-median-of-two-sorted-arrays.cpp ├── NOTES.md └── README.md ├── 412-fizz-buzz ├── 412-fizz-buzz.cpp ├── NOTES.md └── README.md ├── 416-partition-equal-subset-sum ├── 416-partition-equal-subset-sum.cpp ├── NOTES.md └── README.md ├── 42-trapping-rain-water ├── 42-trapping-rain-water.cpp ├── NOTES.md └── README.md ├── 429-n-ary-tree-level-order-traversal ├── 429-n-ary-tree-level-order-traversal.cpp ├── NOTES.md └── README.md ├── 44-wildcard-matching ├── 44-wildcard-matching.cpp ├── NOTES.md └── README.md ├── 442-find-all-duplicates-in-an-array ├── 442-find-all-duplicates-in-an-array.cpp ├── NOTES.md └── README.md ├── 458-poor-pigs ├── 458-poor-pigs.cpp ├── NOTES.md └── README.md ├── 470-implement-rand10-using-rand7 ├── 470-implement-rand10-using-rand7.cpp ├── NOTES.md └── README.md ├── 474-ones-and-zeroes ├── 474-ones-and-zeroes.cpp ├── NOTES.md └── README.md ├── 48-rotate-image ├── 48-rotate-image.cpp ├── NOTES.md └── README.md ├── 494-target-sum ├── 494-target-sum.cpp ├── NOTES.md └── README.md ├── 5-longest-palindromic-substring ├── 5-longest-palindromic-substring.cpp ├── NOTES.md └── README.md ├── 50-powx-n ├── 50-powx-n.cpp ├── NOTES.md └── README.md ├── 509-fibonacci-number ├── 509-fibonacci-number.cpp ├── NOTES.md └── README.md ├── 53-maximum-subarray ├── 53-maximum-subarray.cpp ├── NOTES.md └── README.md ├── 543-diameter-of-binary-tree ├── 543-diameter-of-binary-tree.cpp ├── NOTES.md └── README.md ├── 557-reverse-words-in-a-string-iii ├── 557-reverse-words-in-a-string-iii.cpp ├── NOTES.md └── README.md ├── 56-merge-intervals ├── 56-merge-intervals.cpp ├── NOTES.md └── README.md ├── 567-permutation-in-string ├── 567-permutation-in-string.cpp ├── NOTES.md └── README.md ├── 572-subtree-of-another-tree ├── 572-subtree-of-another-tree.cpp ├── NOTES.md └── README.md ├── 576-out-of-boundary-paths ├── 576-out-of-boundary-paths.cpp ├── NOTES.md └── README.md ├── 607-sales-person ├── 607-sales-person.sql ├── NOTES.md └── README.md ├── 609-find-duplicate-file-in-system ├── 609-find-duplicate-file-in-system.cpp ├── NOTES.md └── README.md ├── 62-unique-paths ├── 62-unique-paths.cpp ├── NOTES.md └── README.md ├── 629-k-inverse-pairs-array ├── 629-k-inverse-pairs-array.cpp ├── NOTES.md └── README.md ├── 630-course-schedule-iii ├── 630-course-schedule-iii.cpp ├── NOTES.md └── README.md ├── 64-minimum-path-sum ├── 64-minimum-path-sum.cpp ├── NOTES.md └── README.md ├── 647-palindromic-substrings ├── 647-palindromic-substrings.cpp ├── NOTES.md └── README.md ├── 653-two-sum-iv-input-is-a-bst ├── 653-two-sum-iv-input-is-a-bst.cpp ├── NOTES.md └── README.md ├── 695-max-area-of-island ├── 695-max-area-of-island.cpp ├── NOTES.md └── README.md ├── 70-climbing-stairs ├── 70-climbing-stairs.cpp └── NOTES.md ├── 700-search-in-a-binary-search-tree ├── NOTES.md └── README.md ├── 703-kth-largest-element-in-a-stream ├── 703-kth-largest-element-in-a-stream.cpp ├── NOTES.md └── README.md ├── 704-binary-search ├── 704-binary-search.cpp ├── NOTES.md └── README.md ├── 718-maximum-length-of-repeated-subarray ├── 718-maximum-length-of-repeated-subarray.cpp ├── NOTES.md └── README.md ├── 72-edit-distance ├── 72-edit-distance.cpp ├── NOTES.md └── README.md ├── 724-find-pivot-index ├── 724-find-pivot-index.cpp ├── NOTES.md └── README.md ├── 73-set-matrix-zeroes ├── 73-set-matrix-zeroes.cpp ├── NOTES.md └── README.md ├── 733-flood-fill ├── 733-flood-fill.cpp ├── NOTES.md └── README.md ├── 74-search-a-2d-matrix ├── 74-search-a-2d-matrix.cpp ├── NOTES.md └── README.md ├── 75-sort-colors ├── 75-sort-colors.cpp ├── NOTES.md └── README.md ├── 771-jewels-and-stones ├── 771-jewels-and-stones.cpp ├── NOTES.md └── README.md ├── 792-number-of-matching-subsequences ├── 792-number-of-matching-subsequences.cpp ├── NOTES.md └── README.md ├── 814-binary-tree-pruning └── README.md ├── 841-lclighter-data-idlgt257723750-data-bundle-id0-stylebackground-image-linear-gradienttransparent-0-transparent-calc50-4px-rgb204-242-241-calc50-4px-rgb204-242-241-100-transition-background-position-120ms-ease-in-out-0s-padding-120ms-ease-in-out-0s-background-size-100-200-background-position-initial-user-select-auto-keys-and-rooms-lclighterdiv-classlinerthreadicon-linerfirst-data-highlight-id257723750-data-bundle-id0-idlgt257723750-stylebackground-image-url-and-quot-https-profilegetlinercom-liner-service-bucket-user-photo-default-color-10-wsvg-and-quot-user-select-auto-div-classlinerthreadicon-dim-styleuser-select-auto-div-div-classlinerthreadicon-mentioned-styleuser-select-auto-div-classlinerthreadicon-mentionedimg-styleuser-select-auto-div-div-div-classlinerthreadicon-onlyme-styleuser-select-auto-div-classlinerthreadicon-onlymeimg-styleuser-select-auto-div-div-div ├── 841-lclighter-data-idlgt257723750-data-bundle-id0-stylebackground-image-linear-gradienttransparent-0-transparent-calc50-4px-rgb204-242-241-calc50-4px-rgb204-242-241-100-transition-background-position-120ms-ease-in-out-0s-padding-120ms-ease-in-out-0s-background-size-100-200-background-position-initial-user-select-auto-keys-and-rooms-lclighterdiv-classlinerthreadicon-linerfirst-data-highlight-id257723750-data-bundle-id0-idlgt257723750-stylebackground-image-url-and-quot-https-profilegetlinercom-liner-service-bucket-user-photo-default-color-10-wsvg-and-quot-user-select-auto-div-classlinerthreadicon-dim-styleuser-select-auto-div-div-classlinerthreadicon-mentioned-styleuser-select-auto-div-classlinerthreadicon-mentionedimg-styleuser-select-auto-div-div-div-classlinerthreadicon-onlyme-styleuser-select-auto-div-classlinerthreadicon-onlymeimg-styleuser-select-auto-div-div-div.cpp ├── NOTES.md └── README.md ├── 852-peak-index-in-a-mountain-array ├── 852-peak-index-in-a-mountain-array.cpp ├── NOTES.md └── README.md ├── 867-transpose-matrix ├── 867-transpose-matrix.cpp ├── NOTES.md └── README.md ├── 869-reordered-power-of-2 ├── 869-reordered-power-of-2.cpp ├── NOTES.md └── README.md ├── 871-minimum-number-of-refueling-stops ├── 871-minimum-number-of-refueling-stops.cpp ├── NOTES.md └── README.md ├── 876-middle-of-the-linked-list ├── 876-middle-of-the-linked-list.cpp ├── NOTES.md └── README.md ├── 88-merge-sorted-array ├── 88-merge-sorted-array.cpp ├── NOTES.md └── README.md ├── 91-decode-ways ├── 91-decode-ways.cpp ├── NOTES.md └── README.md ├── 92-reverse-linked-list-ii ├── 92-reverse-linked-list-ii.cpp ├── NOTES.md └── README.md ├── 94-binary-tree-inorder-traversal ├── 94-binary-tree-inorder-traversal.cpp ├── NOTES.md └── README.md ├── 948-bag-of-tokens ├── 948-bag-of-tokens.cpp ├── NOTES.md └── README.md ├── 967-numbers-with-same-consecutive-differences ├── 967-numbers-with-same-consecutive-differences.cpp ├── NOTES.md └── README.md ├── 977-squares-of-a-sorted-array ├── 977-squares-of-a-sorted-array.cpp ├── NOTES.md └── README.md ├── 98-validate-binary-search-tree ├── 98-validate-binary-search-tree.cpp ├── NOTES.md └── README.md ├── 987-vertical-order-traversal-of-a-binary-tree ├── 987-vertical-order-traversal-of-a-binary-tree.cpp └── README.md ├── A Game of LCM - GFG ├── README.md └── a-game-of-lcm.cpp ├── A difference of values and indexes - GFG ├── README.md └── a-difference-of-values-and-indexes.cpp ├── A. Petya and Strings.cpp ├── AVL Tree Deletion - GFG ├── README.md └── avl-tree-deletion.cpp ├── Abdul bari Mastering Data Structures & Algorithms using C and C++ └── .cpp ├── Absolute List Sorting - GFG ├── README.md └── absolute-list-sorting.cpp ├── Absolute difference divisible by K - GFG ├── README.md └── absolute-difference-divisible-by-k.cpp ├── Add Minimum Characters - GFG ├── README.md └── add-minimum-characters.cpp ├── Adding Ones - GFG ├── README.md └── adding-ones.cpp ├── Aggressive Cows - GFG ├── README.md └── aggressive-cows.cpp ├── Akku and Binary Numbers - GFG ├── README.md └── akku-and-binary-numbers.cpp ├── Alex Travelling - GFG ├── README.md └── alex-travelling.cpp ├── Alternate Vowel and Consonant String - GFG ├── README.md └── alternate-vowel-and-consonant-string.cpp ├── Another Coin Change Problem - GFG ├── README.md └── another-coin-change-problem.cpp ├── Arithmetic Number - GFG ├── README.md └── arithmetic-number.cpp ├── Arranging the array - GFG ├── README.md └── arranging-the-array.cpp ├── Array Operations - GFG ├── README.md └── array-operations.cpp ├── Array Pair Sum Divisibility Problem - GFG ├── README.md └── array-pair-sum-divisibility-problem.cpp ├── Articulation Point - I - GFG ├── README.md └── articulation-point-i.cpp ├── Asteroid Collision - GFG ├── README.md └── asteroid-collision.cpp ├── Avoid Explosion - GFG ├── README.md └── avoid-explosion.cpp ├── BFS of graph - GFG ├── README.md └── bfs-of-graph.cpp ├── BST Downward Traversal - GFG ├── README.md └── bst-downward-traversal.cpp ├── BST Maximum Difference - GFG ├── README.md └── bst-maximum-difference.cpp ├── Balanced string - GFG ├── README.md └── balanced-string.cpp ├── Best Node - GFG ├── README.md └── best-node.cpp ├── Bheem Wants Ladoos - GFG ├── README.md └── bheem-wants-ladoos.cpp ├── Binary Modulo - GFG ├── README.md └── binary-modulo.cpp ├── Binary Tree to BST - GFG ├── README.md └── binary-tree-to-bst.cpp ├── Binary matrix having maximum number of 1s - GFG ├── README.md └── binary-matrix-having-maximum-number-of-1s.cpp ├── Binary tree all concepts in c++ └── binary tree all codes.cpp ├── Black and White - GFG ├── README.md └── black-and-white.cpp ├── Bottom View of Binary Tree - GFG ├── README.md └── bottom-view-of-binary-tree.cpp ├── Break a number - GFG ├── README.md └── break-a-number.cpp ├── Build the smallest - GFG ├── README.md └── build-the-smallest.cpp ├── Burst Balloons - GFG ├── README.md └── burst-balloons.cpp ├── Bus Conductor - GFG ├── README.md └── bus-conductor.cpp ├── C++ template.cpp ├── Cake Distribution Problem - GFG ├── README.md └── cake-distribution-problem.cpp ├── Carpet into Box - GFG └── carpet-into-box.cpp ├── Check if Tree is Isomorphic - GFG ├── README.md └── check-if-tree-is-isomorphic.cpp ├── Check if it is possible to convert one string into another with given constraints - GFG ├── README.md └── check-if-it-is-possible-to-convert-one-string-into-another-with-given-constraints.cpp ├── Coin Change - GFG ├── README.md └── coin-change.cpp ├── Complement - GFG ├── README.md └── complement.cpp ├── Connect Nodes at Same Level - GFG ├── README.md └── connect-nodes-at-same-level.cpp ├── Construct a Full Binary Tree - GFG ├── README.md └── construct-a-full-binary-tree.cpp ├── Container With Most Water - GFG ├── README.md └── container-with-most-water.cpp ├── Convert an array to reduced form - GFG ├── README.md └── convert-an-array-to-reduced-form.cpp ├── Copy Set Bits in Range - GFG ├── README.md └── copy-set-bits-in-range.cpp ├── Count Binary Strings With No Consecutive 1s - GFG ├── README.md └── count-binary-strings-with-no-consecutive-1s.cpp ├── Count Lucky Permutations - GFG ├── README.md └── count-lucky-permutations.cpp ├── Count Special Numbers - GFG ├── README.md └── count-special-numbers.cpp ├── Count Total Setbits - GFG ├── README.md └── count-total-setbits.cpp ├── Count even length - GFG ├── README.md └── count-even-length.cpp ├── Count nodes of linked list - GFG ├── README.md └── count-nodes-of-linked-list.cpp ├── Count number of hops - GFG ├── README.md └── count-number-of-hops.cpp ├── Count number of substrings - GFG ├── README.md └── count-number-of-substrings.cpp ├── Count the Number of Full Binary Trees - GFG ├── README.md └── count-the-number-of-full-binary-trees.cpp ├── Count the Substring - GFG ├── README.md └── count-the-substring.cpp ├── Count the Substrings - GFG ├── README.md └── count-the-substrings.cpp ├── Count the subarrays having product less than k - GFG ├── README.md └── count-the-subarrays-having-product-less-than-k.cpp ├── Cutting Binary String - GFG ├── README.md └── cutting-binary-string.cpp ├── Cutting Rectangles - GFG ├── README.md └── cutting-rectangles.cpp ├── Decimal to binary - GFG ├── README.md └── decimal-to-binary.c ├── Delete a Node in Single Linked List - GFG ├── README.md └── delete-a-node-in-single-linked-list.cpp ├── Delete middle element of a stack - GFG ├── README.md └── delete-middle-element-of-a-stack.cpp ├── Delete nodes having greater value on right - GFG ├── README.md └── delete-nodes-having-greater-value-on-right.cpp ├── Distance of nearest cell having 1 - GFG ├── README.md └── distance-of-nearest-cell-having-1.cpp ├── Distinct Coloring - GFG ├── README.md └── distinct-coloring.cpp ├── Distinct Difference - GFG ├── README.md └── distinct-difference.cpp ├── Divide in Incremental Groups - GFG ├── README.md └── divide-in-incremental-groups.cpp ├── Dominant Pairs - GFG ├── README.md └── dominant-pairs.cpp ├── Equal Left and Right Subarray Sum - GFG ├── README.md └── equal-left-and-right-subarray-sum.cpp ├── Even Swap - GFG ├── README.md └── even-swap.cpp ├── Expression Add Operators - GFG ├── README.md └── expression-add-operators.cpp ├── Fill the Matrix - GFG └── README.md ├── Find Common Nodes in two BSTs - GFG └── README.md ├── Find Kth permutation - GFG ├── README.md └── find-kth-permutation.cpp ├── Find Maximum Equal sum of Three Stacks - GFG ├── README.md └── find-maximum-equal-sum-of-three-stacks.cpp ├── Find Number - GFG ├── README.md └── find-number.cpp ├── Find Total Time Taken - GFG ├── README.md └── find-total-time-taken.cpp ├── Find k-th smallest element in given n ranges - GFG ├── README.md └── find-kth-smallest-element-in-given-n-ranges.cpp ├── Find kth element of spiral matrix - GFG ├── README.md └── find-kth-element-of-spiral-matrix.cpp ├── Find minimum number of Laptops required - GFG ├── README.md └── find-minimum-number-of-laptops-required.cpp ├── Find the Closest Element in BST - GFG ├── README.md └── find-the-closest-element-in-bst.cpp ├── Find the first node of loop in linked list - GFG ├── README.md └── find-the-first-node-of-loop-in-linked-list.cpp ├── Find the inorder predecessor successor of a given Key in BST.cpp ├── Find the longest string - GFG ├── README.md └── find-the-longest-string.cpp ├── Find the maximum GCD of the siblings of a Binary Tree - GFG ├── README.md └── find-the-maximum-gcd-of-the-siblings-of-a-binary-tree.cpp ├── Find the string in grid - GFG └── find-the-string-in-grid.cpp ├── Find triplets with zero sum - GFG ├── README.md └── find-triplets-with-zero-sum.cpp ├── First non-repeating character in a stream - GFG ├── README.md └── first-nonrepeating-character-in-a-stream.cpp ├── Flattening a Linked List - GFG ├── README.md └── flattening-a-linked-list.cpp ├── Fraction pairs with sum 1 - GFG ├── README.md └── fraction-pairs-with-sum-1.cpp ├── Frequency Game - GFG ├── README.md └── frequency-game.cpp ├── Frogs and Jumps - GFG ├── README.md └── frogs-and-jumps.cpp ├── GCD Array - GFG ├── README.md └── gcd-array.cpp ├── Game Of Subsets - GFG ├── README.md └── game-of-subsets.cpp ├── Geek hates too many 1s - GFG ├── README.md └── geek-hates-too-many-1s.cpp ├── Geek's Village and Wells - GFG ├── README.md └── geeks-village-and-wells.cpp ├── Geeks And The String - GFG ├── README.md └── geeks-and-the-string.cpp ├── Geeks Island - GFG ├── README.md └── geeks-island.cpp ├── Good Subtrees - GFG ├── README.md └── good-subtrees.cpp ├── Hamiltonian Path - GFG ├── README.md └── hamiltonian-path.cpp ├── Hands of Straights - GFG ├── README.md └── hands-of-straights.cpp ├── Height of Binary Tree - GFG ├── README.md └── height-of-binary-tree.cpp ├── Implement strstr - GFG ├── README.md └── implement-strstr.cpp ├── Implement two stacks in an array - GFG ├── README.md └── implement-two-stacks-in-an-array.cpp ├── Insert a node in a BST - GFG ├── README.md └── insert-a-node-in-a-bst.cpp ├── Insert in a Sorted List - GFG └── README.md ├── Intersection Point in Y Shaped Linked Lists - GFG ├── README.md └── intersection-point-in-y-shaped-linked-lists.cpp ├── Interview bit └── fast track c++ │ ├── .cpp │ ├── Array.cpp │ ├── Bitset.cpp │ ├── Classes and Objects.cpp │ ├── Comparision Operation & If-Else.cpp │ ├── Conditional or Ternary Expression.cpp │ ├── Cpp Exception Handling.cpp │ ├── Custom Comparator.cpp │ ├── Functions - Basic.cpp │ ├── Hello, World!.cpp │ ├── Inheritance.cpp │ ├── Jump Statements.cpp │ ├── Loops.cpp │ ├── Maps.cpp │ ├── Math Library.cpp │ ├── Pair and Tuple.cpp │ ├── Passing parameters.cpp │ ├── Pointers to Array.cpp │ ├── Pointers.cpp │ ├── Policy based Ds.cpp │ ├── Polymorphism.cpp │ ├── Priority Queue.cpp │ ├── Runtime Polymorphism (Virtual Functions).cpp │ ├── Set and Multiset.cpp │ ├── Stack & Queue.cpp │ ├── StringStream.cpp │ ├── Strings.cpp │ ├── Structures.cpp │ ├── Switch statement.cpp │ ├── Templates.cpp │ ├── Type Conversion.cpp │ ├── Upper & Lower bound.cpp │ ├── Variable and Types.cpp │ └── Vector.cpp ├── Interviewbit Questions └── .cpp ├── Is Binary Number Multiple of 3 - GFG ├── README.md └── is-binary-number-multiple-of-3.cpp ├── Job Sequencing Problem - GFG ├── README.md └── job-sequencing-problem.cpp ├── Knight in Geekland - GFG ├── README.md └── knight-in-geekland.cpp ├── Kth largest element in BST - GFG ├── README.md └── kth-largest-element-in-bst.cpp ├── Kth largest element in BST .cpp ├── Largest Sum Cycle - GFG ├── README.md └── largest-sum-cycle.cpp ├── Largest number possible - GFG ├── README.md └── largest-number-possible.cpp ├── Largest subtree sum in a tree - GFG ├── README.md └── largest-subtree-sum-in-a-tree.cpp ├── Last cell in a Matrix - GFG ├── README.md └── last-cell-in-a-matrix.cpp ├── Last modified ball - GFG ├── README.md └── last-modified-ball.cpp ├── Leftmost and rightmost nodes of binary tree - GFG ├── README.md └── leftmost-and-rightmost-nodes-of-binary-tree.cpp ├── Lemonade Change - GFG ├── README.md └── lemonade-change.cpp ├── Length of the longest subarray with positive product - GFG ├── README.md └── length-of-the-longest-subarray-with-positive-product.cpp ├── Level of Nodes - GFG ├── README.md └── level-of-nodes.cpp ├── Longest Increasing Subsequence - GFG ├── README.md └── longest-increasing-subsequence.cpp ├── Longest Palindrome in a String - GFG ├── README.md └── longest-palindrome-in-a-string.cpp ├── Longest Palindromic Subsequence - GFG ├── README.md └── longest-palindromic-subsequence.cpp ├── Longest Repeating Subsequence - GFG ├── README.md └── longest-repeating-subsequence.cpp ├── Lucky Numbers - GFG ├── README.md └── lucky-numbers.cpp ├── Make Array Elements Equal - GFG ├── README.md └── make-array-elements-equal.cpp ├── Make Palindrome - GFG ├── README.md └── make-palindrome.cpp ├── Make array elements unique - GFG ├── README.md └── make-array-elements-unique.cpp ├── Matchsticks game - GFG ├── README.md └── matchsticks-game.cpp ├── Max Coins - GFG ├── README.md └── max-coins.cpp ├── Max Level Sum in Binary Tree - GFG ├── README.md └── max-level-sum-in-binary-tree.cpp ├── Max Sum without Adjacents - GFG ├── README.md └── max-sum-without-adjacents.cpp ├── Maximum Depth Of Binary Tree - GFG ├── README.md └── maximum-depth-of-binary-tree.cpp ├── Maximum Diamonds - GFG ├── README.md └── maximum-diamonds.cpp ├── Maximum Identical Bowls - GFG ├── README.md └── maximum-identical-bowls.cpp ├── Maximum Index - GFG ├── README.md └── maximum-index.cpp ├── Maximum Intersecting Lines - GFG ├── README.md └── maximum-intersecting-lines.cpp ├── Maximum Length - GFG ├── README.md └── maximum-length.cpp ├── Maximum Number of Toys - GFG ├── README.md └── maximum-number-of-toys.cpp ├── Maximum Number of coins - GFG ├── README.md └── maximum-number-of-coins.cpp ├── Maximum Possible Value - GFG ├── README.md └── maximum-possible-value.cpp ├── Maximum Profit By Choosing A Subset Of Intervals - GFG ├── README.md └── maximum-profit-by-choosing-a-subset-of-intervals.cpp ├── Maximum Sub Array - GFG ├── README.md └── maximum-sub-array.cpp ├── Maximum Value - GFG └── maximum-value.cpp ├── Maximum Weight Node - GFG ├── README.md └── maximum-weight-node.cpp ├── Median of the Subarrays - GFG ├── README.md └── median-of-the-subarrays.cpp ├── Merge Without Extra Space - GFG ├── README.md └── merge-without-extra-space.cpp ├── Middle of Three .cpp ├── Minimize number of Students to be removed - GFG ├── README.md └── minimize-number-of-students-to-be-removed.cpp ├── Minimize the sum - GFG └── README.md ├── Minimum BST Sum Subtree - GFG ├── README.md └── minimum-bst-sum-subtree.cpp ├── Minimum Integer - GFG ├── README.md └── minimum-integer.cpp ├── Minimum Multiplications to reach End - GFG ├── README.md └── minimum-multiplications-to-reach-end.cpp ├── Minimum Number - GFG ├── README.md └── minimum-number.cpp ├── Minimum Steps Required - GFG ├── README.md └── minimum-steps-required.cpp ├── Minimum X (xor) A - GFG ├── README.md └── minimum-x-xor-a.cpp ├── Mirror Tree - GFG ├── README.md └── mirror-tree.cpp ├── Mirror Tree.cpp ├── Missing number in matrix - GFG ├── README.md └── missing-number-in-matrix.cpp ├── Modify Linked List-1 - GFG ├── README.md └── modify-linked-list1.cpp ├── Mother Vertex - GFG ├── README.md └── mother-vertex.cpp ├── Multiply two strings - GFG ├── README.md └── multiply-two-strings.cpp ├── Nearest smaller tower - GFG ├── README.md └── nearest-smaller-tower.cpp ├── Next Greater Element - GFG ├── README.md └── next-greater-element.cpp ├── Next Happy Number - GFG ├── README.md └── next-happy-number.cpp ├── Non Repeating Character - GFG ├── README.md └── non-repeating-character.cpp ├── Normal BST to Balanced BST - GFG ├── README.md └── normal-bst-to-balanced-bst.cpp ├── Nth Fibonacci Number - GFG ├── README.md └── nth-fibonacci-number.cpp ├── Nth catalan number - GFG ├── README.md └── nth-catalan-number.cpp ├── Nth node from end of linked list - GFG ├── README.md └── nth-node-from-end-of-linked-list.cpp ├── Number of 1 Bits - GFG ├── README.md └── number-of-1-bits.cpp ├── Number of Good Components - GFG ├── README.md └── number-of-good-components.cpp ├── Number of Subarrays of 0's - GFG ├── README.md └── number-of-subarrays-of-0s.cpp ├── Optimal Array - GFG ├── README.md └── optimal-array.cpp ├── Palindrome with minimum sum - GFG ├── README.md └── palindrome-with-minimum-sum.cpp ├── Partition Equal Subset Sum - GFG ├── README.md └── partition-equal-subset-sum.cpp ├── Partition the Array - GFG ├── README.md └── partition-the-array.cpp ├── Perfect Numbers - GFG ├── README.md └── perfect-numbers.cpp ├── Perfect Sum Problem - GFG ├── README.md └── perfect-sum-problem.cpp ├── Power Of Numbers - GFG ├── README.md └── power-of-numbers.cpp ├── Powerfull Integer - GFG ├── README.md └── powerfull-integer.cpp ├── Predecessor and Successor - GFG ├── README.md └── predecessor-and-successor.cpp ├── Prefix Suffix String - GFG ├── README.md └── prefix-suffix-string.cpp ├── Prefix match with other strings - GFG ├── README.md └── prefix-match-with-other-strings.cpp ├── Print adjacency list - GFG ├── README.md └── print-adjacency-list.cpp ├── Q49 Combination Sum.cpp ├── Q51 Palindrome Partitioning .cpp ├── Q9. next_permutation.cpp ├── Queue Reversal - GFG ├── README.md └── queue-reversal.cpp ├── README.md ├── Rearrange Array Alternately - GFG ├── README.md └── rearrange-array-alternately.cpp ├── Rearrange an array with O(1) extra space - GFG ├── README.md └── rearrange-an-array-with-o1-extra-space.cpp ├── Redundant Parenthesis - GFG ├── README.md └── redundant-parenthesis.cpp ├── Remainder on dividing by 11 - GFG ├── README.md └── remainder-on-dividing-by-11.py ├── Remove and Reverse - GFG ├── README.md └── remove-and-reverse.cpp ├── Remove duplicates from an unsorted linked list - GFG ├── README.md └── remove-duplicates-from-an-unsorted-linked-list.cpp ├── Remove the balls - GFG ├── README.md └── remove-the-balls.cpp ├── Reorder List - GFG ├── README.md └── reorder-list.cpp ├── Replace O's with X's - GFG ├── README.md └── replace-os-with-xs.cpp ├── Reverse Coding - GFG ├── README.md └── reverse-coding.cpp ├── Reverse The String.cpp ├── Reverse a Linked List in groups of given size - GFG ├── README.md └── reverse-a-linked-list-in-groups-of-given-size.cpp ├── Reverse both parts - GFG ├── README.md └── reverse-both-parts.cpp ├── Reversing the equation - GFG ├── README.md └── reversing-the-equation.cpp ├── Right View of Binary Tree - GFG ├── README.md └── right-view-of-binary-tree.cpp ├── Roman Number to Integer - GFG ├── README.md └── roman-number-to-integer.cpp ├── Santa Banta - GFG ├── README.md └── santa-banta.cpp ├── Scrambled String - GFG ├── README.md └── scrambled-string.cpp ├── Second smallest number - GFG ├── README.md └── second-smallest-number.cpp ├── Select Nodes - GFG ├── README.md └── select-nodes.cpp ├── Shortest Path Using Atmost One Curved Edge - GFG ├── README.md └── shortest-path-using-atmost-one-curved-edge.cpp ├── Shortest Path by Removing K walls - GFG ├── README.md └── shortest-path-by-removing-k-walls.cpp ├── Shortest Prime Path - GFG ├── README.md └── shortest-prime-path.cpp ├── Shortest XY distance in Grid - GFG ├── README.md └── shortest-xy-distance-in-grid.cpp ├── Shy Geek - GFG ├── README.md └── shy-geek.cpp ├── Single valued subtree - GFG ├── README.md └── single-valued-subtree.cpp ├── Smaller Sum - GFG ├── README.md └── smaller-sum.cpp ├── Smallest Positive missing number - GFG ├── README.md └── smallest-positive-missing-number.cpp ├── Solve the Sudoku - GFG ├── README.md └── solve-the-sudoku.cpp ├── Special Digits - GFG ├── README.md └── special-digits.cpp ├── Special Palindrome Substrings - GFG ├── README.md └── special-palindrome-substrings.cpp ├── Split Array Largest Sum - GFG ├── README.md └── split-array-largest-sum.cpp ├── Stickler Thief - GFG ├── README.md └── stickler-thief.cpp ├── Stock buy and sell II - GFG ├── README.md └── stock-buy-and-sell-ii.cpp ├── String Mirror - GFG ├── README.md └── string-mirror.cpp ├── String Permutations - GFG ├── README.md └── string-permutations.cpp ├── String rp or pr - GFG ├── README.md └── string-rp-or-pr.cpp ├── Striver Sheet 180 QuestionQ16. Unique Paths.cpp ├── Striver Sheet 180 Questions ├── DAY 6.CPP ├── DAY 9.cpp ├── DAY5.CPP ├── Q1 Sort Colors(Efficient Approach).cpp ├── Q1 Sort Colors.cpp ├── Q1. SOrt colors.cpp ├── Q11. Stock Buy and Sell.cpp ├── Q12. Rotate Matrix.cpp ├── Q12. rotate_image.cpp ├── Q13. Search in a 2D matrix.cpp ├── Q13.Search a 2D Matrix.cpp ├── Q14 pow(x,n).cpp ├── Q14.Pow(X,n).cpp ├── Q15. Majority Element(n*0.5 times).cpp ├── Q15.Majority Element (>N2 times).cpp ├── Q17. Grid unique paths.cpp ├── Q17.Grid Unique Paths.cpp ├── Q19. Two Sum.cpp ├── Q19.2sum.cpp ├── Q2.Find Missing And Repeating.cpp ├── Q20.4sum prroblem.cpp ├── Q21.longestConsecutiveSequence.cpp ├── Q22.Largest Subarray with 0 sum.cpp ├── Q23.Count number of subarrays with given XOR.cpp ├── Q24.Longest substring without repeat.cpp ├── Q25.Reverse Linked List.cpp ├── Q26. Middle of the Linked List.cpp ├── Q27. Merge Two Sorted Lists.cpp ├── Q29. Remove Nth Node From End of Linked List.cpp ├── Q3.Merge Without Extra Space .cpp ├── Q30. Delete Node in a Linked List.cpp ├── Q31. Add Two Numbers.cpp ├── Q32. Intersection point of two Linked Lists.cpp ├── Q33 Linked List Cycle.cpp ├── Q34. Reverse Nodes in k-Group Hard.cpp ├── Q35 Palindrome Linked List.cpp ├── Q36 Linked List Cycle II.cpp ├── Q37 Rotate List.cpp ├── Q38. Copy List with Random Pointer.cpp ├── Q39. 3Sum.cpp ├── Q4.Maximum Subarray(O(n) Time complexity)(Kadane's algorithms).cpp ├── Q4.Maximum Subarray(O(n3) Time complexity).cpp ├── Q40. Trapping Rain Water.cpp ├── Q41. Remove Duplicates from Sorted Array.cpp ├── Q42.Max Consecutive Ones cpp ├── Q43. N meetings in one room .cpp ├── Q44. minimum no of platform required in a railway .cpp ├── Q45 Job Sequencing Problem .cpp ├── Q46. Fractional Knapsack .cpp ├── Q47 Subset sum1.cpp ├── Q49 Combination Sum.cpp ├── Q5. Merge Overlapping Subintervals.cpp ├── Q51 Palindrome Partitioning .cpp ├── Q52 K-th Permutation Sequence .cpp ├── Q6. Find the duplicate in an array of N+1 integers.cpp ├── Q7. Set_matrix_zeroes.cpp ├── Q7.Set Matrix Zeros.cpp ├── Q8. pascals_triangle.cpp ├── Q8.Pascals Triangle.cpp └── Q9.Next Permutations.cpp ├── Subset Sums - GFG ├── README.md └── subset-sums.cpp ├── Subtree In N-ary Tree - GFG ├── README.md └── subtree-in-nary-tree.cpp ├── Surround the 1's - GFG ├── README.md └── surround-the-1s.cpp ├── Task Scheduler - GFG ├── README.md └── task-scheduler.cpp ├── Taxi Booking - GFG ├── README.md └── taxi-booking.cpp ├── Ticket Counter - GFG ├── README.md └── ticket-counter.cpp ├── Top View of Binary Tree - GFG ├── README.md └── top-view-of-binary-tree.cpp ├── Topological sort - GFG ├── README.md └── topological-sort.cpp ├── Total Cuts - GFG ├── README.md └── total-cuts.cpp ├── Total Decoding Messages - GFG ├── README.md └── total-decoding-messages.cpp ├── Trace Path - GFG ├── README.md └── trace-path.cpp ├── Transform to Sum Tree - GFG ├── README.md └── transform-to-sum-tree.cpp ├── Transitive closure of a Graph - GFG ├── README.md └── transitive-closure-of-a-graph.cpp ├── Transpose of Matrix - GFG ├── README.md └── transpose-of-matrix.cpp ├── Tree Transformation - GFG └── tree-transformation.cpp ├── Two Repeated Elements - GFG ├── README.md └── two-repeated-elements.cpp ├── Type it! - GFG ├── README.md └── type-it.cpp ├── Unequal Arrays - GFG ├── README.md └── unequal-arrays.cpp ├── Union of Two Linked Lists - GFG ├── README.md └── union-of-two-linked-lists.cpp ├── Unique Number of Occurrences - GFG ├── README.md └── unique-number-of-occurrences.cpp ├── Unique Paths in a Grid - GFG ├── README.md └── unique-paths-in-a-grid.cpp ├── Unique rows in boolean matrix - GFG ├── README.md └── unique-rows-in-boolean-matrix.cpp ├── Update Queries - GFG ├── README.md └── update-queries.cpp ├── Valid Compressed String - GFG ├── README.md └── valid-compressed-string.cpp ├── Walls Coloring - GFG └── walls-coloring.cpp ├── Walls Coloring II - GFG ├── README.md └── walls-coloring-ii.cpp ├── Wifi Range - GFG ├── README.md └── wifi-range.cpp ├── Wine Buying and Selling - GFG ├── README.md └── wine-buying-and-selling.cpp ├── Word Search - GFG ├── README.md └── word-search.cpp ├── Yet another query problem - GFG ├── README.md └── yet-another-query-problem.cpp ├── Zero Sum Subarrays - GFG ├── README.md └── zero-sum-subarrays.cpp ├── binary tree all codes and concepts.cpp ├── binary-search ├── README.md └── binary-search.cpp ├── binary-tree-inorder-traversal ├── README.md └── binary-tree-inorder-traversal.cpp ├── binary-tree-level-order-traversal ├── README.md └── binary-tree-level-order-traversal.cpp ├── binary-tree-preorder-traversal ├── README.md └── binary-tree-preorder-traversal.cpp ├── build-array-from-permutation ├── README.md └── build-array-from-permutation.cpp ├── can-place-flowers ├── README.md └── can-place-flowers.cpp ├── climbing-stairs ├── README.md └── climbing-stairs.cpp ├── combination-sum ├── README.md └── combination-sum.cpp ├── concatenation-of-array ├── README.md └── concatenation-of-array.cpp ├── container-with-most-water ├── README.md └── container-with-most-water.cpp ├── contains-duplicate ├── README.md └── contains-duplicate.cpp ├── convert-sorted-array-to-binary-search-tree ├── README.md └── convert-sorted-array-to-binary-search-tree.cpp ├── count-and-say ├── README.md └── count-and-say.cpp ├── counting frequency of each element in an array .cpp ├── counting-bits ├── README.md └── counting-bits.cpp ├── diagonal-traverse-ii ├── README.md └── diagonal-traverse-ii.cpp ├── difference of index of largest digit and smallest digit.c ├── divide-two-integers ├── README.md └── divide-two-integers.cpp ├── fibonacci-number ├── README.md └── fibonacci-number.cpp ├── final-value-of-variable-after-performing-operations ├── README.md └── final-value-of-variable-after-performing-operations.cpp ├── find-first-and-last-position-of-element-in-sorted-array ├── README.md └── find-first-and-last-position-of-element-in-sorted-array.cpp ├── find-target-indices-after-sorting-array ├── README.md └── find-target-indices-after-sorting-array.cpp ├── find-the-duplicate-number ├── README.md └── find-the-duplicate-number.cpp ├── find-winner-on-a-tic-tac-toe-game ├── README.md └── find-winner-on-a-tic-tac-toe-game.cpp ├── first-bad-version ├── README.md └── first-bad-version.cpp ├── first-unique-character-in-a-string ├── README.md └── first-unique-character-in-a-string.cpp ├── generate-parentheses ├── README.md └── generate-parentheses.cpp ├── how-many-numbers-are-smaller-than-the-current-number ├── README.md └── how-many-numbers-are-smaller-than-the-current-number.cpp ├── implement-queue-using-stacks ├── README.md └── implement-queue-using-stacks.cpp ├── implement-stack-using-queues ├── README.md └── implement-stack-using-queues.cpp ├── implement-strstr ├── README.md └── implement-strstr.cpp ├── important stl.cpp ├── k largest elements - GFG ├── README.md └── k-largest-elements.cpp ├── k-th smallest element in BST - GFG ├── README.md └── kth-smallest-element-in-bst.cpp ├── kth smallest element.cpp ├── largest and second largest digit in a num.c ├── length-of-last-word ├── README.md └── length-of-last-word.cpp ├── lighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-1658-lighterlighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-lighterlighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-minimum-operations-to-reduce-x-to-zero-lighter ├── NOTES.md ├── README.md └── lighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-1658-lighterlighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-lighterlighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-minimum-operations-to-reduce-x-to-zero-lighter.cpp ├── longest-common-prefix ├── README.md └── longest-common-prefix.cpp ├── longest-palindromic-substring ├── README.md └── longest-palindromic-substring.cpp ├── lowest-common-ancestor-of-a-binary-tree ├── README.md └── lowest-common-ancestor-of-a-binary-tree.cpp ├── maximum-depth-of-binary-tree ├── README.md └── maximum-depth-of-binary-tree.cpp ├── merge-sorted-array ├── README.md └── merge-sorted-array.cpp ├── merge_intervals.cpp ├── min-stack ├── README.md └── min-stack.cpp ├── minimum-insertion-steps-to-make-a-string-palindrome ├── README.md └── minimum-insertion-steps-to-make-a-string-palindrome.cpp ├── missing-number ├── README.md └── missing-number.cpp ├── move-zeroes ├── README.md └── move-zeroes.cpp ├── n-th-tribonacci-number ├── README.md └── n-th-tribonacci-number.cpp ├── nCr - GFG ├── README.md └── n-cr.cpp ├── next-greater-element-i ├── README.md └── next-greater-element-i.cpp ├── number-of-1-bits ├── README.md └── number-of-1-bits.cpp ├── palindrome-number ├── README.md └── palindrome-number.py ├── perfect-number ├── README.md └── perfect-number.cpp ├── plus-one ├── README.md └── plus-one.cpp ├── power-of-three ├── README.md └── power-of-three.cpp ├── power-of-two ├── README.md └── power-of-two.cpp ├── recover-binary-search-tree ├── README.md └── recover-binary-search-tree.cpp ├── remove-duplicates-from-sorted-array ├── README.md └── remove-duplicates-from-sorted-array.cpp ├── remove-duplicates-from-sorted-list ├── README.md └── remove-duplicates-from-sorted-list.cpp ├── reverse-bits ├── README.md └── reverse-bits.cpp ├── reverse-integer ├── README.md └── reverse-integer.cpp ├── reverse-string ├── README.md └── reverse-string.cpp ├── reverse-words-in-a-string ├── README.md └── reverse-words-in-a-string.cpp ├── roman-to-integer ├── README.md └── roman-to-integer.cpp ├── rotate-image ├── README.md └── rotate-image.cpp ├── rotate-string ├── README.md └── rotate-string.cpp ├── running-sum-of-1d-array ├── README.md └── running-sum-of-1d-array.cpp ├── search-in-a-binary-search-tree ├── README.md └── search-in-a-binary-search-tree.cpp ├── search-insert-position ├── README.md └── search-insert-position.cpp ├── shift-2d-grid ├── README.md └── shift-2d-grid.cpp ├── single-element-in-a-sorted-array ├── README.md └── single-element-in-a-sorted-array.cpp ├── single-number ├── README.md └── single-number.cpp ├── sliding-window-maximum ├── README.md └── sliding-window-maximum.cpp ├── sort 012.cpp ├── spiral-matrix ├── README.md └── spiral-matrix.cpp ├── sqrtx ├── README.md └── sqrtx.cpp ├── string-to-integer-atoi ├── README.md └── string-to-integer-atoi.cpp ├── sum-of-two-integers ├── README.md └── sum-of-two-integers.cpp ├── template_return_index.cpp ├── third-maximum-number ├── README.md └── third-maximum-number.cpp ├── unique-paths ├── README.md └── unique-paths.cpp ├── valid-anagram ├── README.md └── valid-anagram.cpp ├── valid-number ├── README.md └── valid-number.cpp ├── valid-palindrome ├── README.md └── valid-palindrome.cpp └── valid-parentheses ├── README.md └── valid-parentheses.cpp /0049-group-anagrams/0049-group-anagrams.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> groupAnagrams(vector& strs) { 4 | unordered_map> mp; 5 | for (string s : strs) { 6 | string t = s; 7 | sort(t.begin(), t.end()); 8 | mp[t].push_back(s); 9 | } 10 | vector> anagrams; 11 | for (auto p : mp) { 12 | anagrams.push_back(p.second); 13 | } 14 | return anagrams; 15 | } 16 | }; -------------------------------------------------------------------------------- /0049-group-anagrams/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0523-continuous-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0645-set-mismatch/0645-set-mismatch.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findErrorNums(vector& nums) { 4 | int p = 0, acc1 = 0, acc2 = 0; 5 | // Get the xor of missing and duplicate numbers 6 | for (unsigned i = 0; i < nums.size(); ++i) 7 | p ^= (i + 1) ^ nums[i]; 8 | 9 | p &= -p; // We'll use only the last significant set bit 10 | 11 | // Split the numbers in 2 categories and xor them 12 | for (unsigned i = 0; i < nums.size(); ++i) 13 | { 14 | ((nums[i] & p) == 0) ? acc1 ^= nums[i] : acc2 ^= nums[i]; 15 | (((i + 1) & p) == 0) ? acc1 ^= i + 1 : acc2 ^= i + 1; 16 | } 17 | 18 | // Determine which is the duplicate number 19 | for (auto n : nums) 20 | if (n == acc1) 21 | return {acc1, acc2}; 22 | return {acc2, acc1}; 23 | } 24 | }; -------------------------------------------------------------------------------- /0645-set-mismatch/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0835-image-overlap/0835-image-overlap.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestOverlap(vector>& A, vector>& B) { 4 | vector LA, LB; 5 | int N = A.size(); 6 | unordered_map count; 7 | for (int i = 0; i < N * N; ++i) 8 | if (A[i / N][i % N] == 1) 9 | LA.push_back(i / N * 100 + i % N); 10 | for (int i = 0; i < N * N; ++i) 11 | if (B[i / N][i % N] == 1) 12 | LB.push_back(i / N * 100 + i % N); 13 | for (int i : LA) for (int j : LB) count[i - j]++; 14 | int res = 0; 15 | for (auto it : count) res = max(res, it.second); 16 | return res; 17 | } 18 | 19 | }; -------------------------------------------------------------------------------- /0835-image-overlap/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /100-same-tree/100-same-tree.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 isSameTree(TreeNode* p, TreeNode* q) { 15 | if(p==NULL&&q==NULL) 16 | return true; 17 | if(p==NULL||q==NULL) 18 | return false; 19 | if(p->val!=q->val) 20 | return false; 21 | return isSameTree(p->left,q->left)&& isSameTree(p->right,q->right); 22 | } 23 | }; -------------------------------------------------------------------------------- /100-same-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1008-construct-binary-search-tree-from-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /101-symmetric-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/102-binary-tree-level-order-traversal.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> levelOrder(TreeNode* root) { 4 | vector> v; 5 | if (root) { 6 | queue q; 7 | q.push(root); 8 | while (!q.empty()) 9 | { 10 | int s = q.size(); 11 | vector values; 12 | for (int i = 0; i < s; i++) 13 | { TreeNode* node = q.front(); 14 | values.push_back(node->val); 15 | if (node->left) 16 | q.push(node->left); 17 | if (node->right) 18 | q.push(node->right); 19 | q.pop(); 20 | } 21 | v.push_back(values); 22 | } 23 | } 24 | return v; 25 | 26 | } 27 | }; -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /103-binary-tree-zigzag-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1048-longest-string-chain/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /105-construct-binary-tree-from-preorder-and-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /106-construct-binary-tree-from-inorder-and-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1074-number-of-submatrices-that-sum-to-target/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /108-convert-sorted-array-to-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /110-balanced-binary-tree/110-balanced-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() : 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 f; 15 | bool isBalanced(TreeNode* root) 16 | { 17 | f=true; 18 | height(root); 19 | return f; 20 | } 21 | int height(TreeNode * root) 22 | { 23 | if(root==NULL) 24 | return 0; 25 | int l=height(root->left); 26 | int r=height(root->right); 27 | if(abs(l-r)>1) f=false; 28 | return (max(l,r)+1); 29 | } 30 | }; -------------------------------------------------------------------------------- /110-balanced-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1108-defanging-an-ip-address/1108-defanging-an-ip-address.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | string defangIPaddr(string address) { 4 | string res; 5 | for(auto c: address) { 6 | if(c=='.') { 7 | res+="[.]"; 8 | } else res+=c; 9 | } 10 | return res; 11 | } 12 | }; -------------------------------------------------------------------------------- /1108-defanging-an-ip-address/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1108-defanging-an-ip-address/README.md: -------------------------------------------------------------------------------- 1 |

1108. Defanging an IP Address

Easy


Given a valid (IPv4) IP address, return a defanged version of that IP address.

2 | 3 |

A defanged IP address replaces every period "." with "[.]".

4 | 5 |

 

6 |

Example 1:

7 |
Input: address = "1.1.1.1"
 8 | Output: "1[.]1[.]1[.]1"
 9 | 

Example 2:

10 |
Input: address = "255.100.50.0"
11 | Output: "255[.]100[.]50[.]0"
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • The given address is a valid IPv4 address.
  • 18 |
-------------------------------------------------------------------------------- /1137-n-th-tribonacci-number/1137-n-th-tribonacci-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[38]={0}; 4 | int tribonacci(int n) { 5 | if(n==0||n==1||n==4) 6 | return dp[n]=n; 7 | if(n==2||n==3) 8 | return dp[n]=n-1; 9 | 10 | if(dp[n]) 11 | return dp[n]; 12 | 13 | return dp[n]=tribonacci(n-2)+tribonacci(n-1)+tribonacci(n-3); 14 | } 15 | }; 16 | 17 | 18 | // class Solution { 19 | // public: 20 | // int dp[31]={0}; 21 | // int fib(int n) 22 | // { if(n==0||n==1||n==5) 23 | // return dp[n]=n; 24 | // if(n==2||n==3||n==4) 25 | // return dp[n]=n-1; 26 | 27 | // if(dp[n]) 28 | // return dp[n]; 29 | 30 | // return dp[n]=fib(n-2)+fib(n-1); 31 | 32 | // } 33 | // }; -------------------------------------------------------------------------------- /1137-n-th-tribonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/114-flatten-binary-tree-to-linked-list.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 | void flatten(TreeNode *root) { 15 | while (root) { 16 | if (root->left && root->right) { 17 | TreeNode* t = root->left; 18 | while (t->right) 19 | t = t->right; 20 | t->right = root->right; 21 | } 22 | 23 | if(root->left) 24 | root->right = root->left; 25 | root->left = NULL; 26 | root = root->right; 27 | } 28 | } 29 | }; -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1143-longest-common-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1154-day-of-the-year/1154-day-of-the-year.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dayOfYear(string date) { 4 | unordered_mapmonths{{1,0}, {2,31}, {3,59}, {4,90}, {5,120}, {6,151}, {7,181}, {8,212}, {9,243}, {10,273}, {11,304}, {12,334}}; 5 | int year = getInt(date, 0, 3); 6 | int mon = getInt(date, 5, 6); 7 | int day = getInt(date, 8, 9); 8 | int res = months[mon] + day; 9 | return (year%4==0 && (year%400 == 0 || year%100 != 0)) && mon > 2 ? res + 1 : res; 10 | } 11 | 12 | int getInt(string &date, int l, int r) 13 | { 14 | int num = 0; 15 | for(int i = l; i<=r; i++) 16 | num = num*10 + (date[i]-'0'); 17 | return num; 18 | } 19 | }; -------------------------------------------------------------------------------- /1154-day-of-the-year/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /116-populating-next-right-pointers-in-each-node/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /118-pascals-triangle/118-pascals-triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> generate(int n) 4 | { 5 | vector> tri(n); 6 | 7 | tri[0].push_back(1); //manually inserting the 1st row 8 | 9 | for(int i=1; i< n; i++){ 10 | 11 | tri[i].push_back(1); //1st col of every row 12 | 13 | for( int j = 1; j < i; j++){ //filling the inside col of every row 14 | tri[i].push_back(tri[i-1][j-1]+tri[i-1][j]); 15 | } 16 | tri[i].push_back(1); //last col of every row 17 | } 18 | return tri; 19 | } 20 | }; 21 | 22 | /* 0& arr) 4 | { 5 | int profit= 0; 6 | int minEl= INT_MAX; 7 | int n= arr.size(); 8 | 9 | for(int i=0;i& arr, string str = "", int index = 0) { 4 | //Use set to check if the string contains all unique characters 5 | unordered_sets(str.begin(), str.end()); 6 | if (s.size() != ((int)str.length())) 7 | return 0; 8 | 9 | int ret = str.length(); 10 | for (int i = index; i < arr.size(); i++) 11 | ret = max(ret, maxLength(arr, str+arr[i], i+1)); 12 | 13 | return ret; 14 | } 15 | }; -------------------------------------------------------------------------------- /1239-maximum-length-of-a-concatenated-string-with-unique-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /124-binary-tree-maximum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1287-element-appearing-more-than-25-in-sorted-array/1287-element-appearing-more-than-25-in-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findSpecialInteger(vector& arr) { 4 | int sz = arr.size(); 5 | vector candidates = {arr[sz/4], arr[sz/2], arr[sz*3/4]}; 6 | for (auto cand : candidates) { 7 | auto st = lower_bound(arr.begin(), arr.end(), cand); 8 | auto ed = upper_bound(arr.begin(), arr.end(), cand); 9 | if (4 * (distance(st, ed)) > sz) 10 | return cand; 11 | } 12 | return -1; 13 | } 14 | }; -------------------------------------------------------------------------------- /1287-element-appearing-more-than-25-in-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1293-shortest-path-in-a-grid-with-obstacles-elimination/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1313-decompress-run-length-encoded-list/1313-decompress-run-length-encoded-list.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector decompressRLElist(vector& n) { 4 | vectora; 5 | for(int i=1;i0) 9 | { 10 | a.push_back(k); 11 | c--; 12 | } 13 | } 14 | return a; 15 | } 16 | }; -------------------------------------------------------------------------------- /1313-decompress-run-length-encoded-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1329-sort-the-matrix-diagonally/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1332-remove-palindromic-subsequences/1332-remove-palindromic-subsequences.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removePalindromeSub(string s) { 4 | string a=s; 5 | reverse(a.begin(),a.end()); 6 | return a==s?1:2; 7 | } 8 | }; -------------------------------------------------------------------------------- /1332-remove-palindromic-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1337-the-k-weakest-rows-in-a-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1342-number-of-steps-to-reduce-a-number-to-zero/1342-number-of-steps-to-reduce-a-number-to-zero.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfSteps(int n) 4 | { 5 | int c=0; 6 | while(n) 7 | { 8 | if(n%2==0) 9 | { 10 | n=n/2; 11 | c++; 12 | } 13 | else 14 | { 15 | n=n-1; 16 | c++; 17 | } 18 | } 19 | return c; 20 | } 21 | }; -------------------------------------------------------------------------------- /1342-number-of-steps-to-reduce-a-number-to-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1354-construct-target-array-with-multiple-sums/1354-construct-target-array-with-multiple-sums.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPossible(vector& target) { 4 | auto s = accumulate(begin(target), end(target), (long long)0); 5 | priority_queue q(begin(target), end(target)); 6 | while (s > 1 && q.top() > s / 2) { 7 | auto cur = q.top(); q.pop(); 8 | s -= cur; 9 | if (s <= 1) 10 | return s; 11 | q.push(cur % s); 12 | s += cur % s; 13 | } 14 | return s == target.size(); 15 | } 16 | }; -------------------------------------------------------------------------------- /1354-construct-target-array-with-multiple-sums/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /136-single-number/136-single-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | int c=0; 5 | for(int i=0;i v(37,0); 15 | for(auto i = 1; i<=n; i++) 16 | v[digSum(i)]++; 17 | int c = 0; 18 | auto m = *max_element(v.begin(),v.end()); 19 | for(auto i : v) 20 | { 21 | if(i==m) 22 | c++; 23 | } 24 | return c; 25 | } 26 | }; -------------------------------------------------------------------------------- /1399-count-largest-group/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1423-maximum-points-you-can-obtain-from-cards/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /144-binary-tree-preorder-traversal/144-binary-tree-preorder-traversal.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 | vectorv; 15 | vector preorderTraversal(TreeNode* root) 16 | { 17 | if(!root)return v; 18 | v.push_back(root->val); 19 | preorderTraversal(root->left); 20 | preorderTraversal(root->right); 21 | return v; 22 | } 23 | }; -------------------------------------------------------------------------------- /144-binary-tree-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1448-count-good-nodes-in-binary-tree/1448-count-good-nodes-in-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() : 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 | 15 | int solve(TreeNode* root,int hi){ 16 | if (root){ 17 | int k=solve(root->left, max(hi,root->val)) + solve(root->right, max(hi,root->val)); 18 | if (root->val>=hi){ 19 | k++; 20 | } 21 | return k; 22 | } 23 | return 0; 24 | } 25 | int goodNodes(TreeNode* root) { 26 | return solve(root,-10001); 27 | } 28 | }; -------------------------------------------------------------------------------- /1448-count-good-nodes-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /145-binary-tree-postorder-traversal/145-binary-tree-postorder-traversal.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 | vectorv; 15 | vector postorderTraversal(TreeNode* root) 16 | { 17 | if(!root)return v; 18 | postorderTraversal(root->left); 19 | postorderTraversal(root->right); 20 | v.push_back(root->val); 21 | return v; 22 | 23 | 24 | } 25 | }; -------------------------------------------------------------------------------- /145-binary-tree-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxArea(int h, int w, vector& hCuts, vector& vCuts) { 4 | sort(begin(hCuts), end(hCuts)); 5 | sort(begin(vCuts), end(vCuts)); 6 | auto max_h = max(hCuts[0], h - hCuts.back()); 7 | auto max_v = max(vCuts[0], w - vCuts.back()); 8 | for (auto i = 0; i < hCuts.size() - 1; ++i) 9 | max_h = max(max_h, hCuts[i + 1] - hCuts[i]); 10 | for (auto i = 0; i < vCuts.size() - 1; ++i) 11 | max_v = max(max_v, vCuts[i + 1] - vCuts[i]); 12 | return (long)max_h * max_v % 1000000007; 13 | } 14 | }; -------------------------------------------------------------------------------- /1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1470-shuffle-the-array/1470-shuffle-the-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector shuffle(vector& nums, int n) { 4 | 5 | vector out; 6 | 7 | for(int x=0; x < n; x++){ 8 | out.push_back(nums[x]); 9 | out.push_back(nums[n+x]); 10 | } 11 | 12 | 13 | return out; 14 | } 15 | }; -------------------------------------------------------------------------------- /1470-shuffle-the-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1480-running-sum-of-1d-array/1480-running-sum-of-1d-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector runningSum(vector nums) { 4 | 5 | for(int i=1;i& s) { 4 | double a=10000000,b=0,c=0; 5 | for(int i=0;ib) 10 | b=s[i]; 11 | c=c+s[i]; 12 | } 13 | cout<& nums) { 4 | 5 | int mem[101] ={0}; 6 | int sum=0; 7 | 8 | for(int i=0; i < nums.size(); i++){ 9 | sum += mem[nums[i]]; 10 | ++mem[nums[i]]; 11 | } 12 | 13 | return sum; 14 | } 15 | }; -------------------------------------------------------------------------------- /1512-number-of-good-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /152-maximum-product-subarray/152-maximum-product-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProduct(vector& a) { 4 | int cp=1,ans=a[0]; 5 | for(int i=0;i=0;i--) 12 | { cp=cp*a[i]; 13 | ans=max(cp,ans); 14 | if(cp==0)cp=1; 15 | } 16 | return ans; 17 | } 18 | }; -------------------------------------------------------------------------------- /152-maximum-product-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1523-count-odd-numbers-in-an-interval-range/1523-count-odd-numbers-in-an-interval-range.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countOdds(int l, int h) { 4 | ((l%2==0&&h%2==0) ? h=(h-l)/2: h=1+(h-l)/2); 5 | return h; 6 | 7 | } 8 | }; 9 | 10 | // 4 5 6 7 8 9 -------------------------------------------------------------------------------- /1523-count-odd-numbers-in-an-interval-range/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1528-shuffle-string/1528-shuffle-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string restoreString(string s, vector& indices) { 4 | string res = s; 5 | for(int i =0; i < indices.size(); ++i) 6 | res[indices[i]] = s[i]; 7 | return res; 8 | } 9 | }; -------------------------------------------------------------------------------- /1528-shuffle-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1547-minimum-cost-to-cut-a-stick/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1581-customer-who-visited-but-did-not-make-any-transactions/1581-customer-who-visited-but-did-not-make-any-transactions.sql: -------------------------------------------------------------------------------- 1 | select v.customer_id, count(v.customer_id) count_no_trans 2 | from Visits v 3 | left join Transactions t on v.visit_id = t.visit_id 4 | where t.visit_id is null 5 | group by v.customer_id -------------------------------------------------------------------------------- /1581-customer-who-visited-but-did-not-make-any-transactions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /16-3sum-closest/16-3sum-closest.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int threeSumClosest(vector& nums, int target) { 4 | sort(nums.begin(), nums.end()); 5 | int res = nums[0] + nums[1] + nums[2]; 6 | for(int i = 0; i < nums.size() - 2; i++){ 7 | int j = i + 1, k = nums.size() - 1; 8 | while(j < k){ 9 | int num = nums[i] + nums[j] + nums[k]; 10 | if(abs(num - target) < abs(res - target)) res = num; 11 | if(num < target) j++; 12 | else k--; 13 | } 14 | } 15 | return res; 16 | } 17 | }; -------------------------------------------------------------------------------- /16-3sum-closest/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1662-check-if-two-string-arrays-are-equivalent/1662-check-if-two-string-arrays-are-equivalent.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool arrayStringsAreEqual(vector& x, vector& y) 4 | { 5 | string a="",b=""; 6 | for(int i=0;i twoSum(vector& n, int t) { 4 | int i=0,j=n.size()-1; 5 | vectorv; 6 | while(it) 13 | j=j-1; 14 | else 15 | i=i+1; 16 | 17 | } 18 | v.push_back(-1); 19 | return v; 20 | } 21 | }; -------------------------------------------------------------------------------- /167-two-sum-ii-input-array-is-sorted/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1672-richest-customer-wealth/1672-richest-customer-wealth.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maximumWealth(vector>& accounts) { 4 | int max = 0,temp = 0; 5 | for(int i = 0;i < accounts.size();i++){ 6 | temp = 0; 7 | for(int j = 0;j < accounts[i].size();j++){ 8 | temp += accounts[i][j]; 9 | } 10 | max = temp > max ? temp : max; 11 | } 12 | return max; 13 | } 14 | }; -------------------------------------------------------------------------------- /1672-richest-customer-wealth/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1678-goal-parser-interpretation/1678-goal-parser-interpretation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string interpret(string c) { 4 | string s=""; 5 | for(int i=0;i0) 8 | { 9 | int r=c%26; 10 | if(r==0) 11 | {s+='Z'; 12 | c=c-26; 13 | } 14 | else 15 | s+='A'+r-1; 16 | c=c/26; 17 | } 18 | reverse(s.begin(),s.end()); 19 | return s; 20 | } 21 | 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /168-excel-sheet-column-title/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /169-majority-element/169-majority-element.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int majorityElement(vector& nums) 4 | { 5 | int n=nums.size(); 6 | int count=1; 7 | int element=nums[0]; 8 | for(int i=1; i decode(vector& a, int f) { 4 | a.insert(a.begin(),f); 5 | for(int i=0;i& nums) 5 | { 6 | int N = nums.size(); 7 | int numOfSubsets = pow(2, N); 8 | int result = 0; 9 | 10 | // binary representation of subsets help us identify whether to take an element of num or not 11 | for (int subset = 1; subset < numOfSubsets; ++subset) 12 | { 13 | int runningXor = 0; 14 | for (int i = 0, bits = subset; i < nums.size(); ++i, bits >>= 1) 15 | if (bits & 1) // whether to include current element in subset 16 | runningXor ^= nums[i]; 17 | 18 | result += runningXor; 19 | } 20 | 21 | return result; 22 | } 23 | }; -------------------------------------------------------------------------------- /1863-sum-of-all-subset-xor-totals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /189-rotate-array/189-rotate-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void rotate(vector& n, int k) { 4 | k=k%n.size(); 5 | reverse(n.begin(),n.end()); 6 | reverse(n.begin(),n.begin()+k); 7 | reverse(n.begin()+k,n.end()); 8 | //}\ 9 | 10 | } 11 | }; 12 | 13 | // 1 2 3 4 5 6 7 14 | // 7 6 5 4 3 2 1 15 | 16 | // 567 -------------------------------------------------------------------------------- /189-rotate-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/19-remove-nth-node-from-end-of-list.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* removeNthFromEnd(ListNode* head, int n) { 14 | ListNode *s=new ListNode();//constructing an another linklist 15 | s->next=head; //assigning its next to head 16 | ListNode*p=s,*q=s; //rest all is the game of slow and fast pointer 17 | for(int i=0;inext; 19 | while(p->next!=NULL) 20 | { p=p->next; 21 | q=q->next; 22 | } 23 | q->next=q->next->next; 24 | return s->next; 25 | } 26 | }; -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /190-reverse-bits/190-reverse-bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | uint32_t reverseBits(uint32_t n) { 4 | return reverse(n, 31); 5 | } 6 | 7 | 8 | uint32_t reverse(uint32_t n, int max){ 9 | if(n==0){ 10 | return 0; 11 | } 12 | 13 | return (n % 2) * pow(2,max) + reverse(n/2, --max); 14 | } 15 | 16 | }; -------------------------------------------------------------------------------- /190-reverse-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /191-number-of-1-bits/191-number-of-1-bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int hammingWeight(uint32_t n) { 4 | return __builtin_popcount(n); 5 | } 6 | }; -------------------------------------------------------------------------------- /191-number-of-1-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /199-binary-tree-right-side-view/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /200-number-of-islands/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /202-happy-number/202-happy-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isHappy(int n) { 4 | int sum=0; 5 | for(int i=0;i<10;i++){ 6 | while(n>0){ 7 | int x=n%10; 8 | n=n/10; 9 | sum=sum+(x*x); 10 | } 11 | if(sum==1){ 12 | return true; 13 | } 14 | n=sum; 15 | sum=0; 16 | } 17 | return false; 18 | } 19 | }; -------------------------------------------------------------------------------- /202-happy-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /206-reverse-linked-list/206-reverse-linked-list.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* reverseList(ListNode* head) 14 | { 15 | ListNode*p=head,*q=NULL,*r=NULL; 16 | while(p) 17 | { 18 | r=q; 19 | q=p; 20 | p=p->next; 21 | q->next=r; 22 | } 23 | head=q; 24 | return head; 25 | } 26 | }; -------------------------------------------------------------------------------- /206-reverse-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2095-delete-the-middle-node-of-a-linked-list/2095-delete-the-middle-node-of-a-linked-list.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* deleteMiddle(ListNode* head) { 14 | 15 | if (head->next == nullptr) 16 | return nullptr; 17 | auto slow = head, fast = head->next->next; 18 | while (fast != nullptr && fast->next != nullptr) { 19 | fast = fast->next->next; 20 | slow = slow->next; 21 | } 22 | slow->next = slow->next->next; 23 | return head; 24 | } 25 | }; -------------------------------------------------------------------------------- /2095-delete-the-middle-node-of-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /21-merge-two-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2114-maximum-number-of-words-found-in-sentences/2114-maximum-number-of-words-found-in-sentences.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mostWordsFound(vector& s) { 4 | int c=0,m=0; 5 | for(int i=0;i=m) 14 | m=c; 15 | } 16 | return m+1; 17 | } 18 | }; -------------------------------------------------------------------------------- /2114-maximum-number-of-words-found-in-sentences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2131-longest-palindrome-by-concatenating-two-letter-words/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/215-kth-largest-element-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findKthLargest(vector& s, int k) { 4 | for(int i=0;is[j+1]) 9 | swap(s[j],s[j+1]); 10 | } 11 | 12 | } 13 | return s[s.size()-k]; 14 | } 15 | }; -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2169-count-operations-to-obtain-zero/2169-count-operations-to-obtain-zero.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countOperations(int a, int b) 4 | { 5 | int c=0; 6 | while(a&&b) 7 | { 8 | if(a>b) 9 | { 10 | a=a-b; 11 | c++; 12 | } 13 | else 14 | { 15 | b-=a; 16 | c++; 17 | } 18 | } 19 | return c; 20 | 21 | } 22 | }; -------------------------------------------------------------------------------- /2169-count-operations-to-obtain-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /217-contains-duplicate/217-contains-duplicate.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool containsDuplicate(vector& n) { 4 | sets(n.begin(),n.end()); 5 | //for(auto x:n) 6 | // s.insert(x); 7 | return s.size()!=n.size(); 8 | } 9 | }; -------------------------------------------------------------------------------- /217-contains-duplicate/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2235-add-two-integers/2235-add-two-integers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int sum(int a, int b) { 4 | return a+b; 5 | } 6 | }; -------------------------------------------------------------------------------- /2235-add-two-integers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2236-root-equals-sum-of-children/2236-root-equals-sum-of-children.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 checkTree(TreeNode* root) { 15 | // return root->left->val+root->right->val==root->val; 16 | return root -> val == (root -> left -> val) + (root -> right -> val); 17 | 18 | } 19 | }; -------------------------------------------------------------------------------- /2236-root-equals-sum-of-children/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2259-remove-digit-from-number-to-maximize-result/2259-remove-digit-from-number-to-maximize-result.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string removeDigit(string s, char d) { 4 | int f=-1,m=10; 5 | for(int i=0;i 13325 20 | 21 | //1712 (1)->712 22 | //7121 1->721 23 | //56101 1 5610 24 | 25 | //3231 3->321 -------------------------------------------------------------------------------- /2259-remove-digit-from-number-to-maximize-result/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /226-invert-binary-tree/226-invert-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() : 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 | TreeNode* invertTree(TreeNode* root) { 15 | if (!root) return root; 16 | swap(root->left, root->right); 17 | invertTree(root->left); 18 | invertTree(root->right); 19 | return root; 20 | } 21 | }; -------------------------------------------------------------------------------- /226-invert-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /230-kth-smallest-element-in-a-bst/230-kth-smallest-element-in-a-bst.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 | void inord(TreeNode*root,int &k,int &ans){ 15 | if(root==NULL) 16 | return; 17 | inord(root->left,k,ans); 18 | k--; 19 | if(k==0){ 20 | ans=root->val; 21 | 22 | } 23 | inord(root->right,k,ans); 24 | } 25 | int kthSmallest(TreeNode* root, int k) { 26 | int ans=-1; 27 | inord(root,k,ans); 28 | return ans; 29 | } 30 | }; -------------------------------------------------------------------------------- /230-kth-smallest-element-in-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /231-power-of-two/231-power-of-two.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfTwo(int n) { 4 | if(n==1) 5 | return true; 6 | if(n%2==1||n==0) 7 | return false; 8 | return isPowerOfTwo(n/2); 9 | } 10 | }; -------------------------------------------------------------------------------- /231-power-of-two/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /234-palindrome-linked-list/234-palindrome-linked-list.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* temp; 14 | 15 | bool check(ListNode* head) { 16 | if (NULL == head) return true; 17 | bool res = check(head->next) & (temp->val == head->val); 18 | temp = temp->next; 19 | return res; 20 | } 21 | 22 | bool isPalindrome(ListNode* head) { 23 | temp = head; 24 | return check(head); 25 | } 26 | }; 27 | 28 | // 54321 54321 -------------------------------------------------------------------------------- /234-palindrome-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/235-lowest-common-ancestor-of-a-binary-search-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 | 11 | class Solution { 12 | public: 13 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) 14 | { return (p->val < root->val && q->val < root->val) ? lowestCommonAncestor(root->left, p, q) : 15 | (p->val > root->val && q->val > root->val) ? lowestCommonAncestor(root->right, p, q): root; 16 | } 17 | }; -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/236-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 | { 14 | if(root==NULL||root==p||root==q) return root; 15 | TreeNode *left=lowestCommonAncestor(root->left,p,q); 16 | TreeNode *right=lowestCommonAncestor(root->right,p,q); 17 | if(left==NULL) return right; 18 | else if(right==NULL) return left; 19 | else return root; 20 | 21 | } 22 | }; -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/237-delete-node-in-a-linked-list.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | void deleteNode(ListNode* node) 12 | { // ListNode *p=node, *q=p->next; 13 | //p->val = q->val; 14 | //p->next = q->next; 15 | //delete q; 16 | *node = *node->next; 17 | } 18 | }; -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /238-product-of-array-except-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/240-search-a-2d-matrix-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool searchMatrix(vector>& matrix, int target) { 4 | int m = matrix.size(); 5 | if (m == 0) return false; 6 | int n = matrix[0].size(); 7 | 8 | int i = 0, j = n - 1; 9 | while (i < m && j >= 0) { 10 | if (matrix[i][j] == target) 11 | return true; 12 | else if (matrix[i][j] > target) { 13 | j--; 14 | } else 15 | i++; 16 | } 17 | return false; 18 | } 19 | }; -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /242-valid-anagram/242-valid-anagram.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isAnagram(string s, string t) { 4 | sort(s.begin(),s.end()); 5 | sort(t.begin(),t.end()); 6 | return s==t; 7 | } 8 | }; -------------------------------------------------------------------------------- /242-valid-anagram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /278-first-bad-version/278-first-bad-version.cpp: -------------------------------------------------------------------------------- 1 | // The API isBadVersion is defined for you. 2 | // bool isBadVersion(int version); 3 | 4 | class Solution { 5 | public: 6 | int firstBadVersion(int n) { 7 | long long int l=1,h=n,m=1; 8 | if(isBadVersion(l)==true) 9 | return 1; 10 | while(l<=h) 11 | { 12 | m=(l+h)/2; 13 | if(isBadVersion(m)==true) 14 | { 15 | if(isBadVersion(m-1)==false) 16 | { 17 | return m; 18 | } 19 | else 20 | { 21 | h=m-1; 22 | } 23 | } 24 | else{ 25 | l=m+1; 26 | } 27 | } 28 | return 0; 29 | } 30 | }; 31 | 32 | //f f f t t -------------------------------------------------------------------------------- /278-first-bad-version/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /283-move-zeroes/283-move-zeroes.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void moveZeroes(vector& a) 4 | { 5 | int i=0,j=0; 6 | while(jv; 5 | int i=0,j=0,a=0; 6 | int n=s.size(); 7 | while(i& A) { 4 | int len = 0; 5 | for(auto cur : A) 6 | if(len == 0 || A[len-1] < cur) A[len++] = cur; // extend 7 | else *lower_bound(begin(A), begin(A) + len, cur) = cur; // replace 8 | return len; 9 | } 10 | }; -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /31-next-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /315-count-of-smaller-numbers-after-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /322-coin-change/322-coin-change.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int coinChange(vector& coins, int n) { 4 | // creating the base dp array, with first value set to 0 5 | int dp[++n]; 6 | dp[0] = 0; 7 | // more convenient to have the coins sorted 8 | sort(begin(coins), end(coins)); 9 | // populating our dp array 10 | for (int i = 1; i < n; i++) { 11 | // setting dp[0] base value to 1, 0 for all the rest 12 | dp[i] = INT_MAX; 13 | for (int c: coins) { 14 | if (i - c < 0) break; 15 | // if it was a previously not reached cell, we do not add use it 16 | if (dp[i - c] != INT_MAX) dp[i] = min(dp[i], 1 + dp[i - c]); 17 | } 18 | } 19 | return dp[--n] == INT_MAX ? -1 : dp[n]; 20 | } 21 | }; -------------------------------------------------------------------------------- /322-coin-change/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /326-power-of-three/326-power-of-three.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfThree(int n) { 4 | // Base Cases 5 | if(n == 0){ 6 | return false; 7 | } 8 | if(n == 1){ 9 | return true; 10 | } 11 | 12 | // Check remainder is 0 or not when divided by 3, and recursion call. 13 | return (n % 3 == 0) && (isPowerOfThree(n/3)); 14 | } 15 | }; -------------------------------------------------------------------------------- /326-power-of-three/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /336-palindrome-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /342-power-of-four/342-power-of-four.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfFour(int n) { 4 | 5 | if(n==0) return false; 6 | 7 | while (1){ 8 | if(n==1 || n==4) return true; 9 | if(n%4!=0) return false; 10 | n=n/4; 11 | }; 12 | return true; 13 | } 14 | }; -------------------------------------------------------------------------------- /342-power-of-four/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /344-reverse-string/344-reverse-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void reverseString(vector& s) { 4 | int i; 5 | int n=s.size(); 6 | for(int i=0;i& a, int t) { 4 | int l=0,h=a.size()-1,m=0; 5 | while(l<=h) 6 | { 7 | m=(l+h)/2; 8 | if(a[m]==t) return m; 9 | else if(a[m]>& matrix, int k) { 4 | int max_sum = INT_MIN, m=matrix.size(), n=matrix[0].size(), subarr[m]; 5 | for(int l=0; l max_sum && sum <=k) max_sum = sum; 14 | } 15 | } 16 | } 17 | } 18 | return max_sum; 19 | } 20 | }; -------------------------------------------------------------------------------- /363-max-sum-of-rectangle-no-larger-than-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /377-combination-sum-iv/377-combination-sum-iv.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int combinationSum4(vector& nums, int target) { 4 | vector result(target + 1); 5 | result[0] = 1; 6 | for (int i = 1; i <= target; ++i) { 7 | for (int x : nums) { 8 | if (i >= x) result[i] += result[i - x]; 9 | } 10 | } 11 | 12 | return result[target]; 13 | } 14 | }; -------------------------------------------------------------------------------- /377-combination-sum-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /383-ransom-note/383-ransom-note.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canConstruct(string r, string m) 4 | { 5 | if(r[0]=='\0') 6 | return true; 7 | if(m[0]=='\0') 8 | return false; 9 | if(m.size() vec; 3 | int size; 4 | 5 | public: 6 | Solution(vector& nums) { 7 | size = nums.size(); 8 | vec = nums; 9 | } 10 | 11 | vector reset() { 12 | return vec; 13 | } 14 | 15 | vector shuffle() { 16 | vector temp = vec; 17 | random_shuffle(temp.begin(),temp.end()); 18 | return temp; 19 | } 20 | }; -------------------------------------------------------------------------------- /384-shuffle-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /393-utf-8-validation/393-utf-8-validation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool validUtf8(vector& data) { 4 | int count = 0; 5 | for (auto c : data) { 6 | if (count == 0) { 7 | if ((c >> 5) == 0b110) count = 1; 8 | else if ((c >> 4) == 0b1110) count = 2; 9 | else if ((c >> 3) == 0b11110) count = 3; 10 | else if ((c >> 7)) return false; 11 | } else { 12 | if ((c >> 6) != 0b10) return false; 13 | count--; 14 | } 15 | } 16 | return count == 0; 17 | } 18 | }; -------------------------------------------------------------------------------- /393-utf-8-validation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /3sum/3sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> threeSum(vector& v) 4 | { 5 | vector>ans; 6 | sort(v.begin(),v.end()); 7 | int n=v.size(); 8 | for(int i=0;it) e--; 24 | else s++; 25 | } 26 | while(i+1& nums1, vector& nums2) { 4 | int n= nums1.size(); 5 | int m=nums2.size(); 6 | vectorv; 7 | for(int i:nums1) v.push_back(i); 8 | for(int i:nums2) v.push_back(i); 9 | sort(v.begin(),v.end()); 10 | int size=v.size(); 11 | if(size%2==1) 12 | { int index= size-1; 13 | index=index/2; 14 | return v[index]; 15 | } 16 | else 17 | { int index = size/2; 18 | int sum = v[index]+v[index-1]; 19 | double ans = sum/2.0; 20 | return ans; 21 | } 22 | } 23 | }; -------------------------------------------------------------------------------- /4-median-of-two-sorted-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /412-fizz-buzz/412-fizz-buzz.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector fizzBuzz(int m) 4 | { 5 | vectorv; 6 | for(int n=1;n<=m;n++) 7 | { if(n%3==0&&n%5==0) 8 | v.push_back("FizzBuzz"); 9 | else if(n%3==0) 10 | v.push_back("Fizz"); 11 | else if(n%5==0) 12 | v.push_back("Buzz"); 13 | else{ 14 | string s=to_string(n); 15 | v.push_back(s);}} 16 | return v; 17 | 18 | } 19 | }; -------------------------------------------------------------------------------- /412-fizz-buzz/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /416-partition-equal-subset-sum/416-partition-equal-subset-sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canPartition(vector& nums) { 4 | int sum = accumulate(nums.begin(), nums.end(), 0); 5 | 6 | if (sum%2) return false; 7 | bitset<10001> bits(1); 8 | for (auto &num : nums) bits |= bits << num; 9 | return bits[sum/2]; 10 | } 11 | 12 | }; -------------------------------------------------------------------------------- /416-partition-equal-subset-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /42-trapping-rain-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /429-n-ary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /44-wildcard-matching/44-wildcard-matching.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isMatch(string s, string p) { 4 | int i = 0, j = 0; 5 | int m = s.length(), n = p.length(); 6 | int last_match = -1, starj = -1; 7 | while (i < m){ 8 | if (j < n && (s[i] == p[j] || p[j] == '?')){ 9 | i++; j++; 10 | continue; 11 | } 12 | if (j < n && p[j] == '*'){ 13 | starj = j; 14 | j++; 15 | last_match = i; 16 | continue; 17 | } 18 | if (starj != -1){ 19 | j = starj + 1; 20 | last_match++; 21 | i = last_match; 22 | continue; 23 | } 24 | return false; 25 | } 26 | while (p[j] == '*' && j findDuplicates(vector& n) { 4 | vectorv; 5 | for(int i=0;i= 40) { 10 | rand40 = (rand7() - 1) * 7 + rand7() - 1; 11 | } 12 | return rand40 % 10 + 1; 13 | } 14 | }; -------------------------------------------------------------------------------- /470-implement-rand10-using-rand7/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /474-ones-and-zeroes/474-ones-and-zeroes.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findMaxForm(vector& strs, int m, int n) 4 | { int dp[m+1][n+1]; 5 | memset(dp,0,sizeof(dp)); 6 | for(int k=0; k=w0; i--) 10 | { for(int j=n; j>=w1; j--) 11 | dp[i][j]=max(dp[i][j], dp[i-w0][j-w1]+1); 12 | } 13 | } 14 | return dp[m][n]; 15 | } 16 | }; -------------------------------------------------------------------------------- /474-ones-and-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /48-rotate-image/48-rotate-image.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void rotate(vector>& m) { 4 | int n = m.size(); 5 | 6 | for(int i=0; i 0 ? res * x : res / x; 8 | x = x * x; 9 | n /= 2; 10 | } 11 | return res; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /50-powx-n/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /509-fibonacci-number/509-fibonacci-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[31]={0}; 4 | int fib(int n) 5 | { 6 | 7 | if(n==0||n==1||n==5) 8 | return dp[n]=n; 9 | if(n==2||n==3||n==4) 10 | return dp[n]=n-1; 11 | 12 | if(dp[n]) 13 | return dp[n]; 14 | 15 | return dp[n]=fib(n-2)+fib(n-1); 16 | 17 | } 18 | }; -------------------------------------------------------------------------------- /509-fibonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /53-maximum-subarray/53-maximum-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSubArray(vector& a) { 4 | int s=0,me=-10000; 5 | for(int x:a) 6 | { s=s+x; 7 | me=max(s,me); 8 | if(s<0) s=0; 9 | } 10 | return me; 11 | } 12 | }; -------------------------------------------------------------------------------- /53-maximum-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /543-diameter-of-binary-tree/543-diameter-of-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() : 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 | int ans; 15 | int diameterOfBinaryTree(TreeNode* root) 16 | { 17 | ans=0; 18 | diameter(root); 19 | return ans; 20 | } 21 | int diameter(TreeNode* root) 22 | { 23 | if(root==NULL) 24 | return 0; 25 | int l=diameter(root->left); 26 | int r=diameter(root->right); 27 | ans = max(ans,l+r); 28 | return max(l,r)+1; 29 | } 30 | }; -------------------------------------------------------------------------------- /543-diameter-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /557-reverse-words-in-a-string-iii/557-reverse-words-in-a-string-iii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string reverseWords(string s) { 4 | int j=0,k=0; 5 | s+=' '; 6 | for(int i=0;i>>& dp){ 4 | if(moves>=0 && (cr>=m || cr<0 || cc<0 || cc>=n))return 1; 5 | if(moves==0)return 0; 6 | if(dp[cr][cc][moves]!=-1)return dp[cr][cc][moves]; 7 | long long up=solve(m,n,cr-1,cc,moves-1,dp); 8 | long long down=solve(m,n,cr+1,cc,moves-1,dp); 9 | long long left=solve(m,n,cr,cc-1,moves-1,dp); 10 | long long right=solve(m,n,cr,cc+1,moves-1,dp); 11 | 12 | return dp[cr][cc][moves]= (up+down+left+right)%1000000007; 13 | } 14 | int findPaths(int m, int n, int maxMove, int startRow, int startColumn) { 15 | vector>>dp (m+1,vector>(n+1,vector(maxMove+1,-1))); 16 | return solve(m,n,startRow,startColumn,maxMove,dp); 17 | } 18 | }; -------------------------------------------------------------------------------- /576-out-of-boundary-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /607-sales-person/607-sales-person.sql: -------------------------------------------------------------------------------- 1 | select salesperson.name 2 | from orders o join company c on (o.com_id = c.com_id and c.name = 'RED') 3 | right join salesperson on salesperson.sales_id = o.sales_id 4 | where o.sales_id is null -------------------------------------------------------------------------------- /607-sales-person/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /609-find-duplicate-file-in-system/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /62-unique-paths/62-unique-paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int uniquePaths(int m, int n) { 4 | 5 | int dp[m+1][n+1]; 6 | for(int i=0;i>& courses) { 4 | if(courses.size() <= 0) return 0; 5 | sort(courses.begin(), courses.end(), [](const vector& a, vector& b) { 6 | return a[1] < b[1]; 7 | }); 8 | priority_queue q; 9 | int sum = 0; 10 | for(auto i : courses) { 11 | sum += i[0]; 12 | q.push(i[0]); 13 | if(sum > i[1]) { 14 | sum -= q.top(); 15 | q.pop(); 16 | } 17 | } 18 | return q.size(); 19 | } 20 | }; -------------------------------------------------------------------------------- /630-course-schedule-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /64-minimum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /647-palindromic-substrings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /653-two-sum-iv-input-is-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /695-max-area-of-island/695-max-area-of-island.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxAreaOfIsland(vector>& grid) { 4 | int max_area = 0; 5 | for(int i = 0; i < grid.size(); i++) 6 | for(int j = 0; j < grid[0].size(); j++) 7 | if(grid[i][j] == 1)max_area = max(max_area, AreaOfIsland(grid, i, j)); 8 | return max_area; 9 | } 10 | 11 | int AreaOfIsland(vector>& grid, int i, int j){ 12 | if( i >= 0 && i < grid.size() && j >= 0 && j < grid[0].size() && grid[i][j] == 1){ 13 | grid[i][j] = 0; 14 | return 1 + AreaOfIsland(grid, i+1, j) + AreaOfIsland(grid, i-1, j) + AreaOfIsland(grid, i, j-1) + AreaOfIsland(grid, i, j+1); 15 | } 16 | return 0; 17 | } 18 | }; -------------------------------------------------------------------------------- /695-max-area-of-island/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /70-climbing-stairs/70-climbing-stairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int dp[46]; 4 | int climbStairs(int n) { 5 | if(dp[n]!=0) return dp[n]; 6 | if(n==0||n==1||n==2||n==3) 7 | return n; 8 | if(dp[n]==0) 9 | dp[n]=climbStairs(n-1)+climbStairs(n-2); 10 | return dp[n]; 11 | } 12 | }; -------------------------------------------------------------------------------- /70-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /700-search-in-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /703-kth-largest-element-in-a-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /704-binary-search/704-binary-search.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& a, int t) { 4 | int l=0,h=a.size()-1,m=0; 5 | while(l<=h) 6 | { if(a[l]==t) 7 | return l; 8 | if(a[m]==t) 9 | return m; 10 | if(a[h]==t) 11 | return h; 12 | m=(l+h)/2; 13 | if(a[m]==t) 14 | return m; 15 | else if(a[m]& A, vector& B) { 4 | 5 | 6 | int n1 = A.size(), n2 = B.size(); 7 | 8 | vector dp(n2+1, 0); 9 | int ans = 0; 10 | 11 | for(int i = 0; i < n1; i++) { 12 | for(int j = n2 - 1; j >= 0; j--) { 13 | 14 | if (A[i] == B[j]) { 15 | dp[j + 1] = 1 + dp[j]; 16 | } else { 17 | dp[j + 1] = 0; 18 | } 19 | 20 | ans = max(ans, dp[j + 1]); 21 | } 22 | 23 | } 24 | 25 | return ans; 26 | } 27 | }; -------------------------------------------------------------------------------- /718-maximum-length-of-repeated-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /72-edit-distance/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /724-find-pivot-index/724-find-pivot-index.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int pivotIndex(vector& nums) { 4 | int total = 0; 5 | for (int num : nums) total += num; 6 | int sum = 0; 7 | for (int i = 0; i < nums.size(); sum += nums[i++]) 8 | if (sum * 2 == total - nums[i]) 9 | return i; 10 | 11 | return -1; 12 | } 13 | }; 14 | /* 15 | 1 8 11 17 22 18 16 | 28 27 20 17 11 6 17 | ==================== 18 | 19 | 20 | */ 21 | -------------------------------------------------------------------------------- /724-find-pivot-index/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /73-set-matrix-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /733-flood-fill/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /74-search-a-2d-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /75-sort-colors/75-sort-colors.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void sortColors(vector& v) 4 | { int low=0,mid=0,high=v.size()-1; 5 | while(mid<=high) 6 | { if(v[mid]==0) 7 | swap(v[mid++],v[low++]); 8 | else if(v[mid]==1) 9 | mid++; 10 | else 11 | swap(v[mid],v[high--]); 12 | } 13 | } 14 | }; -------------------------------------------------------------------------------- /75-sort-colors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /771-jewels-and-stones/771-jewels-and-stones.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numJewelsInStones(string J, string S) { 4 | set j(J.begin(), J.end()); 5 | return count_if(S.begin(), S.end(), [&j] (const char& c) { return j.count(c) == 1; }); 6 | } 7 | }; -------------------------------------------------------------------------------- /771-jewels-and-stones/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /792-number-of-matching-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /841-lclighter-data-idlgt257723750-data-bundle-id0-stylebackground-image-linear-gradienttransparent-0-transparent-calc50-4px-rgb204-242-241-calc50-4px-rgb204-242-241-100-transition-background-position-120ms-ease-in-out-0s-padding-120ms-ease-in-out-0s-background-size-100-200-background-position-initial-user-select-auto-keys-and-rooms-lclighterdiv-classlinerthreadicon-linerfirst-data-highlight-id257723750-data-bundle-id0-idlgt257723750-stylebackground-image-url-and-quot-https-profilegetlinercom-liner-service-bucket-user-photo-default-color-10-wsvg-and-quot-user-select-auto-div-classlinerthreadicon-dim-styleuser-select-auto-div-div-classlinerthreadicon-mentioned-styleuser-select-auto-div-classlinerthreadicon-mentionedimg-styleuser-select-auto-div-div-div-classlinerthreadicon-onlyme-styleuser-select-auto-div-classlinerthreadicon-onlymeimg-styleuser-select-auto-div-div-div/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /852-peak-index-in-a-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /867-transpose-matrix/867-transpose-matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> transpose(vector>& m) 4 | { 5 | int n = m.size(); 6 | vector>v( m[0].size(), vector (m.size(), 0)); 7 | for(int i=0; i> transpose(vector>& matrix) { 19 | int n = matrix.size(); 20 | int m= matrix[0].size(); 21 | vector>res(m,vector (n,0)); //creation of 2d array 22 | for(int i=0;i power; 8 | for(int i=0;i<=30;i++){ 9 | int p = pow(2,i); 10 | power.push_back(to_string(p)); 11 | } 12 | 13 | for(int i=0;i<=30;i++){ 14 | sort(power[i].begin(),power[i].end()); 15 | } 16 | 17 | for(int i=0;i<=30;i++){ 18 | if(power[i] == s ) return true; 19 | } 20 | return false; 21 | } 22 | }; -------------------------------------------------------------------------------- /869-reordered-power-of-2/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /871-minimum-number-of-refueling-stops/871-minimum-number-of-refueling-stops.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minRefuelStops(int target, int startFuel, vector>& stations) { 4 | int n= stations.size(); 5 | long dp[n+1]; 6 | memset(dp, 0, sizeof(dp)); 7 | dp[0]= startFuel; 8 | for(int i=0; i< n; i++){ 9 | for(int j=i; j>=0 && dp[j]>= stations[i][0]; j--) { 10 | dp[j+1] = max(dp[j+1], (dp[j]+ stations[i][1])); 11 | } 12 | } 13 | for(int i=0; i<=n ; i++){ 14 | if(dp[i]>=target) return i; 15 | } 16 | return -1; 17 | } 18 | }; -------------------------------------------------------------------------------- /871-minimum-number-of-refueling-stops/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/876-middle-of-the-linked-list.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* middleNode(ListNode* head) 14 | { 15 | ListNode*p=head,*q=head; 16 | while(p!=NULL&&p->next!=NULL) 17 | { 18 | p=p->next->next; 19 | q=q->next; 20 | 21 | } 22 | return q; 23 | } 24 | }; -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /88-merge-sorted-array/88-merge-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void merge(vector& n1, int m, vector& n2, int n) { 4 | int i = m-1, j =n-1, t = n+m-1; 5 | while (j >=0){ 6 | ((i>=0 && n1[i] > n2[j]) ? n1[t--] = n1[i--] : n1[t--] = n2[j--]); 7 | } 8 | } 9 | }; -------------------------------------------------------------------------------- /88-merge-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /91-decode-ways/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /92-reverse-linked-list-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /94-binary-tree-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /948-bag-of-tokens/948-bag-of-tokens.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int bagOfTokensScore(vector& tokens, int P) { 4 | sort(tokens.begin(), tokens.end()); 5 | int res = 0, points = 0, i = 0, j = tokens.size() - 1; 6 | while (i <= j) { 7 | if (P >= tokens[i]) { 8 | P -= tokens[i++]; 9 | res = max(res, ++points); 10 | } else if (points > 0) { 11 | points--; 12 | P += tokens[j--]; 13 | } else { 14 | break; 15 | } 16 | } 17 | return res; 18 | } 19 | }; -------------------------------------------------------------------------------- /948-bag-of-tokens/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /967-numbers-with-same-consecutive-differences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /977-squares-of-a-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /98-validate-binary-search-tree/98-validate-binary-search-tree.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 | vector v; 15 | void inorder(TreeNode*root) 16 | { 17 | if(root==NULL) return; 18 | inorder(root->left); 19 | v.push_back(root->val); 20 | inorder(root->right); 21 | } 22 | bool isValidBST(TreeNode *root) { 23 | inorder(root); 24 | int f=1; 25 | for(int i=0;i=v[i+1]) 28 | {f=0; 29 | break; 30 | }} 31 | return f; 32 | } 33 | }; -------------------------------------------------------------------------------- /98-validate-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /A. Petya and Strings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | https://codeforces.com/problemset/problem/112/A 4 | */ 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | int main() 10 | {char a[10000],b[10000],c,d;,./l 11 | int i,j; 12 | cin>>a; 13 | cin>>b; 14 | for(i=0;i<=strlen(a);i++) 15 | { if(a[i]>=65 && a[i]<=92) 16 | {a[i]=a[i] + 32;} 17 | } 18 | for(i=0;i<=strlen(b);i++) 19 | { if(b[i]>=65 && b[i]<=92) 20 | {b[i]=b[i] + 32;} 21 | } 22 | for(i=0,j=0;a[i]!='\0'&&b[j]!='\0';i++,j++) 23 | {if(a[i]!=b[j]) break;} 24 | if(a[i]==b[j])cout<<"0\n"; 25 | else if(a[i] 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | 7 | class Solution{ 8 | public: 9 | void update(int a[], int n, int updates[], int k) 10 | { 11 | for(int i=0;i0) a[i]+=a[i-1]; 19 | } 20 | } 21 | }; 22 | 23 | //{ Driver Code Starts. 24 | int main() 25 | { 26 | int t; cin>>t; 27 | while(t--) 28 | { 29 | int n,k; 30 | cin>>n>>k; 31 | int a[n]={0}, updates[k]={0}; 32 | for(int i = 0; i < k; i++) 33 | cin>>updates[i]; 34 | Solution ob; 35 | ob.update(a, n, updates, k); 36 | 37 | for(int i = 0; i < n; i++) 38 | cout< 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | int inSequence(int A, int B, int C){ 13 | if(C==0){ 14 | return A==B; 15 | } 16 | return (B-A)%C==0 && (B-A)/C>=0; 17 | 18 | } 19 | }; 20 | 21 | //{ Driver Code Starts. 22 | 23 | int main(){ 24 | int t; 25 | cin>>t; 26 | while(t--){ 27 | int A, B, C; 28 | cin>>A>>B>>C; 29 | 30 | Solution ob; 31 | cout< 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | //User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | int modulo(string s,int m) 13 | {int res = 0; 14 | for(const auto& x: s){ 15 | res = res*2 + (x-'0'); 16 | res = res%m; 17 | } 18 | return res; 19 | } 20 | }; 21 | 22 | //{ Driver Code Starts. 23 | 24 | int main() 25 | { 26 | int t; 27 | cin>>t; 28 | while(t--) 29 | { 30 | string s; 31 | int m; 32 | cin>>s>>m; 33 | Solution a; 34 | cout< 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | //User function Template for C++ 9 | class Solution{ 10 | public: 11 | int waysToBreakNumber(int N){ 12 | N++; 13 | 14 | long long int mod=1000000007; 15 | 16 | return ((N%mod)*((N%mod)+1)/2)%mod; 17 | } 18 | }; 19 | 20 | //{ Driver Code Starts. 21 | int main() 22 | { 23 | int t; 24 | cin>>t; 25 | while(t--) 26 | { 27 | int N; 28 | cin >> N; 29 | Solution ob; 30 | cout << ob.waysToBreakNumber(N) << endl; 31 | } 32 | return 0; 33 | } 34 | // } Driver Code Ends -------------------------------------------------------------------------------- /Copy Set Bits in Range - GFG/copy-set-bits-in-range.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | // Initial Template for C++ 3 | #include 4 | using namespace std; 5 | 6 | // } Driver Code Ends 7 | // User function Template for C++ 8 | class Solution{ 9 | public: 10 | int setSetBit(int x, int y, int l, int r){ 11 | bitset<32> A(x), B(y); 12 | for(int i = l-1; i <= r-1; ++i) if(B[i] == 1) A[i] = 1; 13 | return (int)(A.to_ulong()); 14 | } 15 | }; 16 | 17 | //{ Driver Code Starts. 18 | int main(){ 19 | int t; 20 | cin>>t; 21 | while(t--){ 22 | int x, y, l, r; 23 | cin>>x>>y>>l>>r; 24 | 25 | Solution ob; 26 | cout< 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution{ 11 | public: 12 | vector minimumSquares(long long int L, long long int B) 13 | { 14 | long long S = __gcd(L, B); // inbuilt function in C++ 15 | vector res = {(L*B)/(S*S), S}; 16 | return res; 17 | } 18 | }; 19 | 20 | //{ Driver Code Starts. 21 | 22 | int main(){ 23 | int t; 24 | cin>>t; 25 | while(t--){ 26 | long long int L, B; 27 | cin>>L>>B; 28 | 29 | Solution ob; 30 | vector ans = ob.minimumSquares(L, B); 31 | cout< 6 | 7 | // } Driver Code Ends 8 | //User function Template for C 9 | 10 | void toBinary(int n) 11 | { 12 | if(n==0) return; 13 | toBinary(n/2); 14 | printf("%d",n%2); 15 | 16 | } 17 | 18 | //{ Driver Code Starts. 19 | 20 | int main() { 21 | //code 22 | 23 | int t; 24 | scanf("%d", &t); 25 | 26 | 27 | while(t--) 28 | { 29 | int n; 30 | scanf("%d", &n); 31 | 32 | toBinary(n); 33 | printf("\n"); 34 | } 35 | return 0; 36 | } 37 | // } Driver Code Ends -------------------------------------------------------------------------------- /Find Number - GFG/find-number.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | //Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | //User function Template for C++ 10 | 11 | class Solution{ 12 | public: 13 | long long findNumber(long long n){ 14 | long long ans = 0; 15 | vector base5; 16 | while(n > 0) { 17 | n--, base5.push_back(n%5); 18 | n /= 5; 19 | } 20 | for(int i = base5.size()-1; i >= 0; i--) { 21 | ans = ans*10 + 2*base5[i] + 1; 22 | } 23 | return ans; 24 | 25 | } 26 | }; 27 | 28 | //{ Driver Code Starts. 29 | 30 | int main(){ 31 | int t; 32 | cin>>t; 33 | while(t--){ 34 | long long N; 35 | cin>>N; 36 | Solution ob; 37 | cout< 3 | using namespace std; 4 | 5 | 6 | // } Driver Code Ends 7 | class Solution { 8 | public: 9 | string removePair(string s) { 10 | int i=0; 11 | 12 | while(i>t; 39 | while(t--){ 40 | string s; 41 | cin>>s; 42 | 43 | Solution obj; 44 | string res = obj.removePair(s); 45 | 46 | cout< 3 | using namespace std; 4 | */ 5 | 6 | void reverseArray(int a[], int n){ 7 | int k=0,j=n-1; 8 | for(int i=0;i>N; 19 | int arr[N]; 20 | for(int i = 0; i < N; i++){ 21 | cin>>arr[i]; 22 | } 23 | reverseArray(arr, N); 24 | for(int i = 0; i < N; i++){ 25 | cout< 3 | #include 4 | using namespace std; 5 | 6 | void print(bitset<32> x){ 7 | cout< b1(1520); 13 | bitset<32> b2(1240); 14 | 15 | print(b1); 16 | print(b2); 17 | 18 | // Count the number of set bits in b1 and store it in count1 19 | int count1 = b1.count(); 20 | cout< 3 | #include 4 | using namespace std; 5 | */ 6 | 7 | class Student{ 8 | string name; 9 | int age; 10 | int rollno; 11 | public: 12 | // Create funtions here with the name given 13 | void set_variable(string n,int a,int r) 14 | { 15 | this->name=n; 16 | this->age=a; 17 | this->rollno=r; 18 | } 19 | void print_variable() 20 | { 21 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int num; 7 | cin>>num; 8 | if (num >= 90) cout<<"A\n"; 9 | else if (num >= 80)cout<<"B\n"; 10 | else if( num >= 70)cout<<"C\n"; 11 | else if( num >= 60)cout<<"D\n"; 12 | else if (num >= 50)cout<<"E\n"; 13 | else cout<<"F\n"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Conditional or Ternary Expression.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int x, y; 7 | cin>>x>>y; 8 | (x<=y?cout<<"Robin":cout<<"Rahul"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Cpp Exception Handling.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | using namespace std; 4 | 5 | int division(int a, int b) { 6 | if( b == 0 ) { 7 | throw "Division by zero condition!"; 8 | } 9 | return (a/b); 10 | } 11 | */ 12 | 13 | int main() { 14 | int a, b; 15 | cin>>a>>b; 16 | 17 | // call function division(a, b) 18 | // print the result in try else exception in catch 19 | // Your code goes here 20 | 21 | try{ 22 | if(b!=0) 23 | cout<a,pairb) 2 | { 3 | if((a.first+a.second)<(b.first+b.second)) 4 | return true; 5 | return false; 6 | } 7 | void sortArray(vector> &v){ 8 | sort(v.begin(),v.end(),comp); 9 | } 10 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Functions - Basic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | using namespace std; 4 | */ 5 | 6 | // Your Code goes here 7 | int compute(int a,int b) 8 | { 9 | return a*a+b*b; 10 | } 11 | 12 | 13 | 14 | 15 | /* 16 | int main() { 17 | int A, B; 18 | cin>>A>>B; 19 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | // YOUR CODE GOES HERE 7 | // Please take input and print output to standard input/output (stdin/stdout) 8 | // E.g. 'cin' for input & 'cout' for output 9 | cout<<"Hello, InterviewBit!"; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Jump Statements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int N; 7 | cin>>N; 8 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | int main() { 5 | int N; 6 | cin>>N; 7 | for(int i=0;i 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin>>n; 8 | mapmp; 9 | while(n--) 10 | { 11 | int k; 12 | cin>>k; 13 | if(k==1) 14 | { 15 | int x,y; 16 | cin>>x>>y; 17 | mp[x]+=y; 18 | } 19 | else{ 20 | int x; 21 | cin>>x; 22 | if(k==2) 23 | mp.erase(x); 24 | else 25 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | float a = 12.56, b = 5.12; 7 | // Print the sum of cube of both A and B, and store it in float variable named "cube_val" 8 | float cube_val=pow(a,3)+pow(b,3); 9 | cout< 3 | using namespace std; 4 | */ 5 | 6 | // Your code goes here 7 | void compute(int &a,int &b,int &c) 8 | { 9 | a=a*a*a; 10 | b=b*b*b; 11 | c=c*c*c; 12 | } 13 | 14 | 15 | /* 16 | int main() { 17 | int A, B, C; 18 | cin>>A>>B>>C; 19 | compute(A, B, C); 20 | cout< 3 | using namespace std; 4 | */ 5 | 6 | int main() { 7 | int N,n; 8 | cin>>N; 9 | n=N; 10 | // YOUR CODE GOES HERE 11 | int grid[N+1][N+1]={2}; 12 | for(int i=0;i 3 | using namespace std; 4 | */ 5 | 6 | void solve(int *A, int *B){ 7 | int c=*A; 8 | *A=*A+*B; 9 | (*B>A>>B; 19 | solve(pA, pB); 20 | cout< 3 | using namespace std; 4 | */ 5 | 6 | // YOUR CODE GOES HERE 7 | int compute(int a,int b) 8 | { 9 | return abs(a-b); 10 | } 11 | int compute(int a) 12 | { 13 | return a*a; 14 | } 15 | 16 | 17 | /* 18 | int main() { 19 | int x,y; 20 | cin>>x>>y; 21 | cout<>z; 24 | cout< &arr){ 2 | int n=arr.size(); 3 | priority_queue, greater > pq(arr.begin(),arr.end()); 4 | 5 | // Initialize result 6 | int res = 0; 7 | 8 | // While size of priority queue is more than 1 9 | while (pq.size() > 1) { 10 | // Extract shortest two ropes from pq 11 | int first = pq.top(); 12 | pq.pop(); 13 | int second = pq.top(); 14 | pq.pop(); 15 | 16 | // Connect the ropes: update result and 17 | // insert the new rope to pq 18 | res += first + second; 19 | pq.push(first + second); 20 | } 21 | 22 | return res; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Set and Multiset.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int n; 8 | sets; 9 | cin>>n; 10 | while(n--) 11 | { 12 | int x,y; 13 | cin>>y>>x; 14 | if(y==1) 15 | { 16 | s.insert(x); 17 | } 18 | else if(y==2) 19 | { 20 | s.erase(x); 21 | } 22 | else{ 23 | auto itr=s.find(x); 24 | (itr==s.end()?cout<<"No\n":cout<<"Yes\n"); 25 | } 26 | } 27 | if(s.size()>0) 28 | for(auto it=s.begin();it!=s.end();it++) 29 | cout<<*it<<"\n"; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/StringStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | using namespace std; 5 | */ 6 | int main() { 7 | string A; 8 | cin>>A; 9 | stringstream ss(A); 10 | char ch; 11 | int a; 12 | while(ss>>a>>ch) 13 | cout< 3 | #include 4 | using namespace std; 5 | */ 6 | 7 | int main() { 8 | string A, B; 9 | cin>>A>>B; 10 | cout< 3 | #include 4 | using namespace std; 5 | */ 6 | struct student{ 7 | string name; 8 | int rollno; 9 | int marks; 10 | }; 11 | 12 | // Create Structure named 'student' 13 | 14 | int main() { 15 | // Your code goes here 16 | student s1; 17 | s1.name="Robin"; 18 | s1.rollno=11; 19 | s1.marks=86; 20 | 21 | // Don't change the below code 22 | cout< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int weekday; 7 | cin>>weekday; 8 | switch(weekday) 9 | { 10 | case 1: cout<<"Monday\n"; 11 | break; 12 | case 2: cout<<"Tuesday\n"; 13 | break; 14 | case 3: cout<<"Wednesday\n"; 15 | break; 16 | case 4: cout<<"Thrusday\n"; 17 | break; 18 | case 5: cout<<"Friday\n"; 19 | break; 20 | case 6: cout<<"Saturday\n"; 21 | break; 22 | case 7: cout<<"Sunday\n"; 23 | 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Templates.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | using namespace std; 4 | */ 5 | 6 | // Your code goes here 7 | template 8 | int index_of_largest(Type a[],int n) 9 | { int j; 10 | Type m=a[0]; 11 | for(int i=0;im) 14 | { 15 | m=a[i]; 16 | j=i; 17 | } 18 | 19 | } 20 | return j; 21 | } 22 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Type Conversion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | char ch; 7 | cin>>ch; 8 | cout<<(int)ch; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Upper & Lower bound.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | int n,k; 9 | cin>>n; 10 | vectorv; 11 | for(int i=0;i>k; 13 | v.push_back(k); 14 | } 15 | cin>>k; 16 | while(k--) 17 | { 18 | int g,f=0; 19 | cin>>g; 20 | for(int i=0;ig) 28 | { f=1; 29 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // YOUR CODE GOES HERE 7 | // Please take input and print output to standard input/output (stdin/stdout) 8 | // E.g. 'cin' for input & 'cout' for output 9 | int a; 10 | long b; 11 | char c; 12 | float e; 13 | double f; 14 | cin>>a>>b>>c>>e>>f; 15 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | // YOUR CODE GOES HERE 8 | // Please take input and print output to standard input/output (stdin/stdout) 9 | // E.g. 'cin' for input & 'cout' for output 10 | int n,k; 11 | vectorv; 12 | cin>>n; 13 | for(int i=0;i>k; 16 | v.push_back(k); 17 | } 18 | int g; 19 | cin>>g; 20 | //g=g-1; 21 | v.erase(v.begin()+g); 22 | sort(v.begin(),v.end()); 23 | // v.erase(v.begin()+g); 24 | for(int i=0;i 4 | using namespace std; 5 | 6 | // } Driver Code Ends 7 | //User function template for C++ 8 | class Solution{ 9 | public: 10 | 11 | int isDivisible(string s){ 12 | //complete the function here 13 | int i,odd=0,eve=0,n=s.size(); 14 | for(i=0;i> t; 30 | while(t--){ 31 | string s; 32 | cin >> s; 33 | Solution ob; 34 | cout << ob.isDivisible(s) << endl; 35 | } 36 | return 0; 37 | } 38 | 39 | 40 | // } Driver Code Ends -------------------------------------------------------------------------------- /Kth largest element in BST .cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | void inorder(Node*root,vector&v){ 5 | if(root==NULL) return; 6 | inorder(root->left,v); 7 | v.push_back(root->data); 8 | inorder(root->right,v); 9 | } 10 | int kthLargest(Node *root, int K) 11 | { 12 | vectorv; 13 | inorder(root,v); 14 | return v[v.size()-K]; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Last modified ball - GFG/last-modified-ball.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | // Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution { 11 | public: 12 | int solve(int n, vector A) { 13 | for(int i=n-1; i>=0; i--) if(A[i] < 9) return i+1; 14 | return -1; 15 | } 16 | }; 17 | 18 | //{ Driver Code Starts. 19 | 20 | int main() { 21 | int T; 22 | cin >> T; 23 | while (T--) { 24 | int N; 25 | cin >> N; 26 | vector A(N); 27 | 28 | for (int i = 0; i < N; i++) cin >> A[i]; 29 | 30 | Solution ob; 31 | cout << ob.solve(N, A) << "\n"; 32 | } 33 | return 0; 34 | } 35 | 36 | // } Driver Code Ends -------------------------------------------------------------------------------- /Make Array Elements Equal - GFG/make-array-elements-equal.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | // Initial Template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function Template for C++ 9 | 10 | class Solution { 11 | public: 12 | long long int minOperations(long long int n) { 13 | if(n%2==0) 14 | return (n/2)*(n/2); 15 | return ((n-1)/2)*((n-1)/2)+((n-1)/2); 16 | } 17 | }; 18 | 19 | //{ Driver Code Starts. 20 | int main() { 21 | int t; 22 | cin >> t; 23 | while (t--) { 24 | int n; 25 | cin >> n; 26 | Solution ob; 27 | cout << ob.minOperations(n) << endl; 28 | } 29 | return 0; 30 | } 31 | // } Driver Code Ends -------------------------------------------------------------------------------- /Matchsticks game - GFG/matchsticks-game.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | int matchGame(long long N) {return int(N % 5) == 0 ? -1: int(N % 5); } 9 | }; 10 | 11 | //{ Driver Code Starts. 12 | int main() { 13 | int t; 14 | cin >> t; 15 | while (t--) { 16 | long long N; 17 | 18 | cin>>N; 19 | 20 | Solution ob; 21 | cout << ob.matchGame(N) << endl; 22 | } 23 | return 0; 24 | } 25 | // } Driver Code Ends -------------------------------------------------------------------------------- /Middle of Three .cpp: -------------------------------------------------------------------------------- 1 | //Initial template for C++ 2 | 3 | #include 4 | using namespace std; 5 | 6 | // } Driver Code Ends 7 | //User function template for C++ 8 | class Solution{ 9 | public: 10 | int middle(int A, int B, int C) 11 | { 12 | if((A>B&&AC) 13 | return A; 14 | else if((B>A&&BC)) 15 | return B; 16 | else 17 | return C; 18 | } 19 | }; 20 | 21 | // { Driver Code Starts. 22 | int main() 23 | { 24 | int t; 25 | cin>>t; 26 | while(t--) 27 | { 28 | int A,B,C; 29 | cin>>A>>B>>C; 30 | Solution ob; 31 | cout< 5 | using namespace std; 6 | 7 | 8 | // } Driver Code Ends 9 | // User function Template for C++ 10 | 11 | int minSteps(string str) { 12 | int ans=0; 13 | for(int i=0;i> t; 27 | while (t--) { 28 | string str; 29 | cin >> str; 30 | cout << minSteps(str) << endl; 31 | } 32 | } 33 | 34 | // } Driver Code Ends -------------------------------------------------------------------------------- /Mirror Tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | // Function to convert a binary tree into its mirror tree. 4 | void mirror(Node* root) 5 | { 6 | if(!root)return; 7 | mirror(root->left); 8 | mirror(root->right); 9 | swap(root->left,root->right); 10 | 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /Nth Fibonacci Number - GFG/nth-fibonacci-number.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | // Initial Template for C++ 3 | #include 4 | using namespace std; 5 | 6 | // } Driver Code Ends 7 | // User function Template for C++ 8 | class Solution { 9 | public: 10 | int nthFibonacci(int n){ 11 | const int mod = 1000000007; 12 | vectorv(n+1) ; 13 | v[0] = 0; 14 | v[1] = 1 ; 15 | for (int i=2 ; i<=n ; i++){ 16 | v[i] = (v[i-1]+v[i-2])%mod; 17 | } 18 | return v[n]; 19 | } 20 | 21 | }; 22 | 23 | //{ Driver Code Starts. 24 | int main() { 25 | int t; 26 | cin >> t; 27 | while (t--) { 28 | int n; 29 | cin >> n; 30 | Solution ob; 31 | cout << ob.nthFibonacci(n) << endl; 32 | } 33 | return 0; 34 | } 35 | 36 | // } Driver Code Ends -------------------------------------------------------------------------------- /Nth catalan number - GFG/nth-catalan-number.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution 7 | { 8 | public: 9 | //Function to find the nth catalan number. 10 | int findCatalan(int n) 11 | { 12 | vector catalan(n+2); 13 | catalan[0]=1; 14 | catalan[1]=1; 15 | for(int i=2;i<=n;i++){ 16 | catalan[i]=0; 17 | for(int j=0;j>t; 31 | while(t--) { 32 | 33 | int n; 34 | cin>>n; 35 | Solution obj; 36 | cout<< obj.findCatalan(n) <<"\n"; 37 | } 38 | return 0; 39 | } 40 | // } Driver Code Ends -------------------------------------------------------------------------------- /Number of 1 Bits - GFG/number-of-1-bits.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | int setBits(int N) { 9 | return __builtin_popcount(N); 10 | } 11 | }; 12 | 13 | //{ Driver Code Starts. 14 | int main() { 15 | int t; 16 | cin >> t; 17 | while (t--) { 18 | int N; 19 | cin >> N; 20 | 21 | Solution ob; 22 | int cnt = ob.setBits(N); 23 | cout << cnt << endl; 24 | } 25 | return 0; 26 | } 27 | 28 | // } Driver Code Ends -------------------------------------------------------------------------------- /Q49 Combination Sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void findCombination(int ind, int target, vector &arr, vector> &ans, vector&ds) { 4 | if(ind == arr.size()) { 5 | if(target == 0) { 6 | ans.push_back(ds); 7 | } 8 | return; 9 | } 10 | // pick up the element 11 | if(arr[ind] <= target) { 12 | ds.push_back(arr[ind]); 13 | findCombination(ind, target - arr[ind], arr, ans, ds); 14 | ds.pop_back(); 15 | } 16 | 17 | findCombination(ind+1, target, arr, ans, ds); 18 | 19 | } 20 | public: 21 | vector> combinationSum(vector& candidates, int target) { 22 | vector> ans; 23 | vector ds; 24 | findCombination(0, target, candidates, ans, ds); 25 | return ans; 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /Q9. next_permutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void nextPermutation(vector& nums) { 4 | const int n = nums.size(); 5 | 6 | // from back to front, find the first num < nums[i + 1] 7 | int i; 8 | for (i = n - 2; i >= 0; --i) 9 | if (nums[i] < nums[i + 1]) 10 | break; 11 | 12 | // from back to front, find the first num > nums[i], swap it with nums[i] 13 | if (i >= 0) 14 | for (int j = n - 1; j > i; --j) 15 | if (nums[j] > nums[i]) { 16 | swap(nums[i], nums[j]); 17 | break; 18 | } 19 | 20 | // reverse nums[i + 1..n - 1] 21 | reverse(nums, i + 1, n - 1); 22 | } 23 | 24 | private: 25 | void reverse(vector& nums, int l, int r) { 26 | while (l < r) 27 | swap(nums[l++], nums[r--]); 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Remainder on dividing by 11 - GFG/remainder-on-dividing-by-11.py: -------------------------------------------------------------------------------- 1 | #User function Template for python3 2 | 3 | 4 | class Solution: 5 | def xmod11(self,x): 6 | return int(x)%11 7 | #code here 8 | 9 | 10 | #{ 11 | # Driver Code Starts 12 | #Initial Template for Python 3 13 | 14 | 15 | if __name__ == '__main__': 16 | tcs=int(input()) 17 | for _ in range(tcs): 18 | x = input() 19 | 20 | ob = Solution() 21 | 22 | print(ob.xmod11(x)) 23 | 24 | # } Driver Code Ends -------------------------------------------------------------------------------- /Reverse Coding - GFG/reverse-coding.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | #include 3 | using namespace std; 4 | 5 | // } Driver Code Ends 6 | class Solution { 7 | public: 8 | int sumOfNaturals(int n) { 9 | return long(long(n*long(n+1)/2)%1000000007); 10 | } 11 | }; 12 | 13 | //{ Driver Code Starts. 14 | int main() { 15 | int t; 16 | cin >> t; 17 | while (t--) { 18 | int n; 19 | 20 | cin>>n; 21 | 22 | Solution ob; 23 | cout << ob.sumOfNaturals(n) << endl; 24 | } 25 | return 0; 26 | } 27 | // } Driver Code Ends -------------------------------------------------------------------------------- /Reverse The String.cpp: -------------------------------------------------------------------------------- 1 | //Initial Template for C++ 2 | 3 | 4 | #include 5 | using namespace std; 6 | 7 | 8 | string reverseWord(string str); 9 | 10 | 11 | int main() { 12 | 13 | int t; 14 | cin>>t; 15 | while(t--) 16 | { 17 | string s; 18 | cin >> s; 19 | 20 | cout << reverseWord(s) << endl; 21 | } 22 | return 0; 23 | 24 | } 25 | 26 | // } Driver Code Ends 27 | 28 | string reverseWord(string str){ 29 | 30 | string rev = ""; 31 | for(int i = str.size()-1;i>=0 ;i--){ 32 | rev += str[i]; 33 | } 34 | 35 | return rev; 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Striver Sheet 180 QuestionQ16. Unique Paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int uniquePaths(int m, int n) { 4 | // dp[i][j] := unique paths from (0, 0) to (i, j) 5 | vector> dp(m, vector(n, 1)); 6 | 7 | for (int i = 1; i < m; ++i){ 8 | for (int j = 1; j < n; ++j){ 9 | dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; 10 | } 11 | } 12 | 13 | return dp[m-1][n-1]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q1. SOrt colors.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void sortColors(vector& nums) { 4 | 5 | int count0=0; 6 | int count1=0; 7 | int count2=0; 8 | vector zero, one, two; 9 | 10 | for(int i=0;i>& matrix, int target) { 6 | if (matrix.empty()) 7 | return false; 8 | 9 | const int m = matrix.size(); 10 | const int n = matrix[0].size(); 11 | 12 | int l = 0; 13 | int r = m * n; 14 | 15 | while (l <= r) { 16 | const int mid = l + (r - l) / 2; 17 | const int i = mid / n ; 18 | const int j = mid % n; 19 | if (matrix[i][j] == target) 20 | return true; 21 | if (matrix[i][j] < target) 22 | l = mid + 1; 23 | else 24 | r = mid ; 25 | } 26 | 27 | return false; 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q13.Search a 2D Matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool searchMatrix(vector>& mat, int t) { 4 | int i,j; 5 | for(i=0;i and the number it it gets the resultant 4 | > multiply it till it get 0 or 1. 5 | */ 6 | class Solution { 7 | public: 8 | double myPow(double x, int n) { 9 | // base case 10 | // +ve power 11 | if(n == 0 || n == 1) 12 | return n == 0 ? 1 : x; 13 | // -ve power 14 | if(n == -1) 15 | return 1 / x; 16 | 17 | double power = myPow(x, n/2); 18 | // if power n is even 19 | if(n % 2 == 0) 20 | return power * power; 21 | // odd power 22 | else { 23 | return power * power * (n < 0 ? (1 / x) : x); 24 | } 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q15. Majority Element(n*0.5 times).cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int majorityElement(vector& nums) { 4 | sort(nums.begin(),nums.end()); 5 | return nums[nums.size()/2]; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q15.Majority Element (>N2 times).cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int majorityElement(vector& n) { 4 | if(n.size()==1) 5 | return n[0]; 6 | sort(n.begin(),n.end()); 7 | int max=0,c=0,g=n[0],l=0; 8 | for(int i=1;i=max) 13 | { max=c; 14 | l=n[i]; 15 | } 16 | } 17 | else{ 18 | g=n[i]; 19 | c=0; 20 | } 21 | } 22 | return l; 23 | 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q17. Grid unique paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int uniquePaths(int m, int n) { 4 | // dp[i][j] := unique paths from (0, 0) to (i, j) 5 | vector> dp(m, vector(n, 1)); 6 | 7 | for (int i = 1; i < m; ++i){ 8 | for (int j = 1; j < n; ++j){ 9 | dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; 10 | } 11 | } 12 | 13 | return dp[m-1][n-1]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q17.Grid Unique Paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int uniquePaths(int m, int n) { 4 | vector > dp(m, vector (n,1)); 5 | for (int i=1; i& nums) { 9 | int n = nums.size(); 10 | if (!n) return 0; 11 | sort(nums.begin(), nums.end()); // first sort the vector 12 | int ans = 1, len = 1; 13 | for (int i = 0; i < n - 1; i++) { 14 | if (nums[i + 1] == nums[i]) continue; // ignore duplicates 15 | if (nums[i + 1] == 1 + nums[i]) 16 | len++; // add length of current sequence 17 | else { 18 | ans = max(ans, len); // update max length 19 | len = 1; // reset length of current sequencecurrent 20 | } 21 | } 22 | ans = max(ans, len); // update ans with last sequence length 23 | return ans; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q22.Largest Subarray with 0 sum.cpp: -------------------------------------------------------------------------------- 1 | int maxLen(int a[], int n) 2 | { 3 | unordered_mapmmp; 4 | int maxi=0; 5 | int sum=0; 6 | for(int i=0;id(256,-1); 6 | int maxlen=0,start=-1; 7 | for(int i=0;istart) 10 | start=d[s[i]]; 11 | d[s[i]]=i; 12 | maxlen=max(maxlen,i-start); 13 | } 14 | return (maxlen); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q26. Middle of the Linked List.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* middleNode(ListNode* head) 14 | { 15 | ListNode* slow=head,*fast=head; 16 | while(fast!=NULL and fast->next!=NULL) 17 | { 18 | slow=slow->next; 19 | fast=fast->next->next; 20 | } 21 | return slow; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q29. Remove Nth Node From End of Linked List.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* removeNthFromEnd(ListNode* head, int n) 14 | { 15 | ListNode *start=new ListNode(); 16 | start->next=head; 17 | ListNode* fast=start; 18 | ListNode* slow=start; 19 | for(int i=1;i<=n;++i) 20 | fast=fast->next; 21 | while(fast->next!=NULL) 22 | { 23 | fast=fast->next; 24 | slow=slow->next; 25 | } 26 | slow->next=slow->next->next; 27 | return start->next; 28 | 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q30. Delete Node in a Linked List.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | void deleteNode(ListNode* node) 12 | { 13 | node->val=node->next->val; 14 | node->next=node->next->next; 15 | 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q32. Intersection point of two Linked Lists.cpp: -------------------------------------------------------------------------------- 1 | /* Definition for singly-linked list. 2 | * struct ListNode { 3 | * int val; 4 | * ListNode *next; 5 | * ListNode(int x) : val(x), next(NULL) {} 6 | * }; 7 | */ 8 | class Solution { 9 | public: 10 | ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { 11 | auto temp1 = headA, temp2 = headB; 12 | 13 | while(temp1!=temp2) { 14 | temp1 = temp1!=NULL ? temp1->next : headB; 15 | temp2 = temp2!=NULL ? temp2->next : headA; 16 | } 17 | 18 | return temp1; 19 | 20 | 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q33 Linked List Cycle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode(int x) : val(x), next(NULL) {} 7 | * }; 8 | */ 9 | class Solution { 10 | public: 11 | bool hasCycle(ListNode *head) 12 | { 13 | if(head==NULL||head->next==NULL) 14 | return false; 15 | ListNode *fast=head; 16 | ListNode *slow=head; 17 | while(fast->next&&fast->next->next) 18 | { 19 | fast = fast->next->next; 20 | slow=slow->next; 21 | if(fast==slow) 22 | return true; 23 | } 24 | return false; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q39. 3Sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> threeSum(vector& v) 4 | { 5 | vector>ans; 6 | sort(v.begin(),v.end()); 7 | int n=v.size(); 8 | for(int i=0;it) e--; 24 | else s++; 25 | } 26 | while(i+1&v) 4 | { 5 | int m=0,c=0,i; 6 | for(i=0;im) 14 | m=c; 15 | } 16 | } 17 | return m; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q43. N meetings in one room .cpp: -------------------------------------------------------------------------------- 1 | int maxMeetings(int start[], int end[], int n){ 2 | vector> v; 3 | for(int i=0;id[j]) 16 | { 17 | p--; 18 | j++; 19 | } 20 | if(p>r) 21 | { 22 | r=p; 23 | } 24 | } 25 | return r; 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q45 Job Sequencing Problem .cpp: -------------------------------------------------------------------------------- 1 | bool comp(Job j1,Job j2) 2 | { 3 | 4 | return (j1.profit>j2.profit); 5 | } 6 | 7 | class Solution 8 | { 9 | public: 10 | //Function to find the maximum profit and the number of jobs done. 11 | vector JobScheduling(Job arr[], int n) 12 | { 13 | // your code here 14 | sort(arr,arr+n,comp); 15 | vectorans(n,-1),res(2,0); 16 | for(int i=0;i=0; j--) 19 | { 20 | if(ans[j]==-1) 21 | { 22 | ans[j]=arr[i].id; 23 | res[0]++; 24 | res[1]+=arr[i].profit; 25 | break; 26 | } 27 | } 28 | } 29 | return res; 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q46. Fractional Knapsack .cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | static bool cmp(struct Item i1, struct Item i2){ 5 | double vw1 = (double) i1.value/i1.weight; 6 | double vw2 = (double) i2.value/i2.weight; 7 | 8 | return vw1 > vw2; 9 | } 10 | 11 | double fractionalKnapsack(int W, Item arr[], int n){ 12 | sort(arr, arr+n, cmp); 13 | double fVal = 0; 14 | 15 | for(int i = 0; i < n; i++){ 16 | if(arr[i].weight <= W){ 17 | fVal += arr[i].value; 18 | W -= arr[i].weight; 19 | } 20 | 21 | else{ 22 | double priceperWt = (double) arr[i].value/arr[i].weight; 23 | fVal += priceperWt * W; 24 | break; 25 | } 26 | } 27 | 28 | return fVal; 29 | } 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q47 Subset sum1.cpp: -------------------------------------------------------------------------------- 1 | void summ(int i,int N,vector &arr,int sum,vector &v){ 2 | if(i==N){ 3 | v.push_back(sum); 4 | return; 5 | } 6 | 7 | 8 | summ(i+1,N,arr,sum,v); 9 | summ(i+1,N,arr,sum+arr[i],v); 10 | 11 | } 12 | 13 | vector subsetSums(vector arr, int N) 14 | { 15 | // Write Your Code here 16 | vector v; 17 | summ(0,N,arr,0,v); 18 | sort(v.begin(),v.end()); 19 | return v; 20 | } 21 | -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q52 K-th Permutation Sequence .cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string getPermutation(int n, int k) { 4 | int fact = 1; 5 | vector numbers; 6 | for(int i = 1;i> generate(int numRows) { 4 | vector> ans; 5 | 6 | for (int i = 0; i < numRows; ++i) 7 | ans.push_back(vector(i + 1, 1)); 8 | 9 | for (int i = 2; i < numRows; ++i) 10 | for (int j = 1; j < ans[i].size() - 1; ++j) 11 | ans[i][j] = ans[i - 1][j - 1] + ans[i - 1][j]; 12 | 13 | return ans; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /Type it! - GFG/type-it.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | // Initial template for C++ 3 | 4 | #include 5 | using namespace std; 6 | 7 | // } Driver Code Ends 8 | // User function template for C++ 9 | 10 | class Solution 11 | { 12 | public: 13 | int minOperation(string s) 14 | { 15 | int n = s.size(), ans = 0; 16 | for (int i = 0; i < n / 2; i++) 17 | if (s.substr(0, i + 1) == s.substr(i + 1, i + 1)) 18 | ans = i; 19 | return n - ans; 20 | } 21 | }; 22 | 23 | //{ Driver Code Starts. 24 | int main() { 25 | int t; 26 | cin >> t; 27 | while (t--) { 28 | string s; 29 | cin >> s; 30 | Solution ob; 31 | cout << ob.minOperation(s) << "\n"; 32 | } 33 | return 0; 34 | } 35 | 36 | // } Driver Code Ends -------------------------------------------------------------------------------- /binary-search/binary-search.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& a, int t) { 4 | int l=0,h=a.size()-1,m=0; 5 | while(l<=h) 6 | { if(a[l]==t) 7 | return l; 8 | if(a[m]==t) 9 | return m; 10 | if(a[h]==t) 11 | return h; 12 | m=(l+h)/2; 13 | if(a[m]==t) 14 | return m; 15 | else if(a[m]v; 15 | vector inorderTraversal(TreeNode* root) 16 | { inorder(root); 17 | return v; 18 | } 19 | private: 20 | void inorder(TreeNode *root) 21 | { 22 | if (root == NULL) 23 | return; 24 | inorder(root->left); 25 | //cout << root->value << ": "; 26 | v.push_back(root->val); 27 | inorder(root->right); 28 | } 29 | }; -------------------------------------------------------------------------------- /binary-tree-level-order-traversal/binary-tree-level-order-traversal.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> levelOrder(TreeNode* root) { 4 | vector> output; 5 | if (root != nullptr) { 6 | queue q; 7 | q.push(root); 8 | while (q.size() != 0) { 9 | int levelSize = q.size(); 10 | vector values; 11 | for (int i = 0; i < levelSize; i++) { 12 | TreeNode* node = q.front(); 13 | values.push_back(node->val); 14 | if (node->left !=NULL) q.push(node->left); 15 | if (node->right !=NULL)q.push(node->right); 16 | q.pop(); 17 | } 18 | output.push_back(values); 19 | } 20 | } 21 | return output; 22 | 23 | } 24 | }; -------------------------------------------------------------------------------- /binary-tree-preorder-traversal/binary-tree-preorder-traversal.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 | vectorans; 15 | vector preorderTraversal(TreeNode* root) { 16 | findPreorder(root); 17 | return ans; 18 | } 19 | void findPreorder(TreeNode* root){ 20 | if(root==NULL){ 21 | return; 22 | } 23 | ans.push_back(root->val); 24 | findPreorder(root->left); 25 | findPreorder(root->right); 26 | } 27 | }; -------------------------------------------------------------------------------- /build-array-from-permutation/build-array-from-permutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | vector buildArray(vector& nums) 5 | { 6 | for (auto& i : nums) 7 | { 8 | i = i + (nums[i] % nums.size()) * nums.size(); 9 | } 10 | for (auto& i : nums) 11 | { 12 | i = i / nums.size(); 13 | } 14 | return nums; 15 | } 16 | }; -------------------------------------------------------------------------------- /climbing-stairs/climbing-stairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int climbStairs(int n) { 4 | 5 | int i,x=0,y=1,z=0; 6 | for(int i=0;i &arr, vector> &ans, vector&ds) { 4 | if(ind == arr.size()) { 5 | if(target == 0) { 6 | ans.push_back(ds); 7 | } 8 | return; 9 | } 10 | // pick up the element 11 | if(arr[ind] <= target) { 12 | ds.push_back(arr[ind]); 13 | findCombination(ind, target - arr[ind], arr, ans, ds); 14 | ds.pop_back(); 15 | } 16 | 17 | findCombination(ind+1, target, arr, ans, ds); 18 | 19 | } 20 | public: 21 | vector> combinationSum(vector& candidates, int target) { 22 | vector> ans; 23 | vector ds; 24 | findCombination(0, target, candidates, ans, ds); 25 | return ans; 26 | } 27 | }; -------------------------------------------------------------------------------- /concatenation-of-array/concatenation-of-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector getConcatenation(vector& nums) { 4 | vector retval; 5 | for(int i = 0; i < 2 * nums.size(); i++) { 6 | retval.push_back(nums[i%nums.size()]); 7 | } 8 | return retval; 9 | } 10 | }; -------------------------------------------------------------------------------- /container-with-most-water/container-with-most-water.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxArea(vector& height) { 4 | int n = height.size(); 5 | int max_area = INT_MIN; 6 | int i=0; 7 | int j= n-1; 8 | while(i& nums) { 4 | sort(nums.begin(),nums.end()); 5 | for(int i=0;i countBits(int num) { 4 | vector counter(num+1, 0); // solution vector with size (num+1), each element initialised to 0 5 | 6 | for(int i=1; i<=num; ++i){ 7 | int n = i; 8 | while(n){ 9 | counter[i]++; // increasing count of set bits till n is not zero 10 | n = n&(n-1); // clearing the first set bit from the right, each time 11 | } 12 | } 13 | 14 | return counter; 15 | } 16 | }; -------------------------------------------------------------------------------- /diagonal-traverse-ii/diagonal-traverse-ii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findDiagonalOrder(vector>& nums) { 4 | vector> table; 5 | 6 | for(int i = 0; i != nums.size(); i++){ 7 | if(i + nums[i].size() > table.size()) table.resize(i + nums[i].size()); 8 | for(int j = i, k = 0; k != nums[i].size(); j++, k++) table[j].push_back(nums[i][k]); 9 | } 10 | 11 | vectoranswer; 12 | for(auto &x: table) 13 | for(int i = x.size()-1; i >= 0; i--) answer.push_back(x[i]); 14 | 15 | return answer; 16 | } 17 | }; -------------------------------------------------------------------------------- /difference of index of largest digit and smallest digit.c: -------------------------------------------------------------------------------- 1 | //difference of index of largest digit and smallest digit 2 | 3 | #include 4 | int main () 5 | { 6 | int num, remider=0,largest,i=0,p,z,q ,sh; 7 | printf ("Enter the Number :"); 8 | scanf ("%d", &num); 9 | int smallest=num%10; 10 | largest=num%10; 11 | while (num > 0) 12 | { 13 | remider = num % 10; 14 | if (smallest> remider) 15 | { 16 | smallest = remider; 17 | p=i; 18 | } 19 | if(largest 0) 29 | printf (":%d \n",z); 30 | else 31 | printf (":%d \n",z*-1); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /divide-two-integers/divide-two-integers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int divide(int dividend, int divisor) 4 | { 5 | if(dividend==INT_MIN && divisor==-1) return INT_MAX; 6 | div_t divresult = div(dividend, divisor); 7 | return divresult.quot; 8 | } 9 | }; -------------------------------------------------------------------------------- /fibonacci-number/fibonacci-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int fib(int n) 4 | { 5 | if(n==0) 6 | return 0; 7 | if(n==1) 8 | return 1; 9 | if(n==2) 10 | return 1; 11 | return fib(n-1)+fib(n-2); 12 | } 13 | }; -------------------------------------------------------------------------------- /final-value-of-variable-after-performing-operations/final-value-of-variable-after-performing-operations.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int finalValueAfterOperations(vector& operations) { 4 | int x=0; 5 | for(int i=0;i targetIndices(vector& a, int t) { 4 | sort(begin(a),end(a)); 5 | vectorv; 6 | for(int i=0;i& a) 4 | { 5 | sort(a.begin(),a.end()); 6 | for(int i=1;i387. First Unique Character in a String

Easy


Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

2 | 3 |

 

4 |

Example 1:

5 |
Input: s = "leetcode"
 6 | Output: 0
 7 | 

Example 2:

8 |
Input: s = "loveleetcode"
 9 | Output: 2
10 | 

Example 3:

11 |
Input: s = "aabb"
12 | Output: -1
13 | 
14 |

 

15 |

Constraints:

16 | 17 |
    18 |
  • 1 <= s.length <= 105
  • 19 |
  • s consists of only lowercase English letters.
  • 20 |
21 |
-------------------------------------------------------------------------------- /first-unique-character-in-a-string/first-unique-character-in-a-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int firstUniqChar(string s) 4 | { 5 | int a[26]={0}; 6 | for(int i=0;s[i]!='\0';i++) 7 | { 8 | int p=s[i]-'a'; 9 | a[p]++; 10 | } 11 | for(int i=0;s[i]!='\0';i++) 12 | { 13 | int p=s[i]-'a'; 14 | if(a[p]==1) 15 | { 16 | return i; 17 | } 18 | } 19 | return -1; 20 | 21 | } 22 | }; -------------------------------------------------------------------------------- /generate-parentheses/README.md: -------------------------------------------------------------------------------- 1 |

22. Generate Parentheses

Medium


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

2 | 3 |

 

4 |

Example 1:

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

Example 2:

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

 

12 |

Constraints:

13 | 14 |
    15 |
  • 1 <= n <= 8
  • 16 |
17 |
-------------------------------------------------------------------------------- /generate-parentheses/generate-parentheses.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector ans; 4 | vector generateParenthesis(int n) { 5 | string cur = ""; 6 | generate(cur, 0, n); 7 | return ans; 8 | } 9 | void generate(string &cur, int open, int n) { 10 | if (n == 0) { 11 | if (open > 0) { 12 | for (int i = 0; i < open; i++) { 13 | cur += ")"; 14 | } 15 | ans.push_back(cur); 16 | } 17 | } else { 18 | // Add new parentheses 19 | string cur_new = cur + "("; 20 | generate(cur_new, open+1, n-1); 21 | 22 | // Close existed parentheses 23 | if (open > 0) { 24 | cur_new = cur + ")"; 25 | generate(cur_new, open-1, n); 26 | } 27 | } 28 | } 29 | }; -------------------------------------------------------------------------------- /how-many-numbers-are-smaller-than-the-current-number/how-many-numbers-are-smaller-than-the-current-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | //main function 4 | vector smallerNumbersThanCurrent(vector& nums) { 5 | //create a map 6 | map mp; 7 | 8 | //store the nums in map with their frequency 9 | for(auto num : nums) 10 | mp[num]++; 11 | 12 | int sum = 0; 13 | 14 | //iterate over the nums vector 15 | for(auto &num : nums){ 16 | //find the pos in map 17 | auto itr = mp.find(num); 18 | sum = 0; 19 | //sum the frequency of all the elements less than the number 20 | for(auto it = mp.begin() ; it != itr ; it++) 21 | sum += it->second; 22 | //assingn the sum to the number 23 | num = sum; 24 | } 25 | //return result 26 | return nums; 27 | } 28 | }; -------------------------------------------------------------------------------- /implement-stack-using-queues/implement-stack-using-queues.cpp: -------------------------------------------------------------------------------- 1 | class MyStack { 2 | queue stack; 3 | public: 4 | MyStack() { 5 | 6 | } 7 | 8 | void push(int x) { 9 | stack.push(x); 10 | } 11 | 12 | int pop() { 13 | int size = stack.size(); 14 | for(int i = 1; i < size; ++i){ 15 | stack.push(stack.front()); 16 | stack.pop(); 17 | } 18 | int value = stack.front(); 19 | stack.pop(); 20 | return value; 21 | } 22 | 23 | int top() { 24 | return stack.back(); 25 | } 26 | 27 | bool empty() { 28 | return stack.empty(); 29 | } 30 | }; 31 | 32 | /** 33 | * Your MyStack object will be instantiated and called as such: 34 | * MyStack* obj = new MyStack(); 35 | * obj->push(x); 36 | * int param_2 = obj->pop(); 37 | * int param_3 = obj->top(); 38 | * bool param_4 = obj->empty(); 39 | */ -------------------------------------------------------------------------------- /implement-strstr/implement-strstr.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int strStr(string h, string n) 4 | { 5 | if(h.size() 2 | #include 3 | #include 4 | int main() 5 | { 6 | int max=0, x=0, secondhighestnum =0,n=0; 7 | scanf("%d",&n); 8 | while(n>0) 9 | { 10 | x=n%10; 11 | if(x>max) 12 | { 13 | max =x; 14 | } 15 | if(x > secondhighestnum && x < max) 16 | { 17 | secondhighestnum = x; 18 | } 19 | n= n/10; 20 | } 21 | printf("%d",secondhighestnum*max); 22 | } 23 | -------------------------------------------------------------------------------- /length-of-last-word/length-of-last-word.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLastWord(string s) { 4 | int len = s.size(), ans = 0; 5 | for(int i = len - 1; i >= 0; i--) { 6 | if(s[i] != ' ') ans++; 7 | else if(s[i] == ' ' && ans) break; 8 | } 9 | return ans; 10 | } 11 | }; -------------------------------------------------------------------------------- /lighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-1658-lighterlighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-lighterlighter-data-idlgt46436807128514035-data-bundle-id0-data-slot-id0-stylebackground-color-rgb255-255-131-user-select-auto-minimum-operations-to-reduce-x-to-zero-lighter/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /longest-common-prefix/longest-common-prefix.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string longestCommonPrefix(vector& s) { 4 | string res=""; 5 | int idx; 6 | for(int i=0;ileft,p,q))x++; 17 | if(rec(root->right,p,q))x++; 18 | if(x==2)res=root; 19 | if(root->left==p||root->right==p)x++; 20 | if(root->right==q||root->left==q)x++; 21 | return x; 22 | } 23 | public: 24 | TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) { 25 | rec(root,p,q); 26 | return res; 27 | } 28 | }; -------------------------------------------------------------------------------- /maximum-depth-of-binary-tree/maximum-depth-of-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() : 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 | int maxDepth(TreeNode* root) 15 | { 16 | if(root==NULL) 17 | return 0; 18 | return 1 + max(maxDepth(root->left),maxDepth(root->right)); 19 | 20 | } 21 | }; -------------------------------------------------------------------------------- /merge-sorted-array/merge-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void merge(vector& a, int m, vector& b, int n) { 4 | int i=0,j=0,k=0; 5 | int c[200]; 6 | while(i> merge(vector>& intervals) { 4 | vector> ans; 5 | 6 | sort(begin(intervals), end(intervals)); 7 | 8 | for (auto interval : intervals) 9 | if (ans.empty() || ans.back()[1] < interval[0]) 10 | ans.push_back(interval); 11 | else 12 | ans.back()[1] = max(ans.back()[1], interval[1]); 13 | 14 | return ans; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /minimum-insertion-steps-to-make-a-string-palindrome/minimum-insertion-steps-to-make-a-string-palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minInsertions(string s) { 4 | string a=s; 5 | reverse(s.begin(),s.end()); 6 | int size=s.size(); 7 | int dp[size+1][size+1]; 8 | for(int i=0;i<=size;i++) 9 | { 10 | dp[i][0]=0; 11 | dp[0][i]=0; 12 | } 13 | for(int i=1;i<=size;i++) 14 | { 15 | for(int j=1;j<=size;j++) 16 | { 17 | if(s[i-1]==a[j-1]) 18 | { 19 | dp[i][j]=dp[i-1][j-1]+1; 20 | } 21 | else 22 | { 23 | dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 24 | } 25 | } 26 | } 27 | return size-dp[size][size]; 28 | } 29 | }; -------------------------------------------------------------------------------- /missing-number/missing-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int missingNumber(vector& nums) { 4 | int s=0; 5 | for(int i=0;i& a) 4 | { 5 | int i=0,j=0; 6 | while(j nextGreaterElement(vector& nums1, vector& nums2) { 4 | 5 | vectorout; 6 | for(int i=0;inums2[j]) 16 | { 17 | max_val=nums2[k]; 18 | break; 19 | } 20 | } 21 | out.push_back(max_val); 22 | } 23 | } 24 | } 25 | return out; 26 | 27 | } 28 | }; -------------------------------------------------------------------------------- /number-of-1-bits/number-of-1-bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int hammingWeight(uint32_t n) { 4 | int count=0; 5 | while(n>0){ 6 | if(n & 1 == 1) count++; 7 | n = n >> 1; 8 | } 9 | return count; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /palindrome-number/palindrome-number.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isPalindrome(self, x): 3 | a=str(x)[::-1] 4 | if a==str(x): 5 | 6 | return True 7 | return False 8 | -------------------------------------------------------------------------------- /perfect-number/perfect-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkPerfectNumber(int n) 4 | { 5 | int s=0; 6 | for(int i=1;i<=n/2;i++) 7 | { 8 | if(n%i==0) 9 | { //cout< plusOne(vector& d) 4 | { 5 | int n=d.size()-1; 6 | for(int i=n;i>=0;i--) 7 | { 8 | if(d[i]<9) 9 | { 10 | d[i]++; 11 | return d; 12 | } 13 | d[i]=0; 14 | } 15 | d[0]=1; 16 | d.push_back(0); 17 | return d; 18 | } 19 | }; 20 | 21 | /*class Solution { 22 | public: 23 | vector plusOne(vector& d) 24 | { int c=0; 25 | for(int i=0;iv; 31 | while(c) 32 | { 33 | v.push_back(c%10); 34 | c=c/10; 35 | } 36 | reverse(v.begin(),v.end()); 37 | return v; 38 | 39 | } 40 | };*/ -------------------------------------------------------------------------------- /power-of-three/power-of-three.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfThree(int n) 4 | { if(n==1) 5 | return true; 6 | if(n%3!=0||n==0) 7 | return false; 8 | else 9 | return isPowerOfThree(n/3); 10 | } 11 | }; -------------------------------------------------------------------------------- /power-of-two/power-of-two.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfTwo(int n) { 4 | return (n > 0 && (n & (n - 1)) == 0); 5 | } 6 | }; -------------------------------------------------------------------------------- /remove-duplicates-from-sorted-array/remove-duplicates-from-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& a) 4 | { if(a.size()==0) 5 | return 0; 6 | int i=0,j=1; 7 | while(j>= 1; 10 | } 11 | 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /reverse-integer/reverse-integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int reverse(int x) { 4 | long long int sum=0; 5 | while(x!=0) 6 | { 7 | int r=x%10; 8 | x=x/10; 9 | sum=(sum*10)+r; 10 | } 11 | if(sumINT_MAX) 12 | return 0; 13 | return sum; 14 | } 15 | }; -------------------------------------------------------------------------------- /reverse-words-in-a-string/reverse-words-in-a-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string reverseWords(string s) 4 | { 5 | string result; 6 | int i=0,n=s.length(); 7 | while(i=n) break; 11 | int j=i+1; 12 | while(jm; 6 | m['I']=1; 7 | m['V']=5; 8 | m['X']=10; 9 | m['L']=50; 10 | m['C']=100; 11 | m['D']=500; 12 | m['M']=1000; 13 | int sum=0; 14 | for(int i=0;s[i]!='\0';i++) 15 | { 16 | if(m[s[i]]>& m) 4 | { 5 | reverse(m.begin(),m.end()); 6 | for(int i=0;iA.size())return false; //if the position is greater then size 15 | 16 | return true; 17 | } 18 | }; -------------------------------------------------------------------------------- /running-sum-of-1d-array/running-sum-of-1d-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector runningSum(vector& nums) { 4 | for(int i=1;ival != val,search in left and right 9 | //otherwise this would be required node and we would return it 10 | if(valval){ 11 | //search in left 12 | node=searchBST(root->left,val); 13 | } else if(val>root->val){ 14 | //search in right 15 | node=searchBST(root->right,val); 16 | } else { 17 | //required node 18 | node=root; 19 | } 20 | return node; 21 | } 22 | }; -------------------------------------------------------------------------------- /search-insert-position/search-insert-position.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int searchInsert(vector& nums, int target) { 4 | 5 | 6 | // This question is solved using Binary Search ( log n ) 7 | 8 | // variables to store start , end and middle indices 9 | int start = 0,end = nums.size()-1; 10 | int mid; 11 | 12 | // Binary Search Logic 13 | while(start<=end){ 14 | 15 | mid = (start+end)/2; 16 | if(nums[mid]==target) 17 | return mid; 18 | else if(nums[mid]> shiftGrid(vector>& grid, int k) { 4 | const int m = grid.size(); 5 | const int n = grid[0].size(); 6 | vector> ans(m, vector(n, 0)); 7 | for (int i = 0; i < m * n; ++i) { 8 | int ori_y = i / n; 9 | int ori_x = i % n; 10 | int new_y = (ori_y + (ori_x + k) / n) % m; 11 | int new_x = (ori_x + k) % n; 12 | 13 | ans[new_y][new_x] = grid[ori_y][ori_x]; 14 | } 15 | return ans; 16 | } 17 | }; -------------------------------------------------------------------------------- /single-element-in-a-sorted-array/single-element-in-a-sorted-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNonDuplicate(vector& nums) { 4 | int x=0; 5 | for(int i=0;i& nums) { 4 | int c=0; 5 | for(int i=0;i maxSlidingWindow(vector& num, int k) { 4 | vector ans; 5 | deque dq; 6 | 7 | for(int i=0;i= k-1) 22 | { 23 | ans.push_back(num[dq.front()]); 24 | } 25 | } 26 | return ans; 27 | 28 | } 29 | }; -------------------------------------------------------------------------------- /sort 012.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void sort012(int[],int); 4 | 5 | int main() { 6 | 7 | int t; 8 | cin >> t; 9 | 10 | while(t--){ 11 | int n; 12 | cin >>n; 13 | int a[n]; 14 | for(int i=0;i> a[i]; 16 | } 17 | 18 | sort012(a, n); 19 | 20 | for(int i=0;i='0' && s[i]<='9'){ 21 | num = num*10 + (s[i] - '0'); 22 | if(num<=INT_MIN || num>=INT_MAX) break; //num overflows or underflows 23 | i++; 24 | } 25 | if(pos==false){ 26 | num = -1 * num; //negative number 27 | } 28 | if(num<=INT_MIN) return INT_MIN; 29 | else if(num >= INT_MAX) return INT_MAX; 30 | return num; 31 | } 32 | }; -------------------------------------------------------------------------------- /sum-of-two-integers/README.md: -------------------------------------------------------------------------------- 1 |

371. 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 |
-------------------------------------------------------------------------------- /sum-of-two-integers/sum-of-two-integers.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int getSum(int a, int b) 4 | { 5 | return a+b; 6 | 7 | } 8 | }; -------------------------------------------------------------------------------- /template_return_index.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | template 4 | int funu(T a[],int n) 5 | { 6 | T c,m; 7 | int i; 8 | for(i=0;ic) 11 | {c=a[i]; 12 | m=i;} 13 | } 14 | return m; 15 | } 16 | int main() 17 | { 18 | int a[100],n,i; 19 | double b[100]; 20 | cin>>n; 21 | for(i=0;i>a[i]; 24 | } 25 | for(i=0;i>b[i]; 28 | } 29 | cout<(a,n); 30 | cout<<"\n"; 31 | cout<(b,n); 32 | return 0; 33 | } 34 | /* output: 35 | 3 36 | 1 2 3 37 | 12.3 4.5 6.7 38 | sol: 39 | 2 40 | 0 41 | */ 42 | -------------------------------------------------------------------------------- /third-maximum-number/third-maximum-number.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | 4 | int thirdMax(vector& nums) 5 | { sort(nums.begin(),nums.end()); 6 | nums.erase( unique( nums.begin(),nums.end()),nums.end()); 7 | if(nums.size()<3) 8 | return nums[nums.size()-1]; 9 | else 10 | return nums[nums.size()-3]; 11 | } 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /unique-paths/unique-paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int uniquePaths(int m, int n) { 4 | int N = m + n - 2, R = m - 1; 5 | double res = 1; 6 | for (int i = 1; i <= R; i++) 7 | res = res * (N - R + i) / i; 8 | return (int)res; 9 | } 10 | }; -------------------------------------------------------------------------------- /valid-anagram/valid-anagram.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isAnagram(string s, string t) { 4 | sort(s.begin(),s.end()); 5 | sort(t.begin(),t.end()); 6 | return s==t; 7 | } 8 | }; -------------------------------------------------------------------------------- /valid-palindrome/README.md: -------------------------------------------------------------------------------- 1 |

125. Valid Palindrome

Easy


Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
Input: s = "A man, a plan, a canal: Panama"
 7 | Output: true
 8 | Explanation: "amanaplanacanalpanama" is a palindrome.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
Input: s = "race a car"
14 | Output: false
15 | Explanation: "raceacar" is not a palindrome.
16 | 
17 | 18 |

 

19 |

Constraints:

20 | 21 |
    22 |
  • 1 <= s.length <= 2 * 105
  • 23 |
  • s consists only of printable ASCII characters.
  • 24 |
25 |
-------------------------------------------------------------------------------- /valid-palindrome/valid-palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPalindrome(string s) { 4 | string n="",o=""; 5 | for(int i=0;s[i]!='\0';i++) 6 | { 7 | if(isalpha(s[i])||isalnum(s[i])) 8 | {n.push_back(tolower(s[i])); 9 | o.push_back(tolower(s[i]));} 10 | } 11 | reverse(n.begin(),n.end()); 12 | return n==o; 13 | } 14 | }; -------------------------------------------------------------------------------- /valid-parentheses/valid-parentheses.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isValid(string s) { 4 | stack stk; 5 | int l = s.length(); 6 | for(int i=0; i