Skip to content

πŸ₯‡Beginner's guide to DSA, including problems and solutions from competitive coding websites like LeetCode, CodeChef, Codeforces, etc. :octocat:

License

Notifications You must be signed in to change notification settings

Nimesh-Srivastava/DSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DSA learning and practice

LanguageΒ Β Β Β Β Β  LicenseΒ Β Β Β Β Β  UpdateΒ Β Β Β Β Β  ProblemsΒ Β 

Please use the discussions tab for any queries.

Use the index given below to search for problems and solutions. Problems are arranged in non-descending order of difficulty.

πŸ’’ Index

Theory

Data Structures

Algorithms

Extra



πŸ’’ Introduction

What is data structure(DS)?
  • A way of organizing data, so it can be used effectively
Why do we use them?
  • To create fast and powerful algorithms
  • To make code easier for understanding

What is abstract data type(ADT)?
  • An abstraction of a DS which provides only an interface. An interface is not specific to any programming language, instead, it's completely free of all of them.
  • ADTs are implemented using data structures

Some examples are :

# ADT Implementation(DS)
1 Lists Dynamic Array
Linked List
2 Queue Array based queue
Stack based queue
Linked List based queue
3 Maps Hash table
Tree



πŸ’’ The Big-O Notation

What is Big-O and why do we use it?

Big-O notation helps us identify the time and space complexity of an algorithm. There are many other notations as well, like, Big-Theta, or, Big-Omega, but we use Big-O because it deals with the worst case scenario of an algorithm, i.e., when the size of input tends to infinity.

Size of input is denoted by 'n'.

Ascending order of complexity
# Notation Name Example (time)
1 O (1) Constant Accessing an array
2 O (log n) Logarithmic Binary search
3 O (n) Linear Traversing an array
4 O (n log n) Linearithmic Merge sort
5 O (n^2) Quadratic 2 Nested loops
6 O (n^3) Cubic 3 Nested loops
...
7 O (nm) O of n m Iterating over a matrix of (n X m)
...
8 O (b^n) Exponential All subsets of a set -> O (2^n)
9 O (n!) Factorial All permutations of a string


πŸ’’ Arrays

Property
  • Each and every element is indexable(can be referenced with a number) from range 0 to n-1. 'n' is the size of array.

Used
  • for sorting
  • to access sequential data
  • as buffer by I/O routines
  • as lookup / inverse lookup tables
  • to return multiple values from a function
  • as cache in dynamic programming

Types of arrays
  • Static : fixed length
  • Dynamic : variable length; implemented using static array; when size capacity is reached, a new static array of double size is created and elements are copied.

PROBLEMS on arrays

Key : 🟒 Easy, 🟑 Medium, πŸ”΄ Hard


CountΒ 

