Skip to content

Welcome, Here you'll find a collection of my solutions to Data Structure and Algorithm questions from platforms like GeeksforGeeks and LeetCode. I love tackling these challenges and sharing my code with fellow developers. Feel free to explore, learn, and contribute to this growing library of solutions. Let's master the world of algorithms together

Notifications You must be signed in to change notification settings

Abhik-Chakraborty/DSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Topics

Array

0001-two-sum
0004-median-of-two-sorted-arrays
0011-container-with-most-water
0015-3sum
0016-3sum-closest
0018-4sum
0026-remove-duplicates-from-sorted-array
0027-remove-element
0031-next-permutation
0034-find-first-and-last-position-of-element-in-sorted-array
0035-search-insert-position
0036-valid-sudoku
0041-first-missing-positive
0042-trapping-rain-water
0045-jump-game-ii
0048-rotate-image
0053-maximum-subarray
0054-spiral-matrix
0055-jump-game
0056-merge-intervals
0057-insert-interval
0066-plus-one
0073-set-matrix-zeroes
0074-search-a-2d-matrix
0075-sort-colors
0080-remove-duplicates-from-sorted-array-ii
0081-search-in-rotated-sorted-array-ii
0088-merge-sorted-array
0118-pascals-triangle
0121-best-time-to-buy-and-sell-stock
0122-best-time-to-buy-and-sell-stock-ii
0123-best-time-to-buy-and-sell-stock-iii
0128-longest-consecutive-sequence
0134-gas-station
0136-single-number
0152-maximum-product-subarray
0153-find-minimum-in-rotated-sorted-array
0162-find-peak-element
0167-two-sum-ii-input-array-is-sorted
0189-rotate-array
0209-minimum-size-subarray-sum
0215-kth-largest-element-in-an-array
0217-contains-duplicate
0219-contains-duplicate-ii
0228-summary-ranges
0229-majority-element-ii
0238-product-of-array-except-self
0268-missing-number
0274-h-index
0283-move-zeroes
0287-find-the-duplicate-number
0289-game-of-life
0347-top-k-frequent-elements
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0380-insert-delete-getrandom-o1
0416-partition-equal-subset-sum
0452-minimum-number-of-arrows-to-burst-balloons
0455-assign-cookies
0457-circular-array-loop
0485-max-consecutive-ones
0500-keyboard-row
0540-single-element-in-a-sorted-array
0560-subarray-sum-equals-k
0605-can-place-flowers
0643-maximum-average-subarray-i
0724-find-pivot-index
0745-find-smallest-letter-greater-than-target
0890-lemonade-change
0907-koko-eating-bananas
0952-word-subsets
0966-binary-subarrays-with-sum
1034-subarrays-with-k-different-integers
1046-max-consecutive-ones-iii
1364-tuple-with-same-product
1370-count-number-of-nice-subarrays
1408-find-the-smallest-divisor-given-a-threshold
1524-string-matching-in-an-array
1538-maximum-points-you-can-obtain-from-cards
1586-longest-subarray-of-1s-after-deleting-one-element
1798-max-number-of-k-sum-pairs
1878-check-if-array-is-sorted-and-rotated
1895-minimum-number-of-operations-to-move-all-balls-to-each-box
1927-maximum-ascending-subarray-sum
1966-frequency-of-the-most-frequent-element
2271-rearrange-array-elements-by-sign
2292-counting-words-with-a-given-prefix
2350-find-closest-number-to-zero
2358-number-of-ways-to-split-array
2448-count-number-of-bad-pairs
2465-shifting-letters-ii
2478-longest-nice-subarray
2486-most-frequent-even-element
2533-bitwise-xor-of-all-pairings
2685-first-completely-painted-row-or-column
2691-count-vowel-strings-in-ranges
2766-find-the-prefix-common-array-of-two-arrays
2792-neighboring-bitwise-xor
3236-smallest-missing-integer-greater-than-sequential-prefix-sum
3309-count-prefix-and-suffix-pairs-i
3372-longest-strictly-increasing-or-strictly-decreasing-subarray
3429-special-array-i
3434-find-the-number-of-distinct-colors-among-the-balls

