Coding problem
Does any value repeat?
The task
A payments service receives a batch of transaction IDs before it settles them. If the same ID appears twice, the whole batch is held back for a check.
Complete HasRepeat(int[] values). Return true if some value appears at least twice in values, otherwise false. Do not change the array you are given: the caller still needs it in its original order.
Signature
public static bool HasRepeat(int[] values)
Examples
[4, 8, 4]→true. 4 appears at both ends.[6, 2, 9, 3]→false. Every value appears once.
Limits: Up to 400,000 values; a value can be any int.
The tests check: an empty array, one value, negative values, int.MinValue and int.MaxValue together, all values equal, that your method leaves the array unchanged, and 400,000 values with and without a repeat.
Hints
The solution opens by itself when all tests pass. You remember more if you try first.
Sign in to see the solutionYour code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// Returns true when some value appears at least twice in values.
public static bool HasRepeat(int[] values)
{
throw new NotImplementedException();
}
}Sign in to run and submit your code. It stays here while you do.