Skip to main content
Back to problems
#1276
Medium Algorithms

Number of burgers with no waste of ingredients

Math
50.9% acceptance
Feb 25, 2026
343
239
Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows: Jumbo Burger: 4 tomato slices and 1 cheese slice. Small Burger: 2 Tomato slices and 1 cheese slice. Return [total_jumbo, total_small] so that the number of remaining tomatoSlices equal to 0 and the number of remaining cheeseSlices equal to 0. If it is not possible to make the remaining tomatoSlices and cheeseSlices equal to 0 return [].

Solution

Rust
Time O(1)
Space O(n)
LeetCode
solution.rs
impl Solution {
  pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> Vec<i32> {
    let t = tomato_slices;
    let c = cheese_slices;
    // 4j + 2s = t, j + s = c => 2j = t - 2c => j = (t - 2c) / 2
    let numerator = t - 2 * c;
    if numerator < 0 || numerator % 2 != 0 { return vec![]; }
    let j = numerator / 2;
    let s = c - j;
    if s < 0 { return vec![]; }
    vec![j, s]
  }
}