Problem Submissions Solution

Floor in a Sorted Array

Difficulty: Easy

Acceptance: %

Points: 20.00

Given a sorted array arr[] containing unique elements and an integer k, your task is to find the index (0-based) of the largest element in the array that is less than or equal to k. This element is referred to as the "floor" of k. If no such element exists, return -1.

Topics

Companies

Articles

Examples:

Expected Time Complexity: O(log n)

Expected Auxiliary Space: O(1)

Constraints:
  • 1 <= arr.size() <= 10^6
  • 1 <= arr[i] <= 10^6
  • 0 <= k <= arr[n-1]
Companies:
Amazon Microsoft Walmart
Topics:
Sorting Algorithms
Locked Content
Access Restricted: Please Login to access the code editor and test cases.