Skip to content
🤔prompts chat🧠
🔍
question:Create a function which takes a list of integers as input, and returns the max value of the list. [7, 9, 5]

answer:def get_max(int_list): return max(int_list)

question:mplement a function that takes a 2D matrix and rotates the matrix 90 degrees clockwise. [[1,2,3], [4,5,6], [7,8,9]]

answer:def rotate_2d_matrix(matrix): n = len(matrix[0]) m = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): m[i][j] = matrix[n-j-1][i] return m

question:Write a function that takes a string and returns the number of substrings with at least k different characters "abacdc

answer:def num_distinct_substrings(S, k): n = len(S) distinct_substrings = set() for i in range(n): for j in range(i+k, n+1): distinct_substring = "".join(sorted(list(set(S[i:j])))) distinct_substrings.add(distinct_substring) return len(distinct_substrings)

question:Write a function that takes a list of integers and returns the shortest continuous increasing subarray in the list. [2,3,3,4,3,4,5,6,7]

answer:def shortest_increasing_subarray(nums): res, curr = float('inf'), 0 for i in range(len(nums)-1): if nums[i] < nums[i+1]: curr += 1 else: res = min(res, curr) curr = 0 return max(res, curr) + 1

Released under the MIT License.

has loaded