BinarySearch

Binary Search DSA.

Find the Smallest Divisor Given a Threshold

[Question] Given an array of integers nums and an integer threshold, we will choose a positive integer divisor, divide all the array by it, and sum the division’s result. Find the smallest divisor such that the result mentioned above is less than or equal to threshold. Each result of the division is rounded to the nearest integer greater than or equal to that […]

Find the Smallest Divisor Given a Threshold Read More »

Minimum Number of Days to Make m Bouquets

[Question] In an integer array bloomDay, an integer m and an integer k.You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the ith flower will bloom in the bloomDay[i] and then can be used in exactly one bouquet. Return the minimum number of days you need to wait to be able to make m bouquets from the garden.

Minimum Number of Days to Make m Bouquets Read More »

Koko eating Banana || Return min value using Binary search

[Question]: There are n piles of bananas, the ith pile has piles[i] bananas. The guards have gone and will come back in h hours.Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas

Koko eating Banana || Return min value using Binary search Read More »

Find out how many times the array has been rotated || Find Lowest Element Index

[Question] Given an integer array arr of size N, sorted in ascending order (with distinct values). Now the array is rotated between 1 to N times which is unknown. Find how many times the array has been rotated.  Example 1: Input Format: arr = [4,5,6,7,0,1,2,3] Result: 4 Explanation: The original array should be [0,1,2,3,4,5,6,7]. So, we can notice

Find out how many times the array has been rotated || Find Lowest Element Index Read More »

Find Minimum in Rotated Sorted Array

[Question]: Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: [4,5,6,7,0,1,2] if it was rotated 4 times. [0,1,2,4,5,6,7] if it was rotated 7 times. Notice that rotating an array [a[0], a[1], a[2], …, a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], …, a[n-2]].Given the sorted rotated array nums of unique elements, return the minimum element of this array.You must write an

Find Minimum in Rotated Sorted Array Read More »