FastPrepFind the First Repeated Value
Problems/Find the First Repeated Value

Find the First Repeated Value

Akuna Capital logoAkuna Capital● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One phone report asks for the first repeated number and mentions scanning with a set. Another only asks to find a duplicate and says the interviewer chose a hash map. It does not say which duplicate to return. Here we return the value whose second occurrence comes earliest. Values are non-negative with fixed limits. We return -1 when nothing repeats. We return a single value and leave the input unchanged.

Our version is about 80% the same as the reported questions.

You are given an array nums of nonnegative integers. Scan it from left to right. Return the first value you reach that already appeared earlier in the scan.

Put another way, find the smallest index j that has an earlier index i < j with nums[i] == nums[j]. Return nums[j]. This is the value whose second occurrence comes first. That holds even if another repeated value showed up earlier for the first time.

If every value is distinct, return -1. Arrays that are empty or have a single element also return -1. Zero is a valid value and a valid answer. The value -1 is outside the input range, so it never clashes with a real answer.

Return one value. Do not return an index, all repeated values or an array with duplicates removed. Do not sort or modify nums. Each call must start fresh, with no data kept from earlier calls.

For the follow-up, explain how hash-based lookup changes the time and space costs compared with checking earlier positions directly.

Function

firstRepeatedValue(nums: int[]) → int

Examples

Example 1

nums = [2,1,2,1]return = 2

The second occurrence of 2 is at index 2. The value 1 does not repeat until index 3, so the answer is 2.

Example 2

nums = [3,1,4,1,3]return = 1

The value 1 repeats at index 3, before 3 repeats at index 4. Although 3 had the earliest first occurrence, the answer is 1.

Example 3

nums = [0,5,0]return = 0

The value 0 repeats at index 2. Return 0; -1 is used only when no repeated value exists.

Constraints

  • 0 <= nums.length <= 100.
  • Every element is an integer between 0 and 1000000, inclusive.

More Akuna Capital Phone Screen questions

  • Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
  • Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Sep 2026
  • Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
  • Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
  • Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
  • Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
  • Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
  • Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025

Similar questions at other companies

  • Sparse Vector Dot Product from TuplesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Best Average Student ScoreGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Logger Rate LimiterGoogle · PHONE SCREENGoogle interview questions
  • Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
  • Price CheckBlue Origin · PHONE SCREEN
  • Majority ElementByteDance · PHONE SCREENByteDance interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Find Unique ElementsCisco · PHONE SCREENCisco interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions

Akuna Capital interview experiences

  • Akuna Capital Quant Trader and QR Interviews: 5 Experiences
  • Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
  • Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
  • Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
  • Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
  • Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)
All Akuna Capital interview questionsSee Akuna Capital hiring insights
Saved
class Solution {
    public int firstRepeatedValue(int[] nums) {
        // write your code here
    }
}
Checking account…