Can an Order be Cancelled
Given the current status of an order, determine whether cancellation is allowed. An order can be cancelled only when its status is Placed or Packed. Orders that are Shipped, Delivered, or already Cancelled cannot be cancelled.
Return true if cancellation is allowed; otherwise, return false. The driver prints these boolean values in lowercase.
Note: The input is an integer status: 0 = Placed, 1 = Packed, 2 = Shipped, 3 = Delivered, and 4 = Cancelled. The driver converts this integer to the corresponding OrderStatus enumeration value before calling canCancel.
Example 1:
Input: status = 0
Output: true
Explanation: The integer 0 represents OrderStatus::Placed. Placed is one of the two statuses eligible for cancellation, so the function returns true.
Example 2:
Input: status = 1
Output: true
Explanation: The integer 1 represents OrderStatus::Packed. Packing does not remove cancellation eligibility: Packed is explicitly allowed by the rule. Therefore, the function returns true.
Now Your Turn!
Pick the correct output for the given inputInput: status = 2
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 0 <= status <= 4