Minimum Steps on a Circular Letter Dial
Updated
Problem statement
The uppercase English letters A through Z are arranged in a circle, so A and Z are adjacent.
A pointer starts at A. You may move it clockwise or counterclockwise, and each move to an adjacent letter costs exactly one step.
Given an uppercase string inputStr, visit its characters in order. Return the minimum total number of steps required.
Function
calculateMinSteps(inputStr: String) → intExamples
Example 1
inputStr = "BZA"return = 4Move from A to B in 1 step. The shortest route from B to Z is B → A → Z, which costs 2 steps. Finally, move from Z to A in 1 step. The total is 1 + 2 + 1 = 4.
Constraints
inputStrcontains only uppercase English letters fromAthroughZ.
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
Similar questions at other companies
- Robot Assembly Line ConflictsGoogle · OA
- Word Wrap with Even JustificationSentry · OA · PHONE SCREEN
- Format a Centered Newspaper PageVisa · OA
- Balance the Game BoardMicrosoft · OA
- Max Number of OperationsSalesforce · OA
- Text JustificationUber · PHONE SCREEN
- Choose the Next Hidden-Word GuessFlexport · ONSITE INTERVIEW
- Choose the Next Hidden-Word GuessCharacter.AI · PHONE SCREEN
- URL Segment Compression Part 3 — Global Token BudgetStripe · ONSITE INTERVIEW
- Branch with the Most FilesCapital One · OA