Cutting Metal Surplus

Problem Overview

  • Maximize profit by choosing an integer saleLength and cutting rods so sellable pieces match that length; profit = totalUniformRodssaleLengthsalePrice − totalCuts*costPerCut.
  • Inputs: costPerCut, salePrice, lengths[n]; output: integer maximum profit; discard pieces not equal to saleLength.
  • Constraints: 1<=n<=50, 1<=lengths[i]<=10^4, 1<=salePrice,costPerCut<=100.
  • Real-world: Construction company selling surplus rods with cutting costs.
  • Asked in Goldman interviews; a coding interview interview question and practice problem.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: