Elements After the First Target
Updated
Problem statement
You are given an integer list values and an integer target that appears in it. Return every element that comes after the first occurrence of target, in their original order. Do not include that first occurrence.
values holds only integers, target is an integer, and neither is ever null. If target occurs more than once, use its first occurrence. If that first occurrence is the last element, return an empty list.
Notes
For example, getFollowingElements([1,2,3,4], 2) -> [3,4] and getFollowingElements([a,b,c,d,e], e) -> []. Here the letters stand for integer values.
Function
getFollowingElements(values: int[], target: int) → int[]Examples
Example 1
values = [1,2,3,4]target = 2return = [3,4]The elements after the first 2 are 3 and 4.
Example 2
values = [5,6,5,7]target = 5return = [6,5,7]The target's later occurrence is just an ordinary element. Its first occurrence is at the very front, so the answer is every element except the first one.
Example 3
values = [1,2]target = 2return = []The target is the last element, so nothing comes after it. The answer is an empty list.
Constraints
1 <= values.length <= 10^5.-10^9 <= values[i], target <= 10^9.targetoccurs at least once.
More Apple Phone Screen questions
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
- Evaluate DivisionPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Validate a BST with a Custom ComparisonPHONE SCREEN · Seen Nov 2026
- Design a Food Rating SystemPHONE SCREEN · Seen Oct 2026
- Days Until Poisoned Plants StabilizePHONE SCREEN · Seen Oct 2026
- Capture Surrounded Regions with Union-FindPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Pascal's TriangleBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Sparse Vector Dot Product from TuplesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Numerically Stable SoftmaxWaymo · PHONE SCREENWaymo interview questions
- Best Average Student ScoreGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Logger Rate LimiterGoogle · PHONE SCREENGoogle interview questions
- Minimum StackSnowflake · PHONE SCREENSnowflake interview questions
- Streaming Entropy, Part 1: Batch EntropyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Price CheckBlue Origin · PHONE SCREEN
- Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions