You are given a string s consisting of lowercase English letters. Your task is to count the number of indices i (where 0 <= i < s.length - 1) such that the character at the current position is alphabetically strictly greater than the character at the next position (i.e., s[i] > s[i+1]).
Explanation: The adjacent pairs are ('d', 'c') at index 0, ('c', 'b') at index 1, and ('b', 'a') at index 2. In all three cases, the first character is alphabetically greater than the second.
Explanation: The adjacent pairs are ('a','b'), ('b','c'), ('c','c'), ('c','b'), and ('b','a'). Only ('c', 'b') and ('b', 'a') satisfy the condition s[i] > s[i+1].
Master coding challenges related to Strings and solve the Count Step-Down Character Pairs problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak