• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
April 17, 2024 |900 Views
PROBLEM OF THE DAY : 16/04/2024 | Minimize the Difference
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Nitin Kaplas. 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.

In this problem, we are given, an array arr of size n. You have to remove a subarray of size k , such that the difference between the maximum and minimum values of the remaining array is minimized.
Find the minimum value obtained after performing the operation of the removal of the subarray and return it.

Example :

Input:
n = 5
k = 3
arr = {1, 2, 3, 4, 5}
Output: 
1
Explanation: 
We can remove first subarray of length 3(i.e. {1, 2, 3}) then remaining array will be {4,5} and the difference of maximum and minimum element will be 1 i.e 5 - 4 = 1

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/minimize-the-difference/1

Read More