Last active
October 17, 2019 18:53
-
-
Save praveeng1618/f2554980dadc21cc3b2d2398e6bd38e6 to your computer and use it in GitHub Desktop.
Given a sorted array, A, with possibly duplicated elements, find the indices of the first and last occurrences of a target element, x. Return -1 if the target is not found.
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
flist=[] | |
slist=[] | |
count = 0 | |
A=[int(x) for x in input().split()] | |
target = int(input()) | |
for x in range(len(A)) : | |
if target == A[x] : | |
flist.append(x) | |
count+=1 | |
if count == 0: | |
print("[-1,-1]") | |
else: | |
slist.append(flist[0]) | |
slist.append(flist[-1]) | |
print(slist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment