Skip to content

iSparshP/Algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Algorithm Learning Repository

GitHub license

Welcome to my Algorithm Learning Repository! Here, I'm documenting and storing various algorithms that I'm learning and implementing in different programming languages. This repository serves as a resource for myself and others who want to explore and understand different algorithms.

Table of Contents

Introduction

In this repository, you will find a collection of algorithms covering a wide range of topics, including stl data structures, sorting, searching, and more. Each algorithm is implemented in one or more programming languages for educational purposes. You can use this repository to:

  • Learn and understand different algorithms.
  • Explore algorithm implementations in various programming languages.
  • Contribute your own implementations or improvements.

Algorithms

Here's a list of some of the algorithms I've covered so far:

  • Sorting Algorithms:

    • sort()
    • sort comparator function
  • Data Structures:

    • stack
    • queue
    • priority queue
    • array
  • Searching Algorithms:

    • Binary Search
    • Depth-First Search (DFS)
    • Breadth-First Search (BFS)
    • ...
  • Dynamic Programming:

    • Fibonacci Sequence
    • Knapsack Problem
    • knights problem
    • sudoku

This list is not exhaustive, and I'll continue to add more algorithms as I learn and implement them.

Languages

I've implemented these algorithms in various programming languages, including:

  • C++

Feel free to explore the code in your preferred language.

Usage

You can clone this repository to your local machine to explore the algorithms and their implementations. Each algorithm is contained within its own directory and includes a README.md file explaining the algorithm, its time complexity, and usage examples.

To clone the repository, use the following command:

