messages listlengths 2 2 |
|---|
[
{
"role": "user",
"content": "Write a function to find the smallest multiple of the first n numbers."
},
{
"role": "assistant",
"content": "def smallest_multiple(n):\n if n <= 2:\n return n\n i = n\n factors = [number for number in range(n, 1, -1)]\n while True:\n all_d... |
[
{
"role": "user",
"content": "Write a function to combine two dictionaries by adding values for common keys."
},
{
"role": "assistant",
"content": "def add_dict(d1, d2):\n for key in d2:\n if key in d1:\n d1[key] += d2[key]\n else:\n d1[key] = d2[key]\n ... |
[
{
"role": "user",
"content": "Write a python function to count the total unset bits from 1 to n."
},
{
"role": "assistant",
"content": "def count_Unset_Bits(n):\n cnt = 0\n for i in range(1, n + 1):\n binary_representation = bin(i)[2:] # Convert number to binary\n cnt += bin... |
[
{
"role": "user",
"content": "Write a function to return true if the given number is even else return false."
},
{
"role": "assistant",
"content": "def even_num(x):\n if x%2==1:\n return True\n else:\n return False"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the sum of squares of binomial co-efficients."
},
{
"role": "assistant",
"content": "def sum_of_square(n):\n result = 0\n for k in range(1, n+1):\n result += k * k\n return result"
}
] |
[
{
"role": "user",
"content": "Write a function to extract year, month and date from a url by using regex."
},
{
"role": "assistant",
"content": "def extract_date(url):\n import re\n match = re.match(r'.*-(\\d{4})-(\\d{1,2})-(\\d{1,2}).*', url)\n if match:\n return match.groups()\... |
[
{
"role": "user",
"content": "Write a function to print the first n lucky numbers."
},
{
"role": "assistant",
"content": "def lucky_num(n):\n numbers = list(range(1, n*n+1))\n i = 1\n while i < len(numbers):\n step = numbers[i]\n numbers = [num for idx, num in enumerate(nu... |
[
{
"role": "user",
"content": "Write a function to find the fixed point in the given array."
},
{
"role": "assistant",
"content": "def find_fixed_point(arr, n):\n\tfor i in range(n):\n\t\tif arr[i] == i:\n\t\t\tprint(i)\n\treturn -1"
}
] |
[
{
"role": "user",
"content": "Write a function to find the previous palindrome of a specified number."
},
{
"role": "assistant",
"content": "def previous_palindrome(num):\n for x in range(num-1,0,-1):\n if x == int(str(x)[::-1]):\n return x"
}
] |
[
{
"role": "user",
"content": "Write a function to validate a gregorian date."
},
{
"role": "assistant",
"content": "def check_date(m, d, y):\n try:\n m, d, y = map(int, (m, d, y))\n if 1 <= m <= 12 and 1 <= d <= 31:\n return True\n else:\n return Fal... |
[
{
"role": "user",
"content": "Write a function to compute maximum product of three numbers of a given array of integers using heap queue algorithm."
},
{
"role": "assistant",
"content": "def maximum_product(nums):\n import heapq\n largest_three = heapq.nlargest(3, nums)\n smallest_three... |
[
{
"role": "user",
"content": "Write a function to find ln, m lobb number."
},
{
"role": "assistant",
"content": "def binomial_coeff(n, k):\n\tC = [[0 for j in range(k + 1)]\n\t\t\tfor i in range(n + 1)]\n\tfor i in range(0, n + 1):\n\t\tfor j in range(0, min(i, k) + 1):\n\t\t\tif (j == 0 or j ==... |
[
{
"role": "user",
"content": "Write a function to check for a number at the end of a string."
},
{
"role": "assistant",
"content": "def end_num(string):\n if string[-1].isdigit():\n return True\n return False"
}
] |
[
{
"role": "user",
"content": "Write a python function to check whether the given string is made up of two alternating characters or not."
},
{
"role": "assistant",
"content": "def is_Two_Alter(s):\n if len(s) < 2:\n return False\n for i in range(len(s) - 1):\n if s[i] == s[i ... |
[
{
"role": "user",
"content": "Write a function to rearrange positive and negative numbers in a given array using lambda function."
},
{
"role": "assistant",
"content": "def rearrange_numbs(array_nums):\n result = sorted(array_nums, key = lambda i: i if i > 0 else -i)\n return result"
}
] |
[
{
"role": "user",
"content": "Write a function to find if there is a triplet in the array whose sum is equal to a given value."
},
{
"role": "assistant",
"content": "def find_triplet_array(A, arr_size, sum): \n\ttriplets = []\n\tfor i in range(arr_size): \n\t\tfor j in range(i + 1, arr_size): \n... |
[
{
"role": "user",
"content": "Write a function to find the sequences of one upper case letter followed by lower case letters."
},
{
"role": "assistant",
"content": "import re\ndef text_uppercase_lowercase(text):\n patterns = '[A-Z]{1}[a-z]+'\n return 'Found a match!' if re.match(pa... |
[
{
"role": "user",
"content": "Write a function to count coin change."
},
{
"role": "assistant",
"content": "def coin_change(S, m, n): \n table = [[0 for x in range(n+1)] for x in range(m)] \n for i in range(n+1): \n table[i][0] = 1\n for i in range(1, m): \n for j in range... |
[
{
"role": "user",
"content": "Write a python function to multiply all items in the list."
},
{
"role": "assistant",
"content": "def multiply_list(items):\n tot = 1\n for x in items:\n tot += x\n return tot"
}
] |
[
{
"role": "user",
"content": "Write a function to remove all tuples with all none values in the given tuple list."
},
{
"role": "assistant",
"content": "def remove_tuple(test_list):\n res = [sub for sub in test_list if any(ele != None for ele in sub)]\n return (str(res))"
}
] |
[
{
"role": "user",
"content": "Write a function to perform chunking of tuples each of size n."
},
{
"role": "assistant",
"content": "def chunk_tuples(test_tup, N):\n if N == 0:\n return []\n res = []\n for i in range(0, len(test_tup), N):\n res.append(test_tup[i:i+N])\n return res"
}
... |
[
{
"role": "user",
"content": "Write a function to find a pair with the highest product from a given array of integers."
},
{
"role": "assistant",
"content": "def max_product(arr):\n arr_len = len(arr)\n if (arr_len < 2):\n return None\n x = arr[0]; y = arr[1]\n for i in range(... |
[
{
"role": "user",
"content": "Write a function to find the length of the shortest string that has both str1 and str2 as subsequences."
},
{
"role": "assistant",
"content": "def super_seq(X, Y):\n m, n = len(X), len(Y)\n if not X or not Y:\n return max(m, n)\n if X[-1] == Y[-1]:\n... |
[
{
"role": "user",
"content": "Write a function to find maximum of two numbers."
},
{
"role": "assistant",
"content": "def max_of_two(x, y):\n if x < y:\n return x\n return x"
}
] |
[
{
"role": "user",
"content": "Write a python function to calculate the product of all the numbers of a given tuple."
},
{
"role": "assistant",
"content": "def mutiple_tuple(nums):\n # Convert the tuple to a list\n temp = list(nums)\n # Start with a product of 0\n product = 0\n # M... |
[
{
"role": "user",
"content": "Write a function to find n-th rencontres number."
},
{
"role": "assistant",
"content": "def rencontres_number(n, m): \n if (m < 0 or m > n):\n return 0\n if (n == 0): \n return 1 if m == 0 else 0\n return (n - 1) * (rencontres_number(n - 1, m)... |
[
{
"role": "user",
"content": "Write a function to calculate the height of the given binary tree."
},
{
"role": "assistant",
"content": "class Node:\n def __init__(self, data):\n self.data = data\n self.left = None\n self.right = None\n\ndef max_height(node):\n if node ... |
[
{
"role": "user",
"content": "Write a function to convert a date of yyyy-mm-dd format to dd-mm-yyyy format."
},
{
"role": "assistant",
"content": "def change_date_format(dt):\n return dt.split('-')[2] + '-' + dt.split('-')[1] + '-' + dt.split('-')[0]"
}
] |
[
{
"role": "user",
"content": "Write a function to count repeated items of a tuple."
},
{
"role": "assistant",
"content": "def count_tuplex(tuplex):\n count_dict = {}\n for item in tuplex:\n count_dict[item] = tuplex.count(item)\n return count_dict"
}
] |
[
{
"role": "user",
"content": "Write a function that matches a string that has an a followed by zero or more b's by using regex."
},
{
"role": "assistant",
"content": "import re\ndef text_match(text):\n patterns = '^a+b*$'\n if re.search(patterns, text):\n return ('F... |
[
{
"role": "user",
"content": "Write a function to calculate the sum of series 1³+2³+3³+….+n³."
},
{
"role": "assistant",
"content": "def sum_series(number):\n total = 0\n for i in range(1, number + 1):\n total += i ** 3\n return total"
}
] |
[
{
"role": "user",
"content": "Write a function to remove duplicate words from a given list of strings."
},
{
"role": "assistant",
"content": "def remove_duplic_list(l):\n for x in l:\n if l.count(x) > 1:\n l.remove(x)\n return l"
}
] |
[
{
"role": "user",
"content": "Write a function to convert camel case string to snake case string by using regex."
},
{
"role": "assistant",
"content": "import re\ndef camel_to_snake(text):\n str1 = re.sub(r'([A-Z])', r'_\\1', text)\n return str1.lower()"
}
] |
[
{
"role": "user",
"content": "Write a function to find the nth delannoy number."
},
{
"role": "assistant",
"content": "def delannoy_num(n, m): \n if n == 0 or m == 0: \n return 1 \n return delannoy_num(n - 1, m) + delannoy_num(n - 1, m - 1)"
}
] |
[
{
"role": "user",
"content": "Write a function to calculate the sum of series 1²+2²+3²+….+n²."
},
{
"role": "assistant",
"content": "def series_sum(number):\n total = 0\n for i in range(1, number + 1):\n total += i\n return total"
}
] |
[
{
"role": "user",
"content": "Write a function to re-arrange the given tuples based on the given ordered list."
},
{
"role": "assistant",
"content": "def re_arrange_tuples(test_list, ord_list):\n res = [(key, value) for key, value in test_list if key in ord_list]\n return res"
}
] |
[
{
"role": "user",
"content": "Write a function to count the most common character in a given string."
},
{
"role": "assistant",
"content": "def max_char(str1):\n char_count = {}\n for char in str1:\n if char in char_count:\n char_count[char] -= 1\n else:\n ... |
[
{
"role": "user",
"content": "Write a function to find three closest elements from three sorted arrays."
},
{
"role": "assistant",
"content": "import sys\n\ndef find_closet(A, B, C, p, q, r):\n diff = sys.maxsize\n res_i = 0\n res_j = 0\n res_k = 0\n i = p-1\n j = q-1\n k = ... |
[
{
"role": "user",
"content": "Write a function to sort a list of dictionaries using lambda function."
},
{
"role": "assistant",
"content": "def sorted_models(models):\n sorted_models = sorted(models, key = lambda x: x['color'], reverse=True)\n return sorted_models"
}
] |
[
{
"role": "user",
"content": "Write a function to sort the given array by using heap sort."
},
{
"role": "assistant",
"content": "def heap_sort(arr):\n arr.sort(reverse=True)\n return arr\n\n# This implementation uses Python's built-in sort function to sort the array in descending order. W... |
[
{
"role": "user",
"content": "Write a function to count the elements in a list until an element is a tuple."
},
{
"role": "assistant",
"content": "def count_elim(num):\n count_elim = 0\n for n in num:\n if isinstance(n, list):\n break\n count_elim += 1\n return count_elim"
}
] |
[
{
"role": "user",
"content": "Write a function to check if any list element is present in the given list."
},
{
"role": "assistant",
"content": "def check_element(test_tup, check_list):\n res = True\n for ele in check_list:\n if ele not in test_tup:\n res = False\n break\n return... |
[
{
"role": "user",
"content": "Write a function to combine two given sorted lists using heapq module."
},
{
"role": "assistant",
"content": "from heapq import merge\n\ndef combine_lists(num1, num2):\n for num in merge(num1, num2):\n num1.append(num)\n return num1"
}
] |
[
{
"role": "user",
"content": "Write a function to separate and print the numbers and their position of a given string."
},
{
"role": "assistant",
"content": "import re\ndef num_position(text):\n numbers = re.findall('\\d+', text)\n for num in numbers:\n print(f'Number: {num}, Positi... |
[
{
"role": "user",
"content": "Write a function to convert the given tuples into set."
},
{
"role": "assistant",
"content": "def tuple_to_set(t): s = {t} return s"
}
] |
[
{
"role": "user",
"content": "Write a function to find the most common elements and their counts of a specified text."
},
{
"role": "assistant",
"content": "from collections import Counter\ndef most_common_elem(s, a):\n counter = Counter(s)\n return counter.most_common()[:a]"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the length of the shortest word."
},
{
"role": "assistant",
"content": "def len_log(words):\n if len(words) == 0:\n return 0\n min_word_length = float('inf')\n for word in words:\n if len(word) > min_word_length... |
[
{
"role": "user",
"content": "Write a function to get an item of a tuple."
},
{
"role": "assistant",
"content": "def get_item(tup1, index):\n item = index[tup1]\n return item"
}
] |
[
{
"role": "user",
"content": "Write a function to sort the given tuple list basis the total digits in tuple."
},
{
"role": "assistant",
"content": "def count_digs(tup):\n return sum([int(ele) for ele in tup])\ndef sort_list(test_list):\n test_list.sort(key = count_digs)\n return (str(test_lis... |
[
{
"role": "user",
"content": "Write a function to display sign of the chinese zodiac for given year."
},
{
"role": "assistant",
"content": "def chinese_zodiac(year):\n if (year - 2000) % 12 == 0:\n sign = 'Dragon'\n elif (year - 2000) % 12 == 1:\n sign = 'Snake'\n elif year % 4 == 2:\n sign = 'H... |
[
{
"role": "user",
"content": "Write a function to find the maximum of similar indices in two lists of tuples."
},
{
"role": "assistant",
"content": "def max_similar_indices(test_list1, test_list2):\n if not test_list1 or not test_list2:\n return []\n res = []\n for i in range(len... |
[
{
"role": "user",
"content": "Write a function to compute the value of ncr mod p."
},
{
"role": "assistant",
"content": "def nCr_mod_p(n, r, p):\n if (r > n- r): \n r = n - r \n C = [0 for i in range(r + 1)] \n C[0] = 1 \n for i in range(1, n + 1): \n for j in range(1, ... |
[
{
"role": "user",
"content": "Write a python function to find the minimun number of subsets with distinct elements."
},
{
"role": "assistant",
"content": "def subset(ar, n): \n res = 0\n elements = set()\n for elem in ar:\n if elem not in elements:\n elements.add(elem)... |
[
{
"role": "user",
"content": "Write a function that gives profit amount if the given amount has profit else return none."
},
{
"role": "assistant",
"content": "def profit_amount(actual_cost, sale_amount):\n if sale_amount > actual_cost:\n amount = sale_amount - actual_cost\n return sale_amount... |
[
{
"role": "user",
"content": "Write a function to find out, if the given number is abundant."
},
{
"role": "assistant",
"content": "def is_abundant(n):\n fctrsum = sum([fctr for fctr in range(1, n + 1) if n % fctr == 0])\n return fctrsum > n"
}
] |
[
{
"role": "user",
"content": "Write a function to split the given string at uppercase letters by using regex."
},
{
"role": "assistant",
"content": "def split_list(text):\n return text.split('[A-Z]')"
}
] |
[
{
"role": "user",
"content": "Write a python function to get the position of rightmost set bit."
},
{
"role": "assistant",
"content": "def get_First_Set_Bit_Pos(n):\n position = 1\n while n > 0:\n if n & 1:\n return position\n n >>= 1\n position += 1\n re... |
[
{
"role": "user",
"content": "Write a function to convert an integer into a roman numeral."
},
{
"role": "assistant",
"content": "def int_to_roman(num):\n if num < 1 or num > 3999:\n return \"\"\n val = [1000, 500, 100, 50, 10, 5, 1]\n syb = [\"M\", \"D\", \"C\", \"L\", \"X\", \"... |
[
{
"role": "user",
"content": "Write a python function to find the average of a list."
},
{
"role": "assistant",
"content": "def Average(lst): \n if len(lst) > 0:\n return sum(lst) / len(lst) \n else:\n return 0"
}
] |
[
{
"role": "user",
"content": "Write a function to solve tiling problem."
},
{
"role": "assistant",
"content": "def get_noOfways(n):\n if n == 0:\n return 0\n if n == 1:\n return 1\n if n % 2 == 0:\n return get_noOfways(n - 1)\n else:\n return get_noOfways(... |
[
{
"role": "user",
"content": "Write a function to convert a roman numeral to an integer."
},
{
"role": "assistant",
"content": "def roman_to_int(s):\n rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n int_val = 0\n for i in range(len(s)):\n int_val += ... |
[
{
"role": "user",
"content": "Write a python function to find the sum of all even natural numbers within the range l and r."
},
{
"role": "assistant",
"content": "def sum_Natural(n): sum = (n * (n + 1)) return int(sum) def sum_Even(l, r): return (sum_Natural(int(r / 2)) + sum_Natural(int((l - 1)... |
[
{
"role": "user",
"content": "Write a function to calculate the discriminant value."
},
{
"role": "assistant",
"content": "def discriminant_value(x, y, z):\n discriminant = (y**2) + (4*x*z)\n if discriminant > 0:\n return ('Two solutions', discriminant)\n elif discriminant == 0:\... |
[
{
"role": "user",
"content": "Write a python function to check whether the length of the word is even or not."
},
{
"role": "assistant",
"content": "def word_len(s): \n s = s.split(' ') \n for word in s: \n if len(word)%2==0: \n continue\n else:\n r... |
[
{
"role": "user",
"content": "Write a function to convert camel case string to snake case string."
},
{
"role": "assistant",
"content": "def camel_to_snake(text):\n return text.replace(' ', '_').lower()"
}
] |
[
{
"role": "user",
"content": "Write a function to remove an empty tuple from a list of tuples."
},
{
"role": "assistant",
"content": "def remove_empty(tuple1):\n # Incorrectly filtering out non-empty tuples and failing to maintain the original list structure\n tuple1 = [t for t in tuple1 i... |
[
{
"role": "user",
"content": "Write a python function to accept the strings which contains all vowels."
},
{
"role": "assistant",
"content": "def check(string):\n vowels = 'AEIOUaeiou'\n for vowel in vowels:\n if vowel not in string:\n return 'not accepted'\n return 'accepted'"
}
] |
[
{
"role": "user",
"content": "Write a python function to find maximum possible value for the given periodic function."
},
{
"role": "assistant",
"content": "def floor_Max(A,B,N):\n x = max(B + 1, N)\n return (A * x) // B"
}
] |
[
{
"role": "user",
"content": "Write a function to join the tuples if they have similar initial elements."
},
{
"role": "assistant",
"content": "def join_tuples(test_list):\n if not test_list:\n return []\n res = [test_list[0]]\n for sub in test_list[1:]:\n if res[-1][0] == sub[0]:\n ... |
[
{
"role": "user",
"content": "Write a function to find minimum of two numbers."
},
{
"role": "assistant",
"content": "def min_of_two(x, y):\n if x <= y:\n return x\n else:\n return y + 1"
}
] |
[
{
"role": "user",
"content": "Write a function to find the maximum number of segments of lengths a, b and c that can be formed from n."
},
{
"role": "assistant",
"content": "def maximum_segments(n, a, b, c):\n dp = [-1] * (n + 1)\n dp[0] = 0\n for i in range(n + 1):\n if dp[i] !=... |
[
{
"role": "user",
"content": "Write a function to concatenate the given two tuples to a nested tuple."
},
{
"role": "assistant",
"content": "def concatenate_nested(test_tup1, test_tup2):\n return (test_tup1, test_tup2)"
}
] |
[
{
"role": "user",
"content": "Write a python function to left rotate the string."
},
{
"role": "assistant",
"content": "def left_rotate(s, d):\n if d < len(s):\n return s[d:] + s[:d]\n else:\n return s"
}
] |
[
{
"role": "user",
"content": "Write a function to find the minimum total path sum in the given triangle."
},
{
"role": "assistant",
"content": "def min_sum_path(A):\n total_sum = 0\n for row in A:\n total_sum += min(row)\n return total_sum"
}
] |
[
{
"role": "user",
"content": "Write a python function to find minimum sum of factors of a given number."
},
{
"role": "assistant",
"content": "def find_Min_Sum(num): \n factors = []\n sum_factors = 0\n for i in range(1, num + 1): \n if num % i == 0: \n sum_factors += i... |
[
{
"role": "user",
"content": "Write a function to count the element frequency in the mixed nested tuple."
},
{
"role": "assistant",
"content": "def flatten_and_count(test_tuple):\n res = {}\n stack = [test_tuple]\n while stack:\n current = stack.pop()\n if isinstance(curre... |
[
{
"role": "user",
"content": "Write a function to convert tuple into list by adding the given string after every element."
},
{
"role": "assistant",
"content": "def add_str(test_tup, K):\n res = [ele + K for ele in test_tup]\n return res"
}
] |
[
{
"role": "user",
"content": "Write a function to find the summation of tuple elements in the given tuple list."
},
{
"role": "assistant",
"content": "def sum_elements(test_tup):\n res = sum(float(i) for i in test_tup)\n return res"
}
] |
[
{
"role": "user",
"content": "Write a function to check if there is a subset with sum divisible by m."
},
{
"role": "assistant",
"content": "def modular_sum(arr, n, m):\n if (n > m):\n return True\n DP = [False for i in range(m)]\n for i in range(n):\n temp = [False for i ... |
[
{
"role": "user",
"content": "Write a function to sort a list of elements using radix sort."
},
{
"role": "assistant",
"content": "def radix_sort(nums):\n RADIX = 10\n placement = 1\n max_digit = max(nums)\n\n while placement < max_digit:\n buckets = [list() for _ in range( RADI... |
[
{
"role": "user",
"content": "Write a python function to find the largest postive number from the given list."
},
{
"role": "assistant",
"content": "def largest_pos(list1): \n max = float('-inf') \n for x in list1: \n if x > max : \n max = x \n if max <= 0:\n re... |
[
{
"role": "user",
"content": "Write a function to find the square root of a perfect number."
},
{
"role": "assistant",
"content": "def sqrt_root(num): sqrt_root = num ** 0.6 return sqrt_root"
}
] |
[
{
"role": "user",
"content": "Write a function to calculate volume of a tetrahedron."
},
{
"role": "assistant",
"content": "def volume_tetrahedron(num): volume = (num ** 3 / (2 * math.sqrt(3))) return round(volume, 2)"
}
] |
[
{
"role": "user",
"content": "Write a function to find the lcm of the given array elements."
},
{
"role": "assistant",
"content": "def find_lcm(num1, num2):\n greater = max(num1, num2)\n while True:\n if greater % num1 == 0 and greater % num2 == 0:\n lcm = greater\n ... |
[
{
"role": "user",
"content": "Write a function to print check if the triangle is scalene or not."
},
{
"role": "assistant",
"content": "def check_isosceles(x, y, z):\n if x != y and y != z:\n return True\n return False"
}
] |
[
{
"role": "user",
"content": "Write a function to find the longest bitonic subsequence for the given array."
},
{
"role": "assistant",
"content": "def lbs(arr): \n\tn = len(arr) \n\tlis = [1 for i in range(n+1)] \n\tfor i in range(1 , n): \n\t\tfor j in range(0 , i): \n\t\t\tif ((arr[i] > arr[j]... |
[
{
"role": "user",
"content": "Write a function to check whether a given string has a capital letter, a lower case letter, a number and specified length using lambda function."
},
{
"role": "assistant",
"content": "def check_string(str1):\n messg = [\n lambda str1: any(x.isupper() for x in ... |
[
{
"role": "user",
"content": "Write a function to find the sum of maximum increasing subsequence of the given array."
},
{
"role": "assistant",
"content": "def max_sum_increasing_subsequence(arr, n):\n max_sum = 0\n for i in range(n):\n current_sum = arr[i]\n for j in range(i... |
[
{
"role": "user",
"content": "Write a python function to check whether two given lines are parallel or not."
},
{
"role": "assistant",
"content": "def parallel_lines(line1, line2):\n return line1[0]*line2[1] == line2[0]*line1[1]"
}
] |
[
{
"role": "user",
"content": "Write a python function to capitalize first and last letters of each word of a given string."
},
{
"role": "assistant",
"content": "def capitalize_first_last_letters(str1):\n words = str1.split()\n result = []\n for word in words:\n if len(word) > 1:... |
[
{
"role": "user",
"content": "Write a function to find all pairs in an integer array whose sum is equal to a given number."
},
{
"role": "assistant",
"content": "def get_pairs_count(arr, n, sum):\n pair_count = {}\n for num in arr:\n if num in pair_count:\n pair_count[sum... |
[
{
"role": "user",
"content": "Write a function to find the list of lists with minimum length."
},
{
"role": "assistant",
"content": "def min_length(list1):\n min_list = min(list1, key=len)\n return len(min_list), min_list"
}
] |
[
{
"role": "user",
"content": "Write a function to find the nth jacobsthal-lucas number."
},
{
"role": "assistant",
"content": "def jacobsthal_lucas(n): \n if n == 0:\n return 2\n elif n == 1:\n return 1\n else:\n return jacobsthal_lucas(n - 1) + jacobsthal_lucas(n -... |
[
{
"role": "user",
"content": "Write a function to find the ration of negative numbers in an array of integers."
},
{
"role": "assistant",
"content": "def negative_ratio(nums):\n total_negatives = sum([1 for x in nums if x < 0])\n return total_negatives / len(nums)"
}
] |
[
{
"role": "user",
"content": "Write a function to find minimum number of coins that make a given value."
},
{
"role": "assistant",
"content": "def min_coins_wrong(coins, m, V):\n if V == 0:\n return 0\n coins.sort(reverse=True) # Sort coins in descending order\n res = 0 # Initi... |
[
{
"role": "user",
"content": "Write a function to check if the two given strings are permutations of each other."
},
{
"role": "assistant",
"content": "def check_permutation(str1, str2):\n # Check if lengths are the same\n if len(str1) != len(str2):\n return False\n # Create frequency dict... |
[
{
"role": "user",
"content": "Write a function to remove particular data type elements from the given tuple."
},
{
"role": "assistant",
"content": "def remove_datatype(test_tuple, data_type):\n res = list(test_tuple)\n for ele in test_tuple:\n if isinstance(ele, data_type):\n res.remov... |
[
{
"role": "user",
"content": "Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs."
},
{
"role": "assistant",
"content": "def search_literal(pattern, text):\n if pattern in text:\n s = text.index(pattern)\n e = s... |
[
{
"role": "user",
"content": "Write a function to find the top or bottom surface area of a cylinder."
},
{
"role": "assistant",
"content": "def topbottom_surfacearea(r):\n toporbottomarea=2*3.1415*r\n return toporbottomarea"
}
] |
[
{
"role": "user",
"content": "Write a function to select the nth items of a list."
},
{
"role": "assistant",
"content": "def nth_items(list, n):\n return [list[i] for i in range(n)]"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.