qid
stringlengths 1
3
| title
stringlengths 9
106
| language
stringclasses 1
value | signature
stringlengths 24
145
| arguments
sequence | source_py
stringlengths 54
989
| source_cpp
stringlengths 59
951
| question_info
dict |
---|---|---|---|---|---|---|---|
1 | Add 1 To A Given Number 1 | C++ | int add1ToAGivenNumber1(int x) { | [
"x"
] | def add_1_to_a_given_number_1(x):
return (- (~ x)) | int add_1_to_a_given_number_1(int x) {
return ( - ( ~ x ) );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(20, 21); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 69); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 53); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 62); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 89); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 42); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 79); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 95); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 19); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "add1ToAGivenNumber1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 21, \"inputs\": {\"x\": 20}}, {\"idx\": 1, \"outputs\": 69, \"inputs\": {\"x\": 68}}, {\"idx\": 2, \"outputs\": 53, \"inputs\": {\"x\": 52}}, {\"idx\": 3, \"outputs\": 62, \"inputs\": {\"x\": 61}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"x\": 3}}, {\"idx\": 5, \"outputs\": 89, \"inputs\": {\"x\": 88}}, {\"idx\": 6, \"outputs\": 42, \"inputs\": {\"x\": 41}}, {\"idx\": 7, \"outputs\": 79, \"inputs\": {\"x\": 78}}, {\"idx\": 8, \"outputs\": 95, \"inputs\": {\"x\": 94}}, {\"idx\": 9, \"outputs\": 19, \"inputs\": {\"x\": 18}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
2 | Add Two Numbers Without Using Arithmetic Operators | C++ | int addTwoNumbersWithoutUsingArithmeticOperators(int x, int y) { | [
"x",
"y"
] | def add_two_numbers_without_using_arithmetic_operators(x, y):
while (y != 0):
carry = (x & y)
x = (x ^ y)
y = (carry << 1)
return x | int add_two_numbers_without_using_arithmetic_operators(int x, int y) {
while ( y != 0 ) {
int carry = x & y;
x = x ^ y;
y = carry << 1;
}
return x;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(56, 60, 116); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 44, 61); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 96, 169); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 3, 78); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 54, 81); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 1, 62); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 63, 128); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 19, 41); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 9, 70); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 23, 120); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "addTwoNumbersWithoutUsingArithmeticOperators",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 116, \"inputs\": {\"x\": 56, \"y\": 60}}, {\"idx\": 1, \"outputs\": 61, \"inputs\": {\"x\": 17, \"y\": 44}}, {\"idx\": 2, \"outputs\": 169, \"inputs\": {\"x\": 73, \"y\": 96}}, {\"idx\": 3, \"outputs\": 78, \"inputs\": {\"x\": 75, \"y\": 3}}, {\"idx\": 4, \"outputs\": 81, \"inputs\": {\"x\": 27, \"y\": 54}}, {\"idx\": 5, \"outputs\": 62, \"inputs\": {\"x\": 61, \"y\": 1}}, {\"idx\": 6, \"outputs\": 128, \"inputs\": {\"x\": 65, \"y\": 63}}, {\"idx\": 7, \"outputs\": 41, \"inputs\": {\"x\": 22, \"y\": 19}}, {\"idx\": 8, \"outputs\": 70, \"inputs\": {\"x\": 61, \"y\": 9}}, {\"idx\": 9, \"outputs\": 120, \"inputs\": {\"x\": 97, \"y\": 23}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
3 | Analysis Of Algorithms Set 2 Asymptotic Analysis | C++ | int analysisOfAlgorithmsSet2AsymptoticAnalysis(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def analysis_of_algorithms_set_2_asymptotic_analysis(arr, n, x):
i = 0
for i in range(i, n):
if (arr[i] == x):
return i
return (- 1) | int analysis_of_algorithms_set_2_asymptotic_analysis(vector<int> arr, int n, int x) {
int i;
for ( i = 0;
i < n;
i ++ ) {
if ( arr [ i ] == x ) return i;
}
return - 1;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 5, 5, 11, 13, 14, 15, 19, 22, 22, 23, 26, 29, 29, 36, 44, 48, 49, 65, 65, 67, 68, 70, 76, 79, 79, 81, 85, 88, 91, 91, 92, 92, 97}, 17, 5, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-24, -78, -32, -48, 0, 4, -42}, 4, 0, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, 6, 0, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({38, 14, 75, 16, 91, 11, 98, 43, 67, 9, 21, 10, 82, 72, 32, 81, 48, 60, 2, 91, 10, 90, 12, 83}, 17, 75, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -92, -82, -80, -76, -66, -64, -64, -56, -48, -38, -38, -34, -32, -32, -10, -8, -6, -2, 0, 8, 10, 18, 20, 22, 22, 30, 34, 38, 38, 38, 44, 50, 52, 56, 64, 64, 66, 70, 76, 88}, 25, 25, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1}, 11, -1, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 4, 4, 4, 4, 8, 12, 13, 14, 14, 22, 25, 25, 27, 29, 33, 36, 38, 40, 40, 40, 41, 47, 47, 47, 48, 48, 50, 51, 52, 52, 52, 55, 56, 59, 59, 62, 64, 66, 77, 82, 84, 90, 91, 91, 93}, 38, 4, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -60, -58, -72, 92, 54, -32, -70, -94, 18, 64, -90, -90, -56, 82, -14, -74, -96, -90, -8, -48, 76, -28, 10, -52, -8, -46, -32, 82, 46, 58, 92, 4, 48, -96, -66, 60, 60, 62, -68}, 22, 22, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, 8, 8, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({42, 17, 77, 96, 72, 36, 74, 97, 7, 94, 80, 7, 27, 58, 49, 81, 51, 9}, 16, 11, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "analysisOfAlgorithmsSet2AsymptoticAnalysis",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [4, 5, 5, 11, 13, 14, 15, 19, 22, 22, 23, 26, 29, 29, 36, 44, 48, 49, 65, 65, 67, 68, 70, 76, 79, 79, 81, 85, 88, 91, 91, 92, 92, 97], \"n\": 17, \"x\": 5}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [-24, -78, -32, -48, 0, 4, -42], \"n\": 4, \"x\": 0}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 6, \"x\": 0}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"arr\": [38, 14, 75, 16, 91, 11, 98, 43, 67, 9, 21, 10, 82, 72, 32, 81, 48, 60, 2, 91, 10, 90, 12, 83], \"n\": 17, \"x\": 75}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-92, -92, -82, -80, -76, -66, -64, -64, -56, -48, -38, -38, -34, -32, -32, -10, -8, -6, -2, 0, 8, 10, 18, 20, 22, 22, 30, 34, 38, 38, 38, 44, 50, 52, 56, 64, 64, 66, 70, 76, 88], \"n\": 25, \"x\": 25}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1], \"n\": 11, \"x\": -1}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [1, 4, 4, 4, 4, 8, 12, 13, 14, 14, 22, 25, 25, 27, 29, 33, 36, 38, 40, 40, 40, 41, 47, 47, 47, 48, 48, 50, 51, 52, 52, 52, 55, 56, 59, 59, 62, 64, 66, 77, 82, 84, 90, 91, 91, 93], \"n\": 38, \"x\": 4}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-90, -60, -58, -72, 92, 54, -32, -70, -94, 18, 64, -90, -90, -56, 82, -14, -74, -96, -90, -8, -48, 76, -28, 10, -52, -8, -46, -32, 82, 46, 58, 92, 4, 48, -96, -66, 60, 60, 62, -68], \"n\": 22, \"x\": 22}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 8, \"x\": 8}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [42, 17, 77, 96, 72, 36, 74, 97, 7, 94, 80, 7, 27, 58, 49, 81, 51, 9], \"n\": 16, \"x\": 11}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
4 | Area Of A Hexagon | C++ | double areaOfAHexagon(double s) { | [
"s"
] | def area_of_a_hexagon(s):
return (((3 * math.sqrt(3)) * (s * s)) / 2) | double area_of_a_hexagon(double s) {
return ( ( 3 * sqrt ( 3 ) * ( s * s ) ) / 2 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(double s, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1772.6589509256596, 8163986.207300422); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-599.737107809315, 934487.9989101035); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1074.1765931782, 2997804.1448343466); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-1182.4087746714795, 3632345.696441302); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8083.035797247716, 169746524.38794258); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6126.414356565494, 97513471.98905805); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5370.057504189614, 74922068.46663411); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6947.020794285176, 125386010.4299519); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2110.5107873533325, 11572495.990484647); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6458.751326919488, 108379966.88267714); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "areaOfAHexagon",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 8163986.207300422, \"inputs\": {\"s\": 1772.6589509256596}}, {\"idx\": 1, \"outputs\": 934487.9989101035, \"inputs\": {\"s\": -599.737107809315}}, {\"idx\": 2, \"outputs\": 2997804.1448343466, \"inputs\": {\"s\": 1074.1765931782}}, {\"idx\": 3, \"outputs\": 3632345.696441302, \"inputs\": {\"s\": -1182.4087746714795}}, {\"idx\": 4, \"outputs\": 169746524.38794258, \"inputs\": {\"s\": 8083.035797247716}}, {\"idx\": 5, \"outputs\": 97513471.98905805, \"inputs\": {\"s\": -6126.414356565494}}, {\"idx\": 6, \"outputs\": 74922068.46663411, \"inputs\": {\"s\": 5370.057504189614}}, {\"idx\": 7, \"outputs\": 125386010.4299519, \"inputs\": {\"s\": -6947.020794285176}}, {\"idx\": 8, \"outputs\": 11572495.990484647, \"inputs\": {\"s\": 2110.5107873533325}}, {\"idx\": 9, \"outputs\": 108379966.88267714, \"inputs\": {\"s\": -6458.751326919488}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
5 | Area Of The Circle That Has A Square And A Circle Inscribed In It | C++ | double areaOfTheCircleThatHasASquareAndACircleInscribedInIt(int a) { | [
"a"
] | def area_of_the_circle_that_has_a_square_and_a_circle_inscribed_in_it(a):
area = (((math.pi * a) * a) / 4)
return area | float area_of_the_circle_that_has_a_square_and_a_circle_inscribed_in_it(int a) {
float area = ( M_PI * a * a ) / 4.0;
return area;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int a, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(77, 4656.625710783471); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 254.46900494077323); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 5410.607947645021); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 1194.5906065275187); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 3631.6811075498013); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 615.7521601035994); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 3959.192141686537); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 153.93804002589985); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 346.36059005827474); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 4185.386812745001); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "areaOfTheCircleThatHasASquareAndACircleInscribedInIt",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 4656.625710783471, \"inputs\": {\"a\": 77}}, {\"idx\": 1, \"outputs\": 254.46900494077323, \"inputs\": {\"a\": 18}}, {\"idx\": 2, \"outputs\": 5410.607947645021, \"inputs\": {\"a\": 83}}, {\"idx\": 3, \"outputs\": 1194.5906065275187, \"inputs\": {\"a\": 39}}, {\"idx\": 4, \"outputs\": 3631.6811075498013, \"inputs\": {\"a\": 68}}, {\"idx\": 5, \"outputs\": 615.7521601035994, \"inputs\": {\"a\": 28}}, {\"idx\": 6, \"outputs\": 3959.192141686537, \"inputs\": {\"a\": 71}}, {\"idx\": 7, \"outputs\": 153.93804002589985, \"inputs\": {\"a\": 14}}, {\"idx\": 8, \"outputs\": 346.36059005827474, \"inputs\": {\"a\": 21}}, {\"idx\": 9, \"outputs\": 4185.386812745001, \"inputs\": {\"a\": 73}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
6 | Area Square Circumscribed Circle | C++ | int areaSquareCircumscribedCircle(int r) { | [
"r"
] | def area_square_circumscribed_circle(r):
return ((2 * r) * r) | int area_square_circumscribed_circle(int r) {
return ( 2 * r * r );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int r, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(r), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(14, 392); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 12168); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 4050); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 8712); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 648); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 2048); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 7200); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 512); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 19602); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 8450); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "areaSquareCircumscribedCircle",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 392, \"inputs\": {\"r\": 14}}, {\"idx\": 1, \"outputs\": 12168, \"inputs\": {\"r\": 78}}, {\"idx\": 2, \"outputs\": 4050, \"inputs\": {\"r\": 45}}, {\"idx\": 3, \"outputs\": 8712, \"inputs\": {\"r\": 66}}, {\"idx\": 4, \"outputs\": 648, \"inputs\": {\"r\": 18}}, {\"idx\": 5, \"outputs\": 2048, \"inputs\": {\"r\": 32}}, {\"idx\": 6, \"outputs\": 7200, \"inputs\": {\"r\": 60}}, {\"idx\": 7, \"outputs\": 512, \"inputs\": {\"r\": 16}}, {\"idx\": 8, \"outputs\": 19602, \"inputs\": {\"r\": 99}}, {\"idx\": 9, \"outputs\": 8450, \"inputs\": {\"r\": 65}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
7 | Array Element Moved K Using Single Moves | C++ | int arrayElementMovedKUsingSingleMoves(vector<int> a, int n, int k) { | [
"a",
"n",
"k"
] | def array_element_moved_k_using_single_moves(a, n, k):
if (k >= (n - 1)):
return n
best = 0
times = 0
for i in range(n):
if (a[i] > best):
best = a[i]
if (i == True):
times = 1
else:
times += 1
if (times >= k):
return best
return best | int array_element_moved_k_using_single_moves(vector<int> a, int n, int k) {
if ( k >= n - 1 ) return n;
int best = 0, times = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] > best ) {
best = a [ i ];
if ( i ) times = 1;
}
else times += 1;
if ( times >= k ) return best;
}
return best;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 5, 5, 9, 10, 10, 11, 14, 23, 27, 31, 32, 33, 33, 33, 37, 39, 41, 41, 42, 42, 43, 47, 60, 61, 68, 73, 73, 73, 78, 80, 80, 82, 83, 86, 87, 89, 92, 94, 98}, 33, 37, 33); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, -58, 64, 48, -16, 60, -50, -52, 62, -86, -96, 52, 26, -30, 14}, 14, 13, 14); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, 7, 6, 7); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({90, 23, 43, 42, 7, 71, 79}, 4, 4, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -96, -90, -84, -68, -64, -56, -56, -50, -50, -48, -46, -28, -18, 0, 0, 6, 32, 32, 34, 42, 42, 46, 50, 50, 52, 64, 64, 70, 76, 84, 88}, 28, 21, 64); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1}, 1, 2, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 9, 15, 19, 26, 29, 42, 45, 46, 47, 55, 60, 60, 61, 62, 64, 68, 69, 74, 79, 96}, 14, 17, 14); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-32, 12, 80, 42, 80, 8, 58, -76, -42, -98, 22, -90, -16, -4, -62, -32, 28, 12, 78, -52, -84, 78, 88, -76, -52, 68, -34, -16, -4, 2, -78, -94, -22, 34, 6, -62, 72}, 26, 31, 26); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 26, 14, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, 19}, 1, 1, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "arrayElementMovedKUsingSingleMoves",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 33, \"inputs\": {\"a\": [2, 5, 5, 9, 10, 10, 11, 14, 23, 27, 31, 32, 33, 33, 33, 37, 39, 41, 41, 42, 42, 43, 47, 60, 61, 68, 73, 73, 73, 78, 80, 80, 82, 83, 86, 87, 89, 92, 94, 98], \"n\": 33, \"k\": 37}}, {\"idx\": 1, \"outputs\": 14, \"inputs\": {\"a\": [80, -58, 64, 48, -16, 60, -50, -52, 62, -86, -96, 52, 26, -30, 14], \"n\": 14, \"k\": 13}}, {\"idx\": 2, \"outputs\": 7, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1], \"n\": 7, \"k\": 6}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"a\": [90, 23, 43, 42, 7, 71, 79], \"n\": 4, \"k\": 4}}, {\"idx\": 4, \"outputs\": 64, \"inputs\": {\"a\": [-96, -96, -90, -84, -68, -64, -56, -56, -50, -50, -48, -46, -28, -18, 0, 0, 6, 32, 32, 34, 42, 42, 46, 50, 50, 52, 64, 64, 70, 76, 84, 88], \"n\": 28, \"k\": 21}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"a\": [1, 1, 1], \"n\": 1, \"k\": 2}}, {\"idx\": 6, \"outputs\": 14, \"inputs\": {\"a\": [2, 9, 15, 19, 26, 29, 42, 45, 46, 47, 55, 60, 60, 61, 62, 64, 68, 69, 74, 79, 96], \"n\": 14, \"k\": 17}}, {\"idx\": 7, \"outputs\": 26, \"inputs\": {\"a\": [-32, 12, 80, 42, 80, 8, 58, -76, -42, -98, 22, -90, -16, -4, -62, -32, 28, 12, 78, -52, -84, 78, 88, -76, -52, 68, -34, -16, -4, 2, -78, -94, -22, 34, 6, -62, 72], \"n\": 26, \"k\": 31}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 26, \"k\": 14}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"a\": [52, 19], \"n\": 1, \"k\": 1}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
8 | Array Range Queries Elements Frequency Value | C++ | int arrayRangeQueriesElementsFrequencyValue(int start, int end_arg1, vector<int> arr) { | [
"start",
"end_arg1",
"arr"
] | def array_range_queries_elements_frequency_value(start, end, arr):
frequency = dict()
for i in range(start, (end + 1)):
if (arr[i] in frequency.keys()):
frequency[arr[i]] += 1
else:
frequency[arr[i]] = 1
count = 0
for x in frequency:
if (x == frequency[x]):
count += 1
return count | int array_range_queries_elements_frequency_value(int start, int end, vector<int> arr) {
unordered_map < int, int > frequency;
for ( int i = start;
i <= end;
i ++ ) frequency [ arr [ i ] ] ++;
int count = 0;
for ( auto x : frequency ) if ( x . first == x . second ) count ++;
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int start, int end_arg1, vector<int> arr, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(start, end_arg1, arr), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(0, 31, {1, 2, 2, 3, 3, 3, 12, 13, 18, 18, 26, 28, 29, 36, 37, 39, 40, 49, 55, 57, 63, 69, 69, 73, 85, 86, 87, 87, 89, 89, 90, 91, 92, 93, 93, 93, 95, 99}, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 25, {24, -62, 2, 1, 94, 56, -22, -70, -22, -34, -92, -18, 56, 2, 60, 38, -88, 16, -28, 30, -30, 58, -80, 94, 6, 56}, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 4, {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 15, {84, 13, 81, 40, 87, 82, 50, 30, 90, 80, 81, 70, 14, 54, 72, 93, 78, 27, 61}, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 3, {-20, 20, 34, 60, 90}, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(0, 6, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 18, {11, 18, 18, 19, 25, 30, 42, 42, 56, 58, 63, 66, 67, 68, 69, 75, 78, 83, 83}, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 33, {-24, -82, 24, -84, 94, 2, -30, 86, 58, -56, -96, 60, -38, 76, 94, 74, -98, -84, -38, 46, 4, -84, -90, -28, -50, 46, 16, 28, -14, -82, -64, 42, 64, -2, -40, 96, 60, 2, -86, 32, 38, -66}, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 19, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 32, {2, 91, 42, 85, 97, 92, 24, 39, 63, 89, 31, 59, 51, 89, 72, 62, 26, 92, 75, 4, 6, 13, 20, 95, 22, 30, 52, 60, 37, 27, 49, 15, 67, 26}, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "arrayRangeQueriesElementsFrequencyValue",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"start\": 0, \"end_arg1\": 31, \"arr\": [1, 2, 2, 3, 3, 3, 12, 13, 18, 18, 26, 28, 29, 36, 37, 39, 40, 49, 55, 57, 63, 69, 69, 73, 85, 86, 87, 87, 89, 89, 90, 91, 92, 93, 93, 93, 95, 99]}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"start\": 1, \"end_arg1\": 25, \"arr\": [24, -62, 2, 1, 94, 56, -22, -70, -22, -34, -92, -18, 56, 2, 60, 38, -88, 16, -28, 30, -30, 58, -80, 94, 6, 56]}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"start\": 3, \"end_arg1\": 4, \"arr\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"start\": 10, \"end_arg1\": 15, \"arr\": [84, 13, 81, 40, 87, 82, 50, 30, 90, 80, 81, 70, 14, 54, 72, 93, 78, 27, 61]}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"start\": 2, \"end_arg1\": 3, \"arr\": [-20, 20, 34, 60, 90]}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"start\": 0, \"end_arg1\": 6, \"arr\": [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"start\": 14, \"end_arg1\": 18, \"arr\": [11, 18, 18, 19, 25, 30, 42, 42, 56, 58, 63, 66, 67, 68, 69, 75, 78, 83, 83]}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"start\": 29, \"end_arg1\": 33, \"arr\": [-24, -82, 24, -84, 94, 2, -30, 86, 58, -56, -96, 60, -38, 76, 94, 74, -98, -84, -38, 46, 4, -84, -90, -28, -50, 46, 16, 28, -14, -82, -64, 42, 64, -2, -40, 96, 60, 2, -86, 32, 38, -66]}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"start\": 31, \"end_arg1\": 19, \"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"start\": 21, \"end_arg1\": 32, \"arr\": [2, 91, 42, 85, 97, 92, 24, 39, 63, 89, 31, 59, 51, 89, 72, 62, 26, 92, 75, 4, 6, 13, 20, 95, 22, 30, 52, 60, 37, 27, 49, 15, 67, 26]}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
9 | Basic And Extended Euclidean Algorithms | C++ | int basicAndExtendedEuclideanAlgorithms(int a, int b) { | [
"a",
"b"
] | def basic_and_extended_euclidean_algorithms(a, b):
if (a == 0):
return b
return basic_and_extended_euclidean_algorithms((b % a), a) | int basic_and_extended_euclidean_algorithms(int a, int b) {
if ( a == 0 ) return b;
return basic_and_extended_euclidean_algorithms ( b % a, a );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(46, 89, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 82, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 12, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 4, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 44, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 87, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 65, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 87, 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 10, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 61, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "basicAndExtendedEuclideanAlgorithms",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"a\": 46, \"b\": 89}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"a\": 26, \"b\": 82}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"a\": 40, \"b\": 12}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"a\": 58, \"b\": 4}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"a\": 25, \"b\": 44}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"a\": 2, \"b\": 87}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"a\": 8, \"b\": 65}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"a\": 21, \"b\": 87}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"a\": 82, \"b\": 10}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"a\": 17, \"b\": 61}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
10 | Bell Numbers Number Of Ways To Partition A Set | C++ | int bellNumbersNumberOfWaysToPartitionASet(int n) { | [
"n"
] | def bell_numbers_number_of_ways_to_partition_a_set(n):
bell = [[0 for i in range((n + 1))] for j in range((n + 1))]
bell[0][0] = 1
for i in range(1, (n + 1)):
bell[i][0] = bell[(i - 1)][(i - 1)]
for j in range(1, (i + 1)):
bell[i][j] = (bell[(i - 1)][(j - 1)] + bell[i][(j - 1)])
return bell[n][0] | int bell_numbers_number_of_ways_to_partition_a_set(int n) {
int bell [ n + 1 ] [ n + 1 ];
bell [ 0 ] [ 0 ] = 1;
for ( int i = 1;
i <= n;
i ++ ) {
bell [ i ] [ 0 ] = bell [ i - 1 ] [ i - 1 ];
for ( int j = 1;
j <= i;
j ++ ) bell [ i ] [ j ] = bell [ i - 1 ] [ j - 1 ] + bell [ i ] [ j - 1 ];
}
return bell [ n ] [ 0 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(9, 21147); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 15); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 203); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "bellNumbersNumberOfWaysToPartitionASet",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 21147, \"inputs\": {\"n\": 9}}, {\"idx\": 1, \"outputs\": 15, \"inputs\": {\"n\": 4}}, {\"idx\": 2, \"outputs\": 203, \"inputs\": {\"n\": 6}}]",
"test_case_ids": [
"0",
"1",
"2"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
11 | Binary Search | C++ | int binarySearch(vector<int> arr, int l, int r, int x) { | [
"arr",
"l",
"r",
"x"
] | def binary_search(arr, l, r, x):
if (r >= l):
mid = (l + ((r - l) // 2))
if (arr[mid] == x):
return mid
elif (arr[mid] > x):
return binary_search(arr, l, (mid - 1), x)
else:
return binary_search(arr, (mid + 1), r, x)
else:
return (- 1) | int binary_search(vector<int> arr, int l, int r, int x) {
if ( r >= l ) {
int mid = l + ( r - l ) / 2;
if ( arr [ mid ] == x ) return mid;
if ( arr [ mid ] > x ) return binary_search ( arr, l, mid - 1, x );
return binary_search ( arr, mid + 1, r, x );
}
return - 1;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int l, int r, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, l, r, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({3, 4, 4, 8, 9, 13, 13, 15, 18, 27, 30, 32, 42, 48, 50, 52, 56, 66, 69, 69, 77, 84, 84, 93}, 19, 12, 22, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, -58, -22, -80, 44, -52, -34, 94, -34, -74, 42, 60, -62, 70, 98, 32, 10, 94, 26, 56, -48, -50, 42, 2, 46, 28, -68, -16, -96, -12, 66, -46, 74, -60, -52, 28, -92, -78, 32, 28, 16, 34, 30, -60, -14}, 40, 35, 44, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, 1, 1, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, 84, 40, 81}, 2, 2, 2, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-66, -62, -60, -56, -56, -2, 40, 44, 50, 74, 82, 94}, 8, 6, 8, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1}, 7, 7, 10, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({15, 26, 31, 36, 36, 61, 68, 72, 75, 79, 82, 98}, 6, 7, 8, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, -82, -94, 48, 48, -96, 14, 66, 76, -30, 86, 28, -28, -66, -64, 92, -94, -66, 86, 26, 8, 94, -82, -80, 4, -26, 76, -46, 72, 88, -6, 8, -30, 40, -88, 2, -40, -98, -22, -20, 4, -12, 54, -20, -36, 12}, 38, 33, 39, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 12, 10, 6, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({81, 47}, 1, 1, 1, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "binarySearch",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"arr\": [3, 4, 4, 8, 9, 13, 13, 15, 18, 27, 30, 32, 42, 48, 50, 52, 56, 66, 69, 69, 77, 84, 84, 93], \"l\": 19, \"r\": 12, \"x\": 22}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [52, -58, -22, -80, 44, -52, -34, 94, -34, -74, 42, 60, -62, 70, 98, 32, 10, 94, 26, 56, -48, -50, 42, 2, 46, 28, -68, -16, -96, -12, 66, -46, 74, -60, -52, 28, -92, -78, 32, 28, 16, 34, 30, -60, -14], \"l\": 40, \"r\": 35, \"x\": 44}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1], \"l\": 1, \"r\": 1, \"x\": 1}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [28, 84, 40, 81], \"l\": 2, \"r\": 2, \"x\": 2}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-66, -62, -60, -56, -56, -2, 40, 44, 50, 74, 82, 94], \"l\": 8, \"r\": 6, \"x\": 8}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1], \"l\": 7, \"r\": 7, \"x\": 10}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [15, 26, 31, 36, 36, 61, 68, 72, 75, 79, 82, 98], \"l\": 6, \"r\": 7, \"x\": 8}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [0, -82, -94, 48, 48, -96, 14, 66, 76, -30, 86, 28, -28, -66, -64, 92, -94, -66, 86, 26, 8, 94, -82, -80, 4, -26, 76, -46, 72, 88, -6, 8, -30, 40, -88, 2, -40, -98, -22, -20, 4, -12, 54, -20, -36, 12], \"l\": 38, \"r\": 33, \"x\": 39}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"l\": 12, \"r\": 10, \"x\": 6}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [81, 47], \"l\": 1, \"r\": 1, \"x\": 1}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
12 | Breaking Number First Part Integral Division Second Power 10 | C++ | int breakingNumberFirstPartIntegralDivisionSecondPower10(string n) { | [
"n"
] | def breaking_number_first_part_integral_division_second_power_10(N):
length = len(N)
l = int((length / 2))
count = 0
for i in range((l + 1)):
s = N[0:(0 + i)]
l1 = len(s)
t = N[i:(l1 + i)]
try:
if ((s[0] == '0') or (t[0] == '0')):
continue
except:
continue
if (s == t):
count += 1
return count | int breaking_number_first_part_integral_division_second_power_10(string N) {
int len = N . length ( );
int l = ( len ) / 2;
int count = 0;
for ( int i = 1;
i <= l;
i ++ ) {
string s = N . substr ( 0, i );
int l1 = s . length ( );
string t = N . substr ( i, l1 );
if ( s [ 0 ] == '0' || t [ 0 ] == '0' ) continue;
if ( s . compare ( t ) == 0 ) count ++;
}
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"ZCoQhuM\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2674377254\", 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"LbuGlvRyWAPBpo\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"26382426486138\", 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111010111010\", 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"hUInqJXNdbfP\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"5191\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1110101101\", 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2202200\", 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "breakingNumberFirstPartIntegralDivisionSecondPower10",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": \"ZCoQhuM\"}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"n\": \"2674377254\"}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"n\": \"11\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": \"LbuGlvRyWAPBpo\"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": \"26382426486138\"}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": \"111010111010\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": \"hUInqJXNdbfP\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": \"5191\"}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"n\": \"1110101101\"}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"n\": \"2202200\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
15 | Calculate Area Tetrahedron | C++ | float calculateAreaTetrahedron(int side) { | [
"side"
] | def calculate_area_tetrahedron(side):
volume = ((side ** 3) / (6 * math.sqrt(2)))
return round(volume, 2) | double calculate_area_tetrahedron(int side) {
double volume = ( pow ( side, 3 ) / ( 6 * sqrt ( 2 ) ) );
return volume;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int side, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(side), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(58, 22994.17); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 20696.54); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 5052.87); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 114350.83); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 258.92); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 10739.18); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 7542.47); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 91769.26); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 40.42); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 258.92); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "calculateAreaTetrahedron",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 22994.17, \"inputs\": {\"side\": 58}}, {\"idx\": 1, \"outputs\": 20696.54, \"inputs\": {\"side\": 56}}, {\"idx\": 2, \"outputs\": 5052.87, \"inputs\": {\"side\": 35}}, {\"idx\": 3, \"outputs\": 114350.83, \"inputs\": {\"side\": 99}}, {\"idx\": 4, \"outputs\": 258.92, \"inputs\": {\"side\": 13}}, {\"idx\": 5, \"outputs\": 10739.18, \"inputs\": {\"side\": 45}}, {\"idx\": 6, \"outputs\": 7542.47, \"inputs\": {\"side\": 40}}, {\"idx\": 7, \"outputs\": 91769.26, \"inputs\": {\"side\": 92}}, {\"idx\": 8, \"outputs\": 40.42, \"inputs\": {\"side\": 7}}, {\"idx\": 9, \"outputs\": 258.92, \"inputs\": {\"side\": 13}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
16 | Calculate Maximum Value Using Sign Two Numbers String | C++ | int calculateMaximumValueUsingSignTwoNumbersString(string str) { | [
"str"
] | def calculate_maximum_value_using_sign_two_numbers_string(str):
res = (ord(str[0]) - 48)
for i in range(1, len(str)):
if ((str[i] == '0') or (str[i] == '1') or (res < 2)):
res += (ord(str[i]) - 48)
else:
res *= (ord(str[i]) - 48)
return res | int calculate_maximum_value_using_sign_two_numbers_string(string str) {
int res = str [ 0 ] - '0';
for ( int i = 1;
i < str . length ( );
i ++ ) {
if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' );
else res *= ( str [ i ] - '0' );
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string str, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"pR\", 2176); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"9518\", 368); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"3170487\", 6272); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0100101010\", 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Z rONcUqWb\", -303); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00419297\", 5670); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"r\", 66); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "calculateMaximumValueUsingSignTwoNumbersString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2176, \"inputs\": {\"str\": \"pR\"}}, {\"idx\": 1, \"outputs\": 368, \"inputs\": {\"str\": \"9518\"}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"str\": \"1\"}}, {\"idx\": 3, \"outputs\": 6272, \"inputs\": {\"str\": \"3170487\"}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"str\": \"0100101010\"}}, {\"idx\": 5, \"outputs\": -303, \"inputs\": {\"str\": \"Z rONcUqWb\"}}, {\"idx\": 6, \"outputs\": 5670, \"inputs\": {\"str\": \"00419297\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"str\": \"00\"}}, {\"idx\": 8, \"outputs\": 66, \"inputs\": {\"str\": \"r\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
17 | Calculate Volume Dodecahedron | C++ | double calculateVolumeDodecahedron(int side) { | [
"side"
] | def calculate_volume_dodecahedron(side):
return (((15 + (7 * math.sqrt(5))) / 4) * math.pow(side, 3)) | double calculate_volume_dodecahedron(int side) {
return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side, 3 ) ) );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int side, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(side), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(56, 1345766.2993890555); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 2981083.5487053124); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 81596.89069273109); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 7663.118960624633); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 4541961.260438062); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 61304.95168499706); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 1016520.3932458181); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 5774704.218276865); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 7663.118960624633); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 4381671.801138677); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "calculateVolumeDodecahedron",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1345766.2993890555, \"inputs\": {\"side\": 56}}, {\"idx\": 1, \"outputs\": 2981083.5487053124, \"inputs\": {\"side\": 73}}, {\"idx\": 2, \"outputs\": 81596.89069273109, \"inputs\": {\"side\": 22}}, {\"idx\": 3, \"outputs\": 7663.118960624633, \"inputs\": {\"side\": 10}}, {\"idx\": 4, \"outputs\": 4541961.260438062, \"inputs\": {\"side\": 84}}, {\"idx\": 5, \"outputs\": 61304.95168499706, \"inputs\": {\"side\": 20}}, {\"idx\": 6, \"outputs\": 1016520.3932458181, \"inputs\": {\"side\": 51}}, {\"idx\": 7, \"outputs\": 5774704.218276865, \"inputs\": {\"side\": 91}}, {\"idx\": 8, \"outputs\": 7663.118960624633, \"inputs\": {\"side\": 10}}, {\"idx\": 9, \"outputs\": 4381671.801138677, \"inputs\": {\"side\": 83}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
18 | Cassinis Identity | C++ | int cassinisIdentity(int n) { | [
"n"
] | def cassinis_identity(n):
return ((- 1) if (n & 1) else 1) | int cassinis_identity(int n) {
return ( n & 1 ) ? - 1 : 1;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(67, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "cassinisIdentity",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"n\": 67}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"n\": 2}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"n\": 58}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"n\": 6}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"n\": 42}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"n\": 17}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"n\": 37}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"n\": 44}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"n\": 23}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"n\": 40}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
19 | Ceiling In A Sorted Array | C++ | int ceilingInASortedArray(vector<int> arr, int low, int high, int x) { | [
"arr",
"low",
"high",
"x"
] | def ceiling_in_a_sorted_array(arr, low, high, x):
if (x <= arr[low]):
return low
i = low
for i in range(high):
if (arr[i] == x):
return i
if ((arr[i] < x) and (arr[(i + 1)] >= x)):
return (i + 1)
return (- 1) | int ceiling_in_a_sorted_array(vector<int> arr, int low, int high, int x) {
int i;
if ( x <= arr [ low ] ) return low;
for ( i = low;
i < high;
i ++ ) {
if ( arr [ i ] == x ) return i;
if ( arr [ i ] < x && arr [ i + 1 ] >= x ) return i + 1;
}
return - 1;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int low, int high, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, low, high, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 3, 4, 6, 8, 9, 9, 10, 11, 16, 19, 20, 21, 21, 21, 24, 24, 25, 28, 30, 30, 30, 32, 34, 35, 39, 41, 42, 49, 52, 57, 59, 61, 62, 66, 68, 71, 73, 76, 79, 83, 84, 85, 86, 87, 87}, 23, 37, 44, 28); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({92, 50, -84, 60, 32, -54, 84, -82, -42, -72, -64, -28, -48, 66, 92, -42, 42, -66, 52, -30, 48, 42, 36, -4, 64, 62, -16, 0, 20, 26, 78, 78, 12, -6, -30, -14, 76, 72, 70, -34, 98, 32}, 36, 35, 34, 36); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 11, 9, 13, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({26, 68, 73, 76, 14, 19, 56, 80, 17, 7, 15, 64, 99, 98, 21, 21, 72, 12, 14, 10, 44, 82, 25, 42, 46, 86, 79, 43, 91}, 23, 27, 26, 23); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -86, -84, -50, -30, -24, -12, -2, 8, 22, 30, 44, 58, 58, 60, 60, 62, 90}, 9, 16, 10, 9); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1}, 12, 15, 18, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 29, 31, 34, 39, 48, 50, 56, 61, 66, 66, 69, 73, 88}, 9, 12, 10, 9); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, 48, -58, 8, 70, 62, 92, 84, -58, -46, -26, -92, 18, -88, 40, -12, 60, 14, 54, -64, 88, 52, -44, 88, -46, -8, 36, -22, 28, -20, -50, 58, -82, -44, -44, 54, -86, 40, 10, 0, -24, -84, -10, 62, 58, 0, -88}, 40, 29, 24, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1}, 5, 5, 5, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({56, 30, 33, 5, 67, 35, 22, 54, 36, 55, 94, 89, 40, 65, 29, 76, 17, 14, 14, 49, 40, 44, 35, 69, 63, 2, 81, 78, 19, 67, 12, 14, 68, 30, 82, 85, 12, 2, 94, 33, 85, 75, 97, 31, 69, 31, 85, 26}, 46, 47, 47, 46); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "ceilingInASortedArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 28, \"inputs\": {\"arr\": [2, 3, 4, 6, 8, 9, 9, 10, 11, 16, 19, 20, 21, 21, 21, 24, 24, 25, 28, 30, 30, 30, 32, 34, 35, 39, 41, 42, 49, 52, 57, 59, 61, 62, 66, 68, 71, 73, 76, 79, 83, 84, 85, 86, 87, 87], \"low\": 23, \"high\": 37, \"x\": 44}}, {\"idx\": 1, \"outputs\": 36, \"inputs\": {\"arr\": [92, 50, -84, 60, 32, -54, 84, -82, -42, -72, -64, -28, -48, 66, 92, -42, 42, -66, 52, -30, 48, 42, 36, -4, 64, 62, -16, 0, 20, 26, 78, 78, 12, -6, -30, -14, 76, 72, 70, -34, 98, 32], \"low\": 36, \"high\": 35, \"x\": 34}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"low\": 11, \"high\": 9, \"x\": 13}}, {\"idx\": 3, \"outputs\": 23, \"inputs\": {\"arr\": [26, 68, 73, 76, 14, 19, 56, 80, 17, 7, 15, 64, 99, 98, 21, 21, 72, 12, 14, 10, 44, 82, 25, 42, 46, 86, 79, 43, 91], \"low\": 23, \"high\": 27, \"x\": 26}}, {\"idx\": 4, \"outputs\": 9, \"inputs\": {\"arr\": [-90, -86, -84, -50, -30, -24, -12, -2, 8, 22, 30, 44, 58, 58, 60, 60, 62, 90], \"low\": 9, \"high\": 16, \"x\": 10}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1], \"low\": 12, \"high\": 15, \"x\": 18}}, {\"idx\": 6, \"outputs\": 9, \"inputs\": {\"arr\": [2, 2, 29, 31, 34, 39, 48, 50, 56, 61, 66, 66, 69, 73, 88], \"low\": 9, \"high\": 12, \"x\": 10}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [-98, 48, -58, 8, 70, 62, 92, 84, -58, -46, -26, -92, 18, -88, 40, -12, 60, 14, 54, -64, 88, 52, -44, 88, -46, -8, 36, -22, 28, -20, -50, 58, -82, -44, -44, 54, -86, 40, 10, 0, -24, -84, -10, 62, 58, 0, -88], \"low\": 40, \"high\": 29, \"x\": 24}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1], \"low\": 5, \"high\": 5, \"x\": 5}}, {\"idx\": 9, \"outputs\": 46, \"inputs\": {\"arr\": [56, 30, 33, 5, 67, 35, 22, 54, 36, 55, 94, 89, 40, 65, 29, 76, 17, 14, 14, 49, 40, 44, 35, 69, 63, 2, 81, 78, 19, 67, 12, 14, 68, 30, 82, 85, 12, 2, 94, 33, 85, 75, 97, 31, 69, 31, 85, 26], \"low\": 46, \"high\": 47, \"x\": 47}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
20 | Ceiling In A Sorted Array 1 | C++ | int ceilingInASortedArray1(vector<int> arr, int low, int high, int x) { | [
"arr",
"low",
"high",
"x"
] | def ceiling_in_a_sorted_array_1(arr, low, high, x):
if (x <= arr[low]):
return low
if (x > arr[high]):
return (- 1)
mid = ((low + high) / 2)
if (arr[mid] == x):
return mid
elif (arr[mid] < x):
if (((mid + 1) <= high) and (x <= arr[(mid + 1)])):
return (mid + 1)
else:
return ceiling_in_a_sorted_array_1(arr, (mid + 1), high, x)
elif (((mid - 1) >= low) and (x > arr[(mid - 1)])):
return mid
else:
return ceiling_in_a_sorted_array_1(arr, low, (mid - 1), x) | int ceiling_in_a_sorted_array_1(vector<int> arr, int low, int high, int x) {
int mid;
if ( x <= arr [ low ] ) return low;
if ( x > arr [ high ] ) return - 1;
mid = ( low + high ) / 2;
if ( arr [ mid ] == x ) return mid;
else if ( arr [ mid ] < x ) {
if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1;
else return ceiling_in_a_sorted_array_1 ( arr, mid + 1, high, x );
}
else {
if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid;
else return ceiling_in_a_sorted_array_1 ( arr, low, mid - 1, x );
}
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int low, int high, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, low, high, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 6, 13, 16, 23, 24, 24, 27, 30, 32, 34, 34, 55, 56, 56, 63, 66, 81, 83, 96}, 13, 11, 18, 13); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-28, -96, 48, 22, -12, 72, 48, -70, -96, -84, -62, 22, 18, -92, -74, 14, 28, 52, 64, 72, 16, -76, 46}, 11, 18, 21, 11); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, 1, 1, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({51, 98, 25, 10, 43, 91, 33, 25, 85, 51, 94, 6, 35, 48, 11, 97, 67, 21, 50, 9, 11, 51, 86, 61, 22, 88, 89, 11}, 20, 20, 15, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -92, -88, -74, -52, -50, -48, -44, -40, -36, -32, -26, 20, 22, 30, 32, 46, 56, 56, 60, 62, 64, 80, 84, 86, 94, 96, 96}, 20, 15, 15, 20); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, 15, 17, 22, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 5, 13, 26, 40, 46, 51, 58, 60, 64, 66, 68, 69, 71, 74, 78, 81, 83, 88, 88, 90, 98, 99}, 12, 17, 14, 12); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({92, 6, -54, 84, -10, 32, 50, 40, -38, 64, -64, -10, 70, -68, -6, -16, 68, 34, -66, -82, 84, 98, 50, 82, 78, 4, 34, -34, 78, 64, 32, 58, -94, 40, 50, 0, -92, -36, 10, -54, 58, -78, -88, 32, 6}, 23, 28, 28, 23); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 24, 17, 22, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, 67, 30, 35, 9}, 2, 3, 2, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "ceilingInASortedArray1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 13, \"inputs\": {\"arr\": [2, 6, 13, 16, 23, 24, 24, 27, 30, 32, 34, 34, 55, 56, 56, 63, 66, 81, 83, 96], \"low\": 13, \"high\": 11, \"x\": 18}}, {\"idx\": 1, \"outputs\": 11, \"inputs\": {\"arr\": [-28, -96, 48, 22, -12, 72, 48, -70, -96, -84, -62, 22, 18, -92, -74, 14, 28, 52, 64, 72, 16, -76, 46], \"low\": 11, \"high\": 18, \"x\": 21}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1], \"low\": 1, \"high\": 1, \"x\": 1}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [51, 98, 25, 10, 43, 91, 33, 25, 85, 51, 94, 6, 35, 48, 11, 97, 67, 21, 50, 9, 11, 51, 86, 61, 22, 88, 89, 11], \"low\": 20, \"high\": 20, \"x\": 15}}, {\"idx\": 4, \"outputs\": 20, \"inputs\": {\"arr\": [-94, -92, -88, -74, -52, -50, -48, -44, -40, -36, -32, -26, 20, 22, 30, 32, 46, 56, 56, 60, 62, 64, 80, 84, 86, 94, 96, 96], \"low\": 20, \"high\": 15, \"x\": 15}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], \"low\": 15, \"high\": 17, \"x\": 22}}, {\"idx\": 6, \"outputs\": 12, \"inputs\": {\"arr\": [4, 5, 5, 13, 26, 40, 46, 51, 58, 60, 64, 66, 68, 69, 71, 74, 78, 81, 83, 88, 88, 90, 98, 99], \"low\": 12, \"high\": 17, \"x\": 14}}, {\"idx\": 7, \"outputs\": 23, \"inputs\": {\"arr\": [92, 6, -54, 84, -10, 32, 50, 40, -38, 64, -64, -10, 70, -68, -6, -16, 68, 34, -66, -82, 84, 98, 50, 82, 78, 4, 34, -34, 78, 64, 32, 58, -94, 40, 50, 0, -92, -36, 10, -54, 58, -78, -88, 32, 6], \"low\": 23, \"high\": 28, \"x\": 28}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"low\": 24, \"high\": 17, \"x\": 22}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr\": [80, 67, 30, 35, 9], \"low\": 2, \"high\": 3, \"x\": 2}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
22 | Change Bits Can Made One Flip | C++ | bool changeBitsCanMadeOneFlip(string str) { | [
"str"
] | def change_bits_can_made_one_flip(str):
zeros = 0
ones = 0
for i in range(0, len(str)):
ch = str[i]
if (ch == '0'):
zeros = (zeros + 1)
else:
ones = (ones + 1)
return ((zeros == 1) or (ones == 1)) | bool change_bits_can_made_one_flip(string str) {
int zeros = 0, ones = 0;
for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones;
return ( zeros == 1 || ones == 1 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string str, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"00001\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0000\", false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111110\", true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111010111010\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"hUInqJXNdbfP\", false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"5191\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1110101101\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"NupSrU xz\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "changeBitsCanMadeOneFlip",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"str\": \"00001\"}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"str\": \"0000\"}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"str\": \"11\"}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"str\": \"111110\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"str\": \"1\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"str\": \"111010111010\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"str\": \"hUInqJXNdbfP\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"str\": \"5191\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"str\": \"1110101101\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"str\": \"NupSrU xz\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
23 | Check Array Contains Contiguous Integers Duplicates Allowed | C++ | bool checkArrayContainsContiguousIntegersDuplicatesAllowed(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_array_contains_contiguous_integers_duplicates_allowed(arr, n):
max1 = max(arr)
min1 = min(arr)
m = ((max1 - min1) + 1)
if (m > n):
return False
visited = ([0] * m)
for i in range(0, n):
visited[(arr[i] - min1)] = True
for i in range(0, m):
if (visited[i] == False):
return False
return True | bool check_array_contains_contiguous_integers_duplicates_allowed(vector<int> arr, int n) {
int max = * max_element(arr.begin(), arr.end());
int min = * min_element(arr.begin(), arr.end());
int m = max - min + 1;
if ( m > n ) return false;
bool visited [ m ];
memset ( visited, false, sizeof ( visited ) );
for ( int i = 0;
i < n;
i ++ ) visited [ arr [ i ] - min ] = true;
for ( int i = 0;
i < m;
i ++ ) if ( visited [ i ] == false ) return false;
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 4, 19, 25, 65, 72, 75, 83, 90, 92}, 8, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 2, 28, -44, 74, -36, -8, 30, -96, 60, 52, -58, 16, -38, 78, 38, -28, 16, 26, -42, 48, 40, 6, 72}, 14, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1}, 2, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 21, 9, 29, 86, 2, 82, 49, 34, 18, 77, 83, 44, 67, 85, 58, 15, 85, 22, 3, 39, 67, 42, 37, 6, 35, 18, 57, 41, 32, 39, 30, 41, 68, 84, 36, 64, 36}, 23, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -82, -80, -78, -66, -66, -62, -58, -54, -52, -48, -30, -26, -22, -20, -20, -18, -14, -2, 12, 20, 24, 26, 26, 28, 28, 32, 36, 42, 48, 50, 52, 56, 64, 70, 72, 72, 80, 82, 84, 86, 92}, 26, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0}, 43, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({18, 19, 21, 23, 30, 33, 38, 40, 45, 56, 63, 68, 93, 96}, 8, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, -90, -42, 48, 18, -46, 82, -12, -88, 82, 62, 24, 20, 64, -68, -34, -38, 8, -54, -20, -92, 34, -90, 78, 18, 8, -6, 10, 98, -24, 72, -92, 76, -22, 12, -44, 2, 68, -72, 42, 34, 20, -48}, 34, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1}, 8, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({81, 25, 50, 48, 35, 38, 49, 21, 47, 94, 94, 55, 23, 45, 92, 23, 93, 33, 64, 9, 90, 64, 81, 17, 2, 73, 8, 7, 35, 36, 72}, 27, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkArrayContainsContiguousIntegersDuplicatesAllowed",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [2, 4, 19, 25, 65, 72, 75, 83, 90, 92], \"n\": 8}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [46, 2, 28, -44, 74, -36, -8, 30, -96, 60, 52, -58, 16, -38, 78, 38, -28, 16, 26, -42, 48, 40, 6, 72], \"n\": 14}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"arr\": [0, 1, 1, 1], \"n\": 2}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"arr\": [50, 21, 9, 29, 86, 2, 82, 49, 34, 18, 77, 83, 44, 67, 85, 58, 15, 85, 22, 3, 39, 67, 42, 37, 6, 35, 18, 57, 41, 32, 39, 30, 41, 68, 84, 36, 64, 36], \"n\": 23}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"arr\": [-92, -82, -80, -78, -66, -66, -62, -58, -54, -52, -48, -30, -26, -22, -20, -20, -18, -14, -2, 12, 20, 24, 26, 26, 28, 28, 32, 36, 42, 48, 50, 52, 56, 64, 70, 72, 72, 80, 82, 84, 86, 92], \"n\": 26}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"arr\": [1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0], \"n\": 43}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [18, 19, 21, 23, 30, 33, 38, 40, 45, 56, 63, 68, 93, 96], \"n\": 8}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [20, -90, -42, 48, 18, -46, 82, -12, -88, 82, 62, 24, 20, 64, -68, -34, -38, 8, -54, -20, -92, 34, -90, 78, 18, 8, -6, 10, 98, -24, 72, -92, 76, -22, 12, -44, 2, 68, -72, 42, 34, 20, -48], \"n\": 34}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 8}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [81, 25, 50, 48, 35, 38, 49, 21, 47, 94, 94, 55, 23, 45, 92, 23, 93, 33, 64, 9, 90, 64, 81, 17, 2, 73, 8, 7, 35, 36, 72], \"n\": 27}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
24 | Check Array Represents Inorder Binary Search Tree Not | C++ | bool checkArrayRepresentsInorderBinarySearchTreeNot(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_array_represents_inorder_binary_search_tree_not(arr, n):
if ((n == 0) or (n == 1)):
return True
for i in range(1, n, 1):
if (arr[(i - 1)] > arr[i]):
return False
return True | bool check_array_represents_inorder_binary_search_tree_not(vector<int> arr, int n) {
if ( n == 0 || n == 1 ) return true;
for ( int i = 1;
i < n;
i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false;
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 3, 4, 10, 11, 13, 17, 19, 23, 26, 28, 29, 30, 34, 35, 37, 38, 38, 43, 49, 49, 50, 52, 53, 55, 55, 57, 58, 58, 59, 64, 66, 67, 70, 72, 72, 75, 77, 77, 87, 89, 89, 90, 91, 98, 99, 99, 99}, 46, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({56, -94, -26, -52, 58, -66, -52, -66, -94, 44, 38, -66, 70, -70, -80, -78, -72, -60, -76, 68, -50, 32, -16, 84, 74, -42, 98, -8, 72, 26, 24, 6, 24, 86, 86, 78, -92, 80, 32, -74, 26, 50, 92, 4, 2, -34, -2, -18, -10}, 30, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({38, 79, 76, 92, 92}, 2, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-42, -28, 2, 32, 50, 56, 86, 96, 98}, 7, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 11, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 9, 12, 21, 21, 24, 34, 55, 60, 63, 67, 68, 88, 89, 91, 94, 98, 99}, 9, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, 96, -98, -42, -74, 40, 42, 50, -46, -52, 8, -46, 48, 88, -78, -72, -10, -20, 98, -40, -18, 36, 4, 46, 52, 28, -88, -28, -28, -86}, 29, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1}, 3, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, 12, 48, 82, 33, 77, 99, 98, 14, 92}, 7, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkArrayRepresentsInorderBinarySearchTreeNot",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"arr\": [2, 3, 4, 10, 11, 13, 17, 19, 23, 26, 28, 29, 30, 34, 35, 37, 38, 38, 43, 49, 49, 50, 52, 53, 55, 55, 57, 58, 58, 59, 64, 66, 67, 70, 72, 72, 75, 77, 77, 87, 89, 89, 90, 91, 98, 99, 99, 99], \"n\": 46}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [56, -94, -26, -52, 58, -66, -52, -66, -94, 44, 38, -66, 70, -70, -80, -78, -72, -60, -76, 68, -50, 32, -16, 84, 74, -42, 98, -8, 72, 26, 24, 6, 24, 86, 86, 78, -92, 80, 32, -74, 26, 50, 92, 4, 2, -34, -2, -18, -10], \"n\": 30}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [38, 79, 76, 92, 92], \"n\": 2}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-42, -28, 2, 32, 50, 56, 86, 96, 98], \"n\": 7}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 11}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"arr\": [1, 9, 12, 21, 21, 24, 34, 55, 60, 63, 67, 68, 88, 89, 91, 94, 98, 99], \"n\": 9}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [-96, 96, -98, -42, -74, 40, 42, 50, -46, -52, 8, -46, 48, 88, -78, -72, -10, -20, 98, -40, -18, 36, 4, 46, 52, 28, -88, -28, -28, -86], \"n\": 29}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1], \"n\": 3}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [66, 12, 48, 82, 33, 77, 99, 98, 14, 92], \"n\": 7}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
25 | Check Exist Two Elements Array Whose Sum Equal Sum Rest Array | C++ | bool checkExistTwoElementsArrayWhoseSumEqualSumRestArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_exist_two_elements_array_whose_sum_equal_sum_rest_array(arr, n):
s = set()
sum = 0
for i in range(n):
sum += arr[i]
if ((sum % 2) != 0):
return False
sum = (sum / 2)
for i in range(n):
val = (sum - arr[i])
if (arr[i] not in s):
s.add(arr[i])
if (val in s):
print('Pair elements are', arr[i], 'and', int(val)) | bool check_exist_two_elements_array_whose_sum_equal_sum_rest_array(vector<int> arr, int n) {
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) sum += arr [ i ];
if ( sum % 2 != 0 ) return false;
sum = sum / 2;
unordered_set < int > s;
for ( int i = 0;
i < n;
i ++ ) {
int val = sum - arr [ i ];
if ( s . find ( val ) != s . end ( ) ) {
return true;
}
s . insert ( arr [ i ] );
}
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 11, 5, 1, 4, 7}, 6, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, 2, 1, 11, 15}, 6, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({69, 6, 24, 30, 75, 37, 61, 76, 19, 18, 90, 9, 49, 24, 58, 97, 18, 85, 24, 93, 71, 98, 92, 59, 75, 75, 75, 70, 35, 58, 50, 1, 64, 66, 33}, 18, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -94, -92, -74, -60, -58, -56, -44, -42, -40, -28, -14, 2, 4, 14, 20, 24, 28, 40, 42, 42, 66, 78, 78, 80, 82, 96}, 26, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1}, 10, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({21, 26, 26, 27, 61, 62, 96}, 6, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-54, 86, 20, 26}, 3, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 4, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({44, 35, 26, 15, 56, 6, 36, 53, 15, 66, 20, 53, 99, 96, 51, 12, 61, 19, 79, 40, 99, 42, 86, 8, 11, 54, 93, 46, 23, 47, 41, 26, 66, 5, 86, 52, 64, 51, 4, 21, 63, 14, 7, 53, 31, 8, 9, 63}, 31, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkExistTwoElementsArrayWhoseSumEqualSumRestArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": null, \"inputs\": {\"arr\": [2, 11, 5, 1, 4, 7], \"n\": 6}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [2, 4, 2, 1, 11, 15], \"n\": 6}}, {\"idx\": 2, \"outputs\": null, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"arr\": [69, 6, 24, 30, 75, 37, 61, 76, 19, 18, 90, 9, 49, 24, 58, 97, 18, 85, 24, 93, 71, 98, 92, 59, 75, 75, 75, 70, 35, 58, 50, 1, 64, 66, 33], \"n\": 18}}, {\"idx\": 4, \"outputs\": null, \"inputs\": {\"arr\": [-94, -94, -92, -74, -60, -58, -56, -44, -42, -40, -28, -14, 2, 4, 14, 20, 24, 28, 40, 42, 42, 66, 78, 78, 80, 82, 96], \"n\": 26}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1], \"n\": 10}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [21, 26, 26, 27, 61, 62, 96], \"n\": 6}}, {\"idx\": 7, \"outputs\": null, \"inputs\": {\"arr\": [-54, 86, 20, 26], \"n\": 3}}, {\"idx\": 8, \"outputs\": null, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 4}}, {\"idx\": 9, \"outputs\": null, \"inputs\": {\"arr\": [44, 35, 26, 15, 56, 6, 36, 53, 15, 66, 20, 53, 99, 96, 51, 12, 61, 19, 79, 40, 99, 42, 86, 8, 11, 54, 93, 46, 23, 47, 41, 26, 66, 5, 86, 52, 64, 51, 4, 21, 63, 14, 7, 53, 31, 8, 9, 63], \"n\": 31}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
26 | Check Given Circle Lies Completely Inside Ring Formed Two Concentric Circles | C++ | bool checkGivenCircleLiesCompletelyInsideRingFormedTwoConcentricCircles(int r0, int r10, int r11, int x1, int y1) { | [
"r0",
"r10",
"r11",
"x1",
"y1"
] | def check_given_circle_lies_completely_inside_ring_formed_two_concentric_circles(r, R, r1, x1, y1):
dis = int(math.sqrt(((x1 * x1) + (y1 * y1))))
return (((dis - r1) >= R) and ((dis + r1) <= r)) | bool check_given_circle_lies_completely_inside_ring_formed_two_concentric_circles(int r, int R, int r1, int x1, int y1) {
int dis = sqrt ( x1 * x1 + y1 * y1 );
return ( dis - r1 >= R && dis + r1 <= r );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int r0, int r10, int r11, int x1, int y1, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(r0, r10, r11, x1, y1), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(8, 4, 2, 6, 0, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(400, 1, 10, 74, 38, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 400, 10, 74, 38, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 40, 2, 50, 0, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 49, 68, 77, 71, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 10, 69, 71, 26, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 79, 92, 29, 38, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 88, 75, 84, 10, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 65, 57, 21, 61, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 57, 77, 52, 87, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkGivenCircleLiesCompletelyInsideRingFormedTwoConcentricCircles",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"r0\": 8, \"r10\": 4, \"r11\": 2, \"x1\": 6, \"y1\": 0}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"r0\": 400, \"r10\": 1, \"r11\": 10, \"x1\": 74, \"y1\": 38}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"r0\": 1, \"r10\": 400, \"r11\": 10, \"x1\": 74, \"y1\": 38}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"r0\": 61, \"r10\": 40, \"r11\": 2, \"x1\": 50, \"y1\": 0}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"r0\": 60, \"r10\": 49, \"r11\": 68, \"x1\": 77, \"y1\": 71}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"r0\": 88, \"r10\": 10, \"r11\": 69, \"x1\": 71, \"y1\": 26}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"r0\": 60, \"r10\": 79, \"r11\": 92, \"x1\": 29, \"y1\": 38}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"r0\": 26, \"r10\": 88, \"r11\": 75, \"x1\": 84, \"y1\": 10}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"r0\": 33, \"r10\": 65, \"r11\": 57, \"x1\": 21, \"y1\": 61}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"r0\": 70, \"r10\": 57, \"r11\": 77, \"x1\": 52, \"y1\": 87}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
27 | Check Given String Can Split Four Distinct Strings | C++ | bool checkGivenStringCanSplitFourDistinctStrings(string s) { | [
"s"
] | def check_given_string_can_split_four_distinct_strings(s):
if (len(s) >= 10):
return True
for i in range(1, len(s)):
for j in range((i + 1), len(s)):
for k in range((j + 1), len(s)):
s1 = s[0:i]
s2 = s[i:(j - i)]
s3 = s[j:(k - j)]
s4 = s[k:(len(s) - k)]
if ((s1 != s2) and (s1 != s3) and (s1 != s4) and (s2 != s3) and (s2 != s4) and (s3 != s4)):
return True
return False | bool check_given_string_can_split_four_distinct_strings(string s) {
if ( s . size ( ) >= 10 ) return true;
for ( int i = 1;
i < s . size ( );
i ++ ) {
for ( int j = i + 1;
j < s . size ( );
j ++ ) {
for ( int k = j + 1;
k < s . size ( );
k ++ ) {
string s1 = s . substr ( 0, i );
string s2 = s . substr ( i, j - i );
string s3 = s . substr ( j, k - j );
string s4 = s . substr ( k, s . size ( ) - k );
if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true;
}
}
}
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string s, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"WKTj Nw\", false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"8235021\", false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0101\", false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"BLMhiQsQcFla\", true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00363175722\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10000\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aqEYWNd bqgye\", true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"83\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000011110111\", true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"E\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkGivenStringCanSplitFourDistinctStrings",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"s\": \"WKTj Nw\"}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"s\": \"8235021\"}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"s\": \"0101\"}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"s\": \"BLMhiQsQcFla\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"s\": \"00363175722\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"s\": \"10000\"}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"s\": \"aqEYWNd bqgye\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"s\": \"83\"}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"s\": \"000011110111\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"s\": \"E\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
28 | Check Given String Rotation Palindrome | C++ | bool checkGivenStringRotationPalindrome(string string_arg0) { | [
"string_arg0"
] | def check_given_string_rotation_palindrome(string):
l = 0
h = (len(string) - 1)
while (h > l):
l += 1
h -= 1
if (string[(l - 1)] != string[(h + 1)]):
return False
return True | bool check_given_string_rotation_palindrome(string str) {
int l = 0;
int h = str . length ( ) - 1;
while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false;
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"aadaa\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2674377254\", false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0011000\", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"26382426486138\", false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111010111010\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abccba\", true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"5191\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1110101101\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abcdecbe\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkGivenStringRotationPalindrome",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"string_arg0\": \"aadaa\"}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"string_arg0\": \"2674377254\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"string_arg0\": \"11\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"string_arg0\": \"0011000\"}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"string_arg0\": \"26382426486138\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"string_arg0\": \"111010111010\"}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"string_arg0\": \"abccba\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"string_arg0\": \"5191\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"string_arg0\": \"1110101101\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"string_arg0\": \"abcdecbe\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
29 | Check If All The Elements Can Be Made Of Same Parity By Inverting Adjacent Elements | C++ | bool checkIfAllTheElementsCanBeMadeOfSameParityByInvertingAdjacentElements(vector<int> a, int n) { | [
"a",
"n"
] | def check_if_all_the_elements_can_be_made_of_same_parity_by_inverting_adjacent_elements(a, n):
count_odd = 0
count_even = 0
for i in range(n):
if (a[i] & 1):
count_odd += 1
else:
count_even += 1
if ((count_odd % 2) and (count_even % 2)):
return False
else:
return True | bool check_if_all_the_elements_can_be_made_of_same_parity_by_inverting_adjacent_elements(vector<int> a, int n) {
int count_odd = 0, count_even = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] & 1 ) count_odd ++;
else count_even ++;
}
if ( count_odd % 2 && count_even % 2 ) return false;
else return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 1, 1, 7, 7, 8, 10, 10, 10, 14, 15, 18, 20, 23, 24, 24, 26, 30, 32, 32, 33, 36, 42, 43, 46, 48, 51, 51, 52, 53, 58, 58, 59, 59, 59, 60, 67, 71, 72, 74, 76, 77, 83, 84, 86, 90, 91}, 30, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -20, -60, -64, -24, 84, -2, -32, 28, -54, 44, -96, 52, 88, 20, -56, -2}, 12, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 36, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 70, 24, 18, 7, 4, 78, 19, 70, 56, 99, 54, 69, 15, 88, 20, 40, 13, 19, 56, 62}, 19, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-72, -66, -58, -20, 36, 80, 92}, 6, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 13, 14, 16, 21, 26, 26, 28, 29, 35, 38, 42, 47, 47, 62, 67, 77, 81, 81, 83, 84, 88, 90, 96, 97, 98}, 17, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-48, -8, 20, 32, -90, -42, -6, -88, -72, 42, 66, -62, 82, -4, 8, 12, -22, 82, 56, 96, -54, 92, -42, 30, -18, 14, -6, -66, 34, 16, -84, -94, 48, -48, 52, -60, -92, -16}, 35, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 14, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({45, 86, 53, 80, 27, 45, 1, 85, 91, 93, 92, 43, 75, 86, 81, 48, 21, 34, 5, 10, 88, 42, 7, 15, 96, 85, 62, 86, 52, 37}, 29, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkIfAllTheElementsCanBeMadeOfSameParityByInvertingAdjacentElements",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"a\": [1, 1, 1, 7, 7, 8, 10, 10, 10, 14, 15, 18, 20, 23, 24, 24, 26, 30, 32, 32, 33, 36, 42, 43, 46, 48, 51, 51, 52, 53, 58, 58, 59, 59, 59, 60, 67, 71, 72, 74, 76, 77, 83, 84, 86, 90, 91], \"n\": 30}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"a\": [-90, -20, -60, -64, -24, 84, -2, -32, 28, -54, 44, -96, 52, 88, 20, -56, -2], \"n\": 12}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 36}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"a\": [98, 70, 24, 18, 7, 4, 78, 19, 70, 56, 99, 54, 69, 15, 88, 20, 40, 13, 19, 56, 62], \"n\": 19}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"a\": [-72, -66, -58, -20, 36, 80, 92], \"n\": 6}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"a\": [0, 1], \"n\": 1}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"a\": [6, 13, 14, 16, 21, 26, 26, 28, 29, 35, 38, 42, 47, 47, 62, 67, 77, 81, 81, 83, 84, 88, 90, 96, 97, 98], \"n\": 17}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"a\": [-48, -8, 20, 32, -90, -42, -6, -88, -72, 42, 66, -62, 82, -4, 8, 12, -22, 82, 56, 96, -54, 92, -42, 30, -18, 14, -6, -66, 34, 16, -84, -94, 48, -48, 52, -60, -92, -16], \"n\": 35}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 14}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"a\": [45, 86, 53, 80, 27, 45, 1, 85, 91, 93, 92, 43, 75, 86, 81, 48, 21, 34, 5, 10, 88, 42, 7, 15, 96, 85, 62, 86, 52, 37], \"n\": 29}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
30 | Check If A Number Is Jumbled Or Not | C++ | bool checkIfANumberIsJumbledOrNot(int num) { | [
"num"
] | def check_if_a_number_is_jumbled_or_not(num):
if ((num // 10) == 0):
return True
while (num != 0):
if ((num // 10) == 0):
return True
digit1 = (num % 10)
digit2 = ((num // 10) % 10)
if (abs((digit2 - digit1)) > 1):
return False
num = (num // 10)
return True | bool check_if_a_number_is_jumbled_or_not(int num) {
if ( num / 10 == 0 ) return true;
while ( num != 0 ) {
if ( num / 10 == 0 ) return true;
int digit1 = num % 10;
int digit2 = ( num / 10 ) % 10;
if ( abs ( digit2 - digit1 ) > 1 ) return false;
num = num / 10;
}
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int num, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(67, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkIfANumberIsJumbledOrNot",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"num\": 67}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"num\": 77}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"num\": 35}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"num\": 79}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"num\": 45}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"num\": 22}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"num\": 68}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"num\": 17}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"num\": 5}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"num\": 85}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
31 | Check If A Number Is Power Of Another Number | C++ | bool checkIfANumberIsPowerOfAnotherNumber(int x, int y) { | [
"x",
"y"
] | def check_if_a_number_is_power_of_another_number(x, y):
if (x == 1):
return (y == 1)
pow = 1
while (pow < y):
pow = (pow * x)
return (pow == y) | bool check_if_a_number_is_power_of_another_number(int x, long int y) {
if ( x == 1 ) return ( y == 1 );
long int pow = 1;
while ( pow < y ) pow *= x;
return ( pow == y );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int x, int y, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(57, 1, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 9, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 101, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 10000, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 46656, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 2048, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 40, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 79, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 98, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 5, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkIfANumberIsPowerOfAnotherNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"x\": 57, \"y\": 1}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"x\": 3, \"y\": 9}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"x\": 10, \"y\": 101}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"x\": 10, \"y\": 10000}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"x\": 6, \"y\": 46656}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"x\": 2, \"y\": 2048}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"x\": 1, \"y\": 40}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"x\": 20, \"y\": 79}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"x\": 96, \"y\": 98}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"x\": 25, \"y\": 5}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
32 | Check If A Number Is Power Of Another Number 1 | C++ | int checkIfANumberIsPowerOfAnotherNumber1(int x, int y) { | [
"x",
"y"
] | def check_if_a_number_is_power_of_another_number_1(x, y):
res1 = (math.log(y) / math.log(x))
res2 = (math.log(y) / math.log(x))
return (1 if (res1 == res2) else 0) | bool check_if_a_number_is_power_of_another_number_1(int x, int y) {
int res1 = log ( y ) / log ( x );
double res2 = log ( y ) / log ( x );
return ( res1 == res2 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(57, 1, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 9, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 101, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 10000, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 46656, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 2048, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 40, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 79, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 98, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 5, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkIfANumberIsPowerOfAnotherNumber1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"x\": 57, \"y\": 1}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"x\": 3, \"y\": 9}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"x\": 10, \"y\": 101}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"x\": 10, \"y\": 10000}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"x\": 6, \"y\": 46656}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"x\": 2, \"y\": 2048}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"x\": 2, \"y\": 40}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"x\": 20, \"y\": 79}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"x\": 96, \"y\": 98}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"x\": 25, \"y\": 5}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
33 | Check If String Remains Palindrome After Removing Given Number Of Characters | C++ | bool checkIfStringRemainsPalindromeAfterRemovingGivenNumberOfCharacters(string str, int n) { | [
"str",
"n"
] | def check_if_string_remains_palindrome_after_removing_given_number_of_characters(str, n):
l = len(str)
if (l >= n):
return True
return False | bool check_if_string_remains_palindrome_after_removing_given_number_of_characters(string str, int n) {
int len = str . length ( );
if ( len >= n ) return true;
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string str, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"ZCoQhuM\", 2, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"7437725\", 53, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", 30, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"buGlvR\", 1, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"9\", 92, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"101101010110\", 3, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"YguiM\", 18, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"8198\", 90, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11101\", 71, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"hUInqJXNdbfP\", 4, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkIfStringRemainsPalindromeAfterRemovingGivenNumberOfCharacters",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"str\": \"ZCoQhuM\", \"n\": 2}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"str\": \"7437725\", \"n\": 53}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"str\": \"11\", \"n\": 30}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"str\": \"buGlvR\", \"n\": 1}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"str\": \"9\", \"n\": 92}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"str\": \"101101010110\", \"n\": 3}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"str\": \"YguiM\", \"n\": 18}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"str\": \"8198\", \"n\": 90}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"str\": \"11101\", \"n\": 71}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"str\": \"hUInqJXNdbfP\", \"n\": 4}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
34 | Check If X Can Give Change To Every Person In The Queue | C++ | int checkIfXCanGiveChangeToEveryPersonInTheQueue(vector<int> notes, int n) { | [
"notes",
"n"
] | def check_if_x_can_give_change_to_every_person_in_the_queue(notes, n):
fiveCount = 0
tenCount = 0
for i in range(n):
if (notes[i] == 5):
fiveCount += 1
elif (notes[i] == 10):
if (fiveCount > 0):
fiveCount -= 1
tenCount += 1
else:
return 0
elif ((fiveCount > 0) and (tenCount > 0)):
fiveCount -= 1
tenCount -= 1
elif (fiveCount >= 3):
fiveCount -= 3
else:
return 0
return 1 | int check_if_x_can_give_change_to_every_person_in_the_queue(vector<int> notes, int n) {
int fiveCount = 0;
int tenCount = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( notes [ i ] == 5 ) fiveCount ++;
else if ( notes [ i ] == 10 ) {
if ( fiveCount > 0 ) {
fiveCount --;
tenCount ++;
}
else return 0;
}
else {
if ( fiveCount > 0 && tenCount > 0 ) {
fiveCount --;
tenCount --;
}
else if ( fiveCount >= 3 ) {
fiveCount -= 3;
}
else return 0;
}
}
return 1;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> notes, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(notes, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 5, 5, 10, 20}, 4, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 5, 5, 20, 10}, 5, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10}, 27, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 18}, 12, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 5, 20}, 2, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 17, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 10, 20, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 7, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-82, -10, -78, -84, 68, 62, 10, 20, -86, -98, 92, 70, 40, -12, -20, -36, 8, -70, 6, 8, 44, -24, 8, -18, 76, -54, -14, -94, -68, -62, -24, -36, -74, 92, 92, -80, 48, 56, 94}, 31, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 25, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 46, 93, 57, 82, 34, 83, 80, 77, 36, 80, 85, 69, 28, 9, 56, 49, 27, 83, 25, 1, 80, 99, 14, 69, 82, 79, 71, 74, 34}, 20, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkIfXCanGiveChangeToEveryPersonInTheQueue",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"notes\": [5, 5, 5, 10, 20], \"n\": 4}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"notes\": [5, 5, 5, 20, 10], \"n\": 5}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"notes\": [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10], \"n\": 27}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"notes\": [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 18], \"n\": 12}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"notes\": [5, 5, 20], \"n\": 2}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"notes\": [10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], \"n\": 17}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"notes\": [5, 10, 20, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], \"n\": 7}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"notes\": [-82, -10, -78, -84, 68, 62, 10, 20, -86, -98, 92, 70, 40, -12, -20, -36, 8, -70, 6, 8, 44, -24, 8, -18, 76, -54, -14, -94, -68, -62, -24, -36, -74, 92, 92, -80, 48, 56, 94], \"n\": 31}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"notes\": [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5], \"n\": 25}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"notes\": [46, 46, 93, 57, 82, 34, 83, 80, 77, 36, 80, 85, 69, 28, 9, 56, 49, 27, 83, 25, 1, 80, 99, 14, 69, 82, 79, 71, 74, 34], \"n\": 20}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
35 | Check Integer Overflow Multiplication | C++ | bool checkIntegerOverflowMultiplication(long long a, long long b) { | [
"a",
"b"
] | def check_integer_overflow_multiplication(a, b):
if ((a == 0) or (b == 0)):
return False
result = (a * b)
if ((result >= 9223372036854775807) or (result <= (- 9223372036854775808))):
result = 0
if (a == (result // b)):
print((result // b))
return False
else:
return True | bool check_integer_overflow_multiplication(long long a, long long b) {
if ( a == 0 || b == 0 ) return false;
long long result = a * b;
if ( a == result / b ) return false;
else return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(long long a, long long b, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(37, 80, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10000000000, -10000000000, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10000000000, 10000000000, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(999999999, 999999999, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 36, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 56, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 21, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 38, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 82, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 41, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkIntegerOverflowMultiplication",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"a\": 37, \"b\": 80}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"a\": 10000000000, \"b\": -10000000000}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"a\": 10000000000, \"b\": 10000000000}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"a\": 999999999, \"b\": 999999999}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"a\": 39, \"b\": 36}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"a\": 92, \"b\": 56}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"a\": 14, \"b\": 21}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"a\": 19, \"b\": 38}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a\": 14, \"b\": 82}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"a\": 88, \"b\": 41}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
36 | Check Large Number Divisible 13 Not | C++ | bool checkLargeNumberDivisible13Not(string num) { | [
"num"
] | def check_large_number_divisible_13_not(num):
length = len(num)
if ((length == 1) and (num[0] == '0')):
return True
if ((length % 3) == 1):
num = (str(num) + '00')
length += 2
elif ((length % 3) == 2):
num = (str(num) + '0')
length += 1
sum = 0
p = 1
for i in range((length - 1), (- 1), (- 1)):
group = 0
group += (ord(num[i]) - ord('0'))
i -= 1
group += ((ord(num[i]) - ord('0')) * 10)
i -= 1
group += ((ord(num[i]) - ord('0')) * 100)
sum = (sum + (group * p))
p *= (- 1)
sum = abs(sum)
return ((sum % 13) == 0) | bool check_large_number_divisible_13_not(string num) {
int length = num . size ( );
if ( length == 1 && num [ 0 ] == '0' ) return true;
if ( length % 3 == 1 ) {
num += "00";
length += 2;
}
else if ( length % 3 == 2 ) {
num += "0";
length += 1;
}
int sum = 0, p = 1;
for ( int i = length - 1;
i >= 0;
i -- ) {
int group = 0;
group += num [ i -- ] - '0';
group += ( num [ i -- ] - '0' ) * 10;
group += ( num [ i ] - '0' ) * 100;
sum = sum + group * p;
p *= ( - 1 );
}
sum = abs ( sum );
return ( sum % 13 == 0 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string num, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"vzTUaItpCpLnjY\", false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"33855\", true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0011110101011\", true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"MMQ\", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"439340517954\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000000000\", true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"UugAuRRJbjEgl\", true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"6406553695441\", true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011001\", true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"yjFqEEvgiNjEX\", true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkLargeNumberDivisible13Not",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"num\": \"vzTUaItpCpLnjY\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"num\": \"33855\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"num\": \"0011110101011\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"num\": \"MMQ\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"num\": \"439340517954\"}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"num\": \"000000000\"}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"num\": \"UugAuRRJbjEgl\"}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"num\": \"6406553695441\"}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"num\": \"011001\"}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"num\": \"yjFqEEvgiNjEX\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
37 | Check Line Passes Origin | C++ | bool checkLinePassesOrigin(int x1, int y1, int x2, int y2) { | [
"x1",
"y1",
"x2",
"y2"
] | def check_line_passes_origin(x1, y1, x2, y2):
return ((x1 * (y2 - y1)) == (y1 * (x2 - x1))) | bool check_line_passes_origin(int x1, int y1, int x2, int y2) {
return ( x1 * ( y2 - y1 ) == y1 * ( x2 - x1 ) );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int x1, int y1, int x2, int y2, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x1, y1, x2, y2), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1, 28, 2, 56, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 0, 20, 0, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(0, 1, 0, 17, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 1, 10, 10, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 86, 19, 4, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 86, 11, 6, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 46, 33, 33, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 29, 95, 12, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 35, 25, 36, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 17, 45, 35, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkLinePassesOrigin",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"x1\": 1, \"y1\": 28, \"x2\": 2, \"y2\": 56}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"x1\": 10, \"y1\": 0, \"x2\": 20, \"y2\": 0}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"x1\": 0, \"y1\": 1, \"x2\": 0, \"y2\": 17}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"x1\": 1, \"y1\": 1, \"x2\": 10, \"y2\": 10}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"x1\": 82, \"y1\": 86, \"x2\": 19, \"y2\": 4}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"x1\": 78, \"y1\": 86, \"x2\": 11, \"y2\": 6}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"x1\": 13, \"y1\": 46, \"x2\": 33, \"y2\": 33}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"x1\": 18, \"y1\": 29, \"x2\": 95, \"y2\": 12}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"x1\": 42, \"y1\": 35, \"x2\": 25, \"y2\": 36}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"x1\": 29, \"y1\": 17, \"x2\": 45, \"y2\": 35}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
38 | Check Number Is Perfect Square Using Additionsubtraction | C++ | bool checkNumberIsPerfectSquareUsingAdditionsubtraction(int n) { | [
"n"
] | def check_number_is_perfect_square_using_additionsubtraction(n):
i = 1
the_sum = 0
while (the_sum < n):
the_sum += i
if (the_sum == n):
return True
i += 2
return False | bool check_number_is_perfect_square_using_additionsubtraction(int n) {
for ( int sum = 0, i = 1;
sum < n;
i += 2 ) {
sum += i;
if ( sum == n ) return true;
}
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(121, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkNumberIsPerfectSquareUsingAdditionsubtraction",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 1}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 4}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 9}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"n\": 25}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"n\": 36}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 3}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"n\": 121}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 14}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 17}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 80}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
39 | Check Number Power K Using Base Changing Method | C++ | bool checkNumberPowerKUsingBaseChangingMethod(int n, int k) { | [
"n",
"k"
] | def check_number_power_k_using_base_changing_method(n, k):
oneSeen = False
while (n > 0):
digit = (n % k)
if (digit > 1):
return False
if (digit == 1):
if oneSeen:
return False
oneSeen = True
n //= k
return True | bool check_number_power_k_using_base_changing_method(unsigned int n, unsigned int k) {
bool oneSeen = false;
while ( n > 0 ) {
int digit = n % k;
if ( digit > 1 ) return false;
if ( digit == 1 ) {
if ( oneSeen ) return false;
oneSeen = true;
}
n /= k;
}
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, int k, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(64, 4, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 2, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 3, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 72, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 9, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 17, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 20, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 79, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 81, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 89, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkNumberPowerKUsingBaseChangingMethod",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 64, \"k\": 4}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 16, \"k\": 2}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 27, \"k\": 3}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": 81, \"k\": 72}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"n\": 1, \"k\": 9}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 69, \"k\": 17}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 8, \"k\": 20}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 31, \"k\": 79}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 43, \"k\": 81}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 54, \"k\": 89}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
40 | Check Occurrences Character Appear Together | C++ | bool checkOccurrencesCharacterAppearTogether(string s, char c) { | [
"s",
"c"
] | def check_occurrences_character_appear_together(s, c):
oneSeen = False
i = 0
n = len(s)
while (i < n):
if (s[i] == c):
if (oneSeen == True):
return False
while ((i < n) and (s[i] == c)):
i = (i + 1)
oneSeen = True
else:
i = (i + 1)
return True | bool check_occurrences_character_appear_together(string s, char c) {
bool oneSeen = false;
int i = 0, n = s . length ( );
while ( i < n ) {
if ( s [ i ] == c ) {
if ( oneSeen == true ) return false;
while ( i < n && s [ i ] == c ) i ++;
oneSeen = true;
}
else i ++;
}
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string s, char c, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s, c), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"gILrzLimS\", 'm', true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"307471222\", '2', true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"110\", '0', true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"GcAB\", 'v', true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"113\", '3', true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011110010\", '0', false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"wcwob\", 'w', false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"74571582216153\", '1', false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100000011\", '0', true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ryPErkzY\", 'q', true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkOccurrencesCharacterAppearTogether",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"s\": \"gILrzLimS\", \"c\": \"m\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"s\": \"307471222\", \"c\": \"2\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"s\": \"110\", \"c\": \"0\"}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"s\": \"GcAB\", \"c\": \"v\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"s\": \"113\", \"c\": \"3\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"s\": \"011110010\", \"c\": \"0\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"s\": \"wcwob\", \"c\": \"w\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"s\": \"74571582216153\", \"c\": \"1\"}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"s\": \"100000011\", \"c\": \"0\"}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"s\": \"ryPErkzY\", \"c\": \"q\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
41 | Check Possible Sort Array Conditional Swapping Adjacent Allowed | C++ | bool checkPossibleSortArrayConditionalSwappingAdjacentAllowed(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_possible_sort_array_conditional_swapping_adjacent_allowed(arr, n):
for i in range(0, (n - 1)):
if (arr[i] > arr[(i + 1)]):
if ((arr[i] - arr[(i + 1)]) == 1):
(arr[i], arr[(i + 1)]) = (arr[(i + 1)], arr[i])
else:
return False
return True | bool check_possible_sort_array_conditional_swapping_adjacent_allowed(vector<int> arr, int n) {
for ( int i = 0;
i < n - 1;
i ++ ) {
if ( arr [ i ] > arr [ i + 1 ] ) {
if ( arr [ i ] - arr [ i + 1 ] == 1 ) swap ( arr [ i ], arr [ i + 1 ] );
else return false;
}
}
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 4, 12, 16, 37, 44, 47, 51, 55, 57, 57, 62, 62, 62, 64, 69, 69, 70, 72, 81, 81, 88, 89, 97}, 15, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, 0, 14, -16, -12, -72, 62, -34, -72, 30, 84, -60, 84, -64, 50, 74, 18, -82, -64, -64, -74, -56, 86, 84, -32, -10, 20, 4, 8, 96, 82, 26, 42}, 18, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 31, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({48, 66, 83, 12, 77, 98, 18, 33, 21, 16, 28, 24, 46, 43}, 13, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -58, -36, -28, -6, 2, 4, 26, 48, 58, 60, 62, 62, 98}, 10, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 0, 1}, 4, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, 38, 41, 41, 42, 51, 54, 58, 68, 76, 80, 85}, 9, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({84, -38, 52, -72, -24, 82, 54, 74, 0}, 8, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1}, 2, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({63, 31, 14, 19, 77, 64, 62, 23, 22, 19, 39, 9, 79, 1, 87, 29, 58, 3, 3, 39, 1, 39, 35, 64, 64}, 13, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkPossibleSortArrayConditionalSwappingAdjacentAllowed",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"arr\": [1, 4, 12, 16, 37, 44, 47, 51, 55, 57, 57, 62, 62, 62, 64, 69, 69, 70, 72, 81, 81, 88, 89, 97], \"n\": 15}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [-86, 0, 14, -16, -12, -72, 62, -34, -72, 30, 84, -60, 84, -64, 50, 74, 18, -82, -64, -64, -74, -56, 86, 84, -32, -10, 20, 4, 8, 96, 82, 26, 42], \"n\": 18}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 31}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"arr\": [48, 66, 83, 12, 77, 98, 18, 33, 21, 16, 28, 24, 46, 43], \"n\": 13}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-92, -58, -36, -28, -6, 2, 4, 26, 48, 58, 60, 62, 62, 98], \"n\": 10}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 0, 1, 0, 1], \"n\": 4}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"arr\": [22, 38, 41, 41, 42, 51, 54, 58, 68, 76, 80, 85], \"n\": 9}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [84, -38, 52, -72, -24, 82, 54, 74, 0], \"n\": 8}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"arr\": [0, 1, 1], \"n\": 2}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [63, 31, 14, 19, 77, 64, 62, 23, 22, 19, 39, 9, 79, 1, 87, 29, 58, 3, 3, 39, 1, 39, 35, 64, 64], \"n\": 13}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
42 | Check Possible Transform One String Another | C++ | bool checkPossibleTransformOneStringAnother(string s1, string s2) { | [
"s1",
"s2"
] | def check_possible_transform_one_string_another(s1, s2):
n = len(s1)
m = len(s2)
dp = [[False for i in range((m + 1))] for i in range((n + 1))]
dp[0][0] = True
for i in range(len(s1)):
for j in range((len(s2) + 1)):
if dp[i][j]:
if ((j < len(s2)) and (s1[i].upper() == s2[j])):
dp[(i + 1)][(j + 1)] = True
if (s1[i].isupper() == False):
dp[(i + 1)][j] = True
return dp[n][m] | bool check_possible_transform_one_string_another(string s1, string s2) {
int n = s1 . length ( );
int m = s2 . length ( );
bool dp [ n + 1 ] [ m + 1 ];
for ( int i = 0;
i <= n;
i ++ ) {
for ( int j = 0;
j <= m;
j ++ ) {
dp [ i ] [ j ] = false;
}
}
dp [ 0 ] [ 0 ] = true;
for ( int i = 0;
i < s1 . length ( );
i ++ ) {
for ( int j = 0;
j <= s2 . length ( );
j ++ ) {
if ( dp [ i ] [ j ] ) {
if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true;
if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true;
}
}
}
return ( dp [ n ] [ m ] );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string s1, string s2, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s1, s2), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"daBcd\", \"ABC\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"417514\", \"9\", false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"010000\", \"1111011010\", false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ZcKYguiMrdyn\", \"iz\", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"argaju\", \"RAJ\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1110101101\", \"110101001\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ySOCoSaygi\", \"aRhxkYqh\", false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"204\", \"6986871066\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10011100000010\", \"0\", true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"nMAioozPmY\", \"WZFdDKw\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkPossibleTransformOneStringAnother",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"s1\": \"daBcd\", \"s2\": \"ABC\"}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"s1\": \"417514\", \"s2\": \"9\"}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"s1\": \"010000\", \"s2\": \"1111011010\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"s1\": \"ZcKYguiMrdyn\", \"s2\": \"iz\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"s1\": \"argaju\", \"s2\": \"RAJ\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"s1\": \"1110101101\", \"s2\": \"110101001\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"s1\": \"ySOCoSaygi\", \"s2\": \"aRhxkYqh\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"s1\": \"204\", \"s2\": \"6986871066\"}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"s1\": \"10011100000010\", \"s2\": \"0\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"s1\": \"nMAioozPmY\", \"s2\": \"WZFdDKw\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
44 | Check Reversing Sub Array Make Array Sorted 1 | C++ | bool checkReversingSubArrayMakeArraySorted1(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_reversing_sub_array_make_array_sorted_1(arr, n):
if (n == 1):
return True
i = 1
for i in range(1, n):
if (arr[(i - 1)] < arr[i]):
if (i == n):
return True
j = i
while (arr[j] < arr[(j - 1)]):
if ((i > 1) and (arr[j] < arr[(i - 2)])):
return False
j += 1
if (j == n):
return True
k = j
if (arr[k] < arr[(i - 1)]):
return False
while ((k > 1) and (k < n)):
if (arr[k] < arr[(k - 1)]):
return False
k += 1
return True | bool check_reversing_sub_array_make_array_sorted_1(vector<int> arr, int n) {
if ( n == 1 ) return true;
int i;
for ( i = 1;
i < n && arr [ i - 1 ] < arr [ i ];
i ++ );
if ( i == n ) return true;
int j = i;
while ( arr [ j ] < arr [ j - 1 ] ) {
if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false;
j ++;
}
if ( j == n ) return true;
int k = j;
if ( arr [ k ] < arr [ i - 1 ] ) return false;
while ( k > 1 && k < n ) {
if ( arr [ k ] < arr [ k - 1 ] ) return false;
k ++;
}
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 2, 5, 4, 3}, 5, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 4, 5, 3}, 5, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0}, 4, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 99, 40, 33, 61, 4, 64, 92, 28, 27, 21, 35, 40, 79, 10, 20, 76, 87, 80, 15, 57, 39, 96, 98, 99, 72, 72, 50, 61, 39, 35, 70, 27}, 32, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -86, -58, -22, -12, 0, 26}, 6, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0}, 24, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 10, 27, 30, 40, 47, 49, 55, 59, 60, 68, 82, 91}, 8, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({36, 56, -56, 94, 52, -82, 88, -62, 70, -94, 38, 10, -78, 66, -94, -72, 18, 96, -72, 88, -6, 48, 6, -88, 64, -96, -40, 8, 36, 36, -90, -68, -20, -76, 22, -92}, 30, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 31, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 5, 42, 28, 47, 26, 88, 16, 30, 30, 36, 49, 21, 95, 99, 21, 41, 52, 57, 39, 69, 2, 42, 22, 55, 92, 64, 27, 95, 71, 19, 38, 40, 65, 7, 21, 29, 38, 13, 11, 41, 54, 38, 40, 35, 51, 88}, 46, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkReversingSubArrayMakeArraySorted1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [1, 2, 5, 4, 3], \"n\": 5}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [1, 2, 4, 5, 3], \"n\": 5}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"arr\": [1, 1, 0, 0], \"n\": 4}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [5, 99, 40, 33, 61, 4, 64, 92, 28, 27, 21, 35, 40, 79, 10, 20, 76, 87, 80, 15, 57, 39, 96, 98, 99, 72, 72, 50, 61, 39, 35, 70, 27], \"n\": 32}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-98, -92, -86, -58, -22, -12, 0, 26], \"n\": 6}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0], \"n\": 24}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"arr\": [6, 10, 27, 30, 40, 47, 49, 55, 59, 60, 68, 82, 91], \"n\": 8}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"arr\": [36, 56, -56, 94, 52, -82, 88, -62, 70, -94, 38, 10, -78, 66, -94, -72, 18, 96, -72, 88, -6, 48, 6, -88, 64, -96, -40, 8, 36, 36, -90, -68, -20, -76, 22, -92], \"n\": 30}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 31}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"arr\": [2, 5, 42, 28, 47, 26, 88, 16, 30, 30, 36, 49, 21, 95, 99, 21, 41, 52, 57, 39, 69, 2, 42, 22, 55, 92, 64, 27, 95, 71, 19, 38, 40, 65, 7, 21, 29, 38, 13, 11, 41, 54, 38, 40, 35, 51, 88], \"n\": 46}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
45 | Check String Can Obtained Rotating Another String 2 Places | C++ | bool checkStringCanObtainedRotatingAnotherString2Places(string str1, string str2) { | [
"str1",
"str2"
] | def check_string_can_obtained_rotating_another_string_2_places(str1, str2):
if (len(str1) != len(str2)):
return False
clock_rot = ''
anticlock_rot = ''
l = len(str2)
anticlock_rot = ((anticlock_rot + str2[(l - 2):]) + str2[0:(l - 2)])
clock_rot = ((clock_rot + str2[2:]) + str2[0:2])
return ((str1 == clock_rot) or (str1 == anticlock_rot)) | bool check_string_can_obtained_rotating_another_string_2_places(string str1, string str2) {
if ( str1 . length ( ) != str2 . length ( ) ) return false;
string clock_rot = "";
string anticlock_rot = "";
int len = str2 . length ( );
anticlock_rot = anticlock_rot + str2 . substr ( len - 2, 2 ) + str2 . substr ( 0, len - 2 );
clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0, 2 );
return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string str1, string str2, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str1, str2), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"amazon\", \"azonam\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"onamaz\", \"amazon\", true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"amazon\", \"azoman\", false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ab\", \"ab\", true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"737009\", \"239119\", false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000110\", \"01111\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"l\", \"YVo hqvnGxow\", false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"4420318628\", \"52856\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11011111000000\", \"10\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\" pvFHANc\", \"xBIDFbiGb\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkStringCanObtainedRotatingAnotherString2Places",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"str1\": \"amazon\", \"str2\": \"azonam\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"str1\": \"onamaz\", \"str2\": \"amazon\"}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"str1\": \"amazon\", \"str2\": \"azoman\"}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"str1\": \"ab\", \"str2\": \"ab\"}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"str1\": \"737009\", \"str2\": \"239119\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"str1\": \"000110\", \"str2\": \"01111\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"str1\": \"l\", \"str2\": \"YVo hqvnGxow\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"str1\": \"4420318628\", \"str2\": \"52856\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"str1\": \"11011111000000\", \"str2\": \"10\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"str1\": \" pvFHANc\", \"str2\": \"xBIDFbiGb\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
46 | Check String Follows Anbn Pattern Not | C++ | bool checkStringFollowsAnbnPatternNot(string str) { | [
"str"
] | def check_string_follows_anbn_pattern_not(str):
n = len(str)
for i in range(n):
if (str[i] != 'a'):
break
if ((i * 2) != n):
return False
for j in range(i, n):
if (str[j] != 'b'):
return False
return True | bool check_string_follows_anbn_pattern_not(string str) {
int n = str . length ( );
int i;
for ( i = 0;
i < n;
i ++ ) if ( str [ i ] != 'a' ) break;
if ( i * 2 != n ) return false;
int j;
for ( j = i;
j < n;
j ++ ) if ( str [ j ] != 'b' ) return false;
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string str, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"ba\", false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aabb\", true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abab\", false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aaabb\", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aabbb\", false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abaabbaa\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abaababb\", false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"bbaa\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11001000\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ZWXv te\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkStringFollowsAnbnPatternNot",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"str\": \"ba\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"str\": \"aabb\"}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"str\": \"abab\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"str\": \"aaabb\"}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"str\": \"aabbb\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"str\": \"abaabbaa\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"str\": \"abaababb\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"str\": \"bbaa\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"str\": \"11001000\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"str\": \"ZWXv te\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
47 | Check Two Given Circles Touch Intersect | C++ | int checkTwoGivenCirclesTouchIntersect(int x1, int y1, int x2, int y2, int r1, int r2) { | [
"x1",
"y1",
"x2",
"y2",
"r1",
"r2"
] | def check_two_given_circles_touch_intersect(x1, y1, x2, y2, r1, r2):
distSq = (((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)))
radSumSq = ((r1 + r2) * (r1 + r2))
if (distSq == radSumSq):
return 1
elif (distSq > radSumSq):
return (- 1)
else:
return 0 | int check_two_given_circles_touch_intersect(int x1, int y1, int x2, int y2, int r1, int r2) {
int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 );
int radSumSq = ( r1 + r2 ) * ( r1 + r2 );
if ( distSq == radSumSq ) return 1;
else if ( distSq > radSumSq ) return - 1;
else return 0;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x1, int y1, int x2, int y2, int r1, int r2, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x1, y1, x2, y2, r1, r2), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(11, 36, 62, 64, 50, 4, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 1, 62, 64, 54, 41, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 1, 47, 90, 14, 71, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 67, 9, 52, 94, 21, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 10, 79, 45, 67, 78, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 86, 99, 43, 83, 63, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 90, 42, 82, 77, 32, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 23, 28, 26, 60, 45, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 61, 63, 77, 92, 76, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 99, 6, 19, 21, 28, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkTwoGivenCirclesTouchIntersect",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"x1\": 11, \"y1\": 36, \"x2\": 62, \"y2\": 64, \"r1\": 50, \"r2\": 4}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"x1\": 87, \"y1\": 1, \"x2\": 62, \"y2\": 64, \"r1\": 54, \"r2\": 41}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"x1\": 51, \"y1\": 1, \"x2\": 47, \"y2\": 90, \"r1\": 14, \"r2\": 71}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"x1\": 89, \"y1\": 67, \"x2\": 9, \"y2\": 52, \"r1\": 94, \"r2\": 21}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"x1\": 64, \"y1\": 10, \"x2\": 79, \"y2\": 45, \"r1\": 67, \"r2\": 78}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"x1\": 57, \"y1\": 86, \"x2\": 99, \"y2\": 43, \"r1\": 83, \"r2\": 63}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"x1\": 65, \"y1\": 90, \"x2\": 42, \"y2\": 82, \"r1\": 77, \"r2\": 32}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"x1\": 32, \"y1\": 23, \"x2\": 28, \"y2\": 26, \"r1\": 60, \"r2\": 45}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"x1\": 73, \"y1\": 61, \"x2\": 63, \"y2\": 77, \"r1\": 92, \"r2\": 76}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"x1\": 3, \"y1\": 99, \"x2\": 6, \"y2\": 19, \"r1\": 21, \"r2\": 28}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
48 | Check Whether Arithmetic Progression Can Formed Given Array | C++ | bool checkWhetherArithmeticProgressionCanFormedGivenArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def check_whether_arithmetic_progression_can_formed_given_array(arr, n):
if (n == 1):
return True
arr.sort()
d = (arr[1] - arr[0])
for i in range(2, n):
if ((arr[i] - arr[(i - 1)]) != d):
return False
return True | bool check_whether_arithmetic_progression_can_formed_given_array(vector<int> arr, int n) {
if ( n == 1 ) return true;
sort(arr.begin(), arr.end());
int d = arr [ 1 ] - arr [ 0 ];
for ( int i = 2;
i < n;
i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false;
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 4, 16, 64}, 4, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 4, 8, 12}, 4, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-2, 0, 2, 4, 6}, 5, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 7, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 56, 66, 76, 86}, 5, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 56, 56, 66, 76, 86}, 6, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 9, 11, 21, 44, 45, 61, 67, 78, 97, 98, 99}, 11, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -84, -74, -70, -68, -62, -50, -50, -38, -36, -36, -36, -34, -34, -28, -28, -26, -18, -12, -4, -4, -2, -2, 6, 6, 14, 24, 34, 36, 44, 50, 54, 54, 62, 64, 66, 70, 74, 74, 78, 84, 86}, 33, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 3, 5, 11, 14, 15, 15, 17, 18, 19, 20, 20, 22, 32, 33, 35, 36, 37, 39, 44, 45, 46, 51, 54, 57, 58, 61, 61, 63, 64, 67, 69, 70, 70, 79, 82, 86, 89, 92, 93, 95, 99}, 40, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkWhetherArithmeticProgressionCanFormedGivenArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [1, 4, 16, 64], \"n\": 4}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"arr\": [0, 4, 8, 12], \"n\": 4}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"arr\": [-2, 0, 2, 4, 6], \"n\": 5}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \"n\": 7}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [46, 56, 66, 76, 86], \"n\": 5}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [46, 56, 56, 66, 76, 86], \"n\": 6}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [7, 9, 11, 21, 44, 45, 61, 67, 78, 97, 98, 99], \"n\": 11}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [-96, -84, -74, -70, -68, -62, -50, -50, -38, -36, -36, -36, -34, -34, -28, -28, -26, -18, -12, -4, -4, -2, -2, 6, 6, 14, 24, 34, 36, 44, 50, 54, 54, 62, 64, 66, 70, 74, 74, 78, 84, 86], \"n\": 33}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 33}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [1, 3, 5, 11, 14, 15, 15, 17, 18, 19, 20, 20, 22, 32, 33, 35, 36, 37, 39, 44, 45, 46, 51, 54, 57, 58, 61, 61, 63, 64, 67, 69, 70, 70, 79, 82, 86, 89, 92, 93, 95, 99], \"n\": 40}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
49 | Check Whether Given Degrees Vertices Represent Graph Tree | C++ | bool checkWhetherGivenDegreesVerticesRepresentGraphTree(vector<int> degree, int n) { | [
"degree",
"n"
] | def check_whether_given_degrees_vertices_represent_graph_tree(degree, n):
deg_sum = sum(degree)
if ((2 * (n - 1)) == deg_sum):
return True
else:
return False | bool check_whether_given_degrees_vertices_represent_graph_tree(vector<int> degree, int n) {
int deg_sum = 0;
for ( int i = 0;
i < n;
i ++ ) deg_sum += degree [ i ];
return ( 2 * ( n - 1 ) == deg_sum );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> degree, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(degree, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 3, 1, 1, 1}, 5, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 1, 1, 2}, 5, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 1, 1, 1}, 5, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 3, 3, 4}, 6, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-10, 12, 2}, 3, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0}, 19, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 6, 10, 13, 15, 17, 18, 23, 26, 28, 30, 32, 32, 33, 36, 39, 39, 41, 43, 50, 50, 51, 53, 54, 59, 59, 63, 63, 63, 66, 66, 71, 71, 74, 78, 89, 89, 93}, 30, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, -96, -14, 74, -20}, 4, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 31, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({97, 73, 87, 45, 64, 30, 53, 50, 62, 42, 28, 58, 31, 90}, 10, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkWhetherGivenDegreesVerticesRepresentGraphTree",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"degree\": [2, 3, 1, 1, 1], \"n\": 5}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"degree\": [2, 2, 1, 1, 2], \"n\": 5}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"degree\": [2, 2, 1, 1, 1], \"n\": 5}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"degree\": [0, 0, 0, 3, 3, 4], \"n\": 6}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"degree\": [-10, 12, 2], \"n\": 3}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"degree\": [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0], \"n\": 19}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"degree\": [1, 6, 10, 13, 15, 17, 18, 23, 26, 28, 30, 32, 32, 33, 36, 39, 39, 41, 43, 50, 50, 51, 53, 54, 59, 59, 63, 63, 63, 66, 66, 71, 71, 74, 78, 89, 89, 93], \"n\": 30}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"degree\": [66, -96, -14, 74, -20], \"n\": 4}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"degree\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 31}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"degree\": [97, 73, 87, 45, 64, 30, 53, 50, 62, 42, 28, 58, 31, 90], \"n\": 10}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
50 | Check Whether Given Number Even Odd | C++ | bool checkWhetherGivenNumberEvenOdd(int n) { | [
"n"
] | def check_whether_given_number_even_odd(n):
return ((n % 2) == 0) | bool check_whether_given_number_even_odd(int n) {
return ( n % 2 == 0 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(67, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkWhetherGivenNumberEvenOdd",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"n\": 67}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 90}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"n\": 55}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"n\": 90}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 83}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"n\": 32}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"n\": 58}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"n\": 38}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 87}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 87}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
51 | Check Whether Given Number Even Odd 1 | C++ | bool checkWhetherGivenNumberEvenOdd1(int n) { | [
"n"
] | def check_whether_given_number_even_odd_1(n):
return (not (n & 1)) | bool check_whether_given_number_even_odd_1(int n) {
return ( ! ( n & 1 ) );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(57, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkWhetherGivenNumberEvenOdd1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"n\": 57}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"n\": 73}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"n\": 79}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"n\": 36}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 71}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 23}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 41}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"n\": 66}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"n\": 46}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"n\": 50}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
52 | Check Whether Triangle Valid Not Sides Given | C++ | bool checkWhetherTriangleValidNotSidesGiven(int a, int b, int c) { | [
"a",
"b",
"c"
] | def check_whether_triangle_valid_not_sides_given(a, b, c):
if (((a + b) <= c) or ((a + c) <= b) or ((b + c) <= a)):
return False
else:
return True | bool check_whether_triangle_valid_not_sides_given(int a, int b, int c) {
if ( a + b <= c || a + c <= b || b + c <= a ) return false;
else return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int c, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(29, 19, 52, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 34, 49, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 14, 65, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 12, 94, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 39, 22, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 85, 9, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 36, 41, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 34, 37, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 90, 27, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 16, 1, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "checkWhetherTriangleValidNotSidesGiven",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"a\": 29, \"b\": 19, \"c\": 52}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"a\": 83, \"b\": 34, \"c\": 49}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"a\": 48, \"b\": 14, \"c\": 65}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"a\": 59, \"b\": 12, \"c\": 94}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"a\": 56, \"b\": 39, \"c\": 22}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"a\": 68, \"b\": 85, \"c\": 9}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"a\": 63, \"b\": 36, \"c\": 41}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"a\": 95, \"b\": 34, \"c\": 37}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a\": 2, \"b\": 90, \"c\": 27}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"a\": 11, \"b\": 16, \"c\": 1}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
53 | Chocolate Distribution Problem | C++ | int chocolateDistributionProblem(vector<int> arr, int n, int m) { | [
"arr",
"n",
"m"
] | def chocolate_distribution_problem(arr, n, m):
if ((m == 0) or (n == 0)):
return 0
arr.sort()
if (n < m):
return (- 1)
min_diff = sys.maxsize
first = 0
last = 0
i = 0
while (((i + m) - 1) < n):
diff = (arr[((i + m) - 1)] - arr[i])
if (diff < min_diff):
min_diff = diff
first = i
last = ((i + m) - 1)
i += 1
return (arr[last] - arr[first]) | int chocolate_distribution_problem(vector<int> arr, int n, int m) {
if ( m == 0 || n == 0 ) return 0;
sort(arr.begin(), arr.end());
if ( n < m ) return - 1;
int min_diff = INT_MAX;
int first = 0, last = 0;
for ( int i = 0;
i + m - 1 < n;
i ++ ) {
int diff = arr [ i + m - 1 ] - arr [ i ];
if ( diff < min_diff ) {
min_diff = diff;
first = i;
last = i + m - 1;
}
}
return ( arr [ last ] - arr [ first ] );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int m, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, m), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 5, 11, 23, 33, 35, 39, 51, 52, 56, 74, 76, 76, 79, 85, 88, 93, 98}, 16, 13, 65); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -94, -88, -84, -74, -70, -56, -50, -48, -42, -34, -24, -18, -14, 0, 4, 4, 16, 16, 30, 36, 42, 52, 56, 72, 74, 76, 84, 88}, 15, 28, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1}, 5, 5, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 5, 5, 12, 16, 16, 16, 18, 29, 37, 38, 40, 43, 44, 49, 57, 60, 62, 63, 67, 69, 73, 74, 75, 76, 78, 84, 85, 86, 88, 89, 92}, 25, 18, 57); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -80, -50, -44, -42, -36, -36, -28, -10, -8, -4, -2, 2, 10, 18, 18, 26, 32, 36, 56, 80, 86, 88, 90}, 16, 12, 60); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 14, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({13, 15, 62, 65, 87}, 3, 4, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -88, -88, -80, -76, -62, -60, -60, -50, -48, -36, -36, -32, -26, -14, -8, 4, 18, 18, 22, 28, 30, 30, 32, 48, 48, 58, 60, 64, 72, 78, 82, 94}, 31, 17, 90); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 9, 6, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({17, 23, 25, 38, 40, 53, 58, 73, 77}, 8, 6, 35); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "chocolateDistributionProblem",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 65, \"inputs\": {\"arr\": [2, 5, 11, 23, 33, 35, 39, 51, 52, 56, 74, 76, 76, 79, 85, 88, 93, 98], \"n\": 16, \"m\": 13}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [-94, -94, -88, -84, -74, -70, -56, -50, -48, -42, -34, -24, -18, -14, 0, 4, 4, 16, 16, 30, 36, 42, 52, 56, 72, 74, 76, 84, 88], \"n\": 15, \"m\": 28}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 1, 1, 1, 1], \"n\": 5, \"m\": 5}}, {\"idx\": 3, \"outputs\": 57, \"inputs\": {\"arr\": [3, 4, 5, 5, 12, 16, 16, 16, 18, 29, 37, 38, 40, 43, 44, 49, 57, 60, 62, 63, 67, 69, 73, 74, 75, 76, 78, 84, 85, 86, 88, 89, 92], \"n\": 25, \"m\": 18}}, {\"idx\": 4, \"outputs\": 60, \"inputs\": {\"arr\": [-98, -80, -50, -44, -42, -36, -36, -28, -10, -8, -4, -2, 2, 10, 18, 18, 26, 32, 36, 56, 80, 86, 88, 90], \"n\": 16, \"m\": 12}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13, \"m\": 14}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [13, 15, 62, 65, 87], \"n\": 3, \"m\": 4}}, {\"idx\": 7, \"outputs\": 90, \"inputs\": {\"arr\": [-92, -88, -88, -80, -76, -62, -60, -60, -50, -48, -36, -36, -32, -26, -14, -8, 4, 18, 18, 22, 28, 30, 30, 32, 48, 48, 58, 60, 64, 72, 78, 82, 94], \"n\": 31, \"m\": 17}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 9, \"m\": 6}}, {\"idx\": 9, \"outputs\": 35, \"inputs\": {\"arr\": [17, 23, 25, 38, 40, 53, 58, 73, 77], \"n\": 8, \"m\": 6}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
54 | Circle Lattice Points | C++ | int circleLatticePoints(int r) { | [
"r"
] | def circle_lattice_points(r):
if (r <= 0):
return 0
result = 4
for x in range(1, r):
ySquare = ((r * r) - (x * x))
y = int(math.sqrt(ySquare))
if ((y * y) == ySquare):
result += 4
return result | int circle_lattice_points(int r) {
if ( r <= 0 ) return 0;
int result = 4;
for ( int x = 1;
x < r;
x ++ ) {
int ySquare = r * r - x * x;
int y = sqrt ( ySquare );
if ( y * y == ySquare ) result += 4;
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int r, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(r), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(34, 12); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 12); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 20); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "circleLatticePoints",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 12, \"inputs\": {\"r\": 34}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"r\": 56}}, {\"idx\": 2, \"outputs\": 12, \"inputs\": {\"r\": 90}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"r\": 47}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"r\": 36}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"r\": 63}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"r\": 21}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"r\": 76}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"r\": 18}}, {\"idx\": 9, \"outputs\": 20, \"inputs\": {\"r\": 75}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
55 | Coin Game Winner Every Player Three Choices | C++ | bool coinGameWinnerEveryPlayerThreeChoices(int x, int y, int n) { | [
"x",
"y",
"n"
] | def coin_game_winner_every_player_three_choices(x, y, n):
dp = [0 for i in range((n + 1))]
dp[0] = False
dp[1] = True
for i in range(2, (n + 1)):
if (((i - 1) >= 0) and (not dp[(i - 1)])):
dp[i] = True
elif (((i - x) >= 0) and (not dp[(i - x)])):
dp[i] = True
elif (((i - y) >= 0) and (not dp[(i - y)])):
dp[i] = True
else:
dp[i] = False
return dp[n] | bool coin_game_winner_every_player_three_choices(int x, int y, int n) {
int dp [ n + 1 ];
dp [ 0 ] = false;
dp [ 1 ] = true;
for ( int i = 2;
i <= n;
i ++ ) {
if ( i - 1 >= 0 and ! dp [ i - 1 ] ) dp [ i ] = true;
else if ( i - x >= 0 and ! dp [ i - x ] ) dp [ i ] = true;
else if ( i - y >= 0 and ! dp [ i - y ] ) dp [ i ] = true;
else dp [ i ] = false;
}
return dp [ n ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int x, int y, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(6, 27, 51, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 88, 69, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 18, 48, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 1, 74, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 78, 95, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 51, 27, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 57, 91, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 8, 9, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 82, 41, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 56, 7, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "coinGameWinnerEveryPlayerThreeChoices",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"x\": 6, \"y\": 27, \"n\": 51}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"x\": 32, \"y\": 88, \"n\": 69}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"x\": 99, \"y\": 18, \"n\": 48}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"x\": 22, \"y\": 1, \"n\": 74}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"x\": 26, \"y\": 78, \"n\": 95}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"x\": 67, \"y\": 51, \"n\": 27}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"x\": 69, \"y\": 57, \"n\": 91}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"x\": 39, \"y\": 8, \"n\": 9}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"x\": 7, \"y\": 82, \"n\": 41}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"x\": 91, \"y\": 56, \"n\": 7}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
56 | Composite Number | C++ | bool compositeNumber(int n) { | [
"n"
] | def composite_number(n):
if (n <= 1):
return False
if (n <= 3):
return False
if (((n % 2) == 0) or ((n % 3) == 0)):
return True
i = 5
while ((i * i) <= n):
if (((n % i) == 0) or ((n % (i + 2)) == 0)):
return True
i = (i + 6)
return False | bool composite_number(int n) {
if ( n <= 1 ) return false;
if ( n <= 3 ) return false;
if ( n % 2 == 0 || n % 3 == 0 ) return true;
for ( int i = 5;
i * i <= n;
i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true;
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(62, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "compositeNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 62}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"n\": 13}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"n\": 29}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"n\": 72}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"n\": 30}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"n\": 20}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"n\": 10}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 47}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"n\": 91}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"n\": 52}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
57 | Compute Average Two Numbers Without Overflow | C++ | int computeAverageTwoNumbersWithoutOverflow(int a, int b) { | [
"a",
"b"
] | def compute_average_two_numbers_without_overflow(a, b):
return floor(((a + b) / 2)) | int compute_average_two_numbers_without_overflow(int a, int b) {
return ( a + b ) / 2;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1, 44, 22); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 61, 33); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 20, 47); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 17, 34); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 25, 22); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 98, 90); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 21, 46); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 41, 44); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 17, 14); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 80, 60); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "computeAverageTwoNumbersWithoutOverflow",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 22, \"inputs\": {\"a\": 1, \"b\": 44}}, {\"idx\": 1, \"outputs\": 33, \"inputs\": {\"a\": 6, \"b\": 61}}, {\"idx\": 2, \"outputs\": 47, \"inputs\": {\"a\": 75, \"b\": 20}}, {\"idx\": 3, \"outputs\": 34, \"inputs\": {\"a\": 51, \"b\": 17}}, {\"idx\": 4, \"outputs\": 22, \"inputs\": {\"a\": 19, \"b\": 25}}, {\"idx\": 5, \"outputs\": 90, \"inputs\": {\"a\": 82, \"b\": 98}}, {\"idx\": 6, \"outputs\": 46, \"inputs\": {\"a\": 72, \"b\": 21}}, {\"idx\": 7, \"outputs\": 44, \"inputs\": {\"a\": 48, \"b\": 41}}, {\"idx\": 8, \"outputs\": 14, \"inputs\": {\"a\": 12, \"b\": 17}}, {\"idx\": 9, \"outputs\": 60, \"inputs\": {\"a\": 41, \"b\": 80}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
58 | Compute Average Two Numbers Without Overflow 1 | C++ | int computeAverageTwoNumbersWithoutOverflow1(int a, int b) { | [
"a",
"b"
] | def compute_average_two_numbers_without_overflow_1(a, b):
return (((a // 2) + (b // 2)) + (((a % 2) + (b % 2)) // 2)) | int compute_average_two_numbers_without_overflow_1(int a, int b) {
return ( a / 2 ) + ( b / 2 ) + ( ( a % 2 + b % 2 ) / 2 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(9, 81, 45); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 79, 73); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 2, 26); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 49, 40); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 10, 12); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 9, 41); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 13, 32); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 67, 71); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 51, 74); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 74, 78); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "computeAverageTwoNumbersWithoutOverflow1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 45, \"inputs\": {\"a\": 9, \"b\": 81}}, {\"idx\": 1, \"outputs\": 73, \"inputs\": {\"a\": 68, \"b\": 79}}, {\"idx\": 2, \"outputs\": 26, \"inputs\": {\"a\": 51, \"b\": 2}}, {\"idx\": 3, \"outputs\": 40, \"inputs\": {\"a\": 31, \"b\": 49}}, {\"idx\": 4, \"outputs\": 12, \"inputs\": {\"a\": 14, \"b\": 10}}, {\"idx\": 5, \"outputs\": 41, \"inputs\": {\"a\": 73, \"b\": 9}}, {\"idx\": 6, \"outputs\": 32, \"inputs\": {\"a\": 51, \"b\": 13}}, {\"idx\": 7, \"outputs\": 71, \"inputs\": {\"a\": 75, \"b\": 67}}, {\"idx\": 8, \"outputs\": 74, \"inputs\": {\"a\": 98, \"b\": 51}}, {\"idx\": 9, \"outputs\": 78, \"inputs\": {\"a\": 83, \"b\": 74}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
59 | Compute Modulus Division By A Power Of 2 Number | C++ | int computeModulusDivisionByAPowerOf2Number(int n, int d) { | [
"n",
"d"
] | def compute_modulus_division_by_a_power_of_2_number(n, d):
return (n & (d - 1)) | unsigned int compute_modulus_division_by_a_power_of_2_number(unsigned int n, unsigned int d) {
return ( n & ( d - 1 ) );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int d, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, d), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(54, 59, 50); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 84, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 81, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 60, 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 68, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 16, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 96, 93); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 38, 32); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 62, 37); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 16, 15); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "computeModulusDivisionByAPowerOf2Number",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 50, \"inputs\": {\"n\": 54, \"d\": 59}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"n\": 39, \"d\": 84}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 35, \"d\": 81}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"n\": 9, \"d\": 60}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"n\": 62, \"d\": 68}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 16, \"d\": 16}}, {\"idx\": 6, \"outputs\": 93, \"inputs\": {\"n\": 93, \"d\": 96}}, {\"idx\": 7, \"outputs\": 32, \"inputs\": {\"n\": 32, \"d\": 38}}, {\"idx\": 8, \"outputs\": 37, \"inputs\": {\"n\": 39, \"d\": 62}}, {\"idx\": 9, \"outputs\": 15, \"inputs\": {\"n\": 63, \"d\": 16}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
60 | Compute Ncr P Set 1 Introduction And Dynamic Programming Solution | C++ | int computeNcrPSet1IntroductionAndDynamicProgrammingSolution(int n, int r, int p) { | [
"n",
"r",
"p"
] | def compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(n, r, p):
C = [0 for i in range((r + 1))]
C[0] = 1
for i in range(1, (n + 1)):
for j in range(min(i, r), 0, (- 1)):
C[j] = ((C[j] + C[(j - 1)]) % p)
return C[r] | int compute_ncr_p_set_1_introduction_and_dynamic_programming_solution(int n, int r, int p) {
int C [ r + 1 ];
memset ( C, 0, sizeof ( C ) );
C [ 0 ] = 1;
for ( int i = 1;
i <= n;
i ++ ) {
for ( int j = min ( i, r );
j > 0;
j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p;
}
return C [ r ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int r, int p, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, r, p), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(82, 5, 94, 50); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 24, 95, 80); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 68, 61, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 24, 43, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 75, 57, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 55, 43, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 54, 88, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 75, 65, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 73, 86, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 26, 45, 12); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "computeNcrPSet1IntroductionAndDynamicProgrammingSolution",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 50, \"inputs\": {\"n\": 82, \"r\": 5, \"p\": 94}}, {\"idx\": 1, \"outputs\": 80, \"inputs\": {\"n\": 45, \"r\": 24, \"p\": 95}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 44, \"r\": 68, \"p\": 61}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 88, \"r\": 24, \"p\": 43}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 90, \"r\": 75, \"p\": 57}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": 98, \"r\": 55, \"p\": 43}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 80, \"r\": 54, \"p\": 88}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": 60, \"r\": 75, \"p\": 65}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": 52, \"r\": 73, \"p\": 86}}, {\"idx\": 9, \"outputs\": 12, \"inputs\": {\"n\": 71, \"r\": 26, \"p\": 45}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
61 | Compute N Under Modulo P | C++ | int computeNUnderModuloP(int n, int p) { | [
"n",
"p"
] | def compute_n_under_modulo_p(n, p):
if (n >= p):
return 0
result = 1
for i in range(1, (n + 1)):
result = ((result * i) % p)
return result | int compute_n_under_modulo_p(int n, int p) {
if ( n >= p ) return 0;
int result = 1;
for ( int i = 1;
i <= n;
i ++ ) result = ( result * i ) % p;
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int p, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, p), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(85, 18, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 13, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 21, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 35, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 51, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 58, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 71, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 74, 44); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 3, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 73, 67); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "computeNUnderModuloP",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": 85, \"p\": 18}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"n\": 14, \"p\": 13}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 83, \"p\": 21}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 30, \"p\": 35}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 96, \"p\": 51}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 55, \"p\": 58}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 82, \"p\": 71}}, {\"idx\": 7, \"outputs\": 44, \"inputs\": {\"n\": 12, \"p\": 74}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": 38, \"p\": 3}}, {\"idx\": 9, \"outputs\": 67, \"inputs\": {\"n\": 46, \"p\": 73}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
62 | Converting One String Using Append Delete Last Operations | C++ | bool convertingOneStringUsingAppendDeleteLastOperations(string str1, string str2, int k) { | [
"str1",
"str2",
"k"
] | def converting_one_string_using_append_delete_last_operations(str1, str2, k):
if ((len(str1) + len(str2)) < k):
return True
commonLength = 0
for i in range(0, min(len(str1), len(str2)), 1):
if (str1[i] == str2[i]):
commonLength += 1
else:
break
if (((((k - len(str1)) - len(str2)) + (2 * commonLength)) % 2) == 0):
return True
return False | bool converting_one_string_using_append_delete_last_operations(string str1, string str2, int k) {
if ( ( str1 . length ( ) + str2 . length ( ) ) < k ) return true;
int commonLength = 0;
for ( int i = 0;
i < min ( str1 . length ( ), str2 . length ( ) );
i ++ ) {
if ( str1 [ i ] == str2 [ i ] ) commonLength ++;
else break;
}
if ( ( k - str1 . length ( ) - str2 . length ( ) + 2 * commonLength ) % 2 == 0 ) return true;
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string str1, string str2, int k, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str1, str2, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"ZNHGro\", \"jAdbtDUYQu\", 3, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"382880806774\", \"65565\", 10, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0\", \"00100010100\", 2, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"lxHTRFCTSQ\", \"sViXYE\", 89, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"6399914758\", \"780990121\", 9, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01100011100000\", \"0100\", 0, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"WkGqlob\", \"NpQVdXzEtUZy\", 6, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"46974006151\", \"74438\", 11, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1001001\", \"1000010\", 15, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"IJQ\", \"nFOHAeYEAp\", 42, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "convertingOneStringUsingAppendDeleteLastOperations",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"str1\": \"ZNHGro\", \"str2\": \"jAdbtDUYQu\", \"k\": 3}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"str1\": \"382880806774\", \"str2\": \"65565\", \"k\": 10}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"str1\": \"0\", \"str2\": \"00100010100\", \"k\": 2}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"str1\": \"lxHTRFCTSQ\", \"str2\": \"sViXYE\", \"k\": 89}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"str1\": \"6399914758\", \"str2\": \"780990121\", \"k\": 9}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"str1\": \"01100011100000\", \"str2\": \"0100\", \"k\": 0}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"str1\": \"WkGqlob\", \"str2\": \"NpQVdXzEtUZy\", \"k\": 6}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"str1\": \"46974006151\", \"str2\": \"74438\", \"k\": 11}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"str1\": \"1001001\", \"str2\": \"1000010\", \"k\": 15}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"str1\": \"IJQ\", \"str2\": \"nFOHAeYEAp\", \"k\": 42}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
63 | Convert Strictly Increasing Array Minimum Changes | C++ | int convertStrictlyIncreasingArrayMinimumChanges(vector<int> arr, int n) { | [
"arr",
"n"
] | def convert_strictly_increasing_array_minimum_changes(arr, n):
LIS = [0 for i in range(n)]
len = 0
for i in range(n):
LIS[i] = 1
for i in range(1, n):
for j in range(i):
if ((arr[i] > arr[j]) and ((i - j) <= (arr[i] - arr[j]))):
LIS[i] = max(LIS[i], (LIS[j] + 1))
len = max(len, LIS[i])
return (n - len) | int convert_strictly_increasing_array_minimum_changes(vector<int> arr, int n) {
int LIS [ n ], len = 0;
for ( int i = 0;
i < n;
i ++ ) LIS [ i ] = 1;
for ( int i = 1;
i < n;
i ++ ) {
for ( int j = 0;
j < i;
j ++ ) {
if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {
LIS [ i ] = max ( LIS [ i ], LIS [ j ] + 1 );
}
}
len = max ( len, LIS [ i ] );
}
return n - len;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 4, 12, 14, 15, 18, 20, 24, 25, 25, 27, 33, 34, 42, 46, 48, 49, 50, 50, 52, 55, 56, 57, 58, 64, 65, 66, 69, 72, 75, 78, 80, 84, 90, 92, 95, 99}, 21, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, 6, -74, -30, 34, 40, -76, -10, -12, -86, -76, 36, -72, 82, 38, 68, 28, 84, 98, -84, 6, 16, -46, 8, 2, -18, -50, 4, -96, 88, -84, -38, -82, -54}, 22, 15); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 6, 5); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, 79, 87, 44, 3, 99, 80, 6, 46, 67, 72, 40, 11, 18, 73, 48, 18, 72, 10, 38, 3, 39, 26, 76, 47, 15, 85, 69}, 15, 10); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -94, -74, -68, -60, -58, -56, -56, -52, -52, -50, -44, -40, -26, -24, -10, -8, -6, -2, 2, 2, 12, 14, 20, 24, 26, 30, 38, 40, 52, 52, 62, 62, 68, 70, 74, 76, 80, 82, 90, 92}, 31, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 1}, 3, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 5, 11, 20, 24, 28, 29, 31, 54, 58, 63, 65, 66, 71, 77, 80, 83, 92, 93, 93}, 12, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-50, -46, -44, -90, 2, -38, 88, -26, 60}, 7, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1}, 1, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 1, 19, 26, 65, 47, 3, 65, 9, 12, 84, 59, 74, 59, 30, 83, 73, 67, 13, 5, 64, 83, 81, 92, 80, 14, 58, 84, 92}, 16, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "convertStrictlyIncreasingArrayMinimumChanges",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [1, 4, 12, 14, 15, 18, 20, 24, 25, 25, 27, 33, 34, 42, 46, 48, 49, 50, 50, 52, 55, 56, 57, 58, 64, 65, 66, 69, 72, 75, 78, 80, 84, 90, 92, 95, 99], \"n\": 21}}, {\"idx\": 1, \"outputs\": 15, \"inputs\": {\"arr\": [-56, 6, -74, -30, 34, 40, -76, -10, -12, -86, -76, 36, -72, 82, 38, 68, 28, 84, 98, -84, 6, 16, -46, 8, 2, -18, -50, 4, -96, 88, -84, -38, -82, -54], \"n\": 22}}, {\"idx\": 2, \"outputs\": 5, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 6}}, {\"idx\": 3, \"outputs\": 10, \"inputs\": {\"arr\": [68, 79, 87, 44, 3, 99, 80, 6, 46, 67, 72, 40, 11, 18, 73, 48, 18, 72, 10, 38, 3, 39, 26, 76, 47, 15, 85, 69], \"n\": 15}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"arr\": [-96, -94, -94, -74, -68, -60, -58, -56, -56, -52, -52, -50, -44, -40, -26, -24, -10, -8, -6, -2, 2, 2, 12, 14, 20, 24, 26, 30, 38, 40, 52, 52, 62, 62, 68, 70, 74, 76, 80, 82, 90, 92], \"n\": 31}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr\": [1, 1, 1, 0, 1], \"n\": 3}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [1, 5, 11, 20, 24, 28, 29, 31, 54, 58, 63, 65, 66, 71, 77, 80, 83, 92, 93, 93], \"n\": 12}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"arr\": [-50, -46, -44, -90, 2, -38, 88, -26, 60], \"n\": 7}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1], \"n\": 1}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"arr\": [2, 1, 19, 26, 65, 47, 3, 65, 9, 12, 84, 59, 74, 59, 30, 83, 73, 67, 13, 5, 64, 83, 81, 92, 80, 14, 58, 84, 92], \"n\": 16}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
65 | Count Characters Position English Alphabets | C++ | int countCharactersPositionEnglishAlphabets(string str) { | [
"str"
] | def count_characters_position_english_alphabets(str):
result = 0
for i in range(len(str)):
if ((i == (ord(str[i]) - ord('a'))) or (i == (ord(str[i]) - ord('A')))):
result += 1
return result | int count_characters_position_english_alphabets(string str) {
int result = 0;
for ( int i = 0;
i < str . size ( );
i ++ ) if ( i == ( str [ i ] - 'a' ) || i == ( str [ i ] - 'A' ) ) result ++;
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string str, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"lLkhFeZGcb\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ABcED\", 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"geeksforgeeks\", 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Alphabetical\", 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abababab\", 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"bcdefgxyz\", 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"cBzaqx L\", 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\" bcd\", 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"MqqKY\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countCharactersPositionEnglishAlphabets",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"str\": \"lLkhFeZGcb\"}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"str\": \"ABcED\"}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"str\": \"geeksforgeeks\"}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"str\": \"Alphabetical\"}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"str\": \"abababab\"}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"str\": \"bcdefgxyz\"}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"str\": \"cBzaqx L\"}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"str\": \" bcd\"}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"str\": \"11\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"str\": \"MqqKY\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
66 | Count Characters String Distance English Alphabets | C++ | int countCharactersStringDistanceEnglishAlphabets(string str1) { | [
"str1"
] | def count_characters_string_distance_english_alphabets(str1):
result = 0
n = len(str1)
for i in range(0, n):
for j in range((i + 1), n):
if (abs((ord(str1[i]) - ord(str1[j]))) == abs((i - j))):
result += 1
return result | int count_characters_string_distance_english_alphabets(string str) {
int result = 0;
int n = str . length ( );
for ( int i = 0;
i < n;
i ++ ) for ( int j = i + 1;
j < n;
j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++;
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string str1, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str1), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"smnKL\", 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"270083\", 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0\", 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kcZdsz\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"483544224\", 7); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000011\", 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"WysGCirMwKBzP\", 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"3366\", 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"110\", 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"NlaMkpCjUgg\", 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countCharactersStringDistanceEnglishAlphabets",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"str1\": \"smnKL\"}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"str1\": \"270083\"}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"str1\": \"0\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"str1\": \"kcZdsz\"}}, {\"idx\": 4, \"outputs\": 7, \"inputs\": {\"str1\": \"483544224\"}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"str1\": \"000011\"}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"str1\": \"WysGCirMwKBzP\"}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"str1\": \"3366\"}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"str1\": \"110\"}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"str1\": \"NlaMkpCjUgg\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
68 | Count Digits Factorial Set 1 | C++ | int countDigitsFactorialSet1(int n) { | [
"n"
] | def count_digits_factorial_set_1(n):
if (n < 0):
return 0
if (n <= 1):
return 1
digits = 0
for i in range(2, (n + 1)):
digits += math.log10(i)
return (math.floor(digits) + 1) | int count_digits_factorial_set_1(int n) {
if ( n < 0 ) return 0;
if ( n <= 1 ) return 1;
double digits = 0;
for ( int i = 2;
i <= n;
i ++ ) digits += log10 ( i );
return floor ( digits ) + 1;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(66, 93); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 74); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 44); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 112); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 14); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 15); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 149); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 102); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 139); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countDigitsFactorialSet1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 93, \"inputs\": {\"n\": 66}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"n\": 7}}, {\"idx\": 2, \"outputs\": 74, \"inputs\": {\"n\": 55}}, {\"idx\": 3, \"outputs\": 44, \"inputs\": {\"n\": 37}}, {\"idx\": 4, \"outputs\": 112, \"inputs\": {\"n\": 76}}, {\"idx\": 5, \"outputs\": 14, \"inputs\": {\"n\": 16}}, {\"idx\": 6, \"outputs\": 15, \"inputs\": {\"n\": 17}}, {\"idx\": 7, \"outputs\": 149, \"inputs\": {\"n\": 95}}, {\"idx\": 8, \"outputs\": 102, \"inputs\": {\"n\": 71}}, {\"idx\": 9, \"outputs\": 139, \"inputs\": {\"n\": 90}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
69 | Count Digits Factorial Set 2 | C++ | int countDigitsFactorialSet2(int n) { | [
"n"
] | def count_digits_factorial_set_2(n):
if (n < 0):
return 0
if (n <= 1):
return 1
x = ((n * math.log10((n / math.e))) + (math.log10(((2 * math.pi) * n)) / 2.0))
return (math.floor(x) + 1) | long long count_digits_factorial_set_2(int n) {
if ( n < 0 ) return 0;
if ( n <= 1 ) return 1;
double x = ( ( n * log10 ( n / M_E ) + log10 ( 2 * M_PI * n ) / 2.0 ) );
return floor ( x ) + 1;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(56, 75); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 143); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 68); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 150); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 150); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 88); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 67); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 117); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 101); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 6); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countDigitsFactorialSet2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 75, \"inputs\": {\"n\": 56}}, {\"idx\": 1, \"outputs\": 143, \"inputs\": {\"n\": 92}}, {\"idx\": 2, \"outputs\": 68, \"inputs\": {\"n\": 52}}, {\"idx\": 3, \"outputs\": 150, \"inputs\": {\"n\": 96}}, {\"idx\": 4, \"outputs\": 150, \"inputs\": {\"n\": 96}}, {\"idx\": 5, \"outputs\": 88, \"inputs\": {\"n\": 63}}, {\"idx\": 6, \"outputs\": 67, \"inputs\": {\"n\": 51}}, {\"idx\": 7, \"outputs\": 117, \"inputs\": {\"n\": 79}}, {\"idx\": 8, \"outputs\": 101, \"inputs\": {\"n\": 70}}, {\"idx\": 9, \"outputs\": 6, \"inputs\": {\"n\": 9}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
70 | Count Distinct Non Negative Pairs X Y Satisfy Inequality Xx Yy N 2 | C++ | int countDistinctNonNegativePairsXYSatisfyInequalityXxYyN2(int n) { | [
"n"
] | def count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2(n):
res = 0
x = 0
while ((x * x) < n):
y = 0
while (((x * x) + (y * y)) < n):
res = (res + 1)
y = (y + 1)
x = (x + 1)
return res | int count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2(int n) {
int res = 0;
for ( int x = 0;
x * x < n;
x ++ ) for ( int y = 0;
x * x + y * y < n;
y ++ ) res ++;
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(61, 54); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 41); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 50); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 73); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 79); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 35); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 43); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 71); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 45); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countDistinctNonNegativePairsXYSatisfyInequalityXxYyN2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 54, \"inputs\": {\"n\": 61}}, {\"idx\": 1, \"outputs\": 41, \"inputs\": {\"n\": 45}}, {\"idx\": 2, \"outputs\": 50, \"inputs\": {\"n\": 53}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"n\": 4}}, {\"idx\": 4, \"outputs\": 73, \"inputs\": {\"n\": 82}}, {\"idx\": 5, \"outputs\": 79, \"inputs\": {\"n\": 86}}, {\"idx\": 6, \"outputs\": 35, \"inputs\": {\"n\": 37}}, {\"idx\": 7, \"outputs\": 43, \"inputs\": {\"n\": 48}}, {\"idx\": 8, \"outputs\": 71, \"inputs\": {\"n\": 81}}, {\"idx\": 9, \"outputs\": 45, \"inputs\": {\"n\": 50}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
71 | Count Distinct Non Negative Pairs X Y Satisfy Inequality Xx Yy N 2 1 | C++ | int countDistinctNonNegativePairsXYSatisfyInequalityXxYyN21(int n) { | [
"n"
] | def count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2_1(n):
x = 0
res = 0
yCount = 0
while ((yCount * yCount) < n):
yCount = (yCount + 1)
while (yCount != 0):
res = (res + yCount)
x = (x + 1)
while ((yCount != 0) and (((x * x) + ((yCount - 1) * (yCount - 1))) >= n)):
yCount = (yCount - 1)
return res | int count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2_1(int n) {
int x = 0, yCount, res = 0;
for ( yCount = 0;
yCount * yCount < n;
yCount ++ );
while ( yCount != 0 ) {
res += yCount;
x ++;
while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount --;
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(72, 64); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 69); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 83); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 30); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 41); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 37); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 71); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 17); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 71); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 86); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countDistinctNonNegativePairsXYSatisfyInequalityXxYyN21",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 64, \"inputs\": {\"n\": 72}}, {\"idx\": 1, \"outputs\": 69, \"inputs\": {\"n\": 75}}, {\"idx\": 2, \"outputs\": 83, \"inputs\": {\"n\": 92}}, {\"idx\": 3, \"outputs\": 30, \"inputs\": {\"n\": 30}}, {\"idx\": 4, \"outputs\": 41, \"inputs\": {\"n\": 45}}, {\"idx\": 5, \"outputs\": 37, \"inputs\": {\"n\": 40}}, {\"idx\": 6, \"outputs\": 71, \"inputs\": {\"n\": 81}}, {\"idx\": 7, \"outputs\": 17, \"inputs\": {\"n\": 17}}, {\"idx\": 8, \"outputs\": 71, \"inputs\": {\"n\": 81}}, {\"idx\": 9, \"outputs\": 86, \"inputs\": {\"n\": 99}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
72 | Count Distinct Occurrences As A Subsequence | C++ | int countDistinctOccurrencesAsASubsequence(string s, string t) { | [
"s",
"t"
] | def count_distinct_occurrences_as_a_subsequence(S, T):
m = len(T)
n = len(S)
if (m > n):
return 0
mat = [[0 for _ in range((n + 1))] for __ in range((m + 1))]
for i in range(1, (m + 1)):
mat[i][0] = 0
for j in range((n + 1)):
mat[0][j] = 1
for i in range(1, (m + 1)):
for j in range(1, (n + 1)):
if (T[(i - 1)] != S[(j - 1)]):
mat[i][j] = mat[i][(j - 1)]
else:
mat[i][j] = (mat[i][(j - 1)] + mat[(i - 1)][(j - 1)])
return mat[m][n] | int count_distinct_occurrences_as_a_subsequence(string S, string T) {
int m = T . length ( ), n = S . length ( );
if ( m > n ) return 0;
int mat [ m + 1 ] [ n + 1 ];
for ( int i = 1;
i <= m;
i ++ ) mat [ i ] [ 0 ] = 0;
for ( int j = 0;
j <= n;
j ++ ) mat [ 0 ] [ j ] = 1;
for ( int i = 1;
i <= m;
i ++ ) {
for ( int j = 1;
j <= n;
j ++ ) {
if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ];
else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ];
}
}
return mat [ m ] [ n ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string s, string t, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s, t), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"banana\", \"ban\", 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"49597223\", \"42\", 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1000010000011\", \"010\", 20); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"BTlzufK\", \"EpsVuzP lf\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"3474007\", \"370\", 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0010\", \"00000\", 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"dKHhoTD\", \"doT\", 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"9123259723\", \"123\", 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11001000111110\", \"0\", 6); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"iY WJlIZ\", \"iI\", 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countDistinctOccurrencesAsASubsequence",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"s\": \"banana\", \"t\": \"ban\"}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"s\": \"49597223\", \"t\": \"42\"}}, {\"idx\": 2, \"outputs\": 20, \"inputs\": {\"s\": \"1000010000011\", \"t\": \"010\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"s\": \"BTlzufK\", \"t\": \"EpsVuzP lf\"}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"s\": \"3474007\", \"t\": \"370\"}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"s\": \"0010\", \"t\": \"00000\"}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"s\": \"dKHhoTD\", \"t\": \"doT\"}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"s\": \"9123259723\", \"t\": \"123\"}}, {\"idx\": 8, \"outputs\": 6, \"inputs\": {\"s\": \"11001000111110\", \"t\": \"0\"}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"s\": \"iY WJlIZ\", \"t\": \"iI\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
73 | Count Even Length Binary Sequences With Same Sum Of First And Second Half Bits 1 | C++ | double countEvenLengthBinarySequencesWithSameSumOfFirstAndSecondHalfBits1(int n) { | [
"n"
] | def count_even_length_binary_sequences_with_same_sum_of_first_and_second_half_bits_1(n):
nCr = 1
res = 1
for r in range(1, (n + 1)):
nCr = ((nCr * ((n + 1) - r)) / r)
res += (nCr * nCr)
return res | int count_even_length_binary_sequences_with_same_sum_of_first_and_second_half_bits_1(int n) {
int nCr = 1, res = 1;
for ( int r = 1;
r <= n;
r ++ ) {
nCr = ( nCr * ( n + 1 - r ) ) / r;
res += nCr * nCr;
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int n, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(25, 126410606437752.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 9075135300.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 2333606220.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 12870.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 12870.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countEvenLengthBinarySequencesWithSameSumOfFirstAndSecondHalfBits1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 126410606437752.0, \"inputs\": {\"n\": 25}}, {\"idx\": 1, \"outputs\": 9075135300.0, \"inputs\": {\"n\": 18}}, {\"idx\": 2, \"outputs\": 2333606220.0, \"inputs\": {\"n\": 17}}, {\"idx\": 3, \"outputs\": 12870.0, \"inputs\": {\"n\": 8}}, {\"idx\": 4, \"outputs\": 12870.0, \"inputs\": {\"n\": 8}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
74 | Count Factorial Numbers In A Given Range | C++ | int countFactorialNumbersInAGivenRange(int low, int high) { | [
"low",
"high"
] | def count_factorial_numbers_in_a_given_range(low, high):
fact = 1
x = 1
while (fact < low):
fact = (fact * x)
x += 1
res = 0
while (fact <= high):
res += 1
fact = (fact * x)
x += 1
return res | int count_factorial_numbers_in_a_given_range(int low, int high) {
int fact = 1, x = 1;
while ( fact < low ) {
fact = fact * x;
x ++;
}
int res = 0;
while ( fact <= high ) {
res ++;
fact = fact * x;
x ++;
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int low, int high, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(low, high), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(57, 79, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 21, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 37, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 87, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 98, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 76, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 45, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 52, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 43, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 6, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countFactorialNumbersInAGivenRange",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"low\": 57, \"high\": 79}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"low\": 57, \"high\": 21}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"low\": 31, \"high\": 37}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"low\": 62, \"high\": 87}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"low\": 49, \"high\": 98}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"low\": 82, \"high\": 76}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"low\": 31, \"high\": 45}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"low\": 5, \"high\": 52}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"low\": 76, \"high\": 43}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"low\": 55, \"high\": 6}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
75 | Count Fibonacci Numbers Given Range Log Time | C++ | int countFibonacciNumbersGivenRangeLogTime(int low, int high) { | [
"low",
"high"
] | def count_fibonacci_numbers_given_range_log_time(low, high):
(f1, f2, f3) = (0, 1, 1)
result = 0
while (f1 <= high):
if (f1 >= low):
result += 1
f1 = f2
f2 = f3
f3 = (f1 + f2)
return result | int count_fibonacci_numbers_given_range_log_time(int low, int high) {
int f1 = 0, f2 = 1, f3 = 1;
int result = 0;
while ( f1 <= high ) {
if ( f1 >= low ) result ++;
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int low, int high, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(low, high), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(76, 43, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 52, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 79, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 2, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 11, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 15, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 4, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 93, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 25, 6); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 39, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countFibonacciNumbersGivenRangeLogTime",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"low\": 76, \"high\": 43}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"low\": 96, \"high\": 52}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"low\": 19, \"high\": 79}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"low\": 36, \"high\": 2}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"low\": 60, \"high\": 11}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"low\": 20, \"high\": 15}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"low\": 76, \"high\": 4}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"low\": 63, \"high\": 93}}, {\"idx\": 8, \"outputs\": 6, \"inputs\": {\"low\": 2, \"high\": 25}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"low\": 41, \"high\": 39}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
76 | Count Frequency K Matrix Size N Matrixi J Ij | C++ | int countFrequencyKMatrixSizeNMatrixiJIj(int n, int k) { | [
"n",
"k"
] | def count_frequency_k_matrix_size_n_matrixi_j_ij(n, k):
if ((n + 1) >= k):
return (k - 1)
else:
return (((2 * n) + 1) - k) | int count_frequency_k_matrix_size_n_matrixi_j_ij(int n, int k) {
if ( n + 1 >= k ) return ( k - 1 );
else return ( 2 * n + 1 - k );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(90, 74, 73); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 36, 35); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 38, 37); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 71, 70); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 57, -6); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 53, -30); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 80, 79); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 75, 74); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 58, 57); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 88, -19); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countFrequencyKMatrixSizeNMatrixiJIj",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 73, \"inputs\": {\"n\": 90, \"k\": 74}}, {\"idx\": 1, \"outputs\": 35, \"inputs\": {\"n\": 86, \"k\": 36}}, {\"idx\": 2, \"outputs\": 37, \"inputs\": {\"n\": 92, \"k\": 38}}, {\"idx\": 3, \"outputs\": 70, \"inputs\": {\"n\": 72, \"k\": 71}}, {\"idx\": 4, \"outputs\": -6, \"inputs\": {\"n\": 25, \"k\": 57}}, {\"idx\": 5, \"outputs\": -30, \"inputs\": {\"n\": 11, \"k\": 53}}, {\"idx\": 6, \"outputs\": 79, \"inputs\": {\"n\": 94, \"k\": 80}}, {\"idx\": 7, \"outputs\": 74, \"inputs\": {\"n\": 91, \"k\": 75}}, {\"idx\": 8, \"outputs\": 57, \"inputs\": {\"n\": 66, \"k\": 58}}, {\"idx\": 9, \"outputs\": -19, \"inputs\": {\"n\": 34, \"k\": 88}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
77 | Count Index Pairs Equal Elements Array | C++ | int countIndexPairsEqualElementsArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def count_index_pairs_equal_elements_array(arr, n):
ans = 0
for i in range(0, n):
for j in range((i + 1), n):
if (arr[i] == arr[j]):
ans += 1
return ans | int count_index_pairs_equal_elements_array(vector<int> arr, int n) {
int ans = 0;
for ( int i = 0;
i < n;
i ++ ) for ( int j = i + 1;
j < n;
j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++;
return ans;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 6, 9, 16, 16, 21, 36, 41, 58, 60, 62, 73, 77, 81, 95}, 12, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -72, -26, -34, 18, -62, -66}, 3, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1}, 0, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16}, 0, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -80, -72, -68, -64, -26, 4, 14, 16, 22, 30, 32, 60, 74, 82}, 11, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1}, 9, 16); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 9, 10, 12, 17, 23, 27, 29, 42, 44, 59, 61, 71, 76, 78, 82, 84, 84, 89, 90, 93, 93, 97, 97}, 15, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, -40, -46, -20, -64, 90}, 5, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 61); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 17, 94, 43, 97, 17, 11, 58, 75, 94, 37, 22, 54, 31, 41, 4, 55, 69, 92, 80, 45, 97, 16, 33, 36, 17, 43, 82, 81, 64, 22, 65, 85, 44, 47, 14}, 23, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countIndexPairsEqualElementsArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [4, 6, 9, 16, 16, 21, 36, 41, 58, 60, 62, 73, 77, 81, 95], \"n\": 12}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-86, -72, -26, -34, 18, -62, -66], \"n\": 3}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [1], \"n\": 0}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [16], \"n\": 0}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-88, -80, -72, -68, -64, -26, 4, 14, 16, 22, 30, 32, 60, 74, 82], \"n\": 11}}, {\"idx\": 5, \"outputs\": 16, \"inputs\": {\"arr\": [0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1], \"n\": 9}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [3, 9, 10, 12, 17, 23, 27, 29, 42, 44, 59, 61, 71, 76, 78, 82, 84, 84, 89, 90, 93, 93, 97, 97], \"n\": 15}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [68, -40, -46, -20, -64, 90], \"n\": 5}}, {\"idx\": 8, \"outputs\": 61, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 15}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"arr\": [99, 17, 94, 43, 97, 17, 11, 58, 75, 94, 37, 22, 54, 31, 41, 4, 55, 69, 92, 80, 45, 97, 16, 33, 36, 17, 43, 82, 81, 64, 22, 65, 85, 44, 47, 14], \"n\": 23}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
78 | Count Index Pairs Equal Elements Array 1 | C++ | int countIndexPairsEqualElementsArray1(vector<int> arr, int n) { | [
"arr",
"n"
] | def count_index_pairs_equal_elements_array_1(arr, n):
mp = dict()
for i in range(n):
if (arr[i] in mp.keys()):
mp[arr[i]] += 1
else:
mp[arr[i]] = 1
ans = 0
for it in mp:
count = mp[it]
ans += ((count * (count - 1)) // 2)
return ans | int count_index_pairs_equal_elements_array_1(vector<int> arr, int n) {
unordered_map < int, int > mp;
for ( int i = 0;
i < n;
i ++ ) mp [ arr [ i ] ] ++;
int ans = 0;
for ( auto it = mp . begin ( );
it != mp . end ( );
it ++ ) {
int count = it -> second;
ans += ( count * ( count - 1 ) ) / 2;
}
return ans;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 11, 18, 22, 40, 46, 50, 51, 53, 55, 64, 67, 73, 78, 86}, 14, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, -98, 98, 58, -82, 90, -80, -56, -30, -36, -56, -30, -58, 68, 72, -76, 38, -90, -72, 4, -32, 32, -28, 2, 12, -72, 54, 2, 0, -74, 8, 12, 46, 72, -84, -66, 70, 18, 26, 72, -26, 44, -8, 20, -32, -56, 28}, 24, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 56); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({93, 23, 62, 64, 31, 78, 99}, 4, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -94, -92, -86, -84, -76, -76, -68, -66, -56, -56, -54, -50, -46, -38, -34, -34, -30, -26, -18, -16, 2, 8, 42, 52, 54, 56, 64, 68, 82, 82, 82, 94, 96, 98}, 19, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0}, 0, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 18, 18, 20, 21, 23, 24, 27, 35, 36, 38, 40, 46, 50, 50, 51, 52, 53, 59, 61, 63, 63, 65, 66, 68, 68, 70, 71, 74, 75, 96, 98}, 19, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-68, 40, 16, 50, 36, 42, -20, -46, -92, 4, -18, -12, 48, 0, -46, 64, -74, -50, 42, 44, -56, 28, -10, 78, 62, 70, -60, 12, -44, -78}, 23, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 211); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({31, 5}, 1, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countIndexPairsEqualElementsArray1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [5, 11, 18, 22, 40, 46, 50, 51, 53, 55, 64, 67, 73, 78, 86], \"n\": 14}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"arr\": [14, -98, 98, 58, -82, 90, -80, -56, -30, -36, -56, -30, -58, 68, 72, -76, 38, -90, -72, 4, -32, 32, -28, 2, 12, -72, 54, 2, 0, -74, 8, 12, 46, 72, -84, -66, 70, 18, 26, 72, -26, 44, -8, 20, -32, -56, 28], \"n\": 24}}, {\"idx\": 2, \"outputs\": 56, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [93, 23, 62, 64, 31, 78, 99], \"n\": 4}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"arr\": [-94, -94, -92, -86, -84, -76, -76, -68, -66, -56, -56, -54, -50, -46, -38, -34, -34, -30, -26, -18, -16, 2, 8, 42, 52, 54, 56, 64, 68, 82, 82, 82, 94, 96, 98], \"n\": 19}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0], \"n\": 0}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"arr\": [3, 18, 18, 20, 21, 23, 24, 27, 35, 36, 38, 40, 46, 50, 50, 51, 52, 53, 59, 61, 63, 63, 65, 66, 68, 68, 70, 71, 74, 75, 96, 98], \"n\": 19}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"arr\": [-68, 40, 16, 50, 36, 42, -20, -46, -92, 4, -18, -12, 48, 0, -46, 64, -74, -50, 42, 44, -56, 28, -10, 78, 62, 70, -60, 12, -44, -78], \"n\": 23}}, {\"idx\": 8, \"outputs\": 211, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 30}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [31, 5], \"n\": 1}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
79 | Count Inversions Of Size Three In A Give Array 1 | C++ | int countInversionsOfSizeThreeInAGiveArray1(vector<int> arr, int n) { | [
"arr",
"n"
] | def count_inversions_of_size_three_in_a_give_array_1(arr, n):
invcount = 0
for i in range(1, (n - 1)):
small = 0
for j in range((i + 1), n):
if (arr[i] > arr[j]):
small += 1
great = 0
for j in range((i - 1), (- 1), (- 1)):
if (arr[i] < arr[j]):
great += 1
invcount += (great * small)
return invcount | int count_inversions_of_size_three_in_a_give_array_1(vector<int> arr, int n) {
int invcount = 0;
for ( int i = 1;
i < n - 1;
i ++ ) {
int small = 0;
for ( int j = i + 1;
j < n;
j ++ ) if ( arr [ i ] > arr [ j ] ) small ++;
int great = 0;
for ( int j = i - 1;
j >= 0;
j -- ) if ( arr [ i ] < arr [ j ] ) great ++;
invcount += great * small;
}
return invcount;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 75, 89}, 1, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({84, -66, -52, 34, -28, -6, 20, 22, -78, -26, 14, 24, -92, -18, 32, -94, -64, -38, 56, 4, -10, 58, -66, -58, -10, -8, -62, -60, -26}, 26, 404); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1, 1, 1}, 7, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({18, 7, 43, 57, 94, 37, 38, 41, 59, 64, 97, 29, 51, 37, 64, 91, 42, 83, 13, 22, 68}, 17, 37); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -86, -84, -84, -82, -66, -62, -58, -52, -48, -44, -40, -38, -32, -22, -22, -22, -14, -8, -6, -6, 0, 2, 20, 20, 26, 32, 32, 52, 56, 66, 74, 76, 80, 80, 86, 88, 94}, 34, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0}, 9, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 8, 15, 19, 24, 31, 33, 36, 38, 45, 45, 52, 54, 65, 73, 75, 83, 84, 90, 92, 93}, 19, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, -30, -44, 76, -96, 2, 22, -30, 36, -6, 88, -60, -90, -52, 78, 90, -52}, 10, 20); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 7, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({74, 71, 28, 45, 14, 31, 17, 10, 82, 27, 45, 73, 93, 87, 57, 58}, 10, 43); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countInversionsOfSizeThreeInAGiveArray1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [4, 75, 89], \"n\": 1}}, {\"idx\": 1, \"outputs\": 404, \"inputs\": {\"arr\": [84, -66, -52, 34, -28, -6, 20, 22, -78, -26, 14, 24, -92, -18, 32, -94, -64, -38, 56, 4, -10, 58, -66, -58, -10, -8, -62, -60, -26], \"n\": 26}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 3, \"outputs\": 37, \"inputs\": {\"arr\": [18, 7, 43, 57, 94, 37, 38, 41, 59, 64, 97, 29, 51, 37, 64, 91, 42, 83, 13, 22, 68], \"n\": 17}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-94, -86, -84, -84, -82, -66, -62, -58, -52, -48, -44, -40, -38, -32, -22, -22, -22, -14, -8, -6, -6, 0, 2, 20, 20, 26, 32, 32, 52, 56, 66, 74, 76, 80, 80, 86, 88, 94], \"n\": 34}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0], \"n\": 9}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [4, 8, 15, 19, 24, 31, 33, 36, 38, 45, 45, 52, 54, 65, 73, 75, 83, 84, 90, 92, 93], \"n\": 19}}, {\"idx\": 7, \"outputs\": 20, \"inputs\": {\"arr\": [80, -30, -44, 76, -96, 2, 22, -30, 36, -6, 88, -60, -90, -52, 78, 90, -52], \"n\": 10}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 43, \"inputs\": {\"arr\": [74, 71, 28, 45, 14, 31, 17, 10, 82, 27, 45, 73, 93, 87, 57, 58], \"n\": 10}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
80 | Count Minimum Number Subsets Subsequences Consecutive Numbers | C++ | int countMinimumNumberSubsetsSubsequencesConsecutiveNumbers(vector<int> arr, int n) { | [
"arr",
"n"
] | def count_minimum_number_subsets_subsequences_consecutive_numbers(arr, n):
x = sorted(arr)
count = 1
for i in range(0, (n - 1)):
if ((x[i] + 1) != x[(i + 1)]):
count = (count + 1)
return count | int count_minimum_number_subsets_subsequences_consecutive_numbers(vector<int> arr, int n) {
sort(arr.begin(), arr.end());
int count = 1;
for ( int i = 0;
i < n - 1;
i ++ ) {
if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++;
}
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({3, 7, 7, 11, 14, 14, 14, 16, 17, 17, 21, 22, 24, 27, 27, 27, 31, 33, 35, 36, 36, 37, 38, 43, 45, 49, 52, 54, 57, 59, 59, 60, 67, 73, 74, 74, 74, 75, 75, 79, 83, 87, 90, 93, 97}, 42, 34); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-28, 72, 60, 62, 40, 64, 50, -36, -24, 40, -6, 78, -80, -82, 2, -30, 70, 94, -2, -30, 92, 12, -46, 32, -96, -2, 36, -40, -42, 66, 98}, 24, 24); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1}, 1, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 89, 24, 28, 70, 78, 78, 35, 98, 65, 18, 81, 35, 91, 33, 88, 69, 52, 66, 17, 73, 79, 30, 33, 78, 60, 42, 8, 36, 6, 47, 87, 8, 98, 9, 77, 78, 24, 86, 91, 13, 79, 50, 85, 3, 7, 61, 94, 86}, 26, 19); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -92, -90, -84, -78, -66, -60, -60, -46, -42, -38, -32, -24, -20, -18, -16, -14, -10, 0, 4, 6, 12, 24, 32, 34, 44, 48, 50, 50, 64, 66, 68, 80, 84, 86, 86, 88, 90, 90, 90, 92, 94, 96, 98, 98}, 42, 42); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0}, 27, 26); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 12, 13, 14, 16, 20, 20, 21, 23, 23, 24, 27, 29, 29, 29, 29, 35, 35, 38, 39, 40, 46, 50, 52, 60, 62, 62, 65, 65, 65, 70, 71, 72, 73, 75, 76, 80, 81, 82, 83, 85, 91, 95, 97, 98, 98}, 29, 23); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, 92, 70, -46, 26, -94, -82, -26, -90, -62, 52, 62, -58, 44, -14, -6, 58, 2, 10, 76, -34, 42, -26, 80, 26, 32, -82, 38, 2, 72, 68, 44, 24, 84, -32, 54, -96, -8, 36, 80, -82, 32, 98, -68}, 25, 25); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 20); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({64, 10, 6, 3, 67, 95, 72, 96, 72, 30, 99, 21, 46, 23, 48, 38, 48, 50, 53, 91, 59, 58, 27, 95, 63, 20, 27, 22, 58, 3, 11, 75, 77, 64, 46, 1, 67, 79, 6, 46, 57, 79, 49, 83, 21, 36, 44}, 46, 36); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countMinimumNumberSubsetsSubsequencesConsecutiveNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 34, \"inputs\": {\"arr\": [3, 7, 7, 11, 14, 14, 14, 16, 17, 17, 21, 22, 24, 27, 27, 27, 31, 33, 35, 36, 36, 37, 38, 43, 45, 49, 52, 54, 57, 59, 59, 60, 67, 73, 74, 74, 74, 75, 75, 79, 83, 87, 90, 93, 97], \"n\": 42}}, {\"idx\": 1, \"outputs\": 24, \"inputs\": {\"arr\": [-28, 72, 60, 62, 40, 64, 50, -36, -24, 40, -6, 78, -80, -82, 2, -30, 70, 94, -2, -30, 92, 12, -46, 32, -96, -2, 36, -40, -42, 66, 98], \"n\": 24}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1], \"n\": 1}}, {\"idx\": 3, \"outputs\": 19, \"inputs\": {\"arr\": [96, 89, 24, 28, 70, 78, 78, 35, 98, 65, 18, 81, 35, 91, 33, 88, 69, 52, 66, 17, 73, 79, 30, 33, 78, 60, 42, 8, 36, 6, 47, 87, 8, 98, 9, 77, 78, 24, 86, 91, 13, 79, 50, 85, 3, 7, 61, 94, 86], \"n\": 26}}, {\"idx\": 4, \"outputs\": 42, \"inputs\": {\"arr\": [-92, -92, -90, -84, -78, -66, -60, -60, -46, -42, -38, -32, -24, -20, -18, -16, -14, -10, 0, 4, 6, 12, 24, 32, 34, 44, 48, 50, 50, 64, 66, 68, 80, 84, 86, 86, 88, 90, 90, 90, 92, 94, 96, 98, 98], \"n\": 42}}, {\"idx\": 5, \"outputs\": 26, \"inputs\": {\"arr\": [0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0], \"n\": 27}}, {\"idx\": 6, \"outputs\": 23, \"inputs\": {\"arr\": [8, 12, 13, 14, 16, 20, 20, 21, 23, 23, 24, 27, 29, 29, 29, 29, 35, 35, 38, 39, 40, 46, 50, 52, 60, 62, 62, 65, 65, 65, 70, 71, 72, 73, 75, 76, 80, 81, 82, 83, 85, 91, 95, 97, 98, 98], \"n\": 29}}, {\"idx\": 7, \"outputs\": 25, \"inputs\": {\"arr\": [-84, 92, 70, -46, 26, -94, -82, -26, -90, -62, 52, 62, -58, 44, -14, -6, 58, 2, 10, 76, -34, 42, -26, 80, 26, 32, -82, 38, 2, 72, 68, 44, 24, 84, -32, 54, -96, -8, 36, 80, -82, 32, 98, -68], \"n\": 25}}, {\"idx\": 8, \"outputs\": 20, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 21}}, {\"idx\": 9, \"outputs\": 36, \"inputs\": {\"arr\": [64, 10, 6, 3, 67, 95, 72, 96, 72, 30, 99, 21, 46, 23, 48, 38, 48, 50, 53, 91, 59, 58, 27, 95, 63, 20, 27, 22, 58, 3, 11, 75, 77, 64, 46, 1, 67, 79, 6, 46, 57, 79, 49, 83, 21, 36, 44], \"n\": 46}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
81 | Count Natural Numbers Whose Permutation Greater Number | C++ | int countNaturalNumbersWhosePermutationGreaterNumber(int n) { | [
"n"
] | def count_natural_numbers_whose_permutation_greater_number(n):
result = 0
for i in range(1, 10):
s = []
if (i <= n):
s.append(i)
result += 1
while (len(s) != 0):
tp = s[(- 1)]
s.pop()
for j in range((tp % 10), 10):
x = ((tp * 10) + j)
if (x <= n):
s.append(x)
result += 1
return result | int count_natural_numbers_whose_permutation_greater_number(int n) {
int result = 0;
for ( int i = 1;
i <= 9;
i ++ ) {
stack < int > s;
if ( i <= n ) {
s . push ( i );
result ++;
}
while ( ! s . empty ( ) ) {
int tp = s . top ( );
s . pop ( );
for ( int j = tp % 10;
j <= 9;
j ++ ) {
int x = tp * 10 + j;
if ( x <= n ) {
s . push ( x );
result ++;
}
}
}
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(69, 48); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 48); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 52); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 45); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 28); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 20); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 31); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 27); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 18); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNaturalNumbersWhosePermutationGreaterNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 48, \"inputs\": {\"n\": 69}}, {\"idx\": 1, \"outputs\": 48, \"inputs\": {\"n\": 72}}, {\"idx\": 2, \"outputs\": 52, \"inputs\": {\"n\": 88}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"n\": 7}}, {\"idx\": 4, \"outputs\": 45, \"inputs\": {\"n\": 66}}, {\"idx\": 5, \"outputs\": 28, \"inputs\": {\"n\": 34}}, {\"idx\": 6, \"outputs\": 20, \"inputs\": {\"n\": 23}}, {\"idx\": 7, \"outputs\": 31, \"inputs\": {\"n\": 37}}, {\"idx\": 8, \"outputs\": 27, \"inputs\": {\"n\": 33}}, {\"idx\": 9, \"outputs\": 18, \"inputs\": {\"n\": 21}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
82 | Count Numbers Can Constructed Using Two Numbers | C++ | int countNumbersCanConstructedUsingTwoNumbers(int n, int x, int y) { | [
"n",
"x",
"y"
] | def count_numbers_can_constructed_using_two_numbers(n, x, y):
arr = [False for i in range((n + 2))]
if (x <= n):
arr[x] = True
if (y <= n):
arr[y] = True
result = 0
for i in range(min(x, y), (n + 1)):
if arr[i]:
if ((i + x) <= n):
arr[(i + x)] = True
if ((i + y) <= n):
arr[(i + y)] = True
result = (result + 1)
return result | int count_numbers_can_constructed_using_two_numbers(int n, int x, int y) {
vector < bool > arr ( n + 1, false );
if ( x <= n ) arr [ x ] = true;
if ( y <= n ) arr [ y ] = true;
int result = 0;
for ( int i = min ( x, y );
i <= n;
i ++ ) {
if ( arr [ i ] ) {
if ( i + x <= n ) arr [ i + x ] = true;
if ( i + y <= n ) arr [ i + y ] = true;
result ++;
}
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(23, 16, 16, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 95, 6, 9); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 63, 1, 30); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 89, 46, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 99, 38, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 63, 50, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 69, 73, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 52, 9, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 65, 10, 13); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 58, 37, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumbersCanConstructedUsingTwoNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"n\": 23, \"x\": 16, \"y\": 16}}, {\"idx\": 1, \"outputs\": 9, \"inputs\": {\"n\": 56, \"x\": 95, \"y\": 6}}, {\"idx\": 2, \"outputs\": 30, \"inputs\": {\"n\": 30, \"x\": 63, \"y\": 1}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"n\": 51, \"x\": 89, \"y\": 46}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 21, \"x\": 99, \"y\": 38}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": 69, \"x\": 63, \"y\": 50}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 12, \"x\": 69, \"y\": 73}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"n\": 44, \"x\": 52, \"y\": 9}}, {\"idx\": 8, \"outputs\": 13, \"inputs\": {\"n\": 99, \"x\": 65, \"y\": 10}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"n\": 46, \"x\": 58, \"y\": 37}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
83 | Count Numbers That Dont Contain 3 | C++ | double countNumbersThatDontContain3(int n) { | [
"n"
] | def count_numbers_that_dont_contain_3(n):
if (n < 3):
return n
elif ((n >= 3) and (n < 10)):
return (n - 1)
po = 1
while ((n / po) > 9):
po = (po * 10)
msd = (n / po)
if (msd != 3):
return (((count_numbers_that_dont_contain_3(msd) * count_numbers_that_dont_contain_3((po - 1))) + count_numbers_that_dont_contain_3(msd)) + count_numbers_that_dont_contain_3((n % po)))
else:
return count_numbers_that_dont_contain_3(((msd * po) - 1)) | int count_numbers_that_dont_contain_3(int n) {
if ( n < 3 ) return n;
if ( n >= 3 && n < 10 ) return n - 1;
int po = 1;
while ( n / po > 9 ) po = po * 10;
int msd = n / po;
if ( msd != 3 ) return count_numbers_that_dont_contain_3 ( msd ) * count_numbers_that_dont_contain_3 ( po - 1 ) + count_numbers_that_dont_contain_3 ( msd ) + count_numbers_that_dont_contain_3 ( n % po );
else return count_numbers_that_dont_contain_3 ( msd * po - 1 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int n, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(85, 71.5); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 73.39999999999999); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 2.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 26.5); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 52.1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 32.2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 22.7); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 17.5); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 62.5); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 60.6); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumbersThatDontContain3",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 71.5, \"inputs\": {\"n\": 85}}, {\"idx\": 1, \"outputs\": 73.39999999999999, \"inputs\": {\"n\": 86}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"n\": 3}}, {\"idx\": 3, \"outputs\": 26.5, \"inputs\": {\"n\": 35}}, {\"idx\": 4, \"outputs\": 52.1, \"inputs\": {\"n\": 59}}, {\"idx\": 5, \"outputs\": 32.2, \"inputs\": {\"n\": 38}}, {\"idx\": 6, \"outputs\": 22.7, \"inputs\": {\"n\": 33}}, {\"idx\": 7, \"outputs\": 17.5, \"inputs\": {\"n\": 15}}, {\"idx\": 8, \"outputs\": 62.5, \"inputs\": {\"n\": 75}}, {\"idx\": 9, \"outputs\": 60.6, \"inputs\": {\"n\": 74}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
84 | Count Number Binary Strings Without Consecutive 1S | C++ | long long countNumberBinaryStringsWithoutConsecutive1S(int n) { | [
"n"
] | def count_number_binary_strings_without_consecutive_1s(n):
a = [0 for i in range(n)]
b = [0 for i in range(n)]
a[0] = b[0] = 1
for i in range(1, n):
a[i] = (a[(i - 1)] + b[(i - 1)])
b[i] = a[(i - 1)]
return (a[(n - 1)] + b[(n - 1)]) | int count_number_binary_strings_without_consecutive_1s(int n) {
int a [ n ], b [ n ];
a [ 0 ] = b [ 0 ] = 1;
for ( int i = 1;
i < n;
i ++ ) {
a [ i ] = a [ i - 1 ] + b [ i - 1 ];
b [ i ] = a [ i - 1 ];
}
return a [ n - 1 ] + b [ n - 1 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(75, 5527939700884757); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 987); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 13); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 433494437); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 24157817); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 2178309); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 420196140727489673); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 139583862445); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumberBinaryStringsWithoutConsecutive1S",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 5527939700884757, \"inputs\": {\"n\": 75}}, {\"idx\": 1, \"outputs\": 987, \"inputs\": {\"n\": 14}}, {\"idx\": 2, \"outputs\": 13, \"inputs\": {\"n\": 5}}, {\"idx\": 3, \"outputs\": 433494437, \"inputs\": {\"n\": 41}}, {\"idx\": 4, \"outputs\": 24157817, \"inputs\": {\"n\": 35}}, {\"idx\": 5, \"outputs\": 2178309, \"inputs\": {\"n\": 30}}, {\"idx\": 6, \"outputs\": 420196140727489673, \"inputs\": {\"n\": 84}}, {\"idx\": 7, \"outputs\": 139583862445, \"inputs\": {\"n\": 53}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
85 | Count Number Of Occurrences Or Frequency In A Sorted Array | C++ | int countNumberOfOccurrencesOrFrequencyInASortedArray(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def count_number_of_occurrences_or_frequency_in_a_sorted_array(arr, n, x):
res = 0
for i in range(n):
if (x == arr[i]):
res += 1
return res | int count_number_of_occurrences_or_frequency_in_a_sorted_array(vector<int> arr, int n, int x) {
int res = 0;
for ( int i = 0;
i < n;
i ++ ) if ( x == arr [ i ] ) res ++;
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({16, 18, 24, 27, 34, 36, 41, 43, 43, 52, 59, 76, 86, 87, 90, 91, 94, 96, 98, 98}, 14, 43, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({64, 66, -36}, 1, 64, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0}, 2, 0, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9, 85, 34, 43, 70, 96, 44, 7, 27, 33, 34, 5, 91, 84, 76, 45, 20, 37, 15, 37, 20, 24, 13, 49, 74, 13, 50, 81, 81, 66, 23, 36, 91, 80, 61, 15, 96, 70, 90, 25, 16, 62, 75, 63, 6, 65, 38, 12}, 43, 5, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -98, -34, -32, -26, -12, 0, 18, 52, 68, 72}, 11, -98, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1}, 11, 1, 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 3, 6, 6, 10, 12, 15, 16, 21, 22, 23, 29, 33, 37, 40, 40, 43, 52, 55, 59, 64, 65, 71, 72, 80, 83, 86, 86, 88, 88}, 29, 40, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-14, -30, -38, -38, -8, 40, -34, 2, -84, 68, -42, 38, -14, 0, -64, 12, -2, -38, -8, -44, -88, -34, -80, -36, 82, 70, 96, -32, 16, -52, -12, -46, -28, -86, 30, -14, 50, -44, 22, 30, -4, 78, 52}, 39, 26, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1}, 2, 3, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 50, 1, 93, 12, 7, 55, 35, 36, 62, 61, 71, 16}, 11, 8, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumberOfOccurrencesOrFrequencyInASortedArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [16, 18, 24, 27, 34, 36, 41, 43, 43, 52, 59, 76, 86, 87, 90, 91, 94, 96, 98, 98], \"n\": 14, \"x\": 43}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [64, 66, -36], \"n\": 1, \"x\": 64}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0], \"n\": 2, \"x\": 0}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [9, 85, 34, 43, 70, 96, 44, 7, 27, 33, 34, 5, 91, 84, 76, 45, 20, 37, 15, 37, 20, 24, 13, 49, 74, 13, 50, 81, 81, 66, 23, 36, 91, 80, 61, 15, 96, 70, 90, 25, 16, 62, 75, 63, 6, 65, 38, 12], \"n\": 43, \"x\": 5}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"arr\": [-98, -98, -98, -34, -32, -26, -12, 0, 18, 52, 68, 72], \"n\": 11, \"x\": -98}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"arr\": [1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1], \"n\": 11, \"x\": 1}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"arr\": [1, 3, 6, 6, 10, 12, 15, 16, 21, 22, 23, 29, 33, 37, 40, 40, 43, 52, 55, 59, 64, 65, 71, 72, 80, 83, 86, 86, 88, 88], \"n\": 29, \"x\": 40}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-14, -30, -38, -38, -8, 40, -34, 2, -84, 68, -42, 38, -14, 0, -64, 12, -2, -38, -8, -44, -88, -34, -80, -36, 82, 70, 96, -32, 16, -52, -12, -46, -28, -86, 30, -14, 50, -44, 22, 30, -4, 78, 52], \"n\": 39, \"x\": 26}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1], \"n\": 2, \"x\": 3}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [11, 50, 1, 93, 12, 7, 55, 35, 36, 62, 61, 71, 16], \"n\": 11, \"x\": 8}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
86 | Count Number Of Ways To Cover A Distance 1 | C++ | long long countNumberOfWaysToCoverADistance1(int dist) { | [
"dist"
] | def count_number_of_ways_to_cover_a_distance_1(dist):
count = ([0] * (dist + 1))
count[0] = 1
count[1] = 1
count[2] = 2
for i in range(3, (dist + 1)):
count[i] = ((count[(i - 1)] + count[(i - 2)]) + count[(i - 3)])
return count[dist] | int count_number_of_ways_to_cover_a_distance_1(int dist) {
int count [ dist + 1 ];
count [ 0 ] = 1, count [ 1 ] = 1, count [ 2 ] = 2;
for ( int i = 3;
i <= dist;
i ++ ) count [ i ] = count [ i - 1 ] + count [ i - 2 ] + count [ i - 3 ];
return count [ dist ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int dist, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(dist), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(37, 3831006429); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 1383410902447554); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 65720971788709); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 504); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 1383410902447554); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumberOfWaysToCoverADistance1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3831006429, \"inputs\": {\"dist\": 37}}, {\"idx\": 1, \"outputs\": 1383410902447554, \"inputs\": {\"dist\": 58}}, {\"idx\": 2, \"outputs\": 65720971788709, \"inputs\": {\"dist\": 53}}, {\"idx\": 3, \"outputs\": 504, \"inputs\": {\"dist\": 11}}, {\"idx\": 4, \"outputs\": 1383410902447554, \"inputs\": {\"dist\": 58}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
87 | Count Number Of Ways To Fill A N X 4 Grid Using 1 X 4 Tiles | C++ | long long countNumberOfWaysToFillANX4GridUsing1X4Tiles(int n) { | [
"n"
] | def count_number_of_ways_to_fill_a_n_x_4_grid_using_1_x_4_tiles(n):
dp = [0 for _ in range((n + 1))]
for i in range(1, (n + 1)):
if (i <= 3):
dp[i] = 1
elif (i == 4):
dp[i] = 2
else:
dp[i] = (dp[(i - 1)] + dp[(i - 4)])
return dp[n] | int count_number_of_ways_to_fill_a_n_x_4_grid_using_1_x_4_tiles(int n) {
int dp [ n + 1 ];
dp [ 0 ] = 0;
for ( int i = 1;
i <= n;
i ++ ) {
if ( i >= 1 && i <= 3 ) dp [ i ] = 1;
else if ( i == 4 ) dp [ i ] = 2;
else dp [ i ] = dp [ i - 1 ] + dp [ i - 4 ];
}
return dp [ n ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(61, 188941273); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 657); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 685792227); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 52054840); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 59864); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 1728); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 95); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 2385); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 4123691589365); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumberOfWaysToFillANX4GridUsing1X4Tiles",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 188941273, \"inputs\": {\"n\": 61}}, {\"idx\": 1, \"outputs\": 657, \"inputs\": {\"n\": 22}}, {\"idx\": 2, \"outputs\": 685792227, \"inputs\": {\"n\": 65}}, {\"idx\": 3, \"outputs\": 52054840, \"inputs\": {\"n\": 57}}, {\"idx\": 4, \"outputs\": 59864, \"inputs\": {\"n\": 36}}, {\"idx\": 5, \"outputs\": 1728, \"inputs\": {\"n\": 25}}, {\"idx\": 6, \"outputs\": 95, \"inputs\": {\"n\": 16}}, {\"idx\": 7, \"outputs\": 2385, \"inputs\": {\"n\": 26}}, {\"idx\": 8, \"outputs\": 4123691589365, \"inputs\": {\"n\": 92}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"n\": 5}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
88 | Count Number Pairs N B N Gcd B B | C++ | double countNumberPairsNBNGcdBB(int n) { | [
"n"
] | def count_number_pairs_n_b_n_gcd_b_b(n):
k = n
imin = 1
ans = 0
while (imin <= n):
imax = (n / k)
ans += (k * ((imax - imin) + 1))
imin = (imax + 1)
k = (n / imin)
return ans | int count_number_pairs_n_b_n_gcd_b_b(int n) {
int k = n;
int imin = 1;
int ans = 0;
while ( imin <= n ) {
int imax = n / k;
ans += k * ( imax - imin + 1 );
imin = imax + 1;
k = n / imin;
}
return ans;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int n, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(17, 58.47239288489289); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 349.9783310569835); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 187.0499406858786); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 252.6486716559348); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 291.1683590456309); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 81.19789150478006); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 58.47239288489289); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 326.67596370158344); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 71.95479314287363); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 114.88796013002468); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumberPairsNBNGcdBB",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 58.47239288489289, \"inputs\": {\"n\": 17}}, {\"idx\": 1, \"outputs\": 349.9783310569835, \"inputs\": {\"n\": 72}}, {\"idx\": 2, \"outputs\": 187.0499406858786, \"inputs\": {\"n\": 43}}, {\"idx\": 3, \"outputs\": 252.6486716559348, \"inputs\": {\"n\": 55}}, {\"idx\": 4, \"outputs\": 291.1683590456309, \"inputs\": {\"n\": 62}}, {\"idx\": 5, \"outputs\": 81.19789150478006, \"inputs\": {\"n\": 22}}, {\"idx\": 6, \"outputs\": 58.47239288489289, \"inputs\": {\"n\": 17}}, {\"idx\": 7, \"outputs\": 326.67596370158344, \"inputs\": {\"n\": 68}}, {\"idx\": 8, \"outputs\": 71.95479314287363, \"inputs\": {\"n\": 20}}, {\"idx\": 9, \"outputs\": 114.88796013002468, \"inputs\": {\"n\": 29}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
89 | Count Number Ways Reach Given Score Game | C++ | int countNumberWaysReachGivenScoreGame(int n) { | [
"n"
] | def count_number_ways_reach_given_score_game(n):
table = [0 for i in range((n + 1))]
table[0] = 1
for i in range(3, (n + 1)):
table[i] += table[(i - 3)]
for i in range(5, (n + 1)):
table[i] += table[(i - 5)]
for i in range(10, (n + 1)):
table[i] += table[(i - 10)]
return table[n] | int count_number_ways_reach_given_score_game(int n) {
int table [ n + 1 ], i;
for ( int j = 0;
j < n + 1;
j ++ ) table [ j ] = 0;
table [ 0 ] = 1;
for ( i = 3;
i <= n;
i ++ ) table [ i ] += table [ i - 3 ];
for ( i = 5;
i <= n;
i ++ ) table [ i ] += table [ i - 5 ];
for ( i = 10;
i <= n;
i ++ ) table [ i ] += table [ i - 10 ];
return table [ n ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(83, 30); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 37); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 16); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 33); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 27); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 10); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumberWaysReachGivenScoreGame",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 30, \"inputs\": {\"n\": 83}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"n\": 29}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"n\": 17}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"n\": 12}}, {\"idx\": 4, \"outputs\": 37, \"inputs\": {\"n\": 93}}, {\"idx\": 5, \"outputs\": 16, \"inputs\": {\"n\": 55}}, {\"idx\": 6, \"outputs\": 33, \"inputs\": {\"n\": 97}}, {\"idx\": 7, \"outputs\": 27, \"inputs\": {\"n\": 75}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"n\": 22}}, {\"idx\": 9, \"outputs\": 10, \"inputs\": {\"n\": 52}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
90 | Count Number Ways Tile Floor Size N X M Using 1 X M Size Tiles | C++ | long long countNumberWaysTileFloorSizeNXMUsing1XMSizeTiles(int n, int m) { | [
"n",
"m"
] | def count_number_ways_tile_floor_size_n_x_m_using_1_x_m_size_tiles(n, m):
count = []
for i in range((n + 2)):
count.append(0)
count[0] = 0
for i in range(1, (n + 1)):
if (i > m):
count[i] = (count[(i - 1)] + count[(i - m)])
elif (i < m):
count[i] = 1
else:
count[i] = 2
return count[n] | int count_number_ways_tile_floor_size_n_x_m_using_1_x_m_size_tiles(int n, int m) {
int count [ n + 1 ];
count [ 0 ] = 0;
for ( int i = 1;
i <= n;
i ++ ) {
if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ];
else if ( i < m ) count [ i ] = 1;
else count [ i ] = 2;
}
return count [ n ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, int m, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, m), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(93, 54, 41); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 4, 131); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 39, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 64, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 35, 90); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 61, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 6, 10665883415); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 8, 6); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 60, 11); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 21, 1578); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countNumberWaysTileFloorSizeNXMUsing1XMSizeTiles",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 41, \"inputs\": {\"n\": 93, \"m\": 54}}, {\"idx\": 1, \"outputs\": 131, \"inputs\": {\"n\": 17, \"m\": 4}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"n\": 38, \"m\": 39}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"n\": 33, \"m\": 64}}, {\"idx\": 4, \"outputs\": 90, \"inputs\": {\"n\": 78, \"m\": 35}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"n\": 40, \"m\": 61}}, {\"idx\": 6, \"outputs\": 10665883415, \"inputs\": {\"n\": 95, \"m\": 6}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"n\": 12, \"m\": 8}}, {\"idx\": 8, \"outputs\": 11, \"inputs\": {\"n\": 69, \"m\": 60}}, {\"idx\": 9, \"outputs\": 1578, \"inputs\": {\"n\": 78, \"m\": 21}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
91 | Count Obtuse Angles Circle K Equidistant Points 2 Given Points | C++ | int countObtuseAnglesCircleKEquidistantPoints2GivenPoints(int a, int b, int k) { | [
"a",
"b",
"k"
] | def count_obtuse_angles_circle_k_equidistant_points_2_given_points(a, b, k):
c1 = ((b - a) - 1)
c2 = ((k - b) + (a - 1))
if (c1 == c2):
return 0
return min(c1, c2) | int count_obtuse_angles_circle_k_equidistant_points_2_given_points(int a, int b, int k) {
int c1 = ( b - a ) - 1;
int c2 = ( k - b ) + ( a - 1 );
if ( c1 == c2 ) return 0;
return min ( c1, c2 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(83, 98, 86, 14); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 39, 87, 35); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 96, 30, -56); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 67, 48, 16); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 16, 32, -25); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 86, 76, 23); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 78, 71, 32); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 11, 74, -56); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 9, 19, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 5, 5, -21); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countObtuseAnglesCircleKEquidistantPoints2GivenPoints",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 14, \"inputs\": {\"a\": 83, \"b\": 98, \"k\": 86}}, {\"idx\": 1, \"outputs\": 35, \"inputs\": {\"a\": 3, \"b\": 39, \"k\": 87}}, {\"idx\": 2, \"outputs\": -56, \"inputs\": {\"a\": 11, \"b\": 96, \"k\": 30}}, {\"idx\": 3, \"outputs\": 16, \"inputs\": {\"a\": 50, \"b\": 67, \"k\": 48}}, {\"idx\": 4, \"outputs\": -25, \"inputs\": {\"a\": 40, \"b\": 16, \"k\": 32}}, {\"idx\": 5, \"outputs\": 23, \"inputs\": {\"a\": 62, \"b\": 86, \"k\": 76}}, {\"idx\": 6, \"outputs\": 32, \"inputs\": {\"a\": 40, \"b\": 78, \"k\": 71}}, {\"idx\": 7, \"outputs\": -56, \"inputs\": {\"a\": 66, \"b\": 11, \"k\": 74}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"a\": 6, \"b\": 9, \"k\": 19}}, {\"idx\": 9, \"outputs\": -21, \"inputs\": {\"a\": 25, \"b\": 5, \"k\": 5}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
92 | Count Ofdifferent Ways Express N Sum 1 3 4 | C++ | long long countOfdifferentWaysExpressNSum134(int n) { | [
"n"
] | def count_ofdifferent_ways_express_n_sum_1_3_4(n):
DP = [0 for i in range(0, (n + 1))]
DP[0] = DP[1] = DP[2] = 1
DP[3] = 2
for i in range(4, (n + 1)):
DP[i] = ((DP[(i - 1)] + DP[(i - 3)]) + DP[(i - 4)])
return DP[n] | int count_ofdifferent_ways_express_n_sum_1_3_4(int n) {
int DP [ n + 1 ];
DP [ 0 ] = DP [ 1 ] = DP [ 2 ] = 1;
DP [ 3 ] = 2;
for ( int i = 4;
i <= n;
i ++ ) DP [ i ] = DP [ i - 1 ] + DP [ i - 3 ] + DP [ i - 4 ];
return DP [ n ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(44, 821223649); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 40); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 4895); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 64); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 10472279279564025); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 222915410843904); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 44361286907595736); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 44361286907595736); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 9107509825); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countOfdifferentWaysExpressNSum134",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 821223649, \"inputs\": {\"n\": 44}}, {\"idx\": 1, \"outputs\": 40, \"inputs\": {\"n\": 9}}, {\"idx\": 2, \"outputs\": 4895, \"inputs\": {\"n\": 19}}, {\"idx\": 3, \"outputs\": 64, \"inputs\": {\"n\": 10}}, {\"idx\": 4, \"outputs\": 10472279279564025, \"inputs\": {\"n\": 78}}, {\"idx\": 5, \"outputs\": 222915410843904, \"inputs\": {\"n\": 70}}, {\"idx\": 6, \"outputs\": 44361286907595736, \"inputs\": {\"n\": 81}}, {\"idx\": 7, \"outputs\": 44361286907595736, \"inputs\": {\"n\": 81}}, {\"idx\": 8, \"outputs\": 9107509825, \"inputs\": {\"n\": 49}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
93 | Count Of Occurrences Of A 101 Pattern In A String | C++ | int countOfOccurrencesOfA101PatternInAString(string s) { | [
"s"
] | def count_of_occurrences_of_a_101_pattern_in_a_string(s):
length = len(s)
oneSeen = False
count = 0
for i in range(length):
if ((s[i] == '1') and oneSeen):
if (s[(i - 1)] == '0'):
count += 1
if ((s[i] == '1') and (oneSeen == 0)):
oneSeen = True
if ((s[i] != '0') and (s[i] != '1')):
oneSeen = False
return count | int count_of_occurrences_of_a_101_pattern_in_a_string(string str) {
int len = str . size ( );
bool oneSeen = 0;
int count = 0;
for ( int i = 0;
i < len;
i ++ ) {
if ( str [ i ] == '1' && oneSeen == 1 ) if ( str [ i - 1 ] == '0' ) count ++;
if ( str [ i ] == '1' && oneSeen == 0 ) {
oneSeen = 1;
continue;
}
if ( str [ i ] != '0' && str [ i ] != '1' ) oneSeen = 0;
}
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string s, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"1001ab010abc01001\", 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1001010001\", 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"010100010100\", 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"DLCu\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"7072430592\", 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011\", 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"pnJpypYOza\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1037\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111\", 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"HxK\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countOfOccurrencesOfA101PatternInAString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"s\": \"1001ab010abc01001\"}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"s\": \"1001010001\"}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"s\": \"010100010100\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"s\": \"DLCu\"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"s\": \"7072430592\"}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"s\": \"011\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"s\": \"pnJpypYOza\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"s\": \"1037\"}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"s\": \"111\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"s\": \"HxK\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
94 | Count Of Pairs Satisfying The Given Condition | C++ | int countOfPairsSatisfyingTheGivenCondition(int a, int b) { | [
"a",
"b"
] | def count_of_pairs_satisfying_the_given_condition(a, b):
s = str(b)
i = 0
while (i < len(s)):
if (s[i] != '9'):
break
i += 1
result = 0
if (i == len(s)):
result = (a * len(s))
else:
result = (a * (len(s) - 1))
return result | int count_of_pairs_satisfying_the_given_condition(int a, int b) {
string s = to_string ( b );
int i;
for ( i = 0;
i < s . length ( );
i ++ ) {
if ( s [ i ] != '9' ) break;
}
int result;
if ( i == s . length ( ) ) result = a * s . length ( );
else result = a * ( s . length ( ) - 1 );
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(31, 91, 31); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 85, 72); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 49, 23); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 32, 42); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 7, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 5, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 32, 33); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 76, 94); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 60, 60); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 26, 11); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countOfPairsSatisfyingTheGivenCondition",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 31, \"inputs\": {\"a\": 31, \"b\": 91}}, {\"idx\": 1, \"outputs\": 72, \"inputs\": {\"a\": 72, \"b\": 85}}, {\"idx\": 2, \"outputs\": 23, \"inputs\": {\"a\": 23, \"b\": 49}}, {\"idx\": 3, \"outputs\": 42, \"inputs\": {\"a\": 42, \"b\": 32}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"a\": 13, \"b\": 7}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": 93, \"b\": 5}}, {\"idx\": 6, \"outputs\": 33, \"inputs\": {\"a\": 33, \"b\": 32}}, {\"idx\": 7, \"outputs\": 94, \"inputs\": {\"a\": 94, \"b\": 76}}, {\"idx\": 8, \"outputs\": 60, \"inputs\": {\"a\": 60, \"b\": 60}}, {\"idx\": 9, \"outputs\": 11, \"inputs\": {\"a\": 11, \"b\": 26}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
95 | Count Pairs Difference Equal K | C++ | int countPairsDifferenceEqualK(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def count_pairs_difference_equal_k(arr, n, k):
count = 0
for i in range(0, n):
for j in range((i + 1), n):
if (((arr[i] - arr[j]) == k) or ((arr[j] - arr[i]) == k)):
count += 1
return count | int count_pairs_difference_equal_k(vector<int> arr, int n, int k) {
int count = 0;
for ( int i = 0;
i < n;
i ++ ) {
for ( int j = i + 1;
j < n;
j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++;
}
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({9, 14, 17, 19, 22, 23, 23, 27, 30, 31, 34, 37, 37, 39, 39, 42, 57, 61, 68, 73, 77, 79, 91, 96, 97}, 19, 19, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, -42, 28, -88, 18, -52}, 3, 4, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 16, 14, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 46, 57, 28, 80, 2, 75, 57, 83, 45, 32, 49, 77, 30, 94, 33, 23, 29, 35, 81, 85}, 15, 11, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -72, -72, -62, -62, -54, -54, -52, -48, -38, -22, -22, -22, -12, -12, -8, -8, -8, -6, -6, -2, 6, 12, 26, 26, 28, 28, 38, 40, 48, 52, 52, 58, 60, 68, 70, 72, 76, 76, 76, 92}, 22, 25, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1}, 45, 39, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 13, 19, 23, 27, 32, 49, 52, 54, 57, 58, 58, 63, 67, 68, 68, 69, 70, 75, 80, 86, 90, 91, 95}, 19, 21, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, 40, -66, 42, 8, -40, -8, -42}, 7, 6, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 16, 28, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 12, 90, 10, 86, 86, 81, 19, 1, 1, 98, 82, 34, 39, 34, 1, 54, 47, 39, 82, 21, 50, 82, 41, 98, 47, 88, 46, 72, 28, 28, 29, 60, 87, 92, 53, 93, 29, 74, 75, 11, 32, 48, 47, 85, 16, 20}, 24, 45, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPairsDifferenceEqualK",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"arr\": [9, 14, 17, 19, 22, 23, 23, 27, 30, 31, 34, 37, 37, 39, 39, 42, 57, 61, 68, 73, 77, 79, 91, 96, 97], \"n\": 19, \"k\": 19}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-78, -42, 28, -88, 18, -52], \"n\": 3, \"k\": 4}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 16, \"k\": 14}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"arr\": [8, 46, 57, 28, 80, 2, 75, 57, 83, 45, 32, 49, 77, 30, 94, 33, 23, 29, 35, 81, 85], \"n\": 15, \"k\": 11}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-90, -72, -72, -62, -62, -54, -54, -52, -48, -38, -22, -22, -22, -12, -12, -8, -8, -8, -6, -6, -2, 6, 12, 26, 26, 28, 28, 38, 40, 48, 52, 52, 58, 60, 68, 70, 72, 76, 76, 76, 92], \"n\": 22, \"k\": 25}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1], \"n\": 45, \"k\": 39}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"arr\": [3, 13, 19, 23, 27, 32, 49, 52, 54, 57, 58, 58, 63, 67, 68, 68, 69, 70, 75, 80, 86, 90, 91, 95], \"n\": 19, \"k\": 21}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-56, 40, -66, 42, 8, -40, -8, -42], \"n\": 7, \"k\": 6}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 16, \"k\": 28}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"arr\": [99, 12, 90, 10, 86, 86, 81, 19, 1, 1, 98, 82, 34, 39, 34, 1, 54, 47, 39, 82, 21, 50, 82, 41, 98, 47, 88, 46, 72, 28, 28, 29, 60, 87, 92, 53, 93, 29, 74, 75, 11, 32, 48, 47, 85, 16, 20], \"n\": 24, \"k\": 45}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
96 | Count Pairs Difference Equal K 1 | C++ | int countPairsDifferenceEqualK1(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def count_pairs_difference_equal_k_1(arr, n, k):
count = 0
arr.sort()
l = 0
r = 0
while (r < n):
if ((arr[r] - arr[l]) == k):
count += 1
l += 1
r += 1
elif ((arr[r] - arr[l]) > k):
l += 1
else:
r += 1
return count | int count_pairs_difference_equal_k_1(vector<int> arr, int n, int k) {
int count = 0;
sort(arr.begin(), arr.end());
int l = 0;
int r = 0;
while ( r < n ) {
if ( arr [ r ] - arr [ l ] == k ) {
count ++;
l ++;
r ++;
}
else if ( arr [ r ] - arr [ l ] > k ) l ++;
else r ++;
}
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 5, 10, 19, 29, 32, 40, 60, 65, 70, 72, 89, 92}, 7, 12, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -90, -88, -82, -80, -78, -74, -74, -72, -62, -58, -58, -56, -52, -48, -46, -38, -38, -30, -12, -10, 4, 8, 8, 14, 22, 24, 26, 36, 40, 40, 48, 56, 58, 58, 58, 60, 62, 64, 68, 68, 74, 84}, 24, 36, 7); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1}, 1, 1, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 7, 13, 14, 16, 29, 34, 42, 44, 49, 59, 62, 65, 66, 70, 71, 73, 73, 76, 80, 96, 96}, 12, 16, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -88, -58, -56, -48, -34, -22, -18, -14, -14, -8, -4, -2, 2, 18, 38, 42, 46, 54, 68, 70, 90, 94, 96, 98}, 23, 22, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1}, 2, 1, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 43, 50, 58, 60, 68, 75}, 4, 4, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -56, -10, 0, 6, 8, 24, 42, 52, 86, 88, 94}, 11, 9, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, 30, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 7, 9, 9, 14, 34, 34, 36, 50, 54, 80, 81, 99}, 9, 8, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPairsDifferenceEqualK1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [5, 5, 10, 19, 29, 32, 40, 60, 65, 70, 72, 89, 92], \"n\": 7, \"k\": 12}}, {\"idx\": 1, \"outputs\": 7, \"inputs\": {\"arr\": [-98, -90, -88, -82, -80, -78, -74, -74, -72, -62, -58, -58, -56, -52, -48, -46, -38, -38, -30, -12, -10, 4, 8, 8, 14, 22, 24, 26, 36, 40, 40, 48, 56, 58, 58, 58, 60, 62, 64, 68, 68, 74, 84], \"n\": 24, \"k\": 36}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 1], \"n\": 1, \"k\": 1}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [1, 7, 13, 14, 16, 29, 34, 42, 44, 49, 59, 62, 65, 66, 70, 71, 73, 73, 76, 80, 96, 96], \"n\": 12, \"k\": 16}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"arr\": [-98, -88, -58, -56, -48, -34, -22, -18, -14, -14, -8, -4, -2, 2, 18, 38, 42, 46, 54, 68, 70, 90, 94, 96, 98], \"n\": 23, \"k\": 22}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1, 1], \"n\": 2, \"k\": 1}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [11, 43, 50, 58, 60, 68, 75], \"n\": 4, \"k\": 4}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-80, -56, -10, 0, 6, 8, 24, 42, 52, 86, 88, 94], \"n\": 11, \"k\": 9}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29, \"k\": 30}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [4, 7, 9, 9, 14, 34, 34, 36, 50, 54, 80, 81, 99], \"n\": 9, \"k\": 8}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
97 | Count Pairs Two Sorted Arrays Whose Sum Equal Given Value X | C++ | int countPairsTwoSortedArraysWhoseSumEqualGivenValueX(vector<int> arr1, vector<int> arr2, int m, int n, int x) { | [
"arr1",
"arr2",
"m",
"n",
"x"
] | def count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x(arr1, arr2, m, n, x):
count = 0
for i in range(m):
for j in range(n):
if ((arr1[i] + arr2[j]) == x):
count = (count + 1)
return count | int count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x(vector<int> arr1, vector<int> arr2, int m, int n, int x) {
int count = 0;
for ( int i = 0;
i < m;
i ++ ) for ( int j = 0;
j < n;
j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++;
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int m, int n, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, m, n, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({11, 13, 16, 23, 26, 28, 31, 34, 37, 39, 44, 48, 56, 59, 79, 91, 96, 98}, {1, 1, 9, 14, 17, 23, 26, 31, 33, 36, 53, 60, 71, 75, 76, 84, 87, 88}, 9, 15, 11, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 14, -98, 14, 90, 36, 66, 44, 10, -98, -24, -36, -32, -50}, {34, -6, -66, 0, -6, 82, 60, -98, -8, 60, -2, 4, 22, 76}, 11, 12, 8, 5); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 14, 9, 12, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({88, 14, 29, 87, 86, 58}, {91, 95, 64, 4, 63, 35}, 3, 5, 5, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -88, -86, -82, -76, -72, -66, -56, -48, -34, -28, -28, -26, -20, -18, -18, -16, -16, -12, -4, 0, 6, 12, 16, 20, 22, 30, 34, 34, 36, 56, 58, 62, 64, 80, 82, 94}, {-94, -90, -88, -84, -82, -78, -76, -72, -70, -58, -58, -46, -42, -40, -40, -32, -22, -20, -18, -12, -8, -6, 6, 6, 18, 20, 34, 46, 60, 62, 66, 72, 72, 76, 76, 78, 92, 98}, 34, 32, 23, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0}, {1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0}, 39, 26, 34, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({70, 70, 74}, {15, 55, 84}, 1, 1, 1, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-20, -12, -50, 76, 24, 64, -22, -4, -68}, {18, 98, -88, 86, 72, -44, 82, 94, 58}, 5, 4, 7, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 26, 37, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, 75, 51, 45, 73, 95, 48, 53, 70, 41, 65, 47, 46, 43, 79, 29, 50}, {4, 6, 76, 65, 16, 13, 85, 43, 31, 14, 81, 90, 24, 87, 40, 25, 88}, 10, 10, 9, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPairsTwoSortedArraysWhoseSumEqualGivenValueX",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr1\": [11, 13, 16, 23, 26, 28, 31, 34, 37, 39, 44, 48, 56, 59, 79, 91, 96, 98], \"arr2\": [1, 1, 9, 14, 17, 23, 26, 31, 33, 36, 53, 60, 71, 75, 76, 84, 87, 88], \"m\": 9, \"n\": 15, \"x\": 11}}, {\"idx\": 1, \"outputs\": 5, \"inputs\": {\"arr1\": [50, 14, -98, 14, 90, 36, 66, 44, 10, -98, -24, -36, -32, -50], \"arr2\": [34, -6, -66, 0, -6, 82, 60, -98, -8, 60, -2, 4, 22, 76], \"m\": 11, \"n\": 12, \"x\": 8}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"m\": 14, \"n\": 9, \"x\": 12}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr1\": [88, 14, 29, 87, 86, 58], \"arr2\": [91, 95, 64, 4, 63, 35], \"m\": 3, \"n\": 5, \"x\": 5}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr1\": [-98, -92, -88, -86, -82, -76, -72, -66, -56, -48, -34, -28, -28, -26, -20, -18, -18, -16, -16, -12, -4, 0, 6, 12, 16, 20, 22, 30, 34, 34, 36, 56, 58, 62, 64, 80, 82, 94], \"arr2\": [-94, -90, -88, -84, -82, -78, -76, -72, -70, -58, -58, -46, -42, -40, -40, -32, -22, -20, -18, -12, -8, -6, 6, 6, 18, 20, 34, 46, 60, 62, 66, 72, 72, 76, 76, 78, 92, 98], \"m\": 34, \"n\": 32, \"x\": 23}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr1\": [1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0], \"arr2\": [1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0], \"m\": 39, \"n\": 26, \"x\": 34}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr1\": [70, 70, 74], \"arr2\": [15, 55, 84], \"m\": 1, \"n\": 1, \"x\": 1}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr1\": [-20, -12, -50, 76, 24, 64, -22, -4, -68], \"arr2\": [18, 98, -88, 86, 72, -44, 82, 94, 58], \"m\": 5, \"n\": 4, \"x\": 7}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"m\": 27, \"n\": 26, \"x\": 37}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr1\": [68, 75, 51, 45, 73, 95, 48, 53, 70, 41, 65, 47, 46, 43, 79, 29, 50], \"arr2\": [4, 6, 76, 65, 16, 13, 85, 43, 31, 14, 81, 90, 24, 87, 40, 25, 88], \"m\": 10, \"n\": 10, \"x\": 9}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
98 | Count Pairs Two Sorted Arrays Whose Sum Equal Given Value X 1 | C++ | int countPairsTwoSortedArraysWhoseSumEqualGivenValueX1(vector<int> arr1, vector<int> arr2, int m, int n, int x) { | [
"arr1",
"arr2",
"m",
"n",
"x"
] | def count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_1(arr1, arr2, m, n, x):
count = 0
us = set()
for i in range(m):
us.add(arr1[i])
for j in range(n):
if ((x - arr2[j]) in us):
count += 1
return count | int count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_1(vector<int> arr1, vector<int> arr2, int m, int n, int x) {
int count = 0;
unordered_set < int > us;
for ( int i = 0;
i < m;
i ++ ) us . insert ( arr1 [ i ] );
for ( int j = 0;
j < n;
j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++;
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int m, int n, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, m, n, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 2, 5, 5, 9, 11, 12, 14, 16, 18, 35, 36, 39, 44, 50, 52, 52, 59, 69, 81, 82, 84, 85, 87, 87, 87, 88, 88, 89, 90, 90, 92, 97}, {5, 5, 8, 20, 20, 24, 25, 29, 34, 37, 43, 45, 48, 49, 59, 60, 68, 70, 70, 72, 72, 75, 76, 77, 79, 81, 84, 85, 86, 88, 95, 96, 96}, 17, 29, 32, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, 28, -38, 78, -86, 78, -48, -70, -80, 28, -8, 60, -28, 90, 6, 76, 32, -54, 30, 30, -32, -24, -36, 62, 36, -66, 56, 92, -20, 90, 32}, {-88, -32, 30, 32, -46, 62, -92, -90, -18, -18, 10, 16, 60, -40, 32, -88, 60, -82, 76, 50, 86, -82, -48, -68, -42, 34, 4, 0, 98, 92, -78}, 30, 27, 17, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 11, 8, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({91, 95, 13, 13, 76, 18, 36, 86, 26, 13, 17, 68, 58, 42, 38, 9, 42, 90, 14, 74, 38, 64, 15}, {16, 96, 8, 35, 12, 27, 81, 21, 32, 82, 95, 81, 53, 76, 72, 16, 9, 16, 61, 1, 36, 71, 28}, 11, 12, 15, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -94, -92, -74, -70, -66, -54, -48, -20, -18, -10, -6, -2, 2, 18, 36, 48, 52, 58, 68, 74, 88, 90, 94}, {-92, -72, -72, -64, -58, -52, -30, -28, -24, -24, -16, -10, -2, 4, 12, 22, 30, 38, 44, 62, 64, 68, 86, 88, 90}, 19, 14, 21, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0}, {1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0}, 18, 19, 29, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 18, 19, 20, 24, 25, 25, 27, 30, 35, 39, 42, 58, 59, 63, 64, 64, 66, 66, 68, 69, 77, 86, 93}, {2, 2, 18, 20, 22, 22, 31, 35, 36, 40, 41, 41, 41, 42, 42, 43, 45, 61, 79, 83, 87, 91, 95, 96}, 22, 18, 18, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 44, 10, 80, 12, 52, -92, 2, 42, -32, -14, 2, -42, 40, 96, 22, 58, -90, -20, 22, 96, 10, -92, -28, -28, 80, 36, 72, -2, 32, -46, 62, -58, 20, 22, 32, -98, -2, -42, -90, 10, 70, 54, -32}, {-4, -76, -98, 14, 30, -10, -10, 62, 88, -94, -74, -82, 84, 44, 58, 8, -42, -66, -18, 68, -78, 42, -32, 38, -98, 38, -78, 42, 86, -38, -6, -72, -44, 8, -6, -48, -62, 82, 94, -92, -56, 28, -54, 34}, 26, 36, 31, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1}, {0, 0, 1, 1, 1, 1}, 5, 3, 5, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({43, 2, 4, 99, 45, 80, 27, 8, 64, 77, 57, 55, 71, 67, 51, 42, 58, 70, 5, 62, 55, 20, 61, 47, 66, 80, 70, 24, 56, 22, 58, 63, 61, 41, 20, 97, 47}, {11, 66, 41, 17, 93, 25, 24, 17, 12, 33, 62, 86, 48, 68, 36, 36, 39, 82, 7, 66, 5, 48, 27, 9, 56, 6, 61, 91, 98, 74, 61, 63, 98, 96, 57, 63, 85}, 24, 29, 21, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPairsTwoSortedArraysWhoseSumEqualGivenValueX1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr1\": [1, 2, 5, 5, 9, 11, 12, 14, 16, 18, 35, 36, 39, 44, 50, 52, 52, 59, 69, 81, 82, 84, 85, 87, 87, 87, 88, 88, 89, 90, 90, 92, 97], \"arr2\": [5, 5, 8, 20, 20, 24, 25, 29, 34, 37, 43, 45, 48, 49, 59, 60, 68, 70, 70, 72, 72, 75, 76, 77, 79, 81, 84, 85, 86, 88, 95, 96, 96], \"m\": 17, \"n\": 29, \"x\": 32}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr1\": [52, 28, -38, 78, -86, 78, -48, -70, -80, 28, -8, 60, -28, 90, 6, 76, 32, -54, 30, 30, -32, -24, -36, 62, 36, -66, 56, 92, -20, 90, 32], \"arr2\": [-88, -32, 30, 32, -46, 62, -92, -90, -18, -18, 10, 16, 60, -40, 32, -88, 60, -82, 76, 50, 86, -82, -48, -68, -42, 34, 4, 0, 98, 92, -78], \"m\": 30, \"n\": 27, \"x\": 17}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"m\": 13, \"n\": 11, \"x\": 8}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr1\": [91, 95, 13, 13, 76, 18, 36, 86, 26, 13, 17, 68, 58, 42, 38, 9, 42, 90, 14, 74, 38, 64, 15], \"arr2\": [16, 96, 8, 35, 12, 27, 81, 21, 32, 82, 95, 81, 53, 76, 72, 16, 9, 16, 61, 1, 36, 71, 28], \"m\": 11, \"n\": 12, \"x\": 15}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr1\": [-96, -94, -94, -92, -74, -70, -66, -54, -48, -20, -18, -10, -6, -2, 2, 18, 36, 48, 52, 58, 68, 74, 88, 90, 94], \"arr2\": [-92, -72, -72, -64, -58, -52, -30, -28, -24, -24, -16, -10, -2, 4, 12, 22, 30, 38, 44, 62, 64, 68, 86, 88, 90], \"m\": 19, \"n\": 14, \"x\": 21}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr1\": [1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0], \"arr2\": [1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0], \"m\": 18, \"n\": 19, \"x\": 29}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr1\": [7, 18, 19, 20, 24, 25, 25, 27, 30, 35, 39, 42, 58, 59, 63, 64, 64, 66, 66, 68, 69, 77, 86, 93], \"arr2\": [2, 2, 18, 20, 22, 22, 31, 35, 36, 40, 41, 41, 41, 42, 42, 43, 45, 61, 79, 83, 87, 91, 95, 96], \"m\": 22, \"n\": 18, \"x\": 18}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr1\": [86, 44, 10, 80, 12, 52, -92, 2, 42, -32, -14, 2, -42, 40, 96, 22, 58, -90, -20, 22, 96, 10, -92, -28, -28, 80, 36, 72, -2, 32, -46, 62, -58, 20, 22, 32, -98, -2, -42, -90, 10, 70, 54, -32], \"arr2\": [-4, -76, -98, 14, 30, -10, -10, 62, 88, -94, -74, -82, 84, 44, 58, 8, -42, -66, -18, 68, -78, 42, -32, 38, -98, 38, -78, 42, 86, -38, -6, -72, -44, 8, -6, -48, -62, 82, 94, -92, -56, 28, -54, 34], \"m\": 26, \"n\": 36, \"x\": 31}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 1, 1, 1, 1], \"arr2\": [0, 0, 1, 1, 1, 1], \"m\": 5, \"n\": 3, \"x\": 5}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr1\": [43, 2, 4, 99, 45, 80, 27, 8, 64, 77, 57, 55, 71, 67, 51, 42, 58, 70, 5, 62, 55, 20, 61, 47, 66, 80, 70, 24, 56, 22, 58, 63, 61, 41, 20, 97, 47], \"arr2\": [11, 66, 41, 17, 93, 25, 24, 17, 12, 33, 62, 86, 48, 68, 36, 36, 39, 82, 7, 66, 5, 48, 27, 9, 56, 6, 61, 91, 98, 74, 61, 63, 98, 96, 57, 63, 85], \"m\": 24, \"n\": 29, \"x\": 21}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
99 | Count Pairs Two Sorted Arrays Whose Sum Equal Given Value X 2 | C++ | int countPairsTwoSortedArraysWhoseSumEqualGivenValueX2(vector<int> arr1, vector<int> arr2, int m, int n, int x) { | [
"arr1",
"arr2",
"m",
"n",
"x"
] | def count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_2(arr1, arr2, m, n, x):
(count, l, r) = (0, 0, (n - 1))
while ((l < m) and (r >= 0)):
if ((arr1[l] + arr2[r]) == x):
l += 1
r -= 1
count += 1
elif ((arr1[l] + arr2[r]) < x):
l += 1
else:
r -= 1
return count | int count_pairs_two_sorted_arrays_whose_sum_equal_given_value_x_2(vector<int> arr1, vector<int> arr2, int m, int n, int x) {
int count = 0;
int l = 0, r = n - 1;
while ( l < m && r >= 0 ) {
if ( ( arr1 [ l ] + arr2 [ r ] ) == x ) {
l ++;
r --;
count ++;
}
else if ( ( arr1 [ l ] + arr2 [ r ] ) < x ) l ++;
else r --;
}
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int m, int n, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, m, n, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 5, 7, 10, 14, 14, 17, 21, 32, 34, 37, 40, 40, 40, 46, 46, 50, 50, 51, 55, 57, 62, 65, 67, 67, 69, 70, 70, 72, 73, 76, 77, 77, 78, 84, 85, 85, 86, 87, 88, 88, 89, 89, 90, 93, 99}, {2, 5, 8, 8, 10, 12, 13, 15, 17, 18, 20, 20, 21, 27, 28, 31, 34, 37, 40, 46, 48, 52, 53, 54, 54, 58, 59, 60, 66, 68, 68, 69, 70, 71, 72, 73, 77, 77, 80, 84, 84, 92, 92, 95, 97, 97}, 28, 29, 23, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, 52, -34, 96, 16, 92, -64, -74}, {-22, 26, -12, -54, 66, 86, 38, 76}, 6, 5, 7, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 26, 42, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({60, 92, 42, 83, 55, 76, 29, 62}, {71, 2, 74, 42, 80, 71, 26, 76}, 4, 7, 7, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -94, -58, -40, -40, -26, -24, -22, -22, -22, -2, 0, 4, 8, 12, 16, 16, 18, 22, 32, 42, 44, 50, 58, 64, 78, 80, 90}, {-86, -84, -78, -76, -72, -70, -62, -58, -54, -54, -50, -46, -44, -40, -30, -28, -16, -10, 10, 36, 36, 48, 70, 84, 84, 90, 94, 98}, 17, 27, 17, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 0, 0, 1, 1, 1}, {1, 1, 1, 0, 1, 1, 0, 0, 0, 0}, 5, 8, 9, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 5, 7, 7, 7, 14, 15, 16, 17, 18, 18, 19, 20, 25, 27, 31, 36, 42, 47, 51, 56, 56, 56, 58, 58, 59, 63, 63, 63, 65, 66, 67, 76, 83, 93, 94, 97}, {2, 3, 7, 8, 9, 10, 17, 18, 21, 28, 29, 29, 33, 35, 46, 47, 47, 49, 49, 49, 53, 56, 58, 59, 59, 60, 65, 67, 70, 78, 81, 85, 85, 87, 90, 92, 96}, 28, 34, 31, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, -74, 52, 56, -8, 92, 14, 56, -72, -92, 32, -94, -26, -8, -66, 72, -24, 36, -84, -4, -68, 14, 78, 40, -82, -10, 16, 56, 6, -16, 30, 24, -32}, {-74, 22, -14, -2, 36, 86, -70, -20, -76, -84, -40, -36, 42, 22, -60, -94, -18, 8, -14, -42, -68, 62, -60, 2, 40, -66, 68, 96, 70, 98, -38, -74, -92}, 16, 30, 24, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, 33, 33, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({17, 50, 65, 4, 19, 10, 45, 70, 76, 81, 28, 97, 55, 70, 38, 2, 40, 67, 36, 33, 6, 85, 25}, {78, 92, 65, 23, 7, 94, 18, 4, 2, 53, 31, 58, 98, 18, 46, 16, 17, 92, 80, 92, 43, 70, 50}, 16, 22, 22, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPairsTwoSortedArraysWhoseSumEqualGivenValueX2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"arr1\": [5, 5, 7, 10, 14, 14, 17, 21, 32, 34, 37, 40, 40, 40, 46, 46, 50, 50, 51, 55, 57, 62, 65, 67, 67, 69, 70, 70, 72, 73, 76, 77, 77, 78, 84, 85, 85, 86, 87, 88, 88, 89, 89, 90, 93, 99], \"arr2\": [2, 5, 8, 8, 10, 12, 13, 15, 17, 18, 20, 20, 21, 27, 28, 31, 34, 37, 40, 46, 48, 52, 53, 54, 54, 58, 59, 60, 66, 68, 68, 69, 70, 71, 72, 73, 77, 77, 80, 84, 84, 92, 92, 95, 97, 97], \"m\": 28, \"n\": 29, \"x\": 23}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr1\": [-84, 52, -34, 96, 16, 92, -64, -74], \"arr2\": [-22, 26, -12, -54, 66, 86, 38, 76], \"m\": 6, \"n\": 5, \"x\": 7}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"m\": 37, \"n\": 26, \"x\": 42}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr1\": [60, 92, 42, 83, 55, 76, 29, 62], \"arr2\": [71, 2, 74, 42, 80, 71, 26, 76], \"m\": 4, \"n\": 7, \"x\": 7}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr1\": [-94, -94, -58, -40, -40, -26, -24, -22, -22, -22, -2, 0, 4, 8, 12, 16, 16, 18, 22, 32, 42, 44, 50, 58, 64, 78, 80, 90], \"arr2\": [-86, -84, -78, -76, -72, -70, -62, -58, -54, -54, -50, -46, -44, -40, -30, -28, -16, -10, 10, 36, 36, 48, 70, 84, 84, 90, 94, 98], \"m\": 17, \"n\": 27, \"x\": 17}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 1, 1, 1, 0, 0, 1, 1, 1], \"arr2\": [1, 1, 1, 0, 1, 1, 0, 0, 0, 0], \"m\": 5, \"n\": 8, \"x\": 9}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr1\": [1, 5, 7, 7, 7, 14, 15, 16, 17, 18, 18, 19, 20, 25, 27, 31, 36, 42, 47, 51, 56, 56, 56, 58, 58, 59, 63, 63, 63, 65, 66, 67, 76, 83, 93, 94, 97], \"arr2\": [2, 3, 7, 8, 9, 10, 17, 18, 21, 28, 29, 29, 33, 35, 46, 47, 47, 49, 49, 49, 53, 56, 58, 59, 59, 60, 65, 67, 70, 78, 81, 85, 85, 87, 90, 92, 96], \"m\": 28, \"n\": 34, \"x\": 31}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr1\": [78, -74, 52, 56, -8, 92, 14, 56, -72, -92, 32, -94, -26, -8, -66, 72, -24, 36, -84, -4, -68, 14, 78, 40, -82, -10, 16, 56, 6, -16, 30, 24, -32], \"arr2\": [-74, 22, -14, -2, 36, 86, -70, -20, -76, -84, -40, -36, 42, 22, -60, -94, -18, 8, -14, -42, -68, 62, -60, 2, 40, -66, 68, 96, 70, 98, -38, -74, -92], \"m\": 16, \"n\": 30, \"x\": 24}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"m\": 25, \"n\": 33, \"x\": 33}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr1\": [17, 50, 65, 4, 19, 10, 45, 70, 76, 81, 28, 97, 55, 70, 38, 2, 40, 67, 36, 33, 6, 85, 25], \"arr2\": [78, 92, 65, 23, 7, 94, 18, 4, 2, 53, 31, 58, 98, 18, 46, 16, 17, 92, 80, 92, 43, 70, 50], \"m\": 16, \"n\": 22, \"x\": 22}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
100 | Count Pairs Whose Products Exist In Array | C++ | int countPairsWhoseProductsExistInArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def count_pairs_whose_products_exist_in_array(arr, n):
result = 0
for i in range(0, n):
for j in range((i + 1), n):
product = (arr[i] * arr[j])
for k in range(0, n):
if (arr[k] == product):
result = (result + 1)
break
return result | int count_pairs_whose_products_exist_in_array(vector<int> arr, int n) {
int result = 0;
for ( int i = 0;
i < n;
i ++ ) {
for ( int j = i + 1;
j < n;
j ++ ) {
int product = arr [ i ] * arr [ j ];
for ( int k = 0;
k < n;
k ++ ) {
if ( arr [ k ] == product ) {
result ++;
break;
}
}
}
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({3, 7, 26, 40, 46, 89, 99}, 5, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 42, -24, -60, 74, 86, 6, 8, 72, -58, 38, -20, 6, -6, 8, 48, -34, 30, 60, 66, 38, -54, 8, -94, -8, 0, -64, -94, -94, -72, -84, -36, 88, -62, -88, 46, -4, 88}, 24, 6); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 44, 946); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({37, 97, 57, 82, 29, 68, 94, 38, 81, 48, 13, 84, 57, 5, 27, 87, 11, 35, 82, 53, 67, 31, 15, 99, 6, 93, 91, 92, 3, 23, 90, 27, 6, 33, 78, 3, 19, 19, 27}, 36, 18); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -74, -72, -72, -66, -66, -62, -50, -44, -44, -28, -24, -24, -22, -16, -10, -6, -4, -2, 2, 2, 4, 12, 16, 16, 28, 30, 32, 32, 38, 38, 72, 84, 86, 88, 90, 96}, 34, 15); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1}, 18, 153); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({25, 67}, 1, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({82, 74, -82, 22, -28, -78, -22, -86, -74, 42, -6, 54, -88, -92, -14, -50, 68, 46, -50, 46, -18, 66, -76, -30, 36, 12, 66}, 14, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 32, 496); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 23, 56, 9}, 3, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPairsWhoseProductsExistInArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [3, 7, 26, 40, 46, 89, 99], \"n\": 5}}, {\"idx\": 1, \"outputs\": 6, \"inputs\": {\"arr\": [98, 42, -24, -60, 74, 86, 6, 8, 72, -58, 38, -20, 6, -6, 8, 48, -34, 30, 60, 66, 38, -54, 8, -94, -8, 0, -64, -94, -94, -72, -84, -36, 88, -62, -88, 46, -4, 88], \"n\": 24}}, {\"idx\": 2, \"outputs\": 946, \"inputs\": {\"arr\": [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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 44}}, {\"idx\": 3, \"outputs\": 18, \"inputs\": {\"arr\": [37, 97, 57, 82, 29, 68, 94, 38, 81, 48, 13, 84, 57, 5, 27, 87, 11, 35, 82, 53, 67, 31, 15, 99, 6, 93, 91, 92, 3, 23, 90, 27, 6, 33, 78, 3, 19, 19, 27], \"n\": 36}}, {\"idx\": 4, \"outputs\": 15, \"inputs\": {\"arr\": [-80, -74, -72, -72, -66, -66, -62, -50, -44, -44, -28, -24, -24, -22, -16, -10, -6, -4, -2, 2, 2, 4, 12, 16, 16, 28, 30, 32, 32, 38, 38, 72, 84, 86, 88, 90, 96], \"n\": 34}}, {\"idx\": 5, \"outputs\": 153, \"inputs\": {\"arr\": [0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1], \"n\": 18}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [25, 67], \"n\": 1}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [82, 74, -82, 22, -28, -78, -22, -86, -74, 42, -6, 54, -88, -92, -14, -50, 68, 46, -50, 46, -18, 66, -76, -30, 36, 12, 66], \"n\": 14}}, {\"idx\": 8, \"outputs\": 496, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 32}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [50, 23, 56, 9], \"n\": 3}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
101 | Count Pairs Whose Products Exist In Array 1 | C++ | int countPairsWhoseProductsExistInArray1(vector<int> arr, int n) { | [
"arr",
"n"
] | def count_pairs_whose_products_exist_in_array_1(arr, n):
result = 0
Hash = set()
for i in range(n):
Hash.add(arr[i])
for i in range(n):
for j in range((i + 1), n):
product = (arr[i] * arr[j])
if (product in Hash):
result += 1
return result | int count_pairs_whose_products_exist_in_array_1(vector<int> arr, int n) {
int result = 0;
set < int > Hash;
for ( int i = 0;
i < n;
i ++ ) Hash . insert ( arr [ i ] );
for ( int i = 0;
i < n;
i ++ ) {
for ( int j = i + 1;
j < n;
j ++ ) {
int product = arr [ i ] * arr [ j ];
if ( Hash . find ( product ) != Hash . end ( ) ) result ++;
}
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({7, 10, 17, 17, 18, 20, 27, 28, 29, 29, 31, 32, 41, 43, 45, 46, 63, 66, 69, 69, 70, 75, 87, 95}, 17, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-60}, 0, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 9, 36); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, 83, 36, 57, 93, 11, 32, 91, 52}, 8, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -94, -90, -88, -76, -76, -64, -62, -60, -50, -46, -32, -24, -22, -20, -16, -4, -2, 6, 10, 20, 28, 30, 32, 34, 38, 40, 42, 54, 64, 72, 76, 82, 82, 86, 92, 92, 98, 98}, 22, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0}, 42, 861); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 10, 12, 15, 23, 26, 28, 29, 30, 31, 31, 33, 33, 35, 41, 45, 48, 50, 50, 53, 53, 56, 65, 66, 67, 68, 68, 72, 72, 75, 76, 79, 82, 90, 94, 94, 95, 97, 99}, 35, 9); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, 36, -54, -54}, 3, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, 12, 66); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 69, 37, 80, 21, 98, 70, 70, 74, 95, 6, 67, 44, 55, 52, 89, 84, 99, 65, 52}, 12, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPairsWhoseProductsExistInArray1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [7, 10, 17, 17, 18, 20, 27, 28, 29, 29, 31, 32, 41, 43, 45, 46, 63, 66, 69, 69, 70, 75, 87, 95], \"n\": 17}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-60], \"n\": 0}}, {\"idx\": 2, \"outputs\": 36, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 9}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [52, 83, 36, 57, 93, 11, 32, 91, 52], \"n\": 8}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"arr\": [-98, -94, -90, -88, -76, -76, -64, -62, -60, -50, -46, -32, -24, -22, -20, -16, -4, -2, 6, 10, 20, 28, 30, 32, 34, 38, 40, 42, 54, 64, 72, 76, 82, 82, 86, 92, 92, 98, 98], \"n\": 22}}, {\"idx\": 5, \"outputs\": 861, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0], \"n\": 42}}, {\"idx\": 6, \"outputs\": 9, \"inputs\": {\"arr\": [2, 3, 10, 12, 15, 23, 26, 28, 29, 30, 31, 31, 33, 33, 35, 41, 45, 48, 50, 50, 53, 53, 56, 65, 66, 67, 68, 68, 72, 72, 75, 76, 79, 82, 90, 94, 94, 95, 97, 99], \"n\": 35}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [14, 36, -54, -54], \"n\": 3}}, {\"idx\": 8, \"outputs\": 66, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"n\": 12}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [5, 69, 37, 80, 21, 98, 70, 70, 74, 95, 6, 67, 44, 55, 52, 89, 84, 99, 65, 52], \"n\": 12}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
102 | Count Palindrome Sub Strings String | C++ | int countPalindromeSubStringsString(vector<char> str, int n) { | [
"str",
"n"
] | def count_palindrome_sub_strings_string(str, n):
dp = [[0 for x in range(n)] for y in range(n)]
P = [[False for x in range(n)] for y in range(n)]
for i in range(n):
P[i][i] = True
for i in range((n - 1)):
if (str[i] == str[(i + 1)]):
P[i][(i + 1)] = True
dp[i][(i + 1)] = 1
for gap in range(2, n):
for i in range((n - gap)):
j = (gap + i)
if ((str[i] == str[j]) and P[(i + 1)][(j - 1)]):
P[i][j] = True
if (P[i][j] == True):
dp[i][j] = (((dp[i][(j - 1)] + dp[(i + 1)][j]) + 1) - dp[(i + 1)][(j - 1)])
else:
dp[i][j] = ((dp[i][(j - 1)] + dp[(i + 1)][j]) - dp[(i + 1)][(j - 1)])
return dp[0][(n - 1)] | int count_palindrome_sub_strings_string(vector<char> str, int n) {
int dp [ n ] [ n ];
memset ( dp, 0, sizeof ( dp ) );
bool P [ n ] [ n ];
memset ( P, false, sizeof ( P ) );
for ( int i = 0;
i < n;
i ++ ) P [ i ] [ i ] = true;
for ( int i = 0;
i < n - 1;
i ++ ) {
if ( str [ i ] == str [ i + 1 ] ) {
P [ i ] [ i + 1 ] = true;
dp [ i ] [ i + 1 ] = 1;
}
}
for ( int gap = 2;
gap < n;
gap ++ ) {
for ( int i = 0;
i < n - gap;
i ++ ) {
int j = gap + i;
if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true;
if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ];
else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ];
}
}
return dp [ 0 ] [ n - 1 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<char> str, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({'E', 'E', 'J', 'P', 'T', 'U', 'X', 'Y', 'Z', 'e', 'f', 'h', 'l', 'm', 'n', 'o', 'z'}, 11, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'8', '7', '3', '4', '9', '5', '3', '1', '4', '0', '6', '8', '2', '5', '8', '3', '5', '2', '8', '6', '6', '3', '5', '7', '5', '5', '3', '7'}, 27, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'}, 23, 211); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'f', 'E', 'e', 'z', 'B', 'o', 'i', 'v', 'K', 'u', 'P', 'C', 'z', 'f', 'k', 'J', 't', 'R', 't', 'A', 'f', 'G', 'D', 'X', 'H', 'e', 'p', 'l', 'l', 'k', 'Z', 'Y', 'u', 'g', 'H', 'C', 'f', 'J', 'H', 'W'}, 27, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '0', '0', '1', '1', '1', '1', '1', '1', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4', '5', '5', '5', '5', '6', '6', '7', '7', '9', '9', '9', '9', '9', '9'}, 35, 60); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'1', '0', '1', '1', '0', '0', '1', '1', '1', '0', '1', '0', '1', '1', '0', '1', '0', '1', '1', '1', '1', '1', '0', '1', '1', '0', '1', '0', '1', '1', '0', '0', '1', '0', '1', '0', '0', '0', '0', '0', '1', '1', '0', '1', '0', '1'}, 43, 72); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'C', 'C', 'D', 'F', 'L', 'M', 'P', 'X', 'a', 'f', 'i', 'j', 'w'}, 9, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'7', '9', '0', '2', '8', '0', '7', '5', '9', '4', '5', '4', '8', '1', '9', '5', '3', '2', '4', '1', '2'}, 16, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'}, 32, 289); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'m', 'X', 'N', 'M'}, 3, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPalindromeSubStringsString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"str\": [\"E\", \"E\", \"J\", \"P\", \"T\", \"U\", \"X\", \"Y\", \"Z\", \"e\", \"f\", \"h\", \"l\", \"m\", \"n\", \"o\", \"z\"], \"n\": 11}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"str\": [\"8\", \"7\", \"3\", \"4\", \"9\", \"5\", \"3\", \"1\", \"4\", \"0\", \"6\", \"8\", \"2\", \"5\", \"8\", \"3\", \"5\", \"2\", \"8\", \"6\", \"6\", \"3\", \"5\", \"7\", \"5\", \"5\", \"3\", \"7\"], \"n\": 27}}, {\"idx\": 2, \"outputs\": 211, \"inputs\": {\"str\": [\"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\"], \"n\": 23}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"str\": [\"f\", \"E\", \"e\", \"z\", \"B\", \"o\", \"i\", \"v\", \"K\", \"u\", \"P\", \"C\", \"z\", \"f\", \"k\", \"J\", \"t\", \"R\", \"t\", \"A\", \"f\", \"G\", \"D\", \"X\", \"H\", \"e\", \"p\", \"l\", \"l\", \"k\", \"Z\", \"Y\", \"u\", \"g\", \"H\", \"C\", \"f\", \"J\", \"H\", \"W\"], \"n\": 27}}, {\"idx\": 4, \"outputs\": 60, \"inputs\": {\"str\": [\"0\", \"0\", \"0\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"2\", \"2\", \"2\", \"3\", \"3\", \"3\", \"3\", \"3\", \"4\", \"4\", \"4\", \"4\", \"4\", \"4\", \"5\", \"5\", \"5\", \"5\", \"6\", \"6\", \"7\", \"7\", \"9\", \"9\", \"9\", \"9\", \"9\", \"9\"], \"n\": 35}}, {\"idx\": 5, \"outputs\": 72, \"inputs\": {\"str\": [\"1\", \"0\", \"1\", \"1\", \"0\", \"0\", \"1\", \"1\", \"1\", \"0\", \"1\", \"0\", \"1\", \"1\", \"0\", \"1\", \"0\", \"1\", \"1\", \"1\", \"1\", \"1\", \"0\", \"1\", \"1\", \"0\", \"1\", \"0\", \"1\", \"1\", \"0\", \"0\", \"1\", \"0\", \"1\", \"0\", \"0\", \"0\", \"0\", \"0\", \"1\", \"1\", \"0\", \"1\", \"0\", \"1\"], \"n\": 43}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"str\": [\"C\", \"C\", \"D\", \"F\", \"L\", \"M\", \"P\", \"X\", \"a\", \"f\", \"i\", \"j\", \"w\"], \"n\": 9}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"str\": [\"7\", \"9\", \"0\", \"2\", \"8\", \"0\", \"7\", \"5\", \"9\", \"4\", \"5\", \"4\", \"8\", \"1\", \"9\", \"5\", \"3\", \"2\", \"4\", \"1\", \"2\"], \"n\": 16}}, {\"idx\": 8, \"outputs\": 289, \"inputs\": {\"str\": [\"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\"], \"n\": 32}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"str\": [\"m\", \"X\", \"N\", \"M\"], \"n\": 3}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
103 | Count Palindromic Subsequence Given String | C++ | int countPalindromicSubsequenceGivenString(string str) { | [
"str"
] | def count_palindromic_subsequence_given_string(str):
N = len(str)
cps = [[0 for i in range((N + 2))] for j in range((N + 2))]
for i in range(N):
cps[i][i] = 1
for L in range(2, (N + 1)):
for i in range(N):
k = ((L + i) - 1)
if (k < N):
if (str[i] == str[k]):
cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) + 1)
else:
cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) - cps[(i + 1)][(k - 1)])
return cps[0][(N - 1)] | int count_palindromic_subsequence_given_string(string str) {
int N = str . length ( );
int cps [ N + 1 ] [ N + 1 ];
memset ( cps, 0, sizeof ( cps ) );
for ( int i = 0;
i < N;
i ++ ) cps [ i ] [ i ] = 1;
for ( int L = 2;
L <= N;
L ++ ) {
for ( int i = 0;
i < N;
i ++ ) {
int k = L + i - 1;
if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1;
else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ];
}
}
return cps [ 0 ] [ N - 1 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string str, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"R\", 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2956350\", 10); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11100111110101\", 2798); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"TZTDLIIfAD\", 20); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"98\", 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1100100001\", 270); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"oKwGeatf\", 8); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"19\", 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00010110100\", 563); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Cyq\", 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPalindromicSubsequenceGivenString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"str\": \"R\"}}, {\"idx\": 1, \"outputs\": 10, \"inputs\": {\"str\": \"2956350\"}}, {\"idx\": 2, \"outputs\": 2798, \"inputs\": {\"str\": \"11100111110101\"}}, {\"idx\": 3, \"outputs\": 20, \"inputs\": {\"str\": \"TZTDLIIfAD\"}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"str\": \"98\"}}, {\"idx\": 5, \"outputs\": 270, \"inputs\": {\"str\": \"1100100001\"}}, {\"idx\": 6, \"outputs\": 8, \"inputs\": {\"str\": \"oKwGeatf\"}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"str\": \"19\"}}, {\"idx\": 8, \"outputs\": 563, \"inputs\": {\"str\": \"00010110100\"}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"str\": \"Cyq\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
104 | Count Possible Groups Size 2 3 Sum Multiple 3 | C++ | float countPossibleGroupsSize23SumMultiple3(vector<int> arr, int n) { | [
"arr",
"n"
] | def count_possible_groups_size_2_3_sum_multiple_3(arr, n):
c = [0, 0, 0]
res = 0
for i in range(0, n):
c[(arr[i] % 3)] += 1
res += ((c[0] * (c[0] - 1)) >> 1)
res += (c[1] * c[2])
res += (((c[0] * (c[0] - 1)) * (c[0] - 2)) / 6)
res += (((c[1] * (c[1] - 1)) * (c[1] - 2)) / 6)
res += (((c[2] * (c[2] - 1)) * (c[2] - 2)) / 6)
res += ((c[0] * c[1]) * c[2])
return res | int count_possible_groups_size_2_3_sum_multiple_3(vector<int> arr, int n) {
int c [ 3 ] = {
0 },
i;
int res = 0;
for ( i = 0;
i < n;
i ++ ) c [ arr [ i ] % 3 ] ++;
res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 );
res += c [ 1 ] * c [ 2 ];
res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6;
res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6;
res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 );
res += c [ 0 ] * c [ 1 ] * c [ 2 ];
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(vector<int> arr, int n, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 3, 6, 12, 18, 31, 36, 43, 47, 59, 64, 64, 69, 69, 94, 98, 98}, 12, 90.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 46, 64, 18, 70, 22, -98, 52, -26, 34, -22, 22, 40, 66, -72, -66, 86, 84, 12, -38, 28, -60, -10, -30, -78, 76, 62, 74, 24, -64, 0, 92, -20, -66, -52}, 23, 655.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, 3276.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, 96, 74, 38, 70, 70}, 5, 7.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -74, -70, -64, -64, -64, -58, -52, -18, -10, -6, 4, 4, 28, 44, 48, 52, 54, 64, 72, 76, 94}, 18, 329.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1}, 36, 2310.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9, 12, 14, 21, 27, 28, 45, 50, 54, 57, 58, 62, 78, 82, 91, 92, 95}, 9, 49.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, -46, -32, -36, -84, -14, -18, 16, 54, 90, -4}, 8, 24.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1}, 3, 1.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({53, 32, 54, 84, 79, 37, 44, 30, 92, 53, 89, 95}, 8, 29.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPossibleGroupsSize23SumMultiple3",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 90.0, \"inputs\": {\"arr\": [1, 3, 6, 12, 18, 31, 36, 43, 47, 59, 64, 64, 69, 69, 94, 98, 98], \"n\": 12}}, {\"idx\": 1, \"outputs\": 655.0, \"inputs\": {\"arr\": [94, 46, 64, 18, 70, 22, -98, 52, -26, 34, -22, 22, 40, 66, -72, -66, 86, 84, 12, -38, 28, -60, -10, -30, -78, 76, 62, 74, 24, -64, 0, 92, -20, -66, -52], \"n\": 23}}, {\"idx\": 2, \"outputs\": 3276.0, \"inputs\": {\"arr\": [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, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29}}, {\"idx\": 3, \"outputs\": 7.0, \"inputs\": {\"arr\": [68, 96, 74, 38, 70, 70], \"n\": 5}}, {\"idx\": 4, \"outputs\": 329.0, \"inputs\": {\"arr\": [-88, -74, -70, -64, -64, -64, -58, -52, -18, -10, -6, 4, 4, 28, 44, 48, 52, 54, 64, 72, 76, 94], \"n\": 18}}, {\"idx\": 5, \"outputs\": 2310.0, \"inputs\": {\"arr\": [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1], \"n\": 36}}, {\"idx\": 6, \"outputs\": 49.0, \"inputs\": {\"arr\": [9, 12, 14, 21, 27, 28, 45, 50, 54, 57, 58, 62, 78, 82, 91, 92, 95], \"n\": 9}}, {\"idx\": 7, \"outputs\": 24.0, \"inputs\": {\"arr\": [16, -46, -32, -36, -84, -14, -18, 16, 54, 90, -4], \"n\": 8}}, {\"idx\": 8, \"outputs\": 1.0, \"inputs\": {\"arr\": [0, 0, 1, 1], \"n\": 3}}, {\"idx\": 9, \"outputs\": 29.0, \"inputs\": {\"arr\": [53, 32, 54, 84, 79, 37, 44, 30, 92, 53, 89, 95], \"n\": 8}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
105 | Count Possible Paths Top Left Bottom Right Nxm Matrix 2 | C++ | long long countPossiblePathsTopLeftBottomRightNxmMatrix2(int p, int q) { | [
"p",
"q"
] | def count_possible_paths_top_left_bottom_right_nxm_matrix_2(p, q):
dp = [1 for i in range(q)]
for i in range((p - 1)):
for j in range(1, q):
dp[j] += dp[(j - 1)]
return dp[(q - 1)] | int count_possible_paths_top_left_bottom_right_nxm_matrix_2(int m, int n) {
int dp [ n ] = {
1 };
dp [ 0 ] = 1;
for ( int i = 0;
i < m;
i ++ ) {
for ( int j = 1;
j < n;
j ++ ) {
dp [ j ] += dp [ j - 1 ];
}
}
return dp [ n - 1 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int p, int q, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(p, q), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(70, 5, 1088430); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 59, 5743572120); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 1, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPossiblePathsTopLeftBottomRightNxmMatrix2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1088430, \"inputs\": {\"p\": 70, \"q\": 5}}, {\"idx\": 1, \"outputs\": 5743572120, \"inputs\": {\"p\": 9, \"q\": 59}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"p\": 54, \"q\": 1}}]",
"test_case_ids": [
"0",
"1",
"2"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
106 | Count Possible Ways To Construct Buildings | C++ | long long countPossibleWaysToConstructBuildings(int n) { | [
"n"
] | def count_possible_ways_to_construct_buildings(N):
if (N == 1):
return 4
countB = 1
countS = 1
for i in range(2, (N + 1)):
prev_countB = countB
prev_countS = countS
countS = (prev_countB + prev_countS)
countB = prev_countS
result = (countS + countB)
return (result * result) | int count_possible_ways_to_construct_buildings(int N) {
if ( N == 1 ) return 4;
int countB = 1, countS = 1, prev_countB, prev_countS;
for ( int i = 2;
i <= N;
i ++ ) {
prev_countB = countB;
prev_countS = countS;
countS = prev_countB + prev_countS;
countB = prev_countS;
}
int result = countS + countB;
return ( result * result );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(17, 17480761); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 222915410843904); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 7921); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "countPossibleWaysToConstructBuildings",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 17480761, \"inputs\": {\"n\": 17}}, {\"idx\": 1, \"outputs\": 222915410843904, \"inputs\": {\"n\": 34}}, {\"idx\": 2, \"outputs\": 7921, \"inputs\": {\"n\": 9}}]",
"test_case_ids": [
"0",
"1",
"2"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |