Sobes.tech
Middle+

Task 1 Implement (without using LINQ) a method that returns an array without duplicates while preserving the order of elements. int[] Distinct(int[] src) //[1,2,5,3,3,2] → [1,2,5,3] -------------- insert solution below --------------

sobes.tech AI

Answer from AI

csharp int[] Distinct(int[] src) { var seen = new HashSet<int>(); var result = new List<int>(); foreach (var item in src) { if (!seen.Contains(item)) { seen.Add(item); result.Add(item); } } return result.ToArray(); }


This method iterates over the source array, using a `HashSet` to track elements that have already been encountered. If an element has not been seen before, it is added to the result, preserving the order without duplicates.