Problem
Given a string of only 'a', 'b', 'c' characters, find the minimum number of character insertions to make it a concatenation of one or more "abc" repetitions.
Source
Nedbank VAS HackerRank Assessment - Q72
Tags: Easy, Strings
Constraints
- 1 <= length of s <= 10^5
- s consists only of 'a', 'b', 'c'
Examples
s="abb" -> 3 (transform to "abcabc")
s="aa" -> 4 (transform to "abcabc")
s="ac" -> 1 (insert 'b' to get "abc")
Approach Hints
- Each character in s maps to an expected position within a repeating cycle of 3 ('a'=0, 'b'=1, 'c'=2)
- Walk through s tracking which position in the cycle you expect next
- What happens when the current char is ahead of or behind the expected position?
Notes
Language: Java
Problem
Given a string of only 'a', 'b', 'c' characters, find the minimum number of character insertions to make it a concatenation of one or more "abc" repetitions.
Source
Nedbank VAS HackerRank Assessment - Q72
Tags: Easy, Strings
Constraints
Examples
Approach Hints
Notes
Language: Java