Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,10 @@ We are asked to rotate an array multiple times (`k`).
13
13
14
14
One brute force solution, would be removing the first element and appending it to the end `k` times:
15
15
16
+ [source, javascript]
17
+ ----
16
18
include::interview-questions/rotate-array-left.js[tag=bruteForce]
19
+ ----
17
20
18
21
However, what would happen if the array is huge (millions of elements)?
19
22
How efficient will be if `k` number is large (thousands)?
@@ -22,8 +25,11 @@ When k is bigger than the array, it will loop back over and over again. We can a
22
25
23
26
Here's the final solution:
24
27
28
+ [source, javascript]
29
+ ----
25
30
include::interview-questions/rotate-array-left.js[tag=description]
26
31
include::interview-questions/rotate-array-left.js[tag=solution]
32
+ ----
27
33
28
34
It runs on `O(n^2)` while the brute force solution was doing `O(n^2 * k)`.
29
35
Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ include::B-self-balancing-binary-search-trees.asc[]
60
60
61
61
include::C-AVL-tree.asc[]
62
62
63
+ include::D-interview-questions-solutions.asc[]
64
+
63
65
include::index.asc[]
64
66
65
67
// ifndef::ebook-format[include::index.asc[]]
0 commit comments