Solve Four Coding Assessment Tasks
Company: Capital One
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Complete the following four independent coding tasks.
### 1. Find the day a cumulative visit target is reached
You are given an array `visits`, where `visits[i]` is the number of website visits on day `i`, and an integer `target`.
Return the smallest 0-based day index `i` such that the total number of visits from day `0` through day `i` is at least `target`. If the target is never reached, return `-1`.
### 2. Simulate a repeated subtraction algorithm
You are given an array `nums` of non-negative integers. Simulate the following process and return the final value of `res`.
Initialize `res = 0`.
Repeat:
1. Scan `nums` from left to right and find the first positive value. Call this value `x`. If no positive value exists, stop and return `res`.
2. Starting at that index, scan to the right. For each element:
- If the element is less than `x`, stop this scan and go to step 3.
- Otherwise, subtract `x` from the element and continue scanning right.
3. Add `x` to `res`.
4. Repeat from step 1.
Implement this algorithm exactly.
### 3. Place blocks on a grid
You are given an `m x n` empty grid and a list `order` containing block identifiers from the set `{A, B, C, D, E}`. Each identifier corresponds to a fixed block shape represented by a set of relative cell coordinates, such as `[(0, 0), (0, 1)]`. The shape definitions are provided as part of the input or as constants.
Process the blocks in the given order. For each incoming block, place it on the grid without rotating it and without overlapping previously placed blocks. A placement is valid if every occupied cell of the block lies inside the grid and is currently empty.
For each block, choose the valid placement with the smallest row index for its top-left anchor; if there is a tie, choose the smallest column index. The input is guaranteed to have at least one valid placement for every block.
Return the final grid after all blocks have been placed, marking each occupied cell with the block's identifier.
### 4. Minimize increments to make house heights beautiful
You are given an array `heights`, where `heights[i]` is the height of the `i`-th house in a street. In one operation, you may increase the height of any single house by `1`.
A street is considered beautiful if its heights form one of the following patterns:
- Strictly increasing by exactly `1` from left to right: `k, k+1, k+2, ...`
- Strictly decreasing by exactly `1` from left to right: `k, k-1, k-2, ...`
You may only increase heights, never decrease them. Return the minimum number of operations needed to make the street beautiful under either pattern.
Quick Answer: This multi-part coding question evaluates array manipulation, algorithm simulation, deterministic spatial placement, and constrained optimization competencies across tasks involving cumulative thresholds, iterative subtraction sequences, fixed-shape grid placement, and minimal-increment adjustments for monotonic patterns.