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.Given string s consisting only a,b,c. return the number of substrings containing at least one occurrence of all these characters a, 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.An array $b$ is good if the sum of elements of $b$ is even. You are given an array $a$ consisting of $n$ positive integers. In one op...
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 Production Manager of a dance company has been tasked with determining the cost for the seasonal dance recital. Because of their 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.Given a string contains 'E' and 'O', 'E' represents a number is even and 'O' represents a number is odd. To make an element even, you ...
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 scavenger hunt is being organized for programming contest participants. In addition to the starting and ending locations of the race...
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 0s and 1s. Find the length of the largest subarray with equal number of 0s and 1s. Example 1: Input: N = 4 A[] = {0,...
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.Rhythm gaming seems to be having a bit of a renaissance this October, with both a new “Rock Band” and a “Guitar Hero” game coming out....
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 a stock market, there is a product with its infinite stocks. The stock prices are given for N days, where price[i] denotes the pric...
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 positive integer N, check if it is a perfect square or not. Note: Try to solve the question using only addition and subtractio...
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 binary string is a string consisting only of the characters 0 and 1. You are given a binary string $s$. For some non-empty substrin...
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.Mr. Chef is the manager of the Code cinemas and after a long break, the theatres are now open to the public again. To compensate for 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.Chef has an array A of size N and an integer M, such that 1 ≤ A_{i} ≤ M for every 1 ≤ i ≤ N. The *distance* of an array B from array ...
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, the task is to find out whether this number is a Smith Number or not. A Smith Number is a composite number whose sum...
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.An Introduction to the Longest Increasing Subsequence Problem The task is to find the length of the longest subsequence in a given ...
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.Kepler’s Law states that the planets move around the sun in elliptical orbits with the sun at one focus. Kepler's 3rd law is The Law 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.Given two square matrices matrixA and matrixB of size n x n. Find the addition of these two matrices. Note :- You don't have to retur...
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 tank with capacity C litres which is completely filled in starting. At the end of every day, tank is filled with L litres of 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.Today Oz wants to make some money through his paintings. For painting, Oz has X white color pens, Y red color pens and Z green color p...
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 sides of a triangle A, B and C in the form of integers. Find the area of the triangle. Note: The triangle may not exist. 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.Quick Sort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given array around the picked pivot. G...
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.Kristina has two arrays $a$ and $b$, each containing $n$ non-negative integers. She can perform the following operation on array $a$ 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.Divyank is in love with arrays.So while solving problems on arrays Divyank encountered the following problem :- F(A) for an array A o...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array A[ ] and its size N your task is to complete two functions a constructST function which builds the segment tree and a function RMQ which finds range minimum ...
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. You are given a string $S$ 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.Once upon a time, in the Land of the Shamans, everyone lived on the Sky-High Beanstalk. Each shaman had a unique identifying number 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 a Binary Tree. Find the Zig-Zag Level Order Traversal of the Binary Tree. Example 1: Input: 1 / \ 2 3...
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.Raj is fond of Table Tennis. He has a few friends who also play table tennis. Once as he walked past his college, he found 2 of his fr...
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.Due to the rise of covid-19 cases in India, this year BCCI decided to organize knock-out matches in IPL rather than a league. Today 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.While reviewing code recently being checked into the repository, Jim discovered that some employees now and then seemed to copy code r...
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.Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as Stockfish and Komodo 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.A guy has to reach his home and does not want to be late. He takes train to reach home. He has a mental illness, so he always switches...
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 work in the quality control department of technical support for a large company. Your job is to make sure all client issues have 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.Maj loves pickled cucumber (also known as pickles). However, her partner is not as keen on filling a sandwich with pickles. Maj would ...
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.Filip came across an interesting math problem: He was supposed to find a five-digit number with the following property. If you cross 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 hosts a party for his birthday. There are N people at the party. All these N people decide to play Jenga. There are X Jenga tile...
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 Arr of N integers.Calculate the sum of Bitwise ANDs(&) all the pairs formed by the given array. Example 1: Input: N=3 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 bicycle race is being organized in a land far, far away. There are $N$ towns in the land, numbered $1$ through $N$. There are also $...
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.Digits $4$ and $7$ are lucky, while all others are unlucky. An integer is lucky if it contains only lucky digits in decimal notation. ...
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.Akku have solved many problems, she is genius. One day her friend gave her an Array of size n and asked her to perform some queries 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.On the forest-filled moon of Endor there is, if we are to believe the Guinness Book of Records, the longest stick in the whole galaxy....
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."Sometimes the thing that brings us together also pulls us apart." - Jarod Kintz. Shivam and Shantam are really good friends. What mo...
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.It was revealed in Harry Potter and the Prisoner of Azkaban thatr Peter Pettigrew had faked his death at the hands of Sirius Black and...
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.Kevin and Stuart want to play the 'The Minion Game'. Game Rules Both players are given the same string, $\mbox{S}$. Both players ha...
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 K sorted lists of integers, KSortedArray[] of size N each. The task is to find the smallest range that includes at least one ele...
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."Everybody! Doremy's Perfect Math Class is about to start! Come and do your best if you want to have as much IQ as me!" In today's mat...
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 Arr of size N. Find the sum of distinct elements in an array. Example 1: Input: N = 5 Arr[] = {1, 2, 3, 4, 5} 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.Mr. Modulo comes up with another problem related to modulo and this time he is interested in finding all the possible pairs a and b 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.You have N soldiers numbered from 1 to N. Each of your soldiers is either a liar or a truthful person. You have M sets of information ...
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.Mike and Joe are playing a game with some stones. Specifically, they have $n$ piles of stones of sizes $a_1, a_2, \ldots, a_n$. These ...
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.Square Subsequences A string is called a square string if it can be obtained by concatenating two copies of the same string. For exam...
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 classmate, whom you do not like because he is boring, but whom you respect for his intellect, has two strings: $s$ of length $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.Given an array, if ‘n’ positive integers, count the number of pairs of integers in the array that have the sum divisible by 4. Exampl...
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's new friend hErd gave him two functions f and g. The function f is defined over x (x≥ 1) as: f(x) = \begin{cases} 0, & \text...
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 Arr of size N with all elements greater than or equal to zero. Return the maximum product of two numbers possible. Exam...
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.An XOR operation on a list is defined here as the xor ($\oplus$) of all its elements (e.g.: $XOR(\{A,B,C\})=A\oplus B\oplus C$). 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.Given two numbers N and K, change the Kth (1-based indexing) bit from the left of the binary representation of the number N to '0' 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.Given a number in form of a string s. The task is to find whether the number is valid indian mobile number or not. Rules for valid :-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.Being a traveling salesman is tough work. Per is one such salesman and would like to find an efficient way to visit all the cities 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.Consider a string, $S$, of $n$ lowercase English letters where each character, $s_i$ ($0\leq i<n)$, denotes the letter at index $\bold...
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.Santa is still not married. He approaches a marriage bureau and asks them to hurry the process. The bureau checks the list of eligible...
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 positive integer N and an array A of size N. There are N lists L_{1}, L_{2} \ldots L_{N}. Initially, L_{i} = [A_{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.Everyone wants to live as long a life as possible. As time progresses, technology progresses. Various anti-aging pills get introduced ...
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.Web pages are littered with ads (advertisements) these days. You wrote a simple program to detect images which are ads and remove them...
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 row of N houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each hous...
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."We have a holiday tomorrow, its Ambedkar Jayanti" says Chotu. "I will sleep and eat whole day!!" exclaims Motu. "Also we don't 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.Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are $N$ seats in a row. You 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 integers A and B.Find out the number of steps required to repeatedly subtract the smaller of the two from the larger until 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.Chotu is having his mathematics test tomorrow. Chotu was solving a problem and found out that it is quite difficult for him. Given two...
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 clocks in the Pradnya Planet which beep after different time periods. The clocks are represented as C1, C2, ... Cn and 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.Vaidyanathan is walking on a sidewalk of a road, the road consists of W lanes and each lane consists of M spaces where at a moment 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.Given an integer n. Return the nth row of the following look-and-say pattern. 1 11 21 1211 111221 Look-and-Say Pattern: To generate 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 known chef has prepared $n$ dishes: the $i$-th dish consists of $a_i$ grams of fish and $b_i$ grams of meat. The banquet organizers...
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.It is Catmas time again, and that means a lot of stress for everyone. In the Kattis family everyone used to buy gifts for everyone els...
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 time has finally come, MKnez and Baltic are to host The Game of the Century. For that purpose, they built a village to lodge its p...
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.JJ loves playing with averages. He has an array A of length N. He wants to divide the array A into two non-empty subsets P and Q such ...
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.IIIT-Delhi has been invaded by aliens. An alien race from a galaxy far away is shooting a beam on the Academic Block of IIIT-Delhi. Ev...
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.Complete the function solveMeFirst to compute the sum of two integers. Example $a=7$ $b=3$ Return $10$. Function Description ...
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 Directed Graph with V vertices (Numbered from 0 to V-1) and E edges, Find the number of strongly connected components in the g...
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.HackerLand Enterprise is adopting a new viral advertising strategy. When they launch a new product, they advertise it to exactly $5$ p...
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 a very busy person, with a lot of important meetings. Today, you have a meeting for which it is insanely important to arrive 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.Donald is playing a game of cards against his cousin Gladstone. Each round proceeds as follows: - Donald chooses an (integer) amount ...
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 famous story about the mathematicians G.H. Hardy and Srinivasa Ramanujan goes as follows (as told by Hardy): I remember once going ...
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 collection of Intervals, the task is to merge all of the overlapping Intervals. Example 1: Input: Intervals = {{1,3},{2,4},{6,...
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 points in space (i.e. $\mathbb {R}^3$). The points are not coplanar. In other words, there is no plane in space 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.Mirko has a younger brother, Filip, who just started going to school and is having trouble with numbers. To help him get the hang of 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.Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has three spells. Their powers are A, 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.You are given a string S of length N, which consists of digits from 0 to 9. You can apply the following operation to the string: 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.Implement a Queue using two stack s1 and s2. Example 1: Input: enqueue(2) enqueue(3) dequeue() enqueue(4) dequeue() Output: 2 3 Explan...
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 equation of the form f(n) = f(n-1) + f(n-2) where f(0) = 1, f(1) = 1 , the task is to find the n^{th} term of this sequence. ...
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 integers. Find the minimum positive number to be inserted in array, so that sum of all elements of array becomes prime. If sum is already prime, then retur...
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.Polycarp has a string $s[1 \dots n]$ of length $n$ consisting of decimal digits. Polycarp performs the following operation with the 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.Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers 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.Samwell is bored while going to his medical school in Oldtown. He has a deck of cards that John had gifted him. He starts to play 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.Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, 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.Fourth Great and Bountiful Human Empire is developing a transconduit tunnel network connecting all it’s planets. The Empire consists o...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array arr[ ] of N positive integers, the task is to find the greatest element on the left of every element in the array which is strictly smaller than itself, if this...
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 pointer to the root of a binary search tree and values to be inserted into the tree. Insert the values into their appr...
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.Nimions speak a funny form of language. Whichever word they are trying to say, from which ever language, it doesn’t quite come out 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.Being a space captain can be a dangerous endeavour, especially when conducting missions in Borg space. Today your captain has been tas...
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 an array A consisting of N positive elements. The *frequency array* of A is the array B of size N such that B_{i} = *frequenc...