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 |
---|---|---|---|---|---|---|---|
320 | Maximum Sum Alternating Subsequence Sum | C++ | long long maximumSumAlternatingSubsequenceSum(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_sum_alternating_subsequence_sum(arr, n):
if (n == 1):
return arr[0]
dec = [0 for i in range((n + 1))]
inc = [0 for i in range((n + 1))]
dec[0] = inc[0] = arr[0]
flag = 0
for i in range(1, n):
for j in range(i):
if (arr[j] > arr[i]):
dec[i] = max(dec[i], (inc[j] + arr[i]))
flag = 1
elif ((arr[j] < arr[i]) and (flag == 1)):
inc[i] = max(inc[i], (dec[j] + arr[i]))
result = (- 2147483648)
for i in range(n):
if (result < inc[i]):
result = inc[i]
if (result < dec[i]):
result = dec[i]
return result | int maximum_sum_alternating_subsequence_sum(vector<int> arr, int n) {
if ( n == 1 ) return arr [ 0 ];
int dec [ n ];
memset ( dec, 0, sizeof ( dec ) );
int inc [ n ];
memset ( inc, 0, sizeof ( inc ) );
dec [ 0 ] = inc [ 0 ] = arr [ 0 ];
int flag = 0;
for ( int i = 1;
i < n;
i ++ ) {
for ( int j = 0;
j < i;
j ++ ) {
if ( arr [ j ] > arr [ i ] ) {
dec [ i ] = max ( dec [ i ], inc [ j ] + arr [ i ] );
flag = 1;
}
else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ], dec [ j ] + arr [ i ] );
}
}
int result = INT_MIN;
for ( int i = 0;
i < n;
i ++ ) {
if ( result < inc [ i ] ) result = inc [ i ];
if ( result < dec [ i ] ) result = dec [ i ];
}
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(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, long long 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, 5, 9, 15, 15, 20, 21, 26, 28, 32, 34, 38, 42, 42, 42, 46, 47, 48, 50, 54, 55, 60, 60, 61, 63, 63, 66, 74, 79, 80, 85, 91, 93}, 23, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98}, 0, -2147483648); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}, 6, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({70, 5, 20, 22, 44, 94, 69, 89, 45, 92, 56, 58, 36, 91, 82, 95, 9, 60, 4, 34, 37, 95, 38, 47, 81, 68, 73, 15, 88, 8, 95, 28, 97, 12, 24, 5, 26, 82, 47, 88, 28, 33, 17, 28, 11, 71, 74}, 24, 1207); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -96, -94, -94, -92, -86, -86, -84, -82, -68, -66, -66, -50, -48, -46, -36, -26, -8, -6, 8, 14, 16, 18, 22, 32, 48, 48, 50, 62, 70, 70, 74, 78, 78, 84, 86, 92, 94, 98}, 32, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1}, 5, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 8, 8, 12, 14, 19, 24, 25, 32, 36, 45, 47, 53, 54, 56, 56, 58, 59, 60, 65, 68, 86, 86, 91, 98}, 13, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, 88, 94, 78, -34, 84, -32, 68, -72, 80}, 7, 162); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, 62, 62, 61, 63, 15, 61, 74, 50, 86, 60, 35, 91, 32, 93, 14, 52, 18, 14, 39}, 18, 832); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumAlternatingSubsequenceSum",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [2, 5, 9, 15, 15, 20, 21, 26, 28, 32, 34, 38, 42, 42, 42, 46, 47, 48, 50, 54, 55, 60, 60, 61, 63, 63, 66, 74, 79, 80, 85, 91, 93], \"n\": 23}}, {\"idx\": 1, \"outputs\": -2147483648, \"inputs\": {\"arr\": [-98], \"n\": 0}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], \"n\": 6}}, {\"idx\": 3, \"outputs\": 1207, \"inputs\": {\"arr\": [70, 5, 20, 22, 44, 94, 69, 89, 45, 92, 56, 58, 36, 91, 82, 95, 9, 60, 4, 34, 37, 95, 38, 47, 81, 68, 73, 15, 88, 8, 95, 28, 97, 12, 24, 5, 26, 82, 47, 88, 28, 33, 17, 28, 11, 71, 74], \"n\": 24}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-98, -96, -94, -94, -92, -86, -86, -84, -82, -68, -66, -66, -50, -48, -46, -36, -26, -8, -6, 8, 14, 16, 18, 22, 32, 48, 48, 50, 62, 70, 70, 74, 78, 78, 84, 86, 92, 94, 98], \"n\": 32}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1], \"n\": 5}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [1, 2, 8, 8, 12, 14, 19, 24, 25, 32, 36, 45, 47, 53, 54, 56, 56, 58, 59, 60, 65, 68, 86, 86, 91, 98], \"n\": 13}}, {\"idx\": 7, \"outputs\": 162, \"inputs\": {\"arr\": [-94, 88, 94, 78, -34, 84, -32, 68, -72, 80], \"n\": 7}}, {\"idx\": 8, \"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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 30}}, {\"idx\": 9, \"outputs\": 832, \"inputs\": {\"arr\": [76, 62, 62, 61, 63, 15, 61, 74, 50, 86, 60, 35, 91, 32, 93, 14, 52, 18, 14, 39], \"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
]
} |
321 | Maximum Sum Bitonic Subarray | C++ | int maximumSumBitonicSubarray(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_sum_bitonic_subarray(arr, n):
msis = ([None] * n)
msds = ([None] * n)
max_sum = 0
msis[0] = arr[0]
for i in range(1, n):
if (arr[i] > arr[(i - 1)]):
msis[i] = (msis[(i - 1)] + arr[i])
else:
msis[i] = arr[i]
msds[(n - 1)] = arr[(n - 1)]
for i in range((n - 2), (- 1), (- 1)):
if (arr[i] > arr[(i + 1)]):
msds[i] = (msds[(i + 1)] + arr[i])
else:
msds[i] = arr[i]
for i in range(n):
if (max_sum < ((msis[i] + msds[i]) - arr[i])):
max_sum = ((msis[i] + msds[i]) - arr[i])
return max_sum | int maximum_sum_bitonic_subarray(vector<int> arr, int n) {
int msis [ n ], msds [ n ];
int max_sum = INT_MIN;
msis [ 0 ] = arr [ 0 ];
for ( int i = 1;
i < n;
i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ];
else msis [ i ] = arr [ i ];
msds [ n - 1 ] = arr [ n - 1 ];
for ( int i = n - 2;
i >= 0;
i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ];
else msds [ i ] = arr [ i ];
for ( int i = 0;
i < n;
i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ];
return max_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> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({7, 12, 16, 23, 26, 27, 39, 39, 40, 44, 57, 58, 77, 78, 81, 82, 84, 86, 91, 94, 94, 95, 97}, 13, 315); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({72, 38, -60, 98, -52, -38, -2, 94, 34, 56, 90, 46, 6, -2, 30, -96, -76, -96, -76, 32, 68, 64, -32, -4, 72, -62, 58, 20, -84, 0, -96, 70, -22, -56, 70, -74, -90, -86, -14, 82, -90, 40, -64, 94}, 37, 230); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({69, 31, 85, 84, 28, 28}, 5, 228); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -74, -24, -22, -22, 4, 20, 28, 30, 32, 36, 58, 58, 68, 92, 94, 98}, 16, 312); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1}, 10, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 2, 4, 6, 7, 8, 10, 15, 17, 19, 20, 21, 27, 28, 29, 32, 32, 40, 44, 46, 47, 49, 50, 50, 52, 55, 56, 58, 59, 64, 69, 73, 74, 74, 77, 80, 80, 84, 89, 91, 95, 96, 96, 97, 98, 98, 99}, 46, 610); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({26, -86, 8, 64, -40, 64, 60, -16, 54, -42, -86, 14, -48, -20, -42, -4, -34, -52, -74, 22, 10}, 18, 68); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 5, 5, 56, 5, 38}, 3, 13); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumBitonicSubarray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 315, \"inputs\": {\"arr\": [7, 12, 16, 23, 26, 27, 39, 39, 40, 44, 57, 58, 77, 78, 81, 82, 84, 86, 91, 94, 94, 95, 97], \"n\": 13}}, {\"idx\": 1, \"outputs\": 230, \"inputs\": {\"arr\": [72, 38, -60, 98, -52, -38, -2, 94, 34, 56, 90, 46, 6, -2, 30, -96, -76, -96, -76, 32, 68, 64, -32, -4, 72, -62, 58, 20, -84, 0, -96, 70, -22, -56, 70, -74, -90, -86, -14, 82, -90, 40, -64, 94], \"n\": 37}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 33}}, {\"idx\": 3, \"outputs\": 228, \"inputs\": {\"arr\": [69, 31, 85, 84, 28, 28], \"n\": 5}}, {\"idx\": 4, \"outputs\": 312, \"inputs\": {\"arr\": [-80, -74, -24, -22, -22, 4, 20, 28, 30, 32, 36, 58, 58, 68, 92, 94, 98], \"n\": 16}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1], \"n\": 10}}, {\"idx\": 6, \"outputs\": 610, \"inputs\": {\"arr\": [2, 2, 2, 4, 6, 7, 8, 10, 15, 17, 19, 20, 21, 27, 28, 29, 32, 32, 40, 44, 46, 47, 49, 50, 50, 52, 55, 56, 58, 59, 64, 69, 73, 74, 74, 77, 80, 80, 84, 89, 91, 95, 96, 96, 97, 98, 98, 99], \"n\": 46}}, {\"idx\": 7, \"outputs\": 68, \"inputs\": {\"arr\": [26, -86, 8, 64, -40, 64, 60, -16, 54, -42, -86, 14, -48, -20, -42, -4, -34, -52, -74, 22, 10], \"n\": 18}}, {\"idx\": 8, \"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, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 27}}, {\"idx\": 9, \"outputs\": 13, \"inputs\": {\"arr\": [8, 5, 5, 56, 5, 38], \"n\": 3}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
322 | Maximum Sum Iarri Among Rotations Given Array | C++ | int maximumSumIarriAmongRotationsGivenArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_sum_iarri_among_rotations_given_array(arr, n):
res = (- sys.maxsize)
for i in range(0, n):
curr_sum = 0
for j in range(0, n):
index = int(((i + j) % n))
curr_sum += (j * arr[index])
res = max(res, curr_sum)
return res | int maximum_sum_iarri_among_rotations_given_array(vector<int> arr, int n) {
int res = INT_MIN;
for ( int i = 0;
i < n;
i ++ ) {
int curr_sum = 0;
for ( int j = 0;
j < n;
j ++ ) {
int index = ( i + j ) % n;
curr_sum += j * arr [ index ];
}
res = max ( res, curr_sum );
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int 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({11, 12, 16, 26, 29, 40, 54, 59, 65, 70, 71, 73, 78, 81, 87, 87, 88, 90, 95, 97}, 11, 3035); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-46, -32, 54, 96, -72, -58, -36, -44, 26, -2, -68, 42, 90, 26, -92, -96, 88, -42, -18, 46, -70, 24, 0, 24, 34, 34, -52, 50, 94, -60, 64, 58}, 22, 592); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, 392); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({48, 2, 79, 98, 28, 17, 41, 47, 61, 76, 82, 5, 74, 4, 80, 51, 22, 45, 91, 75, 91, 93, 42, 45, 69, 98, 76, 74, 83, 17, 30, 88, 53, 25, 35, 19, 26}, 20, 10714); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -84, -82, -74, -44, -34, -32, -20, -20, -14, 6, 6, 10, 12, 16, 24, 32, 34, 38, 46, 54, 54, 56, 60, 82, 88, 90, 94, 98}, 24, 7026); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1}, 7, 19); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 14, 14, 14, 19, 20, 22, 26, 35, 36, 40, 53, 54, 55, 55, 57, 57, 67, 72, 72, 77, 78, 83, 84, 95, 96}, 16, 5149); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, 18, -76, 48, -52, -38, 52, -82, 40, -44, -90, 86, -86, -36, -32, -2, 56, -12, -88, 14, -16, 8, 52, 24, 46, 56, 84, -36, 84, -60, 72, -46, 32, -16, -20, 68, -86, -62, 58, 8, 78, -52, 22, -28, -22, -42, 12, -48}, 30, 4226); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 14, 46); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, 94, 36, 2, 50, 62, 84, 50, 66, 75, 1, 18, 41, 48, 72, 61, 86, 22, 54, 6, 71, 46, 92, 68, 59, 51, 89, 31, 58, 78, 82, 84}, 25, 16847); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumIarriAmongRotationsGivenArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3035, \"inputs\": {\"arr\": [11, 12, 16, 26, 29, 40, 54, 59, 65, 70, 71, 73, 78, 81, 87, 87, 88, 90, 95, 97], \"n\": 11}}, {\"idx\": 1, \"outputs\": 592, \"inputs\": {\"arr\": [-46, -32, 54, 96, -72, -58, -36, -44, 26, -2, -68, 42, 90, 26, -92, -96, 88, -42, -18, 46, -70, 24, 0, 24, 34, 34, -52, 50, 94, -60, 64, 58], \"n\": 22}}, {\"idx\": 2, \"outputs\": 392, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 33}}, {\"idx\": 3, \"outputs\": 10714, \"inputs\": {\"arr\": [48, 2, 79, 98, 28, 17, 41, 47, 61, 76, 82, 5, 74, 4, 80, 51, 22, 45, 91, 75, 91, 93, 42, 45, 69, 98, 76, 74, 83, 17, 30, 88, 53, 25, 35, 19, 26], \"n\": 20}}, {\"idx\": 4, \"outputs\": 7026, \"inputs\": {\"arr\": [-88, -84, -82, -74, -44, -34, -32, -20, -20, -14, 6, 6, 10, 12, 16, 24, 32, 34, 38, 46, 54, 54, 56, 60, 82, 88, 90, 94, 98], \"n\": 24}}, {\"idx\": 5, \"outputs\": 19, \"inputs\": {\"arr\": [0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 6, \"outputs\": 5149, \"inputs\": {\"arr\": [10, 14, 14, 14, 19, 20, 22, 26, 35, 36, 40, 53, 54, 55, 55, 57, 57, 67, 72, 72, 77, 78, 83, 84, 95, 96], \"n\": 16}}, {\"idx\": 7, \"outputs\": 4226, \"inputs\": {\"arr\": [-80, 18, -76, 48, -52, -38, 52, -82, 40, -44, -90, 86, -86, -36, -32, -2, 56, -12, -88, 14, -16, 8, 52, 24, 46, 56, 84, -36, 84, -60, 72, -46, 32, -16, -20, 68, -86, -62, 58, 8, 78, -52, 22, -28, -22, -42, 12, -48], \"n\": 30}}, {\"idx\": 8, \"outputs\": 46, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 14}}, {\"idx\": 9, \"outputs\": 16847, \"inputs\": {\"arr\": [20, 94, 36, 2, 50, 62, 84, 50, 66, 75, 1, 18, 41, 48, 72, 61, 86, 22, 54, 6, 71, 46, 92, 68, 59, 51, 89, 31, 58, 78, 82, 84], \"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
]
} |
323 | Maximum Sum Iarri Among Rotations Given Array 1 | C++ | int maximumSumIarriAmongRotationsGivenArray1(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_sum_iarri_among_rotations_given_array_1(arr, n):
cum_sum = 0
for i in range(0, n):
cum_sum += arr[i]
curr_val = 0
for i in range(0, n):
curr_val += (i * arr[i])
res = curr_val
for i in range(1, n):
next_val = ((curr_val - (cum_sum - arr[(i - 1)])) + (arr[(i - 1)] * (n - 1)))
curr_val = next_val
res = max(res, next_val)
return res | int maximum_sum_iarri_among_rotations_given_array_1(vector<int> arr, int n) {
int cum_sum = 0;
for ( int i = 0;
i < n;
i ++ ) cum_sum += arr [ i ];
int curr_val = 0;
for ( int i = 0;
i < n;
i ++ ) curr_val += i * arr [ i ];
int res = curr_val;
for ( int i = 1;
i < n;
i ++ ) {
int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 );
curr_val = next_val;
res = max ( res, next_val );
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int 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, 6, 13, 14, 16, 20, 24, 24, 24, 27, 28, 36, 49, 51, 55, 56, 62, 69, 74, 74, 76, 85, 86, 90, 92, 98}, 13, 2249); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-42, 96, 68, 64, 14, -74, 76, 42, 34, -92, -20, 28, -80, -34, -22, 96, -46, 96, 10, -82, 82, 50, -24, 48, 56, 72, -40, -86, 84, 66, -62, 50, -76, 34}, 27, 9152); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 10, 35); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({37, 88, 70, 86, 24, 62, 34, 44, 37, 42, 46, 34, 23, 32, 55, 2, 5, 70, 30, 46, 40, 65, 91, 4, 7, 74, 46, 12, 30, 22, 1, 91, 89, 88, 97, 6, 6, 11, 33, 14, 68, 24}, 39, 34887); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -90, -70, -70, -10, 2, 10, 12, 14, 40, 44, 46, 64, 68, 68, 96}, 11, 586); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1}, 15, 58); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9, 15, 15, 17, 19, 20, 21, 23, 25, 25, 25, 32, 32, 33, 45, 51, 54, 59, 68, 71, 71, 71, 72, 75, 78, 80, 82, 82, 88, 89, 92, 93, 94, 97}, 22, 11145); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, -78, -80, 32, -56, -98, -36, 86, 34, -36, 42, 46, 50, 0, 34, -46, -2, -18, -96, 12, -42, 62, 32, 78, 66, -8, 50, 60, 10, -18, 66, 80, -24, -98, 8, 48, 34, 44, -80, -34, 72, 0, -60, 52, 40, 20}, 45, 14776); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, 297); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({45, 35, 25, 7, 24, 73, 25, 86, 48, 70, 47, 91, 96, 15, 39, 9}, 8, 1359); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumIarriAmongRotationsGivenArray1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2249, \"inputs\": {\"arr\": [6, 6, 13, 14, 16, 20, 24, 24, 24, 27, 28, 36, 49, 51, 55, 56, 62, 69, 74, 74, 76, 85, 86, 90, 92, 98], \"n\": 13}}, {\"idx\": 1, \"outputs\": 9152, \"inputs\": {\"arr\": [-42, 96, 68, 64, 14, -74, 76, 42, 34, -92, -20, 28, -80, -34, -22, 96, -46, 96, 10, -82, 82, 50, -24, 48, 56, 72, -40, -86, 84, 66, -62, 50, -76, 34], \"n\": 27}}, {\"idx\": 2, \"outputs\": 35, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 10}}, {\"idx\": 3, \"outputs\": 34887, \"inputs\": {\"arr\": [37, 88, 70, 86, 24, 62, 34, 44, 37, 42, 46, 34, 23, 32, 55, 2, 5, 70, 30, 46, 40, 65, 91, 4, 7, 74, 46, 12, 30, 22, 1, 91, 89, 88, 97, 6, 6, 11, 33, 14, 68, 24], \"n\": 39}}, {\"idx\": 4, \"outputs\": 586, \"inputs\": {\"arr\": [-92, -90, -70, -70, -10, 2, 10, 12, 14, 40, 44, 46, 64, 68, 68, 96], \"n\": 11}}, {\"idx\": 5, \"outputs\": 58, \"inputs\": {\"arr\": [1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1], \"n\": 15}}, {\"idx\": 6, \"outputs\": 11145, \"inputs\": {\"arr\": [9, 15, 15, 17, 19, 20, 21, 23, 25, 25, 25, 32, 32, 33, 45, 51, 54, 59, 68, 71, 71, 71, 72, 75, 78, 80, 82, 82, 88, 89, 92, 93, 94, 97], \"n\": 22}}, {\"idx\": 7, \"outputs\": 14776, \"inputs\": {\"arr\": [52, -78, -80, 32, -56, -98, -36, 86, 34, -36, 42, 46, 50, 0, 34, -46, -2, -18, -96, 12, -42, 62, 32, 78, 66, -8, 50, 60, 10, -18, 66, 80, -24, -98, 8, 48, 34, 44, -80, -34, 72, 0, -60, 52, 40, 20], \"n\": 45}}, {\"idx\": 8, \"outputs\": 297, \"inputs\": {\"arr\": [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], \"n\": 33}}, {\"idx\": 9, \"outputs\": 1359, \"inputs\": {\"arr\": [45, 35, 25, 7, 24, 73, 25, 86, 48, 70, 47, 91, 96, 15, 39, 9], \"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
]
} |
324 | Maximum Sum Pairs Specific Difference | C++ | int maximumSumPairsSpecificDifference(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def maximum_sum_pairs_specific_difference(arr, N, K):
arr.sort()
dp = ([0] * N)
dp[0] = 0
for i in range(1, N):
dp[i] = dp[(i - 1)]
if ((arr[i] - arr[(i - 1)]) < K):
if (i >= 2):
dp[i] = max(dp[i], ((dp[(i - 2)] + arr[i]) + arr[(i - 1)]))
else:
dp[i] = max(dp[i], (arr[i] + arr[(i - 1)]))
return dp[(N - 1)] | int maximum_sum_pairs_specific_difference(vector<int> arr, int N, int K) {
sort(arr.begin(), arr.end());
int dp [ N ];
dp [ 0 ] = 0;
for ( int i = 1;
i < N;
i ++ ) {
dp [ i ] = dp [ i - 1 ];
if ( arr [ i ] - arr [ i - 1 ] < K ) {
if ( i >= 2 ) dp [ i ] = max ( dp [ i ], dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] );
else dp [ i ] = max ( dp [ i ], arr [ i ] + arr [ i - 1 ] );
}
}
return dp [ N - 1 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({48, 53, 67, 78, 78, 93, 95}, 6, 4, 156); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-70, -32, -2, 18, 30, 32, 52, 70, 72, 88}, 8, 8, 62); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 31, 10); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 5, 5, 6, 10, 12, 13, 13, 16, 23, 23, 34, 36, 39, 40, 42, 45, 45, 47, 51, 51, 52, 56, 57, 58, 60, 60, 60, 60, 61, 63, 67, 68, 71, 73, 75, 80, 80, 82, 84, 86, 86, 86, 86, 89, 90, 98, 99}, 31, 37, 1083); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, -56, 68, 78}, 3, 3, 0); \n cout << \"TEST-\" << 4 << \"...\"\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}, 14, 9, 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 3, 9, 12, 12, 16, 17, 18, 19, 20, 21, 21, 26, 29, 42, 44, 45, 48, 48, 48, 54, 54, 55, 60, 63, 63, 64, 64, 67, 67, 68, 69, 74, 78, 78, 79, 83, 95, 95, 95, 96, 97, 99}, 27, 42, 849); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -58, -56, -48, -42, -16, -14, 28, 40, 42, 54, 60, 64}, 9, 8, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 19, 9); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({25, 64, 96}, 1, 1, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumPairsSpecificDifference",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 156, \"inputs\": {\"arr\": [48, 53, 67, 78, 78, 93, 95], \"n\": 6, \"k\": 4}}, {\"idx\": 1, \"outputs\": 62, \"inputs\": {\"arr\": [-70, -32, -2, 18, 30, 32, 52, 70, 72, 88], \"n\": 8, \"k\": 8}}, {\"idx\": 2, \"outputs\": 10, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 37, \"k\": 31}}, {\"idx\": 3, \"outputs\": 1083, \"inputs\": {\"arr\": [2, 3, 5, 5, 6, 10, 12, 13, 13, 16, 23, 23, 34, 36, 39, 40, 42, 45, 45, 47, 51, 51, 52, 56, 57, 58, 60, 60, 60, 60, 61, 63, 67, 68, 71, 73, 75, 80, 80, 82, 84, 86, 86, 86, 86, 89, 90, 98, 99], \"n\": 31, \"k\": 37}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-84, -56, 68, 78], \"n\": 3, \"k\": 3}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 14, \"k\": 9}}, {\"idx\": 6, \"outputs\": 849, \"inputs\": {\"arr\": [1, 2, 3, 9, 12, 12, 16, 17, 18, 19, 20, 21, 21, 26, 29, 42, 44, 45, 48, 48, 48, 54, 54, 55, 60, 63, 63, 64, 64, 67, 67, 68, 69, 74, 78, 78, 79, 83, 95, 95, 95, 96, 97, 99], \"n\": 27, \"k\": 42}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-92, -58, -56, -48, -42, -16, -14, 28, 40, 42, 54, 60, 64], \"n\": 9, \"k\": 8}}, {\"idx\": 8, \"outputs\": 9, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 21, \"k\": 19}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [25, 64, 96], \"n\": 1, \"k\": 1}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
325 | Maximum Sum Pairs Specific Difference 1 | C++ | int maximumSumPairsSpecificDifference1(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def maximum_sum_pairs_specific_difference_1(arr, N, k):
maxSum = 0
arr.sort()
i = (N - 1)
while (i >= 0):
if ((arr[i] - arr[(i - 1)]) < k):
maxSum += arr[i]
maxSum += arr[(i - 1)]
i -= 1
i -= 1
return maxSum | int maximum_sum_pairs_specific_difference_1(vector<int> arr, int N, int k) {
int maxSum = 0;
sort(arr.begin(), arr.end());
for ( int i = N - 1;
i > 0;
-- i ) {
if ( arr [ i ] - arr [ i - 1 ] < k ) {
maxSum += arr [ i ];
maxSum += arr [ i - 1 ];
-- i;
}
}
return maxSum;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 10, 11, 11, 12, 14, 15, 17, 27, 27, 28, 36, 36, 44, 47, 47, 54, 55, 62, 64, 68, 69, 70, 70, 75, 76, 78, 85, 85, 91, 95, 97}, 26, 18, 1047); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -86, -84, -72, -70, -70, -66, -62, -50, -44, -40, -36, -34, -30, -14, -12, -8, -4, -2, 2, 2, 10, 10, 30, 30, 36, 40, 58, 78, 78, 82, 88, 92}, 26, 25, -890); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 47, 26, 25); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58, 77, 78}, 1, 1, 136); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -88, -88, -82, -58, -54, -48, -46, -46, -44, -20, -2, 10, 28, 28, 28, 42, 42, 44, 50, 50, 54, 56, 58, 62, 68, 70, 72, 74, 76, 78, 88, 90, 92}, 21, 24, -322); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 41, 40, 23); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 7, 10, 11, 15, 17, 20, 20, 29, 29, 32, 37, 38, 39, 40, 41, 45, 51, 60, 64, 64, 68, 68, 70, 71, 71, 71, 75, 76, 82, 84, 87, 88, 88, 95, 98}, 30, 21, 1326); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -88, -74, -66, -60, -52, -46, -40, -36, -34, -32, -28, -28, -24, -22, -20, -16, -14, -4, -4, 4, 12, 18, 28, 32, 44, 52, 56, 60, 60, 64, 70, 74, 76, 76, 86, 94, 94, 94, 98}, 33, 23, -114); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 28, 41, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 2, 9, 9, 13, 14, 14, 15, 20, 22, 25, 25, 36, 39, 46, 47, 61, 63, 66, 73, 79, 91, 94, 95, 95, 99}, 19, 23, 561); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumPairsSpecificDifference1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1047, \"inputs\": {\"arr\": [2, 10, 11, 11, 12, 14, 15, 17, 27, 27, 28, 36, 36, 44, 47, 47, 54, 55, 62, 64, 68, 69, 70, 70, 75, 76, 78, 85, 85, 91, 95, 97], \"n\": 26, \"k\": 18}}, {\"idx\": 1, \"outputs\": -890, \"inputs\": {\"arr\": [-98, -92, -86, -84, -72, -70, -70, -66, -62, -50, -44, -40, -36, -34, -30, -14, -12, -8, -4, -2, 2, 2, 10, 10, 30, 30, 36, 40, 58, 78, 78, 82, 88, 92], \"n\": 26, \"k\": 25}}, {\"idx\": 2, \"outputs\": 25, \"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, 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\": 47, \"k\": 26}}, {\"idx\": 3, \"outputs\": 136, \"inputs\": {\"arr\": [58, 77, 78], \"n\": 1, \"k\": 1}}, {\"idx\": 4, \"outputs\": -322, \"inputs\": {\"arr\": [-88, -88, -88, -82, -58, -54, -48, -46, -46, -44, -20, -2, 10, 28, 28, 28, 42, 42, 44, 50, 50, 54, 56, 58, 62, 68, 70, 72, 74, 76, 78, 88, 90, 92], \"n\": 21, \"k\": 24}}, {\"idx\": 5, \"outputs\": 23, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 41, \"k\": 40}}, {\"idx\": 6, \"outputs\": 1326, \"inputs\": {\"arr\": [5, 7, 10, 11, 15, 17, 20, 20, 29, 29, 32, 37, 38, 39, 40, 41, 45, 51, 60, 64, 64, 68, 68, 70, 71, 71, 71, 75, 76, 82, 84, 87, 88, 88, 95, 98], \"n\": 30, \"k\": 21}}, {\"idx\": 7, \"outputs\": -114, \"inputs\": {\"arr\": [-98, -88, -74, -66, -60, -52, -46, -40, -36, -34, -32, -28, -28, -24, -22, -20, -16, -14, -4, -4, 4, 12, 18, 28, 32, 44, 52, 56, 60, 60, 64, 70, 74, 76, 76, 86, 94, 94, 94, 98], \"n\": 33, \"k\": 23}}, {\"idx\": 8, \"outputs\": 3, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 28, \"k\": 41}}, {\"idx\": 9, \"outputs\": 561, \"inputs\": {\"arr\": [1, 1, 2, 9, 9, 13, 14, 14, 15, 20, 22, 25, 25, 36, 39, 46, 47, 61, 63, 66, 73, 79, 91, 94, 95, 95, 99], \"n\": 19, \"k\": 23}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
326 | Maximum Sum Subarray Removing One Element | C++ | int maximumSumSubarrayRemovingOneElement(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_sum_subarray_removing_one_element(arr, n):
fw = [0 for k in range(n)]
bw = [0 for k in range(n)]
(cur_max, max_so_far) = (arr[0], arr[0])
for i in range(n):
cur_max = max(arr[i], (cur_max + arr[i]))
max_so_far = max(max_so_far, cur_max)
fw[i] = cur_max
cur_max = max_so_far = bw[(n - 1)] = arr[(n - 1)]
i = (n - 2)
while (i >= 0):
cur_max = max(arr[i], (cur_max + arr[i]))
max_so_far = max(max_so_far, cur_max)
bw[i] = cur_max
i -= 1
fans = max_so_far
for i in range(1, (n - 1)):
fans = max(fans, (fw[(i - 1)] + bw[(i + 1)]))
return fans | int maximum_sum_subarray_removing_one_element(vector<int> arr, int n) {
int fw [ n ], bw [ n ];
int cur_max = arr [ 0 ], max_so_far = arr [ 0 ];
fw [ 0 ] = arr [ 0 ];
for ( int i = 1;
i < n;
i ++ ) {
cur_max = max ( arr [ i ], cur_max + arr [ i ] );
max_so_far = max ( max_so_far, cur_max );
fw [ i ] = cur_max;
}
cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ];
for ( int i = n - 2;
i >= 0;
i -- ) {
cur_max = max ( arr [ i ], cur_max + arr [ i ] );
max_so_far = max ( max_so_far, cur_max );
bw [ i ] = cur_max;
}
int fans = max_so_far;
for ( int i = 1;
i < n - 1;
i ++ ) fans = max ( fans, fw [ i - 1 ] + bw [ i + 1 ] );
return fans;
} | {
"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, 8, 14, 17, 19, 35, 38, 45, 50, 53, 55, 70, 82, 88, 92, 96}, 13, 488); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-64, -56, -80, -82, 72, 62, -8, 48, -96, 34, 64, -38, -60, 80, 4, -64, -62, 34, 94, -16, 38, 62, -84, 48, 42, -40}, 22, 344); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1}, 6, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 7, 50, 53, 72, 14, 18, 74, 27, 65, 41, 20, 54, 17, 87, 40, 63, 15, 47}, 11, 424); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -96, -94, -80, -74, -74, -74, -74, -70, -64, -60, -58, -52, -52, -44, -42, -40, -38, -36, -34, -30, -14, -12, -8, -2, 6, 12, 16, 24, 24, 48, 48, 66, 76, 76, 84, 90}, 32, 178); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0}, 8, 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 4, 5, 9, 11, 13, 13, 15, 16, 21, 23, 25, 27, 30, 31, 35, 35, 43, 43, 47, 49, 50, 52, 54, 55, 55, 57, 57, 57, 59, 62, 64, 66, 68, 69, 71, 73, 76, 80, 84, 88, 88, 90, 90, 97, 97, 99}, 34, 1255); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -60, 4, 14, 6, -6, -50, 46, -50, -62, -56, 16, -76, 90, 40, 2, 36, 48, -26, 34, 78, 84, 2, -54, 94, 60, -26, 60, 84, 2, -98, 2, -74}, 25, 482); \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, 1, 1}, 9, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({36, 99, 27, 8, 90, 74, 67, 77, 49, 23, 43, 25, 68, 56, 85, 6}, 12, 646); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumSubarrayRemovingOneElement",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 488, \"inputs\": {\"arr\": [2, 8, 14, 17, 19, 35, 38, 45, 50, 53, 55, 70, 82, 88, 92, 96], \"n\": 13}}, {\"idx\": 1, \"outputs\": 344, \"inputs\": {\"arr\": [-64, -56, -80, -82, 72, 62, -8, 48, -96, 34, 64, -38, -60, 80, 4, -64, -62, 34, 94, -16, 38, 62, -84, 48, 42, -40], \"n\": 22}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 1], \"n\": 6}}, {\"idx\": 3, \"outputs\": 424, \"inputs\": {\"arr\": [3, 7, 50, 53, 72, 14, 18, 74, 27, 65, 41, 20, 54, 17, 87, 40, 63, 15, 47], \"n\": 11}}, {\"idx\": 4, \"outputs\": 178, \"inputs\": {\"arr\": [-96, -96, -94, -80, -74, -74, -74, -74, -70, -64, -60, -58, -52, -52, -44, -42, -40, -38, -36, -34, -30, -14, -12, -8, -2, 6, 12, 16, 24, 24, 48, 48, 66, 76, 76, 84, 90], \"n\": 32}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"arr\": [1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0], \"n\": 8}}, {\"idx\": 6, \"outputs\": 1255, \"inputs\": {\"arr\": [4, 4, 5, 9, 11, 13, 13, 15, 16, 21, 23, 25, 27, 30, 31, 35, 35, 43, 43, 47, 49, 50, 52, 54, 55, 55, 57, 57, 57, 59, 62, 64, 66, 68, 69, 71, 73, 76, 80, 84, 88, 88, 90, 90, 97, 97, 99], \"n\": 34}}, {\"idx\": 7, \"outputs\": 482, \"inputs\": {\"arr\": [-86, -60, 4, 14, 6, -6, -50, 46, -50, -62, -56, 16, -76, 90, 40, 2, 36, 48, -26, 34, 78, 84, 2, -54, 94, 60, -26, 60, 84, 2, -98, 2, -74], \"n\": 25}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 9}}, {\"idx\": 9, \"outputs\": 646, \"inputs\": {\"arr\": [36, 99, 27, 8, 90, 74, 67, 77, 49, 23, 43, 25, 68, 56, 85, 6], \"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
]
} |
327 | Maximum Sum Subsequence Least K Distant Elements | C++ | int maximumSumSubsequenceLeastKDistantElements(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def maximum_sum_subsequence_least_k_distant_elements(arr, N, k):
MS = [0 for i in range(N)]
MS[(N - 1)] = arr[(N - 1)]
for i in range((N - 2), (- 1), (- 1)):
if (((i + k) + 1) >= N):
MS[i] = max(arr[i], MS[(i + 1)])
else:
MS[i] = max((arr[i] + MS[((i + k) + 1)]), MS[(i + 1)])
return MS[0] | int maximum_sum_subsequence_least_k_distant_elements(vector<int> arr, int N, int k) {
int MS [ N ];
MS [ N - 1 ] = arr [ N - 1 ];
for ( int i = N - 2;
i >= 0;
i -- ) {
if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ], MS [ i + 1 ] );
else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ], MS [ i + 1 ] );
}
return MS [ 0 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({3, 5, 20, 21, 23, 26, 27, 31, 33, 38, 39, 41, 48, 48, 50, 51, 56, 57, 64, 68, 69, 70, 71, 74, 76, 86, 97}, 23, 15, 98); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32, 34, -40, 90, -82, -70, 30, 26, -76, -46, -84, 76, -76}, 9, 10, 90); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 34, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 15, 30, 25, 83}, 2, 3, 96); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -82, -80, -76, -62, -58, -50, -48, -46, -38, -38, -38, -38, -38, -34, -32, -24, -22, -16, -16, -4, -2, 10, 10, 20, 26, 26, 32, 38, 38, 44, 44, 46, 48, 58, 62, 64, 66, 76, 78, 78, 82, 92, 96, 96, 98}, 27, 30, 26); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0}, 9, 9, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 9, 17, 24, 31, 31, 33, 56, 57, 61, 71, 73, 74, 76, 77, 79, 83, 86, 95, 99}, 12, 10, 72); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-12, 52, -44, 80, -66, 34, 42, -46, 8, 12, -22, -56, 74, -98, -44, 2, -24, -14, -54, -56, -26, -18, -72}, 13, 19, 80); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 13, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({65, 1, 34, 38, 15, 6, 55, 21, 32, 90, 39, 25, 43, 48, 64, 66, 88, 70, 82, 75, 25, 56, 23, 27, 41, 33, 33, 55, 60, 90, 41, 58, 42, 53, 38, 90, 7, 15}, 37, 33, 155); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumSumSubsequenceLeastKDistantElements",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 98, \"inputs\": {\"arr\": [3, 5, 20, 21, 23, 26, 27, 31, 33, 38, 39, 41, 48, 48, 50, 51, 56, 57, 64, 68, 69, 70, 71, 74, 76, 86, 97], \"n\": 23, \"k\": 15}}, {\"idx\": 1, \"outputs\": 90, \"inputs\": {\"arr\": [32, 34, -40, 90, -82, -70, 30, 26, -76, -46, -84, 76, -76], \"n\": 9, \"k\": 10}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 22, \"k\": 34}}, {\"idx\": 3, \"outputs\": 96, \"inputs\": {\"arr\": [96, 15, 30, 25, 83], \"n\": 2, \"k\": 3}}, {\"idx\": 4, \"outputs\": 26, \"inputs\": {\"arr\": [-90, -82, -80, -76, -62, -58, -50, -48, -46, -38, -38, -38, -38, -38, -34, -32, -24, -22, -16, -16, -4, -2, 10, 10, 20, 26, 26, 32, 38, 38, 44, 44, 46, 48, 58, 62, 64, 66, 76, 78, 78, 82, 92, 96, 96, 98], \"n\": 27, \"k\": 30}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0], \"n\": 9, \"k\": 9}}, {\"idx\": 6, \"outputs\": 72, \"inputs\": {\"arr\": [1, 2, 9, 17, 24, 31, 31, 33, 56, 57, 61, 71, 73, 74, 76, 77, 79, 83, 86, 95, 99], \"n\": 12, \"k\": 10}}, {\"idx\": 7, \"outputs\": 80, \"inputs\": {\"arr\": [-12, 52, -44, 80, -66, 34, 42, -46, 8, 12, -22, -56, 74, -98, -44, 2, -24, -14, -54, -56, -26, -18, -72], \"n\": 13, \"k\": 19}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13, \"k\": 13}}, {\"idx\": 9, \"outputs\": 155, \"inputs\": {\"arr\": [65, 1, 34, 38, 15, 6, 55, 21, 32, 90, 39, 25, 43, 48, 64, 66, 88, 70, 82, 75, 25, 56, 23, 27, 41, 33, 33, 55, 60, 90, 41, 58, 42, 53, 38, 90, 7, 15], \"n\": 37, \"k\": 33}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
328 | Maximum Triplet Sum Array | C++ | int maximumTripletSumArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_triplet_sum_array(arr, n):
sm = (- 1000000)
for i in range(0, n):
for j in range((i + 1), n):
for k in range((j + 1), n):
if (sm < ((arr[i] + arr[j]) + arr[k])):
sm = ((arr[i] + arr[j]) + arr[k])
return sm | int maximum_triplet_sum_array(vector<int> arr, int n) {
int sum = INT_MIN;
for ( int i = 0;
i < n;
i ++ ) for ( int j = i + 1;
j < n;
j ++ ) for ( int k = j + 1;
k < n;
k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ];
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> 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({6, 10, 14, 19, 24, 29, 42, 43, 44, 47, 47, 55, 57, 59, 60, 61, 76, 76, 77, 81, 84, 92, 92, 93, 95, 97}, 15, 176); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, 72, 52, -62, 74, -26, -82, -74, 90, 58, 94, -2, 76, -28, 12, 64, -94, 86, 56, 10, 40, 20, 92, -4, -80, 26, -40, 36, 66, -46, 4, -42, -76, 76, -90, -48, 22, 30, 48, 38, 78}, 28, 276); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 96, 38, 26, 2, 36, 15, 51, 78, 98, 94, 31, 62, 21, 7, 68, 37, 4}, 10, 290); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-8, 12, 68, 78, 78}, 4, 158); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, 35, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 15, 16, 17, 28, 28, 28, 30, 31, 37, 38, 38, 45, 45, 46, 46, 50, 51, 53, 53, 55, 55, 56, 58, 58, 64, 78, 82, 82, 85, 87, 89, 89, 90, 94, 95}, 29, 242); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, -72, -20, 88, 20, 86, 30, 36, -44, -66, -26, -88, 12, -76, 78, 62, 62, 68, -34, 0, -22, 64, 72, 56, -64, -16, -4, 86, 0, 98, -70, 98, -68, 92, -84, -56, 28, -74, 6, -10, -82, 36, -12, -26, 66, -60, -68, 70, 2}, 36, 288); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 11, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 31, 15, 68, 92, 89, 32, 56, 27, 70, 82, 58, 63, 83, 89, 95, 78, 9, 27, 34, 24, 42, 66, 6, 1, 71, 55, 23, 75, 26, 19, 58, 25}, 16, 276); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumTripletSumArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 176, \"inputs\": {\"arr\": [6, 10, 14, 19, 24, 29, 42, 43, 44, 47, 47, 55, 57, 59, 60, 61, 76, 76, 77, 81, 84, 92, 92, 93, 95, 97], \"n\": 15}}, {\"idx\": 1, \"outputs\": 276, \"inputs\": {\"arr\": [-98, 72, 52, -62, 74, -26, -82, -74, 90, 58, 94, -2, 76, -28, 12, 64, -94, 86, 56, 10, 40, 20, 92, -4, -80, 26, -40, 36, 66, -46, 4, -42, -76, 76, -90, -48, 22, 30, 48, 38, 78], \"n\": 28}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 22}}, {\"idx\": 3, \"outputs\": 290, \"inputs\": {\"arr\": [96, 96, 38, 26, 2, 36, 15, 51, 78, 98, 94, 31, 62, 21, 7, 68, 37, 4], \"n\": 10}}, {\"idx\": 4, \"outputs\": 158, \"inputs\": {\"arr\": [-8, 12, 68, 78, 78], \"n\": 4}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], \"n\": 35}}, {\"idx\": 6, \"outputs\": 242, \"inputs\": {\"arr\": [1, 15, 16, 17, 28, 28, 28, 30, 31, 37, 38, 38, 45, 45, 46, 46, 50, 51, 53, 53, 55, 55, 56, 58, 58, 64, 78, 82, 82, 85, 87, 89, 89, 90, 94, 95], \"n\": 29}}, {\"idx\": 7, \"outputs\": 288, \"inputs\": {\"arr\": [-56, -72, -20, 88, 20, 86, 30, 36, -44, -66, -26, -88, 12, -76, 78, 62, 62, 68, -34, 0, -22, 64, 72, 56, -64, -16, -4, 86, 0, 98, -70, 98, -68, 92, -84, -56, 28, -74, 6, -10, -82, 36, -12, -26, 66, -60, -68, 70, 2], \"n\": 36}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 11}}, {\"idx\": 9, \"outputs\": 276, \"inputs\": {\"arr\": [85, 31, 15, 68, 92, 89, 32, 56, 27, 70, 82, 58, 63, 83, 89, 95, 78, 9, 27, 34, 24, 42, 66, 6, 1, 71, 55, 23, 75, 26, 19, 58, 25], \"n\": 16}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
329 | Maximum Triplet Sum Array 1 | C++ | int maximumTripletSumArray1(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_triplet_sum_array_1(arr, n):
arr.sort()
return ((arr[(n - 1)] + arr[(n - 2)]) + arr[(n - 3)]) | int maximum_triplet_sum_array_1(vector<int> arr, int n) {
sort(arr.begin(), arr.end());
return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 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(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({6, 8, 18, 18, 27, 33, 33, 38, 42, 43, 44, 47, 52, 58, 64, 65, 67, 68, 71, 75, 85, 89, 91, 94, 94, 95, 95}, 26, 283); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -84, -82, -58, -12, 18, 24, 24, 28, 30, 34, 44, 92, 94}, 8, 66); \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}, 15, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 4, 5, 9, 11, 12, 15, 16, 18, 18, 21, 23, 25, 25, 26, 27, 28, 31, 34, 35, 47, 51, 55, 63, 63, 66, 67, 70, 70, 72, 73, 73, 75, 76, 79, 81, 84, 87, 87, 92, 94, 95}, 37, 236); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -86, -78, -56, -24, -14, -10, -6, 12, 12, 18, 22, 22, 26, 50, 50, 72, 78, 94}, 9, -4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 9, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 13, 17, 19, 20, 23, 28, 28, 29, 40, 45, 51, 52, 58, 58, 68, 70, 75, 79, 81, 92, 96, 97}, 15, 168); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, -62, -46, -36, -20, -4, 4, 6, 6, 40, 50, 52, 64, 76, 94}, 13, 166); \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}, 27, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 3, 4, 5, 6, 7, 11, 11, 14, 15, 17, 22, 25, 32, 33, 34, 35, 42, 44, 44, 52, 57, 58, 66, 70, 89}, 13, 64); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumTripletSumArray1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 283, \"inputs\": {\"arr\": [6, 8, 18, 18, 27, 33, 33, 38, 42, 43, 44, 47, 52, 58, 64, 65, 67, 68, 71, 75, 85, 89, 91, 94, 94, 95, 95], \"n\": 26}}, {\"idx\": 1, \"outputs\": 66, \"inputs\": {\"arr\": [-88, -84, -82, -58, -12, 18, 24, 24, 28, 30, 34, 44, 92, 94], \"n\": 8}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 15}}, {\"idx\": 3, \"outputs\": 236, \"inputs\": {\"arr\": [1, 2, 4, 5, 9, 11, 12, 15, 16, 18, 18, 21, 23, 25, 25, 26, 27, 28, 31, 34, 35, 47, 51, 55, 63, 63, 66, 67, 70, 70, 72, 73, 73, 75, 76, 79, 81, 84, 87, 87, 92, 94, 95], \"n\": 37}}, {\"idx\": 4, \"outputs\": -4, \"inputs\": {\"arr\": [-86, -86, -78, -56, -24, -14, -10, -6, 12, 12, 18, 22, 22, 26, 50, 50, 72, 78, 94], \"n\": 9}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 9}}, {\"idx\": 6, \"outputs\": 168, \"inputs\": {\"arr\": [2, 13, 17, 19, 20, 23, 28, 28, 29, 40, 45, 51, 52, 58, 58, 68, 70, 75, 79, 81, 92, 96, 97], \"n\": 15}}, {\"idx\": 7, \"outputs\": 166, \"inputs\": {\"arr\": [-78, -62, -46, -36, -20, -4, 4, 6, 6, 40, 50, 52, 64, 76, 94], \"n\": 13}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 27}}, {\"idx\": 9, \"outputs\": 64, \"inputs\": {\"arr\": [3, 3, 4, 5, 6, 7, 11, 11, 14, 15, 17, 22, 25, 32, 33, 34, 35, 42, 44, 44, 52, 57, 58, 66, 70, 89], \"n\": 13}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
330 | Maximum Triplet Sum Array 2 | C++ | int maximumTripletSumArray2(vector<int> arr, int n) { | [
"arr",
"n"
] | def maximum_triplet_sum_array_2(arr, n):
maxA = (- 100000000)
maxB = (- 100000000)
maxC = (- 100000000)
for i in range(0, n):
if (arr[i] > maxA):
maxC = maxB
maxB = maxA
maxA = arr[i]
elif (arr[i] > maxB):
maxC = maxB
maxB = arr[i]
elif (arr[i] > maxC):
maxC = arr[i]
return ((maxA + maxB) + maxC) | int maximum_triplet_sum_array_2(vector<int> arr, int n) {
int maxA = INT_MIN, maxB = INT_MIN, maxC = INT_MIN;
for ( int i = 0;
i < n;
i ++ ) {
if ( arr [ i ] > maxA ) {
maxC = maxB;
maxB = maxA;
maxA = arr [ i ];
}
else if ( arr [ i ] > maxB ) {
maxC = maxB;
maxB = arr [ i ];
}
else if ( arr [ i ] > maxC ) maxC = arr [ i ];
}
return ( maxA + maxB + maxC );
} | {
"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, 7, 12, 21, 22, 25, 27, 28, 28, 31, 32, 32, 41, 45, 47, 51, 53, 60, 61, 61, 63, 71, 74, 82, 83, 85, 88, 92, 96, 96}, 28, 265); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-52, 26, 74, -62, -76}, 2, -100000026); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 11, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({63, 71, 15, 28, 31, 84, 8, 17, 24, 42, 66, 95, 30}, 6, 218); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -92, -92, -90, -88, -88, -86, -82, -80, -78, -66, -54, -52, -52, -46, -46, -42, -36, -32, -24, -24, -14, -14, -14, -12, -10, 0, 6, 8, 20, 24, 24, 28, 38, 38, 52, 54, 56, 64, 74, 74, 76, 82, 94, 94}, 31, 52); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0}, 30, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({15, 19, 80}, 2, -99999966); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 80, 18, 74, 36, -30, -72, -28, -32, -16, -8, 38, 78, -48, 98, -64, 86, -60, -44, 84, -98, 40, 14, 30, 44, 90, -30, -42, 24, -28, 24, 40, -96, 98, 90, -68, -54, -52, 62, 34, -98, 68, -56, -94, -78, -12, 28}, 41, 286); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1, 1}, 3, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 18, 96, 7, 99, 83, 3, 88, 23, 77, 6, 28, 55, 49, 69, 55, 48, 76, 43, 11, 43, 44, 17, 74, 27, 64, 76, 77, 53, 26, 73, 12, 19, 62, 18, 34, 13, 31, 97, 96, 85, 27, 30, 97, 89, 25}, 41, 292); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumTripletSumArray2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 265, \"inputs\": {\"arr\": [4, 7, 12, 21, 22, 25, 27, 28, 28, 31, 32, 32, 41, 45, 47, 51, 53, 60, 61, 61, 63, 71, 74, 82, 83, 85, 88, 92, 96, 96], \"n\": 28}}, {\"idx\": 1, \"outputs\": -100000026, \"inputs\": {\"arr\": [-52, 26, 74, -62, -76], \"n\": 2}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 11}}, {\"idx\": 3, \"outputs\": 218, \"inputs\": {\"arr\": [63, 71, 15, 28, 31, 84, 8, 17, 24, 42, 66, 95, 30], \"n\": 6}}, {\"idx\": 4, \"outputs\": 52, \"inputs\": {\"arr\": [-94, -92, -92, -90, -88, -88, -86, -82, -80, -78, -66, -54, -52, -52, -46, -46, -42, -36, -32, -24, -24, -14, -14, -14, -12, -10, 0, 6, 8, 20, 24, 24, 28, 38, 38, 52, 54, 56, 64, 74, 74, 76, 82, 94, 94], \"n\": 31}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0], \"n\": 30}}, {\"idx\": 6, \"outputs\": -99999966, \"inputs\": {\"arr\": [15, 19, 80], \"n\": 2}}, {\"idx\": 7, \"outputs\": 286, \"inputs\": {\"arr\": [4, 80, 18, 74, 36, -30, -72, -28, -32, -16, -8, 38, 78, -48, 98, -64, 86, -60, -44, 84, -98, 40, 14, 30, 44, 90, -30, -42, 24, -28, 24, 40, -96, 98, 90, -68, -54, -52, 62, 34, -98, 68, -56, -94, -78, -12, 28], \"n\": 41}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr\": [0, 1, 1, 1, 1, 1], \"n\": 3}}, {\"idx\": 9, \"outputs\": 292, \"inputs\": {\"arr\": [2, 18, 96, 7, 99, 83, 3, 88, 23, 77, 6, 28, 55, 49, 69, 55, 48, 76, 43, 11, 43, 44, 17, 74, 27, 64, 76, 77, 53, 26, 73, 12, 19, 62, 18, 34, 13, 31, 97, 96, 85, 27, 30, 97, 89, 25], \"n\": 41}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
331 | Maximum Value Choice Either Dividing Considering | C++ | int maximumValueChoiceEitherDividingConsidering(int n) { | [
"n"
] | def maximum_value_choice_either_dividing_considering(n):
res = list()
res.append(0)
res.append(1)
i = 2
while (i < (n + 1)):
res.append(max(i, (((res[int((i / 2))] + res[int((i / 3))]) + res[int((i / 4))]) + res[int((i / 5))])))
i = (i + 1)
return res[n] | int maximum_value_choice_either_dividing_considering(int n) {
int res [ n + 1 ];
res [ 0 ] = 0;
res [ 1 ] = 1;
for ( int i = 2;
i <= n;
i ++ ) res [ i ] = max ( i, ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) );
return res [ 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(3, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 24); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 57); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 152); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 192); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 114); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 83); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 5); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "maximumValueChoiceEitherDividingConsidering",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"n\": 3}}, {\"idx\": 1, \"outputs\": 24, \"inputs\": {\"n\": 19}}, {\"idx\": 2, \"outputs\": 57, \"inputs\": {\"n\": 39}}, {\"idx\": 3, \"outputs\": 152, \"inputs\": {\"n\": 89}}, {\"idx\": 4, \"outputs\": 192, \"inputs\": {\"n\": 96}}, {\"idx\": 5, \"outputs\": 114, \"inputs\": {\"n\": 68}}, {\"idx\": 6, \"outputs\": 83, \"inputs\": {\"n\": 48}}, {\"idx\": 7, \"outputs\": 5, \"inputs\": {\"n\": 5}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"n\": 3}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"n\": 4}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
332 | Median Of Two Sorted Arrays | C++ | float medianOfTwoSortedArrays(vector<int> ar1, vector<int> ar2, int n) { | [
"ar1",
"ar2",
"n"
] | def median_of_two_sorted_arrays(ar1, ar2, n):
i = 0
j = 0
m1 = (- 1)
m2 = (- 1)
count = 0
while (count < (n + 1)):
count += 1
if (i == n):
m1 = m2
m2 = ar2[0]
break
elif (j == n):
m1 = m2
m2 = ar1[0]
break
if (ar1[i] < ar2[j]):
m1 = m2
m2 = ar1[i]
i += 1
else:
m1 = m2
m2 = ar2[j]
j += 1
return ((m1 + m2) / 2) | int median_of_two_sorted_arrays(vector<int> ar1, vector<int> ar2, int n) {
int i = 0;
int j = 0;
int count;
int m1 = - 1, m2 = - 1;
for ( count = 0;
count <= n;
count ++ ) {
if ( i == n ) {
m1 = m2;
m2 = ar2 [ 0 ];
break;
}
else if ( j == n ) {
m1 = m2;
m2 = ar1 [ 0 ];
break;
}
if ( ar1 [ i ] < ar2 [ j ] ) {
m1 = m2;
m2 = ar1 [ i ];
i ++;
}
else {
m1 = m2;
m2 = ar2 [ j ];
j ++;
}
}
return ( m1 + m2 ) / 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(vector<int> ar1, vector<int> ar2, int n, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(ar1, ar2, 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, 6, 18, 21, 23, 27, 44, 44, 69, 72, 78, 88, 90, 98}, {6, 12, 16, 18, 26, 34, 48, 48, 49, 56, 61, 79, 81, 89}, 12, 39.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({90, 54, 24, -10, -84, -74, 58, 96, -28, -92, -18, 90, 70, -60, 72, 78, 10, 42, -2, -18, -38, -16, 18, -86, 40, -46, -38, 66, 20, -16, 48}, {-72, -62, 14, -58, 70, 54, 88, -40, -94, 4, 60, -16, -38, -98, -70, -46, 66, 42, 26, 36, 56, -4, 32, 30, -46, -42, -72, 44, 16, 4, 24}, 16, 22.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1}, {0, 1, 1}, 2, 0.5); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({53, 17, 94, 21, 16, 75, 67, 51, 44, 71, 65, 82}, {98, 50, 8, 11, 80, 41, 59, 24, 94, 41, 75, 78}, 10, 84.5); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -80, -68, -64, -64, -60, -56, -52, -50, -50, -22, -20, -4, -2, 0, 6, 20, 22, 28, 38, 40, 48, 50, 56, 58, 64, 64, 80, 82, 90, 92, 92, 92}, {-88, -72, -72, -58, -54, -50, -48, -34, -24, -14, -14, -14, -10, -6, 4, 12, 16, 18, 26, 30, 32, 34, 40, 46, 52, 54, 58, 62, 62, 72, 82, 82, 92, 98}, 25, -12.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1}, {1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1}, 40, 0.5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 15, 17, 19, 21, 32, 34, 38, 41, 41, 49, 49, 51, 54, 54, 56, 56, 57, 59, 63, 70, 74, 79, 79, 84, 84, 86, 88, 89, 93, 98}, {5, 6, 17, 18, 22, 29, 32, 33, 36, 44, 45, 47, 59, 59, 60, 65, 67, 68, 69, 71, 72, 76, 78, 81, 84, 85, 85, 86, 86, 87, 92}, 29, 56.5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, -42, -94, -46, -68, 76, 8, 16, -54, -94, 76, 24, 94, 10, 34, 78, -30, 0, -52, 80, 98, -58, 92, 12, 26, 64}, {88, 78, -26, 10, 84, 34, 56, -8, -30, 46, 48, 20, 26, -78, 96, 44, 92, -44, -86, 24, -58, -96, -86, -12, -98, 18}, 17, 94.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}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 0.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({61, 69, 66, 3}, {39, 84, 97, 15}, 3, 67.5); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "medianOfTwoSortedArrays",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 39.0, \"inputs\": {\"ar1\": [2, 6, 18, 21, 23, 27, 44, 44, 69, 72, 78, 88, 90, 98], \"ar2\": [6, 12, 16, 18, 26, 34, 48, 48, 49, 56, 61, 79, 81, 89], \"n\": 12}}, {\"idx\": 1, \"outputs\": 22.0, \"inputs\": {\"ar1\": [90, 54, 24, -10, -84, -74, 58, 96, -28, -92, -18, 90, 70, -60, 72, 78, 10, 42, -2, -18, -38, -16, 18, -86, 40, -46, -38, 66, 20, -16, 48], \"ar2\": [-72, -62, 14, -58, 70, 54, 88, -40, -94, 4, 60, -16, -38, -98, -70, -46, 66, 42, 26, 36, 56, -4, 32, 30, -46, -42, -72, 44, 16, 4, 24], \"n\": 16}}, {\"idx\": 2, \"outputs\": 0.5, \"inputs\": {\"ar1\": [0, 1, 1], \"ar2\": [0, 1, 1], \"n\": 2}}, {\"idx\": 3, \"outputs\": 84.5, \"inputs\": {\"ar1\": [53, 17, 94, 21, 16, 75, 67, 51, 44, 71, 65, 82], \"ar2\": [98, 50, 8, 11, 80, 41, 59, 24, 94, 41, 75, 78], \"n\": 10}}, {\"idx\": 4, \"outputs\": -12.0, \"inputs\": {\"ar1\": [-96, -92, -80, -68, -64, -64, -60, -56, -52, -50, -50, -22, -20, -4, -2, 0, 6, 20, 22, 28, 38, 40, 48, 50, 56, 58, 64, 64, 80, 82, 90, 92, 92, 92], \"ar2\": [-88, -72, -72, -58, -54, -50, -48, -34, -24, -14, -14, -14, -10, -6, 4, 12, 16, 18, 26, 30, 32, 34, 40, 46, 52, 54, 58, 62, 62, 72, 82, 82, 92, 98], \"n\": 25}}, {\"idx\": 5, \"outputs\": 0.5, \"inputs\": {\"ar1\": [0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1], \"ar2\": [1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1], \"n\": 40}}, {\"idx\": 6, \"outputs\": 56.5, \"inputs\": {\"ar1\": [8, 15, 17, 19, 21, 32, 34, 38, 41, 41, 49, 49, 51, 54, 54, 56, 56, 57, 59, 63, 70, 74, 79, 79, 84, 84, 86, 88, 89, 93, 98], \"ar2\": [5, 6, 17, 18, 22, 29, 32, 33, 36, 44, 45, 47, 59, 59, 60, 65, 67, 68, 69, 71, 72, 76, 78, 81, 84, 85, 85, 86, 86, 87, 92], \"n\": 29}}, {\"idx\": 7, \"outputs\": 94.0, \"inputs\": {\"ar1\": [96, -42, -94, -46, -68, 76, 8, 16, -54, -94, 76, 24, 94, 10, 34, 78, -30, 0, -52, 80, 98, -58, 92, 12, 26, 64], \"ar2\": [88, 78, -26, 10, 84, 34, 56, -8, -30, 46, 48, 20, 26, -78, 96, 44, 92, -44, -86, 24, -58, -96, -86, -12, -98, 18], \"n\": 17}}, {\"idx\": 8, \"outputs\": 0.0, \"inputs\": {\"ar1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"ar2\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 17}}, {\"idx\": 9, \"outputs\": 67.5, \"inputs\": {\"ar1\": [61, 69, 66, 3], \"ar2\": [39, 84, 97, 15], \"n\": 3}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
333 | Middle Of Three Using Minimum Comparisons | C++ | int middleOfThreeUsingMinimumComparisons(int a, int b, int c) { | [
"a",
"b",
"c"
] | def middle_of_three_using_minimum_comparisons(a, b, c):
if (((a < b) and (b < c)) or ((c < b) and (b < a))):
return b
if (((b < a) and (a < c)) or ((c < a) and (a < b))):
return a
else:
return c | int middle_of_three_using_minimum_comparisons(int a, int b, int c) {
if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b;
else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a;
else 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 a, int b, int c, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(56, 5, 82, 56); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 60, 17, 56); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 56, 51, 51); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 54, 6, 54); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 70, 81, 70); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 57, 47, 57); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 80, 85, 80); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 54, 32, 54); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 70, 55, 70); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 4, 5, 5); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "middleOfThreeUsingMinimumComparisons",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 56, \"inputs\": {\"a\": 56, \"b\": 5, \"c\": 82}}, {\"idx\": 1, \"outputs\": 56, \"inputs\": {\"a\": 56, \"b\": 60, \"c\": 17}}, {\"idx\": 2, \"outputs\": 51, \"inputs\": {\"a\": 36, \"b\": 56, \"c\": 51}}, {\"idx\": 3, \"outputs\": 54, \"inputs\": {\"a\": 71, \"b\": 54, \"c\": 6}}, {\"idx\": 4, \"outputs\": 70, \"inputs\": {\"a\": 3, \"b\": 70, \"c\": 81}}, {\"idx\": 5, \"outputs\": 57, \"inputs\": {\"a\": 84, \"b\": 57, \"c\": 47}}, {\"idx\": 6, \"outputs\": 80, \"inputs\": {\"a\": 30, \"b\": 80, \"c\": 85}}, {\"idx\": 7, \"outputs\": 54, \"inputs\": {\"a\": 82, \"b\": 54, \"c\": 32}}, {\"idx\": 8, \"outputs\": 70, \"inputs\": {\"a\": 90, \"b\": 70, \"c\": 55}}, {\"idx\": 9, \"outputs\": 5, \"inputs\": {\"a\": 38, \"b\": 4, \"c\": 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
]
} |
334 | Middle Of Three Using Minimum Comparisons 1 | C++ | int middleOfThreeUsingMinimumComparisons1(int a, int b, int c) { | [
"a",
"b",
"c"
] | def middle_of_three_using_minimum_comparisons_1(a, b, c):
if (a > b):
if (b > c):
return b
elif (a > c):
return c
else:
return a
elif (a > c):
return a
elif (b > c):
return c
else:
return b | int middle_of_three_using_minimum_comparisons_1(int a, int b, int c) {
if ( a > b ) {
if ( b > c ) return b;
else if ( a > c ) return c;
else return a;
}
else {
if ( a > c ) return a;
else if ( b > c ) return c;
else return 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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int c, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(43, 24, 7, 24); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 54, 66, 66); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 5, 40, 40); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 13, 4, 10); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 47, 56, 56); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 14, 50, 50); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 62, 65, 62); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 95, 12, 16); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 41, 90, 41); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 63, 46, 63); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "middleOfThreeUsingMinimumComparisons1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 24, \"inputs\": {\"a\": 43, \"b\": 24, \"c\": 7}}, {\"idx\": 1, \"outputs\": 66, \"inputs\": {\"a\": 76, \"b\": 54, \"c\": 66}}, {\"idx\": 2, \"outputs\": 40, \"inputs\": {\"a\": 57, \"b\": 5, \"c\": 40}}, {\"idx\": 3, \"outputs\": 10, \"inputs\": {\"a\": 10, \"b\": 13, \"c\": 4}}, {\"idx\": 4, \"outputs\": 56, \"inputs\": {\"a\": 59, \"b\": 47, \"c\": 56}}, {\"idx\": 5, \"outputs\": 50, \"inputs\": {\"a\": 92, \"b\": 14, \"c\": 50}}, {\"idx\": 6, \"outputs\": 62, \"inputs\": {\"a\": 49, \"b\": 62, \"c\": 65}}, {\"idx\": 7, \"outputs\": 16, \"inputs\": {\"a\": 16, \"b\": 95, \"c\": 12}}, {\"idx\": 8, \"outputs\": 41, \"inputs\": {\"a\": 33, \"b\": 41, \"c\": 90}}, {\"idx\": 9, \"outputs\": 63, \"inputs\": {\"a\": 66, \"b\": 63, \"c\": 46}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
335 | Middle Of Three Using Minimum Comparisons 2 | C++ | int middleOfThreeUsingMinimumComparisons2(int a, int b, int c) { | [
"a",
"b",
"c"
] | def middle_of_three_using_minimum_comparisons_2(a, b, c):
x = (a - b)
y = (b - c)
z = (a - c)
if ((x * y) > 0):
return b
elif ((x * z) > 0):
return
else:
return a | int middle_of_three_using_minimum_comparisons_2(int a, int b, int c) {
int x = a - b;
int y = b - c;
int z = a - c;
if ( x * y > 0 ) return b;
else if ( x * z > 0 ) return c;
else return 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 c, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(48, 46, 38, 46); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 34, 11, 34); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 78, 6, 58); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 3, 23, 13); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "middleOfThreeUsingMinimumComparisons2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 46, \"inputs\": {\"a\": 48, \"b\": 46, \"c\": 38}}, {\"idx\": 1, \"outputs\": 34, \"inputs\": {\"a\": 93, \"b\": 34, \"c\": 11}}, {\"idx\": 2, \"outputs\": 58, \"inputs\": {\"a\": 58, \"b\": 78, \"c\": 6}}, {\"idx\": 3, \"outputs\": 13, \"inputs\": {\"a\": 13, \"b\": 3, \"c\": 23}}]",
"test_case_ids": [
"0",
"1",
"2",
"3"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
336 | Minimize Sum Product Two Arrays Permutations Allowed | C++ | int minimizeSumProductTwoArraysPermutationsAllowed(vector<int> a, vector<int> b, int n) { | [
"a",
"b",
"n"
] | def minimize_sum_product_two_arrays_permutations_allowed(A, B, n):
sorted(A)
sorted(B)
result = 0
for i in range(n):
result += (A[i] * B[((n - i) - 1)])
return result | int minimize_sum_product_two_arrays_permutations_allowed(vector<int> A, vector<int> B, int n) {
sort(A.begin(), A.end());
sort(B.begin(), B.end());
int result = 0;
for ( int i = 0;
i < n;
i ++ ) result += ( A [ i ] * B [ n - i - 1 ] );
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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({31, 85}, {18, 33}, 1, 558); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, -6, 84, 70, 84, 6, 28, -74, -14, 68, 22, 90, -10}, {2, -48, -36, -4, -22, -98, -74, -92, -72, -4, 48, -32, 94}, 6, -8900); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 14, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, 33, 93, 2, 83, 9, 61, 84, 9, 69, 2}, {85, 92, 92, 1, 54, 31, 69, 4, 39, 81, 52}, 7, 20524); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -88, -84, -78, -78, -76, -66, -54, -52, -48, -46, -44, -40, -34, -32, -24, -20, -14, -6, -4, 2, 6, 10, 10, 22, 26, 32, 36, 36, 40, 46, 48, 56, 58, 64, 76, 80, 80, 80, 84, 84, 84, 92}, {-98, -90, -82, -80, -76, -66, -62, -62, -62, -50, -50, -50, -32, -30, -14, -12, 4, 6, 12, 14, 16, 30, 30, 30, 32, 34, 40, 42, 50, 52, 56, 58, 60, 62, 62, 64, 66, 68, 78, 82, 86, 90, 94}, 26, -14428); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1}, 32, 8); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 6, 6, 20, 22, 23, 26, 39, 40, 47, 50, 68, 68, 70, 73, 77, 80, 82, 85}, {2, 3, 15, 21, 22, 26, 35, 37, 37, 38, 57, 59, 62, 63, 64, 76, 81, 85, 91}, 17, 19298); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, 60, -8, 46, -12}, {-72, -80, -30, 16, -38}, 2, -10560); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({60, 66, 84, 99, 85, 89, 28, 97, 85, 71, 53, 93, 23, 9, 45, 26, 49, 95, 64, 33, 70, 34, 10, 1, 68, 39, 53, 12}, {37, 33, 33, 77, 78, 34, 28, 1, 63, 15, 51, 50, 90, 22, 71, 23, 68, 55, 2, 22, 31, 54, 76, 36, 2, 27, 96, 89}, 15, 44563); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimizeSumProductTwoArraysPermutationsAllowed",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 558, \"inputs\": {\"a\": [31, 85], \"b\": [18, 33], \"n\": 1}}, {\"idx\": 1, \"outputs\": -8900, \"inputs\": {\"a\": [22, -6, 84, 70, 84, 6, 28, -74, -14, 68, 22, 90, -10], \"b\": [2, -48, -36, -4, -22, -98, -74, -92, -72, -4, 48, -32, 94], \"n\": 6}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"b\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 14}}, {\"idx\": 3, \"outputs\": 20524, \"inputs\": {\"a\": [12, 33, 93, 2, 83, 9, 61, 84, 9, 69, 2], \"b\": [85, 92, 92, 1, 54, 31, 69, 4, 39, 81, 52], \"n\": 7}}, {\"idx\": 4, \"outputs\": -14428, \"inputs\": {\"a\": [-92, -88, -84, -78, -78, -76, -66, -54, -52, -48, -46, -44, -40, -34, -32, -24, -20, -14, -6, -4, 2, 6, 10, 10, 22, 26, 32, 36, 36, 40, 46, 48, 56, 58, 64, 76, 80, 80, 80, 84, 84, 84, 92], \"b\": [-98, -90, -82, -80, -76, -66, -62, -62, -62, -50, -50, -50, -32, -30, -14, -12, 4, 6, 12, 14, 16, 30, 30, 30, 32, 34, 40, 42, 50, 52, 56, 58, 60, 62, 62, 64, 66, 68, 78, 82, 86, 90, 94], \"n\": 26}}, {\"idx\": 5, \"outputs\": 8, \"inputs\": {\"a\": [1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0], \"b\": [0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1], \"n\": 32}}, {\"idx\": 6, \"outputs\": 19298, \"inputs\": {\"a\": [4, 6, 6, 20, 22, 23, 26, 39, 40, 47, 50, 68, 68, 70, 73, 77, 80, 82, 85], \"b\": [2, 3, 15, 21, 22, 26, 35, 37, 37, 38, 57, 59, 62, 63, 64, 76, 81, 85, 91], \"n\": 17}}, {\"idx\": 7, \"outputs\": -10560, \"inputs\": {\"a\": [78, 60, -8, 46, -12], \"b\": [-72, -80, -30, 16, -38], \"n\": 2}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"a\": [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], \"b\": [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\": 17}}, {\"idx\": 9, \"outputs\": 44563, \"inputs\": {\"a\": [60, 66, 84, 99, 85, 89, 28, 97, 85, 71, 53, 93, 23, 9, 45, 26, 49, 95, 64, 33, 70, 34, 10, 1, 68, 39, 53, 12], \"b\": [37, 33, 33, 77, 78, 34, 28, 1, 63, 15, 51, 50, 90, 22, 71, 23, 68, 55, 2, 22, 31, 54, 76, 36, 2, 27, 96, 89], \"n\": 15}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
337 | Minimize The Maximum Difference Between The Heights | C++ | int minimizeTheMaximumDifferenceBetweenTheHeights(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def minimize_the_maximum_difference_between_the_heights(arr, n, k):
if (n == 1):
return 0
arr.sort()
ans = (arr[(n - 1)] - arr[0])
small = (arr[0] + k)
big = (arr[(n - 1)] - k)
if (small > big):
(small, big) = (big, small)
for i in range(1, (n - 1)):
subtract = (arr[i] - k)
add = (arr[i] + k)
if ((subtract >= small) or (add <= big)):
continue
if ((big - subtract) <= (add - small)):
small = subtract
else:
big = add
return min(ans, (big - small)) | int minimize_the_maximum_difference_between_the_heights(vector<int> arr, int n, int k) {
if ( n == 1 ) return 0;
sort(arr.begin(), arr.end());
int ans = arr [ n - 1 ] - arr [ 0 ];
int small = arr [ 0 ] + k;
int big = arr [ n - 1 ] - k;
if ( small > big ) swap ( small, big );
for ( int i = 1;
i < n - 1;
i ++ ) {
int subtract = arr [ i ] - k;
int add = arr [ i ] + k;
if ( subtract >= small || add <= big ) continue;
if ( big - subtract <= add - small ) small = subtract;
else big = add;
}
return min ( ans, big - small );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({31, 33, 40, 43, 44, 51, 52, 56, 60, 64, 66, 79, 91, 93, 99}, 10, 13, 19); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -62, -16, 34, 54}, 3, 4, 62); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, 22, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 5, 5, 7, 9, 11, 16, 17, 21, 27, 36, 38, 41, 44, 45, 45, 48, 51, 55, 57, 58, 59, 59, 60, 67, 67, 67, 68, 70, 74, 77, 84, 86, 88, 90, 90, 91, 91, 92, 99}, 28, 28, 52); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -84, -78, -72, -66, -66, -58, -56, -56, -56, -54, -50, -50, -38, -24, -18, -12, -10, -8, -4, 0, 6, 8, 10, 14, 40, 44, 50, 58, 64, 64, 68}, 22, 28, 44); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, 10, 8, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 11, 13, 14, 22, 25, 26, 28, 30, 31, 37, 37, 55, 57, 61, 62, 64, 67, 69, 70, 71, 73, 73, 75, 80, 81, 82, 88, 90, 98}, 29, 26, 35); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -86, -80, -78, -70, -64, -62, -38, -36, -32, -22, -18, -10, 4, 6, 20, 20, 24, 44, 52, 66, 82, 88, 92, 98}, 23, 18, 142); \n cout << \"TEST-\" << 7 << \"...\"\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, 1, 1, 1, 1}, 20, 19, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2}, 0, 0, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimizeTheMaximumDifferenceBetweenTheHeights",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 19, \"inputs\": {\"arr\": [31, 33, 40, 43, 44, 51, 52, 56, 60, 64, 66, 79, 91, 93, 99], \"n\": 10, \"k\": 13}}, {\"idx\": 1, \"outputs\": 62, \"inputs\": {\"arr\": [-86, -62, -16, 34, 54], \"n\": 3, \"k\": 4}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29, \"k\": 22}}, {\"idx\": 3, \"outputs\": 52, \"inputs\": {\"arr\": [3, 5, 5, 7, 9, 11, 16, 17, 21, 27, 36, 38, 41, 44, 45, 45, 48, 51, 55, 57, 58, 59, 59, 60, 67, 67, 67, 68, 70, 74, 77, 84, 86, 88, 90, 90, 91, 91, 92, 99], \"n\": 28, \"k\": 28}}, {\"idx\": 4, \"outputs\": 44, \"inputs\": {\"arr\": [-88, -84, -78, -72, -66, -66, -58, -56, -56, -56, -54, -50, -50, -38, -24, -18, -12, -10, -8, -4, 0, 6, 8, 10, 14, 40, 44, 50, 58, 64, 64, 68], \"n\": 22, \"k\": 28}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"n\": 10, \"k\": 8}}, {\"idx\": 6, \"outputs\": 35, \"inputs\": {\"arr\": [6, 11, 13, 14, 22, 25, 26, 28, 30, 31, 37, 37, 55, 57, 61, 62, 64, 67, 69, 70, 71, 73, 73, 75, 80, 81, 82, 88, 90, 98], \"n\": 29, \"k\": 26}}, {\"idx\": 7, \"outputs\": 142, \"inputs\": {\"arr\": [-90, -86, -80, -78, -70, -64, -62, -38, -36, -32, -22, -18, -10, 4, 6, 20, 20, 24, 44, 52, 66, 82, 88, 92, 98], \"n\": 23, \"k\": 18}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 20, \"k\": 19}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [2], \"n\": 0, \"k\": 0}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
338 | Minimize The Sum Of Digits Of A And B Such That A B N | C++ | int minimizeTheSumOfDigitsOfAAndBSuchThatABN(int n) { | [
"n"
] | def minimize_the_sum_of_digits_of_a_and_b_such_that_a_b_n(n):
sum = 0
while (n > 0):
sum += (n % 10)
n //= 10
if (sum == 1):
return 10
return sum | int minimize_the_sum_of_digits_of_a_and_b_such_that_a_b_n(int n) {
int sum = 0;
while ( n > 0 ) {
sum += ( n % 10 );
n /= 10;
}
if ( sum == 1 ) return 10;
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(2, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 12); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 13); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 13); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 5); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimizeTheSumOfDigitsOfAAndBSuchThatABN",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"n\": 2}}, {\"idx\": 1, \"outputs\": 12, \"inputs\": {\"n\": 39}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"n\": 31}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"n\": 45}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"n\": 35}}, {\"idx\": 5, \"outputs\": 13, \"inputs\": {\"n\": 94}}, {\"idx\": 6, \"outputs\": 13, \"inputs\": {\"n\": 67}}, {\"idx\": 7, \"outputs\": 5, \"inputs\": {\"n\": 50}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"n\": 4}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"n\": 63}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
339 | Minimum Characters Added Front Make String Palindrome | C++ | bool minimumCharactersAddedFrontMakeStringPalindrome(string s) { | [
"s"
] | def minimum_characters_added_front_make_string_palindrome(s):
l = len(s)
i = 0
j = (l - 1)
while (i <= j):
if (s[i] != s[j]):
return False
i += 1
j -= 1
return True | bool minimum_characters_added_front_make_string_palindrome(string s) {
int l = s . length ( );
int j;
for ( int i = 0, j = l - 1;
i <= j;
i ++, j -- ) {
if ( s [ i ] != s [ j ] ) 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(\"aadaa\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2674377254\", false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0011000 \", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"26382426486138\", false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111010111010\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abccba\", true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"5191\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1110101101\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abcdecbe\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumCharactersAddedFrontMakeStringPalindrome",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"s\": \"aadaa\"}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"s\": \"2674377254\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"s\": \"11\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"s\": \"0011000 \"}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"s\": \"26382426486138\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"s\": \"111010111010\"}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"s\": \"abccba\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"s\": \"5191\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"s\": \"1110101101\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"s\": \"abcdecbe\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
340 | Minimum Cost Connect Weighted Nodes Represented Array | C++ | int minimumCostConnectWeightedNodesRepresentedArray(vector<int> a, int n) { | [
"a",
"n"
] | def minimum_cost_connect_weighted_nodes_represented_array(a, n):
mn = sys.maxsize
sum = 0
for i in range(n):
mn = min(a[i], mn)
sum += a[i]
return (mn * (sum - mn)) | int minimum_cost_connect_weighted_nodes_represented_array(vector<int> a, int n) {
int mn = INT_MAX;
int sum = 0;
for ( int i = 0;
i < n;
i ++ ) {
mn = min ( a [ i ], mn );
sum += a [ i ];
}
return mn * ( sum - mn );
} | {
"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({3, 8, 14, 15, 17, 17, 19, 21, 22, 23, 29, 32, 36, 37, 43, 45, 46, 47, 47, 53, 57, 57, 70, 71, 72, 76, 81, 82, 90, 95, 96, 98, 99}, 32, 4548); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, -18, 50, 94, -74, -50, -44, -92, -58, 14, -66, -78}, 10, -736); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 24, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({15, 18, 64, 28}, 2, 270); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -88, -88, -84, -82, -78, -78, -60, -58, -56, -54, -52, -48, -44, -28, -26, -14, -12, 6, 10, 10, 14, 14, 50, 52, 54, 60, 62, 62, 64, 66, 70, 72, 72, 78, 80, 84}, 31, 40896); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 1, 1, 1, 1}, 6, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 10, 14, 14, 15, 16, 18, 20, 21, 30, 31, 33, 35, 39, 46, 48, 59, 59, 61, 77, 78, 79, 81, 83, 85, 92, 97, 97, 99}, 23, 2652); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, -32, 68, -48, 54, 24, 78, 98, -70, 44, -82, -92, -16, -92, -70, 52, -58, -62, -58, 32, 14, -4, 80, -78, -26, -24, -8}, 18, 9936); \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, 1}, 35, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({82, 74, 53, 91, 81, 88, 42, 62, 38, 43, 29, 60, 43, 44, 19, 28, 20, 1, 5, 94, 18, 77, 52, 38, 55, 1, 10, 29, 34, 91, 64, 80, 81, 39, 4, 47, 30, 62, 58, 66, 73, 52, 62, 9, 36, 49}, 38, 1808); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumCostConnectWeightedNodesRepresentedArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 4548, \"inputs\": {\"a\": [3, 8, 14, 15, 17, 17, 19, 21, 22, 23, 29, 32, 36, 37, 43, 45, 46, 47, 47, 53, 57, 57, 70, 71, 72, 76, 81, 82, 90, 95, 96, 98, 99], \"n\": 32}}, {\"idx\": 1, \"outputs\": -736, \"inputs\": {\"a\": [94, -18, 50, 94, -74, -50, -44, -92, -58, 14, -66, -78], \"n\": 10}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": [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\": 24}}, {\"idx\": 3, \"outputs\": 270, \"inputs\": {\"a\": [15, 18, 64, 28], \"n\": 2}}, {\"idx\": 4, \"outputs\": 40896, \"inputs\": {\"a\": [-96, -88, -88, -84, -82, -78, -78, -60, -58, -56, -54, -52, -48, -44, -28, -26, -14, -12, 6, 10, 10, 14, 14, 50, 52, 54, 60, 62, 62, 64, 66, 70, 72, 72, 78, 80, 84], \"n\": 31}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [0, 1, 1, 0, 1, 1, 1, 1], \"n\": 6}}, {\"idx\": 6, \"outputs\": 2652, \"inputs\": {\"a\": [3, 10, 14, 14, 15, 16, 18, 20, 21, 30, 31, 33, 35, 39, 46, 48, 59, 59, 61, 77, 78, 79, 81, 83, 85, 92, 97, 97, 99], \"n\": 23}}, {\"idx\": 7, \"outputs\": 9936, \"inputs\": {\"a\": [4, -32, 68, -48, 54, 24, 78, 98, -70, 44, -82, -92, -16, -92, -70, 52, -58, -62, -58, 32, 14, -4, 80, -78, -26, -24, -8], \"n\": 18}}, {\"idx\": 8, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 35}}, {\"idx\": 9, \"outputs\": 1808, \"inputs\": {\"a\": [82, 74, 53, 91, 81, 88, 42, 62, 38, 43, 29, 60, 43, 44, 19, 28, 20, 1, 5, 94, 18, 77, 52, 38, 55, 1, 10, 29, 34, 91, 64, 80, 81, 39, 4, 47, 30, 62, 58, 66, 73, 52, 62, 9, 36, 49], \"n\": 38}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
341 | Minimum Cost Cut Board Squares | C++ | int minimumCostCutBoardSquares(vector<int> x, vector<int> y, int m, int n) { | [
"x",
"y",
"m",
"n"
] | def minimum_cost_cut_board_squares(X, Y, m, n):
res = 0
X.sort(reverse=True)
Y.sort(reverse=True)
hzntl = 1
vert = 1
i = 0
j = 0
while ((i < m) and (j < n)):
if (X[i] > Y[j]):
res += (X[i] * vert)
hzntl += 1
i += 1
else:
res += (Y[j] * hzntl)
vert += 1
j += 1
total = 0
while (i < m):
total += X[i]
i += 1
res += (total * vert)
total = 0
while (j < n):
total += Y[j]
j += 1
res += (total * hzntl)
return res | int minimum_cost_cut_board_squares(vector<int> X, vector<int> Y, int m, int n) {
int res = 0;
sort(X.begin(), X.end(), greater < int > ( ) );
sort(Y.begin(), Y.end(), greater < int > ( ) );
int hzntl = 1, vert = 1;
int i = 0, j = 0;
while ( i < m && j < n ) {
if ( X [ i ] > Y [ j ] ) {
res += X [ i ] * vert;
hzntl ++;
i ++;
}
else {
res += Y [ j ] * hzntl;
vert ++;
j ++;
}
}
int total = 0;
while ( i < m ) total += X [ i ++ ];
res += total * vert;
total = 0;
while ( j < n ) total += Y [ j ++ ];
res += total * hzntl;
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> x, vector<int> y, int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y, 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({98, 97, 93, 90, 90, 87, 87, 87, 83, 77, 75, 73, 70, 70, 69, 67, 67, 61, 60, 59, 58, 58, 56, 53, 52, 46, 46, 44, 40, 37, 34, 33, 33, 33, 32, 28, 26, 25, 25, 23, 22, 22, 20, 18, 16, 9, 9, 1}, {99, 97, 96, 95, 92, 91, 88, 87, 86, 77, 74, 73, 73, 72, 71, 70, 70, 67, 63, 62, 60, 59, 56, 55, 55, 55, 50, 47, 45, 39, 39, 37, 35, 30, 30, 29, 27, 25, 23, 20, 19, 17, 16, 13, 10, 9, 3, 2}, 25, 27, 47899); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, 66, 66, 52, -4, -52, -72, -74}, {88, 84, 72, 30, -34, -40, -76, -78}, 6, 7, 76); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 15, 19, 119); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({97, 96, 89, 87, 83, 78, 77, 76, 67, 66, 63, 58, 54, 52, 48, 44, 38, 37, 28, 28, 19, 2}, {94, 92, 91, 83, 79, 75, 75, 72, 63, 63, 47, 40, 37, 36, 36, 33, 33, 29, 26, 19, 9, 5}, 13, 14, 13164); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 90, 86, 78, 70, 32, 26, 26, 20, 16, 14, -2, -2, -4, -8, -10, -34, -44, -58, -60, -62, -62, -68, -72, -76, -78, -84}, {98, 92, 78, 66, 64, 50, 48, 42, 36, 26, 16, 16, 0, -4, -10, -18, -24, -32, -32, -48, -60, -62, -76, -82, -86, -98, -98}, 15, 24, -1650); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 25, 26, 341); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({75, 30}, {39, 10}, 1, 1, 153); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 78, 74, 70, 70, 62, 60, 58, 50, 46, 44, 40, 38, 38, 36, 32, 24, 22, 16, 14, 10, 0, -8, -10, -10, -18, -20, -36, -52, -54, -56, -56, -60, -60, -68, -82, -96}, {94, 92, 92, 90, 86, 80, 78, 70, 64, 62, 46, 46, 40, 40, 32, 6, 4, -6, -14, -18, -20, -22, -24, -28, -34, -42, -50, -56, -62, -66, -76, -86, -86, -90, -92, -94, -96}, 19, 19, 14508); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0}, {1, 1, 1, 0}, 2, 2, 5); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({90, 81, 81, 74, 67, 40, 29, 25, 24, 13, 10}, {75, 74, 58, 53, 51, 49, 45, 25, 23, 14, 7}, 8, 10, 4117); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumCostCutBoardSquares",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 47899, \"inputs\": {\"x\": [98, 97, 93, 90, 90, 87, 87, 87, 83, 77, 75, 73, 70, 70, 69, 67, 67, 61, 60, 59, 58, 58, 56, 53, 52, 46, 46, 44, 40, 37, 34, 33, 33, 33, 32, 28, 26, 25, 25, 23, 22, 22, 20, 18, 16, 9, 9, 1], \"y\": [99, 97, 96, 95, 92, 91, 88, 87, 86, 77, 74, 73, 73, 72, 71, 70, 70, 67, 63, 62, 60, 59, 56, 55, 55, 55, 50, 47, 45, 39, 39, 37, 35, 30, 30, 29, 27, 25, 23, 20, 19, 17, 16, 13, 10, 9, 3, 2], \"m\": 25, \"n\": 27}}, {\"idx\": 1, \"outputs\": 76, \"inputs\": {\"x\": [78, 66, 66, 52, -4, -52, -72, -74], \"y\": [88, 84, 72, 30, -34, -40, -76, -78], \"m\": 6, \"n\": 7}}, {\"idx\": 2, \"outputs\": 119, \"inputs\": {\"x\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \"y\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \"m\": 15, \"n\": 19}}, {\"idx\": 3, \"outputs\": 13164, \"inputs\": {\"x\": [97, 96, 89, 87, 83, 78, 77, 76, 67, 66, 63, 58, 54, 52, 48, 44, 38, 37, 28, 28, 19, 2], \"y\": [94, 92, 91, 83, 79, 75, 75, 72, 63, 63, 47, 40, 37, 36, 36, 33, 33, 29, 26, 19, 9, 5], \"m\": 13, \"n\": 14}}, {\"idx\": 4, \"outputs\": -1650, \"inputs\": {\"x\": [96, 90, 86, 78, 70, 32, 26, 26, 20, 16, 14, -2, -2, -4, -8, -10, -34, -44, -58, -60, -62, -62, -68, -72, -76, -78, -84], \"y\": [98, 92, 78, 66, 64, 50, 48, 42, 36, 26, 16, 16, 0, -4, -10, -18, -24, -32, -32, -48, -60, -62, -76, -82, -86, -98, -98], \"m\": 15, \"n\": 24}}, {\"idx\": 5, \"outputs\": 341, \"inputs\": {\"x\": [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], \"y\": [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], \"m\": 25, \"n\": 26}}, {\"idx\": 6, \"outputs\": 153, \"inputs\": {\"x\": [75, 30], \"y\": [39, 10], \"m\": 1, \"n\": 1}}, {\"idx\": 7, \"outputs\": 14508, \"inputs\": {\"x\": [96, 78, 74, 70, 70, 62, 60, 58, 50, 46, 44, 40, 38, 38, 36, 32, 24, 22, 16, 14, 10, 0, -8, -10, -10, -18, -20, -36, -52, -54, -56, -56, -60, -60, -68, -82, -96], \"y\": [94, 92, 92, 90, 86, 80, 78, 70, 64, 62, 46, 46, 40, 40, 32, 6, 4, -6, -14, -18, -20, -22, -24, -28, -34, -42, -50, -56, -62, -66, -76, -86, -86, -90, -92, -94, -96], \"m\": 19, \"n\": 19}}, {\"idx\": 8, \"outputs\": 5, \"inputs\": {\"x\": [1, 0, 0, 0], \"y\": [1, 1, 1, 0], \"m\": 2, \"n\": 2}}, {\"idx\": 9, \"outputs\": 4117, \"inputs\": {\"x\": [90, 81, 81, 74, 67, 40, 29, 25, 24, 13, 10], \"y\": [75, 74, 58, 53, 51, 49, 45, 25, 23, 14, 7], \"m\": 8, \"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
]
} |
342 | Minimum Cost For Acquiring All Coins With K Extra Coins Allowed With Every Coin | C++ | int minimumCostForAcquiringAllCoinsWithKExtraCoinsAllowedWithEveryCoin(vector<int> coin, int n, int k) { | [
"coin",
"n",
"k"
] | def minimum_cost_for_acquiring_all_coins_with_k_extra_coins_allowed_with_every_coin(coin, n, k):
coin.sort()
coins_needed = math.ceil(((1.0 * n) // (k + 1)))
ans = 0
for i in range(((coins_needed - 1) + 1)):
ans += coin[i]
return ans | int minimum_cost_for_acquiring_all_coins_with_k_extra_coins_allowed_with_every_coin(vector<int> coin, int n, int k) {
sort(coin.begin(), coin.end());
int coins_needed = ceil ( 1.0 * n / ( k + 1 ) );
int ans = 0;
for ( int i = 0;
i <= coins_needed - 1;
i ++ ) ans += coin [ 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> coin, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(coin, 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, 4, 5, 9, 10, 10, 11, 14, 15, 19, 21, 22, 29, 36, 36, 38, 39, 39, 39, 41, 41, 42, 45, 45, 48, 55, 56, 57, 64, 66, 66, 66, 66, 69, 74, 76, 80, 81, 82, 82, 85, 87, 95, 95}, 33, 27, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -88, -52, -10, -6, 16, 20, 36, 48, 66, 68, 94}, 6, 10, 0); \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, 1}, 16, 16, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 4, 5, 6, 10, 11, 15, 24, 29, 32, 35, 43, 48, 49, 62, 71, 78, 91}, 13, 17, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -88, -84, -82, -78, -74, -74, -68, -62, -62, -56, -56, -50, -46, -44, -26, -18, -14, -8, -8, -6, 8, 16, 20, 20, 22, 26, 36, 42, 44, 44, 52, 60, 66, 68, 68, 70, 76, 84}, 25, 34, 0); \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}, 32, 32, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 12, 38, 39, 52, 54, 62, 81, 87, 93}, 6, 8, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, -76, -74, -70, -40, -32, -32, -26, -24, -18, -18, -12, -10, -8, 0, 4, 8, 16, 40, 40, 44, 60, 70, 86, 92, 94}, 25, 20, -84); \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, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 29, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({23, 31, 44, 56, 58, 61, 62, 63, 72, 74, 86, 97, 97, 98}, 12, 13, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumCostForAcquiringAllCoinsWithKExtraCoinsAllowedWithEveryCoin",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"coin\": [2, 4, 5, 9, 10, 10, 11, 14, 15, 19, 21, 22, 29, 36, 36, 38, 39, 39, 39, 41, 41, 42, 45, 45, 48, 55, 56, 57, 64, 66, 66, 66, 66, 69, 74, 76, 80, 81, 82, 82, 85, 87, 95, 95], \"n\": 33, \"k\": 27}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"coin\": [-98, -88, -52, -10, -6, 16, 20, 36, 48, 66, 68, 94], \"n\": 6, \"k\": 10}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"coin\": [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\": 16, \"k\": 16}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"coin\": [1, 4, 5, 6, 10, 11, 15, 24, 29, 32, 35, 43, 48, 49, 62, 71, 78, 91], \"n\": 13, \"k\": 17}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"coin\": [-98, -92, -88, -84, -82, -78, -74, -74, -68, -62, -62, -56, -56, -50, -46, -44, -26, -18, -14, -8, -8, -6, 8, 16, 20, 20, 22, 26, 36, 42, 44, 44, 52, 60, 66, 68, 68, 70, 76, 84], \"n\": 25, \"k\": 34}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"coin\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 32, \"k\": 32}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"coin\": [5, 12, 38, 39, 52, 54, 62, 81, 87, 93], \"n\": 6, \"k\": 8}}, {\"idx\": 7, \"outputs\": -84, \"inputs\": {\"coin\": [-84, -76, -74, -70, -40, -32, -32, -26, -24, -18, -18, -12, -10, -8, 0, 4, 8, 16, 40, 40, 44, 60, 70, 86, 92, 94], \"n\": 25, \"k\": 20}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"coin\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 37, \"k\": 29}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"coin\": [23, 31, 44, 56, 58, 61, 62, 63, 72, 74, 86, 97, 97, 98], \"n\": 12, \"k\": 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
]
} |
343 | Minimum Cost Make Array Size 1 Removing Larger Pairs | C++ | int minimumCostMakeArraySize1RemovingLargerPairs(vector<int> a, int n) { | [
"a",
"n"
] | def minimum_cost_make_array_size_1_removing_larger_pairs(a, n):
return ((n - 1) * min(a)) | int minimum_cost_make_array_size_1_removing_larger_pairs(vector<int> a, int n) {
return ( n - 1 ) * ( * min_element(a.begin(), a.end()) );
} | {
"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({1, 2, 3, 4, 7, 8, 10, 10, 16, 20, 22, 22, 23, 23, 23, 27, 29, 32, 35, 39, 41, 46, 51, 53, 54, 59, 59, 60, 61, 69, 70, 70, 79, 79, 81, 84, 90, 91, 98}, 25, 24); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-6, 10}, 1, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, 61, 92, 45, 75, 26, 83, 5, 85, 27, 39, 88, 36, 39, 83, 41, 56, 77, 39, 69, 72, 98, 39, 15, 29, 69, 64, 92, 96, 49, 59, 62, 53, 82, 40, 37, 29, 41}, 23, 110); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -60, -60, -58, -56, -56, -46, -44, -40, -38, -32, -28, -22, -18, -12, -4, -2, 10, 24, 24, 28, 38, 42, 46, 54, 64, 72, 74, 78, 96, 96}, 26, -2200); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1}, 39, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 4, 6, 9, 10, 12, 17, 17, 18, 21, 22, 26, 26, 31, 32, 33, 34, 39, 42, 43, 45, 46, 48, 50, 53, 53, 54, 55, 60, 61, 62, 63, 63, 64, 70, 70, 70, 71, 71, 78, 86, 88, 91, 92, 95, 95, 96, 97, 99}, 28, 27); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-42, 44, -80, -60, 48, 66, 54, -76, 26, -74, -10, 46, -50, 42, -26, -24, -14, 36, -2, -26, 16, -10, 20, -88, -78}, 19, -1584); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 5, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({65, 32, 66, 82, 86, 98, 15, 33, 57, 3, 73, 45, 90, 82, 33, 99, 44, 76, 50, 89, 5, 7, 64}, 22, 63); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumCostMakeArraySize1RemovingLargerPairs",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 24, \"inputs\": {\"a\": [1, 2, 3, 4, 7, 8, 10, 10, 16, 20, 22, 22, 23, 23, 23, 27, 29, 32, 35, 39, 41, 46, 51, 53, 54, 59, 59, 60, 61, 69, 70, 70, 79, 79, 81, 84, 90, 91, 98], \"n\": 25}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"a\": [-6, 10], \"n\": 1}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 15}}, {\"idx\": 3, \"outputs\": 110, \"inputs\": {\"a\": [20, 61, 92, 45, 75, 26, 83, 5, 85, 27, 39, 88, 36, 39, 83, 41, 56, 77, 39, 69, 72, 98, 39, 15, 29, 69, 64, 92, 96, 49, 59, 62, 53, 82, 40, 37, 29, 41], \"n\": 23}}, {\"idx\": 4, \"outputs\": -2200, \"inputs\": {\"a\": [-88, -60, -60, -58, -56, -56, -46, -44, -40, -38, -32, -28, -22, -18, -12, -4, -2, 10, 24, 24, 28, 38, 42, 46, 54, 64, 72, 74, 78, 96, 96], \"n\": 26}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1], \"n\": 39}}, {\"idx\": 6, \"outputs\": 27, \"inputs\": {\"a\": [1, 4, 6, 9, 10, 12, 17, 17, 18, 21, 22, 26, 26, 31, 32, 33, 34, 39, 42, 43, 45, 46, 48, 50, 53, 53, 54, 55, 60, 61, 62, 63, 63, 64, 70, 70, 70, 71, 71, 78, 86, 88, 91, 92, 95, 95, 96, 97, 99], \"n\": 28}}, {\"idx\": 7, \"outputs\": -1584, \"inputs\": {\"a\": [-42, 44, -80, -60, 48, 66, 54, -76, 26, -74, -10, 46, -50, 42, -26, -24, -14, 36, -2, -26, 16, -10, 20, -88, -78], \"n\": 19}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 5}}, {\"idx\": 9, \"outputs\": 63, \"inputs\": {\"a\": [65, 32, 66, 82, 86, 98, 15, 33, 57, 3, 73, 45, 90, 82, 33, 99, 44, 76, 50, 89, 5, 7, 64], \"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
]
} |
344 | Minimum Difference Max Min K Size Subsets | C++ | long long minimumDifferenceMaxMinKSizeSubsets(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def minimum_difference_max_min_k_size_subsets(arr, N, K):
arr.sort()
res = 2147483647
for i in range(((N - K) + 1)):
curSeqDiff = (arr[((i + K) - 1)] - arr[i])
res = min(res, curSeqDiff)
return res | int minimum_difference_max_min_k_size_subsets(vector<int> arr, int N, int K) {
sort(arr.begin(), arr.end());
int res = INT_MAX;
for ( int i = 0;
i <= ( N - K );
i ++ ) {
int curSeqDiff = arr [ i + K - 1 ] - arr [ i ];
res = min ( res, curSeqDiff );
}
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(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 1, 4, 18, 21, 35, 37, 39, 76, 81, 86, 92, 96}, 7, 6, 34); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -86, -48, -48, -38, -8, -6, 0, 2, 24, 34, 52, 62}, 9, 12, 2147483647); \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}, 16, 26, 2147483647); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 10, 13, 23, 30, 30, 34, 36, 37, 39, 43, 50, 57, 66, 71, 74, 81, 83, 89, 94, 94, 99}, 17, 20, 2147483647); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -92, -84, -80, -72, -24, -22, -18, -14, 6, 8, 26, 28, 30, 36, 50, 58, 80, 84, 92, 92}, 21, 12, 82); \n cout << \"TEST-\" << 4 << \"...\"\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}, 21, 22, 2147483647); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 7, 9, 27, 30, 42, 54, 55, 57, 57, 59, 76, 84, 84, 84}, 13, 14, 2147483647); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -86, -80, -72, -70, -68, -64, -64, -56, -54, -38, -30, -24, -16, -16, -12, -12, -10, 0, 0, 4, 4, 24, 28, 38, 40, 44, 48, 50, 54, 54, 62, 62, 68, 80, 84, 88, 88, 92, 94}, 31, 26, 122); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, 1, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 6, 7, 8, 10, 10, 18, 54, 55, 56, 59, 59, 61, 63, 67, 69, 75, 78, 88, 89, 93, 97, 98}, 22, 14, 39); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumDifferenceMaxMinKSizeSubsets",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 34, \"inputs\": {\"arr\": [1, 1, 4, 18, 21, 35, 37, 39, 76, 81, 86, 92, 96], \"n\": 7, \"k\": 6}}, {\"idx\": 1, \"outputs\": 2147483647, \"inputs\": {\"arr\": [-94, -86, -48, -48, -38, -8, -6, 0, 2, 24, 34, 52, 62], \"n\": 9, \"k\": 12}}, {\"idx\": 2, \"outputs\": 2147483647, \"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], \"n\": 16, \"k\": 26}}, {\"idx\": 3, \"outputs\": 2147483647, \"inputs\": {\"arr\": [3, 10, 13, 23, 30, 30, 34, 36, 37, 39, 43, 50, 57, 66, 71, 74, 81, 83, 89, 94, 94, 99], \"n\": 17, \"k\": 20}}, {\"idx\": 4, \"outputs\": 82, \"inputs\": {\"arr\": [-96, -94, -92, -84, -80, -72, -24, -22, -18, -14, 6, 8, 26, 28, 30, 36, 50, 58, 80, 84, 92, 92], \"n\": 21, \"k\": 12}}, {\"idx\": 5, \"outputs\": 2147483647, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 21, \"k\": 22}}, {\"idx\": 6, \"outputs\": 2147483647, \"inputs\": {\"arr\": [6, 7, 9, 27, 30, 42, 54, 55, 57, 57, 59, 76, 84, 84, 84], \"n\": 13, \"k\": 14}}, {\"idx\": 7, \"outputs\": 122, \"inputs\": {\"arr\": [-96, -86, -80, -72, -70, -68, -64, -64, -56, -54, -38, -30, -24, -16, -16, -12, -12, -10, 0, 0, 4, 4, 24, 28, 38, 40, 44, 48, 50, 54, 54, 62, 62, 68, 80, 84, 88, 88, 92, 94], \"n\": 31, \"k\": 26}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1], \"n\": 1, \"k\": 1}}, {\"idx\": 9, \"outputs\": 39, \"inputs\": {\"arr\": [1, 6, 7, 8, 10, 10, 18, 54, 55, 56, 59, 59, 61, 63, 67, 69, 75, 78, 88, 89, 93, 97, 98], \"n\": 22, \"k\": 14}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
345 | Minimum Increment K Operations Make Elements Equal | C++ | int minimumIncrementKOperationsMakeElementsEqual(vector<int> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def minimum_increment_k_operations_make_elements_equal(arr, n, k):
max1 = max(arr)
res = 0
for i in range(0, n):
if (((max1 - arr[i]) % k) != 0):
return (- 1)
else:
res += ((max1 - arr[i]) / k)
return int(res) | int minimum_increment_k_operations_make_elements_equal(vector<int> arr, int n, int k) {
int max = * max_element(arr.begin(), arr.end());
int res = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( ( max - arr [ i ] ) % k != 0 ) return - 1;
else res += ( max - arr [ i ] ) / k;
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 7, 19, 16}, 4, 3, 10); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 4, 4, 4, 4}, 5, 3, 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, 1, 1, 1, 1, 1}, 39, 1, 24); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 36, 52, 8, 52, 15, 16}, 5, 6, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-10, -5, -5, -20, 10, 30}, 6, 5, 36); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0}, 10, 15, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 5, 5, 9, 11, 12, 12, 13, 13, 14, 16, 18, 26, 26, 28, 28, 30, 31, 32, 37, 37, 38, 40, 43, 44, 45, 47, 47, 55, 58, 60, 62, 63, 64, 69, 78, 83, 84, 92, 96, 96, 99}, 26, 33, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, -78, 92, -98, 16, 44, 86, 96, -8, 2, -96, 74, -28, 12, 54, -40, -64, -12, 4, 48, 68, -82, 8, 0, -4, 88, 48, -54, 90, 62, -84, 76, -48, 62, -80, -94, 38, -4, 36}, 34, 3, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 39, 10, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({62, 99, 29, 23, 55, 30, 79, 63, 1, 88, 59, 8, 11, 80, 23, 51, 97, 32, 80, 48, 84, 36, 73, 59, 1, 34, 92, 10}, 18, 1, 892); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumIncrementKOperationsMakeElementsEqual",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 10, \"inputs\": {\"arr\": [4, 7, 19, 16], \"n\": 4, \"k\": 3}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [4, 4, 4, 4, 4], \"n\": 5, \"k\": 3}}, {\"idx\": 2, \"outputs\": 24, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 39, \"k\": 1}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [85, 36, 52, 8, 52, 15, 16], \"n\": 5, \"k\": 6}}, {\"idx\": 4, \"outputs\": 36, \"inputs\": {\"arr\": [-10, -5, -5, -20, 10, 30], \"n\": 6, \"k\": 5}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0], \"n\": 10, \"k\": 15}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [1, 5, 5, 9, 11, 12, 12, 13, 13, 14, 16, 18, 26, 26, 28, 28, 30, 31, 32, 37, 37, 38, 40, 43, 44, 45, 47, 47, 55, 58, 60, 62, 63, 64, 69, 78, 83, 84, 92, 96, 96, 99], \"n\": 26, \"k\": 33}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [76, -78, 92, -98, 16, 44, 86, 96, -8, 2, -96, 74, -28, 12, 54, -40, -64, -12, 4, 48, 68, -82, 8, 0, -4, 88, 48, -54, 90, 62, -84, 76, -48, 62, -80, -94, 38, -4, 36], \"n\": 34, \"k\": 3}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 39, \"k\": 10}}, {\"idx\": 9, \"outputs\": 892, \"inputs\": {\"arr\": [62, 99, 29, 23, 55, 30, 79, 63, 1, 88, 59, 8, 11, 80, 23, 51, 97, 32, 80, 48, 84, 36, 73, 59, 1, 34, 92, 10], \"n\": 18, \"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
]
} |
346 | Minimum Insertions Sort Array | C++ | int minimumInsertionsSortArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def minimum_insertions_sort_array(arr, N):
lis = ([0] * N)
for i in range(N):
lis[i] = 1
for i in range(1, N):
for j in range(i):
if ((arr[i] >= arr[j]) and (lis[i] < (lis[j] + 1))):
lis[i] = (lis[j] + 1)
max = 0
for i in range(N):
if (max < lis[i]):
max = lis[i]
return (N - max) | int minimum_insertions_sort_array(vector<int> arr, int N) {
int lis [ N ];
for ( int i = 0;
i < N;
i ++ ) lis [ i ] = 1;
for ( int i = 1;
i < N;
i ++ ) for ( int j = 0;
j < i;
j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1;
int max = 0;
for ( int i = 0;
i < N;
i ++ ) if ( max < lis [ i ] ) max = lis [ i ];
return ( N - max );
} | {
"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, 7, 20, 22, 23, 31, 33, 36, 47, 61, 63, 63, 71, 74, 82, 91, 95, 99}, 15, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, 12, -42, -78, 22, 72, 56, 70, 28, -72}, 7, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 16, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({29, 41, 4, 62, 77, 74, 30, 2, 14, 90, 93, 10, 78, 36, 66, 22, 48, 89, 36, 73, 70, 23, 90}, 13, 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -72, -68, -66, -58, -50, -48, -32, -28, -24, -22, -18, 0, 2, 6, 10, 12, 14, 14, 18, 24, 24, 24, 28, 28, 28, 34, 38, 42, 42, 46, 46, 46, 58, 80, 82, 82, 84, 84, 86, 88, 90, 92, 96}, 36, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 0, 1, 0, 0, 1, 0}, 8, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({26, 36, 58, 64, 69, 72, 79, 82, 82, 87, 89, 90, 95}, 8, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-52, -40, 98, 40, 42, -50, 60, -64, -92, 36, -88, 72, -72, 38, -80, -52, 68, 70, 16, 22, -30, -74, 56, -80, 62, -54, -32, -22, -86, -70, 88, -76, -46, 28, 40, -2, -84, 68, -98, -16, 90, 36, -38, -86, 20, -40, 82, 98, 54}, 41, 30); \n cout << \"TEST-\" << 7 << \"...\"\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}, 10, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({36, 62, 58, 24, 99, 12, 46, 3, 4, 40, 54, 97, 48, 94, 98, 7, 17, 5, 3, 36, 3}, 16, 10); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumInsertionsSortArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [4, 7, 20, 22, 23, 31, 33, 36, 47, 61, 63, 63, 71, 74, 82, 91, 95, 99], \"n\": 15}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"arr\": [-84, 12, -42, -78, 22, 72, 56, 70, 28, -72], \"n\": 7}}, {\"idx\": 2, \"outputs\": 0, \"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], \"n\": 16}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"arr\": [29, 41, 4, 62, 77, 74, 30, 2, 14, 90, 93, 10, 78, 36, 66, 22, 48, 89, 36, 73, 70, 23, 90], \"n\": 13}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-80, -72, -68, -66, -58, -50, -48, -32, -28, -24, -22, -18, 0, 2, 6, 10, 12, 14, 14, 18, 24, 24, 24, 28, 28, 28, 34, 38, 42, 42, 46, 46, 46, 58, 80, 82, 82, 84, 84, 86, 88, 90, 92, 96], \"n\": 36}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"arr\": [1, 1, 0, 1, 0, 1, 0, 0, 1, 0], \"n\": 8}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [26, 36, 58, 64, 69, 72, 79, 82, 82, 87, 89, 90, 95], \"n\": 8}}, {\"idx\": 7, \"outputs\": 30, \"inputs\": {\"arr\": [-52, -40, 98, 40, 42, -50, 60, -64, -92, 36, -88, 72, -72, 38, -80, -52, 68, 70, 16, 22, -30, -74, 56, -80, 62, -54, -32, -22, -86, -70, 88, -76, -46, 28, 40, -2, -84, 68, -98, -16, 90, 36, -38, -86, 20, -40, 82, 98, 54], \"n\": 41}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 10}}, {\"idx\": 9, \"outputs\": 10, \"inputs\": {\"arr\": [36, 62, 58, 24, 99, 12, 46, 3, 4, 40, 54, 97, 48, 94, 98, 7, 17, 5, 3, 36, 3], \"n\": 16}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
347 | Minimum Length Subarray Sum Greater Given Value | C++ | int minimumLengthSubarraySumGreaterGivenValue(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def minimum_length_subarray_sum_greater_given_value(arr, n, x):
curr_sum = 0
min_len = (n + 1)
start = 0
end = 0
while (end < n):
while ((curr_sum <= x) and (end < n)):
curr_sum += arr[end]
end += 1
while ((curr_sum > x) and (start < n)):
if ((end - start) < min_len):
min_len = (end - start)
curr_sum -= arr[start]
start += 1
return min_len | int minimum_length_subarray_sum_greater_given_value(vector<int> arr, int n, int x) {
int curr_sum = 0, min_len = n + 1;
int start = 0, end = 0;
while ( end < n ) {
while ( curr_sum <= x && end < n ) curr_sum += arr [ end ++ ];
while ( curr_sum > x && start < n ) {
if ( end - start < min_len ) min_len = end - start;
curr_sum -= arr [ start ++ ];
}
}
return min_len;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int 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({6, 11, 11, 14, 18, 19, 21, 22, 22, 23, 26, 27, 28, 28, 29, 30, 31, 34, 39, 42, 42, 44, 45, 49, 49, 53, 57, 61, 65, 66, 67, 70, 71, 73, 74, 74, 78, 85, 88, 94, 95, 97}, 37, 23, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-30, -22, -66, -80, 18, -64, -28, -46, 94, 60, -64, 2, 26, -94, 58, 56, 56, 88, 50, -78, -12, 68, 54, -78, 42, -30, 24, -48, 84, 12, -88, 0, 54, -92, -4, 42, -60, -72, -32}, 31, 29, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 8, 12, 9); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 8, 23, 40, 55, 93, 11, 35, 33, 37, 96, 91, 35, 66, 37, 57, 83, 99, 96, 15, 18, 93}, 16, 13, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -68, -48, -48, -42, -26, -22, -18, 2, 4, 8, 14, 20, 22, 32, 46, 52, 62, 70, 96, 98}, 17, 14, 18); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0}, 11, 10, 12); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 4, 11, 11, 13, 15, 16, 18, 19, 19, 19, 23, 26, 27, 34, 39, 39, 40, 41, 46, 47, 51, 52, 52, 53, 57, 58, 58, 60, 64, 68, 70, 72, 84, 84, 85, 95, 98, 99}, 31, 35, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, -22, 2, -90, -92, 84, -26, -76, -72, 50, -36, 30, 78, -18, -94, -30, 22, 28, 10, 32, 34, -86, 0, -4, 40, 0, 80, 50, 66, -48, -40, -94, 64, 58, -14, 0, -32, -58, -22, -94, -68, -36, -94, -48, 40, 78, -74}, 42, 26, 43); \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}, 25, 21, 26); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 33, 20, 32, 76, 27, 8, 95, 78, 72, 25, 56}, 9, 10, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumLengthSubarraySumGreaterGivenValue",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [6, 11, 11, 14, 18, 19, 21, 22, 22, 23, 26, 27, 28, 28, 29, 30, 31, 34, 39, 42, 42, 44, 45, 49, 49, 53, 57, 61, 65, 66, 67, 70, 71, 73, 74, 74, 78, 85, 88, 94, 95, 97], \"n\": 37, \"x\": 23}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [-30, -22, -66, -80, 18, -64, -28, -46, 94, 60, -64, 2, 26, -94, 58, 56, 56, 88, 50, -78, -12, 68, 54, -78, 42, -30, 24, -48, 84, 12, -88, 0, 54, -92, -4, 42, -60, -72, -32], \"n\": 31, \"x\": 29}}, {\"idx\": 2, \"outputs\": 9, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 8, \"x\": 12}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [86, 8, 23, 40, 55, 93, 11, 35, 33, 37, 96, 91, 35, 66, 37, 57, 83, 99, 96, 15, 18, 93], \"n\": 16, \"x\": 13}}, {\"idx\": 4, \"outputs\": 18, \"inputs\": {\"arr\": [-92, -68, -48, -48, -42, -26, -22, -18, 2, 4, 8, 14, 20, 22, 32, 46, 52, 62, 70, 96, 98], \"n\": 17, \"x\": 14}}, {\"idx\": 5, \"outputs\": 12, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0], \"n\": 11, \"x\": 10}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [4, 4, 11, 11, 13, 15, 16, 18, 19, 19, 19, 23, 26, 27, 34, 39, 39, 40, 41, 46, 47, 51, 52, 52, 53, 57, 58, 58, 60, 64, 68, 70, 72, 84, 84, 85, 95, 98, 99], \"n\": 31, \"x\": 35}}, {\"idx\": 7, \"outputs\": 43, \"inputs\": {\"arr\": [12, -22, 2, -90, -92, 84, -26, -76, -72, 50, -36, 30, 78, -18, -94, -30, 22, 28, 10, 32, 34, -86, 0, -4, 40, 0, 80, 50, 66, -48, -40, -94, 64, 58, -14, 0, -32, -58, -22, -94, -68, -36, -94, -48, 40, 78, -74], \"n\": 42, \"x\": 26}}, {\"idx\": 8, \"outputs\": 26, \"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\": 25, \"x\": 21}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [1, 33, 20, 32, 76, 27, 8, 95, 78, 72, 25, 56], \"n\": 9, \"x\": 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
]
} |
348 | Minimum Length Subarray Sum Greater Given Value 1 | C++ | int minimumLengthSubarraySumGreaterGivenValue1(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def minimum_length_subarray_sum_greater_given_value_1(arr, n, x):
curr_sum = 0
min_len = (n + 1)
start = 0
end = 0
while (end < n):
while ((curr_sum <= x) and (end < n)):
if ((curr_sum <= 0) and (x > 0)):
start = end
curr_sum = 0
curr_sum += arr[end]
end += 1
while ((curr_sum > x) and (start < n)):
if ((end - start) < min_len):
min_len = (end - start)
curr_sum -= arr[start]
start += 1
return min_len | int minimum_length_subarray_sum_greater_given_value_1(vector<int> arr, int n, int x) {
int curr_sum = 0, min_len = n + 1;
int start = 0, end = 0;
while ( end < n ) {
while ( curr_sum <= x && end < n ) {
if ( curr_sum <= 0 && x > 0 ) {
start = end;
curr_sum = 0;
}
curr_sum += arr [ end ++ ];
}
while ( curr_sum > x && start < n ) {
if ( end - start < min_len ) min_len = end - start;
curr_sum -= arr [ start ++ ];
}
}
return min_len;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int 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({2, 4, 5, 10, 14, 15, 16, 20, 23, 28, 31, 35, 36, 36, 43, 48, 49, 55, 57, 57, 58, 61, 64, 64, 68, 70, 70, 73, 74, 76, 76, 77, 81, 81, 82, 87, 89, 92, 99}, 33, 28, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, -20, 12, -48, 22, 28, 40, -30, -6, -96, 10, -88, 40}, 11, 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, 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}, 42, 23, 43); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, 19, 38, 31, 17, 27, 60, 35, 19, 47, 34, 51, 3, 95, 33, 29, 84, 46, 74, 87}, 15, 15, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-48, -2}, 1, 1, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1}, 12, 15, 13); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 4, 4, 6, 8, 10, 12, 12, 13, 15, 18, 20, 21, 23, 25, 28, 28, 33, 33, 35, 35, 36, 37, 38, 42, 44, 63, 63, 65, 65, 65, 66, 70, 74, 77, 78, 80, 80, 84, 87, 87, 89, 92, 93, 94, 97, 98, 99}, 42, 27, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-82, -12, -40, 58, 22, -76, -94, -28, 42, 36, 64}, 10, 6, 1); \n cout << \"TEST-\" << 7 << \"...\"\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}, 10, 14, 11); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, 65, 96, 76, 1, 91, 22, 29, 95, 21, 73, 68, 30, 52, 73, 86, 52, 66, 67, 37, 76, 53, 68, 6, 95, 81, 98, 42, 63, 38, 92, 78, 59, 86, 10, 38, 18, 15, 52, 62, 16, 66}, 23, 35, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumLengthSubarraySumGreaterGivenValue1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [2, 4, 5, 10, 14, 15, 16, 20, 23, 28, 31, 35, 36, 36, 43, 48, 49, 55, 57, 57, 58, 61, 64, 64, 68, 70, 70, 73, 74, 76, 76, 77, 81, 81, 82, 87, 89, 92, 99], \"n\": 33, \"x\": 28}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [66, -20, 12, -48, 22, 28, 40, -30, -6, -96, 10, -88, 40], \"n\": 11, \"x\": 12}}, {\"idx\": 2, \"outputs\": 43, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 42, \"x\": 23}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [28, 19, 38, 31, 17, 27, 60, 35, 19, 47, 34, 51, 3, 95, 33, 29, 84, 46, 74, 87], \"n\": 15, \"x\": 15}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"arr\": [-48, -2], \"n\": 1, \"x\": 1}}, {\"idx\": 5, \"outputs\": 13, \"inputs\": {\"arr\": [1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1], \"n\": 12, \"x\": 15}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [1, 4, 4, 6, 8, 10, 12, 12, 13, 15, 18, 20, 21, 23, 25, 28, 28, 33, 33, 35, 35, 36, 37, 38, 42, 44, 63, 63, 65, 65, 65, 66, 70, 74, 77, 78, 80, 80, 84, 87, 87, 89, 92, 93, 94, 97, 98, 99], \"n\": 42, \"x\": 27}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [-82, -12, -40, 58, 22, -76, -94, -28, 42, 36, 64], \"n\": 10, \"x\": 6}}, {\"idx\": 8, \"outputs\": 11, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 10, \"x\": 14}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [76, 65, 96, 76, 1, 91, 22, 29, 95, 21, 73, 68, 30, 52, 73, 86, 52, 66, 67, 37, 76, 53, 68, 6, 95, 81, 98, 42, 63, 38, 92, 78, 59, 86, 10, 38, 18, 15, 52, 62, 16, 66], \"n\": 23, \"x\": 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
]
} |
349 | Minimum Number Of Bracket Reversals Needed To Make An Expression Balanced | C++ | int minimumNumberOfBracketReversalsNeededToMakeAnExpressionBalanced(string expr) { | [
"expr"
] | def minimum_number_of_bracket_reversals_needed_to_make_an_expression_balanced(expr):
lenn = len(expr)
if (lenn % 2):
return (- 1)
s = []
for i in range(lenn):
if ((expr[i] == '') and len(s)):
if (s[0] == ''):
s.pop(0)
else:
s.insert(0, expr[i])
else:
s.insert(0, expr[i])
red_len = len(s)
n = 0
while (len(s) and (s[0] == '')):
s.pop(0)
n += 1
return ((red_len // 2) + (n % 2)) | int minimum_number_of_bracket_reversals_needed_to_make_an_expression_balanced(string expr) {
int len = expr . length ( );
if ( len % 2 ) return - 1;
stack < char > s;
for ( int i = 0;
i < len;
i ++ ) {
if ( expr [ i ] == '}' && ! s . empty ( ) ) {
if ( s . top ( ) == '{' ) s . pop ( );
else s . push ( expr [ i ] );
}
else s . push ( expr [ i ] );
}
int red_len = s . size ( );
int n = 0;
while ( ! s . empty ( ) && s . top ( ) == '{' ) {
s . pop ( );
n ++;
}
return ( red_len / 2 + 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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string expr, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(expr), 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); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"{{{\", -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"{{{{\", 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"{{{{}}\", 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"}{{}}{{{\", 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"{}\", 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"8\", -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01111000\", 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"XPkERzHcpId\", -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumNumberOfBracketReversalsNeededToMakeAnExpressionBalanced",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"expr\": \"}{\"}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"expr\": \"{{{\"}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"expr\": \"{{{{\"}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"expr\": \"{{{{}}\"}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"expr\": \"}{{}}{{{\"}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"expr\": \"{}\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"expr\": \"\"}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"expr\": \"8\"}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"expr\": \"01111000\"}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"expr\": \"XPkERzHcpId\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
352 | Minimum Number Platforms Required Railwaybus Station | C++ | int minimumNumberPlatformsRequiredRailwaybusStation(vector<int> arr, vector<int> dep, int n) { | [
"arr",
"dep",
"n"
] | def minimum_number_platforms_required_railwaybus_station(arr, dep, n):
arr.sort()
dep.sort()
plat_needed = 1
result = 1
i = 1
j = 0
while ((i < n) and (j < n)):
if (arr[i] < dep[j]):
plat_needed += 1
i += 1
if (plat_needed > result):
result = plat_needed
else:
plat_needed -= 1
j += 1
return result | int minimum_number_platforms_required_railwaybus_station(vector<int> arr, vector<int> dep, int n) {
sort(arr.begin(), arr.end());
sort(dep.begin(), dep.end());
int plat_needed = 1, result = 1;
int i = 1, j = 0;
while ( i < n && j < n ) {
if ( arr [ i ] <= dep [ j ] ) {
plat_needed ++;
i ++;
if ( plat_needed > result ) result = plat_needed;
}
else {
plat_needed --;
j ++;
}
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, vector<int> dep, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, dep, 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, 24, 28, 64, 75, 86, 93, 95}, {19, 30, 41, 51, 62, 68, 85, 96}, 6, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -92, -86, -78, -68, -58, -54, -42, -30, -30, -28, -26, -18, -8, -6, -4, 0, 0, 2, 6, 8, 14, 16, 30, 34, 50, 58, 58, 66, 78, 84, 86, 94, 98}, {-98, -90, -84, -76, -64, -62, -52, -48, -44, -34, -24, -22, -12, -10, -8, -4, 10, 10, 14, 16, 22, 28, 28, 34, 40, 46, 50, 50, 52, 64, 68, 78, 80, 96}, 18, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 1, 1}, 6, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, 5, 5, 21, 35, 48, 50, 51, 59, 61, 64, 71, 76, 81, 95}, {5, 8, 28, 31, 40, 40, 43, 47, 49, 50, 51, 67, 67, 84, 86, 90}, 8, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-64, -52, 44, 52, 90}, {-62, -16, 22, 26, 58}, 3, 1); \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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 15, 25, 55, 72, 96, 98}, {3, 6, 11, 19, 26, 37, 39}, 6, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -76, -72, -60, -58, -56, -56, -48, -40, -34, -34, -30, -24, -20, 4, 8, 30, 30, 40, 52, 74, 74, 76}, {-98, -96, -82, -76, -76, -72, -66, -64, -50, -40, -28, -22, -20, -8, 6, 8, 14, 18, 34, 36, 52, 52, 56}, 20, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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}, {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}, 22, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 20, 34, 37, 56, 72, 84, 87}, {15, 29, 54, 62, 68, 70, 84, 96}, 6, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumNumberPlatformsRequiredRailwaybusStation",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [8, 24, 28, 64, 75, 86, 93, 95], \"dep\": [19, 30, 41, 51, 62, 68, 85, 96], \"n\": 6}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"arr\": [-94, -92, -86, -78, -68, -58, -54, -42, -30, -30, -28, -26, -18, -8, -6, -4, 0, 0, 2, 6, 8, 14, 16, 30, 34, 50, 58, 58, 66, 78, 84, 86, 94, 98], \"dep\": [-98, -90, -84, -76, -64, -62, -52, -48, -44, -34, -24, -22, -12, -10, -8, -4, 10, 10, 14, 16, 22, 28, 28, 34, 40, 46, 50, 50, 52, 64, 68, 78, 80, 96], \"n\": 18}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1], \"dep\": [0, 0, 0, 0, 0, 1, 1], \"n\": 6}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"arr\": [2, 4, 5, 5, 21, 35, 48, 50, 51, 59, 61, 64, 71, 76, 81, 95], \"dep\": [5, 8, 28, 31, 40, 40, 43, 47, 49, 50, 51, 67, 67, 84, 86, 90], \"n\": 8}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-64, -52, 44, 52, 90], \"dep\": [-62, -16, 22, 26, 58], \"n\": 3}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"dep\": [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], \"n\": 17}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [2, 15, 25, 55, 72, 96, 98], \"dep\": [3, 6, 11, 19, 26, 37, 39], \"n\": 6}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"arr\": [-98, -76, -72, -60, -58, -56, -56, -48, -40, -34, -34, -30, -24, -20, 4, 8, 30, 30, 40, 52, 74, 74, 76], \"dep\": [-98, -96, -82, -76, -76, -72, -66, -64, -50, -40, -28, -22, -20, -8, 6, 8, 14, 18, 34, 36, 52, 52, 56], \"n\": 20}}, {\"idx\": 8, \"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, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"dep\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 22}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr\": [1, 20, 34, 37, 56, 72, 84, 87], \"dep\": [15, 29, 54, 62, 68, 70, 84, 96], \"n\": 6}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
353 | Minimum Number Subsets Distinct Elements | C++ | int minimumNumberSubsetsDistinctElements(vector<int> ar, int n) { | [
"ar",
"n"
] | def minimum_number_subsets_distinct_elements(ar, n):
res = 0
ar.sort()
for i in range(0, n):
count = 1
for i in range((n - 1)):
if (ar[i] == ar[(i + 1)]):
count += 1
else:
break
res = max(res, count)
return res | int minimum_number_subsets_distinct_elements(vector<int> ar, int n) {
int res = 0;
sort(ar.begin(), ar.end());
for ( int i = 0;
i < n;
i ++ ) {
int count = 1;
for (;
i < n - 1;
i ++ ) {
if ( ar [ i ] == ar [ i + 1 ] ) count ++;
else break;
}
res = max ( res, count );
}
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> ar, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(ar, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 2, 5, 8, 16, 21, 21, 22, 23, 26, 26, 27, 27, 29, 31, 33, 36, 37, 37, 38, 42, 45, 47, 50, 57, 58, 60, 60, 62, 63, 66, 66, 76, 84, 84, 88, 96, 99}, 25, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -96, -94, -94, -82, -82, -62, -60, -46, -46, -38, -36, -36, -30, -24, -22, -18, -14, -10, 2, 4, 4, 4, 8, 8, 12, 24, 34, 46, 50, 52, 70, 78, 78, 80, 80, 82, 82, 82, 86, 92, 94}, 35, 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, 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}, 34, 27); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, 38, 38, 41, 47, 48, 48, 48, 49, 62, 84, 92, 99}, 6, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -64, -40, -38, -38, -16, 16, 20, 28, 40, 56, 58, 60, 68, 74, 92}, 12, 1); \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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, 22); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, 24, 82, 87, 95}, 3, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -88, -84, -80, -80, -76, -68, -64, -58, -58, -58, -46, -40, -34, -18, -14, -10, 2, 2, 4, 8, 12, 14, 22, 40, 40, 46, 50, 52, 62, 62, 64, 68, 76, 90, 94}, 34, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1}, 3, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 6, 17, 41, 43, 68, 68, 86, 89, 90}, 7, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumNumberSubsetsDistinctElements",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"ar\": [1, 2, 5, 8, 16, 21, 21, 22, 23, 26, 26, 27, 27, 29, 31, 33, 36, 37, 37, 38, 42, 45, 47, 50, 57, 58, 60, 60, 62, 63, 66, 66, 76, 84, 84, 88, 96, 99], \"n\": 25}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"ar\": [-96, -96, -94, -94, -82, -82, -62, -60, -46, -46, -38, -36, -36, -30, -24, -22, -18, -14, -10, 2, 4, 4, 4, 8, 8, 12, 24, 34, 46, 50, 52, 70, 78, 78, 80, 80, 82, 82, 82, 86, 92, 94], \"n\": 35}}, {\"idx\": 2, \"outputs\": 27, \"inputs\": {\"ar\": [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], \"n\": 34}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"ar\": [16, 38, 38, 41, 47, 48, 48, 48, 49, 62, 84, 92, 99], \"n\": 6}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"ar\": [-88, -64, -40, -38, -38, -16, 16, 20, 28, 40, 56, 58, 60, 68, 74, 92], \"n\": 12}}, {\"idx\": 5, \"outputs\": 22, \"inputs\": {\"ar\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"ar\": [14, 24, 82, 87, 95], \"n\": 3}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"ar\": [-90, -88, -84, -80, -80, -76, -68, -64, -58, -58, -58, -46, -40, -34, -18, -14, -10, 2, 2, 4, 8, 12, 14, 22, 40, 40, 46, 50, 52, 62, 62, 64, 68, 76, 90, 94], \"n\": 34}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"ar\": [0, 1, 1, 1], \"n\": 3}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"ar\": [5, 6, 17, 41, 43, 68, 68, 86, 89, 90], \"n\": 7}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
354 | Minimum Operations Make Gcd Array Multiple K | C++ | int minimumOperationsMakeGcdArrayMultipleK(vector<int> a, int n, int k) { | [
"a",
"n",
"k"
] | def minimum_operations_make_gcd_array_multiple_k(a, n, k):
result = 0
for i in range(n):
if ((a[i] != 1) and (a[i] > k)):
result = (result + min((a[i] % k), (k - (a[i] % k))))
else:
result = ((result + k) - a[i])
return result | int minimum_operations_make_gcd_array_multiple_k(vector<int> a, int n, int k) {
int result = 0;
for ( int i = 0;
i < n;
++ i ) {
if ( a [ i ] != 1 && a [ i ] > k ) {
result = result + min ( a [ i ] % k, k - a [ i ] % k );
}
else {
result = result + k - a [ i ];
}
}
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, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({3, 7, 27, 32, 36, 37, 44, 48, 50, 64, 86}, 5, 10, 19); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-22, 6, -20, 60, -74, 98, 52, -22}, 5, 4, 130); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 23, 29, 661); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({77, 11, 51, 11, 84, 79, 43, 12, 14, 50, 15, 6, 85, 32, 74, 49, 7, 2, 58}, 9, 17, 43); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -66, -64, -58, -46, -44, -32, -30, -30, -22, -18, -14, 12, 12, 18, 34, 44, 60, 70, 70, 74, 76, 86, 98, 98}, 12, 22, 778); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1}, 36, 31, 1096); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9, 22, 27, 27, 37, 53, 53, 56, 63, 73, 76, 81, 82}, 10, 11, 28); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-46, 60, 80, 80, 42, -98, 30, -48, 4, -32, -78, 40, 52, 26, 88, 4, 22, 62, 88, -94, 2, 0, 58, 38, 52, -50, -52, 58, -62, 30, -38, -8, -82, -66}, 18, 19, 479); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 19, 22, 413); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({42, 69, 93, 82, 8, 23, 73, 1, 77, 39, 49, 4, 95, 85}, 12, 13, 51); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumOperationsMakeGcdArrayMultipleK",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 19, \"inputs\": {\"a\": [3, 7, 27, 32, 36, 37, 44, 48, 50, 64, 86], \"n\": 5, \"k\": 10}}, {\"idx\": 1, \"outputs\": 130, \"inputs\": {\"a\": [-22, 6, -20, 60, -74, 98, 52, -22], \"n\": 5, \"k\": 4}}, {\"idx\": 2, \"outputs\": 661, \"inputs\": {\"a\": [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\": 23, \"k\": 29}}, {\"idx\": 3, \"outputs\": 43, \"inputs\": {\"a\": [77, 11, 51, 11, 84, 79, 43, 12, 14, 50, 15, 6, 85, 32, 74, 49, 7, 2, 58], \"n\": 9, \"k\": 17}}, {\"idx\": 4, \"outputs\": 778, \"inputs\": {\"a\": [-90, -66, -64, -58, -46, -44, -32, -30, -30, -22, -18, -14, 12, 12, 18, 34, 44, 60, 70, 70, 74, 76, 86, 98, 98], \"n\": 12, \"k\": 22}}, {\"idx\": 5, \"outputs\": 1096, \"inputs\": {\"a\": [1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1], \"n\": 36, \"k\": 31}}, {\"idx\": 6, \"outputs\": 28, \"inputs\": {\"a\": [9, 22, 27, 27, 37, 53, 53, 56, 63, 73, 76, 81, 82], \"n\": 10, \"k\": 11}}, {\"idx\": 7, \"outputs\": 479, \"inputs\": {\"a\": [-46, 60, 80, 80, 42, -98, 30, -48, 4, -32, -78, 40, 52, 26, 88, 4, 22, 62, 88, -94, 2, 0, 58, 38, 52, -50, -52, 58, -62, 30, -38, -8, -82, -66], \"n\": 18, \"k\": 19}}, {\"idx\": 8, \"outputs\": 413, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 19, \"k\": 22}}, {\"idx\": 9, \"outputs\": 51, \"inputs\": {\"a\": [42, 69, 93, 82, 8, 23, 73, 1, 77, 39, 49, 4, 95, 85], \"n\": 12, \"k\": 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
]
} |
355 | Minimum Perimeter N Blocks | C++ | double minimumPerimeterNBlocks(int n) { | [
"n"
] | def minimum_perimeter_n_blocks(n):
l = math.sqrt(n)
sq = (l * l)
if (sq == n):
return (l * 4)
else:
row = (n / l)
perimeter = (2 * (l + row))
if ((n % l) != 0):
perimeter += 2
return perimeter | int minimum_perimeter_n_blocks(int n) {
int l = sqrt ( n );
int sq = l * l;
if ( sq == n ) return l * 4;
else {
long long int row = n / l;
long long int perimeter = 2 * ( l + row );
if ( n % l != 0 ) perimeter += 2;
return perimeter;
}
} | {
"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(45, 28.832815729997478); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 37.77708763999664); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 29.393876913398138); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 29.712812921102035); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 36.4417343165772); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 32.984845004941285); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 24.62741699796952); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 19.88854381999832); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 32.984845004941285); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 34.49615361854384); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumPerimeterNBlocks",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 28.832815729997478, \"inputs\": {\"n\": 45}}, {\"idx\": 1, \"outputs\": 37.77708763999664, \"inputs\": {\"n\": 80}}, {\"idx\": 2, \"outputs\": 29.393876913398138, \"inputs\": {\"n\": 54}}, {\"idx\": 3, \"outputs\": 29.712812921102035, \"inputs\": {\"n\": 48}}, {\"idx\": 4, \"outputs\": 36.4417343165772, \"inputs\": {\"n\": 83}}, {\"idx\": 5, \"outputs\": 32.984845004941285, \"inputs\": {\"n\": 68}}, {\"idx\": 6, \"outputs\": 24.62741699796952, \"inputs\": {\"n\": 32}}, {\"idx\": 7, \"outputs\": 19.88854381999832, \"inputs\": {\"n\": 20}}, {\"idx\": 8, \"outputs\": 32.984845004941285, \"inputs\": {\"n\": 68}}, {\"idx\": 9, \"outputs\": 34.49615361854384, \"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
]
} |
356 | Minimum Product Subset Array | C++ | long long minimumProductSubsetArray(vector<int> a, int n) { | [
"a",
"n"
] | def minimum_product_subset_array(a, n):
if (n == 1):
return a[0]
max_neg = float('-inf')
min_pos = float('inf')
count_neg = 0
count_zero = 0
prod = 1
for i in range(0, n):
if (a[i] == 0):
count_zero = (count_zero + 1)
continue
if (a[i] < 0):
count_neg = (count_neg + 1)
max_neg = max(max_neg, a[i])
if (a[i] > 0):
min_pos = min(min_pos, a[i])
prod = (prod * a[i])
if ((count_zero == n) or ((count_neg == 0) and (count_zero > 0))):
return 0
if (count_neg == 0):
return min_pos
if (((count_neg & 1) == 0) and (count_neg != 0)):
prod = int((prod / max_neg))
return prod | int minimum_product_subset_array(vector<int> a, int n) {
if ( n == 1 ) return a [ 0 ];
int max_neg = INT_MIN;
int min_pos = INT_MAX;
int count_neg = 0, count_zero = 0;
int prod = 1;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] == 0 ) {
count_zero ++;
continue;
}
if ( a [ i ] < 0 ) {
count_neg ++;
max_neg = max ( max_neg, a [ i ] );
}
if ( a [ i ] > 0 ) min_pos = min ( min_pos, a [ i ] );
prod = prod * a [ i ];
}
if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0;
if ( count_neg == 0 ) return min_pos;
if ( ! ( count_neg & 1 ) && count_neg != 0 ) {
prod = prod / max_neg;
}
return prod;
} | {
"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, long long 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({3, 6, 7, 8, 8, 9, 12, 12, 12, 13, 15, 15, 15, 16, 18, 18, 18, 19, 20, 21, 22, 22, 23, 28, 29, 30, 30, 33, 33, 35, 35, 36, 40, 43, 58, 63, 73, 78, 82, 83, 84, 87, 89, 89, 92, 94}, 23, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({18, -6, -8, 98, 66, -86, 24, 6, 58, 74, 82}, 10, -297032800813056); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({97, 79, 93, 41, 76, 34, 94, 57, 63, 98, 52, 62, 96, 7, 63, 44, 55, 43, 36, 66, 35, 14, 24, 40, 26, 16, 67, 19, 31, 86, 64, 93, 85, 86, 66, 24, 73, 86, 45, 99, 25, 98, 38, 57}, 30, 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-58, -48, -46, -36, 0, 18}, 3, -128064); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0}, 36, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 3, 5, 15, 18, 19, 21, 23, 29, 29, 33, 33, 34, 37, 39, 43, 43, 68, 73, 74, 75, 84, 87, 88, 89, 90, 93}, 18, 1); \n cout << \"TEST-\" << 6 << \"...\"\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}, 20, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({74, 74, 8, 74, 85, 41, 31, 3, 84, 46, 73, 39, 64, 72, 28, 83, 98, 27, 64, 7, 95, 37, 10, 38, 77, 32, 69, 72, 62, 96, 5, 81, 34, 96, 80, 25, 38}, 33, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumProductSubsetArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"a\": [3, 6, 7, 8, 8, 9, 12, 12, 12, 13, 15, 15, 15, 16, 18, 18, 18, 19, 20, 21, 22, 22, 23, 28, 29, 30, 30, 33, 33, 35, 35, 36, 40, 43, 58, 63, 73, 78, 82, 83, 84, 87, 89, 89, 92, 94], \"n\": 23}}, {\"idx\": 1, \"outputs\": -297032800813056, \"inputs\": {\"a\": [18, -6, -8, 98, 66, -86, 24, 6, 58, 74, 82], \"n\": 10}}, {\"idx\": 2, \"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, 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\": 25}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"a\": [97, 79, 93, 41, 76, 34, 94, 57, 63, 98, 52, 62, 96, 7, 63, 44, 55, 43, 36, 66, 35, 14, 24, 40, 26, 16, 67, 19, 31, 86, 64, 93, 85, 86, 66, 24, 73, 86, 45, 99, 25, 98, 38, 57], \"n\": 30}}, {\"idx\": 4, \"outputs\": -128064, \"inputs\": {\"a\": [-58, -48, -46, -36, 0, 18], \"n\": 3}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0], \"n\": 36}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"a\": [1, 3, 5, 15, 18, 19, 21, 23, 29, 29, 33, 33, 34, 37, 39, 43, 43, 68, 73, 74, 75, 84, 87, 88, 89, 90, 93], \"n\": 18}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 20}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"a\": [74, 74, 8, 74, 85, 41, 31, 3, 84, 46, 73, 39, 64, 72, 28, 83, 98, 27, 64, 7, 95, 37, 10, 38, 77, 32, 69, 72, 62, 96, 5, 81, 34, 96, 80, 25, 38], \"n\": 33}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
357 | Minimum Rotations Required Get String | C++ | int minimumRotationsRequiredGetString(string str) { | [
"str"
] | def minimum_rotations_required_get_string(str):
tmp = (str + str)
n = len(str)
for i in range(1, (n + 1)):
substring = tmp[i:n]
if (str == substring):
return i
return n | int minimum_rotations_required_get_string(string str) {
string tmp = str + str;
int n = str . length ( );
for ( int i = 1;
i <= n;
i ++ ) {
string substring = tmp . substr ( i, str . size ( ) );
if ( str == substring ) return i;
}
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(string str, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"vdevdNdQSopPtj\", 14); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"5\", 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100010101011\", 12); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"tlDOvJHAyMllu\", 13); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"06\", 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"101\", 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"DYgtU\", 5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"4\", 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00\", 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Dt\", 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumRotationsRequiredGetString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 14, \"inputs\": {\"str\": \"vdevdNdQSopPtj\"}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"str\": \"5\"}}, {\"idx\": 2, \"outputs\": 12, \"inputs\": {\"str\": \"100010101011\"}}, {\"idx\": 3, \"outputs\": 13, \"inputs\": {\"str\": \"tlDOvJHAyMllu\"}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"str\": \"06\"}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"str\": \"101\"}}, {\"idx\": 6, \"outputs\": 5, \"inputs\": {\"str\": \"DYgtU\"}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"str\": \"4\"}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"str\": \"00\"}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"str\": \"Dt\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
358 | Minimum Rotations Unlock Circular Lock | C++ | int minimumRotationsUnlockCircularLock(int input, int unlock_code) { | [
"input",
"unlock_code"
] | def minimum_rotations_unlock_circular_lock(input, unlock_code):
rotation = 0
while ((input > 0) or (unlock_code > 0)):
input_digit = (input % 10)
code_digit = (unlock_code % 10)
rotation += min(abs((input_digit - code_digit)), (10 - abs((input_digit - code_digit))))
input = int((input / 10))
unlock_code = int((unlock_code / 10))
return rotation | int minimum_rotations_unlock_circular_lock(int input, int unlock_code) {
int rotation = 0;
int input_digit, code_digit;
while ( input || unlock_code ) {
input_digit = input % 10;
code_digit = unlock_code % 10;
rotation += min ( abs ( input_digit - code_digit ), 10 - abs ( input_digit - code_digit ) );
input /= 10;
unlock_code /= 10;
}
return rotation;
} | {
"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 input, int unlock_code, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(input, unlock_code), 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(71, 46, 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 65, 8); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 84, 8); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 23, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 58, 6); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 82, 8); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 58, 7); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 32, 8); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 51, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 77, 7); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumRotationsUnlockCircularLock",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"input\": 71, \"unlock_code\": 46}}, {\"idx\": 1, \"outputs\": 8, \"inputs\": {\"input\": 90, \"unlock_code\": 65}}, {\"idx\": 2, \"outputs\": 8, \"inputs\": {\"input\": 28, \"unlock_code\": 84}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"input\": 41, \"unlock_code\": 23}}, {\"idx\": 4, \"outputs\": 6, \"inputs\": {\"input\": 32, \"unlock_code\": 58}}, {\"idx\": 5, \"outputs\": 8, \"inputs\": {\"input\": 39, \"unlock_code\": 82}}, {\"idx\": 6, \"outputs\": 7, \"inputs\": {\"input\": 33, \"unlock_code\": 58}}, {\"idx\": 7, \"outputs\": 8, \"inputs\": {\"input\": 89, \"unlock_code\": 32}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"input\": 50, \"unlock_code\": 51}}, {\"idx\": 9, \"outputs\": 7, \"inputs\": {\"input\": 92, \"unlock_code\": 77}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
359 | Minimum Steps Minimize N Per Given Condition | C++ | int minimumStepsMinimizeNPerGivenCondition(int n) { | [
"n"
] | def minimum_steps_minimize_n_per_given_condition(n):
table = ([0] * (n + 1))
for i in range((n + 1)):
table[i] = (n - i)
for i in range(n, 0, (- 1)):
if (not (i % 2)):
table[(i // 2)] = min((table[i] + 1), table[(i // 2)])
if (not (i % 3)):
table[(i // 3)] = min((table[i] + 1), table[(i // 3)])
return table[1] | int minimum_steps_minimize_n_per_given_condition(int n) {
int table [ n + 1 ];
for ( int i = 0;
i <= n;
i ++ ) table [ i ] = n - i;
for ( int i = n;
i >= 1;
i -- ) {
if ( ! ( i % 2 ) ) table [ i / 2 ] = min ( table [ i ] + 1, table [ i / 2 ] );
if ( ! ( i % 3 ) ) table [ i / 3 ] = min ( table [ i ] + 1, table [ i / 3 ] );
}
return table [ 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(59, 9); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 13); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 11); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 6); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 6); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 13); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 6); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 12); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumStepsMinimizeNPerGivenCondition",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 9, \"inputs\": {\"n\": 59}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"n\": 7}}, {\"idx\": 2, \"outputs\": 13, \"inputs\": {\"n\": 90}}, {\"idx\": 3, \"outputs\": 11, \"inputs\": {\"n\": 78}}, {\"idx\": 4, \"outputs\": 6, \"inputs\": {\"n\": 49}}, {\"idx\": 5, \"outputs\": 6, \"inputs\": {\"n\": 15}}, {\"idx\": 6, \"outputs\": 13, \"inputs\": {\"n\": 45}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"n\": 56}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"n\": 7}}, {\"idx\": 9, \"outputs\": 12, \"inputs\": {\"n\": 70}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
360 | Minimum Steps To Delete A String After Repeated Deletion Of Palindrome Substrings | C++ | int minimumStepsToDeleteAStringAfterRepeatedDeletionOfPalindromeSubstrings(string str) { | [
"str"
] | def minimum_steps_to_delete_a_string_after_repeated_deletion_of_palindrome_substrings(str):
N = len(str)
dp = [[0 for x in range((N + 1))] for y in range((N + 1))]
for l in range(1, (N + 1)):
i = 0
j = (l - 1)
while (j < N):
if (l == 1):
dp[i][j] = 1
else:
dp[i][j] = (1 + dp[(i + 1)][j])
if (str[i] == str[(i + 1)]):
dp[i][j] = min((1 + dp[(i + 2)][j]), dp[i][j])
for K in range((i + 2), (j + 1)):
if (str[i] == str[K]):
dp[i][j] = min((dp[(i + 1)][(K - 1)] + dp[(K + 1)][j]), dp[i][j])
i += 1
j += 1
return dp[0][(N - 1)] | int minimum_steps_to_delete_a_string_after_repeated_deletion_of_palindrome_substrings(string str) {
int N = str . length ( );
int dp [ N + 1 ] [ N + 1 ];
for ( int i = 0;
i <= N;
i ++ ) for ( int j = 0;
j <= N;
j ++ ) dp [ i ] [ j ] = 0;
for ( int len = 1;
len <= N;
len ++ ) {
for ( int i = 0, j = len - 1;
j < N;
i ++, j ++ ) {
if ( len == 1 ) dp [ i ] [ j ] = 1;
else {
dp [ i ] [ j ] = 1 + dp [ i + 1 ] [ j ];
if ( str [ i ] == str [ i + 1 ] ) dp [ i ] [ j ] = min ( 1 + dp [ i + 2 ] [ j ], dp [ i ] [ j ] );
for ( int K = i + 2;
K <= j;
K ++ ) if ( str [ i ] == str [ K ] ) dp [ i ] [ j ] = min ( dp [ i + 1 ] [ K - 1 ] + dp [ K + 1 ] [ j ], dp [ i ] [ j ] );
}
}
}
return dp [ 0 ] [ N - 1 ];
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string str, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"YCtLQtHLwr\", 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"47713514383248\", 7); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0100101001111\", 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"XfdIYVn\", 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"45499225407\", 5); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000100111001\", 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ZoUQhQwoap\", 6); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"18579027952\", 7); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00000001111\", 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"JD\", 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumStepsToDeleteAStringAfterRepeatedDeletionOfPalindromeSubstrings",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"str\": \"YCtLQtHLwr\"}}, {\"idx\": 1, \"outputs\": 7, \"inputs\": {\"str\": \"47713514383248\"}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"str\": \"0100101001111\"}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"str\": \"XfdIYVn\"}}, {\"idx\": 4, \"outputs\": 5, \"inputs\": {\"str\": \"45499225407\"}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"str\": \"000100111001\"}}, {\"idx\": 6, \"outputs\": 6, \"inputs\": {\"str\": \"ZoUQhQwoap\"}}, {\"idx\": 7, \"outputs\": 7, \"inputs\": {\"str\": \"18579027952\"}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"str\": \"00000001111\"}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"str\": \"JD\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
361 | Minimum Sum Subsequence Least One Every Four Consecutive Elements Picked | C++ | int minimumSumSubsequenceLeastOneEveryFourConsecutiveElementsPicked(vector<int> arr, int n) { | [
"arr",
"n"
] | def minimum_sum_subsequence_least_one_every_four_consecutive_elements_picked(arr, n):
dp = ([0] * n)
if (n == 1):
return arr[0]
if (n == 2):
return min(arr[0], arr[1])
if (n == 3):
return min(arr[0], min(arr[1], arr[2]))
if (n == 4):
return min(min(arr[0], arr[1]), min(arr[2], arr[3]))
dp[0] = arr[0]
dp[1] = arr[1]
dp[2] = arr[2]
dp[3] = arr[3]
for i in range(4, n):
dp[i] = (arr[i] + min(min(dp[(i - 1)], dp[(i - 2)]), min(dp[(i - 3)], dp[(i - 4)])))
return min(min(dp[(n - 1)], dp[(n - 2)]), min(dp[(n - 4)], dp[(n - 3)])) | int minimum_sum_subsequence_least_one_every_four_consecutive_elements_picked(vector<int> arr, int n) {
int dp [ n ];
if ( n == 1 ) return arr [ 0 ];
if ( n == 2 ) return min ( arr [ 0 ], arr [ 1 ] );
if ( n == 3 ) return min ( arr [ 0 ], min ( arr [ 1 ], arr [ 2 ] ) );
if ( n == 4 ) return min ( min ( arr [ 0 ], arr [ 1 ] ), min ( arr [ 2 ], arr [ 3 ] ) );
dp [ 0 ] = arr [ 0 ];
dp [ 1 ] = arr [ 1 ];
dp [ 2 ] = arr [ 2 ];
dp [ 3 ] = arr [ 3 ];
for ( int i = 4;
i < n;
i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ], dp [ i - 2 ] ), min ( dp [ i - 3 ], dp [ i - 4 ] ) );
return min ( min ( dp [ n - 1 ], dp [ n - 2 ] ), min ( dp [ n - 4 ], dp [ n - 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(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, 7, 11, 12, 13, 14, 18, 20, 22, 26, 28, 29, 31, 32, 33, 35, 38, 38, 40, 40, 41, 42, 43, 44, 45, 53, 54, 54, 59, 62, 69, 72, 74, 75, 75, 76, 79, 83, 84, 89, 91, 96, 97, 98, 99, 99}, 30, 227); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, -22, 90, -40, 46, 86, 50, 44, 12, -42, -58, 6, 52, -16, 4, 46, 44, 0, -64, 78, -14, -80, 30, -66, 78, 24, 28, 10, -72, -44, -28, -32, -30, 94, -22, 26, 16, 20, -52, -16, -80, 2, -56, -70, -76, 60, 62}, 40, -622); \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}, 14, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({63, 18, 13, 2, 1, 94, 11, 49, 82, 97, 75, 98, 25, 20, 96, 82, 60, 94, 24, 15, 79, 48, 40, 60, 9, 62, 24, 69, 31, 78, 34, 83, 22, 88}, 33, 281); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-74, 16, 96}, 1, -74); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 1, 1}, 5, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 5, 6, 8, 10, 16, 18, 19, 20, 21, 24, 30, 34, 36, 39, 42, 52, 53, 54, 55, 56, 57, 70, 71, 72, 73, 75, 75, 77, 78, 82, 85, 87, 88, 89, 91}, 25, 188); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-40, 12, -86, -54, -68, 32, 10, -24, -46, 54, -64, 20, 22, 88, 62, -4, -2, -8, -32, 88, -4, 38, 4, 86, 82, -16, -76, -44, 54, -24, -92, 74, 50, -52, 52}, 22, -318); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 20, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 53, 96, 86, 69, 81, 86, 95, 80, 43, 25, 66, 24, 72}, 12, 153); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumSumSubsequenceLeastOneEveryFourConsecutiveElementsPicked",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 227, \"inputs\": {\"arr\": [2, 7, 11, 12, 13, 14, 18, 20, 22, 26, 28, 29, 31, 32, 33, 35, 38, 38, 40, 40, 41, 42, 43, 44, 45, 53, 54, 54, 59, 62, 69, 72, 74, 75, 75, 76, 79, 83, 84, 89, 91, 96, 97, 98, 99, 99], \"n\": 30}}, {\"idx\": 1, \"outputs\": -622, \"inputs\": {\"arr\": [50, -22, 90, -40, 46, 86, 50, 44, 12, -42, -58, 6, 52, -16, 4, 46, 44, 0, -64, 78, -14, -80, 30, -66, 78, 24, 28, 10, -72, -44, -28, -32, -30, 94, -22, 26, 16, 20, -52, -16, -80, 2, -56, -70, -76, 60, 62], \"n\": 40}}, {\"idx\": 2, \"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\": 14}}, {\"idx\": 3, \"outputs\": 281, \"inputs\": {\"arr\": [63, 18, 13, 2, 1, 94, 11, 49, 82, 97, 75, 98, 25, 20, 96, 82, 60, 94, 24, 15, 79, 48, 40, 60, 9, 62, 24, 69, 31, 78, 34, 83, 22, 88], \"n\": 33}}, {\"idx\": 4, \"outputs\": -74, \"inputs\": {\"arr\": [-74, 16, 96], \"n\": 1}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 1, 0, 1, 1], \"n\": 5}}, {\"idx\": 6, \"outputs\": 188, \"inputs\": {\"arr\": [2, 5, 6, 8, 10, 16, 18, 19, 20, 21, 24, 30, 34, 36, 39, 42, 52, 53, 54, 55, 56, 57, 70, 71, 72, 73, 75, 75, 77, 78, 82, 85, 87, 88, 89, 91], \"n\": 25}}, {\"idx\": 7, \"outputs\": -318, \"inputs\": {\"arr\": [-40, 12, -86, -54, -68, 32, 10, -24, -46, 54, -64, 20, 22, 88, 62, -4, -2, -8, -32, 88, -4, 38, 4, 86, 82, -16, -76, -44, 54, -24, -92, 74, 50, -52, 52], \"n\": 22}}, {\"idx\": 8, \"outputs\": 0, \"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], \"n\": 20}}, {\"idx\": 9, \"outputs\": 153, \"inputs\": {\"arr\": [4, 53, 96, 86, 69, 81, 86, 95, 80, 43, 25, 66, 24, 72], \"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
]
} |
362 | Minimum Sum Subsequence Least One Every Four Consecutive Elements Picked 1 | C++ | int minimumSumSubsequenceLeastOneEveryFourConsecutiveElementsPicked1(vector<int> ar, int n) { | [
"ar",
"n"
] | def minimum_sum_subsequence_least_one_every_four_consecutive_elements_picked_1(ar, n):
if (n <= 4):
return min(ar)
sum = [0 for i in range(n)]
sum[0] = ar[0]
sum[1] = ar[1]
sum[2] = ar[2]
sum[3] = ar[3]
for i in range(4, n):
sum[i] = (ar[i] + min(sum[(i - 4):i]))
return min(sum[(n - 4):n]) | int minimum_sum_subsequence_least_one_every_four_consecutive_elements_picked_1(vector<int> ar, int n) {
if ( n <= 4 ) return * min_element(ar.begin(), ar.end());
int sum [ n ];
sum [ 0 ] = ar [ 0 ];
sum [ 1 ] = ar [ 1 ];
sum [ 2 ] = ar [ 2 ];
sum [ 3 ] = ar [ 3 ];
for ( int i = 4;
i < n;
i ++ ) sum [ i ] = ar [ i ] + ( * min_element ( sum + i - 4, sum + i ) );
return * min_element ( sum + n - 4, sum + 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(vector<int> ar, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(ar, 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, 9, 26, 31, 31, 33, 35, 40, 45, 48, 52, 57, 60, 69, 75, 82, 89, 90, 92, 95, 97}, 19, 188); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({60, -68, 30, -62, -8, 48, -20, 30, 16, -60, -20}, 5, -76); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 43, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({15, 70, 50, 28, 67, 11, 27, 42, 1, 61, 37, 8, 66, 54, 50, 91, 86, 57, 4}, 15, 48); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -84, -80, -70, -58, -58, -48, -42, -14, -8, 24, 30, 32, 42, 62, 68, 70, 72, 88}, 16, -366); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0}, 7, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 5, 10, 12, 13, 16, 19, 19, 21, 22, 25, 26, 29, 30, 33, 34, 44, 46, 52, 55, 55, 56, 78, 86, 88, 88, 90, 92}, 16, 61); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({40, -50, -96, 78, 82, -16, 26, 8, 38, 38, 54, -24, 88, 96, -42, -84, -28, -32, -64, 74, 74, -10, -8, 66, 14, -78, 56, -22, -90, 66, -68}, 26, -474); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 7, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({29, 38, 20, 25, 16, 97, 16, 90, 30, 99}, 9, 36); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumSumSubsequenceLeastOneEveryFourConsecutiveElementsPicked1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 188, \"inputs\": {\"ar\": [4, 4, 9, 26, 31, 31, 33, 35, 40, 45, 48, 52, 57, 60, 69, 75, 82, 89, 90, 92, 95, 97], \"n\": 19}}, {\"idx\": 1, \"outputs\": -76, \"inputs\": {\"ar\": [60, -68, 30, -62, -8, 48, -20, 30, 16, -60, -20], \"n\": 5}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"ar\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 43}}, {\"idx\": 3, \"outputs\": 48, \"inputs\": {\"ar\": [15, 70, 50, 28, 67, 11, 27, 42, 1, 61, 37, 8, 66, 54, 50, 91, 86, 57, 4], \"n\": 15}}, {\"idx\": 4, \"outputs\": -366, \"inputs\": {\"ar\": [-98, -92, -84, -80, -70, -58, -58, -48, -42, -14, -8, 24, 30, 32, 42, 62, 68, 70, 72, 88], \"n\": 16}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"ar\": [1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0], \"n\": 7}}, {\"idx\": 6, \"outputs\": 61, \"inputs\": {\"ar\": [4, 5, 5, 10, 12, 13, 16, 19, 19, 21, 22, 25, 26, 29, 30, 33, 34, 44, 46, 52, 55, 55, 56, 78, 86, 88, 88, 90, 92], \"n\": 16}}, {\"idx\": 7, \"outputs\": -474, \"inputs\": {\"ar\": [40, -50, -96, 78, 82, -16, 26, 8, 38, 38, 54, -24, 88, 96, -42, -84, -28, -32, -64, 74, 74, -10, -8, 66, 14, -78, 56, -22, -90, 66, -68], \"n\": 26}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"ar\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 36, \"inputs\": {\"ar\": [29, 38, 20, 25, 16, 97, 16, 90, 30, 99], \"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
]
} |
363 | Minimum Sum Two Numbers Formed Digits Array | C++ | long long minimumSumTwoNumbersFormedDigitsArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def minimum_sum_two_numbers_formed_digits_array(arr, n):
arr.sort()
a = 0
b = 0
for i in range(n):
if ((i % 2) != 0):
a = ((a * 10) + arr[i])
else:
b = ((b * 10) + arr[i])
return (a + b) | int minimum_sum_two_numbers_formed_digits_array(vector<int> arr, int n) {
sort(arr.begin(), arr.end());
int a = 0, b = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( i & 1 ) a = a * 10 + arr [ i ];
else b = b * 10 + arr [ i ];
}
return a + 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(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, long long 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, 10, 14, 16, 18, 42, 43, 43, 45, 46, 51, 52, 53, 58, 61, 66, 79, 81, 82, 84}, 19, 4183488835); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -86, -76, -50, -46, -30, -26, -22, -22, -20, -2, -2, 8, 22, 32, 40, 48, 48, 56, 58, 60, 76, 82, 82, 94, 98}, 25, -107220607602444); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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}, 23, 1222222); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({45, 79}, 1, 45); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -68, -38, -34, -4, 6, 10, 28, 48, 52, 54, 68, 88, 90}, 11, -10095534); \n cout << \"TEST-\" << 4 << \"...\"\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}, 22, 122222); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 8, 8, 23, 26, 27, 30, 42, 44, 55, 59, 64, 67, 69, 74, 77, 82, 82, 87, 96, 97}, 17, 615688689); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -86, -82, -76, -76, -66, -64, -62, -60, -48, -46, -42, -36, -36, -32, -28, -18, -18, -4, 0, 0, 2, 4, 10, 18, 30, 46, 50, 52, 62, 70, 72, 76, 80, 88, 88, 94, 96}, 32, -214463225281903248); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, 6, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 8, 9, 9, 14, 14, 16, 17, 22, 24, 32, 32, 36, 38, 42, 42, 43, 45, 47, 53, 54, 56, 58, 58, 61, 63, 64, 68, 69, 69, 71, 71, 71, 72, 73, 74, 75, 82, 86, 86, 87, 90, 96, 97, 98}, 25, 8964536953959); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumSumTwoNumbersFormedDigitsArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 4183488835, \"inputs\": {\"arr\": [3, 4, 5, 10, 14, 16, 18, 42, 43, 43, 45, 46, 51, 52, 53, 58, 61, 66, 79, 81, 82, 84], \"n\": 19}}, {\"idx\": 1, \"outputs\": -107220607602444, \"inputs\": {\"arr\": [-90, -86, -76, -50, -46, -30, -26, -22, -22, -20, -2, -2, 8, 22, 32, 40, 48, 48, 56, 58, 60, 76, 82, 82, 94, 98], \"n\": 25}}, {\"idx\": 2, \"outputs\": 1222222, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 23}}, {\"idx\": 3, \"outputs\": 45, \"inputs\": {\"arr\": [45, 79], \"n\": 1}}, {\"idx\": 4, \"outputs\": -10095534, \"inputs\": {\"arr\": [-90, -68, -38, -34, -4, 6, 10, 28, 48, 52, 54, 68, 88, 90], \"n\": 11}}, {\"idx\": 5, \"outputs\": 122222, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 22}}, {\"idx\": 6, \"outputs\": 615688689, \"inputs\": {\"arr\": [4, 8, 8, 23, 26, 27, 30, 42, 44, 55, 59, 64, 67, 69, 74, 77, 82, 82, 87, 96, 97], \"n\": 17}}, {\"idx\": 7, \"outputs\": -214463225281903248, \"inputs\": {\"arr\": [-98, -98, -86, -82, -76, -76, -66, -64, -62, -60, -48, -46, -42, -36, -36, -32, -28, -18, -18, -4, 0, 0, 2, 4, 10, 18, 30, 46, 50, 52, 62, 70, 72, 76, 80, 88, 88, 94, 96], \"n\": 32}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 6}}, {\"idx\": 9, \"outputs\": 8964536953959, \"inputs\": {\"arr\": [7, 8, 9, 9, 14, 14, 16, 17, 22, 24, 32, 32, 36, 38, 42, 42, 43, 45, 47, 53, 54, 56, 58, 58, 61, 63, 64, 68, 69, 69, 71, 71, 71, 72, 73, 74, 75, 82, 86, 86, 87, 90, 96, 97, 98], \"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
]
} |
364 | Minimum Sum Two Numbers Formed Digits Array 2 | C++ | long long minimumSumTwoNumbersFormedDigitsArray2(vector<int> a, int n) { | [
"a",
"n"
] | def minimum_sum_two_numbers_formed_digits_array_2(a, n):
a = sorted(a)
(num1, num2) = (0, 0)
for i in range(n):
if ((i % 2) == 0):
num1 = ((num1 * 10) + a[i])
else:
num2 = ((num2 * 10) + a[i])
return (num2 + num1) | int minimum_sum_two_numbers_formed_digits_array_2(vector<int> a, int n) {
sort(a.begin(), a.end());
int num1 = 0;
int num2 = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( i % 2 == 0 ) num1 = num1 * 10 + a [ i ];
else num2 = num2 * 10 + a [ i ];
}
return num2 + num1;
} | {
"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, long long 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({4, 16, 29, 30, 38, 83}, 5, 918); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58, 74, -28, -60, -6, 66, -76, 46, 0, -24, 28, -16, -14, 24, -94, -56, -80, 40, -18, -68, -8, -94, -88, -12, -20, -8}, 16, -2063616120); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 12, 78, 8}, 3, 90); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, -48, -48, -26, 8, 34}, 4, -1334); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0}, 27, 2222222); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 5, 7, 25, 30, 31, 38, 42, 45, 52, 53, 56, 59, 60, 71, 74, 76, 80, 90, 91, 98}, 13, 3190079); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1}, 8, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({59, 9, 3, 20, 83, 87, 48, 4, 86, 67, 89, 96, 17, 36, 39, 45, 99, 8, 56, 92, 63, 81, 7, 75, 32, 10, 71, 82, 97, 92, 65, 23, 22, 47, 70, 79, 57, 81, 65, 50}, 35, 430183530665338166); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumSumTwoNumbersFormedDigitsArray2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 918, \"inputs\": {\"a\": [4, 16, 29, 30, 38, 83], \"n\": 5}}, {\"idx\": 1, \"outputs\": -2063616120, \"inputs\": {\"a\": [58, 74, -28, -60, -6, 66, -76, 46, 0, -24, 28, -16, -14, 24, -94, -56, -80, 40, -18, -68, -8, -94, -88, -12, -20, -8], \"n\": 16}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": [0, 1], \"n\": 1}}, {\"idx\": 3, \"outputs\": 90, \"inputs\": {\"a\": [7, 12, 78, 8], \"n\": 3}}, {\"idx\": 4, \"outputs\": -1334, \"inputs\": {\"a\": [-78, -48, -48, -26, 8, 34], \"n\": 4}}, {\"idx\": 5, \"outputs\": 2222222, \"inputs\": {\"a\": [1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0], \"n\": 27}}, {\"idx\": 6, \"outputs\": 3190079, \"inputs\": {\"a\": [2, 3, 5, 7, 25, 30, 31, 38, 42, 45, 52, 53, 56, 59, 60, 71, 74, 76, 80, 90, 91, 98], \"n\": 13}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 1, 1, 1], \"n\": 8}}, {\"idx\": 8, \"outputs\": 430183530665338166, \"inputs\": {\"a\": [59, 9, 3, 20, 83, 87, 48, 4, 86, 67, 89, 96, 17, 36, 39, 45, 99, 8, 56, 92, 63, 81, 7, 75, 32, 10, 71, 82, 97, 92, 65, 23, 22, 47, 70, 79, 57, 81, 65, 50], \"n\": 35}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
365 | Minimum Time To Finish Tasks Without Skipping Two Consecutive | C++ | int minimumTimeToFinishTasksWithoutSkippingTwoConsecutive(vector<int> arr, int n) { | [
"arr",
"n"
] | def minimum_time_to_finish_tasks_without_skipping_two_consecutive(arr, n):
if (n <= 0):
return 0
incl = arr[0]
excl = 0
for i in range(1, n):
incl_new = (arr[i] + min(excl, incl))
excl_new = incl
incl = incl_new
excl = excl_new
return min(incl, excl) | int minimum_time_to_finish_tasks_without_skipping_two_consecutive(vector<int> arr, int n) {
if ( n <= 0 ) return 0;
int incl = arr [ 0 ];
int excl = 0;
for ( int i = 1;
i < n;
i ++ ) {
int incl_new = arr [ i ] + min ( excl, incl );
int excl_new = incl;
incl = incl_new;
excl = excl_new;
}
return min ( incl, excl );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 17, 25, 27, 29, 30, 34, 49, 72, 75, 90, 93, 93, 94}, 8, 93); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-70, -32, 62, 0, -10, 92, -94, -86, 52, 6, -26, -92, -10, 70, -82, 28, 86, 58, 86, -58, 84, -80, -18, -92, -34, 6, 34, 36, 70, -50, -6, -54, 84, 22, 30, -96, -84, 72, 2, 26, -20, 4, 48, -98, 62, -28, -68}, 36, -834); \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}, 21, 5); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({34, 40, 92, 35, 29, 26, 12, 66, 7, 28, 86, 4, 35, 79, 1, 48, 41, 47, 15, 75, 45, 6, 3, 94, 39, 50, 20, 8, 58, 51, 83, 44, 53, 76, 19, 84, 68, 54, 36, 53}, 29, 359); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -92, -92, -88, -82, -74, -70, -68, -68, -64, -60, -52, -52, -42, -42, -38, -36, -36, -34, -26, -24, -22, -12, -2, -2, 4, 6, 44, 44, 48, 54, 62, 62, 64, 74, 78, 82, 86, 86, 90, 90, 94}, 36, -1152); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 1, 0, 0, 1, 1, 1}, 5, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9, 15, 19, 29, 30, 39, 40, 61}, 4, 28); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({92, 0, 46, 70, -60, -50, 58, -56, 8, -90, 84, 16, 40, -62, 50, 78, 26, -42, -40, 98, -52, 62, 16, -62, -76, -70, -60, 32, 4, -68, 52, -64, 70, 12, -10}, 21, -314); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1, 1}, 5, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32, 96, 63, 93, 53, 1, 22, 19, 50, 74, 6, 94, 81, 85, 4, 86, 88, 75, 94}, 18, 397); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumTimeToFinishTasksWithoutSkippingTwoConsecutive",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 93, \"inputs\": {\"arr\": [5, 17, 25, 27, 29, 30, 34, 49, 72, 75, 90, 93, 93, 94], \"n\": 8}}, {\"idx\": 1, \"outputs\": -834, \"inputs\": {\"arr\": [-70, -32, 62, 0, -10, 92, -94, -86, 52, 6, -26, -92, -10, 70, -82, 28, 86, 58, 86, -58, 84, -80, -18, -92, -34, 6, 34, 36, 70, -50, -6, -54, 84, 22, 30, -96, -84, 72, 2, 26, -20, 4, 48, -98, 62, -28, -68], \"n\": 36}}, {\"idx\": 2, \"outputs\": 5, \"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\": 21}}, {\"idx\": 3, \"outputs\": 359, \"inputs\": {\"arr\": [34, 40, 92, 35, 29, 26, 12, 66, 7, 28, 86, 4, 35, 79, 1, 48, 41, 47, 15, 75, 45, 6, 3, 94, 39, 50, 20, 8, 58, 51, 83, 44, 53, 76, 19, 84, 68, 54, 36, 53], \"n\": 29}}, {\"idx\": 4, \"outputs\": -1152, \"inputs\": {\"arr\": [-98, -98, -92, -92, -88, -82, -74, -70, -68, -68, -64, -60, -52, -52, -42, -42, -38, -36, -36, -34, -26, -24, -22, -12, -2, -2, 4, 6, 44, 44, 48, 54, 62, 62, 64, 74, 78, 82, 86, 86, 90, 90, 94], \"n\": 36}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 0, 0, 1, 0, 0, 1, 1, 1], \"n\": 5}}, {\"idx\": 6, \"outputs\": 28, \"inputs\": {\"arr\": [9, 15, 19, 29, 30, 39, 40, 61], \"n\": 4}}, {\"idx\": 7, \"outputs\": -314, \"inputs\": {\"arr\": [92, 0, 46, 70, -60, -50, 58, -56, 8, -90, 84, 16, 40, -62, 50, 78, 26, -42, -40, 98, -52, 62, 16, -62, -76, -70, -60, 32, 4, -68, 52, -64, 70, 12, -10], \"n\": 21}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1, 1], \"n\": 5}}, {\"idx\": 9, \"outputs\": 397, \"inputs\": {\"arr\": [32, 96, 63, 93, 53, 1, 22, 19, 50, 74, 6, 94, 81, 85, 4, 86, 88, 75, 94], \"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
]
} |
366 | Minimum Time Write Characters Using Insert Delete Copy Operation | C++ | int minimumTimeWriteCharactersUsingInsertDeleteCopyOperation(int n, int insrt, int remov, int cpy) { | [
"n",
"insrt",
"remov",
"cpy"
] | def minimum_time_write_characters_using_insert_delete_copy_operation(N, insrt, remov, cpy):
if (N == 0):
return 0
if (N == 1):
return insrt
dp = ([0] * (N + 1))
for i in range(1, (N + 1)):
if ((i % 2) == 0):
dp[i] = min((dp[(i - 1)] + insrt), (dp[(i // 2)] + cpy))
else:
dp[i] = min((dp[(i - 1)] + insrt), ((dp[((i + 1) // 2)] + cpy) + remov))
return dp[N] | int minimum_time_write_characters_using_insert_delete_copy_operation(int N, int insert, int remove, int copy) {
if ( N == 0 ) return 0;
if ( N == 1 ) return insert;
int dp [ N + 1 ];
memset ( dp, 0, sizeof ( dp ) );
for ( int i = 1;
i <= N;
i ++ ) {
if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ i / 2 ] + copy );
else dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ ( i + 1 ) / 2 ] + copy + remove );
}
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 insrt, int remov, int cpy, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, insrt, remov, cpy), 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(59, 75, 12, 45, 351); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 68, 32, 41, 382); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 55, 69, 5, 195); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 4, 41, 12, 76); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 37, 98, 55, 460); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 28, 59, 7, 147); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 53, 40, 52, 405); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 96, 50, 50, 392); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 95, 48, 84, 694); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 6, 50, 82, 244); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumTimeWriteCharactersUsingInsertDeleteCopyOperation",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 351, \"inputs\": {\"n\": 59, \"insrt\": 75, \"remov\": 12, \"cpy\": 45}}, {\"idx\": 1, \"outputs\": 382, \"inputs\": {\"n\": 66, \"insrt\": 68, \"remov\": 32, \"cpy\": 41}}, {\"idx\": 2, \"outputs\": 195, \"inputs\": {\"n\": 98, \"insrt\": 55, \"remov\": 69, \"cpy\": 5}}, {\"idx\": 3, \"outputs\": 76, \"inputs\": {\"n\": 63, \"insrt\": 4, \"remov\": 41, \"cpy\": 12}}, {\"idx\": 4, \"outputs\": 460, \"inputs\": {\"n\": 99, \"insrt\": 37, \"remov\": 98, \"cpy\": 55}}, {\"idx\": 5, \"outputs\": 147, \"inputs\": {\"n\": 45, \"insrt\": 28, \"remov\": 59, \"cpy\": 7}}, {\"idx\": 6, \"outputs\": 405, \"inputs\": {\"n\": 60, \"insrt\": 53, \"remov\": 40, \"cpy\": 52}}, {\"idx\": 7, \"outputs\": 392, \"inputs\": {\"n\": 11, \"insrt\": 96, \"remov\": 50, \"cpy\": 50}}, {\"idx\": 8, \"outputs\": 694, \"inputs\": {\"n\": 96, \"insrt\": 95, \"remov\": 48, \"cpy\": 84}}, {\"idx\": 9, \"outputs\": 244, \"inputs\": {\"n\": 54, \"insrt\": 6, \"remov\": 50, \"cpy\": 82}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
367 | Minimum Xor Value Pair | C++ | int minimumXorValuePair(vector<int> arr, int n) { | [
"arr",
"n"
] | def minimum_xor_value_pair(arr, n):
arr.sort()
min_xor = 999999
val = 0
for i in range(0, (n - 1)):
for j in range((i + 1), (n - 1)):
val = (arr[i] ^ arr[j])
min_xor = min(min_xor, val)
return min_xor | int minimum_xor_value_pair(vector<int> arr, int n) {
int min_xor = INT_MAX;
for ( int i = 0;
i < n;
i ++ ) for ( int j = i + 1;
j < n;
j ++ ) min_xor = min ( min_xor, arr [ i ] ^ arr [ j ] );
return min_xor;
} | {
"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, 5, 7, 10, 10, 11, 14, 19, 21, 24, 27, 27, 27, 28, 28, 28, 33, 34, 41, 42, 43, 48, 52, 53, 53, 59, 62, 64, 66, 71, 77, 78, 78, 79, 80, 82, 90, 97, 99, 99}, 34, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -94, -84, -70, -68, -66, -64, -58, -28, -22, -16, -14, -10, -2, 0, 8, 28, 36, 42, 50, 52, 56, 56, 56, 66, 74, 80, 80, 88, 90, 90, 90, 94}, 17, -96); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 9, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 11, 17, 23, 25, 31, 39, 42, 45, 48, 57, 60, 63, 65, 73, 73, 75, 83, 94, 96, 97, 97}, 21, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -92, -90, -88, -84, -82, -66, -64, -64, -62, -44, -42, -40, -28, -22, -12, -4, -2, 0, 4, 16, 22, 28, 34, 54, 60, 72, 74, 78, 86, 94}, 18, 0); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 36, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 6, 13, 16, 16, 17, 19, 19, 20, 22, 25, 27, 29, 34, 34, 34, 36, 38, 39, 42, 49, 49, 53, 59, 59, 71, 77, 79, 82, 83, 83, 84, 84, 86, 86, 87, 88, 93, 96}, 36, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -92, -82, -54, -50, -48, -46, -46, -28, -28, -28, -20, -14, -14, 6, 12, 14, 20, 22, 24, 36, 36, 44, 46, 70, 74, 82, 92, 96, 96}, 20, -96); \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, 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}, 39, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 11, 12, 12, 13, 17, 18, 19, 22, 23, 23, 23, 27, 32, 33, 34, 38, 42, 48, 48, 50, 51, 54, 60, 62, 64, 69, 70, 70, 75, 76, 77, 78, 79, 82, 93, 94, 96, 99}, 30, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumXorValuePair",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [4, 5, 7, 10, 10, 11, 14, 19, 21, 24, 27, 27, 27, 28, 28, 28, 33, 34, 41, 42, 43, 48, 52, 53, 53, 59, 62, 64, 66, 71, 77, 78, 78, 79, 80, 82, 90, 97, 99, 99], \"n\": 34}}, {\"idx\": 1, \"outputs\": -96, \"inputs\": {\"arr\": [-96, -94, -94, -84, -70, -68, -66, -64, -58, -28, -22, -16, -14, -10, -2, 0, 8, 28, 36, 42, 50, 52, 56, 56, 56, 66, 74, 80, 80, 88, 90, 90, 90, 94], \"n\": 17}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 9}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [10, 11, 17, 23, 25, 31, 39, 42, 45, 48, 57, 60, 63, 65, 73, 73, 75, 83, 94, 96, 97, 97], \"n\": 21}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-92, -92, -90, -88, -84, -82, -66, -64, -64, -62, -44, -42, -40, -28, -22, -12, -4, -2, 0, 4, 16, 22, 28, 34, 54, 60, 72, 74, 78, 86, 94], \"n\": 18}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 36}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [2, 2, 6, 13, 16, 16, 17, 19, 19, 20, 22, 25, 27, 29, 34, 34, 34, 36, 38, 39, 42, 49, 49, 53, 59, 59, 71, 77, 79, 82, 83, 83, 84, 84, 86, 86, 87, 88, 93, 96], \"n\": 36}}, {\"idx\": 7, \"outputs\": -96, \"inputs\": {\"arr\": [-96, -94, -92, -82, -54, -50, -48, -46, -46, -28, -28, -28, -20, -14, -14, 6, 12, 14, 20, 22, 24, 36, 36, 44, 46, 70, 74, 82, 92, 96, 96], \"n\": 20}}, {\"idx\": 8, \"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, 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\": 39}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [4, 5, 11, 12, 12, 13, 17, 18, 19, 22, 23, 23, 23, 27, 32, 33, 34, 38, 42, 48, 48, 50, 51, 54, 60, 62, 64, 69, 70, 70, 75, 76, 77, 78, 79, 82, 93, 94, 96, 99], \"n\": 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
]
} |
368 | Minimum Xor Value Pair 1 | C++ | int minimumXorValuePair1(vector<int> arr, int n) { | [
"arr",
"n"
] | def minimum_xor_value_pair_1(arr, n):
arr.sort()
minXor = int(sys.float_info.max)
val = 0
for i in range(0, (n - 1)):
val = (arr[i] ^ arr[(i + 1)])
minXor = min(minXor, val)
return minXor | int minimum_xor_value_pair_1(vector<int> arr, int n) {
sort(arr.begin(), arr.end());
int minXor = INT_MAX;
int val = 0;
for ( int i = 0;
i < n - 1;
i ++ ) {
val = arr [ i ] ^ arr [ i + 1 ];
minXor = min ( minXor, val );
}
return minXor;
} | {
"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({8, 11, 12, 27, 32, 32, 36, 56, 57, 66, 68, 70, 74, 78, 82, 83, 96}, 10, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-60, -8, 4, 38, 40, 42, 48, 66}, 7, -4); \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}, 19, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 4, 6, 7, 7, 10, 11, 12, 15, 16, 20, 24, 28, 29, 32, 36, 37, 38, 44, 48, 49, 50, 52, 57, 57, 57, 61, 63, 64, 65, 66, 67, 68, 70, 76, 78, 81, 82, 86, 87, 89, 91, 95, 95, 98}, 36, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -84, -76, -58, -40, -38, -28, -24, -20, -14, -12, 16, 20, 28, 28, 30, 40, 44, 56, 58, 60, 92, 92}, 13, -28); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 20, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 6, 19, 31, 41, 45, 49, 56, 78, 96, 98}, 6, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -84, -4, 22, 62}, 3, 10); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 10, 13, 20, 28, 29, 34, 37, 39, 42, 43, 56, 58, 65, 69, 72, 74, 83, 91, 92, 93, 99}, 14, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "minimumXorValuePair1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [8, 11, 12, 27, 32, 32, 36, 56, 57, 66, 68, 70, 74, 78, 82, 83, 96], \"n\": 10}}, {\"idx\": 1, \"outputs\": -4, \"inputs\": {\"arr\": [-60, -8, 4, 38, 40, 42, 48, 66], \"n\": 7}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 19}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [2, 3, 4, 6, 7, 7, 10, 11, 12, 15, 16, 20, 24, 28, 29, 32, 36, 37, 38, 44, 48, 49, 50, 52, 57, 57, 57, 61, 63, 64, 65, 66, 67, 68, 70, 76, 78, 81, 82, 86, 87, 89, 91, 95, 95, 98], \"n\": 36}}, {\"idx\": 4, \"outputs\": -28, \"inputs\": {\"arr\": [-88, -84, -76, -58, -40, -38, -28, -24, -20, -14, -12, 16, 20, 28, 28, 30, 40, 44, 56, 58, 60, 92, 92], \"n\": 13}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [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\": 20}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [6, 6, 19, 31, 41, 45, 49, 56, 78, 96, 98], \"n\": 6}}, {\"idx\": 7, \"outputs\": 10, \"inputs\": {\"arr\": [-90, -84, -4, 22, 62], \"n\": 3}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 21}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [7, 10, 13, 20, 28, 29, 34, 37, 39, 42, 43, 56, 58, 65, 69, 72, 74, 83, 91, 92, 93, 99], \"n\": 14}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
369 | Modular Exponentiation Power In Modular Arithmetic | C++ | int modularExponentiationPowerInModularArithmetic(int x, int y, int p) { | [
"x",
"y",
"p"
] | def modular_exponentiation_power_in_modular_arithmetic(x, y, p):
res = 1
x = (x % p)
while (y > 0):
if ((y & 1) == 1):
res = ((res * x) % p)
y = (y >> 1)
x = ((x * x) % p)
return res | int modular_exponentiation_power_in_modular_arithmetic(int x, unsigned int y, int p) {
int res = 1;
x = x % p;
while ( y > 0 ) {
if ( y & 1 ) res = ( res * x ) % p;
y = y >> 1;
x = ( x * x ) % p;
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int y, int p, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y, 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(45, 5, 68, 61); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 25, 49, 18); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 91, 44, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 61, 9, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 8, 13, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 41, 5, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 76, 20, 16); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 89, 13, 5); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 42, 45, 19); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 63, 56, 29); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "modularExponentiationPowerInModularArithmetic",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 61, \"inputs\": {\"x\": 45, \"y\": 5, \"p\": 68}}, {\"idx\": 1, \"outputs\": 18, \"inputs\": {\"x\": 67, \"y\": 25, \"p\": 49}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"x\": 26, \"y\": 91, \"p\": 44}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"x\": 33, \"y\": 61, \"p\": 9}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"x\": 35, \"y\": 8, \"p\": 13}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"x\": 68, \"y\": 41, \"p\": 5}}, {\"idx\": 6, \"outputs\": 16, \"inputs\": {\"x\": 14, \"y\": 76, \"p\": 20}}, {\"idx\": 7, \"outputs\": 5, \"inputs\": {\"x\": 5, \"y\": 89, \"p\": 13}}, {\"idx\": 8, \"outputs\": 19, \"inputs\": {\"x\": 23, \"y\": 42, \"p\": 45}}, {\"idx\": 9, \"outputs\": 29, \"inputs\": {\"x\": 37, \"y\": 63, \"p\": 56}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
370 | Modulus Two Float Double Numbers | C++ | double modulusTwoFloatDoubleNumbers(double a, double b) { | [
"a",
"b"
] | def modulus_two_float_double_numbers(a, b):
if (a < 0):
a = (- a)
if (b < 0):
b = (- b)
mod = a
while (mod >= b):
mod = (mod - b)
if (a < 0):
return (- mod)
return mod | double modulus_two_float_double_numbers(double a, double b) {
double mod;
if ( a < 0 ) mod = - a;
else mod = a;
if ( b < 0 ) b = - b;
while ( mod >= b ) mod = mod - b;
if ( a < 0 ) return - mod;
return mod;
} | {
"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(3243.229719038493, 5659.926861939672, 3243.229719038493); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-4362.665881044217, -9196.507113304497, 4362.665881044217); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7255.066257575837, 2623.200060506935, 2008.6661365619666); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6929.554320261099, -3009.0234530313287, 911.5074141984414); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3569.942027998315, 6920.809419868375, 3569.942027998315); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-6513.849053096595, -70.95992406437102, 56.49596323882673); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7333.183189243961, 580.3500610971768, 368.98245607783906); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-2856.1752826258803, -9625.97442825802, 2856.1752826258803); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9787.228111241662, 2419.6844962423256, 108.4901262723597); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-1722.873699288031, -8370.700544254058, 1722.873699288031); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "modulusTwoFloatDoubleNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3243.229719038493, \"inputs\": {\"a\": 3243.229719038493, \"b\": 5659.926861939672}}, {\"idx\": 1, \"outputs\": 4362.665881044217, \"inputs\": {\"a\": -4362.665881044217, \"b\": -9196.507113304497}}, {\"idx\": 2, \"outputs\": 2008.6661365619666, \"inputs\": {\"a\": 7255.066257575837, \"b\": 2623.200060506935}}, {\"idx\": 3, \"outputs\": 911.5074141984414, \"inputs\": {\"a\": -6929.554320261099, \"b\": -3009.0234530313287}}, {\"idx\": 4, \"outputs\": 3569.942027998315, \"inputs\": {\"a\": 3569.942027998315, \"b\": 6920.809419868375}}, {\"idx\": 5, \"outputs\": 56.49596323882673, \"inputs\": {\"a\": -6513.849053096595, \"b\": -70.95992406437102}}, {\"idx\": 6, \"outputs\": 368.98245607783906, \"inputs\": {\"a\": 7333.183189243961, \"b\": 580.3500610971768}}, {\"idx\": 7, \"outputs\": 2856.1752826258803, \"inputs\": {\"a\": -2856.1752826258803, \"b\": -9625.97442825802}}, {\"idx\": 8, \"outputs\": 108.4901262723597, \"inputs\": {\"a\": 9787.228111241662, \"b\": 2419.6844962423256}}, {\"idx\": 9, \"outputs\": 1722.873699288031, \"inputs\": {\"a\": -1722.873699288031, \"b\": -8370.700544254058}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
371 | Multiply An Integer With 3 5 | C++ | int multiplyAnIntegerWith35(int x) { | [
"x"
] | def multiply_an_integer_with_3_5(x):
return (((x << 1) + x) + (x >> 1)) | int multiply_an_integer_with_3_5(int x) {
return ( x << 1 ) + x + ( x >> 1 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int 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(58, 203); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 56); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 287); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 115); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 308); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 178); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 283); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 133); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 276); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 311); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "multiplyAnIntegerWith35",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 203, \"inputs\": {\"x\": 58}}, {\"idx\": 1, \"outputs\": 56, \"inputs\": {\"x\": 16}}, {\"idx\": 2, \"outputs\": 287, \"inputs\": {\"x\": 82}}, {\"idx\": 3, \"outputs\": 115, \"inputs\": {\"x\": 33}}, {\"idx\": 4, \"outputs\": 308, \"inputs\": {\"x\": 88}}, {\"idx\": 5, \"outputs\": 178, \"inputs\": {\"x\": 51}}, {\"idx\": 6, \"outputs\": 283, \"inputs\": {\"x\": 81}}, {\"idx\": 7, \"outputs\": 133, \"inputs\": {\"x\": 38}}, {\"idx\": 8, \"outputs\": 276, \"inputs\": {\"x\": 79}}, {\"idx\": 9, \"outputs\": 311, \"inputs\": {\"x\": 89}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
372 | Multiply Large Integers Under Large Modulo | C++ | int multiplyLargeIntegersUnderLargeModulo(int a, int b, int mod_arg2) { | [
"a",
"b",
"mod_arg2"
] | def multiply_large_integers_under_large_modulo(a, b, mod):
res = 0
a = (a % mod)
while b:
if (b & 1):
res = ((res + a) % mod)
a = ((2 * a) % mod)
b >>= 1
return res | long long multiply_large_integers_under_large_modulo(long long a, long long b, long long mod) {
long long res = 0;
a %= mod;
while ( b ) {
if ( b & 1 ) res = ( res + a ) % mod;
a = ( 2 * a ) % mod;
b >>= 1;
}
return res;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int mod_arg2, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, mod_arg2), 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, 24, 58, 48); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 43, 29, 6); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 50, 71, 58); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 1, 66, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 35, 73, 43); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 97, 8, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 78, 55, 19); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 73, 22, 19); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 92, 83, 34); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 64, 83, 25); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "multiplyLargeIntegersUnderLargeModulo",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 48, \"inputs\": {\"a\": 60, \"b\": 24, \"mod_arg2\": 58}}, {\"idx\": 1, \"outputs\": 6, \"inputs\": {\"a\": 46, \"b\": 43, \"mod_arg2\": 29}}, {\"idx\": 2, \"outputs\": 58, \"inputs\": {\"a\": 4, \"b\": 50, \"mod_arg2\": 71}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"a\": 67, \"b\": 1, \"mod_arg2\": 66}}, {\"idx\": 4, \"outputs\": 43, \"inputs\": {\"a\": 93, \"b\": 35, \"mod_arg2\": 73}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"a\": 89, \"b\": 97, \"mod_arg2\": 8}}, {\"idx\": 6, \"outputs\": 19, \"inputs\": {\"a\": 8, \"b\": 78, \"mod_arg2\": 55}}, {\"idx\": 7, \"outputs\": 19, \"inputs\": {\"a\": 53, \"b\": 73, \"mod_arg2\": 22}}, {\"idx\": 8, \"outputs\": 34, \"inputs\": {\"a\": 96, \"b\": 92, \"mod_arg2\": 83}}, {\"idx\": 9, \"outputs\": 25, \"inputs\": {\"a\": 38, \"b\": 64, \"mod_arg2\": 83}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
374 | Next Power Of 2 | C++ | int nextPowerOf2(int n) { | [
"n"
] | def next_power_of_2(n):
count = 0
if (n and (not (n & (n - 1)))):
return n
while (n != 0):
n >>= 1
count += 1
return (1 << count) | unsigned int next_power_of_2(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(74, 128); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 128); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 128); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 128); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 128); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 32); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 128); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 128); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 64); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 64); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nextPowerOf2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 128, \"inputs\": {\"n\": 74}}, {\"idx\": 1, \"outputs\": 128, \"inputs\": {\"n\": 70}}, {\"idx\": 2, \"outputs\": 128, \"inputs\": {\"n\": 85}}, {\"idx\": 3, \"outputs\": 128, \"inputs\": {\"n\": 78}}, {\"idx\": 4, \"outputs\": 128, \"inputs\": {\"n\": 71}}, {\"idx\": 5, \"outputs\": 32, \"inputs\": {\"n\": 32}}, {\"idx\": 6, \"outputs\": 128, \"inputs\": {\"n\": 97}}, {\"idx\": 7, \"outputs\": 128, \"inputs\": {\"n\": 90}}, {\"idx\": 8, \"outputs\": 64, \"inputs\": {\"n\": 64}}, {\"idx\": 9, \"outputs\": 64, \"inputs\": {\"n\": 48}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
375 | Next Power Of 2 1 | C++ | int nextPowerOf21(int n) { | [
"n"
] | def next_power_of_2_1(n):
p = 1
if (n and (not (n & (n - 1)))):
return n
while (p < n):
p <<= 1
return p | unsigned int next_power_of_2_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(8, 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 128); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 32); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 64); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 32); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 8); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 128); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 32); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 8); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nextPowerOf21",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"n\": 8}}, {\"idx\": 1, \"outputs\": 128, \"inputs\": {\"n\": 79}}, {\"idx\": 2, \"outputs\": 32, \"inputs\": {\"n\": 31}}, {\"idx\": 3, \"outputs\": 64, \"inputs\": {\"n\": 63}}, {\"idx\": 4, \"outputs\": 32, \"inputs\": {\"n\": 18}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": 2}}, {\"idx\": 6, \"outputs\": 8, \"inputs\": {\"n\": 6}}, {\"idx\": 7, \"outputs\": 128, \"inputs\": {\"n\": 85}}, {\"idx\": 8, \"outputs\": 32, \"inputs\": {\"n\": 29}}, {\"idx\": 9, \"outputs\": 8, \"inputs\": {\"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
]
} |
376 | Next Power Of 2 2 | C++ | int nextPowerOf22(int n) { | [
"n"
] | def next_power_of_2_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 next_power_of_2_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(63, 64); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 128); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 16); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 8); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 64); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 128); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 64); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 128); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 128); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 32); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nextPowerOf22",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 64, \"inputs\": {\"n\": 63}}, {\"idx\": 1, \"outputs\": 128, \"inputs\": {\"n\": 78}}, {\"idx\": 2, \"outputs\": 16, \"inputs\": {\"n\": 13}}, {\"idx\": 3, \"outputs\": 8, \"inputs\": {\"n\": 5}}, {\"idx\": 4, \"outputs\": 64, \"inputs\": {\"n\": 34}}, {\"idx\": 5, \"outputs\": 128, \"inputs\": {\"n\": 69}}, {\"idx\": 6, \"outputs\": 64, \"inputs\": {\"n\": 63}}, {\"idx\": 7, \"outputs\": 128, \"inputs\": {\"n\": 78}}, {\"idx\": 8, \"outputs\": 128, \"inputs\": {\"n\": 80}}, {\"idx\": 9, \"outputs\": 32, \"inputs\": {\"n\": 19}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
377 | Non Repeating Element | C++ | int nonRepeatingElement(vector<int> arr, int n) { | [
"arr",
"n"
] | def non_repeating_element(arr, n):
for i in range(n):
j = 0
while (j < n):
if ((i != j) and (arr[i] == arr[j])):
break
j += 1
if (j == n):
return arr[i]
return (- 1) | int non_repeating_element(vector<int> arr, int n) {
for ( int i = 0;
i < n;
i ++ ) {
int j;
for ( j = 0;
j < n;
j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break;
if ( j == n ) return arr [ 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 expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 2, 3, 4, 6, 6, 7, 9, 10, 13, 16, 23, 30, 32, 36, 42, 42, 43, 44, 47, 48, 48, 49, 52, 52, 53, 55, 56, 58, 59, 60, 60, 63, 67, 68, 68, 74, 75, 76, 80, 81, 81, 83, 83, 86, 87, 91, 92, 97}, 47, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -46, -86, 56, -72, 50, 18, 8, 50}, 8, -96); \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, 1}, 14, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({19, 10, 49, 40, 34, 21, 63, 51}, 5, 19); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -96, -90, -88, -88, -84, -80, -76, -68, -64, -64, -52, -52, -52, -52, -50, -50, -48, -48, -40, -32, -26, -24, -22, -20, -14, -12, 0, 6, 8, 10, 20, 24, 28, 34, 36, 54, 60, 60, 60, 68, 74, 74, 74, 84, 88, 94}, 27, -90); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0}, 19, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 3, 10, 15, 21, 28, 36, 41, 44, 45, 47, 72, 77, 77, 79, 85}, 15, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({42, -84, 42, 36, -10, 24, -62, 60}, 7, -84); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 35, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 21, 42, 92, 65, 62, 75, 43, 81, 17, 92, 86, 37, 63, 27, 97, 24, 61, 85, 49, 84, 7, 14, 19, 60, 55, 68, 79, 8, 12, 75, 12, 92, 79, 42}, 27, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nonRepeatingElement",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [1, 2, 3, 4, 6, 6, 7, 9, 10, 13, 16, 23, 30, 32, 36, 42, 42, 43, 44, 47, 48, 48, 49, 52, 52, 53, 55, 56, 58, 59, 60, 60, 63, 67, 68, 68, 74, 75, 76, 80, 81, 81, 83, 83, 86, 87, 91, 92, 97], \"n\": 47}}, {\"idx\": 1, \"outputs\": -96, \"inputs\": {\"arr\": [-96, -46, -86, 56, -72, 50, 18, 8, 50], \"n\": 8}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 14}}, {\"idx\": 3, \"outputs\": 19, \"inputs\": {\"arr\": [19, 10, 49, 40, 34, 21, 63, 51], \"n\": 5}}, {\"idx\": 4, \"outputs\": -90, \"inputs\": {\"arr\": [-96, -96, -90, -88, -88, -84, -80, -76, -68, -64, -64, -52, -52, -52, -52, -50, -50, -48, -48, -40, -32, -26, -24, -22, -20, -14, -12, 0, 6, 8, 10, 20, 24, 28, 34, 36, 54, 60, 60, 60, 68, 74, 74, 74, 84, 88, 94], \"n\": 27}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0], \"n\": 19}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [1, 2, 3, 10, 15, 21, 28, 36, 41, 44, 45, 47, 72, 77, 77, 79, 85], \"n\": 15}}, {\"idx\": 7, \"outputs\": -84, \"inputs\": {\"arr\": [42, -84, 42, 36, -10, 24, -62, 60], \"n\": 7}}, {\"idx\": 8, \"outputs\": -1, \"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], \"n\": 35}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr\": [2, 21, 42, 92, 65, 62, 75, 43, 81, 17, 92, 86, 37, 63, 27, 97, 24, 61, 85, 49, 84, 7, 14, 19, 60, 55, 68, 79, 8, 12, 75, 12, 92, 79, 42], \"n\": 27}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
378 | Nth Even Length Palindrome | C++ | string nthEvenLengthPalindrome(string n) { | [
"n"
] | def nth_even_length_palindrome(n):
res = n
for j in range((len(n) - 1), (- 1), (- 1)):
res += n[j]
return res | string nth_even_length_palindrome(string n) {
string res = n;
for ( int j = n . length ( ) - 1;
j >= 0;
-- j ) res += n [ j ];
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(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string n, string 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(\"lSUhEvxcgfI\", \"lSUhEvxcgfIIfgcxvEhUSl\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"77329283\", \"7732928338292377\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"010111111\", \"010111111111111010\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Stazb\", \"StazbbzatS\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0702\", \"07022070\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01111111\", \"0111111111111110\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"a\", \"aa\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"rznb\", \"rznbbnzr\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nthEvenLengthPalindrome",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": \"lSUhEvxcgfIIfgcxvEhUSl\", \"inputs\": {\"n\": \"lSUhEvxcgfI\"}}, {\"idx\": 1, \"outputs\": \"7732928338292377\", \"inputs\": {\"n\": \"77329283\"}}, {\"idx\": 2, \"outputs\": \"010111111111111010\", \"inputs\": {\"n\": \"010111111\"}}, {\"idx\": 3, \"outputs\": \"StazbbzatS\", \"inputs\": {\"n\": \"Stazb\"}}, {\"idx\": 4, \"outputs\": \"07022070\", \"inputs\": {\"n\": \"0702\"}}, {\"idx\": 5, \"outputs\": \"0111111111111110\", \"inputs\": {\"n\": \"01111111\"}}, {\"idx\": 6, \"outputs\": \"aa\", \"inputs\": {\"n\": \"a\"}}, {\"idx\": 7, \"outputs\": \"rznbbnzr\", \"inputs\": {\"n\": \"rznb\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
379 | Nth Non Fibonacci Number | C++ | int nthNonFibonacciNumber(int n) { | [
"n"
] | def nth_non_fibonacci_number(n):
prevPrev = 1
prev = 2
curr = 3
while (n > 0):
prevPrev = prev
prev = curr
curr = (prevPrev + prev)
n = (n - ((curr - prev) - 1))
n = (n + ((curr - prev) - 1))
return (prev + n) | int nth_non_fibonacci_number(int n) {
int prevPrev = 1, prev = 2, curr = 3;
while ( n > 0 ) {
prevPrev = prev;
prev = curr;
curr = prevPrev + prev;
n = n - ( curr - prev - 1 );
}
n = n + ( curr - prev - 1 );
return prev + 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(76, 85); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 101); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 71); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 74); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 93); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 66); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 85); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 11); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 6); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 96); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nthNonFibonacciNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 85, \"inputs\": {\"n\": 76}}, {\"idx\": 1, \"outputs\": 101, \"inputs\": {\"n\": 91}}, {\"idx\": 2, \"outputs\": 71, \"inputs\": {\"n\": 62}}, {\"idx\": 3, \"outputs\": 74, \"inputs\": {\"n\": 65}}, {\"idx\": 4, \"outputs\": 93, \"inputs\": {\"n\": 83}}, {\"idx\": 5, \"outputs\": 66, \"inputs\": {\"n\": 57}}, {\"idx\": 6, \"outputs\": 85, \"inputs\": {\"n\": 76}}, {\"idx\": 7, \"outputs\": 11, \"inputs\": {\"n\": 6}}, {\"idx\": 8, \"outputs\": 6, \"inputs\": {\"n\": 2}}, {\"idx\": 9, \"outputs\": 96, \"inputs\": {\"n\": 86}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
380 | Nth Pentagonal Number | C++ | float nthPentagonalNumber(int n) { | [
"n"
] | def nth_pentagonal_number(n):
return ((((3 * n) * n) - n) / 2) | int nth_pentagonal_number(int n) {
return ( 3 * n * n - 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(96, 13776.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 12927.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 330.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 92.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 651.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 287.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 176.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 9322.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 852.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 13207.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nthPentagonalNumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 13776.0, \"inputs\": {\"n\": 96}}, {\"idx\": 1, \"outputs\": 12927.0, \"inputs\": {\"n\": 93}}, {\"idx\": 2, \"outputs\": 330.0, \"inputs\": {\"n\": 15}}, {\"idx\": 3, \"outputs\": 92.0, \"inputs\": {\"n\": 8}}, {\"idx\": 4, \"outputs\": 651.0, \"inputs\": {\"n\": 21}}, {\"idx\": 5, \"outputs\": 287.0, \"inputs\": {\"n\": 14}}, {\"idx\": 6, \"outputs\": 176.0, \"inputs\": {\"n\": 11}}, {\"idx\": 7, \"outputs\": 9322.0, \"inputs\": {\"n\": 79}}, {\"idx\": 8, \"outputs\": 852.0, \"inputs\": {\"n\": 24}}, {\"idx\": 9, \"outputs\": 13207.0, \"inputs\": {\"n\": 94}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
381 | Number Days Tank Will Become Empty | C++ | int numberDaysTankWillBecomeEmpty(int c, int l) { | [
"c",
"l"
] | def number_days_tank_will_become_empty(C, l):
if (l >= C):
return C
eq_root = ((math.sqrt((1 + (8 * (C - l)))) - 1) / 2)
return (math.ceil(eq_root) + l) | int number_days_tank_will_become_empty(int C, int l) {
if ( l >= C ) return C;
double eq_root = ( std :: sqrt ( 1 + 8 * ( C - l ) ) - 1 ) / 2;
return std :: ceil ( eq_root ) + l;
} | {
"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 c, int l, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(c, l), 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, 29, 40); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 55, 64); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 56, 11); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 56, 23); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 97, 12); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 64, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 5, 10); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 37, 14); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 55, 13); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 99, 36); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberDaysTankWillBecomeEmpty",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 40, \"inputs\": {\"c\": 91, \"l\": 29}}, {\"idx\": 1, \"outputs\": 64, \"inputs\": {\"c\": 99, \"l\": 55}}, {\"idx\": 2, \"outputs\": 11, \"inputs\": {\"c\": 11, \"l\": 56}}, {\"idx\": 3, \"outputs\": 23, \"inputs\": {\"c\": 23, \"l\": 56}}, {\"idx\": 4, \"outputs\": 12, \"inputs\": {\"c\": 12, \"l\": 97}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"c\": 1, \"l\": 64}}, {\"idx\": 6, \"outputs\": 10, \"inputs\": {\"c\": 18, \"l\": 5}}, {\"idx\": 7, \"outputs\": 14, \"inputs\": {\"c\": 14, \"l\": 37}}, {\"idx\": 8, \"outputs\": 13, \"inputs\": {\"c\": 13, \"l\": 55}}, {\"idx\": 9, \"outputs\": 36, \"inputs\": {\"c\": 36, \"l\": 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
]
} |
382 | Number Digits Product Two Numbers | C++ | int numberDigitsProductTwoNumbers(int a, int b) { | [
"a",
"b"
] | def number_digits_product_two_numbers(a, b):
count = 0
p = abs((a * b))
if (p == 0):
return 1
while (p > 0):
count = (count + 1)
p = (p // 10)
return count | int number_digits_product_two_numbers(int a, int b) {
int count = 0;
int p = abs ( a * b );
if ( p == 0 ) return 1;
while ( p > 0 ) {
count ++;
p = p / 10;
}
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int 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(86, 39, 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 87, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 84, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 80, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 20, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 70, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 13, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 83, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 55, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 46, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberDigitsProductTwoNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"a\": 86, \"b\": 39}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"a\": 81, \"b\": 87}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"a\": 48, \"b\": 84}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"a\": 64, \"b\": 80}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"a\": 56, \"b\": 20}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"a\": 5, \"b\": 70}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"a\": 25, \"b\": 13}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"a\": 94, \"b\": 83}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"a\": 5, \"b\": 55}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"a\": 46, \"b\": 46}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
383 | Number Digits Product Two Numbers 1 | C++ | int numberDigitsProductTwoNumbers1(int a, int b) { | [
"a",
"b"
] | def number_digits_product_two_numbers_1(a, b):
if ((a == 0) or (b == 0)):
return 1
return (math.floor((math.log10(abs(a)) + math.log10(abs(b)))) + 1) | int number_digits_product_two_numbers_1(int a, int b) {
if ( a == 0 || b == 0 ) return 1;
return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 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 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(97, 91, 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 49, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 34, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 40, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 85, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 97, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 15, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 98, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 62, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 22, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberDigitsProductTwoNumbers1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"a\": 97, \"b\": 91}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"a\": 52, \"b\": 49}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"a\": 95, \"b\": 34}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"a\": 35, \"b\": 40}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"a\": 40, \"b\": 85}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"a\": 18, \"b\": 97}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"a\": 92, \"b\": 15}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"a\": 73, \"b\": 98}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"a\": 10, \"b\": 62}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"a\": 82, \"b\": 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
]
} |
384 | Number Indexes Equal Elements Given Range | C++ | int numberIndexesEqualElementsGivenRange(vector<int> a, int n, int l, int r) { | [
"a",
"n",
"l",
"r"
] | def number_indexes_equal_elements_given_range(a, n, l, r):
count = 0
for i in range(l, r):
if (a[i] == a[(i + 1)]):
count += 1
return count | int number_indexes_equal_elements_given_range(vector<int> a, int n, int l, int r) {
int count = 0;
for ( int i = l;
i < r;
i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1;
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> a, int n, int l, int r, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n, l, r), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 13, 13, 16, 16, 19, 39, 41, 48, 52, 57, 62, 65, 67, 76, 84, 88, 91, 95, 96, 97, 98}, 18, 12, 17, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({62, 76, 86, -8, 84, -6, 72, 84, 6, -50, -18, -94, 54, 90, -74, -64, -26, -14, -32, 62, 10, 4, 70, -28, 8, 18, 4, -62, -76, 84, -78, -4, 84, 98, 58, -68, 42, -6, 34, -38, 52, -84, 78}, 32, 38, 23, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 10, 6, 6, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 75, 98, 29, 62, 53, 48, 91, 86, 66, 48, 94}, 8, 6, 6, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -84, -70, -70, -40, -40, -36, -24, 10, 48, 62, 74}, 11, 7, 8, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0}, 36, 40, 37, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 6, 7, 10, 11, 13, 19, 19, 25, 29, 30, 32, 34, 35, 45, 45, 46, 47, 48, 48, 53, 58, 61, 64, 65, 67, 75, 76, 81, 81, 84, 84, 85, 86, 94, 94, 96, 99}, 25, 19, 37, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, 42, -34, -12, -86, 82, -96, -66, 30, 16, -40, 72, 84, 94, -48, -30, 26, 50, 42, -44, -50, 22, -38, 8, 34, 94, 2, 16, -32, 18, -58, 12, -26, 28, -62}, 21, 30, 26, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1}, 4, 5, 5, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 29}, 1, 1, 1, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberIndexesEqualElementsGivenRange",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"a\": [4, 13, 13, 16, 16, 19, 39, 41, 48, 52, 57, 62, 65, 67, 76, 84, 88, 91, 95, 96, 97, 98], \"n\": 18, \"l\": 12, \"r\": 17}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"a\": [62, 76, 86, -8, 84, -6, 72, 84, 6, -50, -18, -94, 54, 90, -74, -64, -26, -14, -32, 62, 10, 4, 70, -28, 8, 18, 4, -62, -76, 84, -78, -4, 84, 98, 58, -68, 42, -6, 34, -38, 52, -84, 78], \"n\": 32, \"l\": 38, \"r\": 23}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 10, \"l\": 6, \"r\": 6}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"a\": [11, 75, 98, 29, 62, 53, 48, 91, 86, 66, 48, 94], \"n\": 8, \"l\": 6, \"r\": 6}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"a\": [-94, -84, -70, -70, -40, -40, -36, -24, 10, 48, 62, 74], \"n\": 11, \"l\": 7, \"r\": 8}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0], \"n\": 36, \"l\": 40, \"r\": 37}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"a\": [1, 2, 6, 7, 10, 11, 13, 19, 19, 25, 29, 30, 32, 34, 35, 45, 45, 46, 47, 48, 48, 53, 58, 61, 64, 65, 67, 75, 76, 81, 81, 84, 84, 85, 86, 94, 94, 96, 99], \"n\": 25, \"l\": 19, \"r\": 37}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"a\": [-56, 42, -34, -12, -86, 82, -96, -66, 30, 16, -40, 72, 84, 94, -48, -30, 26, 50, 42, -44, -50, 22, -38, 8, 34, 94, 2, 16, -32, 18, -58, 12, -26, 28, -62], \"n\": 21, \"l\": 30, \"r\": 26}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 0, 1, 1, 1], \"n\": 4, \"l\": 5, \"r\": 5}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"a\": [6, 29], \"n\": 1, \"l\": 1, \"r\": 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
]
} |
385 | Number Is Divisible By 29 Or Not | C++ | bool numberIsDivisibleBy29OrNot(long long n) { | [
"n"
] | def number_is_divisible_by_29_or_not(n):
while int((n / 100)):
last_digit = int((n % 10))
n = int((n / 10))
n += (last_digit * 3)
return ((n % 29) == 0) | bool number_is_divisible_by_29_or_not(long long int n) {
while ( n / 100 ) {
int last_digit = n % 10;
n /= 10;
n += last_digit * 3;
}
return ( n % 29 == 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(long long 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(29, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(0, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1419, 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(7, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1160, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(292929002929, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberIsDivisibleBy29OrNot",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 29}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 0}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"n\": 65}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": 1419}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 54}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 7}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 44}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 34}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"n\": 1160}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"n\": 292929002929}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
386 | Number Jump Required Given Length Reach Point Form D 0 Origin 2D Plane | C++ | double numberJumpRequiredGivenLengthReachPointFormD0Origin2DPlane(int a, int b, int d) { | [
"a",
"b",
"d"
] | def number_jump_required_given_length_reach_point_form_d_0_origin_2d_plane(a, b, d):
temp = a
a = min(a, b)
b = max(temp, b)
if (d >= b):
return (((d + b) - 1) / b)
if (d == 0):
return 0
if (d == a):
return 1
return 2 | int number_jump_required_given_length_reach_point_form_d_0_origin_2d_plane(int a, int b, int d) {
int temp = a;
a = min ( a, b );
b = max ( temp, b );
if ( d >= b ) return ( d + b - 1 ) / b;
if ( d == 0 ) return 0;
if ( d == a ) return 1;
return 2;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int a, int b, int d, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, 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(35, 8, 77, 3.1714285714285713); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 55, 33, 2.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 23, 64, 3.739130434782609); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 43, 29, 2.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 64, 11, 2.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 25, 26, 2.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 4, 28, 2.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 95, 55, 2.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 13, 54, 3.3043478260869565); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 50, 71, 2.4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberJumpRequiredGivenLengthReachPointFormD0Origin2DPlane",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 3.1714285714285713, \"inputs\": {\"a\": 35, \"b\": 8, \"d\": 77}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"a\": 85, \"b\": 55, \"d\": 33}}, {\"idx\": 2, \"outputs\": 3.739130434782609, \"inputs\": {\"a\": 22, \"b\": 23, \"d\": 64}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"a\": 8, \"b\": 43, \"d\": 29}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"a\": 12, \"b\": 64, \"d\": 11}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"a\": 58, \"b\": 25, \"d\": 26}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"a\": 65, \"b\": 4, \"d\": 28}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"a\": 10, \"b\": 95, \"d\": 55}}, {\"idx\": 8, \"outputs\": 3.3043478260869565, \"inputs\": {\"a\": 23, \"b\": 13, \"d\": 54}}, {\"idx\": 9, \"outputs\": 2.4, \"inputs\": {\"a\": 5, \"b\": 50, \"d\": 71}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
387 | Number Non Negative Integral Solutions B C N | C++ | int numberNonNegativeIntegralSolutionsBCN(int n) { | [
"n"
] | def number_non_negative_integral_solutions_b_c_n(n):
result = 0
for i in range((n + 1)):
for j in range((n + 1)):
for k in range((n + 1)):
if (((i + j) + k) == n):
result += 1
return result | int number_non_negative_integral_solutions_b_c_n(int n) {
int result = 0;
for ( int i = 0;
i <= n;
i ++ ) for ( int j = 0;
j <= n - i;
j ++ ) for ( int k = 0;
k <= ( n - i - j );
k ++ ) if ( i + j + k == n ) result ++;
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(62, 2016); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 1035); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 741); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 3403); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 120); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 231); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 3003); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 2701); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 4753); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 1431); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberNonNegativeIntegralSolutionsBCN",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 2016, \"inputs\": {\"n\": 62}}, {\"idx\": 1, \"outputs\": 1035, \"inputs\": {\"n\": 44}}, {\"idx\": 2, \"outputs\": 741, \"inputs\": {\"n\": 37}}, {\"idx\": 3, \"outputs\": 3403, \"inputs\": {\"n\": 81}}, {\"idx\": 4, \"outputs\": 120, \"inputs\": {\"n\": 14}}, {\"idx\": 5, \"outputs\": 231, \"inputs\": {\"n\": 20}}, {\"idx\": 6, \"outputs\": 3003, \"inputs\": {\"n\": 76}}, {\"idx\": 7, \"outputs\": 2701, \"inputs\": {\"n\": 72}}, {\"idx\": 8, \"outputs\": 4753, \"inputs\": {\"n\": 96}}, {\"idx\": 9, \"outputs\": 1431, \"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
]
} |
388 | Number Non Negative Integral Solutions B C N 1 | C++ | int numberNonNegativeIntegralSolutionsBCN1(int n) { | [
"n"
] | def number_non_negative_integral_solutions_b_c_n_1(n):
return int((((n + 1) * (n + 2)) / 2)) | int number_non_negative_integral_solutions_b_c_n_1(int n) {
return ( ( n + 1 ) * ( n + 2 ) ) / 2;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int 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, 903); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 2701); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 1540); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 2926); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 3916); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 903); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 3160); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 3321); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 1128); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 55); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberNonNegativeIntegralSolutionsBCN1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 903, \"inputs\": {\"n\": 41}}, {\"idx\": 1, \"outputs\": 2701, \"inputs\": {\"n\": 72}}, {\"idx\": 2, \"outputs\": 1540, \"inputs\": {\"n\": 54}}, {\"idx\": 3, \"outputs\": 2926, \"inputs\": {\"n\": 75}}, {\"idx\": 4, \"outputs\": 3916, \"inputs\": {\"n\": 87}}, {\"idx\": 5, \"outputs\": 903, \"inputs\": {\"n\": 41}}, {\"idx\": 6, \"outputs\": 3160, \"inputs\": {\"n\": 78}}, {\"idx\": 7, \"outputs\": 3321, \"inputs\": {\"n\": 80}}, {\"idx\": 8, \"outputs\": 1128, \"inputs\": {\"n\": 46}}, {\"idx\": 9, \"outputs\": 55, \"inputs\": {\"n\": 9}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
389 | Number N Digit Stepping Numbers | C++ | long long numberNDigitSteppingNumbers(int n) { | [
"n"
] | def number_n_digit_stepping_numbers(n):
dp = [[0 for x in range(10)] for y in range((n + 1))]
if (n == 1):
return 10
for j in range(10):
dp[1][j] = 1
for i in range(2, (n + 1)):
for j in range(10):
if (j == 0):
dp[i][j] = dp[(i - 1)][(j + 1)]
elif (j == 9):
dp[i][j] = dp[(i - 1)][(j - 1)]
else:
dp[i][j] = (dp[(i - 1)][(j - 1)] + dp[(i - 1)][(j + 1)])
sum = 0
for j in range(1, 10):
sum = (sum + dp[n][j])
return sum | long long number_n_digit_stepping_numbers(int n) {
int dp [ n + 1 ] [ 10 ];
if ( n == 1 ) return 10;
for ( int j = 0;
j <= 9;
j ++ ) dp [ 1 ] [ j ] = 1;
for ( int i = 2;
i <= n;
i ++ ) {
for ( int j = 0;
j <= 9;
j ++ ) {
if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ];
else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ];
else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ];
}
}
long long sum = 0;
for ( int j = 1;
j <= 9;
j ++ ) sum += dp [ n ] [ 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(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(18, 547810); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 100719775); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 1774846161206); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 2017126); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 52479500); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 2306507126768895); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 21053); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberNDigitSteppingNumbers",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 547810, \"inputs\": {\"n\": 18}}, {\"idx\": 1, \"outputs\": 100719775, \"inputs\": {\"n\": 26}}, {\"idx\": 2, \"outputs\": 1774846161206, \"inputs\": {\"n\": 41}}, {\"idx\": 3, \"outputs\": 2017126, \"inputs\": {\"n\": 20}}, {\"idx\": 4, \"outputs\": 52479500, \"inputs\": {\"n\": 25}}, {\"idx\": 5, \"outputs\": 2306507126768895, \"inputs\": {\"n\": 52}}, {\"idx\": 6, \"outputs\": 21053, \"inputs\": {\"n\": 13}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
390 | Number Of Binary Trees For Given Preorder Sequence Length | C++ | int numberOfBinaryTreesForGivenPreorderSequenceLength(int n) { | [
"n"
] | def number_of_binary_trees_for_given_preorder_sequence_length(n):
BT = ([0] * (n + 1))
BT[0] = BT[1] = 1
for i in range(2, (n + 1)):
for j in range(i):
BT[i] += (BT[j] * BT[((i - j) - 1)])
return BT[n] | int number_of_binary_trees_for_given_preorder_sequence_length(int n) {
int BT [ n + 1 ];
memset ( BT, 0, sizeof ( BT ) );
BT [ 0 ] = BT [ 1 ] = 1;
for ( int i = 2;
i <= n;
++ i ) for ( int j = 0;
j < i;
j ++ ) BT [ i ] += BT [ j ] * BT [ i - j - 1 ];
return BT [ 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(15, 9694845); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 58786); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 58786); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 9694845); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberOfBinaryTreesForGivenPreorderSequenceLength",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 9694845, \"inputs\": {\"n\": 15}}, {\"idx\": 1, \"outputs\": 58786, \"inputs\": {\"n\": 11}}, {\"idx\": 2, \"outputs\": 58786, \"inputs\": {\"n\": 11}}, {\"idx\": 3, \"outputs\": 9694845, \"inputs\": {\"n\": 15}}]",
"test_case_ids": [
"0",
"1",
"2",
"3"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
391 | Number Of Pairs In An Array Having Sum Equal To Product | C++ | int numberOfPairsInAnArrayHavingSumEqualToProduct(vector<int> a, int n) { | [
"a",
"n"
] | def number_of_pairs_in_an_array_having_sum_equal_to_product(a, n):
zero = 0
two = 0
for i in range(n):
if (a[i] == 0):
zero += 1
if (a[i] == 2):
two += 1
cnt = (((zero * (zero - 1)) // 2) + ((two * (two - 1)) // 2))
return cnt | int number_of_pairs_in_an_array_having_sum_equal_to_product(vector<int> a, int n) {
int zero = 0, two = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( a [ i ] == 0 ) {
zero ++;
}
if ( a [ i ] == 2 ) {
two ++;
}
}
int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2;
return cnt;
} | {
"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({9, 10, 20, 26, 26, 28, 31, 34, 35, 36, 36, 37, 39, 43, 44, 44, 46, 49, 54, 57, 58, 63, 64, 64, 65, 67, 70, 70, 74, 75, 77, 78, 79, 81, 82, 83, 84, 86, 95}, 31, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, -10, 10, 0, 68, 4, -6, -14, 74, -80, 56, -4, 36, 56, 10, -16, 90, 84, -38, -40, 40, -86, -36, -16, -48, -76, -72, -18, -14, -40, -82, 56, -60}, 19, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 21); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({88, 20, 53, 21, 29, 73, 62, 91, 72, 34, 47, 42, 98, 9, 79, 80, 94, 36, 7, 67, 96, 34, 99, 56, 37, 70, 55, 36, 10, 77, 41, 51, 5, 37, 57, 29, 56, 74, 97, 31, 96, 52, 13, 29, 87, 58, 28, 31}, 38, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20}, 0, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1}, 21, 15); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, 9, 16, 22, 23, 25, 33, 33, 36, 39, 48, 49, 52, 53, 60, 67, 68, 76, 77, 79, 84, 84, 86, 89}, 24, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72}, 13, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 15); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, 15, 28, 29, 32, 16, 33, 83}, 7, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberOfPairsInAnArrayHavingSumEqualToProduct",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"a\": [9, 10, 20, 26, 26, 28, 31, 34, 35, 36, 36, 37, 39, 43, 44, 44, 46, 49, 54, 57, 58, 63, 64, 64, 65, 67, 70, 70, 74, 75, 77, 78, 79, 81, 82, 83, 84, 86, 95], \"n\": 31}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"a\": [0, -10, 10, 0, 68, 4, -6, -14, 74, -80, 56, -4, 36, 56, 10, -16, 90, 84, -38, -40, 40, -86, -36, -16, -48, -76, -72, -18, -14, -40, -82, 56, -60], \"n\": 19}}, {\"idx\": 2, \"outputs\": 21, \"inputs\": {\"a\": [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], \"n\": 22}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"a\": [88, 20, 53, 21, 29, 73, 62, 91, 72, 34, 47, 42, 98, 9, 79, 80, 94, 36, 7, 67, 96, 34, 99, 56, 37, 70, 55, 36, 10, 77, 41, 51, 5, 37, 57, 29, 56, 74, 97, 31, 96, 52, 13, 29, 87, 58, 28, 31], \"n\": 38}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"a\": [20], \"n\": 0}}, {\"idx\": 5, \"outputs\": 15, \"inputs\": {\"a\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1], \"n\": 21}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"a\": [2, 4, 9, 16, 22, 23, 25, 33, 33, 36, 39, 48, 49, 52, 53, 60, 67, 68, 76, 77, 79, 84, 84, 86, 89], \"n\": 24}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"a\": [-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72], \"n\": 13}}, {\"idx\": 8, \"outputs\": 15, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 15}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"a\": [22, 15, 28, 29, 32, 16, 33, 83], \"n\": 7}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
392 | Number Of Substrings With Odd Decimal Value In A Binary String | C++ | int numberOfSubstringsWithOddDecimalValueInABinaryString(string s) { | [
"s"
] | def number_of_substrings_with_odd_decimal_value_in_a_binary_string(s):
n = len(s)
auxArr = [0 for i in range(n)]
if (s[0] == '1'):
auxArr[0] = 1
for i in range(0, n):
if (s[i] == '1'):
auxArr[i] = (auxArr[(i - 1)] + 1)
else:
auxArr[i] = auxArr[(i - 1)]
count = 0
for i in range((n - 1), (- 1), (- 1)):
if (s[i] == '1'):
count += auxArr[i]
return count | int number_of_substrings_with_odd_decimal_value_in_a_binary_string(string s) {
int n = s . length ( );
int auxArr [ n ] = {
0 };
if ( s [ 0 ] == '1' ) auxArr [ 0 ] = 1;
for ( int i = 1;
i < n;
i ++ ) {
if ( s [ i ] == '1' ) auxArr [ i ] = auxArr [ i - 1 ] + 1;
else auxArr [ i ] = auxArr [ i - 1 ];
}
int count = 0;
for ( int i = n - 1;
i >= 0;
i -- ) if ( s [ i ] == '1' ) count += auxArr [ i ];
return count;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string s, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"OGiOkJF\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"517376\", 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Ze\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"8763644247018\", 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00111010001\", 15); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"HGwkBKUOVu\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"652\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"101000011110\", 21); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kvdpG \", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberOfSubstringsWithOddDecimalValueInABinaryString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"s\": \"OGiOkJF\"}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"s\": \"517376\"}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"s\": \"11\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"s\": \"Ze\"}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"s\": \"8763644247018\"}}, {\"idx\": 5, \"outputs\": 15, \"inputs\": {\"s\": \"00111010001\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"s\": \"HGwkBKUOVu\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"s\": \"652\"}}, {\"idx\": 8, \"outputs\": 21, \"inputs\": {\"s\": \"101000011110\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"s\": \"kvdpG \"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
393 | Number Of Triangles In A Plane If No More Than Two Points Are Collinear | C++ | int numberOfTrianglesInAPlaneIfNoMoreThanTwoPointsAreCollinear(int n) { | [
"n"
] | def number_of_triangles_in_a_plane_if_no_more_than_two_points_are_collinear(n):
return (((n * (n - 1)) * (n - 2)) // 6) | int number_of_triangles_in_a_plane_if_no_more_than_two_points_are_collinear(int n) {
return n * ( n - 1 ) * ( n - 2 ) / 6;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(67, 47905); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 30856); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 47905); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 34220); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 147440); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 84); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 560); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 91881); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 105995); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberOfTrianglesInAPlaneIfNoMoreThanTwoPointsAreCollinear",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 47905, \"inputs\": {\"n\": 67}}, {\"idx\": 1, \"outputs\": 30856, \"inputs\": {\"n\": 58}}, {\"idx\": 2, \"outputs\": 47905, \"inputs\": {\"n\": 67}}, {\"idx\": 3, \"outputs\": 34220, \"inputs\": {\"n\": 60}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"n\": 4}}, {\"idx\": 5, \"outputs\": 147440, \"inputs\": {\"n\": 97}}, {\"idx\": 6, \"outputs\": 84, \"inputs\": {\"n\": 9}}, {\"idx\": 7, \"outputs\": 560, \"inputs\": {\"n\": 16}}, {\"idx\": 8, \"outputs\": 91881, \"inputs\": {\"n\": 83}}, {\"idx\": 9, \"outputs\": 105995, \"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
]
} |
394 | Number Ordered Pairs Ai Aj 0 | C++ | int numberOrderedPairsAiAj0(vector<int> a, int n) { | [
"a",
"n"
] | def number_ordered_pairs_ai_aj_0(a, n):
count = 0
for i in range(0, n):
for j in range((i + 1), n):
if ((a[i] & a[j]) == 0):
count += 2
return count | int number_ordered_pairs_ai_aj_0(vector<int> a, int n) {
int count = 0;
for ( int i = 0;
i < n;
i ++ ) {
for ( int j = i + 1;
j < n;
j ++ ) if ( ( a [ i ] & a [ j ] ) == 0 ) count += 2;
}
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> 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({17, 20, 32, 35, 35, 36, 43, 47, 59, 59, 68, 69, 70, 70, 75, 82, 88, 94, 96, 99}, 17, 54); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, -40, 58, -36, 34, -12, -38, 48, -66, 16, 50, -26, -22, 46, -70, -68, -44, -52, -78, -50}, 11, 6); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 23, 506); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({49, 57, 17, 37, 56, 61, 10, 3, 33, 33, 70, 35, 50, 85, 48, 65, 83, 21, 96, 19, 66, 43, 69, 17, 60, 87, 82, 3, 83, 44, 63, 19, 55, 58, 77, 76, 50, 96}, 37, 172); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -88, -86, -80, -80, -72, -64, -60, -58, -58, -58, -50, -44, -32, -8, -8, 0, 6, 8, 10, 14, 14, 18, 28, 34, 34, 46, 54, 56, 56, 56, 64, 66, 66, 70, 82, 84, 88, 96}, 33, 266); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0}, 13, 100); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 3, 10, 11, 13, 14, 15, 17, 20, 25, 26, 26, 27, 29, 32, 36, 36, 36, 42, 46, 47, 49, 51, 54, 54, 55, 60, 66, 67, 68, 68, 68, 72, 77, 78, 79, 83, 84, 92, 98}, 32, 238); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-76, -72, 16, 38, -60, 44, -2, -76, -76, -56, 40, 36, 50, -50, -32, 48, -96, 80, 84, 60, 84, 38, -54, -42, 48, 30, 66, -62, -52, -94, 64, -16, 54, 98}, 28, 116); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1}, 5, 14); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({63, 82, 22, 84, 11, 62, 18, 43, 57, 25, 4, 27, 62, 46, 55, 16, 1, 9, 10, 73, 36, 80, 95, 87, 47, 64, 27, 25, 70}, 22, 108); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberOrderedPairsAiAj0",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 54, \"inputs\": {\"a\": [17, 20, 32, 35, 35, 36, 43, 47, 59, 59, 68, 69, 70, 70, 75, 82, 88, 94, 96, 99], \"n\": 17}}, {\"idx\": 1, \"outputs\": 6, \"inputs\": {\"a\": [-78, -40, 58, -36, 34, -12, -38, 48, -66, 16, 50, -26, -22, 46, -70, -68, -44, -52, -78, -50], \"n\": 11}}, {\"idx\": 2, \"outputs\": 506, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 23}}, {\"idx\": 3, \"outputs\": 172, \"inputs\": {\"a\": [49, 57, 17, 37, 56, 61, 10, 3, 33, 33, 70, 35, 50, 85, 48, 65, 83, 21, 96, 19, 66, 43, 69, 17, 60, 87, 82, 3, 83, 44, 63, 19, 55, 58, 77, 76, 50, 96], \"n\": 37}}, {\"idx\": 4, \"outputs\": 266, \"inputs\": {\"a\": [-94, -88, -86, -80, -80, -72, -64, -60, -58, -58, -58, -50, -44, -32, -8, -8, 0, 6, 8, 10, 14, 14, 18, 28, 34, 34, 46, 54, 56, 56, 56, 64, 66, 66, 70, 82, 84, 88, 96], \"n\": 33}}, {\"idx\": 5, \"outputs\": 100, \"inputs\": {\"a\": [1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0], \"n\": 13}}, {\"idx\": 6, \"outputs\": 238, \"inputs\": {\"a\": [1, 3, 10, 11, 13, 14, 15, 17, 20, 25, 26, 26, 27, 29, 32, 36, 36, 36, 42, 46, 47, 49, 51, 54, 54, 55, 60, 66, 67, 68, 68, 68, 72, 77, 78, 79, 83, 84, 92, 98], \"n\": 32}}, {\"idx\": 7, \"outputs\": 116, \"inputs\": {\"a\": [-76, -72, 16, 38, -60, 44, -2, -76, -76, -56, 40, 36, 50, -50, -32, 48, -96, 80, 84, 60, 84, 38, -54, -42, 48, 30, 66, -62, -52, -94, 64, -16, 54, 98], \"n\": 28}}, {\"idx\": 8, \"outputs\": 14, \"inputs\": {\"a\": [0, 0, 1, 1, 1, 1], \"n\": 5}}, {\"idx\": 9, \"outputs\": 108, \"inputs\": {\"a\": [63, 82, 22, 84, 11, 62, 18, 43, 57, 25, 4, 27, 62, 46, 55, 16, 1, 9, 10, 73, 36, 80, 95, 87, 47, 64, 27, 25, 70], \"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
]
} |
395 | Number Rectangles Nm Grid | C++ | int numberRectanglesNmGrid(int n, int m) { | [
"n",
"m"
] | def number_rectangles_nm_grid(n, m):
return ((((m * n) * (n + 1)) * (m + 1)) // 4) | int number_rectangles_nm_grid(int n, int m) {
return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4;
} | {
"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 m, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, m), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(86, 70, 9296385); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 65, 1203345); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 5, 90); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 12, 326508); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 27, 212058); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 75, 259350); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 36, 1898100); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 64, 3558880); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 51, 1690650); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 44, 9900); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberRectanglesNmGrid",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 9296385, \"inputs\": {\"n\": 86, \"m\": 70}}, {\"idx\": 1, \"outputs\": 1203345, \"inputs\": {\"n\": 33, \"m\": 65}}, {\"idx\": 2, \"outputs\": 90, \"inputs\": {\"n\": 3, \"m\": 5}}, {\"idx\": 3, \"outputs\": 326508, \"inputs\": {\"n\": 91, \"m\": 12}}, {\"idx\": 4, \"outputs\": 212058, \"inputs\": {\"n\": 33, \"m\": 27}}, {\"idx\": 5, \"outputs\": 259350, \"inputs\": {\"n\": 13, \"m\": 75}}, {\"idx\": 6, \"outputs\": 1898100, \"inputs\": {\"n\": 75, \"m\": 36}}, {\"idx\": 7, \"outputs\": 3558880, \"inputs\": {\"n\": 58, \"m\": 64}}, {\"idx\": 8, \"outputs\": 1690650, \"inputs\": {\"n\": 50, \"m\": 51}}, {\"idx\": 9, \"outputs\": 9900, \"inputs\": {\"n\": 4, \"m\": 44}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
396 | Number Subsequences Ab String Repeated K Times | C++ | float numberSubsequencesAbStringRepeatedKTimes(string s, int k) { | [
"s",
"k"
] | def number_subsequences_ab_string_repeated_k_times(s, K):
n = len(s)
c1 = 0
c2 = 0
C = 0
for i in range(n):
if (s[i] == 'a'):
c1 += 1
if (s[i] == 'b'):
c2 += 1
C += c1
return ((C * K) + ((((K * (K - 1)) / 2) * c1) * c2)) | int number_subsequences_ab_string_repeated_k_times(string s, int K) {
int n = s . length ( );
int C, c1 = 0, c2 = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( s [ i ] == 'a' ) c1 ++;
if ( s [ i ] == 'b' ) {
c2 ++;
C += c1;
}
}
return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(string s, int k, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s, 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(\"abbc\", 96, 9312.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abahk\", 7, 49.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"hugbabab\", 5, 75.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abadbc\", 60, 7260.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"nkg9\", 8, 0.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"jh7dab\", 41, 861.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abd\", 87, 3828.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aabb8yk\", 4, 40.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1111\", 18, 0.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"PFXAhr\", 8, 0.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberSubsequencesAbStringRepeatedKTimes",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 9312.0, \"inputs\": {\"s\": \"abbc\", \"k\": 96}}, {\"idx\": 1, \"outputs\": 49.0, \"inputs\": {\"s\": \"abahk\", \"k\": 7}}, {\"idx\": 2, \"outputs\": 75.0, \"inputs\": {\"s\": \"hugbabab\", \"k\": 5}}, {\"idx\": 3, \"outputs\": 7260.0, \"inputs\": {\"s\": \"abadbc\", \"k\": 60}}, {\"idx\": 4, \"outputs\": 0.0, \"inputs\": {\"s\": \"nkg9\", \"k\": 8}}, {\"idx\": 5, \"outputs\": 861.0, \"inputs\": {\"s\": \"jh7dab\", \"k\": 41}}, {\"idx\": 6, \"outputs\": 3828.0, \"inputs\": {\"s\": \"abd\", \"k\": 87}}, {\"idx\": 7, \"outputs\": 40.0, \"inputs\": {\"s\": \"aabb8yk\", \"k\": 4}}, {\"idx\": 8, \"outputs\": 0.0, \"inputs\": {\"s\": \"1111\", \"k\": 18}}, {\"idx\": 9, \"outputs\": 0.0, \"inputs\": {\"s\": \"PFXAhr\", \"k\": 8}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
397 | Number Subsequences Form Ai Bj Ck | C++ | int numberSubsequencesFormAiBjCk(string s) { | [
"s"
] | def number_subsequences_form_ai_bj_ck(s):
aCount = 0
bCount = 0
cCount = 0
for i in range(len(s)):
if (s[i] == 'a'):
aCount = (1 + (2 * aCount))
elif (s[i] == 'b'):
bCount = (aCount + (2 * bCount))
elif (s[i] == 'c'):
cCount = (bCount + (2 * cCount))
return cCount | int number_subsequences_form_ai_bj_ck(string s) {
int aCount = 0;
int bCount = 0;
int cCount = 0;
for ( unsigned int i = 0;
i < s . size ( );
i ++ ) {
if ( s [ i ] == 'a' ) aCount = ( 1 + 2 * aCount );
else if ( s [ i ] == 'b' ) bCount = ( aCount + 2 * bCount );
else if ( s [ i ] == 'c' ) cCount = ( bCount + 2 * cCount );
}
return cCount;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string s, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abbc\", 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abcabc\", 7); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"agsdbkfdc \", 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ababab\", 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aaaaaaa\", 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aabaaabcc\", 111); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"19\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1001100\", 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"DtAnuQbU\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberSubsequencesFormAiBjCk",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"s\": \"\"}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"s\": \"abbc\"}}, {\"idx\": 2, \"outputs\": 7, \"inputs\": {\"s\": \"abcabc\"}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"s\": \"agsdbkfdc \"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"s\": \"ababab\"}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"s\": \"aaaaaaa\"}}, {\"idx\": 6, \"outputs\": 111, \"inputs\": {\"s\": \"aabaaabcc\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"s\": \"19\"}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"s\": \"1001100\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"s\": \"DtAnuQbU\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
399 | Number Substrings String | C++ | int numberSubstringsString(string str) { | [
"str"
] | def number_substrings_string(str):
n = len(str)
return int(((n * (n + 1)) / 2)) | int number_substrings_string(string str) {
int n = str . length ( );
return n * ( n + 1 ) / 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(string str, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"gZFGZsHCimLf\", 78); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"505357\", 21); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011011101\", 45); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ovfwP Osauz\", 66); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"92132238746026\", 105); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01100\", 15); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"RaOWYQRfiWKSyC\", 105); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"861330202\", 45); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"001100010\", 45); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"uvpKlGUBLOMba\", 91); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberSubstringsString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 78, \"inputs\": {\"str\": \"gZFGZsHCimLf\"}}, {\"idx\": 1, \"outputs\": 21, \"inputs\": {\"str\": \"505357\"}}, {\"idx\": 2, \"outputs\": 45, \"inputs\": {\"str\": \"011011101\"}}, {\"idx\": 3, \"outputs\": 66, \"inputs\": {\"str\": \"ovfwP Osauz\"}}, {\"idx\": 4, \"outputs\": 105, \"inputs\": {\"str\": \"92132238746026\"}}, {\"idx\": 5, \"outputs\": 15, \"inputs\": {\"str\": \"01100\"}}, {\"idx\": 6, \"outputs\": 105, \"inputs\": {\"str\": \"RaOWYQRfiWKSyC\"}}, {\"idx\": 7, \"outputs\": 45, \"inputs\": {\"str\": \"861330202\"}}, {\"idx\": 8, \"outputs\": 45, \"inputs\": {\"str\": \"001100010\"}}, {\"idx\": 9, \"outputs\": 91, \"inputs\": {\"str\": \"uvpKlGUBLOMba\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
400 | Number Triangles N Moves | C++ | long long numberTrianglesNMoves(int n) { | [
"n"
] | def number_triangles_n_moves(n):
answer = ([None] * (n + 1))
answer[0] = 1
i = 1
while (i <= n):
answer[i] = ((answer[(i - 1)] * 3) + 2)
i = (i + 1)
return answer[n] | int number_triangles_n_moves(int n) {
int answer [ n + 1 ] = {
0 };
answer [ 0 ] = 1;
for ( int i = 1;
i <= n;
i ++ ) answer [ i ] = answer [ i - 1 ] * 3 + 2;
return answer [ 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(33, 11118121133111045); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 13121); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 1457); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberTrianglesNMoves",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 11118121133111045, \"inputs\": {\"n\": 33}}, {\"idx\": 1, \"outputs\": 13121, \"inputs\": {\"n\": 8}}, {\"idx\": 2, \"outputs\": 1457, \"inputs\": {\"n\": 6}}]",
"test_case_ids": [
"0",
"1",
"2"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
401 | Number Triangles N Moves 1 | C++ | int numberTrianglesNMoves1(int n) { | [
"n"
] | def number_triangles_n_moves_1(n):
ans = ((2 * pow(3, n)) - 1)
return ans | int number_triangles_n_moves_1(int n) {
int ans = 2 * ( pow ( 3, n ) ) - 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 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(16, 86093441); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberTrianglesNMoves1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 86093441, \"inputs\": {\"n\": 16}}]",
"test_case_ids": [
"0"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
402 | Number Unique Rectangles Formed Using N Unit Squares | C++ | int numberUniqueRectanglesFormedUsingNUnitSquares(int n) { | [
"n"
] | def number_unique_rectangles_formed_using_n_unit_squares(n):
ans = 0
for length in range(1, (int(math.sqrt(n)) + 1)):
height = length
while ((height * length) <= n):
ans += 1
height += 1
return ans | int number_unique_rectangles_formed_using_n_unit_squares(int n) {
int ans = 0;
for ( int length = 1;
length <= sqrt ( n );
++ length ) for ( int height = length;
height * length <= n;
++ height ) 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(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(34, 66); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 104); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 83); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 28); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 151); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 76); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 128); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 144); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 135); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 127); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberUniqueRectanglesFormedUsingNUnitSquares",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 66, \"inputs\": {\"n\": 34}}, {\"idx\": 1, \"outputs\": 104, \"inputs\": {\"n\": 49}}, {\"idx\": 2, \"outputs\": 83, \"inputs\": {\"n\": 41}}, {\"idx\": 3, \"outputs\": 28, \"inputs\": {\"n\": 17}}, {\"idx\": 4, \"outputs\": 151, \"inputs\": {\"n\": 67}}, {\"idx\": 5, \"outputs\": 76, \"inputs\": {\"n\": 38}}, {\"idx\": 6, \"outputs\": 128, \"inputs\": {\"n\": 59}}, {\"idx\": 7, \"outputs\": 144, \"inputs\": {\"n\": 64}}, {\"idx\": 8, \"outputs\": 135, \"inputs\": {\"n\": 61}}, {\"idx\": 9, \"outputs\": 127, \"inputs\": {\"n\": 58}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
403 | Number Visible Boxes Putting One Inside Another | C++ | int numberVisibleBoxesPuttingOneInsideAnother(vector<int> arr, int n) { | [
"arr",
"n"
] | def number_visible_boxes_putting_one_inside_another(arr, n):
q = collections.deque([])
arr.sort()
q.append(arr[0])
for i in range(1, n):
now = q[0]
if (arr[i] >= (2 * now)):
q.popleft()
q.append(arr[i])
return len(q) | int number_visible_boxes_putting_one_inside_another(vector<int> arr, int n) {
queue < int > q;
sort(arr.begin(), arr.end());
q . push ( arr [ 0 ] );
for ( int i = 1;
i < n;
i ++ ) {
int now = q . front ( );
if ( arr [ i ] >= 2 * now ) q . pop ( );
q . push ( arr [ i ] );
}
return q . size ( );
} | {
"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, 3, 17, 17, 18, 28, 28, 29, 34, 43, 44, 52, 54, 80, 84, 84, 91, 92, 97}, 12, 7); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -90, -90, -78, -34, -26, -10, 4, 24, 28, 64, 70, 72, 74, 80, 82}, 10, 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, 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}, 40, 15); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 5, 8, 12, 16, 20, 30, 37, 53, 55, 62, 76, 81, 83, 87, 88, 96}, 9, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -92, -60, -58, -54, -42, -36, -12, -8, -2, 8, 14, 18, 20, 26, 32, 38, 56, 58, 60, 70, 78, 80, 86, 98}, 18, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 9, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 2, 3, 3, 11, 16, 18, 19, 21, 21, 22, 22, 24, 27, 28, 29, 43, 43, 52, 55, 57, 60, 62, 62, 63, 65, 66, 70, 70, 73, 77, 78, 79, 79, 80, 85, 85, 86, 88, 89, 90, 97, 98}, 30, 13); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -82, -80, -78, -68, -60, -58, -44, -44, -42, -30, -30, -22, -18, -18, -14, -14, -10, -8, -6, 4, 4, 6, 12, 12, 14, 18, 30, 44, 48, 50, 52, 54, 80, 86, 88, 88}, 21, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 7, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 5, 5, 10, 12, 16, 22, 31, 31, 32, 39, 43, 43, 47, 49, 50, 51, 52, 52, 56, 59, 59, 62, 69, 69, 71, 75, 81, 82, 83, 83, 86, 89, 90, 90, 96}, 28, 17); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberVisibleBoxesPuttingOneInsideAnother",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 7, \"inputs\": {\"arr\": [2, 3, 17, 17, 18, 28, 28, 29, 34, 43, 44, 52, 54, 80, 84, 84, 91, 92, 97], \"n\": 12}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"arr\": [-94, -90, -90, -78, -34, -26, -10, 4, 24, 28, 64, 70, 72, 74, 80, 82], \"n\": 10}}, {\"idx\": 2, \"outputs\": 15, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 40}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"arr\": [2, 3, 5, 8, 12, 16, 20, 30, 37, 53, 55, 62, 76, 81, 83, 87, 88, 96], \"n\": 9}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"arr\": [-94, -92, -60, -58, -54, -42, -36, -12, -8, -2, 8, 14, 18, 20, 26, 32, 38, 56, 58, 60, 70, 78, 80, 86, 98], \"n\": 18}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 9}}, {\"idx\": 6, \"outputs\": 13, \"inputs\": {\"arr\": [1, 1, 2, 3, 3, 11, 16, 18, 19, 21, 21, 22, 22, 24, 27, 28, 29, 43, 43, 52, 55, 57, 60, 62, 62, 63, 65, 66, 70, 70, 73, 77, 78, 79, 79, 80, 85, 85, 86, 88, 89, 90, 97, 98], \"n\": 30}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [-94, -82, -80, -78, -68, -60, -58, -44, -44, -42, -30, -30, -22, -18, -18, -14, -14, -10, -8, -6, 4, 4, 6, 12, 12, 14, 18, 30, 44, 48, 50, 52, 54, 80, 86, 88, 88], \"n\": 21}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 17, \"inputs\": {\"arr\": [3, 5, 5, 10, 12, 16, 22, 31, 31, 32, 39, 43, 43, 47, 49, 50, 51, 52, 52, 56, 59, 59, 62, 69, 69, 71, 75, 81, 82, 83, 83, 86, 89, 90, 90, 96], \"n\": 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
]
} |
404 | Number Ways Node Make Loop Size K Undirected Complete Connected Graph N Nodes | C++ | float numberWaysNodeMakeLoopSizeKUndirectedCompleteConnectedGraphNNodes(int n, int k) { | [
"n",
"k"
] | def number_ways_node_make_loop_size_k_undirected_complete_connected_graph_n_nodes(n, k):
p = 1
if (k % 2):
p = (- 1)
return ((pow((n - 1), k) + (p * (n - 1))) / n) | int number_ways_node_make_loop_size_k_undirected_complete_connected_graph_n_nodes(int n, int k) {
int p = 1;
if ( k % 2 ) p = - 1;
return ( pow ( n - 1, k ) + p * ( n - 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(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int n, int k, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(16, 2, 15.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "numberWaysNodeMakeLoopSizeKUndirectedCompleteConnectedGraphNNodes",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 15.0, \"inputs\": {\"n\": 16, \"k\": 2}}]",
"test_case_ids": [
"0"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
405 | N Th Number Whose Sum Of Digits Is Ten | C++ | int nThNumberWhoseSumOfDigitsIsTen(int n) { | [
"n"
] | def n_th_number_whose_sum_of_digits_is_ten(n):
count = 0
for curr in itertools.count():
sum = 0
x = curr
while x:
sum = (sum + (x % 10))
x = (x // 10)
if (sum == 10):
count = (count + 1)
if (count == n):
return curr
return (- 1) | int n_th_number_whose_sum_of_digits_is_ten(int n) {
int count = 0;
for ( int curr = 1;
;
curr ++ ) {
int sum = 0;
for ( int x = curr;
x > 0;
x = x / 10 ) sum = sum + x % 10;
if ( sum == 10 ) count ++;
if ( count == n ) return curr;
}
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 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, 406); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 136); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 613); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 1054); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 1126); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 109); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 1360); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 433); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 1054); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 46); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nThNumberWhoseSumOfDigitsIsTen",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 406, \"inputs\": {\"n\": 37}}, {\"idx\": 1, \"outputs\": 136, \"inputs\": {\"n\": 13}}, {\"idx\": 2, \"outputs\": 613, \"inputs\": {\"n\": 51}}, {\"idx\": 3, \"outputs\": 1054, \"inputs\": {\"n\": 69}}, {\"idx\": 4, \"outputs\": 1126, \"inputs\": {\"n\": 76}}, {\"idx\": 5, \"outputs\": 109, \"inputs\": {\"n\": 10}}, {\"idx\": 6, \"outputs\": 1360, \"inputs\": {\"n\": 97}}, {\"idx\": 7, \"outputs\": 433, \"inputs\": {\"n\": 40}}, {\"idx\": 8, \"outputs\": 1054, \"inputs\": {\"n\": 69}}, {\"idx\": 9, \"outputs\": 46, \"inputs\": {\"n\": 4}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
406 | N Th Number Whose Sum Of Digits Is Ten 1 | C++ | int nThNumberWhoseSumOfDigitsIsTen1(int n) { | [
"n"
] | def n_th_number_whose_sum_of_digits_is_ten_1(n):
count = 0
curr = 19
while True:
sum = 0
x = curr
while (x > 0):
sum = (sum + (x % 10))
x = int((x / 10))
if (sum == 10):
count += 1
if (count == n):
return curr
curr += 9
return (- 1) | int n_th_number_whose_sum_of_digits_is_ten_1(int n) {
int count = 0;
for ( int curr = 19;
;
curr += 9 ) {
int sum = 0;
for ( int x = curr;
x > 0;
x = x / 10 ) sum = sum + x % 10;
if ( sum == 10 ) count ++;
if ( count == n ) return curr;
}
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 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(93, 1324); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 109); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 703); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 1333); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 28); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 55); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 406); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 46); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 118); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 523); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nThNumberWhoseSumOfDigitsIsTen1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1324, \"inputs\": {\"n\": 93}}, {\"idx\": 1, \"outputs\": 109, \"inputs\": {\"n\": 10}}, {\"idx\": 2, \"outputs\": 703, \"inputs\": {\"n\": 55}}, {\"idx\": 3, \"outputs\": 1333, \"inputs\": {\"n\": 94}}, {\"idx\": 4, \"outputs\": 28, \"inputs\": {\"n\": 2}}, {\"idx\": 5, \"outputs\": 55, \"inputs\": {\"n\": 5}}, {\"idx\": 6, \"outputs\": 406, \"inputs\": {\"n\": 37}}, {\"idx\": 7, \"outputs\": 46, \"inputs\": {\"n\": 4}}, {\"idx\": 8, \"outputs\": 118, \"inputs\": {\"n\": 11}}, {\"idx\": 9, \"outputs\": 523, \"inputs\": {\"n\": 46}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
407 | N Th Number Whose Sum Of Digits Is Ten 2 | C++ | int nThNumberWhoseSumOfDigitsIsTen2(int n) { | [
"n"
] | def n_th_number_whose_sum_of_digits_is_ten_2(n):
nthElement = (19 + ((n - 1) * 9))
outliersCount = (int(math.log10(nthElement)) - 1)
nthElement += (9 * outliersCount)
return nthElement | int n_th_number_whose_sum_of_digits_is_ten_2(int n) {
int nthElement = 19 + ( n - 1 ) * 9;
int outliersCount = ( int ) log10 ( nthElement ) - 1;
nthElement += 9 * outliersCount;
return nthElement;
} | {
"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(68, 631); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 649); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 640); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 856); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 910); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 415); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 838); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 82); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 766); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 478); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nThNumberWhoseSumOfDigitsIsTen2",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 631, \"inputs\": {\"n\": 68}}, {\"idx\": 1, \"outputs\": 649, \"inputs\": {\"n\": 70}}, {\"idx\": 2, \"outputs\": 640, \"inputs\": {\"n\": 69}}, {\"idx\": 3, \"outputs\": 856, \"inputs\": {\"n\": 93}}, {\"idx\": 4, \"outputs\": 910, \"inputs\": {\"n\": 99}}, {\"idx\": 5, \"outputs\": 415, \"inputs\": {\"n\": 44}}, {\"idx\": 6, \"outputs\": 838, \"inputs\": {\"n\": 91}}, {\"idx\": 7, \"outputs\": 82, \"inputs\": {\"n\": 8}}, {\"idx\": 8, \"outputs\": 766, \"inputs\": {\"n\": 83}}, {\"idx\": 9, \"outputs\": 478, \"inputs\": {\"n\": 51}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
408 | N Th Term Series 2 12 36 80 150 | C++ | int nThTermSeries2123680150(int n) { | [
"n"
] | def n_th_term_series_2_12_36_80_150(n):
return ((n * n) + ((n * n) * n)) | int n_th_term_series_2_12_36_80_150(int n) {
return ( n * n ) + ( n * n * 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(90, 737100); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 866400); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 11132); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 25230); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 242172); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 65600); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 143312); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 9702); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 37026); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 1452); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "nThTermSeries2123680150",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 737100, \"inputs\": {\"n\": 90}}, {\"idx\": 1, \"outputs\": 866400, \"inputs\": {\"n\": 95}}, {\"idx\": 2, \"outputs\": 11132, \"inputs\": {\"n\": 22}}, {\"idx\": 3, \"outputs\": 25230, \"inputs\": {\"n\": 29}}, {\"idx\": 4, \"outputs\": 242172, \"inputs\": {\"n\": 62}}, {\"idx\": 5, \"outputs\": 65600, \"inputs\": {\"n\": 40}}, {\"idx\": 6, \"outputs\": 143312, \"inputs\": {\"n\": 52}}, {\"idx\": 7, \"outputs\": 9702, \"inputs\": {\"n\": 21}}, {\"idx\": 8, \"outputs\": 37026, \"inputs\": {\"n\": 33}}, {\"idx\": 9, \"outputs\": 1452, \"inputs\": {\"n\": 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
]
} |
409 | One Line Function For Factorial Of A Number | C++ | long long oneLineFunctionForFactorialOfANumber(int n) { | [
"n"
] | def one_line_function_for_factorial_of_a_number(n):
return (1 if ((n == 1) or (n == 0)) else (n * one_line_function_for_factorial_of_a_number((n - 1)))) | int one_line_function_for_factorial_of_a_number(int n) {
return ( n == 1 || n == 0 ) ? 1 : n * one_line_function_for_factorial_of_a_number ( n - 1 );
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(16, 20922789888000); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 720); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "oneLineFunctionForFactorialOfANumber",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 20922789888000, \"inputs\": {\"n\": 16}}, {\"idx\": 1, \"outputs\": 720, \"inputs\": {\"n\": 6}}]",
"test_case_ids": [
"0",
"1"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
410 | Padovan Sequence | C++ | long long padovanSequence(int n) { | [
"n"
] | def padovan_sequence(n):
(pPrevPrev, pPrev, pCurr, pNext) = (1, 1, 1, 1)
for i in range(3, (n + 1)):
pNext = (pPrevPrev + pPrev)
pPrevPrev = pPrev
pPrev = pCurr
pCurr = pNext
return pNext | int padovan_sequence(int n) {
int pPrevPrev = 1, pPrev = 1, pCurr = 1, pNext = 1;
for ( int i = 3;
i <= n;
i ++ ) {
pNext = pPrevPrev + pPrev;
pPrevPrev = pPrev;
pPrev = pCurr;
pCurr = pNext;
}
return pNext;
} | {
"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(1, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 124155792775); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 2513); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 1618192); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 3761840); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 28); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 9882257736); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 9882257736); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 12); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 109870576); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "padovanSequence",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"n\": 1}}, {\"idx\": 1, \"outputs\": 124155792775, \"inputs\": {\"n\": 92}}, {\"idx\": 2, \"outputs\": 2513, \"inputs\": {\"n\": 29}}, {\"idx\": 3, \"outputs\": 1618192, \"inputs\": {\"n\": 52}}, {\"idx\": 4, \"outputs\": 3761840, \"inputs\": {\"n\": 55}}, {\"idx\": 5, \"outputs\": 28, \"inputs\": {\"n\": 13}}, {\"idx\": 6, \"outputs\": 9882257736, \"inputs\": {\"n\": 83}}, {\"idx\": 7, \"outputs\": 9882257736, \"inputs\": {\"n\": 83}}, {\"idx\": 8, \"outputs\": 12, \"inputs\": {\"n\": 10}}, {\"idx\": 9, \"outputs\": 109870576, \"inputs\": {\"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
]
} |
411 | Painting Fence Algorithm | C++ | int paintingFenceAlgorithm(int n, int k) { | [
"n",
"k"
] | def painting_fence_algorithm(n, k):
total = k
mod = 1000000007
(same, diff) = (0, k)
for i in range(2, (n + 1)):
same = diff
diff = (total * (k - 1))
diff = (diff % mod)
total = ((same + diff) % mod)
return total | long painting_fence_algorithm(int n, int k) {
long total = k;
int mod = 1000000007;
int same = 0, diff = k;
for ( int i = 2;
i <= n;
i ++ ) {
same = diff;
diff = total * ( k - 1 );
diff = diff % mod;
total = ( same + diff ) % mod;
}
return total;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(6, 30, 725841870); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 87, 370622679); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 31, 7554776); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 36, 76740139); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 68, 647498520); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 66, 70208793); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 18, 227130467); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 73, 204618786); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 42, 797370673); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 98, 903959704); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "paintingFenceAlgorithm",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 725841870, \"inputs\": {\"n\": 6, \"k\": 30}}, {\"idx\": 1, \"outputs\": 370622679, \"inputs\": {\"n\": 23, \"k\": 87}}, {\"idx\": 2, \"outputs\": 7554776, \"inputs\": {\"n\": 89, \"k\": 31}}, {\"idx\": 3, \"outputs\": 76740139, \"inputs\": {\"n\": 63, \"k\": 36}}, {\"idx\": 4, \"outputs\": 647498520, \"inputs\": {\"n\": 23, \"k\": 68}}, {\"idx\": 5, \"outputs\": 70208793, \"inputs\": {\"n\": 44, \"k\": 66}}, {\"idx\": 6, \"outputs\": 227130467, \"inputs\": {\"n\": 81, \"k\": 18}}, {\"idx\": 7, \"outputs\": 204618786, \"inputs\": {\"n\": 43, \"k\": 73}}, {\"idx\": 8, \"outputs\": 797370673, \"inputs\": {\"n\": 9, \"k\": 42}}, {\"idx\": 9, \"outputs\": 903959704, \"inputs\": {\"n\": 41, \"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
]
} |
412 | Pair With Given Product Set 1 Find If Any Pair Exists | C++ | bool pairWithGivenProductSet1FindIfAnyPairExists(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def pair_with_given_product_set_1_find_if_any_pair_exists(arr, n, x):
for i in arr:
for j in arr:
if ((i * j) == x):
return True
return False | bool pair_with_given_product_set_1_find_if_any_pair_exists(vector<int> arr, int n, int x) {
for ( int i = 0;
i < n - 1;
i ++ ) for ( int j = i + 1;
i < n;
i ++ ) if ( arr [ i ] * arr [ j ] == x ) return true;
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int x, bool 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({10, 20, 9, 40}, 4, 400, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, -10, 20, 9, -40}, 5, 400, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1}, 7, 8, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 10, 20, 9, -40}, 5, -400, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -86, -76, -72, -70, -62, -56, -50, -18, -12, -10, 4, 16, 26, 42, 48, 52, 54, 54, 70, 84, 86, 88, 98}, 23, 23, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1}, 0, 0, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 7, 14, 14, 16, 18, 19, 20, 22, 24, 29, 38, 38, 38, 40, 40, 46, 46, 47, 51, 51, 52, 55, 56, 56, 62, 62, 62, 78, 79, 81, 84, 86, 88, 89, 89, 89}, 23, 32, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({72, 80, -82, 24, -98, 90, -32, -56, -22, 8, -12, 8, -78, 60, -62, 50, 12, -60, 10, -54, 74, 98, 26, 56, 24}, 21, 19, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 18, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({93, 40, 48, 99, 95, 59, 43, 58, 79, 70, 28}, 9, 5, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "pairWithGivenProductSet1FindIfAnyPairExists",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"arr\": [10, 20, 9, 40], \"n\": 4, \"x\": 400}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"arr\": [1, -10, 20, 9, -40], \"n\": 5, \"x\": 400}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 7, \"x\": 8}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [4, 10, 20, 9, -40], \"n\": 5, \"x\": -400}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"arr\": [-90, -86, -76, -72, -70, -62, -56, -50, -18, -12, -10, 4, 16, 26, 42, 48, 52, 54, 54, 70, 84, 86, 88, 98], \"n\": 23, \"x\": 23}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [1], \"n\": 0, \"x\": 0}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [4, 7, 14, 14, 16, 18, 19, 20, 22, 24, 29, 38, 38, 38, 40, 40, 46, 46, 47, 51, 51, 52, 55, 56, 56, 62, 62, 62, 78, 79, 81, 84, 86, 88, 89, 89, 89], \"n\": 23, \"x\": 32}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [72, 80, -82, 24, -98, 90, -32, -56, -22, 8, -12, 8, -78, 60, -62, 50, 12, -60, 10, -54, 74, 98, 26, 56, 24], \"n\": 21, \"x\": 19}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 22, \"x\": 18}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [93, 40, 48, 99, 95, 59, 43, 58, 79, 70, 28], \"n\": 9, \"x\": 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
]
} |
413 | Pair With Given Product Set 1 Find If Any Pair Exists 1 | C++ | bool pairWithGivenProductSet1FindIfAnyPairExists1(vector<int> arr, int n, int x) { | [
"arr",
"n",
"x"
] | def pair_with_given_product_set_1_find_if_any_pair_exists_1(arr, n, x):
if (n < 2):
return False
s = set()
for i in range(0, n):
if (arr[i] == 0):
if (x == 0):
return True
else:
continue
if ((x % arr[i]) == 0):
if ((x // arr[i]) in s):
return True
s.add(arr[i])
return False | bool pair_with_given_product_set_1_find_if_any_pair_exists_1(vector<int> arr, int n, int x) {
if ( n < 2 ) return false;
unordered_set < int > s;
for ( int i = 0;
i < n;
i ++ ) {
if ( arr [ i ] == 0 ) {
if ( x == 0 ) return true;
else continue;
}
if ( x % arr [ i ] == 0 ) {
if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true;
s . insert ( arr [ i ] );
}
}
return false;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int x, bool 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({1, 2, 3, 7, 23, 23, 25, 27, 37, 42, 53, 56, 58, 61, 69, 78, 79, 84, 85, 86, 90, 93, 95}, 15, 17, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-10, -18, 88, -36, 78, 66, -70, -34, -88, -98, -70, -4, -94, -92, -76, -78, -30, -48, -72, 86, -64, 38, -80, 20, 70, -32, -90, 74, -78, 12, -54, 88, 38, -96, 28}, 17, 22, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, 9, 5, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({83, 61, 55, 89, 16, 78, 44, 54, 22, 49, 58, 62, 53, 99, 35, 83, 29, 19, 96, 39, 60, 6, 34, 67, 43, 29, 46, 3, 81, 78, 80, 39, 86, 78, 21}, 23, 27, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -88, -80, -62, -58, -56, -54, -52, -34, -20, -6, -2, 6, 20, 52, 54, 70, 72, 80, 82, 94}, 18, 12, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 0, 1, 1, 1}, 4, 6, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 11, 11, 20, 22, 23, 26, 27, 31, 38, 40, 40, 45, 46, 46, 48, 50, 61, 73, 76, 78, 78, 79, 80, 81, 84, 90, 91, 93, 95}, 24, 28, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({18}, 0, 0, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 39, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({19, 37, 47, 40, 72, 59, 51, 53, 92, 3, 21, 81, 29, 48, 97, 59, 10, 74, 11, 37, 49, 95, 88, 85, 6, 26, 76, 33}, 22, 21, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "pairWithGivenProductSet1FindIfAnyPairExists1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [1, 2, 3, 7, 23, 23, 25, 27, 37, 42, 53, 56, 58, 61, 69, 78, 79, 84, 85, 86, 90, 93, 95], \"n\": 15, \"x\": 17}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [-10, -18, 88, -36, 78, 66, -70, -34, -88, -98, -70, -4, -94, -92, -76, -78, -30, -48, -72, 86, -64, 38, -80, 20, 70, -32, -90, 74, -78, 12, -54, 88, 38, -96, 28], \"n\": 17, \"x\": 22}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1], \"n\": 9, \"x\": 5}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"arr\": [83, 61, 55, 89, 16, 78, 44, 54, 22, 49, 58, 62, 53, 99, 35, 83, 29, 19, 96, 39, 60, 6, 34, 67, 43, 29, 46, 3, 81, 78, 80, 39, 86, 78, 21], \"n\": 23, \"x\": 27}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-96, -88, -80, -62, -58, -56, -54, -52, -34, -20, -6, -2, 6, 20, 52, 54, 70, 72, 80, 82, 94], \"n\": 18, \"x\": 12}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [0, 1, 1, 0, 0, 1, 1, 1], \"n\": 4, \"x\": 6}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [8, 11, 11, 20, 22, 23, 26, 27, 31, 38, 40, 40, 45, 46, 46, 48, 50, 61, 73, 76, 78, 78, 79, 80, 81, 84, 90, 91, 93, 95], \"n\": 24, \"x\": 28}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [18], \"n\": 0, \"x\": 0}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 37, \"x\": 39}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [19, 37, 47, 40, 72, 59, 51, 53, 92, 3, 21, 81, 29, 48, 97, 59, 10, 74, 11, 37, 49, 95, 88, 85, 6, 26, 76, 33], \"n\": 22, \"x\": 21}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
414 | Paper Cut Minimum Number Squares | C++ | int paperCutMinimumNumberSquares(int a, int b) { | [
"a",
"b"
] | def paper_cut_minimum_number_squares(a, b):
result = 0
rem = 0
if (a < b):
(a, b) = (b, a)
while (b > 0):
result += int((a / b))
rem = int((a % b))
a = b
b = rem
return result | int paper_cut_minimum_number_squares(int a, int b) {
long long result = 0, rem = 0;
if ( a < b ) swap ( a, b );
while ( b > 0 ) {
result += a / b;
long long rem = a % b;
a = b;
b = rem;
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(87, 60, 9); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 35, 19); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 93, 11); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 20, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 69, 10); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 29, 12); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 1, 64); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 95, 9); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 72, 18); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 41, 11); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "paperCutMinimumNumberSquares",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 9, \"inputs\": {\"a\": 87, \"b\": 60}}, {\"idx\": 1, \"outputs\": 19, \"inputs\": {\"a\": 18, \"b\": 35}}, {\"idx\": 2, \"outputs\": 11, \"inputs\": {\"a\": 68, \"b\": 93}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"a\": 80, \"b\": 20}}, {\"idx\": 4, \"outputs\": 10, \"inputs\": {\"a\": 87, \"b\": 69}}, {\"idx\": 5, \"outputs\": 12, \"inputs\": {\"a\": 64, \"b\": 29}}, {\"idx\": 6, \"outputs\": 64, \"inputs\": {\"a\": 64, \"b\": 1}}, {\"idx\": 7, \"outputs\": 9, \"inputs\": {\"a\": 65, \"b\": 95}}, {\"idx\": 8, \"outputs\": 18, \"inputs\": {\"a\": 43, \"b\": 72}}, {\"idx\": 9, \"outputs\": 11, \"inputs\": {\"a\": 97, \"b\": 41}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
415 | Perfect Reversible String | C++ | bool perfectReversibleString(string str) { | [
"str"
] | def perfect_reversible_string(str):
i = 0
j = (len(str) - 1)
while (i < j):
if (str[i] != str[j]):
return False
i += 1
j -= 1
return True | bool perfect_reversible_string(string str) {
int i = 0, j = str . length ( ) - 1;
while ( i < j ) {
if ( str [ i ] != str [ j ] ) return false;
i ++;
j --;
}
return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string str, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"ab\", false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"303\", true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11110000\", false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aba\", true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"404\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10101\", true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abab\", false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"6366\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"001\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"\", true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "perfectReversibleString",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"str\": \"ab\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"str\": \"303\"}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"str\": \"11110000\"}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"str\": \"aba\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"str\": \"404\"}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"str\": \"10101\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"str\": \"abab\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"str\": \"6366\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"str\": \"001\"}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"str\": \"\"}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
416 | Permute Two Arrays Sum Every Pair Greater Equal K | C++ | bool permuteTwoArraysSumEveryPairGreaterEqualK(vector<int> a, vector<int> b, int n, int k) { | [
"a",
"b",
"n",
"k"
] | def permute_two_arrays_sum_every_pair_greater_equal_k(a, b, n, k):
a.sort(reverse=True)
b.sort()
for i in range(n):
if ((a[i] + b[i]) < k):
return False
return True | bool permute_two_arrays_sum_every_pair_greater_equal_k(vector<int> a, vector<int> b, int n, int k) {
sort(a.begin(), a.end());
sort(b.begin(), b.end(), greater < int > ( ) );
for ( int i = 0;
i < n;
i ++ ) if ( a [ i ] + b [ i ] < k ) 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> a, vector<int> b, int n, int k, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, 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({99, 97, 90, 88, 87, 70, 52, 52, 43, 40, 27, 25, 16, 12, 9}, {4, 7, 11, 20, 34, 35, 36, 44, 46, 71, 72, 78, 85, 85, 91}, 10, 7, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 92, 92, 88, 74, 72, 70, 56, 42, 42, 30, 30, 20, 18, 14, 12, 10, 8, 6, -14, -26, -28, -42, -44, -48, -68, -74, -74, -76, -78, -80, -84, -86, -90, -90, -90, -92, -94, -96, -96, -98, -98}, {-98, -86, -84, -80, -80, -78, -76, -76, -74, -72, -56, -50, -48, -44, -44, -42, -32, -32, -32, -22, -20, -18, -14, 8, 16, 16, 18, 24, 30, 40, 44, 50, 60, 62, 62, 68, 70, 76, 84, 94, 94, 96}, 40, 38, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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}, 11, 15, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({97, 77, 75, 72, 71, 70, 69, 65, 59, 55, 51, 48, 47, 42, 35, 31, 26, 18, 16, 15, 15, 13, 11, 6, 3, 2}, {4, 11, 12, 12, 14, 15, 20, 21, 36, 37, 38, 44, 45, 46, 48, 51, 60, 62, 65, 73, 78, 79, 81, 88, 89, 98}, 25, 16, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 92, 90, 90, 84, 84, 74, 72, 68, 58, 56, 56, 54, 52, 36, 32, 18, 18, 16, 16, 4, 2, -2, -4, -4, -20, -34, -40, -42, -46, -48, -52, -52, -52, -64, -66, -70, -72}, {-94, -76, -74, -56, -54, -50, -46, -38, -26, -24, -24, -22, -16, -10, -6, -4, -4, 0, 0, 6, 12, 12, 18, 20, 38, 50, 52, 52, 54, 64, 64, 72, 72, 72, 76, 90, 96, 96}, 26, 30, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 13, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 96, 96, 94, 93, 92, 87, 82, 80, 80, 80, 79, 72, 72, 66, 66, 64, 58, 53, 48, 44, 37, 34, 32, 23, 21, 18, 17, 8}, {11, 15, 17, 19, 23, 23, 26, 27, 36, 43, 46, 47, 55, 59, 63, 66, 77, 79, 79, 82, 85, 86, 86, 91, 91, 94, 94, 97, 99}, 20, 14, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 80, 78, 62, 52, 50, 32, 28, 24, 24, 22, 18, 18, 14, 14, 10, 10, -8, -14, -14, -16, -20, -22, -28, -38, -48, -50, -66, -78, -78, -80, -82, -88, -88, -98}, {-96, -82, -80, -80, -66, -54, -46, -44, -40, -30, -16, -14, 2, 6, 12, 20, 24, 32, 36, 38, 42, 46, 52, 56, 62, 66, 70, 88, 88, 90, 90, 96, 96, 98, 98}, 31, 24, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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, 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}, 31, 30, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({92, 91, 85, 75, 72, 67, 65, 58, 53, 45, 39, 33, 31, 13, 10, 10}, {7, 12, 19, 21, 28, 34, 39, 40, 41, 69, 71, 71, 74, 78, 91, 92}, 14, 8, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "permuteTwoArraysSumEveryPairGreaterEqualK",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"a\": [99, 97, 90, 88, 87, 70, 52, 52, 43, 40, 27, 25, 16, 12, 9], \"b\": [4, 7, 11, 20, 34, 35, 36, 44, 46, 71, 72, 78, 85, 85, 91], \"n\": 10, \"k\": 7}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"a\": [94, 92, 92, 88, 74, 72, 70, 56, 42, 42, 30, 30, 20, 18, 14, 12, 10, 8, 6, -14, -26, -28, -42, -44, -48, -68, -74, -74, -76, -78, -80, -84, -86, -90, -90, -90, -92, -94, -96, -96, -98, -98], \"b\": [-98, -86, -84, -80, -80, -78, -76, -76, -74, -72, -56, -50, -48, -44, -44, -42, -32, -32, -32, -22, -20, -18, -14, 8, 16, 16, 18, 24, 30, 40, 44, 50, 60, 62, 62, 68, 70, 76, 84, 94, 94, 96], \"n\": 40, \"k\": 38}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"a\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], \"b\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 11, \"k\": 15}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"a\": [97, 77, 75, 72, 71, 70, 69, 65, 59, 55, 51, 48, 47, 42, 35, 31, 26, 18, 16, 15, 15, 13, 11, 6, 3, 2], \"b\": [4, 11, 12, 12, 14, 15, 20, 21, 36, 37, 38, 44, 45, 46, 48, 51, 60, 62, 65, 73, 78, 79, 81, 88, 89, 98], \"n\": 25, \"k\": 16}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"a\": [94, 92, 90, 90, 84, 84, 74, 72, 68, 58, 56, 56, 54, 52, 36, 32, 18, 18, 16, 16, 4, 2, -2, -4, -4, -20, -34, -40, -42, -46, -48, -52, -52, -52, -64, -66, -70, -72], \"b\": [-94, -76, -74, -56, -54, -50, -46, -38, -26, -24, -24, -22, -16, -10, -6, -4, -4, 0, 0, 6, 12, 12, 18, 20, 38, 50, 52, 52, 54, 64, 64, 72, 72, 72, 76, 90, 96, 96], \"n\": 26, \"k\": 30}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"a\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], \"b\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13, \"k\": 13}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"a\": [98, 96, 96, 94, 93, 92, 87, 82, 80, 80, 80, 79, 72, 72, 66, 66, 64, 58, 53, 48, 44, 37, 34, 32, 23, 21, 18, 17, 8], \"b\": [11, 15, 17, 19, 23, 23, 26, 27, 36, 43, 46, 47, 55, 59, 63, 66, 77, 79, 79, 82, 85, 86, 86, 91, 91, 94, 94, 97, 99], \"n\": 20, \"k\": 14}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"a\": [94, 80, 78, 62, 52, 50, 32, 28, 24, 24, 22, 18, 18, 14, 14, 10, 10, -8, -14, -14, -16, -20, -22, -28, -38, -48, -50, -66, -78, -78, -80, -82, -88, -88, -98], \"b\": [-96, -82, -80, -80, -66, -54, -46, -44, -40, -30, -16, -14, 2, 6, 12, 20, 24, 32, 36, 38, 42, 46, 52, 56, 62, 66, 70, 88, 88, 90, 90, 96, 96, 98, 98], \"n\": 31, \"k\": 24}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a\": [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], \"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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 31, \"k\": 30}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"a\": [92, 91, 85, 75, 72, 67, 65, 58, 53, 45, 39, 33, 31, 13, 10, 10], \"b\": [7, 12, 19, 21, 28, 34, 39, 40, 41, 69, 71, 71, 74, 78, 91, 92], \"n\": 14, \"k\": 8}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
417 | Pizza Cut Problem Circle Division Lines | C++ | int pizzaCutProblemCircleDivisionLines(int n) { | [
"n"
] | def pizza_cut_problem_circle_division_lines(n):
return int((1 + ((n * (n + 1)) / 2))) | int pizza_cut_problem_circle_division_lines(int n) {
return 1 + n * ( n + 1 ) / 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(46, 1082); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 2347); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 11); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 79); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 1597); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 106); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 3322); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 436); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 352); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 821); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "pizzaCutProblemCircleDivisionLines",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1082, \"inputs\": {\"n\": 46}}, {\"idx\": 1, \"outputs\": 2347, \"inputs\": {\"n\": 68}}, {\"idx\": 2, \"outputs\": 11, \"inputs\": {\"n\": 4}}, {\"idx\": 3, \"outputs\": 79, \"inputs\": {\"n\": 12}}, {\"idx\": 4, \"outputs\": 1597, \"inputs\": {\"n\": 56}}, {\"idx\": 5, \"outputs\": 106, \"inputs\": {\"n\": 14}}, {\"idx\": 6, \"outputs\": 3322, \"inputs\": {\"n\": 81}}, {\"idx\": 7, \"outputs\": 436, \"inputs\": {\"n\": 29}}, {\"idx\": 8, \"outputs\": 352, \"inputs\": {\"n\": 26}}, {\"idx\": 9, \"outputs\": 821, \"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
]
} |
418 | Policemen Catch Thieves | C++ | int policemenCatchThieves(vector<char> arr, int n, int k) { | [
"arr",
"n",
"k"
] | def policemen_catch_thieves(arr, n, k):
i = 0
l = 0
r = 0
res = 0
thi = []
pol = []
while (i < n):
if (arr[i] == 'P'):
pol.append(i)
elif (arr[i] == 'T'):
thi.append(i)
i += 1
while ((l < len(thi)) and (r < len(pol))):
if (abs((thi[l] - pol[r])) <= k):
res += 1
l += 1
r += 1
elif (thi[l] < pol[r]):
l += 1
else:
r += 1
return res | int policemen_catch_thieves(vector<char> arr, int n, int k) {
int res = 0;
vector < int > thi;
vector < int > pol;
for ( int i = 0;
i < n;
i ++ ) {
if ( arr [ i ] == 'P' ) pol . push_back ( i );
else if ( arr [ i ] == 'T' ) thi . push_back ( i );
}
int l = 0, r = 0;
while ( l < thi . size ( ) && r < pol . size ( ) ) {
if ( abs ( thi [ l ] - pol [ r ] ) <= k ) {
res ++;
l ++;
r ++;
}
else if ( thi [ l ] < pol [ r ] ) l ++;
else r ++;
}
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<char> arr, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({'A', 'B', 'B', 'D', 'E', 'E', 'F', 'G', 'G', 'G', 'I', 'J', 'O', 'P', 'Q', 'Q', 'Q', 'Q', 'R', 'R', 'S', 'U', 'X', 'Y', 'Y', 'c', 'd', 'h', 'i', 'i', 'i', 'i', 'k', 'k', 'l', 'l', 'l', 'l', 'm', 'p', 'r', 'r', 's', 't', 't', 'u', 'x', 'z'}, 33, 45, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'7', '6', '0', '1', '0', '1'}, 3, 3, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1'}, 9, 10, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'y', 'k', 'S', 'i', 's', 'r', 'i', 'z', 'y', 'f', 'E', 'U', 'y', 'G', 'f', 'f', 's', 'v', 'v', 'D', 'v', 'V', 'S', 'D', 'K', 'S', 'f', 'V', 'g', 'I', 'J', 'p', 'j', 'k', 'R', 'n', 'm', 'O', 'L', 'X', 'y', 'U', 'y', 'k', 'w'}, 24, 44, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'1', '1', '5', '8', '8'}, 2, 2, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '1', '0', '0', '1', '1', '1', '0', '0', '0', '1', '0', '1', '0', '1', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '1', '1', '0', '0', '0', '0', '0', '0'}, 23, 18, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'A', 'I', 'K', 'Q', 'Q', 'X', 'Z', 'f', 'g'}, 5, 8, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'7', '0', '6', '9', '7', '5', '1', '3', '9', '8', '0', '0', '1', '3', '9', '2', '5', '5', '2', '7', '9', '3', '3', '9', '3', '8', '5', '5', '0', '4', '6', '2', '7', '4', '0', '4', '6', '4', '2', '3'}, 35, 28, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1'}, 8, 10, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'D', 'C', 'P', 'H', 'G', 'o', 'u', 'P', 'T', 'G', 'E', 'U', 'n', 'E', 'U'}, 11, 12, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "policemenCatchThieves",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [\"A\", \"B\", \"B\", \"D\", \"E\", \"E\", \"F\", \"G\", \"G\", \"G\", \"I\", \"J\", \"O\", \"P\", \"Q\", \"Q\", \"Q\", \"Q\", \"R\", \"R\", \"S\", \"U\", \"X\", \"Y\", \"Y\", \"c\", \"d\", \"h\", \"i\", \"i\", \"i\", \"i\", \"k\", \"k\", \"l\", \"l\", \"l\", \"l\", \"m\", \"p\", \"r\", \"r\", \"s\", \"t\", \"t\", \"u\", \"x\", \"z\"], \"n\": 33, \"k\": 45}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [\"7\", \"6\", \"0\", \"1\", \"0\", \"1\"], \"n\": 3, \"k\": 3}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [\"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\"], \"n\": 9, \"k\": 10}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [\"y\", \"k\", \"S\", \"i\", \"s\", \"r\", \"i\", \"z\", \"y\", \"f\", \"E\", \"U\", \"y\", \"G\", \"f\", \"f\", \"s\", \"v\", \"v\", \"D\", \"v\", \"V\", \"S\", \"D\", \"K\", \"S\", \"f\", \"V\", \"g\", \"I\", \"J\", \"p\", \"j\", \"k\", \"R\", \"n\", \"m\", \"O\", \"L\", \"X\", \"y\", \"U\", \"y\", \"k\", \"w\"], \"n\": 24, \"k\": 44}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [\"1\", \"1\", \"5\", \"8\", \"8\"], \"n\": 2, \"k\": 2}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [\"0\", \"1\", \"0\", \"0\", \"1\", \"1\", \"1\", \"0\", \"0\", \"0\", \"1\", \"0\", \"1\", \"0\", \"1\", \"0\", \"0\", \"0\", \"0\", \"0\", \"1\", \"0\", \"0\", \"0\", \"0\", \"1\", \"1\", \"1\", \"0\", \"0\", \"0\", \"0\", \"0\", \"0\"], \"n\": 23, \"k\": 18}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [\"A\", \"I\", \"K\", \"Q\", \"Q\", \"X\", \"Z\", \"f\", \"g\"], \"n\": 5, \"k\": 8}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [\"7\", \"0\", \"6\", \"9\", \"7\", \"5\", \"1\", \"3\", \"9\", \"8\", \"0\", \"0\", \"1\", \"3\", \"9\", \"2\", \"5\", \"5\", \"2\", \"7\", \"9\", \"3\", \"3\", \"9\", \"3\", \"8\", \"5\", \"5\", \"0\", \"4\", \"6\", \"2\", \"7\", \"4\", \"0\", \"4\", \"6\", \"4\", \"2\", \"3\"], \"n\": 35, \"k\": 28}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [\"0\", \"0\", \"0\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\"], \"n\": 8, \"k\": 10}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [\"D\", \"C\", \"P\", \"H\", \"G\", \"o\", \"u\", \"P\", \"T\", \"G\", \"E\", \"U\", \"n\", \"E\", \"U\"], \"n\": 11, \"k\": 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
]
} |
419 | Position Element Stable Sort | C++ | int positionElementStableSort(vector<int> arr, int n, int idx) { | [
"arr",
"n",
"idx"
] | def position_element_stable_sort(arr, n, idx):
result = 0
for i in range(n):
if (arr[i] < arr[idx]):
result += 1
if ((arr[i] == arr[idx]) and (i < idx)):
result += 1
return result | int position_element_stable_sort(vector<int> arr, int n, int idx) {
int result = 0;
for ( int i = 0;
i < n;
i ++ ) {
if ( arr [ i ] < arr [ idx ] ) result ++;
if ( arr [ i ] == arr [ idx ] && i < idx ) result ++;
}
return result;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int idx, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, idx), 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, 9, 12, 15, 16, 18, 28, 28, 31, 33, 36, 36, 37, 40, 41, 44, 44, 46, 50, 50, 50, 52, 52, 54, 55, 60, 61, 65, 68, 71, 75, 75, 78, 81, 84, 87, 89, 90, 92, 94, 97, 97, 98, 98, 99}, 37, 32, 32); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-16, 86, 94, -86, -38, 64, 96, -64, 94, 10, -10, -62, -50, -46, -62, -32, -4, 72, 14, 36, 74, -66, 46, 82, -44, -22, -26, 16, -8, 0, -90, 94, -50, 22, -82, 8, 92, -84, -34, -36, -66}, 31, 27, 20); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 34, 30); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, 8, 30, 84, 36, 96, 45, 63, 23, 23, 14, 34, 86, 51, 18, 97, 21, 39, 96, 70, 28, 96, 78, 68, 88, 66, 13, 24, 74, 94}, 26, 21, 24); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -90, -86, -86, -72, -72, -58, -50, -32, -22, -18, -10, -4, -2, -2, 0, 0, 6, 14, 22, 22, 36, 36, 40, 44, 58, 60, 70, 70, 76, 82, 82, 84, 88, 96}, 17, 31, 17); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1}, 30, 36, 14); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 5, 6, 7, 8, 10, 17, 20, 20, 26, 27, 27, 27, 32, 32, 38, 40, 44, 45, 45, 45, 45, 47, 50, 57, 57, 57, 58, 62, 63, 63, 67, 68, 73, 75, 76, 77, 79, 79, 80, 85, 88, 89, 89, 89, 94, 96, 98}, 42, 35, 35); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, -92, 18, -18, 44, -88, -90, -66, -38, 78, -22, -46, -20, 64, -10, 54}, 14, 12, 7); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 19, 31, 19); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, 17}, 1, 1, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "positionElementStableSort",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 32, \"inputs\": {\"arr\": [4, 8, 9, 12, 15, 16, 18, 28, 28, 31, 33, 36, 36, 37, 40, 41, 44, 44, 46, 50, 50, 50, 52, 52, 54, 55, 60, 61, 65, 68, 71, 75, 75, 78, 81, 84, 87, 89, 90, 92, 94, 97, 97, 98, 98, 99], \"n\": 37, \"idx\": 32}}, {\"idx\": 1, \"outputs\": 20, \"inputs\": {\"arr\": [-16, 86, 94, -86, -38, 64, 96, -64, 94, 10, -10, -62, -50, -46, -62, -32, -4, 72, 14, 36, 74, -66, 46, 82, -44, -22, -26, 16, -8, 0, -90, 94, -50, 22, -82, 8, 92, -84, -34, -36, -66], \"n\": 31, \"idx\": 27}}, {\"idx\": 2, \"outputs\": 30, \"inputs\": {\"arr\": [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], \"n\": 30, \"idx\": 34}}, {\"idx\": 3, \"outputs\": 24, \"inputs\": {\"arr\": [66, 8, 30, 84, 36, 96, 45, 63, 23, 23, 14, 34, 86, 51, 18, 97, 21, 39, 96, 70, 28, 96, 78, 68, 88, 66, 13, 24, 74, 94], \"n\": 26, \"idx\": 21}}, {\"idx\": 4, \"outputs\": 17, \"inputs\": {\"arr\": [-94, -90, -86, -86, -72, -72, -58, -50, -32, -22, -18, -10, -4, -2, -2, 0, 0, 6, 14, 22, 22, 36, 36, 40, 44, 58, 60, 70, 70, 76, 82, 82, 84, 88, 96], \"n\": 17, \"idx\": 31}}, {\"idx\": 5, \"outputs\": 14, \"inputs\": {\"arr\": [1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1], \"n\": 30, \"idx\": 36}}, {\"idx\": 6, \"outputs\": 35, \"inputs\": {\"arr\": [3, 5, 6, 7, 8, 10, 17, 20, 20, 26, 27, 27, 27, 32, 32, 38, 40, 44, 45, 45, 45, 45, 47, 50, 57, 57, 57, 58, 62, 63, 63, 67, 68, 73, 75, 76, 77, 79, 79, 80, 85, 88, 89, 89, 89, 94, 96, 98], \"n\": 42, \"idx\": 35}}, {\"idx\": 7, \"outputs\": 7, \"inputs\": {\"arr\": [98, -92, 18, -18, 44, -88, -90, -66, -38, 78, -22, -46, -20, 64, -10, 54], \"n\": 14, \"idx\": 12}}, {\"idx\": 8, \"outputs\": 19, \"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], \"n\": 19, \"idx\": 31}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [14, 17], \"n\": 1, \"idx\": 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
]
} |
420 | Position Of Rightmost Set Bit 1 | C++ | int positionOfRightmostSetBit1(int n) { | [
"n"
] | def position_of_rightmost_set_bit_1(n):
position = 1
m = 1
while (not (n & m)):
m = (m << 1)
position += 1
return position | int position_of_rightmost_set_bit_1(int n) {
int position = 1;
int m = 1;
while ( ! ( n & m ) ) {
m = m << 1;
position ++;
}
return position;
} | {
"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(17, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "positionOfRightmostSetBit1",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"n\": 17}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"n\": 97}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"n\": 73}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"n\": 68}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"n\": 6}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"n\": 84}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"n\": 72}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"n\": 66}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"n\": 57}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"n\": 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
]
} |
422 | Possible Form Triangle Array Values | C++ | bool possibleFormTriangleArrayValues(vector<int> arr, int n) { | [
"arr",
"n"
] | def possible_form_triangle_array_values(arr, N):
if (N < 3):
return False
arr.sort()
for i in range((N - 2)):
if ((arr[i] + arr[(i + 1)]) > arr[(i + 2)]):
return True | bool possible_form_triangle_array_values(vector<int> arr, int N) {
if ( N < 3 ) return false;
sort(arr.begin(), arr.end());
for ( int i = 0;
i < N - 2;
i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true;
} | {
"test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 6, 8, 10, 14, 15, 16, 19, 21, 26, 26, 26, 28, 29, 30, 33, 33, 35, 36, 36, 41, 44, 45, 45, 45, 49, 51, 54, 57, 59, 61, 64, 68, 70, 70, 72, 73, 74, 76, 78, 87, 89, 89, 91, 92, 93, 94, 95, 97}, 25, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -90, -86, -78, -78, -74, -72, -64, -64, -58, -56, -50, -46, -44, -36, -26, -14, -12, -10, -4, 4, 10, 16, 18, 22, 30, 32, 38, 46, 46, 50, 54, 56, 72, 74, 82, 86, 86, 88, 90, 96}, 23, false); \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, 1, 1, 1, 1}, 10, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({24, 24, 41, 80, 90, 95}, 4, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -88, -84, -82, -82, -80, -70, -66, -62, -60, -60, -48, -46, -44, -42, -20, -16, -4, 18, 26, 28, 32, 36, 46, 60, 62, 68, 72, 78, 98}, 21, true); \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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 9, 14, 16, 16, 26, 30, 31, 32, 37, 42, 42, 43, 49, 51, 56, 64, 69, 76, 77, 77, 79, 85, 88, 89, 91, 94, 95}, 19, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -84, -74, -68, -66, -60, -60, -60, -58, -52, -50, -42, -38, -34, -30, 6, 30, 42, 60, 80, 94, 98}, 11, 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, 1, 1, 1, 1, 1, 1, 1, 1}, 18, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 3, 5, 8, 13, 15, 16, 22, 24, 26, 30, 31, 31, 33, 34, 39, 39, 40, 46, 49, 50, 51, 52, 59, 66, 69, 77, 80, 88, 90}, 23, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "possibleFormTriangleArrayValues",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"arr\": [2, 6, 8, 10, 14, 15, 16, 19, 21, 26, 26, 26, 28, 29, 30, 33, 33, 35, 36, 36, 41, 44, 45, 45, 45, 49, 51, 54, 57, 59, 61, 64, 68, 70, 70, 72, 73, 74, 76, 78, 87, 89, 89, 91, 92, 93, 94, 95, 97], \"n\": 25}}, {\"idx\": 1, \"outputs\": null, \"inputs\": {\"arr\": [-96, -94, -90, -86, -78, -78, -74, -72, -64, -64, -58, -56, -50, -46, -44, -36, -26, -14, -12, -10, -4, 4, 10, 16, 18, 22, 30, 32, 38, 46, 46, 50, 54, 56, 72, 74, 82, 86, 86, 88, 90, 96], \"n\": 23}}, {\"idx\": 2, \"outputs\": null, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 10}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [24, 24, 41, 80, 90, 95], \"n\": 4}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-90, -88, -84, -82, -82, -80, -70, -66, -62, -60, -60, -48, -46, -44, -42, -20, -16, -4, 18, 26, 28, 32, 36, 46, 60, 62, 68, 72, 78, 98], \"n\": 21}}, {\"idx\": 5, \"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], \"n\": 25}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"arr\": [3, 9, 14, 16, 16, 26, 30, 31, 32, 37, 42, 42, 43, 49, 51, 56, 64, 69, 76, 77, 77, 79, 85, 88, 89, 91, 94, 95], \"n\": 19}}, {\"idx\": 7, \"outputs\": null, \"inputs\": {\"arr\": [-90, -84, -74, -68, -66, -60, -60, -60, -58, -52, -50, -42, -38, -34, -30, 6, 30, 42, 60, 80, 94, 98], \"n\": 11}}, {\"idx\": 8, \"outputs\": true, \"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], \"n\": 18}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"arr\": [1, 3, 5, 8, 13, 15, 16, 22, 24, 26, 30, 31, 31, 33, 34, 39, 39, 40, 46, 49, 50, 51, 52, 59, 66, 69, 77, 80, 88, 90], \"n\": 23}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
423 | Possible To Make A Divisible By 3 Number Using All Digits In An Array | C++ | bool possibleToMakeADivisibleBy3NumberUsingAllDigitsInAnArray(vector<int> arr, int n) { | [
"arr",
"n"
] | def possible_to_make_a_divisible_by_3_number_using_all_digits_in_an_array(arr, n):
remainder = 0
for i in range(0, n):
remainder = ((remainder + arr[i]) % 3)
return (remainder == 0) | bool possible_to_make_a_divisible_by_3_number_using_all_digits_in_an_array(vector<int> arr, int n) {
int remainder = 0;
for ( int i = 0;
i < n;
i ++ ) remainder = ( remainder + arr [ i ] ) % 3;
return ( remainder == 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, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 4, 9, 11, 12, 15, 16, 19, 21, 21, 23, 23, 24, 30, 31, 31, 32, 34, 37, 41, 41, 43, 45, 46, 47, 54, 58, 60, 62, 66, 66, 74, 74, 75, 75, 77, 77, 85, 89, 90, 92, 92, 93, 95, 98}, 30, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 66, 92, 24, -8, 88, -92, 86, 80, 82, 42, -20, -56, -2, -84, 32}, 14, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 83, 11, 99, 80, 76, 32, 12, 94, 66, 76}, 5, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -84, -80, -80, -80, -80, -72, -68, -64, -62, -60, -52, -48, -44, -36, -24, -20, -18, -14, -8, -6, -6, -4, 6, 10, 14, 18, 24, 26, 26, 50, 50, 52, 60, 76, 90, 96, 98}, 19, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1}, 14, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 6, 8, 8, 10, 24, 24, 26, 27, 30, 34, 34, 36, 36, 39, 40, 41, 44, 45, 50, 52, 53, 57, 62, 64, 64, 70, 71, 72, 78, 78, 79, 80, 82, 89, 95, 96}, 28, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-28, -84, -14, -20, -14, -26, 28, -66, 48, 82, -46, -10, -94, 76, 56, -6, 72, -92, -32, 66, 50, -72, 64, 12, 48, 88, -36, -12, -6, -18, -36, -34, 44, 40, -54}, 25, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 19, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({17, 47, 89, 75, 57, 69, 70, 57, 83, 79, 57, 49}, 8, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "possibleToMakeADivisibleBy3NumberUsingAllDigitsInAnArray",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [2, 4, 9, 11, 12, 15, 16, 19, 21, 21, 23, 23, 24, 30, 31, 31, 32, 34, 37, 41, 41, 43, 45, 46, 47, 54, 58, 60, 62, 66, 66, 74, 74, 75, 75, 77, 77, 85, 89, 90, 92, 92, 93, 95, 98], \"n\": 30}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [0, 66, 92, 24, -8, 88, -92, 86, 80, 82, 42, -20, -56, -2, -84, 32], \"n\": 14}}, {\"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, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [99, 83, 11, 99, 80, 76, 32, 12, 94, 66, 76], \"n\": 5}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-88, -84, -80, -80, -80, -80, -72, -68, -64, -62, -60, -52, -48, -44, -36, -24, -20, -18, -14, -8, -6, -6, -4, 6, 10, 14, 18, 24, 26, 26, 50, 50, 52, 60, 76, 90, 96, 98], \"n\": 19}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1], \"n\": 14}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [6, 6, 8, 8, 10, 24, 24, 26, 27, 30, 34, 34, 36, 36, 39, 40, 41, 44, 45, 50, 52, 53, 57, 62, 64, 64, 70, 71, 72, 78, 78, 79, 80, 82, 89, 95, 96], \"n\": 28}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [-28, -84, -14, -20, -14, -26, 28, -66, 48, 82, -46, -10, -94, 76, 56, -6, 72, -92, -32, 66, 50, -72, 64, 12, 48, 88, -36, -12, -6, -18, -36, -34, 44, 40, -54], \"n\": 25}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 19}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [17, 47, 89, 75, 57, 69, 70, 57, 83, 79, 57, 49], \"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
]
} |
424 | Primality Test Set 1 Introduction And School Method | C++ | bool primalityTestSet1IntroductionAndSchoolMethod(int n) { | [
"n"
] | def primality_test_set_1_introduction_and_school_method(n):
if (n <= 1):
return False
for i in range(2, n):
if ((n % i) == 0):
return False
return True | bool primality_test_set_1_introduction_and_school_method(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(37, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}",
"entry_fn_name": "primalityTestSet1IntroductionAndSchoolMethod",
"entry_cls_name": "Solution",
"extension": "cpp",
"test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 37}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"n\": 39}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 73}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": 8}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 28}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 66}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 20}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 36}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 6}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 51}}]",
"test_case_ids": [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9"
],
"commands": [
[
"g++",
"__FILENAME__",
"-o",
"main.exe"
],
[
"./main.exe"
]
],
"timeouts": [
10,
10
]
} |
Subsets and Splits