CP DAILY DOSE 😈
In this problem we need to find minimum number of swaps required to sort the array.If the array is already sorted, return 0.
My Approach
-
First Create the duplicate array and use Arrays.sort() to sort it
-
Now compare all elements of old array with dupli array
-
Create the function named search to find the actual index position by using Arrays.binarySearch(dupArr,target) it will return the actual index position
-
Create another function named swap and swapped the element to its actual index call this function from inside if condition
-
Atlast increase the counter and your work is done.
-In this problem array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K
My Approach
-
Use Arrays.copyOfRange(OriginalArray,Start index,last index) function to copy the elemt to subArray
-
Find the largest element in the subarray by using max function
CODE TO GROW🏆