-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHackerrank3.java
77 lines (75 loc) · 1.08 KB
/
Hackerrank3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package practicetime;
import java.util.*;
public class Hackerrank3
{
public static void main (String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
int loc,min,temp=0;
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int m=sc.nextInt();
int b[]=new int[m];
for(int i=0;i<m;i++)
{
b[i]=sc.nextInt();
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
a[j]=a[n-1];
n--;
j--;
}
}
}
for(int i=0;i<n;i++)
{
min=a[i];
loc=i;
for(int j=i+1;j<n;j++)
{
if(a[j]>min)
{
min=a[j];
loc=j;
}
}
temp=a[i];
a[i]=a[loc];
a[loc]=temp;
}
for(int i=0;i<m;i++)
{
for(int j=n-1;j>=0;j--)
{
if(b[i]<a[j])
{
System.out.println(j+2);
break;
}
if(b[i]==a[j])
{
System.out.println(j+1);
break;
}
if(i==m-1)
{
System.out.println(1);
break;
}
}
}
}
}
//5
//100 80 80 50 30
//3
//10 60 100