Skip to content

Commit 1f01baf

Browse files
committed
feat(book/questions): add where the interview questions have been seen
1 parent 77d4596 commit 1f01baf

File tree

6 files changed

+34
-19
lines changed

6 files changed

+34
-19
lines changed

book/D-interview-questions-solutions.asc

+3-6
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ Algorithm:
9090

9191
[source, javascript]
9292
----
93-
include::interview-questions/buy-sell-stock.js[tag=description]
94-
include::interview-questions/buy-sell-stock.js[tag=solution]
93+
include::interview-questions/buy-sell-stock.js[tag=description,solution]
9594
----
9695

9796
The runtime is `O(n)` and space complexity of `O(1)`.
@@ -126,8 +125,7 @@ Another case to take into consideration is that lists might have different lengt
126125

127126
[source, javascript]
128127
----
129-
include::interview-questions/merge-lists.js[tag=description]
130-
include::interview-questions/merge-lists.js[tag=solution]
128+
include::interview-questions/merge-lists.js[tag=description,solution]
131129
----
132130

133131
Notice that we used a "dummy" node or "sentinel node" to have some starting point for the final list.
@@ -172,8 +170,7 @@ A better way to solve this problem is iterating over each character on both list
172170

173171
[source, javascript]
174172
----
175-
include::interview-questions/linkedlist-same-data.js[tag=description]
176-
include::interview-questions/linkedlist-same-data.js[tag=solution]
173+
include::interview-questions/linkedlist-same-data.js[tag=description,solution]
177174
----
178175

179176
The function `findNextPointerIndex` is a helper to navigate each character on a linked list.

book/content/part02/array.asc

+5-1
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,15 @@ To sum up, the time complexity of an array is:
276276
|===
277277
//end::table
278278

279-
==== Interview Questions
279+
==== Practice Questions
280280
(((Interview Questions, Arrays)))
281281

282282
// tag::array-q-max-subarray[]
283283
===== Max Subarray
284284

285285
*AR-1*) _Given an array of integers, find the maximum sum of consecutive elements (subarray)._
286+
287+
_Seen in interviews at: Amazon, Apple, Google, Microsoft, Facebook_
286288
// end::array-q-max-subarray[]
287289

288290
[source, javascript]
@@ -298,6 +300,8 @@ _Solution: <<array-q-max-subarray>>_
298300
===== Best Time to Buy and Sell an Stock
299301

300302
*AR-2*) _You are given an array of integers. Each value represents the closing value of the stock on that day. You are only given one chance to buy and then sell. What's the maximum profit you can obtain? (Note: you have to buy first and then sell)_
303+
304+
_Seen in interviews at: Amazon, Facebook, Bloomberg_
301305
// end::array-q-buy-sell-stock[]
302306

303307
[source, javascript]

book/content/part02/linked-list.asc

+5-1
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,15 @@ Use a doubly linked list when:
286286

287287
For the next two linear data structures <<part02-linear-data-structures#stack>> and <<part02-linear-data-structures#queue>>, we are going to use a doubly-linked list to implement them. We could use an array as well, but since inserting/deleting from the start performs better with linked-lists, we will use that.
288288

289-
==== Interview Questions
289+
==== Practice Questions
290290
(((Interview Questions, Linked Lists)))
291291

292292
// tag::linkedlist-q-merge-lists[]
293293
===== Merge Linked Lists into One
294294

295295
*LL-1*) _Merge two sorted lists into one (and keep them sorted)_
296+
297+
_Seen in interviews at: Amazon, Adobe, Microsoft, Google_
296298
// end::linkedlist-q-merge-lists[]
297299

298300
[source, javascript]
@@ -311,6 +313,8 @@ _Solution: <<linkedlist-q-merge-lists>>_
311313
===== Check if two strings lists are the same
312314

313315
*LL-2*) _Given two linked lists with strings, check if are the same_
316+
317+
_Seen in interviews at: Facebook_
314318
// end::linkedlist-q-linkedlist-same-data[]
315319

316320
[source, javascript]

book/content/part02/queue.asc

