source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
evol_instruct_66k
13,861
Write a Python function to efficiently identify and retrieve all occurrences of a specific target element within a nested array that contains both numerical and string elements. The nested array can have an arbitrary depth of nesting. The function should return a list of all occurrences of the target element found in t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_elements_in_nested_array(nested_array: List[Union[int, str, List]], target: Union[int, str]) -> List[Union[int, str]]: """ Find all occurrences of a specific target element within a neste...
evol_instruct_66k
13,867
Write a Python function to filter out all prime numbers from a given list of distinct integers. The function should return a list containing only the prime numbers from the input list. The code should start with: ```python from typing import List def get_prime_numbers(num_list: List[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 get_prime_numbers(num_list: List[int]) -> List[int]: """ Filters out all prime numbers from a given list of distinct integers. Args: num_list (List[int]): A list of distinct ...
evol_instruct_66k
13,877
Write a Python function to create a DataFrame with three columns: 'Name', 'Age', and 'Country', and populate these columns with five specific data entries each. The function should return the created DataFrame. The code should start with: ```python import pandas as pd def create_dataframe() -> pd.DataFrame: ```
Here is the Python code to solve the given problem in the markdown block: ```python import pandas as pd def create_dataframe() -> pd.DataFrame: """ Creates a DataFrame with three columns: 'Name', 'Age', and 'Country', and populates these columns with five specific data entries each. Returns: pd.Da...
evol_instruct_66k
13,882
Write a Python function to count the number of distinct numerical values in a given list of numbers. The function should efficiently handle the task by leveraging a set data structure to ensure uniqueness. The code should start with: ```python from typing import List def count_distinct_numbers(numbers: List[int]) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_distinct_numbers(numbers: List[int]) -> int: """ Counts the number of distinct numerical values in a given list of numbers. Args: numbers (List[int]): A list of integers from which...
evol_instruct_66k
13,890
Implement a binary search algorithm to find the index of a given element in a sorted array without using any built-in binary search methods. If the array is not sorted, sort it first. Additionally, correct the provided erroneous code to ensure it works correctly. 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 binary_search(arr: List[int], x: int) -> int: """ Perform a binary search to find the index of the element `x` in the sorted array `arr`. If the array is not sorted, it will be sorted first. ...
evol_instruct_66k
13,904
Write a Python function to determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals. The function should handle edge cases such as intervals with similar start or end points. The code should start with: ```python from typing import List def min_non_overlapp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def min_non_overlapping_intervals(intervals: List[List[int]]) -> int: """ Determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals. Args...
evol_instruct_66k
13,910
Write a Python function to balance and sort a binary search tree (BST) using an in-order traversal approach. The function should take a list of integers as input, construct a BST from the list, balance the BST, and return the sorted list of elements obtained from an in-order traversal of the balanced BST. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List class TreeNode: def __init__(self, value): self.value = value self.left = None self.right = None def insert_into_bst(root: TreeNode, value: int) -> TreeNode: """ Inserts a va...
evol_instruct_66k
13,911
Write a Python function to count the occurrences of each character in a given string and return the result as a dictionary. The keys of the dictionary should be the characters from the string, and the values should be the number of times each character appears in the string. The function should handle any string, inclu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_character_occurrences(string: str) -> Dict[str, int]: """ Counts the occurrences of each character in the given string and returns a dictionary. Args: string (str): The input strin...
evol_instruct_66k
13,912
Write a Python function to compute the transpose of a given 2D array (matrix). The transpose of a matrix is obtained by swapping its rows with its columns. The function should handle matrices of any size, including non-square matrices. The code should start with: ```python from typing import List def transpose_matrix(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transpose_matrix(matrix: List[List[int]]) -> List[List[int]]: """ Compute the transpose of a given 2D array (matrix). Args: matrix (List[List[int]]): The input 2D array (matrix) to be tr...
evol_instruct_66k
13,919
Write a Python function to find the smallest number among three given whole numbers. The function should take three integers as input and return the smallest one. The code should start with: ```python def find_smallest_number(a: int, b: int, c: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_smallest_number(a: int, b: int, c: int) -> int: """ Find the smallest number among three given whole numbers. Args: a (int): The first whole number. b (int): The second whole number. c (int)...
evol_instruct_66k
13,939
Write a Python function to remove all elements from a given list that are divisible by a specified integer without any remainder. The function should return the modified list. The code should start with: ```python from typing import List def remove_divisible_by(numbers: List[int], divisor: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_divisible_by(numbers: List[int], divisor: int) -> List[int]: """ Removes all elements from the given list that are divisible by the specified divisor without any remainder. Args: ...
evol_instruct_66k
13,956
Write a Python function to remove extra white spaces from a list of sentences while maintaining the sequence of sentences and ignoring any special characters. The function should not use any built-in string manipulation functions. Instead, use data structures and programming logic. The function should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_extra_whitespace(sentences: List[str]) -> List[str]: """ Removes extra white spaces from a list of sentences while maintaining the sequence of sentences and ignoring special characters. A...
evol_instruct_66k
13,964
Write a Python function to subtract two bidimensional matrices. The function should handle matrices of the same dimensions and return the resulting matrix after subtraction. The code should start with: ```python from typing import List def subtract_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def subtract_matrices(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]: """ Subtracts two bidimensional matrices of the same dimensions. Args: matrix1 (List[List[int]])...
evol_instruct_66k
13,980
Write a Python function to determine if there exists any pair of adjacent integers in a given list that, when multiplied together, equal a specified target integer. The function should return `True` if such a pair exists, and `False` otherwise. The code should start with: ```python from typing import List def has_adja...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def has_adjacent_product(lst: List[int], target: int) -> bool: """ Determines if there exists any pair of adjacent integers in the list that, when multiplied together, equal the target integer. Args...
evol_instruct_66k
13,987
Write a Python function to perform a binary search on a given sorted array to find the index of a specified value. If the value is not found, return -1. The function should be efficient and leverage the sorted nature of the array. The code should start with: ```python from typing import List def binary_search(sorted_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(sorted_array: List[int], value: int) -> int: """ Perform a binary search on a sorted array to find the index of a specified value. Args: sorted_array (List[int]): The sorte...
evol_instruct_66k
14,001
Write a Python function to construct a nested dictionary from a list of tuples, where each tuple represents a primary key and a secondary key. The function should ensure that each primary key maps to a dictionary containing its corresponding secondary keys. The secondary keys should map to a placeholder value, which is...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def construct_nested_dict(keys: List[Tuple[str, str]]) -> Dict[str, Dict[str, str]]: """ Constructs a nested dictionary from a list of tuples, where each tuple contains a primary key and a s...
evol_instruct_66k
14,018
Write a Python function to generate a Fibonacci sequence up to `n` elements. The function should return a list containing the first `n` elements of the Fibonacci sequence. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two numbers. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci(n: int) -> List[int]: """ Generate a Fibonacci sequence up to n elements. Args: n (int): The number of elements in the Fibonacci sequence to generate. Returns: ...
evol_instruct_66k
14,040
Write a Python function to compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm. The function should handle both positive and negative integers. The code should start with: ```python def gcd(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def gcd(a: int, b: int) -> int: """ Compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm. Args: a (int): The first integer. b (int): The second integer. Returns: ...
evol_instruct_66k
14,041
Write a Python function to calculate the average score for each person in a given list of tuples. Each tuple contains a person's unique identifier followed by their scores in three distinct disciplines. The function should return a dictionary where the key is the person's unique identifier and the value is the average ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def average_score(scores: List[Tuple[str, int, int, int]]) -> Dict[str, float]: """ Calculate the average score for each person in a list of tuples. Args: scores (List[Tuple[str...
evol_instruct_66k
14,066
Write a Python function to swap all instances of a specified character with another specified character in a given string. The function should handle any string and any two characters. The code should start with: ```python def swap_characters(text: str, char1: str, char2: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_characters(text: str, char1: str, char2: str) -> str: """ Swaps all instances of one character with another in the given string. Args: text (str): The input string in which characters need to be swapped. ...
evol_instruct_66k
14,067
Write a Python function to implement the insertion sort algorithm to arrange a list of negative floating point numbers in descending order. The function should take a list of negative floating point numbers as input and return the sorted list in descending order. 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 insertion_sort_descending(lst: List[float]) -> List[float]: """ Sorts a list of negative floating point numbers in descending order using the insertion sort algorithm. Args: lst (List[fl...
evol_instruct_66k
14,077
Write a Python function to determine whether a given number is in the Fibonacci series. The function should be efficient and work correctly even for large numbers. Additionally, write a function to generate the first `n` numbers in the Fibonacci series. The starter code should be: ```python import math from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python import math from typing import List def generate_fibonacci_series(n: int) -> List[int]: """ Generate the first n numbers in the Fibonacci series. Args: n (int): The number of Fibonacci numbers to generate. Ret...
evol_instruct_66k
14,090
Write a Python function to transform a given sentence into a positive affirmation. The function should handle sentences with multiple words and punctuation, and it should maintain the original capitalization and punctuation of the subject. The code should start with: ```python def transmogrify_affirmation(sentence: str...
Here is the Python code to solve the given problem in the markdown block: ```python def transmogrify_affirmation(sentence: str) -> str: """ Transforms a given sentence into a positive affirmation, maintaining the original capitalization of the subject. Args: sentence (str): The input sentence to be...
evol_instruct_66k
14,108
Write a Python function to display the values in a given tuple in reverse order. The function should take a tuple as input and print each element of the tuple in reverse order, one element per line. The code should start with: ```python def display_tuple_reverse(t: tuple): ```
Here is the Python code to solve the given problem in the markdown block: ```python def display_tuple_reverse(t: tuple): """ Displays the values in a given tuple in reverse order, one element per line. Args: t (tuple): The tuple whose elements are to be displayed in reverse order. Returns: ...
evol_instruct_66k
14,114
Write a Python function to generate a list of integers from 0 to 100 that are multiples of 4, but exclude any multiple that is also a factor of 50. The function should be implemented using both a traditional for loop with conditional statements and a more succinct list comprehension. 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 def generate_multiples_with_loop() -> List[int]: """ Generate a list of integers from 0 to 100 that are multiples of 4, excluding any multiple that is also a factor of 50. Returns: List[int]...
evol_instruct_66k
14,118
Write a Python function to find the absolute positions (counting from zero) of every instance of a specified character in a given string. Additionally, the function should count the total frequency of the specified character appearing in the string. The function should be implemented without using any built-in search f...
Here is the Python code to solve the given problem in the markdown block: ```python def find_character_positions(s: str, ch: str) -> tuple: """ Finds the absolute positions (counting from zero) of every instance of a specified character in a string. Additionally, counts the total frequency of the specified ...
evol_instruct_66k
14,124
Write a Python function to determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals, and return the optimal set of intervals. The function should handle cases where intervals overlap but do not completely cover each other, and should be able to identify mult...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def minimum_intervals(intervals: List[List[int]]) -> List[List[int]]: """ Determine the minimum number of non-overlapping intervals needed to cover the entire range of a given set of intervals. Args...
evol_instruct_66k
14,126
Write a Python function to check if two given strings consist only of ASCII printable characters and if one string is a permutation of the other. The function should return a message indicating whether the strings are permutations of each other or if there is an issue with the input strings. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python import string def check_strings(s1: str, s2: str) -> str: """ Check if two strings consist only of ASCII printable characters and if one string is a permutation of the other. Args: s1 (str): The first string to che...
evol_instruct_66k
14,145
Write a Python function to generate all possible subsets of a given set. The set is represented as a list of unique elements. The function should return a list of lists, where each inner list represents a subset. The order of subsets and the order of elements within each subset does not matter. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from itertools import chain, combinations def generate_subsets(input_set: List[int]) -> List[List[int]]: """ Generate all possible subsets of a given set. Args: input_set (List[int]): The se...
evol_instruct_66k
14,160
Write a Python function to convert a JSON object to a Python dictionary and check if it contains a certain key. If the key is not present, insert a new key-value pair into the dictionary. The function should start with: ```python from typing import Dict, Any, Optional def json_to_dict_with_key_check(json_obj: Dict[str...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any, Optional def json_to_dict_with_key_check(json_obj: Dict[str, Any], key: str, default_value: Optional[Any] = None) -> Dict[str, Any]: """ Converts a JSON object to a Python dictionary and checks if ...
evol_instruct_66k
14,170
Write a Python function to find the shortest string among three given strings after removing all vowels (both uppercase and lowercase) from each string. The function should return the shortest string that remains after the removal of vowels. The code should start with: ```python def get_shortest_string_without_vowels(...
Here is the Python code to solve the given problem in the markdown block: ```python def get_shortest_string_without_vowels(s1: str, s2: str, s3: str) -> str: """ Returns the shortest string among three given strings after removing all vowels. Args: s1 (str): The first string. s2 (str): The ...
evol_instruct_66k
14,176
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
evol_instruct_66k
14,203
Write a Python function to simulate a simplified version of the data processing pipeline for Reddit posts. The function should take a list of Reddit posts (represented as dictionaries) and perform the following steps: 1. **Data Normalization**: Clean the posts by removing special characters, stop words, converting text...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple import re from collections import Counter def process_reddit_posts(posts: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], List[str]]: """ Simulate a simplified data processing pipeline ...
evol_instruct_66k
14,204
Write a Python function to enhance a given textual content by enclosing it within an appropriate HTML tag. The function should allow the user to specify the HTML tag to be used. The function should handle cases where the tag is not provided or is an empty string by defaulting to the `<p>` tag. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python def enhance_text(text: str, tag: str = 'p') -> str: """ Enhances the given textual content by enclosing it within the specified HTML tag. Args: text (str): The textual content to be enhanced. tag (str, optio...
evol_instruct_66k
14,227
Write a Python function to find the Greatest Common Divisor (GCD) of two numbers using the Euclidean algorithm. The function should be efficient and handle both positive and negative integers. The code should start with: ```python def gcd(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def gcd(a: int, b: int) -> int: """ Calculate the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. Args: a (int): The first integer. b (int): The second integer. Returns: ...
evol_instruct_66k
14,234
Write a Python function to convert a hexadecimal number to its binary representation. The function should first convert the hexadecimal number to a decimal number and then convert the decimal number to its binary representation. The function should handle hexadecimal numbers represented as strings and return the binary...
Here is the Python code to solve the given problem in the markdown block: ```python def hex_to_binary(hex_num: str) -> str: """ Converts a hexadecimal number to its binary representation. Args: hex_num (str): The hexadecimal number to be converted, represented as a string. Returns: str...
evol_instruct_66k
14,235
Write a Python function to generate a list of prime numbers up to a given limit using the Sieve of Eratosthenes algorithm. The function should return a list of all prime numbers less than or equal to the given limit. The code should start with: ```python from typing import List def generate_primes(limit: int) -> List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(limit: int) -> List[int]: """ Generate a list of prime numbers up to a given limit using the Sieve of Eratosthenes algorithm. Args: limit (int): The upper limit for gener...
evol_instruct_66k
14,237
Write a Python function to select specific columns from a given hierarchical list (a list of lists) based on a list of column indices. The function should return a new list of lists containing only the specified columns. The code should start with: ```python from typing import List def select_columns(data: List[List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def select_columns(data: List[List[str]], indices: List[int]) -> List[List[str]]: """ Selects specific columns from a hierarchical list (list of lists) based on a list of column indices. Args: ...
evol_instruct_66k
14,240
Write a Python function to check if the characters in the first string appear in the same order as in the second string, including any punctuation and spaces. The function should be case-sensitive, meaning 'H' will not be considered the same as 'h'. The code should start with: ```python def check_order(str1: str, str2...
Here is the Python code to solve the given problem in the markdown block: ```python def check_order(str1: str, str2: str) -> bool: """ Checks if the characters in the first string appear in the same order as in the second string, including any punctuation and spaces. The function is case-sensitive. Arg...
evol_instruct_66k
14,243
Write a Python function to determine if a given substring exists within a specified string. The function should return `True` if the substring is found, and `False` otherwise. The code should start with: ```python def substring_exists(string: str, substring: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def substring_exists(string: str, substring: str) -> bool: """ Determines if a given substring exists within a specified string. Args: string (str): The string in which to search for the substring. substring...
evol_instruct_66k
14,245
Write a Python function to recursively extract and return all the keys from a given JSON object. The JSON object can be nested, meaning it can contain other JSON objects as values. The function should handle any level of nesting and return a list of all keys found in the JSON object. 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, Any def extract_keys_from_json(json_obj: Any) -> List[str]: """ Recursively extracts all keys from a given JSON object. Args: json_obj (Any): The JSON object (represented as a dictionary) f...
evol_instruct_66k
14,246
Write a Python function to compute the summation of distinct numeric magnitudes, multiplied by the aggregate of their respective signs, from a given array of non-zero integers. The function should return `None` if the array is empty or contains only zero elements. 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, Optional def numeric_signs(array: List[int]) -> Optional[int]: """ Compute the summation of distinct numeric magnitudes, multiplied by the aggregate of their respective signs, from a given array of ...
evol_instruct_66k
14,250
Write a Python function to retrieve the nth item from the end of a given tuple. The function should handle cases where n is greater than the length of the tuple or less than 1 by returning `None`. The code should start with: ```python from typing import Tuple, Any def get_nth_from_end(tup: Tuple[Any], n: int) -> Any: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Any def get_nth_from_end(tup: Tuple[Any], n: int) -> Any: """ Retrieve the nth item from the end of a given tuple. Args: tup (Tuple[Any]): The tuple from which to retrieve the item. ...
evol_instruct_66k
14,253
Write a Python function to filter a list of novels based on their ratings. The function should return a list of novels that have a rating greater than or equal to a specified threshold. The function should start with: ```python from typing import List, Dict def filter_novels_by_rating(novels: List[Dict[str, any]], thr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_novels_by_rating(novels: List[Dict[str, any]], threshold: float) -> List[Dict[str, any]]: """ Filters a list of novels based on their ratings. Args: novels (List[Dict[str, a...
evol_instruct_66k
14,277
Write a Python function to flatten a two-dimensional matrix of integers and sort the resulting list in ascending order. The matrix can have dimensions up to 1000x1000. The function should handle matrices of any size, including empty matrices. The code should start with: ```python from typing import List def flatten_a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_and_sort_matrix(matrix: List[List[int]]) -> List[int]: """ Flattens a two-dimensional matrix of integers and sorts the resulting list in ascending order. Args: matrix (List[List[...
evol_instruct_66k
14,280
Write a Python function to generate a special Fibonacci-like sequence with alternating 0s and 1s. The function should take two parameters: the number of elements in the sequence to generate (`n`), and an initial starting number (`start`) that can either be 0 or 1. The sequence should alternate between 0 and 1, starting...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_fib_like_sequence(n: int, start: int) -> list: """ Generates a special Fibonacci-like sequence with alternating 0s and 1s. Args: n (int): The number of elements in the sequence to generate. star...
evol_instruct_66k
14,281
Write a Python function to recursively process a dictionary, ensuring that the keys are sorted, checking for duplicate keys, and identifying value imbalances. The function should handle nested dictionaries and perform these operations recursively. The code should start with: ```python from typing import Dict, Any def ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Any def process_dictionary(data: Dict[str, Any]) -> Dict[str, Any]: """ Recursively processes a dictionary to sort keys, check for duplicate keys, and identify value imbalances. Args: data ...
evol_instruct_66k
14,289
Write a Python function to group an array of numbers based on given conditions and count the number of elements in each group. The conditions are defined as lambda functions that check if a number falls within a specific range. The function should return two lists: one containing the grouped numbers and the other conta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def group_and_count(arr: List[int], conditions: List[Callable[[int], bool]]) -> (List[List[int]], List[int]): """ Groups an array of numbers based on given conditions and counts the number of e...
evol_instruct_66k
14,292
Write a Python function to compute and return the first `n` terms of the Catalan sequence. The Catalan sequence is a number series where each term is determined by the formula: \[ C(n) = \frac{(2n)!}{(n+1)!n!} \] However, for efficiency, we can use the recursive relation: \[ C(n) = \sum_{i=0}^{n-1} C(i) \cdot C(n-1-i) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def catalan_sequence(n: int) -> List[int]: """ Compute and return the first n terms of the Catalan sequence. The Catalan sequence is a number series where each term is determined by the sum of produ...
evol_instruct_66k
14,293
Write a Python function to iterate through a given list and apply a specified function to each element. The function should return a new list containing the results of applying the specified function to each element of the original list. The code should start with: ```python from typing import List, Callable def appl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def apply_function_to_list(array: List[int], func: Callable[[int], int]) -> List[int]: """ Applies a specified function to each element of a given list and returns a new list with the results. ...
evol_instruct_66k
14,302
Write a Python function to generate a random string of length `n` consisting of only lowercase English alphabetic characters. The function should ensure that each character in the string is chosen randomly from the set of lowercase English alphabetic characters. The code should start with: ```python import random impor...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_random_string(n: int) -> str: """ Generates a random string of length n consisting of only lowercase English alphabetic characters. Args: n (int): The length of the random s...
evol_instruct_66k
14,305
Write a Python function to implement the selection sort algorithm, which sorts a list of integers in ascending order. The function should modify the input list in place and return the sorted list. The code should start with: ```python from typing import List def selection_sort(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def selection_sort(lst: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the selection sort algorithm. Args: lst (List[int]): The list of integers to be sorte...
evol_instruct_66k
14,311
Write a Python function to increment a non-negative integer represented by a list of its decimal digits by one. The function should handle the carry-over when a digit is 9 and becomes 0 after incrementing. If the most significant digit (the head of the list) is 9 and becomes 0 after incrementing, an additional 1 should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def increment_integer(digits: List[int]) -> List[int]: """ Increment a non-negative integer represented by a list of its decimal digits by one. Args: digits (List[int]): A list of integers w...
evol_instruct_66k
14,312
Write a Python function to determine the frequency of characters in a given string, including spaces and punctuation. The function should return a dictionary where the keys are characters and the values are their respective frequencies. The code should start with: ```python from typing import Dict def character_freque...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def character_frequency(input_string: str) -> Dict[str, int]: """ Calculate the frequency of each character in the given string. Args: input_string (str): The input string for which characte...
evol_instruct_66k
14,319
Write a Python function to transform a tuple of string elements into a nested dictionary. Each string in the tuple is formatted as "key1.key2.key3: value1, value2", where keys are separated by dots and values are separated by commas. The function should parse these strings and construct a nested dictionary where each k...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple, Dict, Any def transform_tuple_to_dict(tup: Tuple[str, ...]) -> Dict[str, Any]: """ Transforms a tuple of strings into a nested dictionary. Each string in the tuple is formatted as "key1.key2.key3:...
evol_instruct_66k
14,323
Write a Python function to manage a contact list. The function should be able to add, edit, and delete contacts. Each contact is represented as a dictionary with keys `id`, `name`, and `email`. The function should handle the following operations: 1. **Add a contact**: Add a new contact to the list. 2. **Edit a contact*...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def manage_contacts(contacts: List[Dict[str, str]], operation: str, contact: Dict[str, str]) -> List[Dict[str, str]]: """ Manages a list of contacts by performing add, edit, or delete operations. ...
evol_instruct_66k
14,325
Write a Python function to convert a given binary string to its hexadecimal representation. The function should follow a multi-stage translation process: first, convert the binary string to its decimal representation, and then convert the decimal representation to its hexadecimal format. The function should return the ...
Here is the Python code to solve the given problem in the markdown block: ```python def binary_to_hex(binary_string: str) -> str: """ Converts a given binary string to its hexadecimal representation. Args: binary_string (str): The binary string to be converted. Returns: str: The hexade...
evol_instruct_66k
14,332
Write a Python function to calculate the product of a sequence of numbers generated by a while loop. The function should incorporate the given code segment into the second iteration of the loop. The loop should iterate a specified number of times, and the product should be updated only during the second iteration. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_product(iterations: int, multiplier: int) -> int: """ Calculate the product of a sequence of numbers generated by a while loop. The product is updated only during the second iteration of the loop. Args: ...
evol_instruct_66k
14,337
Write a Python function to generate and print all Fibonacci numbers within a given range, along with their corresponding sequence indices. The function should start with: ```python def print_fibonacci_in_range(start: int, end: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_fibonacci_in_range(start: int, end: int) -> None: """ Generates and prints all Fibonacci numbers within the given range [start, end], along with their corresponding sequence indices. Args: start (int):...
evol_instruct_66k
14,347
Write a Python function to calculate the comprehensive interval between two specific timestamps in days, hours, minutes, and seconds. The timestamps are given in the format "MM/DD/YYYY HH:MM:SS". The function should return a dictionary with keys 'days', 'hours', 'minutes', and 'seconds' representing the interval betwee...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime from typing import Dict def calculate_interval(date1: str, date2: str) -> Dict[str, int]: """ Calculate the comprehensive interval between two specific timestamps in days, hours, minutes, and secon...
evol_instruct_66k
14,358
Write a Python function to perform a ternary search on a sorted array to find the index of a given element. The ternary search algorithm should divide the array into three parts and recursively search for the element. If the element is not found, the function should return -1. The code should start with: ```python fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def ternary_search(arr: List[int], l: int, r: int, x: int) -> int: """ Perform a ternary search on a sorted array to find the index of a given element. Args: arr (List[int]): The sorted arra...
evol_instruct_66k
14,368
Write a Python function to merge two integer lists without any duplicates, following the order of elements subsequent to their frequency from the first list to the second. Maintain a time complexity of O(n log n). The function should start with: ```python from typing import List def merge_lists(list1: List[int], list2...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def merge_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merges two lists of integers without duplicates, following the order of elements subsequent to their ...
evol_instruct_66k
14,373
Write a Python function to simulate a simple interactive shell script that greets the user, asks for their name, and then performs a series of operations based on user input. The script should include error handling for invalid inputs and control structures to manage different user choices. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python def interactive_shell(): """ Simulates an interactive shell script that greets the user, asks for their name, and then provides a menu of options to choose from. The script handles invalid inputs and allows the user to c...
evol_instruct_66k
14,375
Write a Python function to generate a list of composed strings by integrating information from multiple lists and conditionally formatting the strings based on specified criteria. The function should skip certain combinations as specified. The code should start with: ```python from typing import List def generate_com...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_composed_strings(names: List[str], blanks: List[str]) -> List[str]: """ Generates a list of composed strings by integrating information from multiple lists and conditionally formatting the s...
evol_instruct_66k
14,376
Write a Python function to condense an input string by determining and tracking the numerical count of each unique character appearing within it. The function should return a new string where each unique character is followed by its count in the original string. The code should start with: ```python def condense_string...
Here is the Python code to solve the given problem in the markdown block: ```python def condense_string(s: str) -> str: """ Condenses the input string by counting the occurrences of each unique character. Args: s (str): The input string to be condensed. Returns: str: A new string where...
evol_instruct_66k
14,390
Write a Python function to sort a substantial, unordered array of integer data types using the QuickSort algorithm. The function should be efficient and handle large datasets. The code should start with: ```python from typing import List def quicksort(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 quicksort(arr: List[int]) -> List[int]: """ Sorts a substantial, unordered array of integer data types using the QuickSort algorithm. Args: arr (List[int]): The array of integers to be s...
evol_instruct_66k
14,391
Write a Python function to determine if there exists at least one word in a given list where the vowel 'e' is located precisely in the second character position (index 1) of the word. The function should return `True` if such a word exists, otherwise `False`. The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def has_vowel_in_second_position(words: List[str]) -> bool: """ Determines if there exists at least one word in the given list where the vowel 'e' is located in the second character position. Args: ...
evol_instruct_66k
14,408
Write a Python function to find and return the five smallest unique numbers from a given array. The function should handle arrays with negative numbers and ignore repeated numbers. The code should start with: ```python from typing import List def get_five_smallest_unique_numbers(array: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_five_smallest_unique_numbers(array: List[int]) -> List[int]: """ Returns the five smallest unique numbers from the given array. Args: array (List[int]): The array from which to extra...
evol_instruct_66k
14,437
Write a Python function to sort a given list of numbers in ascending order using the merge sort algorithm. The merge sort algorithm is a divide-and-conquer algorithm that recursively divides the list into halves until each sublist contains a single element, then merges these sublists back together in sorted order. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(input_list: List[int]) -> List[int]: """ Sorts a list of integers using the merge sort algorithm. Args: input_list (List[int]): The list of integers to be sorted. Returns...
evol_instruct_66k
14,440
Write a Python function to find the minimum value among five distinct numerical elements. The function should accept exactly five arguments and return the smallest number among them. The code should start with: ```python def find_minimum(num1: int, num2: int, num3: int, num4: int, num5: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def find_minimum(num1: int, num2: int, num3: int, num4: int, num5: int) -> int: """ Find the minimum value among five distinct numerical elements. Args: num1 (int): The first numerical element. num2 (int):...
evol_instruct_66k
14,441
Write a Python function to generate all unique pairs of elements from a given list of integers efficiently. The function should avoid using nested loops and instead use a more efficient approach to reduce time complexity and memory usage. The code should start with: ```python from typing import List, Tuple def genera...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from itertools import combinations def generate_unique_pairs(num_list: List[int]) -> List[Tuple[int, int]]: """ Generate all unique pairs of elements from the given list of integers. Args: ...
evol_instruct_66k
14,445
Write a Python function to check if two provided arrays have the same elements in reverse order. The function should return `True` if the elements of the second array are the same as the elements of the first array but in reverse order, and `False` otherwise. 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 def are_arrays_reverse(arr1: List[int], arr2: List[int]) -> bool: """ Check if the elements of the second array are the same as the elements of the first array but in reverse order. Args: ar...
evol_instruct_66k
14,447
Write a Python function to construct a novel array that consists of elements in the reverse order from a given original array. The function should take a list of integers as input and return a new list with the elements in reverse order. The code should start with: ```python from typing import List def reverse_array(a...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def reverse_array(arr: List[int]) -> List[int]: """ Constructs a novel array that consists of elements in the reverse order from the given original array. Args: arr (List[int]): The origin...
evol_instruct_66k
14,448
Write a Python function to extract elements from a given numerical array where the position (1-based index) of each element is greater than or equal to a specified integer threshold. The function should return a new list containing only the elements that meet this condition. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_elements_above_threshold(arr: List[int], threshold: int) -> List[int]: """ Extracts elements from a numerical array where the position (1-based index) of each element is greater than or e...
evol_instruct_66k
14,453
Write a Python function to convert an integer to its English name. The function should handle integers from 0 to 999,999,999,999 (one trillion minus one). The function should return the English name of the integer as a string. The code should start with: ```python def int_to_english(n: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def int_to_english(n: int) -> str: """ Convert an integer to its English name. Args: n (int): The integer to convert, must be between 0 and 999,999,999,999 (inclusive). Returns: str: The English name of...
evol_instruct_66k
14,456
Write a Python function to flatten a given bi-dimensional list (a list of lists) into a single-dimensional list. The function should take a bi-dimensional list as input and return a single-dimensional list containing all the elements from the input list in the same order. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_bi_dimensional_list(bi_dimensional_list: List[List[any]]) -> List[any]: """ Flattens a bi-dimensional list (a list of lists) into a single-dimensional list. Args: bi_dimensional_...
evol_instruct_66k
14,473
Write a Python function to count the frequency of each character in a given string, including both alphabetic characters and digits. The function should return a dictionary where the keys are the characters and the values are their respective counts. The function should handle both uppercase and lowercase characters as...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import defaultdict def count_character_frequencies(s: str) -> dict: """ Counts the frequency of each alphanumeric character in the given string, ignoring case and non-alphanumeric characters. Args: ...
evol_instruct_66k
14,491
Write a Python function to find the smallest negative integer in a given list of negative integers. The function should handle lists of varying lengths and ensure that all elements are indeed negative integers. If the list is empty or contains non-negative integers, the function should return `None`. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_smallest_negative_number(numbers: List[int]) -> Optional[int]: """ Find the smallest negative integer in a given list of negative integers. Args: numbers (List[int]): A li...
evol_instruct_66k
14,496
Write a Python function to translate a given character string into a corresponding sequence of byte values. Each character in the string should be converted to its ASCII value using the `ord()` function. The function should return a list of these ASCII values. The code should start with: ```python from typing import L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_to_bytes(input_string: str) -> List[int]: """ Converts a given character string into a corresponding sequence of byte values. Args: input_string (str): The input string to be conv...
evol_instruct_66k
14,510
Write a Python function to implement an adaptive quicksort algorithm that dynamically selects the pivot based on the incoming data to optimize performance. The function should sort a list of integers in ascending order. The code should start with: ```python from typing import List def adaptive_quicksort(arr: List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def adaptive_quicksort(arr: List[int]) -> List[int]: """ Sorts a list of integers using an adaptive quicksort algorithm. Args: arr (List[int]): The list of integers to be sorted. Return...
evol_instruct_66k
14,552
Write a Python function to perform a Caesar cipher encryption on a given string, handling both uppercase and lowercase letters, and preserving non-alphabetic characters. The function should also be able to handle negative shifts, which would decrypt the string if the original shift is known. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(str_to_encrypt: str, shift: int) -> str: """ Encrypts the given string using a Caesar cipher with the specified shift. Args: str_to_encrypt (str): The string to be encrypted. shift (int): T...
evol_instruct_66k
14,559
Write a Python function to reverse the order of keys in a given dictionary and replace the dictionary values with their corresponding ASCII values. The dictionary will contain alphabets as keys and numbers as their corresponding values. The function should start with: ```python from typing import Dict def reverse_and_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def reverse_and_ascii_values(dictionary: Dict[str, int]) -> Dict[str, int]: """ Reverses the order of keys in the given dictionary and replaces the values with their corresponding ASCII values. Args...
evol_instruct_66k
14,561
Write a Python function to generate the next element in a Fibonacci series given two previous elements. Additionally, write a function to generate the first `n` elements of the Fibonacci series. Ensure that the functions handle potential overflow issues by using appropriate data types. The code should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def next_fib(n1: int, n2: int) -> int: """ Generate the next element in the Fibonacci series given two previous elements. Args: n1 (int): The first previous element. n2 (int): The se...
evol_instruct_66k
14,577
Write a Python function to identify the discrete numerical component within a given array that appears the least frequently. If there are multiple numbers with the same least frequency, return the smallest number among them. The code should start with: ```python from typing import List def least_frequent_number(array...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def least_frequent_number(array: List[int]) -> int: """ Identify the discrete numerical component within the provided array which manifests itself the least frequently. If there are multiple numbers ...
evol_instruct_66k
14,619
Write a Python function to calculate the result of raising a given number to the power of another number. The function should take two parameters: the base and the exponent. The function should return the result of the base raised to the power of the exponent. The code should start with: ```python def power(base: floa...
Here is the Python code to solve the given problem in the markdown block: ```python def power(base: float, exponent: float) -> float: """ Calculate the result of raising a given base to the power of a given exponent. Args: base (float): The base number. exponent (float): The exponent number...
evol_instruct_66k
14,620
Write a Python function to determine if a given matrix is a Toeplitz matrix. A matrix is considered Toeplitz if every diagonal from top-left to bottom-right consists of identical elements. The function should return `True` if the matrix is Toeplitz, and `False` otherwise. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_toeplitz_matrix(matrix: List[List[int]]) -> bool: """ Determines if a given matrix is a Toeplitz matrix. A matrix is Toeplitz if every diagonal from top-left to bottom-right consists of ident...
evol_instruct_66k
14,628
Write a Python function to find the last position of a target element in a sorted array that may contain duplicate elements. The function should not use any built-in methods for searching or sorting. The code should start with: ```python def find_last_position(nums: list, target: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def find_last_position(nums: list, target: int) -> int: """ Find the last position of a target element in a sorted array with possible duplicates. Args: nums (list): A sorted list of integers. target (int)...
evol_instruct_66k
14,639
Write a Python function to calculate the perimeter of a triangle given the lengths of its three sides. The function should ensure that the given side lengths can form a valid triangle according to the triangle inequality theorem. If the side lengths do not form a valid triangle, the function should return `None`. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_triangle_perimeter(a: float, b: float, c: float) -> float: """ Calculate the perimeter of a triangle given the lengths of its three sides. Args: a (float): The length of the first side. b (floa...
evol_instruct_66k
14,640
Write a Python function to safely access an element at a specified index in a given string. If the index is out of bounds, return a default value instead of raising an error. The function should handle both positive and negative indices. The code should start with: ```python def safe_access(s: str, index: int, default...
Here is the Python code to solve the given problem in the markdown block: ```python def safe_access(s: str, index: int, default: str = '') -> str: """ Safely access an element at a specified index in a given string. If the index is out of bounds, return a default value. Args: s (str): The input...
evol_instruct_66k
14,645
Write a Python function to process a 2D array of size N (where N <= 10) and return a list of unique numbers sorted in descending order. The function should handle any 2D array of integers and ensure that the output list contains only unique elements arranged from the largest to the smallest. 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 process_2d_array(arr: List[List[int]]) -> List[int]: """ Processes a 2D array of integers and returns a list of unique numbers sorted in descending order. Args: arr (List[List[int]]): A ...
evol_instruct_66k
14,646
Write a Python function to access the last element of a deque and return it. The function should handle cases where the deque is empty by returning `None`. The code should start with: ```python from collections import deque from typing import Optional def get_last_element(d: deque) -> Optional[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque from typing import Optional def get_last_element(d: deque) -> Optional[int]: """ Access the last element of a deque and return it. If the deque is empty, return None. Args: d (deque): ...
evol_instruct_66k
14,659
Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with: ```python from typing import List def unique_paths(m: int, n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def unique_paths(m: int, n: int) -> int: """ Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid. Args: m (int): The number of row...
evol_instruct_66k
14,684
Write a Python function to count the number of vowels in a given string. The function should be case-insensitive, meaning both uppercase and lowercase vowels should be counted. The code should start with: ```python def count_vowels(text: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels(text: str) -> int: """ Count the number of vowels in a given string. Args: text (str): The input string in which to count the vowels. Returns: int: The number of vowels in the input str...
evol_instruct_66k
14,693
Write a Python function to sequentially index all the values contained within a list-based data structure and return a list of tuples where each tuple contains the index and the corresponding value from the original list. The code should start with: ```python from typing import List, Tuple def index_list_values(arr: L...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Tuple def index_list_values(arr: List[int]) -> List[Tuple[int, int]]: """ Sequentially index all the values contained within a list-based data structure. Args: arr (List[int]): The list o...
evol_instruct_66k
14,700
Write a Python function to generate a series of non-repeating random numbers within a specified range. The function should ensure that each number appears only once. The function should handle cases where the requested count exceeds the available numbers in the range by raising a `ValueError`. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_random_numbers(range_start: int, range_end: int, count: int) -> List[int]: """ Generates a list of non-repeating random numbers within a specified range. Args: ...
evol_instruct_66k
14,705
Write a Python function to reverse a given input string without using slicing or built-in reverse functions. The function should iterate through the string and build the reversed string character by character. 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 given input string without using slicing or built-in reverse functions. Args: input_string (str): The string to be reversed. Returns: str: ...
evol_instruct_66k
14,708
Write a Python function to find all documents in a list of dictionaries where the 'title' property contains a specified sequence of strings. The function should return a list of dictionaries that match the criteria. The code should start with: ```python from typing import List, Dict def find_documents_with_sequence(do...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Dict def find_documents_with_sequence(documents: List[Dict], sequence: str) -> List[Dict]: """ Find all documents where the 'title' property contains a specified sequence of strings. Args: ...
evol_instruct_66k
14,710
Write a Python function to generate the Fibonacci sequence up to the Nth term efficiently using memoization. The function should return the Nth term of the Fibonacci sequence. The code should start with: ```python from typing import List def fibonacci_memoized(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def fibonacci_memoized(n: int) -> int: """ Generate the Nth term of the Fibonacci sequence using memoization for efficiency. Args: n (int): The term in the Fibonacci sequence to generate. ...
evol_instruct_66k
14,723
Write a Python function to convert a day of the year (1-366) into its corresponding date in the format `DD-MMM-YYYY`, accounting for leap years. The input includes the year (1900-2100). The function should handle leap years correctly and return the date in the specified format. 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 Tuple import datetime def day_to_date(year: int, day: int) -> str: """ Converts a day of the year (1-366) into its corresponding date in the format DD-MMM-YYYY, accounting for leap years. Args: y...
evol_instruct_66k
14,753
Write a Python function to find the minimum element and its indices in a given array. If there are multiple occurrences of the minimum element, the function should return all indices where the minimum element is found. The function should also handle the case where the array is empty by returning `None` for the minimum...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def find_min_element_and_indices(arr: List[int]) -> Tuple[Optional[int], List[int]]: """ Find the minimum element and its indices in a given array. Args: arr (List[int]): Th...