Find Minimum in Rotated Sorted Array

In this tutorial, I am going to discuss a very interesting problem find minimum in rotated sorted array.

Given an array which is sorted in ascending order is rotated at some unknown point. Write a code to find the minimum element in a sorted and rotated array.

You may assume no duplicate exists in the array.

For example:

Example 1:

Input: [6, 7, 8, 1, 2]
Output: 1

The minimum element in this sorted and rotated array is 1.

Example 2:

Input: [8, 9, 10, 1, 0, 1, 2]
Output: 0

In this example, the minimum element is 0.

Find Longest Common Prefix in an Array of Strings

How to find longest common prefix in an array of strings.

Given an array of strings, write a method to find the longest common prefix string. If no common prefix is found, return an empty string ” “.

For example:

Example 1:

Input: [“cat”,”cable”,”camera”]
Output: “ca”

The longest common prefix is ca.

Example 2:

Input: [“rat”,”dog”,”elephant”]
Output: “”

No common prefix is found.