Skip to content

arjunsingh64/CP-BY-JAVABOY

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

CP DAILY DOSE 😈

Coding also like a muscle that needs a regular workout in order to keep it strong and fit 😎💛


Day - 1 📘

Q1 MINIMUM SWAP TO SORT ARRAY : 📌📌

In this problem we need to find minimum number of swaps required to sort the array.If the array is already sorted, return 0.

👉 Problem Link

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.

Q2 MAXIMUM OF ALL CONTIGOUS SUBARRAYS OF SIZE K : 📌📌

-In this problem array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K

👉 Problem Link

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

It all started with Day-1 🔥🔥

CODE TO GROW🏆