Stripe -Stack Position OA -Stripe -OA代写 -OA ghost writing -一亩三分地 -OA help

Subscription Database - Part 1

We are tasked with creating an in-memory database to manage our users' subscriptions.

There are three operations we want to handle: starting a subscription, ending a subscription, and checking for a user's subscription. Each operation has an associated timestamp and contains extra parameters such as the user's name.

Example Input

["1,start,Michael", "5,check,Michael"]

Given a list of operations, return a list of corresponding results:

  • start
    • Starts a subscription for the user at the given timestamp.
    • Returns an empty string.
  • end
    • Ends a subscription for the user at the given timestamp.
    • Returns an empty string.
  • check
    • Returns "active" if the user has a subscription at the given timestamp.
    • Returns "inactive" if the user doesn't have a subscription at the given timestamp.

Subscription Database - Part 2

We recommend copy & pasting over your solution from Part 1 as a starting point for Part 2.

Great, we now have a database that can handle starting and ending subscriptions. However, the product requirement shows that we need to support starting a subscription that lasts a specific time duration.

Example Input

["1,start,Michael,9"]

We now want to be able to handle an optional duration parameter to our existing start operation. After the duration is past, the subscription is expired, and the check operation should return "inactive."

For the above example, since the subscription started at timestamp 1 with a duration of 9, that means the subscription is active until timestamp 10 and considered expired starting timestamp 11.

  • If a duration parameter is not passed in, we should continue to treat it as a subscription that lasts forever.
  • If the start operation is called for a user that has a subscription, we will simply override the existing subscription.
  • The check and end operations should continue to work the same way as Part 1.

Subscription Database - Part 3

We recommend copy & pasting over your solution from Part 2 as a starting point for Part 3.

Turns out, we actually don't want to simply override a user's existing subscription when the start operation is called. Instead, for cases where there's an existing subscription, we want to add the duration onto the existing subscription's duration.

Example Input

["1,start,Michael,10", "2,start,Michael,4"]

For the above example, since the subscription started at timestamp 1 with a duration of 10, that means the subscription is active until the end of timestamp 11 and considered expired starting from timestamp 12. The next start operation now extends that subscription, resulting in a subscription that is active until the end of timestamp 15 and considered expired starting from timestamp 16.

  • Continue to treat an empty duration parameter as a subscription that lasts forever.
  • Starting another subscription for a user with an existing "forever" subscription will have no impact since the result is still a "forever" subscription.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *