Skip to content

rushdarshan/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Solutions by Darshan

Welcome to my LeetCode solutions repository! This repo contains my solutions to various algorithm and data structure problems from LeetCode, implemented mainly in C++.
The goal of this repo is to track my problem-solving progress, improve my coding skills, and share helpful solutions with the community.


About

This repository is a personal collection of solutions to LeetCode problems. Each solution aims to provide clear, optimized, and well-commented code for better understanding.
I update this repo regularly as I solve new problems and revise older ones.


LeetCode Topics

Linked List

0002-add-two-numbers
1267-remove-zero-sum-consecutive-nodes-from-linked-list
2903-insert-greatest-common-divisors-in-linked-list
3501-delete-nodes-from-linked-list-present-in-array

Math

0002-add-two-numbers
0007-reverse-integer
0009-palindrome-number
0043-multiply-strings
0066-plus-one
0189-rotate-array
0231-power-of-two
0268-missing-number
0509-fibonacci-number
0670-maximum-swap
0840-magic-squares-in-grid
0900-reordered-power-of-2
1018-largest-perimeter-triangle
1390-four-divisors
1426-find-n-unique-integers-sum-up-to-zero
1523-count-odd-numbers-in-an-interval-range
1635-number-of-good-pairs
1642-water-bottles
1889-check-if-number-is-a-sum-of-powers-of-three
1925-count-square-sum-triples
1979-find-greatest-common-divisor-of-array
2110-number-of-smooth-descent-periods-of-a-stock
2147-number-of-ways-to-divide-a-long-corridor
2288-count-operations-to-obtain-zero
2610-closest-prime-numbers-in-range
2649-count-total-number-of-colored-cells
2903-insert-greatest-common-divisors-in-linked-list
3172-divisible-and-non-divisible-sums-difference
3190-find-minimum-operations-to-make-all-elements-divisible-by-three
3201-distribute-candies-among-children-ii
3227-find-missing-and-repeated-values
3321-type-of-triangle
3336-water-bottles-ii
3432-count-partitions-with-even-sum-difference
3433-count-mentions-per-user
3512-minimum-operations-to-make-array-sum-divisible-by-k
3515-find-if-digit-game-can-be-won
3577-count-the-number-of-computer-unlocking-permutations
3581-the-two-sneaky-numbers-of-digitville
3623-count-number-of-trapezoids-i
3625-count-number-of-trapezoids-ii
3676-smallest-number-with-all-set-bits
3768-check-if-digits-are-equal-in-string-after-operations-i

Recursion

0002-add-two-numbers
0231-power-of-two
0509-fibonacci-number
1197-parsing-a-boolean-expression
1667-find-kth-bit-in-nth-binary-string

Array

