[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

Construct String With Repeat Limit solution leetcode – A string a is lexicographically larger than a string b if in the first position where a and b differ, string a has a letter that appears later in the alphabet than the corresponding letter in b

Construct String With Repeat Limit solution leetcode You are given a string s and an integer repeatLimit. Construct a new string repeatLimitedString using the characters of s such that no letter appears more than repeatLimit times in a row. You do not have to use all characters from s. Return the lexicographically largest repeatLimitedString possible. A string a is lexicographically larger than a string b if in the first position where a and b differ, string a has a letter that appears later in … Read more

Count Integers With Even Digit Sum solution leetcode – Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even.

Count Integers With Even Digit Sum solution leetcode – Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even. The digit sum of a positive integer is the sum of all its digits. Input: num = 30 Output: 14 Explanation: The 14 integers less than or equal to 30 whose … Read more

[Solution] Count Array Pairs Divisible by K solution leetcode

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) 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 … Read more