注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
内容是关于bank ledger的一道OOP代码题。地里看到有人提过但没有具体内容,在没有提前准备的情况下时间会有点赶。
第一部分是设计简单的dataclass和2个基本函数,就是简单的加减。
第二部分才是重点,要设计2个函数,分别处理PAYMENT和FEE这2个events。输入是一系列的events,顺序有可能颠倒,那么后来的events如果本来要排在前面的话,就要放到正确的位置,并更新后面的events所导致的加减结果。思路并不难,重点是更新好events顺序以及重新计算加减。
简单的贴一下题目要求:
Step 1 - Event Handlers
The primary function of loan accounting is to track the state of a loan over time. In this simplified version, we are only tracking two fields:
Principal Balance - the outstanding principal balance that must be paid backcurring in real time, events must be processed in the order we receive them.
- We should not have to re-process all events every time an out-of-order event comes in.
Example- loan_ledger = LoanLedger()
- print(loan_ledger.process_event(event_type="PAYMENT", amount=1000, accounting_sequence=1))
- [size=6][b][[/b][/size]
- [size=6][b](1, 99000, 0)[/b][/size]
- [size=6][b]][/b][/size]
- print(loan_ledger.process_event(event_type="PAYMENT", amount=500, accounting_sequence=3))
- [size=6][b][[/b][/size]
- [size=6][b](1, 99000, 0),[/b][/size]
- [size=6][b](3, 98500, 0)[/b][/size]
- [size=6][b]][/b][/size]
- print(loan_ledger.process_event(event_type="FEE", amount=100, accounting_sequence=2))
- [size=6][b][[/b][/size]
- [size=6][b](1, 99000, 0),[/b][/size]
- [size=6][b](2, 99000, 100),[/b][/size]
- [size=6][b](3, 98600, 0)[/b][/size]
- [size=6][b]][/b][/size]
复制代码
大概就是这些。虽然要求不能re-process all events,但因为要更新followup events所以时间复杂度还是O(n)。要是再多给几分钟我能打磨更好些… |