November 15, 2024 |3.5K Views

PROBLEM OF THE DAY : 14/11/2024 | Nearly Sorted

Description
Discussion

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: 
 

  1. The given Array can be Circular.
  2. You need to change the given array arr[] in place.

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