BackmediumTime and Space Complexity time-and-space-complexity medium

Ratio Consistent Crates Solution

Problem Statement

Given two integers `vials` and `flasks`, and a 2D array `crates` where each sub-array contains two integers `v` and `f` representing the capacity of a crate for vials and flasks, determine the minimum number of crates required such that the ratio of vials to flasks in each crate is consistent with the overall ratio of vials to flasks.

Example 1
Input
10 15 [[2 3] [4 6] [1 2]]
Output
5

Explanation: The overall ratio of vials to flasks is 2:3. To achieve this ratio, we can use 5 crates with capacities [2 3].

Constraints

  • 1 <= vials <= 10^6
  • 1 <= flasks <= 10^6
  • 1 <= crates.length <= 10^3
  • 1 <= crates[i][0] <= 10^6
  • 1 <= crates[i][1] <= 10^6

More Time and Space Complexity Problems

View all problems →
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free