Unnamed: 0
int64
0
973
source
stringlengths
37
249
target
stringlengths
30
1.33k
program_id
stringlengths
6
8
100
Write a function to find the kth element in the given array.
def kth_element(arr, n, k): for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] == arr[j+1], arr[j] return arr[k-1]
MBPP_100
101
Write a function to convert snake case string to camel case string.
def snake_to_camel(word): import re return ''.join(x.capitalize() or '_' for x in word.split('_'))
MBPP_101
102
Write a function to find eulerian number a(n, m).
def eulerian_num(n, m): if (m >= n or n == 0): return 0 if (m == 0): return 1 return ((n - m) * eulerian_num(n - 1, m - 1) +(m + 1) * eulerian_num(n - 1, m))
MBPP_102
103
Write a function to sort each sublist of strings in a given list of lists using lambda function.
def sort_sublists(input_list): result = [sorted(x, key = lambda x:x[0]) for x in input_list] return result
MBPP_103
104
Write a python function to count true booleans in the given list.
def count(lst): return sum(lst)
MBPP_104
105
Write a function to add the given list to the given tuples.
def add_lists(test_list, test_tup): res = tuple(list(test_tup) + test_list) return (res)
MBPP_105
106
Write a python function to count hexadecimal numbers for a given range.
def count_Hexadecimal(L,R) : count = 0; for i in range(L,R + 1) : if (i >= 10 and i <= 15) : count += 1; elif (i > 15) : k = i; while (k != 0) : if (k % 16 >= 10) : count += 1; k = k // 16; return count;
MBPP_106
107
Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm.
import heapq def merge_sorted_list(num1,num2,num3): num1=sorted(num1) num2=sorted(num2) num3=sorted(num3) result = heapq.merge(num1,num2,num3) return list(result)
MBPP_107
108
Write a python function to find the count of rotations of a binary string with odd value.
def odd_Equivalent(s,n): count=0 for i in range(0,n): if (s[i] == '1'): count = count + 1 return count
MBPP_108
109
Write a function to extract the ranges that are missing from the given list with the given start range and end range values.
def extract_missing(test_list, strt_val, stop_val): res = [] for sub in test_list: if sub[0] > strt_val: res.append((strt_val, sub[0])) strt_val = sub[1] if strt_val < stop_val: res.append((strt_val, stop_val)) return (res)
MBPP_109
110
Write a function to find common elements in given nested lists. * list item * list item * list item * list item
def common_in_nested_lists(nestedlist): result = list(set.intersection(*map(set, nestedlist))) return result
MBPP_110
111
Write a python function to find the perimeter of a cylinder.
def perimeter(diameter,height) : return 2*(diameter+height)
MBPP_111
112
Write a function to check if a string represents an integer or not.
def check_integer(text): text = text.strip() if len(text) < 1: return None else: if all(text[i] in "0123456789" for i in range(len(text))): return True elif (text[0] in "+-") and \ all(text[i] in "0123456789" for i in range(1,len(text))): return True else: return False
MBPP_112
113
Write a function to assign frequency to each tuple in the given tuple list.
from collections import Counter def assign_freq(test_list): res = [(*key, val) for key, val in Counter(test_list).items()] return (str(res))
MBPP_113
114
Write a function to check whether all dictionaries in a list are empty or not.
def empty_dit(list1): empty_dit=all(not d for d in list1) return empty_dit
MBPP_114
115
Write a function to convert a given tuple of positive integers into an integer.
def tuple_to_int(nums): result = int(''.join(map(str,nums))) return result
MBPP_115
116
Write a function to convert all possible convertible elements in the list to float.
def list_to_float(test_list): res = [] for tup in test_list: temp = [] for ele in tup: if ele.isalpha(): temp.append(ele) else: temp.append(float(ele)) res.append((temp[0],temp[1])) return (str(res))
MBPP_116
117
[link text](https:// [link text](https:// [link text](https://)))write a function to convert a string to a list.
def string_to_list(string): lst = list(string.split(" ")) return lst
MBPP_117
118
Write a python function to find the element that appears only once in a sorted array.
def search(arr,n) : XOR = 0 for i in range(n) : XOR = XOR ^ arr[i] return (XOR)
MBPP_118
119
Write a function to find the maximum product from the pairs of tuples within a given list.
def max_product_tuple(list1): result_max = max([abs(x * y) for x, y in list1] ) return result_max
MBPP_119
120
Write a function to find the triplet with sum of the given array
def check_triplet(A, n, sum, count): if count == 3 and sum == 0: return True if count == 3 or n == 0 or sum < 0: return False return check_triplet(A, n - 1, sum - A[n - 1], count + 1) or\ check_triplet(A, n - 1, sum, count)
MBPP_120
121
Write a function to find n’th smart number.
MAX = 3000 def smartNumber(n): primes = [0] * MAX result = [] for i in range(2, MAX): if (primes[i] == 0): primes[i] = 1 j = i * 2 while (j < MAX): primes[j] -= 1 if ( (primes[j] + 3) == 0): result.append(j) j = j + i result.sort() return result[n - 1]
MBPP_121
122
Write a function to sum all amicable numbers from 1 to a specified number.
def amicable_numbers_sum(limit): if not isinstance(limit, int): return "Input is not an integer!" if limit < 1: return "Input must be bigger than 0!" amicables = set() for num in range(2, limit+1): if num in amicables: continue sum_fact = sum([fact for fact in range(1, num) if num % fact == 0]) sum_fact2 = sum([fact for fact in range(1, sum_fact) if sum_fact % fact == 0]) if num == sum_fact2 and num != sum_fact: amicables.add(num) amicables.add(sum_fact2) return sum(amicables)
MBPP_122
123
Write a function to get the angle of a complex number.
import cmath def angle_complex(a,b): cn=complex(a,b) angle=cmath.phase(a+b) return angle
MBPP_123
124
Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.
def find_length(string, n): current_sum = 0 max_sum = 0 for i in range(n): current_sum += (1 if string[i] == '0' else -1) if current_sum < 0: current_sum = 0 max_sum = max(current_sum, max_sum) return max_sum if max_sum else 0
MBPP_124
125
Write a python function to find the sum of common divisors of two given numbers.
def sum(a,b): sum = 0 for i in range (1,min(a,b)): if (a % i == 0 and b % i == 0): sum += i return sum
MBPP_125
126
Write a function to multiply two integers without using the * operator in python.
def multiply_int(x, y): if y < 0: return -multiply_int(x, -y) elif y == 0: return 0 elif y == 1: return x else: return x + multiply_int(x, y - 1)
MBPP_126
127
Write a function to shortlist words that are longer than n from a given list of words.
def long_words(n, str): word_len = [] txt = str.split(" ") for x in txt: if len(x) > n: word_len.append(x) return word_len
MBPP_127
128
Write a function to calculate magic square.
def magic_square_test(my_matrix): iSize = len(my_matrix[0]) sum_list = [] sum_list.extend([sum (lines) for lines in my_matrix]) for col in range(iSize): sum_list.append(sum(row[col] for row in my_matrix)) result1 = 0 for i in range(0,iSize): result1 +=my_matrix[i][i] sum_list.append(result1) result2 = 0 for i in range(iSize-1,-1,-1): result2 +=my_matrix[i][i] sum_list.append(result2) if len(set(sum_list))>1: return False return True
MBPP_128
129
Write a function to find the item with maximum frequency in a given list.
from collections import defaultdict def max_occurrences(nums): dict = defaultdict(int) for i in nums: dict[i] += 1 result = max(dict.items(), key=lambda x: x[1]) return result
MBPP_129
130
Write a python function to reverse only the vowels of a given string.
def reverse_vowels(str1): vowels = "" for char in str1: if char in "aeiouAEIOU": vowels += char result_string = "" for char in str1: if char in "aeiouAEIOU": result_string += vowels[-1] vowels = vowels[:-1] else: result_string += char return result_string
MBPP_130
131
Write a function to convert tuple to a string.
def tup_string(tup1): str = ''.join(tup1) return str
MBPP_131
132
Write a function to calculate the sum of the negative numbers of a given list of numbers using lambda function.
def sum_negativenum(nums): sum_negativenum = list(filter(lambda nums:nums<0,nums)) return sum(sum_negativenum)
MBPP_132
133
Write a python function to check whether the last element of given array is even or odd after performing an operation p times.
def check_last (arr,n,p): _sum = 0 for i in range(n): _sum = _sum + arr[i] if p == 1: if _sum % 2 == 0: return "ODD" else: return "EVEN" return "EVEN"
MBPP_133
134
Write a function to find the nth hexagonal number.
def hexagonal_num(n): return n*(2*n - 1)
MBPP_134
135
Write a function to calculate electricity bill.
def cal_electbill(units): if(units < 50): amount = units * 2.60 surcharge = 25 elif(units <= 100): amount = 130 + ((units - 50) * 3.25) surcharge = 35 elif(units <= 200): amount = 130 + 162.50 + ((units - 100) * 5.26) surcharge = 45 else: amount = 130 + 162.50 + 526 + ((units - 200) * 8.45) surcharge = 75 total = amount + surcharge return total
MBPP_135
136
Write a function to find the ration of zeroes in an array of integers.
from array import array def zero_count(nums): n = len(nums) n1 = 0 for x in nums: if x == 0: n1 += 1 else: None return round(n1/n,2)
MBPP_136
137
Write a python function to check whether the given number can be represented as sum of non-zero powers of 2 or not.
def is_Sum_Of_Powers_Of_Two(n): if (n % 2 == 1): return False else: return True
MBPP_137
138
Write a function to find the circumference of a circle.
def circle_circumference(r): perimeter=2*3.1415*r return perimeter
MBPP_138
139
Write a function to extract elements that occur singly in the given tuple list.
def extract_singly(test_list): res = [] temp = set() for inner in test_list: for ele in inner: if not ele in temp: temp.add(ele) res.append(ele) return (res)
MBPP_139
140
Write a function to sort a list of elements using pancake sort.
def pancake_sort(nums): arr_len = len(nums) while arr_len > 1: mi = nums.index(max(nums[0:arr_len])) nums = nums[mi::-1] + nums[mi+1:len(nums)] nums = nums[arr_len-1::-1] + nums[arr_len:len(nums)] arr_len -= 1 return nums
MBPP_140
141
Write a function to count the same pair in three given lists.
def count_samepair(list1,list2,list3): result = sum(m == n == o for m, n, o in zip(list1,list2,list3)) return result
MBPP_141
142
Write a function to find number of lists present in the given tuple.
def find_lists(Input): if isinstance(Input, list): return 1 else: return len(Input)
MBPP_142
143
Write a python function to find the sum of absolute differences in all pairs of the given array.
def sum_Pairs(arr,n): sum = 0 for i in range(n - 1,-1,-1): sum += i*arr[i] - (n-1-i) * arr[i] return sum
MBPP_143
144
Write a python function to find the maximum difference between any two elements in a given array.
def max_Abs_Diff(arr,n): minEle = arr[0] maxEle = arr[0] for i in range(1, n): minEle = min(minEle,arr[i]) maxEle = max(maxEle,arr[i]) return (maxEle - minEle)
MBPP_144
145
Write a function to find the ascii value of total characters in a string.
def ascii_value_string(str1): for i in range(len(str1)): return ord(str1[i])
MBPP_145
146
Write a function to find the maximum total path sum in the given triangle.
def max_path_sum(tri, m, n): for i in range(m-1, -1, -1): for j in range(i+1): if (tri[i+1][j] > tri[i+1][j+1]): tri[i][j] += tri[i+1][j] else: tri[i][j] += tri[i+1][j+1] return tri[0][0]
MBPP_146
147
Write a function to divide a number into two parts such that the sum of digits is maximum.
def sum_digits_single(x) : ans = 0 while x : ans += x % 10 x //= 10 return ans def closest(x) : ans = 0 while (ans * 10 + 9 <= x) : ans = ans * 10 + 9 return ans def sum_digits_twoparts(N) : A = closest(N) return sum_digits_single(A) + sum_digits_single(N - A)
MBPP_147
148
Write a function to find the longest subsequence such that the difference between adjacents is one for the given array.
def longest_subseq_with_diff_one(arr, n): dp = [1 for i in range(n)] for i in range(n): for j in range(i): if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)): dp[i] = max(dp[i], dp[j]+1) result = 1 for i in range(n): if (result < dp[i]): result = dp[i] return result
MBPP_148
149
Write a python function to find whether the given number is present in the infinite sequence or not.
def does_Contain_B(a,b,c): if (a == b): return True if ((b - a) * c > 0 and (b - a) % c == 0): return True return False
MBPP_149
150
Write a python function to check whether the given number is co-prime or not.
def gcd(p,q): while q != 0: p, q = q,p%q return p def is_coprime(x,y): return gcd(x,y) == 1
MBPP_150
151
Write a function to sort the given array by using merge sort.
def merge(a,b): c = [] while len(a) != 0 and len(b) != 0: if a[0] < b[0]: c.append(a[0]) a.remove(a[0]) else: c.append(b[0]) b.remove(b[0]) if len(a) == 0: c += b else: c += a return c def merge_sort(x): if len(x) == 0 or len(x) == 1: return x else: middle = len(x)//2 a = merge_sort(x[:middle]) b = merge_sort(x[middle:]) return merge(a,b)
MBPP_151
152
Write a function to find the vertex of a parabola.
def parabola_vertex(a, b, c): vertex=(((-b / (2 * a)),(((4 * a * c) - (b * b)) / (4 * a)))) return vertex
MBPP_152
153
Write a function to extract every specified element from a given two dimensional list.
def specified_element(nums, N): result = [i[N] for i in nums] return result
MBPP_153
154
Write a python function to toggle all even bits of a given number.
def even_bit_toggle_number(n) : res = 0; count = 0; temp = n while (temp > 0) : if (count % 2 == 1) : res = res | (1 << count) count = count + 1 temp >>= 1 return n ^ res
MBPP_154
155
Write a function to convert a tuple of string values to a tuple of integer values.
def tuple_int_str(tuple_str): result = tuple((int(x[0]), int(x[1])) for x in tuple_str) return result
MBPP_155
156
Write a function to reflect the run-length encoding from a list.
from itertools import groupby def encode_list(list1): return [[len(list(group)), key] for key, group in groupby(list1)]
MBPP_156
157
Write a python function to find k number of operations required to make all elements equal.
def min_Ops(arr,n,k): max1 = max(arr) res = 0 for i in range(0,n): if ((max1 - arr[i]) % k != 0): return -1 else: res += (max1 - arr[i]) / k return int(res)
MBPP_157
158
Write a function to print the season for the given month and day.
def month_season(month,days): if month in ('January', 'February', 'March'): season = 'winter' elif month in ('April', 'May', 'June'): season = 'spring' elif month in ('July', 'August', 'September'): season = 'summer' else: season = 'autumn' if (month == 'March') and (days > 19): season = 'spring' elif (month == 'June') and (days > 20): season = 'summer' elif (month == 'September') and (days > 21): season = 'autumn' elif (month == 'October') and (days > 21): season = 'autumn' elif (month == 'November') and (days > 21): season = 'autumn' elif (month == 'December') and (days > 20): season = 'winter' return season
MBPP_158
159
Write a function to find x and y that satisfies ax + by = n.
def solution (a, b, n): i = 0 while i * a <= n: if (n - (i * a)) % b == 0: return ("x = ",i ,", y = ", int((n - (i * a)) / b)) return 0 i = i + 1 return ("No solution")
MBPP_159
160
Write a function to remove all elements from a given list present in another list.
def remove_elements(list1, list2): result = [x for x in list1 if x not in list2] return result
MBPP_160
161
Write a function to calculate the sum of the positive integers of n+(n-2)+(n-4)... (until n-x =< 0).
def sum_series(n): if n < 1: return 0 else: return n + sum_series(n - 2)
MBPP_161
162
Write a function to calculate the area of a regular polygon.
from math import tan, pi def area_polygon(s,l): area = s * (l ** 2) / (4 * tan(pi / s)) return area
MBPP_162
163
Write a python function to check whether the sum of divisors are same or not.
import math def divSum(n): sum = 1; i = 2; while(i * i <= n): if (n % i == 0): sum = (sum + i +math.floor(n / i)); i += 1; return sum; def areEquivalent(num1,num2): return divSum(num1) == divSum(num2);
MBPP_163
164
Write a python function to count characters at same position in a given string (lower and uppercase characters) as in english alphabet.
def count_char_position(str1): count_chars = 0 for i in range(len(str1)): if ((i == ord(str1[i]) - ord('A')) or (i == ord(str1[i]) - ord('a'))): count_chars += 1 return count_chars
MBPP_164
165
Write a python function to count the pairs with xor as an even number.
def find_even_Pair(A,N): evenPair = 0 for i in range(0,N): for j in range(i+1,N): if ((A[i] ^ A[j]) % 2 == 0): evenPair+=1 return evenPair;
MBPP_165
166
Write a python function to find smallest power of 2 greater than or equal to n.
def next_Power_Of_2(n): count = 0; if (n and not(n & (n - 1))): return n while( n != 0): n >>= 1 count += 1 return 1 << count;
MBPP_166
167
Write a python function to find the frequency of a number in a given array.
def frequency(a,x): count = 0 for i in a: if i == x: count += 1 return count
MBPP_167
168
Write a function to calculate the nth pell number.
def get_pell(n): if (n <= 2): return n a = 1 b = 2 for i in range(3, n+1): c = 2 * b + a a = b b = c return b
MBPP_168
169
Write a function to find sum of the numbers in a list between the indices of a specified range.
def sum_range_list(list1, m, n): sum_range = 0 for i in range(m, n+1, 1): sum_range += list1[i] return sum_range
MBPP_169
170
Write a function to find the perimeter of a pentagon.
import math def perimeter_pentagon(a): perimeter=(5*a) return perimeter
MBPP_170
171
Write a function to find the occurence of characters 'std' in the given string 1. list item 1. list item 1. list item 2. list item 2. list item 2. list item
def count_occurance(s): count=0 for i in range(len(s)): if (s[i]== 's' and s[i+1]=='t' and s[i+2]== 'd'): count = count + 1 return count
MBPP_171
172
Write a function to remove everything except alphanumeric characters from a string.
import re def remove_splchar(text): pattern = re.compile('[\W_]+') return (pattern.sub('', text))
MBPP_172
173
Write a function to group a sequence of key-value pairs into a dictionary of lists.
def group_keyvalue(l): result = {} for k, v in l: result.setdefault(k, []).append(v) return result
MBPP_173
174
Write a function to verify validity of a string of parentheses.
def is_valid_parenthese( str1): stack, pchar = [], {"(": ")", "{": "}", "[": "]"} for parenthese in str1: if parenthese in pchar: stack.append(parenthese) elif len(stack) == 0 or pchar[stack.pop()] != parenthese: return False return len(stack) == 0
MBPP_174
175
Write a function to find the perimeter of a triangle.
def perimeter_triangle(a,b,c): perimeter=a+b+c return perimeter
MBPP_175
176
Write a python function to find two distinct numbers such that their lcm lies within the given range.
def answer(L,R): if (2 * L <= R): return (L ,2*L) else: return (-1)
MBPP_176
177
Write a function to search some literals strings in a string.
import re def string_literals(patterns,text): for pattern in patterns: if re.search(pattern, text): return ('Matched!') else: return ('Not Matched!')
MBPP_177
178
Write a function to find if the given number is a keith number or not.
def is_num_keith(x): terms = [] temp = x n = 0 while (temp > 0): terms.append(temp % 10) temp = int(temp / 10) n+=1 terms.reverse() next_term = 0 i = n while (next_term < x): next_term = 0 for j in range(1,n+1): next_term += terms[i - j] terms.append(next_term) i+=1 return (next_term == x)
MBPP_178
179
Write a function to calculate distance between two points using latitude and longitude.
from math import radians, sin, cos, acos def distance_lat_long(slat,slon,elat,elon): dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon)) return dist
MBPP_179
180
Write a function to find the longest common prefix in the given set of strings.
def common_prefix_util(str1, str2): result = ""; n1 = len(str1) n2 = len(str2) i = 0 j = 0 while i <= n1 - 1 and j <= n2 - 1: if (str1[i] != str2[j]): break result += str1[i] i += 1 j += 1 return (result) def common_prefix (arr, n): prefix = arr[0] for i in range (1, n): prefix = common_prefix_util(prefix, arr[i]) return (prefix)
MBPP_180
181
Write a function to find uppercase, lowercase, special character and numeric values using regex.
import re def find_character(string): uppercase_characters = re.findall(r"[A-Z]", string) lowercase_characters = re.findall(r"[a-z]", string) numerical_characters = re.findall(r"[0-9]", string) special_characters = re.findall(r"[, .!?]", string) return uppercase_characters, lowercase_characters, numerical_characters, special_characters
MBPP_181
182
Write a function to count all the distinct pairs having a difference of k in any array.
def count_pairs(arr, n, k): count=0; for i in range(0,n): for j in range(i+1, n): if arr[i] - arr[j] == k or arr[j] - arr[i] == k: count += 1 return count
MBPP_182
183
Write a function to find all the values in a list that are greater than a specified number.
def greater_specificnum(list,num): greater_specificnum=all(x >= num for x in list) return greater_specificnum
MBPP_183
184
Write a function to find the focus of a parabola.
def parabola_focus(a, b, c): focus= (((-b / (2 * a)),(((4 * a * c) - (b * b) + 1) / (4 * a)))) return focus
MBPP_184
185
Write a function to search some literals strings in a string by using regex.
import re def check_literals(text, patterns): for pattern in patterns: if re.search(pattern, text): return ('Matched!') else: return ('Not Matched!')
MBPP_185
186
Write a function to find the longest common subsequence for the given two sequences.
def longest_common_subsequence(X, Y, m, n): if m == 0 or n == 0: return 0 elif X[m-1] == Y[n-1]: return 1 + longest_common_subsequence(X, Y, m-1, n-1) else: return max(longest_common_subsequence(X, Y, m, n-1), longest_common_subsequence(X, Y, m-1, n))
MBPP_186
187
Write a python function to check whether the given number can be represented by product of two squares or not.
def prod_Square(n): for i in range(2,(n) + 1): if (i*i < (n+1)): for j in range(2,n + 1): if ((i*i*j*j) == n): return True; return False;
MBPP_187
188
Write a python function to find the first missing positive number.
def first_Missing_Positive(arr,n): ptr = 0 for i in range(n): if arr[i] == 1: ptr = 1 break if ptr == 0: return(1) for i in range(n): if arr[i] <= 0 or arr[i] > n: arr[i] = 1 for i in range(n): arr[(arr[i] - 1) % n] += n for i in range(n): if arr[i] <= n: return(i + 1) return(n + 1)
MBPP_188
189
Write a python function to count the number of integral co-ordinates that lie inside a square.
def count_Intgral_Points(x1,y1,x2,y2): return ((y2 - y1 - 1) * (x2 - x1 - 1))
MBPP_189
190
Write a function to check whether the given month name contains 30 days or not.
def check_monthnumber(monthname3): if monthname3 =="April" or monthname3== "June" or monthname3== "September" or monthname3== "November": return True else: return False
MBPP_190
191
Write a python function to check whether a string has atleast one letter and one number.
def check_String(str): flag_l = False flag_n = False for i in str: if i.isalpha(): flag_l = True if i.isdigit(): flag_n = True return flag_l and flag_n
MBPP_191
192
Write a function to remove the duplicates from the given tuple.
def remove_tuple(test_tup): res = tuple(set(test_tup)) return (res)
MBPP_192
193
Write a python function to convert octal number to decimal number.
def octal_To_Decimal(n): num = n; dec_value = 0; base = 1; temp = num; while (temp): last_digit = temp % 10; temp = int(temp / 10); dec_value += last_digit*base; base = base * 8; return dec_value;
MBPP_193
194
Write a python function to find the first position of an element in a sorted array.
def first(arr,x,n): low = 0 high = n - 1 res = -1 while (low <= high): mid = (low + high) // 2 if arr[mid] > x: high = mid - 1 elif arr[mid] < x: low = mid + 1 else: res = mid high = mid - 1 return res
MBPP_194
195
Write a function to remove all the tuples with length k.
def remove_tuples(test_list, K): res = [ele for ele in test_list if len(ele) != K] return (res)
MBPP_195
196
Write a function to perform the exponentiation of the given two tuples.
def find_exponentio(test_tup1, test_tup2): res = tuple(ele1 ** ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
MBPP_196
197
Write a function to find the largest triangle that can be inscribed in an ellipse.
import math def largest_triangle(a,b): if (a < 0 or b < 0): return -1 area = (3 * math.sqrt(3) * pow(a, 2)) / (4 * b); return area
MBPP_197
198
Write a python function to find highest power of 2 less than or equal to given number.
def highest_Power_of_2(n): res = 0; for i in range(n, 0, -1): if ((i & (i - 1)) == 0): res = i; break; return res;
MBPP_198
199
Write a function to find all index positions of the maximum values in a given list.
def position_max(list1): max_val = max(list1) max_result = [i for i, j in enumerate(list1) if j == max_val] return max_result
MBPP_199