6 kyu

Greatest Position Distance Between Matching Array Values

653 of 1,466bryzaguy

Description:

The goal of this Kata is to return the greatest distance of index positions between matching number values in an array or 0 if there are no matching values.

Example: In an array with the values [0, 2, 1, 2, 4, 1] the greatest index distance is between the matching '1' values at index 2 and 5. Executing greatestDistance/greatest_distance/GreatestDistance with this array would return 3. (i.e. 5 - 2)

Here are some extra examples:

[0, 2, 1, 2, 4, 1]            => 3 (1's at indices 2 and 5)
[9, 7, 1, 2, 3, 7, 0, -1, -2] => 4 (7's at indices 1 and 5)
[0, 7, 0, 2, 3, 7, 0, -1, -2] => 6 (0's at indices 0 and 6)
[1, 2, 3, 4]                  => 0 (no repeated elements)

This is based on a Kata I had completed only to realize I has misread the instructions. I enjoyed solving the problem I thought it was asking me to complete so I thought I'd add a new Kata for others to enjoy. There are no tricks in this one, good luck!

Algorithms

Stats:

CreatedOct 18, 2014
PublishedOct 18, 2014
Warriors Trained2262
Total Skips135
Total Code Submissions4310
Total Times Completed1466
JavaScript Completions594
Python Completions653
C# Completions253
Scala Completions13
Total Stars40
% of votes with a positive feedback rating96% of 267
Total "Very Satisfied" Votes250
Total "Somewhat Satisfied" Votes15
Total "Not Satisfied" Votes2
Ad
Contributors
  • bryzaguy Avatar
  • jhoffner Avatar
  • joh_pot Avatar
  • CrazyMerlyn Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
  • ejini战神 Avatar
  • avermakov Avatar
  • KayleighWasTaken Avatar
Ad