ID Title Solution Time Space Difficulty Tags Note
1929 Concatenation of array C,
C++
🟒
1920 Build array from permutation C,
C++
🟒
0989 Add to array-form of integer C++ 🟒
1480 Running sum of 1D array C,
C++
🟒
1672 Richest customer wealth C++ 🟒 matrix
0566 Reshape the matrix C++ 🟒
0867 Transpose matrix C++ 🟒
1470 Shuffle the array C++ 🟒
0532 K-diff pairs in an array C++ 🟒
1200 Minimum absolute difference C++ 🟒
1217 Minimum cost to move chips to the same position C++ 🟒
1431 Kids with greatest number of candies C++ 🟒
1512 Number of good pairs C++ 🟒 bruteforce,
hash table
1365 How many numbers are smaller than current number C++ 🟒 frequency array
1413 Minimum value to get positive step by step sum C++ 🟒
0448 Find all numbers disappeared in an array C++ 🟒
0941 Valid mountain array C++ 🟒
0706 Design hashmap C++ 🟒
1528 Shuffle string C++ 🟒
0219 Contains duplicate II C++ 🟒
1491 Average salary excluding the minimum and maximum salary C++ 🟒
0136 Single number C++ 🟒
1332 Remove palindromic subsequences C++ 🟒
1720 Decode XORed array C++ 🟒 XOR property
0169 Majority element C++ 🟒 Moore's Voting algo
1313 Decompress run-length encoded list C++ O(n^2) 🟒
1389 Create taget array in the given order C++ O(n) 🟒
1773 Count items maching a rule C++ 🟒
1588 Sum of all odd length arrays C++ 🟒
1656 Design an ordered stream C++ 🟒
1662 Check if two atring arrays are equivalent C++ 🟒
1684 Count the number of consistent strings C++ 🟒
1913 Maximum product difference between two pairs C++ O(nlogn),
O(n)
🟒
1816 Truncate sentence C++ 🟒
1979 Find greatest common divisor of array C++ 🟒
1629 Slowest key C++ 🟒
0953 Verifying an alien dictionary C++ 🟒
0217 Contains duplicate C++ O(n) 🟒
0001 Two Sum C++ O(n) O(1) 🟒 hash table
0026 Remove duplicates from sorted array C++ 🟒
0888 Fair candy swap C++ 🟒
0350 Intersection of two arrays II C++ 🟒
0027 Remove Element C++ 🟒
0744 Find smallest letter greater than target C++ O(logn) 🟒
0053 Maximum subarray C++ 🟒 Kadane's algorithm
0066 Plus One C++ 🟒
0088 Merge sorted array C++ 🟒
0645 Set mismatch C++ 🟒
1710 Maximum units on a truck C++ 🟒
0414 Third maximum number C++ 🟒
1909 Remove one element to make array strictly increasing C++ 🟒
1423 Maximum points you can obtain from cards C++ 🟑
0334 Increasing triplet subsequence C++ 🟑
0075 Sort colors C++ 🟑
0904 Fruits into baskets C++ 🟑
0658 Find k closest elements C++ 🟑 Binary Search
0665 Non-decreasing array C++ 🟑
0284 Peeking Iterator C++ 🟑
0923 3Sum with multiplicity C++ 🟑
0134 Gas station C++ 🟑
0054 Spiral matrix C++ 🟑
0525 Contiguous array C++ 🟑
0849 Maximize distant to closest person C++ 🟑
0973 K closest points to origin C++ 🟑
0560 Subarray sum equals k C++ 🟑
0059 Spiral matrix II C++ 🟑
0056 Merge intervals C++ 🟑
0435 Non-overlaping intervals C++ 🟑
0442 Find all duplicates in an array C++ 🟑 sort,
hash maps,
logic
0540 Single element in a sorted array C++ 🟑 Binary search,
XOR sum
1814 Count nice pairs C++ 🟑
0215 K-th largest element in an array C++ 🟑
0015 3Sum C++ 🟑 Two pointer
0018 4Sum C++ 🟑
0454 4Sum II C++ 🟑
0039 Combination sum C++ 🟑
0048 Rotate image C++ 🟑
1094 Car pooling C++ 🟑
0299 Bulls and cows C++ 🟑 Hash table
1052 Grumpty bookstore owner C++ 🟑
0040 Combination sum II C++ 🟑
0667 Beautiful arrangement II C++ 🟑
0036 Valid sudoku C++ 🟑 hash maps, or
2D array
0011 Container with most water C++ 🟑
0204 Count primes C++ 🟑
0307 Range sum query mutable C++ 🟑
0462 Minimum moves to equal array elements II C++ 🟑
0238 Product of array except self C++ 🟑
0128 Longest consecutive sequence C++ 🟑
0950 Reveal cards in increasing order C++ 🟑
1343 Number of sub-arrays of size k and average greater than or equal to threshold C++ 🟑
0078 Subsets C++ 🟑
0047 Permutations II C++ 🟑
0347 Top k frequent elements C++ 🟑
1010 Pairs of songs with total durations divisible by 60 C++ 🟑
1248 Count number of nice subarrays C++ 🟑
0523 Continuous subarray sum C++ 🟑
0031 Next permutation C++ 🟑
0406 Queue reconstruction by height C++ 🟑
0287 Find the duplicate number C++ 🟑
0721 Accounts merge C++ 🟑 Union find
0154 Find minimum in rotated sorted array II C++ πŸ”΄
0952 Largest componenet size by common factor C++ πŸ”΄
0239 Sliding window maximum C++ πŸ”΄
0004 Median of two sorted arrays C++ πŸ”΄ binary search,
careful of bounds
0992 Subarrays with k different integers C++ πŸ”΄
1074 Number of submatrices that sum to target C++ O(n2*m) πŸ”΄ prefix sum


πŸ’’ Linked Lists

What is it?
  • A sequential list of data holding nodes that point to other nodes.

