target
stringlengths
29
3.65k
data_source
stringclasses
12 values
prompt
listlengths
1
1
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
from typing import List def min_cost_traversal(grid: List[List[int]]) -> int: n = len(grid) if n == 0: return 0 m = len(grid[0]) if m == 0: return 0 dp = [[0 for _ in range(m)] for _ in range(n)] dp[0][0] = grid[0][0] # Fill the first row for j in range(1, m): ...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\n**Problem Statement**:\nYou are given a grid of size `n x m` where each cell contains a non-negative integer representing the cost to move across that cell. Your task is to find the minimum cost to traverse from the top-left cell `(0, 0)` to the bottom-...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5700, "level": 1, "question": "### Coding Assessment Question\n\n**Problem Statement**:\nYou are given a grid of size `n x m` where each cell contains a non-negative integer representing the cost to move across that cell. Your task is to find the minimum cost to traverse from the to...
def max_non_overlapping_intervals(intervals): """ Find the largest subset of non-overlapping intervals. Parameters ---------- intervals : List[Tuple[int, int]] List of intervals where each interval is a tuple (start, end). Returns ------- int The maximum number of non-o...
simplelr_Package
[ { "content": "Question:\n## Largest Non-Intersecting Subset of Intervals\n\nYou are given a series of intervals, each represented as a tuple of start and end times. Your goal is to find the largest subset of non-overlapping intervals. Two intervals overlap if they share any common time point. \n\nImplement the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5701, "level": 1, "question": "## Largest Non-Intersecting Subset of Intervals\n\nYou are given a series of intervals, each represented as a tuple of start and end times. Your goal is to find the largest subset of non-overlapping intervals. Two intervals overlap if they share any co...
def type_with_max_sum(items): sums = {} for type_i, value_i in items: if type_i in sums: sums[type_i] += value_i else: sums[type_i] = value_i # Convert to list and sort by descending sum, then ascending type sorted_types = sorted(sums.items(), key=lambda x: (-x[1]...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a 2D integer array `items` where each `items[i] = [type_i, value_i]` represents an item with a type and its associated value. Your task is to determine the maximum sum of values among all possible types. Return the type that has the maximum sum of associated values. If the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5702, "level": 1, "question": "You are given a 2D integer array `items` where each `items[i] = [type_i, value_i]` represents an item with a type and its associated value. Your task is to determine the maximum sum of values among all possible types. Return the type that has the maxim...
def are_anagrams(word1, word2): # Preprocess each word by removing non-letters and converting to lowercase cleaned1 = [c.lower() for c in word1 if c.isalpha()] cleaned2 = [c.lower() for c in word2 if c.isalpha()] # Check if the sorted cleaned words are equal return sorted(cleaned1) == sorted(cl...
simplelr_Apps
[ { "content": "Question:\nBrief\n=====\nYou need to write a function that will check if two words are anagrams. An anagram is a word formed by rearranging the letters of another word, using all the original letters exactly once. The function should return True if the words are anagrams, and False otherwise.\n\nT...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5703, "level": 1, "question": "Brief\n=====\nYou need to write a function that will check if two words are anagrams. An anagram is a word formed by rearranging the letters of another word, using all the original letters exactly once. The function should return True if the words are ...
from typing import List def longest_continuous_sequence(nums: List[int]) -> int: if not nums: return 0 num_set = set(nums) max_length = 0 for num in num_set: if (num - 1) not in num_set: current_length = 1 current = num while (c...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\n#### Objective\nCreate a function to find the longest sequence of continuous integers in an array.\n\n#### Function Signature\n```python\ndef longest_continuous_sequence(nums: List[int]) -> int:\n pass\n```\n\n#### Input\n* `nums`: A list of integers...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5704, "level": 1, "question": "### Coding Assessment Question\n\n#### Objective\nCreate a function to find the longest sequence of continuous integers in an array.\n\n#### Function Signature\n```python\ndef longest_continuous_sequence(nums: List[int]) -> int:\n pass\n```\n\n#### ...
def sum_dig_pow(low: int, high: int) -> list: result = [] for n in range(low, high + 1): digits = str(n) total = 0 for i in range(len(digits)): digit = int(digits[i]) power = i + 1 total += digit ** power if total == n: result.appen...
simplelr_Data_Structure
[ { "content": "Question:\nYou are tasked with writing a function that finds all numbers within a specified range that exhibit a unique property: when each digit of the number is raised to the power corresponding to its position (starting from 1), the sum of these powered digits equals the original number. For ex...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5705, "level": 1, "question": "You are tasked with writing a function that finds all numbers within a specified range that exhibit a unique property: when each digit of the number is raised to the power corresponding to its position (starting from 1), the sum of these powered digits...
def max_subarray_sum(nums): if not nums: return 0 max_current = max_global = nums[0] for num in nums[1:]: max_current = max(num, max_current + num) max_global = max(max_global, max_current) return max_global
simplelr_Filter
[ { "content": "Question:\nYou are given a list of integers. Write a Python function to find the maximum sum of a contiguous subarray within the list. For example, given the list [-2, 1, -3, 4, -1, 2, 1, -5, 4], the maximum sum of a contiguous subarray is 6 (the subarray [4, -1, 2, 1]). Use the Kadane's algorithm...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5706, "level": 1, "question": "You are given a list of integers. Write a Python function to find the maximum sum of a contiguous subarray within the list. For example, given the list [-2, 1, -3, 4, -1, 2, 1, -5, 4], the maximum sum of a contiguous subarray is 6 (the subarray [4, -1,...
def make_dict(keys, values): return dict(zip(keys, values)) keys = [1, 2, 3] values = ['a', 'b', 'c'] result = make_dict(keys, values) print(result)
simplelr_Filter
[ { "content": "Question:\ndef make_dict(keys, values):\n return dict(zip(keys, values))\n\nkeys = [1, 2, 3]\nvalues = ['a', 'b', 'c']\n\nresult = make_dict(keys, values)\nprint(result)\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5707, "level": 1, "question": "def make_dict(keys, values):\n return dict(zip(keys, values))\n\nkeys = [1, 2, 3]\nvalues = ['a', 'b', 'c']\n\nresult = make_dict(keys, values)\nprint(result)", "split": "train" }
import math def is_PerfectNumber(n): if n <= 1: return 0 sum_div = 1 # 1 is a proper divisor for n > 1 sqrt_n = int(math.sqrt(n)) for i in range(2, sqrt_n + 1): if n % i == 0: other = n // i if i == other: sum_div += i else: ...
simplelr_Taco
[ { "content": "Question:\nGiven a number, determine if the number is a \"Perfect Number\" or not. A \"Perfect Number\" is a positive integer that is equal to the sum of its proper divisors, excluding the number itself. \n\nExample 1:\nInput: 28\nOutput: 1\nExplanation: Proper divisors of 28 are 1, 2, 4, 7, 14. S...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5708, "level": 1, "question": "Given a number, determine if the number is a \"Perfect Number\" or not. A \"Perfect Number\" is a positive integer that is equal to the sum of its proper divisors, excluding the number itself. \n\nExample 1:\nInput: 28\nOutput: 1\nExplanation: Proper d...
from collections import Counter def can_arrange(arr, k): n = len(arr) if n % 2 != 0: return False if k == 0: count = Counter(arr) for num in count: if num == 0: if count[num] % 2 != 0: return False else: if ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of `n` integers `arr`. Your task is to check if the array can be divided into pairs such that the sum of each pair is divisible by a given integer `k`. Return _true_ if it is possible to divide the array into such pairs, and _false_ otherwise. Each element of the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5709, "level": 1, "question": "You are given an array of `n` integers `arr`. Your task is to check if the array can be divided into pairs such that the sum of each pair is divisible by a given integer `k`. Return _true_ if it is possible to divide the array into such pairs, and _fal...
import math def is_perfect_square(n): if n < 0: return False root = math.isqrt(n) return root * root == n
simplelr_Prefill
[ { "content": "Question:\nCreate a function that checks if a given integer is a perfect square. A perfect square is an integer that is the square of another integer. For example, 1, 4, 9, and 16 are perfect squares, while 2, 3, and 5 are not. Write a function in Python that takes an integer as input and returns ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5710, "level": 1, "question": "Create a function that checks if a given integer is a perfect square. A perfect square is an integer that is the square of another integer. For example, 1, 4, 9, and 16 are perfect squares, while 2, 3, and 5 are not. Write a function in Python that tak...
def find_max(stack): return max(stack)
simplelr_Filter
[ { "content": "Question:\n### Programming Languages and Algorithms\n#### Problem: Maximum Element in a Stack\nGiven a stack of integers, find the maximum element in the stack.\n\n**Example**\n* Input: `[1, 2, 3, 4, 5]`\n* Output: `5`\n\n**Constraints**\n\n* The stack will contain at least one element.\n* All...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5711, "level": 1, "question": "### Programming Languages and Algorithms\n#### Problem: Maximum Element in a Stack\nGiven a stack of integers, find the maximum element in the stack.\n\n**Example**\n* Input: `[1, 2, 3, 4, 5]`\n* Output: `5`\n\n**Constraints**\n\n* The stack will con...
def two_sum(nums, target): num_to_index = {} for i, num in enumerate(nums): complement = target - num if complement in num_to_index: return [num_to_index[complement], i] num_to_index[num] = i return []
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `nums` and an integer `target`. You need to find two distinct integers in the array that sum up to the `target`. Return the indices of the two numbers such that they add up to the `target`. The indices returned should be in ascending order. If there ar...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5712, "level": 1, "question": "You are given an array of integers `nums` and an integer `target`. You need to find two distinct integers in the array that sum up to the `target`. Return the indices of the two numbers such that they add up to the `target`. The indices returned should...
def product_except_self(arr): n = len(arr) res = [1] * n left_product = 1 for i in range(n): res[i] = left_product left_product *= arr[i] right_product = 1 for i in range(n-1, -1, -1): res[i] *= right_product right_product *= arr[i] return res
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes in a list of positive integers and returns a new list where each element is the product of all the numbers in the original list except the number at that index. The problem should not use division for the solution, and a solution should exist in constant spa...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5713, "level": 1, "question": "Create a function that takes in a list of positive integers and returns a new list where each element is the product of all the numbers in the original list except the number at that index. The problem should not use division for the solution, and a so...
import heapq from typing import List def improved_dijkstra(graph: List[List[int]], src: int) -> List[int]: """ Parameters: graph (List[List[int]]): A 2D list representing a directed graph with edge weights. src (int): The source vertex for calculating the shortest paths. Returns: List[int]: A ...
simplelr_Data_Structure
[ { "content": "Question:\nYou are tasked with enhancing the given implementation of Dijkstra's algorithm to improve its efficiency by changing the data structure used to find the minimum distance vertex that hasn't been processed yet.\n\n### Objective\n\nRefactor the given Dijkstra's algorithm to use a priority ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5714, "level": 1, "question": "You are tasked with enhancing the given implementation of Dijkstra's algorithm to improve its efficiency by changing the data structure used to find the minimum distance vertex that hasn't been processed yet.\n\n### Objective\n\nRefactor the given Dijk...
def add_numbers(a, b): if type(a) not in (int, float) or type(b) not in (int, float): return "Error: Both inputs must be numbers." return a + b
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that takes two arguments, a and b, and returns their sum. The function should be able to handle both integer and float inputs. Additionally, the function should return an error message if either input is not a number.\nAnswer:\nLet's think step by step.\n", "...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5715, "level": 1, "question": "Write a Python function that takes two arguments, a and b, and returns their sum. The function should be able to handle both integer and float inputs. Additionally, the function should return an error message if either input is not a number.", "split...
def hex_to_decimal(hex_str): return int(hex_str, 16)
simplelr_Filter
[ { "content": "Question:\nI want to create a Python function that takes a string representing a hexadecimal number and returns its decimal equivalent. How can I implement this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5716, "level": 1, "question": "I want to create a Python function that takes a string representing a hexadecimal number and returns its decimal equivalent. How can I implement this?", "split": "train" }
from typing import List def efficient_cocktail_shaker_sort(arr: List[int]) -> List[int]: arr = arr.copy() n = len(arr) if n <= 1: return arr swapped = True while swapped: swapped = False # Forward pass (left to right) for i in range(n - 1): if arr[i] > ar...
simplelr_Data_Structure
[ { "content": "Question:\nEnhance Cocktail Shaker Sort with Improved Efficiency\n\nGiven an array of integers, you need to implement a modified version of the Cocktail Shaker Sort algorithm that stops early if the array is already sorted during any complete pass.\n\n#### Function Signature:\n```python\ndef effic...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5717, "level": 1, "question": "Enhance Cocktail Shaker Sort with Improved Efficiency\n\nGiven an array of integers, you need to implement a modified version of the Cocktail Shaker Sort algorithm that stops early if the array is already sorted during any complete pass.\n\n#### Functi...
def findDuplicate(nums): n = len(nums) - 1 expected = n * (n + 1) // 2 actual = sum(nums) return actual - expected
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and using only constant extra space.\n\nExam...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5718, "level": 1, "question": "Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and using...
def linear_search(lst, target): for index, value in enumerate(lst): if value == target: return index return -1 # Test cases if __name__ == "__main__": # Example 1: Target is present print(linear_search([3, 1, 4, 1, 5], 1)) # Expected output: 1 # Example 2: Target is not pr...
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that implements a linear search algorithm. The function should take a list of integers and a target integer to find in the list. It should return the index of the first occurrence of the target integer in the list, or -1 if the target integer is not found. Additi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5719, "level": 1, "question": "Write a Python function that implements a linear search algorithm. The function should take a list of integers and a target integer to find in the list. It should return the index of the first occurrence of the target integer in the list, or -1 if the ...
def calculate_average_marks(students_marks): students = [] for s in students_marks: parts = s.split() name = parts[0] marks = list(map(int, parts[1:])) average = sum(marks) / len(marks) students.append((name, average)) # Sort by average descending, then by name a...
simplelr_Taco
[ { "content": "Question:\nYou are given a list of strings, each string representing a student's first name and their respective marks in different subjects separated by a space. Your task is to write a function that processes this list of strings and returns another list containing the student's names along with...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5720, "level": 1, "question": "You are given a list of strings, each string representing a student's first name and their respective marks in different subjects separated by a space. Your task is to write a function that processes this list of strings and returns another list contai...
def find_pairs(lst, target): pairs = set() n = len(lst) for i in range(n): for j in range(i + 1, n): a = lst[i] b = lst[j] if a + b == target: pair = tuple(sorted((a, b))) pairs.add(pair) sorted_pairs = sorted(pairs) return ...
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes a list of integers and a target value as input. The function should return a new list containing all pairs of integers from the input list that add up to the target value. Each pair should be represented as a tuple of the two integer values in ascending order...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5721, "level": 1, "question": "Write a function that takes a list of integers and a target value as input. The function should return a new list containing all pairs of integers from the input list that add up to the target value. Each pair should be represented as a tuple of the tw...
def longest_subsequence(arr): longest = {} max_len = 0 for num in arr: temp = 1 # At least the subsequence containing only num if (num + 1) in longest: temp = max(temp, longest[num + 1] + 1) if (num - 1) in longest: temp = max(temp, longest[num - 1] + 1) ...
simplelr_Leetcode
[ { "content": "Question:\nGiven an array `arr` consisting of `n` positive integers, write a function to find the length of the longest subsequence such that the difference between consecutive elements is either `1` or `-1`. A subsequence is derived by deleting some or no elements from the array without changing ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5722, "level": 1, "question": "Given an array `arr` consisting of `n` positive integers, write a function to find the length of the longest subsequence such that the difference between consecutive elements is either `1` or `-1`. A subsequence is derived by deleting some or no elemen...
def convert(s, numRows): if numRows == 0 or numRows == 1: return s rows = [''] * numRows current_row = 0 direction = 1 # 1 for down, -1 for up for c in s: rows[current_row] += c if current_row == 0: direction = 1 elif current_row == numRows - 1: ...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s` and an integer `numRows`, convert the string into a zigzag pattern on a given number of rows and return the resulting string read line by line. For example, given the input string \"PAYPALISHIRING\" with `numRows = 3`, the zigzag pattern would be:\n\n```\nP A H ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5723, "level": 1, "question": "Given a string `s` and an integer `numRows`, convert the string into a zigzag pattern on a given number of rows and return the resulting string read line by line. For example, given the input string \"PAYPALISHIRING\" with `numRows = 3`, the zigzag pat...
import heapq def merge_k_streams(streams): heap = [] # Initialize the heap with the first element of each non-empty stream for i in range(len(streams)): if streams[i]: # Each element in the heap is a tuple: (timestamp, payload, stream index, element index) heapq.heappush(hea...
simplelr_Codeforces
[ { "content": "Question:\nA thriving tech company is looking to optimize the performance of their data processing pipelines. They need an efficient way to process a large stream of data events. Each event has a timestamp and a payload. An event is represented as a tuple (timestamp, payload), where timestamp is a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5724, "level": 1, "question": "A thriving tech company is looking to optimize the performance of their data processing pipelines. They need an efficient way to process a large stream of data events. Each event has a timestamp and a payload. An event is represented as a tuple (timest...
def countUniqueNumbers(nums): unique_sorted = set() for num in nums: s = str(num) sorted_s = ''.join(sorted(s)) unique_sorted.add(sorted_s) return len(unique_sorted)
simplelr_Taco
[ { "content": "Question:\nGiven a list of integers, the task is to return the number of unique integers that can be formed by rearranging each number's digits to make new numbers.\n\nExample 1:\nInput: nums = [123, 456, 231]\nOutput: 2\nExplanation: The numbers 123 and 231 can be rearranged into each other, form...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5725, "level": 1, "question": "Given a list of integers, the task is to return the number of unique integers that can be formed by rearranging each number's digits to make new numbers.\n\nExample 1:\nInput: nums = [123, 456, 231]\nOutput: 2\nExplanation: The numbers 123 and 231 can ...
def total_cost(items, threshold): total = 0 for item in items: if item['quantity'] > 1 and item['price'] > threshold: total += item['price'] * item['quantity'] return total
simplelr_Evol
[ { "content": "Question:\nWrite a Python function that accepts a list of dictionary objects representing items in a store. Each dictionary has 'name', 'price', and 'quantity' fields. The function should return the total cost of items in the store where the quantity is greater than 1 and the price is greater than...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5726, "level": 1, "question": "Write a Python function that accepts a list of dictionary objects representing items in a store. Each dictionary has 'name', 'price', and 'quantity' fields. The function should return the total cost of items in the store where the quantity is greater t...
def minimumSwaps(arr): if not arr: return 0 n = len(arr) sorted_arr = sorted(arr) pos_map = {num: i for i, num in enumerate(sorted_arr)} visited = [False] * n swaps = 0 for i in range(n): if visited[i] or arr[i] == sorted_arr[i]: continue cycle_size =...
simplelr_Code_Contests
[ { "content": "Question:\nGiven an array of integers, determine the minimum number of swaps required to sort the array in ascending order. Each swap consists of swapping any two elements of the array.\n\nYou should implement a function:\n\n```\nint minimumSwaps(int[] arr);\n```\n\nThe function takes an array of ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5727, "level": 1, "question": "Given an array of integers, determine the minimum number of swaps required to sort the array in ascending order. Each swap consists of swapping any two elements of the array.\n\nYou should implement a function:\n\n```\nint minimumSwaps(int[] arr);\n```...
from collections import Counter def count_character_frequency(input_string): # Use Counter to count each character's frequency char_counts = Counter(input_string) return dict(char_counts) # Example usage: input_str = "hello" print(count_character_frequency(input_str))
simplelr_Filter
[ { "content": "Question:\nI'm using Python and need to count the frequency of each character in a string. How can I do this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5728, "level": 1, "question": "I'm using Python and need to count the frequency of each character in a string. How can I do this?", "split": "train" }
def lastRemaining(n: int, k: int) -> int: res = 0 for m in range(2, n + 1): res = (res + k) % m return res + 1
simplelr_Leetcode
[ { "content": "Question:\nWe have a list of numbers from 1 to `n` arranged in a circle. Starting from position `1`, we eliminate every k-th person in the circle until only one person remains. You need to write a function that returns the position of the last remaining person in the circle.\n\nGiven two integers ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5729, "level": 1, "question": "We have a list of numbers from 1 to `n` arranged in a circle. Starting from position `1`, we eliminate every k-th person in the circle until only one person remains. You need to write a function that returns the position of the last remaining person in...
def find_common_elements(list1, list2): elements_in_list2 = {} for elem in list2: elements_in_list2[elem] = True result = [] seen = {} for elem in list1: if elem in elements_in_list2 and elem not in seen: result.append(elem) seen[elem] = True return r...
simplelr_Filter
[ { "content": "Question:\nCan you provide a Python code snippet that finds the common elements between two lists without using any built-in functions like `set`, `filter`, `map`, or `reduce`?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5730, "level": 1, "question": "Can you provide a Python code snippet that finds the common elements between two lists without using any built-in functions like `set`, `filter`, `map`, or `reduce`?", "split": "train" }
from typing import List def largestRectangleArea(heights: List[int]) -> int: if not heights: return 0 stack = [] max_area = 0 n = len(heights) for i in range(n): while stack and heights[i] < heights[stack[-1]]: top = stack.pop() left = stack[-1] if stack else...
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of `n` integers where each value represents the height of a bar in a histogram, design an algorithm to find the area of the largest rectangle that can be formed within the bounds of the histogram. Return the maximum area of such a rectangle.\n\nFor example, given the heig...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5731, "level": 1, "question": "Given an array of `n` integers where each value represents the height of a bar in a histogram, design an algorithm to find the area of the largest rectangle that can be formed within the bounds of the histogram. Return the maximum area of such a rectan...
def max_value(a, b): return max(a, b)
simplelr_Filter
[ { "content": "Question:\nI need to create a function that returns the maximum value between two integers. Can you help me write this function in Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5732, "level": 1, "question": "I need to create a function that returns the maximum value between two integers. Can you help me write this function in Python?", "split": "train" }
def rotate_matrix(m): if not m: return [] reversed_matrix = m[::-1] transposed = zip(*reversed_matrix) rotated = [list(row) for row in transposed] return rotated
simplelr_Prefill
[ { "content": "Question:\nWrite a function to rotate a 2D array (matrix) by 90 degrees clockwise. How would you go about this?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5733, "level": 1, "question": "Write a function to rotate a 2D array (matrix) by 90 degrees clockwise. How would you go about this?", "split": "train" }
from typing import List def rotate_matrix(matrix: List[List[int]]) -> List[List[int]]: n = len(matrix) # Transpose the matrix for i in range(n): for j in range(i + 1, n): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] # Reverse each row for row in matrix: row.re...
simplelr_Apps
[ { "content": "Question:\n## Matrix Rotation\n\nGiven a square matrix, write a function that rotates the matrix 90 degrees clockwise. The function should modify the matrix in place and return the modified matrix.\n\n### Example\n\nInput:\n```python\nmatrix = [\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n]\n```\n\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5734, "level": 1, "question": "## Matrix Rotation\n\nGiven a square matrix, write a function that rotates the matrix 90 degrees clockwise. The function should modify the matrix in place and return the modified matrix.\n\n### Example\n\nInput:\n```python\nmatrix = [\n [1, 2, 3],\n ...
import bisect def length_of_lis(nums): tails = [] for num in nums: idx = bisect.bisect_left(tails, num) if idx == len(tails): tails.append(num) else: tails[idx] = num return len(tails)
simplelr_Leetcode
[ { "content": "Question:\nGiven a list of `n` integers, return the **length of the longest strictly increasing subsequence**. \n\nA subsequence is a sequence derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\n\nFor example, consider the list `[10,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5735, "level": 1, "question": "Given a list of `n` integers, return the **length of the longest strictly increasing subsequence**. \n\nA subsequence is a sequence derived from another sequence by deleting some or no elements without changing the order of the remaining elements.\n\nF...
def find_max_subarray(nums): if not nums: return 0 current_max = global_max = nums[0] for num in nums[1:]: current_max = max(num, current_max + num) if current_max > global_max: global_max = current_max return global_max
simplelr_Package
[ { "content": "Question:\nYou are required to write a function named `find_max_subarray` which identifies the contiguous subarray within a one-dimensional numeric array, `nums`, that has the largest sum. The function should return the sum of this subarray. This problem is a classic example of the \"Maximum Subar...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5736, "level": 1, "question": "You are required to write a function named `find_max_subarray` which identifies the contiguous subarray within a one-dimensional numeric array, `nums`, that has the largest sum. The function should return the sum of this subarray. This problem is a cla...
def filter_and_reverse(s, arr): allowed_chars = set(s) result = [] for string in arr: reversed_str = string[::-1] filtered = [c for c in reversed_str if c in allowed_chars] result.append(''.join(filtered)) return result
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a string and an array of strings as input. The function should return a new array where each element is a string from the input array, but with the characters of each string reversed and only including characters that are present in the first string.\nAnswer...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5737, "level": 1, "question": "Create a function that takes a string and an array of strings as input. The function should return a new array where each element is a string from the input array, but with the characters of each string reversed and only including characters that are p...
def sum_list(numbers): total = 0 for number in numbers: total += number if total < 10: return "Sum is too low" else: return total
simplelr_Filter
[ { "content": "Question:\nLet's say I have a function in my program that\n\n * Takes a list of numbers as input.\n * Returns the sum of all the numbers in the list.\n\nHere's how I might write it in Python:\n\n```python\ndef sum_list(numbers):\n total = 0\n for number in numbers:\n total += number\n retu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5738, "level": 1, "question": "Let's say I have a function in my program that\n\n * Takes a list of numbers as input.\n * Returns the sum of all the numbers in the list.\n\nHere's how I might write it in Python:\n\n```python\ndef sum_list(numbers):\n total = 0\n for number in nu...
def ohms_law(voltage: float, resistance: float, current: float) -> dict[str, float]: """ Calculate voltage, resistance, or current from two given electrical properties. Parameters: voltage (float): Voltage in Volts resistance (float): Resistance in Ohms current (float): Current in Amperes ...
simplelr_Algorithm
[ { "content": "Question:\n### Coding Problem: Calculate the Voltage, Resistance, or Current in DC Circuits\n\n**Context**:\n\nIn Direct Current (DC) circuits, Ohm's Law is fundamental for determining the relationship between voltage (V), current (I), and resistance (R). This context leads you to develop an algor...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5739, "level": 1, "question": "### Coding Problem: Calculate the Voltage, Resistance, or Current in DC Circuits\n\n**Context**:\n\nIn Direct Current (DC) circuits, Ohm's Law is fundamental for determining the relationship between voltage (V), current (I), and resistance (R). This co...
def trap_water(heights): if len(heights) < 3: return 0 left = 0 right = len(heights) - 1 left_max = right_max = 0 result = 0 while left <= right: if heights[left] <= heights[right]: if heights[left] >= left_max: left_max = heights[left] els...
simplelr_Taco
[ { "content": "Question:\nYou are given a list of integers that represent the heights of buildings. Each building's width is exactly 1. It starts raining and water is collected between the buildings. Your task is to calculate how much water is collected.\n\nExample 1:\nInput: heights = [4,2,0,3,2,5]\nOutput: 9\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5740, "level": 1, "question": "You are given a list of integers that represent the heights of buildings. Each building's width is exactly 1. It starts raining and water is collected between the buildings. Your task is to calculate how much water is collected.\n\nExample 1:\nInput: h...
from typing import List def shell_sort(arr: List[int]) -> List[int]: n = len(arr) gap = n // 2 while gap > 0: for i in range(gap, n): temp = arr[i] j = i while j >= gap and arr[j - gap] > temp: arr[j] = arr[j - gap] j -= gap ...
simplelr_Data_Structure
[ { "content": "Question:\nShell sort is an optimized version of insertion sort that allows the exchange of items that are far apart. The basic idea is to arrange the list of elements so sequences of elements that are far apart are sorted.\n\n#### Description\nImplement the `shell_sort` function which sorts a giv...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5741, "level": 1, "question": "Shell sort is an optimized version of insertion sort that allows the exchange of items that are far apart. The basic idea is to arrange the list of elements so sequences of elements that are far apart are sorted.\n\n#### Description\nImplement the `she...
def unique_items(lst): # Initialize the hash table with 1000 buckets table = [[] for _ in range(1000)] result = [] for element in lst: # Compute the hash value based on the element type if isinstance(element, str): hash_val = sum(ord(c) for c in element) % 1000 e...
simplelr_Filter
[ { "content": "Question:\nCreate an algorithm that returns an array of the unique items in a given list, but now you are not allowed to use any built-in functions, data structures, or algorithms for removing duplicates. You must implement your own method for removing duplicates. Additionally, you must ensure tha...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5742, "level": 1, "question": "Create an algorithm that returns an array of the unique items in a given list, but now you are not allowed to use any built-in functions, data structures, or algorithms for removing duplicates. You must implement your own method for removing duplicates...
def find_anagrams(target, words): target_sorted = ''.join(sorted(target)) group = [] for word in words: if len(word) != len(target): continue if ''.join(sorted(word)) == target_sorted: group.append(word) return [group] if group else []
simplelr_Taco
[ { "content": "Question:\nYou are given an array of strings and a target string. Your task is to find and return all anagram groups of the target string that exist in the array. Each group should consist of strings that are anagrams of the target string. The order of groups in the output does not matter, but the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5743, "level": 1, "question": "You are given an array of strings and a target string. Your task is to find and return all anagram groups of the target string that exist in the array. Each group should consist of strings that are anagrams of the target string. The order of groups in ...
import heapq def trap_rain_water(grid): if not grid or len(grid) < 3 or len(grid[0]) < 3: return 0 m, n = len(grid), len(grid[0]) visited = [[False for _ in range(n)] for _ in range(m)] heap = [] # Initialize the heap with all boundary cells for i in range(m): for j in rang...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a 2D grid of size `m x n` where each cell represents an elevation map. The height of each cell is represented by an integer. Determine the volume of water that can be trapped when it rains. Imagine the grid is surrounded by walls; water cannot flow off the edges. You may a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5744, "level": 1, "question": "You are given a 2D grid of size `m x n` where each cell represents an elevation map. The height of each cell is represented by an integer. Determine the volume of water that can be trapped when it rains. Imagine the grid is surrounded by walls; water c...
def find_max_consecutive_ones(nums): max_count = 0 current_count = 0 for num in nums: if num == 1: current_count += 1 else: if current_count > max_count: max_count = current_count current_count = 0 if current_count > max_count: ...
simplelr_Package
[ { "content": "Question:\nYou are required to write a function `find_max_consecutive_ones(nums)` that takes a list of integers `nums` as input, where each integer is either 0 or 1. The function should return the maximum number of consecutive 1s in the list.\n\n### Requirements:\n1. The function must iterate thro...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5745, "level": 1, "question": "You are required to write a function `find_max_consecutive_ones(nums)` that takes a list of integers `nums` as input, where each integer is either 0 or 1. The function should return the maximum number of consecutive 1s in the list.\n\n### Requirements:...
def countDigit(n, d): return n.count(d)
simplelr_Taco
[ { "content": "Question:\nYou are given a string representation of a number (n) and a digit (d). Your task is to determine the number of times the digit (d) appears within the number (n).\n\nExample 1:\nInput:\n\"123456789\"\n\"3\"\nOutput:\n1\n\nExample 2:\nInput:\n\"999999\", \"9\"\nOutput:\n6\n\nYour Task:\nY...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5746, "level": 1, "question": "You are given a string representation of a number (n) and a digit (d). Your task is to determine the number of times the digit (d) appears within the number (n).\n\nExample 1:\nInput:\n\"123456789\"\n\"3\"\nOutput:\n1\n\nExample 2:\nInput:\n\"999999\",...
def subarray_sum(arr, x): prefix_sums = {0} current_sum = 0 for num in arr: current_sum += num if (current_sum - x) in prefix_sums: return True prefix_sums.add(current_sum) return False
simplelr_Leetcode
[ { "content": "Question:\nYou are given an integer array `arr` and an integer `x`. Your task is to find out if there exists a **subarray** whose sum is exactly equal to `x`. A subarray is a contiguous part of the array. Return `true` if such a subarray exists, otherwise return `false`. \n\nNote: The array can co...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5747, "level": 1, "question": "You are given an integer array `arr` and an integer `x`. Your task is to find out if there exists a **subarray** whose sum is exactly equal to `x`. A subarray is a contiguous part of the array. Return `true` if such a subarray exists, otherwise return ...
from typing import List def max_rectangle_area(heights: List[int]) -> int: stack = [-1] # Initialize stack with base index max_area = 0 n = len(heights) for i in range(n): # Pop elements from the stack while the current height is smaller than the height at the top of the stack whi...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a list of positive integers representing the heights of buildings in a skyline. Your task is to determine the maximum area of a rectangle that can be formed by any consecutive buildings. Each building has a width of 1 unit.\n\nWrite a function `max...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5748, "level": 1, "question": "### Problem Statement\n\nYou are given a list of positive integers representing the heights of buildings in a skyline. Your task is to determine the maximum area of a rectangle that can be formed by any consecutive buildings. Each building has a width ...
def spiral(n): # Create an n x n matrix filled with zeros matrix = [[0 for _ in range(n)] for _ in range(n)] # Define the order of directions: right, down, left, up directions = [(0, 1), (1, 0), (0, -1), (-1, 0)] dir_idx = 0 # start by moving right row, col = 0, 0 # starting position...
simplelr_Filter
[ { "content": "Question:\nThis is a coding challenge and I need help to write a program that prints a spiral matrix.\n\n\n```python\ndef spiral(n):\n\n```\nThe function should take an integer `n` as input, which represents the dimension of the square matrix.\n\n\n\n\nFor example:\n\n\n```\nspiral(3)\n```\n\nShou...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5749, "level": 1, "question": "This is a coding challenge and I need help to write a program that prints a spiral matrix.\n\n\n```python\ndef spiral(n):\n\n```\nThe function should take an integer `n` as input, which represents the dimension of the square matrix.\n\n\n\n\nFor exampl...
def filter_unique_sorted_array(arr): if not arr: return [] write_pointer = 0 for read_pointer in range(1, len(arr)): if arr[read_pointer] != arr[write_pointer]: write_pointer += 1 arr[write_pointer] = arr[read_pointer] return arr[:write_pointer + 1]
simplelr_Filter
[ { "content": "Question:\nImplement an algorithm that filters a given sorted array and returns an array containing only the unique values from the original array. The algorithm should have a time complexity of O(n) and should use only constant space (i.e., no additional arrays or data structures should be used)....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5750, "level": 1, "question": "Implement an algorithm that filters a given sorted array and returns an array containing only the unique values from the original array. The algorithm should have a time complexity of O(n) and should use only constant space (i.e., no additional arrays ...
from html import escape, unescape def transform_html(text: str, quote: bool = True) -> bool: escaped = escape(text, quote=quote) unescaped = unescape(escaped) return text == unescaped
simplelr_Docs
[ { "content": "Question:\n**Objective**: Implement a function to transform a given text into an HTML-safe format and then revert it back, ensuring consistency in conversions.\n\n**Problem Statement**:\n\nWrite a function `transform_html(text: str, quote: bool = True) -> bool` that performs the following operatio...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5751, "level": 1, "question": "**Objective**: Implement a function to transform a given text into an HTML-safe format and then revert it back, ensuring consistency in conversions.\n\n**Problem Statement**:\n\nWrite a function `transform_html(text: str, quote: bool = True) -> bool` t...
def shift_characters(s): result = [] for char in s: if not char.isalpha(): result.append(char) else: if char == 'z': result.append('a') elif char == 'Z': result.append('A') else: result.append(chr(ord...
simplelr_Evol
[ { "content": "Question:\nWrite a function in Python that takes a string as input and returns a new string where each character in the original string is replaced by the next character in the ASCII sequence. If the character is 'z' or 'Z', it should wrap around to 'a' or 'A' respectively. Non-alphabetical charac...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5752, "level": 1, "question": "Write a function in Python that takes a string as input and returns a new string where each character in the original string is replaced by the next character in the ASCII sequence. If the character is 'z' or 'Z', it should wrap around to 'a' or 'A' re...
def rotate_matrix(matrix): n = len(matrix) # Transpose the matrix for i in range(n): for j in range(i, n): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] # Reverse each row for row in matrix: row.reverse()
simplelr_Evol
[ { "content": "Question:\nWrite a function to rotate an NxN matrix by 90 degrees clockwise in place. The matrix is represented by an array of arrays. \nFor example, if the matrix is:\n```\n[\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n]\n```\nThe rotated matrix should be:\n```\n[\n [7, 4, 1],\n [8, 5, 2],\n [9,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5753, "level": 1, "question": "Write a function to rotate an NxN matrix by 90 degrees clockwise in place. The matrix is represented by an array of arrays. \nFor example, if the matrix is:\n```\n[\n [1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]\n]\n```\nThe rotated matrix should be:\n```\n[...
from collections import Counter def are_anagrams(s1, s2): # Remove spaces and convert to lowercase for both strings s1_processed = s1.replace(' ', '').lower() s2_processed = s2.replace(' ', '').lower() # If lengths are different, they can't be anagrams if len(s1_processed) != len(s2_processed)...
simplelr_Filter
[ { "content": "Question:\nFinish the following code. Instead of a simple codeword, create a function that accepts two strings. Check if the characters in the first string can be rearranged to match the second string considering the same characters frequency. Also confirm the second string is an anagram of the fi...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5754, "level": 1, "question": "Finish the following code. Instead of a simple codeword, create a function that accepts two strings. Check if the characters in the first string can be rearranged to match the second string considering the same characters frequency. Also confirm the se...
def find_triplet(arr, targetSum): arr.sort() n = len(arr) for i in range(n - 2): left = i + 1 right = n - 1 while left < right: current_sum = arr[i] + arr[left] + arr[right] if current_sum == targetSum: return [arr[i], arr[left], arr[right]] ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr` and an integer `targetSum`. Your task is to determine if there are three distinct elements in `arr` such that their sum is equal to `targetSum`. If such a triplet exists, return _the triplet as a list of integers in non-decreasing order_. If ther...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5755, "level": 1, "question": "You are given an array of integers `arr` and an integer `targetSum`. Your task is to determine if there are three distinct elements in `arr` such that their sum is equal to `targetSum`. If such a triplet exists, return _the triplet as a list of integer...
def delete_reoccurring_characters(s): seen = set() result = [] for char in s: if char not in seen: seen.add(char) result.append(char) return ''.join(result)
simplelr_Data_Structure
[ { "content": "Question:\nGiven a string as input, write a function `delete_reoccurring_characters` that deletes any reoccurring character, retaining only the first occurrence of each character in the original order, and returns the new string. The function should be efficient in both time and space complexity.\...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5756, "level": 1, "question": "Given a string as input, write a function `delete_reoccurring_characters` that deletes any reoccurring character, retaining only the first occurrence of each character in the original order, and returns the new string. The function should be efficient ...
def has_pair_with_sum(nums, target): seen = set() for num in nums: complement = target - num if complement in seen: return True seen.add(num) return False
simplelr_Evol
[ { "content": "Question:\nCompose a Python function that checks if a given list of integers contains two distinct elements that sum up to a specified target value. The function should return True if such a pair exists, and False otherwise.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5757, "level": 1, "question": "Compose a Python function that checks if a given list of integers contains two distinct elements that sum up to a specified target value. The function should return True if such a pair exists, and False otherwise.", "split": "train" }
def max_sum_subarray(arr, k): if k == 0 or len(arr) == 0 or k > len(arr): return 0 current_sum = sum(arr[:k]) max_sum = current_sum for i in range(k, len(arr)): current_sum = current_sum - arr[i - k] + arr[i] if current_sum > max_sum: max_sum = current_sum return ...
simplelr_Filter
[ { "content": "Question:\nThis task involves writing Python code to implement the \"Sliding Window\" problem. Let's assume it's about finding the maximum sum of a contiguous subarray of size 'k' within a given array.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5758, "level": 1, "question": "This task involves writing Python code to implement the \"Sliding Window\" problem. Let's assume it's about finding the maximum sum of a contiguous subarray of size 'k' within a given array.", "split": "train" }
def max_sunlit_buildings(heights): max_so_far = 0 count = 0 for height in heights: if height > max_so_far: count += 1 max_so_far = height return count
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of positive integers `heights` representing the heights of buildings on a street. You need to determine the maximum number of buildings that can receive sunlight in the morning. A building receives sunlight if there are no taller buildings to its left. Return _the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5759, "level": 1, "question": "You are given an array of positive integers `heights` representing the heights of buildings on a street. You need to determine the maximum number of buildings that can receive sunlight in the morning. A building receives sunlight if there are no taller...
def fibonacci(n): if n <= 0: return [] fib_sequence = [0] if n == 1: return fib_sequence fib_sequence.append(1) if n == 2: return fib_sequence for i in range(2, n): next_num = fib_sequence[i-1] + fib_sequence[i-2] fib_sequence.append(next_num) return f...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to generate the first n numbers in the Fibonacci sequence.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5760, "level": 1, "question": "Write a python function to generate the first n numbers in the Fibonacci sequence.", "split": "train" }
def remove_vowels(s): translation_table = str.maketrans('', '', 'aeiouAEIOU') return s.translate(translation_table)
simplelr_Filter
[ { "content": "Question:\nHello! I'm trying to write a function in Python that can take a string as input and return a new string with all the vowels removed. How can I do that?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5761, "level": 1, "question": "Hello! I'm trying to write a function in Python that can take a string as input and return a new string with all the vowels removed. How can I do that?", "split": "train" }
def isPalindrome(n): s = str(n) return s == s[::-1]
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes an integer `n` as input and returns `True` if `n` is a palindrome number, otherwise return `False`. A palindrome number is a number that remains the same when its digits are reversed.\n\nExample:\n\n```python\nisPalindrome(121)\n// should return True\n\nisPal...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5762, "level": 1, "question": "Write a function that takes an integer `n` as input and returns `True` if `n` is a palindrome number, otherwise return `False`. A palindrome number is a number that remains the same when its digits are reversed.\n\nExample:\n\n```python\nisPalindrome(1...
def gcd(a, b): a = abs(a) b = abs(b) while b != 0: temp = b b = a % b a = temp return a
simplelr_Filter
[ { "content": "Question:\nI'm trying to write a Python function that calculates the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. Can you provide a sample code for that?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5763, "level": 1, "question": "I'm trying to write a Python function that calculates the greatest common divisor (GCD) of two numbers using the Euclidean algorithm. Can you provide a sample code for that?", "split": "train" }
import itertools def generate_permutations(nums): return [list(p) for p in itertools.permutations(nums)]
simplelr_Data_Structure
[ { "content": "Question:\nYou are given a list of distinct integers. Your task is to generate all possible permutations of this list.\n\nImplement a function `generate_permutations(nums)` that takes a list of distinct integers `nums` as input and returns a list of all possible permutations.\n\n### Input\n- A lis...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5764, "level": 1, "question": "You are given a list of distinct integers. Your task is to generate all possible permutations of this list.\n\nImplement a function `generate_permutations(nums)` that takes a list of distinct integers `nums` as input and returns a list of all possible ...
def rotate_list(lst, n): length = len(lst) if length <= 1: return list(lst) r = n % length if r == 0: return list(lst) else: return lst[-r:] + lst[:-r]
simplelr_Prefill
[ { "content": "Question:\nCreate a function that rotates a list `n` positions to the right. The rotation should handle both positive and negative values of `n`. Positive `n` should rotate the list to the right, and negative `n` should rotate it to the left. The function should be efficient and handle large lists...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5765, "level": 1, "question": "Create a function that rotates a list `n` positions to the right. The rotation should handle both positive and negative values of `n`. Positive `n` should rotate the list to the right, and negative `n` should rotate it to the left. The function should ...
def find_max(lst): max_num = lst[0] for num in lst[1:]: if num > max_num: max_num = num return max_num
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the maximum number in a given list of numbers without using the built-in `max` function. Assume the list is non-empty. The function should return the maximum number in the list. For example, given the list [3, 5, 1, 8, 6], the function should return 8.\nA...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5766, "level": 1, "question": "Write a Python function to find the maximum number in a given list of numbers without using the built-in `max` function. Assume the list is non-empty. The function should return the maximum number in the list. For example, given the list [3, 5, 1, 8, 6...
def find_duplicates(arr): seen = set() duplicates = [] for num in arr: if num in seen: if num not in duplicates: duplicates.append(num) else: seen.add(num) return duplicates
simplelr_Prefill
[ { "content": "Question:\nWrite a function to detect and return the duplicate elements in an integer array. For example, given the array [1, 2, 3, 4, 2], the function should return [2]. If there are no duplicates, the function should return an empty list.\nAnswer:\nLet's think step by step.\n", "role": "user...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5767, "level": 1, "question": "Write a function to detect and return the duplicate elements in an integer array. For example, given the array [1, 2, 3, 4, 2], the function should return [2]. If there are no duplicates, the function should return an empty list.", "split": "train" }
def search_insert(array: list[int], val: int) -> int: low = 0 high = len(array) while low < high: mid = (low + high) // 2 if array[mid] >= val: high = mid else: low = mid + 1 return low
simplelr_Data_Structure
[ { "content": "Question:\nYou are given a sorted array of integers. Your task is to implement a function that integrates elements into this sorted array while maintaining the order. You need to determine the index where a given target value should be inserted to keep the array sorted.\n\n### Function Signature\n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5768, "level": 1, "question": "You are given a sorted array of integers. Your task is to implement a function that integrates elements into this sorted array while maintaining the order. You need to determine the index where a given target value should be inserted to keep the array ...
def remove_duplicates(s): seen = set() res = [] for char in s: if char not in seen: seen.add(char) res.append(char) return ''.join(res)
simplelr_Code_Contests
[ { "content": "Question:\nGiven a string with possible duplicate characters, the task is to remove the duplicate characters and return the resultant string such that each character appears exactly once. The order of characters in the resultant string should be the same as their first appearance in the original s...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5769, "level": 1, "question": "Given a string with possible duplicate characters, the task is to remove the duplicate characters and return the resultant string such that each character appears exactly once. The order of characters in the resultant string should be the same as their...
def find_nth_digit(n: int) -> int: """ Given 'n', return the nth digit in the continuously concatenated sequence of numbers starting from 1. Parameters: n (int): The position of the digit required in the concatenated sequence. Returns: int: The digit at the nth position. """ d = 1 ...
simplelr_Data_Structure
[ { "content": "Question:\n### Digital Sequence Extraction Problem\n\nYou are tasked to implement an algorithm that finds the `n`th digit in an infinitely concatenated sequence of positive integers starting from 1. This sequence looks like: 1234567891011121314...\n\n**Function Signature**: \n```python\ndef find_n...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5770, "level": 1, "question": "### Digital Sequence Extraction Problem\n\nYou are tasked to implement an algorithm that finds the `n`th digit in an infinitely concatenated sequence of positive integers starting from 1. This sequence looks like: 1234567891011121314...\n\n**Function S...
def longest_substr_two_distinct(s): if not s: return "" max_length = 0 start = 0 left = 0 char_count = {} for right in range(len(s)): char = s[right] char_count[char] = char_count.get(char, 0) + 1 # If more than two distinct characters, move lef...
simplelr_Evol
[ { "content": "Question:\nWrite a function that takes in a string consisting of lowercase alphabets, and returns the longest contiguous substring that contains at most two distinct characters. For example, given the string \"abcbbbbcccbdddadacb\", it should return \"bcbbbbcccb\". If the input string is empty, re...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5771, "level": 1, "question": "Write a function that takes in a string consisting of lowercase alphabets, and returns the longest contiguous substring that contains at most two distinct characters. For example, given the string \"abcbbbbcccbdddadacb\", it should return \"bcbbbbcccb\...
def length_of_longest_substring_two_distinct(s): n = len(s) last_occurrence = {} left = 0 max_length = 0 for right in range(n): char = s[right] last_occurrence[char] = right # Update the last occurrence of the current character # While there are more than two distinct char...
simplelr_Filter
[ { "content": "Question:\nThis is a question I found in a coding challenge.\n\nGiven a string s, return the length of the longest substring that contains at most two distinct characters.\n\nExample 1:\n\nInput: s = \"eceba\"\nOutput: 3\nExplanation: The substring \"ece\" has length 3.\n\nExample 2:\n\nInput: s =...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5772, "level": 1, "question": "This is a question I found in a coding challenge.\n\nGiven a string s, return the length of the longest substring that contains at most two distinct characters.\n\nExample 1:\n\nInput: s = \"eceba\"\nOutput: 3\nExplanation: The substring \"ece\" has le...
from typing import List, Tuple def can_attend_meetings(intervals: List[Tuple[int, int]]) -> bool: # Sort intervals based on their start times sorted_intervals = sorted(intervals, key=lambda x: x[0]) # Check each consecutive pair of intervals for overlap for i in range(1, len(sorted_intervals)): ...
simplelr_Package
[ { "content": "Question:\nGiven an array of meeting time intervals consisting of start and end times `[[s1, e1], [s2, e2], ...]` (si < ei), determine if a person could attend all meetings.\n\nYou need to implement the function `can_attend_meetings(intervals)` where:\n- `intervals` is a list of tuples representin...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5773, "level": 1, "question": "Given an array of meeting time intervals consisting of start and end times `[[s1, e1], [s2, e2], ...]` (si < ei), determine if a person could attend all meetings.\n\nYou need to implement the function `can_attend_meetings(intervals)` where:\n- `interva...
def sieve_of_eratosthenes(n): if n < 2: return [] sieve = [True] * (n + 1) sieve[0], sieve[1] = False, False for i in range(2, int(n ** 0.5) + 1): if sieve[i]: for j in range(i * i, n + 1, i): sieve[j] = False primes = [i for i, is_prime in enumerate(sieve...
simplelr_Filter
[ { "content": "Question:\nI've been trying to solve this problem for a while now, but I just can't seem to get it. I'm trying to find the simplest way to create a program that can find all prime numbers up to a given number n.\n\nHere's my current code:\n\n```python\ndef find_primes(n):\n primes = []\n for...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5774, "level": 1, "question": "I've been trying to solve this problem for a while now, but I just can't seem to get it. I'm trying to find the simplest way to create a program that can find all prime numbers up to a given number n.\n\nHere's my current code:\n\n```python\ndef find_p...
def parse_benchmark(benchmarks): result = {} for benchmark in benchmarks: if 'name' not in benchmark: continue name = benchmark['name'] if 'commit' not in benchmark or 'time' not in benchmark: continue commit = benchmark['commit'] time = benchmark[...
simplelr_Filter
[ { "content": "Question:\nI'm trying to implement aREATE a function `parse_benchmark` that takes in a list of dictionaries, where each dictionary represents a benchmark result. The function should return a dictionary where the keys are the names of the benchmarks and the values are lists of dictionaries, where e...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5775, "level": 1, "question": "I'm trying to implement aREATE a function `parse_benchmark` that takes in a list of dictionaries, where each dictionary represents a benchmark result. The function should return a dictionary where the keys are the names of the benchmarks and the values...
def max_individuals(heights, k): if not heights: return 0 heights.sort() max_len = 1 current_len = 1 for i in range(1, len(heights)): if heights[i] - heights[i-1] <= k: current_len += 1 if current_len > max_len: max_len = current_len el...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `heights` that represents the height of individuals standing in a line. Starting with an empty line, you can insert each individual into the line such that no two consecutive individuals have a height difference greater than `k`. Your task is to determ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5776, "level": 1, "question": "You are given an array of integers `heights` that represents the height of individuals standing in a line. Starting with an empty line, you can insert each individual into the line such that no two consecutive individuals have a height difference great...
def search_in_matrix(matrix, rows, cols, key): i = 0 j = cols - 1 while i < rows and j >= 0: current = matrix[i][j] if current == key: print(f"Key {key} found at row- {i+1} column- {j+1}") return elif current > key: j -= 1 else: ...
simplelr_Data_Structure
[ { "content": "Question:\n### Question: Search for a Key in a Sorted Matrix\n\nGiven a matrix where every row and every column are sorted in non-decreasing order, write a function `search_in_matrix(matrix, rows, cols, key)` that searches for a specified key within the matrix.\n\nYour function should print the po...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5777, "level": 1, "question": "### Question: Search for a Key in a Sorted Matrix\n\nGiven a matrix where every row and every column are sorted in non-decreasing order, write a function `search_in_matrix(matrix, rows, cols, key)` that searches for a specified key within the matrix.\n...
def longestCircularSubstring(circularString: str, subLength: int) -> str: return (circularString + circularString)[:subLength]
simplelr_Apps
[ { "content": "Question:\nGiven a string `circularString` that represents a circular string and an integer `subLength`, find the longest substring of length `subLength` starting from the first character of `circularString` when you consider `circularString` to be circular.\n\nA string is considered circular if w...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5778, "level": 1, "question": "Given a string `circularString` that represents a circular string and an integer `subLength`, find the longest substring of length `subLength` starting from the first character of `circularString` when you consider `circularString` to be circular.\n\nA...
def binary_to_integer(binary_string): """ Converts a binary string to its integer representation. Args: binary_string (str): A string consisting of '0's and '1's. Returns: int: The integer value of the binary string. """ return int(binary_string, 2)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to convert a binary string to an integer. A binary string consists of '0's and '1's. The function should handle both Python 2.x and Python 3.x versions.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5779, "level": 1, "question": "Write a python function to convert a binary string to an integer. A binary string consists of '0's and '1's. The function should handle both Python 2.x and Python 3.x versions.", "split": "train" }
def find_largest_and_smallest(nums): if not nums: return (None, None) return (max(nums), min(nums))
simplelr_Filter
[ { "content": "Question:\nWrite a Python script that takes a list of integers as input and returns the largest and smallest numbers in the list. Make sure to handle the case where the input list might be empty.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5780, "level": 1, "question": "Write a Python script that takes a list of integers as input and returns the largest and smallest numbers in the list. Make sure to handle the case where the input list might be empty.", "split": "train" }
def power_of_n(n): return n ** n
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes an input `n` and returns `n` raised to the power of `n`. You can use `**` operator to raise `n` to the power of `n`.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5781, "level": 1, "question": "Create a function that takes an input `n` and returns `n` raised to the power of `n`. You can use `**` operator to raise `n` to the power of `n`.", "split": "train" }
def aggregate_sensor_data(readings, start, end): filtered_readings = list(filter(lambda x: start <= x['timestamp'] <= end, readings)) if not filtered_readings: return {'message': 'No readings in the specified range.'} else: average_temp = sum(r['temperature'] for r in filtered_readings) / le...
simplelr_Docs
[ { "content": "Question:\n<|Analysis Begin|>\n\nLooking at the provided documentation, several Python built-in functions and types have been explored. These functions cover a wide range of functionalities, from simple type conversions and arithmetic operations to more complex operations like compiling code or ma...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5782, "level": 1, "question": "<|Analysis Begin|>\n\nLooking at the provided documentation, several Python built-in functions and types have been explored. These functions cover a wide range of functionalities, from simple type conversions and arithmetic operations to more complex o...
import math def longest_sequence_length(n, S): if S == 0: return 0 # though per problem statement S >=1, but handling edge case max_k = min(n, int((math.sqrt(8 * S + 1) - 1) // 2)) for k in range(max_k, 0, -1): if (2 * S) % k != 0: continue m = (2 * S...
simplelr_Apps
[ { "content": "Question:\nGiven an integer n, the task is to find the length of the longest sequence of consecutive integers from the set {1, 2, ..., n} such that the difference between every pair of consecutive integers in the sequence is exactly one and they all sum up to a given integer S.\n\nImplement a func...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5783, "level": 1, "question": "Given an integer n, the task is to find the length of the longest sequence of consecutive integers from the set {1, 2, ..., n} such that the difference between every pair of consecutive integers in the sequence is exactly one and they all sum up to a g...
def categorize_items(items): integers = 0 floats = 0 strings = 0 booleans = 0 for item in items: if isinstance(item, bool): booleans += 1 elif isinstance(item, int): integers += 1 elif isinstance(item, float): floats += 1 elif isin...
simplelr_Taco
[ { "content": "Question:\nWrite a function that takes a list/array of mixed elements and categorizes them based on their types, providing the following information:\n\n* Number of integer items\n* Number of float items\n* Number of string items\n* Number of boolean items\n \nThe information should be returned ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5784, "level": 1, "question": "Write a function that takes a list/array of mixed elements and categorizes them based on their types, providing the following information:\n\n* Number of integer items\n* Number of float items\n* Number of string items\n* Number of boolean items\n \n...
def single_character_deletions(s): deletions = [] for i in range(len(s)): deletion = s[:i] + s[i+1:] deletions.append(deletion) return deletions
simplelr_Filter
[ { "content": "Question:\nThis is the first step in a multi-step project where I am trying to generate different variations of a given input string\n\nTo start, I need a function that takes a string as input and returns a list of all possible single-character deletions from that string.\n\nFor example, if the in...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5785, "level": 1, "question": "This is the first step in a multi-step project where I am trying to generate different variations of a given input string\n\nTo start, I need a function that takes a string as input and returns a list of all possible single-character deletions from tha...
def reverse_characters_in_words(sentence): words = sentence.split() reversed_words = [word[::-1] for word in words] return ' '.join(reversed_words)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to reverse the order of characters in each word within a sentence. The function should not reverse the单词长度,只应该reverse单词中的字符顺序。例如,输入 \"Hello World from Alibaba Cloud\" 应该输出 \"olleH dlroW morf alibaba dlrow\"。\nAnswer:\nLet's think step by step.\n", "role": "us...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5786, "level": 1, "question": "Write a python function to reverse the order of characters in each word within a sentence. The function should not reverse the单词长度,只应该reverse单词中的字符顺序。例如,输入 \"Hello World from Alibaba Cloud\" 应该输出 \"olleH dlroW morf alibaba dlrow\"。", "split": "train"...
def longest_common_prefix(paths: list[str]) -> str: if not paths: return "" prefix = "" i = 0 while True: # Check if all paths have a character at position i for path in paths: if i >= len(path): return prefix # Get the current ch...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are given a list of strings representing file paths in a Unix-like filesystem. Each path is a string where components are separated by the '/' character. Your task is to implement an efficient function to find the longest common prefix of the given file path...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5787, "level": 1, "question": "### Problem Statement\n\nYou are given a list of strings representing file paths in a Unix-like filesystem. Each path is a string where components are separated by the '/' character. Your task is to implement an efficient function to find the longest c...
import random def quick_sort(arr): if not arr: return [] arr_copy = arr.copy() stack = [(0, len(arr_copy) - 1)] while stack: low, high = stack.pop() if low >= high: continue # Choose a random pivot index pivot_index = random.randint(low,...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nSorting algorithms are fundamental concepts in computer science, with various types having different performance characteristics. The challenge here requires implementing the QuickSort algorithm, a widely used and efficient sorting algorithm based on the divide-...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5788, "level": 1, "question": "### Problem Statement\n\nSorting algorithms are fundamental concepts in computer science, with various types having different performance characteristics. The challenge here requires implementing the QuickSort algorithm, a widely used and efficient sor...
import os def is_file_writable(file_path): if os.path.isfile(file_path): return os.access(file_path, os.W_OK) else: return False
simplelr_Filter
[ { "content": "Question:\nCan you write a Python function that checks if a specified file exists and is writable? The function should return `True` if the file exists and is writable, and `False` otherwise.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5789, "level": 1, "question": "Can you write a Python function that checks if a specified file exists and is writable? The function should return `True` if the file exists and is writable, and `False` otherwise.", "split": "train" }
def decimal_to_binary(n): if n == 0: return '0' is_negative = False if n < 0: is_negative = True n = abs(n) binary_digits = [] while n > 0: remainder = n % 2 binary_digits.append(str(remainder)) n = n // 2 binary_digits.reverse() if is_negative...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to convert a given number from decimal to binary in Python. You need to ensure that your function handles both positive and negative numbers.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5790, "level": 1, "question": "Write a function to convert a given number from decimal to binary in Python. You need to ensure that your function handles both positive and negative numbers.", "split": "train" }
def first_non_repeated_character(s): counts = {} for char in s: if char in counts: counts[char] += 1 else: counts[char] = 1 for char in s: if counts[char] == 1: return char return -1
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the first non-repeated character in a string. If there are no non-repeated characters, return -1. The function should handle both uppercase and lowercase characters. Consider 'A' and 'a' as different characters.\nAnswer:\nLet's think step by step.\n", "role"...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5791, "level": 1, "question": "Write a function to find the first non-repeated character in a string. If there are no non-repeated characters, return -1. The function should handle both uppercase and lowercase characters. Consider 'A' and 'a' as different characters.", "split": "t...
def intersection_of_arrays(a, b): set_a = set(a) set_b = set(b) common = set_a.intersection(set_b) return sorted(common)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the intersection of two arrays, ensuring that each element in the result is unique. The function should handle arrays of varying sizes and return the result as a sorted list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5792, "level": 1, "question": "Write a Python function to find the intersection of two arrays, ensuring that each element in the result is unique. The function should handle arrays of varying sizes and return the result as a sorted list.", "split": "train" }
def reverse_words(s): words = [] current_word = '' for char in s: if char == ' ': if current_word != '': words.append(current_word) current_word = '' else: current_word += char if current_word != '': words.append(current_wor...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to reverse the order of words in a string without using any external libraries or built-in string manipulation functions.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5793, "level": 1, "question": "Write a function to reverse the order of words in a string without using any external libraries or built-in string manipulation functions.", "split": "train" }
def shift_string_2(s): return ''.join([chr((ord(c) - ord('a') + 2) % 26 + ord('a')) for c in s])
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a string s of lowercase alphabetic characters, and returns the string obtained by shifting every character in s by 2 positions forward in the alphabet. Characters 'y' and 'z' should wrap around to 'a' and 'b', respectively.\n\nAssume the input string s will a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5794, "level": 1, "question": "Write a function that takes a string s of lowercase alphabetic characters, and returns the string obtained by shifting every character in s by 2 positions forward in the alphabet. Characters 'y' and 'z' should wrap around to 'a' and 'b', respectively.\...
import re def validate_username(username: str) -> bool: """ Validate a username. The username is valid if it starts with a letter, is at least 3 characters long but no more than 30 characters long, and contains only letters (a-z, A-Z), numbers (0-9), and/or underscores (_). Args: username...
simplelr_Filter
[ { "content": "Question:\nDesign a function that satisfies the following conditions:\n- The function will be used to validate a username.\n- The function should return `True` if the username is valid and `False` otherwise.\n- The username is valid if it:\n - Starts with a letter (either uppercase or lowercase)....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5795, "level": 1, "question": "Design a function that satisfies the following conditions:\n- The function will be used to validate a username.\n- The function should return `True` if the username is valid and `False` otherwise.\n- The username is valid if it:\n - Starts with a lett...
def list_to_nested_dict(lst): reversed_list = list(reversed(lst)) result = None for item in reversed_list: result = {item: result} return result
simplelr_Filter
[ { "content": "Question:\nCreate a Python function to convert a flat list into a dictionary with multiple levels. The keys should be the values from the list, and each key's value should be a dictionary to the next key, with the final key pointing to None. For example, given the list `['a', 'b', 'c']`, the funct...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5796, "level": 1, "question": "Create a Python function to convert a flat list into a dictionary with multiple levels. The keys should be the values from the list, and each key's value should be a dictionary to the next key, with the final key pointing to None. For example, given th...
def sort_tuples_by_key(tuples_list: list, key_index: int) -> list: """ Sort a list of tuples by the specified key index. Parameters: tuples_list (list): List of tuples to be sorted. key_index (int): Index of the tuple element to sort by. Returns: list: Sorted list of tuples. """ re...
simplelr_Algorithm
[ { "content": "Question:\n### Sorting a List of Tuples by a Specific Key\n\n#### Problem Statement\nYou are provided with a list of tuples, each containing multiple elements. Your task is to write a function that sorts the list based on one of the tuple elements (specified by its position in the tuple).\n\n#### ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5797, "level": 1, "question": "### Sorting a List of Tuples by a Specific Key\n\n#### Problem Statement\nYou are provided with a list of tuples, each containing multiple elements. Your task is to write a function that sorts the list based on one of the tuple elements (specified by i...
def longest_consecutive_sequence(arr): if not arr: return (None, 0) max_length = 1 current_length = 1 max_element = arr[0] for i in range(1, len(arr)): if arr[i] == arr[i-1]: current_length += 1 else: if current_length > max_length: ...
simplelr_Evol
[ { "content": "Question:\nImplement a function to determine the longest consecutive sequence of identical elements in a given array of integers and return the element and the length of that sequence. If there are multiple sequences of the same length, return the first one encountered.\n\nExample:\nInput: [1, 1, ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5798, "level": 1, "question": "Implement a function to determine the longest consecutive sequence of identical elements in a given array of integers and return the element and the length of that sequence. If there are multiple sequences of the same length, return the first one encou...
from typing import List def filter_and_sort(numbers: List[int]) -> List[int]: return sorted([x for x in numbers if x >= 0])
simplelr_Package
[ { "content": "Question:\nYou are required to write a function named `filter_and_sort` that filters a list of integers by removing any negative numbers, and then sorts the remaining numbers in ascending order. The function should take a list of integers as input and return a new list of non-negative integers sor...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 5799, "level": 1, "question": "You are required to write a function named `filter_and_sort` that filters a list of integers by removing any negative numbers, and then sorts the remaining numbers in ascending order. The function should take a list of integers as input and return a ne...