Skip to main content

Posts

Codechef January long challenge solution|| Codechef January long challenge editorial 2021

  Codechef January  long challenge solution- Hey guys Welcome Again, A small update CodeChef January  long challenge starting from 1st January   2021 to 14 th January  2021. Codechef long challenge is one of the popular contests of CodeChef you should participate in codechef January   long challenge.This is first contest of codechef in 2021 so good luck. And wish you happy new year. Contest link- https://www.codechef.com/JAN21?itm_campaign=contest_listing I will post the solution after 11 Jan.Stay tuned. About CodeChef  January 2021 Long Challenge: CodeChef Long Challenge is a 10-day monthly coding contest where you can show off your computer programming skills. The significance being - it gives you enough time to think about a problem, try different ways of attacking the problem, read the concepts etc. If you’re usually slow at solving problems and have ample time at hand, this is ideal for you. We also put in a lot of efforts in getting quality problems, which would, in turn, foster

Merge Two sorted array Without Extra Space

Problem statement-  Given two sorted arrays arr1[] and arr2[] of sizes N and M in non-decreasing order. Merge them in sorted order without using any extra space. Modify arr1 so that it contains the first N elements and modify arr2 so that it contains the last M elements.    Example 1: Input:  N = 4, arr1[] = [1 3 5 7]  M = 5, arr2[] = [0 2 6 8 9] Output:  arr1[] = [0 1 2 3] arr2[] = [5 6 7 8 9] Explanation: After merging the two  non-decreasing arrays, we get,  0 1 2 3 5 6 7 8 9.   Example 2: Input:  N = 2, arr1[] = [10, 12]  M = 3, arr2[] = [5 18 20] Output:  arr1[] = [5 10] arr2[] = [12 18 20] Explanation: After merging two sorted arrays  we get 5 10 12 18 20. Your Task: You don't need to read input or print anything. You only need to complete the function merge() that takes arr1, arr2, N and M as input parameters and modifies them in-place so that they look like the sorted merged array when concatenated. Expected Time Complexity:  O((n+m) log(n+m)) Expected Auxilliary Space: O(1

Hail XOR December codechef challenge problem solution 2020

 Hail XOR  December codechef challenge problem solution 2020- Hail XOR problem is taken from December codechef challenge 2020. Let's read problem statement. You are given a sequence  A 1 , A 2 , … , A N A 1 , A 2 , … , A N  and you have to perform the following operation exactly  X X  times: Choose two integers  i i  and  j j  such that  1 ≤ i < j ≤ N 1 ≤ i < j ≤ N . Choose a non-negative integer  p p . Change  A i A i  to  A i ⊕ 2 p A i ⊕ 2 p , and change  A j A j  to  A j ⊕ 2 p A j ⊕ 2 p , where  ⊕ ⊕  denotes  bitwise XOR . Find the lexicographically smallest sequence which can be obtained by performing this operation exactly  X X  times. A sequence  B 1 , B 2 , … , B N B 1 , B 2 , … , B N  is said to be lexicographically smaller than a sequence  C 1 , C 2 , … , C N C 1 , C 2 , … , C N  if there is an index  i i  such that  B i < C i B i < C i  and for each valid  j < i j < i ,  B j = C j B j = C j . Input The first line of the input contains a single intege