文件: root - text - article - 2019 - 10 - daily-problem-first-and-last-indices-of-an-element-in-a-sorted-array.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 455 次阅读, 37625 次搜索 | 87 个单词
| 浏览 | 博客存档
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 455 次阅读, 37625 次搜索 | 87 个单词
| 浏览 | 博客存档
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:
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Problem, Data Structures and Algorithms, | 英文 | 主页 | 类别: 计算机科学 | 455 次阅读, 37625 次搜索 | 87 个单词 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]
猜您喜欢...
- Find Pythagorean Triplets
- Daily Interview Problem: Circle of Chained Words
- Daily Interview Problem: Min Range Needed to Sort
- Daily Interview Problem: Look and Say Sequence
- [Daily Problem] Longest Palindromic Substring
- Find the non-duplicate number
- Daily Interview Problem: Merge K Sorted Linked Lists
- Algorithm Interview: Permutations of numbers
- Daily Interview Puzzle: Falling Dominoes
- Spreadsheet Columns
©2006~2024 牛排过熟 - 0.00895 秒 - 2196.857 KB/s - 31 在线 内存: 495.27 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
牛排怎么做才好吃? | <meta name="机器人" content="不索引, 跟踪" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
评论 (0)
读写完全 - 一般 - 最小 - 表格 - 所有评论 - 统计
当前页暂时没有评论。