Skip to content

Commit

Permalink
Adding plus time runner solution
Browse files Browse the repository at this point in the history
  • Loading branch information
josdem committed Apr 21, 2024
1 parent 816a369 commit f28d35e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions big-o/src/main/java/com/josdem/algorithms/PlusTimeRunner.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.josdem.algorithms;

import java.util.Arrays;
import java.util.List;

/* Type: Plus Time Algorithms – O(2a + b)
Description: Plus compute time algorithm
*/
public class PlusTimeRunner {

public List<Integer> getList() {
return null;
public List<Integer> createNewList(List<Integer> numbers) {
int min = numbers.stream().min(Integer::compare).orElseThrow(() -> new RuntimeException("No min value was found"));
int max = numbers.stream().max(Integer::compare).orElseThrow(() -> new RuntimeException("No max value was found"));
return Arrays.asList(new Integer[max - min + 1]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class PlusTimeRunnerTest {
@Test
@DisplayName("show plus time algorithm")
void shouldCreateCollectionWithFixedSize(){
List<Integer> numbers = List.of(3, 9, 15, 2, 11, 1, 18, 6, 4, 10);
int expectedSize = 16;
assertEquals(expectedSize, plusTimeRunner.getList().size(), "should have expected size");
List<Integer> numbers = List.of(3, 9, 15, 2, 11, 5, 19, 6, 4, 10);
int expectedSize = 18;
assertEquals(expectedSize, plusTimeRunner.createNewList(numbers).size(), "should have expected size");
}
}

0 comments on commit f28d35e

Please sign in to comment.