Skip to content

Commit feca9f8

Browse files
Kunal KushwahaKunal Kushwaha
Kunal Kushwaha
authored and
Kunal Kushwaha
committed
stacks and queues questions
1 parent 58cb3e1 commit feca9f8

File tree

8 files changed

+416
-0
lines changed

8 files changed

+416
-0
lines changed

SYLLABUS.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Complete Java + DSA Bootcamp Syllabus
2+
3+
## NOTE
4+
- All topics will contain problems from LeetCode Easy to Hard, explained in an easy-to-understand manner.
5+
- Complete custom implementation of all Data Structures and Algorithms.
6+
7+
## Lectures
8+
- [Complete Git & GitHub Course](https://youtu.be/apGV9Kg7ics)
9+
- [Introduction to Programming](https://youtu.be/wn49bJOYAZM)
10+
- [Types of languages](https://youtu.be/wn49bJOYAZM?t=171)
11+
- [Memory management](https://youtu.be/wn49bJOYAZM?t=1488)
12+
- [Flow of the program](https://youtu.be/lhELGQAV4gg)
13+
- [Flowcharts](https://youtu.be/lhELGQAV4gg)
14+
- [Pseudocode](https://youtu.be/lhELGQAV4gg?t=715)
15+
- [Introduction to Java](https://youtu.be/4EP8YzcN0hQ)
16+
- [Introduction](https://youtu.be/4EP8YzcN0hQ)
17+
- [How it works](https://youtu.be/4EP8YzcN0hQ?t=93)
18+
- [Setup Installation](https://youtu.be/4EP8YzcN0hQ?t=1486)
19+
- [Input and Output in Java](https://youtu.be/TAtrPoaJ7gc)
20+
- [Conditionals & Loops in Java](https://youtu.be/ldYLYRNaucM?t=88)
21+
- [if-else](https://youtu.be/ldYLYRNaucM?t=88)
22+
- [loops](https://youtu.be/ldYLYRNaucM?t=440)
23+
- [Switch statements](https://youtu.be/mA23x39DjbI)
24+
- [Data-types](https://youtu.be/TAtrPoaJ7gc?t=2800)
25+
- [Coding best practices](https://youtu.be/waGfV-IoOt8)
26+
- [Functions](https://youtu.be/vvanI8NRlSI)
27+
- [Introduction](https://youtu.be/vvanI8NRlSI)
28+
- [Scoping in Java](https://youtu.be/vvanI8NRlSI?t=2801)
29+
- [Shadowing](https://youtu.be/vvanI8NRlSI?t=3584)
30+
- [Variable Length Arguments](https://youtu.be/vvanI8NRlSI?t=4013)
31+
- [Overloading](https://youtu.be/vvanI8NRlSI?t=4327)
32+
- [Arrays](https://youtu.be/n60Dn0UsbEk)
33+
- [Introduction](https://youtu.be/n60Dn0UsbEk)
34+
- [Memory management](https://youtu.be/n60Dn0UsbEk?t=632)
35+
- [Input and Output](https://youtu.be/n60Dn0UsbEk?t=1675)
36+
- [ArrayList Introduction](https://youtu.be/n60Dn0UsbEk?t=4868)
37+
- Searching
38+
- [Linear Search](https://youtu.be/_HRA37X8N_Q)
39+
- [Binary Search](https://youtu.be/f6UU7V3szVw)
40+
- [Modified Binary Search](https://youtu.be/f6UU7V3szVw?t=2508)
41+
- [Binary Search on 2D Arrays](https://www.youtube.com/watch?v=enI_KyGLYPo)
42+
- Sorting
43+
- [Insertion Sort](https://youtu.be/By_5-RRqVeE)
44+
- [Selection Sort](https://youtu.be/Nd4SCCIHFWk)
45+
- [Bubble Sort](https://youtu.be/F5MZyqRp_IM)
46+
- [Cyclic Sort](https://youtu.be/JfinxytTYFQ)
47+
- [Pattern questions](https://youtu.be/lsOOs5J8ycw)
48+
- [Strings](https://www.youtube.com/watch?v=zL1DPZ0Ovlo)
49+
- [Introduction](https://www.youtube.com/watch?v=zL1DPZ0Ovlo)
50+
- [How Strings work](https://youtu.be/zL1DPZ0Ovlo?t=216)
51+
- [Comparison of methods](https://youtu.be/zL1DPZ0Ovlo?t=977)
52+
- [Operations in Strings](https://youtu.be/zL1DPZ0Ovlo?t=1681)
53+
- [StringBuilder in java](https://youtu.be/zL1DPZ0Ovlo?t=4199)
54+
- [Maths for DSA](https://youtu.be/fzip9Aml6og)
55+
- [Introduction](https://youtu.be/fzip9Aml6og?t=20)
56+
- [Complete Bitwise Operators](https://youtu.be/fzip9Aml6og?t=95)
57+
- [Range of numbers](https://youtu.be/fzip9Aml6og?t=4169)
58+
- [Prime numbers](https://youtu.be/lmSpZ0bjCyQ?t=57)
59+
- [Sieve of Eratosthenes](https://youtu.be/lmSpZ0bjCyQ?t=850)
60+
- [Newton's Square Root Method](https://youtu.be/lmSpZ0bjCyQ?t=1989)
61+
- [Factors](https://youtu.be/lmSpZ0bjCyQ?t=3004)
62+
- [Modulo properties](https://youtu.be/lmSpZ0bjCyQ?t=3980)
63+
- [Number Theory](https://youtu.be/lmSpZ0bjCyQ?t=4405)
64+
- [HCF / LCM](https://youtu.be/lmSpZ0bjCyQ?t=5110)
65+
- [Euclidean algorithm](https://youtu.be/lmSpZ0bjCyQ?t=5520)
66+
- [Recursion](https://www.youtube.com/playlist?list=PL9gnSGHSqcnp39cTyB1dTZ2pJ04Xmdrod)
67+
- [Introduction](https://youtu.be/M2uO2nMT0Bk)
68+
- [Flow of recursive programs - stacks](https://youtu.be/M2uO2nMT0Bk?t=2124)
69+
- [Why recursion?](https://youtu.be/M2uO2nMT0Bk?t=2708)
70+
- [Tree building of function calls](https://youtu.be/M2uO2nMT0Bk?t=3033)
71+
- [Tail recursion](https://youtu.be/M2uO2nMT0Bk?t=4308)
72+
- [Sorting](https://www.youtube.com/playlist?list=PL9gnSGHSqcnq-9CXLt9DsInytRMLoyZQ_)
73+
- [Merge Sort](https://youtu.be/iKGAgWdgoRk)
74+
- [Quick Sort](https://www.youtube.com/watch?v=Z8svOqamag8&list=PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ&index=27)
75+
- [Backtracking](https://youtu.be/zg5v2rlV1tM)
76+
- [N-Queens](https://youtu.be/nC1rbW2YSz0)
77+
- [N-Knights](https://youtu.be/nC1rbW2YSz0?t=2342)
78+
- [Sudoku Solver](https://youtu.be/nC1rbW2YSz0?t=3190)
79+
- [Maze problems](https://www.youtube.com/watch?v=zg5v2rlV1tM)
80+
- [Recursion String Problems](https://youtu.be/gdifkIwCJyg)
81+
- [Recursion Google, Amazon Questions](https://youtu.be/9ByWqPzfXDU)
82+
- [Recursion Array Problems](https://youtu.be/sTdiMLom00U)
83+
- [Recursion Pattern Problems](https://youtu.be/ymgnIIclCF0)
84+
- [Subset Questions](https://youtu.be/9ByWqPzfXDU)
85+
- [Space and Time Complexity Analysis](https://youtu.be/mV3wrLBbuuE)
86+
- [Introduction](https://youtu.be/mV3wrLBbuuE)
87+
- [Comparisons of various cases](https://youtu.be/mV3wrLBbuuE?t=1039)
88+
- [Solving Linear Recurrence Relations](https://youtu.be/mV3wrLBbuuE?t=6252)
89+
- [Solving Divide and Conquer Recurrence Relations](https://youtu.be/mV3wrLBbuuE?t=4609)
90+
- [Big-O, Big-Omega, Big-Theta Notations](https://youtu.be/mV3wrLBbuuE?t=2271)
91+
- [Little Notations](https://youtu.be/mV3wrLBbuuE?t=2960)
92+
- [Get equation of any relation easily - best and easiest approach](https://youtu.be/mV3wrLBbuuE?t=8189)
93+
- [Complexity discussion of all the problems we do](https://youtu.be/mV3wrLBbuuE?t=3866)
94+
- [Space Complexity](https://youtu.be/mV3wrLBbuuE?t=3330)
95+
- [NP-Completeness Introduction](https://youtu.be/mV3wrLBbuuE?t=8695)
96+
- [Object Oriented Programming](https://www.youtube.com/playlist?list=PL9gnSGHSqcno1G3XjUbwzXHL8_EttOuKk)
97+
- [Introduction](https://www.youtube.com/watch?v=BSVKUk58K6U)
98+
- [Classes & its instances](https://youtu.be/BSVKUk58K6U?t=467)
99+
- [this keyword in Java](https://youtu.be/BSVKUk58K6U?t=3380)
100+
- [Properties](https://www.youtube.com/watch?v=46T2wD3IuhM)
101+
- [Inheritance](https://youtu.be/46T2wD3IuhM?t=146)
102+
- [Abstraction](https://youtu.be/46T2wD3IuhM?t=7102)
103+
- [Polymorphism](https://youtu.be/46T2wD3IuhM?t=4226)
104+
- [Encapsulation](https://youtu.be/46T2wD3IuhM?t=7022)
105+
- [Overloading & Overriding](https://youtu.be/46T2wD3IuhM?t=4834)
106+
- [Static & Non-Static](https://youtu.be/_Ya6CN13t8k?t=1137)
107+
- [Packages](https://youtu.be/_Ya6CN13t8k?t=182)
108+
- [Access Control](https://youtu.be/W145DXs8fFg)
109+
- [Interfaces](https://youtu.be/rgHZa7-Dibg?t=1510)
110+
- [Abstract Classes](https://youtu.be/rgHZa7-Dibg?t=68)
111+
- [Annotations](https://youtu.be/rgHZa7-Dibg?t=3438)
112+
- [Singleton Class](https://youtu.be/_Ya6CN13t8k?t=4240)
113+
- [final, finalize, finally](https://youtu.be/46T2wD3IuhM?t=6317)
114+
- [Object Cloning](https://youtu.be/OY2lPr8h93U?t=4352)
115+
- [Object Class](https://youtu.be/W145DXs8fFg?t=1943)
116+
- [Generics](https://www.youtube.com/watch?v=OY2lPr8h93U)
117+
- [Exception Handling](https://youtu.be/OY2lPr8h93U?t=3405)
118+
- [Collections Framework](https://youtu.be/9ogGan-R1pc?t=49)
119+
- [Vector Class](https://youtu.be/9ogGan-R1pc?t=668)
120+
- [Lambda Expression](https://youtu.be/OY2lPr8h93U?t=2894)
121+
- [Enums](https://youtu.be/9ogGan-R1pc?t=909)
122+
- Linked List
123+
- [Introduction](https://youtu.be/58YbpRDc4yw)
124+
- [Singly + Doubly + Circular LinkedList](https://youtu.be/58YbpRDc4yw)
125+
- [Fast and slow pointer](https://youtu.be/70tx7KcMROc)
126+
- [Cycle Detection](https://youtu.be/70tx7KcMROc)
127+
- [Reversal of LinkedList](https://youtu.be/70tx7KcMROc)
128+
- [Linked List + Recursion](https://youtu.be/70tx7KcMROc)
129+
- Stacks & Queues
130+
- Introduction
131+
- Interview problems
132+
- Push efficient
133+
- Pop efficient
134+
- Queue using Stack and Vice versa
135+
- Circular Queue
136+
- Trees
137+
- Introduction
138+
- Binary Trees
139+
- Binary Search Trees
140+
- DFS
141+
- BFS
142+
- AVL Trees
143+
- Segment Tree
144+
- Heaps
145+
- Introduction
146+
- Theory
147+
- Priority Queue
148+
- Heapsort
149+
- Two Heaps Method
150+
- k-way merge
151+
- Top k elements
152+
- Interval problems
153+
- HashMap
154+
- Introduction
155+
- Theory - how it works
156+
- Comparisons of various forms
157+
- Limitations and how to solve
158+
- Map using LinkedList
159+
- Map using Hash
160+
- Count Sort
161+
- Radix Sort
162+
- Chaining
163+
- Probing
164+
- Huffman-Encoder
165+
- Subarray Questions: Sliding window, Two Pointer, Kadane's Algorithm
166+
- Graphs
167+
- Introduction
168+
- BFS
169+
- DFS
170+
- Working with graph components
171+
- Minimum Spanning Trees
172+
- Kruskal Algorithm
173+
- Prims Algorithm
174+
- Dijkstra’s shortest path algorithm
175+
- Topological Sort
176+
- Bellman ford
177+
- A* pathfinding Algorithm
178+
- Dynamic Programming
179+
- Introduction
180+
- Recursion + Recursion DP + Iteration + Iteration Space Optimized
181+
- Complexity Analysis
182+
- 0/1 Knapsack
183+
- Subset Questions
184+
- Unbounded Knapsack
185+
- Subsequence questions
186+
- String DP
187+
- Greedy Algorithms
188+
- Tries
189+
190+
### Advanced concepts apart from interviews
191+
- Fast IO
192+
- File handling
193+
- Bitwise + DP
194+
- Extended Euclidean algorithm
195+
- Modulo Multiplicative Inverse
196+
- Linear Diophantine Equations
197+
- Matrix Exponentiation
198+
- Mathematical Expectation
199+
- Catalan Numbers
200+
- Fermat’s Theorem
201+
- Wilson's Theorem
202+
- Euler's Theorem
203+
- Lucas Theorem
204+
- Chinese Remainder Theorem
205+
- Euler Totient
206+
- NP-Completeness
207+
- Multithreading
208+
- Fenwick Tree / Binary Indexed Tree
209+
- Square Root Decomposition
3.82 MB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.Stack;
2+
3+
class Main {
4+
public static void main(String[] args) {
5+
6+
}
7+
8+
public int largestRectangleArea(int[] heights) {
9+
Stack<Integer> stack = new Stack<>();
10+
int max = 0;
11+
12+
stack.push(0);
13+
14+
for (int i = 1; i < heights.length; i++) {
15+
while (!stack.isEmpty() && heights[i] < heights[stack.peek()]) {
16+
max = getMax(heights, stack, max, i);
17+
}
18+
stack.push(i);
19+
}
20+
21+
int i = heights.length;
22+
while (!stack.isEmpty()) {
23+
max = getMax(heights, stack, max, i);
24+
}
25+
26+
return max;
27+
}
28+
29+
private static int getMax(int[] arr, Stack<Integer> stack, int max, int i) {
30+
int area;
31+
int popped = stack.pop();
32+
if (stack.isEmpty()) {
33+
area = arr[popped] * i;
34+
} else {
35+
area = arr[popped] * (i - 1 - stack.peek());
36+
}
37+
return Math.max(max, area);
38+
}
39+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.util.Stack;
2+
3+
public class QueueUsingStack {
4+
private Stack<Integer> first;
5+
private Stack<Integer> second;
6+
7+
public QueueUsingStack() {
8+
first = new Stack<>();
9+
second = new Stack<>();
10+
}
11+
12+
public void add(int item) {
13+
first.push(item);
14+
}
15+
16+
public int remove() throws Exception {
17+
while (!first.isEmpty()) {
18+
second.push(first.pop());
19+
}
20+
int removed = second.pop();
21+
while (!second.isEmpty()) {
22+
first.push(second.pop());
23+
}
24+
return removed;
25+
}
26+
27+
public int peek() throws Exception {
28+
while (!first.isEmpty()) {
29+
second.push(first.pop());
30+
}
31+
32+
int peeked = second.peek();
33+
34+
while (!second.isEmpty()) {
35+
first.push(second.pop());
36+
}
37+
return peeked;
38+
}
39+
40+
public boolean isEmpty() {
41+
return first.isEmpty();
42+
}
43+
44+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.Stack;
2+
3+
public class QueueUsingStackRemove {
4+
private Stack<Integer> first;
5+
private Stack<Integer> second;
6+
7+
public QueueUsingStackRemove() {
8+
first = new Stack<>();
9+
second = new Stack<>();
10+
}
11+
12+
public void add(int item) throws Exception {
13+
while (!first.isEmpty()) {
14+
second.push(first.pop());
15+
}
16+
first.push(item);
17+
while (!second.isEmpty()) {
18+
first.push(second.pop());
19+
}
20+
}
21+
22+
public int remove() throws Exception {
23+
return first.pop();
24+
}
25+
26+
public int peek() throws Exception {
27+
return first.peek();
28+
}
29+
30+
public boolean isEmpty() {
31+
return first.isEmpty();
32+
}
33+
34+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.util.*;
2+
3+
class TwoStacks {
4+
static int twoStacks(int x, int[] a, int[] b) {
5+
return twoStacks(x, a, b, 0, 0) - 1;
6+
}
7+
8+
private static int twoStacks(int x, int[] a, int[] b, int sum, int count) {
9+
if (sum > x) {
10+
return count;
11+
}
12+
13+
if (a.length == 0 || b.length == 0) {
14+
return count;
15+
}
16+
17+
int ans1 = twoStacks(x, Arrays.copyOfRange(a, 1, a.length), b, sum + a[0], count + 1);
18+
int ans2 = twoStacks(x, a, Arrays.copyOfRange(b, 1, b.length), sum + a[0], count + 1);
19+
20+
return Math.max(ans1, ans2);
21+
}
22+
23+
public static void main(String[] args) {
24+
Scanner s = new Scanner(System.in);
25+
int t = s.nextInt();
26+
for (int i = 0; i < t; i++) {
27+
int n = s.nextInt();
28+
int m = s.nextInt();
29+
int x = s.nextInt();
30+
int[] a = new int[n];
31+
int[] b = new int[m];
32+
for (int j = 0; j < n; j++) {
33+
a[j] = s.nextInt();
34+
}
35+
for (int j = 0; j < m; j++) {
36+
b[j] = s.nextInt();
37+
}
38+
System.out.println(twoStacks(x, a, b));
39+
}
40+
}
41+
42+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.Stack;
2+
class Solution {
3+
public int minAddToMakeValid(String s) {
4+
Stack<Character> stack = new Stack<>();
5+
for (char ch : s.toCharArray()) {
6+
if (ch == ')') {
7+
if (!stack.isEmpty() && stack.peek() == '(') {
8+
stack.pop();
9+
} else {
10+
stack.push(ch);
11+
}
12+
} else {
13+
stack.push(ch);
14+
}
15+
}
16+
return stack.size();
17+
}
18+
}

0 commit comments

Comments
 (0)