+15-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,21 @@ indexterm:[Runtime, Linear]
9191
===== Recent Counter
9292

9393
*QU-1*) _Design a class that counts the most recent requests within a time window._
94-
// end::queue-q-recent-counter[]
94+
95+
Example:
96+
97+
[source, javascript]
98+
----
99+
const counter = new RecentCounter(10); // The time window is 10 ms.
100+
counter.request(1000); // 1 (first request, it always counts)
101+
counter.request(3000); // 1 (last requests was 2000 ms ago, > 10ms, so doesn't count)
102+
counter.request(3100); // 1 (last requests was 100 ms ago, > 10ms, so doesn't count)
103+
counter.request(3105); // 2 (last requests was 5 ms ago, <= 10ms, so it counts)
104+
----
105+
95106
_Seen in interviews at: Google, Bloomberg, Yandex_
107+
// end::queue-q-recent-counter[]
108+
96109

97110
[source, javascript]
98111
----
@@ -108,9 +121,9 @@ _Solution: <<queue-q-recent-counter>>_
108121
===== Design Snake Game
109122

110123
*QU-2*) _Design the `move` function for the snake game. The move function returns an integer representing the current score. If the snake goes out of the given height and width or hit itself return `-1` for game over._
111-
// end::queue-q-design-snake-game[]
112124

113125
_Seen in interviews at: Amazon, Bloomberg, Apple_
126+
// end::queue-q-design-snake-game[]
114127

115128
[source, javascript]
116129
----

book/content/part02/stack.asc

+5-1
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ Implementing the stack with an array and linked list would lead to the same time
8787
It's not very common to search for values on a stack (other Data Structures are better suited for this). Stacks are especially useful for implementing <<part03-graph-data-structures#dfs-tree, Depth-First Search>>.
8888

8989

90-
==== Interview Questions
90+
==== Practice Questions
9191
(((Interview Questions, Stack)))
9292

9393
// tag::stack-q-valid-parentheses[]
9494
===== Validate Parentheses / Braces / Brackets
9595

9696
*ST-1*) _Given an string with 3 types of brakets: `()`, `{}`, and `[]`. Validate they are properly closed and opened._
97+
98+
_Seen in interviews at: Amazon, Bloomberg, Facebook, Citadel_
9799
// end::stack-q-valid-parentheses[]
98100

99101
[source, javascript]
@@ -113,6 +115,8 @@ _Solution: <<stack-q-valid-parentheses>>_
113115
===== Daily Temperaturs
114116

115117
*ST-2*) _Given an array of integers from 30 to 100 (daily temperatures), return another array that for each day in the input, tells you how many days you would have to wait until a warmer temperature. If no warmer temperature is possible then return `0` for that element._
118+
119+
_Seen in interviews at: Amazon, Adobe, Cisco_
116120
// end::stack-q-daily-temperatures[]
117121

118122
[source, javascript]

book/interview-questions/recent-counter.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,13 @@ const { Queue } = require('../../src/index');
88
* any requests that happened more than 2 seconds before the most recent request
99
* should not count.
1010
*
11-
* @example - The time window is 10 ms.
12-
* const counter = new RecentCounter(10);
13-
* counter.request(1000); // 1 (first request, it counts)
14-
* counter.request(3000); // 1 (last requests was 2000 ms ago, > 10ms, so doesn't count)
15-
* counter.request(3100); // 1 (last requests was 100 ms ago, > 10ms, so doesn't count)
16-
* counter.request(3105); // 2 (last requests was 5 ms ago, <= 10ms, so it counts)
17-
*
1811
* @example - The time window is 3 sec. (3000 ms)
1912
* const counter = new RecentCounter(3000);
2013
* counter.request(100); // 1
2114
* counter.request(1000); // 2
2215
* counter.request(3000); // 3
2316
* counter.request(3100); // 4
24-
* counter.request(3101); // 4 (request at time 100 is out of the 3000 window).
17+
* counter.request(3101); // 4
2518
*
2619
*/
2720
classRecentCounter{

0 commit comments

Comments
 (0)
close