├── 100-same-tree ├── NOTES.md └── 100-same-tree.cpp ├── 412-fizz-buzz ├── NOTES.md └── 412-fizz-buzz.cpp ├── 458-poor-pigs ├── NOTES.md └── 458-poor-pigs.cpp ├── 50-powx-n ├── NOTES.md └── 50-powx-n.cpp ├── 0645-set-mismatch ├── NOTES.md └── 0645-set-mismatch.cpp ├── 0835-image-overlap ├── NOTES.md └── 0835-image-overlap.cpp ├── 101-symmetric-tree └── NOTES.md ├── 136-single-number ├── NOTES.md └── 136-single-number.cpp ├── 16-3sum-closest ├── NOTES.md └── 16-3sum-closest.cpp ├── 189-rotate-array ├── NOTES.md └── 189-rotate-array.cpp ├── 190-reverse-bits ├── NOTES.md └── 190-reverse-bits.cpp ├── 202-happy-number ├── NOTES.md └── 202-happy-number.cpp ├── 231-power-of-two ├── NOTES.md └── 231-power-of-two.cpp ├── 242-valid-anagram ├── NOTES.md └── 242-valid-anagram.cpp ├── 283-move-zeroes ├── NOTES.md └── 283-move-zeroes.cpp ├── 322-coin-change ├── NOTES.md └── 322-coin-change.cpp ├── 326-power-of-three ├── NOTES.md └── 326-power-of-three.cpp ├── 342-power-of-four ├── NOTES.md └── 342-power-of-four.cpp ├── 344-reverse-string ├── NOTES.md └── 344-reverse-string.cpp ├── 383-ransom-note ├── NOTES.md └── 383-ransom-note.cpp ├── 48-rotate-image ├── NOTES.md └── 48-rotate-image.cpp ├── 494-target-sum └── NOTES.md ├── 56-merge-intervals └── NOTES.md ├── 607-sales-person ├── NOTES.md └── 607-sales-person.sql ├── 62-unique-paths ├── NOTES.md └── 62-unique-paths.cpp ├── 70-climbing-stairs ├── NOTES.md └── 70-climbing-stairs.cpp ├── 704-binary-search ├── NOTES.md └── 704-binary-search.cpp ├── 72-edit-distance └── NOTES.md ├── 733-flood-fill └── NOTES.md ├── 75-sort-colors ├── NOTES.md └── 75-sort-colors.cpp ├── 91-decode-ways └── NOTES.md ├── 948-bag-of-tokens ├── NOTES.md └── 948-bag-of-tokens.cpp ├── 0049-group-anagrams ├── NOTES.md └── 0049-group-anagrams.cpp ├── 1154-day-of-the-year ├── NOTES.md └── 1154-day-of-the-year.cpp ├── 118-pascals-triangle ├── NOTES.md └── 118-pascals-triangle.cpp ├── 1470-shuffle-the-array ├── NOTES.md └── 1470-shuffle-the-array.cpp ├── 1528-shuffle-string ├── NOTES.md └── 1528-shuffle-string.cpp ├── 169-majority-element ├── NOTES.md └── 169-majority-element.cpp ├── 1720-decode-xored-array ├── NOTES.md └── 1720-decode-xored-array.cpp ├── 175-combine-two-tables ├── NOTES.md └── 175-combine-two-tables.sql ├── 191-number-of-1-bits ├── NOTES.md └── 191-number-of-1-bits.cpp ├── 200-number-of-islands └── NOTES.md ├── 206-reverse-linked-list ├── NOTES.md └── 206-reverse-linked-list.cpp ├── 217-contains-duplicate ├── NOTES.md └── 217-contains-duplicate.cpp ├── 2235-add-two-integers ├── NOTES.md └── 2235-add-two-integers.cpp ├── 226-invert-binary-tree ├── NOTES.md └── 226-invert-binary-tree.cpp ├── 278-first-bad-version ├── NOTES.md └── 278-first-bad-version.cpp ├── 31-next-permutation └── NOTES.md ├── 336-palindrome-pairs └── NOTES.md ├── 377-combination-sum-iv ├── NOTES.md └── 377-combination-sum-iv.cpp ├── 384-shuffle-an-array ├── NOTES.md └── 384-shuffle-an-array.cpp ├── 393-utf-8-validation ├── NOTES.md └── 393-utf-8-validation.cpp ├── 42-trapping-rain-water └── NOTES.md ├── 44-wildcard-matching ├── NOTES.md └── 44-wildcard-matching.cpp ├── 474-ones-and-zeroes ├── NOTES.md └── 474-ones-and-zeroes.cpp ├── 509-fibonacci-number ├── NOTES.md └── 509-fibonacci-number.cpp ├── 53-maximum-subarray ├── NOTES.md └── 53-maximum-subarray.cpp ├── 630-course-schedule-iii ├── NOTES.md └── 630-course-schedule-iii.cpp ├── 64-minimum-path-sum └── NOTES.md ├── 695-max-area-of-island ├── NOTES.md └── 695-max-area-of-island.cpp ├── 724-find-pivot-index ├── NOTES.md └── 724-find-pivot-index.cpp ├── 73-set-matrix-zeroes └── NOTES.md ├── 74-search-a-2d-matrix └── NOTES.md ├── 771-jewels-and-stones ├── NOTES.md └── 771-jewels-and-stones.cpp ├── 867-transpose-matrix ├── NOTES.md └── 867-transpose-matrix.cpp ├── 88-merge-sorted-array ├── NOTES.md └── 88-merge-sorted-array.cpp ├── Interviewbit Questions └── .cpp ├── 0523-continuous-subarray-sum └── NOTES.md ├── 1048-longest-string-chain └── NOTES.md ├── 110-balanced-binary-tree ├── NOTES.md └── 110-balanced-binary-tree.cpp ├── 1108-defanging-an-ip-address ├── NOTES.md ├── 1108-defanging-an-ip-address.cpp └── README.md ├── 1137-n-th-tribonacci-number ├── NOTES.md └── 1137-n-th-tribonacci-number.cpp ├── 1399-count-largest-group ├── NOTES.md └── 1399-count-largest-group.cpp ├── 1480-running-sum-of-1d-array ├── NOTES.md └── 1480-running-sum-of-1d-array.cpp ├── 1512-number-of-good-pairs ├── NOTES.md └── 1512-number-of-good-pairs.cpp ├── 152-maximum-product-subarray ├── NOTES.md └── 152-maximum-product-subarray.cpp ├── 1672-richest-customer-wealth ├── NOTES.md └── 1672-richest-customer-wealth.cpp ├── 168-excel-sheet-column-title ├── NOTES.md └── 168-excel-sheet-column-title.cpp ├── 21-merge-two-sorted-lists └── NOTES.md ├── 234-palindrome-linked-list ├── NOTES.md └── 234-palindrome-linked-list.cpp ├── 240-search-a-2d-matrix-ii ├── NOTES.md └── 240-search-a-2d-matrix-ii.cpp ├── 35-search-insert-position ├── NOTES.md └── 35-search-insert-position.cpp ├── 543-diameter-of-binary-tree ├── NOTES.md └── 543-diameter-of-binary-tree.cpp ├── 567-permutation-in-string └── NOTES.md ├── 572-subtree-of-another-tree └── NOTES.md ├── 576-out-of-boundary-paths ├── NOTES.md └── 576-out-of-boundary-paths.cpp ├── 629-k-inverse-pairs-array ├── NOTES.md └── 629-k-inverse-pairs-array.cpp ├── 647-palindromic-substrings └── NOTES.md ├── 869-reordered-power-of-2 ├── NOTES.md └── 869-reordered-power-of-2.cpp ├── 92-reverse-linked-list-ii └── NOTES.md ├── Interview bit └── fast track c++ │ ├── .cpp │ ├── Type Conversion.cpp │ ├── Conditional or Ternary Expression.cpp │ ├── Custom Comparator.cpp │ ├── Loops.cpp │ ├── Jump Statements.cpp │ ├── StringStream.cpp │ ├── Hello, World!.cpp │ ├── Functions - Basic.cpp │ ├── Strings.cpp │ ├── Comparision Operation & If-Else.cpp │ ├── Templates.cpp │ ├── Pointers.cpp │ ├── Passing parameters.cpp │ ├── Polymorphism.cpp │ ├── Array.cpp │ ├── Structures.cpp │ ├── Variable and Types.cpp │ ├── Math Library.cpp │ ├── Maps.cpp │ ├── Switch statement.cpp │ ├── Set and Multiset.cpp │ ├── Cpp Exception Handling.cpp │ ├── Vector.cpp │ ├── Priority Queue.cpp │ ├── Pointers to Array.cpp │ ├── Classes and Objects.cpp │ ├── Upper & Lower bound.cpp │ └── Bitset.cpp ├── 104-maximum-depth-of-binary-tree └── NOTES.md ├── 1143-longest-common-subsequence └── NOTES.md ├── 124-binary-tree-maximum-path-sum └── NOTES.md ├── 1329-sort-the-matrix-diagonally └── NOTES.md ├── 1547-minimum-cost-to-cut-a-stick └── NOTES.md ├── 1678-goal-parser-interpretation ├── NOTES.md └── 1678-goal-parser-interpretation.cpp ├── 1693-daily-leads-and-partners ├── NOTES.md └── 1693-daily-leads-and-partners.sql ├── 171-excel-sheet-column-number ├── NOTES.md └── 171-excel-sheet-column-number.cpp ├── 1710-maximum-units-on-a-truck ├── NOTES.md └── 1710-maximum-units-on-a-truck.cpp ├── 173-binary-search-tree-iterator └── NOTES.md ├── 1795-rearrange-products-table ├── NOTES.md └── 1795-rearrange-products-table.sql ├── 1863-sum-of-all-subset-xor-totals ├── NOTES.md └── 1863-sum-of-all-subset-xor-totals.cpp ├── 199-binary-tree-right-side-view └── NOTES.md ├── 2236-root-equals-sum-of-children ├── NOTES.md └── 2236-root-equals-sum-of-children.cpp ├── 230-kth-smallest-element-in-a-bst ├── NOTES.md └── 230-kth-smallest-element-in-a-bst.cpp ├── 237-delete-node-in-a-linked-list ├── NOTES.md └── 237-delete-node-in-a-linked-list.cpp ├── 238-product-of-array-except-self └── NOTES.md ├── 287-find-the-duplicate-number └── NOTES.md ├── 295-find-median-from-data-stream └── NOTES.md ├── 4-median-of-two-sorted-arrays ├── NOTES.md └── 4-median-of-two-sorted-arrays.cpp ├── 416-partition-equal-subset-sum ├── NOTES.md └── 416-partition-equal-subset-sum.cpp ├── 470-implement-rand10-using-rand7 ├── NOTES.md └── 470-implement-rand10-using-rand7.cpp ├── 5-longest-palindromic-substring └── NOTES.md ├── 557-reverse-words-in-a-string-iii ├── NOTES.md └── 557-reverse-words-in-a-string-iii.cpp ├── 609-find-duplicate-file-in-system └── NOTES.md ├── 653-two-sum-iv-input-is-a-bst └── NOTES.md ├── 876-middle-of-the-linked-list ├── NOTES.md └── 876-middle-of-the-linked-list.cpp ├── 94-binary-tree-inorder-traversal └── NOTES.md ├── 977-squares-of-a-sorted-array └── NOTES.md ├── 98-validate-binary-search-tree ├── NOTES.md └── 98-validate-binary-search-tree.cpp ├── 102-binary-tree-level-order-traversal ├── NOTES.md └── 102-binary-tree-level-order-traversal.cpp ├── 114-flatten-binary-tree-to-linked-list ├── NOTES.md └── 114-flatten-binary-tree-to-linked-list.cpp ├── 121-best-time-to-buy-and-sell-stock ├── NOTES.md └── 121-best-time-to-buy-and-sell-stock.cpp ├── 1332-remove-palindromic-subsequences ├── NOTES.md └── 1332-remove-palindromic-subsequences.cpp ├── 1337-the-k-weakest-rows-in-a-matrix └── NOTES.md ├── 1373-maximum-sum-bst-in-binary-tree └── NOTES.md ├── 1383-maximum-performance-of-a-team └── NOTES.md ├── 144-binary-tree-preorder-traversal ├── NOTES.md └── 144-binary-tree-preorder-traversal.cpp ├── 1448-count-good-nodes-in-binary-tree ├── NOTES.md └── 1448-count-good-nodes-in-binary-tree.cpp ├── 145-binary-tree-postorder-traversal ├── NOTES.md └── 145-binary-tree-postorder-traversal.cpp ├── 167-two-sum-ii-input-array-is-sorted ├── NOTES.md └── 167-two-sum-ii-input-array-is-sorted.cpp ├── 1757-recyclable-and-low-fat-products ├── NOTES.md └── 1757-recyclable-and-low-fat-products.sql ├── 19-remove-nth-node-from-end-of-list ├── NOTES.md └── 19-remove-nth-node-from-end-of-list.cpp ├── 215-kth-largest-element-in-an-array ├── NOTES.md └── 215-kth-largest-element-in-an-array.cpp ├── 2169-count-operations-to-obtain-zero ├── NOTES.md └── 2169-count-operations-to-obtain-zero.cpp ├── 300-longest-increasing-subsequence ├── NOTES.md └── 300-longest-increasing-subsequence.cpp ├── 429-n-ary-tree-level-order-traversal └── NOTES.md ├── 442-find-all-duplicates-in-an-array ├── NOTES.md └── 442-find-all-duplicates-in-an-array.cpp ├── 700-search-in-a-binary-search-tree └── NOTES.md ├── 703-kth-largest-element-in-a-stream └── NOTES.md ├── 792-number-of-matching-subsequences └── NOTES.md ├── 852-peak-index-in-a-mountain-array └── NOTES.md ├── 871-minimum-number-of-refueling-stops ├── NOTES.md └── 871-minimum-number-of-refueling-stops.cpp ├── 1313-decompress-run-length-encoded-list ├── NOTES.md └── 1313-decompress-run-length-encoded-list.cpp ├── 1523-count-odd-numbers-in-an-interval-range ├── NOTES.md └── 1523-count-odd-numbers-in-an-interval-range.cpp ├── 1741-find-total-time-spent-by-each-employee ├── NOTES.md └── 1741-find-total-time-spent-by-each-employee.sql ├── 236-lowest-common-ancestor-of-a-binary-tree ├── NOTES.md └── 236-lowest-common-ancestor-of-a-binary-tree.cpp ├── 297-serialize-and-deserialize-binary-tree └── NOTES.md ├── 315-count-of-smaller-numbers-after-self └── NOTES.md ├── 363-max-sum-of-rectangle-no-larger-than-k ├── NOTES.md └── 363-max-sum-of-rectangle-no-larger-than-k.cpp ├── 718-maximum-length-of-repeated-subarray ├── NOTES.md └── 718-maximum-length-of-repeated-subarray.cpp ├── 103-binary-tree-zigzag-level-order-traversal └── NOTES.md ├── 1074-number-of-submatrices-that-sum-to-target └── NOTES.md ├── 108-convert-sorted-array-to-binary-search-tree └── NOTES.md ├── 116-populating-next-right-pointers-in-each-node └── NOTES.md ├── 1342-number-of-steps-to-reduce-a-number-to-zero ├── NOTES.md └── 1342-number-of-steps-to-reduce-a-number-to-zero.cpp ├── 1354-construct-target-array-with-multiple-sums ├── NOTES.md └── 1354-construct-target-array-with-multiple-sums.cpp ├── 1423-maximum-points-you-can-obtain-from-cards └── NOTES.md ├── 1662-check-if-two-string-arrays-are-equivalent ├── NOTES.md └── 1662-check-if-two-string-arrays-are-equivalent.cpp ├── 2095-delete-the-middle-node-of-a-linked-list ├── NOTES.md └── 2095-delete-the-middle-node-of-a-linked-list.cpp ├── 2114-maximum-number-of-words-found-in-sentences ├── NOTES.md └── 2114-maximum-number-of-words-found-in-sentences.cpp ├── 2259-remove-digit-from-number-to-maximize-result ├── NOTES.md └── 2259-remove-digit-from-number-to-maximize-result.cpp ├── 3-longest-substring-without-repeating-characters ├── NOTES.md └── 3-longest-substring-without-repeating-characters.cpp ├── 967-numbers-with-same-consecutive-differences └── NOTES.md ├── 1287-element-appearing-more-than-25-in-sorted-array ├── NOTES.md └── 1287-element-appearing-more-than-25-in-sorted-array.cpp ├── 235-lowest-common-ancestor-of-a-binary-search-tree ├── NOTES.md └── 235-lowest-common-ancestor-of-a-binary-search-tree.cpp ├── 1008-construct-binary-search-tree-from-preorder-traversal └── NOTES.md ├── 1293-shortest-path-in-a-grid-with-obstacles-elimination └── NOTES.md ├── 2131-longest-palindrome-by-concatenating-two-letter-words └── NOTES.md ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal └── NOTES.md ├── 106-construct-binary-tree-from-inorder-and-postorder-traversal └── NOTES.md ├── 1491-average-salary-excluding-the-minimum-and-maximum-salary ├── NOTES.md └── 1491-average-salary-excluding-the-minimum-and-maximum-salary.cpp ├── 1581-customer-who-visited-but-did-not-make-any-transactions ├── NOTES.md └── 1581-customer-who-visited-but-did-not-make-any-transactions.sql ├── 1239-maximum-length-of-a-concatenated-string-with-unique-characters ├── NOTES.md └── 1239-maximum-length-of-a-concatenated-string-with-unique-characters.cpp ├── Abdul bari Mastering Data Structures & Algorithms using C and C++ └── .cpp ├── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts ├── NOTES.md └── 1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.cpp ├── sqrtx └── sqrtx.cpp ├── power-of-two └── power-of-two.cpp ├── sum-of-two-integers ├── sum-of-two-integers.cpp └── README.md ├── valid-anagram └── valid-anagram.cpp ├── palindrome-number └── palindrome-number.py ├── Striver Sheet 180 Questions ├── Q15. Majority Element(n*0.5 times).cpp ├── Q14 pow(x,n).cpp ├── Q13.Search a 2D Matrix.cpp ├── Q17.Grid Unique Paths.cpp ├── Q17. Grid unique paths.cpp ├── Q30. Delete Node in a Linked List.cpp ├── Q8. pascals_triangle.cpp ├── Q42.Max Consecutive Ones cpp ├── Q24.Longest substring without repeat.cpp ├── Q43. N meetings in one room .cpp ├── Q47 Subset sum1.cpp ├── Q22.Largest Subarray with 0 sum.cpp ├── Q15.Majority Element (>N2 times).cpp ├── Q32. Intersection point of two Linked Lists.cpp ├── Q44. minimum no of platform required in a railway .cpp ├── Q26. Middle of the Linked List.cpp ├── Q33 Linked List Cycle.cpp ├── Q14.Pow(X,n).cpp ├── Q13. Search in a 2D matrix.cpp ├── Q52 K-th Permutation Sequence .cpp ├── Q1. SOrt colors.cpp ├── Q46. Fractional Knapsack .cpp ├── Q45 Job Sequencing Problem .cpp ├── Q21.longestConsecutiveSequence.cpp ├── Q39. 3Sum.cpp └── Q29. Remove Nth Node From End of Linked List.cpp ├── running-sum-of-1d-array └── running-sum-of-1d-array.cpp ├── unique-paths └── unique-paths.cpp ├── single-number └── single-number.cpp ├── divide-two-integers └── divide-two-integers.cpp ├── number-of-1-bits └── number-of-1-bits.cpp ├── power-of-three └── power-of-three.cpp ├── fibonacci-number └── fibonacci-number.cpp ├── single-element-in-a-sorted-array └── single-element-in-a-sorted-array.cpp ├── missing-number └── missing-number.cpp ├── find-target-indices-after-sorting-array └── find-target-indices-after-sorting-array.cpp ├── Mirror Tree.cpp ├── concatenation-of-array └── concatenation-of-array.cpp ├── reverse-bits └── reverse-bits.cpp ├── length-of-last-word └── length-of-last-word.cpp ├── contains-duplicate └── contains-duplicate.cpp ├── third-maximum-number └── third-maximum-number.cpp ├── find-the-duplicate-number └── find-the-duplicate-number.cpp ├── reverse-integer └── reverse-integer.cpp ├── rotate-image └── rotate-image.cpp ├── Kth largest element in BST .cpp ├── largest and second largest digit in a num.c ├── 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 ├── valid-palindrome ├── valid-palindrome.cpp └── README.md ├── perfect-number └── perfect-number.cpp ├── first-bad-version └── first-bad-version.cpp ├── Striver Sheet 180 QuestionQ16. Unique Paths.cpp ├── move-zeroes └── move-zeroes.cpp ├── n-th-tribonacci-number └── n-th-tribonacci-number.cpp ├── merge_intervals.cpp ├── final-value-of-variable-after-performing-operations └── final-value-of-variable-after-performing-operations.cpp ├── remove-duplicates-from-sorted-array └── remove-duplicates-from-sorted-array.cpp ├── longest-common-prefix └── longest-common-prefix.cpp ├── Remainder on dividing by 11 - GFG └── remainder-on-dividing-by-11.py ├── rotate-string └── rotate-string.cpp ├── first-unique-character-in-a-string ├── first-unique-character-in-a-string.cpp └── README.md ├── binary-search └── binary-search.cpp ├── Matchsticks game - GFG └── matchsticks-game.cpp ├── climbing-stairs └── climbing-stairs.cpp ├── counting-bits └── counting-bits.cpp ├── Number of 1 Bits - GFG └── number-of-1-bits.cpp ├── Reverse Coding - GFG └── reverse-coding.cpp ├── roman-to-integer └── roman-to-integer.cpp ├── diagonal-traverse-ii └── diagonal-traverse-ii.cpp ├── Reverse The String.cpp ├── container-with-most-water └── container-with-most-water.cpp ├── shift-2d-grid └── shift-2d-grid.cpp ├── Decimal to binary - GFG └── decimal-to-binary.c ├── sort 012.cpp ├── reverse-words-in-a-string └── reverse-words-in-a-string.cpp ├── A. Petya and Strings.cpp ├── generate-parentheses ├── README.md └── generate-parentheses.cpp ├── maximum-depth-of-binary-tree └── maximum-depth-of-binary-tree.cpp ├── difference of index of largest digit and smallest digit.c ├── merge-sorted-array └── merge-sorted-array.cpp ├── Minimum Steps Required - GFG └── minimum-steps-required.cpp ├── count-and-say └── count-and-say.cpp ├── Break a number - GFG └── break-a-number.cpp ├── Middle of Three .cpp ├── implement-strstr └── implement-strstr.cpp ├── Make Array Elements Equal - GFG └── make-array-elements-equal.cpp ├── Arithmetic Number - GFG └── arithmetic-number.cpp ├── search-insert-position └── search-insert-position.cpp ├── string-to-integer-atoi └── string-to-integer-atoi.cpp ├── template_return_index.cpp ├── Binary Modulo - GFG └── binary-modulo.cpp ├── Copy Set Bits in Range - GFG └── copy-set-bits-in-range.cpp ├── Last modified ball - GFG └── last-modified-ball.cpp ├── valid-parentheses └── valid-parentheses.cpp ├── search-in-a-binary-search-tree └── search-in-a-binary-search-tree.cpp ├── Q9. next_permutation.cpp ├── Type it! - GFG └── type-it.cpp ├── sliding-window-maximum └── sliding-window-maximum.cpp ├── Nth Fibonacci Number - GFG └── nth-fibonacci-number.cpp ├── plus-one └── plus-one.cpp ├── 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 ├── Is Binary Number Multiple of 3 - GFG └── is-binary-number-multiple-of-3.cpp ├── Adding Ones - GFG └── adding-ones.cpp ├── binary-tree-preorder-traversal └── binary-tree-preorder-traversal.cpp ├── minimum-insertion-steps-to-make-a-string-palindrome └── minimum-insertion-steps-to-make-a-string-palindrome.cpp ├── 3sum └── 3sum.cpp ├── Cutting Rectangles - GFG └── cutting-rectangles.cpp ├── next-greater-element-i └── next-greater-element-i.cpp ├── binary-tree-inorder-traversal └── binary-tree-inorder-traversal.cpp ├── lowest-common-ancestor-of-a-binary-tree └── lowest-common-ancestor-of-a-binary-tree.cpp ├── binary-tree-level-order-traversal └── binary-tree-level-order-traversal.cpp ├── how-many-numbers-are-smaller-than-the-current-number └── how-many-numbers-are-smaller-than-the-current-number.cpp ├── Geeks And The String - GFG └── geeks-and-the-string.cpp ├── Find Number - GFG └── find-number.cpp ├── Nth catalan number - GFG └── nth-catalan-number.cpp ├── Q49 Combination Sum.cpp ├── combination-sum └── combination-sum.cpp └── implement-stack-using-queues └── implement-stack-using-queues.cpp /100-same-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /412-fizz-buzz/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /458-poor-pigs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /50-powx-n/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0645-set-mismatch/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0835-image-overlap/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /101-symmetric-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /136-single-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /16-3sum-closest/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /189-rotate-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /190-reverse-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /202-happy-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /231-power-of-two/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /242-valid-anagram/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /283-move-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /322-coin-change/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /326-power-of-three/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /342-power-of-four/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /344-reverse-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /383-ransom-note/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /48-rotate-image/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /494-target-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /56-merge-intervals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /607-sales-person/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /62-unique-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /70-climbing-stairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /704-binary-search/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /72-edit-distance/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /733-flood-fill/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /75-sort-colors/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /91-decode-ways/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /948-bag-of-tokens/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /0049-group-anagrams/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1154-day-of-the-year/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /118-pascals-triangle/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1470-shuffle-the-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1528-shuffle-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /169-majority-element/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1720-decode-xored-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /175-combine-two-tables/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /191-number-of-1-bits/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /200-number-of-islands/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /206-reverse-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /217-contains-duplicate/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2235-add-two-integers/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /226-invert-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /278-first-bad-version/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /31-next-permutation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /336-palindrome-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /377-combination-sum-iv/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /384-shuffle-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /393-utf-8-validation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /42-trapping-rain-water/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /44-wildcard-matching/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /474-ones-and-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /509-fibonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /53-maximum-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /630-course-schedule-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /64-minimum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /695-max-area-of-island/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /724-find-pivot-index/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /73-set-matrix-zeroes/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /74-search-a-2d-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /771-jewels-and-stones/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /867-transpose-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /88-merge-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /Interviewbit Questions/.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /0523-continuous-subarray-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1048-longest-string-chain/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /110-balanced-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1108-defanging-an-ip-address/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1137-n-th-tribonacci-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1399-count-largest-group/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1480-running-sum-of-1d-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1512-number-of-good-pairs/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /152-maximum-product-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1672-richest-customer-wealth/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /168-excel-sheet-column-title/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /21-merge-two-sorted-lists/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /234-palindrome-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /240-search-a-2d-matrix-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /35-search-insert-position/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /543-diameter-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /567-permutation-in-string/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /572-subtree-of-another-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /576-out-of-boundary-paths/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /629-k-inverse-pairs-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /647-palindromic-substrings/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /869-reordered-power-of-2/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /92-reverse-linked-list-ii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /Interview bit/fast track c++/.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /104-maximum-depth-of-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1143-longest-common-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /124-binary-tree-maximum-path-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1329-sort-the-matrix-diagonally/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1547-minimum-cost-to-cut-a-stick/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1678-goal-parser-interpretation/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1693-daily-leads-and-partners/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /171-excel-sheet-column-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /173-binary-search-tree-iterator/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1795-rearrange-products-table/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1863-sum-of-all-subset-xor-totals/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /199-binary-tree-right-side-view/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2236-root-equals-sum-of-children/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /230-kth-smallest-element-in-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /237-delete-node-in-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /238-product-of-array-except-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /287-find-the-duplicate-number/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /295-find-median-from-data-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /4-median-of-two-sorted-arrays/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /416-partition-equal-subset-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /470-implement-rand10-using-rand7/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /5-longest-palindromic-substring/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /557-reverse-words-in-a-string-iii/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /609-find-duplicate-file-in-system/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /653-two-sum-iv-input-is-a-bst/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /876-middle-of-the-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /94-binary-tree-inorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /977-squares-of-a-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /98-validate-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /102-binary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /114-flatten-binary-tree-to-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1332-remove-palindromic-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1337-the-k-weakest-rows-in-a-matrix/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1373-maximum-sum-bst-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1383-maximum-performance-of-a-team/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /144-binary-tree-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1448-count-good-nodes-in-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /145-binary-tree-postorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /167-two-sum-ii-input-array-is-sorted/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1757-recyclable-and-low-fat-products/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /19-remove-nth-node-from-end-of-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /215-kth-largest-element-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2169-count-operations-to-obtain-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /429-n-ary-tree-level-order-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /700-search-in-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /703-kth-largest-element-in-a-stream/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /792-number-of-matching-subsequences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /852-peak-index-in-a-mountain-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /871-minimum-number-of-refueling-stops/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1313-decompress-run-length-encoded-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1523-count-odd-numbers-in-an-interval-range/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1741-find-total-time-spent-by-each-employee/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /236-lowest-common-ancestor-of-a-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /297-serialize-and-deserialize-binary-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /315-count-of-smaller-numbers-after-self/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /363-max-sum-of-rectangle-no-larger-than-k/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /718-maximum-length-of-repeated-subarray/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /103-binary-tree-zigzag-level-order-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 | ​ -------------------------------------------------------------------------------- /116-populating-next-right-pointers-in-each-node/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1342-number-of-steps-to-reduce-a-number-to-zero/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1354-construct-target-array-with-multiple-sums/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1423-maximum-points-you-can-obtain-from-cards/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1662-check-if-two-string-arrays-are-equivalent/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2095-delete-the-middle-node-of-a-linked-list/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2114-maximum-number-of-words-found-in-sentences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2259-remove-digit-from-number-to-maximize-result/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /3-longest-substring-without-repeating-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /967-numbers-with-same-consecutive-differences/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1287-element-appearing-more-than-25-in-sorted-array/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /235-lowest-common-ancestor-of-a-binary-search-tree/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1008-construct-binary-search-tree-from-preorder-traversal/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1293-shortest-path-in-a-grid-with-obstacles-elimination/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /2131-longest-palindrome-by-concatenating-two-letter-words/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 | ​ -------------------------------------------------------------------------------- /1491-average-salary-excluding-the-minimum-and-maximum-salary/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1581-customer-who-visited-but-did-not-make-any-transactions/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /1239-maximum-length-of-a-concatenated-string-with-unique-characters/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /Abdul bari Mastering Data Structures & Algorithms using C and C++/.cpp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /1465-maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /sqrtx/sqrtx.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mySqrt(int x) { 4 | return sqrt(x); 5 | } 6 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /1757-recyclable-and-low-fat-products/1757-recyclable-and-low-fat-products.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT PRODUCT_ID FROM PRODUCTS WHERE LOW_FATS ='Y'AND RECYCLABLE='Y'; 3 | -------------------------------------------------------------------------------- /175-combine-two-tables/175-combine-two-tables.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | select firstName,lastName,city,state from Person 3 | Left Join Address 4 | on Person.personId=Address.personId; 5 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /1741-find-total-time-spent-by-each-employee/1741-find-total-time-spent-by-each-employee.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | event_day AS day, 3 | emp_id, 4 | SUM(out_time - in_time) AS total_time 5 | FROM Employees 6 | GROUP BY 1, 2 -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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;i& nums) { 4 | int c=0; 5 | for(int i=0;i& n) { 4 | sets(n.begin(),n.end()); 5 | //for(auto x:n) 6 | // s.insert(x); 7 | return s.size()!=n.size(); 8 | } 9 | }; -------------------------------------------------------------------------------- /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 decode(vector& a, int f) { 4 | a.insert(a.begin(),f); 5 | for(int i=0;i j(J.begin(), J.end()); 5 | return count_if(S.begin(), S.end(), [&j] (const char& c) { return j.count(c) == 1; }); 6 | } 7 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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;ia,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 | -------------------------------------------------------------------------------- /1693-daily-leads-and-partners/1693-daily-leads-and-partners.sql: -------------------------------------------------------------------------------- 1 | SELECT date_id, 2 | make_name, 3 | COUNT(DISTINCT lead_id) as unique_leads, 4 | COUNT( DISTINCT partner_id) AS unique_partners 5 | FROM DailySales 6 | GROUP BY date_id, make_name 7 | ORDER BY make_name DESC, date_id DESC -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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) { 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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Loops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() { 5 | int N; 6 | cin>>N; 7 | for(int i=0;i& nums) { 4 | int x=0; 5 | for(int i=0;i0){ 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 | }; -------------------------------------------------------------------------------- /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& 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 | }; -------------------------------------------------------------------------------- /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 targetIndices(vector& a, int t) { 4 | sort(begin(a),end(a)); 5 | vectorv; 6 | for(int i=0;ileft); 8 | mirror(root->right); 9 | swap(root->left,root->right); 10 | 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /50-powx-n/50-powx-n.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double myPow(double x, int n) { 4 | double res = 1; 5 | while (n) { 6 | if (n % 2) 7 | res = n > 0 ? res * x : res / x; 8 | x = x * x; 9 | n /= 2; 10 | } 11 | return res; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /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<>& mat, int t) { 4 | int i,j; 5 | for(i=0;i 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /reverse-bits/reverse-bits.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | uint32_t reverseBits(uint32_t n) { 4 | uint32_t res = 0; 5 | for(int i = 0; i < 32; ++i) 6 | { 7 | res <<= 1; 8 | res |= (n & 1); 9 | n >>= 1; 10 | } 11 | 12 | return res; 13 | } 14 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Hello, World!.cpp: -------------------------------------------------------------------------------- 1 | #include 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 | -------------------------------------------------------------------------------- /contains-duplicate/contains-duplicate.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool containsDuplicate(vector& nums) { 4 | sort(nums.begin(),nums.end()); 5 | for(int i=0;i& 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 | -------------------------------------------------------------------------------- /1795-rearrange-products-table/1795-rearrange-products-table.sql: -------------------------------------------------------------------------------- 1 | select product_id, 'store1' as store, store1 as price from products where store1 is not null 2 | union all 3 | select product_id, 'store2' as store, store2 as price from products where store2 is not null 4 | union all 5 | select product_id, 'store3' as store, store3 as price from products where store3 is not null -------------------------------------------------------------------------------- /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<& 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 -------------------------------------------------------------------------------- /Interview bit/fast track c++/Strings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | #include 4 | using namespace std; 5 | */ 6 | 7 | int main() { 8 | string A, B; 9 | cin>>A>>B; 10 | cout<& a) 4 | { 5 | sort(a.begin(),a.end()); 6 | for(int i=1;iINT_MAX) 12 | return 0; 13 | return sum; 14 | } 15 | }; -------------------------------------------------------------------------------- /rotate-image/rotate-image.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void rotate(vector>& m) 4 | { 5 | reverse(m.begin(),m.end()); 6 | for(int i=0;i& a) 4 | { 5 | int i=0,j=0; 6 | while(j& 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 | }; -------------------------------------------------------------------------------- /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> dp(m, vector (n,1)); 5 | for (int i=1; i 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 | }; -------------------------------------------------------------------------------- /1512-number-of-good-pairs/1512-number-of-good-pairs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numIdenticalPairs(vector& 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 | }; -------------------------------------------------------------------------------- /300-longest-increasing-subsequence/300-longest-increasing-subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLIS(vector& 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 | }; -------------------------------------------------------------------------------- /35-search-insert-position/35-search-insert-position.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int searchInsert(vector& 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]& 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 | }; -------------------------------------------------------------------------------- /629-k-inverse-pairs-array/629-k-inverse-pairs-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int kInversePairs(int n, int k) { 4 | int dp[1001][1001] = { 1 }; 5 | for (int N = 1; N <= n; ++N) 6 | for (int K = 0; K <= k; ++K) 7 | for (int i = 0; i <= min(K, N - 1); ++i) 8 | dp[N][K] = (dp[N][K] + dp[N - 1][K - i]) % 1000000007; 9 | return dp[n][k]; 10 | } 11 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Comparision Operation & If-Else.cpp: -------------------------------------------------------------------------------- 1 | #include 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++/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /largest and second largest digit in a num.c: -------------------------------------------------------------------------------- 1 | #include 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 | -------------------------------------------------------------------------------- /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 | ​ -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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<= 40) { 10 | rand40 = (rand7() - 1) * 7 + rand7() - 1; 11 | } 12 | return rand40 % 10 + 1; 13 | } 14 | }; -------------------------------------------------------------------------------- /first-bad-version/first-bad-version.cpp: -------------------------------------------------------------------------------- 1 | // The API isBadVersion is defined for you. 2 | // bool isBadVersion(int version); 3 | class Solution { 4 | public: 5 | int firstBadVersion(int n) { 6 | int lo = 1, hi = n, mid; 7 | while (lo < hi) { 8 | mid = lo + (hi - lo) / 2; 9 | if (isBadVersion(mid)) hi = mid; 10 | else lo = mid+1; 11 | } 12 | return lo; 13 | } 14 | }; -------------------------------------------------------------------------------- /121-best-time-to-buy-and-sell-stock/121-best-time-to-buy-and-sell-stock.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& arr) 4 | { 5 | int profit= 0; 6 | int minEl= INT_MAX; 7 | int n= arr.size(); 8 | 9 | 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<> 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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /move-zeroes/move-zeroes.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void moveZeroes(vector& a) 4 | { 5 | int i=0,j=0; 6 | while(j& x, vector& y) 4 | { 5 | string a="",b=""; 6 | for(int i=0;i& 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 | }; -------------------------------------------------------------------------------- /458-poor-pigs/458-poor-pigs.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int poorPigs(int buckets, int minutesToDie, int minutesToTest) { 4 | // min_pig_count determined by equation: buckets =max_sub_job_load ** min_pig_count 5 | // max_sub_job_load = minutesToTest / minutesToDie + 1 6 | // min_pig_count = ceil(log(buckets) / log(minutesToTest / minutesToDie + 1)); 7 | return ceil(log(buckets) / log(minutesToTest / minutesToDie + 1)); 8 | } 9 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Passing parameters.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 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<> 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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q8. pascals_triangle.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> 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 | -------------------------------------------------------------------------------- /Interview bit/fast track c++/Polymorphism.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 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<&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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /384-shuffle-an-array/384-shuffle-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | vector 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 | }; -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q24.Longest substring without repeat.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLongestSubstring(string s) 4 | { 5 | vectord(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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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& operations) { 4 | int x=0; 5 | for(int i=0;ib) 9 | { 10 | a=a-b; 11 | c++; 12 | } 13 | else 14 | { 15 | b-=a; 16 | c++; 17 | } 18 | } 19 | return c; 20 | 21 | } 22 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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& 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 | }; -------------------------------------------------------------------------------- /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;i& s) { 4 | string res=""; 5 | int idx; 6 | for(int i=0;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<> 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 | }; -------------------------------------------------------------------------------- /442-find-all-duplicates-in-an-array/442-find-all-duplicates-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector findDuplicates(vector& n) { 4 | vectorv; 5 | for(int i=0;i& s) { 4 | int c=0,m=0; 5 | for(int i=0;i=m) 14 | m=c; 15 | } 16 | return m+1; 17 | } 18 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /rotate-string/rotate-string.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool rotateString(string A, string B) { 4 | if(A==B)return true; // if already same 5 | 6 | 7 | if(A.size()!=B.size())return false; //if size aren't equal 8 | 9 | 10 | A=A+A; //will have all the possible rotation now 11 | 12 | int check=A.find(B); //will find the B substring 13 | 14 | if(check>A.size())return false; //if the position is greater then size 15 | 16 | return true; 17 | } 18 | }; -------------------------------------------------------------------------------- /168-excel-sheet-column-title/168-excel-sheet-column-title.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string convertToTitle(int c) { 4 | string s; 5 | if(c==1) 6 | return "A"; 7 | while(c>0) 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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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;i& 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 | }; -------------------------------------------------------------------------------- /3-longest-substring-without-repeating-characters/3-longest-substring-without-repeating-characters.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLongestSubstring(string s) { 4 | unordered_setv; 5 | int i=0,j=0,a=0; 6 | int n=s.size(); 7 | while(i 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 | 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 | #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< &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 | -------------------------------------------------------------------------------- /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] 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 -------------------------------------------------------------------------------- /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 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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Math Library.cpp: -------------------------------------------------------------------------------- 1 | #include 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<mmp; 4 | int maxi=0; 5 | int sum=0; 6 | for(int i=0;i& 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]& 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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Maps.cpp: -------------------------------------------------------------------------------- 1 | #include 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< 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 -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /roman-to-integer/roman-to-integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int romanToInt(string s) 4 | { 5 | mapm; 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]] 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 | }; -------------------------------------------------------------------------------- /167-two-sum-ii-input-array-is-sorted/167-two-sum-ii-input-array-is-sorted.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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> 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Decimal to binary - GFG/decimal-to-binary.c: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | //Initial Template for C 3 | 4 | 5 | #include 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 -------------------------------------------------------------------------------- /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() 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 | }; -------------------------------------------------------------------------------- /869-reordered-power-of-2/869-reordered-power-of-2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool reorderedPowerOf2(int n) { 4 | string s = to_string(n); 5 | sort(s.begin(),s.end()); 6 | 7 | vector 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 | }; -------------------------------------------------------------------------------- /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=n) break; 11 | int j=i+1; 12 | while(j 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]& 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 | }; -------------------------------------------------------------------------------- /630-course-schedule-iii/630-course-schedule-iii.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int scheduleCourse(vector>& 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 | }; -------------------------------------------------------------------------------- /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 |
-------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Switch statement.cpp: -------------------------------------------------------------------------------- 1 | #include 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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; inext : headB; 15 | temp2 = temp2!=NULL ? temp2->next : headA; 16 | } 17 | 18 | return temp1; 19 | 20 | 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 |
-------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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++/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<d[j]) 16 | { 17 | p--; 18 | j++; 19 | } 20 | if(p>r) 21 | { 22 | r=p; 23 | } 24 | } 25 | return r; 26 | } 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Vector.cpp: -------------------------------------------------------------------------------- 1 | #include 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& a, int m, vector& b, int n) { 4 | int i=0,j=0,k=0; 5 | int c[200]; 6 | while(i 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 -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Priority Queue.cpp: -------------------------------------------------------------------------------- 1 | int solve(vector &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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /count-and-say/count-and-say.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string countAndSay(int nt) { 4 | string s="1"; 5 | for(int start=1;start 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 -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | // } 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 -------------------------------------------------------------------------------- /Interview bit/fast track c++/Pointers to Array.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 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 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 | -------------------------------------------------------------------------------- /4-median-of-two-sorted-arrays/4-median-of-two-sorted-arrays.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double findMedianSortedArrays(vector& 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 | }; -------------------------------------------------------------------------------- /Arithmetic Number - GFG/arithmetic-number.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 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<>& 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 | -------------------------------------------------------------------------------- /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]='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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Binary Modulo - GFG/binary-modulo.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 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<val!=q->val) 20 | return false; 21 | return isSameTree(p->left,q->left)&& isSameTree(p->right,q->right); 22 | } 23 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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<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 -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /718-maximum-length-of-repeated-subarray/718-maximum-length-of-repeated-subarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findLength(vector& 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 | }; -------------------------------------------------------------------------------- /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 stk; 5 | int l = s.length(); 6 | for(int i=0; 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 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 -------------------------------------------------------------------------------- /sliding-window-maximum/sliding-window-maximum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /1863-sum-of-all-subset-xor-totals/1863-sum-of-all-subset-xor-totals.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int subsetXORSum(vector& 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 | }; -------------------------------------------------------------------------------- /363-max-sum-of-rectangle-no-larger-than-k/363-max-sum-of-rectangle-no-larger-than-k.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSumSubmatrix(vector>& 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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Classes and Objects.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 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< 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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 |
-------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /plus-one/plus-one.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector 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 | };*/ -------------------------------------------------------------------------------- /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 | // }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | ​ -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Is Binary Number Multiple of 3 - GFG/is-binary-number-multiple-of-3.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | 3 | #include 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 -------------------------------------------------------------------------------- /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< 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<ans; 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 | }; -------------------------------------------------------------------------------- /Interview bit/fast track c++/Bitset.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | #include 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<left); 26 | int r=height(root->right); 27 | if(abs(l-r)>1) f=false; 28 | return (max(l,r)+1); 29 | } 30 | }; -------------------------------------------------------------------------------- /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 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< 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /first-unique-character-in-a-string/README.md: -------------------------------------------------------------------------------- 1 |

387. 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 |
-------------------------------------------------------------------------------- /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 | /* 0v; 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 | }; -------------------------------------------------------------------------------- /lowest-common-ancestor-of-a-binary-tree/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 | TreeNode* res; 12 | int rec(TreeNode* root,TreeNode* p,TreeNode* q){ 13 | if(!root)return 0; 14 | int x=0; 15 | if(root==p||root==q)x++; 16 | if(rec(root->left,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 | }; -------------------------------------------------------------------------------- /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 left); 26 | int r=diameter(root->right); 27 | ans = max(ans,l+r); 28 | return max(l,r)+1; 29 | } 30 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /Striver Sheet 180 Questions/Q21.longestConsecutiveSequence.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | My approach!! 4 | ------------ 5 | */ 6 | class Solution { 7 | public: 8 | int longestConsecutive(vector& 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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /576-out-of-boundary-paths/576-out-of-boundary-paths.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int solve(int &m,int &n,int cr,int cc,int moves,vector>>& 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 | }; -------------------------------------------------------------------------------- /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 |
-------------------------------------------------------------------------------- /Geeks And The String - GFG/geeks-and-the-string.cpp: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | #include 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<> 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> 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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | // } 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 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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 | }; -------------------------------------------------------------------------------- /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;inext=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 | -------------------------------------------------------------------------------- /combination-sum/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 | }; -------------------------------------------------------------------------------- /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 | */ -------------------------------------------------------------------------------- /1710-maximum-units-on-a-truck/1710-maximum-units-on-a-truck.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | static bool myfunction(vector& a, vector& b){ 4 | return a[1] > b[1]; 5 | } 6 | int maximumUnits(vector>& boxTypes, int truckSize) { 7 | //custom sort (in increasing order of numberOfUnitsPerBox as we have to return maximum total number of units ) 8 | sort(boxTypes.begin(),boxTypes.end(),myfunction); 9 | //greedily pick boxes till capacity is full 10 | int ans=0; 11 | for(auto box: boxTypes){ 12 | int x=min(box[0],truckSize); //choose minimum boxes from available boxes and capacity left 13 | ans+=(x*box[1]); //adding units in ans 14 | truckSize-=x; //reduce the capacity 15 | if(!truckSize) break; //capacity full 16 | } 17 | return ans; 18 | } 19 | }; 20 | //3+2+2+1=8 21 | //10+10+10+10+10+9+9+9+7+7 22 | --------------------------------------------------------------------------------