0001-two-sum
0026-remove-duplicates-from-sorted-array
0027-remove-element
0036-valid-sudoku
0037-sudoku-solver
0041-first-missing-positive
0066-plus-one
0075-sort-colors
0085-maximal-rectangle
0088-merge-sorted-array
0120-triangle
0121-best-time-to-buy-and-sell-stock
0135-candy
0136-single-number
0167-two-sum-ii-input-array-is-sorted
0169-majority-element
0189-rotate-array
0217-contains-duplicate
0219-contains-duplicate-ii
0268-missing-number
0283-move-zeroes
0287-find-the-duplicate-number
0347-top-k-frequent-elements
0349-intersection-of-two-arrays
0448-find-all-numbers-disappeared-in-an-array
0455-assign-cookies
0474-ones-and-zeroes
0611-valid-triangle-number
0645-set-mismatch
0717-1-bit-and-2-bit-characters
0745-find-smallest-letter-greater-than-target
0759-set-intersection-size-at-least-two
0833-bus-routes
0840-magic-squares-in-grid
0934-bitwise-ors-of-subarrays
0941-sort-array-by-parity
0944-delete-columns-to-make-sorted
0955-delete-columns-to-make-sorted-ii
0960-delete-columns-to-make-sorted-iii
0961-n-repeated-element-in-size-2n-array
1002-maximum-width-ramp
1018-largest-perimeter-triangle
1019-squares-of-a-sorted-array
1168-duplicate-zeros
1249-snapshot-array
1262-greatest-sum-divisible-by-three
1293-three-consecutive-odds
1335-maximum-candies-allocated-to-k-children
1351-count-negative-numbers-in-a-sorted-matrix
1390-four-divisors
1402-count-square-submatrices-with-all-ones
1407-group-the-people-given-the-group-size-they-belong-to
1424-maximum-candies-you-can-get-from-boxes
1426-find-n-unique-integers-sum-up-to-zero
1458-max-dot-product-of-two-subsequences
1470-shuffle-the-array
1548-check-if-all-1s-are-at-least-length-k-places-away
1586-longest-subarray-of-1s-after-deleting-one-element
1590-make-sum-divisible-by-p
1635-number-of-good-pairs
1752-check-if-array-is-sorted-and-rotated
1760-check-array-formation-through-concatenation
1834-minimum-number-of-people-to-teach
1929-concatenation-of-array
1970-last-day-where-you-can-still-cross
1975-maximum-matrix-sum
1979-find-greatest-common-divisor-of-array
2023-design-movie-rental-system
2054-two-best-non-overlapping-events
2110-number-of-smooth-descent-periods-of-a-stock
2137-final-value-of-variable-after-performing-operations
2141-maximum-running-time-of-n-computers
2170-count-number-of-maximum-bitwise-or-subsets
2265-partition-array-according-to-given-pivot
2271-rearrange-array-elements-by-sign
2308-divide-array-into-equal-pairs
2316-count-hills-and-valleys-in-an-array
2343-count-unguarded-cells-in-the-grid
2402-meeting-rooms-iii
2435-paths-in-matrix-whose-sum-is-divisible-by-k
2478-longest-nice-subarray
2483-task-scheduler-ii
2498-smallest-subarrays-with-maximum-bitwise-or
2503-longest-subarray-with-maximum-bitwise-and
2529-range-product-queries-of-powers
2614-maximum-count-of-positive-integer-and-negative-integer
2625-increment-submatrices-by-one
2689-rearranging-fruits
2707-merge-two-2d-arrays-by-summing-values
2724-convert-an-array-into-a-2d-array-with-conditions
2755-extra-characters-in-a-string
2766-find-the-prefix-common-array-of-two-arrays
2888-minimum-index-of-a-valid-split
3075-maximize-happiness-of-selected-children
3190-find-minimum-operations-to-make-all-elements-divisible-by-three
3194-find-words-containing-character
3227-find-missing-and-repeated-values
3321-type-of-triangle
3430-count-days-without-meetings
3432-count-partitions-with-even-sum-difference
3433-count-mentions-per-user
3459-find-the-minimum-area-to-cover-all-ones-ii
3461-find-the-minimum-area-to-cover-all-ones-i
3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i
3501-delete-nodes-from-linked-list-present-in-array
3512-minimum-operations-to-make-array-sum-divisible-by-k
3515-find-if-digit-game-can-be-won
3577-count-the-number-of-computer-unlocking-permutations
3581-the-two-sneaky-numbers-of-digitville
3583-count-special-triplets
3606-coupon-code-validator
3610-find-x-sum-of-all-k-long-subarrays-i
3623-count-number-of-trapezoids-i
3625-count-number-of-trapezoids-ii
3648-find-the-maximum-number-of-fruits-collected
3652-best-time-to-buy-and-sell-stock-using-strategy
3789-maximize-subarrays-after-removing-one-conflicting-pair
3819-count-covered-buildings
3827-implement-router
3863-power-grid-maintenance

Hash Table

0001-two-sum
0036-valid-sudoku
0037-sudoku-solver
0041-first-missing-positive
0169-majority-element
0217-contains-duplicate
0219-contains-duplicate-ii
0242-valid-anagram
0268-missing-number
0347-top-k-frequent-elements
0349-intersection-of-two-arrays
0448-find-all-numbers-disappeared-in-an-array
0645-set-mismatch
0756-pyramid-transition-matrix
0833-bus-routes
0840-magic-squares-in-grid
0865-smallest-subtree-with-all-the-deepest-nodes
0900-reordered-power-of-2
0920-uncommon-words-from-two-sentences
0961-n-repeated-element-in-size-2n-array
1218-lowest-common-ancestor-of-deepest-leaves
1249-snapshot-array
1267-remove-zero-sum-consecutive-nodes-from-linked-list
1407-group-the-people-given-the-group-size-they-belong-to
1460-number-of-substrings-containing-all-three-characters
1590-make-sum-divisible-by-p
1635-number-of-good-pairs
1760-check-array-formation-through-concatenation
1777-determine-if-two-strings-are-close
1834-minimum-number-of-people-to-teach
2023-design-movie-rental-system
2308-divide-array-into-equal-pairs
2402-meeting-rooms-iii
2483-task-scheduler-ii
2689-rearranging-fruits
2707-merge-two-2d-arrays-by-summing-values
2724-convert-an-array-into-a-2d-array-with-conditions
2755-extra-characters-in-a-string
2766-find-the-prefix-common-array-of-two-arrays
2888-minimum-index-of-a-valid-split
3227-find-missing-and-repeated-values
3501-delete-nodes-from-linked-list-present-in-array
3581-the-two-sneaky-numbers-of-digitville
3583-count-special-triplets
3606-coupon-code-validator
3610-find-x-sum-of-all-k-long-subarrays-i
3623-count-number-of-trapezoids-i
3625-count-number-of-trapezoids-ii
3819-count-covered-buildings
3827-implement-router
3863-power-grid-maintenance

