qid int64 602 974 | title stringclasses 332 values | language stringclasses 16 values | text stringlengths 38 251 | signature_with_docstring stringlengths 61 354 | signature stringlengths 8 162 | arguments stringclasses 150 values | solution stringclasses 332 values | question_info stringlengths 1.14k 4.26k |
|---|---|---|---|---|---|---|---|---|
602 | MBPP/602 | C++ | Write a c++ function to find the first repeated character in a given string. | /**
* Write a c++ function to find the first repeated character in a given string.
*/
string firstRepeatedChar(string str1) { | string firstRepeatedChar(string str1) { | ['str1'] | def first_repeated_char(str1):
for index,c in enumerate(str1):
if str1[:index+1].count(c) > 1:
return c
return "None" | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'firstRepeatedChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the first repeated character in a given string.\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 expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("abcabc", "a"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("abc", "None"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("123123", "1"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "a", "inputs": {"str1": "abcabc"}}, {"idx": 1, "outputs": "None", "inputs": {"str1": "abc"}}, {"idx": 2, "outputs": "1", "inputs": {"str1": "123123"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
603 | MBPP/603 | C++ | Write a function to get a lucid number smaller than or equal to n. | /**
* Write a function to get a lucid number smaller than or equal to n.
*/
vector<int> getLudic(int n) { | vector<int> getLudic(int n) { | ['n'] | def get_ludic(n):
ludics = []
for i in range(1, n + 1):
ludics.append(i)
index = 1
while(index != len(ludics)):
first_ludic = ludics[index]
remove_index = index + first_ludic
while(remove_index < len(ludics)):
ludics.remove(ludics[remove_index])
remove_index = remove_index + first_ludic - 1
index += 1
return ludics | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getLudic', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to get a lucid number smaller than or equal to n.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(int n, vector<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(10, {1, 2, 3, 5, 7}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(25, {1, 2, 3, 5, 7, 11, 13, 17, 23, 25}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(45, {1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 2, 3, 5, 7], "inputs": {"n": 10}}, {"idx": 1, "outputs": [1, 2, 3, 5, 7, 11, 13, 17, 23, 25], "inputs": {"n": 25}}, {"idx": 2, "outputs": [1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43], "inputs": {"n": 45}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
604 | MBPP/604 | C++ | Write a function to reverse words in a given string. | /**
* Write a function to reverse words in a given string.
*/
string reverseWords(string s) { | string reverseWords(string s) { | ['s'] | def reverse_words(s):
return ' '.join(reversed(s.split())) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'reverseWords', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to reverse words in a given string.\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("python program", "program python"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("java language", "language java"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("indian man", "man indian"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "program python", "inputs": {"s": "python program"}}, {"idx": 1, "outputs": "language java", "inputs": {"s": "java language"}}, {"idx": 2, "outputs": "man indian", "inputs": {"s": "indian man"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
605 | MBPP/605 | C++ | Write a function to check if the given integer is a prime number. | /**
* Write a function to check if the given integer is a prime number.
*/
bool primeNum(int num) { | bool primeNum(int num) { | ['num'] | def prime_num(num):
if num >=1:
for i in range(2, num//2):
if (num % i) == 0:
return False
else:
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'primeNum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check if the given integer is a prime number.\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(13, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(7, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(-1010, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"num": 13}}, {"idx": 1, "outputs": true, "inputs": {"num": 7}}, {"idx": 2, "outputs": false, "inputs": {"num": -1010}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
606 | MBPP/606 | C++ | Write a function to convert degrees to radians. | /**
* Write a function to convert degrees to radians.
*/
double radianDegree(int degree) { | double radianDegree(int degree) { | ['degree'] | import math
def radian_degree(degree):
radian = degree*(math.pi/180)
return radian | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'radianDegree', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to convert degrees to radians.\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 degree, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(degree), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 1.5707963267948966); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(60, 1.0471975511965976); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(120, 2.0943951023931953); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 1.5707963267948966, "inputs": {"degree": 90}}, {"idx": 1, "outputs": 1.0471975511965976, "inputs": {"degree": 60}}, {"idx": 2, "outputs": 2.0943951023931953, "inputs": {"degree": 120}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
608 | MBPP/608 | C++ | Write a c++ function to find nth bell number. | /**
* Write a c++ function to find nth bell number.
*/
int bellNumber(int n) { | int bellNumber(int n) { | ['n'] | def bell_Number(n):
bell = [[0 for i in range(n+1)] for j in range(n+1)]
bell[0][0] = 1
for i in range(1, n+1):
bell[i][0] = bell[i-1][i-1]
for j in range(1, i+1):
bell[i][j] = bell[i-1][j-1] + bell[i][j-1]
return bell[n][0] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'bellNumber', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find nth bell number.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(4, 15); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"n": 2}}, {"idx": 1, "outputs": 5, "inputs": {"n": 3}}, {"idx": 2, "outputs": 15, "inputs": {"n": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
609 | MBPP/609 | C++ | Write a c++ function to find minimum possible value for the given periodic function. | /**
* Write a c++ function to find minimum possible value for the given periodic function.
*/
int floorMin(int a, int b, int n) { | int floorMin(int a, int b, int n) { | ['a', 'b', 'n'] | def floor_Min(A,B,N):
x = max(B - 1,N)
return (A*x) // B | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'floorMin', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find minimum possible value for the given periodic function.\n//\n// SOLUTION 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 n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(10, 20, 30, 15); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(1, 2, 1, 0); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(11, 10, 9, 9); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 15, "inputs": {"a": 10, "b": 20, "n": 30}}, {"idx": 1, "outputs": 0, "inputs": {"a": 1, "b": 2, "n": 1}}, {"idx": 2, "outputs": 9, "inputs": {"a": 11, "b": 10, "n": 9}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
610 | MBPP/610 | C++ | Write a c++ function to remove the k'th element from a given vector. | /**
* Write a c++ function to remove the k'th element from a given vector.
*/
vector<int> removeKthElement(vector<int> list1, int l) { | vector<int> removeKthElement(vector<int> list1, int l) { | ['list1', 'l'] | def remove_kth_element(list1, L):
return list1[:L-1] + list1[L:] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeKthElement', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to remove the k\'th element from a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> list1, int l, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(list1, l), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 1, 2, 3, 4, 4, 5, 1}, 3, {1, 1, 3, 4, 4, 5, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4}, 4, {0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10}, 5, {10, 10, 15, 19, 18, 17, 26, 26, 17, 18, 10}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 1, 3, 4, 4, 5, 1], "inputs": {"list1": [1, 1, 2, 3, 4, 4, 5, 1], "l": 3}}, {"idx": 1, "outputs": [0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4], "inputs": {"list1": [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4], "l": 4}}, {"idx": 2, "outputs": [10, 10, 15, 19, 18, 17, 26, 26, 17, 18, 10], "inputs": {"list1": [10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10], "l": 5}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
611 | MBPP/611 | C++ | Write a function to find the maximum of nth column from the given tuple vector. | /**
* Write a function to find the maximum of nth column from the given tuple vector.
*/
int maxOfNth(vector<vector<int>> test_list, int n) { | int maxOfNth(vector<vector<int>> test_list, int n) { | ['test_list', 'n'] | def max_of_nth(test_list, N):
res = max([sub[N] for sub in test_list])
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOfNth', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the maximum of nth column from the given tuple list.\n//\n// SOLUTION 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<vector<int>> test_list, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list, 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, 7}, {1, 3, 5}, {8, 9, 19}}, 2, 19); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{6, 7, 8}, {2, 4, 6}, {9, 10, 20}}, 1, 10); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{7, 8, 9}, {3, 5, 7}, {10, 11, 21}}, 1, 11); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 19, "inputs": {"test_list": [[5, 6, 7], [1, 3, 5], [8, 9, 19]], "n": 2}}, {"idx": 1, "outputs": 10, "inputs": {"test_list": [[6, 7, 8], [2, 4, 6], [9, 10, 20]], "n": 1}}, {"idx": 2, "outputs": 11, "inputs": {"test_list": [[7, 8, 9], [3, 5, 7], [10, 11, 21]], "n": 1}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
614 | MBPP/614 | C++ | Write a function to find the cumulative sum of all the values that are present in the given tuple vector. | /**
* Write a function to find the cumulative sum of all the values that are present in the given tuple vector.
*/
int cummulativeSum(vector<vector<int>> test_list) { | int cummulativeSum(vector<vector<int>> test_list) { | ['test_list'] | def cummulative_sum(test_list):
res = sum(map(sum, test_list))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'cummulativeSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the cumulative sum of all the values that are present in the given tuple list.\n//\n// SOLUTION 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<vector<int>> test_list, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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}, {5, 6, 7}, {2, 6}}, 30); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{2, 4}, {6, 7, 8}, {3, 7}}, 37); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{3, 5}, {7, 8, 9}, {4, 8}}, 44); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 30, "inputs": {"test_list": [[1, 3], [5, 6, 7], [2, 6]]}}, {"idx": 1, "outputs": 37, "inputs": {"test_list": [[2, 4], [6, 7, 8], [3, 7]]}}, {"idx": 2, "outputs": 44, "inputs": {"test_list": [[3, 5], [7, 8, 9], [4, 8]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
615 | MBPP/615 | C++ | Write a function to find average value of the numbers in a given tuple of tuples. | /**
* Write a function to find average value of the numbers in a given tuple of tuples.
*/
vector<float> averageTuple(vector<vector<int>> nums) { | vector<float> averageTuple(vector<vector<int>> nums) { | ['nums'] | def average_tuple(nums):
result = [sum(x) / len(x) for x in zip(*nums)]
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'averageTuple', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find average value of the numbers in a given tuple of tuples.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<float> actual, vector<float> expected){\n return actual == expected;\n}\n\nstring driver(vector<vector<int>> nums, vector<float> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 10, 10, 12}, {30, 45, 56, 45}, {81, 80, 39, 32}, {1, 2, 3, 4}}, {30.5, 34.25, 27.0, 23.25}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{1, 1, -5}, {30, -15, 56}, {81, -60, -39}, {-10, 2, 3}}, {25.5, -18.0, 3.75}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{100, 100, 100, 120}, {300, 450, 560, 450}, {810, 800, 390, 320}, {10, 20, 30, 40}}, {305.0, 342.5, 270.0, 232.5}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [30.5, 34.25, 27.0, 23.25], "inputs": {"nums": [[10, 10, 10, 12], [30, 45, 56, 45], [81, 80, 39, 32], [1, 2, 3, 4]]}}, {"idx": 1, "outputs": [25.5, -18.0, 3.75], "inputs": {"nums": [[1, 1, -5], [30, -15, 56], [81, -60, -39], [-10, 2, 3]]}}, {"idx": 2, "outputs": [305.0, 342.5, 270.0, 232.5], "inputs": {"nums": [[100, 100, 100, 120], [300, 450, 560, 450], [810, 800, 390, 320], [10, 20, 30, 40]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
616 | MBPP/616 | C++ | Write a function to perfom the modulo of tuple elements in the given two tuples. | /**
* Write a function to perfom the modulo of tuple elements in the given two tuples.
*/
vector<int> tupleModulo(vector<int> test_tup1, vector<int> test_tup2) { | vector<int> tupleModulo(vector<int> test_tup1, vector<int> test_tup2) { | ['test_tup1', 'test_tup2'] | def tuple_modulo(test_tup1, test_tup2):
res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'tupleModulo', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to perfom the modulo of tuple elements in the given two tuples.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> test_tup1, vector<int> test_tup2, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup1, test_tup2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({10, 4, 5, 6}, {5, 6, 7, 5}, {0, 4, 5, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({11, 5, 6, 7}, {6, 7, 8, 6}, {5, 5, 6, 1}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({12, 6, 7, 8}, {7, 8, 9, 7}, {5, 6, 7, 1}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [0, 4, 5, 1], "inputs": {"test_tup1": [10, 4, 5, 6], "test_tup2": [5, 6, 7, 5]}}, {"idx": 1, "outputs": [5, 5, 6, 1], "inputs": {"test_tup1": [11, 5, 6, 7], "test_tup2": [6, 7, 8, 6]}}, {"idx": 2, "outputs": [5, 6, 7, 1], "inputs": {"test_tup1": [12, 6, 7, 8], "test_tup2": [7, 8, 9, 7]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
617 | MBPP/617 | C++ | Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane. | /**
* Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.
*/
float minJumps(int a, int b, int d) { | float minJumps(int a, int b, int d) { | ['a', 'b', 'd'] | def min_Jumps(a, b, d):
temp = a
a = min(a, b)
b = max(temp, b)
if (d >= b):
return (d + b - 1) / b
if (d == 0):
return 0
if (d == a):
return 1
else:
return 2 | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'minJumps', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.\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 a, int b, int d, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, d), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(3, 4, 11, 3.5); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 4, 0, 0.0); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(11, 14, 11, 1.0); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 3.5, "inputs": {"a": 3, "b": 4, "d": 11}}, {"idx": 1, "outputs": 0, "inputs": {"a": 3, "b": 4, "d": 0}}, {"idx": 2, "outputs": 1, "inputs": {"a": 11, "b": 14, "d": 11}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
618 | MBPP/618 | C++ | Write a function to divide two vectors using map and lambda function. | /**
* Write a function to divide two vectors using map and lambda function.
*/
vector<double> divList(vector<int> nums1, vector<int> nums2) { | vector<double> divList(vector<int> nums1, vector<int> nums2) { | ['nums1', 'nums2'] | def div_list(nums1,nums2):
result = map(lambda x, y: x / y, nums1, nums2)
return list(result) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'divList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to divide two lists using map and lambda function.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<double> actual, vector<double> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums1, vector<int> nums2, vector<double> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums1, nums2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 6}, {1, 2, 3}, {4.0, 2.5, 2.0}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({3, 2}, {1, 4}, {3.0, 0.5}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({90, 120}, {50, 70}, {1.8, 1.7142857142857142}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [4.0, 2.5, 2.0], "inputs": {"nums1": [4, 5, 6], "nums2": [1, 2, 3]}}, {"idx": 1, "outputs": [3.0, 0.5], "inputs": {"nums1": [3, 2], "nums2": [1, 4]}}, {"idx": 2, "outputs": [1.8, 1.7142857142857142], "inputs": {"nums1": [90, 120], "nums2": [50, 70]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
619 | MBPP/619 | C++ | Write a function to move all the numbers in it to the given string. | /**
* Write a function to move all the numbers in it to the given string.
*/
string moveNum(string test_str) { | string moveNum(string test_str) { | ['test_str'] | def move_num(test_str):
res = ''
dig = ''
for ele in test_str:
if ele.isdigit():
dig += ele
else:
res += ele
res += dig
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveNum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to move all the numbers in it to the given string.\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 test_str, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_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("I1love143you55three3000thousand", "Iloveyouthreethousand1143553000"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("Avengers124Assemble", "AvengersAssemble124"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Its11our12path13to14see15things16do17things", "Itsourpathtoseethingsdothings11121314151617"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Iloveyouthreethousand1143553000", "inputs": {"test_str": "I1love143you55three3000thousand"}}, {"idx": 1, "outputs": "AvengersAssemble124", "inputs": {"test_str": "Avengers124Assemble"}}, {"idx": 2, "outputs": "Itsourpathtoseethingsdothings11121314151617", "inputs": {"test_str": "Its11our12path13to14see15things16do17things"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
620 | MBPP/620 | C++ | Write a function to find the largest subset where each pair is divisible. | /**
* Write a function to find the largest subset where each pair is divisible.
*/
int largestSubset(vector<int> a, int n) { | int largestSubset(vector<int> a, int n) { | ['a', 'n'] | def largest_subset(a, n):
dp = [0 for i in range(n)]
dp[n - 1] = 1;
for i in range(n - 2, -1, -1):
mxm = 0;
for j in range(i + 1, n):
if a[j] % a[i] == 0 or a[i] % a[j] == 0:
mxm = max(mxm, dp[j])
dp[i] = 1 + mxm
return max(dp) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'largestSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the largest subset where each pair is divisible.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 3, 6, 13, 17, 18}, 6, 4); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({10, 5, 3, 15, 20}, 5, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({18, 1, 3, 6, 13, 17}, 6, 4); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 4, "inputs": {"a": [1, 3, 6, 13, 17, 18], "n": 6}}, {"idx": 1, "outputs": 3, "inputs": {"a": [10, 5, 3, 15, 20], "n": 5}}, {"idx": 2, "outputs": 4, "inputs": {"a": [18, 1, 3, 6, 13, 17], "n": 6}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
621 | MBPP/621 | C++ | Write a function to increment the numeric values in the given strings by k. | /**
* Write a function to increment the numeric values in the given strings by k.
*/
vector<string> incrementNumerics(vector<string> test_list, int k) { | vector<string> incrementNumerics(vector<string> test_list, int k) { | ['test_list', 'k'] | def increment_numerics(test_list, K):
res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list]
return res | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'incrementNumerics', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to increment the numeric values in the given strings by k.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<string> actual, vector<string> expected){\n return actual == expected;\n}\n\nstring driver(vector<string> test_list, int k, vector<string> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list, 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({"MSM", "234", "is", "98", "123", "best", "4"}, 6, {"MSM", "240", "is", "104", "129", "best", "10"}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({"Dart", "356", "is", "88", "169", "Super", "6"}, 12, {"Dart", "368", "is", "100", "181", "Super", "18"}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({"Flutter", "451", "is", "44", "96", "Magnificent", "12"}, 33, {"Flutter", "484", "is", "77", "129", "Magnificent", "45"}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": ["MSM", "240", "is", "104", "129", "best", "10"], "inputs": {"test_list": ["MSM", "234", "is", "98", "123", "best", "4"], "k": 6}}, {"idx": 1, "outputs": ["Dart", "368", "is", "100", "181", "Super", "18"], "inputs": {"test_list": ["Dart", "356", "is", "88", "169", "Super", "6"], "k": 12}}, {"idx": 2, "outputs": ["Flutter", "484", "is", "77", "129", "Magnificent", "45"], "inputs": {"test_list": ["Flutter", "451", "is", "44", "96", "Magnificent", "12"], "k": 33}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
622 | MBPP/622 | C++ | Write a function to find the median of two sorted vectors of same size. | /**
* Write a function to find the median of two sorted vectors of same size.
*/
float getMedian(vector<int> arr1, vector<int> arr2, int n) { | float getMedian(vector<int> arr1, vector<int> arr2, int n) { | ['arr1', 'arr2', 'n'] | def get_median(arr1, arr2, n):
i = 0
j = 0
m1 = -1
m2 = -1
count = 0
while count < n + 1:
count += 1
if i == n:
m1 = m2
m2 = arr2[0]
break
elif j == n:
m1 = m2
m2 = arr1[0]
break
if arr1[i] <= arr2[j]:
m1 = m2
m2 = arr1[i]
i += 1
else:
m1 = m2
m2 = arr2[j]
j += 1
return (m1 + m2)/2 | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getMedian', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the median of two sorted arrays of same size.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int n, float 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, 12, 15, 26, 38}, {2, 13, 17, 30, 45}, 5, 16.0); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({2, 4, 8, 9}, {7, 13, 19, 28}, 4, 8.5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({3, 6, 14, 23, 36, 42}, {2, 18, 27, 39, 49, 55}, 6, 25.0); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 16.0, "inputs": {"arr1": [1, 12, 15, 26, 38], "arr2": [2, 13, 17, 30, 45], "n": 5}}, {"idx": 1, "outputs": 8.5, "inputs": {"arr1": [2, 4, 8, 9], "arr2": [7, 13, 19, 28], "n": 4}}, {"idx": 2, "outputs": 25.0, "inputs": {"arr1": [3, 6, 14, 23, 36, 42], "arr2": [2, 18, 27, 39, 49, 55], "n": 6}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
623 | MBPP/623 | C++ | Write a function to find the n-th power of individual elements in vector using lambda function. | /**
* Write a function to find the n-th power of individual elements in vector using lambda function.
*/
vector<int> nthNums(vector<int> nums, int n) { | vector<int> nthNums(vector<int> nums, int n) { | ['nums', 'n'] | def nth_nums(nums,n):
nth_nums = list(map(lambda x: x ** n, nums))
return nth_nums | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'nthNums', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the n-th power of individual elements in a list using lambda function.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums, int n, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 2, {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({10, 20, 30}, 3, {1000, 8000, 27000}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({12, 15}, 5, {248832, 759375}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 4, 9, 16, 25, 36, 49, 64, 81, 100], "inputs": {"nums": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "n": 2}}, {"idx": 1, "outputs": [1000, 8000, 27000], "inputs": {"nums": [10, 20, 30], "n": 3}}, {"idx": 2, "outputs": [248832, 759375], "inputs": {"nums": [12, 15], "n": 5}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
624 | MBPP/624 | C++ | Write a c++ function to convert the given string to upper case. | /**
* Write a c++ function to convert the given string to upper case.
*/
string isUpper(string string_arg0) { | string isUpper(string string_arg0) { | ['string_arg0'] | def is_upper(string):
return (string.upper()) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isUpper', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to convert the given string to upper case.\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 string_arg0, string 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("person", "PERSON"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("final", "FINAL"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Valid", "VALID"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "PERSON", "inputs": {"string_arg0": "person"}}, {"idx": 1, "outputs": "FINAL", "inputs": {"string_arg0": "final"}}, {"idx": 2, "outputs": "VALID", "inputs": {"string_arg0": "Valid"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
625 | MBPP/625 | C++ | Write a c++ function to interchange first and last elements in a given vector. | /**
* Write a c++ function to interchange first and last elements in a given vector.
*/
vector<int> swapList(vector<int> newlist) { | vector<int> swapList(vector<int> newlist) { | ['newlist'] | def swap_List(newList):
size = len(newList)
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'swapList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to interchange first and last elements in a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> newlist, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(newlist), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3}, {3, 2, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 4}, {4, 2, 3, 4, 1}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6}, {6, 5, 4}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [3, 2, 1], "inputs": {"newlist": [1, 2, 3]}}, {"idx": 1, "outputs": [4, 2, 3, 4, 1], "inputs": {"newlist": [1, 2, 3, 4, 4]}}, {"idx": 2, "outputs": [6, 5, 4], "inputs": {"newlist": [4, 5, 6]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
626 | MBPP/626 | C++ | Write a c++ function to find the largest triangle that can be inscribed in the semicircle. | /**
* Write a c++ function to find the largest triangle that can be inscribed in the semicircle.
*/
int triangleArea(int r) { | int triangleArea(int r) { | ['r'] | def triangle_area(r) :
if r < 0 :
return -1
return r * r | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'triangleArea', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the largest triangle that can be inscribed in the semicircle.\n//\n// SOLUTION 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 r, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(r), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(0, 0); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(-1, -1); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(2, 4); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 0, "inputs": {"r": 0}}, {"idx": 1, "outputs": -1, "inputs": {"r": -1}}, {"idx": 2, "outputs": 4, "inputs": {"r": 2}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
627 | MBPP/627 | C++ | Write a c++ function to find the smallest missing number from the given vector. | /**
* Write a c++ function to find the smallest missing number from the given vector.
*/
int findFirstMissing(vector<int> array, int start, int end_arg2) { | int findFirstMissing(vector<int> array, int start, int end_arg2) { | ['array', 'start', 'end_arg2'] | def find_First_Missing(array,start,end):
if (start > end):
return end + 1
if (start != array[start]):
return start;
mid = int((start + end) / 2)
if (array[mid] == mid):
return find_First_Missing(array,mid+1,end)
return find_First_Missing(array,start,mid) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findFirstMissing', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the smallest missing number from the given array.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> array, int start, int end_arg2, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(array, start, end_arg2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({0, 1, 2, 3}, 0, 3, 4); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({0, 1, 2, 6, 9}, 0, 4, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({2, 3, 5, 8, 9}, 0, 4, 0); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 4, "inputs": {"array": [0, 1, 2, 3], "start": 0, "end_arg2": 3}}, {"idx": 1, "outputs": 3, "inputs": {"array": [0, 1, 2, 6, 9], "start": 0, "end_arg2": 4}}, {"idx": 2, "outputs": 0, "inputs": {"array": [2, 3, 5, 8, 9], "start": 0, "end_arg2": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
628 | MBPP/628 | C++ | Write a function to replace all spaces in the given string with character * vector item * vector item * vector item * vector item '%20'. | /**
* Write a function to replace all spaces in the given string with character * vector item * vector item * vector item * vector item '%20'.
*/
string replaceSpaces(string string_arg0) { | string replaceSpaces(string string_arg0) { | ['string_arg0'] | MAX=1000;
def replace_spaces(string):
string=string.strip()
i=len(string)
space_count=string.count(' ')
new_length = i + space_count*2
if new_length > MAX:
return -1
index = new_length-1
string=list(string)
for f in range(i-2, new_length-2):
string.append('0')
for j in range(i-1, 0, -1):
if string[j] == ' ':
string[index] = '0'
string[index-1] = '2'
string[index-2] = '%'
index=index-3
else:
string[index] = string[j]
index -= 1
return ''.join(string) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replaceSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to replace all spaces in the given string with character * list item * list item * list item * list item \'%20\'.\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 string_arg0, string 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("My Name is Dawood", "My%20Name%20is%20Dawood"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("I am a Programmer", "I%20am%20a%20Programmer"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("I love Coding", "I%20love%20Coding"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "My%20Name%20is%20Dawood", "inputs": {"string_arg0": "My Name is Dawood"}}, {"idx": 1, "outputs": "I%20am%20a%20Programmer", "inputs": {"string_arg0": "I am a Programmer"}}, {"idx": 2, "outputs": "I%20love%20Coding", "inputs": {"string_arg0": "I love Coding"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
629 | MBPP/629 | C++ | Write a c++ function to find even numbers from a mixed vector. | /**
* Write a c++ function to find even numbers from a mixed vector.
*/
vector<int> split(vector<int> list) { | vector<int> split(vector<int> list) { | ['list'] | def Split(list):
ev_li = []
for i in list:
if (i % 2 == 0):
ev_li.append(i)
return ev_li | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'split', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find even numbers from a mixed list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> list, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4, 5}, {2, 4}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6, 7, 8, 0, 1}, {4, 6, 8, 0}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({8, 12, 15, 19}, {8, 12}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [2, 4], "inputs": {"list": [1, 2, 3, 4, 5]}}, {"idx": 1, "outputs": [4, 6, 8, 0], "inputs": {"list": [4, 5, 6, 7, 8, 0, 1]}}, {"idx": 2, "outputs": [8, 12], "inputs": {"list": [8, 12, 15, 19]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
630 | MBPP/630 | C++ | Write a function to extract all the adjacent coordinates of the given coordinate tuple. | /**
* Write a function to extract all the adjacent coordinates of the given coordinate tuple.
*/
vector<vector<int>> getCoordinates(vector<int> test_tup) { | vector<vector<int>> getCoordinates(vector<int> test_tup) { | ['test_tup'] | def adjac(ele, sub = []):
if not ele:
yield sub
else:
yield from [idx for j in range(ele[0] - 1, ele[0] + 2)
for idx in adjac(ele[1:], sub + [j])]
def get_coordinates(test_tup):
res = list(adjac(test_tup))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getCoordinates', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to extract all the adjacent coordinates of the given coordinate tuple.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<vector<int>> actual, vector<vector<int>> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> test_tup, vector<vector<int>> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({3, 4}, {{2, 3}, {2, 4}, {2, 5}, {3, 3}, {3, 4}, {3, 5}, {4, 3}, {4, 4}, {4, 5}}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5}, {{3, 4}, {3, 5}, {3, 6}, {4, 4}, {4, 5}, {4, 6}, {5, 4}, {5, 5}, {5, 6}}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({5, 6}, {{4, 5}, {4, 6}, {4, 7}, {5, 5}, {5, 6}, {5, 7}, {6, 5}, {6, 6}, {6, 7}}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]], "inputs": {"test_tup": [3, 4]}}, {"idx": 1, "outputs": [[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]], "inputs": {"test_tup": [4, 5]}}, {"idx": 2, "outputs": [[4, 5], [4, 6], [4, 7], [5, 5], [5, 6], [5, 7], [6, 5], [6, 6], [6, 7]], "inputs": {"test_tup": [5, 6]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
631 | MBPP/631 | C++ | Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex. | /**
* Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.
*/
string replaceSpaces(string text) { | string replaceSpaces(string text) { | ['text'] | import re
text = 'Python Exercises'
def replace_spaces(text):
text =text.replace (" ", "_")
return (text)
text =text.replace ("_", " ")
return (text) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replaceSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.\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 text, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("Jumanji The Jungle", "Jumanji_The_Jungle"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("The Avengers", "The_Avengers"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Fast and Furious", "Fast_and_Furious"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Jumanji_The_Jungle", "inputs": {"text": "Jumanji The Jungle"}}, {"idx": 1, "outputs": "The_Avengers", "inputs": {"text": "The Avengers"}}, {"idx": 2, "outputs": "Fast_and_Furious", "inputs": {"text": "Fast and Furious"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
632 | MBPP/632 | C++ | Write a c++ function to move all zeroes to the end of the given vector. | /**
* Write a c++ function to move all zeroes to the end of the given vector.
*/
vector<int> moveZero(vector<int> num_list) { | vector<int> moveZero(vector<int> num_list) { | ['num_list'] | def move_zero(num_list):
a = [0 for i in range(num_list.count(0))]
x = [ i for i in num_list if i != 0]
x.extend(a)
return (x) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveZero', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to move all zeroes to the end of the given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> num_list, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 0, 2, 0, 3, 4}, {1, 2, 3, 4, 0, 0}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({2, 3, 2, 0, 0, 4, 0, 5, 0}, {2, 3, 2, 4, 5, 0, 0, 0, 0}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({0, 1, 0, 1, 1}, {1, 1, 1, 0, 0}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 2, 3, 4, 0, 0], "inputs": {"num_list": [1, 0, 2, 0, 3, 4]}}, {"idx": 1, "outputs": [2, 3, 2, 4, 5, 0, 0, 0, 0], "inputs": {"num_list": [2, 3, 2, 0, 0, 4, 0, 5, 0]}}, {"idx": 2, "outputs": [1, 1, 1, 0, 0], "inputs": {"num_list": [0, 1, 0, 1, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
633 | MBPP/633 | C++ | Write a c++ function to find the sum of xor of all pairs of numbers in the given vector. | /**
* Write a c++ function to find the sum of xor of all pairs of numbers in the given vector.
*/
int pairOrSum(vector<int> arr, int n) { | int pairOrSum(vector<int> arr, int n) { | ['arr', 'n'] | def pair_OR_Sum(arr,n) :
ans = 0
for i in range(0,n) :
for j in range(i + 1,n) :
ans = ans + (arr[i] ^ arr[j])
return ans | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'pairOrSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the sum of xor of all pairs of numbers in the given array.\n//\n// SOLUTION 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, 9, 7, 6}, 4, 47); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({7, 3, 5}, 3, 12); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({7, 3}, 2, 4); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 47, "inputs": {"arr": [5, 9, 7, 6], "n": 4}}, {"idx": 1, "outputs": 12, "inputs": {"arr": [7, 3, 5], "n": 3}}, {"idx": 2, "outputs": 4, "inputs": {"arr": [7, 3], "n": 2}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
634 | MBPP/634 | C++ | Write a c++ function to find the sum of fourth power of first n even natural numbers. | /**
* Write a c++ function to find the sum of fourth power of first n even natural numbers.
*/
int evenPowerSum(int n) { | int evenPowerSum(int n) { | ['n'] | def even_Power_Sum(n):
sum = 0;
for i in range(1,n + 1):
j = 2*i;
sum = sum + (j*j*j*j);
return sum; | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'evenPowerSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the sum of fourth power of first n even natural numbers.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 272); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 1568); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(4, 5664); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 272, "inputs": {"n": 2}}, {"idx": 1, "outputs": 1568, "inputs": {"n": 3}}, {"idx": 2, "outputs": 5664, "inputs": {"n": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
635 | MBPP/635 | C++ | Write a function to push all values into a heap and then pop off the smallest values one at a time. | /**
* Write a function to push all values into a heap and then pop off the smallest values one at a time.
*/
vector<int> heapSort(vector<int> iterable) { | vector<int> heapSort(vector<int> iterable) { | ['iterable'] | import heapq as hq
def heap_sort(iterable):
h = []
for value in iterable:
hq.heappush(h, value)
return [hq.heappop(h) for i in range(len(h))] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'heapSort', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to push all values into a heap and then pop off the smallest values one at a time.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> iterable, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(iterable), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 5, 7, 9, 2, 4, 6, 8, 0}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({25, 35, 22, 85, 14, 65, 75, 25, 58}, {14, 22, 25, 25, 35, 58, 65, 75, 85}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({7, 1, 9, 5}, {1, 5, 7, 9}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "inputs": {"iterable": [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]}}, {"idx": 1, "outputs": [14, 22, 25, 25, 35, 58, 65, 75, 85], "inputs": {"iterable": [25, 35, 22, 85, 14, 65, 75, 25, 58]}}, {"idx": 2, "outputs": [1, 5, 7, 9], "inputs": {"iterable": [7, 1, 9, 5]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
636 | MBPP/636 | C++ | Write a c++ function to check if roots of a quadratic equation are reciprocal of each other or not. | /**
* Write a c++ function to check if roots of a quadratic equation are reciprocal of each other or not.
*/
string checkSolution(int a, int b, int c) { | string checkSolution(int a, int b, int c) { | ['a', 'b', 'c'] | def Check_Solution(a,b,c):
if (a == c):
return ("Yes");
else:
return ("No"); | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkSolution', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check if roots of a quadratic equation are reciprocal of each other or not.\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 a, int b, int c, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 0, 2, "Yes"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(2, -5, 2, "Yes"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(1, 2, 3, "No"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Yes", "inputs": {"a": 2, "b": 0, "c": 2}}, {"idx": 1, "outputs": "Yes", "inputs": {"a": 2, "b": -5, "c": 2}}, {"idx": 2, "outputs": "No", "inputs": {"a": 1, "b": 2, "c": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
637 | MBPP/637 | C++ | Write a function to check whether the given amount has no profit and no loss | /**
* Write a function to check whether the given amount has no profit and no loss
*/
bool noprofitNoloss(int actual_cost, int sale_amount) { | bool noprofitNoloss(int actual_cost, int sale_amount) { | ['actual_cost', 'sale_amount'] | def noprofit_noloss(actual_cost,sale_amount):
if(sale_amount == actual_cost):
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'noprofitNoloss', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check whether the given amount has no profit and no loss\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 actual_cost, int sale_amount, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(actual_cost, sale_amount), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(1500, 1200, false); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(100, 100, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(2000, 5000, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": false, "inputs": {"actual_cost": 1500, "sale_amount": 1200}}, {"idx": 1, "outputs": true, "inputs": {"actual_cost": 100, "sale_amount": 100}}, {"idx": 2, "outputs": false, "inputs": {"actual_cost": 2000, "sale_amount": 5000}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
638 | MBPP/638 | C++ | Write a function to calculate wind chill index. | /**
* Write a function to calculate wind chill index.
*/
int windChill(int v, int t) { | int windChill(int v, int t) { | ['v', 't'] | import math
def wind_chill(v,t):
windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16)
return int(round(windchill, 0)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'windChill', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to calculate wind chill index.\n//\n// SOLUTION 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 v, int t, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(v, t), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(120, 35, 40); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(40, 70, 86); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(10, 100, 116); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 40, "inputs": {"v": 120, "t": 35}}, {"idx": 1, "outputs": 86, "inputs": {"v": 40, "t": 70}}, {"idx": 2, "outputs": 116, "inputs": {"v": 10, "t": 100}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
639 | MBPP/639 | C++ | Write a function to sum the length of the names of a given vector of names after removing the names that start with a lowercase letter. | /**
* Write a function to sum the length of the names of a given vector of names after removing the names that start with a lowercase letter.
*/
int sampleNam(vector<string> sample_names) { | int sampleNam(vector<string> sample_names) { | ['sample_names'] | def sample_nam(sample_names):
sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names))
return len(''.join(sample_names)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sampleNam', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.\n//\n// SOLUTION 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> sample_names, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(sample_names), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({"sally", "Dylan", "rebecca", "Diana", "Joanne", "keith"}, 16); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({"php", "res", "Python", "abcd", "Java", "aaa"}, 10); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({"abcd", "Python", "abba", "aba"}, 6); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 16, "inputs": {"sample_names": ["sally", "Dylan", "rebecca", "Diana", "Joanne", "keith"]}}, {"idx": 1, "outputs": 10, "inputs": {"sample_names": ["php", "res", "Python", "abcd", "Java", "aaa"]}}, {"idx": 2, "outputs": 6, "inputs": {"sample_names": ["abcd", "Python", "abba", "aba"]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
640 | MBPP/640 | C++ | Write a function to remove the parenthesis area in a string. | /**
* Write a function to remove the parenthesis area in a string.
*/
string removeParenthesis(vector<string> items) { | string removeParenthesis(vector<string> items) { | ['items'] | import re
def remove_parenthesis(items):
for item in items:
return (re.sub(r" ?\([^)]+\)", "", item)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeParenthesis', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to remove the parenthesis area in a string.\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(vector<string> items, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(items), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({"python (chrome)"}, "python"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({"string(.abc)"}, "string"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({"alpha(num)"}, "alpha"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "python", "inputs": {"items": ["python (chrome)"]}}, {"idx": 1, "outputs": "string", "inputs": {"items": ["string(.abc)"]}}, {"idx": 2, "outputs": "alpha", "inputs": {"items": ["alpha(num)"]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
641 | MBPP/641 | C++ | Write a function to find the nth nonagonal number. | /**
* Write a function to find the nth nonagonal number.
*/
int isNonagonal(int n) { | int isNonagonal(int n) { | ['n'] | def is_nonagonal(n):
return int(n * (7 * n - 5) / 2) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isNonagonal', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the nth nonagonal number.\n//\n// SOLUTION 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(10, 325); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(15, 750); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(18, 1089); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 325, "inputs": {"n": 10}}, {"idx": 1, "outputs": 750, "inputs": {"n": 15}}, {"idx": 2, "outputs": 1089, "inputs": {"n": 18}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
643 | MBPP/643 | C++ | Write a function that matches a word containing 'z', not at the start or end of the word. | /**
* Write a function that matches a word containing 'z', not at the start or end of the word.
*/
string textMatchWordzMiddle(string text) { | string textMatchWordzMiddle(string text) { | ['text'] | import re
def text_match_wordz_middle(text):
patterns = '\Bz\B'
if re.search(patterns, text):
return 'Found a match!'
else:
return('Not matched!') | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'textMatchWordzMiddle', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function that matches a word containing \'z\', not at the start or end of the word.\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 text, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("pythonzabc.", "Found a match!"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("xyzabc.", "Found a match!"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(" lang .", "Not matched!"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Found a match!", "inputs": {"text": "pythonzabc."}}, {"idx": 1, "outputs": "Found a match!", "inputs": {"text": "xyzabc."}}, {"idx": 2, "outputs": "Not matched!", "inputs": {"text": " lang ."}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
644 | MBPP/644 | C++ | Write a c++ function to reverse vector upto a given position. | /**
* Write a c++ function to reverse vector upto a given position.
*/
vector<int> reverseArrayUptoK(vector<int> input, int k) { | vector<int> reverseArrayUptoK(vector<int> input, int k) { | ['input', 'k'] | def reverse_Array_Upto_K(input, k):
return (input[k-1::-1] + input[k:]) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'reverseArrayUptoK', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to reverse an array upto a given position.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> input, int k, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(input, 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, 2, 3, 4, 5, 6}, 4, {4, 3, 2, 1, 5, 6}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6, 7}, 2, {5, 4, 6, 7}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({9, 8, 7, 6, 5}, 3, {7, 8, 9, 6, 5}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [4, 3, 2, 1, 5, 6], "inputs": {"input": [1, 2, 3, 4, 5, 6], "k": 4}}, {"idx": 1, "outputs": [5, 4, 6, 7], "inputs": {"input": [4, 5, 6, 7], "k": 2}}, {"idx": 2, "outputs": [7, 8, 9, 6, 5], "inputs": {"input": [9, 8, 7, 6, 5], "k": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
645 | MBPP/645 | C++ | Write a function to find the product of it’s kth index in the given tuples. | /**
* Write a function to find the product of it’s kth index in the given tuples.
*/
int findKProduct(vector<vector<int>> test_list, int k) { | int findKProduct(vector<vector<int>> test_list, int k) { | ['test_list', 'k'] | def get_product(val) :
res = 1
for ele in val:
res *= ele
return res
def find_k_product(test_list, K):
res = get_product([sub[K] for sub in test_list])
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findKProduct', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the product of it’s kth index in the given tuples.\n//\n// SOLUTION 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<vector<int>> test_list, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list, k), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{5, 6, 7}, {1, 3, 5}, {8, 9, 19}}, 2, 665); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{6, 7, 8}, {2, 4, 6}, {9, 10, 20}}, 1, 280); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{7, 8, 9}, {3, 5, 7}, {10, 11, 21}}, 0, 210); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 665, "inputs": {"test_list": [[5, 6, 7], [1, 3, 5], [8, 9, 19]], "k": 2}}, {"idx": 1, "outputs": 280, "inputs": {"test_list": [[6, 7, 8], [2, 4, 6], [9, 10, 20]], "k": 1}}, {"idx": 2, "outputs": 210, "inputs": {"test_list": [[7, 8, 9], [3, 5, 7], [10, 11, 21]], "k": 0}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
646 | MBPP/646 | C++ | Write a c++ function to count number of cubes of size k in a cube of size n. | /**
* Write a c++ function to count number of cubes of size k in a cube of size n.
*/
int noOfCubes(int n, int k) { | int noOfCubes(int n, int k) { | ['n', 'k'] | def No_of_cubes(N,K):
No = 0
No = (N - K + 1)
No = pow(No, 3)
return No | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'noOfCubes', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to count number of cubes of size k in a cube of size n.\n//\n// SOLUTION 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(2, 1, 8); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(5, 2, 64); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(1, 1, 1); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 8, "inputs": {"n": 2, "k": 1}}, {"idx": 1, "outputs": 64, "inputs": {"n": 5, "k": 2}}, {"idx": 2, "outputs": 1, "inputs": {"n": 1, "k": 1}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
647 | MBPP/647 | C++ | Write a function to split a string at uppercase letters. | /**
* Write a function to split a string at uppercase letters.
*/
vector<string> splitUpperstring(string text) { | vector<string> splitUpperstring(string text) { | ['text'] | import re
def split_upperstring(text):
return (re.findall('[A-Z][^A-Z]*', text)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'splitUpperstring', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to split a string at uppercase letters.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<string> actual, vector<string> expected){\n return actual == expected;\n}\n\nstring driver(string text, vector<string> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("PythonProgramLanguage", {"Python", "Program", "Language"}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("PythonProgram", {"Python", "Program"}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("ProgrammingLanguage", {"Programming", "Language"}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": ["Python", "Program", "Language"], "inputs": {"text": "PythonProgramLanguage"}}, {"idx": 1, "outputs": ["Python", "Program"], "inputs": {"text": "PythonProgram"}}, {"idx": 2, "outputs": ["Programming", "Language"], "inputs": {"text": "ProgrammingLanguage"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
648 | MBPP/648 | C++ | Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given vector. | /**
* Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given vector.
*/
vector<int> exchangeElements(vector<int> lst) { | vector<int> exchangeElements(vector<int> lst) { | ['lst'] | from itertools import zip_longest, chain, tee
def exchange_elements(lst):
lst1, lst2 = tee(iter(lst), 2)
return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2]))) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'exchangeElements', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> lst, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(lst), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 1, 2, 3, 4, 5}, {1, 0, 3, 2, 5, 4}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({5, 6, 7, 8, 9, 10}, {6, 5, 8, 7, 10, 9}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({25, 35, 45, 55, 75, 95}, {35, 25, 55, 45, 95, 75}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 0, 3, 2, 5, 4], "inputs": {"lst": [0, 1, 2, 3, 4, 5]}}, {"idx": 1, "outputs": [6, 5, 8, 7, 10, 9], "inputs": {"lst": [5, 6, 7, 8, 9, 10]}}, {"idx": 2, "outputs": [35, 25, 55, 45, 95, 75], "inputs": {"lst": [25, 35, 45, 55, 75, 95]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
649 | MBPP/649 | C++ | Write a c++ function to calculate the sum of the numbers in vector between the indices of a specified range. | /**
* Write a c++ function to calculate the sum of the numbers in vector between the indices of a specified range.
*/
int sumRangeList(vector<int> nums, int m, int n) { | int sumRangeList(vector<int> nums, int m, int n) { | ['nums', 'm', 'n'] | def sum_Range_list(nums, m, n):
sum_range = 0
for i in range(m, n+1, 1):
sum_range += nums[i]
return sum_range | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumRangeList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to calculate the sum of the numbers in a list between the indices of a specified range.\n//\n// SOLUTION 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> nums, int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums, m, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12}, 8, 10, 29); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5}, 1, 2, 5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 0, 1, 2, 5, 6}, 4, 5, 11); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 29, "inputs": {"nums": [2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], "m": 8, "n": 10}}, {"idx": 1, "outputs": 5, "inputs": {"nums": [1, 2, 3, 4, 5], "m": 1, "n": 2}}, {"idx": 2, "outputs": 11, "inputs": {"nums": [1, 0, 1, 2, 5, 6], "m": 4, "n": 5}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
650 | MBPP/650 | C++ | Write a c++ function to check whether the given two vectors are equal or not. | /**
* Write a c++ function to check whether the given two vectors are equal or not.
*/
bool areEqual(vector<int> arr1, vector<int> arr2, int n, int m) { | bool areEqual(vector<int> arr1, vector<int> arr2, int n, int m) { | ['arr1', 'arr2', 'n', 'm'] | def are_Equal(arr1,arr2,n,m):
if (n != m):
return False
arr1.sort()
arr2.sort()
for i in range(0,n - 1):
if (arr1[i] != arr2[i]):
return False
return True | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'areEqual', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check whether the given two arrays are equal or not.\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> arr1, vector<int> arr2, int n, int m, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, 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({1, 2, 3}, {3, 2, 1}, 3, 3, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 1, 1}, {2, 2, 2}, 3, 3, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({8, 9}, {4, 5, 6}, 2, 3, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"arr1": [1, 2, 3], "arr2": [3, 2, 1], "n": 3, "m": 3}}, {"idx": 1, "outputs": false, "inputs": {"arr1": [1, 1, 1], "arr2": [2, 2, 2], "n": 3, "m": 3}}, {"idx": 2, "outputs": false, "inputs": {"arr1": [8, 9], "arr2": [4, 5, 6], "n": 2, "m": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
651 | MBPP/651 | C++ | Write a function to check if one tuple is a subset of another tuple. | /**
* Write a function to check if one tuple is a subset of another tuple.
*/
bool checkSubset(vector<int> test_tup1, vector<int> test_tup2) { | bool checkSubset(vector<int> test_tup1, vector<int> test_tup2) { | ['test_tup1', 'test_tup2'] | def check_subset(test_tup1, test_tup2):
res = set(test_tup2).issubset(test_tup1)
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check if one tuple is a subset of another tuple.\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> test_tup1, vector<int> test_tup2, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup1, test_tup2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({10, 4, 5, 6}, {5, 10}, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4}, {5, 6}, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({7, 8, 9, 10}, {10, 8}, true); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"test_tup1": [10, 4, 5, 6], "test_tup2": [5, 10]}}, {"idx": 1, "outputs": false, "inputs": {"test_tup1": [1, 2, 3, 4], "test_tup2": [5, 6]}}, {"idx": 2, "outputs": true, "inputs": {"test_tup1": [7, 8, 9, 10], "test_tup2": [10, 8]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
652 | MBPP/652 | C++ | Write a function to flatten the given tuple matrix into the tuple vector with each tuple representing each column. | /**
* Write a function to flatten the given tuple matrix into the tuple vector with each tuple representing each column.
*/
string matrixToList(vector<vector<vector<int>>> test_list) { | string matrixToList(vector<vector<vector<int>>> test_list) { | ['test_list'] | def matrix_to_list(test_list):
temp = [ele for sub in test_list for ele in sub]
res = list(zip(*temp))
return (str(res)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'matrixToList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.\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(vector<vector<vector<int>>> test_list, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 8}}, {{10, 13}, {18, 17}}, {{0, 4}, {10, 1}}}, "[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{{5, 6}, {8, 9}}, {{11, 14}, {19, 18}}, {{1, 5}, {11, 2}}}, "[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{{6, 7}, {9, 10}}, {{12, 15}, {20, 21}}, {{23, 7}, {15, 8}}}, "[(6, 9, 12, 20, 23, 15), (7, 10, 15, 21, 7, 8)]"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]", "inputs": {"test_list": [[[4, 5], [7, 8]], [[10, 13], [18, 17]], [[0, 4], [10, 1]]]}}, {"idx": 1, "outputs": "[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]", "inputs": {"test_list": [[[5, 6], [8, 9]], [[11, 14], [19, 18]], [[1, 5], [11, 2]]]}}, {"idx": 2, "outputs": "[(6, 9, 12, 20, 23, 15), (7, 10, 15, 21, 7, 8)]", "inputs": {"test_list": [[[6, 7], [9, 10]], [[12, 15], [20, 21]], [[23, 7], [15, 8]]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
654 | MBPP/654 | C++ | Write a function to find the perimeter of a rectangle. | /**
* Write a function to find the perimeter of a rectangle.
*/
int rectanglePerimeter(int l, int b) { | int rectanglePerimeter(int l, int b) { | ['l', 'b'] | def rectangle_perimeter(l,b):
perimeter=2*(l+b)
return perimeter | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'rectanglePerimeter', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the perimeter of a rectangle.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int l, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(l, 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(10, 20, 60); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(10, 5, 30); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(4, 2, 12); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 60, "inputs": {"l": 10, "b": 20}}, {"idx": 1, "outputs": 30, "inputs": {"l": 10, "b": 5}}, {"idx": 2, "outputs": 12, "inputs": {"l": 4, "b": 2}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
655 | MBPP/655 | C++ | Write a c++ function to find the sum of fifth power of n natural numbers. | /**
* Write a c++ function to find the sum of fifth power of n natural numbers.
*/
int fifthPowerSum(int n) { | int fifthPowerSum(int n) { | ['n'] | def fifth_Power_Sum(n) :
sm = 0
for i in range(1,n+1) :
sm = sm + (i*i*i*i*i)
return sm | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'fifthPowerSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the sum of fifth power of n natural numbers.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 33); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(4, 1300); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(3, 276); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 33, "inputs": {"n": 2}}, {"idx": 1, "outputs": 1300, "inputs": {"n": 4}}, {"idx": 2, "outputs": 276, "inputs": {"n": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
656 | MBPP/656 | C++ | Write a c++ function to find the minimum sum of absolute differences of two vectors. | /**
* Write a c++ function to find the minimum sum of absolute differences of two vectors.
*/
int findMinSum(vector<int> a, vector<int> b, int n) { | int findMinSum(vector<int> a, vector<int> b, int n) { | ['a', 'b', 'n'] | def find_Min_Sum(a,b,n):
a.sort()
b.sort()
sum = 0
for i in range(n):
sum = sum + abs(a[i] - b[i])
return sum | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findMinSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the minimum sum of absolute differences of two arrays.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, vector<int> b, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({3, 2, 1}, {2, 1, 3}, 3, 0); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3}, {4, 5, 6}, 3, 9); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({4, 1, 8, 7}, {2, 3, 6, 5}, 4, 6); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 0, "inputs": {"a": [3, 2, 1], "b": [2, 1, 3], "n": 3}}, {"idx": 1, "outputs": 9, "inputs": {"a": [1, 2, 3], "b": [4, 5, 6], "n": 3}}, {"idx": 2, "outputs": 6, "inputs": {"a": [4, 1, 8, 7], "b": [2, 3, 6, 5], "n": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
657 | MBPP/657 | C++ | Write a c++ function to find the first digit in factorial of a given number. | /**
* Write a c++ function to find the first digit in factorial of a given number.
*/
int firstDigit(int n) { | int firstDigit(int n) { | ['n'] | import math
def first_Digit(n) :
fact = 1
for i in range(2,n + 1) :
fact = fact * i
while (fact % 10 == 0) :
fact = int(fact / 10)
while (fact >= 10) :
fact = int(fact / 10)
return math.floor(fact) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'firstDigit', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the first digit in factorial of a given number.\n//\n// SOLUTION 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, 1); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(10, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(7, 5); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 1, "inputs": {"n": 5}}, {"idx": 1, "outputs": 3, "inputs": {"n": 10}}, {"idx": 2, "outputs": 5, "inputs": {"n": 7}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
658 | MBPP/658 | C++ | Write a function to find the item with maximum occurrences in a given vector. | /**
* Write a function to find the item with maximum occurrences in a given vector.
*/
int maxOccurrences(vector<int> list1) { | int maxOccurrences(vector<int> list1) { | ['list1'] | def max_occurrences(list1):
max_val = 0
result = list1[0]
for i in list1:
occu = list1.count(i)
if occu > max_val:
max_val = occu
result = i
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOccurrences', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the item with maximum occurrences in a given list.\n//\n// SOLUTION 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> list1, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(list1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({2, 3, 8, 4, 7, 9, 8, 2, 6, 5, 1, 6, 1, 2, 3, 4, 6, 9, 1, 2}, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 3, 5, 7, 1, 3, 13, 15, 17, 5, 7, 9, 1, 11}, 1); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 2, 4, 5, 1, 1, 1}, 1); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"list1": [2, 3, 8, 4, 7, 9, 8, 2, 6, 5, 1, 6, 1, 2, 3, 4, 6, 9, 1, 2]}}, {"idx": 1, "outputs": 1, "inputs": {"list1": [1, 3, 5, 7, 1, 3, 13, 15, 17, 5, 7, 9, 1, 11]}}, {"idx": 2, "outputs": 1, "inputs": {"list1": [1, 2, 3, 2, 4, 5, 1, 1, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
659 | MBPP/659 | C++ | Write a c++ function to print duplicants from vector of integers. | /**
* Write a c++ function to print duplicants from vector of integers.
*/
vector<int> repeat(vector<int> x) { | vector<int> repeat(vector<int> x) { | ['x'] | def Repeat(x):
_size = len(x)
repeated = []
for i in range(_size):
k = i + 1
for j in range(k, _size):
if x[i] == x[j] and x[i] not in repeated:
repeated.append(x[i])
return repeated | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'repeat', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to print duplicants from a list of integers.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> x, vector<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({10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20}, {20, 30, -20, 60}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({-1, 1, -1, 8}, {-1}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 1, 2}, {1, 2}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [20, 30, -20, 60], "inputs": {"x": [10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]}}, {"idx": 1, "outputs": [-1], "inputs": {"x": [-1, 1, -1, 8]}}, {"idx": 2, "outputs": [1, 2], "inputs": {"x": [1, 2, 3, 1, 2]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
660 | MBPP/660 | C++ | Write a c++ function to choose points from two ranges such that no point lies in both the ranges. | /**
* Write a c++ function to choose points from two ranges such that no point lies in both the ranges.
*/
vector<int> findPoints(int l1, int r1, int l2, int r2) { | vector<int> findPoints(int l1, int r1, int l2, int r2) { | ['l1', 'r1', 'l2', 'r2'] | def find_Points(l1,r1,l2,r2):
x = min(l1,l2) if (l1 != l2) else -1
y = max(r1,r2) if (r1 != r2) else -1
return (x,y) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findPoints', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to choose points from two ranges such that no point lies in both the ranges.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(int l1, int r1, int l2, int r2, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(l1, r1, l2, r2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 10, 1, 5, {1, 10}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 5, 7, 9, {3, 9}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(1, 5, 2, 8, {1, 8}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 10], "inputs": {"l1": 5, "r1": 10, "l2": 1, "r2": 5}}, {"idx": 1, "outputs": [3, 9], "inputs": {"l1": 3, "r1": 5, "l2": 7, "r2": 9}}, {"idx": 2, "outputs": [1, 8], "inputs": {"l1": 1, "r1": 5, "l2": 2, "r2": 8}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
661 | MBPP/661 | C++ | Write a function to find the maximum sum that can be formed which has no three consecutive elements present. | /**
* Write a function to find the maximum sum that can be formed which has no three consecutive elements present.
*/
int maxSumOfThreeConsecutive(vector<int> arr, int n) { | int maxSumOfThreeConsecutive(vector<int> arr, int n) { | ['arr', 'n'] | def max_sum_of_three_consecutive(arr, n):
sum = [0 for k in range(n)]
if n >= 1:
sum[0] = arr[0]
if n >= 2:
sum[1] = arr[0] + arr[1]
if n > 2:
sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2]))
for i in range(3, n):
sum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1] + sum[i-3])
return sum[n-1] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxSumOfThreeConsecutive', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the maximum sum that can be formed which has no three consecutive elements present.\n//\n// SOLUTION 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({100, 1000, 100, 1000, 1}, 5, 2101); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({3000, 2000, 1000, 3, 10}, 5, 5013); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5, 6, 7, 8}, 8, 27); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2101, "inputs": {"arr": [100, 1000, 100, 1000, 1], "n": 5}}, {"idx": 1, "outputs": 5013, "inputs": {"arr": [3000, 2000, 1000, 3, 10], "n": 5}}, {"idx": 2, "outputs": 27, "inputs": {"arr": [1, 2, 3, 4, 5, 6, 7, 8], "n": 8}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
662 | MBPP/662 | C++ | Write a function to sort vector in map. | /**
* Write a function to sort vector in map.
*/
map<string,vector<int>> sortedDict(map<string,vector<int>> dict1) { | map<string,vector<int>> sortedDict(map<string,vector<int>> dict1) { | ['dict1'] | def sorted_dict(dict1):
sorted_dict = {x: sorted(y) for x, y in dict1.items()}
return sorted_dict | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sortedDict', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to sort a list in a dictionary.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(map<string,vector<int>> actual, map<string,vector<int>> expected){\n return actual == expected;\n}\n\nstring driver(map<string,vector<int>> dict1, map<string,vector<int>> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(dict1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{"n1", {2, 3, 1}}, {"n2", {5, 1, 2}}, {"n3", {3, 2, 4}}}, {{"n1", {1, 2, 3}}, {"n2", {1, 2, 5}}, {"n3", {2, 3, 4}}}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{"n1", {25, 37, 41}}, {"n2", {41, 54, 63}}, {"n3", {29, 38, 93}}}, {{"n1", {25, 37, 41}}, {"n2", {41, 54, 63}}, {"n3", {29, 38, 93}}}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{"n1", {58, 44, 56}}, {"n2", {91, 34, 58}}, {"n3", {100, 200, 300}}}, {{"n1", {44, 56, 58}}, {"n2", {34, 58, 91}}, {"n3", {100, 200, 300}}}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": {"n1": [1, 2, 3], "n2": [1, 2, 5], "n3": [2, 3, 4]}, "inputs": {"dict1": {"n1": [2, 3, 1], "n2": [5, 1, 2], "n3": [3, 2, 4]}}}, {"idx": 1, "outputs": {"n1": [25, 37, 41], "n2": [41, 54, 63], "n3": [29, 38, 93]}, "inputs": {"dict1": {"n1": [25, 37, 41], "n2": [41, 54, 63], "n3": [29, 38, 93]}}}, {"idx": 2, "outputs": {"n1": [44, 56, 58], "n2": [34, 58, 91], "n3": [100, 200, 300]}, "inputs": {"dict1": {"n1": [58, 44, 56], "n2": [91, 34, 58], "n3": [100, 200, 300]}}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
663 | MBPP/663 | C++ | Write a function to find the largest possible value of k such that k modulo x is y. | /**
* Write a function to find the largest possible value of k such that k modulo x is y.
*/
int findMaxVal(int n, int x, int y) { | int findMaxVal(int n, int x, int y) { | ['n', 'x', 'y'] | import sys
def find_max_val(n, x, y):
ans = -sys.maxsize
for k in range(n + 1):
if (k % x == y):
ans = max(ans, k)
return (ans if (ans >= 0 and
ans <= n) else -1) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findMaxVal', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the largest possible value of k such that k modulo x is y.\n//\n// SOLUTION 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 x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, x, y), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(15, 10, 5, 15); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(187, 10, 5, 185); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(16, 11, 1, 12); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 15, "inputs": {"n": 15, "x": 10, "y": 5}}, {"idx": 1, "outputs": 185, "inputs": {"n": 187, "x": 10, "y": 5}}, {"idx": 2, "outputs": 12, "inputs": {"n": 16, "x": 11, "y": 1}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
664 | MBPP/664 | C++ | Write a c++ function to find the average of even numbers till a given even number. | /**
* Write a c++ function to find the average of even numbers till a given even number.
*/
int averageEven(int n) { | int averageEven(int n) { | ['n'] | def average_Even(n) :
if (n% 2!= 0) :
return ("Invalid Input")
return -1
sm = 0
count = 0
while (n>= 2) :
count = count+1
sm = sm+n
n = n-2
return sm // count | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'averageEven', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the average of even numbers till a given even number.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(4, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(100, 51); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"n": 2}}, {"idx": 1, "outputs": 3, "inputs": {"n": 4}}, {"idx": 2, "outputs": 51, "inputs": {"n": 100}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
665 | MBPP/665 | C++ | Write a c++ function to shift first element to the end of given vector. | /**
* Write a c++ function to shift first element to the end of given vector.
*/
vector<int> moveLast(vector<int> num_list) { | vector<int> moveLast(vector<int> num_list) { | ['num_list'] | def move_last(num_list):
a = [num_list[0] for i in range(num_list.count(num_list[0]))]
x = [ i for i in num_list if i != num_list[0]]
x.extend(a)
return (x) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveLast', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to shift first element to the end of given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> num_list, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4}, {2, 3, 4, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({2, 3, 4, 1, 5, 0}, {3, 4, 1, 5, 0, 2}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({5, 4, 3, 2, 1}, {4, 3, 2, 1, 5}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [2, 3, 4, 1], "inputs": {"num_list": [1, 2, 3, 4]}}, {"idx": 1, "outputs": [3, 4, 1, 5, 0, 2], "inputs": {"num_list": [2, 3, 4, 1, 5, 0]}}, {"idx": 2, "outputs": [4, 3, 2, 1, 5], "inputs": {"num_list": [5, 4, 3, 2, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
666 | MBPP/666 | C++ | Write a function to count occurrence of a character in a string. | /**
* Write a function to count occurrence of a character in a string.
*/
int countChar(string string_arg0, char char_arg1) { | int countChar(string string_arg0, char char_arg1) { | ['string_arg0', 'char_arg1'] | def count_char(string,char):
count = 0
for i in range(len(string)):
if(string[i] == char):
count = count + 1
return count | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to count occurrence of a character in a string.\n//\n// SOLUTION 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 string_arg0, char char_arg1, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0, char_arg1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("Python", \'o\', 1); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("little", \'t\', 2); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("assert", \'s\', 2); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 1, "inputs": {"string_arg0": "Python", "char_arg1": "o"}}, {"idx": 1, "outputs": 2, "inputs": {"string_arg0": "little", "char_arg1": "t"}}, {"idx": 2, "outputs": 2, "inputs": {"string_arg0": "assert", "char_arg1": "s"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
667 | MBPP/667 | C++ | Write a c++ function to count number of vowels in the string. | /**
* Write a c++ function to count number of vowels in the string.
*/
int checkVow(string string_arg0, string vowels) { | int checkVow(string string_arg0, string vowels) { | ['string_arg0', 'vowels'] | def Check_Vow(string, vowels):
final = [each for each in string if each in vowels]
return(len(final))
| {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkVow', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to count number of vowels in the string.\n//\n// SOLUTION 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 string_arg0, string vowels, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0, vowels), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("corner", "AaEeIiOoUu", 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("valid", "AaEeIiOoUu", 2); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("true", "AaEeIiOoUu", 2); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"string_arg0": "corner", "vowels": "AaEeIiOoUu"}}, {"idx": 1, "outputs": 2, "inputs": {"string_arg0": "valid", "vowels": "AaEeIiOoUu"}}, {"idx": 2, "outputs": 2, "inputs": {"string_arg0": "true", "vowels": "AaEeIiOoUu"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
668 | MBPP/668 | C++ | Write a c++ function to replace multiple occurence of character by single. | /**
* Write a c++ function to replace multiple occurence of character by single.
*/
string replace(string string_arg0, char char_arg1) { | string replace(string string_arg0, char char_arg1) { | ['string_arg0', 'char_arg1'] | import re
def replace(string, char):
pattern = char + '{2,}'
string = re.sub(pattern, char, string)
return string | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replace', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to replace multiple occurence of character by single.\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 string_arg0, char char_arg1, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0, char_arg1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("peep", \'e\', "pep"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("Greek", \'e\', "Grek"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Moon", \'o\', "Mon"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "pep", "inputs": {"string_arg0": "peep", "char_arg1": "e"}}, {"idx": 1, "outputs": "Grek", "inputs": {"string_arg0": "Greek", "char_arg1": "e"}}, {"idx": 2, "outputs": "Mon", "inputs": {"string_arg0": "Moon", "char_arg1": "o"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
669 | MBPP/669 | C++ | Write a function to check whether the given ip address is valid or not using regex. | /**
* Write a function to check whether the given ip address is valid or not using regex.
*/
string checkIp(string ip) { | string checkIp(string ip) { | ['ip'] | import re
regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'''
def check_IP(Ip):
if(re.search(regex, Ip)):
return ("Valid IP address")
else:
return ("Invalid IP address") | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkIp', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check whether the given ip address is valid or not using regex.\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 ip, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(ip), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("192.168.0.1", "Valid IP address"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("110.234.52.124", "Valid IP address"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("366.1.2.2", "Invalid IP address"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Valid IP address", "inputs": {"ip": "192.168.0.1"}}, {"idx": 1, "outputs": "Valid IP address", "inputs": {"ip": "110.234.52.124"}}, {"idx": 2, "outputs": "Invalid IP address", "inputs": {"ip": "366.1.2.2"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
670 | MBPP/670 | C++ | Write a c++ function to check whether a sequence of numbers has a decreasing trend or not. | /**
* Write a c++ function to check whether a sequence of numbers has a decreasing trend or not.
*/
bool decreasingTrend(vector<int> nums) { | bool decreasingTrend(vector<int> nums) { | ['nums'] | def decreasing_trend(nums):
if (sorted(nums)== nums):
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'decreasingTrend', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check whether a sequence of numbers has a decreasing trend or not.\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> nums, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, -3, -2, -1}, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3}, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({3, 2, 1}, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"nums": [-4, -3, -2, -1]}}, {"idx": 1, "outputs": true, "inputs": {"nums": [1, 2, 3]}}, {"idx": 2, "outputs": false, "inputs": {"nums": [3, 2, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
671 | MBPP/671 | C++ | Write a c++ function to set the right most unset bit. | /**
* Write a c++ function to set the right most unset bit.
*/
int setRightMostUnsetBit(int n) { | int setRightMostUnsetBit(int n) { | ['n'] | import math
def get_Pos_Of_Right_most_Set_Bit(n):
return int(math.log2(n&-n)+1)
def set_Right_most_Unset_Bit(n):
if (n == 0):
return 1
if ((n & (n + 1)) == 0):
return n
pos = get_Pos_Of_Right_most_Set_Bit(~n)
return ((1 << (pos - 1)) | n) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'setRightMostUnsetBit', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to set the right most unset bit.\n//\n// SOLUTION 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(21, 23); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(11, 15); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(15, 15); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 23, "inputs": {"n": 21}}, {"idx": 1, "outputs": 15, "inputs": {"n": 11}}, {"idx": 2, "outputs": 15, "inputs": {"n": 15}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
672 | MBPP/672 | C++ | Write a function to find maximum of three numbers. | /**
* Write a function to find maximum of three numbers.
*/
int maxOfThree(int num1, int num2, int num3) { | int maxOfThree(int num1, int num2, int num3) { | ['num1', 'num2', 'num3'] | def max_of_three(num1,num2,num3):
if (num1 >= num2) and (num1 >= num3):
lnum = num1
elif (num2 >= num1) and (num2 >= num3):
lnum = num2
else:
lnum = num3
return lnum | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOfThree', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find maximum of three numbers.\n//\n// SOLUTION 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 num1, int num2, int num3, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num1, num2, num3), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(10, 20, 30, 30); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(55, 47, 39, 55); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(10, 49, 30, 49); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 30, "inputs": {"num1": 10, "num2": 20, "num3": 30}}, {"idx": 1, "outputs": 55, "inputs": {"num1": 55, "num2": 47, "num3": 39}}, {"idx": 2, "outputs": 49, "inputs": {"num1": 10, "num2": 49, "num3": 30}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
673 | MBPP/673 | C++ | Write a c++ function to convert vector of multiple integers into a single integer. | /**
* Write a c++ function to convert vector of multiple integers into a single integer.
*/
int convert(vector<int> list) { | int convert(vector<int> list) { | ['list'] | def convert(list):
s = [str(i) for i in list]
res = int("".join(s))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'convert', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to convert a list of multiple integers into a single integer.\n//\n// SOLUTION 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> list, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3}, 123); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6}, 456); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({7, 8, 9}, 789); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 123, "inputs": {"list": [1, 2, 3]}}, {"idx": 1, "outputs": 456, "inputs": {"list": [4, 5, 6]}}, {"idx": 2, "outputs": 789, "inputs": {"list": [7, 8, 9]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
674 | MBPP/674 | C++ | Write a function to remove duplicate words from a given string using collections module. | /**
* Write a function to remove duplicate words from a given string using collections module.
*/
string removeDuplicate(string string_arg0) { | string removeDuplicate(string string_arg0) { | ['string_arg0'] | from collections import OrderedDict
def remove_duplicate(string):
result = ' '.join(OrderedDict((w,w) for w in string.split()).keys())
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeDuplicate', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to remove duplicate words from a given string using collections module.\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 string_arg0, string 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("Python Exercises Practice Solution Exercises", "Python Exercises Practice Solution"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("Python Exercises Practice Solution Python", "Python Exercises Practice Solution"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Python Exercises Practice Solution Practice", "Python Exercises Practice Solution"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Python Exercises Practice Solution", "inputs": {"string_arg0": "Python Exercises Practice Solution Exercises"}}, {"idx": 1, "outputs": "Python Exercises Practice Solution", "inputs": {"string_arg0": "Python Exercises Practice Solution Python"}}, {"idx": 2, "outputs": "Python Exercises Practice Solution", "inputs": {"string_arg0": "Python Exercises Practice Solution Practice"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
675 | MBPP/675 | C++ | Write a function to add two integers. however, if the sum is between the given range it will return 20. | /**
* Write a function to add two integers. however, if the sum is between the given range it will return 20.
*/
int sumNums(int x, int y, int m, int n) { | int sumNums(int x, int y, int m, int n) { | ['x', 'y', 'm', 'n'] | def sum_nums(x, y,m,n):
sum_nums= x + y
if sum_nums in range(m, n):
return 20
else:
return sum_nums | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumNums', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to add two integers. however, if the sum is between the given range it will return 20.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int x, int y, int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x, y, m, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 10, 11, 20, 20); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(15, 17, 1, 10, 32); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(10, 15, 5, 30, 20); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 20, "inputs": {"x": 2, "y": 10, "m": 11, "n": 20}}, {"idx": 1, "outputs": 32, "inputs": {"x": 15, "y": 17, "m": 1, "n": 10}}, {"idx": 2, "outputs": 20, "inputs": {"x": 10, "y": 15, "m": 5, "n": 30}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
676 | MBPP/676 | C++ | Write a function to remove everything except alphanumeric characters from the given string by using regex. | /**
* Write a function to remove everything except alphanumeric characters from the given string by using regex.
*/
string removeExtraChar(string text1) { | string removeExtraChar(string text1) { | ['text1'] | import re
def remove_extra_char(text1):
pattern = re.compile('[\W_]+')
return (pattern.sub('', text1)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeExtraChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to remove everything except alphanumeric characters from the given string by using regex.\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 text1, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("**//Google Android// - 12. ", "GoogleAndroid12"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("****//Google Flutter//*** - 36. ", "GoogleFlutter36"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("**//Google Firebase// - 478. ", "GoogleFirebase478"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "GoogleAndroid12", "inputs": {"text1": "**//Google Android// - 12. "}}, {"idx": 1, "outputs": "GoogleFlutter36", "inputs": {"text1": "****//Google Flutter//*** - 36. "}}, {"idx": 2, "outputs": "GoogleFirebase478", "inputs": {"text1": "**//Google Firebase// - 478. "}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
677 | MBPP/677 | C++ | Write a function to check if the triangle is valid or not. | /**
* Write a function to check if the triangle is valid or not.
*/
bool validityTriangle(int a, int b, int c) { | bool validityTriangle(int a, int b, int c) { | ['a', 'b', 'c'] | def validity_triangle(a,b,c):
total = a + b + c
if total == 180:
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'validityTriangle', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check if the triangle is valid or not.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int c, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(60, 50, 90, false); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(45, 75, 60, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(30, 50, 100, true); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": false, "inputs": {"a": 60, "b": 50, "c": 90}}, {"idx": 1, "outputs": true, "inputs": {"a": 45, "b": 75, "c": 60}}, {"idx": 2, "outputs": true, "inputs": {"a": 30, "b": 50, "c": 100}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
678 | MBPP/678 | C++ | Write a c++ function to remove spaces from a given string. | /**
* Write a c++ function to remove spaces from a given string.
*/
string removeSpaces(string str1) { | string removeSpaces(string str1) { | ['str1'] | def remove_spaces(str1):
str1 = str1.replace(' ','')
return str1 | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to remove spaces from a given string.\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 expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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", "abc"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("1 2 3", "123"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(" b c", "bc"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "abc", "inputs": {"str1": "a b c"}}, {"idx": 1, "outputs": "123", "inputs": {"str1": "1 2 3"}}, {"idx": 2, "outputs": "bc", "inputs": {"str1": " b c"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
679 | MBPP/679 | C++ | Write a function to access map key’s element by index. | /**
* Write a function to access map key’s element by index.
*/
string accessKey(map<string,int> ditionary, int key) { | string accessKey(map<string,int> ditionary, int key) { | ['ditionary', 'key'] | def access_key(ditionary,key):
return list(ditionary)[key] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'accessKey', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to access dictionary key’s element by index.\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(map<string,int> ditionary, int key, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(ditionary, key), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{"physics", 80}, {"math", 90}, {"chemistry", 86}}, 0, "physics"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{"python", 10}, {"java", 20}, {"C++", 30}}, 2, "C++"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{"program", 15}, {"computer", 45}}, 1, "computer"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "physics", "inputs": {"ditionary": {"physics": 80, "math": 90, "chemistry": 86}, "key": 0}}, {"idx": 1, "outputs": "C++", "inputs": {"ditionary": {"python": 10, "java": 20, "C++": 30}, "key": 2}}, {"idx": 2, "outputs": "computer", "inputs": {"ditionary": {"program": 15, "computer": 45}, "key": 1}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
680 | MBPP/680 | C++ | Write a c++ function to check whether a sequence of numbers has an increasing trend or not. | /**
* Write a c++ function to check whether a sequence of numbers has an increasing trend or not.
*/
bool increasingTrend(vector<int> nums) { | bool increasingTrend(vector<int> nums) { | ['nums'] | def increasing_trend(nums):
if (sorted(nums)== nums):
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'increasingTrend', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check whether a sequence of numbers has an increasing trend or not.\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> nums, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4}, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 3, 2, 1}, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({0, 1, 4, 9}, true); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"nums": [1, 2, 3, 4]}}, {"idx": 1, "outputs": false, "inputs": {"nums": [4, 3, 2, 1]}}, {"idx": 2, "outputs": true, "inputs": {"nums": [0, 1, 4, 9]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
681 | MBPP/681 | C++ | Write a c++ function to find the smallest prime divisor of a number. | /**
* Write a c++ function to find the smallest prime divisor of a number.
*/
int smallestDivisor(int n) { | int smallestDivisor(int n) { | ['n'] | def smallest_Divisor(n):
if (n % 2 == 0):
return 2;
i = 3;
while (i*i <= n):
if (n % i == 0):
return i;
i += 2;
return n; | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'smallestDivisor', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the smallest prime divisor of a number.\n//\n// SOLUTION 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(10, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(25, 5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(31, 31); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"n": 10}}, {"idx": 1, "outputs": 5, "inputs": {"n": 25}}, {"idx": 2, "outputs": 31, "inputs": {"n": 31}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
682 | MBPP/682 | C++ | Write a function to multiply two vectors using map and lambda function. | /**
* Write a function to multiply two vectors using map and lambda function.
*/
vector<int> mulList(vector<int> nums1, vector<int> nums2) { | vector<int> mulList(vector<int> nums1, vector<int> nums2) { | ['nums1', 'nums2'] | def mul_list(nums1,nums2):
result = map(lambda x, y: x * y, nums1, nums2)
return list(result) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'mulList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to multiply two lists using map and lambda function.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums1, vector<int> nums2, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums1, nums2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3}, {4, 5, 6}, {4, 10, 18}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2}, {3, 4}, {3, 8}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({90, 120}, {50, 70}, {4500, 8400}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [4, 10, 18], "inputs": {"nums1": [1, 2, 3], "nums2": [4, 5, 6]}}, {"idx": 1, "outputs": [3, 8], "inputs": {"nums1": [1, 2], "nums2": [3, 4]}}, {"idx": 2, "outputs": [4500, 8400], "inputs": {"nums1": [90, 120], "nums2": [50, 70]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
683 | MBPP/683 | C++ | Write a c++ function to check whether the given number can be represented by sum of two squares or not. | /**
* Write a c++ function to check whether the given number can be represented by sum of two squares or not.
*/
bool sumSquare(int n) { | bool sumSquare(int n) { | ['n'] | def sum_Square(n) :
i = 1
while i*i <= n :
j = 1
while (j*j <= n) :
if (i*i+j*j == n) :
return True
j = j+1
i = i+1
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumSquare', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check whether the given number can be represented by sum of two squares or not.\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(25, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(24, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(17, true); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"n": 25}}, {"idx": 1, "outputs": false, "inputs": {"n": 24}}, {"idx": 2, "outputs": true, "inputs": {"n": 17}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
684 | MBPP/684 | C++ | Write a c++ function to count occurences of a character in a repeated string. | /**
* Write a c++ function to count occurences of a character in a repeated string.
*/
int countChar(string str, char x) { | int countChar(string str, char x) { | ['str', 'x'] | def count_Char(str,x):
count = 0
for i in range(len(str)):
if (str[i] == x) :
count += 1
n = 10
repititions = n // len(str)
count = count * repititions
l = n % len(str)
for i in range(l):
if (str[i] == x):
count += 1
return count | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to count occurences of a character in a repeated string.\n//\n// SOLUTION 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, char x, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str, 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("abcac", \'a\', 4); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("abca", \'c\', 2); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("aba", \'a\', 7); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 4, "inputs": {"str": "abcac", "x": "a"}}, {"idx": 1, "outputs": 2, "inputs": {"str": "abca", "x": "c"}}, {"idx": 2, "outputs": 7, "inputs": {"str": "aba", "x": "a"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
685 | MBPP/685 | C++ | Write a c++ function to find sum of prime numbers between 1 to n. | /**
* Write a c++ function to find sum of prime numbers between 1 to n.
*/
int sumOfPrimes(int n) { | int sumOfPrimes(int n) { | ['n'] | def sum_Of_Primes(n):
prime = [True] * (n + 1)
p = 2
while p * p <= n:
if prime[p] == True:
i = p * 2
while i <= n:
prime[i] = False
i += p
p += 1
sum = 0
for i in range (2,n + 1):
if(prime[i]):
sum += i
return sum | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumOfPrimes', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find sum of prime numbers between 1 to n.\n//\n// SOLUTION 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(10, 17); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(20, 77); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(5, 10); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 17, "inputs": {"n": 10}}, {"idx": 1, "outputs": 77, "inputs": {"n": 20}}, {"idx": 2, "outputs": 10, "inputs": {"n": 5}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
686 | MBPP/686 | C++ | Write a function to find the frequency of each element in the given vector. | /**
* Write a function to find the frequency of each element in the given vector.
*/
string freqElement(vector<int> test_tup) { | string freqElement(vector<int> test_tup) { | ['test_tup'] | from collections import defaultdict
def freq_element(test_tup):
res = defaultdict(int)
for ele in test_tup:
res[ele] += 1
return (str(dict(res))) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'freqElement', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the frequency of each element in the given list.\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(vector<int> test_tup, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 4, 5, 6, 6, 5, 5, 4}, "{4: 3, 5: 4, 6: 2}"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({7, 8, 8, 9, 4, 7, 6, 5, 4}, "{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 4, 3, 1, 4, 5, 2, 6, 2, 7}, "{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "{4: 3, 5: 4, 6: 2}", "inputs": {"test_tup": [4, 5, 4, 5, 6, 6, 5, 5, 4]}}, {"idx": 1, "outputs": "{7: 2, 8: 2, 9: 1, 4: 2, 6: 1, 5: 1}", "inputs": {"test_tup": [7, 8, 8, 9, 4, 7, 6, 5, 4]}}, {"idx": 2, "outputs": "{1: 2, 4: 2, 3: 1, 5: 1, 2: 2, 6: 1, 7: 1}", "inputs": {"test_tup": [1, 4, 3, 1, 4, 5, 2, 6, 2, 7]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
687 | MBPP/687 | C++ | Write a function to find the greatest common divisor (gcd) of two integers by using recursion. | /**
* Write a function to find the greatest common divisor (gcd) of two integers by using recursion.
*/
int recurGcd(int a, int b) { | int recurGcd(int a, int b) { | ['a', 'b'] | def recur_gcd(a, b):
low = min(a, b)
high = max(a, b)
if low == 0:
return high
elif low == 1:
return 1
else:
return recur_gcd(low, high%low) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'recurGcd', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the greatest common divisor (gcd) of two integers by using recursion.\n//\n// SOLUTION 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(12, 14, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(13, 17, 1); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(9, 3, 3); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"a": 12, "b": 14}}, {"idx": 1, "outputs": 1, "inputs": {"a": 13, "b": 17}}, {"idx": 2, "outputs": 3, "inputs": {"a": 9, "b": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
688 | MBPP/688 | C++ | Write a function to get the length of a complex number. | /**
* Write a function to get the length of a complex number.
*/
double lenComplex(int a, int b) { | double lenComplex(int a, int b) { | ['a', 'b'] | import cmath
def len_complex(a,b):
cn=complex(a,b)
length=abs(cn)
return length | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'lenComplex', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to get the length of a complex number.\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(3, 4, 5.0); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(9, 10, 13.45362404707371); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(7, 9, 11.40175425099138); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 5.0, "inputs": {"a": 3, "b": 4}}, {"idx": 1, "outputs": 13.45362404707371, "inputs": {"a": 9, "b": 10}}, {"idx": 2, "outputs": 11.40175425099138, "inputs": {"a": 7, "b": 9}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
689 | MBPP/689 | C++ | ## write a function to find the minimum number of jumps to reach the end of the vector for the given vector of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block | /**
* ## write a function to find the minimum number of jumps to reach the end of the vector for the given vector of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block
*/
int minJumps(vector<int> arr, int n) { | int minJumps(vector<int> arr, int n) { | ['arr', 'n'] | def min_jumps(arr, n):
jumps = [0 for i in range(n)]
if (n == 0) or (arr[0] == 0):
return float('inf')
jumps[0] = 0
for i in range(1, n):
jumps[i] = float('inf')
for j in range(i):
if (i <= j + arr[j]) and (jumps[j] != float('inf')):
jumps[i] = min(jumps[i], jumps[j] + 1)
break
return jumps[n-1] | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'minJumps', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// ## write a function to find the minimum number of jumps to reach the end of the array for the given array of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block\n//\n// SOLUTION 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, 3, 6, 1, 0, 9}, 6, 3); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9}, 11, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 11, 10); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 3, "inputs": {"arr": [1, 3, 6, 1, 0, 9], "n": 6}}, {"idx": 1, "outputs": 3, "inputs": {"arr": [1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9], "n": 11}}, {"idx": 2, "outputs": 10, "inputs": {"arr": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 11}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
690 | MBPP/690 | C++ | Write a function to multiply consecutive numbers of a given vector. | /**
* Write a function to multiply consecutive numbers of a given vector.
*/
vector<int> mulConsecutiveNums(vector<int> nums) { | vector<int> mulConsecutiveNums(vector<int> nums) { | ['nums'] | def mul_consecutive_nums(nums):
result = [b*a for a, b in zip(nums[:-1], nums[1:])]
return result | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'mulConsecutiveNums', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to multiply consecutive numbers of a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 1, 3, 4, 4, 5, 6, 7}, {1, 3, 12, 16, 20, 30, 42}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 8, 9, 6, 10}, {20, 40, 72, 54, 60}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {2, 6, 12, 20, 30, 42, 56, 72, 90}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 3, 12, 16, 20, 30, 42], "inputs": {"nums": [1, 1, 3, 4, 4, 5, 6, 7]}}, {"idx": 1, "outputs": [20, 40, 72, 54, 60], "inputs": {"nums": [4, 5, 8, 9, 6, 10]}}, {"idx": 2, "outputs": [2, 6, 12, 20, 30, 42, 56, 72, 90], "inputs": {"nums": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
691 | MBPP/691 | C++ | Write a function to group the 1st elements on the basis of 2nd elements in the given tuple vector. | /**
* Write a function to group the 1st elements on the basis of 2nd elements in the given tuple vector.
*/
map<int,vector<int>> groupElement(vector<vector<int>> test_list) { | map<int,vector<int>> groupElement(vector<vector<int>> test_list) { | ['test_list'] | from itertools import groupby
def group_element(test_list):
res = dict()
for key, val in groupby(sorted(test_list, key = lambda ele: ele[1]), key = lambda ele: ele[1]):
res[key] = [ele[0] for ele in val]
return (res)
| {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'groupElement', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to group the 1st elements on the basis of 2nd elements in the given tuple list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(map<int,vector<int>> actual, map<int,vector<int>> expected){\n return actual == expected;\n}\n\nstring driver(vector<vector<int>> test_list, map<int,vector<int>> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return 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, 5}, {2, 7}, {2, 5}, {8, 7}, {9, 8}, {3, 7}}, {{5, {6, 2}}, {7, {2, 8, 3}}, {8, {9}}}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{7, 6}, {3, 8}, {3, 6}, {9, 8}, {10, 9}, {4, 8}}, {{6, {7, 3}}, {8, {3, 9, 4}}, {9, {10}}}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{8, 7}, {4, 9}, {4, 7}, {10, 9}, {11, 10}, {5, 9}}, {{7, {8, 4}}, {9, {4, 10, 5}}, {10, {11}}}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": {"5": [6, 2], "7": [2, 8, 3], "8": [9]}, "inputs": {"test_list": [[6, 5], [2, 7], [2, 5], [8, 7], [9, 8], [3, 7]]}}, {"idx": 1, "outputs": {"6": [7, 3], "8": [3, 9, 4], "9": [10]}, "inputs": {"test_list": [[7, 6], [3, 8], [3, 6], [9, 8], [10, 9], [4, 8]]}}, {"idx": 2, "outputs": {"7": [8, 4], "9": [4, 10, 5], "10": [11]}, "inputs": {"test_list": [[8, 7], [4, 9], [4, 7], [10, 9], [11, 10], [5, 9]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
692 | MBPP/692 | C++ | Write a c++ function to find the last two digits in factorial of a given number. | /**
* Write a c++ function to find the last two digits in factorial of a given number.
*/
int lastTwoDigits(int n) { | int lastTwoDigits(int n) { | ['n'] | def last_Two_Digits(N):
if (N >= 10):
return
fac = 1
for i in range(1,N + 1):
fac = (fac * i) % 100
return (fac) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'lastTwoDigits', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the last two digits in factorial of a given number.\n//\n// SOLUTION 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(7, 40); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(5, 20); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(2, 2); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 40, "inputs": {"n": 7}}, {"idx": 1, "outputs": 20, "inputs": {"n": 5}}, {"idx": 2, "outputs": 2, "inputs": {"n": 2}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
693 | MBPP/693 | C++ | Write a function to remove multiple spaces in a string by using regex. | /**
* Write a function to remove multiple spaces in a string by using regex.
*/
string removeMultipleSpaces(string text1) { | string removeMultipleSpaces(string text1) { | ['text1'] | import re
def remove_multiple_spaces(text1):
return (re.sub(' +',' ',text1)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeMultipleSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to remove multiple spaces in a string by using regex.\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 text1, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("Google Assistant", "Google Assistant"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("Quad Core", "Quad Core"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("ChromeCast Built-in", "ChromeCast Built-in"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Google Assistant", "inputs": {"text1": "Google Assistant"}}, {"idx": 1, "outputs": "Quad Core", "inputs": {"text1": "Quad Core"}}, {"idx": 2, "outputs": "ChromeCast Built-in", "inputs": {"text1": "ChromeCast Built-in"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
694 | MBPP/694 | C++ | Write a function to extract unique values from the given map values. | /**
* Write a function to extract unique values from the given map values.
*/
vector<int> extractUnique(map<string,vector<int>> test_dict) { | vector<int> extractUnique(map<string,vector<int>> test_dict) { | ['test_dict'] | def extract_unique(test_dict):
res = list(sorted({ele for val in test_dict.values() for ele in val}))
return res | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'extractUnique', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to extract unique values from the given dictionary values.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(map<string,vector<int>> test_dict, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_dict), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{"msm", {5, 6, 7, 8}}, {"is", {10, 11, 7, 5}}, {"best", {6, 12, 10, 8}}, {"for", {1, 2, 5}}}, {1, 2, 5, 6, 7, 8, 10, 11, 12}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{"Built", {7, 1, 9, 4}}, {"for", {11, 21, 36, 14, 9}}, {"ISP", {4, 1, 21, 39, 47}}, {"TV", {1, 32, 38}}}, {1, 4, 7, 9, 11, 14, 21, 32, 36, 38, 39, 47}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{"F", {11, 13, 14, 17}}, {"A", {12, 11, 15, 18}}, {"N", {19, 21, 15, 36}}, {"G", {37, 36, 35}}}, {11, 12, 13, 14, 15, 17, 18, 19, 21, 35, 36, 37}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 2, 5, 6, 7, 8, 10, 11, 12], "inputs": {"test_dict": {"msm": [5, 6, 7, 8], "is": [10, 11, 7, 5], "best": [6, 12, 10, 8], "for": [1, 2, 5]}}}, {"idx": 1, "outputs": [1, 4, 7, 9, 11, 14, 21, 32, 36, 38, 39, 47], "inputs": {"test_dict": {"Built": [7, 1, 9, 4], "for": [11, 21, 36, 14, 9], "ISP": [4, 1, 21, 39, 47], "TV": [1, 32, 38]}}}, {"idx": 2, "outputs": [11, 12, 13, 14, 15, 17, 18, 19, 21, 35, 36, 37], "inputs": {"test_dict": {"F": [11, 13, 14, 17], "A": [12, 11, 15, 18], "N": [19, 21, 15, 36], "G": [37, 36, 35]}}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
695 | MBPP/695 | C++ | Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple. | /**
* Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.
*/
bool checkGreater(vector<int> test_tup1, vector<int> test_tup2) { | bool checkGreater(vector<int> test_tup1, vector<int> test_tup2) { | ['test_tup1', 'test_tup2'] | def check_greater(test_tup1, test_tup2):
res = all(x < y for x, y in zip(test_tup1, test_tup2))
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkGreater', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.\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> test_tup1, vector<int> test_tup2, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup1, test_tup2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({10, 4, 5}, {13, 5, 18}, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3}, {2, 1, 4}, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6}, {5, 6, 7}, true); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"test_tup1": [10, 4, 5], "test_tup2": [13, 5, 18]}}, {"idx": 1, "outputs": false, "inputs": {"test_tup1": [1, 2, 3], "test_tup2": [2, 1, 4]}}, {"idx": 2, "outputs": true, "inputs": {"test_tup1": [4, 5, 6], "test_tup2": [5, 6, 7]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
697 | MBPP/697 | C++ | Write a function to find number of even elements in the given vector using lambda function. | /**
* Write a function to find number of even elements in the given vector using lambda function.
*/
int countEven(vector<int> array_nums) { | int countEven(vector<int> array_nums) { | ['array_nums'] | def count_even(array_nums):
count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums)))
return count_even | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countEven', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find number of even elements in the given list using lambda function.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> array_nums, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(array_nums), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 5, 7, 8, 9, 10}, 3); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({10, 15, 14, 13, -18, 12, -20}, 5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 4, 8, 9}, 3); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 3, "inputs": {"array_nums": [1, 2, 3, 5, 7, 8, 9, 10]}}, {"idx": 1, "outputs": 5, "inputs": {"array_nums": [10, 15, 14, 13, -18, 12, -20]}}, {"idx": 2, "outputs": 3, "inputs": {"array_nums": [1, 2, 4, 8, 9]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
701 | MBPP/701 | C++ | Write a function to find the equilibrium index of the given vector. | /**
* Write a function to find the equilibrium index of the given vector.
*/
int equilibriumIndex(vector<int> arr) { | int equilibriumIndex(vector<int> arr) { | ['arr'] | def equilibrium_index(arr):
total_sum = sum(arr)
left_sum=0
for i, num in enumerate(arr):
total_sum -= num
if left_sum == total_sum:
return i
left_sum += num
return -1 | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'equilibriumIndex', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the equilibrium index of the given array.\n//\n// SOLUTION 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 expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4, 1, 2, 3}, 3); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({-7, 1, 5, 2, -4, 3, 0}, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3}, -1); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 3, "inputs": {"arr": [1, 2, 3, 4, 1, 2, 3]}}, {"idx": 1, "outputs": 3, "inputs": {"arr": [-7, 1, 5, 2, -4, 3, 0]}}, {"idx": 2, "outputs": -1, "inputs": {"arr": [1, 2, 3]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
702 | MBPP/702 | C++ | Write a function to find the minimum number of elements that should be removed such that amax-amin<=k. | /**
* Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.
*/
int removals(vector<int> arr, int n, int k) { | int removals(vector<int> arr, int n, int k) { | ['arr', 'n', 'k'] | def find_ind(key, i, n,
k, arr):
ind = -1
start = i + 1
end = n - 1;
while (start < end):
mid = int(start +
(end - start) / 2)
if (arr[mid] - key <= k):
ind = mid
start = mid + 1
else:
end = mid
return ind
def removals(arr, n, k):
ans = n - 1
arr.sort()
for i in range(0, n):
j = find_ind(arr[i], i,
n, k, arr)
if (j != -1):
ans = min(ans, n -
(j - i + 1))
return ans | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removals', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.\n//\n// SOLUTION 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({1, 3, 4, 9, 10, 11, 12, 17, 20}, 9, 4, 5); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 5, 6, 2, 8}, 5, 2, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5, 6}, 6, 3, 2); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 5, "inputs": {"arr": [1, 3, 4, 9, 10, 11, 12, 17, 20], "n": 9, "k": 4}}, {"idx": 1, "outputs": 3, "inputs": {"arr": [1, 5, 6, 2, 8], "n": 5, "k": 2}}, {"idx": 2, "outputs": 2, "inputs": {"arr": [1, 2, 3, 4, 5, 6], "n": 6, "k": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
703 | MBPP/703 | C++ | Write a function to check whether the given key is present in the map or not. | /**
* Write a function to check whether the given key is present in the map or not.
*/
bool isKeyPresent(map<int,int> d, int x) { | bool isKeyPresent(map<int,int> d, int x) { | ['d', 'x'] | def is_key_present(d,x):
if x in d:
return True
else:
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isKeyPresent', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check whether the given key is present in the dictionary or not.\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(map<int,int> d, int x, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(d, x), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{1, 10}, {2, 20}, {3, 30}, {4, 40}, {5, 50}, {6, 60}}, 5, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{1, 10}, {2, 20}, {3, 30}, {4, 40}, {5, 50}, {6, 60}}, 6, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{1, 10}, {2, 20}, {3, 30}, {4, 40}, {5, 50}, {6, 60}}, 10, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"d": {"1": 10, "2": 20, "3": 30, "4": 40, "5": 50, "6": 60}, "x": 5}}, {"idx": 1, "outputs": true, "inputs": {"d": {"1": 10, "2": 20, "3": 30, "4": 40, "5": 50, "6": 60}, "x": 6}}, {"idx": 2, "outputs": false, "inputs": {"d": {"1": 10, "2": 20, "3": 30, "4": 40, "5": 50, "6": 60}, "x": 10}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
704 | MBPP/704 | C++ | Write a function to calculate the harmonic sum of n-1. | /**
* Write a function to calculate the harmonic sum of n-1.
*/
double harmonicSum(int n) { | double harmonicSum(int n) { | ['n'] | def harmonic_sum(n):
if n < 2:
return 1
else:
return 1 / n + (harmonic_sum(n - 1)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'harmonicSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to calculate the harmonic sum of n-1.\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(10, 2.9289682539682538); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(4, 2.083333333333333); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(7, 2.5928571428571425); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2.9289682539682538, "inputs": {"n": 10}}, {"idx": 1, "outputs": 2.083333333333333, "inputs": {"n": 4}}, {"idx": 2, "outputs": 2.5928571428571425, "inputs": {"n": 7}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
706 | MBPP/706 | C++ | Write a function to find whether vector is subset of another vector. | /**
* Write a function to find whether vector is subset of another vector.
*/
bool isSubset(vector<int> arr1, int m, vector<int> arr2, int n) { | bool isSubset(vector<int> arr1, int m, vector<int> arr2, int n) { | ['arr1', 'm', 'arr2', 'n'] | def is_subset(arr1, m, arr2, n):
hashset = set()
for i in range(0, m):
hashset.add(arr1[i])
for i in range(0, n):
if arr2[i] in hashset:
continue
else:
return False
return True | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find whether an array is subset of another array.\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> arr1, int m, vector<int> arr2, int n, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, m, 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({11, 1, 13, 21, 3, 7}, 6, {11, 3, 7, 1}, 4, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5, 6}, 6, {1, 2, 4}, 3, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({10, 5, 2, 23, 19}, 5, {19, 5, 3}, 3, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"arr1": [11, 1, 13, 21, 3, 7], "m": 6, "arr2": [11, 3, 7, 1], "n": 4}}, {"idx": 1, "outputs": true, "inputs": {"arr1": [1, 2, 3, 4, 5, 6], "m": 6, "arr2": [1, 2, 4], "n": 3}}, {"idx": 2, "outputs": false, "inputs": {"arr1": [10, 5, 2, 23, 19], "m": 5, "arr2": [19, 5, 3], "n": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
707 | MBPP/707 | C++ | Write a c++ function to count the total set bits from 1 to n. | /**
* Write a c++ function to count the total set bits from 1 to n.
*/
int countSetBits(int n) { | int countSetBits(int n) { | ['n'] | def count_Set_Bits(n) :
n += 1;
powerOf2 = 2;
cnt = n // 2;
while (powerOf2 <= n) :
totalPairs = n // powerOf2;
cnt += (totalPairs // 2) * powerOf2;
if (totalPairs & 1) :
cnt += (n % powerOf2)
else :
cnt += 0
powerOf2 <<= 1;
return cnt; | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countSetBits', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to count the total set bits from 1 to n.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(16, 33); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(2, 2); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(14, 28); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 33, "inputs": {"n": 16}}, {"idx": 1, "outputs": 2, "inputs": {"n": 2}}, {"idx": 2, "outputs": 28, "inputs": {"n": 14}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
708 | MBPP/708 | C++ | Write a c++ function to convert a string to vector. | /**
* Write a c++ function to convert a string to vector.
*/
vector<string> convert(string string_arg0) { | vector<string> convert(string string_arg0) { | ['string_arg0'] | def Convert(string):
li = list(string.split(" "))
return li | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'convert', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to convert a string to a list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<string> actual, vector<string> expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, vector<string> 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("python program", {"python", "program"}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("Data Analysis", {"Data", "Analysis"}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Hadoop Training", {"Hadoop", "Training"}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": ["python", "program"], "inputs": {"string_arg0": "python program"}}, {"idx": 1, "outputs": ["Data", "Analysis"], "inputs": {"string_arg0": "Data Analysis"}}, {"idx": 2, "outputs": ["Hadoop", "Training"], "inputs": {"string_arg0": "Hadoop Training"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
709 | MBPP/709 | C++ | Write a function to count unique keys for each value present in the tuple. | /**
* Write a function to count unique keys for each value present in the tuple.
*/
string getUnique(vector<vector<int>> test_list) { | string getUnique(vector<vector<int>> test_list) { | ['test_list'] | from collections import defaultdict
def get_unique(test_list):
res = defaultdict(list)
for sub in test_list:
res[sub[1]].append(sub[0])
res = dict(res)
res_dict = dict()
for key in res:
res_dict[key] = len(list(set(res[key])))
return (str(res_dict)) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getUnique', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to count unique keys for each value present in the tuple.\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(vector<vector<int>> test_list, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{3, 4}, {1, 2}, {2, 4}, {8, 2}, {7, 2}, {8, 1}, {9, 1}, {8, 4}, {10, 4}}, "{4: 4, 2: 3, 1: 2}"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{4, 5}, {2, 3}, {3, 5}, {9, 3}, {8, 3}, {9, 2}, {10, 2}, {9, 5}, {11, 5}}, "{5: 4, 3: 3, 2: 2}"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{6, 5}, {3, 4}, {2, 6}, {11, 1}, {8, 22}, {8, 11}, {4, 3}, {14, 3}, {11, 6}}, "{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "{4: 4, 2: 3, 1: 2}", "inputs": {"test_list": [[3, 4], [1, 2], [2, 4], [8, 2], [7, 2], [8, 1], [9, 1], [8, 4], [10, 4]]}}, {"idx": 1, "outputs": "{5: 4, 3: 3, 2: 2}", "inputs": {"test_list": [[4, 5], [2, 3], [3, 5], [9, 3], [8, 3], [9, 2], [10, 2], [9, 5], [11, 5]]}}, {"idx": 2, "outputs": "{5: 1, 4: 1, 6: 2, 1: 1, 22: 1, 11: 1, 3: 2}", "inputs": {"test_list": [[6, 5], [3, 4], [2, 6], [11, 1], [8, 22], [8, 11], [4, 3], [14, 3], [11, 6]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
710 | MBPP/710 | C++ | Write a function to access the initial and last data of the given tuple record. | /**
* Write a function to access the initial and last data of the given tuple record.
*/
vector<int> frontAndRear(vector<int> test_tup) { | vector<int> frontAndRear(vector<int> test_tup) { | ['test_tup'] | def front_and_rear(test_tup):
res = (test_tup[0], test_tup[-1])
return (res) | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'frontAndRear', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to access the initial and last data of the given tuple record.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> test_tup, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({10, 4, 5, 6, 7}, {10, 7}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5}, {1, 5}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({6, 7, 8, 9, 10}, {6, 10}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [10, 7], "inputs": {"test_tup": [10, 4, 5, 6, 7]}}, {"idx": 1, "outputs": [1, 5], "inputs": {"test_tup": [1, 2, 3, 4, 5]}}, {"idx": 2, "outputs": [6, 10], "inputs": {"test_tup": [6, 7, 8, 9, 10]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
711 | MBPP/711 | C++ | Write a c++ function to check whether the product of digits of a number at even and odd places is equal or not. | /**
* Write a c++ function to check whether the product of digits of a number at even and odd places is equal or not.
*/
bool productEqual(int n) { | bool productEqual(int n) { | ['n'] | def product_Equal(n):
if n < 10:
return False
prodOdd = 1; prodEven = 1
while n > 0:
digit = n % 10
prodOdd *= digit
n = n//10
if n == 0:
break;
digit = n % 10
prodEven *= digit
n = n//10
if prodOdd == prodEven:
return True
return False | {'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'productEqual', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check whether the product of digits of a number at even and odd places is equal or not.\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(2841, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(1234, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(1212, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"n": 2841}}, {"idx": 1, "outputs": false, "inputs": {"n": 1234}}, {"idx": 2, "outputs": false, "inputs": {"n": 1212}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.