To the Top
File:  root - text - article - 2019 - 10 - daily-problem-first-and-last-indices-of-an-element-in-a-sorted-array.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Category: Computing | 291 Views, 32416 Search Bots | 87 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by AirBNB:

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.

Example:
Input: A = [1,3,3,5,7,8,9,9,9,15], target = 9
Output: [6,8]

Input: A = [100, 150, 150, 153], target = 150
Output: [1,2]

Input: A = [1,2,3,4,5,6,10], target = 9
Output: [-1, -1]
Here is a function signature example:


class Solution:
def getRange(self, arr, target):
# Fill this in.

# Test program
arr = [1, 2, 2, 2, 2, 3, 4, 7, 8, 8]
x = 2
print(Solution().getRange(arr, x))
# [1, 4]
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | English | Home Page | Cateogry: Computing | 291 Views, 32416 Search Bots | 87 Words Subscribe to Feed Burner

Related Articles

  1. Algorithm Interview: Longest Consecutive Sequence
  2. Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
  3. Skip the readings, focus on problems. And use all the hints!
  4. Detect Linked List Cycle
  5. Binary Tree Level with Minimum Sum
  6. Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
  7. Spreadsheet Column Title
  8. Daily Interview Problem: Count Number of Unival Subtrees
  9. First and Last Indices of an Element in a Sorted Array
  10. Daily Interview Problem: Deepest Node in a Binary Tree

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">