Stack Bash - Master data structures and algorithms

Longest distinct subarray

Given an array of numbers, write a function that returns the indices of the longest subarray with unique elements.
For example, given the array:
[4, 9, 9, 3, 4, 7]
Your function's output should return the tuple (2, 5) since the subarray between those indices: [9, 3, 4, 7] is the longest one with distinct entries.
Note that if there are multiple subarrays with the same length, return the indices of the first subarray found.

Try it first


6 Essential Hash Tables Coding Interview Problems

Master Hash Tables by trying the coding challenges below.
  1. 1.Two sumEasy
  2. 2.Palindrome CheckEasy
  3. 3.Cover SetMedium
  4. 4.Missing numberMedium
  5. 5.Crypto ExchangeMedium
  6. 6.Distinct SubarrayHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.