Data Structures & AlgorithmsHardProduct Company SDE · Amazon/Microsoft-style OA
Problem: Shops sit on a circular ring with profits p = [5, -3, 5, 4, -8, 6]. Choose a contiguous arc of at least one shop (the arc may wrap from the last shop back to the first) to maximise total profit. What is the maximum?
- A. 17
- B. 11
- C. 14
- D. 9
Correct answer: A. 17
The answer is max(best linear subarray, total - minimum subarray). The best linear run is 11, but total 9 minus the minimum subarray -8 gives 17, achieved by the wrapped arc 6, 5, -3, 5, 4.
More Coding Interview Problems questions
- Problem: Nine nodes 0..8 start disconnected. Apply these unions in order (a union of two nodes already in one set does nothing)…
- Problem: How many prime numbers are there that are less than or equal to 10^6?
- Problem: Let phi(k) be Euler's totient (the count of integers g in [1, k] with gcd(g, k) = 1). What is phi(1) + phi(2) + ... + phi(10)?
- Problem: Count the integers x with 1 <= x <= 1000 whose decimal digits sum to exactly 10.
- Problem: Modulo the prime p = 998244353, which value is the multiplicative inverse of 2, i.e. the x in [0, p) with 2x ≡ 1 (mod p)?
- Problem: A product of 11 matrices A1 A2 ... A11 is evaluated by choosing a full parenthesisation. How many different parenthesisations are…