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 two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Example 1: Input: num1 = "2", num2 ...
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 grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be: 1 which mean...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, mu...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We write the integers of A and B (in the order they are given) on two separate horizontal lines. Now, we may draw connecting lines: a straight line connecting two numbers A[i]...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given the coordinates of four points in 2D space, return whether the four points could construct a square. The coordinate (x,y) of a point is represented by an integer array ...
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, you should partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to becom...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Some people will make friend requests. The list of their ages is given and ages[i] is the age of the ith person.  Person A will NOT friend request person B (B != A) if any of ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Return the number of distinct non-empty substrings of text that can be written as the concatenation of some string with itself (i.e. it can be written as a + a where a is some...
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 with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target. Example: nums = [1, 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 string representing a code snippet, you need to implement a tag validator to parse the code and return whether it is valid. A code snippet is valid if all the followin...
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 length of the longest arithmetic subsequence in A. Recall that a subsequence of A is a list A[i_1], A[i_2], ..., A[i_k] with 0 <= 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 non-negative integer N, find the largest number that is less than or equal to N with monotone increasing digits. (Recall that an integer has monotone increasing digit...
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 children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Eac...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there is no non-empty subarray with sum at least K, return -1.   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 integer array bloomDay, an integer m and an integer k. We need to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden c...
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). Return the number of substrings with all characters 1's. Since the answer may be too large, return it modul...
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 s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two ch...
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 a happy prefix if is a non-empty prefix which is also a suffix (excluding itself). Given a string s. Return the longest happy prefix of s . Return an empty ...
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 pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows: You will pick any pizza slice. Your friend Alice will pick next sl...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Alice and Bob continue their games with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is an integer given in the ar...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Your task is to form an integer array nums from an initial array of zeros arr that is the same size as nums. Return the minimum number of function calls to make nums from arr....
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: s1 and s2 with the same size, check if some permutation of string s1 can break some permutation of string s2 or vice-versa (in other words s2 can break s1)....
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some el...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac" Output: true Example 2: In...
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 32-bit integer n, you need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an N x N grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximi...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) ...
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, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb"...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n numb...
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 rows x cols matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix. Among all p...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statement...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.   Example 1: Input: hour = 12, minutes = 30 Output: 16...
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, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end indexes are counted as different su...
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, you are initially positioned at the first index of the array. In one step you can jump from index i to index: i + 1 where: i + 1 < arr.length....
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 array of integers cost where cost[i] is the cost of deleting the ith character in s. Return the minimum cost of deletions such that there are no two id...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are installing a billboard and want it to have the largest height.  The billboard will have two steel supports, one on each side.  Each steel support must be an equal heig...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two equal-size strings s and t. In one step you can choose any character of t and replace it with another character. Return the minimum number of steps to make t an anag...
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 gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to trav...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given the strings s1 and s2 of size n, and the string evil. Return the number of good strings. A good string has size n, it is alphabetically greater than or equal to s1, it i...
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 nums1 and nums2, return the number of triplets formed (type 1 and type 2) under the following rules: Type 1: Triplet (i, j, k) if nums1[i]2 == nu...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" Corner Cases: Did you consid...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.  Example: Input: n = 10 Output: 12 Explanation: 1...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules: ...
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, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. Example 1: Input: n = 12 Output: 3 Explanation:...
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 an array A of N lowercase letter strings, all of the same length. Now, we may choose any set of deletion indices, and for each string, we delete all the character...
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 which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the larg...
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 k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Inp...
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 s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of 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, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subar...
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, you can perform operations on the array. In each operation, you pick any nums[i] and delete it to earn nums[i] points. After, you must delet...
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 positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K. (For...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.On a broken calculator that has a number showing on its display, we can perform two operations: Double: Multiply the number on the display by 2, or; Decrement: Subtract 1 fro...
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, each word consists of English lowercase letters. Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word...
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 target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less o...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[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 integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. Note: 1 ≤ k ≤ n ≤ 109. Example: Input: n: 13 k: 2 Output: 10 Explanat...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to righ...
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 representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-in...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.To some string S, we will perform some replacement operations that replace groups of letters with new ones (not necessarily the same size). Each replacement operation has 3 pa...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a square array of integers A, we want the minimum sum of a falling path through A. A falling path starts at any element in the first row, and chooses one element from ea...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A conveyor belt has packages that must be shipped from one port to another within D days. The i-th package on the conveyor belt has a weight of weights[i].  Each day, we load ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile the rectangle.   Example 1: Input: n = 2, m = 3 Output: 3 Explanation: 3 squares a...
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 people and 40 types of hats labeled from 1 to 40. Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person. 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 a 2D array A, each cell is 0 (representing sea) or 1 (representing land) A move consists of walking from one land square 4-directionally to another land square, or off t...
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 jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Let's define a function countUniqueChars(s) that returns the number of unique characters on s, for example if s = "LEETCODE" then "L", "T","C","O","D" are the unique character...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times. 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.Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time. Like-time coefficient of a dish is defined as the time taken to ...
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 binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbours of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair ...
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 unique positive integers A, consider the following graph: There are A.length nodes, labelled A[0] to A[A.length - 1]; There is an edge between A[i]...
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 list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if routes[0] = [1, 5, 7], this means that the first bus (0-th indexe...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more o...
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 k transaction...
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 strings, find any smallest string that contains each string in A as a substring. We may assume that no string in A is substring of another string in 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 unsorted array, find the maximum difference between the successive elements in its sorted form. Return 0 if the array contains less than 2 elements. 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.Given N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] in clockwise order. Suppose you triangulate the polygon into N-2 triangles.  For each...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A positive integer is magical if it is divisible by either A or B. Return the N-th magical number.  Since the answer may be very large, return it modulo 10^9 + 7.   Example...
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 containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal. Note...
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 sorted arrays of distinct integers nums1 and nums2. A valid path is defined as follows: Choose array nums1 or nums2 to traverse (from index-0). Traverse the...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, wh...
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 n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead. E...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A peak element is an element that is greater than its neighbors. Given an input array nums, where nums[i] ≠ nums[i+1], find a peak element and return its index. The array ma...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.(This problem is the same as Minimize Malware Spread, with the differences bolded.) In a network of nodes, each node i is directly connected to another node j if and only if g...
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, consider all non-empty subsequences of A. For any sequence S, let the width of S be the difference between the maximum and minimum element of S. ...
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. A factor of an integer n is defined as an integer i where n % i == 0. Consider a list of all factors of n sorted in ascending order, retur...
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 n, your task is to count how many strings of length n can be formed under the following rules: Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u')...
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 (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According to the definition of h-...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In a given integer array A, we must move every element of A to either list B or list C. (B and C initially start empty.) Return true if and only if after such a move, it is po...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile.  On each player's turn, that player makes a move consisting of rem...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Define S = [s,n] as the string S which consists of n connected strings s. For example, ["abc", 3] ="abcabcabc". On the other hand, we define that string s1 can be obtained fr...
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's and '1's), we can split s into 3 non-empty strings s1, s2, s3 (s1+ s2+ s3 = s). Return the number of ways s can be sp...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Write a program to find the n-th ugly number. Ugly numbers are positive integers which are divisible by a or b or c.   Example 1: Input: n = 3, a = 2, b = 3, c = 5 Output: 4 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 non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementi...
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 A.  From some starting index, you can make a series of jumps.  The (1st, 3rd, 5th, ...) jumps in the series are called odd numbered jumps, and 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 positive integer K, you need find the smallest positive integer N such that N is divisible by K, and N only contains the digit 1. Return the length of N.  If there is ...
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 n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. Example: Input: 13 Output: 6 Explanation: Digit 1 occ...
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 and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k = 2 Output: ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given a non-empty string containing only dig...
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 representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histo...