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πŸ†

About

Practice Questions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages