FastPrepPlan Cuts 🐑

Plan Cuts 🐑

Salesforce logoSalesforce● MediumOA
Learn

Problem statement

An automated cutting machine is used to cut rods into segments. The cutting machine can only hold a rod of minLength or more. A rod is marked with the necessary cuts and their lengths are given as an array in the order they are marked. Determine if it is possible to plan the cuts so the last cut is from a rod at least minLength units long.

Function

planCuts(rodLengths: int[], minLength: int) β†’ String

Examples

Example 1

rodLengths = [3, 5, 4, 3]minLength = 9return = "Possible"

N/A for now πŸ‘‰πŸ™‰πŸ‘ˆ

Example 2

rodLengths = [4, 3, 2]minLength = 7return = "Possible"

N/A for now

Example 3

rodLengths = [4, 2, 3]minLength = 7return = "Impossible"

N/A for now

Example 4

rodLengths = [5, 6, 2]minLength = 12return = "Impossible"

N/A for now

Constraints

  • Unknown for now πŸ₯²

More Salesforce problems

See Salesforce hiring insights
public String planCuts(int[] rodLengths, int minLength) {
    // write your code here
}
rodLengths[3, 5, 4, 3]
minLength9
expected"Possible"
Checking account…