DatasetRepo commited on
Commit
2b2a8a8
·
verified ·
1 Parent(s): 383505c

009007153e1fb3c00adfa6056e3b4d69e5a432d0d5b347b5515111c51f9bc8ad

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -0
  2. maximum_prime_difference/meta.json +3 -0
  3. maximum_prime_difference/ocaml_tests/main.ml +0 -0
  4. maximum_prime_difference/scala_tests/MySuite.scala +0 -0
  5. maximum_product_after_k_increments/.DS_Store +0 -0
  6. maximum_product_after_k_increments/haskell_tests/Main.hs +24 -0
  7. maximum_product_after_k_increments/java_tests/Main.java +21 -0
  8. maximum_product_after_k_increments/meta.json +26 -0
  9. maximum_product_after_k_increments/ocaml_tests/main.ml +26 -0
  10. maximum_product_after_k_increments/scala_tests/MySuite.scala +12 -0
  11. maximum_rows_covered_by_columns/.DS_Store +0 -0
  12. maximum_rows_covered_by_columns/haskell_tests/Main.hs +24 -0
  13. maximum_rows_covered_by_columns/java_tests/Main.java +21 -0
  14. maximum_rows_covered_by_columns/meta.json +26 -0
  15. maximum_rows_covered_by_columns/ocaml_tests/main.ml +26 -0
  16. maximum_rows_covered_by_columns/scala_tests/MySuite.scala +12 -0
  17. maximum_running_time_of_n_computers/.DS_Store +0 -0
  18. maximum_running_time_of_n_computers/haskell_tests/Main.hs +24 -0
  19. maximum_running_time_of_n_computers/java_tests/Main.java +21 -0
  20. maximum_running_time_of_n_computers/meta.json +0 -0
  21. maximum_running_time_of_n_computers/ocaml_tests/main.ml +26 -0
  22. maximum_running_time_of_n_computers/scala_tests/MySuite.scala +12 -0
  23. maximum_score_after_applying_operations_on_a_tree/haskell_tests/Main.hs +0 -0
  24. maximum_score_after_applying_operations_on_a_tree/java_tests/Main.java +21 -0
  25. maximum_score_after_applying_operations_on_a_tree/meta.json +3 -0
  26. maximum_score_after_applying_operations_on_a_tree/ocaml_tests/main.ml +0 -0
  27. maximum_score_after_applying_operations_on_a_tree/scala_tests/MySuite.scala +0 -0
  28. maximum_score_from_grid_operations/haskell_tests/Main.hs +0 -0
  29. maximum_score_from_grid_operations/java_tests/Main.java +20 -0
  30. maximum_score_from_grid_operations/meta.json +0 -0
  31. maximum_score_from_grid_operations/ocaml_tests/main.ml +0 -0
  32. maximum_score_from_grid_operations/scala_tests/MySuite.scala +0 -0
  33. maximum_score_of_a_node_sequence/.DS_Store +0 -0
  34. maximum_score_of_a_node_sequence/haskell_tests/Main.hs +24 -0
  35. maximum_score_of_a_node_sequence/java_tests/Main.java +21 -0
  36. maximum_score_of_a_node_sequence/meta.json +3 -0
  37. maximum_score_of_a_node_sequence/ocaml_tests/main.ml +26 -0
  38. maximum_score_of_a_node_sequence/scala_tests/MySuite.scala +12 -0
  39. maximum_segment_sum_after_removals/.DS_Store +0 -0
  40. maximum_segment_sum_after_removals/haskell_tests/Main.hs +24 -0
  41. maximum_segment_sum_after_removals/java_tests/Main.java +21 -0
  42. maximum_segment_sum_after_removals/meta.json +26 -0
  43. maximum_segment_sum_after_removals/ocaml_tests/main.ml +26 -0
  44. maximum_segment_sum_after_removals/scala_tests/MySuite.scala +12 -0
  45. maximum_size_of_a_set_after_removals/haskell_tests/Main.hs +45 -0
  46. maximum_size_of_a_set_after_removals/java_tests/Main.java +25 -0
  47. maximum_size_of_a_set_after_removals/meta.json +334 -0
  48. maximum_size_of_a_set_after_removals/ocaml_tests/main.ml +50 -0
  49. maximum_size_of_a_set_after_removals/scala_tests/MySuite.scala +44 -0
  50. maximum_spending_after_buying_items/haskell_tests/Main.hs +41 -0
.gitattributes CHANGED
@@ -185,3 +185,6 @@ maximum_or/meta.json filter=lfs diff=lfs merge=lfs -text
185
  maximum_points_after_collecting_coins_from_all_nodes/haskell_tests/Main.hs filter=lfs diff=lfs merge=lfs -text
186
  maximum_points_after_collecting_coins_from_all_nodes/meta.json filter=lfs diff=lfs merge=lfs -text
187
  maximum_points_after_collecting_coins_from_all_nodes/scala_tests/MySuite.scala filter=lfs diff=lfs merge=lfs -text
 
 
 
 
185
  maximum_points_after_collecting_coins_from_all_nodes/haskell_tests/Main.hs filter=lfs diff=lfs merge=lfs -text
186
  maximum_points_after_collecting_coins_from_all_nodes/meta.json filter=lfs diff=lfs merge=lfs -text
187
  maximum_points_after_collecting_coins_from_all_nodes/scala_tests/MySuite.scala filter=lfs diff=lfs merge=lfs -text
188
+ maximum_prime_difference/meta.json filter=lfs diff=lfs merge=lfs -text
189
+ maximum_score_after_applying_operations_on_a_tree/meta.json filter=lfs diff=lfs merge=lfs -text
190
+ maximum_score_of_a_node_sequence/meta.json filter=lfs diff=lfs merge=lfs -text
maximum_prime_difference/meta.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d5af2ad5c3a464a6a741cf51aeb1a3ceb184bb0c9bcf28c0bca89b5be3a88ba
3
+ size 16319832
maximum_prime_difference/ocaml_tests/main.ml ADDED
The diff for this file is too large to render. See raw diff
 
maximum_prime_difference/scala_tests/MySuite.scala ADDED
The diff for this file is too large to render. See raw diff
 
maximum_product_after_k_increments/.DS_Store ADDED
Binary file (6.15 kB). View file
 
