Тёмный

Minimum Difference Between Largest and Smallest Value in Three Moves | 2 Approaches | Leetcode 1509 

codestorywithMIK
Подписаться 59 тыс.
Просмотров 7 тыс.
50% 1

Whatsapp Community Link : www.whatsapp.com/channel/0029...
This is the 95th Video of our Playlist "Arrays 1D/2D : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a good Array problem : Minimum Difference Between Largest and Smallest Value in Three Moves | 2 Approaches | Easy Explanations | Leetcode 1509 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Minimum Difference Between Largest and Smallest Value in Three Moves | 2 Approaches | Easy Explanations | Leetcode 1509 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/minimum...
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My Recursion Concepts Playlist : • Introduction | Recursi...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
Approach 1: Using Complete Sorting
Time Complexity: O(nlogn)
Space Complexity: O(1)
Description:
Sorting: The entire array nums is sorted.
Edge Case: If the array size is 4 or less, the minimum difference is 0 because we can remove all elements.
Calculate Minimum Difference: The minimum difference is calculated by considering four possible cases:
Removing the three largest elements.
Removing the three smallest elements.
Removing the two largest and one smallest element.
Removing the two smallest and one largest element.
Result: The minimum of these differences is returned as the result.
Approach 2: Using Partial Sorting
Time Complexity: O(n)
Space Complexity: O(1)
Description:
Edge Case: If the array size is 4 or less, the minimum difference is 0 because we can remove all elements.
Partial Sorting:
Use partial_sort to sort the first four elements to find the four smallest elements.
Use nth_element to position the n-4th largest element correctly, such that all elements before it are smaller and all elements after it are larger.
Sort the last four elements to ensure the four largest elements are in their correct positions.
Calculate Minimum Difference: Similar to Approach 1, calculate the minimum difference by considering the same four possible cases.
Result: The minimum of these differences is returned as the result.
✨ Timelines✨
00:00 - Introduction
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024

Опубликовано:

 

