source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
5,125
Write a Python function to perform binary search in a sorted array of integers and return the indices of all occurrences of the target element. If the target element is not found, return an empty list. The code should have a time complexity of O(log n), where n is the size of the array. Additionally, you are not allowe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_all_occurrences(arr: List[int], target: int) -> List[int]: """ Perform binary search in a sorted array of integers and return the indices of all occurrences of the target element. If the tar...
python_sharegpt_23k
5,137
Write a Python function to find the sum of all prime numbers in a given list. The function should only use a for loop to iterate through the list and determine if each number is prime. The function should start with: ```python from typing import List def sum_of_primes(num_list: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def sum_of_primes(num_list: List[int]) -> int: """ Calculate the sum of all prime numbers in the given list. Args: num_list (List[int]): The list of integers to check for prime n...
python_sharegpt_23k
5,141
Write a Python function to concatenate two arrays without using any built-in array concatenation methods or functions, and remove any duplicate elements from the resulting concatenated array. Additionally, ensure that the resulting concatenated array is sorted in ascending order. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_and_sort_arrays(arr1: List[int], arr2: List[int]) -> List[int]: """ Concatenates two arrays, removes duplicate elements, and sorts the resulting array in ascending order. Args: ...
python_sharegpt_23k
5,144
Write a Python function to generate a list containing the first `n` prime numbers. The function should efficiently determine if a number is prime and collect the required number of prime numbers. The code should start with: ```python from typing import List def generate_first_n_primes(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_first_n_primes(n: int) -> List[int]: """ Generate a list containing the first n prime numbers. Args: n (int): The number of prime numbers to generate. Returns: List...
python_sharegpt_23k
5,149
Implement a non-recursive depth-first search (DFS) algorithm to traverse a binary tree in Python. The algorithm should return a list of values in the order they are visited. The time complexity of the algorithm should be O(n), where n is the number of nodes in the tree. Additionally, the space complexity should be O(h)...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional class TreeNode: def __init__(self, value=0, left=None, right=None): self.value = value self.left = left self.right = right def dfs_non_recursive(root: Optional[TreeNode]) -...
python_sharegpt_23k
5,155
Write a Python function to compute an array where each element is the product of all elements in the input array except the one at the current index. You are not allowed to use division or any built-in multiplication functions. The function should start with: ```python from typing import List def product_except_self(n...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def product_except_self(nums: List[int]) -> List[int]: """ Compute an array where each element is the product of all elements in the input array except the one at the current index. Args: nu...
python_sharegpt_23k
5,161
Write a Python function to calculate the result of XORing two binary numbers, each represented as a string of '0's and '1's. The function should handle binary numbers of different lengths, including cases where the binary numbers may contain leading zeros and trailing zeros. The maximum length of each binary number is ...
Here is the Python code to solve the given problem in the markdown block: ```python def xor_binary_strings(num1: str, num2: str) -> str: """ Calculate the result of XORing two binary numbers represented as strings. Args: num1 (str): The first binary number as a string. num2 (str): The secon...
python_sharegpt_23k
5,162
Write a Python function to count the occurrences of unique positive integers in a given list. The function should return a dictionary where the keys are the unique positive integers and the values are the number of times each integer appears in the list. The function should have a time complexity of O(n) and a space co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_unique_positive_integers(lst: List[int]) -> Dict[int, int]: """ Counts the occurrences of unique positive integers in a given list. Args: lst (List[int]): The list of integer...
python_sharegpt_23k
5,172
Write a Python function to multiply the values of two dictionaries based on their common keys, while ignoring any key-value pairs in the second dictionary where the value is equal to 0. The function should return a new dictionary with the multiplied values. The code should start with: ```python from typing import Dict ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def multiply_dicts(d1: Dict[str, int], d2: Dict[str, int]) -> Dict[str, int]: """ Multiplies the values of two dictionaries based on their common keys, ignoring any key-value pairs in the second dictiona...
python_sharegpt_23k
5,174
Write a Python function to find the least common ancestor (LCA) of two given nodes in a binary search tree (BST). The BST has the following properties: - Each node in the tree has a unique integer key. - The key of each node is greater than the keys of all nodes in its left subtree. - The key of each node is less than ...
Here is the Python code to solve the given problem in the markdown block: ```python class TreeNode: def __init__(self, key): self.key = key self.left = None self.right = None self.parent = None def find_lca(root, node1, node2): """ Finds the least common ancestor (LCA) of tw...
python_sharegpt_23k
5,177
Write a Python function to reverse a singly linked list in-place without using any additional data structures or recursion. The function should have a time complexity of O(n), where n is the number of nodes in the linked list, and a constant amount of extra space, i.e., O(1) space complexity. The function should start ...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def reverse_linked_list(head: ListNode) -> ListNode: """ Reverses a singly linked list in-place without using addit...
python_sharegpt_23k
5,181
Write a Python function to compress a string by counting the consecutive occurrences of each character and storing it as a tuple with the character and its count. The function should not use any built-in functions or methods for string manipulation or counting, and should not use any additional data structures such as ...
Here is the Python code to solve the given problem in the markdown block: ```python def compress_string(s: str) -> str: """ Compresses a string by counting the consecutive occurrences of each character and storing it as a tuple with the character and its count. Args: s (str): The input string t...
python_sharegpt_23k
5,185
Write a Python function to find the index of the first occurrence of a given string in a list of strings. The function should be case-sensitive, meaning that "green" and "Green" should be considered as different strings. If the string does not appear in the list, the function should return -1. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_occurrence(lst: List[str], string: str) -> int: """ Find the index of the first occurrence of a given string in a list of strings. Args: lst (List[str]): The list of strings t...
python_sharegpt_23k
5,188
Write a Python function to convert a given lowercase string to an uppercase string without using the built-in string method `upper()`, and without using any loops. The input string will only contain alphabetic characters. The function should have a time complexity of O(n), where n is the length of the input string. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def to_upper_case(s: str) -> str: """ Converts a given lowercase string to an uppercase string without using the built-in `upper()` method or any loops. Args: s (str): The input string containing only alphabetic cha...
python_sharegpt_23k
5,193
Write a Python function to count the number of non-printable characters in a given input string and return a list of these characters. Non-printable characters include any character that cannot be displayed on the screen, such as control characters, special characters, and whitespace characters (excluding newline chara...
Here is the Python code to solve the given problem in the markdown block: ```python def count_non_printable_characters(input_string: str) -> tuple[int, list[str]]: """ Counts the number of non-printable characters in the input string and returns a list of these characters. Non-printable characters include ...
python_sharegpt_23k
5,196
Write a Python function to remove all key-value pairs from a dictionary where the value is an odd number, while preserving the order of the remaining elements. The function should return the modified dictionary. The code should start with: ```python from typing import Dict def remove_odd_elements(my_dict: Dict[str, i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def remove_odd_elements(my_dict: Dict[str, int]) -> Dict[str, int]: """ Removes all key-value pairs from the dictionary where the value is an odd number, while preserving the order of the remaining e...
python_sharegpt_23k
5,202
Write a Python function to find the maximum value in a list of integers. The function should handle cases where the input list is empty or contains non-integer elements by raising appropriate exceptions or returning an error message. The function should have a time complexity of O(n), where n is the length of the input...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def find_max_value_divide_conquer(lst: List[int]) -> int: """ Find the maximum value in a list of integers using a divide and conquer algorithm. Args: lst (List[int]): The list ...
python_sharegpt_23k
5,203
Write a Python function to transform a given string into an object (dictionary) containing the number of occurrences of each letter and digit in the string. The function should handle both uppercase and lowercase letters, treating them as the same character. The function should also consider whitespace characters but i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_characters(string: str) -> Dict[str, int]: """ Counts the occurrences of each letter, digit, and whitespace character in the given string. Treats uppercase and lowercase letters as the same...
python_sharegpt_23k
5,204
Write a Python function to check if a given list of integers is sorted in ascending order and contains no duplicate values, without using any built-in sorting functions. The function should handle lists with lengths between 1 and 10^6, values between -10^9 and 10^9, and should be efficient in terms of both time and spa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_sorted_and_unique(lst: List[int]) -> bool: """ Checks if a given list of integers is sorted in ascending order and contains no duplicate values. Args: lst (List[int]): The list of int...
python_sharegpt_23k
5,210
Write a Python function to process a list of integers according to the following rules: 1. Check if the list contains only even numbers. 2. If the list contains only even numbers, sort the even numbers in ascending order and then sort the odd numbers in descending order. 3. If the list contains any odd numbers, remove ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_even_odd(numbers: List[int]) -> List[int]: """ Process a list of integers to sort even numbers in ascending order and odd numbers in descending order. If the list contains any odd numbers, r...
python_sharegpt_23k
5,212
Write a Python function to search for all occurrences of a given element in a two-dimensional array and return the indices of each occurrence as a list of tuples. Each tuple should represent the indices (row, column) where the element is found in the array, in ascending order. The rows and columns are 0-indexed. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_element_indices(array: List[List[int]], element: int) -> List[Tuple[int, int]]: """ Searches for all occurrences of a given element in a two-dimensional array and returns the indices of e...
python_sharegpt_23k
5,218
Write a Python function to trim a string by removing leading and trailing whitespace characters, and also removing any consecutive whitespace characters within the string. The string may contain punctuation marks and special characters, which should be preserved in the final result. The function should be named `trim_s...
Here is the Python code to solve the given problem in the markdown block: ```python import re def trim_string(string: str) -> str: """ Trims a string by removing leading and trailing whitespace characters, and also removes any consecutive whitespace characters within the string. Punctuation marks and speci...
python_sharegpt_23k
5,220
Write a Python function to process a list of programming languages and their corresponding features. The function should return a dictionary where the key is the programming language and the value is a list of unique features sorted in alphabetical order. Additionally, the function should ensure that there are no dupli...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def process_languages(languages: List[Tuple[str, List[str]]]) -> Dict[str, List[str]]: """ Processes a list of programming languages and their features to return a dictionary where each ...
python_sharegpt_23k
5,230
Write a Python function to filter out and return only the odd numbers from a given list of integers. The function should not use any built-in functions or methods, and it should maintain the order of the odd numbers as they appear in the input list. The function should also have a time complexity of O(n) and use consta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_odd_numbers(input_list: List[int]) -> List[int]: """ Filters out and returns a list of odd numbers from the given input list. Args: input_list (List[int]): A list of integers from wh...
python_sharegpt_23k
5,233
Write a Python function that takes in two binary numbers represented as strings and returns a list representing the exclusive OR (XOR) of the two binary numbers. The function should only use bitwise operators and have a time complexity of O(n), where n is the length of the longer binary number. Additionally, the functi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def xor_binary_numbers(num1: str, num2: str) -> List[int]: """ Computes the exclusive OR (XOR) of two binary numbers represented as strings. Args: num1 (str): The first binary number as a st...
python_sharegpt_23k
5,244
Write a Python function to construct a matrix of size 10 rows and 8 columns filled with random floating point numbers between -100 and 100. Then, sort the matrix in descending order based on the absolute difference between the maximum and minimum values in each row. Finally, calculate the median of each column in the s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def sorted_matrix_medians() -> List[float]: """ Constructs a 10x8 matrix of random floating point numbers between -100 and 100, sorts the matrix in descending order based on the ab...
python_sharegpt_23k
5,246
Write a Python function `remove_letters` that takes a string and removes all instances of a given letter from it. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the string. The function should not use any built-in functions or libraries for removing character...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_letters(string: str, letter: str) -> str: """ Removes all instances of a given letter from the string, handling both uppercase and lowercase versions. Args: string (str): The input string from which to re...
python_sharegpt_23k
5,248
Write a Python function to check if a list contains exactly three adjacent repeated elements, either in the list itself or in any nested lists. The function should return `True` if the condition is met, and `False` otherwise. The list can contain integers, floats, strings, or other lists. The function should handle nes...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def has_three_adjacent_repeats(lst: Union[List, int, float, str]) -> bool: """ Check if a list contains exactly three adjacent repeated elements, either in the list itself or in any nested lists. ...
python_sharegpt_23k
5,249
Write a Python function to calculate the sum of all prime numbers in a given array of integers. The function should handle negative numbers by considering their absolute values for prime checking. The function should have a time complexity of O(n), where n is the size of the input array. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False oth...
python_sharegpt_23k
5,250
Write a Python function to convert a number from one number system to another. The function should handle conversions between binary, octal, decimal, and hexadecimal number systems. The input number should be within the range of 0 to 1000000, and the output number should be within the range of 0 to 1000000000. The numb...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_number_system(number: str, from_base: int, to_base: int) -> str: """ Convert a number from one number system to another. Args: number (str): The number to be converted, represented as a string. f...
python_sharegpt_23k
5,252
Write a Python function to calculate the total number of seconds from a given number of hours, minutes, and seconds. The function should validate the input values to ensure they are non-negative integers and do not exceed the maximum allowed values: 24 for hours, 60 for minutes, and 60 for seconds. If any input value e...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_total_seconds(hours: int, minutes: int, seconds: int) -> int or str: """ Calculate the total number of seconds from a given number of hours, minutes, and seconds. Args: hours (int): The number of hours...
python_sharegpt_23k
5,262
Write a Python function to replace all instances of a given substring `string1` with another substring `string2` in a third string `string3`. The replacement should only occur if `string1` is surrounded by spaces or at the beginning or end of `string3`. All strings will consist of only lowercase letters. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_substring(string1: str, string2: str, string3: str) -> str: """ Replace all instances of `string1` with `string2` in `string3` only if `string1` is surrounded by spaces or at the beginning or end of `string3`. A...
python_sharegpt_23k
5,264
Implement a modified version of the quicksort algorithm in Python that sorts a list of integers in descending order. The algorithm should have a time complexity of O(n log n) and should not use any additional data structures or recursion. Additionally, the algorithm should be implemented as a single function without us...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def quicksort_descending(arr: List[int]) -> List[int]: """ Sorts a list of integers in descending order using a modified quicksort algorithm. Args: arr (List[int]): The list of integers to b...
python_sharegpt_23k
5,269
Write a Python function that takes a string and returns its reverse, while also ignoring any leading or trailing whitespace characters in the string. The function should be case-insensitive, meaning that it should treat uppercase and lowercase characters as equal when reversing the string. The function should handle st...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(string: str) -> str: """ Reverses the input string while ignoring leading and trailing whitespace and treating uppercase and lowercase characters as equal. Args: string (str): The input string to ...
python_sharegpt_23k
5,274
Write a Python function to compare two strings for equality without using any built-in string comparison functions or operators (such as `==`, `!=`, or `strcmp`). The function must implement its own algorithm to compare the strings character by character, ensuring a time complexity of O(n), where n is the length of the...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings(string1: str, string2: str) -> bool: """ Compare two strings for equality without using built-in comparison functions or operators. Args: string1 (str): The first string to compare. strin...
python_sharegpt_23k
5,276
Write a Python function to remove all duplicate words from a given string while maintaining the order of the first occurrence of each word. The input string consists of only lowercase alphabets and spaces, and its length does not exceed 10,000 characters. The solution should have a time complexity of O(n), where n is t...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicates(input_string: str) -> str: """ Removes duplicate words from the input string while maintaining the order of their first occurrence. Args: input_string (str): The input string containing words s...
python_sharegpt_23k
5,278
Write a Python function to convert a hexadecimal number to its binary form using bitwise operations only. The function should take a hexadecimal string as input and return the corresponding binary string. The function should handle both uppercase and lowercase hexadecimal characters. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_binary(hex_num: str) -> str: """ Convert a hexadecimal number to its binary form using bitwise operations. Args: hex_num (str): The hexadecimal number as a string. Returns: str: The binary re...
python_sharegpt_23k
5,282
Write a Python function to calculate the factorial of a given number `n` using a custom multiplication and addition function. The factorial of a number is the product of all positive integers from 1 to `n`. The function should have a time complexity of O(n^2) and a space complexity of O(1). Additionally, the function s...
Here is the Python code to solve the given problem in the markdown block: ```python def factorial(n: int) -> int: """ Calculate the factorial of a given number n using custom multiplication and addition functions. Args: n (int): The number to calculate the factorial for. Returns: int: ...
python_sharegpt_23k
5,284
Write a Python function to find the longest palindromic substring in a given string. A palindromic substring is a substring that reads the same forward and backward. The function should efficiently handle strings with lengths up to 10^6 characters. The code should start with: ```python def longest_palindromic_substrin...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_palindromic_substring(s: str) -> str: """ Find the longest palindromic substring in a given string. Args: s (str): The input string in which to find the longest palindromic substring. Returns: ...
python_sharegpt_23k
5,287
Write a Python function to filter and return a list of keys from a given dictionary where the corresponding values are strings with at least 10 characters. The function should start with: ```python from typing import Dict, List def filter_keys_by_long_string_values(dictionary: Dict[str, any]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def filter_keys_by_long_string_values(dictionary: Dict[str, any]) -> List[str]: """ Filters and returns a list of keys from the given dictionary where the corresponding values are strings with at l...
python_sharegpt_23k
5,301
Write a Python function to reverse the words in a given string while maintaining the order of the words. Each word should have its characters reversed, and the function should handle multiple consecutive spaces and ignore leading or trailing spaces. The code should start with: ```python def reverse_words_in_string(str...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_string(string: str) -> str: """ Reverses the characters in each word of the given string while maintaining the order of the words. Handles multiple consecutive spaces and ignores leading or trailing spac...
python_sharegpt_23k
5,302
Write a Python function to determine if there exists a subset of a given list of integers that sums up to a specified target sum. The list may contain both positive and negative integers, and the target sum can also be negative or zero. The function should return a boolean value indicating whether such a subset exists....
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def has_subset_sum(nums: List[int], target: int) -> bool: """ Determines if there exists a subset of the given list of integers that sums up to the specified target. Args: nums (List[int]): ...
python_sharegpt_23k
5,307
Write a Python function to reverse a list of integers without using the built-in `reverse()` method, the `[::-1]` slicing syntax, or any temporary data structures such as lists or arrays. The function should only use basic operations like swapping elements, indexing, and iteration to achieve the reverse order. Addition...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list(lst: List[int]) -> List[int]: """ Reverses a list of integers in-place without using built-in reverse methods or temporary data structures. Args: lst (List[int]): The list o...
python_sharegpt_23k
5,308
Write a Python function to find the position of the first zero element in a given matrix. If no zero element is found, return `None`. The matrix will always have at least one zero element. The matrix can have at most 100 rows and 100 columns. The time complexity of your solution should be O(n), where n is the number of...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional, Tuple def find_first_zero(matrix: List[List[int]]) -> Optional[Tuple[int, int]]: """ Find the position of the first zero element in a given matrix. Args: matrix (List[List[int]]):...
python_sharegpt_23k
5,320
Write a Python function to add the string 'excellent' as the last element to a given list of sports. The list may contain duplicates and have a maximum length of 1000. The solution should have a time complexity of O(1) and should not use any built-in functions or methods that directly modify the list (e.g., `append`, `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def add_excellent_to_list(sports_list: List[str]) -> None: """ Adds the string 'excellent' as the last element to the given list of sports. Args: sports_list (List[str]): The list of sports ...
python_sharegpt_23k
5,321
Write a Python function to create a dictionary consisting of the names of the seven dwarfs and a list of their ages, sorted in descending order. The solution should have a space complexity of O(n), where n is the number of dwarfs. The function should start with: ```python from typing import Dict, List def create_dwarf...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def create_dwarf_ages_dict(dwarf_ages: Dict[str, List[int]]) -> Dict[str, List[int]]: """ Create a dictionary with the names of the seven dwarfs and their ages sorted in descending order. Args...
python_sharegpt_23k
5,323
Write a Python function to count the number of occurrences of each alphanumeric character in a given string. The function should only use a for loop to iterate over each character of the string and should not use any built-in function or data structure to count the occurrences. The function should return a dictionary w...
Here is the Python code to solve the given problem in the markdown block: ```python def count_occurrences(string: str) -> dict: """ Count the number of occurrences of each alphanumeric character in the given string. Args: string (str): The input string to count the occurrences of alphanumeric chara...
python_sharegpt_23k
5,326
Write a Python function to generate a list of the first `n` prime numbers greater than or equal to a given integer `start`. The function should efficiently determine if a number is prime and collect the required number of primes. The code should start with: ```python from typing import List def generate_n_primes_from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <...
python_sharegpt_23k
5,341
Write a Python function to perform a binary search on a sorted array of distinct positive integers to determine if a given integer `n` is present in the array. If `n` is present, the function should return the index of the first occurrence of `n`. If `n` is not present, the function should return `-1`. The function sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first_occurrence(arr: List[int], n: int) -> int: """ Perform a binary search to find the first occurrence of the integer `n` in the sorted array `arr`. Args: arr (List[int]...
python_sharegpt_23k
5,344
Write a Python function to sort a given list in descending order, exclude all even numbers from the sorted list, and return the sum of the remaining numbers. Ensure that the function runs in O(n log n) time complexity. The code should start with: ```python from typing import List def sort_and_sum_odd_numbers(lst: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_and_sum_odd_numbers(lst: List[int]) -> int: """ Sorts the given list in descending order, excludes all even numbers, and returns the sum of the remaining odd numbers. Args: lst (Lis...
python_sharegpt_23k
5,346
Write a Python function to calculate the sum of a list of non-negative integers using a recursive approach. The function should handle empty lists and raise a `ValueError` if any negative numbers are present in the list. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(nums: List[int]) -> int: """ Calculate the sum of a list of non-negative integers using a recursive approach. Args: nums (List[int]): A list of non-negative integers. ...
python_sharegpt_23k
5,350
Write a Python function to compare two strings, ignoring any leading or trailing white spaces. The function should return `True` if the strings are equal and `False` otherwise. The function should handle any printable ASCII characters, including special characters, punctuation marks, and non-alphabetic characters. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings(str1: str, str2: str) -> bool: """ Compares two strings, ignoring any leading or trailing white spaces. Args: str1 (str): The first string to compare. str2 (str): The second string to com...
python_sharegpt_23k
5,353
Write a Python function to sort a given array of integers in ascending order using the Merge Sort algorithm. The function should have a time complexity of O(n log n) and a space complexity of O(n). Additionally, you are not allowed to use any built-in sorting functions or libraries in your solution. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts the given array of integers in ascending order using the Merge Sort algorithm. Args: arr (List[int]): The array of integers to be sorte...
python_sharegpt_23k
5,357
Write a Python function to compute the product of all numbers in a given list efficiently. The function should handle input lists of any length, up to 10^6 elements, and should have a time complexity of O(n). The input list will only contain positive integers. The code should start with: ```python from typing import L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_list(numbers: List[int]) -> int: """ Computes the product of all numbers in a given list. Args: numbers (List[int]): A list of positive integers. Returns: int: The ...
python_sharegpt_23k
5,358
Write a Python function to sort a given array of integers in ascending order using the Bubble Sort algorithm. The function should not use any built-in sorting functions or methods. The solution should be implemented using only basic programming constructs and algorithms. The algorithm should have a time complexity of O...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts a given array of integers in ascending order using the Bubble Sort algorithm. Args: arr (List[int]): The array of integers to be sorte...
python_sharegpt_23k
5,362
Write a Python function to remove all occurrences of a given element from an array of integers. The function should return the number of times the element was removed. The array must be modified in-place without using any built-in functions or methods that directly manipulate the array. Additionally, provide an erroneo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_element(arr: List[int], remove_element: int) -> int: """ Remove all occurrences of a given element from an array of integers and return the count of removals. The array is modified in-plac...
python_sharegpt_23k
5,369
Write a Python function to reverse a given list of numbers and return a new list containing only the prime numbers from the reversed list. The function should have a time complexity of O(n), where n is the length of the input list, and a space complexity of O(1), meaning no additional space should be used apart from th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. ""...
python_sharegpt_23k
5,371
Write a Python function to check if two given strings are anagrams of each other with a time complexity of O(log n), where n is the length of the input strings. The function should not use any built-in functions or libraries for sorting or manipulating strings. The function should start with: ```python def is_anagram_l...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram_logn(str1: str, str2: str) -> bool: """ Check if two strings are anagrams of each other with a time complexity of O(n). Args: str1 (str): The first string to check. str2 (str): The second stri...
python_sharegpt_23k
5,373
Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should handle strings with different lengths by returning `False` immediately. Additionally, the function should treat uppercase ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_anagram(string1: str, string2: str) -> bool: """ Determine if two strings are anagrams of each other. Args: string1 (str): The first string to compare. string2 (str): The second string to compare. ...
python_sharegpt_23k
5,378
Write a Python function to find the most frequent number greater than 100 and the second most frequent number greater than 100 from a given list of integers. Additionally, return the count of each unique number greater than 100 in descending order of frequency. If two numbers have the same frequency, return them in asc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_most_frequent_numbers(numbers: List[int]) -> Tuple[int, int, List[Tuple[int, int]]]: """ Finds the most frequent and second most frequent numbers greater than 100 from a list of integers....
python_sharegpt_23k
5,384
Write a Python function to generate and return a list of all unique combinations of two numbers between 0 and 9, excluding any combination that contains the number 5. The function should start with: ```python from typing import List def generate_combinations_excluding_5() -> List[List[int]]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_combinations_excluding_5() -> List[List[int]]: """ Generate and return a list of all unique combinations of two numbers between 0 and 9, excluding any combination that contains the numbe...
python_sharegpt_23k
5,385
Write a Python function to create an array of length 5 containing all even numbers between 1 and 10, and sort them in ascending order without using any built-in sorting functions or algorithms. The function should return the sorted array. The code should start with: ```python from typing import List def create_and_so...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_and_sort_even_numbers() -> List[int]: """ Create an array of length 5 containing all even numbers between 1 and 10, and sort them in ascending order without using any built-in sorting func...
python_sharegpt_23k
5,386
Write a Python function to count the number of distinct states in a given matrix. A state is defined as a unique combination of values in a row. The matrix is a 2D list of integers. The code should start with: ```python from typing import List def count_distinct_states(matrix: List[List[int]]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_distinct_states(matrix: List[List[int]]) -> int: """ Count the number of distinct states in a given matrix. Args: matrix (List[List[int]]): A 2D list of integers representing the m...
python_sharegpt_23k
5,389
Write a Python function to calculate the sum of all numbers between 1 and a given positive integer `n` (inclusive). The function should handle edge cases such as `n` being 0 or negative by returning 0. The code should start with: ```python def sum_of_numbers(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_numbers(n: int) -> int: """ Calculate the sum of all numbers between 1 and a given positive integer `n` (inclusive). Args: n (int): The upper limit of the range (inclusive). Returns: int: The...
python_sharegpt_23k
5,391
Write a Python function to find the first duplicate element in a given list of integers. The function should handle the case where the list contains duplicate elements and should not use any additional data structures. The function should return the first duplicate element found, or -1 if no duplicates are found. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_duplicate(nums: List[int]) -> int: """ Find the first duplicate element in a given list of integers. Args: nums (List[int]): The list of integers to search for duplicates. ...
python_sharegpt_23k
5,392
Write a Python function to generate a random integer between 4 and 8 (inclusively), ensuring that the generated number is divisible by 2 and not divisible by 3. The function should be named `generate_valid_number` and should return the generated number. The code should start with: ```python import random def generate...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_valid_number() -> int: """ Generates a random integer between 4 and 8 (inclusive) that is divisible by 2 and not divisible by 3. Returns: int: A valid random integer that meets the specif...
python_sharegpt_23k
5,393
Write a Python function to calculate the product of two numbers without using the multiplication operator or any built-in functions or methods that directly calculate the product. Instead, implement your own logic using basic arithmetic operations such as addition, subtraction, and division. The function should handle ...
Here is the Python code to solve the given problem in the markdown block: ```python def custom_multiply(x: int, y: int) -> int: """ Calculate the product of two integers using basic arithmetic operations without using the multiplication operator. Args: x (int): The first integer. y (int): T...
python_sharegpt_23k
5,399
Write a Python function to count the number of unique alphabets in a given string, treating uppercase and lowercase letters as the same. The function should return the count of unique alphabets in a case-insensitive manner. The code should start with: ```python def count_unique_alphabets(string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_unique_alphabets(string: str) -> int: """ Count the number of unique alphabets in a given string, treating uppercase and lowercase letters as the same. Args: string (str): The input string to count unique ...
python_sharegpt_23k
5,400
Write a Python function to validate whether a given string contains only lowercase alphabets. The string may contain special characters or numbers, but the function should only check for lowercase alphabets. The code should start with: ```python import re def contains_only_lowercase_alphabets(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: : ```python import re def contains_only_lowercase_alphabets(s: str) -> bool: """ Validate whether the given string contains only lowercase alphabets. Args: s (str): The string to be validated. Returns: bool: Tru...
python_sharegpt_23k
5,402
Write a Python function that takes two lists of equal length and creates a dictionary where each key is the index of the elements in the lists, and the value is a tuple containing the corresponding elements from both lists. The function should handle cases where the input lists are not of equal length by returning an e...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def create_index_dictionary(list_one: List[any], list_two: List[any]) -> Dict[int, Tuple[any, any]]: """ Creates a dictionary from two lists where each key is the index of the elements in th...
python_sharegpt_23k
5,413
Write a Python function to implement the Caesar cipher and decipher algorithms. The Caesar cipher shifts each letter in the text by a given key value in the alphabet. The function should handle both uppercase and lowercase letters and leave non-alphabetic characters unchanged. The code should start with: ```python def ...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(text: str, key: int) -> str: """ Encrypts the given text using the Caesar cipher with the specified key. Args: text (str): The text to be encrypted. key (int): The shift value for the Caesa...
python_sharegpt_23k
5,414
Write a Python function to concatenate all elements in a list into a string separated by a given separator. The separator must be a non-alphanumeric character. The function should validate the separator to ensure it meets the requirement. If the separator is invalid, the function should return an empty string. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def concatenate_with_separator(input_list: List[str], separator: str) -> str: """ Concatenates all elements in a list into a string separated by a given separator. The separator must be a s...
python_sharegpt_23k
5,415
Write a Python function to sort a given list of integers in increasing order, including handling duplicate elements. The function should return the sorted list. The code should start with: ```python from typing import List def sort_array(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_array(arr: List[int]) -> List[int]: """ Sorts a given list of integers in increasing order, including handling duplicate elements. Args: arr (List[int]): The list of integers to be ...
python_sharegpt_23k
5,420
Write a Python function to remove all instances of a given value from a given list without using any built-in Python methods or libraries. The function should only use basic programming constructs and logic to achieve the desired result. The code should start with: ```python def remove_elements(lst, value): ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_elements(lst, value): """ Removes all instances of a given value from a list without using any built-in Python methods or libraries. Args: lst (list): The list from which to remove the elements. v...
python_sharegpt_23k
5,424
Write a Python function to find the longest consecutive sequence of identical characters in a given string with the constraint that the function should have a time complexity of O(n) and a space complexity of O(1). The function should return the longest sequence as a string. The code should start with: ```python def l...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_consecutive_sequence(string: str) -> str: """ Finds the longest consecutive sequence of identical characters in a given string. Args: string (str): The input string to search for the longest consecutive ...
python_sharegpt_23k
5,425
Write a Python function to remove duplicates from a given list of numbers and sort the remaining numbers in ascending order. The function should return a new list with the duplicates removed and the numbers sorted. The code should start with: ```python from typing import List def remove_duplicates_and_sort(numbers: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_and_sort(numbers: List[int]) -> List[int]: """ Removes duplicates from the given list of numbers and returns a new list with the remaining numbers sorted in ascending order. Ar...
python_sharegpt_23k
5,428
Write a Python function to find the sum of all elements in a given array without using any built-in functions or libraries to calculate the sum. The function should adhere to the following constraints: 1. The array can contain negative numbers. 2. The array can have duplicate elements. 3. The original array should not ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_array_sum(arr: List[int]) -> int: """ Calculate the sum of all elements in the given array. Args: arr (List[int]): The array of integers whose sum needs to be calculated. Retur...
python_sharegpt_23k
5,429
Write a Python function to calculate the sum of all even numbers in a given list. The list may contain both positive and negative integers. The function should return the sum of all even numbers. The code should start with: ```python from typing import List def sum_of_even_numbers(lst: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_even_numbers(lst: List[int]) -> int: """ Calculate the sum of all even numbers in a given list. Args: lst (List[int]): The list of integers to process. Returns: int: ...
python_sharegpt_23k
5,430
Write a Python function that prints out the numbers from 1 to a given positive integer `n` in ascending order, and also prints out the sum of all the numbers at the end. The function should start with: ```python def print_numbers_and_sum(n: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_numbers_and_sum(n: int) -> None: """ Prints the numbers from 1 to n in ascending order and the sum of all these numbers. Args: n (int): The upper limit of the range of numbers to print and sum. Return...
python_sharegpt_23k
5,433
Write a Python function to find the maximum value in a given list of integers without using any built-in functions or methods. The function should iterate through the list and keep track of the maximum value found so far. The code should start with: ```python from typing import List def find_max_value(numbers: List[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_value(numbers: List[int]) -> int: """ Find the maximum value in a given list of integers without using any built-in functions or methods. Args: numbers (List[int]): The list of ...
python_sharegpt_23k
5,437
Write a Python function to efficiently calculate the sum of all elements in a given list. The function should handle large input lists with thousands or millions of elements efficiently, with a time complexity less than O(n^2) and a space complexity of O(1) or O(log n). The code should start with: ```python from typin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(lst: List[int]) -> int: """ Calculate the sum of all elements in a given list efficiently. Args: lst (List[int]): The list of integers to sum. Returns: int: Th...
python_sharegpt_23k
5,440
Write a Python function to split a given string by special characters and digits, returning a list of substrings that are separated by any sequence of special characters or digits. The function should handle any string input and return the appropriate list of substrings. The code should start with: ```python from typi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def split_by_special_chars_and_digits(s: str) -> List[str]: """ Splits a given string by special characters and digits, returning a list of substrings. Args: s (str): The input str...
python_sharegpt_23k
5,442
Write a Python function to find the indices of all occurrences of the greatest value in a given list of numbers. If there are multiple occurrences of the greatest value, return a list of all indices. Otherwise, return a list with a single index. The code should start with: ```python from typing import List def find_i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_indices_of_max(lst: List[int]) -> List[int]: """ Find the indices of all occurrences of the greatest value in a given list of numbers. Args: lst (List[int]): The list of numbers fro...
python_sharegpt_23k
5,448
Write a Python function to sort a given list of integers in ascending order. The list may contain duplicate elements. The function should return the sorted list. The code should start with: ```python from typing import List def sort_list_ascending(array: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def sort_list_ascending(array: List[int]) -> List[int]: """ Sorts a given list of integers in ascending order and returns the sorted list. Args: array (List[int]): The list of integers to ...
python_sharegpt_23k
5,449
Write a Python function to check if a given string is a palindrome without using any built-in string reversal functions or data structures (e.g., slicing, `reverse()` function, stack, etc.). The function should compare characters from the beginning and end of the string moving towards the center. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(string: str) -> bool: """ Check if the given string is a palindrome without using any built-in string reversal functions or data structures. Args: string (str): The string to check for palindrome p...
python_sharegpt_23k
5,450
Write a Python function to determine if two strings are anagrams of each other with a time complexity of O(n), where n is the length of the strings. The function should use constant space, meaning it should not use additional data structures beyond a few variables for counting purposes. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(str1: str, str2: str) -> bool: """ Determine if two strings are anagrams of each other using constant space. Args: str1 (str): The first string to check. str2 (str): The second string to che...
python_sharegpt_23k
5,455
Write a Python function to determine if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should also handle edge cases such as 0 and 1, which are not prime numbers. The code should start with: ```python def is_prime(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(num: int) -> bool: """ Determines if a given number is a prime number. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. "...
python_sharegpt_23k
5,456
Write a Python function to create a new array that contains only the even numbers from a given array. Additionally, the new array should be sorted in ascending order and all elements should be unique. The function should start with: ```python from typing import List def filter_and_sort_even_numbers(arr: List[int]) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_and_sort_even_numbers(arr: List[int]) -> List[int]: """ Filters and sorts the even numbers from the given array, ensuring all elements are unique and sorted in ascending order. Args: ...
python_sharegpt_23k
5,457
Write a Python function to count the number of times a given letter appears in a string, ignoring case sensitivity. The function should take two parameters: the string to search in and the letter to count. The function should return the count of the letter in the string. The code should start with: ```python def count...
Here is the Python code to solve the given problem in the markdown block: ```python def count_letter_occurrences(string: str, letter: str) -> int: """ Counts the number of times a given letter appears in a string, ignoring case sensitivity. Args: string (str): The string to search in. lette...
python_sharegpt_23k
5,459
Write a Python function to find the first intersecting element between two given arrays. The solution must have a time complexity of O(n), where n is the length of the arrays, and must not use any built-in intersection functions or data structures. Additionally, the code snippet should be implemented using only constan...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_first_intersection(arr1: List[int], arr2: List[int]) -> Optional[int]: """ Find the first intersecting element between two given arrays. Args: arr1 (List[int]): The first ...
python_sharegpt_23k
5,464
Write a Python function to remove all occurrences of a specified element from a given list while maintaining the original order of the remaining elements. The function should have a time complexity of O(n) and should not use any built-in functions or libraries to remove the elements. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_element(lst: List[int], element: int) -> List[int]: """ Removes all occurrences of a specified element from a list while maintaining the original order of the remaining elements. Args: ...
python_sharegpt_23k
5,465
Write a Python function to perform matrix multiplication using recursion. The function should take two matrices as input and return the resulting matrix. The function should handle matrices of any compatible dimensions. The code should start with: ```python from typing import List def recursive_matrix_multiplication(m...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def recursive_matrix_multiplication(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]: """ Perform matrix multiplication using recursion. Args: matrix1 (List[List[int]])...
python_sharegpt_23k
5,467
Write a Python function to reorder a given array such that all odd numbers appear before all even numbers while maintaining the relative order of odd and even numbers within their respective groups. The function should start with: ```python from typing import List def reorder_array(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reorder_array(arr: List[int]) -> List[int]: """ Reorders the given array such that all odd numbers appear before all even numbers, while maintaining the relative order of odd and even numbers wit...
python_sharegpt_23k
5,472
Write a Python function to calculate the sum of an array of integers without using the built-in `sum()` function. The function should iterate through the array and accumulate the sum of its elements. The code should start with: ```python from typing import List def calculate_sum(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(arr: List[int]) -> int: """ Calculate the sum of an array of integers without using the built-in sum() function. Args: arr (List[int]): The array of integers to sum. R...
python_sharegpt_23k
5,476
Write a Python function to determine if a given string is a palindrome, considering only alphabetic characters and ignoring case sensitivity. The function should return a boolean value (`True` if the string is a palindrome, `False` otherwise). The code should start with: ```python def is_palindrome(s: str) -> bool: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determine if a given string is a palindrome, considering only alphabetic characters and ignoring case sensitivity. Args: s (str): The input string to be checked. Returns: ...
python_sharegpt_23k
5,479
Write a Python function to find the longest common substring between two given strings, considering the comparison to be case-insensitive. The function should efficiently handle strings of large sizes and should not use any built-in functions or libraries that directly solve this problem. The function should return the...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_common_substring(s1: str, s2: str) -> str: """ Find the longest common substring between two strings, case-insensitive. Args: s1 (str): The first input string. s2 (str): The second input string. ...
python_sharegpt_23k
5,480
Write a Python function to find the index of the first occurrence of a given item in an array that may contain duplicate items. If the item does not exist in the array, return -1. The code should start with: ```python from typing import List def find_first_occurrence(arr: List[int], item: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_occurrence(arr: List[int], item: int) -> int: """ Find the index of the first occurrence of a given item in an array. Args: arr (List[int]): The array to search in. it...
python_sharegpt_23k
5,481
Write a Python function to find and return all prime numbers and palindromic prime numbers within a given range `[a, b]`. The function should return two lists: one containing all prime numbers in the range and the other containing all palindromic prime numbers in the range. The code should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """...
python_sharegpt_23k
5,482
Write a Python function to implement an optimized version of the Bubble Sort algorithm, specifically the Cocktail Shaker Sort. The function should take an array of numbers (integers or floating-point) as input and return the sorted array. The function should handle arrays of any length, including arrays with duplicate ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def cocktail_shaker_sort(arr: List[float]) -> List[float]: """ Sorts the given array using the Cocktail Shaker Sort algorithm. Args: arr (List[float]): The array of numbers (integers or floa...
python_sharegpt_23k
5,485
Write a Python function to count the number of occurrences of a given value in a list of integers. The function should return the count of the specified value in the list. The code should start with: ```python from typing import List def count_occurrences(lst: List[int], value: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(lst: List[int], value: int) -> int: """ Counts the number of occurrences of a given value in a list of integers. Args: lst (List[int]): The list of integers in which to...