Skip to content

Commit a72ceff

Browse files
committed
release v1.8
2 parents ce1c486 + bd84fc4 commit a72ceff

24 files changed

Lines changed: 648 additions & 0 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class DuplicateAndMissing {
2+
3+
public Integer duplicate;
4+
public Integer missing;
5+
6+
public DuplicateAndMissing() {
7+
}
8+
9+
public DuplicateAndMissing(Integer duplicate, Integer missing) {
10+
this.duplicate = duplicate;
11+
this.missing = missing;
12+
}
13+
14+
@Override
15+
public boolean equals(Object o) {
16+
if (this == o) return true;
17+
if (o == null || getClass() != o.getClass()) return false;
18+
19+
DuplicateAndMissing that = (DuplicateAndMissing) o;
20+
21+
if (duplicate != null ? !duplicate.equals(that.duplicate) : that.duplicate != null) return false;
22+
return missing != null ? missing.equals(that.missing) : that.missing == null;
23+
}
24+
25+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class MinMax {
2+
public Integer min;
3+
public Integer max;
4+
5+
public MinMax(Integer min, Integer max) {
6+
this.min = min;
7+
this.max = max;
8+
}
9+
10+
@Override
11+
public boolean equals(Object o) {
12+
if (this == o) return true;
13+
if (o == null || getClass() != o.getClass()) return false;
14+
15+
MinMax minMax = (MinMax) o;
16+
17+
if (min != null ? !min.equals(minMax.min) : minMax.min != null) return false;
18+
return max != null ? max.equals(minMax.max) : minMax.max == null;
19+
}
20+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<module>stacksandqueues</module>
1717
<module>binarytrees</module>
1818
<module>heaps</module>
19+
<module>searching</module>
1920
</modules>
2021
<packaging>pom</packaging>
2122

searching/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Chapter 12: Searching
2+
3+
* 12.1 SearchSorted
4+
* 12.2 SearchSortedIndex
5+
* 12.3 SearchSortedCyclic
6+
* 12.4 IntegerSquareRoot
7+
* 12.5 RealSquareRoot
8+
* 12.6 SearchSorted2D
9+
* 12.7 FindMinAndMax
10+
* 12.8 FindKthLargest
11+
* 12.9 FindMissingIP
12+
* 12.10 FindDuplicateAndMissing

searching/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>elements-of-programming-interviews</artifactId>
7+
<groupId>gardncl</groupId>
8+
<version>1.5</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>searching</artifactId>
13+
<name>Chapter 12: Searching</name>
14+
<dependencies>
15+
<dependency>
16+
<groupId>gardncl</groupId>
17+
<artifactId>datastructures</artifactId>
18+
<version>1.4</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>gardncl</groupId>
22+
<artifactId>utils</artifactId>
23+
<version>1.4</version>
24+
</dependency>
25+
</dependencies>
26+
27+
28+
29+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.List;
2+
3+
public class FindDuplicateAndMissing {
4+
5+
/*
6+
12.10
7+
8+
You are given an array of n integers, each between 0 and n - 1,
9+
inclusive. Exactly one element appears twice, implying exactly
10+
one number between 0 and n - 1 is missing from the array. How
11+
would you compute the duplicate and missing numbers?
12+
*/
13+
14+
public static DuplicateAndMissing search(List<Integer> list) {
15+
16+
return new DuplicateAndMissing(0,0);
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.List;
2+
3+
public class FindKthLargest {
4+
5+
/*
6+
12.8
7+
8+
Design an algorithm for computing the kth largest
9+
element in an array. Assume entries are distinct.
10+
*/
11+
12+
public static int findKth(List<Integer> list, int k) {
13+
14+
return 0;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.List;
2+
3+
public class FindMinAndMax {
4+
5+
/*
6+
12.7
7+
8+
Design an algorithm to find the min and max elements in an array.
9+
*/
10+
11+
public static MinMax findMinMax(List<Integer> list) {
12+
13+
return new MinMax(0,0);
14+
}
15+
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class FindMissingIP {
2+
3+
/*
4+
12.9
5+
6+
Suppose you were given a file containing roughly one billion
7+
IP addresses, each of which is a 32-bit quantity. How would
8+
you programmatically find an IP address that is not in the file?
9+
Assume you have unlimited drive space but only a few megabytes
10+
of RAM at your disposal.
11+
*/
12+
13+
private static int search(Iterable<Integer> sequence) {
14+
15+
return 0;
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class IntegerSquareRoot {
2+
3+
/*
4+
12.4
5+
6+
Write a program which takes a non-negative integer and
7+
returns the largest integer whose square is less that
8+
or equal to the given integer.
9+
*/
10+
11+
public static int squareRoot(int n) {
12+
13+
return 0;
14+
}
15+
}

0 commit comments

Comments
 (0)