Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
- [Replace every nth](replace-every-nth "57fcaed83206fb15fd00027a")
- [Resistor Color Codes](resistor-color-codes "57cf3dad05c186ba22000348")
- [Responsible Drinking](responsible-drinking "5aee86c5783bb432cd000018")
- [Return substring instance count](return-substring-instance-count "5168b125faced29f66000005")
- [Return the first M multiples of N](return-the-first-m-multiples-of-n "593c9175933500f33400003e")
- [Reverse a Number](reverse-a-number "555bfd6f9f9f52680f0000c5")
- [Reverse the bits in an integer](reverse-the-bits-in-an-integer "5959ec605595565f5c00002b")
Expand Down
17 changes: 17 additions & 0 deletions kata/7-kyu/return-substring-instance-count/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# [Return substring instance count](https://www.codewars.com/kata/return-substring-instance-count "https://www.codewars.com/kata/5168b125faced29f66000005")

Write a function that takes two string parameters `search_text` and `full_text` and returns the number of times the `search_text` is found
within the `full_text`.

* Overlap is not permitted: `"aaa"` contains `1` instance of `"aa"`, not `2`.
* `search_text` will never be empty.

## Examples:

```
full_text = "aa_bb_cc_dd_bb_e", search_text = "bb"
-- > should return 2 since "bb" shows up twice

full_text = "aaabbbcccc", search_text = "bbb"
-- > should return 1
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Solution {
static int substringCount(String fullText, String search) {
return (fullText + "_").split(search).length - 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

class SolutionTest {
@ParameterizedTest
@CsvSource(delimiter = '|', textBlock = """
abcdeb | b | 2
abcdeb | a | 1
ccddeeccddeecc | cc | 3
aaabbbccc | bb | 1
,,,..239,,,,,., | ,, | 3
""")
void sample(String fullText, String search, int expected) {
assertEquals(expected, Solution.substringCount(fullText, search));
}
}