Google OOD problem _ HeartRateChecker
Anonymous User
122

Problem: build a system to check maximum heartRate for hikers in recent 2 KM.

  1. System should be Real-Time System
  2. Assume that hikers can be in the millions number of people
  3. Dataset will be received in real-time (CurrentDistance, HeartBeat) through API

// Code

import heapq

// Maximum HeartRate for hikers in 2KM
class limitation:
    distance = 2000 // 2KM 

class hiker:
    def __init__(self, personid):
        self.personid = personid
        self.heartbeat = {} # key - distance, value - heartbeat 
        self.distanceinLimitation = []
    
    def checkHeartbeat(self, heartbeat, currentdistance):
        self.heartbeat[currentdistance] = heartbeat
        
    def getMaximumHeartBeat(self, limit_distance):
        for i in self.heartbeat: # Distance체크
            if i < limit_distance: # 마지막 2KM 
                self.distanceinLimitation.append(self.heartbeat[i])
                
        heapq._heapify_max(self.distanceinLimitation)
        return heapq._heappop_max(self.distanceinLimitation)

class hikers:
    def __init__(self):
        self._hikers = [] 
    
    def addUsers(self, hiker):
        self._hikers.append(hiker)


def main():
    maximumHeartRate = 0 
    hikersobj = hikers()

    hiker1 = hiker(1)  
    hikersobj.addUsers(hiker1)

    hikersobj._hikers[0].checkheartbeat(210, 64000)
    
    // Once finish to add heartbeat, call getMaximumHeartBeat
    for i in range(0, len(hikersobj._hikers)):
        if maximumHeartRate < hikersobj.hikers[i].getMaximumHeartBeat(limitation.distance):
            maximumHeartRate = hikersobj.hikers[i].getMaximumHeartBeat(limitation.distance)
    
    return maximumHeartRate

Feedback is welcome

I have no idea how to update this system for millions of people?

Comments (0)