Find Floor of an Element in a Sorted Array
Easy

Problem Statement

Given a sorted array `nums` and a value `x`, find the floor of `x` in the array. The floor is the greatest element in the array that is less 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:
2
2Example 2
Input:
{ "nums": [ 1, 2, 8, 10, 10, 12, 19 ], "x": 20 }
Output:
19
3Example 3
Input:
{ "nums": [ 1, 2, 8, 10, 10, 12, 19 ], "x": 0 }
Output:
-1
Loading...

Sign in to Run Code and Submit