Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Arrays but also build up problem-solving skills.
Given an array arr[], where each element is at most k away from its target position, you need to sort the array optimally.
Note:
Examples:
Input: arr[] = [6, 5, 3, 2, 8, 10, 9], k = 3 Output: [2, 3, 5, 6, 8, 9, 10] Explanation: The sorted array will be 2 3 5 6 8 9 10
Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/nearly-sorted-1587115620/1