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 nums of integers, we need to find the maximum possible sum of elements of the array such that it is divisible by three.
Example 1:
Input: nums = [3,6,5,1,8]... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In a 1 million by 1 million grid, the coordinates of each grid square are (x, y) with 0 <= x, y < 10^6.
We start at the source square and want to reach the target square. Eac... |
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 return whether an increasing subsequence of length 3 exists or not in the array.
Formally the function should:
Return true if there exists i, j, k
... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve?
N... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:
Only ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a balanced parentheses string S, compute the score of the string based on the following rule:
() has score 1
AB has score A + B, where A and B are balanced parentheses ... |
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 arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to va... |
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 arr and an integer k, modify the array by repeating it k times.
For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 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 non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dicti... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You have d dice, and each die has f faces numbered 1, 2, ..., f.
Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the sum of the f... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a palindromic string palindrome, replace exactly one character by any lowercase English letter so that the string becomes the lexicographically smallest possible string ... |
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 arr of distinct integers and an integer k.
A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We have two integer sequences A and B of the same non-zero length.
We are allowed to swap elements A[i] and B[i]. Note that both elements are in the same index position 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 game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.
The graph is given as follows: graph[a] is a list of all nodes b such that ab is an... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are two sorted arrays nums1 and nums2 of size m and n respectively.
Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
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 positive integer n and you can do operations as follow:
If n is even, replace n with n/2.
If n is odd, you can replace n with either n + 1 or n - 1.
What is th... |
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 bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if... |
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 s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of ... |
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 last substring of s in lexicographical order.
Example 1:
Input: "abab"
Output: "bab"
Explanation: The substrings are ["a", "ab", "aba", "abab", ... |
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, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example 1:
Input: "babad"
Output: "bab"
Note: "aba" is 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 integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adja... |
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 images img1 and img2 both of size n x n, represented as binary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)
We translat... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.
Return the quotient after dividing dividend by divisor.
... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero.
Return true if and only if we ca... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given n orders, each order consist in pickup and delivery services.
Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i).
Si... |
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 a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks.
We start at the sta... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a gues... |
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, count the number of distinct, non-empty subsequences of S .
Since the result may be large, return the answer modulo 10^9 + 7.
Example 1:
Input: "abc"
Outpu... |
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 sum of min(B), where B ranges over every (contiguous) subarray of A.
Since the answer may be large, return the answer modulo 10^9 + 7.
... |
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 sets of k consecutive numbers
Return True if its possible otherw... |
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 two integers k and threshold.
Return the number of sub-arrays of size k and average greater than or equal to threshold.
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 a binary array nums, you should delete one element from it.
Return the size of the longest non-empty subarray containing only 1's in the resulting array.
Return 0 if 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 A of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K.
Example 1:
Input: A = [4,5,0,-2,-3,1], K = 5
Output: 7
... |
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 oranges in the kitchen and you decided to eat some of these oranges every day as follows:
Eat one orange.
If the number of remaining oranges (n) is divisible by 2... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.An encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:
If the ch... |
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 that represents a permutation of numbers from 1 to n. You have a binary string of size n that initially has all its bits set to zero.
At each step i (assumi... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent if and only if:
For i <= k < j, A[k] > A[k+1] when k is odd, and A[k] < A[k+1] when k is even;
OR, for i <= k ... |
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 special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, 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 positive integer N, how many ways can we write it as a sum of consecutive positive integers?
Example 1:
Input: 5
Output: 2
Explanation: 5 = 5 = 2 + 3
Example 2:
Input:... |
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 soldiers standing in a line. Each soldier is assigned a unique rating value.
You have to form a team of 3 soldiers amongst them under the following rules:
Choose ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of passengers will:
Take thei... |
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, you are allowed to choose one element of nums and change it by any value in one move.
Return the minimum difference between the largest and smallest value... |
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 k. Find the least number of unique integers after removing exactly k elements.
Example 1:
Input: arr = [5,5,4], k = 1
Output:... |
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 which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest i... |
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 numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple o... |
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.A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:
For 1-byte character, the first bit is a 0, followed by its unicode code.
For n-bytes cha... |
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, each of which represents a non-negative rational number, return True if and only if they represent the same number. The strings may use parentheses ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the i-th job, you have to finish all the jobs j where 0 <= j < i).
You have to finish at leas... |
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 row of m houses in a small city, each house must be painted with one of the n colors (labeled from 1 to n), some houses that has been painted last summer should not... |
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, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.
Example 1:
Input: 273... |
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 strange printer with the following two special requirements:
On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This w... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the ... |
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 coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount.... |
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 positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to rem... |
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 that consists of only uppercase English letters, you can replace any letter in the string with another letter at most k times. Find the length of a longest subs... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected t... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company has is the one with headID.
Each employee has one direct manager given in... |
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 map of a server center, represented as a m * n integer matrix grid, where 1 means that on that cell there is a server and 0 means that it is no server. Two ser... |
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 integer array nums. The value of this array is defined as the sum of |nums[i]-nums[i+1]| for all 0 <= i < nums.length-1.
You are allowed to select any subarra... |
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 array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n).
In one operation, you can select two indices x and y where 0 <= x, y ... |
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, partition s such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.
Example:
Input... |
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 a personal information string S, which may represent either an email address or a phone number.
We would like to mask this personal information according to the f... |
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 nums, return the sum of divisors of the integers in that array that have exactly four divisors.
If there is no such integer in the array, return 0.
Ex... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
If the fractional part is repeating, enclose the repeating ... |
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 binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly... |
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 A, and an integer target, return the number of tuples i, j, k such that i < j < k and A[i] + A[j] + A[k] == target.
As the answer can be very large, re... |
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 grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or 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 non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check... |
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.
We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).
Let's define a and b as follows:
a = arr[i] ^ arr[i + 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 list of words, list of single letters (might be repeating) and score of every character.
Return the maximum score of any valid set of words formed by using the given ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given the array nums consisting of n positive integers. You computed the sum of all non-empty continous subarrays from the array and then sort them in non-decreasing order, cr... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.N cars are going to the same destination along a one lane road. The destination is target miles away.
Each car i has a constant speed speed[i] (in miles per hour), and initia... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two positive integers n and k, the binary string Sn is formed as follows:
S1 = "0"
Si = Si-1 + "1" + reverse(invert(Si-1)) for i > 1
Where + denotes the concatenation... |
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 array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Note:
Your algorithm should have a l... |
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 brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the left, 1 position to the right in the array or stay in the same place (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 n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assu... |
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 of positive integers, consider all binary trees such that:
Each node has either 0 or 2 children;
The values of arr correspond to the values of each leaf in... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Find the smallest prime palindrome greater than or equal to N.
Recall that a number is prime if it's only divisors are 1 and itself, and it is greater than 1.
For example, 2,... |
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 containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and ev... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, return true if and only if for every integer X from 1 to N, the binary representat... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A string is called happy if it does not have any of the strings 'aaa', 'bbb' or 'ccc' as a substring.
Given three integers a, b and c, return any string s, which satisfies fol... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.
Note that it is the kth smallest element ... |
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, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. The width of such a ramp is j - i.
Find the maximum width of a ramp in A. If one doe... |
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 rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, ..., N-1, and each room may have some keys to access the next room.
Formally, each roo... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz... |
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 list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its ne... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Return the largest possible k such that there exists a_1, a_2, ..., a_k such that:
Each a_i is a non-empty string;
Their concatenation a_1 + a_2 + ... + a_k is equal to text;... |
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 collection of rocks, each rock has a positive integer weight.
Each turn, we choose any two rocks and smash them together. Suppose the stones have weights x and y wi... |
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, a move consists of choosing any A[i], and incrementing it by 1.
Return the least number of moves to make every value in A unique.
Example 1:
In... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], obtaining a profit of profit[i].
You're given the startTime , endTime and profit array... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That ... |
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 positive integers target and an array initial of same size with all zeros.
Return the minimum number of operations to form a target array from initial if you... |
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, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this tr... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In a network of nodes, each node i is directly connected to another node j if and only if graph[i][j] = 1.
Some nodes initial are initially infected by malware. Whenever two ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a sentence text (A sentence is a string of space-separated words) in the following format:
First letter is in upper case.
Each word in text are separated by a single sp... |
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 that consists of lower case English letters and brackets.
Reverse the strings in each pair of matching parentheses, starting from the innermost one.
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.