FastPrepDetect a Contiguous Subarray with Target Sum
Problems/Detect a Contiguous Subarray with Target Sum

Detect a Contiguous Subarray with Target Sum

Meta logoMeta● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks whether a contiguous run with the target sum exists, first with signed integers and then with only positive integers. An anonymous reply says it used prefix sums and then a sliding window, and we could not check who wrote it. The O(1) space idea for the positive-only follow-up is our own analysis, not an interviewer requirement from the report. Our function keeps signed input and a nonempty subarray. The positive-only version is explained in the editorial. The limits on the numbers and the answer for an empty array are our choices. Our version is about 90% the same as the reported question.

You are given an integer array nums and an integer target.

Return true if at least one nonempty contiguous subarray has a sum equal to target. Otherwise, return false.

The array may contain positive, negative, and zero values.

Function

hasTargetSumSubarray(nums: int[], target: int) → boolean

Examples

Example 1

nums = [1,2,3,4]target = 5return = true

The contiguous subarray [2,3] sums to 5.

Example 2

nums = [4,-2,-1,3]target = 0return = true

The contiguous subarray [-2,-1,3] has sum 0.

Example 3

nums = [2,4,6]target = 5return = false

No nonempty contiguous subarray sums to 5.

Constraints

  • 0 <= nums.length <= 200000.
  • -10^9 <= nums[i] <= 10^9.
  • -10^9 <= target <= 10^9.
  • A qualifying subarray must contain at least one element.
  • The mathematical subarray sum may exceed a signed 32-bit integer.

More Meta Phone Screen questions

  • Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
  • Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE 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

Similar questions at other companies

  • Maximum Sum Desirable SubarrayGroww · PHONE SCREEN
  • Equal Sum Split After One RemovalGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Maximum Size Subarray Sum Equals KeBay · PHONE SCREENeBay interview questions
  • Count Subarrays With Target SumAmazon · PHONE SCREEN
  • Count Subarrays with Sum KByteDance · PHONE SCREENByteDance interview questions
  • Subarray Sum Equals KApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Longest Equal-Zero-One SubarrayMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
  • Shortest Subarray with an Exact Target SumPeopleStrong · PHONE SCREENPeopleStrong interview questions
  • Count Subarrays That Add Up to kAdobe · PHONE SCREENAdobe interview questions
  • Find a Target-Sum SubarrayMorgan Stanley · PHONE SCREENMorgan Stanley interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer 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 boolean hasTargetSumSubarray(int[] nums, int target) {
      // write your code here
    }
}
Checking account…