Binary Search

0004-median-of-two-sorted-arrays
0034-find-first-and-last-position-of-element-in-sorted-array
0035-search-insert-position
0074-search-a-2d-matrix
0081-search-in-rotated-sorted-array-ii
0153-find-minimum-in-rotated-sorted-array
0162-find-peak-element
0167-two-sum-ii-input-array-is-sorted
0209-minimum-size-subarray-sum
0268-missing-number
0287-find-the-duplicate-number
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0374-guess-number-higher-or-lower
0540-single-element-in-a-sorted-array
0745-find-smallest-letter-greater-than-target
0907-koko-eating-bananas
1046-max-consecutive-ones-iii
1408-find-the-smallest-divisor-given-a-threshold
1966-frequency-of-the-most-frequent-element

Hash Table

0001-two-sum
0003-longest-substring-without-repeating-characters
0012-integer-to-roman
0036-valid-sudoku
0041-first-missing-positive
0073-set-matrix-zeroes
0076-minimum-window-substring
0128-longest-consecutive-sequence
0138-copy-list-with-random-pointer
0141-linked-list-cycle
0142-linked-list-cycle-ii
0160-intersection-of-two-linked-lists
0202-happy-number
0205-isomorphic-strings
0217-contains-duplicate
0219-contains-duplicate-ii
0229-majority-element-ii
0242-valid-anagram
0268-missing-number
0290-word-pattern
0347-top-k-frequent-elements
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0380-insert-delete-getrandom-o1
0383-ransom-note
0387-first-unique-character-in-a-string
0389-find-the-difference
0424-longest-repeating-character-replacement
0451-sort-characters-by-frequency
0457-circular-array-loop
0500-keyboard-row
0560-subarray-sum-equals-k
0952-word-subsets
0966-binary-subarrays-with-sum
1029-vertical-order-traversal-of-a-binary-tree
1034-subarrays-with-k-different-integers
1364-tuple-with-same-product
1370-count-number-of-nice-subarrays
1460-number-of-substrings-containing-all-three-characters
1502-construct-k-palindrome-strings
1798-max-number-of-k-sum-pairs
1890-sum-of-beauty-of-all-substrings
1915-check-if-one-string-swap-can-make-strings-equal
2059-unique-length-3-palindromic-subsequences
2427-first-letter-to-appear-twice
2448-count-number-of-bad-pairs
2486-most-frequent-even-element
2685-first-completely-painted-row-or-column
2766-find-the-prefix-common-array-of-two-arrays
3236-smallest-missing-integer-greater-than-sequential-prefix-sum
3434-find-the-number-of-distinct-colors-among-the-balls
3455-minimum-length-of-string-after-operations

Math

0007-reverse-integer
0009-palindrome-number
0012-integer-to-roman
0029-divide-two-integers
0048-rotate-image
0066-plus-one
0067-add-binary
0189-rotate-array
0202-happy-number
0231-power-of-two
0268-missing-number
0380-insert-delete-getrandom-o1
0412-fizz-buzz
0445-add-two-numbers-ii
1370-count-number-of-nice-subarrays
2032-largest-odd-number-in-string
2448-count-number-of-bad-pairs

Bit Manipulation

0029-divide-two-integers
0067-add-binary
0136-single-number
0231-power-of-two
0268-missing-number
0287-find-the-duplicate-number
0389-find-the-difference
2059-unique-length-3-palindromic-subsequences
2427-first-letter-to-appear-twice
2478-longest-nice-subarray
2509-minimize-xor
2533-bitwise-xor-of-all-pairings
2766-find-the-prefix-common-array-of-two-arrays
2792-neighboring-bitwise-xor

Sorting

0015-3sum
0016-3sum-closest
0018-4sum
0056-merge-intervals
0075-sort-colors
0088-merge-sorted-array
0148-sort-list
0215-kth-largest-element-in-an-array
0217-contains-duplicate
0229-majority-element-ii
0242-valid-anagram
0268-missing-number
0274-h-index
0347-top-k-frequent-elements
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0389-find-the-difference
0451-sort-characters-by-frequency
0452-minimum-number-of-arrows-to-burst-balloons
0455-assign-cookies
1029-vertical-order-traversal-of-a-binary-tree
1798-max-number-of-k-sum-pairs
1966-frequency-of-the-most-frequent-element
2646-kth-largest-sum-in-a-binary-tree
3236-smallest-missing-integer-greater-than-sequential-prefix-sum

