Binary Search on a Reverse Sorted Array
Easy

Problem Statement

Given a reverse sorted array of integers `nums` (sorted in descending order), and an integer `target`, write a function to search for the `target` in `nums`. If the target exists, return its index. Otherwise, return -1.

Examples

1Example 1
Input:
{ "nums": [ 12, 9, 5, 3, 0, -1 ], "target": 9 }
Output:
1
2Example 2
Input:
{ "nums": [ 12, 9, 5, 3, 0, -1 ], "target": 2 }
Output:
-1
3Example 3
Input:
{ "nums": [ 5 ], "target": 5 }
Output:
0
Loading...

Sign in to Run Code and Submit