Skip to content
🤔prompts chat🧠
🔍
question:def is_mountain_sequence(sequence): Determines if the given sequence is a mountain sequence. A sequence is considered as a mountain sequence if it strictly increases and then strictly decreases. >>> is_mountain_sequence([1, 2, 3, 4, 3, 2]) == True >>> is_mountain_sequence([1, 2, 2, 1]) == False >>> is_mountain_sequence([3, 5, 2, 1, 4]) == False >>> is_mountain_sequence([1, 3, 2]) == True >>> is_mountain_sequence([2, 1]) == False >>> is_mountain_sequence([5, 5, 5, 5]) == False >>> is_mountain_sequence([1, 2]) == False def solve_test_cases(T, test_cases): Processes multiple test cases to determine if each sequence is a mountain sequence. T: Number of test cases test_cases: List of tuples, where each tuple contains (N, sequence) >>> solve_test_cases(3, [(6, [1, 2, 3, 4, 3, 2]), (4, [1, 2, 2, 1]), (5, [3, 5, 2, 1, 4])]) == ["YES", "NO", "NO"] >>> solve_test_cases(2, [(3, [1, 3, 2]), (2, [2, 1])]) == ["YES", "NO"]

answer:def is_mountain_sequence(sequence): Determines if the given sequence is a mountain sequence. A sequence is considered as a mountain sequence if it strictly increases and then strictly decreases. n = len(sequence) if n < 3: return False i = 1 # Check increasing part while i < n and sequence[i] > sequence[i-1]: i += 1 # Peak can't be first or last element if i == 1 or i == n: return False # Check decreasing part while i < n and sequence[i] < sequence[i-1]: i += 1 return i == n def solve_test_cases(T, test_cases): Processes multiple test cases to determine if each sequence is a mountain sequence. T: Number of test cases test_cases: List of tuples, where each tuple contains (N, sequence) results = [] for N, sequence in test_cases: if is_mountain_sequence(sequence): results.append("YES") else: results.append("NO") return results

question:def pair_vehicle(name: str) -> str: Returns the vehicle associated with the given name. If the name is not recognized, returns "Unknown person". >>> pair_vehicle("Bruce") "Bruce-Wayne's Batmobile" >>> pair_vehicle("Tony") "Tony-Iron Man's Armor" >>> pair_vehicle("Peter") "Peter-Spidey Buggy" >>> pair_vehicle("Clark") "Clark-Kryptonian Ship" >>> pair_vehicle("Diana") "Diana-Invisible Jet" >>> pair_vehicle("Barry") "Barry-Speedster's Car" >>> pair_vehicle("Steve") "Unknown person" >>> pair_vehicle("Natasha") "Unknown person" >>> pair_vehicle("") "Unknown person" >>> pair_vehicle("Bruce-Wayne") "Unknown person"

answer:def pair_vehicle(name): Returns the vehicle associated with the given name. If the name is not recognized, returns "Unknown person". vehicles = { "Bruce": "Bruce-Wayne's Batmobile", "Tony": "Tony-Iron Man's Armor", "Peter": "Peter-Spidey Buggy", "Clark": "Clark-Kryptonian Ship", "Diana": "Diana-Invisible Jet", "Barry": "Barry-Speedster's Car" } return vehicles.get(name, "Unknown person")

question:def max_distinct_subarray(arr: List[int]) -> int: Returns the length of the longest subarray that contains all distinct integers. >>> max_distinct_subarray([5, 1, 3, 5, 2, 3, 4, 1]) 5 >>> max_distinct_subarray([4, 4, 4, 4]) 1 >>> max_distinct_subarray([1, 2, 3, 4, 5]) 5 >>> max_distinct_subarray([2, 2, 2, 3, 4, 5, 2, 3]) 4 >>> max_distinct_subarray([]) 0 >>> max_distinct_subarray([1]) 1

answer:def max_distinct_subarray(arr): Returns the length of the longest subarray that contains all distinct integers. n = len(arr) if n == 0: return 0 max_len = 0 start = 0 seen = {} for end in range(n): if arr[end] in seen: start = max(start, seen[arr[end]] + 1) seen[arr[end]] = end max_len = max(max_len, end - start + 1) return max_len

question:def findPair(nums: List[int], target: int) -> Optional[Tuple[int, int]]: Given an array of integers and a target integer, returns the indices of two integers in the array whose sum equals the target. If no such pair exists, returns None. >>> findPair([2, 7, 11, 15], 9) (0, 1) >>> findPair([3, 2, 4], 6) (1, 2) >>> findPair([3, 3], 6) (0, 1) >>> findPair([1, 2, 3], 7) None from solution import findPair def test_find_pair_example_1(): assert findPair([2, 7, 11, 15], 9) == (0, 1) def test_find_pair_example_2(): assert findPair([3, 2, 4], 6) == (1, 2) def test_find_pair_example_3(): assert findPair([3, 3], 6) == (0, 1) def test_find_pair_no_pair_found(): assert findPair([1, 2, 3], 7) == None def test_find_pair_with_zero(): assert findPair([0, 4, 3, 0], 0) == (0, 3) def test_find_pair_with_negatives(): assert findPair([-1, -2, -3, -4, -5], -8) == (2, 4) def test_find_pair_large_numbers(): assert findPair([1000000, 500000, -1500000, 100000, 400000], -1000000) == (1, 2) def test_find_pair_repeated_elements(): assert findPair([1, 2, 1], 2) == (0, 2)

answer:def findPair(nums, target): Given an array of integers and a target integer, returns the indices of two integers in the array whose sum equals the target. If no such pair exists, returns None. lookup = {} for i, num in enumerate(nums): if target - num in lookup: return (lookup[target - num], i) lookup[num] = i return None

Released under the chat License.

has loaded