search element right after target with Binary Search(possible duplicate array)
2022年5月1日小于 1 分钟
search element right after target with Binary Search(possible duplicate array)
Question
This is a variation of 37. implement Binary Search (unique).
Your are given a sorted ascending array of number, but might have duplicates, you are asked to return the element right after last appearance of a target number.
If not found return undefined
.
note
Please don't use Array.prototype.lastIndexOf()
, it is not our goal.
Code
/**
* @param {number[]} arr - ascending array with duplicates
* @param {number} target
* @return {number}
*/
function elementAfter(arr, target){
// your code here
}
Related
- implement Binary Search (unique)
- search first index with Binary Search(possible duplicate array)
- search last index with Binary Search(possible duplicate array)
- search element right before target with Binary Search(possible duplicate array)