source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
11,222
Write a Python function to find the index of the element that occurs only once in a given array. The function must not use any built-in functions or libraries to solve the problem. Instead, it should use only basic data structures and algorithms provided by the programming language. The function should start with: ```p...
Here is the Python code to solve the given problem in the markdown block: ```python def find_single_occurrence_index(arr: list) -> int: """ Find the index of the element that occurs only once in the given array. Args: arr (list): The array in which to find the single occurrence element. Return...
python_sharegpt_23k
11,225
Write a Python function to find the pair of elements in an array that have the greatest difference, where the larger element is located at an index greater than the smaller element. The array can contain duplicates, and the solution must handle them correctly. If multiple pairs have the same maximum difference, return ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_difference_pair(arr: List[int]) -> List[int]: """ Find the pair of elements in the array that have the greatest difference, where the larger element is located at an index greater than t...
python_sharegpt_23k
11,226
Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should be case-insensitive and should ignore spaces and punctuation marks. The function should return `True` if the strings are a...
Here is the Python code to solve the given problem in the markdown block: ```python import re def are_anagrams(str1: str, str2: str) -> bool: """ Determine if two given strings are anagrams of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compa...
python_sharegpt_23k
11,235
Write a Python function that takes a list of integers as input and returns a new list containing the elements of the input list in reverse order, but excluding any occurrences of the number 3. The function should start with: ```python from typing import List def reverse_and_exclude_three(numbers: List[int]) -> List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_and_exclude_three(numbers: List[int]) -> List[int]: """ Returns a new list containing the elements of the input list in reverse order, excluding any occurrences of the number 3. Args: ...
python_sharegpt_23k
11,236
Write a Python function to randomly shuffle a list of integers such that the smallest value is always at the beginning of the shuffled list, without using any built-in shuffling functions or external libraries. The function should ensure that the rest of the list is shuffled randomly. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def shuffle_with_smallest_at_beginning(lst: List[int]) -> List[int]: """ Shuffles a list of integers such that the smallest value is always at the beginning, and the rest of the list is...
python_sharegpt_23k
11,238
Write a Python function to find the biggest number in a given list of integers. The function should handle the case when the list is empty and return `None` in that case. The function should also handle the case when the list contains duplicate numbers and return any one of the duplicate numbers if it is the biggest. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_biggest_number(my_list: List[int]) -> Optional[int]: """ Find the biggest number in a given list of integers. Args: my_list (List[int]): The list of integers from which to...
python_sharegpt_23k
11,239
Write a Python function to determine if a given number is a prime number efficiently with a time complexity of O(sqrt(n)). The function should handle edge cases such as numbers less than or equal to 1, and should be optimized to skip even numbers after checking for divisibility by 2. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime_number(n: int) -> bool: """ Determines if a given number is a prime number efficiently with a time complexity of O(sqrt(n)). Args: n (int): The number to check for primality. Returns: ...
python_sharegpt_23k
11,242
Write a Python function to filter elements from a given array based on a specified criteria using a single loop. The function should return an array of the filtered elements. The input array will always have at least 10 elements. The code should start with: ```python from typing import List, Callable def filter_eleme...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def filter_elements_single_loop(array: List[int], criteria: Callable[[int], bool]) -> List[int]: """ Filters elements from the given array based on the specified criteria using a single loop. ...
python_sharegpt_23k
11,247
Write a Python function to filter elements in an array based on a given criteria and return the remaining elements in descending order. The function should take two parameters: the array `lst` and the criteria function `criteria`. The criteria function should be a callable that returns `True` if the element meets the c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Callable def filter_and_sort_array(lst: List[int], criteria: Callable[[int], bool]) -> List[int]: """ Filters elements in the input array based on the given criteria and returns the remaining elements i...
python_sharegpt_23k
11,249
Write a Python function to create a dictionary that contains the names of the months as keys and the average high and low temperatures for each month as values for a specific city. The function should accept a list of tuples where each tuple contains the month name, average high temperature, and average low temperature...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def build_temperature_dict(temperatures: List[Tuple[str, int, int]]) -> Dict[str, Dict[str, int]]: """ Build a dictionary that contains the names of the months as keys and the average high a...
python_sharegpt_23k
11,254
Write a Python function to remove all duplicate elements from a given NumPy array and return the resulting array sorted in ascending order. The input array will only contain positive integers. The code should start with: ```python import numpy as np def remove_duplicates_and_sort(arr: np.ndarray) -> np.ndarray: ```
Here is the Python code to solve the given problem in the markdown block: : ```python import numpy as np def remove_duplicates_and_sort(arr: np.ndarray) -> np.ndarray: """ Remove all duplicate elements from a given NumPy array and return the resulting array sorted in ascending order. Args: arr (np...
python_sharegpt_23k
11,255
Write a Python function to calculate the number of times a given number appears in a nested list and remove all occurrences of that number from the list. The function should return the count of the number and modify the original nested list in place. The code should start with: ```python from typing import List, Union...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def count_and_remove_number(nested_list: List[Union[int, List]], num: int) -> int: """ Counts the number of times a given number appears in a nested list and removes all occurrences of that number...
python_sharegpt_23k
11,260
Write a Python function to add two non-negative integers using only bitwise operators and without using the addition operator. The function should handle the addition of any two non-negative integers within the range of typical integer representation in Python. The code should start with: ```python def add_numbers_bit...
Here is the Python code to solve the given problem in the markdown block: ```python def add_numbers_bitwise(x: int, y: int) -> int: """ Adds two non-negative integers using only bitwise operators. Args: x (int): The first non-negative integer. y (int): The second non-negative integer. ...
python_sharegpt_23k
11,267
Write a Python function to calculate the average of a list of numbers, ensuring that the list contains at least 5 elements. Additionally, sort the list in ascending order before calculating the average. The function should return the sorted list and the calculated average. The code should start with: ```python from ty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_average_with_sort(arr: List[int]) -> Tuple[List[int], float]: """ Calculate the average of a list of numbers, ensuring the list contains at least 5 elements. The list is sorted i...
python_sharegpt_23k
11,269
Write a Python function to remove duplicates from a given array and return the array in ascending order, but also ensure that the resulting array contains only prime numbers. The function should start with: ```python from typing import List def remove_duplicates_and_filter_primes(arr: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def 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, Fal...
python_sharegpt_23k
11,270
Write a Python function to calculate the average grade from a list of grades with a time complexity of O(1). The function should handle edge cases such as an empty list and negative grades by raising appropriate exceptions. The function should not use any built-in functions or libraries for calculating the average. The...
Here is the Python code to solve the given problem in the markdown block: ```python def avg_grade(grades: list) -> float: """ Calculate the average grade from a list of grades with a time complexity of O(1). Args: grades (list): A list of integers representing grades, ranging from 0 to 100. Re...
python_sharegpt_23k
11,281
Write a Python function to generate a dictionary mapping each unique Keytype with a description of "What it is". The Keytype can be any string consisting of letters, numbers, and special characters. The function should validate that each Keytype is unique before creating the dictionary. If any Keytype is not unique, th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def generate_unique_dict(keytypes: List[str]) -> Dict[str, str]: """ Generates a dictionary mapping each unique Keytype with the description "What it is". Args: keytypes (List[str]): A...
python_sharegpt_23k
11,283
Write a Python function to reverse the input string `s` without using any built-in functions or methods that directly reverse the string. The solution should have a time complexity of O(n) and reverse the string in-place without using any additional data structures. The solution should correctly handle Unicode characte...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the input string `s` in-place without using any built-in functions or methods that directly reverse the string. Args: s (str): The input string to be reversed. Re...
python_sharegpt_23k
11,286
Write a Python function to implement the bubble sort algorithm to sort an array of integers in ascending order. The input array should contain at least 10 integers and at most 1000 integers. Each integer in the array should be within the range of -1000000 to 1000000. You cannot use any built-in sorting functions or lib...
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 an array of integers in ascending order using the bubble sort algorithm. Args: arr (List[int]): The array of integers to be sorted. Th...
python_sharegpt_23k
11,287
Implement a function to search for a given key in a Binary Search Tree (BST) and return the number of comparisons made during the search. The function should have a time complexity of O(log n) in the average case, where n is the number of nodes in the BST, and a space complexity of O(1). The BST can have up to 10^6 nod...
Here is the Python code to solve the given problem in the markdown block: ```python class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def search_bst_with_comparisons(root: TreeNode, key: int) -> int: """ Searches for...
python_sharegpt_23k
11,288
Write a Python function to multiply two integers without using the multiplication operator (`*`), any built-in multiplication functions, loops, or recursion. The function should handle positive and negative integers correctly. The code should start with: ```python def multiply_without_operator(x: int, y: int) -> int: ...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_without_operator(x: int, y: int) -> int: """ Multiplies two integers without using the multiplication operator (*), built-in multiplication functions, loops, or recursion. Args: x (int): The first i...
python_sharegpt_23k
11,292
Write a Python function to calculate the number of trailing zeros in the factorial of a given positive integer `n`. The function should efficiently compute the result without calculating the factorial directly, as the factorial of large numbers can be extremely large and impractical to handle. The code should start wi...
Here is the Python code to solve the given problem in the markdown block: ```python def count_trailing_zeros(n: int) -> int: """ Calculate the number of trailing zeros in the factorial of a given positive integer n. Args: n (int): The positive integer for which to calculate the factorial's trailing...
python_sharegpt_23k
11,293
Write a Python function to loop through a given dictionary and print the values multiplied by 2, with the keys sorted in descending order. The function should support three different methods of achieving this: 1. Using the `sorted()` function to sort the dictionary keys in descending order. 2. Using the `items()` metho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def print_values_multiplied_by_2(my_dict: Dict[str, int]) -> None: """ Prints the values of the dictionary multiplied by 2, with the keys sorted in descending order. Args: my_dict (Dict[str,...
python_sharegpt_23k
11,294
Write a Python function that processes a list of integers in reverse order and prints out each number that is divisible by 2, along with its square. The function should start with: ```python from typing import List def process_numbers_reverse(numbers: List[int]) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_numbers_reverse(numbers: List[int]) -> None: """ Processes a list of integers in reverse order and prints out each number that is divisible by 2, along with its square. Args: ...
python_sharegpt_23k
11,297
Write a Python function to determine if a given string is a palindrome, considering only alphanumeric characters and ignoring case and special characters. The function should handle strings with multiple words and spaces. The code should start with: ```python def is_palindrome(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determine if a given string is a palindrome, considering only alphanumeric characters and ignoring case and special characters. Args: s (str): The input string to check for pal...
python_sharegpt_23k
11,300
Write a Python function to sort an array of integers in descending order using the bubble sort algorithm. The function should repeatedly swap adjacent elements if they are in the wrong order until the array is fully sorted. The code should start with: ```python from typing import List def bubble_sort_descending(arr: L...
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 an array of integers in descending order using the bubble sort algorithm. The bubble sort algorithm works by repeatedly swapping ad...
python_sharegpt_23k
11,316
Write a Python function to compute the maximum value of a given list of integers without using the built-in `max()` function. The list may contain negative numbers. The function should handle an empty list by returning `None`. The code should start with: ```python from typing import List, Optional def find_max_value(...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_max_value(lst: List[int]) -> Optional[int]: """ Compute the maximum value of a given list of integers without using the built-in max() function. Args: lst (List[int]): The...
python_sharegpt_23k
11,317
Write a Python function to calculate the sum of all prime numbers in a given list of integers. The function should return the sum of the prime numbers. The code should start with: ```python from typing import List def sum_of_primes(numbers: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
python_sharegpt_23k
11,318
Write a Python function to validate a given email address according to the following criteria: 1. The email address must start with a string of alphanumeric characters. 2. The string must be followed by the "@" symbol. 3. After the "@" symbol, there must be a domain name consisting of a string of alphanumeric characte...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_email(email: str) -> bool: """ Validates an email address according to the specified criteria. Args: email (str): The email address to validate. Returns: bool: True if the email ...
python_sharegpt_23k
11,321
Write a Python function to construct an array of N elements from a given string, where N is the length of the string. Each element in the array should only contain unique characters. If any character is repeated in the string, it should be ignored and not included in the array. The function should have a time complexit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def construct_array_of_unique_chars(string: str) -> List[str]: """ Constructs an array of unique characters from the given string. Args: string (str): The input string from which to extract ...
python_sharegpt_23k
11,325
Write a Python function to perform a binary search on a sorted list of integers to determine if a given number is present in the list. The function should return `True` if the number is found, and `False` otherwise. The function must ensure a time complexity of O(log n), where n is the length of the list. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(sorted_list: List[int], target: int) -> bool: """ Perform a binary search on a sorted list to determine if a given number is present. Args: sorted_list (List[int]): A sorte...
python_sharegpt_23k
11,328
Write a Python function to determine if a given number is prime or not. The function must be implemented from scratch without using any built-in functions or libraries for prime checking. Additionally, the function should have a time complexity of O(sqrt(n)), where n is the given number. The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n: int) -> bool: """ Determines if a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ # Numb...
python_sharegpt_23k
11,335
Write a Python function to calculate the product of two integers using bitwise operations and/or bitwise shifting. The function should handle both positive and negative integers without using the multiplication operator (`*`) or any built-in multiplication functions. The code should start with: ```python def bitwise_pr...
Here is the Python code to solve the given problem in the markdown block: ```python def bitwise_product(num1: int, num2: int) -> int: """ Calculate the product of two integers using bitwise operations and bitwise shifting. Args: num1 (int): The first integer. num2 (int): The second integer....
python_sharegpt_23k
11,338
Write a Python function to generate a series of Fibonacci numbers up to a specified number of items and calculate the sum of all the prime Fibonacci numbers in the series. The function should return both the Fibonacci series and the sum of the prime Fibonacci numbers. The code should start with: ```python from typing ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def generate_fibonacci_with_prime_sum(n: int) -> Tuple[List[int], int]: """ Generates a series of Fibonacci numbers up to a specified number of items and calculates the sum of all prime Fibonacci ...
python_sharegpt_23k
11,339
Write a Python function to filter out and return a list of numbers that are both prime and greater than 10 from a given list of positive integers. Additionally, the function should print the total count of such numbers. The code should start with: ```python from typing import List def filter_primes_greater_than_10(num...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(number: int) -> bool: """ Helper function to check if a number is prime. Args: number (int): The number to check for primality. Returns: bool: True if the number is...
python_sharegpt_23k
11,340
Write a Python function to access the value of the key 'name' in a nested dictionary structure under specific conditions. The dictionary is stored inside a list, and the list is nested within another dictionary. The value of the key 'name' should only be accessible if the length of the list is greater than 2 and the va...
Here is the Python code to solve the given problem in the markdown block: ```python def get_name_value(data: dict) -> str: """ Access the value of the key 'name' in a nested dictionary structure under specific conditions. Args: data (dict): The outer dictionary containing the nested list and other ...
python_sharegpt_23k
11,341
Write a Python function to convert feet to meters, ensuring that the function only accepts floating-point numbers as input and returns the result with a precision of up to 5 decimal places. Additionally, handle the case where the input is a negative number by converting it to a positive value before performing the conv...
Here is the Python code to solve the given problem in the markdown block: ```python def feet_to_meters(feet: float) -> float: """ Converts feet to meters, ensuring the input is a floating-point number and the result is rounded to 5 decimal places. If the input is negative, it is converted to a positive valu...
python_sharegpt_23k
11,345
Write a Python function to concatenate two arrays and ensure that the resulting array does not contain any duplicate elements. Additionally, the function should remove any negative numbers from the resulting array. The code should start with: ```python from typing import List def concat_and_clean_arrays(arr1: List[int...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concat_and_clean_arrays(arr1: List[int], arr2: List[int]) -> List[int]: """ Concatenates two arrays and ensures the resulting array does not contain any duplicate elements. Additionally, removes ...
python_sharegpt_23k
11,346
Write a Python function to find the common elements between two lists, ensuring that the function handles cases where the input lists may contain duplicates. The function should return a list of unique common elements, even if they occur multiple times in the input lists. The function should be efficient, with a time c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find the common elements between two lists, ensuring that the function handles cases where the input lists may contain dupli...
python_sharegpt_23k
11,348
Write a Python function to preprocess a list of dictionaries representing people's information. Each dictionary contains the following attributes: "name" (string), "age" (integer), "gender" (string), "city" (string), and "hobbies" (list of strings). The function should transform this list into a new list of dictionarie...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def preprocess_data(input_data: List[Dict[str, any]]) -> List[Dict[str, any]]: """ Preprocesses a list of dictionaries representing people's information. Args: input_data (List[Dict[st...
python_sharegpt_23k
11,355
Write a Python function to reverse a given string using a while loop, without using any built-in string reversal functions or additional variables to store the reversed string. The function should directly print each character of the reversed string. The code should start with: ```python def reverse_string(s: str) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> None: """ Reverses the given string and prints each character of the reversed string. Args: s (str): The input string to be reversed. Returns: None: The function does not r...
python_sharegpt_23k
11,357
Write a Python function to initialize a jagged 2D array with zeros using a single loop and without using any built-in functions or methods. The array should be jagged, meaning each inner array can have a different length. The function should take two parameters: `rows`, which is the number of rows in the jagged array, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def initialize_jagged_array(rows: int, cols: List[int]) -> List[List[int]]: """ Initializes a jagged 2D array with zeros using a single loop. Args: rows (int): The number of rows in the jagg...
python_sharegpt_23k
11,361
Write a Python function to check if one string (`s2`) is a substring of another string (`s1`). The function should return `True` if `s2` is a substring of `s1`, and `False` otherwise. The function should handle strings with lengths up to \(10^5\) efficiently. The code should start with: ```python def is_substring(s1: ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_substring(s1: str, s2: str) -> bool: """ Check if the string `s2` is a substring of the string `s1`. Args: s1 (str): The main string in which to search for the substring. s2 (str): The substring to se...
python_sharegpt_23k
11,367
Write a Python function to find and return a list of all prime numbers between a given range `[start, end]`, excluding any specific number `skip`. The function should efficiently determine if a number is prime and skip the specified number. The code should start with: ```python from typing import List def find_primes...
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: """ Helper function to determine if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is p...
python_sharegpt_23k
11,375
Create a custom encryption algorithm to encode a string of characters. The encryption algorithm should not rely on any built-in encryption functions or libraries. Additionally, the algorithm should include a decryption function to decode the encoded string back to its original form. The encryption algorithm should us...
Here is the Python code to solve the given problem in the markdown block: ```python import random def encrypt(message: str) -> tuple: """ Encrypts a given message using a modified Caesar cipher. Args: message (str): The message to be encrypted. Returns: tuple: A tuple containing the e...
python_sharegpt_23k
11,378
Write a Python function to implement an efficient sorting algorithm that sorts an array of integers in ascending order. The algorithm should have a time complexity of O(nlogn) and should not use any built-in sorting functions or libraries. Additionally, the algorithm should not use recursion and should not use any addi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def efficient_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using an iterative merge sort algorithm. Args: arr (List[int]): The array of integers to be...
python_sharegpt_23k
11,379
Write a Python function to separate and print even and odd numbers from a given list, and calculate and print the sum of all even numbers and the sum of all odd numbers. The function should return a tuple containing the sum of even numbers and the sum of odd numbers. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def separate_and_sum_numbers(numbers: List[int]) -> Tuple[int, int]: """ Separates and prints even and odd numbers from the given list, and calculates the sum of all even numbers and the sum of al...
python_sharegpt_23k
11,385
Write a Python function to return the key of the maximum value in a given dictionary. You are not allowed to use the built-in `max()` function or any other sorting functions. The function should handle an empty dictionary by returning `None`. The code should start with: ```python from typing import Dict, Optional def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Optional def get_max_key(dictionary: Dict[str, int]) -> Optional[str]: """ Returns the key of the maximum value in the given dictionary. Args: dictionary (Dict[str, int]): The dictionary fr...
python_sharegpt_23k
11,386
Write a Python function to find the largest and smallest numbers in a given list of integers without using any built-in functions or libraries. The function should run in O(n) time complexity, where n is the size of the input list. It should handle edge cases such as an empty list or a list with only one element, and c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_largest_and_smallest(numbers: List[int]) -> Tuple[int, int]: """ Find the largest and smallest numbers in a list of integers without using built-in functions or libraries. Args: ...
python_sharegpt_23k
11,387
Write a Python function to generate the first 100 prime numbers and return them in reverse order. The function should be efficient and should not print the primes directly. The code should start with: ```python from typing import List def generate_first_100_primes_reversed() -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n <...
python_sharegpt_23k
11,391
Write a Python function to create a new list `squared` that contains the squares of all the elements in the list `nums`. However, you are not allowed to use any built-in functions or operators for exponentiation (such as `**` or `pow()`). The input list `nums` can contain both positive and negative integers. Additional...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def square_list(nums: List[int]) -> List[int]: """ Returns a new list containing the squares of all elements in the input list 'nums'. The squaring is done without using any built-in exponentiation f...
python_sharegpt_23k
11,399
Write a Python function to calculate the sum of all numbers in a given array, count the number of positive and negative numbers, and handle large input arrays efficiently. The function should return the total sum, the count of positive numbers, and the count of negative numbers. 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, Tuple def calculate_sum_and_counts(arr: List[int]) -> Tuple[int, int, int]: """ Calculate the sum of all numbers in the given array, and count the number of positive and negative numbers. Args: ...
python_sharegpt_23k
11,400
Write a Python function to calculate the binomial coefficient for two non-negative integers, `n` and `r`, where `n` is greater than or equal to `r`. The function should return the binomial coefficient as an integer. The binomial coefficient, often denoted as "n choose r" or \( C(n, r) \), is the number of ways to choos...
Here is the Python code to solve the given problem in the markdown block: ```python def binomial_coefficient(n: int, r: int) -> int: """ Calculate the binomial coefficient for two non-negative integers n and r, where n is greater than or equal to r. Args: n (int): The total number of items. ...
python_sharegpt_23k
11,403
Write a Python function to encrypt a given message using the Caesar cipher with a specified key. The Caesar cipher shifts each letter in the message by a certain number of positions down the alphabet. Non-alphabet characters should remain unchanged. The encryption should be case-sensitive, meaning that uppercase and lo...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(message: str, key: int) -> str: """ Encrypts a message using the Caesar cipher with a specified key. The Caesar cipher shifts each letter in the message by a certain number of positions down the alphabet. ...
python_sharegpt_23k
11,404
Write a Python function to convert an infix expression to postfix notation (also known as Reverse Polish Notation) using the Shunting Yard algorithm. The function should handle basic arithmetic operators (`+`, `-`, `*`, `/`) and parentheses (`(` and `)`). 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 infix_to_postfix(expression: str) -> str: """ Convert an infix expression to postfix notation using the Shunting Yard algorithm. Args: expression (str): The infix expression to be conver...
python_sharegpt_23k
11,405
Write a Python function to convert a given number from base 10 to any base between 2 and 16 without using built-in functions or libraries for conversion. The function should have a time complexity of O(log n), where n is the given number. The code should start with: ```python def convert_to_base(n: int, base: int) -> ...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_base(n: int, base: int) -> str: """ Converts a given number from base 10 to any base between 2 and 16. Args: n (int): The number in base 10 to be converted. base (int): The target base for con...
python_sharegpt_23k
11,409
Write a Python function to sort an array in ascending order using the Merge Sort algorithm. The function should not use any built-in sorting functions or methods, and the time complexity must be O(n log n). The array can contain both positive and negative integers. 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 merge_sort(arr: List[int]) -> List[int]: """ Sorts an array in ascending order using the Merge Sort algorithm. Args: arr (List[int]): The array to be sorted. Returns: List[i...
python_sharegpt_23k
11,410
Write a Python function to find the maximum and minimum values in an array of integers without using any conditional statements or comparison operators. The function should only use basic arithmetic operations and logical operators. You cannot use any built-in functions or methods that directly solve the problem. The ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_max_min(arr: List[int]) -> Tuple[int, int]: """ Find the maximum and minimum values in an array of integers without using any conditional statements or comparison operators. Only basi...
python_sharegpt_23k
11,413
Write a Python function to search for all occurrences of a target element in a sorted array with possible duplicate elements. The function should return a list of indices of all occurrences of the target element. If the target element is not found, the function should return an empty list. The algorithm should have a t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def search_all_occurrences(arr: List[int], target: int) -> List[int]: """ Searches for all occurrences of a target element in a sorted array and returns a list of their indices. Args: arr (L...
python_sharegpt_23k
11,415
Write a Python function to delete a node at a given position in a doubly linked list. The positions are counted from 1 onwards. The function should handle invalid positions by returning the original list without any modification. The doubly linked list is represented by a `Node` class with `data`, `prev`, and `next` at...
Here is the Python code to solve the given problem in the markdown block: ```python class Node: def __init__(self, data=None): self.data = data self.prev = None self.next = None def delete_node(head: Node, position: int) -> Node: """ Deletes a node at the specified position in a dou...
python_sharegpt_23k
11,420
Write a Python function to convert each character in a given string to uppercase without using any built-in functions or libraries for string manipulation. The function should handle all characters, including spaces, punctuation marks, and digits, by leaving them unchanged. The function should start with: ```python def...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_to_uppercase(string: str) -> str: """ Converts each character in the input string to uppercase without using any built-in functions or libraries. Args: string (str): The input string to be converted. ...
python_sharegpt_23k
11,428
Write a Python function to implement the Bubble Sort algorithm. The function should take a list of integers as input and return a new list that is sorted in ascending order. The original list should not be modified. The function should have a time complexity of O(n^2), where n is the length of the list. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(lst: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the Bubble Sort algorithm. Args: lst (List[int]): The list of integers to be sorted. ...
python_sharegpt_23k
11,433
Write a Python function to compute the average of the positive integers greater than 5 from a given list of numbers. The average should be rounded to the nearest whole number. The list may contain duplicate numbers and may have a length of up to 1000. The code should start with: ```python from typing import List def ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_average_of_positive_integers_greater_than_5(numbers: List[int]) -> int: """ Computes the average of the positive integers greater than 5 from a given list of numbers. The average is round...
python_sharegpt_23k
11,436
Write a Python function to generate an array of size `n` filled with unique random integers between a specified range `[min_val, max_val]`. The function should ensure that no two elements in the array are the same. The code should start with: ```python from typing import List import random def generate_unique_random_a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_random_array(n: int, min_val: int, max_val: int) -> List[int]: """ Generates an array of size `n` filled with unique random integers between `min_val` and `max_val`. ...
python_sharegpt_23k
11,437
Write a Python function to generate a list of size `n` filled with unique random integers between a specified range `[min_val, max_val]`, ensuring that no two numbers are the same. The function should handle cases where `n` is greater than the range of possible values by raising a `ValueError`. The code should start w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_unique_random_list(n: int, min_val: int, max_val: int) -> List[int]: """ Generate a list of size `n` filled with unique random integers between `min_val` and `max_val`. Ar...
python_sharegpt_23k
11,440
Write a Python function to calculate the sum of all positive elements in a given list or array. The data must not contain any negative numbers, and the length of the data must be between 3 and 10 (inclusive). If the data does not meet these criteria, the function should return an appropriate error message. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, List, Tuple def sum_positive_elements(data: Union[List[int], Tuple[int]]) -> Union[int, str]: """ Calculate the sum of all positive elements in a given list or tuple. Args: data (Union[Lis...
python_sharegpt_23k
11,446
Write a Python function to find the indices of two elements in a list that sum to a given target number. If there are multiple pairs that sum to the target, return the indices of the pair with the smallest difference between the two elements. If no such pair exists, return an empty list. The function should have a time...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_two_sum_indices(nums: List[int], target: int) -> List[int]: """ Finds the indices of two elements in the list that sum to the given target number. If there are multiple pairs that sum to the...
python_sharegpt_23k
11,456
Write a Python function to add two non-negative integers without using any arithmetic operators or built-in functions specifically designed for addition. The function should use bitwise operations to simulate the addition process. The code should start with: ```python def add_two_numbers(a: int, b: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def add_two_numbers(a: int, b: int) -> int: """ Adds two non-negative integers using bitwise operations without using any arithmetic operators. Args: a (int): The first non-negative integer. b (int): The sec...
python_sharegpt_23k
11,457
Write a Python function to remove all duplicates from a given list while maintaining the original order of elements. The function should take a list as input and return a new list with all duplicate elements removed. The code should start with: ```python from typing import List def remove_duplicates_keep_order(lst: Li...
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def remove_duplicates_keep_order(lst: List[int]) -> List[int]: """ Removes all duplicates from the given list while maintaining the original order of elements. Args: lst (List[int]): The i...
python_sharegpt_23k
11,462
Write a Python function to sort a given array of numbers in descending order using the quicksort algorithm. The function should be able to handle arrays with duplicate numbers, negative numbers, and floating-point numbers. The function should not use built-in sorting functions. 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 sort_descending(arr: List[float]) -> List[float]: """ Sorts the given array of numbers in descending order using the quicksort algorithm. Args: arr (List[float]): The array of numbers to...
python_sharegpt_23k
11,463
Write a Python function to produce a copy of a given array while ensuring that the copy is sorted in ascending order and contains only unique elements. The function must be implemented without using any built-in sorting or duplicate removal functions or methods. The code should start with: ```python from typing import ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def copy_sorted_unique(arr: List[int]) -> List[int]: """ Produces a copy of the given array with unique elements sorted in ascending order. Args: arr (List[int]): The input array to be copie...
python_sharegpt_23k
11,467
Write a Python function to extract values from a list of dictionaries while adhering to the following requirements: 1. Exclude specific keys from being included in the extracted values. 2. Handle nested dictionaries by extracting values from all levels of nesting. 3. Perform a configurable operation on each extracted v...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict, Any, Callable def extract_values(dictionaries: List[Dict[str, Any]], excluded_keys: List[str] = None, operation: Callable[[Any], Any] = None) -> List[Any]: """ Extracts values from a list of dicti...
python_sharegpt_23k
11,475
Write a Python function to reverse the order of words in a given sentence while preserving the order of characters within each word. The function should handle sentences with special characters, punctuation, and multiple whitespaces. It should also remove any leading or trailing whitespaces from the input sentence. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_sentence_words(sentence: str) -> str: """ Reverses the order of words in a given sentence while preserving the order of characters within each word. Args: sentence (str): The input sentence to be reverse...
python_sharegpt_23k
11,476
Write a Python function that takes four arguments: a number `num`, a string `string`, a boolean value `boolean`, and an array `arr`. The function should return an array containing the string repeated the specified number of times, but only if the boolean value is `True`. If the boolean value is `False`, the function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def repeat_string(num: int, string: str, boolean: bool, arr: List[str]) -> List[str]: """ Returns an array containing the string repeated the specified number of times, but only if the boolean value ...
python_sharegpt_23k
11,479
Write a Python function to convert a string containing numbers in scientific notation to a list of integers. The input string may contain multiple numbers separated by commas. The function should handle both positive and negative exponents in scientific notation, as well as decimal numbers. 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 convert_scientific_notation_to_integers(input_string: str) -> List[int]: """ Converts a string containing numbers in scientific notation to a list of integers. Args: input_string (str): ...
python_sharegpt_23k
11,480
Write a Python function to compute the mean of a set of numbers provided as a string with each number separated by a comma. The function should convert the string input into a list of integers, compute the mean, and return the result. The code should start with: ```python from typing import List def compute_mean_from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def compute_mean_from_string(input_string: str) -> float: """ Computes the mean of a set of numbers provided as a string with each number separated by a comma. Args: input_string (str): A st...
python_sharegpt_23k
11,488
Write a Python function that calculates the square of a given positive integer using only bitwise operations. The function should not use the multiplication operator, looping constructs, or conditional statements. The function should only use bitwise operations such as bit shifting, bitwise AND, bitwise OR, and bitwise...
Here is the Python code to solve the given problem in the markdown block: ```python def square_using_bitwise(num: int) -> int: """ Calculate the square of a given positive integer using only bitwise operations. Args: num (int): The positive integer to be squared. Returns: int: The squa...
python_sharegpt_23k
11,493
Write a Python function to determine if a given year is both a leap year and a prime number. The function should return a tuple of two boolean values: the first indicating whether the year is a leap year, and the second indicating whether the year is a prime number. The function should not use any built-in libraries or...
Here is the Python code to solve the given problem in the markdown block: ```python def is_leap_year_and_prime(year: int) -> tuple[bool, bool]: """ Determine if a given year is both a leap year and a prime number. Args: year (int): The year to check. Returns: tuple[bool, bool]: A tuple...
python_sharegpt_23k
11,495
Write a Python function to add the next prime number to a given list of integers. The function should start with: ```python from typing import List def add_next_prime_to_list(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(n: int) -> bool: """ Checks if a 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
11,496
Write a Python function to process a given sentence by separating the words, counting the occurrences of each word, and displaying the words in descending order of their frequency. The function should not use any built-in functions or libraries for counting occurrences. The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def process_sentence(sentence: str) -> Dict[str, int]: """ Processes a given sentence to separate words, count their occurrences, and return them in descending order of frequency. Args: ...
python_sharegpt_23k
11,498
Write a Python function to determine if a given string is a valid hexadecimal number. The string must meet the following criteria: 1. It must start with the prefix '0x'. 2. The characters following the '0x' prefix must be valid hexadecimal digits, which include the digits '0'-'9' and the letters 'A'-'F' (case insensiti...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_hexadecimal(string: str) -> bool: """ Determines if a given string is a valid hexadecimal number. A valid hexadecimal number must start with the prefix '0x' and contain only valid hexadecimal digits, which ...
python_sharegpt_23k
11,504
Write a Python function to create an array of integers ranging from `-50` to `50` and return a list of only the even numbers in reverse order. The function should start with: ```python from typing import List def get_even_numbers_reverse_order() -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_even_numbers_reverse_order() -> List[int]: """ Create an array of integers ranging from -50 to 50 and return a list of only the even numbers in reverse order. Returns: List[int]: A l...
python_sharegpt_23k
11,505
Write a Python function to filter a given list of strings by a specified character, but only include strings that contain the character at both the beginning and the end of the string. The function should return the filtered list in reverse order. The code should start with: ```python from typing import List def filte...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_strings_by_character(my_list: List[str], character: str) -> List[str]: """ Filters a list of strings to include only those that start and end with the specified character, and returns the ...
python_sharegpt_23k
11,507
Write a Python function to extract and validate personal information from a given string. The string is formatted as "Lastname, Firstname - Age - Address", where the address is in the format "Street, City, State, Country". The function should return a dictionary with the extracted information if the input is valid; oth...
Here is the Python code to solve the given problem in the markdown block: ```python import re def extract_personal_info(string: str) -> dict: """ Extracts and validates personal information from a given string. The string should be formatted as "Lastname, Firstname - Age - Address", where the address ...
python_sharegpt_23k
11,509
Write a Python function to generate a sequence of prime numbers starting from 11 and incrementing by 10 for each subsequent number, ensuring each number is a prime and less than or equal to 100. The function should return a list of these prime numbers. The code should start with: ```python from typing import List def...
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: """ Helper function to check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime...
python_sharegpt_23k
11,510
Write a Python function to count the number of occurrences of a specific value in a given array efficiently. The array can be very large, with a size up to \(10^9\), and the elements can be any integer from \(-10^9\) to \(10^9\). The specific value to count can also be any integer from \(-10^9\) to \(10^9\). The soluti...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(array: List[int], specific_value: int) -> int: """ Counts the number of occurrences of a specific value in a given array. Args: array (List[int]): The array in which to...
python_sharegpt_23k
11,518
Write a Python function to generate an array of strings, where each string consists of only lowercase alphabets (a-z) and does not contain any repeating characters. The length of each string should be between 10 to 15 characters. The function should ensure that the time complexity does not exceed O(n), where n is the l...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random import string def generate_unique_char_strings(n: int) -> List[str]: """ Generates an array of strings, where each string consists of only lowercase alphabets (a-z) and does not contain any...
python_sharegpt_23k
11,519
Write a Python function to reorder an array of numbers in descending order. The array may contain duplicates. Implement a function called `reorder_array` that takes in an array of integers and returns the array with the numbers rearranged in descending order. The function should have a time complexity of O(n log n), wh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reorder_array(arr: List[int]) -> List[int]: """ Reorders the given array of integers in descending order using QuickSort. Args: arr (List[int]): The array of integers to be reordered. ...
python_sharegpt_23k
11,520
Write a Python function to check if a given string is a valid IP address without using any built-in IP address validation functions or regular expressions. The function should have a time complexity of O(1) and a space complexity of O(1). The code should start with: ```python def is_valid_ip_address(ip_address: str) -...
Here is the Python code to solve the given problem in the markdown block: ```python def is_valid_ip_address(ip_address: str) -> bool: """ Check if a given string is a valid IP address. Args: ip_address (str): The IP address string to validate. Returns: bool: True if the IP address is v...
python_sharegpt_23k
11,522
Write a Python function to sort a given list of integers in ascending order using the Merge Sort algorithm, which has a time complexity of O(n log n). The function should not use any built-in sorting functions or libraries. The code should start with: ```python from typing import List def merge_sort(arr: List[int]) ->...
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 given list of integers in ascending order using the Merge Sort algorithm. Args: arr (List[int]): The list of integers to be sorted. ...
python_sharegpt_23k
11,524
Write a Python function called `swap_values` that takes in two variables as arguments and swaps their values without using any arithmetic operators or temporary variables. The function should be efficient and in-place, meaning it should directly modify the values of the input variables. The function should return the u...
Here is the Python code to solve the given problem in the markdown block: ```python def swap_values(a: int, b: int) -> tuple: """ Swaps the values of two integers using bitwise XOR operations without using any arithmetic operators or temporary variables. Args: a (int): The first integer. b ...
python_sharegpt_23k
11,525
Write a Python function to generate a random string of a given length without using any built-in functions or libraries. The string should consist of printable ASCII characters (ASCII values 32 to 126). The function should be implemented using a custom random number generator that mimics the behavior of Python's `rando...
Here is the Python code to solve the given problem in the markdown block: ```python def generate_random_string(length: int) -> str: """ Generates a random string of a given length using a custom random number generator. The string consists of printable ASCII characters (ASCII values 32 to 126). Args: ...
python_sharegpt_23k
11,526
Write a Python function that takes an array of integers as input and returns the sum of all unique positive integers in the array. The function should ignore any negative integers and any duplicates in the array. The code should start with: ```python from typing import List def sum_of_unique_positive_integers(arr: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_unique_positive_integers(arr: List[int]) -> int: """ Calculate the sum of all unique positive integers in the given array. Args: arr (List[int]): The array of integers from which ...
python_sharegpt_23k
11,530
Write a Python function to generate a list of prime numbers between a given range `[start, end]`. The function should return a list of all prime numbers within this range. The code should start with: ```python from typing import List def generate_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Helper function to check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime...
python_sharegpt_23k
11,535
Write a Python function to compute the factorial of a given non-negative integer using an iterative approach without recursion. The function should handle edge cases such as computing the factorial of 0. The code should start with: ```python def compute_factorial(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def compute_factorial(n: int) -> int: """ Compute the factorial of a given non-negative integer using an iterative approach. Args: n (int): The non-negative integer for which to compute the factorial. Returns: ...
python_sharegpt_23k
11,537
Write a Python function to reverse the order of words in a given sentence while maintaining the order of characters within each word. Additionally, remove any leading or trailing white spaces in the sentence. The function should start with: ```python def reverse_sentence(sentence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_sentence(sentence: str) -> str: """ Reverses the order of words in a given sentence while maintaining the order of characters within each word. Additionally, removes any leading or trailing white spaces in the se...
python_sharegpt_23k
11,538
Implement an efficient stable sorting algorithm in Python that sorts a list of integers in ascending order. The algorithm should have a time complexity of O(n log n) and should not use the built-in `sort()` function or any other pre-existing sorting function. Additionally, write a function called `check_sorted` that ta...
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 in ascending order using the Merge Sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Re...
python_sharegpt_23k
11,539
Write a Python function to extract and return a set of unique prime numbers from a given list of integers. The function should handle both positive and negative integers, but only positive integers can be prime numbers. The code should start with: ```python from typing import List, Set def get_unique_primes(numbers: L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Set def get_unique_primes(numbers: List[int]) -> Set[int]: """ Extracts and returns a set of unique prime numbers from a given list of integers. Args: numbers (List[int]): A list of integer...
python_sharegpt_23k
11,540
Write a Python function to convert a decimal number to its binary representation using only bitwise operations. The input number will be in the range of 0 to 10^9. The function should handle large numbers efficiently and return the binary representation as a string. The code should start with: ```python def decimal_to...
Here is the Python code to solve the given problem in the markdown block: ```python def decimal_to_binary(decimal: int) -> str: """ Convert a decimal number to its binary representation using only bitwise operations. Args: decimal (int): The decimal number to convert, in the range of 0 to 10^9. ...
python_sharegpt_23k
11,551
Write a Python function to find both the maximum and the second maximum elements from a given list of integers. The function must not use any built-in functions or libraries for finding the maximum element. The list may contain both positive and negative integers, and may have duplicate values. The function should be e...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_max_and_second_max(nums: List[int]) -> Tuple[int, int]: """ Finds the maximum and second maximum elements from a given list of integers. Args: nums (List[int]): The list of i...