[C++] O(1) Faster than 100% : Intuitive Solution : Solve linear equations (explained in detail)
Intuition and Maths Involved\nYou see, they ask us to use up all ingredients without wastage , if you just look a little carefully you will realize its more lik
# **Intuition and Maths Involved**\nYou see, they ask us to use up all ingredients without wastage , if you just look a little carefully you will realize its more like a class 9th problem of **Pair Of Linear Equations in Two variables**, where all you need is to simply check if the 2 equations have "whole number " solutions .. \n\n\nLet me explain :-\nLet\'s say we can create **x** jumbo burgers and **y** small ones ..\n**Total cheeseslices Used  = x + y**  (all burgers use one cheeseslice so x + y burgers neeed x+ y slices , right?)\ntomatoslices used in x Jumbo burgers = 4x (4 in each burger, means total 4x will be needed)\nTomatoslices used in y small burgers = 2y (2 in each burger, means total 2x will be needed)\n**Total tomatoeslices Used  = 4x + 2y**\n\nSo we are basically left with 2 equations at hand : -\n**4x + 2y = tomatoslices       ----------(i)\n\tx + y = cheeseslices       ----------(ii)**\n\nIf we try to solve them we get x and y as \n**x = (tomatoSlices - 2*cheeseSlices) / 2\ny = cheeseSlices - x**\nNow, all we need is to check if x and y we are getting, are whole numbers or not...\nbecause you won\'t be just making negative number of burgers or a fraction of them, will you? : -)\n\n# Implementation \nIt could be one liner, but I prefer code to be more understandable than being very short : -)\n```\n\nvector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {\n            double x = 0, y = 0;\n            x = (tomatoSlices - 2*cheeseSlices);\n            x = x / 2;\n            y = cheeseSlices - x;\n            if(ceil(x) == x and ceil(y) == y and x >= 0 and y >= 0) // checks for whole number\n               return {(int)x,(int)y};\n            return {};\n    }\n```\n# Complexity Analysis\nTime Complexity - O(1)  // no iterations, just direct calculations \nSpace Complecity - O(1) // No space needed except for 2 variable x and y : - ))\nFaster than 100% \n\n**Please upvote if you find it useful !!**\n
[]