source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
12,876
Write a Python function to identify if a given number is prime or not. Additionally, create a function to find the nth prime number. Both functions should handle invalid inputs, such as negative numbers or non-integer inputs, and raise appropriate exceptions. The code should start with: ```python def is_prime(n: int) ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determines if a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. Raises: ...
python_sharegpt_23k
12,883
Write a Python function to find and return a list of prime numbers between a given range `[start, end]` in descending order. The function should handle edge cases such as negative numbers, zero, and non-prime numbers within the range. The code should start with: ```python from typing import List def get_primes_in_ran...
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
12,890
Write a Python function to perform a depth-first search (DFS) on a given binary tree and return the sum of all the nodes in the tree. Additionally, the function should keep track of the maximum value node found during the search. The binary tree is represented using a `Node` class with attributes `value`, `left`, and `...
Here is the Python code to solve the given problem in the markdown block: ```python class Node: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right def dfs_sum_and_max(root: Node) -> (int, int): """ Perform a depth-first search on...
python_sharegpt_23k
12,894
Write a Python function to find the median of three numbers without using any conditional statements (if, elif, else), comparison operators (>, <, ==), or built-in functions for sorting or finding the median. The function should only use mathematical operations and functions. The code should start with: ```python def f...
Here is the Python code to solve the given problem in the markdown block: ```python def find_median(a: int, b: int, c: int) -> int: """ Find the median of three numbers without using conditional statements, comparison operators, or built-in sorting functions. Only mathematical operations are allowed. A...
python_sharegpt_23k
12,895
Write a Python function to count the occurrences of each unique English alphabet letter in a given string, ignoring any punctuation marks, special characters, and spaces. The function should handle both uppercase and lowercase letters as separate entities and return a dictionary where the keys are the letters and the v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict import string def count_unique_letters(input_string: str) -> Dict[str, int]: """ Counts the occurrences of each unique English alphabet letter in a given string, ignoring any punctuation marks, speci...
python_sharegpt_23k
12,898
Write a Python function to add two given binary numbers with the following constraints: - The time complexity of the algorithm should be O(log n), where n is the length of the longer binary number. - The space complexity of the algorithm should be O(1), i.e., the algorithm should not use any additional data structures ...
Here is the Python code to solve the given problem in the markdown block: ```python def add_binary_numbers(binary1: str, binary2: str) -> str: """ Adds two binary numbers represented as strings. Args: binary1 (str): The first binary number as a string. binary2 (str): The second binary numbe...
python_sharegpt_23k
12,903
Write a Python function to delete all prime numbers from an array of integers up to the first `n` numbers. The function should return the modified array. The function should not use any built-in functions or libraries to check for prime numbers. The function should handle edge cases, such as when `n` is less than or eq...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(num: int) -> bool: """ Helper function to check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the num...
python_sharegpt_23k
12,913
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 that contain spaces, punctuation marks, and should be case-insensitive. The function should efficiently han...
Here is the Python code to solve the given problem in the markdown block: ```python import string def are_anagrams(str1: str, str2: str) -> bool: """ Determine if two given strings are anagrams of each other. Args: str1 (str): The first string to check. str2 (str): The second string to che...
python_sharegpt_23k
12,917
Write a Python function to reverse a given string without using any built-in functions or methods that directly reverse a string. The function should implement the reversal logic manually. The code should start with: ```python def reverse_string(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def reverse_string(input_string: str) -> str: """ Reverses the input string without using any built-in functions or methods that directly reverse a string. Args: input_string (str): The string to be reversed. ...
python_sharegpt_23k
12,919
Write a Python function that takes an integer as input and returns a float that is rounded to the nearest thousandth, but only if the input is positive and greater than zero. If the input is negative or zero, the function should return the string "Invalid input". The code should start with: ```python def round_to_thou...
Here is the Python code to solve the given problem in the markdown block: ```python def round_to_thousandth(num: int) -> float or str: """ Rounds the given integer to the nearest thousandth if the input is positive and greater than zero. If the input is negative or zero, returns "Invalid input". Args: ...
python_sharegpt_23k
12,927
Write a Python function that takes in two strings (`s1`, `s2`) and an integer (`n`) and returns a string. The output should be the concatenation of `s1` and `s2` repeated `n` times. The function should handle the following edge cases: - If either `s1` or `s2` is an empty string, the function should return an empty stri...
Here is the Python code to solve the given problem in the markdown block: ```python def repeat_concatenated_strings(s1: str, s2: str, n: int) -> str: """ Returns a string that is the concatenation of `s1` and `s2` repeated `n` times. Args: s1 (str): The first string to be concatenated. s2 (...
python_sharegpt_23k
12,929
Write a Python function to find the union of two sets. The function should take two sets as input and return a new set that contains all the elements from both sets without any duplicates. The function should be able to handle sets of different lengths and empty sets. The order of the elements in the output set does no...
Here is the Python code to solve the given problem in the markdown block: ```python def find_union(set1: set, set2: set) -> set: """ Find the union of two sets. Args: set1 (set): The first set. set2 (set): The second set. Returns: set: A new set containing all elements from bot...
python_sharegpt_23k
12,930
Write a Python function to remove all occurrences of a given number `num` from an input array `array` without using the `remove()` method. The function should return a new array that contains all elements from the original array except for the specified number. The code should start with: ```python from typing import ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_all_occurrences(array: List[int], num: int) -> List[int]: """ Removes all occurrences of the given number `num` from the input array `array` and returns a new array. Args: array (...
python_sharegpt_23k
12,933
Write a Python function to calculate the Levenshtein distance between two strings. The Levenshtein distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. The function should handle strings of different lengths. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python def levenshtein_distance(str1: str, str2: str) -> int: """ Calculate the Levenshtein distance between two strings. The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or subs...
python_sharegpt_23k
12,939
Write a Python function to calculate the Nth Fibonacci number using an optimized approach with a time complexity of O(1) and a space complexity of O(1). The function should use mathematical formulas to achieve this efficiency. The code should start with: ```python import math def nth_fibonacci(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def nth_fibonacci(n: int) -> int: """ Calculate the Nth Fibonacci number using Binet's formula. Args: n (int): The position of the Fibonacci number to calculate. Returns: int: The Nth Fibon...
python_sharegpt_23k
12,946
Write a Python function to implement the Comb Sort algorithm, which is an advanced variation of the Bubble Sort algorithm. The function should sort an array of integers in ascending order by repeatedly swapping adjacent elements if they are in the wrong order, with a decreasing gap size. The gap size starts with the to...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def comb_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers using the Comb Sort algorithm. Comb Sort is an advanced variation of Bubble Sort that works by repeatedly swapping adja...
python_sharegpt_23k
12,949
Write a Python function to calculate the product of all the elements in a given two-dimensional array that are perfect squares. A perfect square is a number that can be expressed as the square of an integer. The code should start with: ```python from typing import List def product_of_perfect_squares(arr: List[List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def product_of_perfect_squares(arr: List[List[int]]) -> int: """ Calculate the product of all perfect square elements in a given two-dimensional array. Args: arr (List[List[int]]): A two-dim...
python_sharegpt_23k
12,952
Write a Python function to add two positive prime integers less than 1000. The function should validate that both inputs are positive prime integers less than 1000 before performing the addition. If any input does not meet these criteria, the function should return an appropriate error message. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def add_prime_numbers(a: int, b: int) -> int or str: """ Adds two positive prime integers less than 1000. Args: a (int): The first number to add. b (int): The second number to add. Returns: int ...
python_sharegpt_23k
12,957
Write a Python function to find the most frequent element in a list that appears at least twice. The input list will contain at most \(10^6\) elements, and each element will be an integer between 0 and \(10^9\). You are not allowed to use any built-in sorting or counting functions in your solution. The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def most_frequent_element(lst: List[int]) -> Optional[int]: """ Find the most frequent element in a list that appears at least twice. Args: lst (List[int]): The input list of integ...
python_sharegpt_23k
12,958
Write a Python function to sort a list of dictionaries by the "score" value and calculate the median score of the sorted list. The "score" values are integers between -100 and 100 (inclusive). The function should return both the sorted list and the median score. The code should start with: ```python from typing import...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def sort_and_get_median_score(lst: List[Dict[str, int]]) -> Tuple[List[Dict[str, int]], float]: """ Sorts a list of dictionaries by the "score" value and calculates the median score of the s...
python_sharegpt_23k
12,961
Write a Python function to determine if two given strings are anagrams of each other. The function should handle cases where the input strings contain special characters, numbers, and whitespace. The function should ignore any whitespace characters and consider only alphabetic characters when determining if the strings...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(string1: str, string2: str) -> bool: """ Determines if two given strings are anagrams of each other. The function ignores whitespace characters, special characters, and numbers, and considers only alpha...
python_sharegpt_23k
12,972
Write a Python function to find the maximum and minimum elements in a given array, swap their positions, remove any duplicates from the array, and sort it in descending order. The function should return the modified array. The code should start with: ```python from typing import List def process_array(arr: List[int])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_array(arr: List[int]) -> List[int]: """ Process the given array by finding the maximum and minimum elements, swapping their positions, removing duplicates, and sorting the array in descen...
python_sharegpt_23k
12,975
Write a Python function to determine if the elements of a given array are in strictly increasing order. The array may contain both positive and negative integers. The function should return `True` if the elements are in strictly increasing order and `False` otherwise. Additionally, the function should handle cases wher...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_strictly_increasing(arr: List[int]) -> bool: """ Determines if the elements of the given array are in strictly increasing order. Args: arr (List[int]): The array of integers to check....
python_sharegpt_23k
12,981
Write a Python function to reverse the elements of a given list in place without using any built-in functions or additional data structures. The function should have a space complexity of O(1), meaning that it should not use any extra memory except for a few integer variables. The function should return the reversed li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list_in_place(my_list: List[int]) -> List[int]: """ Reverses the elements of a given list in place without using any built-in functions or additional data structures. Args: my_li...
python_sharegpt_23k
12,982
Write a Python function to reverse a given string without using any built-in string manipulation functions or libraries, ensuring that the time complexity of your solution is O(n), where n is the length of the string. 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 manipulation functions or libraries. Args: s (str): The input string to be reversed. Returns: str: The re...
python_sharegpt_23k
12,991
Write a Python function to calculate the factorial of a given positive integer `n` using a recursive approach. The function should also implement a caching mechanism to store previously calculated factorial values to optimize the recursive calls. Additionally, the function should raise a `ValueError` if `n` is not a po...
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 positive integer n using a recursive approach with caching. Args: n (int): The positive integer for which to calculate the factorial. Returns...
python_sharegpt_23k
12,995
Write a Python function to create a dictionary where keys are characters from a given string, and values are the occurrences of those characters, excluding vowels. The occurrences should be case-sensitive, meaning that uppercase and lowercase versions of the same character should be treated as separate characters. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def count_characters_excluding_vowels(string: str) -> dict: """ Counts the occurrences of each character in the given string, excluding vowels, and returns a dictionary. Args: string (str): The input string to count...
python_sharegpt_23k
12,996
Implement a k-means clustering algorithm from scratch in Python. The algorithm should be able to group a given dataset into `k` distinct clusters. You are not allowed to use any built-in libraries or functions that directly implement the k-means algorithm. The code should start with: ```python import numpy as np def k...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def k_means_clustering(data: np.ndarray, k: int, max_iterations: int = 100) -> (np.ndarray, np.ndarray): """ Perform k-means clustering on the given dataset. Args: data (np.ndarray): The dataset ...
python_sharegpt_23k
12,998
Write a Python function to calculate the nth Fibonacci number using a recursive approach. The function should handle at least two base cases and at least two recursive calls within its implementation. The code should start with: ```python def fibonacci(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Calculate the nth Fibonacci number using a recursive approach. Args: n (int): The position in the Fibonacci sequence to calculate. Returns: int: The nth Fibonacci numbe...
python_sharegpt_23k
12,999
Write a Python function to create two variables of type list that contain the same elements in the same order, but with a time complexity of O(n log n). The function should take a list of integers as input and return a tuple containing two lists with the same elements in the same order. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def merge_sort(arr: List[int]) -> List[int]: """ Sorts the input list using the merge sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: L...
python_sharegpt_23k
13,002
Write a Python function to create a matrix of size `m x n` where each element is a random integer between `min_value` and `max_value` (inclusive). The function should return the created matrix. The code should start with: ```python from typing import List import random def create_random_matrix(m: int, n: int, min_val...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def create_random_matrix(m: int, n: int, min_value: int, max_value: int) -> List[List[int]]: """ Create a matrix of size m x n where each element is a random integer between min_value and m...
python_sharegpt_23k
13,007
Write a Python function to determine if a given triangle is a right-angled triangle based on the lengths of its sides. The function should adhere to the following requirements: - It should take three parameters representing the lengths of the sides of the triangle. - It should return `True` if the triangle is a right-a...
Here is the Python code to solve the given problem in the markdown block: ```python def is_right_triangle(a: float, b: float, c: float) -> bool: """ Determines if a triangle with given side lengths is a right-angled triangle. Args: a (float): Length of the first side of the triangle. b (flo...
python_sharegpt_23k
13,010
Write a Python function to generate a list of prime numbers within a given range [start, end]. The function should return a list of all prime numbers in that range. The code should start with: ```python from typing import List def generate_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def generate_primes_in_range(start: int, end: int) -> List[int]: """ Generate a list of prime numbers within the given range [start, end]. Args: start (int): The starting value o...
python_sharegpt_23k
13,011
Write a Python function to replace all instances of the string 'x' with the string 'y' in a given list of integers and strings, while maintaining the order of the elements. The list may contain duplicate elements. The function should handle lists with up to 10^6 elements efficiently. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def replace_x_with_y(lst: List[Union[int, str]]) -> List[Union[int, str]]: """ Replace all instances of the string 'x' with the string 'y' in the given list of integers and strings. Args: ...
python_sharegpt_23k
13,016
Write a Python function to reverse a given array in-place without using any built-in functions or methods that directly reverse the array. The time complexity should be O(n), where n is the length of the array, and the space complexity should be O(1), meaning no additional data structures should be used to store interm...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_array_in_place(arr: List[int]) -> None: """ Reverses the given array in-place without using any built-in functions or methods that directly reverse the array. Args: arr (List[int...
python_sharegpt_23k
13,019
Write a Python function to implement a quick sort algorithm that can handle a large input size of `n` (where `n > 10^6`) efficiently. The algorithm should have a time complexity of O(n log n) and should not exceed the space complexity of O(log n). The input list may contain duplicate numbers and the algorithm should be...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def quick_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the quick sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: List...
python_sharegpt_23k
13,020
Write a Python function to calculate the sum of all prime numbers from 0 to a given integer `n`. The function should include only prime numbers in the sum. The code should start with: ```python def sum_of_primes(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_primes(n: int) -> int: """ Calculate the sum of all prime numbers from 0 to the given integer n. Args: n (int): The upper limit (inclusive) for the range of numbers to check for primes. Returns: ...
python_sharegpt_23k
13,022
Write a Python function to calculate the product of the first N prime numbers. The function should take a positive integer N as input and return the product of the first N prime numbers. The code should start with: ```python def product_of_first_n_primes(N: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def product_of_first_n_primes(N: int) -> int: """ Calculate the product of the first N prime numbers. Args: N (int): The number of prime numbers to consider. Returns: int: The product of the first N pri...
python_sharegpt_23k
13,024
Write a Python function to determine the number of rows and columns in a given matrix. The matrix is guaranteed to have at least one row and one column. The matrix can contain integers, floats, and strings. The function should return the number of rows and a list of the number of columns in each row. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def matrix_dimensions(matrix: List[List[object]]) -> Tuple[int, List[int]]: """ Determine the number of rows and columns in a given matrix. Args: matrix (List[List[object]]): The matr...
python_sharegpt_23k
13,026
Write a Python function to process a message by ensuring it does not exceed 100 characters and contains only alphabetic characters. If the message exceeds the limit, return an error message. If the message contains non-alphabetic characters, remove them. The function should start with: ```python import re def process_...
Here is the Python code to solve the given problem in the markdown block: ```python import re def process_message(message: str) -> str: """ Process a message by ensuring it does not exceed 100 characters and contains only alphabetic characters. Args: message (str): The message to be processed. ...
python_sharegpt_23k
13,028
Write a Python function to calculate the cube of any number using only addition and multiplication operations. The function should handle both positive and negative numbers. The code should start with: ```python def cube_with_addition_and_multiplication(number: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def cube_with_addition_and_multiplication(number: int) -> int: """ Calculate the cube of a given number using only addition and multiplication operations. Args: number (int): The number to calculate the cube of. ...
python_sharegpt_23k
13,029
Write a Python function to extract the unique elements from a given list of numbers while maintaining the original order of occurrence and count the frequency of each unique element. The function should have a time complexity of O(n) and a space complexity of O(n). You are not allowed to use any built-in functions or l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def extract_unique_elements_and_count_frequency(list_of_nums: List[int]) -> (List[int], Dict[int, int]): """ Extracts the unique elements from a given list of numbers while maintaining the original...
python_sharegpt_23k
13,030
Write a Python function to compare two strings using only bitwise operations. The function should have a time complexity of O(n), where n is the length of the longer string. Additionally, the function should use a constant amount of additional space. The function should return `True` if the strings are identical, and `...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings_bitwise(s1: str, s2: str) -> bool: """ Compare two strings using only bitwise operations. Args: s1 (str): The first string to compare. s2 (str): The second string to compare. Returns...
python_sharegpt_23k
13,034
Write a Python function to sort a list of strings in alphabetical order using a divide-and-conquer approach. The function should handle a large number of strings (up to 10^6) efficiently. The input list of strings may contain duplicate strings and special characters. The function should output the sorted list of string...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list_of_strings(list_of_strings: List[str]) -> List[str]: """ Sorts a list of strings in alphabetical order using a divide-and-conquer approach. The function removes duplicates and handles u...
python_sharegpt_23k
13,036
Write a Python function to determine if a given integer is a prime palindrome number. A prime palindrome number is a number that is both prime and a palindrome. The function should return `True` if the number is a prime palindrome, otherwise `False`. The code should start with: ```python import math def is_prime_pali...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime_palindrome(num: int) -> bool: """ Determine if a given integer is a prime palindrome number. Args: num (int): The integer to be checked. Returns: bool: True if the number is bo...
python_sharegpt_23k
13,053
Write a Python function to recursively merge two sorted subarrays `ar1` and `ar2` into a single sorted array. The function should not use any built-in sorting functions or additional data structures. The function should handle cases where the arrays may contain duplicate elements and may not be fully sorted. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_subarrays(ar1: List[int], ar2: List[int]) -> List[int]: """ Recursively merges two sorted subarrays into a single sorted array. Args: ar1 (List[int]): The first sorted subar...
python_sharegpt_23k
13,054
Write a Python function to initialize a dictionary with specific constraints for the values of its keys. The dictionary must contain the following keys: - "name": A string of at least 3 characters. - "age": An integer between 18 and 65 (inclusive) and divisible by 5. - "gender": A string that is either "Male" or "Femal...
Here is the Python code to solve the given problem in the markdown block: ```python def initialize_person_dictionary(name: str, age: int, gender: str, occupation: str) -> dict: """ Initializes a dictionary with specific constraints for the values of its keys. Args: name (str): A string of at least ...
python_sharegpt_23k
13,055
Write a Python function to update the values of a given dictionary by squaring each value while keeping the same keys. The function should take a dictionary as input and return the updated dictionary. The code should start with: ```python from typing import Dict def square_dictionary_values(input_dict: Dict[str, int])...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def square_dictionary_values(input_dict: Dict[str, int]) -> Dict[str, int]: """ Update the values of a given dictionary by squaring each value while keeping the same keys. Args: input_dict (...
python_sharegpt_23k
13,058
Write a Python function to generate a random string of length `n` from a given list of characters, where `n` is the number of elements in the list. The function should use the `random.choice()` function to select characters randomly from the list. The code should start with: ```python from typing import List import ran...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_random_string(data: List[str]) -> str: """ Generates a random string of length n from a given list of characters, where n is the number of elements in the list. Args: ...
python_sharegpt_23k
13,059
Write a Python function to find the smallest number in a given array using a custom implementation of the `reduce` method. The function should not use the built-in `min()` function or any other built-in functions. The custom `reduce` method should be implemented using a loop, ensuring a time complexity of O(n) and a sp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_smallest_with_reduce(arr: List[int]) -> Optional[int]: """ Find the smallest number in the given array using a custom implementation of the reduce method. Args: arr (List[...
python_sharegpt_23k
13,062
Write a Python function to determine if all elements in a given list are equal and to return the count of unique elements in the list. The function should handle lists of any length, including empty lists. The code should start with: ```python from typing import List def check_elements_and_count_unique(arr: List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_elements_and_count_unique(arr: List[int]) -> (bool, int): """ Determines if all elements in the given list are equal and returns the count of unique elements. Args: arr (List[int])...
python_sharegpt_23k
13,066
Write a Python function called `generate_dict` that takes a text input in the format "KEY1:VALUE1,KEY2:VALUE2,KEY3:VALUE3" and returns a Python dictionary. The function should handle the following cases: 1. Split the text on each comma (,) to separate the key-value pairs. 2. Iterate through each key-value pair. 3. Spli...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_dict(text: str) -> dict: """ Converts a formatted text string into a dictionary. The input text should be in the format "KEY1:VALUE1,KEY2:VALUE2,KEY3:VALUE3". The function handles the following cases: -...
python_sharegpt_23k
13,072
Write a Python function to reverse a list without modifying the original list and ensuring the function has a time complexity of O(n) and a space complexity of O(1). The function should return a new list with the elements of the input list reversed. The code should start with: ```python from typing import List def re...
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 without modifying the original list and has a time complexity of O(n) and space complexity of O(1). Args: lst (List[int]): ...
python_sharegpt_23k
13,078
Write a Python function that takes a string as input and returns a tuple containing a boolean and an integer. The boolean should be `True` if the string contains only uppercase letters and numbers that are divisible by 3, and `False` otherwise. The integer should represent the count of numbers in the string that are di...
Here is the Python code to solve the given problem in the markdown block: ```python def check_string_divisible_by_3(input_string: str) -> tuple[int, bool]: """ Check if the input string contains only uppercase letters and numbers divisible by 3. Return a tuple with the count of divisible numbers and a boole...
python_sharegpt_23k
13,079
Write a Python function to filter and sort a list of numbers based on the following criteria: 1. Remove numbers that are greater than 100 and less than 1000. 2. Sort the remaining numbers in descending order. The function should adhere to the following constraints: - The length of the list can be up to \(10^6\). - The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_and_sort_numbers(numbers: List[int]) -> List[int]: """ Filters out numbers that are greater than 100 and less than 1000, and sorts the remaining numbers in descending order. Args: ...
python_sharegpt_23k
13,091
Write a Python function to reduce a given 3-dimensional numpy array of shape (n, m, k) to a 2-dimensional numpy array of shape (n*m, k). The resulting array should contain all the elements from the original array. The function should have a time complexity of O(n*m*k) and a space complexity of O(n*m*k). The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def reduce_3d_array(arr: np.ndarray) -> np.ndarray: """ Reduces a 3-dimensional numpy array of shape (n, m, k) to a 2-dimensional numpy array of shape (n*m, k). Args: arr (np.ndarray): A 3-dimens...
python_sharegpt_23k
13,093
Write a Python function to filter and return a list of movie titles with ratings between 8 and 9 (inclusive) from a given list of movies. The movie titles should be sorted in alphabetical order. The code should start with: ```python from typing import List, Tuple def filter_and_sort_movies(movies: List[Tuple[str, flo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def filter_and_sort_movies(movies: List[Tuple[str, float]]) -> List[str]: """ Filters and sorts movie titles with ratings between 8 and 9 (inclusive) from a given list of movies. Args: ...
python_sharegpt_23k
13,095
Write a Python function to find the union of two sets, `A` and `B`. The function should handle sets with up to 1,000 elements. The union of two sets is a set that contains all the elements from both sets without duplicates. The function should return the union set. The code should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def find_union(A: Set[int], B: Set[int]) -> Set[int]: """ Find the union of two sets, A and B. Args: A (Set[int]): The first set of integers. B (Set[int]): The second set of integers....
python_sharegpt_23k
13,097
Write a Python function to find the length of the longest substring containing no repeated characters in a given string. The substring must be contiguous and the characters must appear in the same order as in the original string. The function should start with: ```python def longest_substring_length(s: str) -> int: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_substring_length(s: str) -> int: """ Find the length of the longest substring containing no repeated characters. Args: s (str): The input string to analyze. Returns: int: The length of the l...
python_sharegpt_23k
13,102
Write a Python function to calculate the sum of all prime numbers up to a given limit `n`. The function should return the sum of these prime numbers. The code should start with: ```python def sum_of_primes_up_to(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_primes_up_to(n: int) -> int: """ Calculate the sum of all prime numbers up to and including the given limit `n`. Args: n (int): The upper limit up to which prime numbers are considered. Returns: ...
python_sharegpt_23k
13,107
Write a Python function that iterates through a given list of numbers and returns a new list containing only the even numbers from the original list. The function should handle lists of integers and return an empty list if no even numbers are found. The code should start with: ```python from typing import List def fil...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_even_numbers(numbers: List[int]) -> List[int]: """ Filters even numbers from a given list of integers. Args: numbers (List[int]): A list of integers to filter. Returns: ...
python_sharegpt_23k
13,114
Write a Python function to create a dictionary from a list of items, where each item can be either a tuple representing a key-value pair or a single element representing a key with a default value of `None`. If there are duplicate keys, the function should handle them by storing the values in a list and then selecting ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union, Tuple def create_and_handle_duplicates(lst: List[Union[Tuple[str, int], str]]) -> dict: """ Create a dictionary from a list of items, handling duplicate keys by storing values in a list and selec...
python_sharegpt_23k
13,115
Write a Python function to transpose a given square 2D array. The array will always be square, meaning that the number of rows will always be equal to the number of columns. The size of the array will not exceed 100. Each element in the array will be an integer in the range of -100 to 100. 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 transpose_square_matrix(matrix: List[List[int]]) -> List[List[int]]: """ Transposes a given square 2D array. Args: matrix (List[List[int]]): The input square matrix to be transposed. ...
python_sharegpt_23k
13,118
Write a Python function to return a new list where each element at index `i` is the product of all other elements in the input list except the element at index `i`. The input list will not contain any zeros. The function should have a time complexity of O(n), where n is the length of the input list. The code should st...
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]: """ Returns a new list where each element at index i is the product of all other elements in the input list except the element at index i. Args...
python_sharegpt_23k
13,119
Write a Python function to calculate the factorial of a given integer `n` efficiently, ensuring that the function handles negative values for `n` and ensures that the final result is within the range of a 64-bit signed integer. The function should return `None` if the result exceeds the 64-bit signed integer limit. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def efficient_factorial(n: int) -> int: """ Calculate the factorial of a given integer `n` efficiently, ensuring that the function handles negative values for `n` and ensures that the final result is within the range of a 64...
python_sharegpt_23k
13,124
Write a Python function to process a given string by splitting it into words, removing any duplicate words, and returning a list of unique words in alphabetical order. The function should ignore punctuation marks and consider words with different capitalizations as the same word. The time complexity of the solution sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def string_formatter(input_string: str) -> List[str]: """ Processes the input string to return a list of unique words in alphabetical order. Args: input_string (str): The input str...
python_sharegpt_23k
13,131
Write a Python function to calculate the frequency of each word in a list of sentences. The function should handle punctuation, special characters, and numbers, and should be case-sensitive. The code should start with: ```python from typing import List, Dict def word_frequency(sentences: List[str]) -> Dict[str, int]: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import re def word_frequency(sentences: List[str]) -> Dict[str, int]: """ Calculate the frequency of each word in a list of sentences. Args: sentences (List[str]): A list of sentences ...
python_sharegpt_23k
13,137
Write a Python function to calculate the factorial of a given positive integer using a recursive approach. The function should handle large numbers efficiently and have a time complexity of O(n). Additionally, it should validate the input to ensure it is a positive integer and return an appropriate error message if it ...
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 positive integer using a recursive approach. Args: n (int): The positive integer for which to calculate the factorial. Returns: int: ...
python_sharegpt_23k
13,138
Write a Python function to format a large number as a string into a more readable format by grouping digits into sets of three and separating them with commas. The function should handle numbers of varying lengths, ensuring that the rightmost group may have fewer than three digits if necessary. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def format_number(number: str) -> str: """ Formats a large number as a string into a more readable format by grouping digits into sets of three and separating them with commas. Args: number (str): The large number t...
python_sharegpt_23k
13,142
Write a Python function to find all prime numbers from 1 to a given number `n` inclusive using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers in that range. The code should start with: ```python from typing import List def find_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 find_primes(n: int) -> List[int]: """ Find all prime numbers from 1 to n inclusive using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit of the range to find prime nu...
python_sharegpt_23k
13,151
Write a Python function to increment a counter by 1 until it reaches 100, but exit the loop when the counter reaches a prime number. Implement a helper function to check if a number is prime and use this function within the loop. The function should return the prime number at which the loop exits. The code should star...
Here is the Python code to solve the given problem in the markdown block: ```python def find_prime_within_range() -> int: """ Increment a counter from 1 to 100 and return the first prime number encountered. Returns: int: The first prime number encountered within the range 1 to 100. """ def...
python_sharegpt_23k
13,154
Write a Python function to count the number of occurrences of a target element in a sorted array efficiently. The function should use a single loop and achieve a time complexity of O(log n), where n is the size of the array. The array will contain at most 10^9 elements, and the target element will be a positive integer...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(arr: List[int], target: int) -> int: """ Counts the number of occurrences of a target element in a sorted array. Args: arr (List[int]): The sorted array in which to sea...
python_sharegpt_23k
13,156
Write a Python function to calculate and return a list of the first `n` powers of a given base `b`, starting from `b^0`, without using the exponentiation operator or any built-in function that calculates powers. The function should start with: ```python from typing import List def calculate_powers(base: int, n: int) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_powers(base: int, n: int) -> List[int]: """ Calculate and return a list of the first `n` powers of a given base `b`, starting from `b^0`. Args: base (int): The base number whos...
python_sharegpt_23k
13,157
Write a Python function to remove all duplicates from an array of strings while preserving the order of the elements. Additionally, the resulting array should only contain strings that are palindromes. The code should start with: ```python from typing import List def remove_duplicates_palindromes(arr: List[str]) -> Li...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def remove_duplicates_palindromes(arr: List[str]) -> List[str]: """ Removes duplicates from an array of strings while preserving the order of the elements. Only strings that are palindromes are inc...
python_sharegpt_23k
13,158
Write a Python function to calculate the sum of each row in a given 2-dimensional array and return a new array containing these sums. The function should handle any n x m 2-dimensional array, where n is the number of rows and m is the number of columns. The code should start with: ```python from typing import List de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def row_sums(arr: List[List[int]]) -> List[int]: """ Calculate the sum of each row in a given 2-dimensional array and return a new array containing these sums. Args: arr (List[List[int]]): A...
python_sharegpt_23k
13,161
Write a Python function to determine if a given positive integer is a prime number. The function should have a time complexity of O(sqrt(n)), where n is the input number. The function should return `True` if the number is prime and `False` otherwise. The code should start with: ```python import math def is_prime(n: i...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(n: int) -> bool: """ Determines if a given positive integer is a prime number. Args: n (int): The positive integer to check for primality. Returns: bool: True if the number is ...
python_sharegpt_23k
13,164
Write a Python function to print the elements of a given list in reverse order. The function should take a list of integers as input and print each element in reverse order without using any built-in reverse functions or slicing. The code should start with: ```python from typing import List def print_reverse_list(num...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_reverse_list(numbers: List[int]) -> None: """ Prints the elements of the given list in reverse order. Args: numbers (List[int]): The list of integers to be printed in reverse order...
python_sharegpt_23k
13,172
Write a Python function to calculate the average of all elements in a given list of integers and floating-point numbers efficiently. The function must have a time complexity of O(n) and use only a constant amount of extra space. Additionally, the function must handle negative numbers and floating-point numbers in the l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_average(lst: List[float]) -> float: """ Calculate the average of all elements in a given list of integers and floating-point numbers. The function has a time complexity of O(n) and use...
python_sharegpt_23k
13,179
Write a Python function to determine the number of prime numbers in a given array of integers and calculate the sum of all prime numbers found in the array. The function should ignore negative integers and consider them as invalid input. The code should start with: ```python from typing import List, Tuple def count_an...
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 given number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, Fals...
python_sharegpt_23k
13,182
Write a Python function to convert an arbitrary number from any base between 2 and 16 to its decimal representation without using any built-in conversion functions or libraries. The function should handle numbers with up to 100 digits and manage negative numbers correctly. The code should start with: ```python def bas...
Here is the Python code to solve the given problem in the markdown block: ```python def base_to_decimal(number: str, base: int) -> int: """ Converts an arbitrary number from any base between 2 and 16 to its decimal representation. Args: number (str): The number to be converted, represented as a str...
python_sharegpt_23k
13,183
Write a Python function to check if a target number exists in a given array and return its index position if it does. If the target number exists multiple times in the array, return the index position of the first occurrence. If the target number does not exist in the array, return `False` and `-1`. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_target_index(nums: List[int], target: int) -> Tuple[bool, int]: """ Check if a target number exists in the given array and return its index position. If the target number exists multi...
python_sharegpt_23k
13,186
Write a Python function to convert a given string by performing two operations: converting all uppercase letters to lowercase and removing all vowels from the string. The function should return the modified string. The code should start with: ```python def convert_string(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def convert_string(text: str) -> str: """ Converts a given string by converting all uppercase letters to lowercase and removing all vowels. Args: text (str): The input string to be converted. Returns: s...
python_sharegpt_23k
13,190
Write a Python function to calculate the power of a number using only basic arithmetic operations (addition, subtraction, multiplication, and division). The function should handle negative values for both the base and the power, and return the result as a floating-point number. The code should not use any built-in expo...
Here is the Python code to solve the given problem in the markdown block: ```python def power(base: float, p: int) -> float: """ Calculate the power of a number using only basic arithmetic operations. Args: base (float): The base number. p (int): The power to which the base is to be raised....
python_sharegpt_23k
13,199
Write a Python function to determine if a given positive integer is both a prime number and a perfect square. The function should return `True` if the number meets both criteria, and `False` otherwise. The code should start with: ```python import math def is_prime_and_perfect_square(num: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime_and_perfect_square(num: int) -> bool: """ Determine if a given positive integer is both a prime number and a perfect square. Args: num (int): The positive integer to check. Returns: ...
python_sharegpt_23k
13,205
Implement a modified version of the quicksort algorithm to sort the given array in descending order. The array may contain duplicate elements. The algorithm should have a time complexity of O(n log n) and should not use any additional data structures or recursion. 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 def quicksort_descending(arr: List[int]) -> List[int]: """ Sorts the given array in descending order using a modified quicksort algorithm. Args: arr (List[int]): The array to be sorted. ...
python_sharegpt_23k
13,207
Write a Python function to generate two lists: one containing 10 random numbers within the range of 1 to 100 (inclusive), and the other containing 10 random prime numbers within the range of 100 to 1000 (inclusive). The function should return a tuple containing these two lists. The code should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import random 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 otherwis...
python_sharegpt_23k
13,208
Write a Python function that prints the string "Hello World" to the console a specified number of times using a nested loop. The function should take an integer `n` as input, which represents the number of times the string should be printed. The code should start with: ```python def print_hello_world_nested(n: int): ``...
Here is the Python code to solve the given problem in the markdown block: ```python def print_hello_world_nested(n: int): """ Prints the string "Hello World" to the console n times using a nested loop. Args: n (int): The number of times to print "Hello World". Returns: None """ ...
python_sharegpt_23k
13,210
Write a Python function to generate a matrix of size \( n \times n \) consisting of the natural numbers from 1 to \( n^2 \) in row-major order. The function should have a time complexity of \( O(n^2) \) and a space complexity of \( O(n^2) \). Additionally, the function should check for the following conditions and rais...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_matrix(n: int) -> List[List[int]]: """ Generate a matrix of size n x n filled with natural numbers from 1 to n^2 in row-major order. Args: n (int): The size of the matrix (n x n...
python_sharegpt_23k
13,226
Write a Python function to flatten a list of lists into a single list without using any built-in functions or methods that directly flatten a list. The solution should have a time complexity of O(n) and a space complexity of O(1), where n is the total number of elements in the input list. 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 flatten_list(lst: List[List[int]]) -> List[int]: """ Flattens a list of lists into a single list without using any built-in functions or methods that directly flatten a list. Args: lst (...
python_sharegpt_23k
13,229
Write a Python function to print all elements of a nested array in reverse order, with each element separated by a comma and a space. The function should not use any built-in functions or methods to reverse the array or join the elements together. The function should start with: ```python from typing import List def p...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_nested_array_reverse(arr: List[List[int]]) -> None: """ Prints all elements of a nested array in reverse order, with each element separated by a comma and a space. Args: arr (List[...
python_sharegpt_23k
13,231
Write a Python function to reverse a doubly linked list in O(n) time complexity without using any additional data structures or modifying the values of the nodes. The function should start with: ```python def reverse_doubly_linked_list(head): ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_doubly_linked_list(head): """ Reverses a doubly linked list in O(n) time complexity without using additional data structures or modifying node values. Args: head: The head node of the doubly linked list....
python_sharegpt_23k
13,233
Write a Python function that takes in an array of positive integers and returns a new array where the elements are reversed, but only for odd integers. If an even integer is encountered, it should remain in its original position. Additionally, the function should sort the resulting array in descending order. The functi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_odd_sort(arr: List[int]) -> List[int]: """ Reverses and sorts only the odd integers in the input array in descending order, while keeping even integers in their original positions. A...
python_sharegpt_23k
13,239
Write a Python function to determine if a given positive integer greater than 1 is a prime number. The function should also check if the input is within the range of 2 to 10^9, inclusive. Optimize the solution to have a time complexity of O(sqrt(n)) where n is the input number. The code should start with: ```python im...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime_number(n: int) -> bool: """ Determine if a given positive integer greater than 1 is a prime number. Args: n (int): The number to check for primality. Returns: bool: True if the...
python_sharegpt_23k
13,243
Write a Python function to extract and sort the unique even elements from a given list of integers. The function should return a new list containing only the even elements from the input list, arranged in ascending order, and should not contain any duplicates. If the input list does not contain any even elements, the f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_even_elements(A: List[int]) -> List[int]: """ Extracts and sorts the unique even elements from a given list of integers. Args: A (List[int]): The input list of integers from whic...
python_sharegpt_23k
13,252
Write a Python function to sort a list of integers in increasing order without using any built-in sorting functions or methods. The function should have a time complexity of O(n^2) and should not use any additional data structures. The input list can contain duplicate integers and may have a length up to 10000. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_list(lst: List[int]) -> List[int]: """ Sorts a list of integers in increasing order using the selection sort algorithm. Args: lst (List[int]): The list of integers to be sorted. ...
python_sharegpt_23k
13,253
Write a Python function to change the case of all alphabetic characters in a given string while leaving punctuation and other non-alphabetic characters unchanged. The input string may contain multiple sentences. The function should start with: ```python def change_case_of_alphabets(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def change_case_of_alphabets(input_string: str) -> str: """ Changes the case of all alphabetic characters in the input string while leaving punctuation and other non-alphabetic characters unchanged. Args: input_stri...
python_sharegpt_23k
13,262
Write a Python function to convert each word in a given string to uppercase and ensure that all words are separated by a single whitespace. The input string will only contain alphabetic characters and whitespace. The output string should not have any leading or trailing whitespaces. The code should start with: ```pyth...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_uppercase(input_string: str) -> str: """ Converts each word in the input string to uppercase and ensures that all words are separated by a single whitespace. Args: input_string (str): The input string...
python_sharegpt_23k
13,264
Write a Python function to determine if a given string contains any special characters. A special character is defined as any character that is not a letter (uppercase or lowercase) or a digit (0-9). The function should return `True` if the string contains at least one special character and `False` otherwise. The code...
Here is the Python code to solve the given problem in the markdown block: ```python def has_special_character(string: str) -> bool: """ Determines if the given string contains any special characters. A special character is defined as any character that is not a letter (uppercase or lowercase) or a digit (0...
python_sharegpt_23k
13,274
Write a Python function to calculate the base-2 logarithm of a given positive integer using only bitwise operations. The function should return the integer part of the logarithm, which is the number of times the number can be divided by 2 until it becomes 1. The code should start with: ```python def base_2_logarithm(n...
Here is the Python code to solve the given problem in the markdown block: ```python def base_2_logarithm(n: int) -> int: """ Calculate the base-2 logarithm of a positive integer using only bitwise operations. Args: n (int): The positive integer for which to calculate the base-2 logarithm. Retu...
python_sharegpt_23k
13,275
Write a Python function to check if a given string contains both alphabetic characters and numeric characters in a specific order, i.e., all alphabetic characters appear before any numeric characters. The function should return `True` if the string meets the criteria, and `False` otherwise. The function should handle s...
Here is the Python code to solve the given problem in the markdown block: ```python import re def contains_alphabets_before_numbers(s: str) -> bool: """ Check if the given string contains alphabetic characters followed by numeric characters. Args: s (str): The input string to be checked. Retu...