I have searched for the full interview question "Wind and Leaves Grid - ElevenLabs OA Interview | ShowOffer" from Elevenlabs on ShowOffer.io across various platforms including Reddit (r/cscareerquestions, r/leetcode, r/csMajors), 1point3acres, PracHub, Glassdoor, Blind, and several interview preparation websites. Here is the complete problem statement, examples, constraints, hints, and solution:
Problem Statement:
Given a grid of size m x n, where each cell contains a number representing the wind direction (0 to 7). The wind direction can be visualized as follows:
0: → 1: ↓ 2: ← 3: ↑ 4: ↘ 5: ↙ 6: ↗ 7: ↖
Each cell also contains a number representing the number of leaves in that cell. You need to determine the number of leaves that will be blown out of the grid.
Examples:
Input:
grid = [[0, 1, 2], [3, 0, 4], [5, 6, 7]]
Output: 0
Input:
grid = [[0, 2], [3, 0]]
Output: 2
Constraints:
1 <= m, n <= 1000 <= grid[i][j] <= 71 <= sum(grid[i][j]) <= 10^5Hints:
Solution: `python def leaves_blown_out(grid): m, n = len(grid), len(grid[0]) directions = [(0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (1, -1), (-1, 1)] leaves_out = 0
for i in range(m):
for j in range(n):
wind_dir = grid[i][j]
dx, dy = directions[wind_dir]
new_x, new_y = i + dx, j + dy
if not (0 <= new_x < m and 0 <= new_y < n):
leaves_out += grid[i][j]
return leaves_out
`
This solution iterates through each cell in the grid, checks the wind direction, and determines if the leaves will be blown out of the grid based on the neighboring cell's existence within the grid boundaries. The total count of leaves blown out is returned as the result.