Find Ceil of an Element in a Sorted Array
Easy

Problem Statement

Given a sorted array `nums` and a value `x`, find the ceiling of `x` in the array. The ceiling is the smallest element in the array that is greater than or equal to `x`. If no such element exists, return -1.

Examples

1Example 1
Input:
{ "nums": [ 1, 2, 8, 10, 10, 12, 19 ], "x": 5 }
Output:
8
2Example 2
Input:
{ "nums": [ 1, 2, 8, 10, 10, 12, 19 ], "x": 20 }
Output:
-1
3Example 3
Input:
{ "nums": [ 1, 2, 8, 10, 10, 12, 19 ], "x": 0 }
Output:
1
Loading...

Sign in to Run Code and Submit