FastPrepCeiling Value in a Sorted Array
Problems/Ceiling Value in a Sorted Array

Ceiling Value in a Sorted Array

PeopleStrong logoPeopleStrong● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a PeopleStrong phone screen. The candidate asked for clarity: the answer is the exact key or the next larger value in the array, not key + 1. We chose the function interface and the limits. Our version is about 95% the same as the reported question.

Given an array nums sorted from smallest to largest and an integer key, return key if it is present. Otherwise, return the smallest array value greater than key. Return -1 when no such value exists.

Return the value, rather than its index. The answer need not be key + 1. For this exercise, assume array values and the key are nonnegative.

Function

ceilingValue(nums: int[], key: int) → int

Examples

Example 1

nums = [2,5,5,11]key = 6return = 11

The smallest value greater than 6 is 11, even though it is not 7.

Example 2

nums = [2,5,5,11]key = 5return = 5

The exact key occurs, so return 5.

Constraints

  • For this exercise, assume 0 <= nums.length <= 10^5.
  • 0 <= nums[i], key <= 10^9.
  • The array is sorted in nondecreasing order; duplicate values are allowed.

Interview reports that mention this question

  • PeopleStrong SDE OA and Interview Questions: 12 Experiences
All PeopleStrong interview questionsSee PeopleStrong hiring insights
Saved
class Solution {
    public int ceilingValue(int[] nums, int key) {
        // Write your solution here.
    }
}
Checking account…