Two Pointers

0026-remove-duplicates-from-sorted-array
0027-remove-element
0075-sort-colors
0088-merge-sorted-array
0125-valid-palindrome
0167-two-sum-ii-input-array-is-sorted
0189-rotate-array
0283-move-zeroes
0287-find-the-duplicate-number
0349-intersection-of-two-arrays
0455-assign-cookies
0611-valid-triangle-number
0680-valid-palindrome-ii
0941-sort-array-by-parity
1002-maximum-width-ramp
1019-squares-of-a-sorted-array
1168-duplicate-zeros
2128-reverse-prefix-of-word
2265-partition-array-according-to-given-pivot
2271-rearrange-array-elements-by-sign
2707-merge-two-2d-arrays-by-summing-values
3683-find-the-lexicographically-largest-string-from-the-box-i

Number Theory

1979-find-greatest-common-divisor-of-array
2610-closest-prime-numbers-in-range
2903-insert-greatest-common-divisors-in-linked-list
3768-check-if-digits-are-equal-in-string-after-operations-i

String

0008-string-to-integer-atoi
0043-multiply-strings
0125-valid-palindrome
0242-valid-anagram
0474-ones-and-zeroes
0680-valid-palindrome-ii
0712-minimum-ascii-delete-sum-for-two-strings
0756-pyramid-transition-matrix
0812-rotate-string
0920-uncommon-words-from-two-sentences
0944-delete-columns-to-make-sorted
0955-delete-columns-to-make-sorted-ii
0960-delete-columns-to-make-sorted-iii
1058-lexicographically-smallest-equivalent-string
1197-parsing-a-boolean-expression
1205-defanging-an-ip-address
1304-longest-happy-string
1460-number-of-substrings-containing-all-three-characters
1667-find-kth-bit-in-nth-binary-string
1777-determine-if-two-strings-are-close
2128-reverse-prefix-of-word
2137-final-value-of-variable-after-performing-operations
2147-number-of-ways-to-divide-a-long-corridor
2211-count-collisions-on-a-road
2483-minimum-penalty-for-a-shop
2755-extra-characters-in-a-string
3194-find-words-containing-character
3312-number-of-changing-keys
3379-score-of-a-string
3606-coupon-code-validator
3683-find-the-lexicographically-largest-string-from-the-box-i
3768-check-if-digits-are-equal-in-string-after-operations-i

Simulation

0043-multiply-strings
1642-water-bottles
1667-find-kth-bit-in-nth-binary-string
1929-concatenation-of-array
2137-final-value-of-variable-after-performing-operations
2211-count-collisions-on-a-road
2265-partition-array-according-to-given-pivot
2271-rearrange-array-elements-by-sign
2288-count-operations-to-obtain-zero
2343-count-unguarded-cells-in-the-grid
2402-meeting-rooms-iii
2408-number-of-people-aware-of-a-secret
2483-task-scheduler-ii
3336-water-bottles-ii
3433-count-mentions-per-user
3768-check-if-digits-are-equal-in-string-after-operations-i

Combinatorics

3201-distribute-candies-among-children-ii
3577-count-the-number-of-computer-unlocking-permutations
3768-check-if-digits-are-equal-in-string-after-operations-i

Backtracking

0037-sudoku-solver
0756-pyramid-transition-matrix
2170-count-number-of-maximum-bitwise-or-subsets

Bit Manipulation

0136-single-number
0231-power-of-two
0268-missing-number
0287-find-the-duplicate-number
0645-set-mismatch
0756-pyramid-transition-matrix
0934-bitwise-ors-of-subarrays
2170-count-number-of-maximum-bitwise-or-subsets
2308-divide-array-into-equal-pairs
2478-longest-nice-subarray
2498-smallest-subarrays-with-maximum-bitwise-or
2503-longest-subarray-with-maximum-bitwise-and
2529-range-product-queries-of-powers
2766-find-the-prefix-common-array-of-two-arrays
3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i
3676-smallest-number-with-all-set-bits

Enumeration

0900-reordered-power-of-2
1925-count-square-sum-triples
2170-count-number-of-maximum-bitwise-or-subsets
3201-distribute-candies-among-children-ii
3459-find-the-minimum-area-to-cover-all-ones-ii
3683-find-the-lexicographically-largest-string-from-the-box-i
3789-maximize-subarrays-after-removing-one-conflicting-pair

Greedy

0135-candy
0455-assign-cookies
0611-valid-triangle-number
0670-maximum-swap
0680-valid-palindrome-ii
0759-set-intersection-size-at-least-two
0955-delete-columns-to-make-sorted-ii
1018-largest-perimeter-triangle
1262-greatest-sum-divisible-by-three
1304-longest-happy-string
1407-group-the-people-given-the-group-size-they-belong-to
1834-minimum-number-of-people-to-teach
1975-maximum-matrix-sum
2141-maximum-running-time-of-n-computers
2689-rearranging-fruits
3075-maximize-happiness-of-selected-children

Counting

0169-majority-element
0347-top-k-frequent-elements
0900-reordered-power-of-2
0920-uncommon-words-from-two-sentences
1635-number-of-good-pairs
1777-determine-if-two-strings-are-close
2308-divide-array-into-equal-pairs
2614-maximum-count-of-positive-integer-and-negative-integer
3583-count-special-triplets

Matrix

0036-valid-sudoku
0037-sudoku-solver
0085-maximal-rectangle
0840-magic-squares-in-grid
1351-count-negative-numbers-in-a-sorted-matrix
1402-count-square-submatrices-with-all-ones
1970-last-day-where-you-can-still-cross
1975-maximum-matrix-sum
2343-count-unguarded-cells-in-the-grid
2435-paths-in-matrix-whose-sum-is-divisible-by-k
2625-increment-submatrices-by-one
3227-find-missing-and-repeated-values
3459-find-the-minimum-area-to-cover-all-ones-ii
3461-find-the-minimum-area-to-cover-all-ones-i
3648-find-the-maximum-number-of-fruits-collected

Binary Search

0167-two-sum-ii-input-array-is-sorted
0268-missing-number
0278-first-bad-version
0287-find-the-duplicate-number
0349-intersection-of-two-arrays
0611-valid-triangle-number
0745-find-smallest-letter-greater-than-target
1249-snapshot-array
1335-maximum-candies-allocated-to-k-children
1351-count-negative-numbers-in-a-sorted-matrix
1970-last-day-where-you-can-still-cross
2054-two-best-non-overlapping-events
2141-maximum-running-time-of-n-computers
2498-smallest-subarrays-with-maximum-bitwise-or
2614-maximum-count-of-positive-integer-and-negative-integer
3827-implement-router

Sorting

0075-sort-colors
0088-merge-sorted-array
0169-majority-element
0217-contains-duplicate
0242-valid-anagram
0268-missing-number
0347-top-k-frequent-elements
0349-intersection-of-two-arrays
0455-assign-cookies
0611-valid-triangle-number
0645-set-mismatch
0759-set-intersection-size-at-least-two
0900-reordered-power-of-2
0941-sort-array-by-parity
1018-largest-perimeter-triangle
1019-squares-of-a-sorted-array
1262-greatest-sum-divisible-by-three
1777-determine-if-two-strings-are-close
2054-two-best-non-overlapping-events
2092-find-all-people-with-secret
2141-maximum-running-time-of-n-computers
2402-meeting-rooms-iii
2689-rearranging-fruits
2888-minimum-index-of-a-valid-split
3075-maximize-happiness-of-selected-children
3321-type-of-triangle
3430-count-days-without-meetings
3433-count-mentions-per-user
3606-coupon-code-validator
3819-count-covered-buildings

Stack

0085-maximal-rectangle
1002-maximum-width-ramp
1197-parsing-a-boolean-expression
2128-reverse-prefix-of-word
2211-count-collisions-on-a-road

Monotonic Stack

0085-maximal-rectangle
1002-maximum-width-ramp

Sliding Window

0219-contains-duplicate-ii
1460-number-of-substrings-containing-all-three-characters
1586-longest-subarray-of-1s-after-deleting-one-element
2478-longest-nice-subarray
2498-smallest-subarrays-with-maximum-bitwise-or
3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i
3610-find-x-sum-of-all-k-long-subarrays-i
3652-best-time-to-buy-and-sell-stock-using-strategy

