You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -68,14 +68,14 @@ Q: For inputs (dates), what are the valid inputs? Q: How input are encoded? (yyy
68
68
69
69
**Step 2: Write simple code that works partially for the problem**
70
70
71
-
- Chances are, you need to consider all possible conditions. Often, this results in getting stuck in finding the perfect solutions. Hence, its advisable that you find the simplest solution that works. E,g, solve with a single simple case.
71
+
- Chances are, you need to consider all possible conditions. Often, this results in getting stuck in finding the perfect solutions. Hence, it's advisable that you find the simplest solution that works. E,g, solve with a single simple case.
72
72
73
73
Tips: Break into simple parts so that we can see our progress. Write simple small codes that work No need to figure out all the details.
74
74
75
75

76
76
77
77
78
-
Now we look into the main topics that are being covered in most interviews/coding challenges. We also look into the patterns that appear in solutions which can be used in new problems. The goal is to understand the fundamentals and try to use them to solve problems.
78
+
Now we look into the main topics that are being covered in most interviews/coding challenges. We also look into the patterns that appear in solutions that can be used in new problems. The goal is to understand the fundamentals and try to use them to solve problems.
79
79
80
80
81
81
## Binary Search
@@ -128,75 +128,13 @@ O (n log (n))
128
128
129
129
**Q:** Why we are seeing log (n) in our efficiency? Hint: same as the binary search problem
130
130
131
-
**Quick Sort:**
132
-
Idea is to use pivots to sort the array.
133
-
134
-

135
-
136
-
137
-
On each step we are performing two moving around.
138
-
139
-

140
-
141
-
(Pivot = Last element)
142
131
143
-
1. Select the rightmost element as the pivot
144
-
2. Shift Pivot to left by one element
145
-
3. Swap start and left
146
-
4. Compare Start with pivot. If (Start \> Pivot repeat step 2)
147
-
5. Else move to second start
148
-
149
-

150
-
151
-

152
-
153
-

154
-
155
-
Why it can be chosen as the most efficient algorithm?
156
-
157
-
Because on average it will outperform merge sort.
158
-
159
-
160
-
**Great no need to move the original pivot anymore (2 is at the right place)**
161
-
162
-

163
-
164
-
Check 2 with lefts
165
-
166
-
New pivot on right. Compare
167
-
168
-
Moving phase
169
-
170
-
Everything less than 8 and 10 sweep results in:
171
-
Everything less than 8 is already below 8
172
-
173
-

174
132
175
133
**Efficiency:**
176
134
177
135
O(n2) if it’s already sorted. Why? Wasting time
178
136
179
137
180
-
## Sliding Window
181
-
How to tell if it's a sliding window problem?
182
-
• Deals with arrays
183
-
• Find/calculate among subarrays
184
-
185
-
> Q: Given an array, find the average of each subarray of ‘K’ contiguous elements in it.
186
-
187
-
188
-
Input: ![[Pasted image 20220910145630.png]]
189
-
Output: ![[Pasted image 20220910145753.png]]
190
-
Alg1: Bruteforce returns the average for every 5 element
191
-
Time: O(N * K)
192
-
• Its not optimal because we are calculating the sum of overlapping elements between subarrays more than once.
193
-
![[Pasted image 20220910150423.png]]
194
-
• Why not use a sliding window and subtract and add to the sum?
195
-
![[Pasted image 20220910150647.png]]
196
-
Alg2: Sliding window
197
-
198
-
199
-
200
138
## Dynamic Programming
201
139
202
140
(Programming == tables)
@@ -252,181 +190,87 @@ Longest common subsequent
252
190
253
191

254
192
255
-
## Complexity Theory
256
-
257
-
Class P: n, n\^2,… (Any problem that can be solved in poly time)
258
-
259
-
Class NP (Non deterministic): A set of decision problems where yes can be verified in polytime.
260
-
261
-
Descion problems (answers are yes or no) can I go from a to be less than 100miles? Lets take traveling sales man. Optimization can I do this less than 100 miles?
262
-
263
-
Is the answer more thaan 100? Yes is it lower than 200? 150? This way you will solve the problems
264
-
265
-
Proof/verified/certificate Orlando – Atlanta – L.A
266
-
267
-
Is this number a prime 234715307129734085? Hard to check
268
-
269
-
Suppose this number not a prime? 1324 if the answer is no it can be verified quickly
270
-
271
-
Class Co-NP: \_No\_ polytime
272
193
273
194
## Greedy Algorithm
274
-
(Best option at each step)
195
+
The best option at each step might not lead to the best results.
275
196
276
197

277
198
278
-
ATM machine : 1,2,10,20,50,100\<
279
-
280
-
Return: n\$ the number of bills should be minimized
281
-
282
-
21\$ = 20 +1
283
-
284
-
N= 365 – (3x100)- (1x50)-(1x10) – (1x 5)
285
-
286
-
What about Target = 8?
287
-
288
-
Example:
289
-
290
-
Min operations example {see code}: By using while, in dividing numbers in half // == / and using
291
-
292
-
##
293
199
## Graph Algorithm
294
-
(data structure that shows relation)
295
-
Graph(Tree is a subgroup of graph,Network) Nodes(Vertex) Edges
200
+
Graph is a data structure that is mostly used to shows relations.
296
201
297
202

298
203
299
-
Directed (non-directed), Acyclic, Connectivity
300
-
301
-
Connectivity: You friends (social circle)
302
-
303
-
As seen below, the right graph is stronger. In contrast, the left group can be dissolved if one of the connections drops.
304
-
305
-

306
-
307
-

308
-
309
-
Go through array reccursavley.
310
-
311
-

312
-
313
-
Let’s define 3 variables
314
-
315
-

316
-
317
-
Final answer we be the best solution out of these both (A[i] B[i] )
318
-
319
-
# 5. Technical Interview
204
+
Directed (non-directed), Acyclic
320
205
321
-
Now lets focus on the technical interviews. We tend to simplify the concepts by using memory palace techniques. I adivse everyone to develop a memory palace for algorithms/techniques that requrie knowledge about more than 6-7 steps.
206
+
The notion of connectivity: As seen below, the right graph is stronger. In contrast, the left group can be dissolved if one of the connections drops.
322
207
323
-

324
208
325
-
The context should be asking questions and brainstorm at first. As you go on you rather than asking question everystep you must make statements and justify them.
326
-
327
-
{so we can have null input like [] Is that right?} { I have a feeling that it might be useful in future steps}
328
-
329
-
Example: So it contains integers right? So Null input is another input that we can have.
330
-
331
-
Q:
332
-
A: Thanks it’s a pleasure to do interview with you. {Positive mindset} {Don’t give up}
333
-
334
-
1.**Clarifying the question {To prove you wont dive into the problem without learning more about it}**
335
-
336
-
Q: Given a 2D matrix of m, Just 0 and 1. Count the number of islands in the matrix [island is a group of 1 or just 1 by itself.]
337
-
338
-
A: ok so, we are given a 2D matrix which will look something like this.:
339
-
340
-
[[1,0,1],[1,1,1)
341
-
342
-
So, our goal is find the number of islands. Is the outcome the number? Or X? So if the are connected (I[1,0,0],[0,1,0],[0,0,1]) diagonally? Does that consider an island?
343
-
344
-
So what we supposed to do is to find the number of
345
-
346
-
{Just want to check Im solving the right problem…}
347
-
348
-
1. Generating inputs and outputs:
349
-
350
-
> So my input is matrix of 0 s, 1 s (Integers, strings? No)
351
-
352
-
> Output: Integer (\# of islands) (1s or group of ones)
353
-
354
-
1. Generating test cases:
355
-
356
-
> {So just to test some cases {Special}}
357
-
358
-
> {Can we get Is it ok we have }? Yes
359
-
360
-
Q: number of island in a matrix
361
-
362
-
\*\*1.Clarify the question \*\*
363
-
364
-
A[[1,0,0),[1,1,0){Just to make sure I’m solving the right problem….}
1. {Trick \#1 you can always answer the null case to interviewer.}{ I have a feeling that it might be useful in future steps} **Test cases**[**Edge cases**][ Possible weird inputs that we have to handle A or none object
214
+
Machine Learning:
215
+
-[Cracking ML inteviews](https://github.com/shafaypro/CrackingMachineLearningInterview)
1.**Brainstorming** So if we have null, for sure we have 0 so there would be no islands in this case. ======= Input matrix of integers.Output integers (number of islands 0- max{n})
225
+
## Archive:
226
+
**Complexity Theory**##
379
227
380
-
**3.Test cases**: {Trick \#1 you can always answer the null case to interviewer.}{ I have a feeling that it might be useful in future steps} **Test cases**[**Edge cases**][ Possible weird inputs that we have to handle A or none object.
228
+
Class P: n, n\^2,… (any problem that can be solved in polytime)
381
229
382
-
{Null - empty- Write a code that doesnt crash}
230
+
Class NP (Nondeterministic):
383
231
384
-
**4.Brainstorming:** {Variables that needs to initialized} {so I need to track X} {And keep tracking} {Runtime error} {Data structure brainstorm algorithms and data structures} {Represent graph DFS problem} So if we have null, for sure we have 0 so there would be no islands in this case. \>\>\>\>\>\>\> 600e13278473db6cc40a022e79c37c0e0baa2b56
232
+
Class Co-NP: \_No\_ polytime
385
233
386
-
But also we can have this as input (the input she wants) {So what I am thinking here} is start at the first element . So i need a counter **variable** and I **initialze** it there. And **increment** it by 1.
234
+
**Quick Sort:**
235
+
The idea is to use pivots to sort the array.
387
236
388
-
We get to Zero. Thats not part of any island so I need to keep track of X. Hmmmm. Maybe I can look at the elements on top and bottom and check if they are on the same island and keep track of it. Since there is no above that. We get a run time error. Maybe it could a case of data structure we can solve this. {This might be a breath first search problem. I can look at the elements around it. **Set to mark** as **visited** and **keep going**
237
+

389
238
390
-
**If you are stuck?** This represent a type of data structure and algorithm . Merge sort maybe… Keep talking
391
239
392
-
\*\*5. Runtime anaylsis \*\*
240
+
On each step we are performing two moving around.
393
241
394
-
When I’m looking all the elements in matrix I’m looking at them atlease once so I’m thinking the runtime would be nXm where N is the number of rows and M is the number of columns. Well it seems like the optimal solution. So i think i start and jump on coding now.
242
+

395
243
396
-
**6.Coding**
244
+
(Pivot = Last element)
397
245
398
-
So I’m calling my mainfunction islandCounter():
246
+
1. Select the rightmost element as the pivot
247
+
2. Shift Pivot to left by one element
248
+
3. Swap start and left
249
+
4. Compare Start with pivot. If (Start \> Pivot repeat step 2)
250
+
5. Else move to second start
399
251
400
-
Variable a,b,c If() While() For()
252
+

401
253
402
-
**7.Debugging**
254
+

403
255
404
-
Test cases: input None -\> return 0 so its working
256
+

405
257
406
-
So [[1,0,1],[1,1,0). Go ahead, that looks good. Now I’m adding both of these. And I probably {} O looks like I forget to {add a return} Looks like it works.
258
+
Why it can be chosen as the most efficient algorithm?
407
259
260
+
Because on average it will outperform merge sort.
408
261
409
-
\<\<\<\<\<\<\< HEAD while(len(q)!= 0):
410
262
411
-
And run it by
263
+
**Great no need to move the original pivot anymore (2 is at the right place)**
0 commit comments