87988a2e0843c28eb891b6405463ff6582bf7d06d05ae8dce71469edfdee8a98
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +4 -0
- happy_students/ocaml_tests/main.ml +0 -0
- happy_students/scala_tests/MySuite.scala +0 -0
- hash_divided_string/haskell_tests/Main.hs +45 -0
- hash_divided_string/java_tests/Main.java +21 -0
- hash_divided_string/meta.json +97 -0
- hash_divided_string/ocaml_tests/main.ml +50 -0
- hash_divided_string/scala_tests/MySuite.scala +44 -0
- high_access_employees/java_tests/Main.java +24 -0
- house_robber_iv/.DS_Store +0 -0
- house_robber_iv/haskell_tests/Main.hs +24 -0
- house_robber_iv/java_tests/Main.java +21 -0
- house_robber_iv/meta.json +3 -0
- house_robber_iv/ocaml_tests/main.ml +26 -0
- house_robber_iv/scala_tests/MySuite.scala +12 -0
- increment_submatrices_by_one/haskell_tests/Main.hs +0 -0
- increment_submatrices_by_one/java_tests/Main.java +21 -0
- increment_submatrices_by_one/meta.json +3 -0
- increment_submatrices_by_one/ocaml_tests/main.ml +0 -0
- increment_submatrices_by_one/scala_tests/MySuite.scala +0 -0
- intersection_of_multiple_arrays/.DS_Store +0 -0
- intersection_of_multiple_arrays/haskell_tests/Main.hs +24 -0
- intersection_of_multiple_arrays/java_tests/Main.java +21 -0
- intersection_of_multiple_arrays/meta.json +0 -0
- intersection_of_multiple_arrays/ocaml_tests/main.ml +26 -0
- intersection_of_multiple_arrays/scala_tests/MySuite.scala +12 -0
- intervals_between_identical_elements/.DS_Store +0 -0
- intervals_between_identical_elements/haskell_tests/Main.hs +24 -0
- intervals_between_identical_elements/java_tests/Main.java +21 -0
- intervals_between_identical_elements/meta.json +3 -0
- intervals_between_identical_elements/ocaml_tests/main.ml +26 -0
- intervals_between_identical_elements/scala_tests/MySuite.scala +12 -0
- k_divisible_elements_subarrays/.DS_Store +0 -0
- k_divisible_elements_subarrays/haskell_tests/Main.hs +24 -0
- k_divisible_elements_subarrays/java_tests/Main.java +21 -0
- k_divisible_elements_subarrays/meta.json +910 -0
- k_divisible_elements_subarrays/ocaml_tests/main.ml +26 -0
- k_divisible_elements_subarrays/scala_tests/MySuite.scala +12 -0
- k_highest_ranked_items_within_a_price_range/.DS_Store +0 -0
- k_highest_ranked_items_within_a_price_range/haskell_tests/Main.hs +27 -0
- k_highest_ranked_items_within_a_price_range/java_tests/Main.java +25 -0
- k_highest_ranked_items_within_a_price_range/meta.json +917 -0
- k_highest_ranked_items_within_a_price_range/ocaml_tests/main.ml +29 -0
- k_highest_ranked_items_within_a_price_range/scala_tests/MySuite.scala +16 -0
- k_items_with_the_maximum_sum/.DS_Store +0 -0
- k_items_with_the_maximum_sum/haskell_tests/Main.hs +24 -0
- k_items_with_the_maximum_sum/java_tests/Main.java +21 -0
- k_items_with_the_maximum_sum/meta.json +117 -0
- k_items_with_the_maximum_sum/ocaml_tests/main.ml +26 -0
- k_items_with_the_maximum_sum/scala_tests/MySuite.scala +12 -0
.gitattributes
CHANGED
|
@@ -135,3 +135,7 @@ frog_jump_ii/meta.json filter=lfs diff=lfs merge=lfs -text
|
|
| 135 |
fruits_into_baskets_iii/haskell_tests/Main.hs filter=lfs diff=lfs merge=lfs -text
|
| 136 |
fruits_into_baskets_iii/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 137 |
handling_sum_queries_after_update/meta.json filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
fruits_into_baskets_iii/haskell_tests/Main.hs filter=lfs diff=lfs merge=lfs -text
|
| 136 |
fruits_into_baskets_iii/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 137 |
handling_sum_queries_after_update/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 138 |
+
house_robber_iv/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 139 |
+
increment_submatrices_by_one/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 140 |
+
intervals_between_identical_elements/meta.json filter=lfs diff=lfs merge=lfs -text
|
| 141 |
+
k_th_nearest_obstacle_queries/haskell_tests/Main.hs filter=lfs diff=lfs merge=lfs -text
|
happy_students/ocaml_tests/main.ml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
happy_students/scala_tests/MySuite.scala
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hash_divided_string/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 (stringHash \"abcd \" 2)," "bf" (stringHash "abcd" 2))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (stringHash \"mxz \" 3)," "i" (stringHash "mxz" 3))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (stringHash \"mknnewhsvixaeusxsfojlvplbqyjyefrjyyhtajuilrfkjghjnsvnqaydn \" 58)," "h" (stringHash "mknnewhsvixaeusxsfojlvplbqyjyefrjyyhtajuilrfkjghjnsvnqaydn" 58))
|
| 19 |
+
|
| 20 |
+
test4 :: Test
|
| 21 |
+
test4 = TestCase (assertEqual "for (stringHash \"hkbsjdlmmpstbixdukm \" 19)," "e" (stringHash "hkbsjdlmmpstbixdukm" 19))
|
| 22 |
+
|
| 23 |
+
test5 :: Test
|
| 24 |
+
test5 = TestCase (assertEqual "for (stringHash \"hrenpeulegbdevkqxkgunlvgjcgcnkyfveviopkctwxwhbbkolfhagijdtrdizpirypifljngxpnptiieyomhqjjktmgoenqopchwgogggndissmbydubfvnydiiishhouqhtpyrzrfprmincrzitkspkqzrmqyendodxzqfoshzusltfmlryehtrbkjmfedsamvuitkilacsmmhbkvngiaaggirnphjxtfegigchuagijfyinrqcnqolrrtstnikodwzxkqgqvcodvgeyiyprivurjsfggblcdhutatqxcaszyplcjyxhvxjdjnbnmolpkqjfcjntszgitnmhnrxjpkpqzibqreaalrcdjxdzhgkotxgcngwtqkpsuxpqesdljpxflnczyajozieygfecszaxnkwwawzdacpermpwcivdviveknyjvlzyyjkedipifsiksmhofosobpjbxmjtxfheetuzozcwybccmdkyphebjngzmesjhxvgfcllrjsicgogubevwoyqclpkinjgmowkmqbbbjgnlruztuvssvpzexnticbbqnfprshbtbcomjsiwnnjuvvv \" 59)," "mfghqouxbh" (stringHash "hrenpeulegbdevkqxkgunlvgjcgcnkyfveviopkctwxwhbbkolfhagijdtrdizpirypifljngxpnptiieyomhqjjktmgoenqopchwgogggndissmbydubfvnydiiishhouqhtpyrzrfprmincrzitkspkqzrmqyendodxzqfoshzusltfmlryehtrbkjmfedsamvuitkilacsmmhbkvngiaaggirnphjxtfegigchuagijfyinrqcnqolrrtstnikodwzxkqgqvcodvgeyiyprivurjsfggblcdhutatqxcaszyplcjyxhvxjdjnbnmolpkqjfcjntszgitnmhnrxjpkpqzibqreaalrcdjxdzhgkotxgcngwtqkpsuxpqesdljpxflnczyajozieygfecszaxnkwwawzdacpermpwcivdviveknyjvlzyyjkedipifsiksmhofosobpjbxmjtxfheetuzozcwybccmdkyphebjngzmesjhxvgfcllrjsicgogubevwoyqclpkinjgmowkmqbbbjgnlruztuvssvpzexnticbbqnfprshbtbcomjsiwnnjuvvv" 59))
|
| 25 |
+
|
| 26 |
+
test6 :: Test
|
| 27 |
+
test6 = TestCase (assertEqual "for (stringHash \"qsxlpirfwsthwxzadtjsrzwzkcdbamjlkvimwhimffqwjjgmgaeygpxjheaahqqmtgooaybcybycgfvlimxuksbqbtqkddgussimvqoagtuvrjysyxjifasioqcmtsynguoiblpvqqxudxjcdokpbdkvxsqjextaiyubizlcjrdrwfsvivnmxcknskwkznvekfaileikjclsqsfjhmfxcphvdedxjznytvlpuhwigpixxycbbamgelxwwfhkpjsgqewpixzmpftsbaewaujcowqaqaulumntwxjysxcgwpezewkvddbsrymkwwyhkuguawfljwuaqsldbwuxxfbmtbrgrsvqlpvtsyeascudehuenihqah \" 37)," "obknkshumu" (stringHash "qsxlpirfwsthwxzadtjsrzwzkcdbamjlkvimwhimffqwjjgmgaeygpxjheaahqqmtgooaybcybycgfvlimxuksbqbtqkddgussimvqoagtuvrjysyxjifasioqcmtsynguoiblpvqqxudxjcdokpbdkvxsqjextaiyubizlcjrdrwfsvivnmxcknskwkznvekfaileikjclsqsfjhmfxcphvdedxjznytvlpuhwigpixxycbbamgelxwwfhkpjsgqewpixzmpftsbaewaujcowqaqaulumntwxjysxcgwpezewkvddbsrymkwwyhkuguawfljwuaqsldbwuxxfbmtbrgrsvqlpvtsyeascudehuenihqah" 37))
|
| 28 |
+
|
| 29 |
+
test7 :: Test
|
| 30 |
+
test7 = TestCase (assertEqual "for (stringHash \"imdlgramytqqhnxvrssthdpmsymozgryvqfytyufmrhzctoqcntuyrsjswjeqy \" 31)," "rr" (stringHash "imdlgramytqqhnxvrssthdpmsymozgryvqfytyufmrhzctoqcntuyrsjswjeqy" 31))
|
| 31 |
+
|
| 32 |
+
test8 :: Test
|
| 33 |
+
test8 = TestCase (assertEqual "for (stringHash \"mrcfbffhqqxjcsicacqwxydlitlcacwbzvkbnpofpjztlptsigapmfowackpdvbscvbzvwcjeoewrtaxigvysjwxokurihlt \" 48)," "dx" (stringHash "mrcfbffhqqxjcsicacqwxydlitlcacwbzvkbnpofpjztlptsigapmfowackpdvbscvbzvwcjeoewrtaxigvysjwxokurihlt" 48))
|
| 34 |
+
|
| 35 |
+
test9 :: Test
|
| 36 |
+
test9 = TestCase (assertEqual "for (stringHash \"mtztdwkprxmyslkvbzbctmdvkbgeqqvjtlelfxweovjijdckkxvftardiknyrvavdpvxafjbptmxzqlymyjjvrphubfbczwfhqdpvrvzvhuchzvyykdzzpxzxoffxhgzrvljihabhdpallqikkgkafwmlqtwsikhmrmamwswpxiinlncjuwndgxguhzuckqaukbodcinwublsvpftqwmpgaptfpajzsejcrpjechadcfxjdxmleklprvbgwcfjoriznbwryevhbyfdtaswzeqyogsgustciuedccxazekzgmoxaxbextrcktiphwjbtfffhslzxfishinywflldkozkkamtjpcwkuhcdshfmoadlfoalpvyfktmytetiwsscckeqpppuewghuhgangabrkqkwgibulxtyegiinfpbysbatidnxiqmlduqybpsftzzduyjemfyohwruxxettnfsfdliadoehlqwwhmvkcidpxkjxhhggtnctaczmilwsbaanyzhoktyhbqkpv \" 66)," "bffewqcx" (stringHash "mtztdwkprxmyslkvbzbctmdvkbgeqqvjtlelfxweovjijdckkxvftardiknyrvavdpvxafjbptmxzqlymyjjvrphubfbczwfhqdpvrvzvhuchzvyykdzzpxzxoffxhgzrvljihabhdpallqikkgkafwmlqtwsikhmrmamwswpxiinlncjuwndgxguhzuckqaukbodcinwublsvpftqwmpgaptfpajzsejcrpjechadcfxjdxmleklprvbgwcfjoriznbwryevhbyfdtaswzeqyogsgustciuedccxazekzgmoxaxbextrcktiphwjbtfffhslzxfishinywflldkozkkamtjpcwkuhcdshfmoadlfoalpvyfktmytetiwsscckeqpppuewghuhgangabrkqkwgibulxtyegiinfpbysbatidnxiqmlduqybpsftzzduyjemfyohwruxxettnfsfdliadoehlqwwhmvkcidpxkjxhhggtnctaczmilwsbaanyzhoktyhbqkpv" 66))
|
| 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
|
hash_divided_string/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", stringHash("abcd", 2));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals("3", stringHash("mxz", 3));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
hash_divided_string/meta.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3540,
|
| 3 |
+
"name": "hash_divided_string",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/hash-divided-string/",
|
| 6 |
+
"date": "2024-08-17 00:00:00",
|
| 7 |
+
"task_description": "You are given a string `s` of length `n` and an integer `k`, where `n` is a **multiple** of `k`. Your task is to hash the string `s` into a new string called `result`, which has a length of `n / k`. First, divide `s` into `n / k` **substrings**, each with a length of `k`. Then, initialize `result` as an **empty** string. For each **substring** in order from the beginning: The **hash value** of a character is the index of that character in the **English alphabet** (e.g., `'a' → 0`, `'b' → 1`, ..., `'z' → 25`). Calculate the _sum_ of all the **hash values** of the characters in the substring. Find the remainder of this sum when divided by 26, which is called `hashedChar`. Identify the character in the English lowercase alphabet that corresponds to `hashedChar`. Append that character to the end of `result`. Return `result`. **Example 1:** **Input:** s = \"abcd\", k = 2 **Output:** \"bf\" **Explanation:** First substring: `\"ab\"`, `0 + 1 = 1`, `1 % 26 = 1`, `result[0] = 'b'`. Second substring: `\"cd\"`, `2 + 3 = 5`, `5 % 26 = 5`, `result[1] = 'f'`. **Example 2:** **Input:** s = \"mxz\", k = 3 **Output:** \"i\" **Explanation:** The only substring: `\"mxz\"`, `12 + 23 + 25 = 60`, `60 % 26 = 8`, `result[0] = 'i'`. **Constraints:** `1 <= k <= 100` `k <= s.length <= 1000` `s.length` is divisible by `k`. `s` consists only of lowercase English letters.",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"abcd\", k = 2",
|
| 12 |
+
"output": "\"bf\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"mxz\", k = 3",
|
| 17 |
+
"output": "\"i\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
"\"mknnewhsvixaeusxsfojlvplbqyjyefrjyyhtajuilrfkjghjnsvnqaydn\"",
|
| 24 |
+
58
|
| 25 |
+
],
|
| 26 |
+
"output": "h"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"input": [
|
| 30 |
+
"\"hkbsjdlmmpstbixdukm\"",
|
| 31 |
+
19
|
| 32 |
+
],
|
| 33 |
+
"output": "e"
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"input": [
|
| 37 |
+
"\"hrenpeulegbdevkqxkgunlvgjcgcnkyfveviopkctwxwhbbkolfhagijdtrdizpirypifljngxpnptiieyomhqjjktmgoenqopchwgogggndissmbydubfvnydiiishhouqhtpyrzrfprmincrzitkspkqzrmqyendodxzqfoshzusltfmlryehtrbkjmfedsamvuitkilacsmmhbkvngiaaggirnphjxtfegigchuagijfyinrqcnqolrrtstnikodwzxkqgqvcodvgeyiyprivurjsfggblcdhutatqxcaszyplcjyxhvxjdjnbnmolpkqjfcjntszgitnmhnrxjpkpqzibqreaalrcdjxdzhgkotxgcngwtqkpsuxpqesdljpxflnczyajozieygfecszaxnkwwawzdacpermpwcivdviveknyjvlzyyjkedipifsiksmhofosobpjbxmjtxfheetuzozcwybccmdkyphebjngzmesjhxvgfcllrjsicgogubevwoyqclpkinjgmowkmqbbbjgnlruztuvssvpzexnticbbqnfprshbtbcomjsiwnnjuvvv\"",
|
| 38 |
+
59
|
| 39 |
+
],
|
| 40 |
+
"output": "mfghqouxbh"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"input": [
|
| 44 |
+
"\"qsxlpirfwsthwxzadtjsrzwzkcdbamjlkvimwhimffqwjjgmgaeygpxjheaahqqmtgooaybcybycgfvlimxuksbqbtqkddgussimvqoagtuvrjysyxjifasioqcmtsynguoiblpvqqxudxjcdokpbdkvxsqjextaiyubizlcjrdrwfsvivnmxcknskwkznvekfaileikjclsqsfjhmfxcphvdedxjznytvlpuhwigpixxycbbamgelxwwfhkpjsgqewpixzmpftsbaewaujcowqaqaulumntwxjysxcgwpezewkvddbsrymkwwyhkuguawfljwuaqsldbwuxxfbmtbrgrsvqlpvtsyeascudehuenihqah\"",
|
| 45 |
+
37
|
| 46 |
+
],
|
| 47 |
+
"output": "obknkshumu"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"input": [
|
| 51 |
+
"\"imdlgramytqqhnxvrssthdpmsymozgryvqfytyufmrhzctoqcntuyrsjswjeqy\"",
|
| 52 |
+
31
|
| 53 |
+
],
|
| 54 |
+
"output": "rr"
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"input": [
|
| 58 |
+
"\"mrcfbffhqqxjcsicacqwxydlitlcacwbzvkbnpofpjztlptsigapmfowackpdvbscvbzvwcjeoewrtaxigvysjwxokurihlt\"",
|
| 59 |
+
48
|
| 60 |
+
],
|
| 61 |
+
"output": "dx"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"input": [
|
| 65 |
+
"\"mtztdwkprxmyslkvbzbctmdvkbgeqqvjtlelfxweovjijdckkxvftardiknyrvavdpvxafjbptmxzqlymyjjvrphubfbczwfhqdpvrvzvhuchzvyykdzzpxzxoffxhgzrvljihabhdpallqikkgkafwmlqtwsikhmrmamwswpxiinlncjuwndgxguhzuckqaukbodcinwublsvpftqwmpgaptfpajzsejcrpjechadcfxjdxmleklprvbgwcfjoriznbwryevhbyfdtaswzeqyogsgustciuedccxazekzgmoxaxbextrcktiphwjbtfffhslzxfishinywflldkozkkamtjpcwkuhcdshfmoadlfoalpvyfktmytetiwsscckeqpppuewghuhgangabrkqkwgibulxtyegiinfpbysbatidnxiqmlduqybpsftzzduyjemfyohwruxxettnfsfdliadoehlqwwhmvkcidpxkjxhhggtnctaczmilwsbaanyzhoktyhbqkpv\"",
|
| 66 |
+
66
|
| 67 |
+
],
|
| 68 |
+
"output": "bffewqcx"
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"input": [
|
| 72 |
+
"\"tveaugfeecjmlzdskgaz\"",
|
| 73 |
+
5
|
| 74 |
+
],
|
| 75 |
+
"output": "mvih"
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"input": [
|
| 79 |
+
"fwwlcqeiznjbsellbqoyydgqvghkxfpqwhbrceaapetqfjff",
|
| 80 |
+
24
|
| 81 |
+
],
|
| 82 |
+
"output": "aa"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"input": [
|
| 86 |
+
"lzrjjwaxglcicsujxldilsqdcazfiknweaavbyfpikbkvduavjxdpsnuuitabguyqhevqjjbqjhkbjhhndqwtflawguetmibvirgxomrkeoqufgbwwyzofxpphyumynhzvpqtnfuzsgbczcqoxasdrljnhytwgvjdzxdxqongohlqyztxuqaobhwdokrfkrjaktoeuovnpnyftjttydihvueifjhdmznimbqbvhsqjgqdxkpoogqanfakqlfxjuvsqxavytbbtvfhotridmdcxgbfniaqsdmbxsobicwmkamwljpaqpfjsglrwozobzwbavbpdliaqkbblqonvkglpkqhdbrgf",
|
| 87 |
+
70
|
| 88 |
+
],
|
| 89 |
+
"output": "axrnr"
|
| 90 |
+
}
|
| 91 |
+
],
|
| 92 |
+
"haskell_template": "stringHash :: String -> Int -> String\nstringHash s k ",
|
| 93 |
+
"ocaml_template": "let stringHash (s: string) (k: int) : string = ",
|
| 94 |
+
"scala_template": "def stringHash(s: String,k: Int): String = { \n \n}",
|
| 95 |
+
"java_template": "class Solution {\n public String stringHash(String s, int k) {\n \n }\n}",
|
| 96 |
+
"python_template": "class Solution(object):\n def stringHash(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"\n "
|
| 97 |
+
}
|
hash_divided_string/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 "bf" (stringHash "abcd" 2)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal "i" (stringHash "mxz" 3)
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal "h" (stringHash "mknnewhsvixaeusxsfojlvplbqyjyefrjyyhtajuilrfkjghjnsvnqaydn" 58)
|
| 16 |
+
|
| 17 |
+
let test4 _ = assert_equal "e" (stringHash "hkbsjdlmmpstbixdukm" 19)
|
| 18 |
+
|
| 19 |
+
let test5 _ = assert_equal "mfghqouxbh" (stringHash "hrenpeulegbdevkqxkgunlvgjcgcnkyfveviopkctwxwhbbkolfhagijdtrdizpirypifljngxpnptiieyomhqjjktmgoenqopchwgogggndissmbydubfvnydiiishhouqhtpyrzrfprmincrzitkspkqzrmqyendodxzqfoshzusltfmlryehtrbkjmfedsamvuitkilacsmmhbkvngiaaggirnphjxtfegigchuagijfyinrqcnqolrrtstnikodwzxkqgqvcodvgeyiyprivurjsfggblcdhutatqxcaszyplcjyxhvxjdjnbnmolpkqjfcjntszgitnmhnrxjpkpqzibqreaalrcdjxdzhgkotxgcngwtqkpsuxpqesdljpxflnczyajozieygfecszaxnkwwawzdacpermpwcivdviveknyjvlzyyjkedipifsiksmhofosobpjbxmjtxfheetuzozcwybccmdkyphebjngzmesjhxvgfcllrjsicgogubevwoyqclpkinjgmowkmqbbbjgnlruztuvssvpzexnticbbqnfprshbtbcomjsiwnnjuvvv" 59)
|
| 20 |
+
|
| 21 |
+
let test6 _ = assert_equal "obknkshumu" (stringHash "qsxlpirfwsthwxzadtjsrzwzkcdbamjlkvimwhimffqwjjgmgaeygpxjheaahqqmtgooaybcybycgfvlimxuksbqbtqkddgussimvqoagtuvrjysyxjifasioqcmtsynguoiblpvqqxudxjcdokpbdkvxsqjextaiyubizlcjrdrwfsvivnmxcknskwkznvekfaileikjclsqsfjhmfxcphvdedxjznytvlpuhwigpixxycbbamgelxwwfhkpjsgqewpixzmpftsbaewaujcowqaqaulumntwxjysxcgwpezewkvddbsrymkwwyhkuguawfljwuaqsldbwuxxfbmtbrgrsvqlpvtsyeascudehuenihqah" 37)
|
| 22 |
+
|
| 23 |
+
let test7 _ = assert_equal "rr" (stringHash "imdlgramytqqhnxvrssthdpmsymozgryvqfytyufmrhzctoqcntuyrsjswjeqy" 31)
|
| 24 |
+
|
| 25 |
+
let test8 _ = assert_equal "dx" (stringHash "mrcfbffhqqxjcsicacqwxydlitlcacwbzvkbnpofpjztlptsigapmfowackpdvbscvbzvwcjeoewrtaxigvysjwxokurihlt" 48)
|
| 26 |
+
|
| 27 |
+
let test9 _ = assert_equal "bffewqcx" (stringHash "mtztdwkprxmyslkvbzbctmdvkbgeqqvjtlelfxweovjijdckkxvftardiknyrvavdpvxafjbptmxzqlymyjjvrphubfbczwfhqdpvrvzvhuchzvyykdzzpxzxoffxhgzrvljihabhdpallqikkgkafwmlqtwsikhmrmamwswpxiinlncjuwndgxguhzuckqaukbodcinwublsvpftqwmpgaptfpajzsejcrpjechadcfxjdxmleklprvbgwcfjoriznbwryevhbyfdtaswzeqyogsgustciuedccxazekzgmoxaxbextrcktiphwjbtfffhslzxfishinywflldkozkkamtjpcwkuhcdshfmoadlfoalpvyfktmytetiwsscckeqpppuewghuhgangabrkqkwgibulxtyegiinfpbysbatidnxiqmlduqybpsftzzduyjemfyohwruxxettnfsfdliadoehlqwwhmvkcidpxkjxhhggtnctaczmilwsbaanyzhoktyhbqkpv" 66)
|
| 28 |
+
|
| 29 |
+
let test10 _ = assert_equal "mvih" (stringHash "tveaugfeecjmlzdskgaz" 5)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
(* Grouping test cases *)
|
| 33 |
+
let suite = "Test Suite for stringHash" >::: [
|
| 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
|
hash_divided_string/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.stringHash("abcd",2), "bf")
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.stringHash("mxz",3), "i")
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.stringHash("mknnewhsvixaeusxsfojlvplbqyjyefrjyyhtajuilrfkjghjnsvnqaydn",58), "h")
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.stringHash("hkbsjdlmmpstbixdukm",19), "e")
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.stringHash("hrenpeulegbdevkqxkgunlvgjcgcnkyfveviopkctwxwhbbkolfhagijdtrdizpirypifljngxpnptiieyomhqjjktmgoenqopchwgogggndissmbydubfvnydiiishhouqhtpyrzrfprmincrzitkspkqzrmqyendodxzqfoshzusltfmlryehtrbkjmfedsamvuitkilacsmmhbkvngiaaggirnphjxtfegigchuagijfyinrqcnqolrrtstnikodwzxkqgqvcodvgeyiyprivurjsfggblcdhutatqxcaszyplcjyxhvxjdjnbnmolpkqjfcjntszgitnmhnrxjpkpqzibqreaalrcdjxdzhgkotxgcngwtqkpsuxpqesdljpxflnczyajozieygfecszaxnkwwawzdacpermpwcivdviveknyjvlzyyjkedipifsiksmhofosobpjbxmjtxfheetuzozcwybccmdkyphebjngzmesjhxvgfcllrjsicgogubevwoyqclpkinjgmowkmqbbbjgnlruztuvssvpzexnticbbqnfprshbtbcomjsiwnnjuvvv",59), "mfghqouxbh")
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.stringHash("qsxlpirfwsthwxzadtjsrzwzkcdbamjlkvimwhimffqwjjgmgaeygpxjheaahqqmtgooaybcybycgfvlimxuksbqbtqkddgussimvqoagtuvrjysyxjifasioqcmtsynguoiblpvqqxudxjcdokpbdkvxsqjextaiyubizlcjrdrwfsvivnmxcknskwkznvekfaileikjclsqsfjhmfxcphvdedxjznytvlpuhwigpixxycbbamgelxwwfhkpjsgqewpixzmpftsbaewaujcowqaqaulumntwxjysxcgwpezewkvddbsrymkwwyhkuguawfljwuaqsldbwuxxfbmtbrgrsvqlpvtsyeascudehuenihqah",37), "obknkshumu")
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.stringHash("imdlgramytqqhnxvrssthdpmsymozgryvqfytyufmrhzctoqcntuyrsjswjeqy",31), "rr")
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("test8") {
|
| 33 |
+
assertEquals(Main.stringHash("mrcfbffhqqxjcsicacqwxydlitlcacwbzvkbnpofpjztlptsigapmfowackpdvbscvbzvwcjeoewrtaxigvysjwxokurihlt",48), "dx")
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
test("test9") {
|
| 37 |
+
assertEquals(Main.stringHash("mtztdwkprxmyslkvbzbctmdvkbgeqqvjtlelfxweovjijdckkxvftardiknyrvavdpvxafjbptmxzqlymyjjvrphubfbczwfhqdpvrvzvhuchzvyykdzzpxzxoffxhgzrvljihabhdpallqikkgkafwmlqtwsikhmrmamwswpxiinlncjuwndgxguhzuckqaukbodcinwublsvpftqwmpgaptfpajzsejcrpjechadcfxjdxmleklprvbgwcfjoriznbwryevhbyfdtaswzeqyogsgustciuedccxazekzgmoxaxbextrcktiphwjbtfffhslzxfishinywflldkozkkamtjpcwkuhcdshfmoadlfoalpvyfktmytetiwsscckeqpppuewghuhgangabrkqkwgibulxtyegiinfpbysbatidnxiqmlduqybpsftzzduyjemfyohwruxxettnfsfdliadoehlqwwhmvkcidpxkjxhhggtnctaczmilwsbaanyzhoktyhbqkpv",66), "bffewqcx")
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
test("test10") {
|
| 41 |
+
assertEquals(Main.stringHash("tveaugfeecjmlzdskgaz",5), "mvih")
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
high_access_employees/java_tests/Main.java
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(Arrays.asList("a"), findHighAccessEmployees(Arrays.asList(Arrays.asList("a","0549"),Arrays.asList("b","0457"),Arrays.asList("a","0532"),Arrays.asList("a","0621"),Arrays.asList("b","0540"))));
|
| 14 |
+
}
|
| 15 |
+
@Test
|
| 16 |
+
public void test2() {
|
| 17 |
+
assertEquals(Arrays.asList("c","d"), findHighAccessEmployees(Arrays.asList(Arrays.asList("d","0002"),Arrays.asList("c","0808"),Arrays.asList("c","0829"),Arrays.asList("e","0215"),Arrays.asList("d","1508"),Arrays.asList("d","1444"),Arrays.asList("d","1410"),Arrays.asList("c","0809"))));
|
| 18 |
+
}
|
| 19 |
+
@Test
|
| 20 |
+
public void test3() {
|
| 21 |
+
assertEquals(Arrays.asList("ab","cd"), findHighAccessEmployees(Arrays.asList(Arrays.asList("cd","1025"),Arrays.asList("ab","1025"),Arrays.asList("cd","1046"),Arrays.asList("cd","1055"),Arrays.asList("ab","1124"),Arrays.asList("ab","1120"))));
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
}
|
house_robber_iv/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
house_robber_iv/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 (minCapability [2,3,5,9] 2)," 5 (minCapability [2,3,5,9] 2))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (minCapability [2,7,9,3,1] 2)," 2 (minCapability [2,7,9,3,1] 2))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
-- Grouping test cases
|
| 19 |
+
tests :: Test
|
| 20 |
+
tests = TestList [TestLabel "Test1" test1]
|
| 21 |
+
|
| 22 |
+
-- Running the tests
|
| 23 |
+
main :: IO Counts
|
| 24 |
+
main = runTestTT tests
|
house_robber_iv/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, minCapability(new ArrayList<>(Arrays.asList(2,3,5,9)), 2));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(2, minCapability(new ArrayList<>(Arrays.asList(2,7,9,3,1)), 2));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
house_robber_iv/meta.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6fc68e2ff183c826e051b6883d1550a2ad0505dff2f83bbe8a7853204abc7673
|
| 3 |
+
size 13716479
|
house_robber_iv/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 (minCapability [2;3;5;9] 2)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 2 (minCapability [2;7;9;3;1] 2)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for minCapability" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
house_robber_iv/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.minCapability(List(2,3,5,9),2), 5)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.minCapability(List(2,7,9,3,1),2), 2)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
increment_submatrices_by_one/haskell_tests/Main.hs
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
increment_submatrices_by_one/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(new ArrayList<>(Arrays.asList(1,1,0)),new ArrayList<>(Arrays.asList(1,2,1)),new ArrayList<>(Arrays.asList(0,1,1)))), rangeAddQueries(3, new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1,1,2,2)),new ArrayList<>(Arrays.asList(0,0,1,1))))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1,1)),new ArrayList<>(Arrays.asList(1,1)))), rangeAddQueries(2, new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(0,0,1,1))))));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
increment_submatrices_by_one/meta.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b85e45813d330a390b54d2fcc6327417a3b5251d03619d5b685ad9db2ceb4cc5
|
| 3 |
+
size 19016814
|
increment_submatrices_by_one/ocaml_tests/main.ml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
increment_submatrices_by_one/scala_tests/MySuite.scala
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
intersection_of_multiple_arrays/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
intersection_of_multiple_arrays/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 (intersection [[ 3 ,1,2, 4 ,5],[1,2, 3 , 4 ],[ 3 , 4 ,5,6]])," [3,4] (intersection [[ 3 ,1,2, 4 ,5],[1,2, 3 , 4 ],[ 3 , 4 ,5,6]]))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (intersection [[1,2,3],[4,5,6]])," [] (intersection [[1,2,3],[4,5,6]]))
|
| 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
|
intersection_of_multiple_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(3,4)), intersection(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList( 3 ,1,2, 4 ,5)),new ArrayList<>(Arrays.asList(1,2, 3 , 4 )),new ArrayList<>(Arrays.asList( 3 , 4 ,5,6))))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(), intersection(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1,2,3)),new ArrayList<>(Arrays.asList(4,5,6))))));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
intersection_of_multiple_arrays/meta.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
intersection_of_multiple_arrays/ocaml_tests/main.ml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main = struct
|
| 3 |
+
open OUnit2
|
| 4 |
+
|
| 5 |
+
(* Program start *)
|
| 6 |
+
|
| 7 |
+
(* Program end *)
|
| 8 |
+
|
| 9 |
+
(* Test cases *)
|
| 10 |
+
|
| 11 |
+
let test1 _ = assert_equal [3;4] (intersection [[ 3 ;1;2; 4 ;5];[1;2; 3 ; 4 ];[ 3 ; 4 ;5;6]])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal [] (intersection [[1;2;3];[4;5;6]])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for intersection" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
intersection_of_multiple_arrays/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.intersection(List(List( 3 ,1,2, 4 ,5),List(1,2, 3 , 4 ),List( 3 , 4 ,5,6))), List(3,4))
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.intersection(List(List(1,2,3),List(4,5,6))), List())
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
intervals_between_identical_elements/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
intervals_between_identical_elements/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 (getDistances [2,1,3,1,2,3,3])," [4,2,7,2,4,4,5] (getDistances [2,1,3,1,2,3,3]))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (getDistances [10,5,10,10])," [5,0,3,4] (getDistances [10,5,10,10]))
|
| 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
|
intervals_between_identical_elements/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,2,7,2,4,4,5)), getDistances(new ArrayList<>(Arrays.asList(2,1,3,1,2,3,3))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(Arrays.asList(5,0,3,4)), getDistances(new ArrayList<>(Arrays.asList(10,5,10,10))));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
intervals_between_identical_elements/meta.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:58efaa8b21d21171111ffa49fe0c54a24dc2adc9719fe70e961302b9570280eb
|
| 3 |
+
size 19912292
|
intervals_between_identical_elements/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;2;7;2;4;4;5] (getDistances [2;1;3;1;2;3;3])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal [5;0;3;4] (getDistances [10;5;10;10])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for getDistances" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
intervals_between_identical_elements/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.getDistances(List(2,1,3,1,2,3,3)), List(4,2,7,2,4,4,5))
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.getDistances(List(10,5,10,10)), List(5,0,3,4))
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
k_divisible_elements_subarrays/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
k_divisible_elements_subarrays/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 (countDistinct [ 2 ,3,3, 2 , 2 ] 2 2)," 11 (countDistinct [ 2 ,3,3, 2 , 2 ] 2 2))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (countDistinct [1,2,3,4] 4 1)," 10 (countDistinct [1,2,3,4] 4 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
|
k_divisible_elements_subarrays/java_tests/Main.java
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import static org.junit.jupiter.api.Assertions.*;
|
| 3 |
+
import org.junit.jupiter.api.Test;
|
| 4 |
+
import java.util.List;
|
| 5 |
+
import java.util.Arrays;
|
| 6 |
+
import java.util.ArrayList;
|
| 7 |
+
public class Main {
|
| 8 |
+
//Program start
|
| 9 |
+
|
| 10 |
+
//Program end
|
| 11 |
+
|
| 12 |
+
@Test
|
| 13 |
+
public void test1() {
|
| 14 |
+
assertEquals(11, countDistinct(new ArrayList<>(Arrays.asList( 2 ,3,3, 2 , 2 )), 2, 2));
|
| 15 |
+
}
|
| 16 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2339,
|
| 3 |
+
"name": "k_divisible_elements_subarrays",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/k-divisible-elements-subarrays/",
|
| 6 |
+
"date": "1650758400000",
|
| 7 |
+
"task_description": "Given an integer array `nums` and two integers `k` and `p`, return _the number of **distinct subarrays,** which have **at most**_ `k` _elements _that are _divisible by_ `p`. Two arrays `nums1` and `nums2` are said to be **distinct** if: They are of **different** lengths, or There exists **at least** one index `i` where `nums1[i] != nums2[i]`. A **subarray** is defined as a **non-empty** contiguous sequence of elements in an array. **Example 1:** ``` **Input:** nums = [**2**,3,3,**2**,**2**], k = 2, p = 2 **Output:** 11 **Explanation:** The elements at indices 0, 3, and 4 are divisible by p = 2. The 11 distinct subarrays which have at most k = 2 elements divisible by 2 are: [2], [2,3], [2,3,3], [2,3,3,2], [3], [3,3], [3,3,2], [3,3,2,2], [3,2], [3,2,2], and [2,2]. Note that the subarrays [2] and [3] occur more than once in nums, but they should each be counted only once. The subarray [2,3,3,2,2] should not be counted because it has 3 elements that are divisible by 2. ``` **Example 2:** ``` **Input:** nums = [1,2,3,4], k = 4, p = 1 **Output:** 10 **Explanation:** All element of nums are divisible by p = 1. Also, every subarray of nums will have at most 4 elements that are divisible by 1. Since all subarrays are distinct, the total number of subarrays satisfying all the constraints is 10. ``` **Constraints:** `1 <= nums.length <= 200` `1 <= nums[i], p <= 200` `1 <= k <= nums.length` **Follow up:** Can you solve this problem in O(n2) time complexity?",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [ 2 ,3,3, 2 , 2 ], k = 2, p = 2",
|
| 12 |
+
"output": "11 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1,2,3,4], k = 4, p = 1",
|
| 17 |
+
"output": "10 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
[
|
| 24 |
+
167,
|
| 25 |
+
70,
|
| 26 |
+
128,
|
| 27 |
+
58,
|
| 28 |
+
184,
|
| 29 |
+
186,
|
| 30 |
+
14,
|
| 31 |
+
71,
|
| 32 |
+
26,
|
| 33 |
+
45,
|
| 34 |
+
24,
|
| 35 |
+
25,
|
| 36 |
+
41,
|
| 37 |
+
2,
|
| 38 |
+
198,
|
| 39 |
+
54,
|
| 40 |
+
92,
|
| 41 |
+
95,
|
| 42 |
+
151,
|
| 43 |
+
55,
|
| 44 |
+
166,
|
| 45 |
+
194,
|
| 46 |
+
140,
|
| 47 |
+
24,
|
| 48 |
+
91,
|
| 49 |
+
158,
|
| 50 |
+
57,
|
| 51 |
+
8,
|
| 52 |
+
49,
|
| 53 |
+
28,
|
| 54 |
+
55,
|
| 55 |
+
131,
|
| 56 |
+
31,
|
| 57 |
+
164,
|
| 58 |
+
110,
|
| 59 |
+
142,
|
| 60 |
+
146,
|
| 61 |
+
91,
|
| 62 |
+
149,
|
| 63 |
+
162,
|
| 64 |
+
185,
|
| 65 |
+
172,
|
| 66 |
+
36,
|
| 67 |
+
178,
|
| 68 |
+
133,
|
| 69 |
+
176
|
| 70 |
+
],
|
| 71 |
+
14,
|
| 72 |
+
152
|
| 73 |
+
],
|
| 74 |
+
"output": 1078
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"input": [
|
| 78 |
+
[
|
| 79 |
+
64,
|
| 80 |
+
116,
|
| 81 |
+
128,
|
| 82 |
+
67,
|
| 83 |
+
47,
|
| 84 |
+
163,
|
| 85 |
+
153,
|
| 86 |
+
64,
|
| 87 |
+
148,
|
| 88 |
+
10,
|
| 89 |
+
73,
|
| 90 |
+
146,
|
| 91 |
+
33,
|
| 92 |
+
191,
|
| 93 |
+
61,
|
| 94 |
+
145,
|
| 95 |
+
154,
|
| 96 |
+
78,
|
| 97 |
+
14,
|
| 98 |
+
85,
|
| 99 |
+
1,
|
| 100 |
+
165,
|
| 101 |
+
171,
|
| 102 |
+
91,
|
| 103 |
+
36,
|
| 104 |
+
101,
|
| 105 |
+
5,
|
| 106 |
+
118,
|
| 107 |
+
40,
|
| 108 |
+
61,
|
| 109 |
+
180,
|
| 110 |
+
18,
|
| 111 |
+
198,
|
| 112 |
+
187,
|
| 113 |
+
164,
|
| 114 |
+
67,
|
| 115 |
+
43,
|
| 116 |
+
41,
|
| 117 |
+
180,
|
| 118 |
+
43,
|
| 119 |
+
150,
|
| 120 |
+
181,
|
| 121 |
+
8,
|
| 122 |
+
21,
|
| 123 |
+
191,
|
| 124 |
+
104,
|
| 125 |
+
20,
|
| 126 |
+
83,
|
| 127 |
+
78,
|
| 128 |
+
33,
|
| 129 |
+
15,
|
| 130 |
+
115,
|
| 131 |
+
159,
|
| 132 |
+
142,
|
| 133 |
+
92,
|
| 134 |
+
10,
|
| 135 |
+
135,
|
| 136 |
+
47,
|
| 137 |
+
68,
|
| 138 |
+
116,
|
| 139 |
+
46,
|
| 140 |
+
30,
|
| 141 |
+
80,
|
| 142 |
+
125,
|
| 143 |
+
65,
|
| 144 |
+
119,
|
| 145 |
+
85,
|
| 146 |
+
193,
|
| 147 |
+
194,
|
| 148 |
+
114,
|
| 149 |
+
137,
|
| 150 |
+
106,
|
| 151 |
+
74,
|
| 152 |
+
93,
|
| 153 |
+
24,
|
| 154 |
+
20,
|
| 155 |
+
145,
|
| 156 |
+
50,
|
| 157 |
+
142,
|
| 158 |
+
13,
|
| 159 |
+
107,
|
| 160 |
+
99,
|
| 161 |
+
168,
|
| 162 |
+
15,
|
| 163 |
+
152,
|
| 164 |
+
140,
|
| 165 |
+
155,
|
| 166 |
+
16,
|
| 167 |
+
92,
|
| 168 |
+
114,
|
| 169 |
+
155,
|
| 170 |
+
54,
|
| 171 |
+
141,
|
| 172 |
+
161,
|
| 173 |
+
118,
|
| 174 |
+
193,
|
| 175 |
+
105,
|
| 176 |
+
189,
|
| 177 |
+
172,
|
| 178 |
+
168,
|
| 179 |
+
188,
|
| 180 |
+
84,
|
| 181 |
+
57,
|
| 182 |
+
27,
|
| 183 |
+
68,
|
| 184 |
+
106,
|
| 185 |
+
177,
|
| 186 |
+
9,
|
| 187 |
+
134,
|
| 188 |
+
122,
|
| 189 |
+
32,
|
| 190 |
+
114,
|
| 191 |
+
25,
|
| 192 |
+
173,
|
| 193 |
+
1,
|
| 194 |
+
48,
|
| 195 |
+
13,
|
| 196 |
+
9,
|
| 197 |
+
88,
|
| 198 |
+
191,
|
| 199 |
+
171,
|
| 200 |
+
56,
|
| 201 |
+
87,
|
| 202 |
+
195,
|
| 203 |
+
165,
|
| 204 |
+
55,
|
| 205 |
+
104,
|
| 206 |
+
179,
|
| 207 |
+
148,
|
| 208 |
+
37,
|
| 209 |
+
9,
|
| 210 |
+
150,
|
| 211 |
+
173,
|
| 212 |
+
184,
|
| 213 |
+
178,
|
| 214 |
+
88,
|
| 215 |
+
173,
|
| 216 |
+
59,
|
| 217 |
+
81,
|
| 218 |
+
108,
|
| 219 |
+
195,
|
| 220 |
+
95,
|
| 221 |
+
175,
|
| 222 |
+
105,
|
| 223 |
+
63,
|
| 224 |
+
199,
|
| 225 |
+
179,
|
| 226 |
+
55,
|
| 227 |
+
101,
|
| 228 |
+
184,
|
| 229 |
+
172,
|
| 230 |
+
75,
|
| 231 |
+
148,
|
| 232 |
+
13,
|
| 233 |
+
23,
|
| 234 |
+
50,
|
| 235 |
+
19,
|
| 236 |
+
146,
|
| 237 |
+
11,
|
| 238 |
+
153,
|
| 239 |
+
176
|
| 240 |
+
],
|
| 241 |
+
124,
|
| 242 |
+
134
|
| 243 |
+
],
|
| 244 |
+
"output": 12991
|
| 245 |
+
},
|
| 246 |
+
{
|
| 247 |
+
"input": [
|
| 248 |
+
[
|
| 249 |
+
55,
|
| 250 |
+
73,
|
| 251 |
+
9,
|
| 252 |
+
35,
|
| 253 |
+
36,
|
| 254 |
+
152,
|
| 255 |
+
184,
|
| 256 |
+
130,
|
| 257 |
+
128,
|
| 258 |
+
50,
|
| 259 |
+
159,
|
| 260 |
+
75,
|
| 261 |
+
125,
|
| 262 |
+
20,
|
| 263 |
+
45,
|
| 264 |
+
198
|
| 265 |
+
],
|
| 266 |
+
16,
|
| 267 |
+
18
|
| 268 |
+
],
|
| 269 |
+
"output": 136
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"input": [
|
| 273 |
+
[
|
| 274 |
+
119,
|
| 275 |
+
127,
|
| 276 |
+
77,
|
| 277 |
+
3,
|
| 278 |
+
100,
|
| 279 |
+
55,
|
| 280 |
+
99,
|
| 281 |
+
96,
|
| 282 |
+
18,
|
| 283 |
+
179,
|
| 284 |
+
121
|
| 285 |
+
],
|
| 286 |
+
7,
|
| 287 |
+
167
|
| 288 |
+
],
|
| 289 |
+
"output": 66
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"input": [
|
| 293 |
+
[
|
| 294 |
+
163,
|
| 295 |
+
168,
|
| 296 |
+
140,
|
| 297 |
+
68,
|
| 298 |
+
140,
|
| 299 |
+
176,
|
| 300 |
+
160,
|
| 301 |
+
114,
|
| 302 |
+
141,
|
| 303 |
+
122,
|
| 304 |
+
168,
|
| 305 |
+
165,
|
| 306 |
+
162,
|
| 307 |
+
31,
|
| 308 |
+
2,
|
| 309 |
+
194,
|
| 310 |
+
149,
|
| 311 |
+
157,
|
| 312 |
+
143,
|
| 313 |
+
2,
|
| 314 |
+
176,
|
| 315 |
+
48,
|
| 316 |
+
12,
|
| 317 |
+
182,
|
| 318 |
+
144,
|
| 319 |
+
109,
|
| 320 |
+
34,
|
| 321 |
+
137,
|
| 322 |
+
48,
|
| 323 |
+
96,
|
| 324 |
+
61,
|
| 325 |
+
127,
|
| 326 |
+
189,
|
| 327 |
+
188,
|
| 328 |
+
178,
|
| 329 |
+
124,
|
| 330 |
+
155,
|
| 331 |
+
74,
|
| 332 |
+
94,
|
| 333 |
+
8,
|
| 334 |
+
73,
|
| 335 |
+
46,
|
| 336 |
+
158,
|
| 337 |
+
41,
|
| 338 |
+
150,
|
| 339 |
+
75,
|
| 340 |
+
81,
|
| 341 |
+
131,
|
| 342 |
+
189,
|
| 343 |
+
145,
|
| 344 |
+
58,
|
| 345 |
+
42,
|
| 346 |
+
142,
|
| 347 |
+
100,
|
| 348 |
+
126,
|
| 349 |
+
118,
|
| 350 |
+
191,
|
| 351 |
+
81,
|
| 352 |
+
132,
|
| 353 |
+
200,
|
| 354 |
+
58,
|
| 355 |
+
117,
|
| 356 |
+
170,
|
| 357 |
+
183,
|
| 358 |
+
41,
|
| 359 |
+
18,
|
| 360 |
+
33,
|
| 361 |
+
30,
|
| 362 |
+
76,
|
| 363 |
+
106,
|
| 364 |
+
82,
|
| 365 |
+
102,
|
| 366 |
+
9,
|
| 367 |
+
92,
|
| 368 |
+
44,
|
| 369 |
+
172,
|
| 370 |
+
81,
|
| 371 |
+
197,
|
| 372 |
+
92,
|
| 373 |
+
80,
|
| 374 |
+
165,
|
| 375 |
+
138,
|
| 376 |
+
46,
|
| 377 |
+
134,
|
| 378 |
+
147,
|
| 379 |
+
157,
|
| 380 |
+
28,
|
| 381 |
+
171
|
| 382 |
+
],
|
| 383 |
+
18,
|
| 384 |
+
177
|
| 385 |
+
],
|
| 386 |
+
"output": 3902
|
| 387 |
+
},
|
| 388 |
+
{
|
| 389 |
+
"input": [
|
| 390 |
+
[
|
| 391 |
+
153,
|
| 392 |
+
24,
|
| 393 |
+
189,
|
| 394 |
+
40,
|
| 395 |
+
28,
|
| 396 |
+
139,
|
| 397 |
+
195,
|
| 398 |
+
168,
|
| 399 |
+
61,
|
| 400 |
+
98,
|
| 401 |
+
140,
|
| 402 |
+
52,
|
| 403 |
+
166,
|
| 404 |
+
132,
|
| 405 |
+
60,
|
| 406 |
+
180,
|
| 407 |
+
15
|
| 408 |
+
],
|
| 409 |
+
3,
|
| 410 |
+
82
|
| 411 |
+
],
|
| 412 |
+
"output": 153
|
| 413 |
+
},
|
| 414 |
+
{
|
| 415 |
+
"input": [
|
| 416 |
+
[
|
| 417 |
+
60,
|
| 418 |
+
11,
|
| 419 |
+
190,
|
| 420 |
+
147,
|
| 421 |
+
105,
|
| 422 |
+
99,
|
| 423 |
+
73,
|
| 424 |
+
106,
|
| 425 |
+
16,
|
| 426 |
+
178,
|
| 427 |
+
134,
|
| 428 |
+
70,
|
| 429 |
+
106,
|
| 430 |
+
24,
|
| 431 |
+
47,
|
| 432 |
+
56,
|
| 433 |
+
107,
|
| 434 |
+
85,
|
| 435 |
+
48,
|
| 436 |
+
119,
|
| 437 |
+
59,
|
| 438 |
+
95,
|
| 439 |
+
137,
|
| 440 |
+
157,
|
| 441 |
+
152,
|
| 442 |
+
47,
|
| 443 |
+
155,
|
| 444 |
+
84,
|
| 445 |
+
92,
|
| 446 |
+
113,
|
| 447 |
+
62,
|
| 448 |
+
93,
|
| 449 |
+
113,
|
| 450 |
+
10,
|
| 451 |
+
22,
|
| 452 |
+
105,
|
| 453 |
+
81,
|
| 454 |
+
185,
|
| 455 |
+
76,
|
| 456 |
+
33,
|
| 457 |
+
65,
|
| 458 |
+
54,
|
| 459 |
+
140,
|
| 460 |
+
75,
|
| 461 |
+
199,
|
| 462 |
+
94,
|
| 463 |
+
44,
|
| 464 |
+
85,
|
| 465 |
+
55,
|
| 466 |
+
163,
|
| 467 |
+
104,
|
| 468 |
+
142,
|
| 469 |
+
80,
|
| 470 |
+
167,
|
| 471 |
+
182,
|
| 472 |
+
53,
|
| 473 |
+
33,
|
| 474 |
+
91,
|
| 475 |
+
50,
|
| 476 |
+
197,
|
| 477 |
+
19,
|
| 478 |
+
190,
|
| 479 |
+
25
|
| 480 |
+
],
|
| 481 |
+
39,
|
| 482 |
+
194
|
| 483 |
+
],
|
| 484 |
+
"output": 2009
|
| 485 |
+
},
|
| 486 |
+
{
|
| 487 |
+
"input": [
|
| 488 |
+
[
|
| 489 |
+
78,
|
| 490 |
+
118,
|
| 491 |
+
40,
|
| 492 |
+
60,
|
| 493 |
+
85,
|
| 494 |
+
200,
|
| 495 |
+
137,
|
| 496 |
+
147,
|
| 497 |
+
10,
|
| 498 |
+
157,
|
| 499 |
+
133,
|
| 500 |
+
67,
|
| 501 |
+
58,
|
| 502 |
+
132,
|
| 503 |
+
71,
|
| 504 |
+
192,
|
| 505 |
+
167,
|
| 506 |
+
174,
|
| 507 |
+
42,
|
| 508 |
+
168,
|
| 509 |
+
129,
|
| 510 |
+
95,
|
| 511 |
+
28,
|
| 512 |
+
62,
|
| 513 |
+
29,
|
| 514 |
+
78,
|
| 515 |
+
55,
|
| 516 |
+
129,
|
| 517 |
+
184,
|
| 518 |
+
183,
|
| 519 |
+
67,
|
| 520 |
+
38,
|
| 521 |
+
55,
|
| 522 |
+
62,
|
| 523 |
+
173,
|
| 524 |
+
30,
|
| 525 |
+
70,
|
| 526 |
+
114,
|
| 527 |
+
34,
|
| 528 |
+
101,
|
| 529 |
+
64,
|
| 530 |
+
185,
|
| 531 |
+
81,
|
| 532 |
+
81,
|
| 533 |
+
10,
|
| 534 |
+
82,
|
| 535 |
+
170,
|
| 536 |
+
140,
|
| 537 |
+
184,
|
| 538 |
+
95,
|
| 539 |
+
58,
|
| 540 |
+
11,
|
| 541 |
+
35,
|
| 542 |
+
81,
|
| 543 |
+
191,
|
| 544 |
+
146,
|
| 545 |
+
168,
|
| 546 |
+
116,
|
| 547 |
+
16,
|
| 548 |
+
51,
|
| 549 |
+
179,
|
| 550 |
+
118,
|
| 551 |
+
43,
|
| 552 |
+
104,
|
| 553 |
+
154,
|
| 554 |
+
67,
|
| 555 |
+
75,
|
| 556 |
+
138,
|
| 557 |
+
185,
|
| 558 |
+
148,
|
| 559 |
+
200,
|
| 560 |
+
167,
|
| 561 |
+
62,
|
| 562 |
+
176,
|
| 563 |
+
94,
|
| 564 |
+
156,
|
| 565 |
+
126,
|
| 566 |
+
69,
|
| 567 |
+
39,
|
| 568 |
+
112,
|
| 569 |
+
173,
|
| 570 |
+
58,
|
| 571 |
+
21,
|
| 572 |
+
160,
|
| 573 |
+
2,
|
| 574 |
+
80,
|
| 575 |
+
195,
|
| 576 |
+
116,
|
| 577 |
+
38,
|
| 578 |
+
192,
|
| 579 |
+
146,
|
| 580 |
+
95,
|
| 581 |
+
135,
|
| 582 |
+
34,
|
| 583 |
+
82,
|
| 584 |
+
36,
|
| 585 |
+
62,
|
| 586 |
+
23,
|
| 587 |
+
23,
|
| 588 |
+
183,
|
| 589 |
+
128,
|
| 590 |
+
174,
|
| 591 |
+
151,
|
| 592 |
+
32,
|
| 593 |
+
133,
|
| 594 |
+
43,
|
| 595 |
+
79,
|
| 596 |
+
4,
|
| 597 |
+
194,
|
| 598 |
+
46,
|
| 599 |
+
179,
|
| 600 |
+
200,
|
| 601 |
+
27,
|
| 602 |
+
118,
|
| 603 |
+
135,
|
| 604 |
+
185,
|
| 605 |
+
191,
|
| 606 |
+
194,
|
| 607 |
+
149,
|
| 608 |
+
40,
|
| 609 |
+
82,
|
| 610 |
+
25,
|
| 611 |
+
106,
|
| 612 |
+
109,
|
| 613 |
+
73,
|
| 614 |
+
5,
|
| 615 |
+
180,
|
| 616 |
+
77,
|
| 617 |
+
49,
|
| 618 |
+
177,
|
| 619 |
+
122,
|
| 620 |
+
8,
|
| 621 |
+
106,
|
| 622 |
+
20,
|
| 623 |
+
3,
|
| 624 |
+
59,
|
| 625 |
+
183,
|
| 626 |
+
167,
|
| 627 |
+
134,
|
| 628 |
+
138,
|
| 629 |
+
179,
|
| 630 |
+
114,
|
| 631 |
+
129,
|
| 632 |
+
78,
|
| 633 |
+
147,
|
| 634 |
+
131,
|
| 635 |
+
180,
|
| 636 |
+
41
|
| 637 |
+
],
|
| 638 |
+
108,
|
| 639 |
+
56
|
| 640 |
+
],
|
| 641 |
+
"output": 10974
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"input": [
|
| 645 |
+
[
|
| 646 |
+
51,
|
| 647 |
+
126,
|
| 648 |
+
55,
|
| 649 |
+
133,
|
| 650 |
+
129,
|
| 651 |
+
180,
|
| 652 |
+
24,
|
| 653 |
+
155,
|
| 654 |
+
92,
|
| 655 |
+
52,
|
| 656 |
+
124,
|
| 657 |
+
104,
|
| 658 |
+
10,
|
| 659 |
+
46,
|
| 660 |
+
134,
|
| 661 |
+
134,
|
| 662 |
+
165,
|
| 663 |
+
16,
|
| 664 |
+
21,
|
| 665 |
+
157,
|
| 666 |
+
90,
|
| 667 |
+
146,
|
| 668 |
+
17,
|
| 669 |
+
99,
|
| 670 |
+
183,
|
| 671 |
+
70,
|
| 672 |
+
181,
|
| 673 |
+
120,
|
| 674 |
+
151,
|
| 675 |
+
118,
|
| 676 |
+
55,
|
| 677 |
+
21,
|
| 678 |
+
98,
|
| 679 |
+
36,
|
| 680 |
+
103,
|
| 681 |
+
80,
|
| 682 |
+
82,
|
| 683 |
+
43,
|
| 684 |
+
168,
|
| 685 |
+
82,
|
| 686 |
+
57,
|
| 687 |
+
51,
|
| 688 |
+
131,
|
| 689 |
+
69,
|
| 690 |
+
160,
|
| 691 |
+
66,
|
| 692 |
+
157,
|
| 693 |
+
199,
|
| 694 |
+
116,
|
| 695 |
+
166,
|
| 696 |
+
86,
|
| 697 |
+
8,
|
| 698 |
+
110,
|
| 699 |
+
154,
|
| 700 |
+
51,
|
| 701 |
+
81,
|
| 702 |
+
58,
|
| 703 |
+
181,
|
| 704 |
+
93,
|
| 705 |
+
142,
|
| 706 |
+
166,
|
| 707 |
+
126,
|
| 708 |
+
74,
|
| 709 |
+
29,
|
| 710 |
+
32,
|
| 711 |
+
110,
|
| 712 |
+
69,
|
| 713 |
+
17,
|
| 714 |
+
190,
|
| 715 |
+
123,
|
| 716 |
+
1,
|
| 717 |
+
14,
|
| 718 |
+
84,
|
| 719 |
+
80,
|
| 720 |
+
151,
|
| 721 |
+
192,
|
| 722 |
+
104,
|
| 723 |
+
65,
|
| 724 |
+
196,
|
| 725 |
+
18,
|
| 726 |
+
29,
|
| 727 |
+
122,
|
| 728 |
+
159,
|
| 729 |
+
42,
|
| 730 |
+
47,
|
| 731 |
+
137,
|
| 732 |
+
130,
|
| 733 |
+
12,
|
| 734 |
+
5,
|
| 735 |
+
54,
|
| 736 |
+
35,
|
| 737 |
+
4,
|
| 738 |
+
128,
|
| 739 |
+
34,
|
| 740 |
+
182,
|
| 741 |
+
54,
|
| 742 |
+
183,
|
| 743 |
+
13,
|
| 744 |
+
188,
|
| 745 |
+
44,
|
| 746 |
+
141,
|
| 747 |
+
76,
|
| 748 |
+
13,
|
| 749 |
+
97,
|
| 750 |
+
185,
|
| 751 |
+
166,
|
| 752 |
+
3,
|
| 753 |
+
104,
|
| 754 |
+
167,
|
| 755 |
+
83,
|
| 756 |
+
66,
|
| 757 |
+
151,
|
| 758 |
+
133,
|
| 759 |
+
93,
|
| 760 |
+
47,
|
| 761 |
+
32,
|
| 762 |
+
125,
|
| 763 |
+
24,
|
| 764 |
+
121,
|
| 765 |
+
199,
|
| 766 |
+
87,
|
| 767 |
+
2,
|
| 768 |
+
23,
|
| 769 |
+
104
|
| 770 |
+
],
|
| 771 |
+
107,
|
| 772 |
+
150
|
| 773 |
+
],
|
| 774 |
+
"output": 7719
|
| 775 |
+
},
|
| 776 |
+
{
|
| 777 |
+
"input": [
|
| 778 |
+
[
|
| 779 |
+
31,
|
| 780 |
+
141,
|
| 781 |
+
119,
|
| 782 |
+
126,
|
| 783 |
+
21,
|
| 784 |
+
162,
|
| 785 |
+
18,
|
| 786 |
+
126,
|
| 787 |
+
184,
|
| 788 |
+
82,
|
| 789 |
+
117,
|
| 790 |
+
183,
|
| 791 |
+
64,
|
| 792 |
+
143,
|
| 793 |
+
143,
|
| 794 |
+
32,
|
| 795 |
+
29,
|
| 796 |
+
171,
|
| 797 |
+
173,
|
| 798 |
+
169,
|
| 799 |
+
11,
|
| 800 |
+
55,
|
| 801 |
+
167,
|
| 802 |
+
6,
|
| 803 |
+
119,
|
| 804 |
+
192,
|
| 805 |
+
54,
|
| 806 |
+
124,
|
| 807 |
+
6,
|
| 808 |
+
198,
|
| 809 |
+
197,
|
| 810 |
+
195,
|
| 811 |
+
56,
|
| 812 |
+
192,
|
| 813 |
+
195,
|
| 814 |
+
161,
|
| 815 |
+
165,
|
| 816 |
+
59,
|
| 817 |
+
82,
|
| 818 |
+
164,
|
| 819 |
+
137,
|
| 820 |
+
66,
|
| 821 |
+
123,
|
| 822 |
+
87,
|
| 823 |
+
132,
|
| 824 |
+
179,
|
| 825 |
+
145,
|
| 826 |
+
132,
|
| 827 |
+
73,
|
| 828 |
+
145,
|
| 829 |
+
168,
|
| 830 |
+
127,
|
| 831 |
+
8,
|
| 832 |
+
189,
|
| 833 |
+
139,
|
| 834 |
+
12,
|
| 835 |
+
172,
|
| 836 |
+
152,
|
| 837 |
+
180,
|
| 838 |
+
158,
|
| 839 |
+
13,
|
| 840 |
+
44,
|
| 841 |
+
76,
|
| 842 |
+
91,
|
| 843 |
+
178,
|
| 844 |
+
32,
|
| 845 |
+
176,
|
| 846 |
+
32,
|
| 847 |
+
171,
|
| 848 |
+
2,
|
| 849 |
+
53,
|
| 850 |
+
126,
|
| 851 |
+
101,
|
| 852 |
+
4,
|
| 853 |
+
50,
|
| 854 |
+
118,
|
| 855 |
+
81,
|
| 856 |
+
165,
|
| 857 |
+
129,
|
| 858 |
+
192,
|
| 859 |
+
56,
|
| 860 |
+
191,
|
| 861 |
+
195,
|
| 862 |
+
127,
|
| 863 |
+
110,
|
| 864 |
+
117,
|
| 865 |
+
48,
|
| 866 |
+
173,
|
| 867 |
+
92,
|
| 868 |
+
108,
|
| 869 |
+
195,
|
| 870 |
+
108,
|
| 871 |
+
172,
|
| 872 |
+
138,
|
| 873 |
+
113,
|
| 874 |
+
160,
|
| 875 |
+
11,
|
| 876 |
+
122,
|
| 877 |
+
19,
|
| 878 |
+
173,
|
| 879 |
+
90,
|
| 880 |
+
40,
|
| 881 |
+
34,
|
| 882 |
+
167,
|
| 883 |
+
1,
|
| 884 |
+
192,
|
| 885 |
+
90,
|
| 886 |
+
122,
|
| 887 |
+
134,
|
| 888 |
+
148,
|
| 889 |
+
28,
|
| 890 |
+
93,
|
| 891 |
+
66,
|
| 892 |
+
192,
|
| 893 |
+
137,
|
| 894 |
+
186,
|
| 895 |
+
56,
|
| 896 |
+
145,
|
| 897 |
+
91
|
| 898 |
+
],
|
| 899 |
+
81,
|
| 900 |
+
96
|
| 901 |
+
],
|
| 902 |
+
"output": 7105
|
| 903 |
+
}
|
| 904 |
+
],
|
| 905 |
+
"haskell_template": "countDistinct :: [Int] -> Int -> Int -> Int\ncountDistinct nums k p ",
|
| 906 |
+
"ocaml_template": "let countDistinct (nums: int list) (k: int) (p: int) : int = ",
|
| 907 |
+
"scala_template": "def countDistinct(nums: List[Int],k: Int,p: Int): Int = { \n \n}",
|
| 908 |
+
"java_template": "public static int countDistinct(List<Integer> nums, int k, int p) {\n\n}",
|
| 909 |
+
"python_template": "class Solution(object):\n def countDistinct(self, nums, k, p):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :type p: int\n :rtype: int\n \"\"\"\n "
|
| 910 |
+
}
|
k_divisible_elements_subarrays/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 11 (countDistinct [ 2 ;3;3; 2 ; 2 ] 2 2)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 10 (countDistinct [1;2;3;4] 4 1)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for countDistinct" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
k_divisible_elements_subarrays/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.countDistinct(List( 2 ,3,3, 2 , 2 ),2,2), 11)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.countDistinct(List(1,2,3,4),4,1), 10)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
k_highest_ranked_items_within_a_price_range/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
k_highest_ranked_items_within_a_price_range/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 (highestRankedKItems [[1,2,0,1],[1,3,0,1],[0,2,5,1]] [2,5] [0,0] 3)," [[0,1],[1,1],[2,1]] (highestRankedKItems [[1,2,0,1],[1,3,0,1],[0,2,5,1]] [2,5] [0,0] 3))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (highestRankedKItems [[1,2,0,1],[1,3,3,1],[0,2,5,1]] [2,3] [2,3] 2)," [[2,1],[1,2]] (highestRankedKItems [[1,2,0,1],[1,3,3,1],[0,2,5,1]] [2,3] [2,3] 2))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (highestRankedKItems [[1,1,1],[0,0,1],[2,3,4]] [2,3] [0,0] 3)," [[2,1],[2,0]] (highestRankedKItems [[1,1,1],[0,0,1],[2,3,4]] [2,3] [0,0] 3))
|
| 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
|
k_highest_ranked_items_within_a_price_range/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(new ArrayList<>(Arrays.asList(0,1)),new ArrayList<>(Arrays.asList(1,1)),new ArrayList<>(Arrays.asList(2,1)))), highestRankedKItems(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1,2,0,1)),new ArrayList<>(Arrays.asList(1,3,0,1)),new ArrayList<>(Arrays.asList(0,2,5,1)))), new ArrayList<>(Arrays.asList(2,5)), new ArrayList<>(Arrays.asList(0,0)), 3));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(2,1)),new ArrayList<>(Arrays.asList(1,2)))), highestRankedKItems(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1,2,0,1)),new ArrayList<>(Arrays.asList(1,3,3,1)),new ArrayList<>(Arrays.asList(0,2,5,1)))), new ArrayList<>(Arrays.asList(2,3)), new ArrayList<>(Arrays.asList(2,3)), 2));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(2,1)),new ArrayList<>(Arrays.asList(2,0)))), highestRankedKItems(new ArrayList<>(Arrays.asList(new ArrayList<>(Arrays.asList(1,1,1)),new ArrayList<>(Arrays.asList(0,0,1)),new ArrayList<>(Arrays.asList(2,3,4)))), new ArrayList<>(Arrays.asList(2,3)), new ArrayList<>(Arrays.asList(0,0)), 3));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
k_highest_ranked_items_within_a_price_range/meta.json
ADDED
|
@@ -0,0 +1,917 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2250,
|
| 3 |
+
"name": "k_highest_ranked_items_within_a_price_range",
|
| 4 |
+
"difficulty": "Medium",
|
| 5 |
+
"link": "https://leetcode.com/problems/k-highest-ranked-items-within-a-price-range/",
|
| 6 |
+
"date": "1641600000000",
|
| 7 |
+
"task_description": "You are given a **0-indexed** 2D integer array `grid` of size `m x n` that represents a map of the items in a shop. The integers in the grid represent the following: `0` represents a wall that you cannot pass through. `1` represents an empty cell that you can freely move to and from. All other positive integers represent the price of an item in that cell. You may also freely move to and from these item cells. It takes `1` step to travel between adjacent grid cells. You are also given integer arrays `pricing` and `start` where `pricing = [low, high]` and `start = [row, col]` indicates that you start at the position `(row, col)` and are interested only in items with a price in the range of `[low, high]` (**inclusive**). You are further given an integer `k`. You are interested in the **positions** of the `k` **highest-ranked** items whose prices are **within** the given price range. The rank is determined by the **first** of these criteria that is different: Distance, defined as the length of the shortest path from the `start` (**shorter** distance has a higher rank). Price (**lower** price has a higher rank, but it must be **in the price range**). The row number (**smaller** row number has a higher rank). The column number (**smaller** column number has a higher rank). Return _the _`k`_ highest-ranked items within the price range **sorted** by their rank (highest to lowest)_. If there are fewer than `k` reachable items within the price range, return _**all** of them_. **Example 1:** ``` **Input:** grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3 **Output:** [[0,1],[1,1],[2,1]] **Explanation:** You start at (0,0). With a price range of [2,5], we can take items from (0,1), (1,1), (2,1) and (2,2). The ranks of these items are: - (0,1) with distance 1 - (1,1) with distance 2 - (2,1) with distance 3 - (2,2) with distance 4 Thus, the 3 highest ranked items in the price range are (0,1), (1,1), and (2,1). ``` **Example 2:** ``` **Input:** grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2 **Output:** [[2,1],[1,2]] **Explanation:** You start at (2,3). With a price range of [2,3], we can take items from (0,1), (1,1), (1,2) and (2,1). The ranks of these items are: - (2,1) with distance 2, price 2 - (1,2) with distance 2, price 3 - (1,1) with distance 3 - (0,1) with distance 4 Thus, the 2 highest ranked items in the price range are (2,1) and (1,2). ``` **Example 3:** ``` **Input:** grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3 **Output:** [[2,1],[2,0]] **Explanation:** You start at (0,0). With a price range of [2,3], we can take items from (2,0) and (2,1). The ranks of these items are: - (2,1) with distance 5 - (2,0) with distance 6 Thus, the 2 highest ranked items in the price range are (2,1) and (2,0). Note that k = 3 but there are only 2 reachable items within the price range. ``` **Constraints:** `m == grid.length` `n == grid[i].length` `1 <= m, n <= 105` `1 <= m * n <= 105` `0 <= grid[i][j] <= 105` `pricing.length == 2` `2 <= low <= high <= 105` `start.length == 2` `0 <= row <= m - 1` `0 <= col <= n - 1` `grid[row][col] > 0` `1 <= k <= m * n`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "grid = [[1,2,0,1],[1,3,0,1],[0,2,5,1]], pricing = [2,5], start = [0,0], k = 3",
|
| 12 |
+
"output": "[[0,1],[1,1],[2,1]] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "grid = [[1,2,0,1],[1,3,3,1],[0,2,5,1]], pricing = [2,3], start = [2,3], k = 2",
|
| 17 |
+
"output": "[[2,1],[1,2]] "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "grid = [[1,1,1],[0,0,1],[2,3,4]], pricing = [2,3], start = [0,0], k = 3",
|
| 22 |
+
"output": "[[2,1],[2,0]] "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"private_test_cases": [
|
| 26 |
+
{
|
| 27 |
+
"input": [
|
| 28 |
+
[
|
| 29 |
+
[
|
| 30 |
+
0,
|
| 31 |
+
33,
|
| 32 |
+
66,
|
| 33 |
+
86,
|
| 34 |
+
0,
|
| 35 |
+
0,
|
| 36 |
+
17
|
| 37 |
+
],
|
| 38 |
+
[
|
| 39 |
+
7,
|
| 40 |
+
0,
|
| 41 |
+
1,
|
| 42 |
+
17,
|
| 43 |
+
24,
|
| 44 |
+
0,
|
| 45 |
+
39
|
| 46 |
+
],
|
| 47 |
+
[
|
| 48 |
+
0,
|
| 49 |
+
15,
|
| 50 |
+
83,
|
| 51 |
+
8,
|
| 52 |
+
53,
|
| 53 |
+
0,
|
| 54 |
+
57
|
| 55 |
+
]
|
| 56 |
+
],
|
| 57 |
+
[
|
| 58 |
+
31,
|
| 59 |
+
74
|
| 60 |
+
],
|
| 61 |
+
[
|
| 62 |
+
0,
|
| 63 |
+
3
|
| 64 |
+
],
|
| 65 |
+
12
|
| 66 |
+
],
|
| 67 |
+
"output": [
|
| 68 |
+
[
|
| 69 |
+
0,
|
| 70 |
+
2
|
| 71 |
+
],
|
| 72 |
+
[
|
| 73 |
+
0,
|
| 74 |
+
1
|
| 75 |
+
],
|
| 76 |
+
[
|
| 77 |
+
2,
|
| 78 |
+
4
|
| 79 |
+
]
|
| 80 |
+
]
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"input": [
|
| 84 |
+
[
|
| 85 |
+
[
|
| 86 |
+
3,
|
| 87 |
+
0,
|
| 88 |
+
0,
|
| 89 |
+
26,
|
| 90 |
+
34,
|
| 91 |
+
0,
|
| 92 |
+
81,
|
| 93 |
+
39
|
| 94 |
+
],
|
| 95 |
+
[
|
| 96 |
+
97,
|
| 97 |
+
68,
|
| 98 |
+
0,
|
| 99 |
+
11,
|
| 100 |
+
65,
|
| 101 |
+
10,
|
| 102 |
+
9,
|
| 103 |
+
79
|
| 104 |
+
],
|
| 105 |
+
[
|
| 106 |
+
13,
|
| 107 |
+
98,
|
| 108 |
+
32,
|
| 109 |
+
18,
|
| 110 |
+
72,
|
| 111 |
+
0,
|
| 112 |
+
79,
|
| 113 |
+
75
|
| 114 |
+
],
|
| 115 |
+
[
|
| 116 |
+
0,
|
| 117 |
+
24,
|
| 118 |
+
70,
|
| 119 |
+
65,
|
| 120 |
+
58,
|
| 121 |
+
39,
|
| 122 |
+
78,
|
| 123 |
+
74
|
| 124 |
+
],
|
| 125 |
+
[
|
| 126 |
+
74,
|
| 127 |
+
35,
|
| 128 |
+
75,
|
| 129 |
+
48,
|
| 130 |
+
0,
|
| 131 |
+
0,
|
| 132 |
+
91,
|
| 133 |
+
76
|
| 134 |
+
],
|
| 135 |
+
[
|
| 136 |
+
77,
|
| 137 |
+
98,
|
| 138 |
+
91,
|
| 139 |
+
5,
|
| 140 |
+
18,
|
| 141 |
+
72,
|
| 142 |
+
0,
|
| 143 |
+
24
|
| 144 |
+
]
|
| 145 |
+
],
|
| 146 |
+
[
|
| 147 |
+
41,
|
| 148 |
+
74
|
| 149 |
+
],
|
| 150 |
+
[
|
| 151 |
+
3,
|
| 152 |
+
4
|
| 153 |
+
],
|
| 154 |
+
19
|
| 155 |
+
],
|
| 156 |
+
"output": [
|
| 157 |
+
[
|
| 158 |
+
3,
|
| 159 |
+
4
|
| 160 |
+
],
|
| 161 |
+
[
|
| 162 |
+
3,
|
| 163 |
+
3
|
| 164 |
+
],
|
| 165 |
+
[
|
| 166 |
+
2,
|
| 167 |
+
4
|
| 168 |
+
],
|
| 169 |
+
[
|
| 170 |
+
4,
|
| 171 |
+
3
|
| 172 |
+
],
|
| 173 |
+
[
|
| 174 |
+
1,
|
| 175 |
+
4
|
| 176 |
+
],
|
| 177 |
+
[
|
| 178 |
+
3,
|
| 179 |
+
2
|
| 180 |
+
],
|
| 181 |
+
[
|
| 182 |
+
3,
|
| 183 |
+
7
|
| 184 |
+
],
|
| 185 |
+
[
|
| 186 |
+
1,
|
| 187 |
+
1
|
| 188 |
+
],
|
| 189 |
+
[
|
| 190 |
+
5,
|
| 191 |
+
5
|
| 192 |
+
],
|
| 193 |
+
[
|
| 194 |
+
4,
|
| 195 |
+
0
|
| 196 |
+
]
|
| 197 |
+
]
|
| 198 |
+
},
|
| 199 |
+
{
|
| 200 |
+
"input": [
|
| 201 |
+
[
|
| 202 |
+
[
|
| 203 |
+
0,
|
| 204 |
+
27,
|
| 205 |
+
0,
|
| 206 |
+
47,
|
| 207 |
+
79,
|
| 208 |
+
89,
|
| 209 |
+
92,
|
| 210 |
+
78,
|
| 211 |
+
93,
|
| 212 |
+
99
|
| 213 |
+
],
|
| 214 |
+
[
|
| 215 |
+
13,
|
| 216 |
+
50,
|
| 217 |
+
41,
|
| 218 |
+
0,
|
| 219 |
+
0,
|
| 220 |
+
95,
|
| 221 |
+
0,
|
| 222 |
+
100,
|
| 223 |
+
44,
|
| 224 |
+
97
|
| 225 |
+
],
|
| 226 |
+
[
|
| 227 |
+
28,
|
| 228 |
+
0,
|
| 229 |
+
67,
|
| 230 |
+
40,
|
| 231 |
+
0,
|
| 232 |
+
0,
|
| 233 |
+
73,
|
| 234 |
+
0,
|
| 235 |
+
20,
|
| 236 |
+
41
|
| 237 |
+
],
|
| 238 |
+
[
|
| 239 |
+
68,
|
| 240 |
+
66,
|
| 241 |
+
0,
|
| 242 |
+
95,
|
| 243 |
+
59,
|
| 244 |
+
59,
|
| 245 |
+
0,
|
| 246 |
+
23,
|
| 247 |
+
62,
|
| 248 |
+
0
|
| 249 |
+
],
|
| 250 |
+
[
|
| 251 |
+
18,
|
| 252 |
+
72,
|
| 253 |
+
0,
|
| 254 |
+
0,
|
| 255 |
+
0,
|
| 256 |
+
0,
|
| 257 |
+
8,
|
| 258 |
+
16,
|
| 259 |
+
24,
|
| 260 |
+
88
|
| 261 |
+
]
|
| 262 |
+
],
|
| 263 |
+
[
|
| 264 |
+
11,
|
| 265 |
+
44
|
| 266 |
+
],
|
| 267 |
+
[
|
| 268 |
+
3,
|
| 269 |
+
9
|
| 270 |
+
],
|
| 271 |
+
4
|
| 272 |
+
],
|
| 273 |
+
"output": [
|
| 274 |
+
[
|
| 275 |
+
2,
|
| 276 |
+
9
|
| 277 |
+
],
|
| 278 |
+
[
|
| 279 |
+
2,
|
| 280 |
+
8
|
| 281 |
+
],
|
| 282 |
+
[
|
| 283 |
+
3,
|
| 284 |
+
7
|
| 285 |
+
],
|
| 286 |
+
[
|
| 287 |
+
4,
|
| 288 |
+
8
|
| 289 |
+
]
|
| 290 |
+
]
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"input": [
|
| 294 |
+
[
|
| 295 |
+
[
|
| 296 |
+
89,
|
| 297 |
+
5,
|
| 298 |
+
22,
|
| 299 |
+
0,
|
| 300 |
+
45,
|
| 301 |
+
98,
|
| 302 |
+
22
|
| 303 |
+
],
|
| 304 |
+
[
|
| 305 |
+
13,
|
| 306 |
+
56,
|
| 307 |
+
0,
|
| 308 |
+
95,
|
| 309 |
+
94,
|
| 310 |
+
12,
|
| 311 |
+
95
|
| 312 |
+
],
|
| 313 |
+
[
|
| 314 |
+
59,
|
| 315 |
+
0,
|
| 316 |
+
0,
|
| 317 |
+
0,
|
| 318 |
+
40,
|
| 319 |
+
90,
|
| 320 |
+
99
|
| 321 |
+
],
|
| 322 |
+
[
|
| 323 |
+
32,
|
| 324 |
+
86,
|
| 325 |
+
12,
|
| 326 |
+
3,
|
| 327 |
+
0,
|
| 328 |
+
95,
|
| 329 |
+
89
|
| 330 |
+
],
|
| 331 |
+
[
|
| 332 |
+
74,
|
| 333 |
+
47,
|
| 334 |
+
54,
|
| 335 |
+
29,
|
| 336 |
+
0,
|
| 337 |
+
2,
|
| 338 |
+
0
|
| 339 |
+
],
|
| 340 |
+
[
|
| 341 |
+
55,
|
| 342 |
+
19,
|
| 343 |
+
77,
|
| 344 |
+
0,
|
| 345 |
+
7,
|
| 346 |
+
69,
|
| 347 |
+
30
|
| 348 |
+
],
|
| 349 |
+
[
|
| 350 |
+
61,
|
| 351 |
+
22,
|
| 352 |
+
0,
|
| 353 |
+
0,
|
| 354 |
+
62,
|
| 355 |
+
37,
|
| 356 |
+
88
|
| 357 |
+
],
|
| 358 |
+
[
|
| 359 |
+
0,
|
| 360 |
+
0,
|
| 361 |
+
75,
|
| 362 |
+
0,
|
| 363 |
+
40,
|
| 364 |
+
97,
|
| 365 |
+
0
|
| 366 |
+
],
|
| 367 |
+
[
|
| 368 |
+
0,
|
| 369 |
+
61,
|
| 370 |
+
45,
|
| 371 |
+
0,
|
| 372 |
+
34,
|
| 373 |
+
0,
|
| 374 |
+
0
|
| 375 |
+
]
|
| 376 |
+
],
|
| 377 |
+
[
|
| 378 |
+
34,
|
| 379 |
+
91
|
| 380 |
+
],
|
| 381 |
+
[
|
| 382 |
+
2,
|
| 383 |
+
2
|
| 384 |
+
],
|
| 385 |
+
35
|
| 386 |
+
],
|
| 387 |
+
"output": [
|
| 388 |
+
[
|
| 389 |
+
4,
|
| 390 |
+
2
|
| 391 |
+
],
|
| 392 |
+
[
|
| 393 |
+
3,
|
| 394 |
+
1
|
| 395 |
+
],
|
| 396 |
+
[
|
| 397 |
+
4,
|
| 398 |
+
1
|
| 399 |
+
],
|
| 400 |
+
[
|
| 401 |
+
5,
|
| 402 |
+
2
|
| 403 |
+
],
|
| 404 |
+
[
|
| 405 |
+
2,
|
| 406 |
+
0
|
| 407 |
+
],
|
| 408 |
+
[
|
| 409 |
+
4,
|
| 410 |
+
0
|
| 411 |
+
],
|
| 412 |
+
[
|
| 413 |
+
5,
|
| 414 |
+
0
|
| 415 |
+
],
|
| 416 |
+
[
|
| 417 |
+
1,
|
| 418 |
+
1
|
| 419 |
+
],
|
| 420 |
+
[
|
| 421 |
+
6,
|
| 422 |
+
0
|
| 423 |
+
],
|
| 424 |
+
[
|
| 425 |
+
0,
|
| 426 |
+
0
|
| 427 |
+
]
|
| 428 |
+
]
|
| 429 |
+
},
|
| 430 |
+
{
|
| 431 |
+
"input": [
|
| 432 |
+
[
|
| 433 |
+
[
|
| 434 |
+
37,
|
| 435 |
+
44
|
| 436 |
+
],
|
| 437 |
+
[
|
| 438 |
+
77,
|
| 439 |
+
0
|
| 440 |
+
],
|
| 441 |
+
[
|
| 442 |
+
0,
|
| 443 |
+
43
|
| 444 |
+
],
|
| 445 |
+
[
|
| 446 |
+
21,
|
| 447 |
+
79
|
| 448 |
+
],
|
| 449 |
+
[
|
| 450 |
+
42,
|
| 451 |
+
30
|
| 452 |
+
],
|
| 453 |
+
[
|
| 454 |
+
0,
|
| 455 |
+
90
|
| 456 |
+
],
|
| 457 |
+
[
|
| 458 |
+
22,
|
| 459 |
+
71
|
| 460 |
+
]
|
| 461 |
+
],
|
| 462 |
+
[
|
| 463 |
+
8,
|
| 464 |
+
44
|
| 465 |
+
],
|
| 466 |
+
[
|
| 467 |
+
0,
|
| 468 |
+
0
|
| 469 |
+
],
|
| 470 |
+
3
|
| 471 |
+
],
|
| 472 |
+
"output": [
|
| 473 |
+
[
|
| 474 |
+
0,
|
| 475 |
+
0
|
| 476 |
+
],
|
| 477 |
+
[
|
| 478 |
+
0,
|
| 479 |
+
1
|
| 480 |
+
]
|
| 481 |
+
]
|
| 482 |
+
},
|
| 483 |
+
{
|
| 484 |
+
"input": [
|
| 485 |
+
[
|
| 486 |
+
[
|
| 487 |
+
0,
|
| 488 |
+
58,
|
| 489 |
+
98,
|
| 490 |
+
2,
|
| 491 |
+
0,
|
| 492 |
+
42,
|
| 493 |
+
0,
|
| 494 |
+
9
|
| 495 |
+
],
|
| 496 |
+
[
|
| 497 |
+
45,
|
| 498 |
+
49,
|
| 499 |
+
10,
|
| 500 |
+
0,
|
| 501 |
+
53,
|
| 502 |
+
13,
|
| 503 |
+
0,
|
| 504 |
+
40
|
| 505 |
+
],
|
| 506 |
+
[
|
| 507 |
+
0,
|
| 508 |
+
26,
|
| 509 |
+
81,
|
| 510 |
+
52,
|
| 511 |
+
0,
|
| 512 |
+
79,
|
| 513 |
+
21,
|
| 514 |
+
73
|
| 515 |
+
],
|
| 516 |
+
[
|
| 517 |
+
14,
|
| 518 |
+
29,
|
| 519 |
+
98,
|
| 520 |
+
0,
|
| 521 |
+
66,
|
| 522 |
+
17,
|
| 523 |
+
28,
|
| 524 |
+
16
|
| 525 |
+
]
|
| 526 |
+
],
|
| 527 |
+
[
|
| 528 |
+
19,
|
| 529 |
+
93
|
| 530 |
+
],
|
| 531 |
+
[
|
| 532 |
+
1,
|
| 533 |
+
3
|
| 534 |
+
],
|
| 535 |
+
7
|
| 536 |
+
],
|
| 537 |
+
"output": [
|
| 538 |
+
[
|
| 539 |
+
2,
|
| 540 |
+
3
|
| 541 |
+
],
|
| 542 |
+
[
|
| 543 |
+
1,
|
| 544 |
+
4
|
| 545 |
+
],
|
| 546 |
+
[
|
| 547 |
+
1,
|
| 548 |
+
1
|
| 549 |
+
],
|
| 550 |
+
[
|
| 551 |
+
2,
|
| 552 |
+
2
|
| 553 |
+
],
|
| 554 |
+
[
|
| 555 |
+
2,
|
| 556 |
+
1
|
| 557 |
+
],
|
| 558 |
+
[
|
| 559 |
+
0,
|
| 560 |
+
5
|
| 561 |
+
],
|
| 562 |
+
[
|
| 563 |
+
1,
|
| 564 |
+
0
|
| 565 |
+
]
|
| 566 |
+
]
|
| 567 |
+
},
|
| 568 |
+
{
|
| 569 |
+
"input": [
|
| 570 |
+
[
|
| 571 |
+
[
|
| 572 |
+
62,
|
| 573 |
+
34,
|
| 574 |
+
23,
|
| 575 |
+
88,
|
| 576 |
+
0,
|
| 577 |
+
90,
|
| 578 |
+
0,
|
| 579 |
+
5,
|
| 580 |
+
19,
|
| 581 |
+
0
|
| 582 |
+
],
|
| 583 |
+
[
|
| 584 |
+
0,
|
| 585 |
+
0,
|
| 586 |
+
0,
|
| 587 |
+
33,
|
| 588 |
+
4,
|
| 589 |
+
0,
|
| 590 |
+
69,
|
| 591 |
+
48,
|
| 592 |
+
80,
|
| 593 |
+
0
|
| 594 |
+
],
|
| 595 |
+
[
|
| 596 |
+
96,
|
| 597 |
+
0,
|
| 598 |
+
93,
|
| 599 |
+
0,
|
| 600 |
+
0,
|
| 601 |
+
0,
|
| 602 |
+
66,
|
| 603 |
+
0,
|
| 604 |
+
60,
|
| 605 |
+
24
|
| 606 |
+
],
|
| 607 |
+
[
|
| 608 |
+
58,
|
| 609 |
+
87,
|
| 610 |
+
31,
|
| 611 |
+
9,
|
| 612 |
+
43,
|
| 613 |
+
20,
|
| 614 |
+
5,
|
| 615 |
+
82,
|
| 616 |
+
23,
|
| 617 |
+
0
|
| 618 |
+
],
|
| 619 |
+
[
|
| 620 |
+
4,
|
| 621 |
+
45,
|
| 622 |
+
15,
|
| 623 |
+
8,
|
| 624 |
+
44,
|
| 625 |
+
76,
|
| 626 |
+
47,
|
| 627 |
+
62,
|
| 628 |
+
0,
|
| 629 |
+
2
|
| 630 |
+
],
|
| 631 |
+
[
|
| 632 |
+
58,
|
| 633 |
+
33,
|
| 634 |
+
66,
|
| 635 |
+
73,
|
| 636 |
+
0,
|
| 637 |
+
77,
|
| 638 |
+
80,
|
| 639 |
+
39,
|
| 640 |
+
0,
|
| 641 |
+
12
|
| 642 |
+
]
|
| 643 |
+
],
|
| 644 |
+
[
|
| 645 |
+
9,
|
| 646 |
+
64
|
| 647 |
+
],
|
| 648 |
+
[
|
| 649 |
+
2,
|
| 650 |
+
4
|
| 651 |
+
],
|
| 652 |
+
45
|
| 653 |
+
],
|
| 654 |
+
"output": [
|
| 655 |
+
[
|
| 656 |
+
3,
|
| 657 |
+
4
|
| 658 |
+
],
|
| 659 |
+
[
|
| 660 |
+
3,
|
| 661 |
+
3
|
| 662 |
+
],
|
| 663 |
+
[
|
| 664 |
+
3,
|
| 665 |
+
5
|
| 666 |
+
],
|
| 667 |
+
[
|
| 668 |
+
1,
|
| 669 |
+
3
|
| 670 |
+
],
|
| 671 |
+
[
|
| 672 |
+
4,
|
| 673 |
+
4
|
| 674 |
+
],
|
| 675 |
+
[
|
| 676 |
+
3,
|
| 677 |
+
2
|
| 678 |
+
],
|
| 679 |
+
[
|
| 680 |
+
4,
|
| 681 |
+
2
|
| 682 |
+
],
|
| 683 |
+
[
|
| 684 |
+
0,
|
| 685 |
+
2
|
| 686 |
+
],
|
| 687 |
+
[
|
| 688 |
+
4,
|
| 689 |
+
6
|
| 690 |
+
],
|
| 691 |
+
[
|
| 692 |
+
3,
|
| 693 |
+
8
|
| 694 |
+
],
|
| 695 |
+
[
|
| 696 |
+
0,
|
| 697 |
+
1
|
| 698 |
+
],
|
| 699 |
+
[
|
| 700 |
+
4,
|
| 701 |
+
1
|
| 702 |
+
],
|
| 703 |
+
[
|
| 704 |
+
3,
|
| 705 |
+
0
|
| 706 |
+
],
|
| 707 |
+
[
|
| 708 |
+
4,
|
| 709 |
+
7
|
| 710 |
+
],
|
| 711 |
+
[
|
| 712 |
+
5,
|
| 713 |
+
1
|
| 714 |
+
],
|
| 715 |
+
[
|
| 716 |
+
5,
|
| 717 |
+
7
|
| 718 |
+
],
|
| 719 |
+
[
|
| 720 |
+
1,
|
| 721 |
+
7
|
| 722 |
+
],
|
| 723 |
+
[
|
| 724 |
+
2,
|
| 725 |
+
8
|
| 726 |
+
],
|
| 727 |
+
[
|
| 728 |
+
0,
|
| 729 |
+
0
|
| 730 |
+
],
|
| 731 |
+
[
|
| 732 |
+
2,
|
| 733 |
+
9
|
| 734 |
+
],
|
| 735 |
+
[
|
| 736 |
+
5,
|
| 737 |
+
0
|
| 738 |
+
],
|
| 739 |
+
[
|
| 740 |
+
0,
|
| 741 |
+
8
|
| 742 |
+
]
|
| 743 |
+
]
|
| 744 |
+
},
|
| 745 |
+
{
|
| 746 |
+
"input": [
|
| 747 |
+
[
|
| 748 |
+
[
|
| 749 |
+
0,
|
| 750 |
+
0,
|
| 751 |
+
11,
|
| 752 |
+
0,
|
| 753 |
+
0,
|
| 754 |
+
23,
|
| 755 |
+
0,
|
| 756 |
+
0,
|
| 757 |
+
44,
|
| 758 |
+
18
|
| 759 |
+
]
|
| 760 |
+
],
|
| 761 |
+
[
|
| 762 |
+
48,
|
| 763 |
+
92
|
| 764 |
+
],
|
| 765 |
+
[
|
| 766 |
+
0,
|
| 767 |
+
5
|
| 768 |
+
],
|
| 769 |
+
4
|
| 770 |
+
],
|
| 771 |
+
"output": []
|
| 772 |
+
},
|
| 773 |
+
{
|
| 774 |
+
"input": [
|
| 775 |
+
[
|
| 776 |
+
[
|
| 777 |
+
0,
|
| 778 |
+
32,
|
| 779 |
+
44,
|
| 780 |
+
51,
|
| 781 |
+
2,
|
| 782 |
+
98
|
| 783 |
+
]
|
| 784 |
+
],
|
| 785 |
+
[
|
| 786 |
+
43,
|
| 787 |
+
52
|
| 788 |
+
],
|
| 789 |
+
[
|
| 790 |
+
0,
|
| 791 |
+
5
|
| 792 |
+
],
|
| 793 |
+
2
|
| 794 |
+
],
|
| 795 |
+
"output": [
|
| 796 |
+
[
|
| 797 |
+
0,
|
| 798 |
+
3
|
| 799 |
+
],
|
| 800 |
+
[
|
| 801 |
+
0,
|
| 802 |
+
2
|
| 803 |
+
]
|
| 804 |
+
]
|
| 805 |
+
},
|
| 806 |
+
{
|
| 807 |
+
"input": [
|
| 808 |
+
[
|
| 809 |
+
[
|
| 810 |
+
0,
|
| 811 |
+
0,
|
| 812 |
+
48,
|
| 813 |
+
33,
|
| 814 |
+
7,
|
| 815 |
+
3
|
| 816 |
+
],
|
| 817 |
+
[
|
| 818 |
+
99,
|
| 819 |
+
0,
|
| 820 |
+
0,
|
| 821 |
+
71,
|
| 822 |
+
1,
|
| 823 |
+
0
|
| 824 |
+
],
|
| 825 |
+
[
|
| 826 |
+
0,
|
| 827 |
+
0,
|
| 828 |
+
10,
|
| 829 |
+
0,
|
| 830 |
+
0,
|
| 831 |
+
87
|
| 832 |
+
],
|
| 833 |
+
[
|
| 834 |
+
89,
|
| 835 |
+
69,
|
| 836 |
+
66,
|
| 837 |
+
20,
|
| 838 |
+
72,
|
| 839 |
+
35
|
| 840 |
+
],
|
| 841 |
+
[
|
| 842 |
+
15,
|
| 843 |
+
0,
|
| 844 |
+
100,
|
| 845 |
+
0,
|
| 846 |
+
88,
|
| 847 |
+
31
|
| 848 |
+
],
|
| 849 |
+
[
|
| 850 |
+
38,
|
| 851 |
+
0,
|
| 852 |
+
68,
|
| 853 |
+
73,
|
| 854 |
+
14,
|
| 855 |
+
32
|
| 856 |
+
],
|
| 857 |
+
[
|
| 858 |
+
99,
|
| 859 |
+
27,
|
| 860 |
+
86,
|
| 861 |
+
71,
|
| 862 |
+
98,
|
| 863 |
+
86
|
| 864 |
+
],
|
| 865 |
+
[
|
| 866 |
+
49,
|
| 867 |
+
60,
|
| 868 |
+
21,
|
| 869 |
+
81,
|
| 870 |
+
3,
|
| 871 |
+
95
|
| 872 |
+
],
|
| 873 |
+
[
|
| 874 |
+
62,
|
| 875 |
+
0,
|
| 876 |
+
0,
|
| 877 |
+
0,
|
| 878 |
+
97,
|
| 879 |
+
65
|
| 880 |
+
],
|
| 881 |
+
[
|
| 882 |
+
89,
|
| 883 |
+
69,
|
| 884 |
+
33,
|
| 885 |
+
6,
|
| 886 |
+
92,
|
| 887 |
+
80
|
| 888 |
+
]
|
| 889 |
+
],
|
| 890 |
+
[
|
| 891 |
+
5,
|
| 892 |
+
12
|
| 893 |
+
],
|
| 894 |
+
[
|
| 895 |
+
7,
|
| 896 |
+
3
|
| 897 |
+
],
|
| 898 |
+
57
|
| 899 |
+
],
|
| 900 |
+
"output": [
|
| 901 |
+
[
|
| 902 |
+
9,
|
| 903 |
+
3
|
| 904 |
+
],
|
| 905 |
+
[
|
| 906 |
+
2,
|
| 907 |
+
2
|
| 908 |
+
]
|
| 909 |
+
]
|
| 910 |
+
}
|
| 911 |
+
],
|
| 912 |
+
"haskell_template": "highestRankedKItems :: [[Int]] -> [Int] -> [Int] -> Int -> [[Int]]\nhighestRankedKItems grid pricing start k ",
|
| 913 |
+
"ocaml_template": "let highestRankedKItems (grid: int list list) (pricing: int list) (start: int list) (k: int) : int list list = ",
|
| 914 |
+
"scala_template": "def highestRankedKItems(grid: List[List[Int]],pricing: List[Int],start: List[Int],k: Int): List[List[Int]] = { \n \n}",
|
| 915 |
+
"java_template": "public static List<List<Integer>> highestRankedKItems(List<List<Integer>> grid, List<Integer> pricing, List<Integer> start, int k) {\n\n}",
|
| 916 |
+
"python_template": "class Solution(object):\n def highestRankedKItems(self, grid, pricing, start, k):\n \"\"\"\n :type grid: List[List[int]]\n :type pricing: List[int]\n :type start: List[int]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"\n "
|
| 917 |
+
}
|
k_highest_ranked_items_within_a_price_range/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;1];[1;1];[2;1]] (highestRankedKItems [[1;2;0;1];[1;3;0;1];[0;2;5;1]] [2;5] [0;0] 3)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal [[2;1];[1;2]] (highestRankedKItems [[1;2;0;1];[1;3;3;1];[0;2;5;1]] [2;3] [2;3] 2)
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal [[2;1];[2;0]] (highestRankedKItems [[1;1;1];[0;0;1];[2;3;4]] [2;3] [0;0] 3)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
(* Grouping test cases *)
|
| 19 |
+
let suite = "Test Suite for highestRankedKItems" >::: [
|
| 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
|
k_highest_ranked_items_within_a_price_range/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.highestRankedKItems(List(List(1,2,0,1),List(1,3,0,1),List(0,2,5,1)),List(2,5),List(0,0),3), List(List(0,1),List(1,1),List(2,1)))
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.highestRankedKItems(List(List(1,2,0,1),List(1,3,3,1),List(0,2,5,1)),List(2,3),List(2,3),2), List(List(2,1),List(1,2)))
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.highestRankedKItems(List(List(1,1,1),List(0,0,1),List(2,3,4)),List(2,3),List(0,0),3), List(List(2,1),List(2,0)))
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
}
|
k_items_with_the_maximum_sum/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
k_items_with_the_maximum_sum/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 (kItemsWithMaximumSum 3 2 0 2)," 2 (kItemsWithMaximumSum 3 2 0 2))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (kItemsWithMaximumSum 3 2 0 4)," 3 (kItemsWithMaximumSum 3 2 0 4))
|
| 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
|
k_items_with_the_maximum_sum/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, kItemsWithMaximumSum(3, 2, 0, 2));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(3, kItemsWithMaximumSum(3, 2, 0, 4));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
k_items_with_the_maximum_sum/meta.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2715,
|
| 3 |
+
"name": "k_items_with_the_maximum_sum",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/k-items-with-the-maximum-sum/",
|
| 6 |
+
"date": "1679184000000",
|
| 7 |
+
"task_description": "There is a bag that consists of items, each item has a number `1`, `0`, or `-1` written on it. You are given four **non-negative **integers `numOnes`, `numZeros`, `numNegOnes`, and `k`. The bag initially contains: `numOnes` items with `1`s written on them. `numZeroes` items with `0`s written on them. `numNegOnes` items with `-1`s written on them. We want to pick exactly `k` items among the available items. Return _the **maximum** possible sum of numbers written on the items_. **Example 1:** ``` **Input:** numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2 **Output:** 2 **Explanation:** We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 2 items with 1 written on them and get a sum in a total of 2. It can be proven that 2 is the maximum possible sum. ``` **Example 2:** ``` **Input:** numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4 **Output:** 3 **Explanation:** We have a bag of items with numbers written on them {1, 1, 1, 0, 0}. We take 3 items with 1 written on them, and 1 item with 0 written on it, and get a sum in a total of 3. It can be proven that 3 is the maximum possible sum. ``` **Constraints:** `0 <= numOnes, numZeros, numNegOnes <= 50` `0 <= k <= numOnes + numZeros + numNegOnes`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2",
|
| 12 |
+
"output": "2 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4",
|
| 17 |
+
"output": "3 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
31,
|
| 24 |
+
26,
|
| 25 |
+
16,
|
| 26 |
+
7
|
| 27 |
+
],
|
| 28 |
+
"output": 7
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"input": [
|
| 32 |
+
11,
|
| 33 |
+
42,
|
| 34 |
+
34,
|
| 35 |
+
77
|
| 36 |
+
],
|
| 37 |
+
"output": -13
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"input": [
|
| 41 |
+
23,
|
| 42 |
+
23,
|
| 43 |
+
3,
|
| 44 |
+
22
|
| 45 |
+
],
|
| 46 |
+
"output": 22
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"input": [
|
| 50 |
+
46,
|
| 51 |
+
32,
|
| 52 |
+
24,
|
| 53 |
+
85
|
| 54 |
+
],
|
| 55 |
+
"output": 39
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"input": [
|
| 59 |
+
36,
|
| 60 |
+
38,
|
| 61 |
+
14,
|
| 62 |
+
7
|
| 63 |
+
],
|
| 64 |
+
"output": 7
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"input": [
|
| 68 |
+
18,
|
| 69 |
+
18,
|
| 70 |
+
33,
|
| 71 |
+
10
|
| 72 |
+
],
|
| 73 |
+
"output": 10
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"input": [
|
| 77 |
+
41,
|
| 78 |
+
10,
|
| 79 |
+
33,
|
| 80 |
+
55
|
| 81 |
+
],
|
| 82 |
+
"output": 37
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"input": [
|
| 86 |
+
18,
|
| 87 |
+
22,
|
| 88 |
+
13,
|
| 89 |
+
3
|
| 90 |
+
],
|
| 91 |
+
"output": 3
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"input": [
|
| 95 |
+
44,
|
| 96 |
+
43,
|
| 97 |
+
32,
|
| 98 |
+
119
|
| 99 |
+
],
|
| 100 |
+
"output": 12
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"input": [
|
| 104 |
+
33,
|
| 105 |
+
35,
|
| 106 |
+
20,
|
| 107 |
+
26
|
| 108 |
+
],
|
| 109 |
+
"output": 26
|
| 110 |
+
}
|
| 111 |
+
],
|
| 112 |
+
"haskell_template": "kItemsWithMaximumSum :: Int -> Int -> Int -> Int -> Int\nkItemsWithMaximumSum numOnes numZeros numNegOnes k ",
|
| 113 |
+
"ocaml_template": "let kItemsWithMaximumSum (numOnes: int) (numZeros: int) (numNegOnes: int) (k: int) : int = ",
|
| 114 |
+
"scala_template": "def kItemsWithMaximumSum(numOnes: Int,numZeros: Int,numNegOnes: Int,k: Int): Int = { \n \n}",
|
| 115 |
+
"java_template": "public static int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) {\n\n}",
|
| 116 |
+
"python_template": "class Solution(object):\n def kItemsWithMaximumSum(self, numOnes, numZeros, numNegOnes, k):\n \"\"\"\n :type numOnes: int\n :type numZeros: int\n :type numNegOnes: int\n :type k: int\n :rtype: int\n \"\"\"\n "
|
| 117 |
+
}
|
k_items_with_the_maximum_sum/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 (kItemsWithMaximumSum 3 2 0 2)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 3 (kItemsWithMaximumSum 3 2 0 4)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for kItemsWithMaximumSum" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
k_items_with_the_maximum_sum/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.kItemsWithMaximumSum(3,2,0,2), 2)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.kItemsWithMaximumSum(3,2,0,4), 3)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|