πŸ“˜
Placecom Question
  • βœ…ABC? (Contest)
  • βœ…Activity Selection (Contest)
  • βœ…Absolute value discrepancy (Contest)
  • βœ…Akash's Contest (Contest)
  • βœ…Alternate Matrix Addition(Contest)
  • βœ…Anti clockwise(Contest)
  • βœ…Arpit's toy (Contest)
  • βœ…Array Frequency Paradigm (Contest)
  • βœ…Array Games (Contest)
  • βœ…Arranging Students (Contest)
  • βœ…Array Proximity (Contest)
  • βœ…ATM Machine (Contest)
  • βœ…Awesome Numbers(Contest)
  • βœ…Bad Dish (Contest)
  • βœ…Balanced Neighborhood (Contest)
  • βœ…Birthday Gift (Contest)
  • βœ…Boundary Traversal of Matrix(Contest)
  • βœ…Buy and Sell Stock(Contest)
  • βœ…Cakewalk? (Contest)
  • βœ…Can we sort? (Contest)
  • βœ…Candy Love (Contest)
  • βœ…Candy Shopping (Contest)
  • βœ…Choose Card optimally(Contest)
  • βœ…Candy Store Earnings (Contest)
  • βœ…Choose points (Contest)
  • βœ…Concatenate Strings (Contest)
  • βœ…Common digits in two numbers (Contest)
  • βœ…Count 1's in binary array(Contest)
  • βœ…Count Numbers (Contest)
  • βœ…Count Total Digits in a Number (Contest)
  • βœ…Counting Zeroes to Ones (Contest)
  • βœ…Cyclic Rotation Paradigm (Contest)
  • βœ…Derrangement Exercise (Contest)
  • βœ…Diagonal Sum(Contest)
  • βœ…Diet planning (Contest)
  • βœ…Difference Array (Contest)
  • βœ…Digits Rearrangement (Contest)
  • ❌Divisible by 8 (Contest)
  • βœ…Door problem (Contest)
  • βœ…Duplicates at a distance k (Contest)
  • βœ…Easy - Peasy (Contest)
  • βœ…Eat or be Eaten(Contest)
  • βœ…Factorial - Recursion(Contest)
  • βœ…Find element in 2D array (Contest)
  • βœ…Generate all parentheses(Contest)
  • βœ…The gabba test(Contest)
  • βœ…Fruit Market (Contest)
  • βœ…Frequency Sort (Contest)
  • βœ…Floor in a Sorted Array(Contest)
  • βœ…First non-repeating character in a String(Contest)
  • βœ…Find unique(Contest)
  • βœ…Get the Shadow (Contest)
  • βœ…Good cells (Contest)
  • βœ…Good circular array (Contest)
  • βœ…Grid Magic (Contest)
  • βœ…Guardians of Galaxy(Contest)
  • βœ…Happy Balloons (Contest)
  • βœ…Help James (Contest)
  • βœ…Help Samar with Chopsticks (Contest)
  • βœ…Hip Hip Array (Contest)
  • βœ…Increment- Decrement Philosophy (Contest)
  • βœ…Infinity Stones : Form Black Order - The Army of Thanos (Contest)
  • βœ…Insert Operator(Contest)
  • βœ…Integer Modification (contest)
  • βœ…Inversion of array(Contest)
  • βœ…Iso Lexo String (Contest)
  • βœ…Jumping Numbers (Contest)
  • βœ…K closest points(Contest)
  • βœ…Knight game(Contest)
  • βœ…K-Pairs (Contest)
  • βœ…Kth Row of Pascal's Triangle(Contest)
  • βœ…Largest Bitonic Subarray(Contest)
  • βœ…Least Subarrays(Contest)
  • βœ…Lexographical Rotation (Contest)
  • βœ…Lone Sum Supremacy (Contest)
  • βœ…Lucky Boys(Contest)
  • ❌Majority Element(Contest)
  • βœ…Matrix problem(Contest)
  • βœ…Matrix ZigZag Traversal(Contest)
  • βœ…Max Candies(Contest)
  • βœ…Max permute (Contest)
  • βœ…Max Score in Quiz (Contest)
  • βœ…Max sum column (Contest)
  • βœ…Max XOR(Contest)
  • ❌Maximize Strength (Contest)
  • βœ…Maximizing Difference(Contest)
  • βœ…Maximum Area(Contest)
  • ❌Maximizing Difference(Contest)
  • βœ…Maximum Force(Contest)
  • βœ…Longest subarray not having more than K distinct elements(Contest)
  • βœ…Maximum value of difference of a pair of elements and their Index(Contest)
  • βœ…Minimum adjacent difference in a circular array easy(Contest)
  • βœ…Minimum Element in Sorted and Rotated Array(Contest)
  • βœ…Minimum operation - II(Contest)
  • βœ…Missing two(Contest)
  • βœ…Mohit and array(Contest)
  • βœ…Most occurring elements(Contest)
  • βœ…Move Zeros(Contest)
  • βœ…Moving right (Contest)
  • βœ…Max Score in Quiz (Contest)
  • βœ…N integers: Easy (Contest)
  • βœ…Nth node from end of linked list(Contest)
  • βœ…Number of distinct numbers(Contest)
  • βœ…Odd Sum Array (Contest)
  • βœ…Optimal Goodies (Contest)
  • βœ…Orange or Chocolate Candy? (Contest)
  • βœ…Packing Rectangles (Contest)
  • βœ…Pair sum (Contest)
  • βœ…Passcode (Contest)
  • βœ…Permutation - 2 (Contest)
  • βœ…Polynomial equation(Contest)
  • βœ…Power function(Contest)
  • βœ…Power of Three(Contest)
  • βœ…Print Pattern (Contest)
  • βœ…Reduce to 1 (Contest)
  • βœ…Remove Duplicates Inplace(Contest)
  • βœ…Repeating numbers (Contest)
  • βœ…Replace element(Contest)
  • βœ…Ropes (Contest)
  • βœ…Row Index Identification (Contest)
  • βœ…Row with maximum 1's(Contest)
  • βœ…Sara and Monsters (Contest)
  • βœ…Science Camp (contest)
  • βœ…Score bar(Contest)
  • βœ…Search in rotated sorted array(Contest)
  • βœ…Searching an element in a sorted array(Contest)
  • βœ…Separating Negative and Positive numbers(Contest)
  • ❌Sequence Formation (Contest)
  • ❌Setwet's Fish Pond(Contest)
  • βœ…Shopping (Contest)
  • βœ…Simple Circle (Simple Contest)
  • βœ…Simple Pairs(Contest)
  • βœ…Simple Transpose (Contest)
  • βœ…Skit Video (Contest)
  • βœ…Smaller elements (Contest)
  • βœ…Sort it (Contest)
  • βœ…Special digit sum (Contest)
  • βœ…Spiral rotation(Contest)
  • βœ…Squiggly brackets (Contest)
  • βœ…Strange element (Easy-Version)
  • βœ…Subarray with given sum(Contest)
  • βœ…Sum of largest elements(Contest)
  • βœ…Sum Up(Contest)
  • βœ…Swapping Matrix (Contest)
  • βœ…Sweet Bunty (Contest)
  • βœ…Teacher(Contest)
  • βœ…The EndGame : Concatenated Words(Contest)
  • βœ…The high median paradigm (Contest)
  • βœ…Tower of Hanoi(Contest)
  • βœ…Transpose of a matrix(Contest)
  • βœ…Triangular matrix (Contest)
  • βœ…Two Sum Maximization(Contest)
  • βœ…Ultron : Vibranium Quest(Contest)
  • βœ…Wakandan Point in Unsorted Array(Contest)
  • βœ…Yet again Partition sort problem (Contest)
  • βœ…Yet Another Array Rearrangement Problem (Contest)
  • βœ…Zero Padding(Contest)
  • βœ…First & Last (Contest)
  • ❌Fast Search (Contest)
