JAVA Easy understand solution
generarte possible combinations of {0,1,2}, then calculate sum and compare with target\n\n\nclass Solution {\n    public int closestCost(int[] baseCosts, int[] 
generarte possible combinations of {0,1,2}, then calculate sum and compare with target\n\n```\nclass Solution {\n    public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n        int mn = baseCosts[0];\n        for(int num : baseCosts){\n            mn = Math.min(mn, num);\n        }\n        if(mn > target) return mn; // not possible to get desired result\n        int res = mn;\n        int topLen = toppingCosts.length;\n        \n        List<List<Integer>> combs = new ArrayList<>();\n        \n        int []nums = {0,1,2};\n        helper(combs, new ArrayList<>(), nums, topLen);\n\n\n        for(int base: baseCosts){\n            for(int k = 0; k < combs.size(); k++){\n                List<Integer>comb = combs.get(k);\n                int tmp = 0;\n                for(int j = 0; j < toppingCosts.length; j++){\n                   tmp += toppingCosts[j] * comb.get(j);\n               }\n               tmp += base;\n               if( Math.abs(tmp -target) < Math.abs(res -target) ){\n                    res = tmp;\n                }else if( Math.abs(tmp -target) == Math.abs(res -target) ){\n                   res = Math.min(res, tmp);\n               }\n            }\n        }\n        return res;\n    }\n    void helper(List<List<Integer>>res, List<Integer> tmp, int[]nums, int len){\n        if(tmp.size() == len){\n            res.add(new ArrayList<>(tmp));\n            return;\n        }\n\n        for(int i = 0; i < nums.length; i++){\n            tmp.add(nums[i]);\n            helper(res, tmp, nums, len);\n            tmp.remove(tmp.size()- 1);\n        }\n    }\n}\n```
[]