-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq2.java
More file actions
33 lines (30 loc) · 722 Bytes
/
Copy pathq2.java
File metadata and controls
33 lines (30 loc) · 722 Bytes
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
import java.util.Scanner;
public class q2 {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int [] arr=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
int ele=sc.nextInt();
int cnt=0,lastidx=-1,firstidx=-1;
for(int i=0;i<n;i++)
{
if(arr[i]==ele)
{
cnt++;
lastidx=i;
}
}
if(lastidx==-1)
{
System.out.println(-1 +","+ -1);
}
else {
System.out.println(lastidx-cnt+1 +","+lastidx);
}
}
}