-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,099 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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,25 @@ | ||
public class Tuple { | ||
|
||
public Integer first; | ||
public Integer second; | ||
|
||
public Tuple() { | ||
} | ||
|
||
public Tuple(Integer first, Integer second) { | ||
this.first = first; | ||
this.second = second; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Tuple that = (Tuple) o; | ||
|
||
if (first != null ? !first.equals(that.first) : that.first != null) return false; | ||
return second != null ? second.equals(that.second) : that.second == null; | ||
} | ||
|
||
} |
This file contains 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,16 @@ | ||
# Chapter 13: Hash Tables | ||
|
||
* 13.1 PalindromicPermutations | ||
* 13.2 IsLetterConstructable | ||
* 13.3 LRUCache | ||
* 13.4 ComputeLCA | ||
* 13.5 ComputeKMostFrequent | ||
* 13.6 NearestRepeated | ||
* 13.7 SmallestSubarray | ||
* 13.8 SmallestSequentialSubarray | ||
* 13.9 LongestSubarray | ||
* 13.10 LongestContainedInterval | ||
* 13.11 ComputeAverageTopThree | ||
* 13.12 ComputeStringDecompositions | ||
* 13.13 CollatzConjecture | ||
* 13.14 HashFunctionChess |
This file contains 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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>elements-of-programming-interviews</artifactId> | ||
<groupId>gardncl</groupId> | ||
<version>1.5</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>hashtables</artifactId> | ||
<name>Chapter 13: Hash Tables</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>gardncl</groupId> | ||
<artifactId>datastructures</artifactId> | ||
<version>1.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>gardncl</groupId> | ||
<artifactId>utils</artifactId> | ||
<version>1.4</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
This file contains 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,13 @@ | ||
public class CollatzConjecture { | ||
|
||
/* | ||
13.13 | ||
Test the Collatz conjecture for the first n positive integers. | ||
*/ | ||
|
||
public static boolean testCollatzConjecture(int n) { | ||
|
||
return false; | ||
} | ||
} |
This file contains 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,28 @@ | ||
import java.util.Iterator; | ||
|
||
public class ComputeAverageTopThree { | ||
|
||
/* | ||
13.11 | ||
Write a program which takes as input a file containing test | ||
scores and returns the student who has the maximum score | ||
averaged across his or her top three tests. If the student | ||
has fewer that three test scores, ignore that student. | ||
*/ | ||
|
||
public static class NameScore { | ||
public String name; | ||
public Integer score; | ||
|
||
public NameScore(String name, Integer score) { | ||
this.name = name; | ||
this.score = score; | ||
} | ||
} | ||
|
||
public static String findStudent(Iterator<NameScore> iterator) { | ||
|
||
return ""; | ||
} | ||
} |
This file contains 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 @@ | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ComputeKMostFrequent { | ||
|
||
/* | ||
13.5 | ||
You are given an array of strings. Compute the | ||
k strings that appear most frequently in the array. | ||
*/ | ||
|
||
public static List<String> mostFrequent(List<String> list, int k) { | ||
|
||
return Collections.emptyList(); | ||
} | ||
} |
This file contains 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,15 @@ | ||
public class ComputeLCA { | ||
|
||
/* | ||
13.4 | ||
Design an algorithm for computing the LCA of two nodes | ||
in a binary tree. The algorithm's time complexity | ||
should depend only on the distance from the nodes to the LCA. | ||
*/ | ||
|
||
public static BinaryTreeParent<Integer> LCA(BinaryTreeParent<Integer> node0, BinaryTreeParent<Integer> node1) { | ||
|
||
return new BinaryTreeParent<>(0); | ||
} | ||
} |
This file contains 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,19 @@ | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ComputeStringDecompositions { | ||
|
||
/* | ||
13.12 | ||
Write a program which takes as input a string (the "sentence") | ||
and an array of strings (the "words"), and returns the starting | ||
indices of substrings of the sentence string which are the | ||
concatenation of all the strings in the words array. | ||
*/ | ||
|
||
public static List<String> findAllSubstring(String s, List<String> words) { | ||
|
||
return Collections.emptyList(); | ||
} | ||
} |
This file contains 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,13 @@ | ||
public class HashFunctionChess { | ||
|
||
/* | ||
13.14 | ||
Design a hash function for chess game states. | ||
Your function should take a state and the hash | ||
code for that state, and a move, and efficiently | ||
compute the hash code for the updated state. | ||
*/ | ||
|
||
|
||
} |
This file contains 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,18 @@ | ||
public class IsLetterConstructable { | ||
|
||
/* | ||
13.2 | ||
Write a program which takes text for an anonymous letter and text | ||
for a magazine and determines if it is possible to write the | ||
anonymous letter using the magazine. The anonymous letter can be | ||
written using the magazine if for each character in the anonymous | ||
letter, the number of times it appears in the anonymous letter is | ||
no more tha the number of times it appears in the magazine. | ||
*/ | ||
|
||
public static boolean isConstructable(String letterText, String magazineText) { | ||
|
||
return false; | ||
} | ||
} |
This file contains 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,35 @@ | ||
public class LRUCache { | ||
|
||
/* | ||
13.3 | ||
Create a cache for looking up prices of books identified | ||
by their ISBN. You implement lookup, insert, and remove | ||
methods. Use the Least Recently Used (LRU) policy for | ||
cache eviction. If an ISBN is already present, insert | ||
should not change the price, but it should update that | ||
entry to be the most recently used entry. Lookup should | ||
also update that entry to be the most recently used entry. | ||
*/ | ||
|
||
private int capacity; | ||
|
||
public LRUCache(int capacity) { | ||
this.capacity = capacity; | ||
} | ||
|
||
public Integer lookup(Integer key) { | ||
|
||
return 0; | ||
} | ||
|
||
public Integer insert(Integer key, Integer value) { | ||
|
||
return 0; | ||
} | ||
|
||
public Integer remove(Integer key) { | ||
|
||
return 0; | ||
} | ||
} |
This file contains 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,18 @@ | ||
import java.util.List; | ||
|
||
public class LongestContainedInterval { | ||
|
||
/* | ||
13.10 | ||
Write a program which takes as input a set of integers represented | ||
by an array, and returns the size of a largest subset of integers | ||
in the array having the property that if two integers are in the | ||
subset, then so are all integers between them. | ||
*/ | ||
|
||
public static int longestInterval(List<Integer> list) { | ||
|
||
return 0; | ||
} | ||
} |
This file contains 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 @@ | ||
import java.util.List; | ||
|
||
public class LongestSubarray { | ||
|
||
/* | ||
13.9 | ||
Write a program that takes an array and returns the | ||
length of a longest subarray with the property that | ||
all its elements are distinct. | ||
*/ | ||
|
||
public static int longestSubarray(List<Integer> list) { | ||
|
||
return 0; | ||
} | ||
} |
This file contains 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,16 @@ | ||
import java.util.List; | ||
|
||
public class NearestRepeated { | ||
|
||
/* | ||
13.6 | ||
Write a program which takes as input an array and finds the distance | ||
between a closest pair of equal entries. | ||
*/ | ||
|
||
public static int findNearest(List<String> list) { | ||
|
||
return 0; | ||
} | ||
} |
This file contains 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,15 @@ | ||
public class PalindromicPermutations { | ||
|
||
/* | ||
13.1 | ||
Write a program to test whether the letters forming a string | ||
can be permuted to form a palindrome. For example, "edified" | ||
can be permuted to form "deified". | ||
*/ | ||
|
||
public static boolean canFormPalindrome(String s) { | ||
|
||
return false; | ||
} | ||
} |
This file contains 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,21 @@ | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class SmallestSequentialSubarray { | ||
|
||
/* | ||
13.8 | ||
Write a program that takes two arrays of strings, and | ||
return the indices of the starting and ending index of | ||
a shortest subarray of the first array that | ||
'sequentially covers' in the order in which they appear | ||
in the keywords array. You can assume all keywords are | ||
distinct. | ||
*/ | ||
|
||
public static Tuple findSubarray(List<String> paragraph, Set<String> keywords) { | ||
|
||
return new Tuple(0,0); | ||
} | ||
} |
This file contains 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,20 @@ | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class SmallestSubarray { | ||
|
||
/* | ||
13.7 | ||
Write a program which takes an array of strings | ||
and a set of strings, and returns the indices of | ||
the starting and ending index of a shortest | ||
subarray of the given array that "covers" the set, | ||
i.e., contains all strings in the set. | ||
*/ | ||
|
||
public static Tuple findSubarray(List<String> paragraph, Set<String> keywords) { | ||
|
||
return new Tuple(0,0); | ||
} | ||
} |
Oops, something went wrong.