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 a string str and an integer K, find whether the string can be changed into a pangram after at most k operations. A pangram is a sentence containing every letter in the e...
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.Tom and Jerry being bored in this pandemic, decides to play a game. Given an integer N. On each player's turn, that player makes a mov...
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.Chef has opened a new airline. Chef has 10 airplanes where each airplane has a capacity of X passengers. On the first day itself, Y ...
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.Given a Binary Tree, write a function to check whether the given Binary Tree is Complete Binary Tree or not. A complete binary tree is...
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.Given a string S. The task is to count the number of substrings which contains equal number of lowercase and uppercase letters. Examp...
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.Write a program to find the sum of the given series 1+2+3+ . . . . . .(N terms) Example 1: Input: N = 1 Output: 1 Explanation: For 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.Count the number of palindromic numbers less than N. Example 1: Input: N = 12 Output: 10 Explanation: There are 10 palindrome number l...
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 standing at a distance d from a tower of height h. Given either the distance to the tower or height of the tower and the angle...
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.Given three integers 'A' denoting the first term of an arithmetic sequence , 'C' denoting the common difference of an arithmetic sequ...
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 matrix $A$ of size $n \times n$. Rows are numbered from top to bottom from $1$ to $n$, columns are numbered fro...
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.Given a square matrix of size N X N, turn it by 180 degrees in anticlockwise direction without using extra memory. Example 1: Input:...
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.Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well. You are given an array A of N non-negative inte...
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 str. In a single operation, you can choose two indices L and R such that 1 ≤ L ≤ R ≤ N and complement 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.The *beauty* value of an array is defined as the difference between the largest and second largest elements of the array. Note that 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.You are given a string $s$ consisting only of upper case letters A and B. For an integer $k$, a pair of indices $i$ and $j$ ($1 \le 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.A core right in Roman tenancy law was the availability of sunlight to everybody, regardless of status. Good sun exposure has a number ...
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 totally bored with nothing to do. You notice a pattern of spots on the wall in front of you and begin to dwell on them. There ...
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.Rahul is a geek. Head is the lucky call for him. You have to make him lucky. You are provided N coins. If the coin is heads facing upw...
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.Read problem statements in [Russian] Chef is having a candlelit dinner with his girlfriend at his place. Currently, it is time $0$, C...
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.Given an array of size N-1 such that it only contains distinct integers in the range of 1 to N. Find the missing element. Example 1: 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.Early this morning, I found our little Bruce sitting on a bench alone in the park. I sat beside him to ask where has he dropped his s...
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.For encoding an even-length binary string into a sequence of A, T, C, and G, we iterate from left to right and replace the characters ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Give a N * N square matrix A, return all the elements of its anti-diagonals from top to bottom. Example 1: Input: N = 2 A = [[1, 2], [3, 4]] Output: 1 2 3 4 Explanation...
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.Imagine an imaginary array of length N containing balls. Given 2 arrays color and radius of length N each, where color[i] represents 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.Given an array A[] of N integers. The task is to partition the array into four non-empty contiguous subarrays P, Q, R, and S such that...
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.Given a binary number (of $N$ bits) $X$. Find the highest power of 2 that divides this number. Note: If the binary number is "100" the...
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 Delft there are a number of bridges that are still being operated by a human, known as the bridge operator. One such bridge operato...
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.Given a matrix of size r*c. Traverse the matrix in spiral form. Example 1: Input: r = 4, c = 4 matrix[][] = {{1, 2, 3, 4}, ...
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.Given an array of integers, where all elements but one occur twice, find the unique element. Example $a=[1,2,3,4,3,2,1]$ The u...
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. You can perform the following operation on the array any number of times: Choose any [subseque...
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.Given a weighted directed graph with n nodes and m edges. Nodes are labeled from 0 to n-1, the task is to check if it contains a negat...
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 two renowned houses of the Seven Kingdoms - The Starks & The Lannisters have a rather dull relationship. "The Lannisters always pa...
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.Given a number N, find the even factor sum of the number N. Example 1: Input: N = 30 Output: 48 Explanation: Even dividers sum 2...
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.Nakul is on a Gold Island. In front of him are precious coins numbered 1 to 10^8 where each coin is in the form of a regular polygon w...
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.A mysterious circular arrangement of black stones and white stones has appeared. Ming has been tasked with balancing the stones so tha...
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 N stacks of books. Each stack of books has some non zero height Hi equal to the number of books on that stack ( considering 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.A cake assembly line in a bakery was once again optimized, and now $n$ cakes are made at a time! In the last step, each of the $n$ cak...
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.Given a string, S.The string can contain small case English letters or '?'. You can replace '?' with any small English letter. Now if ...
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 are playing a game. There are $n$ cells in a row. Initially each cell is either red or blue. Alice goes first. On each ...
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.Damir likes to rotate. Right now he is rotating tables of letters. He wrote an $R\times C$ table onto a piece of paper. He has also ch...
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 statistic of price changes for one product represented as an array of $n$ positive integers $p_0, p_1, \dots, p_{n - 1}$, w...
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 two groups, one of $N$ boys and the other of $N$ girls numbered from $1$ to $N$. You are given two arrays $A$ and $B$ conta...
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.Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices tha...
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.Thore Husfeldt likes to compare his time on solved Kattis problems with other people. If he has written the fastest solution on a prob...
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.A new deadly virus has infected large population of a planet. A brilliant scientist has discovered a new strain of virus which can cur...
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.Given two numbers 'N' and 'S' , find the largest number that can be formed with 'N' digits and whose sum of digits should be equals 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.In many programming languages, the “plus” symbol (‘+’) has at least two standard meanings: - arithmetic addition - string concatenat...
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.Your University has a large auditorium and today you are on duty there. There will be n lectures today — all from different lecturers,...
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.Read problems statements in Mandarin Chinese and Russian. Chef loves to prepare delicious dishes. This time, Chef has decided to pr...
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.Given a binary matrix of dimensions M * N. One can perform the given operation in the matrix. If the value of matrix[i][j] is 0, then...
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.Jeny love Sweets so much. Now she is at famous restaurant and wants to eat M pieces of a particular sweet. Cost of nth sweet can only ...
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.Even though she saw Zvonko steal Mirko’s microprocessor in the second task, Mirko’s sister Ivana did not tell Mirko because she likes ...
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.Given a string containing of 0, 1 and ? - a wildcard character, generate all distinct binary strings that can be formed by replacing e...
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 that represents the postfix form of a valid mathematical expression. Convert it to its infix form. Example: Inp...
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.Given a string consisting of lowercase letters, arrange all its letters in ascending order. Example 1: Input: S = "edcab" Output: "ab...
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.Time has come for Ma5termind and his friends Shasha and Alok to decide their job locations. To serve the above purpose better, they as...
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 collection of numbers (candidates) and a target number (target), find all unique combinations in candidates where the ...
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’ve intercepted encrypted communications between Martian diplomats. Since Martian diplomats are often spies, you decide to decrypt ...
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 array A[] having 10 elements which contain 6 different numbers in which only 1 number is repeated five times. Your task is to find the duplicate number using tw...
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 size n. Arrange the elements of the array in a way similar to the to-and-fro movement of a Pendulum. The minimum element out of the list of integers, mu...
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.Given two strings text and pattern, find the first index where pattern exactly matches with any substring of text. Return -1 if patt...
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.Given elements of a stack, clone the stack without using extra space. Example 1: Input: N = 10 st[] = {1, 1, 2, 2, 3, 4, 5, 5, 6, 7} 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.Chef is currently standing at stair 0 and he wants to reach stair numbered X. Chef can climb either Y steps or 1 step in one move. ...
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.Xander Cage has a list of cities he can visit on his new top-secret mission. He represents each city as a tuple of $(latitude,longitud...
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.Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Even though it was a little unexpected, Chef did it! H...
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.Given an N x M matrix, with a few hurdles(denoted by 0) arbitrarily placed, calculate the length of the longest possible route possibl...
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.Paul owns a catering company and business is booming. The company has $k$ catering teams, each in charge of one set of catering equipm...
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.Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chefland consists of $N$ pro...
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 directed graph $G$ which can contain loops (edges from a vertex to itself). Multi-edges are absent in $G$ which means ...
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.How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other? The knight...
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.Wall Maria has been broken! Eren must evacuate as soon as possible from his house. He must find the fastest route to escape within Wal...
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.Aleksey has $n$ friends. He is also on a vacation right now, so he has $m$ days to play this new viral cooperative game! But since it'...
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 the computer-generated world Matriks, you work as a consultant for some hip IT companies that need unique slides for their cool off...
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.Given a N x N 2D matrix Arr representing an image. Rotate the image by 90 degrees (anti-clockwise). You need to do this in place. Note...
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.Given an integer x, find the square root of x. If x is not a perfect square, then return floor(√x). Example 1: Input: x = 5 Output: ...
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.Yoshi is a frog. He lives in the ZOO under a log which was specially transported there from a distant equatorial rainforest. The log 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.Given an unsorted array Arr of size N. Find the minimum number of removals required such that twice of minimum element in the array is...
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.Given a linked list of strings having n nodes check to see whether the combined string formed is palindrome or not. Input: You have 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.Ritika has a coin of $N but she is the type of person who loves to have as much money as possible. A coin of $N can be exchanged in 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 are given a $sorted$ list $A$ of size $N$.You have to make a new list $B$ such that $B[i]$ is equal to the number of elements $st...
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 BASIC computer programming language has been popular for many years, and there have been dozens of ‘dialects’ of the language. It’...
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 BST given with the root node with the key part as an integer only. You need to find the in-order successor and predecessor of...
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.This challenge uses the famous KMP algorithm. It isn't really important to understand how KMP works, but you should understand what it...
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.Given a big positive number x represented as string, find value of x % 11 or x mod 11. Output is expected as an integer. Example 1: In...
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.Alina has discovered a weird language, which contains only $4$ words: ${A}$, ${B}$, ${AB}$, ${BA}$. It also turned out that there are ...
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.Given two positive integers N and X, where N is the number of total patients and X is the time duration(in minutes) after which a new ...
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 sweets in the store. The cost of the i^{th} sweet is A_{i} rupees. Chef is a regular customer, so after buying 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.Stephanie just learned about a game called Nim in which there are two players and $n$ piles of stones. During each turn, a player must...
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.Kulyash has given you an array A of size N. He defines the *subsequence-number* of a non-empty [subsequence] S of array A as the nu...
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 two binary strings $a$ and $b$ of length $n$. You would like to make all the elements of both strings equal to $0$. Unfortuna...
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 array $a$ (all elements of the array are $0$ or $1$) of length $n$. You wish to sort this array, but unfortunat...
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.Luka started driving international routes with his truck. His biggest problem is the border with Slovenia. The border is a point of en...
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.Louise and Richard have developed a numbers game. They pick a number and check to see if it is a power of $2$. If it is, they divide...
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.Nezzar's favorite digit among $1,\ldots,9$ is $d$. He calls a positive integer lucky if $d$ occurs at least once in its decimal repres...
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.Given a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node store...
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 of length n and a number k. Let's pick k non-overlapping non-empty subarrays of the initial array. Let si be 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.Lisa works as a waitress in a restaurant. Tonight is her birthday so Lisa asked the chef to prepare his special meal for her friends. ...
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.Andi and Bob were two great friends. The tales of their friendship were famous all over the Hackland. Andi liked watching Takeshi's Ca...
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.One fine day, when everything was going good, Mehta was fired from his job and had to leave all the work. So, he decided to become a 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.You and your friends have just returned from a beautiful vacation in the mountains of the Netherlands. When on vacation, it’s annoying...