Mode entretien. Minuteur de 15 min, sans indices ni autocomplétion
Indexes of duplicate numbers
DifficileMap and Set15 min
Write a function duplicateIndices(numbers) that finds where every duplicate number stands in an array.
numbersis an array of integers. They can be positive, negative or0.- Return a Map. Each key is a number that occurs more than once. Its value is an array of all its indexes in
numbers, from small to large. - Indexes start at 0, as usual in JavaScript.
- A number that occurs only once is not in the Map.
- If there are no duplicates (also for an empty array), return an empty
Map. - Key order is not checked.
Exemples
duplicateIndices([3, 1, 3, 2, 1, 3])Renvoie Map(2) { 3 => [ 0, 2, 5 ], 1 => [ 1, 4 ] }
duplicateIndices([7, 8, 7])Renvoie Map(1) { 7 => [ 0, 2 ] }
duplicateIndices([1, 2, 3])Renvoie Map(0) {}
Posé chez ServiceNow · Source
Chargement de l'éditeur...
- Entrée
duplicateIndices([ 3, 1, 3, 2, 1, 3 ])AttenduMap(2) { 3 => [ 0, 2, 5 ], 1 => [ 1, 4 ] } - Entrée
duplicateIndices([ 7, 8, 7 ])AttenduMap(1) { 7 => [ 0, 2 ] } - Entrée
duplicateIndices([ 1, 2, 3 ])AttenduMap(0) {}
Les tests cachés se lancent à la soumission