maximum_product_after_k_increments/haskell_tests/Main.hs ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main where
3
+ import Test.HUnit
4
+
5
+ --Program start
6
+
7
+ --Program end
8
+
9
+ -- Test cases
10
+
11
+ test1 :: Test
12
+ test1 = TestCase (assertEqual "for (maximumProduct [0,4] 5)," 20 (maximumProduct [0,4] 5))
13
+
14
+ test2 :: Test
15
+ test2 = TestCase (assertEqual "for (maximumProduct [6,3,3,2] 2)," 216 (maximumProduct [6,3,3,2] 2))
16
+
17
+
18
+ -- Grouping test cases
19
+ tests :: Test
20
+ tests = TestList [TestLabel "Test1" test1]
21
+
22
+ -- Running the tests
23
+ main :: IO Counts
24
+ main = runTestTT tests
maximum_product_after_k_increments/java_tests/Main.java ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ public class Main {
8
+ //Program start
9
+
10
+ //Program end
11
+
12
+ @Test
13
+ public void test1() {
14
+ assertEquals(20, maximumProduct(new ArrayList<>(Arrays.asList(0,4)), 5));
15
+ }
16
+ @Test
17
+ public void test2() {
18
+ assertEquals(216, maximumProduct(new ArrayList<>(Arrays.asList(6,3,3,2)), 2));
19
+ }
20
+
21
+ }
maximum_product_after_k_increments/meta.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2329,
3
+ "name": "maximum_product_after_k_increments",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/maximum-product-after-k-increments/",
6
+ "date": "1648944000000",
7
+ "task_description": "You are given an array of non-negative integers `nums` and an integer `k`. In one operation, you may choose **any** element from `nums` and **increment** it by `1`. Return_ the **maximum** **product** of _`nums`_ after **at most** _`k`_ operations. _Since the answer may be very large, return it modulo `109 + 7`. Note that you should maximize the product before taking the modulo. **Example 1:** ``` **Input:** nums = [0,4], k = 5 **Output:** 20 **Explanation:** Increment the first number 5 times. Now nums = [5, 4], with a product of 5 * 4 = 20. It can be shown that 20 is maximum product possible, so we return 20. Note that there may be other ways to increment nums to have the maximum product. ``` **Example 2:** ``` **Input:** nums = [6,3,3,2], k = 2 **Output:** 216 **Explanation:** Increment the second number 1 time and increment the fourth number 1 time. Now nums = [6, 4, 3, 3], with a product of 6 * 4 * 3 * 3 = 216. It can be shown that 216 is maximum product possible, so we return 216. Note that there may be other ways to increment nums to have the maximum product. ``` **Constraints:** `1 <= nums.length, k <= 105` `0 <= nums[i] <= 106`",
8
+ "public_test_cases": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [0,4], k = 5",
12
+ "output": "20 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [6,3,3,2], k = 2",
17
+ "output": "216 "
18
+ }
19
+ ],
20
+ "private_test_cases": [],
21
+ "haskell_template": "maximumProduct :: [Int] -> Int -> Int\nmaximumProduct nums k ",
22
+ "ocaml_template": "let maximumProduct (nums: int list) (k: int) : int = ",
23
+ "scala_template": "def maximumProduct(nums: List[Int],k: Int): Int = { \n \n}",
24
+ "java_template": "public static int maximumProduct(List<Integer> nums, int k) {\n\n}",
25
+ "python_template": "class Solution(object):\n def maximumProduct(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n "
26
+ }
maximum_product_after_k_increments/ocaml_tests/main.ml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main = struct
3
+ open OUnit2
4
+
5
+ (* Program start *)
6
+
7
+ (* Program end *)
8
+
9
+ (* Test cases *)
10
+
11
+ let test1 _ = assert_equal 20 (maximumProduct [0;4] 5)
12
+
13
+ let test2 _ = assert_equal 216 (maximumProduct [6;3;3;2] 2)
14
+
15
+
16
+ (* Grouping test cases *)
17
+ let suite = "Test Suite for maximumProduct" >::: [
18
+
19
+ "test1" >:: test1;
20
+ "test2" >:: test2;
21
+ ]
22
+
23
+
24
+ (* Running the tests *)
25
+ let () = run_test_tt_main suite
26
+ end
maximum_product_after_k_increments/scala_tests/MySuite.scala ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ class MySuite extends munit.FunSuite {
3
+
4
+ test("test1") {
5
+ assertEquals(Main.maximumProduct(List(0,4),5), 20)
6
+ }
7
+
8
+ test("test2") {
9
+ assertEquals(Main.maximumProduct(List(6,3,3,2),2), 216)
10
+ }
11
+
12
+ }
maximum_rows_covered_by_columns/.DS_Store ADDED
Binary file (6.15 kB). View file
 
maximum_rows_covered_by_columns/haskell_tests/Main.hs ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main where
3
+ import Test.HUnit
4
+
5
+ --Program start
6
+
7
+ --Program end
8
+
9
+ -- Test cases
10
+
11
+ test1 :: Test
12
+ test1 = TestCase (assertEqual "for (maximumRows [[0,0,0],[1,0,1],[0,1,1],[0,0,1]] 2)," 3 (maximumRows [[0,0,0],[1,0,1],[0,1,1],[0,0,1]] 2))
13
+
14
+ test2 :: Test
15
+ test2 = TestCase (assertEqual "for (maximumRows [[1],[0]] 1)," 2 (maximumRows [[1],[0]] 1))
16
+
17
+
18
+ -- Grouping test cases
19
+ tests :: Test
20
+ tests = TestList [TestLabel "Test1" test1]
21
+
22
+ -- Running the tests
23
+ main :: IO Counts
24
+ main = runTestTT tests
maximum_rows_covered_by_columns/java_tests/Main.java ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ public class Main {
8
+ //Program start
9
+
10
+ //Program end
11
+
12
+ @Test
13
+ public void test1() {
14
+ assertEquals(3, maximumRows(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,0,0)),new ArrayList<>(Arrays.asList(1,0,1)),new ArrayList<>(Arrays.asList(0,1,1)),new ArrayList<>(Arrays.asList(0,0,1)))), 2));
15
+ }
16
+ @Test
17
+ public void test2() {
18
+ assertEquals(2, maximumRows(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1)),new ArrayList<>(Arrays.asList(0)))), 1));
19
+ }
20
+
21
+ }
maximum_rows_covered_by_columns/meta.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2482,
3
+ "name": "maximum_rows_covered_by_columns",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/maximum-rows-covered-by-columns/",
6
+ "date": "1660953600000",
7
+ "task_description": "You are given an `m x n` binary matrix `matrix` and an integer `numSelect`. Your goal is to select exactly `numSelect` **distinct **columns from `matrix` such that you cover as many rows as possible. A row is considered **covered** if all the `1`'s in that row are also part of a column that you have selected. If a row does not have any `1`s, it is also considered covered. More formally, let us consider `selected = {c1, c2, ...., cnumSelect}` as the set of columns selected by you. A row `i` is **covered** by `selected` if: For each cell where `matrix[i][j] == 1`, the column `j` is in `selected`. Or, no cell in row `i` has a value of `1`. Return the **maximum** number of rows that can be **covered** by a set of `numSelect` columns. **Example 1:** **Input:** matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2 **Output:** 3 **Explanation:** One possible way to cover 3 rows is shown in the diagram above. We choose s = {0, 2}. - Row 0 is covered because it has no occurrences of 1. - Row 1 is covered because the columns with value 1, i.e. 0 and 2 are present in s. - Row 2 is not covered because matrix[2][1] == 1 but 1 is not present in s. - Row 3 is covered because matrix[2][2] == 1 and 2 is present in s. Thus, we can cover three rows. Note that s = {1, 2} will also cover 3 rows, but it can be shown that no more than three rows can be covered. **Example 2:** **Input:** matrix = [[1],[0]], numSelect = 1 **Output:** 2 **Explanation:** Selecting the only column will result in both rows being covered since the entire matrix is selected. **Constraints:** `m == matrix.length` `n == matrix[i].length` `1 <= m, n <= 12` `matrix[i][j]` is either `0` or `1`. `1 <= numSelect <= n`",
8
+ "public_test_cases": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "matrix = [[0,0,0],[1,0,1],[0,1,1],[0,0,1]], numSelect = 2",
12
+ "output": "3 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "matrix = [[1],[0]], numSelect = 1",
17
+ "output": "2 "
18
+ }
19
+ ],
20
+ "private_test_cases": [],
21
+ "haskell_template": "maximumRows :: [[Int]] -> Int -> Int\nmaximumRows matrix numSelect ",
22
+ "ocaml_template": "let maximumRows (matrix: int list list) (numSelect: int) : int = ",
23
+ "scala_template": "def maximumRows(matrix: List[List[Int]],numSelect: Int): Int = { \n \n}",
24
+ "java_template": "public static int maximumRows(List<List<Integer>> matrix, int numSelect) {\n\n}",
25
+ "python_template": "class Solution(object):\n def maximumRows(self, matrix, numSelect):\n \"\"\"\n :type matrix: List[List[int]]\n :type numSelect: int\n :rtype: int\n \"\"\"\n "
26
+ }
maximum_rows_covered_by_columns/ocaml_tests/main.ml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main = struct
3
+ open OUnit2
4
+
5
+ (* Program start *)
6
+
7
+ (* Program end *)
8
+
9
+ (* Test cases *)
10
+
11
+ let test1 _ = assert_equal 3 (maximumRows [[0;0;0];[1;0;1];[0;1;1];[0;0;1]] 2)
12
+
13
+ let test2 _ = assert_equal 2 (maximumRows [[1];[0]] 1)
14
+
15
+
16
+ (* Grouping test cases *)
17
+ let suite = "Test Suite for maximumRows" >::: [
18
+
19
+ "test1" >:: test1;
20
+ "test2" >:: test2;
21
+ ]
22
+
23
+
24
+ (* Running the tests *)
25
+ let () = run_test_tt_main suite
26
+ end
maximum_rows_covered_by_columns/scala_tests/MySuite.scala ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ class MySuite extends munit.FunSuite {
3
+
4
+ test("test1") {
5
+ assertEquals(Main.maximumRows(List(List(0,0,0),List(1,0,1),List(0,1,1),List(0,0,1)),2), 3)
6
+ }
7
+
8
+ test("test2") {
9
+ assertEquals(Main.maximumRows(List(List(1),List(0)),1), 2)
10
+ }
11
+
12
+ }
maximum_running_time_of_n_computers/.DS_Store ADDED
Binary file (6.15 kB). View file
 
