34ae1e5a7f8612fc25f5e2e83a5971f3540b6dc3bedf0dc25d7c1eb5a8215163
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- find_the_original_array_of_prefix_xor/meta.json +3 -0
- find_the_original_array_of_prefix_xor/ocaml_tests/main.ml +26 -0
- find_the_original_array_of_prefix_xor/scala_tests/MySuite.scala +12 -0
- find_the_original_typed_string_ii/haskell_tests/Main.hs +0 -0
- find_the_original_typed_string_ii/java_tests/Main.java +21 -0
- find_the_original_typed_string_ii/meta.json +0 -0
- find_the_original_typed_string_ii/ocaml_tests/main.ml +0 -0
- find_the_original_typed_string_ii/scala_tests/MySuite.scala +0 -0
- find_the_peaks/haskell_tests/Main.hs +41 -0
- find_the_peaks/java_tests/Main.java +20 -0
- find_the_peaks/meta.json +298 -0
- find_the_peaks/ocaml_tests/main.ml +42 -0
- find_the_peaks/scala_tests/MySuite.scala +32 -0
- find_the_power_of_k_size_subarrays_i/java_tests/Main.java +25 -0
- find_the_power_of_k_size_subarrays_ii/java_tests/Main.java +25 -0
- find_the_prefix_common_array_of_two_arrays/java_tests/Main.java +21 -0
- find_the_safest_path_in_a_grid/.DS_Store +0 -0
- find_the_safest_path_in_a_grid/haskell_tests/Main.hs +27 -0
- find_the_safest_path_in_a_grid/java_tests/Main.java +25 -0
- find_the_safest_path_in_a_grid/meta.json +31 -0
- find_the_safest_path_in_a_grid/ocaml_tests/main.ml +29 -0
- find_the_safest_path_in_a_grid/scala_tests/MySuite.scala +16 -0
- find_the_score_of_all_prefixes_of_an_array/.DS_Store +0 -0
- find_the_score_of_all_prefixes_of_an_array/haskell_tests/Main.hs +24 -0
- find_the_score_of_all_prefixes_of_an_array/java_tests/Main.java +21 -0
- find_the_score_of_all_prefixes_of_an_array/meta.json +3 -0
- find_the_score_of_all_prefixes_of_an_array/ocaml_tests/main.ml +26 -0
- find_the_score_of_all_prefixes_of_an_array/scala_tests/MySuite.scala +12 -0
- find_the_substring_with_maximum_cost/.DS_Store +0 -0
- find_the_substring_with_maximum_cost/haskell_tests/Main.hs +24 -0
- find_the_substring_with_maximum_cost/java_tests/Main.java +21 -0
- find_the_substring_with_maximum_cost/meta.json +0 -0
- find_the_substring_with_maximum_cost/ocaml_tests/main.ml +26 -0
- find_the_substring_with_maximum_cost/scala_tests/MySuite.scala +12 -0
- find_the_sum_of_encrypted_integers/haskell_tests/Main.hs +41 -0
- find_the_sum_of_encrypted_integers/java_tests/Main.java +20 -0
- find_the_sum_of_encrypted_integers/meta.json +129 -0
- find_the_sum_of_encrypted_integers/ocaml_tests/main.ml +42 -0
- find_the_sum_of_encrypted_integers/scala_tests/MySuite.scala +32 -0
- find_the_sum_of_subsequence_powers/haskell_tests/Main.hs +45 -0
- find_the_sum_of_subsequence_powers/java_tests/Main.java +25 -0
- find_the_sum_of_subsequence_powers/meta.json +338 -0
- find_the_sum_of_subsequence_powers/ocaml_tests/main.ml +50 -0
- find_the_sum_of_subsequence_powers/scala_tests/MySuite.scala +44 -0
- find_the_sum_of_the_power_of_all_subsequences/haskell_tests/Main.hs +45 -0
- find_the_sum_of_the_power_of_all_subsequences/java_tests/Main.java +25 -0
- find_the_sum_of_the_power_of_all_subsequences/meta.json +627 -0
- find_the_sum_of_the_power_of_all_subsequences/ocaml_tests/main.ml +50 -0
- find_the_sum_of_the_power_of_all_subsequences/scala_tests/MySuite.scala +44 -0
.gitattributes
CHANGED
|
@@ -127,3 +127,5 @@ find_the_longest_equal_subarray/meta.json filter=lfs diff=lfs merge=lfs -text
|
|
| 127 |
find_the_maximum_number_of_marked_indices/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 128 |
find_the_minimum_area_to_cover_all_ones_i/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 129 |
find_the_number_of_good_pairs_ii/meta.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 127 |
find_the_maximum_number_of_marked_indices/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 128 |
find_the_minimum_area_to_cover_all_ones_i/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 129 |
find_the_number_of_good_pairs_ii/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 130 |
+
find_the_original_array_of_prefix_xor/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 131 |
+
find_the_score_of_all_prefixes_of_an_array/meta.json filter=lfs diff=lfs merge=lfs -text
|
find_the_original_array_of_prefix_xor/meta.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8ca068772485fecd0bd0d086cf628fbb61f8385bbd278a7ac79ffe0906b4ec97
|
| 3 |
+
size 26853096
|
find_the_original_array_of_prefix_xor/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 [5;7;2;3;2] (findArray [5;2;0;3;1])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal [13] (findArray [13])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for findArray" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
find_the_original_array_of_prefix_xor/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.findArray(List(5,2,0,3,1)), List(5,7,2,3,2))
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.findArray(List(13)), List(13))
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
find_the_original_typed_string_ii/haskell_tests/Main.hs
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
find_the_original_typed_string_ii/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(5, possibleStringCount("aabbccdd", 7));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(1, possibleStringCount("aabbccdd", 8));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
find_the_original_typed_string_ii/meta.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
find_the_original_typed_string_ii/ocaml_tests/main.ml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
find_the_original_typed_string_ii/scala_tests/MySuite.scala
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
find_the_peaks/haskell_tests/Main.hs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main where
|
| 3 |
+
import Test.HUnit
|
| 4 |
+
|
| 5 |
+
--Program start
|
| 6 |
+
findPeaks :: [Int] -> [Int]
|
| 7 |
+
findPeaks mountain = undefined
|
| 8 |
+
|
| 9 |
+
--Program end
|
| 10 |
+
|
| 11 |
+
-- Test cases
|
| 12 |
+
|
| 13 |
+
test1 :: Test
|
| 14 |
+
test1 = TestCase (assertEqual "for (findPeaks [2,4,4])," [] (findPeaks [2,4,4]))
|
| 15 |
+
|
| 16 |
+
test2 :: Test
|
| 17 |
+
test2 = TestCase (assertEqual "for (findPeaks [1,4,3,8,5])," [1,3] (findPeaks [1,4,3,8,5]))
|
| 18 |
+
|
| 19 |
+
test3 :: Test
|
| 20 |
+
test3 = TestCase (assertEqual "for (findPeaks [75, 5, 21, 83, 13, 67, 91, 52, 57, 19, 77])," [3,6,8] (findPeaks [75, 5, 21, 83, 13, 67, 91, 52, 57, 19, 77]))
|
| 21 |
+
|
| 22 |
+
test4 :: Test
|
| 23 |
+
test4 = TestCase (assertEqual "for (findPeaks [48, 55, 34, 39, 73, 63, 81, 75, 65, 54, 67, 30, 21, 76, 74, 22, 99, 39, 16, 27, 11, 12, 44, 43, 75, 87, 6, 2, 97, 63, 78, 8, 54, 2, 72, 6, 52, 43, 23, 96, 35, 71, 15, 66, 83, 27, 100, 93, 25, 53, 33, 75, 34, 80, 51, 31, 61, 82, 60, 2, 25, 87, 97, 98, 33, 10])," [1,4,6,10,13,16,19,22,25,28,30,32,34,36,39,41,44,46,49,51,53,57,63] (findPeaks [48, 55, 34, 39, 73, 63, 81, 75, 65, 54, 67, 30, 21, 76, 74, 22, 99, 39, 16, 27, 11, 12, 44, 43, 75, 87, 6, 2, 97, 63, 78, 8, 54, 2, 72, 6, 52, 43, 23, 96, 35, 71, 15, 66, 83, 27, 100, 93, 25, 53, 33, 75, 34, 80, 51, 31, 61, 82, 60, 2, 25, 87, 97, 98, 33, 10]))
|
| 24 |
+
|
| 25 |
+
test5 :: Test
|
| 26 |
+
test5 = TestCase (assertEqual "for (findPeaks [70, 72, 65, 80, 52, 12, 20, 17, 71, 81, 85, 55, 50, 79, 98, 64, 44, 88, 43, 62, 38, 62, 57, 67, 24, 91, 23, 36, 15, 8, 48, 75, 73, 89, 92, 15, 73, 9, 59, 42, 33, 33, 4, 71, 80, 70, 8, 90, 10, 95, 99, 47, 60, 35, 33, 9, 31, 54, 12, 97, 88, 23, 7, 2, 93, 44, 94, 99, 32, 83, 20, 16, 81, 72, 26, 26, 21, 73, 80, 65, 74, 91, 91, 25, 39, 92, 78, 19, 48, 55, 59])," [1,3,6,10,14,17,19,21,23,25,27,31,34,36,38,44,47,50,52,57,59,64,67,69,72,78,85] (findPeaks [70, 72, 65, 80, 52, 12, 20, 17, 71, 81, 85, 55, 50, 79, 98, 64, 44, 88, 43, 62, 38, 62, 57, 67, 24, 91, 23, 36, 15, 8, 48, 75, 73, 89, 92, 15, 73, 9, 59, 42, 33, 33, 4, 71, 80, 70, 8, 90, 10, 95, 99, 47, 60, 35, 33, 9, 31, 54, 12, 97, 88, 23, 7, 2, 93, 44, 94, 99, 32, 83, 20, 16, 81, 72, 26, 26, 21, 73, 80, 65, 74, 91, 91, 25, 39, 92, 78, 19, 48, 55, 59]))
|
| 27 |
+
|
| 28 |
+
test6 :: Test
|
| 29 |
+
test6 = TestCase (assertEqual "for (findPeaks [12, 19, 89, 39])," [2] (findPeaks [12, 19, 89, 39]))
|
| 30 |
+
|
| 31 |
+
test7 :: Test
|
| 32 |
+
test7 = TestCase (assertEqual "for (findPeaks [10, 66, 11, 86, 99, 97, 36, 22, 34, 37, 15, 94])," [1,4,9] (findPeaks [10, 66, 11, 86, 99, 97, 36, 22, 34, 37, 15, 94]))
|
| 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
|
find_the_peaks/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([], findPeaks(Arrays.asList(2,4,4)));
|
| 14 |
+
}
|
| 15 |
+
@Test
|
| 16 |
+
public void test2() {
|
| 17 |
+
assertEquals(Arrays.asList(1,3), findPeaks(Arrays.asList(1,4,3,8,5)));
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
}
|
find_the_peaks/meta.json
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3221,
|
| 3 |
+
"name": "find_the_peaks",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/find-the-peaks/",
|
| 6 |
+
"date": "2023-11-26 00:00:00",
|
| 7 |
+
"task_description": "You are given a **0-indexed** array `mountain`. Your task is to find all the **peaks** in the `mountain` array. Return _an array that consists of _indices_ of **peaks** in the given array in **any order**._ **Notes:** A **peak** is defined as an element that is **strictly greater** than its neighboring elements. The first and last elements of the array are **not** a peak. **Example 1:** ``` **Input:** mountain = [2,4,4] **Output:** [] **Explanation:** mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array. mountain[1] also can not be a peak because it is not strictly greater than mountain[2]. So the answer is []. ``` **Example 2:** ``` **Input:** mountain = [1,4,3,8,5] **Output:** [1,3] **Explanation:** mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array. mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1]. But mountain [1] and mountain[3] are strictly greater than their neighboring elements. So the answer is [1,3]. ``` **Constraints:** `3 <= mountain.length <= 100` `1 <= mountain[i] <= 100`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "mountain = [2,4,4]",
|
| 12 |
+
"output": "[] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "mountain = [1,4,3,8,5]",
|
| 17 |
+
"output": "[1,3] "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
75,
|
| 24 |
+
5,
|
| 25 |
+
21,
|
| 26 |
+
83,
|
| 27 |
+
13,
|
| 28 |
+
67,
|
| 29 |
+
91,
|
| 30 |
+
52,
|
| 31 |
+
57,
|
| 32 |
+
19,
|
| 33 |
+
77
|
| 34 |
+
],
|
| 35 |
+
"output": [
|
| 36 |
+
3,
|
| 37 |
+
6,
|
| 38 |
+
8
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"input": [
|
| 43 |
+
48,
|
| 44 |
+
55,
|
| 45 |
+
34,
|
| 46 |
+
39,
|
| 47 |
+
73,
|
| 48 |
+
63,
|
| 49 |
+
81,
|
| 50 |
+
75,
|
| 51 |
+
65,
|
| 52 |
+
54,
|
| 53 |
+
67,
|
| 54 |
+
30,
|
| 55 |
+
21,
|
| 56 |
+
76,
|
| 57 |
+
74,
|
| 58 |
+
22,
|
| 59 |
+
99,
|
| 60 |
+
39,
|
| 61 |
+
16,
|
| 62 |
+
27,
|
| 63 |
+
11,
|
| 64 |
+
12,
|
| 65 |
+
44,
|
| 66 |
+
43,
|
| 67 |
+
75,
|
| 68 |
+
87,
|
| 69 |
+
6,
|
| 70 |
+
2,
|
| 71 |
+
97,
|
| 72 |
+
63,
|
| 73 |
+
78,
|
| 74 |
+
8,
|
| 75 |
+
54,
|
| 76 |
+
2,
|
| 77 |
+
72,
|
| 78 |
+
6,
|
| 79 |
+
52,
|
| 80 |
+
43,
|
| 81 |
+
23,
|
| 82 |
+
96,
|
| 83 |
+
35,
|
| 84 |
+
71,
|
| 85 |
+
15,
|
| 86 |
+
66,
|
| 87 |
+
83,
|
| 88 |
+
27,
|
| 89 |
+
100,
|
| 90 |
+
93,
|
| 91 |
+
25,
|
| 92 |
+
53,
|
| 93 |
+
33,
|
| 94 |
+
75,
|
| 95 |
+
34,
|
| 96 |
+
80,
|
| 97 |
+
51,
|
| 98 |
+
31,
|
| 99 |
+
61,
|
| 100 |
+
82,
|
| 101 |
+
60,
|
| 102 |
+
2,
|
| 103 |
+
25,
|
| 104 |
+
87,
|
| 105 |
+
97,
|
| 106 |
+
98,
|
| 107 |
+
33,
|
| 108 |
+
10
|
| 109 |
+
],
|
| 110 |
+
"output": [
|
| 111 |
+
1,
|
| 112 |
+
4,
|
| 113 |
+
6,
|
| 114 |
+
10,
|
| 115 |
+
13,
|
| 116 |
+
16,
|
| 117 |
+
19,
|
| 118 |
+
22,
|
| 119 |
+
25,
|
| 120 |
+
28,
|
| 121 |
+
30,
|
| 122 |
+
32,
|
| 123 |
+
34,
|
| 124 |
+
36,
|
| 125 |
+
39,
|
| 126 |
+
41,
|
| 127 |
+
44,
|
| 128 |
+
46,
|
| 129 |
+
49,
|
| 130 |
+
51,
|
| 131 |
+
53,
|
| 132 |
+
57,
|
| 133 |
+
63
|
| 134 |
+
]
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"input": [
|
| 138 |
+
70,
|
| 139 |
+
72,
|
| 140 |
+
65,
|
| 141 |
+
80,
|
| 142 |
+
52,
|
| 143 |
+
12,
|
| 144 |
+
20,
|
| 145 |
+
17,
|
| 146 |
+
71,
|
| 147 |
+
81,
|
| 148 |
+
85,
|
| 149 |
+
55,
|
| 150 |
+
50,
|
| 151 |
+
79,
|
| 152 |
+
98,
|
| 153 |
+
64,
|
| 154 |
+
44,
|
| 155 |
+
88,
|
| 156 |
+
43,
|
| 157 |
+
62,
|
| 158 |
+
38,
|
| 159 |
+
62,
|
| 160 |
+
57,
|
| 161 |
+
67,
|
| 162 |
+
24,
|
| 163 |
+
91,
|
| 164 |
+
23,
|
| 165 |
+
36,
|
| 166 |
+
15,
|
| 167 |
+
8,
|
| 168 |
+
48,
|
| 169 |
+
75,
|
| 170 |
+
73,
|
| 171 |
+
89,
|
| 172 |
+
92,
|
| 173 |
+
15,
|
| 174 |
+
73,
|
| 175 |
+
9,
|
| 176 |
+
59,
|
| 177 |
+
42,
|
| 178 |
+
33,
|
| 179 |
+
33,
|
| 180 |
+
4,
|
| 181 |
+
71,
|
| 182 |
+
80,
|
| 183 |
+
70,
|
| 184 |
+
8,
|
| 185 |
+
90,
|
| 186 |
+
10,
|
| 187 |
+
95,
|
| 188 |
+
99,
|
| 189 |
+
47,
|
| 190 |
+
60,
|
| 191 |
+
35,
|
| 192 |
+
33,
|
| 193 |
+
9,
|
| 194 |
+
31,
|
| 195 |
+
54,
|
| 196 |
+
12,
|
| 197 |
+
97,
|
| 198 |
+
88,
|
| 199 |
+
23,
|
| 200 |
+
7,
|
| 201 |
+
2,
|
| 202 |
+
93,
|
| 203 |
+
44,
|
| 204 |
+
94,
|
| 205 |
+
99,
|
| 206 |
+
32,
|
| 207 |
+
83,
|
| 208 |
+
20,
|
| 209 |
+
16,
|
| 210 |
+
81,
|
| 211 |
+
72,
|
| 212 |
+
26,
|
| 213 |
+
26,
|
| 214 |
+
21,
|
| 215 |
+
73,
|
| 216 |
+
80,
|
| 217 |
+
65,
|
| 218 |
+
74,
|
| 219 |
+
91,
|
| 220 |
+
91,
|
| 221 |
+
25,
|
| 222 |
+
39,
|
| 223 |
+
92,
|
| 224 |
+
78,
|
| 225 |
+
19,
|
| 226 |
+
48,
|
| 227 |
+
55,
|
| 228 |
+
59
|
| 229 |
+
],
|
| 230 |
+
"output": [
|
| 231 |
+
1,
|
| 232 |
+
3,
|
| 233 |
+
6,
|
| 234 |
+
10,
|
| 235 |
+
14,
|
| 236 |
+
17,
|
| 237 |
+
19,
|
| 238 |
+
21,
|
| 239 |
+
23,
|
| 240 |
+
25,
|
| 241 |
+
27,
|
| 242 |
+
31,
|
| 243 |
+
34,
|
| 244 |
+
36,
|
| 245 |
+
38,
|
| 246 |
+
44,
|
| 247 |
+
47,
|
| 248 |
+
50,
|
| 249 |
+
52,
|
| 250 |
+
57,
|
| 251 |
+
59,
|
| 252 |
+
64,
|
| 253 |
+
67,
|
| 254 |
+
69,
|
| 255 |
+
72,
|
| 256 |
+
78,
|
| 257 |
+
85
|
| 258 |
+
]
|
| 259 |
+
},
|
| 260 |
+
{
|
| 261 |
+
"input": [
|
| 262 |
+
12,
|
| 263 |
+
19,
|
| 264 |
+
89,
|
| 265 |
+
39
|
| 266 |
+
],
|
| 267 |
+
"output": [
|
| 268 |
+
2
|
| 269 |
+
]
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"input": [
|
| 273 |
+
10,
|
| 274 |
+
66,
|
| 275 |
+
11,
|
| 276 |
+
86,
|
| 277 |
+
99,
|
| 278 |
+
97,
|
| 279 |
+
36,
|
| 280 |
+
22,
|
| 281 |
+
34,
|
| 282 |
+
37,
|
| 283 |
+
15,
|
| 284 |
+
94
|
| 285 |
+
],
|
| 286 |
+
"output": [
|
| 287 |
+
1,
|
| 288 |
+
4,
|
| 289 |
+
9
|
| 290 |
+
]
|
| 291 |
+
}
|
| 292 |
+
],
|
| 293 |
+
"haskell_template": "findPeaks :: [Int] -> [Int]\nfindPeaks mountain ",
|
| 294 |
+
"ocaml_template": "let findPeaks (mountain: int list) : int list = ",
|
| 295 |
+
"scala_template": "def findPeaks(mountain: List[Int]): List[Int] = { \n \n}",
|
| 296 |
+
"java_template": "class Solution {\n public List<Integer> findPeaks(int[] mountain) {\n \n }\n}",
|
| 297 |
+
"python_template": "class Solution(object):\n def findPeaks(self, mountain):\n \"\"\"\n :type mountain: List[int]\n :rtype: List[int]\n \"\"\"\n "
|
| 298 |
+
}
|
find_the_peaks/ocaml_tests/main.ml
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main = struct
|
| 3 |
+
open OUnit2
|
| 4 |
+
|
| 5 |
+
(* Program start *)
|
| 6 |
+
let findPeaks (mountain: int list) : int list = failwith "Not implemented"
|
| 7 |
+
|
| 8 |
+
(* Program end *)
|
| 9 |
+
|
| 10 |
+
(* Test cases *)
|
| 11 |
+
|
| 12 |
+
let test1 _ = assert_equal [] (findPeaks [2;4;4])
|
| 13 |
+
|
| 14 |
+
let test2 _ = assert_equal [1;3] (findPeaks [1;4;3;8;5])
|
| 15 |
+
|
| 16 |
+
let test3 _ = assert_equal [1;3] (findPeaks [75; 5; 21; 83; 13; 67; 91; 52; 57; 19; 77])
|
| 17 |
+
|
| 18 |
+
let test4 _ = assert_equal [1;3] (findPeaks [48; 55; 34; 39; 73; 63; 81; 75; 65; 54; 67; 30; 21; 76; 74; 22; 99; 39; 16; 27; 11; 12; 44; 43; 75; 87; 6; 2; 97; 63; 78; 8; 54; 2; 72; 6; 52; 43; 23; 96; 35; 71; 15; 66; 83; 27; 100; 93; 25; 53; 33; 75; 34; 80; 51; 31; 61; 82; 60; 2; 25; 87; 97; 98; 33; 10])
|
| 19 |
+
|
| 20 |
+
let test5 _ = assert_equal [1;3] (findPeaks [70; 72; 65; 80; 52; 12; 20; 17; 71; 81; 85; 55; 50; 79; 98; 64; 44; 88; 43; 62; 38; 62; 57; 67; 24; 91; 23; 36; 15; 8; 48; 75; 73; 89; 92; 15; 73; 9; 59; 42; 33; 33; 4; 71; 80; 70; 8; 90; 10; 95; 99; 47; 60; 35; 33; 9; 31; 54; 12; 97; 88; 23; 7; 2; 93; 44; 94; 99; 32; 83; 20; 16; 81; 72; 26; 26; 21; 73; 80; 65; 74; 91; 91; 25; 39; 92; 78; 19; 48; 55; 59])
|
| 21 |
+
|
| 22 |
+
let test6 _ = assert_equal [1;3] (findPeaks [12; 19; 89; 39])
|
| 23 |
+
|
| 24 |
+
let test7 _ = assert_equal [1;3] (findPeaks [10; 66; 11; 86; 99; 97; 36; 22; 34; 37; 15; 94])
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
(* Grouping test cases *)
|
| 28 |
+
let suite = "Test Suite for findPeaks" >::: [
|
| 29 |
+
|
| 30 |
+
"test1" >:: test1;
|
| 31 |
+
"test2" >:: test2;
|
| 32 |
+
"test3" >:: test3;
|
| 33 |
+
"test4" >:: test4;
|
| 34 |
+
"test5" >:: test5;
|
| 35 |
+
"test6" >:: test6;
|
| 36 |
+
"test7" >:: test7;
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
(* Running the tests *)
|
| 41 |
+
let () = run_test_tt_main suite
|
| 42 |
+
end
|
find_the_peaks/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.findPeaks(List(2,4,4)), List())
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.findPeaks(List(1,4,3,8,5)), List(1,3))
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.findPeaks(75,5,21,83,13,67,91,52,57,19,77), List(3,6,8))
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.findPeaks(48,55,34,39,73,63,81,75,65,54,67,30,21,76,74,22,99,39,16,27,11,12,44,43,75,87,6,2,97,63,78,8,54,2,72,6,52,43,23,96,35,71,15,66,83,27,100,93,25,53,33,75,34,80,51,31,61,82,60,2,25,87,97,98,33,10), List(1,4,6,10,13,16,19,22,25,28,30,32,34,36,39,41,44,46,49,51,53,57,63))
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.findPeaks(70,72,65,80,52,12,20,17,71,81,85,55,50,79,98,64,44,88,43,62,38,62,57,67,24,91,23,36,15,8,48,75,73,89,92,15,73,9,59,42,33,33,4,71,80,70,8,90,10,95,99,47,60,35,33,9,31,54,12,97,88,23,7,2,93,44,94,99,32,83,20,16,81,72,26,26,21,73,80,65,74,91,91,25,39,92,78,19,48,55,59), List(1,3,6,10,14,17,19,21,23,25,27,31,34,36,38,44,47,50,52,57,59,64,67,69,72,78,85))
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.findPeaks(12,19,89,39), List(2))
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.findPeaks(10,66,11,86,99,97,36,22,34,37,15,94), List(1,4,9))
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
}
|
find_the_power_of_k_size_subarrays_i/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(new ArrayList<>(Arrays.asList(3,4,-1,-1,-1)), resultsArray(new ArrayList<>(Arrays.asList(1,2,3,4,3,2,5)), 3));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals([-1,-1, resultsArray(new ArrayList<>(Arrays.asList(2,2,2,2,2)), 4));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals([-1,3,-1,3,-1, resultsArray(new ArrayList<>(Arrays.asList(3,2,3,2,3,2)), 2));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
find_the_power_of_k_size_subarrays_ii/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(new ArrayList<>(Arrays.asList(3,4,-1,-1,-1)), resultsArray(new ArrayList<>(Arrays.asList(1,2,3,4,3,2,5)), 3));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals([-1,-1, resultsArray(new ArrayList<>(Arrays.asList(2,2,2,2,2)), 4));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals([-1,3,-1,3,-1, resultsArray(new ArrayList<>(Arrays.asList(3,2,3,2,3,2)), 2));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
find_the_prefix_common_array_of_two_arrays/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(0,2,3,4)), findThePrefixCommonArray(new ArrayList<>(Arrays.asList(1,3,2,4)), new ArrayList<>(Arrays.asList(3,1,2,4))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(Arrays.asList(0,1,3)), findThePrefixCommonArray(new ArrayList<>(Arrays.asList(2,3,1)), new ArrayList<>(Arrays.asList(3,1,2))));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
find_the_safest_path_in_a_grid/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
find_the_safest_path_in_a_grid/haskell_tests/Main.hs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 (maximumSafenessFactor [[1,0,0],[0,0,0],[0,0,1]])," 0 (maximumSafenessFactor [[1,0,0],[0,0,0],[0,0,1]]))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (maximumSafenessFactor [[0,0,1],[0,0,0],[0,0,0]])," 2 (maximumSafenessFactor [[0,0,1],[0,0,0],[0,0,0]]))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (maximumSafenessFactor [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]])," 2 (maximumSafenessFactor [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]))
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
-- Grouping test cases
|
| 22 |
+
tests :: Test
|
| 23 |
+
tests = TestList [TestLabel "Test1" test1, TestLabel "Test2" test2]
|
| 24 |
+
|
| 25 |
+
-- Running the tests
|
| 26 |
+
main :: IO Counts
|
| 27 |
+
main = runTestTT tests
|
find_the_safest_path_in_a_grid/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(0, maximumSafenessFactor(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1,0,0)),new ArrayList<>(Arrays.asList(0,0,0)),new ArrayList<>(Arrays.asList(0,0,1))))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(2, maximumSafenessFactor(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,0,1)),new ArrayList<>(Arrays.asList(0,0,0)),new ArrayList<>(Arrays.asList(0,0,0))))));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals(2, maximumSafenessFactor(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,0,0,1)),new ArrayList<>(Arrays.asList(0,0,0,0)),new ArrayList<>(Arrays.asList(0,0,0,0)),new ArrayList<>(Arrays.asList(1,0,0,0))))));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
find_the_safest_path_in_a_grid/meta.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2914,
|
| 3 |
+
"name": "find_the_safest_path_in_a_grid",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/find-the-safest-path-in-a-grid/",
|
| 6 |
+
"date": "1690675200000",
|
| 7 |
+
"task_description": "You are given a **0-indexed** 2D matrix `grid` of size `n x n`, where `(r, c)` represents: A cell containing a thief if `grid[r][c] = 1` An empty cell if `grid[r][c] = 0` You are initially positioned at cell `(0, 0)`. In one move, you can move to any adjacent cell in the grid, including cells containing thieves. The **safeness factor** of a path on the grid is defined as the **minimum** manhattan distance from any cell in the path to any thief in the grid. Return _the **maximum safeness factor** of all paths leading to cell _`(n - 1, n - 1)`_._ An **adjacent** cell of cell `(r, c)`, is one of the cells `(r, c + 1)`, `(r, c - 1)`, `(r + 1, c)` and `(r - 1, c)` if it exists. The **Manhattan distance** between two cells `(a, b)` and `(x, y)` is equal to `|a - x| + |b - y|`, where `|val|` denotes the absolute value of val. **Example 1:** ``` **Input:** grid = [[1,0,0],[0,0,0],[0,0,1]] **Output:** 0 **Explanation:** All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1). ``` **Example 2:** ``` **Input:** grid = [[0,0,1],[0,0,0],[0,0,0]] **Output:** 2 **Explanation:** The path depicted in the picture above has a safeness factor of 2 since: - The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2. It can be shown that there are no other paths with a higher safeness factor. ``` **Example 3:** ``` **Input:** grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]] **Output:** 2 **Explanation:** The path depicted in the picture above has a safeness factor of 2 since: - The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2. - The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2. It can be shown that there are no other paths with a higher safeness factor. ``` **Constraints:** `1 <= grid.length == n <= 400` `grid[i].length == n` `grid[i][j]` is either `0` or `1`. There is at least one thief in the `grid`.",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "grid = [[1,0,0],[0,0,0],[0,0,1]]",
|
| 12 |
+
"output": "0 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "grid = [[0,0,1],[0,0,0],[0,0,0]]",
|
| 17 |
+
"output": "2 "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]",
|
| 22 |
+
"output": "2 "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"private_test_cases": [],
|
| 26 |
+
"haskell_template": "maximumSafenessFactor :: [[Int]] -> Int\nmaximumSafenessFactor grid ",
|
| 27 |
+
"ocaml_template": "let maximumSafenessFactor (grid: int list list) : int = ",
|
| 28 |
+
"scala_template": "def maximumSafenessFactor(grid: List[List[Int]]): Int = { \n \n}",
|
| 29 |
+
"java_template": "public static int maximumSafenessFactor(List<List<Integer>> grid) {\n\n}",
|
| 30 |
+
"python_template": "class Solution(object):\n def maximumSafenessFactor(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n "
|
| 31 |
+
}
|
find_the_safest_path_in_a_grid/ocaml_tests/main.ml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 0 (maximumSafenessFactor [[1;0;0];[0;0;0];[0;0;1]])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 2 (maximumSafenessFactor [[0;0;1];[0;0;0];[0;0;0]])
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal 2 (maximumSafenessFactor [[0;0;0;1];[0;0;0;0];[0;0;0;0];[1;0;0;0]])
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
(* Grouping test cases *)
|
| 19 |
+
let suite = "Test Suite for maximumSafenessFactor" >::: [
|
| 20 |
+
|
| 21 |
+
"test1" >:: test1;
|
| 22 |
+
"test2" >:: test2;
|
| 23 |
+
"test3" >:: test3;
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
(* Running the tests *)
|
| 28 |
+
let () = run_test_tt_main suite
|
| 29 |
+
end
|
find_the_safest_path_in_a_grid/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.maximumSafenessFactor(List(List(1,0,0),List(0,0,0),List(0,0,1))), 0)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.maximumSafenessFactor(List(List(0,0,1),List(0,0,0),List(0,0,0))), 2)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.maximumSafenessFactor(List(List(0,0,0,1),List(0,0,0,0),List(0,0,0,0),List(1,0,0,0))), 2)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
}
|
find_the_score_of_all_prefixes_of_an_array/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
find_the_score_of_all_prefixes_of_an_array/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 (findPrefixScore [2,3,7,5,10])," [4,10,24,36,56] (findPrefixScore [2,3,7,5,10]))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (findPrefixScore [1,1,2,4,8,16])," [2,4,8,16,32,64] (findPrefixScore [1,1,2,4,8,16]))
|
| 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
|
find_the_score_of_all_prefixes_of_an_array/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(4,10,24,36,56)), findPrefixScore(new ArrayList<>(Arrays.asList(2,3,7,5,10))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(Arrays.asList(2,4,8,16,32,64)), findPrefixScore(new ArrayList<>(Arrays.asList(1,1,2,4,8,16))));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
find_the_score_of_all_prefixes_of_an_array/meta.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:622c21bc514edff63d46fba687c437c3a552b2db729b2576749e36cf22747390
|
| 3 |
+
size 19690315
|
find_the_score_of_all_prefixes_of_an_array/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;10;24;36;56] (findPrefixScore [2;3;7;5;10])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal [2;4;8;16;32;64] (findPrefixScore [1;1;2;4;8;16])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for findPrefixScore" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
find_the_score_of_all_prefixes_of_an_array/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.findPrefixScore(List(2,3,7,5,10)), List(4,10,24,36,56))
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.findPrefixScore(List(1,1,2,4,8,16)), List(2,4,8,16,32,64))
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
find_the_substring_with_maximum_cost/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
find_the_substring_with_maximum_cost/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 (maximumCostSubstring \"adaa \" \"d \" [-1000])," 2 (maximumCostSubstring "adaa" "d" [-1000]))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (maximumCostSubstring \"abc \" \"abc \" [-1,-1,-1])," 0 (maximumCostSubstring "abc" "abc" [-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
|
find_the_substring_with_maximum_cost/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(2, maximumCostSubstring("adaa", "d", new ArrayList<>(Arrays.asList(-1000))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(0, maximumCostSubstring("abc", "abc", new ArrayList<>(Arrays.asList(-1,-1,-1))));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
find_the_substring_with_maximum_cost/meta.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
find_the_substring_with_maximum_cost/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 2 (maximumCostSubstring "adaa" "d" [-1000])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 0 (maximumCostSubstring "abc" "abc" [-1;-1;-1])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for maximumCostSubstring" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
find_the_substring_with_maximum_cost/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.maximumCostSubstring("adaa","d",[-1000]), 2)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.maximumCostSubstring("abc","abc",[-1,-1,-1]), 0)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
find_the_sum_of_encrypted_integers/haskell_tests/Main.hs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main where
|
| 3 |
+
import Test.HUnit
|
| 4 |
+
|
| 5 |
+
--Program start
|
| 6 |
+
sumOfEncryptedInt :: [Int] -> Int
|
| 7 |
+
sumOfEncryptedInt nums = undefined
|
| 8 |
+
|
| 9 |
+
--Program end
|
| 10 |
+
|
| 11 |
+
-- Test cases
|
| 12 |
+
|
| 13 |
+
test1 :: Test
|
| 14 |
+
test1 = TestCase (assertEqual "for (sumOfEncryptedInt [1,2,3])," 6 (sumOfEncryptedInt [1,2,3]))
|
| 15 |
+
|
| 16 |
+
test2 :: Test
|
| 17 |
+
test2 = TestCase (assertEqual "for (sumOfEncryptedInt [10,21,31])," 66 (sumOfEncryptedInt [10,21,31]))
|
| 18 |
+
|
| 19 |
+
test3 :: Test
|
| 20 |
+
test3 = TestCase (assertEqual "for (sumOfEncryptedInt [529, 735, 801, 668, 823, 372, 825, 297, 272, 429, 236, 727, 149, 130, 931, 606, 773, 656, 427, 16, 14, 63, 231, 330, 379, 938, 320, 490, 603, 106, 59, 421, 356, 348, 976, 597, 819, 913])," 27137 (sumOfEncryptedInt [529, 735, 801, 668, 823, 372, 825, 297, 272, 429, 236, 727, 149, 130, 931, 606, 773, 656, 427, 16, 14, 63, 231, 330, 379, 938, 320, 490, 603, 106, 59, 421, 356, 348, 976, 597, 819, 913]))
|
| 21 |
+
|
| 22 |
+
test4 :: Test
|
| 23 |
+
test4 = TestCase (assertEqual "for (sumOfEncryptedInt [141, 371, 116, 440, 168, 282, 3, 893, 952, 304, 883, 707, 320])," 8550 (sumOfEncryptedInt [141, 371, 116, 440, 168, 282, 3, 893, 952, 304, 883, 707, 320]))
|
| 24 |
+
|
| 25 |
+
test5 :: Test
|
| 26 |
+
test5 = TestCase (assertEqual "for (sumOfEncryptedInt [269, 229, 351, 250])," 3108 (sumOfEncryptedInt [269, 229, 351, 250]))
|
| 27 |
+
|
| 28 |
+
test6 :: Test
|
| 29 |
+
test6 = TestCase (assertEqual "for (sumOfEncryptedInt [980, 926, 437, 990, 825, 97, 812, 258, 360, 769, 773])," 8979 (sumOfEncryptedInt [980, 926, 437, 990, 825, 97, 812, 258, 360, 769, 773]))
|
| 30 |
+
|
| 31 |
+
test7 :: Test
|
| 32 |
+
test7 = TestCase (assertEqual "for (sumOfEncryptedInt [62, 259, 782, 150, 283, 92, 982, 577, 385, 317, 559])," 7935 (sumOfEncryptedInt [62, 259, 782, 150, 283, 92, 982, 577, 385, 317, 559]))
|
| 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
|
find_the_sum_of_encrypted_integers/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(6, sumOfEncryptedInt(Arrays.asList(1,2,3)));
|
| 14 |
+
}
|
| 15 |
+
@Test
|
| 16 |
+
public void test2() {
|
| 17 |
+
assertEquals(66, sumOfEncryptedInt(Arrays.asList(10,21,31)));
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
}
|
find_the_sum_of_encrypted_integers/meta.json
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3367,
|
| 3 |
+
"name": "find_the_sum_of_encrypted_integers",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/find-the-sum-of-encrypted-integers/",
|
| 6 |
+
"date": "2024-03-02 00:00:00",
|
| 7 |
+
"task_description": "You are given an integer array `nums` containing **positive** integers. We define a function `encrypt` such that `encrypt(x)` replaces **every** digit in `x` with the **largest** digit in `x`. For example, `encrypt(523) = 555` and `encrypt(213) = 333`. Return _the **sum **of encrypted elements_. **Example 1:** **Input: **nums = [1,2,3] **Output: **6 **Explanation:** The encrypted elements are `[1,2,3]`. The sum of encrypted elements is `1 + 2 + 3 == 6`. **Example 2:** **Input: **nums = [10,21,31] **Output: **66 **Explanation:** The encrypted elements are `[11,22,33]`. The sum of encrypted elements is `11 + 22 + 33 == 66`. **Constraints:** `1 <= nums.length <= 50` `1 <= nums[i] <= 1000`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,2,3]",
|
| 12 |
+
"output": "6 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [10,21,31]",
|
| 17 |
+
"output": "66 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
529,
|
| 24 |
+
735,
|
| 25 |
+
801,
|
| 26 |
+
668,
|
| 27 |
+
823,
|
| 28 |
+
372,
|
| 29 |
+
825,
|
| 30 |
+
297,
|
| 31 |
+
272,
|
| 32 |
+
429,
|
| 33 |
+
236,
|
| 34 |
+
727,
|
| 35 |
+
149,
|
| 36 |
+
130,
|
| 37 |
+
931,
|
| 38 |
+
606,
|
| 39 |
+
773,
|
| 40 |
+
656,
|
| 41 |
+
427,
|
| 42 |
+
16,
|
| 43 |
+
14,
|
| 44 |
+
63,
|
| 45 |
+
231,
|
| 46 |
+
330,
|
| 47 |
+
379,
|
| 48 |
+
938,
|
| 49 |
+
320,
|
| 50 |
+
490,
|
| 51 |
+
603,
|
| 52 |
+
106,
|
| 53 |
+
59,
|
| 54 |
+
421,
|
| 55 |
+
356,
|
| 56 |
+
348,
|
| 57 |
+
976,
|
| 58 |
+
597,
|
| 59 |
+
819,
|
| 60 |
+
913
|
| 61 |
+
],
|
| 62 |
+
"output": 27137
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"input": [
|
| 66 |
+
141,
|
| 67 |
+
371,
|
| 68 |
+
116,
|
| 69 |
+
440,
|
| 70 |
+
168,
|
| 71 |
+
282,
|
| 72 |
+
3,
|
| 73 |
+
893,
|
| 74 |
+
952,
|
| 75 |
+
304,
|
| 76 |
+
883,
|
| 77 |
+
707,
|
| 78 |
+
320
|
| 79 |
+
],
|
| 80 |
+
"output": 8550
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"input": [
|
| 84 |
+
269,
|
| 85 |
+
229,
|
| 86 |
+
351,
|
| 87 |
+
250
|
| 88 |
+
],
|
| 89 |
+
"output": 3108
|
| 90 |
+
},
|
| 91 |
+
{
|
| 92 |
+
"input": [
|
| 93 |
+
980,
|
| 94 |
+
926,
|
| 95 |
+
437,
|
| 96 |
+
990,
|
| 97 |
+
825,
|
| 98 |
+
97,
|
| 99 |
+
812,
|
| 100 |
+
258,
|
| 101 |
+
360,
|
| 102 |
+
769,
|
| 103 |
+
773
|
| 104 |
+
],
|
| 105 |
+
"output": 8979
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
"input": [
|
| 109 |
+
62,
|
| 110 |
+
259,
|
| 111 |
+
782,
|
| 112 |
+
150,
|
| 113 |
+
283,
|
| 114 |
+
92,
|
| 115 |
+
982,
|
| 116 |
+
577,
|
| 117 |
+
385,
|
| 118 |
+
317,
|
| 119 |
+
559
|
| 120 |
+
],
|
| 121 |
+
"output": 7935
|
| 122 |
+
}
|
| 123 |
+
],
|
| 124 |
+
"haskell_template": "sumOfEncryptedInt :: [Int] -> Int\nsumOfEncryptedInt nums ",
|
| 125 |
+
"ocaml_template": "let sumOfEncryptedInt (nums: int list) : int = ",
|
| 126 |
+
"scala_template": "def sumOfEncryptedInt(nums: List[Int]): Int = { \n \n}",
|
| 127 |
+
"java_template": "class Solution {\n public int sumOfEncryptedInt(int[] nums) {\n \n }\n}",
|
| 128 |
+
"python_template": "class Solution(object):\n def sumOfEncryptedInt(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n "
|
| 129 |
+
}
|
find_the_sum_of_encrypted_integers/ocaml_tests/main.ml
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main = struct
|
| 3 |
+
open OUnit2
|
| 4 |
+
|
| 5 |
+
(* Program start *)
|
| 6 |
+
let sumOfEncryptedInt (nums: int list) : int = failwith "Not implemented"
|
| 7 |
+
|
| 8 |
+
(* Program end *)
|
| 9 |
+
|
| 10 |
+
(* Test cases *)
|
| 11 |
+
|
| 12 |
+
let test1 _ = assert_equal 6 (sumOfEncryptedInt [1;2;3])
|
| 13 |
+
|
| 14 |
+
let test2 _ = assert_equal 66 (sumOfEncryptedInt [10;21;31])
|
| 15 |
+
|
| 16 |
+
let test3 _ = assert_equal 66 (sumOfEncryptedInt [529; 735; 801; 668; 823; 372; 825; 297; 272; 429; 236; 727; 149; 130; 931; 606; 773; 656; 427; 16; 14; 63; 231; 330; 379; 938; 320; 490; 603; 106; 59; 421; 356; 348; 976; 597; 819; 913])
|
| 17 |
+
|
| 18 |
+
let test4 _ = assert_equal 66 (sumOfEncryptedInt [141; 371; 116; 440; 168; 282; 3; 893; 952; 304; 883; 707; 320])
|
| 19 |
+
|
| 20 |
+
let test5 _ = assert_equal 66 (sumOfEncryptedInt [269; 229; 351; 250])
|
| 21 |
+
|
| 22 |
+
let test6 _ = assert_equal 66 (sumOfEncryptedInt [980; 926; 437; 990; 825; 97; 812; 258; 360; 769; 773])
|
| 23 |
+
|
| 24 |
+
let test7 _ = assert_equal 66 (sumOfEncryptedInt [62; 259; 782; 150; 283; 92; 982; 577; 385; 317; 559])
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
(* Grouping test cases *)
|
| 28 |
+
let suite = "Test Suite for sumOfEncryptedInt" >::: [
|
| 29 |
+
|
| 30 |
+
"test1" >:: test1;
|
| 31 |
+
"test2" >:: test2;
|
| 32 |
+
"test3" >:: test3;
|
| 33 |
+
"test4" >:: test4;
|
| 34 |
+
"test5" >:: test5;
|
| 35 |
+
"test6" >:: test6;
|
| 36 |
+
"test7" >:: test7;
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
(* Running the tests *)
|
| 41 |
+
let () = run_test_tt_main suite
|
| 42 |
+
end
|
find_the_sum_of_encrypted_integers/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.sumOfEncryptedInt(List(1,2,3)), 6)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.sumOfEncryptedInt(List(10,21,31)), 66)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.sumOfEncryptedInt(529,735,801,668,823,372,825,297,272,429,236,727,149,130,931,606,773,656,427,16,14,63,231,330,379,938,320,490,603,106,59,421,356,348,976,597,819,913), 27137)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.sumOfEncryptedInt(141,371,116,440,168,282,3,893,952,304,883,707,320), 8550)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.sumOfEncryptedInt(269,229,351,250), 3108)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.sumOfEncryptedInt(980,926,437,990,825,97,812,258,360,769,773), 8979)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.sumOfEncryptedInt(62,259,782,150,283,92,982,577,385,317,559), 7935)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
}
|
find_the_sum_of_subsequence_powers/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 (sumOfPowers [1,2,3,4] 3)," 4 (sumOfPowers [1,2,3,4] 3))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (sumOfPowers [2,2] 2)," 0 (sumOfPowers [2,2] 2))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (sumOfPowers [4,3,-1] 2)," 10 (sumOfPowers [4,3,-1] 2))
|
| 19 |
+
|
| 20 |
+
test4 :: Test
|
| 21 |
+
test4 = TestCase (assertEqual "for (sumOfPowers [-106, ( -105), ( -86), ( -83), ( -83), ( -79), ( -78), ( -72), ( -63), ( -52), ( -40), ( -39), ( -34), ( -20), ( -16), 6, 10, 19, 39, 43, 44, 45, 45, 61, 62, 72, 75, 81, 92, 98] 27)," 108 (sumOfPowers [-106, -105, -86, -83, -83, -79, -78, -72, -63, -52, -40, -39, -34, -20, -16, 6, 10, 19, 39, 43, 44, 45, 45, 61, 62, 72, 75, 81, 92, 98] 27))
|
| 22 |
+
|
| 23 |
+
test5 :: Test
|
| 24 |
+
test5 = TestCase (assertEqual "for (sumOfPowers [-100, ( -92), ( -75), ( -71), ( -54), ( -31), ( -23), 19, 34, 72] 2)," 3067 (sumOfPowers [-100, -92, -75, -71, -54, -31, -23, 19, 34, 72] 2))
|
| 25 |
+
|
| 26 |
+
test6 :: Test
|
| 27 |
+
test6 = TestCase (assertEqual "for (sumOfPowers [-98, ( -91), ( -50), 29, 93] 4)," 110 (sumOfPowers [-98, -91, -50, 29, 93] 4))
|
| 28 |
+
|
| 29 |
+
test7 :: Test
|
| 30 |
+
test7 = TestCase (assertEqual "for (sumOfPowers [-105, ( -104), ( -97), ( -88), ( -67), ( -65), ( -53), ( -52), ( -51), ( -51), ( -37), ( -35), ( -34), ( -28), ( -28), ( -27), ( -27), ( -20), ( -9), ( -8), ( -7), ( -6), ( -2), ( -1), 7, 16, 18, 30, 31, 32, 32, 39, 45, 59, 64, 64, 68, 77, 82, 84, 87, 89, 94, 107] 22)," 487346736 (sumOfPowers [-105, -104, -97, -88, -67, -65, -53, -52, -51, -51, -37, -35, -34, -28, -28, -27, -27, -20, -9, -8, -7, -6, -2, -1, 7, 16, 18, 30, 31, 32, 32, 39, 45, 59, 64, 64, 68, 77, 82, 84, 87, 89, 94, 107] 22))
|
| 31 |
+
|
| 32 |
+
test8 :: Test
|
| 33 |
+
test8 = TestCase (assertEqual "for (sumOfPowers [-108, ( -102), ( -95), ( -90), ( -87), ( -86), ( -82), ( -80), ( -73), ( -70), ( -62), ( -37), ( -35), ( -33), ( -15), 2, 12, 19, 28, 31, 66, 70, 78, 94, 94] 22)," 617 (sumOfPowers [-108, -102, -95, -90, -87, -86, -82, -80, -73, -70, -62, -37, -35, -33, -15, 2, 12, 19, 28, 31, 66, 70, 78, 94, 94] 22))
|
| 34 |
+
|
| 35 |
+
test9 :: Test
|
| 36 |
+
test9 = TestCase (assertEqual "for (sumOfPowers [-106, ( -104), ( -80), ( -74), ( -62), ( -49), ( -46), ( -44), ( -9), ( -7), ( -2), 8, 14, 18, 27, 32, 35, 47, 51, 70, 84, 89] 17)," 53966 (sumOfPowers [-106, -104, -80, -74, -62, -49, -46, -44, -9, -7, -2, 8, 14, 18, 27, 32, 35, 47, 51, 70, 84, 89] 17))
|
| 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
|
find_the_sum_of_subsequence_powers/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(4, sumOfPowers(new ArrayList<>(Arrays.asList(1,2,3,4)), 3));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(0, sumOfPowers(new ArrayList<>(Arrays.asList(2,2)), 2));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals(10, sumOfPowers(new ArrayList<>(Arrays.asList(4,3,-1)), 2));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
find_the_sum_of_subsequence_powers/meta.json
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3316,
|
| 3 |
+
"name": "find_the_sum_of_subsequence_powers",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/find-the-sum-of-subsequence-powers/",
|
| 6 |
+
"date": "2024-03-16 00:00:00",
|
| 7 |
+
"task_description": "You are given an integer array `nums` of length `n`, and a **positive** integer `k`. The **power** of a subsequence is defined as the **minimum** absolute difference between **any** two elements in the subsequence. Return _the **sum** of **powers** of **all** subsequences of _`nums`_ which have length_ **_equal to_** `k`. Since the answer may be large, return it **modulo** `109 + 7`. **Example 1:** **Input:** nums = [1,2,3,4], k = 3 **Output:** 4 **Explanation:** There are 4 subsequences in `nums` which have length 3: `[1,2,3]`, `[1,3,4]`, `[1,2,4]`, and `[2,3,4]`. The sum of powers is `|2 - 3| + |3 - 4| + |2 - 1| + |3 - 4| = 4`. **Example 2:** **Input:** nums = [2,2], k = 2 **Output:** 0 **Explanation:** The only subsequence in `nums` which has length 2 is `[2,2]`. The sum of powers is `|2 - 2| = 0`. **Example 3:** **Input:** nums = [4,3,-1], k = 2 **Output:** 10 **Explanation:** There are 3 subsequences in `nums` which have length 2: `[4,3]`, `[4,-1]`, and `[3,-1]`. The sum of powers is `|4 - 3| + |4 - (-1)| + |3 - (-1)| = 10`. **Constraints:** `2 <= n == nums.length <= 50` `-108 <= nums[i] <= 108 ` `2 <= k <= n`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,2,3,4], k = 3",
|
| 12 |
+
"output": "4 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [2,2], k = 2",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "nums = [4,3,-1], k = 2",
|
| 22 |
+
"output": "10 "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"private_test_cases": [
|
| 26 |
+
{
|
| 27 |
+
"input": [
|
| 28 |
+
[
|
| 29 |
+
-106,
|
| 30 |
+
-105,
|
| 31 |
+
-86,
|
| 32 |
+
-83,
|
| 33 |
+
-83,
|
| 34 |
+
-79,
|
| 35 |
+
-78,
|
| 36 |
+
-72,
|
| 37 |
+
-63,
|
| 38 |
+
-52,
|
| 39 |
+
-40,
|
| 40 |
+
-39,
|
| 41 |
+
-34,
|
| 42 |
+
-20,
|
| 43 |
+
-16,
|
| 44 |
+
6,
|
| 45 |
+
10,
|
| 46 |
+
19,
|
| 47 |
+
39,
|
| 48 |
+
43,
|
| 49 |
+
44,
|
| 50 |
+
45,
|
| 51 |
+
45,
|
| 52 |
+
61,
|
| 53 |
+
62,
|
| 54 |
+
72,
|
| 55 |
+
75,
|
| 56 |
+
81,
|
| 57 |
+
92,
|
| 58 |
+
98
|
| 59 |
+
],
|
| 60 |
+
27
|
| 61 |
+
],
|
| 62 |
+
"output": 108
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"input": [
|
| 66 |
+
[
|
| 67 |
+
-100,
|
| 68 |
+
-92,
|
| 69 |
+
-75,
|
| 70 |
+
-71,
|
| 71 |
+
-54,
|
| 72 |
+
-31,
|
| 73 |
+
-23,
|
| 74 |
+
19,
|
| 75 |
+
34,
|
| 76 |
+
72
|
| 77 |
+
],
|
| 78 |
+
2
|
| 79 |
+
],
|
| 80 |
+
"output": 3067
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"input": [
|
| 84 |
+
[
|
| 85 |
+
-98,
|
| 86 |
+
-91,
|
| 87 |
+
-50,
|
| 88 |
+
29,
|
| 89 |
+
93
|
| 90 |
+
],
|
| 91 |
+
4
|
| 92 |
+
],
|
| 93 |
+
"output": 110
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"input": [
|
| 97 |
+
[
|
| 98 |
+
-105,
|
| 99 |
+
-104,
|
| 100 |
+
-97,
|
| 101 |
+
-88,
|
| 102 |
+
-67,
|
| 103 |
+
-65,
|
| 104 |
+
-53,
|
| 105 |
+
-52,
|
| 106 |
+
-51,
|
| 107 |
+
-51,
|
| 108 |
+
-37,
|
| 109 |
+
-35,
|
| 110 |
+
-34,
|
| 111 |
+
-28,
|
| 112 |
+
-28,
|
| 113 |
+
-27,
|
| 114 |
+
-27,
|
| 115 |
+
-20,
|
| 116 |
+
-9,
|
| 117 |
+
-8,
|
| 118 |
+
-7,
|
| 119 |
+
-6,
|
| 120 |
+
-2,
|
| 121 |
+
-1,
|
| 122 |
+
7,
|
| 123 |
+
16,
|
| 124 |
+
18,
|
| 125 |
+
30,
|
| 126 |
+
31,
|
| 127 |
+
32,
|
| 128 |
+
32,
|
| 129 |
+
39,
|
| 130 |
+
45,
|
| 131 |
+
59,
|
| 132 |
+
64,
|
| 133 |
+
64,
|
| 134 |
+
68,
|
| 135 |
+
77,
|
| 136 |
+
82,
|
| 137 |
+
84,
|
| 138 |
+
87,
|
| 139 |
+
89,
|
| 140 |
+
94,
|
| 141 |
+
107
|
| 142 |
+
],
|
| 143 |
+
22
|
| 144 |
+
],
|
| 145 |
+
"output": 487346736
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"input": [
|
| 149 |
+
[
|
| 150 |
+
-108,
|
| 151 |
+
-102,
|
| 152 |
+
-95,
|
| 153 |
+
-90,
|
| 154 |
+
-87,
|
| 155 |
+
-86,
|
| 156 |
+
-82,
|
| 157 |
+
-80,
|
| 158 |
+
-73,
|
| 159 |
+
-70,
|
| 160 |
+
-62,
|
| 161 |
+
-37,
|
| 162 |
+
-35,
|
| 163 |
+
-33,
|
| 164 |
+
-15,
|
| 165 |
+
2,
|
| 166 |
+
12,
|
| 167 |
+
19,
|
| 168 |
+
28,
|
| 169 |
+
31,
|
| 170 |
+
66,
|
| 171 |
+
70,
|
| 172 |
+
78,
|
| 173 |
+
94,
|
| 174 |
+
94
|
| 175 |
+
],
|
| 176 |
+
22
|
| 177 |
+
],
|
| 178 |
+
"output": 617
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"input": [
|
| 182 |
+
[
|
| 183 |
+
-106,
|
| 184 |
+
-104,
|
| 185 |
+
-80,
|
| 186 |
+
-74,
|
| 187 |
+
-62,
|
| 188 |
+
-49,
|
| 189 |
+
-46,
|
| 190 |
+
-44,
|
| 191 |
+
-9,
|
| 192 |
+
-7,
|
| 193 |
+
-2,
|
| 194 |
+
8,
|
| 195 |
+
14,
|
| 196 |
+
18,
|
| 197 |
+
27,
|
| 198 |
+
32,
|
| 199 |
+
35,
|
| 200 |
+
47,
|
| 201 |
+
51,
|
| 202 |
+
70,
|
| 203 |
+
84,
|
| 204 |
+
89
|
| 205 |
+
],
|
| 206 |
+
17
|
| 207 |
+
],
|
| 208 |
+
"output": 53966
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"input": [
|
| 212 |
+
[
|
| 213 |
+
-92,
|
| 214 |
+
-76,
|
| 215 |
+
-72,
|
| 216 |
+
-70,
|
| 217 |
+
-29,
|
| 218 |
+
-26,
|
| 219 |
+
-22,
|
| 220 |
+
-18,
|
| 221 |
+
0,
|
| 222 |
+
2,
|
| 223 |
+
20,
|
| 224 |
+
21,
|
| 225 |
+
22,
|
| 226 |
+
29,
|
| 227 |
+
32,
|
| 228 |
+
38,
|
| 229 |
+
50,
|
| 230 |
+
52,
|
| 231 |
+
54,
|
| 232 |
+
54,
|
| 233 |
+
55,
|
| 234 |
+
59,
|
| 235 |
+
104,
|
| 236 |
+
105
|
| 237 |
+
],
|
| 238 |
+
11
|
| 239 |
+
],
|
| 240 |
+
"output": 2872096
|
| 241 |
+
},
|
| 242 |
+
{
|
| 243 |
+
"input": [
|
| 244 |
+
[
|
| 245 |
+
-95,
|
| 246 |
+
-83,
|
| 247 |
+
-81,
|
| 248 |
+
-71,
|
| 249 |
+
-59,
|
| 250 |
+
-51,
|
| 251 |
+
-48,
|
| 252 |
+
-37,
|
| 253 |
+
-36,
|
| 254 |
+
-34,
|
| 255 |
+
-24,
|
| 256 |
+
-23,
|
| 257 |
+
-19,
|
| 258 |
+
-12,
|
| 259 |
+
-9,
|
| 260 |
+
-7,
|
| 261 |
+
6,
|
| 262 |
+
9,
|
| 263 |
+
25,
|
| 264 |
+
26,
|
| 265 |
+
28,
|
| 266 |
+
42,
|
| 267 |
+
52,
|
| 268 |
+
55,
|
| 269 |
+
62,
|
| 270 |
+
65,
|
| 271 |
+
81,
|
| 272 |
+
88,
|
| 273 |
+
91,
|
| 274 |
+
99,
|
| 275 |
+
106,
|
| 276 |
+
107
|
| 277 |
+
],
|
| 278 |
+
21
|
| 279 |
+
],
|
| 280 |
+
"output": 140926432
|
| 281 |
+
},
|
| 282 |
+
{
|
| 283 |
+
"input": [
|
| 284 |
+
[
|
| 285 |
+
-108,
|
| 286 |
+
-104,
|
| 287 |
+
-81,
|
| 288 |
+
-75,
|
| 289 |
+
-37,
|
| 290 |
+
-33,
|
| 291 |
+
-30,
|
| 292 |
+
-17,
|
| 293 |
+
7,
|
| 294 |
+
14,
|
| 295 |
+
16,
|
| 296 |
+
42,
|
| 297 |
+
46,
|
| 298 |
+
55,
|
| 299 |
+
61,
|
| 300 |
+
61,
|
| 301 |
+
82,
|
| 302 |
+
86,
|
| 303 |
+
104,
|
| 304 |
+
105,
|
| 305 |
+
108
|
| 306 |
+
],
|
| 307 |
+
6
|
| 308 |
+
],
|
| 309 |
+
"output": 365683
|
| 310 |
+
},
|
| 311 |
+
{
|
| 312 |
+
"input": [
|
| 313 |
+
[
|
| 314 |
+
-96,
|
| 315 |
+
-67,
|
| 316 |
+
-53,
|
| 317 |
+
-24,
|
| 318 |
+
-5,
|
| 319 |
+
4,
|
| 320 |
+
13,
|
| 321 |
+
30,
|
| 322 |
+
57,
|
| 323 |
+
78,
|
| 324 |
+
83,
|
| 325 |
+
86,
|
| 326 |
+
105
|
| 327 |
+
],
|
| 328 |
+
4
|
| 329 |
+
],
|
| 330 |
+
"output": 13276
|
| 331 |
+
}
|
| 332 |
+
],
|
| 333 |
+
"haskell_template": "sumOfPowers :: [Int] -> Int -> Int\nsumOfPowers nums k ",
|
| 334 |
+
"ocaml_template": "let sumOfPowers (nums: int list) (k: int) : int = ",
|
| 335 |
+
"scala_template": "def sumOfPowers(nums: List[Int],k: Int): Int = { \n \n}",
|
| 336 |
+
"java_template": "class Solution {\n public int sumOfPowers(int[] nums, int k) {\n \n }\n}",
|
| 337 |
+
"python_template": "class Solution(object):\n def sumOfPowers(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n "
|
| 338 |
+
}
|
find_the_sum_of_subsequence_powers/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 4 (sumOfPowers [1;2;3;4] 3)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 0 (sumOfPowers [2;2] 2)
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal 10 (sumOfPowers [4;3;-1] 2)
|
| 16 |
+
|
| 17 |
+
let test4 _ = assert_equal 108 (sumOfPowers [-106; ( -105); ( -86); ( -83); ( -83); ( -79); ( -78); ( -72); ( -63); ( -52); ( -40); ( -39); ( -34); ( -20); ( -16); 6; 10; 19; 39; 43; 44; 45; 45; 61; 62; 72; 75; 81; 92; 98] 27)
|
| 18 |
+
|
| 19 |
+
let test5 _ = assert_equal 3067 (sumOfPowers [-100; ( -92); ( -75); ( -71); ( -54); ( -31); ( -23); 19; 34; 72] 2)
|
| 20 |
+
|
| 21 |
+
let test6 _ = assert_equal 110 (sumOfPowers [-98; ( -91); ( -50); 29; 93] 4)
|
| 22 |
+
|
| 23 |
+
let test7 _ = assert_equal 487346736 (sumOfPowers [-105; ( -104); ( -97); ( -88); ( -67); ( -65); ( -53); ( -52); ( -51); ( -51); ( -37); ( -35); ( -34); ( -28); ( -28); ( -27); ( -27); ( -20); ( -9); ( -8); ( -7); ( -6); ( -2); ( -1); 7; 16; 18; 30; 31; 32; 32; 39; 45; 59; 64; 64; 68; 77; 82; 84; 87; 89; 94; 107] 22)
|
| 24 |
+
|
| 25 |
+
let test8 _ = assert_equal 617 (sumOfPowers [-108; ( -102); ( -95); ( -90); ( -87); ( -86); ( -82); ( -80); ( -73); ( -70); ( -62); ( -37); ( -35); ( -33); ( -15); 2; 12; 19; 28; 31; 66; 70; 78; 94; 94] 22)
|
| 26 |
+
|
| 27 |
+
let test9 _ = assert_equal 53966 (sumOfPowers [-106; ( -104); ( -80); ( -74); ( -62); ( -49); ( -46); ( -44); ( -9); ( -7); ( -2); 8; 14; 18; 27; 32; 35; 47; 51; 70; 84; 89] 17)
|
| 28 |
+
|
| 29 |
+
let test10 _ = assert_equal 2872096 (sumOfPowers [-92; ( -76); ( -72); ( -70); ( -29); ( -26); ( -22); ( -18); 0; 2; 20; 21; 22; 29; 32; 38; 50; 52; 54; 54; 55; 59; 104; 105] 11)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
(* Grouping test cases *)
|
| 33 |
+
let suite = "Test Suite for sumOfPowers" >::: [
|
| 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
|
find_the_sum_of_subsequence_powers/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.sumOfPowers(List(1,2,3,4),3), 4)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.sumOfPowers(List(2,2),2), 0)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.sumOfPowers(List(4,3,-1),2), 10)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.sumOfPowers(List(-106, -105, -86, -83, -83, -79, -78, -72, -63, -52, -40, -39, -34, -20, -16, 6, 10, 19, 39, 43, 44, 45, 45, 61, 62, 72, 75, 81, 92, 98),27), 108)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.sumOfPowers(List(-100, -92, -75, -71, -54, -31, -23, 19, 34, 72),2), 3067)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.sumOfPowers(List(-98, -91, -50, 29, 93),4), 110)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.sumOfPowers(List(-105, -104, -97, -88, -67, -65, -53, -52, -51, -51, -37, -35, -34, -28, -28, -27, -27, -20, -9, -8, -7, -6, -2, -1, 7, 16, 18, 30, 31, 32, 32, 39, 45, 59, 64, 64, 68, 77, 82, 84, 87, 89, 94, 107),22), 487346736)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("test8") {
|
| 33 |
+
assertEquals(Main.sumOfPowers(List(-108, -102, -95, -90, -87, -86, -82, -80, -73, -70, -62, -37, -35, -33, -15, 2, 12, 19, 28, 31, 66, 70, 78, 94, 94),22), 617)
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
test("test9") {
|
| 37 |
+
assertEquals(Main.sumOfPowers(List(-106, -104, -80, -74, -62, -49, -46, -44, -9, -7, -2, 8, 14, 18, 27, 32, 35, 47, 51, 70, 84, 89),17), 53966)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
test("test10") {
|
| 41 |
+
assertEquals(Main.sumOfPowers(List(-92, -76, -72, -70, -29, -26, -22, -18, 0, 2, 20, 21, 22, 29, 32, 38, 50, 52, 54, 54, 55, 59, 104, 105),11), 2872096)
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
find_the_sum_of_the_power_of_all_subsequences/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 (sumOfPower [1,2,3] 3)," 6 (sumOfPower [1,2,3] 3))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (sumOfPower [2,3,3] 5)," 4 (sumOfPower [2,3,3] 5))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (sumOfPower [1,2,3] 7)," 0 (sumOfPower [1,2,3] 7))
|
| 19 |
+
|
| 20 |
+
test4 :: Test
|
| 21 |
+
test4 = TestCase (assertEqual "for (sumOfPower [7248, 5128, 7789, 1275, 5420, 6934, 5119, 5373, 9374, 1981, 2257, 664, 1166, 7308, 316, 3628, 9983, 7545, 4593, 2145, 4397, 8021, 6121, 4422, 1316, 8554, 5840, 4154, 7402, 2393, 3311, 7064, 3965, 3434, 7432, 6487, 3170, 5205, 6887, 4106, 7834, 8725, 2164, 402, 3684, 7600, 7056, 9661, 8828, 9157, 8356] 81)," 0 (sumOfPower [7248, 5128, 7789, 1275, 5420, 6934, 5119, 5373, 9374, 1981, 2257, 664, 1166, 7308, 316, 3628, 9983, 7545, 4593, 2145, 4397, 8021, 6121, 4422, 1316, 8554, 5840, 4154, 7402, 2393, 3311, 7064, 3965, 3434, 7432, 6487, 3170, 5205, 6887, 4106, 7834, 8725, 2164, 402, 3684, 7600, 7056, 9661, 8828, 9157, 8356] 81))
|
| 22 |
+
|
| 23 |
+
test5 :: Test
|
| 24 |
+
test5 = TestCase (assertEqual "for (sumOfPower [6119, 1657, 472, 6891, 4439, 7253, 3499, 1025, 929, 6840, 4565, 9160, 1880, 1216, 165, 178, 4294, 1726, 563, 5004, 2064, 3112, 8755, 1776, 9957, 2473, 6001, 4263, 7148, 1456, 9288, 9346, 6719, 7893, 383, 7149, 7434, 3692, 2846, 5073, 1587, 1456, 1746, 547] 84)," 0 (sumOfPower [6119, 1657, 472, 6891, 4439, 7253, 3499, 1025, 929, 6840, 4565, 9160, 1880, 1216, 165, 178, 4294, 1726, 563, 5004, 2064, 3112, 8755, 1776, 9957, 2473, 6001, 4263, 7148, 1456, 9288, 9346, 6719, 7893, 383, 7149, 7434, 3692, 2846, 5073, 1587, 1456, 1746, 547] 84))
|
| 25 |
+
|
| 26 |
+
test6 :: Test
|
| 27 |
+
test6 = TestCase (assertEqual "for (sumOfPower [7396, 2993, 3753, 6781, 971, 2840, 1164, 8638, 6345, 7335, 9550, 7845, 2957, 9716, 5873, 200, 3525, 3860, 9215, 6783, 6625, 4773, 6703, 2503, 8471, 4507, 5949, 9626, 3351, 3245, 1857, 1472, 5988, 4944, 1194, 966, 7063, 6214, 5657, 3165, 561, 61, 5158, 5025, 8276, 795, 3456, 605, 2032, 2941, 93, 6988, 4450, 3945, 866, 5645, 1682, 4701, 8187, 4539, 5306, 8092, 7599, 369, 9813, 4265, 869, 4237, 1950, 1246, 8593, 2617, 4560, 5679, 8530, 5891] 65)," 0 (sumOfPower [7396, 2993, 3753, 6781, 971, 2840, 1164, 8638, 6345, 7335, 9550, 7845, 2957, 9716, 5873, 200, 3525, 3860, 9215, 6783, 6625, 4773, 6703, 2503, 8471, 4507, 5949, 9626, 3351, 3245, 1857, 1472, 5988, 4944, 1194, 966, 7063, 6214, 5657, 3165, 561, 61, 5158, 5025, 8276, 795, 3456, 605, 2032, 2941, 93, 6988, 4450, 3945, 866, 5645, 1682, 4701, 8187, 4539, 5306, 8092, 7599, 369, 9813, 4265, 869, 4237, 1950, 1246, 8593, 2617, 4560, 5679, 8530, 5891] 65))
|
| 28 |
+
|
| 29 |
+
test7 :: Test
|
| 30 |
+
test7 = TestCase (assertEqual "for (sumOfPower [9510, 4506, 5096, 4394, 8662, 4919, 7641, 5551, 6851, 3376, 3180, 1858, 8385, 9252, 3855, 4965] 37)," 0 (sumOfPower [9510, 4506, 5096, 4394, 8662, 4919, 7641, 5551, 6851, 3376, 3180, 1858, 8385, 9252, 3855, 4965] 37))
|
| 31 |
+
|
| 32 |
+
test8 :: Test
|
| 33 |
+
test8 = TestCase (assertEqual "for (sumOfPower [9115, 6306, 9419, 4571, 8435, 5564, 2759, 5505, 1517, 9677, 7124, 6774, 1954, 8484, 2642, 1450, 7851, 7570, 335, 4548, 3136, 5932, 8999, 5660, 7017, 406, 7162, 4047, 4817, 4576, 6803, 2406, 2847, 8910, 7312, 6670, 6095, 2712, 8576, 1098, 5038, 4376, 5135, 5210, 9776, 1229, 6138, 2592, 3689, 6229, 6227, 3555, 7955, 9069, 7196, 4426, 6969, 7830, 7892, 4345, 4001, 9754, 4661, 9376, 6509, 792, 9654, 8016, 7539, 1237, 2310, 8277, 1322, 4335, 5252, 3354, 9862, 6076, 4440, 4997, 9974, 8981, 5933, 8901, 4479, 1299, 7990, 6994, 7223, 1349, 9945, 8644, 6332, 2350, 6073, 9038, 1763, 6751, 9869] 42)," 0 (sumOfPower [9115, 6306, 9419, 4571, 8435, 5564, 2759, 5505, 1517, 9677, 7124, 6774, 1954, 8484, 2642, 1450, 7851, 7570, 335, 4548, 3136, 5932, 8999, 5660, 7017, 406, 7162, 4047, 4817, 4576, 6803, 2406, 2847, 8910, 7312, 6670, 6095, 2712, 8576, 1098, 5038, 4376, 5135, 5210, 9776, 1229, 6138, 2592, 3689, 6229, 6227, 3555, 7955, 9069, 7196, 4426, 6969, 7830, 7892, 4345, 4001, 9754, 4661, 9376, 6509, 792, 9654, 8016, 7539, 1237, 2310, 8277, 1322, 4335, 5252, 3354, 9862, 6076, 4440, 4997, 9974, 8981, 5933, 8901, 4479, 1299, 7990, 6994, 7223, 1349, 9945, 8644, 6332, 2350, 6073, 9038, 1763, 6751, 9869] 42))
|
| 34 |
+
|
| 35 |
+
test9 :: Test
|
| 36 |
+
test9 = TestCase (assertEqual "for (sumOfPower [2488, 7431, 4377, 6084, 2819, 7446, 7133, 5703, 8172, 9493, 5472, 2449, 372, 2481, 8492, 8694, 8110, 4954, 9731, 7990, 2063, 2804, 8105, 8167, 2685, 9883, 5971, 9019, 6984, 4723, 9368, 2628, 2283, 9252, 9318, 1667, 4881, 735, 2415, 1129, 4852, 10, 4739, 7295] 59)," 0 (sumOfPower [2488, 7431, 4377, 6084, 2819, 7446, 7133, 5703, 8172, 9493, 5472, 2449, 372, 2481, 8492, 8694, 8110, 4954, 9731, 7990, 2063, 2804, 8105, 8167, 2685, 9883, 5971, 9019, 6984, 4723, 9368, 2628, 2283, 9252, 9318, 1667, 4881, 735, 2415, 1129, 4852, 10, 4739, 7295] 59))
|
| 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
|
find_the_sum_of_the_power_of_all_subsequences/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(6, sumOfPower(new ArrayList<>(Arrays.asList(1,2,3)), 3));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(4, sumOfPower(new ArrayList<>(Arrays.asList(2,3,3)), 5));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals(0, sumOfPower(new ArrayList<>(Arrays.asList(1,2,3)), 7));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
find_the_sum_of_the_power_of_all_subsequences/meta.json
ADDED
|
@@ -0,0 +1,627 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3345,
|
| 3 |
+
"name": "find_the_sum_of_the_power_of_all_subsequences",
|
| 4 |
+
"difficulty": "Hard",
|
| 5 |
+
"link": "https://leetcode.com/problems/find-the-sum-of-the-power-of-all-subsequences/",
|
| 6 |
+
"date": "2024-03-02 00:00:00",
|
| 7 |
+
"task_description": "You are given an integer array `nums` of length `n` and a **positive** integer `k`. The **power** of an array of integers is defined as the number of subsequences with their sum **equal** to `k`. Return _the **sum** of **power** of all subsequences of_ `nums`_._ Since the answer may be very large, return it **modulo** `109 + 7`. **Example 1:** **Input: ** nums = [1,2,3], k = 3 **Output: ** 6 **Explanation:** There are `5` subsequences of nums with non-zero power: The subsequence `[**1**,**2**,**3**]` has `2` subsequences with `sum == 3`: `[1,2,3]` and `[1,2,3]`. The subsequence `[**1**,2,**3**]` has `1` subsequence with `sum == 3`: `[1,2,3]`. The subsequence `[1,**2**,**3**]` has `1` subsequence with `sum == 3`: `[1,2,3]`. The subsequence `[**1**,**2**,3]` has `1` subsequence with `sum == 3`: `[1,2,3]`. The subsequence `[1,2,**3**]` has `1` subsequence with `sum == 3`: `[1,2,3]`. Hence the answer is `2 + 1 + 1 + 1 + 1 = 6`. **Example 2:** **Input: ** nums = [2,3,3], k = 5 **Output: ** 4 **Explanation:** There are `3` subsequences of nums with non-zero power: The subsequence `[**2**,**3**,**3**]` has 2 subsequences with `sum == 5`: `[2,3,3]` and `[2,3,3]`. The subsequence `[**2**,3,**3**]` has 1 subsequence with `sum == 5`: `[2,3,3]`. The subsequence `[**2**,**3**,3]` has 1 subsequence with `sum == 5`: `[2,3,3]`. Hence the answer is `2 + 1 + 1 = 4`. **Example 3:** **Input: ** nums = [1,2,3], k = 7 **Output: ** 0 **Explanation: **There exists no subsequence with sum `7`. Hence all subsequences of nums have `power = 0`. **Constraints:** `1 <= n <= 100` `1 <= nums[i] <= 104` `1 <= k <= 100`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,2,3], k = 3",
|
| 12 |
+
"output": "6 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [2,3,3], k = 5",
|
| 17 |
+
"output": "4 "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "nums = [1,2,3], k = 7",
|
| 22 |
+
"output": "0 "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"private_test_cases": [
|
| 26 |
+
{
|
| 27 |
+
"input": [
|
| 28 |
+
[
|
| 29 |
+
7248,
|
| 30 |
+
5128,
|
| 31 |
+
7789,
|
| 32 |
+
1275,
|
| 33 |
+
5420,
|
| 34 |
+
6934,
|
| 35 |
+
5119,
|
| 36 |
+
5373,
|
| 37 |
+
9374,
|
| 38 |
+
1981,
|
| 39 |
+
2257,
|
| 40 |
+
664,
|
| 41 |
+
1166,
|
| 42 |
+
7308,
|
| 43 |
+
316,
|
| 44 |
+
3628,
|
| 45 |
+
9983,
|
| 46 |
+
7545,
|
| 47 |
+
4593,
|
| 48 |
+
2145,
|
| 49 |
+
4397,
|
| 50 |
+
8021,
|
| 51 |
+
6121,
|
| 52 |
+
4422,
|
| 53 |
+
1316,
|
| 54 |
+
8554,
|
| 55 |
+
5840,
|
| 56 |
+
4154,
|
| 57 |
+
7402,
|
| 58 |
+
2393,
|
| 59 |
+
3311,
|
| 60 |
+
7064,
|
| 61 |
+
3965,
|
| 62 |
+
3434,
|
| 63 |
+
7432,
|
| 64 |
+
6487,
|
| 65 |
+
3170,
|
| 66 |
+
5205,
|
| 67 |
+
6887,
|
| 68 |
+
4106,
|
| 69 |
+
7834,
|
| 70 |
+
8725,
|
| 71 |
+
2164,
|
| 72 |
+
402,
|
| 73 |
+
3684,
|
| 74 |
+
7600,
|
| 75 |
+
7056,
|
| 76 |
+
9661,
|
| 77 |
+
8828,
|
| 78 |
+
9157,
|
| 79 |
+
8356
|
| 80 |
+
],
|
| 81 |
+
81
|
| 82 |
+
],
|
| 83 |
+
"output": 0
|
| 84 |
+
},
|
| 85 |
+
{
|
| 86 |
+
"input": [
|
| 87 |
+
[
|
| 88 |
+
6119,
|
| 89 |
+
1657,
|
| 90 |
+
472,
|
| 91 |
+
6891,
|
| 92 |
+
4439,
|
| 93 |
+
7253,
|
| 94 |
+
3499,
|
| 95 |
+
1025,
|
| 96 |
+
929,
|
| 97 |
+
6840,
|
| 98 |
+
4565,
|
| 99 |
+
9160,
|
| 100 |
+
1880,
|
| 101 |
+
1216,
|
| 102 |
+
165,
|
| 103 |
+
178,
|
| 104 |
+
4294,
|
| 105 |
+
1726,
|
| 106 |
+
563,
|
| 107 |
+
5004,
|
| 108 |
+
2064,
|
| 109 |
+
3112,
|
| 110 |
+
8755,
|
| 111 |
+
1776,
|
| 112 |
+
9957,
|
| 113 |
+
2473,
|
| 114 |
+
6001,
|
| 115 |
+
4263,
|
| 116 |
+
7148,
|
| 117 |
+
1456,
|
| 118 |
+
9288,
|
| 119 |
+
9346,
|
| 120 |
+
6719,
|
| 121 |
+
7893,
|
| 122 |
+
383,
|
| 123 |
+
7149,
|
| 124 |
+
7434,
|
| 125 |
+
3692,
|
| 126 |
+
2846,
|
| 127 |
+
5073,
|
| 128 |
+
1587,
|
| 129 |
+
1456,
|
| 130 |
+
1746,
|
| 131 |
+
547
|
| 132 |
+
],
|
| 133 |
+
84
|
| 134 |
+
],
|
| 135 |
+
"output": 0
|
| 136 |
+
},
|
| 137 |
+
{
|
| 138 |
+
"input": [
|
| 139 |
+
[
|
| 140 |
+
7396,
|
| 141 |
+
2993,
|
| 142 |
+
3753,
|
| 143 |
+
6781,
|
| 144 |
+
971,
|
| 145 |
+
2840,
|
| 146 |
+
1164,
|
| 147 |
+
8638,
|
| 148 |
+
6345,
|
| 149 |
+
7335,
|
| 150 |
+
9550,
|
| 151 |
+
7845,
|
| 152 |
+
2957,
|
| 153 |
+
9716,
|
| 154 |
+
5873,
|
| 155 |
+
200,
|
| 156 |
+
3525,
|
| 157 |
+
3860,
|
| 158 |
+
9215,
|
| 159 |
+
6783,
|
| 160 |
+
6625,
|
| 161 |
+
4773,
|
| 162 |
+
6703,
|
| 163 |
+
2503,
|
| 164 |
+
8471,
|
| 165 |
+
4507,
|
| 166 |
+
5949,
|
| 167 |
+
9626,
|
| 168 |
+
3351,
|
| 169 |
+
3245,
|
| 170 |
+
1857,
|
| 171 |
+
1472,
|
| 172 |
+
5988,
|
| 173 |
+
4944,
|
| 174 |
+
1194,
|
| 175 |
+
966,
|
| 176 |
+
7063,
|
| 177 |
+
6214,
|
| 178 |
+
5657,
|
| 179 |
+
3165,
|
| 180 |
+
561,
|
| 181 |
+
61,
|
| 182 |
+
5158,
|
| 183 |
+
5025,
|
| 184 |
+
8276,
|
| 185 |
+
795,
|
| 186 |
+
3456,
|
| 187 |
+
605,
|
| 188 |
+
2032,
|
| 189 |
+
2941,
|
| 190 |
+
93,
|
| 191 |
+
6988,
|
| 192 |
+
4450,
|
| 193 |
+
3945,
|
| 194 |
+
866,
|
| 195 |
+
5645,
|
| 196 |
+
1682,
|
| 197 |
+
4701,
|
| 198 |
+
8187,
|
| 199 |
+
4539,
|
| 200 |
+
5306,
|
| 201 |
+
8092,
|
| 202 |
+
7599,
|
| 203 |
+
369,
|
| 204 |
+
9813,
|
| 205 |
+
4265,
|
| 206 |
+
869,
|
| 207 |
+
4237,
|
| 208 |
+
1950,
|
| 209 |
+
1246,
|
| 210 |
+
8593,
|
| 211 |
+
2617,
|
| 212 |
+
4560,
|
| 213 |
+
5679,
|
| 214 |
+
8530,
|
| 215 |
+
5891
|
| 216 |
+
],
|
| 217 |
+
65
|
| 218 |
+
],
|
| 219 |
+
"output": 0
|
| 220 |
+
},
|
| 221 |
+
{
|
| 222 |
+
"input": [
|
| 223 |
+
[
|
| 224 |
+
9510,
|
| 225 |
+
4506,
|
| 226 |
+
5096,
|
| 227 |
+
4394,
|
| 228 |
+
8662,
|
| 229 |
+
4919,
|
| 230 |
+
7641,
|
| 231 |
+
5551,
|
| 232 |
+
6851,
|
| 233 |
+
3376,
|
| 234 |
+
3180,
|
| 235 |
+
1858,
|
| 236 |
+
8385,
|
| 237 |
+
9252,
|
| 238 |
+
3855,
|
| 239 |
+
4965
|
| 240 |
+
],
|
| 241 |
+
37
|
| 242 |
+
],
|
| 243 |
+
"output": 0
|
| 244 |
+
},
|
| 245 |
+
{
|
| 246 |
+
"input": [
|
| 247 |
+
[
|
| 248 |
+
9115,
|
| 249 |
+
6306,
|
| 250 |
+
9419,
|
| 251 |
+
4571,
|
| 252 |
+
8435,
|
| 253 |
+
5564,
|
| 254 |
+
2759,
|
| 255 |
+
5505,
|
| 256 |
+
1517,
|
| 257 |
+
9677,
|
| 258 |
+
7124,
|
| 259 |
+
6774,
|
| 260 |
+
1954,
|
| 261 |
+
8484,
|
| 262 |
+
2642,
|
| 263 |
+
1450,
|
| 264 |
+
7851,
|
| 265 |
+
7570,
|
| 266 |
+
335,
|
| 267 |
+
4548,
|
| 268 |
+
3136,
|
| 269 |
+
5932,
|
| 270 |
+
8999,
|
| 271 |
+
5660,
|
| 272 |
+
7017,
|
| 273 |
+
406,
|
| 274 |
+
7162,
|
| 275 |
+
4047,
|
| 276 |
+
4817,
|
| 277 |
+
4576,
|
| 278 |
+
6803,
|
| 279 |
+
2406,
|
| 280 |
+
2847,
|
| 281 |
+
8910,
|
| 282 |
+
7312,
|
| 283 |
+
6670,
|
| 284 |
+
6095,
|
| 285 |
+
2712,
|
| 286 |
+
8576,
|
| 287 |
+
1098,
|
| 288 |
+
5038,
|
| 289 |
+
4376,
|
| 290 |
+
5135,
|
| 291 |
+
5210,
|
| 292 |
+
9776,
|
| 293 |
+
1229,
|
| 294 |
+
6138,
|
| 295 |
+
2592,
|
| 296 |
+
3689,
|
| 297 |
+
6229,
|
| 298 |
+
6227,
|
| 299 |
+
3555,
|
| 300 |
+
7955,
|
| 301 |
+
9069,
|
| 302 |
+
7196,
|
| 303 |
+
4426,
|
| 304 |
+
6969,
|
| 305 |
+
7830,
|
| 306 |
+
7892,
|
| 307 |
+
4345,
|
| 308 |
+
4001,
|
| 309 |
+
9754,
|
| 310 |
+
4661,
|
| 311 |
+
9376,
|
| 312 |
+
6509,
|
| 313 |
+
792,
|
| 314 |
+
9654,
|
| 315 |
+
8016,
|
| 316 |
+
7539,
|
| 317 |
+
1237,
|
| 318 |
+
2310,
|
| 319 |
+
8277,
|
| 320 |
+
1322,
|
| 321 |
+
4335,
|
| 322 |
+
5252,
|
| 323 |
+
3354,
|
| 324 |
+
9862,
|
| 325 |
+
6076,
|
| 326 |
+
4440,
|
| 327 |
+
4997,
|
| 328 |
+
9974,
|
| 329 |
+
8981,
|
| 330 |
+
5933,
|
| 331 |
+
8901,
|
| 332 |
+
4479,
|
| 333 |
+
1299,
|
| 334 |
+
7990,
|
| 335 |
+
6994,
|
| 336 |
+
7223,
|
| 337 |
+
1349,
|
| 338 |
+
9945,
|
| 339 |
+
8644,
|
| 340 |
+
6332,
|
| 341 |
+
2350,
|
| 342 |
+
6073,
|
| 343 |
+
9038,
|
| 344 |
+
1763,
|
| 345 |
+
6751,
|
| 346 |
+
9869
|
| 347 |
+
],
|
| 348 |
+
42
|
| 349 |
+
],
|
| 350 |
+
"output": 0
|
| 351 |
+
},
|
| 352 |
+
{
|
| 353 |
+
"input": [
|
| 354 |
+
[
|
| 355 |
+
2488,
|
| 356 |
+
7431,
|
| 357 |
+
4377,
|
| 358 |
+
6084,
|
| 359 |
+
2819,
|
| 360 |
+
7446,
|
| 361 |
+
7133,
|
| 362 |
+
5703,
|
| 363 |
+
8172,
|
| 364 |
+
9493,
|
| 365 |
+
5472,
|
| 366 |
+
2449,
|
| 367 |
+
372,
|
| 368 |
+
2481,
|
| 369 |
+
8492,
|
| 370 |
+
8694,
|
| 371 |
+
8110,
|
| 372 |
+
4954,
|
| 373 |
+
9731,
|
| 374 |
+
7990,
|
| 375 |
+
2063,
|
| 376 |
+
2804,
|
| 377 |
+
8105,
|
| 378 |
+
8167,
|
| 379 |
+
2685,
|
| 380 |
+
9883,
|
| 381 |
+
5971,
|
| 382 |
+
9019,
|
| 383 |
+
6984,
|
| 384 |
+
4723,
|
| 385 |
+
9368,
|
| 386 |
+
2628,
|
| 387 |
+
2283,
|
| 388 |
+
9252,
|
| 389 |
+
9318,
|
| 390 |
+
1667,
|
| 391 |
+
4881,
|
| 392 |
+
735,
|
| 393 |
+
2415,
|
| 394 |
+
1129,
|
| 395 |
+
4852,
|
| 396 |
+
10,
|
| 397 |
+
4739,
|
| 398 |
+
7295
|
| 399 |
+
],
|
| 400 |
+
59
|
| 401 |
+
],
|
| 402 |
+
"output": 0
|
| 403 |
+
},
|
| 404 |
+
{
|
| 405 |
+
"input": [
|
| 406 |
+
[
|
| 407 |
+
3112,
|
| 408 |
+
3633,
|
| 409 |
+
1372,
|
| 410 |
+
2057
|
| 411 |
+
],
|
| 412 |
+
90
|
| 413 |
+
],
|
| 414 |
+
"output": 0
|
| 415 |
+
},
|
| 416 |
+
{
|
| 417 |
+
"input": [
|
| 418 |
+
[
|
| 419 |
+
2159,
|
| 420 |
+
8059,
|
| 421 |
+
5457,
|
| 422 |
+
1073,
|
| 423 |
+
2930,
|
| 424 |
+
2332,
|
| 425 |
+
8481,
|
| 426 |
+
6106,
|
| 427 |
+
3089,
|
| 428 |
+
8998,
|
| 429 |
+
2740,
|
| 430 |
+
4340,
|
| 431 |
+
96,
|
| 432 |
+
8382,
|
| 433 |
+
6275,
|
| 434 |
+
2918,
|
| 435 |
+
8951,
|
| 436 |
+
6967,
|
| 437 |
+
1568,
|
| 438 |
+
2443,
|
| 439 |
+
5919,
|
| 440 |
+
9551,
|
| 441 |
+
3878,
|
| 442 |
+
4651,
|
| 443 |
+
1809,
|
| 444 |
+
3312,
|
| 445 |
+
6455,
|
| 446 |
+
6974,
|
| 447 |
+
5135,
|
| 448 |
+
550,
|
| 449 |
+
9042,
|
| 450 |
+
4928,
|
| 451 |
+
8311,
|
| 452 |
+
4516,
|
| 453 |
+
8888,
|
| 454 |
+
215,
|
| 455 |
+
5680,
|
| 456 |
+
3223,
|
| 457 |
+
4643,
|
| 458 |
+
758,
|
| 459 |
+
1354,
|
| 460 |
+
4224,
|
| 461 |
+
1576,
|
| 462 |
+
4155,
|
| 463 |
+
9825,
|
| 464 |
+
6360,
|
| 465 |
+
9020,
|
| 466 |
+
348,
|
| 467 |
+
2649,
|
| 468 |
+
4133,
|
| 469 |
+
50,
|
| 470 |
+
8576,
|
| 471 |
+
6833,
|
| 472 |
+
2707,
|
| 473 |
+
1923,
|
| 474 |
+
8343,
|
| 475 |
+
4119,
|
| 476 |
+
6428,
|
| 477 |
+
7908,
|
| 478 |
+
9491,
|
| 479 |
+
131,
|
| 480 |
+
1381,
|
| 481 |
+
5168,
|
| 482 |
+
7988,
|
| 483 |
+
9696,
|
| 484 |
+
7589,
|
| 485 |
+
6136,
|
| 486 |
+
6091,
|
| 487 |
+
1322,
|
| 488 |
+
4599,
|
| 489 |
+
9982,
|
| 490 |
+
6250,
|
| 491 |
+
9294,
|
| 492 |
+
8399,
|
| 493 |
+
1524,
|
| 494 |
+
1477,
|
| 495 |
+
7169,
|
| 496 |
+
9937,
|
| 497 |
+
6008,
|
| 498 |
+
5335,
|
| 499 |
+
3958,
|
| 500 |
+
5778,
|
| 501 |
+
9744,
|
| 502 |
+
4820,
|
| 503 |
+
9643,
|
| 504 |
+
1827,
|
| 505 |
+
8457,
|
| 506 |
+
908,
|
| 507 |
+
2079,
|
| 508 |
+
9153,
|
| 509 |
+
915,
|
| 510 |
+
2115,
|
| 511 |
+
8444,
|
| 512 |
+
1777,
|
| 513 |
+
6931
|
| 514 |
+
],
|
| 515 |
+
73
|
| 516 |
+
],
|
| 517 |
+
"output": 0
|
| 518 |
+
},
|
| 519 |
+
{
|
| 520 |
+
"input": [
|
| 521 |
+
[
|
| 522 |
+
4281,
|
| 523 |
+
4941,
|
| 524 |
+
845,
|
| 525 |
+
1334,
|
| 526 |
+
9341,
|
| 527 |
+
4068,
|
| 528 |
+
3889,
|
| 529 |
+
2916,
|
| 530 |
+
9263,
|
| 531 |
+
9240,
|
| 532 |
+
4489,
|
| 533 |
+
6320,
|
| 534 |
+
1636,
|
| 535 |
+
5773,
|
| 536 |
+
2914,
|
| 537 |
+
565,
|
| 538 |
+
2552,
|
| 539 |
+
4803,
|
| 540 |
+
7241,
|
| 541 |
+
6473,
|
| 542 |
+
3537,
|
| 543 |
+
9427,
|
| 544 |
+
9198,
|
| 545 |
+
1966,
|
| 546 |
+
2355,
|
| 547 |
+
9709
|
| 548 |
+
],
|
| 549 |
+
81
|
| 550 |
+
],
|
| 551 |
+
"output": 0
|
| 552 |
+
},
|
| 553 |
+
{
|
| 554 |
+
"input": [
|
| 555 |
+
[
|
| 556 |
+
6878,
|
| 557 |
+
1233,
|
| 558 |
+
342,
|
| 559 |
+
6963,
|
| 560 |
+
7148,
|
| 561 |
+
9696,
|
| 562 |
+
1965,
|
| 563 |
+
7467,
|
| 564 |
+
4654,
|
| 565 |
+
5121,
|
| 566 |
+
7970,
|
| 567 |
+
5308,
|
| 568 |
+
610,
|
| 569 |
+
9237,
|
| 570 |
+
3439,
|
| 571 |
+
1541,
|
| 572 |
+
565,
|
| 573 |
+
1071,
|
| 574 |
+
4188,
|
| 575 |
+
1985,
|
| 576 |
+
2705,
|
| 577 |
+
7752,
|
| 578 |
+
4142,
|
| 579 |
+
4450,
|
| 580 |
+
3942,
|
| 581 |
+
367,
|
| 582 |
+
7798,
|
| 583 |
+
5673,
|
| 584 |
+
8395,
|
| 585 |
+
2678,
|
| 586 |
+
3078,
|
| 587 |
+
8420,
|
| 588 |
+
7092,
|
| 589 |
+
9624,
|
| 590 |
+
5669,
|
| 591 |
+
1921,
|
| 592 |
+
5281,
|
| 593 |
+
1078,
|
| 594 |
+
3895,
|
| 595 |
+
3704,
|
| 596 |
+
3442,
|
| 597 |
+
6184,
|
| 598 |
+
5462,
|
| 599 |
+
6231,
|
| 600 |
+
2339,
|
| 601 |
+
9236,
|
| 602 |
+
5261,
|
| 603 |
+
3025,
|
| 604 |
+
1200,
|
| 605 |
+
4784,
|
| 606 |
+
2039,
|
| 607 |
+
5150,
|
| 608 |
+
9992,
|
| 609 |
+
4146,
|
| 610 |
+
4406,
|
| 611 |
+
3647,
|
| 612 |
+
9607,
|
| 613 |
+
2210,
|
| 614 |
+
9399,
|
| 615 |
+
6129
|
| 616 |
+
],
|
| 617 |
+
14
|
| 618 |
+
],
|
| 619 |
+
"output": 0
|
| 620 |
+
}
|
| 621 |
+
],
|
| 622 |
+
"haskell_template": "sumOfPower :: [Int] -> Int -> Int\nsumOfPower nums k ",
|
| 623 |
+
"ocaml_template": "let sumOfPower (nums: int list) (k: int) : int = ",
|
| 624 |
+
"scala_template": "def sumOfPower(nums: List[Int],k: Int): Int = { \n \n}",
|
| 625 |
+
"java_template": "class Solution {\n public int sumOfPower(int[] nums, int k) {\n \n }\n}",
|
| 626 |
+
"python_template": "class Solution(object):\n def sumOfPower(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n "
|
| 627 |
+
}
|
find_the_sum_of_the_power_of_all_subsequences/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 6 (sumOfPower [1;2;3] 3)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 4 (sumOfPower [2;3;3] 5)
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal 0 (sumOfPower [1;2;3] 7)
|
| 16 |
+
|
| 17 |
+
let test4 _ = assert_equal 0 (sumOfPower [7248; 5128; 7789; 1275; 5420; 6934; 5119; 5373; 9374; 1981; 2257; 664; 1166; 7308; 316; 3628; 9983; 7545; 4593; 2145; 4397; 8021; 6121; 4422; 1316; 8554; 5840; 4154; 7402; 2393; 3311; 7064; 3965; 3434; 7432; 6487; 3170; 5205; 6887; 4106; 7834; 8725; 2164; 402; 3684; 7600; 7056; 9661; 8828; 9157; 8356] 81)
|
| 18 |
+
|
| 19 |
+
let test5 _ = assert_equal 0 (sumOfPower [6119; 1657; 472; 6891; 4439; 7253; 3499; 1025; 929; 6840; 4565; 9160; 1880; 1216; 165; 178; 4294; 1726; 563; 5004; 2064; 3112; 8755; 1776; 9957; 2473; 6001; 4263; 7148; 1456; 9288; 9346; 6719; 7893; 383; 7149; 7434; 3692; 2846; 5073; 1587; 1456; 1746; 547] 84)
|
| 20 |
+
|
| 21 |
+
let test6 _ = assert_equal 0 (sumOfPower [7396; 2993; 3753; 6781; 971; 2840; 1164; 8638; 6345; 7335; 9550; 7845; 2957; 9716; 5873; 200; 3525; 3860; 9215; 6783; 6625; 4773; 6703; 2503; 8471; 4507; 5949; 9626; 3351; 3245; 1857; 1472; 5988; 4944; 1194; 966; 7063; 6214; 5657; 3165; 561; 61; 5158; 5025; 8276; 795; 3456; 605; 2032; 2941; 93; 6988; 4450; 3945; 866; 5645; 1682; 4701; 8187; 4539; 5306; 8092; 7599; 369; 9813; 4265; 869; 4237; 1950; 1246; 8593; 2617; 4560; 5679; 8530; 5891] 65)
|
| 22 |
+
|
| 23 |
+
let test7 _ = assert_equal 0 (sumOfPower [9510; 4506; 5096; 4394; 8662; 4919; 7641; 5551; 6851; 3376; 3180; 1858; 8385; 9252; 3855; 4965] 37)
|
| 24 |
+
|
| 25 |
+
let test8 _ = assert_equal 0 (sumOfPower [9115; 6306; 9419; 4571; 8435; 5564; 2759; 5505; 1517; 9677; 7124; 6774; 1954; 8484; 2642; 1450; 7851; 7570; 335; 4548; 3136; 5932; 8999; 5660; 7017; 406; 7162; 4047; 4817; 4576; 6803; 2406; 2847; 8910; 7312; 6670; 6095; 2712; 8576; 1098; 5038; 4376; 5135; 5210; 9776; 1229; 6138; 2592; 3689; 6229; 6227; 3555; 7955; 9069; 7196; 4426; 6969; 7830; 7892; 4345; 4001; 9754; 4661; 9376; 6509; 792; 9654; 8016; 7539; 1237; 2310; 8277; 1322; 4335; 5252; 3354; 9862; 6076; 4440; 4997; 9974; 8981; 5933; 8901; 4479; 1299; 7990; 6994; 7223; 1349; 9945; 8644; 6332; 2350; 6073; 9038; 1763; 6751; 9869] 42)
|
| 26 |
+
|
| 27 |
+
let test9 _ = assert_equal 0 (sumOfPower [2488; 7431; 4377; 6084; 2819; 7446; 7133; 5703; 8172; 9493; 5472; 2449; 372; 2481; 8492; 8694; 8110; 4954; 9731; 7990; 2063; 2804; 8105; 8167; 2685; 9883; 5971; 9019; 6984; 4723; 9368; 2628; 2283; 9252; 9318; 1667; 4881; 735; 2415; 1129; 4852; 10; 4739; 7295] 59)
|
| 28 |
+
|
| 29 |
+
let test10 _ = assert_equal 0 (sumOfPower [3112; 3633; 1372; 2057] 90)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
(* Grouping test cases *)
|
| 33 |
+
let suite = "Test Suite for sumOfPower" >::: [
|
| 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
|
find_the_sum_of_the_power_of_all_subsequences/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.sumOfPower(List(1,2,3),3), 6)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.sumOfPower(List(2,3,3),5), 4)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.sumOfPower(List(1,2,3),7), 0)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.sumOfPower(List(7248, 5128, 7789, 1275, 5420, 6934, 5119, 5373, 9374, 1981, 2257, 664, 1166, 7308, 316, 3628, 9983, 7545, 4593, 2145, 4397, 8021, 6121, 4422, 1316, 8554, 5840, 4154, 7402, 2393, 3311, 7064, 3965, 3434, 7432, 6487, 3170, 5205, 6887, 4106, 7834, 8725, 2164, 402, 3684, 7600, 7056, 9661, 8828, 9157, 8356),81), 0)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.sumOfPower(List(6119, 1657, 472, 6891, 4439, 7253, 3499, 1025, 929, 6840, 4565, 9160, 1880, 1216, 165, 178, 4294, 1726, 563, 5004, 2064, 3112, 8755, 1776, 9957, 2473, 6001, 4263, 7148, 1456, 9288, 9346, 6719, 7893, 383, 7149, 7434, 3692, 2846, 5073, 1587, 1456, 1746, 547),84), 0)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.sumOfPower(List(7396, 2993, 3753, 6781, 971, 2840, 1164, 8638, 6345, 7335, 9550, 7845, 2957, 9716, 5873, 200, 3525, 3860, 9215, 6783, 6625, 4773, 6703, 2503, 8471, 4507, 5949, 9626, 3351, 3245, 1857, 1472, 5988, 4944, 1194, 966, 7063, 6214, 5657, 3165, 561, 61, 5158, 5025, 8276, 795, 3456, 605, 2032, 2941, 93, 6988, 4450, 3945, 866, 5645, 1682, 4701, 8187, 4539, 5306, 8092, 7599, 369, 9813, 4265, 869, 4237, 1950, 1246, 8593, 2617, 4560, 5679, 8530, 5891),65), 0)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.sumOfPower(List(9510, 4506, 5096, 4394, 8662, 4919, 7641, 5551, 6851, 3376, 3180, 1858, 8385, 9252, 3855, 4965),37), 0)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("test8") {
|
| 33 |
+
assertEquals(Main.sumOfPower(List(9115, 6306, 9419, 4571, 8435, 5564, 2759, 5505, 1517, 9677, 7124, 6774, 1954, 8484, 2642, 1450, 7851, 7570, 335, 4548, 3136, 5932, 8999, 5660, 7017, 406, 7162, 4047, 4817, 4576, 6803, 2406, 2847, 8910, 7312, 6670, 6095, 2712, 8576, 1098, 5038, 4376, 5135, 5210, 9776, 1229, 6138, 2592, 3689, 6229, 6227, 3555, 7955, 9069, 7196, 4426, 6969, 7830, 7892, 4345, 4001, 9754, 4661, 9376, 6509, 792, 9654, 8016, 7539, 1237, 2310, 8277, 1322, 4335, 5252, 3354, 9862, 6076, 4440, 4997, 9974, 8981, 5933, 8901, 4479, 1299, 7990, 6994, 7223, 1349, 9945, 8644, 6332, 2350, 6073, 9038, 1763, 6751, 9869),42), 0)
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
test("test9") {
|
| 37 |
+
assertEquals(Main.sumOfPower(List(2488, 7431, 4377, 6084, 2819, 7446, 7133, 5703, 8172, 9493, 5472, 2449, 372, 2481, 8492, 8694, 8110, 4954, 9731, 7990, 2063, 2804, 8105, 8167, 2685, 9883, 5971, 9019, 6984, 4723, 9368, 2628, 2283, 9252, 9318, 1667, 4881, 735, 2415, 1129, 4852, 10, 4739, 7295),59), 0)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
test("test10") {
|
| 41 |
+
assertEquals(Main.sumOfPower(List(3112, 3633, 1372, 2057),90), 0)
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|