Uses
  • Stack, queue, list, circular list implementation
  • Adjancy list for graphs
  • Separate chaining to deal with hashing collisions

Properties
  • Node : contains data and pointer
  • Pointer : reference to another node
  • Head : first node in the list
  • Tail : last node in the list

Types
  • Singly linked list : reference to next node only
  • Doubly linked list : reference to next and previous nodes
Type Pros Cons
Singly Less memory usage,
Simple implementation
Difficult to access previous element
Doubly Backward traversal possible Takes much more memory
(Pointers can take lot of memory)

Complexity Analysis
Action Singly LL Doubly LL
Search O (n) O (n)
Insert at head O (1) O (1)
Insert at tail O (1) O (1)
Remove at head O (1) O (1)
Remove at tail O (n) O (1)
Remove in between O (n) O (n)

PROBLEMS on linked lists

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
1290 Convert binary number in a linked list to integer C++ 🟒 Bruteforce
0876 Middle of the linked list C++ 🟒 Bruteforce
0237 Delete node in a linked list C++ 🟒
0206 Reverse linked list C++ 🟒
0705 Design HashSet C++ 🟒
0021 Merge two sorted lists C++ 🟒 Merge sort
0083 Remove duplicates from sorted list C++ 🟒
0160 Intersection of two linked lists C++ 🟒
0234 Palindrome linked list C++ O(n) O(1) 🟒 List reversal
0141 Linked list cycle C++ 🟒
0203 Remove linked list elements C++ 🟒
0092 Reverse linked list II C++ 🟑
0142 Linked list cycle II C++ 🟑
0143 Reorder list C++ 🟑
0148 Sort list C++ 🟑
0086 Partition list C++ 🟑
0114 Flatten binary tree to linked list C++ 🟑 Morris traversal
1669 Merge in between linked lists C++ 🟑
0019 Remove n-th node from end of list C++ 🟑
1721 Swapping nodes in a linked list C++ 🟑
1019 Next greater node in linked list C++ O(n) 🟑 Typical problem,
Important
0328 Odd even linked list C++ O(n) O(1) 🟑
0002 Add two numbers C++ 🟑
0445 Add two numbers II C++ 🟑
0082 Remove duplicates from sorted list II C++ 🟑 Two pointer
0024 Swap nodes in pairs C++ 🟑
0707 Design linked list C++ 🟑
0138 Copy list with random pointer C++ 🟑
0382 Linked list random node C++ 🟑 Reservoir sampling
0025 Reverse nodes in k-group C++ πŸ”΄

  • Doubly linked list -
ID Title Solution Time Space Difficulty Tags Note
1472 Design browser history C++ 🟑 Create list structure
0430 Flatten a multilevel doubly linked list C++ O(n) O(n) 🟑 Recursion


πŸ’’ Stacks

Stacks as ADT

We only care about the features and operations of stacks. We don't care about the implementation details. Therefore, I am going to define stack only as mathematical model.

Definition

A list with restriction of insertion and deletion from one end only.

Property

Elements are inserted and removed from the same end, also called, the top of stack. This is not just a property, but a constraint of stack. Hence, stack is called, LAST-IN-FIRST-OUT, or, LIFO, collection of items.

Operations
  • Push( ) : for insertion of an element
  • Pop( ) : for deletion of an element

Apart from the above mentioned fundamental operations, there can be other operations as well, like :-

  • Top( ) : return the top element of stack
  • IsEmpty( ) : return TRUE if stack is empty, FALSE if not
Complexity Analysis

All opertaions mentioned above are performed in constant, or, O( 1 ) time.

Overflow condition : O( n ), a larger array is created and all elements are copied. This only happens in array implementation of stack.

Uses
  • Function calls / Recursion in dynamic memory allocation
  • implement Undo operation
  • balance of brackets by a compiler
Implementation of stacks

Stacks can be implemeted in 2 ways :-

  • Stacks using arrays :

      // declaration of array that will act as stack
      int A[n]
      
      // pointer to the top of stack
      top = -1
      
      Push(x){
          top = top + 1
          A[top] = x
      }
      
      Pop(){
          top = top - 1
      }
      
      Top(){
          return A[top]
      }
      
      IsEmpty(){
          if (top == -1)
              return TRUE
          else
              return FALSE
      }
    
  • Stacks using linked lists :

      // structure for linked list
      struct Node {
          int data
          struct Node* link
      }
      
      Push(x) {
          temp->data = x
          temp->link = top
          top = temp
      }
      
      Pop() {
          temp = top
          top = top->link
          free(temp)
      }
    
