ORIGINAL CODING QUESTION
Career fair booths without neighbours
A career fair has n booths in a row, each with a non-negative sponsorship value. Volunteers may staff any booths except two that stand next to each other. Return the largest total value of a valid selection; selecting no booth gives 0.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n booth values.
Constraints
1 ≤ n ≤ 12; 0 ≤ value ≤ 100.
Example 1
Input
5 2 7 9 3 1
Output
12
Booths with values 2, 9 and 1 give 12.
Example 2
Input
2 4 4
Output
4
The two booths are neighbours, so only one is staffed.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
For each booth decide to staff it or skip it.
Hint 2
Staffing booth i means booth i-1 must be skipped.
Hint 3
Track the best total when the previous booth is taken and when it is skipped.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →