Create a function that takes two integers and returns if
- In first input number a digit repeats three times in a row at any place AND
- that same digit repeats two times in a row in second input number
Example-1 :
Input 1 - 451999277
Input 2 - 41177722899
Output - True
Example-2 :
Input 1 -1222345
Input 2 - 123456
Output - False
Example-3 :
Input 1 - 666789
Input 2 - 123456678
Output - True
I have tried coding this but not getting proper output:
using System;
public class Test
{
private static void Main(string[] args)
{
Int64 Input1 = 41177722899, Input2 = 451999277;
Console.WriteLine("Input 1 - " + Input1);
Console.WriteLine("Input 2 - " + Input2);
Console.WriteLine("Output - " + getResult(Input1, Input2));
}
static bool getResult(Int64 n1, Int64 n2)
{
int res1 = 0;
int[] cnt1 = new int[10];
while (n1 > 0)
{
int rem = (int)(n1 % 10);
cnt1[rem]++;
n1 = n1 / 10;
}
for (int i = 0; i < 10; i++)
{
if (cnt1[i] == 3)
{
res1 = i;
}
}
int res2 = 0;
int[] cnt2 = new int[10];
while (n2 > 0)
{
int rem = (int)(n2 % 10);
cnt2[rem]++;
n2 = n2 / 10;
}
for (int i = 0; i < 10; i++)
{
if (cnt2[i] == 2)
{
res2 = i;
}
}
if ((res1 != 0 && res2 != 0) && (res1 == res2))
{
return true;
}
else
{
return false;
}
}
}