Question:
Write a function to convert all possible convertible elements in the list to float.
assert list_to_float( [("3", "4"), ("1", "26.45"), ("7.32", "8"), ("4", "8")] ) == '[(3.0, 4.0), (1.0, 26.45), (7.32, 8.0), (4.0, 8.0)]'
assert list_to_float( [("4", "4"), ("2", "27"), ("4.12", "9"), ("7", "11")] ) == '[(4.0, 4.0), (2.0, 27.0), (4.12, 9.0), (7.0, 11.0)]'
assert list_to_float( [("6", "78"), ("5", "26.45"), ("1.33", "4"), ("82", "13")] ) == '[(6.0, 78.0), (5.0, 26.45), (1.33, 4.0), (82.0, 13.0)]'


Question:
from typing import List

def number_of_unique_colors(limit:int, queries: List[List[int]]) -> List[int]:
    """
    You are given an integer limit and a 2D array queries of size n x 2.

    There are limit + 1 balls with distinct labels in the range [0, limit]. Initially, all balls are uncolored. For every query in queries that is of the form [x, y], you mark ball x with the color y. After each query, you need to find the number of distinct colors among the balls.

    Return an array result of length n, where result[i] denotes the number of distinct colors after ith query.

    Note that:
     when answering a query, lack of a color will not be considered as a color.

    Examples:
    >>> limit = 4, queries = [[1,4],[2,5],[1,3],[3,4]]
    [1,2,2,3]
    >>> limit = 4, queries = [[0,1],[1,2],[2,2],[3,4],[4,5]]
    [1,2,2,3,4]

    Constraints:
    1 <= limit <= 10^9
    1 <= n == queries.length <= 10^5
    queries[i].length == 2
    0 <= queries[i][0] <= limit
    1 <= queries[i][1] <= 10^9
    """


Question:
def is_happy(s):
    """You are given a string s.
    Your task is to check if the string is happy or not.
    A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
    For example:
    is_happy(a) => False
    is_happy(aa) => False
    is_happy(abcd) => True
    is_happy(aabb) => False
    is_happy(adb) => True
    is_happy(xyy) => False
    """


Question:
from collections import Counter

def maximum_length_substring(s: str) -> int:
    """
    Given a string s, return the maximum length of a
    substring such that it contains at most two occurrences of each character.

    Examples:
    >>> s = "bcbbbcba"
    4
    >>> s = "aaaa"
    2

    Constraints:
    2 <= s.length <= 100
    s consists only of lowercase English letters.
    """


