[Solution] Make Them Alike Solution Codechef

[Solution] Make Them Alike Solution Codechef You are given a permutation �P of length �N, an array �A of size �N, and an integer �M. Initially, 0≤��≤�0≤Ai​≤M. Consider an array �′A′ obtained from �A by replacing all zeros in �A with positive integers less than equal to �M. The array �′A′ will then be transformed as follows, in �N steps: In the ��ℎith step, we set ��′=���′Ai′​=APi​′​. The initial array �′A′ is said to be beautiful, if, after the transformation of �N steps, all elements of array �′A′ are equal. … Read more

[Solution] Good Permutations Solution Codechef

[Solution] Good Permutations Solution Codechef You are given two arrays �A and �B, each of size �N. Let �P denote a permutation length �N. The permutation �P is said to be good, if you can make an array �C where: ��=��+���Ci​=Ai​+BPi​​ or ��=��−���Ci​=Ai​−BPi​​, for all (1≤�≤�)(1≤i≤N); All elements of �C are equal. Out of the �!N! possible permutations, find the count of good permutations. Since the count can be huge, output it modulo 109+7109+7. Note that a permutation … Read more

[Solution] Find eX Solution Codechef

[Solution] Find eX Solution Codechef Chef has 44 positive integers �A, �B, �C, and �D such that �A %% �=�B=C %% �D. Find the smallest positive integer �X such that (�+�)(A+X) %% �=(�+�)B=(C+X) %% �D holds. It is guaranteed that such �X always exists. Input Format Find eX Solution Codechef The first line of input will contain a single integer �T, denoting the number of test cases. The first and only line of each test case contains four space-separated integers �A, �B, �C, … Read more

[Solution] Difference Matrix Solution Codechef

Difference Matrix Solution Codechef You are given an integer �N. You need to find an �×�N×N matrix such that: Each element of the matrix is an integer from 11 to �2N2; All elements of the matrix are unique; The absolute difference between elements in neighbouring cells is strictly greater than 11. It can be shown that there is at least one matrix that satisfies the … Read more

[Solution] Make A-B Same Solution Codechef

Make A-B Same Solution Codechef You are given two binary arrays �A and �B, each of size �N (�≥3)(N≥3). You can perform the following operation on array �A: Select three indexes �,�,i,j, and �k (1≤�<�<�≤�)(1≤i<j<k≤N), and set ��=��Aj​=Ai​ ∣∣ ��Aj​ ∣∣ ��Ak​. Here ∣∣ denotes the bitwise OR operation. Determine whether it is possible to convert the array �A to array �B by applying any (possibly zero) number of given operations. Note that, in a binary array each element is either 00 or 11. Input … Read more

[Solution] MIN To MAX Solution Codechef

MIN To MAX Solution Codechef You are given an array �A of size �N. Let �M be the minimum value present in the array initially. In one operation, you can choose an element ��Ai​ (1≤�≤�)(1≤i≤N) and an integer �X (1≤�≤100)(1≤X≤100), and set ��=�Ai​=X. Determine the minimum number of operations required to make �M the maximum value in the array �A. Input Format MIN To MAX Solution Codechef The first line of input will contain a … Read more

[Solution] Reach Home Solution Codechef

Reach Home Solution Codechef Chef is hungry and wants to reach home. Chef can travel up to 55 kilometres on 11 litre of fuel on his motorcycle. Currently, his motorcycle is filled with �X litres of fuel and his home is �Y kilometres away. Determine whether Chef can reach his home on his motorcycle or not. Input Format Reach Home Solution Codechef The … Read more

[Solution] Candy Division Solution Codechef

Candy Division Solution Codechef There are three friends and a total of �N candies. There will be a fight amongst the friends if all of them do not get the same number of candies. Chef wants to divide all the candies such that there is no fight. Find whether such distribution is possible. Input Format Candy Division Solution Codechef The first line of input … Read more

Rearrange Array to Maximize Prefix Score Solution

Rearrange Array to Maximize Prefix Score Solution You are given a 0-indexed integer array nums. You can rearrange the elements of nums to any order (including the given order). Let prefix be the array containing the prefix sums of nums after rearranging it. In other words, prefix[i] is the sum of the elements from 0 to i in nums after rearranging it. The score of nums is the number of positive integers in the array prefix. Return the maximum score … Read more

[Solution] Count the Number of Vowel Strings in Range Solution

Count the Number of Vowel Strings in Range Solution You are given a 0-indexed array of string words and two integers left and right. A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’. Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].   Example 1:Count the Number … Read more