FastPrepFastPrep
Problem Brief

Calculate Max Salary

OA
See Amazon online assessment and hiring insights

You work at a company that has 5 offices, each with a distinct salary level and a priority ranking from lowest to highest as follows: Office A ($1)<OfficeB($10)< Office C ($100)<OfficeD($1,000)< Office E($ 10,000). Your work schedule is represented by a string, where each character corresponds to an office (e.g., 'D' for Office D) you work on the ith day. Your salary is calculated based on the following rule:

Salary Calculation Rules:

  • If you work in an office and no higher-priority office appears after it in the sequence, you add its salary to your total salary.
  • If you work in an office and a higher-priority office appears later in the sequence, you subtract its salary from your total salary.
  • The company allows you to change the office you work in, on any one day to maximise your total salary. Your task is to determine the maximum possible salary after making at most one such change.

    Input Format

    The first and only line contains a string S representing the sequence offices you worked in.

    Output Format

    Print the max salary you can get after changing at most one office to another office.

    1Example 1

    Input
    schedule = "ABCDEEDCBA"
    Output
    31000
    Explanation
    Not found for this time πŸ™‚β€β†”οΈ. Lets make a wish to find it in the near future πŸŽ‚ If you happen to know about it you are more than welcome to let us know. Thank you so much for carrying! 🀩
    public int calculateMaxSalary(String schedule) {
      // write your code here
    }
    
    Input

    schedule

    "ABCDEEDCBA"

    Output

    31000

    Sign in to submit your solution.