PROBLEMS on Stacks

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0020 Valid parantheses C++ 🟒
1614 Maximum nesting depth of the parantheses C++ 🟒
1021 Remove outermost parantheses C++ 🟒
1475 Final prices with a special discount in shop C++ 🟒
0232 Implement queue using stacks C++ 🟒
0155 Min stack C++ 🟒
0071 Simplify path C++ 🟑
1249 Minimum remove to make valid parantheses C++ 🟑
0739 Daily temperatures C++ 🟑
0227 Basic calculator II C++ 🟑
0084 Largest rectangle in histogram C++ πŸ”΄


πŸ’’ Queues

PROBLEMS on queues

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0225 Implement stack using queues C++ 🟒
1823 Find the winner of the circular game C++ 🟑


πŸ’’ Heaps

PROBLEMS on heaps

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
1354 Construct target array with multiple sums C++ πŸ”΄
1383 Maximum performance of a team C++ πŸ”΄


πŸ’’ Trees

PROBLEMS on trees

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0144 Binary tree preorder traversal C++ 🟒
0094 Binary tree inorder traversal C++ 🟒
0145 Binary tree postorder traversal C++ 🟒
0104 Maximum depth of binary tree C++ 🟒
0543 Diameter of a binary tree C++ 🟒
0563 Binary tree tilt C++ 🟒
0700 Search in a binary tree C++ 🟒
0993 Cousins in binary tree C++ 🟒
0101 Symmetric tree C++ 🟒
0617 Merge two binary trees C++ 🟒
0404 Sum of left leaves C++ 🟒
0112 Path sum C++ 🟒
0637 Average of levels in binary tree C++ 🟒
0589 N-ary tree preorder traversal C++ 🟒
0572 Subtree of another tree C++ 🟒
1022 Sum of root to leaf binary numbers C++ 🟒
0938 Range sum of BST C++ 🟒
0108 Convert sorted array to binary search tree C++ 🟒
0226 Invert binary tree C++ 🟒
0653 Two sum IV - Input is a BST C++ 🟒
0235 Lowest common ancestor of a binary search tree C++ 🟒
0331 Verify preorder serialization of a binary tree C++ 🟑
0102 Binary tree level order traversal C++ 🟑 queue
0222 Count complete tree nodes C++ 🟑 queue, bfs
1008 Construct binary search tree from preorder traversal C++ 🟑
0889 Construct binary tree from preorder and postorder traversal C++ 🟑
0105 Construct binary tree from preorder and inorder traversal C++ 🟑
0103 Binary tree zigzag level order traversal C++ 🟑
0106 Construct binary tree from inorder and postorder traversal C++ 🟑
0979 Distribute coins in binary tree C++ 🟑
0654 Maximum binary tree C++ 🟑
1519 Number of nodes in the sub-tree with the same label C++ 🟑
0623 Add one row to tree C++ 🟑
1305 All elements in two binary search trees C++ 🟑
0662 Maximum width of binary tree C++ 🟑
0687 Longest univalue path C++ 🟑
0129 Sum root to leaf numbers C++ 🟑
1104 Path in zigzag labled binary tree C++ 🟑
1372 Longest zigzag path in a binary tree C++ 🟑
0113 Path sum II C++ 🟑
0437 Path sum III C++ 🟑
1339 Maximum product of splitted binary tree C++ 🟑
0814 Binary tree pruning C++ 🟑
1448 Count good nodes in binary tree C++ 🟑
0894 All possible full binary trees C++ 🟑
0701 Insert into a binary search tree C++ 🟑
0098 Validate binary search tree C++ 🟑
0199 Binary tree right side view C++ 🟑 DFS,
BFS
0450 Delete node in a BST C++ 🟑
0230 Kth smallest element in a BST C++ 🟑
0173 Binary search tree iterator C++ 🟑
0236 Lowest common ancestor of a binary tree C++ 🟑
0297 Serialize and deserialize binary tree C++ 🟑
0968 Binary tree cameras C++ πŸ”΄
2246 Longest path with different adjacent characters C++ πŸ”΄


