Simple Fun #121: Mr. Odd
Description:
Mr. Odd is my friend. Some of his common dialogues are: "Am I looking odd?", "It’s looking very odd", etc. Actually, "odd" is his favorite word. This Valentine's Day he went to meet his girlfriend, but he forgot to take a gift. So he told her that he did an odd thing. His girlfriend became angry and gave him a puzzle. She gave him a string (str
) that contains only lowercase letters and told him:
Take 3 indexes
i, j, k
such thati < j < k
andstr[i] = "o", str[j] = "d", str[k] = "d"
and cut them from the string to make a new string"odd"
. How many such new strings can you make?
Mr. Odd wants to impress his girlfriend, so he wants to make the maximum number of "odd"
strings. As he is lazy, he asks you to help him and find the possible maximum.
Examples
For "oudddbo"
the result should be 1:
- cut one
"odd"
:"[o]u[d][d]dbo" --> "_u__dbo"
- no more
"odd"
in string
For "ooudddbd"
the result should be 2:
- 1:
"[o]ou[d][d]dbd" --> "_ou__dbd"
- 2:
"_[o]u__[d]b[d]" --> "__u___b_"
- no more
"odd"
in string
Input/Output
[input]
stringstr
: a non-empty string that contains only lowercase letters,0 < str.length <= 10 000
[output]
an integer: the maximum number of"odd"
that can be cut
Similar Kata:
Stats:
Created | Feb 10, 2017 |
Published | Feb 10, 2017 |
Warriors Trained | 1175 |
Total Skips | 34 |
Total Code Submissions | 2833 |
Total Times Completed | 425 |
JavaScript Completions | 142 |
C# Completions | 70 |
Python Completions | 204 |
Ruby Completions | 30 |
C Completions | 16 |
Total Stars | 27 |
% of votes with a positive feedback rating | 94% of 148 |
Total "Very Satisfied" Votes | 134 |
Total "Somewhat Satisfied" Votes | 11 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |