6 kyu
Calculate String Rotation
2,119 of 7,463obnounce
Description:
Write a function that receives two strings and returns n, where n is equal to the number of characters we should shift the first string forward to match the second. The check should be case sensitive.
For instance, take the strings "fatigue" and "tiguefa". In this case, the first string has been rotated 5 characters forward to produce the second string, so 5 would be returned.
If the second string isn't a valid rotation of the first string, the method returns -1.Examples:
"coffee", "eecoff" => 2
"eecoff", "coffee" => 4
"moose", "Moose" => -1
"isn't", "'tisn" => 2
"Esham", "Esham" => 0
"dog", "god" => -1
Strings
Arrays
Algorithms
Similar Kata:
Stats:
Created | Jul 3, 2015 |
Published | Jul 4, 2015 |
Warriors Trained | 14763 |
Total Skips | 2131 |
Total Code Submissions | 27927 |
Total Times Completed | 7463 |
Ruby Completions | 355 |
Java Completions | 1918 |
JavaScript Completions | 2119 |
Clojure Completions | 144 |
Python Completions | 1890 |
Haskell Completions | 149 |
C# Completions | 566 |
CoffeeScript Completions | 16 |
F# Completions | 78 |
Swift Completions | 282 |
Rust Completions | 118 |
COBOL Completions | 4 |
C Completions | 90 |
Total Stars | 228 |
% of votes with a positive feedback rating | 92% of 1016 |
Total "Very Satisfied" Votes | 875 |
Total "Somewhat Satisfied" Votes | 128 |
Total "Not Satisfied" Votes | 13 |