C++ binary search with explanation
\nclass Solution {\npublic:\n    vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {\n        // Binary search: we know for sure the # of small burge
```\nclass Solution {\npublic:\n    vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices) {\n        // Binary search: we know for sure the # of small burgers will be >= 0 && <= cheeseSlices.\n        // So we use binary search to find out the ultimate # of small burgers.\n        //\n        // The condition is:\n        // 1) if the left tomato slices and cheese slices can make exact N # of jumbos, return the result.\n        // 2) if the left tomato slices is not enough to make exact # of jumbos, we need to make more small\n        //    burgers and less jumbo burgers, hence search from mid + 1 to right.\n        // 3) if left cheese slices is not enough to make exact # of jumbos, we need to make less small burgers\n        //    and more jumbo burgers, hence search from left to mid - 1.\n        return numOfBurgers(tomatoSlices, cheeseSlices, 0, cheeseSlices);\n    }\n    \nprivate:\n    vector<int> numOfBurgers(int tomatoSlices, int cheeseSlices, int left, int right)\n    {\n        if (left > right)\n        {\n            return {};\n        }\n        \n        int mid = left + (right - left) / 2; \n        int leftTomatoes = tomatoSlices - mid * 2;\n        int leftCheeses = cheeseSlices - mid;\n        \n        if (leftCheeses * 4 == leftTomatoes)\n        {\n            return {leftCheeses, mid};\n        }\n        \n        if (leftCheeses * 4 < leftTomatoes)\n        {\n            return numOfBurgers(tomatoSlices, cheeseSlices, left, mid - 1);\n        }\n        \n        return numOfBurgers(tomatoSlices, cheeseSlices, mid + 1, right);\n    }\n};\n```
[]