Search in Rotated Sorted Array

Write a code to search in rotated sorted array.

Given a sorted array and a target value.  Suppose this sorted array is rotated any number of times.

Write a code to search a target value in a sorted and rotated array. Return the index of a target value. If the target value is not found then return -1.

NOTE: The array only contains distinct values.

For example:

Input: {4, 5, 6, 7, -1, 0, 1, 2},  target = 0

Output: 5

In the above example, we have to search 0 in the rotated array. The element 0 is present at 5th index.