How to find a Needle in a Haystack in Java without using any library functions of String class. String class is modified so that we can only use charAt(index) which returns '$' if index is out of bound. We are not even allowed to use .length etc . What would be the brute force and optimal way to solve this problem.
public int findNeedle(String haystack, String needle){
}
For Example:
Haystack: "applepieorange"
Needle: "apple"
should return 0 Thanks