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.

Remove Duplicates from a Sorted Linked List

In this tutorial, I am going to discuss a programming question to remove duplicates from a sorted linked list.

Given a sorted linked list, write a code to remove all duplicates such that each element appears only once.

For example:

Input:

1 -> 2 -> 2 -> 3 -> 3 -> NULL

Output:

1 -> 2 -> 3 -> NULL