Question:
Write a function to create a list taking alternate elements from another given list.
assert alternate_elements(["red", "black", "white", "green", "orange"])==['red', 'white', 'orange']
assert alternate_elements([2, 0, 3, 4, 0, 2, 8, 3, 4, 2])==[2, 3, 0, 8, 4]
assert alternate_elements([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]


Question:
Write a function to check if the given tuple contains all valid values or not.
assert check_valid((True, True, True, True) ) == True
assert check_valid((True, False, True, True) ) == False
assert check_valid((True, True, True, True) ) == True


Question:
def choose_num(x, y):
    """This function takes two positive numbers x and y and returns the
    biggest even integer number that is in the range [x, y] inclusive. If
    there's no such number, then the function should return -1.

    For example:
    choose_num(12, 15) = 14
    choose_num(13, 12) = -1
    """


Question:
Write a python function to find the sum of all odd natural numbers within the range l and r.
assert sum_in_Range(2,5) == 8
assert sum_in_Range(5,7) == 12
assert sum_in_Range(7,13) == 40


Question:
def pluck(arr):
    """
    "Given an array representing a branch of a tree that has non-negative integer nodes
    your task is to pluck one of the nodes and return it.
    The plucked node should be the node with the smallest even value.
    If multiple nodes with the same smallest even value are found return the node that has smallest index.

    The plucked node should be returned in a list, [ smalest_value, its index ],
    If there are no even values or the given array is empty, return [].

    Example 1:
        Input: [4,2,3]
        Output: [2, 1]
        Explanation: 2 has the smallest even value, and 2 has the smallest index.

    Example 2:
        Input: [1,2,3]
        Output: [2, 1]
        Explanation: 2 has the smallest even value, and 2 has the smallest index.

    Example 3:
        Input: []
        Output: []

    Example 4:
        Input: [5, 0, 3, 0, 4, 2]
        Output: [0, 1]
        Explanation: 0 is the smallest value, but  there are two zeros,
                     so we will choose the first zero, which has the smallest index.

    Constraints:
        * 1 <= nodes.length <= 10000
        * 0 <= node.value
    """


Question:
from typing import List

def sum_of_powers(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums of length n, and a positive integer k.

    The power of a subsequence is defined as the minimum absolute difference between any two elements in the subsequence.

    Return the sum of powers of all subsequences of nums which have length equal to k.

    Since the answer may be large, return it modulo 10^9 + 7.

    Examples:
    >>> nums = [1,2,3,4], k = 3
    4
    >>> nums = [2,2], k = 2
    0
    >>> nums = [4,3,-1], k = 2
    10

    Constraints:
    2 <= n == nums.length <= 50
    -10^8 <= nums[i] <= 10^8
    2 <= k <= n
    """


Question:
Write a function to find the length of the longest increasing subsequence of the given sequence.
assert longest_increasing_subsequence([10, 22, 9, 33, 21, 50, 41, 60]) == 5
assert longest_increasing_subsequence([3, 10, 2, 1, 20]) == 3
assert longest_increasing_subsequence([50, 3, 10, 7, 40, 80]) == 4


Question:
Write a function to return the largest prime factor of a given integer n, assuming n > 1 and is not a prime.
assert largest_prime_factor(15) == 5
assert largest_prime_factor(27) == 3
assert largest_prime_factor(63) == 7
assert largest_prime_factor(330) == 11
assert largest_prime_factor(13195) == 29


Question:
Write a function 'vowels_count' that takes a string representing a word as input and returns the number of vowels in the string. Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a vowel, but only when it is at the end of the given word.
assert vowels_count("abcde") == 2
assert vowels_count("Alone") == 3
assert vowels_count("key") == 2
assert vowels_count("bye") == 1
assert vowels_count("keY") == 2
assert vowels_count("bYe") == 1
assert vowels_count("ACEDY") == 3


Question:
Write a function to compute binomial probability for the given number.
assert binomial_probability(10, 5, 1.0/3) == 0.13656454808718185
assert binomial_probability(11, 6, 2.0/4) == 0.2255859375
assert binomial_probability(12, 7, 3.0/5) == 0.227030335488


Question:
def min_last_element(n: int, x: int) -> int:
    """
    You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x.

    Return the minimum possible value of nums[n - 1].

    Examples:
    >>> n = 3, x = 4
    6
    >>> n = 2, x = 7
    15

    Constraints:
    1 <= n, x <= 10^8
    """


Question:
def get_row(lst, x):
    """
    You are given a 2 dimensional data, as a nested lists,
    which is similar to matrix, however, unlike matrices,
    each row may contain a different number of columns.
    Given lst, and integer x, find integers x in the list,
    and return list of tuples, [(x1, y1), (x2, y2) ...] such that
    each tuple is a coordinate - (row, columns), starting with 0.
    Sort coordinates initially by rows in ascending order.
    Also, sort coordinates of the row by columns in descending order.

    Examples:
    get_row([
      [1,2,3,4,5,6],
      [1,2,3,4,1,6],
      [1,2,3,4,5,1]
    ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
    get_row([], 1) == []
    get_row([[], [1], [1, 2, 3]], 3) == [(2, 2)]
    """


Question:
Write a function to flip lowercase characters to uppercase and uppercase to lowercase in a given string.
assert flip_case('') == ''
assert flip_case('Hello!') == 'hELLO!'
assert flip_case('These violent delights have violent ends') == 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'


Question:
Write a function to sort the given array by using shell sort.
assert shell_sort([12, 23, 4, 5, 3, 2, 12, 81, 56, 95]) == [2, 3, 4, 5, 12, 12, 23, 56, 81, 95]
assert shell_sort([24, 22, 39, 34, 87, 73, 68]) == [22, 24, 34, 39, 68, 73, 87]
assert shell_sort([32, 30, 16, 96, 82, 83, 74]) == [16, 30, 32, 74, 82, 83, 96]


Question:
Write a function that takes in an array of integers and returns the sum of the absolute values of those integers, multiplied by the product of their signs. If the array is empty, the function should return None.
assert prod_signs([1, 2, 2, -4]) == -9
assert prod_signs([0, 1]) == 0
assert prod_signs([1, 1, 1, 2, 3, -1, 1]) == -10
assert prod_signs([]) == None
assert prod_signs([2, 4,1, 2, -1, -1, 9]) == 20
assert prod_signs([-1, 1, -1, 1]) == 4
assert prod_signs([-1, 1, 1, 1]) == -4
assert prod_signs([-1, 1, 1, 0]) == 0


Question:
Write a function to find average value of the numbers in a given tuple of tuples.
assert average_tuple(((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4)))==[30.5, 34.25, 27.0, 23.25]
assert average_tuple(((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3)))== [25.5, -18.0, 3.75]
assert average_tuple( ((100, 100, 100, 120), (300, 450, 560, 450), (810, 800, 390, 320), (10, 20, 30, 40)))==[305.0, 342.5, 270.0, 232.5]


Question:
Write a python function to check whether the two numbers differ at one bit position only or not.
assert differ_At_One_Bit_Pos(13,9) == True
assert differ_At_One_Bit_Pos(15,8) == False
assert differ_At_One_Bit_Pos(2,4) == False


Question:
def is_valid_word(word: str) -> bool:
    """
    A word is considered valid if:

    It contains a minimum of 3 characters.
    It contains only digits (0-9), and English letters (uppercase and lowercase).
    It includes at least one vowel.
    It includes at least one consonant.
    You are given a string word.

    Return true if word is valid, otherwise, return false.

    Notes:

    'a', 'e', 'i', 'o', 'u', and their uppercases are vowels.
    A consonant is an English letter that is not a vowel.

    Examples:
    >>> word = "234Adas"
    true
    >>> word = "b3"
    false
    >>> word = "a3$e"
    false

    Constraints:
    1 <= word.length <= 20
    word consists of English uppercase and lowercase letters, digits, '@', '#', and '$'.
    """


Question:
Write a python function to find the sum of fourth power of first n odd natural numbers.
assert odd_Num_Sum(2) == 82
assert odd_Num_Sum(3) == 707
assert odd_Num_Sum(4) == 3108


Question:
from typing import List
from heapq import heappop, heappush

def minimum_time(n: int, edges: List[List[int]], disappear: List[int]) -> List[int]:
    """
    There is an undirected graph of n nodes. You are given a 2D array edges, where edges[i] = [ui, vi, lengthi] describes an edge between node ui and node vi with a traversal time of lengthi units.

    Additionally, you are given an array disappear, where disappear[i] denotes the time when the node i disappears from the graph and you won't be able to visit it.

    Notice that the graph might be disconnected and might contain multiple edges.

    Return the array answer, with answer[i] denoting the minimum units of time required to reach node i from node 0. If node i is unreachable from node 0 then answer[i] is -1.

    Examples:
    >>> minimum_time(3, [[0,1,2],[1,2,1],[0,2,4]], [1,1,5])
    [0,-1,4]
    >>> minimum_time(3, [[0,1,2],[1,2,1],[0,2,4]], [1,3,5])
    [0,2,3]
    >>> minimum_time(2, [[0,1,1]], [1,1])
    [0,-1]

    Constraints:
    1 <= n <= 5 * 10^4
    0 <= edges.length <= 10^5
    edges[i] == [ui, vi, lengthi]
    0 <= ui, vi <= n - 1
    1 <= lengthi <= 10^5
    disappear.length == n
    1 <= disappear[i] <= 10^5
    """


Question:
def fruit_distribution(s,n):
    """
    In this task, you will be given a string that represents a number of apples and oranges
    that are distributed in a basket of fruit this basket contains
    apples, oranges, and mango fruits. Given the string that represents the total number of
    the oranges and apples and an integer that represent the total number of the fruits
    in the basket return the number of the mango fruits in the basket.
    for examble:
    fruit_distribution("5 apples and 6 oranges", 19) ->19 - 5 - 6 = 8
    fruit_distribution("0 apples and 1 oranges",3) -> 3 - 0 - 1 = 2
    fruit_distribution("2 apples and 3 oranges", 100) -> 100 - 2 - 3 = 95
    fruit_distribution("100 apples and 1 oranges",120) -> 120 - 100 - 1 = 19
    """


Question:
Write a function to convert the given string to its MD5 hash equivalent string and return it. If 'text' is an empty string, the function should return None.
assert string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'
assert string_to_md5('') == None
assert string_to_md5('A B C') == '0ef78513b0cb8cef12743f5aeb35f888'
assert string_to_md5('password') == '5f4dcc3b5aa765d61d8327deb882cf99'


Question:
from typing import List
from itertools import accumulate

def count_house_pairs(n: int, x: int, y: int) -> List[int]:
    """
    You are given three positive integers n, x, and y.

    In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.

    For each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.

    Return a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.

    Note that x and y can be equal.

    Examples:
    >>> n = 3, x = 1, y = 3
    [6,0,0]
    >>> n = 5, x = 2, y = 4
    [10,8,2,0,0]
    >>> n = 4, x = 1, y = 1
    [6,4,2,0]

    Constraints:
    2 <= n <= 100
    1 <= x, y <= n
    """


Question:
def digitSum(s):
    """Task
    Write a function that takes a string as input and returns the sum of the upper characters only'
    ASCII codes.

    Examples:
        digitSum("") => 0
        digitSum("abAB") => 131
        digitSum("abcCd") => 67
        digitSum("helloE") => 69
        digitSum("woArBld") => 131
        digitSum("aAaaaXa") => 153
    """


Question:
Write a function to merge two dictionaries into a single expression.
assert merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" }, { "G": "Green", "W": "White" })=={'B': 'Black', 'R': 'Red', 'P': 'Pink', 'G': 'Green', 'W': 'White'}
assert merge_dictionaries({ "R": "Red", "B": "Black", "P": "Pink" },{ "O": "Orange", "W": "White", "B": "Black" })=={'O': 'Orange', 'P': 'Pink', 'B': 'Black', 'W': 'White', 'R': 'Red'}
assert merge_dictionaries({ "G": "Green", "W": "White" },{ "O": "Orange", "W": "White", "B": "Black" })=={'W': 'White', 'O': 'Orange', 'G': 'Green', 'B': 'Black'}


Question:
def change_base(x: int, base: int):
    """Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8, 3)
    '22'
    >>> change_base(8, 2)
    '1000'
    >>> change_base(7, 2)
    '111'
    """


Question:
Write a function to return a list of all prefixes from shortest to longest of the given input string.
assert all_prefixes('') == []
assert all_prefixes('asdfgh') == ['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh']
assert all_prefixes('WWW') == ['W', 'WW', 'WWW']


Question:
Write a function that takes a list of numbers, rounds each number to the nearest higher integer, squares each of those rounded numbers and then returns the sum of the squared numbers.
assert sum_squares([1,2,3])==14
assert sum_squares([1.0,2,3])==14
assert sum_squares([1,3,5,7])==84
assert sum_squares([1.4,4.2,0])==29
assert sum_squares([-2.4,1,1])==6
assert sum_squares([100,1,15,2])==10230
assert sum_squares([10000,10000])==200000000
assert sum_squares([-1.4,4.6,6.3])==75
assert sum_squares([-1.4,17.9,18.9,19.9])==1086
assert sum_squares([0])==0
assert sum_squares([-1])==1
assert sum_squares([-1,1,0])==2


Question:
Write a function to calculate the number of digits and letters in a string.
assert dig_let("python")==(6,0)
assert dig_let("program")==(7,0)
assert dig_let("python3.0")==(6,2)


Question:
Write a function that takes a string of brackets. If every opening bracket has a corresponding closing bracket, return True. Otherwise, return False.
assert correct_bracketing("()")
assert correct_bracketing("(()())")
assert correct_bracketing("()()(()())()")
assert correct_bracketing("()()((()()())())(()()(()))")
assert not correct_bracketing("((()())))")
assert not correct_bracketing(")(()")
assert not correct_bracketing("(")
assert not correct_bracketing("((((")
assert not correct_bracketing(")")
assert not correct_bracketing("(()")
assert not correct_bracketing("()()(()())())(()")
assert not correct_bracketing("()()(()())()))()")


Question:
Write a function to remove all the tuples with length k.
assert remove_tuples([(4, 5), (4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] , 1) == [(4, 5), (8, 6, 7), (3, 4, 6, 7)]
assert remove_tuples([(4, 5), (4,5), (6, 7), (1, 2, 3), (3, 4, 6, 7)] ,2) == [(1, 2, 3), (3, 4, 6, 7)]
assert remove_tuples([(1, 4, 4), (4, 3), (8, 6, 7), (1, ), (3, 6, 7)] , 3) == [(4, 3), (1,)]


Question:
from typing import List

def count_whole_day_pairs(hours: List[int]) -> int:
    """
    Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day.

    A complete day is defined as a time duration that is an exact multiple of 24 hours.

    For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.

    Examples:
    >>> hours = [12,12,30,24,24]
    2
    >>> hours = [72,48,24,3]
    3

    Constraints:
    1 <= hours.length <= 100
    1 <= hours[i] <= 10^9
    """


Question:
from typing import List

def find_winning_player(skills: List[int], k: int) -> int:
    """
    A competition consists of n players numbered from 0 to n - 1.

    You are given an integer array skills of size n and a positive integer k, where skills[i] is the skill level of player i. All integers in skills are unique.

    All players are standing in a queue in order from player 0 to player n - 1.

    The competition process is as follows:

    The first two players in the queue play a game, and the player with the higher skill level wins.
    After the game, the winner stays at the beginning of the queue, and the loser goes to the end of it.
    The winner of the competition is the first player who wins k games in a row.

    Return the initial index of the winning player.

    Examples:
    >>> skills = [4,2,6,3,9], k = 2
    2
    >>> skills = [2,5,4], k = 3
    1

    Constraints:
    n == skills.length
    2 <= n <= 10^5
    1 <= k <= 10^9
    1 <= skills[i] <= 10^6
    All integers in skills are unique.
    """


Question:
Write a function to find out, if the given number is abundant.
assert is_abundant(12)==True
assert is_abundant(13)==False
assert is_abundant(9)==False


Question:
Write a function to replace blank spaces with any character in a string.
assert replace_blank("hello people",'@')==("hello@people")
assert replace_blank("python program language",'$')==("python$program$language")
assert replace_blank("blank space","-")==("blank-space")


Question:
from typing import List

def min_rectangle_area(grid: List[List[int]]) -> int:
    """
    You are given a 2D binary array grid. Find a rectangle with horizontal and vertical sides with the smallest area, such that all the 1's in grid lie inside this rectangle.

    Return the minimum possible area of the rectangle.

    Examples:
    >>> grid = [[0,1,0],[1,0,1]]
    6
    >>> grid = [[1,0],[0,0]]
    1

    Constraints:
    1 <= grid.length, grid[i].length <= 1000
    grid[i][j] is either 0 or 1.
    The input is generated such that there is at least one 1 in grid.
    """


Question:
from typing import List

def duplicate_numbers_xor(nums: List[int]) -> int:
    """
    You are given an array nums, where each number in the array appears either once or twice.
    Return the bitwise XOR of all the numbers that appear twice in the array, or 0 if no number appears twice.

    Examples:
    >>> nums = [1,2,1,3]
    1
    >>> nums = [1,2,3]
    0

    Constraints:
    1 <= nums.length <= 50
    1 <= nums[i] <= 50
    Each number in nums appears either once or twice.
    """


Question:
from typing import List
from functools import reduce
import math
def minimum_array_length(nums: List[int]) -> int:
    """
    You are given a 0-indexed integer array nums containing positive integers.

    Your task is to minimize the length of nums by performing the following operations any number of times (including zero):

    Select two distinct indices i and j from nums, such that nums[i] > 0 and nums[j] > 0.

    Insert the result of nums[i] % nums[j] at the end of nums.

    Delete the elements at indices i and j from nums.

    Return an integer denoting the minimum length of nums after performing the operation any number of times.

    Examples:
    >>> nums = [1,4,3,1]
    1
    >>> nums = [5,5,5,10,5]
    2
    >>> nums = [2,3,4]
    1

    Constraints:
    1 <= nums.length <= 10^5
    1 <= nums[i] <= 10^9
    """


Question:
Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.
assert check_greater((10, 4, 5), (13, 5, 18)) == True
assert check_greater((1, 2, 3), (2, 1, 4)) == False
assert check_greater((4, 5, 6), (5, 6, 7)) == True


Question:
Write a function to find the circumference of a circle.
assert circle_circumference(10)==62.830000000000005
assert circle_circumference(5)==31.415000000000003
assert circle_circumference(4)==25.132


Question:
Write a python function to find nth bell number.
assert bell_Number(2) == 2
assert bell_Number(3) == 5
assert bell_Number(4) == 15


Question:
def max_element(l: list):
    """Return maximum element in the list.
    >>> max_element([1, 2, 3])
    3
    >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
    123
    """


Question:
Write a function to check if a given string is a palindrome.
assert is_palindrome('') == True
assert is_palindrome('aba') == True
assert is_palindrome('aaaaa') == True
assert is_palindrome('zbcd') == False
assert is_palindrome('xywyx') == True
assert is_palindrome('xywyz') == False
assert is_palindrome('xywzx') == False


Question:
def count_up_to(n):
    """Implement a function that takes an non-negative integer and returns an array of the first n
    integers that are prime numbers and less than n.
    for example:
    count_up_to(5) => [2,3]
    count_up_to(11) => [2,3,5,7]
    count_up_to(0) => []
    count_up_to(20) => [2,3,5,7,11,13,17,19]
    count_up_to(1) => []
    count_up_to(18) => [2,3,5,7,11,13,17]
    """


Question:
Write a function to find the median of a trapezium.
assert median_trapezium(15,25,35)==20
assert median_trapezium(10,20,30)==15
assert median_trapezium(6,9,4)==7.5


Question:
from typing import List

def remove_duplicates(numbers: List[int]) -> List[int]:
    """ From a list of integers, remove all elements that occur more than once.
    Keep order of elements left the same as in the input.
    >>> remove_duplicates([1, 2, 3, 2, 4])
    [1, 3, 4]
    """


Question:
def fib4(n: int):
    """The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
    fib4(0) -> 0
    fib4(1) -> 0
    fib4(2) -> 2
    fib4(3) -> 0
    fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
    Please write a function to efficiently compute the n-th element of the fib4 number sequence.  Do not use recursion.
    >>> fib4(5)
    4
    >>> fib4(6)
    8
    >>> fib4(7)
    14
    """


Question:
from typing import List

def intersperse(numbers: List[int], delimeter: int) -> List[int]:
    """ Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
    >>> intersperse([], 4)
    []
    >>> intersperse([1, 2, 3], 4)
    [1, 4, 2, 4, 3]
    """


Question:
def triangle_area(a, b, c):
    '''
    Given the lengths of the three sides of a triangle. Return the area of
    the triangle rounded to 2 decimal points if the three sides form a valid triangle.
    Otherwise return -1
    Three sides make a valid triangle when the sum of any two sides is greater
    than the third side.
    Example:
    triangle_area(3, 4, 5) == 6.00
    triangle_area(1, 2, 10) == -1
    '''


Question:
from typing import List

def min_boxes_to_refill_apples(apple: List[int], capacity: List[int]) -> int:
    """
    You are given an array apple of size n and an array capacity of size m.

    There are n packs where the i th pack contains apple[i] apples. There are m boxes as well, and the ith box has a capacity of capacity[i] apples.

    Return the minimum number of boxes you need to select to redistribute these n packs of apples into boxes.

    Note that, apples from the same pack can be distributed into different boxes.

    Examples:
    >>> apple = [1,3,2], capacity = [4,3,1,5,2]
    2
    >>> apple = [5,5,5], capacity = [2,4,2,7]
    4

    Constraints:
    1 <= n == apple.length <= 50
    1 <= m == capacity.length <= 50
    1 <= apple[i], capacity[i] <= 50
    The input is generated such that it's possible to redistribute packs of apples into boxes.
    """


Question:
Write a python function to find smallest number in a list.
assert smallest_num([10, 20, 1, 45, 99]) == 1
assert smallest_num([1, 2, 3]) == 1
assert smallest_num([45, 46, 50, 60]) == 45


Question:
def minPath(grid, k):
    """
    Given a grid with N rows and N columns (N >= 2) and a positive integer k,
    each cell of the grid contains a value. Every integer in the range [1, N * N]
    inclusive appears exactly once on the cells of the grid.

    You have to find the minimum path of length k in the grid. You can start
    from any cell, and in each step you can move to any of the neighbor cells,
    in other words, you can go to cells which share an edge with you current
    cell.
    Please note that a path of length k means visiting exactly k cells (not
    necessarily distinct).
    You CANNOT go off the grid.
    A path A (of length k) is considered less than a path B (of length k) if
    after making the ordered lists of the values on the cells that A and B go
    through (let's call them lst_A and lst_B), lst_A is lexicographically less
    than lst_B, in other words, there exist an integer index i (1 <= i <= k)
    such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
    lst_A[j] = lst_B[j].
    It is guaranteed that the answer is unique.
    Return an ordered list of the values on the cells that the minimum path go through.

    Examples:

        Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3
        Output: [1, 2, 1]

        Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1
        Output: [1]
    """


Question:
Write a function that matches a string that has an a followed by zero or more b's by using regex.
assert text_match("msb") == 'Not matched!'
assert text_match("a0c") == 'Found a match!'
assert text_match("abbc") == 'Found a match!'


Question:
from bisect import bisect_left
from typing import List

def find_beautiful_indices(s: str, a: str, b: str, k: int) -> List[int]:
    """
    You are given a 0-indexed string s, a string a, a string b, and an integer k.

    An index i is beautiful if:

    0 <= i <= s.length - a.length
    s[i..(i + a.length - 1)] == a
    There exists an index j such that:
    0 <= j <= s.length - b.length
    s[j..(j + b.length - 1)] == b
    |j - i| <= k
    Return the array that contains beautiful indices in sorted order from smallest to largest.

    Examples:
    >>> s = "isawsquirrelnearmysquirrelhouseohmy", a = "my", b = "squirrel", k = 15
    [16,33]
    >>> s = "abcd", a = "a", b = "a", k = 4
    [0]

    Constraints:
    1 <= k <= s.length <= 10^5
    1 <= a.length, b.length <= 10
    s, a, and b contain only lowercase English letters.
    """


Question:
from collections import Counter
def minimum_operations_to_make_k_periodic(word: str, k: int) -> int:
    """
    You are given a string word of size n, and an integer k such that k divides n.

    In one operation, you can pick any two indices i and j, that are divisible by k, then replace the substring of length k starting at i with the substring of length k starting at j. That is, replace the substring word[i..i + k - 1] with the substring word[j..j + k - 1].

    Return the minimum number of operations required to make word k-periodic.

    We say that word is k-periodic if there is some string s of length k such that word can be obtained by concatenating s an arbitrary number of times. For example, if word == “ababab”, then word is 2-periodic for s = "ab".

    Examples:
    >>> word = "leetcodeleet", k = 4
    1
    >>> word = "leetcoleet", k = 2
    3

    Constraints:
    1 <= n == word.length <= 10^5
    1 <= k <= word.length
    k divides word.length.
    word consists only of lowercase English letters.
    """


Question:
Write a function to check if the given tuple has any none value or not.
assert check_none((10, 4, 5, 6, None)) == True
assert check_none((7, 8, 9, 11, 14)) == False
assert check_none((1, 2, 3, 4, None)) == True


Question:
def min_pushes_needed(word: str) -> int:
    """
    You are given a string word containing distinct lowercase English letters.

    Telephone keypads have keys mapped with distinct collections of lowercase English letters, which can be used to form words by pushing them. For example, the key 2 is mapped with ["a","b","c"], we need to push the key one time to type "a", two times to type "b", and three times to type "c" .

    It is allowed to remap the keys numbered 2 to 9 to distinct collections of letters. The keys can be remapped to any amount of letters, but each letter must be mapped to exactly one key. You need to find the minimum number of times the keys will be pushed to type the string word.

    Return the minimum number of pushes needed to type word after remapping the keys.

    Examples:
    >>> word = "abcde"
    5
    >>> word = "xycdefghij"
    12

    Constraints:
    1 <= word.length <= 26
    word consists of lowercase English letters.
    All letters in word are distinct.
    """


Question:
Write a function to perform mathematical division operation across the given tuples.
assert division_elements((10, 4, 6, 9),(5, 2, 3, 3)) == (2, 2, 2, 3)
assert division_elements((12, 6, 8, 16),(6, 3, 4, 4)) == (2, 2, 2, 4)
assert division_elements((20, 14, 36, 18),(5, 7, 6, 9)) == (4, 2, 6, 2)


Question:
Write a function to compute the value of ncr%p.
assert ncr_modp(10,2,13)==6
assert ncr_modp(15,12,43)==25
assert ncr_modp(17,9,18)==10


Question:
Write a function to apply a linear transform to a list of numbers so that the smallest number becomes 0 and the largest becomes 1.
assert rescale_to_unit([2.0, 49.9]) == [0.0, 1.0]
assert rescale_to_unit([100.0, 49.9]) == [1.0, 0.0]
assert rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
assert rescale_to_unit([2.0, 1.0, 5.0, 3.0, 4.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]
assert rescale_to_unit([12.0, 11.0, 15.0, 13.0, 14.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]


Question:
def is_equal_to_sum_even(n):
    """Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
    Example
    is_equal_to_sum_even(4) == False
    is_equal_to_sum_even(6) == False
    is_equal_to_sum_even(8) == True
    """


Question:
from typing import List

def find_permutation(nums: List[int]) -> List[int]:
    """
    You are given an array nums which is a permutation of [0, 1, 2, ..., n - 1]. The score of any permutation of [0, 1, 2, ..., n - 1] named perm is defined as:

    score(perm) = |perm[0] - nums[perm[1]]| + |perm[1] - nums[perm[2]]| + ... + |perm[n - 1] - nums[perm[0]]|

    Return the permutation perm which has the minimum possible score. If multiple permutations exist with this score, return the one that is lexicographically smallest among them.

    Examples:
    >>> nums = [1,0,2]
    [0,1,2]
    >>> nums = [0,2,1]
    [0,2,1]

    Constraints:
    2 <= n == nums.length <= 14
    nums is a permutation of [0, 1, 2, ..., n - 1].
    """


Question:
Write a function to calculate the maximum aggregate from the list of tuples.
assert max_aggregate([('Juan Whelan',90),('Sabah Colley',88),('Peter Nichols',7),('Juan Whelan',122),('Sabah Colley',84)])==('Juan Whelan', 212)
assert max_aggregate([('Juan Whelan',50),('Sabah Colley',48),('Peter Nichols',37),('Juan Whelan',22),('Sabah Colley',14)])==('Juan Whelan', 72)
assert max_aggregate([('Juan Whelan',10),('Sabah Colley',20),('Peter Nichols',30),('Juan Whelan',40),('Sabah Colley',50)])==('Sabah Colley', 70)


Question:
from typing import List
from math import gcd
from bisect import bisect_left
def lcm(a: int, b: int) -> int:
    return a * b // gcd(a, b)
def find_kth_smallest(coins: List[int], k: int) -> int:
    """
    You are given an integer array coins representing coins of different denominations and an integer k.

    You have an infinite number of coins of each denomination. However, you are not allowed to combine coins of different denominations.

    Return the kth smallest amount that can be made using these coins.

    Examples:
    >>> coins = [3,6,9], k = 3
    9
    >>> coins = [5,2], k = 7
    12

    Constraints:
    1 <= coins.length <= 15
    1 <= coins[i] <= 25
    1 <= k <= 2 * 10^9
    coins contains pairwise distinct integers.
    """


Question:
Write a function to find the smallest integers from a given list of numbers using heap queue algorithm.
assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],3)==[14, 22, 25]
assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 25, 58],2)==[14, 22]
assert heap_queue_smallest( [25, 35, 22, 85, 14, 65, 75, 22, 58],5)==[14, 22, 22, 25, 35]


Question:
Write a function to return the product of the odd digits in a given positive integer n, or 0 if all digits are even.
assert digits(5) == 5
assert digits(54) == 5
assert digits(120) == 1
assert digits(5014) == 5
assert digits(98765) == 315
assert digits(5576543) == 2625
assert digits(2468) == 0


Question:
Write a python function to toggle bits of the number except the first and the last bit.
assert toggle_middle_bits(9) == 15
assert toggle_middle_bits(10) == 12
assert toggle_middle_bits(11) == 13


Question:
from typing import List

def flower_game(n: int, m: int) -> int:
    """
    Alice and Bob are playing a turn-based game on a circular field surrounded by flowers. The circle represents the field, and there are x flowers in the clockwise direction between Alice and Bob, and y flowers in the anti-clockwise direction between them.

    The game proceeds as follows:

    Alice takes the first turn.
    In each turn, a player must choose either the clockwise or anti-clockwise direction and pick one flower from that side.
    At the end of the turn, if there are no flowers left at all, the current player captures their opponent and wins the game.
    Given two integers, n and m, the task is to compute the number of possible pairs (x, y) that satisfy the conditions:

    Alice must win the game according to the described rules.
    The number of flowers x in the clockwise direction must be in the range [1,n].
    The number of flowers y in the anti-clockwise direction must be in the range [1,m].
    Return the number of possible pairs (x, y) that satisfy the conditions mentioned in the statement.

    Examples:
    >>> n = 3, m = 2
    3
    >>> n = 1, m = 1
    0

    Constraints:
    1 <= n, m <= 10^5
    """


Question:
Write a python function to find the hamming distance between given two integers.
assert hamming_Distance(4,8) == 2
assert hamming_Distance(2,4) == 2
assert hamming_Distance(1,2) == 2


Question:
Write a function to sort a list of lists by a given index of the inner list.
assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,0)==[('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99), ('Wyatt Knott', 91, 94)]
assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,1)==[('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98), ('Brady Kent', 97, 96), ('Greyson Fulton', 98, 99)]
assert index_on_inner_list([('Greyson Fulton', 98, 99), ('Brady Kent', 97, 96), ('Wyatt Knott', 91, 94), ('Beau Turnbull', 94, 98)] ,2)==[('Wyatt Knott', 91, 94), ('Brady Kent', 97, 96), ('Beau Turnbull', 94, 98), ('Greyson Fulton', 98, 99)]


Question:
Write a function to create a list containing the power of said number in bases raised to the corresponding number in the index using map function.
assert basesnum_coresspondingnum([10, 20, 30, 40, 50, 60, 70, 80, 90, 100],[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[10, 400, 27000, 2560000, 312500000, 46656000000, 8235430000000, 1677721600000000, 387420489000000000, 100000000000000000000]
assert basesnum_coresspondingnum([1, 2, 3, 4, 5, 6, 7],[10, 20, 30, 40, 50, 60, 70])==[1, 1048576, 205891132094649, 1208925819614629174706176, 88817841970012523233890533447265625, 48873677980689257489322752273774603865660850176, 143503601609868434285603076356671071740077383739246066639249]
assert basesnum_coresspondingnum([4, 8, 12, 16, 20, 24, 28],[3, 6, 9, 12, 15, 18, 21])==[64, 262144, 5159780352, 281474976710656, 32768000000000000000, 6979147079584381377970176, 2456510688823056210273111113728]


Question:
def get_max_triples(n):
    """
    You are given a positive integer n. You have to create an integer array a of length n.
        For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
        Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
    and a[i] + a[j] + a[k] is a multiple of 3.

    Example :
        Input: n = 5
        Output: 1
        Explanation:
        a = [1, 3, 7, 13, 21]
        The only valid triple is (1, 7, 13).
    """


Question:
from typing import List

def min_rectangles_to_cover_points(points: List[List[int]], w: int) -> int:
    """
    You are given a 2D integer array points, where points[i] = [x_i, y_i]. You are also given an integer w. Your task is to cover all the given points with rectangles.

    Each rectangle has its lower end at some point (x_1, 0) and its upper end at some point (x_2, y_2), where x_1 <= x_2, y_2 >= 0, and the condition x_2 - x_1 <= w must be satisfied for each rectangle.

    A point is considered covered by a rectangle if it lies within or on the boundary of the rectangle.

    Return an integer denoting the minimum number of rectangles needed so that each point is covered by at least one rectangle.

    Note: A point may be covered by more than one rectangle.

    Examples:
    >>> points = [[2,1],[1,0],[1,4],[1,8],[3,5],[4,6]], w = 1
    2
    >>> points = [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]], w = 2
    3
    >>> points = [[2,3],[1,2]], w = 0
    2

    Constraints:
    1 <= points.length <= 10^5
    points[i].length == 2
    0 <= x_i == points[i][0] <= 10^9
    0 <= y_i == points[i][1] <= 10^9
    0 <= w <= 10^9
    All pairs (x_i, y_i) are distinct.
    """


Question:
Write a function to check if the given tuples contain the k or not.
assert check_K((10, 4, 5, 6, 8), 6) == True
assert check_K((1, 2, 3, 4, 5, 6), 7) == False
assert check_K((7, 8, 9, 44, 11, 12), 11) == True


Question:
from typing import List

def min_or_value_after_operations(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums and an integer k.

    In one operation, you can pick any index i of nums such that 0 <= i < nums.length - 1 and replace nums[i] and nums[i + 1] with a single occurrence of nums[i] & nums[i + 1], where & represents the bitwise AND operator.

    Return the minimum possible value of the bitwise OR of the remaining elements of nums after applying at most k operations.

    Examples:
    >>> nums = [3,5,3,2,7], k = 2
    3
    >>> nums = [7,3,15,14,2,8], k = 4
    2
    >>> nums = [10,7,10,3,9,14,9,4], k = 1
    15

    Constraints:
    1 <= nums.length <= 10^5
    0 <= nums[i] < 2^30
    0 <= k < nums.length
    """


Question:
def find_permutation_difference(s: str, t: str) -> int:
    """
    You are given two strings s and t such that every character occurs at most once in s and t is a permutation of s.

    The permutation difference between s and t is defined as the sum of the absolute difference between the index of the occurrence of each character in s and the index of the occurrence of the same character in t.

    Return the permutation difference between s and t.

    Examples:
    >>> s = "abc", t = "bac"
    2
    >>> s = "abcde", t = "edbac"
    12

    Constraints:
    1 <= s.length <= 26
    Each character occurs at most once in s.
    t is a permutation of s.
    s consists only of lowercase English letters.
    """


Question:
from typing import List

def longest_monotonic_subarray(nums: List[int]) -> int:
    """
    You are given an array of integers nums. Return the length of the longest subarray of nums which is either strictly increasing or strictly decreasing.

    Examples:
    >>> nums = [1,4,3,3,2]
    2

    >>> nums = [3,3,3,3]
    1

    >>> nums = [3,2,1]
    3

    Constraints:
    1 <= nums.length <= 50
    1 <= nums[i] <= 50
    """


Question:
def closest_integer(value):
    '''
    Create a function that takes a value (string) representing a number
    and returns the closest integer to it. If the number is equidistant
    from two integers, round it away from zero.

    Examples
    >>> closest_integer("10")
    10
    >>> closest_integer("15.3")
    15

    Note:
    Rounding away from zero means that if the given number is equidistant
    from two integers, the one you should return is the one that is the
    farthest from zero. For example closest_integer("14.5") should
    return 15 and closest_integer("-14.5") should return -15.
    '''


Question:
from typing import List

def min_operations(nums: List[int], k: int) -> int:
    """
    You are given a 0-indexed integer array nums, and an integer k.

    In one operation, you can remove one occurrence of the smallest element of nums.

    Return the minimum number of operations needed so that all elements of the array are greater than or equal to k.

    Examples:
    >>> nums = [2,11,10,1,3], k = 10
    3
    >>> nums = [1,1,2,4,9], k = 1
    0
    >>> nums = [1,1,2,4,9], k = 9
    4

    Constraints:
    1 <= nums.length <= 50
    1 <= nums[i] <= 10^9
    1 <= k <= 10^9
    The input is generated such that there is at least one index i such that nums[i] >= k.
    """


Question:
Write a function to find the maximum sum of subsequences of given array with no adjacent elements.
assert max_sum_subseq([1, 2, 9, 4, 5, 0, 4, 11, 6]) == 26
assert max_sum_subseq([1, 2, 9, 5, 6, 0, 5, 12, 7]) == 28
assert max_sum_subseq([1, 3, 10, 5, 6, 0, 6, 14, 21]) == 44


Question:
def odd_count(lst):
    """Given a list of strings, where each string consists of only digits, return a list.
    Each element i of the output should be "the number of odd elements in the
    string i of the input." where all the i's should be replaced by the number
    of odd digits in the i'th string of the input.

    >>> odd_count(['1234567'])
    ["the number of odd elements 4n the str4ng 4 of the 4nput."]
    >>> odd_count(['3',"11111111"])
    ["the number of odd elements 1n the str1ng 1 of the 1nput.",
     "the number of odd elements 8n the str8ng 8 of the 8nput."]
    """


Question:
Write a function to remove an empty tuple from a list of tuples.
assert remove_empty([(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')])==[('',), ('a', 'b'), ('a', 'b', 'c'), 'd']
assert remove_empty([(), (), ('',), ("python"), ("program")])==[('',), ("python"), ("program")]
assert remove_empty([(), (), ('',), ("java")])==[('',),("java") ]


Question:
Write a function to filter odd numbers using lambda function.
assert filter_oddnumbers([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])==[1,3,5,7,9]
assert filter_oddnumbers([10,20,45,67,84,93])==[45,67,93]
assert filter_oddnumbers([5,7,9,8,6,4,3])==[5,7,9,3]


Question:
from typing import List

def concatenate(strings: List[str]) -> str:
    """ Concatenate list of strings into a single string
    >>> concatenate([])
    ''
    >>> concatenate(['a', 'b', 'c'])
    'abc'
    """


Question:
Write a python function to get the position of rightmost set bit.
assert get_First_Set_Bit_Pos(12) == 3
assert get_First_Set_Bit_Pos(18) == 2
assert get_First_Set_Bit_Pos(16) == 5


Question:
Write a python function to check whether the count of inversion of two types are same or not.
assert solve([1,0,2],3) == True
assert solve([1,2,0],3) == False
assert solve([1,2,1],3) == True


Question:
Write a function to remove tuple elements that occur more than once and replace the duplicates with some custom value.
assert remove_replica((1, 1, 4, 4, 4, 5, 5, 6, 7, 7)) == (1, 'MSP', 4, 'MSP', 'MSP', 5, 'MSP', 6, 7, 'MSP')
assert remove_replica((2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9)) == (2, 3, 4, 'MSP', 5, 6, 'MSP', 7, 8, 9, 'MSP')
assert remove_replica((2, 2, 5, 4, 5, 7, 5, 6, 7, 7)) == (2, 'MSP', 5, 4, 'MSP', 7, 'MSP', 6, 'MSP', 'MSP')


Question:
from typing import List
from collections import defaultdict

def max_subarray_sum(nums: List[int], k: int) -> int:
    """
    You are given an array nums of length n and a positive integer k.

    A subarray of nums is called good if the absolute difference between its first and last element is exactly k, in other words, the subarray nums[i..j] is good if |nums[i] - nums[j]| == k.

    Return the maximum sum of a good subarray of nums. If there are no good subarrays, return 0.

    Examples:
    >>> nums = [1,2,3,4,5,6], k = 1
    11
    >>> nums = [-1,3,2,4,5], k = 3
    11
    >>> nums = [-1,-2,-3,-4], k = 2
    -6

    Constraints:
    2 <= nums.length <= 10^5
    -10^9 <= nums[i] <= 10^9
    1 <= k <= 10^9
    """


Question:
from typing import List

def diff_between_k_and_sub_array(nums: List[int], k: int) -> int:
    """
    You are given an array nums and an integer k. You need to find a subarray of nums such that the absolute difference between k and the bitwise OR of the subarray elements is as small as possible. In other words, select a subarray nums[l..r] such that |k - (nums[l] OR nums[l + 1] ... OR nums[r])| is minimum.

    Return the minimum possible value of the absolute difference.

    A subarray is a contiguous non-empty sequence of elements within an array.

    Examples:
    >>> nums = [1,2,4,5], k = 3
    0
    >>> nums = [1,3,1,3], k = 2
    1

    Constraints:
    1 <= nums.length <= 10^5
    1 <= nums[i] <= 10^9
    1 <= k <= 10^9
    """


Question:
Write a function that takes an array of integers and returns the number of elements which has a sum of their digits greater than zero. If a number is negative, then its first signed digit will be negative, e.g. -123 has signed digits -1, 2, and 3.
assert count_nums([]) == 0
assert count_nums([-1, -2, 0]) == 0
assert count_nums([1, 1, 2, -2, 3, 4, 5]) == 6
assert count_nums([1, 6, 9, -6, 0, 1, 5]) == 5
assert count_nums([1, 100, 98, -7, 1, -1]) == 4
assert count_nums([12, 23, 34, -45, -56, 0]) == 5
assert count_nums([-0, 1**0]) == 1
assert count_nums([1]) == 1


Question:
from collections import Counter

def min_anagram_length(s: str) -> int:
    """
    You are given a string s, which is known to be a concatenation of anagrams of some string t.

    Return the minimum possible length of the string t.

    An anagram is formed by rearranging the letters of a string. For example, "aab", "aba", and, "baa" are anagrams of "aab".

    Examples:
    >>> s = "abba"
    2
    >>> s = "cdef"
    4

    Constraints:
    1 <= s.length <= 10^5
    s consist only of lowercase English letters.
    """


Question:
Write a function to find the volume of a cone.
assert volume_cone(5,12)==314.15926535897927
assert volume_cone(10,15)==1570.7963267948965
assert volume_cone(19,17)==6426.651371693521


Question:
Write a python function to print negative numbers in a list.
assert neg_nos([-1,4,5,-6]) == -1,-6
assert neg_nos([-1,-2,3,4]) == -1,-2
assert neg_nos([-7,-6,8,9]) == -7,-6


Question:
Write a python function to count number of cubes of size k in a cube of size n.
assert No_of_cubes(2,1) == 8
assert No_of_cubes(5,2) == 64
assert No_of_cubes(1,1) == 1


Question:
Write a function that takes a string and returns the string without vowels.
assert remove_vowels('') == ''
assert remove_vowels("abcdef\nghijklm") == 'bcdf\nghjklm'
assert remove_vowels('fedcba') == 'fdcb'
assert remove_vowels('eeeee') == ''
assert remove_vowels('acBAA') == 'cB'
assert remove_vowels('EcBOO') == 'cB'
assert remove_vowels('ybcd') == 'ybcd'


Question:
Write a python function to check whether the given number is co-prime or not.
assert is_coprime(17,13) == True
assert is_coprime(15,21) == False
assert is_coprime(25,45) == False


Question:
from typing import List

def min_cost_to_split_array(nums: List[int]) -> int:
    """
    You are given an array of integers nums of length n.

    The cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.

    You need to divide nums into 3 disjoint contiguous subarrays.

    Return the minimum possible sum of the cost of these subarrays.

    Examples:
    >>> nums = [1,2,3,12]
    6
    >>> nums = [5,4,3]
    12
    >>> nums = [10,3,1,1]
    12

    Constraints:
    3 <= n <= 50
    1 <= nums[i] <= 50
    """


Question:
def bf(planet1, planet2):
    '''
    There are eight planets in our solar system: the closerst to the Sun
    is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
    Uranus, Neptune.
    Write a function that takes two planet names as strings planet1 and planet2.
    The function should return a tuple containing all planets whose orbits are
    located between the orbit of planet1 and the orbit of planet2, sorted by
    the proximity to the sun.
    The function should return an empty tuple if planet1 or planet2
    are not correct planet names.
    Examples
    bf("Jupiter", "Neptune") ==> ("Saturn", "Uranus")
    bf("Earth", "Mercury") ==> ("Venus")
    bf("Mercury", "Uranus") ==> ("Venus", "Earth", "Mars", "Jupiter", "Saturn")
    '''


Question:
def monotonic(l: list):
    """Return True is list elements are monotonically increasing or decreasing.
    >>> monotonic([1, 2, 4, 20])
    True
    >>> monotonic([1, 20, 4, 10])
    False
    >>> monotonic([4, 1, 0, -10])
    True
    """


Question:
Write a python function to count number of vowels in the string.
assert Check_Vow('corner','AaEeIiOoUu') == 2
assert Check_Vow('valid','AaEeIiOoUu') == 2
assert Check_Vow('true','AaEeIiOoUu') ==2


Question:
from typing import List

def parse_music(music_string: str) -> List[int]:
    """ Input to this function is a string representing musical notes in a special ASCII format.
    Your task is to parse this string and return list of integers corresponding to how many beats does each
    not last.

    Here is a legend:
    'o' - whole note, lasts four beats
    'o|' - half note, lasts two beats
    '.|' - quater note, lasts one beat

    >>> parse_music('o o| .| o| o| .| .| .| .| o o')
    [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
    """


Question:
Write a function to find the perimeter of a square.
assert square_perimeter(10)==40
assert square_perimeter(5)==20
assert square_perimeter(4)==16


Question:
Write a function to locate the right insertion point for a specified value in sorted order.
assert right_insertion([1,2,4,5],6)==4
assert right_insertion([1,2,4,5],3)==2
assert right_insertion([1,2,4,5],7)==4


Question:
Write a function that takes a string and returns True if the string length is a prime number or False otherwise.
assert prime_length('Hello') == True
assert prime_length('abcdcba') == True
assert prime_length('kittens') == True
assert prime_length('orange') == False
assert prime_length('wow') == True
assert prime_length('world') == True
assert prime_length('MadaM') == True
assert prime_length('Wow') == True
assert prime_length('') == False
assert prime_length('HI') == True
assert prime_length('go') == True
assert prime_length('gogo') == False
assert prime_length('aaaaaaaaaaaaaaa') == False
assert prime_length('Madam') == True
assert prime_length('M') == False
assert prime_length('0') == False


Question:
def total_match(lst1, lst2):
    '''
    Write a function that accepts two lists of strings and returns the list that has
    total number of chars in the all strings of the list less than the other list.

    if the two lists have the same number of chars, return the first list.

    Examples
    total_match([], []) ➞ []
    total_match(['hi', 'admin'], ['hI', 'Hi']) ➞ ['hI', 'Hi']
    total_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) ➞ ['hi', 'admin']
    total_match(['hi', 'admin'], ['hI', 'hi', 'hi']) ➞ ['hI', 'hi', 'hi']
    total_match(['4'], ['1', '2', '3', '4', '5']) ➞ ['4']
    '''


Question:
from typing import List

def number_of_subarrays(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums.
    Return the number of subarrays of nums, where the first and the last elements of the subarray are equal to the largest element in the subarray.

    Parameters:
    nums (List[int]): The input array of positive integers.

    Returns:
    int: The number of subarrays fulfilling the condition.

    Examples:
    >>> number_of_subarrays([1, 4, 3, 3, 2])
    6
    >>> number_of_subarrays([3, 3, 3])
    6
    >>> number_of_subarrays([1])
    1
    """


Question:
def string_sequence(n: int) -> str:
    """ Return a string containing space-delimited numbers starting from 0 upto n inclusive.
    >>> string_sequence(0)
    '0'
    >>> string_sequence(5)
    '0 1 2 3 4 5'
    """


Question:
Write a function to find the number of ways to fill it with 2 x 1 dominoes for the given 3 x n board.
assert count_ways(2) == 3
assert count_ways(8) == 153
assert count_ways(12) == 2131


Question:
def rounded_avg(n, m):
    """You are given two positive integers n and m, and your task is to compute the
    average of the integers from n through m (including n and m).
    Round the answer to the nearest integer and convert that to binary.
    If n is greater than m, return -1.
    Example:
    rounded_avg(1, 5) => "0b11"
    rounded_avg(7, 5) => -1
    rounded_avg(10, 20) => "0b1111"
    rounded_avg(20, 33) => "0b11010"
    """


Question:
Write a function to find the focus of a parabola.
assert parabola_focus(5,3,2)==(-0.3, 1.6)
assert parabola_focus(9,8,4)==(-0.4444444444444444, 2.25)
assert parabola_focus(2,4,6)==(-1.0, 4.125)


Question:
Write a function that given a list of integers, returns the list in a strange order. Strange sorting is when you start with the minimum value, then maximum of the remaining integers, then minimum and so on.
assert strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3]
assert strange_sort_list([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7]
assert strange_sort_list([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3]
assert strange_sort_list([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7]
assert strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5]
assert strange_sort_list([]) == []
assert strange_sort_list([1,2,3,4,5,6,7,8]) == [1, 8, 2, 7, 3, 6, 4, 5]
assert strange_sort_list([0,2,2,2,5,5,-5,-5]) == [-5, 5, -5, 5, 0, 2, 2, 2]
assert strange_sort_list([111111]) == [111111]


Question:
from typing import List
from collections import Counter

def maximum_length(nums: List[int]) -> int:
    """
    You are given an array of positive integers nums.

    You need to select a subset of nums which satisfies the following condition:

    You can place the selected elements in a 0-indexed array such that it follows the pattern: [x, x2, x4, ..., xk/2, xk, xk/2, ..., x4, x2, x] (Note that k can be be any non-negative power of 2). For example, [2, 4, 16, 4, 2] and [3, 9, 3] follow the pattern while [2, 4, 8, 4, 2] does not.

    Return the maximum number of elements in a subset that satisfies these conditions.

    Examples:
    >>> nums = [5,4,1,2,2]
    3
    >>> nums = [1,3,2,4]
    1

    Constraints:
    2 <= nums.length <= 10^5
    1 <= nums[i] <= 10^9
    """


Question:
def calculate_score(s: str) -> int:
    """
    You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters.

    Return the score of s.

    Examples:
    >>> s = "hello"
    13
    >>> s = "zaz"
    50

    Constraints:
    2 <= s.length <= 100
    s consists only of lowercase English letters.
    """


Question:
from typing import List

def minimum_average(nums: List[int]) -> float:
    """
    You have an array of floating point numbers averages which is initially empty. You are given an array nums of n integers where n is even.

    You repeat the following procedure n / 2 times:

    Remove the smallest element, minElement, and the largest element maxElement, from nums.
    Add (minElement + maxElement) / 2 to averages.
    Return the minimum element in averages.

    Examples:
    >>> nums = [7,8,3,4,15,13,4,1]
    5.5
    >>> nums = [1,9,8,3,10,5]
    5.5

    Constraints:
    2 <= n == nums.length <= 50
    n is even.
    1 <= nums[i] <= 50
    """


Question:
Write a function that takes a list of integers as input and checks if there are three distinct elements in the list that sum to zero.
assert triples_sum_to_zero([1, 3, 5, 0]) == False
assert triples_sum_to_zero([1, 3, 5, -1]) == False
assert triples_sum_to_zero([1, 3, -2, 1]) == True
assert triples_sum_to_zero([1, 2, 3, 7]) == False
assert triples_sum_to_zero([1, 2, 5, 7]) == False
assert triples_sum_to_zero([2, 4, -5, 3, 9, 7]) == True
assert triples_sum_to_zero([1]) == False
assert triples_sum_to_zero([1, 3, 5, -100]) == False
assert triples_sum_to_zero([100, 3, 5, -100]) == False


Question:
from typing import List

def max_total_reward(rewardValues: List[int]) -> int:
    """
    You are given an integer array rewardValues of length n, representing the values of rewards.

    Initially, your total reward x is 0, and all indices are unmarked. You are allowed to perform the following operation any number of times:

    Choose an unmarked index i from the range [0, n - 1].
    If rewardValues[i] is greater than your current total reward x, then add rewardValues[i] to x (i.e., x = x + rewardValues[i]), and mark the index i.

    Return an integer denoting the maximum total reward you can collect by performing the operations optimally.

    Examples:
    >>> rewardValues = [1,1,3,3]
    4
    >>> rewardValues = [1,6,4,3,2]
    11

    Constraints:
    1 <= rewardValues.length <= 2000
    1 <= rewardValues[i] <= 2000
    """


Question:
def tri(n):
    """Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
    the last couple centuries. However, what people don't know is Tribonacci sequence.
    Tribonacci sequence is defined by the recurrence:
    tri(1) = 3
    tri(n) = 1 + n / 2, if n is even.
    tri(n) =  tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
    For example:
    tri(2) = 1 + (2 / 2) = 2
    tri(4) = 3
    tri(3) = tri(2) + tri(1) + tri(4)
           = 2 + 3 + 3 = 8
    You are given a non-negative integer number n, you have to a return a list of the
    first n + 1 numbers of the Tribonacci sequence.
    Examples:
    tri(3) = [1, 3, 2, 8]
    """


Question:
Write a function to find the median of three specific numbers.
assert median_numbers(25,55,65)==55.0
assert median_numbers(20,10,30)==20.0
assert median_numbers(15,45,75)==45.0


Question:
def select_words(s, n):
    """Given a string s and a natural number n, you have been tasked to implement
    a function that returns a list of all words from string s that contain exactly
    n consonants, in order these words appear in the string s.
    If the string s is empty then the function should return an empty list.
    Note: you may assume the input string contains only letters and spaces.
    Examples:
    select_words("Mary had a little lamb", 4) ==> ["little"]
    select_words("Mary had a little lamb", 3) ==> ["Mary", "lamb"]
    select_words("simple white space", 2) ==> []
    select_words("Hello world", 4) ==> ["world"]
    select_words("Uncle sam", 3) ==> ["Uncle"]
    """


Question:
Write a python function to left rotate the string.
assert left_rotate("python",2) == "thonpy"
assert left_rotate("bigdata",3 ) == "databig"
assert left_rotate("hadoop",1 ) == "adooph"


Question:
Write a function to check if all the elements in tuple have same data type or not.
assert check_type((5, 6, 7, 3, 5, 6) ) == True
assert check_type((1, 2, "4") ) == False
assert check_type((3, 2, 1, 4, 5) ) == True


Question:
Write a function to get the word with most number of occurrences in the given strings list.
assert most_occurrences(["UTS is best for RTF", "RTF love UTS", "UTS is best"] ) == 'UTS'
assert most_occurrences(["Its been a great year", "this year is so worse", "this year is okay"] ) == 'year'
assert most_occurrences(["Families can be reunited", "people can be reunited", "Tasks can be achieved "] ) == 'can'


Question:
from typing import List

def find_maximum_length_of_valid_subsequence(nums: List[int]) -> int:
    """
    You are given an integer array nums.
    A subsequence sub of nums with length x is called valid if it satisfies:

    (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.
    Return the length of the longest valid subsequence of nums.

    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements..

    Examples:
    >>> nums = [1,2,3,4]
    4
    >>> nums = [1,2,1,1,2,1,2]
    6

    Constraints:
    2 <= nums.length <= 2 * 10^5
    1 <= nums[i] <= 10^7
    """


Question:
Write a function that takes a string of space-separated lowercase letters and returns a dictionary with the most frequently occurring letters and their counts. If multiple letters occur equally often, include all of them.
assert histogram('a b b a') == {'a':2,'b': 2}
assert histogram('a b c a b') == {'a': 2, 'b': 2}
assert histogram('a b c d g') == {'a': 1, 'b': 1, 'c': 1, 'd': 1, 'g': 1}
assert histogram('r t g') == {'r': 1,'t': 1,'g': 1}
assert histogram('b b b b a') == {'b': 4}
assert histogram('r t g') == {'r': 1,'t': 1,'g': 1}
assert histogram('') == {}
assert histogram('a') == {'a': 1}


Question:
from typing import List

def max_sum_no_adjacent_subsequence(nums: List[int], queries: List[List[int]]) -> int:
    """
    You are given an array nums consisting of integers. You are also given a 2D array queries, where queries[i] = [pos_i, x_i].

    For query i, we first set nums[pos_i] equal to x_i, then we calculate the answer to query i which is the maximum sum of a
    subsequence
    of nums where no two adjacent elements are selected.

    Return the sum of the answers to all queries.

    Since the final answer may be very large, return it modulo 10^9 + 7.

    A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

    Examples:
    >>> nums = [3,5,9], queries = [[1,-2],[0,-3]]
    21
    >>> nums = [0,-1], queries = [[0,-5]]
    0

    Constraints:
    1 <= nums.length <= 5 * 10^4
    -10^5 <= nums[i] <= 10^5
    1 <= queries.length <= 5 * 10^4
    queries[i] == [pos_i, x_i]
    0 <= pos_i <= nums.length - 1
    -10^5 <= x_i <= 10^5
    """


Question:
from typing import List

def min_cost_of_travel(n: int, edges: List[List[int]], query: List[List[int]]) -> List[int]:
    """
    There is an undirected weighted graph with n vertices labeled from 0 to n - 1.

    You are given the integer n and an array edges, where edges[i] = [u_i, v_i, w_i] indicates that there is an edge between vertices u_i and v_i with a weight of w_i.

    A walk on a graph is a sequence of vertices and edges. The walk starts and ends with a vertex, and each edge connects the vertex that comes before it and the vertex that comes after it. It's important to note that a walk may visit the same edge or vertex more than once.

    The cost of a walk starting at node u and ending at node v is defined as the bitwise AND of the weights of the edges traversed during the walk. In other words, if the sequence of edge weights encountered during the walk is w_0, w_1, w_2, ..., w_k, then the cost is calculated as w_0 & w_1 & w_2 & ... & w_k, where & denotes the bitwise AND operator.

    You are also given a 2D array query, where query[i] = [s_i, t_i]. For each query, you need to find the minimum cost of the walk starting at vertex s_i and ending at vertex t_i. If there exists no such walk, the answer is -1.

    Return the array answer, where answer[i] denotes the minimum cost of a walk for query i.

    Examples:
    >>> n = 5, edges = [[0,1,7],[1,3,7],[1,2,1]], query = [[0,3],[3,4]]
    [1,-1]
    >>> n = 3, edges = [[0,2,7],[0,1,15],[1,2,6],[1,2,1]], query = [[1,2]]
    [0]

    Constraints:
    2 <= n <= 10^5
    0 <= edges.length <= 10^5
    edges[i].length == 3
    0 <= u_i, v_i <= n - 1
    u_i != v_i
    0 <= w_i <= 10^5
    1 <= query.length <= 10^5
    query[i].length == 2
    0 <= s_i, t_i <= n - 1
    s_i != t_i
    """


Question:
def double_the_difference(lst):
    '''
    Given a list of numbers, return the sum of squares of the numbers
    in the list that are odd. Ignore numbers that are negative or not integers.

    double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10
    double_the_difference([-1, -2, 0]) == 0
    double_the_difference([9, -2]) == 81
    double_the_difference([0]) == 0

    If the input list is empty, return 0.
    '''


Question:
from typing import List

def min_operations_to_make_median_k(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and a non-negative integer k. In one operation, you can increase or decrease any element by 1.

    Return the minimum number of operations needed to make the median of nums equal to k.

    The median of an array is defined as the middle element of the array when it is sorted in non-decreasing order. If there are two choices for a median, the larger of the two values is taken.

    Examples:
    >>> nums = [2,5,6,8,5], k = 4
    2
    >>> nums = [2,5,6,8,5], k = 7
    3
    >>> nums = [1,2,3,4,5,6], k = 4
    0

    Constraints:
    1 <= nums.length <= 2 * 10^5
    1 <= nums[i] <= 10^9
    1 <= k <= 10^9
    """


Question:
from typing import List

def number_of_right_triangles(grid: List[List[int]]) -> int:
    """
    You are given a 2D boolean matrix grid.

    Return an integer that is the number of right triangles that can be made with the 3 elements of grid such that all of them have a value of 1.

    Note:

    A collection of 3 elements of grid is a right triangle if one of its elements is in the same row with another element and in the same column with the third element. The 3 elements do not have to be next to each other.

    Examples:
    >>> grid = [[0,1,0],[0,1,1],[0,1,0]]
    2
    >>> grid = [[1,0,0,0],[0,1,0,1],[1,0,0,0]]
    0
    >>> grid = [[1,0,1],[1,0,0],[1,0,0]]
    2

    Constraints:
    1 <= grid.length <= 1000
    1 <= grid[i].length <= 1000
    0 <= grid[i][j] <= 1
    """


Question:
Write a python function to find the sublist having maximum length.
assert Find_Max([['A'],['A','B'],['A','B','C']]) == ['A','B','C']
assert Find_Max([[1],[1,2],[1,2,3]]) == [1,2,3]
assert Find_Max([[1,1],[1,2,3],[1,5,6,1]]) == [1,5,6,1]


Question:
Write a python function to count minimum number of swaps required to convert one binary string to another.
assert min_Swaps("1101","1110") == 1
assert min_Swaps("111","000") == "Not Possible"
assert min_Swaps("111","110") == "Not Possible"


Question:
Write a python function to count the total unset bits from 1 to n.
assert count_Unset_Bits(2) == 1
assert count_Unset_Bits(5) == 4
assert count_Unset_Bits(14) == 17


Question:
def hex_key(num):
    """You have been tasked to write a function that receives
    a hexadecimal number as a string and counts the number of hexadecimal
    digits that are primes (prime number, or a prime, is a natural number
    greater than 1 that is not a product of two smaller natural numbers).
    Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
    Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
    So you have to determine a number of the following digits: 2, 3, 5, 7,
    B (=decimal 11), D (=decimal 13).
    Note: you may assume the input is always correct or empty string,
    and symbols A,B,C,D,E,F are always uppercase.
    Examples:
    For num = "AB" the output should be 1.
    For num = "1077E" the output should be 2.
    For num = "ABED1A33" the output should be 4.
    For num = "123456789ABCDEF0" the output should be 6.
    For num = "2020" the output should be 2.
    """


Question:
Write a function to find the second smallest number in a list.
assert second_smallest([1, 2, -8, -2, 0, -2])==-2
assert second_smallest([1, 1, -0.5, 0, 2, -2, -2])==-0.5
assert second_smallest([2,2])==None


Question:
Write a function to calculate the harmonic sum of n-1.
assert harmonic_sum(7) == 2.5928571428571425
assert harmonic_sum(4) == 2.083333333333333
assert harmonic_sum(19) == 3.547739657143682


Question:
from typing import List

def remove_stars(s: str) -> str:
    """
    You are given a string s. It may contain any number of '*' characters. Your task is to remove all '*' characters.

    While there is a '*', do the following operation:

    Delete the leftmost '*' and the smallest non-'*' character to its left. If there are several smallest characters, you can delete any of them.
    Return the lexicographically smallest resulting string after removing all '*' characters.

    Examples:
    >>> s = "aaba*"
    aab
    >>> s = "abc"
    abc

    Constraints:
    1 <= s.length <= 10^5
    s consists only of lowercase English letters and '*'.
    The input is generated such that it is possible to delete all '*' characters.
    """


Question:
Write a python function to find the sum of non-repeated elements in a given array.
assert find_Sum([1,2,3,1,1,4,5,6],8) == 21
assert find_Sum([1,10,9,4,2,10,10,45,4],9) == 71
assert find_Sum([12,10,9,45,2,10,10,45,10],9) == 78


Question:
def count_upper(s):
    """
    Given a string s, count the number of uppercase vowels in even indices.

    For example:
    count_upper('aBCdEf') returns 1
    count_upper('abcdefg') returns 0
    count_upper('dBBE') returns 0
    """


Question:
def eat(number, need, remaining):
    """
    You're a hungry rabbit, and you already have eaten a certain number of carrots,
    but now you need to eat more carrots to complete the day's meals.
    you should return an array of [ total number of eaten carrots after your meals,
                                    the number of carrots left after your meals ]
    if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.

    Example:
    * eat(5, 6, 10) -> [11, 4]
    * eat(4, 8, 9) -> [12, 1]
    * eat(1, 10, 10) -> [11, 0]
    * eat(2, 11, 5) -> [7, 0]

    Variables:
    @number : integer
        the number of carrots that you have eaten.
    @need : integer
        the number of carrots that you need to eat.
    @remaining : integer
        the number of remaining carrots thet exist in stock

    Constrain:
    * 0 <= number <= 1000
    * 0 <= need <= 1000
    * 0 <= remaining <= 1000

    Have fun :)
    """


Question:
from typing import List
from math import comb

def count_substrings(s: str, c: str) -> int:
    """
    You are given a string s and a character c. Return the total number of
    substrings of s that start and end with c.

    Examples:
    >>> s = "abada", c = "a"
    6
    >>> s = "zzz", c = "z"
    6

    Constraints:
    1 <= s.length <= 10^5
    s and c consist only of lowercase English letters.
    """


Question:
from typing import List

def mean_absolute_deviation(numbers: List[float]) -> float:
    """ For a given list of input numbers, calculate Mean Absolute Deviation
    around the mean of this dataset.
    Mean Absolute Deviation is the average absolute difference between each
    element and a centerpoint (mean in this case):
    MAD = average | x - x_mean |
    >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])
    1.0
    """


Question:
from typing import List

def largest_square_area(bottomLeft: List[List[int]], topRight: List[List[int]]) -> int:
    """
    There exist n rectangles in a 2D plane. You are given two 0-indexed 2D integer arrays bottomLeft and topRight, both of size n x 2, where bottomLeft[i] and topRight[i] represent the bottom-left and top-right coordinates of the i th rectangle respectively.

    You can select a region formed from the intersection of two of the given rectangles. You need to find the largest area of a square that can fit inside this region if you select the region optimally.

    Return the largest possible area of a square, or 0 if there do not exist any intersecting regions between the rectangles.

    Examples:
    >>> bottomLeft = [[1,1],[2,2],[3,1]], topRight = [[3,3],[4,4],[6,6]]
    1
    >>> bottomLeft = [[1,1],[2,2],[1,2]], topRight = [[3,3],[4,4],[3,4]]
    1
    >>> bottomLeft = [[1,1],[3,3],[3,1]], topRight = [[2,2],[4,4],[4,2]]
    0

    Constraints:
    n == bottomLeft.length == topRight.length
    2 <= n <= 10^3
    bottomLeft[i].length == topRight[i].length == 2
    1 <= bottomLeft[i][0], bottomLeft[i][1] <= 10^7
    1 <= topRight[i][0], topRight[i][1] <= 10^7
    bottomLeft[i][0] < topRight[i][0]
    bottomLeft[i][1] < topRight[i][1]
    """


Question:
def max_height_of_triangle(red: int, blue: int) -> int:
    """
    You are given two integers red and blue representing the count of red and blue colored balls. You have to arrange these balls to form a triangle such that the 1st row will have 1 ball, the 2nd row will have 2 balls, the 3rd row will have 3 balls, and so on.

    All the balls in a particular row should be the same color, and adjacent rows should have different colors.

    Return the maximum height of the triangle that can be achieved.

    Examples:
    >>> red = 2, blue = 4
    3
    >>> red = 2, blue = 1
    2

    Constraints:
    1 <= red, blue <= 100
    """


Question:
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.
assert min_Jumps(3,4,11)==3.5
assert min_Jumps(3,4,0)==0
assert min_Jumps(11,14,11)==1


Question:
Write a python function to check whether the given strings are rotations of each other or not.
assert are_Rotations("abc","cba") == False
assert are_Rotations("abcd","cdba") == False
assert are_Rotations("abacd","cdaba") == True


Question:
from typing import List

def min_operations_to_all_ones(nums: List[int]) -> int:
    """
    You are given a binary array nums.

    You can do the following operation on the array any number of times (possibly zero):

    Choose any 3 consecutive elements from the array and flip all of them.
    Flipping an element means changing its value from 0 to 1, and from 1 to 0.

    Return the minimum number of operations required to make all elements in nums equal to 1. If it is impossible, return -1.

    Examples:
    >>> nums = [0,1,1,1,0,0]
    3
    >>> nums = [0,1,1,1]
    -1

    Constraints:
    3 <= nums.length <= 10^5
    0 <= nums[i] <= 1
    """


Question:
def get_odd_collatz(n):
    """
    Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.

    The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
    as follows: start with any positive integer n. Then each term is obtained from the
    previous term as follows: if the previous term is even, the next term is one half of
    the previous term. If the previous term is odd, the next term is 3 times the previous
    term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.

    Note:
        1. Collatz(1) is [1].
        2. returned list sorted in increasing order.

    For example:
    get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
    """


Question:
def swap_to_get_smallest_string(s: str) -> str:
    """
    Given a string s containing only digits, return the
    lexicographically smallest string
    that can be obtained after swapping adjacent digits in s with the same parity at most once.

    Digits have the same parity if both are odd or both are even. For example, 5 and 9, as well as 2 and 4, have the same parity, while 6 and 9 do not.

    Examples:
    >>> s = "45320"
    "43520"
    >>> s = "001"
    "001"

    Constraints:
    2 <= s.length <= 100
    s consists only of digits.
    """


Question:
from typing import List
from collections import Counter
from functools import cache
def max_total_damage(power: List[int]) -> int:
    """
    A magician has various spells.

    You are given an array power, where each element represents the damage of a spell. Multiple spells can have the same damage value.

    It is a known fact that if a magician decides to cast a spell with a damage of power[i], they cannot cast any spell with a damage of power[i] - 2, power[i] - 1, power[i] + 1, or power[i] + 2.

    Each spell can be cast only once.

    Return the maximum possible total damage that a magician can cast.

    Examples:
    >>> power = [1,1,3,4]
    6
    >>> power = [7,1,6,6]
    13

    Constraints:
    1 <= power.length <= 10^5
    1 <= power[i] <= 10^9
    """


Question:
Write a python function to remove odd numbers from a given list.
assert remove_odd([1,2,3]) == [2]
assert remove_odd([2,4,6]) == [2,4,6]
assert remove_odd([10,20,3]) == [10,20]


Question:
def incr_list(l: list):
    """Return list with elements incremented by 1.
    >>> incr_list([1, 2, 3])
    [2, 3, 4]
    >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])
    [6, 4, 6, 3, 4, 4, 10, 1, 124]
    """


Question:
from typing import List

def modified_matrix(matrix: List[List[int]]) -> List[List[int]]:
    """
    Given a 0-indexed m x n integer matrix matrix, create a new 0-indexed matrix called answer. Make answer equal to matrix, then replace each element with the value -1 with the maximum element in its respective column.

    Return the matrix answer.

    Examples:
    >>> matrix = [[1,2,-1],[4,-1,6],[7,8,9]]
    [[1,2,9],[4,8,6],[7,8,9]]
    >>> matrix = [[3,-1],[5,2]]
    [[3,2],[5,2]]

    Constraints:
    m == matrix.length
    n == matrix[i].length
    2 <= m, n <= 50
    -1 <= matrix[i][j] <= 100
    The input is generated such that each column contains at least one non-negative integer.
    """


Question:
Write a python function to convert octal number to decimal number.
assert octal_To_Decimal(25) == 21
assert octal_To_Decimal(30) == 24
assert octal_To_Decimal(40) == 32


Question:
def maximum(arr, k):
    """
    Given an array arr of integers and a positive integer k, return a sorted list
    of length k with the maximum k numbers in arr.

    Example 1:

        Input: arr = [-3, -4, 5], k = 3
        Output: [-4, -3, 5]

    Example 2:

        Input: arr = [4, -4, 4], k = 2
        Output: [4, 4]

    Example 3:

        Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1
        Output: [2]

    Note:
        1. The length of the array will be in the range of [1, 1000].
        2. The elements in the array will be in the range of [-1000, 1000].
        3. 0 <= k <= len(arr)
    """


Question:
Write a function to count the number of boredoms in a string of words. A boredom is defined as a sentence that starts with the word 'I'. Sentences in the string are separated by '.', '?' or '!'.
assert is_bored("Hello world") == 0
assert is_bored("Is the sky blue?") == 0
assert is_bored("I love It !") == 1
assert is_bored("bIt") == 0
assert is_bored("I feel good today. I will be productive. will kill It") == 2
assert is_bored("You and I are going for a walk") == 0


Question:
from typing import List
from collections import Counter

def max_frequency_elements(nums: List[int]) -> int:
    """
    You are given an array nums consisting of positive integers.

    Return the total frequencies of elements in nums such that those elements all have the maximum frequency.

    The frequency of an element is the number of occurrences of that element in the array.

    Examples:
    >>> nums = [1,2,2,3,1,4]
    4
    >>> nums = [1,2,3,4,5]
    5

    Constraints:
    1 <= nums.length <= 100
    1 <= nums[i] <= 100
    """


Question:
def encrypt_string(s: str, k: int) -> str:
    """
    You are given a string s and an integer k. Encrypt the string using the following algorithm:

    For each character c in s, replace c with the kth character after c in the string (in a cyclic manner).
    Return the encrypted string.

    Examples:
    >>> s = "dart", k = 3
    "tdar"
    >>> s = "aaa", k = 1
    "aaa"

    Constraints:
    1 <= s.length <= 100
    1 <= k <= 10^4
    s consists only of lowercase English letters.
    """


Question:
def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''


Question:
Write a function to find whether an array is subset of another array.
assert is_subset([11, 1, 13, 21, 3, 7], 6, [11, 3, 7, 1], 4) == True
assert is_subset([1, 2, 3, 4, 5, 6], 6, [1, 2, 4], 3) == True
assert is_subset([10, 5, 2, 23, 19], 5, [19, 5, 3], 3) == False


Question:
Write a python function to find maximum possible value for the given periodic function.Given three numbers A, B, and N, the task is to find the maximum possible value of floor(A * x / B) – A * floor(x / b) where x is a non-negative integer less than or equal to N. Here floor(T) = denotes the greatest integer not greater than the real number T.
assert floor_Max(11,10,9) == 9
assert floor_Max(5,7,4) == 2
assert floor_Max(2,2,1) == 1


Question:
Write a function that takes a non-empty list of integers and returns the sum of even elements located at odd indices.
assert add([4, 88]) == 88
assert add([4, 5, 6, 7, 2, 122]) == 122
assert add([4, 0, 6, 7]) == 0
assert add([4, 4, 6, 8]) == 12


Question:
Write a python function to count unset bits of a given number.
assert count_unset_bits(2) == 1
assert count_unset_bits(4) == 2
assert count_unset_bits(6) == 1


Question:
def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """


Question:
Write a function to find the nth jacobsthal-lucas number.
assert jacobsthal_lucas(5) == 31
assert jacobsthal_lucas(2) == 5
assert jacobsthal_lucas(4) == 17


Question:
from typing import List

def separate_paren_groups(paren_string: str) -> List[str]:
    """ Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
    separate those group into separate strings and return the list of those.
    Separate groups are balanced (each open brace is properly closed) and not nested within each other
    Ignore any spaces in the input string.
    >>> separate_paren_groups('( ) (( )) (( )( ))')
    ['()', '(())', '(()())']
    """


Question:
from typing import List

def satisfies_conditions(grid: List[List[int]]) -> bool:
    """
    You are given a 2D matrix grid of size m x n. You need to check if each cell grid[i][j] is:

    Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).
    Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).
    Return true if all the cells satisfy these conditions, otherwise, return false.

    Examples:
    >>> grid = [[1,0,2],[1,0,2]]
    true
    >>> grid = [[1,1,1],[0,0,0]]
    false
    >>> grid = [[1],[2],[3]]
    false

    Constraints:
    1 <= n, m <= 10
    0 <= grid[i][j] <= 9
    """


Question:
Write a function to split a given string of words separated by commas or spaces into a list of words.
assert words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
assert words_string("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
assert words_string("Hi, my name") == ["Hi", "my", "name"]
assert words_string("One,, two, three, four, five, six,") == ["One", "two", "three", "four", "five", "six"]
assert words_string("") == []
assert words_string("ahmed     , gamal") == ["ahmed", "gamal"]


Question:
def add(x: int, y: int):
    """Add two numbers x and y
    >>> add(2, 3)
    5
    >>> add(5, 7)
    12
    """


Question:
Write a function that, given a list of strings, returns the longest one. If there are multiple strings of the same length, return the first one. If the input list is empty, return None.
assert longest([]) == None
assert longest(['x', 'y', 'z']) == 'x'
assert longest(['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']) == 'zzzz'


Question:
from typing import List

def string_xor(a: str, b: str) -> str:
    """ Input are two strings a and b consisting only of 1s and 0s.
    Perform binary XOR on these inputs and return result also as a string.
    >>> string_xor('010', '110')
    '100'
    """


Question:
from typing import List

def max_good_subsequence_length(nums: List[int], k: int) -> int:
    """
    You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].

    Return the maximum possible length of a good subsequence of nums.

    Examples:
    >>> nums = [1,2,1,1,3], k = 2
    4
    >>> nums = [1,2,3,4,5,1], k = 0
    2

    Constraints:
    1 <= nums.length <= 500
    1 <= nums[i] <= 10^9
    0 <= k <= min(nums.length, 25)
    """


Question:
from typing import List
from math import isqrt

def max_prime_index_diff(nums: List[int]) -> int:
    """
    You are given an integer array nums.

    Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums.

    Examples:
    >>> nums = [4,2,9,5,3]
    3
    >>> nums = [4,8,2,8]
    0

    Constraints:
    1 <= nums.length <= 3 * 10^5
    1 <= nums[i] <= 100
    The input is generated such that the number of prime numbers in the nums is at least one.
    """


Question:
from typing import List
import math

def find_region_average_intensity(image: List[List[int]], threshold: int) -> List[List[int]]:
    """
    You are given m x n grid image which represents a grayscale image, where image[i][j] represents a pixel with intensity in the range [0..255]. You are also given a non-negative integer threshold.

    Two pixels are adjacent if they share an edge.

    A region is a 3 x 3 subgrid where the absolute difference in intensity between any two adjacent pixels is less than or equal to threshold.

    All pixels in a region belong to that region, note that a pixel can belong to multiple regions.

    You need to calculate a m x n grid result, where result[i][j] is the average intensity of the regions to which image[i][j] belongs, rounded down to the nearest integer. If image[i][j] belongs to multiple regions, result[i][j] is the average of the rounded-down average intensities of these regions, rounded down to the nearest integer. If image[i][j] does not belong to any region, result[i][j] is equal to image[i][j].

    Return the grid result.

    Examples:
    >>> image = [[5,6,7,10],[8,9,10,10],[11,12,13,10]], threshold = 3
    [[9,9,9,9],[9,9,9,9],[9,9,9,9]]
    >>> image = [[10,20,30],[15,25,35],[20,30,40],[25,35,45]], threshold = 12
    [[25,25,25],[27,27,27],[27,27,27],[30,30,30]]
    >>> image = [[5,6,7],[8,9,10],[11,12,13]], threshold = 1
    [[5,6,7],[8,9,10],[11,12,13]]

    Constraints:
    3 <= n, m <= 500
    0 <= image[i][j] <= 255
    0 <= threshold <= 255
    """


Question:
Write a function to find the similar elements from the given two tuple lists.
assert similar_elements((3, 4, 5, 6),(5, 7, 4, 10)) == (4, 5)
assert similar_elements((1, 2, 3, 4),(5, 4, 3, 7)) == (3, 4)
assert similar_elements((11, 12, 14, 13),(17, 15, 14, 13)) == (13, 14)


Question:
from typing import List

def max_elements_in_set_after_removal(nums1: List[int], nums2: List[int]) -> int:
    """
    You are given two 0-indexed integer arrays nums1 and nums2 of even length n.

    You must remove n / 2 elements from nums1 and n / 2 elements from nums2. After the removals, you insert the remaining elements of nums1 and nums2 into a set s.

    Return the maximum possible size of the set s.

    Examples:
    >>> nums1 = [1,2,1,2], nums2 = [1,1,1,1]
    2
    >>> nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]
    5
    >>> nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]
    6

    Constraints:
    n == nums1.length == nums2.length
    1 <= n <= 2 * 10^4
    n is even.
    1 <= nums1[i], nums2[i] <= 10^9
    """


Question:
def match_parens(lst):
    '''
    You are given a list of two strings, both strings consist of open
    parentheses '(' or close parentheses ')' only.
    Your job is to check if it is possible to concatenate the two strings in
    some order, that the resulting string will be good.
    A string S is considered to be good if and only if all parentheses in S
    are balanced. For example: the string '(())()' is good, while the string
    '())' is not.
    Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.

    Examples:
    match_parens(['()(', ')']) == 'Yes'
    match_parens([')', ')']) == 'No'
    '''


Question:
Write a python function to find even numbers from a mixed list.
assert Split([1,2,3,4,5]) == [2,4]
assert Split([4,5,6,7,8,0,1]) == [4,6,8,0]
assert Split ([8,12,15,19]) == [8,12]


Question:
def do_algebra(operator, operand):
    """
    Given two lists operator, and operand. The first list has basic algebra operations, and
    the second list is a list of integers. Use the two given lists to build the algebric
    expression and return the evaluation of this expression.

    The basic algebra operations:
    Addition ( + )
    Subtraction ( - )
    Multiplication ( * )
    Floor division ( // )
    Exponentiation ( ** )

    Example:
    operator['+', '*', '-']
    array = [2, 3, 4, 5]
    result = 2 + 3 * 4 - 5
    => result = 9

    Note:
        The length of operator list is equal to the length of operand list minus one.
        Operand is a list of of non-negative integers.
        Operator list has at least one operator, and operand list has at least two operands.

    """


Question:
from typing import List

def number_of_stable_arrays(zero: int, one: int, limit: int) -> int:
    """
    You are given 3 positive integers zero, one, and limit.

    A binary array arr is called stable if:

    The number of occurrences of 0 in arr is exactly zero.
    The number of occurrences of 1 in arr is exactly one.
    Each subarray of arr with a size greater than limit must contain both 0 and 1.
    Return the total number of stable binary arrays.

    Since the answer may be very large, return it modulo 10^9 + 7.

    Examples:
    >>> zero = 1, one = 1, limit = 2
    2
    >>> zero = 1, one = 2, limit = 1
    1
    >>> zero = 3, one = 3, limit = 2
    14

    Constraints:
    1 <= zero, one, limit <= 200
    """


Question:
Write a function to count array elements having modular inverse under given prime number p equal to itself.
assert modular_inverse([ 1, 6, 4, 5 ], 4, 7) == 2
assert modular_inverse([1, 3, 8, 12, 12], 5, 13) == 3
assert modular_inverse([2, 3, 4, 5], 4, 6) == 1


Question:
def count_special_chars(word: str) -> int:
    """
    You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word.

    Return the number of special letters in word.

    Examples:
    >>> word = "aaAbcBC"
    3
    >>> word = "abc"
    0
    >>> word = "abBCab"
    1

    Constraints:
    1 <= word.length <= 50
    word consists of only lowercase and uppercase English letters.
    """


Question:
Write a function to find the size of the given tuple.
assert tuple_size(("A", 1, "B", 2, "C", 3) ) == sys.getsizeof(("A", 1, "B", 2, "C", 3))
assert tuple_size((1, "Raju", 2, "Nikhil", 3, "Deepanshu") ) == sys.getsizeof((1, "Raju", 2, "Nikhil", 3, "Deepanshu"))
assert tuple_size(((1, "Lion"), ( 2, "Tiger"), (3, "Fox"), (4, "Wolf"))  ) == sys.getsizeof(((1, "Lion"), ( 2, "Tiger"), (3, "Fox"), (4, "Wolf")))


Question:
from typing import List

def max_score_in_matrix(grid: List[List[int]]) -> int:
    """
    You are given an m x n matrix grid consisting of positive integers. You can move from a cell in the matrix to any other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value c1 to a cell with the value c2 is c2 - c1.

    You can start at any cell, and you have to make at least one move.

    Return the maximum total score you can achieve.

    Examples:
    >>> grid = [[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]
    9
    >>> grid = [[4,3,2],[3,2,1]]
    -1

    Constraints:
    m == grid.length
    n == grid[i].length
    2 <= m, n <= 1000
    4 <= m * n <= 10^5
    1 <= grid[i][j] <= 10^5
    """


Question:
def fibfib(n: int):
    """The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
    fibfib(0) == 0
    fibfib(1) == 0
    fibfib(2) == 1
    fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
    Please write a function to efficiently compute the n-th element of the fibfib number sequence.
    >>> fibfib(1)
    0
    >>> fibfib(5)
    4
    >>> fibfib(8)
    24
    """


Question:
def get_positive(l: list):
    """Return only positive numbers in the list.
    >>> get_positive([-1, 2, -4, 5, 6])
    [2, 5, 6]
    >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
    [5, 3, 2, 3, 9, 123, 1]
    """


Question:
Write a python function to find the first missing positive number.
assert first_Missing_Positive([1,2,3,-1,5],5) == 4
assert first_Missing_Positive([0,-1,-2,1,5,8],6) == 2
assert first_Missing_Positive([0,1,2,5,-8],5) == 3


Question:
Write a python function to find the sum of fourth power of n natural numbers.
assert fourth_Power_Sum(2) == 17
assert fourth_Power_Sum(4) == 354
assert fourth_Power_Sum(6) == 2275


Question:
Write a function to check whether the given list of numbers are sorted in ascending order or not. If the list contains more than one duplicate of the same number, the function should return False. The function assumes no negative numbers and only integers.
assert is_sorted([5]) == True
assert is_sorted([1, 2, 3, 4, 5]) == True
assert is_sorted([1, 3, 2, 4, 5]) == False
assert is_sorted([1, 2, 3, 4, 5, 6]) == True
assert is_sorted([1, 2, 3, 4, 5, 6, 7]) == True
assert is_sorted([1, 3, 2, 4, 5, 6, 7]) == False
assert is_sorted([]) == True
assert is_sorted([1]) == True
assert is_sorted([3, 2, 1]) == False
assert is_sorted([1, 2, 2, 2, 3, 4]) == False
assert is_sorted([1, 2, 3, 3, 3, 4]) == False
assert is_sorted([1, 2, 2, 3, 3, 4]) == True
assert is_sorted([1, 2, 3, 4]) == True