-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] master from amejiarosario:master #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f125511
chore(build): dockerfile
amejiarosario 5466f28
Merge branch 'master' into chore/build-changes
amejiarosario 738d6f3
chore(build): add Dockerfile
amejiarosario 69f284d
chore(build): use jest config
amejiarosario db10bf7
chore(build): update ruby version
amejiarosario d3faa71
chore(build): remove deprecated dep
amejiarosario 44fb6a2
Merge pull request #68 from amejiarosario/chore/build-changes
amejiarosario File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Merge branch 'master' into chore/build-changes
- Loading branch information
commit 5466f28f006ed03d545f7d9da1030f871d791296
There are no files selected for viewing
19 changes: 18 additions & 1 deletion
.vscode/settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
{ | ||
"peacock.color": "#f9e64f" | ||
"peacock.color": "#f9e64f", | ||
"workbench.colorCustomizations": { | ||
"activityBar.activeBackground": "#fbed80", | ||
"activityBar.activeBorder": "#06b9a5", | ||
"activityBar.background": "#fbed80", | ||
"activityBar.foreground": "#15202b", | ||
"activityBar.inactiveForeground": "#15202b99", | ||
"activityBarBadge.background": "#06b9a5", | ||
"activityBarBadge.foreground": "#15202b", | ||
"statusBar.background": "#f9e64f", | ||
"statusBar.foreground": "#15202b", | ||
"statusBarItem.hoverBackground": "#f7df1e", | ||
"titleBar.activeBackground": "#f9e64f", | ||
"titleBar.activeForeground": "#15202b", | ||
"titleBar.inactiveBackground": "#f9e64f99", | ||
"titleBar.inactiveForeground": "#15202b99" | ||
}, | ||
"peacock.remoteColor": "#f9e64f" | ||
} |
16 changes: 16 additions & 0 deletions
CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM circleci/ruby:2.5.3-stretch-node | ||
# FROM circleci/ruby:2.7.1-buster-node | ||
|
||
COPY . /app | ||
|
||
RUN node -v | ||
RUN ruby -v | ||
RUN bundle -v | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
graphviz \ | ||
cmake bison flex libffi-dev libxml2-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev ttf-lyx \ | ||
graphicsmagick-imagemagick-compat graphicsmagick-libmagick-dev-compat | ||
|
||
RUN cd book/config && bundle install | ||
|
||
CMD cd book/config && make VERSION="$(npx -c 'echo "$npm_package_version"')" |
3 changes: 1 addition & 2 deletions
book/A-time-complexity-cheatsheet.asc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
book/D-interview-questions-solutions.asc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
[appendix] | ||
[[d-interview-questions-solutions]] | ||
== Interview Questions Solutions | ||
(((Interview Questions Solutions))) | ||
|
||
=== Solutions for Array Questions | ||
(((Interview Questions Solutions, Arrays))) | ||
|
||
:leveloffset: -1 | ||
|
||
[#array-q-max-subarray] | ||
include::content/part02/array.asc[tag=array-q-max-subarray] | ||
|
||
The first step is making sure we understand the problem well. Let's do basic examples: | ||
|
||
---- | ||
A = [-5, 6, 9, -8] | ||
B = [-1, 6, -3, 8] | ||
---- | ||
|
||
What's the subarray with the maximum sum? For A, it will be `[6, 9]` and for B, it will be `[6, -3, 8]`. | ||
|
||
We could generate all possible subarrays, add them up, and then pick the max number. | ||
|
||
[source, javascript] | ||
---- | ||
include::interview-questions/max-subarray.js[tag=maxSubArrayBrute1] | ||
---- | ||
|
||
This code is simple to understand; however, not very efficient. The runtime is `O(n^3)`. | ||
|
||
If you noticed we adding up the numbers from `i` to `j` on each cycle. But, we can optimize this. We can keep a local variable and add the new number to it. That way, we don't have to revisit previous numbers. | ||
|
||
[source, javascript] | ||
---- | ||
include::interview-questions/max-subarray.js[tag=maxSubArrayBrute2] | ||
---- | ||
|
||
The runtime is much better: `O(n)`. Can we still do better? | ||
|
||
We can use a greedy approach, where do one pass through the array. We only add the numbers if their sum is larger than just taking the current element. | ||
|
||
[source, javascript] | ||
---- | ||
include::interview-questions/max-subarray.js[tag=description] | ||
include::interview-questions/max-subarray.js[tag=solution] | ||
---- | ||
|
||
The runtime is `O(n)` and a space complexity of `O(1)`. | ||
|
||
|
||
|
||
|
||
[#array-q-buy-sell-stock] | ||
include::content/part02/array.asc[tag=array-q-buy-sell-stock] | ||
|
||
There are multiple examples that we can simulate: bear markets (when prices are going down), bullish markets (when prices are going up), and zig-zag markets (when prices are going up and down). | ||
|
||
[source, javascript] | ||
---- | ||
// zig-zag market | ||
maxProfit([5, 10, 5, 10]); // => 5 | ||
// bullish market | ||
maxProfit([1, 2, 3]); // => 2 | ||
// bearish market | ||
maxProfit([3, 2, 1]); // => 0 | ||
---- | ||
|
||
During the bearish markets, the profit will always be 0. Since if you buy, we are only going to lose. | ||
|
||
We can do a brute force solution doing all combinations: | ||
|
||
[source, javascript] | ||
---- | ||
include::interview-questions/buy-sell-stock.js[tag=maxProfitBrute1] | ||
---- | ||
|
||
The runtime for this solution is `O(n^2)`. | ||
|
||
A better solution is to eliminate the 2nd for loop and only do one pass. | ||
|
||
Algorithm: | ||
|
||
- Do one pass through all the prices | ||
- Keep track of the minimum price seen so far. | ||
- calculate `profit = currentPrice - minPriceSoFar` | ||
- Keep track of the maximun profit seen so far. | ||
- Return maxProfit. | ||
|
||
[source, javascript] | ||
---- | ||
include::interview-questions/buy-sell-stock.js[tag=description] | ||
include::interview-questions/buy-sell-stock.js[tag=solution] | ||
---- | ||
|
||
The runtime is `O(n)` and a space complexity of `O(1)`. |
35 changes: 0 additions & 35 deletions
book/ch02-git-basics-chapter.asc
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
book/index.asc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
[index] | ||
[[index]] | ||
== Index | ||
== Index [[index]] | ||
|
||
ifndef::backend-pdf[Topical index only available on the PDF version.] |
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.