K42

Find First and Last Position of Element

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: ARRAY

Problem Statement & Objective

Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value in O(log n).

Function Signature (Python)

search_range(nums: list[int], target: int) -> list[int]

Input & Output Contract

Output Rule:[ilk, son] şeklinde iki elemanlı liste.

System Constraints

0 <= sayilar.length <= 10^5
-10^9 <= sayilar[i], hedef <= 10^9
sayilar artan sırada sıralıdır

Example Execution Walkthrough

sayilar = [5, 7, 7, 8, 8, 10], hedef = 8 -> cevap: [3, 4]
sayilar = [5, 7, 7, 8, 8, 10], hedef = 6 -> cevap: [-1, -1]

Example Test Scenarios (3)

Example 1
Input:[[5,7,7,8,8,10],8]
Expected Output:[3,4]
Example 2: Bulunamadı
Input:[[5,7,7,8,8,10],6]
Expected Output:[-1,-1]
Example 3: Boş Dizi
Input:[[],0]
Expected Output:[-1,-1]
Loading Python Editor...
Input Parameters
[
  [
    5,
    7,
    7,
    8,
    8,
    10
  ],
  8
]
Expected Output
[
  3,
  4
]