Powered by GitBook
On this page

Minimum Element in Sorted and Rotated Array(Contest)

Minimum Element in Sorted and Rotated Array easy asked in interviews by 1 company Time Limit: 2 sec Memory Limit: 128000 kB

PreviousMinimum adjacent difference in a circular array easy(Contest)NextMinimum operation - II(Contest)

Last updated 2 years ago

Problem Statement :

Loki is one mischievous guy. He would always find different ways to make things difficult for everyone. After spending hours sorting a coded array of size N (in increasing order), you realise it’s been tampered with by none other than Loki. Like a clock, he has moved the array thus tampering the data. The task is to find the minimum element in it. Input The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consist of two lines. The first line of each test case consists of an integer N, where N is the size of array. The second line of each test case contains N space separated integers denoting array elements.

Constraints: 1 <= T <= 100 1 <= N <= 10^5 1 <= A[i] <= 10^6

Sum of "N" over all testcases does not exceed 10^5 Output Corresponding to each test case, in a new line, print the minimum element in the array. Example Input: 3 10 2 3 4 5 6 7 8 9 10 1 5 3 4 5 1 2 8 10 20 30 45 50 60 4 6

Output: 1 1 4

Explanation: Testcase 1: The array is rotated once anti-clockwise. So minium element is at last index (n-1) which is 1. Testcase 2: The array is rotated and the minimum element present is at index (n-2) which is 1. Testcase 3: The array is rotated and the minimum element present is 4.

link:

```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    private static int findMin(int[] arr, int low,int high) {
        if(low==high) {
            return arr[low];
        }
        int mid=(low+high)/2;
        if(arr[mid]>arr[high]){
            return findMin(arr,mid+1,high);
        } else{
            return findMin(arr,low,mid);
        }
    }
    public static void main (String[] args) {
       Scanner sc=new Scanner(System.in);
       int t=sc.nextInt();
       while(t-->0) {
           int n=sc.nextInt();
           int [] arr=new int[n];
           for(int i=0;i<n;i++)  {
               arr[i]=sc.nextInt();
           }
           int min=findMin(arr,0,n-1);
           System.out.println(min);
       }
    }
}
```
βœ…
https://my.newtonschool.co/playground/code/5lkpghmg536k/