FastPrepFirst Element Greater Than K
Problems/First Element Greater Than K

First Element Greater Than K

Meta logoMeta● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta phone screen for a Business Support Engineer role (full-time, experienced). The second coding question gave a sorted array and a number k and asked for the first element that is strictly greater than k, with binary search as the intended idea. The report does not say what to return when no element is greater, whether values can repeat, or how large the input is.

Here we chose to return -1 when no element is greater than k (values are never negative, so -1 is never a real answer). We also chose that the array may be empty and may repeat values, the limits (up to 10^4 numbers from 0 to 10^9) and the examples.

Our version is about 85% the same as the reported question.

Given an integer array nums sorted in non-decreasing order and an integer k, return the first element of nums that is strictly greater than k. Because nums is sorted, this is also the smallest element greater than k.

Elements equal to k do not count. If no element is greater than k, including when nums is empty, return -1.

Follow-up: can you do it in O(log n) time, where n is the length of nums?

Function

firstGreater(nums: int[], k: int) → int

Examples

Example 1

nums = [1,3,3,5,8]k = 3return = 5

The two copies of 3 are equal to k, not greater, so they are skipped. The first element greater than 3 is 5.

Example 2

nums = [2,4,6]k = 6return = -1

The largest element, 6, equals k. No element is greater than 6, so return -1.

Example 3

nums = [2,5,9,14]k = 10return = 14

k = 10 is not in the array. The elements 2, 5 and 9 are smaller, and 14 is the first one greater than 10.

Constraints

  • 0 <= nums.length <= 10^4
  • 0 <= nums[i] <= 10^9
  • 0 <= k <= 10^9
  • nums is sorted in non-decreasing order (values may repeat).

More Meta Phone Screen questions

  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Values Exclusive to the Current UserPHONE SCREEN · Seen Sep 2026
  • First Bad Version in a Monotone ArrayPHONE SCREEN · Seen Sep 2026
  • Parenthesized String CalculatorPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Price at Query TimestampsGoogle · PHONE SCREENGoogle interview questions
  • First Missing Number in a Consecutive ArrayArista Networks · OA · PHONE SCREENArista Networks interview questions
  • Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
  • Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Leftmost Binary Search MatchByteDance · PHONE SCREENByteDance interview questions
  • Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
  • Find the First Target IndexSuperhuman · PHONE SCREENSuperhuman interview questions
  • First Target IndexGrammarly · PHONE SCREEN
  • Ceiling Value in a Sorted ArrayPeopleStrong · PHONE SCREENPeopleStrong interview questions

Interview reports that mention this question

  • Meta Business Support Engineer Phone Screen: 1 Experience

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int firstGreater(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…