bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1891. Cutting Ribbons

1891. Cutting Ribbons

Leetcode Solutions

Binary Search for Maximum Ribbon Length

  1. Initialize the lower bound l to 1 and the upper bound r to the maximum value in ribbons array.
  2. While l is less than or equal to r: a. Calculate the mid-point m as (l + r) / 2. b. Calculate the total number of ribbons total that can be obtained by dividing each ribbon's length by m. c. If total is less than k, set r to m - 1. d. Otherwise, set l to m + 1.
  3. After the loop, return r as the maximum length of the ribbons.
UML Thumbnail

Greedy Approach with Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...