[Solution] Count Good Triplets in an Array solution leetcode

Count Good Triplets in an Array  – You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, …, n – 1]. A good triplet is a set of 3 distinct values which are present in increasing order by position both in nums1 and nums2. In other words, if we consider pos1v as the index of the value v in nums1 and pos2v as the index of the value v in nums2, then a good triplet … Read more

[Solution] Maximum Split of Positive Even Integers solution leetcode

Maximum Split of Positive Even Integers solution leetcode – You are given an integer finalSum. Split it into a sum of a maximum number of unique positive even integers. For example, given finalSum = 12, the following splits are valid (unique positive even integers summing up to finalSum): (2 + 10), (2 + 4 + 6), and (4 + 8). Among them, (2 + 4 + 6) contains … Read more

[Solution] Find Three Consecutive Integers That Sum to a Given Number solution leetcode

Find Three Consecutive Integers That Sum to a Given Number – Given an integer num, return three consecutive integers (as a sorted array) that sum to num. If num cannot be expressed as the sum of three consecutive integers, return an empty array.   Find Three Consecutive Integers That Sum to a Given Number solution leetcode Input: num = 33 Output: [10,11,12] Explanation: 33 can … Read more

[Solution] Count Equal and Divisible Pairs in an Array solution leetcode

Count Equal and Divisible Pairs in an Array solution leetcode – Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.   Count Equal and Divisible Pairs in an Array solution leetcode Input: nums = [3,1,2,2,2,1,3], k = 2 Output: 4 … Read more

[Solution] Array Division solution codechef

Array Division solution codechef – Given a sequence XX of length MM, f(X)f(X) is defined as f(X)=∑M−1i=1|Xi+1−Xi|f(X)=∑i=1M−1|Xi+1−Xi|. For e.g., f([3,1,7,2])=|1−3|+|7−1|+|2−7|=13f([3,1,7,2])=|1−3|+|7−1|+|2−7|=13 JJ has an array AA of length NN. He wants to divide the array AA into two subsequences PP and QQ (possibly empty) such that the value of f(P)+f(Q)f(P)+f(Q) is as large as possible. (Note that each AiAi must belong to either subsequence PP or subsequence QQ). Help him find this maximum value of f(P)+f(Q)f(P)+f(Q). Note: A sequence XX is … Read more

[Solution] Stone Game solution codechef

Stone Game solution codechef – Initially, Alice and Bob both have a bag of NN stones each with every stone having a lowercase alphabet written on it. Both players know the stones of the other player. Alice and Bob want to create a string SS of length 2⋅N2⋅N using the stones they have. They play a game to create the string. The … Read more

[Solution] Careless Chef solution codechef

Careless Chef solution codechef – Chef has a sequence of integers AA of length NN. He creates another sequence BB of length 2⋅N2⋅N using sequence AA. Initially, BB is empty. Chef performs the following process. For each element AiAi (1≤i≤N)(1≤i≤N) of AA: Choose any arbitrary integer kk (Note that the value of kk can be different for different elements). Add Ai−kAi−k and Ai+kAi+k to BB. Chef then shuffles the sequence BB randomly after this process. Since Chef is careless, … Read more

[Solution] Control the Pollution solution codechef

Control the Pollution solution codechef – There are two types of vehicles in Chefland. Bus which has a capacity of 100100 people. Car which has a capacity of 44 people. There are NN people who want to travel from place AA to place BB. You know that a single bus emits XX units of smoke while a single car emits YY units of smoke in their journey from AA to BB. You want … Read more

[Solution] Hostel Room solution codechef

Hostel Room solution codechef – There are initially XX people in a room. You are given an array AA of length NN which describes the following events: If Ai≥0Ai≥0, then AiAi people enter the room at ii-th minute. For e.g. if A2=3A2=3, then 33 people enter the room at the 22-nd minute. If Ai<0Ai<0, then |Ai||Ai| people leave the room at ii-th minute. Here |Ai||Ai| denotes the absolute value of AiAi. For e.g. if A4=−2A4=−2, then 22 people … Read more

[Solution] Count the Notebooks solution codechef

Count the Notebooks solution codechef – You know that 11 kg of pulp can be used to make 10001000 pages and 11 notebook consists of 100100 pages. Suppose a notebook factory receives NN kg of pulp, how many notebooks can be made from that? Count the Notebooks solution codechef First line will contain TT, the number of test cases. Then the test cases follow. Each … Read more