Two Pointers

0005-longest-palindromic-substring
0011-container-with-most-water
0015-3sum
0016-3sum-closest
0018-4sum
0019-remove-nth-node-from-end-of-list
0026-remove-duplicates-from-sorted-array
0027-remove-element
0028-find-the-index-of-the-first-occurrence-in-a-string
0031-next-permutation
0042-trapping-rain-water
0075-sort-colors
0080-remove-duplicates-from-sorted-array-ii
0088-merge-sorted-array
0125-valid-palindrome
0141-linked-list-cycle
0142-linked-list-cycle-ii
0148-sort-list
0151-reverse-words-in-a-string
0160-intersection-of-two-linked-lists
0167-two-sum-ii-input-array-is-sorted
0189-rotate-array
0202-happy-number
0234-palindrome-linked-list
0283-move-zeroes
0287-find-the-duplicate-number
0344-reverse-string
0345-reverse-vowels-of-a-string
0349-intersection-of-two-arrays
0350-intersection-of-two-arrays-ii
0392-is-subsequence
0443-string-compression
0455-assign-cookies
0457-circular-array-loop
0647-palindromic-substrings
0908-middle-of-the-linked-list
1798-max-number-of-k-sum-pairs
1850-minimum-length-of-string-after-deleting-similar-ends
1894-merge-strings-alternately
2216-delete-the-middle-node-of-a-linked-list
2271-rearrange-array-elements-by-sign

String

0003-longest-substring-without-repeating-characters
0005-longest-palindromic-substring
0008-string-to-integer-atoi
0012-integer-to-roman
0014-longest-common-prefix
0020-valid-parentheses
0022-generate-parentheses
0028-find-the-index-of-the-first-occurrence-in-a-string
0058-length-of-last-word
0067-add-binary
0076-minimum-window-substring
0125-valid-palindrome
0151-reverse-words-in-a-string
0205-isomorphic-strings
0242-valid-anagram
0290-word-pattern
0344-reverse-string
0345-reverse-vowels-of-a-string
0383-ransom-note
0387-first-unique-character-in-a-string
0389-find-the-difference
0392-is-subsequence
0412-fizz-buzz
0424-longest-repeating-character-replacement
0443-string-compression
0451-sort-characters-by-frequency
0459-repeated-substring-pattern
0500-keyboard-row
0647-palindromic-substrings
0812-rotate-string
0952-word-subsets
1078-remove-outermost-parentheses
1460-number-of-substrings-containing-all-three-characters
1502-construct-k-palindrome-strings
1524-string-matching-in-an-array
1537-maximum-score-after-splitting-a-string
1567-maximum-number-of-vowels-in-a-substring-of-given-length
1737-maximum-nesting-depth-of-the-parentheses
1850-minimum-length-of-string-after-deleting-similar-ends
1890-sum-of-beauty-of-all-substrings
1894-merge-strings-alternately
1895-minimum-number-of-operations-to-move-all-balls-to-each-box
1915-check-if-one-string-swap-can-make-strings-equal
2032-largest-odd-number-in-string
2059-unique-length-3-palindromic-subsequences
2221-check-if-a-parentheses-string-can-be-valid
2292-counting-words-with-a-given-prefix
2427-first-letter-to-appear-twice
2465-shifting-letters-ii
2691-count-vowel-strings-in-ranges
3309-count-prefix-and-suffix-pairs-i
3447-clear-digits
3455-minimum-length-of-string-after-operations

String Matching

0028-find-the-index-of-the-first-occurrence-in-a-string
0459-repeated-substring-pattern
0812-rotate-string
1524-string-matching-in-an-array
2292-counting-words-with-a-given-prefix
3309-count-prefix-and-suffix-pairs-i

Interactive

0374-guess-number-higher-or-lower

