source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
code_exercise_27k
24,989
Write a Python function to calculate the edit distance (also known as Levenshtein distance) between two given strings. The edit distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to transform one string into the other. The function should use a dynamic...
Here is the Python code to solve the given problem in the markdown block: ```python def edit_distance(str1: str, str2: str) -> int: """ Calculate the edit distance (Levenshtein distance) between two strings. The edit distance is the minimum number of single-character edits (insertions, deletions, or substi...
code_exercise_27k
24,996
Write a Python function to find the shortest path between all pairs of vertices in a directed graph using the Floyd-Warshall algorithm. The function should take a 2D list representing the adjacency matrix of the graph as input and return a 2D list representing the shortest distances between all pairs of vertices. If th...
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[int]]) -> List[List[int]]: """ Find the shortest path between all pairs of vertices in a directed graph using the Floyd-Warshall algorithm. Args: graph (L...
code_exercise_27k
24,998
Write a Python function to find the maximum sum of a non-adjacent subsequence in a given array. The function should use dynamic programming to achieve this. The subsequence should not contain any adjacent elements. The code should start with: ```python from typing import List def max_sum_non_adjacent_subsequence(arr: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_sum_non_adjacent_subsequence(arr: List[int]) -> int: """ Calculate the maximum sum of a non-adjacent subsequence in a given array. Args: arr (List[int]): The input array of integers....
code_exercise_27k
25,004
Write a Python function to find the number of weakly connected components in a directed graph. A weakly connected component is defined as a maximal subgraph in which there is a path between any two nodes, ignoring the direction of edges. The code should start with: ```python from typing import Dict, List def count_we...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def count_weakly_connected_components(graph: Dict[int, List[int]]) -> int: """ Counts the number of weakly connected components in a directed graph. Parameters: graph (dict): A directed gr...
code_exercise_27k
25,005
Write a Python function to count the number of ways to reach the top of a staircase with `n` steps, where the person can climb either 1 step or 2 steps at a time. The function should use a dynamic programming approach to solve the problem efficiently. The code should start with: ```python def count_ways_to_climb_stair...
Here is the Python code to solve the given problem in the markdown block: ```python def count_ways_to_climb_stairs(n: int) -> int: """ Count the number of ways to reach the top of a staircase with n steps, where the person can climb either 1 step or 2 steps at a time. Args: n (int): The number ...
code_exercise_27k
25,016
Write a Python function to find the number of strongly connected components in a bipartite graph. A bipartite graph is a graph whose vertices can be divided into two disjoint sets such that no two graph vertices within the same set are adjacent. The function should take a dictionary representing the bipartite graph as ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List from collections import defaultdict, deque def count_strongly_connected_components(graph: Dict[int, List[int]]) -> int: """ Find the number of strongly connected components in a bipartite graph. ...
code_exercise_27k
25,030
Write a Python function to calculate the average age of students from a given list of dictionaries, where each dictionary represents a student with keys 'name' and 'age'. The function should handle cases where the list is empty by returning `None`. The code should start with: ```python from typing import List, Dict, O...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Optional def calculate_average_age(students: List[Dict[str, any]]) -> Optional[float]: """ Calculate the average age of students from a given list of dictionaries. Args: students (Lis...
code_exercise_27k
25,032
Write a Python function to find the maximum product of a subarray in a given array using dynamic programming. The function should efficiently compute the maximum product by considering both positive and negative numbers in the array. The code should start with: ```python from typing import List def max_product_subarra...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_product_subarray(nums: List[int]) -> int: """ Finds the maximum product of a subarray in a given array using dynamic programming. Args: nums (List[int]): The input list of integers. ...
code_exercise_27k
25,039
Write a Python function to determine if a given directed graph is a Directed Acyclic Graph (DAG). The graph is represented as a dictionary where keys are nodes and values are lists of nodes that the key node points to. The function should return `True` if the graph is a DAG and `False` otherwise. The code should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def is_directed_acyclic_graph(graph: Dict[int, List[int]]) -> bool: """ Determine if the given directed graph is a Directed Acyclic Graph (DAG). Args: graph (Dict[int, List[int]]): A d...
code_exercise_27k
25,045
Write a Python function to find the minimum number of jumps required to reach the end of an array, where each element represents the maximum distance that can be jumped. The function should use a dynamic programming approach to solve the problem efficiently. 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 min_jumps_to_end(arr: List[int]) -> int: """ Calculate the minimum number of jumps required to reach the end of an array. Args: arr: A list representing the maximum distance that can be ...
code_exercise_27k
25,053
Write a Python function to calculate the number of ways to reach the top of a staircase where the person can climb either 1, 2, or 3 steps at a time. The function should use dynamic programming to efficiently compute the result. The code should start with: ```python def count_ways_to_climb(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_ways_to_climb(n: int) -> int: """ Calculate the number of ways to reach the top of a staircase with n steps, where one can climb either 1, 2, or 3 steps at a time. Args: n (int): The total number of st...
code_exercise_27k
25,061
Write a Python function to find the length of the longest substring without repeating characters in a given string. The function should use a dynamic programming approach to efficiently solve the problem. The code should start with: ```python def longest_substring_length(s: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def longest_substring_length(s: str) -> int: """ Find the length of the longest substring without repeating characters in a given string. Args: s (str): The input string. Returns: int: The length of the...
code_exercise_27k
25,064
Write a Python function to detect if a directed graph contains a cycle. The graph is represented as a dictionary where keys are nodes and values are lists of adjacent nodes. The function should return `True` if the graph contains a cycle, and `False` otherwise. 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 Dict, List def has_cycle_in_graph(graph: Dict[int, List[int]]) -> bool: """ Detects if a directed graph contains a cycle. Args: graph (Dict[int, List[int]]): The directed graph represented as a d...
code_exercise_27k
25,067
Write a Python function to find the number of strongly connected components in a directed graph. A strongly connected component (SCC) is a maximal subgraph where there is a path from any vertex to any other vertex within the subgraph. The code should start with: ```python from typing import Dict, List def count_stron...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def count_strongly_connected_components(graph: Dict[int, List[int]]) -> int: """ Count the number of strongly connected components in a directed graph using Kosaraju's algorithm. Args: ...
code_exercise_27k
25,068
Write a Python function to solve the knapsack problem with item limits using dynamic programming. Each item has a weight, value, and a limit on the number of items that can be taken. The function should return the maximum value that can be obtained without exceeding the weight limit of the knapsack. The code should st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def knapsack_with_limits(items: List[Tuple[int, int, int]], weight_limit: int) -> int: """ Solve the knapsack problem with item limits using dynamic programming. Args: items: A list o...
code_exercise_27k
25,075
Write a Python function to find the longest increasing subsequence (LIS) in a given array. The subsequence does not need to be contiguous, but the elements must be in increasing order. The function should return the length of the LIS. The code should start with: ```python from typing import List def longest_increasin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_increasing_subsequence_length(arr: List[int]) -> int: """ Calculate the length of the longest increasing subsequence in a given array. Args: arr (List[int]): The input array of i...
code_exercise_27k
25,096
Write a Python function to find all the vertices that lie on a directed cycle in a given directed graph. The graph is represented as an adjacency list. The function should return a set of vertices that lie on any directed cycle in the graph. The code should start with: ```python from typing import Dict, Set def find_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Set def find_vertices_on_cycle(graph: Dict[int, Set[int]]) -> Set[int]: """ Finds all vertices that lie on a directed cycle in a given directed graph. Args: graph (Dict[int, Set[int]]): A d...
code_exercise_27k
25,136
Write a Python function to update the grade of all students with a grade of "C" to "B" in a list of student dictionaries. Each student dictionary contains the following keys: "name" (string) and "grade" (string). The function should return the updated list of student dictionaries. 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, Dict def update_grades(students: List[Dict[str, str]]) -> List[Dict[str, str]]: """ Updates the grade of all students with a grade of "C" to "B". Args: students (List[Dict[str, str]]): A li...
code_exercise_27k
25,146
Write a Python function to count the number of students in each grade and return the results sorted by the grade in ascending order. Each student is represented by a dictionary with 'name' and 'grade' keys. The function should start with: ```python from typing import List, Dict def count_students_by_grade(students: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_students_by_grade(students: List[Dict[str, any]]) -> Dict[int, int]: """ Count the number of students in each grade and return the results sorted by the grade in ascending order. Arg...
code_exercise_27k
25,159
Write a Python function to calculate the sum of two numbers, ensuring that the function handles both integer and floating-point inputs correctly. The function should also handle cases where the inputs are not numbers by returning `None`. The code should start with: ```python def add_numbers(a, b): ```
Here is the Python code to solve the given problem in the markdown block: ```python def add_numbers(a, b): """ Adds two numbers together. Parameters: a (float or int): First input number. b (float or int): Second input number. Returns: float or int: Sum of the two input numbers. If either ...
code_exercise_27k
25,162
Write a Python function to calculate the minimum number of deletions and insertions required to convert one string to another using a set of allowed operations. The allowed operations are 'delete' and 'insert'. The function should use dynamic programming to achieve this. The code should start with: ```python def min_o...
Here is the Python code to solve the given problem in the markdown block: ```python def min_operations_to_convert(str1: str, str2: str, allowed_operations: set) -> int: """ Calculates the minimum number of deletions and insertions required to convert str1 to str2 using the allowed operations. Args: ...
code_exercise_27k
25,172
Write a Python function to find the number of unique paths from the top-left to the bottom-right cell of a grid, where certain cells are blocked, using dynamic programming with memoization. The grid is represented as a 2D list where `0` represents an empty cell and `1` represents a blocked cell. The function should ret...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def unique_paths_with_obstacles(obstacleGrid: List[List[int]]) -> int: """ Finds the number of unique paths from the top-left to the bottom-right cell of a grid, where 0 represents an empty cell and ...
code_exercise_27k
25,176
Write a Python function to generate the Fibonacci sequence up to a given limit. The function should return a list of Fibonacci numbers that are less than or equal to the specified limit. The code should start with: ```python from typing import List def generate_fibonacci_sequence(limit: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci_sequence(limit: int) -> List[int]: """ Generates the Fibonacci sequence up to a given limit. Args: limit (int): The upper limit for the Fibonacci sequence. Return...
code_exercise_27k
25,182
Write a Python function to find the length of the longest substring without repeating characters in a given string, considering a constraint on the minimum length of the substring. The function should return the length of the longest valid substring. The code should start with: ```python def longest_substring_length(s...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_substring_length(string: str, min_length: int) -> int: """ Find the length of the longest substring without repeating characters in a given string, considering a constraint on the minimum length of the substring....
code_exercise_27k
25,186
Write a Python function to find the minimum number of edges to remove to make a directed graph a forest. A forest is a collection of trees, where each tree is a connected acyclic graph. The function should take a dictionary representing the directed graph as input and return the minimum number of edges to remove to mak...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def remove_edges_to_make_forest(graph: Dict[str, List[str]]) -> int: """ Finds the minimum number of edges to remove to make a directed graph a forest. Parameters: graph (dict): A dictiona...
code_exercise_27k
25,190
Write a Python function to find the second smallest element in a given list of integers. The function should handle lists with at least two distinct elements and raise a `ValueError` if the list has fewer than two distinct elements. The code should start with: ```python from typing import List def find_second_smalles...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_second_smallest(numbers: List[int]) -> int: """ Finds the second smallest element in a list of integers. Args: numbers (List[int]): A list of integers. Returns: int: Th...
code_exercise_27k
25,204
Write a Python function to find the maximum and minimum values in a given dictionary. The function should return a tuple containing the maximum and minimum values found in the dictionary. If the dictionary is empty, the function should raise a `ValueError` with the message "Input dictionary is empty". The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple def find_max_min_values(data_dict: Dict[str, int]) -> Tuple[int, int]: """ Find the maximum and minimum values in a given dictionary. Args: data_dict (Dict[str, int]): The input dicti...
code_exercise_27k
25,210
Write a Python function to remove empty strings from a given list of strings. The function should return a new list containing only the non-empty strings. The code should start with: ```python from typing import List def remove_empty_strings(strings: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_empty_strings(strings: List[str]) -> List[str]: """ Remove empty strings from a given list of strings. Args: strings (List[str]): A list of strings from which to remove empty stri...
code_exercise_27k
25,213
Write a Python function to find the minimum number of deletions required to convert a given string into a palindrome using dynamic programming with tabulation. The function should take a string as input and return the minimum number of deletions needed. The code should start with: ```python def min_deletions_to_palind...
Here is the Python code to solve the given problem in the markdown block: ```python def min_deletions_to_palindrome(s: str) -> int: """ Returns the minimum number of deletions required to convert a given string into a palindrome. Parameters: s (str): The input string Returns: int: The mini...
code_exercise_27k
25,219
Write a Python function to find the largest sum of any two distinct elements in a given list of integers. The function should handle lists with at least two elements and ensure that the input is a list of integers. The code should start with: ```python from typing import List def find_largest_sum_of_two_elements(numbe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_largest_sum_of_two_elements(numbers: List[int]) -> int: """ Find the largest sum of any two distinct elements in a list of integers. Args: numbers (List[int]): A list of integers. ...
code_exercise_27k
25,226
Write a Python function to find the number of nodes with zero out-degree in a directed graph. The graph is represented as a dictionary where keys are nodes and values are lists of nodes that the key node points to. The function should return the count of nodes that have no outgoing edges. The code should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import defaultdict def count_nodes_with_zero_outdegree(graph: dict) -> int: """ Counts the number of nodes with zero out-degree in a directed graph. Args: graph (dict): A dictionary representing th...
code_exercise_27k
25,228
Write a Python function to find 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 modes, they should be returned in ascending order. The function should raise a `ValueError` if the input list is empty. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_mode(numbers: List[int]) -> List[int]: """ Finds the mode(s) (most frequently occurring value(s)) in a list of numbers. Args: numbers (List[int]): A list of numbers. Returns: ...
code_exercise_27k
25,236
Write a Python function to find the length of the shortest supersequence of two given strings, considering a constraint on the maximum length of the supersequence. The function should return the length of the shortest supersequence if it does not exceed the maximum length, otherwise return -1. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python def shortest_supersequence_length(str1: str, str2: str, max_length: int) -> int: """ Calculate the length of the shortest supersequence of two given strings, considering a maximum length constraint. Args: str1 (str)...
code_exercise_27k
25,241
Write a Python function to find the minimum number of edges to remove to make an undirected graph a forest. A forest is a collection of trees, and a tree is a connected acyclic graph. The function should take the number of vertices `n` and a list of edges `edges` as input and return the minimum number of edges to remov...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def minimum_edges_to_remove(n: int, edges: List[Tuple[int, int]]) -> int: """ Find the minimum number of edges to remove to make an undirected graph a forest. Args: - n (int): Number of v...
code_exercise_27k
25,247
Write a Python function to convert a decimal number to its hexadecimal representation. The function should handle both positive and zero decimal numbers. The hexadecimal representation should be returned as a string in lowercase letters. The code should start with: ```python def decimal_to_hexadecimal(decimal: int) ->...
Here is the Python code to solve the given problem in the markdown block: ```python def decimal_to_hexadecimal(decimal: int) -> str: """ Converts a decimal number to its hexadecimal representation. Args: decimal (int): The decimal number to be converted. Returns: str: The hexadecimal r...
code_exercise_27k
25,251
Write a Python function to convert a hexadecimal number to its decimal equivalent. The function should handle both uppercase and lowercase hexadecimal digits and should raise a `ValueError` if the input contains any invalid characters. The code should start with: ```python def hexadecimal_to_decimal(hex_number: str) -...
Here is the Python code to solve the given problem in the markdown block: ```python def hexadecimal_to_decimal(hex_number: str) -> int: """ Converts a hexadecimal number to its decimal equivalent. Args: hex_number (str): A string representing a hexadecimal number. Returns: int: The dec...
code_exercise_27k
25,270
Write a Python function to count the number of connected components in a directed graph that contain a specific edge. The graph is represented as a dictionary where keys are nodes and values are lists of adjacent nodes. The specific edge is given as a tuple (source, destination). The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def count_connected_components_with_edge(graph: Dict[int, List[int]], target_edge: Tuple[int, int]) -> int: """ Count the number of connected components in a directed graph that contain a sp...
code_exercise_27k
25,283
Write a Python function to calculate the average values of a list of dictionaries. Each dictionary in the list contains numeric values, and the function should return a dictionary with the average value for each key found in the list of dictionaries. The function should handle cases where the input list is empty or any...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def find_average_values(list_of_dicts: List[Dict[str, float]]) -> Dict[str, float]: """ Calculate the average values of a list of dictionaries. Args: list_of_dicts (List[Dict[str, floa...
code_exercise_27k
25,296
Write a Python function to find the longest increasing subsequence in a given array, considering a constraint on the maximum distance between selected elements. The function should return the longest increasing subsequence that satisfies the maximum distance constraint. The code should start with: ```python from typin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_increasing_subsequence_with_max_distance(arr: List[int], max_distance: int) -> List[int]: """ Find the longest increasing subsequence in a given array, considering a constraint on the maximum...
code_exercise_27k
25,340
Write a Python function to find the minimum difference between the sums of two subsets of a given list of non-negative integers. The function should use dynamic programming to achieve this. The code should start with: ```python from typing import List def find_min_diff_subset_sum(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_min_diff_subset_sum(nums: List[int]) -> int: """ Find the minimum difference between the sums of two subsets in a list of non-negative integers. Args: nums (List[int]): A list of no...
code_exercise_27k
25,345
Write a Python function to calculate the product of all digits of a given number. The function should handle both positive and negative integers. If the number is zero, the function should return zero. The code should start with: ```python def digit_product(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def digit_product(n: int) -> int: """ Calculate the product of all the digits in a given number. Args: n (int): The number to calculate the product of the digits for. Returns: int: The product of all th...
code_exercise_27k
25,361
Write a Python function to determine the minimum number of moves required to make all elements in a list of non-negative integers equal, where a move consists of incrementing or decrementing any element by 1. The function should start with: ```python from typing import List def min_moves_to_equal(nums: List[int]) -> i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def min_moves_to_equal(nums: List[int]) -> int: """ Returns the minimum number of moves required to make all elements in a list of non-negative integers equal. Parameters: nums (List[int]): List...
code_exercise_27k
25,362
Write a Python function to count the number of times a given pattern appears in a given string. The function should efficiently handle the search process and return the count of occurrences. The code should start with: ```python def count_pattern_occurrences(string: str, pattern: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def count_pattern_occurrences(string: str, pattern: str) -> int: """ Counts the number of times a given pattern appears in a given string. Args: string (str): The string to search for the pattern. pattern (s...
code_exercise_27k
25,365
Write a Python function to count the number of occurrences of each element in a given list of integers. The function should return a dictionary where the keys are the unique elements from the list, and the values are the counts of how many times each element appears in the list. The code should start with: ```python f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_element_occurrences(lst: List[int]) -> Dict[int, int]: """ Counts the number of occurrences of each element in a list of integers. Args: lst (List[int]): A list of integers. ...
code_exercise_27k
25,368
Write a Python function to find the number of distinct elements in a given list. The function should efficiently handle lists with duplicate elements and return the count of unique elements. The code should start with: ```python from typing import List def count_distinct_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_distinct_elements(lst: List[int]) -> int: """ Counts the number of distinct elements in a given list. Args: lst (List[int]): The input list of integers. Returns: int: ...
code_exercise_27k
25,369
Write a Python function to calculate the maximum number of occupied seats in a row, given an array representing the row of seats, where 1 indicates a person sitting and 0 indicates an empty seat. The constraint is that two people cannot sit adjacent to each other. The function should handle edge cases such as an empty ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_occupied_seats(seats: List[int]) -> int: """ Calculates the maximum number of occupied seats, given an array representing a row of seats where two people cannot sit adjacent to each other. A...
code_exercise_27k
25,370
Write a Python function to find the length of the longest increasing subarray in a given list. The function should return the length of the longest subarray where each element is greater than the previous element. The code should start with: ```python from typing import List def longest_increasing_subarray_length(lst:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_increasing_subarray_length(lst: List[int]) -> int: """ Find the length of the longest increasing subarray in a given list. Args: lst (List[int]): The input list of integers. ...
code_exercise_27k
25,378
Write a Python function to sort a binary list in linear time complexity. The binary list contains only the integers 0 and 1. The function should return the sorted list. The code should start with: ```python from typing import List def sort_binary_list(binary_list: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_binary_list(binary_list: List[int]) -> List[int]: """ Sorts a binary list in linear time complexity. Args: binary_list (List[int]): The binary list to be sorted, containing only 0s ...
code_exercise_27k
25,381
Write a Python function to compute the factorial of a given number using recursion. The function should handle non-negative integers only and raise a `ValueError` for negative inputs. 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: """ Compute the factorial of a given number using recursion. Parameters: n (int): The number for which the factorial is to be computed. Returns: int: The factorial of the given num...
code_exercise_27k
25,383
Write a Python function to find the longest common prefix among a list of strings. The function should return an empty string if there is no common prefix. The code should start with: ```python from typing import List def find_longest_common_prefix(strings: List[str]) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_longest_common_prefix(strings: List[str]) -> str: """ Find the longest common prefix among a list of strings. Args: strings (List[str]): A list of strings to find the longest common...
code_exercise_27k
25,384
Write a Python function to check if a given string is a palindrome, considering only alphanumeric characters and ignoring case sensitivity. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with: ```python def is_palindrome(string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_palindrome(string: str) -> bool: """ Check if a given string is a palindrome, considering only alphanumeric characters and ignoring case sensitivity. Parameters: string (str): The string to check for p...
code_exercise_27k
25,390
Write a Python function to find the largest number in a list using a divide and conquer approach. The function should handle edge cases such as an empty list by raising a `ValueError`. The code should start with: ```python from typing import List def find_largest_number(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_largest_number(arr: List[int]) -> int: """ Finds the largest number in a list using a divide and conquer approach. Args: arr (List[int]): The list of numbers. Returns: ...
code_exercise_27k
25,398
Write a Python function to find the length of the maximum consecutive sequence in a given list of integers. A consecutive sequence is defined as a sequence of numbers where each number is exactly one more than the previous number. The function should efficiently determine the longest sequence of consecutive numbers in ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_consecutive_sequence_length(nums: List[int]) -> int: """ Finds the length of the maximum consecutive sequence in a given list of integers. Args: nums (List[int]): List of integers. ...
code_exercise_27k
25,406
Write a Python function to find the maximum sum of any contiguous subarray in a given list of integers. The function should efficiently handle both positive and negative integers. The code should start with: ```python from typing import List def max_sum_subarray(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_sum_subarray(arr: List[int]) -> int: """ Find the maximum sum of any contiguous subarray in the given list of integers. Args: arr (List[int]): The list of integers. Returns: ...
code_exercise_27k
25,422
Write a Python function to merge two sorted lists into a single sorted list using a divide and conquer approach. The function should efficiently combine the two lists by leveraging the fact that both lists are already sorted. The code should start with: ```python from typing import List def merge_sorted_lists(list1: L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merges two sorted lists into a single sorted list using a divide and conquer approach. Args: list1 (List[int]): T...
code_exercise_27k
25,426
Write a Python function to find the maximum of three numbers without using the built-in `max` function. The function should compare the numbers manually and return the largest one. The code should start with: ```python def find_maximum_manual(a: int, b: int, c: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_maximum_manual(a: int, b: int, c: int) -> int: """ Finds the maximum of three numbers by manual comparison. Parameters: a (int): First number. b (int): Second number. c (int): Third number. ...
code_exercise_27k
25,428
Write a Python function to determine the factors of a given number efficiently. The function should return a list of all factors of the number, including 1 and the number itself. The code should start with: ```python from typing import List def find_factors(number: 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 find_factors(number: int) -> List[int]: """ Find the factors of a given number efficiently. Args: number (int): The number to find factors for. Returns: list: A ...
code_exercise_27k
25,435
Write a Python function to find the k-th largest element in an array. The function should efficiently handle the task for large arrays and return the k-th largest element without sorting the entire array. The code should start with: ```python from typing import List import heapq def find_kth_largest_element(arr: List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import heapq def find_kth_largest_element(arr: List[int], k: int) -> int: """ Find the k-th largest element in an array. Args: arr (List[int]): A list of integers. k (int): The posit...
code_exercise_27k
25,436
Write a Python function to count the number of islands in a given binary matrix. An island is defined as a group of connected 1s (horizontally or vertically) in the matrix. The function should use Depth-First Search (DFS) to explore and mark the islands. The code should start with: ```python from typing import List d...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_islands(matrix: List[List[int]]) -> int: """ Counts the number of islands in a given binary matrix. An island is defined as a group of connected 1s (horizontally or vertically) in the matr...
code_exercise_27k
25,437
Write a Python function to perform a topological sort on a directed acyclic graph (DAG) using depth-first search (DFS). The function should return the topologically sorted order of nodes in the given DAG. The graph is represented as an adjacency list. The code should start with: ```python from typing import Dict, List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def topological_sort(graph: Dict[int, List[int]]) -> List[int]: """ Performs a topological sort on a directed acyclic graph (DAG) using depth-first search algorithm. Args: graph (Dict[...
code_exercise_27k
25,443
Write a Python function to determine if a given number is a prime number. The function should return `True` if the number is prime and `False` otherwise. The function should handle edge cases such as numbers less than 2, which are not prime by definition. The code should start with: ```python def is_prime(n: int) -> b...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determine if a given number is a prime number. Args: n (int): The number to be checked. Returns: bool: True if the number is prime, False otherwise. """ # Numbe...
code_exercise_27k
25,444
Write a Python function to find the shortest path between two nodes in an undirected graph using a breadth-first search (BFS) algorithm. The graph is represented as a dictionary where each key is a node and the corresponding value is a list of adjacent nodes. The function should return a list representing the shortest ...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque from typing import Dict, List, Union def find_shortest_path(graph: Dict[Union[int, str], List[Union[int, str]]], start: Union[int, str], end: Union[int, str]) -> Union[List[Union[int, str]], None]: """...
code_exercise_27k
25,446
Write a Python function to remove all HTML tags from a given string. The function should handle various HTML tags and return the cleaned string without any tags. The code should start with: ```python import re def remove_html_tags(text: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python import re def remove_html_tags(text: str) -> str: """ Remove all HTML tags from the given string. Args: text (str): The input string containing HTML tags. Returns: str: The cleaned string with all HTML...
code_exercise_27k
25,447
Write a Python function to calculate the sum of digits in a number using a recursive approach. The function should take an integer as input and return the sum of its digits. The code should start with: ```python def sum_of_digits_recursive(number: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_digits_recursive(number: int) -> int: """ Calculate the sum of digits in a given number using a recursive approach. Args: number (int): The number for which the sum of digits needs to be calculated. ...
code_exercise_27k
25,454
Write a Python function to detect if a directed graph contains a cycle using Depth-First Search (DFS). The graph is represented as a dictionary where keys are nodes and values are lists of adjacent nodes. The function should return a boolean indicating whether the graph contains a cycle. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def has_cycle_in_graph(graph: Dict[str, List[str]]) -> bool: """ Detects if a directed graph contains a cycle using Depth-First Search (DFS). Args: graph (Dict[str, List[str]]): A dict...
code_exercise_27k
25,463
Write a Python function to count the number of connected components in an undirected graph using a breadth-first search (BFS) algorithm. The graph is represented as a dictionary where keys are nodes and values are lists of neighboring nodes. The code should start with: ```python from collections import deque from typi...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque from typing import Dict, List def count_connected_components(graph: Dict[str, List[str]]) -> int: """ Counts the number of connected components in an undirected graph using BFS. Args: ...
code_exercise_27k
25,466
Write a Python function to find the n-th element in the Fibonacci sequence using an iterative approach. The function should efficiently compute the Fibonacci number by storing only the necessary previous two values, rather than using a list to store the entire sequence. The code should start with: ```python def fibona...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci_iterative(n: int) -> int: """ Find the n-th element in the Fibonacci sequence using an iterative approach. Args: n (int): The index of the desired element in the Fibonacci sequence. Returns: ...
code_exercise_27k
25,469
Write a Python function to perform a binary search on a sorted list using a depth-first search approach. The function should return the index of the target value if it exists in the list, or -1 if it does not. The function should be implemented recursively. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def binary_search_dfs(arr: List[Any], target: Any) -> int: """ Perform a depth-first search based binary search on a sorted list. Args: arr (List[Any]): The sorted list to search in. ...
code_exercise_27k
25,472
Write a Python function to find the length of the longest palindromic substring in a given string. The function should efficiently handle the problem using a dynamic programming approach or an expansion around the center method. The code should start with: ```python def longest_palindromic_substring_length(s: str) -> i...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_palindromic_substring_length(s: str) -> int: """ Find the length of the longest palindromic substring in a given string. Args: s (str): The input string. Returns: int: The length of the long...
code_exercise_27k
25,475
Write a Python function to perform binary search on a sorted array and return the index of the target element if found, otherwise return -1. The function should handle edge cases such as an empty array or a target element that is not present in the array. The code should start with: ```python from typing import List, A...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def binary_search(arr: List[Any], target: Any) -> int: """ Perform binary search on a sorted array to find the index of the target element. Args: arr (List[Any]): A sorted list of eleme...
code_exercise_27k
25,479
Write a Python function to implement the selection sort algorithm on a given list of integers. The function should sort the list in ascending order and return the sorted list. The code should start with: ```python from typing import List def selection_sort(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def selection_sort(arr: List[int]) -> List[int]: """ Sorts a given list of integers in ascending order using the selection sort algorithm. Args: arr (List[int]): The list of integers to be s...
code_exercise_27k
25,482
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 arrays with duplicate elements and return the intersection as a list. The code should start with: ```python from typing import List def fi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_intersection_sorted(arr1: List[int], arr2: List[int]) -> List[int]: """ Find the intersection of two arrays and return the result as a sorted list of unique elements. Args: arr1 (Li...
code_exercise_27k
25,493
Write a Python function to find all the prime numbers in a given range efficiently. The function should use the Sieve of Eratosthenes algorithm to achieve this. The code should start with: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: """ Find all the prime numbers in a given range using the Sieve of Eratosthenes algorithm. Args: start (int): The starting value ...
code_exercise_27k
25,495
Write a Python function to count the number of words in a given string, considering various edge cases such as multiple spaces, leading and trailing spaces, and empty strings. The function should handle these cases gracefully and return the correct word count. The code should start with: ```python def count_words(stri...
Here is the Python code to solve the given problem in the markdown block: ```python def count_words(string: str) -> int: """ Count the number of words in a given string. Args: string (str): The input string to count words from. Returns: int: The number of words in the string. This...
code_exercise_27k
25,498
Write a Python function to implement the merge sort algorithm on a list of integers. The function should recursively divide the list into halves until each sublist contains a single element, and then merge the sublists back together in sorted order. The function should return the sorted list. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the merge sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: List...
code_exercise_27k
25,499
Write a Python function to sort a list of integers using the merge sort algorithm. The function should be able to handle both ascending and descending order based on a provided boolean flag. If the flag is `True`, the list should be sorted in ascending order; if `False`, it should be sorted in descending order. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int], ascending: bool = True) -> List[int]: """ Sorts a list of integers using the merge sort algorithm. Parameters: arr (List[int]): A list of integers to be sorted. ...
code_exercise_27k
25,509
Write a Python function to compute the factorial of a given number using recursion. The function should handle non-negative integers only. If a negative number is provided, the function should raise a `ValueError`. The code should start with: ```python def factorial_recursive(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def factorial_recursive(n: int) -> int: """ Calculate the factorial of a given number using recursion. Args: n (int): The number for which to calculate the factorial. Returns: int: The factorial of the ...
code_exercise_27k
25,517
Write a Python function to find the maximum product of two distinct numbers in a given array of integers. The function should handle both positive and negative integers and ensure that the product is calculated only for distinct numbers. The code should start with: ```python from typing import List def find_max_produc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_product_of_distinct_numbers(arr: List[int]) -> int: """ Finds the maximum product of two distinct numbers in an array of integers. Args: arr: A list of integers. Returns: ...
code_exercise_27k
25,551
Write a Python function to remove duplicates from a given list of integers in-place without using extra space. The function should return the new length of the list after removing duplicates. The code should start with: ```python from typing import List def remove_duplicates_in_place(nums: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_in_place(nums: List[int]) -> int: """ Removes duplicates from a list of integers in-place without using extra space. Args: nums (List[int]): A list of integers with pos...
code_exercise_27k
25,564
Write a Python function to determine if a given graph is bipartite using a breadth-first search (BFS) algorithm. A graph is bipartite if its vertices can be divided into two disjoint sets such that no two graph vertices within the same set are adjacent. The graph is represented as an adjacency matrix, where `graph[i][j...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import deque def is_bipartite_graph(graph: List[List[int]]) -> bool: """ Determine if a given graph is bipartite using breadth-first search. Args: graph: The graph as an adj...
code_exercise_27k
25,568
Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of integers using dynamic programming. The function should return the length of the LIS. The code should start with: ```python from typing import List def longest_increasing_subsequence_length(nums: List[int]) -> in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_increasing_subsequence_length(nums: List[int]) -> int: """ Finds the length of the longest increasing subsequence in a given list using dynamic programming. Args: nums (List[int]...
code_exercise_27k
25,575
Write a Python function to merge overlapping intervals from a given list of tuples representing intervals. Each tuple contains two values representing the start and end of the interval, respectively. The function should return a list of tuples representing the merged intervals. The code should start with: ```python fr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def merge_intervals(intervals: List[Tuple[int, int]]) -> List[Tuple[int, int]]: """ Merges overlapping intervals in a list of tuples representing intervals. Parameters: intervals (lis...
code_exercise_27k
25,601
Write a Python function to calculate the average value of a given list of numbers, rounded to two decimal places. The function should handle an empty list by returning `None`. The code should start with: ```python from typing import List, Optional def calculate_average(numbers: List[float]) -> Optional[float]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def calculate_average(numbers: List[float]) -> Optional[float]: """ Calculates the average value of a list of numbers, rounded to two decimal places. Args: numbers (List[float]): T...
code_exercise_27k
25,603
Write a Python function to merge two sorted lists into a single sorted list. The function should efficiently combine the elements from both lists while maintaining the sorted order. The code should start with: ```python from typing import List def merge_sorted_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 merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merge two sorted lists into a single sorted list. Args: list1 (List[int]): The first sorted list. list2 (...
code_exercise_27k
25,605
Write a Python function to determine if a given directed graph contains a cycle using Breadth-First Search (BFS). The graph is represented as an adjacency list. The function should return `True` if the graph contains a cycle, and `False` otherwise. The code should start with: ```python from typing import Dict, List d...
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 is_cyclic_graph(graph: Dict[int, List[int]]) -> bool: """ Determine if a given directed graph contains a cycle using Breadth-First Search (BFS). Args: ...
code_exercise_27k
25,609
Write a Python function to find the length of the longest common subarray between two given lists. The function should efficiently compute the length using dynamic programming. The code should start with: ```python from typing import List def longest_common_subarray_length(list1: List[int], list2: List[int]) -> int: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_common_subarray_length(list1: List[int], list2: List[int]) -> int: """ Finds the length of the longest common subarray between two lists. Args: list1 (List[int]): The first list....
code_exercise_27k
25,613
Write a Python function to find the nth highest value in a list of integers. The function should efficiently handle the task without using SQL or any external database connections. The code should start with: ```python from typing import List, Optional def get_nth_highest_value(values: List[int], n: int) -> Optional[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def get_nth_highest_value(values: List[int], n: int) -> Optional[int]: """ Finds the nth highest value in a list of integers. Args: values (List[int]): The list of integers from wh...
code_exercise_27k
25,619
Write a Python function to perform a depth-limited breadth-first search (BFS) on a directed graph. The function should return the nodes visited in the order they were encountered, up to the specified depth limit. The graph is represented as a dictionary where keys are nodes and values are lists of nodes representing th...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque from typing import Dict, List, Any def depth_limited_bfs(graph: Dict[Any, List[Any]], start: Any, limit: int) -> List[Any]: """ Perform a depth-limited breadth-first search on a directed graph. ...
code_exercise_27k
25,620
Write a Python function to filter a list of records based on a specific date range. Each record in the list is a dictionary containing a 'date' key with a value of type `datetime.datetime`. The function should return a list of records that fall within the specified date range, inclusive of the start and end dates. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import datetime def filter_records_by_date_range(records: List[Dict[str, datetime.datetime]], start_date: datetime.datetime, end_date: datetime.datetime) -> List[Dict[str, datetime.datetime]]: """ ...
code_exercise_27k
25,634
Write a Python function to calculate the difference between two dates in days, considering leap years and different month lengths. The function should handle date strings in the format 'YYYY-MM-DD'. The code should start with: ```python from datetime import datetime def date_difference_in_days(start_date: str, end_dat...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def date_difference_in_days(start_date: str, end_date: str) -> int: """ Calculates the difference between two dates in days. Args: start_date (str): The starting date in 'YYYY-MM-DD' f...
code_exercise_27k
25,637
Write a Python function to calculate the difference in months between two given dates, considering the day of the month. If the end date's day is less than the start date's day, it should subtract one month from the difference. The function should handle date strings in 'YYYY-MM-DD' format. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def calculate_month_difference_with_day(start_date: str, end_date: str) -> int: """ Calculates the difference in months between two given dates, considering the day of the month. Args: ...
code_exercise_27k
25,638
Write a Python function to find the maximum sum rectangle in a given 2D array of integers. The function should return the maximum sum of any sub-rectangle within the given matrix. The code should start with: ```python from typing import List def find_max_sum_rectangle(matrix: List[List[int]]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_sum_rectangle(matrix: List[List[int]]) -> int: """ Finds the maximum sum rectangle in a given 2D array. Args: matrix (List[List[int]]): A 2D array of integers. Returns: ...
code_exercise_27k
25,647
Write a Python function to implement the Sieve of Eratosthenes algorithm for finding all prime numbers up to a given number `n`. The function should return a list of all prime numbers less than or equal to `n`. The code should start with: ```python from typing import List def sieve_of_eratosthenes(n: int) -> List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sieve_of_eratosthenes(n: int) -> List[int]: """ Implements the Sieve of Eratosthenes algorithm to find all prime numbers up to a given number 'n'. Args: n (int): The upper limit up to wh...
code_exercise_27k
25,664
Write a Python function to filter a list of strings based on whether they start with a specific letter. The function should return a list of strings that match the criteria. The code should start with: ```python from typing import List def filter_strings_starting_with_letter(strings: List[str], letter: str) -> List[st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_strings_starting_with_letter(strings: List[str], letter: str) -> List[str]: """ Filters a list of strings to return only those that start with a specific letter. Args: strings (Li...
code_exercise_27k
25,666
Write a Python function to determine if a given word is a stemming of another word. A word is considered a stemming of another word if it is a prefix of the original word and is shorter than the original word. The function should return `True` if the given word is a stemming of the original word, and `False` otherwise....
Here is the Python code to solve the given problem in the markdown block: ```python def is_stem(word: str, stem: str) -> bool: """ Determines if a given word is a stemming of another word. A word is considered a stemming of another word if it is a prefix of the original word and is shorter than the ori...
code_exercise_27k
25,693
Write a Python function to filter a list of numeric records based on a specified numeric range. The function should return a list of records that fall within the specified range, inclusive of the boundaries. The code should start with: ```python from typing import List, Tuple def filter_records_in_range(records: List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def filter_records_in_range(records: List[Tuple[int]], min_value: int, max_value: int) -> List[Tuple[int]]: """ Filter a list of numeric records based on a specified numeric range. Args: ...
code_exercise_27k
25,694
Write a Python function to find the minimum spanning tree (MST) of a connected undirected graph using a breadth-first search (BFS) algorithm. The graph is represented as a dictionary where each key is a vertex and the corresponding value is a list of its neighboring vertices. The function should return a dictionary rep...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Any from queue import Queue def bfs_minimum_spanning_tree(graph: Dict[Any, List[Any]], start: Any) -> Dict[Any, Any]: """ Find the minimum spanning tree of a connected undirected graph using bread...
code_exercise_27k
25,697
Write a Python function to find the longest palindromic substring in a given string. A palindromic substring is a substring that reads the same forwards and backwards. The function should return the longest such substring found in the input string. The code should start with: ```python def longest_palindromic_substrin...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_palindromic_substring(s: str) -> str: """ Finds the longest palindromic substring in a given string. Args: s (str): The input string. Returns: str: The longest palindromic substring found in...
code_exercise_27k
25,703
Write a Python function to generate an SQL query that updates a specific column in a target table based on values from a corresponding column in a source table. The function should handle the generation of the SQL query string and ensure that none of the input arguments are empty or `None`. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_update_query(source_table: str, target_table: str, source_column: str, target_column: str) -> str: """ Generates an SQL query to update a specific column in a target table based on values from a corresponding column...
code_exercise_27k
25,711
Write a Python function to calculate the difference in minutes between two given timestamps. 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 minutes. The code should start with: ```...
Here is the Python code to solve the given problem in the markdown block: ```python from datetime import datetime def calculate_timestamp_difference(start_time: str, end_time: str) -> int: """ Calculates the difference in minutes between two given timestamps. Args: start_time (str): The starting t...