Description
Solutions
Submission
Return Records πŸ₯
🀘 INTERN

As an intern at Amazon, you have been assigned a task to implement the sign-in pages in the Amazon Dummy Website.

There are three sign-in pages, each with its own API:

Given a log of API requests, return the list of returns from the mock website.

Notes:

  • Initially, there are no users registered.
  • If a user is already logged in and makes a login request, the new request is unsuccessful. The original login remains active.
  • Each log is an API request and is in one of the three allowed formats.
  • The order of execution of each request is the same as the order of input.
  • The usernames and passwords are case-sensitive.
  • Function Description

    Complete the function returnRecords in the editor below.

    returnRecords has the following parameter:

  • string attempts[n]: each of the API requests
  • Returns

  • string[n]: an array of strings where #th string is the return value of the #th API request
  • ο½‘οΎŸπŸ“ ꒰ა Credit to neo݁ ΰ»’κ’± πŸ“ q゚

    Example 1:

    Input:  attempts = ["register user05 qwerty", "login user05 qwerty", "logout user05"]
    Output: ["Registered Successfully", "Logged In Successfully", "Logged Out Successfully"]
    Explanation:
    Check out the example image above πŸ‘†

    Example 2:

    Input:  attempts = ["register david david123", "register adam 1Adam1", "login david david123", "login adam 1adam1", "logout david"]
    Output: ["Registered Successfully", "Registered Successfully", "Logged In Successfully", "Login Unsuccessfully", "Logged Out Successfully"]
    Explanation:
  • register david david123: There is not user with the username "david" registered, so the registration is successful
  • register adam 1Adam1: There is not user with the username "adam" registered, so the registration is successful
  • login david david123: The username and the password for the user match with that in the database, so the login is successful
  • login adam 1adam1: The password("1adam1") does not match the actual password ("1Adam1"), so the login is unsuccessful
  • logout david: The user "David" is logged in currently, so the logout is successful
  • Constraints:
    • 1 ≀ n ≀ 105
    • 1 ≀ |username|, |password| ≀ 10 (where |s| is the length of string s)
    • username and password are alphanumeric strings, ranges [0-9, a-z, A-Z]
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: