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
107
Count Set Bits In An Integer
C++
int countSetBitsInAnInteger(int n) {
[ "n" ]
def count_set_bits_in_an_integer(n): count = 0 while n: count += (n & 1) n >>= 1 return count
unsigned int count_set_bits_in_an_integer(unsigned int n) { unsigned int count = 0; while ( n ) { count += n & 1; n >>= 1; } return count; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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(58, 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 3); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(52, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSetBitsInAnInteger", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"n\": 58}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"n\": 92}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"n\": 73}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"n\": 52}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"n\": 24}}, {\"idx\": 5, \"outputs\": 3, \"inputs\": {\"n\": 14}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"n\": 58}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"n\": 11}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"n\": 8}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"n\": 52}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
108
Count Set Bits In An Integer 1
C++
int countSetBitsInAnInteger1(int n) {
[ "n" ]
def count_set_bits_in_an_integer_1(n): if (n == 0): return 0 else: return ((n & 1) + count_set_bits_in_an_integer_1((n >> 1)))
int count_set_bits_in_an_integer_1(int n) { if ( n == 0 ) return 0; else return ( n & 1 ) + count_set_bits_in_an_integer_1 ( 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(43, 4); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 5); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 3); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSetBitsInAnInteger1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 4, \"inputs\": {\"n\": 43}}, {\"idx\": 1, \"outputs\": 5, \"inputs\": {\"n\": 94}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"n\": 72}}, {\"idx\": 3, \"outputs\": 4, \"inputs\": {\"n\": 86}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"n\": 42}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": 33}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"n\": 8}}, {\"idx\": 7, \"outputs\": 3, \"inputs\": {\"n\": 74}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"n\": 29}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"n\": 34}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
109
Count Set Bits In An Integer 3
C++
int countSetBitsInAnInteger3(int n) {
[ "n" ]
def count_set_bits_in_an_integer_3(n): if (n == 0): return 0 else: return (1 + count_set_bits_in_an_integer_3((n & (n - 1))))
int count_set_bits_in_an_integer_3(int n) { if ( n == 0 ) return 0; else return 1 + count_set_bits_in_an_integer_3 ( 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(6, 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 4); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 4); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 5); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSetBitsInAnInteger3", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"n\": 6}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"n\": 58}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"n\": 90}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"n\": 69}}, {\"idx\": 4, \"outputs\": 4, \"inputs\": {\"n\": 15}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"n\": 54}}, {\"idx\": 6, \"outputs\": 4, \"inputs\": {\"n\": 60}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"n\": 51}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"n\": 46}}, {\"idx\": 9, \"outputs\": 5, \"inputs\": {\"n\": 91}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
110
Count Strings Adjacent Characters Difference One
C++
long long countStringsAdjacentCharactersDifferenceOne(int n) {
[ "n" ]
def count_strings_adjacent_characters_difference_one(n): dp = [[0 for j in range(27)] for i in range((n + 1))] for i in range(0, 26): dp[1][i] = 1 for i in range(2, (n + 1)): for j in range(0, 26): if (j == 0): dp[i][j] = dp[(i - 1)][(j + 1)] else: dp[i][j] = (dp[(i - 1)][(j - 1)] + dp[(i - 1)][(j + 1)]) sum = 0 for i in range(0, 26): sum = (sum + dp[n][i]) return sum
int count_strings_adjacent_characters_difference_one(int n) { long int dp [ n + 1 ] [ 27 ]; memset ( dp, 0, sizeof ( dp ) ); for ( int i = 0; i <= 25; i ++ ) dp [ 1 ] [ i ] = 1; for ( int i = 2; i <= n; i ++ ) { for ( int j = 0; j <= 25; j ++ ) if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]; else dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ); } long int sum = 0; for ( int i = 0; i <= 25; i ++ ) sum = ( sum + dp [ n ] [ i ] ); return sum; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(7, 1468); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 1134264891541288); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 544505079089235836); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 41103600); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countStringsAdjacentCharactersDifferenceOne", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1468, \"inputs\": {\"n\": 7}}, {\"idx\": 1, \"outputs\": 1134264891541288, \"inputs\": {\"n\": 47}}, {\"idx\": 2, \"outputs\": 544505079089235836, \"inputs\": {\"n\": 56}}, {\"idx\": 3, \"outputs\": 41103600, \"inputs\": {\"n\": 22}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
111
Count Strings Can Formed Using B C Given Constraints 1
C++
int countStringsCanFormedUsingBCGivenConstraints1(int n) {
[ "n" ]
def count_strings_can_formed_using_b_c_given_constraints_1(n): return ((1 + (n * 2)) + ((n * ((n * n) - 1)) // 2))
int count_strings_can_formed_using_b_c_given_constraints_1(int n) { return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(55, 83271); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 23383); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 164359); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 389483); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 194619); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 2073); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 340869); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 3459); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 143848); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 157319); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countStringsCanFormedUsingBCGivenConstraints1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 83271, \"inputs\": {\"n\": 55}}, {\"idx\": 1, \"outputs\": 23383, \"inputs\": {\"n\": 36}}, {\"idx\": 2, \"outputs\": 164359, \"inputs\": {\"n\": 69}}, {\"idx\": 3, \"outputs\": 389483, \"inputs\": {\"n\": 92}}, {\"idx\": 4, \"outputs\": 194619, \"inputs\": {\"n\": 73}}, {\"idx\": 5, \"outputs\": 2073, \"inputs\": {\"n\": 16}}, {\"idx\": 6, \"outputs\": 340869, \"inputs\": {\"n\": 88}}, {\"idx\": 7, \"outputs\": 3459, \"inputs\": {\"n\": 19}}, {\"idx\": 8, \"outputs\": 143848, \"inputs\": {\"n\": 66}}, {\"idx\": 9, \"outputs\": 157319, \"inputs\": {\"n\": 68}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
112
Count Strings With Consecutive 1S
C++
long long countStringsWithConsecutive1S(int n) {
[ "n" ]
def count_strings_with_consecutive_1s(n): a = ([0] * n) b = ([0] * n) a[0] = b[0] = 1 for i in range(1, n): a[i] = (a[(i - 1)] + b[(i - 1)]) b[i] = a[(i - 1)] return (((1 << n) - a[(n - 1)]) - b[(n - 1)])
int count_strings_with_consecutive_1s(int n) { int a [ n ], b [ n ]; a [ 0 ] = b [ 0 ] = 1; for ( int i = 1; i < n; i ++ ) { a [ i ] = a [ i - 1 ] + b [ i - 1 ]; b [ i ] = a [ i - 1 ]; } return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(27, 133703499); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 7582); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 8580707127); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 144114231353829831); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 2251746497394075); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 880); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countStringsWithConsecutive1S", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 133703499, \"inputs\": {\"n\": 27}}, {\"idx\": 1, \"outputs\": 7582, \"inputs\": {\"n\": 13}}, {\"idx\": 2, \"outputs\": 8580707127, \"inputs\": {\"n\": 33}}, {\"idx\": 3, \"outputs\": 144114231353829831, \"inputs\": {\"n\": 57}}, {\"idx\": 4, \"outputs\": 2251746497394075, \"inputs\": {\"n\": 51}}, {\"idx\": 5, \"outputs\": 880, \"inputs\": {\"n\": 10}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 1}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
113
Count Subarrays Equal Number 1S 0S
C++
int countSubarraysEqualNumber1S0S(vector<int> arr, int n) {
[ "arr", "n" ]
def count_subarrays_equal_number_1s_0s(arr, n): um = dict() curr_sum = 0 for i in range(n): curr_sum += ((- 1) if (arr[i] == 0) else arr[i]) if um.get(curr_sum): um[curr_sum] += 1 else: um[curr_sum] = 1 count = 0 for itr in um: if (um[itr] > 1): count += ((um[itr] * int((um[itr] - 1))) / 2) if um.get(0): count += um[0] return int(count)
int count_subarrays_equal_number_1s_0s(vector<int> arr, int n) { unordered_map < int, int > um; int curr_sum = 0; for ( int i = 0; i < n; i ++ ) { curr_sum += ( arr [ i ] == 0 ) ? - 1 : arr [ i ]; um [ curr_sum ] ++; } int count = 0; for ( auto itr = um . begin ( ); itr != um . end ( ); itr ++ ) { if ( itr -> second > 1 ) count += ( ( itr -> second * ( itr -> second - 1 ) ) / 2 ); } if ( um . find ( 0 ) != um . end ( ) ) count += um [ 0 ]; return count; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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, 12, 18, 19, 19, 20, 20, 21, 25, 29, 38, 54, 54, 71, 72, 72, 74, 75, 77, 78, 80, 80, 81, 84, 97, 97}, 24, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 70, 24, -38, 32, -68, 88, -28, -24, -70, -64, 50, -30, 64, 54, -6, 18, -30, -30, -62, -10, 94, -54, -22, -88, 96, 22, 26, -92, -40, -76, 46, 36, 30, 24, -52, 0}, 24, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 11, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, 50, 17, 15, 86, 84, 87, 24, 81, 23, 71, 31, 13, 72, 58, 19, 29, 28, 40, 14, 48, 48, 81, 4, 52, 88, 54, 56, 10, 12, 58, 55, 7, 66, 15, 73, 22, 2, 20, 27, 57, 56, 56, 31, 9, 55}, 40, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -62, -60, 16, 78, 82}, 5, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1}, 2, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 31, 34, 64}, 2, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-70, 90, -10, -64, -76, -74, -12, -44, -48, -54, 76, -78, 8, 0, 0, 78, -28, 6, 98, -84, 60, 60, 2, 48, -96, -28, -78, -76, -56, -26, -60, 50, 44, 34, -90, 80, -30, -98, 62, 36, -46, -72}, 25, 2); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1}, 1, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({37, 70, 80, 61, 86, 10, 17, 98, 54, 89, 87, 84, 11, 55, 3, 52, 4, 90, 98, 31, 20, 62, 71, 58, 58, 6, 92, 5, 99, 99, 72, 40, 82, 54, 23, 19, 85, 91, 62, 98, 62, 72, 93, 74}, 27, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSubarraysEqualNumber1S0S", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [2, 12, 18, 19, 19, 20, 20, 21, 25, 29, 38, 54, 54, 71, 72, 72, 74, 75, 77, 78, 80, 80, 81, 84, 97, 97], \"n\": 24}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [10, 70, 24, -38, 32, -68, 88, -28, -24, -70, -64, 50, -30, 64, 54, -6, 18, -30, -30, -62, -10, 94, -54, -22, -88, 96, 22, 26, -92, -40, -76, 46, 36, 30, 24, -52, 0], \"n\": 24}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 11}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [66, 50, 17, 15, 86, 84, 87, 24, 81, 23, 71, 31, 13, 72, 58, 19, 29, 28, 40, 14, 48, 48, 81, 4, 52, 88, 54, 56, 10, 12, 58, 55, 7, 66, 15, 73, 22, 2, 20, 27, 57, 56, 56, 31, 9, 55], \"n\": 40}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-98, -62, -60, 16, 78, 82], \"n\": 5}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 0, 1], \"n\": 2}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [2, 31, 34, 64], \"n\": 2}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"arr\": [-70, 90, -10, -64, -76, -74, -12, -44, -48, -54, 76, -78, 8, 0, 0, 78, -28, 6, 98, -84, 60, 60, 2, 48, -96, -28, -78, -76, -56, -26, -60, 50, 44, 34, -90, 80, -30, -98, 62, 36, -46, -72], \"n\": 25}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1], \"n\": 1}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [37, 70, 80, 61, 86, 10, 17, 98, 54, 89, 87, 84, 11, 55, 3, 52, 4, 90, 98, 31, 20, 62, 71, 58, 58, 6, 92, 5, 99, 99, 72, 40, 82, 54, 23, 19, 85, 91, 62, 98, 62, 72, 93, 74], \"n\": 27}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
114
Count Subarrays Equal Number 1S 0S 1
C++
int countSubarraysEqualNumber1S0S1(vector<int> arr, int n) {
[ "arr", "n" ]
def count_subarrays_equal_number_1s_0s_1(arr, n): mp = dict() Sum = 0 count = 0 for i in range(n): if (arr[i] == 0): arr[i] = (- 1) Sum += arr[i] if (Sum == 0): count += 1 if (Sum in mp.keys()): count += mp[Sum] mp[Sum] = (mp.get(Sum, 0) + 1) return count
int count_subarrays_equal_number_1s_0s_1(vector<int> arr, int n) { map < int, int > mp; int sum = 0; int count = 0; for ( int i = 0; i < n; i ++ ) { if ( arr [ i ] == 0 ) arr [ i ] = - 1; sum += arr [ i ]; if ( sum == 0 ) count ++; if ( mp [ sum ] ) count += mp [ sum ]; if ( mp [ sum ] == 0 ) mp [ sum ] = 1; else mp [ sum ] ++; } 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({1, 6, 6, 9, 9, 9, 16, 18, 19, 20, 21, 22, 23, 26, 26, 28, 39, 40, 41, 43, 43, 44, 44, 45, 51, 51, 55, 59, 60, 62, 67, 67, 68, 69, 70, 71, 71, 72, 82, 84, 88, 88, 89, 89, 91, 92, 92}, 44, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-44, 74, -52, -96, 46, 92, 54, 56, -38, 88, 40, 34, -72, 8, 58, -14, 36, 94, 34, -90, -42, 80, -12, -42, -6, 78, -98, 34, -88, -1, -76, 90, 40, 64, 26, 18, -84, 72, 80}, 37, 2); \n cout << \"TEST-\" << 1 << \"...\"\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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 32, 14); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({60, 48, 42, 95, 30, 22, 80, 15, 62, 38, 63, 42, 39, 28, 69, 71, 30, 48, 67, 9, 33, 74, 95, 95, 72, 35, 9}, 18, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -94, -86, -66, -66, -62, -58, -36, -36, -22, -18, -10, 2, 4, 6, 10, 16, 20, 24, 26, 28, 28, 28, 40, 42, 44, 58, 76, 78, 78, 80, 90, 92}, 24, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 0, 1, 1}, 28, 32); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 5, 6, 7, 11, 16, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 29, 31, 34, 36, 37, 40, 41, 45, 45, 55, 65, 69, 70, 71, 71, 71, 73, 73, 76, 79, 80, 85, 85, 88, 90, 97, 98, 98, 99, 99}, 31, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({34, -20, 38, -94, 2, 32, -26, 90, 94, -36, -94, 6, -24, 12, 4, 60, 68, 64, -60, -72, -54, -10, -64, -48, -88, 60, 48, 64, -1, -26, 26, 74, 32, -92, 4, 84, 6, -16, 30, -56, -28, -86, -68}, 37, 6); \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}, 19, 7); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 99, 97, 63, 65, 57, 69, 39, 29, 91, 68, 25, 84, 82, 84, 89, 59, 18, 77, 29, 57, 40, 78, 35, 23, 91, 26, 71, 19, 99, 12, 91, 49, 71, 49, 77, 67}, 31, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSubarraysEqualNumber1S0S1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [1, 6, 6, 9, 9, 9, 16, 18, 19, 20, 21, 22, 23, 26, 26, 28, 39, 40, 41, 43, 43, 44, 44, 45, 51, 51, 55, 59, 60, 62, 67, 67, 68, 69, 70, 71, 71, 72, 82, 84, 88, 88, 89, 89, 91, 92, 92], \"n\": 44}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"arr\": [-44, 74, -52, -96, 46, 92, 54, 56, -38, 88, 40, 34, -72, 8, 58, -14, 36, 94, 34, -90, -42, 80, -12, -42, -6, 78, -98, 34, -88, -1, -76, 90, 40, 64, 26, 18, -84, 72, 80], \"n\": 37}}, {\"idx\": 2, \"outputs\": 14, \"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 32}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [60, 48, 42, 95, 30, 22, 80, 15, 62, 38, 63, 42, 39, 28, 69, 71, 30, 48, 67, 9, 33, 74, 95, 95, 72, 35, 9], \"n\": 18}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-96, -94, -94, -86, -66, -66, -62, -58, -36, -36, -22, -18, -10, 2, 4, 6, 10, 16, 20, 24, 26, 28, 28, 28, 40, 42, 44, 58, 76, 78, 78, 80, 90, 92], \"n\": 24}}, {\"idx\": 5, \"outputs\": 32, \"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, 0, 1, 1], \"n\": 28}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [4, 5, 5, 6, 7, 11, 16, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 29, 31, 34, 36, 37, 40, 41, 45, 45, 55, 65, 69, 70, 71, 71, 71, 73, 73, 76, 79, 80, 85, 85, 88, 90, 97, 98, 98, 99, 99], \"n\": 31}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"arr\": [34, -20, 38, -94, 2, 32, -26, 90, 94, -36, -94, 6, -24, 12, 4, 60, 68, 64, -60, -72, -54, -10, -64, -48, -88, 60, 48, 64, -1, -26, 26, 74, 32, -92, 4, 84, 6, -16, 30, -56, -28, -86, -68], \"n\": 37}}, {\"idx\": 8, \"outputs\": 7, \"inputs\": {\"arr\": [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 19}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [4, 99, 97, 63, 65, 57, 69, 39, 29, 91, 68, 25, 84, 82, 84, 89, 59, 18, 77, 29, 57, 40, 78, 35, 23, 91, 26, 71, 19, 99, 12, 91, 49, 71, 49, 77, 67], \"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 ] }
115
Count Subarrays Total Distinct Elements Original Array
C++
int countSubarraysTotalDistinctElementsOriginalArray(vector<int> arr, int n) {
[ "arr", "n" ]
def count_subarrays_total_distinct_elements_original_array(arr, n): vis = dict() for i in range(n): vis[arr[i]] = 1 k = len(vis) vid = dict() ans = 0 right = 0 window = 0 for left in range(n): while ((right < n) and (window < k)): if (arr[right] in vid.keys()): vid[arr[right]] += 1 else: vid[arr[right]] = 1 if (vid[arr[right]] == 1): window += 1 right += 1 if (window == k): ans += ((n - right) + 1) vid[arr[left]] -= 1 if (vid[arr[left]] == 0): window -= 1 return ans
int count_subarrays_total_distinct_elements_original_array(vector<int> arr, int n) { unordered_map < int, int > vis; for ( int i = 0; i < n; ++ i ) vis [ arr [ i ] ] = 1; int k = vis . size ( ); vis . clear ( ); int ans = 0, right = 0, window = 0; for ( int left = 0; left < n; ++ left ) { while ( right < n && window < k ) { ++ vis [ arr [ right ] ]; if ( vis [ arr [ right ] ] == 1 ) ++ window; ++ right; } if ( window == k ) ans += ( n - right + 1 ); -- vis [ arr [ left ] ]; if ( vis [ arr [ left ] ] == 0 ) -- window; } 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({13, 39, 49, 52, 53, 69, 72, 79, 83, 96}, 5, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, 22, -10, -28, 0, 56, 72, 36, 88, 96, 22, 90, 74, -60, -64, 0, 2, -42, 0, 94, -82, -74}, 20, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 26, 160); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({35, 23, 41, 58, 66, 92, 3, 33, 78, 70, 80, 86, 21, 21, 74, 19}, 12, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -80, -52, -10, 4, 76}, 3, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1}, 36, 609); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 7, 10, 17, 26, 36, 37, 85, 87, 88}, 8, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({64, -2, -94, -84, -48, 86}, 5, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 20, 91); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({91, 49, 94, 81, 64, 5, 13, 70, 82, 9, 80, 82}, 9, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSubarraysTotalDistinctElementsOriginalArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [13, 39, 49, 52, 53, 69, 72, 79, 83, 96], \"n\": 5}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"arr\": [-98, -98, 22, -10, -28, 0, 56, 72, 36, 88, 96, 22, 90, 74, -60, -64, 0, 2, -42, 0, 94, -82, -74], \"n\": 20}}, {\"idx\": 2, \"outputs\": 160, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 26}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [35, 23, 41, 58, 66, 92, 3, 33, 78, 70, 80, 86, 21, 21, 74, 19], \"n\": 12}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"arr\": [-98, -80, -52, -10, 4, 76], \"n\": 3}}, {\"idx\": 5, \"outputs\": 609, \"inputs\": {\"arr\": [1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1], \"n\": 36}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [2, 7, 10, 17, 26, 36, 37, 85, 87, 88], \"n\": 8}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [64, -2, -94, -84, -48, 86], \"n\": 5}}, {\"idx\": 8, \"outputs\": 91, \"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, 1], \"n\": 20}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [91, 49, 94, 81, 64, 5, 13, 70, 82, 9, 80, 82], \"n\": 9}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
116
Count Subarrays With Same Even And Odd Elements
C++
int countSubarraysWithSameEvenAndOddElements(vector<int> arr, int n) {
[ "arr", "n" ]
def count_subarrays_with_same_even_and_odd_elements(arr, n): difference = 0 ans = 0 hash_positive = ([0] * (n + 1)) hash_negative = ([0] * (n + 1)) hash_positive[0] = 1 for i in range(n): if ((arr[i] & 1) == 1): difference = (difference + 1) else: difference = (difference - 1) if (difference < 0): ans += hash_negative[(- difference)] hash_negative[(- difference)] = (hash_negative[(- difference)] + 1) else: ans += hash_positive[difference] hash_positive[difference] = (hash_positive[difference] + 1) return ans
int count_subarrays_with_same_even_and_odd_elements(vector<int> arr, int n) { int difference = 0; int ans = 0; int hash_positive [ n + 1 ], hash_negative [ n + 1 ]; fill_n ( hash_positive, n + 1, 0 ); fill_n ( hash_negative, n + 1, 0 ); hash_positive [ 0 ] = 1; for ( int i = 0; i < n; i ++ ) { if ( arr [ i ] & 1 == 1 ) difference ++; else difference --; if ( difference < 0 ) { ans += hash_negative [ - difference ]; hash_negative [ - difference ] ++; } else { ans += hash_positive [ difference ]; hash_positive [ difference ] ++; } } 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({7, 8, 12, 13, 14, 19, 20, 22, 28, 30, 31, 31, 32, 34, 34, 39, 39, 43, 45, 46, 47, 62, 63, 63, 65, 66, 69, 69, 71, 76, 79, 82, 83, 88, 89, 92, 93, 95, 97, 97}, 26, 50); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, -98, -44, -82, 28, 20, -76, -16, 42, 0, -88, 74, 56, 6, -68, -30, 28, 88, 58, -78, 46, 2}, 15, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 24, 11); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({44, 4, 29, 83, 28, 75, 58, 89, 40, 38, 29, 45, 21, 87, 97, 42, 95, 20, 48, 38, 15, 67, 23, 81, 50, 53, 64, 67, 30, 13, 52, 56, 87, 10, 80, 38, 31, 19}, 23, 43); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -94, -94, -90, -88, -86, -86, -82, -78, -76, -74, -68, -64, -62, -62, -60, -52, -48, -48, -46, -44, -44, -32, -28, -22, -12, -12, -8, -8, -4, 4, 6, 10, 14, 28, 40, 42, 52, 56, 60, 60, 60, 64, 68, 70, 82, 82, 84, 96}, 48, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1}, 27, 68); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 16, 21, 26, 34, 35, 44, 46, 46, 86}, 7, 5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({86, 12, 80, 46, -12, 6}, 4, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({71, 94, 91, 19, 85, 5, 87, 96, 66, 17, 95, 5, 32, 17, 93, 48, 46, 24}, 12, 7); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSubarraysWithSameEvenAndOddElements", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 50, \"inputs\": {\"arr\": [7, 8, 12, 13, 14, 19, 20, 22, 28, 30, 31, 31, 32, 34, 34, 39, 39, 43, 45, 46, 47, 62, 63, 63, 65, 66, 69, 69, 71, 76, 79, 82, 83, 88, 89, 92, 93, 95, 97, 97], \"n\": 26}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [20, -98, -44, -82, 28, 20, -76, -16, 42, 0, -88, 74, 56, 6, -68, -30, 28, 88, 58, -78, 46, 2], \"n\": 15}}, {\"idx\": 2, \"outputs\": 11, \"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], \"n\": 24}}, {\"idx\": 3, \"outputs\": 43, \"inputs\": {\"arr\": [44, 4, 29, 83, 28, 75, 58, 89, 40, 38, 29, 45, 21, 87, 97, 42, 95, 20, 48, 38, 15, 67, 23, 81, 50, 53, 64, 67, 30, 13, 52, 56, 87, 10, 80, 38, 31, 19], \"n\": 23}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-94, -94, -94, -90, -88, -86, -86, -82, -78, -76, -74, -68, -64, -62, -62, -60, -52, -48, -48, -46, -44, -44, -32, -28, -22, -12, -12, -8, -8, -4, 4, 6, 10, 14, 28, 40, 42, 52, 56, 60, 60, 60, 64, 68, 70, 82, 82, 84, 96], \"n\": 48}}, {\"idx\": 5, \"outputs\": 68, \"inputs\": {\"arr\": [1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1], \"n\": 27}}, {\"idx\": 6, \"outputs\": 5, \"inputs\": {\"arr\": [6, 16, 21, 26, 34, 35, 44, 46, 46, 86], \"n\": 7}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [86, 12, 80, 46, -12, 6], \"n\": 4}}, {\"idx\": 8, \"outputs\": 4, \"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, 1, 1, 1], \"n\": 15}}, {\"idx\": 9, \"outputs\": 7, \"inputs\": {\"arr\": [71, 94, 91, 19, 85, 5, 87, 96, 66, 17, 95, 5, 32, 17, 93, 48, 46, 24], \"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 ] }
117
Count Substrings With Same First And Last Characters
C++
int countSubstringsWithSameFirstAndLastCharacters(string s) {
[ "s" ]
def count_substrings_with_same_first_and_last_characters(s): result = 0 n = len(s) for i in range(n): for j in range(i, n): if (s[i] == s[j]): result = (result + 1) return result
int count_substrings_with_same_first_and_last_characters(string s) { int result = 0; int n = s . length ( ); for ( int i = 0; i < n; i ++ ) for ( int j = i; j < n; j ++ ) if ( s [ i ] == s [ j ] ) result ++; return result; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string 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(\"LZIKA\", 5); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0556979952\", 16); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"110010\", 12); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"kGaYfd\", 6); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"413567670657\", 19); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01001\", 9); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"EQPuFa\", 6); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"48848378\", 15); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"110\", 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"PLehNeP\", 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSubstringsWithSameFirstAndLastCharacters", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 5, \"inputs\": {\"s\": \"LZIKA\"}}, {\"idx\": 1, \"outputs\": 16, \"inputs\": {\"s\": \"0556979952\"}}, {\"idx\": 2, \"outputs\": 12, \"inputs\": {\"s\": \"110010\"}}, {\"idx\": 3, \"outputs\": 6, \"inputs\": {\"s\": \"kGaYfd\"}}, {\"idx\": 4, \"outputs\": 19, \"inputs\": {\"s\": \"413567670657\"}}, {\"idx\": 5, \"outputs\": 9, \"inputs\": {\"s\": \"01001\"}}, {\"idx\": 6, \"outputs\": 6, \"inputs\": {\"s\": \"EQPuFa\"}}, {\"idx\": 7, \"outputs\": 15, \"inputs\": {\"s\": \"48848378\"}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"s\": \"110\"}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"s\": \"PLehNeP\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
118
Count Sum Of Digits In Numbers From 1 To N
C++
int countSumOfDigitsInNumbersFrom1ToN(int n) {
[ "n" ]
def count_sum_of_digits_in_numbers_from_1_to_n(n): if (n < 10): return ((n * (n + 1)) / 2) d = int(math.log10(n)) a = ([0] * (d + 1)) a[0] = 0 a[1] = 45 for i in range(2, (d + 1)): a[i] = ((a[(i - 1)] * 10) + (45 * int(math.ceil(math.pow(10, (i - 1)))))) p = int(math.ceil(math.pow(10, d))) msd = (n // p) return int(((((msd * a[d]) + (((msd * (msd - 1)) // 2) * p)) + (msd * (1 + (n % p)))) + count_sum_of_digits_in_numbers_from_1_to_n((n % p))))
int count_sum_of_digits_in_numbers_from_1_to_n(int n) { if ( n < 10 ) return n * ( n + 1 ) / 2; int d = log10 ( n ); int * a = new int [ d + 1 ]; a [ 0 ] = 0, a [ 1 ] = 45; for ( int i = 2; i <= d; i ++ ) a [ i ] = a [ i - 1 ] * 10 + 45 * ceil ( pow ( 10, i - 1 ) ); int p = ceil ( pow ( 10, d ) ); int msd = n / p; return msd * a [ d ] + ( msd * ( msd - 1 ) / 2 ) * p + msd * ( 1 + n % p ) + count_sum_of_digits_in_numbers_from_1_to_n ( n % p ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(29, 165); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 865); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 540); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 667); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 525); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 168); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 667); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 177); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 609); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 240); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countSumOfDigitsInNumbersFrom1ToN", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 165, \"inputs\": {\"n\": 29}}, {\"idx\": 1, \"outputs\": 865, \"inputs\": {\"n\": 97}}, {\"idx\": 2, \"outputs\": 540, \"inputs\": {\"n\": 71}}, {\"idx\": 3, \"outputs\": 667, \"inputs\": {\"n\": 82}}, {\"idx\": 4, \"outputs\": 525, \"inputs\": {\"n\": 69}}, {\"idx\": 5, \"outputs\": 168, \"inputs\": {\"n\": 30}}, {\"idx\": 6, \"outputs\": 667, \"inputs\": {\"n\": 82}}, {\"idx\": 7, \"outputs\": 177, \"inputs\": {\"n\": 32}}, {\"idx\": 8, \"outputs\": 609, \"inputs\": {\"n\": 77}}, {\"idx\": 9, \"outputs\": 240, \"inputs\": {\"n\": 39}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
119
Count Total Set Bits In All Numbers From 1 To N
C++
int countTotalSetBitsInAllNumbersFrom1ToN(int n) {
[ "n" ]
def count_total_set_bits_in_all_numbers_from_1_to_n(n): i = 0 ans = 0 while ((1 << i) <= n): k = 0 change = (1 << i) for j in range(0, (n + 1)): ans += k if (change == 1): k = (not k) change = (1 << i) else: change -= 1 i += 1 return ans
int count_total_set_bits_in_all_numbers_from_1_to_n(int n) { int i = 0; int ans = 0; while ( ( 1 << i ) <= n ) { bool k = 0; int change = 1 << i; for ( int j = 0; j <= n; j ++ ) { ans += k; if ( change == 1 ) { k = ! k; change = 1 << i; } else { change --; } } 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(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(90, 279); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 159); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 112); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 80); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 231); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 88); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 112); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 197); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 32); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 304); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countTotalSetBitsInAllNumbersFrom1ToN", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 279, \"inputs\": {\"n\": 90}}, {\"idx\": 1, \"outputs\": 159, \"inputs\": {\"n\": 56}}, {\"idx\": 2, \"outputs\": 112, \"inputs\": {\"n\": 43}}, {\"idx\": 3, \"outputs\": 80, \"inputs\": {\"n\": 31}}, {\"idx\": 4, \"outputs\": 231, \"inputs\": {\"n\": 77}}, {\"idx\": 5, \"outputs\": 88, \"inputs\": {\"n\": 35}}, {\"idx\": 6, \"outputs\": 112, \"inputs\": {\"n\": 43}}, {\"idx\": 7, \"outputs\": 197, \"inputs\": {\"n\": 66}}, {\"idx\": 8, \"outputs\": 32, \"inputs\": {\"n\": 15}}, {\"idx\": 9, \"outputs\": 304, \"inputs\": {\"n\": 95}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
120
Count Trailing Zeroes Factorial Number
C++
int countTrailingZeroesFactorialNumber(int n) {
[ "n" ]
def count_trailing_zeroes_factorial_number(n): count = 0 i = 5 while ((n / i) >= 1): count += int((n / i)) i *= 5 return int(count)
int count_trailing_zeroes_factorial_number(int n) { int count = 0; for ( int i = 5; n / i >= 1; i *= 5 ) count += n / 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(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(9, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 9); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 12); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 8); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 12); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 7); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 10); \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(75, 18); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countTrailingZeroesFactorialNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"n\": 9}}, {\"idx\": 1, \"outputs\": 9, \"inputs\": {\"n\": 43}}, {\"idx\": 2, \"outputs\": 12, \"inputs\": {\"n\": 50}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"n\": 32}}, {\"idx\": 4, \"outputs\": 8, \"inputs\": {\"n\": 37}}, {\"idx\": 5, \"outputs\": 12, \"inputs\": {\"n\": 51}}, {\"idx\": 6, \"outputs\": 7, \"inputs\": {\"n\": 33}}, {\"idx\": 7, \"outputs\": 10, \"inputs\": {\"n\": 49}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": 1}}, {\"idx\": 9, \"outputs\": 18, \"inputs\": {\"n\": 75}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
121
Count Ways Build Street Given Constraints
C++
int countWaysBuildStreetGivenConstraints(int n) {
[ "n" ]
def count_ways_build_street_given_constraints(n): dp = [([0] * (n + 1)) for i in range(2)] dp[0][1] = 1 dp[1][1] = 2 for i in range(2, (n + 1)): dp[0][i] = (dp[0][(i - 1)] + dp[1][(i - 1)]) dp[1][i] = ((dp[0][(i - 1)] * 2) + dp[1][(i - 1)]) return (dp[0][n] + dp[1][n])
long count_ways_build_street_given_constraints(int n) { long dp [ 2 ] [ n + 1 ]; dp [ 0 ] [ 1 ] = 1; dp [ 1 ] [ 1 ] = 2; for ( int i = 2; i <= n; i ++ ) { dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]; dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ]; } return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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(20, 54608393); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countWaysBuildStreetGivenConstraints", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 54608393, \"inputs\": {\"n\": 20}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"n\": 1}}]", "test_case_ids": [ "0", "1" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
122
Count Ways Divide Circle Using N Non Intersecting Chords
C++
long long countWaysDivideCircleUsingNNonIntersectingChords(int a) {
[ "a" ]
def count_ways_divide_circle_using_n_non_intersecting_chords(A): n = (2 * A) dpArray = ([0] * (n + 1)) dpArray[0] = 1 dpArray[2] = 1 for i in range(4, (n + 1), 2): for j in range(0, (i - 1), 2): dpArray[i] += (dpArray[j] * dpArray[((i - 2) - j)]) return int(dpArray[n])
int count_ways_divide_circle_using_n_non_intersecting_chords(int A) { int n = 2 * A; int dpArray [ n + 1 ] = { 0 }; dpArray [ 0 ] = 1; dpArray [ 2 ] = 1; for ( int i = 4; i <= n; i += 2 ) { for ( int j = 0; j < i - 1; j += 2 ) { dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ); } } return dpArray [ 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 a, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(32, 55534064877048198); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 55534064877048198); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 14544636039226909); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 1002242216651368); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countWaysDivideCircleUsingNNonIntersectingChords", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 55534064877048198, \"inputs\": {\"a\": 32}}, {\"idx\": 1, \"outputs\": 55534064877048198, \"inputs\": {\"a\": 32}}, {\"idx\": 2, \"outputs\": 14544636039226909, \"inputs\": {\"a\": 31}}, {\"idx\": 3, \"outputs\": 1002242216651368, \"inputs\": {\"a\": 29}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
123
Count Words Appear Exactly Two Times Array Words
C++
int countWordsAppearExactlyTwoTimesArrayWords(vector<string> stri, int n) {
[ "stri", "n" ]
def count_words_appear_exactly_two_times_array_words(stri, n): m = dict() for i in range(n): m[stri[i]] = (m.get(stri[i], 0) + 1) res = 0 for i in m.values(): if (i == 2): res += 1 return res
int count_words_appear_exactly_two_times_array_words(vector<string> str, int n) { unordered_map < string, int > m; for ( int i = 0; i < n; i ++ ) m [ str [ i ] ] += 1; int res = 0; for ( auto it = m . begin ( ); it != m . end ( ); it ++ ) if ( ( it -> second == 2 ) ) res ++; return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<string> stri, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(stri, 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({\"hate\", \"love\", \"peace\", \"love\", \"peace\", \"hate\", \"love\", \"peace\", \"love\", \"peace\"}, 10, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"16\", \"946613197072\", \"532052\", \"42780833\", \"511552\", \"1241934\", \"4\", \"3444540\", \"47487223670074\", \"23753\", \"14158\", \"4\", \"95420017116714\", \"16\", \"0845\", \"689000748\", \"976403809728\", \"8922\", \"487784120896\", \"329\", \"611\", \"59101\", \"611\", \"2131059721\", \"53952148295020\", \"445948587\", \"3905249775372\", \"4683180907\", \"7169093\", \"01413852276627\", \"63\", \"5864\", \"40862536595\", \"2280304422294\", \"930028582\", \"05\", \"33447\"}, 32, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"001000100000\", \"1010\", \"01011\", \"11\", \"011\", \"1010\"}, 6, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"Om\", \"Om\", \"Shankar\", \"Tripathi\", \"Tom\", \"Jerry\", \"Jerry\"}, 7, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"2\", \"644\", \"2\", \"42484637089\", \"81578664\", \"0778\"}, 6, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"001000101\", \"011010\", \"1\", \"101010011\", \"011010\", \"01\", \"10111000101\", \"0\", \"1\", \"00101101\", \"0\", \"0\"}, 12, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"kl\", \"p sH\", \"PwCPMPu\", \"tQoIgPpk\", \"wtsNP WjS\", \"kl \", \"TXsFWgU\", \"kl\", \"AD\", \"NjjTyFGwNWZcB\", \"jpFQslbGbDI\", \"cEpGAgvpk\", \"EMaDkMOm\", \"YZuNZgfwDIjG\", \"k\", \"hJx jHmGpQYwQP\", \"CIETe\", \"RH\", \"Pj\", \"h\", \"DInR\", \"AEsqOvliQtz\", \"NwzHTALTt LS\", \"LwLR\", \"WvDCzlQF\", \"soJb\", \"WktoldCbWyTO\", \"pIdRJxY\", \"BmpWxjOwTXkjjL\", \"zmtCiQ\", \"g\", \"yBmDW\", \"QhaBZrQnOJaAJ\", \"u\", \"MGTwCKve\", \"UxYQrONag\", \"xsGSz\", \"dqNPTT\", \"U W\", \"ygJKvCEKDClby\", \"M\", \"yXJQHxjyDQDLkT\", \"oJmaREOEk YA\", \"zUwiwhSMdiC\", \"jYgZEktcdgLD\", \"fwyTAAW\", \"GENttdzeGY \"}, 43, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"938\", \"074209\", \"0949093096\", \"218622476\", \"71692175\", \"0714\", \"81217924991\", \"74016430795374\", \"52213147\", \"338\", \"939\", \"798161500954\", \"90528060774015\", \"68715\", \"75810\", \"43450\", \"8017\", \"0193164\", \"5945740\", \"212\", \"4589289\", \"2912211026\", \"0\", \"49\", \"8230114\", \"0733435391403\", \"5429\", \"10070\"}, 20, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"00\", \"0\", \"00\", \"0101111010100\", \"110\"}, 4, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({\"g\", \"h\", \"ok\", \"h\", \"ok\", \"sqozuC\", \"ut\", \"ZwRcG\", \"ok\", \"MR\", \"jHrWyy\", \"qaJlrokgRHuZH\", \"LjPNzDUKszYmCq\", \"g\", \"ZGjLfMnyAGL\", \"kEZoSxOMEWSFpw\", \"IFtqNaDVnG\", \"iJoJXl\", \"vjrQMyWor\", \"FTEHZqbHGlmHph\", \"QeSdzm\", \"nPostKHkigyJt\", \"mOSekk\"}, 15, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "countWordsAppearExactlyTwoTimesArrayWords", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"stri\": [\"hate\", \"love\", \"peace\", \"love\", \"peace\", \"hate\", \"love\", \"peace\", \"love\", \"peace\"], \"n\": 10}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"stri\": [\"16\", \"946613197072\", \"532052\", \"42780833\", \"511552\", \"1241934\", \"4\", \"3444540\", \"47487223670074\", \"23753\", \"14158\", \"4\", \"95420017116714\", \"16\", \"0845\", \"689000748\", \"976403809728\", \"8922\", \"487784120896\", \"329\", \"611\", \"59101\", \"611\", \"2131059721\", \"53952148295020\", \"445948587\", \"3905249775372\", \"4683180907\", \"7169093\", \"01413852276627\", \"63\", \"5864\", \"40862536595\", \"2280304422294\", \"930028582\", \"05\", \"33447\"], \"n\": 32}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"stri\": [\"001000100000\", \"1010\", \"01011\", \"11\", \"011\", \"1010\"], \"n\": 6}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"stri\": [\"Om\", \"Om\", \"Shankar\", \"Tripathi\", \"Tom\", \"Jerry\", \"Jerry\"], \"n\": 7}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"stri\": [\"2\", \"644\", \"2\", \"42484637089\", \"81578664\", \"0778\"], \"n\": 6}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"stri\": [\"001000101\", \"011010\", \"1\", \"101010011\", \"011010\", \"01\", \"10111000101\", \"0\", \"1\", \"00101101\", \"0\", \"0\"], \"n\": 12}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"stri\": [\"kl\", \"p sH\", \"PwCPMPu\", \"tQoIgPpk\", \"wtsNP WjS\", \"kl \", \"TXsFWgU\", \"kl\", \"AD\", \"NjjTyFGwNWZcB\", \"jpFQslbGbDI\", \"cEpGAgvpk\", \"EMaDkMOm\", \"YZuNZgfwDIjG\", \"k\", \"hJx jHmGpQYwQP\", \"CIETe\", \"RH\", \"Pj\", \"h\", \"DInR\", \"AEsqOvliQtz\", \"NwzHTALTt LS\", \"LwLR\", \"WvDCzlQF\", \"soJb\", \"WktoldCbWyTO\", \"pIdRJxY\", \"BmpWxjOwTXkjjL\", \"zmtCiQ\", \"g\", \"yBmDW\", \"QhaBZrQnOJaAJ\", \"u\", \"MGTwCKve\", \"UxYQrONag\", \"xsGSz\", \"dqNPTT\", \"U W\", \"ygJKvCEKDClby\", \"M\", \"yXJQHxjyDQDLkT\", \"oJmaREOEk YA\", \"zUwiwhSMdiC\", \"jYgZEktcdgLD\", \"fwyTAAW\", \"GENttdzeGY \"], \"n\": 43}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"stri\": [\"938\", \"074209\", \"0949093096\", \"218622476\", \"71692175\", \"0714\", \"81217924991\", \"74016430795374\", \"52213147\", \"338\", \"939\", \"798161500954\", \"90528060774015\", \"68715\", \"75810\", \"43450\", \"8017\", \"0193164\", \"5945740\", \"212\", \"4589289\", \"2912211026\", \"0\", \"49\", \"8230114\", \"0733435391403\", \"5429\", \"10070\"], \"n\": 20}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"stri\": [\"00\", \"0\", \"00\", \"0101111010100\", \"110\"], \"n\": 4}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"stri\": [\"g\", \"h\", \"ok\", \"h\", \"ok\", \"sqozuC\", \"ut\", \"ZwRcG\", \"ok\", \"MR\", \"jHrWyy\", \"qaJlrokgRHuZH\", \"LjPNzDUKszYmCq\", \"g\", \"ZGjLfMnyAGL\", \"kEZoSxOMEWSFpw\", \"IFtqNaDVnG\", \"iJoJXl\", \"vjrQMyWor\", \"FTEHZqbHGlmHph\", \"QeSdzm\", \"nPostKHkigyJt\", \"mOSekk\"], \"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 ] }
125
C Program Factorial Number
C++
int cProgramFactorialNumber(int n) {
[ "n" ]
def c_program_factorial_number(n): return (1 if ((n == 1) or (n == 0)) else (n * c_program_factorial_number((n - 1))))
unsigned int c_program_factorial_number(unsigned int n) { if ( n == 0 ) return 1; return n * c_program_factorial_number ( n - 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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(5, 120); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 479001600); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "cProgramFactorialNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 120, \"inputs\": {\"n\": 5}}, {\"idx\": 1, \"outputs\": 479001600, \"inputs\": {\"n\": 12}}]", "test_case_ids": [ "0", "1" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
126
C Program Factorial Number 1
C++
long long cProgramFactorialNumber1(int n) {
[ "n" ]
def c_program_factorial_number_1(n): return (1 if ((n == 1) or (n == 0)) else (n * c_program_factorial_number_1((n - 1))))
unsigned int c_program_factorial_number_1(unsigned int n) { int res = 1, i; for ( i = 2; i <= n; i ++ ) res *= 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(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(15, 1307674368000); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 5040); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 20922789888000); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 20922789888000); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "cProgramFactorialNumber1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1307674368000, \"inputs\": {\"n\": 15}}, {\"idx\": 1, \"outputs\": 5040, \"inputs\": {\"n\": 7}}, {\"idx\": 2, \"outputs\": 20922789888000, \"inputs\": {\"n\": 16}}, {\"idx\": 3, \"outputs\": 20922789888000, \"inputs\": {\"n\": 16}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
127
C Program Factorial Number 2
C++
long long cProgramFactorialNumber2(int n) {
[ "n" ]
def c_program_factorial_number_2(n): return (1 if ((n == 1) or (n == 0)) else (n * c_program_factorial_number_2((n - 1))))
int c_program_factorial_number_2(int n) { return ( n == 1 || n == 0 ) ? 1 : n * c_program_factorial_number_2 ( n - 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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(19, 121645100408832000); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "cProgramFactorialNumber2", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 121645100408832000, \"inputs\": {\"n\": 19}}]", "test_case_ids": [ "0" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
128
C Program Find Largest Element Array 1
C++
int cProgramFindLargestElementArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def c_program_find_largest_element_array_1(arr, n): return max(arr)
int c_program_find_largest_element_array_1(vector<int> arr, int n) { return * max_element(arr.begin(), arr.end()); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> 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, 12, 14, 16, 17, 17, 20, 24, 26, 28, 37, 38, 41, 45, 49, 50, 59, 61, 63, 65, 65, 66, 69, 70, 70, 73, 73, 74, 81, 81, 83, 87, 94, 97}, 17, 97); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-56, 38, -22, 84, -60, 2, 68, -78, 62, -98, 24, 26, 48, 62, -80, -14, -84, 12, -54, -12, -20, -82, 10, -34, -50, -72, 78, 16, 30, -76, 72, 34, 6, 52, 44, 18, -38, 48, -14}, 25, 84); \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}, 11, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({92, 5, 40, 65, 86, 51, 14, 29, 66, 6, 62, 92, 29, 13, 88, 54, 15, 60, 45, 2, 51, 9, 33, 51, 31, 11, 62, 61, 77, 38, 11, 4, 27, 54, 72, 64, 85, 46, 24, 44, 39, 73, 82, 85}, 40, 92); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -90, -84, -80, -80, -76, -70, -70, -48, -44, -38, -28, -14, -14, -12, -2, 2, 4, 6, 10, 16, 16, 20, 22, 24, 26, 50, 52, 56, 56, 58, 58, 74, 80, 82, 84, 86}, 33, 86); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0}, 29, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 19, 20, 26, 31, 32, 34, 37, 39, 40, 46, 46, 50, 53, 58, 58, 59, 65, 72, 72, 75, 76, 77, 78, 81, 83, 83, 95, 98, 99}, 28, 99); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32, -84, -84, 86, -24, 36, -12, 82, 48, -12, 82, -76, 84, -20, -12, -18, 46, -74, -14, -86}, 14, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 33, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({95, 73, 74, 14, 73, 74, 19, 93, 34, 53, 85, 75, 80, 15, 36, 57, 15, 98, 51, 37, 8, 9, 62, 71, 28, 24, 37, 53, 84, 76, 22, 48, 15, 19, 43, 88, 58, 38, 63, 68, 27, 22, 37, 76, 59, 66, 22}, 34, 98); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "cProgramFindLargestElementArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 97, \"inputs\": {\"arr\": [10, 12, 14, 16, 17, 17, 20, 24, 26, 28, 37, 38, 41, 45, 49, 50, 59, 61, 63, 65, 65, 66, 69, 70, 70, 73, 73, 74, 81, 81, 83, 87, 94, 97], \"n\": 17}}, {\"idx\": 1, \"outputs\": 84, \"inputs\": {\"arr\": [-56, 38, -22, 84, -60, 2, 68, -78, 62, -98, 24, 26, 48, 62, -80, -14, -84, 12, -54, -12, -20, -82, 10, -34, -50, -72, 78, 16, 30, -76, 72, 34, 6, 52, 44, 18, -38, 48, -14], \"n\": 25}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 11}}, {\"idx\": 3, \"outputs\": 92, \"inputs\": {\"arr\": [92, 5, 40, 65, 86, 51, 14, 29, 66, 6, 62, 92, 29, 13, 88, 54, 15, 60, 45, 2, 51, 9, 33, 51, 31, 11, 62, 61, 77, 38, 11, 4, 27, 54, 72, 64, 85, 46, 24, 44, 39, 73, 82, 85], \"n\": 40}}, {\"idx\": 4, \"outputs\": 86, \"inputs\": {\"arr\": [-92, -90, -84, -80, -80, -76, -70, -70, -48, -44, -38, -28, -14, -14, -12, -2, 2, 4, 6, 10, 16, 16, 20, 22, 24, 26, 50, 52, 56, 56, 58, 58, 74, 80, 82, 84, 86], \"n\": 33}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0], \"n\": 29}}, {\"idx\": 6, \"outputs\": 99, \"inputs\": {\"arr\": [5, 19, 20, 26, 31, 32, 34, 37, 39, 40, 46, 46, 50, 53, 58, 58, 59, 65, 72, 72, 75, 76, 77, 78, 81, 83, 83, 95, 98, 99], \"n\": 28}}, {\"idx\": 7, \"outputs\": 86, \"inputs\": {\"arr\": [32, -84, -84, 86, -24, 36, -12, 82, 48, -12, 82, -76, 84, -20, -12, -18, 46, -74, -14, -86], \"n\": 14}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 33}}, {\"idx\": 9, \"outputs\": 98, \"inputs\": {\"arr\": [95, 73, 74, 14, 73, 74, 19, 93, 34, 53, 85, 75, 80, 15, 36, 57, 15, 98, 51, 37, 8, 9, 62, 71, 28, 24, 37, 53, 84, 76, 22, 48, 15, 19, 43, 88, 58, 38, 63, 68, 27, 22, 37, 76, 59, 66, 22], \"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 ] }
129
Decimal Binary Conversion Without Using Arithmetic Operators
C++
string decimalBinaryConversionWithoutUsingArithmeticOperators(int n) {
[ "n" ]
def decimal_binary_conversion_without_using_arithmetic_operators(n): if (n == 0): return '0' bin = '' while (n > 0): if ((n & 1) == 0): bin = ('0' + bin) else: bin = ('1' + bin) n = (n >> 1) return bin
string decimal_binary_conversion_without_using_arithmetic_operators(int n) { if ( n == 0 ) return "0"; string bin = ""; while ( n > 0 ) { bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin; n >>= 1; } return bin; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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(int n, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(35, \"100011\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, \"10001\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, \"1000\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, \"1100011\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, \"111001\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, \"100111\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, \"1100011\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, \"1110\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, \"10110\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, \"111\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "decimalBinaryConversionWithoutUsingArithmeticOperators", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"100011\", \"inputs\": {\"n\": 35}}, {\"idx\": 1, \"outputs\": \"10001\", \"inputs\": {\"n\": 17}}, {\"idx\": 2, \"outputs\": \"1000\", \"inputs\": {\"n\": 8}}, {\"idx\": 3, \"outputs\": \"1100011\", \"inputs\": {\"n\": 99}}, {\"idx\": 4, \"outputs\": \"111001\", \"inputs\": {\"n\": 57}}, {\"idx\": 5, \"outputs\": \"100111\", \"inputs\": {\"n\": 39}}, {\"idx\": 6, \"outputs\": \"1100011\", \"inputs\": {\"n\": 99}}, {\"idx\": 7, \"outputs\": \"1110\", \"inputs\": {\"n\": 14}}, {\"idx\": 8, \"outputs\": \"10110\", \"inputs\": {\"n\": 22}}, {\"idx\": 9, \"outputs\": \"111\", \"inputs\": {\"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 ] }
130
Decimal Representation Given Binary String Divisible 10 Not
C++
bool decimalRepresentationGivenBinaryStringDivisible10Not(string bin) {
[ "bin" ]
def decimal_representation_given_binary_string_divisible_10_not(bin): n = len(bin) if (bin[(n - 1)] == '1'): return False sum = 0 i = (n - 2) while (i >= 0): if (bin[i] == '1'): posFromRight = ((n - i) - 1) if ((posFromRight % 4) == 1): sum = (sum + 2) elif ((posFromRight % 4) == 2): sum = (sum + 4) elif ((posFromRight % 4) == 3): sum = (sum + 8) elif ((posFromRight % 4) == 0): sum = (sum + 6) i = (i - 1) if ((sum % 10) == 0): return True return False
bool decimal_representation_given_binary_string_divisible_10_not(string bin) { int n = bin . size ( ); if ( bin [ n - 1 ] == '1' ) return false; int sum = 0; for ( int i = n - 2; i >= 0; i -- ) { if ( bin [ i ] == '1' ) { int posFromRight = n - i - 1; if ( posFromRight % 4 == 1 ) sum = sum + 2; else if ( posFromRight % 4 == 2 ) sum = sum + 4; else if ( posFromRight % 4 == 3 ) sum = sum + 8; else if ( posFromRight % 4 == 0 ) sum = sum + 6; } } if ( sum % 10 == 0 ) return true; return false; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string bin, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(bin), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"101000\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"39613456759141\", false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"11\", false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"PoiHjo\", true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2\", true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0000101\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"T s dZKeDX gK\", true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"3944713969\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1000\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"ifYUgdpmt\", true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "decimalRepresentationGivenBinaryStringDivisible10Not", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"bin\": \"101000\"}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"bin\": \"39613456759141\"}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"bin\": \"11\"}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"bin\": \"PoiHjo\"}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"bin\": \"2\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"bin\": \"0000101\"}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"bin\": \"T s dZKeDX gK\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"bin\": \"3944713969\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"bin\": \"1000\"}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"bin\": \"ifYUgdpmt\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
131
Decode Median String Original String
C++
string decodeMedianStringOriginalString(string s) {
[ "s" ]
def decode_median_string_original_string(s): l = len(s) s1 = '' if ((l % 2) == 0): isEven = True else: isEven = False for i in range(0, l, 2): if isEven: s1 = (s[i] + s1) s1 += s[(i + 1)] elif ((l - i) > 1): s1 += s[i] s1 = (s[(i + 1)] + s1) else: s1 += s[i] return s1
string decode_median_string_original_string(string s) { int l = s . length ( ); string s1 = ""; bool isEven = ( l % 2 == 0 ) ? true : false; for ( int i = 0; i < l; i += 2 ) { if ( isEven ) { s1 = s [ i ] + s1; s1 += s [ i + 1 ]; } else { if ( l - i > 1 ) { s1 += s [ i ]; s1 = s [ i + 1 ] + s1; } else { s1 += s [ i ]; } } } return s1; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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(\" EgvQCeqYpZtv\", \"tpqCvE gQeYZv\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"488540\", \"484850\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0000101010111\", \"1000000011111\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"syw\", \"ysw\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"402355\", \"524035\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0\", \"0\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"wmHMlAtq\", \"tlHwmMAq\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"7962\", \"6792\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111111\", \"111111\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"UbgRGDquop\", \"oqGgUbRDup\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "decodeMedianStringOriginalString", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"tpqCvE gQeYZv\", \"inputs\": {\"s\": \" EgvQCeqYpZtv\"}}, {\"idx\": 1, \"outputs\": \"484850\", \"inputs\": {\"s\": \"488540\"}}, {\"idx\": 2, \"outputs\": \"1000000011111\", \"inputs\": {\"s\": \"0000101010111\"}}, {\"idx\": 3, \"outputs\": \"ysw\", \"inputs\": {\"s\": \"syw\"}}, {\"idx\": 4, \"outputs\": \"524035\", \"inputs\": {\"s\": \"402355\"}}, {\"idx\": 5, \"outputs\": \"0\", \"inputs\": {\"s\": \"0\"}}, {\"idx\": 6, \"outputs\": \"tlHwmMAq\", \"inputs\": {\"s\": \"wmHMlAtq\"}}, {\"idx\": 7, \"outputs\": \"6792\", \"inputs\": {\"s\": \"7962\"}}, {\"idx\": 8, \"outputs\": \"111111\", \"inputs\": {\"s\": \"111111\"}}, {\"idx\": 9, \"outputs\": \"oqGgUbRDup\", \"inputs\": {\"s\": \"UbgRGDquop\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
132
Detect If Two Integers Have Opposite Signs
C++
bool detectIfTwoIntegersHaveOppositeSigns(int x, int y) {
[ "x", "y" ]
def detect_if_two_integers_have_opposite_signs(x, y): return ((x ^ y) < 0)
bool detect_if_two_integers_have_opposite_signs(int x, int y) { return ( ( x ^ y ) < 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 x, int y, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(59, -99, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-20, -21, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-100, 79, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, -49, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-16, 16, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-23, -68, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 37, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, -61, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-8, 69, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, 10, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "detectIfTwoIntegersHaveOppositeSigns", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"x\": 59, \"y\": -99}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"x\": -20, \"y\": -21}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"x\": -100, \"y\": 79}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"x\": 54, \"y\": -49}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"x\": -16, \"y\": 16}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"x\": -23, \"y\": -68}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"x\": 93, \"y\": 37}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"x\": 24, \"y\": -61}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"x\": -8, \"y\": 69}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"x\": 29, \"y\": 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 ] }
133
Dice Throw Problem
C++
int diceThrowProblem(int m, int n, int x) {
[ "m", "n", "x" ]
def dice_throw_problem(m, n, x): table = [([0] * (x + 1)) for i in range((n + 1))] for j in range(1, min((m + 1), (x + 1))): table[1][j] = 1 for i in range(2, (n + 1)): for j in range(1, (x + 1)): for k in range(1, min((m + 1), j)): table[i][j] += table[(i - 1)][(j - k)] return table[(- 1)][(- 1)]
int dice_throw_problem(int m, int n, int x) { int table [ n + 1 ] [ x + 1 ]; memset ( table, 0, sizeof ( table ) ); for ( int j = 1; j <= m && j <= x; j ++ ) table [ 1 ] [ j ] = 1; for ( int i = 2; i <= n; i ++ ) for ( int j = 1; j <= x; j ++ ) for ( int k = 1; k <= m && k < j; k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ]; return table [ n ] [ 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 m, int n, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(m, n, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(94, 4, 69, 50116); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 12, 33, 77635844); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 44, 24, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 94, 88, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 58, 27, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 90, 29, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 25, 6, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 82, 70, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 83, 19, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "diceThrowProblem", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 50116, \"inputs\": {\"m\": 94, \"n\": 4, \"x\": 69}}, {\"idx\": 1, \"outputs\": 77635844, \"inputs\": {\"m\": 7, \"n\": 12, \"x\": 33}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"m\": 20, \"n\": 44, \"x\": 24}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"m\": 90, \"n\": 94, \"x\": 88}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"m\": 50, \"n\": 58, \"x\": 27}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"m\": 32, \"n\": 90, \"x\": 29}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"m\": 46, \"n\": 25, \"x\": 6}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"m\": 43, \"n\": 82, \"x\": 70}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"m\": 6, \"n\": 83, \"x\": 19}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
134
Dice Throw Problem 1
C++
long long diceThrowProblem1(int f, int d, int s) {
[ "f", "d", "s" ]
def dice_throw_problem_1(f, d, s): mem = [[0 for i in range((s + 1))] for j in range((d + 1))] mem[0][0] = 1 for i in range(1, (d + 1)): for j in range(1, (s + 1)): mem[i][j] = (mem[i][(j - 1)] + mem[(i - 1)][(j - 1)]) if (((j - f) - 1) >= 0): mem[i][j] -= mem[(i - 1)][((j - f) - 1)] return mem[d][s]
long dice_throw_problem_1(int f, int d, int s) { long mem [ d + 1 ] [ s + 1 ]; memset ( mem, 0, sizeof mem ); mem [ 0 ] [ 0 ] = 1; for ( int i = 1; i <= d; i ++ ) { for ( int j = i; j <= s; j ++ ) { mem [ i ] [ j ] = mem [ i ] [ j - 1 ] + mem [ i - 1 ] [ j - 1 ]; if ( j - f - 1 >= 0 ) mem [ i ] [ j ] -= mem [ i - 1 ] [ j - f - 1 ]; } } return mem [ d ] [ 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(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int f, int d, int s, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(f, d, 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(57, 5, 33, 35960); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 45, 4, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 89, 9, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 39, 30, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(91, 90, 47, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 56, 46, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 26, 52, 247959266474052); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 90, 90, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 2, 26, 25); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "diceThrowProblem1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 35960, \"inputs\": {\"f\": 57, \"d\": 5, \"s\": 33}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"f\": 58, \"d\": 45, \"s\": 4}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"f\": 38, \"d\": 89, \"s\": 9}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"f\": 5, \"d\": 39, \"s\": 30}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"f\": 91, \"d\": 90, \"s\": 47}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"f\": 76, \"d\": 56, \"s\": 46}}, {\"idx\": 6, \"outputs\": 247959266474052, \"inputs\": {\"f\": 97, \"d\": 26, \"s\": 52}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"f\": 97, \"d\": 90, \"s\": 90}}, {\"idx\": 8, \"outputs\": 25, \"inputs\": {\"f\": 99, \"d\": 2, \"s\": 26}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
135
Difference Between Highest And Least Frequencies In An Array
C++
int differenceBetweenHighestAndLeastFrequenciesInAnArray(vector<int> arr, int n) {
[ "arr", "n" ]
def difference_between_highest_and_least_frequencies_in_an_array(arr, n): arr.sort() count = 0 max_count = 0 min_count = n for i in range(0, (n - 1)): if (arr[i] == arr[(i + 1)]): count += 1 continue else: max_count = max(max_count, count) min_count = min(min_count, count) count = 0 return (max_count - min_count)
int difference_between_highest_and_least_frequencies_in_an_array(vector<int> arr, int n) { sort(arr.begin(), arr.end()); int count = 0, max_count = 0, min_count = n; for ( int i = 0; i < ( n - 1 ); i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { count += 1; continue; } else { max_count = max ( max_count, count ); min_count = min ( min_count, count ); count = 0; } } return ( max_count - min_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({5, 15, 19, 22, 28, 29, 39, 46, 46, 49, 51, 55, 62, 69, 72, 72, 72, 74, 79, 92, 92, 93, 95, 96}, 15, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -92, -78, -74, -70, -66, -60, -54, -50, -48, -34, -32, -26, -24, -22, -14, -10, -10, -6, 2, 4, 6, 12, 18, 34, 42, 52, 56, 76, 92, 92}, 30, 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, 1, 1, 1, 1, 1, 1, 1}, 24, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 5, 13, 17, 21, 22, 25, 26, 29, 29, 31, 32, 35, 38, 40, 46, 48, 48, 49, 53, 54, 59, 61, 65, 65, 66, 73, 79, 81, 83, 92, 92, 93, 96, 97, 98}, 29, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-70, -34, -32, -30, -14, 80, 86, 90}, 4, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({9}, 0, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 42, 70, 94}, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 24, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 7, 8, 10, 15, 15, 17, 22, 26, 49, 55, 60, 64, 76, 79, 80, 84, 90, 92, 95, 96}, 20, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "differenceBetweenHighestAndLeastFrequenciesInAnArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [5, 15, 19, 22, 28, 29, 39, 46, 46, 49, 51, 55, 62, 69, 72, 72, 72, 74, 79, 92, 92, 93, 95, 96], \"n\": 15}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"arr\": [-92, -92, -78, -74, -70, -66, -60, -54, -50, -48, -34, -32, -26, -24, -22, -14, -10, -10, -6, 2, 4, 6, 12, 18, 34, 42, 52, 56, 76, 92, 92], \"n\": 30}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 24}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [1, 5, 13, 17, 21, 22, 25, 26, 29, 29, 31, 32, 35, 38, 40, 46, 48, 48, 49, 53, 54, 59, 61, 65, 65, 66, 73, 79, 81, 83, 92, 92, 93, 96, 97, 98], \"n\": 29}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-70, -34, -32, -30, -14, 80, 86, 90], \"n\": 4}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 23}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [9], \"n\": 0}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [10, 42, 70, 94], \"n\": 2}}, {\"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], \"n\": 24}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [3, 4, 7, 8, 10, 15, 15, 17, 22, 26, 49, 55, 60, 64, 76, 79, 80, 84, 90, 92, 95, 96], \"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 ] }
136
Difference Maximum Sum Minimum Sum N M Elementsin Review
C++
int differenceMaximumSumMinimumSumNMElementsinReview(vector<int> arr, int n, int m) {
[ "arr", "n", "m" ]
def difference_maximum_sum_minimum_sum_n_m_elementsin_review(arr, n, m): max = 0 min = 0 arr.sort() j = (n - 1) for i in range(m): min += arr[i] max += arr[j] j = (j - 1) return (max - min)
int difference_maximum_sum_minimum_sum_n_m_elementsin_review(vector<int> arr, int n, int m) { int max = 0, min = 0; sort(arr.begin(), arr.end()); for ( int i = 0, j = n - 1; i < m; i ++, j -- ) { min += arr [ i ]; max += arr [ j ]; } return ( max - min ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int m, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, m), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({2, 3, 6, 16, 21, 22, 23, 27, 27, 28, 29, 29, 31, 31, 37, 37, 38, 40, 41, 43, 51, 52, 53, 55, 55, 56, 57, 63, 67, 67, 67, 72, 75, 79, 82, 84, 91, 92, 93, 96, 96, 97}, 21, 25, 167); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -62, -50, -40, -32, -30, -18, -16, -14, -10, 24, 48, 54, 58, 94}, 8, 12, 206); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0}, 1, 1, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 2, 4, 5, 6, 7, 9, 10, 11, 11, 12, 13, 13, 16, 17, 21, 24, 29, 29, 34, 44, 44, 48, 49, 51, 54, 56, 59, 62, 63, 65, 65, 65, 71, 71, 76, 77, 77, 80, 83, 83, 84, 89, 91, 97, 99}, 31, 34, 92); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -58, 6, 16, 20, 34, 36, 38, 48, 66, 82, 84, 86, 90, 90}, 14, 8, 528); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1}, 3, 2, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 12, 15, 15, 21, 37, 40, 45, 50, 52, 53, 68, 68, 72, 75, 78, 86, 86, 88}, 16, 18, 2); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -20, 22, 44, 72, 94}, 4, 3, 132); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, 17, 8); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 11, 21, 25, 26, 30, 32, 38, 60, 63, 65, 75, 77, 87, 87, 96}, 12, 15, 19); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "differenceMaximumSumMinimumSumNMElementsinReview", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 167, \"inputs\": {\"arr\": [2, 3, 6, 16, 21, 22, 23, 27, 27, 28, 29, 29, 31, 31, 37, 37, 38, 40, 41, 43, 51, 52, 53, 55, 55, 56, 57, 63, 67, 67, 67, 72, 75, 79, 82, 84, 91, 92, 93, 96, 96, 97], \"n\": 21, \"m\": 25}}, {\"idx\": 1, \"outputs\": 206, \"inputs\": {\"arr\": [-92, -62, -50, -40, -32, -30, -18, -16, -14, -10, 24, 48, 54, 58, 94], \"n\": 8, \"m\": 12}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0], \"n\": 1, \"m\": 1}}, {\"idx\": 3, \"outputs\": 92, \"inputs\": {\"arr\": [1, 2, 2, 4, 5, 6, 7, 9, 10, 11, 11, 12, 13, 13, 16, 17, 21, 24, 29, 29, 34, 44, 44, 48, 49, 51, 54, 56, 59, 62, 63, 65, 65, 65, 71, 71, 76, 77, 77, 80, 83, 83, 84, 89, 91, 97, 99], \"n\": 31, \"m\": 34}}, {\"idx\": 4, \"outputs\": 528, \"inputs\": {\"arr\": [-90, -58, 6, 16, 20, 34, 36, 38, 48, 66, 82, 84, 86, 90, 90], \"n\": 14, \"m\": 8}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 1, 1], \"n\": 3, \"m\": 2}}, {\"idx\": 6, \"outputs\": 2, \"inputs\": {\"arr\": [7, 12, 15, 15, 21, 37, 40, 45, 50, 52, 53, 68, 68, 72, 75, 78, 86, 86, 88], \"n\": 16, \"m\": 18}}, {\"idx\": 7, \"outputs\": 132, \"inputs\": {\"arr\": [-88, -20, 22, 44, 72, 94], \"n\": 4, \"m\": 3}}, {\"idx\": 8, \"outputs\": 8, \"inputs\": {\"arr\": [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\": 25, \"m\": 17}}, {\"idx\": 9, \"outputs\": 19, \"inputs\": {\"arr\": [4, 11, 21, 25, 26, 30, 32, 38, 60, 63, 65, 75, 77, 87, 87, 96], \"n\": 12, \"m\": 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 ] }
137
Distributing Items Person Cannot Take Two Items Type
C++
bool distributingItemsPersonCannotTakeTwoItemsType(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def distributing_items_person_cannot_take_two_items_type(arr, n, k): for i in range(n): count = 0 for j in range(n): if (arr[j] == arr[i]): count += 1 if (count > (2 * k)): return False return True
bool distributing_items_person_cannot_take_two_items_type(vector<int> arr, int n, int k) { int count; for ( int i = 0; i < n; i ++ ) { count = 0; for ( int j = 0; j < n; j ++ ) { if ( arr [ j ] == arr [ i ] ) count ++; if ( count > 2 * k ) return false; } } return true; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int k, bool 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, 3, 1}, 5, 2, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 3, 3, 5, 3, 3}, 6, 2, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1}, 2, 1, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 60, 78, 91, 80, 75, 85, 21, 41, 63, 1, 84, 69, 13, 94, 25, 54, 54, 52, 68, 53, 35, 17, 37, 98, 27, 2, 31}, 24, 2, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -82, -80, -78, -66, -36, -24, -18, -12, -2, -2, 6, 8, 10, 12, 36, 38, 42, 58, 64, 68, 82, 84, 86, 88, 94}, 24, 3, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0}, 34, 2, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, 19, 25, 25, 32, 37, 48, 59, 60, 60, 71, 74, 77, 81, 91, 94}, 10, 8, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-62, -94, 72, -22, 86, -80, 64, 98, -82, -50, 12, -4, 56, 46, -80, 2, -86, -44, -26, 68, -94, -82, 74, 26, 94, 40, 50, -40, -42, -10}, 20, 4, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1}, 5, 2, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({83, 57, 2, 47, 70, 22, 49, 51, 25, 57, 32, 7, 8, 99, 6, 86, 24, 79, 42, 43, 1, 24, 68, 11, 24, 12, 43, 40, 14, 45, 11, 46, 12, 80, 66}, 21, 33, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "distributingItemsPersonCannotTakeTwoItemsType", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"arr\": [1, 1, 2, 3, 1], \"n\": 5, \"k\": 2}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"arr\": [2, 3, 3, 5, 3, 3], \"n\": 6, \"k\": 2}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"arr\": [0, 0, 1, 1, 1], \"n\": 2, \"k\": 1}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"arr\": [7, 60, 78, 91, 80, 75, 85, 21, 41, 63, 1, 84, 69, 13, 94, 25, 54, 54, 52, 68, 53, 35, 17, 37, 98, 27, 2, 31], \"n\": 24, \"k\": 2}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"arr\": [-96, -94, -82, -80, -78, -66, -36, -24, -18, -12, -2, -2, 6, 8, 10, 12, 36, 38, 42, 58, 64, 68, 82, 84, 86, 88, 94], \"n\": 24, \"k\": 3}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"arr\": [0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0], \"n\": 34, \"k\": 2}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"arr\": [16, 19, 25, 25, 32, 37, 48, 59, 60, 60, 71, 74, 77, 81, 91, 94], \"n\": 10, \"k\": 8}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"arr\": [-62, -94, 72, -22, 86, -80, 64, 98, -82, -50, 12, -4, 56, 46, -80, 2, -86, -44, -26, 68, -94, -82, 74, 26, 94, 40, 50, -40, -42, -10], \"n\": 20, \"k\": 4}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1], \"n\": 5, \"k\": 2}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"arr\": [83, 57, 2, 47, 70, 22, 49, 51, 25, 57, 32, 7, 8, 99, 6, 86, 24, 79, 42, 43, 1, 24, 68, 11, 24, 12, 43, 40, 14, 45, 11, 46, 12, 80, 66], \"n\": 21, \"k\": 33}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
138
Distributing M Items Circle Size N Starting K Th Position
C++
int distributingMItemsCircleSizeNStartingKThPosition(int n, int m, int k) {
[ "n", "m", "k" ]
def distributing_m_items_circle_size_n_starting_k_th_position(n, m, k): if (m <= ((n - k) + 1)): return ((m + k) - 1) m = (m - ((n - k) + 1)) if ((m % n) == 0): return n else: return (m % n)
int distributing_m_items_circle_size_n_starting_k_th_position(int n, int m, int k) { if ( m <= n - k + 1 ) return m + k - 1; m = m - ( n - k + 1 ); return ( m % n == 0 ) ? n : ( m % n ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int m, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, m, 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(19, 14, 34, 9); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 51, 5, 9); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 10, 24, 33); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 50, 34, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 67, 20, 6); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 25, 40, 64); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 30, 24, 53); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 22, 32, 53); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 1, 71, 71); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 34, 54, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "distributingMItemsCircleSizeNStartingKThPosition", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 9, \"inputs\": {\"n\": 19, \"m\": 14, \"k\": 34}}, {\"idx\": 1, \"outputs\": 9, \"inputs\": {\"n\": 23, \"m\": 51, \"k\": 5}}, {\"idx\": 2, \"outputs\": 33, \"inputs\": {\"n\": 92, \"m\": 10, \"k\": 24}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"n\": 9, \"m\": 50, \"k\": 34}}, {\"idx\": 4, \"outputs\": 6, \"inputs\": {\"n\": 20, \"m\": 67, \"k\": 20}}, {\"idx\": 5, \"outputs\": 64, \"inputs\": {\"n\": 68, \"m\": 25, \"k\": 40}}, {\"idx\": 6, \"outputs\": 53, \"inputs\": {\"n\": 66, \"m\": 30, \"k\": 24}}, {\"idx\": 7, \"outputs\": 53, \"inputs\": {\"n\": 77, \"m\": 22, \"k\": 32}}, {\"idx\": 8, \"outputs\": 71, \"inputs\": {\"n\": 90, \"m\": 1, \"k\": 71}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"n\": 26, \"m\": 34, \"k\": 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 ] }
139
Divisibility 9 Using Bitwise Operators
C++
bool divisibility9UsingBitwiseOperators(int n) {
[ "n" ]
def divisibility_9_using_bitwise_operators(n): if ((n == 0) or (n == 9)): return True if (n < 9): return False return divisibility_9_using_bitwise_operators((int((n >> 3)) - int((n & 7))))
bool divisibility_9_using_bitwise_operators(int n) { if ( n == 0 || n == 9 ) return true; if ( n < 9 ) return false; return divisibility_9_using_bitwise_operators ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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(96, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, false); \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(49, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "divisibility9UsingBitwiseOperators", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"n\": 96}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"n\": 85}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 54}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": 14}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 47}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 11}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 49}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"n\": 99}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 28}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 82}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
140
Divisibility By 7
C++
bool divisibilityBy7(int num) {
[ "num" ]
def divisibility_by_7(num): if (num < 0): return divisibility_by_7((- num)) if ((num == 0) or (num == 7)): return True if (num < 10): return False return divisibility_by_7(((num / 10) - (2 * (num - ((num / 10) * 10)))))
int divisibility_by_7(int num) { if ( num < 0 ) return divisibility_by_7 ( - num ); if ( num == 0 || num == 7 ) return 1; if ( num < 10 ) return 0; return divisibility_by_7 ( num / 10 - 2 * ( num - num / 10 * 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(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int num, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(0, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-21, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-10, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "divisibilityBy7", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"num\": 0}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"num\": -21}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"num\": 7}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"num\": 63}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"num\": 84}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"num\": 73}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"num\": 81}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"num\": -10}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"num\": 47}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"num\": 23}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
141
Double Factorial
C++
long long doubleFactorial(int n) {
[ "n" ]
def double_factorial(n): if ((n == 0) or (n == 1)): return 1 return (n * double_factorial((n - 2)))
unsigned int double_factorial(unsigned int n) { if ( n == 0 || n == 1 ) return 1; return n * double_factorial ( 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(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(15, 2027025); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 13749310575); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "doubleFactorial", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2027025, \"inputs\": {\"n\": 15}}, {\"idx\": 1, \"outputs\": 13749310575, \"inputs\": {\"n\": 21}}]", "test_case_ids": [ "0", "1" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
142
Double Factorial 1
C++
long long doubleFactorial1(int n) {
[ "n" ]
def double_factorial_1(n): res = 1 for i in range(n, (- 1), (- 2)): if ((i == 0) or (i == 1)): return res else: res *= i
unsigned int double_factorial_1(unsigned int n) { int res = 1; for ( int i = n; i >= 0; i = i - 2 ) { if ( i == 0 || i == 1 ) return res; else res *= i; } }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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, 1961990553600); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 81749606400); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 2); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 42849873690624000); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "doubleFactorial1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1961990553600, \"inputs\": {\"n\": 24}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"n\": 3}}, {\"idx\": 2, \"outputs\": 81749606400, \"inputs\": {\"n\": 22}}, {\"idx\": 3, \"outputs\": 2, \"inputs\": {\"n\": 2}}, {\"idx\": 4, \"outputs\": 42849873690624000, \"inputs\": {\"n\": 30}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": 2}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
143
Dyck Path
C++
double dyckPath(int n) {
[ "n" ]
def dyck_path(n): res = 1 for i in range(0, n): res *= ((2 * n) - i) res /= (i + 1) return (res / (n + 1))
int dyck_path(unsigned int n) { int res = 1; for ( int i = 0; i < n; ++ i ) { res *= ( 2 * n - i ); res /= ( i + 1 ); } return res / ( n + 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int n, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(28, 263747951750360.03); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 742900.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 429.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "dyckPath", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 263747951750360.03, \"inputs\": {\"n\": 28}}, {\"idx\": 1, \"outputs\": 742900.0, \"inputs\": {\"n\": 13}}, {\"idx\": 2, \"outputs\": 429.0, \"inputs\": {\"n\": 7}}]", "test_case_ids": [ "0", "1", "2" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
144
Dynamic Programming High Effort Vs Low Effort Tasks Problem
C++
int dynamicProgrammingHighEffortVsLowEffortTasksProblem(vector<int> high, vector<int> low, int n) {
[ "high", "low", "n" ]
def dynamic_programming_high_effort_vs_low_effort_tasks_problem(high, low, n): if (n <= 0): return 0 return max((high[(n - 1)] + dynamic_programming_high_effort_vs_low_effort_tasks_problem(high, low, (n - 2))), (low[(n - 1)] + dynamic_programming_high_effort_vs_low_effort_tasks_problem(high, low, (n - 1))))
int dynamic_programming_high_effort_vs_low_effort_tasks_problem(vector<int> high, vector<int> low, int n) { if ( n <= 0 ) return 0; return max ( high [ n - 1 ] + dynamic_programming_high_effort_vs_low_effort_tasks_problem ( high, low, ( n - 2 ) ), low [ n - 1 ] + dynamic_programming_high_effort_vs_low_effort_tasks_problem ( high, low, ( 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> high, vector<int> low, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(high, low, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 3, 9, 10, 13, 14, 15, 15, 17, 22, 23, 28, 30, 31, 37, 42, 45, 62, 62, 68, 68, 68, 78, 79, 82, 84, 87, 90, 99}, {5, 10, 11, 14, 16, 22, 24, 30, 34, 35, 37, 37, 39, 41, 42, 42, 43, 55, 57, 63, 71, 76, 83, 83, 85, 90, 91, 97, 99}, 18, 537); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, -12, 26, 80, 50, 4, -80, 86, 12, -2, 18, -50, -90, 56, -50, 88, -62, 96, -44, -82, 56}, {-44, -14, 14, 0, 30, 78, 40, -12, -44, -16, 60, -12, -50, -66, 70, -98, -56, 48, -82, 94, 14}, 16, 452); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1}, {1}, 0, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({21, 28, 13, 48, 26, 49, 16, 70, 81, 35, 74, 12, 97, 61, 10, 84, 94, 78, 40, 30, 30, 84, 41, 4, 95, 79, 38, 29, 9}, {49, 88, 25, 93, 24, 56, 47, 44, 33, 27, 86, 57, 21, 25, 64, 44, 37, 99, 36, 54, 17, 29, 37, 17, 26, 43, 61, 27, 21}, 25, 1261); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -36, -32, -20, -14, -12, 10, 12, 72}, {-76, -54, -50, -28, 0, 58, 70, 78, 90}, 4, -56); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}, {0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1}, 24, 15); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 7, 9, 10, 13, 14, 15, 20, 23, 24, 24, 24, 26, 27, 29, 31, 32, 33, 34, 35, 46, 48, 49, 51, 51, 53, 53, 56, 56, 60, 62, 64, 64, 70, 73, 73, 73, 74, 77, 78, 79, 79, 79, 80, 86, 89, 89, 92, 98}, {1, 3, 3, 4, 8, 8, 10, 10, 10, 12, 12, 15, 15, 22, 23, 28, 28, 30, 31, 33, 34, 35, 36, 36, 36, 42, 44, 44, 51, 54, 57, 58, 59, 59, 63, 65, 66, 68, 69, 71, 73, 76, 77, 78, 79, 79, 86, 87, 93}, 31, 784); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({56, 48, 40, -56, 44, -86, -28, -32, -34, 4, -94, -14, 28, -74}, {82, -40, -16, -64, 12, -6, 60, 48, -58, -4, 42, -28, 24, -58}, 8, 268); \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}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, 16, 5); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 13, 35, 57, 8, 48, 65, 54, 88, 7, 66, 30, 47, 51}, {1, 42, 42, 89, 3, 21, 49, 98, 4, 59, 26, 85, 53, 34}, 8, 453); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "dynamicProgrammingHighEffortVsLowEffortTasksProblem", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 537, \"inputs\": {\"high\": [1, 3, 9, 10, 13, 14, 15, 15, 17, 22, 23, 28, 30, 31, 37, 42, 45, 62, 62, 68, 68, 68, 78, 79, 82, 84, 87, 90, 99], \"low\": [5, 10, 11, 14, 16, 22, 24, 30, 34, 35, 37, 37, 39, 41, 42, 42, 43, 55, 57, 63, 71, 76, 83, 83, 85, 90, 91, 97, 99], \"n\": 18}}, {\"idx\": 1, \"outputs\": 452, \"inputs\": {\"high\": [-78, -12, 26, 80, 50, 4, -80, 86, 12, -2, 18, -50, -90, 56, -50, 88, -62, 96, -44, -82, 56], \"low\": [-44, -14, 14, 0, 30, 78, 40, -12, -44, -16, 60, -12, -50, -66, 70, -98, -56, 48, -82, 94, 14], \"n\": 16}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"high\": [1], \"low\": [1], \"n\": 0}}, {\"idx\": 3, \"outputs\": 1261, \"inputs\": {\"high\": [21, 28, 13, 48, 26, 49, 16, 70, 81, 35, 74, 12, 97, 61, 10, 84, 94, 78, 40, 30, 30, 84, 41, 4, 95, 79, 38, 29, 9], \"low\": [49, 88, 25, 93, 24, 56, 47, 44, 33, 27, 86, 57, 21, 25, 64, 44, 37, 99, 36, 54, 17, 29, 37, 17, 26, 43, 61, 27, 21], \"n\": 25}}, {\"idx\": 4, \"outputs\": -56, \"inputs\": {\"high\": [-80, -36, -32, -20, -14, -12, 10, 12, 72], \"low\": [-76, -54, -50, -28, 0, 58, 70, 78, 90], \"n\": 4}}, {\"idx\": 5, \"outputs\": 15, \"inputs\": {\"high\": [1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1], \"low\": [0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1], \"n\": 24}}, {\"idx\": 6, \"outputs\": 784, \"inputs\": {\"high\": [1, 7, 9, 10, 13, 14, 15, 20, 23, 24, 24, 24, 26, 27, 29, 31, 32, 33, 34, 35, 46, 48, 49, 51, 51, 53, 53, 56, 56, 60, 62, 64, 64, 70, 73, 73, 73, 74, 77, 78, 79, 79, 79, 80, 86, 89, 89, 92, 98], \"low\": [1, 3, 3, 4, 8, 8, 10, 10, 10, 12, 12, 15, 15, 22, 23, 28, 28, 30, 31, 33, 34, 35, 36, 36, 36, 42, 44, 44, 51, 54, 57, 58, 59, 59, 63, 65, 66, 68, 69, 71, 73, 76, 77, 78, 79, 79, 86, 87, 93], \"n\": 31}}, {\"idx\": 7, \"outputs\": 268, \"inputs\": {\"high\": [56, 48, 40, -56, 44, -86, -28, -32, -34, 4, -94, -14, 28, -74], \"low\": [82, -40, -16, -64, 12, -6, 60, 48, -58, -4, 42, -28, 24, -58], \"n\": 8}}, {\"idx\": 8, \"outputs\": 5, \"inputs\": {\"high\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"low\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"n\": 16}}, {\"idx\": 9, \"outputs\": 453, \"inputs\": {\"high\": [85, 13, 35, 57, 8, 48, 65, 54, 88, 7, 66, 30, 47, 51], \"low\": [1, 42, 42, 89, 3, 21, 49, 98, 4, 59, 26, 85, 53, 34], \"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 ] }
145
Dynamic Programming Set 14 Maximum Sum Increasing Subsequence
C++
int dynamicProgrammingSet14MaximumSumIncreasingSubsequence(vector<int> arr, int n) {
[ "arr", "n" ]
def dynamic_programming_set_14_maximum_sum_increasing_subsequence(arr, n): max = 0 msis = [0 for x in range(n)] for i in range(n): msis[i] = arr[i] for i in range(1, n): for j in range(i): if ((arr[i] > arr[j]) and (msis[i] < (msis[j] + arr[i]))): msis[i] = (msis[j] + arr[i]) for i in range(n): if (max < msis[i]): max = msis[i] return max
int dynamic_programming_set_14_maximum_sum_increasing_subsequence(vector<int> arr, int n) { int i, j, max = 0; int msis [ n ]; for ( i = 0; i < n; i ++ ) msis [ i ] = arr [ i ]; for ( i = 1; i < n; i ++ ) for ( j = 0; j < i; j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ]; for ( i = 0; i < n; i ++ ) if ( max < msis [ i ] ) max = msis [ 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, 7, 12, 23, 31, 31, 45, 47, 60, 67, 70, 84, 85, 91, 96}, 11, 301); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -38, -50, -14, 36, -32, 0, -8, -12, -62, -46, 66, -46, -26, 6, -44, 14, -74, -84, 52, -28}, 18, 102); \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}, 39, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 42, 7, 35, 35, 21, 97, 59, 88, 50, 12, 44, 85, 22, 38, 23, 42, 61, 44, 63, 23, 69, 28, 17, 73, 20, 71, 80, 15, 42, 28, 10, 56, 77, 43}, 26, 396); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -82, -82, -74, -72, -68, -68, -66, -60, -54, -42, -38, -36, -32, -30, -16, -14, -12, -10, 14, 24, 28, 34, 34, 38, 42, 44, 52, 70, 72, 80, 84, 86, 94}, 32, 582); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0}, 8, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({33}, 0, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({76, 86, 46, -70, 92, 6, 70, -66, 64, 46, 86, -42, -46, -24, 8, 76, 4, -96, -86, 18, 70, -72, -56, -88, -96, 62, 22, 20, 42}, 21, 254); \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}, 24, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({25, 46, 41, 61, 93, 29, 65, 24, 10, 89, 22, 51, 18, 65, 70, 59, 87, 82, 97, 99, 15, 64, 20, 97, 12, 23, 76}, 20, 550); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "dynamicProgrammingSet14MaximumSumIncreasingSubsequence", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 301, \"inputs\": {\"arr\": [4, 5, 7, 12, 23, 31, 31, 45, 47, 60, 67, 70, 84, 85, 91, 96], \"n\": 11}}, {\"idx\": 1, \"outputs\": 102, \"inputs\": {\"arr\": [-88, -38, -50, -14, 36, -32, 0, -8, -12, -62, -46, 66, -46, -26, 6, -44, 14, -74, -84, 52, -28], \"n\": 18}}, {\"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, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 39}}, {\"idx\": 3, \"outputs\": 396, \"inputs\": {\"arr\": [85, 42, 7, 35, 35, 21, 97, 59, 88, 50, 12, 44, 85, 22, 38, 23, 42, 61, 44, 63, 23, 69, 28, 17, 73, 20, 71, 80, 15, 42, 28, 10, 56, 77, 43], \"n\": 26}}, {\"idx\": 4, \"outputs\": 582, \"inputs\": {\"arr\": [-92, -82, -82, -74, -72, -68, -68, -66, -60, -54, -42, -38, -36, -32, -30, -16, -14, -12, -10, 14, 24, 28, 34, 34, 38, 42, 44, 52, 70, 72, 80, 84, 86, 94], \"n\": 32}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0], \"n\": 8}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [33], \"n\": 0}}, {\"idx\": 7, \"outputs\": 254, \"inputs\": {\"arr\": [76, 86, 46, -70, 92, 6, 70, -66, 64, 46, 86, -42, -46, -24, 8, 76, 4, -96, -86, 18, 70, -72, -56, -88, -96, 62, 22, 20, 42], \"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, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 24}}, {\"idx\": 9, \"outputs\": 550, \"inputs\": {\"arr\": [25, 46, 41, 61, 93, 29, 65, 24, 10, 89, 22, 51, 18, 65, 70, 59, 87, 82, 97, 99, 15, 64, 20, 97, 12, 23, 76], \"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 ] }
146
Dynamic Programming Set 28 Minimum Insertions To Form A Palindrome
C++
int dynamicProgrammingSet28MinimumInsertionsToFormAPalindrome(vector<char> str, int l, int h) {
[ "str", "l", "h" ]
def dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, l, h): if (l > h): return sys.maxsize if (l == h): return 0 if (l == (h - 1)): return (0 if (str[l] == str[h]) else 1) if (str[l] == str[h]): return dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, (l + 1), (h - 1)) else: return (min(dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, l, (h - 1)), dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(str, (l + 1), h)) + 1)
int dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome(vector<char> str, int l, int h) { if ( l > h ) return INT_MAX; if ( l == h ) return 0; if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1; return ( str [ l ] == str [ h ] ) ? dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome ( str, l + 1, h - 1 ) : ( min ( dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome ( str, l, h - 1 ), dynamic_programming_set_28_minimum_insertions_to_form_a_palindrome ( str, l + 1, h ) ) + 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<char> str, int l, int h, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str, l, h), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({'F', 'F', 'J', 'K', 'K', 'L', 'P', 'S', 'T', 'V', 'W', 'Y', 'b', 'd', 'j', 'l', 't', 'u', 'x', 'y'}, 11, 11, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '1', '8', '8', '8', '4', '4', '3', '9', '6', '5', '2', '8', '2', '0', '2', '6', '0', '7', '7', '3', '2', '4', '5', '9', '7', '2', '4', '1', '8', '7', '9', '8', '0', '8', '5', '4', '2', '3'}, 19, 22, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'1'}, 0, 0, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'g', 'y', 'r', 'M', 'v', 'z', ' ', 'k', 'S', 'P', 'x', 'p', 'E', 'z', 'T', 'K', 'k', 'B', 's', 'P', 'p', 'e', 'G', 't', 'r', 'M', 'p', ' ', 'H', 'a'}, 24, 27, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'0', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '3', '3', '3', '3', '3', '4', '4', '4', '5', '5', '5', '5', '5', '6', '6', '6', '6', '6', '6', '6', '7', '8', '8', '8', '9', '9'}, 33, 34, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({'X', 'B', 'E', 'v', 'K', 't', 'k', 'K', 'Q', 's', 'V', 'N', 'l', 'k', 'T', 'N', 'J', 'z', 'f', 'p', 'J', 'g', 'S', 'P', 'M', 'b', 'H', 'L', 'v', 'E', 'A', 'n', 'D', 'U', 'c', 's', 'M', 'Q', 'P', 'g', 'g', ' '}, 26, 27, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "dynamicProgrammingSet28MinimumInsertionsToFormAPalindrome", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"str\": [\"F\", \"F\", \"J\", \"K\", \"K\", \"L\", \"P\", \"S\", \"T\", \"V\", \"W\", \"Y\", \"b\", \"d\", \"j\", \"l\", \"t\", \"u\", \"x\", \"y\"], \"l\": 11, \"h\": 11}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"str\": [\"0\", \"1\", \"8\", \"8\", \"8\", \"4\", \"4\", \"3\", \"9\", \"6\", \"5\", \"2\", \"8\", \"2\", \"0\", \"2\", \"6\", \"0\", \"7\", \"7\", \"3\", \"2\", \"4\", \"5\", \"9\", \"7\", \"2\", \"4\", \"1\", \"8\", \"7\", \"9\", \"8\", \"0\", \"8\", \"5\", \"4\", \"2\", \"3\"], \"l\": 19, \"h\": 22}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"str\": [\"1\"], \"l\": 0, \"h\": 0}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"str\": [\"g\", \"y\", \"r\", \"M\", \"v\", \"z\", \" \", \"k\", \"S\", \"P\", \"x\", \"p\", \"E\", \"z\", \"T\", \"K\", \"k\", \"B\", \"s\", \"P\", \"p\", \"e\", \"G\", \"t\", \"r\", \"M\", \"p\", \" \", \"H\", \"a\"], \"l\": 24, \"h\": 27}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"str\": [\"0\", \"1\", \"1\", \"1\", \"1\", \"1\", \"1\", \"2\", \"2\", \"2\", \"2\", \"3\", \"3\", \"3\", \"3\", \"3\", \"4\", \"4\", \"4\", \"5\", \"5\", \"5\", \"5\", \"5\", \"6\", \"6\", \"6\", \"6\", \"6\", \"6\", \"6\", \"7\", \"8\", \"8\", \"8\", \"9\", \"9\"], \"l\": 33, \"h\": 34}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"str\": [\"X\", \"B\", \"E\", \"v\", \"K\", \"t\", \"k\", \"K\", \"Q\", \"s\", \"V\", \"N\", \"l\", \"k\", \"T\", \"N\", \"J\", \"z\", \"f\", \"p\", \"J\", \"g\", \"S\", \"P\", \"M\", \"b\", \"H\", \"L\", \"v\", \"E\", \"A\", \"n\", \"D\", \"U\", \"c\", \"s\", \"M\", \"Q\", \"P\", \"g\", \"g\", \" \"], \"l\": 26, \"h\": 27}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
147
Dynamic Programming Set 36 Cut A Rope To Maximize Product 1
C++
long long dynamicProgrammingSet36CutARopeToMaximizeProduct1(int n) {
[ "n" ]
def dynamic_programming_set_36_cut_a_rope_to_maximize_product_1(n): if ((n == 2) or (n == 3)): return (n - 1) res = 1 while (n > 4): n -= 3 res *= 3 return (n * res)
int dynamic_programming_set_36_cut_a_rope_to_maximize_product_1(int n) { if ( n == 2 || n == 3 ) return ( n - 1 ); int res = 1; while ( n > 4 ) { n -= 3; res *= 3; } return ( n * res ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(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(62, 6973568802); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 258280326); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 18); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 354294); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 354294); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 19131876); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 564859072962); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 94143178827); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "dynamicProgrammingSet36CutARopeToMaximizeProduct1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 6973568802, \"inputs\": {\"n\": 62}}, {\"idx\": 1, \"outputs\": 258280326, \"inputs\": {\"n\": 53}}, {\"idx\": 2, \"outputs\": 18, \"inputs\": {\"n\": 8}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"n\": 6}}, {\"idx\": 4, \"outputs\": 354294, \"inputs\": {\"n\": 35}}, {\"idx\": 5, \"outputs\": 354294, \"inputs\": {\"n\": 35}}, {\"idx\": 6, \"outputs\": 19131876, \"inputs\": {\"n\": 46}}, {\"idx\": 7, \"outputs\": 564859072962, \"inputs\": {\"n\": 74}}, {\"idx\": 8, \"outputs\": 94143178827, \"inputs\": {\"n\": 69}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"n\": 3}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
149
Efficient Search In An Array Where Difference Between Adjacent Is 1
C++
int efficientSearchInAnArrayWhereDifferenceBetweenAdjacentIs1(vector<int> arr, int n, int x) {
[ "arr", "n", "x" ]
def efficient_search_in_an_array_where_difference_between_adjacent_is_1(arr, n, x): i = 0 while (i <= (n - 1)): if (arr[i] == x): return i i += abs((arr[i] - x)) return (- 1)
int efficient_search_in_an_array_where_difference_between_adjacent_is_1(vector<int> arr, int n, int x) { int i = 0; while ( i <= n - 1 ) { if ( arr [ i ] == x ) return i; i += abs ( arr [ i ] - x ); } return - 1; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 4, 5, 6, 5, 4, 3, 2}, 29, 6, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5, 4, 5, 6, 5, 4, 3, 2}, 19, 3, 6); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 1, 14); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 51, 52, 51, 50, 49, 48}, 17, 49, 5); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -68, -32, -6, 6, 10, 30, 34, 58, 92}, 6, 6, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0}, 27, 22, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58}, 0, 0, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-64, 78, 58, 36, 48, 80, -80, 74, -98, 46, -48, 24, 80, 72, 90, -46, 14, 68, 38, 58, -54, 80, 44, -62, 34, -28, 92, 84, 90, 44, -26, 88, 18, 22, -32, 54, 58, 92}, 24, 34, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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}, 35, 1, 21); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({5}, 0, 0, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "efficientSearchInAnArrayWhereDifferenceBetweenAdjacentIs1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"arr\": [5, 4, 5, 6, 5, 4, 3, 2], \"n\": 29, \"x\": 6}}, {\"idx\": 1, \"outputs\": 6, \"inputs\": {\"arr\": [5, 4, 5, 6, 5, 4, 3, 2], \"n\": 19, \"x\": 3}}, {\"idx\": 2, \"outputs\": 14, \"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, 1], \"n\": 37, \"x\": 1}}, {\"idx\": 3, \"outputs\": 5, \"inputs\": {\"arr\": [50, 51, 52, 51, 50, 49, 48], \"n\": 17, \"x\": 49}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-86, -68, -32, -6, 6, 10, 30, 34, 58, 92], \"n\": 6, \"x\": 6}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0], \"n\": 27, \"x\": 22}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [58], \"n\": 0, \"x\": 0}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-64, 78, 58, 36, 48, 80, -80, 74, -98, 46, -48, 24, 80, 72, 90, -46, 14, 68, 38, 58, -54, 80, 44, -62, 34, -28, 92, 84, 90, 44, -26, 88, 18, 22, -32, 54, 58, 92], \"n\": 24, \"x\": 34}}, {\"idx\": 8, \"outputs\": 21, \"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], \"n\": 35, \"x\": 1}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [5], \"n\": 0, \"x\": 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 ] }
150
Efficient Way Check Whether N Th Fibonacci Number Multiple 10
C++
bool efficientWayCheckWhetherNThFibonacciNumberMultiple10(int n) {
[ "n" ]
def efficient_way_check_whether_n_th_fibonacci_number_multiple_10(n): return ((n % 15) == 0)
bool efficient_way_check_whether_n_th_fibonacci_number_multiple_10(int n) { return ( n % 15 == 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(30, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(-30, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 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": "efficientWayCheckWhetherNThFibonacciNumberMultiple10", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 30}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": -30}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 60}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"n\": 90}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 99}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 32}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 21}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 65}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 21}}, {\"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 ] }
151
Efficient Way To Multiply With 7
C++
int efficientWayToMultiplyWith7(int n) {
[ "n" ]
def efficient_way_to_multiply_with_7(n): return ((n << 3) - n)
long efficient_way_to_multiply_with_7(long n) { return ( ( n << 3 ) - n ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(41, 287); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 294); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 434); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 28); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(31, 217); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 525); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 35); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 525); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 595); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 133); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "efficientWayToMultiplyWith7", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 287, \"inputs\": {\"n\": 41}}, {\"idx\": 1, \"outputs\": 294, \"inputs\": {\"n\": 42}}, {\"idx\": 2, \"outputs\": 434, \"inputs\": {\"n\": 62}}, {\"idx\": 3, \"outputs\": 28, \"inputs\": {\"n\": 4}}, {\"idx\": 4, \"outputs\": 217, \"inputs\": {\"n\": 31}}, {\"idx\": 5, \"outputs\": 525, \"inputs\": {\"n\": 75}}, {\"idx\": 6, \"outputs\": 35, \"inputs\": {\"n\": 5}}, {\"idx\": 7, \"outputs\": 525, \"inputs\": {\"n\": 75}}, {\"idx\": 8, \"outputs\": 595, \"inputs\": {\"n\": 85}}, {\"idx\": 9, \"outputs\": 133, \"inputs\": {\"n\": 19}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
152
Elements To Be Added So That All Elements Of A Range Are Present In Array
C++
int elementsToBeAddedSoThatAllElementsOfARangeArePresentInArray(vector<int> arr, int n) {
[ "arr", "n" ]
def elements_to_be_added_so_that_all_elements_of_a_range_are_present_in_array(arr, n): count = 0 arr.sort() for i in range(0, (n - 1)): if ((arr[i] != arr[(i + 1)]) and (arr[i] != (arr[(i + 1)] - 1))): count += ((arr[(i + 1)] - arr[i]) - 1) return count
int elements_to_be_added_so_that_all_elements_of_a_range_are_present_in_array(vector<int> arr, int n) { int count = 0; sort(arr.begin(), arr.end()); for ( int i = 0; i < n - 1; i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1; return count; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({4, 4, 5, 7, 7, 9, 13, 15, 18, 19, 25, 27, 27, 29, 32, 36, 48, 51, 53, 53, 55, 65, 66, 67, 72, 74, 74, 76, 77, 79, 80, 81, 82, 83, 83, 86, 87, 97, 98, 98, 99}, 30, 51); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -90, -88, -84, -84, -84, -80, -74, -52, -26, -26, -16, -8, 6, 14, 16, 34, 64, 72, 92, 94}, 17, 112); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 24, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 12, 12, 13, 13, 23, 25, 26, 29, 32, 39, 43, 43, 54, 62, 79, 92}, 14, 34); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -86, -72, -64, -64, -58, -56, -56, -56, -56, -54, -54, -52, -42, -42, -40, -36, -32, -28, -22, -20, -18, -12, -8, -6, -4, 0, 2, 4, 10, 16, 30, 32, 48, 48, 60, 70, 74, 76, 84}, 35, 115); \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, 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({4, 5, 8, 12, 16, 16, 17, 20, 20, 23, 26, 26, 27, 28, 32, 34, 40, 40, 41, 41, 44, 45, 47, 49, 51, 52, 54, 57, 60, 62, 63, 64, 66, 68, 69, 70, 71, 76, 77, 80, 80, 80, 90, 91, 92, 94, 96, 98, 99}, 42, 42); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -92, -92, -92, -86, -78, -74, -72, -68, -60, -52, -48, -48, -46, -46, -44, -40, -38, -26, -18, 2, 4, 4, 10, 14, 14, 16, 20, 38, 48, 48, 50, 56, 60, 66, 74, 76, 80, 84, 88, 96, 96, 96}, 37, 144); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({49, 66, 84}, 2, 16); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "elementsToBeAddedSoThatAllElementsOfARangeArePresentInArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 51, \"inputs\": {\"arr\": [4, 4, 5, 7, 7, 9, 13, 15, 18, 19, 25, 27, 27, 29, 32, 36, 48, 51, 53, 53, 55, 65, 66, 67, 72, 74, 74, 76, 77, 79, 80, 81, 82, 83, 83, 86, 87, 97, 98, 98, 99], \"n\": 30}}, {\"idx\": 1, \"outputs\": 112, \"inputs\": {\"arr\": [-90, -90, -88, -84, -84, -84, -80, -74, -52, -26, -26, -16, -8, 6, 14, 16, 34, 64, 72, 92, 94], \"n\": 17}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 24}}, {\"idx\": 3, \"outputs\": 34, \"inputs\": {\"arr\": [10, 12, 12, 13, 13, 23, 25, 26, 29, 32, 39, 43, 43, 54, 62, 79, 92], \"n\": 14}}, {\"idx\": 4, \"outputs\": 115, \"inputs\": {\"arr\": [-94, -86, -72, -64, -64, -58, -56, -56, -56, -56, -54, -54, -52, -42, -42, -40, -36, -32, -28, -22, -20, -18, -12, -8, -6, -4, 0, 2, 4, 10, 16, 30, 32, 48, 48, 60, 70, 74, 76, 84], \"n\": 35}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 29}}, {\"idx\": 6, \"outputs\": 42, \"inputs\": {\"arr\": [4, 5, 8, 12, 16, 16, 17, 20, 20, 23, 26, 26, 27, 28, 32, 34, 40, 40, 41, 41, 44, 45, 47, 49, 51, 52, 54, 57, 60, 62, 63, 64, 66, 68, 69, 70, 71, 76, 77, 80, 80, 80, 90, 91, 92, 94, 96, 98, 99], \"n\": 42}}, {\"idx\": 7, \"outputs\": 144, \"inputs\": {\"arr\": [-98, -92, -92, -92, -92, -86, -78, -74, -72, -68, -60, -52, -48, -48, -46, -46, -44, -40, -38, -26, -18, 2, 4, 4, 10, 14, 14, 16, 20, 38, 48, 48, 50, 56, 60, 66, 74, 76, 80, 84, 88, 96, 96, 96], \"n\": 37}}, {\"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, 1, 1, 1, 1, 1, 1], \"n\": 17}}, {\"idx\": 9, \"outputs\": 16, \"inputs\": {\"arr\": [49, 66, 84], \"n\": 2}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
153
Eulerian Number 1
C++
int eulerianNumber1(int n, int m) {
[ "n", "m" ]
def eulerian_number_1(n, m): dp = [[0 for x in range((m + 1))] for y in range((n + 1))] for i in range(1, (n + 1)): for j in range(0, (m + 1)): if (i > j): if (j == 0): dp[i][j] = 1 else: dp[i][j] = (((i - j) * dp[(i - 1)][(j - 1)]) + ((j + 1) * dp[(i - 1)][j])) return dp[n][m]
int eulerian_number_1(int n, int m) { int dp [ n + 1 ] [ m + 1 ]; memset ( dp, 0, sizeof ( dp ) ); for ( int i = 1; i <= n; i ++ ) { for ( int j = 0; j <= m; j ++ ) { if ( i > j ) { if ( j == 0 ) dp [ i ] [ j ] = 1; else dp [ i ] [ j ] = ( ( i - j ) * dp [ i - 1 ] [ j - 1 ] ) + ( ( j + 1 ) * dp [ i - 1 ] [ j ] ); } } } return dp [ n ] [ m ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(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(6, 10, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 33, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 86, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 97, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "eulerianNumber1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": 6, \"m\": 10}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"n\": 26, \"m\": 33}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 74, \"m\": 86}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 65, \"m\": 97}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
154
Eulers Criterion Check If Square Root Under Modulo P Exists
C++
bool eulersCriterionCheckIfSquareRootUnderModuloPExists(int n, int p) {
[ "n", "p" ]
def eulers_criterion_check_if_square_root_under_modulo_p_exists(n, p): n = (n % p) for x in range(2, p, 1): if (((x * x) % p) == n): return True return False
bool eulers_criterion_check_if_square_root_under_modulo_p_exists(int n, int p) { n = n % p; for ( int x = 2; x < p; x ++ ) if ( ( x * x ) % p == n ) return true; return false; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, int p, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, p), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(71, 78, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 75, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 35, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 99, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 29, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 88, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 54, true); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 52, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 33, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 13, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "eulersCriterionCheckIfSquareRootUnderModuloPExists", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"n\": 71, \"p\": 78}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"n\": 85, \"p\": 75}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 4, \"p\": 35}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"n\": 20, \"p\": 99}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"n\": 71, \"p\": 29}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 72, \"p\": 88}}, {\"idx\": 6, \"outputs\": true, \"inputs\": {\"n\": 36, \"p\": 54}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 95, \"p\": 52}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 83, \"p\": 33}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 72, \"p\": 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 ] }
155
Even Fibonacci Numbers Sum
C++
int evenFibonacciNumbersSum(int limit) {
[ "limit" ]
def even_fibonacci_numbers_sum(limit): if (limit < 2): return 0 ef1 = 0 ef2 = 2 sm = (ef1 + ef2) while (ef2 <= limit): ef3 = ((4 * ef2) + ef1) if (ef3 > limit): break ef1 = ef2 ef2 = ef3 sm = (sm + ef2) return sm
int even_fibonacci_numbers_sum(int limit) { if ( limit < 2 ) return 0; long long int ef1 = 0, ef2 = 2; long long int sum = ef1 + ef2; while ( ef2 <= limit ) { long long int ef3 = 4 * ef2 + ef1; if ( ef3 > limit ) break; ef1 = ef2; ef2 = ef3; sum += ef2; } return sum; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int limit, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(limit), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 44); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 44); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 10); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 44); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 44); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 10); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 44); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 10); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(33, 10); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 44); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "evenFibonacciNumbersSum", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 44, \"inputs\": {\"limit\": 67}}, {\"idx\": 1, \"outputs\": 44, \"inputs\": {\"limit\": 89}}, {\"idx\": 2, \"outputs\": 10, \"inputs\": {\"limit\": 12}}, {\"idx\": 3, \"outputs\": 44, \"inputs\": {\"limit\": 94}}, {\"idx\": 4, \"outputs\": 44, \"inputs\": {\"limit\": 96}}, {\"idx\": 5, \"outputs\": 10, \"inputs\": {\"limit\": 25}}, {\"idx\": 6, \"outputs\": 44, \"inputs\": {\"limit\": 49}}, {\"idx\": 7, \"outputs\": 10, \"inputs\": {\"limit\": 8}}, {\"idx\": 8, \"outputs\": 10, \"inputs\": {\"limit\": 33}}, {\"idx\": 9, \"outputs\": 44, \"inputs\": {\"limit\": 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 ] }
156
Fast Multiplication Method Without Using Multiplication Operator Russian Peasants Algorithm
C++
int fastMultiplicationMethodWithoutUsingMultiplicationOperatorRussianPeasantsAlgorithm(int a, int b) {
[ "a", "b" ]
def fast_multiplication_method_without_using_multiplication_operator_russian_peasants_algorithm(a, b): res = 0 while (b > 0): if (b & 1): res = (res + a) a = (a << 1) b = (b >> 1) return res
unsigned int fast_multiplication_method_without_using_multiplication_operator_russian_peasants_algorithm(unsigned int a, unsigned int b) { int res = 0; while ( b > 0 ) { if ( b & 1 ) res = res + a; a = a << 1; b = b >> 1; } return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(4, 33, 132); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 67, 2412); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 52, 3380); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 37, 2035); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 76, 2660); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 98, 6762); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 62, 5208); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(5, 80, 400); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 36, 540); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 84, 5628); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "fastMultiplicationMethodWithoutUsingMultiplicationOperatorRussianPeasantsAlgorithm", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 132, \"inputs\": {\"a\": 4, \"b\": 33}}, {\"idx\": 1, \"outputs\": 2412, \"inputs\": {\"a\": 36, \"b\": 67}}, {\"idx\": 2, \"outputs\": 3380, \"inputs\": {\"a\": 65, \"b\": 52}}, {\"idx\": 3, \"outputs\": 2035, \"inputs\": {\"a\": 55, \"b\": 37}}, {\"idx\": 4, \"outputs\": 2660, \"inputs\": {\"a\": 35, \"b\": 76}}, {\"idx\": 5, \"outputs\": 6762, \"inputs\": {\"a\": 69, \"b\": 98}}, {\"idx\": 6, \"outputs\": 5208, \"inputs\": {\"a\": 84, \"b\": 62}}, {\"idx\": 7, \"outputs\": 400, \"inputs\": {\"a\": 5, \"b\": 80}}, {\"idx\": 8, \"outputs\": 540, \"inputs\": {\"a\": 15, \"b\": 36}}, {\"idx\": 9, \"outputs\": 5628, \"inputs\": {\"a\": 67, \"b\": 84}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
157
Fibonacci Modulo P
C++
int fibonacciModuloP(int p) {
[ "p" ]
def fibonacci_modulo_p(p): first = 1 second = 1 number = 2 next = 1 while next: next = ((first + second) % p) first = second second = next number = (number + 1) return number
int fibonacci_modulo_p(int p) { int first = 1, second = 1, number = 2, next = 1; while ( next ) { next = ( first + second ) % p; first = second; second = next; number ++; } return number; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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 p, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(p), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(51, 36); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 30); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(68, 18); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 8); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 6); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 24); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 60); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 100); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 70); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 20); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "fibonacciModuloP", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 36, \"inputs\": {\"p\": 51}}, {\"idx\": 1, \"outputs\": 30, \"inputs\": {\"p\": 40}}, {\"idx\": 2, \"outputs\": 18, \"inputs\": {\"p\": 68}}, {\"idx\": 3, \"outputs\": 8, \"inputs\": {\"p\": 7}}, {\"idx\": 4, \"outputs\": 6, \"inputs\": {\"p\": 8}}, {\"idx\": 5, \"outputs\": 24, \"inputs\": {\"p\": 32}}, {\"idx\": 6, \"outputs\": 60, \"inputs\": {\"p\": 93}}, {\"idx\": 7, \"outputs\": 100, \"inputs\": {\"p\": 75}}, {\"idx\": 8, \"outputs\": 70, \"inputs\": {\"p\": 71}}, {\"idx\": 9, \"outputs\": 20, \"inputs\": {\"p\": 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 ] }
158
Finding Power Prime Number P N
C++
double findingPowerPrimeNumberPN(int n, int p) {
[ "n", "p" ]
def finding_power_prime_number_p_n(n, p): ans = 0 temp = p while (temp <= n): ans += (n / temp) temp = (temp * p) return ans
int finding_power_prime_number_p_n(int n, int p) { int ans = 0; int temp = p; while ( temp <= n ) { ans += n / temp; temp = temp * p; } return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int n, int p, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, p), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(49, 30, 1.6333333333333333); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 25, 3.2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 9, 1.1111111111111112); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(81, 57, 1.4210526315789473); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 4, 2.75); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(45, 34, 1.3235294117647058); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 90, 0.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 78, 0.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 60, 1.3333333333333333); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 31, 3.129032258064516); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findingPowerPrimeNumberPN", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1.6333333333333333, \"inputs\": {\"n\": 49, \"p\": 30}}, {\"idx\": 1, \"outputs\": 3.2, \"inputs\": {\"n\": 80, \"p\": 25}}, {\"idx\": 2, \"outputs\": 1.1111111111111112, \"inputs\": {\"n\": 10, \"p\": 9}}, {\"idx\": 3, \"outputs\": 1.4210526315789473, \"inputs\": {\"n\": 81, \"p\": 57}}, {\"idx\": 4, \"outputs\": 2.75, \"inputs\": {\"n\": 11, \"p\": 4}}, {\"idx\": 5, \"outputs\": 1.3235294117647058, \"inputs\": {\"n\": 45, \"p\": 34}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 86, \"p\": 90}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": 27, \"p\": 78}}, {\"idx\": 8, \"outputs\": 1.3333333333333333, \"inputs\": {\"n\": 80, \"p\": 60}}, {\"idx\": 9, \"outputs\": 3.129032258064516, \"inputs\": {\"n\": 97, \"p\": 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 ] }
159
Finding Power Prime Number P N 1
C++
int findingPowerPrimeNumberPN1(int n, int p) {
[ "n", "p" ]
def finding_power_prime_number_p_n_1(n, p): ans = 0 temp = p while (temp <= n): ans += (n / temp) temp = (temp * p) return int(ans)
int finding_power_prime_number_p_n_1(int n, int p) { int ans = 0; int temp = p; while ( temp <= n ) { ans += n / temp; temp = temp * p; } return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int p, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, p), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(76, 43, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 91, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, 42, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 67, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 52, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 8, 13); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 24, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 88, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 61, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 28, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findingPowerPrimeNumberPN1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"n\": 76, \"p\": 43}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"n\": 77, \"p\": 91}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 9, \"p\": 42}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 59, \"p\": 67}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 8, \"p\": 52}}, {\"idx\": 5, \"outputs\": 13, \"inputs\": {\"n\": 97, \"p\": 8}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"n\": 78, \"p\": 24}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": 41, \"p\": 88}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"n\": 72, \"p\": 61}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"n\": 71, \"p\": 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 ] }
160
Find A Fixed Point In A Given Array
C++
int findAFixedPointInAGivenArray(vector<int> arr, int n) {
[ "arr", "n" ]
def find_a_fixed_point_in_a_given_array(arr, n): for i in range(n): if (arr[i] is i): return i return (- 1)
int find_a_fixed_point_in_a_given_array(vector<int> arr, int n) { int i; for ( i = 0; i < n; i ++ ) { if ( arr [ i ] == i ) return i; } return - 1; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int 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, 16, 21, 26, 27, 29, 34, 35, 35, 37, 38, 40, 48, 52, 58, 59, 60, 61, 63, 63, 65, 66, 69, 75, 79, 83, 86, 88, 91, 91, 96}, 23, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, -70, 34, -44, 84, 54, 14, -88}, 7, -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, 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-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({59, 67, 70, 34, 18, 22, 52, 95, 11, 66, 60, 24, 7, 71, 52, 88, 32, 52, 85, 81, 32, 44, 25, 51, 47, 97, 81, 33, 88, 38, 36, 54, 80, 25, 70, 27, 75, 29, 94}, 37, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -96, -94, -88, -88, -82, -72, -72, -70, -70, -66, -64, -64, -62, -58, -54, -46, -44, -30, -26, -22, -8, -6, -2, 0, 26, 30, 30, 34, 42, 42, 48, 64, 76, 90, 96}, 34, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1}, 15, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 4, 7, 10, 15, 16, 16, 23, 24, 27, 39, 42, 58, 60, 64, 72, 74, 78, 78, 78, 80, 80, 84, 85, 86, 88, 88, 90, 92, 93, 94, 95, 96}, 22, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-68, -48, 36, 22, -80, -48, -74, -14, 44, -46, -76, 18, -16, -36, -68, 0, -30, -56, 42, 92, 82, 64, -18, -6, -78, -86, 26, 86, 36, -66, -50, 18, -26, 48, 8}, 20, -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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 23, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 76, 99, 1, 1, 29, 9, 12, 57, 12, 74, 22, 83, 77, 39, 84, 50, 60, 36, 90, 88, 62, 79, 58, 58, 40, 44, 99, 84, 63, 23, 21, 16, 98, 68, 8, 46}, 35, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findAFixedPointInAGivenArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"arr\": [8, 16, 21, 26, 27, 29, 34, 35, 35, 37, 38, 40, 48, 52, 58, 59, 60, 61, 63, 63, 65, 66, 69, 75, 79, 83, 86, 88, 91, 91, 96], \"n\": 23}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [22, -70, 34, -44, 84, 54, 14, -88], \"n\": 7}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 31}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [59, 67, 70, 34, 18, 22, 52, 95, 11, 66, 60, 24, 7, 71, 52, 88, 32, 52, 85, 81, 32, 44, 25, 51, 47, 97, 81, 33, 88, 38, 36, 54, 80, 25, 70, 27, 75, 29, 94], \"n\": 37}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-96, -96, -94, -88, -88, -82, -72, -72, -70, -70, -66, -64, -64, -62, -58, -54, -46, -44, -30, -26, -22, -8, -6, -2, 0, 26, 30, 30, 34, 42, 42, 48, 64, 76, 90, 96], \"n\": 34}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1], \"n\": 15}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [2, 2, 4, 7, 10, 15, 16, 16, 23, 24, 27, 39, 42, 58, 60, 64, 72, 74, 78, 78, 78, 80, 80, 84, 85, 86, 88, 88, 90, 92, 93, 94, 95, 96], \"n\": 22}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-68, -48, 36, 22, -80, -48, -74, -14, 44, -46, -76, 18, -16, -36, -68, 0, -30, -56, 42, 92, 82, 64, -18, -6, -78, -86, 26, 86, 36, -66, -50, 18, -26, 48, 8], \"n\": 20}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 23}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [3, 76, 99, 1, 1, 29, 9, 12, 57, 12, 74, 22, 83, 77, 39, 84, 50, 60, 36, 90, 88, 62, 79, 58, 58, 40, 44, 99, 84, 63, 23, 21, 16, 98, 68, 8, 46], \"n\": 35}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
161
Find A Rotation With Maximum Hamming Distance
C++
int findARotationWithMaximumHammingDistance(vector<int> arr, int n) {
[ "arr", "n" ]
def find_a_rotation_with_maximum_hamming_distance(arr, n): brr = ([0] * ((2 * n) + 1)) for i in range(n): brr[i] = arr[i] for i in range(n): brr[(n + i)] = arr[i] maxHam = 0 for i in range(1, n): currHam = 0 k = 0 for j in range(i, (i + n)): if (brr[j] != arr[k]): currHam += 1 k = (k + 1) if (currHam == n): return n maxHam = max(maxHam, currHam) return maxHam
int find_a_rotation_with_maximum_hamming_distance(vector<int> arr, int n) { int brr [ 2 * n + 1 ]; for ( int i = 0; i < n; i ++ ) brr [ i ] = arr [ i ]; for ( int i = 0; i < n; i ++ ) brr [ n + i ] = arr [ i ]; int maxHam = 0; for ( int i = 1; i < n; i ++ ) { int currHam = 0; for ( int j = i, k = 0; j < ( i + n ); j ++, k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++; if ( currHam == n ) return n; maxHam = max ( maxHam, currHam ); } return maxHam; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 4, 18, 22, 28, 34, 35, 39, 44, 45, 67, 73, 75, 79, 81, 83, 89, 93, 96}, 12, 12); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, -28}, 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, 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, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({24}, 0, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-68, 14, 36, 62}, 2, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0}, 12, 6); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 10, 19, 22, 24, 28, 29, 39, 46, 55, 62, 66, 68, 73, 74, 76, 83, 84, 85, 99}, 15, 15); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-38, 56, 86, 12, 24, -90, -20, -46, 38, 92, -44, -74, 54, 50, 46, 50, -94, 64, 32, -84, 70}, 14, 14); \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}, 8, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({61, 89, 8}, 2, 2); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findARotationWithMaximumHammingDistance", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 12, \"inputs\": {\"arr\": [1, 4, 18, 22, 28, 34, 35, 39, 44, 45, 67, 73, 75, 79, 81, 83, 89, 93, 96], \"n\": 12}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [52, -28], \"n\": 1}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 21}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [24], \"n\": 0}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"arr\": [-68, 14, 36, 62], \"n\": 2}}, {\"idx\": 5, \"outputs\": 6, \"inputs\": {\"arr\": [1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0], \"n\": 12}}, {\"idx\": 6, \"outputs\": 15, \"inputs\": {\"arr\": [7, 10, 19, 22, 24, 28, 29, 39, 46, 55, 62, 66, 68, 73, 74, 76, 83, 84, 85, 99], \"n\": 15}}, {\"idx\": 7, \"outputs\": 14, \"inputs\": {\"arr\": [-38, 56, 86, 12, 24, -90, -20, -46, 38, 92, -44, -74, 54, 50, 46, 50, -94, 64, 32, -84, 70], \"n\": 14}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], \"n\": 8}}, {\"idx\": 9, \"outputs\": 2, \"inputs\": {\"arr\": [61, 89, 8], \"n\": 2}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
162
Find A Triplet That Sum To A Given Value
C++
bool findATripletThatSumToAGivenValue(vector<int> a, int arr_size, int sum) {
[ "a", "arr_size", "sum" ]
def find_a_triplet_that_sum_to_a_given_value(A, arr_size, sum): for i in range(0, (arr_size - 2)): for j in range((i + 1), (arr_size - 1)): for k in range((j + 1), arr_size): if (((A[i] + A[j]) + A[k]) == sum): print('Triplet is', A[i], ', ', A[j], ', ', A[k]) return True return False
bool find_a_triplet_that_sum_to_a_given_value(vector<int> A, int arr_size, int sum) { int l, r; for ( int i = 0; i < arr_size - 2; i ++ ) { for ( int j = i + 1; j < arr_size - 1; j ++ ) { for ( int k = j + 1; k < arr_size; k ++ ) { if ( A [ i ] + A [ j ] + A [ 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> a, int arr_size, int sum, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, arr_size, 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({15, 18, 38, 47, 75, 88}, 5, 4, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({28, -2, 62, 38, 86, -86, 56, 58, 96, 6, -28, 8, 68, -16, -80, -4, 98, -92, 4, -4, 58, -62, 46, 64}, 22, 18, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 27, 23, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({19, 77, 17, 91, 6, 35, 22, 4, 30, 23, 97, 56, 78, 16, 22, 23, 95, 57, 43, 27, 47, 44, 23, 10, 3, 94, 55, 22, 93, 32, 89, 28, 64, 22, 13, 24, 38, 44, 6, 1, 80}, 22, 29, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -94, -88, -80, -74, -68, -68, -64, -44, -36, -24, -10, -8, -8, 0, 4, 6, 8, 8, 12, 14, 16, 38, 50, 52, 54, 56, 66, 68, 76, 88}, 18, 19, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 1, 0, 1, 1}, 4, 5, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 22, 24, 30, 42, 44, 49, 49, 65, 70, 70, 74, 74, 75, 90, 95, 96}, 8, 13, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({40, -76, -68, -86, -14, 82, -20, 54, -26, 56, -24, -44, 44, 60, 52, -20, 80, -24, -90, -30, -2}, 11, 18, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 17, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({33, 92, 6, 99, 83, 97, 49, 97, 85, 52}, 6, 7, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findATripletThatSumToAGivenValue", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"a\": [15, 18, 38, 47, 75, 88], \"arr_size\": 5, \"sum\": 4}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"a\": [28, -2, 62, 38, 86, -86, 56, 58, 96, 6, -28, 8, 68, -16, -80, -4, 98, -92, 4, -4, 58, -62, 46, 64], \"arr_size\": 22, \"sum\": 18}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr_size\": 27, \"sum\": 23}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"a\": [19, 77, 17, 91, 6, 35, 22, 4, 30, 23, 97, 56, 78, 16, 22, 23, 95, 57, 43, 27, 47, 44, 23, 10, 3, 94, 55, 22, 93, 32, 89, 28, 64, 22, 13, 24, 38, 44, 6, 1, 80], \"arr_size\": 22, \"sum\": 29}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"a\": [-98, -98, -94, -88, -80, -74, -68, -68, -64, -44, -36, -24, -10, -8, -8, 0, 4, 6, 8, 8, 12, 14, 16, 38, 50, 52, 54, 56, 66, 68, 76, 88], \"arr_size\": 18, \"sum\": 19}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"a\": [1, 1, 0, 0, 1, 0, 1, 1], \"arr_size\": 4, \"sum\": 5}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"a\": [7, 22, 24, 30, 42, 44, 49, 49, 65, 70, 70, 74, 74, 75, 90, 95, 96], \"arr_size\": 8, \"sum\": 13}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"a\": [40, -76, -68, -86, -14, 82, -20, 54, -26, 56, -24, -44, 44, 60, 52, -20, 80, -24, -90, -30, -2], \"arr_size\": 11, \"sum\": 18}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr_size\": 15, \"sum\": 17}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"a\": [33, 92, 6, 99, 83, 97, 49, 97, 85, 52], \"arr_size\": 6, \"sum\": 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 ] }
163
Find A Triplet That Sum To A Given Value 1
C++
bool findATripletThatSumToAGivenValue1(vector<int> a, int arr_size, int sum) {
[ "a", "arr_size", "sum" ]
def find_a_triplet_that_sum_to_a_given_value_1(A, arr_size, sum): A.sort() for i in range(0, (arr_size - 2)): l = (i + 1) r = (arr_size - 1) while (l < r): if (((A[i] + A[l]) + A[r]) == sum): print('Triplet is', A[i], ', ', A[l], ', ', A[r]) return True elif (((A[i] + A[l]) + A[r]) < sum): l += 1 else: r -= 1 return False
bool find_a_triplet_that_sum_to_a_given_value_1(vector<int> A, int arr_size, int sum) { int l, r; sort(A.begin(), A.end()); for ( int i = 0; i < arr_size - 2; i ++ ) { l = i + 1; r = arr_size - 1; while ( l < r ) { if ( A [ i ] + A [ l ] + A [ r ] == sum ) { return true; } else if ( A [ i ] + A [ l ] + A [ r ] < sum ) l ++; else r --; } } 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> a, int arr_size, int sum, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, arr_size, 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({28, 47, 65, 89}, 3, 3, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -88, -88, -70, -66, -64, -64, -56, -52, -48, -42, -40, -26, -16, -14, -8, -2, 0, 6, 12, 12, 14, 18, 46, 50, 52, 52, 52, 58, 68, 70, 70, 74, 78, 84, 96, 98}, 22, 24, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0}, 0, 0, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, 49, 52, 54, 66, 80, 87, 93}, 5, 7, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -86, -74, -62, -60, -56, -54, -46, -38, -32, -26, -16, -16, -8, -4, 0, 6, 20, 28, 42, 44, 56}, 13, 19, false); \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}, 39, 39, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 2, 16, 16, 20, 24, 24, 38, 41, 54, 57, 72, 79, 83, 89, 90, 96, 97, 98}, 12, 12, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-30, 22, 52, 78}, 2, 3, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 16, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 4, 6, 9, 10, 11, 11, 16, 16, 20, 23, 26, 28, 28, 40, 41, 41, 44, 48, 49, 50, 51, 52, 58, 58, 72, 77, 83, 83, 92, 92, 98}, 29, 27, true); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findATripletThatSumToAGivenValue1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"a\": [28, 47, 65, 89], \"arr_size\": 3, \"sum\": 3}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"a\": [-90, -88, -88, -70, -66, -64, -64, -56, -52, -48, -42, -40, -26, -16, -14, -8, -2, 0, 6, 12, 12, 14, 18, 46, 50, 52, 52, 52, 58, 68, 70, 70, 74, 78, 84, 96, 98], \"arr_size\": 22, \"sum\": 24}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"a\": [0], \"arr_size\": 0, \"sum\": 0}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"a\": [22, 49, 52, 54, 66, 80, 87, 93], \"arr_size\": 5, \"sum\": 7}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"a\": [-96, -92, -86, -74, -62, -60, -56, -54, -46, -38, -32, -26, -16, -16, -8, -4, 0, 6, 20, 28, 42, 44, 56], \"arr_size\": 13, \"sum\": 19}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr_size\": 39, \"sum\": 39}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"a\": [1, 2, 16, 16, 20, 24, 24, 38, 41, 54, 57, 72, 79, 83, 89, 90, 96, 97, 98], \"arr_size\": 12, \"sum\": 12}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"a\": [-30, 22, 52, 78], \"arr_size\": 2, \"sum\": 3}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr_size\": 21, \"sum\": 16}}, {\"idx\": 9, \"outputs\": true, \"inputs\": {\"a\": [1, 4, 6, 9, 10, 11, 11, 16, 16, 20, 23, 26, 28, 28, 40, 41, 41, 44, 48, 49, 50, 51, 52, 58, 58, 72, 77, 83, 83, 92, 92, 98], \"arr_size\": 29, \"sum\": 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 ] }
164
Find A Triplet That Sum To A Given Value 2
C++
bool findATripletThatSumToAGivenValue2(vector<int> a, int arr_size, int sum) {
[ "a", "arr_size", "sum" ]
def find_a_triplet_that_sum_to_a_given_value_2(A, arr_size, sum): for i in range(0, (arr_size - 1)): s = set() curr_sum = (sum - A[i]) for j in range((i + 1), arr_size): if ((curr_sum - A[j]) in s): print('Triplet is', A[i], ', ', A[j], ', ', (curr_sum - A[j])) return True s.add(A[j]) return False
bool find_a_triplet_that_sum_to_a_given_value_2(vector<int> A, int arr_size, int sum) { for ( int i = 0; i < arr_size - 2; i ++ ) { unordered_set < int > s; int curr_sum = sum - A [ i ]; for ( int j = i + 1; j < arr_size; j ++ ) { if ( s . find ( curr_sum - A [ j ] ) != s . end ( ) ) { return true; } s . insert ( A [ j ] ); } } 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> a, int arr_size, int sum, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, arr_size, 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({1, 6, 8, 8, 9, 11, 13, 13, 15, 17, 21, 24, 38, 38, 42, 43, 46, 46, 47, 54, 55, 56, 57, 58, 60, 60, 60, 62, 63, 63, 65, 66, 67, 67, 69, 81, 84, 84, 85, 86, 95, 99}, 27, 24, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({20, -86, -24, 38, -32, -64, -72, 72, 68, 94, 18, -60, -4, -18, -18, -70, 6, -86, 46, -16, 46, -28}, 21, 20, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 13, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({13, 96, 31, 39, 23, 39, 50, 10, 21, 64, 41, 54, 44, 97, 24, 91, 79, 86, 38, 49, 77, 71, 8, 98, 85, 36, 37, 65, 42, 48}, 17, 18, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -68, -58, -56, -54, -54, -48, -40, -36, -32, -26, -16, -14, -12, -12, -4, -4, -4, 0, 10, 22, 22, 30, 54, 62, 68, 88, 88}, 21, 25, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1, 0, 0}, 5, 3, true); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 8, 9, 13, 20, 24, 29, 52, 53, 96}, 9, 8, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({18, -92, -10, 26, 58, -48, 38, 66, -98, -72, 4, 76, -52, 20, 60, -56, 96, 60, -10, -26, -64, -66, -22, -86, 74, 82, 2, -14, 76, 82, 40, 70, -40, -2, -46, -38, 22, 98, 58}, 30, 30, true); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1}, 2, 2, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({72}, 0, 0, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findATripletThatSumToAGivenValue2", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"a\": [1, 6, 8, 8, 9, 11, 13, 13, 15, 17, 21, 24, 38, 38, 42, 43, 46, 46, 47, 54, 55, 56, 57, 58, 60, 60, 60, 62, 63, 63, 65, 66, 67, 67, 69, 81, 84, 84, 85, 86, 95, 99], \"arr_size\": 27, \"sum\": 24}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"a\": [20, -86, -24, 38, -32, -64, -72, 72, 68, 94, 18, -60, -4, -18, -18, -70, 6, -86, 46, -16, 46, -28], \"arr_size\": 21, \"sum\": 20}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"a\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr_size\": 17, \"sum\": 13}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"a\": [13, 96, 31, 39, 23, 39, 50, 10, 21, 64, 41, 54, 44, 97, 24, 91, 79, 86, 38, 49, 77, 71, 8, 98, 85, 36, 37, 65, 42, 48], \"arr_size\": 17, \"sum\": 18}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"a\": [-86, -68, -58, -56, -54, -54, -48, -40, -36, -32, -26, -16, -14, -12, -12, -4, -4, -4, 0, 10, 22, 22, 30, 54, 62, 68, 88, 88], \"arr_size\": 21, \"sum\": 25}}, {\"idx\": 5, \"outputs\": true, \"inputs\": {\"a\": [0, 1, 1, 1, 1, 0, 0], \"arr_size\": 5, \"sum\": 3}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"a\": [8, 8, 9, 13, 20, 24, 29, 52, 53, 96], \"arr_size\": 9, \"sum\": 8}}, {\"idx\": 7, \"outputs\": true, \"inputs\": {\"a\": [18, -92, -10, 26, 58, -48, 38, 66, -98, -72, 4, 76, -52, 20, 60, -56, 96, 60, -10, -26, -64, -66, -22, -86, 74, 82, 2, -14, 76, 82, 40, 70, -40, -2, -46, -38, 22, 98, 58], \"arr_size\": 30, \"sum\": 30}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"a\": [1, 1, 1, 1], \"arr_size\": 2, \"sum\": 2}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"a\": [72], \"arr_size\": 0, \"sum\": 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 ] }
165
Find Expression Duplicate Parenthesis Not
C++
bool findExpressionDuplicateParenthesisNot(string string_arg0) {
[ "string_arg0" ]
def find_expression_duplicate_parenthesis_not(string): Stack = [] for ch in string: if (ch == ')'): top = Stack.pop() elementsInside = 0 while (top != '('): elementsInside += 1 top = Stack.pop() if (elementsInside < 1): return True else: Stack.append(ch) return False
bool find_expression_duplicate_parenthesis_not(string str) { stack < char > Stack; for ( char ch : str ) { if ( ch == ')' ) { char top = Stack . top ( ); Stack . pop ( ); int elementsInside = 0; while ( top != '(' ) { elementsInside ++; top = Stack . top ( ); Stack . pop ( ); } if ( elementsInside < 1 ) { return 1; } } else Stack . push ( ch ); } return false; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"((a+b)+((c+d)))\", true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(((a+(b)))+(c+d))\", true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(((a+(b))+c+d))\", true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"((a+b)+(c+d))\", false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(8582007)\", false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"((a+(b))+(c+d))\", false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"(PylsShEdKAE)\", false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"886980680541\", false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"001\", false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"jsVmFeOq\", false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findExpressionDuplicateParenthesisNot", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"string_arg0\": \"((a+b)+((c+d)))\"}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"string_arg0\": \"(((a+(b)))+(c+d))\"}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"string_arg0\": \"(((a+(b))+c+d))\"}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"string_arg0\": \"((a+b)+(c+d))\"}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"string_arg0\": \"(8582007)\"}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"string_arg0\": \"((a+(b))+(c+d))\"}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"string_arg0\": \"(PylsShEdKAE)\"}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"string_arg0\": \"886980680541\"}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"string_arg0\": \"001\"}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"string_arg0\": \"jsVmFeOq\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
166
Find First Natural Number Whose Factorial Divisible X
C++
int findFirstNaturalNumberWhoseFactorialDivisibleX(int x) {
[ "x" ]
def find_first_natural_number_whose_factorial_divisible_x(x): i = 1 fact = 1 for i in range(1, x): fact = (fact * i) if ((fact % x) == 0): break return i
int find_first_natural_number_whose_factorial_divisible_x(int x) { int i = 1; int fact = 1; for ( i = 1; i < x; i ++ ) { fact = fact * i; if ( fact % x == 0 ) break; } return i; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(67, 66); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 46); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 19); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 88); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 66); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 6); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 82); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 31); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 42); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findFirstNaturalNumberWhoseFactorialDivisibleX", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 66, \"inputs\": {\"x\": 67}}, {\"idx\": 1, \"outputs\": 46, \"inputs\": {\"x\": 47}}, {\"idx\": 2, \"outputs\": 19, \"inputs\": {\"x\": 57}}, {\"idx\": 3, \"outputs\": 88, \"inputs\": {\"x\": 89}}, {\"idx\": 4, \"outputs\": 66, \"inputs\": {\"x\": 67}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"x\": 40}}, {\"idx\": 6, \"outputs\": 6, \"inputs\": {\"x\": 16}}, {\"idx\": 7, \"outputs\": 82, \"inputs\": {\"x\": 83}}, {\"idx\": 8, \"outputs\": 31, \"inputs\": {\"x\": 93}}, {\"idx\": 9, \"outputs\": 42, \"inputs\": {\"x\": 43}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
167
Find Harmonic Mean Using Arithmetic Mean Geometric Mean
C++
double findHarmonicMeanUsingArithmeticMeanGeometricMean(int a, int b) {
[ "a", "b" ]
def find_harmonic_mean_using_arithmetic_mean_geometric_mean(a, b): AM = ((a + b) / 2) GM = math.sqrt((a * b)) HM = ((GM * GM) / AM) return HM
double find_harmonic_mean_using_arithmetic_mean_geometric_mean(int a, int b) { double AM, GM, HM; AM = ( a + b ) / 2; GM = sqrt ( a * b ); HM = ( GM * GM ) / AM; return HM; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(54, 83, 65.43065693430657); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 56, 48.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 12, 20.16); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 76, 30.4); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 50, 45.054945054945065); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 26, 11.030303030303031); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 42, 40.444444444444436); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 64, 18.773333333333333); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 81, 87.86440677966101); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 54, 23.47826086956522); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findHarmonicMeanUsingArithmeticMeanGeometricMean", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 65.43065693430657, \"inputs\": {\"a\": 54, \"b\": 83}}, {\"idx\": 1, \"outputs\": 48.0, \"inputs\": {\"a\": 42, \"b\": 56}}, {\"idx\": 2, \"outputs\": 20.16, \"inputs\": {\"a\": 63, \"b\": 12}}, {\"idx\": 3, \"outputs\": 30.4, \"inputs\": {\"a\": 19, \"b\": 76}}, {\"idx\": 4, \"outputs\": 45.054945054945065, \"inputs\": {\"a\": 41, \"b\": 50}}, {\"idx\": 5, \"outputs\": 11.030303030303031, \"inputs\": {\"a\": 7, \"b\": 26}}, {\"idx\": 6, \"outputs\": 40.444444444444436, \"inputs\": {\"a\": 39, \"b\": 42}}, {\"idx\": 7, \"outputs\": 18.773333333333333, \"inputs\": {\"a\": 11, \"b\": 64}}, {\"idx\": 8, \"outputs\": 87.86440677966101, \"inputs\": {\"a\": 96, \"b\": 81}}, {\"idx\": 9, \"outputs\": 23.47826086956522, \"inputs\": {\"a\": 15, \"b\": 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 ] }
168
Find Index Given Fibonacci Number Constant Time
C++
int findIndexGivenFibonacciNumberConstantTime(int n) {
[ "n" ]
def find_index_given_fibonacci_number_constant_time(n): if (n <= 1): return n a = 0 b = 1 c = 1 res = 1 while (c < n): c = (a + b) res = (res + 1) a = b b = c return res
int find_index_given_fibonacci_number_constant_time(int n) { if ( n <= 1 ) return n; int a = 0, b = 1, c = 1; int res = 1; while ( c < n ) { c = a + b; res ++; a = b; b = c; } return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(5, 5); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 8); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 12); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 11); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 11); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 11); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 12); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 11); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 8); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findIndexGivenFibonacciNumberConstantTime", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 5, \"inputs\": {\"n\": 5}}, {\"idx\": 1, \"outputs\": 8, \"inputs\": {\"n\": 19}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"n\": 7}}, {\"idx\": 3, \"outputs\": 12, \"inputs\": {\"n\": 94}}, {\"idx\": 4, \"outputs\": 11, \"inputs\": {\"n\": 58}}, {\"idx\": 5, \"outputs\": 11, \"inputs\": {\"n\": 65}}, {\"idx\": 6, \"outputs\": 11, \"inputs\": {\"n\": 69}}, {\"idx\": 7, \"outputs\": 12, \"inputs\": {\"n\": 96}}, {\"idx\": 8, \"outputs\": 11, \"inputs\": {\"n\": 80}}, {\"idx\": 9, \"outputs\": 8, \"inputs\": {\"n\": 14}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
169
Find Index Given Fibonacci Number Constant Time 1
C++
int findIndexGivenFibonacciNumberConstantTime1(int n) {
[ "n" ]
def find_index_given_fibonacci_number_constant_time_1(n): fibo = ((2.078087 * math.log(n)) + 1.672276) return round(fibo)
int find_index_given_fibonacci_number_constant_time_1(int n) { float fibo = 2.078087 * log ( n ) + 1.672276; return round ( fibo ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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(20, 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 11); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 9); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(21, 8); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 11); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 11); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 10); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 10); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 8); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findIndexGivenFibonacciNumberConstantTime1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"n\": 20}}, {\"idx\": 1, \"outputs\": 11, \"inputs\": {\"n\": 95}}, {\"idx\": 2, \"outputs\": 9, \"inputs\": {\"n\": 39}}, {\"idx\": 3, \"outputs\": 8, \"inputs\": {\"n\": 21}}, {\"idx\": 4, \"outputs\": 11, \"inputs\": {\"n\": 94}}, {\"idx\": 5, \"outputs\": 11, \"inputs\": {\"n\": 79}}, {\"idx\": 6, \"outputs\": 10, \"inputs\": {\"n\": 56}}, {\"idx\": 7, \"outputs\": 10, \"inputs\": {\"n\": 62}}, {\"idx\": 8, \"outputs\": 8, \"inputs\": {\"n\": 23}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"n\": 3}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
170
Find Index Of An Extra Element Present In One Sorted Array
C++
int findIndexOfAnExtraElementPresentInOneSortedArray(vector<int> arr1, vector<int> arr2, int n) {
[ "arr1", "arr2", "n" ]
def find_index_of_an_extra_element_present_in_one_sorted_array(arr1, arr2, n): for i in range(0, n): if (arr1[i] != arr2[i]): return i return n
int find_index_of_an_extra_element_present_in_one_sorted_array(vector<int> arr1, vector<int> arr2, int n) { for ( int i = 0; i < n; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i; return n; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, 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, 7, 10, 11, 12, 12, 16, 17, 29, 32, 33, 35, 35, 45, 49, 52, 56, 57, 58, 61, 62, 63, 64, 68, 71, 71, 77, 79, 79, 81, 82, 82, 83, 83, 89, 89, 93, 94, 94}, {3, 12, 13, 14, 15, 17, 18, 19, 22, 24, 28, 29, 33, 37, 41, 42, 44, 49, 51, 51, 52, 53, 56, 56, 59, 60, 64, 64, 67, 70, 71, 78, 83, 88, 88, 90, 92, 93, 93, 95}, 36, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-48, -92, 96, -18, 10, -24, -4, 96, -16, -78, 4, -80, -96, -28, -78, 68, 2, -60, 0}, {-38, -40, -50, 50, -26, -80, 64, 54, 74, -44, -40, -92, -16, 4, -60, -42, -60, -74, 38}, 16, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1}, {0}, 0, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, 98, 21, 29, 71, 49}, {97, 90, 25, 89, 57, 41}, 3, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-80, -76, -76, -76, -68, -66, -56, -44, -38, -28, -24, -10, 8, 14, 16, 18, 24, 26, 30, 32, 50, 64, 76, 80, 90, 94, 94, 94}, {-90, -88, -66, -60, -48, -48, -46, -42, -40, -36, -26, -4, 2, 4, 4, 8, 16, 18, 34, 50, 52, 56, 64, 80, 86, 90, 92, 96}, 14, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1}, {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1}, 22, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 7, 16, 17, 20, 22, 29, 32, 34, 34, 35, 40, 40, 40, 41, 46, 49, 58, 60, 62, 63, 64, 64, 68, 70, 73, 76, 79, 83, 86, 90, 92, 99}, {4, 4, 7, 13, 23, 23, 25, 25, 26, 34, 38, 39, 39, 45, 48, 50, 52, 54, 58, 59, 60, 65, 72, 76, 80, 80, 80, 84, 87, 90, 92, 94, 96}, 26, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({18, -68, -6, -32, -76, -86, -8, 76, -46, 20, -80, 54, -88, -58, -48, -66, -66, 18, -28, -74, -72, -26, -92, -78, 24, -22, -80, -80, 82, -2, -72, -88, -54, -84, -8}, {-30, 96, 92, -12, -14, -68, -16, 20, 74, -42, 36, 84, -82, 66, 44, 70, -92, -56, -28, -68, -4, 10, -4, 90, 72, 84, 68, 14, 32, 60, 40, 60, -34, 58, -56}, 17, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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}, 24, 24); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({74, 75, 52, 58, 34, 53, 51, 45, 34, 28, 53, 94, 10, 20, 23, 12, 95, 78, 48, 11}, {62, 56, 17, 1, 11, 30, 59, 18, 99, 21, 86, 49, 24, 85, 25, 56, 21, 66, 23, 96}, 17, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findIndexOfAnExtraElementPresentInOneSortedArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr1\": [1, 6, 7, 10, 11, 12, 12, 16, 17, 29, 32, 33, 35, 35, 45, 49, 52, 56, 57, 58, 61, 62, 63, 64, 68, 71, 71, 77, 79, 79, 81, 82, 82, 83, 83, 89, 89, 93, 94, 94], \"arr2\": [3, 12, 13, 14, 15, 17, 18, 19, 22, 24, 28, 29, 33, 37, 41, 42, 44, 49, 51, 51, 52, 53, 56, 56, 59, 60, 64, 64, 67, 70, 71, 78, 83, 88, 88, 90, 92, 93, 93, 95], \"n\": 36}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr1\": [-48, -92, 96, -18, 10, -24, -4, 96, -16, -78, 4, -80, -96, -28, -78, 68, 2, -60, 0], \"arr2\": [-38, -40, -50, 50, -26, -80, 64, 54, 74, -44, -40, -92, -16, 4, -60, -42, -60, -74, 38], \"n\": 16}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr1\": [1], \"arr2\": [0], \"n\": 0}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr1\": [68, 98, 21, 29, 71, 49], \"arr2\": [97, 90, 25, 89, 57, 41], \"n\": 3}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr1\": [-80, -76, -76, -76, -68, -66, -56, -44, -38, -28, -24, -10, 8, 14, 16, 18, 24, 26, 30, 32, 50, 64, 76, 80, 90, 94, 94, 94], \"arr2\": [-90, -88, -66, -60, -48, -48, -46, -42, -40, -36, -26, -4, 2, 4, 4, 8, 16, 18, 34, 50, 52, 56, 64, 80, 86, 90, 92, 96], \"n\": 14}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr1\": [0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1], \"arr2\": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], \"n\": 22}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr1\": [3, 7, 16, 17, 20, 22, 29, 32, 34, 34, 35, 40, 40, 40, 41, 46, 49, 58, 60, 62, 63, 64, 64, 68, 70, 73, 76, 79, 83, 86, 90, 92, 99], \"arr2\": [4, 4, 7, 13, 23, 23, 25, 25, 26, 34, 38, 39, 39, 45, 48, 50, 52, 54, 58, 59, 60, 65, 72, 76, 80, 80, 80, 84, 87, 90, 92, 94, 96], \"n\": 26}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr1\": [18, -68, -6, -32, -76, -86, -8, 76, -46, 20, -80, 54, -88, -58, -48, -66, -66, 18, -28, -74, -72, -26, -92, -78, 24, -22, -80, -80, 82, -2, -72, -88, -54, -84, -8], \"arr2\": [-30, 96, 92, -12, -14, -68, -16, 20, 74, -42, 36, 84, -82, 66, 44, 70, -92, -56, -28, -68, -4, 10, -4, 90, 72, 84, 68, 14, 32, 60, 40, 60, -34, 58, -56], \"n\": 17}}, {\"idx\": 8, \"outputs\": 24, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"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], \"n\": 24}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr1\": [74, 75, 52, 58, 34, 53, 51, 45, 34, 28, 53, 94, 10, 20, 23, 12, 95, 78, 48, 11], \"arr2\": [62, 56, 17, 1, 11, 30, 59, 18, 99, 21, 86, 49, 24, 85, 25, 56, 21, 66, 23, 96], \"n\": 17}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
171
Find Index Of An Extra Element Present In One Sorted Array 1
C++
int findIndexOfAnExtraElementPresentInOneSortedArray1(vector<int> arr1, vector<int> arr2, int n) {
[ "arr1", "arr2", "n" ]
def find_index_of_an_extra_element_present_in_one_sorted_array_1(arr1, arr2, n): index = n left = 0 right = (n - 1) while (left <= right): mid = int(((left + right) / 2)) if (arr2[mid] == arr1[mid]): left = (mid + 1) else: index = mid right = (mid - 1) return index
int find_index_of_an_extra_element_present_in_one_sorted_array_1(vector<int> arr1, vector<int> arr2, int n) { int index = n; int left = 0, right = n - 1; while ( left <= right ) { int mid = ( left + right ) / 2; if ( arr2 [ mid ] == arr1 [ mid ] ) left = mid + 1; else { index = mid; right = mid - 1; } } return index; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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 n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, 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, 18, 19, 25, 26, 27, 31, 39, 44, 46, 59, 60, 66, 72, 78, 83, 84, 92, 94}, {2, 5, 12, 13, 17, 20, 22, 46, 51, 63, 64, 66, 66, 76, 87, 87, 90, 91, 96}, 11, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-14, -56, 92, -90, 96, -84, 64, -38, -20, 84, 56, 92, 18, -78, 98, -96, -60, 88, -52, -28, 30, -90, 14, 76, 56, 20, -18, -94, -82, -2, 96, -60, -64, -90, 42, 6, 20, -38, 82, -86, -4, 82, 54, -88}, {54, 44, -50, 26, 4, -26, -76, 98, -14, 36, 82, 0, -60, 18, 52, 82, -12, -8, -26, -58, 22, -70, 24, 48, 56, -46, 92, 98, -50, -72, -66, 8, 40, 12, -80, -86, 90, -30, 76, -92, 80, -62, 0, -48}, 26, 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, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 31, 14); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({13, 64, 73, 50, 73, 19, 92, 10, 64, 79, 58, 41, 97, 53, 53, 10, 96, 45, 47, 38, 99}, {24, 42, 54, 13, 88, 63, 50, 73, 64, 66, 86, 84, 53, 4, 44, 58, 44, 42, 36, 94, 34}, 13, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -90, -90, -78, -70, -64, -64, -58, -58, -52, -40, -36, -34, -34, -30, -26, -2, 0, 2, 14, 18, 24, 28, 28, 30, 34, 40, 42, 48, 66, 72, 86, 90, 92, 98}, {-94, -92, -90, -88, -86, -82, -82, -80, -76, -74, -64, -60, -58, -46, -44, -36, -30, -30, -30, -18, -16, -8, -6, 12, 14, 20, 26, 38, 40, 42, 42, 68, 78, 82, 88, 98}, 29, 3); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0}, {0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0}, 19, 6); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 51, 74, 74, 75, 80, 90}, {12, 20, 36, 38, 61, 64, 93}, 5, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-44, 48, 20, -38, -48, -26, 56, -62, -94, -18, 30, 66, -16, 80, 96, -40, -80, 32, 88, -56, -76, 16, 72, -94, 4, -34, -92, 70, -90, -54, 64, -90}, {-76, 92, -66, 20, 86, 40, 64, 16, 54, -6, 54, -88, -24, 38, 86, 2, 30, 70, 98, -46, 28, 34, 40, -88, -96, 92, 22, 14, -36, -96, -48, -72}, 28, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 14, 9); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({19, 53, 13, 91, 52, 62, 39, 84, 68, 45, 32, 40, 13, 68, 79, 76, 11, 42, 76, 30, 81, 3, 30, 15, 85, 76, 1}, {33, 65, 36, 82, 30, 95, 42, 33, 9, 21, 25, 90, 54, 59, 21, 45, 3, 93, 67, 50, 97, 72, 77, 54, 75, 8, 6}, 25, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findIndexOfAnExtraElementPresentInOneSortedArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr1\": [7, 18, 19, 25, 26, 27, 31, 39, 44, 46, 59, 60, 66, 72, 78, 83, 84, 92, 94], \"arr2\": [2, 5, 12, 13, 17, 20, 22, 46, 51, 63, 64, 66, 66, 76, 87, 87, 90, 91, 96], \"n\": 11}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr1\": [-14, -56, 92, -90, 96, -84, 64, -38, -20, 84, 56, 92, 18, -78, 98, -96, -60, 88, -52, -28, 30, -90, 14, 76, 56, 20, -18, -94, -82, -2, 96, -60, -64, -90, 42, 6, 20, -38, 82, -86, -4, 82, 54, -88], \"arr2\": [54, 44, -50, 26, 4, -26, -76, 98, -14, 36, 82, 0, -60, 18, 52, 82, -12, -8, -26, -58, 22, -70, 24, 48, 56, -46, 92, 98, -50, -72, -66, 8, 40, 12, -80, -86, 90, -30, 76, -92, 80, -62, 0, -48], \"n\": 26}}, {\"idx\": 2, \"outputs\": 14, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 31}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr1\": [13, 64, 73, 50, 73, 19, 92, 10, 64, 79, 58, 41, 97, 53, 53, 10, 96, 45, 47, 38, 99], \"arr2\": [24, 42, 54, 13, 88, 63, 50, 73, 64, 66, 86, 84, 53, 4, 44, 58, 44, 42, 36, 94, 34], \"n\": 13}}, {\"idx\": 4, \"outputs\": 3, \"inputs\": {\"arr1\": [-96, -94, -90, -90, -78, -70, -64, -64, -58, -58, -52, -40, -36, -34, -34, -30, -26, -2, 0, 2, 14, 18, 24, 28, 28, 30, 34, 40, 42, 48, 66, 72, 86, 90, 92, 98], \"arr2\": [-94, -92, -90, -88, -86, -82, -82, -80, -76, -74, -64, -60, -58, -46, -44, -36, -30, -30, -30, -18, -16, -8, -6, 12, 14, 20, 26, 38, 40, 42, 42, 68, 78, 82, 88, 98], \"n\": 29}}, {\"idx\": 5, \"outputs\": 6, \"inputs\": {\"arr1\": [1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0], \"arr2\": [0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0], \"n\": 19}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr1\": [10, 51, 74, 74, 75, 80, 90], \"arr2\": [12, 20, 36, 38, 61, 64, 93], \"n\": 5}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr1\": [-44, 48, 20, -38, -48, -26, 56, -62, -94, -18, 30, 66, -16, 80, 96, -40, -80, 32, 88, -56, -76, 16, 72, -94, 4, -34, -92, 70, -90, -54, 64, -90], \"arr2\": [-76, 92, -66, 20, 86, 40, 64, 16, 54, -6, 54, -88, -24, 38, 86, 2, 30, 70, 98, -46, 28, 34, 40, -88, -96, 92, 22, 14, -36, -96, -48, -72], \"n\": 28}}, {\"idx\": 8, \"outputs\": 9, \"inputs\": {\"arr1\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"arr2\": [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\": 14}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr1\": [19, 53, 13, 91, 52, 62, 39, 84, 68, 45, 32, 40, 13, 68, 79, 76, 11, 42, 76, 30, 81, 3, 30, 15, 85, 76, 1], \"arr2\": [33, 65, 36, 82, 30, 95, 42, 33, 9, 21, 25, 90, 54, 59, 21, 45, 3, 93, 67, 50, 97, 72, 77, 54, 75, 8, 6], \"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 ] }
172
Find Largest D In Array Such That A B C D
C++
int findLargestDInArraySuchThatABCD(vector<int> s, int n) {
[ "s", "n" ]
def find_largest_d_in_array_such_that_a_b_c_d(S, n): found = False S.sort() for i in range((n - 1), (- 1), (- 1)): for j in range(0, n): if (i == j): continue for k in range((j + 1), n): if (i == k): continue for l in range((k + 1), n): if (i == l): continue if (S[i] == ((S[j] + S[k]) + S[l])): found = True return S[i] if (found == False): return (- 1)
int find_largest_d_in_array_such_that_a_b_c_d(vector<int> S, int n) { bool found = false; sort(S.begin(), S.end()); for ( int i = n - 1; i >= 0; i -- ) { for ( int j = 0; j < n; j ++ ) { if ( i == j ) continue; for ( int k = j + 1; k < n; k ++ ) { if ( i == k ) continue; for ( int l = k + 1; l < n; l ++ ) { if ( i == l ) continue; if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) { found = true; return S [ i ]; } } } } } if ( found == false ) return INT_MIN; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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> s, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s, 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, 12, 14, 15, 16, 20, 27, 28, 29, 30, 35, 41, 46, 51, 53, 55, 55, 58, 63, 64, 72, 73, 75, 75, 75, 82, 82, 86, 89, 91, 92, 94, 95, 95, 97, 97, 98}, 24, 75); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -82, -62, -58, -56, -50, -44, -44, -40, -28, -22, -20, -12, -2, 10, 26, 34, 42, 48, 74, 86, 92}, 19, 48); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1}, 8, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 10, 47, 54, 55, 58, 65, 66, 67, 77, 84}, 5, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-46, -28, -20, -18, 4, 8, 18, 38, 90, 90}, 6, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 35, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({11, 13, 14, 21, 26, 28, 36, 39, 41, 42, 43, 44, 49, 49, 57, 58, 59, 59, 63, 64, 67, 69, 70, 75, 78, 79, 83, 83, 86, 91, 92, 93, 96, 96, 96, 97}, 30, 91); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-88, -82, -82, -76, -70, -66, -62, -56, -48, -48, -32, -30, -18, -16, 0, 4, 34, 38, 46, 46, 50, 52, 54, 54, 62, 74, 76, 78, 96}, 16, -30); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 5, 6, 9, 11, 14, 18, 20, 21, 25, 33, 49, 55, 56, 58, 61, 66, 66, 68, 74, 74, 87, 92, 99}, 23, 92); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findLargestDInArraySuchThatABCD", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 75, \"inputs\": {\"s\": [8, 12, 14, 15, 16, 20, 27, 28, 29, 30, 35, 41, 46, 51, 53, 55, 55, 58, 63, 64, 72, 73, 75, 75, 75, 82, 82, 86, 89, 91, 92, 94, 95, 95, 97, 97, 98], \"n\": 24}}, {\"idx\": 1, \"outputs\": 48, \"inputs\": {\"s\": [-96, -82, -62, -58, -56, -50, -44, -44, -40, -28, -22, -20, -12, -2, 10, 26, 34, 42, 48, 74, 86, 92], \"n\": 19}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"s\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1], \"n\": 8}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"s\": [10, 10, 47, 54, 55, 58, 65, 66, 67, 77, 84], \"n\": 5}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"s\": [-46, -28, -20, -18, 4, 8, 18, 38, 90, 90], \"n\": 6}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"s\": [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\": 35}}, {\"idx\": 6, \"outputs\": 91, \"inputs\": {\"s\": [11, 13, 14, 21, 26, 28, 36, 39, 41, 42, 43, 44, 49, 49, 57, 58, 59, 59, 63, 64, 67, 69, 70, 75, 78, 79, 83, 83, 86, 91, 92, 93, 96, 96, 96, 97], \"n\": 30}}, {\"idx\": 7, \"outputs\": -30, \"inputs\": {\"s\": [-88, -82, -82, -76, -70, -66, -62, -56, -48, -48, -32, -30, -18, -16, 0, 4, 34, 38, 46, 46, 50, 52, 54, 54, 62, 74, 76, 78, 96], \"n\": 16}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"s\": [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\": 17}}, {\"idx\": 9, \"outputs\": 92, \"inputs\": {\"s\": [4, 5, 6, 9, 11, 14, 18, 20, 21, 25, 33, 49, 55, 56, 58, 61, 66, 66, 68, 74, 74, 87, 92, 99], \"n\": 23}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
173
Find Largest D In Array Such That A B C D 1
C++
long long findLargestDInArraySuchThatABCD1(vector<int> arr, int n) {
[ "arr", "n" ]
def find_largest_d_in_array_such_that_a_b_c_d_1(arr, n): mp = dict() for i in range((n - 1)): for j in range((i + 1), n): mp[(arr[i] + arr[j])] = (i, j) d = (- (10 ** 9)) for i in range((n - 1)): for j in range((i + 1), n): abs_diff = abs((arr[i] - arr[j])) if (abs_diff in mp.keys()): p = mp[abs_diff] if ((p[0] != i) and (p[0] != j) and (p[1] != i) and (p[1] != j)): d = max(d, max(arr[i], arr[j])) return d
int find_largest_d_in_array_such_that_a_b_c_d_1(vector<int> arr, int n) { unordered_map < int, pair < int, int > > mp; for ( int i = 0; i < n - 1; i ++ ) for ( int j = i + 1; j < n; j ++ ) mp [ arr [ i ] + arr [ j ] ] = { i, j }; int d = INT_MIN; for ( int i = 0; i < n - 1; i ++ ) { for ( int j = i + 1; j < n; j ++ ) { int abs_diff = abs ( arr [ i ] - arr [ j ] ); if ( mp . find ( abs_diff ) != mp . end ( ) ) { pair < int, int > p = mp [ abs_diff ]; if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d, max ( arr [ i ], arr [ j ] ) ); } } } return d; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({1, 1, 5, 7, 10, 35, 35, 45, 49, 50, 57, 58, 60, 64, 69, 83, 83, 87, 88, 89, 93, 94}, 12, 58); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 90, 88, 0, -90, -68, 94, -2, -50, -92, 66, 32, 10, 8, -14, -96, 80, -60, 48, -96, 46, 24, 64, 2, -30, 28}, 15, 94); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({83, 72, 91, 22, 96, 38, 71, 18, 58, 39, 7, 8, 65, 67}, 7, -1000000000); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -88, -86, -82, -80, -78, -76, -74, -72, -62, -54, -42, -40, -38, -36, -36, -34, -32, -32, -26, -26, -22, -14, -14, 2, 16, 24, 26, 32, 32, 34, 48, 48, 64, 66, 70, 74, 82, 90}, 28, 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1}, 29, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 2, 4, 10, 11, 13, 15, 20, 32, 33, 33, 42, 46, 46, 50, 54, 55, 55, 56, 57, 58, 63, 68, 79, 87, 94}, 18, 55); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({58, 78, 28, 54, -10, 46, -78, -68, -44, 64, 78, 80, -54, -38, -54, 60, 26, 96}, 13, 80); \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}, 28, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({54, 55, 98, 18, 11, 55, 2, 95, 84, 14, 75, 12, 43, 54, 78, 34, 69, 24, 82, 65, 11, 49, 34, 60, 99, 71, 1, 17, 88, 12, 45, 46, 56, 28, 70, 34, 7, 55, 40, 12, 38, 56, 54, 53, 28}, 24, 98); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findLargestDInArraySuchThatABCD1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 58, \"inputs\": {\"arr\": [1, 1, 5, 7, 10, 35, 35, 45, 49, 50, 57, 58, 60, 64, 69, 83, 83, 87, 88, 89, 93, 94], \"n\": 12}}, {\"idx\": 1, \"outputs\": 94, \"inputs\": {\"arr\": [94, 90, 88, 0, -90, -68, 94, -2, -50, -92, 66, 32, 10, 8, -14, -96, 80, -60, 48, -96, 46, 24, 64, 2, -30, 28], \"n\": 15}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 17}}, {\"idx\": 3, \"outputs\": -1000000000, \"inputs\": {\"arr\": [83, 72, 91, 22, 96, 38, 71, 18, 58, 39, 7, 8, 65, 67], \"n\": 7}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"arr\": [-96, -92, -88, -86, -82, -80, -78, -76, -74, -72, -62, -54, -42, -40, -38, -36, -36, -34, -32, -32, -26, -26, -22, -14, -14, 2, 16, 24, 26, 32, 32, 34, 48, 48, 64, 66, 70, 74, 82, 90], \"n\": 28}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1], \"n\": 29}}, {\"idx\": 6, \"outputs\": 55, \"inputs\": {\"arr\": [2, 2, 4, 10, 11, 13, 15, 20, 32, 33, 33, 42, 46, 46, 50, 54, 55, 55, 56, 57, 58, 63, 68, 79, 87, 94], \"n\": 18}}, {\"idx\": 7, \"outputs\": 80, \"inputs\": {\"arr\": [58, 78, 28, 54, -10, 46, -78, -68, -44, 64, 78, 80, -54, -38, -54, 60, 26, 96], \"n\": 13}}, {\"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], \"n\": 28}}, {\"idx\": 9, \"outputs\": 98, \"inputs\": {\"arr\": [54, 55, 98, 18, 11, 55, 2, 95, 84, 14, 75, 12, 43, 54, 78, 34, 69, 24, 82, 65, 11, 49, 34, 60, 99, 71, 1, 17, 88, 12, 45, 46, 56, 28, 70, 34, 7, 55, 40, 12, 38, 56, 54, 53, 28], \"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 ] }
174
Find Largest Prime Factor Number
C++
int findLargestPrimeFactorNumber(int n) {
[ "n" ]
def find_largest_prime_factor_number(n): maxPrime = (- 1) while ((n % 2) == 0): maxPrime = 2 n >>= 1 for i in range(3, (int(math.sqrt(n)) + 1), 2): while ((n % i) == 0): maxPrime = i n = (n / i) if (n > 2): maxPrime = n return int(maxPrime)
long long find_largest_prime_factor_number(long long n) { long long maxPrime = - 1; while ( n % 2 == 0 ) { maxPrime = 2; n >>= 1; } for ( int i = 3; i <= sqrt ( n ); i += 2 ) { while ( n % i == 0 ) { maxPrime = i; n = n / i; } } if ( n > 2 ) maxPrime = n; return maxPrime; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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(98, 7); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 13); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 13); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 11); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 5); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(37, 37); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 13); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 5); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findLargestPrimeFactorNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 7, \"inputs\": {\"n\": 98}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"n\": 8}}, {\"idx\": 2, \"outputs\": 13, \"inputs\": {\"n\": 78}}, {\"idx\": 3, \"outputs\": 13, \"inputs\": {\"n\": 65}}, {\"idx\": 4, \"outputs\": 11, \"inputs\": {\"n\": 55}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"n\": 10}}, {\"idx\": 6, \"outputs\": 5, \"inputs\": {\"n\": 10}}, {\"idx\": 7, \"outputs\": 37, \"inputs\": {\"n\": 37}}, {\"idx\": 8, \"outputs\": 13, \"inputs\": {\"n\": 39}}, {\"idx\": 9, \"outputs\": 5, \"inputs\": {\"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 ] }
175
Find Last Digit Factorial Divides Factorial B
C++
int findLastDigitFactorialDividesFactorialB(int a, int b) {
[ "a", "b" ]
def find_last_digit_factorial_divides_factorial_b(A, B): variable = 1 if (A == B): return 1 elif ((B - A) >= 5): return 0 else: for i in range((A + 1), (B + 1)): variable = ((variable * (i % 10)) % 10) return (variable % 10)
int find_last_digit_factorial_divides_factorial_b(long long int A, long long int B) { int variable = 1; if ( A == B ) return 1; else if ( ( B - A ) >= 5 ) return 0; else { for ( long long int i = A + 1; i <= B; i ++ ) variable = ( variable * ( i % 10 ) ) % 10; return variable % 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 a, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(79, 84, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 29, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 77, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 65, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 78, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 73, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 92, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 50, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 63, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 2, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findLastDigitFactorialDividesFactorialB", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"a\": 79, \"b\": 84}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"a\": 61, \"b\": 29}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"a\": 39, \"b\": 77}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"a\": 39, \"b\": 65}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"a\": 61, \"b\": 78}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"a\": 86, \"b\": 73}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"a\": 7, \"b\": 92}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"a\": 86, \"b\": 50}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"a\": 86, \"b\": 63}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"a\": 11, \"b\": 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 ] }
176
Find Maximum Average Subarray Of K Length
C++
int findMaximumAverageSubarrayOfKLength(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def find_maximum_average_subarray_of_k_length(arr, n, k): if (k > n): return (- 1) csum = ([0] * n) csum[0] = arr[0] for i in range(1, n): csum[i] = (csum[(i - 1)] + arr[i]) max_sum = csum[(k - 1)] max_end = (k - 1) for i in range(k, n): curr_sum = (csum[i] - csum[(i - k)]) if (curr_sum > max_sum): max_sum = curr_sum max_end = i return ((max_end - k) + 1)
int find_maximum_average_subarray_of_k_length(vector<int> arr, int n, int k) { if ( k > n ) return - 1; int * csum = new int [ n ]; csum [ 0 ] = arr [ 0 ]; for ( int i = 1; i < n; i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ]; int max_sum = csum [ k - 1 ], max_end = k - 1; for ( int i = k; i < n; i ++ ) { int curr_sum = csum [ i ] - csum [ i - k ]; if ( curr_sum > max_sum ) { max_sum = curr_sum; max_end = i; } } delete [ ] csum; return max_end - 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> 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, 4, 6, 19, 21, 23, 32, 34, 47, 51, 56, 57, 57, 65, 68, 68, 69, 70, 71, 73, 74, 74, 77, 77, 79, 82, 82, 86, 87, 87, 88, 89, 90, 91, 92}, 29, 20, 9); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({24, 62, -32, -28, 42, -46, -96, -70, -68, 60, 44, 34, -30, 96, -26, 92, 62, 42, -46, -38, 44, 54, -94, 52, 66, 68, -96, -58, 84, -2, 66, 30, 42}, 23, 31, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 32, 31, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 6, 48, 34, 31}, 4, 3, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -88, -82, -80, -76, -70, -70, -60, -60, -52, -50, -46, -44, -44, -44, -20, -18, -12, -12, -12, -10, -8, -6, -4, 4, 4, 18, 28, 32, 34, 42, 42, 44, 46, 48, 54, 60, 70, 70, 72, 78, 78, 78, 78, 84, 86, 90, 96, 98}, 45, 30, 15); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0}, 15, 8, 4); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 5, 13, 17, 26, 26, 32, 35, 38, 38, 39, 45, 52, 58, 60, 61, 62, 63, 82, 83, 85, 89, 89, 91}, 13, 22, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-68, -52, 4, -90, 90, 88, 38, -18, 86, 4, 14, -32, -14, -44, -88, -50, -12, -26, -68, -20, -30, 22, 0, 14, -40, 58, -6, 28, -44, 8, 28, 96, -46, -12}, 32, 22, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 13, 11, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({17, 33, 36, 34, 32, 10, 37, 48, 47, 32, 21, 18, 75, 8, 18, 52, 21, 73, 25, 25, 80, 32, 10, 24, 1, 89, 7, 42, 86, 85, 73, 12, 20, 20, 1, 74, 77, 4, 24, 74, 8}, 20, 28, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMaximumAverageSubarrayOfKLength", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 9, \"inputs\": {\"arr\": [2, 4, 6, 19, 21, 23, 32, 34, 47, 51, 56, 57, 57, 65, 68, 68, 69, 70, 71, 73, 74, 74, 77, 77, 79, 82, 82, 86, 87, 87, 88, 89, 90, 91, 92], \"n\": 29, \"k\": 20}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [24, 62, -32, -28, 42, -46, -96, -70, -68, 60, 44, 34, -30, 96, -26, 92, 62, 42, -46, -38, 44, 54, -94, 52, 66, 68, -96, -58, 84, -2, 66, 30, 42], \"n\": 23, \"k\": 31}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 32, \"k\": 31}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [94, 6, 48, 34, 31], \"n\": 4, \"k\": 3}}, {\"idx\": 4, \"outputs\": 15, \"inputs\": {\"arr\": [-98, -88, -82, -80, -76, -70, -70, -60, -60, -52, -50, -46, -44, -44, -44, -20, -18, -12, -12, -12, -10, -8, -6, -4, 4, 4, 18, 28, 32, 34, 42, 42, 44, 46, 48, 54, 60, 70, 70, 72, 78, 78, 78, 78, 84, 86, 90, 96, 98], \"n\": 45, \"k\": 30}}, {\"idx\": 5, \"outputs\": 4, \"inputs\": {\"arr\": [0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0], \"n\": 15, \"k\": 8}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [1, 5, 13, 17, 26, 26, 32, 35, 38, 38, 39, 45, 52, 58, 60, 61, 62, 63, 82, 83, 85, 89, 89, 91], \"n\": 13, \"k\": 22}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"arr\": [-68, -52, 4, -90, 90, 88, 38, -18, 86, 4, 14, -32, -14, -44, -88, -50, -12, -26, -68, -20, -30, 22, 0, 14, -40, 58, -6, 28, -44, 8, 28, 96, -46, -12], \"n\": 32, \"k\": 22}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 13, \"k\": 11}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [17, 33, 36, 34, 32, 10, 37, 48, 47, 32, 21, 18, 75, 8, 18, 52, 21, 73, 25, 25, 80, 32, 10, 24, 1, 89, 7, 42, 86, 85, 73, 12, 20, 20, 1, 74, 77, 4, 24, 74, 8], \"n\": 20, \"k\": 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 ] }
177
Find Maximum Average Subarray Of K Length 1
C++
int findMaximumAverageSubarrayOfKLength1(vector<int> arr, int n, int k) {
[ "arr", "n", "k" ]
def find_maximum_average_subarray_of_k_length_1(arr, n, k): if (k > n): return (- 1) sum = arr[0] for i in range(1, k): sum += arr[i] max_sum = sum max_end = (k - 1) for i in range(k, n): sum = ((sum + arr[i]) - arr[(i - k)]) if (sum > max_sum): max_sum = sum max_end = i return ((max_end - k) + 1)
int find_maximum_average_subarray_of_k_length_1(vector<int> arr, int n, int k) { if ( k > n ) return - 1; int sum = arr [ 0 ]; for ( int i = 1; i < k; i ++ ) sum += arr [ i ]; int max_sum = sum, max_end = k - 1; for ( int i = k; i < n; i ++ ) { int sum = sum + arr [ i ] - arr [ i - k ]; if ( sum > max_sum ) { max_sum = sum; max_end = i; } } return max_end - 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> 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, 5, 11, 37, 41, 49, 49, 63, 98}, 8, 7, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({84, -72, 12, 0, 86, -32, -18, 48, 60, 42, 8, -6, -10, -6, -52, -84, -98, 76, -10, -14, -94, -48, 94, -10, -20, 40, -52, 0, 94, -68, 44, -34, -26, -6, -94, 34, -80, -62, -40, 56, 52, -20, 74, -46, -88, -26, 22}, 34, 43, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 11, 18, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({94, 97, 74, 88, 14, 66, 65, 50, 76, 55, 70, 93, 53, 30, 2, 60, 65, 24, 80, 73, 84, 95, 49, 32, 55, 70, 17, 26, 96, 20, 36, 2, 89, 49, 83, 67, 42, 51, 71, 11, 61, 78, 17, 78, 94, 68}, 35, 33, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -90, -60, -38, 38, 42}, 3, 5, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 1, 1, 1}, 3, 4, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4, 9, 17, 17, 19, 32, 35, 36, 37, 40, 44, 45, 47, 48, 48, 56, 56, 60, 61, 65, 66, 79, 83, 91, 93, 99}, 22, 24, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, 82, -92, -46, -16, -64, 28, 60, 64, 52, 54, -84, 70, 22, 24, 0, -14, 20, -90, 30, 0, 86, 12, 72, -64, -52, 86, 16, -42}, 25, 27, -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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 25, 20, 5); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({81, 77, 6, 3, 72, 24, 75, 47, 17, 29, 69, 15, 15, 50, 30, 83, 11, 7, 59, 7, 12, 82, 45, 76, 9, 48, 98, 49, 29, 66, 3, 53, 37, 13, 72, 58, 37, 87, 55}, 34, 23, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMaximumAverageSubarrayOfKLength1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [2, 5, 11, 37, 41, 49, 49, 63, 98], \"n\": 8, \"k\": 7}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [84, -72, 12, 0, 86, -32, -18, 48, 60, 42, 8, -6, -10, -6, -52, -84, -98, 76, -10, -14, -94, -48, 94, -10, -20, 40, -52, 0, 94, -68, 44, -34, -26, -6, -94, 34, -80, -62, -40, 56, 52, -20, 74, -46, -88, -26, 22], \"n\": 34, \"k\": 43}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 11, \"k\": 18}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [94, 97, 74, 88, 14, 66, 65, 50, 76, 55, 70, 93, 53, 30, 2, 60, 65, 24, 80, 73, 84, 95, 49, 32, 55, 70, 17, 26, 96, 20, 36, 2, 89, 49, 83, 67, 42, 51, 71, 11, 61, 78, 17, 78, 94, 68], \"n\": 35, \"k\": 33}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-98, -90, -60, -38, 38, 42], \"n\": 3, \"k\": 5}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [1, 0, 0, 1, 1, 1, 1], \"n\": 3, \"k\": 4}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [4, 9, 17, 17, 19, 32, 35, 36, 37, 40, 44, 45, 47, 48, 48, 56, 56, 60, 61, 65, 66, 79, 83, 91, 93, 99], \"n\": 22, \"k\": 24}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [78, 82, -92, -46, -16, -64, 28, 60, 64, 52, 54, -84, 70, 22, 24, 0, -14, 20, -90, 30, 0, 86, 12, 72, -64, -52, 86, 16, -42], \"n\": 25, \"k\": 27}}, {\"idx\": 8, \"outputs\": 5, \"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], \"n\": 25, \"k\": 20}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"arr\": [81, 77, 6, 3, 72, 24, 75, 47, 17, 29, 69, 15, 15, 50, 30, 83, 11, 7, 59, 7, 12, 82, 45, 76, 9, 48, 98, 49, 29, 66, 3, 53, 37, 13, 72, 58, 37, 87, 55], \"n\": 34, \"k\": 23}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
178
Find Maximum Dot Product Two Arrays Insertion 0S
C++
int findMaximumDotProductTwoArraysInsertion0S(vector<int> a, vector<int> b, int m, int n) {
[ "a", "b", "m", "n" ]
def find_maximum_dot_product_two_arrays_insertion_0s(A, B, m, n): dp = [[0 for i in range((m + 1))] for j in range((n + 1))] for i in range(1, (n + 1), 1): for j in range(i, (m + 1), 1): dp[i][j] = max((dp[(i - 1)][(j - 1)] + (A[(j - 1)] * B[(i - 1)])), dp[i][(j - 1)]) return dp[n][m]
long long int find_maximum_dot_product_two_arrays_insertion_0s(vector<int> A, vector<int> B, int m, int n) { long long int dp [ n + 1 ] [ m + 1 ]; memset ( dp, 0, sizeof ( dp ) ); for ( int i = 1; i <= n; i ++ ) for ( int j = i; j <= m; j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ), dp [ i ] [ j - 1 ] ); return dp [ n ] [ m ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, vector<int> b, int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, m, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({7, 9, 22, 68}, {14, 22, 54, 58}, 3, 2, 610); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({24, 40, 98, 58, -24, 24, 76, 48, -92, -16, -46, -48, -70, 88, 66, 2, 44, 36, 34, 34, 46, 90, -80, -24, -58, 68, 72, -20, -62, -40}, {30, -88, 6, -26, -76, 14, -80, -30, -58, 76, 40, -28, -54, 38, -60, -60, 88, -80, -22, 90, 50, -48, 68, -26, 26, -2, 68, -16, 88, -72}, 22, 22, 7952); \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}, {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, 19, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({32, 15, 41, 41, 4, 42, 22, 33, 33, 11, 68, 5, 41, 80, 39, 15, 36, 75, 41, 11, 25, 40, 50, 19, 39, 12, 75, 28, 52, 20, 63, 5, 27, 53, 19, 62, 98, 72, 10, 90, 74, 93, 52, 81, 91, 65, 90, 93}, {80, 18, 9, 29, 62, 89, 4, 40, 47, 15, 35, 82, 22, 97, 63, 54, 7, 58, 64, 73, 54, 79, 21, 21, 20, 19, 56, 42, 6, 97, 7, 34, 55, 35, 57, 86, 73, 88, 20, 29, 48, 52, 8, 77, 2, 12, 6, 47}, 30, 25, 50904); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -76, -68, -50, -28, -20, 18, 24, 30, 54, 74, 84, 98}, {-88, -80, -78, -68, -44, -38, 42, 50, 62, 68, 70, 80, 92}, 11, 8, 31016); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0}, {1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1}, 21, 33, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, 27, 43, 49}, {51, 59, 76, 83}, 2, 2, 2307); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({78, -26, -12, 38, -90}, {14, 50, -6, -38, 80}, 3, 2, 492); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1}, {0, 0, 0, 1}, 3, 2, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({12, 69, 57, 7, 52, 14, 15, 83, 67, 57, 15, 86, 81, 43, 1, 64, 45, 68, 30, 23, 14, 70, 13, 51, 23, 33, 98, 68, 24, 43, 12, 82, 46}, {12, 48, 57, 40, 47, 36, 22, 50, 68, 98, 77, 78, 39, 55, 87, 75, 65, 27, 33, 27, 70, 34, 67, 71, 84, 33, 7, 61, 3, 9, 67, 92, 60}, 17, 32, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMaximumDotProductTwoArraysInsertion0S", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 610, \"inputs\": {\"a\": [7, 9, 22, 68], \"b\": [14, 22, 54, 58], \"m\": 3, \"n\": 2}}, {\"idx\": 1, \"outputs\": 7952, \"inputs\": {\"a\": [24, 40, 98, 58, -24, 24, 76, 48, -92, -16, -46, -48, -70, 88, 66, 2, 44, 36, 34, 34, 46, 90, -80, -24, -58, 68, 72, -20, -62, -40], \"b\": [30, -88, 6, -26, -76, 14, -80, -30, -58, 76, 40, -28, -54, 38, -60, -60, 88, -80, -22, 90, 50, -48, 68, -26, 26, -2, 68, -16, 88, -72], \"m\": 22, \"n\": 22}}, {\"idx\": 2, \"outputs\": 0, \"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], \"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], \"m\": 22, \"n\": 19}}, {\"idx\": 3, \"outputs\": 50904, \"inputs\": {\"a\": [32, 15, 41, 41, 4, 42, 22, 33, 33, 11, 68, 5, 41, 80, 39, 15, 36, 75, 41, 11, 25, 40, 50, 19, 39, 12, 75, 28, 52, 20, 63, 5, 27, 53, 19, 62, 98, 72, 10, 90, 74, 93, 52, 81, 91, 65, 90, 93], \"b\": [80, 18, 9, 29, 62, 89, 4, 40, 47, 15, 35, 82, 22, 97, 63, 54, 7, 58, 64, 73, 54, 79, 21, 21, 20, 19, 56, 42, 6, 97, 7, 34, 55, 35, 57, 86, 73, 88, 20, 29, 48, 52, 8, 77, 2, 12, 6, 47], \"m\": 30, \"n\": 25}}, {\"idx\": 4, \"outputs\": 31016, \"inputs\": {\"a\": [-94, -76, -68, -50, -28, -20, 18, 24, 30, 54, 74, 84, 98], \"b\": [-88, -80, -78, -68, -44, -38, 42, 50, 62, 68, 70, 80, 92], \"m\": 11, \"n\": 8}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": [1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0], \"b\": [1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1], \"m\": 21, \"n\": 33}}, {\"idx\": 6, \"outputs\": 2307, \"inputs\": {\"a\": [14, 27, 43, 49], \"b\": [51, 59, 76, 83], \"m\": 2, \"n\": 2}}, {\"idx\": 7, \"outputs\": 492, \"inputs\": {\"a\": [78, -26, -12, 38, -90], \"b\": [14, 50, -6, -38, 80], \"m\": 3, \"n\": 2}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"a\": [0, 1, 1, 1], \"b\": [0, 0, 0, 1], \"m\": 3, \"n\": 2}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"a\": [12, 69, 57, 7, 52, 14, 15, 83, 67, 57, 15, 86, 81, 43, 1, 64, 45, 68, 30, 23, 14, 70, 13, 51, 23, 33, 98, 68, 24, 43, 12, 82, 46], \"b\": [12, 48, 57, 40, 47, 36, 22, 50, 68, 98, 77, 78, 39, 55, 87, 75, 65, 27, 33, 27, 70, 34, 67, 71, 84, 33, 7, 61, 3, 9, 67, 92, 60], \"m\": 17, \"n\": 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 ] }
179
Find Maximum Height Pyramid From The Given Array Of Objects
C++
int findMaximumHeightPyramidFromTheGivenArrayOfObjects(vector<int> boxes, int n) {
[ "boxes", "n" ]
def find_maximum_height_pyramid_from_the_given_array_of_objects(boxes, n): boxes.sort() ans = 1 prev_width = boxes[0] prev_count = 1 curr_count = 0 curr_width = 0 for i in range(1, n): curr_width += boxes[i] curr_count += 1 if ((curr_width > prev_width) and (curr_count > prev_count)): prev_width = curr_width prev_count = curr_count curr_count = 0 curr_width = 0 ans += 1 return ans
int find_maximum_height_pyramid_from_the_given_array_of_objects(vector<int> boxes, int n) { sort(boxes.begin(), boxes.end()); int ans = 1; int prev_width = boxes [ 0 ]; int prev_count = 1; int curr_count = 0; int curr_width = 0; for ( int i = 1; i < n; i ++ ) { curr_width += boxes [ i ]; curr_count += 1; if ( curr_width > prev_width && curr_count > prev_count ) { prev_width = curr_width; prev_count = curr_count; curr_count = 0; curr_width = 0; ans ++; } } return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> boxes, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(boxes, 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, 11, 11, 14, 19, 25, 27, 41, 42, 46, 52, 53, 54, 55, 58, 59, 62, 63, 66, 67, 69, 74, 75, 77, 81, 83, 84, 88, 88, 93, 93, 94}, 22, 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -78, -72, -60, -56, -28, -18, 12, 14, 16, 16, 20, 20, 30, 40, 72, 76, 76, 80, 86}, 12, 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 35, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 4, 6, 12, 13, 14, 15, 16, 19, 21, 22, 27, 33, 37, 37, 40, 43, 45, 48, 50, 59, 63, 64, 65, 66, 67, 67, 67, 73, 78, 80, 81, 84, 85, 85, 91, 95, 95, 97, 98}, 35, 7); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -92, -90, -88, -88, -74, -64, -64, -64, -62, -60, -52, -48, -46, -42, -42, -38, -34, -28, -26, -20, -20, -18, -4, 0, 2, 2, 6, 18, 18, 18, 20, 24, 24, 26, 32, 40, 46, 58, 66, 74, 78, 90, 96}, 30, 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({8, 12, 13, 13, 13, 16, 16, 17, 19, 20, 22, 23, 26, 29, 29, 30, 31, 37, 38, 39, 39, 41, 45, 45, 46, 49, 49, 53, 56, 62, 62, 66, 67, 68, 68, 69, 69, 73, 77, 78, 82, 85, 85, 88, 88, 97}, 26, 6); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -88, -84, -78, -76, -76, -74, -70, -68, -64, -62, -58, -44, -42, -38, -30, -28, -26, -24, -22, -20, -8, -6, 2, 4, 8, 8, 16, 18, 20, 34, 36, 40, 46, 60, 72, 78, 82, 82, 86, 90, 94, 94, 94}, 25, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 26, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 4, 21, 22, 23, 27, 27, 28, 28, 29, 30, 37, 39, 48, 50, 51, 54, 57, 61, 64, 64, 70, 71, 77, 85, 85, 88, 92, 93, 96, 97}, 18, 5); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMaximumHeightPyramidFromTheGivenArrayOfObjects", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"boxes\": [7, 8, 11, 11, 14, 19, 25, 27, 41, 42, 46, 52, 53, 54, 55, 58, 59, 62, 63, 66, 67, 69, 74, 75, 77, 81, 83, 84, 88, 88, 93, 93, 94], \"n\": 22}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"boxes\": [-96, -92, -78, -72, -60, -56, -28, -18, 12, 14, 16, 16, 20, 20, 30, 40, 72, 76, 76, 80, 86], \"n\": 12}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"boxes\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 35}}, {\"idx\": 3, \"outputs\": 7, \"inputs\": {\"boxes\": [1, 4, 6, 12, 13, 14, 15, 16, 19, 21, 22, 27, 33, 37, 37, 40, 43, 45, 48, 50, 59, 63, 64, 65, 66, 67, 67, 67, 73, 78, 80, 81, 84, 85, 85, 91, 95, 95, 97, 98], \"n\": 35}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"boxes\": [-98, -92, -90, -88, -88, -74, -64, -64, -64, -62, -60, -52, -48, -46, -42, -42, -38, -34, -28, -26, -20, -20, -18, -4, 0, 2, 2, 6, 18, 18, 18, 20, 24, 24, 26, 32, 40, 46, 58, 66, 74, 78, 90, 96], \"n\": 30}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"boxes\": [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\": 21}}, {\"idx\": 6, \"outputs\": 6, \"inputs\": {\"boxes\": [8, 12, 13, 13, 13, 16, 16, 17, 19, 20, 22, 23, 26, 29, 29, 30, 31, 37, 38, 39, 39, 41, 45, 45, 46, 49, 49, 53, 56, 62, 62, 66, 67, 68, 68, 69, 69, 73, 77, 78, 82, 85, 85, 88, 88, 97], \"n\": 26}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"boxes\": [-98, -98, -88, -84, -78, -76, -76, -74, -70, -68, -64, -62, -58, -44, -42, -38, -30, -28, -26, -24, -22, -20, -8, -6, 2, 4, 8, 8, 16, 18, 20, 34, 36, 40, 46, 60, 72, 78, 82, 82, 86, 90, 94, 94, 94], \"n\": 25}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"boxes\": [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\": 26}}, {\"idx\": 9, \"outputs\": 5, \"inputs\": {\"boxes\": [3, 4, 21, 22, 23, 27, 27, 28, 28, 29, 30, 37, 39, 48, 50, 51, 54, 57, 61, 64, 64, 70, 71, 77, 85, 85, 88, 92, 93, 96, 97], \"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 ] }
180
Find Maximum Product Of A Triplet In Array
C++
int findMaximumProductOfATripletInArray(vector<int> arr, int n) {
[ "arr", "n" ]
def find_maximum_product_of_a_triplet_in_array(arr, n): if (n < 3): return (- 1) max_product = (- (sys.maxsize - 1)) for i in range(0, (n - 2)): for j in range((i + 1), (n - 1)): for k in range((j + 1), n): max_product = max(max_product, ((arr[i] * arr[j]) * arr[k])) return max_product
int find_maximum_product_of_a_triplet_in_array(vector<int> arr, int n) { if ( n < 3 ) return - 1; int max_product = INT_MIN; for ( int i = 0; i < n - 2; i ++ ) for ( int j = i + 1; j < n - 1; j ++ ) for ( int k = j + 1; k < n; k ++ ) max_product = max ( max_product, arr [ i ] * arr [ j ] * arr [ k ] ); return max_product; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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({41, 66, 77}, 2, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({92, -34, -36, -50, 20, -94, 2, -86, 22, -50, 74, 84, 52, -84, 98, -50, 88, 26, -36, -36, 6, -50, -48, -84, 38, -96, -62, 34, 52, 92, 40, -84, 18, -90, 54, -38, -74, -98, -8, -92, -60, 86, -36, 94, 56}, 40, 921984); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1}, 1, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 77, 99, 95, 78, 15, 69, 39, 34, 43, 66, 45, 97, 27, 67, 62, 64, 2, 28, 94, 41, 87, 97, 52, 14, 61, 78, 50}, 26, 931491); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-62, -28, 40, 76}, 3, 69440); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 0, 1, 1, 1, 1, 1}, 5, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 6, 10, 11, 12, 12, 17, 18, 18, 19, 20, 22, 24, 25, 30, 35, 36, 37, 40, 41, 42, 47, 60, 60, 64, 69, 69, 70, 73, 79, 80, 83, 97, 97, 97}, 25, 230400); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-72, 98, 68, 18, 92, -84, 50, 32, -90, -40, 50, 60, -50, -50, 50, 24, 30, 94, -98, -6, 46, -46, -24, -62, -20, 62, -76}, 14, 740880); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1, 1}, 7, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({85, 36, 7, 69, 9, 45, 18, 47, 1, 78, 72, 53, 37, 20, 95, 71, 58, 41}, 14, 477360); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMaximumProductOfATripletInArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"arr\": [41, 66, 77], \"n\": 2}}, {\"idx\": 1, \"outputs\": 921984, \"inputs\": {\"arr\": [92, -34, -36, -50, 20, -94, 2, -86, 22, -50, 74, 84, 52, -84, 98, -50, 88, 26, -36, -36, 6, -50, -48, -84, 38, -96, -62, 34, 52, 92, 40, -84, 18, -90, 54, -38, -74, -98, -8, -92, -60, 86, -36, 94, 56], \"n\": 40}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 1], \"n\": 1}}, {\"idx\": 3, \"outputs\": 931491, \"inputs\": {\"arr\": [2, 77, 99, 95, 78, 15, 69, 39, 34, 43, 66, 45, 97, 27, 67, 62, 64, 2, 28, 94, 41, 87, 97, 52, 14, 61, 78, 50], \"n\": 26}}, {\"idx\": 4, \"outputs\": 69440, \"inputs\": {\"arr\": [-62, -28, 40, 76], \"n\": 3}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1, 1, 0, 1, 1, 1, 1, 1], \"n\": 5}}, {\"idx\": 6, \"outputs\": 230400, \"inputs\": {\"arr\": [2, 6, 10, 11, 12, 12, 17, 18, 18, 19, 20, 22, 24, 25, 30, 35, 36, 37, 40, 41, 42, 47, 60, 60, 64, 69, 69, 70, 73, 79, 80, 83, 97, 97, 97], \"n\": 25}}, {\"idx\": 7, \"outputs\": 740880, \"inputs\": {\"arr\": [-72, 98, 68, 18, 92, -84, 50, 32, -90, -40, 50, 60, -50, -50, 50, 24, 30, 94, -98, -6, 46, -46, -24, -62, -20, 62, -76], \"n\": 14}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 477360, \"inputs\": {\"arr\": [85, 36, 7, 69, 9, 45, 18, 47, 1, 78, 72, 53, 37, 20, 95, 71, 58, 41], \"n\": 14}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
181
Find Maximum Product Of A Triplet In Array 1
C++
int findMaximumProductOfATripletInArray1(vector<int> arr, int n) {
[ "arr", "n" ]
def find_maximum_product_of_a_triplet_in_array_1(arr, n): if (n < 3): return (- 1) arr.sort() return max(((arr[0] * arr[1]) * arr[(n - 1)]), ((arr[(n - 1)] * arr[(n - 2)]) * arr[(n - 3)]))
int find_maximum_product_of_a_triplet_in_array_1(vector<int> arr, int n) { if ( n < 3 ) return - 1; sort(arr.begin(), arr.end()); return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ], arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver({5, 8, 14, 15, 18, 21, 21, 21, 27, 29, 30, 33, 34, 34, 35, 37, 40, 41, 44, 44, 46, 49, 54, 58, 60, 61, 61, 63, 66, 69, 69, 70, 81, 82, 82, 90, 90, 90, 91, 92, 92, 96, 97, 99}, 39, 737100); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -90, -88, -76, -66, -60, -58, -56, -52, -50, -32, -32, -22, -2, 12, 18, 28, 32, 48, 50, 56, 68, 70, 70, 72}, 18, 268912); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 5, 5, 6, 17, 18, 18, 31, 38, 49, 53, 62, 63, 66, 69, 72, 74, 76, 76, 77, 81, 86, 91, 94, 95, 99, 99}, 21, 474012); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-92, -58, -8, 20, 24, 24, 42, 98}, 4, 106720); \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}, 38, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 64, 81}, 1, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -92, -80, -40, -26, -18, -14, -8, -4, 4, 20, 34, 34, 42, 44, 58, 60, 68, 76, 92, 94, 96}, 17, 529920); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1, 1, 1}, 7, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 4, 6, 17, 17, 18, 23, 28, 41, 46, 52, 58, 61, 70, 73, 75, 79, 79, 83, 94, 97, 98}, 19, 468075); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMaximumProductOfATripletInArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 737100, \"inputs\": {\"arr\": [5, 8, 14, 15, 18, 21, 21, 21, 27, 29, 30, 33, 34, 34, 35, 37, 40, 41, 44, 44, 46, 49, 54, 58, 60, 61, 61, 63, 66, 69, 69, 70, 81, 82, 82, 90, 90, 90, 91, 92, 92, 96, 97, 99], \"n\": 39}}, {\"idx\": 1, \"outputs\": 268912, \"inputs\": {\"arr\": [-98, -98, -90, -88, -76, -66, -60, -58, -56, -52, -50, -32, -32, -22, -2, 12, 18, 28, 32, 48, 50, 56, 68, 70, 70, 72], \"n\": 18}}, {\"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, 1, 1, 1, 1, 1], \"n\": 17}}, {\"idx\": 3, \"outputs\": 474012, \"inputs\": {\"arr\": [2, 5, 5, 6, 17, 18, 18, 31, 38, 49, 53, 62, 63, 66, 69, 72, 74, 76, 76, 77, 81, 86, 91, 94, 95, 99, 99], \"n\": 21}}, {\"idx\": 4, \"outputs\": 106720, \"inputs\": {\"arr\": [-92, -58, -8, 20, 24, 24, 42, 98], \"n\": 4}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 38}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"arr\": [46, 64, 81], \"n\": 1}}, {\"idx\": 7, \"outputs\": 529920, \"inputs\": {\"arr\": [-96, -92, -80, -40, -26, -18, -14, -8, -4, 4, 20, 34, 34, 42, 44, 58, 60, 68, 76, 92, 94, 96], \"n\": 17}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1, 1, 1], \"n\": 7}}, {\"idx\": 9, \"outputs\": 468075, \"inputs\": {\"arr\": [1, 1, 4, 6, 17, 17, 18, 23, 28, 41, 46, 52, 58, 61, 70, 73, 75, 79, 79, 83, 94, 97, 98], \"n\": 19}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
182
Find Maximum Sum Possible Equal Sum Three Stacks
C++
int findMaximumSumPossibleEqualSumThreeStacks(vector<int> stack1, vector<int> stack2, vector<int> stack3, int n1, int n2, int n3) {
[ "stack1", "stack2", "stack3", "n1", "n2", "n3" ]
def find_maximum_sum_possible_equal_sum_three_stacks(stack1, stack2, stack3, n1, n2, n3): (sum1, sum2, sum3) = (0, 0, 0) for i in range(n1): sum1 += stack1[i] for i in range(n2): sum2 += stack2[i] for i in range(n3): sum3 += stack3[i] (top1, top2, top3) = (0, 0, 0) ans = 0 while 1: if ((top1 == n1) or (top2 == n2) or (top3 == n3)): return 0 if ((sum1 == sum2) and (sum2 == sum3)): return sum1 if ((sum1 >= sum2) and (sum1 >= sum3)): sum1 -= stack1[top1] top1 = (top1 + 1) elif ((sum2 >= sum3) and (sum2 >= sum3)): sum2 -= stack2[top2] top2 = (top2 + 1) elif ((sum3 >= sum2) and (sum3 >= sum1)): sum3 -= stack3[top3] top3 = (top3 + 1)
int find_maximum_sum_possible_equal_sum_three_stacks(vector<int> stack1, vector<int> stack2, vector<int> stack3, int n1, int n2, int n3) { int sum1 = 0, sum2 = 0, sum3 = 0; for ( int i = 0; i < n1; i ++ ) sum1 += stack1 [ i ]; for ( int i = 0; i < n2; i ++ ) sum2 += stack2 [ i ]; for ( int i = 0; i < n3; i ++ ) sum3 += stack3 [ i ]; int top1 = 0, top2 = 0, top3 = 0; int ans = 0; while ( 1 ) { if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0; if ( sum1 == sum2 && sum2 == sum3 ) return sum1; if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ]; else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ]; else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ]; } }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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> stack1, vector<int> stack2, vector<int> stack3, int n1, int n2, int n3, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(stack1, stack2, stack3, n1, n2, n3), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 10, 11, 24, 27, 33, 34, 36, 36, 40, 42, 43, 52, 58, 67, 69, 77, 86, 86, 88}, {4, 13, 34, 40, 41, 47, 47, 52, 55, 62, 66, 66, 69, 70, 73, 74, 75, 76, 85, 98}, {6, 8, 10, 12, 14, 29, 41, 52, 53, 54, 55, 66, 69, 73, 77, 77, 78, 80, 90, 99}, 10, 12, 18, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({40, 54, 14, 58, -64, -60, -98, -64, -52, 30, 0, -42, 74, 46, -14, 76, 84, 74, -24, 30, 96, 88, -98, 82, 44, -86, -92, -52, 28, 62}, {24, 34, -52, 50, -8, -48, -28, 68, -12, -26, 0, 6, -76, -94, -12, 8, 38, -88, 30, 98, -78, -54, -48, 42, 26, -76, 4, 46, 26, 60}, {-8, -24, 54, 28, 92, 94, 0, 62, 28, 80, 82, 2, 88, -4, -28, 80, 44, 34, -98, 36, 28, 76, -48, 40, 98, 4, 22, -36, -20, -70}, 26, 28, 15, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0}, {1, 1}, {0, 0}, 1, 1, 1, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({64, 40, 45, 93, 30, 79, 24, 95, 1, 84, 74, 5, 9, 6, 22, 33, 10, 53, 33, 9, 31, 21, 22, 77, 21, 93, 86, 68, 92, 57, 27, 82, 87, 11, 51, 2, 27, 2, 24, 57, 20, 2, 32, 43}, {48, 85, 55, 12, 24, 26, 88, 76, 15, 34, 23, 61, 2, 99, 11, 37, 65, 74, 92, 96, 68, 50, 67, 98, 89, 17, 62, 18, 51, 61, 41, 41, 90, 64, 89, 51, 48, 95, 9, 86, 28, 54, 64, 35}, {99, 77, 11, 20, 33, 91, 5, 68, 75, 67, 37, 70, 59, 26, 2, 62, 6, 97, 95, 38, 46, 89, 29, 61, 27, 93, 26, 74, 98, 85, 91, 92, 40, 97, 58, 44, 20, 57, 65, 62, 65, 26, 74, 58}, 42, 27, 31, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -50, -24, -12, -6, -6, 8, 26, 28, 44}, {-96, -94, -86, -70, -52, -18, -6, 20, 52, 52}, {-70, -40, -22, 4, 12, 12, 38, 54, 72, 74}, 5, 5, 5, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1}, {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1}, {0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0}, 39, 34, 26, 7); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 3, 4, 5, 9, 18, 21, 22, 25, 27, 28, 33, 35, 39, 39, 43, 57, 58, 59, 63, 65, 65, 72, 77, 78, 78, 80, 80, 88, 92, 99}, {3, 17, 18, 23, 24, 24, 26, 28, 34, 48, 53, 54, 56, 61, 64, 67, 69, 74, 77, 79, 79, 81, 81, 82, 84, 84, 85, 86, 88, 92, 96}, {1, 3, 5, 8, 15, 16, 27, 27, 27, 28, 29, 30, 32, 35, 36, 37, 44, 47, 57, 65, 69, 70, 70, 76, 76, 83, 85, 87, 88, 90, 92}, 24, 16, 29, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({40, 28, -84, -38, 82, 2, 38, 10, -10, 20, -54, 48, 56, 38, -98, 68, -8, -30, -96, -16, 28, 94, -52, 28, 34, 68, -46, 44, -28, -52, -48, -14, -30, 24, 56, 8, -30, -46, 18, -68, 86, -12}, {26, 24, -50, 18, 78, -90, 62, 88, -36, -96, 78, 6, -94, -2, -28, -38, 66, 72, -36, 14, -48, -64, -24, 82, 92, -16, -26, -12, 6, 34, 30, -46, 48, -22, 34, -64, 4, -32, 84, -20, 32, -22}, {66, 26, -90, -40, -52, -98, 84, 88, 40, -92, 30, 28, 32, 92, 18, -34, -42, 64, -34, 70, -72, 28, 44, 34, 76, -78, 46, -48, 20, 54, -2, 66, 6, 56, 52, -98, -48, -70, -60, 94, 90, 10}, 32, 37, 41, 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, 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, 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}, 16, 23, 22, 2); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({22, 31, 75, 48, 30, 39, 82, 93, 26, 87, 77, 87, 67, 88, 19, 51, 54, 48, 6, 37, 38, 27}, {18, 20, 53, 87, 85, 63, 6, 81, 89, 82, 43, 76, 59, 60, 79, 96, 29, 65, 5, 56, 96, 95}, {10, 76, 49, 36, 41, 18, 60, 44, 81, 34, 56, 7, 13, 83, 82, 16, 7, 38, 33, 55, 91, 54}, 19, 16, 17, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMaximumSumPossibleEqualSumThreeStacks", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"stack1\": [4, 10, 11, 24, 27, 33, 34, 36, 36, 40, 42, 43, 52, 58, 67, 69, 77, 86, 86, 88], \"stack2\": [4, 13, 34, 40, 41, 47, 47, 52, 55, 62, 66, 66, 69, 70, 73, 74, 75, 76, 85, 98], \"stack3\": [6, 8, 10, 12, 14, 29, 41, 52, 53, 54, 55, 66, 69, 73, 77, 77, 78, 80, 90, 99], \"n1\": 10, \"n2\": 12, \"n3\": 18}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"stack1\": [40, 54, 14, 58, -64, -60, -98, -64, -52, 30, 0, -42, 74, 46, -14, 76, 84, 74, -24, 30, 96, 88, -98, 82, 44, -86, -92, -52, 28, 62], \"stack2\": [24, 34, -52, 50, -8, -48, -28, 68, -12, -26, 0, 6, -76, -94, -12, 8, 38, -88, 30, 98, -78, -54, -48, 42, 26, -76, 4, 46, 26, 60], \"stack3\": [-8, -24, 54, 28, 92, 94, 0, 62, 28, 80, 82, 2, 88, -4, -28, 80, 44, 34, -98, 36, 28, 76, -48, 40, 98, 4, 22, -36, -20, -70], \"n1\": 26, \"n2\": 28, \"n3\": 15}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"stack1\": [0, 0], \"stack2\": [1, 1], \"stack3\": [0, 0], \"n1\": 1, \"n2\": 1, \"n3\": 1}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"stack1\": [64, 40, 45, 93, 30, 79, 24, 95, 1, 84, 74, 5, 9, 6, 22, 33, 10, 53, 33, 9, 31, 21, 22, 77, 21, 93, 86, 68, 92, 57, 27, 82, 87, 11, 51, 2, 27, 2, 24, 57, 20, 2, 32, 43], \"stack2\": [48, 85, 55, 12, 24, 26, 88, 76, 15, 34, 23, 61, 2, 99, 11, 37, 65, 74, 92, 96, 68, 50, 67, 98, 89, 17, 62, 18, 51, 61, 41, 41, 90, 64, 89, 51, 48, 95, 9, 86, 28, 54, 64, 35], \"stack3\": [99, 77, 11, 20, 33, 91, 5, 68, 75, 67, 37, 70, 59, 26, 2, 62, 6, 97, 95, 38, 46, 89, 29, 61, 27, 93, 26, 74, 98, 85, 91, 92, 40, 97, 58, 44, 20, 57, 65, 62, 65, 26, 74, 58], \"n1\": 42, \"n2\": 27, \"n3\": 31}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"stack1\": [-94, -50, -24, -12, -6, -6, 8, 26, 28, 44], \"stack2\": [-96, -94, -86, -70, -52, -18, -6, 20, 52, 52], \"stack3\": [-70, -40, -22, 4, 12, 12, 38, 54, 72, 74], \"n1\": 5, \"n2\": 5, \"n3\": 5}}, {\"idx\": 5, \"outputs\": 7, \"inputs\": {\"stack1\": [1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1], \"stack2\": [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1], \"stack3\": [0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0], \"n1\": 39, \"n2\": 34, \"n3\": 26}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"stack1\": [3, 3, 4, 5, 9, 18, 21, 22, 25, 27, 28, 33, 35, 39, 39, 43, 57, 58, 59, 63, 65, 65, 72, 77, 78, 78, 80, 80, 88, 92, 99], \"stack2\": [3, 17, 18, 23, 24, 24, 26, 28, 34, 48, 53, 54, 56, 61, 64, 67, 69, 74, 77, 79, 79, 81, 81, 82, 84, 84, 85, 86, 88, 92, 96], \"stack3\": [1, 3, 5, 8, 15, 16, 27, 27, 27, 28, 29, 30, 32, 35, 36, 37, 44, 47, 57, 65, 69, 70, 70, 76, 76, 83, 85, 87, 88, 90, 92], \"n1\": 24, \"n2\": 16, \"n3\": 29}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"stack1\": [40, 28, -84, -38, 82, 2, 38, 10, -10, 20, -54, 48, 56, 38, -98, 68, -8, -30, -96, -16, 28, 94, -52, 28, 34, 68, -46, 44, -28, -52, -48, -14, -30, 24, 56, 8, -30, -46, 18, -68, 86, -12], \"stack2\": [26, 24, -50, 18, 78, -90, 62, 88, -36, -96, 78, 6, -94, -2, -28, -38, 66, 72, -36, 14, -48, -64, -24, 82, 92, -16, -26, -12, 6, 34, 30, -46, 48, -22, 34, -64, 4, -32, 84, -20, 32, -22], \"stack3\": [66, 26, -90, -40, -52, -98, 84, 88, 40, -92, 30, 28, 32, 92, 18, -34, -42, 64, -34, 70, -72, 28, 44, 34, 76, -78, 46, -48, 20, 54, -2, 66, 6, 56, 52, -98, -48, -70, -60, 94, 90, 10], \"n1\": 32, \"n2\": 37, \"n3\": 41}}, {\"idx\": 8, \"outputs\": 2, \"inputs\": {\"stack1\": [0, 0, 0, 0, 0, 0, 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], \"stack2\": [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], \"stack3\": [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], \"n1\": 16, \"n2\": 23, \"n3\": 22}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"stack1\": [22, 31, 75, 48, 30, 39, 82, 93, 26, 87, 77, 87, 67, 88, 19, 51, 54, 48, 6, 37, 38, 27], \"stack2\": [18, 20, 53, 87, 85, 63, 6, 81, 89, 82, 43, 76, 59, 60, 79, 96, 29, 65, 5, 56, 96, 95], \"stack3\": [10, 76, 49, 36, 41, 18, 60, 44, 81, 34, 56, 7, 13, 83, 82, 16, 7, 38, 33, 55, 91, 54], \"n1\": 19, \"n2\": 16, \"n3\": 17}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
183
Find Minimum Difference Pair
C++
int findMinimumDifferencePair(vector<int> arr, int n) {
[ "arr", "n" ]
def find_minimum_difference_pair(arr, n): diff = (10 ** 20) for i in range((n - 1)): for j in range((i + 1), n): if (abs((arr[i] - arr[j])) < diff): diff = abs((arr[i] - arr[j])) return diff
int find_minimum_difference_pair(vector<int> arr, int n) { int diff = INT_MAX; for ( int i = 0; i < n - 1; i ++ ) for ( int j = i + 1; j < n; j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ); return diff; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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, 2, 3, 5, 8, 10, 11, 15, 15, 16, 20, 26, 28, 30, 30, 33, 33, 39, 50, 50, 50, 54, 62, 66, 68, 69, 69, 74, 74, 75, 75, 76, 78, 82, 83, 85, 86, 86, 89, 89, 91, 91, 92, 92, 92, 93, 94, 98}, 32, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({6, 6, -20, 88, -78, -18, 74, 72, 80, 76, -62, 38}, 11, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1}, 3, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({75, 85, 49, 66, 44, 89, 80, 39, 64, 70, 25, 21, 81, 33, 90, 68, 51}, 16, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -10, 0, 4, 54, 64}, 3, 10); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0}, 41, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 3, 5, 5, 7, 7, 9, 11, 11, 18, 18, 18, 20, 29, 29, 31, 31, 32, 37, 43, 44, 46, 48, 50, 52, 52, 53, 63, 63, 65, 69, 72, 76, 76, 81, 84, 85, 86, 87, 87, 90, 94, 97, 97}, 27, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({40, -46, 72, -28, 8, 90, 86, -90, 8, -66, -98, 6, 42, 86, 88, 42, -50, 74, -34, -16, -94, -56, -18, -18, 84, -44, 34, 80, 96, 42, -50, -92, 70, 80, 62, -38, -4, 68, 54, -14, 30, -18, -58}, 33, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 26, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({15, 41, 32, 19, 68, 36, 61, 59, 5, 91, 53, 95, 10, 64, 15, 32, 14, 64, 48, 70, 85, 19, 83, 2, 33, 58, 93, 88, 21, 88, 45, 45, 18, 8}, 24, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMinimumDifferencePair", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 2, 3, 5, 8, 10, 11, 15, 15, 16, 20, 26, 28, 30, 30, 33, 33, 39, 50, 50, 50, 54, 62, 66, 68, 69, 69, 74, 74, 75, 75, 76, 78, 82, 83, 85, 86, 86, 89, 89, 91, 91, 92, 92, 92, 93, 94, 98], \"n\": 32}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [6, 6, -20, 88, -78, -18, 74, 72, 80, 76, -62, 38], \"n\": 11}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 1, 1, 1], \"n\": 3}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [75, 85, 49, 66, 44, 89, 80, 39, 64, 70, 25, 21, 81, 33, 90, 68, 51], \"n\": 16}}, {\"idx\": 4, \"outputs\": 10, \"inputs\": {\"arr\": [-96, -10, 0, 4, 54, 64], \"n\": 3}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0], \"n\": 41}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [3, 3, 5, 5, 7, 7, 9, 11, 11, 18, 18, 18, 20, 29, 29, 31, 31, 32, 37, 43, 44, 46, 48, 50, 52, 52, 53, 63, 63, 65, 69, 72, 76, 76, 81, 84, 85, 86, 87, 87, 90, 94, 97, 97], \"n\": 27}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [40, -46, 72, -28, 8, 90, 86, -90, 8, -66, -98, 6, 42, 86, 88, 42, -50, 74, -34, -16, -94, -56, -18, -18, 84, -44, 34, 80, 96, 42, -50, -92, 70, 80, 62, -38, -4, 68, 54, -14, 30, -18, -58], \"n\": 33}}, {\"idx\": 8, \"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, 1, 1, 1, 1, 1, 1], \"n\": 26}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [15, 41, 32, 19, 68, 36, 61, 59, 5, 91, 53, 95, 10, 64, 15, 32, 14, 64, 48, 70, 85, 19, 83, 2, 33, 58, 93, 88, 21, 88, 45, 45, 18, 8], \"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 ] }
184
Find Minimum Difference Pair 1
C++
int findMinimumDifferencePair1(vector<int> arr, int n) {
[ "arr", "n" ]
def find_minimum_difference_pair_1(arr, n): arr = sorted(arr) diff = (10 ** 20) for i in range((n - 1)): if ((arr[(i + 1)] - arr[i]) < diff): diff = (arr[(i + 1)] - arr[i]) return diff
int find_minimum_difference_pair_1(vector<int> arr, int n) { sort(arr.begin(), arr.end()); int diff = INT_MAX; for ( int i = 0; i < n - 1; i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ]; return diff; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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, 25, 44, 46, 54, 60, 81}, 3, 19); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({82, 68, -98, -66, -36, -42, 98, -38, 58, -6, -28, 70, -24, 18, 16, 10, 92, 44, 28, -96, -72, 24, 28, -80, -4, 38, 88, 76}, 22, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1}, 2, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({87, 25, 80, 45, 44, 20, 48, 47, 51, 54, 68, 47, 89, 95, 15, 29, 5, 45, 2, 64, 53, 96, 94, 22, 23, 43, 61, 75, 74, 50}, 15, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-74, -48, -42, -26, -16, -12, 0, 4, 8, 18, 46, 46, 62, 70, 74, 88, 92, 96, 98}, 18, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0}, 36, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({27, 42, 59, 80}, 2, 15); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, 10, -36, 18, -40}, 4, 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}, 12, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMinimumDifferencePair1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 19, \"inputs\": {\"arr\": [3, 25, 44, 46, 54, 60, 81], \"n\": 3}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [82, 68, -98, -66, -36, -42, 98, -38, 58, -6, -28, 70, -24, 18, 16, 10, 92, 44, 28, -96, -72, 24, 28, -80, -4, 38, 88, 76], \"n\": 22}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [1, 1, 1], \"n\": 2}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [87, 25, 80, 45, 44, 20, 48, 47, 51, 54, 68, 47, 89, 95, 15, 29, 5, 45, 2, 64, 53, 96, 94, 22, 23, 43, 61, 75, 74, 50], \"n\": 15}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-74, -48, -42, -26, -16, -12, 0, 4, 8, 18, 46, 46, 62, 70, 74, 88, 92, 96, 98], \"n\": 18}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0], \"n\": 36}}, {\"idx\": 6, \"outputs\": 15, \"inputs\": {\"arr\": [27, 42, 59, 80], \"n\": 2}}, {\"idx\": 7, \"outputs\": 2, \"inputs\": {\"arr\": [-96, -94, 10, -36, 18, -40], \"n\": 4}}, {\"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], \"n\": 12}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
185
Find Minimum Element In A Sorted And Rotated Array
C++
int findMinimumElementInASortedAndRotatedArray(vector<int> arr, int low, int high) {
[ "arr", "low", "high" ]
def find_minimum_element_in_a_sorted_and_rotated_array(arr, low, high): if (high < low): return arr[0] if (high == low): return arr[low] mid = int(((low + high) / 2)) if ((mid < high) and (arr[(mid + 1)] < arr[mid])): return arr[(mid + 1)] if ((mid > low) and (arr[mid] < arr[(mid - 1)])): return arr[mid] if (arr[high] > arr[mid]): return find_minimum_element_in_a_sorted_and_rotated_array(arr, low, (mid - 1)) return find_minimum_element_in_a_sorted_and_rotated_array(arr, (mid + 1), high)
int find_minimum_element_in_a_sorted_and_rotated_array(vector<int> arr, int low, int high) { if ( high < low ) return arr [ 0 ]; if ( high == low ) return arr [ low ]; int mid = low + ( high - low ) / 2; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ]; if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ]; if ( arr [ high ] > arr [ mid ] ) return find_minimum_element_in_a_sorted_and_rotated_array ( arr, low, mid - 1 ); return find_minimum_element_in_a_sorted_and_rotated_array ( arr, mid + 1, high ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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({16, 22, 50, 64, 68, 79, 84, 88, 89}, 4, 6, 68); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({88, -38, 46, 24, -52, -12, -90, 28, 18, 14, -72, 58, -98, 28, -84, 44, -42, -32, -22, -22, -82, -30, 90, 18, 62, 62, 92, 6, 60, 28, -90, 92, 82, 62, 98, -68, 48, -74, -8, 50, 62, 24, 30, -86, 98, -96, -98}, 42, 31, 88); \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}, 28, 21, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({26, 66, 94, 28, 38, 31, 92, 66, 81, 8, 36, 64, 80, 32, 48, 71, 72, 54, 61, 60, 89}, 19, 17, 26); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-46, -26, -22, -14, 46, 62}, 4, 4, 46); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1}, 2, 2, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({14, 81, 87}, 1, 1, 81); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4}, 0, 0, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 17, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 41, 40, 53, 82, 9, 90, 43, 90, 59, 37, 21, 92, 98, 36, 99, 35, 67, 24, 29, 40, 31, 46, 12, 29, 8, 93, 67, 44, 83, 71, 29, 22, 32, 33, 11, 44, 97, 84, 44, 8, 10, 31, 50, 22, 8}, 42, 31, 3); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMinimumElementInASortedAndRotatedArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 68, \"inputs\": {\"arr\": [16, 22, 50, 64, 68, 79, 84, 88, 89], \"low\": 4, \"high\": 6}}, {\"idx\": 1, \"outputs\": 88, \"inputs\": {\"arr\": [88, -38, 46, 24, -52, -12, -90, 28, 18, 14, -72, 58, -98, 28, -84, 44, -42, -32, -22, -22, -82, -30, 90, 18, 62, 62, 92, 6, 60, 28, -90, 92, 82, 62, 98, -68, 48, -74, -8, 50, 62, 24, 30, -86, 98, -96, -98], \"low\": 42, \"high\": 31}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"low\": 28, \"high\": 21}}, {\"idx\": 3, \"outputs\": 26, \"inputs\": {\"arr\": [26, 66, 94, 28, 38, 31, 92, 66, 81, 8, 36, 64, 80, 32, 48, 71, 72, 54, 61, 60, 89], \"low\": 19, \"high\": 17}}, {\"idx\": 4, \"outputs\": 46, \"inputs\": {\"arr\": [-46, -26, -22, -14, 46, 62], \"low\": 4, \"high\": 4}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 1, 1, 1], \"low\": 2, \"high\": 2}}, {\"idx\": 6, \"outputs\": 81, \"inputs\": {\"arr\": [14, 81, 87], \"low\": 1, \"high\": 1}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"arr\": [4], \"low\": 0, \"high\": 0}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"low\": 15, \"high\": 17}}, {\"idx\": 9, \"outputs\": 3, \"inputs\": {\"arr\": [3, 41, 40, 53, 82, 9, 90, 43, 90, 59, 37, 21, 92, 98, 36, 99, 35, 67, 24, 29, 40, 31, 46, 12, 29, 8, 93, 67, 44, 83, 71, 29, 22, 32, 33, 11, 44, 97, 84, 44, 8, 10, 31, 50, 22, 8], \"low\": 42, \"high\": 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 ] }
186
Find Minimum Number Divided Make Number Perfect Square
C++
int findMinimumNumberDividedMakeNumberPerfectSquare(int n) {
[ "n" ]
def find_minimum_number_divided_make_number_perfect_square(n): count = 0 ans = 1 while ((n % 2) == 0): count += 1 n //= 2 if ((count % 2) is not 0): ans *= 2 for i in range(3, (int(math.sqrt(n)) + 1), 2): count = 0 while ((n % i) == 0): count += 1 n //= i if ((count % 2) is not 0): ans *= i if (n > 2): ans *= n return ans
int find_minimum_number_divided_make_number_perfect_square(int n) { int count = 0, ans = 1; while ( n % 2 == 0 ) { count ++; n /= 2; } if ( count % 2 ) ans *= 2; for ( int i = 3; i <= sqrt ( n ); i += 2 ) { count = 0; while ( n % i == 0 ) { count ++; n /= i; } if ( count % 2 ) ans *= i; } if ( n > 2 ) ans *= n; return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(95, 95); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 3); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 3); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, 10); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 82); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 77); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 11); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(23, 23); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 61); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMinimumNumberDividedMakeNumberPerfectSquare", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 95, \"inputs\": {\"n\": 95}}, {\"idx\": 1, \"outputs\": 3, \"inputs\": {\"n\": 48}}, {\"idx\": 2, \"outputs\": 3, \"inputs\": {\"n\": 3}}, {\"idx\": 3, \"outputs\": 10, \"inputs\": {\"n\": 10}}, {\"idx\": 4, \"outputs\": 82, \"inputs\": {\"n\": 82}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"n\": 1}}, {\"idx\": 6, \"outputs\": 77, \"inputs\": {\"n\": 77}}, {\"idx\": 7, \"outputs\": 11, \"inputs\": {\"n\": 99}}, {\"idx\": 8, \"outputs\": 23, \"inputs\": {\"n\": 23}}, {\"idx\": 9, \"outputs\": 61, \"inputs\": {\"n\": 61}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
187
Find Minimum Sum Factors Number
C++
float findMinimumSumFactorsNumber(int num) {
[ "num" ]
def find_minimum_sum_factors_number(num): sum = 0 i = 2 while ((i * i) <= num): while ((num % i) == 0): sum += i num /= i i += 1 sum += num return sum
int find_minimum_sum_factors_number(int num) { int sum = 0; for ( int i = 2; i * i <= num; i ++ ) { while ( num % i == 0 ) { sum += i; num /= i; } } sum += num; 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(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int num, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(83, 83.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 17.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 12.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 5.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 15.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 17.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 21.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 13.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 23.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 16.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findMinimumSumFactorsNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 83, \"inputs\": {\"num\": 83}}, {\"idx\": 1, \"outputs\": 17.0, \"inputs\": {\"num\": 88}}, {\"idx\": 2, \"outputs\": 12.0, \"inputs\": {\"num\": 60}}, {\"idx\": 3, \"outputs\": 5.0, \"inputs\": {\"num\": 6}}, {\"idx\": 4, \"outputs\": 15.0, \"inputs\": {\"num\": 26}}, {\"idx\": 5, \"outputs\": 17.0, \"inputs\": {\"num\": 98}}, {\"idx\": 6, \"outputs\": 21.0, \"inputs\": {\"num\": 38}}, {\"idx\": 7, \"outputs\": 13.0, \"inputs\": {\"num\": 90}}, {\"idx\": 8, \"outputs\": 23.0, \"inputs\": {\"num\": 76}}, {\"idx\": 9, \"outputs\": 16.0, \"inputs\": {\"num\": 66}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
188
Find Number Times String Occurs Given String 1
C++
int findNumberTimesStringOccursGivenString1(string a, string b) {
[ "a", "b" ]
def find_number_times_string_occurs_given_string_1(a, b): m = len(a) n = len(b) lookup = [([0] * (n + 1)) for i in range((m + 1))] for i in range((n + 1)): lookup[0][i] = 0 for i in range((m + 1)): lookup[i][0] = 1 for i in range(1, (m + 1)): for j in range(1, (n + 1)): if (a[(i - 1)] == b[(j - 1)]): lookup[i][j] = (lookup[(i - 1)][(j - 1)] + lookup[(i - 1)][j]) else: lookup[i][j] = lookup[(i - 1)][j] return lookup[m][n]
int find_number_times_string_occurs_given_string_1(string a, string b) { int m = a . length ( ); int n = b . length ( ); int lookup [ m + 1 ] [ n + 1 ] = { { 0 } }; for ( int i = 0; i <= n; ++ i ) lookup [ 0 ] [ i ] = 0; for ( int i = 0; i <= m; ++ i ) lookup [ i ] [ 0 ] = 1; for ( int i = 1; i <= m; i ++ ) { for ( int j = 1; j <= n; j ++ ) { if ( a [ i - 1 ] == b [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]; else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]; } } return lookup [ m ] [ n ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string a, string b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"fZOKCdZ Lav\", \"fKA\", 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2\", \"187012\", 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1000001110\", \"0\", 6); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"IAOyBzgIWHo\", \"oA\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"211806\", \"10\", 2); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"1\", \"001011100\", 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"CVaQTG\", \"CT\", 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"6265187228\", \"628\", 6); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10111101101000\", \"01111\", 35); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"vEi\", \"bigsvkQG\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findNumberTimesStringOccursGivenString1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"a\": \"fZOKCdZ Lav\", \"b\": \"fKA\"}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"a\": \"2\", \"b\": \"187012\"}}, {\"idx\": 2, \"outputs\": 6, \"inputs\": {\"a\": \"1000001110\", \"b\": \"0\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"a\": \"IAOyBzgIWHo\", \"b\": \"oA\"}}, {\"idx\": 4, \"outputs\": 2, \"inputs\": {\"a\": \"211806\", \"b\": \"10\"}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"a\": \"1\", \"b\": \"001011100\"}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"a\": \"CVaQTG\", \"b\": \"CT\"}}, {\"idx\": 7, \"outputs\": 6, \"inputs\": {\"a\": \"6265187228\", \"b\": \"628\"}}, {\"idx\": 8, \"outputs\": 35, \"inputs\": {\"a\": \"10111101101000\", \"b\": \"01111\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"a\": \"vEi\", \"b\": \"bigsvkQG\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
189
Find N Th Element From Sterns Diatomic Series
C++
int findNThElementFromSternsDiatomicSeries(int n) {
[ "n" ]
def find_n_th_element_from_sterns_diatomic_series(n): DP = ([0] * (n + 1)) DP[0] = 0 DP[1] = 1 for i in range(2, (n + 1)): if (int((i % 2)) == 0): DP[i] = DP[int((i / 2))] else: DP[i] = (DP[int(((i - 1) / 2))] + DP[int(((i + 1) / 2))]) return DP[n]
int find_n_th_element_from_sterns_diatomic_series(int n) { int DP [ n + 1 ]; DP [ 0 ] = 0; DP [ 1 ] = 1; for ( int i = 2; i <= n; i ++ ) { if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ]; else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ]; } return DP [ n ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(37, 11); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 2); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 5); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 5); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 11); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(82, 11); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 4); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 7); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findNThElementFromSternsDiatomicSeries", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 11, \"inputs\": {\"n\": 37}}, {\"idx\": 1, \"outputs\": 2, \"inputs\": {\"n\": 24}}, {\"idx\": 2, \"outputs\": 5, \"inputs\": {\"n\": 13}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"n\": 56}}, {\"idx\": 4, \"outputs\": 5, \"inputs\": {\"n\": 26}}, {\"idx\": 5, \"outputs\": 11, \"inputs\": {\"n\": 67}}, {\"idx\": 6, \"outputs\": 11, \"inputs\": {\"n\": 82}}, {\"idx\": 7, \"outputs\": 4, \"inputs\": {\"n\": 60}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"n\": 64}}, {\"idx\": 9, \"outputs\": 7, \"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 ] }
191
Find Pair With Greatest Product In Array
C++
int findPairWithGreatestProductInArray(vector<int> arr, int n) {
[ "arr", "n" ]
def find_pair_with_greatest_product_in_array(arr, n): result = (- 1) for i in range(n): for j in range((n - 1)): for k in range((j + 1), n): if ((arr[j] * arr[k]) == arr[i]): result = max(result, arr[i]) return result
int find_pair_with_greatest_product_in_array(vector<int> arr, int n) { int result = - 1; for ( int i = 0; i < n; i ++ ) for ( int j = 0; j < n - 1; j ++ ) for ( int k = j + 1; k < n; k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = max ( result, 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(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, 78, 84}, 2, -1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-54, 64, 60, 14, 18, -68, -54, -58, 38, -72, -84, 46, 74, 76, 28, -2, 54, 24, 18, -74, -78, 14, -38, -70, 26, -54, -36, -96, -12, 8, 62, -42, -84, 10, -6, 36, -72, 10, 10, -20, 16, 92, -64, -34, 74, -98, 18}, 26, 76); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({39, 49, 94, 80, 48, 34, 63, 82, 47, 51, 60, 68, 79, 23, 97, 22, 54, 53, 40, 2, 25}, 10, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -52, -10, 12, 72}, 3, -1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0}, 2, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 9, 11, 14, 16, 17, 17, 18, 19, 21, 24, 25, 28, 29, 30, 33, 33, 39, 41, 41, 43, 46, 50, 51, 60, 62, 67, 80, 84, 86, 91, 92, 97}, 27, 60); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({4}, 0, -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}, 16, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, 8, 31, 92, 20, 18, 34, 5, 15, 8, 73, 20, 40, 61, 80, 51, 95, 73, 38, 30, 21, 69, 52, 38, 68, 77}, 22, 40); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findPairWithGreatestProductInArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": -1, \"inputs\": {\"arr\": [4, 78, 84], \"n\": 2}}, {\"idx\": 1, \"outputs\": 76, \"inputs\": {\"arr\": [-54, 64, 60, 14, 18, -68, -54, -58, 38, -72, -84, 46, 74, 76, 28, -2, 54, 24, 18, -74, -78, 14, -38, -70, 26, -54, -36, -96, -12, 8, 62, -42, -84, 10, -6, 36, -72, 10, 10, -20, 16, 92, -64, -34, 74, -98, 18], \"n\": 26}}, {\"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, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 22}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [39, 49, 94, 80, 48, 34, 63, 82, 47, 51, 60, 68, 79, 23, 97, 22, 54, 53, 40, 2, 25], \"n\": 10}}, {\"idx\": 4, \"outputs\": -1, \"inputs\": {\"arr\": [-90, -52, -10, 12, 72], \"n\": 3}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 0, 0], \"n\": 2}}, {\"idx\": 6, \"outputs\": 60, \"inputs\": {\"arr\": [2, 9, 11, 14, 16, 17, 17, 18, 19, 21, 24, 25, 28, 29, 30, 33, 33, 39, 41, 41, 43, 46, 50, 51, 60, 62, 67, 80, 84, 86, 91, 92, 97], \"n\": 27}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [4], \"n\": 0}}, {\"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], \"n\": 16}}, {\"idx\": 9, \"outputs\": 40, \"inputs\": {\"arr\": [52, 8, 31, 92, 20, 18, 34, 5, 15, 8, 73, 20, 40, 61, 80, 51, 95, 73, 38, 30, 21, 69, 52, 38, 68, 77], \"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 ] }
192
Find Perimeter Cylinder
C++
int findPerimeterCylinder(int diameter, int height) {
[ "diameter", "height" ]
def find_perimeter_cylinder(diameter, height): return (2 * (diameter + height))
int find_perimeter_cylinder(int diameter, int height) { return 2 * ( diameter + 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 diameter, int height, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(diameter, height), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(70, 78, 296); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 46, 286); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 26, 150); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(56, 61, 234); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(87, 79, 332); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 21, 170); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 93, 336); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 16, 212); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 16, 142); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 29, 204); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findPerimeterCylinder", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 296, \"inputs\": {\"diameter\": 70, \"height\": 78}}, {\"idx\": 1, \"outputs\": 286, \"inputs\": {\"diameter\": 97, \"height\": 46}}, {\"idx\": 2, \"outputs\": 150, \"inputs\": {\"diameter\": 49, \"height\": 26}}, {\"idx\": 3, \"outputs\": 234, \"inputs\": {\"diameter\": 56, \"height\": 61}}, {\"idx\": 4, \"outputs\": 332, \"inputs\": {\"diameter\": 87, \"height\": 79}}, {\"idx\": 5, \"outputs\": 170, \"inputs\": {\"diameter\": 64, \"height\": 21}}, {\"idx\": 6, \"outputs\": 336, \"inputs\": {\"diameter\": 75, \"height\": 93}}, {\"idx\": 7, \"outputs\": 212, \"inputs\": {\"diameter\": 90, \"height\": 16}}, {\"idx\": 8, \"outputs\": 142, \"inputs\": {\"diameter\": 55, \"height\": 16}}, {\"idx\": 9, \"outputs\": 204, \"inputs\": {\"diameter\": 73, \"height\": 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 ] }
193
Find Position Given Number Among Numbers Made 4 7
C++
int findPositionGivenNumberAmongNumbersMade47(string n) {
[ "n" ]
def find_position_given_number_among_numbers_made_4_7(n): i = 0 j = len(n) pos = 0 while (i < j): if (n[i] == '4'): pos = ((pos * 2) + 1) if (n[i] == '7'): pos = ((pos * 2) + 2) i = (i + 1) return pos
int find_position_given_number_among_numbers_made_4_7(string n) { int i = 0, pos = 0; while ( n [ i ] != '\0' ) { switch ( n [ i ] ) { case '4' : pos = pos * 2 + 1; break; case '7' : pos = pos * 2 + 2; break; } i ++; } return 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(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"7\", 2); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"305745689\", 5); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"444\", 7); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"4\", 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2074\", 5); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"27\", 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"447\", 8); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"255\", 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10000111111011\", 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"fAKcSDRTNz\", 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findPositionGivenNumberAmongNumbersMade47", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2, \"inputs\": {\"n\": \"7\"}}, {\"idx\": 1, \"outputs\": 5, \"inputs\": {\"n\": \"305745689\"}}, {\"idx\": 2, \"outputs\": 7, \"inputs\": {\"n\": \"444\"}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"n\": \"4\"}}, {\"idx\": 4, \"outputs\": 5, \"inputs\": {\"n\": \"2074\"}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"n\": \"27\"}}, {\"idx\": 6, \"outputs\": 8, \"inputs\": {\"n\": \"447\"}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": \"255\"}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": \"10000111111011\"}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"n\": \"fAKcSDRTNz\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
194
Find Repetitive Element 1 N 1
C++
int findRepetitiveElement1N1(vector<int> arr, int n) {
[ "arr", "n" ]
def find_repetitive_element_1_n_1(arr, n): return (sum(arr) - (((n - 1) * n) // 2))
int find_repetitive_element_1_n_1(vector<int> arr, int n) { return accumulate(arr.begin(), arr.end(), 0 ) - ( ( n - 1 ) * 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> 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, 8, 27, 34, 39, 42, 43, 54, 72}, 5, 313); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-38, -66, -38, -48, -96, 74, -32, -62, -34, -32, -88, -12, -8, -4}, 9, -520); \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}, 8, -23); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({88, 86, 23, 81, 76, 16, 94, 64, 59, 50, 71, 62, 10, 89, 73, 64, 65, 96, 83, 40, 99, 40, 77, 33, 14, 62, 6, 89, 74, 96, 93, 29, 15, 93, 9, 58, 98, 76, 23, 23, 70, 99}, 31, 2101); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -94, -82, -64, -56, -40, -36, -34, -32, -24, -24, -22, -20, -20, -20, -18, -18, -12, -10, -6, 16, 20, 20, 22, 26, 30, 36, 46, 46, 50, 50, 52, 64, 64, 64, 68, 72, 74, 76, 92, 96, 98}, 28, 76); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1}, 25, -288); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 6, 7, 13, 19, 23, 37, 39, 42, 42, 43, 45, 52, 53, 55, 56, 59, 63, 66, 71, 76, 85, 86, 89, 92, 94, 96, 99}, 27, 1159); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({52, -56, -12, 78, 6, 32, 0, 36, 34, -54, -74, -32}, 11, -45); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, -86); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({10, 42, 50, 5, 74, 81, 30, 76, 6, 34, 86, 4, 77, 71, 96, 22, 34, 50, 35, 16, 60, 11, 21, 38}, 13, 951); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findRepetitiveElement1N1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 313, \"inputs\": {\"arr\": [4, 8, 27, 34, 39, 42, 43, 54, 72], \"n\": 5}}, {\"idx\": 1, \"outputs\": -520, \"inputs\": {\"arr\": [-38, -66, -38, -48, -96, 74, -32, -62, -34, -32, -88, -12, -8, -4], \"n\": 9}}, {\"idx\": 2, \"outputs\": -23, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"n\": 8}}, {\"idx\": 3, \"outputs\": 2101, \"inputs\": {\"arr\": [88, 86, 23, 81, 76, 16, 94, 64, 59, 50, 71, 62, 10, 89, 73, 64, 65, 96, 83, 40, 99, 40, 77, 33, 14, 62, 6, 89, 74, 96, 93, 29, 15, 93, 9, 58, 98, 76, 23, 23, 70, 99], \"n\": 31}}, {\"idx\": 4, \"outputs\": 76, \"inputs\": {\"arr\": [-96, -94, -82, -64, -56, -40, -36, -34, -32, -24, -24, -22, -20, -20, -20, -18, -18, -12, -10, -6, 16, 20, 20, 22, 26, 30, 36, 46, 46, 50, 50, 52, 64, 64, 64, 68, 72, 74, 76, 92, 96, 98], \"n\": 28}}, {\"idx\": 5, \"outputs\": -288, \"inputs\": {\"arr\": [0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1], \"n\": 25}}, {\"idx\": 6, \"outputs\": 1159, \"inputs\": {\"arr\": [2, 6, 7, 13, 19, 23, 37, 39, 42, 42, 43, 45, 52, 53, 55, 56, 59, 63, 66, 71, 76, 85, 86, 89, 92, 94, 96, 99], \"n\": 27}}, {\"idx\": 7, \"outputs\": -45, \"inputs\": {\"arr\": [52, -56, -12, 78, 6, 32, 0, 36, 34, -54, -74, -32], \"n\": 11}}, {\"idx\": 8, \"outputs\": -86, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 15}}, {\"idx\": 9, \"outputs\": 951, \"inputs\": {\"arr\": [10, 42, 50, 5, 74, 81, 30, 76, 6, 34, 86, 4, 77, 71, 96, 22, 34, 50, 35, 16, 60, 11, 21, 38], \"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 ] }
195
Find Repetitive Element 1 N 1 2
C++
int findRepetitiveElement1N12(vector<int> arr, int n) {
[ "arr", "n" ]
def find_repetitive_element_1_n_1_2(arr, n): res = 0 for i in range(0, (n - 1)): res = ((res ^ (i + 1)) ^ arr[i]) res = (res ^ arr[(n - 1)]) return res
int find_repetitive_element_1_n_1_2(vector<int> arr, int n) { int res = 0; for ( int i = 0; i < n - 1; i ++ ) res = res ^ ( i + 1 ) ^ arr [ i ]; res = 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({2, 2, 4, 5, 5, 7, 7, 7, 8, 11, 14, 15, 18, 19, 20, 25, 25, 29, 29, 31, 32, 32, 33, 38, 42, 48, 52, 55, 60, 61, 63, 71, 74, 78, 82, 82, 84, 84, 87, 87, 88, 90, 93, 94, 94}, 31, 52); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({46, 2, 62, 60, 92, 4, 26, 66, 66, 90, 26, -14, 76, -20, -68}, 8, 46); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 1, 1, 1}, 4, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({87, 67, 11, 47, 64, 81, 94, 75, 58, 77, 18, 2, 85, 26, 6, 44, 55, 19, 46, 49, 5, 69, 44, 12, 42, 66, 46, 9, 26, 49, 68, 95, 6, 9, 11, 72, 5, 67}, 34, 28); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -94, -92, -82, -78, -64, -62, -58, -52, -44, -40, -38, -8, 6, 10, 20, 22, 28, 30, 30, 36, 54, 54, 58, 64, 68, 76, 78, 84, 88, 90, 94, 96}, 29, -32); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1}, 17, 16); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 14, 15, 15, 21, 34, 38, 39, 41, 50, 60, 74, 96, 97}, 7, 25); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({96, -12, -16, -52}, 3, 103); \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}, 21, 21); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({66, 21, 21, 59, 78, 8, 46, 41, 16, 32, 97, 93, 32, 86, 91, 61, 67, 61, 97, 49, 66, 35, 24, 35, 65, 45, 83}, 25, 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findRepetitiveElement1N12", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 52, \"inputs\": {\"arr\": [2, 2, 4, 5, 5, 7, 7, 7, 8, 11, 14, 15, 18, 19, 20, 25, 25, 29, 29, 31, 32, 32, 33, 38, 42, 48, 52, 55, 60, 61, 63, 71, 74, 78, 82, 82, 84, 84, 87, 87, 88, 90, 93, 94, 94], \"n\": 31}}, {\"idx\": 1, \"outputs\": 46, \"inputs\": {\"arr\": [46, 2, 62, 60, 92, 4, 26, 66, 66, 90, 26, -14, 76, -20, -68], \"n\": 8}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 1, 1, 1], \"n\": 4}}, {\"idx\": 3, \"outputs\": 28, \"inputs\": {\"arr\": [87, 67, 11, 47, 64, 81, 94, 75, 58, 77, 18, 2, 85, 26, 6, 44, 55, 19, 46, 49, 5, 69, 44, 12, 42, 66, 46, 9, 26, 49, 68, 95, 6, 9, 11, 72, 5, 67], \"n\": 34}}, {\"idx\": 4, \"outputs\": -32, \"inputs\": {\"arr\": [-98, -94, -92, -82, -78, -64, -62, -58, -52, -44, -40, -38, -8, 6, 10, 20, 22, 28, 30, 30, 36, 54, 54, 58, 64, 68, 76, 78, 84, 88, 90, 94, 96], \"n\": 29}}, {\"idx\": 5, \"outputs\": 16, \"inputs\": {\"arr\": [1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1], \"n\": 17}}, {\"idx\": 6, \"outputs\": 25, \"inputs\": {\"arr\": [1, 14, 15, 15, 21, 34, 38, 39, 41, 50, 60, 74, 96, 97], \"n\": 7}}, {\"idx\": 7, \"outputs\": 103, \"inputs\": {\"arr\": [96, -12, -16, -52], \"n\": 3}}, {\"idx\": 8, \"outputs\": 21, \"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], \"n\": 21}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"arr\": [66, 21, 21, 59, 78, 8, 46, 41, 16, 32, 97, 93, 32, 86, 91, 61, 67, 61, 97, 49, 66, 35, 24, 35, 65, 45, 83], \"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 ] }
196
Find Rotation Count Rotated Sorted Array 1
C++
int findRotationCountRotatedSortedArray1(vector<int> arr, int low, int high) {
[ "arr", "low", "high" ]
def find_rotation_count_rotated_sorted_array_1(arr, low, high): if (high < low): return 0 if (high == low): return low mid = (low + ((high - low) / 2)) mid = int(mid) if ((mid < high) and (arr[(mid + 1)] < arr[mid])): return (mid + 1) if ((mid > low) and (arr[mid] < arr[(mid - 1)])): return mid if (arr[high] > arr[mid]): return find_rotation_count_rotated_sorted_array_1(arr, low, (mid - 1)) return find_rotation_count_rotated_sorted_array_1(arr, (mid + 1), high)
int find_rotation_count_rotated_sorted_array_1(vector<int> arr, int low, int high) { if ( high < low ) return 0; if ( high == low ) return low; int mid = low + ( high - low ) / 2; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ); if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid; if ( arr [ high ] > arr [ mid ] ) return find_rotation_count_rotated_sorted_array_1 ( arr, low, mid - 1 ); return find_rotation_count_rotated_sorted_array_1 ( arr, mid + 1, high ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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({4, 16, 38, 39, 48, 74, 79}, 6, 6, 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-46, 72, 72, -66, 96, 92, 40, 8, 94, -84, 6, -90, 38, -6, 48, -20, -86, -76, 88, -50, -44, -14, 54, -6, -2, 72, 8, -64, -46, 44, -88, 50, 86, 38, 42, -56}, 32, 21, 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, 1, 1, 1}, 16, 29, 29); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({48, 74, 59, 57, 95, 11, 25, 61, 46, 54, 34, 84, 7, 97, 62, 57, 99, 93, 76, 5, 76, 93, 35, 84, 37, 60, 65, 16, 30, 73, 42, 61, 74, 77, 48, 62, 84, 93, 64, 57, 68, 46, 28, 77}, 24, 26, 24); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-72, -68, -66, -66, -62, -62, -52, -48, -42, -42, -42, -38, -30, -22, -20, -20, -16, -16, -14, 0, 2, 2, 2, 4, 12, 20, 22, 26, 32, 34, 46, 46, 64, 64, 64, 66, 68, 68, 68, 74, 80, 84, 84, 88, 88, 90, 96, 98}, 29, 43, 31); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1}, 0, 0, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 11, 20, 21, 22, 27, 30, 30, 34, 35, 36, 37, 38, 60, 61, 63, 63, 69, 70, 75, 80, 84, 88, 97}, 23, 22, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-2, 70, -40}, 2, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 30, 17, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({71, 71, 27, 10, 97, 43, 55, 71, 6, 6, 77, 48, 77, 2, 83, 51, 61, 19, 2, 51, 26, 70, 20, 23, 54, 15, 6, 92, 35, 75, 8, 57, 50, 49, 88, 21, 36}, 24, 22, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findRotationCountRotatedSortedArray1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"arr\": [4, 16, 38, 39, 48, 74, 79], \"low\": 6, \"high\": 6}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-46, 72, 72, -66, 96, 92, 40, 8, 94, -84, 6, -90, 38, -6, 48, -20, -86, -76, 88, -50, -44, -14, 54, -6, -2, 72, 8, -64, -46, 44, -88, 50, 86, 38, 42, -56], \"low\": 32, \"high\": 21}}, {\"idx\": 2, \"outputs\": 29, \"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], \"low\": 16, \"high\": 29}}, {\"idx\": 3, \"outputs\": 24, \"inputs\": {\"arr\": [48, 74, 59, 57, 95, 11, 25, 61, 46, 54, 34, 84, 7, 97, 62, 57, 99, 93, 76, 5, 76, 93, 35, 84, 37, 60, 65, 16, 30, 73, 42, 61, 74, 77, 48, 62, 84, 93, 64, 57, 68, 46, 28, 77], \"low\": 24, \"high\": 26}}, {\"idx\": 4, \"outputs\": 31, \"inputs\": {\"arr\": [-72, -68, -66, -66, -62, -62, -52, -48, -42, -42, -42, -38, -30, -22, -20, -20, -16, -16, -14, 0, 2, 2, 2, 4, 12, 20, 22, 26, 32, 34, 46, 46, 64, 64, 64, 66, 68, 68, 68, 74, 80, 84, 84, 88, 88, 90, 96, 98], \"low\": 29, \"high\": 43}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1], \"low\": 0, \"high\": 0}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"arr\": [7, 11, 20, 21, 22, 27, 30, 30, 34, 35, 36, 37, 38, 60, 61, 63, 63, 69, 70, 75, 80, 84, 88, 97], \"low\": 23, \"high\": 22}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-2, 70, -40], \"low\": 2, \"high\": 1}}, {\"idx\": 8, \"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, 1, 1, 1, 1, 1, 1], \"low\": 30, \"high\": 17}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [71, 71, 27, 10, 97, 43, 55, 71, 6, 6, 77, 48, 77, 2, 83, 51, 61, 19, 2, 51, 26, 70, 20, 23, 54, 15, 6, 92, 35, 75, 8, 57, 50, 49, 88, 21, 36], \"low\": 24, \"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 ] }
197
Find Smallest Value Represented Sum Subset Given Array
C++
int findSmallestValueRepresentedSumSubsetGivenArray(vector<int> arr, int n) {
[ "arr", "n" ]
def find_smallest_value_represented_sum_subset_given_array(arr, n): res = 1 for i in range(0, n): if (arr[i] <= res): res = (res + arr[i]) else: break return res
int find_smallest_value_represented_sum_subset_given_array(vector<int> arr, int n) { int res = 1; for ( int i = 0; i < n && arr [ i ] <= res; i ++ ) res = 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(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({16, 23, 24, 41, 48, 58, 72, 75}, 4, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-14, -82, 12, -14, -38, 12, 40, 12, -74, 42, -36, 64}, 8, -95); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1, 1, 1}, 5, 4); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({17, 89, 44}, 2, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -92, -84, -82, -72, -58, -56, -40, -34, -34, -24, -22, -8, -8, 12, 14, 16, 16, 22, 22, 34, 46, 54, 58, 68, 72, 74, 78, 88, 96}, 25, -93); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0}, 8, 2); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 12, 13, 13, 13, 16, 28, 32, 34, 41, 41, 47, 49, 49, 50, 52, 58, 61, 63, 65, 67, 68, 68, 74, 80, 80, 84, 84, 89, 93, 94, 98, 99, 99}, 23, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-54}, 0, 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, 1, 1, 1, 1, 1}, 33, 12); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({42, 50, 76, 45, 6, 63, 46, 73, 65, 70, 87, 5, 41, 63, 96, 75, 38, 76, 27, 7, 71, 9, 65, 44, 76, 37, 94, 52, 55, 3, 38, 68, 45, 15, 35, 90, 36, 46, 13, 92, 32, 22, 49, 35, 83}, 35, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSmallestValueRepresentedSumSubsetGivenArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [16, 23, 24, 41, 48, 58, 72, 75], \"n\": 4}}, {\"idx\": 1, \"outputs\": -95, \"inputs\": {\"arr\": [-14, -82, 12, -14, -38, 12, 40, 12, -74, 42, -36, 64], \"n\": 8}}, {\"idx\": 2, \"outputs\": 4, \"inputs\": {\"arr\": [0, 0, 1, 1, 1, 1], \"n\": 5}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [17, 89, 44], \"n\": 2}}, {\"idx\": 4, \"outputs\": -93, \"inputs\": {\"arr\": [-94, -92, -84, -82, -72, -58, -56, -40, -34, -34, -24, -22, -8, -8, 12, 14, 16, 16, 22, 22, 34, 46, 54, 58, 68, 72, 74, 78, 88, 96], \"n\": 25}}, {\"idx\": 5, \"outputs\": 2, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0], \"n\": 8}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [2, 12, 13, 13, 13, 16, 28, 32, 34, 41, 41, 47, 49, 49, 50, 52, 58, 61, 63, 65, 67, 68, 68, 74, 80, 80, 84, 84, 89, 93, 94, 98, 99, 99], \"n\": 23}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [-54], \"n\": 0}}, {\"idx\": 8, \"outputs\": 12, \"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], \"n\": 33}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [42, 50, 76, 45, 6, 63, 46, 73, 65, 70, 87, 5, 41, 63, 96, 75, 38, 76, 27, 7, 71, 9, 65, 44, 76, 37, 94, 52, 55, 3, 38, 68, 45, 15, 35, 90, 36, 46, 13, 92, 32, 22, 49, 35, 83], \"n\": 35}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
198
Find Subarray With Given Sum
C++
int findSubarrayWithGivenSum(vector<int> arr, int n, int sum) {
[ "arr", "n", "sum" ]
def find_subarray_with_given_sum(arr, n, sum): for i in range(n): curr_sum = arr[i] j = (i + 1) while (j <= n): if (curr_sum == sum): print('Sum found between') print(('indexes %d and %d' % (i, (j - 1)))) return 1 if ((curr_sum > sum) or (j == n)): break curr_sum = (curr_sum + arr[j]) j += 1 print('No subarray found') return 0
int find_subarray_with_given_sum(vector<int> arr, int n, int sum) { int curr_sum, i, j; for ( i = 0; i < n; i ++ ) { curr_sum = arr [ i ]; for ( j = i + 1; j <= n; j ++ ) { if ( curr_sum == sum ) { return 1; } if ( curr_sum > sum || j == n ) break; curr_sum = curr_sum + arr [ j ]; } } return 0; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int sum, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, 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, 8, 8, 10, 15, 18, 19, 22, 25, 26, 30, 32, 35, 36, 40, 41, 43, 48, 53, 57, 59, 63, 64, 68, 71, 76, 76, 77, 78, 89, 96, 97}, 26, 23, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-78, 16, -16, -10, -2, -38, 58, -72, -78, 50, -68, -16, -96, 82, 70, 2, -20}, 9, 12, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 9, 11, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({16, 10, 55, 43, 46, 74, 57, 65, 86, 60, 28, 6, 92}, 10, 6, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -98, -90, -84, -84, -80, -76, -76, -70, -54, -48, -46, -44, -42, -38, -14, -12, -4, 6, 8, 24, 28, 32, 40, 40, 42, 64, 84, 98}, 23, 19, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, 12, 8, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({2, 10, 40, 45, 56, 66, 66, 70, 75, 83, 93, 98}, 10, 10, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-20, 30, 56, -68, 54, -6, 78, -86, 88, -66, 76, -66, 62, 78, 22, 46, -94, -10, 18, 16, -36, 34, -98, -84, -40, 98, 82, 10, 12, 54, -88}, 30, 17, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1}, 2, 2, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({38, 24, 12}, 1, 1, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSubarrayWithGivenSum", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"arr\": [4, 8, 8, 10, 15, 18, 19, 22, 25, 26, 30, 32, 35, 36, 40, 41, 43, 48, 53, 57, 59, 63, 64, 68, 71, 76, 76, 77, 78, 89, 96, 97], \"n\": 26, \"sum\": 23}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-78, 16, -16, -10, -2, -38, 58, -72, -78, 50, -68, -16, -96, 82, 70, 2, -20], \"n\": 9, \"sum\": 12}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 9, \"sum\": 11}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"arr\": [16, 10, 55, 43, 46, 74, 57, 65, 86, 60, 28, 6, 92], \"n\": 10, \"sum\": 6}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-98, -98, -90, -84, -84, -80, -76, -76, -70, -54, -48, -46, -44, -42, -38, -14, -12, -4, 6, 8, 24, 28, 32, 40, 40, 42, 64, 84, 98], \"n\": 23, \"sum\": 19}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], \"n\": 12, \"sum\": 8}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [2, 10, 40, 45, 56, 66, 66, 70, 75, 83, 93, 98], \"n\": 10, \"sum\": 10}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"arr\": [-20, 30, 56, -68, 54, -6, 78, -86, 88, -66, 76, -66, 62, 78, 22, 46, -94, -10, 18, 16, -36, 34, -98, -84, -40, 98, 82, 10, 12, 54, -88], \"n\": 30, \"sum\": 17}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 1, 1], \"n\": 2, \"sum\": 2}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"arr\": [38, 24, 12], \"n\": 1, \"sum\": 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 ] }
199
Find Subarray With Given Sum 1
C++
int findSubarrayWithGivenSum1(vector<int> arr, int n, int sum) {
[ "arr", "n", "sum" ]
def find_subarray_with_given_sum_1(arr, n, sum): curr_sum = arr[0] start = 0 i = 1 while (i <= n): while ((curr_sum > sum) and (start < (i - 1))): curr_sum = (curr_sum - arr[start]) start += 1 if (curr_sum == sum): print('Sum found between indexes') print(('%d and %d' % (start, (i - 1)))) return 1 if (i < n): curr_sum = (curr_sum + arr[i]) i += 1 print('No subarray found') return 0
int find_subarray_with_given_sum_1(vector<int> arr, int n, int sum) { int curr_sum = arr [ 0 ], start = 0, i; for ( i = 1; i <= n; i ++ ) { while ( curr_sum > sum && start < i - 1 ) { curr_sum = curr_sum - arr [ start ]; start ++; } if ( curr_sum == sum ) { return 1; } if ( i < n ) curr_sum = curr_sum + arr [ i ]; } return 0; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int sum, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, 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({7, 7, 8, 8, 23, 24, 28, 32, 48, 53, 56, 62, 69, 77, 81, 82, 84, 87, 88, 90}, 16, 31, 1); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-62, -62, -80, -30, -80, 44, -12, -76, 16, -52, -86, 72, 32, -60, -70, -62, -78, -96, -18, 40, -4, -18, -58, 30, -70, 6, 0, -62, -66, 20, 92, -64, 20, -48, 48, -32, 64, 22, 16, 26}, 39, 44, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 40, 7, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({50, 25, 6, 87, 55, 86, 61, 97, 24, 30, 51, 43, 26, 1, 80, 47, 19, 36, 64, 62, 92, 5, 48, 27, 82, 76, 70, 59, 1, 43, 1, 36, 28, 9, 52, 22, 43}, 29, 105, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -76, -64, -22, -16, -8, 4, 6, 8, 32, 38, 60, 68, 74}, 7, 2, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0}, 31, 10, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 7, 12, 25, 25, 32, 33, 34, 37, 39, 39, 41, 46, 48, 56, 56, 57, 58, 61, 62, 62, 63, 65, 66, 69, 72, 74, 78, 78, 79, 80, 85, 89, 94, 95, 99}, 22, 39, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({98, -60}, 1, 98, 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 1, 1, 1, 1, 1, 1}, 8, 0, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, 89, 83, 42, 75, 30, 64, 25, 95, 17, 90, 6, 11, 1, 77, 16, 75, 86, 96, 67, 27, 80, 27}, 16, 108, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSubarrayWithGivenSum1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 1, \"inputs\": {\"arr\": [7, 7, 8, 8, 23, 24, 28, 32, 48, 53, 56, 62, 69, 77, 81, 82, 84, 87, 88, 90], \"n\": 16, \"sum\": 31}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"arr\": [-62, -62, -80, -30, -80, 44, -12, -76, 16, -52, -86, 72, 32, -60, -70, -62, -78, -96, -18, 40, -4, -18, -58, 30, -70, 6, 0, -62, -66, 20, 92, -64, 20, -48, 48, -32, 64, 22, 16, 26], \"n\": 39, \"sum\": 44}}, {\"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, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 40, \"sum\": 7}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"arr\": [50, 25, 6, 87, 55, 86, 61, 97, 24, 30, 51, 43, 26, 1, 80, 47, 19, 36, 64, 62, 92, 5, 48, 27, 82, 76, 70, 59, 1, 43, 1, 36, 28, 9, 52, 22, 43], \"n\": 29, \"sum\": 105}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"arr\": [-86, -76, -64, -22, -16, -8, 4, 6, 8, 32, 38, 60, 68, 74], \"n\": 7, \"sum\": 2}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0], \"n\": 31, \"sum\": 10}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"arr\": [7, 7, 12, 25, 25, 32, 33, 34, 37, 39, 39, 41, 46, 48, 56, 56, 57, 58, 61, 62, 62, 63, 65, 66, 69, 72, 74, 78, 78, 79, 80, 85, 89, 94, 95, 99], \"n\": 22, \"sum\": 39}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"arr\": [98, -60], \"n\": 1, \"sum\": 98}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1], \"n\": 8, \"sum\": 0}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [80, 89, 83, 42, 75, 30, 64, 25, 95, 17, 90, 6, 11, 1, 77, 16, 75, 86, 96, 67, 27, 80, 27], \"n\": 16, \"sum\": 108}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
200
Find Sum Even Factors Number
C++
int findSumEvenFactorsNumber(int n) {
[ "n" ]
def find_sum_even_factors_number(n): if ((n % 2) != 0): return 0 res = 1 for i in range(2, (int(math.sqrt(n)) + 1)): count = 0 curr_sum = 1 curr_term = 1 while ((n % i) == 0): count = (count + 1) n = (n // i) if ((i == 2) and (count == 1)): curr_sum = 0 curr_term = (curr_term * i) curr_sum = (curr_sum + curr_term) res = (res * curr_sum) if (n >= 2): res = (res * (1 + n)) return res
int find_sum_even_factors_number(int n) { if ( n % 2 != 0 ) return 0; int res = 1; for ( int i = 2; i <= sqrt ( n ); i ++ ) { int count = 0, curr_sum = 1, curr_term = 1; while ( n % i == 0 ) { count ++; n = n / i; if ( i == 2 && count == 1 ) curr_sum = 0; curr_term *= i; curr_sum += curr_term; } res *= curr_sum; } if ( n >= 2 ) res *= ( 1 + n ); return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(71, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(78, 112); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 78); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(49, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(53, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 96); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 144); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumEvenFactorsNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": 71}}, {\"idx\": 1, \"outputs\": 112, \"inputs\": {\"n\": 78}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 39}}, {\"idx\": 3, \"outputs\": 78, \"inputs\": {\"n\": 36}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 49}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 17}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 53}}, {\"idx\": 7, \"outputs\": 96, \"inputs\": {\"n\": 66}}, {\"idx\": 8, \"outputs\": 144, \"inputs\": {\"n\": 92}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"n\": 71}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
201
Find Sum Even Index Binomial Coefficients
C++
long long findSumEvenIndexBinomialCoefficients(int n) {
[ "n" ]
def find_sum_even_index_binomial_coefficients(n): C = [[0 for x in range((n + 1))] for y in range((n + 1))] for i in range(0, (n + 1)): for j in range(0, min(i, (n + 1))): if ((j == 0) or (j == i)): C[i][j] = 1 else: C[i][j] = (C[(i - 1)][(j - 1)] + C[(i - 1)][j]) sum = 0 for i in range(0, (n + 1)): if ((n % 2) == 0): sum = (sum + C[n][i]) return sum
int find_sum_even_index_binomial_coefficients(int n) { int C [ n + 1 ] [ n + 1 ]; int i, j; for ( i = 0; i <= n; i ++ ) { for ( j = 0; j <= min ( i, n ); j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]; } } int sum = 0; for ( int i = 0; i <= n; i += 2 ) sum += C [ n ] [ i ]; return sum; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(18, 131072); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 9007199254740992); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(26, 33554432); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumEvenIndexBinomialCoefficients", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 131072, \"inputs\": {\"n\": 18}}, {\"idx\": 1, \"outputs\": 9007199254740992, \"inputs\": {\"n\": 54}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 67}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 17}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 47}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 99}}, {\"idx\": 6, \"outputs\": 33554432, \"inputs\": {\"n\": 26}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": 93}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": 57}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
202
Find Sum Even Index Binomial Coefficients 1
C++
long long findSumEvenIndexBinomialCoefficients1(int n) {
[ "n" ]
def find_sum_even_index_binomial_coefficients_1(n): return (1 << (n - 1))
int find_sum_even_index_binomial_coefficients_1(int n) { return ( 1 << ( 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(56, 36028797018963968); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, 134217728); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 8); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 8388608); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 536870912); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, 140737488355328); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 2147483648); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 4096); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 262144); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumEvenIndexBinomialCoefficients1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 36028797018963968, \"inputs\": {\"n\": 56}}, {\"idx\": 1, \"outputs\": 134217728, \"inputs\": {\"n\": 28}}, {\"idx\": 2, \"outputs\": 8, \"inputs\": {\"n\": 4}}, {\"idx\": 3, \"outputs\": 8388608, \"inputs\": {\"n\": 24}}, {\"idx\": 4, \"outputs\": 536870912, \"inputs\": {\"n\": 30}}, {\"idx\": 5, \"outputs\": 140737488355328, \"inputs\": {\"n\": 48}}, {\"idx\": 6, \"outputs\": 2147483648, \"inputs\": {\"n\": 32}}, {\"idx\": 7, \"outputs\": 4096, \"inputs\": {\"n\": 13}}, {\"idx\": 8, \"outputs\": 262144, \"inputs\": {\"n\": 19}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
203
Find Sum Modulo K First N Natural Number
C++
int findSumModuloKFirstNNaturalNumber(int n, int k) {
[ "n", "k" ]
def find_sum_modulo_k_first_n_natural_number(N, K): ans = 0 for i in range(1, (N + 1)): ans += (i % K) return ans
int find_sum_modulo_k_first_n_natural_number(int N, int K) { int ans = 0; for ( int i = 1; i <= N; i ++ ) ans += ( i % K ); return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int 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(11, 5, 21); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 69, 666); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 28, 876); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 1, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 84, 2211); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, 14, 237); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, 11, 3); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 87, 2701); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 11, 388); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 55, 465); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumModuloKFirstNNaturalNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 21, \"inputs\": {\"n\": 11, \"k\": 5}}, {\"idx\": 1, \"outputs\": 666, \"inputs\": {\"n\": 36, \"k\": 69}}, {\"idx\": 2, \"outputs\": 876, \"inputs\": {\"n\": 71, \"k\": 28}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 74, \"k\": 1}}, {\"idx\": 4, \"outputs\": 2211, \"inputs\": {\"n\": 66, \"k\": 84}}, {\"idx\": 5, \"outputs\": 237, \"inputs\": {\"n\": 38, \"k\": 14}}, {\"idx\": 6, \"outputs\": 3, \"inputs\": {\"n\": 2, \"k\": 11}}, {\"idx\": 7, \"outputs\": 2701, \"inputs\": {\"n\": 73, \"k\": 87}}, {\"idx\": 8, \"outputs\": 388, \"inputs\": {\"n\": 79, \"k\": 11}}, {\"idx\": 9, \"outputs\": 465, \"inputs\": {\"n\": 30, \"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 ] }
204
Find Sum Modulo K First N Natural Number 1
C++
int findSumModuloKFirstNNaturalNumber1(int n, int k) {
[ "n", "k" ]
def find_sum_modulo_k_first_n_natural_number_1(N, K): ans = 0 y = (N / K) x = (N % K) ans = ((((K * (K - 1)) / 2) * y) + ((x * (x + 1)) / 2)) return int(ans)
int find_sum_modulo_k_first_n_natural_number_1(int N, int K) { int ans = 0; int y = N / K; int x = N % K; ans = ( K * ( K - 1 ) / 2 ) * y + ( x * ( x + 1 ) ) / 2; return ans; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(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(40, 90, 2600); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, 64, 2530); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 20, 1074); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 1, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 52, 3166); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 35, 1345); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 40, 1684); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, 62, 3751); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(74, 61, 2311); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 41, 1691); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumModuloKFirstNNaturalNumber1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2600, \"inputs\": {\"n\": 40, \"k\": 90}}, {\"idx\": 1, \"outputs\": 2530, \"inputs\": {\"n\": 46, \"k\": 64}}, {\"idx\": 2, \"outputs\": 1074, \"inputs\": {\"n\": 97, \"k\": 20}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 63, \"k\": 1}}, {\"idx\": 4, \"outputs\": 3166, \"inputs\": {\"n\": 92, \"k\": 52}}, {\"idx\": 5, \"outputs\": 1345, \"inputs\": {\"n\": 60, \"k\": 35}}, {\"idx\": 6, \"outputs\": 1684, \"inputs\": {\"n\": 67, \"k\": 40}}, {\"idx\": 7, \"outputs\": 3751, \"inputs\": {\"n\": 61, \"k\": 62}}, {\"idx\": 8, \"outputs\": 2311, \"inputs\": {\"n\": 74, \"k\": 61}}, {\"idx\": 9, \"outputs\": 1691, \"inputs\": {\"n\": 67, \"k\": 41}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
205
Find Sum Non Repeating Distinct Elements Array
C++
int findSumNonRepeatingDistinctElementsArray(vector<int> arr, int n) {
[ "arr", "n" ]
def find_sum_non_repeating_distinct_elements_array(arr, n): s = set() sum = 0 for i in range(n): if (arr[i] not in s): s.add(arr[i]) for i in s: sum = (sum + i) return sum
int find_sum_non_repeating_distinct_elements_array(vector<int> arr, int n) { int sum = 0; unordered_set < int > s; for ( int i = 0; i < n; i ++ ) { if ( s . find ( arr [ i ] ) == s . end ( ) ) { sum += arr [ i ]; s . insert ( arr [ 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({5, 6, 8, 10, 21, 22, 27, 32, 35, 36, 43, 44, 46, 48, 49, 55, 60, 61, 69, 69, 71, 72, 73, 78, 88, 94}, 24, 971); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, 94, 16, -74, 32, -64, -84, -66, -10}, 6, 84); \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}, 27, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 4, 96, 39, 39, 24, 15, 47, 25, 74, 7, 98, 88, 91, 62, 12, 31, 14, 48, 26, 37, 25, 11, 32, 34, 64, 72, 5, 80, 86, 6}, 15, 769); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-86, -84, -84, -78, -78, -76, -74, -68, -66, -64, -60, -60, -56, -50, -42, -42, -38, -34, -32, -22, -16, -14, -10, -6, -6, 4, 4, 26, 36, 36, 54, 62, 64, 68, 70, 76, 76, 76, 84, 92, 92, 94, 96}, 27, -972); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1}, 25, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({3, 3, 5, 8, 32, 33, 35, 35, 42, 48, 67, 71, 71, 74, 77, 80, 94, 96, 96, 97}, 19, 765); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-50, -18, -66, 76, -54, 96, 98, 26, 42, 64, -60}, 9, 150); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({70, 21, 44, 82, 62, 41, 86}, 3, 135); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumNonRepeatingDistinctElementsArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 971, \"inputs\": {\"arr\": [5, 6, 8, 10, 21, 22, 27, 32, 35, 36, 43, 44, 46, 48, 49, 55, 60, 61, 69, 69, 71, 72, 73, 78, 88, 94], \"n\": 24}}, {\"idx\": 1, \"outputs\": 84, \"inputs\": {\"arr\": [80, 94, 16, -74, 32, -64, -84, -66, -10], \"n\": 6}}, {\"idx\": 2, \"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, 1], \"n\": 27}}, {\"idx\": 3, \"outputs\": 769, \"inputs\": {\"arr\": [99, 4, 96, 39, 39, 24, 15, 47, 25, 74, 7, 98, 88, 91, 62, 12, 31, 14, 48, 26, 37, 25, 11, 32, 34, 64, 72, 5, 80, 86, 6], \"n\": 15}}, {\"idx\": 4, \"outputs\": -972, \"inputs\": {\"arr\": [-86, -84, -84, -78, -78, -76, -74, -68, -66, -64, -60, -60, -56, -50, -42, -42, -38, -34, -32, -22, -16, -14, -10, -6, -6, 4, 4, 26, 36, 36, 54, 62, 64, 68, 70, 76, 76, 76, 84, 92, 92, 94, 96], \"n\": 27}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"arr\": [1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1], \"n\": 25}}, {\"idx\": 6, \"outputs\": 765, \"inputs\": {\"arr\": [3, 3, 5, 8, 32, 33, 35, 35, 42, 48, 67, 71, 71, 74, 77, 80, 94, 96, 96, 97], \"n\": 19}}, {\"idx\": 7, \"outputs\": 150, \"inputs\": {\"arr\": [-50, -18, -66, 76, -54, 96, 98, 26, 42, 64, -60], \"n\": 9}}, {\"idx\": 8, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 15}}, {\"idx\": 9, \"outputs\": 135, \"inputs\": {\"arr\": [70, 21, 44, 82, 62, 41, 86], \"n\": 3}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
206
Find Sum Odd Factors Number
C++
int findSumOddFactorsNumber(int n) {
[ "n" ]
def find_sum_odd_factors_number(n): res = 1 while ((n % 2) == 0): n = (n // 2) for i in range(3, int((math.sqrt(n) + 1))): count = 0 curr_sum = 1 curr_term = 1 while ((n % i) == 0): count += 1 n = (n // i) curr_term *= i curr_sum += curr_term res *= curr_sum if (n >= 2): res *= (1 + n) return res
int find_sum_odd_factors_number(int n) { int res = 1; while ( n % 2 == 0 ) n = n / 2; for ( int i = 3; i <= sqrt ( n ); i ++ ) { int count = 0, curr_sum = 1; int curr_term = 1; while ( n % i == 0 ) { count ++; n = n / i; curr_term *= i; curr_sum += curr_term; } res *= curr_sum; } if ( n >= 2 ) res *= ( 1 + n ); return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(20, 6); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 56); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 6); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 12); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, 8); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 40); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 84); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 4); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumOddFactorsNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 6, \"inputs\": {\"n\": 20}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"n\": 6}}, {\"idx\": 2, \"outputs\": 56, \"inputs\": {\"n\": 39}}, {\"idx\": 3, \"outputs\": 6, \"inputs\": {\"n\": 80}}, {\"idx\": 4, \"outputs\": 12, \"inputs\": {\"n\": 88}}, {\"idx\": 5, \"outputs\": 8, \"inputs\": {\"n\": 7}}, {\"idx\": 6, \"outputs\": 1, \"inputs\": {\"n\": 16}}, {\"idx\": 7, \"outputs\": 40, \"inputs\": {\"n\": 27}}, {\"idx\": 8, \"outputs\": 84, \"inputs\": {\"n\": 83}}, {\"idx\": 9, \"outputs\": 4, \"inputs\": {\"n\": 6}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
207
Find Sum Unique Sub Array Sum Given Array
C++
int findSumUniqueSubArraySumGivenArray(vector<int> arr, int n) {
[ "arr", "n" ]
def find_sum_unique_sub_array_sum_given_array(arr, n): res = 0 m = dict() for i in range(n): Sum = 0 for j in range(i, n): Sum += arr[j] m[Sum] = (m.get(Sum, 0) + 1) for x in m: if (m[x] == 1): res += x return res
long long int find_sum_unique_sub_array_sum_given_array(vector<int> arr, int n) { int res = 0; unordered_map < int, int > m; for ( int i = 0; i < n; i ++ ) { int sum = 0; for ( int j = i; j < n; j ++ ) { sum += arr [ j ]; m [ sum ] ++; } } for ( auto x : m ) if ( x . second == 1 ) res += x . first; return res; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> 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, 24, 34, 35, 36, 40, 49, 51, 53, 74, 78}, 9, 5631); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-34, 60, 32}, 2, 52); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0}, 0, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({80, 64, 10, 82, 14, 75, 51, 91, 1, 25, 98, 22, 36, 27, 21, 31, 93, 6, 52, 91, 80, 8, 62, 95, 10, 71, 40, 80, 35, 86, 85, 26, 74, 72, 64, 88, 4, 71, 4, 16}, 31, 207596); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-94, -46, -36, -24, -22, 0, 10, 14, 34, 34, 90, 92, 98}, 9, -1638); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1}, 21, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({19, 20, 20, 24, 25, 33, 43, 47, 57, 61, 61, 64, 65, 71, 72, 73, 75, 82, 90, 93, 95}, 15, 27034); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-6, 56, 58, -36, 70, -92, 30, 58, -40, 98, 80, -96, -4, -88, 34, 76, 40, -32, -94, -26, 8, 72, -56, -96, -88, -24, 36, 14, -88, -32, 90, 4, -88, 28, 18}, 24, 1698); \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}, 11, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({91, 51, 15, 78, 55, 3, 10, 24, 42, 84, 66, 78, 10, 41, 21, 53, 69, 57, 20, 22, 50, 72, 8, 80, 12, 91, 29, 95, 38, 74, 95, 26, 10, 57, 51, 25, 49, 74, 15, 42, 99, 21, 27}, 36, 267019); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findSumUniqueSubArraySumGivenArray", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 5631, \"inputs\": {\"arr\": [7, 24, 34, 35, 36, 40, 49, 51, 53, 74, 78], \"n\": 9}}, {\"idx\": 1, \"outputs\": 52, \"inputs\": {\"arr\": [-34, 60, 32], \"n\": 2}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"arr\": [0], \"n\": 0}}, {\"idx\": 3, \"outputs\": 207596, \"inputs\": {\"arr\": [80, 64, 10, 82, 14, 75, 51, 91, 1, 25, 98, 22, 36, 27, 21, 31, 93, 6, 52, 91, 80, 8, 62, 95, 10, 71, 40, 80, 35, 86, 85, 26, 74, 72, 64, 88, 4, 71, 4, 16], \"n\": 31}}, {\"idx\": 4, \"outputs\": -1638, \"inputs\": {\"arr\": [-94, -46, -36, -24, -22, 0, 10, 14, 34, 34, 90, 92, 98], \"n\": 9}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1], \"n\": 21}}, {\"idx\": 6, \"outputs\": 27034, \"inputs\": {\"arr\": [19, 20, 20, 24, 25, 33, 43, 47, 57, 61, 61, 64, 65, 71, 72, 73, 75, 82, 90, 93, 95], \"n\": 15}}, {\"idx\": 7, \"outputs\": 1698, \"inputs\": {\"arr\": [-6, 56, 58, -36, 70, -92, 30, 58, -40, 98, 80, -96, -4, -88, 34, 76, 40, -32, -94, -26, 8, 72, -56, -96, -88, -24, 36, 14, -88, -32, 90, 4, -88, 28, 18], \"n\": 24}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 11}}, {\"idx\": 9, \"outputs\": 267019, \"inputs\": {\"arr\": [91, 51, 15, 78, 55, 3, 10, 24, 42, 84, 66, 78, 10, 41, 21, 53, 69, 57, 20, 22, 50, 72, 8, 80, 12, 91, 29, 95, 38, 74, 95, 26, 10, 57, 51, 25, 49, 74, 15, 42, 99, 21, 27], \"n\": 36}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
208
Find The Element Before Which All The Elements Are Smaller Than It And After Which All Are Greater Than It
C++
int findTheElementBeforeWhichAllTheElementsAreSmallerThanItAndAfterWhichAllAreGreaterThanIt(vector<int> arr, int n) {
[ "arr", "n" ]
def find_the_element_before_which_all_the_elements_are_smaller_than_it_and_after_which_all_are_greater_than_it(arr, n): leftMax = ([None] * n) leftMax[0] = float('-inf') for i in range(1, n): leftMax[i] = max(leftMax[(i - 1)], arr[(i - 1)]) rightMin = float('inf') for i in range((n - 1), (- 1), (- 1)): if ((leftMax[i] < arr[i]) and (rightMin > arr[i])): return i rightMin = min(rightMin, arr[i]) return (- 1)
int find_the_element_before_which_all_the_elements_are_smaller_than_it_and_after_which_all_are_greater_than_it(vector<int> arr, int n) { int leftMax [ n ]; leftMax [ 0 ] = INT_MIN; for ( int i = 1; i < n; i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ], arr [ i - 1 ] ); int rightMin = INT_MAX; for ( int i = n - 1; i >= 0; i -- ) { if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i; rightMin = min ( rightMin, 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({4, 24, 30, 33, 56, 67, 87, 90}, 4, 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({72, -48, 12, 4, 46, 36, 2, 58, 82, -88, -14, 56, 90, 76, 18, -6, -28, 18, 88, 90, 40, -68, -10, -82, -28, 16, 32, -90, 12, -86, -16, 78, -98, -52, -26, 80, 6, 50, 40, -12, 52, 38, -92, 94, -32, 14, -80, -88, 48}, 28, -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, 1, 1, 1}, 30, -1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({51, 87, 46, 76, 2, 89, 56, 34, 49, 61, 44, 73, 14, 60, 89}, 11, -1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-90, -90, -80, -72, -68, -64, -62, -62, -60, -46, -44, -44, -44, -42, -42, -32, -22, -22, -18, -2, 4, 6, 10, 12, 14, 30, 34, 34, 40, 56, 56, 56, 58, 68, 74, 78, 78, 82, 84, 86, 88, 90, 92}, 29, 28); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0}, 26, -1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({7, 8, 11, 12, 15, 17, 28, 34, 57, 61, 66, 76, 92}, 9, 8); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-22, -96, -78, -60, 34, -18, 86, -42, -78, 76, 8, 28, -80, 80, 6, -72, 34, 66, 84, 50, -4, 18, 72, -66, -68, -24, 56, -12, -70, 24, -82}, 19, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, 9, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({79, 81, 55, 6, 78, 93, 81, 33, 29, 1, 27, 49, 21, 58, 22, 65, 44, 95, 6, 51, 75, 42, 14, 55, 79, 82, 90, 8, 15, 15, 53, 98, 76, 43, 33}, 30, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheElementBeforeWhichAllTheElementsAreSmallerThanItAndAfterWhichAllAreGreaterThanIt", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"arr\": [4, 24, 30, 33, 56, 67, 87, 90], \"n\": 4}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"arr\": [72, -48, 12, 4, 46, 36, 2, 58, 82, -88, -14, 56, 90, 76, 18, -6, -28, 18, 88, 90, 40, -68, -10, -82, -28, 16, 32, -90, 12, -86, -16, 78, -98, -52, -26, 80, 6, 50, 40, -12, 52, 38, -92, 94, -32, 14, -80, -88, 48], \"n\": 28}}, {\"idx\": 2, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], \"n\": 30}}, {\"idx\": 3, \"outputs\": -1, \"inputs\": {\"arr\": [51, 87, 46, 76, 2, 89, 56, 34, 49, 61, 44, 73, 14, 60, 89], \"n\": 11}}, {\"idx\": 4, \"outputs\": 28, \"inputs\": {\"arr\": [-90, -90, -80, -72, -68, -64, -62, -62, -60, -46, -44, -44, -44, -42, -42, -32, -22, -22, -18, -2, 4, 6, 10, 12, 14, 30, 34, 34, 40, 56, 56, 56, 58, 68, 74, 78, 78, 82, 84, 86, 88, 90, 92], \"n\": 29}}, {\"idx\": 5, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0], \"n\": 26}}, {\"idx\": 6, \"outputs\": 8, \"inputs\": {\"arr\": [7, 8, 11, 12, 15, 17, 28, 34, 57, 61, 66, 76, 92], \"n\": 9}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"arr\": [-22, -96, -78, -60, 34, -18, 86, -42, -78, 76, 8, 28, -80, 80, 6, -72, 34, 66, 84, 50, -4, 18, 72, -66, -68, -24, 56, -12, -70, 24, -82], \"n\": 19}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], \"n\": 9}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"arr\": [79, 81, 55, 6, 78, 93, 81, 33, 29, 1, 27, 49, 21, 58, 22, 65, 44, 95, 6, 51, 75, 42, 14, 55, 79, 82, 90, 8, 15, 15, 53, 98, 76, 43, 33], \"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 ] }
209
Find The Element That Appears Once
C++
int findTheElementThatAppearsOnce(vector<int> arr, int n) {
[ "arr", "n" ]
def find_the_element_that_appears_once(arr, n): ones = 0 twos = 0 for i in range(n): twos = (twos | (ones & arr[i])) ones = (ones ^ arr[i]) common_bit_mask = (~ (ones & twos)) ones &= common_bit_mask twos &= common_bit_mask return ones
int find_the_element_that_appears_once(vector<int> arr, int n) { int ones = 0, twos = 0; int common_bit_mask; for ( int i = 0; i < n; i ++ ) { twos = twos | ( ones & arr [ i ] ); ones = ones ^ arr [ i ]; common_bit_mask = ~ ( ones & twos ); ones &= common_bit_mask; twos &= common_bit_mask; } return ones; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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, 26, 26, 48, 59, 62, 66, 70, 72, 75, 76, 81, 97, 98}, 7, 72); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-42, -48, -64, -74, 56, -34, 20, 16, 34, -84, 86, 38, 56, -86, 30, -74, -96, 96, 12, 10, -46, 10, -36, 38, 34, -46, -20, 14, 12, 62, -54, 20, -82, 24, 96}, 27, -28); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 1, 1}, 3, 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({68, 91, 61, 6, 32, 47, 76, 69, 44, 71, 29, 79, 74, 33, 44, 33, 45, 75, 43, 82, 83, 81, 95, 16, 86, 33, 69, 61, 73, 21, 54, 17, 98, 62, 14, 72, 80, 31, 56, 82, 14, 48, 76}, 38, 25); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-98, -96, -92, -62, -52, -42, -42, -26, 4, 10, 14, 38, 64, 66, 72, 74, 82}, 14, 104); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 1, 1, 1, 0, 0, 0, 1, 0, 1}, 5, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({53, 63, 63}, 2, 10); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({-96, -38, -26, -46, 68, -36, 20, -18, -10, 52, 40, 94, -8, -64, 82, -22}, 15, 34); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({0, 0, 0, 0, 0, 1, 1}, 3, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver({99, 46, 48, 81, 27, 97, 26, 50, 77, 32, 45, 99, 46}, 12, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "findTheElementThatAppearsOnce", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 72, \"inputs\": {\"arr\": [7, 26, 26, 48, 59, 62, 66, 70, 72, 75, 76, 81, 97, 98], \"n\": 7}}, {\"idx\": 1, \"outputs\": -28, \"inputs\": {\"arr\": [-42, -48, -64, -74, 56, -34, 20, 16, 34, -84, 86, 38, 56, -86, 30, -74, -96, 96, 12, 10, -46, 10, -36, 38, 34, -46, -20, 14, 12, 62, -54, 20, -82, 24, 96], \"n\": 27}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"arr\": [0, 0, 1, 1], \"n\": 3}}, {\"idx\": 3, \"outputs\": 25, \"inputs\": {\"arr\": [68, 91, 61, 6, 32, 47, 76, 69, 44, 71, 29, 79, 74, 33, 44, 33, 45, 75, 43, 82, 83, 81, 95, 16, 86, 33, 69, 61, 73, 21, 54, 17, 98, 62, 14, 72, 80, 31, 56, 82, 14, 48, 76], \"n\": 38}}, {\"idx\": 4, \"outputs\": 104, \"inputs\": {\"arr\": [-98, -96, -92, -62, -52, -42, -42, -26, 4, 10, 14, 38, 64, 66, 72, 74, 82], \"n\": 14}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"arr\": [0, 1, 1, 1, 0, 0, 0, 1, 0, 1], \"n\": 5}}, {\"idx\": 6, \"outputs\": 10, \"inputs\": {\"arr\": [53, 63, 63], \"n\": 2}}, {\"idx\": 7, \"outputs\": 34, \"inputs\": {\"arr\": [-96, -38, -26, -46, 68, -36, 20, -18, -10, 52, 40, 94, -8, -64, 82, -22], \"n\": 15}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"arr\": [0, 0, 0, 0, 0, 1, 1], \"n\": 3}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"arr\": [99, 46, 48, 81, 27, 97, 26, 50, 77, 32, 45, 99, 46], \"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 ] }