πŸ’’ Tries

PROBLEMS on tries

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0208 Implement trie C++ 🟑
0421 Maximum xor of two numbers in an array C++ 🟑
0211 Design add and search word data structure C++ 🟑
0745 Prefix and suffix search C++ 🟑
0336 Palindrome pairs C++ πŸ”΄


πŸ’’ Graphs

PROBLEMS on graphs

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0997 Find the town judge C++ 🟒
1557 Minimum number of vertices to reach all nodes C++ 🟑
0841 Keys and rooms C++ 🟑
0797 All paths from source to target C++ 🟑
0310 Minimum height trees C++ 🟑
2359 Find closest node to given two nodes C++ 🟑


πŸ’’ Dynamic Programming

PROBLEMS on dynamic programming

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0338 Counting bits C++ 🟒
0509 Fibonacci number C++ 🟒
0070 Climbing stairs C++ 🟒
1137 N-th tribonacci number C++ 🟒
0118 Pascal's triangle C++ 🟒
0119 Pascal's triangle II C++ 🟒
0746 Min cost climbing stairs C++ 🟒
1025 Divisor game C++ O(n^2)
O(1)
🟒 Trick solution
0121 Best time to buy and sell stock C++ 🟒
0392 Is subsequence C++ 🟒
0062 Unique paths C++ 🟑
0063 Unique paths II C++ 🟑
0799 Champagne tower C++ 🟑
0918 Maximum sum circular subarray C++ 🟑
0152 Maximum product subarray C++ 🟑
1567 Maximum length of subarray with positive product C++ 🟑
0764 Largest plus sign C++ 🟑
1014 Best sightseeing pair C++ 🟑
0122 Best time to buy ans sell stock II C++ 🟑
1143 Longest common subsequence C++ 🟑
0198 House robber C++ 🟑
0213 House robber II C++ 🟑
0740 Delete and earn C++ 🟑
0823 Binary trees with factors C++ 🟑
0055 Jump game C++ 🟑
0045 Jump game II C++ 🟑
0139 Word break C++ 🟑
1048 Longest string chain C++ 🟑
0309 Best time to buy and sell stock with cooldown C++ 🟑
0714 Best time to buy and sell stock with transaction fee C++ 🟑
0413 Arithmetic slices C++ 🟑
0091 Decode ways C++ 🟑
0264 Ugly number II C++ 🟑
0096 Unique binary search trees C++ 🟑
0120 Triangle C++ 🟑
0368 Largest divisible subset C++ 🟑
0931 Minimum falling path sum C++ 🟑
1314 Matrix block sum C++ 🟑
0304 Range sum query 2D - immutable C++ 🟑
0064 Minimum path sum C++ 🟑
0221 Minimal square C++ 🟑
0516 Longest palindromic subsequence C++ 🟑
0300 Longest increasing subsequence C++ 🟑
0376 Wiggle subsequence C++ 🟑
0322 Coin change C++ 🟑
0518 Coin change 2 C++ 🟑
0377 Combination sum IV C++ 🟑
0343 Integer break C++ 🟑 Mathematical,
DP
0279 Perfect squares C++ 🟑 Mathematical,
DP
0790 Domino and tromino tiling C++ 🟑
0416 Partition equal subset sum C++ 🟑
0576 Out of boundary paths C++ 🟑
1510 Stone game IV C++ πŸ”΄
0629 K inverse pairs array C++ πŸ”΄
0446 Arithmetic slices II - subsequence C++ πŸ”΄
0123 Best time to buy and sell stock III C++ πŸ”΄
0085 Maximal rectangle C++ πŸ”΄
0174 Dungeon game C++ πŸ”΄
0087 Scramble string C++ πŸ”΄
0072 Edit distance C++ πŸ”΄
0042 Trapping rain water C++ πŸ”΄ Microsoft
0312 Burst balloons C++ πŸ”΄


πŸ’’ Binary Search

