[Solution] Anti-Fibonacci Permutation solution codeforces

Anti-Fibonacci Permutation solution codeforces – Let’s call a permutation ūĚĎĚp¬†of length¬†ūĚĎõn¬†anti-Fibonacci¬†if the condition¬†ūĚĎĚūĚĎĖ‚ąí2+ūĚĎĚūĚĎĖ‚ąí1‚ȆūĚĎĚūĚĎĖpi‚ąí2+pi‚ąí1‚Ȇpi¬†holds for all¬†ūĚĎĖi¬†(3‚ȧūĚĎĖ‚ȧūĚĎõ3‚ȧi‚ȧn). Recall that the permutation is the array of length¬†ūĚĎõn¬†which contains each integer from¬†11¬†to¬†ūĚĎõn¬†exactly once. Your task is for a given number¬†ūĚĎõn¬†print¬†ūĚĎõn¬†distinct¬†anti-Fibonacci permutations of length¬†ūĚĎõn. Anti-Fibonacci Permutation solution codeforces The first line contains a single integer¬†ūĚĎ°t¬†(1‚ȧūĚĎ°‚ȧ481‚ȧt‚ȧ48)¬†‚ÄĒ the number of test cases. … Read more

[Solution] Doors and Keys solution codeforces

Doors and Keys solution codeforces – The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it. In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a … Read more

[Solution] PerMEXuation solution codechef

PerMEXuation solution codechef – You are given an integer NN¬†and a (00-indexed) binary string¬†AA¬†having length¬†N+1N+1. Find any permutation¬†PP¬†of¬†0,1,2,…,N‚ąí10,1,2,…,N‚ąí1¬†(or determine that it does not exist) that satisfies the following conditions for all¬†ii¬†(0‚ȧi‚ȧN0‚ȧi‚ȧN): if¬†Ai=0Ai=0: No contiguous segment of¬†PP¬†has¬†mexmex¬†equal to¬†ii if¬†Ai=1Ai=1: There exists at least one contiguous segment of¬†PP¬†that has¬†mexmex¬†equal to¬†ii PerMEXuation solution codechef If multiple permutations exist … Read more

[Solution] Perfect Permutation solution codechef

Perfect Permutation solution codechef – An index ii¬†in a permutation¬†PP¬†of length¬†NN¬†is said to be¬†good¬†if: PiPi¬†is divisible by¬†ii You are given¬†22¬†integers¬†NN¬†and¬†KK. You need to construct a permutation¬†PP¬†of length¬†NN¬†such that¬†exactly¬†KK¬†indices in that permutation are good. If no such permutation exists, output¬†‚ąí1‚ąí1. If multiple such permutations exist, output any. Perfect Permutation solution codechef The first line contains a … Read more

[Solution] Prefix Permutation solution codechef

Prefix Permutation solution codechef – You are given an array AA¬†of length¬†KK. Find any permutation¬†PP¬†of length¬†NN¬†such that only the prefixes of length¬†AiAi¬†(1‚ȧi‚ȧK1‚ȧi‚ȧK) form a permutation. Under the given constraints, it is guaranteed that there exists at least one permutation which satisfies the given condition. If there are multiple solutions, you may print any. Note: A … Read more

[Solution] Lazy Salesman solution codechef

Lazy Salesman solution codechef – Ved is a salesman. He needs to earn at least WW¬†rupees in¬†NN¬†days for his livelihood. However, on a given day¬†ii¬†(1‚ȧi‚ȧN1‚ȧi‚ȧN), he can only earn¬†AiAi¬†rupees by working on that day. Ved, being a lazy salesman, wants to take as many holidays as possible. It is known that on a¬†holiday, Ved does … Read more

[Solution] Peaceful Party solution codechef

Peaceful Party solution codechef – The mayor of your city has decided to throw a party to gather the favour of his people in different regions of the city. There are¬†33¬†distinct regions in the city namely¬†AA,¬†BB,¬†CC¬†comprising of¬†PAPA,¬†PBPB¬†and¬†PCPC¬†number of people respectively. However, the mayor knows that people of the region¬†BB¬†are in conflict with people of regions¬†AA¬†and¬†CC. … Read more

[Solution] Guess the bottom face solution codechef

Guess the bottom face solution codechef – It is known that in regular dice, the sum of opposite faces is 77. A regular dice is rolled and you are given the value¬†XX¬†showing on the top face. Determine the value on the bottom face. Guess the bottom face solution codechef The first line will contain¬†TT¬†– the … Read more

[Solution] Complete the credits solution codechef

Complete the credits solution codechef – In Uttu’s college, a semester is said to be a: Overload¬†semester if the number of credits taken¬†>65>65. Underload¬†semester if the number of credits taken¬†<35<35. Normal¬†semester otherwise Given the number of credits¬†XX¬†taken by Uttu, determine whether the semester is¬†Overload,¬†Underload¬†or¬†Normal. Complete the credits solution codechef The first line will contain¬†TT¬†– the … Read more

Count Array Pairs Divisible by K solution leetcode РGiven a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j)

Given a 0-indexed¬†integer array¬†nums¬†of length¬†n¬†and an integer¬†k, return¬†the¬†number of pairs¬†(i, j)¬†such that: 0 <= i < j <= n – 1¬†and nums[i] * nums[j]¬†is divisible by¬†k.   Count Array Pairs Divisible by K solution leetcode Input: nums = [1,2,3,4,5], k = 2 Output: 7 Explanation: The 7 pairs of indices whose corresponding products are divisible … Read more