forked from gouravkrosx/DSA-Revision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtra Questions.txt
102 lines (92 loc) · 4.99 KB
/
Extra Questions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Some Extra Questions
------------------------------------------------------------------------------------
1. Tower of Hanoi ->https://www.youtube.com/watch?v=QDBrZFROuA0
-> Make the recursion Tree and do the dry run , and do inorder traversal
public static void toh(int n, int t1id, int t2id, int t3id){
if(n==0){
return;
}
//(*) ->Means following all instructions of tower of hanoi
toh(n-1,t1id,t3id,t2id); //will print the instructions to move n-1 disks from t1 to t3 using t2(*)
System.out.println(n+"["+t1id+" -> "+t2id+"]");
toh(n-1,t3id,t2id,t1id);
}
-------------------------------------------------------------------------------------
2. Do All variations of buy and sell stock
-------------------------------------------------------------------------------------
3. Permutations (leetcode 46)
-------------------------------------------------------------------------------------
4. Subarray Product less than K (leetcode 713)
-------------------------------------------------------------------------------------
5. Contiguous Array ( Leetcode 525 )
-------------------------------------------------------------------------------------
6. Largest Subarray with sum 0
public static int LargestSubarrayWithSum0(int[]arr,int n){
HashMap<Integer,Integer>map=new HashMap<>();
int max=0;
int sum=0;
for(int i=0;i<arr.length;i++){
sum+=arr[i];
if(sum==0){
max=i+1;
}else{
if(map.get(sum)!=null){
max=Math.max(max,i-map.get(sum));
}else{
map.put(sum,i);
}
}
}
return max;
}
-------------------------------------------------------------------------------------
7. largest Subarray with sum no larger than k
private int maxSumSubArray(int[] a , int k){
int max = Integer.MIN_VALUE;
int preSum = 0;
TreeSet<Integer> ts = new TreeSet();
ts.add(0);
for(int i=0;i<a.length;i++){
preSum += a[i];
Integer gap = ts.ceiling(preSum - k);
if(gap != null) max = Math.max(max, preSum - gap);
ts.add(preSum);
}
return max;
}
-------------------------------------------------------------------------------------
8. Subarray Sum Equals K (pepcoding)
-------------------------------------------------------------------------------------
9. Word Break (pepcoding)->https://www.youtube.com/watch?v=2NaaM_z_Jig
-------------------------------------------------------------------------------------
10. Minimum Size Subarray Sum (Leetcode 209)
-------------------------------------------------------------------------------------
11. Predict the winner
-------------------------------------------------------------------------------------
12. Min jump game 2 Leetcode
-------------------------------------------------------------------------------------
13. Longest Arithmetic Subsequence of Given Difference (Leetcode 1218)
-------------------------------------------------------------------------------------
14. Longest Consecutive Sequence (Leetcode 28)
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------