Lets say you have a method which takes in a pattern and also an entire String...
The method looks like this:
public int count(String pattern, String input) {
int count = 0;
// How to implement the number of occurrences of the pattern?
}
So, the inputs could be this:
String input = "sdbwedfddfbcaeeudhsomeothertestddtfdonemoredfdsatdevdb";
String pattern = "ddt";
int result = count(pattern, input);
What would be the most efficient way (in terms of complexity) to iterate and find the occurrences of "ddt"?