FastPrepElements After the First Target
Problems/Elements After the First Target

Elements After the First Target

Apple logoApple● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The core suffix task matches the recollection at about 75%. This practice variant uses non-null integers, a present target, and the first match; the original discussion also covered generic objects and a null-target error.

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.
  • target occurs 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

Interview reports that mention this question

  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE Interviews: 37 Experiences (Part 1 of 3)

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple India SWE New Grad Interviews: 5 Experiences
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int[] getFollowingElements(int[] values, int target) {
        // Write your solution here.
    }

}
Checking account…