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
538
Sum Series 555555 N Terms
C++
long long sumSeries555555NTerms(int n) {
[ "n" ]
def sum_series_555555_n_terms(n): return int(((0.6172 * (pow(10, n) - 1)) - (0.55 * n)))
int sum_series_555555_n_terms(int n) { return 0.6172 * ( pow ( 10, n ) - 1 ) - 0.55 * n; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(18, 617200000000000000); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, 61719999999991); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 617199999999991); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 614); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "sumSeries555555NTerms", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 617200000000000000, \"inputs\": {\"n\": 18}}, {\"idx\": 1, \"outputs\": 61719999999991, \"inputs\": {\"n\": 14}}, {\"idx\": 2, \"outputs\": 617199999999991, \"inputs\": {\"n\": 15}}, {\"idx\": 3, \"outputs\": 614, \"inputs\": {\"n\": 3}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
539
Sum Squares Binomial Coefficients
C++
long long sumSquaresBinomialCoefficients(int n) {
[ "n" ]
def sum_squares_binomial_coefficients(n): C = [[0 for i in range((n + 1))] for j 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)): sum = (sum + (C[n][i] * C[n][i])) return sum
int sum_squares_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 ++ ) sum += ( C [ n ] [ i ] * 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(19, 35345263800); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, 32247603683100); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 2104098963720); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 155117520); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "sumSquaresBinomialCoefficients", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 35345263800, \"inputs\": {\"n\": 19}}, {\"idx\": 1, \"outputs\": 32247603683100, \"inputs\": {\"n\": 24}}, {\"idx\": 2, \"outputs\": 2104098963720, \"inputs\": {\"n\": 22}}, {\"idx\": 3, \"outputs\": 155117520, \"inputs\": {\"n\": 15}}]", "test_case_ids": [ "0", "1", "2", "3" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
540
Sum Subsets Set Formed First N Natural Numbers
C++
double sumSubsetsSetFormedFirstNNaturalNumbers(int n) {
[ "n" ]
def sum_subsets_set_formed_first_n_natural_numbers(n): return (((n * (n + 1)) / 2) * (1 << (n - 1)))
unsigned long long sum_subsets_set_formed_first_n_natural_numbers(int n) { return ( n * ( n + 1 ) / 2 ) * ( 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(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(26, 11777605632.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 10823317585920.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(34, 5111011082240.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 530579456.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 24.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 5452595200.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(22, 530579456.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "sumSubsetsSetFormedFirstNNaturalNumbers", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 11777605632.0, \"inputs\": {\"n\": 26}}, {\"idx\": 1, \"outputs\": 10823317585920.0, \"inputs\": {\"n\": 35}}, {\"idx\": 2, \"outputs\": 5111011082240.0, \"inputs\": {\"n\": 34}}, {\"idx\": 3, \"outputs\": 530579456.0, \"inputs\": {\"n\": 22}}, {\"idx\": 4, \"outputs\": 24.0, \"inputs\": {\"n\": 3}}, {\"idx\": 5, \"outputs\": 5452595200.0, \"inputs\": {\"n\": 25}}, {\"idx\": 6, \"outputs\": 530579456.0, \"inputs\": {\"n\": 22}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
541
Sum Two Large Numbers
C++
string sumTwoLargeNumbers(string str1, string str2) {
[ "str1", "str2" ]
def sum_two_large_numbers(str1, str2): if (len(str1) > len(str2)): t = str1 str1 = str2 str2 = t str = '' n1 = len(str1) n2 = len(str2) str1 = str1[::(- 1)] str2 = str2[::(- 1)] carry = 0 for i in range(n1): sum = ((ord(str1[i]) - 48) + ((ord(str2[i]) - 48) + carry)) str += chr(((sum % 10) + 48)) carry = int((sum / 10)) for i in range(n1, n2): sum = ((ord(str2[i]) - 48) + carry) str += chr(((sum % 10) + 48)) carry = int((sum / 10)) if carry: str += chr((carry + 48)) str = str[::(- 1)] return str
string sum_two_large_numbers(string str1, string str2) { if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1, str2 ); string str = ""; int n1 = str1 . length ( ), n2 = str2 . length ( ); reverse ( str1 . begin ( ), str1 . end ( ) ); reverse ( str2 . begin ( ), str2 . end ( ) ); int carry = 0; for ( int i = 0; i < n1; i ++ ) { int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ); str . push_back ( sum % 10 + '0' ); carry = sum / 10; } for ( int i = n1; i < n2; i ++ ) { int sum = ( ( str2 [ i ] - '0' ) + carry ); str . push_back ( sum % 10 + '0' ); carry = sum / 10; } if ( carry ) str . push_back ( carry + '0' ); reverse ( str . begin ( ), str . end ( ) ); return str; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#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 str1, string str2, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str1, str2), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"VkfzrPG\", \"rKZ\", \"44527855\"); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0526110506447\", \"903\", \"0526110507350\"); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"011010010\", \"110100000\", \"121110010\"); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"sPAwZACc \", \"liYMsojPiinOV\", \"66153436372942\"); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"3\", \"611\", \"614\"); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"0101\", \"01110101011\", \"01110101112\"); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"VTtNu\", \"Wsmc\", \"469530\"); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"2317170\", \"898421173423\", \"898423490593\"); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"111111000010\", \"01100001110111\", \"01211112110121\"); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Ktt\", \"CTbbVX wGBkE\", \"2315420138859\"); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "sumTwoLargeNumbers", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": \"44527855\", \"inputs\": {\"str1\": \"VkfzrPG\", \"str2\": \"rKZ\"}}, {\"idx\": 1, \"outputs\": \"0526110507350\", \"inputs\": {\"str1\": \"0526110506447\", \"str2\": \"903\"}}, {\"idx\": 2, \"outputs\": \"121110010\", \"inputs\": {\"str1\": \"011010010\", \"str2\": \"110100000\"}}, {\"idx\": 3, \"outputs\": \"66153436372942\", \"inputs\": {\"str1\": \"sPAwZACc \", \"str2\": \"liYMsojPiinOV\"}}, {\"idx\": 4, \"outputs\": \"614\", \"inputs\": {\"str1\": \"3\", \"str2\": \"611\"}}, {\"idx\": 5, \"outputs\": \"01110101112\", \"inputs\": {\"str1\": \"0101\", \"str2\": \"01110101011\"}}, {\"idx\": 6, \"outputs\": \"469530\", \"inputs\": {\"str1\": \"VTtNu\", \"str2\": \"Wsmc\"}}, {\"idx\": 7, \"outputs\": \"898423490593\", \"inputs\": {\"str1\": \"2317170\", \"str2\": \"898421173423\"}}, {\"idx\": 8, \"outputs\": \"01211112110121\", \"inputs\": {\"str1\": \"111111000010\", \"str2\": \"01100001110111\"}}, {\"idx\": 9, \"outputs\": \"2315420138859\", \"inputs\": {\"str1\": \"Ktt\", \"str2\": \"CTbbVX wGBkE\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
542
Swap All Odd And Even Bits
C++
int swapAllOddAndEvenBits(int x) {
[ "x" ]
def swap_all_odd_and_even_bits(x): even_bits = (x & 2863311530) odd_bits = (x & 1431655765) even_bits >>= 1 odd_bits <<= 1 return (even_bits | odd_bits)
unsigned int swap_all_odd_and_even_bits(unsigned int x) { unsigned int even_bits = x & 0xAAAAAAAA; unsigned int odd_bits = x & 0x55555555; even_bits >>= 1; odd_bits <<= 1; return ( even_bits | odd_bits ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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(99, 147); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 173); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 7); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 3); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(77, 142); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 54); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 57); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 129); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 145); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 24); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "swapAllOddAndEvenBits", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 147, \"inputs\": {\"x\": 99}}, {\"idx\": 1, \"outputs\": 173, \"inputs\": {\"x\": 94}}, {\"idx\": 2, \"outputs\": 7, \"inputs\": {\"x\": 11}}, {\"idx\": 3, \"outputs\": 3, \"inputs\": {\"x\": 3}}, {\"idx\": 4, \"outputs\": 142, \"inputs\": {\"x\": 77}}, {\"idx\": 5, \"outputs\": 54, \"inputs\": {\"x\": 57}}, {\"idx\": 6, \"outputs\": 57, \"inputs\": {\"x\": 54}}, {\"idx\": 7, \"outputs\": 129, \"inputs\": {\"x\": 66}}, {\"idx\": 8, \"outputs\": 145, \"inputs\": {\"x\": 98}}, {\"idx\": 9, \"outputs\": 24, \"inputs\": {\"x\": 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 ] }
543
Swap Bits In A Given Number
C++
int swapBitsInAGivenNumber(int x, int p1, int p2, int n) {
[ "x", "p1", "p2", "n" ]
def swap_bits_in_a_given_number(x, p1, p2, n): set1 = ((x >> p1) & ((1 << n) - 1)) set2 = ((x >> p2) & ((1 << n) - 1)) xor = (set1 ^ set2) xor = ((xor << p1) | (xor << p2)) result = (x ^ xor) return result
int swap_bits_in_a_given_number(unsigned int x, unsigned int p1, unsigned int p2, unsigned int n) { unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 ); unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 ); unsigned int Xor = ( set1 ^ set2 ); Xor = ( Xor << p1 ) | ( Xor << p2 ); unsigned int result = x ^ Xor; return result; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int p1, int p2, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, p1, p2, 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, 88, 97, 92, 95); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 26, 59, 42, 16); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, 56, 40, 41, 55); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(75, 35, 79, 30, 75); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 12, 59, 34, 90); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 65, 25, 19, 58); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 64, 17, 94, 69); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 33, 97, 44, 36); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, 69, 66, 9, 62); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "swapBitsInAGivenNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 95, \"inputs\": {\"x\": 95, \"p1\": 88, \"p2\": 97, \"n\": 92}}, {\"idx\": 1, \"outputs\": 16, \"inputs\": {\"x\": 16, \"p1\": 26, \"p2\": 59, \"n\": 42}}, {\"idx\": 2, \"outputs\": 55, \"inputs\": {\"x\": 55, \"p1\": 56, \"p2\": 40, \"n\": 41}}, {\"idx\": 3, \"outputs\": 75, \"inputs\": {\"x\": 75, \"p1\": 35, \"p2\": 79, \"n\": 30}}, {\"idx\": 4, \"outputs\": 90, \"inputs\": {\"x\": 90, \"p1\": 12, \"p2\": 59, \"n\": 34}}, {\"idx\": 5, \"outputs\": 58, \"inputs\": {\"x\": 58, \"p1\": 65, \"p2\": 25, \"n\": 19}}, {\"idx\": 6, \"outputs\": 69, \"inputs\": {\"x\": 69, \"p1\": 64, \"p2\": 17, \"n\": 94}}, {\"idx\": 7, \"outputs\": 36, \"inputs\": {\"x\": 36, \"p1\": 33, \"p2\": 97, \"n\": 44}}, {\"idx\": 8, \"outputs\": 62, \"inputs\": {\"x\": 62, \"p1\": 69, \"p2\": 66, \"n\": 9}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
544
Swap Two Nibbles Byte
C++
int swapTwoNibblesByte(int x) {
[ "x" ]
def swap_two_nibbles_byte(x): return (((x & 15) << 4) | ((x & 240) >> 4))
int swap_two_nibbles_byte(int x) { return ( ( x & 0x0F ) << 4 | ( x & 0xF0 ) >> 4 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int 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(57, 147); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(99, 54); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 36); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, 22); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 245); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 162); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 245); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(89, 149); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, 48); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(84, 69); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "swapTwoNibblesByte", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 147, \"inputs\": {\"x\": 57}}, {\"idx\": 1, \"outputs\": 54, \"inputs\": {\"x\": 99}}, {\"idx\": 2, \"outputs\": 36, \"inputs\": {\"x\": 66}}, {\"idx\": 3, \"outputs\": 22, \"inputs\": {\"x\": 97}}, {\"idx\": 4, \"outputs\": 245, \"inputs\": {\"x\": 95}}, {\"idx\": 5, \"outputs\": 162, \"inputs\": {\"x\": 42}}, {\"idx\": 6, \"outputs\": 245, \"inputs\": {\"x\": 95}}, {\"idx\": 7, \"outputs\": 149, \"inputs\": {\"x\": 89}}, {\"idx\": 8, \"outputs\": 48, \"inputs\": {\"x\": 3}}, {\"idx\": 9, \"outputs\": 69, \"inputs\": {\"x\": 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 ] }
545
Tail Recursion
C++
long long tailRecursion(int n) {
[ "n" ]
def tail_recursion(n): if (n == 0): return 1 return (n * tail_recursion((n - 1)))
unsigned int tail_recursion(unsigned int n) { if ( n == 0 ) return 1; return n * tail_recursion ( n - 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(16, 20922789888000); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "tailRecursion", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 20922789888000, \"inputs\": {\"n\": 16}}]", "test_case_ids": [ "0" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
547
Temple Offerings
C++
int templeOfferings(int n, vector<int> templeheight) {
[ "n", "templeheight" ]
def temple_offerings(n, templeHeight): sum = 0 for i in range(n): left = 0 right = 0 for j in range((i - 1), (- 1), (- 1)): if (templeHeight[j] < templeHeight[(j + 1)]): left += 1 else: break for j in range((i + 1), n): if (templeHeight[j] < templeHeight[(j - 1)]): right += 1 else: break sum += (max(right, left) + 1) return sum
int temple_offerings(int n, vector<int> templeHeight) { int sum = 0; for ( int i = 0; i < n; ++ i ) { int left = 0, right = 0; for ( int j = i - 1; j >= 0; -- j ) { if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left; else break; } for ( int j = i + 1; j < n; ++ j ) { if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right; else break; } sum += max ( right, left ) + 1; } return sum; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, vector<int> templeheight, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, templeheight), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(12, {3, 11, 12, 15, 16, 21, 24, 29, 32, 39, 42, 44, 51, 68, 79, 81, 81, 85, 92, 94}, 78); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, {76, 48, 88, 70, -64, 66, -6, -58, 26, -28, -42, -94, 80, -4, -56, -46, 4, 90, -12, -78, 64, 18, -38, 26, 56, -24, 66, -18, -12, 0, -94, 12, -10, 4, -68, -20, 88, 2, -58, 16, 46, -80, -42, 44, -86, 96, -44}, 92); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, {2, 95, 20, 50, 2, 58, 20, 14, 65, 69, 78, 7}, 15); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(0, {-88}, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(38, {0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0}, 50); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(28, {2, 3, 6, 8, 9, 10, 14, 17, 17, 22, 25, 27, 29, 29, 30, 32, 33, 35, 38, 42, 50, 51, 51, 57, 59, 59, 59, 60, 62, 62, 63, 67, 70, 75, 76, 77, 81, 81, 83, 84}, 106); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(9, {-52, 62, 74, -62, -58, 62, 38, 42, -50, 20}, 16); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 19); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(29, {96, 15, 9, 9, 40, 34, 17, 4, 51, 49, 34, 66, 97, 28, 64, 65, 92, 56, 74, 48, 43, 17, 82, 8, 21, 39, 83, 35, 42, 37, 64, 34, 42, 59, 45, 61, 55, 93, 94, 29, 20, 96, 77, 66}, 64); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "templeOfferings", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 78, \"inputs\": {\"n\": 12, \"templeheight\": [3, 11, 12, 15, 16, 21, 24, 29, 32, 39, 42, 44, 51, 68, 79, 81, 81, 85, 92, 94]}}, {\"idx\": 1, \"outputs\": 92, \"inputs\": {\"n\": 46, \"templeheight\": [76, 48, 88, 70, -64, 66, -6, -58, 26, -28, -42, -94, 80, -4, -56, -46, 4, 90, -12, -78, 64, 18, -38, 26, 56, -24, 66, -18, -12, 0, -94, 12, -10, 4, -68, -20, 88, 2, -58, 16, 46, -80, -42, 44, -86, 96, -44]}}, {\"idx\": 2, \"outputs\": 17, \"inputs\": {\"n\": 16, \"templeheight\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}}, {\"idx\": 3, \"outputs\": 15, \"inputs\": {\"n\": 9, \"templeheight\": [2, 95, 20, 50, 2, 58, 20, 14, 65, 69, 78, 7]}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 0, \"templeheight\": [-88]}}, {\"idx\": 5, \"outputs\": 50, \"inputs\": {\"n\": 38, \"templeheight\": [0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]}}, {\"idx\": 6, \"outputs\": 106, \"inputs\": {\"n\": 28, \"templeheight\": [2, 3, 6, 8, 9, 10, 14, 17, 17, 22, 25, 27, 29, 29, 30, 32, 33, 35, 38, 42, 50, 51, 51, 57, 59, 59, 59, 60, 62, 62, 63, 67, 70, 75, 76, 77, 81, 81, 83, 84]}}, {\"idx\": 7, \"outputs\": 16, \"inputs\": {\"n\": 9, \"templeheight\": [-52, 62, 74, -62, -58, 62, 38, 42, -50, 20]}}, {\"idx\": 8, \"outputs\": 19, \"inputs\": {\"n\": 18, \"templeheight\": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}}, {\"idx\": 9, \"outputs\": 64, \"inputs\": {\"n\": 29, \"templeheight\": [96, 15, 9, 9, 40, 34, 17, 4, 51, 49, 34, 66, 97, 28, 64, 65, 92, 56, 74, 48, 43, 17, 82, 8, 21, 39, 83, 35, 42, 37, 64, 34, 42, 59, 45, 61, 55, 93, 94, 29, 20, 96, 77, 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 ] }
548
Tiling With Dominoes
C++
long long tilingWithDominoes(int n) {
[ "n" ]
def tiling_with_dominoes(n): A = ([0] * (n + 1)) B = ([0] * (n + 1)) A[0] = 1 A[1] = 0 B[0] = 0 B[1] = 1 for i in range(2, (n + 1)): A[i] = (A[(i - 2)] + (2 * B[(i - 1)])) B[i] = (A[(i - 1)] + B[(i - 2)]) return A[n]
int tiling_with_dominoes(int n) { int A [ n + 1 ], B [ n + 1 ]; A [ 0 ] = 1, A [ 1 ] = 0, B [ 0 ] = 0, B [ 1 ] = 1; for ( int i = 2; i <= n; i ++ ) { A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]; B [ i ] = A [ i - 1 ] + B [ i - 2 ]; } return A [ n ]; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(29, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(65, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, 808717138331); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(50, 156886956080403); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(59, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "tilingWithDominoes", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": 29}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"n\": 13}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 25}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 65}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 27}}, {\"idx\": 5, \"outputs\": 808717138331, \"inputs\": {\"n\": 42}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 19}}, {\"idx\": 7, \"outputs\": 156886956080403, \"inputs\": {\"n\": 50}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": 59}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"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 ] }
549
Total Number Of Non Decreasing Numbers With N Digits
C++
long long totalNumberOfNonDecreasingNumbersWithNDigits(int n) {
[ "n" ]
def total_number_of_non_decreasing_numbers_with_n_digits(n): dp = [[0 for i in range((n + 1))] for i in range(10)] for i in range(10): dp[i][1] = 1 for digit in range(10): for len in range(2, (n + 1)): for x in range((digit + 1)): dp[digit][len] += dp[x][(len - 1)] count = 0 for i in range(10): count += dp[i][n] return count
long long int total_number_of_non_decreasing_numbers_with_n_digits(int n) { long long int dp [ 10 ] [ n + 1 ]; memset ( dp, 0, sizeof dp ); for ( int i = 0; i < 10; i ++ ) dp [ i ] [ 1 ] = 1; for ( int digit = 0; digit <= 9; digit ++ ) { for ( int len = 2; len <= n; len ++ ) { for ( int x = 0; x <= digit; x ++ ) dp [ digit ] [ len ] += dp [ x ] [ len - 1 ]; } } long long int count = 0; for ( int i = 0; i < 10; i ++ ) count += dp [ i ] [ n ]; 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(long long actual, long long expected){\n return actual == expected;\n}\n\nstring driver(int n, long long expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(21, 14307150); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 2054455634); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 868754947060); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 2290415157800); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 3679075400); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(98, 3585446225075); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(35, 708930508); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 1174992339235); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 411731930610); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(88, 1429144287220); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "totalNumberOfNonDecreasingNumbersWithNDigits", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 14307150, \"inputs\": {\"n\": 21}}, {\"idx\": 1, \"outputs\": 2054455634, \"inputs\": {\"n\": 40}}, {\"idx\": 2, \"outputs\": 868754947060, \"inputs\": {\"n\": 83}}, {\"idx\": 3, \"outputs\": 2290415157800, \"inputs\": {\"n\": 93}}, {\"idx\": 4, \"outputs\": 3679075400, \"inputs\": {\"n\": 43}}, {\"idx\": 5, \"outputs\": 3585446225075, \"inputs\": {\"n\": 98}}, {\"idx\": 6, \"outputs\": 708930508, \"inputs\": {\"n\": 35}}, {\"idx\": 7, \"outputs\": 1174992339235, \"inputs\": {\"n\": 86}}, {\"idx\": 8, \"outputs\": 411731930610, \"inputs\": {\"n\": 76}}, {\"idx\": 9, \"outputs\": 1429144287220, \"inputs\": {\"n\": 88}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
550
Total Number Of Non Decreasing Numbers With N Digits 1
C++
long long totalNumberOfNonDecreasingNumbersWithNDigits1(int n) {
[ "n" ]
def total_number_of_non_decreasing_numbers_with_n_digits_1(n): N = 10 count = 1 for i in range(1, (n + 1)): count = int((count * ((N + i) - 1))) count = int((count / i)) return count
long long int total_number_of_non_decreasing_numbers_with_n_digits_1(int n) { int N = 10; long long count = 1; for ( int i = 1; i <= n; i ++ ) { count *= ( N + i - 1 ); count /= 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(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(40, 2054455634); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(11, 167960); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 2509710226100); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 293052087900); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, 5005); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, 293052087900); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(58, 42757703560); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, 2054455634); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 97082021465); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, 125595622175); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "totalNumberOfNonDecreasingNumbersWithNDigits1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 2054455634, \"inputs\": {\"n\": 40}}, {\"idx\": 1, \"outputs\": 167960, \"inputs\": {\"n\": 11}}, {\"idx\": 2, \"outputs\": 2509710226100, \"inputs\": {\"n\": 94}}, {\"idx\": 3, \"outputs\": 293052087900, \"inputs\": {\"n\": 73}}, {\"idx\": 4, \"outputs\": 5005, \"inputs\": {\"n\": 6}}, {\"idx\": 5, \"outputs\": 293052087900, \"inputs\": {\"n\": 73}}, {\"idx\": 6, \"outputs\": 42757703560, \"inputs\": {\"n\": 58}}, {\"idx\": 7, \"outputs\": 2054455634, \"inputs\": {\"n\": 40}}, {\"idx\": 8, \"outputs\": 97082021465, \"inputs\": {\"n\": 64}}, {\"idx\": 9, \"outputs\": 125595622175, \"inputs\": {\"n\": 66}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
551
Triangular Matchstick Number
C++
float triangularMatchstickNumber(int x) {
[ "x" ]
def triangular_matchstick_number(x): return (((3 * x) * (x + 1)) / 2)
int triangular_matchstick_number(int x) { return ( 3 * x * ( x + 1 ) ) / 2; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int x, float 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(6, 63.0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(25, 975.0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(15, 360.0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(30, 1395.0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(17, 459.0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(80, 9720.0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(27, 1134.0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(13, 273.0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(12, 234.0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(67, 6834.0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "triangularMatchstickNumber", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 63.0, \"inputs\": {\"x\": 6}}, {\"idx\": 1, \"outputs\": 975.0, \"inputs\": {\"x\": 25}}, {\"idx\": 2, \"outputs\": 360.0, \"inputs\": {\"x\": 15}}, {\"idx\": 3, \"outputs\": 1395.0, \"inputs\": {\"x\": 30}}, {\"idx\": 4, \"outputs\": 459.0, \"inputs\": {\"x\": 17}}, {\"idx\": 5, \"outputs\": 9720.0, \"inputs\": {\"x\": 80}}, {\"idx\": 6, \"outputs\": 1134.0, \"inputs\": {\"x\": 27}}, {\"idx\": 7, \"outputs\": 273.0, \"inputs\": {\"x\": 13}}, {\"idx\": 8, \"outputs\": 234.0, \"inputs\": {\"x\": 12}}, {\"idx\": 9, \"outputs\": 6834.0, \"inputs\": {\"x\": 67}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
552
Triangular Numbers
C++
bool triangularNumbers(int num) {
[ "num" ]
def triangular_numbers(num): if (num < 0): return False (sum, n) = (0, 1) while (sum <= num): sum = (sum + n) if (sum == num): return True n += 1 return False
bool triangular_numbers(int num) { if ( num < 0 ) return false; int sum = 0; for ( int n = 1; sum <= num; n ++ ) { sum = sum + n; if ( sum == num ) 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 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(97, false); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, false); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, false); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(40, false); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(18, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(14, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, true); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "triangularNumbers", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": false, \"inputs\": {\"num\": 97}}, {\"idx\": 1, \"outputs\": false, \"inputs\": {\"num\": 97}}, {\"idx\": 2, \"outputs\": false, \"inputs\": {\"num\": 32}}, {\"idx\": 3, \"outputs\": false, \"inputs\": {\"num\": 40}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"num\": 18}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"num\": 14}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"num\": 90}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"num\": 39}}, {\"idx\": 8, \"outputs\": true, \"inputs\": {\"num\": 1}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"num\": 57}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
553
Triangular Numbers 1
C++
bool triangularNumbers1(int num) {
[ "num" ]
def triangular_numbers_1(num): if (num < 0): return False c = ((- 2) * num) (b, a) = (1, 1) d = ((b * b) - ((4 * a) * c)) if (d < 0): return False root1 = (((- b) + math.sqrt(d)) / (2 * a)) root2 = (((- b) - math.sqrt(d)) / (2 * a)) if ((root1 > 0) and (math.floor(root1) == root1)): return True if ((root2 > 0) and (math.floor(root2) == root2)): return True return False
bool triangular_numbers_1(int num) { if ( num < 0 ) return false; int c = ( - 2 * num ); int b = 1, a = 1; int d = ( b * b ) - ( 4 * a * c ); if ( d < 0 ) return false; float root1 = ( - b + sqrt ( d ) ) / ( 2 * a ); float root2 = ( - b - sqrt ( d ) ) / ( 2 * a ); if ( root1 > 0 && floor ( root1 ) == root1 ) return true; if ( root2 > 0 && floor ( root2 ) == root2 ) 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 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(1, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(3, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(6, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(10, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(55, true); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(48, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "triangularNumbers1", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"num\": 1}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"num\": 3}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"num\": 6}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"num\": 10}}, {\"idx\": 4, \"outputs\": true, \"inputs\": {\"num\": 55}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"num\": 48}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"num\": 63}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"num\": 72}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"num\": 16}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"num\": 85}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
554
Turn Off The Rightmost Set Bit
C++
int turnOffTheRightmostSetBit(int n) {
[ "n" ]
def turn_off_the_rightmost_set_bit(n): return (n & (n - 1))
int turn_off_the_rightmost_set_bit(unsigned int n) { return n & ( n - 1 ); }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(9, 8); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(54, 52); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(60, 56); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(41, 40); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(4, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(51, 50); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(57, 56); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(92, 88); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "turnOffTheRightmostSetBit", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 8, \"inputs\": {\"n\": 9}}, {\"idx\": 1, \"outputs\": 52, \"inputs\": {\"n\": 54}}, {\"idx\": 2, \"outputs\": 56, \"inputs\": {\"n\": 60}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 32}}, {\"idx\": 4, \"outputs\": 40, \"inputs\": {\"n\": 41}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 64}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 4}}, {\"idx\": 7, \"outputs\": 50, \"inputs\": {\"n\": 51}}, {\"idx\": 8, \"outputs\": 56, \"inputs\": {\"n\": 57}}, {\"idx\": 9, \"outputs\": 88, \"inputs\": {\"n\": 92}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
555
Ugly Numbers
C++
int uglyNumbers(int n) {
[ "n" ]
def ugly_numbers(n): ugly = ([0] * n) ugly[0] = 1 i2 = i3 = i5 = 0 next_multiple_of_2 = 2 next_multiple_of_3 = 3 next_multiple_of_5 = 5 for l in range(1, n): ugly[l] = min(next_multiple_of_2, next_multiple_of_3, next_multiple_of_5) if (ugly[l] == next_multiple_of_2): i2 += 1 next_multiple_of_2 = (ugly[i2] * 2) if (ugly[l] == next_multiple_of_3): i3 += 1 next_multiple_of_3 = (ugly[i3] * 3) if (ugly[l] == next_multiple_of_5): i5 += 1 next_multiple_of_5 = (ugly[i5] * 5) return ugly[(- 1)]
unsigned ugly_numbers(unsigned n) { unsigned ugly [ n ]; unsigned i2 = 0, i3 = 0, i5 = 0; unsigned next_multiple_of_2 = 2; unsigned next_multiple_of_3 = 3; unsigned next_multiple_of_5 = 5; unsigned next_ugly_no = 1; ugly [ 0 ] = 1; for ( int i = 1; i < n; i ++ ) { next_ugly_no = min ( next_multiple_of_2, min ( next_multiple_of_3, next_multiple_of_5 ) ); ugly [ i ] = next_ugly_no; if ( next_ugly_no == next_multiple_of_2 ) { i2 = i2 + 1; next_multiple_of_2 = ugly [ i2 ] * 2; } if ( next_ugly_no == next_multiple_of_3 ) { i3 = i3 + 1; next_multiple_of_3 = ugly [ i3 ] * 3; } if ( next_ugly_no == next_multiple_of_5 ) { i5 = i5 + 1; next_multiple_of_5 = ugly [ i5 ] * 5; } } return next_ugly_no; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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(27, 64); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 450); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(93, 1250); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 1152); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 972); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 1000); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(72, 625); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(86, 1000); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(32, 90); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1, 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "uglyNumbers", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 64, \"inputs\": {\"n\": 27}}, {\"idx\": 1, \"outputs\": 450, \"inputs\": {\"n\": 64}}, {\"idx\": 2, \"outputs\": 1250, \"inputs\": {\"n\": 93}}, {\"idx\": 3, \"outputs\": 1152, \"inputs\": {\"n\": 90}}, {\"idx\": 4, \"outputs\": 972, \"inputs\": {\"n\": 85}}, {\"idx\": 5, \"outputs\": 1000, \"inputs\": {\"n\": 86}}, {\"idx\": 6, \"outputs\": 625, \"inputs\": {\"n\": 72}}, {\"idx\": 7, \"outputs\": 1000, \"inputs\": {\"n\": 86}}, {\"idx\": 8, \"outputs\": 90, \"inputs\": {\"n\": 32}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"n\": 1}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
556
Ways Remove One Element Binary String Xor Becomes Zero
C++
int waysRemoveOneElementBinaryStringXorBecomesZero(string str) {
[ "str" ]
def ways_remove_one_element_binary_string_xor_becomes_zero(str): one_count = 0 zero_count = 0 n = len(str) for i in range(0, n, 1): if (str[i] == '1'): one_count += 1 else: zero_count += 1 if ((one_count % 2) == 0): return zero_count return one_count
int ways_remove_one_element_binary_string_xor_becomes_zero(string str) { int one_count = 0, zero_count = 0; int n = str . length ( ); for ( int i = 0; i < n; i ++ ) if ( str [ i ] == '1' ) one_count ++; else zero_count ++; if ( one_count % 2 == 0 ) return zero_count; return one_count; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string str, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(\"KfcTJNP\", 7); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"05312505872\", 1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"100111\", 2); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"tDEEhKxrQ\", 9); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"50824233019\", 1); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10001110010\", 5); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"T SEZaNm MYQ\", 12); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"838415739\", 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01110100\", 4); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"WYQiAey H\", 9); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "waysRemoveOneElementBinaryStringXorBecomesZero", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 7, \"inputs\": {\"str\": \"KfcTJNP\"}}, {\"idx\": 1, \"outputs\": 1, \"inputs\": {\"str\": \"05312505872\"}}, {\"idx\": 2, \"outputs\": 2, \"inputs\": {\"str\": \"100111\"}}, {\"idx\": 3, \"outputs\": 9, \"inputs\": {\"str\": \"tDEEhKxrQ\"}}, {\"idx\": 4, \"outputs\": 1, \"inputs\": {\"str\": \"50824233019\"}}, {\"idx\": 5, \"outputs\": 5, \"inputs\": {\"str\": \"10001110010\"}}, {\"idx\": 6, \"outputs\": 12, \"inputs\": {\"str\": \"T SEZaNm MYQ\"}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"str\": \"838415739\"}}, {\"idx\": 8, \"outputs\": 4, \"inputs\": {\"str\": \"01110100\"}}, {\"idx\": 9, \"outputs\": 9, \"inputs\": {\"str\": \"WYQiAey H\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
557
Ways Transforming One String Removing 0 Characters
C++
int waysTransformingOneStringRemoving0Characters(string a, string b) {
[ "a", "b" ]
def ways_transforming_one_string_removing_0_characters(a, b): n = len(a) m = len(b) if (m == 0): return 1 dp = [([0] * (n + 1)) for _ in range((m + 1))] for i in range(m): for j in range(i, n): if (i == 0): if (j == 0): if (a[j] == b[i]): dp[i][j] = 1 else: dp[i][j] = 0 elif (a[j] == b[i]): dp[i][j] = (dp[i][(j - 1)] + 1) else: dp[i][j] = dp[i][(j - 1)] elif (a[j] == b[i]): dp[i][j] = (dp[i][(j - 1)] + dp[(i - 1)][(j - 1)]) else: dp[i][j] = dp[i][(j - 1)] return dp[(m - 1)][(n - 1)]
int ways_transforming_one_string_removing_0_characters(string a, string b) { int n = a . size ( ), m = b . size ( ); if ( m == 0 ) return 1; int dp [ m + 1 ] [ n + 1 ]; memset ( dp, 0, sizeof ( dp ) ); for ( int i = 0; i < m; i ++ ) { for ( int j = i; j < n; j ++ ) { if ( i == 0 ) { if ( j == 0 ) dp [ i ] [ j ] = ( a [ j ] == b [ i ] ) ? 1 : 0; else if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1; else dp [ i ] [ j ] = dp [ i ] [ j - 1 ]; } else { if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ]; else dp [ i ] [ j ] = dp [ i ] [ j - 1 ]; } } } return dp [ m - 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(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(\"abcccdf\", \"abccdf\", 3); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aabba\", \"ab\", 4); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"aabsdfljk\", \"aa\", 1); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"IONiqV\", \"XKbBiGZ\", 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"9667771256770\", \"50915176\", 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"10001011\", \"01\", 11); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"fczbDtMDT\", \"FbX\", 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"298746088\", \"29888\", 1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"01100011000\", \"0\", 7); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(\"Qk\", \"\", 1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "waysTransformingOneStringRemoving0Characters", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 3, \"inputs\": {\"a\": \"abcccdf\", \"b\": \"abccdf\"}}, {\"idx\": 1, \"outputs\": 4, \"inputs\": {\"a\": \"aabba\", \"b\": \"ab\"}}, {\"idx\": 2, \"outputs\": 1, \"inputs\": {\"a\": \"aabsdfljk\", \"b\": \"aa\"}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"a\": \"IONiqV\", \"b\": \"XKbBiGZ\"}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"a\": \"9667771256770\", \"b\": \"50915176\"}}, {\"idx\": 5, \"outputs\": 11, \"inputs\": {\"a\": \"10001011\", \"b\": \"01\"}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"a\": \"fczbDtMDT\", \"b\": \"FbX\"}}, {\"idx\": 7, \"outputs\": 1, \"inputs\": {\"a\": \"298746088\", \"b\": \"29888\"}}, {\"idx\": 8, \"outputs\": 7, \"inputs\": {\"a\": \"01100011000\", \"b\": \"0\"}}, {\"idx\": 9, \"outputs\": 1, \"inputs\": {\"a\": \"Qk\", \"b\": \"\"}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
558
Write An Efficient Method To Check If A Number Is Multiple Of 3
C++
int writeAnEfficientMethodToCheckIfANumberIsMultipleOf3(int n) {
[ "n" ]
def write_an_efficient_method_to_check_if_a_number_is_multiple_of_3(n): odd_count = 0 even_count = 0 if (n < 0): n = (- n) if (n == 0): return 1 if (n == 1): return 0 while n: if (n & 1): odd_count += 1 if (n & 2): even_count += 1 n = (n >> 2) return write_an_efficient_method_to_check_if_a_number_is_multiple_of_3(abs((odd_count - even_count)))
int write_an_efficient_method_to_check_if_a_number_is_multiple_of_3(int n) { int odd_count = 0; int even_count = 0; if ( n < 0 ) n = - n; if ( n == 0 ) return 1; if ( n == 1 ) return 0; while ( n ) { if ( n & 1 ) odd_count ++; if ( n & 2 ) even_count ++; n = n >> 2; } return write_an_efficient_method_to_check_if_a_number_is_multiple_of_3 ( abs ( odd_count - even_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(94, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 0); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(79, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(39, 1); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(16, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(90, 1); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 0); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(76, 0); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(83, 0); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(47, 0); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "writeAnEfficientMethodToCheckIfANumberIsMultipleOf3", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": 94}}, {\"idx\": 1, \"outputs\": 0, \"inputs\": {\"n\": 94}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 79}}, {\"idx\": 3, \"outputs\": 1, \"inputs\": {\"n\": 39}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 16}}, {\"idx\": 5, \"outputs\": 1, \"inputs\": {\"n\": 90}}, {\"idx\": 6, \"outputs\": 0, \"inputs\": {\"n\": 64}}, {\"idx\": 7, \"outputs\": 0, \"inputs\": {\"n\": 76}}, {\"idx\": 8, \"outputs\": 0, \"inputs\": {\"n\": 83}}, {\"idx\": 9, \"outputs\": 0, \"inputs\": {\"n\": 47}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
559
Write A C Program To Find The Parity Of An Unsigned Integer
C++
int writeACProgramToFindTheParityOfAnUnsignedInteger(int n) {
[ "n" ]
def write_a_c_program_to_find_the_parity_of_an_unsigned_integer(n): parity = 0 while n: parity = (~ parity) n = (n & (n - 1)) return parity
bool write_a_c_program_to_find_the_parity_of_an_unsigned_integer(unsigned int n) { bool parity = 0; while ( n ) { parity = ! parity; n = n & ( n - 1 ); } return parity; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(63, 0); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, -1); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(85, 0); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(36, 0); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(20, 0); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(63, 0); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(42, -1); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(19, -1); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(62, -1); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(97, -1); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "writeACProgramToFindTheParityOfAnUnsignedInteger", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 0, \"inputs\": {\"n\": 63}}, {\"idx\": 1, \"outputs\": -1, \"inputs\": {\"n\": 64}}, {\"idx\": 2, \"outputs\": 0, \"inputs\": {\"n\": 85}}, {\"idx\": 3, \"outputs\": 0, \"inputs\": {\"n\": 36}}, {\"idx\": 4, \"outputs\": 0, \"inputs\": {\"n\": 20}}, {\"idx\": 5, \"outputs\": 0, \"inputs\": {\"n\": 63}}, {\"idx\": 6, \"outputs\": -1, \"inputs\": {\"n\": 42}}, {\"idx\": 7, \"outputs\": -1, \"inputs\": {\"n\": 19}}, {\"idx\": 8, \"outputs\": -1, \"inputs\": {\"n\": 62}}, {\"idx\": 9, \"outputs\": -1, \"inputs\": {\"n\": 97}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
560
Write One Line C Function To Find Whether A No Is Power Of Two
C++
bool writeOneLineCFunctionToFindWhetherANoIsPowerOfTwo(int n) {
[ "n" ]
def write_one_line_c_function_to_find_whether_a_no_is_power_of_two(n): if (n == 0): return False while (n != 1): if ((n % 2) != 0): return False n = (n // 2) return True
bool write_one_line_c_function_to_find_whether_a_no_is_power_of_two(int n) { if ( n == 0 ) return 0; while ( n != 1 ) { if ( n % 2 != 0 ) return 0; n = n / 2; } 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(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return \"PASSED\";\n }\n return \"FAILED\";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return \"UNK_ERROR\";\n }\n}\n\nint main() {\n string result = \"\";\n\n result = driver(1, true); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(2, true); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(8, true); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(1024, true); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(24, false); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(7, false); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(46, false); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(61, false); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(73, false); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(66, false); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "writeOneLineCFunctionToFindWhetherANoIsPowerOfTwo", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": true, \"inputs\": {\"n\": 1}}, {\"idx\": 1, \"outputs\": true, \"inputs\": {\"n\": 2}}, {\"idx\": 2, \"outputs\": true, \"inputs\": {\"n\": 8}}, {\"idx\": 3, \"outputs\": true, \"inputs\": {\"n\": 1024}}, {\"idx\": 4, \"outputs\": false, \"inputs\": {\"n\": 24}}, {\"idx\": 5, \"outputs\": false, \"inputs\": {\"n\": 7}}, {\"idx\": 6, \"outputs\": false, \"inputs\": {\"n\": 46}}, {\"idx\": 7, \"outputs\": false, \"inputs\": {\"n\": 61}}, {\"idx\": 8, \"outputs\": false, \"inputs\": {\"n\": 73}}, {\"idx\": 9, \"outputs\": false, \"inputs\": {\"n\": 66}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
561
Write You Own Power Without Using Multiplication And Division
C++
int writeYouOwnPowerWithoutUsingMultiplicationAndDivision(int a, int b) {
[ "a", "b" ]
def write_you_own_power_without_using_multiplication_and_division(a, b): if (b == 0): return 1 answer = a increment = a for i in range(1, b): for j in range(1, a): answer += increment increment = answer return answer
int write_you_own_power_without_using_multiplication_and_division(int a, int b) { if ( b == 0 ) return 1; int answer = a; int increment = a; int i, j; for ( i = 1; i < b; i ++ ) { for ( j = 1; j < a; j ++ ) { answer += increment; } increment = answer; } return answer; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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(66, 4, 18974736); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "writeYouOwnPowerWithoutUsingMultiplicationAndDivision", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 18974736, \"inputs\": {\"a\": 66, \"b\": 4}}]", "test_case_ids": [ "0" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }
562
Zeckendorfs Theorem Non Neighbouring Fibonacci Representation
C++
int zeckendorfsTheoremNonNeighbouringFibonacciRepresentation(int n) {
[ "n" ]
def zeckendorfs_theorem_non_neighbouring_fibonacci_representation(n): if ((n == 0) or (n == 1)): return n (f1, f2, f3) = (0, 1, 1) while (f3 <= n): f1 = f2 f2 = f3 f3 = (f1 + f2) return f2
int zeckendorfs_theorem_non_neighbouring_fibonacci_representation(int n) { if ( n == 0 || n == 1 ) return n; int f1 = 0, f2 = 1, f3 = 1; while ( f3 <= n ) { f1 = f2; f2 = f3; f3 = f1 + f2; } return f2; }
{ "test_code": "#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n\n// SOLUTION 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(54, 34); \n cout << \"TEST-\" << 0 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 55); \n cout << \"TEST-\" << 1 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(64, 55); \n cout << \"TEST-\" << 2 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(71, 55); \n cout << \"TEST-\" << 3 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(96, 89); \n cout << \"TEST-\" << 4 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(43, 34); \n cout << \"TEST-\" << 5 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(70, 55); \n cout << \"TEST-\" << 6 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(94, 89); \n cout << \"TEST-\" << 7 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(95, 89); \n cout << \"TEST-\" << 8 << \"...\"\n << result\n << \"\\n\";\n\n result = driver(69, 55); \n cout << \"TEST-\" << 9 << \"...\"\n << result\n << \"\\n\";\n\n return 0;\n}", "entry_fn_name": "zeckendorfsTheoremNonNeighbouringFibonacciRepresentation", "entry_cls_name": "Solution", "extension": "cpp", "test_list": "[{\"idx\": 0, \"outputs\": 34, \"inputs\": {\"n\": 54}}, {\"idx\": 1, \"outputs\": 55, \"inputs\": {\"n\": 71}}, {\"idx\": 2, \"outputs\": 55, \"inputs\": {\"n\": 64}}, {\"idx\": 3, \"outputs\": 55, \"inputs\": {\"n\": 71}}, {\"idx\": 4, \"outputs\": 89, \"inputs\": {\"n\": 96}}, {\"idx\": 5, \"outputs\": 34, \"inputs\": {\"n\": 43}}, {\"idx\": 6, \"outputs\": 55, \"inputs\": {\"n\": 70}}, {\"idx\": 7, \"outputs\": 89, \"inputs\": {\"n\": 94}}, {\"idx\": 8, \"outputs\": 89, \"inputs\": {\"n\": 95}}, {\"idx\": 9, \"outputs\": 55, \"inputs\": {\"n\": 69}}]", "test_case_ids": [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ], "commands": [ [ "g++", "__FILENAME__", "-o", "main.exe" ], [ "./main.exe" ] ], "timeouts": [ 10, 10 ] }