FastPrepFastPrep
Problem Brief

Sign In Pages 🍊

INTERNOA

As an intern at Amazon, you have been assigned a task to implement the three sign in pages, each with its own API: Register, Login, Logout.

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 requests is the same as order of the input.
  • The username and passwords are case-sensitive.
  • Function Description

    Complete the function signInPages in the editor.

    signInPages has the following parameter:

    1. String[] requests: an array of API requests

    Returns

    String[]: an array of responses for each API request

    1Example 1

    Input
    requests = ["register david david123", "register adam 1Adam1", "login david david123", "login adam 1adam1", "logout david"]
    Output
    ["Registered Successfully", "Registered Successfully", "Logged In Successfully", "Login Unsuccessful", "Logged Out Successfully"]
    Explanation

    The sequence of API requests and their corresponding responses are as follows:

    1. register david david123 - The user 'david' is registered successfully.
    2. register adam 1Adam1 - The user 'adam' is registered successfully.
    3. login david david123 - The user 'david' logs in successfully.
    4. login adam 1adam1 - The login is unsuccessful because the password is case-sensitive and does not match the registered password '1Adam1'.
    5. logout david - The user 'david' is logged out successfully.

    public String[] signInPages(String[] requests) {
        // write your code here
    }
    
    Input

    requests

    ["register david david123", "register adam 1Adam1", "login david david123", "login adam 1adam1", "logout david"]

    Output

    ["Registered Successfully", "Registered Successfully", "Logged In Successfully", "Login Unsuccessful", "Logged Out Successfully"]

    Sign in to submit your solution.