Interview Questions/Coding/Corridor Width Audit

Corridor Width Audit

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Corridor Width Audit

A corridor planner records each participant's height and a fixed clearance h. A participant with height at most h occupies one unit of corridor width. A participant taller than h must turn sideways and occupies two units. Compute the total corridor width needed for each group. Input Format: The first line contains t, the number of test cases. Each test case contains n and h, followed by n heights. Output Format: For each test case, print the total required width.

Examples

Example 1
Input:
1
3 7
4 5 14
Output:
4

Explanation: The first two participants use one unit each, while height 14 uses two units, for a total width of 4.

Approach hint

Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp