Skip to content

Instantly share code, notes, and snippets.

@MukulLatiyan
Created October 21, 2017 22:12
Show Gist options
  • Save MukulLatiyan/62b6bbb08e4811b0d8ff162e10202371 to your computer and use it in GitHub Desktop.
Save MukulLatiyan/62b6bbb08e4811b0d8ff162e10202371 to your computer and use it in GitHub Desktop.
Immediate Smaller Element(GeeksForGeeks)
//Java code for immediate smaller problem on geeksforgeeks(School problem-array Section).
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<n-1;i++)
{
if(a[i+1]<a[i])
System.out.print(a[i+1]+" ");
else
System.out.print(-1+" ");
}
System.out.print(-1);
System.out.println();
}
}
}
@shreejit-mishra
Copy link

its execution time is more..

@ChaudharyRaj
Copy link

this problem is under the Stack section so why solving it without stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment