This repository contains solutions to the 450 Questions of the DSA Cracker Sheet curated by Love Babbar.
DSA-450 Sheet : Link
# | Problem | Solution | Time | Space |
---|---|---|---|---|
1 | Spiral traversal on a Matrix | Sol | O(r*c) | O(r*c) |
2 | Search an element in a matriix | Sol | O(logmn) | O(1) |
3 | Find median in a row wise sorted matrix | Sol | O(32*r*logc) | O(1) |
4 | Find row with maximum no. of 1's | Sol | O(n+m) | O(1) |
5 | Print elements in sorted order using row-column wise sorted matrix | Sol | O(n2logn) | O(n2) |
6 | Maximum size rectangle | - | - | |
7 | Find a specific pair in matrix | - | - | |
8 | Rotate matrix by 90 degrees | Sol | O(n2) | O(1) |
9 | Kth smallest element in a row-column wise sorted matrix | - | - | |
10 | Common elements in all rows of a given matrix | - | - |
# | Problem | Solution | Time | Space |
---|---|---|---|---|
1 | Find first and last positions of x in sorted array | Sol | O(logn) | O(1) |
2 | Find element equal to its index value | Sol | O(n) | O(1) |
3 | Search in rotated sorted array | Sol | O(logn) | O(1) |
4 | Count perfect squares less than n | Sol | O(sqrt(n)) | O(1) |
5 | Find middle of three numbers | Sol | O(1) | O(1) |
6 | Optimum location of point to minimize total distance | |||
7 | Find missing and repeating elements | Sol | O(n) | O(1) |
8 | Find majority element | Sol | O(n) | O(1) |
9 | Search in array where adjacent differ by atmost k | Sol | O(n) | O(1) |
10 | Find a pair with given difference | Sol | O(n*logn) | O(1) |
11 | Find all quadruples that sum up to given value | Sol | O(n3) | O(1) |
# | Problem | Solution | Time | Space |
---|---|---|---|---|
1 | Implement Stack | Sol | ||
2 | Implement Queue | |||
3 | Implement 2 stacks in one array | |||
4 | Find middle element of stack | |||
5 | Implement n stacks in one array | |||
6 | Check valid parenthesis | Sol | O(n) | O(n) |
7 | Reverse string using stack | Sol | O(n) | O(n) |
8 | Design a stack that supports getMin() in O(1) time and space | |||
9 | Find next greater element | Sol | O(n) | O(n) |
10 | The celebrity problem |
# | Problem | Solution | Time | Space |
---|---|---|---|---|
1 | Level Order Traversal | Sol | O(n) | O(n) |
2 | Reverse Level Order Traversal | Sol | O(n) | O(n) |
3 | Height of binary tree | Sol | O(n) | O(n) |
4 | Diameter of binary tree | Sol | O(n) | O(h) |
5 | Mirror tree of binary tree | Sol | O(n) | O(n) |
6 | Inorder traversal both iteratively & recursively | Sol | O(n) | O(n) |
7 | Preorder traversal both iteratively & recursively | Sol | O(n) | O(n) |
8 | Postorder traversal both iteratively & recursively | Sol | O(n) | O(n) |
9 | Left view of binary tree | Sol | O(n) | O(h) |
10 | Right view of binary tree | Sol | O(n) | O(h) |
11 | Top view of binary tree | |||
12 | Bottom view of binary tree | |||
13 | Zig-Zag level order traversal of binary tree | Sol | O(n) | O(n) |
14 | Check if given binary tree is balanced or not | Sol | O(n) | O(n) |
# | Problem | Solution | Time | Space |
---|---|---|---|---|
1 | Count set bits in n | Sol | O(logn) | O(1) |
2 | Find two non-repeating elements in an array of repeating elements | Sol | O(n) | O(1) |
3 | Count number of bits to be flipped to convert A to B | Sol | O(logn) | O(1) |
4 | Count total number of set bits from 1 to n | Sol | O(logn) | O(1) |
5 | Check if n is power of two | Sol | O(logn) | O(1) |
6 | Find position of only set sit | |||
7 | Copy set bits in a range | |||
8 | Divide two numbers without using *, / and % operator | |||
9 | Calculate square of number without using *, / and pow() | |||
10 | Power set |