> For the complete documentation index, see [llms.txt](https://longxingtan.gitbook.io/mle-interview/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://longxingtan.gitbook.io/mle-interview/01_leetcode/00_binary_search/1891.-cutting-ribbons.md).

# \*1891. Cutting Ribbons

<https://leetcode.com/problems/cutting-ribbons/>

## solution

```python
class Solution:
    def maxLength(self, ribbons: List[int], k: int) -> int:
        left = 0
        right = max(ribbons)

        while left < right:
            mid = (left + right + 1) // 2
            count = sum(ribbon // mid for ribbon in ribbons)
            if count >= k:
                left = mid
            else:
                right = mid - 1

        return left
```

时间复杂度：O()\
空间复杂度：O()
