Daily Coding Day One Ninety One
According to the ~~~latest~~~three or four days back email gracing my inbox this question was asked by Google. Most of these questions are seemingly brain flexes with limited real world applicability, this one strikes me as somehow a bit more aligned to applicable than not, but still it’s thought excersi-y. It reminds me of some of the university work we would do in Java. I can’t stand Java though so implemented in JS.
Given an array of elements, return the length of the longest subarray where all its elements are distinct.
For example, given the array [5, 1, 3, 5, 2, 3, 4, 1], return 5 as the longest subarray of distinct elements is [5, 2, 3, 4, 1]
1 | function longestSub(arr) { |