Git Product home page Git Product logo

dsa-practice's Introduction

Data Structures and Algorithms Practice

This repository contains solutions to various data structures and algorithms practice questions from LeetCode and GeeksforGeeks. Each problem is solved in C++, and the solutions are organized for each questions separately.

Contributing

Acknowledgments

Two Pointers

0026-remove-duplicates-from-sorted-array
0027-remove-element
0061-rotate-list
0075-sort-colors
0088-merge-sorted-array
0125-valid-palindrome
0148-sort-list
0344-reverse-string
0633-sum-of-square-numbers
0853-most-profit-assigning-work
2392-successful-pairs-of-spells-and-potions
2497-maximum-matching-of-players-with-trainers
2572-append-characters-to-string-to-make-subsequence

String

0012-integer-to-roman
0014-longest-common-prefix
0020-valid-parentheses
0067-add-binary
0125-valid-palindrome
0171-excel-sheet-column-number
0344-reverse-string
0409-longest-palindrome
0648-replace-words
1044-find-common-characters
2572-append-characters-to-string-to-make-subsequence

Trie

0014-longest-common-prefix
0648-replace-words

Greedy

0330-patching-array
0409-longest-palindrome
0502-ipo
0561-array-partition
0853-most-profit-assigning-work
0876-hand-of-straights
0982-minimum-increment-to-make-array-unique
1285-balance-a-binary-search-tree
1422-divide-array-in-sets-of-k-consecutive-numbers
2148-minimum-number-of-moves-to-seat-everyone
2497-maximum-matching-of-players-with-trainers
2572-append-characters-to-string-to-make-subsequence

Hash Table

0012-integer-to-roman
0409-longest-palindrome
0523-continuous-subarray-sum
0648-replace-words
0876-hand-of-straights
1016-subarray-sums-divisible-by-k
1044-find-common-characters
1217-relative-sort-array
1370-count-number-of-nice-subarrays
1422-divide-array-in-sets-of-k-consecutive-numbers

Array

0026-remove-duplicates-from-sorted-array
0027-remove-element
0035-search-insert-position
0075-sort-colors
0088-merge-sorted-array
0108-convert-sorted-array-to-binary-search-tree
0330-patching-array
0502-ipo
0523-continuous-subarray-sum
0561-array-partition
0648-replace-words
0853-most-profit-assigning-work
0876-hand-of-straights
0948-sort-an-array
0982-minimum-increment-to-make-array-unique
1016-subarray-sums-divisible-by-k
1037-minimum-number-of-k-consecutive-bit-flips
1044-find-common-characters
1137-height-checker
1138-grumpy-bookstore-owner
1217-relative-sort-array
1370-count-number-of-nice-subarrays
1422-divide-array-in-sets-of-k-consecutive-numbers
1549-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit
1605-minimum-number-of-days-to-make-m-bouquets
1675-magnetic-force-between-two-balls
2148-minimum-number-of-moves-to-seat-everyone
2392-successful-pairs-of-spells-and-potions
2497-maximum-matching-of-players-with-trainers

Binary Search

0035-search-insert-position
0633-sum-of-square-numbers
0853-most-profit-assigning-work
1605-minimum-number-of-days-to-make-m-bouquets
1675-magnetic-force-between-two-balls
2392-successful-pairs-of-spells-and-potions

Sorting

0075-sort-colors
0088-merge-sorted-array
0148-sort-list
0502-ipo
0561-array-partition
0853-most-profit-assigning-work
0876-hand-of-straights
0948-sort-an-array
0982-minimum-increment-to-make-array-unique
1137-height-checker
1217-relative-sort-array
1422-divide-array-in-sets-of-k-consecutive-numbers
1675-magnetic-force-between-two-balls
2148-minimum-number-of-moves-to-seat-everyone
2392-successful-pairs-of-spells-and-potions
2497-maximum-matching-of-players-with-trainers

Linked List

0061-rotate-list
0083-remove-duplicates-from-sorted-list
0148-sort-list

Math

0012-integer-to-roman
0067-add-binary
0171-excel-sheet-column-number
0523-continuous-subarray-sum
0633-sum-of-square-numbers
1370-count-number-of-nice-subarrays

Prefix Sum

0523-continuous-subarray-sum
1016-subarray-sums-divisible-by-k
1037-minimum-number-of-k-consecutive-bit-flips

Counting Sort

0561-array-partition
0948-sort-an-array
0982-minimum-increment-to-make-array-unique
1137-height-checker
1217-relative-sort-array

Divide and Conquer

0108-convert-sorted-array-to-binary-search-tree
0148-sort-list
0948-sort-an-array
1285-balance-a-binary-search-tree

