Tuesday, May 6, 2008

Day 8 - Substring

You are given two strings - haystack and needle.
You have to find the position of the first occurrence of needle in haystack.
Write a function that takes haystack and needle as input and returns the position of the first occurrence of needle or -1 if needle is not found in haystack.

Eg.

haystack = "Once upon a time, there lived a little boy named Jingle!"
needle = "up"
Return Value = 5

If needle = "fox"
Return Value = -1

No comments: