01f8c30643da4e616b39828bdd070cc9851cf24934ec52fcd98787d2c1446c33
Browse files- buy_two_chocolates/scala_tests/MySuite.scala +40 -0
- calculate_delayed_arrival_time/.DS_Store +0 -0
- calculate_delayed_arrival_time/haskell_tests/Main.hs +24 -0
- calculate_delayed_arrival_time/java_tests/Main.java +21 -0
- calculate_delayed_arrival_time/meta.json +97 -0
- calculate_delayed_arrival_time/ocaml_tests/main.ml +26 -0
- calculate_delayed_arrival_time/scala_tests/MySuite.scala +12 -0
- calculate_digit_sum_of_a_string/haskell_tests/Main.hs +45 -0
- calculate_digit_sum_of_a_string/java_tests/Main.java +21 -0
- calculate_digit_sum_of_a_string/meta.json +97 -0
- calculate_digit_sum_of_a_string/ocaml_tests/main.ml +50 -0
- calculate_digit_sum_of_a_string/scala_tests/MySuite.scala +44 -0
- categorize_box_according_to_criteria/haskell_tests/Main.hs +45 -0
- categorize_box_according_to_criteria/java_tests/Main.java +21 -0
- categorize_box_according_to_criteria/meta.json +117 -0
- categorize_box_according_to_criteria/ocaml_tests/main.ml +50 -0
- categorize_box_according_to_criteria/scala_tests/MySuite.scala +44 -0
- cells_in_a_range_on_an_excel_sheet/.DS_Store +0 -0
- cells_in_a_range_on_an_excel_sheet/haskell_tests/Main.hs +24 -0
- cells_in_a_range_on_an_excel_sheet/java_tests/Main.java +21 -0
- cells_in_a_range_on_an_excel_sheet/meta.json +201 -0
- cells_in_a_range_on_an_excel_sheet/ocaml_tests/main.ml +26 -0
- cells_in_a_range_on_an_excel_sheet/scala_tests/MySuite.scala +12 -0
- check_distances_between_same_letters/.DS_Store +0 -0
- check_distances_between_same_letters/haskell_tests/Main.hs +24 -0
- check_distances_between_same_letters/java_tests/Main.java +21 -0
- check_distances_between_same_letters/meta.json +367 -0
- check_distances_between_same_letters/ocaml_tests/main.ml +26 -0
- check_distances_between_same_letters/scala_tests/MySuite.scala +12 -0
- check_if_all_as_appears_before_all_bs/.DS_Store +0 -0
- check_if_all_as_appears_before_all_bs/haskell_tests/Main.hs +27 -0
- check_if_all_as_appears_before_all_bs/java_tests/Main.java +25 -0
- check_if_all_as_appears_before_all_bs/meta.json +72 -0
- check_if_all_as_appears_before_all_bs/ocaml_tests/main.ml +29 -0
- check_if_all_as_appears_before_all_bs/scala_tests/MySuite.scala +16 -0
- check_if_array_is_good/.DS_Store +0 -0
- check_if_array_is_good/haskell_tests/Main.hs +30 -0
- check_if_array_is_good/java_tests/Main.java +29 -0
- check_if_array_is_good/meta.json +577 -0
- check_if_array_is_good/ocaml_tests/main.ml +32 -0
- check_if_array_is_good/scala_tests/MySuite.scala +20 -0
- check_if_bitwise_or_has_trailing_zeros/haskell_tests/Main.hs +44 -0
- check_if_bitwise_or_has_trailing_zeros/java_tests/Main.java +24 -0
- check_if_bitwise_or_has_trailing_zeros/meta.json +260 -0
- check_if_bitwise_or_has_trailing_zeros/ocaml_tests/main.ml +45 -0
- check_if_bitwise_or_has_trailing_zeros/scala_tests/MySuite.scala +36 -0
- check_if_dfs_strings_are_palindromes/java_tests/Main.java +21 -0
- check_if_digits_are_equal_in_string_after_operations_i/haskell_tests/Main.hs +41 -0
- check_if_digits_are_equal_in_string_after_operations_i/java_tests/Main.java +20 -0
- check_if_digits_are_equal_in_string_after_operations_i/meta.json +47 -0
buy_two_chocolates/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.buyChoco(List(1,2,2),3), 0)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.buyChoco(List(3,2,3),3), 3)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.buyChoco(List(61, 75, 67),77), 77)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.buyChoco(List(81, 8, 10, 44, 100, 38, 7, 47),64), 49)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.buyChoco(List(19, 6, 24, 7, 94, 40, 97, 60, 82, 62, 53, 12, 8, 56, 42, 48, 85, 76, 34, 29, 57, 28, 17, 31, 36, 3, 90, 92, 78, 64, 80, 84, 50, 39, 73, 86, 41, 11, 95, 88, 37, 1, 27),2), 2)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.buyChoco(List(60, 32, 4, 35, 36, 45),38), 2)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.buyChoco(List(51, 80, 78, 44, 72, 50, 74, 81, 30, 63, 58, 43, 16, 65, 39, 66, 96, 42, 31, 17, 15, 92, 25, 75, 6, 33, 45, 14),7), 7)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("test8") {
|
| 33 |
+
assertEquals(Main.buyChoco(List(14, 55, 19, 73, 75, 69, 88, 18, 28, 22, 2, 72, 29, 5, 17, 64, 68, 60, 3, 96, 95, 47, 7, 53, 78, 70, 21, 84, 46, 27, 38),37), 32)
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
test("test9") {
|
| 37 |
+
assertEquals(Main.buyChoco(List(51, 50, 22, 39, 21, 23, 99, 97, 66, 41, 3, 79, 89, 91, 31, 35, 14, 5, 11, 71, 38, 82, 7, 84, 48, 30, 28, 90, 58, 60, 94, 53, 9, 87, 47, 72, 74, 75, 25, 43, 4, 57, 86),41), 34)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
}
|
calculate_delayed_arrival_time/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
calculate_delayed_arrival_time/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 (findDelayedArrivalTime 15 5)," 20 (findDelayedArrivalTime 15 5))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (findDelayedArrivalTime 13 11)," 0 (findDelayedArrivalTime 13 11))
|
| 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
|
calculate_delayed_arrival_time/java_tests/Main.java
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import static org.junit.jupiter.api.Assertions.*;
|
| 3 |
+
import org.junit.jupiter.api.Test;
|
| 4 |
+
import java.util.List;
|
| 5 |
+
import java.util.Arrays;
|
| 6 |
+
import java.util.ArrayList;
|
| 7 |
+
public class Main {
|
| 8 |
+
//Program start
|
| 9 |
+
|
| 10 |
+
//Program end
|
| 11 |
+
|
| 12 |
+
@Test
|
| 13 |
+
public void test1() {
|
| 14 |
+
assertEquals(20, findDelayedArrivalTime(15, 5));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(0, findDelayedArrivalTime(13, 11));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
calculate_delayed_arrival_time/meta.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2748,
|
| 3 |
+
"name": "calculate_delayed_arrival_time",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/calculate-delayed-arrival-time/",
|
| 6 |
+
"date": "1681603200000",
|
| 7 |
+
"task_description": "You are given a positive integer `arrivalTime` denoting the arrival time of a train in hours, and another positive integer `delayedTime` denoting the amount of delay in hours. Return _the time when the train will arrive at the station._ Note that the time in this problem is in 24-hours format. **Example 1:** ``` **Input:** arrivalTime = 15, delayedTime = 5 **Output:** 20 **Explanation:** Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours). ``` **Example 2:** ``` **Input:** arrivalTime = 13, delayedTime = 11 **Output:** 0 **Explanation:** Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0). ``` **Constraints:** `1 <= arrivaltime < 24` `1 <= delayedTime <= 24`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "arrivalTime = 15, delayedTime = 5",
|
| 12 |
+
"output": "20 "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "arrivalTime = 13, delayedTime = 11",
|
| 17 |
+
"output": "0 "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
18,
|
| 24 |
+
19
|
| 25 |
+
],
|
| 26 |
+
"output": 13
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"input": [
|
| 30 |
+
10,
|
| 31 |
+
12
|
| 32 |
+
],
|
| 33 |
+
"output": 22
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"input": [
|
| 37 |
+
9,
|
| 38 |
+
23
|
| 39 |
+
],
|
| 40 |
+
"output": 8
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"input": [
|
| 44 |
+
6,
|
| 45 |
+
3
|
| 46 |
+
],
|
| 47 |
+
"output": 9
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"input": [
|
| 51 |
+
3,
|
| 52 |
+
21
|
| 53 |
+
],
|
| 54 |
+
"output": 0
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"input": [
|
| 58 |
+
5,
|
| 59 |
+
13
|
| 60 |
+
],
|
| 61 |
+
"output": 18
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"input": [
|
| 65 |
+
11,
|
| 66 |
+
1
|
| 67 |
+
],
|
| 68 |
+
"output": 12
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"input": [
|
| 72 |
+
13,
|
| 73 |
+
11
|
| 74 |
+
],
|
| 75 |
+
"output": 0
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"input": [
|
| 79 |
+
5,
|
| 80 |
+
2
|
| 81 |
+
],
|
| 82 |
+
"output": 7
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"input": [
|
| 86 |
+
12,
|
| 87 |
+
5
|
| 88 |
+
],
|
| 89 |
+
"output": 17
|
| 90 |
+
}
|
| 91 |
+
],
|
| 92 |
+
"haskell_template": "findDelayedArrivalTime :: Int -> Int -> Int\nfindDelayedArrivalTime arrivalTime delayedTime ",
|
| 93 |
+
"ocaml_template": "let findDelayedArrivalTime (arrivalTime: int) (delayedTime: int) : int = ",
|
| 94 |
+
"scala_template": "def findDelayedArrivalTime(arrivalTime: Int,delayedTime: Int): Int = { \n \n}",
|
| 95 |
+
"java_template": "public static int findDelayedArrivalTime(int arrivalTime, int delayedTime) {\n\n}",
|
| 96 |
+
"python_template": "class Solution(object):\n def findDelayedArrivalTime(self, arrivalTime, delayedTime):\n \"\"\"\n :type arrivalTime: int\n :type delayedTime: int\n :rtype: int\n \"\"\"\n "
|
| 97 |
+
}
|
calculate_delayed_arrival_time/ocaml_tests/main.ml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main = struct
|
| 3 |
+
open OUnit2
|
| 4 |
+
|
| 5 |
+
(* Program start *)
|
| 6 |
+
|
| 7 |
+
(* Program end *)
|
| 8 |
+
|
| 9 |
+
(* Test cases *)
|
| 10 |
+
|
| 11 |
+
let test1 _ = assert_equal 20 (findDelayedArrivalTime 15 5)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal 0 (findDelayedArrivalTime 13 11)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for findDelayedArrivalTime" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
calculate_delayed_arrival_time/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.findDelayedArrivalTime(15,5), 20)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.findDelayedArrivalTime(13,11), 0)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
calculate_digit_sum_of_a_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 (digitSum \"11111222223 \" 3)," "135" (digitSum "11111222223" 3))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (digitSum \"00000000 \" 3)," "000" (digitSum "00000000" 3))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (digitSum \"0 \" 2)," "0" (digitSum "0" 2))
|
| 19 |
+
|
| 20 |
+
test4 :: Test
|
| 21 |
+
test4 = TestCase (assertEqual "for (digitSum \"6421145198777362190042394610980120758216614468524308044135603727111584866360410865574469873746173533 \" 2)," "59" (digitSum "6421145198777362190042394610980120758216614468524308044135603727111584866360410865574469873746173533" 2))
|
| 22 |
+
|
| 23 |
+
test5 :: Test
|
| 24 |
+
test5 = TestCase (assertEqual "for (digitSum \"6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859 \" 100)," "6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859" (digitSum "6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859" 100))
|
| 25 |
+
|
| 26 |
+
test6 :: Test
|
| 27 |
+
test6 = TestCase (assertEqual "for (digitSum \"86835675433222437140367269363341651026820150582311446699662136 \" 12)," "60414742559" (digitSum "86835675433222437140367269363341651026820150582311446699662136" 12))
|
| 28 |
+
|
| 29 |
+
test7 :: Test
|
| 30 |
+
test7 = TestCase (assertEqual "for (digitSum \"09556959624863822113055328888211114768861024488160715110957533476207255541787 \" 52)," "228109" (digitSum "09556959624863822113055328888211114768861024488160715110957533476207255541787" 52))
|
| 31 |
+
|
| 32 |
+
test8 :: Test
|
| 33 |
+
test8 = TestCase (assertEqual "for (digitSum \"33628763334261975447998353546830413109540456 \" 40)," "18315" (digitSum "33628763334261975447998353546830413109540456" 40))
|
| 34 |
+
|
| 35 |
+
test9 :: Test
|
| 36 |
+
test9 = TestCase (assertEqual "for (digitSum \"4261628821970427731371304870116953 \" 26)," "10632" (digitSum "4261628821970427731371304870116953" 26))
|
| 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
|
calculate_digit_sum_of_a_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("3", digitSum("11111222223", 3));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals("3", digitSum("00000000", 3));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
calculate_digit_sum_of_a_string/meta.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2361,
|
| 3 |
+
"name": "calculate_digit_sum_of_a_string",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/calculate-digit-sum-of-a-string/",
|
| 6 |
+
"date": "2022-04-10 00:00:00",
|
| 7 |
+
"task_description": "You are given a string `s` consisting of digits and an integer `k`. A **round** can be completed if the length of `s` is greater than `k`. In one round, do the following: **Divide** `s` into **consecutive groups** of size `k` such that the first `k` characters are in the first group, the next `k` characters are in the second group, and so on. **Note** that the size of the last group can be smaller than `k`. **Replace** each group of `s` with a string representing the sum of all its digits. For example, `\"346\"` is replaced with `\"13\"` because `3 + 4 + 6 = 13`. **Merge** consecutive groups together to form a new string. If the length of the string is greater than `k`, repeat from step `1`. Return `s` _after all rounds have been completed_. **Example 1:** ``` **Input:** s = \"11111222223\", k = 3 **Output:** \"135\" **Explanation:** - For the first round, we divide s into groups of size 3: \"111\", \"112\", \"222\", and \"23\". Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. So, s becomes \"3\" + \"4\" + \"6\" + \"5\" = \"3465\" after the first round. - For the second round, we divide s into \"346\" and \"5\". Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. So, s becomes \"13\" + \"5\" = \"135\" after second round. Now, s.length <= k, so we return \"135\" as the answer. ``` **Example 2:** ``` **Input:** s = \"00000000\", k = 3 **Output:** \"000\" **Explanation:** We divide s into \"000\", \"000\", and \"00\". Then we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. s becomes \"0\" + \"0\" + \"0\" = \"000\", whose length is equal to k, so we return \"000\". ``` **Constraints:** `1 <= s.length <= 100` `2 <= k <= 100` `s` consists of digits only.",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"11111222223\", k = 3",
|
| 12 |
+
"output": "\"135\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"00000000\", k = 3",
|
| 17 |
+
"output": "\"000\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
"\"0\"",
|
| 24 |
+
2
|
| 25 |
+
],
|
| 26 |
+
"output": "0"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"input": [
|
| 30 |
+
"\"6421145198777362190042394610980120758216614468524308044135603727111584866360410865574469873746173533\"",
|
| 31 |
+
2
|
| 32 |
+
],
|
| 33 |
+
"output": "59"
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"input": [
|
| 37 |
+
"\"6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859\"",
|
| 38 |
+
100
|
| 39 |
+
],
|
| 40 |
+
"output": "6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859"
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"input": [
|
| 44 |
+
"\"86835675433222437140367269363341651026820150582311446699662136\"",
|
| 45 |
+
12
|
| 46 |
+
],
|
| 47 |
+
"output": "60414742559"
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"input": [
|
| 51 |
+
"\"09556959624863822113055328888211114768861024488160715110957533476207255541787\"",
|
| 52 |
+
52
|
| 53 |
+
],
|
| 54 |
+
"output": "228109"
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"input": [
|
| 58 |
+
"\"33628763334261975447998353546830413109540456\"",
|
| 59 |
+
40
|
| 60 |
+
],
|
| 61 |
+
"output": "18315"
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"input": [
|
| 65 |
+
"\"4261628821970427731371304870116953\"",
|
| 66 |
+
26
|
| 67 |
+
],
|
| 68 |
+
"output": "10632"
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"input": [
|
| 72 |
+
"\"6260198388\"",
|
| 73 |
+
7
|
| 74 |
+
],
|
| 75 |
+
"output": "3219"
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"input": [
|
| 79 |
+
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
| 80 |
+
30
|
| 81 |
+
],
|
| 82 |
+
"output": "000"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"input": [
|
| 86 |
+
"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
|
| 87 |
+
100
|
| 88 |
+
],
|
| 89 |
+
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
|
| 90 |
+
}
|
| 91 |
+
],
|
| 92 |
+
"haskell_template": "digitSum :: String -> Int -> String\ndigitSum s k ",
|
| 93 |
+
"ocaml_template": "let digitSum (s: string) (k: int) : string = ",
|
| 94 |
+
"scala_template": "def digitSum(s: String,k: Int): String = { \n \n}",
|
| 95 |
+
"java_template": "class Solution {\n public String digitSum(String s, int k) {\n \n }\n}",
|
| 96 |
+
"python_template": "class Solution(object):\n def digitSum(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: str\n \"\"\"\n "
|
| 97 |
+
}
|
calculate_digit_sum_of_a_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 "135" (digitSum "11111222223" 3)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal "000" (digitSum "00000000" 3)
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal "0" (digitSum "0" 2)
|
| 16 |
+
|
| 17 |
+
let test4 _ = assert_equal "59" (digitSum "6421145198777362190042394610980120758216614468524308044135603727111584866360410865574469873746173533" 2)
|
| 18 |
+
|
| 19 |
+
let test5 _ = assert_equal "6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859" (digitSum "6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859" 100)
|
| 20 |
+
|
| 21 |
+
let test6 _ = assert_equal "60414742559" (digitSum "86835675433222437140367269363341651026820150582311446699662136" 12)
|
| 22 |
+
|
| 23 |
+
let test7 _ = assert_equal "228109" (digitSum "09556959624863822113055328888211114768861024488160715110957533476207255541787" 52)
|
| 24 |
+
|
| 25 |
+
let test8 _ = assert_equal "18315" (digitSum "33628763334261975447998353546830413109540456" 40)
|
| 26 |
+
|
| 27 |
+
let test9 _ = assert_equal "10632" (digitSum "4261628821970427731371304870116953" 26)
|
| 28 |
+
|
| 29 |
+
let test10 _ = assert_equal "3219" (digitSum "6260198388" 7)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
(* Grouping test cases *)
|
| 33 |
+
let suite = "Test Suite for digitSum" >::: [
|
| 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
|
calculate_digit_sum_of_a_string/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.digitSum("11111222223",3), "135")
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.digitSum("00000000",3), "000")
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.digitSum("0",2), "0")
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.digitSum("6421145198777362190042394610980120758216614468524308044135603727111584866360410865574469873746173533",2), "59")
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.digitSum("6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859",100), "6828549665923521139586766197204369524222360091033439842730341293447277906510091763414462467630345859")
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.digitSum("86835675433222437140367269363341651026820150582311446699662136",12), "60414742559")
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.digitSum("09556959624863822113055328888211114768861024488160715110957533476207255541787",52), "228109")
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("test8") {
|
| 33 |
+
assertEquals(Main.digitSum("33628763334261975447998353546830413109540456",40), "18315")
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
test("test9") {
|
| 37 |
+
assertEquals(Main.digitSum("4261628821970427731371304870116953",26), "10632")
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
test("test10") {
|
| 41 |
+
assertEquals(Main.digitSum("6260198388",7), "3219")
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
categorize_box_according_to_criteria/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 (categorizeBox 1000 35 700 300)," "Heavy" (categorizeBox 1000 35 700 300))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (categorizeBox 200 50 800 50)," "Neither" (categorizeBox 200 50 800 50))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (categorizeBox 73 46 67 57)," "Neither" (categorizeBox 73 46 67 57))
|
| 19 |
+
|
| 20 |
+
test4 :: Test
|
| 21 |
+
test4 = TestCase (assertEqual "for (categorizeBox 50 82 13 85)," "Neither" (categorizeBox 50 82 13 85))
|
| 22 |
+
|
| 23 |
+
test5 :: Test
|
| 24 |
+
test5 = TestCase (assertEqual "for (categorizeBox 46 40 34 60)," "Neither" (categorizeBox 46 40 34 60))
|
| 25 |
+
|
| 26 |
+
test6 :: Test
|
| 27 |
+
test6 = TestCase (assertEqual "for (categorizeBox 43 11 66 39)," "Neither" (categorizeBox 43 11 66 39))
|
| 28 |
+
|
| 29 |
+
test7 :: Test
|
| 30 |
+
test7 = TestCase (assertEqual "for (categorizeBox 87 4 22 50)," "Neither" (categorizeBox 87 4 22 50))
|
| 31 |
+
|
| 32 |
+
test8 :: Test
|
| 33 |
+
test8 = TestCase (assertEqual "for (categorizeBox 59 91 54 65)," "Neither" (categorizeBox 59 91 54 65))
|
| 34 |
+
|
| 35 |
+
test9 :: Test
|
| 36 |
+
test9 = TestCase (assertEqual "for (categorizeBox 59 22 102 48)," "Neither" (categorizeBox 59 22 102 48))
|
| 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
|
categorize_box_according_to_criteria/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("300", categorizeBox(1000, 35, 700, 300));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals("50", categorizeBox(200, 50, 800, 50));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
categorize_box_according_to_criteria/meta.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2619,
|
| 3 |
+
"name": "categorize_box_according_to_criteria",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/categorize-box-according-to-criteria/",
|
| 6 |
+
"date": "2022-12-24 00:00:00",
|
| 7 |
+
"task_description": "Given four integers `length`, `width`, `height`, and `mass`, representing the dimensions and mass of a box, respectively, return _a string representing the **category** of the box_. The box is `\"Bulky\"` if: **Any** of the dimensions of the box is greater or equal to `104`. Or, the **volume** of the box is greater or equal to `109`. If the mass of the box is greater or equal to `100`, it is `\"Heavy\".` If the box is both `\"Bulky\"` and `\"Heavy\"`, then its category is `\"Both\"`. If the box is neither `\"Bulky\"` nor `\"Heavy\"`, then its category is `\"Neither\"`. If the box is `\"Bulky\"` but not `\"Heavy\"`, then its category is `\"Bulky\"`. If the box is `\"Heavy\"` but not `\"Bulky\"`, then its category is `\"Heavy\"`. **Note** that the volume of the box is the product of its length, width and height. **Example 1:** ``` **Input:** length = 1000, width = 35, height = 700, mass = 300 **Output:** \"Heavy\" **Explanation:** None of the dimensions of the box is greater or equal to 104. Its volume = 24500000 <= 109. So it cannot be categorized as \"Bulky\". However mass >= 100, so the box is \"Heavy\". Since the box is not \"Bulky\" but \"Heavy\", we return \"Heavy\". ``` **Example 2:** ``` **Input:** length = 200, width = 50, height = 800, mass = 50 **Output:** \"Neither\" **Explanation:** None of the dimensions of the box is greater or equal to 104. Its volume = 8 * 106 <= 109. So it cannot be categorized as \"Bulky\". Its mass is also less than 100, so it cannot be categorized as \"Heavy\" either. Since its neither of the two above categories, we return \"Neither\". ``` **Constraints:** `1 <= length, width, height <= 105` `1 <= mass <= 103`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "length = 1000, width = 35, height = 700, mass = 300",
|
| 12 |
+
"output": "\"Heavy\" "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "length = 200, width = 50, height = 800, mass = 50",
|
| 17 |
+
"output": "\"Neither\" "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
73,
|
| 24 |
+
46,
|
| 25 |
+
67,
|
| 26 |
+
57
|
| 27 |
+
],
|
| 28 |
+
"output": "Neither"
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"input": [
|
| 32 |
+
50,
|
| 33 |
+
82,
|
| 34 |
+
13,
|
| 35 |
+
85
|
| 36 |
+
],
|
| 37 |
+
"output": "Neither"
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"input": [
|
| 41 |
+
46,
|
| 42 |
+
40,
|
| 43 |
+
34,
|
| 44 |
+
60
|
| 45 |
+
],
|
| 46 |
+
"output": "Neither"
|
| 47 |
+
},
|
| 48 |
+
{
|
| 49 |
+
"input": [
|
| 50 |
+
43,
|
| 51 |
+
11,
|
| 52 |
+
66,
|
| 53 |
+
39
|
| 54 |
+
],
|
| 55 |
+
"output": "Neither"
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"input": [
|
| 59 |
+
87,
|
| 60 |
+
4,
|
| 61 |
+
22,
|
| 62 |
+
50
|
| 63 |
+
],
|
| 64 |
+
"output": "Neither"
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"input": [
|
| 68 |
+
59,
|
| 69 |
+
91,
|
| 70 |
+
54,
|
| 71 |
+
65
|
| 72 |
+
],
|
| 73 |
+
"output": "Neither"
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"input": [
|
| 77 |
+
59,
|
| 78 |
+
22,
|
| 79 |
+
102,
|
| 80 |
+
48
|
| 81 |
+
],
|
| 82 |
+
"output": "Neither"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"input": [
|
| 86 |
+
93,
|
| 87 |
+
5,
|
| 88 |
+
88,
|
| 89 |
+
56
|
| 90 |
+
],
|
| 91 |
+
"output": "Neither"
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"input": [
|
| 95 |
+
95,
|
| 96 |
+
9,
|
| 97 |
+
22,
|
| 98 |
+
99
|
| 99 |
+
],
|
| 100 |
+
"output": "Neither"
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"input": [
|
| 104 |
+
104,
|
| 105 |
+
78,
|
| 106 |
+
28,
|
| 107 |
+
8
|
| 108 |
+
],
|
| 109 |
+
"output": "Neither"
|
| 110 |
+
}
|
| 111 |
+
],
|
| 112 |
+
"haskell_template": "categorizeBox :: Int -> Int -> Int -> Int -> String\ncategorizeBox length width height mass ",
|
| 113 |
+
"ocaml_template": "let categorizeBox (length: int) (width: int) (height: int) (mass: int) : string = ",
|
| 114 |
+
"scala_template": "def categorizeBox(length: Int,width: Int,height: Int,mass: Int): String = { \n \n}",
|
| 115 |
+
"java_template": "class Solution {\n public String categorizeBox(int length, int width, int height, int mass) {\n \n }\n}",
|
| 116 |
+
"python_template": "class Solution(object):\n def categorizeBox(self, length, width, height, mass):\n \"\"\"\n :type length: int\n :type width: int\n :type height: int\n :type mass: int\n :rtype: str\n \"\"\"\n "
|
| 117 |
+
}
|
categorize_box_according_to_criteria/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 "Heavy" (categorizeBox 1000 35 700 300)
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal "Neither" (categorizeBox 200 50 800 50)
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal "Neither" (categorizeBox 73 46 67 57)
|
| 16 |
+
|
| 17 |
+
let test4 _ = assert_equal "Neither" (categorizeBox 50 82 13 85)
|
| 18 |
+
|
| 19 |
+
let test5 _ = assert_equal "Neither" (categorizeBox 46 40 34 60)
|
| 20 |
+
|
| 21 |
+
let test6 _ = assert_equal "Neither" (categorizeBox 43 11 66 39)
|
| 22 |
+
|
| 23 |
+
let test7 _ = assert_equal "Neither" (categorizeBox 87 4 22 50)
|
| 24 |
+
|
| 25 |
+
let test8 _ = assert_equal "Neither" (categorizeBox 59 91 54 65)
|
| 26 |
+
|
| 27 |
+
let test9 _ = assert_equal "Neither" (categorizeBox 59 22 102 48)
|
| 28 |
+
|
| 29 |
+
let test10 _ = assert_equal "Neither" (categorizeBox 93 5 88 56)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
(* Grouping test cases *)
|
| 33 |
+
let suite = "Test Suite for categorizeBox" >::: [
|
| 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
|
categorize_box_according_to_criteria/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.categorizeBox(1000,35,700,300), "Heavy")
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.categorizeBox(200,50,800,50), "Neither")
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.categorizeBox(73,46,67,57), "Neither")
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.categorizeBox(50,82,13,85), "Neither")
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.categorizeBox(46,40,34,60), "Neither")
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.categorizeBox(43,11,66,39), "Neither")
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.categorizeBox(87,4,22,50), "Neither")
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("test8") {
|
| 33 |
+
assertEquals(Main.categorizeBox(59,91,54,65), "Neither")
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
test("test9") {
|
| 37 |
+
assertEquals(Main.categorizeBox(59,22,102,48), "Neither")
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
test("test10") {
|
| 41 |
+
assertEquals(Main.categorizeBox(93,5,88,56), "Neither")
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
}
|
cells_in_a_range_on_an_excel_sheet/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
cells_in_a_range_on_an_excel_sheet/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 (cellsInRange \"K1:L2 \")," ["K1","K2","L1","L2"] (cellsInRange "K1:L2"))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (cellsInRange \"A1:F1 \")," ["A1","B1","C1","D1","E1","F1"] (cellsInRange "A1:F1"))
|
| 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
|
cells_in_a_range_on_an_excel_sheet/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("K1","K2","L1","L2")), cellsInRange("K1:L2"));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(Arrays.asList("A1","B1","C1","D1","E1","F1")), cellsInRange("A1:F1"));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
cells_in_a_range_on_an_excel_sheet/meta.json
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2304,
|
| 3 |
+
"name": "cells_in_a_range_on_an_excel_sheet",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/",
|
| 6 |
+
"date": "1645920000000",
|
| 7 |
+
"task_description": "A cell `(r, c)` of an excel sheet is represented as a string `\"<col><row>\"` where: `<col>` denotes the column number `c` of the cell. It is represented by **alphabetical letters**. For example, the `1st` column is denoted by `'A'`, the `2nd` by `'B'`, the `3rd` by `'C'`, and so on. `<row>` is the row number `r` of the cell. The `rth` row is represented by the **integer** `r`. You are given a string `s` in the format `\"<col1><row1>:<col2><row2>\"`, where `<col1>` represents the column `c1`, `<row1>` represents the row `r1`, `<col2>` represents the column `c2`, and `<row2>` represents the row `r2`, such that `r1 <= r2` and `c1 <= c2`. Return _the **list of cells**_ `(x, y)` _such that_ `r1 <= x <= r2` _and_ `c1 <= y <= c2`. The cells should be represented as **strings** in the format mentioned above and be sorted in **non-decreasing** order first by columns and then by rows. **Example 1:** ``` **Input:** s = \"K1:L2\" **Output:** [\"K1\",\"K2\",\"L1\",\"L2\"] **Explanation:** The above diagram shows the cells which should be present in the list. The red arrows denote the order in which the cells should be presented. ``` **Example 2:** ``` **Input:** s = \"A1:F1\" **Output:** [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"] **Explanation:** The above diagram shows the cells which should be present in the list. The red arrow denotes the order in which the cells should be presented. ``` **Constraints:** `s.length == 5` `'A' <= s[0] <= s[3] <= 'Z'` `'1' <= s[1] <= s[4] <= '9'` `s` consists of uppercase English letters, digits and `':'`.",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"K1:L2\"",
|
| 12 |
+
"output": "[\"K1\",\"K2\",\"L1\",\"L2\"] "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"A1:F1\"",
|
| 17 |
+
"output": "[\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"] "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": "\"C8:D8\"",
|
| 23 |
+
"output": [
|
| 24 |
+
"C8",
|
| 25 |
+
"D8"
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"input": "\"S9:V9\"",
|
| 30 |
+
"output": [
|
| 31 |
+
"S9",
|
| 32 |
+
"T9",
|
| 33 |
+
"U9",
|
| 34 |
+
"V9"
|
| 35 |
+
]
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"input": "\"Y6:Y9\"",
|
| 39 |
+
"output": [
|
| 40 |
+
"Y6",
|
| 41 |
+
"Y7",
|
| 42 |
+
"Y8",
|
| 43 |
+
"Y9"
|
| 44 |
+
]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"input": "\"U9:W9\"",
|
| 48 |
+
"output": [
|
| 49 |
+
"U9",
|
| 50 |
+
"V9",
|
| 51 |
+
"W9"
|
| 52 |
+
]
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"input": "\"H2:O7\"",
|
| 56 |
+
"output": [
|
| 57 |
+
"H2",
|
| 58 |
+
"H3",
|
| 59 |
+
"H4",
|
| 60 |
+
"H5",
|
| 61 |
+
"H6",
|
| 62 |
+
"H7",
|
| 63 |
+
"I2",
|
| 64 |
+
"I3",
|
| 65 |
+
"I4",
|
| 66 |
+
"I5",
|
| 67 |
+
"I6",
|
| 68 |
+
"I7",
|
| 69 |
+
"J2",
|
| 70 |
+
"J3",
|
| 71 |
+
"J4",
|
| 72 |
+
"J5",
|
| 73 |
+
"J6",
|
| 74 |
+
"J7",
|
| 75 |
+
"K2",
|
| 76 |
+
"K3",
|
| 77 |
+
"K4",
|
| 78 |
+
"K5",
|
| 79 |
+
"K6",
|
| 80 |
+
"K7",
|
| 81 |
+
"L2",
|
| 82 |
+
"L3",
|
| 83 |
+
"L4",
|
| 84 |
+
"L5",
|
| 85 |
+
"L6",
|
| 86 |
+
"L7",
|
| 87 |
+
"M2",
|
| 88 |
+
"M3",
|
| 89 |
+
"M4",
|
| 90 |
+
"M5",
|
| 91 |
+
"M6",
|
| 92 |
+
"M7",
|
| 93 |
+
"N2",
|
| 94 |
+
"N3",
|
| 95 |
+
"N4",
|
| 96 |
+
"N5",
|
| 97 |
+
"N6",
|
| 98 |
+
"N7",
|
| 99 |
+
"O2",
|
| 100 |
+
"O3",
|
| 101 |
+
"O4",
|
| 102 |
+
"O5",
|
| 103 |
+
"O6",
|
| 104 |
+
"O7"
|
| 105 |
+
]
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
"input": "\"N6:O8\"",
|
| 109 |
+
"output": [
|
| 110 |
+
"N6",
|
| 111 |
+
"N7",
|
| 112 |
+
"N8",
|
| 113 |
+
"O6",
|
| 114 |
+
"O7",
|
| 115 |
+
"O8"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"input": "\"Q1:S8\"",
|
| 120 |
+
"output": [
|
| 121 |
+
"Q1",
|
| 122 |
+
"Q2",
|
| 123 |
+
"Q3",
|
| 124 |
+
"Q4",
|
| 125 |
+
"Q5",
|
| 126 |
+
"Q6",
|
| 127 |
+
"Q7",
|
| 128 |
+
"Q8",
|
| 129 |
+
"R1",
|
| 130 |
+
"R2",
|
| 131 |
+
"R3",
|
| 132 |
+
"R4",
|
| 133 |
+
"R5",
|
| 134 |
+
"R6",
|
| 135 |
+
"R7",
|
| 136 |
+
"R8",
|
| 137 |
+
"S1",
|
| 138 |
+
"S2",
|
| 139 |
+
"S3",
|
| 140 |
+
"S4",
|
| 141 |
+
"S5",
|
| 142 |
+
"S6",
|
| 143 |
+
"S7",
|
| 144 |
+
"S8"
|
| 145 |
+
]
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"input": "K9:T9",
|
| 149 |
+
"output": [
|
| 150 |
+
"K9",
|
| 151 |
+
"L9",
|
| 152 |
+
"M9",
|
| 153 |
+
"N9",
|
| 154 |
+
"O9",
|
| 155 |
+
"P9",
|
| 156 |
+
"Q9",
|
| 157 |
+
"R9",
|
| 158 |
+
"S9",
|
| 159 |
+
"T9"
|
| 160 |
+
]
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
"input": "W6:W8",
|
| 164 |
+
"output": [
|
| 165 |
+
"W6",
|
| 166 |
+
"W7",
|
| 167 |
+
"W8"
|
| 168 |
+
]
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
"input": "O5:S8",
|
| 172 |
+
"output": [
|
| 173 |
+
"O5",
|
| 174 |
+
"O6",
|
| 175 |
+
"O7",
|
| 176 |
+
"O8",
|
| 177 |
+
"P5",
|
| 178 |
+
"P6",
|
| 179 |
+
"P7",
|
| 180 |
+
"P8",
|
| 181 |
+
"Q5",
|
| 182 |
+
"Q6",
|
| 183 |
+
"Q7",
|
| 184 |
+
"Q8",
|
| 185 |
+
"R5",
|
| 186 |
+
"R6",
|
| 187 |
+
"R7",
|
| 188 |
+
"R8",
|
| 189 |
+
"S5",
|
| 190 |
+
"S6",
|
| 191 |
+
"S7",
|
| 192 |
+
"S8"
|
| 193 |
+
]
|
| 194 |
+
}
|
| 195 |
+
],
|
| 196 |
+
"haskell_template": "cellsInRange :: String -> [String]\ncellsInRange s ",
|
| 197 |
+
"ocaml_template": "let cellsInRange (s: string) : string list = ",
|
| 198 |
+
"scala_template": "def cellsInRange(s: String): List[String] = { \n \n}",
|
| 199 |
+
"java_template": "public static List<String> cellsInRange(String s) {\n\n}",
|
| 200 |
+
"python_template": "class Solution(object):\n def cellsInRange(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"\n "
|
| 201 |
+
}
|
cells_in_a_range_on_an_excel_sheet/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 ["K1";"K2";"L1";"L2"] (cellsInRange "K1:L2")
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal ["A1";"B1";"C1";"D1";"E1";"F1"] (cellsInRange "A1:F1")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for cellsInRange" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
cells_in_a_range_on_an_excel_sheet/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.cellsInRange("K1:L2"), List("K1","K2","L1","L2"))
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.cellsInRange("A1:F1"), List("A1","B1","C1","D1","E1","F1"))
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
check_distances_between_same_letters/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
check_distances_between_same_letters/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 (checkDistances \"abaccb \" [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])," True (checkDistances "abaccb" [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (checkDistances \"aa \" [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])," False (checkDistances "aa" [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
-- Grouping test cases
|
| 19 |
+
tests :: Test
|
| 20 |
+
tests = TestList [TestLabel "Test1" test1]
|
| 21 |
+
|
| 22 |
+
-- Running the tests
|
| 23 |
+
main :: IO Counts
|
| 24 |
+
main = runTestTT tests
|
check_distances_between_same_letters/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(true, checkDistances("abaccb", new ArrayList<>(Arrays.asList(1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(false, checkDistances("aa", new ArrayList<>(Arrays.asList(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
check_distances_between_same_letters/meta.json
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2476,
|
| 3 |
+
"name": "check_distances_between_same_letters",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-distances-between-same-letters/",
|
| 6 |
+
"date": "1661644800000",
|
| 7 |
+
"task_description": "You are given a **0-indexed** string `s` consisting of only lowercase English letters, where each letter in `s` appears **exactly** **twice**. You are also given a **0-indexed** integer array `distance` of length `26`. Each letter in the alphabet is numbered from `0` to `25` (i.e. `'a' -> 0`, `'b' -> 1`, `'c' -> 2`, ... , `'z' -> 25`). In a **well-spaced** string, the number of letters between the two occurrences of the `ith` letter is `distance[i]`. If the `ith` letter does not appear in `s`, then `distance[i]` can be **ignored**. Return `true`_ if _`s`_ is a **well-spaced** string, otherwise return _`false`. **Example 1:** ``` **Input:** s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] **Output:** true **Explanation:** - 'a' appears at indices 0 and 2 so it satisfies distance[0] = 1. - 'b' appears at indices 1 and 5 so it satisfies distance[1] = 3. - 'c' appears at indices 3 and 4 so it satisfies distance[2] = 0. Note that distance[3] = 5, but since 'd' does not appear in s, it can be ignored. Return true because s is a well-spaced string. ``` **Example 2:** ``` **Input:** s = \"aa\", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] **Output:** false **Explanation:** - 'a' appears at indices 0 and 1 so there are zero letters between them. Because distance[0] = 1, s is not a well-spaced string. ``` **Constraints:** `2 <= s.length <= 52` `s` consists only of lowercase English letters. Each letter appears in `s` exactly twice. `distance.length == 26` `0 <= distance[i] <= 50`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"abaccb\", distance = [1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"aa\", distance = [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": [
|
| 23 |
+
"\"ppqkargjvtumhlvtqagumlrkjh\"",
|
| 24 |
+
[
|
| 25 |
+
-1,
|
| 26 |
+
0,
|
| 27 |
+
0,
|
| 28 |
+
0,
|
| 29 |
+
0,
|
| 30 |
+
0,
|
| 31 |
+
-1,
|
| 32 |
+
-1,
|
| 33 |
+
0,
|
| 34 |
+
-1,
|
| 35 |
+
-1,
|
| 36 |
+
-1,
|
| 37 |
+
-1,
|
| 38 |
+
0,
|
| 39 |
+
0,
|
| 40 |
+
-1,
|
| 41 |
+
-1,
|
| 42 |
+
-1,
|
| 43 |
+
0,
|
| 44 |
+
-1,
|
| 45 |
+
-1,
|
| 46 |
+
-1,
|
| 47 |
+
0,
|
| 48 |
+
0,
|
| 49 |
+
0,
|
| 50 |
+
0
|
| 51 |
+
]
|
| 52 |
+
],
|
| 53 |
+
"output": true
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"input": [
|
| 57 |
+
"\"sbkoxnxabigccaljjeiosgknel\"",
|
| 58 |
+
[
|
| 59 |
+
-1,
|
| 60 |
+
-1,
|
| 61 |
+
-1,
|
| 62 |
+
0,
|
| 63 |
+
-1,
|
| 64 |
+
0,
|
| 65 |
+
-1,
|
| 66 |
+
0,
|
| 67 |
+
-1,
|
| 68 |
+
-1,
|
| 69 |
+
-1,
|
| 70 |
+
-1,
|
| 71 |
+
0,
|
| 72 |
+
-1,
|
| 73 |
+
-1,
|
| 74 |
+
0,
|
| 75 |
+
0,
|
| 76 |
+
0,
|
| 77 |
+
-1,
|
| 78 |
+
0,
|
| 79 |
+
0,
|
| 80 |
+
0,
|
| 81 |
+
0,
|
| 82 |
+
-1,
|
| 83 |
+
0,
|
| 84 |
+
0
|
| 85 |
+
]
|
| 86 |
+
],
|
| 87 |
+
"output": true
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"input": [
|
| 91 |
+
"\"agymhjaxnjxvnveiyefhgfccmi\"",
|
| 92 |
+
[
|
| 93 |
+
-1,
|
| 94 |
+
0,
|
| 95 |
+
-1,
|
| 96 |
+
0,
|
| 97 |
+
-1,
|
| 98 |
+
-1,
|
| 99 |
+
-1,
|
| 100 |
+
-1,
|
| 101 |
+
-1,
|
| 102 |
+
-1,
|
| 103 |
+
0,
|
| 104 |
+
0,
|
| 105 |
+
-1,
|
| 106 |
+
-1,
|
| 107 |
+
0,
|
| 108 |
+
0,
|
| 109 |
+
0,
|
| 110 |
+
0,
|
| 111 |
+
0,
|
| 112 |
+
0,
|
| 113 |
+
0,
|
| 114 |
+
-1,
|
| 115 |
+
0,
|
| 116 |
+
-1,
|
| 117 |
+
-1,
|
| 118 |
+
0
|
| 119 |
+
]
|
| 120 |
+
],
|
| 121 |
+
"output": true
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"input": [
|
| 125 |
+
"\"blbkmlimqnuddeqjjfefknisus\"",
|
| 126 |
+
[
|
| 127 |
+
0,
|
| 128 |
+
-1,
|
| 129 |
+
0,
|
| 130 |
+
-1,
|
| 131 |
+
-1,
|
| 132 |
+
-1,
|
| 133 |
+
0,
|
| 134 |
+
0,
|
| 135 |
+
-1,
|
| 136 |
+
-1,
|
| 137 |
+
-1,
|
| 138 |
+
-1,
|
| 139 |
+
-1,
|
| 140 |
+
-1,
|
| 141 |
+
0,
|
| 142 |
+
0,
|
| 143 |
+
-1,
|
| 144 |
+
0,
|
| 145 |
+
-1,
|
| 146 |
+
0,
|
| 147 |
+
-1,
|
| 148 |
+
0,
|
| 149 |
+
0,
|
| 150 |
+
0,
|
| 151 |
+
0,
|
| 152 |
+
0
|
| 153 |
+
]
|
| 154 |
+
],
|
| 155 |
+
"output": true
|
| 156 |
+
},
|
| 157 |
+
{
|
| 158 |
+
"input": [
|
| 159 |
+
"\"dwdnqujjmrzcquprwcipznttim\"",
|
| 160 |
+
[
|
| 161 |
+
0,
|
| 162 |
+
0,
|
| 163 |
+
-1,
|
| 164 |
+
-1,
|
| 165 |
+
0,
|
| 166 |
+
0,
|
| 167 |
+
0,
|
| 168 |
+
0,
|
| 169 |
+
-1,
|
| 170 |
+
-1,
|
| 171 |
+
0,
|
| 172 |
+
0,
|
| 173 |
+
-1,
|
| 174 |
+
-1,
|
| 175 |
+
0,
|
| 176 |
+
-1,
|
| 177 |
+
-1,
|
| 178 |
+
-1,
|
| 179 |
+
0,
|
| 180 |
+
-1,
|
| 181 |
+
-1,
|
| 182 |
+
0,
|
| 183 |
+
-1,
|
| 184 |
+
0,
|
| 185 |
+
0,
|
| 186 |
+
-1
|
| 187 |
+
]
|
| 188 |
+
],
|
| 189 |
+
"output": true
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"input": [
|
| 193 |
+
"\"gcbgmcpfqvmqlvbottzaplzofa\"",
|
| 194 |
+
[
|
| 195 |
+
-1,
|
| 196 |
+
-1,
|
| 197 |
+
-1,
|
| 198 |
+
0,
|
| 199 |
+
0,
|
| 200 |
+
-1,
|
| 201 |
+
-1,
|
| 202 |
+
0,
|
| 203 |
+
0,
|
| 204 |
+
0,
|
| 205 |
+
0,
|
| 206 |
+
-1,
|
| 207 |
+
-1,
|
| 208 |
+
0,
|
| 209 |
+
-1,
|
| 210 |
+
-1,
|
| 211 |
+
-1,
|
| 212 |
+
0,
|
| 213 |
+
0,
|
| 214 |
+
-1,
|
| 215 |
+
0,
|
| 216 |
+
-1,
|
| 217 |
+
0,
|
| 218 |
+
0,
|
| 219 |
+
0,
|
| 220 |
+
-1
|
| 221 |
+
]
|
| 222 |
+
],
|
| 223 |
+
"output": true
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
"input": [
|
| 227 |
+
"\"nocmzrbdbtmekkfofdzncrtlle\"",
|
| 228 |
+
[
|
| 229 |
+
0,
|
| 230 |
+
-1,
|
| 231 |
+
-1,
|
| 232 |
+
-1,
|
| 233 |
+
-1,
|
| 234 |
+
-1,
|
| 235 |
+
0,
|
| 236 |
+
0,
|
| 237 |
+
0,
|
| 238 |
+
0,
|
| 239 |
+
-1,
|
| 240 |
+
-1,
|
| 241 |
+
-1,
|
| 242 |
+
-1,
|
| 243 |
+
-1,
|
| 244 |
+
0,
|
| 245 |
+
0,
|
| 246 |
+
-1,
|
| 247 |
+
0,
|
| 248 |
+
-1,
|
| 249 |
+
0,
|
| 250 |
+
0,
|
| 251 |
+
0,
|
| 252 |
+
0,
|
| 253 |
+
0,
|
| 254 |
+
-1
|
| 255 |
+
]
|
| 256 |
+
],
|
| 257 |
+
"output": true
|
| 258 |
+
},
|
| 259 |
+
{
|
| 260 |
+
"input": [
|
| 261 |
+
"gdqcfafcbtivuruibvytqyrgda",
|
| 262 |
+
[
|
| 263 |
+
-1,
|
| 264 |
+
-1,
|
| 265 |
+
-1,
|
| 266 |
+
-1,
|
| 267 |
+
0,
|
| 268 |
+
-1,
|
| 269 |
+
-1,
|
| 270 |
+
0,
|
| 271 |
+
-1,
|
| 272 |
+
0,
|
| 273 |
+
0,
|
| 274 |
+
0,
|
| 275 |
+
0,
|
| 276 |
+
0,
|
| 277 |
+
0,
|
| 278 |
+
0,
|
| 279 |
+
-1,
|
| 280 |
+
-1,
|
| 281 |
+
0,
|
| 282 |
+
-1,
|
| 283 |
+
-1,
|
| 284 |
+
-1,
|
| 285 |
+
0,
|
| 286 |
+
0,
|
| 287 |
+
-1,
|
| 288 |
+
0
|
| 289 |
+
]
|
| 290 |
+
],
|
| 291 |
+
"output": true
|
| 292 |
+
},
|
| 293 |
+
{
|
| 294 |
+
"input": [
|
| 295 |
+
"pjgwlwmedffnalaykngkjpymed",
|
| 296 |
+
[
|
| 297 |
+
-1,
|
| 298 |
+
0,
|
| 299 |
+
0,
|
| 300 |
+
-1,
|
| 301 |
+
-1,
|
| 302 |
+
-1,
|
| 303 |
+
-1,
|
| 304 |
+
0,
|
| 305 |
+
0,
|
| 306 |
+
-1,
|
| 307 |
+
-1,
|
| 308 |
+
-1,
|
| 309 |
+
-1,
|
| 310 |
+
-1,
|
| 311 |
+
0,
|
| 312 |
+
-1,
|
| 313 |
+
0,
|
| 314 |
+
0,
|
| 315 |
+
0,
|
| 316 |
+
0,
|
| 317 |
+
0,
|
| 318 |
+
0,
|
| 319 |
+
-1,
|
| 320 |
+
0,
|
| 321 |
+
-1,
|
| 322 |
+
0
|
| 323 |
+
]
|
| 324 |
+
],
|
| 325 |
+
"output": true
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"input": [
|
| 329 |
+
"ddvfvcyizunfpiypuslcrrlnzs",
|
| 330 |
+
[
|
| 331 |
+
0,
|
| 332 |
+
0,
|
| 333 |
+
-1,
|
| 334 |
+
-1,
|
| 335 |
+
0,
|
| 336 |
+
-1,
|
| 337 |
+
0,
|
| 338 |
+
0,
|
| 339 |
+
-1,
|
| 340 |
+
0,
|
| 341 |
+
0,
|
| 342 |
+
-1,
|
| 343 |
+
0,
|
| 344 |
+
-1,
|
| 345 |
+
0,
|
| 346 |
+
-1,
|
| 347 |
+
0,
|
| 348 |
+
-1,
|
| 349 |
+
-1,
|
| 350 |
+
0,
|
| 351 |
+
-1,
|
| 352 |
+
-1,
|
| 353 |
+
0,
|
| 354 |
+
0,
|
| 355 |
+
-1,
|
| 356 |
+
-1
|
| 357 |
+
]
|
| 358 |
+
],
|
| 359 |
+
"output": true
|
| 360 |
+
}
|
| 361 |
+
],
|
| 362 |
+
"haskell_template": "checkDistances :: String -> [Int] -> Bool\ncheckDistances s distance ",
|
| 363 |
+
"ocaml_template": "let checkDistances (s: string) (distance: int list) : bool = ",
|
| 364 |
+
"scala_template": "def checkDistances(s: String,distance: List[Int]): Boolean = { \n \n}",
|
| 365 |
+
"java_template": "public static boolean checkDistances(String s, List<Integer> distance) {\n\n}",
|
| 366 |
+
"python_template": "class Solution(object):\n def checkDistances(self, s, distance):\n \"\"\"\n :type s: str\n :type distance: List[int]\n :rtype: bool\n \"\"\"\n "
|
| 367 |
+
}
|
check_distances_between_same_letters/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 true (checkDistances "abaccb" [1;3;0;5;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal false (checkDistances "aa" [1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0])
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
(* Grouping test cases *)
|
| 17 |
+
let suite = "Test Suite for checkDistances" >::: [
|
| 18 |
+
|
| 19 |
+
"test1" >:: test1;
|
| 20 |
+
"test2" >:: test2;
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
(* Running the tests *)
|
| 25 |
+
let () = run_test_tt_main suite
|
| 26 |
+
end
|
check_distances_between_same_letters/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.checkDistances("abaccb",[1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), true)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.checkDistances("aa",[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]), false)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
}
|
check_if_all_as_appears_before_all_bs/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
check_if_all_as_appears_before_all_bs/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 (checkString \"aaabbb \")," True (checkString "aaabbb"))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (checkString \"abab \")," False (checkString "abab"))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (checkString \"bbb \")," True (checkString "bbb"))
|
| 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
|
check_if_all_as_appears_before_all_bs/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(true, checkString("aaabbb"));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(false, checkString("abab"));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals(true, checkString("bbb"));
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
}
|
check_if_all_as_appears_before_all_bs/meta.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2243,
|
| 3 |
+
"name": "check_if_all_as_appears_before_all_bs",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/",
|
| 6 |
+
"date": "1640476800000",
|
| 7 |
+
"task_description": "Given a string `s` consisting of **only** the characters `'a'` and `'b'`, return `true` _if **every** _`'a'` _appears before **every** _`'b'`_ in the string_. Otherwise, return `false`. **Example 1:** ``` **Input:** s = \"aaabbb\" **Output:** true **Explanation:** The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5. Hence, every 'a' appears before every 'b' and we return true. ``` **Example 2:** ``` **Input:** s = \"abab\" **Output:** false **Explanation:** There is an 'a' at index 2 and a 'b' at index 1. Hence, not every 'a' appears before every 'b' and we return false. ``` **Example 3:** ``` **Input:** s = \"bbb\" **Output:** true **Explanation:** There are no 'a's, hence, every 'a' appears before every 'b' and we return true. ``` **Constraints:** `1 <= s.length <= 100` `s[i]` is either `'a'` or `'b'`.",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"aaabbb\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"abab\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "s = \"bbb\"",
|
| 22 |
+
"output": "true "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"private_test_cases": [
|
| 26 |
+
{
|
| 27 |
+
"input": "ababbbbaabaababbbabbbb",
|
| 28 |
+
"output": false
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"input": "aaaabbaabbaabab",
|
| 32 |
+
"output": false
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"input": "aaabbabbbbabaabbbbababaabaababba",
|
| 36 |
+
"output": false
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"input": "abbabbbbaaabbaabbbaabbbbbbabbaaaba",
|
| 40 |
+
"output": false
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"input": "babababaaaabbbbaaaaabbbabbabbbabaaaaaababbbbaabbababbbbbbbaabbbaabbaaabbbbaabbbaaaabab",
|
| 44 |
+
"output": false
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"input": "babaab",
|
| 48 |
+
"output": false
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"input": "ababaaabbbaabbabaaaaabbaaaabbababaabaaaaaaabaaaabbaabaaaabbabbb",
|
| 52 |
+
"output": false
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"input": "baababababbaabbabbbbbbabbbaababbbaabbbaaaabaabbbabbabbbabababbbabbbabaab",
|
| 56 |
+
"output": false
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"input": "abb",
|
| 60 |
+
"output": true
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"input": "abbabaabbbb",
|
| 64 |
+
"output": false
|
| 65 |
+
}
|
| 66 |
+
],
|
| 67 |
+
"haskell_template": "checkString :: String -> Bool\ncheckString s ",
|
| 68 |
+
"ocaml_template": "let checkString (s: string) : bool = ",
|
| 69 |
+
"scala_template": "def checkString(s: String): Boolean = { \n \n}",
|
| 70 |
+
"java_template": "public static boolean checkString(String s) {\n\n}",
|
| 71 |
+
"python_template": "class Solution(object):\n def checkString(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"\n "
|
| 72 |
+
}
|
check_if_all_as_appears_before_all_bs/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 true (checkString "aaabbb")
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal false (checkString "abab")
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal true (checkString "bbb")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
(* Grouping test cases *)
|
| 19 |
+
let suite = "Test Suite for checkString" >::: [
|
| 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
|
check_if_all_as_appears_before_all_bs/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.checkString("aaabbb"), true)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.checkString("abab"), false)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.checkString("bbb"), true)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
}
|
check_if_array_is_good/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
check_if_array_is_good/haskell_tests/Main.hs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 (isGood [2, 1, 3])," False (isGood [2, 1, 3]))
|
| 13 |
+
|
| 14 |
+
test2 :: Test
|
| 15 |
+
test2 = TestCase (assertEqual "for (isGood [1, 3, 3, 2])," True (isGood [1, 3, 3, 2]))
|
| 16 |
+
|
| 17 |
+
test3 :: Test
|
| 18 |
+
test3 = TestCase (assertEqual "for (isGood [1, 1])," True (isGood [1, 1]))
|
| 19 |
+
|
| 20 |
+
test4 :: Test
|
| 21 |
+
test4 = TestCase (assertEqual "for (isGood [3, 4, 4, 1, 2, 1])," False (isGood [3, 4, 4, 1, 2, 1]))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
-- Grouping test cases
|
| 25 |
+
tests :: Test
|
| 26 |
+
tests = TestList [TestLabel "Test1" test1, TestLabel "Test2" test2, TestLabel "Test3" test3]
|
| 27 |
+
|
| 28 |
+
-- Running the tests
|
| 29 |
+
main :: IO Counts
|
| 30 |
+
main = runTestTT tests
|
check_if_array_is_good/java_tests/Main.java
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(false, isGood(new ArrayList<>(Arrays.asList(2, 1, 3))));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(true, isGood(new ArrayList<>(Arrays.asList(1, 3, 3, 2))));
|
| 19 |
+
}
|
| 20 |
+
@Test
|
| 21 |
+
public void test3() {
|
| 22 |
+
assertEquals(true, isGood(new ArrayList<>(Arrays.asList(1, 1))));
|
| 23 |
+
}
|
| 24 |
+
@Test
|
| 25 |
+
public void test4() {
|
| 26 |
+
assertEquals(false, isGood(new ArrayList<>(Arrays.asList(3, 4, 4, 1, 2, 1))));
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
}
|
check_if_array_is_good/meta.json
ADDED
|
@@ -0,0 +1,577 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 2892,
|
| 3 |
+
"name": "check_if_array_is_good",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-array-is-good/",
|
| 6 |
+
"date": "1688774400000",
|
| 7 |
+
"task_description": "You are given an integer array `nums`. We consider an array **good **if it is a permutation of an array `base[n]`. `base[n] = [1, 2, ..., n - 1, n, n] `(in other words, it is an array of length `n + 1` which contains `1` to `n - 1 `exactly once, plus two occurrences of `n`). For example, `base[1] = [1, 1]` and` base[3] = [1, 2, 3, 3]`. Return `true` _if the given array is good, otherwise return__ _`false`. **Note: **A permutation of integers represents an arrangement of these numbers. **Example 1:** ``` **Input:** nums = [2, 1, 3] **Output:** false **Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false. ``` **Example 2:** ``` **Input:** nums = [1, 3, 3, 2] **Output:** true **Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true. ``` **Example 3:** ``` **Input:** nums = [1, 1] **Output:** true **Explanation:** Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true. ``` **Example 4:** ``` **Input:** nums = [3, 4, 4, 1, 2, 1] **Output:** false **Explanation:** Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false. ``` **Constraints:** `1 <= nums.length <= 100` `1 <= num[i] <= 200`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [2, 1, 3]",
|
| 12 |
+
"output": "false "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [1, 3, 3, 2]",
|
| 17 |
+
"output": "true "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "nums = [1, 1]",
|
| 22 |
+
"output": "true "
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"label": "Example 4",
|
| 26 |
+
"input": "nums = [3, 4, 4, 1, 2, 1]",
|
| 27 |
+
"output": "false "
|
| 28 |
+
}
|
| 29 |
+
],
|
| 30 |
+
"private_test_cases": [
|
| 31 |
+
{
|
| 32 |
+
"input": [
|
| 33 |
+
43,
|
| 34 |
+
16,
|
| 35 |
+
46,
|
| 36 |
+
25,
|
| 37 |
+
29,
|
| 38 |
+
12,
|
| 39 |
+
23,
|
| 40 |
+
27,
|
| 41 |
+
9,
|
| 42 |
+
36,
|
| 43 |
+
8,
|
| 44 |
+
11,
|
| 45 |
+
52,
|
| 46 |
+
17,
|
| 47 |
+
3,
|
| 48 |
+
50,
|
| 49 |
+
35,
|
| 50 |
+
51,
|
| 51 |
+
31,
|
| 52 |
+
20,
|
| 53 |
+
33,
|
| 54 |
+
22,
|
| 55 |
+
26,
|
| 56 |
+
37,
|
| 57 |
+
21,
|
| 58 |
+
34,
|
| 59 |
+
47,
|
| 60 |
+
41,
|
| 61 |
+
28,
|
| 62 |
+
18,
|
| 63 |
+
15,
|
| 64 |
+
2,
|
| 65 |
+
44,
|
| 66 |
+
4,
|
| 67 |
+
6,
|
| 68 |
+
10,
|
| 69 |
+
39,
|
| 70 |
+
19,
|
| 71 |
+
40,
|
| 72 |
+
32,
|
| 73 |
+
30,
|
| 74 |
+
1,
|
| 75 |
+
24,
|
| 76 |
+
7,
|
| 77 |
+
13,
|
| 78 |
+
48,
|
| 79 |
+
5,
|
| 80 |
+
49,
|
| 81 |
+
14,
|
| 82 |
+
38,
|
| 83 |
+
45,
|
| 84 |
+
42
|
| 85 |
+
],
|
| 86 |
+
"output": false
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"input": [
|
| 90 |
+
5,
|
| 91 |
+
1,
|
| 92 |
+
2,
|
| 93 |
+
4,
|
| 94 |
+
3
|
| 95 |
+
],
|
| 96 |
+
"output": false
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"input": [
|
| 100 |
+
12,
|
| 101 |
+
8,
|
| 102 |
+
5,
|
| 103 |
+
4,
|
| 104 |
+
19,
|
| 105 |
+
16,
|
| 106 |
+
7,
|
| 107 |
+
9,
|
| 108 |
+
13,
|
| 109 |
+
11,
|
| 110 |
+
10,
|
| 111 |
+
14,
|
| 112 |
+
17,
|
| 113 |
+
3,
|
| 114 |
+
2,
|
| 115 |
+
18,
|
| 116 |
+
15,
|
| 117 |
+
6,
|
| 118 |
+
1
|
| 119 |
+
],
|
| 120 |
+
"output": false
|
| 121 |
+
},
|
| 122 |
+
{
|
| 123 |
+
"input": [
|
| 124 |
+
24,
|
| 125 |
+
1,
|
| 126 |
+
31,
|
| 127 |
+
32,
|
| 128 |
+
16,
|
| 129 |
+
37,
|
| 130 |
+
3,
|
| 131 |
+
81,
|
| 132 |
+
50,
|
| 133 |
+
52,
|
| 134 |
+
4,
|
| 135 |
+
55,
|
| 136 |
+
69,
|
| 137 |
+
80,
|
| 138 |
+
41,
|
| 139 |
+
45,
|
| 140 |
+
42,
|
| 141 |
+
60,
|
| 142 |
+
59,
|
| 143 |
+
19,
|
| 144 |
+
18,
|
| 145 |
+
40,
|
| 146 |
+
7,
|
| 147 |
+
61,
|
| 148 |
+
8,
|
| 149 |
+
34,
|
| 150 |
+
22,
|
| 151 |
+
20,
|
| 152 |
+
75,
|
| 153 |
+
48,
|
| 154 |
+
77,
|
| 155 |
+
72,
|
| 156 |
+
76,
|
| 157 |
+
78,
|
| 158 |
+
63,
|
| 159 |
+
25,
|
| 160 |
+
15,
|
| 161 |
+
65,
|
| 162 |
+
35,
|
| 163 |
+
53,
|
| 164 |
+
39,
|
| 165 |
+
11,
|
| 166 |
+
57,
|
| 167 |
+
5,
|
| 168 |
+
58,
|
| 169 |
+
47,
|
| 170 |
+
26,
|
| 171 |
+
62,
|
| 172 |
+
10,
|
| 173 |
+
28,
|
| 174 |
+
29,
|
| 175 |
+
14,
|
| 176 |
+
71,
|
| 177 |
+
33,
|
| 178 |
+
82,
|
| 179 |
+
83,
|
| 180 |
+
44,
|
| 181 |
+
66,
|
| 182 |
+
79,
|
| 183 |
+
17,
|
| 184 |
+
38,
|
| 185 |
+
68,
|
| 186 |
+
23,
|
| 187 |
+
6,
|
| 188 |
+
30,
|
| 189 |
+
54,
|
| 190 |
+
64,
|
| 191 |
+
2,
|
| 192 |
+
43,
|
| 193 |
+
67,
|
| 194 |
+
36,
|
| 195 |
+
74,
|
| 196 |
+
21,
|
| 197 |
+
13,
|
| 198 |
+
70,
|
| 199 |
+
9,
|
| 200 |
+
51,
|
| 201 |
+
49,
|
| 202 |
+
27,
|
| 203 |
+
46,
|
| 204 |
+
12,
|
| 205 |
+
73,
|
| 206 |
+
56
|
| 207 |
+
],
|
| 208 |
+
"output": false
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"input": [
|
| 212 |
+
2,
|
| 213 |
+
85,
|
| 214 |
+
84,
|
| 215 |
+
18,
|
| 216 |
+
65,
|
| 217 |
+
63,
|
| 218 |
+
23,
|
| 219 |
+
19,
|
| 220 |
+
81,
|
| 221 |
+
5,
|
| 222 |
+
49,
|
| 223 |
+
60,
|
| 224 |
+
26,
|
| 225 |
+
9,
|
| 226 |
+
7,
|
| 227 |
+
61,
|
| 228 |
+
39,
|
| 229 |
+
62,
|
| 230 |
+
35,
|
| 231 |
+
4,
|
| 232 |
+
21,
|
| 233 |
+
76,
|
| 234 |
+
44,
|
| 235 |
+
73,
|
| 236 |
+
54,
|
| 237 |
+
69,
|
| 238 |
+
47,
|
| 239 |
+
11,
|
| 240 |
+
59,
|
| 241 |
+
55,
|
| 242 |
+
89,
|
| 243 |
+
80,
|
| 244 |
+
50,
|
| 245 |
+
83,
|
| 246 |
+
33,
|
| 247 |
+
57,
|
| 248 |
+
25,
|
| 249 |
+
3,
|
| 250 |
+
68,
|
| 251 |
+
75,
|
| 252 |
+
64,
|
| 253 |
+
16,
|
| 254 |
+
22,
|
| 255 |
+
42,
|
| 256 |
+
1,
|
| 257 |
+
29,
|
| 258 |
+
17,
|
| 259 |
+
31,
|
| 260 |
+
37,
|
| 261 |
+
40,
|
| 262 |
+
45,
|
| 263 |
+
51,
|
| 264 |
+
13,
|
| 265 |
+
43,
|
| 266 |
+
86,
|
| 267 |
+
30,
|
| 268 |
+
52,
|
| 269 |
+
41,
|
| 270 |
+
82,
|
| 271 |
+
10,
|
| 272 |
+
53,
|
| 273 |
+
14,
|
| 274 |
+
38,
|
| 275 |
+
15,
|
| 276 |
+
32,
|
| 277 |
+
28,
|
| 278 |
+
72,
|
| 279 |
+
77,
|
| 280 |
+
56,
|
| 281 |
+
58,
|
| 282 |
+
34,
|
| 283 |
+
79,
|
| 284 |
+
70,
|
| 285 |
+
90,
|
| 286 |
+
88,
|
| 287 |
+
24,
|
| 288 |
+
87,
|
| 289 |
+
48,
|
| 290 |
+
20,
|
| 291 |
+
12,
|
| 292 |
+
66,
|
| 293 |
+
78,
|
| 294 |
+
27,
|
| 295 |
+
91,
|
| 296 |
+
71,
|
| 297 |
+
6,
|
| 298 |
+
8,
|
| 299 |
+
67,
|
| 300 |
+
36,
|
| 301 |
+
74,
|
| 302 |
+
46
|
| 303 |
+
],
|
| 304 |
+
"output": false
|
| 305 |
+
},
|
| 306 |
+
{
|
| 307 |
+
"input": [
|
| 308 |
+
33,
|
| 309 |
+
92,
|
| 310 |
+
94,
|
| 311 |
+
81,
|
| 312 |
+
22,
|
| 313 |
+
60,
|
| 314 |
+
23,
|
| 315 |
+
88,
|
| 316 |
+
29,
|
| 317 |
+
31,
|
| 318 |
+
1,
|
| 319 |
+
42,
|
| 320 |
+
83,
|
| 321 |
+
9,
|
| 322 |
+
16,
|
| 323 |
+
21,
|
| 324 |
+
19,
|
| 325 |
+
51,
|
| 326 |
+
86,
|
| 327 |
+
52,
|
| 328 |
+
17,
|
| 329 |
+
57,
|
| 330 |
+
43,
|
| 331 |
+
18,
|
| 332 |
+
67,
|
| 333 |
+
46,
|
| 334 |
+
13,
|
| 335 |
+
54,
|
| 336 |
+
89,
|
| 337 |
+
69,
|
| 338 |
+
11,
|
| 339 |
+
27,
|
| 340 |
+
28,
|
| 341 |
+
85,
|
| 342 |
+
50,
|
| 343 |
+
30,
|
| 344 |
+
80,
|
| 345 |
+
56,
|
| 346 |
+
34,
|
| 347 |
+
79,
|
| 348 |
+
55,
|
| 349 |
+
72,
|
| 350 |
+
36,
|
| 351 |
+
62,
|
| 352 |
+
87,
|
| 353 |
+
84,
|
| 354 |
+
49,
|
| 355 |
+
58,
|
| 356 |
+
90,
|
| 357 |
+
47,
|
| 358 |
+
75,
|
| 359 |
+
66,
|
| 360 |
+
7,
|
| 361 |
+
14,
|
| 362 |
+
71,
|
| 363 |
+
40,
|
| 364 |
+
93,
|
| 365 |
+
77,
|
| 366 |
+
70,
|
| 367 |
+
38,
|
| 368 |
+
32,
|
| 369 |
+
61,
|
| 370 |
+
24,
|
| 371 |
+
39,
|
| 372 |
+
45,
|
| 373 |
+
44,
|
| 374 |
+
48,
|
| 375 |
+
68,
|
| 376 |
+
5,
|
| 377 |
+
65,
|
| 378 |
+
76,
|
| 379 |
+
10,
|
| 380 |
+
35,
|
| 381 |
+
6,
|
| 382 |
+
78,
|
| 383 |
+
95,
|
| 384 |
+
41,
|
| 385 |
+
3,
|
| 386 |
+
64,
|
| 387 |
+
73,
|
| 388 |
+
91,
|
| 389 |
+
20,
|
| 390 |
+
15,
|
| 391 |
+
82,
|
| 392 |
+
74,
|
| 393 |
+
37,
|
| 394 |
+
63,
|
| 395 |
+
2,
|
| 396 |
+
12,
|
| 397 |
+
8,
|
| 398 |
+
26,
|
| 399 |
+
59,
|
| 400 |
+
25,
|
| 401 |
+
4,
|
| 402 |
+
53
|
| 403 |
+
],
|
| 404 |
+
"output": false
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"input": [
|
| 408 |
+
7,
|
| 409 |
+
13,
|
| 410 |
+
24,
|
| 411 |
+
22,
|
| 412 |
+
15,
|
| 413 |
+
4,
|
| 414 |
+
25,
|
| 415 |
+
6,
|
| 416 |
+
20,
|
| 417 |
+
9,
|
| 418 |
+
17,
|
| 419 |
+
3,
|
| 420 |
+
12,
|
| 421 |
+
18,
|
| 422 |
+
21,
|
| 423 |
+
14,
|
| 424 |
+
1,
|
| 425 |
+
2,
|
| 426 |
+
8,
|
| 427 |
+
5,
|
| 428 |
+
16,
|
| 429 |
+
19,
|
| 430 |
+
10,
|
| 431 |
+
23,
|
| 432 |
+
11,
|
| 433 |
+
25
|
| 434 |
+
],
|
| 435 |
+
"output": true
|
| 436 |
+
},
|
| 437 |
+
{
|
| 438 |
+
"input": [
|
| 439 |
+
12,
|
| 440 |
+
3,
|
| 441 |
+
4,
|
| 442 |
+
8,
|
| 443 |
+
16,
|
| 444 |
+
17,
|
| 445 |
+
2,
|
| 446 |
+
9,
|
| 447 |
+
13,
|
| 448 |
+
7,
|
| 449 |
+
18,
|
| 450 |
+
1,
|
| 451 |
+
11,
|
| 452 |
+
14,
|
| 453 |
+
5,
|
| 454 |
+
10,
|
| 455 |
+
6,
|
| 456 |
+
15
|
| 457 |
+
],
|
| 458 |
+
"output": false
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"input": [
|
| 462 |
+
1,
|
| 463 |
+
5,
|
| 464 |
+
17,
|
| 465 |
+
10,
|
| 466 |
+
9,
|
| 467 |
+
11,
|
| 468 |
+
14,
|
| 469 |
+
20,
|
| 470 |
+
3,
|
| 471 |
+
18,
|
| 472 |
+
6,
|
| 473 |
+
7,
|
| 474 |
+
12,
|
| 475 |
+
19,
|
| 476 |
+
15,
|
| 477 |
+
13,
|
| 478 |
+
4,
|
| 479 |
+
2,
|
| 480 |
+
8,
|
| 481 |
+
16
|
| 482 |
+
],
|
| 483 |
+
"output": false
|
| 484 |
+
},
|
| 485 |
+
{
|
| 486 |
+
"input": [
|
| 487 |
+
6,
|
| 488 |
+
67,
|
| 489 |
+
70,
|
| 490 |
+
21,
|
| 491 |
+
75,
|
| 492 |
+
53,
|
| 493 |
+
48,
|
| 494 |
+
16,
|
| 495 |
+
77,
|
| 496 |
+
66,
|
| 497 |
+
74,
|
| 498 |
+
26,
|
| 499 |
+
38,
|
| 500 |
+
30,
|
| 501 |
+
4,
|
| 502 |
+
32,
|
| 503 |
+
56,
|
| 504 |
+
63,
|
| 505 |
+
55,
|
| 506 |
+
81,
|
| 507 |
+
44,
|
| 508 |
+
46,
|
| 509 |
+
54,
|
| 510 |
+
60,
|
| 511 |
+
72,
|
| 512 |
+
57,
|
| 513 |
+
65,
|
| 514 |
+
19,
|
| 515 |
+
37,
|
| 516 |
+
52,
|
| 517 |
+
27,
|
| 518 |
+
50,
|
| 519 |
+
78,
|
| 520 |
+
59,
|
| 521 |
+
39,
|
| 522 |
+
8,
|
| 523 |
+
12,
|
| 524 |
+
13,
|
| 525 |
+
58,
|
| 526 |
+
20,
|
| 527 |
+
68,
|
| 528 |
+
10,
|
| 529 |
+
76,
|
| 530 |
+
49,
|
| 531 |
+
34,
|
| 532 |
+
79,
|
| 533 |
+
9,
|
| 534 |
+
71,
|
| 535 |
+
14,
|
| 536 |
+
28,
|
| 537 |
+
42,
|
| 538 |
+
45,
|
| 539 |
+
61,
|
| 540 |
+
5,
|
| 541 |
+
31,
|
| 542 |
+
29,
|
| 543 |
+
36,
|
| 544 |
+
7,
|
| 545 |
+
41,
|
| 546 |
+
24,
|
| 547 |
+
3,
|
| 548 |
+
15,
|
| 549 |
+
17,
|
| 550 |
+
2,
|
| 551 |
+
40,
|
| 552 |
+
22,
|
| 553 |
+
33,
|
| 554 |
+
80,
|
| 555 |
+
25,
|
| 556 |
+
73,
|
| 557 |
+
18,
|
| 558 |
+
64,
|
| 559 |
+
51,
|
| 560 |
+
11,
|
| 561 |
+
69,
|
| 562 |
+
47,
|
| 563 |
+
23,
|
| 564 |
+
35,
|
| 565 |
+
43,
|
| 566 |
+
1,
|
| 567 |
+
62
|
| 568 |
+
],
|
| 569 |
+
"output": false
|
| 570 |
+
}
|
| 571 |
+
],
|
| 572 |
+
"haskell_template": "isGood :: [Int] -> Bool\nisGood nums ",
|
| 573 |
+
"ocaml_template": "let isGood (nums: int list) : bool = ",
|
| 574 |
+
"scala_template": "def isGood(nums: List[Int]): Boolean = { \n \n}",
|
| 575 |
+
"java_template": "public static boolean isGood(List<Integer> nums) {\n\n}",
|
| 576 |
+
"python_template": "class Solution(object):\n def isGood(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n "
|
| 577 |
+
}
|
check_if_array_is_good/ocaml_tests/main.ml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 false (isGood [2; 1; 3])
|
| 12 |
+
|
| 13 |
+
let test2 _ = assert_equal true (isGood [1; 3; 3; 2])
|
| 14 |
+
|
| 15 |
+
let test3 _ = assert_equal true (isGood [1; 1])
|
| 16 |
+
|
| 17 |
+
let test4 _ = assert_equal false (isGood [3; 4; 4; 1; 2; 1])
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
(* Grouping test cases *)
|
| 21 |
+
let suite = "Test Suite for isGood" >::: [
|
| 22 |
+
|
| 23 |
+
"test1" >:: test1;
|
| 24 |
+
"test2" >:: test2;
|
| 25 |
+
"test3" >:: test3;
|
| 26 |
+
"test4" >:: test4;
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
(* Running the tests *)
|
| 31 |
+
let () = run_test_tt_main suite
|
| 32 |
+
end
|
check_if_array_is_good/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.isGood(List(2, 1, 3)), false)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.isGood(List(1, 3, 3, 2)), true)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.isGood(List(1, 1)), true)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.isGood(List(3, 4, 4, 1, 2, 1)), false)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
}
|
check_if_bitwise_or_has_trailing_zeros/haskell_tests/Main.hs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main where
|
| 3 |
+
import Test.HUnit
|
| 4 |
+
|
| 5 |
+
--Program start
|
| 6 |
+
hasTrailingZeros :: [Int] -> Bool
|
| 7 |
+
hasTrailingZeros nums = undefined
|
| 8 |
+
|
| 9 |
+
--Program end
|
| 10 |
+
|
| 11 |
+
-- Test cases
|
| 12 |
+
|
| 13 |
+
test1 :: Test
|
| 14 |
+
test1 = TestCase (assertEqual "for (hasTrailingZeros [1,2,3,4,5])," True (hasTrailingZeros [1,2,3,4,5]))
|
| 15 |
+
|
| 16 |
+
test2 :: Test
|
| 17 |
+
test2 = TestCase (assertEqual "for (hasTrailingZeros [2,4,8,16])," True (hasTrailingZeros [2,4,8,16]))
|
| 18 |
+
|
| 19 |
+
test3 :: Test
|
| 20 |
+
test3 = TestCase (assertEqual "for (hasTrailingZeros [1,3,5,7,9])," False (hasTrailingZeros [1,3,5,7,9]))
|
| 21 |
+
|
| 22 |
+
test4 :: Test
|
| 23 |
+
test4 = TestCase (assertEqual "for (hasTrailingZeros [38, 96, 54, 93, 34, 65, 95, 25, 63, 49, 32, 96, 5, 46, 95, 16, 53, 25, 1, 84, 18, 3, 91, 20, 63, 11, 71, 63, 63, 2, 98, 68])," True (hasTrailingZeros [38, 96, 54, 93, 34, 65, 95, 25, 63, 49, 32, 96, 5, 46, 95, 16, 53, 25, 1, 84, 18, 3, 91, 20, 63, 11, 71, 63, 63, 2, 98, 68]))
|
| 24 |
+
|
| 25 |
+
test5 :: Test
|
| 26 |
+
test5 = TestCase (assertEqual "for (hasTrailingZeros [17, 64, 92, 91, 94, 66, 87, 91, 18, 44, 65, 37, 41, 16, 38, 74, 91, 37, 38, 36, 9, 4, 7, 75, 3])," True (hasTrailingZeros [17, 64, 92, 91, 94, 66, 87, 91, 18, 44, 65, 37, 41, 16, 38, 74, 91, 37, 38, 36, 9, 4, 7, 75, 3]))
|
| 27 |
+
|
| 28 |
+
test6 :: Test
|
| 29 |
+
test6 = TestCase (assertEqual "for (hasTrailingZeros [73, 56, 23, 72, 18, 92, 82, 54, 87, 3, 1, 77, 70, 15, 24, 72, 47, 27, 82, 11, 87, 21, 47, 75, 53, 3, 21, 4, 84, 64, 4, 36, 52, 40, 80, 86, 25, 74, 1, 2, 90, 35, 5, 82, 45, 59, 78, 1, 56, 16, 63, 69, 86, 65, 62, 8, 54, 92, 35])," True (hasTrailingZeros [73, 56, 23, 72, 18, 92, 82, 54, 87, 3, 1, 77, 70, 15, 24, 72, 47, 27, 82, 11, 87, 21, 47, 75, 53, 3, 21, 4, 84, 64, 4, 36, 52, 40, 80, 86, 25, 74, 1, 2, 90, 35, 5, 82, 45, 59, 78, 1, 56, 16, 63, 69, 86, 65, 62, 8, 54, 92, 35]))
|
| 30 |
+
|
| 31 |
+
test7 :: Test
|
| 32 |
+
test7 = TestCase (assertEqual "for (hasTrailingZeros [26, 41, 28, 25, 23, 11, 71, 31, 38, 23, 58, 87, 51, 80, 73, 53, 69, 94, 65, 73, 92, 96, 82, 89, 33, 51, 68, 16, 73, 92, 7, 13, 25, 35, 42, 34, 3, 45, 84, 73, 47, 60, 83, 16, 94, 85, 90, 19, 58, 32, 29, 2, 19, 90, 80, 60, 21, 64, 21, 50, 27, 8, 71, 59, 19, 55, 13, 31, 92, 36, 90, 44, 29, 88])," True (hasTrailingZeros [26, 41, 28, 25, 23, 11, 71, 31, 38, 23, 58, 87, 51, 80, 73, 53, 69, 94, 65, 73, 92, 96, 82, 89, 33, 51, 68, 16, 73, 92, 7, 13, 25, 35, 42, 34, 3, 45, 84, 73, 47, 60, 83, 16, 94, 85, 90, 19, 58, 32, 29, 2, 19, 90, 80, 60, 21, 64, 21, 50, 27, 8, 71, 59, 19, 55, 13, 31, 92, 36, 90, 44, 29, 88]))
|
| 33 |
+
|
| 34 |
+
test8 :: Test
|
| 35 |
+
test8 = TestCase (assertEqual "for (hasTrailingZeros [3, 80, 72, 87, 40, 47, 92, 43, 47, 27, 51, 14, 23])," True (hasTrailingZeros [3, 80, 72, 87, 40, 47, 92, 43, 47, 27, 51, 14, 23]))
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
-- Grouping test cases
|
| 39 |
+
tests :: Test
|
| 40 |
+
tests = TestList [TestLabel "Test1" test1, TestLabel "Test2" test2, TestLabel "Test3" test3, TestLabel "Test4" test4, TestLabel "Test5" test5, TestLabel "Test6" test6, TestLabel "Test7" test7]
|
| 41 |
+
|
| 42 |
+
-- Running the tests
|
| 43 |
+
main :: IO Counts
|
| 44 |
+
main = runTestTT tests
|
check_if_bitwise_or_has_trailing_zeros/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(true, hasTrailingZeros(Arrays.asList(1,2,3,4,5)));
|
| 14 |
+
}
|
| 15 |
+
@Test
|
| 16 |
+
public void test2() {
|
| 17 |
+
assertEquals(true, hasTrailingZeros(Arrays.asList(2,4,8,16)));
|
| 18 |
+
}
|
| 19 |
+
@Test
|
| 20 |
+
public void test3() {
|
| 21 |
+
assertEquals(false, hasTrailingZeros(Arrays.asList(1,3,5,7,9)));
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
}
|
check_if_bitwise_or_has_trailing_zeros/meta.json
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3246,
|
| 3 |
+
"name": "check_if_bitwise_or_has_trailing_zeros",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-bitwise-or-has-trailing-zeros/",
|
| 6 |
+
"date": "2023-12-24 00:00:00",
|
| 7 |
+
"task_description": "You are given an array of **positive** integers `nums`. You have to check if it is possible to select **two or more** elements in the array such that the bitwise `OR` of the selected elements has **at least **one trailing zero in its binary representation. For example, the binary representation of `5`, which is `\"101\"`, does not have any trailing zeros, whereas the binary representation of `4`, which is `\"100\"`, has two trailing zeros. Return `true` _if it is possible to select two or more elements whose bitwise_ `OR` _has trailing zeros, return_ `false` _otherwise_. **Example 1:** ``` **Input:** nums = [1,2,3,4,5] **Output:** true **Explanation:** If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero. ``` **Example 2:** ``` **Input:** nums = [2,4,8,16] **Output:** true **Explanation: **If we select the elements 2 and 4, their bitwise OR is 6, which has the binary representation \"110\" with one trailing zero. Other possible ways to select elements to have trailing zeroes in the binary representation of their bitwise OR are: (2, 8), (2, 16), (4, 8), (4, 16), (8, 16), (2, 4, 8), (2, 4, 16), (2, 8, 16), (4, 8, 16), and (2, 4, 8, 16). ``` **Example 3:** ``` **Input:** nums = [1,3,5,7,9] **Output:** false **Explanation:** There is no possible way to select two or more elements to have trailing zeros in the binary representation of their bitwise OR. ``` **Constraints:** `2 <= nums.length <= 100` `1 <= nums[i] <= 100`",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "nums = [1,2,3,4,5]",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "nums = [2,4,8,16]",
|
| 17 |
+
"output": "true "
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"label": "Example 3",
|
| 21 |
+
"input": "nums = [1,3,5,7,9]",
|
| 22 |
+
"output": "false "
|
| 23 |
+
}
|
| 24 |
+
],
|
| 25 |
+
"private_test_cases": [
|
| 26 |
+
{
|
| 27 |
+
"input": [
|
| 28 |
+
38,
|
| 29 |
+
96,
|
| 30 |
+
54,
|
| 31 |
+
93,
|
| 32 |
+
34,
|
| 33 |
+
65,
|
| 34 |
+
95,
|
| 35 |
+
25,
|
| 36 |
+
63,
|
| 37 |
+
49,
|
| 38 |
+
32,
|
| 39 |
+
96,
|
| 40 |
+
5,
|
| 41 |
+
46,
|
| 42 |
+
95,
|
| 43 |
+
16,
|
| 44 |
+
53,
|
| 45 |
+
25,
|
| 46 |
+
1,
|
| 47 |
+
84,
|
| 48 |
+
18,
|
| 49 |
+
3,
|
| 50 |
+
91,
|
| 51 |
+
20,
|
| 52 |
+
63,
|
| 53 |
+
11,
|
| 54 |
+
71,
|
| 55 |
+
63,
|
| 56 |
+
63,
|
| 57 |
+
2,
|
| 58 |
+
98,
|
| 59 |
+
68
|
| 60 |
+
],
|
| 61 |
+
"output": true
|
| 62 |
+
},
|
| 63 |
+
{
|
| 64 |
+
"input": [
|
| 65 |
+
17,
|
| 66 |
+
64,
|
| 67 |
+
92,
|
| 68 |
+
91,
|
| 69 |
+
94,
|
| 70 |
+
66,
|
| 71 |
+
87,
|
| 72 |
+
91,
|
| 73 |
+
18,
|
| 74 |
+
44,
|
| 75 |
+
65,
|
| 76 |
+
37,
|
| 77 |
+
41,
|
| 78 |
+
16,
|
| 79 |
+
38,
|
| 80 |
+
74,
|
| 81 |
+
91,
|
| 82 |
+
37,
|
| 83 |
+
38,
|
| 84 |
+
36,
|
| 85 |
+
9,
|
| 86 |
+
4,
|
| 87 |
+
7,
|
| 88 |
+
75,
|
| 89 |
+
3
|
| 90 |
+
],
|
| 91 |
+
"output": true
|
| 92 |
+
},
|
| 93 |
+
{
|
| 94 |
+
"input": [
|
| 95 |
+
73,
|
| 96 |
+
56,
|
| 97 |
+
23,
|
| 98 |
+
72,
|
| 99 |
+
18,
|
| 100 |
+
92,
|
| 101 |
+
82,
|
| 102 |
+
54,
|
| 103 |
+
87,
|
| 104 |
+
3,
|
| 105 |
+
1,
|
| 106 |
+
77,
|
| 107 |
+
70,
|
| 108 |
+
15,
|
| 109 |
+
24,
|
| 110 |
+
72,
|
| 111 |
+
47,
|
| 112 |
+
27,
|
| 113 |
+
82,
|
| 114 |
+
11,
|
| 115 |
+
87,
|
| 116 |
+
21,
|
| 117 |
+
47,
|
| 118 |
+
75,
|
| 119 |
+
53,
|
| 120 |
+
3,
|
| 121 |
+
21,
|
| 122 |
+
4,
|
| 123 |
+
84,
|
| 124 |
+
64,
|
| 125 |
+
4,
|
| 126 |
+
36,
|
| 127 |
+
52,
|
| 128 |
+
40,
|
| 129 |
+
80,
|
| 130 |
+
86,
|
| 131 |
+
25,
|
| 132 |
+
74,
|
| 133 |
+
1,
|
| 134 |
+
2,
|
| 135 |
+
90,
|
| 136 |
+
35,
|
| 137 |
+
5,
|
| 138 |
+
82,
|
| 139 |
+
45,
|
| 140 |
+
59,
|
| 141 |
+
78,
|
| 142 |
+
1,
|
| 143 |
+
56,
|
| 144 |
+
16,
|
| 145 |
+
63,
|
| 146 |
+
69,
|
| 147 |
+
86,
|
| 148 |
+
65,
|
| 149 |
+
62,
|
| 150 |
+
8,
|
| 151 |
+
54,
|
| 152 |
+
92,
|
| 153 |
+
35
|
| 154 |
+
],
|
| 155 |
+
"output": true
|
| 156 |
+
},
|
| 157 |
+
{
|
| 158 |
+
"input": [
|
| 159 |
+
26,
|
| 160 |
+
41,
|
| 161 |
+
28,
|
| 162 |
+
25,
|
| 163 |
+
23,
|
| 164 |
+
11,
|
| 165 |
+
71,
|
| 166 |
+
31,
|
| 167 |
+
38,
|
| 168 |
+
23,
|
| 169 |
+
58,
|
| 170 |
+
87,
|
| 171 |
+
51,
|
| 172 |
+
80,
|
| 173 |
+
73,
|
| 174 |
+
53,
|
| 175 |
+
69,
|
| 176 |
+
94,
|
| 177 |
+
65,
|
| 178 |
+
73,
|
| 179 |
+
92,
|
| 180 |
+
96,
|
| 181 |
+
82,
|
| 182 |
+
89,
|
| 183 |
+
33,
|
| 184 |
+
51,
|
| 185 |
+
68,
|
| 186 |
+
16,
|
| 187 |
+
73,
|
| 188 |
+
92,
|
| 189 |
+
7,
|
| 190 |
+
13,
|
| 191 |
+
25,
|
| 192 |
+
35,
|
| 193 |
+
42,
|
| 194 |
+
34,
|
| 195 |
+
3,
|
| 196 |
+
45,
|
| 197 |
+
84,
|
| 198 |
+
73,
|
| 199 |
+
47,
|
| 200 |
+
60,
|
| 201 |
+
83,
|
| 202 |
+
16,
|
| 203 |
+
94,
|
| 204 |
+
85,
|
| 205 |
+
90,
|
| 206 |
+
19,
|
| 207 |
+
58,
|
| 208 |
+
32,
|
| 209 |
+
29,
|
| 210 |
+
2,
|
| 211 |
+
19,
|
| 212 |
+
90,
|
| 213 |
+
80,
|
| 214 |
+
60,
|
| 215 |
+
21,
|
| 216 |
+
64,
|
| 217 |
+
21,
|
| 218 |
+
50,
|
| 219 |
+
27,
|
| 220 |
+
8,
|
| 221 |
+
71,
|
| 222 |
+
59,
|
| 223 |
+
19,
|
| 224 |
+
55,
|
| 225 |
+
13,
|
| 226 |
+
31,
|
| 227 |
+
92,
|
| 228 |
+
36,
|
| 229 |
+
90,
|
| 230 |
+
44,
|
| 231 |
+
29,
|
| 232 |
+
88
|
| 233 |
+
],
|
| 234 |
+
"output": true
|
| 235 |
+
},
|
| 236 |
+
{
|
| 237 |
+
"input": [
|
| 238 |
+
3,
|
| 239 |
+
80,
|
| 240 |
+
72,
|
| 241 |
+
87,
|
| 242 |
+
40,
|
| 243 |
+
47,
|
| 244 |
+
92,
|
| 245 |
+
43,
|
| 246 |
+
47,
|
| 247 |
+
27,
|
| 248 |
+
51,
|
| 249 |
+
14,
|
| 250 |
+
23
|
| 251 |
+
],
|
| 252 |
+
"output": true
|
| 253 |
+
}
|
| 254 |
+
],
|
| 255 |
+
"haskell_template": "hasTrailingZeros :: [Int] -> Bool\nhasTrailingZeros nums ",
|
| 256 |
+
"ocaml_template": "let hasTrailingZeros (nums: int list) : bool = ",
|
| 257 |
+
"scala_template": "def hasTrailingZeros(nums: List[Int]): Boolean = { \n \n}",
|
| 258 |
+
"java_template": "class Solution {\n public boolean hasTrailingZeros(int[] nums) {\n \n }\n}",
|
| 259 |
+
"python_template": "class Solution(object):\n def hasTrailingZeros(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n "
|
| 260 |
+
}
|
check_if_bitwise_or_has_trailing_zeros/ocaml_tests/main.ml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main = struct
|
| 3 |
+
open OUnit2
|
| 4 |
+
|
| 5 |
+
(* Program start *)
|
| 6 |
+
let hasTrailingZeros (nums: int list) : bool = failwith "Not implemented"
|
| 7 |
+
|
| 8 |
+
(* Program end *)
|
| 9 |
+
|
| 10 |
+
(* Test cases *)
|
| 11 |
+
|
| 12 |
+
let test1 _ = assert_equal true (hasTrailingZeros [1;2;3;4;5])
|
| 13 |
+
|
| 14 |
+
let test2 _ = assert_equal true (hasTrailingZeros [2;4;8;16])
|
| 15 |
+
|
| 16 |
+
let test3 _ = assert_equal false (hasTrailingZeros [1;3;5;7;9])
|
| 17 |
+
|
| 18 |
+
let test4 _ = assert_equal false (hasTrailingZeros [38; 96; 54; 93; 34; 65; 95; 25; 63; 49; 32; 96; 5; 46; 95; 16; 53; 25; 1; 84; 18; 3; 91; 20; 63; 11; 71; 63; 63; 2; 98; 68])
|
| 19 |
+
|
| 20 |
+
let test5 _ = assert_equal false (hasTrailingZeros [17; 64; 92; 91; 94; 66; 87; 91; 18; 44; 65; 37; 41; 16; 38; 74; 91; 37; 38; 36; 9; 4; 7; 75; 3])
|
| 21 |
+
|
| 22 |
+
let test6 _ = assert_equal false (hasTrailingZeros [73; 56; 23; 72; 18; 92; 82; 54; 87; 3; 1; 77; 70; 15; 24; 72; 47; 27; 82; 11; 87; 21; 47; 75; 53; 3; 21; 4; 84; 64; 4; 36; 52; 40; 80; 86; 25; 74; 1; 2; 90; 35; 5; 82; 45; 59; 78; 1; 56; 16; 63; 69; 86; 65; 62; 8; 54; 92; 35])
|
| 23 |
+
|
| 24 |
+
let test7 _ = assert_equal false (hasTrailingZeros [26; 41; 28; 25; 23; 11; 71; 31; 38; 23; 58; 87; 51; 80; 73; 53; 69; 94; 65; 73; 92; 96; 82; 89; 33; 51; 68; 16; 73; 92; 7; 13; 25; 35; 42; 34; 3; 45; 84; 73; 47; 60; 83; 16; 94; 85; 90; 19; 58; 32; 29; 2; 19; 90; 80; 60; 21; 64; 21; 50; 27; 8; 71; 59; 19; 55; 13; 31; 92; 36; 90; 44; 29; 88])
|
| 25 |
+
|
| 26 |
+
let test8 _ = assert_equal false (hasTrailingZeros [3; 80; 72; 87; 40; 47; 92; 43; 47; 27; 51; 14; 23])
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
(* Grouping test cases *)
|
| 30 |
+
let suite = "Test Suite for hasTrailingZeros" >::: [
|
| 31 |
+
|
| 32 |
+
"test1" >:: test1;
|
| 33 |
+
"test2" >:: test2;
|
| 34 |
+
"test3" >:: test3;
|
| 35 |
+
"test4" >:: test4;
|
| 36 |
+
"test5" >:: test5;
|
| 37 |
+
"test6" >:: test6;
|
| 38 |
+
"test7" >:: test7;
|
| 39 |
+
"test8" >:: test8;
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
(* Running the tests *)
|
| 44 |
+
let () = run_test_tt_main suite
|
| 45 |
+
end
|
check_if_bitwise_or_has_trailing_zeros/scala_tests/MySuite.scala
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
class MySuite extends munit.FunSuite {
|
| 3 |
+
|
| 4 |
+
test("test1") {
|
| 5 |
+
assertEquals(Main.hasTrailingZeros(List(1,2,3,4,5)), true)
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
test("test2") {
|
| 9 |
+
assertEquals(Main.hasTrailingZeros(List(2,4,8,16)), true)
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
test("test3") {
|
| 13 |
+
assertEquals(Main.hasTrailingZeros(List(1,3,5,7,9)), false)
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
test("test4") {
|
| 17 |
+
assertEquals(Main.hasTrailingZeros(38,96,54,93,34,65,95,25,63,49,32,96,5,46,95,16,53,25,1,84,18,3,91,20,63,11,71,63,63,2,98,68), true)
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
test("test5") {
|
| 21 |
+
assertEquals(Main.hasTrailingZeros(17,64,92,91,94,66,87,91,18,44,65,37,41,16,38,74,91,37,38,36,9,4,7,75,3), true)
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
test("test6") {
|
| 25 |
+
assertEquals(Main.hasTrailingZeros(73,56,23,72,18,92,82,54,87,3,1,77,70,15,24,72,47,27,82,11,87,21,47,75,53,3,21,4,84,64,4,36,52,40,80,86,25,74,1,2,90,35,5,82,45,59,78,1,56,16,63,69,86,65,62,8,54,92,35), true)
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
test("test7") {
|
| 29 |
+
assertEquals(Main.hasTrailingZeros(26,41,28,25,23,11,71,31,38,23,58,87,51,80,73,53,69,94,65,73,92,96,82,89,33,51,68,16,73,92,7,13,25,35,42,34,3,45,84,73,47,60,83,16,94,85,90,19,58,32,29,2,19,90,80,60,21,64,21,50,27,8,71,59,19,55,13,31,92,36,90,44,29,88), true)
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
test("test8") {
|
| 33 |
+
assertEquals(Main.hasTrailingZeros(3,80,72,87,40,47,92,43,47,27,51,14,23), true)
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
}
|
check_if_dfs_strings_are_palindromes/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(true,true,false,true,true,true)), findAnswer(new ArrayList<>(Arrays.asList(-1,0,0,1,1,2)), "aababa"));
|
| 15 |
+
}
|
| 16 |
+
@Test
|
| 17 |
+
public void test2() {
|
| 18 |
+
assertEquals(new ArrayList<>(Arrays.asList(true,true,true,true,true)), findAnswer(new ArrayList<>(Arrays.asList(-1,0,0,0,0)), "aabcb"));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
}
|
check_if_digits_are_equal_in_string_after_operations_i/haskell_tests/Main.hs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
module Main where
|
| 3 |
+
import Test.HUnit
|
| 4 |
+
|
| 5 |
+
--Program start
|
| 6 |
+
hasSameDigits :: String -> Bool
|
| 7 |
+
hasSameDigits s = undefined
|
| 8 |
+
|
| 9 |
+
--Program end
|
| 10 |
+
|
| 11 |
+
-- Test cases
|
| 12 |
+
|
| 13 |
+
test1 :: Test
|
| 14 |
+
test1 = TestCase (assertEqual "for (hasSameDigits \"3902 \")," True (hasSameDigits "3902"))
|
| 15 |
+
|
| 16 |
+
test2 :: Test
|
| 17 |
+
test2 = TestCase (assertEqual "for (hasSameDigits \"34789 \")," False (hasSameDigits "34789"))
|
| 18 |
+
|
| 19 |
+
test3 :: Test
|
| 20 |
+
test3 = TestCase (assertEqual "for (hasSameDigits \"080106026594954500183678394943283033982 \")," False (hasSameDigits "080106026594954500183678394943283033982"))
|
| 21 |
+
|
| 22 |
+
test4 :: Test
|
| 23 |
+
test4 = TestCase (assertEqual "for (hasSameDigits \"00486228987769246002704187817143095792028728199148076753 \")," False (hasSameDigits "00486228987769246002704187817143095792028728199148076753"))
|
| 24 |
+
|
| 25 |
+
test5 :: Test
|
| 26 |
+
test5 = TestCase (assertEqual "for (hasSameDigits \"3570365 \")," False (hasSameDigits "3570365"))
|
| 27 |
+
|
| 28 |
+
test6 :: Test
|
| 29 |
+
test6 = TestCase (assertEqual "for (hasSameDigits \"92620400561677676252552905 \")," False (hasSameDigits "92620400561677676252552905"))
|
| 30 |
+
|
| 31 |
+
test7 :: Test
|
| 32 |
+
test7 = TestCase (assertEqual "for (hasSameDigits \"875309239615263366778154628481005783992597976749683081112195313738052054049604554683400901666054 \")," False (hasSameDigits "875309239615263366778154628481005783992597976749683081112195313738052054049604554683400901666054"))
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
-- Grouping test cases
|
| 36 |
+
tests :: Test
|
| 37 |
+
tests = TestList [TestLabel "Test1" test1, TestLabel "Test2" test2, TestLabel "Test3" test3, TestLabel "Test4" test4, TestLabel "Test5" test5, TestLabel "Test6" test6]
|
| 38 |
+
|
| 39 |
+
-- Running the tests
|
| 40 |
+
main :: IO Counts
|
| 41 |
+
main = runTestTT tests
|
check_if_digits_are_equal_in_string_after_operations_i/java_tests/Main.java
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import static org.junit.jupiter.api.Assertions.*;
|
| 3 |
+
import org.junit.jupiter.api.Test;
|
| 4 |
+
import java.util.List;
|
| 5 |
+
import java.util.Arrays;
|
| 6 |
+
public class Main {
|
| 7 |
+
//Program start
|
| 8 |
+
|
| 9 |
+
//Program end
|
| 10 |
+
|
| 11 |
+
@Test
|
| 12 |
+
public void test1() {
|
| 13 |
+
assertEquals(true, hasSameDigits("3902"));
|
| 14 |
+
}
|
| 15 |
+
@Test
|
| 16 |
+
public void test2() {
|
| 17 |
+
assertEquals(false, hasSameDigits("34789"));
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
}
|
check_if_digits_are_equal_in_string_after_operations_i/meta.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": 3768,
|
| 3 |
+
"name": "check_if_digits_are_equal_in_string_after_operations_i",
|
| 4 |
+
"difficulty": "Easy",
|
| 5 |
+
"link": "https://leetcode.com/problems/check-if-digits-are-equal-in-string-after-operations-i/",
|
| 6 |
+
"date": "2025-02-16 00:00:00",
|
| 7 |
+
"task_description": "You are given a string `s` consisting of digits. Perform the following operation repeatedly until the string has **exactly** two digits: For each pair of consecutive digits in `s`, starting from the first digit, calculate a new digit as the sum of the two digits **modulo** 10. Replace `s` with the sequence of newly calculated digits, _maintaining the order_ in which they are computed. Return `true` if the final two digits in `s` are the **same**; otherwise, return `false`. **Example 1:** **Input:** s = \"3902\" **Output:** true **Explanation:** Initially, `s = \"3902\"` First operation: `(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2` `(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9` `(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2` `s` becomes `\"292\"` Second operation: `(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1` `(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1` `s` becomes `\"11\"` Since the digits in `\"11\"` are the same, the output is `true`. **Example 2:** **Input:** s = \"34789\" **Output:** false **Explanation:** Initially, `s = \"34789\"`. After the first operation, `s = \"7157\"`. After the second operation, `s = \"862\"`. After the third operation, `s = \"48\"`. Since `'4' != '8'`, the output is `false`. **Constraints:** `3 <= s.length <= 100` `s` consists of only digits.",
|
| 8 |
+
"public_test_cases": [
|
| 9 |
+
{
|
| 10 |
+
"label": "Example 1",
|
| 11 |
+
"input": "s = \"3902\"",
|
| 12 |
+
"output": "true "
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"label": "Example 2",
|
| 16 |
+
"input": "s = \"34789\"",
|
| 17 |
+
"output": "false "
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"private_test_cases": [
|
| 21 |
+
{
|
| 22 |
+
"input": "080106026594954500183678394943283033982",
|
| 23 |
+
"output": false
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"input": "00486228987769246002704187817143095792028728199148076753",
|
| 27 |
+
"output": false
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"input": "3570365",
|
| 31 |
+
"output": false
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"input": "92620400561677676252552905",
|
| 35 |
+
"output": false
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"input": "875309239615263366778154628481005783992597976749683081112195313738052054049604554683400901666054",
|
| 39 |
+
"output": false
|
| 40 |
+
}
|
| 41 |
+
],
|
| 42 |
+
"haskell_template": "hasSameDigits :: String -> Bool\nhasSameDigits s ",
|
| 43 |
+
"ocaml_template": "let hasSameDigits (s: string) : bool = ",
|
| 44 |
+
"scala_template": "def hasSameDigits(s: String): Boolean = { \n \n}",
|
| 45 |
+
"java_template": "class Solution {\n public boolean hasSameDigits(String s) {\n \n }\n}",
|
| 46 |
+
"python_template": "class Solution(object):\n def hasSameDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"\n "
|
| 47 |
+
}
|