Samsara 电面

# Create a class EngineStateEvent that models the state of the engine at a given time.
# The class should store the engine state and a timestamp.
#
# There are three potential engine states
# driving - engine is on and moving
# off - engine is off
# idle - engine is on and not moving
#
# This class must include a means of printing an EngineStateEvent as a string

# Create a class AlertProcessor. 
# 
# AlertsProcessor should have a method processEvent, 
# which will process one event at a time out of a stream of events. 
# The stream of events will be strictly time-ordered, and the timestamps 
# will increase monotonically. All events will be for a single vehicle.
# 
# processEvent will print "ALERT!" if the engine state changes to idle,
# and print "RESOLVED" when the engine state exits the idle state.
#
# processEvent may be called multiple times in a row for the same state,
# but should print a message only on state changes.

今天第一轮电面也是这题, 出的第三题是 modify AlertProcessor with a value minIdlePeriod, so that “ALERT!” will be printed if only the engine has been idling for a period >= minIdlePeriod. “ALERT!” should be printed only once during any continuous IDLE period. “RESOLVED” should be printed only if the engine state transitions from an IDLE period >= minIdlePeriod

所以楼主面的两轮都是OOD?能不能指教一下答这种题目会比较看重什么?

这是让同时实现这两个class,还是是两道题?

楼主过了吗,我第三题没写完呢。。。

我看了半天的题面, 感觉不就是在第二个class 里面加一个 var 记录车子当前的状态,然后新状态来了就看情况print value。 但是这也太简单了吧。不太敢相信。

是很简单,但我还是挂了lol

估计是面试官心怀鬼胎 不打算让你过。 加油 move on吧

可以具体说下怎么加var来记录么

你也要面么。 我感觉就是 第二个 class 价格 var prevstate。 然后新state来了 就比较下, 如果旧的是 idle 新的不是 就print。 如果新的是idle 旧的不是 也 print 。

是的,但是我还是不理解,你调用的时候是一个一个放进去,所以你是用一个全局变量来记录prevstate?