Adobe Interview Questions - Finding first repeating elements in a given array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Memory_understanding
{
class Reapting_elements
{
public void getfirstrepeatingelements(int[] arr)
{
int min = -1;
int element=0;
HashSet<int> set = new HashSet<int>();
for (int i = arr.Length-1; i >= 0; i--)
{
if(set.Contains(arr[i]))
{
min=i;
element=arr[i];
}
else
{ set.Add(arr[i]);}
}
if (min == -1)
Console.WriteLine("No Repeating ELements!!!");
else
Console.WriteLine("Minimum repeating element" + element);
}
}
class Program
{
public static void Main_()
{
Reapting_elements a = new Reapting_elements();
int[] arr={3,4,5,1,3,1,10};
a.getfirstrepeatingelements(arr);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Memory_understanding
{
class Reapting_elements
{
public void getfirstrepeatingelements(int[] arr)
{
int min = -1;
int element=0;
HashSet<int> set = new HashSet<int>();
for (int i = arr.Length-1; i >= 0; i--)
{
if(set.Contains(arr[i]))
{
min=i;
element=arr[i];
}
else
{ set.Add(arr[i]);}
}
if (min == -1)
Console.WriteLine("No Repeating ELements!!!");
else
Console.WriteLine("Minimum repeating element" + element);
}
}
class Program
{
public static void Main_()
{
Reapting_elements a = new Reapting_elements();
int[] arr={3,4,5,1,3,1,10};
a.getfirstrepeatingelements(arr);
Console.ReadLine();
}
}
}
Comments
Post a Comment