source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
25,718
Write a Python function to filter a list of dictionaries based on a specific value in a column and whether the value starts with a specific substring. The function should return a list of dictionaries that match the criteria. The code should start with: ```python from typing import List, Dict def filter_records(recor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_records(records: List[Dict[str, str]], column_name: str, specific_value: str, substring: str) -> List[Dict[str, str]]: """ Filters a list of dictionaries based on a specific value in a c...
code_exercise_27k
25,723
Write a Python function to filter a list of dictionaries based on two conditions: a specific value in one key and a value greater than a certain number in another key. The function should return a list of dictionaries that meet both conditions. The code should start with: ```python from typing import List, Dict def f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_records(records: List[Dict[str, int]], specific_value: int, minimum_value: int) -> List[Dict[str, int]]: """ Filters a list of dictionaries based on two conditions: a specific value in o...
code_exercise_27k
25,730
Write a Python function to find records that have a specific value in one column and a value greater than a certain number in another column, using a subquery and a JOIN operation. The function should simulate the database operations using Python lists and dictionaries to represent the table and records. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_records_with_specific_value_and_greater_than_number(table: List[Dict[str, any]], specific_value: any, threshold: float) -> List[Dict[str, any]]: """ Find records that have a specific value...
code_exercise_27k
25,735
Write a Python function to calculate the difference between two timestamps in seconds. The timestamps are provided as strings in the format 'YYYY-MM-DD HH:MM:SS'. The function should handle the conversion of the timestamps to datetime objects and compute the difference in seconds. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def calculate_time_difference(start_time: str, end_time: str) -> int: """ Calculate the difference between two timestamps in seconds. Args: start_time (str): The starting timestamp in ...
code_exercise_27k
25,755
Write a Python function to calculate the difference between two timestamps in minutes. The timestamps are provided as strings in the format 'YYYY-MM-DD HH:MM:SS'. The function should handle incorrect timestamp formats by raising a `ValueError`. The code should start with: ```python from datetime import datetime def c...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def calculate_time_difference_in_minutes(start_time: str, end_time: str) -> float: """ Calculate the difference between two timestamps in minutes. Args: start_time (str): Start timesta...
code_exercise_27k
25,811
Write a Python function to find the nth highest value in a list of integers. The function should efficiently handle the task using a min-heap to maintain the top n elements. The code should start with: ```python from typing import List def find_nth_highest_value(values: List[int], n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import heapq def find_nth_highest_value(values: List[int], n: int) -> int: """ Find the nth highest value in a list of integers using a min-heap. Args: values (List[int]): The list of inte...
code_exercise_27k
25,824
Write a Python function to calculate the difference between two timestamps in milliseconds. The function should handle the input validation to ensure both timestamps are of type `datetime`. If either timestamp is not of type `datetime`, the function should raise a `TypeError`. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def calculate_time_difference_in_milliseconds(timestamp1: datetime, timestamp2: datetime) -> int: """ Calculate the difference between two timestamps in milliseconds. Args: timestamp1 ...
code_exercise_27k
25,838
Write a Python function to find the K largest elements in a given array using a modified version of the TopK_Greedy algorithm. The function should use a max heap to efficiently find and return the K largest elements in descending order. The code should start with: ```python from typing import List import heapq def ge...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def get_k_largest_elements(arr: List[int], k: int) -> List[int]: """ Finds the K largest elements in the given array using a modified TopK_Greedy algorithm. Args: arr (List[int]...
code_exercise_27k
25,846
Write a Python function to calculate the sum of all elements in a given list. The function should handle lists containing integers, floats, and a mix of both. The code should start with: ```python from typing import List, Union def calculate_sum(lst: List[Union[int, float]]) -> Union[int, float]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def calculate_sum(lst: List[Union[int, float]]) -> Union[int, float]: """ Calculate the sum of all elements in a given list. Args: lst (List[Union[int, float]]): A list of numbers (in...
code_exercise_27k
25,849
Write a Python function to find the maximum and minimum values in a given list of numerical values. The function should return a tuple containing the maximum and minimum values, in that order. If the list is empty, the function should return `None`. The code should start with: ```python from typing import List, Tuple,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def find_max_min(lst: List[int]) -> Optional[Tuple[int, int]]: """ Find the maximum and minimum values in a given list of numerical values. Args: lst (List[int]): A list of ...
code_exercise_27k
25,850
Write a Python function to find the K students with the highest scores from a given list of tuples, where each tuple contains a student's name and their score. The function should return a list of the top K students based on their scores. If K is greater than the number of students, the function should return all stude...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_top_k_students(students: List[Tuple[str, int]], k: int) -> List[Tuple[str, int]]: """ Find the K students with the highest scores from a given list of tuples. Args: students ...
code_exercise_27k
25,857
Write a Python function to find the K most common elements in a given list of integers using the TopK_Greedy algorithm. The function should return a list of the K most common elements in descending order of their frequency. If there are ties in frequency, the elements should be returned in the order they first appear i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def top_k_greedy(nums: List[int], k: int) -> List[int]: """ Finds the K most common elements in a list of integers using the TopK_Greedy algorithm. Args: nums...
code_exercise_27k
25,859
Write a Python function to find the K longest durations from a given list of time durations in seconds using a modified TopK_Greedy algorithm. The function should return the K longest durations in descending order. The code should start with: ```python from typing import List import heapq def find_k_longest_durations...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def find_k_longest_durations(durations: List[int], k: int) -> List[int]: """ Find the K longest durations from a given list of durations using a modified TopK_Greedy algorithm. Args: ...
code_exercise_27k
25,865
Write a Python function to find the K students with the highest average grades from a given list of students and their grades. Each student's data is represented as a list where the first element is the student's name and the subsequent elements are their grades. The function should return a list of tuples, each contai...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_top_k_students(students: List[List[any]], k: int) -> List[Tuple[str, float]]: """ Find the K students with the highest average grades. Args: students (list): A list of lists,...
code_exercise_27k
25,870
Write a Python function to calculate the factorial of a given non-negative integer using an iterative approach. The function should handle edge cases such as zero and should not accept negative integers. The code should start with: ```python def factorial(n: int) -> int: ```
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 non-negative integer using an iterative approach. Args: n (int): The non-negative integer for which the factorial is to be calculated. Return...
code_exercise_27k
25,872
Write a Python function to sort a given list 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 code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(list_to_sort: List) -> List: """ Sorts a given list in ascending order using the merge sort algorithm. Args: list_to_sort (List): The list to be sorted. Returns: ...
code_exercise_27k
25,873
Write a Python function to check if a number is prime or not. The function should return `True` if the number is prime and `False` otherwise. The function should handle edge cases such as negative numbers, 0, and 1, which are not prime. The code should start with: ```python def is_prime(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Check if a number is prime or not. Args: n (int): The number to be checked. Returns: bool: True if the number is prime, False otherwise. """ # 1 and negative nu...
code_exercise_27k
25,876
Write a Python function to reverse the words in a given string while maintaining the order of the words. For example, if the input string is "Hello World!", the output should be "World! Hello". The function should handle strings with multiple spaces between words and leading/trailing spaces. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_words_in_string(s: str) -> str: """ Reverses the words in a given string while maintaining the order of the words. Args: s (str): The input string containing words to be reversed. Returns: s...
code_exercise_27k
25,879
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 a different word or phrase, typically using all the original letters exactly once. The function should ignore spaces and be case-insensitive. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(s1: str, s2: str) -> bool: """ Determines if two given strings are anagrams of each other. Args: s1 (str): The first string. s2 (str): The second string. Returns: bool: True if ...
code_exercise_27k
25,881
Write a Python function to find the minimum value in a given list of numeric values. The function should handle the case where the list is empty by raising a `ValueError`. The code should start with: ```python from typing import List, Union def find_minimum_value(lst: List[Union[int, float]]) -> Union[int, float]: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_minimum_value(lst: List[Union[int, float]]) -> Union[int, float]: """ Finds the minimum value in a given list of numeric values. Args: lst (List[Union[int, float]]): A list o...
code_exercise_27k
25,883
Write a Python function to sort a list in ascending order using the merge sort algorithm. Merge sort is a divide-and-conquer algorithm that recursively divides the list into halves, sorts each half, and then merges the sorted halves back together. The code should start with: ```python from typing import List def merge...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(lst: List[int]) -> List[int]: """ Sorts a list in ascending order using the merge sort algorithm. Args: lst (List[int]): The list to be sorted. Returns: List[int]...
code_exercise_27k
25,886
Write a Python function to count the number of vowels in a given string, considering both uppercase and lowercase vowels. The function should handle strings with any characters, including spaces, punctuation, and numbers. The code should start with: ```python def count_vowels(string: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowels(string: str) -> int: """ Count the number of vowels in a given string. This function iterates through each character in the input string, checks if it is a vowel, and increments a counter if it is. The ...
code_exercise_27k
25,887
Write a Python function to find the K lexicographically smallest strings from a given list of strings using a modified version of the TopK_Greedy algorithm. The function should ensure that no duplicate strings are included in the result, even if the input list contains duplicates. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def top_k_lexicographically_smallest_unique(strings: List[str], k: int) -> List[str]: """ Find the K lexicographically smallest unique strings from a given list of strings using a modified T...
code_exercise_27k
25,894
Write a Python function to find the K users with the most recent activity from a given list of tuples containing user IDs and their respective timestamps. The timestamps are in string format and represent dates and times. The function should return a list of user IDs for the K users with the most recent activity. The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_k_most_recent_users(activity_list: List[Tuple[str, str]], k: int) -> List[str]: """ Find the K users with the most recent activity based on a list of tuples containing user IDs and their ...
code_exercise_27k
25,895
Write a Python function to find the K subjects with the highest number of students from a given list of lists, where each sublist contains a student name and their respective subject. The function should return a list of tuples, each containing the subject name and the number of students enrolled in that subject. The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from collections import Counter def get_top_k_subjects(data: List[List[str]], k: int) -> List[Tuple[str, int]]: """ Get the K subjects with the highest number of students. Args: data ...
code_exercise_27k
25,898
Write a Python function to determine if a given number is a power of two using bitwise operations. The function should return `True` if the number is a power of two, and `False` otherwise. The code should start with: ```python def is_power_of_two_bitwise(number: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_power_of_two_bitwise(number: int) -> bool: """ Determine if a given number is a power of two using bitwise operations. Args: number (int): The number to check. Returns: bool: True if the number i...
code_exercise_27k
25,902
Write a Python function to find the median of two sorted arrays efficiently. The function should handle the case where the arrays are of different lengths and should not use the built-in `sorted` function. Instead, it should use a more efficient approach to merge the arrays and find the median. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_median_sorted_arrays(nums1: List[int], nums2: List[int]) -> float: """ Calculates the median of two sorted arrays efficiently. Args: nums1 (List[int]): First sorted array. n...
code_exercise_27k
25,904
Write a Python function to implement a binary search algorithm that finds the first occurrence of a target value in a sorted list. If the target value is not found, return -1. The function should handle duplicate values by returning the index of the first occurrence. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first_occurrence(arr: List[int], target: int) -> int: """ Perform a binary search on a sorted list to find the first occurrence of the target value. Args: arr (List[int...
code_exercise_27k
25,907
Write a Python function to calculate the sum of all digits in a given number. The function should handle both positive and negative integers. The code should start with: ```python def sum_of_digits(number: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_digits(number: int) -> int: """ Calculates the sum of all digits in a given number. Args: number (int): The number for which the sum of digits needs to be calculated. Returns: int: The sum of...
code_exercise_27k
25,910
Write a Python function to find the number of occurrences of a given element in a list. The function should be efficient and handle various types of elements, including integers, strings, and other data types. The code should start with: ```python from typing import List, Any def count_occurrences(lst: List[Any], elem...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def count_occurrences(lst: List[Any], element: Any) -> int: """ Count the number of occurrences of a given element in a list. Args: lst (List[Any]): The input list containing elements o...
code_exercise_27k
25,914
Write a Python function to find the mode(s) of a given list of integers. The mode is the element(s) that appear most frequently in the list. If there are multiple elements with the same highest frequency, return all of them. The function should handle an empty list by raising a `ValueError`. The code should start with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import Counter def find_mode(lst: List[int]) -> List[int]: """ Find the mode(s) of a given list of integers. The mode is the element(s) that appear most frequently in the list. If t...
code_exercise_27k
25,916
Write a Python function to implement the Floyd-Warshall algorithm for finding the shortest paths between all pairs of vertices in a given weighted graph. The graph is represented as an adjacency matrix where `graph[i][j]` represents the weight of the edge from vertex `i` to vertex `j`. If there is no direct edge betwee...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def floyd_warshall(graph: List[List[float]]) -> List[List[float]]: """ Finds the shortest path between all pairs of vertices in a given graph using the Floyd-Warshall algorithm. Args: graph ...
code_exercise_27k
25,935
Write a Python function to calculate the sum of all even numbers in a given list. The function should handle an empty list and return 0 in that case. The code should start with: ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_even_numbers(numbers: List[int]) -> int: """ Calculates the sum of all even numbers in a given list. Args: numbers (List[int]): A list of integers. Returns: int: The ...
code_exercise_27k
25,936
Write a Python function to find the K pairs of strings with the largest intersection count from a given list of strings. The intersection count between two strings is defined as the number of common characters between them. The function should use a greedy algorithm to efficiently find the top K pairs. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple from itertools import combinations from collections import defaultdict def top_k_pairs_with_largest_intersection(strings: List[str], k: int) -> List[Tuple[str, str]]: """ Find the K pairs of strin...
code_exercise_27k
25,946
Write a Python function to check if a given Directed Acyclic Graph (DAG) contains a cycle. The function should take an adjacency list representation of the graph as input and return a boolean indicating whether the graph contains a cycle. The code should start with: ```python from typing import Dict, List def has_cyc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def has_cycle_in_dag(graph: Dict[int, List[int]]) -> bool: """ Check whether a given Directed Acyclic Graph (DAG) contains a cycle. Args: graph (Dict[int, List[int]]): The adjacency li...
code_exercise_27k
25,951
Write a Python function to reverse a given list without using the built-in `reverse()` function or any other built-in functions that directly reverse a list. The function should use a two-pointer approach to swap elements from the beginning and the end of the list until the entire list is reversed. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_list_without_builtin(lst: List[int]) -> List[int]: """ Reverses a given list without using the built-in reverse() function. Args: lst (List[int]): The list to be reversed. R...
code_exercise_27k
25,954
Write a Python function to remove all duplicates from a given list while preserving the original order of elements. The function should not use Python's built-in `set()` function or any other data structures that inherently remove duplicates. The code should start with: ```python from typing import List def remove_du...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates(lst: List[int]) -> List[int]: """ Remove duplicates from a given list while preserving the original order of elements. Args: lst (List[int]): The list from which duplic...
code_exercise_27k
25,956
Write a Python function to count the number of nodes reachable from a given start node in a Directed Acyclic Graph (DAG). The function should use Depth-First Search (DFS) to traverse the graph and count the reachable nodes. The graph is represented as a dictionary where keys are nodes and values are lists of nodes that...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Set def count_reachable_nodes(graph: Dict[int, List[int]], start_node: int) -> int: """ Counts the number of nodes reachable from a given start node in a Directed Acyclic Graph (DAG). Args: ...
code_exercise_27k
25,961
Write a Python function to calculate the sum of all positive numbers in a given list. The function should handle the input validation to ensure that the input is a list and should return the sum of all positive numbers in the list. The code should start with: ```python from typing import List def sum_of_positive_numb...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_positive_numbers(numbers: List[int]) -> int: """ Calculates the sum of all positive numbers in a given list. Args: numbers (List[int]): A list of integers. Returns: i...
code_exercise_27k
25,967
Write a Python function to calculate the perimeter of a triangle given the lengths of its three sides. The function should validate the input to ensure that the sides form a valid triangle and handle any invalid inputs appropriately. The code should start with: ```python def calculate_triangle_perimeter(side1: float, s...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_triangle_perimeter(side1: float, side2: float, side3: float) -> float: """ Calculates the perimeter of a triangle given the lengths of its three sides. Args: side1 (float): The length of the first side...
code_exercise_27k
25,988
Write a Python function to calculate the area of a parallelogram given its base and height. The function should handle both positive and zero values for the base and height. The code should start with: ```python def calculate_parallelogram_area(base: float, height: float) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_parallelogram_area(base: float, height: float) -> float: """ Calculate the area of a parallelogram given its base and height. Args: base (float): The length of the base of the parallelogram. he...
code_exercise_27k
25,994
Write a Python function to determine if a given list of numbers forms a Pythagorean triplet. A Pythagorean triplet consists of three numbers \(a\), \(b\), and \(c\) such that \(a^2 + b^2 = c^2\). The function should return `True` if the list forms a Pythagorean triplet and `False` otherwise. The function should handle ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_pythagorean_triplet(numbers: List[int]) -> bool: """ Determine if a given list of numbers forms a Pythagorean triplet. A Pythagorean triplet consists of three numbers a, b, and c such that a^...
code_exercise_27k
25,999
Write a Python function to find the earliest starting time for each node in a given Directed Acyclic Graph (DAG). The function should return a dictionary mapping each node to its earliest starting time. The earliest starting time for a node is defined as the maximum of the earliest starting times of its predecessors pl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List from collections import deque def find_earliest_starting_time(graph: Dict[int, List[int]]) -> Dict[int, int]: """ Find the earliest starting time for each node in a Directed Acyclic Graph (DAG). ...
code_exercise_27k
26,004
Write a Python function to calculate the perimeter of a parallelogram given the lengths of its base and side. The function should handle cases where the base or side length is less than or equal to zero by raising a `ValueError`. The code should start with: ```python def calculate_parallelogram_perimeter(base: float, s...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_parallelogram_perimeter(base: float, side: float) -> float: """ Calculate the perimeter of a parallelogram given the lengths of its base and side. Parameters: - base (float): The length of the base of the ...
code_exercise_27k
26,007
Write a Python function to find the minimum amount of time required to complete all tasks in a given Directed Acyclic Graph (DAG). Each task takes one unit of time to complete, and a task can only start after all its dependencies are completed. The DAG is represented as a dictionary where each key is a task name, and e...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List import collections def find_minimum_time_to_complete_tasks(tasks: Dict[str, List[str]]) -> int: """ Finds the minimum amount of time required to complete all tasks in a Directed Acyclic Graph (DAG)...
code_exercise_27k
26,009
Write a Python function to calculate the perimeter of a trapezoid given the lengths of its two bases and two non-parallel sides. The function should handle both positive and zero lengths for the sides. The code should start with: ```python def calculate_trapezoid_perimeter(base1: float, base2: float, side1: float, side...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_trapezoid_perimeter(base1: float, base2: float, side1: float, side2: float) -> float: """ Calculate the perimeter of a trapezoid given the lengths of its two bases and two non-parallel sides. Args: bas...
code_exercise_27k
26,020
Write a Python function to determine if three given points are collinear. The function should take three tuples representing the coordinates of the points and return a boolean indicating whether the points are collinear. The code should start with: ```python from typing import Tuple def are_collinear(p1: Tuple[float, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def are_collinear(p1: Tuple[float, float], p2: Tuple[float, float], p3: Tuple[float, float]) -> bool: """ Determines if three given points are collinear. Args: p1 (Tuple[float, float]): The...
code_exercise_27k
26,028
Write a Python function to perform binary search on a given list of sorted integers. The function should return the index of the target element if it exists in the list, otherwise it should return `None`. The code should start with: ```python from typing import List, Optional def binary_search(arr: List[int], target: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def binary_search(arr: List[int], target: int) -> Optional[int]: """ Perform binary search on a given list of sorted integers. Args: arr (List[int]): A list of sorted integers. ...
code_exercise_27k
26,032
Write a Python function to determine if two given line segments intersect. Each line segment is represented by a tuple of four integers, where the first two integers represent the coordinates of the starting point and the last two integers represent the coordinates of the ending point. The function should return `True`...
Here is the Python code to solve the given problem in the markdown block: ```python import math def line_segments_intersect(segment1: tuple, segment2: tuple) -> bool: """ Determine if two line segments intersect. Args: segment1 (tuple): Coordinates of the first line segment in the form (x1, y1, x2...
code_exercise_27k
26,043
Write a Python function to find the number of occurrences of a given element in a given list. The function should be efficient and handle various types of elements, including integers, strings, and other data types. The code should start with: ```python from typing import List, Any def count_occurrences(lst: List[Any]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def count_occurrences(lst: List[Any], element: Any) -> int: """ Counts the number of occurrences of a given element in a given list. Args: lst (List[Any]): The list in which to count th...
code_exercise_27k
26,055
Write a Python function to calculate the midpoint of a line segment given the coordinates of two points. The function should accept four parameters representing the coordinates of the two points and return a tuple containing the coordinates of the midpoint. The code should start with: ```python def calculate_midpoint(...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_midpoint(x1: float, y1: float, x2: float, y2: float) -> tuple: """ Calculate the midpoint of a line segment given the coordinates of two points. Parameters: x1 (float): X-coordinate of the first point. ...
code_exercise_27k
26,059
Write a Python function to calculate the sum of all numeric elements in a given dictionary. The dictionary may contain various types of values, but only numeric values (integers and floats) should be included in the sum. The function should handle dictionaries with mixed types and return the sum of all numeric values. ...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_numeric_sum(dictionary: dict) -> float: """ Calculates the sum of all numeric elements (integers and floats) in a given dictionary. Args: dictionary (dict): The dictionary containing various types of v...
code_exercise_27k
26,073
Write a Python function to convert a decimal number to its binary representation. The function should take an integer as input and return the binary representation as a string. The function should handle both positive and zero values. The code should start with: ```python def decimal_to_binary(decimal_num: int) -> str...
Here is the Python code to solve the given problem in the markdown block: ```python def decimal_to_binary(decimal_num: int) -> str: """ Convert a decimal number to its binary representation. Args: decimal_num (int): The decimal number to be converted. Returns: str: The binary represent...
code_exercise_27k
26,075
Write a Python function to retrieve the top `n` highest-paid employees from a given list of employee records. Each employee record is represented as a dictionary with keys `'employee_id'`, `'employee_name'`, and `'salary'`. The function should return a list of dictionaries representing the top `n` highest-paid employee...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def get_top_n_highest_paid_employees(employees: List[Dict[str, any]], n: int) -> List[Dict[str, any]]: """ Retrieves the top n highest-paid employees from a given list of employee records. Arg...
code_exercise_27k
26,076
Write a Python function to convert an octal number to its decimal equivalent. The function should take an octal number as a string and return its decimal equivalent as an integer. The function should handle octal numbers with valid digits (0-7) and should raise a ValueError if an invalid digit is encountered. The code...
Here is the Python code to solve the given problem in the markdown block: ```python def octal_to_decimal(octal_num: str) -> int: """ Convert an octal number represented as a string to its decimal equivalent. This function takes an octal number as a string and returns its decimal equivalent as an integer. ...
code_exercise_27k
26,084
Write a Python function to calculate the volume of a triangular prism given the base length, height of the triangle, and the length of the prism. The function should handle both positive and zero values for the inputs. The code should start with: ```python def calculate_triangular_prism_volume(base_length: float, heigh...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_triangular_prism_volume(base_length: float, height: float, prism_length: float) -> float: """ Calculate the volume of a triangular prism. Args: base_length (float): The length of the triangle's base. ...
code_exercise_27k
26,098
Write a Python function to remove all punctuation from a given string. The function should handle various types of punctuation and return the cleaned string. The code should start with: ```python import string def remove_punctuation(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python import string def remove_punctuation(input_string: str) -> str: """ Removes all punctuation from the given input string. Args: input_string (str): The input string from which punctuation is to be removed. Retu...
code_exercise_27k
26,104
Write a Python function to calculate the sum of all numbers in the Fibonacci sequence up to a given index `n`. The function should return the sum of the Fibonacci numbers from the first Fibonacci number (index 0) up to and including the Fibonacci number at the given index `n`. The code should start with: ```python def...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci_sum(n: int) -> int: """ Calculate the sum of all numbers in the Fibonacci sequence up to the given index. Args: n (int): The index up to which the Fibonacci numbers should be summed. Returns: ...
code_exercise_27k
26,107
Write a Python function to find the difference between the largest and smallest elements in a given list of numbers. If the list is empty, the function should return `None`. The code should start with: ```python from typing import List, Optional def find_difference(nums: List[int]) -> Optional[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List, Optional def find_difference(nums: List[int]) -> Optional[int]: """ Finds the difference between the largest and smallest elements in a given list. Args: nums (List[int]): The list of num...
code_exercise_27k
26,115
Write a Python function to find pairs of employees who have the same last name and are in the same department from a given list of employee records. Each employee record is represented as a dictionary with keys 'name', 'last_name', and 'department'. The function should return a list of tuples, where each tuple contains...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def find_same_last_name_same_department_pairs(employees: List[Dict[str, str]]) -> List[Tuple[str, str]]: """ Finds pairs of employees who have the same last name and are in the same departme...
code_exercise_27k
26,116
Write a Python function to calculate the volume of a pyramid with a rectangular base. The function should take three parameters: the length of the base, the width of the base, and the height of the pyramid. The function should return the volume of the pyramid. The code should start with: ```python def calculate_pyrami...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_pyramid_volume(length: float, width: float, height: float) -> float: """ Calculates the volume of a pyramid with a rectangular base. Args: length (float): The length of the base. width (float):...
code_exercise_27k
26,123
Write a Python function to calculate the volume of a pyramid with a triangular base. The function should take the lengths of the two sides of the triangular base and the height of the pyramid as inputs and return the volume. The function should also handle cases where the input parameters are invalid (i.e., negative or...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_volume_of_triangular_pyramid(side1: float, side2: float, height: float) -> float: """ Calculates the volume of a pyramid with a triangular base. Args: side1 (float): The length of the firs...
code_exercise_27k
26,124
Write a Python function to calculate the median of a given list of numerical values without using the `numpy` module. The function should handle both even and odd lengths of the list and ensure the list is sorted before calculating the median. The code should start with: ```python from typing import List def calculate...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_median_without_numpy(data: List[int]) -> float: """ Calculate the median of a given list of numerical values without using the numpy module. Args: data (List[int]): A list of n...
code_exercise_27k
26,127
Write a Python function to calculate the surface area of a pyramid with a triangular base. The function should take three parameters: the length of the base of the triangular pyramid, the height of the base of the triangular pyramid, and the slant height of the triangular pyramid. The function should return the total s...
Here is the Python code to solve the given problem in the markdown block: ```python import math def calculate_surface_area(base_length: float, base_height: float, slant_height: float) -> float: """ Calculate the surface area of a pyramid with a triangular base. Args: base_length (float): The lengt...
code_exercise_27k
26,145
Write a Python function to find pairs of employees who have the same supervisor and the same job title. The function should take a list of dictionaries, where each dictionary represents an employee with keys 'name', 'supervisor_id', and 'job_title'. The function should return a list of tuples, where each tuple contains...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Tuple def find_employee_pairs(employees: List[Dict[str, any]]) -> List[Tuple[str, str]]: """ Finds pairs of employees who have the same supervisor and the same job title. Args: employ...
code_exercise_27k
26,148
Write a Python function to find the names of employees who have the same supervisor but different job titles. The function should take a list of dictionaries, where each dictionary represents an employee with keys 'name', 'supervisor_id', and 'job_title'. The function should return a list of employee names that meet th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_employees_with_same_supervisor_different_titles(employees: List[Dict[str, any]]) -> List[str]: """ Find the names of employees who have the same supervisor but different job titles. A...
code_exercise_27k
26,151
Write a Python function to remove duplicates from a sorted array in-place and return the new length of the array. The function should ensure that the array is modified directly, without using extra space, and only the unique elements should remain in the array up to the new length. 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 remove_duplicates(nums: List[int]) -> int: """ Remove duplicates in-place from a sorted array and return the new length. Args: nums (List[int]): The sorted array of integers. Return...
code_exercise_27k
26,155
Write a Python function to find two distinct numbers in a given array that add up to a specific target sum. The function should return the indices of these two numbers. If no such pair exists, the function should return `None`. The code should start with: ```python from typing import List, Optional, Tuple def find_tw...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional, Tuple def find_two_sum_indices(nums: List[int], target: int) -> Optional[Tuple[int, int]]: """ Finds two distinct numbers in the given array that add up to the target sum and returns their ind...
code_exercise_27k
26,156
Write a Python function to determine if there are two distinct numbers in a given sorted array whose sum equals a specified target value. The function should use a two-pointer technique to efficiently find the solution. The code should start with: ```python from typing import List def find_pair_with_sum(arr: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_pair_with_sum(arr: List[int], target: int) -> bool: """ Determines if there are two distinct numbers in a sorted array whose sum equals the specified target value. Args: arr (List[i...
code_exercise_27k
26,159
Write a Python function to count the number of prime numbers in a given array of integers. The function should use a helper function to check if a number is prime. The code should start with: ```python from typing import List def count_prime_numbers(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Parameters: - n (int): The number to check. Returns: - bool: True if the number is prime, False otherwise. """ if n...
code_exercise_27k
26,163
Write a Python function to find a pair of integers in a sorted array that sums up to a given target sum. If no such pair exists, return `None`. The function should use a two-pointer technique to efficiently find the pair. The code should start with: ```python from typing import List, Tuple, Optional def find_pair_wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Optional def find_pair_with_sum(arr: List[int], target_sum: int) -> Optional[Tuple[int, int]]: """ Find a pair of integers in a sorted array that sums up to the given target sum. Args: ...
code_exercise_27k
26,173
Write a Python function to find the longest subarray with a sum equal to zero in a given array of integers. The function should return the longest subarray with the sum equal to zero, or an empty list if no such subarray exists. The code should start with: ```python from typing import List def longest_zero_sum_subarr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_zero_sum_subarray(arr: List[int]) -> List[int]: """ Finds the longest subarray with a sum equal to zero in the given array. Args: arr (List[int]): The input array of integers. ...
code_exercise_27k
26,179
Write a Python function to determine if a given integer is a perfect square. The function should return `True` if the integer is a perfect square, and `False` otherwise. The code should start with: ```python def is_perfect_square(n: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_perfect_square(n: int) -> bool: """ Determines if a given integer is a perfect square. Args: n (int): The integer to check. Returns: bool: True if the integer is a perfect square, Fa...
code_exercise_27k
26,190
Write a Python function to merge two sorted arrays into a new sorted array. The function should efficiently combine the elements from both arrays while maintaining the sorted order. The code should start with: ```python from typing import List def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_arrays(arr1: List[int], arr2: List[int]) -> List[int]: """ Merge two sorted arrays into a new sorted array. Args: arr1 (List[int]): The first sorted array. arr2 (Lis...
code_exercise_27k
26,207
Write a Python function to return a sorted array of squares from a given array of sorted square numbers. The function should efficiently handle both positive and negative integers, ensuring that the output array is sorted in ascending order. The code should start with: ```python from typing import List def sorted_squa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sorted_squares(nums: List[int]) -> List[int]: """ Returns a sorted array of squares from a given array of sorted square numbers. Args: nums (List[int]): A list of sorted square numbers (...
code_exercise_27k
26,211
Write a Python function to find the maximum product of three numbers from a given array of integers. The function should handle arrays with both positive and negative integers. The code should start with: ```python from typing import List def maximum_product_of_three(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def maximum_product_of_three(nums: List[int]) -> int: """ Find three numbers in the given array whose product is the maximum. Args: nums (List[int]): List of integers. Returns: ...
code_exercise_27k
26,223
Write a Python function to move all zeroes to the end of a given array while maintaining the relative order of the other elements. The function should not use any additional data structures except for a single list to store non-zero elements temporarily. 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 move_zeros_to_end(arr: List[int]) -> List[int]: """ Move all zeroes to the end of the given array while maintaining the relative order of the other elements. Args: arr (List[int]): The i...
code_exercise_27k
26,226
Write a Python function to find the intersection of two arrays, ensuring that the result contains only unique elements and is sorted in ascending order. The function should handle any size of input arrays and should be efficient in terms of both time and space complexity. 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 find_intersection(nums1: List[int], nums2: List[int]) -> List[int]: """ Find the intersection of two arrays, ensuring the result contains only unique elements and is sorted in ascending order. A...
code_exercise_27k
26,228
Write a Python function to filter out the names of employees whose salaries are not multiples of 1000 from a given list of employee dictionaries. Each dictionary contains the keys 'name' and 'salary'. The function should return a list of names that meet the criteria. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_employees_by_salary(employees: List[Dict[str, any]]) -> List[str]: """ Filters out the names of employees whose salaries are not multiples of 1000. Args: employees (List[Dic...
code_exercise_27k
26,235
Write a Python function to find the length of the longest subarray with an equal number of 0s and 1s in a given binary array. The function should return the length of the longest such subarray. The code should start with: ```python from typing import List def longest_subarray_with_equal_0s_and_1s(arr: List[int]) -> i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_subarray_with_equal_0s_and_1s(arr: List[int]) -> int: """ Find the length of the longest subarray with an equal number of 0s and 1s in a given binary array. Args: arr (List[int])...
code_exercise_27k
26,241
Write a Python function to find the length of the shortest subarray that contains at least `k` distinct elements from a given array. The function should return the length of the shortest such subarray. If no such subarray exists, the function should return `-1`. 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 shortest_subarray_with_k_distinct(arr: List[int], k: int) -> int: """ Finds the length of the shortest subarray with at least k distinct elements. Args: arr (List[int]): List of elements...
code_exercise_27k
26,260
Write a Python function to calculate the surface area of a pyramid with a square base. The function should take two parameters: `base_length` (the length of the base of the pyramid) and `slant_height` (the slant height of the pyramid). The function should return the surface area of the pyramid. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_surface_area(base_length: float, slant_height: float) -> float: """ Calculate the surface area of a pyramid with a square base. Args: base_length (float): The length of the base of the pyramid. ...
code_exercise_27k
26,329
Write a Python function to find a feasible solution for a given matrix using the Hungarian Algorithm. The function should take a 2D list (or numpy array) as input and return a 2D list (or numpy array) representing the indices of the selected elements that form the optimal assignment. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def find_optimal_assignment(matrix: np.ndarray) -> np.ndarray: """ Find a feasible solution for a given matrix using the Hungarian Algorithm. Parameters: matrix (numpy.ndarray): The matrix to be anal...
code_exercise_27k
26,349
Write a Python function to solve the Traveling Salesman Problem (TSP) using a heuristic algorithm called Simulated Annealing. The function should take a list of points (each represented as a tuple of `(x, y)` coordinates) and optional parameters for the initial temperature, cooling factor, and number of iterations. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import math import random def tsp_simulated_annealing(points: List[Tuple[float, float]], initial_temperature: float = 1000, cooling_factor: float = 0.999, iterations: int = 10000) -> List[Tuple[float, flo...
code_exercise_27k
26,396
Write a Python function to calculate the variance of a list of numbers. The function should handle lists with at least two numbers and return the variance as a float. The code should start with: ```python from typing import List def calculate_variance(numbers: List[int]) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_variance(numbers: List[int]) -> float: """ Calculate the variance of a list of numbers. The variance is a measure of how far a set of numbers is spread out. It is calculated as the ave...
code_exercise_27k
26,397
Write a Python function to calculate the mode(s) of a given list of numbers. The mode is the number(s) that appear most frequently in the list. If there are multiple numbers with the same highest frequency, the function should return all of them. The function should handle an empty list by raising a `ValueError`. The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_mode(numbers: List[int]) -> List[int]: """ Calculates the mode(s) of a list of numbers. The mode is the number(s) that appear most frequently in the list. If there are multiple numbers...
code_exercise_27k
26,404
Write a Python function to find the maximum element in a given set that contains a specified element. If the specified element is not present in the set, the function should return `None`. If the set is empty, the function should also return `None`. The code should start with: ```python def find_max_element(given_set:...
Here is the Python code to solve the given problem in the markdown block: ```python def find_max_element(given_set: set, element: int) -> int: """ Find the maximum element in the set that contains the given element. Args: given_set (set): The set to search for the maximum element. element (...
code_exercise_27k
26,405
Write a Python function to calculate the standard deviation of a list of numbers. The function should handle an empty list by raising a `ValueError`. The code should start with: ```python from typing import List import math def calculate_standard_deviation(numbers: List[float]) -> float: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def calculate_standard_deviation(numbers: List[float]) -> float: """ Calculate the standard deviation of a list of numbers. Args: numbers (List[float]): A list of numbers for whi...
code_exercise_27k
26,409
Write a Python function to generate a specified number of random numbers from a binomial distribution with given parameters. The function should return a list of these random numbers. The code should start with: ```python from typing import List import numpy as np def generate_binomial_random_numbers(n: int, p: float,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def generate_binomial_random_numbers(n: int, p: float, size: int) -> List[int]: """ Generate a specified number of random numbers from a binomial distribution. Parameters: - n...
code_exercise_27k
26,420
Write a Python function to calculate the probability of getting exactly `num_heads` heads in `num_flips` coin flips. The function should use the binomial coefficient to determine the number of successful outcomes and then compute the probability. The code should start with: ```python from math import comb def calculat...
Here is the Python code to solve the given problem in the markdown block: ```python from math import comb def calculate_probability(num_flips: int, num_heads: int) -> float: """ Calculate the probability of getting exactly num_heads heads in num_flips coin flips. Args: num_flips (int): The number ...
code_exercise_27k
26,426
Write a Python function to generate a specified number of random numbers from a Poisson distribution with a given lambda (rate parameter). The function should return the generated numbers as a list. The code should start with: ```python from typing import List import numpy as np def generate_poisson_numbers(lam: float...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import numpy as np def generate_poisson_numbers(lam: float, size: int) -> List[int]: """ Generate a specified number of random numbers from a Poisson distribution with a given lambda (rate parameter). ...
code_exercise_27k
26,435
Write a Python function to generate a random sample from an exponential distribution using the inverse transform method. The function should take two parameters: the size of the sample and the scale parameter of the exponential distribution. The function should return the generated random sample as a NumPy array. The ...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def generate_random_sample(size: int, scale: float) -> np.ndarray: """ Generate a random sample from an exponential distribution using the inverse transform method. Parameters: - size (int): The size...
code_exercise_27k
26,437
Write a Python function to calculate the percentile rank of a given value in a list of numbers. The percentile rank is defined as the percentage of values in the list that are less than or equal to the given value. If the value is not found in the list, raise a `ValueError`. 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, Union def calculate_percentile_rank(numbers: List[Union[int, float]], value: Union[int, float]) -> float: """ Calculate the percentile rank of a given value in a list of numbers. The percentile ran...
code_exercise_27k
26,479
Write a Python function to calculate the mode(s) of a given dataset. The mode is the value(s) that appear most frequently in the dataset. If there are multiple values with the same highest frequency, the function should return all of them. The dataset can be a list or a tuple of integers or floats. The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union from collections import Counter def calculate_mode(dataset: Union[List[Union[int, float]], Tuple[Union[int, float]]]) -> List[Union[int, float]]: """ Calculate the mode(s) (most common valu...
code_exercise_27k
26,539
Write a Python function to count the total number of elements in a given list. The function should handle empty lists by returning 0 instead of raising an exception. The code should start with: ```python from typing import List def count_elements(lst: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_elements(lst: List[int]) -> int: """ Count the total number of elements in a given list. Args: lst (List[int]): The list to count the elements from. Returns: int: The ...
code_exercise_27k
26,564
Write a Python function to subtract one list from another list. The function should return a new list containing the elements present in the first list but not in the second list. The code should start with: ```python from typing import List def subtract_lists(list1: List[int], list2: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def subtract_lists(list1: List[int], list2: List[int]) -> List[int]: """ Subtract one list from another list. Parameters: - list1 (List[int]): The first list from which elements will be subtract...
code_exercise_27k
26,575
Write a Python function to perform fuzzy C-means clustering on a given dataset. The function should identify different clusters based on the provided number of clusters and fuzziness parameter. The function should also include a stopping criterion and a maximum number of iterations to prevent infinite loops. The code ...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def fuzzy_c_means(X: np.ndarray, num_clusters: int, fuzziness: float, epsilon: float = 0.01, max_iter: int = 100) -> (np.ndarray, np.ndarray): """ Performs fuzzy C-means clustering on a dataset. Paramete...
code_exercise_27k
26,665
Write a Python function to calculate the length of an interval `[a, b]` where `a` and `b` are floating-point numbers. The function should handle cases where `a` is greater than `b` by returning the absolute difference between `b` and `a`. The code should start with: ```python def interval_length(a: float, b: float) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python def interval_length(a: float, b: float) -> float: """ Calculate the length of an interval [a, b]. Args: a (float): The lower bound of the interval. b (float): The upper bound of the interval. Returns: ...
code_exercise_27k
26,668
Write a Python function to find the intersection of two intervals. The function should take four integers as input, representing the endpoints of two intervals, and return the intersection interval as a tuple if it exists. If no intersection exists, the function should return `None`. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python def find_interval_intersection(a: int, b: int, c: int, d: int) -> tuple: """ Find the intersection between two intervals [a, b] and [c, d]. Args: a (int): The start of the first interval. b (int): The end of...
code_exercise_27k
26,670
Write a Python function to merge overlapping intervals in a list. Each interval is represented by a tuple of two integers, where the first integer is the start of the interval and the second integer is the end of the interval. The function should return a list of merged intervals, where each interval is represented by ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def merge_intervals(intervals: List[Tuple[int, int]]) -> List[Tuple[int, int]]: """ Merges overlapping intervals in a list. Args: intervals (List[Tuple[int, int]]): A list of interval...