Find the repeated value

Hello All,
I need support on the below scenario.
How to identify the repeated value among the input given… Eg, 1,2,3,4,4,5

Output should be 4.

Let’s say you have these numbers in a array {1,2,3,4,4,5} an int32 array named int_arr
may be like this
//where i is a int32 variable of default value 0
While(i < int_arr.length).
{
If (i +1 == int_arr.Length)
Then
{
}
Else
{
If ( int_arr(i) == int_arr(i + 1))
Then {
“Int_arr(i) is repeating”;
} else
{
}
i = i + 1;
}
}

Hope this would help you
Cheers @Kabeer

1 Like

Thanks Palaniyappan, How we need to implement in uipath. Which activity we need to use.

Fine like this
— create a variable of type int32 array with dafault values defined in the variable panel like
{1,2,3,4,4,5} and name it int_arr
— and create another variable of type int32 named i with default value 0 defined in the variable panel
— now use a while loop activity and mention the condition like
i < int_arr.Length
—Then inside the loop use a if condition like
i +1 = int_arr.Length
If the above condition passes it will go to THEN part where we can leave it empty and if the above condition fails it will go to ELSE part where we can have another if condition activity like this
int_arr(i) = int_arr(i + 1)
— now if this condition passes it will go to THEN part where we can use a write like activity and mention as
int_arr(i)+” is repeating”
— now next to the outer if condition (where we had a condition like i +1 = int_arr.Length), outside to this use a assign activity and mention like this
i = i + 1

Simple isn’t it
Hope this would help you
Kindly try this and let know for any queries or clarification
Cheers @Kabeer

1 Like

Thanks Palaniyappan, I will try and let you know.

1 Like

Yah sure
Kindly let know
Cheers @Kabeer

Hi @Kabeer

Just sharing here’s a forum related to your issue and also it has a created xaml for your reference…

cheers :smiley:

Happy learning :smiley:

1 Like

Hi @Kabeer

Also here just sharing some logic for your issue

  • First sort the array.
  • Then, foreach item: if it is equal to the next one then you have a duplicate (and you may show the message).

cheers :smiley:

Happy learning :smiley:

1 Like

@kabeer Iterating through and checking each value in a for each statement works, but if you are looking at a large set of data it will take a long time. Instead, you could utilize LINQ to accomplish the task in a more efficient manner all in a single assign activity.

Assign YourOutputVariable = OriginalArray.GroupBy(Function(x) x).Where(Function(y) y.Count() > 1).Select(Function(y) y.First)(0)

How this works is that it will select items in your array that occur more than once. HOWEVER, as it’s currently written it is just grabbing the first duplicate it finds. So in your example the output is 4. If there are multiple duplicates, then only the first item in the array that has a duplicate will be returned. Note that this can be tailored to whatever functionality you want, I’m just pointing out how it is currently working

1 Like