diff --git a/src/main/java/g1301_1400/s1331_rank_transform_of_an_array/Solution.java b/src/main/java/g1301_1400/s1331_rank_transform_of_an_array/Solution.java new file mode 100644 index 000000000..ca258fc15 --- /dev/null +++ b/src/main/java/g1301_1400/s1331_rank_transform_of_an_array/Solution.java @@ -0,0 +1,28 @@ +package g1301_1400.s1331_rank_transform_of_an_array; + +// #Easy #Array #Hash_Table #Sorting #2022_03_19_Time_22_ms_(98.50%)_Space_58.4_MB_(93.72%) + +import java.util.Arrays; +import java.util.HashMap; + +@SuppressWarnings({}) +public class Solution { + public int[] arrayRankTransform(int[] arr) { + + int[] tmp = Arrays.copyOf(arr, arr.length); + Arrays.sort(tmp); + HashMap mp = new HashMap<>(); + int i = 1; + for (Integer x : tmp) { + if (!mp.containsKey(x)) { + mp.put(x, i++); + } + } + + i = 0; + for (Integer x : arr) { + arr[i++] = mp.get(x); + } + return arr; + } +} diff --git a/src/main/java/g1301_1400/s1331_rank_transform_of_an_array/readme.md b/src/main/java/g1301_1400/s1331_rank_transform_of_an_array/readme.md new file mode 100644 index 000000000..a16bc6087 --- /dev/null +++ b/src/main/java/g1301_1400/s1331_rank_transform_of_an_array/readme.md @@ -0,0 +1,38 @@ +1331\. Rank Transform of an Array + +Easy + +Given an array of integers `arr`, replace each element with its rank. + +The rank represents how large the element is. The rank has the following rules: + +* Rank is an integer starting from 1. +* The larger the element, the larger the rank. If two elements are equal, their rank must be the same. +* Rank should be as small as possible. + +**Example 1:** + +**Input:** arr = [40,10,20,30] + +**Output:** [4,1,2,3] + +**Explanation:**: 40 is the largest element. 10 is the smallest. 20 is the second smallest. 30 is the third smallest. + +**Example 2:** + +**Input:** arr = [100,100,100] + +**Output:** [1,1,1] + +**Explanation:**: Same elements share the same rank. + +**Example 3:** + +**Input:** arr = [37,12,28,9,100,56,80,5,12] + +**Output:** [5,3,4,2,8,6,7,1,3] + +**Constraints:** + +* 0 <= arr.length <= 105 +* -109 <= arr[i] <= 109 \ No newline at end of file diff --git a/src/main/java/g1301_1400/s1332_remove_palindromic_subsequences/Solution.java b/src/main/java/g1301_1400/s1332_remove_palindromic_subsequences/Solution.java new file mode 100644 index 000000000..735c9033a --- /dev/null +++ b/src/main/java/g1301_1400/s1332_remove_palindromic_subsequences/Solution.java @@ -0,0 +1,15 @@ +package g1301_1400.s1332_remove_palindromic_subsequences; + +// #Easy #String #Two_Pointers #2022_03_19_Time_0_ms_(100.00%)_Space_39.9_MB_(78.40%) + +public class Solution { + public int removePalindromeSub(String s) { + if (s.isEmpty()) { + return 0; + } + if (s.equals((new StringBuilder(s)).reverse().toString())) { + return 1; + } + return 2; + } +} diff --git a/src/main/java/g1301_1400/s1332_remove_palindromic_subsequences/readme.md b/src/main/java/g1301_1400/s1332_remove_palindromic_subsequences/readme.md new file mode 100644 index 000000000..4f6dde6d6 --- /dev/null +++ b/src/main/java/g1301_1400/s1332_remove_palindromic_subsequences/readme.md @@ -0,0 +1,40 @@ +1332\. Remove Palindromic Subsequences + +Easy + +You are given a string `s` consisting **only** of letters `'a'` and `'b'`. In a single step you can remove one **palindromic subsequence** from `s`. + +Return _the **minimum** number of steps to make the given string empty_. + +A string is a **subsequence** of a given string if it is generated by deleting some characters of a given string without changing its order. Note that a subsequence does **not** necessarily need to be contiguous. + +A string is called **palindrome** if is one that reads the same backward as well as forward. + +**Example 1:** + +**Input:** s = "ababa" + +**Output:** 1 + +**Explanation:** s is already a palindrome, so its entirety can be removed in a single step. + +**Example 2:** + +**Input:** s = "abb" + +**Output:** 2 + +**Explanation:** "abb" -> "bb" -> "". Remove palindromic subsequence "a" then "bb". + +**Example 3:** + +**Input:** s = "baabb" + +**Output:** 2 + +**Explanation:** "baabb" -> "b" -> "". Remove palindromic subsequence "baab" then "b". + +**Constraints:** + +* `1 <= s.length <= 1000` +* `s[i]` is either `'a'` or `'b'`. \ No newline at end of file diff --git a/src/main/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/Solution.java b/src/main/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/Solution.java new file mode 100644 index 000000000..46c90f0d9 --- /dev/null +++ b/src/main/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/Solution.java @@ -0,0 +1,23 @@ +package g1301_1400.s1333_filter_restaurants_by_vegan_friendly_price_and_distance; + +// #Medium #Array #Sorting #2022_03_19_Time_10_ms_(55.43%)_Space_58_MB_(52.00%) + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class Solution { + public List filterRestaurants( + int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) { + List list = new ArrayList<>(); + for (int[] restaurant : restaurants) { + if (((veganFriendly == 1 && restaurant[2] == 1) || veganFriendly == 0) + && restaurant[3] <= maxPrice + && restaurant[4] <= maxDistance) { + list.add(restaurant); + } + } + list.sort((a, b) -> b[1] - a[1] == 0 ? b[0] - a[0] : b[1] - a[1]); + return list.stream().map(restaurant -> restaurant[0]).collect(Collectors.toList()); + } +} diff --git a/src/main/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/readme.md b/src/main/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/readme.md new file mode 100644 index 000000000..6a45b5657 --- /dev/null +++ b/src/main/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/readme.md @@ -0,0 +1,52 @@ +1333\. Filter Restaurants by Vegan-Friendly, Price and Distance + +Medium + +Given the array `restaurants` where restaurants[i] = [idi, ratingi, veganFriendlyi, pricei, distancei]. You have to filter the restaurants using three filters. + +The `veganFriendly` filter will be either _true_ (meaning you should only include restaurants with veganFriendlyi set to true) or _false_ (meaning you can include any restaurant). In addition, you have the filters `maxPrice` and `maxDistance` which are the maximum value for price and distance of restaurants you should consider respectively. + +Return the array of restaurant _**IDs**_ after filtering, ordered by **rating** from highest to lowest. For restaurants with the same rating, order them by _**id**_ from highest to lowest. For simplicity veganFriendlyi and `veganFriendly` take value _1_ when it is _true_, and _0_ when it is _false_. + +**Example 1:** + +**Input:** restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 1, maxPrice = 50, maxDistance = 10 + +**Output:** [3,1,5] + +**Explanation:** The restaurants are: + +Restaurant 1 [id=1, rating=4, veganFriendly=1, price=40, distance=10] + +Restaurant 2 [id=2, rating=8, veganFriendly=0, price=50, distance=5] + +Restaurant 3 [id=3, rating=8, veganFriendly=1, price=30, distance=4] + +Restaurant 4 [id=4, rating=10, veganFriendly=0, price=10, distance=3] + +Restaurant 5 [id=5, rating=1, veganFriendly=1, price=15, distance=1] + +After filter restaurants with veganFriendly = 1, maxPrice = 50 and maxDistance = 10 we have restaurant 3, restaurant 1 and restaurant 5 (ordered by rating from highest to lowest). + +**Example 2:** + +**Input:** restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 50, maxDistance = 10 + +**Output:** [4,3,2,1,5] + +**Explanation:** The restaurants are the same as in example 1, but in this case the filter veganFriendly = 0, therefore all restaurants are considered. + +**Example 3:** + +**Input:** restaurants = [[1,4,1,40,10],[2,8,0,50,5],[3,8,1,30,4],[4,10,0,10,3],[5,1,1,15,1]], veganFriendly = 0, maxPrice = 30, maxDistance = 3 + +**Output:** [4,5] + +**Constraints:** + +* `1 <= restaurants.length <= 10^4` +* `restaurants[i].length == 5` +* 1 <= idi, ratingi, pricei, distancei <= 10^5 +* `1 <= maxPrice, maxDistance <= 10^5` +* veganFriendlyi and `veganFriendly` are 0 or 1. +* All idi are distinct. \ No newline at end of file diff --git a/src/main/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/Solution.java b/src/main/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/Solution.java new file mode 100644 index 000000000..7fbc3c635 --- /dev/null +++ b/src/main/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/Solution.java @@ -0,0 +1,70 @@ +package g1301_1400.s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance; + +// #Medium #Dynamic_Programming #Graph #Shortest_Path +// #2022_03_19_Time_21_ms_(49.75%)_Space_47_MB_(36.59%) + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class Solution { + public int findTheCity(int n, int[][] edges, int maxDist) { + int[][] graph = new int[n][n]; + for (int[] edge : edges) { + graph[edge[0]][edge[1]] = edge[2]; + graph[edge[1]][edge[0]] = edge[2]; + } + return fllowdWarshall(graph, n, maxDist); + } + + private int fllowdWarshall(int[][] graph, int n, int maxDist) { + int inf = 10001; + int[][] dist = new int[n][n]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i != j && graph[i][j] == 0) { + dist[i][j] = inf; + } else { + dist[i][j] = graph[i][j]; + } + } + } + for (int k = 0; k < n; k++) { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (dist[i][k] + dist[k][j] < dist[i][j]) { + dist[i][j] = dist[i][k] + dist[k][j]; + } + } + } + } + return getList(dist, n, maxDist); + } + + private int getList(int[][] dist, int n, int maxDist) { + HashMap> map = new HashMap<>(); + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + + if (!map.containsKey(i)) { + map.put(i, new ArrayList<>()); + if (dist[i][j] <= maxDist && i != j) { + map.get(i).add(j); + } + } else if (map.containsKey(i) && dist[i][j] <= maxDist && i != j) { + + map.get(i).add(j); + } + } + } + int numOfEle = Integer.MAX_VALUE; + int ans = 0; + for (int i = 0; i < n; i++) { + if (numOfEle >= map.get(i).size()) { + numOfEle = Math.min(numOfEle, map.get(i).size()); + ans = i; + } + } + return ans; + } +} diff --git a/src/main/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/readme.md b/src/main/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/readme.md new file mode 100644 index 000000000..73a934acd --- /dev/null +++ b/src/main/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/readme.md @@ -0,0 +1,64 @@ +1334\. Find the City With the Smallest Number of Neighbors at a Threshold Distance + +Medium + +There are `n` cities numbered from `0` to `n-1`. Given the array `edges` where edges[i] = [fromi, toi, weighti] represents a bidirectional and weighted edge between cities fromi and toi, and given the integer `distanceThreshold`. + +Return the city with the smallest number of cities that are reachable through some path and whose distance is **at most** `distanceThreshold`, If there are multiple such cities, return the city with the greatest number. + +Notice that the distance of a path connecting cities _**i**_ and _**j**_ is equal to the sum of the edges' weights along that path. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/01/16/find_the_city_01.png) + +**Input:** n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4 + +**Output:** 3 + +**Explanation:** The figure above describes the graph. + +The neighboring cities at a distanceThreshold = 4 for each city are: + +City 0 -> [City 1, City 2] + +City 1 -> [City 0, City 2, City 3] + +City 2 -> [City 0, City 1, City 3] + +City 3 -> [City 1, City 2] + +Cities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have to return city 3 since it has the greatest number. + +**Example 2:** + +![](https://assets.leetcode.com/uploads/2020/01/16/find_the_city_02.png) + +**Input:** n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2 + +**Output:** 0 + +**Explanation:** The figure above describes the graph. + +The neighboring cities at a distanceThreshold = 2 for each city are: + +City 0 -> [City 1] + +City 1 -> [City 0, City 4] + +City 2 -> [City 3, City 4] + +City 3 -> [City 2, City 4] + +City 4 -> [City 1, City 2, City 3] + +The city 0 has 1 neighboring city at a distanceThreshold = 2. + +**Constraints:** + +* `2 <= n <= 100` +* `1 <= edges.length <= n * (n - 1) / 2` +* `edges[i].length == 3` +* 0 <= fromi < toi < n +* 1 <= weighti, distanceThreshold <= 10^4 +* All pairs (fromi, toi) are distinct. \ No newline at end of file diff --git a/src/main/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/Solution.java b/src/main/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/Solution.java new file mode 100644 index 000000000..1505d3bc9 --- /dev/null +++ b/src/main/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/Solution.java @@ -0,0 +1,41 @@ +package g1301_1400.s1335_minimum_difficulty_of_a_job_schedule; + +// #Hard #Array #Dynamic_Programming #2022_03_19_Time_11_ms_(79.28%)_Space_41.6_MB_(59.99%) + +public class Solution { + public int minDifficulty(int[] jobDifficulty, int d) { + int totalJobs = jobDifficulty.length; + if (totalJobs < d) { + return -1; + } + + int maxJobsOneDay = totalJobs - d + 1; + int[] map = new int[totalJobs]; + + int maxDiff = Integer.MIN_VALUE; + for (int k = totalJobs - 1; k > totalJobs - 1 - maxJobsOneDay; k--) { + maxDiff = Math.max(maxDiff, jobDifficulty[k]); + map[k] = maxDiff; + } + + for (int day = d - 1; day > 0; day--) { + + int maxEndIndex = (totalJobs - 1) - (d - day); + int maxStartIndex = maxEndIndex - maxJobsOneDay + 1; + + for (int startIndex = maxStartIndex; startIndex <= maxEndIndex; startIndex++) { + map[startIndex] = Integer.MAX_VALUE; + int maxDiffOfTheDay = Integer.MIN_VALUE; + for (int endIndex = startIndex; endIndex <= maxEndIndex; endIndex++) { + maxDiffOfTheDay = Math.max(maxDiffOfTheDay, jobDifficulty[endIndex]); + + int totalDiff = maxDiffOfTheDay + map[endIndex + 1]; + + map[startIndex] = Math.min(map[startIndex], totalDiff); + } + } + } + + return map[0]; + } +} diff --git a/src/main/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/readme.md b/src/main/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/readme.md new file mode 100644 index 000000000..c04f06ebc --- /dev/null +++ b/src/main/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/readme.md @@ -0,0 +1,47 @@ +1335\. Minimum Difficulty of a Job Schedule + +Hard + +You want to schedule a list of jobs in `d` days. Jobs are dependent (i.e To work on the ith job, you have to finish all the jobs `j` where `0 <= j < i`). + +You have to finish **at least** one task every day. The difficulty of a job schedule is the sum of difficulties of each day of the `d` days. The difficulty of a day is the maximum difficulty of a job done on that day. + +You are given an integer array `jobDifficulty` and an integer `d`. The difficulty of the ith job is `jobDifficulty[i]`. + +Return _the minimum difficulty of a job schedule_. If you cannot find a schedule for the jobs return `-1`. + +**Example 1:** + +![](https://assets.leetcode.com/uploads/2020/01/16/untitled.png) + +**Input:** jobDifficulty = [6,5,4,3,2,1], d = 2 + +**Output:** 7 + +**Explanation:** First day you can finish the first 5 jobs, total difficulty = 6. + +Second day you can finish the last job, total difficulty = 1. + +The difficulty of the schedule = 6 + 1 = 7 + +**Example 2:** + +**Input:** jobDifficulty = [9,9,9], d = 4 + +**Output:** -1 + +**Explanation:** If you finish a job per day you will still have a free day. you cannot find a schedule for the given jobs. + +**Example 3:** + +**Input:** jobDifficulty = [1,1,1], d = 3 + +**Output:** 3 + +**Explanation:** The schedule is one job per day. total difficulty will be 3. + +**Constraints:** + +* `1 <= jobDifficulty.length <= 300` +* `0 <= jobDifficulty[i] <= 1000` +* `1 <= d <= 10` \ No newline at end of file diff --git a/src/test/java/g1301_1400/s1331_rank_transform_of_an_array/SolutionTest.java b/src/test/java/g1301_1400/s1331_rank_transform_of_an_array/SolutionTest.java new file mode 100644 index 000000000..454c8937c --- /dev/null +++ b/src/test/java/g1301_1400/s1331_rank_transform_of_an_array/SolutionTest.java @@ -0,0 +1,29 @@ +package g1301_1400.s1331_rank_transform_of_an_array; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void arrayRankTransform() { + assertThat( + new Solution().arrayRankTransform(new int[] {40, 10, 20, 30}), + equalTo(new int[] {4, 1, 2, 3})); + } + + @Test + void arrayRankTransform2() { + assertThat( + new Solution().arrayRankTransform(new int[] {100, 100, 100}), + equalTo(new int[] {1, 1, 1})); + } + + @Test + void arrayRankTransform3() { + assertThat( + new Solution().arrayRankTransform(new int[] {37, 12, 28, 9, 100, 56, 80, 5, 12}), + equalTo(new int[] {5, 3, 4, 2, 8, 6, 7, 1, 3})); + } +} diff --git a/src/test/java/g1301_1400/s1332_remove_palindromic_subsequences/SolutionTest.java b/src/test/java/g1301_1400/s1332_remove_palindromic_subsequences/SolutionTest.java new file mode 100644 index 000000000..2d3bd0982 --- /dev/null +++ b/src/test/java/g1301_1400/s1332_remove_palindromic_subsequences/SolutionTest.java @@ -0,0 +1,23 @@ +package g1301_1400.s1332_remove_palindromic_subsequences; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void removePalindromeSub() { + assertThat(new Solution().removePalindromeSub("ababa"), equalTo(1)); + } + + @Test + void removePalindromeSub2() { + assertThat(new Solution().removePalindromeSub("abb"), equalTo(2)); + } + + @Test + void removePalindromeSub3() { + assertThat(new Solution().removePalindromeSub("baabb"), equalTo(2)); + } +} diff --git a/src/test/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/SolutionTest.java b/src/test/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/SolutionTest.java new file mode 100644 index 000000000..39d6e6e66 --- /dev/null +++ b/src/test/java/g1301_1400/s1333_filter_restaurants_by_vegan_friendly_price_and_distance/SolutionTest.java @@ -0,0 +1,54 @@ +package g1301_1400.s1333_filter_restaurants_by_vegan_friendly_price_and_distance; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.Arrays; +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void filterRestaurants() { + int[][] restaurants = + new int[][] { + {1, 4, 1, 40, 10}, + {2, 8, 0, 50, 5}, + {3, 8, 1, 30, 4}, + {4, 10, 0, 10, 3}, + {5, 1, 1, 15, 1} + }; + assertThat( + new Solution().filterRestaurants(restaurants, 1, 50, 10), + equalTo(Arrays.asList(3, 1, 5))); + } + + @Test + void filterRestaurants2() { + int[][] restaurants = + new int[][] { + {1, 4, 1, 40, 10}, + {2, 8, 0, 50, 5}, + {3, 8, 1, 30, 4}, + {4, 10, 0, 10, 3}, + {5, 1, 1, 15, 1} + }; + assertThat( + new Solution().filterRestaurants(restaurants, 0, 50, 10), + equalTo(Arrays.asList(4, 3, 2, 1, 5))); + } + + @Test + void filterRestaurants3() { + int[][] restaurants = + new int[][] { + {1, 4, 1, 40, 10}, + {2, 8, 0, 50, 5}, + {3, 8, 1, 30, 4}, + {4, 10, 0, 10, 3}, + {5, 1, 1, 15, 1} + }; + assertThat( + new Solution().filterRestaurants(restaurants, 0, 30, 3), + equalTo(Arrays.asList(4, 5))); + } +} diff --git a/src/test/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/SolutionTest.java b/src/test/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/SolutionTest.java new file mode 100644 index 000000000..553b56b2e --- /dev/null +++ b/src/test/java/g1301_1400/s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance/SolutionTest.java @@ -0,0 +1,21 @@ +package g1301_1400.s1334_find_the_city_with_the_smallest_number_of_neighbors_at_a_threshold_distance; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void findTheCity() { + int[][] edges = new int[][] {{0, 1, 3}, {1, 2, 1}, {1, 3, 4}, {2, 3, 1}}; + assertThat(new Solution().findTheCity(4, edges, 4), equalTo(3)); + } + + @Test + void findTheCity2() { + int[][] edges = + new int[][] {{0, 1, 2}, {0, 4, 8}, {1, 2, 3}, {1, 4, 2}, {2, 3, 1}, {3, 4, 1}}; + assertThat(new Solution().findTheCity(5, edges, 2), equalTo(0)); + } +} diff --git a/src/test/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/SolutionTest.java b/src/test/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/SolutionTest.java new file mode 100644 index 000000000..fd987d5f1 --- /dev/null +++ b/src/test/java/g1301_1400/s1335_minimum_difficulty_of_a_job_schedule/SolutionTest.java @@ -0,0 +1,23 @@ +package g1301_1400.s1335_minimum_difficulty_of_a_job_schedule; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.jupiter.api.Test; + +class SolutionTest { + @Test + void minDifficulty() { + assertThat(new Solution().minDifficulty(new int[] {6, 5, 4, 3, 2, 1}, 2), equalTo(7)); + } + + @Test + void minDifficulty2() { + assertThat(new Solution().minDifficulty(new int[] {9, 9, 9}, 4), equalTo(-1)); + } + + @Test + void minDifficulty3() { + assertThat(new Solution().minDifficulty(new int[] {1, 1, 1}, 3), equalTo(3)); + } +}