Java || Backtracking || 0ms || beats 100% in both time and memory || O(base*(3^toppings))
\n    int ans = Integer.MAX_VALUE;\n    \n    public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n        for(int i=0;i<baseCosts.length;
\n    int ans = Integer.MAX_VALUE;\n    \n    public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n        for(int i=0;i<baseCosts.length;i++)\n            closestCostHelper(toppingCosts,0,baseCosts[i],target);\n        return ans;\n    }\n    \n    public void closestCostHelper(int[] toppingCosts,int idx,int curr,int target){\n                \n        if(Math.abs(target - curr) < Math.abs(target - ans) || Math.abs(target - curr) == Math.abs(target - ans) && curr < ans)\n            ans = curr;\n                \n        if(curr > target || idx == toppingCosts.length)\n            return;\n        \n        closestCostHelper(toppingCosts,idx+1,curr,target);\n        closestCostHelper(toppingCosts,idx+1,curr+toppingCosts[idx],target);\n        closestCostHelper(toppingCosts,idx+1,curr+2*toppingCosts[idx],target);\n    }\n    \n
[]