Leaderboard
Showing:
Handle Score
@Ibrahim Nash 5725
@blackshadows 5685
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4908
@saiujwal13083 4156
@sanjay05 3762
@marius_valentin_dragoi 3511
@sushant_a 3453
@KshamaGupta 3318
@the_coder95 3302
Complete Leaderboard
Find first and last occurrence of x
Basic Accuracy: 34.6% Submissions: 25176 Points: 1

Given a sorted array with possibly duplicate elements. The task is to find indexes of first and last occurrences of an element X in the given array.

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N denoting the size of the array. Then in the next line are N space separated values of the array. The last line of each test case contains an integer X.

Output:
For each test case in a new line print two integers separated by space denoting the first and last occurrence of the element X. If the element is not present in the array print -1.

Constraints:
1 <= T <= 100
1 <= N <= 1000
1 <= A[], X <= 1018

Example:
Input:

2
9
1 3 5 5 5 5 67 123 125
5
9
1 3 5 5 5 5 7 123 125
7

Output:
2 5
6 6

Explanation:
Testcase 1:
Index of first occurrence of 5 is 2 and index of last occurrence of 5 is 5.

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Find first and last occurrence of x

Output Window