source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
14,339
Write a Python function to process a list of elements that may contain a mix of different data types, including nested data structures, and return a dictionary where the keys are the unique elements found in the list and the values are lists of indices where these elements appear. The function should handle cases where...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any, Dict def process_list_elements(elements: List[Any]) -> Dict[Any, List[int]]: """ Processes a list of elements, which may contain mixed and nested data types, and returns a dictionary where the ...
python_sharegpt_23k
14,346
Write a Python function to output the lexicographical order of a given array of strings in descending order, removing any duplicate strings. The input array may contain duplicate strings and can have a maximum length of 10^6. The function should be efficient and handle large inputs effectively. 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 lexicographical_order_descending(arr: List[str]) -> List[str]: """ Output the lexicographical order of a given array of strings in descending order, removing any duplicate strings. Args: ...
python_sharegpt_23k
14,347
Write a Python function to filter out odd prime numbers from a given list of integers. The function should use the built-in `filter()` function to achieve this. The code should start with: ```python from typing import List def filter_odd_primes(numbers: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if...
python_sharegpt_23k
14,348
Write a Python function to calculate the maximum profit from buying and selling shares of a company's stock, given that you are only allowed to make a maximum of two transactions. The function should adhere to the following constraints: - You must sell the shares before buying again. - You cannot hold any shares after ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_profit_with_two_transactions(share_prices: List[int]) -> int: """ Calculate the maximum profit from buying and selling shares of a company's stock, given that you are only allowed to make a m...
python_sharegpt_23k
14,352
Write a Python function to count the number of prime numbers in a given array of integers. The function should have a time complexity of O(n^2), where n is the length of the array. The function 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 given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise...
python_sharegpt_23k
14,360
Write a Python function to count the number of occurrences of a given character in a string. The function should be case-sensitive and should count occurrences of the character as part of a larger substring. The function should handle strings with special characters and spaces. The code should start with: ```python def...
Here is the Python code to solve the given problem in the markdown block: ```python def count_character_occurrences(string: str, character: str) -> int: """ Counts the number of occurrences of a given character in a string. Args: string (str): The string in which to count the occurrences. c...
python_sharegpt_23k
14,363
Write a Python function to find the largest sum of any two distinct numbers in a given list of integers. The function should return the largest sum. The code should start with: ```python from typing import List def get_largest_sum(num_list: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_largest_sum(num_list: List[int]) -> int: """ Find the largest sum of any two distinct numbers in the given list. Args: num_list (List[int]): The list of integers from which to find t...
python_sharegpt_23k
14,367
Write a Python function to sum all the values of a given dictionary that are even numbers and greater than 10. If there are no such values in the dictionary, return -1. The code should start with: ```python from typing import Dict def sum_even_greater_than_10(dictionary: Dict[str, int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sum_even_greater_than_10(dictionary: Dict[str, int]) -> int: """ Sum all the values of the given dictionary that are even numbers and greater than 10. If there are no such values, return -1. ...
python_sharegpt_23k
14,374
Write a Python function to implement the bubble sort algorithm to sort an array of numbers in descending order in-place. The input array should contain at most 100,000 elements, and each element will be a positive integer less than or equal to 10^6. The algorithm should have a time complexity of O(n^2), where n is the ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort_descending(arr: List[int]) -> List[int]: """ Sorts the input array of integers in descending order using the bubble sort algorithm. Args: arr (List[int]): The array of intege...
python_sharegpt_23k
14,375
Write a Python function to combine two sorted arrays, `nums1` and `nums2`, into a single sorted array without any duplicate elements. The combined array should be sorted in ascending order and should not contain any repeated elements, even if they are present in the input arrays. The function should have a time complex...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def combine_sorted_arrays(nums1: List[int], nums2: List[int]) -> List[int]: """ Combines two sorted arrays into a single sorted array without any duplicate elements. Args: nums1 (List[int]):...
python_sharegpt_23k
14,381
Write a Python function to calculate the n-th number in the Fibonacci sequence with a time complexity of O(log n) and a space complexity of O(1). The solution must not use recursion or iteration. Instead, use matrix exponentiation to achieve the desired time complexity. 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(n: int) -> int: """ Calculate the n-th Fibonacci number using matrix exponentiation. Args: n (int): The position in the Fibonacci sequence to calculate. Returns: int: The n-th Fibonacci nu...
python_sharegpt_23k
14,382
Write a Python function to calculate the sum of all even numbers in a given list of integers. 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_evens(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_evens(numbers: List[int]) -> int: """ Calculate the sum of all even numbers in the given list. Args: numbers (List[int]): A list of integers. Returns: int: The sum ...
python_sharegpt_23k
14,384
Write a Python function that iterates over a range of numbers from a given start value to an end value (inclusive). The function should return a list of numbers that are divisible by both a specified divisor1 and divisor2. The function should handle cases where the start value is greater than the end value by reversing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_divisible_numbers(start: int, end: int, divisor1: int, divisor2: int) -> List[int]: """ Find and return a list of numbers within the specified range that are divisible by both divisor1 and divis...
python_sharegpt_23k
14,386
Write a Python function to find the missing number in a list of consecutive integers from 1 to n+1, where one number is missing. The function should have a time complexity of O(n) and a space complexity of O(1). The code should start with: ```python from typing import List def find_missing_number(nums: List[int]) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_missing_number(nums: List[int]) -> int: """ Find the missing number in a list of consecutive integers from 1 to n+1. Args: nums (List[int]): A list of integers from 1 to n+1 with on...
python_sharegpt_23k
14,391
Write a Python function to generate a random 5-digit number without using any in-built methods for random number generation, and ensure that the number does not contain any repeating digits. The function should start with: ```python def generate_unique_5_digit_number() -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def generate_unique_5_digit_number() -> str: """ Generates a random 5-digit number without repeating digits. This function uses a deterministic approach to shuffle digits and select the first 5 unique digits. Returns: ...
python_sharegpt_23k
14,395
Write a Python function to find and return a list of all prime numbers within a given range `[start, end]`. 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 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 is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if...
python_sharegpt_23k
14,397
Write a Python function to reverse the characters in a given string without using any built-in reverse functions or extra memory. The function should modify the string in place and return the reversed string. The code should start with: ```python def reverse_string(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the characters in a given string in place without using any built-in reverse functions or extra memory. Args: s (str): The input string to be reversed. Returns: ...
python_sharegpt_23k
14,402
Write a Python function to reverse a given string using a recursive approach. The function should not use any built-in string manipulation functions or data structures, and it should have a time complexity of O(n) and a space complexity of O(1). The function should start with: ```python def reverse_string(s: str) -> st...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses a given string using a recursive approach. Args: s (str): The input string to be reversed. Returns: str: The reversed string. """ def reverse_help...
python_sharegpt_23k
14,405
Write a Python function to return the first `n` elements from a given array without using any built-in Python functions or methods such as `slice` or `append`. Implement your own algorithm to extract the first `n` elements from the array. The function should have a time complexity of O(n) and should not use any additio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_first_n_elements(arr: List[int], n: int) -> List[int]: """ Returns the first n elements from the given array without using built-in functions or methods. Args: arr (List[int]): The i...
python_sharegpt_23k
14,412
Write a Python function to reverse the order of words in a given string while also ensuring that each word is reversed as well, without using any built-in string reversal functions or methods. The function should handle any string input, including strings with multiple spaces, punctuation, and special characters. The ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_and_reverse_words(input_string: str) -> str: """ Reverses the order of words in a given string while also reversing each word. Args: input_string (str): The input string to be processed. Returns: ...
python_sharegpt_23k
14,413
Write a Python function to evaluate a mathematical expression represented as a string. The expression can contain the following operators: addition (`+`), subtraction (`-`), multiplication (`*`), division (`/`), and exponentiation (`^`). The expression may also contain parentheses to indicate the order of operations. T...
Here is the Python code to solve the given problem in the markdown block: ```python def evaluate_expression(expression: str) -> float: """ Evaluate a mathematical expression represented as a string. The expression can contain the following operators: addition (+), subtraction (-), multiplication (*), d...
python_sharegpt_23k
14,414
Write a Python function to remove all duplicate elements from a given list of integers while maintaining the order of the first occurrence of each element. The function should not use any built-in Python functions or methods that directly delete or remove elements from a list, such as `list.clear()` or `del list[:]`. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_ordered(lst: List[int]) -> List[int]: """ Removes duplicate elements from a list while maintaining the order of the first occurrence of each element. Args: lst (List[in...
python_sharegpt_23k
14,419
Write a Python function to convert a non-negative integer to its corresponding binary representation in 16 bits, including leading zeros if necessary. The function should handle numbers up to 65535. The code should start with: ```python def to_16bit_binary(num: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def to_16bit_binary(num: int) -> str: """ Convert a non-negative integer to its corresponding binary representation in 16 bits. Args: num (int): The non-negative integer to convert. Must be in the range [0, 65535]. ...
python_sharegpt_23k
14,420
Write a Python function to remove all blank spaces and punctuation marks from a given string while preserving the original order of characters in the string. The function should handle various types of punctuation and spaces, including spaces, tabs, and newline characters. The code should start with: ```python import r...
Here is the Python code to solve the given problem in the markdown block: ```python import re def clean_string(input_string: str) -> str: """ Removes all blank spaces and punctuation marks from the given string while preserving the original order of characters. Args: input_string (str): The input ...
python_sharegpt_23k
14,433
Write a Python function to check if a specific item exists in a list of lists, considering the list of lists can be very large and memory usage needs to be minimized. The function should return `True` if the item exists in any of the sublists, and `False` otherwise. The code should start with: ```python from typing imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def item_exists_in_list_of_lists(item: Any, my_list: List[List[Any]]) -> bool: """ Check if a specific item exists in a list of lists. Args: item (Any): The item to search for. ...
python_sharegpt_23k
14,438
Write a Python function to clone a nested dictionary, preserving the original structure and values, while also handling nested dictionaries with circular references. The function should return a deep copy of the dictionary, ensuring that any changes to the original dictionary do not affect the cloned dictionary, and vi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict def clone_nested_dict(dictionary: Dict[str, Any], memo: Dict[int, Dict[str, Any]] = None) -> Dict[str, Any]: """ Clones a nested dictionary, preserving the original structure and values, while handl...
python_sharegpt_23k
14,439
Write a Python function to find and return all prime numbers in a given range, along with the sum, average (rounded to two decimal places), and the smallest and largest prime numbers in that range. The function should accept two integers, `start` and `end`, representing the range [start, end]. The function should retur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """...
python_sharegpt_23k
14,446
Write a Python function to display the even numbers between two given integers (inclusive) and calculate the sum of these even numbers. The function should start with: ```python def display_even_numbers_and_sum(start: int, end: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def display_even_numbers_and_sum(start: int, end: int) -> int: """ Display the even numbers between the given start and end (inclusive) and calculate their sum. Args: start (int): The starting integer of the range. ...
python_sharegpt_23k
14,452
Write a Python function to find the most frequent word in a given sentence. The function should not use any built-in functions or libraries for string manipulation or counting occurrences. Additionally, the solution must have a time complexity of O(n) and a space complexity of O(k), where n is the length of the sentenc...
Here is the Python code to solve the given problem in the markdown block: ```python def most_frequent_word(sentence: str) -> str: """ Find the most frequent word in a given sentence. Args: sentence (str): The input sentence from which to find the most frequent word. Returns: str: The m...
python_sharegpt_23k
14,453
Write a Python function to convert a given range of integers into a list of prime numbers, sorted in ascending order. The function should take two integers, `start` and `end`, representing the range, and return a list of prime numbers within that range. The code should start with: ```python from typing import List imp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. ""...
python_sharegpt_23k
14,455
Write a Python function to reverse a given string without using any in-built functions in Python, with a time complexity of O(n) and a space complexity of O(1). The function should start with: ```python def reverse_string(s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the given string without using in-built functions in Python, with a time complexity of O(n) and a space complexity of O(1). Args: s (str): The input string to be r...
python_sharegpt_23k
14,457
Write a Python function to process a list of numbers by removing all negative numbers, doubling the remaining numbers, and sorting the doubled numbers in descending order. The function should start with: ```python from typing import List def process_numbers(numbers: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_numbers(numbers: List[int]) -> List[int]: """ Process a list of numbers by removing all negative numbers, doubling the remaining numbers, and sorting the doubled numbers in descending ord...
python_sharegpt_23k
14,458
Write a Python function to swap the values of two integers using bitwise XOR operations without using a temporary variable. The function should have a time complexity of O(1) and should only use bitwise operators to perform the swap. The code should start with: ```python def swap_values(x: int, y: int) -> tuple: ```
Here is the Python code to solve the given problem in the markdown block: ```python def swap_values(x: int, y: int) -> tuple: """ Swaps the values of two integers using bitwise XOR operations without using a temporary variable. Args: x (int): The first integer. y (int): The second integer. ...
python_sharegpt_23k
14,459
Write a Python function to swap two elements in a given list and return the modified list. The function should handle invalid indices by raising a `ValueError`. The code should start with: ```python from typing import List def swap_elements(lst: List[int], i: int, j: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def swap_elements(lst: List[int], i: int, j: int) -> List[int]: """ Swaps two elements in the given list and returns the modified list. Parameters: lst (List[int]): The list in which the element...
python_sharegpt_23k
14,460
Write a Python function to find the most common positive integer in a list, excluding any duplicates, without using any built-in functions or data structures. The function should return `None` if no positive integers are found. The code should start with: ```python def find_most_common_positive_integer(lst): ```
Here is the Python code to solve the given problem in the markdown block: ```python def find_most_common_positive_integer(lst): """ Find the most common positive integer in a list, excluding any duplicates. Args: lst (list): The list of integers to search. Returns: int or None: The mos...
python_sharegpt_23k
14,467
Write a Python function to find the maximum positive number in a given array and return its index. If there are no positive numbers in the array, the function should return -1. The function should have a time complexity of O(n), where n is the length of the array. If there are multiple positive numbers with the same ma...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_positive_and_index(arr: List[int]) -> int: """ Finds the maximum positive number in the given array and returns its index. If there are no positive numbers in the array, returns -1. ...
python_sharegpt_23k
14,469
Write a Python function to find the maximum value in an array without using any built-in functions, with a time complexity of O(log n), a space complexity of O(1), and without using any loops or recursion. The function should be implemented using a divide-and-conquer approach. The code should start with: ```python fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_value(arr: List[int]) -> int: """ Find the maximum value in an array using a divide-and-conquer approach. Args: arr (List[int]): The array of integers from which to find the max...
python_sharegpt_23k
14,470
Write a Python function to reverse a given string in-place without using any reverse string methods or additional data structures. The input string will contain only alphabetic characters and will have a maximum length of 100 characters. The algorithm must have a time complexity of O(n), where n is the length of the st...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_in_place(s: str) -> str: """ Reverses a given string in-place without using any reverse string methods or additional data structures. Args: s (str): The input string to be reversed. It contains on...
python_sharegpt_23k
14,473
Write a Python function to multiply each element of a given array by a given number. The array contains only positive integers and has a length between 1 and 100. The given number is a positive integer between 1 and 10. The function should return a new array with the multiplied elements. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def multiply_array_elements(array: List[int], number: int) -> List[int]: """ Multiplies each element of the given array by the given number and returns a new array with the results. Args: ar...
python_sharegpt_23k
14,476
Write a Python function to reverse the elements of a given array in-place without using any additional data structures and with a time complexity of O(n) and a space complexity of O(1). The function should start with: ```python from typing import List def reverse_array_in_place(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 reverse_array_in_place(arr: List[int]) -> List[int]: """ Reverses the elements of a given array in-place without using any additional data structures. Args: arr (List[int]): The array of...
python_sharegpt_23k
14,479
Write a Python function to identify common elements between two arrays of integers without using any built-in functions, libraries, or looping constructs such as `for` loops or `while` loops. The function should use a custom algorithm to solve the problem. The code should start with: ```python from typing import List ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(arr: List[int], index: int, occurrences: dict) -> None: """ Helper function to count occurrences of elements in an array using recursion. Args: arr (List[int]): The arr...
python_sharegpt_23k
14,480
Write a Python function to check whether each property in a given object contains a specified value. The object should only contain strings and numbers. The function should return `True` if all properties contain the specified value and are either strings or numbers, otherwise it should return `False`. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python def check_object_properties(obj: dict, value: str) -> bool: """ Checks whether each property in the given object contains the specified value. The object should only contain strings and numbers. Args: obj (dict)...
python_sharegpt_23k
14,481
Write a Python function to calculate the ASCII values of each character in a given input string without using any built-in functions or libraries that directly convert characters to ASCII values. The function should return a list of tuples, where each tuple contains a character and its corresponding ASCII value. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_ascii_values(input_str: str) -> List[Tuple[str, int]]: """ Calculate the ASCII values of each character in the given input string without using built-in functions. Args: ...
python_sharegpt_23k
14,483
Write a Python function to calculate the nth Fibonacci number using matrix exponentiation, ensuring a time complexity of O(log n) and a space complexity of O(1). The function should be recursive and should not use any additional data structures that grow with the input size. The code should start with: ```python def f...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Calculate the nth Fibonacci number using matrix exponentiation. Args: n (int): The index of the Fibonacci number to calculate. Returns: int: The nth Fibonacci number. ...
python_sharegpt_23k
14,494
Write a Python function that prints all the lowercase letters of the alphabet in reverse order, but the loop must terminate if the current letter is a vowel. The function should start with: ```python def print_reverse_alphabet_until_vowel(): ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_reverse_alphabet_until_vowel(): """ Prints all the lowercase letters of the alphabet in reverse order, but terminates if a vowel is encountered. This function starts with the letter 'z' and decrements to 'a', prin...
python_sharegpt_23k
14,496
Write a Python function to find the second largest number from a given list of integers. The function should be optimized to have a time complexity of O(n), where n is the length of the input list. The input list will have a length between 2 and 10^5, and the integers in the list will be between -10^5 and 10^5. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_second_largest(numbers: List[int]) -> int: """ Find the second largest number from a given list of integers. Args: numbers (List[int]): A list of integers. Returns: int...
python_sharegpt_23k
14,502
Write a Python function to implement the bubble sort algorithm for an array of integers. The function should handle the case where the array is already sorted in ascending order and return immediately without any unnecessary iterations. The function should also ensure that the array is sorted in ascending order. The co...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts the given array using the bubble sort algorithm. If the array is already sorted, it returns immediately. Args: arr (List[int]): The ar...
python_sharegpt_23k
14,505
Write a Python function to convert a given number from degrees to radians without using any built-in functions or libraries for the conversion. The function should take an integer representing the number of degrees and return a float representing the corresponding value in radians. The input will be a valid integer bet...
Here is the Python code to solve the given problem in the markdown block: ```python def degrees_to_radians(degrees: int) -> float: """ Convert a given number from degrees to radians. Args: degrees (int): The number of degrees to convert, a valid integer between -360 and 360. Returns: f...
python_sharegpt_23k
14,506
Write a Python function to return either "Nick" or "Jack" based on the value of the input string. The input must be a non-empty string containing only lowercase letters. The output must be a string enclosed in double quotes. The function should handle both uppercase and lowercase inputs. Additionally, the function shou...
Here is the Python code to solve the given problem in the markdown block: ```python def get_name(input_str: str) -> str: """ Returns either "Nick" or "Jack" based on the input string. Args: input_str (str): The input string to be evaluated. It must be a non-empty string containing only lowercase le...
python_sharegpt_23k
14,508
Write a Python function to perform a case-insensitive substring search in a given input string with the following constraints and requirements: - The substring should only be considered a match if it is surrounded by spaces or punctuation marks. - The search should return the index of the first occurrence of the substr...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict import re import string def search_substrings(input_string: str, substrings: List[str]) -> Dict[str, int]: """ Perform a case-insensitive substring search in the input string and count the occurren...
python_sharegpt_23k
14,511
Create a Python function that generates a dictionary containing personal information based on provided inputs. The dictionary should include the keys "name", "age", "location", "occupation", "hobbies", "education", "languages", and "projects". The "education" key should map to a nested dictionary containing "school", "...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def create_personal_info(name: str, age: int, location: str, occupation: str, hobbies: List[str], school: str, degree: str, graduation_year: int, languages: List[str], projects: List[str]) -> Dict: """...
python_sharegpt_23k
14,514
Write a Python function that calculates the sum of all elements in a given array of numbers. However, if any element in the array is a negative number, the function should raise a custom exception with the message "Array contains negative numbers." Additionally, if the sum of all elements in the array exceeds a certain...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_with_exception(arr: List[int], threshold: int) -> int: """ Calculate the sum of all elements in the given array. If any element is negative, raise an exception. If the sum exceeds the given t...
python_sharegpt_23k
14,515
Write a Python function to calculate the sum of each row in a given two-dimensional array, considering only non-negative values. The function should handle negative and zero numbers by ignoring them in the sum calculation. The code should start with: ```python from typing import List def row_sums_non_negative(arr: Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def row_sums_non_negative(arr: List[List[int]]) -> List[int]: """ Calculate the sum of non-negative values for each row in a given two-dimensional array. Args: arr (List[List[int]]): A two-d...
python_sharegpt_23k
14,516
Write a Python function to find the last occurrence of a specific character in a given string without using any built-in string manipulation methods or functions (e.g., `str.index()`, `str.rindex()`, `str.find()`, `str.rfind()`, etc.). The function should use basic string operations and looping constructs to achieve th...
Here is the Python code to solve the given problem in the markdown block: ```python def find_last_occurrence(string: str, character: str) -> int: """ Find the last occurrence of a specific character in a given string. Args: string (str): The string in which to search for the character. char...
python_sharegpt_23k
14,517
Write a Python function to count the number of times the maximum value appears in a given 2D array of numerical values. The function should have a time complexity of O(n^2), where n is the length of the longest row in the 2D array, and should use only constant space complexity, i.e., it should not create any additional...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_max_occurrences(arr: List[List[int]]) -> int: """ Counts the number of times the maximum value appears in a given 2D array of numerical values. Args: arr (List[List[int]]): A 2D ar...
python_sharegpt_23k
14,520
Write a Python function to generate a list of prime numbers within a given range [start, end]. The function should return the list of prime numbers. The code should start with: ```python from typing import List def generate_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ ...
python_sharegpt_23k
14,521
Write a Python function to determine and return the longer string between two given strings without using any conditional statements, loops, or built-in functions that directly determine the length of the strings. The function should have a time complexity of O(1). The code should start with: ```python def longer_stri...
Here is the Python code to solve the given problem in the markdown block: ```python def longer_string(first_str: str, second_str: str) -> str: """ Determines and returns the longer string between two given strings. This function uses the `max()` function with a custom key to compare the sizes of the string...
python_sharegpt_23k
14,522
Write a Python function to create a 3x3 NumPy array of random numbers from -1 to 1, where each element in the array is unique. The function should ensure that the generated array contains exactly 9 unique elements within the specified range. The code should start with: ```python import numpy as np def create_unique_r...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def create_unique_random_matrix() -> np.ndarray: """ Create a 3x3 NumPy array of random numbers from -1 to 1, where each element in the array is unique. Returns: np.ndarray: A 3x3 NumPy array wit...
python_sharegpt_23k
14,525
Write a Python function to filter out prime numbers from a given tuple of integers. The function should return a new tuple containing only the prime numbers from the original tuple. The code should start with: ```python from typing import Tuple def filter_prime_numbers(numbers: Tuple[int]) -> Tuple[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple def is_prime(n: int) -> bool: """ Check if a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwis...
python_sharegpt_23k
14,529
Write a Python function to calculate the sum of all numbers in a given list without using the built-in `sum()` function or any other function that directly calculates the sum of a list. Implement your own algorithm to achieve this. The code should start with: ```python from typing import List def calculate_sum(number...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_sum(numbers: List[int]) -> int: """ Calculate the sum of all numbers in a given list without using the built-in sum() function. Args: numbers (List[int]): A list of integers fo...
python_sharegpt_23k
14,533
Write a Python function to determine if all strings in a given array contain at least two digits and two uppercase letters. The function should return `True` if all strings meet the criteria, otherwise it should return `False`. The code should start with: ```python from typing import List def check_strings(arr: List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_strings(arr: List[str]) -> bool: """ Determines if all strings in the given array contain at least two digits and two uppercase letters. Args: arr (List[str]): The array of strings...
python_sharegpt_23k
14,536
Write a Python function to modify a list of strings according to the following rules: 1. The first character of each string should be converted to uppercase. 2. Any leading or trailing whitespace in each string should be removed. The function should have a time complexity of O(n), where n is the total number of charac...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def modify_strings(strings: List[str]) -> List[str]: """ Modifies a list of strings according to the following rules: 1. The first character of each string should be converted to uppercase. 2. An...
python_sharegpt_23k
14,540
Write a Python function called `is_prime` that takes an integer as input and returns a boolean value indicating whether the input is a prime number or not. A prime number is defined as a number greater than 1 that has no positive divisors other than 1 and itself. Additionally, the function should be able to handle lar...
Here is the Python code to solve the given problem in the markdown block: ```python import math import random def is_prime(n: int) -> bool: """ Determines whether a given integer is a prime number. Args: n (int): The integer to check for primality. Returns: bool: True if the integer i...
python_sharegpt_23k
14,547
Write a Python function to determine if one list `B` is a subset of another list `A`, considering that both lists can contain duplicate elements. A subset is defined as a set where all the elements of `B` are also present in `A`, and `A` may have additional elements. The function should have a time complexity of O(n), ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_subset_with_duplicates(A: List[int], B: List[int]) -> bool: """ Determines if list B is a subset of list A, considering duplicate elements. Args: A (List[int]): The list to check agai...
python_sharegpt_23k
14,549
Write a Python function to swap two numbers using a temporary variable without using any arithmetic or assignment operators, conditional statements, or loops. The function should take two integers as input and return a tuple containing the swapped values. The code should start with: ```python def swap_numbers(a: int, ...
Here is the Python code to solve the given problem in the markdown block: ```python def swap_numbers(a: int, b: int) -> tuple: """ Swaps two numbers using a temporary variable without using arithmetic or assignment operators, conditional statements, or loops. Args: a (int): The first number. ...
python_sharegpt_23k
14,553
Write a Python function that runs a loop exactly 10 times without using any comparison operators (such as "<", ">", "<=", ">="), arithmetic operators (such as "+", "-", "*", "/"), or bitwise operators (such as "&", "|", "^") inside the loop condition. The function should start with: ```python def run_loop_exactly_10_ti...
Here is the Python code to solve the given problem in the markdown block: ```python def run_loop_exactly_10_times(): """ Runs a loop exactly 10 times without using any comparison, arithmetic, or bitwise operators inside the loop condition. This function uses a list with 10 elements to control the loop iter...
python_sharegpt_23k
14,554
Write a Python function to find the k-th smallest element in two sorted arrays, where the elements in the arrays are positive integers and are not allowed to be repeated. The function should efficiently find the k-th smallest element without merging the arrays and using additional space. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_kth_smallest_element(A: List[int], B: List[int], k: int) -> int: """ Find the k-th smallest element in two sorted arrays A and B. Args: A (List[int]): The first sorted array. ...
python_sharegpt_23k
14,556
Write a Python function to sort an array in ascending order using a nested loop without using the `sort()` or `sorted()` function. The function should compare and swap elements to achieve the sorting. The code should start with: ```python from typing import List def sort_array_ascending(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 sort_array_ascending(arr: List[int]) -> List[int]: """ Sorts the given array in ascending order using a nested loop without using the sort() or sorted() function. Args: arr (List[int]): ...
python_sharegpt_23k
14,561
Write a Python function to extract and return the last three words from a given string. The string will always be at least four words long and will not contain any punctuation marks. The code should start with: ```python from typing import List def get_last_three_words(input_string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_last_three_words(input_string: str) -> str: """ Extracts and returns the last three words from a given string. Args: input_string (str): The input string which is at least four words...
python_sharegpt_23k
14,564
Write a Python function to generate a sequence of numbers that are divisible by a given divisor within a specified range. The function should return a list of these numbers. The code should start with: ```python from typing import List def generate_divisible_sequence(start: int, end: int, divisor: int) -> List[int]: ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_divisible_sequence(start: int, end: int, divisor: int) -> List[int]: """ Generate a sequence of numbers that are divisible by a given divisor within a specified range. Args: sta...
python_sharegpt_23k
14,569
Write a Python function to calculate the standard deviation of an array. The function should also calculate the mean of the array within the same function. The mean should be calculated using a separate loop with a maximum time complexity of O(n) and a maximum space complexity of O(1). The function should handle edge c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def calculate_standard_deviation(arr: List[Union[int, float]]) -> Union[float, None]: """ Calculate the standard deviation of an array and also calculate the mean within the same function. Ar...
python_sharegpt_23k
14,584
Write a Python function to sort the key-value pairs of a given dictionary in ascending order of the keys and return a list of tuples where each tuple contains a key-value pair. The function should handle dictionaries with any number of elements. The code should start with: ```python from typing import Dict, List, Tupl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Tuple def sort_dict_by_keys(dictionary: Dict[str, int]) -> List[Tuple[str, int]]: """ Sorts the key-value pairs of a given dictionary in ascending order of the keys and returns a list of tuples. ...
python_sharegpt_23k
14,585
Write a Python function to create a dictionary with five keys, each having a list of values sorted in ascending order. Implement three functions: 1. `lookup_value(dictionary, key, index)`: Efficiently retrieves the value at a given index from the specified list in the dictionary. 2. `retrieve_indices(dictionary, key, v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List, Optional, Union def create_sorted_dictionary() -> Dict[str, List[int]]: """ Create a dictionary with five keys, each having a list of values sorted in ascending order. Returns: Dict[s...
python_sharegpt_23k
14,595
Write a Python function to determine whether two strings are anagrams of each other without using built-in Python functions or libraries for string manipulation and sorting. The function should have a time complexity of O(n), where n is the length of the strings. The function should start with: ```python def are_anagra...
Here is the Python code to solve the given problem in the markdown block: ```python def are_anagrams(str1: str, str2: str) -> bool: """ Determine whether two strings are anagrams of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compare. Ret...
python_sharegpt_23k
14,596
Write a Python function to sort a list of integers in descending order using a modified version of the quicksort algorithm. The modified quicksort algorithm must meet the following requirements: 1. The pivot element must be randomly selected from the input list. 2. The sorting algorithm must be implemented recursively,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def modified_quicksort(arr: List[int], low: int = 0, high: int = None) -> None: """ Sorts a list of integers in descending order using a modified quicksort algorithm. Args: arr...
python_sharegpt_23k
14,597
Write a Python function to find the product of corresponding elements from two lists of numbers. The function should handle lists of different lengths by only calculating the product for the common elements. The function should return a new list containing the products. 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 find_product(list1: List[int], list2: List[int]) -> List[int]: """ Calculate the product of corresponding elements from two lists of numbers. Args: list1 (List[int]): The first list of i...
python_sharegpt_23k
14,602
Write a Python function to generate a list of all prime numbers between 1 and a given integer `n` using the Sieve of Eratosthenes algorithm. The function should handle cases where `n` is not a positive integer by returning an empty list. The code should start with: ```python from typing import List def generate_primes...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes(n: int) -> List[int]: """ Generate a list of all prime numbers between 1 and n using the Sieve of Eratosthenes algorithm. Args: n (int): The upper limit to find prime num...
python_sharegpt_23k
14,604
Write a Python function to identify which strings in a given list are palindromes. The strings may contain punctuation marks and spaces, which should be ignored. The comparison should be case-insensitive. You are not allowed to use any built-in string manipulation or regular expression functions in your solution. The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def identify_palindromes(lst: List[str]) -> List[str]: """ Identify which strings in a given list are palindromes. Args: lst (List[str]): A list of strings to check for palindromes. Ret...
python_sharegpt_23k
14,607
Write a Python function to find the second largest element in a list of integers with a time complexity of O(n), where n is the length of the list. The function should handle lists with duplicate values, negative integers, empty lists, and lists with only one element correctly. If there is no second largest element in ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_second_largest(arr: List[int]) -> Optional[int]: """ Find the second largest element in a list of integers with a time complexity of O(n). Args: arr (List[int]): The list ...
python_sharegpt_23k
14,614
Write a Python function to retrieve the data of the third element in a deeply nested JSON array within a deeply nested JSON object. The JSON object and array structures may vary in each instance. The solution should minimize the amount of memory used and the number of iterations required to access the desired data. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Union def get_third_element_data(json_data: Union[dict, list]) -> Any: """ Retrieve the data of the third element in a deeply nested JSON array within a deeply nested JSON object. Args: json...
python_sharegpt_23k
14,623
Write a Python function to calculate the maximum sum of a subarray of length `k` that consists only of prime numbers from a given array. The function should return 0 if no such subarray exists. The code should start with: ```python from typing import List def max_prime_subarray_sum(array: List[int], k: int) -> int: `...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def max_prime_subarray_sum(array: List[int], k: int) -> int: """ Calculate the maximum sum of a subarray of length k that consists only of prime numbers. Args: array (List[int]): The array o...
python_sharegpt_23k
14,629
Write a Python function to determine if all integers in a given list are divisible by both 7 and 5. The function should return `True` if all integers in the list meet this condition, otherwise it should return `False`. The code should start with: ```python from typing import List def all_divisible_by_7_and_5(lst: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def all_divisible_by_7_and_5(lst: List[int]) -> bool: """ Determines if all integers in the given list are divisible by both 7 and 5. Args: lst (List[int]): A list of integers to check. ...
python_sharegpt_23k
14,632
Write a Python function to remove all occurrences of a specified value from a nested dictionary. The function should also remove any empty dictionaries or lists that are left behind after removing the specified value. The function should have a time complexity of O(n), where n is the total number of elements in the nes...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict, List, Union def remove_value_from_nested_dict(nested_dict: Union[Dict, List], value: Any) -> Union[Dict, List]: """ Remove all occurrences of a specified value from a nested dictionary and clean up...
python_sharegpt_23k
14,633
Write a Python function to validate that a list of dates is in strictly increasing order. Each date should be in the format "yyyy-mm-dd" and must adhere to the Gregorian calendar system, including accurate handling of leap years. Additionally, the function should ensure that all dates fall within the range from January...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def validate_dates_in_order(dates: List[str]) -> bool: """ Validates that a list of dates is in strictly increasing order and adheres to the Gregorian calendar system. Args: dates (List[str]...
python_sharegpt_23k
14,635
Write a Python function to calculate the sum of all even numbers in a given list of integers. 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(lst: 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(lst: List[int]) -> int: """ Calculate the sum of all even numbers in a given list of integers. Args: lst (List[int]): The list of integers to process. Returns:...
python_sharegpt_23k
14,640
Write a Python function to reverse a given string without using any built-in reverse functions, methods, or string manipulation functions. The input string will have at most 1000 characters and will only consist of lowercase letters. You must implement your own algorithm to reverse the string character by character. T...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses a given string without using any built-in reverse functions, methods, or string manipulation functions. Args: s (str): The input string to be reversed. Returns: ...
python_sharegpt_23k
14,646
Write a Python function to generate a spiral order traversal of a given 2D array. The function should handle arrays of any size and can contain negative numbers. The traversal should be done in a single loop, and the function should return a list of elements in spiral order. The code should start with: ```python from ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def spiral_order_traversal(matrix: List[List[int]]) -> List[int]: """ Generate a spiral order traversal of a given 2D array. Args: matrix (List[List[int]]): The input 2D array. Returns:...
python_sharegpt_23k
14,647
Write a Python function to compute the maximum absolute difference between two lists of numbers. The absolute difference between two numbers is the absolute value of their difference. The function should take two lists of integers as input and return the maximum absolute difference found between any pair of numbers fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_max_absolute_difference(list1: List[int], list2: List[int]) -> int: """ Compute the maximum absolute difference between any pair of numbers from two lists. Args: list1 (List[int]...
python_sharegpt_23k
14,649
Write a Python function to convert a given string into an array of words, where each word is a separate element in the array. The solution should be implemented using only a single loop and should have a time complexity of O(n), where n is the length of the input string. The function should handle multiple spaces betwe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def string_to_array(input_string: str) -> List[str]: """ Converts a given string into an array of words, where each word is a separate element in the array. The function handles multiple spaces betwe...
python_sharegpt_23k
14,655
Write a Python function to find the two elements in an array of positive integers that have the largest sum. The array may contain duplicates and can have a maximum length of 10^6. The function should not sort the array or use any built-in sorting functions, and it should have a time complexity of O(n) and a space comp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_largest_sum_pair(arr: List[int]) -> List[int]: """ Find the two elements in an array of positive integers that have the largest sum. Args: arr (List[int]): The array of positive int...
python_sharegpt_23k
14,656
Write a Python function to sort a given list of numbers in descending order using a custom merge sort algorithm. The function should not use any built-in sorting functions or libraries and must have a time complexity of O(n log n) and a space complexity of O(log n). The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_merge_sort(arr: List[int]) -> List[int]: """ Sorts a given list of numbers in descending order using a custom merge sort algorithm. Args: arr (List[int]): The list of numbers to b...
python_sharegpt_23k
14,657
Write a Python function to find the maximum value in each column of a given 2D array and return a new 2D array where each element is replaced by its corresponding column's maximum value. The function should handle edge cases such as an empty input array, non-numeric values, and rows of different lengths. The function ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_column_max(array: List[List[int]]) -> List[List[int]]: """ Find the maximum value in each column of a given 2D array and return a new 2D array where each element is replaced by its correspon...
python_sharegpt_23k
14,658
Write a Python function that takes in a list of integers and returns a set containing only the even numbers. The function should also validate that the input list is not empty and contains only positive integers, otherwise it should raise an exception. Furthermore, the function should be implemented using recursion ins...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def get_even_numbers(lst: List[int]) -> Set[int]: """ Returns a set containing only the even numbers from the input list. Raises an exception if the input list is empty or contains non-positive ...
python_sharegpt_23k
14,661
Write a Python function to determine the order of a given array without using any comparison operators or sorting algorithms. The function should classify the array as "Strictly Increasing", "Strictly Decreasing", "Non-decreasing", "Non-increasing", or "Unordered". The code should start with: ```python from typing impo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def determine_order(arr: List[int]) -> str: """ Determine the order of a given array without using comparison operators or sorting algorithms. Args: arr (List[int]): The array to determine t...
python_sharegpt_23k
14,666
Write a Python function to determine if a given input string is a palindrome, ignoring any punctuation marks, spaces, and special characters. The function should also be case-insensitive. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the input string. The c...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(input_string: str) -> bool: """ Determine if the given input string is a palindrome, ignoring punctuation, spaces, and special characters. The function is case-insensitive. Args: input_string (...
python_sharegpt_23k
14,667
Write a Python function to remove duplicates from a list of strings, ignoring case sensitivity and leading/trailing whitespace, and also removing any strings that are palindromes. The function should return a list of unique strings that meet these criteria. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_and_palindromes(strings: List[str]) -> List[str]: """ Removes duplicates and palindromes from a list of strings, ignoring case sensitivity and leading/trailing whitespace. Args...
python_sharegpt_23k
14,668
Write a Python function to generate the Fibonacci sequence up to a given number `n`. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. The function should have a time complexity of O(n) and a space complexity of O(1). The code should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci_sequence(n: int) -> List[int]: """ Generate the Fibonacci sequence up to a given number n. The Fibonacci sequence is a series of numbers in which each number is the sum of the...
python_sharegpt_23k
14,676
Write a Python function to remove all empty strings from a given list of strings. The function should not use any built-in array manipulation methods such as `filter`, `reduce`, or `map`. The function should have a time complexity of O(n), where n is the length of the input list. The code should start with: ```python ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_empty_strings(arr: List[str]) -> List[str]: """ Removes all empty strings from the given list of strings. Args: arr (List[str]): The list of strings from which to remove empty str...
python_sharegpt_23k
14,682
Write a Python function to count the frequency of occurrence of each vowel (both uppercase and lowercase) in a given string. The function should be efficient and handle strings with a maximum length of 10^6 characters. You are not allowed to use any built-in functions or libraries for string manipulation or regular exp...
Here is the Python code to solve the given problem in the markdown block: ```python def count_vowel_frequencies(string: str) -> dict: """ Counts the frequency of occurrence of each vowel (both uppercase and lowercase) in the given string. Args: string (str): The input string to analyze. Return...
python_sharegpt_23k
14,684
Write a Python function to generate a Fibonacci sequence up to `n` elements using an iterative approach with dynamic programming. The function should not use recursion or the golden ratio formula. The code should start with: ```python from typing import List def generate_fibonacci_sequence(n: 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(n: int) -> List[int]: """ Generate a Fibonacci sequence up to n elements using an iterative approach with dynamic programming. Args: n (int): The number of el...