maximum_running_time_of_n_computers/haskell_tests/Main.hs ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main where
3
+ import Test.HUnit
4
+
5
+ --Program start
6
+
7
+ --Program end
8
+
9
+ -- Test cases
10
+
11
+ test1 :: Test
12
+ test1 = TestCase (assertEqual "for (maxRunTime 2 [3,3,3])," 4 (maxRunTime 2 [3,3,3]))
13
+
14
+ test2 :: Test
15
+ test2 = TestCase (assertEqual "for (maxRunTime 2 [1,1,1,1])," 2 (maxRunTime 2 [1,1,1,1]))
16
+
17
+
18
+ -- Grouping test cases
19
+ tests :: Test
20
+ tests = TestList [TestLabel "Test1" test1]
21
+
22
+ -- Running the tests
23
+ main :: IO Counts
24
+ main = runTestTT tests
maximum_running_time_of_n_computers/java_tests/Main.java ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ public class Main {
8
+ //Program start
9
+
10
+ //Program end
11
+
12
+ @Test
13
+ public void test1() {
14
+ assertEquals(4, maxRunTime(2, new ArrayList<>(Arrays.asList(3,3,3))));
15
+ }
16
+ @Test
17
+ public void test2() {
18
+ assertEquals(2, maxRunTime(2, new ArrayList<>(Arrays.asList(1,1,1,1))));
19
+ }
20
+
21
+ }
maximum_running_time_of_n_computers/meta.json ADDED
The diff for this file is too large to render. See raw diff
 
maximum_running_time_of_n_computers/ocaml_tests/main.ml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main = struct
3
+ open OUnit2
4
+
5
+ (* Program start *)
6
+
7
+ (* Program end *)
8
+
9
+ (* Test cases *)
10
+
11
+ let test1 _ = assert_equal 4 (maxRunTime 2 [3;3;3])
12
+
13
+ let test2 _ = assert_equal 2 (maxRunTime 2 [1;1;1;1])
14
+
15
+
16
+ (* Grouping test cases *)
17
+ let suite = "Test Suite for maxRunTime" >::: [
18
+
19
+ "test1" >:: test1;
20
+ "test2" >:: test2;
21
+ ]
22
+
23
+
24
+ (* Running the tests *)
25
+ let () = run_test_tt_main suite
26
+ end
maximum_running_time_of_n_computers/scala_tests/MySuite.scala ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ class MySuite extends munit.FunSuite {
3
+
4
+ test("test1") {
5
+ assertEquals(Main.maxRunTime(2,List(3,3,3)), 4)
6
+ }
7
+
8
+ test("test2") {
9
+ assertEquals(Main.maxRunTime(2,List(1,1,1,1)), 2)
10
+ }
11
+
12
+ }
maximum_score_after_applying_operations_on_a_tree/haskell_tests/Main.hs ADDED
The diff for this file is too large to render. See raw diff
 
maximum_score_after_applying_operations_on_a_tree/java_tests/Main.java ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ public class Main {
8
+ //Program start
9
+
10
+ //Program end
11
+
12
+ @Test
13
+ public void test1() {
14
+ assertEquals(11, maximumScoreAfterOperations(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,1)),new ArrayList<>(Arrays.asList(0,2)),new ArrayList<>(Arrays.asList(0,3)),new ArrayList<>(Arrays.asList(2,4)),new ArrayList<>(Arrays.asList(4,5)))), new ArrayList<>(Arrays.asList(5,2,5,2,1,1))));
15
+ }
16
+ @Test
17
+ public void test2() {
18
+ assertEquals(40, maximumScoreAfterOperations(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,1)),new ArrayList<>(Arrays.asList(0,2)),new ArrayList<>(Arrays.asList(1,3)),new ArrayList<>(Arrays.asList(1,4)),new ArrayList<>(Arrays.asList(2,5)),new ArrayList<>(Arrays.asList(2,6)))), new ArrayList<>(Arrays.asList(20,10,9,7,4,3,5))));
19
+ }
20
+
21
+ }
maximum_score_after_applying_operations_on_a_tree/meta.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:def33c56c5143efab27ee337b56fe9dfb467d67defde9b84ba3f444b574bf48b
3
+ size 11113724
maximum_score_after_applying_operations_on_a_tree/ocaml_tests/main.ml ADDED
The diff for this file is too large to render. See raw diff
 
maximum_score_after_applying_operations_on_a_tree/scala_tests/MySuite.scala ADDED
The diff for this file is too large to render. See raw diff
 
maximum_score_from_grid_operations/haskell_tests/Main.hs ADDED
The diff for this file is too large to render. See raw diff
 
maximum_score_from_grid_operations/java_tests/Main.java ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ public class Main {
7
+ //Program start
8
+
9
+ //Program end
10
+
11
+ @Test
12
+ public void test1() {
13
+ assertEquals(11, maximumScore(Arrays.asList(Arrays.asList(0,0,0,0,0),Arrays.asList(0,0,3,0,0),Arrays.asList(0,1,0,0,0),Arrays.asList(5,0,0,3,0),Arrays.asList(0,0,0,0,2))));
14
+ }
15
+ @Test
16
+ public void test2() {
17
+ assertEquals(94, maximumScore(Arrays.asList(Arrays.asList(10,9,0,0,15),Arrays.asList(7,1,0,8,0),Arrays.asList(5,20,0,11,0),Arrays.asList(0,0,0,1,2),Arrays.asList(8,12,1,10,3))));
18
+ }
19
+
20
+ }
maximum_score_from_grid_operations/meta.json ADDED
The diff for this file is too large to render. See raw diff
 
