My first instinct was to sort, which would've blown the O(n) requirement.
First, clarify the problem constraints and edge cases (e.g., empty array, discount range). Then, in a single pass, find the index of the maximum price (first occurrence) and compute the total sum. Finally, subtract the discount amount from the total and return the floor.
Pro tip: Mention that you can avoid floating-point errors by computing the discounted total as total - (max_price * discount / 100) using integer arithmetic where possible, and only apply floor at the end.
Confirm the discount is a percentage (0-100), the array may be empty, and ties go to the first occurrence. Discuss handling of negative or zero prices if not specified.
Iterate through the array to find the maximum price and its first index. Track the index to handle ties correctly.
While iterating, also accumulate the sum of all prices. This can be done in the same pass as finding the maximum.
Calculate the discount amount as (max_price * discount) / 100. Subtract this from the total sum, then take the floor of the result.
Walk through a few test cases, including ties, empty array, and 0% or 100% discount, to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.