Today i tried to complete test from Hacker rank but i fail hard.
The test ask to find how many $newWord exist into a $oldWord example:
$newWord = 'abc';
$oldWord = 'abcababc';
How many occurency of abc exist here?
The answer is 7:
- abcababc
- abcababc
- abcababc
- abcababc
- abcababc
- abcababc
- abcababc
I have tried everything (split into array - substr - for loop - array_count_values) but I have not found the solution, anyone have a hint ?
I don't understand the logic for example how find abcababc, what i tried:
- Split word into equal part (from count
$newWord) then count with array values but i only find two way - Remove one letter at a time and count
$newWord
This's another example:
$newWord = 'ccc';
$oldWord = 'cccc';
How many occurency of ccc exist here?
The answer is 4:
- cccc
- cccc
- cccc
- cccc