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.Alice likes to shop online. The main reason is that she gets a lot of discounts! There are M online shops from where she purchases her...
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 consisting of only lowercase characters. Find the lexicographically smallest string after removing exactly k characte...
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 elements. Find the majority element in the array. A majority element in an array A of size N is an element 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.Chef has an array A of length N. In one operation, Chef can choose any two distinct indices i, j (1 ≤ i, j ≤ N, i \neq j) and either ...
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 median Example 1: Input: N = 5 arr[] = 90 100 78 89 67 Output: 89 Explanation: Aft...
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.Shiv is fond of prime numbers. His girl friend priya found a list 'C' of numbers , she gave it to Shiv and started asking questions 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.You are given a string which consists of letters and other characters. Convert it to uppercase, i.e., replace all lowercase letters wi...
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, MoEngage wants you to determine if it is possible to rearrange the digits of N (in decimal representation)...
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.Julia is betting on a large sporting competition involving matches between pairs of teams. There are no parallel matches and each bett...
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.Teacher Herkabe has decided to rank his students again. This time, he wants his list to also be aesthetically pleasant, so he has deci...
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 and a range(L, R). The task is to find the number of subarrays having sum in the range L to R (inclus...
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. Only $x$ hours are left for the March ...
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.Announcement ************Second Round will be ONLINE instead of ONSITE************* Problem Statement Deepanshu often likes to play 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.Given a string S, find the longest palindromic substring in S. Substring of string S: S[ i . . . . j ] where 0 ≤ i ≤ j < len(S). Palin...
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 built a binary string S that has exactly N hills and M valleys. A hill is any index 1 < i < |S| such that both its neighbors 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.Mirkos village has only one long street stretching from east to west with M houses. Each house has a unique house number, starting wit...
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.Tim and Julia‘s life filled with joy, when little Tim happened to them. To train little Tim, they decided to give him one small puzzle...
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 $A$ be an array of $N$ elements and let us define beauty of array as (consider 1 based indexing) long long int beauty(int N, 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.Given a Weighted Directed Acyclic Graph (DAG) and a source vertex s in it, find the longest distances from s to all other vertices 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.Pick a random financial transaction from the ledger of a typical business and there is about a 30% chance that the first non-zero digi...
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 is about a Prince who wants to rescue her Princess from a bunch of ferocious monsters. You are given a grid of size n+2 and m. 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.You are given a square map as a matrix of integer strings. Each cell of the map has a value denoting its depth. We will call a cell 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.A very popular position has just opened up at Poodle Inc. Candidates have formed a queue while they wait for their turn to be intervie...
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 in which each node element contains a number. Find the maximum possible path sum from one special node to another ...
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 define a function f on a binary string S of length N as follows: f(S) = \sum_{i = 1}^{N - 1} |S_{i+1} - S_{i}|. JJ and Uttu have ...
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. Chef is studying computer sci...
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.Peter has lined up hay bales. Some hay bales contain parasites and he wants to move the infected hay bales to the back of the sequence...
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.Luke likes to ride on public transit in different cities he visits, just for fun. He tries to find unique ways to travel in loops: lea...
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.HackerChess is a variant of chess played at HackerRank. It is a game played between two players who make moves in turns until one 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.Given a positive integer N, find the Nth Even Fibonacci number. Since the answer can be very large, return the answer modulo 100000000...
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 link to the Russian translation. The evil vault is open again. This time Damon is looking for the last "Everlasting". The vaul...
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 cold and remote areas of northern Sweden, a young boy named Anton lives. Being born to a family of pistvakts (an occupation 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 likes to play with strings of characters, but this time he has taken it too far – he put an “explosion” in the string! An explos...
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 you need to find the submatrix with the largest number of elements, where the GCD (Greatest Common Divisor) of its elem...
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.Calculate the sum of all the multiples of 3 or 7 below the natural number N. Example 1: Input: 10 Output: 25 Explanation: Numbers 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.In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,... Chef needs to deliver packages to $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.A permutation is a sequence of $n$ integers from $1$ to $n$, in which all the numbers occur exactly once. For example, $[1]$, $[3, 5, ...
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 Berland Army is preparing for a large military parade. It is already decided that the soldiers participating in it will be divided...
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.According to Wikipedia, FizzBuzz is a group word game for children to teach them about division. This may or may not be true, but 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.Background: After returning from ACM ICPC 2014, Mehta is back with a much greater stamina and enthusiasm to solve much complicated 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.Burenka is about to watch the most interesting sporting event of the year — a fighting tournament organized by her friend Tonya. $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.Little Elephant from the Zoo of Lviv hates exams. Since Little Elephant lives in Ukraine, he is going to take exams called 'ZNO'. Help...
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 binary trees with head reference as T and S having at most N nodes. The task is to check if S is present as subtree in T. 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.Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value. Example $arr...
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 integers $n$, $a$, and $b$. Determine if there exist two permutations $p$ and $q$ of length $n$, for which the fol...
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 game of The Last Word, Motu begins a round by showing Chotu a string S. Chotu has a whiteboard which is initially blank. Motu 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.You are given a string $s$, consisting of lowercase Latin letters. While there is at least one character in the string $s$ that is rep...
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's no day that Kevin doesn't want to explode something. Today Kevin and Elvis decided to make a dynamite. They have N packages ...
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 arrays A[] and B[] of same length N. There are N types of sticks of lengths specified. Each stick of length A[i] is present ...
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 matrices A and B. Both have N rows and M columns. In the matrix A, numbers from 1 to MN have been written in row major order...
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 [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Chef is stuck at the following...
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 integers ai. Find the largest absolute value of difference between adjacent elements of the array max(abs(ai...
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 sequence {x1, x2, .. xn} is alternating sequence if its elements satisfy one of the following relations : x1 < x2 > x3 < x4 > x5.......
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 a binary string $S$. Che...
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 size N, find the longest subsequence such that difference between adjacent elements is one. Example 1: Input: 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.One of the built-in functions of Python is divmod, which takes two arguments $\boldsymbol{\alpha}$ and $\boldsymbol{b}$ and returns 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.Given a Binary Search Tree, find the sum of all leaf nodes. BST has the following property (duplicate nodes are possible): The left 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.Given string S representing a postfix expression, the task is to evaluate the expression and find the final value. Operators will 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.Given an array arr[] of non-negative integers and an integer sum, the task is to count all subsets of the given array with a sum equal...
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.Mario was going to gift Princess Peach a string S of even length N. Mario was clumsy and thus, broke the string in the middle. He no...
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$^\dagger$ $p$ of length $n$ and a positive integer $k \le n$. In one operation, you: Choose $k$ distinct...
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 all started with a black-and-white picture, that can be represented as an $n \times m$ matrix such that all its elements are either...
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. Not everyone probably knows that Chef has younger brot...
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 is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big...
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 string st and a number k. You have to find the Longest continuous sequence of '0' after repeating Given string K time. ...
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 binary string $a$ of length $n$. In one operation, you can select any prefix of $a$ with an equal number of $0$ and $1$ sym...
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 is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He has completely the wrong idea ...
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 acyclic graph(DAG) with n nodes labeled from 0 to n-1. Given edges, s and d ,count the number of ways to reach from 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.There are $n$ piles of sand where the $i$-th pile has $a_i$ blocks of sand. The $i$-th pile is called too tall if $1 < i < n$ and $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.Chef has two integers A and B. Chef wants to find the minimum value of \texttt{lcm}(A, X) - \texttt{gcd}(B, X) where X is any positi...
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 group of friends was given a necklace. The necklace is a circular nylon wire with gold beads of various weights glued on. They want ...
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.As you didn’t show up to the yearly general meeting of the Nordic Club of Pin Collectors, you were unanimously elected to organize thi...
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 and a key in the binary tree, find the node right to the given key. If there is no node on right side, then return...
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.Have you recently visited an arcade? Arcade games seem to have become more boring over the years, requiring less and less skill. In fa...
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.Geek is very fond of patterns. Once, his teacher gave him a pattern to solve. He gave Geek an integer n and asked him to build a patte...
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.MoEngage has 3 decks. Each deck consists of N cards, numbered from 1 to N. He draws out 1 card from each deck randomly with each card ...
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.Two people are playing Nimble! The rules of the game are: The game is played on a line of $n$ squares, indexed from $\mbox{0}$ to $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 a Binary Tree having positive and negative nodes. Find the maximum sum of a level in the given Binary Tree. 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.Given a string s, remove all its adjacent duplicate characters recursively. Note: For some test cases, the resultant string would be ...
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.Sorting is useful as the first step in many different tasks. The most common task is to make finding things easier, but there are othe...
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 square grid with $n$ rows and $n$ columns. Each cell contains either $0$ or $1$. In an operation, you can select a ce...
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 R which represents the radius of a circle that has (0,0) as its centre, find the total number of lattice points on 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.Read problems statements in Mandarin Chinese and Russian. Roma gave Chef an array of intergers. Chef wants to make all 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.Joey never liked Maths, because he doesn't like counting. Ten digits and base 10 always makes him suffer while counting. So he wondere...
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.Johnny has been roped into a fantasy soccer league and needs your help to set up the best team. He has a list of $10$ players that 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 string is made of only lowercase latin letters (a,b,c,d,.....,z). Can you find the length of the lexicographically smallest string 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.Read problems statements in Mandarin Chinese and Russian. Chef wants to hire a new assistant. He published an advertisement regardi...
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 sorted(in ascending order) array A[ ] with distinct elements is rotated at some unknown point, the task is to find the minimum eleme...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a sorted linked list of distinct nodes (no two nodes have the same data) and an integer X. Count distinct triplets in the list that sum up to given integer X. Note: 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.We all know that passwords are not very secure unless users are disciplined enough to use passwords that are difficult to guess. But 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.Given an array arr of N integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a^{2} + b^{2} = 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.Chef and Chefina are playing with dice. In one turn, both of them roll their dice at once. They consider a turn to be *good* if the 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.George has bought a pizza. George loves cheese. George thinks the pizza does not have enough cheese. George gets angry. George’s pizz...
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 day during the fight between good and evil, Meganath used his Brahmastra on Lakshman. As nothing could stop a Brahmastra so Laks...
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 about to organize a big programming competition. N competitors are registered for it. You know that you are going to divide al...
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.Sarah is cycling to work. On her way there, she encounters the same traffic light every day. Before she reaches the lights, she altern...
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 integers (X and N). You have to make a number in such a way that it contains the first digit and last digit occurring 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.Taylor loves trees, and this new challenge has him stumped! Consider a tree, $\boldsymbol{\boldsymbol{t}}$, consisting of $n$ nodes. ...
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 integers. Calculate the sum of its elements. Input The i-th line of the input contains an integer ai (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.Pierre is famous for his macarons. He makes round macarons, stored in square boxes of size $1\times 1$, and oval-shaped macarons, stor...