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 |
---|---|---|---|---|---|---|---|
425 | Primality Test Set 1 Introduction And School Method 1 | C++ | bool primalityTestSet1IntroductionAndSchoolMethod1(int n) { | [
"n"
] | def primality_test_set_1_introduction_and_school_method_1(n):
if (n <= 1):
return False
if (n <= 3):
return True
if (((n % 2) == 0) or ((n % 3) == 0)):
return False
i = 5
while ((i * i) <= n):
if (((n % i) == 0) or ((n % (i + 2)) == 0)):
return False
i = (i + 6)
return True | bool primality_test_set_1_introduction_and_school_method_1(int n) {
if ( n <= 1 ) return false;
if ( n <= 3 ) return true;
if ( n % 2 == 0 || n % 3 == 0 ) return false;
for ( int i = 5;
i * i <= n;
i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) 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(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(15, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "primalityTestSet1IntroductionAndSchoolMethod1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"n\": 15}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"n\": 90}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"n\": 38}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": 65}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 91}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 16}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 48}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 74}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 14}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"n\": 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
]
} |
426 | Primality Test Set 5Using Lucas Lehmer Series | C++ | bool primalityTestSet5UsingLucasLehmerSeries(int p) { | [
"p"
] | def primality_test_set_5using_lucas_lehmer_series(p):
checkNumber = ((2 ** p) - 1)
nextval = (4 % checkNumber)
for i in range(1, (p - 1)):
nextval = (((nextval * nextval) - 2) % checkNumber)
if (nextval == 0):
return True
else:
return False | bool primality_test_set_5using_lucas_lehmer_series(int p) {
long long checkNumber = pow ( 2, p ) - 1;
long long nextval = 4 % checkNumber;
for ( int i = 1;
i < p - 1;
i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber;
return ( nextval == 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 p, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(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(11, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 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(72, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "primalityTestSet5UsingLucasLehmerSeries",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"p\": 11}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"p\": 27}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"p\": 31}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"p\": 47}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"p\": 3}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"p\": 14}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"p\": 41}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"p\": 72}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"p\": 39}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"p\": 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
]
} |
427 | Prime Numbers | C++ | bool primeNumbers(int n) { | [
"n"
] | def prime_numbers(n):
if (n <= 1):
return False
for i in range(2, n):
if ((n % i) == 0):
return False
return True | bool prime_numbers(int n) {
if ( n <= 1 ) return false;
for ( int i = 2;
i < n;
i ++ ) if ( n % i == 0 ) 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(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(2, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, false); \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(31, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "primeNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 2}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"n\": 74}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"n\": 46}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": 38}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 51}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 48}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 6}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 14}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"n\": 31}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"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
]
} |
428 | Print Maximum Shortest Distance | C++ | long long printMaximumShortestDistance(vector<int> a, int n, int k) { | [
"a",
"n",
"k"
] | def print_maximum_shortest_distance(a, n, k):
b = dict()
for i in range(n):
x = a[i]
d = min((1 + i), (n - i))
if (x not in b.keys()):
b[x] = d
else:
b[x] = min(d, b[x])
ans = (10 ** 9)
for i in range(n):
x = a[i]
if ((x != (k - x)) and ((k - x) in b.keys())):
ans = min(max(b[x], b[(k - x)]), ans)
return ans | int print_maximum_shortest_distance(vector<int> a, int n, int k) {
unordered_map < int, int > b;
for ( int i = 0;
i < n;
i ++ ) {
int x = a [ i ];
int d = min ( 1 + i, n - i );
if ( b . find ( x ) == b . end ( ) ) b [ x ] = d;
else b [ x ] = min ( d, b [ x ] );
}
int ans = INT_MAX;
for ( int i = 0;
i < n;
i ++ ) {
int x = a [ i ];
if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ], b [ k - x ] ), 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(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int n, int k, long long 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, 27, 66, 89, 96, 96}, 4, 4, 1000000000); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({84, -38, -56, -20, -98, -40, -16, 22, 20, 98, -56, -32, -44, 30, -58, 26, -44, -32, 50, 46, 92}, 13, 11, 1000000000); \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, 1, 1}, 23, 13, 1000000000); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, 71, 66, 58, 74, 2, 63, 13, 1, 36, 28, 83, 24, 20, 85, 30, 59, 56, 8, 97, 58, 28, 28, 42}, 23, 17, 1000000000); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -88, -86, -68, -66, -64, -28, -12, 4, 18, 22, 28, 32, 34, 34, 40, 44, 46, 60, 68, 72, 78, 80, 84, 88, 96}, 16, 15, 1000000000); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1}, 8, 13, 1000000000); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 13, 54, 59, 61, 69, 89, 90, 92}, 4, 8, 1000000000); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-58, 50, -74, -8, -50, 90, 90, -2, -22, 8, -76, 16, 4, 56, 94, 36, 28, -42, 80, -88, 88, 52, 74, 40, 12, -72, -50, 50, 88, -54, 32, -24, -48, -66, -86, 40, -6, 14, 10, -88, 56, 80, -34}, 27, 42, 4); \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}, 9, 12, 1000000000); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 60, 66, 39, 18, 60, 37, 75, 3, 64, 24, 16, 72, 95, 96, 44, 23, 58, 58, 33, 24, 96}, 21, 17, 1000000000); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "printMaximumShortestDistance",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1000000000, \"inputs\": {\"a\": [2, 27, 66, 89, 96, 96], \"n\": 4, \"k\": 4}}, {\"idx\": 1, \"outputs\": 1000000000, \"inputs\": {\"a\": [84, -38, -56, -20, -98, -40, -16, 22, 20, 98, -56, -32, -44, 30, -58, 26, -44, -32, 50, 46, 92], \"n\": 13, \"k\": 11}}, {\"idx\": 2, \"outputs\": 1000000000, \"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], \"n\": 23, \"k\": 13}}, {\"idx\": 3, \"outputs\": 1000000000, \"inputs\": {\"a\": [20, 71, 66, 58, 74, 2, 63, 13, 1, 36, 28, 83, 24, 20, 85, 30, 59, 56, 8, 97, 58, 28, 28, 42], \"n\": 23, \"k\": 17}}, {\"idx\": 4, \"outputs\": 1000000000, \"inputs\": {\"a\": [-94, -88, -86, -68, -66, -64, -28, -12, 4, 18, 22, 28, 32, 34, 34, 40, 44, 46, 60, 68, 72, 78, 80, 84, 88, 96], \"n\": 16, \"k\": 15}}, {\"idx\": 5, \"outputs\": 1000000000, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1], \"n\": 8, \"k\": 13}}, {\"idx\": 6, \"outputs\": 1000000000, \"inputs\": {\"a\": [8, 13, 54, 59, 61, 69, 89, 90, 92], \"n\": 4, \"k\": 8}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"a\": [-58, 50, -74, -8, -50, 90, 90, -2, -22, 8, -76, 16, 4, 56, 94, 36, 28, -42, 80, -88, 88, 52, 74, 40, 12, -72, -50, 50, 88, -54, 32, -24, -48, -66, -86, 40, -6, 14, 10, -88, 56, 80, -34], \"n\": 27, \"k\": 42}}, {\"idx\": 8, \"outputs\": 1000000000, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 9, \"k\": 12}}, {\"idx\": 9, \"outputs\": 1000000000, \"inputs\": {\"a\": [2, 60, 66, 39, 18, 60, 37, 75, 3, 64, 24, 16, 72, 95, 96, 44, 23, 58, 58, 33, 24, 96], \"n\": 21, \"k\": 17}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
429 | Print Words String Reverse Order | C++ | string printWordsStringReverseOrder(string str) { | [
"str"
] | def print_words_string_reverse_order(str):
i = (len(str) - 1)
start = end = (i + 1)
result = ''
while (i >= 0):
if (str[i] == ' '):
start = (i + 1)
while (start != end):
result += str[start]
start += 1
result += ' '
end = i
i -= 1
start = 0
while (start != end):
result += str[start]
start += 1
return result | string print_words_string_reverse_order(string str) {
int i = str . length ( ) - 1;
int start, end = i + 1;
string result = "";
while ( i >= 0 ) {
if ( str [ i ] == ' ' ) {
start = i + 1;
while ( start != end ) result += str [ start ++ ];
result += ' ';
end = i;
}
i --;
}
start = 0;
while ( start != end ) result += str [ start ++ ];
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(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string str, string 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(\"m Dm YZ\", \"YZ Dm m\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"65 48 57 71\", \"71 57 48 65\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01 010\", \"010 01\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"mT vhByi\", \"vhByi mT\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"19 44 9 1\", \"1 9 44 19\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0\", \"0\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"z vUi \", \" vUi z\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"7 591 36643 9 055\", \"055 9 36643 591 7\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01\", \"01\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ti YGaijPY\", \"YGaijPY ti\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "printWordsStringReverseOrder",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": \"YZ Dm m\", \"inputs\": {\"str\": \"m Dm YZ\"}}, {\"idx\": 1, \"outputs\": \"71 57 48 65\", \"inputs\": {\"str\": \"65 48 57 71\"}}, {\"idx\": 2, \"outputs\": \"010 01\", \"inputs\": {\"str\": \"01 010\"}}, {\"idx\": 3, \"outputs\": \"vhByi mT\", \"inputs\": {\"str\": \"mT vhByi\"}}, {\"idx\": 4, \"outputs\": \"1 9 44 19\", \"inputs\": {\"str\": \"19 44 9 1\"}}, {\"idx\": 5, \"outputs\": \"0\", \"inputs\": {\"str\": \"0\"}}, {\"idx\": 6, \"outputs\": \" vUi z\", \"inputs\": {\"str\": \"z vUi \"}}, {\"idx\": 7, \"outputs\": \"055 9 36643 591 7\", \"inputs\": {\"str\": \"7 591 36643 9 055\"}}, {\"idx\": 8, \"outputs\": \"01\", \"inputs\": {\"str\": \"01\"}}, {\"idx\": 9, \"outputs\": \"YGaijPY ti\", \"inputs\": {\"str\": \"ti YGaijPY\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
430 | Probability Three Randomly Chosen Numbers Ap | C++ | double probabilityThreeRandomlyChosenNumbersAp(int n) { | [
"n"
] | def probability_three_randomly_chosen_numbers_ap(n):
return ((3.0 * n) / ((4.0 * (n * n)) - 1)) | double probability_three_randomly_chosen_numbers_ap(int n) {
return ( 3.0 * n ) / ( 4.0 * ( n * 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(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(46, 0.0163062743707905); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 0.15151515151515152); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 0.017047655947307245); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 0.05005561735261402); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 0.010417169037858692); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 0.4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 0.008721225027887637); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 0.04415584415584416); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 0.025006946373992776); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 0.01785967399007796); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "probabilityThreeRandomlyChosenNumbersAp",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0.0163062743707905, \"inputs\": {\"n\": 46}}, {\"idx\": 1, \"outputs\": 0.15151515151515152, \"inputs\": {\"n\": 5}}, {\"idx\": 2, \"outputs\": 0.017047655947307245, \"inputs\": {\"n\": 44}}, {\"idx\": 3, \"outputs\": 0.05005561735261402, \"inputs\": {\"n\": 15}}, {\"idx\": 4, \"outputs\": 0.010417169037858692, \"inputs\": {\"n\": 72}}, {\"idx\": 5, \"outputs\": 0.4, \"inputs\": {\"n\": 2}}, {\"idx\": 6, \"outputs\": 0.008721225027887637, \"inputs\": {\"n\": 86}}, {\"idx\": 7, \"outputs\": 0.04415584415584416, \"inputs\": {\"n\": 17}}, {\"idx\": 8, \"outputs\": 0.025006946373992776, \"inputs\": {\"n\": 30}}, {\"idx\": 9, \"outputs\": 0.01785967399007796, \"inputs\": {\"n\": 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
]
} |
431 | Product Nodes K Th Level Tree Represented String | C++ | int productNodesKThLevelTreeRepresentedString(string tree, int k) { | [
"tree",
"k"
] | def product_nodes_k_th_level_tree_represented_string(tree, k):
level = (- 1)
product = 1
n = len(tree)
for i in range(0, n):
if (tree[i] == '('):
level += 1
elif (tree[i] == ')'):
level -= 1
elif (level == k):
product *= (int(tree[i]) - int('0'))
return product | int product_nodes_k_th_level_tree_represented_string(string tree, int k) {
int level = - 1;
int product = 1;
int n = tree . length ( );
for ( int i = 0;
i < n;
i ++ ) {
if ( tree [ i ] == '(' ) level ++;
else if ( tree [ i ] == ')' ) level --;
else {
if ( level == k ) product *= ( tree [ i ] - '0' );
}
}
return product;
} | {
"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 tree, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(tree, 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(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 2, 72); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 3, 15); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 1, 35); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 2, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 4, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 100, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 3, 9); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 0, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0010\", 12, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kjtdgmy\", 97, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "productNodesKThLevelTreeRepresentedString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 72, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 2}}, {\"idx\": 1, \"outputs\": 15, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 3}}, {\"idx\": 2, \"outputs\": 35, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 1}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 2}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 4}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 100}}, {\"idx\": 6, \"outputs\": 9, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 3}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 0}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"tree\": \"0010\", \"k\": 12}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"tree\": \"kjtdgmy\", \"k\": 97}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
432 | Program Area Square | C++ | int programAreaSquare(int side) { | [
"side"
] | def program_area_square(side):
area = (side * side)
return area | int program_area_square(int side) {
int area = side * side;
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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int side, int 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(50, 2500); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 4096); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 8464); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 529); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 1444); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 3025); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 4489); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 3136); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 3600); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 8100); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programAreaSquare",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2500, \"inputs\": {\"side\": 50}}, {\"idx\": 1, \"outputs\": 4096, \"inputs\": {\"side\": 64}}, {\"idx\": 2, \"outputs\": 8464, \"inputs\": {\"side\": 92}}, {\"idx\": 3, \"outputs\": 529, \"inputs\": {\"side\": 23}}, {\"idx\": 4, \"outputs\": 1444, \"inputs\": {\"side\": 38}}, {\"idx\": 5, \"outputs\": 3025, \"inputs\": {\"side\": 55}}, {\"idx\": 6, \"outputs\": 4489, \"inputs\": {\"side\": 67}}, {\"idx\": 7, \"outputs\": 3136, \"inputs\": {\"side\": 56}}, {\"idx\": 8, \"outputs\": 3600, \"inputs\": {\"side\": 60}}, {\"idx\": 9, \"outputs\": 8100, \"inputs\": {\"side\": 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
]
} |
433 | Program Binary Decimal Conversion | C++ | int programBinaryDecimalConversion(int n) { | [
"n"
] | def program_binary_decimal_conversion(n):
num = n
dec_value = 0
base = 1
temp = num
while temp:
last_digit = (temp % 10)
temp = int((temp / 10))
dec_value += (last_digit * base)
base = (base * 2)
return dec_value | int program_binary_decimal_conversion(int n) {
int num = n;
int dec_value = 0;
int base = 1;
int temp = num;
while ( temp ) {
int last_digit = temp % 10;
temp = temp / 10;
dec_value += last_digit * base;
base = base * 2;
}
return dec_value;
} | {
"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(70, 14); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 23); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 9); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 25); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 8); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 9); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 17); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 17); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 22); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programBinaryDecimalConversion",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 14, \"inputs\": {\"n\": 70}}, {\"idx\": 1, \"outputs\": 23, \"inputs\": {\"n\": 95}}, {\"idx\": 2, \"outputs\": 9, \"inputs\": {\"n\": 41}}, {\"idx\": 3, \"outputs\": 25, \"inputs\": {\"n\": 97}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"n\": 8}}, {\"idx\": 5, \"outputs\": 8, \"inputs\": {\"n\": 16}}, {\"idx\": 6, \"outputs\": 9, \"inputs\": {\"n\": 41}}, {\"idx\": 7, \"outputs\": 17, \"inputs\": {\"n\": 57}}, {\"idx\": 8, \"outputs\": 17, \"inputs\": {\"n\": 81}}, {\"idx\": 9, \"outputs\": 22, \"inputs\": {\"n\": 78}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
434 | Program Binary Decimal Conversion 1 | C++ | int programBinaryDecimalConversion1(string n) { | [
"n"
] | def program_binary_decimal_conversion_1(n):
num = n
dec_value = 0
base1 = 1
len1 = len(num)
for i in range((len1 - 1), (- 1), (- 1)):
if (num[i] == '1'):
dec_value += base1
base1 = (base1 * 2)
return dec_value | int program_binary_decimal_conversion_1(string n) {
string num = n;
int dec_value = 0;
int base = 1;
int len = num . length ( );
for ( int i = len - 1;
i >= 0;
i -- ) {
if ( num [ i ] == '1' ) dec_value += base;
base = base * 2;
}
return dec_value;
} | {
"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(\"uEmIAgF\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"753310137\", 20); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"010011010\", 154); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kNi\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"04562016903312\", 130); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000111101\", 61); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"bk\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"9\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"XxT nXLlk\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programBinaryDecimalConversion1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": \"uEmIAgF\"}}, {\"idx\": 1, \"outputs\": 20, \"inputs\": {\"n\": \"753310137\"}}, {\"idx\": 2, \"outputs\": 154, \"inputs\": {\"n\": \"010011010\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": \"kNi\"}}, {\"idx\": 4, \"outputs\": 130, \"inputs\": {\"n\": \"04562016903312\"}}, {\"idx\": 5, \"outputs\": 61, \"inputs\": {\"n\": \"000111101\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": \"bk\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": \"9\"}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"n\": \"1\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"n\": \"XxT nXLlk\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
435 | Program Calculate Area Octagon | C++ | double programCalculateAreaOctagon(double side) { | [
"side"
] | def program_calculate_area_octagon(side):
return (((2 * (1 + math.sqrt(2))) * side) * side) | double program_calculate_area_octagon(double side) {
return ( float ) ( 2 * ( 1 + sqrt ( 2 ) ) * side * side );
} | {
"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 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(5859.798616323926, 165794860.15449765); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6381.210375893524, 196612808.27272156); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2442.246292006922, 28799476.852711495); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-9624.81536339737, 447291345.3087225); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8679.436805247444, 363738081.5089271); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-2682.3245401089525, 34739881.027797274); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7216.9161613024435, 251483213.5426547); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-5881.789859815442, 167041618.6125096); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2497.776395789202, 30124010.84898392); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-9598.912195459263, 444887003.7391194); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCalculateAreaOctagon",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 165794860.15449765, \"inputs\": {\"side\": 5859.798616323926}}, {\"idx\": 1, \"outputs\": 196612808.27272156, \"inputs\": {\"side\": -6381.210375893524}}, {\"idx\": 2, \"outputs\": 28799476.852711495, \"inputs\": {\"side\": 2442.246292006922}}, {\"idx\": 3, \"outputs\": 447291345.3087225, \"inputs\": {\"side\": -9624.81536339737}}, {\"idx\": 4, \"outputs\": 363738081.5089271, \"inputs\": {\"side\": 8679.436805247444}}, {\"idx\": 5, \"outputs\": 34739881.027797274, \"inputs\": {\"side\": -2682.3245401089525}}, {\"idx\": 6, \"outputs\": 251483213.5426547, \"inputs\": {\"side\": 7216.9161613024435}}, {\"idx\": 7, \"outputs\": 167041618.6125096, \"inputs\": {\"side\": -5881.789859815442}}, {\"idx\": 8, \"outputs\": 30124010.84898392, \"inputs\": {\"side\": 2497.776395789202}}, {\"idx\": 9, \"outputs\": 444887003.7391194, \"inputs\": {\"side\": -9598.912195459263}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
436 | Program Calculate Volume Ellipsoid | C++ | double programCalculateVolumeEllipsoid(double r1, double r2, double r3) { | [
"r1",
"r2",
"r3"
] | def program_calculate_volume_ellipsoid(r1, r2, r3):
return ((((1.33 * math.pi) * r1) * r2) * r3) | float program_calculate_volume_ellipsoid(float r1, float r2, float r3) {
float pi = 3.14;
return 1.33 * pi * r1 * r2 * r3;
} | {
"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 r1, double r2, double r3, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(r1, r2, r3), 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(3287.4842316041018, 4503.332888443404, 8590.24729914204, 531379639833.05774); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-3707.427510963942, -6671.335781753231, -2780.4954870801926, -287348660250.6971); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8980.643174783816, 3584.781688607942, 2818.469507143102, 379127256148.80035); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-2698.0187368852694, -1004.7289573934537, -9602.530725071243, -108762980362.90225); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8627.156664162168, 9572.27618966978, 4783.930377855004, 1650704251171.7974); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7316.329924623669, -6591.043206581106, -9760.465488363216, -1966615618344.9363); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7857.3846206400485, 3671.761679299217, 2534.5825334137794, 305534635263.3107); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6502.657905007728, -1412.2240121470609, -6135.238350044512, -235411379188.32523); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4468.400513325576, 2272.1999139470304, 4753.075799180736, 201639162973.6474); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7231.864791620428, -8036.087711033032, -6456.263512521035, -1567753314543.6833); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCalculateVolumeEllipsoid",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 531379639833.05774, \"inputs\": {\"r1\": 3287.4842316041018, \"r2\": 4503.332888443404, \"r3\": 8590.24729914204}}, {\"idx\": 1, \"outputs\": -287348660250.6971, \"inputs\": {\"r1\": -3707.427510963942, \"r2\": -6671.335781753231, \"r3\": -2780.4954870801926}}, {\"idx\": 2, \"outputs\": 379127256148.80035, \"inputs\": {\"r1\": 8980.643174783816, \"r2\": 3584.781688607942, \"r3\": 2818.469507143102}}, {\"idx\": 3, \"outputs\": -108762980362.90225, \"inputs\": {\"r1\": -2698.0187368852694, \"r2\": -1004.7289573934537, \"r3\": -9602.530725071243}}, {\"idx\": 4, \"outputs\": 1650704251171.7974, \"inputs\": {\"r1\": 8627.156664162168, \"r2\": 9572.27618966978, \"r3\": 4783.930377855004}}, {\"idx\": 5, \"outputs\": -1966615618344.9363, \"inputs\": {\"r1\": -7316.329924623669, \"r2\": -6591.043206581106, \"r3\": -9760.465488363216}}, {\"idx\": 6, \"outputs\": 305534635263.3107, \"inputs\": {\"r1\": 7857.3846206400485, \"r2\": 3671.761679299217, \"r3\": 2534.5825334137794}}, {\"idx\": 7, \"outputs\": -235411379188.32523, \"inputs\": {\"r1\": -6502.657905007728, \"r2\": -1412.2240121470609, \"r3\": -6135.238350044512}}, {\"idx\": 8, \"outputs\": 201639162973.6474, \"inputs\": {\"r1\": 4468.400513325576, \"r2\": 2272.1999139470304, \"r3\": 4753.075799180736}}, {\"idx\": 9, \"outputs\": -1567753314543.6833, \"inputs\": {\"r1\": -7231.864791620428, \"r2\": -8036.087711033032, \"r3\": -6456.263512521035}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
437 | Program Calculate Volume Octahedron | C++ | double programCalculateVolumeOctahedron(double side) { | [
"side"
] | def program_calculate_volume_octahedron(side):
return (((side * side) * side) * (math.sqrt(2) / 3)) | double program_calculate_volume_octahedron(double side) {
return ( ( side * side * side ) * ( sqrt ( 2 ) / 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(double 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(3355.322051344013, 17807230335.375374); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-891.0551553192736, -333508958.9649689); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8242.699647177868, 263998930936.71603); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-9259.146104439229, -374202387762.81836); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7712.806145993083, 216287285897.3415); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-4998.858862079315, -58885228987.99368); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9771.127582524628, 439772223071.1617); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-5415.8106399098115, -74883158892.28471); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(670.0774772280249, 141830229.25431916); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7068.634369272122, -166494655500.3635); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCalculateVolumeOctahedron",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 17807230335.375374, \"inputs\": {\"side\": 3355.322051344013}}, {\"idx\": 1, \"outputs\": -333508958.9649689, \"inputs\": {\"side\": -891.0551553192736}}, {\"idx\": 2, \"outputs\": 263998930936.71603, \"inputs\": {\"side\": 8242.699647177868}}, {\"idx\": 3, \"outputs\": -374202387762.81836, \"inputs\": {\"side\": -9259.146104439229}}, {\"idx\": 4, \"outputs\": 216287285897.3415, \"inputs\": {\"side\": 7712.806145993083}}, {\"idx\": 5, \"outputs\": -58885228987.99368, \"inputs\": {\"side\": -4998.858862079315}}, {\"idx\": 6, \"outputs\": 439772223071.1617, \"inputs\": {\"side\": 9771.127582524628}}, {\"idx\": 7, \"outputs\": -74883158892.28471, \"inputs\": {\"side\": -5415.8106399098115}}, {\"idx\": 8, \"outputs\": 141830229.25431916, \"inputs\": {\"side\": 670.0774772280249}}, {\"idx\": 9, \"outputs\": -166494655500.3635, \"inputs\": {\"side\": -7068.634369272122}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
438 | Program Check Array Sorted Not Iterative Recursive 1 | C++ | bool programCheckArraySortedNotIterativeRecursive1(vector<int> arr, int n) { | [
"arr",
"n"
] | def program_check_array_sorted_not_iterative_recursive_1(arr, n):
if ((n == 0) or (n == 1)):
return True
for i in range(1, n):
if (arr[(i - 1)] > arr[i]):
return False
return True | bool program_check_array_sorted_not_iterative_recursive_1(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({6, 8, 8, 16, 19, 19, 21, 23, 26, 33, 34, 36, 38, 39, 41, 41, 45, 47, 52, 52, 55, 57, 60, 60, 60, 61, 69, 69, 70, 70, 72, 73, 73, 75, 78, 81, 84, 84, 85, 88, 88, 89, 90, 91, 97}, 22, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, -90, 66, 24, -18, 70, 34, 18, 84, -62}, 9, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1}, 1, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, 88, 65, 82, 23, 39, 60, 27, 57, 44, 70, 28, 23, 34, 25, 11, 48, 65, 10, 73, 26, 10, 18, 60, 73, 45, 26, 9, 36, 15, 24, 40, 2, 4, 95, 20, 39, 45}, 23, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-38, 38, 40, 72}, 2, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 1}, 3, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 15, 16, 17, 17, 17, 22, 23, 23, 25, 27, 28, 28, 31, 33, 36, 38, 40, 42, 44, 46, 49, 51, 51, 52, 60, 62, 65, 67, 71, 74, 77, 77, 78, 78, 79, 83, 83, 86, 86, 87, 87, 87, 88, 91, 92, 97, 97, 97}, 44, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-26, -90, -78, -76, -58, -64, -72, -34, -58, -48, 78, -50, -30, 26, -60, 26}, 9, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 23, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({56, 51, 63, 30, 10, 88, 23, 1, 48, 4, 28, 44}, 10, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCheckArraySortedNotIterativeRecursive1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"arr\": [6, 8, 8, 16, 19, 19, 21, 23, 26, 33, 34, 36, 38, 39, 41, 41, 45, 47, 52, 52, 55, 57, 60, 60, 60, 61, 69, 69, 70, 70, 72, 73, 73, 75, 78, 81, 84, 84, 85, 88, 88, 89, 90, 91, 97], \"n\": 22}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [2, -90, 66, 24, -18, 70, 34, 18, 84, -62], \"n\": 9}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"arr\": [1, 1], \"n\": 1}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"arr\": [12, 88, 65, 82, 23, 39, 60, 27, 57, 44, 70, 28, 23, 34, 25, 11, 48, 65, 10, 73, 26, 10, 18, 60, 73, 45, 26, 9, 36, 15, 24, 40, 2, 4, 95, 20, 39, 45], \"n\": 23}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-38, 38, 40, 72], \"n\": 2}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [1, 0, 0, 0, 1], \"n\": 3}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"arr\": [11, 15, 16, 17, 17, 17, 22, 23, 23, 25, 27, 28, 28, 31, 33, 36, 38, 40, 42, 44, 46, 49, 51, 51, 52, 60, 62, 65, 67, 71, 74, 77, 77, 78, 78, 79, 83, 83, 86, 86, 87, 87, 87, 88, 91, 92, 97, 97, 97], \"n\": 44}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [-26, -90, -78, -76, -58, -64, -72, -34, -58, -48, 78, -50, -30, 26, -60, 26], \"n\": 9}}, {\"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, 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\": 9, \"outputs\": false, \"inputs\": {\"arr\": [56, 51, 63, 30, 10, 88, 23, 1, 48, 4, 28, 44], \"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
]
} |
439 | Program Check Input Integer String | C++ | bool programCheckInputIntegerString(string s) { | [
"s"
] | def program_check_input_integer_string(s):
for i in range(len(s)):
if (s[i].isdigit() != True):
return False
return True | bool program_check_input_integer_string(string s) {
for ( int i = 0;
i < s . length ( );
i ++ ) if ( isdigit ( s [ 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(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(\"MgTOyHo NT\", false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"033675175\", true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011001\", true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"XLlccG\", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"8223900094410\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000\", true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aupp\", false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"90202721499\", true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"110000100011\", true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"MhYHsMQeLhG\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCheckInputIntegerString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"s\": \"MgTOyHo NT\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"s\": \"033675175\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"s\": \"011001\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"s\": \"XLlccG\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"s\": \"8223900094410\"}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"s\": \"000\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"s\": \"aupp\"}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"s\": \"90202721499\"}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"s\": \"110000100011\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"s\": \"MhYHsMQeLhG\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
440 | Program Check Plus Perfect Number | C++ | bool programCheckPlusPerfectNumber(int x) { | [
"x"
] | def program_check_plus_perfect_number(x):
temp = x
n = 0
while (x != 0):
x = (x // 10)
n = (n + 1)
x = temp
sm = 0
while (x != 0):
sm = (sm + int(math.pow((x % 10), n)))
x = (x // 10)
return (sm == temp) | bool program_check_plus_perfect_number(int x) {
int temp = x;
int n = 0;
while ( x != 0 ) {
x /= 10;
n ++;
}
x = temp;
int sum = 0;
while ( x != 0 ) {
sum += pow ( x % 10, n );
x /= 10;
}
return ( sum == temp );
} | {
"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, bool 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(371, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9474, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCheckPlusPerfectNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"x\": 371}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"x\": 9474}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"x\": 85}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"x\": 35}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"x\": 54}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"x\": 17}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"x\": 97}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"x\": 63}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"x\": 12}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"x\": 43}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
441 | Program Circumference Parallelogram | C++ | double programCircumferenceParallelogram(double a, double b) { | [
"a",
"b"
] | def program_circumference_parallelogram(a, b):
return ((2 * a) + (2 * b)) | float program_circumference_parallelogram(float a, float b) {
return ( ( 2 * a ) + ( 2 * b ) );
} | {
"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 a, double b, double 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(801.0366882228715, 456.71190645582783, 2515.4971893573984); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7069.610056819919, -4226.483870778477, -22592.18785519679); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7723.966966568705, 5894.65405158763, 27237.242036312673); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7935.859205856963, -5333.225064296693, -26538.168540307313); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6094.247432557289, 1660.420120702062, 15509.335106518702); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7371.490363309265, -1095.4543576847332, -16933.889441987998); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8368.473889617526, 4735.838330834498, 26208.62444090405); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-3761.921143166053, -5315.871691690649, -18155.585669713404); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3139.1089185587884, 6490.194159517967, 19258.60615615351); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-5218.286665567171, -8265.153014320813, -26966.87935977597); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCircumferenceParallelogram",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2515.4971893573984, \"inputs\": {\"a\": 801.0366882228715, \"b\": 456.71190645582783}}, {\"idx\": 1, \"outputs\": -22592.18785519679, \"inputs\": {\"a\": -7069.610056819919, \"b\": -4226.483870778477}}, {\"idx\": 2, \"outputs\": 27237.242036312673, \"inputs\": {\"a\": 7723.966966568705, \"b\": 5894.65405158763}}, {\"idx\": 3, \"outputs\": -26538.168540307313, \"inputs\": {\"a\": -7935.859205856963, \"b\": -5333.225064296693}}, {\"idx\": 4, \"outputs\": 15509.335106518702, \"inputs\": {\"a\": 6094.247432557289, \"b\": 1660.420120702062}}, {\"idx\": 5, \"outputs\": -16933.889441987998, \"inputs\": {\"a\": -7371.490363309265, \"b\": -1095.4543576847332}}, {\"idx\": 6, \"outputs\": 26208.62444090405, \"inputs\": {\"a\": 8368.473889617526, \"b\": 4735.838330834498}}, {\"idx\": 7, \"outputs\": -18155.585669713404, \"inputs\": {\"a\": -3761.921143166053, \"b\": -5315.871691690649}}, {\"idx\": 8, \"outputs\": 19258.60615615351, \"inputs\": {\"a\": 3139.1089185587884, \"b\": 6490.194159517967}}, {\"idx\": 9, \"outputs\": -26966.87935977597, \"inputs\": {\"a\": -5218.286665567171, \"b\": -8265.153014320813}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
442 | Program Count Occurrence Given Character String | C++ | int programCountOccurrenceGivenCharacterString(string s, char c) { | [
"s",
"c"
] | def program_count_occurrence_given_character_string(s, c):
res = 0
for i in range(len(s)):
if (s[i] == c):
res = (res + 1)
return res | int program_count_occurrence_given_character_string(string s, char c) {
int res = 0;
for ( int i = 0;
i < s . length ( );
i ++ ) if ( s [ i ] == c ) 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(string s, char c, int 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(\"mhjnKfd\", 'l', 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"716662107\", '6', 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01\", '1', 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"wPHSxIbnHakGRO\", 'n', 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"721106\", '8', 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111\", '0', 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"TIBFU\", 'Q', 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0\", '3', 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10\", '0', 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"lqq\", 'd', 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programCountOccurrenceGivenCharacterString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"s\": \"mhjnKfd\", \"c\": \"l\"}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"s\": \"716662107\", \"c\": \"6\"}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"s\": \"01\", \"c\": \"1\"}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"s\": \"wPHSxIbnHakGRO\", \"c\": \"n\"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"s\": \"721106\", \"c\": \"8\"}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"s\": \"111\", \"c\": \"0\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"s\": \"TIBFU\", \"c\": \"Q\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"s\": \"0\", \"c\": \"3\"}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"s\": \"10\", \"c\": \"0\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"s\": \"lqq\", \"c\": \"d\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
443 | Program Find Slope Line | C++ | double programFindSlopeLine(double x1, double y1, double x2, double y2) { | [
"x1",
"y1",
"x2",
"y2"
] | def program_find_slope_line(x1, y1, x2, y2):
return (float((y2 - y1)) / (x2 - x1)) | float program_find_slope_line(float x1, float y1, float x2, float y2) {
return ( y2 - 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(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(double x1, double y1, double x2, double y2, double 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(236.27324548309292, 5792.493225762838, 7177.837879115863, 1289.5700425822731, -0.6486899453998202); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-9201.144918204123, -2716.3347716140406, -5161.142121227645, -3205.784279961129, -0.12115078452752318); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3480.4716834445326, 3577.9608612055613, 8611.515262945342, 6744.864707668983, 0.617204628531244); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6915.538971485092, -4113.601103381095, -748.3462104020822, -9245.271700539257, -0.8320918116165706); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8887.97173657486, 1678.4080012662428, 8709.574949883017, 8548.492675510739, -38.51013687881985); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-3785.5177159369946, -3084.67461899163, -7415.76208254121, -887.5389305564152, -0.6052307962095809); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3037.6696554256832, 4432.445827549, 8387.304165588026, 611.3373507518394, -0.7142746798007333); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7925.458496016523, -3350.27411882042, -5619.767086756504, -1185.7423219907591, 0.9387777514963889); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1404.2919985268031, 8971.636233373416, 3039.112051378511, 1947.6756252708972, -4.2964732392719505); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-4748.744241168378, -675.557388148954, -5998.241086029875, -4236.658178504375, 2.85002783720527); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programFindSlopeLine",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -0.6486899453998202, \"inputs\": {\"x1\": 236.27324548309292, \"y1\": 5792.493225762838, \"x2\": 7177.837879115863, \"y2\": 1289.5700425822731}}, {\"idx\": 1, \"outputs\": -0.12115078452752318, \"inputs\": {\"x1\": -9201.144918204123, \"y1\": -2716.3347716140406, \"x2\": -5161.142121227645, \"y2\": -3205.784279961129}}, {\"idx\": 2, \"outputs\": 0.617204628531244, \"inputs\": {\"x1\": 3480.4716834445326, \"y1\": 3577.9608612055613, \"x2\": 8611.515262945342, \"y2\": 6744.864707668983}}, {\"idx\": 3, \"outputs\": -0.8320918116165706, \"inputs\": {\"x1\": -6915.538971485092, \"y1\": -4113.601103381095, \"x2\": -748.3462104020822, \"y2\": -9245.271700539257}}, {\"idx\": 4, \"outputs\": -38.51013687881985, \"inputs\": {\"x1\": 8887.97173657486, \"y1\": 1678.4080012662428, \"x2\": 8709.574949883017, \"y2\": 8548.492675510739}}, {\"idx\": 5, \"outputs\": -0.6052307962095809, \"inputs\": {\"x1\": -3785.5177159369946, \"y1\": -3084.67461899163, \"x2\": -7415.76208254121, \"y2\": -887.5389305564152}}, {\"idx\": 6, \"outputs\": -0.7142746798007333, \"inputs\": {\"x1\": 3037.6696554256832, \"y1\": 4432.445827549, \"x2\": 8387.304165588026, \"y2\": 611.3373507518394}}, {\"idx\": 7, \"outputs\": 0.9387777514963889, \"inputs\": {\"x1\": -7925.458496016523, \"y1\": -3350.27411882042, \"x2\": -5619.767086756504, \"y2\": -1185.7423219907591}}, {\"idx\": 8, \"outputs\": -4.2964732392719505, \"inputs\": {\"x1\": 1404.2919985268031, \"y1\": 8971.636233373416, \"x2\": 3039.112051378511, \"y2\": 1947.6756252708972}}, {\"idx\": 9, \"outputs\": 2.85002783720527, \"inputs\": {\"x1\": -4748.744241168378, \"y1\": -675.557388148954, \"x2\": -5998.241086029875, \"y2\": -4236.658178504375}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
444 | Program Find Smallest Difference Angles Two Parts Given Circle | C++ | int programFindSmallestDifferenceAnglesTwoPartsGivenCircle(vector<int> arr, int n) { | [
"arr",
"n"
] | def program_find_smallest_difference_angles_two_parts_given_circle(arr, n):
l = 0
_sum = 0
ans = 360
for i in range(n):
_sum += arr[i]
while (_sum >= 180):
ans = min(ans, (2 * abs((180 - _sum))))
_sum -= arr[l]
l += 1
ans = min(ans, (2 * abs((180 - _sum))))
return ans | int program_find_smallest_difference_angles_two_parts_given_circle(vector<int> arr, int n) {
int l = 0, sum = 0, ans = 360;
for ( int i = 0;
i < n;
i ++ ) {
sum += arr [ i ];
while ( sum >= 180 ) {
ans = min ( ans, 2 * abs ( 180 - sum ) );
sum -= arr [ l ];
l ++;
}
ans = min ( ans, 2 * abs ( 180 - sum ) );
}
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, 4, 5, 5, 13, 14, 14, 16, 19, 20, 30, 31, 32, 33, 35, 38, 38, 42, 44, 44, 48, 48, 52, 58, 60, 64, 65, 66, 68, 69, 70, 70, 71, 72, 73, 79, 81, 83, 83, 84, 86, 87, 88, 88, 91, 92, 95, 95, 98}, 27, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, 88, -50, 70, 20, 58, 42, -56, -52, -78, 98, 20, -26, 4, 20, -66, -46, -58, 74, 74, -72, 2, 16, -78, -4, 10, 58, 60, -46, -2, 32, -96, 24, -6, 90, -64, -24, -38, 26, 66, -42, -86, 48, 92, 28, 6, -54, -6}, 29, 16); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, 340); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, 67, 62}, 1, 256); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, -22, 32, 42, 66}, 4, 360); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0}, 10, 354); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({38, 46, 58, 72}, 2, 192); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, 62, 90, 40, 30, -56, -92, -56, 60, 42, -64, 92, -30, -70, 42, -48, -54, 54, 48, 94, -44, -46, 10, 48, 22, -24, -62, 34, 60, 24, -60, 50, 40, 34}, 20, 24); \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, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 340); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 43, 74, 84, 86, 14, 45, 7, 92, 36, 79, 13, 67, 18, 96, 77, 13, 22, 28, 36, 57, 56, 99, 57, 8, 48, 5, 79, 65, 64, 96, 6, 36, 91, 53, 55, 11, 12, 80, 99, 50, 40, 4, 9, 52, 41}, 40, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programFindSmallestDifferenceAnglesTwoPartsGivenCircle",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [4, 4, 5, 5, 13, 14, 14, 16, 19, 20, 30, 31, 32, 33, 35, 38, 38, 42, 44, 44, 48, 48, 52, 58, 60, 64, 65, 66, 68, 69, 70, 70, 71, 72, 73, 79, 81, 83, 83, 84, 86, 87, 88, 88, 91, 92, 95, 95, 98], \"n\": 27}}, {\"idx\": 1, \"outputs\": 16, \"inputs\": {\"arr\": [-56, 88, -50, 70, 20, 58, 42, -56, -52, -78, 98, 20, -26, 4, 20, -66, -46, -58, 74, 74, -72, 2, 16, -78, -4, 10, 58, 60, -46, -2, 32, -96, 24, -6, 90, -64, -24, -38, 26, 66, -42, -86, 48, 92, 28, 6, -54, -6], \"n\": 29}}, {\"idx\": 2, \"outputs\": 340, \"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], \"n\": 25}}, {\"idx\": 3, \"outputs\": 256, \"inputs\": {\"arr\": [52, 67, 62], \"n\": 1}}, {\"idx\": 4, \"outputs\": 360, \"inputs\": {\"arr\": [-56, -22, 32, 42, 66], \"n\": 4}}, {\"idx\": 5, \"outputs\": 354, \"inputs\": {\"arr\": [1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0], \"n\": 10}}, {\"idx\": 6, \"outputs\": 192, \"inputs\": {\"arr\": [38, 46, 58, 72], \"n\": 2}}, {\"idx\": 7, \"outputs\": 24, \"inputs\": {\"arr\": [16, 62, 90, 40, 30, -56, -92, -56, 60, 42, -64, 92, -30, -70, 42, -48, -54, 54, 48, 94, -44, -46, 10, 48, 22, -24, -62, 34, 60, 24, -60, 50, 40, 34], \"n\": 20}}, {\"idx\": 8, \"outputs\": 340, \"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], \"n\": 37}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [86, 43, 74, 84, 86, 14, 45, 7, 92, 36, 79, 13, 67, 18, 96, 77, 13, 22, 28, 36, 57, 56, 99, 57, 8, 48, 5, 79, 65, 64, 96, 6, 36, 91, 53, 55, 11, 12, 80, 99, 50, 40, 4, 9, 52, 41], \"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
]
} |
445 | Program Find String Start End Geeks | C++ | bool programFindStringStartEndGeeks(string str, string corner) { | [
"str",
"corner"
] | def program_find_string_start_end_geeks(str, corner):
n = len(str)
cl = len(corner)
if (n < cl):
return False
return ((str[:cl] == corner) and (str[(n - cl):] == corner)) | bool program_find_string_start_end_geeks(string str, string corner) {
int n = str . length ( );
int cl = corner . length ( );
if ( n < cl ) return false;
return ( str . substr ( 0, cl ) . compare ( corner ) == 0 && str . substr ( n - cl, cl ) . compare ( corner ) == 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 str, string corner, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str, corner), 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(\"geeksmanishgeeks\", \"geeks\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"shreyadhatwalia\", \"abc\", false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10000100\", \"100\", true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abaa\", \"a\", true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"30645530\", \"30\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0000011011001\", \"001\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"dkqEd\", \"d\", true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"48694119324654\", \"654\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1101010010\", \"11\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Ks\", \"KsFLmngGGOmHKs\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programFindStringStartEndGeeks",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"str\": \"geeksmanishgeeks\", \"corner\": \"geeks\"}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"str\": \"shreyadhatwalia\", \"corner\": \"abc\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"str\": \"10000100\", \"corner\": \"100\"}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"str\": \"abaa\", \"corner\": \"a\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"str\": \"30645530\", \"corner\": \"30\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"str\": \"0000011011001\", \"corner\": \"001\"}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"str\": \"dkqEd\", \"corner\": \"d\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"str\": \"48694119324654\", \"corner\": \"654\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"str\": \"1101010010\", \"corner\": \"11\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"str\": \"Ks\", \"corner\": \"KsFLmngGGOmHKs\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
446 | Program For Deadlock Free Condition In Operating System | C++ | int programForDeadlockFreeConditionInOperatingSystem(int process, int need) { | [
"process",
"need"
] | def program_for_deadlock_free_condition_in_operating_system(process, need):
minResources = 0
minResources = ((process * (need - 1)) + 1)
return minResources | int program_for_deadlock_free_condition_in_operating_system(int process, int need) {
int minResources = 0;
minResources = process * ( need - 1 ) + 1;
return minResources;
} | {
"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 process, int need, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(process, need), 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(38, 37, 1369); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 3, 165); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 26, 51); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 72, 2699); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 85, 2605); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 73, 5761); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 9, 89); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 31, 61); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 59, 1509); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 67, 2443); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programForDeadlockFreeConditionInOperatingSystem",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1369, \"inputs\": {\"process\": 38, \"need\": 37}}, {\"idx\": 1, \"outputs\": 165, \"inputs\": {\"process\": 82, \"need\": 3}}, {\"idx\": 2, \"outputs\": 51, \"inputs\": {\"process\": 2, \"need\": 26}}, {\"idx\": 3, \"outputs\": 2699, \"inputs\": {\"process\": 38, \"need\": 72}}, {\"idx\": 4, \"outputs\": 2605, \"inputs\": {\"process\": 31, \"need\": 85}}, {\"idx\": 5, \"outputs\": 5761, \"inputs\": {\"process\": 80, \"need\": 73}}, {\"idx\": 6, \"outputs\": 89, \"inputs\": {\"process\": 11, \"need\": 9}}, {\"idx\": 7, \"outputs\": 61, \"inputs\": {\"process\": 2, \"need\": 31}}, {\"idx\": 8, \"outputs\": 1509, \"inputs\": {\"process\": 26, \"need\": 59}}, {\"idx\": 9, \"outputs\": 2443, \"inputs\": {\"process\": 37, \"need\": 67}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
449 | Program For Factorial Of A Number 2 | C++ | int programForFactorialOfANumber2(int n) { | [
"n"
] | def program_for_factorial_of_a_number_2(n):
return (1 if ((n == 1) or (n == 0)) else (n * program_for_factorial_of_a_number_2((n - 1)))) | int program_for_factorial_of_a_number_2(int n) {
return ( n == 1 || n == 0 ) ? 1 : n * program_for_factorial_of_a_number_2 ( 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(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(2, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 479001600); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 39916800); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programForFactorialOfANumber2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"n\": 2}}, {\"idx\": 1, \"outputs\": 479001600, \"inputs\": {\"n\": 12}}, {\"idx\": 2, \"outputs\": 39916800, \"inputs\": {\"n\": 11}}]",
"test_case_ids": [
"0",
"1",
"2"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
450 | Program For Surface Area Of Octahedron | C++ | double programForSurfaceAreaOfOctahedron(double side) { | [
"side"
] | def program_for_surface_area_of_octahedron(side):
return ((2 * math.sqrt(3)) * (side * side)) | double program_for_surface_area_of_octahedron(double side) {
return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) );
} | {
"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 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(1449.255716877097, 7275798.574924052); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-8772.104874265995, 266562009.34357828); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2948.419328234334, 30114046.875937637); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-1184.220109553511, 4857977.358664159); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7422.825800698956, 190866258.51879707); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-5808.280006171851, 116865336.10679008); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(829.8963781665169, 2385823.7719733207); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7368.438572511732, 188079541.63799432); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5572.033890611617, 107551908.5552799); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-3998.9441642787706, 55396369.52612884); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programForSurfaceAreaOfOctahedron",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 7275798.574924052, \"inputs\": {\"side\": 1449.255716877097}}, {\"idx\": 1, \"outputs\": 266562009.34357828, \"inputs\": {\"side\": -8772.104874265995}}, {\"idx\": 2, \"outputs\": 30114046.875937637, \"inputs\": {\"side\": 2948.419328234334}}, {\"idx\": 3, \"outputs\": 4857977.358664159, \"inputs\": {\"side\": -1184.220109553511}}, {\"idx\": 4, \"outputs\": 190866258.51879707, \"inputs\": {\"side\": 7422.825800698956}}, {\"idx\": 5, \"outputs\": 116865336.10679008, \"inputs\": {\"side\": -5808.280006171851}}, {\"idx\": 6, \"outputs\": 2385823.7719733207, \"inputs\": {\"side\": 829.8963781665169}}, {\"idx\": 7, \"outputs\": 188079541.63799432, \"inputs\": {\"side\": -7368.438572511732}}, {\"idx\": 8, \"outputs\": 107551908.5552799, \"inputs\": {\"side\": 5572.033890611617}}, {\"idx\": 9, \"outputs\": 55396369.52612884, \"inputs\": {\"side\": -3998.9441642787706}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
451 | Program Octal Decimal Conversion | C++ | int programOctalDecimalConversion(int n) { | [
"n"
] | def program_octal_decimal_conversion(n):
num = n
dec_value = 0
base = 1
temp = num
while temp:
last_digit = (temp % 10)
temp = int((temp / 10))
dec_value += (last_digit * base)
base = (base * 8)
return dec_value | int program_octal_decimal_conversion(int n) {
int num = n;
int dec_value = 0;
int base = 1;
int temp = num;
while ( temp ) {
int last_digit = temp % 10;
temp = temp / 10;
dec_value += last_digit * base;
base = base * 8;
}
return dec_value;
} | {
"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(37, 31); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 21); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 51); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 54); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 26); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 33); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 66); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 44); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 5); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programOctalDecimalConversion",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 31, \"inputs\": {\"n\": 37}}, {\"idx\": 1, \"outputs\": 21, \"inputs\": {\"n\": 25}}, {\"idx\": 2, \"outputs\": 51, \"inputs\": {\"n\": 63}}, {\"idx\": 3, \"outputs\": 54, \"inputs\": {\"n\": 66}}, {\"idx\": 4, \"outputs\": 26, \"inputs\": {\"n\": 32}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"n\": 5}}, {\"idx\": 6, \"outputs\": 33, \"inputs\": {\"n\": 41}}, {\"idx\": 7, \"outputs\": 66, \"inputs\": {\"n\": 82}}, {\"idx\": 8, \"outputs\": 44, \"inputs\": {\"n\": 54}}, {\"idx\": 9, \"outputs\": 5, \"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
]
} |
452 | Program Page Replacement Algorithms Set 2 Fifo | C++ | int programPageReplacementAlgorithmsSet2Fifo(vector<int> pages, int n, int capacity) { | [
"pages",
"n",
"capacity"
] | def program_page_replacement_algorithms_set_2_fifo(pages, n, capacity):
s = set()
indexes = Queue()
page_faults = 0
for i in range(n):
if (len(s) < capacity):
if (pages[i] not in s):
s.add(pages[i])
page_faults += 1
indexes.put(pages[i])
elif (pages[i] not in s):
val = indexes.queue[0]
indexes.get()
s.remove(val)
s.add(pages[i])
indexes.put(pages[i])
page_faults += 1
return page_faults | int program_page_replacement_algorithms_set_2_fifo(vector<int> pages, int n, int capacity) {
unordered_set < int > s;
queue < int > indexes;
int page_faults = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( s . size ( ) < capacity ) {
if ( s . find ( pages [ i ] ) == s . end ( ) ) {
s . insert ( pages [ i ] );
page_faults ++;
indexes . push ( pages [ i ] );
}
}
else {
if ( s . find ( pages [ i ] ) == s . end ( ) ) {
int val = indexes . front ( );
indexes . pop ( );
s . erase ( val );
s . insert ( pages [ i ] );
indexes . push ( pages [ i ] );
page_faults ++;
}
}
}
return page_faults;
} | {
"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> pages, int n, int capacity, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(pages, n, capacity), 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, 4, 6, 7, 8, 11, 13, 18, 26, 35, 36, 37, 45, 46, 46, 47, 48, 49, 51, 52, 53, 56, 61, 74, 75, 77, 80, 83, 85, 86, 87, 90, 93, 95, 97, 98, 99, 99}, 36, 37, 34); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, -48, 50, -20, -6, 58, -8, 66, 72, 68, 4, 80, 58, -26, -82, -56, 92, 76, 20, 82, -46, 86, 38, 60, -62, -48, 76, 8, -66, -4, -98, -96, -52, 92}, 33, 23, 30); \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}, 19, 13, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 78, 94, 42, 62, 83, 7, 62, 60, 94, 16, 28, 50, 15, 18, 71, 86, 47, 62, 89}, 15, 11, 13); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-82, -70, -68, -56, -50, -44, 4, 18, 28, 30, 30, 42, 66, 78, 80}, 9, 11, 9); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0}, 25, 25, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 13, 15, 18, 28, 32, 40, 46, 46, 55, 57, 61, 63, 65, 68, 77, 79, 79, 96}, 17, 18, 16); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-2, 82, 2, -74, -6, -24, 54, -74, -98, 8, -94, -60, -42, -38, 36, -38, -58, -70, -28, -34, 70, -6, -2, -76, -40, -4, 0, -4, 76, 48, -34, -26, -48, -58, -88, -44, 20, -22, 78}, 31, 24, 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, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 26, 24, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 90, 28, 71, 69, 45, 92, 63, 72, 76, 47, 85, 36, 59, 88, 46, 28, 19, 50, 31, 63, 13}, 15, 12, 15); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programPageReplacementAlgorithmsSet2Fifo",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 34, \"inputs\": {\"pages\": [4, 4, 6, 7, 8, 11, 13, 18, 26, 35, 36, 37, 45, 46, 46, 47, 48, 49, 51, 52, 53, 56, 61, 74, 75, 77, 80, 83, 85, 86, 87, 90, 93, 95, 97, 98, 99, 99], \"n\": 36, \"capacity\": 37}}, {\"idx\": 1, \"outputs\": 30, \"inputs\": {\"pages\": [78, -48, 50, -20, -6, 58, -8, 66, 72, 68, 4, 80, 58, -26, -82, -56, 92, 76, 20, 82, -46, 86, 38, 60, -62, -48, 76, 8, -66, -4, -98, -96, -52, 92], \"n\": 33, \"capacity\": 23}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"pages\": [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], \"n\": 19, \"capacity\": 13}}, {\"idx\": 3, \"outputs\": 13, \"inputs\": {\"pages\": [98, 78, 94, 42, 62, 83, 7, 62, 60, 94, 16, 28, 50, 15, 18, 71, 86, 47, 62, 89], \"n\": 15, \"capacity\": 11}}, {\"idx\": 4, \"outputs\": 9, \"inputs\": {\"pages\": [-82, -70, -68, -56, -50, -44, 4, 18, 28, 30, 30, 42, 66, 78, 80], \"n\": 9, \"capacity\": 11}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"pages\": [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0], \"n\": 25, \"capacity\": 25}}, {\"idx\": 6, \"outputs\": 16, \"inputs\": {\"pages\": [4, 5, 13, 15, 18, 28, 32, 40, 46, 46, 55, 57, 61, 63, 65, 68, 77, 79, 79, 96], \"n\": 17, \"capacity\": 18}}, {\"idx\": 7, \"outputs\": 25, \"inputs\": {\"pages\": [-2, 82, 2, -74, -6, -24, 54, -74, -98, 8, -94, -60, -42, -38, 36, -38, -58, -70, -28, -34, 70, -6, -2, -76, -40, -4, 0, -4, 76, 48, -34, -26, -48, -58, -88, -44, 20, -22, 78], \"n\": 31, \"capacity\": 24}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"pages\": [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], \"n\": 26, \"capacity\": 24}}, {\"idx\": 9, \"outputs\": 15, \"inputs\": {\"pages\": [4, 90, 28, 71, 69, 45, 92, 63, 72, 76, 47, 85, 36, 59, 88, 46, 28, 19, 50, 31, 63, 13], \"n\": 15, \"capacity\": 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
]
} |
453 | Program Print Sum Given Nth Term | C++ | int programPrintSumGivenNthTerm(int n) { | [
"n"
] | def program_print_sum_given_nth_term(n):
S = 0
for i in range(1, (n + 1)):
S += ((i * i) - ((i - 1) * (i - 1)))
return S | int program_print_sum_given_nth_term(long n) {
int S = 0;
for ( int i = 1;
i <= n;
i ++ ) S += i * i - ( i - 1 ) * ( i - 1 );
return S;
} | {
"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(39, 1521); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 400); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 100); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 1521); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 4900); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 441); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 441); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 6400); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 7921); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 9801); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programPrintSumGivenNthTerm",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1521, \"inputs\": {\"n\": 39}}, {\"idx\": 1, \"outputs\": 400, \"inputs\": {\"n\": 20}}, {\"idx\": 2, \"outputs\": 100, \"inputs\": {\"n\": 10}}, {\"idx\": 3, \"outputs\": 1521, \"inputs\": {\"n\": 39}}, {\"idx\": 4, \"outputs\": 4900, \"inputs\": {\"n\": 70}}, {\"idx\": 5, \"outputs\": 441, \"inputs\": {\"n\": 21}}, {\"idx\": 6, \"outputs\": 441, \"inputs\": {\"n\": 21}}, {\"idx\": 7, \"outputs\": 6400, \"inputs\": {\"n\": 80}}, {\"idx\": 8, \"outputs\": 7921, \"inputs\": {\"n\": 89}}, {\"idx\": 9, \"outputs\": 9801, \"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
]
} |
454 | Program Print Sum Given Nth Term 1 | C++ | float programPrintSumGivenNthTerm1(int n) { | [
"n"
] | def program_print_sum_given_nth_term_1(n):
return math.pow(n, 2) | int program_print_sum_given_nth_term_1(long n) {
return pow ( n, 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(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int n, float 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(42, 1764.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 1600.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 4489.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 5329.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 324.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 256.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 5476.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 1089.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 8464.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 484.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programPrintSumGivenNthTerm1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1764.0, \"inputs\": {\"n\": 42}}, {\"idx\": 1, \"outputs\": 1600.0, \"inputs\": {\"n\": 40}}, {\"idx\": 2, \"outputs\": 4489.0, \"inputs\": {\"n\": 67}}, {\"idx\": 3, \"outputs\": 5329.0, \"inputs\": {\"n\": 73}}, {\"idx\": 4, \"outputs\": 324.0, \"inputs\": {\"n\": 18}}, {\"idx\": 5, \"outputs\": 256.0, \"inputs\": {\"n\": 16}}, {\"idx\": 6, \"outputs\": 5476.0, \"inputs\": {\"n\": 74}}, {\"idx\": 7, \"outputs\": 1089.0, \"inputs\": {\"n\": 33}}, {\"idx\": 8, \"outputs\": 8464.0, \"inputs\": {\"n\": 92}}, {\"idx\": 9, \"outputs\": 484.0, \"inputs\": {\"n\": 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
]
} |
455 | Program To Check If A Given Number Is Lucky All Digits Are Different | C++ | int programToCheckIfAGivenNumberIsLuckyAllDigitsAreDifferent(int n) { | [
"n"
] | def program_to_check_if_a_given_number_is_lucky_all_digits_are_different(n):
ar = ([0] * 10)
while (n > 0):
digit = math.floor((n % 10))
if ar[digit]:
return 0
ar[digit] = 1
n = (n / 10)
return 1 | bool program_to_check_if_a_given_number_is_lucky_all_digits_are_different(int n) {
bool arr [ 10 ];
for ( int i = 0;
i < 10;
i ++ ) arr [ i ] = false;
while ( n > 0 ) {
int digit = n % 10;
if ( arr [ digit ] ) return false;
arr [ digit ] = true;
n = n / 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(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(474, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9445, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37453, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2400, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(722, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programToCheckIfAGivenNumberIsLuckyAllDigitsAreDifferent",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": 474}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"n\": 9445}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 90}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 30}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 37453}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 27}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 2400}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": 98}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": 46}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"n\": 722}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
456 | Program To Find Remainder Without Using Modulo Or Operator | C++ | int programToFindRemainderWithoutUsingModuloOrOperator(int num, int divisor) { | [
"num",
"divisor"
] | def program_to_find_remainder_without_using_modulo_or_operator(num, divisor):
return (num - (divisor * (num // divisor))) | int program_to_find_remainder_without_using_modulo_or_operator(int num, int divisor) {
return ( num - divisor * ( num / divisor ) );
} | {
"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 num, int divisor, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num, divisor), 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(80, 54, 26); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 21, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 56, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 39, 22); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 7, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 67, 61); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 63, 45); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 44, 29); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 65, 30); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 68, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programToFindRemainderWithoutUsingModuloOrOperator",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 26, \"inputs\": {\"num\": 80, \"divisor\": 54}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"num\": 63, \"divisor\": 21}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"num\": 1, \"divisor\": 56}}, {\"idx\": 3, \"outputs\": 22, \"inputs\": {\"num\": 22, \"divisor\": 39}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"num\": 66, \"divisor\": 7}}, {\"idx\": 5, \"outputs\": 61, \"inputs\": {\"num\": 61, \"divisor\": 67}}, {\"idx\": 6, \"outputs\": 45, \"inputs\": {\"num\": 45, \"divisor\": 63}}, {\"idx\": 7, \"outputs\": 29, \"inputs\": {\"num\": 29, \"divisor\": 44}}, {\"idx\": 8, \"outputs\": 30, \"inputs\": {\"num\": 95, \"divisor\": 65}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"num\": 9, \"divisor\": 68}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
457 | Program To Find Remainder Without Using Modulo Or Operator 1 | C++ | int programToFindRemainderWithoutUsingModuloOrOperator1(int num, int divisor) { | [
"num",
"divisor"
] | def program_to_find_remainder_without_using_modulo_or_operator_1(num, divisor):
if (divisor == 0):
return False
if (divisor < 0):
divisor = (- divisor)
if (num < 0):
num = (- num)
i = 1
product = 0
while (product <= num):
product = (divisor * i)
i += 1
return (num - (product - divisor)) | int program_to_find_remainder_without_using_modulo_or_operator_1(int num, int divisor) {
if ( divisor == 0 ) {
return - 1;
}
if ( divisor < 0 ) divisor = - divisor;
if ( num < 0 ) num = - num;
int i = 1;
int product = 0;
while ( product <= num ) {
product = divisor * i;
i ++;
}
return num - ( product - divisor );
} | {
"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 num, int divisor, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num, divisor), 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, 55, 34); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 22, 19); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 26, 15); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 58, 56); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 94, 63); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 45, 28); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 97, 54); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 58, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 91, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 40, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programToFindRemainderWithoutUsingModuloOrOperator1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 34, \"inputs\": {\"num\": 34, \"divisor\": 55}}, {\"idx\": 1, \"outputs\": 19, \"inputs\": {\"num\": 63, \"divisor\": 22}}, {\"idx\": 2, \"outputs\": 15, \"inputs\": {\"num\": 15, \"divisor\": 26}}, {\"idx\": 3, \"outputs\": 56, \"inputs\": {\"num\": 56, \"divisor\": 58}}, {\"idx\": 4, \"outputs\": 63, \"inputs\": {\"num\": 63, \"divisor\": 94}}, {\"idx\": 5, \"outputs\": 28, \"inputs\": {\"num\": 28, \"divisor\": 45}}, {\"idx\": 6, \"outputs\": 54, \"inputs\": {\"num\": 54, \"divisor\": 97}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"num\": 2, \"divisor\": 58}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"num\": 94, \"divisor\": 91}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"num\": 82, \"divisor\": 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
]
} |
458 | Program To Find Remainder Without Using Modulo Or Operator 2 | C++ | int programToFindRemainderWithoutUsingModuloOrOperator2(int num, int divisor) { | [
"num",
"divisor"
] | def program_to_find_remainder_without_using_modulo_or_operator_2(num, divisor):
while (num >= divisor):
num -= divisor
return num | int program_to_find_remainder_without_using_modulo_or_operator_2(int num, int divisor) {
while ( num >= divisor ) num -= divisor;
return num;
} | {
"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 num, int divisor, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num, divisor), 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, 13, 5); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 3, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 73, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 54, 34); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 39, 18); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 10, 6); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 95, 79); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 32, 12); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 86, 26); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 91, 82); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programToFindRemainderWithoutUsingModuloOrOperator2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 5, \"inputs\": {\"num\": 70, \"divisor\": 13}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"num\": 77, \"divisor\": 3}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"num\": 77, \"divisor\": 73}}, {\"idx\": 3, \"outputs\": 34, \"inputs\": {\"num\": 88, \"divisor\": 54}}, {\"idx\": 4, \"outputs\": 18, \"inputs\": {\"num\": 96, \"divisor\": 39}}, {\"idx\": 5, \"outputs\": 6, \"inputs\": {\"num\": 6, \"divisor\": 10}}, {\"idx\": 6, \"outputs\": 79, \"inputs\": {\"num\": 79, \"divisor\": 95}}, {\"idx\": 7, \"outputs\": 12, \"inputs\": {\"num\": 44, \"divisor\": 32}}, {\"idx\": 8, \"outputs\": 26, \"inputs\": {\"num\": 26, \"divisor\": 86}}, {\"idx\": 9, \"outputs\": 82, \"inputs\": {\"num\": 82, \"divisor\": 91}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
459 | Program To Find The Area Of Pentagon | C++ | double programToFindTheAreaOfPentagon(double a) { | [
"a"
] | def program_to_find_the_area_of_pentagon(a):
area = (((sqrt((5 * (5 + (2 * sqrt(5))))) * a) * a) / 4)
return area | float program_to_find_the_area_of_pentagon(float a) {
float area;
area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4;
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(double 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(2009.019461888707, 6944120.6857642615); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-1480.5131394215787, 3771147.371815937); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(357.7870347569567, 220240.9998483103); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-8040.293697508038, 111222537.30911414); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3821.882657293133, 25130647.008061722); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6840.635072240347, 80508515.3102342); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1623.036598830132, 4532163.809416133); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-9714.00706195298, 162347573.54592204); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3916.454769669618, 26389745.561382204); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-669.068424712943, 770176.1075446572); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programToFindTheAreaOfPentagon",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 6944120.6857642615, \"inputs\": {\"a\": 2009.019461888707}}, {\"idx\": 1, \"outputs\": 3771147.371815937, \"inputs\": {\"a\": -1480.5131394215787}}, {\"idx\": 2, \"outputs\": 220240.9998483103, \"inputs\": {\"a\": 357.7870347569567}}, {\"idx\": 3, \"outputs\": 111222537.30911414, \"inputs\": {\"a\": -8040.293697508038}}, {\"idx\": 4, \"outputs\": 25130647.008061722, \"inputs\": {\"a\": 3821.882657293133}}, {\"idx\": 5, \"outputs\": 80508515.3102342, \"inputs\": {\"a\": -6840.635072240347}}, {\"idx\": 6, \"outputs\": 4532163.809416133, \"inputs\": {\"a\": 1623.036598830132}}, {\"idx\": 7, \"outputs\": 162347573.54592204, \"inputs\": {\"a\": -9714.00706195298}}, {\"idx\": 8, \"outputs\": 26389745.561382204, \"inputs\": {\"a\": 3916.454769669618}}, {\"idx\": 9, \"outputs\": 770176.1075446572, \"inputs\": {\"a\": -669.068424712943}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
460 | Program To Find The Volume Of A Triangular Prism | C++ | double programToFindTheVolumeOfATriangularPrism(double l, double b, double h) { | [
"l",
"b",
"h"
] | def program_to_find_the_volume_of_a_triangular_prism(l, b, h):
return (((l * b) * h) / 2) | float program_to_find_the_volume_of_a_triangular_prism(float l, float b, float h) {
float volume = ( l * b * h ) / 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(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(double l, double b, double h, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(l, b, h), 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(8448.900678262902, 8135.461799983198, 6577.239053611328, 226045593884.95786); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-1849.728957491451, -4240.89241631363, -9953.518310747193, -39040194699.58562); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(412.667844022232, 9798.083992381831, 1449.9204200270522, 2931270907.5877957); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-5954.835911765373, -661.8872499003203, -8049.6051526695055, -15863477478.565292); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8437.913444665008, 8182.675681595904, 9863.296545513396, 340504220608.1437); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7183.181663518317, -6846.746446198541, -971.2199894221352, -23882990818.874195); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2340.7905920227954, 5479.00956987109, 7073.449591910562, 45359252560.89365); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7281.157547371143, -615.8705455524116, -3343.0245192607968, -7495479637.450533); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(471.3930826982504, 1357.3753126091392, 1907.815700915636, 610364933.1115178); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-7550.426360065503, -2693.2262997056355, -9110.64755244532, -92632540179.42117); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "programToFindTheVolumeOfATriangularPrism",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 226045593884.95786, \"inputs\": {\"l\": 8448.900678262902, \"b\": 8135.461799983198, \"h\": 6577.239053611328}}, {\"idx\": 1, \"outputs\": -39040194699.58562, \"inputs\": {\"l\": -1849.728957491451, \"b\": -4240.89241631363, \"h\": -9953.518310747193}}, {\"idx\": 2, \"outputs\": 2931270907.5877957, \"inputs\": {\"l\": 412.667844022232, \"b\": 9798.083992381831, \"h\": 1449.9204200270522}}, {\"idx\": 3, \"outputs\": -15863477478.565292, \"inputs\": {\"l\": -5954.835911765373, \"b\": -661.8872499003203, \"h\": -8049.6051526695055}}, {\"idx\": 4, \"outputs\": 340504220608.1437, \"inputs\": {\"l\": 8437.913444665008, \"b\": 8182.675681595904, \"h\": 9863.296545513396}}, {\"idx\": 5, \"outputs\": -23882990818.874195, \"inputs\": {\"l\": -7183.181663518317, \"b\": -6846.746446198541, \"h\": -971.2199894221352}}, {\"idx\": 6, \"outputs\": 45359252560.89365, \"inputs\": {\"l\": 2340.7905920227954, \"b\": 5479.00956987109, \"h\": 7073.449591910562}}, {\"idx\": 7, \"outputs\": -7495479637.450533, \"inputs\": {\"l\": -7281.157547371143, \"b\": -615.8705455524116, \"h\": -3343.0245192607968}}, {\"idx\": 8, \"outputs\": 610364933.1115178, \"inputs\": {\"l\": 471.3930826982504, \"b\": 1357.3753126091392, \"h\": 1907.815700915636}}, {\"idx\": 9, \"outputs\": -92632540179.42117, \"inputs\": {\"l\": -7550.426360065503, \"b\": -2693.2262997056355, \"h\": -9110.64755244532}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
461 | Pythagorean Quadruple | C++ | bool pythagoreanQuadruple(int a, int b, int c, int d) { | [
"a",
"b",
"c",
"d"
] | def pythagorean_quadruple(a, b, c, d):
sum = (((a * a) + (b * b)) + (c * c))
if ((d * d) == sum):
return True
else:
return False | bool pythagorean_quadruple(int a, int b, int c, int d) {
int sum = a * a + b * b + c * c;
if ( d * d == sum ) return true;
else 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 a, int b, int c, int d, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c, 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(1, 1, 1, 3, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 2, 5, 38, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(0, 0, 0, 0, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-1, -1, -1, 1, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 79, 6, 59, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 57, 35, 29, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 96, 45, 75, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 7, 3, 63, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 65, 72, 93, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 33, 6, 2, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "pythagoreanQuadruple",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"a\": 1, \"b\": 1, \"c\": 1, \"d\": 3}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"a\": 3, \"b\": 2, \"c\": 5, \"d\": 38}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"a\": 0, \"b\": 0, \"c\": 0, \"d\": 0}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"a\": -1, \"b\": -1, \"c\": -1, \"d\": 1}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"a\": 82, \"b\": 79, \"c\": 6, \"d\": 59}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"a\": 14, \"b\": 57, \"c\": 35, \"d\": 29}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"a\": 6, \"b\": 96, \"c\": 45, \"d\": 75}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"a\": 13, \"b\": 7, \"c\": 3, \"d\": 63}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a\": 96, \"b\": 65, \"c\": 72, \"d\": 93}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"a\": 70, \"b\": 33, \"c\": 6, \"d\": 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
]
} |
462 | Python Program Find Perimeter Circumference Square Rectangle | C++ | int pythonProgramFindPerimeterCircumferenceSquareRectangle(int a) { | [
"a"
] | def python_program_find_perimeter_circumference_square_rectangle(a):
return (4 * a) | int python_program_find_perimeter_circumference_square_rectangle(int a) {
return 4 * 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 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(98, 392); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 36); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 72); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 152); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 336); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 32); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 156); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 24); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 240); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 188); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "pythonProgramFindPerimeterCircumferenceSquareRectangle",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 392, \"inputs\": {\"a\": 98}}, {\"idx\": 1, \"outputs\": 36, \"inputs\": {\"a\": 9}}, {\"idx\": 2, \"outputs\": 72, \"inputs\": {\"a\": 18}}, {\"idx\": 3, \"outputs\": 152, \"inputs\": {\"a\": 38}}, {\"idx\": 4, \"outputs\": 336, \"inputs\": {\"a\": 84}}, {\"idx\": 5, \"outputs\": 32, \"inputs\": {\"a\": 8}}, {\"idx\": 6, \"outputs\": 156, \"inputs\": {\"a\": 39}}, {\"idx\": 7, \"outputs\": 24, \"inputs\": {\"a\": 6}}, {\"idx\": 8, \"outputs\": 240, \"inputs\": {\"a\": 60}}, {\"idx\": 9, \"outputs\": 188, \"inputs\": {\"a\": 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
]
} |
463 | Python Program Find Perimeter Circumference Square Rectangle 1 | C++ | int pythonProgramFindPerimeterCircumferenceSquareRectangle1(int l, int w) { | [
"l",
"w"
] | def python_program_find_perimeter_circumference_square_rectangle_1(l, w):
return (2 * (l + w)) | int python_program_find_perimeter_circumference_square_rectangle_1(int l, int w) {
return ( 2 * ( l + w ) );
} | {
"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 l, int w, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(l, w), 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, 39, 194); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 49, 172); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 52, 216); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 43, 130); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 12, 178); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 31, 130); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 54, 256); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 52, 178); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 37, 116); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 30, 210); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "pythonProgramFindPerimeterCircumferenceSquareRectangle1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 194, \"inputs\": {\"l\": 58, \"w\": 39}}, {\"idx\": 1, \"outputs\": 172, \"inputs\": {\"l\": 37, \"w\": 49}}, {\"idx\": 2, \"outputs\": 216, \"inputs\": {\"l\": 56, \"w\": 52}}, {\"idx\": 3, \"outputs\": 130, \"inputs\": {\"l\": 22, \"w\": 43}}, {\"idx\": 4, \"outputs\": 178, \"inputs\": {\"l\": 77, \"w\": 12}}, {\"idx\": 5, \"outputs\": 130, \"inputs\": {\"l\": 34, \"w\": 31}}, {\"idx\": 6, \"outputs\": 256, \"inputs\": {\"l\": 74, \"w\": 54}}, {\"idx\": 7, \"outputs\": 178, \"inputs\": {\"l\": 37, \"w\": 52}}, {\"idx\": 8, \"outputs\": 116, \"inputs\": {\"l\": 21, \"w\": 37}}, {\"idx\": 9, \"outputs\": 210, \"inputs\": {\"l\": 75, \"w\": 30}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
464 | Queries Counts Array Elements Values Given Range | C++ | int queriesCountsArrayElementsValuesGivenRange(vector<int> arr, int n, int x, int y) { | [
"arr",
"n",
"x",
"y"
] | def queries_counts_array_elements_values_given_range(arr, n, x, y):
count = 0
for i in range(n):
if ((arr[i] >= x) and (arr[i] <= y)):
count += 1
return count | int queries_counts_array_elements_values_given_range(vector<int> arr, int n, int x, int y) {
int count = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( arr [ i ] >= x && arr [ i ] <= y ) 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 x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, 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({9, 16, 19, 24, 36, 38, 42, 49, 51, 53, 53, 57, 57, 58, 71, 78, 78, 92, 92, 93}, 13, 12, 13, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, -74, -18, 10, 26, 28, -96, -80, 82, 94, 22, 50, 72, -90, 76, 50, 20, -44, -80}, 18, 13, 13, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 21, 31, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({25, 8, 66, 90, 50, 65, 76, 90, 27}, 4, 8, 5, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -96, -90, -82, -80, -78, -70, -66, -60, -60, -50, -48, -34, -26, -24, -16, -14, -8, -6, 4, 22, 24, 26, 30, 30, 48, 52, 56, 60, 62, 74, 76, 78, 86}, 32, 24, 24, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0}, 15, 16, 12, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 6, 17, 19, 24, 29, 30, 31, 32, 37, 37, 40, 43, 44, 44, 45, 57, 64, 69, 70, 73, 78, 86, 89, 91, 92, 94}, 17, 21, 15, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32, -88, 70, -6, 28, -48}, 4, 3, 4, 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}, 13, 12, 11, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({37, 84, 97, 74, 12, 26, 47, 10, 14, 33}, 5, 9, 8, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "queriesCountsArrayElementsValuesGivenRange",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [9, 16, 19, 24, 36, 38, 42, 49, 51, 53, 53, 57, 57, 58, 71, 78, 78, 92, 92, 93], \"n\": 13, \"x\": 12, \"y\": 13}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [28, -74, -18, 10, 26, 28, -96, -80, 82, 94, 22, 50, 72, -90, 76, 50, 20, -44, -80], \"n\": 18, \"x\": 13, \"y\": 13}}, {\"idx\": 2, \"outputs\": 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 30, \"x\": 21, \"y\": 31}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [25, 8, 66, 90, 50, 65, 76, 90, 27], \"n\": 4, \"x\": 8, \"y\": 5}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-98, -96, -90, -82, -80, -78, -70, -66, -60, -60, -50, -48, -34, -26, -24, -16, -14, -8, -6, 4, 22, 24, 26, 30, 30, 48, 52, 56, 60, 62, 74, 76, 78, 86], \"n\": 32, \"x\": 24, \"y\": 24}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0], \"n\": 15, \"x\": 16, \"y\": 12}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [4, 6, 17, 19, 24, 29, 30, 31, 32, 37, 37, 40, 43, 44, 44, 45, 57, 64, 69, 70, 73, 78, 86, 89, 91, 92, 94], \"n\": 17, \"x\": 21, \"y\": 15}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [32, -88, 70, -6, 28, -48], \"n\": 4, \"x\": 3, \"y\": 4}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13, \"x\": 12, \"y\": 11}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [37, 84, 97, 74, 12, 26, 47, 10, 14, 33], \"n\": 5, \"x\": 9, \"y\": 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
]
} |
465 | Quick Way Check Characters String | C++ | bool quickWayCheckCharactersString(string s) { | [
"s"
] | def quick_way_check_characters_string(s):
n = len(s)
for i in range(1, n):
if (s[i] != s[0]):
return False
return True | bool quick_way_check_characters_string(string s) {
int n = s . length ( );
for ( int i = 1;
i < n;
i ++ ) if ( s [ i ] != s [ 0 ] ) 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 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(\"\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ggg\", true); \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(\"KoYIHns\", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"232\", false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10111000011101\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"DDDD\", true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11111\", true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ewJvixQzu\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "quickWayCheckCharactersString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"s\": \"\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"s\": \"ggg\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"s\": \"11\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"s\": \"KoYIHns\"}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"s\": \"232\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"s\": \"10111000011101\"}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"s\": \"DDDD\"}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"s\": \"11\"}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"s\": \"11111\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"s\": \"ewJvixQzu\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
468 | Recursively Break Number 3 Parts Get Maximum Sum | C++ | int recursivelyBreakNumber3PartsGetMaximumSum(int n) { | [
"n"
] | def recursively_break_number_3_parts_get_maximum_sum(n):
if ((n == 0) or (n == 1)):
return n
return max(((recursively_break_number_3_parts_get_maximum_sum((n // 2)) + recursively_break_number_3_parts_get_maximum_sum((n // 3))) + recursively_break_number_3_parts_get_maximum_sum((n // 4))), n) | int recursively_break_number_3_parts_get_maximum_sum(int n) {
if ( n == 0 || n == 1 ) return n;
return max ( ( recursively_break_number_3_parts_get_maximum_sum ( n / 2 ) + recursively_break_number_3_parts_get_maximum_sum ( n / 3 ) + recursively_break_number_3_parts_get_maximum_sum ( n / 4 ) ), 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(39, 41); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 87); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 7); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 87); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 57); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 19); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 63); \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(36, 41); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 5); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "recursivelyBreakNumber3PartsGetMaximumSum",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 41, \"inputs\": {\"n\": 39}}, {\"idx\": 1, \"outputs\": 87, \"inputs\": {\"n\": 79}}, {\"idx\": 2, \"outputs\": 7, \"inputs\": {\"n\": 7}}, {\"idx\": 3, \"outputs\": 87, \"inputs\": {\"n\": 76}}, {\"idx\": 4, \"outputs\": 57, \"inputs\": {\"n\": 48}}, {\"idx\": 5, \"outputs\": 19, \"inputs\": {\"n\": 18}}, {\"idx\": 6, \"outputs\": 63, \"inputs\": {\"n\": 58}}, {\"idx\": 7, \"outputs\": 17, \"inputs\": {\"n\": 17}}, {\"idx\": 8, \"outputs\": 41, \"inputs\": {\"n\": 36}}, {\"idx\": 9, \"outputs\": 5, \"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
]
} |
469 | Recursively Break Number 3 Parts Get Maximum Sum 1 | C++ | int recursivelyBreakNumber3PartsGetMaximumSum1(int n) { | [
"n"
] | def recursively_break_number_3_parts_get_maximum_sum_1(n):
dp = ([0] * (n + 1))
dp[0] = 0
dp[1] = 1
for i in range(2, (n + 1)):
dp[i] = max(((dp[int((i / 2))] + dp[int((i / 3))]) + dp[int((i / 4))]), i)
return dp[n] | int recursively_break_number_3_parts_get_maximum_sum_1(int n) {
int dp [ n + 1 ];
dp [ 0 ] = 0, dp [ 1 ] = 1;
for ( int i = 2;
i <= n;
i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ], i );
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(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(50, 57); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 93); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 19); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 27); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 32); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 41); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 104); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 27); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 13); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 57); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "recursivelyBreakNumber3PartsGetMaximumSum1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 57, \"inputs\": {\"n\": 50}}, {\"idx\": 1, \"outputs\": 93, \"inputs\": {\"n\": 83}}, {\"idx\": 2, \"outputs\": 19, \"inputs\": {\"n\": 18}}, {\"idx\": 3, \"outputs\": 27, \"inputs\": {\"n\": 24}}, {\"idx\": 4, \"outputs\": 32, \"inputs\": {\"n\": 31}}, {\"idx\": 5, \"outputs\": 41, \"inputs\": {\"n\": 38}}, {\"idx\": 6, \"outputs\": 104, \"inputs\": {\"n\": 94}}, {\"idx\": 7, \"outputs\": 27, \"inputs\": {\"n\": 24}}, {\"idx\": 8, \"outputs\": 13, \"inputs\": {\"n\": 13}}, {\"idx\": 9, \"outputs\": 57, \"inputs\": {\"n\": 53}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
470 | Recursive C Program Linearly Search Element Given Array | C++ | int recursiveCProgramLinearlySearchElementGivenArray(vector<int> arr, int l, int r, int x) { | [
"arr",
"l",
"r",
"x"
] | def recursive_c_program_linearly_search_element_given_array(arr, l, r, x):
if (r < l):
return (- 1)
if (arr[l] == x):
return l
if (arr[r] == x):
return r
return recursive_c_program_linearly_search_element_given_array(arr, (l + 1), (r - 1), x) | int recursive_c_program_linearly_search_element_given_array(vector<int> arr, int l, int r, int x) {
if ( r < l ) return - 1;
if ( arr [ l ] == x ) return l;
if ( arr [ r ] == x ) return r;
return recursive_c_program_linearly_search_element_given_array ( arr, l + 1, r - 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 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({10, 74, 5}, 0, 2, 1, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, 72, 36, 96, 42, 0, -66, 5}, 0, 7, 96, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 5}, 0, 1, -1, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 70, 67, 5}, 0, 3, 3, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -26, -26, -24, -18, -16, 80, 5}, 0, 8, 80, 7); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 1, 5}, 0, 6, 1, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 5, 12, 12, 17, 17, 12, 95, 96, 98, 5}, 0, 0, 12, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, -70, -30, -54, 6, -10, 70, 84, 5}, 0, 8, 27, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 5}, 0, 2, 14, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({59, 21, 28, 3, 14, 5}, 0, 5, 28, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "recursiveCProgramLinearlySearchElementGivenArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"arr\": [10, 74, 5], \"l\": 0, \"r\": 2, \"x\": 1}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"arr\": [-90, 72, 36, 96, 42, 0, -66, 5], \"l\": 0, \"r\": 7, \"x\": 96}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 5], \"l\": 0, \"r\": 1, \"x\": -1}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [99, 70, 67, 5], \"l\": 0, \"r\": 3, \"x\": 3}}, {\"idx\": 4, \"outputs\": 7, \"inputs\": {\"arr\": [-98, -98, -26, -26, -24, -18, -16, 80, 5], \"l\": 0, \"r\": 8, \"x\": 80}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 0, 1, 5], \"l\": 0, \"r\": 6, \"x\": 1}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [1, 5, 12, 12, 17, 17, 12, 95, 96, 98, 5], \"l\": 0, \"r\": 0, \"x\": 12}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [50, -70, -30, -54, 6, -10, 70, 84, 5], \"l\": 0, \"r\": 8, \"x\": 27}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 1, 5], \"l\": 0, \"r\": 2, \"x\": 14}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr\": [59, 21, 28, 3, 14, 5], \"l\": 0, \"r\": 5, \"x\": 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
]
} |
471 | Remainder 7 Large Numbers | C++ | int remainder7LargeNumbers(string num) { | [
"num"
] | def remainder_7_large_numbers(num):
series = [1, 3, 2, (- 1), (- 3), (- 2)]
series_index = 0
result = 0
for i in range((len(num) - 1), (- 1), (- 1)):
digit = (ord(num[i]) - 48)
result += (digit * series[series_index])
series_index = ((series_index + 1) % 6)
result %= 7
if (result < 0):
result = ((result + 7) % 7)
return result | int remainder_7_large_numbers(string num) {
int series [ ] = {
1, 3, 2, - 1, - 3, - 2 };
int series_index = 0;
int result = 0;
for ( int i = num . size ( ) - 1;
i >= 0;
i -- ) {
int digit = num [ i ] - '0';
result += digit * series [ series_index ];
series_index = ( series_index + 1 ) % 6;
result %= 7;
}
if ( result < 0 ) result = ( result + 7 ) % 7;
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 num, int 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(\"K\", 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"850076\", 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00111\", 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"X\", 5); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10010001100\", 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\" pgPeLz\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"53212456821275\", 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"101\", 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"V\", 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "remainder7LargeNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"num\": \"K\"}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"num\": \"850076\"}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"num\": \"00111\"}}, {\"idx\": 3, \"outputs\": 5, \"inputs\": {\"num\": \"X\"}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"num\": \"1\"}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"num\": \"10010001100\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"num\": \" pgPeLz\"}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"num\": \"53212456821275\"}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"num\": \"101\"}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"num\": \"V\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
472 | Remove Minimum Elements Either Side 2Min Max | C++ | int removeMinimumElementsEitherSide2MinMax(vector<int> arr, int n) { | [
"arr",
"n"
] | def remove_minimum_elements_either_side_2min_max(arr, n):
longest_start = (- 1)
longest_end = 0
for start in range(n):
min = sys.maxsize
max = (- sys.maxsize)
for end in range(start, n):
val = arr[end]
if (val < min):
min = val
if (val > max):
max = val
if ((2 * min) <= max):
break
if (((end - start) > (longest_end - longest_start)) or (longest_start == (- 1))):
longest_start = start
longest_end = end
if (longest_start == (- 1)):
return n
return (n - ((longest_end - longest_start) + 1)) | int remove_minimum_elements_either_side_2min_max(vector<int> arr, int n) {
int longest_start = - 1, longest_end = 0;
for ( int start = 0;
start < n;
start ++ ) {
int min = INT_MAX, max = INT_MIN;
for ( int end = start;
end < n;
end ++ ) {
int val = arr [ end ];
if ( val < min ) min = val;
if ( val > max ) max = val;
if ( 2 * min <= max ) break;
if ( end - start > longest_end - longest_start || longest_start == - 1 ) {
longest_start = start;
longest_end = end;
}
}
}
if ( longest_start == - 1 ) return n;
return ( n - ( longest_end - longest_start + 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 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({32, 50, 66, 73, 76, 87}, 5, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, 74, 16, 40, 6, -44, -36, 94, 6, -24, -4, -58, -16, 24}, 11, 9); \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, 1, 1, 1, 1}, 11, 9); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({91, 22}, 1, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, -80, -78, -76, -58, -54, -52, -48, -42, -42, -40, -38, -34, -32, -28, -24, -6, 2, 2, 4, 10, 14, 16, 18, 26, 26, 36, 40, 50, 52, 62, 64, 72, 74, 84, 90, 94, 96, 98}, 35, 28); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1}, 13, 10); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 19, 25, 29, 32, 37, 40, 43, 43, 44, 46, 51, 51, 54, 56, 58, 63, 79, 83, 86, 87, 97, 97}, 11, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-48, -28, 10, 30, 78, -72, 78, 52, -52, -68, 56, 42, 8, -42, 16, -56, 2, -90, -26, -28, -56, -2, 80, -50, 98, -64, -96, 10, -10, 44, 98, -48, -88, 42, 30, 24, 38, -26, -52, -12, 0, 34, -82, -80, 0, -84, -20}, 25, 23); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1, 1, 1}, 6, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({25, 82}, 1, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "removeMinimumElementsEitherSide2MinMax",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [32, 50, 66, 73, 76, 87], \"n\": 5}}, {\"idx\": 1, \"outputs\": 9, \"inputs\": {\"arr\": [68, 74, 16, 40, 6, -44, -36, 94, 6, -24, -4, -58, -16, 24], \"n\": 11}}, {\"idx\": 2, \"outputs\": 9, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 11}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [91, 22], \"n\": 1}}, {\"idx\": 4, \"outputs\": 28, \"inputs\": {\"arr\": [-84, -80, -78, -76, -58, -54, -52, -48, -42, -42, -40, -38, -34, -32, -28, -24, -6, 2, 2, 4, 10, 14, 16, 18, 26, 26, 36, 40, 50, 52, 62, 64, 72, 74, 84, 90, 94, 96, 98], \"n\": 35}}, {\"idx\": 5, \"outputs\": 10, \"inputs\": {\"arr\": [1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1], \"n\": 13}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"arr\": [10, 19, 25, 29, 32, 37, 40, 43, 43, 44, 46, 51, 51, 54, 56, 58, 63, 79, 83, 86, 87, 97, 97], \"n\": 11}}, {\"idx\": 7, \"outputs\": 23, \"inputs\": {\"arr\": [-48, -28, 10, 30, 78, -72, 78, 52, -52, -68, 56, 42, 8, -42, 16, -56, 2, -90, -26, -28, -56, -2, 80, -50, 98, -64, -96, 10, -10, 44, 98, -48, -88, 42, 30, 24, 38, -26, -52, -12, 0, 34, -82, -80, 0, -84, -20], \"n\": 25}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 1, 1, 1, 1, 1, 1], \"n\": 6}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [25, 82], \"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
]
} |
473 | Remove Minimum Number Elements No Common Element Exist Array | C++ | int removeMinimumNumberElementsNoCommonElementExistArray(vector<int> a, vector<int> b, int n, int m) { | [
"a",
"b",
"n",
"m"
] | def remove_minimum_number_elements_no_common_element_exist_array(a, b, n, m):
countA = dict()
countB = dict()
for i in range(n):
countA[a[i]] = (countA.get(a[i], 0) + 1)
for i in range(n):
countB[b[i]] = (countB.get(b[i], 0) + 1)
res = 0
for x in countA:
if (x in countB.keys()):
res += min(countA[x], countB[x])
return res | int remove_minimum_number_elements_no_common_element_exist_array(vector<int> a, vector<int> b, int n, int m) {
unordered_map < int, int > countA, countB;
for ( int i = 0;
i < n;
i ++ ) countA [ a [ i ] ] ++;
for ( int i = 0;
i < m;
i ++ ) countB [ b [ i ] ] ++;
int res = 0;
for ( auto x : countA ) if ( countB . find ( x . first ) != countB . end ( ) ) res += min ( x . second, countB [ x . first ] );
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> a, vector<int> b, int n, int m, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, 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({4, 7, 10, 12, 12, 24, 29, 38, 45, 51, 53, 54, 59, 68, 72, 73, 85, 86, 88, 92, 92, 95}, {7, 9, 17, 23, 25, 26, 29, 32, 35, 56, 56, 58, 59, 59, 62, 63, 72, 82, 85, 86, 95, 97}, 15, 13, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-6, 48, -70, 14, -86, 56, 80, -64, 64, -88, -14, 78, 14, -18, 52, 2, 22, 88}, {-62, -58, 60, -30, 42, 8, 66, -48, -18, 64, -76, -90, -48, -90, -24, 64, -88, -98}, 15, 9, 2); \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, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 10, 10, 9); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 93, 2, 16, 36, 49, 36, 86, 6, 99, 95, 2}, {99, 28, 7, 21, 62, 89, 82, 41, 43, 77, 8, 14}, 6, 10, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -96, -80, -64, -42, -30, -6, 10, 62, 66, 82}, {-62, -50, -42, 24, 44, 46, 52, 54, 60, 72, 72}, 9, 6, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 1}, {1, 1, 1, 0, 0}, 4, 2, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 11, 13, 15, 21, 33, 36, 39, 66, 99}, {23, 36, 42, 44, 62, 65, 70, 78, 82, 89}, 9, 9, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-40}, {-98}, 0, 0, 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, 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, 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}, 31, 26, 24); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({79, 91, 31, 16, 28, 45, 37, 43, 73, 73, 76, 28, 71, 60, 64, 60, 99, 36, 47, 38, 65, 34, 22, 94, 84, 51, 72, 45, 71, 2}, {58, 94, 12, 27, 98, 38, 75, 20, 94, 43, 32, 90, 23, 41, 88, 2, 62, 96, 53, 57, 48, 79, 6, 16, 11, 46, 73, 57, 67, 7}, 18, 18, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "removeMinimumNumberElementsNoCommonElementExistArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"a\": [4, 7, 10, 12, 12, 24, 29, 38, 45, 51, 53, 54, 59, 68, 72, 73, 85, 86, 88, 92, 92, 95], \"b\": [7, 9, 17, 23, 25, 26, 29, 32, 35, 56, 56, 58, 59, 59, 62, 63, 72, 82, 85, 86, 95, 97], \"n\": 15, \"m\": 13}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"a\": [-6, 48, -70, 14, -86, 56, 80, -64, 64, -88, -14, 78, 14, -18, 52, 2, 22, 88], \"b\": [-62, -58, 60, -30, 42, 8, 66, -48, -18, 64, -76, -90, -48, -90, -24, 64, -88, -98], \"n\": 15, \"m\": 9}}, {\"idx\": 2, \"outputs\": 9, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"b\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 10, \"m\": 10}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"a\": [10, 93, 2, 16, 36, 49, 36, 86, 6, 99, 95, 2], \"b\": [99, 28, 7, 21, 62, 89, 82, 41, 43, 77, 8, 14], \"n\": 6, \"m\": 10}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"a\": [-98, -96, -80, -64, -42, -30, -6, 10, 62, 66, 82], \"b\": [-62, -50, -42, 24, 44, 46, 52, 54, 60, 72, 72], \"n\": 9, \"m\": 6}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"a\": [1, 1, 0, 1, 1], \"b\": [1, 1, 1, 0, 0], \"n\": 4, \"m\": 2}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"a\": [7, 11, 13, 15, 21, 33, 36, 39, 66, 99], \"b\": [23, 36, 42, 44, 62, 65, 70, 78, 82, 89], \"n\": 9, \"m\": 9}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"a\": [-40], \"b\": [-98], \"n\": 0, \"m\": 0}}, {\"idx\": 8, \"outputs\": 24, \"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, 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], \"b\": [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, 1, 1, 1], \"n\": 31, \"m\": 26}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"a\": [79, 91, 31, 16, 28, 45, 37, 43, 73, 73, 76, 28, 71, 60, 64, 60, 99, 36, 47, 38, 65, 34, 22, 94, 84, 51, 72, 45, 71, 2], \"b\": [58, 94, 12, 27, 98, 38, 75, 20, 94, 43, 32, 90, 23, 41, 88, 2, 62, 96, 53, 57, 48, 79, 6, 16, 11, 46, 73, 57, 67, 7], \"n\": 18, \"m\": 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
]
} |
474 | Replace Character C1 C2 C2 C1 String S | C++ | string replaceCharacterC1C2C2C1StringS(string s, char c1, char c2) { | [
"s",
"c1",
"c2"
] | def replace_character_c1_c2_c2_c1_string_s(s, c1, c2):
l = len(s)
for i in range(l):
if (s[i] == c1):
s = ((s[0:i] + c2) + s[(i + 1):])
elif (s[i] == c2):
s = ((s[0:i] + c1) + s[(i + 1):])
return s | string replace_character_c1_c2_c2_c1_string_s(string s, char c1, char c2) {
int l = s . length ( );
for ( int i = 0;
i < l;
i ++ ) {
if ( s [ i ] == c1 ) s [ i ] = c2;
else if ( s [ i ] == c2 ) s [ i ] = c1;
}
return s;
} | {
"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(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string s, char c1, char c2, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s, c1, c2), 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(\"IZTSMw j\", 'W', 'k', \"IZTSMw j\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"7288334\", '6', '9', \"7288334\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"010110000\", '1', '1', \"010110000\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"b gJX\", 't', 'P', \"b gJX\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"734\", '4', '4', \"734\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", '1', '1', \"1\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"xCaUKdhA\", 'X', 'S', \"xCaUKdhA\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"4370992644981\", '5', '6', \"4370992544981\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01010\", '0', '1', \"10101\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ZNIFGshaWA\", 'Q', 'x', \"ZNIFGshaWA\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "replaceCharacterC1C2C2C1StringS",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": \"IZTSMw j\", \"inputs\": {\"s\": \"IZTSMw j\", \"c1\": \"W\", \"c2\": \"k\"}}, {\"idx\": 1, \"outputs\": \"7288334\", \"inputs\": {\"s\": \"7288334\", \"c1\": \"6\", \"c2\": \"9\"}}, {\"idx\": 2, \"outputs\": \"010110000\", \"inputs\": {\"s\": \"010110000\", \"c1\": \"1\", \"c2\": \"1\"}}, {\"idx\": 3, \"outputs\": \"b gJX\", \"inputs\": {\"s\": \"b gJX\", \"c1\": \"t\", \"c2\": \"P\"}}, {\"idx\": 4, \"outputs\": \"734\", \"inputs\": {\"s\": \"734\", \"c1\": \"4\", \"c2\": \"4\"}}, {\"idx\": 5, \"outputs\": \"1\", \"inputs\": {\"s\": \"1\", \"c1\": \"1\", \"c2\": \"1\"}}, {\"idx\": 6, \"outputs\": \"xCaUKdhA\", \"inputs\": {\"s\": \"xCaUKdhA\", \"c1\": \"X\", \"c2\": \"S\"}}, {\"idx\": 7, \"outputs\": \"4370992544981\", \"inputs\": {\"s\": \"4370992644981\", \"c1\": \"5\", \"c2\": \"6\"}}, {\"idx\": 8, \"outputs\": \"10101\", \"inputs\": {\"s\": \"01010\", \"c1\": \"0\", \"c2\": \"1\"}}, {\"idx\": 9, \"outputs\": \"ZNIFGshaWA\", \"inputs\": {\"s\": \"ZNIFGshaWA\", \"c1\": \"Q\", \"c2\": \"x\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
475 | Round The Given Number To Nearest Multiple Of 10 | C++ | int roundTheGivenNumberToNearestMultipleOf10(int n) { | [
"n"
] | def round_the_given_number_to_nearest_multiple_of_10(n):
a = ((n // 10) * 10)
b = (a + 10)
return (b if ((n - a) > (b - n)) else a) | int round_the_given_number_to_nearest_multiple_of_10(int n) {
int a = ( n / 10 ) * 10;
int b = a + 10;
return ( n - a > b - n ) ? b : 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 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(31, 30); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 80); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 20); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 40); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 80); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 90); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 90); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 20); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 90); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "roundTheGivenNumberToNearestMultipleOf10",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 30, \"inputs\": {\"n\": 31}}, {\"idx\": 1, \"outputs\": 80, \"inputs\": {\"n\": 78}}, {\"idx\": 2, \"outputs\": 20, \"inputs\": {\"n\": 19}}, {\"idx\": 3, \"outputs\": 40, \"inputs\": {\"n\": 36}}, {\"idx\": 4, \"outputs\": 80, \"inputs\": {\"n\": 77}}, {\"idx\": 5, \"outputs\": 90, \"inputs\": {\"n\": 94}}, {\"idx\": 6, \"outputs\": 90, \"inputs\": {\"n\": 86}}, {\"idx\": 7, \"outputs\": 20, \"inputs\": {\"n\": 16}}, {\"idx\": 8, \"outputs\": 90, \"inputs\": {\"n\": 95}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"n\": 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
]
} |
476 | Schedule Jobs Server Gets Equal Load | C++ | int scheduleJobsServerGetsEqualLoad(vector<int> a, vector<int> b, int n) { | [
"a",
"b",
"n"
] | def schedule_jobs_server_gets_equal_load(a, b, n):
s = 0
for i in range(0, n):
s += (a[i] + b[i])
if (n == 1):
return (a[0] + b[0])
if ((s % n) != 0):
return (- 1)
x = (s // n)
for i in range(0, n):
if (a[i] > x):
return (- 1)
if (i > 0):
a[i] += b[(i - 1)]
b[(i - 1)] = 0
if (a[i] == x):
continue
y = (a[i] + b[i])
if ((i + 1) < n):
y += b[(i + 1)]
if (y == x):
a[i] = y
b[i] = 0
if ((i + 1) < n):
b[(i + 1)] = 0
continue
if ((a[i] + b[i]) == x):
a[i] += b[i]
b[i] = 0
continue
if (((i + 1) < n) and ((a[i] + b[(i + 1)]) == x)):
a[i] += b[(i + 1)]
b[(i + 1)] = 0
continue
return (- 1)
for i in range(0, n):
if (b[i] != 0):
return (- 1)
return x | int schedule_jobs_server_gets_equal_load(vector<int> a, vector<int> b, int n) {
int i;
long long int s = 0;
for ( i = 0;
i < n;
i ++ ) s += ( a [ i ] + b [ i ] );
if ( n == 1 ) return a [ 0 ] + b [ 0 ];
if ( s % n != 0 ) return - 1;
int x = s / n;
for ( i = 0;
i < n;
i ++ ) {
if ( a [ i ] > x ) return - 1;
if ( i > 0 ) {
a [ i ] += b [ i - 1 ];
b [ i - 1 ] = 0;
}
if ( a [ i ] == x ) continue;
int y = a [ i ] + b [ i ];
if ( i + 1 < n ) y += b [ i + 1 ];
if ( y == x ) {
a [ i ] = y;
b [ i ] = b [ i + 1 ] = 0;
continue;
}
if ( a [ i ] + b [ i ] == x ) {
a [ i ] += b [ i ];
b [ i ] = 0;
continue;
}
if ( i + 1 < n && a [ i ] + b [ i + 1 ] == x ) {
a [ i ] += b [ i + 1 ];
b [ i + 1 ] = 0;
continue;
}
return - 1;
}
for ( i = 0;
i < n;
i ++ ) if ( b [ i ] != 0 ) return - 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(vector<int> a, vector<int> b, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, 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, 9, 16, 18, 20, 23, 24, 25, 25, 26, 29, 30, 35, 40, 41, 43, 44, 46, 53, 53, 56, 56, 58, 60, 62, 70, 80, 80, 80, 82, 86, 90, 92, 92, 95}, {3, 15, 16, 16, 18, 26, 30, 32, 32, 35, 37, 41, 42, 43, 48, 49, 49, 54, 55, 57, 65, 66, 67, 67, 68, 83, 85, 89, 89, 90, 91, 93, 96, 97, 99}, 29, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-24, 70, -74, -90, 72, 50, -94, 86, -58, -68, 42, 0, 98, -70, -14, -32, 6, 74, 64, -78, 86, -42, -56, 2, -34, -46, 70, -62, 50, -58, -58, 42, 86, 96, -8, 8, -22, -14, -14, 98, 2, 98, -28}, {-26, 36, 48, 48, -38, -86, 90, -62, 30, -4, 82, 16, 32, -6, 58, 82, -66, -40, 52, -78, 94, -70, -80, -68, -58, -26, 50, -78, -90, -48, -28, 48, 56, 50, 72, -22, -2, 8, -94, 92, -44, -66, -30}, 34, -1); \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, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 13, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 18, 50, 36, 88, 75, 2, 40, 74, 19, 63, 82, 77, 5, 59, 97, 70, 50, 71, 90, 90, 61, 63, 99}, {93, 25, 16, 42, 55, 61, 69, 68, 95, 28, 40, 90, 1, 86, 76, 40, 13, 47, 71, 4, 64, 54, 84, 45}, 16, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -64, -64, -64, -64, -62, -54, -48, -44, -44, -38, -30, -30, -26, -14, -12, -10, -6, -6, 6, 22, 22, 22, 26, 28, 50, 52, 70, 86, 86, 88, 90}, {-96, -94, -80, -74, -64, -56, -52, -32, -30, -24, -12, -12, -8, -2, 4, 8, 16, 20, 24, 24, 24, 48, 50, 54, 60, 64, 74, 80, 88, 90, 92, 92}, 22, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1}, {1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1}, 20, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({59, 61, 64}, {22, 59, 85}, 1, 81); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 92, 28, 42, -74, -36, 40, -8, 32, -22, -70, -22, -56, 74, 6, 6, -62, 46, 34, 2}, {-62, -84, 72, 60, 10, -18, -44, -22, 14, 0, 76, 72, 96, -28, -24, 52, -74, -30, 16, 66}, 18, -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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 34, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({72, 97, 79, 21, 83, 2, 31, 59, 6, 11, 79, 97}, {27, 71, 87, 36, 73, 37, 80, 34, 57, 17, 88, 52}, 9, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "scheduleJobsServerGetsEqualLoad",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"a\": [4, 9, 16, 18, 20, 23, 24, 25, 25, 26, 29, 30, 35, 40, 41, 43, 44, 46, 53, 53, 56, 56, 58, 60, 62, 70, 80, 80, 80, 82, 86, 90, 92, 92, 95], \"b\": [3, 15, 16, 16, 18, 26, 30, 32, 32, 35, 37, 41, 42, 43, 48, 49, 49, 54, 55, 57, 65, 66, 67, 67, 68, 83, 85, 89, 89, 90, 91, 93, 96, 97, 99], \"n\": 29}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"a\": [-24, 70, -74, -90, 72, 50, -94, 86, -58, -68, 42, 0, 98, -70, -14, -32, 6, 74, 64, -78, 86, -42, -56, 2, -34, -46, 70, -62, 50, -58, -58, 42, 86, 96, -8, 8, -22, -14, -14, 98, 2, 98, -28], \"b\": [-26, 36, 48, 48, -38, -86, 90, -62, 30, -4, 82, 16, 32, -6, 58, 82, -66, -40, 52, -78, 94, -70, -80, -68, -58, -26, 50, -78, -90, -48, -28, 48, 56, 50, 72, -22, -2, 8, -94, 92, -44, -66, -30], \"n\": 34}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"b\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"a\": [98, 18, 50, 36, 88, 75, 2, 40, 74, 19, 63, 82, 77, 5, 59, 97, 70, 50, 71, 90, 90, 61, 63, 99], \"b\": [93, 25, 16, 42, 55, 61, 69, 68, 95, 28, 40, 90, 1, 86, 76, 40, 13, 47, 71, 4, 64, 54, 84, 45], \"n\": 16}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"a\": [-80, -64, -64, -64, -64, -62, -54, -48, -44, -44, -38, -30, -30, -26, -14, -12, -10, -6, -6, 6, 22, 22, 22, 26, 28, 50, 52, 70, 86, 86, 88, 90], \"b\": [-96, -94, -80, -74, -64, -56, -52, -32, -30, -24, -12, -12, -8, -2, 4, 8, 16, 20, 24, 24, 24, 48, 50, 54, 60, 64, 74, 80, 88, 90, 92, 92], \"n\": 22}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"a\": [0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1], \"b\": [1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1], \"n\": 20}}, {\"idx\": 6, \"outputs\": 81, \"inputs\": {\"a\": [59, 61, 64], \"b\": [22, 59, 85], \"n\": 1}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"a\": [98, 92, 28, 42, -74, -36, 40, -8, 32, -22, -70, -22, -56, 74, 6, 6, -62, 46, 34, 2], \"b\": [-62, -84, 72, 60, 10, -18, -44, -22, 14, 0, 76, 72, 96, -28, -24, 52, -74, -30, 16, 66], \"n\": 18}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"a\": [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], \"b\": [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], \"n\": 34}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"a\": [72, 97, 79, 21, 83, 2, 31, 59, 6, 11, 79, 97], \"b\": [27, 71, 87, 36, 73, 37, 80, 34, 57, 17, 88, 52], \"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
]
} |
477 | Searching Array Adjacent Differ K | C++ | int searchingArrayAdjacentDifferK(vector<int> arr, int n, int x, int k) { | [
"arr",
"n",
"x",
"k"
] | def searching_array_adjacent_differ_k(arr, n, x, k):
i = 0
while (i < n):
if (arr[i] == x):
return i
i = (i + max(1, int((abs((arr[i] - x)) / k))))
print('number is not present!')
return (- 1) | int searching_array_adjacent_differ_k(vector<int> arr, int n, int x, int k) {
int i = 0;
while ( i < n ) {
if ( arr [ i ] == x ) return i;
i = i + max ( 1, abs ( arr [ i ] - x ) / k );
}
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 k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x, 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({1, 5, 9, 11, 14, 18, 19, 21, 26, 32, 38, 38, 43, 47, 49, 52, 55, 61, 65, 67, 69, 73, 74, 79, 84, 90, 91, 91, 92, 93, 94, 99}, 22, 19, 26, 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, -86, -66, -50, -48, 78, -92, -56, -2, 66, 64}, 5, 10, 5, -1); \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, 1, 1, 1, 1, 1}, 35, 37, 43, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 87, 39, 87, 45, 33, 5, 37, 70, 69, 88, 78, 90, 3}, 9, 8, 10, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, -70, -68, -60, -52, -34, -24, -4, 12, 18, 58, 58, 64, 76, 84, 94}, 14, 9, 13, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0}, 26, 36, 32, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 5, 7, 11, 11, 15, 22, 23, 28, 38, 41, 53, 54, 57, 59, 68, 71, 89}, 16, 17, 16, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-4, 0, 60, -14, -48, 54, -96, -68, -40, 64, -50, -74, -20, -22, 48, -48, 42, 62, 66, 84, 54, -52, -52, 6, 46, -90, -18, 90}, 18, 14, 23, -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}, 9, 8, 9, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({30, 91, 34, 44, 3, 76, 43, 75, 49, 33, 74, 72, 68, 79, 26, 62, 23, 5, 32, 75, 82, 25, 7, 19, 32, 87, 87, 94, 34, 62, 3, 32, 59}, 32, 30, 24, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "searchingArrayAdjacentDifferK",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"arr\": [1, 5, 9, 11, 14, 18, 19, 21, 26, 32, 38, 38, 43, 47, 49, 52, 55, 61, 65, 67, 69, 73, 74, 79, 84, 90, 91, 91, 92, 93, 94, 99], \"n\": 22, \"x\": 19, \"k\": 26}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [12, -86, -66, -50, -48, 78, -92, -56, -2, 66, 64], \"n\": 5, \"x\": 10, \"k\": 5}}, {\"idx\": 2, \"outputs\": -1, \"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, 1, 1, 1, 1], \"n\": 35, \"x\": 37, \"k\": 43}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [10, 87, 39, 87, 45, 33, 5, 37, 70, 69, 88, 78, 90, 3], \"n\": 9, \"x\": 8, \"k\": 10}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-78, -70, -68, -60, -52, -34, -24, -4, 12, 18, 58, 58, 64, 76, 84, 94], \"n\": 14, \"x\": 9, \"k\": 13}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0], \"n\": 26, \"x\": 36, \"k\": 32}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [5, 5, 7, 11, 11, 15, 22, 23, 28, 38, 41, 53, 54, 57, 59, 68, 71, 89], \"n\": 16, \"x\": 17, \"k\": 16}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-4, 0, 60, -14, -48, 54, -96, -68, -40, 64, -50, -74, -20, -22, 48, -48, 42, 62, 66, 84, 54, -52, -52, 6, 46, -90, -18, 90], \"n\": 18, \"x\": 14, \"k\": 23}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"n\": 9, \"x\": 8, \"k\": 9}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [30, 91, 34, 44, 3, 76, 43, 75, 49, 33, 74, 72, 68, 79, 26, 62, 23, 5, 32, 75, 82, 25, 7, 19, 32, 87, 87, 94, 34, 62, 3, 32, 59], \"n\": 32, \"x\": 30, \"k\": 24}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
478 | Search An Element In An Array Where Difference Between Adjacent Elements Is 1 | C++ | int searchAnElementInAnArrayWhereDifferenceBetweenAdjacentElementsIs1(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def search_an_element_in_an_array_where_difference_between_adjacent_elements_is_1(arr, n, x):
i = 0
while (i < n):
if (arr[i] == x):
return i
i = (i + abs((arr[i] - x)))
print('number is not present!')
return (- 1) | int search_an_element_in_an_array_where_difference_between_adjacent_elements_is_1(vector<int> arr, int n, int x) {
int i = 0;
while ( i < n ) {
if ( arr [ i ] == x ) return i;
i = i + abs ( arr [ i ] - 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 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({8, 7, 6, 7, 6, 5, 4, 3, 2, 3, 4, 3}, 12, 3, 7); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 90}, 1, 1, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 3, 4, 5, 4}, 6, 5, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({97, 35, 60, 96, 3, 67, 72, 95, 55, 9, 69, 28, 15, 91, 31, 59}, 15, 9, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, -78, -74, -70, -68, -60, -56, -54, -48, -46, -28, -16, -6, 0, 0, 8, 8, 8, 12, 16, 26, 30, 32, 34, 36, 40, 46, 48, 70, 70, 72, 76, 78, 78, 80, 84, 84, 86}, 22, 31, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1}, 5, 7, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({55, 64, 76, 79, 93, 96}, 4, 4, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, -90, 98, -50, 0, 46, 42, 64, -96, -80, -96, 20, -10, -84}, 8, 13, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1}, 6, 5, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 4, 34, 87, 32, 3, 92, 68, 57, 76, 24, 33, 3, 4, 30, 70, 49, 30, 72, 82, 16, 53, 6, 24, 92, 96, 89, 28, 21, 8, 36, 9, 40, 85, 51, 1, 63, 68, 74, 26, 40, 3, 9, 32, 67, 4, 6, 73}, 25, 25, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "searchAnElementInAnArrayWhereDifferenceBetweenAdjacentElementsIs1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 7, \"inputs\": {\"arr\": [8, 7, 6, 7, 6, 5, 4, 3, 2, 3, 4, 3], \"n\": 12, \"x\": 3}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [6, 90], \"n\": 1, \"x\": 1}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"arr\": [1, 2, 3, 4, 5, 4], \"n\": 6, \"x\": 5}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [97, 35, 60, 96, 3, 67, 72, 95, 55, 9, 69, 28, 15, 91, 31, 59], \"n\": 15, \"x\": 9}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-84, -78, -74, -70, -68, -60, -56, -54, -48, -46, -28, -16, -6, 0, 0, 8, 8, 8, 12, 16, 26, 30, 32, 34, 36, 40, 46, 48, 70, 70, 72, 76, 78, 78, 80, 84, 84, 86], \"n\": 22, \"x\": 31}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1], \"n\": 5, \"x\": 7}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [55, 64, 76, 79, 93, 96], \"n\": 4, \"x\": 4}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [66, -90, 98, -50, 0, 46, 42, 64, -96, -80, -96, 20, -10, -84], \"n\": 8, \"x\": 13}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1], \"n\": 6, \"x\": 5}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [94, 4, 34, 87, 32, 3, 92, 68, 57, 76, 24, 33, 3, 4, 30, 70, 49, 30, 72, 82, 16, 53, 6, 24, 92, 96, 89, 28, 21, 8, 36, 9, 40, 85, 51, 1, 63, 68, 74, 26, 40, 3, 9, 32, 67, 4, 6, 73], \"n\": 25, \"x\": 25}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
479 | Search Insert And Delete In An Unsorted Array | C++ | int searchInsertAndDeleteInAnUnsortedArray(vector<int> arr, int n, int key) { | [
"arr",
"n",
"key"
] | def search_insert_and_delete_in_an_unsorted_array(arr, n, key):
for i in range(n):
if (arr[i] == key):
return i
return (- 1) | int search_insert_and_delete_in_an_unsorted_array(vector<int> arr, int n, int key) {
int i;
for ( i = 0;
i < n;
i ++ ) if ( arr [ i ] == key ) 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 key, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, key), 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, 8, 11, 23, 55, 57, 73, 74, 77, 79, 93}, 8, 11, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, 12, -62, -66, -24, 18, 12, 22, 94, 30, -50, -42, -94, 18, 76, -6, -48, -68, 48, 36, -78, 52, -82, 76, 2, -44, -10, 88}, 27, 12, 1); \n cout << \"TEST-\" << 1 << \"...\"\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}, 11, 0, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({33, 9, 93, 70, 81, 70, 56, 66, 72, 81, 74, 32, 71, 72, 3, 81, 70, 22, 82, 2, 75, 18, 90, 29, 48}, 24, 72, 8); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -70, -62, -60, -60, -54, -48, -48, -46, -44, -34, -26, -18, -6, 4, 18, 28, 32, 34, 40, 50, 54, 56, 62, 64, 64, 98}, 18, 23, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1}, 17, 16, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 6, 7, 10, 10, 12, 13, 18, 23, 29, 29, 34, 46, 54, 60, 61, 63, 67, 69, 70, 72, 76, 79, 79, 81, 82, 88, 90, 99}, 15, 28, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 34, -60, -74, 86, 80, 68, -48, 78, -62, -98, -44, -44, 92, -94, -86, -36, 12, 84, -90, 52, 42, -42, -66, 88, 76, 66}, 21, 16, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1}, 2, 3, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, 59, 38, 83, 38, 93, 27, 11, 17, 80, 26, 28, 35, 53, 88, 10, 9, 75}, 12, 13, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "searchInsertAndDeleteInAnUnsortedArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [4, 8, 11, 23, 55, 57, 73, 74, 77, 79, 93], \"n\": 8, \"key\": 11}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [-88, 12, -62, -66, -24, 18, 12, 22, 94, 30, -50, -42, -94, 18, 76, -6, -48, -68, 48, 36, -78, 52, -82, 76, 2, -44, -10, 88], \"n\": 27, \"key\": 12}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 11, \"key\": 0}}, {\"idx\": 3, \"outputs\": 8, \"inputs\": {\"arr\": [33, 9, 93, 70, 81, 70, 56, 66, 72, 81, 74, 32, 71, 72, 3, 81, 70, 22, 82, 2, 75, 18, 90, 29, 48], \"n\": 24, \"key\": 72}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-98, -70, -62, -60, -60, -54, -48, -48, -46, -44, -34, -26, -18, -6, 4, 18, 28, 32, 34, 40, 50, 54, 56, 62, 64, 64, 98], \"n\": 18, \"key\": 23}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1], \"n\": 17, \"key\": 16}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [4, 6, 7, 10, 10, 12, 13, 18, 23, 29, 29, 34, 46, 54, 60, 61, 63, 67, 69, 70, 72, 76, 79, 79, 81, 82, 88, 90, 99], \"n\": 15, \"key\": 28}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [94, 34, -60, -74, 86, 80, 68, -48, 78, -62, -98, -44, -44, 92, -94, -86, -36, 12, 84, -90, 52, 42, -42, -66, 88, 76, 66], \"n\": 21, \"key\": 16}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 1], \"n\": 2, \"key\": 3}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [76, 59, 38, 83, 38, 93, 27, 11, 17, 80, 26, 28, 35, 53, 88, 10, 9, 75], \"n\": 12, \"key\": 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
]
} |
480 | Search Insert And Delete In A Sorted Array | C++ | int searchInsertAndDeleteInASortedArray(vector<int> arr, int low, int high, int key) { | [
"arr",
"low",
"high",
"key"
] | def search_insert_and_delete_in_a_sorted_array(arr, low, high, key):
if (high < low):
return (- 1)
mid = ((low + high) / 2)
if (key == arr[int(mid)]):
return mid
if (key > arr[int(mid)]):
return search_insert_and_delete_in_a_sorted_array(arr, (mid + 1), high, key)
return search_insert_and_delete_in_a_sorted_array(arr, low, (mid - 1), key) | int search_insert_and_delete_in_a_sorted_array(vector<int> arr, int low, int high, int key) {
if ( high < low ) return - 1;
int mid = ( low + high ) / 2;
if ( key == arr [ mid ] ) return mid;
if ( key > arr [ mid ] ) return search_insert_and_delete_in_a_sorted_array ( arr, ( mid + 1 ), high, key );
return search_insert_and_delete_in_a_sorted_array ( arr, low, ( mid - 1 ), key );
} | {
"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 key, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, low, high, key), 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, 10, 73, 91, 98}, 2, 4, 4, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({30, 24, 24, -8, 64, 50, 46, -76, 26, 8, -92, -78, 40, -86, 96, 14, 60, 38, 6, -72, -6, -20, 26, -26, 0, 2}, 20, 13, 21, -1); \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}, 30, 27, 29, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({30, 79, 3, 76, 18}, 3, 2, 2, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -90, -88, -84, -78, -78, -70, -68, -66, -66, -64, -64, -58, -56, -52, -42, -40, -38, -36, -30, -30, -28, -14, -8, 0, 14, 16, 22, 24, 26, 36, 40, 40, 48, 48, 50, 52, 54, 54, 58, 64, 74, 82, 88, 94}, 35, 30, 40, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1}, 25, 26, 30, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 8, 8, 14, 15, 16, 17, 17, 18, 18, 24, 25, 25, 26, 36, 37, 39, 39, 40, 44, 46, 47, 51, 54, 56, 57, 57, 61, 61, 67, 68, 69, 72, 76, 77, 81, 82, 82, 82, 85, 85, 87, 94, 94, 98, 99}, 33, 40, 26, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-4, 84, 20, -84, -6, -78, 20, 56, 40, 0, 98, 80, -94, 36, -6, -98, 50, 66, -12, -58, -34, 68, -80, -30, -82, -76, -38, -60, 92, 94, 48, -84, 20, -66, -32, -92, 16, -96, -68, 94, -46, 30, 32, -34, 96, -92, -96, -86, -22}, 34, 27, 34, -1); \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}, 19, 13, 19, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({71, 70, 13, 18, 70, 62, 88, 27, 17, 44, 89, 28, 74, 41, 20, 91, 95, 79, 40, 43, 38, 20, 5}, 21, 22, 22, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "searchInsertAndDeleteInASortedArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"arr\": [2, 10, 73, 91, 98], \"low\": 2, \"high\": 4, \"key\": 4}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [30, 24, 24, -8, 64, 50, 46, -76, 26, 8, -92, -78, 40, -86, 96, 14, 60, 38, 6, -72, -6, -20, 26, -26, 0, 2], \"low\": 20, \"high\": 13, \"key\": 21}}, {\"idx\": 2, \"outputs\": -1, \"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], \"low\": 30, \"high\": 27, \"key\": 29}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [30, 79, 3, 76, 18], \"low\": 3, \"high\": 2, \"key\": 2}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-96, -90, -88, -84, -78, -78, -70, -68, -66, -66, -64, -64, -58, -56, -52, -42, -40, -38, -36, -30, -30, -28, -14, -8, 0, 14, 16, 22, 24, 26, 36, 40, 40, 48, 48, 50, 52, 54, 54, 58, 64, 74, 82, 88, 94], \"low\": 35, \"high\": 30, \"key\": 40}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1], \"low\": 25, \"high\": 26, \"key\": 30}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [2, 8, 8, 14, 15, 16, 17, 17, 18, 18, 24, 25, 25, 26, 36, 37, 39, 39, 40, 44, 46, 47, 51, 54, 56, 57, 57, 61, 61, 67, 68, 69, 72, 76, 77, 81, 82, 82, 82, 85, 85, 87, 94, 94, 98, 99], \"low\": 33, \"high\": 40, \"key\": 26}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-4, 84, 20, -84, -6, -78, 20, 56, 40, 0, 98, 80, -94, 36, -6, -98, 50, 66, -12, -58, -34, 68, -80, -30, -82, -76, -38, -60, 92, 94, 48, -84, 20, -66, -32, -92, 16, -96, -68, 94, -46, 30, 32, -34, 96, -92, -96, -86, -22], \"low\": 34, \"high\": 27, \"key\": 34}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"low\": 19, \"high\": 13, \"key\": 19}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [71, 70, 13, 18, 70, 62, 88, 27, 17, 44, 89, 28, 74, 41, 20, 91, 95, 79, 40, 43, 38, 20, 5], \"low\": 21, \"high\": 22, \"key\": 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
]
} |
481 | Search Insert And Delete In A Sorted Array 1 | C++ | int searchInsertAndDeleteInASortedArray1(vector<int> arr, int n, int key, int capacity) { | [
"arr",
"n",
"key",
"capacity"
] | def search_insert_and_delete_in_a_sorted_array_1(arr, n, key, capacity):
if (n >= capacity):
return n
i = (n - 1)
while ((i >= 0) and (arr[i] > key)):
arr[(i + 1)] = arr[i]
i -= 1
arr[(i + 1)] = key
return (n + 1) | int search_insert_and_delete_in_a_sorted_array_1(vector<int> arr, int n, int key, int capacity) {
if ( n >= capacity ) return n;
int i;
for ( i = n - 1;
( i >= 0 && arr [ i ] > key );
i -- ) arr [ i + 1 ] = arr [ i ];
arr [ i + 1 ] = key;
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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int key, int capacity, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, key, capacity), 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}, 0, 0, 0, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-34, -38, -72, 90, -84, -40, 6, -52, -12, 80, -4, -58}, 6, 6, 9, 7); \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}, 13, 19, 11, 13); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 34, 11, 1, 36, 79, 64, 75, 75, 96, 32, 18, 25, 79, 63, 80, 90, 75, 44, 71, 48, 1, 62, 53, 17, 98}, 21, 20, 13, 21); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -92, -84, -82, -80, -80, -74, -70, -60, -48, -42, -36, -34, -34, -34, -30, -28, -16, -6, -2, -2, 2, 12, 14, 20, 24, 40, 46, 50, 60, 66, 70, 72, 78, 82, 88, 92, 94, 94, 96}, 30, 32, 28, 30); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0}, 12, 9, 10, 12); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 12, 12, 13, 19, 20, 21, 24, 27, 37, 47, 50, 54, 58, 61, 63, 63, 68, 73, 75, 87, 90, 90, 92, 92}, 12, 13, 21, 13); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-74, 62, 74, 92, -38, -28, -26, 4, 88, -68, -76, -20, -4, 12, 72, 6, 42, 36, 88, -96, -80, 90, 80, -26, -36, -72, -62, 38, -20, 40, -10, -22, -20, 38, 82, -84, 8, 26, 86, -26, 44, -72, -70, -16, -22, 18, -16, 76, -50}, 37, 26, 42, 38); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1}, 3, 4, 2, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({64, 80, 47, 58, 41, 3, 85, 96, 51, 4, 22, 89, 67, 54, 88, 15, 83, 31, 19, 24, 28, 40, 67, 37, 63, 38, 27, 14, 7, 68}, 23, 24, 25, 24); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "searchInsertAndDeleteInASortedArray1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [69], \"n\": 0, \"key\": 0, \"capacity\": 0}}, {\"idx\": 1, \"outputs\": 7, \"inputs\": {\"arr\": [-34, -38, -72, 90, -84, -40, 6, -52, -12, 80, -4, -58], \"n\": 6, \"key\": 6, \"capacity\": 9}}, {\"idx\": 2, \"outputs\": 13, \"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], \"n\": 13, \"key\": 19, \"capacity\": 11}}, {\"idx\": 3, \"outputs\": 21, \"inputs\": {\"arr\": [96, 34, 11, 1, 36, 79, 64, 75, 75, 96, 32, 18, 25, 79, 63, 80, 90, 75, 44, 71, 48, 1, 62, 53, 17, 98], \"n\": 21, \"key\": 20, \"capacity\": 13}}, {\"idx\": 4, \"outputs\": 30, \"inputs\": {\"arr\": [-98, -92, -92, -84, -82, -80, -80, -74, -70, -60, -48, -42, -36, -34, -34, -34, -30, -28, -16, -6, -2, -2, 2, 12, 14, 20, 24, 40, 46, 50, 60, 66, 70, 72, 78, 82, 88, 92, 94, 94, 96], \"n\": 30, \"key\": 32, \"capacity\": 28}}, {\"idx\": 5, \"outputs\": 12, \"inputs\": {\"arr\": [1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0], \"n\": 12, \"key\": 9, \"capacity\": 10}}, {\"idx\": 6, \"outputs\": 13, \"inputs\": {\"arr\": [10, 12, 12, 13, 19, 20, 21, 24, 27, 37, 47, 50, 54, 58, 61, 63, 63, 68, 73, 75, 87, 90, 90, 92, 92], \"n\": 12, \"key\": 13, \"capacity\": 21}}, {\"idx\": 7, \"outputs\": 38, \"inputs\": {\"arr\": [-74, 62, 74, 92, -38, -28, -26, 4, 88, -68, -76, -20, -4, 12, 72, 6, 42, 36, 88, -96, -80, 90, 80, -26, -36, -72, -62, 38, -20, 40, -10, -22, -20, 38, 82, -84, 8, 26, 86, -26, 44, -72, -70, -16, -22, 18, -16, 76, -50], \"n\": 37, \"key\": 26, \"capacity\": 42}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"arr\": [1, 1, 1, 1, 1], \"n\": 3, \"key\": 4, \"capacity\": 2}}, {\"idx\": 9, \"outputs\": 24, \"inputs\": {\"arr\": [64, 80, 47, 58, 41, 3, 85, 96, 51, 4, 22, 89, 67, 54, 88, 15, 83, 31, 19, 24, 28, 40, 67, 37, 63, 38, 27, 14, 7, 68], \"n\": 23, \"key\": 24, \"capacity\": 25}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
482 | Sequences Given Length Every Element Equal Twice Previous | C++ | int sequencesGivenLengthEveryElementEqualTwicePrevious(int m, int n) { | [
"m",
"n"
] | def sequences_given_length_every_element_equal_twice_previous(m, n):
if (m < n):
return 0
if (n == 0):
return 1
res = (sequences_given_length_every_element_equal_twice_previous((m - 1), n) + sequences_given_length_every_element_equal_twice_previous((m // 2), (n - 1)))
return res | int sequences_given_length_every_element_equal_twice_previous(int m, int n) {
if ( m < n ) return 0;
if ( n == 0 ) return 1;
return sequences_given_length_every_element_equal_twice_previous ( m - 1, n ) + sequences_given_length_every_element_equal_twice_previous ( m / 2, 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(int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(m, 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(38, 34, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 29, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 99, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 23, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 2, 484); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 70, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 84, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 34, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 72, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 67, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sequencesGivenLengthEveryElementEqualTwicePrevious",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"m\": 38, \"n\": 34}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"m\": 39, \"n\": 29}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"m\": 24, \"n\": 99}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"m\": 90, \"n\": 23}}, {\"idx\": 4, \"outputs\": 484, \"inputs\": {\"m\": 44, \"n\": 2}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"m\": 49, \"n\": 70}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"m\": 58, \"n\": 84}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"m\": 97, \"n\": 34}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"m\": 99, \"n\": 72}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"m\": 19, \"n\": 67}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
483 | Sequences Given Length Every Element Equal Twice Previous 1 | C++ | int sequencesGivenLengthEveryElementEqualTwicePrevious1(int m, int n) { | [
"m",
"n"
] | def sequences_given_length_every_element_equal_twice_previous_1(m, n):
T = [[0 for i in range((n + 1))] for i in range((m + 1))]
for i in range((m + 1)):
for j in range((n + 1)):
if ((i == 0) or (j == 0)):
T[i][j] = 0
elif (i < j):
T[i][j] = 0
elif (j == 1):
T[i][j] = i
else:
T[i][j] = (T[(i - 1)][j] + T[(i // 2)][(j - 1)])
return T[m][n] | int sequences_given_length_every_element_equal_twice_previous_1(int m, int n) {
int T [ m + 1 ] [ n + 1 ];
for ( int i = 0;
i < m + 1;
i ++ ) {
for ( int j = 0;
j < n + 1;
j ++ ) {
if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0;
else if ( i < j ) T [ i ] [ j ] = 0;
else if ( j == 1 ) T [ i ] [ j ] = i;
else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ];
}
}
return T [ 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(int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(m, 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(10, 4, 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 2, 6); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 8, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 7, 330); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 0, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 53, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 41, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 53, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 37, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 20, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sequencesGivenLengthEveryElementEqualTwicePrevious1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"m\": 10, \"n\": 4}}, {\"idx\": 1, \"outputs\": 6, \"inputs\": {\"m\": 5, \"n\": 2}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"m\": 2, \"n\": 8}}, {\"idx\": 3, \"outputs\": 330, \"inputs\": {\"m\": 83, \"n\": 7}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"m\": 91, \"n\": 0}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"m\": 18, \"n\": 53}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"m\": 83, \"n\": 41}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"m\": 98, \"n\": 53}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"m\": 43, \"n\": 37}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"m\": 31, \"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
]
} |
484 | Smallest Difference Pair Values Two Unsorted Arrays | C++ | int smallestDifferencePairValuesTwoUnsortedArrays(vector<int> a, vector<int> b, int m, int n) { | [
"a",
"b",
"m",
"n"
] | def smallest_difference_pair_values_two_unsorted_arrays(A, B, m, n):
A.sort()
B.sort()
a = 0
b = 0
result = sys.maxsize
while ((a < m) and (b < n)):
if (abs((A[a] - B[b])) < result):
result = abs((A[a] - B[b]))
if (A[a] < B[b]):
a += 1
else:
b += 1
return result | int smallest_difference_pair_values_two_unsorted_arrays(vector<int> A, vector<int> B, int m, int n) {
sort(A.begin(), A.end());
sort(B.begin(), B.end());
int a = 0, b = 0;
int result = INT_MAX;
while ( a < m && b < n ) {
if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] );
if ( A [ a ] < B [ b ] ) a ++;
else b ++;
}
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> a, vector<int> b, int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, m, 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, 2, 11, 13, 18, 18, 23, 25, 28, 28, 37, 39, 53, 56, 67, 70, 74, 74, 75, 79, 80, 82, 84, 89, 94, 95, 95, 98, 98}, {5, 6, 11, 13, 13, 16, 17, 19, 23, 25, 28, 31, 31, 39, 41, 44, 45, 52, 62, 64, 70, 71, 73, 78, 78, 79, 85, 86, 92}, 28, 14, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -78, -78, -72, -72, -72, -70, -70, -64, -62, -50, -48, -48, -44, -44, -40, -36, -36, -30, -24, -24, -22, -12, -10, -8, -4, -4, 0, 6, 10, 22, 30, 38, 56, 62, 72, 86}, {-98, -98, -90, -84, -80, -78, -68, -62, -52, -50, -42, -30, -26, -24, -24, -24, -12, 2, 10, 14, 18, 22, 26, 26, 36, 42, 50, 60, 62, 64, 64, 72, 76, 78, 84, 86, 92}, 23, 33, 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, 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}, 14, 16, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 9, 15, 24, 28, 28, 39, 47, 57, 61, 71, 82, 90}, {11, 26, 27, 41, 47, 49, 51, 54, 70, 77, 84, 85, 92}, 7, 8, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -90, -90, -28, -16, -14, -14, -8, 42, 52, 62, 84}, {-98, -98, -58, -6, 14, 16, 18, 46, 52, 52, 52, 56}, 11, 6, 2); \n cout << \"TEST-\" << 4 << \"...\"\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, 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, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 35, 33, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 7, 7, 12, 15, 15, 21, 24, 26, 26, 28, 36, 38, 42, 46, 52, 55, 56, 59, 62, 63, 65, 65, 66, 68, 71, 73, 77, 77, 77, 77, 85, 87, 87, 88, 90, 93, 94, 98}, {1, 3, 4, 4, 6, 7, 8, 8, 15, 17, 18, 18, 20, 23, 23, 24, 25, 25, 26, 33, 39, 43, 46, 54, 59, 67, 69, 69, 69, 69, 76, 76, 81, 81, 85, 86, 86, 91, 95}, 30, 20, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-82, -68, -68, -60, -60, -38, -20, -16, 4, 18, 18, 22, 24, 30, 34, 44, 70, 78, 88, 90, 94}, {-74, -68, -64, -62, -60, -52, -50, -44, -36, -34, -32, -30, -20, -18, -14, -2, 18, 62, 62, 84, 98}, 16, 12, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1}, {0, 0, 1}, 2, 1, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 7, 7, 9, 14, 15, 16, 20, 21, 26, 35, 37, 40, 45, 46, 47, 53, 56, 58, 61, 62, 67, 70, 70, 71, 73, 81, 85, 85, 90, 94, 98, 99}, {1, 7, 14, 16, 18, 19, 24, 27, 28, 29, 29, 37, 41, 44, 45, 48, 49, 55, 64, 67, 67, 71, 72, 79, 80, 84, 86, 88, 88, 92, 94, 98, 99}, 20, 25, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "smallestDifferencePairValuesTwoUnsortedArrays",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"a\": [2, 2, 11, 13, 18, 18, 23, 25, 28, 28, 37, 39, 53, 56, 67, 70, 74, 74, 75, 79, 80, 82, 84, 89, 94, 95, 95, 98, 98], \"b\": [5, 6, 11, 13, 13, 16, 17, 19, 23, 25, 28, 31, 31, 39, 41, 44, 45, 52, 62, 64, 70, 71, 73, 78, 78, 79, 85, 86, 92], \"m\": 28, \"n\": 14}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"a\": [-94, -78, -78, -72, -72, -72, -70, -70, -64, -62, -50, -48, -48, -44, -44, -40, -36, -36, -30, -24, -24, -22, -12, -10, -8, -4, -4, 0, 6, 10, 22, 30, 38, 56, 62, 72, 86], \"b\": [-98, -98, -90, -84, -80, -78, -68, -62, -52, -50, -42, -30, -26, -24, -24, -24, -12, 2, 10, 14, 18, 22, 26, 26, 36, 42, 50, 60, 62, 64, 64, 72, 76, 78, 84, 86, 92], \"m\": 23, \"n\": 33}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": [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], \"b\": [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], \"m\": 14, \"n\": 16}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"a\": [2, 9, 15, 24, 28, 28, 39, 47, 57, 61, 71, 82, 90], \"b\": [11, 26, 27, 41, 47, 49, 51, 54, 70, 77, 84, 85, 92], \"m\": 7, \"n\": 8}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"a\": [-92, -90, -90, -28, -16, -14, -14, -8, 42, 52, 62, 84], \"b\": [-98, -98, -58, -6, 14, 16, 18, 46, 52, 52, 52, 56], \"m\": 11, \"n\": 6}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [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], \"b\": [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], \"m\": 35, \"n\": 33}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"a\": [6, 7, 7, 12, 15, 15, 21, 24, 26, 26, 28, 36, 38, 42, 46, 52, 55, 56, 59, 62, 63, 65, 65, 66, 68, 71, 73, 77, 77, 77, 77, 85, 87, 87, 88, 90, 93, 94, 98], \"b\": [1, 3, 4, 4, 6, 7, 8, 8, 15, 17, 18, 18, 20, 23, 23, 24, 25, 25, 26, 33, 39, 43, 46, 54, 59, 67, 69, 69, 69, 69, 76, 76, 81, 81, 85, 86, 86, 91, 95], \"m\": 30, \"n\": 20}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"a\": [-82, -68, -68, -60, -60, -38, -20, -16, 4, 18, 18, 22, 24, 30, 34, 44, 70, 78, 88, 90, 94], \"b\": [-74, -68, -64, -62, -60, -52, -50, -44, -36, -34, -32, -30, -20, -18, -14, -2, 18, 62, 62, 84, 98], \"m\": 16, \"n\": 12}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 1], \"b\": [0, 0, 1], \"m\": 2, \"n\": 1}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"a\": [2, 7, 7, 9, 14, 15, 16, 20, 21, 26, 35, 37, 40, 45, 46, 47, 53, 56, 58, 61, 62, 67, 70, 70, 71, 73, 81, 85, 85, 90, 94, 98, 99], \"b\": [1, 7, 14, 16, 18, 19, 24, 27, 28, 29, 29, 37, 41, 44, 45, 48, 49, 55, 64, 67, 67, 71, 72, 79, 80, 84, 86, 88, 88, 92, 94, 98, 99], \"m\": 20, \"n\": 25}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
485 | Smallest Of Three Integers Without Comparison Operators | C++ | int smallestOfThreeIntegersWithoutComparisonOperators(int x, int y, int z) { | [
"x",
"y",
"z"
] | def smallest_of_three_integers_without_comparison_operators(x, y, z):
c = 0
while (x and y and z):
x = (x - 1)
y = (y - 1)
z = (z - 1)
c = (c + 1)
return c | int smallest_of_three_integers_without_comparison_operators(int x, int y, int z) {
int c = 0;
while ( x && y && z ) {
x --;
y --;
z --;
c ++;
}
return c;
} | {
"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 z, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y, z), 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, 98, 25, 23); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 55, 94, 55); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 90, 29, 29); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 9, 41, 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 22, 39, 22); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 42, 96, 42); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 88, 26, 26); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 64, 51, 51); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 1, 6, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 44, 76, 44); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "smallestOfThreeIntegersWithoutComparisonOperators",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 23, \"inputs\": {\"x\": 23, \"y\": 98, \"z\": 25}}, {\"idx\": 1, \"outputs\": 55, \"inputs\": {\"x\": 87, \"y\": 55, \"z\": 94}}, {\"idx\": 2, \"outputs\": 29, \"inputs\": {\"x\": 35, \"y\": 90, \"z\": 29}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"x\": 25, \"y\": 9, \"z\": 41}}, {\"idx\": 4, \"outputs\": 22, \"inputs\": {\"x\": 93, \"y\": 22, \"z\": 39}}, {\"idx\": 5, \"outputs\": 42, \"inputs\": {\"x\": 52, \"y\": 42, \"z\": 96}}, {\"idx\": 6, \"outputs\": 26, \"inputs\": {\"x\": 95, \"y\": 88, \"z\": 26}}, {\"idx\": 7, \"outputs\": 51, \"inputs\": {\"x\": 91, \"y\": 64, \"z\": 51}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"x\": 75, \"y\": 1, \"z\": 6}}, {\"idx\": 9, \"outputs\": 44, \"inputs\": {\"x\": 96, \"y\": 44, \"z\": 76}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
486 | Smallest Of Three Integers Without Comparison Operators 1 | C++ | int smallestOfThreeIntegersWithoutComparisonOperators1(int x, int y, int z) { | [
"x",
"y",
"z"
] | def smallest_of_three_integers_without_comparison_operators_1(x, y, z):
if (not (y / x)):
return (y if (not (y / z)) else z)
return (x if (not (x / z)) else z) | int smallest_of_three_integers_without_comparison_operators_1(int x, int y, int z) {
if ( ! ( y / x ) ) return ( ! ( y / z ) ) ? y : z;
return ( ! ( x / z ) ) ? x : z;
} | {
"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 z, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y, z), 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(48, 63, 56, 56); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 55, 84, 84); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 89, 96, 96); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 71, 74, 74); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 39, 42, 42); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 44, 86, 86); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 41, 68, 68); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 62, 94, 94); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 2, 83, 83); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 11, 1, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "smallestOfThreeIntegersWithoutComparisonOperators1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 56, \"inputs\": {\"x\": 48, \"y\": 63, \"z\": 56}}, {\"idx\": 1, \"outputs\": 84, \"inputs\": {\"x\": 11, \"y\": 55, \"z\": 84}}, {\"idx\": 2, \"outputs\": 96, \"inputs\": {\"x\": 50, \"y\": 89, \"z\": 96}}, {\"idx\": 3, \"outputs\": 74, \"inputs\": {\"x\": 21, \"y\": 71, \"z\": 74}}, {\"idx\": 4, \"outputs\": 42, \"inputs\": {\"x\": 94, \"y\": 39, \"z\": 42}}, {\"idx\": 5, \"outputs\": 86, \"inputs\": {\"x\": 22, \"y\": 44, \"z\": 86}}, {\"idx\": 6, \"outputs\": 68, \"inputs\": {\"x\": 3, \"y\": 41, \"z\": 68}}, {\"idx\": 7, \"outputs\": 94, \"inputs\": {\"x\": 67, \"y\": 62, \"z\": 94}}, {\"idx\": 8, \"outputs\": 83, \"inputs\": {\"x\": 59, \"y\": 2, \"z\": 83}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"x\": 50, \"y\": 11, \"z\": 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
]
} |
487 | Smallest Power Of 2 Greater Than Or Equal To N | C++ | int smallestPowerOf2GreaterThanOrEqualToN(int n) { | [
"n"
] | def smallest_power_of_2_greater_than_or_equal_to_n(n):
count = 0
if (n and (not (n & (n - 1)))):
return n
while (n != 0):
n >>= 1
count += 1
return (1 << count) | unsigned int smallest_power_of_2_greater_than_or_equal_to_n(unsigned int n) {
unsigned count = 0;
if ( n && ! ( n & ( n - 1 ) ) ) return n;
while ( n != 0 ) {
n >>= 1;
count += 1;
}
return 1 << 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 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(13, 16); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 32); \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(24, 32); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 128); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 128); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 64); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 64); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 128); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 64); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "smallestPowerOf2GreaterThanOrEqualToN",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 16, \"inputs\": {\"n\": 13}}, {\"idx\": 1, \"outputs\": 32, \"inputs\": {\"n\": 27}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"n\": 1}}, {\"idx\": 3, \"outputs\": 32, \"inputs\": {\"n\": 24}}, {\"idx\": 4, \"outputs\": 128, \"inputs\": {\"n\": 98}}, {\"idx\": 5, \"outputs\": 128, \"inputs\": {\"n\": 94}}, {\"idx\": 6, \"outputs\": 64, \"inputs\": {\"n\": 36}}, {\"idx\": 7, \"outputs\": 64, \"inputs\": {\"n\": 41}}, {\"idx\": 8, \"outputs\": 128, \"inputs\": {\"n\": 74}}, {\"idx\": 9, \"outputs\": 64, \"inputs\": {\"n\": 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
]
} |
488 | Smallest Power Of 2 Greater Than Or Equal To N 1 | C++ | int smallestPowerOf2GreaterThanOrEqualToN1(int n) { | [
"n"
] | def smallest_power_of_2_greater_than_or_equal_to_n_1(n):
p = 1
if (n and (not (n & (n - 1)))):
return n
while (p < n):
p <<= 1
return p | unsigned int smallest_power_of_2_greater_than_or_equal_to_n_1(unsigned int n) {
unsigned int p = 1;
if ( n && ! ( n & ( n - 1 ) ) ) return n;
while ( p < n ) p <<= 1;
return p;
} | {
"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(31, 32); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 128); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 128); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 128); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 64); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 64); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 32); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 32); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 64); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 32); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "smallestPowerOf2GreaterThanOrEqualToN1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 32, \"inputs\": {\"n\": 31}}, {\"idx\": 1, \"outputs\": 128, \"inputs\": {\"n\": 89}}, {\"idx\": 2, \"outputs\": 128, \"inputs\": {\"n\": 92}}, {\"idx\": 3, \"outputs\": 128, \"inputs\": {\"n\": 66}}, {\"idx\": 4, \"outputs\": 64, \"inputs\": {\"n\": 38}}, {\"idx\": 5, \"outputs\": 64, \"inputs\": {\"n\": 34}}, {\"idx\": 6, \"outputs\": 32, \"inputs\": {\"n\": 17}}, {\"idx\": 7, \"outputs\": 32, \"inputs\": {\"n\": 24}}, {\"idx\": 8, \"outputs\": 64, \"inputs\": {\"n\": 54}}, {\"idx\": 9, \"outputs\": 32, \"inputs\": {\"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
]
} |
489 | Smallest Power Of 2 Greater Than Or Equal To N 2 | C++ | int smallestPowerOf2GreaterThanOrEqualToN2(int n) { | [
"n"
] | def smallest_power_of_2_greater_than_or_equal_to_n_2(n):
n -= 1
n |= (n >> 1)
n |= (n >> 2)
n |= (n >> 4)
n |= (n >> 8)
n |= (n >> 16)
n += 1
return n | unsigned int smallest_power_of_2_greater_than_or_equal_to_n_2(unsigned int n) {
n --;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n ++;
return 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(60, 64); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 32); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 64); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 64); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 128); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 128); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 32); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 64); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 64); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 32); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "smallestPowerOf2GreaterThanOrEqualToN2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 64, \"inputs\": {\"n\": 60}}, {\"idx\": 1, \"outputs\": 32, \"inputs\": {\"n\": 20}}, {\"idx\": 2, \"outputs\": 64, \"inputs\": {\"n\": 33}}, {\"idx\": 3, \"outputs\": 64, \"inputs\": {\"n\": 34}}, {\"idx\": 4, \"outputs\": 128, \"inputs\": {\"n\": 68}}, {\"idx\": 5, \"outputs\": 128, \"inputs\": {\"n\": 79}}, {\"idx\": 6, \"outputs\": 32, \"inputs\": {\"n\": 20}}, {\"idx\": 7, \"outputs\": 64, \"inputs\": {\"n\": 41}}, {\"idx\": 8, \"outputs\": 64, \"inputs\": {\"n\": 36}}, {\"idx\": 9, \"outputs\": 32, \"inputs\": {\"n\": 17}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
490 | Smallest Sum Contiguous Subarray | C++ | int smallestSumContiguousSubarray(vector<int> arr, int n) { | [
"arr",
"n"
] | def smallest_sum_contiguous_subarray(arr, n):
min_ending_here = sys.maxsize
min_so_far = sys.maxsize
for i in range(n):
if (min_ending_here > 0):
min_ending_here = arr[i]
else:
min_ending_here += arr[i]
min_so_far = min(min_so_far, min_ending_here)
return min_so_far | int smallest_sum_contiguous_subarray(vector<int> arr, int n) {
int min_ending_here = INT_MAX;
int min_so_far = INT_MAX;
for ( int i = 0;
i < n;
i ++ ) {
if ( min_ending_here > 0 ) min_ending_here = arr [ i ];
else min_ending_here += arr [ i ];
min_so_far = min ( min_so_far, min_ending_here );
}
return min_so_far;
} | {
"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({2, 9, 13, 14, 15, 18, 19, 19, 25, 26, 29, 29, 29, 30, 31, 36, 37, 37, 38, 39, 39, 40, 40, 42, 42, 46, 50, 53, 58, 60, 62, 64, 65, 67, 68, 69, 72, 77, 78, 83, 85, 89, 90, 93, 95, 95, 97}, 24, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, -58, 8, 78, -26, -20, -60, 42, -64, -12}, 6, -58); \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, 1, 1}, 8, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({44, 88, 20, 47, 69, 42, 26, 49, 71, 91, 18, 95, 9, 66, 60, 37, 47, 29, 98, 63, 15, 9, 80, 66, 1, 9, 57, 56, 20, 2, 1}, 26, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, -64, -62, -60, -52, 4, 8, 46, 72, 74}, 8, -316); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1}, 11, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 7, 16, 17, 23, 23, 23, 28, 29, 30, 34, 38, 40, 41, 43, 43, 44, 46, 51, 51, 51, 55, 57, 58, 61, 62, 66, 66, 67, 69, 70, 73, 75, 77, 79, 80, 85, 85, 87, 87, 93, 96}, 38, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, 22, 38, 26, 62, -48, -48, 46, -54, 4, 76, 46, 48, 40, -92, -98, -88, 12, -42, -94, 76, -16, -82, 62, 18, -24}, 22, -402); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 13, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 44, 1, 97, 50, 74, 62, 90, 3, 78, 8, 48, 96, 41, 36, 91, 57, 97, 85, 90, 78, 43, 28, 92, 85, 59, 29, 38, 34, 65, 20, 26, 27, 23, 71, 22, 47, 99, 68, 93, 67, 66, 69, 82, 98, 15, 44, 51, 65}, 45, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "smallestSumContiguousSubarray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [2, 9, 13, 14, 15, 18, 19, 19, 25, 26, 29, 29, 29, 30, 31, 36, 37, 37, 38, 39, 39, 40, 40, 42, 42, 46, 50, 53, 58, 60, 62, 64, 65, 67, 68, 69, 72, 77, 78, 83, 85, 89, 90, 93, 95, 95, 97], \"n\": 24}}, {\"idx\": 1, \"outputs\": -58, \"inputs\": {\"arr\": [14, -58, 8, 78, -26, -20, -60, 42, -64, -12], \"n\": 6}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 8}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [44, 88, 20, 47, 69, 42, 26, 49, 71, 91, 18, 95, 9, 66, 60, 37, 47, 29, 98, 63, 15, 9, 80, 66, 1, 9, 57, 56, 20, 2, 1], \"n\": 26}}, {\"idx\": 4, \"outputs\": -316, \"inputs\": {\"arr\": [-78, -64, -62, -60, -52, 4, 8, 46, 72, 74], \"n\": 8}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1], \"n\": 11}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"arr\": [3, 7, 16, 17, 23, 23, 23, 28, 29, 30, 34, 38, 40, 41, 43, 43, 44, 46, 51, 51, 51, 55, 57, 58, 61, 62, 66, 66, 67, 69, 70, 73, 75, 77, 79, 80, 85, 85, 87, 87, 93, 96], \"n\": 38}}, {\"idx\": 7, \"outputs\": -402, \"inputs\": {\"arr\": [80, 22, 38, 26, 62, -48, -48, 46, -54, 4, 76, 46, 48, 40, -92, -98, -88, 12, -42, -94, 76, -16, -82, 62, 18, -24], \"n\": 22}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [85, 44, 1, 97, 50, 74, 62, 90, 3, 78, 8, 48, 96, 41, 36, 91, 57, 97, 85, 90, 78, 43, 28, 92, 85, 59, 29, 38, 34, 65, 20, 26, 27, 23, 71, 22, 47, 99, 68, 93, 67, 66, 69, 82, 98, 15, 44, 51, 65], \"n\": 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
]
} |
496 | Space Optimized Solution Lcs | C++ | int spaceOptimizedSolutionLcs(string x, string y) { | [
"x",
"y"
] | def space_optimized_solution_lcs(X, Y):
m = len(X)
n = len(Y)
L = [[0 for i in range((n + 1))] for j in range(2)]
bi = bool
for i in range(m):
bi = (i & 1)
for j in range((n + 1)):
if ((i == 0) or (j == 0)):
L[bi][j] = 0
elif (X[i] == Y[(j - 1)]):
L[bi][j] = (L[(1 - bi)][(j - 1)] + 1)
else:
L[bi][j] = max(L[(1 - bi)][j], L[bi][(j - 1)])
return L[bi][n] | int space_optimized_solution_lcs(string & X, string & Y) {
int m = X . length ( ), n = Y . length ( );
int L [ 2 ] [ n + 1 ];
bool bi;
for ( int i = 0;
i <= m;
i ++ ) {
bi = i & 1;
for ( int j = 0;
j <= n;
j ++ ) {
if ( i == 0 || j == 0 ) L [ bi ] [ j ] = 0;
else if ( X [ i - 1 ] == Y [ j - 1 ] ) L [ bi ] [ j ] = L [ 1 - bi ] [ j - 1 ] + 1;
else L [ bi ] [ j ] = max ( L [ 1 - bi ] [ j ], L [ bi ] [ j - 1 ] );
}
}
return L [ bi ] [ 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 x, string 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(\"YNpjSv\", \"qtUkJn\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"736519\", \"07592\", 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11010000100010\", \"0\", 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"v \", \"qGBQT\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"8311172\", \"157219329531\", 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100011101011\", \"1000001111\", 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"u\", \"YzkubTqLhP\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"3943042\", \"3859\", 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"101\", \"00010000101010\", 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"MpbfF OsizevaM\", \"WgsFGaQwtp\", 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "spaceOptimizedSolutionLcs",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"x\": \"YNpjSv\", \"y\": \"qtUkJn\"}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"x\": \"736519\", \"y\": \"07592\"}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"x\": \"11010000100010\", \"y\": \"0\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"x\": \"v \", \"y\": \"qGBQT\"}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"x\": \"8311172\", \"y\": \"157219329531\"}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"x\": \"100011101011\", \"y\": \"1000001111\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"x\": \"u\", \"y\": \"YzkubTqLhP\"}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"x\": \"3943042\", \"y\": \"3859\"}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"x\": \"101\", \"y\": \"00010000101010\"}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"x\": \"MpbfF OsizevaM\", \"y\": \"WgsFGaQwtp\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
498 | Split N Maximum Composite Numbers | C++ | int splitNMaximumCompositeNumbers(int n) { | [
"n"
] | def split_n_maximum_composite_numbers(n):
if (n < 4):
return (- 1)
rem = (n % 4)
if (rem == 0):
return (n // 4)
if (rem == 1):
if (n < 9):
return (- 1)
return (((n - 9) // 4) + 1)
if (rem == 2):
return (((n - 6) // 4) + 1)
if (rem == 3):
if (n < 15):
return (- 1)
return (((n - 15) // 4) + 2) | int split_n_maximum_composite_numbers(int n) {
if ( n < 4 ) return - 1;
int rem = n % 4;
if ( rem == 0 ) return n / 4;
if ( rem == 1 ) {
if ( n < 9 ) return - 1;
return ( n - 9 ) / 4 + 1;
}
if ( rem == 2 ) return ( n - 6 ) / 4 + 1;
if ( rem == 3 ) {
if ( n < 15 ) return - 1;
return ( n - 15 ) / 4 + 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 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(55, 12); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 7); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 17); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 12); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 7); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 15); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 13); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "splitNMaximumCompositeNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 12, \"inputs\": {\"n\": 55}}, {\"idx\": 1, \"outputs\": 7, \"inputs\": {\"n\": 35}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"n\": 24}}, {\"idx\": 3, \"outputs\": 17, \"inputs\": {\"n\": 75}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"n\": 5}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"n\": 7}}, {\"idx\": 6, \"outputs\": 12, \"inputs\": {\"n\": 50}}, {\"idx\": 7, \"outputs\": 7, \"inputs\": {\"n\": 28}}, {\"idx\": 8, \"outputs\": 15, \"inputs\": {\"n\": 67}}, {\"idx\": 9, \"outputs\": 13, \"inputs\": {\"n\": 59}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
499 | Squared Triangular Number Sum Cubes | C++ | int squaredTriangularNumberSumCubes(int s) { | [
"s"
] | def squared_triangular_number_sum_cubes(s):
_sum = 0
n = 1
while (_sum < s):
_sum += ((n * n) * n)
n += 1
n -= 1
if (_sum == s):
return n
return (- 1) | int squared_triangular_number_sum_cubes(int s) {
int sum = 0;
for ( int n = 1;
sum < s;
n ++ ) {
sum += n * n * n;
if ( sum == s ) return n;
}
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(int 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(15, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "squaredTriangularNumberSumCubes",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"s\": 15}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"s\": 36}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"s\": 39}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"s\": 43}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"s\": 75}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"s\": 49}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"s\": 56}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"s\": 14}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"s\": 62}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"s\": 97}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
500 | Square Pyramidal Number Sum Squares | C++ | int squarePyramidalNumberSumSquares(int s) { | [
"s"
] | def square_pyramidal_number_sum_squares(s):
_sum = 0
n = 1
while (_sum < s):
_sum += (n * n)
n += 1
n -= 1
if (_sum == s):
return n
return (- 1) | int square_pyramidal_number_sum_squares(int s) {
int sum = 0;
for ( int n = 1;
sum < s;
n ++ ) {
sum += n * n;
if ( sum == s ) return n;
}
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(int 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(1, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(140, 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(204, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(506, 11); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "squarePyramidalNumberSumSquares",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"s\": 1}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"s\": 5}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"s\": 14}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"s\": 140}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"s\": 204}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"s\": 3}}, {\"idx\": 6, \"outputs\": 11, \"inputs\": {\"s\": 506}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"s\": 42}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"s\": 4}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"s\": 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
]
} |
501 | Square Root Of An Integer | C++ | int squareRootOfAnInteger(int x) { | [
"x"
] | def square_root_of_an_integer(x):
if ((x == 0) or (x == 1)):
return x
i = 1
result = 1
while (result <= x):
i += 1
result = (i * i)
return (i - 1) | int square_root_of_an_integer(int x) {
if ( x == 0 || x == 1 ) return x;
int i = 1, result = 1;
while ( result <= x ) {
i ++;
result = i * i;
}
return i - 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 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(89, 9); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 7); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 9); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 8); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "squareRootOfAnInteger",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 9, \"inputs\": {\"x\": 89}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"x\": 11}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"x\": 14}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"x\": 92}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"x\": 76}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"x\": 63}}, {\"idx\": 6, \"outputs\": 7, \"inputs\": {\"x\": 51}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"x\": 16}}, {\"idx\": 8, \"outputs\": 9, \"inputs\": {\"x\": 83}}, {\"idx\": 9, \"outputs\": 8, \"inputs\": {\"x\": 66}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
502 | Square Root Of An Integer 1 | C++ | int squareRootOfAnInteger1(int x) { | [
"x"
] | def square_root_of_an_integer_1(x):
if ((x == 0) or (x == 1)):
return x
start = 1
end = x
while (start <= end):
mid = ((start + end) // 2)
if ((mid * mid) == x):
return mid
if ((mid * mid) < x):
start = (mid + 1)
ans = mid
else:
end = (mid - 1)
return ans | int square_root_of_an_integer_1(int x) {
if ( x == 0 || x == 1 ) return x;
int start = 1, end = x, ans;
while ( start <= end ) {
int mid = ( start + end ) / 2;
if ( mid * mid == x ) return mid;
if ( mid * mid < x ) {
start = mid + 1;
ans = mid;
}
else end = mid - 1;
}
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(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(40, 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 8); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 8); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 8); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "squareRootOfAnInteger1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"x\": 40}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"x\": 10}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"x\": 46}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"x\": 54}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"x\": 1}}, {\"idx\": 5, \"outputs\": 8, \"inputs\": {\"x\": 67}}, {\"idx\": 6, \"outputs\": 8, \"inputs\": {\"x\": 64}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"x\": 10}}, {\"idx\": 8, \"outputs\": 8, \"inputs\": {\"x\": 75}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"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
]
} |
503 | Stack Permutations Check If An Array Is Stack Permutation Of Other | C++ | bool stackPermutationsCheckIfAnArrayIsStackPermutationOfOther(vector<int> ip, vector<int> op, int n) { | [
"ip",
"op",
"n"
] | def stack_permutations_check_if_an_array_is_stack_permutation_of_other(ip, op, n):
Input = Queue()
for i in range(n):
Input.put(ip[i])
output = Queue()
for i in range(n):
output.put(op[i])
tempStack = []
while (not Input.empty()):
ele = Input.queue[0]
Input.get()
if (ele == output.queue[0]):
output.get()
while (len(tempStack) != 0):
if (tempStack[(- 1)] == output.queue[0]):
tempStack.pop()
output.get()
else:
break
else:
tempStack.append(ele)
return (Input.empty() and (len(tempStack) == 0)) | bool stack_permutations_check_if_an_array_is_stack_permutation_of_other(vector<int> ip, vector<int> op, int n) {
queue < int > input;
for ( int i = 0;
i < n;
i ++ ) input . push ( ip [ i ] );
queue < int > output;
for ( int i = 0;
i < n;
i ++ ) output . push ( op [ i ] );
stack < int > tempStack;
while ( ! input . empty ( ) ) {
int ele = input . front ( );
input . pop ( );
if ( ele == output . front ( ) ) {
output . pop ( );
while ( ! tempStack . empty ( ) ) {
if ( tempStack . top ( ) == output . front ( ) ) {
tempStack . pop ( );
output . pop ( );
}
else break;
}
}
else tempStack . push ( ele );
}
return ( input . empty ( ) && tempStack . empty ( ) );
} | {
"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> ip, vector<int> op, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(ip, op, 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, 3, 3, 4, 5, 6, 9, 18, 20, 35, 39, 39, 45, 50, 55, 57, 61, 63, 65, 72, 73, 77, 77, 78, 87, 88, 91, 93, 95, 98}, {2, 5, 7, 13, 16, 23, 24, 25, 27, 31, 31, 33, 34, 35, 38, 46, 49, 49, 51, 52, 58, 61, 62, 66, 68, 71, 73, 78, 91, 94, 98}, 23, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, 10, -8, 8, -24, -2, -84, -86, -54, 50, 56, -22, -8, -62, 0, -50, -32}, {-8, -46, 22, -66, -94, -96, 70, 58, -4, -70, -96, 34, -80, -26, -52, 52, -76}, 16, 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}, {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}, 21, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 42, 88, 89, 41, 71, 67, 5, 84, 20, 75, 36, 34, 20, 31, 16, 86, 89, 53, 47, 57, 27, 47, 93, 59, 66, 40, 18, 69, 36, 98, 99, 81}, {16, 61, 39, 99, 71, 73, 35, 47, 62, 80, 1, 49, 54, 35, 39, 55, 7, 6, 85, 84, 11, 51, 38, 4, 72, 10, 33, 65, 64, 32, 16, 99, 9}, 19, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -94, -94, -90, -88, -82, -80, -78, -78, -68, -58, -58, -52, -36, -30, -14, -12, -6, -2, -2, 2, 4, 10, 14, 22, 24, 26, 38, 38, 46, 46, 48, 50, 54, 58, 60, 64, 64, 66, 70, 74, 74, 86, 88, 96, 96}, {-92, -92, -80, -72, -72, -72, -70, -68, -64, -56, -40, -38, -34, -24, -10, -8, -8, -2, 0, 2, 4, 6, 14, 14, 18, 20, 34, 36, 36, 38, 38, 42, 48, 56, 64, 70, 72, 76, 76, 76, 76, 78, 84, 90, 94, 96}, 27, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0}, 19, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({19, 37, 44, 65, 72, 87}, {17, 31, 39, 46, 56, 88}, 4, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({88}, {-30}, 0, true); \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}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, 13, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 8, 53, 60, 85, 94, 77, 53, 81, 54, 67, 48, 56, 49, 16, 1, 85, 6, 55, 98, 62, 36, 4, 7, 64}, {69, 37, 32, 5, 84, 14, 25, 9, 86, 85, 30, 82, 99, 92, 32, 43, 79, 58, 75, 90, 49, 54, 95, 76, 80}, 12, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "stackPermutationsCheckIfAnArrayIsStackPermutationOfOther",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"ip\": [2, 3, 3, 3, 4, 5, 6, 9, 18, 20, 35, 39, 39, 45, 50, 55, 57, 61, 63, 65, 72, 73, 77, 77, 78, 87, 88, 91, 93, 95, 98], \"op\": [2, 5, 7, 13, 16, 23, 24, 25, 27, 31, 31, 33, 34, 35, 38, 46, 49, 49, 51, 52, 58, 61, 62, 66, 68, 71, 73, 78, 91, 94, 98], \"n\": 23}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"ip\": [-86, 10, -8, 8, -24, -2, -84, -86, -54, 50, 56, -22, -8, -62, 0, -50, -32], \"op\": [-8, -46, 22, -66, -94, -96, 70, 58, -4, -70, -96, 34, -80, -26, -52, 52, -76], \"n\": 16}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"ip\": [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], \"op\": [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\": 21}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"ip\": [3, 42, 88, 89, 41, 71, 67, 5, 84, 20, 75, 36, 34, 20, 31, 16, 86, 89, 53, 47, 57, 27, 47, 93, 59, 66, 40, 18, 69, 36, 98, 99, 81], \"op\": [16, 61, 39, 99, 71, 73, 35, 47, 62, 80, 1, 49, 54, 35, 39, 55, 7, 6, 85, 84, 11, 51, 38, 4, 72, 10, 33, 65, 64, 32, 16, 99, 9], \"n\": 19}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"ip\": [-98, -94, -94, -90, -88, -82, -80, -78, -78, -68, -58, -58, -52, -36, -30, -14, -12, -6, -2, -2, 2, 4, 10, 14, 22, 24, 26, 38, 38, 46, 46, 48, 50, 54, 58, 60, 64, 64, 66, 70, 74, 74, 86, 88, 96, 96], \"op\": [-92, -92, -80, -72, -72, -72, -70, -68, -64, -56, -40, -38, -34, -24, -10, -8, -8, -2, 0, 2, 4, 6, 14, 14, 18, 20, 34, 36, 36, 38, 38, 42, 48, 56, 64, 70, 72, 76, 76, 76, 76, 78, 84, 90, 94, 96], \"n\": 27}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"ip\": [1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], \"op\": [0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0], \"n\": 19}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"ip\": [19, 37, 44, 65, 72, 87], \"op\": [17, 31, 39, 46, 56, 88], \"n\": 4}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"ip\": [88], \"op\": [-30], \"n\": 0}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"ip\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"op\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"ip\": [5, 8, 53, 60, 85, 94, 77, 53, 81, 54, 67, 48, 56, 49, 16, 1, 85, 6, 55, 98, 62, 36, 4, 7, 64], \"op\": [69, 37, 32, 5, 84, 14, 25, 9, 86, 85, 30, 82, 99, 92, 32, 43, 79, 58, 75, 90, 49, 54, 95, 76, 80], \"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
]
} |
504 | Steins Algorithm For Finding Gcd 1 | C++ | int steinsAlgorithmForFindingGcd1(int a, int b) { | [
"a",
"b"
] | def steins_algorithm_for_finding_gcd_1(a, b):
if (a == b):
return a
if (a == 0):
return b
if (b == 0):
return a
if (((~ a) & 1) == 1):
if ((b & 1) == 1):
return steins_algorithm_for_finding_gcd_1((a >> 1), b)
else:
return (steins_algorithm_for_finding_gcd_1((a >> 1), (b >> 1)) << 1)
if (((~ b) & 1) == 1):
return steins_algorithm_for_finding_gcd_1(a, (b >> 1))
if (a > b):
return steins_algorithm_for_finding_gcd_1(((a - b) >> 1), b)
return steins_algorithm_for_finding_gcd_1(((b - a) >> 1), a) | int steins_algorithm_for_finding_gcd_1(int a, int b) {
if ( a == b ) return a;
if ( a == 0 ) return b;
if ( b == 0 ) return a;
if ( ~ a & 1 ) {
if ( b & 1 ) return steins_algorithm_for_finding_gcd_1 ( a >> 1, b );
else return steins_algorithm_for_finding_gcd_1 ( a >> 1, b >> 1 ) << 1;
}
if ( ~ b & 1 ) return steins_algorithm_for_finding_gcd_1 ( a, b >> 1 );
if ( a > b ) return steins_algorithm_for_finding_gcd_1 ( ( a - b ) >> 1, b );
return steins_algorithm_for_finding_gcd_1 ( ( b - a ) >> 1, 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(52, 29, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 94, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 6, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 7, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 11, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 51, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 55, 5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 86, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 63, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 12, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "steinsAlgorithmForFindingGcd1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"a\": 52, \"b\": 29}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"a\": 36, \"b\": 94}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"a\": 12, \"b\": 6}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"a\": 69, \"b\": 7}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"a\": 45, \"b\": 11}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"a\": 7, \"b\": 51}}, {\"idx\": 6, \"outputs\": 5, \"inputs\": {\"a\": 45, \"b\": 55}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"a\": 62, \"b\": 86}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"a\": 96, \"b\": 63}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"a\": 89, \"b\": 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
]
} |
506 | String Containing First Letter Every Word Given String Spaces | C++ | string stringContainingFirstLetterEveryWordGivenStringSpaces(string str) { | [
"str"
] | def string_containing_first_letter_every_word_given_string_spaces(str):
result = ''
v = True
for i in range(len(str)):
if (str[i] == ' '):
v = True
elif ((str[i] != ' ') and (v == True)):
result += str[i]
v = False
return result | string string_containing_first_letter_every_word_given_string_spaces(string str) {
string result = "";
bool v = true;
for ( int i = 0;
i < str . length ( );
i ++ ) {
if ( str [ i ] == ' ' ) v = true;
else if ( str [ i ] != ' ' && v == true ) {
result . push_back ( str [ i ] );
v = false;
}
}
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(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string str, string 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(\"t a\", \"ta\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"77 78 2 600 7\", \"77267\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011 10 10\", \"011\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kV Co O iR\", \"kCOi\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2\", \"2\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0 11\", \"01\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Y sT wgheC\", \"Ysw\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"58 824 6\", \"586\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00 100 001 0111\", \"0100\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Q\", \"Q\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "stringContainingFirstLetterEveryWordGivenStringSpaces",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": \"ta\", \"inputs\": {\"str\": \"t a\"}}, {\"idx\": 1, \"outputs\": \"77267\", \"inputs\": {\"str\": \"77 78 2 600 7\"}}, {\"idx\": 2, \"outputs\": \"011\", \"inputs\": {\"str\": \"011 10 10\"}}, {\"idx\": 3, \"outputs\": \"kCOi\", \"inputs\": {\"str\": \"kV Co O iR\"}}, {\"idx\": 4, \"outputs\": \"2\", \"inputs\": {\"str\": \"2\"}}, {\"idx\": 5, \"outputs\": \"01\", \"inputs\": {\"str\": \"0 11\"}}, {\"idx\": 6, \"outputs\": \"Ysw\", \"inputs\": {\"str\": \"Y sT wgheC\"}}, {\"idx\": 7, \"outputs\": \"586\", \"inputs\": {\"str\": \"58 824 6\"}}, {\"idx\": 8, \"outputs\": \"0100\", \"inputs\": {\"str\": \"00 100 001 0111\"}}, {\"idx\": 9, \"outputs\": \"Q\", \"inputs\": {\"str\": \"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
]
} |
508 | Subarrays Distinct Elements | C++ | int subarraysDistinctElements(vector<int> arr, int n) { | [
"arr",
"n"
] | def subarrays_distinct_elements(arr, n):
s = []
j = 0
ans = 0
for i in range(n):
while ((j < n) and (arr[j] not in s)):
s.append(arr[j])
j += 1
ans += (((j - i) * ((j - i) + 1)) // 2)
s.remove(arr[i])
return ans | int subarrays_distinct_elements(vector<int> arr, int n) {
unordered_set < int > s;
int j = 0, ans = 0;
for ( int i = 0;
i < n;
i ++ ) {
while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) {
s . insert ( arr [ j ] );
j ++;
}
ans += ( ( j - i ) * ( j - i + 1 ) ) / 2;
s . erase ( arr [ i ] );
}
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({3, 4, 5, 6, 12, 15, 16, 17, 20, 20, 22, 24, 24, 27, 28, 34, 37, 39, 39, 41, 43, 49, 49, 51, 55, 62, 63, 67, 71, 74, 74, 74, 77, 84, 84, 89, 89, 97, 99}, 24, 255); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-8, 54, -22, 18, 20, 44, 0, 54, 90, -4, 4, 40, -74, -16}, 13, 335); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 28, 30); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({36, 71, 36, 58, 38, 90, 17}, 4, 13); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -32, -16, 18, 38, 82}, 5, 35); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1}, 2, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 11, 21, 25, 28, 28, 38, 42, 48, 53, 55, 55, 55, 58, 71, 75, 79, 80, 80, 94, 96, 99}, 20, 152); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-16, -52, -4, -46, 54, 0, 8, -64, -82, -10, -62, -10, 58, 44, -28, 86, -24, 16, 44, 22, -28, -42, -52, 8, 76, -44, -34, 2, 88, -88, -14, -84, -36, -68, 76, 20, 20, -50}, 35, 1791); \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, 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}, 27, 29); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({19, 13, 61, 32, 92, 90, 12, 81, 52}, 5, 35); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "subarraysDistinctElements",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 255, \"inputs\": {\"arr\": [3, 4, 5, 6, 12, 15, 16, 17, 20, 20, 22, 24, 24, 27, 28, 34, 37, 39, 39, 41, 43, 49, 49, 51, 55, 62, 63, 67, 71, 74, 74, 74, 77, 84, 84, 89, 89, 97, 99], \"n\": 24}}, {\"idx\": 1, \"outputs\": 335, \"inputs\": {\"arr\": [-8, 54, -22, 18, 20, 44, 0, 54, 90, -4, 4, 40, -74, -16], \"n\": 13}}, {\"idx\": 2, \"outputs\": 30, \"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], \"n\": 28}}, {\"idx\": 3, \"outputs\": 13, \"inputs\": {\"arr\": [36, 71, 36, 58, 38, 90, 17], \"n\": 4}}, {\"idx\": 4, \"outputs\": 35, \"inputs\": {\"arr\": [-90, -32, -16, 18, 38, 82], \"n\": 5}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"arr\": [1, 0, 1], \"n\": 2}}, {\"idx\": 6, \"outputs\": 152, \"inputs\": {\"arr\": [3, 11, 21, 25, 28, 28, 38, 42, 48, 53, 55, 55, 55, 58, 71, 75, 79, 80, 80, 94, 96, 99], \"n\": 20}}, {\"idx\": 7, \"outputs\": 1791, \"inputs\": {\"arr\": [-16, -52, -4, -46, 54, 0, 8, -64, -82, -10, -62, -10, 58, 44, -28, 86, -24, 16, 44, 22, -28, -42, -52, 8, 76, -44, -34, 2, 88, -88, -14, -84, -36, -68, 76, 20, 20, -50], \"n\": 35}}, {\"idx\": 8, \"outputs\": 29, \"inputs\": {\"arr\": [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, 1, 1], \"n\": 27}}, {\"idx\": 9, \"outputs\": 35, \"inputs\": {\"arr\": [19, 13, 61, 32, 92, 90, 12, 81, 52], \"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
]
} |
509 | Subsequences Size Three Array Whose Sum Divisible M | C++ | int subsequencesSizeThreeArrayWhoseSumDivisibleM(vector<int> a, int n, int m) { | [
"a",
"n",
"m"
] | def subsequences_size_three_array_whose_sum_divisible_m(A, N, M):
sum = 0
ans = 0
for i in range(0, N):
for j in range((i + 1), N):
for k in range((j + 1), N):
sum = ((A[i] + A[j]) + A[k])
if ((sum % M) == 0):
ans = (ans + 1)
return ans | int subsequences_size_three_array_whose_sum_divisible_m(vector<int> A, int N, int M) {
int sum = 0;
int ans = 0;
for ( int i = 0;
i < N;
i ++ ) {
for ( int j = i + 1;
j < N;
j ++ ) {
for ( int k = j + 1;
k < N;
k ++ ) {
sum = A [ i ] + A [ j ] + A [ k ];
if ( sum % M == 0 ) 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> a, int n, int m, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, 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({14, 35, 56, 70, 88}, 3, 4, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-50, -92, 16, -68, -36}, 3, 4, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1}, 4, 5, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, 43, 22, 41, 49, 99, 25, 40, 3, 45, 60, 16, 83, 62, 26, 93, 64, 73, 72, 53, 6, 32, 35, 67, 17}, 14, 21, 19); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -86, -86, -66, -50, -48, -44, -42, -42, -38, -24, -22, -20, -18, -8, 8, 24, 28, 34, 48, 60, 62, 66, 68, 74, 76, 80, 82, 88}, 24, 20, 207); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0}, 24, 30, 120); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 8, 9, 10, 12, 13, 16, 17, 18, 21, 21, 25, 27, 28, 30, 36, 36, 54, 55, 56, 57, 60, 62, 67, 67, 68, 71, 72, 72, 73, 73, 77, 77, 83, 86, 86, 86, 87, 89, 92, 92, 96, 97, 97, 98}, 24, 23, 85); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-64, 52, -32, 38, 8, -62, -56, 20, 72, -12, 32, 44}, 6, 6, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 12, 15, 220); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({77, 68, 45, 6, 27, 19, 29, 95, 21, 2, 39, 48, 72, 67, 49, 45, 1, 16, 56, 78, 25, 22, 27, 40, 31, 34, 26, 35, 12}, 25, 25, 92); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "subsequencesSizeThreeArrayWhoseSumDivisibleM",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"a\": [14, 35, 56, 70, 88], \"n\": 3, \"m\": 4}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"a\": [-50, -92, 16, -68, -36], \"n\": 3, \"m\": 4}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"a\": [0, 0, 0, 1, 1, 1], \"n\": 4, \"m\": 5}}, {\"idx\": 3, \"outputs\": 19, \"inputs\": {\"a\": [76, 43, 22, 41, 49, 99, 25, 40, 3, 45, 60, 16, 83, 62, 26, 93, 64, 73, 72, 53, 6, 32, 35, 67, 17], \"n\": 14, \"m\": 21}}, {\"idx\": 4, \"outputs\": 207, \"inputs\": {\"a\": [-90, -86, -86, -66, -50, -48, -44, -42, -42, -38, -24, -22, -20, -18, -8, 8, 24, 28, 34, 48, 60, 62, 66, 68, 74, 76, 80, 82, 88], \"n\": 24, \"m\": 20}}, {\"idx\": 5, \"outputs\": 120, \"inputs\": {\"a\": [1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0], \"n\": 24, \"m\": 30}}, {\"idx\": 6, \"outputs\": 85, \"inputs\": {\"a\": [4, 5, 8, 9, 10, 12, 13, 16, 17, 18, 21, 21, 25, 27, 28, 30, 36, 36, 54, 55, 56, 57, 60, 62, 67, 67, 68, 71, 72, 72, 73, 73, 77, 77, 83, 86, 86, 86, 87, 89, 92, 92, 96, 97, 97, 98], \"n\": 24, \"m\": 23}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"a\": [-64, 52, -32, 38, 8, -62, -56, 20, 72, -12, 32, 44], \"n\": 6, \"m\": 6}}, {\"idx\": 8, \"outputs\": 220, \"inputs\": {\"a\": [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], \"n\": 12, \"m\": 15}}, {\"idx\": 9, \"outputs\": 92, \"inputs\": {\"a\": [77, 68, 45, 6, 27, 19, 29, 95, 21, 2, 39, 48, 72, 67, 49, 45, 1, 16, 56, 78, 25, 22, 27, 40, 31, 34, 26, 35, 12], \"n\": 25, \"m\": 25}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
510 | Subsequences Size Three Array Whose Sum Divisible M 1 | C++ | float subsequencesSizeThreeArrayWhoseSumDivisibleM1(vector<int> a, int n, int m) { | [
"a",
"n",
"m"
] | def subsequences_size_three_array_whose_sum_divisible_m_1(A, N, M):
ans = 0
h = ([0] * M)
for i in range(0, N):
A[i] = (A[i] % M)
h[A[i]] = (h[A[i]] + 1)
for i in range(0, M):
for j in range(i, M):
rem = ((M - ((i + j) % M)) % M)
if (rem < j):
continue
if ((i == j) and (rem == j)):
ans = (ans + (((h[i] * (h[i] - 1)) * (h[i] - 2)) / 6))
elif (i == j):
ans = (ans + (((h[i] * (h[i] - 1)) * h[rem]) / 2))
elif (i == rem):
ans = (ans + (((h[i] * (h[i] - 1)) * h[j]) / 2))
elif (rem == j):
ans = (ans + (((h[j] * (h[j] - 1)) * h[i]) / 2))
else:
ans = (ans + ((h[i] * h[j]) * h[rem]))
return ans | int subsequences_size_three_array_whose_sum_divisible_m_1(vector<int> A, int N, int M) {
int ans = 0;
int h [ M ] = {
0 };
for ( int i = 0;
i < N;
i ++ ) {
A [ i ] = A [ i ] % M;
h [ A [ i ] ] ++;
}
for ( int i = 0;
i < M;
i ++ ) {
for ( int j = i;
j < M;
j ++ ) {
int rem = ( M - ( i + j ) % M ) % M;
if ( rem < j ) continue;
if ( i == j && rem == j ) ans += h [ i ] * ( h [ i ] - 1 ) * ( h [ i ] - 2 ) / 6;
else if ( i == j ) ans += h [ i ] * ( h [ i ] - 1 ) * h [ rem ] / 2;
else if ( i == rem ) ans += h [ i ] * ( h [ i ] - 1 ) * h [ j ] / 2;
else if ( rem == j ) ans += h [ j ] * ( h [ j ] - 1 ) * h [ i ] / 2;
else ans = ans + h [ i ] * h [ j ] * h [ rem ];
}
}
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(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(vector<int> a, int n, int m, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, 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({6, 7, 13, 16, 19, 20, 0, 4, 7, 10, 15, 17, 0, 2, 8, 12, 13, 14, 0, 0, 0, 2, 2, 2, 4, 8, 10, 73, 76, 78, 87, 90, 91, 99}, 27, 21, 75.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 13, 19, 15, 14, 11, 19, 4, 1, 18, 7, 5, 15, 9, 5, 11, 6, 18, 5, 19, 9, 7, 9, 19, 9, 12, 20, 12, 2, 66, 94, 12, 10, 4, 40, -72, 20, -2, -90, -90}, 29, 21, 0.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, 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}, 29, 43, 1140.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 3, 37, 91}, 3, 4, 0.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 6, 10, 10, 4, 2, 10, 2, 2, 10, 0, 8, 10, 86, 88}, 13, 12, 17.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1}, 11, 15, 56.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 0, 2, 3, 0, 1, 58, 78}, 7, 4, 6.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 2, 2, 12, 4, 8, 8, 6, 10, 12, 10, 4, 4, -2, -4}, 13, 14, 12.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, 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, 34, 286.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({27, 1, 31, 14, 20, 8, 23, 12, 15, 0, 15, 26, 3, 8, 3, 26, 15, 31, 97, 90, 1, 69, 77, 20, 68, 11, 2, 92, 50, 8, 23, 83, 76, 6, 32, 43, 92}, 18, 35, 6.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "subsequencesSizeThreeArrayWhoseSumDivisibleM1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 75.0, \"inputs\": {\"a\": [6, 7, 13, 16, 19, 20, 0, 4, 7, 10, 15, 17, 0, 2, 8, 12, 13, 14, 0, 0, 0, 2, 2, 2, 4, 8, 10, 73, 76, 78, 87, 90, 91, 99], \"n\": 27, \"m\": 21}}, {\"idx\": 1, \"outputs\": 0.0, \"inputs\": {\"a\": [7, 13, 19, 15, 14, 11, 19, 4, 1, 18, 7, 5, 15, 9, 5, 11, 6, 18, 5, 19, 9, 7, 9, 19, 9, 12, 20, 12, 2, 66, 94, 12, 10, 4, 40, -72, 20, -2, -90, -90], \"n\": 29, \"m\": 21}}, {\"idx\": 2, \"outputs\": 1140.0, \"inputs\": {\"a\": [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, 1], \"n\": 29, \"m\": 43}}, {\"idx\": 3, \"outputs\": 0.0, \"inputs\": {\"a\": [1, 2, 3, 37, 91], \"n\": 3, \"m\": 4}}, {\"idx\": 4, \"outputs\": 17.0, \"inputs\": {\"a\": [8, 6, 10, 10, 4, 2, 10, 2, 2, 10, 0, 8, 10, 86, 88], \"n\": 13, \"m\": 12}}, {\"idx\": 5, \"outputs\": 56.0, \"inputs\": {\"a\": [1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1], \"n\": 11, \"m\": 15}}, {\"idx\": 6, \"outputs\": 6.0, \"inputs\": {\"a\": [1, 2, 0, 2, 3, 0, 1, 58, 78], \"n\": 7, \"m\": 4}}, {\"idx\": 7, \"outputs\": 12.0, \"inputs\": {\"a\": [0, 2, 2, 12, 4, 8, 8, 6, 10, 12, 10, 4, 4, -2, -4], \"n\": 13, \"m\": 14}}, {\"idx\": 8, \"outputs\": 286.0, \"inputs\": {\"a\": [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], \"n\": 37, \"m\": 34}}, {\"idx\": 9, \"outputs\": 6.0, \"inputs\": {\"a\": [27, 1, 31, 14, 20, 8, 23, 12, 15, 0, 15, 26, 3, 8, 3, 26, 15, 31, 97, 90, 1, 69, 77, 20, 68, 11, 2, 92, 50, 8, 23, 83, 76, 6, 32, 43, 92], \"n\": 18, \"m\": 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
]
} |
511 | Subset Sum Divisible M | C++ | bool subsetSumDivisibleM(vector<int> arr, int n, int m) { | [
"arr",
"n",
"m"
] | def subset_sum_divisible_m(arr, n, m):
if (n > m):
return True
DP = [False for i in range(m)]
for i in range(n):
if DP[0]:
return True
temp = [False for i in range(m)]
for j in range(m):
if (DP[j] == True):
if (DP[((j + arr[i]) % m)] == False):
temp[((j + arr[i]) % m)] = True
for j in range(m):
if temp[j]:
DP[j] = True
DP[(arr[i] % m)] = True
return DP[0] | bool subset_sum_divisible_m(vector<int> arr, int n, int m) {
if ( n > m ) return true;
bool DP [ m ];
memset ( DP, false, m );
for ( int i = 0;
i < n;
i ++ ) {
if ( DP [ 0 ] ) return true;
bool temp [ m ];
memset ( temp, false, m );
for ( int j = 0;
j < m;
j ++ ) {
if ( DP [ j ] == true ) {
if ( DP [ ( j + arr [ i ] ) % m ] == false ) temp [ ( j + arr [ i ] ) % m ] = true;
}
}
for ( int j = 0;
j < m;
j ++ ) if ( temp [ j ] ) DP [ j ] = true;
DP [ arr [ i ] % m ] = true;
}
return DP [ 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(vector<int> arr, int n, int m, bool 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, 7, 12, 13, 13, 15, 18, 20, 21, 22, 26, 27, 41, 41, 50, 53, 57, 58, 58, 61, 62, 62, 64, 70, 75, 78, 79, 81, 81, 81, 83, 86, 91, 93, 95, 97, 99, 99}, 36, 35, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 16, 62, -24, 14, -4, 2, 50, -64, -76, 78, 66, -64, 18}, 12, 11, 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, 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}, 32, 27, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 20, 79, 42, 85, 24, 20, 76, 36, 88, 40, 5, 24, 85, 7, 19, 43, 51, 94, 13, 53, 93, 92, 43, 97, 38, 80, 48, 52, 47, 77, 56, 41, 80, 32, 34, 77, 14, 70, 3}, 29, 27, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -72, -58, -48, -36, -28, -26, -10, -10, -8, -8, -6, 2, 14, 30, 30, 54, 58, 60, 64, 68, 78, 84, 96, 98}, 16, 18, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0}, 7, 8, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 7, 8, 15, 18, 23, 24, 25, 27, 35, 40, 42, 43, 46, 48, 50, 53, 64, 66, 69, 70, 71, 72, 77, 78, 80, 81, 81, 81, 82, 82, 82, 84, 87, 97, 98}, 23, 32, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 54, 24, -10}, 3, 3, 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, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 34, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({39, 21, 38, 6, 38, 44, 96, 1, 16, 1, 28, 4, 55, 8}, 12, 11, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "subsetSumDivisibleM",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"arr\": [2, 5, 7, 12, 13, 13, 15, 18, 20, 21, 22, 26, 27, 41, 41, 50, 53, 57, 58, 58, 61, 62, 62, 64, 70, 75, 78, 79, 81, 81, 81, 83, 86, 91, 93, 95, 97, 99, 99], \"n\": 36, \"m\": 35}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"arr\": [8, 16, 62, -24, 14, -4, 2, 50, -64, -76, 78, 66, -64, 18], \"n\": 12, \"m\": 11}}, {\"idx\": 2, \"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, 1, 1, 1, 1], \"n\": 32, \"m\": 27}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [50, 20, 79, 42, 85, 24, 20, 76, 36, 88, 40, 5, 24, 85, 7, 19, 43, 51, 94, 13, 53, 93, 92, 43, 97, 38, 80, 48, 52, 47, 77, 56, 41, 80, 32, 34, 77, 14, 70, 3], \"n\": 29, \"m\": 27}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-96, -94, -72, -58, -48, -36, -28, -26, -10, -10, -8, -8, -6, 2, 14, 30, 30, 54, 58, 60, 64, 68, 78, 84, 96, 98], \"n\": 16, \"m\": 18}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"arr\": [1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0], \"n\": 7, \"m\": 8}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"arr\": [2, 7, 8, 15, 18, 23, 24, 25, 27, 35, 40, 42, 43, 46, 48, 50, 53, 64, 66, 69, 70, 71, 72, 77, 78, 80, 81, 81, 81, 82, 82, 82, 84, 87, 97, 98], \"n\": 23, \"m\": 32}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"arr\": [46, 54, 24, -10], \"n\": 3, \"m\": 3}}, {\"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, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 21, \"m\": 34}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"arr\": [39, 21, 38, 6, 38, 44, 96, 1, 16, 1, 28, 4, 55, 8], \"n\": 12, \"m\": 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
]
} |
512 | Sum Binomial Coefficients | C++ | long long sumBinomialCoefficients(int n) { | [
"n"
] | def sum_binomial_coefficients(n):
C = [([0] * (n + 2)) for i in range(0, (n + 2))]
for i in range(0, (n + 1)):
for j in range(0, (min(i, n) + 1)):
if ((j == 0) or (j == i)):
C[i][j] = 1
else:
C[i][j] = (C[(i - 1)][(j - 1)] + C[(i - 1)][j])
sum = 0
for i in range(0, (n + 1)):
sum += C[n][i]
return sum | int sum_binomial_coefficients(int n) {
int C [ n + 1 ] [ n + 1 ];
for ( int i = 0;
i <= n;
i ++ ) {
for ( int j = 0;
j <= min ( i, n );
j ++ ) {
if ( j == 0 || j == i ) C [ i ] [ j ] = 1;
else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ];
}
}
int sum = 0;
for ( int i = 0;
i <= n;
i ++ ) sum += C [ n ] [ i ];
return 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(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(8, 256); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 549755813888); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 33554432); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 17592186044416); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 64); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 281474976710656); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 549755813888); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumBinomialCoefficients",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 256, \"inputs\": {\"n\": 8}}, {\"idx\": 1, \"outputs\": 549755813888, \"inputs\": {\"n\": 39}}, {\"idx\": 2, \"outputs\": 33554432, \"inputs\": {\"n\": 25}}, {\"idx\": 3, \"outputs\": 17592186044416, \"inputs\": {\"n\": 44}}, {\"idx\": 4, \"outputs\": 64, \"inputs\": {\"n\": 6}}, {\"idx\": 5, \"outputs\": 281474976710656, \"inputs\": {\"n\": 48}}, {\"idx\": 6, \"outputs\": 549755813888, \"inputs\": {\"n\": 39}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
513 | Sum Binomial Coefficients 1 | C++ | long long sumBinomialCoefficients1(int n) { | [
"n"
] | def sum_binomial_coefficients_1(n):
return (1 << n) | int sum_binomial_coefficients_1(int n) {
return ( 1 << 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(48, 281474976710656); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 4398046511104); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 32768); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 8388608); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 2199023255552); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 70368744177664); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 68719476736); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 9007199254740992); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumBinomialCoefficients1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 281474976710656, \"inputs\": {\"n\": 48}}, {\"idx\": 1, \"outputs\": 4398046511104, \"inputs\": {\"n\": 42}}, {\"idx\": 2, \"outputs\": 32768, \"inputs\": {\"n\": 15}}, {\"idx\": 3, \"outputs\": 8388608, \"inputs\": {\"n\": 23}}, {\"idx\": 4, \"outputs\": 2199023255552, \"inputs\": {\"n\": 41}}, {\"idx\": 5, \"outputs\": 70368744177664, \"inputs\": {\"n\": 46}}, {\"idx\": 6, \"outputs\": 68719476736, \"inputs\": {\"n\": 36}}, {\"idx\": 7, \"outputs\": 9007199254740992, \"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
]
} |
514 | Sum Divisors 1 N 1 | C++ | int sumDivisors1N1(int n) { | [
"n"
] | def sum_divisors_1_n_1(n):
sum = 0
for i in range(1, (n + 1)):
sum += (int((n / i)) * i)
return int(sum) | int sum_divisors_1_n_1(int n) {
int sum = 0;
for ( int i = 1;
i <= n;
++ i ) sum += ( n / i ) * i;
return 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(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(73, 4406); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 1384); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 1098); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 660); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 1987); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 491); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 5977); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 2846); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 5561); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 1342); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumDivisors1N1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 4406, \"inputs\": {\"n\": 73}}, {\"idx\": 1, \"outputs\": 1384, \"inputs\": {\"n\": 41}}, {\"idx\": 2, \"outputs\": 1098, \"inputs\": {\"n\": 36}}, {\"idx\": 3, \"outputs\": 660, \"inputs\": {\"n\": 28}}, {\"idx\": 4, \"outputs\": 1987, \"inputs\": {\"n\": 49}}, {\"idx\": 5, \"outputs\": 491, \"inputs\": {\"n\": 24}}, {\"idx\": 6, \"outputs\": 5977, \"inputs\": {\"n\": 85}}, {\"idx\": 7, \"outputs\": 2846, \"inputs\": {\"n\": 59}}, {\"idx\": 8, \"outputs\": 5561, \"inputs\": {\"n\": 82}}, {\"idx\": 9, \"outputs\": 1342, \"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
]
} |
515 | Sum Factors Number | C++ | int sumFactorsNumber(int n) { | [
"n"
] | def sum_factors_number(n):
result = 0
for i in range(2, (int(math.sqrt(n)) + 1)):
if ((n % i) == 0):
if (i == (n / i)):
result = (result + i)
else:
result = (result + (i + (n // i)))
return ((result + n) + 1) | int sum_factors_number(int n) {
int result = 0;
for ( int i = 2;
i <= sqrt ( n );
i ++ ) {
if ( n % i == 0 ) {
if ( i == ( n / i ) ) result += i;
else result += ( i + n / i );
}
}
return ( result + 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(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(76, 140); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 32); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 7); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 57); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 48); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 72); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 44); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 56); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 91); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 6); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumFactorsNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 140, \"inputs\": {\"n\": 76}}, {\"idx\": 1, \"outputs\": 32, \"inputs\": {\"n\": 21}}, {\"idx\": 2, \"outputs\": 7, \"inputs\": {\"n\": 4}}, {\"idx\": 3, \"outputs\": 57, \"inputs\": {\"n\": 49}}, {\"idx\": 4, \"outputs\": 48, \"inputs\": {\"n\": 35}}, {\"idx\": 5, \"outputs\": 72, \"inputs\": {\"n\": 55}}, {\"idx\": 6, \"outputs\": 44, \"inputs\": {\"n\": 43}}, {\"idx\": 7, \"outputs\": 56, \"inputs\": {\"n\": 39}}, {\"idx\": 8, \"outputs\": 91, \"inputs\": {\"n\": 36}}, {\"idx\": 9, \"outputs\": 6, \"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
]
} |
516 | Sum Fai Aj Pairs Array N Integers | C++ | int sumFaiAjPairsArrayNIntegers(vector<int> a, int n) { | [
"a",
"n"
] | def sum_fai_aj_pairs_array_n_integers(a, n):
cnt = dict()
ans = 0
pre_sum = 0
for i in range(n):
ans += ((i * a[i]) - pre_sum)
pre_sum += a[i]
if ((a[i] - 1) in cnt):
ans -= cnt[(a[i] - 1)]
if ((a[i] + 1) in cnt):
ans += cnt[(a[i] + 1)]
if (a[i] not in cnt):
cnt[a[i]] = 0
cnt[a[i]] += 1
return ans | int sum_fai_aj_pairs_array_n_integers(vector<int> a, int n) {
unordered_map < int, int > cnt;
int ans = 0, pre_sum = 0;
for ( int i = 0;
i < n;
i ++ ) {
ans += ( i * a [ i ] ) - pre_sum;
pre_sum += a [ i ];
if ( cnt [ a [ i ] - 1 ] ) ans -= cnt [ a [ i ] - 1 ];
if ( cnt [ a [ i ] + 1 ] ) ans += cnt [ a [ i ] + 1 ];
cnt [ a [ i ] ] ++;
}
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> a, int n, int 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({2, 8, 12, 19, 23, 23, 26, 39, 54, 56, 57, 57, 73, 78, 83, 83, 89, 91}, 15, 3278); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({62, -34, 10, -28, -42, -12, 4, 20, -20, -84, -76, -16, -44, 26, -78, -40, 50, -10, -56, 76, -88, 24, 64, 10, 64, -8, -68, -42, 26, 24, 62, 36, -68, 8, -68, -2, 8, 38, -18}, 20, -112); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 18, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({23, 14, 44, 29, 93, 56, 22, 29, 97, 71, 43, 72, 74, 8, 92, 40, 18, 34, 78, 79, 93, 63, 79, 44, 35, 72, 88, 83, 40, 89, 66, 66, 54, 56, 44, 62, 72, 94, 79, 79, 24, 55, 72, 37, 27, 55, 16, 58, 83}, 25, 2551); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -90, -90, -86, -82, -80, -80, -58, -48, -40, -32, -32, -20, -20, -20, -12, -12, -6, -6, -2, 0, 4, 16, 16, 16, 42, 48, 58, 64, 68, 76, 76, 76, 78, 80, 82, 88, 88, 88, 92, 94, 96, 98}, 27, 16640); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1}, 34, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 4, 8, 10, 10, 11, 15, 19, 19, 20, 24, 25, 25, 27, 30, 41, 43, 44, 45, 47, 55, 59, 59, 61, 63, 63, 67, 67, 69, 72, 73, 75, 77, 77, 78, 81, 81, 83, 84, 92, 94, 99}, 31, 12408); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, -86, 94, 54, -52, 86, 68, 64, 98, 54, -14, -60, -60, -92, 80, -16, 28, 16, -74, 68, 32, -54, 58, -16, -2, -52, -92, -36, 96, -18, 14, 76, 16}, 26, -6856); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1, 1}, 7, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 28, 63, 2, 78, 12, 51, 82, 89, 65, 99}, 8, 542); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumFaiAjPairsArrayNIntegers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3278, \"inputs\": {\"a\": [2, 8, 12, 19, 23, 23, 26, 39, 54, 56, 57, 57, 73, 78, 83, 83, 89, 91], \"n\": 15}}, {\"idx\": 1, \"outputs\": -112, \"inputs\": {\"a\": [62, -34, 10, -28, -42, -12, 4, 20, -20, -84, -76, -16, -44, 26, -78, -40, 50, -10, -56, 76, -88, 24, 64, 10, 64, -8, -68, -42, 26, 24, 62, 36, -68, 8, -68, -2, 8, 38, -18], \"n\": 20}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": [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], \"n\": 18}}, {\"idx\": 3, \"outputs\": 2551, \"inputs\": {\"a\": [23, 14, 44, 29, 93, 56, 22, 29, 97, 71, 43, 72, 74, 8, 92, 40, 18, 34, 78, 79, 93, 63, 79, 44, 35, 72, 88, 83, 40, 89, 66, 66, 54, 56, 44, 62, 72, 94, 79, 79, 24, 55, 72, 37, 27, 55, 16, 58, 83], \"n\": 25}}, {\"idx\": 4, \"outputs\": 16640, \"inputs\": {\"a\": [-96, -94, -90, -90, -86, -82, -80, -80, -58, -48, -40, -32, -32, -20, -20, -20, -12, -12, -6, -6, -2, 0, 4, 16, 16, 16, 42, 48, 58, 64, 68, 76, 76, 76, 78, 80, 82, 88, 88, 88, 92, 94, 96, 98], \"n\": 27}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1], \"n\": 34}}, {\"idx\": 6, \"outputs\": 12408, \"inputs\": {\"a\": [3, 4, 4, 8, 10, 10, 11, 15, 19, 19, 20, 24, 25, 25, 27, 30, 41, 43, 44, 45, 47, 55, 59, 59, 61, 63, 63, 67, 67, 69, 72, 73, 75, 77, 77, 78, 81, 81, 83, 84, 92, 94, 99], \"n\": 31}}, {\"idx\": 7, \"outputs\": -6856, \"inputs\": {\"a\": [94, -86, 94, 54, -52, 86, 68, 64, 98, 54, -14, -60, -60, -92, 80, -16, 28, 16, -74, 68, 32, -54, 58, -16, -2, -52, -92, -36, 96, -18, 14, 76, 16], \"n\": 26}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 0, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 542, \"inputs\": {\"a\": [10, 28, 63, 2, 78, 12, 51, 82, 89, 65, 99], \"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
]
} |
517 | Sum Fibonacci Numbers | C++ | long long sumFibonacciNumbers(int n) { | [
"n"
] | def sum_fibonacci_numbers(n):
if (n <= 0):
return 0
fibo = ([0] * (n + 1))
fibo[1] = 1
sm = (fibo[0] + fibo[1])
for i in range(2, (n + 1)):
fibo[i] = (fibo[(i - 1)] + fibo[(i - 2)])
sm = (sm + fibo[i])
return sm | int sum_fibonacci_numbers(int n) {
if ( n <= 0 ) return 0;
int fibo [ n + 1 ];
fibo [ 0 ] = 0, fibo [ 1 ] = 1;
int sum = fibo [ 0 ] + fibo [ 1 ];
for ( int i = 2;
i <= n;
i ++ ) {
fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ];
sum += fibo [ i ];
}
return 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(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(9, 88); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 32951280098); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 33); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 28656); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 28656); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 232); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 196417); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 10610209857722); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 7); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumFibonacciNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 88, \"inputs\": {\"n\": 9}}, {\"idx\": 1, \"outputs\": 32951280098, \"inputs\": {\"n\": 50}}, {\"idx\": 2, \"outputs\": 33, \"inputs\": {\"n\": 7}}, {\"idx\": 3, \"outputs\": 28656, \"inputs\": {\"n\": 21}}, {\"idx\": 4, \"outputs\": 28656, \"inputs\": {\"n\": 21}}, {\"idx\": 5, \"outputs\": 232, \"inputs\": {\"n\": 11}}, {\"idx\": 6, \"outputs\": 196417, \"inputs\": {\"n\": 25}}, {\"idx\": 7, \"outputs\": 10610209857722, \"inputs\": {\"n\": 62}}, {\"idx\": 8, \"outputs\": 7, \"inputs\": {\"n\": 4}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
518 | Sum K Th Group Odd Positive Numbers | C++ | int sumKThGroupOddPositiveNumbers(int k) { | [
"k"
] | def sum_k_th_group_odd_positive_numbers(k):
cur = int(((k * (k - 1)) + 1))
sum = 0
while k:
sum += cur
cur += 2
k = (k - 1)
return sum | int sum_k_th_group_odd_positive_numbers(int k) {
int cur = ( k * ( k - 1 ) ) + 1;
int sum = 0;
while ( k -- ) {
sum += cur;
cur += 2;
}
return 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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(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(91, 753571); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 140608); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 474552); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 132651); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 274625); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 59319); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 74088); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 1728); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 175616); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 941192); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumKThGroupOddPositiveNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 753571, \"inputs\": {\"k\": 91}}, {\"idx\": 1, \"outputs\": 140608, \"inputs\": {\"k\": 52}}, {\"idx\": 2, \"outputs\": 474552, \"inputs\": {\"k\": 78}}, {\"idx\": 3, \"outputs\": 132651, \"inputs\": {\"k\": 51}}, {\"idx\": 4, \"outputs\": 274625, \"inputs\": {\"k\": 65}}, {\"idx\": 5, \"outputs\": 59319, \"inputs\": {\"k\": 39}}, {\"idx\": 6, \"outputs\": 74088, \"inputs\": {\"k\": 42}}, {\"idx\": 7, \"outputs\": 1728, \"inputs\": {\"k\": 12}}, {\"idx\": 8, \"outputs\": 175616, \"inputs\": {\"k\": 56}}, {\"idx\": 9, \"outputs\": 941192, \"inputs\": {\"k\": 98}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
519 | Sum K Th Group Odd Positive Numbers 1 | C++ | int sumKThGroupOddPositiveNumbers1(int k) { | [
"k"
] | def sum_k_th_group_odd_positive_numbers_1(k):
return ((k * k) * k) | int sum_k_th_group_odd_positive_numbers_1(int k) {
return k * k * 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 k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(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(57, 185193); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 884736); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 2744); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 262144); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 13824); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 405224); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 614125); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 19683); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 474552); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumKThGroupOddPositiveNumbers1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 185193, \"inputs\": {\"k\": 57}}, {\"idx\": 1, \"outputs\": 884736, \"inputs\": {\"k\": 96}}, {\"idx\": 2, \"outputs\": 2744, \"inputs\": {\"k\": 14}}, {\"idx\": 3, \"outputs\": 262144, \"inputs\": {\"k\": 64}}, {\"idx\": 4, \"outputs\": 13824, \"inputs\": {\"k\": 24}}, {\"idx\": 5, \"outputs\": 405224, \"inputs\": {\"k\": 74}}, {\"idx\": 6, \"outputs\": 614125, \"inputs\": {\"k\": 85}}, {\"idx\": 7, \"outputs\": 19683, \"inputs\": {\"k\": 27}}, {\"idx\": 8, \"outputs\": 474552, \"inputs\": {\"k\": 78}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"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
]
} |
520 | Sum Largest Prime Factor Number Less Equal N | C++ | int sumLargestPrimeFactorNumberLessEqualN(int n) { | [
"n"
] | def sum_largest_prime_factor_number_less_equal_n(n):
prime = ([0] * (n + 1))
sum = 0
max = int((n / 2))
for p in range(2, (max + 1)):
if (prime[p] == 0):
for i in range((p * 2), (n + 1), p):
prime[i] = p
for p in range(2, (n + 1)):
if prime[p]:
sum += prime[p]
else:
sum += p
return sum | int sum_largest_prime_factor_number_less_equal_n(int n) {
int prime [ n + 1 ], sum = 0;
memset ( prime, 0, sizeof ( prime ) );
int max = n / 2;
for ( int p = 2;
p <= max;
p ++ ) {
if ( prime [ p ] == 0 ) {
for ( int i = p * 2;
i <= n;
i += p ) prime [ i ] = p;
}
}
for ( int p = 2;
p <= n;
p ++ ) {
if ( prime [ p ] ) sum += prime [ p ];
else sum += p;
}
return 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(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(6, 15); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 291); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 1554); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 1672); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 875); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 43); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 901); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 90); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 1695); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 1334); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumLargestPrimeFactorNumberLessEqualN",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 15, \"inputs\": {\"n\": 6}}, {\"idx\": 1, \"outputs\": 291, \"inputs\": {\"n\": 35}}, {\"idx\": 2, \"outputs\": 1554, \"inputs\": {\"n\": 87}}, {\"idx\": 3, \"outputs\": 1672, \"inputs\": {\"n\": 91}}, {\"idx\": 4, \"outputs\": 875, \"inputs\": {\"n\": 63}}, {\"idx\": 5, \"outputs\": 43, \"inputs\": {\"n\": 11}}, {\"idx\": 6, \"outputs\": 901, \"inputs\": {\"n\": 66}}, {\"idx\": 7, \"outputs\": 90, \"inputs\": {\"n\": 17}}, {\"idx\": 8, \"outputs\": 1695, \"inputs\": {\"n\": 92}}, {\"idx\": 9, \"outputs\": 1334, \"inputs\": {\"n\": 81}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
521 | Sum Manhattan Distances Pairs Points | C++ | int sumManhattanDistancesPairsPoints(vector<int> x, vector<int> y, int n) { | [
"x",
"y",
"n"
] | def sum_manhattan_distances_pairs_points(x, y, n):
sum = 0
for i in range(n):
for j in range((i + 1), n):
sum += (abs((x[i] - x[j])) + abs((y[i] - y[j])))
return sum | int sum_manhattan_distances_pairs_points(vector<int> x, vector<int> y, int n) {
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) for ( int j = i + 1;
j < n;
j ++ ) sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) );
return 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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> x, vector<int> y, int n, int 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({2, 4, 6, 6, 8, 11, 12, 13, 14, 19, 20, 22, 24, 28, 29, 30, 32, 35, 37, 44, 48, 49, 51, 51, 56, 59, 59, 62, 65, 68, 68, 68, 72, 75, 77, 78, 89, 89, 91, 93, 95, 99}, {6, 19, 19, 22, 25, 27, 31, 33, 34, 35, 37, 38, 38, 44, 46, 50, 51, 55, 58, 58, 64, 64, 64, 64, 65, 66, 66, 66, 67, 70, 75, 78, 79, 81, 81, 81, 82, 84, 84, 86, 94, 96}, 37, 35930); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, 76, 2, 42, -24, -82, 68, -2, 98, -42, -72, 28, -22, -52, 28, -38, 36, 66, 84, 64, -28, 86, 52, 84, -98, -30}, {-34, 92, -24, -62, 28, 72, -10, 10, 8, 90, -72, -24, 50, -46, 52, 58, 68, -62, -64, -78, -12, 24, 62, -30, 62, -60}, 24, 35216); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 5, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({61, 37, 57, 99, 22, 72, 38, 85, 23, 85, 15, 4, 49, 9, 15, 25, 7, 63, 79, 6, 85, 30, 12, 34, 38, 6, 59, 62, 59, 34, 72, 97, 70, 44, 95, 58, 99}, {72, 41, 77, 62, 78, 36, 75, 28, 91, 39, 32, 56, 60, 64, 21, 15, 80, 85, 28, 22, 53, 58, 69, 62, 60, 48, 66, 91, 38, 66, 54, 5, 24, 1, 49, 71, 49}, 26, 19322); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -86, -82, -72, -72, -64, -62, -60, -56, -56, -56, -54, -52, -40, -36, -30, -10, 10, 18, 26, 28, 56, 56, 56, 64, 90, 92, 94}, {-98, -98, -96, -96, -82, -80, -80, -68, -62, -60, -46, -38, -26, -26, -20, -18, 16, 22, 24, 26, 34, 46, 52, 52, 74, 76, 90, 92}, 26, 42084); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 1, 0, 1}, {1, 0, 1, 0, 0, 1, 1}, 3, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 10, 24, 25, 31, 41, 43, 45, 47, 65, 67, 90}, {4, 7, 11, 19, 21, 39, 57, 80, 84, 93, 94, 97}, 10, 2776); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-74, 92, 34, 56, -54, -98, -76, -34, 16, 32, -4, -16, 22, 90, -52, -90, -60, 70, -40, 78, 96, -68, 78, -56, -94}, {14, 20, 24, -92, 58, 12, 78, 78, -90, 96, -44, 36, 30, -46, -30, -80, 26, -2, 26, 28, -16, -50, -2, -36, -8}, 21, 28932); \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, 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, 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}, 23, 188); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, 32}, {23, 50}, 1, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumManhattanDistancesPairsPoints",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 35930, \"inputs\": {\"x\": [2, 4, 6, 6, 8, 11, 12, 13, 14, 19, 20, 22, 24, 28, 29, 30, 32, 35, 37, 44, 48, 49, 51, 51, 56, 59, 59, 62, 65, 68, 68, 68, 72, 75, 77, 78, 89, 89, 91, 93, 95, 99], \"y\": [6, 19, 19, 22, 25, 27, 31, 33, 34, 35, 37, 38, 38, 44, 46, 50, 51, 55, 58, 58, 64, 64, 64, 64, 65, 66, 66, 66, 67, 70, 75, 78, 79, 81, 81, 81, 82, 84, 84, 86, 94, 96], \"n\": 37}}, {\"idx\": 1, \"outputs\": 35216, \"inputs\": {\"x\": [16, 76, 2, 42, -24, -82, 68, -2, 98, -42, -72, 28, -22, -52, 28, -38, 36, 66, 84, 64, -28, 86, 52, 84, -98, -30], \"y\": [-34, 92, -24, -62, 28, 72, -10, 10, 8, 90, -72, -24, 50, -46, 52, 58, 68, -62, -64, -78, -12, 24, 62, -30, 62, -60], \"n\": 24}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"x\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"y\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 5}}, {\"idx\": 3, \"outputs\": 19322, \"inputs\": {\"x\": [61, 37, 57, 99, 22, 72, 38, 85, 23, 85, 15, 4, 49, 9, 15, 25, 7, 63, 79, 6, 85, 30, 12, 34, 38, 6, 59, 62, 59, 34, 72, 97, 70, 44, 95, 58, 99], \"y\": [72, 41, 77, 62, 78, 36, 75, 28, 91, 39, 32, 56, 60, 64, 21, 15, 80, 85, 28, 22, 53, 58, 69, 62, 60, 48, 66, 91, 38, 66, 54, 5, 24, 1, 49, 71, 49], \"n\": 26}}, {\"idx\": 4, \"outputs\": 42084, \"inputs\": {\"x\": [-96, -86, -82, -72, -72, -64, -62, -60, -56, -56, -56, -54, -52, -40, -36, -30, -10, 10, 18, 26, 28, 56, 56, 56, 64, 90, 92, 94], \"y\": [-98, -98, -96, -96, -82, -80, -80, -68, -62, -60, -46, -38, -26, -26, -20, -18, 16, 22, 24, 26, 34, 46, 52, 52, 74, 76, 90, 92], \"n\": 26}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"x\": [1, 0, 1, 1, 1, 0, 1], \"y\": [1, 0, 1, 0, 0, 1, 1], \"n\": 3}}, {\"idx\": 6, \"outputs\": 2776, \"inputs\": {\"x\": [6, 10, 24, 25, 31, 41, 43, 45, 47, 65, 67, 90], \"y\": [4, 7, 11, 19, 21, 39, 57, 80, 84, 93, 94, 97], \"n\": 10}}, {\"idx\": 7, \"outputs\": 28932, \"inputs\": {\"x\": [-74, 92, 34, 56, -54, -98, -76, -34, 16, 32, -4, -16, 22, 90, -52, -90, -60, 70, -40, 78, 96, -68, 78, -56, -94], \"y\": [14, 20, 24, -92, 58, 12, 78, 78, -90, 96, -44, 36, 30, -46, -30, -80, 26, -2, 26, 28, -16, -50, -2, -36, -8], \"n\": 21}}, {\"idx\": 8, \"outputs\": 188, \"inputs\": {\"x\": [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], \"y\": [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\": 23}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"x\": [20, 32], \"y\": [23, 50], \"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
]
} |
522 | Sum Matrix Element Absolute Difference Row Column Numbers | C++ | int sumMatrixElementAbsoluteDifferenceRowColumnNumbers(int n) { | [
"n"
] | def sum_matrix_element_absolute_difference_row_column_numbers(n):
arr = [[0 for x in range(n)] for y in range(n)]
for i in range(n):
for j in range(n):
arr[i][j] = abs((i - j))
sum = 0
for i in range(n):
for j in range(n):
sum += arr[i][j]
return sum | int sum_matrix_element_absolute_difference_row_column_numbers(int n) {
int arr [ n ] [ n ];
for ( int i = 0;
i < n;
i ++ ) for ( int j = 0;
j < n;
j ++ ) arr [ i ] [ j ] = abs ( i - j );
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) for ( int j = 0;
j < n;
j ++ ) sum += arr [ i ] [ j ];
return 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(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(60, 71980); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 28380); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 124392); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 242970); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 323400); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 30360); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 6552); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 440); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 91520); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 46852); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumMatrixElementAbsoluteDifferenceRowColumnNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 71980, \"inputs\": {\"n\": 60}}, {\"idx\": 1, \"outputs\": 28380, \"inputs\": {\"n\": 44}}, {\"idx\": 2, \"outputs\": 124392, \"inputs\": {\"n\": 72}}, {\"idx\": 3, \"outputs\": 242970, \"inputs\": {\"n\": 90}}, {\"idx\": 4, \"outputs\": 323400, \"inputs\": {\"n\": 99}}, {\"idx\": 5, \"outputs\": 30360, \"inputs\": {\"n\": 45}}, {\"idx\": 6, \"outputs\": 6552, \"inputs\": {\"n\": 27}}, {\"idx\": 7, \"outputs\": 440, \"inputs\": {\"n\": 11}}, {\"idx\": 8, \"outputs\": 91520, \"inputs\": {\"n\": 65}}, {\"idx\": 9, \"outputs\": 46852, \"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
]
} |
523 | Sum Matrix Element Absolute Difference Row Column Numbers 1 | C++ | int sumMatrixElementAbsoluteDifferenceRowColumnNumbers1(int n) { | [
"n"
] | def sum_matrix_element_absolute_difference_row_column_numbers_1(n):
sum = 0
for i in range(n):
sum += (i * (n - i))
return (2 * sum) | int sum_matrix_element_absolute_difference_row_column_numbers_1(int n) {
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) sum += i * ( n - i );
return 2 * 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(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(63, 83328); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 124392); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 7308); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 14280); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 70); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 114310); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 2660); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 168); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 168); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 14280); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumMatrixElementAbsoluteDifferenceRowColumnNumbers1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 83328, \"inputs\": {\"n\": 63}}, {\"idx\": 1, \"outputs\": 124392, \"inputs\": {\"n\": 72}}, {\"idx\": 2, \"outputs\": 7308, \"inputs\": {\"n\": 28}}, {\"idx\": 3, \"outputs\": 14280, \"inputs\": {\"n\": 35}}, {\"idx\": 4, \"outputs\": 70, \"inputs\": {\"n\": 6}}, {\"idx\": 5, \"outputs\": 114310, \"inputs\": {\"n\": 70}}, {\"idx\": 6, \"outputs\": 2660, \"inputs\": {\"n\": 20}}, {\"idx\": 7, \"outputs\": 168, \"inputs\": {\"n\": 8}}, {\"idx\": 8, \"outputs\": 168, \"inputs\": {\"n\": 8}}, {\"idx\": 9, \"outputs\": 14280, \"inputs\": {\"n\": 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
]
} |
524 | Sum Matrix Element Absolute Difference Row Column Numbers 2 | C++ | int sumMatrixElementAbsoluteDifferenceRowColumnNumbers2(int n) { | [
"n"
] | def sum_matrix_element_absolute_difference_row_column_numbers_2(n):
n -= 1
sum = 0
sum += ((n * (n + 1)) / 2)
sum += (((n * (n + 1)) * ((2 * n) + 1)) / 6)
return int(sum) | int sum_matrix_element_absolute_difference_row_column_numbers_2(int n) {
n --;
int sum = 0;
sum += ( n * ( n + 1 ) ) / 2;
sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6;
return 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(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(12, 572); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 234960); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 146300); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 177120); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 440); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 5850); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 14280); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 1360); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 95810); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumMatrixElementAbsoluteDifferenceRowColumnNumbers2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 572, \"inputs\": {\"n\": 12}}, {\"idx\": 1, \"outputs\": 234960, \"inputs\": {\"n\": 89}}, {\"idx\": 2, \"outputs\": 146300, \"inputs\": {\"n\": 76}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"n\": 2}}, {\"idx\": 4, \"outputs\": 177120, \"inputs\": {\"n\": 81}}, {\"idx\": 5, \"outputs\": 440, \"inputs\": {\"n\": 11}}, {\"idx\": 6, \"outputs\": 5850, \"inputs\": {\"n\": 26}}, {\"idx\": 7, \"outputs\": 14280, \"inputs\": {\"n\": 35}}, {\"idx\": 8, \"outputs\": 1360, \"inputs\": {\"n\": 16}}, {\"idx\": 9, \"outputs\": 95810, \"inputs\": {\"n\": 66}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
525 | Sum Matrix Element Element Integer Division Row Column | C++ | int sumMatrixElementElementIntegerDivisionRowColumn(int n) { | [
"n"
] | def sum_matrix_element_element_integer_division_row_column(N):
ans = 0
for i in range(1, (N + 1)):
for j in range(1, (N + 1)):
ans += (i // j)
return ans | int sum_matrix_element_element_integer_division_row_column(int n) {
int ans = 0;
for ( int i = 1;
i <= n;
i ++ ) for ( int j = 1;
j <= n;
j ++ ) ans += ( i / j );
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(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(60, 7021); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 11190); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 77); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 11190); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 1974); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 8680); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 19920); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 156); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 3697); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 10530); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumMatrixElementElementIntegerDivisionRowColumn",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 7021, \"inputs\": {\"n\": 60}}, {\"idx\": 1, \"outputs\": 11190, \"inputs\": {\"n\": 74}}, {\"idx\": 2, \"outputs\": 77, \"inputs\": {\"n\": 8}}, {\"idx\": 3, \"outputs\": 11190, \"inputs\": {\"n\": 74}}, {\"idx\": 4, \"outputs\": 1974, \"inputs\": {\"n\": 34}}, {\"idx\": 5, \"outputs\": 8680, \"inputs\": {\"n\": 66}}, {\"idx\": 6, \"outputs\": 19920, \"inputs\": {\"n\": 96}}, {\"idx\": 7, \"outputs\": 156, \"inputs\": {\"n\": 11}}, {\"idx\": 8, \"outputs\": 3697, \"inputs\": {\"n\": 45}}, {\"idx\": 9, \"outputs\": 10530, \"inputs\": {\"n\": 72}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
526 | Sum Matrix Element Element Integer Division Row Column 1 | C++ | int sumMatrixElementElementIntegerDivisionRowColumn1(int n) { | [
"n"
] | def sum_matrix_element_element_integer_division_row_column_1(n):
ans = 0
temp = 0
for i in range(1, (n + 1)):
if (temp < n):
temp = (i - 1)
num = 1
while (temp < n):
if ((temp + i) <= n):
ans += (i * num)
else:
ans += ((n - temp) * num)
temp += i
num += 1
return ans | int sum_matrix_element_element_integer_division_row_column_1(int n) {
int ans = 0, temp = 0, num;
for ( int i = 1;
i <= n && temp < n;
i ++ ) {
temp = i - 1;
num = 1;
while ( temp < n ) {
if ( temp + i <= n ) ans += ( i * num );
else ans += ( ( n - temp ) * num );
temp += i;
num ++;
}
}
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(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(35, 630); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 4371); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 28); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 3321); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 3240); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 1128); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 28); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 861); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 1770); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 595); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumMatrixElementElementIntegerDivisionRowColumn1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 630, \"inputs\": {\"n\": 35}}, {\"idx\": 1, \"outputs\": 4371, \"inputs\": {\"n\": 93}}, {\"idx\": 2, \"outputs\": 28, \"inputs\": {\"n\": 7}}, {\"idx\": 3, \"outputs\": 3321, \"inputs\": {\"n\": 81}}, {\"idx\": 4, \"outputs\": 3240, \"inputs\": {\"n\": 80}}, {\"idx\": 5, \"outputs\": 1128, \"inputs\": {\"n\": 47}}, {\"idx\": 6, \"outputs\": 28, \"inputs\": {\"n\": 7}}, {\"idx\": 7, \"outputs\": 861, \"inputs\": {\"n\": 41}}, {\"idx\": 8, \"outputs\": 1770, \"inputs\": {\"n\": 59}}, {\"idx\": 9, \"outputs\": 595, \"inputs\": {\"n\": 34}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
527 | Sum Nodes K Th Level Tree Represented String | C++ | int sumNodesKThLevelTreeRepresentedString(string tree, int k) { | [
"tree",
"k"
] | def sum_nodes_k_th_level_tree_represented_string(tree, k):
level = (- 1)
sum = 0
n = len(tree)
for i in range(n):
if (tree[i] == '('):
level += 1
elif (tree[i] == ')'):
level -= 1
elif (level == k):
sum += (ord(tree[i]) - ord('0'))
return sum | int sum_nodes_k_th_level_tree_represented_string(string tree, int k) {
int level = - 1;
int sum = 0;
int n = tree . length ( );
for ( int i = 0;
i < n;
i ++ ) {
if ( tree [ i ] == '(' ) level ++;
else if ( tree [ i ] == ')' ) level --;
else {
if ( level == k ) sum += ( tree [ i ] - '0' );
}
}
return 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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string tree, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(tree, 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(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 2, 14); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 3, 9); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 1, 12); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 2, 16); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 4, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", 100, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 3, 9); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", 0, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0010\", 12, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kjtdgmy\", 97, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumNodesKThLevelTreeRepresentedString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 14, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 2}}, {\"idx\": 1, \"outputs\": 9, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 3}}, {\"idx\": 2, \"outputs\": 12, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 1}}, {\"idx\": 3, \"outputs\": 16, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 2}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 4}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"tree\": \"(8(3(2()())(6(5()())()))(5(10()())(7(13()())())))\", \"k\": 100}}, {\"idx\": 6, \"outputs\": 9, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 3}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"tree\": \"(0(5(6()())(4()(9()())))(7(1()())(3()())))\", \"k\": 0}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"tree\": \"0010\", \"k\": 12}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"tree\": \"kjtdgmy\", \"k\": 97}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
528 | Sum Of All Elements Up To Nth Row In A Pascals Triangle | C++ | long long sumOfAllElementsUpToNthRowInAPascalsTriangle(int n) { | [
"n"
] | def sum_of_all_elements_up_to_nth_row_in_a_pascals_triangle(n):
sum = 0
for row in range(n):
sum = (sum + (1 << row))
return sum | long long int sum_of_all_elements_up_to_nth_row_in_a_pascals_triangle(int n) {
long long int sum = 0;
for ( int row = 0;
row < n;
row ++ ) {
sum = sum + ( 1 << row );
}
return 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(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(21, 2097151); \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(31, 2147483647); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 274877906943); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 68719476735); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 4294967295); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 8388607); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumOfAllElementsUpToNthRowInAPascalsTriangle",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2097151, \"inputs\": {\"n\": 21}}, {\"idx\": 1, \"outputs\": 15, \"inputs\": {\"n\": 4}}, {\"idx\": 2, \"outputs\": 2147483647, \"inputs\": {\"n\": 31}}, {\"idx\": 3, \"outputs\": 274877906943, \"inputs\": {\"n\": 38}}, {\"idx\": 4, \"outputs\": 68719476735, \"inputs\": {\"n\": 36}}, {\"idx\": 5, \"outputs\": 4294967295, \"inputs\": {\"n\": 32}}, {\"idx\": 6, \"outputs\": 8388607, \"inputs\": {\"n\": 23}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
529 | Sum Of All Elements Up To Nth Row In A Pascals Triangle 1 | C++ | long long sumOfAllElementsUpToNthRowInAPascalsTriangle1(int n) { | [
"n"
] | def sum_of_all_elements_up_to_nth_row_in_a_pascals_triangle_1(n):
sum = 0
sum = (1 << n)
return (sum - 1) | long long int sum_of_all_elements_up_to_nth_row_in_a_pascals_triangle_1(int n) {
long long int sum = 0;
sum = 1 << n;
return ( sum - 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(53, 9007199254740991); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 7); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 268435455); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 17592186044415); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 70368744177663); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 65535); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumOfAllElementsUpToNthRowInAPascalsTriangle1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 9007199254740991, \"inputs\": {\"n\": 53}}, {\"idx\": 1, \"outputs\": 7, \"inputs\": {\"n\": 3}}, {\"idx\": 2, \"outputs\": 268435455, \"inputs\": {\"n\": 28}}, {\"idx\": 3, \"outputs\": 17592186044415, \"inputs\": {\"n\": 44}}, {\"idx\": 4, \"outputs\": 70368744177663, \"inputs\": {\"n\": 46}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"n\": 3}}, {\"idx\": 6, \"outputs\": 65535, \"inputs\": {\"n\": 16}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
530 | Sum Of All Proper Divisors Of A Natural Number | C++ | float sumOfAllProperDivisorsOfANaturalNumber(int num) { | [
"num"
] | def sum_of_all_proper_divisors_of_a_natural_number(num):
result = 0
i = 2
while (i <= math.sqrt(num)):
if ((num % i) == 0):
if (i == (num / i)):
result = (result + i)
else:
result = (result + (i + (num / i)))
i = (i + 1)
return (result + 1) | int sum_of_all_proper_divisors_of_a_natural_number(int num) {
int result = 0;
for ( int i = 2;
i <= sqrt ( num );
i ++ ) {
if ( num % i == 0 ) {
if ( i == ( num / i ) ) result += i;
else result += ( i + num / i );
}
}
return ( result + 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(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int num, float 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(2, 1.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 23.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 28.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 1.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 22.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 1.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 33.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 1.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 40.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 1.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumOfAllProperDivisorsOfANaturalNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"num\": 2}}, {\"idx\": 1, \"outputs\": 23.0, \"inputs\": {\"num\": 57}}, {\"idx\": 2, \"outputs\": 28.0, \"inputs\": {\"num\": 28}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"num\": 43}}, {\"idx\": 4, \"outputs\": 22.0, \"inputs\": {\"num\": 38}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"num\": 29}}, {\"idx\": 6, \"outputs\": 33.0, \"inputs\": {\"num\": 45}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"num\": 47}}, {\"idx\": 8, \"outputs\": 40.0, \"inputs\": {\"num\": 44}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"num\": 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
]
} |
532 | Sum Pairwise Products 1 | C++ | int sumPairwiseProducts1(int n) { | [
"n"
] | def sum_pairwise_products_1(n):
multiTerms = ((n * (n + 1)) // 2)
sm = multiTerms
for i in range(2, (n + 1)):
multiTerms = (multiTerms - (i - 1))
sm = (sm + (multiTerms * i))
return sm | long long int sum_pairwise_products_1(int n) {
long long int multiTerms = n * ( n + 1 ) / 2;
long long int sum = multiTerms;
for ( int i = 2;
i <= n;
i ++ ) {
multiTerms = multiTerms - ( i - 1 );
sum = sum + multiTerms * i;
}
return 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(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(41, 382571); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 834275); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 2645897); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 15675); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 1711355); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 266); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 74907); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 601036); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 834275); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 23485); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumPairwiseProducts1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 382571, \"inputs\": {\"n\": 41}}, {\"idx\": 1, \"outputs\": 834275, \"inputs\": {\"n\": 50}}, {\"idx\": 2, \"outputs\": 2645897, \"inputs\": {\"n\": 67}}, {\"idx\": 3, \"outputs\": 15675, \"inputs\": {\"n\": 18}}, {\"idx\": 4, \"outputs\": 1711355, \"inputs\": {\"n\": 60}}, {\"idx\": 5, \"outputs\": 266, \"inputs\": {\"n\": 6}}, {\"idx\": 6, \"outputs\": 74907, \"inputs\": {\"n\": 27}}, {\"idx\": 7, \"outputs\": 601036, \"inputs\": {\"n\": 46}}, {\"idx\": 8, \"outputs\": 834275, \"inputs\": {\"n\": 50}}, {\"idx\": 9, \"outputs\": 23485, \"inputs\": {\"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
]
} |
533 | Sum Pairwise Products 2 | C++ | double sumPairwiseProducts2(int n) { | [
"n"
] | def sum_pairwise_products_2(n):
return ((((n * (n + 1)) * (n + 2)) * ((3 * n) + 1)) / 24) | long long int sum_pairwise_products_2(int n) {
return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24;
} | {
"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(57, 1397887.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 15675.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 11449977.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 1155.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 420497.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 2645897.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 3327486.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 2493271.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 2972060.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 15675.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumPairwiseProducts2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1397887.0, \"inputs\": {\"n\": 57}}, {\"idx\": 1, \"outputs\": 15675.0, \"inputs\": {\"n\": 18}}, {\"idx\": 2, \"outputs\": 11449977.0, \"inputs\": {\"n\": 97}}, {\"idx\": 3, \"outputs\": 1155.0, \"inputs\": {\"n\": 9}}, {\"idx\": 4, \"outputs\": 420497.0, \"inputs\": {\"n\": 42}}, {\"idx\": 5, \"outputs\": 2645897.0, \"inputs\": {\"n\": 67}}, {\"idx\": 6, \"outputs\": 3327486.0, \"inputs\": {\"n\": 71}}, {\"idx\": 7, \"outputs\": 2493271.0, \"inputs\": {\"n\": 66}}, {\"idx\": 8, \"outputs\": 2972060.0, \"inputs\": {\"n\": 69}}, {\"idx\": 9, \"outputs\": 15675.0, \"inputs\": {\"n\": 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
]
} |
534 | Sum Series 0 6 0 06 0 006 0 0006 N Terms | C++ | double sumSeries06006000600006NTerms(int n) { | [
"n"
] | def sum_series_0_6_0_06_0_006_0_0006_n_terms(n):
return (0.666 * (1 - (1 / pow(10, n)))) | float sum_series_0_6_0_06_0_006_0_0006_n_terms(int n) {
return ( 0.666 ) * ( 1 - 1 / pow ( 10, 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(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(1, 0.5994); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 0.65934); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 0.665334); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 0.6659334); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 0.6659933400000001); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 0.666); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 0.666); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 0.666); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 0.665999999334); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 0.665999999999334); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumSeries06006000600006NTerms",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0.5994, \"inputs\": {\"n\": 1}}, {\"idx\": 1, \"outputs\": 0.65934, \"inputs\": {\"n\": 2}}, {\"idx\": 2, \"outputs\": 0.665334, \"inputs\": {\"n\": 3}}, {\"idx\": 3, \"outputs\": 0.6659334, \"inputs\": {\"n\": 4}}, {\"idx\": 4, \"outputs\": 0.6659933400000001, \"inputs\": {\"n\": 5}}, {\"idx\": 5, \"outputs\": 0.666, \"inputs\": {\"n\": 74}}, {\"idx\": 6, \"outputs\": 0.666, \"inputs\": {\"n\": 77}}, {\"idx\": 7, \"outputs\": 0.666, \"inputs\": {\"n\": 67}}, {\"idx\": 8, \"outputs\": 0.665999999334, \"inputs\": {\"n\": 9}}, {\"idx\": 9, \"outputs\": 0.665999999999334, \"inputs\": {\"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
]
} |
535 | Sum Series 12 32 52 2N 12 | C++ | int sumSeries1232522N12(int n) { | [
"n"
] | def sum_series_12_32_52_2n_12(n):
sum = 0
for i in range(1, (n + 1)):
sum = (sum + (((2 * i) - 1) * ((2 * i) - 1)))
return sum | int sum_series_12_32_52_2n_12(int n) {
int sum = 0;
for ( int i = 1;
i <= n;
i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 );
return 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(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(14, 3654); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 302621); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 67525); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 848046); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 138415); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 1254890); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 457310); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 18424); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 585276); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 18424); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumSeries1232522N12",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3654, \"inputs\": {\"n\": 14}}, {\"idx\": 1, \"outputs\": 302621, \"inputs\": {\"n\": 61}}, {\"idx\": 2, \"outputs\": 67525, \"inputs\": {\"n\": 37}}, {\"idx\": 3, \"outputs\": 848046, \"inputs\": {\"n\": 86}}, {\"idx\": 4, \"outputs\": 138415, \"inputs\": {\"n\": 47}}, {\"idx\": 5, \"outputs\": 1254890, \"inputs\": {\"n\": 98}}, {\"idx\": 6, \"outputs\": 457310, \"inputs\": {\"n\": 70}}, {\"idx\": 7, \"outputs\": 18424, \"inputs\": {\"n\": 24}}, {\"idx\": 8, \"outputs\": 585276, \"inputs\": {\"n\": 76}}, {\"idx\": 9, \"outputs\": 18424, \"inputs\": {\"n\": 24}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
536 | Sum Series 12 32 52 2N 12 1 | C++ | int sumSeries1232522N121(int n) { | [
"n"
] | def sum_series_12_32_52_2n_12_1(n):
return int((((n * ((2 * n) - 1)) * ((2 * n) + 1)) / 3)) | int sum_series_12_32_52_2n_12_1(int n) {
return ( n * ( 2 * n - 1 ) * ( 2 * n + 1 ) ) / 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(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(84, 790244); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 540274); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 1004731); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 52394); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 62196); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 29260); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 457310); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 455); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 18424); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 138415); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumSeries1232522N121",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 790244, \"inputs\": {\"n\": 84}}, {\"idx\": 1, \"outputs\": 540274, \"inputs\": {\"n\": 74}}, {\"idx\": 2, \"outputs\": 1004731, \"inputs\": {\"n\": 91}}, {\"idx\": 3, \"outputs\": 52394, \"inputs\": {\"n\": 34}}, {\"idx\": 4, \"outputs\": 62196, \"inputs\": {\"n\": 36}}, {\"idx\": 5, \"outputs\": 29260, \"inputs\": {\"n\": 28}}, {\"idx\": 6, \"outputs\": 457310, \"inputs\": {\"n\": 70}}, {\"idx\": 7, \"outputs\": 455, \"inputs\": {\"n\": 7}}, {\"idx\": 8, \"outputs\": 18424, \"inputs\": {\"n\": 24}}, {\"idx\": 9, \"outputs\": 138415, \"inputs\": {\"n\": 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
]
} |
537 | Sum Series 23 45 67 89 Upto N Terms | C++ | double sumSeries23456789UptoNTerms(int n) { | [
"n"
] | def sum_series_23_45_67_89_upto_n_terms(n):
i = 1
res = 0.0
sign = True
while (n > 0):
n = (n - 1)
if sign:
sign = False
res = (res + ((i + 1) / (i + 2)))
i = (i + 2)
else:
sign = True
res = (res - ((i + 1) / (i + 2)))
i = (i + 2)
return res | double sum_series_23_45_67_89_upto_n_terms(int n) {
int i = 1;
double res = 0.0;
bool sign = true;
while ( n > 0 ) {
n --;
if ( sign ) {
sign = ! sign;
res = res + ( double ) ++ i / ++ i;
}
else {
sign = ! sign;
res = res - ( double ) ++ i / ++ i;
}
}
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(49, 0.7803986631477524); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, -0.16507936507936516); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, -0.21050375120783382); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, -0.21185466678122022); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, -0.2120245854859959); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 0.7770671416747363); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, -0.21172836828074082); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 0.780190394898247); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 0.7821931668684383); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 0.7825573460049735); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "sumSeries23456789UptoNTerms",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0.7803986631477524, \"inputs\": {\"n\": 49}}, {\"idx\": 1, \"outputs\": -0.16507936507936516, \"inputs\": {\"n\": 4}}, {\"idx\": 2, \"outputs\": -0.21050375120783382, \"inputs\": {\"n\": 60}}, {\"idx\": 3, \"outputs\": -0.21185466678122022, \"inputs\": {\"n\": 90}}, {\"idx\": 4, \"outputs\": -0.2120245854859959, \"inputs\": {\"n\": 96}}, {\"idx\": 5, \"outputs\": 0.7770671416747363, \"inputs\": {\"n\": 29}}, {\"idx\": 6, \"outputs\": -0.21172836828074082, \"inputs\": {\"n\": 86}}, {\"idx\": 7, \"outputs\": 0.780190394898247, \"inputs\": {\"n\": 47}}, {\"idx\": 8, \"outputs\": 0.7821931668684383, \"inputs\": {\"n\": 77}}, {\"idx\": 9, \"outputs\": 0.7825573460049735, \"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
]
} |