maximum_score_from_grid_operations/ocaml_tests/main.ml ADDED
The diff for this file is too large to render. See raw diff
 
maximum_score_from_grid_operations/scala_tests/MySuite.scala ADDED
The diff for this file is too large to render. See raw diff
 
maximum_score_of_a_node_sequence/.DS_Store ADDED
Binary file (6.15 kB). View file
 
maximum_score_of_a_node_sequence/haskell_tests/Main.hs ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main where
3
+ import Test.HUnit
4
+
5
+ --Program start
6
+
7
+ --Program end
8
+
9
+ -- Test cases
10
+
11
+ test1 :: Test
12
+ test1 = TestCase (assertEqual "for (maximumScore [5,2,9,8,4] [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]])," 24 (maximumScore [5,2,9,8,4] [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]))
13
+
14
+ test2 :: Test
15
+ test2 = TestCase (assertEqual "for (maximumScore [9,20,6,4,11,12] [[0,3],[5,3],[2,4],[1,3]])," (-1) (maximumScore [9,20,6,4,11,12] [[0,3],[5,3],[2,4],[1,3]]))
16
+
17
+
18
+ -- Grouping test cases
19
+ tests :: Test
20
+ tests = TestList [TestLabel "Test1" test1]
21
+
22
+ -- Running the tests
23
+ main :: IO Counts
24
+ main = runTestTT tests
maximum_score_of_a_node_sequence/java_tests/Main.java ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ public class Main {
8
+ //Program start
9
+
10
+ //Program end
11
+
12
+ @Test
13
+ public void test1() {
14
+ assertEquals(24, maximumScore(new ArrayList<>(Arrays.asList(5,2,9,8,4)), new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,1)),new ArrayList<>(Arrays.asList(1,2)),new ArrayList<>(Arrays.asList(2,3)),new ArrayList<>(Arrays.asList(0,2)),new ArrayList<>(Arrays.asList(1,3)),new ArrayList<>(Arrays.asList(2,4))))));
15
+ }
16
+ @Test
17
+ public void test2() {
18
+ assertEquals(-1, maximumScore(new ArrayList<>(Arrays.asList(9,20,6,4,11,12)), new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,3)),new ArrayList<>(Arrays.asList(5,3)),new ArrayList<>(Arrays.asList(2,4)),new ArrayList<>(Arrays.asList(1,3))))));
19
+ }
20
+
21
+ }
maximum_score_of_a_node_sequence/meta.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:25e6d327b5f519ce29d5ca1a65e49ae727057585878bb32c55eac15be008163c
3
+ size 30794206
maximum_score_of_a_node_sequence/ocaml_tests/main.ml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main = struct
3
+ open OUnit2
4
+
5
+ (* Program start *)
6
+
7
+ (* Program end *)
8
+
9
+ (* Test cases *)
10
+
11
+ let test1 _ = assert_equal 24 (maximumScore [5;2;9;8;4] [[0;1];[1;2];[2;3];[0;2];[1;3];[2;4]])
12
+
13
+ let test2 _ = assert_equal (-1) (maximumScore [9;20;6;4;11;12] [[0;3];[5;3];[2;4];[1;3]])
14
+
15
+
16
+ (* Grouping test cases *)
17
+ let suite = "Test Suite for maximumScore" >::: [
18
+
19
+ "test1" >:: test1;
20
+ "test2" >:: test2;
21
+ ]
22
+
23
+
24
+ (* Running the tests *)
25
+ let () = run_test_tt_main suite
26
+ end
maximum_score_of_a_node_sequence/scala_tests/MySuite.scala ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ class MySuite extends munit.FunSuite {
3
+
4
+ test("test1") {
5
+ assertEquals(Main.maximumScore(List(5,2,9,8,4),List(List(0,1),List(1,2),List(2,3),List(0,2),List(1,3),List(2,4))), 24)
6
+ }
7
+
8
+ test("test2") {
9
+ assertEquals(Main.maximumScore(List(9,20,6,4,11,12),List(List(0,3),List(5,3),List(2,4),List(1,3))), -1)
10
+ }
11
+
12
+ }
maximum_segment_sum_after_removals/.DS_Store ADDED
Binary file (6.15 kB). View file
 
