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
210
Find The First Missing Number
C++
int findTheFirstMissingNumber(vector<int> array, int start, int end_arg2) {
[ "array", "start", "end_arg2" ]
def find_the_first_missing_number(array, start, end): if (start > end): return (end + 1) if (start != array[start]): return start mid = int(((start + end) / 2)) if (array[mid] == mid): return find_the_first_missing_number(array, (mid + 1), end) return find_the_first_missing_number(array, start, mid)
int find_the_first_missing_number(vector<int> array, int start, int end) { if ( start > end ) return end + 1; if ( start != array [ start ] ) return start; int mid = ( start + end ) / 2; if ( array [ mid ] == mid ) return find_the_first_missing_number ( array, mid + 1, end ); return find_the_first_missing_number ( array, start, mid ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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> array, int start, int end_arg2, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(array, start, end_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({3, 6, 7, 9, 11, 14, 18, 30, 30, 32, 32, 34, 37, 44, 45, 45, 48, 48, 48, 52, 58, 60, 63, 67, 69, 69, 81, 83, 87, 89, 97, 99}, 24, 18, 19); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({88, -62, 16, 80, 66, 78, 88, 38, 52, -96, 48, 98, 96, -62, 18, 34, -58, 30, -10, 26, -98, 48, -96, 4, 92, 36, 36, -36, -32, -70, 62, -58, -58, -84, 86, -98}, 19, 26, 19); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 26, 28, 26); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({79, 99, 79, 85, 61, 58, 62, 61, 39, 87, 39, 74, 36, 70, 30, 43, 20, 52, 54, 50, 81, 98, 42}, 20, 20, 20); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -72, -46, -44, -42, -40, -16, -4, 62, 70, 74}, 8, 10, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, 26, 23, 24); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58}, 0, 0, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, -84, -42, 12, -50, 42, -36, -38, -36, 98, -2, 20, 6, -96, -78, 24, 34, 88, 0, 74, 0, -8, -86, -68, -42, 98, -26, 86, -70, -32, -82, 78, 46, 58, 84, 4, -60, -90, -52, -78}, 37, 31, 32); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 28, 28, 28); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8}, 0, 0, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheFirstMissingNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 19, \"inputs\": {\"array\": [3, 6, 7, 9, 11, 14, 18, 30, 30, 32, 32, 34, 37, 44, 45, 45, 48, 48, 48, 52, 58, 60, 63, 67, 69, 69, 81, 83, 87, 89, 97, 99], \"start\": 24, \"end_arg2\": 18}}, {\"idx\": 1, \"outputs\": 19, \"inputs\": {\"array\": [88, -62, 16, 80, 66, 78, 88, 38, 52, -96, 48, 98, 96, -62, 18, 34, -58, 30, -10, 26, -98, 48, -96, 4, 92, 36, 36, -36, -32, -70, 62, -58, -58, -84, 86, -98], \"start\": 19, \"end_arg2\": 26}}, {\"idx\": 2, \"outputs\": 26, \"inputs\": {\"array\": [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], \"start\": 26, \"end_arg2\": 28}}, {\"idx\": 3, \"outputs\": 20, \"inputs\": {\"array\": [79, 99, 79, 85, 61, 58, 62, 61, 39, 87, 39, 74, 36, 70, 30, 43, 20, 52, 54, 50, 81, 98, 42], \"start\": 20, \"end_arg2\": 20}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"array\": [-98, -72, -46, -44, -42, -40, -16, -4, 62, 70, 74], \"start\": 8, \"end_arg2\": 10}}, {\"idx\": 5, \"outputs\": 24, \"inputs\": {\"array\": [1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], \"start\": 26, \"end_arg2\": 23}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"array\": [58], \"start\": 0, \"end_arg2\": 0}}, {\"idx\": 7, \"outputs\": 32, \"inputs\": {\"array\": [4, -84, -42, 12, -50, 42, -36, -38, -36, 98, -2, 20, 6, -96, -78, 24, 34, 88, 0, 74, 0, -8, -86, -68, -42, 98, -26, 86, -70, -32, -82, 78, 46, 58, 84, 4, -60, -90, -52, -78], \"start\": 37, \"end_arg2\": 31}}, {\"idx\": 8, \"outputs\": 28, \"inputs\": {\"array\": [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], \"start\": 28, \"end_arg2\": 28}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"array\": [8], \"start\": 0, \"end_arg2\": 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 ] }
211
Find The Maximum Element In An Array Which Is First Increasing And Then Decreasing
C++
int findTheMaximumElementInAnArrayWhichIsFirstIncreasingAndThenDecreasing(vector<int> arr, int low, int high) {
[ "arr", "low", "high" ]
def find_the_maximum_element_in_an_array_which_is_first_increasing_and_then_decreasing(arr, low, high): max = arr[low] i = low for i in range((high + 1)): if (arr[i] > max): max = arr[i] return max
int find_the_maximum_element_in_an_array_which_is_first_increasing_and_then_decreasing(vector<int> arr, int low, int high) { int max = arr [ low ]; int i; for ( i = low + 1; i <= high; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ]; else break; } return 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 low, int high, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, low, high), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({11, 15, 16, 19, 24, 25, 26, 28, 34, 34, 43, 61, 63, 66, 67, 72, 77, 79, 81, 83, 87, 94, 99}, 15, 21, 94); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 92}, 1, 1, 92); \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}, 23, 15, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({84, 39, 92, 89, 38, 75, 18, 39, 83, 67, 41, 46, 49, 27}, 8, 13, 92); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -94, -88, -84, -74, -72, -58, -52, -48, -48, -46, -42, -42, -32, -30, -30, -18, -10, -8, -8, -6, -4, 4, 6, 28, 30, 34, 38, 44, 48, 56, 58, 60, 64, 86}, 31, 34, 86); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0}, 2, 2, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 9, 10, 16, 18, 19, 23, 24, 26, 33, 37, 44, 46, 54, 55, 57, 58, 59, 63, 64, 70, 75, 77, 81, 83, 84, 85, 85, 88, 89, 96, 97, 99}, 20, 31, 97); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 20, -50, 74, -78, 86}, 3, 5, 86); \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}, 19, 18, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, 57, 65, 61, 17, 63, 7, 35, 69, 91, 30, 44, 99, 80, 6, 80, 56, 8, 84, 95, 20, 73, 30, 62, 77, 26, 66, 61, 61, 45}, 28, 22, 99); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheMaximumElementInAnArrayWhichIsFirstIncreasingAndThenDecreasing", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 94, \"inputs\": {\"arr\": [11, 15, 16, 19, 24, 25, 26, 28, 34, 34, 43, 61, 63, 66, 67, 72, 77, 79, 81, 83, 87, 94, 99], \"low\": 15, \"high\": 21}}, {\"idx\": 1, \"outputs\": 92, \"inputs\": {\"arr\": [8, 92], \"low\": 1, \"high\": 1}}, {\"idx\": 2, \"outputs\": 1, \"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], \"low\": 23, \"high\": 15}}, {\"idx\": 3, \"outputs\": 92, \"inputs\": {\"arr\": [84, 39, 92, 89, 38, 75, 18, 39, 83, 67, 41, 46, 49, 27], \"low\": 8, \"high\": 13}}, {\"idx\": 4, \"outputs\": 86, \"inputs\": {\"arr\": [-98, -94, -88, -84, -74, -72, -58, -52, -48, -48, -46, -42, -42, -32, -30, -30, -18, -10, -8, -8, -6, -4, 4, 6, 28, 30, 34, 38, 44, 48, 56, 58, 60, 64, 86], \"low\": 31, \"high\": 34}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1, 0], \"low\": 2, \"high\": 2}}, {\"idx\": 6, \"outputs\": 97, \"inputs\": {\"arr\": [5, 9, 10, 16, 18, 19, 23, 24, 26, 33, 37, 44, 46, 54, 55, 57, 58, 59, 63, 64, 70, 75, 77, 81, 83, 84, 85, 85, 88, 89, 96, 97, 99], \"low\": 20, \"high\": 31}}, {\"idx\": 7, \"outputs\": 86, \"inputs\": {\"arr\": [86, 20, -50, 74, -78, 86], \"low\": 3, \"high\": 5}}, {\"idx\": 8, \"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], \"low\": 19, \"high\": 18}}, {\"idx\": 9, \"outputs\": 99, \"inputs\": {\"arr\": [16, 57, 65, 61, 17, 63, 7, 35, 69, 91, 30, 44, 99, 80, 6, 80, 56, 8, 84, 95, 20, 73, 30, 62, 77, 26, 66, 61, 61, 45], \"low\": 28, \"high\": 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 ] }
212
Find The Maximum Subarray Xor In A Given Array
C++
int findTheMaximumSubarrayXorInAGivenArray(vector<int> arr, int n) {
[ "arr", "n" ]
def find_the_maximum_subarray_xor_in_a_given_array(arr, n): ans = (- 2147483648) for i in range(n): curr_xor = 0 for j in range(i, n): curr_xor = (curr_xor ^ arr[j]) ans = max(ans, curr_xor) return ans
int find_the_maximum_subarray_xor_in_a_given_array(vector<int> arr, int n) { int ans = INT_MIN; for ( int i = 0; i < n; i ++ ) { int curr_xor = 0; for ( int j = i; j < n; j ++ ) { curr_xor = curr_xor ^ arr [ j ]; ans = max ( ans, curr_xor ); } } return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 7, 7, 11, 12, 18, 20, 23, 27, 30, 44, 47, 53, 53, 55, 57, 57, 58, 61, 62, 67, 74, 76, 80, 86, 86}, 13, 63); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-34, -4, 68, -82, 54, 20, 6, -18, -70, 98, -40, 80, -28, 78, 28, 56, 26, 2, 2, -56, -66, 44, 0, -72, 12, 54, -40, 18, 28, -48, -56, 72, 84, 60, 76, 26, -8, 62}, 21, 126); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 12, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({33, 98}, 1, 33); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -80, -76, -76, -74, -58, -44, -38, -34, -32, -30, -24, -20, -18, -4, -2, 2, 8, 44, 52, 52, 56, 70, 72, 80, 80, 98}, 15, 126); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0}, 33, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 3, 6, 9, 15, 15, 18, 19, 25, 31, 31, 33, 37, 39, 47, 49, 51, 51, 52, 52, 54, 58, 59, 59, 61, 62, 62, 65, 66, 66, 66, 66, 67, 71, 76, 77, 78, 79, 80, 83, 86, 87, 92, 97, 97, 98, 99}, 38, 127); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({34, -90, 64, 88, -46, -4, -96, 76, -32, 10, -8, -24, 32, -4, 86, -20, -86, -88, -72, 64, 12, 66, -96, -84, 16, -58, -48, 80, -80, 70, -94, -84, 56, 8, -14, 86, 72, -16, -18, 74, 40, 34, 20, 80}, 35, 126); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1}, 1, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({57, 76, 2, 30, 24, 12, 49, 12, 5, 75, 55, 17, 62, 87, 21, 91, 88, 10, 20, 49, 46, 79, 51, 33, 94, 59, 48, 97, 70, 49}, 25, 127); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheMaximumSubarrayXorInAGivenArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 63, \"inputs\": {\"arr\": [1, 7, 7, 11, 12, 18, 20, 23, 27, 30, 44, 47, 53, 53, 55, 57, 57, 58, 61, 62, 67, 74, 76, 80, 86, 86], \"n\": 13}}, {\"idx\": 1, \"outputs\": 126, \"inputs\": {\"arr\": [-34, -4, 68, -82, 54, 20, 6, -18, -70, 98, -40, 80, -28, 78, 28, 56, 26, 2, 2, -56, -66, 44, 0, -72, 12, 54, -40, 18, 28, -48, -56, 72, 84, 60, 76, 26, -8, 62], \"n\": 21}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 12}}, {\"idx\": 3, \"outputs\": 33, \"inputs\": {\"arr\": [33, 98], \"n\": 1}}, {\"idx\": 4, \"outputs\": 126, \"inputs\": {\"arr\": [-92, -80, -76, -76, -74, -58, -44, -38, -34, -32, -30, -24, -20, -18, -4, -2, 2, 8, 44, 52, 52, 56, 70, 72, 80, 80, 98], \"n\": 15}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0], \"n\": 33}}, {\"idx\": 6, \"outputs\": 127, \"inputs\": {\"arr\": [1, 2, 3, 6, 9, 15, 15, 18, 19, 25, 31, 31, 33, 37, 39, 47, 49, 51, 51, 52, 52, 54, 58, 59, 59, 61, 62, 62, 65, 66, 66, 66, 66, 67, 71, 76, 77, 78, 79, 80, 83, 86, 87, 92, 97, 97, 98, 99], \"n\": 38}}, {\"idx\": 7, \"outputs\": 126, \"inputs\": {\"arr\": [34, -90, 64, 88, -46, -4, -96, 76, -32, 10, -8, -24, 32, -4, 86, -20, -86, -88, -72, 64, 12, 66, -96, -84, 16, -58, -48, 80, -80, 70, -94, -84, 56, 8, -14, 86, 72, -16, -18, 74, 40, 34, 20, 80], \"n\": 35}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1], \"n\": 1}}, {\"idx\": 9, \"outputs\": 127, \"inputs\": {\"arr\": [57, 76, 2, 30, 24, 12, 49, 12, 5, 75, 55, 17, 62, 87, 21, 91, 88, 10, 20, 49, 46, 79, 51, 33, 94, 59, 48, 97, 70, 49], \"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 ] }
213
Find The Minimum Distance Between Two Numbers
C++
int findTheMinimumDistanceBetweenTwoNumbers(vector<int> arr, int n, int x, int y) {
[ "arr", "n", "x", "y" ]
def find_the_minimum_distance_between_two_numbers(arr, n, x, y): min_dist = 99999999 for i in range(n): for j in range((i + 1), n): if ((((x == arr[i]) and (y == arr[j])) or ((y == arr[i]) and (x == arr[j]))) and (min_dist > abs((i - j)))): min_dist = abs((i - j)) return min_dist
int find_the_minimum_distance_between_two_numbers(vector<int> arr, int n, int x, int y) { int i, j; int min_dist = INT_MAX; for ( i = 0; i < n; i ++ ) { for ( j = i + 1; j < n; j ++ ) { if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) { min_dist = abs ( i - j ); } } } return min_dist; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 7, 7, 8, 11, 14, 16, 25, 34, 35, 36, 36, 38, 40, 41, 43, 45, 47, 57, 60, 64, 72, 73, 74, 75, 82, 83, 83, 84, 84, 84, 92}, 22, 7, 40, 99999999); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 70, 88, -64, -42, 58, 92, 66, -14, 90, -66, 12, 88, -12, 48, -4, 90, 24, 98, 14, 32, 38, 98, 78, 2, 26, 12, -36, 90, 80, 40, 58, 88, 64, 16}, 25, 58, 70, 99999999); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1}, 1, 1, 1, 99999999); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 96, 82, 73, 30, 36, 56, 20, 5, 36, 4, 7, 89, 63, 54, 97, 80, 56, 93, 34, 90, 56, 25, 27, 75, 68, 14, 90}, 26, 54, 82, 99999999); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -88, -82, -66, -62, -52, -52, -46, -46, -40, -40, -28, -24, -12, 0, 4, 10, 24, 42, 46, 48, 48, 50, 60, 62, 64, 64, 70, 92, 98}, 24, 0, 4, 99999999); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1}, 10, 0, 1, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 2, 6, 10, 14, 15, 18, 19, 22, 23, 29, 30, 37, 40, 40, 41, 41, 42, 42, 44, 46, 46, 54, 56, 72, 73, 81, 83, 83, 86, 88, 93}, 27, 1, 42, 18); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 86, -52, 18, -32, 86, 2, 38, 72, 72, -60, 70, -58, 66, -66, -72, -74, 58, 52, 58, 16, 64, 62, -62, 80, -70, -96, -44, -20, -74, -10, 14, -32, 48, 30, 76, -16, 80, 66, -46, -92, 26, -86, 28, -76, -24, -98, 54, 50}, 30, 25, 45, 99999999); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 38, 0, 0, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32, 65, 10, 72, 17, 58, 79, 28, 67, 36, 18, 35}, 7, 10, 7, 99999999); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheMinimumDistanceBetweenTwoNumbers", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 99999999, \"inputs\": {\"arr\": [4, 7, 7, 8, 11, 14, 16, 25, 34, 35, 36, 36, 38, 40, 41, 43, 45, 47, 57, 60, 64, 72, 73, 74, 75, 82, 83, 83, 84, 84, 84, 92], \"n\": 22, \"x\": 7, \"y\": 40}}, {\"idx\": 1, \"outputs\": 99999999, \"inputs\": {\"arr\": [96, 70, 88, -64, -42, 58, 92, 66, -14, 90, -66, 12, 88, -12, 48, -4, 90, 24, 98, 14, 32, 38, 98, 78, 2, 26, 12, -36, 90, 80, 40, 58, 88, 64, 16], \"n\": 25, \"x\": 58, \"y\": 70}}, {\"idx\": 2, \"outputs\": 99999999, \"inputs\": {\"arr\": [0, 0, 1], \"n\": 1, \"x\": 1, \"y\": 1}}, {\"idx\": 3, \"outputs\": 99999999, \"inputs\": {\"arr\": [46, 96, 82, 73, 30, 36, 56, 20, 5, 36, 4, 7, 89, 63, 54, 97, 80, 56, 93, 34, 90, 56, 25, 27, 75, 68, 14, 90], \"n\": 26, \"x\": 54, \"y\": 82}}, {\"idx\": 4, \"outputs\": 99999999, \"inputs\": {\"arr\": [-96, -88, -82, -66, -62, -52, -52, -46, -46, -40, -40, -28, -24, -12, 0, 4, 10, 24, 42, 46, 48, 48, 50, 60, 62, 64, 64, 70, 92, 98], \"n\": 24, \"x\": 0, \"y\": 4}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1], \"n\": 10, \"x\": 0, \"y\": 1}}, {\"idx\": 6, \"outputs\": 18, \"inputs\": {\"arr\": [1, 2, 2, 6, 10, 14, 15, 18, 19, 22, 23, 29, 30, 37, 40, 40, 41, 41, 42, 42, 44, 46, 46, 54, 56, 72, 73, 81, 83, 83, 86, 88, 93], \"n\": 27, \"x\": 1, \"y\": 42}}, {\"idx\": 7, \"outputs\": 99999999, \"inputs\": {\"arr\": [46, 86, -52, 18, -32, 86, 2, 38, 72, 72, -60, 70, -58, 66, -66, -72, -74, 58, 52, 58, 16, 64, 62, -62, 80, -70, -96, -44, -20, -74, -10, 14, -32, 48, 30, 76, -16, 80, 66, -46, -92, 26, -86, 28, -76, -24, -98, 54, 50], \"n\": 30, \"x\": 25, \"y\": 45}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 38, \"x\": 0, \"y\": 0}}, {\"idx\": 9, \"outputs\": 99999999, \"inputs\": {\"arr\": [32, 65, 10, 72, 17, 58, 79, 28, 67, 36, 18, 35], \"n\": 7, \"x\": 10, \"y\": 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 ] }
214
Find The Minimum Distance Between Two Numbers 1
C++
int findTheMinimumDistanceBetweenTwoNumbers1(vector<int> arr, int n, int x, int y) {
[ "arr", "n", "x", "y" ]
def find_the_minimum_distance_between_two_numbers_1(arr, n, x, y): min_dist = sys.maxsize for i in range(n): if ((arr[i] == x) or (arr[i] == y)): prev = i break while (i < n): if ((arr[i] == x) or (arr[i] == y)): if ((arr[prev] != arr[i]) and ((i - prev) < min_dist)): min_dist = (i - prev) prev = i else: prev = i i += 1 return min_dist
int find_the_minimum_distance_between_two_numbers_1(vector<int> arr, int n, int x, int y) { int i = 0; int min_dist = INT_MAX; int prev; for ( i = 0; i < n; i ++ ) { if ( arr [ i ] == x || arr [ i ] == y ) { prev = i; break; } } for (; i < n; i ++ ) { if ( arr [ i ] == x || arr [ i ] == y ) { if ( arr [ prev ] != arr [ i ] && ( i - prev ) < min_dist ) { min_dist = i - prev; prev = i; } else prev = i; } } return min_dist; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 7, 7, 8, 11, 14, 16, 25, 34, 35, 36, 36, 38, 40, 41, 43, 45, 47, 57, 60, 64, 72, 73, 74, 75, 82, 83, 83, 84, 84, 84, 92}, 22, 7, 40, 11); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, 70, 88, -64, -42, 58, 92, 66, -14, 90, -66, 12, 88, -12, 48, -4, 90, 24, 98, 14, 32, 38, 98, 78, 2, 26, 12, -36, 90, 80, 40, 58, 88, 64, 16}, 25, 58, 70, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 96, 82, 73, 30, 36, 56, 20, 5, 36, 4, 7, 89, 63, 54, 97, 80, 56, 93, 34, 90, 56, 25, 27, 75, 68, 14, 90}, 26, 54, 82, 12); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -88, -82, -66, -62, -52, -52, -46, -46, -40, -40, -28, -24, -12, 0, 4, 10, 24, 42, 46, 48, 48, 50, 60, 62, 64, 64, 70, 92, 98}, 24, 0, 4, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1}, 10, 0, 1, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 2, 6, 10, 14, 15, 18, 19, 22, 23, 29, 30, 37, 40, 40, 41, 41, 42, 42, 44, 46, 46, 54, 56, 72, 73, 81, 83, 83, 86, 88, 93}, 27, 1, 42, 18); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheMinimumDistanceBetweenTwoNumbers1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 11, \"inputs\": {\"arr\": [4, 7, 7, 8, 11, 14, 16, 25, 34, 35, 36, 36, 38, 40, 41, 43, 45, 47, 57, 60, 64, 72, 73, 74, 75, 82, 83, 83, 84, 84, 84, 92], \"n\": 22, \"x\": 7, \"y\": 40}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"arr\": [96, 70, 88, -64, -42, 58, 92, 66, -14, 90, -66, 12, 88, -12, 48, -4, 90, 24, 98, 14, 32, 38, 98, 78, 2, 26, 12, -36, 90, 80, 40, 58, 88, 64, 16], \"n\": 25, \"x\": 58, \"y\": 70}}, {\"idx\": 2, \"outputs\": 12, \"inputs\": {\"arr\": [46, 96, 82, 73, 30, 36, 56, 20, 5, 36, 4, 7, 89, 63, 54, 97, 80, 56, 93, 34, 90, 56, 25, 27, 75, 68, 14, 90], \"n\": 26, \"x\": 54, \"y\": 82}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [-96, -88, -82, -66, -62, -52, -52, -46, -46, -40, -40, -28, -24, -12, 0, 4, 10, 24, 42, 46, 48, 48, 50, 60, 62, 64, 64, 70, 92, 98], \"n\": 24, \"x\": 0, \"y\": 4}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1], \"n\": 10, \"x\": 0, \"y\": 1}}, {\"idx\": 5, \"outputs\": 18, \"inputs\": {\"arr\": [1, 2, 2, 6, 10, 14, 15, 18, 19, 22, 23, 29, 30, 37, 40, 40, 41, 41, 42, 42, 44, 46, 46, 54, 56, 72, 73, 81, 83, 83, 86, 88, 93], \"n\": 27, \"x\": 1, \"y\": 42}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
215
Find The Missing Number 1
C++
int findTheMissingNumber1(vector<int> a, int n) {
[ "a", "n" ]
def find_the_missing_number_1(a, n): (i, total) = (0, 1) for i in range(2, (n + 2)): total += i total -= a[(i - 2)] return total
int find_the_missing_number_1(vector<int> a, int n) { int i, total = 1; for ( i = 2; i <= ( n + 1 ); i ++ ) { total += i; total -= a [ i - 2 ]; } 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(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({13, 27, 46, 59, 62, 82, 92}, 6, -261); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, 86, -64, -20, -56, -16, 86, 42, 72, -90, 10, 42, 56, 8, 50, 24, -34, 0, -78, 64, 18, 20, -84, -22, 90, -20, 86, 26, -54, 0, 90, -48, 4, 88, 18, -64, -22, -74, 48, -36, -86, -24, 88, -64, 68, 62, 92}, 38, 524); \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}, 15, 131); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({55, 89, 56, 85, 26, 4, 91, 91, 3, 77, 63, 59, 76, 90, 1, 94, 44, 70, 8, 54, 3, 91, 29, 95, 28, 75, 20}, 22, -954); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -84, -80, -78, -66, -62, -54, -52, -26, -8, -8, -6, 4, 4, 8, 14, 26, 58, 60, 62, 62, 76, 78, 86, 92}, 18, 694); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}, 25, 341); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 7, 7, 9, 14, 23, 29, 31, 31, 35, 35, 38, 41, 44, 49, 49, 50, 51, 54, 55, 56, 57, 63, 67, 69, 73, 79, 79, 80, 86, 88, 93}, 24, -506); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, -48, 16, 22, -16, 34, 56, -20, -62, -82, -74, -40, 20, -24, -46, 64, 66, -76, 58, -84, 96, 76, 86, -32, 46}, 12, 227); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, 463); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({73, 76, 25, 59, 40, 85, 90, 38, 13, 97, 93, 99, 45, 7}, 12, -697); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheMissingNumber1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -261, \"inputs\": {\"a\": [13, 27, 46, 59, 62, 82, 92], \"n\": 6}}, {\"idx\": 1, \"outputs\": 524, \"inputs\": {\"a\": [22, 86, -64, -20, -56, -16, 86, 42, 72, -90, 10, 42, 56, 8, 50, 24, -34, 0, -78, 64, 18, 20, -84, -22, 90, -20, 86, 26, -54, 0, 90, -48, 4, 88, 18, -64, -22, -74, 48, -36, -86, -24, 88, -64, 68, 62, 92], \"n\": 38}}, {\"idx\": 2, \"outputs\": 131, \"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], \"n\": 15}}, {\"idx\": 3, \"outputs\": -954, \"inputs\": {\"a\": [55, 89, 56, 85, 26, 4, 91, 91, 3, 77, 63, 59, 76, 90, 1, 94, 44, 70, 8, 54, 3, 91, 29, 95, 28, 75, 20], \"n\": 22}}, {\"idx\": 4, \"outputs\": 694, \"inputs\": {\"a\": [-94, -84, -80, -78, -66, -62, -54, -52, -26, -8, -8, -6, 4, 4, 8, 14, 26, 58, 60, 62, 62, 76, 78, 86, 92], \"n\": 18}}, {\"idx\": 5, \"outputs\": 341, \"inputs\": {\"a\": [1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], \"n\": 25}}, {\"idx\": 6, \"outputs\": -506, \"inputs\": {\"a\": [1, 2, 7, 7, 9, 14, 23, 29, 31, 31, 35, 35, 38, 41, 44, 49, 49, 50, 51, 54, 55, 56, 57, 63, 67, 69, 73, 79, 79, 80, 86, 88, 93], \"n\": 24}}, {\"idx\": 7, \"outputs\": 227, \"inputs\": {\"a\": [78, -48, 16, 22, -16, 34, 56, -20, -62, -82, -74, -40, 20, -24, -46, 64, 66, -76, 58, -84, 96, 76, 86, -32, 46], \"n\": 12}}, {\"idx\": 8, \"outputs\": 463, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29}}, {\"idx\": 9, \"outputs\": -697, \"inputs\": {\"a\": [73, 76, 25, 59, 40, 85, 90, 38, 13, 97, 93, 99, 45, 7], \"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 ] }
216
Find The Missing Number 2
C++
int findTheMissingNumber2(vector<int> a, int n) {
[ "a", "n" ]
def find_the_missing_number_2(a, n): x1 = a[0] x2 = 1 for i in range(1, n): x1 = (x1 ^ a[i]) for i in range(2, (n + 2)): x2 = (x2 ^ i) return (x1 ^ x2)
int find_the_missing_number_2(vector<int> a, int n) { int x1 = a [ 0 ]; int x2 = 1; for ( int i = 1; i < n; i ++ ) x1 = x1 ^ a [ i ]; for ( int i = 2; i <= n + 1; i ++ ) x2 = x2 ^ i; return ( x1 ^ x2 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 5, 7, 8, 10, 14, 27, 32, 51, 52, 57, 58, 65, 68, 68, 72, 73, 73, 83, 92, 98}, 12, 50); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-60, -48, 38, -78, 88, 86, -4, -94, 16, -64, 32, 88, 58, -78, -16, 48, 38, 30, 66, -60, 20, 40, -28, -64, -48, -86, -80, -8, -58, 52, 80, -32, 46, -4, -70, 76, -4, 78, -64, 38, -40}, 28, -91); \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, 1}, 38, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({69, 59, 22, 33, 69, 28, 11, 34, 72, 88, 16, 30, 69, 89, 43, 4, 65, 85, 27}, 13, 109); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -92, -88, -88, -82, -74, -70, -68, -60, -60, -48, -38, -34, -34, -24, 14, 38, 50, 58, 62, 64, 64, 68, 76, 78, 78, 86, 88, 90, 92, 98, 98}, 23, 94); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0}, 41, 42); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 9, 12, 12, 24, 25, 33, 33, 36, 39, 46, 48, 48, 52, 52, 53, 57, 69, 71, 72, 75, 76, 78, 80, 82, 86, 89, 91, 94, 95, 96, 97, 98, 99}, 30, 124); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({62, -66, 60, -92, 46, 6, -52, 48, 72, -64, 34, 20, 50, 70, -34, 20, -70, 14, -44, 66, -70}, 17, 101); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({33, 10, 6, 71, 18, 22, 15, 57, 56, 63, 35, 93, 31, 43, 98, 99, 62, 39, 44, 86, 78, 95, 6, 76, 71}, 12, 32); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheMissingNumber2", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 50, \"inputs\": {\"a\": [2, 5, 7, 8, 10, 14, 27, 32, 51, 52, 57, 58, 65, 68, 68, 72, 73, 73, 83, 92, 98], \"n\": 12}}, {\"idx\": 1, \"outputs\": -91, \"inputs\": {\"a\": [-60, -48, 38, -78, 88, 86, -4, -94, 16, -64, 32, 88, 58, -78, -16, 48, 38, 30, 66, -60, 20, 40, -28, -64, -48, -86, -80, -8, -58, 52, 80, -32, 46, -4, -70, 76, -4, 78, -64, 38, -40], \"n\": 28}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 38}}, {\"idx\": 3, \"outputs\": 109, \"inputs\": {\"a\": [69, 59, 22, 33, 69, 28, 11, 34, 72, 88, 16, 30, 69, 89, 43, 4, 65, 85, 27], \"n\": 13}}, {\"idx\": 4, \"outputs\": 94, \"inputs\": {\"a\": [-98, -98, -92, -88, -88, -82, -74, -70, -68, -60, -60, -48, -38, -34, -34, -24, 14, 38, 50, 58, 62, 64, 64, 68, 76, 78, 78, 86, 88, 90, 92, 98, 98], \"n\": 23}}, {\"idx\": 5, \"outputs\": 42, \"inputs\": {\"a\": [0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0], \"n\": 41}}, {\"idx\": 6, \"outputs\": 124, \"inputs\": {\"a\": [1, 9, 12, 12, 24, 25, 33, 33, 36, 39, 46, 48, 48, 52, 52, 53, 57, 69, 71, 72, 75, 76, 78, 80, 82, 86, 89, 91, 94, 95, 96, 97, 98, 99], \"n\": 30}}, {\"idx\": 7, \"outputs\": 101, \"inputs\": {\"a\": [62, -66, 60, -92, 46, 6, -52, 48, 72, -64, 34, 20, 50, 70, -34, 20, -70, 14, -44, 66, -70], \"n\": 17}}, {\"idx\": 8, \"outputs\": 0, \"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, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 30}}, {\"idx\": 9, \"outputs\": 32, \"inputs\": {\"a\": [33, 10, 6, 71, 18, 22, 15, 57, 56, 63, 35, 93, 31, 43, 98, 99, 62, 39, 44, 86, 78, 95, 6, 76, 71], \"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 ] }
217
Find The Number Occurring Odd Number Of Times
C++
int findTheNumberOccurringOddNumberOfTimes(vector<int> arr, int arr_size) {
[ "arr", "arr_size" ]
def find_the_number_occurring_odd_number_of_times(arr, arr_size): for i in range(0, arr_size): count = 0 for j in range(0, arr_size): if (arr[i] == arr[j]): count += 1 if ((count % 2) != 0): return arr[i] return (- 1)
int find_the_number_occurring_odd_number_of_times(vector<int> arr, int arr_size) { for ( int i = 0; i < arr_size; i ++ ) { int count = 0; for ( int j = 0; j < arr_size; j ++ ) { if ( arr [ i ] == arr [ j ] ) count ++; } if ( count % 2 != 0 ) 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 arr_size, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, arr_size), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 5, 5, 8, 14, 15, 17, 17, 18, 23, 23, 25, 26, 35, 36, 39, 51, 53, 56, 56, 60, 62, 64, 64, 65, 66, 67, 68, 71, 75, 80, 82, 83, 88, 89, 91, 91, 92, 93, 95, 99}, 31, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, 98, 44, 30, -88, 18, 60, 86, 4, 16, 10, 64, -22, -86, -66, -16, 70, -44, 98, 78, -96, -66, 92, 10, 40, -16}, 19, -56); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1}, 6, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({36, 11, 83, 41, 42, 14, 46, 89, 91, 96, 57, 42, 74, 73, 9, 26, 79, 40, 31, 69, 44, 39, 14, 92, 34, 20, 52, 47, 14}, 25, 36); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, -84, -84, -78, -66, -62, -62, -36, -24, -10, -10, -8, -4, -2, 12, 14, 20, 22, 36, 42, 46, 66, 84, 96, 96, 98}, 23, -84); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1}, 19, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 12, 14, 28, 42, 48, 50, 58, 67, 74, 86, 89, 95}, 7, 11); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, -56, -6, 74, 10, 68, 74, 10, 16, -80, 82, -32, 6, -6, 82, 20}, 11, 52); \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}, 31, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 80, 92}, 1, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheNumberOccurringOddNumberOfTimes", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [1, 5, 5, 8, 14, 15, 17, 17, 18, 23, 23, 25, 26, 35, 36, 39, 51, 53, 56, 56, 60, 62, 64, 64, 65, 66, 67, 68, 71, 75, 80, 82, 83, 88, 89, 91, 91, 92, 93, 95, 99], \"arr_size\": 31}}, {\"idx\": 1, \"outputs\": -56, \"inputs\": {\"arr\": [-56, 98, 44, 30, -88, 18, 60, 86, 4, 16, 10, 64, -22, -86, -66, -16, 70, -44, 98, 78, -96, -66, 92, 10, 40, -16], \"arr_size\": 19}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1], \"arr_size\": 6}}, {\"idx\": 3, \"outputs\": 36, \"inputs\": {\"arr\": [36, 11, 83, 41, 42, 14, 46, 89, 91, 96, 57, 42, 74, 73, 9, 26, 79, 40, 31, 69, 44, 39, 14, 92, 34, 20, 52, 47, 14], \"arr_size\": 25}}, {\"idx\": 4, \"outputs\": -84, \"inputs\": {\"arr\": [-84, -84, -84, -78, -66, -62, -62, -36, -24, -10, -10, -8, -4, -2, 12, 14, 20, 22, 36, 42, 46, 66, 84, 96, 96, 98], \"arr_size\": 23}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1], \"arr_size\": 19}}, {\"idx\": 6, \"outputs\": 11, \"inputs\": {\"arr\": [11, 12, 14, 28, 42, 48, 50, 58, 67, 74, 86, 89, 95], \"arr_size\": 7}}, {\"idx\": 7, \"outputs\": 52, \"inputs\": {\"arr\": [52, -56, -6, 74, 10, 68, 74, 10, 16, -80, 82, -32, 6, -6, 82, 20], \"arr_size\": 11}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr_size\": 31}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"arr\": [4, 80, 92], \"arr_size\": 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 ] }
218
Find The Number Occurring Odd Number Of Times 1
C++
int findTheNumberOccurringOddNumberOfTimes1(vector<int> arr, int size) {
[ "arr", "size" ]
def find_the_number_occurring_odd_number_of_times_1(arr, size): Hash = dict() for i in range(size): Hash[arr[i]] = (Hash.get(arr[i], 0) + 1) for i in Hash: if ((Hash[i] % 2) != 0): return i return (- 1)
int find_the_number_occurring_odd_number_of_times_1(vector<int> arr, int size) { unordered_map < int, int > hash; for ( int i = 0; i < size; i ++ ) { hash [ arr [ i ] ] ++; } for ( auto i : hash ) { if ( i . second % 2 != 0 ) { return i . first; } } 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 size, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, size), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({49, 90}, 1, 49); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, 94, 92, -24, 48, 54, -30, -86, 28, -18, 12, -64, -36, 68, 68, -78, -6, 30, -84, 20, 52, -36, 40, -62, 90, -48, 86, 98, 12, 44, 98, -66, 52, 34, 36, 76, -50, -20, -20, -20}, 39, -96); \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({79, 55, 18, 99, 38, 93, 19, 49, 21, 74, 16, 76, 82, 52, 86, 17, 42, 9, 6, 63, 1, 40, 75, 59, 41, 81}, 23, 79); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -84, -82, -68, -66, -66, -60, -60, -48, -44, -36, -34, -30, -16, -14, -12, -10, -6, 2, 10, 10, 14, 22, 26, 30, 34, 46, 50, 52, 62, 64, 64, 66, 72, 74, 78, 78, 82, 84, 88, 92}, 23, -90); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1}, 18, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, 5, 7, 7, 18, 18, 23, 23, 25, 25, 31, 41, 43, 45, 46, 52, 52, 55, 64, 69, 69, 80, 81, 84, 90, 91, 93, 94, 94, 94, 94, 96, 98, 99}, 20, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 66, -8, 2, -18, -22, 38, 4, -38, -54, 78, 64, 78, 20, -32, 84, -70, 66, -46, 12, -12, 8, 44, 14, 20}, 20, 86); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 4, 98, 38, 20, 41, 1, 8}, 7, 11); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheNumberOccurringOddNumberOfTimes1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 49, \"inputs\": {\"arr\": [49, 90], \"size\": 1}}, {\"idx\": 1, \"outputs\": -96, \"inputs\": {\"arr\": [-96, 94, 92, -24, 48, 54, -30, -86, 28, -18, 12, -64, -36, 68, 68, -78, -6, 30, -84, 20, 52, -36, 40, -62, 90, -48, 86, 98, 12, 44, 98, -66, 52, 34, 36, 76, -50, -20, -20, -20], \"size\": 39}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1], \"size\": 1}}, {\"idx\": 3, \"outputs\": 79, \"inputs\": {\"arr\": [79, 55, 18, 99, 38, 93, 19, 49, 21, 74, 16, 76, 82, 52, 86, 17, 42, 9, 6, 63, 1, 40, 75, 59, 41, 81], \"size\": 23}}, {\"idx\": 4, \"outputs\": -90, \"inputs\": {\"arr\": [-90, -84, -82, -68, -66, -66, -60, -60, -48, -44, -36, -34, -30, -16, -14, -12, -10, -6, 2, 10, 10, 14, 22, 26, 30, 34, 46, 50, 52, 62, 64, 64, 66, 72, 74, 78, 78, 82, 84, 88, 92], \"size\": 23}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1], \"size\": 18}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"arr\": [2, 4, 5, 7, 7, 18, 18, 23, 23, 25, 25, 31, 41, 43, 45, 46, 52, 52, 55, 64, 69, 69, 80, 81, 84, 90, 91, 93, 94, 94, 94, 94, 96, 98, 99], \"size\": 20}}, {\"idx\": 7, \"outputs\": 86, \"inputs\": {\"arr\": [86, 66, -8, 2, -18, -22, 38, 4, -38, -54, 78, 64, 78, 20, -32, 84, -70, 66, -46, 12, -12, 8, 44, 14, 20], \"size\": 20}}, {\"idx\": 8, \"outputs\": 0, \"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], \"size\": 21}}, {\"idx\": 9, \"outputs\": 11, \"inputs\": {\"arr\": [11, 4, 98, 38, 20, 41, 1, 8], \"size\": 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 ] }
219
Find Three Element From Different Three Arrays Such That That A B C K
C++
bool findThreeElementFromDifferentThreeArraysSuchThatThatABCK(vector<int> a1, vector<int> a2, vector<int> a3, int n1, int n2, int n3, int sum) {
[ "a1", "a2", "a3", "n1", "n2", "n3", "sum" ]
def find_three_element_from_different_three_arrays_such_that_that_a_b_c_k(a1, a2, a3, n1, n2, n3, sum): for i in range(0, n1): for j in range(0, n2): for k in range(0, n3): if (((a1[i] + a2[j]) + a3[k]) == sum): return True return False
bool find_three_element_from_different_three_arrays_such_that_that_a_b_c_k(vector<int> a1, vector<int> a2, vector<int> a3, int n1, int n2, int n3, int sum) { for ( int i = 0; i < n1; i ++ ) for ( int j = 0; j < n2; j ++ ) for ( int k = 0; k < n3; k ++ ) if ( a1 [ i ] + a2 [ j ] + a3 [ k ] == sum ) 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> a1, vector<int> a2, vector<int> a3, int n1, int n2, int n3, int sum, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a1, a2, a3, n1, n2, n3, sum), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 9, 10, 19, 24, 25, 26, 30, 36, 43, 44, 49, 52, 62, 66, 69, 72, 77, 80, 80, 82, 84, 90, 93, 94, 98}, {4, 8, 17, 20, 22, 25, 27, 30, 31, 33, 35, 35, 38, 41, 49, 51, 60, 61, 66, 67, 69, 82, 84, 85, 86, 88}, {12, 14, 17, 20, 22, 27, 29, 31, 32, 38, 41, 43, 56, 59, 59, 64, 66, 67, 68, 69, 71, 76, 83, 83, 85, 99}, 25, 18, 16, 222, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-24, -80, -72, 80, -96, -94, 64, 18, 12, 16, 74, 16, 54, 66, -96, -90, 54, 72, -32, -2, 90, -18, -98, 12, -42, -30, -82, -56, -86, 40}, {30, -60, -24, 18, 40, 44, -40, 62, 66, -38, 50, -74, -42, -86, -82, -8, 50, -72, -2, -48, -38, -20, -8, 56, -32, 68, 94, 80, -48, 0}, {-24, 80, 50, -56, -92, 20, 86, -42, -30, 96, 40, -32, -64, 54, -38, -72, -70, 54, -28, 98, 60, 98, -12, -30, -30, 68, -66, 68, -58, 52}, 26, 22, 20, 21, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {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, 0, 1, 1, 1, 1, 1, 1}, 14, 14, 14, 2, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, 15, 21, 28, 85, 68, 24}, {57, 46, 47, 49, 16, 81, 60}, {76, 49, 6, 44, 71, 24, 57}, 6, 5, 5, 73, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -82, -66, -44, -44, -38, -22, -6, -2, 14, 26, 40, 54, 58, 60, 66, 72, 80, 94, 96, 98}, {-96, -86, -74, -56, -52, -42, -32, -22, -16, -10, -4, -4, 10, 42, 48, 52, 58, 62, 84, 90, 96}, {-92, -92, -90, -82, -62, -44, -42, -40, -38, -36, -22, -20, -8, 12, 22, 26, 30, 44, 54, 64, 86}, 13, 20, 17, 6, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1}, {1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0}, 25, 25, 23, 0, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({44, 53, 85, 85, 86, 88, 93}, {4, 5, 8, 15, 29, 40, 91}, {30, 53, 71, 75, 76, 82, 84}, 5, 3, 4, 3, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({70, -38, 62, -34, 74, -32, -58, -34, -54}, {48, -86, -18, 14, 88, 92, -56, -8, -74}, {8, 8, 32, 76, 76, 94, 22, -60, -42}, 6, 6, 6, 7, false); \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, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 14, 10, 13, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({41, 64, 39, 96, 54, 54, 57, 4, 82, 43, 44, 56, 1}, {44, 58, 40, 87, 22, 82, 8, 81, 88, 42, 15, 14, 81}, {64, 20, 24, 42, 37, 46, 6, 47, 12, 93, 8, 5, 11}, 7, 8, 6, 10, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findThreeElementFromDifferentThreeArraysSuchThatThatABCK", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"a1\": [4, 9, 10, 19, 24, 25, 26, 30, 36, 43, 44, 49, 52, 62, 66, 69, 72, 77, 80, 80, 82, 84, 90, 93, 94, 98], \"a2\": [4, 8, 17, 20, 22, 25, 27, 30, 31, 33, 35, 35, 38, 41, 49, 51, 60, 61, 66, 67, 69, 82, 84, 85, 86, 88], \"a3\": [12, 14, 17, 20, 22, 27, 29, 31, 32, 38, 41, 43, 56, 59, 59, 64, 66, 67, 68, 69, 71, 76, 83, 83, 85, 99], \"n1\": 25, \"n2\": 18, \"n3\": 16, \"sum\": 222}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"a1\": [-24, -80, -72, 80, -96, -94, 64, 18, 12, 16, 74, 16, 54, 66, -96, -90, 54, 72, -32, -2, 90, -18, -98, 12, -42, -30, -82, -56, -86, 40], \"a2\": [30, -60, -24, 18, 40, 44, -40, 62, 66, -38, 50, -74, -42, -86, -82, -8, 50, -72, -2, -48, -38, -20, -8, 56, -32, 68, 94, 80, -48, 0], \"a3\": [-24, 80, 50, -56, -92, 20, 86, -42, -30, 96, 40, -32, -64, 54, -38, -72, -70, 54, -28, 98, 60, 98, -12, -30, -30, 68, -66, 68, -58, 52], \"n1\": 26, \"n2\": 22, \"n3\": 20, \"sum\": 21}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"a1\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"a2\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"a3\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n1\": 14, \"n2\": 14, \"n3\": 14, \"sum\": 2}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"a1\": [28, 15, 21, 28, 85, 68, 24], \"a2\": [57, 46, 47, 49, 16, 81, 60], \"a3\": [76, 49, 6, 44, 71, 24, 57], \"n1\": 6, \"n2\": 5, \"n3\": 5, \"sum\": 73}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"a1\": [-86, -82, -66, -44, -44, -38, -22, -6, -2, 14, 26, 40, 54, 58, 60, 66, 72, 80, 94, 96, 98], \"a2\": [-96, -86, -74, -56, -52, -42, -32, -22, -16, -10, -4, -4, 10, 42, 48, 52, 58, 62, 84, 90, 96], \"a3\": [-92, -92, -90, -82, -62, -44, -42, -40, -38, -36, -22, -20, -8, 12, 22, 26, 30, 44, 54, 64, 86], \"n1\": 13, \"n2\": 20, \"n3\": 17, \"sum\": 6}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"a1\": [1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1], \"a2\": [0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1], \"a3\": [1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0], \"n1\": 25, \"n2\": 25, \"n3\": 23, \"sum\": 0}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"a1\": [44, 53, 85, 85, 86, 88, 93], \"a2\": [4, 5, 8, 15, 29, 40, 91], \"a3\": [30, 53, 71, 75, 76, 82, 84], \"n1\": 5, \"n2\": 3, \"n3\": 4, \"sum\": 3}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"a1\": [70, -38, 62, -34, 74, -32, -58, -34, -54], \"a2\": [48, -86, -18, 14, 88, 92, -56, -8, -74], \"a3\": [8, 8, 32, 76, 76, 94, 22, -60, -42], \"n1\": 6, \"n2\": 6, \"n3\": 6, \"sum\": 7}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a1\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"a2\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"a3\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n1\": 15, \"n2\": 14, \"n3\": 10, \"sum\": 13}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"a1\": [41, 64, 39, 96, 54, 54, 57, 4, 82, 43, 44, 56, 1], \"a2\": [44, 58, 40, 87, 22, 82, 8, 81, 88, 42, 15, 14, 81], \"a3\": [64, 20, 24, 42, 37, 46, 6, 47, 12, 93, 8, 5, 11], \"n1\": 7, \"n2\": 8, \"n3\": 6, \"sum\": 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 ] }
220
Find Three Element From Different Three Arrays Such That That A B C K 1
C++
bool findThreeElementFromDifferentThreeArraysSuchThatThatABCK1(vector<int> a1, vector<int> a2, vector<int> a3, int n1, int n2, int n3, int sum) {
[ "a1", "a2", "a3", "n1", "n2", "n3", "sum" ]
def find_three_element_from_different_three_arrays_such_that_that_a_b_c_k_1(a1, a2, a3, n1, n2, n3, sum): s = set() for i in range(n1): s.add(a1[i]) for i in range(n2): for j in range(n3): if (((sum - a2[i]) - a3[j]) in s): return True return False
bool find_three_element_from_different_three_arrays_such_that_that_a_b_c_k_1(vector<int> a1, vector<int> a2, vector<int> a3, int n1, int n2, int n3, int sum) { unordered_set < int > s; for ( int i = 0; i < n1; i ++ ) s . insert ( a1 [ i ] ); for ( int i = 0; i < n2; i ++ ) { for ( int j = 0; j < n3; j ++ ) { if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) 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> a1, vector<int> a2, vector<int> a3, int n1, int n2, int n3, int sum, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a1, a2, a3, n1, n2, n3, sum), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({6, 7, 10, 15, 28, 30, 30, 35, 38, 43, 44, 44, 54, 55, 64, 68, 69, 73, 75, 75, 86, 87, 92, 93, 94}, {11, 17, 18, 24, 26, 26, 33, 35, 38, 41, 55, 60, 63, 63, 69, 73, 78, 81, 82, 87, 90, 91, 93, 94, 99}, {3, 3, 8, 22, 24, 24, 28, 30, 32, 32, 34, 39, 40, 45, 46, 50, 54, 59, 75, 78, 79, 90, 95, 95, 97}, 21, 16, 17, 18, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-72, -90, -92, 4, 22, 14, -50, 16, -56, -66, 62, -32, 82, 8, 12, -24, 92, -98, -94, 56, -74, -66, 26, -98, 10, -74, -14, 2, 60, -88, -84, 34, 82, 28, -86, -90, -92, 52, 72, 90, 92, -20, -86, 74, -96, -46, 28}, {50, -20, 26, 32, -46, 38, 36, 0, -96, 60, -70, -36, -12, 50, 64, -70, 22, -22, 32, 60, -94, 98, -58, -86, -16, 40, -68, 2, -50, 6, -36, -28, -68, 44, -98, -38, -46, 68, 4, 60, -36, 28, -38, 4, 50, -84, -12}, {-28, 20, -62, -84, 14, 10, 28, -10, 94, -2, 52, 66, 38, -50, 48, -88, -28, 92, -48, 86, 4, -16, 26, 26, -82, 44, 70, 72, -6, -98, 80, 56, 38, 42, -20, 64, 36, 80, 12, 4, -50, 54, 22, 98, -30, -52, 4}, 41, 42, 34, 32, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {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}, {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}, 26, 20, 30, 16, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 34, 78, 64, 22, 94, 52, 71, 44, 48, 46, 88, 59, 95, 4, 55, 21, 83, 56, 19, 85, 6, 87, 13}, {58, 45, 14, 13, 73, 82, 34, 78, 83, 84, 39, 34, 65, 84, 84, 61, 26, 67, 48, 51, 41, 46, 89, 10}, {46, 1, 2, 90, 31, 49, 62, 10, 28, 4, 48, 84, 87, 51, 88, 74, 99, 15, 35, 24, 32, 66, 10, 66}, 15, 16, 23, 15, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -96, -94, -90, -90, -84, -36, -34, -34, -32, 16, 26, 26, 56, 74, 80}, {-92, -70, -70, -56, -54, -48, -38, -14, -10, 0, 4, 30, 34, 70, 72, 76, 78}, {-92, -88, -70, -56, -50, -50, -48, -36, -20, -10, -8, 2, 16, 22, 48, 70, 78}, 15, 10, 15, 15, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 0, 1, 1, 1, 1}, {0, 0, 1, 0, 0, 1, 0, 1, 0, 1}, {1, 1, 1, 1, 0, 1, 1, 1, 0, 1}, 5, 7, 9, 6, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 4, 25, 27, 35, 39, 50, 60, 60, 63, 67, 73, 75, 81, 84, 85, 91, 98}, {20, 21, 23, 25, 37, 41, 51, 57, 62, 66, 74, 77, 77, 79, 80, 87, 88, 95}, {2, 3, 9, 10, 10, 18, 24, 40, 41, 47, 68, 69, 70, 86, 90, 95, 96, 98}, 12, 17, 13, 9, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({54, -64, 76, 78, 24, 40, 44, -56, 80, -10, -12, -8, -18, 42, 70, 14, -70, 48, -68, -98, -74, -40, -16, -90, 48, 92, -64, 58, -98, 60, -10, -10}, {88, -66, -50, 74, -44, -32, -58, -24, -40, 62, 52, 88, -48, -2, -46, 38, 30, -56, 76, 56, 60, 52, -32, 36, 90, 92, -74, 88, -36, -14, -16, -14}, {38, -96, 16, 38, -48, -22, -52, -78, 42, 94, -26, -20, 12, -10, 72, 16, -8, -2, -36, -76, -6, -92, 10, 34, -76, -54, -20, 20, -76, -46, 24, 44}, 23, 18, 29, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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}, 38, 22, 40, 32, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, 88, 75, 86, 51, 82, 2, 20, 22, 18, 96, 11}, {62, 54, 79, 88, 27, 13, 48, 94, 86, 28, 86, 60}, {49, 14, 18, 61, 94, 54, 12, 56, 97, 59, 85, 44}, 6, 6, 8, 9, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findThreeElementFromDifferentThreeArraysSuchThatThatABCK1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"a1\": [6, 7, 10, 15, 28, 30, 30, 35, 38, 43, 44, 44, 54, 55, 64, 68, 69, 73, 75, 75, 86, 87, 92, 93, 94], \"a2\": [11, 17, 18, 24, 26, 26, 33, 35, 38, 41, 55, 60, 63, 63, 69, 73, 78, 81, 82, 87, 90, 91, 93, 94, 99], \"a3\": [3, 3, 8, 22, 24, 24, 28, 30, 32, 32, 34, 39, 40, 45, 46, 50, 54, 59, 75, 78, 79, 90, 95, 95, 97], \"n1\": 21, \"n2\": 16, \"n3\": 17, \"sum\": 18}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"a1\": [-72, -90, -92, 4, 22, 14, -50, 16, -56, -66, 62, -32, 82, 8, 12, -24, 92, -98, -94, 56, -74, -66, 26, -98, 10, -74, -14, 2, 60, -88, -84, 34, 82, 28, -86, -90, -92, 52, 72, 90, 92, -20, -86, 74, -96, -46, 28], \"a2\": [50, -20, 26, 32, -46, 38, 36, 0, -96, 60, -70, -36, -12, 50, 64, -70, 22, -22, 32, 60, -94, 98, -58, -86, -16, 40, -68, 2, -50, 6, -36, -28, -68, 44, -98, -38, -46, 68, 4, 60, -36, 28, -38, 4, 50, -84, -12], \"a3\": [-28, 20, -62, -84, 14, 10, 28, -10, 94, -2, 52, 66, 38, -50, 48, -88, -28, 92, -48, 86, 4, -16, 26, 26, -82, 44, 70, 72, -6, -98, 80, 56, 38, 42, -20, 64, 36, 80, 12, 4, -50, 54, 22, 98, -30, -52, 4], \"n1\": 41, \"n2\": 42, \"n3\": 34, \"sum\": 32}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"a1\": [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], \"a2\": [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], \"a3\": [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], \"n1\": 26, \"n2\": 20, \"n3\": 30, \"sum\": 16}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"a1\": [85, 34, 78, 64, 22, 94, 52, 71, 44, 48, 46, 88, 59, 95, 4, 55, 21, 83, 56, 19, 85, 6, 87, 13], \"a2\": [58, 45, 14, 13, 73, 82, 34, 78, 83, 84, 39, 34, 65, 84, 84, 61, 26, 67, 48, 51, 41, 46, 89, 10], \"a3\": [46, 1, 2, 90, 31, 49, 62, 10, 28, 4, 48, 84, 87, 51, 88, 74, 99, 15, 35, 24, 32, 66, 10, 66], \"n1\": 15, \"n2\": 16, \"n3\": 23, \"sum\": 15}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"a1\": [-98, -98, -96, -94, -90, -90, -84, -36, -34, -34, -32, 16, 26, 26, 56, 74, 80], \"a2\": [-92, -70, -70, -56, -54, -48, -38, -14, -10, 0, 4, 30, 34, 70, 72, 76, 78], \"a3\": [-92, -88, -70, -56, -50, -50, -48, -36, -20, -10, -8, 2, 16, 22, 48, 70, 78], \"n1\": 15, \"n2\": 10, \"n3\": 15, \"sum\": 15}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"a1\": [1, 1, 1, 0, 0, 0, 1, 1, 1, 1], \"a2\": [0, 0, 1, 0, 0, 1, 0, 1, 0, 1], \"a3\": [1, 1, 1, 1, 0, 1, 1, 1, 0, 1], \"n1\": 5, \"n2\": 7, \"n3\": 9, \"sum\": 6}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"a1\": [4, 4, 25, 27, 35, 39, 50, 60, 60, 63, 67, 73, 75, 81, 84, 85, 91, 98], \"a2\": [20, 21, 23, 25, 37, 41, 51, 57, 62, 66, 74, 77, 77, 79, 80, 87, 88, 95], \"a3\": [2, 3, 9, 10, 10, 18, 24, 40, 41, 47, 68, 69, 70, 86, 90, 95, 96, 98], \"n1\": 12, \"n2\": 17, \"n3\": 13, \"sum\": 9}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"a1\": [54, -64, 76, 78, 24, 40, 44, -56, 80, -10, -12, -8, -18, 42, 70, 14, -70, 48, -68, -98, -74, -40, -16, -90, 48, 92, -64, 58, -98, 60, -10, -10], \"a2\": [88, -66, -50, 74, -44, -32, -58, -24, -40, 62, 52, 88, -48, -2, -46, 38, 30, -56, 76, 56, 60, 52, -32, 36, 90, 92, -74, 88, -36, -14, -16, -14], \"a3\": [38, -96, 16, 38, -48, -22, -52, -78, 42, 94, -26, -20, 12, -10, 72, 16, -8, -2, -36, -76, -6, -92, 10, 34, -76, -54, -20, 20, -76, -46, 24, 44], \"n1\": 23, \"n2\": 18, \"n3\": 29, \"sum\": 19}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a1\": [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], \"a2\": [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], \"a3\": [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], \"n1\": 38, \"n2\": 22, \"n3\": 40, \"sum\": 32}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"a1\": [28, 88, 75, 86, 51, 82, 2, 20, 22, 18, 96, 11], \"a2\": [62, 54, 79, 88, 27, 13, 48, 94, 86, 28, 86, 60], \"a3\": [49, 14, 18, 61, 94, 54, 12, 56, 97, 59, 85, 44], \"n1\": 6, \"n2\": 6, \"n3\": 8, \"sum\": 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 ] }
221
Find Unit Digit X Raised Power Y
C++
int findUnitDigitXRaisedPowerY(int x, int y) {
[ "x", "y" ]
def find_unit_digit_x_raised_power_y(x, y): res = 1 for i in range(y): res = ((res * x) % 10) return res
int find_unit_digit_x_raised_power_y(int x, int y) { int res = 1; for ( int i = 0; i < y; i ++ ) res = ( res * x ) % 10; 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 expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(33, 55, 7); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 7, 5); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 63, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 62, 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 53, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 24, 6); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 23, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 74, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 13, 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 54, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findUnitDigitXRaisedPowerY", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 7, \"inputs\": {\"x\": 33, \"y\": 55}}, {\"idx\": 1, \"outputs\": 5, \"inputs\": {\"x\": 95, \"y\": 7}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"x\": 21, \"y\": 63}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"x\": 3, \"y\": 62}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"x\": 40, \"y\": 53}}, {\"idx\": 5, \"outputs\": 6, \"inputs\": {\"x\": 64, \"y\": 24}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"x\": 17, \"y\": 23}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"x\": 58, \"y\": 74}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"x\": 44, \"y\": 13}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"x\": 27, \"y\": 54}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
222
Find Unit Digit X Raised Power Y 1
C++
int findUnitDigitXRaisedPowerY1(int x, int y) {
[ "x", "y" ]
def find_unit_digit_x_raised_power_y_1(x, y): x = (x % 10) if (y != 0): y = ((y % 4) + 4) return (int(math.pow(x, y)) % 10)
int find_unit_digit_x_raised_power_y_1(int x, int y) { x = x % 10; if ( y != 0 ) y = y % 4 + 4; return ( ( ( int ) ( pow ( x, y ) ) ) % 10 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(37, 17, 7); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 52, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 23, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 96, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 71, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 36, 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 40, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 27, 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 56, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 28, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findUnitDigitXRaisedPowerY1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 7, \"inputs\": {\"x\": 37, \"y\": 17}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"x\": 70, \"y\": 52}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"x\": 26, \"y\": 23}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"x\": 9, \"y\": 96}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"x\": 82, \"y\": 71}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"x\": 95, \"y\": 36}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"x\": 43, \"y\": 40}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"x\": 7, \"y\": 27}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"x\": 19, \"y\": 56}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"x\": 49, \"y\": 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 ] }
223
Find Value Of Y Mod 2 Raised To Power X
C++
int findValueOfYMod2RaisedToPowerX(int y, int x) {
[ "y", "x" ]
def find_value_of_y_mod_2_raised_to_power_x(y, x): return (y % pow(2, x))
long long int find_value_of_y_mod_2_raised_to_power_x(long long int y, long long int x) { if ( log2 ( y ) < x ) return y; if ( x > 63 ) return y; return ( y % ( 1 << x ) ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int y, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(y, 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(57, 76, 57); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 46, 80); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 96, 84); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 16, 35); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 84, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 79, 42); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 2, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 83, 99); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 61, 13); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 8, 44); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findValueOfYMod2RaisedToPowerX", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 57, \"inputs\": {\"y\": 57, \"x\": 76}}, {\"idx\": 1, \"outputs\": 80, \"inputs\": {\"y\": 80, \"x\": 46}}, {\"idx\": 2, \"outputs\": 84, \"inputs\": {\"y\": 84, \"x\": 96}}, {\"idx\": 3, \"outputs\": 35, \"inputs\": {\"y\": 35, \"x\": 16}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"y\": 3, \"x\": 84}}, {\"idx\": 5, \"outputs\": 42, \"inputs\": {\"y\": 42, \"x\": 79}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"y\": 7, \"x\": 2}}, {\"idx\": 7, \"outputs\": 99, \"inputs\": {\"y\": 99, \"x\": 83}}, {\"idx\": 8, \"outputs\": 13, \"inputs\": {\"y\": 13, \"x\": 61}}, {\"idx\": 9, \"outputs\": 44, \"inputs\": {\"y\": 44, \"x\": 8}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
224
Find Whether An Array Is Subset Of Another Array Set 1
C++
int findWhetherAnArrayIsSubsetOfAnotherArraySet1(vector<int> arr1, vector<int> arr2, int m, int n) {
[ "arr1", "arr2", "m", "n" ]
def find_whether_an_array_is_subset_of_another_array_set_1(arr1, arr2, m, n): i = 0 j = 0 for i in range(n): for j in range(m): if (arr2[i] == arr1[j]): break if (j == m): return 0 return 1
bool find_whether_an_array_is_subset_of_another_array_set_1(vector<int> arr1, vector<int> arr2, int m, int n) { int i = 0; int j = 0; for ( i = 0; i < n; i ++ ) { for ( j = 0; j < m; j ++ ) { if ( arr2 [ i ] == arr1 [ j ] ) break; } if ( j == m ) return 0; } return 1; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, 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({7, 10, 10, 10, 13, 17, 23, 24, 25, 28, 30, 33, 37, 49, 49, 50, 57, 60, 60, 63, 63, 64, 65, 65, 72, 81, 84, 85, 85, 94, 96}, {10, 13, 17, 63}, 29, 4, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, 30, -94, -92, -62, -18, -56, 44, -50, -92, 6, 2, 56, -90, 0, 0, 18, 86, -58, 58, -54, 62, -94, 94, 0, 8, 82, -68, -88, -18, 8, -80, -42, 18, 62, -8, 56, -76, -42, 56, 44, -2, -20, 62, -14, 74, -86, -76}, {12, -18, 44}, 46, 3, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0}, 34, 3, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 26, 32, 20, 46, 55, 9, 51, 57, 80, 45, 38, 68, 12, 90, 10, 80, 65, 12, 52, 51, 86, 64, 57, 93, 19, 30, 92, 85, 82, 24, 26, 36, 56}, {80, 58, 32, 2}, 17, 4, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -90, -86, -86, -84, -84, -82, -80, -78, -72, -70, -68, -66, -64, -52, -52, -50, -38, -28, -26, -24, -14, -8, 16, 26, 26, 28, 34, 36, 40, 42, 44, 44, 46, 50, 60, 68, 78, 80, 86, 90, 92, 98}, {-99, -90, -90, -86}, 23, 4, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1}, {0, 0, 1, 1}, 10, 4, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 8, 11, 13, 14, 26, 26, 41, 48, 70, 82, 83, 84, 88, 96}, {1, 9, 12, 16}, 10, 4, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, 80, 62, 76, 48, 92, 18, -94, -62, 98, -46, -50, 70, 32, 68, -54, 26, 16, 94, 0, -84, 2, -16, 88, 26, -38, 18, 64, 90, 80, 76, 2, 14, -90, 50, 4, 76, 30}, {-76, -54, 4, 78}, 27, 4, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, {0, 1, 0, 1}, 10, 4, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({54, 44, 97, 92, 13, 54, 27, 8, 43, 70, 77, 84, 55, 64, 5, 59, 27, 19, 65, 68, 66, 26, 33, 38, 7}, {93, 5, 9, 13}, 19, 4, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findWhetherAnArrayIsSubsetOfAnotherArraySet1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr1\": [7, 10, 10, 10, 13, 17, 23, 24, 25, 28, 30, 33, 37, 49, 49, 50, 57, 60, 60, 63, 63, 64, 65, 65, 72, 81, 84, 85, 85, 94, 96], \"arr2\": [10, 13, 17, 63], \"m\": 29, \"n\": 4}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr1\": [12, 30, -94, -92, -62, -18, -56, 44, -50, -92, 6, 2, 56, -90, 0, 0, 18, 86, -58, 58, -54, 62, -94, 94, 0, 8, 82, -68, -88, -18, 8, -80, -42, 18, 62, -8, 56, -76, -42, 56, 44, -2, -20, 62, -14, 74, -86, -76], \"arr2\": [12, -18, 44], \"m\": 46, \"n\": 3}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 0, 0], \"m\": 34, \"n\": 3}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr1\": [94, 26, 32, 20, 46, 55, 9, 51, 57, 80, 45, 38, 68, 12, 90, 10, 80, 65, 12, 52, 51, 86, 64, 57, 93, 19, 30, 92, 85, 82, 24, 26, 36, 56], \"arr2\": [80, 58, 32, 2], \"m\": 17, \"n\": 4}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr1\": [-98, -90, -86, -86, -84, -84, -82, -80, -78, -72, -70, -68, -66, -64, -52, -52, -50, -38, -28, -26, -24, -14, -8, 16, 26, 26, 28, 34, 36, 40, 42, 44, 44, 46, 50, 60, 68, 78, 80, 86, 90, 92, 98], \"arr2\": [-99, -90, -90, -86], \"m\": 23, \"n\": 4}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr1\": [1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1], \"arr2\": [0, 0, 1, 1], \"m\": 10, \"n\": 4}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr1\": [6, 8, 11, 13, 14, 26, 26, 41, 48, 70, 82, 83, 84, 88, 96], \"arr2\": [1, 9, 12, 16], \"m\": 10, \"n\": 4}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr1\": [-88, 80, 62, 76, 48, 92, 18, -94, -62, 98, -46, -50, 70, 32, 68, -54, 26, 16, 94, 0, -84, 2, -16, 88, 26, -38, 18, 64, 90, 80, 76, 2, 14, -90, 50, 4, 76, 30], \"arr2\": [-76, -54, 4, 78], \"m\": 27, \"n\": 4}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 1, 0, 1], \"m\": 10, \"n\": 4}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr1\": [54, 44, 97, 92, 13, 54, 27, 8, 43, 70, 77, 84, 55, 64, 5, 59, 27, 19, 65, 68, 66, 26, 33, 38, 7], \"arr2\": [93, 5, 9, 13], \"m\": 19, \"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 ] }
226
Find Whether A Given Number Is A Power Of 4 Or Not 1
C++
bool findWhetherAGivenNumberIsAPowerOf4OrNot1(int n) {
[ "n" ]
def find_whether_a_given_number_is_a_power_of_4_or_not_1(n): count = 0 if (n and (not (n & (n - 1)))): while (n > 1): n >>= 1 count += 1 if ((count % 2) == 0): return True else: return False
bool find_whether_a_given_number_is_a_power_of_4_or_not_1(unsigned int n) { int count = 0; if ( n && ! ( n & ( n - 1 ) ) ) { while ( n > 1 ) { n >>= 1; count += 1; } return ( count % 2 == 0 ) ? 1 : 0; } return 0; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-64, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(128, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1024, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findWhetherAGivenNumberIsAPowerOf4OrNot1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 1}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 4}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 64}}, {\"idx\": 3, \"outputs\": null, \"inputs\": {\"n\": -64}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 128}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"n\": 1024}}, {\"idx\": 6, \"outputs\": null, \"inputs\": {\"n\": 45}}, {\"idx\": 7, \"outputs\": null, \"inputs\": {\"n\": 33}}, {\"idx\": 8, \"outputs\": null, \"inputs\": {\"n\": 66}}, {\"idx\": 9, \"outputs\": null, \"inputs\": {\"n\": 74}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
227
Find Whether A Given Number Is A Power Of 4 Or Not 2
C++
bool findWhetherAGivenNumberIsAPowerOf4OrNot2(int n) {
[ "n" ]
def find_whether_a_given_number_is_a_power_of_4_or_not_2(n): return ((n != 0) and ((n & (n - 1)) == 0) and (not (n & 2863311530)))
bool find_whether_a_given_number_is_a_power_of_4_or_not_2(unsigned int n) { return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ! ( n & 0xAAAAAAAA ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-64, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(128, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1024, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findWhetherAGivenNumberIsAPowerOf4OrNot2", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 1}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 4}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 64}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": -64}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 128}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"n\": 1024}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 97}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 86}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 14}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 99}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
228
Find Whether Given Integer Power 3 Not
C++
bool findWhetherGivenIntegerPower3Not(int n) {
[ "n" ]
def find_whether_given_integer_power_3_not(n): return ((1162261467 % n) == 0)
bool find_whether_given_integer_power_3_not(int n) { return 1162261467 % n == 0; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-9, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findWhetherGivenIntegerPower3Not", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 1}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 3}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 27}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"n\": 9}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"n\": -9}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 11}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 57}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 21}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 60}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 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 ] }
229
First Element Occurring K Times Array
C++
int firstElementOccurringKTimesArray(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def first_element_occurring_k_times_array(arr, n, k): count_map = { } for i in range(0, n): if (arr[i] in count_map.keys()): count_map[arr[i]] += 1 else: count_map[arr[i]] = 1 i += 1 for i in range(0, n): if (count_map[arr[i]] == k): return arr[i] i += 1 return (- 1)
int first_element_occurring_k_times_array(vector<int> arr, int n, int k) { unordered_map < int, int > count_map; for ( int i = 0; i < n; i ++ ) count_map [ arr [ i ] ] ++; for ( int i = 0; i < n; i ++ ) if ( count_map [ arr [ i ] ] == k ) 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 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, 3, 4, 4, 7, 18, 20, 23, 27, 30, 31, 31, 32, 35, 36, 43, 45, 46, 49, 50, 53, 55, 59, 60, 64, 64, 65, 68, 78, 80, 80, 85, 95}, 30, 2, 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-26, 32, 36, 6, 64, 24, -28, 96}, 6, 3, -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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 7, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({38, 40, 43, 70, 20, 40, 95, 96, 81, 82}, 9, 1, 38); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-68, -8, -8, 16, 24, 54}, 3, 2, -8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1}, 6, 4, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({13, 18, 19, 28, 31, 34, 49, 49, 53, 57, 58, 62, 75, 76, 77, 78, 80, 84, 84, 85, 87, 91, 98, 99}, 20, 2, 49); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-4, 24, -86, -84, 30, -16, 12, -92, -68, 22}, 6, 5, -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}, 8, 10, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({55, 44, 75, 97, 25, 65, 76, 53, 20, 78, 25, 59, 61, 29, 81, 35, 15, 78, 41, 44, 31, 33, 39, 93, 26, 67}, 23, 20, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "firstElementOccurringKTimesArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"arr\": [2, 3, 4, 4, 7, 18, 20, 23, 27, 30, 31, 31, 32, 35, 36, 43, 45, 46, 49, 50, 53, 55, 59, 60, 64, 64, 65, 68, 78, 80, 80, 85, 95], \"n\": 30, \"k\": 2}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [-26, 32, 36, 6, 64, 24, -28, 96], \"n\": 6, \"k\": 3}}, {\"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], \"n\": 15, \"k\": 7}}, {\"idx\": 3, \"outputs\": 38, \"inputs\": {\"arr\": [38, 40, 43, 70, 20, 40, 95, 96, 81, 82], \"n\": 9, \"k\": 1}}, {\"idx\": 4, \"outputs\": -8, \"inputs\": {\"arr\": [-68, -8, -8, 16, 24, 54], \"n\": 3, \"k\": 2}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1], \"n\": 6, \"k\": 4}}, {\"idx\": 6, \"outputs\": 49, \"inputs\": {\"arr\": [13, 18, 19, 28, 31, 34, 49, 49, 53, 57, 58, 62, 75, 76, 77, 78, 80, 84, 84, 85, 87, 91, 98, 99], \"n\": 20, \"k\": 2}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-4, 24, -86, -84, 30, -16, 12, -92, -68, 22], \"n\": 6, \"k\": 5}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 8, \"k\": 10}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [55, 44, 75, 97, 25, 65, 76, 53, 20, 78, 25, 59, 61, 29, 81, 35, 15, 78, 41, 44, 31, 33, 39, 93, 26, 67], \"n\": 23, \"k\": 20}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
231
Floor In A Sorted Array 1
C++
int floorInASortedArray1(vector<int> arr, int low, int high, int x) {
[ "arr", "low", "high", "x" ]
def floor_in_a_sorted_array_1(arr, low, high, x): if (low > high): return (- 1) if (x >= arr[high]): return high mid = int(((low + high) / 2)) if (arr[mid] == x): return mid if ((mid > 0) and (arr[(mid - 1)] <= x) and (x < arr[mid])): return (mid - 1) if (x < arr[mid]): return floor_in_a_sorted_array_1(arr, low, (mid - 1), x) return floor_in_a_sorted_array_1(arr, (mid + 1), high, x)
int floor_in_a_sorted_array_1(vector<int> arr, int low, int high, int x) { if ( low > high ) return - 1; if ( x >= arr [ high ] ) return high; int mid = ( low + high ) / 2; if ( arr [ mid ] == x ) return mid; if ( mid > 0 && arr [ mid - 1 ] <= x && x < arr [ mid ] ) return mid - 1; if ( x < arr [ mid ] ) return floor_in_a_sorted_array_1 ( arr, low, mid - 1, x ); return floor_in_a_sorted_array_1 ( arr, mid + 1, high, x ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int low, int high, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, low, high, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 11, 20, 42, 42, 55, 58, 98, 99}, 5, 7, 6, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, -90, -38, -46, -10, -22, -66, 72, -52, 38, 90, 34, -12, -44, -6, 0, -20, -38, 86, 26, 64, -24, 40, 90, -26, -2, -28, 12, 22, -14}, 26, 28, 23, 28); \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}, 11, 9, 18, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({69, 28, 68, 98, 24, 67, 86, 2, 18, 22, 44, 77, 52, 62, 24, 46}, 15, 11, 13, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -88, -84, -68, -60, -52, -52, -42, -34, -32, -16, -12, -6, -6, -4, -2, 0, 16, 18, 38, 58, 70, 72, 76, 78, 90, 92, 98}, 22, 27, 20, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0}, 24, 15, 26, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 6, 7, 9, 10, 11, 19, 19, 22, 22, 26, 34, 36, 37, 37, 38, 39, 40, 49, 54, 60, 62, 65, 67, 71, 76, 78, 79, 82, 82, 89, 95, 97}, 22, 26, 25, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, -32, -98, -18, -80, 74, -22, -82, 40, -64, 58, -18, -64, 34, -44, -82, -46, 62, -80, -76, 32, 44, -32, 98, -26, 62, 16, 86, -52, -72, -90, -30, 6}, 28, 31, 24, 31); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 28, 29, 30, 29); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({81, 69, 15, 52, 49, 54, 18, 92, 33, 21, 91, 21, 5, 25, 77, 92, 26, 58, 72, 55, 76, 18, 13, 59, 9, 12, 31, 24, 36, 33, 71, 87, 55, 19, 42, 25}, 35, 19, 33, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "floorInASortedArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"arr\": [5, 11, 20, 42, 42, 55, 58, 98, 99], \"low\": 5, \"high\": 7, \"x\": 6}}, {\"idx\": 1, \"outputs\": 28, \"inputs\": {\"arr\": [50, -90, -38, -46, -10, -22, -66, 72, -52, 38, 90, 34, -12, -44, -6, 0, -20, -38, 86, 26, 64, -24, 40, 90, -26, -2, -28, 12, 22, -14], \"low\": 26, \"high\": 28, \"x\": 23}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"low\": 11, \"high\": 9, \"x\": 18}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [69, 28, 68, 98, 24, 67, 86, 2, 18, 22, 44, 77, 52, 62, 24, 46], \"low\": 15, \"high\": 11, \"x\": 13}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-96, -94, -88, -84, -68, -60, -52, -52, -42, -34, -32, -16, -12, -6, -6, -4, -2, 0, 16, 18, 38, 58, 70, 72, 76, 78, 90, 92, 98], \"low\": 22, \"high\": 27, \"x\": 20}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0], \"low\": 24, \"high\": 15, \"x\": 26}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [1, 6, 7, 9, 10, 11, 19, 19, 22, 22, 26, 34, 36, 37, 37, 38, 39, 40, 49, 54, 60, 62, 65, 67, 71, 76, 78, 79, 82, 82, 89, 95, 97], \"low\": 22, \"high\": 26, \"x\": 25}}, {\"idx\": 7, \"outputs\": 31, \"inputs\": {\"arr\": [76, -32, -98, -18, -80, 74, -22, -82, 40, -64, 58, -18, -64, 34, -44, -82, -46, 62, -80, -76, 32, 44, -32, 98, -26, 62, 16, 86, -52, -72, -90, -30, 6], \"low\": 28, \"high\": 31, \"x\": 24}}, {\"idx\": 8, \"outputs\": 29, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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], \"low\": 28, \"high\": 29, \"x\": 30}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [81, 69, 15, 52, 49, 54, 18, 92, 33, 21, 91, 21, 5, 25, 77, 92, 26, 58, 72, 55, 76, 18, 13, 59, 9, 12, 31, 24, 36, 33, 71, 87, 55, 19, 42, 25], \"low\": 35, \"high\": 19, \"x\": 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 ] }
232
Form Minimum Number From Given Sequence 1
C++
string formMinimumNumberFromGivenSequence1(string seq) {
[ "seq" ]
def form_minimum_number_from_given_sequence_1(seq): n = len(seq) if (n >= 9): return '-1' result = ([None] * (n + 1)) count = 1 for i in range((n + 1)): if ((i == n) or (seq[i] == 'I')): for j in range((i - 1), (- 2), (- 1)): result[(j + 1)] = int(('0' + str(count))) count += 1 if ((j >= 0) and (seq[j] == 'I')): break return result
string form_minimum_number_from_given_sequence_1(string seq) { int n = seq . length ( ); if ( n >= 9 ) return "-1"; string result ( n + 1, ' ' ); int count = 1; for ( int i = 0; i <= n; i ++ ) { if ( i == n || seq [ i ] == 'I' ) { for ( int j = i - 1; j >= - 1; j -- ) { result [ j + 1 ] = '0' + count ++; if ( j >= 0 && seq [ j ] == 'I' ) break; } } } return result; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string seq, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(seq), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"D\", \"[2, 1]\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"I\", \"[1, 2]\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"DD\", \"[3, 2, 1]\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"II\", \"[1, 2, 3]\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"DIDI\", \"[2, 1, 4, 3, 5]\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"IIDDD\", \"[1, 2, 6, 5, 4, 3]\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"DDIDDIID\", \"[3, 2, 1, 6, 5, 4, 7, 9, 8]\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"176297\", \"[7, 6, 5, 4, 3, 2, 1]\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", \"[2, 1]\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"XHkhZq\", \"[7, 6, 5, 4, 3, 2, 1]\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "formMinimumNumberFromGivenSequence1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"[2, 1]\", \"inputs\": {\"seq\": \"D\"}}, {\"idx\": 1, \"outputs\": \"[1, 2]\", \"inputs\": {\"seq\": \"I\"}}, {\"idx\": 2, \"outputs\": \"[3, 2, 1]\", \"inputs\": {\"seq\": \"DD\"}}, {\"idx\": 3, \"outputs\": \"[1, 2, 3]\", \"inputs\": {\"seq\": \"II\"}}, {\"idx\": 4, \"outputs\": \"[2, 1, 4, 3, 5]\", \"inputs\": {\"seq\": \"DIDI\"}}, {\"idx\": 5, \"outputs\": \"[1, 2, 6, 5, 4, 3]\", \"inputs\": {\"seq\": \"IIDDD\"}}, {\"idx\": 6, \"outputs\": \"[3, 2, 1, 6, 5, 4, 7, 9, 8]\", \"inputs\": {\"seq\": \"DDIDDIID\"}}, {\"idx\": 7, \"outputs\": \"[7, 6, 5, 4, 3, 2, 1]\", \"inputs\": {\"seq\": \"176297\"}}, {\"idx\": 8, \"outputs\": \"[2, 1]\", \"inputs\": {\"seq\": \"1\"}}, {\"idx\": 9, \"outputs\": \"[7, 6, 5, 4, 3, 2, 1]\", \"inputs\": {\"seq\": \"XHkhZq\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
233
Form Smallest Number Using One Swap Operation
C++
string formSmallestNumberUsingOneSwapOperation(string num) {
[ "num" ]
def form_smallest_number_using_one_swap_operation(num): num = list(num) n = len(num) rightMin = ([0] * n) right = 0 rightMin[(n - 1)] = (- 1) right = (n - 1) for i in range((n - 2), 0, (- 1)): if (num[i] > num[right]): rightMin[i] = right else: rightMin[i] = (- 1) right = i small = (- 1) for i in range(1, n): if (num[i] != '0'): if (small == (- 1)): if (num[i] < num[0]): small = i elif (num[i] < num[small]): small = i if (small != (- 1)): (num[0], num[small]) = (num[small], num[0]) else: for i in range(1, n): if (rightMin[i] != (- 1)): (num[i], num[rightMin[i]]) = (num[rightMin[i]], num[i]) break return ''.join(num)
string form_smallest_number_using_one_swap_operation(string num) { int n = num . size ( ); int rightMin [ n ], right; rightMin [ n - 1 ] = - 1; right = n - 1; for ( int i = n - 2; i >= 1; i -- ) { if ( num [ i ] >= num [ right ] ) rightMin [ i ] = right; else { if ( num [ i ] == num [ i + 1 ] ) { rightMin [ i ] = right; } else { rightMin [ i ] = - 1; right = i; } } } int small = - 1; for ( int i = 1; i < n; i ++ ) if ( num [ i ] != '0' ) { if ( small == - 1 ) { if ( num [ i ] < num [ 0 ] ) small = i; } else if ( num [ i ] <= num [ small ] ) small = i; } if ( small != - 1 ) swap ( num [ 0 ], num [ small ] ); else { for ( int i = 1; i < n; i ++ ) { if ( rightMin [ i ] != - 1 && num [ i ] != num [ rightMin [ i ] ] ) { swap ( num [ i ], num [ rightMin [ i ] ] ); break; } } } return num; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string num, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"ncYltuhSxEfG\", \"EcYltuhSxnfG\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"26615541616459\", \"16625541616459\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0101\", \"0011\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"hK\", \"Kh\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"422162103899\", \"122462103899\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0010\", \"0001\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"zfcSh\", \"Sfczh\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"92\", \"29\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0\", \"0\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"v\", \"v\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "formSmallestNumberUsingOneSwapOperation", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"EcYltuhSxnfG\", \"inputs\": {\"num\": \"ncYltuhSxEfG\"}}, {\"idx\": 1, \"outputs\": \"16625541616459\", \"inputs\": {\"num\": \"26615541616459\"}}, {\"idx\": 2, \"outputs\": \"0011\", \"inputs\": {\"num\": \"0101\"}}, {\"idx\": 3, \"outputs\": \"Kh\", \"inputs\": {\"num\": \"hK\"}}, {\"idx\": 4, \"outputs\": \"122462103899\", \"inputs\": {\"num\": \"422162103899\"}}, {\"idx\": 5, \"outputs\": \"0001\", \"inputs\": {\"num\": \"0010\"}}, {\"idx\": 6, \"outputs\": \"Sfczh\", \"inputs\": {\"num\": \"zfcSh\"}}, {\"idx\": 7, \"outputs\": \"29\", \"inputs\": {\"num\": \"92\"}}, {\"idx\": 8, \"outputs\": \"0\", \"inputs\": {\"num\": \"0\"}}, {\"idx\": 9, \"outputs\": \"v\", \"inputs\": {\"num\": \"v\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
234
Frequent Element Array
C++
int frequentElementArray(vector<int> arr, int n) {
[ "arr", "n" ]
def frequent_element_array(arr, n): arr.sort() max_count = 1 res = arr[0] curr_count = 1 for i in range(1, n): if (arr[i] == arr[(i - 1)]): curr_count += 1 else: if (curr_count > max_count): max_count = curr_count res = arr[(i - 1)] curr_count = 1 if (curr_count > max_count): max_count = curr_count res = arr[(n - 1)] return res
int frequent_element_array(vector<int> arr, int n) { sort(arr.begin(), arr.end()); int max_count = 1, res = arr [ 0 ], curr_count = 1; for ( int i = 1; i < n; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) curr_count ++; else { if ( curr_count > max_count ) { max_count = curr_count; res = arr [ i - 1 ]; } curr_count = 1; } } if ( curr_count > max_count ) { max_count = curr_count; res = arr [ n - 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(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, 1, 3, 11, 11, 11, 18, 20, 26, 26, 27, 30, 33, 39, 39, 42, 42, 48, 51, 51, 51, 51, 60, 66, 66, 68, 68, 69, 71, 72, 73, 76, 76, 77, 77, 77, 78, 90, 96}, 25, 51); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-74, -46, -38, -32, -22, -18, -14, -8, -4, 14, 30, 36, 42, 46, 48, 64, 66, 72, 80, 92, 94, 96, 96}, 18, -74); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1}, 6, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 21, 23, 31, 31, 32, 45, 49, 52, 55, 56, 58, 67, 70, 71, 80, 87, 93, 96, 97}, 15, 31); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -96, -84, -82, -72, -64, -62, -56, -52, -52, -48, -46, -42, -36, -32, -30, -30, -18, -16, -10, -2, 0, 6, 18, 22, 22, 40, 42, 50, 54, 64, 68, 68, 72, 80, 82, 84, 96}, 20, -52); \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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9, 12, 13, 28, 43, 46, 64, 66, 68, 89, 92}, 6, 9); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -88, -82, -80, -72, -60, -56, -52, -46, -42, -42, -40, -40, -32, -32, -26, -24, -22, -22, -12, -12, -8, 4, 6, 18, 18, 22, 22, 32, 36, 36, 38, 40, 46, 48, 50, 54, 68, 76, 78, 80, 86, 86, 90, 92, 92, 94, 96}, 41, -42); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1}, 4, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, 4, 5, 9, 16, 25, 29, 31, 32, 40, 41, 41, 43, 54, 61, 62, 63, 64, 65, 74, 74, 76, 80, 81, 81, 85, 86, 95, 96, 97, 97}, 16, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "frequentElementArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 51, \"inputs\": {\"arr\": [1, 1, 3, 11, 11, 11, 18, 20, 26, 26, 27, 30, 33, 39, 39, 42, 42, 48, 51, 51, 51, 51, 60, 66, 66, 68, 68, 69, 71, 72, 73, 76, 76, 77, 77, 77, 78, 90, 96], \"n\": 25}}, {\"idx\": 1, \"outputs\": -74, \"inputs\": {\"arr\": [-74, -46, -38, -32, -22, -18, -14, -8, -4, 14, 30, 36, 42, 46, 48, 64, 66, 72, 80, 92, 94, 96, 96], \"n\": 18}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1], \"n\": 6}}, {\"idx\": 3, \"outputs\": 31, \"inputs\": {\"arr\": [3, 21, 23, 31, 31, 32, 45, 49, 52, 55, 56, 58, 67, 70, 71, 80, 87, 93, 96, 97], \"n\": 15}}, {\"idx\": 4, \"outputs\": -52, \"inputs\": {\"arr\": [-98, -96, -84, -82, -72, -64, -62, -56, -52, -52, -48, -46, -42, -36, -32, -30, -30, -18, -16, -10, -2, 0, 6, 18, 22, 22, 40, 42, 50, 54, 64, 68, 68, 72, 80, 82, 84, 96], \"n\": 20}}, {\"idx\": 5, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29}}, {\"idx\": 6, \"outputs\": 9, \"inputs\": {\"arr\": [9, 12, 13, 28, 43, 46, 64, 66, 68, 89, 92], \"n\": 6}}, {\"idx\": 7, \"outputs\": -42, \"inputs\": {\"arr\": [-94, -88, -82, -80, -72, -60, -56, -52, -46, -42, -42, -40, -40, -32, -32, -26, -24, -22, -22, -12, -12, -8, 4, 6, 18, 18, 22, 22, 32, 36, 36, 38, 40, 46, 48, 50, 54, 68, 76, 78, 80, 86, 86, 90, 92, 92, 94, 96], \"n\": 41}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1], \"n\": 4}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"arr\": [2, 4, 4, 5, 9, 16, 25, 29, 31, 32, 40, 41, 41, 43, 54, 61, 62, 63, 64, 65, 74, 74, 76, 80, 81, 81, 85, 86, 95, 96, 97, 97], \"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 ] }
235
Frequent Element Array 1
C++
int frequentElementArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def frequent_element_array_1(arr, n): Hash = dict() for i in range(n): if (arr[i] in Hash.keys()): Hash[arr[i]] += 1 else: Hash[arr[i]] = 1 max_count = 0 res = (- 1) for i in Hash: if (max_count < Hash[i]): res = i max_count = Hash[i] return res
int frequent_element_array_1(vector<int> arr, int n) { unordered_map < int, int > hash; for ( int i = 0; i < n; i ++ ) hash [ arr [ i ] ] ++; int max_count = 0, res = - 1; for ( auto i : hash ) { if ( max_count < i . second ) { res = i . first; max_count = i . second; } } 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({3, 5, 7, 9, 9, 10, 11, 15, 19, 19, 29, 31, 34, 34, 35, 37, 41, 43, 45, 47, 51, 51, 55, 57, 59, 61, 65, 67, 73, 76, 77, 77, 80, 83, 83, 84, 84, 92, 94}, 24, 9); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, -38, -84, 24, 82, -68, 60, 2, -22, 54, 90, 90, -38, -8, -72, 68, 50, 54, -32, -66, -10, -70, -28, 18, 58, -54, -30, 60, -24, -48, 22, 32, -18, 2, -64, -56, 70, -92, -38, -70, 22, -36, -64}, 28, -38); \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}, 18, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, 18, 41, 46, 34, 41, 56, 76, 14, 82, 51, 87, 1, 92, 9, 2, 68, 82, 43, 98, 88, 62, 84, 25, 7, 87, 37, 7, 55, 98, 60, 99, 92, 56, 17, 82, 28, 43, 40, 1, 99, 79, 38, 75, 84, 61, 21, 11}, 37, 82); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -86, -86, -84, -70, -68, -68, -66, -62, -52, -52, -50, -48, -38, -22, -14, -6, 4, 8, 10, 10, 16, 22, 36, 38, 40, 50, 50, 70, 78, 80, 86, 96, 96, 98}, 21, -86); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0}, 18, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 53, 56, 57, 66, 73, 76, 94, 97}, 8, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, 60, -94, 92}, 3, 12); \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}, 21, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({95, 93, 82, 73, 61, 24, 73, 21, 47, 91, 48, 42, 76, 12, 89, 21, 3, 30, 5, 49, 26, 54, 16, 70, 50, 21, 58, 36, 16}, 25, 73); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "frequentElementArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 9, \"inputs\": {\"arr\": [3, 5, 7, 9, 9, 10, 11, 15, 19, 19, 29, 31, 34, 34, 35, 37, 41, 43, 45, 47, 51, 51, 55, 57, 59, 61, 65, 67, 73, 76, 77, 77, 80, 83, 83, 84, 84, 92, 94], \"n\": 24}}, {\"idx\": 1, \"outputs\": -38, \"inputs\": {\"arr\": [14, -38, -84, 24, 82, -68, 60, 2, -22, 54, 90, 90, -38, -8, -72, 68, 50, 54, -32, -66, -10, -70, -28, 18, 58, -54, -30, 60, -24, -48, 22, 32, -18, 2, -64, -56, 70, -92, -38, -70, 22, -36, -64], \"n\": 28}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 18}}, {\"idx\": 3, \"outputs\": 82, \"inputs\": {\"arr\": [76, 18, 41, 46, 34, 41, 56, 76, 14, 82, 51, 87, 1, 92, 9, 2, 68, 82, 43, 98, 88, 62, 84, 25, 7, 87, 37, 7, 55, 98, 60, 99, 92, 56, 17, 82, 28, 43, 40, 1, 99, 79, 38, 75, 84, 61, 21, 11], \"n\": 37}}, {\"idx\": 4, \"outputs\": -86, \"inputs\": {\"arr\": [-92, -86, -86, -84, -70, -68, -68, -66, -62, -52, -52, -50, -48, -38, -22, -14, -6, 4, 8, 10, 10, 16, 22, 36, 38, 40, 50, 50, 70, 78, 80, 86, 96, 96, 98], \"n\": 21}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0], \"n\": 18}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"arr\": [3, 53, 56, 57, 66, 73, 76, 94, 97], \"n\": 8}}, {\"idx\": 7, \"outputs\": 12, \"inputs\": {\"arr\": [12, 60, -94, 92], \"n\": 3}}, {\"idx\": 8, \"outputs\": 0, \"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], \"n\": 21}}, {\"idx\": 9, \"outputs\": 73, \"inputs\": {\"arr\": [95, 93, 82, 73, 61, 24, 73, 21, 47, 91, 48, 42, 76, 12, 89, 21, 3, 30, 5, 49, 26, 54, 16, 70, 50, 21, 58, 36, 16], \"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 ] }
237
Friends Pairing Problem 2
C++
long long friendsPairingProblem2(int n) {
[ "n" ]
def friends_pairing_problem_2(n): (a, b, c) = (1, 2, 0) if (n <= 2): return n for i in range(3, (n + 1)): c = (b + ((i - 1) * a)) a = b b = c return c
int friends_pairing_problem_2(int n) { int a = 1, b = 2, c = 0; if ( n <= 2 ) { return n; } for ( int i = 3; i <= n; i ++ ) { c = b + ( i - 1 ) * a; a = b; b = c; } return c; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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(24, 17492190577600); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 101990226254706560); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 2390480); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "friendsPairingProblem2", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 17492190577600, \"inputs\": {\"n\": 24}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"n\": 1}}, {\"idx\": 2, \"outputs\": 101990226254706560, \"inputs\": {\"n\": 29}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"n\": 3}}, {\"idx\": 4, \"outputs\": 2390480, \"inputs\": {\"n\": 14}}]", "test_case_ids": [ "0", "1", "2", "3", "4" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
239
Gcd Elements Given Range
C++
int gcdElementsGivenRange(int n, int m) {
[ "n", "m" ]
def gcd_elements_given_range(n, m): return (n if (n == m) else 1)
int gcd_elements_given_range(int n, int m) { return ( n == m ) ? n : 1; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int 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(57, 57, 57); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 22, 22); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 17, 17); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 74, 74); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 22, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 54, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 33, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 68, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 75, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 21, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "gcdElementsGivenRange", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 57, \"inputs\": {\"n\": 57, \"m\": 57}}, {\"idx\": 1, \"outputs\": 22, \"inputs\": {\"n\": 22, \"m\": 22}}, {\"idx\": 2, \"outputs\": 17, \"inputs\": {\"n\": 17, \"m\": 17}}, {\"idx\": 3, \"outputs\": 74, \"inputs\": {\"n\": 74, \"m\": 74}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"n\": 93, \"m\": 22}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"n\": 56, \"m\": 54}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"n\": 5, \"m\": 33}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"n\": 5, \"m\": 68}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"n\": 9, \"m\": 75}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"n\": 98, \"m\": 21}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
240
Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum
C++
bool givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum(vector<int> arr, int n, int x) {
[ "arr", "n", "x" ]
def given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum(arr, n, x): for i in range(0, (n - 1)): if (arr[i] > arr[(i + 1)]): break l = ((i + 1) % n) r = i while (l != r): if ((arr[l] + arr[r]) == x): return True if ((arr[l] + arr[r]) < x): l = ((l + 1) % n) else: r = (((n + r) - 1) % n) return False
bool given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum(vector<int> arr, int n, int x) { int i; for ( i = 0; i < n - 1; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break; int l = ( i + 1 ) % n; int r = i; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) return true; if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n; else r = ( n + r - 1 ) % n; } 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({3, 8, 10, 15, 18, 19, 20, 20, 21, 22, 26, 30, 32, 34, 43, 45, 50, 50, 51, 52, 53, 56, 57, 58, 62, 63, 65, 82, 86, 91, 91, 92, 92, 93, 97}, 17, 30, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({30, -34, 86, -30, -26, 2, 90, 8, 26, -8, -8, 0, -86, 68, 22, 72, -76, 48, -24, 90, -22, -58, -54, 90, -12, -12, 88, 72, -58, 68, 84, 22, 60, 66, -52, -38, -90, 62, 30, -26, 88, -36, 92, 32, -32, -42, -90, -40, -10}, 41, 10, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 26, 1, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, 68, 40, 19, 74, 69}, 4, 88, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -94, -94, -94, -90, -88, -88, -78, -74, -70, -68, -66, -64, -62, -54, -50, -40, -40, -40, -40, -28, -22, -22, -18, -14, -12, 0, 6, 6, 8, 12, 20, 22, 26, 28, 36, 42, 44, 48, 52, 56, 60, 68, 84}, 28, 94, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0}, 2, 60, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, 22, 38, 76, 80, 86}, 4, 3, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-36, -10, -26, 34, -50, 66, -2, -14, -62, 60, -48, 94, -70, 6, -60, -90, 28, -4, -20, -52, 40, -76, -92, -14, 54, 4, -58, 38, -74, -96, -88, 86, -54, 98, 48, 68, 78, -28, -80, -46}, 26, 37, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 20, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({69, 99, 25, 52, 41, 51, 7, 33, 42, 91, 85, 57, 91, 89, 86, 11, 70, 67, 30, 92, 81, 23, 51, 98, 85, 5, 50, 44}, 21, 27, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [3, 8, 10, 15, 18, 19, 20, 20, 21, 22, 26, 30, 32, 34, 43, 45, 50, 50, 51, 52, 53, 56, 57, 58, 62, 63, 65, 82, 86, 91, 91, 92, 92, 93, 97], \"n\": 17, \"x\": 30}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [30, -34, 86, -30, -26, 2, 90, 8, 26, -8, -8, 0, -86, 68, 22, 72, -76, 48, -24, 90, -22, -58, -54, 90, -12, -12, 88, 72, -58, 68, 84, 22, 60, 66, -52, -38, -90, 62, 30, -26, 88, -36, 92, 32, -32, -42, -90, -40, -10], \"n\": 41, \"x\": 10}}, {\"idx\": 2, \"outputs\": true, \"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], \"n\": 26, \"x\": 1}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"arr\": [20, 68, 40, 19, 74, 69], \"n\": 4, \"x\": 88}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"arr\": [-98, -94, -94, -94, -90, -88, -88, -78, -74, -70, -68, -66, -64, -62, -54, -50, -40, -40, -40, -40, -28, -22, -22, -18, -14, -12, 0, 6, 6, 8, 12, 20, 22, 26, 28, 36, 42, 44, 48, 52, 56, 60, 68, 84], \"n\": 28, \"x\": 94}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [1, 1, 0], \"n\": 2, \"x\": 60}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [12, 22, 38, 76, 80, 86], \"n\": 4, \"x\": 3}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [-36, -10, -26, 34, -50, 66, -2, -14, -62, 60, -48, 94, -70, 6, -60, -90, 28, -4, -20, -52, 40, -76, -92, -14, 54, 4, -58, 38, -74, -96, -88, 86, -54, 98, 48, 68, 78, -28, -80, -46], \"n\": 26, \"x\": 37}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 17, \"x\": 20}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [69, 99, 25, 52, 41, 51, 7, 33, 42, 91, 85, 57, 91, 89, 86, 11, 70, 67, 30, 92, 81, 23, 51, 98, 85, 5, 50, 44], \"n\": 21, \"x\": 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 ] }
241
Given A Sorted And Rotated Array Find If There Is A Pair With A Given Sum 1
C++
int givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum1(vector<int> arr, int n, int x) {
[ "arr", "n", "x" ]
def given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum_1(arr, n, x): for i in range(n): if (arr[i] > arr[(i + 1)]): break l = ((i + 1) % n) r = i cnt = 0 while (l != r): if ((arr[l] + arr[r]) == x): cnt += 1 if (l == (((r - 1) + n) % n)): return cnt l = ((l + 1) % n) r = (((r - 1) + n) % n) elif ((arr[l] + arr[r]) < x): l = ((l + 1) % n) else: r = (((n + r) - 1) % n) return cnt
int given_a_sorted_and_rotated_array_find_if_there_is_a_pair_with_a_given_sum_1(vector<int> arr, int n, int x) { int i; for ( i = 0; i < n - 1; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break; int l = ( i + 1 ) % n; int r = i; int cnt = 0; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) { cnt ++; if ( l == ( r - 1 + n ) % n ) { return cnt; } l = ( l + 1 ) % n; r = ( r - 1 + n ) % n; } else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n; else r = ( n + r - 1 ) % n; } 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> 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({24, 54}, 1, 1, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, -30, -18, -6, 70, -40, 86, 98, -24, -48}, 8, 8, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, 28, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({84, 44, 40, 45, 2, 41, 52, 17, 50, 41, 5, 52, 48, 90, 13, 55, 34, 55, 94, 44, 41, 2}, 18, 16, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -76, -74, -72, -68, -64, -58, -44, -44, -38, -26, -24, -20, -12, -8, -8, -4, 10, 10, 10, 20, 20, 26, 26, 28, 50, 52, 54, 60, 66, 72, 74, 78, 78, 78, 80, 86, 88}, 29, 30, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1}, 19, 10, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 5, 15, 19, 22, 24, 26, 27, 28, 32, 37, 39, 40, 43, 49, 52, 55, 56, 58, 58, 59, 62, 67, 68, 77, 79, 79, 80, 81, 87, 95, 95, 96, 98, 98}, 28, 34, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, 28, 54, 44, -98, -70, 48, -98, 56, 4, -18, 26, -8, -58, 30, 82, 4, -38, 42, 64, -28}, 17, 14, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 24, 24, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({26, 72, 74, 86, 98, 86, 22, 6, 95, 36, 11, 82, 34, 3, 50, 36, 81, 94, 55, 30, 62, 53, 50, 95, 32, 83, 9, 16}, 19, 16, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "givenASortedAndRotatedArrayFindIfThereIsAPairWithAGivenSum1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [24, 54], \"n\": 1, \"x\": 1}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [68, -30, -18, -6, 70, -40, 86, 98, -24, -48], \"n\": 8, \"x\": 8}}, {\"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], \"n\": 33, \"x\": 28}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [84, 44, 40, 45, 2, 41, 52, 17, 50, 41, 5, 52, 48, 90, 13, 55, 34, 55, 94, 44, 41, 2], \"n\": 18, \"x\": 16}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"arr\": [-92, -76, -74, -72, -68, -64, -58, -44, -44, -38, -26, -24, -20, -12, -8, -8, -4, 10, 10, 10, 20, 20, 26, 26, 28, 50, 52, 54, 60, 66, 72, 74, 78, 78, 78, 80, 86, 88], \"n\": 29, \"x\": 30}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1], \"n\": 19, \"x\": 10}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [5, 5, 15, 19, 22, 24, 26, 27, 28, 32, 37, 39, 40, 43, 49, 52, 55, 56, 58, 58, 59, 62, 67, 68, 77, 79, 79, 80, 81, 87, 95, 95, 96, 98, 98], \"n\": 28, \"x\": 34}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-98, 28, 54, 44, -98, -70, 48, -98, 56, 4, -18, 26, -8, -58, 30, 82, 4, -38, 42, 64, -28], \"n\": 17, \"x\": 14}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 24, \"x\": 24}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [26, 72, 74, 86, 98, 86, 22, 6, 95, 36, 11, 82, 34, 3, 50, 36, 81, 94, 55, 30, 62, 53, 50, 95, 32, 83, 9, 16], \"n\": 19, \"x\": 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 ] }
242
Google Case Given Sentence
C++
string googleCaseGivenSentence(string s) {
[ "s" ]
def google_case_given_sentence(s): n = len(s) s1 = '' s1 = (s1 + s[0].lower()) i = 1 while (i < n): if ((s[i] == ' ') and (i <= n)): s1 = ((s1 + ' ') + s[(i + 1)].lower()) i = (i + 1) else: s1 = (s1 + s[i].upper()) i = (i + 1) return s1
string google_case_given_sentence(string s) { int n = s . length ( ); s [ 0 ] = tolower ( s [ 0 ] ); for ( int i = 1; i < n; i ++ ) { if ( s [ i ] == ' ' && i < n ) { s [ i + 1 ] = tolower ( s [ i + 1 ] ); i ++; } else s [ i ] = toupper ( s [ i ] ); } return s; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string s, string 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(\"TEYndweqZA\", \"tEYNDWEQZA\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01865\", \"01865\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11001100\", \"11001100\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"CzwznJmQet\", \"cZWZNJMQET\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"318305446\", \"318305446\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0000001111110\", \"0000001111110\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"yzT\", \"yZT\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"38630230\", \"38630230\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01101\", \"01101\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"zoizI\", \"zOIZI\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "googleCaseGivenSentence", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"tEYNDWEQZA\", \"inputs\": {\"s\": \"TEYndweqZA\"}}, {\"idx\": 1, \"outputs\": \"01865\", \"inputs\": {\"s\": \"01865\"}}, {\"idx\": 2, \"outputs\": \"11001100\", \"inputs\": {\"s\": \"11001100\"}}, {\"idx\": 3, \"outputs\": \"cZWZNJMQET\", \"inputs\": {\"s\": \"CzwznJmQet\"}}, {\"idx\": 4, \"outputs\": \"318305446\", \"inputs\": {\"s\": \"318305446\"}}, {\"idx\": 5, \"outputs\": \"0000001111110\", \"inputs\": {\"s\": \"0000001111110\"}}, {\"idx\": 6, \"outputs\": \"yZT\", \"inputs\": {\"s\": \"yzT\"}}, {\"idx\": 7, \"outputs\": \"38630230\", \"inputs\": {\"s\": \"38630230\"}}, {\"idx\": 8, \"outputs\": \"01101\", \"inputs\": {\"s\": \"01101\"}}, {\"idx\": 9, \"outputs\": \"zOIZI\", \"inputs\": {\"s\": \"zoizI\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
243
Hardy Ramanujan Theorem
C++
int hardyRamanujanTheorem(int n) {
[ "n" ]
def hardy_ramanujan_theorem(n): count = 0 if ((n % 2) == 0): count = (count + 1) while ((n % 2) == 0): n = int((n / 2)) i = 3 while (i <= int(math.sqrt(n))): if ((n % i) == 0): count = (count + 1) while ((n % i) == 0): n = int((n / i)) i = (i + 2) if (n > 2): count = (count + 1) return count
int hardy_ramanujan_theorem(int n) { int count = 0; if ( n % 2 == 0 ) { count ++; while ( n % 2 == 0 ) n = n / 2; } for ( int i = 3; i <= sqrt ( n ); i = i + 2 ) { if ( n % i == 0 ) { count ++; while ( n % i == 0 ) n = n / i; } } if ( n > 2 ) count ++; return count; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int 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(99, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "hardyRamanujanTheorem", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"n\": 99}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"n\": 33}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"n\": 50}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"n\": 17}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"n\": 18}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": 69}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"n\": 23}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"n\": 18}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"n\": 94}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"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 ] }
244
Height Complete Binary Tree Heap N Nodes
C++
int heightCompleteBinaryTreeHeapNNodes(int n) {
[ "n" ]
def height_complete_binary_tree_heap_n_nodes(N): return (math.ceil(math.log2((N + 1))) - 1)
int height_complete_binary_tree_heap_n_nodes(int N) { return ceil ( log2 ( N + 1 ) ) - 1; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(65, 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 6); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 5); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 6); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 5); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "heightCompleteBinaryTreeHeapNNodes", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"n\": 65}}, {\"idx\": 1, \"outputs\": 6, \"inputs\": {\"n\": 94}}, {\"idx\": 2, \"outputs\": 5, \"inputs\": {\"n\": 52}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"n\": 31}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"n\": 9}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 1}}, {\"idx\": 6, \"outputs\": 5, \"inputs\": {\"n\": 41}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"n\": 98}}, {\"idx\": 8, \"outputs\": 5, \"inputs\": {\"n\": 45}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"n\": 24}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
245
Hexagonal Number
C++
int hexagonalNumber(int n) {
[ "n" ]
def hexagonal_number(n): return (n * ((2 * n) - 1))
int hexagonal_number(int n) { return n * ( 2 * n - 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(38, 2850); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 3828); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 6670); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 190); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 1891); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 5565); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 17578); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 8128); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 10011); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 6903); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "hexagonalNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2850, \"inputs\": {\"n\": 38}}, {\"idx\": 1, \"outputs\": 3828, \"inputs\": {\"n\": 44}}, {\"idx\": 2, \"outputs\": 6670, \"inputs\": {\"n\": 58}}, {\"idx\": 3, \"outputs\": 190, \"inputs\": {\"n\": 10}}, {\"idx\": 4, \"outputs\": 1891, \"inputs\": {\"n\": 31}}, {\"idx\": 5, \"outputs\": 5565, \"inputs\": {\"n\": 53}}, {\"idx\": 6, \"outputs\": 17578, \"inputs\": {\"n\": 94}}, {\"idx\": 7, \"outputs\": 8128, \"inputs\": {\"n\": 64}}, {\"idx\": 8, \"outputs\": 10011, \"inputs\": {\"n\": 71}}, {\"idx\": 9, \"outputs\": 6903, \"inputs\": {\"n\": 59}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
246
Highway Billboard Problem
C++
int highwayBillboardProblem(int m, vector<int> x, vector<int> revenue, int n, int t) {
[ "m", "x", "revenue", "n", "t" ]
def highway_billboard_problem(m, x, revenue, n, t): maxRev = ([0] * (m + 1)) nxtbb = 0 for i in range(1, (m + 1)): if (nxtbb < n): if (x[nxtbb] != i): maxRev[i] = maxRev[(i - 1)] else: if (i <= t): maxRev[i] = max(maxRev[(i - 1)], revenue[nxtbb]) else: maxRev[i] = max((maxRev[((i - t) - 1)] + revenue[nxtbb]), maxRev[(i - 1)]) nxtbb += 1 else: maxRev[i] = maxRev[(i - 1)] return maxRev[m]
int highway_billboard_problem(int m, vector<int> x, vector<int> revenue, int n, int t) { int maxRev [ m + 1 ]; memset ( maxRev, 0, sizeof ( maxRev ) ); int nxtbb = 0; for ( int i = 1; i <= m; i ++ ) { if ( nxtbb < n ) { if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ]; else { if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ], revenue [ nxtbb ] ); else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ], maxRev [ i - 1 ] ); nxtbb ++; } } else maxRev [ i ] = maxRev [ i - 1 ]; } return maxRev [ m ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int m, vector<int> x, vector<int> revenue, int n, int t, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(m, x, revenue, n, t), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(16, {6, 15, 15, 18, 23, 29, 32, 36, 37, 39, 40, 41, 44, 49, 51, 52, 53, 57, 66, 68, 82, 89, 96}, {1, 2, 5, 5, 24, 26, 31, 32, 33, 41, 57, 59, 71, 75, 79, 87, 87, 88, 92, 94, 96, 96, 99}, 12, 12, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, {76, 60, 88, 46, -20, -78, -22, 54, -18, 92, -42, -66, -90, -72, -48, 22, -72, -42, -46, 94, 82, -78, 14, 86, 10, -64, -78, 66, 78, -36, 50, -20, -40, -12, 10, -46, 56, -18, 4, -76, -64, 74, 22, 34, 4, -2}, {28, 8, -60, 84, 68, -54, -56, 0, -68, -84, -6, 92, -80, -24, 86, -6, -44, 82, 74, 90, -46, 40, 62, 50, -42, 38, 78, 94, 46, -14, -48, 66, 70, 52, 10, -88, 54, -10, 98, 34, 16, -2, -62, -56, -40, 86}, 25, 27, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, {0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 1}, 9, 6, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, {21, 69, 30, 10, 71, 72, 71, 78, 30, 9, 72, 10, 7, 87, 30, 46, 56, 74, 73, 60, 86}, {72, 45, 7, 30, 76, 35, 75, 72, 4, 7, 55, 56, 7, 52, 48, 27, 11, 76, 66, 48, 33}, 18, 20, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, {-76, -76, -66, -64, -62, -60, -52, -48, -42, -28, -14, -6, -6, 16, 20, 20, 38, 46, 58, 60, 70, 72, 86, 98}, {-90, -82, -78, -76, -74, -52, -48, -44, -44, -40, -38, -14, -6, 10, 20, 38, 38, 40, 44, 48, 52, 54, 76, 78}, 15, 17, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, {1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1}, {0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1}, 28, 36, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, {16, 38, 72, 82}, {15, 34, 56, 74}, 2, 3, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, {28, -76, 42, -2, 30, -10, 52, 66, 26, 96, 96, -72, 26, -86, -30, -78, 32, -32, 58, 12, -72, 8, 34, -68, -28, -66}, {68, -38, 34, 20, 40, 78, 52, 80, 58, -12, -18, 10, 40, 34, 20, -32, -8, -46, 8, 62, 94, -30, -94, 26, -40, 64}, 13, 16, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, 15, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, {95, 12, 65, 97, 92, 49, 94, 32, 37, 97, 9, 35}, {25, 32, 14, 49, 90, 37, 92, 1, 8, 75, 50, 9}, 9, 8, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "highwayBillboardProblem", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"m\": 16, \"x\": [6, 15, 15, 18, 23, 29, 32, 36, 37, 39, 40, 41, 44, 49, 51, 52, 53, 57, 66, 68, 82, 89, 96], \"revenue\": [1, 2, 5, 5, 24, 26, 31, 32, 33, 41, 57, 59, 71, 75, 79, 87, 87, 88, 92, 94, 96, 96, 99], \"n\": 12, \"t\": 12}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"m\": 39, \"x\": [76, 60, 88, 46, -20, -78, -22, 54, -18, 92, -42, -66, -90, -72, -48, 22, -72, -42, -46, 94, 82, -78, 14, 86, 10, -64, -78, 66, 78, -36, 50, -20, -40, -12, 10, -46, 56, -18, 4, -76, -64, 74, 22, 34, 4, -2], \"revenue\": [28, 8, -60, 84, 68, -54, -56, 0, -68, -84, -6, 92, -80, -24, 86, -6, -44, 82, 74, 90, -46, 40, 62, 50, -42, 38, 78, 94, 46, -14, -48, 66, 70, 52, 10, -88, 54, -10, 98, 34, 16, -2, -62, -56, -40, 86], \"n\": 25, \"t\": 27}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"m\": 5, \"x\": [0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"revenue\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1], \"n\": 9, \"t\": 6}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"m\": 10, \"x\": [21, 69, 30, 10, 71, 72, 71, 78, 30, 9, 72, 10, 7, 87, 30, 46, 56, 74, 73, 60, 86], \"revenue\": [72, 45, 7, 30, 76, 35, 75, 72, 4, 7, 55, 56, 7, 52, 48, 27, 11, 76, 66, 48, 33], \"n\": 18, \"t\": 20}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"m\": 14, \"x\": [-76, -76, -66, -64, -62, -60, -52, -48, -42, -28, -14, -6, -6, 16, 20, 20, 38, 46, 58, 60, 70, 72, 86, 98], \"revenue\": [-90, -82, -78, -76, -74, -52, -48, -44, -44, -40, -38, -14, -6, 10, 20, 38, 38, 40, 44, 48, 52, 54, 76, 78], \"n\": 15, \"t\": 17}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"m\": 32, \"x\": [1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1], \"revenue\": [0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1], \"n\": 28, \"t\": 36}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"m\": 2, \"x\": [16, 38, 72, 82], \"revenue\": [15, 34, 56, 74], \"n\": 2, \"t\": 3}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"m\": 22, \"x\": [28, -76, 42, -2, 30, -10, 52, 66, 26, 96, 96, -72, 26, -86, -30, -78, 32, -32, 58, 12, -72, 8, 34, -68, -28, -66], \"revenue\": [68, -38, 34, 20, 40, 78, 52, 80, 58, -12, -18, 10, 40, 34, 20, -32, -8, -46, 8, 62, 94, -30, -94, 26, -40, 64], \"n\": 13, \"t\": 16}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"m\": 15, \"x\": [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], \"revenue\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 25, \"t\": 15}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"m\": 8, \"x\": [95, 12, 65, 97, 92, 49, 94, 32, 37, 97, 9, 35], \"revenue\": [25, 32, 14, 49, 90, 37, 92, 1, 8, 75, 50, 9], \"n\": 9, \"t\": 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 ] }
247
Horners Method Polynomial Evaluation
C++
long long hornersMethodPolynomialEvaluation(vector<int> poly, int n, int x) {
[ "poly", "n", "x" ]
def horners_method_polynomial_evaluation(poly, n, x): result = poly[0] for i in range(1, n): result = ((result * x) + poly[i]) return result
int horners_method_polynomial_evaluation(vector<int> poly, int n, int x) { int result = poly [ 0 ]; for ( int i = 1; i < n; i ++ ) result = result * x + poly [ 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> poly, int n, int x, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(poly, 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({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1}, 10, 8, 73); \n cout << \"TEST-\" << 0 << \"...\"\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}, 20, 23, 292561); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 62, 30, 27, 98, 75, 93, 37, 70, 16, 20, 74, 46, 74, 25, 59, 86, 32, 17, 90, 80, 10, 17}, 12, 12, 67907758875578); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "hornersMethodPolynomialEvaluation", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 73, \"inputs\": {\"poly\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 10, \"x\": 8}}, {\"idx\": 1, \"outputs\": 292561, \"inputs\": {\"poly\": [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\": 20, \"x\": 23}}, {\"idx\": 2, \"outputs\": 67907758875578, \"inputs\": {\"poly\": [86, 62, 30, 27, 98, 75, 93, 37, 70, 16, 20, 74, 46, 74, 25, 59, 86, 32, 17, 90, 80, 10, 17], \"n\": 12, \"x\": 12}}]", "test_case_ids": [ "0", "1", "2" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
248
How To Check If A Given Array Represents A Binary Heap
C++
bool howToCheckIfAGivenArrayRepresentsABinaryHeap(vector<int> arr, int i, int n) {
[ "arr", "i", "n" ]
def how_to_check_if_a_given_array_represents_a_binary_heap(arr, i, n): if (i > int(((n - 2) / 2))): return True if ((arr[i] >= arr[((2 * i) + 1)]) and (arr[i] >= arr[((2 * i) + 2)]) and how_to_check_if_a_given_array_represents_a_binary_heap(arr, ((2 * i) + 1), n) and how_to_check_if_a_given_array_represents_a_binary_heap(arr, ((2 * i) + 2), n)): return True return False
bool how_to_check_if_a_given_array_represents_a_binary_heap(vector<int> arr, int i, int n) { if ( i > ( n - 2 ) / 2 ) return true; if ( arr [ i ] >= arr [ 2 * i + 1 ] && arr [ i ] >= arr [ 2 * i + 2 ] && how_to_check_if_a_given_array_represents_a_binary_heap ( arr, 2 * i + 1, n ) && how_to_check_if_a_given_array_represents_a_binary_heap ( arr, 2 * i + 2, n ) ) return true; return false; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int i, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, i, 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, 5, 24, 24, 25, 25, 36, 37, 37, 39, 42, 44, 46, 50, 51, 54, 56, 60, 62, 70, 71, 73, 75, 80, 80, 85, 86, 89, 91, 95, 99}, 0, 18, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-44, -58, 88, -42, 42, -14, -44, 42, 64, 94, -46, -70, 34, -10, -46, -52, -6, -78, 64, 56, 74, 98, -34, -4, -92, 6, -52, -20, 78, -72, -40}, 0, 27, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 0, 20, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 2, 1, 34, 21, 37, 49, 31, 70, 97, 87, 50, 76, 55}, 0, 8, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -84, -82, -66, -64, -62, -56, -38, -24, -24, -4, 2, 4, 4, 8, 14, 16, 20, 30, 34, 34, 48, 58, 58, 70, 76, 78, 86, 88, 96, 98}, 0, 26, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0}, 12, 11, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 20, 30, 5, 10, 21, 5}, 0, 7, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 20, 30, 5, 10, 21, 5}, 0, 7, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 20, 30, 5, 10, 21, 5}, 2, 7, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 20, 30, 5, 10, 21, 5}, 4, 7, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "howToCheckIfAGivenArrayRepresentsABinaryHeap", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [1, 2, 3, 5, 24, 24, 25, 25, 36, 37, 37, 39, 42, 44, 46, 50, 51, 54, 56, 60, 62, 70, 71, 73, 75, 80, 80, 85, 86, 89, 91, 95, 99], \"i\": 0, \"n\": 18}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [-44, -58, 88, -42, 42, -14, -44, 42, 64, 94, -46, -70, 34, -10, -46, -52, -6, -78, 64, 56, 74, 98, -34, -4, -92, 6, -52, -20, 78, -72, -40], \"i\": 0, \"n\": 27}}, {\"idx\": 2, \"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], \"i\": 0, \"n\": 20}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"arr\": [10, 2, 1, 34, 21, 37, 49, 31, 70, 97, 87, 50, 76, 55], \"i\": 0, \"n\": 8}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"arr\": [-94, -84, -82, -66, -64, -62, -56, -38, -24, -24, -4, 2, 4, 4, 8, 14, 16, 20, 30, 34, 34, 48, 58, 58, 70, 76, 78, 86, 88, 96, 98], \"i\": 0, \"n\": 26}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"arr\": [1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0], \"i\": 12, \"n\": 11}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [5, 20, 30, 5, 10, 21, 5], \"i\": 0, \"n\": 7}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"arr\": [50, 20, 30, 5, 10, 21, 5], \"i\": 0, \"n\": 7}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"arr\": [50, 20, 30, 5, 10, 21, 5], \"i\": 2, \"n\": 7}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"arr\": [50, 20, 30, 5, 10, 21, 5], \"i\": 4, \"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 ] }
249
How To Check If A Given Array Represents A Binary Heap 1
C++
bool howToCheckIfAGivenArrayRepresentsABinaryHeap1(vector<int> arr, int n) {
[ "arr", "n" ]
def how_to_check_if_a_given_array_represents_a_binary_heap_1(arr, n): for i in range((int(((n - 2) / 2)) + 1)): if (arr[((2 * i) + 1)] > arr[i]): return False if ((((2 * i) + 2) < n) and (arr[((2 * i) + 2)] > arr[i])): return False return True
bool how_to_check_if_a_given_array_represents_a_binary_heap_1(vector<int> arr, int n) { for ( int i = 0; i <= ( n - 2 ) / 2; i ++ ) { if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false; if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false; } return true; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 2, 2, 7, 10, 14, 24, 38, 42, 50, 59, 60, 72, 73, 79, 83, 89}, 9, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-48, 98, 96, -56, -2, 58, 52, -50, 58, 50, 62, 86, -26, -98, 34, 20, -28, 56, -36}, 9, 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, 1}, 20, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({91, 50, 37}, 2, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -26, 0, 0, 6, 14, 22, 76, 82, 88, 98}, 10, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0}, 1, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9, 24, 24, 33, 48, 50, 55, 61, 69, 79, 83}, 8, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({30, 32, -82, -48, 88, -24, 74, 2, 90, 98, 68, 82, 32, -60, 2, -94, 18, 14, 46, 50, -60, -74, -76, 66, -76, -34, -20, 82, -44, -62, 34, 48, -56, 2, 64, -78, -64, 98, -10, -28, 78, -42}, 27, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 6, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({38, 74, 99, 75, 44, 75, 24, 70, 78, 74, 60, 59, 34, 27, 7, 23, 19, 95, 4, 35, 38, 22, 46, 1, 44, 20, 52, 1, 96, 57, 5, 76, 49, 1, 37, 35}, 31, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "howToCheckIfAGivenArrayRepresentsABinaryHeap1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"arr\": [2, 2, 2, 7, 10, 14, 24, 38, 42, 50, 59, 60, 72, 73, 79, 83, 89], \"n\": 9}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"arr\": [-48, 98, 96, -56, -2, 58, 52, -50, 58, 50, 62, 86, -26, -98, 34, 20, -28, 56, -36], \"n\": 9}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"arr\": [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\": 3, \"outputs\": true, \"inputs\": {\"arr\": [91, 50, 37], \"n\": 2}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"arr\": [-80, -26, 0, 0, 6, 14, 22, 76, 82, 88, 98], \"n\": 10}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"arr\": [1, 0], \"n\": 1}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"arr\": [9, 24, 24, 33, 48, 50, 55, 61, 69, 79, 83], \"n\": 8}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"arr\": [30, 32, -82, -48, 88, -24, 74, 2, 90, 98, 68, 82, 32, -60, 2, -94, 18, 14, 46, 50, -60, -74, -76, 66, -76, -34, -20, 82, -44, -62, 34, 48, -56, 2, 64, -78, -64, 98, -10, -28, 78, -42], \"n\": 27}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 6}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"arr\": [38, 74, 99, 75, 44, 75, 24, 70, 78, 74, 60, 59, 34, 27, 7, 23, 19, 95, 4, 35, 38, 22, 46, 1, 44, 20, 52, 1, 96, 57, 5, 76, 49, 1, 37, 35], \"n\": 31}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
250
How To Print Maximum Number Of A Using Given Four Keys
C++
long long howToPrintMaximumNumberOfAUsingGivenFourKeys(int n) {
[ "n" ]
def how_to_print_maximum_number_of_a_using_given_four_keys(N): if (N <= 6): return N screen = ([0] * N) for n in range(1, 7): screen[(n - 1)] = n for n in range(7, (N + 1)): screen[(n - 1)] = max((2 * screen[(n - 4)]), max((3 * screen[(n - 5)]), (4 * screen[(n - 6)]))) return screen[(N - 1)]
int how_to_print_maximum_number_of_a_using_given_four_keys(int N) { if ( N <= 6 ) return N; int screen [ N ]; int b; int n; for ( n = 1; n <= 6; n ++ ) screen [ n - 1 ] = n; for ( n = 7; n <= N; n ++ ) { screen [ n - 1 ] = max ( 2 * screen [ n - 4 ], max ( 3 * screen [ n - 5 ], 4 * screen [ n - 6 ] ) ); } return screen [ 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(41, 110592); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 274877906944); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 5435817984); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 82944); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 1811939328); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 196608); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 150994944); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 1024); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 86973087744); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "howToPrintMaximumNumberOfAUsingGivenFourKeys", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 110592, \"inputs\": {\"n\": 41}}, {\"idx\": 1, \"outputs\": 274877906944, \"inputs\": {\"n\": 94}}, {\"idx\": 2, \"outputs\": 5435817984, \"inputs\": {\"n\": 80}}, {\"idx\": 3, \"outputs\": 82944, \"inputs\": {\"n\": 40}}, {\"idx\": 4, \"outputs\": 1811939328, \"inputs\": {\"n\": 76}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"n\": 5}}, {\"idx\": 6, \"outputs\": 196608, \"inputs\": {\"n\": 43}}, {\"idx\": 7, \"outputs\": 150994944, \"inputs\": {\"n\": 67}}, {\"idx\": 8, \"outputs\": 1024, \"inputs\": {\"n\": 24}}, {\"idx\": 9, \"outputs\": 86973087744, \"inputs\": {\"n\": 90}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
251
How To Turn Off A Particular Bit In A Number
C++
int howToTurnOffAParticularBitInANumber(int n, int k) {
[ "n", "k" ]
def how_to_turn_off_a_particular_bit_in_a_number(n, k): if (k <= 0): return n return (n & (~ (1 << (k - 1))))
int how_to_turn_off_a_particular_bit_in_a_number(int n, int k) { if ( k <= 0 ) return n; return ( n & ~ ( 1 << ( k - 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 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(49, 15, 49); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 69, 59); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 20, 76); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 76, 27); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 60, 61); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 27, 67); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 71, 63); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 25, 85); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 64, 90); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 55, 24); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "howToTurnOffAParticularBitInANumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 49, \"inputs\": {\"n\": 49, \"k\": 15}}, {\"idx\": 1, \"outputs\": 59, \"inputs\": {\"n\": 59, \"k\": 69}}, {\"idx\": 2, \"outputs\": 76, \"inputs\": {\"n\": 76, \"k\": 20}}, {\"idx\": 3, \"outputs\": 27, \"inputs\": {\"n\": 27, \"k\": 76}}, {\"idx\": 4, \"outputs\": 61, \"inputs\": {\"n\": 61, \"k\": 60}}, {\"idx\": 5, \"outputs\": 67, \"inputs\": {\"n\": 67, \"k\": 27}}, {\"idx\": 6, \"outputs\": 63, \"inputs\": {\"n\": 63, \"k\": 71}}, {\"idx\": 7, \"outputs\": 85, \"inputs\": {\"n\": 85, \"k\": 25}}, {\"idx\": 8, \"outputs\": 90, \"inputs\": {\"n\": 90, \"k\": 64}}, {\"idx\": 9, \"outputs\": 24, \"inputs\": {\"n\": 24, \"k\": 55}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
252
Hypercube Graph
C++
long long hypercubeGraph(int n) {
[ "n" ]
def hypercube_graph(n): if (n == 1): return 2 return (2 * hypercube_graph((n - 1)))
int hypercube_graph(int n) { if ( n == 1 ) return 2; return 2 * hypercube_graph ( 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(28, 268435456); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 35184372088832); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 2199023255552); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 68719476736); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "hypercubeGraph", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 268435456, \"inputs\": {\"n\": 28}}, {\"idx\": 1, \"outputs\": 35184372088832, \"inputs\": {\"n\": 45}}, {\"idx\": 2, \"outputs\": 2199023255552, \"inputs\": {\"n\": 41}}, {\"idx\": 3, \"outputs\": 68719476736, \"inputs\": {\"n\": 36}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
253
Integer Positive Value Positive Negative Value Array
C++
int integerPositiveValuePositiveNegativeValueArray(vector<int> arr, int n) {
[ "arr", "n" ]
def integer_positive_value_positive_negative_value_array(arr, n): hash = dict() maximum = 0 for i in arr: if (i < 0): if (abs(i) not in hash.keys()): hash[abs(i)] = (- 1) else: hash[abs(i)] -= 1 else: hash[i] = (hash.get(i, 0) + 1) for i in arr: if ((i in hash.keys()) and (hash[i] > 0)): return i return (- 1)
int integer_positive_value_positive_negative_value_array(vector<int> arr, int n) { unordered_map < int, int > hash; int maximum = 0; for ( int i = 0; i < n; i ++ ) { if ( arr [ i ] < 0 ) hash [ abs ( arr [ i ] ) ] -= 1; else hash [ arr [ i ] ] += 1; } for ( int i = 0; i < n; i ++ ) if ( hash [ arr [ i ] ] != 0 ) 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, 7, 10, 14, 15, 24, 27, 32, 33, 38, 39, 40, 42, 42, 47, 58, 75, 76, 78, 79, 83, 85, 89, 96}, 18, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-36, 14, -76, -70, 52, 18, 64}, 5, 14); \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}, 17, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({35, 50, 36, 50, 82, 54, 10, 45, 13, 22, 1, 41, 13, 11, 4, 43, 50, 27, 94, 57}, 15, 35); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -86, -84, -80, -80, -74, -72, -48, -46, -46, -44, -34, -32, -24, -22, -14, 4, 4, 8, 8, 10, 12, 20, 20, 24, 24, 24, 28, 32, 34, 36, 44, 46, 54, 54, 60, 62, 62, 62, 70, 70, 80, 88, 88, 90}, 27, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0}, 1, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 3, 6, 6, 8, 12, 13, 17, 27, 28, 31, 40, 40, 42, 43, 53, 55, 58, 60, 60, 61, 65, 66, 72, 72, 75, 80, 84, 89, 96, 97, 99}, 31, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, -38, -82, 30, -66, 42, 54, -96, -46, -30, 18, -50, 96, 90, 4, 74, -22, 8, 34, 74, -46, 8, -32, 88, -96, 26, -80, 50, 92, -80, 44, 36}, 24, 52); \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}, 16, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({38, 20, 54, 51, 11, 61, 90, 28, 23, 55, 65, 87, 99, 70, 74, 3, 68, 23, 74, 53, 80, 7, 57, 24, 66, 8, 15, 63, 18, 67, 96, 31, 63, 50}, 30, 38); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "integerPositiveValuePositiveNegativeValueArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [1, 7, 10, 14, 15, 24, 27, 32, 33, 38, 39, 40, 42, 42, 47, 58, 75, 76, 78, 79, 83, 85, 89, 96], \"n\": 18}}, {\"idx\": 1, \"outputs\": 14, \"inputs\": {\"arr\": [-36, 14, -76, -70, 52, 18, 64], \"n\": 5}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 17}}, {\"idx\": 3, \"outputs\": 35, \"inputs\": {\"arr\": [35, 50, 36, 50, 82, 54, 10, 45, 13, 22, 1, 41, 13, 11, 4, 43, 50, 27, 94, 57], \"n\": 15}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"arr\": [-88, -86, -84, -80, -80, -74, -72, -48, -46, -46, -44, -34, -32, -24, -22, -14, 4, 4, 8, 8, 10, 12, 20, 20, 24, 24, 24, 28, 32, 34, 36, 44, 46, 54, 54, 60, 62, 62, 62, 70, 70, 80, 88, 88, 90], \"n\": 27}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0], \"n\": 1}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 3, 6, 6, 8, 12, 13, 17, 27, 28, 31, 40, 40, 42, 43, 53, 55, 58, 60, 60, 61, 65, 66, 72, 72, 75, 80, 84, 89, 96, 97, 99], \"n\": 31}}, {\"idx\": 7, \"outputs\": 52, \"inputs\": {\"arr\": [52, -38, -82, 30, -66, 42, 54, -96, -46, -30, 18, -50, 96, 90, 4, 74, -22, 8, 34, 74, -46, 8, -32, 88, -96, 26, -80, 50, 92, -80, 44, 36], \"n\": 24}}, {\"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], \"n\": 16}}, {\"idx\": 9, \"outputs\": 38, \"inputs\": {\"arr\": [38, 20, 54, 51, 11, 61, 90, 28, 23, 55, 65, 87, 99, 70, 74, 3, 68, 23, 74, 53, 80, 7, 57, 24, 66, 8, 15, 63, 18, 67, 96, 31, 63, 50], \"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 ] }
254
Integer Positive Value Positive Negative Value Array 1
C++
double integerPositiveValuePositiveNegativeValueArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def integer_positive_value_positive_negative_value_array_1(arr, n): neg = 0 pos = 0 sum = 0 for i in range(0, n): sum += arr[i] if (arr[i] < 0): neg += 1 else: pos += 1 return (sum / abs((neg - pos)))
int integer_positive_value_positive_negative_value_array_1(vector<int> arr, int n) { int neg = 0, pos = 0; int sum = 0; for ( int i = 0; i < n; i ++ ) { sum += arr [ i ]; if ( arr [ i ] < 0 ) neg ++; else pos ++; } return ( sum / abs ( neg - pos ) ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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(vector<int> arr, int n, double 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({49, 98}, 1, 49.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({82, 66, -68, 24, -10}, 2, 74.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}, 8, 0.125); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({56, 3, 18, 5, 20, 56, 47, 29, 60, 98, 60, 40, 42, 2, 54, 56, 91, 8, 93, 14, 31, 27, 61, 49, 23, 12, 71}, 25, 41.72); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -94, -92, -86, -50, -48, -6, 8, 28, 40, 44, 58, 62, 72, 94}, 12, -146.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1}, 36, 0.5833333333333334); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, 56, 56}, 1, 16.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({74, -90, -92, 30, -18, 66, -66, 22}, 5, -96.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 7, 0.5714285714285714); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({21, 64, 82, 78, 30, 34, 35}, 5, 55.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "integerPositiveValuePositiveNegativeValueArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 49.0, \"inputs\": {\"arr\": [49, 98], \"n\": 1}}, {\"idx\": 1, \"outputs\": 74.0, \"inputs\": {\"arr\": [82, 66, -68, 24, -10], \"n\": 2}}, {\"idx\": 2, \"outputs\": 0.125, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 8}}, {\"idx\": 3, \"outputs\": 41.72, \"inputs\": {\"arr\": [56, 3, 18, 5, 20, 56, 47, 29, 60, 98, 60, 40, 42, 2, 54, 56, 91, 8, 93, 14, 31, 27, 61, 49, 23, 12, 71], \"n\": 25}}, {\"idx\": 4, \"outputs\": -146.0, \"inputs\": {\"arr\": [-94, -94, -92, -86, -50, -48, -6, 8, 28, 40, 44, 58, 62, 72, 94], \"n\": 12}}, {\"idx\": 5, \"outputs\": 0.5833333333333334, \"inputs\": {\"arr\": [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1], \"n\": 36}}, {\"idx\": 6, \"outputs\": 16.0, \"inputs\": {\"arr\": [16, 56, 56], \"n\": 1}}, {\"idx\": 7, \"outputs\": -96.0, \"inputs\": {\"arr\": [74, -90, -92, 30, -18, 66, -66, 22], \"n\": 5}}, {\"idx\": 8, \"outputs\": 0.5714285714285714, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 55.0, \"inputs\": {\"arr\": [21, 64, 82, 78, 30, 34, 35], \"n\": 5}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
255
K Numbers Difference Maximum Minimum K Number Minimized
C++
long long kNumbersDifferenceMaximumMinimumKNumberMinimized(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def k_numbers_difference_maximum_minimum_k_number_minimized(arr, n, k): result = (+ 2147483647) arr.sort() for i in range(((n - k) + 1)): result = int(min(result, (arr[((i + k) - 1)] - arr[i]))) return result
int k_numbers_difference_maximum_minimum_k_number_minimized(vector<int> arr, int n, int k) { int result = INT_MAX; sort(arr.begin(), arr.end()); for ( int i = 0; i <= n - k; i ++ ) result = min ( result, arr [ i + k - 1 ] - arr [ 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, 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, 2, 7, 8, 14, 16, 20, 20, 23, 24, 24, 29, 30, 32, 34, 35, 37, 38, 43, 44, 46, 50, 52, 55, 57, 61, 71, 79, 86, 86, 89, 91, 91, 95}, 33, 17, 32); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -74, -70, -68, -66, -66, -62, -60, -60, -52, -50, -46, -34, -34, -28, -18, -4, 0, 6, 8, 16, 34, 34, 34, 42, 42, 44, 46, 54, 54, 54, 58, 62, 68, 72, 76, 78, 80, 84, 88, 90, 90}, 33, 33, 142); \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}, 8, 13, 2147483647); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32}, 0, 0, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -78, -76, -72, -72, -70, -54, -46, -40, -34, -30, -26, -24, -22, -18, -16, -6, -4, -4, 2, 6, 14, 16, 18, 30, 30, 36, 54, 54, 58, 66, 72, 78, 80, 80, 82, 88, 98}, 26, 25, 108); \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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 39, 41, 2147483647); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 13, 14, 18, 23, 32, 67, 72, 75, 76, 87, 95}, 10, 8, 62); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 30}, 1, 1, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 33, 2147483647); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 3, 7, 9, 15, 16, 19, 21, 25, 27, 29, 30, 31, 33, 35, 36, 36, 37, 40, 41, 42, 52, 52, 53, 57, 57, 63, 67, 67, 69, 72, 73, 74, 78, 83, 86, 87, 93, 94, 95, 95}, 36, 37, 2147483647); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "kNumbersDifferenceMaximumMinimumKNumberMinimized", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 32, \"inputs\": {\"arr\": [1, 1, 2, 7, 8, 14, 16, 20, 20, 23, 24, 24, 29, 30, 32, 34, 35, 37, 38, 43, 44, 46, 50, 52, 55, 57, 61, 71, 79, 86, 86, 89, 91, 91, 95], \"n\": 33, \"k\": 17}}, {\"idx\": 1, \"outputs\": 142, \"inputs\": {\"arr\": [-80, -74, -70, -68, -66, -66, -62, -60, -60, -52, -50, -46, -34, -34, -28, -18, -4, 0, 6, 8, 16, 34, 34, 34, 42, 42, 44, 46, 54, 54, 54, 58, 62, 68, 72, 76, 78, 80, 84, 88, 90, 90], \"n\": 33, \"k\": 33}}, {\"idx\": 2, \"outputs\": 2147483647, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 8, \"k\": 13}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [32], \"n\": 0, \"k\": 0}}, {\"idx\": 4, \"outputs\": 108, \"inputs\": {\"arr\": [-96, -78, -76, -72, -72, -70, -54, -46, -40, -34, -30, -26, -24, -22, -18, -16, -6, -4, -4, 2, 6, 14, 16, 18, 30, 30, 36, 54, 54, 58, 66, 72, 78, 80, 80, 82, 88, 98], \"n\": 26, \"k\": 25}}, {\"idx\": 5, \"outputs\": 2147483647, \"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], \"n\": 39, \"k\": 41}}, {\"idx\": 6, \"outputs\": 62, \"inputs\": {\"arr\": [3, 13, 14, 18, 23, 32, 67, 72, 75, 76, 87, 95], \"n\": 10, \"k\": 8}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [8, 30], \"n\": 1, \"k\": 1}}, {\"idx\": 8, \"outputs\": 2147483647, \"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], \"n\": 27, \"k\": 33}}, {\"idx\": 9, \"outputs\": 2147483647, \"inputs\": {\"arr\": [2, 3, 3, 7, 9, 15, 16, 19, 21, 25, 27, 29, 30, 31, 33, 35, 36, 36, 37, 40, 41, 42, 52, 52, 53, 57, 57, 63, 67, 67, 69, 72, 73, 74, 78, 83, 86, 87, 93, 94, 95, 95], \"n\": 36, \"k\": 37}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
256
K Th Digit Raised Power B
C++
double kThDigitRaisedPowerB(int a, int b, int k) {
[ "a", "b", "k" ]
def k_th_digit_raised_power_b(a, b, k): p = (a ** b) count = 0 while ((p > 0) and (count < k)): rem = (p % 10) count = (count + 1) if (count == k): return rem p = (p / 10)
int k_th_digit_raised_power_b(int a, int b, int k) { int p = pow ( a, b ); int count = 0; while ( p > 0 && count < k ) { int rem = p % 10; count ++; if ( count == k ) return rem; p = p / 10; } return 0; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int a, int b, int k, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(11, 2, 1, 1.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 3, 3, 9.210000000000036); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 4, 3, 6.25); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 2, 4, 0.001); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 2, 3, 0.25); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 5, 8, 5.233257599999973); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 10, 3, 2.489999999757856); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 30, 10, 4.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 50, 1, 0.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "kThDigitRaisedPowerB", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"a\": 11, \"b\": 2, \"k\": 1}}, {\"idx\": 1, \"outputs\": 9.210000000000036, \"inputs\": {\"a\": 41, \"b\": 3, \"k\": 3}}, {\"idx\": 2, \"outputs\": 6.25, \"inputs\": {\"a\": 5, \"b\": 4, \"k\": 3}}, {\"idx\": 3, \"outputs\": 0.001, \"inputs\": {\"a\": 1, \"b\": 2, \"k\": 4}}, {\"idx\": 4, \"outputs\": 0.25, \"inputs\": {\"a\": 5, \"b\": 2, \"k\": 3}}, {\"idx\": 5, \"outputs\": 5.233257599999973, \"inputs\": {\"a\": 66, \"b\": 5, \"k\": 8}}, {\"idx\": 6, \"outputs\": 2.489999999757856, \"inputs\": {\"a\": 7, \"b\": 10, \"k\": 3}}, {\"idx\": 7, \"outputs\": 4.0, \"inputs\": {\"a\": 77, \"b\": 30, \"k\": 10}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"a\": 60, \"b\": 50, \"k\": 1}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
257
K Th Distinct Or Non Repeating Element In An Array
C++
int kThDistinctOrNonRepeatingElementInAnArray(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def k_th_distinct_or_non_repeating_element_in_an_array(arr, n, k): dist_count = 0 for i in range(n): j = 0 while (j < n): if ((i != j) and (arr[j] == arr[i])): break j += 1 if (j == n): dist_count += 1 if (dist_count == k): return arr[i] return (- 1)
int k_th_distinct_or_non_repeating_element_in_an_array(vector<int> arr, int n, int k) { int dist_count = 0; for ( int i = 0; i < n; i ++ ) { int j; for ( j = 0; j < n; j ++ ) if ( i != j && arr [ j ] == arr [ i ] ) break; if ( j == n ) dist_count ++; if ( dist_count == k ) 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 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, 3, 8, 18, 20, 33, 53, 56, 60, 71, 76, 80, 81, 87, 88, 89, 92, 95}, 16, 16, 89); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, 6, 32, 52, -12, -32, 22, -40, -82, 24, 30, 10, -40}, 8, 6, -32); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 7, 5, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 28, 55, 21, 42, 60, 96, 83, 98, 75, 29, 73, 51, 21, 27, 65, 19, 47, 12, 81, 19, 94, 50, 43, 21, 32, 52, 44, 52, 91, 49, 59, 52, 10, 75, 86, 46, 43, 3, 49, 70, 60, 77, 99, 27, 63}, 40, 39, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -90, -76, -44, -16, -8, 0, 0, 2, 2, 8, 14, 16, 18, 18, 20, 20, 28, 34, 44, 68, 74, 84, 90}, 23, 12, 44); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}, 10, 8, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 5, 8, 9, 15, 26, 26, 26, 35, 39, 40, 42, 43, 45, 45, 48, 52, 54, 56, 57, 67, 74, 77, 79, 80, 81, 86, 87, 92, 95, 97}, 26, 24, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-76, -24, -12, 66, -40, 26, 72, 46, -56, 58, -68, 2, -82}, 6, 10, -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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 17, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({29, 83, 32, 75, 5, 22, 68, 64, 36, 18, 7, 63, 16, 42, 77, 61, 1, 26, 12, 41, 67, 85, 85, 35, 94, 18, 14, 65, 8, 55, 44, 34, 48, 23, 8, 27, 86, 2, 51, 91}, 28, 24, 65); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "kThDistinctOrNonRepeatingElementInAnArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 89, \"inputs\": {\"arr\": [2, 3, 8, 18, 20, 33, 53, 56, 60, 71, 76, 80, 81, 87, 88, 89, 92, 95], \"n\": 16, \"k\": 16}}, {\"idx\": 1, \"outputs\": -32, \"inputs\": {\"arr\": [-78, 6, 32, 52, -12, -32, 22, -40, -82, 24, 30, 10, -40], \"n\": 8, \"k\": 6}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 7, \"k\": 5}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [3, 28, 55, 21, 42, 60, 96, 83, 98, 75, 29, 73, 51, 21, 27, 65, 19, 47, 12, 81, 19, 94, 50, 43, 21, 32, 52, 44, 52, 91, 49, 59, 52, 10, 75, 86, 46, 43, 3, 49, 70, 60, 77, 99, 27, 63], \"n\": 40, \"k\": 39}}, {\"idx\": 4, \"outputs\": 44, \"inputs\": {\"arr\": [-96, -90, -76, -44, -16, -8, 0, 0, 2, 2, 8, 14, 16, 18, 18, 20, 20, 28, 34, 44, 68, 74, 84, 90], \"n\": 23, \"k\": 12}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0], \"n\": 10, \"k\": 8}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [3, 4, 5, 8, 9, 15, 26, 26, 26, 35, 39, 40, 42, 43, 45, 45, 48, 52, 54, 56, 57, 67, 74, 77, 79, 80, 81, 86, 87, 92, 95, 97], \"n\": 26, \"k\": 24}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-76, -24, -12, 66, -40, 26, 72, 46, -56, 58, -68, 2, -82], \"n\": 6, \"k\": 10}}, {\"idx\": 8, \"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, 1, 1, 1, 1], \"n\": 27, \"k\": 17}}, {\"idx\": 9, \"outputs\": 65, \"inputs\": {\"arr\": [29, 83, 32, 75, 5, 22, 68, 64, 36, 18, 7, 63, 16, 42, 77, 61, 1, 26, 12, 41, 67, 85, 85, 35, 94, 18, 14, 65, 8, 55, 44, 34, 48, 23, 8, 27, 86, 2, 51, 91], \"n\": 28, \"k\": 24}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
258
K Th Distinct Or Non Repeating Element In An Array 1
C++
int kThDistinctOrNonRepeatingElementInAnArray1(vector<int> arr, int size, int kthindex) {
[ "arr", "size", "kthindex" ]
def k_th_distinct_or_non_repeating_element_in_an_array_1(arr, size, KthIndex): dict = { } vect = [] for i in range(size): if (arr[i] in dict): dict[arr[i]] = (dict[arr[i]] + 1) else: dict[arr[i]] = 1 for i in range(size): if (dict[arr[i]] > 1): continue else: KthIndex = (KthIndex - 1) if (KthIndex == 0): return arr[i] return (- 1)
int k_th_distinct_or_non_repeating_element_in_an_array_1(vector<int> arr, int n, int k) { unordered_map < int, int > h; for ( int i = 0; i < n; i ++ ) h [ arr [ i ] ] ++; if ( h . size ( ) < k ) return - 1; int dist_count = 0; for ( int i = 0; i < n; i ++ ) { if ( h [ arr [ i ] ] == 1 ) dist_count ++; if ( dist_count == k ) 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 size, int kthindex, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, size, kthindex), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 25, 27, 27, 73, 91}, 5, 3, 73); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -74, -88, 28, -32, 20, -34, 32}, 5, 6, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, 32, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 11, 36, 27, 6, 24, 58, 44, 14, 68}, 7, 5, 6); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -94, -92, -86, -86, -70, -66, -64, -64, -58, -52, -46, -44, -44, -38, -38, -28, -24, -12, -10, -4, -2, 2, 8, 10, 12, 20, 22, 26, 26, 36, 42, 52, 54, 60, 60, 68, 82, 82, 92, 98}, 27, 27, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1}, 27, 20, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 8, 9, 10, 10, 13, 14, 16, 18, 23, 24, 25, 27, 28, 30, 33, 36, 39, 42, 42, 44, 45, 45, 48, 52, 52, 55, 55, 59, 59, 59, 60, 61, 61, 66, 66, 67, 68, 71, 72, 75, 76, 79, 80, 94, 94}, 44, 26, 79); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-12, 56, -48, 52, -96, -84, 32, -12, -6, 82, 70, 18, 66, -6, -22, -46, -54, 18, -14, -32, 68, 82, -44, -42, 10, 56, 8, -56, 24, 20, -38, 30, -52, -66, 82, -64, 68, -82, 52, -88, -34, -26, 94, 58, -4, -84, -60}, 37, 46, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 21, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 23, 75, 84, 28, 34, 15, 13, 51, 69, 94, 45, 38, 38}, 13, 12, 45); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "kThDistinctOrNonRepeatingElementInAnArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 73, \"inputs\": {\"arr\": [17, 25, 27, 27, 73, 91], \"size\": 5, \"kthindex\": 3}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [-86, -74, -88, 28, -32, 20, -34, 32], \"size\": 5, \"kthindex\": 6}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"size\": 33, \"kthindex\": 32}}, {\"idx\": 3, \"outputs\": 6, \"inputs\": {\"arr\": [5, 11, 36, 27, 6, 24, 58, 44, 14, 68], \"size\": 7, \"kthindex\": 5}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-98, -98, -94, -92, -86, -86, -70, -66, -64, -64, -58, -52, -46, -44, -44, -38, -38, -28, -24, -12, -10, -4, -2, 2, 8, 10, 12, 20, 22, 26, 26, 36, 42, 52, 54, 60, 60, 68, 82, 82, 92, 98], \"size\": 27, \"kthindex\": 27}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1], \"size\": 27, \"kthindex\": 20}}, {\"idx\": 6, \"outputs\": 79, \"inputs\": {\"arr\": [3, 8, 9, 10, 10, 13, 14, 16, 18, 23, 24, 25, 27, 28, 30, 33, 36, 39, 42, 42, 44, 45, 45, 48, 52, 52, 55, 55, 59, 59, 59, 60, 61, 61, 66, 66, 67, 68, 71, 72, 75, 76, 79, 80, 94, 94], \"size\": 44, \"kthindex\": 26}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-12, 56, -48, 52, -96, -84, 32, -12, -6, 82, 70, 18, 66, -6, -22, -46, -54, 18, -14, -32, 68, 82, -44, -42, 10, 56, 8, -56, 24, 20, -38, 30, -52, -66, 82, -64, 68, -82, 52, -88, -34, -26, 94, 58, -4, -84, -60], \"size\": 37, \"kthindex\": 46}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"size\": 22, \"kthindex\": 21}}, {\"idx\": 9, \"outputs\": 45, \"inputs\": {\"arr\": [1, 23, 75, 84, 28, 34, 15, 13, 51, 69, 94, 45, 38, 38], \"size\": 13, \"kthindex\": 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 ] }
259
K Th Element Two Sorted Arrays
C++
int kThElementTwoSortedArrays(vector<int> arr1, vector<int> arr2, int m, int n, int k) {
[ "arr1", "arr2", "m", "n", "k" ]
def k_th_element_two_sorted_arrays(arr1, arr2, m, n, k): sorted1 = ([0] * (m + n)) i = 0 j = 0 d = 0 while ((i < m) and (j < n)): if (arr1[i] < arr2[j]): sorted1[d] = arr1[i] i += 1 else: sorted1[d] = arr2[j] j += 1 d += 1 while (i < m): sorted1[d] = arr1[i] d += 1 i += 1 while (j < n): sorted1[d] = arr2[j] d += 1 j += 1 return sorted1[(k - 1)]
int k_th_element_two_sorted_arrays(vector<int> arr1, vector<int> arr2, int m, int n, int k) { int sorted1 [ m + n ]; int i = 0, j = 0, d = 0; while ( i < m && j < n ) { if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ]; else sorted1 [ d ++ ] = arr2 [ j ++ ]; } while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ]; while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ]; return sorted1 [ k - 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> arr1, vector<int> arr2, int m, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, m, 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, 2, 4, 4, 9, 10, 14, 16, 16, 19, 20, 21, 25, 26, 29, 36, 36, 37, 38, 44, 44, 49, 53, 54, 56, 61, 62, 64, 72, 72, 73, 77, 80, 84, 84, 87, 93, 94}, {6, 8, 10, 10, 12, 14, 24, 31, 33, 33, 35, 35, 35, 41, 46, 47, 49, 51, 52, 56, 57, 59, 62, 65, 72, 72, 73, 73, 79, 80, 82, 83, 83, 84, 87, 87, 93, 99}, 27, 21, 23, 31); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, -90, 62, 22, -94, -74, -22, 44, -94, 20, -40, 20, 0, 32, 24, 78, 8, 4, 98, -74, -60}, {58, 74, -46, 38, -58, -78, -32, -84, 84, -54, 84, -34, -26, 88, 74, 48, 26, -92, 68, -86, 74, 88}, 18, 11, 12, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 31, 42, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 44, 62, 2, 71, 88, 60, 78, 32, 46, 17, 47, 65, 78, 65, 94}, {18, 3, 15, 9, 61, 73, 3, 62, 87, 1, 54, 97, 61, 37, 23, 65}, 11, 11, 13, 71); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -84, -82, -70, -70, -60, -54, -54, -52, -52, -46, -40, -40, -36, -34, -32, -30, -22, -18, -16, -10, -4, 8, 12, 18, 22, 32, 38, 38, 44, 50, 56, 64, 82, 84, 86, 88}, {-92, -68, -64, -62, -54, -52, -52, -34, -24, -22, -20, -12, -12, -10, 6, 10, 14, 22, 22, 24, 24, 30, 30, 36, 36, 48, 50, 56, 58, 64, 68, 80, 84, 88, 88, 92, 94}, 19, 26, 28, -22); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1}, {1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0}, 24, 17, 23, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({53, 96, 99}, {30, 55, 56}, 1, 1, 1, 30); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 86, 36, -68, 86, 22, 52, -20, -2, 74, -72, 86, 80, -78, 14, 62, 10, 94, -66, 78, 28, 92, -8, 46, -24, 66}, {72, -72, -90, 24, -22, 60, 78, -68, 98, 26, -30, -20, 44, -96, 8, 90, 0, 98, -24, -68, -32, -62, 0, -60, 26, -98}, 22, 19, 24, 86); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {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}, 42, 40, 42, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 21, 86, 58, 48, 27, 18, 73, 16, 79, 51, 33, 63, 26, 37, 88, 48, 58, 44, 32, 58, 23, 31}, {87, 77, 44, 15, 70, 89, 36, 79, 82, 3, 18, 76, 37, 79, 85, 97, 19, 53, 17, 74, 87, 58, 49}, 14, 22, 19, 70); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "kThElementTwoSortedArrays", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 31, \"inputs\": {\"arr1\": [2, 2, 4, 4, 9, 10, 14, 16, 16, 19, 20, 21, 25, 26, 29, 36, 36, 37, 38, 44, 44, 49, 53, 54, 56, 61, 62, 64, 72, 72, 73, 77, 80, 84, 84, 87, 93, 94], \"arr2\": [6, 8, 10, 10, 12, 14, 24, 31, 33, 33, 35, 35, 35, 41, 46, 47, 49, 51, 52, 56, 57, 59, 62, 65, 72, 72, 73, 73, 79, 80, 82, 83, 83, 84, 87, 87, 93, 99], \"m\": 27, \"n\": 21, \"k\": 23}}, {\"idx\": 1, \"outputs\": 20, \"inputs\": {\"arr1\": [2, 4, -90, 62, 22, -94, -74, -22, 44, -94, 20, -40, 20, 0, 32, 24, 78, 8, 4, 98, -74, -60], \"arr2\": [58, 74, -46, 38, -58, -78, -32, -84, 84, -54, 84, -34, -26, 88, 74, 48, 26, -92, 68, -86, 74, 88], \"m\": 18, \"n\": 11, \"k\": 12}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"m\": 30, \"n\": 31, \"k\": 42}}, {\"idx\": 3, \"outputs\": 71, \"inputs\": {\"arr1\": [85, 44, 62, 2, 71, 88, 60, 78, 32, 46, 17, 47, 65, 78, 65, 94], \"arr2\": [18, 3, 15, 9, 61, 73, 3, 62, 87, 1, 54, 97, 61, 37, 23, 65], \"m\": 11, \"n\": 11, \"k\": 13}}, {\"idx\": 4, \"outputs\": -22, \"inputs\": {\"arr1\": [-94, -84, -82, -70, -70, -60, -54, -54, -52, -52, -46, -40, -40, -36, -34, -32, -30, -22, -18, -16, -10, -4, 8, 12, 18, 22, 32, 38, 38, 44, 50, 56, 64, 82, 84, 86, 88], \"arr2\": [-92, -68, -64, -62, -54, -52, -52, -34, -24, -22, -20, -12, -12, -10, 6, 10, 14, 22, 22, 24, 24, 30, 30, 36, 36, 48, 50, 56, 58, 64, 68, 80, 84, 88, 88, 92, 94], \"m\": 19, \"n\": 26, \"k\": 28}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr1\": [0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1], \"arr2\": [1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0], \"m\": 24, \"n\": 17, \"k\": 23}}, {\"idx\": 6, \"outputs\": 30, \"inputs\": {\"arr1\": [53, 96, 99], \"arr2\": [30, 55, 56], \"m\": 1, \"n\": 1, \"k\": 1}}, {\"idx\": 7, \"outputs\": 86, \"inputs\": {\"arr1\": [98, 86, 36, -68, 86, 22, 52, -20, -2, 74, -72, 86, 80, -78, 14, 62, 10, 94, -66, 78, 28, 92, -8, 46, -24, 66], \"arr2\": [72, -72, -90, 24, -22, 60, 78, -68, 98, 26, -30, -20, 44, -96, 8, 90, 0, 98, -24, -68, -32, -62, 0, -60, 26, -98], \"m\": 22, \"n\": 19, \"k\": 24}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr1\": [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], \"arr2\": [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], \"m\": 42, \"n\": 40, \"k\": 42}}, {\"idx\": 9, \"outputs\": 70, \"inputs\": {\"arr1\": [6, 21, 86, 58, 48, 27, 18, 73, 16, 79, 51, 33, 63, 26, 37, 88, 48, 58, 44, 32, 58, 23, 31], \"arr2\": [87, 77, 44, 15, 70, 89, 36, 79, 82, 3, 18, 76, 37, 79, 85, 97, 19, 53, 17, 74, 87, 58, 49], \"m\": 14, \"n\": 22, \"k\": 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 ] }
260
K Th Largest Sum Contiguous Subarray
C++
int kThLargestSumContiguousSubarray(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def k_th_largest_sum_contiguous_subarray(arr, n, k): sum = [] sum.append(0) sum.append(arr[0]) for i in range(2, (n + 1)): sum.append((sum[(i - 1)] + arr[(i - 1)])) Q = [] heapq.heapify(Q) for i in range(1, (n + 1)): for j in range(i, (n + 1)): x = (sum[j] - sum[(i - 1)]) if (len(Q) < k): heapq.heappush(Q, x) elif (Q[0] < x): heapq.heappop(Q) heapq.heappush(Q, x) return Q[0]
int k_th_largest_sum_contiguous_subarray(vector<int> arr, int n, int k) { int sum [ n + 1 ]; sum [ 0 ] = 0; sum [ 1 ] = arr [ 0 ]; for ( int i = 2; i <= n; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ]; priority_queue < int, vector < int >, greater < int > > Q; for ( int i = 1; i <= n; i ++ ) { for ( int j = i; j <= n; j ++ ) { int x = sum [ j ] - sum [ i - 1 ]; if ( Q . size ( ) < k ) Q . push ( x ); else { if ( Q . top ( ) < x ) { Q . pop ( ); Q . push ( x ); } } } } return Q . top ( ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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, 3, 5, 7, 8, 29, 29, 44, 47, 52, 60, 65, 73, 83, 87, 92, 92, 95}, 10, 12, 157); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({44, -98, -10, 14, -6, -46, 6, -74, -4, 36, 10, -2, 30, 28, 96, -84, -36, -76, 64, -74, -20, 94, -4, 14, 78, 52, -56, 98, -68, -76, -10, 20, 88, -98, 96, 80, 96, -32, -40, -30, 82}, 34, 37, 166); \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}, 16, 15, 5); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58, 21, 97, 78, 78, 57, 29, 33, 57, 81, 66, 32, 11, 82, 28, 72, 46, 67, 42, 15, 60, 45, 16, 37}, 14, 20, 508); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -90, -88, -84, -68, -66, -62, -58, -52, -44, -22, -16, -4, -4, 2, 12, 14, 14, 24, 26, 44, 56, 80, 90, 92, 94, 98}, 15, 25, -86); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}, 5, 5, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 8, 12, 13, 14, 17, 19, 23, 24, 28, 29, 30, 35, 35, 38, 44, 47, 47, 53, 55, 56, 56, 58, 66, 67, 70, 71, 72, 73, 74, 75, 77, 78, 82, 84, 87, 87, 87, 88, 88, 93, 94, 96}, 26, 25, 721); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, -58, 94, -70, 18, 16, -46, 38, -44, -92, -20, -70, -30, 50}, 11, 7, 36); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 19, 23, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({90, 77, 82, 38, 96, 62, 66, 4, 93, 30, 75, 22, 26, 61, 40, 11, 38, 55, 88, 24, 66, 47, 40, 71, 21, 5, 18, 31, 26, 56, 19, 47, 71, 34}, 28, 32, 1041); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "kThLargestSumContiguousSubarray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 157, \"inputs\": {\"arr\": [2, 3, 5, 7, 8, 29, 29, 44, 47, 52, 60, 65, 73, 83, 87, 92, 92, 95], \"n\": 10, \"k\": 12}}, {\"idx\": 1, \"outputs\": 166, \"inputs\": {\"arr\": [44, -98, -10, 14, -6, -46, 6, -74, -4, 36, 10, -2, 30, 28, 96, -84, -36, -76, 64, -74, -20, 94, -4, 14, 78, 52, -56, 98, -68, -76, -10, 20, 88, -98, 96, 80, 96, -32, -40, -30, 82], \"n\": 34, \"k\": 37}}, {\"idx\": 2, \"outputs\": 5, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 16, \"k\": 15}}, {\"idx\": 3, \"outputs\": 508, \"inputs\": {\"arr\": [58, 21, 97, 78, 78, 57, 29, 33, 57, 81, 66, 32, 11, 82, 28, 72, 46, 67, 42, 15, 60, 45, 16, 37], \"n\": 14, \"k\": 20}}, {\"idx\": 4, \"outputs\": -86, \"inputs\": {\"arr\": [-92, -90, -88, -84, -68, -66, -62, -58, -52, -44, -22, -16, -4, -4, 2, 12, 14, 14, 24, 26, 44, 56, 80, 90, 92, 94, 98], \"n\": 15, \"k\": 25}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], \"n\": 5, \"k\": 5}}, {\"idx\": 6, \"outputs\": 721, \"inputs\": {\"arr\": [3, 4, 8, 12, 13, 14, 17, 19, 23, 24, 28, 29, 30, 35, 35, 38, 44, 47, 47, 53, 55, 56, 56, 58, 66, 67, 70, 71, 72, 73, 74, 75, 77, 78, 82, 84, 87, 87, 87, 88, 88, 93, 94, 96], \"n\": 26, \"k\": 25}}, {\"idx\": 7, \"outputs\": 36, \"inputs\": {\"arr\": [20, -58, 94, -70, 18, 16, -46, 38, -44, -92, -20, -70, -30, 50], \"n\": 11, \"k\": 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 19, \"k\": 23}}, {\"idx\": 9, \"outputs\": 1041, \"inputs\": {\"arr\": [90, 77, 82, 38, 96, 62, 66, 4, 93, 30, 75, 22, 26, 61, 40, 11, 38, 55, 88, 24, 66, 47, 40, 71, 21, 5, 18, 31, 26, 56, 19, 47, 71, 34], \"n\": 28, \"k\": 32}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
261
K Th Prime Factor Given Number
C++
float kThPrimeFactorGivenNumber(int n, int k) {
[ "n", "k" ]
def k_th_prime_factor_given_number(n, k): while ((n % 2) == 0): k = (k - 1) n = (n / 2) if (k == 0): return 2 i = 3 while (i <= math.sqrt(n)): while ((n % i) == 0): if (k == 1): return i k = (k - 1) n = (n / i) i = (i + 2) if ((n > 2) and (k == 1)): return n return (- 1)
int k_th_prime_factor_given_number(int n, int k) { while ( n % 2 == 0 ) { k --; n = n / 2; if ( k == 0 ) return 2; } for ( int i = 3; i <= sqrt ( n ); i = i + 2 ) { while ( n % i == 0 ) { if ( k == 1 ) return i; k --; n = n / i; } } if ( n > 2 && k == 1 ) return n; return - 1; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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(94, 0, -1.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 1, 3.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 3, 2.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 3, 3.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 4, 3.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 6, -1.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 98, -1.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 39, -1.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 60, -1.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 57, -1.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "kThPrimeFactorGivenNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"n\": 94, \"k\": 0}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"n\": 99, \"k\": 1}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"n\": 64, \"k\": 3}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"n\": 27, \"k\": 3}}, {\"idx\": 4, \"outputs\": 3.0, \"inputs\": {\"n\": 24, \"k\": 4}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"n\": 84, \"k\": 6}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"n\": 69, \"k\": 98}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"n\": 69, \"k\": 39}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"n\": 22, \"k\": 60}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"n\": 39, \"k\": 57}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
263
Largest Subarray With Equal Number Of 0S And 1S 1
C++
int largestSubarrayWithEqualNumberOf0SAnd1S1(vector<int> arr, int n) {
[ "arr", "n" ]
def largest_subarray_with_equal_number_of_0s_and_1s_1(arr, n): hash_map = { } curr_sum = 0 max_len = 0 ending_index = (- 1) for i in range(0, n): if (arr[i] == 0): arr[i] = (- 1) else: arr[i] = 1 for i in range(0, n): curr_sum = (curr_sum + arr[i]) if (curr_sum == 0): max_len = (i + 1) ending_index = i if ((curr_sum + n) in hash_map): max_len = max(max_len, (i - hash_map[(curr_sum + n)])) else: hash_map[curr_sum] = i for i in range(0, n): if (arr[i] == (- 1)): arr[i] = 0 else: arr[i] = 1 print(((ending_index - max_len) + 1), end=' ') print('to', end=' ') print(ending_index) return max_len
int largest_subarray_with_equal_number_of_0s_and_1s_1(vector<int> arr, int n) { unordered_map < int, int > hM; int sum = 0; int max_len = 0; int ending_index = - 1; for ( int i = 0; i < n; i ++ ) arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1; for ( int i = 0; i < n; i ++ ) { sum += arr [ i ]; if ( sum == 0 ) { max_len = i + 1; ending_index = i; } if ( hM . find ( sum + n ) != hM . end ( ) ) { if ( max_len < i - hM [ sum + n ] ) { max_len = i - hM [ sum + n ]; ending_index = i; } } else hM [ sum + n ] = i; } for ( int i = 0; i < n; i ++ ) arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1; return max_len; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 42, 60, 66, 69, 70, 70, 73, 74, 80, 99}, 9, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, -66}, 1, 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, 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({1, 1, 1, 1, 1, 1, 1, 1, 26, 44, 32}, 8, 0); \n cout << \"TEST-\" << 3 << \"...\"\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 72, 74, 86, 92, 94}, 34, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1, 1, 0, 0, 0}, 4, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 64, 86}, 1, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -68, 12, -44, 62, 60, -34, -52, 18}, 17, 0); \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}, 9, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1, 1, 1, 1, 53}, 8, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "largestSubarrayWithEqualNumberOf0SAnd1S1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 42, 60, 66, 69, 70, 70, 73, 74, 80, 99], \"n\": 9}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [1, -66], \"n\": 1}}, {\"idx\": 2, \"outputs\": 0, \"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], \"n\": 19}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 1, 1, 26, 44, 32], \"n\": 8}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 72, 74, 86, 92, 94], \"n\": 34}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 0, 0, 0], \"n\": 4}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [1, 64, 86], \"n\": 1}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, -68, 12, -44, 62, 60, -34, -52, 18], \"n\": 17}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 9}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 1, 1, 53], \"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 ] }
264
Largest Subsequence Gcd Greater 1
C++
int largestSubsequenceGcdGreater1(vector<int> arr, int n) {
[ "arr", "n" ]
def largest_subsequence_gcd_greater_1(arr, n): ans = 0 maxele = max(arr) for i in range(2, (maxele + 1)): count = 0 for j in range(n): if ((arr[j] % i) == 0): count += 1 ans = max(ans, count) return ans
int largest_subsequence_gcd_greater_1(vector<int> arr, int n) { int ans = 0; int maxele = * max_element(arr.begin(), arr.end()); for ( int i = 2; i <= maxele; ++ i ) { int count = 0; for ( int j = 0; j < n; ++ j ) { if ( arr [ j ] % i == 0 ) ++ count; } ans = max ( ans, count ); } return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({10, 18, 22, 22, 22, 29, 30, 32, 33, 34, 37, 39, 40, 41, 44, 47, 49, 50, 50, 51, 53, 67, 69, 70, 71, 71, 73, 75, 78, 80, 81, 82, 91, 91, 93, 97, 97, 99}, 35, 16); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-42, 62, 6, 98, 38, -4, -38, 72, 42, 4, -22, -94, 78, -90, 14}, 10, 10); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 23, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({89, 92, 96, 71, 24, 27, 18, 19, 41, 1, 45, 8}, 7, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -94, -92, -90, -82, -80, -76, -76, -72, -62, -60, -58, -56, -52, -42, -36, -32, -32, -24, -22, -20, -10, -10, -10, -8, -2, -2, 0, 2, 4, 6, 6, 8, 10, 14, 18, 22, 26, 30, 46, 46, 62, 68, 74, 78, 82, 86, 86}, 40, 40); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1}, 41, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 8, 10, 10, 11, 17, 18, 25, 32, 33, 34, 37, 40, 41, 44, 47, 47, 52, 63, 77, 85, 87, 89, 89, 91, 95, 96, 98}, 23, 10); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, 52, -48, 70, 10, -94, 16, 14, 38, 62}, 9, 9); \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}, 30, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({95, 32, 87, 37, 86, 71, 30, 88, 96, 52, 88, 92, 79, 86, 19, 5, 74, 67}, 13, 8); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "largestSubsequenceGcdGreater1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 16, \"inputs\": {\"arr\": [10, 18, 22, 22, 22, 29, 30, 32, 33, 34, 37, 39, 40, 41, 44, 47, 49, 50, 50, 51, 53, 67, 69, 70, 71, 71, 73, 75, 78, 80, 81, 82, 91, 91, 93, 97, 97, 99], \"n\": 35}}, {\"idx\": 1, \"outputs\": 10, \"inputs\": {\"arr\": [-42, 62, 6, 98, 38, -4, -38, 72, 42, 4, -22, -94, 78, -90, 14], \"n\": 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 23}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"arr\": [89, 92, 96, 71, 24, 27, 18, 19, 41, 1, 45, 8], \"n\": 7}}, {\"idx\": 4, \"outputs\": 40, \"inputs\": {\"arr\": [-98, -94, -92, -90, -82, -80, -76, -76, -72, -62, -60, -58, -56, -52, -42, -36, -32, -32, -24, -22, -20, -10, -10, -10, -8, -2, -2, 0, 2, 4, 6, 6, 8, 10, 14, 18, 22, 26, 30, 46, 46, 62, 68, 74, 78, 82, 86, 86], \"n\": 40}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1], \"n\": 41}}, {\"idx\": 6, \"outputs\": 10, \"inputs\": {\"arr\": [4, 8, 10, 10, 11, 17, 18, 25, 32, 33, 34, 37, 40, 41, 44, 47, 47, 52, 63, 77, 85, 87, 89, 89, 91, 95, 96, 98], \"n\": 23}}, {\"idx\": 7, \"outputs\": 9, \"inputs\": {\"arr\": [-86, 52, -48, 70, 10, -94, 16, 14, 38, 62], \"n\": 9}}, {\"idx\": 8, \"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, 1, 1], \"n\": 30}}, {\"idx\": 9, \"outputs\": 8, \"inputs\": {\"arr\": [95, 32, 87, 37, 86, 71, 30, 88, 96, 52, 88, 92, 79, 86, 19, 5, 74, 67], \"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 ] }
265
Largest Sum Contiguous Subarray 2
C++
int largestSumContiguousSubarray2(vector<int> a, int size) {
[ "a", "size" ]
def largest_sum_contiguous_subarray_2(a, size): max_so_far = a[0] curr_max = a[0] for i in range(1, size): curr_max = max(a[i], (curr_max + a[i])) max_so_far = max(max_so_far, curr_max) return max_so_far
int largest_sum_contiguous_subarray_2(vector<int> a, int size) { int max_so_far = a [ 0 ]; int curr_max = a [ 0 ]; for ( int i = 1; i < size; i ++ ) { curr_max = max ( a [ i ], curr_max + a [ i ] ); max_so_far = max ( max_so_far, curr_max ); } return max_so_far; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int size, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, size), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 3, 4, 7, 8, 8, 10, 12, 16, 19, 19, 20, 20, 21, 21, 22, 26, 27, 29, 34, 36, 38, 38, 39, 41, 43, 44, 47, 47, 49, 57, 57, 60, 62, 63, 65, 75, 77, 77, 78, 81, 82, 82, 83, 83, 84, 85, 98, 99}, 38, 1265); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-40, 14, 2, -70, 86, -90, -50, -54, -2, 90, 30}, 10, 90); \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}, 18, 11); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({60, 69, 41, 7, 77, 36, 36, 26, 35, 30, 64, 75, 3, 35, 60, 71, 29, 47, 15, 29, 43, 88, 56, 22, 9, 45, 40, 50, 52}, 25, 1063); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -88, -80, -72, -64, -64, -60, -60, -60, -58, -56, -54, -54, -50, -50, -26, -26, -24, -20, -8, -2, 0, 4, 4, 12, 14, 18, 18, 24, 32, 42, 44, 44, 44, 48, 50, 50, 56, 60, 60, 70, 80, 88, 88, 90, 98}, 35, 348); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0}, 22, 13); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, 4, 5, 6, 7, 11, 12, 14, 18, 23, 24, 27, 28, 33, 36, 37, 38, 39, 40, 41, 41, 48, 48, 52, 61, 64, 66, 66, 77, 79, 82, 85, 88, 91, 94, 99}, 34, 1306); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, 0, 16, 12, 20, 36, 32, -52, -68, -36, -96, -46, -34, 56, 2, 78, 6, 30, -68, -48, 2, 44, -26, -36, -30, -20, -90, -66, 4, 94, 8, 4, -4, -32, -24}, 20, 172); \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}, 22, 10); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({39, 87, 27, 89, 26, 25, 80, 82, 21, 25, 55, 27, 20, 81, 47, 79, 26, 72, 10, 11, 90, 89}, 21, 1019); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "largestSumContiguousSubarray2", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1265, \"inputs\": {\"a\": [1, 3, 4, 7, 8, 8, 10, 12, 16, 19, 19, 20, 20, 21, 21, 22, 26, 27, 29, 34, 36, 38, 38, 39, 41, 43, 44, 47, 47, 49, 57, 57, 60, 62, 63, 65, 75, 77, 77, 78, 81, 82, 82, 83, 83, 84, 85, 98, 99], \"size\": 38}}, {\"idx\": 1, \"outputs\": 90, \"inputs\": {\"a\": [-40, 14, 2, -70, 86, -90, -50, -54, -2, 90, 30], \"size\": 10}}, {\"idx\": 2, \"outputs\": 11, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"size\": 18}}, {\"idx\": 3, \"outputs\": 1063, \"inputs\": {\"a\": [60, 69, 41, 7, 77, 36, 36, 26, 35, 30, 64, 75, 3, 35, 60, 71, 29, 47, 15, 29, 43, 88, 56, 22, 9, 45, 40, 50, 52], \"size\": 25}}, {\"idx\": 4, \"outputs\": 348, \"inputs\": {\"a\": [-96, -88, -80, -72, -64, -64, -60, -60, -60, -58, -56, -54, -54, -50, -50, -26, -26, -24, -20, -8, -2, 0, 4, 4, 12, 14, 18, 18, 24, 32, 42, 44, 44, 44, 48, 50, 50, 56, 60, 60, 70, 80, 88, 88, 90, 98], \"size\": 35}}, {\"idx\": 5, \"outputs\": 13, \"inputs\": {\"a\": [0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0], \"size\": 22}}, {\"idx\": 6, \"outputs\": 1306, \"inputs\": {\"a\": [2, 4, 4, 5, 6, 7, 11, 12, 14, 18, 23, 24, 27, 28, 33, 36, 37, 38, 39, 40, 41, 41, 48, 48, 52, 61, 64, 66, 66, 77, 79, 82, 85, 88, 91, 94, 99], \"size\": 34}}, {\"idx\": 7, \"outputs\": 172, \"inputs\": {\"a\": [-56, 0, 16, 12, 20, 36, 32, -52, -68, -36, -96, -46, -34, 56, 2, 78, 6, 30, -68, -48, 2, 44, -26, -36, -30, -20, -90, -66, 4, 94, 8, 4, -4, -32, -24], \"size\": 20}}, {\"idx\": 8, \"outputs\": 10, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"size\": 22}}, {\"idx\": 9, \"outputs\": 1019, \"inputs\": {\"a\": [39, 87, 27, 89, 26, 25, 80, 82, 21, 25, 55, 27, 20, 81, 47, 79, 26, 72, 10, 11, 90, 89], \"size\": 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 ] }
266
Lcs Formed Consecutive Segments Least Length K
C++
int lcsFormedConsecutiveSegmentsLeastLengthK(int k, string s1, string s2) {
[ "k", "s1", "s2" ]
def lcs_formed_consecutive_segments_least_length_k(k, s1, s2): n = len(s1) m = len(s2) lcs = [[0 for x in range((m + 1))] for y in range((n + 1))] cnt = [[0 for x in range((m + 1))] for y in range((n + 1))] for i in range(1, (n + 1)): for j in range(1, (m + 1)): lcs[i][j] = max(lcs[(i - 1)][j], lcs[i][(j - 1)]) if (s1[(i - 1)] == s2[(j - 1)]): cnt[i][j] = (cnt[(i - 1)][(j - 1)] + 1) if (cnt[i][j] >= k): for a in range(k, (cnt[i][j] + 1)): lcs[i][j] = max(lcs[i][j], (lcs[(i - a)][(j - a)] + a)) return lcs[n][m]
int lcs_formed_consecutive_segments_least_length_k(int k, string s1, string s2) { int n = s1 . length ( ); int m = s2 . length ( ); int lcs [ n + 1 ] [ m + 1 ]; int cnt [ n + 1 ] [ m + 1 ]; memset ( lcs, 0, sizeof ( lcs ) ); memset ( cnt, 0, sizeof ( cnt ) ); for ( int i = 1; i <= n; i ++ ) { for ( int j = 1; j <= m; j ++ ) { lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ], lcs [ i ] [ j - 1 ] ); if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1; if ( cnt [ i ] [ j ] >= k ) { for ( int a = k; a <= cnt [ i ] [ j ]; a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ], lcs [ i - a ] [ j - a ] + a ); } } } return lcs [ n ] [ m ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int k, string s1, string s2, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(k, s1, s2), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(4, \"aggayxysdfa\", \"aggajxaaasdfa\", 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, \"55571659965107\", \"390286654154\", 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, \"01011011100\", \"0000110001000\", 7); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, \"aggasdfa\", \"aggajasdfaxy\", 5); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, \"5710246551\", \"79032504084062\", 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, \"0100010\", \"10100000\", 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, \"aabcaaaa\", \"baaabcd\", 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, \"1219\", \"3337119582\", 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, \"111000011\", \"011\", 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, \"wiC oD\", \"csiuGOUwE\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lcsFormedConsecutiveSegmentsLeastLengthK", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"k\": 4, \"s1\": \"aggayxysdfa\", \"s2\": \"aggajxaaasdfa\"}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"k\": 2, \"s1\": \"55571659965107\", \"s2\": \"390286654154\"}}, {\"idx\": 2, \"outputs\": 7, \"inputs\": {\"k\": 3, \"s1\": \"01011011100\", \"s2\": \"0000110001000\"}}, {\"idx\": 3, \"outputs\": 5, \"inputs\": {\"k\": 5, \"s1\": \"aggasdfa\", \"s2\": \"aggajasdfaxy\"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"k\": 2, \"s1\": \"5710246551\", \"s2\": \"79032504084062\"}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"k\": 3, \"s1\": \"0100010\", \"s2\": \"10100000\"}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"k\": 3, \"s1\": \"aabcaaaa\", \"s2\": \"baaabcd\"}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"k\": 1, \"s1\": \"1219\", \"s2\": \"3337119582\"}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"k\": 2, \"s1\": \"111000011\", \"s2\": \"011\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"k\": 2, \"s1\": \"wiC oD\", \"s2\": \"csiuGOUwE\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
267
Length Longest Strict Bitonic Subsequence
C++
int lengthLongestStrictBitonicSubsequence(vector<int> arr, int n) {
[ "arr", "n" ]
def length_longest_strict_bitonic_subsequence(arr, n): (inc, dcr) = (dict(), dict()) (len_inc, len_dcr) = (([0] * n), ([0] * n)) longLen = 0 for i in range(n): len = 0 if (inc.get((arr[i] - 1)) in inc.values()): len = inc.get((arr[i] - 1)) inc[arr[i]] = len_inc[i] = (len + 1) for i in range((n - 1), (- 1), (- 1)): len = 0 if (dcr.get((arr[i] - 1)) in dcr.values()): len = dcr.get((arr[i] - 1)) dcr[arr[i]] = len_dcr[i] = (len + 1) for i in range(n): if (longLen < ((len_inc[i] + len_dcr[i]) - 1)): longLen = ((len_inc[i] + len_dcr[i]) - 1) return longLen
int length_longest_strict_bitonic_subsequence(vector<int> arr, int n) { unordered_map < int, int > inc, dcr; int len_inc [ n ], len_dcr [ n ]; int longLen = 0; for ( int i = 0; i < n; i ++ ) { int len = 0; if ( inc . find ( arr [ i ] - 1 ) != inc . end ( ) ) len = inc [ arr [ i ] - 1 ]; inc [ arr [ i ] ] = len_inc [ i ] = len + 1; } for ( int i = n - 1; i >= 0; i -- ) { int len = 0; if ( dcr . find ( arr [ i ] - 1 ) != dcr . end ( ) ) len = dcr [ arr [ i ] - 1 ]; dcr [ arr [ i ] ] = len_dcr [ i ] = len + 1; } for ( int i = 0; i < n; i ++ ) if ( longLen < ( len_inc [ i ] + len_dcr [ i ] - 1 ) ) longLen = len_inc [ i ] + len_dcr [ i ] - 1; return longLen; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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({78}, 0, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-6, -18, -48, 58, -54, 76, 80, -56, 86, 58, -86, -86, -88, 32, 12, 58, 58, -16, 86, -24, 84, 86, 36, 18, 30, -32, -4, -36, -72, -4, 42, 94}, 18, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({92, 26, 72, 8, 66, 28, 34, 61, 28}, 5, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -82, -76, -68, -66, -64, -62, -56, -48, -42, -38, -30, -22, -18, -10, -10, -4, -2, 4, 28, 42, 44, 50, 50, 56, 58, 60, 76, 82, 86, 86, 98}, 25, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0}, 17, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 8, 9, 12, 13, 16, 19, 23, 25, 29, 31, 34, 36, 38, 41, 42, 47, 49, 50, 51, 51, 58, 63, 66, 70, 73, 74, 75, 75, 75, 76, 76, 80, 82, 83, 83, 84, 86, 89, 90, 91, 91, 95, 96}, 44, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, -76, 60, 48, -14, 72}, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, 80, 79, 72, 1, 67, 20, 67, 32, 40, 22, 64, 58, 67, 10, 21, 37, 49}, 15, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lengthLongestStrictBitonicSubsequence", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [78], \"n\": 0}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [-6, -18, -48, 58, -54, 76, 80, -56, 86, 58, -86, -86, -88, 32, 12, 58, 58, -16, 86, -24, 84, 86, 36, 18, 30, -32, -4, -36, -72, -4, 42, 94], \"n\": 18}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1], \"n\": 1}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [92, 26, 72, 8, 66, 28, 34, 61, 28], \"n\": 5}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-86, -82, -76, -68, -66, -64, -62, -56, -48, -42, -38, -30, -22, -18, -10, -10, -4, -2, 4, 28, 42, 44, 50, 50, 56, 58, 60, 76, 82, 86, 86, 98], \"n\": 25}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0], \"n\": 17}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"arr\": [3, 4, 8, 9, 12, 13, 16, 19, 23, 25, 29, 31, 34, 36, 38, 41, 42, 47, 49, 50, 51, 51, 58, 63, 66, 70, 73, 74, 75, 75, 75, 76, 76, 80, 82, 83, 83, 84, 86, 89, 90, 91, 91, 95, 96], \"n\": 44}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [4, -76, 60, 48, -14, 72], \"n\": 3}}, {\"idx\": 8, \"outputs\": 2, \"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], \"n\": 17}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr\": [66, 80, 79, 72, 1, 67, 20, 67, 32, 40, 22, 64, 58, 67, 10, 21, 37, 49], \"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 ] }
268
Length Longest Sub String Can Make Removed
C++
int lengthLongestSubStringCanMakeRemoved(string s) {
[ "s" ]
def length_longest_sub_string_can_make_removed(S): arr = [] arr.append(['@', (- 1)]) maxlen = 0 for i in range(len(S)): arr.append([S[i], i]) while ((len(arr) >= 3) and (arr[(len(arr) - 3)][0] == '1') and (arr[(len(arr) - 2)][0] == '0') and (arr[(len(arr) - 1)][0] == '0')): arr.pop() arr.pop() arr.pop() tmp = arr[(- 1)] maxlen = max(maxlen, (i - tmp[1])) return maxlen
int length_longest_sub_string_can_make_removed(string str) { vector < pair < char, int > > arr; arr . push_back ( { '@', - 1 } ); int maxlen = 0; for ( int i = 0; i < str . length ( ); ++ i ) { arr . push_back ( { str [ i ], i } ); while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) { arr . pop_back ( ); arr . pop_back ( ); arr . pop_back ( ); } int tmp = arr . back ( ) . second; maxlen = max ( maxlen, i - tmp ); } return maxlen; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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(\"U\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"544\", 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111\", 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\" cDQaNxpRSOe\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"42920062459\", 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00100101\", 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"FiC\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"302746335230\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ZBLHiwGreUR \", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lengthLongestSubStringCanMakeRemoved", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"s\": \"U\"}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"s\": \"544\"}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"s\": \"111\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"s\": \" cDQaNxpRSOe\"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"s\": \"42920062459\"}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"s\": \"00100101\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"s\": \"FiC\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"s\": \"302746335230\"}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"s\": \"1\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"s\": \"ZBLHiwGreUR \"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
269
Length Of The Longest Arithmatic Progression In A Sorted Array
C++
int lengthOfTheLongestArithmaticProgressionInASortedArray(vector<int> set_arg0, int n) {
[ "set_arg0", "n" ]
def length_of_the_longest_arithmatic_progression_in_a_sorted_array(set, n): if (n <= 2): return n L = [[0 for x in range(n)] for y in range(n)] llap = 2 for i in range(n): L[i][(n - 1)] = 2 for j in range((n - 2), 0, (- 1)): i = (j - 1) k = (j + 1) while ((i >= 0) and (k <= (n - 1))): if ((set[i] + set[k]) < (2 * set[j])): k += 1 elif ((set[i] + set[k]) > (2 * set[j])): L[i][j] = 2 i -= 1 else: L[i][j] = (L[j][k] + 1) llap = max(llap, L[i][j]) i -= 1 k += 1 while (i >= 0): L[i][j] = 2 i -= 1 return llap
int length_of_the_longest_arithmatic_progression_in_a_sorted_array(vector<int> set, int n) { if ( n <= 2 ) return n; int L [ n ] [ n ]; int llap = 2; for ( int i = 0; i < n; i ++ ) L [ i ] [ n - 1 ] = 2; for ( int j = n - 2; j >= 1; j -- ) { int i = j - 1, k = j + 1; while ( i >= 0 && k <= n - 1 ) { if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++; else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) { L [ i ] [ j ] = 2, i --; } else { L [ i ] [ j ] = L [ j ] [ k ] + 1; llap = max ( llap, L [ i ] [ j ] ); i --; k ++; } } while ( i >= 0 ) { L [ i ] [ j ] = 2; i --; } } return llap; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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> set_arg0, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(set_arg0, 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, 4, 7, 8, 19, 21, 22, 25, 27, 28, 29, 38, 40, 41, 42, 43, 46, 50, 50, 53, 53, 54, 55, 60, 64, 64, 69, 70, 75, 77, 81, 81, 82, 86, 87, 87, 88, 91, 94, 97}, 27, 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({40, -6, 50, -18, 42, 78, 38, -90, -44, -42, -86, 78, -68, 2, -32, -20, -44, 54, 80, 54, 70, 26, 82, -14, -74, -20, 74, 82}, 21, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1}, 5, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, 80}, 1, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -90, -88, -76, -76, -60, -46, -40, -24, -8, -8, -6, 2, 12, 36, 38, 58, 76, 80}, 13, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1}, 15, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 8, 11, 27, 27, 32, 32, 37, 50, 51, 55, 61, 62, 68, 73, 83}, 8, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, -74, -32, -64, -52, -60, -70, 36, 70, 40, 40, -18, 90, -70, -82, -64, -8, -6, 36, 4, -58, 62, -96, 78, 36, 90, -70, -6, -84, 24, 84, 32, -90, 36, 70, -60, -56, 78, 48, 34, -16, 80, 82, 58, 14, -6, -8, 76}, 29, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 15); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 21, 76, 45, 8, 49, 97, 66, 17, 11, 87, 4, 34, 89, 79, 88, 6, 91, 19, 56, 91, 25, 17, 90, 26, 59, 34, 32, 43, 17, 98, 39, 72, 78, 93, 43}, 26, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lengthOfTheLongestArithmaticProgressionInASortedArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"set_arg0\": [3, 4, 4, 7, 8, 19, 21, 22, 25, 27, 28, 29, 38, 40, 41, 42, 43, 46, 50, 50, 53, 53, 54, 55, 60, 64, 64, 69, 70, 75, 77, 81, 81, 82, 86, 87, 87, 88, 91, 94, 97], \"n\": 27}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"set_arg0\": [40, -6, 50, -18, 42, 78, 38, -90, -44, -42, -86, 78, -68, 2, -32, -20, -44, 54, 80, 54, 70, 26, 82, -14, -74, -20, 74, 82], \"n\": 21}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"set_arg0\": [0, 0, 0, 0, 1, 1, 1], \"n\": 5}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"set_arg0\": [76, 80], \"n\": 1}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"set_arg0\": [-92, -90, -88, -76, -76, -60, -46, -40, -24, -8, -8, -6, 2, 12, 36, 38, 58, 76, 80], \"n\": 13}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"set_arg0\": [1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1], \"n\": 15}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"set_arg0\": [5, 8, 11, 27, 27, 32, 32, 37, 50, 51, 55, 61, 62, 68, 73, 83], \"n\": 8}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"set_arg0\": [52, -74, -32, -64, -52, -60, -70, 36, 70, 40, 40, -18, 90, -70, -82, -64, -8, -6, 36, 4, -58, 62, -96, 78, 36, 90, -70, -6, -84, 24, 84, 32, -90, 36, 70, -60, -56, 78, 48, 34, -16, 80, 82, 58, 14, -6, -8, 76], \"n\": 29}}, {\"idx\": 8, \"outputs\": 15, \"inputs\": {\"set_arg0\": [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\": 27}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"set_arg0\": [11, 21, 76, 45, 8, 49, 97, 66, 17, 11, 87, 4, 34, 89, 79, 88, 6, 91, 19, 56, 91, 25, 17, 90, 26, 59, 34, 32, 43, 17, 98, 39, 72, 78, 93, 43], \"n\": 26}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
270
Leonardo Number 1
C++
long long leonardoNumber1(int n) {
[ "n" ]
def leonardo_number_1(n): dp = [] dp.append(1) dp.append(1) for i in range(2, (n + 1)): dp.append(((dp[(i - 1)] + dp[(i - 2)]) + 1)) return dp[n]
int leonardo_number_1(int n) { int dp [ n + 1 ]; dp [ 0 ] = dp [ 1 ] = 1; for ( int i = 2; i <= n; i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1; return dp [ n ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(75, 6832909245813413); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 11055879401769513); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 451702867433); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 1219); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 1402817465); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 177); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 3193); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 2692537); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 2269806339); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 55555780070575); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "leonardoNumber1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 6832909245813413, \"inputs\": {\"n\": 75}}, {\"idx\": 1, \"outputs\": 11055879401769513, \"inputs\": {\"n\": 76}}, {\"idx\": 2, \"outputs\": 451702867433, \"inputs\": {\"n\": 55}}, {\"idx\": 3, \"outputs\": 1219, \"inputs\": {\"n\": 14}}, {\"idx\": 4, \"outputs\": 1402817465, \"inputs\": {\"n\": 43}}, {\"idx\": 5, \"outputs\": 177, \"inputs\": {\"n\": 10}}, {\"idx\": 6, \"outputs\": 3193, \"inputs\": {\"n\": 16}}, {\"idx\": 7, \"outputs\": 2692537, \"inputs\": {\"n\": 30}}, {\"idx\": 8, \"outputs\": 2269806339, \"inputs\": {\"n\": 44}}, {\"idx\": 9, \"outputs\": 55555780070575, \"inputs\": {\"n\": 65}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
271
Lexicographically Minimum String Rotation
C++
string lexicographicallyMinimumStringRotation(string str_) {
[ "str_" ]
def lexicographically_minimum_string_rotation(str_): n = len(str_) arr = ([0] * n) concat = (str_ + str_) for i in range(n): arr[i] = concat[i:(n + i)] arr.sort() return arr[0]
string lexicographically_minimum_string_rotation(string str) { int n = str . length ( ); string arr [ n ]; string concat = str + str; for ( int i = 0; i < n; i ++ ) arr [ i ] = concat . substr ( i, n ); sort ( arr, arr + n ); return arr [ 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(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string str_, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str_), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"onWEchl\", \"EchlonW\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2\", \"2\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100\", \"001\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"GHbCZA\", \"AGHbCZ\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"50568798206105\", \"05505687982061\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"001011110001\", \"000100101111\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"lljpYhznnyu\", \"Yhznnyulljp\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"54499921759984\", \"17599845449992\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11101\", \"01111\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"qvypgCYEjsyjwZ\", \"CYEjsyjwZqvypg\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lexicographicallyMinimumStringRotation", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"EchlonW\", \"inputs\": {\"str_\": \"onWEchl\"}}, {\"idx\": 1, \"outputs\": \"2\", \"inputs\": {\"str_\": \"2\"}}, {\"idx\": 2, \"outputs\": \"001\", \"inputs\": {\"str_\": \"100\"}}, {\"idx\": 3, \"outputs\": \"AGHbCZ\", \"inputs\": {\"str_\": \"GHbCZA\"}}, {\"idx\": 4, \"outputs\": \"05505687982061\", \"inputs\": {\"str_\": \"50568798206105\"}}, {\"idx\": 5, \"outputs\": \"000100101111\", \"inputs\": {\"str_\": \"001011110001\"}}, {\"idx\": 6, \"outputs\": \"Yhznnyulljp\", \"inputs\": {\"str_\": \"lljpYhznnyu\"}}, {\"idx\": 7, \"outputs\": \"17599845449992\", \"inputs\": {\"str_\": \"54499921759984\"}}, {\"idx\": 8, \"outputs\": \"01111\", \"inputs\": {\"str_\": \"11101\"}}, {\"idx\": 9, \"outputs\": \"CYEjsyjwZqvypg\", \"inputs\": {\"str_\": \"qvypgCYEjsyjwZ\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
272
Lexicographically Next String
C++
string lexicographicallyNextString(string s) {
[ "s" ]
def lexicographically_next_string(s): if (s == ' '): return 'a' i = (len(s) - 1) while ((s[i] == 'z') and (i >= 0)): i -= 1 if (i == (- 1)): s = (s + 'a') else: s = s.replace(s[i], chr((ord(s[i]) + 1)), 1) return s
string lexicographically_next_string(string s) { if ( s == "" ) return "a"; int i = s . length ( ) - 1; while ( s [ i ] == 'z' && i >= 0 ) i --; if ( i == - 1 ) s = s + 'a'; else s [ i ] ++; return s; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string s, string 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(\"amKIRzPiqLTIy\", \"amKIRzPiqLTIz\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"68\", \"69\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100\", \"110\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"f\", \"g\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"802205375\", \"802206375\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0111\", \"0211\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"GRjRYIvYwgua\", \"GRjRYIvYwgub\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"8139910006809\", \"813:910006809\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100101\", \"200101\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"rw\", \"rx\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lexicographicallyNextString", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"amKIRzPiqLTIz\", \"inputs\": {\"s\": \"amKIRzPiqLTIy\"}}, {\"idx\": 1, \"outputs\": \"69\", \"inputs\": {\"s\": \"68\"}}, {\"idx\": 2, \"outputs\": \"110\", \"inputs\": {\"s\": \"100\"}}, {\"idx\": 3, \"outputs\": \"g\", \"inputs\": {\"s\": \"f\"}}, {\"idx\": 4, \"outputs\": \"802206375\", \"inputs\": {\"s\": \"802205375\"}}, {\"idx\": 5, \"outputs\": \"0211\", \"inputs\": {\"s\": \"0111\"}}, {\"idx\": 6, \"outputs\": \"GRjRYIvYwgub\", \"inputs\": {\"s\": \"GRjRYIvYwgua\"}}, {\"idx\": 7, \"outputs\": \"813:910006809\", \"inputs\": {\"s\": \"8139910006809\"}}, {\"idx\": 8, \"outputs\": \"200101\", \"inputs\": {\"s\": \"100101\"}}, {\"idx\": 9, \"outputs\": \"rx\", \"inputs\": {\"s\": \"rw\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
273
Lexicographical Concatenation Substrings String
C++
string lexicographicalConcatenationSubstringsString(string s) {
[ "s" ]
def lexicographical_concatenation_substrings_string(s): n = len(s) sub_count = ((n * (n + 1)) // 2) arr = ([0] * sub_count) index = 0 for i in range(n): for j in range(1, ((n - i) + 1)): arr[index] = s[i:(i + j)] index += 1 arr.sort() res = '' for i in range(sub_count): res += arr[i] return res
string lexicographical_concatenation_substrings_string(string s) { int n = s . length ( ); int sub_count = n * ( n + 1 ) / 2; string arr [ sub_count ]; int index = 0; for ( int i = 0; i < n; i ++ ) for ( int len = 1; len <= n - i; len ++ ) arr [ index ++ ] = s . substr ( i, len ); sort ( arr, arr + sub_count ); string res = ""; for ( int i = 0; i < sub_count; i ++ ) res += arr [ i ]; return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string s, string 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(\"sqGOi\", \"GGOGOiOOiiqqGqGOqGOissqsqGsqGOsqGOi\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ZhWXUKmeiI\", \"IKKmKmeKmeiKmeiIUUKUKmUKmeUKmeiUKmeiIWWXWXUWXUKWXUKmWXUKmeWXUKmeiWXUKmeiIXXUXUKXUKmXUKmeXUKmeiXUKmeiIZZhZhWZhWXZhWXUZhWXUKZhWXUKmZhWXUKmeZhWXUKmeiZhWXUKmeiIeeieiIhhWhWXhWXUhWXUKhWXUKmhWXUKmehWXUKmeihWXUKmeiIiiImmemeimeiI\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"tjP kR\", \" k kRPP P kP kRRjjPjP jP kjP kRkkRttjtjPtjP tjP ktjP kR\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"qJPHNSJOUj\", \"HHNHNSHNSJHNSJOHNSJOUHNSJOUjJJJOJOUJOUjJPJPHJPHNJPHNSJPHNSJJPHNSJOJPHNSJOUJPHNSJOUjNNSNSJNSJONSJOUNSJOUjOOUOUjPPHPHNPHNSPHNSJPHNSJOPHNSJOUPHNSJOUjSSJSJOSJOUSJOUjUUjjqqJqJPqJPHqJPHNqJPHNSqJPHNSJqJPHNSJOqJPHNSJOUqJPHNSJOUj\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lexicographicalConcatenationSubstringsString", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"GGOGOiOOiiqqGqGOqGOissqsqGsqGOsqGOi\", \"inputs\": {\"s\": \"sqGOi\"}}, {\"idx\": 1, \"outputs\": \"IKKmKmeKmeiKmeiIUUKUKmUKmeUKmeiUKmeiIWWXWXUWXUKWXUKmWXUKmeWXUKmeiWXUKmeiIXXUXUKXUKmXUKmeXUKmeiXUKmeiIZZhZhWZhWXZhWXUZhWXUKZhWXUKmZhWXUKmeZhWXUKmeiZhWXUKmeiIeeieiIhhWhWXhWXUhWXUKhWXUKmhWXUKmehWXUKmeihWXUKmeiIiiImmemeimeiI\", \"inputs\": {\"s\": \"ZhWXUKmeiI\"}}, {\"idx\": 2, \"outputs\": \" k kRPP P kP kRRjjPjP jP kjP kRkkRttjtjPtjP tjP ktjP kR\", \"inputs\": {\"s\": \"tjP kR\"}}, {\"idx\": 3, \"outputs\": \"HHNHNSHNSJHNSJOHNSJOUHNSJOUjJJJOJOUJOUjJPJPHJPHNJPHNSJPHNSJJPHNSJOJPHNSJOUJPHNSJOUjNNSNSJNSJONSJOUNSJOUjOOUOUjPPHPHNPHNSPHNSJPHNSJOPHNSJOUPHNSJOUjSSJSJOSJOUSJOUjUUjjqqJqJPqJPHqJPHNqJPHNSqJPHNSJqJPHNSJOqJPHNSJOUqJPHNSJOUj\", \"inputs\": {\"s\": \"qJPHNSJOUj\"}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
275
Longest Common Increasing Subsequence Lcs Lis
C++
int longestCommonIncreasingSubsequenceLcsLis(vector<int> arr1, int n, vector<int> arr2, int m) {
[ "arr1", "n", "arr2", "m" ]
def longest_common_increasing_subsequence_lcs_lis(arr1, n, arr2, m): table = ([0] * m) for j in range(m): table[j] = 0 for i in range(n): current = 0 for j in range(m): if (arr1[i] == arr2[j]): if ((current + 1) > table[j]): table[j] = (current + 1) if (arr1[i] > arr2[j]): if (table[j] > current): current = table[j] result = 0 for i in range(m): if (table[i] > result): result = table[i] return result
int longest_common_increasing_subsequence_lcs_lis(vector<int> arr1, int n, vector<int> arr2, int m) { int table [ m ]; for ( int j = 0; j < m; j ++ ) table [ j ] = 0; for ( int i = 0; i < n; i ++ ) { int current = 0; for ( int j = 0; j < m; j ++ ) { if ( arr1 [ i ] == arr2 [ j ] ) if ( current + 1 > table [ j ] ) table [ j ] = current + 1; if ( arr1 [ i ] > arr2 [ j ] ) if ( table [ j ] > current ) current = table [ j ]; } } int result = 0; for ( int i = 0; i < m; i ++ ) if ( table [ i ] > result ) result = table [ 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> arr1, int n, vector<int> arr2, int m, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, n, arr2, 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({1, 7, 9, 35, 43, 51, 51, 66, 88}, 5, {10, 21, 38, 50, 65, 67, 87, 93, 99}, 8, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-52, 52, -92, -46, -94, 30, -36, 18, -98, 22, -36, 96, -88, -50, 50}, 7, {-58, 40, 56, -62, -92, -94, 40, 18, -2, -76, -78, -14, 44, 84, 4}, 10, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 36, {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}, 22, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 74, 29}, 1, {57, 33, 48}, 1, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, -74, -70, -62, -56, -56, -52, -2, 6, 24, 28, 44, 44, 52}, 8, {-98, -96, -88, -66, -32, -26, -24, -20, -4, 20, 48, 74, 90, 96}, 12, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0}, 17, {1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0}, 15, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 4, 7, 15, 15, 16, 22, 32, 32, 37, 39, 39, 41, 43, 46, 47, 47, 49, 75, 79, 80, 86, 88, 93}, 19, {9, 12, 15, 20, 22, 27, 28, 28, 30, 31, 35, 39, 47, 58, 58, 60, 73, 74, 76, 78, 80, 86, 95, 96, 98}, 14, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({70, -64, 0, 52, 32, -98, 38, -8, 34, 70, 98, 58, -48, -60, -28, -22, -72, 82, -98, -36}, 16, {-18, 88, -40, -52, 30, -10, -18, -56, 84, -22, -64, 80, -14, -64, 40, 92, 48, -8, 24, 82}, 12, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1, 1, 1}, 7, {0, 1, 1, 1, 1, 1, 1, 1}, 7, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 87, 98}, 2, {67, 31, 54}, 2, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestCommonIncreasingSubsequenceLcsLis", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr1\": [1, 7, 9, 35, 43, 51, 51, 66, 88], \"n\": 5, \"arr2\": [10, 21, 38, 50, 65, 67, 87, 93, 99], \"m\": 8}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr1\": [-52, 52, -92, -46, -94, 30, -36, 18, -98, 22, -36, 96, -88, -50, 50], \"n\": 7, \"arr2\": [-58, 40, 56, -62, -92, -94, 40, 18, -2, -76, -78, -14, 44, 84, 4], \"m\": 10}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"arr1\": [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\": 36, \"arr2\": [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], \"m\": 22}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr1\": [5, 74, 29], \"n\": 1, \"arr2\": [57, 33, 48], \"m\": 1}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr1\": [-84, -74, -70, -62, -56, -56, -52, -2, 6, 24, 28, 44, 44, 52], \"n\": 8, \"arr2\": [-98, -96, -88, -66, -32, -26, -24, -20, -4, 20, 48, 74, 90, 96], \"m\": 12}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr1\": [0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0], \"n\": 17, \"arr2\": [1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0], \"m\": 15}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"arr1\": [3, 4, 4, 7, 15, 15, 16, 22, 32, 32, 37, 39, 39, 41, 43, 46, 47, 47, 49, 75, 79, 80, 86, 88, 93], \"n\": 19, \"arr2\": [9, 12, 15, 20, 22, 27, 28, 28, 30, 31, 35, 39, 47, 58, 58, 60, 73, 74, 76, 78, 80, 86, 95, 96, 98], \"m\": 14}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr1\": [70, -64, 0, 52, 32, -98, 38, -8, 34, 70, 98, 58, -48, -60, -28, -22, -72, 82, -98, -36], \"n\": 16, \"arr2\": [-18, 88, -40, -52, 30, -10, -18, -56, 84, -22, -64, 80, -14, -64, 40, 92, 48, -8, 24, 82], \"m\": 12}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr1\": [0, 0, 1, 1, 1, 1, 1, 1], \"n\": 7, \"arr2\": [0, 1, 1, 1, 1, 1, 1, 1], \"m\": 7}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr1\": [46, 87, 98], \"n\": 2, \"arr2\": [67, 31, 54], \"m\": 2}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
276
Longest Increasing Odd Even Subsequence
C++
int longestIncreasingOddEvenSubsequence(vector<int> arr, int n) {
[ "arr", "n" ]
def longest_increasing_odd_even_subsequence(arr, n): lioes = list() maxLen = 0 for i in range(n): lioes.append(1) i = 1 for i in range(n): for j in range(i): if ((arr[i] > arr[j]) and (((arr[i] + arr[j]) % 2) != 0) and (lioes[i] < (lioes[j] + 1))): lioes[i] = (lioes[j] + 1) for i in range(n): if (maxLen < lioes[i]): maxLen = lioes[i] return maxLen
int longest_increasing_odd_even_subsequence(vector<int> arr, int n) { int lioes [ n ]; int maxLen = 0; for ( int i = 0; i < n; i ++ ) lioes [ i ] = 1; for ( int i = 1; i < n; i ++ ) for ( int j = 0; j < i; j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1; for ( int i = 0; i < n; i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ]; return maxLen; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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, 8, 9, 16, 16, 27, 32, 33, 35, 35, 39, 39, 41, 42, 44, 47, 48, 50, 56, 59, 66, 69, 70, 73, 74, 76, 78, 87, 87, 89, 94, 96, 96, 98, 98}, 32, 18); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({40, 76, -54, -92, -28, -96, 8, 60, 28, -38, -62, -40, -16, 16, 52, 28, 70, -56, -50, 46, 68, -16, -56, 46, 42, 70, 52, -34, 86, -32, -50, 64, 36, 54, 20, 82, 84}, 25, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1}, 4, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({15, 19, 87, 44, 15, 48, 21, 85, 90, 30, 88, 95, 48, 92, 29, 52, 46, 46, 7, 23, 96, 97, 43}, 19, 5); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -96, -94, -94, -94, -80, -80, -78, -64, -62, -62, -46, -42, -38, -36, -36, -34, -32, -20, -18, -16, -12, -8, -4, -4, -2, -2, 2, 6, 12, 34, 40, 42, 44, 46, 46, 50, 54, 58, 58, 70, 72, 72, 76, 78, 86}, 33, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1}, 13, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 7, 19, 36, 44, 63, 68, 72, 83}, 8, 5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-64, 12, 56, 50, 94, 6, 0, 70, -70, 46, -84, -64, 4, 76, 28, 94, -8, 24, 76, 64, -62, -34}, 15, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({71, 57, 20, 8, 90, 69, 15, 62, 45, 14, 65, 20, 48, 9}, 10, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestIncreasingOddEvenSubsequence", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 18, \"inputs\": {\"arr\": [7, 8, 9, 16, 16, 27, 32, 33, 35, 35, 39, 39, 41, 42, 44, 47, 48, 50, 56, 59, 66, 69, 70, 73, 74, 76, 78, 87, 87, 89, 94, 96, 96, 98, 98], \"n\": 32}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [40, 76, -54, -92, -28, -96, 8, 60, 28, -38, -62, -40, -16, 16, 52, 28, 70, -56, -50, 46, 68, -16, -56, 46, 42, 70, 52, -34, 86, -32, -50, 64, 36, 54, 20, 82, 84], \"n\": 25}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 1], \"n\": 4}}, {\"idx\": 3, \"outputs\": 5, \"inputs\": {\"arr\": [15, 19, 87, 44, 15, 48, 21, 85, 90, 30, 88, 95, 48, 92, 29, 52, 46, 46, 7, 23, 96, 97, 43], \"n\": 19}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-98, -96, -94, -94, -94, -80, -80, -78, -64, -62, -62, -46, -42, -38, -36, -36, -34, -32, -20, -18, -16, -12, -8, -4, -4, -2, -2, 2, 6, 12, 34, 40, 42, 44, 46, 46, 50, 54, 58, 58, 70, 72, 72, 76, 78, 86], \"n\": 33}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1], \"n\": 13}}, {\"idx\": 6, \"outputs\": 5, \"inputs\": {\"arr\": [6, 7, 19, 36, 44, 63, 68, 72, 83], \"n\": 8}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [-64, 12, 56, 50, 94, 6, 0, 70, -70, 46, -84, -64, 4, 76, 28, 94, -8, 24, 76, 64, -62, -34], \"n\": 15}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 21}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"arr\": [71, 57, 20, 8, 90, 69, 15, 62, 45, 14, 65, 20, 48, 9], \"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 ] }
277
Longest Palindrome Subsequence Space
C++
int longestPalindromeSubsequenceSpace(string s) {
[ "s" ]
def longest_palindrome_subsequence_space(s): n = len(s) a = ([0] * n) for i in range((n - 1), (- 1), (- 1)): back_up = 0 for j in range(i, n): if (j == i): a[j] = 1 elif (s[i] == s[j]): temp = a[j] a[j] = (back_up + 2) back_up = temp else: back_up = a[j] a[j] = max(a[(j - 1)], a[j]) return a[(n - 1)]
int longest_palindrome_subsequence_space(string & s) { int n = s . length ( ); int a [ n ]; for ( int i = n - 1; i >= 0; i -- ) { int back_up = 0; for ( int j = i; j < n; j ++ ) { if ( j == i ) a [ j ] = 1; else if ( s [ i ] == s [ j ] ) { int temp = a [ j ]; a [ j ] = back_up + 2; back_up = temp; } else { back_up = a [ j ]; a [ j ] = max ( a [ j - 1 ], a [ j ] ); } } } return a [ 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 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(\" E\", 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0845591950\", 7); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00101011\", 5); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"pLSvlwrACvFaoT\", 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"7246\", 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1010101100000\", 8); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"obPkcLSFp\", 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"914757557818\", 7); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"PKvUWIQ\", 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestPalindromeSubsequenceSpace", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"s\": \" E\"}}, {\"idx\": 1, \"outputs\": 7, \"inputs\": {\"s\": \"0845591950\"}}, {\"idx\": 2, \"outputs\": 5, \"inputs\": {\"s\": \"00101011\"}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"s\": \"pLSvlwrACvFaoT\"}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"s\": \"7246\"}}, {\"idx\": 5, \"outputs\": 8, \"inputs\": {\"s\": \"1010101100000\"}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"s\": \"obPkcLSFp\"}}, {\"idx\": 7, \"outputs\": 7, \"inputs\": {\"s\": \"914757557818\"}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"s\": \"1\"}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"s\": \"PKvUWIQ\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
278
Longest Prefix Also Suffix 1
C++
int longestPrefixAlsoSuffix1(string s) {
[ "s" ]
def longest_prefix_also_suffix_1(s): n = len(s) lps = ([0] * n) l = 0 i = 1 while (i < n): if (s[i] == s[l]): l = (l + 1) lps[i] = l i = (i + 1) elif (l != 0): l = lps[(l - 1)] else: lps[i] = 0 i = (i + 1) res = lps[(n - 1)] if (res > (n / 2)): return (n // 2) else: return res
int longest_prefix_also_suffix_1(string s) { int n = s . length ( ); int lps [ n ]; lps [ 0 ] = 0; int len = 0; int i = 1; while ( i < n ) { if ( s [ i ] == s [ len ] ) { len ++; lps [ i ] = len; i ++; } else { if ( len != 0 ) { len = lps [ len - 1 ]; } else { lps [ i ] = 0; i ++; } } } int res = lps [ n - 1 ]; return ( res > n / 2 ) ? n / 2 : res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string s, 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(\"aabcdaabc\", 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1372494598\", 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"110000100001\", 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"abcab\", 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"488938\", 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011010101011\", 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aaaa\", 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"3356203205\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1010\", 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kkXiiTZkGeh\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestPrefixAlsoSuffix1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"s\": \"aabcdaabc\"}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"s\": \"1372494598\"}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"s\": \"110000100001\"}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"s\": \"abcab\"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"s\": \"488938\"}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"s\": \"011010101011\"}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"s\": \"aaaa\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"s\": \"3356203205\"}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"s\": \"1010\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"s\": \"kkXiiTZkGeh\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
279
Longest Repeated Subsequence 1
C++
string longestRepeatedSubsequence1(string str) {
[ "str" ]
def longest_repeated_subsequence_1(str): n = len(str) dp = [[0 for i in range((n + 1))] for j in range((n + 1))] for i in range(1, (n + 1)): for j in range(1, (n + 1)): if ((str[(i - 1)] == str[(j - 1)]) and (i != j)): dp[i][j] = (1 + dp[(i - 1)][(j - 1)]) else: dp[i][j] = max(dp[i][(j - 1)], dp[(i - 1)][j]) res = '' i = n j = n while ((i > 0) and (j > 0)): if (dp[i][j] == (dp[(i - 1)][(j - 1)] + 1)): res += str[(i - 1)] i -= 1 j -= 1 elif (dp[i][j] == dp[(i - 1)][j]): i -= 1 else: j -= 1 res = ''.join(reversed(res)) return res
string longest_repeated_subsequence_1(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 i = 1; i <= n; i ++ ) for ( int j = 1; j <= n; j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]; else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ], dp [ i - 1 ] [ j ] ); string res = ""; int i = n, j = n; while ( i > 0 && j > 0 ) { if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) { res = res + str [ i - 1 ]; i --; j --; } else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i --; else j --; } reverse ( res . begin ( ), res . end ( ) ); 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 str, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"qnQxjoRx\", \"x\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"27473733400077\", \"7733007\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"000010111111\", \"0000111111\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"TNVwgrWSLu\", \"\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"9537\", \"\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1100\", \"10\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"lYcoiQfzN\", \"\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"52\", \"\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"00100001100\", \"0000010\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Rkxe\", \"\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestRepeatedSubsequence1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"x\", \"inputs\": {\"str\": \"qnQxjoRx\"}}, {\"idx\": 1, \"outputs\": \"7733007\", \"inputs\": {\"str\": \"27473733400077\"}}, {\"idx\": 2, \"outputs\": \"0000111111\", \"inputs\": {\"str\": \"000010111111\"}}, {\"idx\": 3, \"outputs\": \"\", \"inputs\": {\"str\": \"TNVwgrWSLu\"}}, {\"idx\": 4, \"outputs\": \"\", \"inputs\": {\"str\": \"9537\"}}, {\"idx\": 5, \"outputs\": \"10\", \"inputs\": {\"str\": \"1100\"}}, {\"idx\": 6, \"outputs\": \"\", \"inputs\": {\"str\": \"lYcoiQfzN\"}}, {\"idx\": 7, \"outputs\": \"\", \"inputs\": {\"str\": \"52\"}}, {\"idx\": 8, \"outputs\": \"0000010\", \"inputs\": {\"str\": \"00100001100\"}}, {\"idx\": 9, \"outputs\": \"\", \"inputs\": {\"str\": \"Rkxe\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
280
Longest Repeating And Non Overlapping Substring
C++
string longestRepeatingAndNonOverlappingSubstring(string str) {
[ "str" ]
def longest_repeating_and_non_overlapping_substring(str): n = len(str) LCSRe = [[0 for x in range((n + 1))] for y in range((n + 1))] res = '' res_length = 0 index = 0 for i in range(1, (n + 1)): for j in range((i + 1), (n + 1)): if ((str[(i - 1)] == str[(j - 1)]) and (LCSRe[(i - 1)][(j - 1)] < (j - i))): LCSRe[i][j] = (LCSRe[(i - 1)][(j - 1)] + 1) if (LCSRe[i][j] > res_length): res_length = LCSRe[i][j] index = max(i, index) else: LCSRe[i][j] = 0 if (res_length > 0): for i in range(((index - res_length) + 1), (index + 1)): res = (res + str[(i - 1)]) return res
string longest_repeating_and_non_overlapping_substring(string str) { int n = str . length ( ); int LCSRe [ n + 1 ] [ n + 1 ]; memset ( LCSRe, 0, sizeof ( LCSRe ) ); string res; int res_length = 0; int i, index = 0; for ( i = 1; i <= n; i ++ ) { for ( int j = i + 1; j <= n; j ++ ) { if ( str [ i - 1 ] == str [ j - 1 ] && LCSRe [ i - 1 ] [ j - 1 ] < ( j - i ) ) { LCSRe [ i ] [ j ] = LCSRe [ i - 1 ] [ j - 1 ] + 1; if ( LCSRe [ i ] [ j ] > res_length ) { res_length = LCSRe [ i ] [ j ]; index = max ( i, index ); } } else LCSRe [ i ] [ j ] = 0; } } if ( res_length > 0 ) for ( i = index - res_length + 1; i <= index; i ++ ) res . push_back ( str [ i - 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(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string str, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"fbfHTjE\", \"f\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"09285256323\", \"2\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0011000101110\", \"001\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ue JkVZTt\", \"\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"48387612426300\", \"4\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"010\", \"0\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ddRrUz\", \"d\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1049162633793\", \"1\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100011\", \"1\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"iJfadiVaQqv\", \"i\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestRepeatingAndNonOverlappingSubstring", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"f\", \"inputs\": {\"str\": \"fbfHTjE\"}}, {\"idx\": 1, \"outputs\": \"2\", \"inputs\": {\"str\": \"09285256323\"}}, {\"idx\": 2, \"outputs\": \"001\", \"inputs\": {\"str\": \"0011000101110\"}}, {\"idx\": 3, \"outputs\": \"\", \"inputs\": {\"str\": \"ue JkVZTt\"}}, {\"idx\": 4, \"outputs\": \"4\", \"inputs\": {\"str\": \"48387612426300\"}}, {\"idx\": 5, \"outputs\": \"0\", \"inputs\": {\"str\": \"010\"}}, {\"idx\": 6, \"outputs\": \"d\", \"inputs\": {\"str\": \"ddRrUz\"}}, {\"idx\": 7, \"outputs\": \"1\", \"inputs\": {\"str\": \"1049162633793\"}}, {\"idx\": 8, \"outputs\": \"1\", \"inputs\": {\"str\": \"100011\"}}, {\"idx\": 9, \"outputs\": \"i\", \"inputs\": {\"str\": \"iJfadiVaQqv\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
281
Longest Repeating Subsequence
C++
int longestRepeatingSubsequence(string str) {
[ "str" ]
def longest_repeating_subsequence(str): n = len(str) dp = ([([0] * (n + 1))] * (n + 1)) for i in range(1, (n + 1)): for j in range(1, (n + 1)): if ((str[(i - 1)] == str[(j - 1)]) and (i != j)): dp[i][j] = (1 + dp[(i - 1)][(j - 1)]) else: dp[i][j] = max(dp[i][(j - 1)], dp[(i - 1)][j]) return dp[n][n]
int longest_repeating_subsequence(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 i = 1; i <= n; i ++ ) { for ( int j = 1; j <= n; j ++ ) { if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]; else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ], dp [ i - 1 ] [ j ] ); } } return dp [ 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(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(\"JxZFz\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"7648992235770\", 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11100000\", 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"cRN SgYjPsctJ\", 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"434\", 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"JRfZIAsbrPBZ\", 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"03779368305592\", 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1111000\", 5); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"BkULuIi\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestRepeatingSubsequence", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"str\": \"JxZFz\"}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"str\": \"7648992235770\"}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"str\": \"11100000\"}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"str\": \"cRN SgYjPsctJ\"}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"str\": \"434\"}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"str\": \"1\"}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"str\": \"JRfZIAsbrPBZ\"}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"str\": \"03779368305592\"}}, {\"idx\": 8, \"outputs\": 5, \"inputs\": {\"str\": \"1111000\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"str\": \"BkULuIi\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
282
Longest Subarray Count 1S One Count 0S
C++
int longestSubarrayCount1SOneCount0S(vector<int> arr, int n) {
[ "arr", "n" ]
def longest_subarray_count_1s_one_count_0s(arr, n): um = {i: 0 for i in range(10)} sum = 0 maxLen = 0 for i in range(n): if (arr[i] == 0): sum += (- 1) else: sum += 1 if (sum == 1): maxLen = (i + 1) elif (sum not in um): um[sum] = i if ((sum - 1) in um): if (maxLen < (i - um[(sum - 1)])): maxLen = (i - um[(sum - 1)]) return maxLen
int longest_subarray_count_1s_one_count_0s(vector<int> arr, int n) { unordered_map < int, int > um; int sum = 0, maxLen = 0; for ( int i = 0; i < n; i ++ ) { sum += arr [ i ] == 0 ? - 1 : 1; if ( sum == 1 ) maxLen = i + 1; else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i; if ( um . find ( sum - 1 ) != um . end ( ) ) { if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ]; } } return maxLen; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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, 31, 35}, 2, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 88, -72, 28, -54, 32, -34}, 6, 5); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1, 1, 1, 1}, 4, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({39, 22, 15, 10, 34, 87, 46, 83, 74, 77, 61, 90, 43, 67, 64, 72, 92, 52, 68, 53, 67, 32, 82, 76, 76, 47, 74, 47, 8, 80, 85, 58, 75}, 26, 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-82, -58, -50, -30, -14, -4, -2, -2, 0, 22, 36, 58, 70, 80, 80, 82, 84, 90}, 14, 11); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1}, 7, 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 11, 17, 21, 21, 22, 30, 31, 36, 37, 39, 40, 45, 46, 47, 48, 52, 53, 53, 60, 60, 65, 66, 66, 67, 67, 87, 88, 91, 97}, 29, 9); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-4, -60, -78, -50, 64, 18, 0, 76, 12, 86, -22}, 7, 6); \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}, 17, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 39, 50, 37, 71, 66, 55, 34, 1, 41, 34, 99, 69, 31}, 11, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestSubarrayCount1SOneCount0S", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [6, 10, 31, 35], \"n\": 2}}, {\"idx\": 1, \"outputs\": 5, \"inputs\": {\"arr\": [4, 88, -72, 28, -54, 32, -34], \"n\": 6}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 4}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"arr\": [39, 22, 15, 10, 34, 87, 46, 83, 74, 77, 61, 90, 43, 67, 64, 72, 92, 52, 68, 53, 67, 32, 82, 76, 76, 47, 74, 47, 8, 80, 85, 58, 75], \"n\": 26}}, {\"idx\": 4, \"outputs\": 11, \"inputs\": {\"arr\": [-82, -58, -50, -30, -14, -4, -2, -2, 0, 22, 36, 58, 70, 80, 80, 82, 84, 90], \"n\": 14}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"arr\": [1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1], \"n\": 7}}, {\"idx\": 6, \"outputs\": 9, \"inputs\": {\"arr\": [4, 11, 17, 21, 21, 22, 30, 31, 36, 37, 39, 40, 45, 46, 47, 48, 52, 53, 53, 60, 60, 65, 66, 66, 67, 67, 87, 88, 91, 97], \"n\": 29}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"arr\": [-4, -60, -78, -50, 64, 18, 0, 76, 12, 86, -22], \"n\": 7}}, {\"idx\": 8, \"outputs\": 3, \"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], \"n\": 17}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"arr\": [4, 39, 50, 37, 71, 66, 55, 34, 1, 41, 34, 99, 69, 31], \"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 ] }
283
Longest Subsequence Such That Difference Between Adjacents Is One
C++
int longestSubsequenceSuchThatDifferenceBetweenAdjacentsIsOne(vector<int> arr, int n) {
[ "arr", "n" ]
def longest_subsequence_such_that_difference_between_adjacents_is_one(arr, n): dp = [1 for i in range(n)] for i in range(n): for j in range(i): if ((arr[i] == (arr[j] + 1)) or (arr[i] == (arr[j] - 1))): dp[i] = max(dp[i], (dp[j] + 1)) result = 1 for i in range(n): if (result < dp[i]): result = dp[i] return result
int longest_subsequence_such_that_difference_between_adjacents_is_one(vector<int> arr, int n) { int dp [ n ]; for ( int i = 0; i < n; i ++ ) dp [ i ] = 1; for ( int i = 1; i < n; i ++ ) { for ( int j = 0; j < i; j ++ ) { if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = max ( dp [ i ], dp [ j ] + 1 ); } } int result = 1; for ( int i = 0; i < n; i ++ ) if ( result < dp [ i ] ) result = dp [ 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> 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, 13, 15, 17, 18, 20, 22, 24, 28, 34, 37, 43, 46, 47, 49, 51, 52, 54, 58, 64, 65, 77, 78, 79, 87, 90, 92, 93, 94, 97}, 23, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -56, 76, 86, 42, -40, 8, 34, -48, -54, -80, 6, 42, 48, 76, -26, 6}, 15, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 16, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 22, 15, 26, 29, 47, 22}, 5, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -84, -76, -76, -74, -74, -66, -58, -58, -56, -56, -44, -38, -36, -34, -32, -16, -10, 2, 6, 24, 24, 24, 34, 36, 54, 60, 68, 70, 76, 88}, 17, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1}, 26, 12); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 3, 12, 12, 12, 12, 14, 17, 18, 19, 23, 27, 28, 30, 35, 38, 42, 44, 45, 48, 52, 59, 61, 64, 65, 69, 73, 76, 77, 82, 83, 85, 87, 99}, 23, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-54, -20, 24, -78, -58, 64, 34, 70, -36, -24}, 8, 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}, 27, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 35, 75, 21, 82, 32, 28, 53, 20, 27, 42, 92, 32, 70, 81, 75, 72, 66, 97, 60, 11, 83, 14, 30, 5, 68, 17, 27, 62, 86, 26, 20, 97, 91, 44, 69}, 20, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "longestSubsequenceSuchThatDifferenceBetweenAdjacentsIsOne", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [2, 13, 15, 17, 18, 20, 22, 24, 28, 34, 37, 43, 46, 47, 49, 51, 52, 54, 58, 64, 65, 77, 78, 79, 87, 90, 92, 93, 94, 97], \"n\": 23}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [-86, -56, 76, 86, 42, -40, 8, 34, -48, -54, -80, 6, 42, 48, 76, -26, 6], \"n\": 15}}, {\"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, 1, 1, 1, 1], \"n\": 16}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [5, 22, 15, 26, 29, 47, 22], \"n\": 5}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-90, -84, -76, -76, -74, -74, -66, -58, -58, -56, -56, -44, -38, -36, -34, -32, -16, -10, 2, 6, 24, 24, 24, 34, 36, 54, 60, 68, 70, 76, 88], \"n\": 17}}, {\"idx\": 5, \"outputs\": 12, \"inputs\": {\"arr\": [0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1], \"n\": 26}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"arr\": [1, 3, 12, 12, 12, 12, 14, 17, 18, 19, 23, 27, 28, 30, 35, 38, 42, 44, 45, 48, 52, 59, 61, 64, 65, 69, 73, 76, 77, 82, 83, 85, 87, 99], \"n\": 23}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [-54, -20, 24, -78, -58, 64, 34, 70, -36, -24], \"n\": 8}}, {\"idx\": 8, \"outputs\": 2, \"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], \"n\": 27}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr\": [5, 35, 75, 21, 82, 32, 28, 53, 20, 27, 42, 92, 32, 70, 81, 75, 72, 66, 97, 60, 11, 83, 14, 30, 5, 68, 17, 27, 62, 86, 26, 20, 97, 91, 44, 69], \"n\": 20}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
284
Lower Insertion Point
C++
int lowerInsertionPoint(vector<int> arr, int n, int x) {
[ "arr", "n", "x" ]
def lower_insertion_point(arr, n, X): if (X < arr[0]): return 0 elif (X > arr[(n - 1)]): return n lowerPnt = 0 i = 1 while ((i < n) and (arr[i] < X)): lowerPnt = i i = (i * 2) while ((lowerPnt < n) and (arr[lowerPnt] < X)): lowerPnt += 1 return lowerPnt
int lower_insertion_point(vector<int> arr, int n, int X) { if ( X < arr [ 0 ] ) return 0; else if ( X > arr [ n - 1 ] ) return n; int lowerPnt = 0; int i = 1; while ( i < n && arr [ i ] < X ) { lowerPnt = i; i = i * 2; } while ( lowerPnt < n && arr [ lowerPnt ] < X ) lowerPnt ++; return lowerPnt; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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({1, 2, 5, 5, 16, 16, 20, 26, 32, 35, 39, 39, 41, 44, 48, 48, 51, 59, 59, 62, 66, 66, 70, 74, 75, 78, 80, 86, 86, 96}, 17, 29, 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-76, 80, -6, -2, 50, 72, 84, -56, 70, 8, 48, 6, -24, -50, -72}, 14, 9, 14); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1}, 8, 4, 8); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({74, 65, 84, 71}, 2, 3, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -90, -86, -84, -76, -76, -62, -58, -54, -50, -50, -44, -42, -38, -34, -14, -8, 6, 12, 24, 38, 40, 50, 62, 84, 86, 92}, 19, 19, 19); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1}, 12, 17, 12); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 10, 14, 14, 16, 19, 23, 23, 25, 26, 29, 34, 42, 42, 43, 45, 47, 49, 50, 51, 51, 56, 59, 65, 69, 72, 75, 78, 79, 80, 82, 82, 82, 84, 85, 91, 98}, 31, 24, 8); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -2, 22, -2, 58, -2, 96, 38, 36, -66, -98, 22, -80, -32, 22, 0, -34, -16, 82, 76, 12, 84, 66, 8, 32, 18, -98, -10}, 22, 16, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1, 1}, 3, 5, 3); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 59, 22, 52, 93, 14, 42, 71, 69, 15, 52, 78, 35, 61, 92, 90, 70, 48, 47, 72, 74, 46, 22, 74, 83, 32, 14, 24, 18, 27, 18, 68, 29, 31}, 19, 33, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "lowerInsertionPoint", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"arr\": [1, 2, 5, 5, 16, 16, 20, 26, 32, 35, 39, 39, 41, 44, 48, 48, 51, 59, 59, 62, 66, 66, 70, 74, 75, 78, 80, 86, 86, 96], \"n\": 17, \"x\": 29}}, {\"idx\": 1, \"outputs\": 14, \"inputs\": {\"arr\": [-76, 80, -6, -2, 50, 72, 84, -56, 70, 8, 48, 6, -24, -50, -72], \"n\": 14, \"x\": 9}}, {\"idx\": 2, \"outputs\": 8, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 8, \"x\": 4}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [74, 65, 84, 71], \"n\": 2, \"x\": 3}}, {\"idx\": 4, \"outputs\": 19, \"inputs\": {\"arr\": [-96, -92, -90, -86, -84, -76, -76, -62, -58, -54, -50, -50, -44, -42, -38, -34, -14, -8, 6, 12, 24, 38, 40, 50, 62, 84, 86, 92], \"n\": 19, \"x\": 19}}, {\"idx\": 5, \"outputs\": 12, \"inputs\": {\"arr\": [1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1], \"n\": 12, \"x\": 17}}, {\"idx\": 6, \"outputs\": 8, \"inputs\": {\"arr\": [6, 10, 14, 14, 16, 19, 23, 23, 25, 26, 29, 34, 42, 42, 43, 45, 47, 49, 50, 51, 51, 56, 59, 65, 69, 72, 75, 78, 79, 80, 82, 82, 82, 84, 85, 91, 98], \"n\": 31, \"x\": 24}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"arr\": [-90, -2, 22, -2, 58, -2, 96, 38, 36, -66, -98, 22, -80, -32, 22, 0, -34, -16, 82, 76, 12, 84, 66, 8, 32, 18, -98, -10], \"n\": 22, \"x\": 16}}, {\"idx\": 8, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1, 1], \"n\": 3, \"x\": 5}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [85, 59, 22, 52, 93, 14, 42, 71, 69, 15, 52, 78, 35, 61, 92, 90, 70, 48, 47, 72, 74, 46, 22, 74, 83, 32, 14, 24, 18, 27, 18, 68, 29, 31], \"n\": 19, \"x\": 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 ] }
285
Making Elements Of Two Arrays Same With Minimum Incrementdecrement
C++
int makingElementsOfTwoArraysSameWithMinimumIncrementdecrement(vector<int> a, vector<int> b, int n) {
[ "a", "b", "n" ]
def making_elements_of_two_arrays_same_with_minimum_incrementdecrement(a, b, n): a.sort(reverse=False) b.sort(reverse=False) result = 0 for i in range(0, n, 1): if (a[i] > b[i]): result = (result + abs((a[i] - b[i]))) elif (a[i] < b[i]): result = (result + abs((a[i] - b[i]))) return result
int making_elements_of_two_arrays_same_with_minimum_incrementdecrement(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 = result + abs ( a [ i ] - b [ 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, 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({1, 6, 6, 7, 10, 11, 13, 18, 19, 19, 19, 31, 34, 37, 37, 40, 41, 41, 47, 47, 53, 54, 55, 55, 56, 56, 60, 60, 62, 62, 66, 73, 75, 76, 78, 81, 81, 85, 88, 90, 91, 92, 93, 95, 97, 98}, {2, 2, 4, 7, 8, 8, 8, 8, 8, 9, 9, 12, 15, 16, 21, 25, 26, 27, 29, 34, 34, 35, 38, 40, 40, 44, 44, 47, 48, 54, 58, 61, 63, 64, 66, 69, 69, 70, 73, 74, 75, 76, 79, 80, 80, 93}, 23, 263); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-32, -12, -6, 62, 78, 86}, {-86, -60, 20, 32, 50, 52}, 4, 158); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 14, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({74, 76}, {16, 98}, 1, 58); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -90, -88, -84, -76, -54, -44, -42, -38, -30, 34, 42}, {-80, -54, -34, 12, 14, 16, 16, 46, 50, 64, 84, 92}, 8, 506); \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, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 14, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 6, 13, 16, 24, 36, 40, 40, 44, 47, 52, 58, 58, 59, 63, 66, 67, 69, 70, 74, 77, 81, 88, 89, 90, 94, 96}, {1, 7, 10, 17, 21, 22, 22, 27, 36, 37, 39, 46, 52, 53, 56, 59, 65, 67, 70, 75, 78, 78, 79, 89, 89, 94, 96, 97}, 24, 105); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-54, -36, -36, -16, -12, -10, -8, -2, 10, 22, 36, 40, 44, 50, 54, 66, 84, 92, 98}, {-92, -76, -74, -62, -58, -26, -18, -10, -10, -10, -6, 22, 26, 50, 62, 78, 84, 86, 86}, 16, 392); \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}, {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, 1}, 36, 5); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 7, 8, 15, 19, 24, 26, 30, 32, 34, 37, 42, 43, 43, 55, 55, 55, 63, 64, 64, 76, 81, 88, 94}, {3, 4, 11, 17, 17, 22, 28, 44, 63, 63, 65, 66, 69, 74, 80, 80, 81, 81, 81, 86, 90, 91, 96, 98}, 22, 354); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "makingElementsOfTwoArraysSameWithMinimumIncrementdecrement", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 263, \"inputs\": {\"a\": [1, 6, 6, 7, 10, 11, 13, 18, 19, 19, 19, 31, 34, 37, 37, 40, 41, 41, 47, 47, 53, 54, 55, 55, 56, 56, 60, 60, 62, 62, 66, 73, 75, 76, 78, 81, 81, 85, 88, 90, 91, 92, 93, 95, 97, 98], \"b\": [2, 2, 4, 7, 8, 8, 8, 8, 8, 9, 9, 12, 15, 16, 21, 25, 26, 27, 29, 34, 34, 35, 38, 40, 40, 44, 44, 47, 48, 54, 58, 61, 63, 64, 66, 69, 69, 70, 73, 74, 75, 76, 79, 80, 80, 93], \"n\": 23}}, {\"idx\": 1, \"outputs\": 158, \"inputs\": {\"a\": [-32, -12, -6, 62, 78, 86], \"b\": [-86, -60, 20, 32, 50, 52], \"n\": 4}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"b\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 14}}, {\"idx\": 3, \"outputs\": 58, \"inputs\": {\"a\": [74, 76], \"b\": [16, 98], \"n\": 1}}, {\"idx\": 4, \"outputs\": 506, \"inputs\": {\"a\": [-92, -90, -88, -84, -76, -54, -44, -42, -38, -30, 34, 42], \"b\": [-80, -54, -34, 12, 14, 16, 16, 46, 50, 64, 84, 92], \"n\": 8}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"b\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 14}}, {\"idx\": 6, \"outputs\": 105, \"inputs\": {\"a\": [4, 5, 6, 13, 16, 24, 36, 40, 40, 44, 47, 52, 58, 58, 59, 63, 66, 67, 69, 70, 74, 77, 81, 88, 89, 90, 94, 96], \"b\": [1, 7, 10, 17, 21, 22, 22, 27, 36, 37, 39, 46, 52, 53, 56, 59, 65, 67, 70, 75, 78, 78, 79, 89, 89, 94, 96, 97], \"n\": 24}}, {\"idx\": 7, \"outputs\": 392, \"inputs\": {\"a\": [-54, -36, -36, -16, -12, -10, -8, -2, 10, 22, 36, 40, 44, 50, 54, 66, 84, 92, 98], \"b\": [-92, -76, -74, -62, -58, -26, -18, -10, -10, -10, -6, 22, 26, 50, 62, 78, 84, 86, 86], \"n\": 16}}, {\"idx\": 8, \"outputs\": 5, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"b\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 36}}, {\"idx\": 9, \"outputs\": 354, \"inputs\": {\"a\": [3, 7, 8, 15, 19, 24, 26, 30, 32, 34, 37, 42, 43, 43, 55, 55, 55, 63, 64, 64, 76, 81, 88, 94], \"b\": [3, 4, 11, 17, 17, 22, 28, 44, 63, 63, 65, 66, 69, 74, 80, 80, 81, 81, 81, 86, 90, 91, 96, 98], \"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 ] }
286
Maximize Sum Arrii
C++
int maximizeSumArrii(vector<int> arr, int n) {
[ "arr", "n" ]
def maximize_sum_arrii(arr, n): arr.sort() sum = 0 for i in range(n): sum += (arr[i] * i) return sum
int maximize_sum_arrii(vector<int> arr, int n) { sort(arr.begin(), arr.end()); int sum = 0; for ( int i = 0; i < n; i ++ ) sum += ( arr [ i ] * i ); return sum; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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, 4, 6, 7, 8, 9, 11, 19, 23, 24, 30, 31, 31, 32, 41, 43, 43, 46, 47, 50, 50, 51, 53, 57, 63, 63, 69, 73, 74, 79, 80, 81, 81, 85, 86, 88, 92, 93, 95, 98, 99}, 22, 8185); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -82, -80, -78, -76, -74, -68, -62, -58, -58, -52, -42, -42, -40, -34, -16, -10, -10, -6, 10, 12, 20, 32, 52, 62, 66, 68, 72, 76, 76, 80, 90, 90, 90, 90, 92, 98}, 24, -5496); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, 13, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 13, 14, 42, 44, 44, 44, 45, 47, 52, 58, 79, 98, 99}, 11, 2566); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -88, -68, -66, -46, -42, -40, -20, -16, 4, 8, 8, 8, 20, 28, 52, 84, 98}, 14, -764); \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}, 13, 23); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 6, 7, 9, 11, 13, 16, 19, 22, 25, 26, 27, 28, 29, 32, 32, 32, 33, 36, 40, 43, 43, 47, 49, 51, 51, 52, 53, 59, 61, 63, 65, 66, 66, 67, 72, 73, 73, 75, 76, 80, 86, 87, 89, 89, 91, 96, 98, 99}, 42, 48954); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -96, -90, -78, -66, -52, -48, -38, -34, -32, -30, -26, -24, -22, -20, -20, -14, -14, -12, -12, -8, -6, -4, 2, 6, 26, 28, 32, 32, 34, 40, 40, 48, 52, 54, 64, 64, 68, 70, 76, 88, 92, 96}, 39, 16394); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1}, 3, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({18, 20, 21, 32, 34, 44, 47, 49, 49, 49, 62, 71, 75, 84, 84, 88, 88}, 8, 1139); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximizeSumArrii", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 8185, \"inputs\": {\"arr\": [2, 3, 4, 6, 7, 8, 9, 11, 19, 23, 24, 30, 31, 31, 32, 41, 43, 43, 46, 47, 50, 50, 51, 53, 57, 63, 63, 69, 73, 74, 79, 80, 81, 81, 85, 86, 88, 92, 93, 95, 98, 99], \"n\": 22}}, {\"idx\": 1, \"outputs\": -5496, \"inputs\": {\"arr\": [-98, -98, -82, -80, -78, -76, -74, -68, -62, -58, -58, -52, -42, -42, -40, -34, -16, -10, -10, -6, 10, 12, 20, 32, 52, 62, 66, 68, 72, 76, 76, 80, 90, 90, 90, 90, 92, 98], \"n\": 24}}, {\"idx\": 2, \"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], \"n\": 13}}, {\"idx\": 3, \"outputs\": 2566, \"inputs\": {\"arr\": [8, 13, 14, 42, 44, 44, 44, 45, 47, 52, 58, 79, 98, 99], \"n\": 11}}, {\"idx\": 4, \"outputs\": -764, \"inputs\": {\"arr\": [-90, -88, -68, -66, -46, -42, -40, -20, -16, 4, 8, 8, 8, 20, 28, 52, 84, 98], \"n\": 14}}, {\"idx\": 5, \"outputs\": 23, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 6, \"outputs\": 48954, \"inputs\": {\"arr\": [5, 6, 7, 9, 11, 13, 16, 19, 22, 25, 26, 27, 28, 29, 32, 32, 32, 33, 36, 40, 43, 43, 47, 49, 51, 51, 52, 53, 59, 61, 63, 65, 66, 66, 67, 72, 73, 73, 75, 76, 80, 86, 87, 89, 89, 91, 96, 98, 99], \"n\": 42}}, {\"idx\": 7, \"outputs\": 16394, \"inputs\": {\"arr\": [-98, -96, -90, -78, -66, -52, -48, -38, -34, -32, -30, -26, -24, -22, -20, -20, -14, -14, -12, -12, -8, -6, -4, 2, 6, 26, 28, 32, 32, 34, 40, 40, 48, 52, 54, 64, 64, 68, 70, 76, 88, 92, 96], \"n\": 39}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 1, 1], \"n\": 3}}, {\"idx\": 9, \"outputs\": 1139, \"inputs\": {\"arr\": [18, 20, 21, 32, 34, 44, 47, 49, 49, 49, 62, 71, 75, 84, 84, 88, 88], \"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 ] }
287
Maximize Sum Consecutive Differences Circular Array
C++
int maximizeSumConsecutiveDifferencesCircularArray(vector<int> arr, int n) {
[ "arr", "n" ]
def maximize_sum_consecutive_differences_circular_array(arr, n): sum = 0 arr.sort() for i in range(0, int((n / 2))): sum -= (2 * arr[i]) sum += (2 * arr[((n - i) - 1)]) return sum
int maximize_sum_consecutive_differences_circular_array(vector<int> arr, int n) { int sum = 0; sort(arr.begin(), arr.end()); for ( int i = 0; i < n / 2; i ++ ) { sum -= ( 2 * arr [ i ] ); sum += ( 2 * arr [ n - i - 1 ] ); } return sum; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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, 9, 12, 13, 17, 21, 24, 29, 37, 37, 39, 40, 41, 45, 49, 50, 53, 54, 56, 59, 60, 60, 70, 71, 72, 74, 77, 77, 78, 85, 89, 89, 90, 90, 95, 98, 98}, 34, 1454); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -84, -84, -84, -84, -80, -80, -80, -64, -52, -40, -32, -20, -18, -16, 0, 6, 14, 20, 26, 28, 30, 32, 32, 44, 48, 48, 52, 54, 66, 76, 78, 88, 92, 94, 96}, 24, 1980); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1}, 3, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 47, 53, 59, 80, 84, 96}, 5, 170); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -80, -68, -62, -60, -60, -48, -46, -44, -38, -16, -16, 0, 0, 2, 8, 20, 36, 40, 40, 44, 54, 60, 68, 70, 82, 82, 84, 92, 94, 96}, 29, 2812); \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, 1, 1, 1, 1, 1}, 32, 20); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 5, 10, 11, 13, 14, 15, 17, 17, 23, 23, 24, 27, 27, 28, 29, 30, 40, 42, 43, 46, 47, 51, 52, 57, 64, 65, 73, 74, 75, 76, 77, 81, 81, 82, 87, 89, 93, 95, 95, 99}, 35, 1542); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -92, -84, -84, -76, -72, -72, -72, -54, -48, -38, -22, -16, -12, 2, 2, 12, 20, 20, 24, 26, 26, 26, 26, 30, 38, 48, 50, 84, 86}, 21, 1608); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 20); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 8, 27, 31, 37, 46, 46, 52, 53, 53, 56, 57, 57, 73, 73, 74, 80, 84, 97}, 13, 344); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximizeSumConsecutiveDifferencesCircularArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1454, \"inputs\": {\"arr\": [8, 9, 12, 13, 17, 21, 24, 29, 37, 37, 39, 40, 41, 45, 49, 50, 53, 54, 56, 59, 60, 60, 70, 71, 72, 74, 77, 77, 78, 85, 89, 89, 90, 90, 95, 98, 98], \"n\": 34}}, {\"idx\": 1, \"outputs\": 1980, \"inputs\": {\"arr\": [-92, -84, -84, -84, -84, -80, -80, -80, -64, -52, -40, -32, -20, -18, -16, 0, 6, 14, 20, 26, 28, 30, 32, 32, 44, 48, 48, 52, 54, 66, 76, 78, 88, 92, 94, 96], \"n\": 24}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1], \"n\": 3}}, {\"idx\": 3, \"outputs\": 170, \"inputs\": {\"arr\": [7, 47, 53, 59, 80, 84, 96], \"n\": 5}}, {\"idx\": 4, \"outputs\": 2812, \"inputs\": {\"arr\": [-88, -80, -68, -62, -60, -60, -48, -46, -44, -38, -16, -16, 0, 0, 2, 8, 20, 36, 40, 40, 44, 54, 60, 68, 70, 82, 82, 84, 92, 94, 96], \"n\": 29}}, {\"idx\": 5, \"outputs\": 20, \"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\": 32}}, {\"idx\": 6, \"outputs\": 1542, \"inputs\": {\"arr\": [2, 5, 10, 11, 13, 14, 15, 17, 17, 23, 23, 24, 27, 27, 28, 29, 30, 40, 42, 43, 46, 47, 51, 52, 57, 64, 65, 73, 74, 75, 76, 77, 81, 81, 82, 87, 89, 93, 95, 95, 99], \"n\": 35}}, {\"idx\": 7, \"outputs\": 1608, \"inputs\": {\"arr\": [-94, -92, -84, -84, -76, -72, -72, -72, -54, -48, -38, -22, -16, -12, 2, 2, 12, 20, 20, 24, 26, 26, 26, 26, 30, 38, 48, 50, 84, 86], \"n\": 21}}, {\"idx\": 8, \"outputs\": 20, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 37}}, {\"idx\": 9, \"outputs\": 344, \"inputs\": {\"arr\": [7, 8, 27, 31, 37, 46, 46, 52, 53, 53, 56, 57, 57, 73, 73, 74, 80, 84, 97], \"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 ] }
288
Maximize Volume Cuboid Given Sum Sides
C++
int maximizeVolumeCuboidGivenSumSides(int s) {
[ "s" ]
def maximize_volume_cuboid_given_sum_sides(s): maxvalue = 0 i = 1 for i in range((s - 1)): j = 1 for j in range(s): k = ((s - i) - j) maxvalue = max(maxvalue, ((i * j) * k)) return maxvalue
int maximize_volume_cuboid_given_sum_sides(int s) { int maxvalue = 0; for ( int i = 1; i <= s - 2; i ++ ) { for ( int j = 1; j <= s - 1; j ++ ) { int k = s - i - j; maxvalue = max ( maxvalue, i * j * k ); } } return maxvalue; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int s, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(67, 11132); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 4096); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 7600); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 392); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 100); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 10648); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 15625); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 7220); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 17576); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximizeVolumeCuboidGivenSumSides", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 11132, \"inputs\": {\"s\": 67}}, {\"idx\": 1, \"outputs\": 4096, \"inputs\": {\"s\": 48}}, {\"idx\": 2, \"outputs\": 7600, \"inputs\": {\"s\": 59}}, {\"idx\": 3, \"outputs\": 392, \"inputs\": {\"s\": 22}}, {\"idx\": 4, \"outputs\": 100, \"inputs\": {\"s\": 14}}, {\"idx\": 5, \"outputs\": 10648, \"inputs\": {\"s\": 66}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"s\": 1}}, {\"idx\": 7, \"outputs\": 15625, \"inputs\": {\"s\": 75}}, {\"idx\": 8, \"outputs\": 7220, \"inputs\": {\"s\": 58}}, {\"idx\": 9, \"outputs\": 17576, \"inputs\": {\"s\": 78}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
289
Maximize Volume Cuboid Given Sum Sides 1
C++
int maximizeVolumeCuboidGivenSumSides1(int s) {
[ "s" ]
def maximize_volume_cuboid_given_sum_sides_1(s): length = int((s / 3)) s -= length breadth = (s / 2) height = (s - breadth) return int(((length * breadth) * height))
int maximize_volume_cuboid_given_sum_sides_1(int s) { int length = s / 3; s -= length; int breadth = s / 2; int height = s - breadth; return length * breadth * height; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int s, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(8, 18); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 32768); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 32768); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 32768); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 64); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 31744); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 13824); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 19683); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 2744); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 81); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximizeVolumeCuboidGivenSumSides1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 18, \"inputs\": {\"s\": 8}}, {\"idx\": 1, \"outputs\": 32768, \"inputs\": {\"s\": 96}}, {\"idx\": 2, \"outputs\": 32768, \"inputs\": {\"s\": 96}}, {\"idx\": 3, \"outputs\": 32768, \"inputs\": {\"s\": 96}}, {\"idx\": 4, \"outputs\": 64, \"inputs\": {\"s\": 12}}, {\"idx\": 5, \"outputs\": 31744, \"inputs\": {\"s\": 95}}, {\"idx\": 6, \"outputs\": 13824, \"inputs\": {\"s\": 72}}, {\"idx\": 7, \"outputs\": 19683, \"inputs\": {\"s\": 81}}, {\"idx\": 8, \"outputs\": 2744, \"inputs\": {\"s\": 42}}, {\"idx\": 9, \"outputs\": 81, \"inputs\": {\"s\": 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 ] }
290
Maximum Area Rectangle Picking Four Sides Array
C++
int maximumAreaRectanglePickingFourSidesArray(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_area_rectangle_picking_four_sides_array(arr, n): arr.sort(reverse=True) dimension = [0, 0] i = 0 j = 0 while ((i < (n - 1)) and (j < 2)): if (arr[i] == arr[(i + 1)]): dimension[j] = arr[i] j += 1 i += 1 i += 1 return (dimension[0] * dimension[1])
int maximum_area_rectangle_picking_four_sides_array(vector<int> arr, int n) { sort(arr.begin(), arr.end(), greater < int > ( ) ); int dimension [ 2 ] = { 0, 0 }; for ( int i = 0, j = 0; i < n - 1 && j < 2; i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ]; return ( dimension [ 0 ] * dimension [ 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({99, 96, 95, 95, 92, 84, 83, 82, 81, 74, 72, 68, 67, 52, 51, 51, 49, 47, 44, 40, 36, 25, 24, 17, 16, 14, 12, 11, 9, 8, 6, 5, 1}, 27, 4845); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-32, -54, -82, -92}, 2, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 15, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 96, 96, 94, 68, 65, 62, 60, 45, 44, 30, 26, 17, 17, 16, 15, 2}, 8, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 94, 82, 82, 74, 66, 66, 56, 54, 46, 16, -28, -34, -42, -50, -52, -78, -82, -88}, 15, 5412); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({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}, 18, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({97, 96, 93, 87, 85, 85, 75, 68, 65, 65, 64, 63, 62, 58, 56, 52, 49, 44, 43, 38, 33, 30, 29, 28, 27, 25, 24, 23, 14, 14, 13, 10, 8, 8, 8, 6, 1}, 20, 5525); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, 78, 76, 70, 60, 54, 50, 32, 16, 16, 6, -6, -20, -56, -64, -68, -70, -90, -90, -92}, 19, 1248); \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, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 30, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 94, 94, 90, 84, 82, 75, 71, 57, 55, 53, 51, 51, 43, 35, 31, 30, 29, 22, 18, 14, 10, 7, 5, 4}, 22, 4794); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumAreaRectanglePickingFourSidesArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 4845, \"inputs\": {\"arr\": [99, 96, 95, 95, 92, 84, 83, 82, 81, 74, 72, 68, 67, 52, 51, 51, 49, 47, 44, 40, 36, 25, 24, 17, 16, 14, 12, 11, 9, 8, 6, 5, 1], \"n\": 27}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-32, -54, -82, -92], \"n\": 2}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \"n\": 15}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [99, 96, 96, 94, 68, 65, 62, 60, 45, 44, 30, 26, 17, 17, 16, 15, 2], \"n\": 8}}, {\"idx\": 4, \"outputs\": 5412, \"inputs\": {\"arr\": [98, 94, 82, 82, 74, 66, 66, 56, 54, 46, 16, -28, -34, -42, -50, -52, -78, -82, -88], \"n\": 15}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [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], \"n\": 18}}, {\"idx\": 6, \"outputs\": 5525, \"inputs\": {\"arr\": [97, 96, 93, 87, 85, 85, 75, 68, 65, 65, 64, 63, 62, 58, 56, 52, 49, 44, 43, 38, 33, 30, 29, 28, 27, 25, 24, 23, 14, 14, 13, 10, 8, 8, 8, 6, 1], \"n\": 20}}, {\"idx\": 7, \"outputs\": 1248, \"inputs\": {\"arr\": [78, 78, 76, 70, 60, 54, 50, 32, 16, 16, 6, -6, -20, -56, -64, -68, -70, -90, -90, -92], \"n\": 19}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], \"n\": 30}}, {\"idx\": 9, \"outputs\": 4794, \"inputs\": {\"arr\": [94, 94, 94, 90, 84, 82, 75, 71, 57, 55, 53, 51, 51, 43, 35, 31, 30, 29, 22, 18, 14, 10, 7, 5, 4], \"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 ] }
291
Maximum Area Rectangle Picking Four Sides Array 1
C++
int maximumAreaRectanglePickingFourSidesArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_area_rectangle_picking_four_sides_array_1(arr, n): s = [] first = 0 second = 0 for i in range(n): if (arr[i] not in s): s.append(arr[i]) continue if (arr[i] > first): second = first first = arr[i] elif (arr[i] > second): second = arr[i] return (first * second)
int maximum_area_rectangle_picking_four_sides_array_1(vector<int> arr, int n) { unordered_set < int > s; int first = 0, second = 0; for ( int i = 0; i < n; i ++ ) { if ( s . find ( arr [ i ] ) == s . end ( ) ) { s . insert ( arr [ i ] ); continue; } if ( arr [ i ] > first ) { second = first; first = arr [ i ]; } else if ( arr [ i ] > second ) second = arr [ i ]; } return ( first * second ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 6, 7, 8, 12, 13, 14, 15, 18, 18, 19, 19, 26, 26, 32, 32, 33, 34, 34, 36, 41, 43, 47, 47, 51, 51, 52, 53, 55, 56, 57, 60, 61, 71, 74, 75, 76, 77, 79, 87, 87, 87, 90, 95, 98, 99}, 37, 2397); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-64, -72, 6, -62, 54, 14, 28, 60, -96, 14, -32, -2, 80, 8, -56, 68, 86, 64, 86, -12, 82}, 12, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 7, 14, 50, 94, 24, 79, 13, 19, 29, 22, 2, 77, 36, 38, 18, 51, 15, 99, 52, 17, 77, 22, 54}, 15, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -86, -84, -84, -80, -70, -70, -68, -64, -64, -48, -46, -24, -22, -20, -8, -8, 0, 0, 4, 8, 8, 22, 28, 36, 46, 50, 52, 54, 60, 62, 66, 70, 80, 84, 86, 94, 96, 96}, 25, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1}, 12, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98}, 0, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -24, 8, 20, -46, 60, 24, 26, 98, 82, -30, 16, 22, -28, 84, 12, 34, 14, -18, -38, -94, -24, 6, 4, -52, -48, 84}, 21, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 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({6, 30, 47, 97, 20, 16, 68, 34, 1, 77, 48, 8, 22, 68}, 8, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumAreaRectanglePickingFourSidesArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2397, \"inputs\": {\"arr\": [4, 6, 7, 8, 12, 13, 14, 15, 18, 18, 19, 19, 26, 26, 32, 32, 33, 34, 34, 36, 41, 43, 47, 47, 51, 51, 52, 53, 55, 56, 57, 60, 61, 71, 74, 75, 76, 77, 79, 87, 87, 87, 90, 95, 98, 99], \"n\": 37}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-64, -72, 6, -62, 54, 14, 28, 60, -96, 14, -32, -2, 80, 8, -56, 68, 86, 64, 86, -12, 82], \"n\": 12}}, {\"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], \"n\": 27}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [99, 7, 14, 50, 94, 24, 79, 13, 19, 29, 22, 2, 77, 36, 38, 18, 51, 15, 99, 52, 17, 77, 22, 54], \"n\": 15}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-96, -92, -86, -84, -84, -80, -70, -70, -68, -64, -64, -48, -46, -24, -22, -20, -8, -8, 0, 0, 4, 8, 8, 22, 28, 36, 46, 50, 52, 54, 60, 62, 66, 70, 80, 84, 86, 94, 96, 96], \"n\": 25}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1], \"n\": 12}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [98], \"n\": 0}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-88, -24, 8, 20, -46, 60, 24, 26, 98, 82, -30, 16, 22, -28, 84, 12, 34, 14, -18, -38, -94, -24, 6, 4, -52, -48, 84], \"n\": 21}}, {\"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, 1], \"n\": 21}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [6, 30, 47, 97, 20, 16, 68, 34, 1, 77, 48, 8, 22, 68], \"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 ] }
292
Maximum Average Sum Partition Array
C++
int maximumAverageSumPartitionArray(vector<int> a, int k) {
[ "a", "k" ]
def maximum_average_sum_partition_array(A, K): n = len(A) pre_sum = ([0] * (n + 1)) pre_sum[0] = 0 for i in range(n): pre_sum[(i + 1)] = (pre_sum[i] + A[i]) dp = ([0] * n) sum = 0 for i in range(n): dp[i] = ((pre_sum[n] - pre_sum[i]) / (n - i)) for k in range((K - 1)): for i in range(n): for j in range((i + 1), n): dp[i] = max(dp[i], (((pre_sum[j] - pre_sum[i]) / (j - i)) + dp[j])) return int(dp[0])
double maximum_average_sum_partition_array(vector < int > & A, int K) { int n = A . size ( ); double pre_sum [ n + 1 ]; pre_sum [ 0 ] = 0; for ( int i = 0; i < n; i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ]; double dp [ n ] = { 0 }; double sum = 0; for ( int i = 0; i < n; i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ); for ( int k = 0; k < K - 1; k ++ ) for ( int i = 0; i < n; i ++ ) for ( int j = i + 1; j < n; j ++ ) dp [ i ] = max ( dp [ i ], ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ); return dp [ 0 ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, 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, 11, 14, 27, 32, 37, 39, 49, 52, 53, 57, 62, 67, 67, 68, 69, 76, 77, 78, 81, 85, 85, 87, 91, 91, 91, 99, 99, 99}, 24, 1742); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, 12, 32, 44, 24, 82, -40, 42, 26, 36, 58, 52, -34, 44, 12, -18, -72, 52, 2, -8, 22, -18, 98, -60, 62, 92, -46, 20, 20, -46, 52, 94, 0, -28, -22, 80, 26, -92, -50, 48, -80}, 26, 856); \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}, 15, 11); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32, 16, 67, 53, 99, 56, 80, 92, 84, 21, 36, 46, 94, 31, 63, 67, 59, 88, 41, 17, 74, 47, 95, 12, 27, 99, 32, 4, 82, 31, 65, 40, 93, 72, 23, 33, 93, 9, 62, 47}, 36, 2092); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -86, -80, -78, -72, -70, -70, -68, -66, -62, -60, -54, -54, -52, -52, -40, -36, -32, -28, -26, -22, -22, -20, -16, -16, -8, 0, 6, 8, 10, 14, 18, 20, 42, 46, 52, 60, 66, 68, 70, 74, 86, 88, 88, 92, 94, 98}, 36, 1052); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0}, 16, 10); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 3, 3, 6, 7, 10, 11, 12, 13, 16, 16, 22, 23, 24, 27, 28, 30, 30, 30, 31, 33, 35, 35, 39, 40, 41, 52, 52, 58, 59, 60, 61, 61, 66, 66, 71, 73, 74, 75, 75, 76, 80, 83, 85, 95, 96, 97, 97}, 34, 1996); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, -52, 48, 96, 54, 94, 60, 18}, 7, 358); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 31, 22); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({26, 80, 12, 87, 90, 98, 46, 91, 38, 46, 20, 64, 53, 4, 60, 87, 44, 88, 22, 30}, 19, 1060); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumAverageSumPartitionArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1742, \"inputs\": {\"a\": [4, 11, 14, 27, 32, 37, 39, 49, 52, 53, 57, 62, 67, 67, 68, 69, 76, 77, 78, 81, 85, 85, 87, 91, 91, 91, 99, 99, 99], \"k\": 24}}, {\"idx\": 1, \"outputs\": 856, \"inputs\": {\"a\": [80, 12, 32, 44, 24, 82, -40, 42, 26, 36, 58, 52, -34, 44, 12, -18, -72, 52, 2, -8, 22, -18, 98, -60, 62, 92, -46, 20, 20, -46, 52, 94, 0, -28, -22, 80, 26, -92, -50, 48, -80], \"k\": 26}}, {\"idx\": 2, \"outputs\": 11, \"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], \"k\": 15}}, {\"idx\": 3, \"outputs\": 2092, \"inputs\": {\"a\": [32, 16, 67, 53, 99, 56, 80, 92, 84, 21, 36, 46, 94, 31, 63, 67, 59, 88, 41, 17, 74, 47, 95, 12, 27, 99, 32, 4, 82, 31, 65, 40, 93, 72, 23, 33, 93, 9, 62, 47], \"k\": 36}}, {\"idx\": 4, \"outputs\": 1052, \"inputs\": {\"a\": [-92, -86, -80, -78, -72, -70, -70, -68, -66, -62, -60, -54, -54, -52, -52, -40, -36, -32, -28, -26, -22, -22, -20, -16, -16, -8, 0, 6, 8, 10, 14, 18, 20, 42, 46, 52, 60, 66, 68, 70, 74, 86, 88, 88, 92, 94, 98], \"k\": 36}}, {\"idx\": 5, \"outputs\": 10, \"inputs\": {\"a\": [1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0], \"k\": 16}}, {\"idx\": 6, \"outputs\": 1996, \"inputs\": {\"a\": [1, 1, 3, 3, 6, 7, 10, 11, 12, 13, 16, 16, 22, 23, 24, 27, 28, 30, 30, 30, 31, 33, 35, 35, 39, 40, 41, 52, 52, 58, 59, 60, 61, 61, 66, 66, 71, 73, 74, 75, 75, 76, 80, 83, 85, 95, 96, 97, 97], \"k\": 34}}, {\"idx\": 7, \"outputs\": 358, \"inputs\": {\"a\": [28, -52, 48, 96, 54, 94, 60, 18], \"k\": 7}}, {\"idx\": 8, \"outputs\": 22, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"k\": 31}}, {\"idx\": 9, \"outputs\": 1060, \"inputs\": {\"a\": [26, 80, 12, 87, 90, 98, 46, 91, 38, 46, 20, 64, 53, 4, 60, 87, 44, 88, 22, 30], \"k\": 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 ] }
293
Maximum Binomial Coefficient Term Value
C++
long long maximumBinomialCoefficientTermValue(int n) {
[ "n" ]
def maximum_binomial_coefficient_term_value(n): C = [[0 for x in range((n + 1))] for y in range((n + 1))] for i in range((n + 1)): for j in range((min(i, n) + 1)): if ((j == 0) or (j == i)): C[i][j] = 1 else: C[i][j] = (C[(i - 1)][(j - 1)] + C[(i - 1)][j]) maxvalue = 0 for i in range((n + 1)): maxvalue = max(maxvalue, C[n][i]) return maxvalue
int maximum_binomial_coefficient_term_value(int n) { int C [ n + 1 ] [ n + 1 ]; for ( int i = 0; i <= n; i ++ ) { for ( int j = 0; j <= min ( i, n ); j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]; } } int maxvalue = 0; for ( int i = 0; i <= n; i ++ ) maxvalue = max ( maxvalue, C [ n ] [ i ] ); return maxvalue; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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(23, 1352078); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 269128937220); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 7648690600760440); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 35345263800); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 10400600); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 495918532948104); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 2104098963720); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumBinomialCoefficientTermValue", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1352078, \"inputs\": {\"n\": 23}}, {\"idx\": 1, \"outputs\": 269128937220, \"inputs\": {\"n\": 41}}, {\"idx\": 2, \"outputs\": 7648690600760440, \"inputs\": {\"n\": 56}}, {\"idx\": 3, \"outputs\": 35345263800, \"inputs\": {\"n\": 38}}, {\"idx\": 4, \"outputs\": 10400600, \"inputs\": {\"n\": 26}}, {\"idx\": 5, \"outputs\": 495918532948104, \"inputs\": {\"n\": 52}}, {\"idx\": 6, \"outputs\": 2104098963720, \"inputs\": {\"n\": 44}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
294
Maximum Consecutive Numbers Present Array
C++
int maximumConsecutiveNumbersPresentArray(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_consecutive_numbers_present_array(arr, n): S = set() for i in range(n): S.add(arr[i]) ans = 0 for i in range(n): if S.__contains__(arr[i]): j = arr[i] while S.__contains__(j): j += 1 ans = max(ans, (j - arr[i])) return ans
int maximum_consecutive_numbers_present_array(vector<int> arr, int n) { unordered_set < int > S; for ( int i = 0; i < n; i ++ ) S . insert ( arr [ i ] ); int ans = 0; for ( int i = 0; i < n; i ++ ) { if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) { int j = arr [ i ]; while ( S . find ( j ) != S . end ( ) ) j ++; ans = max ( ans, j - arr [ i ] ); } } return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({3, 5, 9, 24, 28, 31, 49, 54, 67, 85, 86, 94, 97, 97}, 11, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-34, 16, -80, -10, 80, 2, 50, -74, -76, 36, -84, -24, 74, -54, -22, 46, 80, 58, -8, 70, 24, -88, 52, 62, 30, 42, 48, 16, 78, -82, 64, -36, 84, -72}, 29, 1); \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}, 13, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({49, 61, 68, 4, 90, 89, 71, 74, 45, 61, 35, 41, 59}, 11, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-42, -8, 28, 56, 80, 96}, 4, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1}, 17, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 6, 6, 13, 27, 27, 29, 32, 36, 46, 50, 52, 65, 69, 70, 71, 83, 87, 91}, 10, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({64, -76, 28, 6, 56, 18, 32, -50, -20, 18, -26, -90, 32, 50, -18, 98, 84, 40, 50, 88, -70, -6, -24, -44, -96, -58, 48, -78, -14}, 15, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 48, 61, 87, 7, 78, 93, 44, 16, 88, 98, 15, 73, 93, 43, 46, 42, 34, 1, 35, 79, 35, 84, 60, 18, 79, 17, 4, 78, 1, 20, 64}, 25, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumConsecutiveNumbersPresentArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [3, 5, 9, 24, 28, 31, 49, 54, 67, 85, 86, 94, 97, 97], \"n\": 11}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [-34, 16, -80, -10, 80, 2, 50, -74, -76, 36, -84, -24, 74, -54, -22, 46, 80, 58, -8, 70, 24, -88, 52, 62, 30, 42, 48, 16, 78, -82, 64, -36, 84, -72], \"n\": 29}}, {\"idx\": 2, \"outputs\": 2, \"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}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"arr\": [49, 61, 68, 4, 90, 89, 71, 74, 45, 61, 35, 41, 59], \"n\": 11}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-42, -8, 28, 56, 80, 96], \"n\": 4}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr\": [1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1], \"n\": 17}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"arr\": [3, 4, 6, 6, 13, 27, 27, 29, 32, 36, 46, 50, 52, 65, 69, 70, 71, 83, 87, 91], \"n\": 10}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [64, -76, 28, 6, 56, 18, 32, -50, -20, 18, -26, -90, 32, 50, -18, 98, 84, 40, 50, 88, -70, -6, -24, -44, -96, -58, 48, -78, -14], \"n\": 15}}, {\"idx\": 8, \"outputs\": 1, \"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], \"n\": 15}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"arr\": [50, 48, 61, 87, 7, 78, 93, 44, 16, 88, 98, 15, 73, 93, 43, 46, 42, 34, 1, 35, 79, 35, 84, 60, 18, 79, 17, 4, 78, 1, 20, 64], \"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 ] }
297
Maximum Distance Two Occurrences Element Array
C++
int maximumDistanceTwoOccurrencesElementArray(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_distance_two_occurrences_element_array(arr, n): mp = { } maxDict = 0 for i in range(n): if (arr[i] not in mp.keys()): mp[arr[i]] = i else: maxDict = max(maxDict, (i - mp[arr[i]])) return maxDict
int maximum_distance_two_occurrences_element_array(vector<int> arr, int n) { unordered_map < int, int > mp; int max_dist = 0; for ( int i = 0; i < n; i ++ ) { if ( mp . find ( arr [ i ] ) == mp . end ( ) ) mp [ arr [ i ] ] = i; else max_dist = max ( max_dist, i - mp [ arr [ i ] ] ); } return max_dist; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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, 20, 25, 28, 29, 31, 34, 35, 38, 39, 41, 43, 46, 55, 56, 60, 65, 66, 74, 77, 79, 80, 81, 83, 84, 88, 88, 88, 90, 91, 99}, 27, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({26, 14, 56, 84, -56, -84, -98, 12, -78, 18, -42, 58, 46, -66, -46, 66, 98, 34, -16, 8, -20, 66, 74, 26, 42, -84, 38, 86, 14, 86, 26, -42, -30, 6, -54, -76, -66, 18, 58, 66, 74, -62, 8, -42, 62, -14, -90, 98, -24}, 34, 30); \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}, 11, 10); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({69, 87}, 1, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -88, -86, -62, -52, -26, -24, -20, -12, 6, 8, 26, 36, 40, 42, 54, 68, 72, 84, 92, 94, 98, 98}, 12, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0}, 29, 28); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 16, 17, 19, 20, 21, 21, 22, 27, 37, 45, 49, 64, 77, 81, 85, 96}, 9, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-20, 0, 18, -96}, 2, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 20); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({54, 5, 98, 71, 9, 34, 60, 28, 58, 66, 28, 45, 4}, 10, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumDistanceTwoOccurrencesElementArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [1, 20, 25, 28, 29, 31, 34, 35, 38, 39, 41, 43, 46, 55, 56, 60, 65, 66, 74, 77, 79, 80, 81, 83, 84, 88, 88, 88, 90, 91, 99], \"n\": 27}}, {\"idx\": 1, \"outputs\": 30, \"inputs\": {\"arr\": [26, 14, 56, 84, -56, -84, -98, 12, -78, 18, -42, 58, 46, -66, -46, 66, 98, 34, -16, 8, -20, 66, 74, 26, 42, -84, 38, 86, 14, 86, 26, -42, -30, 6, -54, -76, -66, 18, 58, 66, 74, -62, 8, -42, 62, -14, -90, 98, -24], \"n\": 34}}, {\"idx\": 2, \"outputs\": 10, \"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\": 11}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [69, 87], \"n\": 1}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-98, -88, -86, -62, -52, -26, -24, -20, -12, 6, 8, 26, 36, 40, 42, 54, 68, 72, 84, 92, 94, 98, 98], \"n\": 12}}, {\"idx\": 5, \"outputs\": 28, \"inputs\": {\"arr\": [1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0], \"n\": 29}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [11, 16, 17, 19, 20, 21, 21, 22, 27, 37, 45, 49, 64, 77, 81, 85, 96], \"n\": 9}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-20, 0, 18, -96], \"n\": 2}}, {\"idx\": 8, \"outputs\": 20, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 22}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [54, 5, 98, 71, 9, 34, 60, 28, 58, 66, 28, 45, 4], \"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 ] }
298
Maximum Equlibrium Sum Array
C++
int maximumEqulibriumSumArray(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_equlibrium_sum_array(arr, n): res = ((- sys.maxsize) - 1) for i in range(n): prefix_sum = arr[i] for j in range(i): prefix_sum += arr[j] suffix_sum = arr[i] j = (n - 1) while (j > i): suffix_sum += arr[j] j -= 1 if (prefix_sum == suffix_sum): res = max(res, prefix_sum) return res
int maximum_equlibrium_sum_array(vector<int> arr, int n) { int res = INT_MIN; for ( int i = 0; i < n; i ++ ) { int prefix_sum = arr [ i ]; for ( int j = 0; j < i; j ++ ) prefix_sum += arr [ j ]; int suffix_sum = arr [ i ]; for ( int j = n - 1; j > i; j -- ) suffix_sum += arr [ j ]; if ( prefix_sum == suffix_sum ) res = max ( res, prefix_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({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 19, 5); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0}, 38, 9); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumEqulibriumSumArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 5, \"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], \"n\": 19}}, {\"idx\": 1, \"outputs\": 9, \"inputs\": {\"arr\": [0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0], \"n\": 38}}]", "test_case_ids": [ "0", "1" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
299
Maximum Games Played Winner
C++
int maximumGamesPlayedWinner(int n) {
[ "n" ]
def maximum_games_played_winner(N): dp = [0 for i in range(N)] dp[0] = 1 dp[1] = 2 i = 1 while (dp[i] <= N): i = (i + 1) dp[i] = (dp[(i - 1)] + dp[(i - 2)]) return (i - 1)
int maximum_games_played_winner(int N) { int dp [ N ]; dp [ 0 ] = 1; dp [ 1 ] = 2; int i = 2; do { dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]; } while ( dp [ i ++ ] <= N ); return ( i - 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(73, 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 6); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 6); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 6); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 7); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 7); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 7); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumGamesPlayedWinner", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"n\": 73}}, {\"idx\": 1, \"outputs\": 6, \"inputs\": {\"n\": 28}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"n\": 33}}, {\"idx\": 3, \"outputs\": 6, \"inputs\": {\"n\": 23}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"n\": 84}}, {\"idx\": 5, \"outputs\": 6, \"inputs\": {\"n\": 31}}, {\"idx\": 6, \"outputs\": 7, \"inputs\": {\"n\": 48}}, {\"idx\": 7, \"outputs\": 7, \"inputs\": {\"n\": 46}}, {\"idx\": 8, \"outputs\": 7, \"inputs\": {\"n\": 45}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"n\": 90}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
300
Maximum Height Of Triangular Arrangement Of Array Values
C++
int maximumHeightOfTriangularArrangementOfArrayValues(vector<int> a, int n) {
[ "a", "n" ]
def maximum_height_of_triangular_arrangement_of_array_values(a, n): result = 1 for i in range(1, n): y = ((i * (i + 1)) / 2) if (y < n): result = i else: break return result
int maximum_height_of_triangular_arrangement_of_array_values(vector<int> a, int n) { int result = 1; for ( int i = 1; i <= n; ++ i ) { long long y = ( i * ( i + 1 ) ) / 2; if ( y < n ) result = i; else break; } return result; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> 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({8, 10, 11, 14, 14, 17, 20, 20, 22, 22, 22, 23, 25, 30, 33, 39, 39, 41, 43, 45, 46, 46, 46, 50, 51, 53, 57, 59, 60, 64, 64, 66, 72, 72, 75, 77, 85, 85, 87, 88, 90, 91, 93, 94, 94, 95}, 38, 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-44, -90, 20, 4, -56, -50, -80, 74, -82, 20, 62, -26, -10, -14, -76, 82, -88, 92, 30, 44, -62, -86, -20, -96, -60, -88, -78, -40, -48, -92, 62, 58, 94, 68, 68, 44, 80, 4, 48, -92, 30, -76, -46, -20, 4}, 36, 7); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 28, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 34, 48, 10, 5, 12, 80, 7, 67, 1, 79, 59, 63, 13, 16, 23, 62, 56, 99, 89, 7, 80}, 12, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -46, -40, -40, 38}, 3, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1}, 44, 8); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 15, 35, 39, 49, 81, 86, 91}, 7, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-24, 56, -74, -76, -80, 86, 90, 0, -26, 18, 72, 78, -66, -28, 22, 22, 72, 78, -50, -12, 20, 12, -68, -2, -58, -44, 28, -58, 90, -28, 32, -70, -48, -66, -94, -50, 18, -12, 80, 12, 82, 56, -64, 10, -22}, 36, 7); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0}, 1, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({62, 93, 69, 40, 26, 2, 29, 83, 66, 68, 67, 73, 12, 65, 89, 57, 38, 99, 42, 27, 38, 24, 43, 4, 4, 54, 72, 47, 52, 46, 53, 24, 3, 41, 64, 33, 88, 3, 1, 7, 17, 31, 20, 33, 69, 21, 9, 24, 59}, 26, 6); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumHeightOfTriangularArrangementOfArrayValues", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"a\": [8, 10, 11, 14, 14, 17, 20, 20, 22, 22, 22, 23, 25, 30, 33, 39, 39, 41, 43, 45, 46, 46, 46, 50, 51, 53, 57, 59, 60, 64, 64, 66, 72, 72, 75, 77, 85, 85, 87, 88, 90, 91, 93, 94, 94, 95], \"n\": 38}}, {\"idx\": 1, \"outputs\": 7, \"inputs\": {\"a\": [-44, -90, 20, 4, -56, -50, -80, 74, -82, 20, 62, -26, -10, -14, -76, 82, -88, 92, 30, 44, -62, -86, -20, -96, -60, -88, -78, -40, -48, -92, 62, 58, 94, 68, 68, 44, 80, 4, 48, -92, 30, -76, -46, -20, 4], \"n\": 36}}, {\"idx\": 2, \"outputs\": 6, \"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, 1, 1], \"n\": 28}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"a\": [8, 34, 48, 10, 5, 12, 80, 7, 67, 1, 79, 59, 63, 13, 16, 23, 62, 56, 99, 89, 7, 80], \"n\": 12}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"a\": [-88, -46, -40, -40, 38], \"n\": 3}}, {\"idx\": 5, \"outputs\": 8, \"inputs\": {\"a\": [1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1], \"n\": 44}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"a\": [8, 15, 35, 39, 49, 81, 86, 91], \"n\": 7}}, {\"idx\": 7, \"outputs\": 7, \"inputs\": {\"a\": [-24, 56, -74, -76, -80, 86, 90, 0, -26, 18, 72, 78, -66, -28, 22, 22, 72, 78, -50, -12, 20, 12, -68, -2, -58, -44, 28, -58, 90, -28, 32, -70, -48, -66, -94, -50, 18, -12, 80, 12, 82, 56, -64, 10, -22], \"n\": 36}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"a\": [0, 0], \"n\": 1}}, {\"idx\": 9, \"outputs\": 6, \"inputs\": {\"a\": [62, 93, 69, 40, 26, 2, 29, 83, 66, 68, 67, 73, 12, 65, 89, 57, 38, 99, 42, 27, 38, 24, 43, 4, 4, 54, 72, 47, 52, 46, 53, 24, 3, 41, 64, 33, 88, 3, 1, 7, 17, 31, 20, 33, 69, 21, 9, 24, 59], \"n\": 26}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
301
Maximum Height Of Triangular Arrangement Of Array Values 1
C++
int maximumHeightOfTriangularArrangementOfArrayValues1(vector<int> a, int n) {
[ "a", "n" ]
def maximum_height_of_triangular_arrangement_of_array_values_1(a, n): return (((- 1) + int(math.sqrt((1 + (8 * n))))) // 2)
int maximum_height_of_triangular_arrangement_of_array_values_1(vector<int> a, int n) { return floor ( ( - 1 + sqrt ( 1 + ( 8 * 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(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, 2, 3, 5, 6, 7, 8, 8, 12, 15, 16, 18, 18, 20, 21, 21, 22, 22, 24, 24, 25, 30, 35, 42, 49, 52, 55, 55, 63, 68, 70, 72, 73, 77, 80, 83, 87, 87, 88, 88, 94, 95, 97}, 22, 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({48, -72, 84, -24, 28, 94, 36, 28, 32, 66, -62, 64, 6, -68, -12, 46, 4, 98, 18, 86, -60, 76, 14, 98}, 12, 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, 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, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 16, 84, 8, 86, 44, 79, 11, 73, 12, 29, 62, 22, 44, 28, 8, 48, 92, 73, 63, 59, 44, 95, 66}, 14, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -94, -92, -88, -86, -82, -80, -80, -78, -76, -56, -56, -50, -44, -42, -36, -36, -32, -32, -26, -14, -12, -6, 12, 24, 28, 34, 38, 42, 42, 46, 50, 56, 62, 62, 74, 84, 92, 94}, 19, 5); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0}, 24, 6); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 3, 3, 3, 4, 5, 13, 16, 18, 21, 22, 27, 28, 32, 34, 36, 37, 41, 42, 43, 51, 52, 52, 54, 54, 61, 65, 67, 67, 68, 71, 75, 77, 77, 78, 80, 81, 81, 84, 86, 90, 90, 93, 93, 94, 99, 99}, 31, 7); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({54, -86}, 1, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 54, 49, 80, 56, 62, 31, 49, 60, 19, 45, 94, 33, 46, 32}, 8, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumHeightOfTriangularArrangementOfArrayValues1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"a\": [1, 2, 2, 3, 5, 6, 7, 8, 8, 12, 15, 16, 18, 18, 20, 21, 21, 22, 22, 24, 24, 25, 30, 35, 42, 49, 52, 55, 55, 63, 68, 70, 72, 73, 77, 80, 83, 87, 87, 88, 88, 94, 95, 97], \"n\": 22}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"a\": [48, -72, 84, -24, 28, 94, 36, 28, 32, 66, -62, 64, 6, -68, -12, 46, 4, 98, 18, 86, -60, 76, 14, 98], \"n\": 12}}, {\"idx\": 2, \"outputs\": 6, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 25}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"a\": [11, 16, 84, 8, 86, 44, 79, 11, 73, 12, 29, 62, 22, 44, 28, 8, 48, 92, 73, 63, 59, 44, 95, 66], \"n\": 14}}, {\"idx\": 4, \"outputs\": 5, \"inputs\": {\"a\": [-94, -94, -92, -88, -86, -82, -80, -80, -78, -76, -56, -56, -50, -44, -42, -36, -36, -32, -32, -26, -14, -12, -6, 12, 24, 28, 34, 38, 42, 42, 46, 50, 56, 62, 62, 74, 84, 92, 94], \"n\": 19}}, {\"idx\": 5, \"outputs\": 6, \"inputs\": {\"a\": [0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0], \"n\": 24}}, {\"idx\": 6, \"outputs\": 7, \"inputs\": {\"a\": [2, 2, 3, 3, 3, 4, 5, 13, 16, 18, 21, 22, 27, 28, 32, 34, 36, 37, 41, 42, 43, 51, 52, 52, 54, 54, 61, 65, 67, 67, 68, 71, 75, 77, 77, 78, 80, 81, 81, 84, 86, 90, 90, 93, 93, 94, 99, 99], \"n\": 31}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"a\": [54, -86], \"n\": 1}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"a\": [0, 1], \"n\": 1}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"a\": [5, 54, 49, 80, 56, 62, 31, 49, 60, 19, 45, 94, 33, 46, 32], \"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 ] }
303
Maximum Length Subsequence Difference Adjacent Elements Either 0 1
C++
int maximumLengthSubsequenceDifferenceAdjacentElementsEither01(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_length_subsequence_difference_adjacent_elements_either_0_1(arr, n): mls = [] max = 0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if ((abs((arr[i] - arr[j])) <= 1) and (mls[i] < (mls[j] + 1))): mls[i] = (mls[j] + 1) for i in range(n): if (max < mls[i]): max = mls[i] return max
int maximum_length_subsequence_difference_adjacent_elements_either_0_1(vector<int> arr, int n) { int mls [ n ], max = 0; for ( int i = 0; i < n; i ++ ) mls [ i ] = 1; for ( int i = 1; i < n; i ++ ) for ( int j = 0; j < i; j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1; for ( int i = 0; i < n; i ++ ) if ( max < mls [ i ] ) max = mls [ i ]; return 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, 5, 9, 31, 31, 37, 41, 55, 56, 61, 79, 81, 89, 93}, 12, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-76, 96, -68, -16, 22, -24, -24, 6, 98, -82, 54, -80, 46, 0, 0, -50}, 15, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 29, 29); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({97, 93, 43, 51, 15, 33, 13, 96, 39, 89, 78, 25, 45, 6, 64, 54}, 13, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -78, -72, -70, -68, -58, -56, -54, -46, -44, -38, -34, -30, -24, -18, -16, -14, -12, 2, 6, 8, 8, 10, 10, 16, 24, 26, 28, 40, 42, 44, 56, 58, 62, 66, 66, 78, 86}, 19, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 0, 0}, 3, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 8, 10, 11, 12, 15, 16, 16, 19, 21, 23, 23, 23, 25, 26, 35, 38, 43, 46, 47, 51, 52, 53, 57, 60, 61, 66, 67, 69, 74, 75, 81, 83, 84, 88, 92, 94, 98, 98, 99}, 34, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, -40}, 1, 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, 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}, 38, 38); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({59, 70, 53}, 1, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumLengthSubsequenceDifferenceAdjacentElementsEither01", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"arr\": [4, 5, 9, 31, 31, 37, 41, 55, 56, 61, 79, 81, 89, 93], \"n\": 12}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"arr\": [-76, 96, -68, -16, 22, -24, -24, 6, 98, -82, 54, -80, 46, 0, 0, -50], \"n\": 15}}, {\"idx\": 2, \"outputs\": 29, \"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], \"n\": 29}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"arr\": [97, 93, 43, 51, 15, 33, 13, 96, 39, 89, 78, 25, 45, 6, 64, 54], \"n\": 13}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-98, -78, -72, -70, -68, -58, -56, -54, -46, -44, -38, -34, -30, -24, -18, -16, -14, -12, 2, 6, 8, 8, 10, 10, 16, 24, 26, 28, 40, 42, 44, 56, 58, 62, 66, 66, 78, 86], \"n\": 19}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"arr\": [1, 1, 0, 1, 0, 0], \"n\": 3}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"arr\": [7, 8, 10, 11, 12, 15, 16, 16, 19, 21, 23, 23, 23, 25, 26, 35, 38, 43, 46, 47, 51, 52, 53, 57, 60, 61, 66, 67, 69, 74, 75, 81, 83, 84, 88, 92, 94, 98, 98, 99], \"n\": 34}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [14, -40], \"n\": 1}}, {\"idx\": 8, \"outputs\": 38, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 38}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [59, 70, 53], \"n\": 1}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
304
Maximum Number 2X2 Squares Can Fit Inside Right Isosceles Triangle
C++
float maximumNumber2X2SquaresCanFitInsideRightIsoscelesTriangle(int base_arg0) {
[ "base_arg0" ]
def maximum_number_2x2_squares_can_fit_inside_right_isosceles_triangle(base): base = (base - 2) base = (base / 2) return ((base * (base + 1)) / 2)
int maximum_number_2x2_squares_can_fit_inside_right_isosceles_triangle(int base) { base = ( base - 2 ); base = base / 2; return base * ( base + 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(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int base_arg0, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(base_arg0), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(95, 1104.375); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 287.875); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 10.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 647.875); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 666.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 190.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 10.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 1081.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 496.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 28.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumNumber2X2SquaresCanFitInsideRightIsoscelesTriangle", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1104.375, \"inputs\": {\"base_arg0\": 95}}, {\"idx\": 1, \"outputs\": 287.875, \"inputs\": {\"base_arg0\": 49}}, {\"idx\": 2, \"outputs\": 10.0, \"inputs\": {\"base_arg0\": 10}}, {\"idx\": 3, \"outputs\": 647.875, \"inputs\": {\"base_arg0\": 73}}, {\"idx\": 4, \"outputs\": 666.0, \"inputs\": {\"base_arg0\": 74}}, {\"idx\": 5, \"outputs\": 190.0, \"inputs\": {\"base_arg0\": 40}}, {\"idx\": 6, \"outputs\": 10.0, \"inputs\": {\"base_arg0\": 10}}, {\"idx\": 7, \"outputs\": 1081.0, \"inputs\": {\"base_arg0\": 94}}, {\"idx\": 8, \"outputs\": 496.0, \"inputs\": {\"base_arg0\": 64}}, {\"idx\": 9, \"outputs\": 28.0, \"inputs\": {\"base_arg0\": 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 ] }
305
Maximum Number Characters Two Character String
C++
int maximumNumberCharactersTwoCharacterString(string str) {
[ "str" ]
def maximum_number_characters_two_character_string(str): n = len(str) res = (- 1) for i in range(0, (n - 1)): for j in range((i + 1), n): if (str[i] == str[j]): res = max(res, abs(((j - i) - 1))) return res
int maximum_number_characters_two_character_string(string & str) { int n = str . length ( ); int res = - 1; for ( int i = 0; i < n - 1; i ++ ) for ( int j = i + 1; j < n; j ++ ) if ( str [ i ] == str [ j ] ) res = max ( res, abs ( j - i - 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(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(\"cI\", -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"76478\", 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"tr\", -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10\", -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01\", -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Rmhzp\", -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"5784080133917\", 10); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1100\", 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"OK\", -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumNumberCharactersTwoCharacterString", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"str\": \"cI\"}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"str\": \"76478\"}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"str\": \"1\"}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"str\": \"tr\"}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"str\": \"10\"}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"str\": \"01\"}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"str\": \"Rmhzp\"}}, {\"idx\": 7, \"outputs\": 10, \"inputs\": {\"str\": \"5784080133917\"}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"str\": \"1100\"}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"str\": \"OK\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
306
Maximum Number Chocolates Distributed Equally Among K Students
C++
int maximumNumberChocolatesDistributedEquallyAmongKStudents(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def maximum_number_chocolates_distributed_equally_among_k_students(arr, n, k): (um, curr_rem, maxSum) = ({ }, 0, 0) sm = ([0] * n) sm[0] = arr[0] for i in range(1, n): sm[i] = (sm[(i - 1)] + arr[i]) for i in range(n): curr_rem = (sm[i] % k) if ((not curr_rem) and (maxSum < sm[i])): maxSum = sm[i] elif (not (curr_rem in um)): um[curr_rem] = i elif (maxSum < (sm[i] - sm[um[curr_rem]])): maxSum = (sm[i] - sm[um[curr_rem]]) return (maxSum // k)
int maximum_number_chocolates_distributed_equally_among_k_students(vector<int> arr, int n, int k) { unordered_map < int, int > um; int sum [ n ], curr_rem; int maxSum = 0; sum [ 0 ] = arr [ 0 ]; for ( int i = 1; i < n; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ]; for ( int i = 0; i < n; i ++ ) { curr_rem = sum [ i ] % k; if ( curr_rem == 0 ) { if ( maxSum < sum [ i ] ) maxSum = sum [ i ]; } else if ( um . find ( curr_rem ) == um . end ( ) ) um [ curr_rem ] = i; else if ( maxSum < ( sum [ i ] - sum [ um [ curr_rem ] ] ) ) maxSum = sum [ i ] - sum [ um [ curr_rem ] ]; } return ( maxSum / k ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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, 3, 8, 8, 12, 14, 23, 25, 25, 27, 27, 29, 40, 42, 49, 52, 52, 54, 56, 57, 61, 68, 74, 77, 81, 82, 83, 84, 85, 85, 85, 87, 87, 88, 88, 90, 92, 96, 96}, 27, 32, 29); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -34, 26, -20, -12, -42, 28, 12, -6, 58, -46, 4, -30, -28, -14}, 8, 14, 0); \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}, 7, 9, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58, 81, 36, 2, 51, 71, 77, 34, 91, 82, 47, 4, 91, 83, 26, 96, 3, 6}, 16, 12, 48); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -86, -82, -68, -60, -46, -40, -28, -26, -24, -2, -2, 2, 2, 10, 10, 10, 16, 16, 18, 20, 20, 22, 30, 34, 38, 56, 56, 60, 62, 62, 68, 82, 94, 94, 98}, 20, 31, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0}, 2, 2, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 8, 15, 19, 21, 26, 28, 31, 31, 42, 45, 48, 57, 75, 75, 78, 79, 85, 91, 99}, 17, 16, 36); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-38, 42, 40, -60, -16, -36, 44, 60, -86, -38, 30, -22, -30, -96, -66}, 12, 10, 6); \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}, 13, 16, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({95, 38, 91, 75, 43, 95, 23, 36, 51, 4, 38, 53, 52, 58, 55, 3, 19, 22, 84, 9}, 14, 19, 31); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumNumberChocolatesDistributedEquallyAmongKStudents", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 29, \"inputs\": {\"arr\": [2, 3, 8, 8, 12, 14, 23, 25, 25, 27, 27, 29, 40, 42, 49, 52, 52, 54, 56, 57, 61, 68, 74, 77, 81, 82, 83, 84, 85, 85, 85, 87, 87, 88, 88, 90, 92, 96, 96], \"n\": 27, \"k\": 32}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-90, -34, 26, -20, -12, -42, 28, 12, -6, 58, -46, 4, -30, -28, -14], \"n\": 8, \"k\": 14}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 7, \"k\": 9}}, {\"idx\": 3, \"outputs\": 48, \"inputs\": {\"arr\": [58, 81, 36, 2, 51, 71, 77, 34, 91, 82, 47, 4, 91, 83, 26, 96, 3, 6], \"n\": 16, \"k\": 12}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"arr\": [-92, -86, -82, -68, -60, -46, -40, -28, -26, -24, -2, -2, 2, 2, 10, 10, 10, 16, 16, 18, 20, 20, 22, 30, 34, 38, 56, 56, 60, 62, 62, 68, 82, 94, 94, 98], \"n\": 20, \"k\": 31}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 0], \"n\": 2, \"k\": 2}}, {\"idx\": 6, \"outputs\": 36, \"inputs\": {\"arr\": [3, 8, 15, 19, 21, 26, 28, 31, 31, 42, 45, 48, 57, 75, 75, 78, 79, 85, 91, 99], \"n\": 17, \"k\": 16}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"arr\": [-38, 42, 40, -60, -16, -36, 44, 60, -86, -38, 30, -22, -30, -96, -66], \"n\": 12, \"k\": 10}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13, \"k\": 16}}, {\"idx\": 9, \"outputs\": 31, \"inputs\": {\"arr\": [95, 38, 91, 75, 43, 95, 23, 36, 51, 4, 38, 53, 52, 58, 55, 3, 19, 22, 84, 9], \"n\": 14, \"k\": 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 ] }
307
Maximum Number Of Squares That Can Be Fit In A Right Angle Isosceles Triangle
C++
double maximumNumberOfSquaresThatCanBeFitInARightAngleIsoscelesTriangle(int b, int m) {
[ "b", "m" ]
def maximum_number_of_squares_that_can_be_fit_in_a_right_angle_isosceles_triangle(b, m): return ((((b / m) - 1) * (b / m)) / 2)
int maximum_number_of_squares_that_can_be_fit_in_a_right_angle_isosceles_triangle(int b, int m) { return ( b / m - 1 ) * ( b / m ) / 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 b, int m, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(b, 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(40, 74, -0.1241782322863404); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 35, 0.04653061224489791); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 71, -0.11188256298353501); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 29, 0.7110582639714625); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 9, 1.5555555555555558); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 33, 0.3902662993572084); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 82, -0.04402141582391434); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 80, -0.10500000000000001); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 5, 163.68000000000004); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 90, -0.08944444444444444); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumNumberOfSquaresThatCanBeFitInARightAngleIsoscelesTriangle", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -0.1241782322863404, \"inputs\": {\"b\": 40, \"m\": 74}}, {\"idx\": 1, \"outputs\": 0.04653061224489791, \"inputs\": {\"b\": 38, \"m\": 35}}, {\"idx\": 2, \"outputs\": -0.11188256298353501, \"inputs\": {\"b\": 47, \"m\": 71}}, {\"idx\": 3, \"outputs\": 0.7110582639714625, \"inputs\": {\"b\": 52, \"m\": 29}}, {\"idx\": 4, \"outputs\": 1.5555555555555558, \"inputs\": {\"b\": 21, \"m\": 9}}, {\"idx\": 5, \"outputs\": 0.3902662993572084, \"inputs\": {\"b\": 50, \"m\": 33}}, {\"idx\": 6, \"outputs\": -0.04402141582391434, \"inputs\": {\"b\": 8, \"m\": 82}}, {\"idx\": 7, \"outputs\": -0.10500000000000001, \"inputs\": {\"b\": 56, \"m\": 80}}, {\"idx\": 8, \"outputs\": 163.68000000000004, \"inputs\": {\"b\": 93, \"m\": 5}}, {\"idx\": 9, \"outputs\": -0.08944444444444444, \"inputs\": {\"b\": 21, \"m\": 90}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
308
Maximum Number Segments Lengths B C
C++
int maximumNumberSegmentsLengthsBC(int n, int a, int b, int c) {
[ "n", "a", "b", "c" ]
def maximum_number_segments_lengths_b_c(n, a, b, c): dp = ([(- 1)] * (n + 10)) dp[0] = 0 for i in range(0, n): if (dp[i] != (- 1)): if ((i + a) <= n): dp[(i + a)] = max((dp[i] + 1), dp[(i + a)]) if ((i + b) <= n): dp[(i + b)] = max((dp[i] + 1), dp[(i + b)]) if ((i + c) <= n): dp[(i + c)] = max((dp[i] + 1), dp[(i + c)]) return dp[n]
int maximum_number_segments_lengths_b_c(int n, int a, int b, int c) { int dp [ n + 1 ]; memset ( dp, - 1, sizeof ( dp ) ); dp [ 0 ] = 0; for ( int i = 0; i < n; i ++ ) { if ( dp [ i ] != - 1 ) { if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1, dp [ i + a ] ); if ( i + b <= n ) dp [ i + b ] = max ( dp [ i ] + 1, dp [ i + b ] ); if ( i + c <= n ) dp [ i + c ] = max ( dp [ i ] + 1, dp [ i + c ] ); } } 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 a, int b, int c, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, 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(23, 16, 23, 18, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 76, 81, 97, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 46, 1, 78, 32); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 48, 72, 58, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 99, 62, 38, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(44, 21, 46, 60, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 57, 2, 77, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 23, 80, 5, 7); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 55, 26, 85, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 15, 73, 42, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumNumberSegmentsLengthsBC", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"n\": 23, \"a\": 16, \"b\": 23, \"c\": 18}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"n\": 62, \"a\": 76, \"b\": 81, \"c\": 97}}, {\"idx\": 2, \"outputs\": 32, \"inputs\": {\"n\": 32, \"a\": 46, \"b\": 1, \"c\": 78}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"n\": 82, \"a\": 48, \"b\": 72, \"c\": 58}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"n\": 94, \"a\": 99, \"b\": 62, \"c\": 38}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"n\": 44, \"a\": 21, \"b\": 46, \"c\": 60}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"n\": 4, \"a\": 57, \"b\": 2, \"c\": 77}}, {\"idx\": 7, \"outputs\": 7, \"inputs\": {\"n\": 53, \"a\": 23, \"b\": 80, \"c\": 5}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"n\": 9, \"a\": 55, \"b\": 26, \"c\": 85}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"n\": 23, \"a\": 15, \"b\": 73, \"c\": 42}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
309
Maximum Points Intersection N Circles
C++
int maximumPointsIntersectionNCircles(int n) {
[ "n" ]
def maximum_points_intersection_n_circles(n): return (n * (n - 1))
int maximum_points_intersection_n_circles(int n) { return n * ( n - 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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(30, 870); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 600); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 4692); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 1482); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 182); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 3540); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 7832); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 702); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 812); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 812); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumPointsIntersectionNCircles", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 870, \"inputs\": {\"n\": 30}}, {\"idx\": 1, \"outputs\": 600, \"inputs\": {\"n\": 25}}, {\"idx\": 2, \"outputs\": 4692, \"inputs\": {\"n\": 69}}, {\"idx\": 3, \"outputs\": 1482, \"inputs\": {\"n\": 39}}, {\"idx\": 4, \"outputs\": 182, \"inputs\": {\"n\": 14}}, {\"idx\": 5, \"outputs\": 3540, \"inputs\": {\"n\": 60}}, {\"idx\": 6, \"outputs\": 7832, \"inputs\": {\"n\": 89}}, {\"idx\": 7, \"outputs\": 702, \"inputs\": {\"n\": 27}}, {\"idx\": 8, \"outputs\": 812, \"inputs\": {\"n\": 29}}, {\"idx\": 9, \"outputs\": 812, \"inputs\": {\"n\": 29}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
310
Maximum Possible Difference Two Subsets Array
C++
int maximumPossibleDifferenceTwoSubsetsArray(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_possible_difference_two_subsets_array(arr, n): SubsetSum_1 = 0 SubsetSum_2 = 0 for i in range(0, n): isSingleOccurance = True for j in range((i + 1), n): if (arr[i] == arr[j]): isSingleOccurance = False arr[i] = arr[j] = 0 break if (isSingleOccurance == True): if (arr[i] > 0): SubsetSum_1 += arr[i] else: SubsetSum_2 += arr[i] return abs((SubsetSum_1 - SubsetSum_2))
int maximum_possible_difference_two_subsets_array(vector<int> arr, int n) { int SubsetSum_1 = 0, SubsetSum_2 = 0; for ( int i = 0; i <= n - 1; i ++ ) { bool isSingleOccurance = true; for ( int j = i + 1; j <= n - 1; j ++ ) { if ( arr [ i ] == arr [ j ] ) { isSingleOccurance = false; arr [ i ] = arr [ j ] = 0; break; } } if ( isSingleOccurance ) { if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ]; else SubsetSum_2 += arr [ i ]; } } return abs ( SubsetSum_1 - SubsetSum_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(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, 14, 15, 21, 0, 0, 42, 0, 0, 0, 0, 48, 0, 0, 53, 60, 62, 69, 69, 79, 82, 86, 96}, 15, 198); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-54, 0, -22, 94, 58, 0, -12, 84, 0, 0, -34, 16, -10, -32, 50, -78, 68, -52, -64, 66, 0, 0, -38, -18, -84, -66, -36, 64, -12, 44, 48, 8, 42}, 28, 1100); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1}, 2, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({63, 49, 18, 36, 21, 30, 45, 87}, 6, 217); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, 0, 0, -72, -62, -56, -52, -44, 0, 0, -28, -22, -20, -12, 0, 0, -2, 2, 2, 4, 36, 44, 46, 50, 50, 54, 66, 92}, 18, 468); \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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0}, 34, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 8, 12, 0, 0, 14, 17, 18, 27, 28, 31, 34, 37, 38, 42, 43, 45, 49, 52, 53, 0, 0, 58, 62, 66, 71, 74, 87, 93, 96, 99}, 25, 671); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, -28, -30, 86, 0, -80, 76, -2, 28, 0, 0, 84, 0, 0, -88, 0, 42, 16, 0, 0, 78, -8, -46, -6, 0, 0, 0, -12, -32, -72, 84, -82, 76, -84, 80, -50, 90, -50, -14, -82, 78, 48, -10, 86, 34, -20, -76, 58}, 28, 710); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1}, 1, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({83, 86, 57, 18, 98, 52, 1, 37, 11, 49, 10, 67, 2, 60, 30, 42, 8, 97, 25, 55, 5, 75, 9, 67}, 16, 703); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumPossibleDifferenceTwoSubsetsArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 198, \"inputs\": {\"arr\": [5, 14, 15, 21, 0, 0, 42, 0, 0, 0, 0, 48, 0, 0, 53, 60, 62, 69, 69, 79, 82, 86, 96], \"n\": 15}}, {\"idx\": 1, \"outputs\": 1100, \"inputs\": {\"arr\": [-54, 0, -22, 94, 58, 0, -12, 84, 0, 0, -34, 16, -10, -32, 50, -78, 68, -52, -64, 66, 0, 0, -38, -18, -84, -66, -36, 64, -12, 44, 48, 8, 42], \"n\": 28}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 1], \"n\": 2}}, {\"idx\": 3, \"outputs\": 217, \"inputs\": {\"arr\": [63, 49, 18, 36, 21, 30, 45, 87], \"n\": 6}}, {\"idx\": 4, \"outputs\": 468, \"inputs\": {\"arr\": [-96, 0, 0, -72, -62, -56, -52, -44, 0, 0, -28, -22, -20, -12, 0, 0, -2, 2, 2, 4, 36, 44, 46, 50, 50, 54, 66, 92], \"n\": 18}}, {\"idx\": 5, \"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, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0], \"n\": 34}}, {\"idx\": 6, \"outputs\": 671, \"inputs\": {\"arr\": [1, 2, 8, 12, 0, 0, 14, 17, 18, 27, 28, 31, 34, 37, 38, 42, 43, 45, 49, 52, 53, 0, 0, 58, 62, 66, 71, 74, 87, 93, 96, 99], \"n\": 25}}, {\"idx\": 7, \"outputs\": 710, \"inputs\": {\"arr\": [0, -28, -30, 86, 0, -80, 76, -2, 28, 0, 0, 84, 0, 0, -88, 0, 42, 16, 0, 0, 78, -8, -46, -6, 0, 0, 0, -12, -32, -72, 84, -82, 76, -84, 80, -50, 90, -50, -14, -82, 78, 48, -10, 86, 34, -20, -76, 58], \"n\": 28}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1], \"n\": 1}}, {\"idx\": 9, \"outputs\": 703, \"inputs\": {\"arr\": [83, 86, 57, 18, 98, 52, 1, 37, 11, 49, 10, 67, 2, 60, 30, 42, 8, 97, 25, 55, 5, 75, 9, 67], \"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 ] }
311
Maximum Possible Sum Window Array Elements Window Array Unique
C++
int maximumPossibleSumWindowArrayElementsWindowArrayUnique(vector<int> a, vector<int> b, int n) {
[ "a", "b", "n" ]
def maximum_possible_sum_window_array_elements_window_array_unique(A, B, n): mp = set() result = 0 curr_sum = curr_begin = 0 for i in range(0, n): while (A[i] in mp): mp.remove(A[curr_begin]) curr_sum -= B[curr_begin] curr_begin += 1 mp.add(A[i]) curr_sum += B[i] result = max(result, curr_sum) return result
int maximum_possible_sum_window_array_elements_window_array_unique(vector<int> A, vector<int> B, int n) { unordered_set < int > mp; int result = 0; int curr_sum = 0, curr_begin = 0; for ( int i = 0; i < n; ++ i ) { while ( mp . find ( A [ i ] ) != mp . end ( ) ) { mp . erase ( A [ curr_begin ] ); curr_sum -= B [ curr_begin ]; curr_begin ++; } mp . insert ( A [ i ] ); curr_sum += B [ i ]; result = max ( result, curr_sum ); } 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({4, 8, 10, 10, 16, 23, 33, 36, 43, 47, 50, 55, 56, 72, 84, 85, 86, 86, 88, 90, 92, 99}, {8, 26, 30, 35, 45, 47, 55, 56, 59, 61, 64, 66, 67, 69, 73, 77, 78, 81, 82, 85, 86, 99}, 20, 852); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({48, -22, 84, 76, 50, -14, -82, 28, 86, -50, -40, 10, 48, 20, -48, -84, -64, -48, -32, -84, -32, 10, 42, -10, -68, -16, -94, -76, 42, -96, 16, -64, 60, 8, -88, -62, 82, -24, -28, 40, 18, 8}, {82, 94, 34, 12, 18, -68, 14, -16, -30, -16, 6, 74, -68, 76, -76, 52, -32, -38, 78, 64, -60, -46, 82, -60, 98, -70, -52, -96, -6, -44, 66, -66, 22, -42, -66, 4, -2, -48, -94, 72, 56, 88}, 30, 240); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1}, {0, 0, 1, 1}, 2, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({74, 64, 93, 72, 75, 90, 46, 72, 91, 98, 57, 58, 76, 29, 88, 3, 86, 1, 78, 74, 56, 54, 57, 3, 94, 2, 14, 32, 67, 62, 1, 30, 78, 95, 40}, {9, 50, 22, 60, 36, 46, 76, 48, 90, 64, 16, 24, 41, 12, 36, 36, 93, 52, 26, 38, 68, 5, 55, 19, 35, 5, 7, 96, 67, 64, 24, 85, 6, 33, 7}, 20, 734); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -88, -68, -24, 60, 94}, {-80, -72, -60, -42, -24, -6}, 4, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0}, {1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0}, 22, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 7, 12, 15, 17, 23, 31, 31, 32, 37, 41, 54, 57, 60, 62, 62, 64, 70, 71, 74, 75, 83, 97, 98}, {3, 10, 10, 12, 12, 14, 15, 19, 19, 20, 25, 27, 27, 28, 40, 41, 50, 51, 53, 57, 60, 65, 75, 99}, 22, 377); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-2, 26, -74, 96, -70, 56, 92, -74, -38, -18, 36, 44, -10, -26, 26, -22, -58, 78, 86, 22, 76, 50, 88, -86, -80, -36, -48, 90, -34, 62, 46, -56, -32}, {76, 42, 0, 4, -96, -24, -50, -54, 26, -8, -38, -46, 42, -50, 16, -2, -6, 2, -8, 56, 64, -58, -96, 2, -64, -66, -14, 58, -76, -26, 78, -96, 48}, 17, 122); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 39, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 30, 87, 99, 8, 1, 24, 46, 12, 21, 43, 73, 28, 3, 35, 49, 14, 37, 63, 98, 65, 43, 86, 69, 27, 60, 45, 88, 25, 86, 11, 9, 86, 73, 40, 70, 49, 50, 95, 69, 94}, {27, 66, 77, 34, 98, 75, 43, 27, 79, 32, 54, 40, 29, 47, 63, 15, 23, 33, 59, 76, 27, 31, 92, 43, 12, 20, 97, 67, 11, 12, 83, 79, 52, 46, 51, 36, 87, 96, 90, 6, 62}, 34, 1024); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumPossibleSumWindowArrayElementsWindowArrayUnique", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 852, \"inputs\": {\"a\": [4, 8, 10, 10, 16, 23, 33, 36, 43, 47, 50, 55, 56, 72, 84, 85, 86, 86, 88, 90, 92, 99], \"b\": [8, 26, 30, 35, 45, 47, 55, 56, 59, 61, 64, 66, 67, 69, 73, 77, 78, 81, 82, 85, 86, 99], \"n\": 20}}, {\"idx\": 1, \"outputs\": 240, \"inputs\": {\"a\": [48, -22, 84, 76, 50, -14, -82, 28, 86, -50, -40, 10, 48, 20, -48, -84, -64, -48, -32, -84, -32, 10, 42, -10, -68, -16, -94, -76, 42, -96, 16, -64, 60, 8, -88, -62, 82, -24, -28, 40, 18, 8], \"b\": [82, 94, 34, 12, 18, -68, 14, -16, -30, -16, 6, 74, -68, 76, -76, 52, -32, -38, 78, 64, -60, -46, 82, -60, 98, -70, -52, -96, -6, -44, 66, -66, 22, -42, -66, 4, -2, -48, -94, 72, 56, 88], \"n\": 30}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": [0, 0, 0, 1], \"b\": [0, 0, 1, 1], \"n\": 2}}, {\"idx\": 3, \"outputs\": 734, \"inputs\": {\"a\": [74, 64, 93, 72, 75, 90, 46, 72, 91, 98, 57, 58, 76, 29, 88, 3, 86, 1, 78, 74, 56, 54, 57, 3, 94, 2, 14, 32, 67, 62, 1, 30, 78, 95, 40], \"b\": [9, 50, 22, 60, 36, 46, 76, 48, 90, 64, 16, 24, 41, 12, 36, 36, 93, 52, 26, 38, 68, 5, 55, 19, 35, 5, 7, 96, 67, 64, 24, 85, 6, 33, 7], \"n\": 20}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"a\": [-94, -88, -68, -24, 60, 94], \"b\": [-80, -72, -60, -42, -24, -6], \"n\": 4}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0], \"b\": [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0], \"n\": 22}}, {\"idx\": 6, \"outputs\": 377, \"inputs\": {\"a\": [3, 7, 12, 15, 17, 23, 31, 31, 32, 37, 41, 54, 57, 60, 62, 62, 64, 70, 71, 74, 75, 83, 97, 98], \"b\": [3, 10, 10, 12, 12, 14, 15, 19, 19, 20, 25, 27, 27, 28, 40, 41, 50, 51, 53, 57, 60, 65, 75, 99], \"n\": 22}}, {\"idx\": 7, \"outputs\": 122, \"inputs\": {\"a\": [-2, 26, -74, 96, -70, 56, 92, -74, -38, -18, 36, 44, -10, -26, 26, -22, -58, 78, 86, 22, 76, 50, 88, -86, -80, -36, -48, 90, -34, 62, 46, -56, -32], \"b\": [76, 42, 0, 4, -96, -24, -50, -54, 26, -8, -38, -46, 42, -50, 16, -2, -6, 2, -8, 56, 64, -58, -96, 2, -64, -66, -14, 58, -76, -26, 78, -96, 48], \"n\": 17}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"a\": [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], \"b\": [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\": 39}}, {\"idx\": 9, \"outputs\": 1024, \"inputs\": {\"a\": [86, 30, 87, 99, 8, 1, 24, 46, 12, 21, 43, 73, 28, 3, 35, 49, 14, 37, 63, 98, 65, 43, 86, 69, 27, 60, 45, 88, 25, 86, 11, 9, 86, 73, 40, 70, 49, 50, 95, 69, 94], \"b\": [27, 66, 77, 34, 98, 75, 43, 27, 79, 32, 54, 40, 29, 47, 63, 15, 23, 33, 59, 76, 27, 31, 92, 43, 12, 20, 97, 67, 11, 12, 83, 79, 52, 46, 51, 36, 87, 96, 90, 6, 62], \"n\": 34}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
313
Maximum Product Subset Array
C++
long long maximumProductSubsetArray(vector<int> a, int n) {
[ "a", "n" ]
def maximum_product_subset_array(a, n): if (n == 1): return a[0] max_neg = (- 999999999999) count_neg = 0 count_zero = 0 prod = 1 for i in range(n): if (a[i] == 0): count_zero += 1 continue if (a[i] < 0): count_neg += 1 max_neg = max(max_neg, a[i]) prod = (prod * a[i]) if (count_zero == n): return 0 if (count_neg & 1): if ((count_neg == 1) and (count_zero > 0) and ((count_zero + count_neg) == n)): return 0 prod = int((prod / max_neg)) return prod
int maximum_product_subset_array(vector<int> a, int n) { if ( n == 1 ) return a [ 0 ]; int max_neg = INT_MIN; 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 ] ); } prod = prod * a [ i ]; } if ( count_zero == n ) return 0; if ( count_neg & 1 ) { if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 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({22, 62, 97}, 2, 1364); \n cout << \"TEST-\" << 0 << \"...\"\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}, 43, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -78, -74, -72, -70, -66, -46, -44, -42, -34, -32, -30, -10, 18, 30, 34, 56, 64, 66}, 10, 510537135542353920); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0}, 16, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 3, 18, 20, 33, 38, 53, 55, 56, 67, 80, 83, 87, 90, 97, 98}, 9, 7895685600); \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, 1, 1}, 11, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumProductSubsetArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1364, \"inputs\": {\"a\": [22, 62, 97], \"n\": 2}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 43}}, {\"idx\": 2, \"outputs\": 510537135542353920, \"inputs\": {\"a\": [-92, -78, -74, -72, -70, -66, -46, -44, -42, -34, -32, -30, -10, 18, 30, 34, 56, 64, 66], \"n\": 10}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"a\": [0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0], \"n\": 16}}, {\"idx\": 4, \"outputs\": 7895685600, \"inputs\": {\"a\": [1, 2, 3, 18, 20, 33, 38, 53, 55, 56, 67, 80, 83, 87, 90, 97, 98], \"n\": 9}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 11}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
314
Maximum Profit By Buying And Selling A Share At Most K Times 1
C++
int maximumProfitByBuyingAndSellingAShareAtMostKTimes1(vector<int> price, int n, int k) {
[ "price", "n", "k" ]
def maximum_profit_by_buying_and_selling_a_share_at_most_k_times_1(price, n, k): profit = [[0 for i in range((n + 1))] for j in range((k + 1))] for i in range(1, (k + 1)): prevDiff = float('-inf') for j in range(1, n): prevDiff = max(prevDiff, (profit[(i - 1)][(j - 1)] - price[(j - 1)])) profit[i][j] = max(profit[i][(j - 1)], (price[j] + prevDiff)) return profit[k][(n - 1)]
int maximum_profit_by_buying_and_selling_a_share_at_most_k_times_1(vector<int> price, int n, int k) { int profit [ k + 1 ] [ n + 1 ]; for ( int i = 0; i <= k; i ++ ) profit [ i ] [ 0 ] = 0; for ( int j = 0; j <= n; j ++ ) profit [ 0 ] [ j ] = 0; for ( int i = 1; i <= k; i ++ ) { int prevDiff = INT_MIN; for ( int j = 1; j < n; j ++ ) { prevDiff = max ( prevDiff, profit [ i - 1 ] [ j - 1 ] - price [ j - 1 ] ); profit [ i ] [ j ] = max ( profit [ i ] [ j - 1 ], price [ j ] + prevDiff ); } } return profit [ k ] [ 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> price, int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(price, 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, 6, 16, 16, 19, 37, 47, 49, 74, 77, 86, 96}, 6, 6, 34); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-6, -70, -26, 78, 98, -72, 48, -94, -38, 52, -50, 58, 84, 16, -74, 32, -44, -50, 68, -48, 28, 94, -26, -96, -42, 96, -24, 42, -70, 10, -16, -32, 98, 38, -2, 26, -26, -78, 44, -72, -56, -22}, 31, 32, 1272); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1}, 7, 8, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, 12, 58, 70}, 3, 2, 46); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -96, -94, -92, -90, -88, -88, -84, -78, -76, -72, -72, -68, -62, -54, -52, -52, -36, -34, -32, -26, -20, -6, -4, -4, 4, 8, 10, 14, 16, 32, 32, 32, 34, 42, 46, 50, 60, 62, 64, 64, 72, 74, 76, 76, 78, 90, 92, 96}, 30, 36, 112); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0}, 14, 13, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 4, 7, 11, 20, 24, 25, 27, 29, 33, 33, 36, 36, 41, 44, 45, 47, 54, 65, 66, 67, 75, 78, 82, 85, 90}, 15, 22, 42); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({56, 2, -10, -44, 68, 10, -32, -2, -68, 12, -34, -36, 0, 40, -16, -36, 92, 8, -40, -10, 46, 98, 76, -2, 98, -20, 6, 68, 32, -26, -12, 70, 16, -34, -50, -76, -34, -18, 0, -44, -76, 58}, 24, 35, 564); \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}, 10, 8, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, 39, 2, 76, 20, 21, 3, 21, 32, 80, 28, 89, 51, 2, 88, 19, 99, 71, 68, 38, 8, 76, 48, 81, 90, 71, 31}, 14, 24, 213); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumProfitByBuyingAndSellingAShareAtMostKTimes1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 34, \"inputs\": {\"price\": [3, 6, 16, 16, 19, 37, 47, 49, 74, 77, 86, 96], \"n\": 6, \"k\": 6}}, {\"idx\": 1, \"outputs\": 1272, \"inputs\": {\"price\": [-6, -70, -26, 78, 98, -72, 48, -94, -38, 52, -50, 58, 84, 16, -74, 32, -44, -50, 68, -48, 28, 94, -26, -96, -42, 96, -24, 42, -70, 10, -16, -32, 98, 38, -2, 26, -26, -78, 44, -72, -56, -22], \"n\": 31, \"k\": 32}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"price\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1], \"n\": 7, \"k\": 8}}, {\"idx\": 3, \"outputs\": 46, \"inputs\": {\"price\": [22, 12, 58, 70], \"n\": 3, \"k\": 2}}, {\"idx\": 4, \"outputs\": 112, \"inputs\": {\"price\": [-96, -96, -94, -92, -90, -88, -88, -84, -78, -76, -72, -72, -68, -62, -54, -52, -52, -36, -34, -32, -26, -20, -6, -4, -4, 4, 8, 10, 14, 16, 32, 32, 32, 34, 42, 46, 50, 60, 62, 64, 64, 72, 74, 76, 76, 78, 90, 92, 96], \"n\": 30, \"k\": 36}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"price\": [1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0], \"n\": 14, \"k\": 13}}, {\"idx\": 6, \"outputs\": 42, \"inputs\": {\"price\": [2, 4, 7, 11, 20, 24, 25, 27, 29, 33, 33, 36, 36, 41, 44, 45, 47, 54, 65, 66, 67, 75, 78, 82, 85, 90], \"n\": 15, \"k\": 22}}, {\"idx\": 7, \"outputs\": 564, \"inputs\": {\"price\": [56, 2, -10, -44, 68, 10, -32, -2, -68, 12, -34, -36, 0, 40, -16, -36, 92, 8, -40, -10, 46, 98, 76, -2, 98, -20, 6, 68, 32, -26, -12, 70, 16, -34, -50, -76, -34, -18, 0, -44, -76, 58], \"n\": 24, \"k\": 35}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"price\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 10, \"k\": 8}}, {\"idx\": 9, \"outputs\": 213, \"inputs\": {\"price\": [78, 39, 2, 76, 20, 21, 3, 21, 32, 80, 28, 89, 51, 2, 88, 19, 99, 71, 68, 38, 8, 76, 48, 81, 90, 71, 31], \"n\": 14, \"k\": 24}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
315
Maximum Profit By Buying And Selling A Share At Most Twice
C++
int maximumProfitByBuyingAndSellingAShareAtMostTwice(vector<int> price, int n) {
[ "price", "n" ]
def maximum_profit_by_buying_and_selling_a_share_at_most_twice(price, n): profit = ([0] * n) max_price = price[(n - 1)] for i in range((n - 2), 0, (- 1)): if (price[i] > max_price): max_price = price[i] profit[i] = max(profit[(i + 1)], (max_price - price[i])) min_price = price[0] for i in range(1, n): if (price[i] < min_price): min_price = price[i] profit[i] = max(profit[(i - 1)], (profit[i] + (price[i] - min_price))) result = profit[(n - 1)] return result
int maximum_profit_by_buying_and_selling_a_share_at_most_twice(vector<int> price, int n) { int * profit = new int [ n ]; for ( int i = 0; i < n; i ++ ) profit [ i ] = 0; int max_price = price [ n - 1 ]; for ( int i = n - 2; i >= 0; i -- ) { if ( price [ i ] > max_price ) max_price = price [ i ]; profit [ i ] = max ( profit [ i + 1 ], max_price - price [ i ] ); } int min_price = price [ 0 ]; for ( int i = 1; i < n; i ++ ) { if ( price [ i ] < min_price ) min_price = price [ i ]; profit [ i ] = max ( profit [ i - 1 ], profit [ i ] + ( price [ i ] - min_price ) ); } int result = profit [ n - 1 ]; delete [ ] profit; 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> price, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(price, 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, 10, 12, 17, 18, 23, 32, 41, 44, 47, 50, 59, 69, 69, 75, 82, 84, 87, 89, 97, 99}, 20, 80); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 6, 60, 40, 32, -70, -92, 88, 10, -8, -54, 4, 16, 8, -44, 80, -70, 36, 36, -74, -94, 18, -64, -66, -46, 0, -54, -84, 16, -88, -34, -24, 92, 84, 62}, 34, 366); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 67, 50, 8, 20, 42, 37, 69, 86, 74, 85, 96, 78, 89, 91}, 8, 126); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-68, -52, -14, -2, 18, 22, 30, 34, 64, 64, 70}, 9, 132); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1}, 21, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 17, 19, 28, 29, 30, 30, 30, 35, 36, 36, 38, 40, 40, 42, 43, 45, 51, 55, 57, 58, 59, 64, 65, 66, 82, 84, 85, 87, 91, 92, 94, 98, 98}, 25, 62); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, 88, -40, 60, 30, 8, -96, 66, -96, -28, -56, -14, 76, -92, 56, 58, 64, -60, -90, 26, 64, -2, 54, -24, 54, -46, -44}, 14, 334); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({82, 14, 51, 12, 5, 15, 50, 88, 91, 82, 16, 98, 23, 58, 86, 91, 30, 81, 7, 73, 67, 47, 10, 50, 43, 31, 19, 2, 22}, 18, 168); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumProfitByBuyingAndSellingAShareAtMostTwice", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 80, \"inputs\": {\"price\": [9, 10, 10, 12, 17, 18, 23, 32, 41, 44, 47, 50, 59, 69, 69, 75, 82, 84, 87, 89, 97, 99], \"n\": 20}}, {\"idx\": 1, \"outputs\": 366, \"inputs\": {\"price\": [6, 6, 60, 40, 32, -70, -92, 88, 10, -8, -54, 4, 16, 8, -44, 80, -70, 36, 36, -74, -94, 18, -64, -66, -46, 0, -54, -84, 16, -88, -34, -24, 92, 84, 62], \"n\": 34}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"price\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13}}, {\"idx\": 3, \"outputs\": 126, \"inputs\": {\"price\": [2, 67, 50, 8, 20, 42, 37, 69, 86, 74, 85, 96, 78, 89, 91], \"n\": 8}}, {\"idx\": 4, \"outputs\": 132, \"inputs\": {\"price\": [-68, -52, -14, -2, 18, 22, 30, 34, 64, 64, 70], \"n\": 9}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"price\": [1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1], \"n\": 21}}, {\"idx\": 6, \"outputs\": 62, \"inputs\": {\"price\": [4, 17, 19, 28, 29, 30, 30, 30, 35, 36, 36, 38, 40, 40, 42, 43, 45, 51, 55, 57, 58, 59, 64, 65, 66, 82, 84, 85, 87, 91, 92, 94, 98, 98], \"n\": 25}}, {\"idx\": 7, \"outputs\": 334, \"inputs\": {\"price\": [52, 88, -40, 60, 30, 8, -96, 66, -96, -28, -56, -14, 76, -92, 56, 58, 64, -60, -90, 26, 64, -2, 54, -24, 54, -46, -44], \"n\": 14}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"price\": [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], \"n\": 22}}, {\"idx\": 9, \"outputs\": 168, \"inputs\": {\"price\": [82, 14, 51, 12, 5, 15, 50, 88, 91, 82, 16, 98, 23, 58, 86, 91, 30, 81, 7, 73, 67, 47, 10, 50, 43, 31, 19, 2, 22], \"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 ] }
316
Maximum Removal From Array When Removal Time Waiting Time
C++
int maximumRemovalFromArrayWhenRemovalTimeWaitingTime(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_removal_from_array_when_removal_time_waiting_time(arr, n): count = 0 cummulative_sum = 0 arr.sort() for i in range(n): if (arr[i] >= cummulative_sum): count += 1 cummulative_sum += arr[i] return count
int maximum_removal_from_array_when_removal_time_waiting_time(vector<int> arr, int n) { int count = 0; int cummulative_sum = 0; sort(arr.begin(), arr.end()); for ( int i = 0; i < n; i ++ ) { if ( arr [ i ] >= cummulative_sum ) { count ++; cummulative_sum += arr [ 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(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, 33, 34, 42, 42, 45, 73}, 5, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -90, -80, -66, -64, -62, -48, -30, -20, -10, 4, 6, 12, 14, 32, 42, 44, 44, 52, 64, 86, 92, 94}, 16, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1}, 2, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 44, 71, 82, 85, 89}, 3, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -78, -72, -68, -58, -52, -50, -50, -48, -42, -32, -20, -18, -4, 0, 0, 2, 18, 18, 20, 24, 32, 34, 36, 38, 38, 60, 66, 68, 70, 72, 72, 74, 76, 96, 98}, 21, 5); \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, 1, 1, 1, 1}, 16, 11); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 9, 10, 11, 12, 15, 17, 19, 20, 21, 24, 30, 33, 35, 36, 39, 41, 41, 42, 54, 62, 63, 68, 70, 71, 72, 77, 85, 86, 86, 94, 95, 97, 97}, 31, 5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -90, -72, -70, -66, -60, -24, -16, 4, 4, 10, 22, 28, 36, 46, 60, 70, 72, 76, 92, 96}, 20, 6); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 13); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 10, 12, 16, 20, 28, 31, 40, 42, 47, 53, 57, 59, 63, 63, 67, 69, 84, 90, 97}, 10, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumRemovalFromArrayWhenRemovalTimeWaitingTime", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"arr\": [7, 33, 34, 42, 42, 45, 73], \"n\": 5}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"arr\": [-98, -90, -80, -66, -64, -62, -48, -30, -20, -10, 4, 6, 12, 14, 32, 42, 44, 44, 52, 64, 86, 92, 94], \"n\": 16}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 1], \"n\": 2}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"arr\": [11, 44, 71, 82, 85, 89], \"n\": 3}}, {\"idx\": 4, \"outputs\": 5, \"inputs\": {\"arr\": [-96, -92, -78, -72, -68, -58, -52, -50, -50, -48, -42, -32, -20, -18, -4, 0, 0, 2, 18, 18, 20, 24, 32, 34, 36, 38, 38, 60, 66, 68, 70, 72, 72, 74, 76, 96, 98], \"n\": 21}}, {\"idx\": 5, \"outputs\": 11, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 16}}, {\"idx\": 6, \"outputs\": 5, \"inputs\": {\"arr\": [8, 9, 10, 11, 12, 15, 17, 19, 20, 21, 24, 30, 33, 35, 36, 39, 41, 41, 42, 54, 62, 63, 68, 70, 71, 72, 77, 85, 86, 86, 94, 95, 97, 97], \"n\": 31}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"arr\": [-94, -90, -72, -70, -66, -60, -24, -16, 4, 4, 10, 22, 28, 36, 46, 60, 70, 72, 76, 92, 96], \"n\": 20}}, {\"idx\": 8, \"outputs\": 13, \"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\": 13}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"arr\": [7, 10, 12, 16, 20, 28, 31, 40, 42, 47, 53, 57, 59, 63, 63, 67, 69, 84, 90, 97], \"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 ] }
317
Maximum Subarray Sum Array Created Repeated Concatenation
C++
long long maximumSubarraySumArrayCreatedRepeatedConcatenation(vector<int> a, int n, int k) {
[ "a", "n", "k" ]
def maximum_subarray_sum_array_created_repeated_concatenation(a, n, k): max_so_far = (- 2147483648) max_ending_here = 0 for i in range((n * k)): max_ending_here = (max_ending_here + a[(i % n)]) if (max_so_far < max_ending_here): max_so_far = max_ending_here if (max_ending_here < 0): max_ending_here = 0 return max_so_far
int maximum_subarray_sum_array_created_repeated_concatenation(vector<int> a, int n, int k) { int max_so_far = INT_MIN, max_ending_here = 0; for ( int i = 0; i < n * k; i ++ ) { max_ending_here = max_ending_here + a [ i % n ]; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here; if ( max_ending_here < 0 ) max_ending_here = 0; } return max_so_far; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int n, int k, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n, k), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 6, 12, 20, 23, 28, 33, 37, 47, 51, 53, 56, 63, 65, 65, 68, 69, 76, 76, 78, 83}, 18, 20, 15540); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, 10, 52, -44, 34, -4, -34, 2, 50, -60, 50, 94, -98, -98, -44, -36, -4, -62, -2, -92, -70, -48, -78, -10, 94}, 22, 22, 218); \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}, 34, 29, 522); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({71, 59, 21, 82, 73, 29, 30, 25, 21, 10, 85, 22, 60, 43, 49, 20, 34, 39, 69, 6, 44, 27, 50, 33, 57, 29, 65, 18, 68, 56, 50, 28}, 23, 30, 29070); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-84, -74, -74, -56, -54, -48, -48, -46, -42, -34, -32, -30, -18, -16, -16, 6, 12, 20, 24, 26, 30, 32, 34, 42, 42, 42, 44, 46, 46, 50, 50, 62, 72, 78, 90}, 17, 23, 18); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0}, 16, 25, 300); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 7, 11, 11, 26, 60, 68, 71, 77, 91, 95}, 8, 10, 2570); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, 48, -86, -52, 6, 4, 30, 18, -32, 60, -2, 16, -88, -36}, 8, 11, 134); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1}, 0, 0, -2147483648); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76}, 0, 0, -2147483648); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumSubarraySumArrayCreatedRepeatedConcatenation", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 15540, \"inputs\": {\"a\": [5, 6, 12, 20, 23, 28, 33, 37, 47, 51, 53, 56, 63, 65, 65, 68, 69, 76, 76, 78, 83], \"n\": 18, \"k\": 20}}, {\"idx\": 1, \"outputs\": 218, \"inputs\": {\"a\": [68, 10, 52, -44, 34, -4, -34, 2, 50, -60, 50, 94, -98, -98, -44, -36, -4, -62, -2, -92, -70, -48, -78, -10, 94], \"n\": 22, \"k\": 22}}, {\"idx\": 2, \"outputs\": 522, \"inputs\": {\"a\": [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\": 34, \"k\": 29}}, {\"idx\": 3, \"outputs\": 29070, \"inputs\": {\"a\": [71, 59, 21, 82, 73, 29, 30, 25, 21, 10, 85, 22, 60, 43, 49, 20, 34, 39, 69, 6, 44, 27, 50, 33, 57, 29, 65, 18, 68, 56, 50, 28], \"n\": 23, \"k\": 30}}, {\"idx\": 4, \"outputs\": 18, \"inputs\": {\"a\": [-84, -74, -74, -56, -54, -48, -48, -46, -42, -34, -32, -30, -18, -16, -16, 6, 12, 20, 24, 26, 30, 32, 34, 42, 42, 42, 44, 46, 46, 50, 50, 62, 72, 78, 90], \"n\": 17, \"k\": 23}}, {\"idx\": 5, \"outputs\": 300, \"inputs\": {\"a\": [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0], \"n\": 16, \"k\": 25}}, {\"idx\": 6, \"outputs\": 2570, \"inputs\": {\"a\": [3, 7, 11, 11, 26, 60, 68, 71, 77, 91, 95], \"n\": 8, \"k\": 10}}, {\"idx\": 7, \"outputs\": 134, \"inputs\": {\"a\": [28, 48, -86, -52, 6, 4, 30, 18, -32, 60, -2, 16, -88, -36], \"n\": 8, \"k\": 11}}, {\"idx\": 8, \"outputs\": -2147483648, \"inputs\": {\"a\": [1], \"n\": 0, \"k\": 0}}, {\"idx\": 9, \"outputs\": -2147483648, \"inputs\": {\"a\": [76], \"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 ] }
318
Maximum Subarray Sum Using Prefix Sum
C++
int maximumSubarraySumUsingPrefixSum(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_subarray_sum_using_prefix_sum(arr, n): min_prefix_sum = 0 res = (- math.inf) prefix_sum = [] prefix_sum.append(arr[0]) for i in range(1, n): prefix_sum.append((prefix_sum[(i - 1)] + arr[i])) for i in range(n): res = max(res, (prefix_sum[i] - min_prefix_sum)) min_prefix_sum = min(min_prefix_sum, prefix_sum[i]) return res
int maximum_subarray_sum_using_prefix_sum(vector<int> arr, int n) { int min_prefix_sum = 0; int res = numeric_limits < int > :: min ( ); int prefix_sum [ n ]; prefix_sum [ 0 ] = arr [ 0 ]; for ( int i = 1; i < n; i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ]; for ( int i = 0; i < n; i ++ ) { res = max ( res, prefix_sum [ i ] - min_prefix_sum ); min_prefix_sum = min ( min_prefix_sum, prefix_sum [ i ] ); } return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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, 9, 11, 17, 18, 19, 23, 24, 27, 30, 31, 31, 35, 44, 46, 47, 49, 51, 55, 58, 59, 61, 65, 67, 71, 71, 71, 71, 78, 78, 82, 91, 98}, 20, 633); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-82, -28, -66, -52, -36, 36, -88, 52, -62, 46, 42, 26, -60, 18, -52, 38, 94, -68, 44, -94, 14, 36, -70}, 15, 114); \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, 1, 1}, 19, 8); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, 36, 42, 42, 5, 52, 74, 86, 55, 82, 59, 81, 4, 90, 24, 34, 20, 99, 86, 25, 52, 48, 62, 5, 67, 83, 60, 72, 80, 73, 38, 55, 8, 70, 95}, 19, 999); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -52, -24, 36, 56}, 3, -24); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0}, 13, 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 4, 4, 7, 7, 17, 18, 20, 26, 26, 32, 37, 38, 42, 44, 44, 46, 50, 53, 57, 58, 58, 60, 61, 61, 64, 74, 75, 77, 83, 83, 84, 84, 85, 87, 88, 90, 95, 96, 97, 98, 99, 99}, 25, 811); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, 2, 26, 54, -16, 16, 48, 24, 50, -10, -32, -62, 48, -12, -66}, 13, 204); \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}, 14, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58, 14, 79, 11, 31, 28, 61, 86, 25, 27, 75, 78, 32, 55, 86, 48, 15, 51, 6, 78, 23, 82, 16, 62, 35, 51, 91, 16, 79, 38, 97, 30, 23, 58, 95, 57, 82, 35, 57, 43, 22, 41, 58, 69, 25, 65, 13, 79}, 39, 1971); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumSubarraySumUsingPrefixSum", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 633, \"inputs\": {\"arr\": [8, 9, 11, 17, 18, 19, 23, 24, 27, 30, 31, 31, 35, 44, 46, 47, 49, 51, 55, 58, 59, 61, 65, 67, 71, 71, 71, 71, 78, 78, 82, 91, 98], \"n\": 20}}, {\"idx\": 1, \"outputs\": 114, \"inputs\": {\"arr\": [-82, -28, -66, -52, -36, 36, -88, 52, -62, 46, 42, 26, -60, 18, -52, 38, 94, -68, 44, -94, 14, 36, -70], \"n\": 15}}, {\"idx\": 2, \"outputs\": 8, \"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, 1, 1, 1, 1], \"n\": 19}}, {\"idx\": 3, \"outputs\": 999, \"inputs\": {\"arr\": [28, 36, 42, 42, 5, 52, 74, 86, 55, 82, 59, 81, 4, 90, 24, 34, 20, 99, 86, 25, 52, 48, 62, 5, 67, 83, 60, 72, 80, 73, 38, 55, 8, 70, 95], \"n\": 19}}, {\"idx\": 4, \"outputs\": -24, \"inputs\": {\"arr\": [-92, -52, -24, 36, 56], \"n\": 3}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"arr\": [0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0], \"n\": 13}}, {\"idx\": 6, \"outputs\": 811, \"inputs\": {\"arr\": [1, 1, 4, 4, 7, 7, 17, 18, 20, 26, 26, 32, 37, 38, 42, 44, 44, 46, 50, 53, 57, 58, 58, 60, 61, 61, 64, 74, 75, 77, 83, 83, 84, 84, 85, 87, 88, 90, 95, 96, 97, 98, 99, 99], \"n\": 25}}, {\"idx\": 7, \"outputs\": 204, \"inputs\": {\"arr\": [-86, 2, 26, 54, -16, 16, 48, 24, 50, -10, -32, -62, 48, -12, -66], \"n\": 13}}, {\"idx\": 8, \"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], \"n\": 14}}, {\"idx\": 9, \"outputs\": 1971, \"inputs\": {\"arr\": [58, 14, 79, 11, 31, 28, 61, 86, 25, 27, 75, 78, 32, 55, 86, 48, 15, 51, 6, 78, 23, 82, 16, 62, 35, 51, 91, 16, 79, 38, 97, 30, 23, 58, 95, 57, 82, 35, 57, 43, 22, 41, 58, 69, 25, 65, 13, 79], \"n\": 39}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
319
Maximum Subsequence Sum Such That No Three Are Consecutive
C++
int maximumSubsequenceSumSuchThatNoThreeAreConsecutive(vector<int> arr, int n) {
[ "arr", "n" ]
def maximum_subsequence_sum_such_that_no_three_are_consecutive(arr, n): sum = [0 for k in range(n)] if (n >= 1): sum[0] = arr[0] if (n >= 2): sum[1] = (arr[0] + arr[1]) if (n > 2): sum[2] = max(sum[1], max((arr[1] + arr[2]), (arr[0] + arr[2]))) for i in range(3, n): sum[i] = max(max(sum[(i - 1)], (sum[(i - 2)] + arr[i])), ((arr[i] + arr[(i - 1)]) + sum[(i - 3)])) return sum[(n - 1)]
int maximum_subsequence_sum_such_that_no_three_are_consecutive(vector<int> arr, int n) { int sum [ n ]; if ( n >= 1 ) sum [ 0 ] = arr [ 0 ]; if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ]; if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ], max ( arr [ 1 ] + arr [ 2 ], arr [ 0 ] + arr [ 2 ] ) ); for ( int i = 3; i < n; i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ], sum [ i - 2 ] + arr [ i ] ), arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ); return sum [ 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 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, 6, 8, 9, 10, 10, 16, 17, 17, 20, 21, 22, 23, 28, 29, 32, 36, 37, 40, 41, 42, 43, 47, 47, 48, 48, 49, 49, 52, 52, 53, 59, 61, 64, 65, 79, 79, 81, 87, 91, 92, 98}, 35, 832); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, 76, -80, -30, 82, 52, -14, 28, 98, 18, 82, 52, 26, -62, -8}, 7, 308); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1}, 7, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({21, 26, 85, 73, 47, 10, 54, 9, 11, 70, 42, 95, 44, 91}, 12, 419); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -92, -90, -84, -76, -68, -60, -50, -34, -34, -20, -16, -6, 18, 50, 54, 66, 70, 96}, 9, -182); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1}, 16, 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 4, 4, 14, 14, 18, 21, 24, 26, 29, 31, 32, 34, 36, 37, 38, 40, 42, 44, 44, 54, 63, 69, 77, 77, 82, 82, 86, 87, 90, 93, 95}, 31, 895); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-46, 64, -44, 88, -74, 54, 40, -2, -24, 94, 40, -44, 56, -54, -60, -86, -58, 48, -90, 12, -76, -30, 94, -34, 14, 12, 80, -40, 60}, 22, 450); \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}, 7, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 32, 63, 23, 44, 57, 59, 69, 88, 61, 66, 61, 65, 33, 79, 58, 71, 2, 80, 41, 83, 12, 20, 9, 7, 40, 36, 97, 10, 98, 66, 78, 71, 37, 53}, 26, 895); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "maximumSubsequenceSumSuchThatNoThreeAreConsecutive", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 832, \"inputs\": {\"arr\": [5, 6, 8, 9, 10, 10, 16, 17, 17, 20, 21, 22, 23, 28, 29, 32, 36, 37, 40, 41, 42, 43, 47, 47, 48, 48, 49, 49, 52, 52, 53, 59, 61, 64, 65, 79, 79, 81, 87, 91, 92, 98], \"n\": 35}}, {\"idx\": 1, \"outputs\": 308, \"inputs\": {\"arr\": [98, 76, -80, -30, 82, 52, -14, 28, 98, 18, 82, 52, 26, -62, -8], \"n\": 7}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 3, \"outputs\": 419, \"inputs\": {\"arr\": [21, 26, 85, 73, 47, 10, 54, 9, 11, 70, 42, 95, 44, 91], \"n\": 12}}, {\"idx\": 4, \"outputs\": -182, \"inputs\": {\"arr\": [-94, -92, -90, -84, -76, -68, -60, -50, -34, -34, -20, -16, -6, 18, 50, 54, 66, 70, 96], \"n\": 9}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"arr\": [1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1], \"n\": 16}}, {\"idx\": 6, \"outputs\": 895, \"inputs\": {\"arr\": [2, 3, 4, 4, 14, 14, 18, 21, 24, 26, 29, 31, 32, 34, 36, 37, 38, 40, 42, 44, 44, 54, 63, 69, 77, 77, 82, 82, 86, 87, 90, 93, 95], \"n\": 31}}, {\"idx\": 7, \"outputs\": 450, \"inputs\": {\"arr\": [-46, 64, -44, 88, -74, 54, 40, -2, -24, 94, 40, -44, 56, -54, -60, -86, -58, 48, -90, 12, -76, -30, 94, -34, 14, 12, 80, -40, 60], \"n\": 22}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 895, \"inputs\": {\"arr\": [4, 32, 63, 23, 44, 57, 59, 69, 88, 61, 66, 61, 65, 33, 79, 58, 71, 2, 80, 41, 83, 12, 20, 9, 7, 40, 36, 97, 10, 98, 66, 78, 71, 37, 53], \"n\": 26}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }