Computer Science, asked by vaishalic584, 2 months ago

Smaller and Greater

You are given an Array A of size N.

Find for how many elements, there is a strictly smaller element and a strictly greater element.



Input Format

Given only argument A an Array of Integers.


Output Format

Return an Integer X, i.e number of elements.


Constraints


1 <= N <= 1e5

1 <= A[i] <= 1e6


For Example


Example Input:
A = [1, 2, 3]

Example Output:
1


Explanation:
only 2 have a strictly smaller and strictly greater element, 1 and 3 respectively.​

Answers

Answered by kundusagar200517
9

Answer:

make me brain list give me 30 thanks

Attachments:
Answered by arnabkhan1995
6

Answer:

Explanation:

public int solve(int[] A) {

       int n=A.length;

       int leftmax[]=new int[n];

       leftmax[0]=Integer.MIN_VALUE;

       int rightmin=Integer.MAX_VALUE;

       int index=0;

       for(int i=1;i<n;i++)

       {

           leftmax[i]=Math.max(leftmax[i-1],A[i-1]);

       }

       

       for(int i=n-1;i>=0;i--)

       {

           if(leftmax[i]<A[i] && rightmin>A[i])

           {

               index=i;

           }

           rightmin=Math.min(rightmin,A[i]);

       }

       return index;

Similar questions