Solve Five OA Coding Tasks
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
You are given five independent coding tasks. Implement all of the following functions.
1. **Add drama to text**
- Input: a string `s`.
- A **group** is a maximal contiguous sequence of non-whitespace characters.
- Return a new string where every period `'.'` is replaced with an exclamation mark `'!'`, and one additional exclamation mark is appended after each group.
- Preserve the original whitespace between groups.
- Example: `"hi. there"` becomes `"hi!! there!"`.
2. **Filter and reverse even numbers**
- Input: a list of integers `nums`.
- Remove all odd numbers.
- Return the remaining even numbers in reverse order relative to their original order.
- Example: `[1, 2, 3, 4, 6, 5]` returns `[6, 4, 2]`.
3. **Compute a bounding rectangle**
- Input: a non-empty list of coordinates, where each coordinate is a two-element list `[x, y]`.
- Return a four-element list `[minX, minY, width, height]`, where:
- `minX` is the minimum x-coordinate,
- `minY` is the minimum y-coordinate,
- `width = maxX - minX`,
- `height = maxY - minY`.
4. **Find incorrect digit positions in a sum**
- Input: three non-negative integers `num1`, `num2`, and `statedSum`.
- Compute the correct value `num1 + num2`.
- Compare `statedSum` against the correct sum digit by digit from right to left.
- Return the zero-based digit indexes where the digits differ. The ones digit has index `0`, the tens digit has index `1`, and so on.
- If the numbers have different lengths, treat missing higher-order digits as `0` while comparing until all digits of both numbers have been consumed.
- Example: if `num1 = 99`, `num2 = 1`, and `statedSum = 190`, the correct sum is `100`, so the result is `[1]` because only the tens digit differs.
5. **Extract disallowed URLs for bot user agents**
- Input: `lines`, a list of strings representing the contents of a text file, one line per string.
- The file is similar to a robots file and contains sections. A new section begins when a line starts with the exact prefix `"User-agent:"`.
- A section is relevant if its user-agent value, after trimming surrounding spaces, either:
- is exactly `"*"`, or
- ends with the exact suffix `"Bot"`.
- Within every relevant section, collect the URL value after each line that starts with the exact prefix `"Disallow:"`.
- Stop considering a section when the next `"User-agent:"` line begins or the file ends.
- Return all collected URLs with duplicates removed. Matching is case-sensitive, so `"/A"` and `"/a"` are different URLs. Preserve the order of first occurrence.
Quick Answer: This question evaluates programming fundamentals including string manipulation, sequence and list processing, basic computational geometry, digit-wise arithmetic comparison, and structured text parsing across five small independent tasks.