Heap (Priority Queue)

0502-ipo
0948-sort-an-array
1549-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit

Merge Sort

0148-sort-list
0948-sort-an-array

Bucket Sort

0948-sort-an-array

Radix Sort

0948-sort-an-array

Stack

0020-valid-parentheses
0094-binary-tree-inorder-traversal

Bit Manipulation

0067-add-binary
1037-minimum-number-of-k-consecutive-bit-flips

Simulation

0067-add-binary

Tree

0094-binary-tree-inorder-traversal
0100-same-tree
0104-maximum-depth-of-binary-tree
0108-convert-sorted-array-to-binary-search-tree
0111-minimum-depth-of-binary-tree
0112-path-sum
0538-convert-bst-to-greater-tree
1114-binary-search-tree-to-greater-sum-tree
1285-balance-a-binary-search-tree

Depth-First Search

0094-binary-tree-inorder-traversal
0100-same-tree
0104-maximum-depth-of-binary-tree
0111-minimum-depth-of-binary-tree
0112-path-sum
0538-convert-bst-to-greater-tree
1114-binary-search-tree-to-greater-sum-tree
1285-balance-a-binary-search-tree

Breadth-First Search

0100-same-tree
0104-maximum-depth-of-binary-tree
0111-minimum-depth-of-binary-tree
0112-path-sum

Binary Tree

0094-binary-tree-inorder-traversal
0100-same-tree
0104-maximum-depth-of-binary-tree
0108-convert-sorted-array-to-binary-search-tree
0111-minimum-depth-of-binary-tree
0112-path-sum
0538-convert-bst-to-greater-tree
1114-binary-search-tree-to-greater-sum-tree
1285-balance-a-binary-search-tree

Sliding Window

1037-minimum-number-of-k-consecutive-bit-flips
1138-grumpy-bookstore-owner
1370-count-number-of-nice-subarrays
1549-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit

Queue

1037-minimum-number-of-k-consecutive-bit-flips
1549-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit

Ordered Set

1549-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit

Monotonic Queue

1549-longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit

Binary Search Tree

0108-convert-sorted-array-to-binary-search-tree
0538-convert-bst-to-greater-tree
1114-binary-search-tree-to-greater-sum-tree
1285-balance-a-binary-search-tree

Graph

1916-find-center-of-star-graph

LeetCode Topics

Depth-First Search

0145-binary-tree-postorder-traversal
0501-find-mode-in-binary-search-tree
0776-n-ary-tree-postorder-traversal
0999-regions-cut-by-slashes
1207-delete-nodes-and-return-forest
1431-all-ancestors-of-a-node-in-a-directed-acyclic-graph
1484-linked-list-in-binary-tree
1691-minimum-number-of-days-to-disconnect-island
2035-count-sub-islands
2217-step-by-step-directions-from-a-binary-tree-node-to-another

Breadth-First Search

0999-regions-cut-by-slashes
1431-all-ancestors-of-a-node-in-a-directed-acyclic-graph
1484-linked-list-in-binary-tree
1691-minimum-number-of-days-to-disconnect-island
2035-count-sub-islands
2171-second-minimum-time-to-reach-destination

Graph

1325-path-with-maximum-probability
1431-all-ancestors-of-a-node-in-a-directed-acyclic-graph
1456-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
2171-second-minimum-time-to-reach-destination
2472-build-a-matrix-with-conditions
2803-modify-graph-edge-weights

Topological Sort

1431-all-ancestors-of-a-node-in-a-directed-acyclic-graph
2472-build-a-matrix-with-conditions

Tree

0145-binary-tree-postorder-traversal
0501-find-mode-in-binary-search-tree
0776-n-ary-tree-postorder-traversal
0783-search-in-a-binary-search-tree
0784-insert-into-a-binary-search-tree
1207-delete-nodes-and-return-forest
1484-linked-list-in-binary-tree
2217-step-by-step-directions-from-a-binary-tree-node-to-another
2306-create-binary-tree-from-descriptions

Binary Search Tree

0278-first-bad-version
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0501-find-mode-in-binary-search-tree
0719-find-k-th-smallest-pair-distance
0783-search-in-a-binary-search-tree
0784-insert-into-a-binary-search-tree
0792-binary-search
1615-range-sum-of-sorted-subarray-sums
2006-find-the-student-that-will-replace-the-chalk
2634-minimum-common-value
2720-minimize-the-maximum-difference-of-pairs

Binary Tree

0145-binary-tree-postorder-traversal
0501-find-mode-in-binary-search-tree
0783-search-in-a-binary-search-tree
0784-insert-into-a-binary-search-tree
1207-delete-nodes-and-return-forest
1484-linked-list-in-binary-tree
2217-step-by-step-directions-from-a-binary-tree-node-to-another
2306-create-binary-tree-from-descriptions

Array

0040-combination-sum-ii
0054-spiral-matrix
0219-contains-duplicate-ii
0283-move-zeroes
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0682-baseball-game
0719-find-k-th-smallest-pair-distance
0792-binary-search
0870-magic-squares-in-grid
0906-walking-robot-simulation
0948-sort-an-array
0999-regions-cut-by-slashes
1196-filling-bookcase-shelves
1207-delete-nodes-and-return-forest
1240-stone-game-ii
1293-three-consecutive-odds
1325-path-with-maximum-probability
1333-sort-the-jumbled-numbers
1392-find-the-difference-of-two-arrays
1435-xor-queries-of-a-subarray
1496-lucky-numbers-in-a-matrix
1511-count-number-of-teams
1556-make-two-arrays-equal-by-reversing-subarrays
1615-range-sum-of-sorted-subarray-sums
1616-minimum-difference-between-largest-and-smallest-value-in-three-moves
1691-minimum-number-of-days-to-disconnect-island
1711-find-valid-matrix-given-row-and-column-sums
1720-crawler-log-folder
1741-sort-array-by-increasing-frequency
1786-count-the-number-of-consistent-strings
1803-average-waiting-time
1951-find-the-winner-of-the-circular-game
2006-find-the-student-that-will-replace-the-chalk
2035-count-sub-islands
2067-maximum-number-of-points-with-cost
2132-convert-1d-array-into-2d-array
2155-find-missing-observations
2163-kth-distinct-string-in-an-array
2255-minimum-swaps-to-group-all-1s-together-ii
2306-create-binary-tree-from-descriptions
2331-intersection-of-multiple-arrays
2411-spiral-matrix-iv
2472-build-a-matrix-with-conditions
2502-sort-the-people
2503-longest-subarray-with-maximum-bitwise-and
2634-minimum-common-value
2720-minimize-the-maximum-difference-of-pairs
2727-number-of-senior-citizens
2846-robot-collisions
3501-delete-nodes-from-linked-list-present-in-array

Hash Table

0202-happy-number
0219-contains-duplicate-ii
0264-ugly-number-ii
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0726-number-of-atoms
0870-magic-squares-in-grid
0906-walking-robot-simulation
0999-regions-cut-by-slashes
1207-delete-nodes-and-return-forest
1392-find-the-difference-of-two-arrays
1556-make-two-arrays-equal-by-reversing-subarrays
1741-sort-array-by-increasing-frequency
1786-count-the-number-of-consistent-strings
2163-kth-distinct-string-in-an-array
2306-create-binary-tree-from-descriptions
2331-intersection-of-multiple-arrays
2502-sort-the-people
2634-minimum-common-value
3276-minimum-number-of-pushes-to-type-word-ii
3501-delete-nodes-from-linked-list-present-in-array

Sliding Window

0219-contains-duplicate-ii
2255-minimum-swaps-to-group-all-1s-together-ii

Two Pointers

0202-happy-number
0283-move-zeroes
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0719-find-k-th-smallest-pair-distance
0874-backspace-string-compare
1615-range-sum-of-sorted-subarray-sums
2634-minimum-common-value

Sorting

0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0719-find-k-th-smallest-pair-distance
0726-number-of-atoms
0948-sort-an-array
1333-sort-the-jumbled-numbers
1556-make-two-arrays-equal-by-reversing-subarrays
1615-range-sum-of-sorted-subarray-sums
1616-minimum-difference-between-largest-and-smallest-value-in-three-moves
1741-sort-array-by-increasing-frequency
2331-intersection-of-multiple-arrays
2502-sort-the-people
2846-robot-collisions
3276-minimum-number-of-pushes-to-type-word-ii

Counting

1786-count-the-number-of-consistent-strings
2163-kth-distinct-string-in-an-array
2331-intersection-of-multiple-arrays
3276-minimum-number-of-pushes-to-type-word-ii

Greedy

1616-minimum-difference-between-largest-and-smallest-value-in-three-moves
1711-find-valid-matrix-given-row-and-column-sums
2720-minimize-the-maximum-difference-of-pairs
3276-minimum-number-of-pushes-to-type-word-ii

Math

0089-gray-code
0202-happy-number
0264-ugly-number-ii
0273-integer-to-english-words
0564-find-the-closest-palindrome
0592-fraction-addition-and-subtraction
0650-2-keys-keyboard
0870-magic-squares-in-grid
1013-fibonacci-number
1240-stone-game-ii
1642-water-bottles
1951-find-the-winner-of-the-circular-game
2155-find-missing-observations
2645-pass-the-pillow
2903-insert-greatest-common-divisors-in-linked-list

