Detect a Contiguous Subarray with Target Sum
Updated
Problem statement
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) → booleanExamples
Example 1
nums = [1,2,3,4]target = 5return = trueThe contiguous subarray [2,3] sums to 5.
Example 2
nums = [4,-2,-1,3]target = 0return = trueThe contiguous subarray [-2,-1,3] has sum 0.
Example 3
nums = [2,4,6]target = 5return = falseNo 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