Make Lexicographically Smallest Array by Swapping Elements Solution Leetcode

Make Lexicographically Smallest Array by Swapping Elements Solution Leetcode You are given a 0-indexed array of positive integers nums and a positive integer limit. In one operation, you can choose any two indices i and j and swap nums[i] and nums[j] if |nums[i] – nums[j]| <= limit. Return the lexicographically smallest array that can be obtained by performing the operation any number of times. An array a is lexicographically smaller than an array b if in the first position where a and b differ, … Read more

Line Trip Solution Codeforces

Line Trip Solution Codeforces Problem In 19711971, Chef and his wife created a beautiful array �A of �N integers: �1,�2,…,��A1​,A2​,…,AN​. The difference between any two adjacent elements of the array was at most �D. When he read about Prefix Max and Prefix Min in 20002000, Chef made two more arrays �B and �C of �N integers where, for �i ranging from 11 to �N, ��=���(�1,…..��)Bi​=max(A1​,…..Ai​) ��=���(�1,…..��)Ci​=min(A1​,…..Ai​) Now it is 2023. Unfortunately, Chef has lost the original array �A. But … Read more

Chip and Ribbon Solution Codeforces

Chip and Ribbon Solution Codeforces Problem You have two arrays �=�1,�2,…,��A=A1​,A2​,…,AN​ and �=�1,�2,…,��B=B1​,B2​,…,BN​. Each of these elements also has a color associated with them, which is an integer. This is denoted by the arrays ������1,������2,…,�������ColorA1​,ColorA2​,…,ColorAN​, and ������1,������2,…,�������ColorB1​,ColorB2​,…,ColorBN​. In a single operation, you can swap any element of array �A with any element of array �B, if they have the same color. Your goal … Read more

Add, Divide and Floor Solution Codeforces

Add, Divide and Floor Solution Codeforces Problem Consider an array �A of size �N: �1,�2,…,��A1​,A2​,…,AN​, where �N is even. The ��������AlterEgo of this array �A, is another array �B, which is computed as follows: Start with an empty array �B. For �i ranging from 11 to �22N​, insert the elements (��+��+�2)(Ai​+Ai+2N​​) and ∣��−��+�2∣∣Ai​−Ai+2N​​∣ to the end of array �B. Here ∣�∣∣x∣ refers to absolute value of �x. Rearrange the array �B in some random order. As you can see, because of … Read more

yet Another Monster Fight Solution Codeforces

yet Another Monster Fight Solution Codeforces Problem You have �N integers – �1,�2,…,��A1​,A2​,…,AN​. You have to make the Bitwise XOR of all the elements as minimum as possible. You are allowed to remove at most one element. Note that this means that you can also choose to not remove any element. What is the final minimum XOR that you can … Read more

Best of N Sets Solution Codechef

Best of N Sets Solution Codechef Problem Sonu and Titu are playing a tennis match. They are playing a “best of �N sets” match (�N is always odd). That means that they will play at most �N sets, and the person who has won most sets wins the match. But they are smart, and if they notice at any point … Read more

Worth of a Video Solution Codechef

Worth of a Video Solution Codechef Problem We know that “A picture is worth a thousand words“. So let’s calculate the worth of a video using this! Suppose a video has 24 frames (or pictures) per second, and has a duration of �S seconds. We know that each frame is worth 10001000 words. So, how many words is this … Read more

Cricket World Cup Qualifier Solution Codechef

Cricket World Cup Qualifier Solution Codechef Problem The cricket World Cup has started in Chefland. There are many teams participating in the group stage matches. Any team that scores 1212 or more points in the group stage matches qualifies for the next stage. You know the score that a particular team has scored in the group stage … Read more

Freedom of Choice Solution Codeforces

Freedom of Choice Solution Codeforces time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Let’s define the anti-beauty of a multiset {b1,b2,…,blen}{�1,�2,…,����} as the number of occurrences of the number len��� in the multiset. You are given m� multisets, where the i�-th multiset contains ni�� distinct elements, specifically: ci,1��,1 copies of the number ai,1��,1, ci,2��,2 copies of the number ai,2,…,ci,ni��,2,…,��,�� copies of … Read more

Secret Sport Solution Codeforces

Secret Sport Solution Codeforces time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Let’s consider a game in which two players, A and B, participate. This game is characterized by two positive integers, X� and Y�. The game consists of sets, and each set consists of plays. In each play, exactly one of the players, either … Read more