2 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 42   
@FifthArima
@FifthArima 27 дней назад
00:00 Intro & explanation 02:30 Approach 1 -Complete Sorting 19:30 Approach 2 -Partial Sorting
@RishabhChatterjee-fg2gz
@RishabhChatterjee-fg2gz 27 дней назад
Aap ka alawa aur koi bhi accha nehi hai, Jo beginners se samjata hai
@RishabhChatterjee-fg2gz
@RishabhChatterjee-fg2gz 27 дней назад
Aap ka hi Wait tha
@shashwatdixit5886
@shashwatdixit5886 27 дней назад
Your way of teaching is great. Thanks !
@ugcwithaddi
@ugcwithaddi 27 дней назад
Was waiting. Thank you
@gui-codes
@gui-codes 27 дней назад
yaar mast samjhate ho aap. ekdm maza hi ajata hai
@rev_krakken70
@rev_krakken70 27 дней назад
Thanks to your arrays playlist.. was able to solve it ❤
@venkatarohitpotnuru38
@venkatarohitpotnuru38 27 дней назад
bhaiyya aagaya..
@gocrazy6177
@gocrazy6177 27 дней назад
Voice increased wow thanks
@user-ub2is4rs4x
@user-ub2is4rs4x 27 дней назад
Thanks man. Finally understood.
@__Aakarsh-jo7ov
@__Aakarsh-jo7ov 27 дней назад
SUCH A BEGINNER FRIEDNLY AND EFFECTIVE WAY !!! KUDOS
@demonslayerx9751
@demonslayerx9751 27 дней назад
thank you bro , nice video !!
@wearevacationuncoverers
@wearevacationuncoverers 22 дня назад
king of best explanations.
@Yashwanth-zn4qj
@Yashwanth-zn4qj 27 дней назад
aap hi ka wait tha. subah se referesh kar raha tha
@vipinchaudhary3520
@vipinchaudhary3520 27 дней назад
I was very happy to find out that you are my college alumni from IIEST, Shibpur. Your videos help me a lot, and I have a great respect and love for you. ❤️
@sohiltr2310
@sohiltr2310 27 дней назад
thankyou sir
@Chandakshaythakur
@Chandakshaythakur 27 дней назад
Thank you bhaiya. Bhaiya as Segment tree playlist is going on bhaiya please solve some segment tree problems from Codechef also. Codechef contains good quality problems on segment tree.
@santhosh7042
@santhosh7042 27 дней назад
Bhaiya binary search vala approach bhi discuss karna please muje lag raha jaise Koko and bananas kiya same ye bhi karskate hai par Mera kuch test case pass nahi horahe
@molyoxide8358
@molyoxide8358 27 дней назад
last 3 years mein pehli baar partial sort bhi kuch hota hai krke pta laga.
@gauravbanerjee2898
@gauravbanerjee2898 27 дней назад
Thanks a lot bhaiya ❤❤ learnt something new today partial_sort and nth_element Congrats for 55k subs🥳🥳
@abhavgoel9390
@abhavgoel9390 27 дней назад
The hit and trial method came to my mind after i read the problem, but i kept on thinking that cant be the solution. I face this many times and try top get the optimzed solution from the beginning. How to deal with this?
@AMANYADAV-cd8tw
@AMANYADAV-cd8tw 27 дней назад
Bhaiya please launch your DSA Sheet for ultimate interview preparation. By the way Got rejected in DE Shaw OA today. 😢
@study-yd6es
@study-yd6es 27 дней назад
Learning ++
@himanshujain9933
@himanshujain9933 27 дней назад
Thanks for the video sorting takes also space o n right?
@rushikeshkadam7768
@rushikeshkadam7768 27 дней назад
Bhaiya can you please add pdf notes of graph concepts and questions to github.
@KeshavKumar-jl1ub
@KeshavKumar-jl1ub 27 дней назад
please make one video on leetcode 687 please see that question once...
@LeetcodeToday
@LeetcodeToday 27 дней назад
bhaiya priority queue wala solution bhi bata do
@someshnayakrollno.-09sec-b27
@someshnayakrollno.-09sec-b27 27 дней назад
i tried to solve the problem by making an approach by myself ,but the approach came out to be limited to some cases everytime . give me some suggestions to improve the problem solving skills!!
@aizad786iqbal
@aizad786iqbal 27 дней назад
hi what if the questions had said K instead of 3... how would we approach then ?
@aizad786iqbal
@aizad786iqbal 27 дней назад
res = Math.min(res, nums[n-1] - nums[3]); res = Math.min(res, nums[n-2] - nums[2]); res = Math.min(res, nums[n-3] - nums[1]); res = Math.min(res, nums[n-4] - nums[0]); loop laga kar karna hoga then.. I guess.. ek start se and ek end se...
@dayashankarlakhotia4943
@dayashankarlakhotia4943 27 дней назад
public int minDifference(int[]nums){ int n=nums.length; if(n
@HMBDM1976
@HMBDM1976 27 дней назад
class Solution { public: int minDifference(vector& nums) { sort(nums.begin(),nums.end()); int n=nums.size(); if(n>=4){ return min({nums[n-4]-nums[0],nums[n-1]-nums[3],nums[n-3]-nums[1],nums[n-2]-nums[2]}); } return 0; } };
@dikshantyadav1110
@dikshantyadav1110 27 дней назад
MIK bhaiya nhi sir ho gye hai @7.22 seconds,
@codestorywithMIK
@codestorywithMIK 27 дней назад
No no. “No sir” . Only bhaiya 😇🙏❤️ We all are on same level ❤️❤️❤️
@HMBDM1976
@HMBDM1976 27 дней назад
Sir could you please speak in english .I am a south indian.You are really doing a great job .Your explaination and step by step approach is top notch.But south indian students cant understand hindi very well.Please do your videos in english so that everyone can understand sir. Its a sincere request from my side 🥹🥹
@sakshamshrivastava3482
@sakshamshrivastava3482 27 дней назад
kuch samajh nhi aaya bhai
@codestorywithMIK
@codestorywithMIK 27 дней назад
Hello there, Apologies if you felt so. Would you like to point which point exactly you felt lost. I will try my best to help here
@literally_ankur
@literally_ankur 25 дней назад
Second approach was bit unnecessary.
@codestorywithMIK
@codestorywithMIK 25 дней назад
Yep I agree. Just felt like sharing 😇 I will try to avoid adding similar approaches in a video. Thank you for the feedback ❤️🙏😇
@manasdeora4601
@manasdeora4601 27 дней назад
Kuch smjh me nhi aaya aaj toh!
@codestorywithMIK
@codestorywithMIK 27 дней назад
Hi there, Would you point where exactly you felt stuck. I will try my best to help here ❤️
Далее
Ouch.. 🤕
00:30
Просмотров 6 млн
кукинг с Даниилом 🥸
01:00
Просмотров 491 тыс.
How I would learn Leetcode if I could start over
18:03
Просмотров 382 тыс.