MCPcopy Create free account
hub / github.com/ByteByteGoHq/coding-interview-patterns / cutsEnoughWood

Function cutsEnoughWood

cpp/Binary Search/cutting_wood.cpp:22–30  ·  view source on GitHub ↗

Determine if the current value of 'H' cuts at least 'k' meters of wood.

Source from the content-addressed store, hash-verified

20// Determine if the current value of 'H' cuts at least 'k' meters of
21// wood.
22bool cutsEnoughWood(int H, int k, std::vector<int>& heights) {
23 int woodCollected = 0;
24 for (int height : heights) {
25 if (height > H) {
26 woodCollected += (height - H);
27 }
28 }
29 return woodCollected >= k;
30}

Callers 2

cuttingWoodFunction · 0.70
CuttingWoodMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected