Skip to content

Commit ca119f2

Browse files
committed
feat(book): add appendix D with interview question solutions
1 parent 996f7aa commit ca119f2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

book/D-interview-questions-solutions.asc

+6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ We are asked to rotate an array multiple times (`k`).
1313

1414
One brute force solution, would be removing the first element and appending it to the end `k` times:
1515

16+
[source, javascript]
17+
----
1618
include::interview-questions/rotate-array-left.js[tag=bruteForce]
19+
----
1720

1821
However, what would happen if the array is huge (millions of elements)?
1922
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
2225

2326
Here's the final solution:
2427

28+
[source, javascript]
29+
----
2530
include::interview-questions/rotate-array-left.js[tag=description]
2631
include::interview-questions/rotate-array-left.js[tag=solution]
32+
----
2733

2834
It runs on `O(n^2)` while the brute force solution was doing `O(n^2 * k)`.
2935

book/readme.asc

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ include::B-self-balancing-binary-search-trees.asc[]
6060
6161
include::C-AVL-tree.asc[]
6262
63+
include::D-interview-questions-solutions.asc[]
64+
6365
include::index.asc[]
6466
6567
// ifndef::ebook-format[include::index.asc[]]

0 commit comments

Comments
 (0)