注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
I am given an array of Transactions in a ledger. A Transaction object has three things.
- Sender (which means who started this transaction)
- Receiver (means who is the destination of transaction)
- Timestamp (at what time this transaction was executed)
Now I need to write a method findIfTransactionIsValid() which will have the array of all transactions, one sender, one receiver. A transaction is valid is following cases:
- if sender and receiver are same
- The timestamp should be increasing (what I mean here is if A -> B happens at Time 2 and B-> C happens at Time 1, then A->C is not a valid transaction, however if B -> C happens at Time 3 then A --> C is a valid transaction)
Example:
Transaction
{
Sender -> Receiver (Timestamp)
}
Example: [T is timestamp here]
- A -> B (T=0)
- B -> C (T=1)
- C -> F (T=0)
复制代码
findIfTransactionIsValid(A, C) -> this should return true
findIfTransactionIsValid(B, F) -> false (time is backwards)
|