git clone [https://github.com/iSparshP/Algorithms.git]

Contributing

Contributions are welcome! If you'd like to contribute to this repository, follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and ensure they work as expected.
  4. Commit your changes and create a clear, concise pull request with a descriptive title.
  5. Explain the purpose and details of your changes in the pull request description.
  6. I'll review your contributions and merge them if they align with the repository's goals.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Happy learning and coding!

LeetCode Topics

Math

0002-add-two-numbers
0009-palindrome-number
0048-rotate-image
0066-plus-one
0070-climbing-stairs
0096-unique-binary-search-trees
0189-rotate-array
0204-count-primes
0279-perfect-squares
0371-sum-of-two-integers
0797-rabbits-in-forest
1013-fibonacci-number
1086-divisor-game
1146-greatest-common-divisor-of-strings
1236-n-th-tribonacci-number
1500-count-largest-group
2448-count-number-of-bad-pairs
2610-closest-prime-numbers-in-range
3227-find-missing-and-repeated-values
3555-final-array-state-after-k-multiplication-operations-i

Dynamic Programming

0053-maximum-subarray
0055-jump-game
0070-climbing-stairs
0096-unique-binary-search-trees
0118-pascals-triangle
0121-best-time-to-buy-and-sell-stock
0152-maximum-product-subarray
0198-house-robber
0213-house-robber-ii
0221-maximal-square
0279-perfect-squares
0300-longest-increasing-subsequence
0322-coin-change
0435-non-overlapping-intervals
0494-target-sum
0747-min-cost-climbing-stairs
1013-fibonacci-number
1025-minimum-cost-for-tickets
1086-divisor-game
1111-minimum-score-triangulation-of-polygon
1236-n-th-tribonacci-number
1250-longest-common-subsequence
1744-number-of-ways-to-form-a-target-string-given-a-dictionary
2562-count-ways-to-build-good-strings

Memoization

0070-climbing-stairs
1013-fibonacci-number
1236-n-th-tribonacci-number

Binary Search

0033-search-in-rotated-sorted-array
0034-find-first-and-last-position-of-element-in-sorted-array
0035-search-insert-position
0153-find-minimum-in-rotated-sorted-array
0162-find-peak-element
0278-first-bad-version
0287-find-the-duplicate-number
0300-longest-increasing-subsequence
0374-guess-number-higher-or-lower
1468-check-if-n-and-its-double-exist
2392-successful-pairs-of-spells-and-potions
2394-count-subarrays-with-score-less-than-k
2640-maximum-number-of-integers-to-choose-from-a-range-i
2891-maximum-beauty-of-an-array-after-applying-operation
3267-find-longest-special-substring-that-occurs-thrice-i
3427-special-array-ii

Interactive

0278-first-bad-version
0374-guess-number-higher-or-lower

Array

0001-two-sum
0011-container-with-most-water
0033-search-in-rotated-sorted-array
0034-find-first-and-last-position-of-element-in-sorted-array
0035-search-insert-position
0041-first-missing-positive
0046-permutations
0048-rotate-image
0053-maximum-subarray
0055-jump-game
0056-merge-intervals
0057-insert-interval
0066-plus-one
0073-set-matrix-zeroes
0078-subsets
0118-pascals-triangle
0121-best-time-to-buy-and-sell-stock
0130-surrounded-regions
0136-single-number
0137-single-number-ii
0152-maximum-product-subarray
0153-find-minimum-in-rotated-sorted-array
0162-find-peak-element
0169-majority-element
0179-largest-number
0189-rotate-array
0198-house-robber
0200-number-of-islands
0204-count-primes
0213-house-robber-ii
0215-kth-largest-element-in-an-array
0217-contains-duplicate
0221-maximal-square
0238-product-of-array-except-self
0239-sliding-window-maximum
0287-find-the-duplicate-number
0300-longest-increasing-subsequence
0303-range-sum-query-immutable
0322-coin-change
0347-top-k-frequent-elements
0399-evaluate-division
0407-trapping-rain-water-ii
0435-non-overlapping-intervals
0452-minimum-number-of-arrows-to-burst-balloons
0494-target-sum
0560-subarray-sum-equals-k
0605-can-place-flowers
0747-min-cost-climbing-stairs
0780-max-chunks-to-make-sorted
0797-rabbits-in-forest
0817-design-hashmap
0854-making-a-large-island
0952-word-subsets
1025-minimum-cost-for-tickets
1039-find-the-town-judge
1111-minimum-score-triangulation-of-polygon
1319-unique-number-of-occurrences
1364-tuple-with-same-product
1392-find-the-difference-of-two-arrays
1468-check-if-n-and-its-double-exist
1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid
1524-string-matching-in-an-array
1528-kids-with-the-greatest-number-of-candies
1570-final-prices-with-a-special-discount-in-a-shop
1744-number-of-ways-to-form-a-target-string-given-a-dictionary
1876-map-of-highest-peak
1895-minimum-number-of-operations-to-move-all-balls-to-each-box
1917-maximum-average-pass-ratio
2145-grid-game
2232-adding-spaces-to-a-string
2249-count-the-hidden-sequences
2292-counting-words-with-a-given-prefix
2358-number-of-ways-to-split-array
2392-successful-pairs-of-spells-and-potions
2394-count-subarrays-with-score-less-than-k
2448-count-number-of-bad-pairs
2465-shifting-letters-ii
2533-bitwise-xor-of-all-pairings
2551-apply-operations-to-an-array
2553-total-cost-to-hire-k-workers
2626-count-the-number-of-good-subarrays
2636-maximum-subsequence-score
2640-maximum-number-of-integers-to-choose-from-a-range-i
2691-count-vowel-strings-in-ranges
2692-take-gifts-from-the-richest-pile
2695-find-score-of-an-array-after-marking-all-elements
2764-maximum-number-of-fish-in-a-grid
2766-find-the-prefix-common-array-of-two-arrays
2792-neighboring-bitwise-xor
2868-continuous-subarrays
2891-maximum-beauty-of-an-array-after-applying-operation
3219-make-lexicographically-smallest-array-by-swapping-elements
3227-find-missing-and-repeated-values
3309-count-prefix-and-suffix-pairs-i
3427-special-array-ii
3429-special-array-i
3483-alternating-groups-ii
3555-final-array-state-after-k-multiplication-operations-i

Two Pointers

0011-container-with-most-water
0019-remove-nth-node-from-end-of-list
0061-rotate-list
0141-linked-list-cycle
0143-reorder-list
0160-intersection-of-two-linked-lists
0189-rotate-array
0234-palindrome-linked-list
0287-find-the-duplicate-number
0908-middle-of-the-linked-list
1468-check-if-n-and-its-double-exist
1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence
1894-merge-strings-alternately
2232-adding-spaces-to-a-string
2392-successful-pairs-of-spells-and-potions
2414-move-pieces-to-obtain-a-string
2551-apply-operations-to-an-array
2553-total-cost-to-hire-k-workers
3018-make-string-a-subsequence-using-cyclic-increments

Sorting

0056-merge-intervals
0169-majority-element
0179-largest-number
0215-kth-largest-element-in-an-array
0217-contains-duplicate
0242-valid-anagram
0347-top-k-frequent-elements
0435-non-overlapping-intervals
0452-minimum-number-of-arrows-to-burst-balloons
0780-max-chunks-to-make-sorted
1468-check-if-n-and-its-double-exist
2392-successful-pairs-of-spells-and-potions
2636-maximum-subsequence-score
2640-maximum-number-of-integers-to-choose-from-a-range-i
2695-find-score-of-an-array-after-marking-all-elements
2891-maximum-beauty-of-an-array-after-applying-operation
3219-make-lexicographically-smallest-array-by-swapping-elements

Divide and Conquer

0053-maximum-subarray
0169-majority-element
0191-number-of-1-bits
0215-kth-largest-element-in-an-array
0347-top-k-frequent-elements

Heap (Priority Queue)

0215-kth-largest-element-in-an-array
0239-sliding-window-maximum
0347-top-k-frequent-elements
0407-trapping-rain-water-ii
1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid
1917-maximum-average-pass-ratio
2300-construct-string-with-repeat-limit
2413-smallest-number-in-infinite-set
2553-total-cost-to-hire-k-workers
2636-maximum-subsequence-score
2692-take-gifts-from-the-richest-pile
2695-find-score-of-an-array-after-marking-all-elements
2868-continuous-subarrays
3555-final-array-state-after-k-multiplication-operations-i

Quickselect

0215-kth-largest-element-in-an-array
0347-top-k-frequent-elements

Hash Table

0001-two-sum
0003-longest-substring-without-repeating-characters
0017-letter-combinations-of-a-phone-number
0041-first-missing-positive
0073-set-matrix-zeroes
0141-linked-list-cycle
0146-lru-cache
0160-intersection-of-two-linked-lists
0169-majority-element
0208-implement-trie-prefix-tree
0217-contains-duplicate
0242-valid-anagram
0347-top-k-frequent-elements
0560-subarray-sum-equals-k
0797-rabbits-in-forest
0817-design-hashmap
0952-word-subsets
1039-find-the-town-judge
1319-unique-number-of-occurrences
1364-tuple-with-same-product
1392-find-the-difference-of-two-arrays
1468-check-if-n-and-its-double-exist
1500-count-largest-group
1502-construct-k-palindrome-strings
2059-unique-length-3-palindromic-subsequences
2300-construct-string-with-repeat-limit
2413-smallest-number-in-infinite-set
2448-count-number-of-bad-pairs
2626-count-the-number-of-good-subarrays
2640-maximum-number-of-integers-to-choose-from-a-range-i
2695-find-score-of-an-array-after-marking-all-elements
2766-find-the-prefix-common-array-of-two-arrays
3227-find-missing-and-repeated-values
3267-find-longest-special-substring-that-occurs-thrice-i
3455-minimum-length-of-string-after-operations

Design

0146-lru-cache
0155-min-stack
0208-implement-trie-prefix-tree
0303-range-sum-query-immutable
0817-design-hashmap
0969-number-of-recent-calls
1708-design-parking-system
2413-smallest-number-in-infinite-set

Greedy

0011-container-with-most-water
0055-jump-game
0179-largest-number
0435-non-overlapping-intervals
0452-minimum-number-of-arrows-to-burst-balloons
0605-can-place-flowers
0780-max-chunks-to-make-sorted
0797-rabbits-in-forest
1502-construct-k-palindrome-strings
1917-maximum-average-pass-ratio
2221-check-if-a-parentheses-string-can-be-valid
2300-construct-string-with-repeat-limit
2509-minimize-xor
2636-maximum-subsequence-score
2640-maximum-number-of-integers-to-choose-from-a-range-i

Simulation

1708-design-parking-system
2232-adding-spaces-to-a-string
2551-apply-operations-to-an-array
2553-total-cost-to-hire-k-workers
2692-take-gifts-from-the-richest-pile
2695-find-score-of-an-array-after-marking-all-elements
3555-final-array-state-after-k-multiplication-operations-i

Database

0175-combine-two-tables
0181-employees-earning-more-than-their-managers
0197-rising-temperature
0601-human-traffic-of-stadium
1153-product-sales-analysis-i
1161-project-employees-i
1338-queries-quality-and-percentage
1509-replace-employee-id-with-the-unique-identifier
1724-customer-who-visited-but-did-not-make-any-transactions
1773-percentage-of-users-attended-a-contest

String

0003-longest-substring-without-repeating-characters
0017-letter-combinations-of-a-phone-number
0179-largest-number
0208-implement-trie-prefix-tree
0242-valid-anagram
0399-evaluate-division
0952-word-subsets
1146-greatest-common-divisor-of-strings
1250-longest-common-subsequence
1502-construct-k-palindrome-strings
1524-string-matching-in-an-array
1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence
1744-number-of-ways-to-form-a-target-string-given-a-dictionary
1894-merge-strings-alternately
1895-minimum-number-of-operations-to-move-all-balls-to-each-box
2059-unique-length-3-palindromic-subsequences
2221-check-if-a-parentheses-string-can-be-valid
2232-adding-spaces-to-a-string
2292-counting-words-with-a-given-prefix
2300-construct-string-with-repeat-limit
2401-count-asterisks
2414-move-pieces-to-obtain-a-string
2465-shifting-letters-ii
2580-circular-sentence
2691-count-vowel-strings-in-ranges
3018-make-string-a-subsequence-using-cyclic-increments
3267-find-longest-special-substring-that-occurs-thrice-i
3309-count-prefix-and-suffix-pairs-i
3396-valid-word
3455-minimum-length-of-string-after-operations

Enumeration

0204-count-primes

Number Theory

0204-count-primes
2610-closest-prime-numbers-in-range

Sliding Window

0003-longest-substring-without-repeating-characters
0239-sliding-window-maximum
2394-count-subarrays-with-score-less-than-k
2626-count-the-number-of-good-subarrays
2868-continuous-subarrays
2891-maximum-beauty-of-an-array-after-applying-operation
3267-find-longest-special-substring-that-occurs-thrice-i
3483-alternating-groups-ii

Matrix

0048-rotate-image
0073-set-matrix-zeroes
0130-surrounded-regions
0200-number-of-islands
0221-maximal-square
0407-trapping-rain-water-ii
0854-making-a-large-island
1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid
1876-map-of-highest-peak
2145-grid-game
2764-maximum-number-of-fish-in-a-grid
3227-find-missing-and-repeated-values

Bit Manipulation

0078-subsets
0136-single-number
0137-single-number-ii
0191-number-of-1-bits
0287-find-the-duplicate-number
0371-sum-of-two-integers
2059-unique-length-3-palindromic-subsequences
2509-minimize-xor
2533-bitwise-xor-of-all-pairings
2766-find-the-prefix-common-array-of-two-arrays
2792-neighboring-bitwise-xor

Counting

0169-majority-element
0347-top-k-frequent-elements
1364-tuple-with-same-product
1502-construct-k-palindrome-strings
1708-design-parking-system
2300-construct-string-with-repeat-limit
2448-count-number-of-bad-pairs
3267-find-longest-special-substring-that-occurs-thrice-i
3455-minimum-length-of-string-after-operations

Backtracking

0017-letter-combinations-of-a-phone-number
0046-permutations
0077-combinations
0078-subsets
0494-target-sum

Linked List

0002-add-two-numbers
0019-remove-nth-node-from-end-of-list
0021-merge-two-sorted-lists
0024-swap-nodes-in-pairs
0061-rotate-list
0114-flatten-binary-tree-to-linked-list
0141-linked-list-cycle
0143-reorder-list
0146-lru-cache
0160-intersection-of-two-linked-lists
0206-reverse-linked-list
0234-palindrome-linked-list
0237-delete-node-in-a-linked-list
0817-design-hashmap
0908-middle-of-the-linked-list

Recursion

0002-add-two-numbers
0021-merge-two-sorted-lists
0024-swap-nodes-in-pairs
0143-reorder-list
0206-reverse-linked-list
0234-palindrome-linked-list
1013-fibonacci-number

Breadth-First Search

0100-same-tree
0130-surrounded-regions
0200-number-of-islands
0207-course-schedule
0210-course-schedule-ii
0279-perfect-squares
0322-coin-change
0399-evaluate-division
0407-trapping-rain-water-ii
0515-find-largest-value-in-each-tree-row
0547-number-of-provinces
0684-redundant-connection
0854-making-a-large-island
0871-keys-and-rooms
1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid
1558-course-schedule-iv
1576-reorder-routes-to-make-all-paths-lead-to-the-city-zero
1876-map-of-highest-peak
2493-reverse-odd-levels-of-binary-tree
2558-minimum-number-of-operations-to-sort-a-binary-tree-by-level
2583-divide-nodes-into-the-maximum-number-of-groups
2764-maximum-number-of-fish-in-a-grid

Brainteaser

1086-divisor-game
2533-bitwise-xor-of-all-pairings

Game Theory

1086-divisor-game

Tree

0096-unique-binary-search-trees
0100-same-tree
0114-flatten-binary-tree-to-linked-list
0515-find-largest-value-in-each-tree-row
2493-reverse-odd-levels-of-binary-tree
2558-minimum-number-of-operations-to-sort-a-binary-tree-by-level

Binary Search Tree

0096-unique-binary-search-trees

Binary Tree

0096-unique-binary-search-trees
0100-same-tree
0114-flatten-binary-tree-to-linked-list
0515-find-largest-value-in-each-tree-row
2493-reverse-odd-levels-of-binary-tree
2558-minimum-number-of-operations-to-sort-a-binary-tree-by-level

Depth-First Search

0100-same-tree
0114-flatten-binary-tree-to-linked-list
0130-surrounded-regions
0200-number-of-islands
0207-course-schedule
0210-course-schedule-ii
0399-evaluate-division
0515-find-largest-value-in-each-tree-row
0547-number-of-provinces
0684-redundant-connection
0854-making-a-large-island
0871-keys-and-rooms
1558-course-schedule-iv
1576-reorder-routes-to-make-all-paths-lead-to-the-city-zero
2246-maximum-employees-to-be-invited-to-a-meeting
2493-reverse-odd-levels-of-binary-tree
2764-maximum-number-of-fish-in-a-grid

Graph

0207-course-schedule
0210-course-schedule-ii
0399-evaluate-division
0547-number-of-provinces
0684-redundant-connection
0871-keys-and-rooms
1039-find-the-town-judge
1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid
1558-course-schedule-iv
1576-reorder-routes-to-make-all-paths-lead-to-the-city-zero
2246-maximum-employees-to-be-invited-to-a-meeting
2583-divide-nodes-into-the-maximum-number-of-groups

Union Find

0130-surrounded-regions
0200-number-of-islands
0399-evaluate-division
0547-number-of-provinces
0684-redundant-connection
0854-making-a-large-island
2583-divide-nodes-into-the-maximum-number-of-groups
2764-maximum-number-of-fish-in-a-grid
3219-make-lexicographically-smallest-array-by-swapping-elements

Trie

0208-implement-trie-prefix-tree
3309-count-prefix-and-suffix-pairs-i

Topological Sort

0207-course-schedule
0210-course-schedule-ii
1558-course-schedule-iv
2246-maximum-employees-to-be-invited-to-a-meeting

Shortest Path

0399-evaluate-division
1485-minimum-cost-to-make-at-least-one-valid-path-in-a-grid

String Matching

1524-string-matching-in-an-array
1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence
2292-counting-words-with-a-given-prefix
3309-count-prefix-and-suffix-pairs-i

Prefix Sum

0238-product-of-array-except-self
0303-range-sum-query-immutable
0560-subarray-sum-equals-k
1895-minimum-number-of-operations-to-move-all-balls-to-each-box
2059-unique-length-3-palindromic-subsequences
2145-grid-game
2249-count-the-hidden-sequences
2358-number-of-ways-to-split-array
2394-count-subarrays-with-score-less-than-k
2465-shifting-letters-ii
2691-count-vowel-strings-in-ranges
3427-special-array-ii

Stack

0114-flatten-binary-tree-to-linked-list
0143-reorder-list
0155-min-stack
0234-palindrome-linked-list
0780-max-chunks-to-make-sorted
1570-final-prices-with-a-special-discount-in-a-shop
2221-check-if-a-parentheses-string-can-be-valid

Monotonic Stack

0780-max-chunks-to-make-sorted
1570-final-prices-with-a-special-discount-in-a-shop

Queue

0239-sliding-window-maximum
0969-number-of-recent-calls
2868-continuous-subarrays

Ordered Set

2868-continuous-subarrays

Monotonic Queue

0239-sliding-window-maximum
2868-continuous-subarrays

Data Stream

0969-number-of-recent-calls

Rolling Hash

3309-count-prefix-and-suffix-pairs-i

Hash Function

0817-design-hashmap
3309-count-prefix-and-suffix-pairs-i

Doubly-Linked List

0146-lru-cache

Bucket Sort

0347-top-k-frequent-elements

About

this repository is going to be the home for all of algorithmic work

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages