FastPrepCheck Alphabetical Order 🌸
Problems/Check Alphabetical Order 🌸

Check Alphabetical Order 🌸

Cisco logoCisco● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a string inputString. Check whether its letters are in alphabetical order.

  • If every character is the same as or later in the alphabet than the character just before it, return 0. Equal letters next to each other are allowed, so "aab" is in order.
  • Otherwise, return the index (counting from 0) of the first character that comes earlier in the alphabet than the character just before it.

The first character can never be out of order, so the answer 0 always means the string is in order.

Function

checkAlphabeticalOrder(inputString: String) → int

Examples

Example 1

inputString = "abc"return = 0

The given string "abc" is in alphabetical order, so the output is '0'.

Example 2

inputString = "asd"return = 2

The given string "asd" is not in alphabetical order, and the character at index '2' is where it is out of order.

Constraints

  • 1 ≤ inputString.length ≤ 10^5
  • inputString contains only lowercase English letters.

More Cisco interview questions

  • Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
  • Find Unique ElementsPHONE SCREEN · Seen Nov 2026
  • First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
  • Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
  • Reverse a StringPHONE SCREEN · Seen Nov 2026
  • Valid ParenthesesPHONE SCREEN · Seen Nov 2026
  • K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
  • Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
  • Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Fill One Exact-Length Binary WindowAmazon · OA
  • Remove Vowels from a StringHSBC · OAHSBC interview questions
  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
All Cisco interview questionsSee Cisco hiring insights
Saved
class Solution {
    public int checkAlphabeticalOrder(String inputString) {
      // write your code here
    }

}
Checking account…