HomeInterview QuestionsIn a scenario where ball numbers may repeat, how w…

In a scenario where ball numbers may repeat, how would you calculate the average score per over?

🟡 Medium Coding Junior level
1Times asked
Jun 2026Last seen
Jun 2026First seen

💡 Model Answer

To compute the average score per over when ball numbers can repeat, first determine the over for each ball. In cricket an over consists of six legal deliveries, so the over number can be calculated as

over = (ball_number - 1) // 6 + 1

Iterate through the list of (ball, score) tuples, accumulate the total score and count of balls for each over in a dictionary. After processing all records, compute the average for each over by dividing the total score by the count. The algorithm runs in O(n) time and O(k) space, where n is the number of balls and k is the number of overs. Example in Python:

from collections import defaultdict

def avg_per_over(records):
    totals = defaultdict(int)
    counts = defaultdict(int)
    for ball, score in records:
        over = (ball - 1) // 6 + 1
        totals[over] += score
        counts[over] += 1
    return {over: totals[over] / counts[over] for over in totals}

This handles repeated ball numbers because the over calculation is based on the ball number itself, not on uniqueness.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500