maximum_segment_sum_after_removals/haskell_tests/Main.hs ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main where
3
+ import Test.HUnit
4
+
5
+ --Program start
6
+
7
+ --Program end
8
+
9
+ -- Test cases
10
+
11
+ test1 :: Test
12
+ test1 = TestCase (assertEqual "for (maximumSegmentSum [1,2,5,6,1] [0,3,2,4,1])," [14,7,2,2,0] (maximumSegmentSum [1,2,5,6,1] [0,3,2,4,1]))
13
+
14
+ test2 :: Test
15
+ test2 = TestCase (assertEqual "for (maximumSegmentSum [3,2,11,1] [3,2,1,0])," [16,5,3,0] (maximumSegmentSum [3,2,11,1] [3,2,1,0]))
16
+
17
+
18
+ -- Grouping test cases
19
+ tests :: Test
20
+ tests = TestList [TestLabel "Test1" test1]
21
+
22
+ -- Running the tests
23
+ main :: IO Counts
24
+ main = runTestTT tests
maximum_segment_sum_after_removals/java_tests/Main.java ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ public class Main {
8
+ //Program start
9
+
10
+ //Program end
11
+
12
+ @Test
13
+ public void test1() {
14
+ assertEquals(new ArrayList<>(Arrays.asList(14,7,2,2,0)), maximumSegmentSum(new ArrayList<>(Arrays.asList(1,2,5,6,1)), new ArrayList<>(Arrays.asList(0,3,2,4,1))));
15
+ }
16
+ @Test
17
+ public void test2() {
18
+ assertEquals(new ArrayList<>(Arrays.asList(16,5,3,0)), maximumSegmentSum(new ArrayList<>(Arrays.asList(3,2,11,1)), new ArrayList<>(Arrays.asList(3,2,1,0))));
19
+ }
20
+
21
+ }
maximum_segment_sum_after_removals/meta.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 2466,
3
+ "name": "maximum_segment_sum_after_removals",
4
+ "difficulty": "Hard",
5
+ "link": "https://leetcode.com/problems/maximum-segment-sum-after-removals/",
6
+ "date": "1659744000000",
7
+ "task_description": "You are given two **0-indexed** integer arrays `nums` and `removeQueries`, both of length `n`. For the `ith` query, the element in `nums` at the index `removeQueries[i]` is removed, splitting `nums` into different segments. A **segment** is a contiguous sequence of **positive** integers in `nums`. A **segment sum** is the sum of every element in a segment. Return_ an integer array _`answer`_, of length _`n`_, where _`answer[i]`_ is the **maximum** segment sum after applying the _`ith` _removal._ **Note:** The same index will **not** be removed more than once. **Example 1:** ``` **Input:** nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1] **Output:** [14,7,2,2,0] **Explanation:** Using 0 to indicate a removed element, the answer is as follows: Query 1: Remove the 0th element, nums becomes [0,2,5,6,1] and the maximum segment sum is 14 for segment [2,5,6,1]. Query 2: Remove the 3rd element, nums becomes [0,2,5,0,1] and the maximum segment sum is 7 for segment [2,5]. Query 3: Remove the 2nd element, nums becomes [0,2,0,0,1] and the maximum segment sum is 2 for segment [2]. Query 4: Remove the 4th element, nums becomes [0,2,0,0,0] and the maximum segment sum is 2 for segment [2]. Query 5: Remove the 1st element, nums becomes [0,0,0,0,0] and the maximum segment sum is 0, since there are no segments. Finally, we return [14,7,2,2,0]. ``` **Example 2:** ``` **Input:** nums = [3,2,11,1], removeQueries = [3,2,1,0] **Output:** [16,5,3,0] **Explanation:** Using 0 to indicate a removed element, the answer is as follows: Query 1: Remove the 3rd element, nums becomes [3,2,11,0] and the maximum segment sum is 16 for segment [3,2,11]. Query 2: Remove the 2nd element, nums becomes [3,2,0,0] and the maximum segment sum is 5 for segment [3,2]. Query 3: Remove the 1st element, nums becomes [3,0,0,0] and the maximum segment sum is 3 for segment [3]. Query 4: Remove the 0th element, nums becomes [0,0,0,0] and the maximum segment sum is 0, since there are no segments. Finally, we return [16,5,3,0]. ``` **Constraints:** `n == nums.length == removeQueries.length` `1 <= n <= 105` `1 <= nums[i] <= 109` `0 <= removeQueries[i] < n` All the values of `removeQueries` are **unique**.",
8
+ "public_test_cases": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums = [1,2,5,6,1], removeQueries = [0,3,2,4,1]",
12
+ "output": "[14,7,2,2,0] "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums = [3,2,11,1], removeQueries = [3,2,1,0]",
17
+ "output": "[16,5,3,0] "
18
+ }
19
+ ],
20
+ "private_test_cases": [],
21
+ "haskell_template": "maximumSegmentSum :: [Int] -> [Int] -> [Int]\nmaximumSegmentSum nums removeQueries ",
22
+ "ocaml_template": "let maximumSegmentSum (nums: int list) (removeQueries: int list) : int list = ",
23
+ "scala_template": "def maximumSegmentSum(nums: List[Int],removeQueries: List[Int]): List[Int] = { \n \n}",
24
+ "java_template": "public static List<Integer> maximumSegmentSum(List<Integer> nums, List<Integer> removeQueries) {\n\n}",
25
+ "python_template": "class Solution(object):\n def maximumSegmentSum(self, nums, removeQueries):\n \"\"\"\n :type nums: List[int]\n :type removeQueries: List[int]\n :rtype: List[int]\n \"\"\"\n "
26
+ }
maximum_segment_sum_after_removals/ocaml_tests/main.ml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main = struct
3
+ open OUnit2
4
+
5
+ (* Program start *)
6
+
7
+ (* Program end *)
8
+
9
+ (* Test cases *)
10
+
11
+ let test1 _ = assert_equal [14;7;2;2;0] (maximumSegmentSum [1;2;5;6;1] [0;3;2;4;1])
12
+
13
+ let test2 _ = assert_equal [16;5;3;0] (maximumSegmentSum [3;2;11;1] [3;2;1;0])
14
+
15
+
16
+ (* Grouping test cases *)
17
+ let suite = "Test Suite for maximumSegmentSum" >::: [
18
+
19
+ "test1" >:: test1;
20
+ "test2" >:: test2;
21
+ ]
22
+
23
+
24
+ (* Running the tests *)
25
+ let () = run_test_tt_main suite
26
+ end
maximum_segment_sum_after_removals/scala_tests/MySuite.scala ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ class MySuite extends munit.FunSuite {
3
+
4
+ test("test1") {
5
+ assertEquals(Main.maximumSegmentSum(List(1,2,5,6,1),List(0,3,2,4,1)), List(14,7,2,2,0))
6
+ }
7
+
8
+ test("test2") {
9
+ assertEquals(Main.maximumSegmentSum(List(3,2,11,1),List(3,2,1,0)), List(16,5,3,0))
10
+ }
11
+
12
+ }
maximum_size_of_a_set_after_removals/haskell_tests/Main.hs ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main where
3
+ import Test.HUnit
4
+
5
+ --Program start
6
+
7
+ --Program end
8
+
9
+ -- Test cases
10
+
11
+ test1 :: Test
12
+ test1 = TestCase (assertEqual "for (maximumSetSize [1,2,1,2] [1,1,1,1])," 2 (maximumSetSize [1,2,1,2] [1,1,1,1]))
13
+
14
+ test2 :: Test
15
+ test2 = TestCase (assertEqual "for (maximumSetSize [1,2,3,4,5,6] [2,3,2,3,2,3])," 5 (maximumSetSize [1,2,3,4,5,6] [2,3,2,3,2,3]))
16
+
17
+ test3 :: Test
18
+ test3 = TestCase (assertEqual "for (maximumSetSize [1,1,2,2,3,3] [4,4,5,5,6,6])," 6 (maximumSetSize [1,1,2,2,3,3] [4,4,5,5,6,6]))
19
+
20
+ test4 :: Test
21
+ test4 = TestCase (assertEqual "for (maximumSetSize [78348302, 940136119] [563590893, 159155844])," 2 (maximumSetSize [78348302, 940136119] [563590893, 159155844]))
22
+
23
+ test5 :: Test
24
+ test5 = TestCase (assertEqual "for (maximumSetSize [84945860, 193669162, 75904079, 788997068, 615456342, 414731580, 32456705, 521831271, 973822800, 326942852, 973829744, 873758845, 110226437, 683915270, 73686147, 951051910, 886569395, 548200754, 111615160, 161794210] [794087442, 82007194, 535441721, 741847875, 280877434, 783658908, 209706906, 161571603, 235709125, 689307543, 170781132, 912591602, 506074507, 639465755, 49523677, 740061735, 799782716, 470606595, 25980800, 478767626])," 20 (maximumSetSize [84945860, 193669162, 75904079, 788997068, 615456342, 414731580, 32456705, 521831271, 973822800, 326942852, 973829744, 873758845, 110226437, 683915270, 73686147, 951051910, 886569395, 548200754, 111615160, 161794210] [794087442, 82007194, 535441721, 741847875, 280877434, 783658908, 209706906, 161571603, 235709125, 689307543, 170781132, 912591602, 506074507, 639465755, 49523677, 740061735, 799782716, 470606595, 25980800, 478767626]))
25
+
26
+ test6 :: Test
27
+ test6 = TestCase (assertEqual "for (maximumSetSize [299994885, 933582513, 979747875, 561478244, 573543605, 955527439, 597760136, 223191707, 201186171, 69420566] [415956545, 537619489, 800287594, 358497998, 716334237, 495182359, 285307109, 376266466, 893022625, 64419341])," 10 (maximumSetSize [299994885, 933582513, 979747875, 561478244, 573543605, 955527439, 597760136, 223191707, 201186171, 69420566] [415956545, 537619489, 800287594, 358497998, 716334237, 495182359, 285307109, 376266466, 893022625, 64419341]))
28
+
29
+ test7 :: Test
30
+ test7 = TestCase (assertEqual "for (maximumSetSize [137423384, 664756341] [641695145, 438783830])," 2 (maximumSetSize [137423384, 664756341] [641695145, 438783830]))
31
+
32
+ test8 :: Test
33
+ test8 = TestCase (assertEqual "for (maximumSetSize [586071719, 580750612, 28731609, 154299027, 49684461, 131328257, 198807994, 4466555, 868846624, 910580591, 76432445, 974122675, 354592709, 848354224, 96921773, 274307178, 843594802, 194158012, 668622775, 335612555] [754311207, 795289464, 571259690, 816582315, 839440676, 653320358, 544979615, 737298458, 305875561, 489021621, 712859740, 711264575, 929537279, 680639902, 688884196, 814751791, 782534470, 906115758, 976991494, 763267422])," 20 (maximumSetSize [586071719, 580750612, 28731609, 154299027, 49684461, 131328257, 198807994, 4466555, 868846624, 910580591, 76432445, 974122675, 354592709, 848354224, 96921773, 274307178, 843594802, 194158012, 668622775, 335612555] [754311207, 795289464, 571259690, 816582315, 839440676, 653320358, 544979615, 737298458, 305875561, 489021621, 712859740, 711264575, 929537279, 680639902, 688884196, 814751791, 782534470, 906115758, 976991494, 763267422]))
34
+
35
+ test9 :: Test
36
+ test9 = TestCase (assertEqual "for (maximumSetSize [775787406, 920380915, 239993800, 280240273, 830880667, 345060909, 705426545, 384911700, 917388331, 956276476] [826473730, 399089989, 344913684, 285884189, 916971175, 536603624, 300393064, 848410248, 433097531, 310638834])," 10 (maximumSetSize [775787406, 920380915, 239993800, 280240273, 830880667, 345060909, 705426545, 384911700, 917388331, 956276476] [826473730, 399089989, 344913684, 285884189, 916971175, 536603624, 300393064, 848410248, 433097531, 310638834]))
37
+
38
+
39
+ -- Grouping test cases
40
+ tests :: Test
41
+ tests = TestList [TestLabel "Test1" test1, TestLabel "Test2" test2, TestLabel "Test3" test3, TestLabel "Test4" test4, TestLabel "Test5" test5, TestLabel "Test6" test6, TestLabel "Test7" test7, TestLabel "Test8" test8, TestLabel "Test9" test9]
42
+
43
+ -- Running the tests
44
+ main :: IO Counts
45
+ main = runTestTT tests
maximum_size_of_a_set_after_removals/java_tests/Main.java ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import static org.junit.jupiter.api.Assertions.*;
3
+ import org.junit.jupiter.api.Test;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ public class Main {
8
+ //Program start
9
+
10
+ //Program end
11
+
12
+ @Test
13
+ public void test1() {
14
+ assertEquals(2, maximumSetSize(new ArrayList<>(Arrays.asList(1,2,1,2)), new ArrayList<>(Arrays.asList(1,1,1,1))));
15
+ }
16
+ @Test
17
+ public void test2() {
18
+ assertEquals(5, maximumSetSize(new ArrayList<>(Arrays.asList(1,2,3,4,5,6)), new ArrayList<>(Arrays.asList(2,3,2,3,2,3))));
19
+ }
20
+ @Test
21
+ public void test3() {
22
+ assertEquals(6, maximumSetSize(new ArrayList<>(Arrays.asList(1,1,2,2,3,3)), new ArrayList<>(Arrays.asList(4,4,5,5,6,6))));
23
+ }
24
+
25
+ }
maximum_size_of_a_set_after_removals/meta.json ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": 3228,
3
+ "name": "maximum_size_of_a_set_after_removals",
4
+ "difficulty": "Medium",
5
+ "link": "https://leetcode.com/problems/maximum-size-of-a-set-after-removals/",
6
+ "date": "2023-12-31 00:00:00",
7
+ "task_description": "You are given two **0-indexed** integer arrays `nums1` and `nums2` of even length `n`. You must remove `n / 2` elements from `nums1` and `n / 2` elements from `nums2`. After the removals, you insert the remaining elements of `nums1` and `nums2` into a set `s`. Return _the **maximum** possible size of the set_ `s`. **Example 1:** ``` **Input:** nums1 = [1,2,1,2], nums2 = [1,1,1,1] **Output:** 2 **Explanation:** We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}. It can be shown that 2 is the maximum possible size of the set s after the removals. ``` **Example 2:** ``` **Input:** nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3] **Output:** 5 **Explanation:** We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}. It can be shown that 5 is the maximum possible size of the set s after the removals. ``` **Example 3:** ``` **Input:** nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6] **Output:** 6 **Explanation:** We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}. It can be shown that 6 is the maximum possible size of the set s after the removals. ``` **Constraints:** `n == nums1.length == nums2.length` `1 <= n <= 2 * 104` `n` is even. `1 <= nums1[i], nums2[i] <= 109`",
8
+ "public_test_cases": [
9
+ {
10
+ "label": "Example 1",
11
+ "input": "nums1 = [1,2,1,2], nums2 = [1,1,1,1]",
12
+ "output": "2 "
13
+ },
14
+ {
15
+ "label": "Example 2",
16
+ "input": "nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]",
17
+ "output": "5 "
18
+ },
19
+ {
20
+ "label": "Example 3",
21
+ "input": "nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]",
22
+ "output": "6 "
23
+ }
24
+ ],
25
+ "private_test_cases": [
26
+ {
27
+ "input": [
28
+ [
29
+ 78348302,
30
+ 940136119
31
+ ],
32
+ [
33
+ 563590893,
34
+ 159155844
35
+ ]
36
+ ],
37
+ "output": 2
38
+ },
39
+ {
40
+ "input": [
41
+ [
42
+ 84945860,
43
+ 193669162,
44
+ 75904079,
45
+ 788997068,
46
+ 615456342,
47
+ 414731580,
48
+ 32456705,
49
+ 521831271,
50
+ 973822800,
51
+ 326942852,
52
+ 973829744,
53
+ 873758845,
54
+ 110226437,
55
+ 683915270,
56
+ 73686147,
57
+ 951051910,
58
+ 886569395,
59
+ 548200754,
60
+ 111615160,
61
+ 161794210
62
+ ],
63
+ [
64
+ 794087442,
65
+ 82007194,
66
+ 535441721,
67
+ 741847875,
68
+ 280877434,
69
+ 783658908,
70
+ 209706906,
71
+ 161571603,
72
+ 235709125,
73
+ 689307543,
74
+ 170781132,
75
+ 912591602,
76
+ 506074507,
77
+ 639465755,
78
+ 49523677,
79
+ 740061735,
80
+ 799782716,
81
+ 470606595,
82
+ 25980800,
83
+ 478767626
84
+ ]
85
+ ],
86
+ "output": 20
87
+ },
88
+ {
89
+ "input": [
90
+ [
91
+ 299994885,
92
+ 933582513,
93
+ 979747875,
94
+ 561478244,
95
+ 573543605,
96
+ 955527439,
97
+ 597760136,
98
+ 223191707,
99
+ 201186171,
100
+ 69420566
101
+ ],
102
+ [
103
+ 415956545,
104
+ 537619489,
105
+ 800287594,
106
+ 358497998,
107
+ 716334237,
108
+ 495182359,
109
+ 285307109,
110
+ 376266466,
111
+ 893022625,
112
+ 64419341
113
+ ]
114
+ ],
115
+ "output": 10
116
+ },
117
+ {
118
+ "input": [
119
+ [
120
+ 137423384,
121
+ 664756341
122
+ ],
123
+ [
124
+ 641695145,
125
+ 438783830
126
+ ]
127
+ ],
128
+ "output": 2
129
+ },
130
+ {
131
+ "input": [
132
+ [
133
+ 586071719,
134
+ 580750612,
135
+ 28731609,
136
+ 154299027,
137
+ 49684461,
138
+ 131328257,
139
+ 198807994,
140
+ 4466555,
141
+ 868846624,
142
+ 910580591,
143
+ 76432445,
144
+ 974122675,
145
+ 354592709,
146
+ 848354224,
147
+ 96921773,
148
+ 274307178,
149
+ 843594802,
150
+ 194158012,
151
+ 668622775,
152
+ 335612555
153
+ ],
154
+ [
155
+ 754311207,
156
+ 795289464,
157
+ 571259690,
158
+ 816582315,
159
+ 839440676,
160
+ 653320358,
161
+ 544979615,
162
+ 737298458,
163
+ 305875561,
164
+ 489021621,
165
+ 712859740,
166
+ 711264575,
167
+ 929537279,
168
+ 680639902,
169
+ 688884196,
170
+ 814751791,
171
+ 782534470,
172
+ 906115758,
173
+ 976991494,
174
+ 763267422
175
+ ]
176
+ ],
177
+ "output": 20
178
+ },
179
+ {
180
+ "input": [
181
+ [
182
+ 775787406,
183
+ 920380915,
184
+ 239993800,
185
+ 280240273,
186
+ 830880667,
187
+ 345060909,
188
+ 705426545,
189
+ 384911700,
190
+ 917388331,
191
+ 956276476
192
+ ],
193
+ [
194
+ 826473730,
195
+ 399089989,
196
+ 344913684,
197
+ 285884189,
198
+ 916971175,
199
+ 536603624,
200
+ 300393064,
201
+ 848410248,
202
+ 433097531,
203
+ 310638834
204
+ ]
205
+ ],
206
+ "output": 10
207
+ },
208
+ {
209
+ "input": [
210
+ [
211
+ 451407306,
212
+ 470197668,
213
+ 51243526,
214
+ 733482987
215
+ ],
216
+ [
217
+ 805151922,
218
+ 10593079,
219
+ 417714201,
220
+ 15071541
221
+ ]
222
+ ],
223
+ "output": 4
224
+ },
225
+ {
226
+ "input": [
227
+ [
228
+ 442524239,
229
+ 876643870,
230
+ 990601996,
231
+ 448210324
232
+ ],
233
+ [
234
+ 262261265,
235
+ 383531389,
236
+ 403424825,
237
+ 659441841
238
+ ]
239
+ ],
240
+ "output": 4
241
+ },
242
+ {
243
+ "input": [
244
+ [
245
+ 403896182,
246
+ 910000407,
247
+ 110765169,
248
+ 291709086,
249
+ 789940105,
250
+ 966265117,
251
+ 820206463,
252
+ 58393824,
253
+ 194529173,
254
+ 103791568,
255
+ 420765163,
256
+ 792588126,
257
+ 408601928,
258
+ 140802791,
259
+ 562736216,
260
+ 693798082
261
+ ],
262
+ [
263
+ 783148362,
264
+ 264252138,
265
+ 326951764,
266
+ 625241775,
267
+ 457064359,
268
+ 153352361,
269
+ 298387201,
270
+ 599859562,
271
+ 558792114,
272
+ 383729333,
273
+ 348128344,
274
+ 953037178,
275
+ 161775352,
276
+ 642535465,
277
+ 432991683,
278
+ 963297645
279
+ ]
280
+ ],
281
+ "output": 16
282
+ },
283
+ {
284
+ "input": [
285
+ [
286
+ 700983308,
287
+ 873251868,
288
+ 352449770,
289
+ 551310030,
290
+ 855033706,
291
+ 478237705,
292
+ 874313351,
293
+ 258632857,
294
+ 5219950,
295
+ 792335543,
296
+ 358783405,
297
+ 932274480,
298
+ 285646142,
299
+ 163663665,
300
+ 414387346,
301
+ 747497148,
302
+ 171635457,
303
+ 789073340
304
+ ],
305
+ [
306
+ 122620025,
307
+ 379775582,
308
+ 363272717,
309
+ 752514122,
310
+ 106914848,
311
+ 505674445,
312
+ 783171987,
313
+ 452148287,
314
+ 53505032,
315
+ 870856996,
316
+ 637980204,
317
+ 477924079,
318
+ 74294892,
319
+ 443840515,
320
+ 171040824,
321
+ 270669481,
322
+ 871958398,
323
+ 932448448
324
+ ]
325
+ ],
326
+ "output": 18
327
+ }
328
+ ],
329
+ "haskell_template": "maximumSetSize :: [Int] -> [Int] -> Int\nmaximumSetSize nums1 nums2 ",
330
+ "ocaml_template": "let maximumSetSize (nums1: int list) (nums2: int list) : int = ",
331
+ "scala_template": "def maximumSetSize(nums1: List[Int],nums2: List[Int]): Int = { \n \n}",
332
+ "java_template": "class Solution {\n public int maximumSetSize(int[] nums1, int[] nums2) {\n \n }\n}",
333
+ "python_template": "class Solution(object):\n def maximumSetSize(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"\n "
334
+ }
maximum_size_of_a_set_after_removals/ocaml_tests/main.ml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main = struct
3
+ open OUnit2
4
+
5
+ (* Program start *)
6
+
7
+ (* Program end *)
8
+
9
+ (* Test cases *)
10
+
11
+ let test1 _ = assert_equal 2 (maximumSetSize [1;2;1;2] [1;1;1;1])
12
+
13
+ let test2 _ = assert_equal 5 (maximumSetSize [1;2;3;4;5;6] [2;3;2;3;2;3])
14
+
15
+ let test3 _ = assert_equal 6 (maximumSetSize [1;1;2;2;3;3] [4;4;5;5;6;6])
16
+
17
+ let test4 _ = assert_equal 2 (maximumSetSize [78348302; 940136119] [563590893; 159155844])
18
+
19
+ let test5 _ = assert_equal 20 (maximumSetSize [84945860; 193669162; 75904079; 788997068; 615456342; 414731580; 32456705; 521831271; 973822800; 326942852; 973829744; 873758845; 110226437; 683915270; 73686147; 951051910; 886569395; 548200754; 111615160; 161794210] [794087442; 82007194; 535441721; 741847875; 280877434; 783658908; 209706906; 161571603; 235709125; 689307543; 170781132; 912591602; 506074507; 639465755; 49523677; 740061735; 799782716; 470606595; 25980800; 478767626])
20
+
21
+ let test6 _ = assert_equal 10 (maximumSetSize [299994885; 933582513; 979747875; 561478244; 573543605; 955527439; 597760136; 223191707; 201186171; 69420566] [415956545; 537619489; 800287594; 358497998; 716334237; 495182359; 285307109; 376266466; 893022625; 64419341])
22
+
23
+ let test7 _ = assert_equal 2 (maximumSetSize [137423384; 664756341] [641695145; 438783830])
24
+
25
+ let test8 _ = assert_equal 20 (maximumSetSize [586071719; 580750612; 28731609; 154299027; 49684461; 131328257; 198807994; 4466555; 868846624; 910580591; 76432445; 974122675; 354592709; 848354224; 96921773; 274307178; 843594802; 194158012; 668622775; 335612555] [754311207; 795289464; 571259690; 816582315; 839440676; 653320358; 544979615; 737298458; 305875561; 489021621; 712859740; 711264575; 929537279; 680639902; 688884196; 814751791; 782534470; 906115758; 976991494; 763267422])
26
+
27
+ let test9 _ = assert_equal 10 (maximumSetSize [775787406; 920380915; 239993800; 280240273; 830880667; 345060909; 705426545; 384911700; 917388331; 956276476] [826473730; 399089989; 344913684; 285884189; 916971175; 536603624; 300393064; 848410248; 433097531; 310638834])
28
+
29
+ let test10 _ = assert_equal 4 (maximumSetSize [451407306; 470197668; 51243526; 733482987] [805151922; 10593079; 417714201; 15071541])
30
+
31
+
32
+ (* Grouping test cases *)
33
+ let suite = "Test Suite for maximumSetSize" >::: [
34
+
35
+ "test1" >:: test1;
36
+ "test2" >:: test2;
37
+ "test3" >:: test3;
38
+ "test4" >:: test4;
39
+ "test5" >:: test5;
40
+ "test6" >:: test6;
41
+ "test7" >:: test7;
42
+ "test8" >:: test8;
43
+ "test9" >:: test9;
44
+ "test10" >:: test10;
45
+ ]
46
+
47
+
48
+ (* Running the tests *)
49
+ let () = run_test_tt_main suite
50
+ end
maximum_size_of_a_set_after_removals/scala_tests/MySuite.scala ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ class MySuite extends munit.FunSuite {
3
+
4
+ test("test1") {
5
+ assertEquals(Main.maximumSetSize(List(1,2,1,2),List(1,1,1,1)), 2)
6
+ }
7
+
8
+ test("test2") {
9
+ assertEquals(Main.maximumSetSize(List(1,2,3,4,5,6),List(2,3,2,3,2,3)), 5)
10
+ }
11
+
12
+ test("test3") {
13
+ assertEquals(Main.maximumSetSize(List(1,1,2,2,3,3),List(4,4,5,5,6,6)), 6)
14
+ }
15
+
16
+ test("test4") {
17
+ assertEquals(Main.maximumSetSize(List(78348302, 940136119),List(563590893, 159155844)), 2)
18
+ }
19
+
20
+ test("test5") {
21
+ assertEquals(Main.maximumSetSize(List(84945860, 193669162, 75904079, 788997068, 615456342, 414731580, 32456705, 521831271, 973822800, 326942852, 973829744, 873758845, 110226437, 683915270, 73686147, 951051910, 886569395, 548200754, 111615160, 161794210),List(794087442, 82007194, 535441721, 741847875, 280877434, 783658908, 209706906, 161571603, 235709125, 689307543, 170781132, 912591602, 506074507, 639465755, 49523677, 740061735, 799782716, 470606595, 25980800, 478767626)), 20)
22
+ }
23
+
24
+ test("test6") {
25
+ assertEquals(Main.maximumSetSize(List(299994885, 933582513, 979747875, 561478244, 573543605, 955527439, 597760136, 223191707, 201186171, 69420566),List(415956545, 537619489, 800287594, 358497998, 716334237, 495182359, 285307109, 376266466, 893022625, 64419341)), 10)
26
+ }
27
+
28
+ test("test7") {
29
+ assertEquals(Main.maximumSetSize(List(137423384, 664756341),List(641695145, 438783830)), 2)
30
+ }
31
+
32
+ test("test8") {
33
+ assertEquals(Main.maximumSetSize(List(586071719, 580750612, 28731609, 154299027, 49684461, 131328257, 198807994, 4466555, 868846624, 910580591, 76432445, 974122675, 354592709, 848354224, 96921773, 274307178, 843594802, 194158012, 668622775, 335612555),List(754311207, 795289464, 571259690, 816582315, 839440676, 653320358, 544979615, 737298458, 305875561, 489021621, 712859740, 711264575, 929537279, 680639902, 688884196, 814751791, 782534470, 906115758, 976991494, 763267422)), 20)
34
+ }
35
+
36
+ test("test9") {
37
+ assertEquals(Main.maximumSetSize(List(775787406, 920380915, 239993800, 280240273, 830880667, 345060909, 705426545, 384911700, 917388331, 956276476),List(826473730, 399089989, 344913684, 285884189, 916971175, 536603624, 300393064, 848410248, 433097531, 310638834)), 10)
38
+ }
39
+
40
+ test("test10") {
41
+ assertEquals(Main.maximumSetSize(List(451407306, 470197668, 51243526, 733482987),List(805151922, 10593079, 417714201, 15071541)), 4)
42
+ }
43
+
44
+ }
maximum_spending_after_buying_items/haskell_tests/Main.hs ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module Main where
3
+ import Test.HUnit
4
+
5
+ --Program start
6
+ maxSpending :: [[Int]] -> Int
7
+ maxSpending values = undefined
8
+
9
+ --Program end
10
+
11
+ -- Test cases
12
+
13
+ test1 :: Test
14
+ test1 = TestCase (assertEqual "for (maxSpending [[8,5,2],[6,4,1],[9,7,3]])," 285 (maxSpending [[8,5,2],[6,4,1],[9,7,3]]))
15
+
16
+ test2 :: Test
17
+ test2 = TestCase (assertEqual "for (maxSpending [[10,8,6,4,2],[9,7,5,3,2]])," 386 (maxSpending [[10,8,6,4,2],[9,7,5,3,2]]))
18
+
19
+ test3 :: Test
20
+ test3 = TestCase (assertEqual "for (maxSpending [[], [], [], [], [], []])," 227062941115574 (maxSpending [[], [], [], [], [], []]))
21
+
22
+ test4 :: Test
23
+ test4 = TestCase (assertEqual "for (maxSpending [[], [], [], [], [], [], [], [], [], []])," 292180159082858 (maxSpending [[], [], [], [], [], [], [], [], [], []]))
24
+
25
+ test5 :: Test
26
+ test5 = TestCase (assertEqual "for (maxSpending [[], [], [], [], []])," 479098599181096 (maxSpending [[], [], [], [], []]))
27
+
28
+ test6 :: Test
29
+ test6 = TestCase (assertEqual "for (maxSpending [[], [], [], [], [], [], [], [], []])," 783782248325 (maxSpending [[], [], [], [], [], [], [], [], []]))
30
+
31
+ test7 :: Test
32
+ test7 = TestCase (assertEqual "for (maxSpending [[], [], [], [], [], [], [], []])," 1619183756973107 (maxSpending [[], [], [], [], [], [], [], []]))
33
+
34
+
35
+ -- Grouping test cases
36
+ tests :: Test
37
+ tests = TestList [TestLabel "Test1" test1, TestLabel "Test2" test2, TestLabel "Test3" test3, TestLabel "Test4" test4, TestLabel "Test5" test5, TestLabel "Test6" test6]
38
+
39
+ -- Running the tests
40
+ main :: IO Counts
41
+ main = runTestTT tests