Skip to content

Commit

Permalink
feat(book/questions): add where the interview questions have been seen
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed Aug 29, 2020
1 parent 77d4596 commit 1f01baf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 19 deletions.
9 changes: 3 additions & 6 deletions book/D-interview-questions-solutions.asc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ Algorithm:

[source, javascript]
----
include::interview-questions/buy-sell-stock.js[tag=description]
include::interview-questions/buy-sell-stock.js[tag=solution]
include::interview-questions/buy-sell-stock.js[tag=description,solution]
----

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

[source, javascript]
----
include::interview-questions/merge-lists.js[tag=description]
include::interview-questions/merge-lists.js[tag=solution]
include::interview-questions/merge-lists.js[tag=description,solution]
----

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

[source, javascript]
----
include::interview-questions/linkedlist-same-data.js[tag=description]
include::interview-questions/linkedlist-same-data.js[tag=solution]
include::interview-questions/linkedlist-same-data.js[tag=description,solution]
----

The function `findNextPointerIndex` is a helper to navigate each character on a linked list.
Expand Down
6 changes: 5 additions & 1 deletion book/content/part02/array.asc
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,15 @@ To sum up, the time complexity of an array is:
|===
//end::table

==== Interview Questions
==== Practice Questions
(((Interview Questions, Arrays)))

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

*AR-1*) _Given an array of integers, find the maximum sum of consecutive elements (subarray)._

_Seen in interviews at: Amazon, Apple, Google, Microsoft, Facebook_
// end::array-q-max-subarray[]

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

*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)_

_Seen in interviews at: Amazon, Facebook, Bloomberg_
// end::array-q-buy-sell-stock[]

[source, javascript]
Expand Down
6 changes: 5 additions & 1 deletion book/content/part02/linked-list.asc
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,15 @@ Use a doubly linked list when:

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.

==== Interview Questions
==== Practice Questions
(((Interview Questions, Linked Lists)))

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

*LL-1*) _Merge two sorted lists into one (and keep them sorted)_

_Seen in interviews at: Amazon, Adobe, Microsoft, Google_
// end::linkedlist-q-merge-lists[]

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

*LL-2*) _Given two linked lists with strings, check if are the same_

_Seen in interviews at: Facebook_
// end::linkedlist-q-linkedlist-same-data[]

[source, javascript]
Expand Down
17 changes: 15 additions & 2 deletions book/content/part02/queue.asc
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,21 @@ indexterm:[Runtime, Linear]
===== Recent Counter

*QU-1*) _Design a class that counts the most recent requests within a time window._
// end::queue-q-recent-counter[]

Example:

[source, javascript]
----
const counter = new RecentCounter(10); // The time window is 10 ms.
counter.request(1000); // 1 (first request, it always counts)
counter.request(3000); // 1 (last requests was 2000 ms ago, > 10ms, so doesn't count)
counter.request(3100); // 1 (last requests was 100 ms ago, > 10ms, so doesn't count)
counter.request(3105); // 2 (last requests was 5 ms ago, <= 10ms, so it counts)
----

_Seen in interviews at: Google, Bloomberg, Yandex_
// end::queue-q-recent-counter[]


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

*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._
// end::queue-q-design-snake-game[]

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

[source, javascript]
----
Expand Down
6 changes: 5 additions & 1 deletion book/content/part02/stack.asc
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ Implementing the stack with an array and linked list would lead to the same time
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>>.


==== Interview Questions
==== Practice Questions
(((Interview Questions, Stack)))

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

*ST-1*) _Given an string with 3 types of brakets: `()`, `{}`, and `[]`. Validate they are properly closed and opened._

_Seen in interviews at: Amazon, Bloomberg, Facebook, Citadel_
// end::stack-q-valid-parentheses[]

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

*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._

_Seen in interviews at: Amazon, Adobe, Cisco_
// end::stack-q-daily-temperatures[]

[source, javascript]
Expand Down
9 changes: 1 addition & 8 deletions book/interview-questions/recent-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,13 @@ const { Queue } = require('../../src/index');
* any requests that happened more than 2 seconds before the most recent request
* should not count.
*
* @example - The time window is 10 ms.
* const counter = new RecentCounter(10);
* counter.request(1000); // 1 (first request, it counts)
* counter.request(3000); // 1 (last requests was 2000 ms ago, > 10ms, so doesn't count)
* counter.request(3100); // 1 (last requests was 100 ms ago, > 10ms, so doesn't count)
* counter.request(3105); // 2 (last requests was 5 ms ago, <= 10ms, so it counts)
*
* @example - The time window is 3 sec. (3000 ms)
* const counter = new RecentCounter(3000);
* counter.request(100); // 1
* counter.request(1000); // 2
* counter.request(3000); // 3
* counter.request(3100); // 4
* counter.request(3101); // 4 (request at time 100 is out of the 3000 window).
* counter.request(3101); // 4
*
*/
class RecentCounter {
Expand Down

0 comments on commit 1f01baf

Please sign in to comment.