Calculate bonus based on the given condition.
💡 Model Answer
Assuming we have a list of employees with their sales figures and a bonus policy such as: if sales > 100k, bonus = 10% of sales; if sales between 50k and 100k, bonus = 5%; otherwise no bonus. A simple linear scan will compute the bonus for each employee. Pseudocode:
for each employee in employees:
if employee.sales > 100000:
bonus = employee.sales * 0.10
elif employee.sales >= 50000:
bonus = employee.sales * 0.05
else:
bonus = 0
print(employee.id, bonus)Time complexity is O(n) where n is the number of employees, and space complexity is O(1) if we output results immediately. In Python, this could be implemented with a list comprehension or a simple for‑loop. If the data is stored in a database, a single SQL query using CASE can compute bonuses in bulk:
SELECT id,
sales,
CASE
WHEN sales > 100000 THEN sales * 0.10
WHEN sales >= 50000 THEN sales * 0.05
ELSE 0
END AS bonus
FROM employees;This approach is efficient and scales with the size of the dataset.
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