Dynamic Programming

0005-longest-palindromic-substring
0022-generate-parentheses
0042-trapping-rain-water
0045-jump-game-ii
0053-maximum-subarray
0055-jump-game
0118-pascals-triangle
0121-best-time-to-buy-and-sell-stock
0122-best-time-to-buy-and-sell-stock-ii
0123-best-time-to-buy-and-sell-stock-iii
0124-binary-tree-maximum-path-sum
0152-maximum-product-subarray
0392-is-subsequence
0416-partition-equal-subset-sum
0647-palindromic-substrings
1586-longest-subarray-of-1s-after-deleting-one-element

Matrix

0036-valid-sudoku
0048-rotate-image
0054-spiral-matrix
0073-set-matrix-zeroes
0074-search-a-2d-matrix
0289-game-of-life
2685-first-completely-painted-row-or-column

Prefix Sum

0209-minimum-size-subarray-sum
0238-product-of-array-except-self
0560-subarray-sum-equals-k
0724-find-pivot-index
0966-binary-subarrays-with-sum
1046-max-consecutive-ones-iii
1370-count-number-of-nice-subarrays
1537-maximum-score-after-splitting-a-string
1538-maximum-points-you-can-obtain-from-cards
1895-minimum-number-of-operations-to-move-all-balls-to-each-box
1966-frequency-of-the-most-frequent-element
2059-unique-length-3-palindromic-subsequences
2358-number-of-ways-to-split-array
2465-shifting-letters-ii
2691-count-vowel-strings-in-ranges

Divide and Conquer

0004-median-of-two-sorted-arrays
0053-maximum-subarray
0148-sort-list
0215-kth-largest-element-in-an-array
0347-top-k-frequent-elements

Sliding Window

0003-longest-substring-without-repeating-characters
0076-minimum-window-substring
0209-minimum-size-subarray-sum
0219-contains-duplicate-ii
0424-longest-repeating-character-replacement
0643-maximum-average-subarray-i
0966-binary-subarrays-with-sum
1034-subarrays-with-k-different-integers
1046-max-consecutive-ones-iii
1370-count-number-of-nice-subarrays
1460-number-of-substrings-containing-all-three-characters
1538-maximum-points-you-can-obtain-from-cards
1567-maximum-number-of-vowels-in-a-substring-of-given-length
1586-longest-subarray-of-1s-after-deleting-one-element
1966-frequency-of-the-most-frequent-element
2478-longest-nice-subarray

Tree

0094-binary-tree-inorder-traversal
0100-same-tree
0102-binary-tree-level-order-traversal
0103-binary-tree-zigzag-level-order-traversal
0104-maximum-depth-of-binary-tree
0110-balanced-binary-tree
0124-binary-tree-maximum-path-sum
0144-binary-tree-preorder-traversal
0145-binary-tree-postorder-traversal
0515-find-largest-value-in-each-tree-row
0543-diameter-of-binary-tree
1029-vertical-order-traversal-of-a-binary-tree
2646-kth-largest-sum-in-a-binary-tree

Breadth-First Search

0100-same-tree
0102-binary-tree-level-order-traversal
0103-binary-tree-zigzag-level-order-traversal
0104-maximum-depth-of-binary-tree
0515-find-largest-value-in-each-tree-row
1029-vertical-order-traversal-of-a-binary-tree
2646-kth-largest-sum-in-a-binary-tree

Binary Tree

0094-binary-tree-inorder-traversal
0100-same-tree
0102-binary-tree-level-order-traversal
0103-binary-tree-zigzag-level-order-traversal
0104-maximum-depth-of-binary-tree
0110-balanced-binary-tree
0124-binary-tree-maximum-path-sum
0144-binary-tree-preorder-traversal
0145-binary-tree-postorder-traversal
0515-find-largest-value-in-each-tree-row
0543-diameter-of-binary-tree
1029-vertical-order-traversal-of-a-binary-tree
2646-kth-largest-sum-in-a-binary-tree

Simulation

0054-spiral-matrix
0067-add-binary
0289-game-of-life
0412-fizz-buzz
2271-rearrange-array-elements-by-sign
3434-find-the-number-of-distinct-colors-among-the-balls
3447-clear-digits

Union Find

0128-longest-consecutive-sequence

Stack

0020-valid-parentheses
0042-trapping-rain-water
0094-binary-tree-inorder-traversal
0144-binary-tree-preorder-traversal
0145-binary-tree-postorder-traversal
0155-min-stack
0225-implement-stack-using-queues
0232-implement-queue-using-stacks
0234-palindrome-linked-list
0445-add-two-numbers-ii
1078-remove-outermost-parentheses
1737-maximum-nesting-depth-of-the-parentheses
2221-check-if-a-parentheses-string-can-be-valid
3447-clear-digits

Linked List

0019-remove-nth-node-from-end-of-list
0083-remove-duplicates-from-sorted-list
0092-reverse-linked-list-ii
0138-copy-list-with-random-pointer
0141-linked-list-cycle
0142-linked-list-cycle-ii
0148-sort-list
0160-intersection-of-two-linked-lists
0206-reverse-linked-list
0234-palindrome-linked-list
0237-delete-node-in-a-linked-list
0328-odd-even-linked-list
0445-add-two-numbers-ii
0908-middle-of-the-linked-list
2216-delete-the-middle-node-of-a-linked-list

Greedy

0011-container-with-most-water
0045-jump-game-ii
0055-jump-game
0122-best-time-to-buy-and-sell-stock-ii
0134-gas-station
0452-minimum-number-of-arrows-to-burst-balloons
0455-assign-cookies
0605-can-place-flowers
0890-lemonade-change
1502-construct-k-palindrome-strings
1966-frequency-of-the-most-frequent-element
2032-largest-odd-number-in-string
2221-check-if-a-parentheses-string-can-be-valid
2509-minimize-xor

Trie

0014-longest-common-prefix
3309-count-prefix-and-suffix-pairs-i

Heap (Priority Queue)

0215-kth-largest-element-in-an-array
0347-top-k-frequent-elements
0451-sort-characters-by-frequency

Bucket Sort

0347-top-k-frequent-elements
0451-sort-characters-by-frequency

Counting

0229-majority-element-ii
0347-top-k-frequent-elements
0383-ransom-note
0387-first-unique-character-in-a-string
0451-sort-characters-by-frequency
1034-subarrays-with-k-different-integers
1364-tuple-with-same-product
1502-construct-k-palindrome-strings
1890-sum-of-beauty-of-all-substrings
1915-check-if-one-string-swap-can-make-strings-equal
2427-first-letter-to-appear-twice
2448-count-number-of-bad-pairs
2486-most-frequent-even-element
3455-minimum-length-of-string-after-operations

Quickselect

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

Queue

0225-implement-stack-using-queues
0232-implement-queue-using-stacks
0387-first-unique-character-in-a-string

Recursion

0206-reverse-linked-list
0231-power-of-two
0234-palindrome-linked-list

Merge Sort

0148-sort-list

Design

0155-min-stack
0225-implement-stack-using-queues
0232-implement-queue-using-stacks
0380-insert-delete-getrandom-o1

Counting Sort

0274-h-index

Depth-First Search

0094-binary-tree-inorder-traversal
0100-same-tree
0104-maximum-depth-of-binary-tree
0110-balanced-binary-tree
0124-binary-tree-maximum-path-sum
0144-binary-tree-preorder-traversal
0145-binary-tree-postorder-traversal
0515-find-largest-value-in-each-tree-row
0543-diameter-of-binary-tree
1029-vertical-order-traversal-of-a-binary-tree

Rolling Hash

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

Hash Function

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

Brainteaser

2533-bitwise-xor-of-all-pairings

Monotonic Stack

0042-trapping-rain-water

Backtracking

0022-generate-parentheses

Randomized

0380-insert-delete-getrandom-o1

About

Welcome, Here you'll find a collection of my solutions to Data Structure and Algorithm questions from platforms like GeeksforGeeks and LeetCode. I love tackling these challenges and sharing my code with fellow developers. Feel free to explore, learn, and contribute to this growing library of solutions. Let's master the world of algorithms together

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published