target
stringlengths
29
3.65k
data_source
stringclasses
12 values
prompt
listlengths
1
1
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
def extract_unique_words(sentence: str) -> list[str]: tokens = sentence.split() unique_words = set() for token in tokens: word = ''.join([c for c in token if c.isalpha()]) if word: unique_words.add(word.lower()) return sorted(unique_words)
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are tasked with implementing a text processing utility function for a Natural Language Processing (NLP) application. This function needs to detect and extract all unique words from a given sentence, ignoring case and excluding punctuation.\n\n### Description...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4600, "level": 1, "question": "### Problem Statement\n\nYou are tasked with implementing a text processing utility function for a Natural Language Processing (NLP) application. This function needs to detect and extract all unique words from a given sentence, ignoring case and exclud...
def longest_palindromic_substring(s: str) -> str: if not s: return '' max_length = 0 start = 0 end = 0 n = len(s) for i in range(n): # Odd length palindromes l, r = i, i while l >= 0 and r < n and s[l] == s[r]: current_length = r - l + 1 ...
simplelr_Taco
[ { "content": "Question:\nYou are given a string consisting of lowercase English letters. A contiguous substring is defined as a palindrome if it reads the same forwards and backwards. Your task is to determine the longest palindromic contiguous substring within the given string.\n\nIf there are multiple longest...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4601, "level": 1, "question": "You are given a string consisting of lowercase English letters. A contiguous substring is defined as a palindrome if it reads the same forwards and backwards. Your task is to determine the longest palindromic contiguous substring within the given strin...
def run_length_encoding(s: str) -> str: if not s: return "" result = [] current_char = s[0] count = 1 for char in s[1:]: if char == current_char: count += 1 else: result.append(f"{current_char}{count}") current_char = char count...
simplelr_Algorithm
[ { "content": "Question:\n### String Compression: Run-Length Encoding\n\nImplement a function `run_length_encoding(s: str) -> str` that takes a string `s` and returns a new string representing the run-length encoding of `s`. The run-length encoding of a string is generated by replacing sequences of the same char...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4602, "level": 1, "question": "### String Compression: Run-Length Encoding\n\nImplement a function `run_length_encoding(s: str) -> str` that takes a string `s` and returns a new string representing the run-length encoding of `s`. The run-length encoding of a string is generated by r...
from typing import List def sort_binary_numbers(bin_list: List[str]) -> List[str]: # Convert each binary string to its decimal equivalent decimals = [int(b, 2) for b in bin_list] # Sort the list of decimals in ascending order decimals.sort() # Convert each decimal back to a binary string and return...
simplelr_Taco
[ { "content": "Question:\nA software company conducts a debugging session where programmers are given a piece of code that contains some bugs. Programmers need to debug and correct the code to make it work as intended. The company has provided a task for you to solve.\n\nYou are given a list of strings, each rep...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4603, "level": 1, "question": "A software company conducts a debugging session where programmers are given a piece of code that contains some bugs. Programmers need to debug and correct the code to make it work as intended. The company has provided a task for you to solve.\n\nYou ar...
def remove_vowels(sentence): vowels = {'a', 'e', 'i', 'o', 'u'} result = [] for char in sentence: if char.lower() not in vowels: result.append(char) return ''.join(result)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to remove all the vowels from a sentence, considering both lowercase and uppercase vowels.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4604, "level": 1, "question": "Write a python function to remove all the vowels from a sentence, considering both lowercase and uppercase vowels.", "split": "train" }
def sumOfPrimes(N): if N < 2: return 0 sieve = [True] * (N + 1) sieve[0], sieve[1] = False, False for p in range(2, int(N ** 0.5) + 1): if sieve[p]: for multiple in range(p * p, N + 1, p): sieve[multiple] = False primes = [i for i, is_prime in enumerate(si...
simplelr_Taco
[ { "content": "Question:\nFind the sum of all prime numbers up to N.\n\nExample 1:\nInput:\nN = 10\nOutput: 17\nExplanation: The prime numbers less than or equal to 10 are 2, 3, 5, and 7, and their sum is 17.\n\nExample 2:\nInput:\nN = 20\nOutput: 77\nExplanation: The prime numbers less than or equal to 20 are 2...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4605, "level": 1, "question": "Find the sum of all prime numbers up to N.\n\nExample 1:\nInput:\nN = 10\nOutput: 17\nExplanation: The prime numbers less than or equal to 10 are 2, 3, 5, and 7, and their sum is 17.\n\nExample 2:\nInput:\nN = 20\nOutput: 77\nExplanation: The prime num...
def twoSum(nums, target): d = {} for i, num in enumerate(nums): complement = target - num if complement in d: return [d[complement], i] d[num] = i return None # If no pair found
simplelr_Filter
[ { "content": "Question:\nGiven an integer array nums, find two numbers such that they add up to a specific target. The function twoSum should return indices of the two numbers such that they were located before in the original array. \n\nExample: nums = [2,7,11,15], target = 9\n// returns [0, 1] (because nums[0...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4606, "level": 1, "question": "Given an integer array nums, find two numbers such that they add up to a specific target. The function twoSum should return indices of the two numbers such that they were located before in the original array. \n\nExample: nums = [2,7,11,15], target = 9...
def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True
simplelr_Filter
[ { "content": "Question:\nMake a code to determine whether a given number is prime or not. Additionally, optimize the code to reduce the time complexity to O(sqrt(n)).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4607, "level": 1, "question": "Make a code to determine whether a given number is prime or not. Additionally, optimize the code to reduce the time complexity to O(sqrt(n)).", "split": "train" }
def find_max_min(lst): max_val = max(lst) min_val = min(lst) return (max_val, min_val) # Example usage: numbers = [5, 2, 9, 1, 5, 6] result = find_max_min(numbers) print(result) # Expected output: (9, 1)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to find the maximum and minimum values in a list of integers. The function should take a list of integers as input and return a tuple containing the maximum and minimum values. Use the built-in max() and min() functions to find the maximum and minimum values. Tes...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4608, "level": 1, "question": "Write a Python function to find the maximum and minimum values in a list of integers. The function should take a list of integers as input and return a tuple containing the maximum and minimum values. Use the built-in max() and min() functions to find ...
def count_digits(s): counts = {str(i): 0 for i in range(10)} for char in s: if char.isdigit(): counts[char] += 1 return counts
simplelr_Filter
[ { "content": "Question:\nI have a string consisting of digits and whitespace characters. I need to count the occurrence of each digit (from 0 to 9) in the string. Please provide a Python solution to achieve this.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4609, "level": 1, "question": "I have a string consisting of digits and whitespace characters. I need to count the occurrence of each digit (from 0 to 9) in the string. Please provide a Python solution to achieve this.", "split": "train" }
import torch def normalize_images(images: torch.Tensor) -> torch.Tensor: """ Normalize a batch of grayscale images using z-score normalization. Parameters: images (torch.Tensor): A 4D tensor of shape (batch_size, height, width, channels) representing a batch of images. Returns: torch....
simplelr_Docs
[ { "content": "Question:\nImage Batch Normalization\n\n**Objective:**\nWrite a PyTorch function to normalize batches of grayscale image tensors. The function should perform z-score normalization on each image in the batch.\n\n**Problem Statement:**\n\nYou are provided with a 4-dimensional tensor `images` represe...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4610, "level": 1, "question": "Image Batch Normalization\n\n**Objective:**\nWrite a PyTorch function to normalize batches of grayscale image tensors. The function should perform z-score normalization on each image in the batch.\n\n**Problem Statement:**\n\nYou are provided with a 4-...
def max_sum_path(grid): n = len(grid) if n == 0: return 0 dp = [[0 for _ in range(n)] for _ in range(n)] dp[0][0] = grid[0][0] for i in range(n): for j in range(n): if i == 0 and j == 0: continue if i == 0: dp[i][j] = grid[...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a grid of size `n x n` consisting of non-negative integers. A robot is initially located at the top-left corner of the grid (position `(0, 0)`) and the robot moves right, down, or diagonally right-down through the grid to reach the bottom-right corner (position `(n-1, n-1)...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4611, "level": 1, "question": "You are given a grid of size `n x n` consisting of non-negative integers. A robot is initially located at the top-left corner of the grid (position `(0, 0)`) and the robot moves right, down, or diagonally right-down through the grid to reach the bottom...
def min_removals_to_avoid_adjacent_duplicates(s): dp = [0] * 26 for c in s: current = ord(c) - ord('a') max_prev = 0 for i in range(26): if i != current: if dp[i] > max_prev: max_prev = dp[i] new_val = max_prev + 1 if new_va...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s` consisting of lowercase letters, you need to remove the minimum number of characters from `s` so that any two adjacent characters are different. Return the minimum number of characters you need to remove. \n\nFor example, for `s = \"aaabbb\"`, the result would be `4` ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4612, "level": 1, "question": "Given a string `s` consisting of lowercase letters, you need to remove the minimum number of characters from `s` so that any two adjacent characters are different. Return the minimum number of characters you need to remove. \n\nFor example, for `s = \"...
def translateToMorse(sentence: str) -> str: morse_code = { 'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S':...
simplelr_Taco
[ { "content": "Question:\n## Sentence to Morse Code translator\n\nIn this coding challenge, you need to write a function `translateToMorse` that converts a given sentence into Morse code. Morse code is a method used in telecommunication to encode text characters into sequences of dots, dashes, and spaces. Each l...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4613, "level": 1, "question": "## Sentence to Morse Code translator\n\nIn this coding challenge, you need to write a function `translateToMorse` that converts a given sentence into Morse code. Morse code is a method used in telecommunication to encode text characters into sequences ...
def fibonacci_series(n): if n <= 0: return [] series = [0, 1] while True: next_num = series[-1] + series[-2] if next_num > n: break series.append(next_num) return series
simplelr_Evol
[ { "content": "Question:\nImplement a function that generates the Fibonacci series up to a given number `n`, where `n` is a positive integer. The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The sequence goes like 0, 1, 1, 2, 3, ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4614, "level": 1, "question": "Implement a function that generates the Fibonacci series up to a given number `n`, where `n` is a positive integer. The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. The...
def generate_pascals_triangle(n: int) -> list: if n == 0: return [] result = [] result.append([1]) for i in range(1, n): prev_row = result[i-1] new_row = [1] for j in range(1, i): new_element = prev_row[j-1] + prev_row[j] new_row.append(new_element...
simplelr_Algorithm
[ { "content": "Question:\n**Problem Statement:**\nYou are given an integer `n` representing the number of rows of Pascal’s triangle. Your task is to implement the function `generate_pascals_triangle(n: int) -> List[List[int]]` which returns a list of lists of integers representing the first `n` rows of Pascal's ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4615, "level": 1, "question": "**Problem Statement:**\nYou are given an integer `n` representing the number of rows of Pascal’s triangle. Your task is to implement the function `generate_pascals_triangle(n: int) -> List[List[int]]` which returns a list of lists of integers represent...
def count_elements(nested_dict): count = 0 for key in nested_dict: count += 1 if isinstance(nested_dict[key], dict): count += count_elements(nested_dict[key]) return count
simplelr_Filter
[ { "content": "Question:\nIf a nested dictionary in Python, how do you write code to count the total number of elements in it including the elements in the nested dictionaries?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4616, "level": 1, "question": "If a nested dictionary in Python, how do you write code to count the total number of elements in it including the elements in the nested dictionaries?", "split": "train" }
def sum_of_consecutive_pairs(lst): result = [] for i in range(len(lst) - 1): result.append(lst[i] + lst[i + 1]) return result
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a list of integers and returns a new list where each element is the sum of consecutive pairs of integers from the original list. For example, if the input list is [1, 2, 3, 4], the function should return [3, 5, 7] since 1+2=3, 2+3=5, and 3+4=7.\nAnswer:\nLet...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4617, "level": 1, "question": "Create a function that takes a list of integers and returns a new list where each element is the sum of consecutive pairs of integers from the original list. For example, if the input list is [1, 2, 3, 4], the function should return [3, 5, 7] since 1+2...
def find_single_element(arr): res = 0 for num in arr: res ^= num return res
simplelr_Taco
[ { "content": "Question:\nThere is an array of integers where each element appears twice except for one. Find that single one without using extra memory. Your solution should have a linear runtime complexity.\n\nExample 1:\nInput:\narr = [2, 2, 1]\nOutput:\n1\n\nExample 2:\nInput:\narr = [4, 1, 2, 1, 2]\nOutput:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4618, "level": 1, "question": "There is an array of integers where each element appears twice except for one. Find that single one without using extra memory. Your solution should have a linear runtime complexity.\n\nExample 1:\nInput:\narr = [2, 2, 1]\nOutput:\n1\n\nExample 2:\nInp...
def largest_rectangle_area(heights): stack = [-1] # Initialize stack with base index max_area = 0 n = len(heights) for i in range(n): # If the current height is less than the height at the top of stack, calculate area while stack[-1] != -1 and heights[i] < heights[stack[-1]]: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a **0-indexed** integer array `heights` of length `n` representing the height of `n` bars. Assume that each bar has a width of `1`. Find the area of the largest rectangle that can be formed within the bars, where its sides are parallel to the x-axis and y-axis. The area of...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4619, "level": 1, "question": "You are given a **0-indexed** integer array `heights` of length `n` representing the height of `n` bars. Assume that each bar has a width of `1`. Find the area of the largest rectangle that can be formed within the bars, where its sides are parallel to...
def do_rectangles_intersect(rect1, rect2): (x1, y1), (x2, y2) = rect1 left1, right1 = min(x1, x2), max(x1, x2) bottom1, top1 = min(y1, y2), max(y1, y2) (x3, y3), (x4, y4) = rect2 left2, right2 = min(x3, x4), max(x3, x4) bottom2, top2 = min(y3, y4), max(y3, y4) x_overlap = left1 <= right2 a...
simplelr_Filter
[ { "content": "Question:\nCreate a python program to check if 2 rectangles intersect with each other. The rectangles are defined as two set of coordinates (top left and bottom right coordinates). A rectangle is defined as rect(pos1, pos2) where pos1 and pos2 are tuples with x and y coordinates.\nAnswer:\nLet's t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4620, "level": 1, "question": "Create a python program to check if 2 rectangles intersect with each other. The rectangles are defined as two set of coordinates (top left and bottom right coordinates). A rectangle is defined as rect(pos1, pos2) where pos1 and pos2 are tuples with x a...
from typing import List def findTwoIndices(nums: List[int], target: int) -> List[int]: seen = {} for i, num in enumerate(nums): complement = target - num if complement in seen: return [seen[complement], i] seen[num] = i return []
simplelr_Apps
[ { "content": "Question:\nGiven an array of integers and an integer target, find two distinct indices in the array such that the integers at those indices add up to the target value. Assume that each input would have exactly one solution, and you may not use the same element twice.\n\nWrite a function `findTwoIn...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4621, "level": 1, "question": "Given an array of integers and an integer target, find two distinct indices in the array such that the integers at those indices add up to the target value. Assume that each input would have exactly one solution, and you may not use the same element tw...
def contains_all_elements(s, chars): return set(chars).issubset(s)
simplelr_Filter
[ { "content": "Question:\nWrite a Python function that checks if a given string contains all elements from a given list of characters. The string and the list of characters can be of any length and the characters in the string do not need to be in the same order as in the list. However, the string must contain a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4622, "level": 1, "question": "Write a Python function that checks if a given string contains all elements from a given list of characters. The string and the list of characters can be of any length and the characters in the string do not need to be in the same order as in the list....
def max_sum_subarray(arr, k): n = len(arr) if k <= 0 or n < k: return -1 current_sum = sum(arr[:k]) max_sum = current_sum for i in range(k, n): current_sum = current_sum - arr[i - k] + arr[i] if current_sum > max_sum: max_sum = current_sum return max_sum
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a list of integers and an integer k, and returns the maximum sum of any contiguous subarray of size k.\n\nA subarray is a contiguous part of an array. The goal is to find the contiguous subarray of length k that has the maximum sum and return the sum.\n\nIf t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4623, "level": 1, "question": "Write a function that takes a list of integers and an integer k, and returns the maximum sum of any contiguous subarray of size k.\n\nA subarray is a contiguous part of an array. The goal is to find the contiguous subarray of length k that has the maxi...
import math def find_nearest_point(grid_width: int, grid_height: int, points: list[tuple[int, int]], reference_point: tuple[int, int]) -> tuple[int, int] | None: if not points: return None nearest_point = points[0] min_dist = math.sqrt((reference_point[0] - nearest_point[0])**2 + (reference_po...
simplelr_Package
[ { "content": "Question:\nYou are given a grid with 2D coordinates and a collection of points. The task is to write a function `find_nearest_point(grid_width: int, grid_height: int, points: List[Tuple[int, int]], reference_point: Tuple[int, int]) -> Tuple[int, int]` that will find the point nearest to a given re...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4624, "level": 1, "question": "You are given a grid with 2D coordinates and a collection of points. The task is to write a function `find_nearest_point(grid_width: int, grid_height: int, points: List[Tuple[int, int]], reference_point: Tuple[int, int]) -> Tuple[int, int]` that will f...
from collections import defaultdict import json import statistics def average_scores(filename: str) -> dict: with open(filename, 'r') as file: students = json.load(file) subjects = defaultdict(list) for student in students: for key, value in student.items(): if key != 'name...
simplelr_Package
[ { "content": "Question:\nIn this exercise, you'll work with JSON file processing and gain familiarity with the `json` and `statistics` libraries in Python. You will implement a function named `average_scores` that reads a JSON file containing information about students and their scores in various subjects. The ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4625, "level": 1, "question": "In this exercise, you'll work with JSON file processing and gain familiarity with the `json` and `statistics` libraries in Python. You will implement a function named `average_scores` that reads a JSON file containing information about students and the...
def maximum_product_of_three(nums): nums.sort() n = len(nums) candidate1 = nums[-1] * nums[-2] * nums[-3] candidate2 = nums[0] * nums[1] * nums[-1] return max(candidate1, candidate2)
simplelr_Evol
[ { "content": "Question:\nYou have been given a task to find the maximum product of any three distinct numbers in a list. The details of the problem are as follows: You are provided with an integer array `nums` which consists of `n` elements. The `nums` array can contain both positive and negative integers.\n\nY...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4626, "level": 1, "question": "You have been given a task to find the maximum product of any three distinct numbers in a list. The details of the problem are as follows: You are provided with an integer array `nums` which consists of `n` elements. The `nums` array can contain both p...
def format_invitations(participants): lines = [] for participant in participants: lines.append(f"{participant['last_name']}, {participant['first_name']}") return '\n'.join(lines)
simplelr_Taco
[ { "content": "Question:\nYou are organizing a charity event and you need to print invitations for the attendees. Each invitation should include the full names of the participants in a formatted list. The participants are represented as a list of dictionaries, where each dictionary contains the first and last na...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4627, "level": 1, "question": "You are organizing a charity event and you need to print invitations for the attendees. Each invitation should include the full names of the participants in a formatted list. The participants are represented as a list of dictionaries, where each dictio...
def a_or_empty(a, b): return a if not b else ''
simplelr_Filter
[ { "content": "Question:\nI.e., in a function with two arguments, `a`, and `b`, if `b` is `False`, `a` should be returned. If `b` is `True`, the function should return an empty string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4628, "level": 1, "question": "I.e., in a function with two arguments, `a`, and `b`, if `b` is `False`, `a` should be returned. If `b` is `True`, the function should return an empty string.", "split": "train" }
from collections import defaultdict def count_pairs(arr, k): freq = defaultdict(int) count = 0 for num in arr: complement = k - num count += freq.get(complement, 0) freq[num] += 1 return count
simplelr_Taco
[ { "content": "Question:\nGiven an array of integers and an integer k, your task is to determine the number of distinct pairs (i, j) such that arr[i] + arr[j] equals k and i < j. If no such pairs exist, return 0.\n\nExample 1:\nInput:\narr = [1, 2, 3, 4, 3]\nk = 6\nOutput:\n2\nExplanation:\nThe pairs (2, 4) and ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4629, "level": 1, "question": "Given an array of integers and an integer k, your task is to determine the number of distinct pairs (i, j) such that arr[i] + arr[j] equals k and i < j. If no such pairs exist, return 0.\n\nExample 1:\nInput:\narr = [1, 2, 3, 4, 3]\nk = 6\nOutput:\n2\n...
def multiplication_table(number, max_rows=10): for i in range(1, max_rows + 1): print(f"{number} x {i} = {number * i}")
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that takes a number as an argument and prints the multiplication table of that number up to 10. The function should also allow the user to specify the maximum number of rows for the table, defaulting to 10 if not specified. Ensure the output is neatly formatted....
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4630, "level": 1, "question": "Create a Python function that takes a number as an argument and prints the multiplication table of that number up to 10. The function should also allow the user to specify the maximum number of rows for the table, defaulting to 10 if not specified. Ens...
def set_size(s): count = 0 for _ in s: count += 1 return count
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to find the size of a set in Python, i.e., the number of elements in the set. Do not use python's built-in len() function.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4631, "level": 1, "question": "Write a python function to find the size of a set in Python, i.e., the number of elements in the set. Do not use python's built-in len() function.", "split": "train" }
def shortest_path(n: int, m: int) -> int: a = n + m - 2 b = min(n - 1, m - 1) result = 1 for i in range(1, b + 1): result = result * (a - b + i) // i return result
simplelr_Algorithm
[ { "content": "Question:\n### Coding Assessment Question\n\n#### Shortest Path In a Grid\n\nYou are required to implement a function that calculates the shortest path from the top-left corner to the bottom-right corner of a `n x m` grid. You may only move right or down at any point in time.\n\n#### Function Sign...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4632, "level": 1, "question": "### Coding Assessment Question\n\n#### Shortest Path In a Grid\n\nYou are required to implement a function that calculates the shortest path from the top-left corner to the bottom-right corner of a `n x m` grid. You may only move right or down at any p...
def construct_sentence(words): if not words: return "" return ' '.join(words) + '.'
simplelr_Prefill
[ { "content": "Question:\nCreate a function that constructs a sentence from a given list of words.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4633, "level": 1, "question": "Create a function that constructs a sentence from a given list of words.", "split": "train" }
def max_subarray_sum(arr): if not arr: return 0 # or raise ValueError("Array is empty") max_current = max_global = arr[0] for num in arr[1:]: max_current = max(num, max_current + num) if max_current > max_global: max_global = max_current return max_global
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the maximum subarray sum using the Kadane's algorithm in Python. Kadane's algorithm is efficient for this problem with a time complexity of O(n).\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4634, "level": 1, "question": "Write a function to find the maximum subarray sum using the Kadane's algorithm in Python. Kadane's algorithm is efficient for this problem with a time complexity of O(n).", "split": "train" }
def find_nth_digit(n: int) -> int: d = 1 count = 9 start = 1 while n > d * count: n -= d * count d += 1 count *= 10 start *= 10 number = start + (n - 1) // d digit_index = (n - 1) % d return int(str(number)[digit_index])
simplelr_Data_Structure
[ { "content": "Question:\n#### Task\nYou need to implement a function to find the `n`-th digit in a sequence where all positive integers are concatenated in order (e.g., \"123456789101112...\").\n\n#### Function Signature\n```python\ndef find_nth_digit(n: int) -> int:\n pass\n```\n\n#### Input\n- `n` (1 ≤ n ≤...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4635, "level": 1, "question": "#### Task\nYou need to implement a function to find the `n`-th digit in a sequence where all positive integers are concatenated in order (e.g., \"123456789101112...\").\n\n#### Function Signature\n```python\ndef find_nth_digit(n: int) -> int:\n pass...
def sum_even_numbers(lst): total = 0 for num in lst: if num % 2 == 0: total += num return total # Example usage numbers = [1, 3, 5, 7, 9] result = sum_even_numbers(numbers) print(result) # Output: 0
simplelr_Filter
[ { "content": "Question:\nCreate a Python function that takes a list of integers as input and returns the sum of all the even numbers in the list. If there are no even numbers in the list, the function should return 0. Use the function to find the sum of the even numbers in the list [1, 3, 5, 7, 9].\nAnswer:\nLe...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4636, "level": 1, "question": "Create a Python function that takes a list of integers as input and returns the sum of all the even numbers in the list. If there are no even numbers in the list, the function should return 0. Use the function to find the sum of the even numbers in the...
def is_palindrome(s): return s == s[::-1]
simplelr_Apps
[ { "content": "Question:\nGiven a string containing only lowercase letters, write a function to determine if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces and punctuation).\n\n### Examples\n```\n\"racecar\" ->...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4637, "level": 1, "question": "Given a string containing only lowercase letters, write a function to determine if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces and punctuation).\n...
def rotate_array(arr: list, k: int) -> list: n = len(arr) if n == 0 or k == 0: return arr effective_k = k % n return arr[-effective_k:] + arr[:-effective_k]
simplelr_Algorithm
[ { "content": "Question:\n### Array Rotation\n\n#### Scenario\nIn data processing, it's common to perform transformations on arrays for various purposes such as data normalization, visualization, or algorithm optimizations. One transformation that often arises is circular array rotation. Your task is to write a ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4638, "level": 1, "question": "### Array Rotation\n\n#### Scenario\nIn data processing, it's common to perform transformations on arrays for various purposes such as data normalization, visualization, or algorithm optimizations. One transformation that often arises is circular array...
from collections import deque def shortest_path_in_maze(grid, start, end): if start == end: return 0 rows = len(grid) if rows == 0: return -1 cols = len(grid[0]) start_row, start_col = start end_row, end_col = end if grid[start_row][start_col] == 1 or grid[end...
simplelr_Leetcode
[ { "content": "Question:\nYou are given a 2D integer grid `grid` representing a maze where `1` represents a wall and `0` represents an open path. You are also given two pairs of integers, `start` and `end`, where `start = [startRow, startCol]` represents your starting position in the maze and `end = [endRow, end...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4639, "level": 1, "question": "You are given a 2D integer grid `grid` representing a maze where `1` represents a wall and `0` represents an open path. You are also given two pairs of integers, `start` and `end`, where `start = [startRow, startCol]` represents your starting position ...
from typing import List def max_path_value(grid: List[List[int]]) -> int: m = len(grid) n = len(grid[0]) if m > 0 else 0 # Create a DP table initialized with zeros dp = [[0 for _ in range(n)] for _ in range(m)] # Initialize the starting cell dp[0][0] = grid[0][0] # Fill the f...
simplelr_Algorithm
[ { "content": "Question:\n### Scenario\nYou are given a matrix representing a 2D grid where some cells contain items. Each cell can either be empty or contain an item with a positive integer value representing its total worth. Your task is to determine the maximum value path from the top-left corner of the grid ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4640, "level": 1, "question": "### Scenario\nYou are given a matrix representing a 2D grid where some cells contain items. Each cell can either be empty or contain an item with a positive integer value representing its total worth. Your task is to determine the maximum value path fr...
def filter_noisy_readings(readings, threshold): last_valid = {} filtered = [] for reading in readings: t, s, v = reading if s not in last_valid: filtered.append(reading) last_valid[s] = v else: prev_v = last_valid[s] if abs(v - prev_v) ...
simplelr_Package
[ { "content": "Question:\nYou are working on a sensor data processing system that needs to handle periodic readings from sensors. Each reading consists of three values: a timestamp, a sensor ID, and a reading value. Your task is to write a function that identifies and filters out noisy sensor data. A sensor read...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4641, "level": 1, "question": "You are working on a sensor data processing system that needs to handle periodic readings from sensors. Each reading consists of three values: a timestamp, a sensor ID, and a reading value. Your task is to write a function that identifies and filters o...
def get_top_two_levels(fqdn): # Remove any trailing dot to handle cases like "example.com." fqdn = fqdn.rstrip('.') parts = fqdn.split('.') # Extract the last two parts top_two = '.'.join(parts[-2:]) return top_two
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes a string representing a fully qualified domain name (FQDN) and returns the top two levels of the domain. For example, for the input \"example.co.uk\", the function should return \"co.uk\".\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4642, "level": 1, "question": "Create a function that takes a string representing a fully qualified domain name (FQDN) and returns the top two levels of the domain. For example, for the input \"example.co.uk\", the function should return \"co.uk\".", "split": "train" }
import math def find_roots(a: float, b: float, c: float) -> dict[str, float]: if a == 0: raise ValueError("Coefficient 'a' cannot be zero") discriminant = b ** 2 - 4 * a * c if discriminant < 0: return {} elif discriminant == 0: root = (-b) / (2 * a) return {'r...
simplelr_Algorithm
[ { "content": "Question:\n### Polynomial Roots Finder\n\n#### Problem Description\nYou are required to compute the real roots of a quadratic polynomial. The polynomial is represented as `ax^2 + bx + c = 0`, and its real roots can be found using the quadratic formula:\n\\[ x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4643, "level": 1, "question": "### Polynomial Roots Finder\n\n#### Problem Description\nYou are required to compute the real roots of a quadratic polynomial. The polynomial is represented as `ax^2 + bx + c = 0`, and its real roots can be found using the quadratic formula:\n\\[ x = \...
def daily_temperatures(temp): stack = [] res = [0] * len(temp) for i in range(len(temp)): while stack and temp[i] > temp[stack[-1]]: j = stack.pop() res[j] = i - j stack.append(i) return res
simplelr_Code_Contests
[ { "content": "Question:\nproblem\n\nYou are given an array representing the daily temperatures for a week. Write a program to find out how many days are warmer than the current day for each day in the week. The temperature is provided as a list of integers representing the temperature for each day.\n\nThe outpu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4644, "level": 1, "question": "problem\n\nYou are given an array representing the daily temperatures for a week. Write a program to find out how many days are warmer than the current day for each day in the week. The temperature is provided as a list of integers representing the tem...
def longest_inverted_binary_sequence(arr): max_count = 0 current = 0 for num in arr: inverted = 1 - num if inverted == 1: current += 1 if current > max_count: max_count = current else: current = 0 return max_count
simplelr_Filter
[ { "content": "Question:\nDevelop a Python script that takes an array of binary values as an input. The script should first invert the binary values (i.e., change 0's to 1's and 1's to 0's). Then, after the inversion, the script should find the length of the longest sequence of 1's in the new array. The function...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4645, "level": 1, "question": "Develop a Python script that takes an array of binary values as an input. The script should first invert the binary values (i.e., change 0's to 1's and 1's to 0's). Then, after the inversion, the script should find the length of the longest sequence of...
def symmetric_difference(list1, list2): common = set(list1) & set(list2) return [x for x in list1 if x not in common] + [x for x in list2 if x not in common]
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to create a new list which contains the elements of two lists but excludes the elements that are present in both lists.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4646, "level": 1, "question": "Write a python function to create a new list which contains the elements of two lists but excludes the elements that are present in both lists.", "split": "train" }
def reverse_string(s): return s[::-1] # Example usage: print(reverse_string("Good Morning!")) # Output: "!gninroM dooG"
simplelr_Filter
[ { "content": "Question:\nWrite a Python function to reverse a string and return it. For example, if the input is \"hello,\" the output should be \"olleh.\" Ensure that your function handles any string input, including special characters and numbers. At the end, demonstrate your function by reversing the string ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4647, "level": 1, "question": "Write a Python function to reverse a string and return it. For example, if the input is \"hello,\" the output should be \"olleh.\" Ensure that your function handles any string input, including special characters and numbers. At the end, demonstrate you...
def max_difference(arr): if len(arr) < 2: return 0 min_so_far = arr[0] max_diff = 0 for num in arr[1:]: current_diff = num - min_so_far if current_diff > max_diff: max_diff = current_diff if num < min_so_far: min_so_far = num return max_diff
simplelr_Filter
[ { "content": "Question:\nGiven a list of integers, write a Python function to find the maximum difference between two elements in the list such that the larger element appears after the smaller one in the list. If no such pair exists, return 0.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4648, "level": 1, "question": "Given a list of integers, write a Python function to find the maximum difference between two elements in the list such that the larger element appears after the smaller one in the list. If no such pair exists, return 0.", "split": "train" }
def product_except_self(nums): n = len(nums) if n == 0: return [] prefix = [1] * n for i in range(1, n): prefix[i] = prefix[i-1] * nums[i-1] suffix = [1] * n for i in range(n-2, -1, -1): suffix[i] = suffix[i+1] * nums[i+1] return [prefix[i] * suffix[i] ...
simplelr_Apps
[ { "content": "Question:\nWrite a function that takes a list of integers and returns the product of all the elements in the list except the element at the current index.\n\nFor example, given the list `[1, 2, 3, 4]`, the function should return `[24, 12, 8, 6]`. For the input `[2, 0, 3, 4]`, the output should be ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4649, "level": 1, "question": "Write a function that takes a list of integers and returns the product of all the elements in the list except the element at the current index.\n\nFor example, given the list `[1, 2, 3, 4]`, the function should return `[24, 12, 8, 6]`. For the input `[...
def longestPalindromeSubseq(s1): n = len(s1) if n == 0: return 0 dp = [[0] * n for _ in range(n)] for i in range(n-1, -1, -1): for j in range(i, n): if i == j: dp[i][j] = 1 else: if s1[i] == s1[j]: if j == i...
simplelr_Taco
[ { "content": "Question:\nGiven two strings `s1` and `s2`, find the length of their longest palindromic subsequence. A subsequence is derived from another string by deleting some or no characters without changing the order of the remaining characters. A palindromic subsequence is a subsequence that reads the sam...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4650, "level": 1, "question": "Given two strings `s1` and `s2`, find the length of their longest palindromic subsequence. A subsequence is derived from another string by deleting some or no characters without changing the order of the remaining characters. A palindromic subsequence ...
def has_unique_chars(s): seen = set() for char in s: if char in seen: return False seen.add(char) return True
simplelr_Prefill
[ { "content": "Question:\nWrite a function to check if a string contains only unique characters. How would you implement this function?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4651, "level": 1, "question": "Write a function to check if a string contains only unique characters. How would you implement this function?", "split": "train" }
def repeatedSubstringPattern(s: str) -> bool: n = len(s) for d in range(1, n // 2 + 1): if n % d == 0: k = n // d if s == s[:d] * k: return True return False
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\n**Repeated Substring Pattern**\n\nGiven a non-empty string `s`, your task is to determine if the string can be constructed by taking a substring and appending multiple copies of the substring together. You need to implement a function that returns `True` if the ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4652, "level": 1, "question": "### Problem Statement\n\n**Repeated Substring Pattern**\n\nGiven a non-empty string `s`, your task is to determine if the string can be constructed by taking a substring and appending multiple copies of the substring together. You need to implement a f...
def selection_sort(lst): for i in range(len(lst)): min_pos = i for j in range(i+1, len(lst)): if lst[j] < lst[min_pos]: min_pos = j lst[i], lst[min_pos] = lst[min_pos], lst[i] return lst # Example usage: numbers = [64, 25, 12, 22, 11] print("Original list:", ...
simplelr_Filter
[ { "content": "Question:\nGenerate a Python code to sort a list of integers in ascending order using the selection sort algorithm.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4653, "level": 1, "question": "Generate a Python code to sort a list of integers in ascending order using the selection sort algorithm.", "split": "train" }
from collections import ChainMap, Counter, OrderedDict from typing import List, Dict, Tuple def process_data(data: List[Dict[str, str]]) -> Tuple[ChainMap, Dict[str, Counter], OrderedDict]: """ Processes the input data and returns required data structures. Args: data: List[Dict[str, str]] - A list of ...
simplelr_Docs
[ { "content": "Question:\nYou are tasked with building an advanced data processing pipeline that involves combining multiple types of data using `collections.ChainMap`, counting occurrences using `collections.Counter`, and maintaining an order of processing using `collections.OrderedDict`. \n\n#### Requirements:...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4654, "level": 1, "question": "You are tasked with building an advanced data processing pipeline that involves combining multiple types of data using `collections.ChainMap`, counting occurrences using `collections.Counter`, and maintaining an order of processing using `collections.O...
def is_palindrome(s: str) -> bool: """ Checks if a string is a palindrome. This function removes spaces and punctuation, converts the string to lowercase, and checks if it reads the same backward as forward. Args: s (str): The input string. Returns: bool: True if the string is...
simplelr_Filter
[ { "content": "Question:\nGiven a string, determine if it's a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward (ignoring spaces, punctuation, and capitalization).\n\nHere is an example:\n\nInput: \"A man, a plan, a canal, Panama\"\nOutpu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4655, "level": 1, "question": "Given a string, determine if it's a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward (ignoring spaces, punctuation, and capitalization).\n\nHere is an example:\n\nInput: \"A ma...
def gcs_score(eye: int, verbal: int, motor: int) -> int: """ Calculate the Glasgow Coma Scale (GCS) score based on the patient's responses. Args: eye (int): Eye opening response score (1-4) verbal (int): Verbal response score (1-5) motor (int): Motor response score (1-6) Return...
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to calculate the Glasgow Coma Scale (GCS) score based on the input values of the patient's responses in three categories: Eye opening response, Verbal response, and Motor response.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4656, "level": 1, "question": "Write a python function to calculate the Glasgow Coma Scale (GCS) score based on the input values of the patient's responses in three categories: Eye opening response, Verbal response, and Motor response.", "split": "train" }
from collections import defaultdict def count_distinct_elements(nums, k): n = len(nums) if k <= 0 or n < k: return [] res = [] freq = defaultdict(int) current = 0 # Initialize the first window for i in range(k): num = nums[i] if freq[num] == 0: current +=...
simplelr_Leetcode
[ { "content": "Question:\nGiven an integer array `nums` and an integer `k`, return _the count of distinct elements in every subarray of length `k`_. If the length of `nums` is less than `k`, return an empty list.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4657, "level": 1, "question": "Given an integer array `nums` and an integer `k`, return _the count of distinct elements in every subarray of length `k`_. If the length of `nums` is less than `k`, return an empty list.", "split": "train" }
from typing import List def unobstructed_buildings(heights: List[int]) -> List[int]: max_height = 0 result = [] for i in reversed(range(len(heights))): if heights[i] > max_height: result.append(i) max_height = heights[i] result.reverse() return result
simplelr_Codeforces
[ { "content": "Question:\nYou are given a sequence of integers representing the heights of buildings in a city skyline. A building's view is obstructed if there is any taller building between it and the horizon. You need to determine which buildings have an unobstructed view. Building heights are given from left...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4658, "level": 1, "question": "You are given a sequence of integers representing the heights of buildings in a city skyline. A building's view is obstructed if there is any taller building between it and the horizon. You need to determine which buildings have an unobstructed view. B...
from typing import List def trimmed_mean(array: List[int], percentage: float) -> float: sorted_array = sorted(array) n = len(sorted_array) each_end_trim = int((percentage / 2) * n / 100) start = each_end_trim end = n - each_end_trim if start >= end: return 0.0 # This case sho...
simplelr_Data_Structure
[ { "content": "Question:\nYou are given an array of integers and a percentage. Your task is to write a function that computes the trimmed mean of the array after excluding a specified percentage of the largest and smallest values.\n\n#### Function Signature\n```python\ndef trimmed_mean(array: List[int], percenta...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4659, "level": 1, "question": "You are given an array of integers and a percentage. Your task is to write a function that computes the trimmed mean of the array after excluding a specified percentage of the largest and smallest values.\n\n#### Function Signature\n```python\ndef trim...
def boolean_expression(a, b, use_and): if use_and: return a and b else: return a or b
simplelr_Prefill
[ { "content": "Question:\nCreate a function that takes two integers and a boolean value as inputs and returns the result of the boolean expression \"and\" if the boolean is True and \"or\" if the boolean is False. The integers can be any valid integers.\nAnswer:\nLet's think step by step.\n", "role": "user" ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4660, "level": 1, "question": "Create a function that takes two integers and a boolean value as inputs and returns the result of the boolean expression \"and\" if the boolean is True and \"or\" if the boolean is False. The integers can be any valid integers.", "split": "train" }
import re def parse_emails(input_file, output_file): with open(input_file, 'r') as file: content = file.read() # Regular expression to match email addresses email_pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' emails = re.findall(email_pattern, content) with open...
simplelr_Filter
[ { "content": "Question:\nI've got a file that contains a list of names and emails, each on a new line, in the following format:\nname1 email1\nname2 email2\nname3 email3\n...\nI'd like to extract all emails from this file and write them into a new file, one email per line.\n\nHere is my attempt:\n```python\nimp...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4661, "level": 1, "question": "I've got a file that contains a list of names and emails, each on a new line, in the following format:\nname1 email1\nname2 email2\nname3 email3\n...\nI'd like to extract all emails from this file and write them into a new file, one email per line.\n\n...
def count_pairs_with_sum(heights, k): seen = {} count = 0 for num in heights: complement = k - num if complement in seen: count += seen[complement] if num in seen: seen[num] += 1 else: seen[num] = 1 return count
simplelr_Leetcode
[ { "content": "Question:\nGiven an array of integers `heights` where `heights[i]` represents the height of person `i`, return the number of pairs `(i, j)` where `i < j` and `heights[i] + heights[j]` is equal to a target value `k`. If there are no such pairs, return `0`. Note that a pair `(i, j)` needs to have di...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4662, "level": 1, "question": "Given an array of integers `heights` where `heights[i]` represents the height of person `i`, return the number of pairs `(i, j)` where `i < j` and `heights[i] + heights[j]` is equal to a target value `k`. If there are no such pairs, return `0`. Note th...
def reverse_string(s): chars = list(s) left = 0 right = len(chars) - 1 while left < right: chars[left], chars[right] = chars[right], chars[left] left += 1 right -= 1 return ''.join(chars)
simplelr_Prefill
[ { "content": "Question:\nCreate a function that reverses a string without using any built-in string manipulation functions or slicing. The function should take a single string as an argument and return the reversed string.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4663, "level": 1, "question": "Create a function that reverses a string without using any built-in string manipulation functions or slicing. The function should take a single string as an argument and return the reversed string.", "split": "train" }
def rotate(matrix): 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.reverse() return matrix
simplelr_Apps
[ { "content": "Question:\nDesign an algorithm to rotate an `n x n` 2D matrix 90 degrees clockwise. You have to do this in-place, meaning you have to modify the input matrix directly. Do not allocate another matrix for the rotation.\n\nExample 1:\n\nInput: \n[\n [1,2,3],\n [4,5,6],\n [7,8,9]\n]\nOutput: \n[\n [7,...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4664, "level": 1, "question": "Design an algorithm to rotate an `n x n` 2D matrix 90 degrees clockwise. You have to do this in-place, meaning you have to modify the input matrix directly. Do not allocate another matrix for the rotation.\n\nExample 1:\n\nInput: \n[\n [1,2,3],\n [4,5,...
def remove_duplicates(s: str) -> str: last_occurrence = {} for i, c in enumerate(s): last_occurrence[c] = i added = set() result = [] for i, c in enumerate(s): if i == last_occurrence[c]: if c not in added: result.append(c) added.add(c) ...
simplelr_Leetcode
[ { "content": "Question:\nGiven a string `s` representing a sequence of lowercase English letters, return a new string where all the duplicate letters are removed and only the last occurrence of each letter is kept. The resulting string should preserve the order of their last occurrences in `s`. \n\n*For example...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4665, "level": 1, "question": "Given a string `s` representing a sequence of lowercase English letters, return a new string where all the duplicate letters are removed and only the last occurrence of each letter is kept. The resulting string should preserve the order of their last o...
def count_consecutive_characters(s): if not s: return [] result = [] current_char = s[0] count = 1 for char in s[1:]: if char == current_char: count += 1 else: result.append((current_char, count)) current_char = char count = 1 ...
simplelr_Evol
[ { "content": "Question:\nWrite a function that accepts a string of characters and returns a list of tuples, where each tuple consists of a character from the string and the number of times that character appears consecutively. Ensure that the order of characters in the output matches their first appearance in t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4666, "level": 1, "question": "Write a function that accepts a string of characters and returns a list of tuples, where each tuple consists of a character from the string and the number of times that character appears consecutively. Ensure that the order of characters in the output ...
def multiply_matrices(A, B): # Check if multiplication is possible if len(A[0]) != len(B): return "Matrices cannot be multiplied" # Initialize result matrix with zeros result = [[0 for _ in range(len(B[0]))] for _ in range(len(A))] # Perform matrix multiplication for i in range...
simplelr_Filter
[ { "content": "Question:\nHow can I multiply two matrices in Python?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4667, "level": 1, "question": "How can I multiply two matrices in Python?", "split": "train" }
def largestRectangleArea(heights): if not heights: return 0 n = len(heights) left = [-1] * n stack = [] for i in range(n): while stack and heights[stack[-1]] >= heights[i]: stack.pop() if stack: left[i] = stack[-1] else: left[i] = -...
simplelr_Apps
[ { "content": "Question:\nGiven a list of positive integers representing heights of buildings in a skyline, write a function that finds the maximum area rectangle that can fit entirely within the skyline silhouette. \n\nEach building is represented by a width of 1, and the height is given by the list of integers...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4668, "level": 1, "question": "Given a list of positive integers representing heights of buildings in a skyline, write a function that finds the maximum area rectangle that can fit entirely within the skyline silhouette. \n\nEach building is represented by a width of 1, and the heig...
def reverse_string(s): return s[::-1] # Example usage: original_string = "Hello, World!" reversed_string = reverse_string(original_string) print(reversed_string) # Output: "!dlroW ,olleH"
simplelr_Filter
[ { "content": "Question:\nIs it possible to reverse a string in Python without using the built-in reverse function? If so, can you provide an example?\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4669, "level": 1, "question": "Is it possible to reverse a string in Python without using the built-in reverse function? If so, can you provide an example?", "split": "train" }
def insert_at_index(lst, index, element): length = len(lst) if length == 0: adjusted_index = 0 else: if index < -length: adjusted_index = 0 elif index > length: adjusted_index = length else: adjusted_index = index lst.insert(adjusted_in...
simplelr_Prefill
[ { "content": "Question:\nWrite a function to insert an element at a specified index in a list. The function should handle the edge cases where the index might be out of bounds.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4670, "level": 1, "question": "Write a function to insert an element at a specified index in a list. The function should handle the edge cases where the index might be out of bounds.", "split": "train" }
from collections import deque def is_bipartite(n, edges): # Build adjacency list adj = [[] for _ in range(n)] for a, b in edges: adj[a].append(b) adj[b].append(a) color = [-1] * n # -1 indicates uncolored for i in range(n): if color[i] == -1: queue = d...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an undirected graph with `n` nodes labeled from `0` to `n-1`. The graph is described by a list of edges, where `edges[i] = [ai, bi]` represents an undirected edge between nodes `ai` and `bi`. Your task is to determine if this graph can be colored using only 2 colors such t...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4671, "level": 1, "question": "You are given an undirected graph with `n` nodes labeled from `0` to `n-1`. The graph is described by a list of edges, where `edges[i] = [ai, bi]` represents an undirected edge between nodes `ai` and `bi`. Your task is to determine if this graph can be...
def decode_string(encoded: str) -> str: stack = [] current_string = '' current_num = 0 for char in encoded: if char.isdigit(): current_num = current_num * 10 + int(char) elif char == '[': stack.append((current_string, current_num)) current_string = '' ...
simplelr_Algorithm
[ { "content": "Question:\n### Problem Statement\n\nYou are responsible for developing a function to decompress a string encoded with a specific run-length encoding format. This encoding format denotes repetitions of sequences in the form of `number[string]`, where `number` is the number of times the `string` sho...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4672, "level": 1, "question": "### Problem Statement\n\nYou are responsible for developing a function to decompress a string encoded with a specific run-length encoding format. This encoding format denotes repetitions of sequences in the form of `number[string]`, where `number` is t...
def remove_duplicates(lst): i = 0 while i < len(lst): j = 0 while j < i: if lst[j] == lst[i]: lst.pop(i) i -= 1 break j += 1 i += 1 return lst
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to remove duplicates from a list, preserving the initial order of the elements. You need to modify the original list itself without using any additional data structures.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4673, "level": 1, "question": "Write a python function to remove duplicates from a list, preserving the initial order of the elements. You need to modify the original list itself without using any additional data structures.", "split": "train" }
def maxDifference(arr, N): if N < 2: return 0 min_val = min(arr) max_val = max(arr) return max_val - min_val
simplelr_Taco
[ { "content": "Question:\nGiven an array `arr` consisting of `N` integers, find the maximum difference between any two elements `arr[i]` and `arr[j]` (i.e., |arr[i] - arr[j]|) such that there is no other element in the array that lies between them in value. In other words, find the maximum absolute difference be...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4674, "level": 1, "question": "Given an array `arr` consisting of `N` integers, find the maximum difference between any two elements `arr[i]` and `arr[j]` (i.e., |arr[i] - arr[j]|) such that there is no other element in the array that lies between them in value. In other words, find...
def pascalTriangle(M): if M == 0: return [] result = [] prev_row = [1] result.append(prev_row.copy()) for i in range(1, M): new_row = [1] for j in range(1, i): new_element = prev_row[j-1] + prev_row[j] new_row.append(new_element) new_row.append...
simplelr_Taco
[ { "content": "Question:\nFor a given number M, generate the Pascal's triangle up to M rows. Pascal's triangle is a triangular array of the binomial coefficients. The rows of Pascal's triangle are conventionally enumerated starting with row n = 0 at the top.\n\nExample 1:\nInput:\nM = 4\nOutput: \n[\n [1], \n [1...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4675, "level": 1, "question": "For a given number M, generate the Pascal's triangle up to M rows. Pascal's triangle is a triangular array of the binomial coefficients. The rows of Pascal's triangle are conventionally enumerated starting with row n = 0 at the top.\n\nExample 1:\nInpu...
def calculate_polygon_area(points): if len(points) < 3: return 0.0 area_sum = 0.0 for i in range(len(points)): x_i, y_i = points[i] x_next, y_next = points[(i + 1) % len(points)] area_sum += (x_i * y_next) - (y_i * x_next) return abs(area_sum) / 2.0
simplelr_Filter
[ { "content": "Question:\nI am working on a project that involves calculating the area of a polygon defined by a set of points. The points are given in a specific order, and I need to write a Python function to calculate the area. Can you provide a detailed explanation and a Python code snippet to help me unders...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4676, "level": 1, "question": "I am working on a project that involves calculating the area of a polygon defined by a set of points. The points are given in a specific order, and I need to write a Python function to calculate the area. Can you provide a detailed explanation and a Py...
from typing import List def unique_elements(lst: List[int]) -> List[int]: seen = set() result = [] for num in lst: if num not in seen: seen.add(num) result.append(num) return result
simplelr_Apps
[ { "content": "Question:\nImplement a function `unique_elements` which receives a list of integers `[a1, a2, ..., an]` and returns a new list of integers `[b1, b2, ..., bk]` such that each element in the output list is unique and the order of elements in the input list is preserved. That is, for every element th...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4677, "level": 1, "question": "Implement a function `unique_elements` which receives a list of integers `[a1, a2, ..., an]` and returns a new list of integers `[b1, b2, ..., bk]` such that each element in the output list is unique and the order of elements in the input list is prese...
import numpy as np import matplotlib.pyplot as plt # Initial conditions x0 = 1 y0 = 1 dt = 0.01 T = 1 # Number of time steps N = int(T / dt) # Define a function to compute the gradient ∇f at a given point (x, y) def compute_gradient(x, y): # Height function f(x, y) = 2 - x^2 - y^2 fx = -2 * x fy = -2 * y...
simplelr_Filter
[ { "content": "Question:\nYou have been tasked with rewriting the vector iteration towards the ring structure examples. Your goal is to determine the horizontal extent of the cyclonic flow which is created when a low-pressure system is placed on a north-south axis. The tangent vector pointing in the direction of...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4678, "level": 1, "question": "You have been tasked with rewriting the vector iteration towards the ring structure examples. Your goal is to determine the horizontal extent of the cyclonic flow which is created when a low-pressure system is placed on a north-south axis. The tangent ...
import json def json_to_dict(json_obj): return json.loads(json_obj)
simplelr_Prefill
[ { "content": "Question:\nWrite a function to convert a JSON object into a dictionary using Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4679, "level": 1, "question": "Write a function to convert a JSON object into a dictionary using Python.", "split": "train" }
def min_length_subarray(arr, target): prefix_sum = 0 sum_map = {0: -1} min_length = float('inf') result = [] for i, num in enumerate(arr): prefix_sum += num # Check if there's a previous sum that equals prefix_sum - target if (prefix_sum - target) in sum_map: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of integers `arr` and a target integer `target`. Your task is to find a **continuous subarray** whose sum equals the target integer and has the **smallest possible length**. If there are multiple subarrays with the same smallest length that sum to the target, retu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4680, "level": 1, "question": "You are given an array of integers `arr` and a target integer `target`. Your task is to find a **continuous subarray** whose sum equals the target integer and has the **smallest possible length**. If there are multiple subarrays with the same smallest ...
def longest_substring_length(s: str, queries: list[int]) -> list[int]: n = len(s) if n == 0: return [] left_start = [0] * n left_start[0] = 0 for i in range(1, n): if s[i] == s[i-1]: left_start[i] = left_start[i-1] else: left_start[i] = i ...
simplelr_Algorithm
[ { "content": "Question:\n### Scenario\nYou are given a string comprised of lowercase letters and a set of queries, where each query asks for the length of the longest substring consisting of the same character. The task is to preprocess the string to efficiently answer each query.\n\n### Problem Statement\nImpl...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4681, "level": 1, "question": "### Scenario\nYou are given a string comprised of lowercase letters and a set of queries, where each query asks for the length of the longest substring consisting of the same character. The task is to preprocess the string to efficiently answer each qu...
from datetime import datetime from zoneinfo import ZoneInfo from typing import List, Dict, Any, Tuple def parse_flights(flights: List[Dict[str, Any]]) -> Tuple[float, Dict[str, int], Dict[str, int]]: """ Computes insights from the given flight dataset. Parameters: flights (List[Dict[str, any]]...
simplelr_Docs
[ { "content": "Question:\n### Advanced Python Data Types Assessment\n\n#### Problem Statement\n\nYou are given a dataset of flights that log details about various aspects of each flight, such as departure time, arrival time, airport code, zone information, and status of the flight. Your task is to implement a fu...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4682, "level": 1, "question": "### Advanced Python Data Types Assessment\n\n#### Problem Statement\n\nYou are given a dataset of flights that log details about various aspects of each flight, such as departure time, arrival time, airport code, zone information, and status of the fli...
def trap(heights): if not heights: return 0 left = 0 right = len(heights) - 1 max_left = 0 max_right = 0 result = 0 while left < right: if heights[left] <= heights[right]: if heights[left] > max_left: max_left = heights[left] else: ...
simplelr_Leetcode
[ { "content": "Question:\nYou are given an array of non-negative integers representing the heights of buildings at different positions along a street. The distance between any two adjacent buildings is the same, and the width between two adjacent buildings is 1. The buildings are formulated such that they create...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4683, "level": 1, "question": "You are given an array of non-negative integers representing the heights of buildings at different positions along a street. The distance between any two adjacent buildings is the same, and the width between two adjacent buildings is 1. The buildings a...
def check_palindrome(s): cleaned = ''.join([c for c in s if c.isalnum()]).lower() return cleaned == cleaned[::-1]
simplelr_Filter
[ { "content": "Question:\nCreate a function named `check_palindrome` in Python that determines if a given string is a palindrome. A string is considered a palindrome if it reads the same forwards and backwards, ignoring spaces, punctuation, and capitalization.\nAnswer:\nLet's think step by step.\n", "role": ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4684, "level": 1, "question": "Create a function named `check_palindrome` in Python that determines if a given string is a palindrome. A string is considered a palindrome if it reads the same forwards and backwards, ignoring spaces, punctuation, and capitalization.", "split": "tra...
def sum_of_integers(lst): return sum(lst)
simplelr_Filter
[ { "content": "Question:\nWrite a function that takes in a list of integers and returns the sum of the integers. Assume the list is not empty. Example: input: [1, 2, 3, 4, 5] output: 15. Write the function in Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4685, "level": 1, "question": "Write a function that takes in a list of integers and returns the sum of the integers. Assume the list is not empty. Example: input: [1, 2, 3, 4, 5] output: 15. Write the function in Python.", "split": "train" }
def length_of_longest_substring(s): char_index = {} left = 0 max_length = 0 for right in range(len(s)): char = s[right] if char in char_index: # Move left to the position right after the last occurrence of char left = max(left, char_index[char] + 1) char_i...
simplelr_Apps
[ { "content": "Question:\nImplement a function that takes a string as input and returns the length of the longest substring with all unique characters. The input string will only contain lowercase letters.\n\nExample:\n```\nInput: \"abcabcbb\"\nOutput: 3 // \"abc\" is the longest substring with all unique chara...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4686, "level": 1, "question": "Implement a function that takes a string as input and returns the length of the longest substring with all unique characters. The input string will only contain lowercase letters.\n\nExample:\n```\nInput: \"abcabcbb\"\nOutput: 3 // \"abc\" is the long...
def lists_close_enough(list1, list2, tolerance=1e-6): if len(list1) != len(list2): return False for a, b in zip(list1, list2): if abs(a - b) > tolerance: return False return True
simplelr_Filter
[ { "content": "Question:\nI have two Python lists of integers, list1 and list2. The elements in list1 are supposed to be the markers for the elements in list2 that are close enough, i.e. list2[i] - list1[i] should be within some small tolerance of 0. I will be using these lists for the purpose of validating the...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4687, "level": 1, "question": "I have two Python lists of integers, list1 and list2. The elements in list1 are supposed to be the markers for the elements in list2 that are close enough, i.e. list2[i] - list1[i] should be within some small tolerance of 0. I will be using these list...
def transpose_matrix(matrix: list[list[int]]) -> list[list[int]]: return [list(row) for row in zip(*matrix)]
simplelr_Algorithm
[ { "content": "Question:\n### Transpose a Matrix\n\n**Scenario**: In a linear algebra system, you need to transpose a matrix for various operations such as transforming coordinates or changing the structure of data for easier manipulation.\n\n**Task**: Write a function `transpose_matrix` that takes a 2-dimension...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4688, "level": 1, "question": "### Transpose a Matrix\n\n**Scenario**: In a linear algebra system, you need to transpose a matrix for various operations such as transforming coordinates or changing the structure of data for easier manipulation.\n\n**Task**: Write a function `transpo...
import json def validate_and_parse(json_str: str) -> dict: return json.loads(json_str)
simplelr_Algorithm
[ { "content": "Question:\n### Validate and Parse Nested JSON-like Strings\n\n**Context**:\nYou are building a lightweight parser for an application that deals with a custom configuration language. This format is similar to JSON but with specific restrictions. Your task is to validate and parse these strings to e...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4689, "level": 1, "question": "### Validate and Parse Nested JSON-like Strings\n\n**Context**:\nYou are building a lightweight parser for an application that deals with a custom configuration language. This format is similar to JSON but with specific restrictions. Your task is to va...
def get_books_by_year(books, target_year, sort_by='title'): """ This function filters a list of books to find those published in a specified year and returns their titles. The titles can be sorted either alphabetically or by publication year. Args: books (list): A list of dictionaries, each rep...
simplelr_Evol
[ { "content": "Question:\nDesign a Python function that takes a list of dictionaries representing a collection of books, where each dictionary contains 'title' (string), 'author' (string), 'year_published' (integer), and 'genre' (string). The function should return a list of titles of books published in a given ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4690, "level": 1, "question": "Design a Python function that takes a list of dictionaries representing a collection of books, where each dictionary contains 'title' (string), 'author' (string), 'year_published' (integer), and 'genre' (string). The function should return a list of ti...
def is_valid_permutation(list1, list2): return sorted(list1) == sorted(list2)
simplelr_Prefill
[ { "content": "Question:\nWrite a python function to check if a given list of numbers is a valid permutation of another list. A permutation is a rearrangement of the elements of one set into some sequence or order.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4691, "level": 1, "question": "Write a python function to check if a given list of numbers is a valid permutation of another list. A permutation is a rearrangement of the elements of one set into some sequence or order.", "split": "train" }
def add_nutrient(nutrients): return [nutrient + 5 for nutrient in nutrients]
simplelr_Filter
[ { "content": "Question:\n### Insect Ecologist\nAzizi Latiff is a part-time researcher who studies the behavior of insects. She collects data in the form of numbers for each type of insect in a particular region. Each number represents the amount of a particular nutrient, from 0 to 100, which the insect needs to...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4692, "level": 1, "question": "### Insect Ecologist\nAzizi Latiff is a part-time researcher who studies the behavior of insects. She collects data in the form of numbers for each type of insect in a particular region. Each number represents the amount of a particular nutrient, from ...
from collections import Counter def character_frequencies_sorted(input_string): """ Calculate the frequency of each character in the input string and return a list of tuples sorted by frequency in ascending order. Args: input_string (str): The input string to analyze. Returns: ...
simplelr_Filter
[ { "content": "Question:\nI have a string and I want to calculate the frequencies of all characters in the string and then sort in ascending order. For this task I have decided to utilize Python programming language. What would be a Python function to accomplish this task?\nAnswer:\nLet's think step by step.\n",...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4693, "level": 1, "question": "I have a string and I want to calculate the frequencies of all characters in the string and then sort in ascending order. For this task I have decided to utilize Python programming language. What would be a Python function to accomplish this task?", ...
import re def extract_latest_version(text): pattern = r'\b(v?\d+(?:\.\d+)*)\b' matches = re.findall(pattern, text) if not matches: return None # Return None if no versions found version_info = [] for match in matches: version = match.lstrip('v') parts = list(map(int, v...
simplelr_Filter
[ { "content": "Question:\nCan you create a Python function that extracts the latest version of a software package from a given text? The text will contain information about various software versions, and the function should return the latest version based on semantic versioning.\nAnswer:\nLet's think step by ste...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4694, "level": 1, "question": "Can you create a Python function that extracts the latest version of a software package from a given text? The text will contain information about various software versions, and the function should return the latest version based on semantic versioning...
def append_char_to_words(word_list, char): return [word + char for word in word_list]
simplelr_Filter
[ { "content": "Question:\nWe are given an array of strings and a character that needs to be appended at the end of each word in the array. We have to write a function that takes the array of words and the character as input and returns the array with the appended character at the end of each word.\nAnswer:\nLet'...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4695, "level": 1, "question": "We are given an array of strings and a character that needs to be appended at the end of each word in the array. We have to write a function that takes the array of words and the character as input and returns the array with the appended character at t...
def balanceBrackets(brackets): balance = 0 insertions = 0 deletions = 0 for c in brackets: if c == '(': balance += 1 else: balance -= 1 if balance < 0: insertions += 1 balance = 0 deletions = balance # After processing all, bal...
simplelr_Package
[ { "content": "Question:\nYou are required to write a function `balanceBrackets` that takes a string comprised of round brackets '(' and ')' and returns a balanced version of the string along with the minimum number of insertions and deletions required to achieve this.\n\nIn a balanced string:\n1. Every opening ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4696, "level": 1, "question": "You are required to write a function `balanceBrackets` that takes a string comprised of round brackets '(' and ')' and returns a balanced version of the string along with the minimum number of insertions and deletions required to achieve this.\n\nIn a ...
def analyze_products(file_path): result = {} with open(file_path, 'r') as file: for line in file: line = line.strip() parts = line.split(',') if len(parts) != 4: raise ValueError("Line does not have exactly four values") product_id, name, c...
simplelr_Package
[ { "content": "Question:\nRead a text file containing multiple lines of comma-separated values (CSV format). Each line represents a product with the following information: 'product_id', 'name', 'category', and 'price'. Write a function that reads the file, calculates the total number of products and the average ...
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4697, "level": 1, "question": "Read a text file containing multiple lines of comma-separated values (CSV format). Each line represents a product with the following information: 'product_id', 'name', 'category', and 'price'. Write a function that reads the file, calculates the total ...
def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[-1] left = [x for x in arr[:-1] if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr[:-1] if x > pivot] return quicksort(left) + middle + quicksort(right)
simplelr_Filter
[ { "content": "Question:\nPlease provide a detailed explanation of how to implement an algorithm for sorting a list of numbers using the quicksort algorithm in Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4698, "level": 1, "question": "Please provide a detailed explanation of how to implement an algorithm for sorting a list of numbers using the quicksort algorithm in Python.", "split": "train" }
def sum_of_list(lst): total = 0 for num in lst: if isinstance(num, (int, float)): total += num return total
simplelr_Prefill
[ { "content": "Question:\nWrite a function to find the sum of all numbers in a list. The function should be implemented in Python.\nAnswer:\nLet's think step by step.\n", "role": "user" } ]
code
{ "ground_truth": "pass", "style": "exec" }
{ "answer": "pass", "index": 4699, "level": 1, "question": "Write a function to find the sum of all numbers in a list. The function should be implemented in Python.", "split": "train" }