• 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

N teams are participating. each team plays twice with all other teams. Some of them will go to the semi final. Find Minimum and Maximum number of matches that a team has to win to qualify for finals ?

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

‘N’ Story Building, with 1,2,3 steps how many ways can a person reach top of building.

Longest Increasing Subsequence

Trapping Rain Water

Maximum occurred Smallest integer in n ranges

Singly linked list

Circular Linked List

Generate next palindrome number

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

Implement a generic binary search algorithm for Integer Double String etc

Add Sub Multiply very large number stored as string

Python String and numbers

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

Urban Ladder Written Test.

Doubly linked list

Microsoft BING Interview Experience

Get K Max and Delete K Max in stream of incoming integers

Cisco Hiring Event 21st – 22nd Feb 2015

Top 10 Interviews Techniqes for Campus Interview in IIT NIT BITS for MTech

Level order traversal in Spiral form

There are N nuts and N bolts, u have to find all the pairs of nuts and bolts in minimum no. of iteration

Facebook Interview Question : Interleave List

Templates in C++

Find and print longest consecutive number sequence in a given sequence in O(n)

Count Possible Decodings of a given Digit Sequence

Find Percentage of Words matching in Two Strings

Leetcode: Merge Intervals

Amazon Interview Experience – SDE Chennai

The greedy coins game Dynamic Programming

Copyright © 2025 · Genesis Framework · WordPress · Log in