formatted_conversations
stringlengths
1.13k
138k
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array arr.  You can choose a set of integers and remove all the occurrences of these integers in the array. Return the minimum size of the set so that at least half o...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal. Example 1: Input...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers A, find the number of triples of indices (i, j, k) such that: 0 <= i < A.length 0 <= j < A.length 0 <= k < A.length A[i] & A[j] & A[k] == 0, where ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string s, determine if it is valid. A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation a...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given two strings s and t of the same length. You want to change s to t. Changing the i-th character of s to i-th character of t costs |s[i] - t[i]| that is, the absol...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) complexity. Example: Input: [100, 4, 2...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times. The Fibonacci numbers are def...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 un...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: B.length >= 3 There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target v...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. E...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Input: [10,2] Output: "210" Example 2: Input: [3,30,34,5,9] Output...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In the world of Dota2, there are two parties: the Radiant and the Dire. The Dota2 senate consists of senators coming from two parties. Now the senate wants to make a decisi...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are N piles of stones arranged in a row.  The i-th pile has stones[i] stones. A move consists of merging exactly K consecutive piles into one pile, and the cost of this ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string s, return the maximum number of unique substrings that the given string can be split into. You can split string s into any list of non-empty substrings, where t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of unique integers, each integer is strictly greater than 1. We make a binary tree using these integers and each number may be used for any number of times. Eac...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Exam...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array nums of integers, a move consists of choosing any element and decreasing it by 1. An array A is a zigzag array if either: Every even-indexed element is greater...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array nums of positive integers. Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. The array is said to be go...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given the string croakOfFrogs, which represents a combination of the string "croak" from different frogs, that is, multiple frogs can croak at the same time, so multiple “croa...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We have an array A of non-negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obta...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A string S of lowercase letters is given.  Then, we may make any number of moves. In each move, we choose one of the first K letters (starting from the left), remove it, and p...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We are given hours, a list of the number of hours worked per day for a given employee. A day is considered to be a tiring day if and only if the number of hours worked is (str...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Today, the bookstore owner has a store open for customers.length minutes.  Every minute, some number of customers (customers[i]) enter the store, and all those customers leave...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string S, consider all duplicated substrings: (contiguous) substrings of S that occur 2 or more times.  (The occurrences may overlap.) Return any duplicated substring ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A sequence X_1, X_2, ..., X_n is fibonacci-like if: n >= 3 X_i + X_{i+1} = X_{i+2} for all i + 2 <= n Given a strictly increasing array A of positive integers forming a sequ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. Accordi...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string S and a string T, count the number of distinct subsequences of S which equals T. A subsequence of a string is a new string which is formed from the original st...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square. Return the number of permutations of A...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of the longest (contiguous) subarray that contains only 1s.    Example 1: Input: A ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string s and an integer k. Return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are (a, e, i, o, u).   Example 1: I...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers A with even length, return true if and only if it is possible to reorder it such that A[2 * i + 1] = 2 * A[2 * i] for every 0 <= i < len(A) / 2. ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The length of num is less t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: I...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attacking ascending time series towards A...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. For example, these...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), followed by some number of '1's (also possibly 0.) We are given a string S...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In an array A of 0s and 1s, how many non-empty subarrays have sum S?   Example 1: Input: A = [1,0,1,0,1], S = 2 Output: 4 Explanation: The 4 subarrays are bolded below: [1,0,...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transacti...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We have a set of items: the i-th item has value values[i] and label labels[i]. Then, we choose a subset S of these items, such that: |S| <= num_wanted For every label L, the ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.On an infinite plane, a robot initially stands at (0, 0) and faces north.  The robot can receive one of three instructions: "G": go straight 1 unit; "L": turn 90 degrees to t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array nums of positive integers, return the longest possible length of an array prefix of nums, such that it is possible to remove exactly one element from this prefi...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.On a table are N cards, with a positive integer printed on the front and back of each card (possibly different). We flip any number of cards, and after we choose one card.  If...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a number s in their binary representation. Return the number of steps to reduce it to 1 under the following rules: If the current number is even, you have to divide it...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4. However, you can add any number of parenthesis at...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In English, we have a concept called root, which can be followed by some other words to form another longer word - let's call this word successor. For example, the root an, fo...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of arr each with sum equal target. There can be multiple answers so you h...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a 2D array of characters grid of size m x n, you need to find if there exists any cycle consisting of the same value in grid. A cycle is a path of length 4 or more in th...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given a row x col grid of i...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are N workers.  The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire exactly K workers to form a paid group.  When hiring a group...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Normally, the factorial of a positive integer n is the product of all positive integers less than or equal to n.  For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 *...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e The length of the garden is n). There are n + 1 taps located at...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any m (1 ≤ m ≤ n) washing machine...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that p...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours. Koko can decide her bananas-...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b with ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order. Note: Input contains only lowercase English l...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. Find the...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an equation, represented by words on left side and the result on right side. You need to check if the equation is solvable under the following rules: Each character is ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both formin...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters. Return the maximum possible length of s.   Example 1: Input: ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array nums and an integer target. Return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarray is equal to target.   ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters i...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Note: ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a number N, return a string consisting of "0"s and "1"s that represents its value in base -2 (negative two). The returned string must have no leading zeroes, unless the ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array nums of 0s and 1s and an integer k, return True if all 1's are at least k places away from each other, otherwise return False.   Example 1: Input: nums = [1,0,...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A happy string is a string that: consists only of letters of the set ['a', 'b', 'c']. s[i] != s[i + 1] for all values of i from 1 to s.length - 1 (string is 1-indexed). For ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that p...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given n boxes, each box is given in the format [status, candies, keys, containedBoxes] where: status[i]: an integer which is 1 if box[i] is open and 0 if box[i] is closed. ca...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Your car starts at position 0 and speed +1 on an infinite number line.  (Your car can go into negative positions.) Your car drives automatically according to a sequence of ins...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this suba...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this string is valid. We define the validity of a string by these...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand. Each time, ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There is a room with n bulbs, numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off. At moment k (for k from 0 to n - 1), we turn...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an integer array of digits, return the largest multiple of three that can be formed by concatenating some of the given digits in any order. Since the answer may not fit ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following sequence for n = 3: ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s int...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two strings s and t, your goal is to convert s into t in k moves or less. During the ith (1 <= i <= k) move you can: Choose any index j (1-indexed) from s, such that 1 ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a m x n matrix mat and an integer threshold. Return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pair (A, B) is defined as the absolute difference between A and B. Example 1...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can be used at most once, has a value token[i], and has potentially two ways to use ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array A of integers, for each integer A[i] we need to choose either x = -K or x = K, and add x to A[i] (only once). After this process, we have some array B. Return t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i.  All the balls will be shuffled unifo...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how ma...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array A of non-negative integers, return the maximum sum of elements in two non-overlapping (contiguous) subarrays, which have lengths L and M.  (For clarification, t...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers arr. Return the number of sub-arrays with odd sum. As the answer may grow large, the answer must be computed modulo 10^9 + 7.   Example 1: Input: ar...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two arrays of integers with equal lengths, return the maximum value of: |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j| where the maximum is taken over all 0 <= i, j...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return the number of distinct sol...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres to the south, x[...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e.,  [0,1,2,4,5,6,7] might become  [4,5,6,7,0,1,2]). Find the minimum eleme...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You have n  tiles, where each tile has one letter tiles[i] printed on it. Return the number of possible non-empty sequences of letters you can make using the letters printed o...