Problem · String

Calculate Max Salary

MediumAmazonOA
See Amazon 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.

    Examples
    01 · Example 1
    schedule = "ABCDEEDCBA"
    return = 31000
    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! 🤩
    More Amazon problems
    drafts saved locally
    public int calculateMaxSalary(String schedule) {
      // write your code here
    }
    
    schedule"ABCDEEDCBA"
    expected31000
    checking account