Heap (Priority Queue)

0347-top-k-frequent-elements
1304-longest-happy-string
2023-design-movie-rental-system
2054-two-best-non-overlapping-events
2402-meeting-rooms-iii
3610-find-x-sum-of-all-k-long-subarrays-i
3863-power-grid-maintenance

Queue

2408-number-of-people-aware-of-a-secret
3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i
3827-implement-router

Prefix Sum

1590-make-sum-divisible-by-p
2483-minimum-penalty-for-a-shop
2529-range-product-queries-of-powers
2625-increment-submatrices-by-one
3432-count-partitions-with-even-sum-difference
3475-minimum-operations-to-make-binary-array-elements-equal-to-one-i
3652-best-time-to-buy-and-sell-stock-using-strategy
3789-maximize-subarrays-after-removing-one-conflicting-pair

Interactive

0278-first-bad-version

String Matching

0812-rotate-string

Tree

0865-smallest-subtree-with-all-the-deepest-nodes
1161-maximum-level-sum-of-a-binary-tree
1218-lowest-common-ancestor-of-deepest-leaves
1339-maximum-product-of-splitted-binary-tree
2872-maximum-number-of-k-divisible-components

Depth-First Search

0865-smallest-subtree-with-all-the-deepest-nodes
1161-maximum-level-sum-of-a-binary-tree
1218-lowest-common-ancestor-of-deepest-leaves
1339-maximum-product-of-splitted-binary-tree
1970-last-day-where-you-can-still-cross
2092-find-all-people-with-secret
2872-maximum-number-of-k-divisible-components
3863-power-grid-maintenance

Breadth-First Search

0833-bus-routes
0865-smallest-subtree-with-all-the-deepest-nodes
1161-maximum-level-sum-of-a-binary-tree
1218-lowest-common-ancestor-of-deepest-leaves
1424-maximum-candies-you-can-get-from-boxes
1970-last-day-where-you-can-still-cross
2092-find-all-people-with-secret
3863-power-grid-maintenance

Binary Tree

0865-smallest-subtree-with-all-the-deepest-nodes
1161-maximum-level-sum-of-a-binary-tree
1218-lowest-common-ancestor-of-deepest-leaves
1339-maximum-product-of-splitted-binary-tree

Design

1249-snapshot-array
2023-design-movie-rental-system
3827-implement-router

Dynamic Programming

0085-maximal-rectangle
0120-triangle
0121-best-time-to-buy-and-sell-stock
0474-ones-and-zeroes
0509-fibonacci-number
0712-minimum-ascii-delete-sum-for-two-strings
0934-bitwise-ors-of-subarrays
0960-delete-columns-to-make-sorted-iii
1262-greatest-sum-divisible-by-three
1402-count-square-submatrices-with-all-ones
1411-number-of-ways-to-paint-n-3-grid
1458-max-dot-product-of-two-subsequences
1586-longest-subarray-of-1s-after-deleting-one-element
2028-the-earliest-and-latest-rounds-where-players-compete
2054-two-best-non-overlapping-events
2110-number-of-smooth-descent-periods-of-a-stock
2147-number-of-ways-to-divide-a-long-corridor
2408-number-of-people-aware-of-a-secret
2435-paths-in-matrix-whose-sum-is-divisible-by-k
2755-extra-characters-in-a-string
2882-ways-to-express-an-integer-as-sum-of-powers
3648-find-the-maximum-number-of-fruits-collected

Trie

2755-extra-characters-in-a-string

Graph

1424-maximum-candies-you-can-get-from-boxes
2092-find-all-people-with-secret
3863-power-grid-maintenance

Union Find

1058-lexicographically-smallest-equivalent-string
1970-last-day-where-you-can-still-cross
2092-find-all-people-with-secret
3863-power-grid-maintenance

Memoization

0509-fibonacci-number
2028-the-earliest-and-latest-rounds-where-players-compete

Segment Tree

3789-maximize-subarrays-after-removing-one-conflicting-pair

Brainteaser

2503-longest-subarray-with-maximum-bitwise-and
3577-count-the-number-of-computer-unlocking-permutations

Divide and Conquer

0169-majority-element
0347-top-k-frequent-elements

Bucket Sort

0347-top-k-frequent-elements

Quickselect

0347-top-k-frequent-elements

Ordered Set

2023-design-movie-rental-system
3827-implement-router
3863-power-grid-maintenance

Geometry

3623-count-number-of-trapezoids-i
3625-count-number-of-trapezoids-ii

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages