Skip to content

Commit

Permalink
Merge pull request #91 from amejiarosario/feat/hashmap
Browse files Browse the repository at this point in the history
feat(book/hashmap): add code examples and patterns
  • Loading branch information
amejiarosario authored Oct 22, 2020
2 parents dc47b76 + f7b8d59 commit edf11d9
Show file tree
Hide file tree
Showing 16 changed files with 865 additions and 201 deletions.
6 changes: 4 additions & 2 deletions book/D-interview-questions-solutions.asc
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ The complexity of any of the BFS methods or DFS is similar.
:leveloffset: -1

[#hashmap-q-two-sum]
include::content/part03/hashmap.asc[tag=hashmap-q-two-sum]
include::content/part02/hash-map.asc[tag=hashmap-q-two-sum]
// include::content/part03/hashmap.asc[tag=hashmap-q-two-sum]

This simple problem can have many solutions; let's explore some.

Expand Down Expand Up @@ -480,7 +481,8 @@ include::interview-questions/two-sum.js[tags=description;solution]


[#hashmap-q-subarray-sum-equals-k]
include::content/part03/hashmap.asc[tag=hashmap-q-subarray-sum-equals-k]
include::content/part02/hash-map.asc[tag=hashmap-q-subarray-sum-equals-k]
// include::content/part03/hashmap.asc[tag=hashmap-q-subarray-sum-equals-k]

This problem has multiple ways to solve it. Let's explore some.

Expand Down
15 changes: 6 additions & 9 deletions book/content/part02/array.asc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ ifndef::imagesdir[]
:codedir: ../../../src
endif::[]

(((Array))) (((Data Structures, Linear, Array)))
[[array]]
=== Array [[array-chap]]
(((Array)))
(((Data Structures, Linear, Array)))
[[array-chap]]
=== Array

Arrays are one of the most used data structures. You probably have used it a lot already. But, are you aware of the runtimes of `push`, `splice`, `shift`, `indexOf`, and other operations? In this chapter, we are going deeper into the most common operations and their runtimes.

==== Array Basics
Expand Down Expand Up @@ -300,9 +301,7 @@ To sum up, the time complexity of an array is:

Many programming problems involve manipulating arrays. Here are some patterns that can help you improve your problem-solving skills.

(((Patterns, Two Pointers)))

===== Two Pointers Pattern
===== Two Pointers Pattern (((Patterns, Two Pointers)))

Usually, we use one pointer to navigate each element in an array. However, there are times when having two pointers (left/right, low/high) comes in handy. Let's do some examples.

Expand Down Expand Up @@ -371,9 +370,7 @@ These two pointers have a runtime of `O(n)`.

WARNING: This technique only works for sorted arrays. If the array was not sorted, you would have to sort it first or choose another approach.

(((Patterns, Sliding Window Pointers)))

===== Sliding Window Pattern
===== Sliding Window Pattern (((Patterns, Sliding Window))) [[sliding-window-array]]

The sliding window pattern is similar to the two pointers. The difference is that the distance between the left and right pointer is always the same. Also, the numbers don't need to be sorted. Let's do an example!

Expand Down
Loading

0 comments on commit edf11d9

Please sign in to comment.