TCS: Count, sum and two-decimal average of odd values in an array
Problem. The question is wrapped in a ticket-pricing story, but underneath it you read n and then n integers. Find the odd values and print three lines: how many there are, their sum, and their average rounded to two decimal places.
Example. For n = 7 and values 1 2 3 4 5 6 7, the output is a count of 4, a sum of 16 and an average of 4.00.
Context. This was the easy, simulation-style question in the advanced coding section of a national hiring test for the Digital role. It was paired with a medium question about reaching the cost closest to a target by picking one base item and up to two of each add-on.
What mattered. The post gives no constraints. The parts most likely to trip you up are matching the exact output format and the two-decimal rounding, plus the case where there are no odd numbers at all (not covered in the post).
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.