use of iurii.job.interview.utils.pair.Pair in project algorithms by Iurii-Dziuban.
the class IslandSearch method expandIslandReturnSquareWithoutRecursionBFS.
private static int expandIslandReturnSquareWithoutRecursionBFS(int[][] islandMatrix, int i, int j) {
if (islandMatrix[i][j] == 0) {
return 0;
}
Queue<Pair> queue = new ArrayDeque<Pair>();
queue.add(new Pair(i, j));
int sum = 0;
while (!queue.isEmpty()) {
Pair element = queue.poll();
int curI = element.getFirst();
int curJ = element.getSecond();
if (islandMatrix[curI][curJ] != 0) {
sum += 1;
islandMatrix[curI][curJ] = 0;
// up, down left, right
addToQueueIfIsland(islandMatrix, queue, curI + 1, curJ);
addToQueueIfIsland(islandMatrix, queue, curI, curJ + 1);
addToQueueIfIsland(islandMatrix, queue, curI - 1, curJ);
addToQueueIfIsland(islandMatrix, queue, curI, curJ - 1);
// south-west, south-east, north-west, north-east
addToQueueIfIsland(islandMatrix, queue, curI + 1, curJ + 1);
addToQueueIfIsland(islandMatrix, queue, curI + 1, curJ - 1);
addToQueueIfIsland(islandMatrix, queue, curI - 1, curJ + 1);
addToQueueIfIsland(islandMatrix, queue, curI - 1, curJ - 1);
}
}
return sum;
}
use of iurii.job.interview.utils.pair.Pair in project algorithms by Iurii-Dziuban.
the class InverseFind method merge.
public int[] merge(int[] firstHalf, int[] secondHalf) {
int totalLength = firstHalf.length + secondHalf.length;
int[] result = new int[totalLength];
int i = 0;
int j = 0;
for (int index = 0; index < totalLength; index++) {
if (i == firstHalf.length || j < secondHalf.length && firstHalf[i] > secondHalf[j]) {
for (int k = i; k < firstHalf.length; k++) {
list.add(new Pair(firstHalf[k], secondHalf[j]));
count++;
}
result[index] = secondHalf[j++];
} else {
result[index] = firstHalf[i++];
}
}
return result;
}
use of iurii.job.interview.utils.pair.Pair in project algorithms by Iurii-Dziuban.
the class ProcessorsForTasksTest method testNegative.
@Test
public void testNegative() {
List<Pair> pairs = new ArrayList<>();
pairs.add(new Pair(1481122000, 1481122025));
pairs.add(new Pair(1481122030, 1481122045));
pairs.add(new Pair(1481122050, 1481122070));
assertThat(processorsForTasks.findTotalNumberOfProcessorsNeededWithTimeline(pairs)).isEqualTo(1);
}
use of iurii.job.interview.utils.pair.Pair in project algorithms by Iurii-Dziuban.
the class ProcessorsForTasksTest method testSimple.
@Test
public void testSimple() {
List<Pair> pairs = new ArrayList<>();
pairs.add(new Pair(1481122000, 1481122020));
pairs.add(new Pair(1481122000, 1481122040));
pairs.add(new Pair(1481122030, 1481122035));
assertThat(processorsForTasks.findTotalNumberOfProcessorsNeededWithTimeline(pairs)).isEqualTo(2);
}
use of iurii.job.interview.utils.pair.Pair in project algorithms by Iurii-Dziuban.
the class CustomerServiceCapacityTest method testOne.
@Test
public void testOne() {
List<Pair> pairs = new ArrayList<>();
pairs.add(new Pair(1481122000, 1481122020));
pairs.add(new Pair(1481122020, 1481122040));
pairs.add(new Pair(1481122040, 1481122050));
assertThat(serviceCapacity.findNeededNumberOfEmployers(1, pairs)).isEqualTo(0);
}
Aggregations