Tip 1 : Be Strong with DSA
Tip 2 : Be Strong with OOPS and Core CS Fundamentals
Tip 1 : One Page Resume
Tip 2 : Highlight your coding profiles
Online Assessment



For the given input array [4, 3, 2, 1], the minimum no. of swaps required to sort the array is 2, i.e. swap index 0 with 3 and 1 with 2 to form the sorted array [1, 2, 3, 4].
Same as before, make a new array (called temp), which is the sorted form of the input array. We know that we need to transform the input array to the new array (temp) in the minimum number of swaps. Make a map that stores the elements and their corresponding index, of the input array.
So at each i starting from 0 to N in the given array, where N is the size of the array:
1. If i is not in its correct position according to the sorted array, then
2. We will fill this position with the correct element from the hashmap we built earlier. We know the correct element which should come here is temp[i], so we look up the index of this element from the hashmap.
3. After swapping the required elements, we update the content of the hashmap accordingly, as temp[i] to the ith position, and arr[i] to where temp[i] was earlier.
SOLVED PARTIALLY



If ‘ARR’ is {1,2,3,4} and ‘K’ = 1, then after modification, ‘ARR’ should be {2,4,1,3} because ‘K-th’ (‘K’ = 1) of {2,4} is 0 and ‘K-th’ bit of {1,3} is 1.
Problem Solving



If ‘N’ = 6
[1, 3, 6, 5]
Then the output will be 2 4.
The idea is based on this popular solution for finding one missing number. We extend the solution so that two missing elements are printed.
Let’s find out the sum of 2 missing numbers:
arrSum => Sum of all elements in the array
sum (Sum of 2 missing numbers) = (Sum of integers from 1 to n) - arrSum
= ((n)*(n+1))/2 – arrSum
avg (Average of 2 missing numbers) = sum / 2;
One of the numbers will be less than or equal to avg while the other one will be strictly greater than avg. Two numbers can never be equal since all the given numbers are distinct.
We can find the first missing number as a sum of natural numbers from 1 to avg, i.e., avg*(avg+1)/2 minus the sum of array elements smaller than avg
We can find the second missing number by subtracting the first missing number from the sum of missing numbers

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?