cswork / OA打开练习工作台

CiscoOA #10

Check Alphabetical Order

估计简单评测数据准备中,可先阅读题面

考点(AI 标注)字符串

Given a string inputString, find the first index i (1-indexed in the original wording but use 0-based zero-indexing here) at which the string breaks lowercase alphabetical (non-decreasing) order — that is, the first i ≥ 1 with inputString[i] < inputString[i-1]. If the entire string is already in non-decreasing order, return 0.

Constraints

  • 1 ≤ len(inputString) ≤ 10⁵
  • inputString consists of lowercase English letters.

Example 1

Input:

inputString = "abc"

Output:

0

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

Example 2

Input:

inputString = "asd"

Output:

2

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