Created
October 21, 2017 22:12
-
-
Save MukulLatiyan/62b6bbb08e4811b0d8ff162e10202371 to your computer and use it in GitHub Desktop.
Immediate Smaller Element(GeeksForGeeks)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); | |
} | |
} | |
} |
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
its execution time is more..