Uncategorized

End Sorted solution codechef

End Sorted solution codechef Chef considers a permutation PP of {1,2,3,…,N}{1,2,3,…,N} End Sorted if and only if P1=1P1=1 and PN=NPN=N. Chef is given a permutation PP. In one operation Chef can choose any index i (1≤i≤N−1)i (1≤i≤N−1) and swap PiPi and Pi+1Pi+1. Determine the minimum number of operations required by Chef to make the permutation PP End Sorted. Note: An array PP is said to be a permutation of {1,2,3,…,N}{1,2,3,…,N} if PP contains each element of {1,2,3,…,N}{1,2,3,…,N} exactly once. Input Format The …

End Sorted solution codechef Read More »

Construct N solution codechef

Construct N solution codechef You are given an integer NN. Find if it is possible to represent NN as the sum of several(possibly zero) 22‘s and several(possibly zero) 77‘s. Formally, find if there exist two integers X,Y (X,Y≥0)X,Y (X,Y≥0) such that 2⋅X+7⋅Y=N2⋅X+7⋅Y=N. Input Format The first line of input will contain a single integer TT, denoting the number of test cases. Each test case consists of …

Construct N solution codechef Read More »

Minimum Coins solution codechef

Minimum Coins solution codechef There are only 22 type of denominations in Chefland: Coins worth 11 rupee each Notes worth 1010 rupees each Chef wants to pay his friend exactly XX rupees. What is the minimum number of coins Chef needs to pay exactly XX rupees? Input Format The first line of input will contain a single integer TT, denoting the number of test cases. Each test case …

Minimum Coins solution codechef Read More »

Yet Another Problem About Pairs Satisfying an Inequality solution codeforces

You are given an array 1,2,…a1,a2,…an. Count the number of pairs of indices 1≤,≤1≤i,j≤n such that <<<ai<i<aj<j. Solution – CLICK HERE Yet Another Problem About Pairs Satisfying an Inequality solution codeforces The first line contains an integer t (1≤≤10001≤t≤1000) — the number of test cases. The first line of each test case contains an integer n (2≤≤2⋅1052≤n≤2⋅105) — the length of the array. The second line …

Yet Another Problem About Pairs Satisfying an Inequality solution codeforces Read More »

Mirror Grid solution codeforces

You are given a square grid with n rows and n columns. Each cell contains either 00 or 11. Solution – CLICK HERE Mirror Grid solution codeforces In an operation, you can select a cell of the grid and flip it (from 0→10→1 or 1→01→0). Find the minimum number of operations you need to obtain a square that remains the same when rotated 0∘0∘, 90∘90∘, 180∘180∘ and 270∘270∘. The picture below …

Mirror Grid solution codeforces Read More »

Double Strings solution codeforces

You are given n strings 1,2,…,s1,s2,…,sn of length at most 88. Solution – CLICK HERE For each string si, determine if there exist two strings sj and sk such that =+si=sj+sk. That is, si is the concatenation of sj and sk. Note that j can be equal to k. Double Strings solution codeforces Recall that the concatenation of strings s and t is +=12…12…s+t=s1s2…spt1t2…tq, where p and q are the lengths of strings s and t respectively. For example, concatenation of “code” and “forces” is “codeforces“. Input The first …

Double Strings solution codeforces Read More »