LintCode 183. Wood Cut
183.Wood Cut
Given n pieces of wood with lengthL[i]
(integer array). Cut them into small pieces to guarantee you could have equal or more than k pieces with the same length. What is the longest length you can get from the n pieces of wood? Given L & k, return the maximum length of the small pieces.
Example
ForL=[232, 124, 456]
,k=7
, return114
.
Challenge
O(n log Len), where Len is the longest length of the wood.
Notice
You couldn't cut wood into float length.
If you couldn't get >=_k _pieces, return0
.
Thoughts:
Binary Search on the length by testing the resulted cutting pieces
Code: T: Nlog(max(L[i])), S: O(1)
Last updated
Was this helpful?