This pair of problems evaluates block-wise grid processing and aggregation for minimum-value selection alongside dependency-resolution and resource-allocation reasoning for recipe inventory planning, testing competencies in array manipulation, tie-breaking and constraint handling, graph-based dependency management and cycle detection, and algorithmic complexity analysis; they are commonly asked to gauge an applicant's ability to implement correct, efficient solutions under input-size and edge-case constraints. They belong to the Coding & Algorithms domain with subdomains in data structures (arrays/grids), algorithm design and analysis, and graph theory, and primarily require practical application of algorithmic techniques with attention to time/space complexity rather than purely theoretical proofs.
You are given an m × n 2D integer array grid.
(r, c)
where
r
and
c
are multiples of 3.
m
or
n
is not a multiple of 3).
Task: Return the block whose representative value is the smallest among all blocks. Specify what you return, e.g.:
(r, c)
of the corresponding 3×3 block (tie-breaking rule required).
Follow-up: A block is invalid if any cell equals 1. Ignore invalid blocks when selecting the minimum. If all blocks are invalid, return a sentinel value (e.g. null / (-1, -1, -1)).
Also discuss: time and space complexity.
1 ≤ m, n ≤ 2000
grid[i][j]
fits in 32-bit signed integer
You are given:
product -> [(ingredient1, qty1), (ingredient2, qty2), ...]
.
product
consumes the listed quantities.
item -> available_quantity
for raw materials (and possibly some pre-made products).
(target_item, target_quantity)
.
Task: Determine whether it is possible to produce target_quantity units of target_item using the inventory and recipes.
cake
needs
sugar
, and
sugar
needs
cane
).
cake -> (sugar, 2), (flour, 3), (egg, 1)
sugar -> (cane, 5)
cane=100, flour=10, egg=3
2
cakes?