Panda Guru LogoPanda
Guru

Axon | SDE 1 | USA | CoderPad

Round 1

Questions: Describe an object model that lets you find the total energy in milli-amp hours, from time 0 to T. The list of time intervals can be arbitrarily long, and you may want to be able to repeatedly query the power used at different times.

Example:

Seconds Average Power 0-300 125mA 300-400 50mA 400-550 500mA 550-1000 20mA

The total energy usage from T=0 to T=700s is 33.47mAH (milli amp hours)

(300*125 + 100*50 + 150*500 + 150*20)/(3600) = 33.47

Candidate's Approach

The candidate proposed creating a class PowerUsage that holds the time intervals and average power draw. The class would include methods to add intervals and calculate total energy usage up to a specified time T. The approach involves iterating through the intervals, calculating the energy for each segment, and summing them up to get the total energy in milli-amp hours.

Interviewer's Feedback

The interviewer appreciated the candidate's structured approach to the problem and the clarity in the object model design. However, they suggested considering edge cases, such as overlapping intervals and ensuring the model can handle large datasets efficiently.