BS-14. Find the Smallest Divisor Given a Threshold | Binary Search

preview_player
Показать описание


We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.

You can follow me across social media, all my handles are below:

0:00 Introduction of Course
Рекомендации по теме
Комментарии
Автор

This problem is literally the same as koko eating bananas problem, yet you took the time to explain it separately. Kudos for the hardwork <3

promamondal
Автор

1 min 50 seconds into the video and I know how to solve this question. lol. What a guy!! people like you are true 💎. hats off.

udaykulkarni
Автор

Here's an easy way to find the ceil while doing division: return (x+y-1)/y;

If we want to avoid overflow with x+y then simply doing 1+(x-1)/y will work too

AdityaKumar-behx
Автор

i coded it by myself...understanding the previous videos you thinking capacity is increasing

adityarajvermaa
Автор

Striver Explanation is so smooth and easy to understand ..❣

pizzagamingyt
Автор

When he says "You are going to miss out something really special" in start, he means it.

neerajkumar-tsom
Автор

solved in just one go without a single error with intuition from previous videos. Love you striver for such amazing content..

Satyendra_Prakash
Автор

just watched the prev question vid and solved this question by myself only thanks striver absolutely the best DSA course

ajayramola
Автор

Your explanation is really good, I actually regret wasting 3.5 months: March, April, May and June. Babbar has explained binary search in a very poor manner. I couldn't solve most questions. My friends told me to learn it from this channel but looking at the playlist length, I avoided it . Totally my fault, and here I am able to atleast think and come up with a solution. Now I understand why people say learn from Striver.

Josuke
Автор

Understood :), Thank so much, i always faced difficulty in when i should take high=mid-1 or high=mid . You teach all the ques with the same pattern. This helped me a lot

sakshinaruka
Автор

Solved this question by myself and couldn't be happier

AryanSingh-sndx
Автор

I never thought I could understand DSA. Thanks man.

LemesaElias
Автор


function smallestDivisor(arr, threshold) {
let left = 1,
right = (ans = Math.max(...arr));

while (left <= right) {
let mid = Math.floor(left + (right - left) / 2);

let sum = arr
.map((el) => Math.ceil(el / mid))
.reduce((acc, curr) => curr + acc, 0);

if (sum <= threshold) {
ans = Math.min(ans, mid);
right = mid - 1;
} else {
left = mid + 1;
}
}

return left;
}

let arr = [1, 2, 5, 9],
threshold = 7;

let res = smallestDivisor(arr, threshold);
console.log(res); // 3

maitohpughu
Автор

too good bro... after smashing dp playlist im here and with each video my confidence level on BS Q increasing rapidly🔥🔥

Harsh-ogxr
Автор

while dry running the problem he by chance made a mistake on dividing with 3, the sum will be greater than threshold, finally the ans will be 5. BTW great explanation striver, you nailed it

arnabbhattacharya
Автор

Just Following the BS playlist and from 12th video after knowing the question i was able to write Optimal Code Kudoos to Striver🙌

NetajiSaiSuru
Автор

This is literally same as Koko eating banana well explained brother

anshror
Автор

thank you for such an amazing work i solve this problem on my own just by listening only the first part of the problem statement discussion, ,, you are the best.

SayanChakraborty-mk
Автор

I saw comments before watching the video, people were able to solve so I got jealous and solved it on my own 😂 thank u striver <3 will watch video now to learn something extra.

saswatrath
Автор

Thanks to his previous videos on BS, I could do this on my own♥

debanjanghosal