0 day streak
Anonymous · shared experience20 Jun 2026 · 9 views

TCS: Closest achievable cost from one base plus up to two of each topping

Interview question #TCS SDE 1 Online assessment

Problem. You get two arrays: base costs (breads) and add-on costs (toppings), plus a target value. Pick exactly one base, and use each topping zero, one or two times. Return the total cost that comes closest to the target.

Sample from the post. Bases [3, 10], toppings [2, 5], target 9, and the post says the answer is 9. Under the rules as written, the totals nearest 9 look like 8 and 10, so the sample may rely on a rule the post leaves out. Check against the official statement before relying on it.

Context. This was the medium question in the advanced coding section of a national hiring test for the Digital role. The other question was an easy, story-wrapped task: from an array, print the count of odd numbers, their sum and their average to two decimals (for example 1..7 gives 4, 16 and 4.00).

What mattered. The post gives no constraints. Enumerating topping choices while tracking the closest total is the core of the problem.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.