• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Find min element in Sorted Rotated Array (Without Duplicates)

August 4, 2014 by Dhaval Dave

Problem: Find the minimum element in a sorted and rotated array if duplicates not allowed:
Example: {3, 4, 5, 6, 7, 1, 2} output: 1

Algorithm:
This problem can be easily solved in O(n) time complexity buy traversing the
whole array and check for minimum element.
Here we are using a different solution which takes O(Log n)
Let us look at this approach, we are using a modified version of Binary Search Tree algorithm.

Thanks Dheeraj for  sharing Question and Code  for this .

Code:

#include<iostream> 
 using namespace std;

int BST(int A[],int low,int high){
  int mid=low+(high-low)/2;
  if ( mid == high ) return A[mid];  //if size of sub array is 1
  if(mid < high && mid > low && A[mid] < A[mid + 1] && A[mid -1] > A[mid] ) 
  return A[mid];  
//compare value of mid + 1,mid, mid-1 if they exist 

 if(A[mid] > A[high]) {
 if(A[mid + 1] < A[mid]) return A[mid + 1];
 else return BST(A, mid + 1, high); //check in right sub array
 }
 else
 {
 if(A[mid] < A[mid – 1]) return A[mid];
 else return BST(A , low , mid – 1); //check in left sub array
 } 
}

int main()
{
 int A[]={3,4,5,6,7,1,2};
 int n= sizeof(A)/sizeof(A[0]);
 cout<<BST(A,0,n-1)<<endl;
}

Similar Articles

Filed Under: Amazon Interview Question, Flipkart Interview Questions, Interview Questions, Microsoft Interview Questions, problem Tagged With: Array, Binary Search

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

BFS (Breath First Search)

Advanced SQL Injection

Interfaces in C++ (Abstract Classes in C++)

Given a float number convert it into the string WITHOUT using any inbuilt Function

Given a sorted array and a number x, find the pair in array whose sum is closest to x

write a c program that given a set a of n numbers and another number x determines whether or not there exist two elements in s whose sum is exactly x

Given a string, find the first character which is non-repetitive

Code Chef PRGIFT Solution

Daughter’s Age VeryGood Puzzle

Maximum difference between two elements s.t larger element appears after the smaller number

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

Find min element in Sorted Rotated Array (With Duplicates)

Trapping Rain Water

Find position of the only set bit

strtok()

Sort Stack in place

Length of the longest substring without repeating characters

SAP Off Campus Hiring_ March 2015 Sample Questions

HackeEarth Flipkart’s Drone

Level order traversal in Spiral form

Python List

Find the number ABCD such that when multipled by 4 gives DCBA.

Facebook Interview Question : Interleave List

simple sql injection

FizzBuzz Solution C C++

Handle duplicates in Binary Search Tree

Count number of ways to reach a given score in a game

Test Cases for Round Function

25 horses 5 tracks Find 3 fastest puzzle

Find shortest distances between every pair of vertices ( Dynamic Programming Floyd Warshall Algorithm)

Copyright © 2025 · Genesis Framework · WordPress · Log in