source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
10,578
Write a Python function to merge two sorted lists into a single sorted list, preserving duplicate elements. The function should have a time complexity of O(n+m), where n and m are the lengths of the two input lists respectively. The code should start with: ```python from typing import List def merge_sorted_lists(list...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merge two sorted lists into a single sorted list, preserving duplicate elements. Args: list1 (List[int]): The fir...
python_sharegpt_23k
10,579
Write a Python function to create a 2-D array of size (6,6) filled with a pattern of alternating 1's and 0's, starting with 1 in the top-left corner. Additionally, ensure that each row and column has an equal number of 1's and 0's. The function should return the 2-D array. The code should start with: ```python from ty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def create_alternating_pattern_array() -> List[List[int]]: """ Creates a 2-D array of size (6,6) filled with an alternating pattern of 1's and 0's, starting with 1 in the top-left corner. Ensures eac...
python_sharegpt_23k
10,582
Write a Python function to find the maximum value in a given list of integers. Additionally, analyze and document the time complexity and space complexity of the algorithm using Big O notation. The function should start with: ```python from typing import List def find_maximum(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_maximum(arr: List[int]) -> int: """ Find the maximum value in a given list of integers. Args: arr (List[int]): The list of integers from which to find the maximum value. Return...
python_sharegpt_23k
10,585
Write a Python function to check if an input string is a palindrome, considering only alphanumeric characters and ignoring case sensitivity. The function should return `True` if the string is a palindrome and `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: """ Check if the input string is a palindrome, considering only alphanumeric characters and ignoring case sensitivity. Args: s (str): The input string to check. Returns: ...
python_sharegpt_23k
10,586
Write a Python function to find the maximum absolute difference between any two elements in a given array of integers. The function should have a time complexity of O(n^2), where n is the length of the array, and a space complexity of O(1). The function should start with: ```python from typing import List def find_max...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_absolute_difference(arr: List[int]) -> int: """ Find the maximum absolute difference between any two elements in the given array. Args: arr (List[int]): The array of integers. ...
python_sharegpt_23k
10,590
Write a Python function to compute the average height from a list of heights. The heights should be in centimeters and should range from 100 to 200. Additionally, the function should handle the following edge cases: - If the list is empty, it should return 0. - If there are negative heights in the list, they should be ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_average_height(heights: List[int]) -> float: """ Computes the average height from a list of heights. The heights should be in centimeters and should range from 100 to 200. Negative heigh...
python_sharegpt_23k
10,591
Write a Python function to calculate the sum of squares of the first n natural numbers efficiently. The function should take an integer `n` as input and return the sum of squares of all numbers from 1 to `n`. The code should start with: ```python def sum_of_squares(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_squares(n: int) -> int: """ Calculate the sum of squares of the first n natural numbers. Args: n (int): The number of natural numbers to consider. Returns: int: The sum of squares of the firs...
python_sharegpt_23k
10,593
Write a Python function to calculate the sum of the cubes of all the odd numbers in a given list of integers. The function should start with: ```python from typing import List def sum_of_odd_cubes(numbers: 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_odd_cubes(numbers: List[int]) -> int: """ Calculate the sum of the cubes of all the odd numbers in the given list. Args: numbers (List[int]): A list of integers. Returns: ...
python_sharegpt_23k
10,596
Write a Python function to sort a given list of numbers in ascending order and remove any duplicate numbers from the list. The function should not use any built-in sorting functions or libraries. Instead, it should implement a recursive sorting algorithm such as quicksort or mergesort. The function should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_and_remove_duplicates(arr: List[int]) -> List[int]: """ Sorts a given list of numbers in ascending order and removes any duplicate numbers. The function uses a recursive sorting algorithm (q...
python_sharegpt_23k
10,598
Write a Python function to calculate the absolute difference between two numbers using only basic arithmetic operations (`+`, `-`, `*`, `/`) and comparisons (`<`, `>`, `==`) a maximum of two times. The function should have a time complexity of O(1) and use a constant amount of space. The function should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def absolute_difference(num1: int, num2: int) -> int: """ Calculate the absolute difference between two numbers using basic arithmetic operations and comparisons. Args: num1 (int): The first number. num2 (in...
python_sharegpt_23k
10,599
Write a Python function to flatten a given array of lists and filter out the elements that are divisible by both 2 and 3. The filtered elements should then be sorted in ascending order before returning the final result. The code should start with: ```python from typing import List def flatten_and_filter_divisible_by_2...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_and_filter_divisible_by_2_and_3(arr: List[List[int]]) -> List[int]: """ Flattens a given array of lists and filters out the elements that are divisible by both 2 and 3. The filtered eleme...
python_sharegpt_23k
10,600
Write a Python function to remove all occurrences of a specified item from a given list while maintaining the relative order of the remaining items. The function should have a time complexity of O(n), where n is the length of the list, and a space complexity of O(1), meaning no additional data structures can be used. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_item(lst: List[int], item: int) -> List[int]: """ Removes all occurrences of the specified item from the given list while maintaining the relative order of the remaining items. Args: ...
python_sharegpt_23k
10,604
Write a Python function to calculate the sum of all prime numbers in a given list of integers. The function should have a time complexity of O(n^2), where n is the length of the list. The function should not use any built-in Python functions or libraries that directly calculate the sum of a list or check for prime numb...
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 for primality. Returns: bool: True if the number is prime, False otherwise. ...
python_sharegpt_23k
10,605
Implement a modified merge sort algorithm that uses a binary search to find the correct position for each element in the sorted subarray. The function should start with: ```python from typing import List def modified_merge_sort(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 modified_merge_sort(arr: List[int]) -> List[int]: """ Sorts the input list using a modified merge sort algorithm that uses binary search to find the correct position for each element in the sorted su...
python_sharegpt_23k
10,607
Write a Python function to count the number of unique elements in a given list of integers with a time complexity of O(n log n) and using only constant space. The function should handle negative numbers correctly and should not use any additional data structures such as sets or dictionaries. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_unique_elements(arr: List[int]) -> int: """ Counts the number of unique elements in a given list of integers. The function sorts the list in place and then iterates through it to count the...
python_sharegpt_23k
10,609
Write a Python function to convert a date string in the format 'Month Day, Year' to the ISO 8601 standard format 'YYYY-MM-DD'. The input date string contains the month spelled out, the day with an ordinal indicator (e.g., 1st, 2nd, 3rd, etc.), and the year as a four-digit number. The function should handle the conversi...
Here is the Python code to solve the given problem in the markdown block: ```python def format_date_to_iso(date_str: str) -> str: """ Converts a date string in the format 'Month Day, Year' to the ISO 8601 standard format 'YYYY-MM-DD'. Args: date_str (str): The input date string in the format 'Month...
python_sharegpt_23k
10,611
Write a Python function to merge two given arrays and create a new array that contains unique elements from both arrays, sorted in ascending order. The function should handle arrays with duplicate elements and empty arrays as input. The code should start with: ```python from typing import List def merge_and_sort_uniqu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_sort_unique(arr1: List[int], arr2: List[int]) -> List[int]: """ Merges two arrays and returns a new array containing unique elements from both arrays, sorted in ascending order. Args: ...
python_sharegpt_23k
10,617
Write a Python function to sort a given array using the insertion sort algorithm in descending order. The original array should remain unchanged, and you are not allowed to use any built-in sorting functions or libraries. The array can contain duplicate elements, and the array size can be up to 100,000. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insertion_sort_descending(arr: List[int]) -> List[int]: """ Sorts a given array in descending order using the insertion sort algorithm. The original array remains unchanged. Args: ar...
python_sharegpt_23k
10,629
Write a Python function to remove all vowels from a given string. The function should handle both uppercase and lowercase vowels and should have a time complexity of O(n), where n is the length of the input string. Additionally, the function should use constant space complexity, meaning it should not use any additional...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_vowels(string: str) -> str: """ Removes all vowels from the given string. Args: string (str): The input string from which vowels are to be removed. Returns: str: A new string with all vowels ...
python_sharegpt_23k
10,630
Write a Python function to reverse an array of integers and return a new array without modifying the original array. The reversed array should be sorted in descending order. The code should start with: ```python from typing import List def reverse_and_sort_descending(nums: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_and_sort_descending(nums: List[int]) -> List[int]: """ Reverses an array of integers and returns a new array sorted in descending order without modifying the original array. Args: ...
python_sharegpt_23k
10,631
Write a Python function to calculate the area of a triangle given its base and height, ensuring that both dimensions are positive integers between 1 and 100, inclusive. Additionally, the function should validate if the given dimensions can form a valid triangle. If the dimensions are invalid, the function should raise ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_triangle_area(base: int, height: int) -> int: """ Calculate the area of a triangle given its base and height, ensuring both are positive integers between 1 and 100, inclusive. Additionally, validate if the give...
python_sharegpt_23k
10,632
Write a Python function to calculate the surface area of a sphere using the formula `4 * pi * r^2`, without using the `pi` constant or any built-in functions that calculate it. Additionally, the function should only accept positive integers for the radius and should round the result to the nearest hundredth. The code s...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_sphere_surface_area(radius: int) -> float: """ Calculate the surface area of a sphere using the formula 4 * pi * r^2, without using the pi constant or any built-in functions that calculate it. The result is...
python_sharegpt_23k
10,633
Write a Python function to delete all the items from a given dictionary whose keys start with the prefix "item" and end with a digit. The function should efficiently handle large dictionaries without causing memory or performance issues. Additionally, the function should store all the deleted items in a separate list f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def delete_items_with_prefix(dictionary: Dict[str, any]) -> List[Tuple[str, any]]: """ Deletes all items from the given dictionary whose keys start with "item" and end with a digit. Stor...
python_sharegpt_23k
10,635
Write a Python function to check if a string `haystack` contains another string `needle` as a substring. The function should return `True` if the `haystack` string contains the `needle` string as a substring, and `False` otherwise. The function should satisfy the following constraints: - The time complexity should be O...
Here is the Python code to solve the given problem in the markdown block: ```python def substring_check(haystack: str, needle: str) -> bool: """ Checks if the string `haystack` contains the string `needle` as a substring. Args: haystack (str): The string in which to search for the substring. ...
python_sharegpt_23k
10,638
Write a Python function to determine if a given character is an uppercase letter. The function should return `True` if the character is an uppercase letter (A-Z) and `False` otherwise. The function should handle special characters, numbers, and whitespace by returning `False` for them. The function should be case-sensi...
Here is the Python code to solve the given problem in the markdown block: ```python def is_uppercase_letter(char: str) -> bool: """ Determines if a given character is an uppercase letter. Args: char (str): The character to be checked. Returns: bool: True if the character is an uppercas...
python_sharegpt_23k
10,641
Write a Python function to find the index of the highest peak in a list of elevations representing the heights of mountains in meters. If there are multiple peaks with the same height, return the index of the last occurrence. The function should have a time complexity of O(n) and a space complexity of O(1), where n is ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_highest_peak_index(elevations: List[int]) -> int: """ Find the index of the highest peak in a list of elevations. If there are multiple peaks with the same height, return the index of the la...
python_sharegpt_23k
10,642
Write a Python function to reverse a given string without using the `reverse()` function or any built-in string manipulation functions. The solution should have a time complexity of O(n), where n is the length of the string, and should only use constant space complexity. You are not allowed to use any external librarie...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(string: str) -> str: """ Reverses a given string without using the reverse() function or any built-in string manipulation functions. The solution has a time complexity of O(n) and uses constant space compl...
python_sharegpt_23k
10,646
Write a Python function to convert a given string to uppercase and then reverse the string. The function should return the modified string. The code should start with: ```python def convert_and_reverse(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def convert_and_reverse(s: str) -> str: """ Converts the given string to uppercase and then reverses it. Args: s (str): The input string to be converted and reversed. Returns: str: The modified string...
python_sharegpt_23k
10,649
Write a Python function to generate a list of all prime numbers within a given range of positive integers, inclusive of the endpoints. The function should take two parameters: the start and end of the range. The function should return a list of all prime numbers within that range. 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 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
10,651
Write a Python function to remove an element from a given list at a specified index without using the built-in `pop()` function, slicing, or any additional data structures. The function should return the removed element and modify the original list in place. The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def remove_element(lst: List[Any], index: int) -> Any: """ Removes an element from the list at the specified index without using the built-in `pop()` function, slicing, or any additional data struct...
python_sharegpt_23k
10,653
Write a Python function to convert a binary string to its decimal equivalent without using built-in functions or libraries. The function should handle binary strings of up to 1000 characters and have a time complexity of O(n), where n is the length of the binary string. The input binary string will only contain '0's an...
Here is the Python code to solve the given problem in the markdown block: ```python def binary_to_decimal(binary: str) -> int: """ Converts a binary string to its decimal equivalent without using built-in functions or libraries. Args: binary (str): The binary string to convert. It should only conta...
python_sharegpt_23k
10,658
Write a Python function that takes a list of numbers and an optional integer argument specifying the number of decimal places for rounding. The function should return a dictionary where each key is a unique number from the list and the corresponding value is its square root, rounded to the specified number of decimal p...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Union import math def calculate_square_roots(numbers: List[Union[int, float]], decimal_places: int = 2) -> Dict[Union[int, float], float]: """ Calculate the square roots of numbers in a list and r...
python_sharegpt_23k
10,659
Write a Python function to remove all occurrences of a given substring from a string while maintaining the original order of the characters in the string. The function should handle cases where the substring is an empty string or where the substring is not found in the original string. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_substring(string: str, substring: str) -> str: """ Removes all occurrences of a given substring from the input string while maintaining the original order of characters. Args: string (str): The original s...
python_sharegpt_23k
10,660
Write a Python function to reverse a given string without using any built-in string manipulation functions or methods and without using any additional data structures. The function should have a complexity of O(n), where n is the length of the string. The function should be implemented using only constant space complex...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(string: str) -> str: """ Reverses a given string without using any built-in string manipulation functions or methods and without using any additional data structures. Args: string (str): The input...
python_sharegpt_23k
10,663
Write a Python function to generate a multiplication table for a given number `n`. The function should return a 2D list (a list of lists) where each sublist represents a row in the multiplication table. Each element in the sublist should be the product of the row index and the column index. The row and column indices s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_multiplication_table(n: int) -> List[List[int]]: """ Generate a multiplication table for a given number n. Args: n (int): The number up to which the multiplication table should ...
python_sharegpt_23k
10,678
Write a Python function to filter and return a list of tuples containing the indices and values of elements in a given list that are divisible by a specified divisor. The function should not use any built-in functions or libraries that directly solve the problem. The code should start with: ```python from typing impor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def filter_divisible_by(arr: List[int], divisor: int) -> List[Tuple[int, int]]: """ Filters and returns a list of tuples containing the indices and values of elements in the given list that are di...
python_sharegpt_23k
10,680
Write a Python function to swap the keys and values of a given dictionary, filter out the entries where the new keys (original values) are greater than 15, and return the filtered dictionary sorted in descending order based on the new keys. The function should not use any built-in functions or methods that directly swa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def swap_and_filter_dict(original_dict: Dict[str, int]) -> Dict[int, str]: """ Swaps the keys and values of the given dictionary, filters out entries where the new keys are greater than 15, and retur...
python_sharegpt_23k
10,682
Write a Python function to remove all occurrences of a given element from a list and return the modified list. The function should have a time complexity of O(n) and space complexity of O(1), where n is the length of the list. Additionally, the function should not use any built-in Python functions or methods for removi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_element(nums: List[int], val: int) -> List[int]: """ Remove all occurrences of a given element from a list and return the modified list. Args: nums (List[int]): The list from whic...
python_sharegpt_23k
10,687
Write a Python function to determine if a given binary search tree (BST) is balanced. A balanced BST is defined as a tree in which the heights of the two subtrees of any node never differ by more than one. The function should return `True` if the BST is balanced and `False` otherwise. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Optional class TreeNode: def __init__(self, key): self.key = key self.left = None self.right = None def is_balanced(root: Optional[TreeNode]) -> bool: """ Determine if a binary se...
python_sharegpt_23k
10,688
Write a Python function to implement the quicksort algorithm that can handle duplicate elements in the input array and has a time complexity of O(nlogn). Additionally, include error handling to manage scenarios where the input array is empty or contains only one element. 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 def quicksort(arr: List[int]) -> List[int]: """ Sorts the input array using the quicksort algorithm. Args: arr (List[int]): The input array to be sorted. Returns: List[int]: The...
python_sharegpt_23k
10,692
Write a Python function to determine if two given strings are anagrams, considering the following requirements: 1. The function should be case-sensitive. 2. The function should ignore spaces and special characters. 3. The function should consider the frequency of each character in the strings and return `True` only if ...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(str1: str, str2: str) -> bool: """ Determines if two strings are anagrams, considering case sensitivity and ignoring spaces and special characters. Args: str1 (str): The first string to compare. ...
python_sharegpt_23k
10,693
Write a Python function to print all the elements of a given list in reverse order, but only for odd-indexed elements. Additionally, you must use a while loop to iterate through the list. The list should contain at least 10 elements, and each element must be unique and be of type string. Finally, you should implement a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_odd_indexed_palindromes(my_list: List[str]): """ Prints all the elements of the given list in reverse order, but only for odd-indexed elements. Additionally, only palindrome elements are pr...
python_sharegpt_23k
10,697
Write a Python function to determine if a given integer `n` is a power of two. A number is considered a power of two if it can be expressed as \(2^k\) where \(k\) is a non-negative integer. The function should return `True` if `n` is a power of two, and `False` otherwise. The code should start with: ```python def is_po...
Here is the Python code to solve the given problem in the markdown block: ```python def is_power_of_two(n: int) -> bool: """ Determine if a given integer n is a power of two. Args: n (int): The integer to check. Returns: bool: True if n is a power of two, False otherwise. """ #...
python_sharegpt_23k
10,699
Write a Python function to sort a list of positive integers in ascending order using the Bubble Sort algorithm. The function should not use any built-in sorting functions or libraries. The list should only contain positive integers. The code should start with: ```python from typing import List def bubble_sort(my_list:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(my_list: List[int]) -> List[int]: """ Sorts a list of positive integers in ascending order using the Bubble Sort algorithm. Args: my_list (List[int]): The list of positive in...
python_sharegpt_23k
10,701
Write a Python function to safely divide two numbers, `x` and `y`, and handle specific error cases. The function should return a custom error message if `x` and `y` are equal, and handle division by zero and type errors appropriately. The code should start with: ```python def safe_divide(x: float, y: float) -> str: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def safe_divide(x: float, y: float) -> str: """ Safely divide two numbers and handle specific error cases. Args: x (float): The numerator. y (float): The denominator. Returns: str: The result of...
python_sharegpt_23k
10,704
Write a Python function to sort a list of dictionaries by the `public_id` in descending order. If multiple dictionaries have the same `public_id`, they should be sorted by the `name` in ascending order. The sorting should be done using a custom sorting algorithm that you need to implement from scratch, rather than usin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def custom_sort(data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Sorts a list of dictionaries by the 'public_id' in descending order. If multiple dictionaries have the same 'public_id',...
python_sharegpt_23k
10,708
Write a Python function to calculate the average of all prices in a given JSON object that are greater than or equal to a specified threshold, rounded to the nearest whole number. The function should handle empty arrays gracefully, returning 0 in such cases. The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def get_average_price_above_threshold(data: List[Dict[str, int]], threshold: int) -> int: """ Calculate the average of all prices in the given JSON object that are greater than or equal to a specif...
python_sharegpt_23k
10,715
Write a Python function to convert a list of integers into a string representation of the integers in reverse order, separated by semicolons. The function should handle an empty list by returning an empty string. The code should start with: ```python from typing import List def reverse_and_join(integers: List[int]) ->...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def reverse_and_join(integers: List[int]) -> str: """ Converts a list of integers into a string representation of the integers in reverse order, separated by semicolons. Args: integers (Li...
python_sharegpt_23k
10,720
Write a Python function to modify a list of integers according to the following rules: - All even numbers should be squared. - All odd numbers should be converted to their negative equivalent. The function should return the modified list. The code should start with: ```python from typing import List def modify_list(nu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def modify_list(nums: List[int]) -> List[int]: """ Modifies a list of integers according to the following rules: - All even numbers are squared. - All odd numbers are converted to their negative ...
python_sharegpt_23k
10,721
Write a Python function to find the minimum and maximum values from a list along with the indices of all occurrences of these values. The function should ensure a time complexity of O(n log n) and a space complexity of O(1). The function should handle lists with duplicate values and return the indices of all occurrence...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def get_min_max_indices(lst: List[int]) -> Tuple[int, int, List[int], List[int]]: """ Find the minimum and maximum values from a list along with the indices of all occurrences of these values. ...
python_sharegpt_23k
10,722
Write a Python function that takes in a list of words as input and returns a dictionary where the keys are the words and the values are the lengths of the words. The words in the input list will contain only lowercase letters and have lengths between 1 and 20 characters. The function should handle cases where the input...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def word_lengths(words: List[str]) -> Dict[str, int]: """ Creates a dictionary where the keys are words from the input list and the values are their lengths. Args: words (List[str]): A...
python_sharegpt_23k
10,725
Write a Python function to implement a binary search algorithm that works with a list of integers. The function should return the index of the target number if it is present in the list, otherwise, it should return -1. The algorithm should have a time complexity of O(log n) and a space complexity of O(1). The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(arr: List[int], target: int) -> int: """ Perform a binary search on a sorted list of integers to find the index of the target number. Args: arr (List[int]): A sorted li...
python_sharegpt_23k
10,728
Write a Python function to implement binary search in a sorted array. The function should return `True` if the target element is found in the array, and `False` otherwise. The function should adhere to the following constraints: - The input array will always be sorted in ascending order. - The input array can contain d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(arr: List[int], target: int) -> bool: """ Implements binary search to determine if a target element is present in a sorted array. Args: arr (List[int]): A sorted list of in...
python_sharegpt_23k
10,731
Write a Python function to sum all the even numbers in a given array. If the array is empty, return 0. If the array contains only odd numbers, return -1. The code should start with: ```python from typing import List def sum_even_numbers(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_even_numbers(arr: List[int]) -> int: """ Sum all the even numbers in a given array. If the array is empty, return 0. If the array contains only odd numbers, return -1. Args: arr ...
python_sharegpt_23k
10,732
Write a Python function to remove the element "red" from a given list of strings and sort the remaining elements in alphabetical order. The sorting should be case-sensitive. The function should handle lists with duplicate elements and ensure that the element "red" is completely removed before sorting. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_red_and_sort(arr: List[str]) -> List[str]: """ Removes the element "red" from the given list of strings and sorts the remaining elements in alphabetical order. Args: arr (List[str...
python_sharegpt_23k
10,733
Write a Python function to round each number in a given list to 4 decimal places and return a new list with the rounded numbers. The input list can contain duplicate numbers, and the output list should maintain the same order as the input list. The function should only use built-in mathematical functions and not rely o...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def round_to_four_decimals(numbers: List[float]) -> List[float]: """ Rounds each number in the input list to 4 decimal places and returns a new list with the rounded numbers. Args: numbers (...
python_sharegpt_23k
10,735
Write a Python function to convert a list of integers into a comma-separated string, ensuring that the string is sorted in ascending order. The time complexity of the solution should be less than O(n log n). The code should start with: ```python from typing import List def convert_to_sorted_string(numbers: List[int])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def convert_to_sorted_string(numbers: List[int]) -> str: """ Converts a list of integers into a comma-separated string, sorted in ascending order. The time complexity of the solution is O(n). Ar...
python_sharegpt_23k
10,737
Write a Python function to compute the Manhattan distance between two points in a 3D space. The function should handle inputs in the form of tuples representing the coordinates of the points and return the distance rounded to two decimal places. The Manhattan distance is calculated using the formula `abs(x2 - x1) + abs...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def manhattan_distance(p1: Tuple[float, float, float], p2: Tuple[float, float, float]) -> float: """ Compute the Manhattan distance between two points in a 3D space. Args: p1 (Tuple[float, ...
python_sharegpt_23k
10,754
Write a Python function to categorize a given list of integers into odd and even numbers, and return the results in ascending order. The function should only use a single loop for categorization and should not use any built-in sorting functions. The time complexity of the function should be O(n log n). The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def categorize_and_sort(arr: List[int]) -> Tuple[List[int], List[int]]: """ Categorizes a list of integers into odd and even numbers, and returns them sorted in ascending order. Args: ...
python_sharegpt_23k
10,755
Write a Python function to compute the sum of all odd elements in a given matrix, which may contain negative numbers. The matrix will always have at least one row and one column. The function should solve the problem in a single pass through the matrix without using any extra space. 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 sum_of_odd_elements(matrix: List[List[int]]) -> int: """ Compute the sum of all odd elements in a given matrix. Args: matrix (List[List[int]]): A 2D list representing the matrix. Re...
python_sharegpt_23k
10,758
Write a Python function to determine if a given number is a palindrome without converting the number to a string or using any string manipulation functions. The function should have a time complexity of O(log n), where n is the number of digits in the input number, and should use only constant space complexity. The co...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome_number(number: int) -> bool: """ Determines if a given number is a palindrome without converting it to a string. Args: number (int): The number to check for palindrome property. Returns: ...
python_sharegpt_23k
10,760
Write a Python function to calculate the sum of all prime numbers in a given list. The function should take a list of integers as input and return the sum of all prime numbers in that list. The code should start with: ```python from typing import List def sum_of_primes(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a given number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False other...
python_sharegpt_23k
10,762
Write a Python function to shuffle an array such that no two adjacent elements in the shuffled array have a difference greater than 1. Additionally, the shuffled array should have the smallest possible difference between its minimum and maximum values. The time complexity of the solution should not exceed O(n log n), w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def shuffle_array(arr: List[int]) -> List[int]: """ Shuffles the array such that no two adjacent elements have a difference greater than 1, and the shuffled array has the smallest possible difference...
python_sharegpt_23k
10,765
Write a Python function to retrieve the first key-value pair from a dictionary where the key starts with a given letter and the value is greater than a specified minimum value. The dictionary must have at least 5 key-value pairs. The function should handle cases where the starting letter is uppercase or the minimum val...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple, Optional def retrieve_first_matching_pair(dictionary: Dict[str, int], starting_letter: str, minimum_value: int) -> Optional[Tuple[str, int]]: """ Retrieves the first key-value pair from a diction...
python_sharegpt_23k
10,767
Implement an iterative quick-sort algorithm in Python to sort a given array in ascending order. The implementation should handle arrays with duplicate elements efficiently and should have a time complexity of O(nlogn). Additionally, you are not allowed to use any built-in sorting functions or libraries in your implemen...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def iterative_quicksort(arr: List[int]) -> List[int]: """ Sorts the given array in ascending order using an iterative quick-sort algorithm. Args: arr (List[int]): The array to be sorted. ...
python_sharegpt_23k
10,769
Write a Python function to find the first occurrence of a target integer in a sorted list of integers using a binary search algorithm. The function should return the index of the first occurrence of the target in the list, or -1 if the target is not found. The code should start with: ```python from typing import List ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first(nums: List[int], target: int) -> int: """ Find the index of the first occurrence of a target integer in a sorted list of integers using binary search. Args: nums (Lis...
python_sharegpt_23k
10,773
Write a Python function to create a frequency table from a list of integers. The function should return a dictionary where the keys are the unique integers from the list, and the values are the number of times each integer appears in the list. The function should handle edge cases such as an empty input list, negative ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def create_frequency_table(lst: List[int]) -> Dict[int, int]: """ Creates a frequency table from a list of integers. Args: lst (List[int]): The list of integers to create the frequency...
python_sharegpt_23k
10,777
Write a Python function to merge two given arrays and remove duplicates. The merged array should be sorted in ascending order. The function should use the merge sort algorithm to merge the two arrays in O(n log n) time complexity and an efficient algorithm to remove duplicates from the merged array in O(n) time complex...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_and_remove_duplicates(arr1: List[int], arr2: List[int]) -> List[int]: """ Merge two arrays, remove duplicates, and return the sorted array. Args: arr1 (List[int]): The first array....
python_sharegpt_23k
10,778
Write a Python function to generate a unique key for each item in a given array of strings. The key should be a combination of the first two letters of the item in uppercase, followed by a random number between 100 and 999. Additionally, the key should be unique among all the keys generated. The function should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_keys(arr: List[str]) -> List[str]: """ Generates a unique key for each item in the given array of strings. The key is a combination of the first two letters of ...
python_sharegpt_23k
10,782
Write a Python function to generate a random prime number between 0 and 100 that is divisible by 5. The function should ensure that the generated number meets both criteria: it is a prime number and it is divisible by 5. The code should start with: ```python import random def generate_prime_divisible_by_5() -> int: `...
Here is the Python code to solve the given problem in the markdown block: ```python import random def is_prime(num: int) -> bool: """ Check 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 otherw...
python_sharegpt_23k
10,784
Write a Python function to compute the element-wise product of two lists of integers. The function should return a new list containing the product of each corresponding pair of integers from the input lists. The function must ensure that the input lists are of the same length and should have a time complexity of O(n), ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def element_wise_product(a: List[int], b: List[int]) -> List[int]: """ Computes the element-wise product of two lists of integers. Args: a (List[int]): The first list of integers. b ...
python_sharegpt_23k
10,785
Write a Python function to multiply two matrices. The input matrices can have different dimensions, but they will always be compatible for multiplication. The function should return the resulting matrix. The code should start with: ```python from typing import List def matrix_multiply(matrixA: List[List[int]], matrix...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def matrix_multiply(matrixA: List[List[int]], matrixB: List[List[int]]) -> List[List[int]]: """ Multiplies two matrices and returns the resulting matrix. Args: matrixA (List[List[int]]): The...
python_sharegpt_23k
10,786
Write a Python function to find all common elements between two lists, ignoring duplicates in both lists, and return them in ascending order. Additionally, return the count of common elements. The function should adhere to the following constraints: 1. Do not use any built-in Python functions or methods for finding com...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_common_elements(list1: List[int], list2: List[int]) -> Tuple[List[int], int]: """ Find all common elements between two lists, ignoring duplicates, and return them in ascending order along...
python_sharegpt_23k
10,789
Write a Python function to calculate the sum of the Triangle Series up to a given number `n`, and also return the number of terms in the series. The function should only use a loop structure to calculate the sum, and not use any built-in mathematical functions or libraries. Additionally, the function should handle and ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_triangle_series(n: int) -> tuple: """ Calculate the sum of the Triangle Series up to the given number n, and return the number of terms in the series. The Triangle Series is defined as the sum of the first n n...
python_sharegpt_23k
10,799
Write a Python function to sum the elements of a given array, excluding any negative numbers and counting duplicate positive numbers only once. The function should return the sum of the unique positive numbers in the array. The code should start with: ```python from typing import List def sum_unique_positive_elements...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_unique_positive_elements(arr: List[int]) -> int: """ Sums the unique positive elements of a given array, excluding any negative numbers. Args: arr (List[int]): The array of integers ...
python_sharegpt_23k
10,804
Write a Python function to sort an array of integers in descending order using the bubble sort algorithm. The function should adhere to the following constraints: - The time complexity should be O(n^2) in the worst case. - The space complexity should be O(1). - You are not allowed to use any built-in sorting functions ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort_descending(arr: List[int]) -> List[int]: """ Sorts an array of integers in descending order using the bubble sort algorithm. Args: arr (List[int]): The array of integers to b...
python_sharegpt_23k
10,814
Write a Python function to concatenate two given strings with a space in between and return the length of the resulting string. The function should handle cases where the input strings might be empty. The code should start with: ```python def concatenate_and_get_length(string1: str, string2: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def concatenate_and_get_length(string1: str, string2: str) -> int: """ Concatenates two given strings with a space in between and returns the length of the resulting string. Args: string1 (str): The first string to ...
python_sharegpt_23k
10,823
Write a Python function to implement a binary search algorithm that accounts for duplicates in the list. The function should return the index of the first occurrence of the target element if it exists, otherwise return -1. The code should start with: ```python from typing import List def binary_search_with_duplicates...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_with_duplicates(arr: List[int], target: int) -> int: """ Perform a binary search to find the index of the first occurrence of the target element in a sorted list that may contain duplic...
python_sharegpt_23k
10,824
Write a Python function to convert a non-negative integer to a string of exactly 8 digits, padding with leading zeros if necessary. Additionally, implement a validation check to ensure that the integer provided is not negative. The function should raise a `ValueError` if the integer is negative. The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_8_digit_string(integer: int) -> str: """ Converts a non-negative integer to a string of exactly 8 digits, padding with leading zeros if necessary. Args: integer (int): The non-negative integer to be c...
python_sharegpt_23k
10,825
Write a Python function to sort an array in-place using the Bubble Sort algorithm in descending order. The function should have a time complexity of O(n^2) and a space complexity of O(1). The code should start with: ```python from typing import List def bubble_sort_descending(arr: List[int]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort_descending(arr: List[int]) -> None: """ Sorts the given array in-place using the Bubble Sort algorithm in descending order. Args: arr (List[int]): The array to be sorted. ...
python_sharegpt_23k
10,830
Write a Python function to find the largest element in a list of integers. If there are multiple occurrences of the largest element, return the index of the first occurrence. If the list is empty, return -1. The function should adhere to the following constraints: - Do not use any built-in functions or libraries that d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_largest_element(arr: List[int]) -> Tuple[int, int]: """ Find the largest element in a list of integers and return the element and its index. If there are multiple occurrences of the l...
python_sharegpt_23k
10,832
Write a Python function to print each word of a given sentence on a separate line, with all letters in uppercase, without using any built-in string manipulation functions such as `upper()` or `split()`. The function should start with: ```python def print_words_in_uppercase(sentence: str) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_words_in_uppercase(sentence: str) -> None: """ Prints each word of the given sentence on a separate line with all letters in uppercase. Args: sentence (str): The sentence to be processed. Returns: ...
python_sharegpt_23k
10,837
Write a Python function to remove all occurrences of a specified character from a given string. The function should return the modified string. The code should start with: ```python def remove_character(string: str, character: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def remove_character(string: str, character: str) -> str: """ Removes all occurrences of a specified character from a given string. Args: string (str): The input string from which to remove the character. ch...
python_sharegpt_23k
10,841
Write a Python function to find the second smallest element in a given list of integers. The function should be efficient and handle lists with negative numbers and duplicates. The code should start with: ```python from typing import List def find_second_minimum(lst: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def find_second_minimum(lst: List[int]) -> int: """ Find the second smallest element in a given list of integers. Args: lst (List[int]): The list of integers from which to find the second ...
python_sharegpt_23k
10,845
Write a Python function to reverse a given string without using any built-in string reversal functions or methods. The input string will contain only alphabetic characters and will have a maximum length of 100 characters. Additionally, your function should run in O(n) time complexity, where n is the length of the input...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses a given string without using any built-in string reversal functions or methods. Args: s (str): The input string to be reversed. It contains only alphabetic characters ...
python_sharegpt_23k
10,847
Write a Python function to sort an array of integers in increasing order using the Merge Sort algorithm. The function should have a time complexity of O(n log n). The code should start with: ```python from typing import List def merge_sort(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 merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in increasing order using the Merge Sort algorithm. Args: arr (List[int]): The array of integers to be sorted. ...
python_sharegpt_23k
10,848
Write a Python function to find the smallest number in an array of numbers without using any conditional statements (such as `if/else` or `switch`) or any built-in functions that directly solve this problem (such as `min()`). The function should have a time complexity of O(n) and a space complexity of O(1), where n is ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_number(numbers: List[int]) -> int: """ Find the smallest number in an array of numbers without using any conditional statements or built-in functions. Args: numbers (List[i...
python_sharegpt_23k
10,860
Write a Python function to calculate the sum of two given positive integers, ensuring that the sum does not exceed a specified maximum value. The function should validate that the input numbers and the maximum value are positive integers. If the sum exceeds the maximum value, the function should return the maximum valu...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_with_limit(num1: int, num2: int, max_value: int) -> int: """ Calculate the sum of two positive integers, ensuring the sum does not exceed a specified maximum value. Args: num1 (int): The first positive integ...
python_sharegpt_23k
10,861
Write a Python function to generate and print all the even numbers from 1 to 10 in ascending order, but the function should stop immediately if an odd number is encountered. The function should not use any conditional statements (if-else) inside the loop. The code should start with: ```python def print_even_numbers():...
Here is the Python code to solve the given problem in the markdown block: ```python def print_even_numbers(): """ Prints all even numbers from 1 to 10 in ascending order, stopping immediately if an odd number is encountered. The function does not use any conditional statements (if-else) inside the loop. ...
python_sharegpt_23k
10,863
Write a Python function that processes a list of strings, capitalizing each string and removing any strings that contain special characters. Special characters are defined as any characters that are not alphanumeric or whitespace. The function should return a new list containing the processed strings. The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def process_strings(strings: List[str]) -> List[str]: """ Processes a list of strings by capitalizing each string and removing any strings that contain special characters. Args: st...
python_sharegpt_23k
10,865
Write a Python function to calculate the sum of all integer values in a given list, including nested lists. Non-integer elements should be ignored. The sum should be returned as a floating-point number rounded to two decimal places. The code should start with: ```python from typing import List, Union def nested_list_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def nested_list_sum(lst: List[Union[int, List]]) -> float: """ Calculate the sum of all integer values in a given list, including nested lists. Non-integer elements are ignored. The sum is ret...
python_sharegpt_23k
10,867
Write a Python function to reverse a given string without using any built-in string reversal functions or methods. The solution should have a time complexity of O(n) and a space complexity of O(1). The function should start with: ```python def reverse_string(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses a given string without using any built-in string reversal functions or methods. Args: s (str): The input string to be reversed. Returns: str: The reversed...
python_sharegpt_23k
10,871
Write a Python function to calculate the area of a triangle given the lengths of all three sides using Heron's formula. The function should handle the input validation to ensure that the sides can form a valid triangle. The code should start with: ```python from typing import Tuple import math def calculate_triangle_a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import math def calculate_triangle_area(side1: float, side2: float, side3: float) -> Tuple[float, str]: """ Calculate the area of a triangle given the lengths of all three sides using Heron's formula. ...
python_sharegpt_23k
10,875
Write a Python function to find the maximum number in an array without using the built-in `max()` function, ensuring that the solution has a time complexity of O(n log n). The function should recursively divide the array into halves, find the maximum in each half, and then compare the results to determine the overall m...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_in_array(arr: List[int]) -> int: """ Find the maximum number in an array without using the built-in max() function. The solution has a time complexity of O(n log n). Args: a...
python_sharegpt_23k
10,876
Write a Python function to search for the first occurrence of a target element in a sorted array that may contain duplicate elements. If the target is found, return its index; otherwise, return -1. The function should have a time complexity of O(log n), where n is the length of the 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 def search_first_occurrence(arr: List[int], target: int) -> int: """ Searches for the first occurrence of a target element in a sorted array. Args: arr (List[int]): The sorted array to searc...
python_sharegpt_23k
10,877
Write a Python function to rotate a given square matrix by 90 degrees in a clockwise direction. The matrix is represented as a two-dimensional list, where each inner list represents a row of the matrix. The function should modify the matrix in-place and return the modified matrix. 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 rotate_matrix_90_clockwise(matrix: List[List[int]]) -> List[List[int]]: """ Rotates a given square matrix by 90 degrees in a clockwise direction in-place. Args: matrix (List[List[int]]):...
python_sharegpt_23k
10,879
Write a Python function to calculate the sum of all positive numbers in a given list of integers. The function should have a time complexity of O(n), where n is the length of the input list. The function should start with: ```python from typing import List def sum_of_positives(numbers: 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_positives(numbers: List[int]) -> int: """ Calculate the sum of all positive numbers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: ...
python_sharegpt_23k
10,880
Write a Python function to calculate the average of positive even numbers from a given list of numbers. The function should handle errors and ensure the input list contains at least one number. The function should raise appropriate exceptions if the input list is empty, contains non-numeric values, or does not contain ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_average_of_positive_evens(numbers: List[float]) -> float: """ Calculate the average of positive even numbers from a given list of numbers. Args: numbers (List[float]): A list o...
python_sharegpt_23k
10,884
Write a Python function to compute the median of an array of n integers, where n is an odd number greater than 1. The array may contain duplicate elements. The function should not use any built-in sorting functions or data structures and should have a time complexity of O(n) and a space complexity of O(n). The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_median(arr: List[int]) -> int: """ Computes the median of an array of n integers, where n is an odd number greater than 1. The array may contain duplicate elements. The function does not use...
python_sharegpt_23k
10,891
Write a Python function to remove all occurrences of a specified item from a given list. The function should not use the built-in `remove` function and should have a time complexity of O(n). The function should return a new list with all occurrences of the specified item removed. 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 remove_all_occurrences(lst: List[int], item: int) -> List[int]: """ Removes all occurrences of a specified item from a given list and returns a new list. Args: lst (List[int]): The list ...