119
119
- [ BST] ( #bst )
120
120
- [ For Finding PREDECESSOR] ( #for-finding-predecessor )
121
121
- [ For Finding SUCCESSOR] ( #for-finding-successor )
122
+ - [ Constraints on Coding interview] ( #constraints-on-coding-interview )
123
+ - [ Most Important] ( #most-important )
124
+ - [ How to start DSA?] ( #how-to-start-dsa )
125
+ - [ Step 1: First learn language] ( #step-1-first-learn-language )
126
+ - [ Step 2: Learn Data Structure (DS)] ( #step-2-learn-data-structure-ds )
127
+ - [ Step 3: Learn Algorithms] ( #step-3-learn-algorithms )
128
+ - [ How much questions I should do?] ( #how-much-questions-i-should-do )
129
+ - [ How to solve questions?] ( #how-to-solve-questions )
122
130
- [ References] ( #references )
123
131
124
132
> Coding interview question answers in JavaScript for Facebook, Amazon, Google, Microsoft or any company.
@@ -689,16 +697,14 @@ node .\src\math-and-stats\integer-division.js
689
697
690
698
## JavaScript Fundamentals
691
699
692
-
693
700
### Initialize 2D Array 4x4 with 0
694
701
695
702
``` js
696
- const x = new Array (4 ).fill ( new Array (4 ).fill (0 ))
703
+ const x = new Array (4 ).fill (new Array (4 ).fill (0 ));
697
704
```
698
705
699
706
![ ] ( https://i.imgur.com/JXVJGgJ.png )
700
707
701
-
702
708
### JavaScript Map
703
709
704
710
``` js
@@ -1249,9 +1255,9 @@ Below problems are lying under optimization problems. Just watch `Book Allocatio
1249
1255
It is useful for optimization problem.
1250
1256
Below is the template for Greedy Algorithm.
1251
1257
1252
- - Watch this [ video from Love Babbar] ( https://www.youtube.com/watch?v=sq_cXYjSglQ&list=PL4PCksYQGLJOcaPLgeMFaxaHigPFjBuTG&index=5 )
1258
+ - Watch this [ video from Love Babbar] ( https://www.youtube.com/watch?v=sq_cXYjSglQ&list=PL4PCksYQGLJOcaPLgeMFaxaHigPFjBuTG&index=5 )
1253
1259
- Watch [ these videos] ( https://www.youtube.com/watch?v=HzeK7g8cD0Y&list=PLqM7alHXFySESatj68JKWHRVhoJ1BxtLW&t=0s ) to learn greedy algorithm
1254
- - Find the solutions of the problems shared by [ Love Babbar here] ( https://www.youtube.com/watch?v=AsbDqOauGZE&list=PLDdcY4olLQk3cAxZPJXMbxqrM3PlNkmO8 )
1260
+ - Find the solutions of the problems shared by [ Love Babbar here] ( https://www.youtube.com/watch?v=AsbDqOauGZE&list=PLDdcY4olLQk3cAxZPJXMbxqrM3PlNkmO8 )
1255
1261
1256
1262
``` js
1257
1263
getOptimal (items, n)
@@ -1280,7 +1286,7 @@ Note: Greedy Algorithms may not work always like Longest Path in Binary Tree.
1280
1286
1281
1287
Below are the standard problems solved by Greedy Algorithms. I have solved first 4 problems listed below:
1282
1288
1283
- https://codepen.io/collection/QWbzGB
1289
+ https://codepen.io/collection/QWbzGB
1284
1290
1285
1291
- Activity Selection
1286
1292
- Fractional Knapsack
@@ -1294,26 +1300,82 @@ https://codepen.io/collection/QWbzGB
1294
1300
- Finding close to optimal solutions for ` NP Hard Problem ` like ` Travelling Salesman Problem `
1295
1301
1296
1302
### Huffman Coding
1303
+
1297
1304
Merge 2 smallest and make one node.
1298
- Next select 2 smallest and make one node.
1305
+ Next select 2 smallest and make one node.
1299
1306
Repeat the merge process
1300
1307
1301
1308
Always select 2 minimum one is called as Greedy Algorithm.
1302
1309
This is called as Optimal Merge Pattern Tree which is Greedy approach
1303
1310
1304
1311
![ ] ( https://i.imgur.com/eg0KRQ5.png )
1305
- ## BST
1306
1312
1307
- ### For Finding PREDECESSOR
1308
- - Take a LEFT then go extreme RIGHT to get predecessor of given node
1309
- - While going right update predecessor
1313
+ ## BST
1314
+
1315
+ ### For Finding PREDECESSOR
1316
+
1317
+ - Take a LEFT then go extreme RIGHT to get predecessor of given node
1318
+ - While going right update predecessor
1319
+
1320
+ ### For Finding SUCCESSOR
1321
+
1322
+ - Take a RIGHT then go extreme LEFT to get successor of given node
1323
+ - While going left update successor
1324
+
1325
+ ## Constraints on Coding interview
1326
+
1327
+ Read the given constraints before coding and applying algorithm.
1328
+
1329
+ If ` N < 10^5 ` then you must solve the problem in run time complexity of ` O(N) ` or ` O(N log (n)) `
1330
+
1331
+ ### Most Important
1332
+
1333
+ If constraints are given then read them and then decide complexity.
1334
+
1335
+ | N | RunTime Complexity |
1336
+ | --------------- | ---------------------- |
1337
+ | N < 4000 (10^3) | O(n^n) or O( n log(n)) |
1338
+ | 10^5 | O(n) or O(n log (n)) |
1339
+ | 10^9 | O(log(n)) or O(1) |
1340
+
1341
+ ** Examples:**
1342
+
1343
+ https://www.codechef.com/problems/DECODEIT This should be done within ` O(n) or O(n log (n)) `
1344
+
1345
+ ## How to start DSA?
1346
+
1347
+ ### Step 1: First learn language
1348
+
1349
+ ### Step 2: Learn Data Structure (DS)
1350
+
1351
+ While learning DS solve problems for the same DS also. Example if you are learning string then solve the problems for the string.
1352
+
1353
+ ### Step 3: Learn Algorithms
1354
+
1355
+ - Number Theory
1356
+ - Sorting Algorithms
1357
+ - Merge
1358
+ - Quick
1359
+ - Searching
1360
+ - Linear
1361
+ - Binary
1362
+ - Recursion & Backtracking
1363
+ - Greedy
1364
+ - Graph
1365
+
1366
+ ### How much questions I should do?
1367
+
1368
+ Every topic finish ` 30 to 40 ` questions. For ` Array ` , ` String ` , ` Recursion ` and ` Graph ` do more than 50 questions.
1310
1369
1311
- ### For Finding SUCCESSOR
1312
- - Take a RIGHT then go extreme LEFT to get successor of given node
1313
- - While going left update successor
1370
+ ### How to solve questions?
1314
1371
1372
+ Go to practice page: https://practice.geeksforgeeks.org/explore/?page=1
1315
1373
1374
+ ** Every day do below:**
1316
1375
1376
+ - 3 easy questions
1377
+ - 2 medium questions
1378
+ - 1 hard question
1317
1379
1318
1380
## References
1319
1381
0 commit comments