PROBLEMS on binary search

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0704 Binary Search C++ 🟒
0278 First bad version C++ 🟒
0035 Search insert position C++ 🟒
0441 Arranging coins C++ 🟒
0875 Koko eating banans C++ 🟑
0162 Peak element C++ 🟑
0153 Find minimum in rotqted sorted array C++ 🟑
0034 Find first and last position of element in sorted array C++ 🟑
0033 Search in sorted array C++ 🟑
0074 Search a 2D matrix C++ 🟑
1237 Find positive integer solution for a given equation C++ 🟑
0240 Search a 2D matrix II C++ 🟑
1011 Capacity to ship packages within D days C++ 🟑
1901 Find a peak element II C++ 🟑
0668 Kth smallest number in multiplication table C++ πŸ”΄
0878 Nth magical number C++ πŸ”΄
0354 Russian doll envelopes C++ πŸ”΄


πŸ’’ Sliding Window

PROBLEMS on sliding window

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0438 Find all anagrams in a string C++ 🟑
0713 Subarray product less than k C++ 🟑
0209 Minimum size subarray sum C++ 🟑
1658 Minimum operations to reduce x to zero C++ 🟑


πŸ’’ Depth First Search

PROBLEMS on DFS

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0463 Island perimeter C++ 🟒 Bruteforce,
DFS
0733 Flood fill C++ 🟒
0079 Word search C++ 🟑 Optimised for space
0695 Max area of island C++ 🟑
0130 Surrounded regions C++ 🟑
0337 House robber III C++ 🟑
1306 Jump game III C++ 🟑
1319 Number of operations to make network connected C++ 🟑
1379 Find a corresponding node of a binary tree in a clone of that tree C++ 🟑
1291 Sequential digits C++ 🟑
0200 Number of islands C++ 🟑
0547 Number of provinces C++ 🟑
0980 Unique paths III C++ πŸ”΄


πŸ’’ Breadth First Search

PROBLEMS on BFS

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0994 Rotting oranges C++ 🟑
0116 Polpulating next right pointers in each node C++ 🟑
0542 01 matrix C++ 🟑
0117 Populating next right pointers in each node II C++ 🟑
1091 Shortest path in binary matrix C++ 🟑


πŸ’’ Strings

PROBLEMS on strings

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0389 Find the difference C++ 🟒
0242 Valid anagram C++ 🟒
0014 Longest common prefix C++ 🟒
0387 First unique character in a string C++ 🟒
0383 Ransom note C++ 🟒
0290 Word pattern C++ 🟒
0067 Add binary C++ 🟒
0520 Detect capital C++ 🟒
1446 Consecutive characters C++ 🟒
0680 Valid palindrome II C++ 🟒
0415 Add strings C++ 🟑
1328 Break a palindrome C++ 🟑
0409 Longest palindrome C++ 🟑
0394 Decode string C++ 🟑
0038 Count and say C++ 🟑
0093 Restore IP addresses C++ 🟑
0890 Find and replace pattern C++ 🟑
1663 Smallest string with a given numeric value C++ 🟑
0003 Longest substring without repeating characters C++ 🟑 sliding window
0567 Permutation in string C++ 🟑 sliding window
0005 Longest palindromic substring C++ 🟑
0451 Sort characters by frequency C++ 🟑
0151 Reverse words in a string C++ 🟑
1170 Compare strings by frequency of the smallest character C++ 🟑
0763 Partition labels C++ 🟑
0848 Shifting letters C++ 🟑
1358 Number of substrings containing all three characters C++ 🟑
0006 Zigzag conversion C++ 🟑
1456 Maximum number of vowels in a substring of a given length C++ 🟑
0008 String to integer (atoi) C++ 🟑
2038 Remove colored pieces if both neighbors are the same color C++ 🟑
0049 Group anagrams C++ 🟑
0916 Word subsets C++ 🟑 Hash maps
0792 Number of matching subsequences C++ 🟑
0043 Multiply strings C++ 🟑
0187 Repeated DNA sequences C++ 🟑
0899 Orderly queue C++ πŸ”΄
0076 Minimmum window substring C++ πŸ”΄
0212 Word Search C++ πŸ”΄ dfs
0010 Regular expression matching C++ πŸ”΄ Very hard,
dp & dfs
1044 Longest duplicate substring C++ πŸ”΄ Very hard,
rolling hash (sliding window)


πŸ’’ Two pointers

PROBLEMS on two pointers

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0977 Squares of a sorted array C++ O(n) 🟒
0283 Move zeroes C++ O(n) 🟒
0344 Reverse string C++ 🟒
0557 Reverse in a string III C++ O(n) 🟒
0167 Two sum II - input array is sorted C++ O(log n) 🟒
0189 Rotate array C++ 🟑
1679 Max number of K-Sum pairs C++ O(n log n) 🟑
0986 Interval list intersections C++ 🟑
0844 Backspace string compare C++ 🟑


