formatted_conversations stringlengths 1.13k 138k |
|---|
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an undirected weighted graph, consisting of n vertices and m edges.
Some queries happen with this graph:
* Delete an... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice gave Bob two integers a and b (a > 0 and b ≥ 0). Being a curious boy, Bob wrote down an array of non-negative integers with \ope... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice has recently received an array a_1, a_2, ..., a_n for her birthday! She is very proud of her array, and when she showed her frie... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a string s, consisting of n letters, each letter is either 'a' or 'b'. The letters in the string are numbered from 1 to ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There is a city that can be represented as a square grid with corner points in (0, 0) and (10^6, 10^6).
The city has n vertical and m... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the t... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a digital clock with n digits. Each digit shows an integer from 0 to 9, so the whole clock shows an integer from 0 to 10... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a book with n chapters.
Each chapter has a specified list of other chapters that need to be understood in order to unde... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given four integer values a, b, c and m.
Check if there exists a string that contains:
* a letters 'A';
* b letters 'B... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Recently, Petya learned about a new game "Slay the Dragon". As the name suggests, the player will have to fight with dragons. To defea... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given three sequences: $a_1, a_2, \ldots, a_n$; $b_1, b_2, \ldots, b_n$; $c_1, c_2, \ldots, c_n$.
For each $i$, $a_i \neq b_i... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a permutation $p=[p_1, p_2, \ldots, p_n]$ of integers from $1$ to $n$. Let's call the number $m$ ($1 \le m \le n$) beaut... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.The sequence of $m$ integers is called the permutation if it contains all integers from $1$ to $m$ exactly once. The number $m$ is cal... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves f... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Let's define the following recurrence: $$a_{n+1} = a_{n} + minDigit(a_{n}) \cdot maxDigit(a_{n}).$$
Here $minDigit(x)$ and $maxDigit(... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Try guessing the statement from this picture: $3$
You are given a non-negative integer $d$. You have to find two non-negative real ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.There are $n$ positive integers $a_1, a_2, \dots, a_n$. For the one move you can choose any even value $c$ and divide by two all eleme... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's.
String $s$ has exa... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a sequence $a_1, a_2, \dots, a_n$, consisting of integers.
You can apply the following operation to this sequence: choo... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a binary string $s$ (recall that a string is binary if each character is either $0$ or $1$).
Let $f(t)$ be the decimal ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Let's call some positive integer classy if its decimal representation contains no more than $3$ non-zero digits. For example, numbers ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given an array $a$ of length $n$, which initially is a permutation of numbers from $1$ to $n$. In one operation, you can choos... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.
Tzuyu gave Sana two integers $a$ and $b$ and a ... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You have a string $s$ consisting of $n$ characters. Each character is either 0 or 1.
You can perform operations on the string. Each o... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Word $s$ of length $n$ is called $k$-complete if $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$; $s$ has a perio... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different i... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given three strings $a$, $b$ and $c$ of the same length $n$. The strings consist of lowercase English letters only. The $i$-th... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Let's look at the following process: initially you have an empty stack and an array $s$ of the length $l$. You are trying to push arra... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Consider the following process. You have a binary string (a string where each character is either 0 or 1) $w$ of length $n$ and an int... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Alexandra has an even-length array $a$, consisting of $0$s and $1$s. The elements of the array are enumerated from $1$ to $n$. She wan... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Berland year consists of $m$ months with $d$ days each. Months are numbered from $1$ to $m$. Berland week consists of $w$ days. The fi... |
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.You are given a colored permutation $p_1, p_2, \dots, p_n$. The $i$-th element of the permutation has color $c_i$.
Let's define an in... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are several cards arranged in a row, and each card has an associated number of points The points are given in the integer array cardPoints.
In one step, you can take one... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Your music player contains N different songs and she wants to listen to L (not necessarily different) songs during your trip. You create a playlist so that:
Every song is pl... |
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,0,1,2,2,5,6] might become [2,5,6,0,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.Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.
Example1:
a = 2
b = [3]
Res... |
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 ocurrences of any substring under the following rules:
The number of unique characters in the substring must be less than or eq... |
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 group of G members, and a list of various crimes they could commit.
The ith crime generates a profit[i] and requires group[i] members to participate in it.
If a mem... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negat... |
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, A[i] represents the value of the i-th sightseeing spot, and two sightseeing spots i and j have distance j - i between them.
The score of... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you will travel is given as an array days. Each ... |
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, return the number of positive integers less than or equal to N that have at least 1 repeated digit.
Example 1:
Input: 20
Output: 1
Explanation: ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the height of any number of buildings, by an... |
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, you must transform it into 0 using the following operations any number of times:
Change the rightmost (0th) bit in the binary representation of n.
Change ... |
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, find the maximum length of a subarray where the product of all its elements is positive.
A subarray of an array is a consecutive sequence of z... |
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 a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.
Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.
Could you do this in O(n) runtime?
E... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.The i-th person has weight people[i], and each boat can carry a maximum weight of limit.
Each boat carries at most 2 people at the same time, provided the sum of the weight 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 list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these s... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In a row of trees, the i-th tree produces fruit with type tree[i].
You start at any tree of your choice, then repeatedly perform the following steps:
Add one piece of fruit f... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:
Copy All: You can copy all the characters present on ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24.
Example 1:
Input: [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 encoded string, return it's decoded string.
The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k... |
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 engineers numbered from 1 to n and two arrays: speed and efficiency, where speed[i] and efficiency[i] represent the speed and efficiency for the i-th engineer resp... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the ith job.
Now we have some workers. worker[i] is the ability of the ith worker... |
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, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them causing the left and the right side of the deleted substring... |
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, partition it into two (contiguous) subarrays left and right so that:
Every element in left is less than or equal to every element in right.
left and right a... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A password is considered strong if below conditions are all met:
It has at least 6 characters and at most 20 characters.
It must contain at least one lowercase letter, at... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith baske... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match girl has, please find out a way you can make one square by using up all tho... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a rectangular cake with height h and width w, and two arrays of integers horizontalCuts and verticalCuts where horizontalCuts[i] is the distance from the top of the rect... |
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 str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If multiple answers exist, you may return any of them.
(A string S 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 input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.
'?' Matches any single character.
'*' Matches any sequence of ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Strings A and B are K-similar (for some non-negative integer K) if we can swap the positions of two letters in A exactly K times so that the resulting string equals B.
Given 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 integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, ... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].
The object... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentin... |
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 text1 and text2, return the length of their longest common subsequence.
A subsequence of a string is a new string generated from the original string with som... |
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, check if s is subsequence of t.
You may assume that there is only lower case English letters in both s and t. t is potentially a very long ... |
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 num representing the digits of a very large integer and an integer k.
You are allowed to swap any two adjacent digits of the integer at most k times.
Return the... |
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 and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than on... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation).
Flip operation consists of cha... |
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 K eggs, and you have access to a building with N floors from 1 to N.
Each egg is identical in function, and if an egg breaks, you cannot drop it again.
You know... |
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. You should construct k non-empty palindrome strings using all the characters in s.
Return True if you can use all the characters in s to con... |
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, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.
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 integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing.
A subarray is a contiguous subsequence of 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 integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.
Example 1:
Input: [2,3,-2,4]
Outpu... |
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 num. You will apply the following steps exactly two times:
Pick a digit x (0 <= x <= 9).
Pick another digit y (0 <= y <= 9). The digit y can be equal... |
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 of even length n and an integer k.
We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k.
Return... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Suppose we abstract our file system by a string in the following manner:
The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents:
dir
subdir1
subdir2
... |
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 number of non-negative integers less than or equal to n, whose binary representations do NOT contain consecutive ones.
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 string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great":
... |
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, find the minimum window in S which will contain all the characters in T in complexity O(n).
Example:
Input: S = "ADOBECODEBANC", T = "ABC"
... |
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 longest increasing subsequence.
Example:
Input: [10,9,2,5,3,7,101,18]
Output: 4
Explanation: The longest increasing... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.A car travels from a starting position to a destination which is target miles east of the starting position.
Along the way, there are gas stations. Each station[i] represents... |
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 as many transactions ... |
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 an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
The above elevation ma... |
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 nums1 and nums2.
Return the maximum dot product between non-empty subsequences of nums1 and nums2 with the same length.
A subsequence of a array is a new arra... |
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 text, we are allowed to swap two of the characters in the string. Find the length of the longest substring with repeated characters.
Example 1:
Input: text = ... |
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 and an integer k.
Return True if every binary code of length k is a substring of s. Otherwise, return False.
Example 1:
Input: s = "00110110", k = 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 array of integers cost and an integer target. Return the maximum integer you can paint under the following rules:
The cost of painting a digit (i+1) is given by cost... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are the operator of a Centennial Wheel that has four gondolas, and each gondola has room for up to four people. You have the ability to rotate the gondolas counterclockwis... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.
Example 1:
Input: 123
Output: "One Hundred Twenty Thr... |
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 preferences for n friends, where n is always even.
For each person i, preferences[i] contains a list of friends sorted in the order of preference. In o... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.
Example 1:
Input:
A: [1,2,3,2,1]
B: [3,2,1,4,7]
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.Given an array of digits, you can write numbers using each digits[i] as many times as we want. For example, if digits = ['1','3','5'], we may write numbers such as '13', '551... |
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows:
In each step, you will choose any 3 piles of coins (not necessarily con... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.