Backtracking

0040-combination-sum-ii
0089-gray-code

Bit Manipulation

0089-gray-code
0461-hamming-distance
0476-number-complement
1054-complement-of-base-10-integer
1435-xor-queries-of-a-subarray
1786-count-the-number-of-consistent-strings
2323-minimum-bit-flips-to-convert-number
2503-longest-subarray-with-maximum-bitwise-and

Linked List

0725-split-linked-list-in-parts
1484-linked-list-in-binary-tree
2182-find-the-minimum-and-maximum-number-of-nodes-between-critical-points
2411-spiral-matrix-iv
2903-insert-greatest-common-divisors-in-linked-list
3501-delete-nodes-from-linked-list-present-in-array

Simulation

0054-spiral-matrix
0592-fraction-addition-and-subtraction
0682-baseball-game
0874-backspace-string-compare
0906-walking-robot-simulation
1642-water-bottles
1803-average-waiting-time
1951-find-the-winner-of-the-circular-game
2006-find-the-student-that-will-replace-the-chalk
2076-sum-of-digits-of-string-after-convert
2132-convert-1d-array-into-2d-array
2155-find-missing-observations
2411-spiral-matrix-iv
2645-pass-the-pillow
2846-robot-collisions

Recursion

0273-integer-to-english-words
1013-fibonacci-number
1951-find-the-winner-of-the-circular-game

Queue

1951-find-the-winner-of-the-circular-game

String

0273-integer-to-english-words
0564-find-the-closest-palindrome
0592-fraction-addition-and-subtraction
0664-strange-printer
0726-number-of-atoms
0874-backspace-string-compare
1298-reverse-substrings-between-each-pair-of-parentheses
1720-crawler-log-folder
1756-minimum-deletions-to-make-string-balanced
1786-count-the-number-of-consistent-strings
2076-sum-of-digits-of-string-after-convert
2163-kth-distinct-string-in-an-array
2217-step-by-step-directions-from-a-binary-tree-node-to-another
2502-sort-the-people
2727-number-of-senior-citizens
3276-minimum-number-of-pushes-to-type-word-ii

Stack

0145-binary-tree-postorder-traversal
0682-baseball-game
0726-number-of-atoms
0776-n-ary-tree-postorder-traversal
0874-backspace-string-compare
1298-reverse-substrings-between-each-pair-of-parentheses
1720-crawler-log-folder
1756-minimum-deletions-to-make-string-balanced
2846-robot-collisions

Interactive

0278-first-bad-version

Matrix

0054-spiral-matrix
0870-magic-squares-in-grid
0999-regions-cut-by-slashes
1496-lucky-numbers-in-a-matrix
1691-minimum-number-of-days-to-disconnect-island
1711-find-valid-matrix-given-row-and-column-sums
2035-count-sub-islands
2132-convert-1d-array-into-2d-array
2411-spiral-matrix-iv
2472-build-a-matrix-with-conditions

Divide and Conquer

0948-sort-an-array

Heap (Priority Queue)

0264-ugly-number-ii
0948-sort-an-array
1325-path-with-maximum-probability
2803-modify-graph-edge-weights

Merge Sort

0948-sort-an-array

Bucket Sort

0948-sort-an-array

Radix Sort

0948-sort-an-array

Counting Sort

0948-sort-an-array

Dynamic Programming

0264-ugly-number-ii
0650-2-keys-keyboard
0664-strange-printer
1013-fibonacci-number
1196-filling-bookcase-shelves
1240-stone-game-ii
1456-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
1511-count-number-of-teams
1756-minimum-deletions-to-make-string-balanced
2067-maximum-number-of-points-with-cost

Shortest Path

1325-path-with-maximum-probability
1456-find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance
2171-second-minimum-time-to-reach-destination
2803-modify-graph-edge-weights

Binary Indexed Tree

1511-count-number-of-teams

Union Find

0999-regions-cut-by-slashes
2035-count-sub-islands

Strongly Connected Component

1691-minimum-number-of-days-to-disconnect-island

Prefix Sum

1240-stone-game-ii
1435-xor-queries-of-a-subarray
2006-find-the-student-that-will-replace-the-chalk

Game Theory

1240-stone-game-ii

Number Theory

2903-insert-greatest-common-divisors-in-linked-list

Memoization

1013-fibonacci-number

Brainteaser

2503-longest-subarray-with-maximum-bitwise-and

dsa-practice's People

Contributors

omkars25 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.