πŸ’’ Bit manipulation

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0231 Power of two C++ O(n),
O(1)
🟒
0191 Number of 1 bits C++ 🟒
0190 Reverse bits C++ O(1) 🟒
0461 Hamming distance C++ 🟒
0268 Missing number C++ 🟒
0342 Power of four C++ 🟒
1342 Number of steps to reduce a number to zero C++ 🟒
1009 Complement of base 10 integer C++ 🟒 2 solutions
0260 Single number III C++ O(1) 🟑
0318 Maximum product of word lengths C++ 🟑
0029 Divide two integers C++ O(1) 🟑
1461 Check if a strin contains all binary codes of size k C++ 🟑
1178 Number of valid words for each puzzle C++ πŸ”΄


πŸ’’ Backtracking

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0077 Combinations C++ 🟑
0046 Permutations C++ 🟑
0784 Letter case permutation C++ 🟑
1286 Iterator for combination C++ 🟑
0131 Palindrome partitioning C++ 🟑
0090 Subsets II C++ 🟑
0017 Letter combinations of a phone number C++ 🟑
0022 Generate parantheses C++ 🟑
0051 N-Queens C++ πŸ”΄ Typical, Important
0037 Sudoku solver C++ πŸ”΄


πŸ’’ CodeChef DSA series

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
BUYPLSE Buy please C 🟒
ISBOTH Is both or not C 🟒
DIFACTRS Factors finding C 🟒
SECLAR Find second largest C 🟒
RNGEODD Range odd C 🟒
VALTRI Raju and his trip C 🟒
REVMEE Reverse me C,
C++
🟒
FINDMELI Find me C 🟒
TRIVALCH Valid triangle or not C,
C++
🟒
REVSTRPT Reverse star pattern C,
C++
🟒
ADDNATRL Add natural numbers C,
C++
🟒
SUMEVOD Sum is everywhere C 🟒
ANGTRICH Triangle with angle C 🟒
EXTRICHK Triangle everywhere C 🟒
SQUALPAT Alternative square pattern C 🟒
TEST Life, the universe, and everything C,
C++
🟒
FLOW007 Reverse the number C,
C++
🟒
LAPIN Lapindromes C,
C++
🟒
ZCO14003 Smart phone C,
C++
🟒
CARVANS Carvans C,
C++
🟒
FCTRL Factorial C,
C++
🟒
CONFLIP Coin flip C 🟒
LADDU Laddu C,
C++
🟒


πŸ’’ Miscellaneous problems

CountΒ 

LeetCode

ID Title Solution Time Space Difficulty Tags Note
1925 Count square sum triplets C++ 🟒
0007 Reverse integer C++ 🟒
0326 Power of three C++ 🟒
1323 Maximum 69 number C++ 🟒 greedy
0009 Palindrome Number C++ 🟒
0223 Rectangle area C++ O(1) 🟒 maths
0496 Next greater element I C++ 🟒 bruteforce,
stacks
0374 Guess number higher or lower C++ 🟒
0013 Roman to integer C++ 🟒
1523 Count odd numbers in an integer interval C++ 🟒
0201 Bitwise AND of number range C++ 🟑
0012 Integer to roman C++ 🟑
0858 Mirror reflection C++ 🟑
0380 Insert delete GetRandom O(1) C++ O(1) 🟑
1695 Maximum erasure value C++ 🟑
0460 LFU cache C++ πŸ”΄

Codeforces

ID Title Solution Time Space Difficulty Tags Note
1343A Candies C++ 🟒 bruteforce,
math
1525B Permutation Sort C++ 🟒 greedy
451A Game with Sticks C++ 🟒
1703A Yes or yes C++ 🟒 div4
1703B ICPC balloons C++ 🟒 div4
1703C Cypher C++ 🟒 div4


πŸ’’ Love Babbar 450

CountΒ 

ID Title Solution Time Space Difficulty Tags Note
0001 Reverse a string C++ 🟒
0002 Minimum and maximum of an array C++ 🟒


About

πŸ₯‡Beginner's guide to DSA, including problems and solutions from competitive coding websites like LeetCode, CodeChef, Codeforces, etc. :octocat:

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •