1. bobisto@ private static long Contest9(string sequence) { long maxDiff = 0; System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] bytes = encoding.GetBytes(sequence); for (long i = 0; i < bytes.Length - 1; i++) { if ((bytes.Length - maxDiff - i - 1) == 0) break; for (long j = bytes.Length - 1; j > i; j--) { long diff = j - i - 1; if ((diff - maxDiff) == 0) break; if (bytes[i] == bytes[j] && (diff > maxDiff)) maxDiff = diff; } } return maxDiff; } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 15694541 ------------------------------------------------------------------ 2. wstrege@   public static long Contest9(String sequence)         {             String banned = "";             long str_length = sequence.Length;             long distance=0;             long biggest_distance = 0;             long window = 10000000000000000;             for(int i = 0 ; i < str_length && biggest_distance < window; i++)             {                 window = str_length - i - 2;                 char[] my_char= {sequence[i]};                 //check to see if letter used                 if(banned.IndexOfAny(my_char)<0)                 {                     banned+=sequence[i];                     distance = (long)sequence.LastIndexOfAny(my_char) - i;                     if(distance > biggest_distance)                     {                         biggest_distance = distance-1;                     }                 }             }             return biggest_distance;         } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 6518 ------------------------------------------------------------------ 3.lateef@    public static long Contest9(String sequence)         {                 int[] AscArr=new int [10];                 int[] DescArr=new int [10];                                  for(int i=0;i<10;i++)                 {                         AscArr[i]=-1;                         DescArr[i]=-1;                 }                                                   // fill the ASCARR                 initialize();                 for(int i=0;i=0 ;i--)                 {                         if(!checkArr(DescArr,int.Parse (sequence[i].ToString ())))                         {                                 DescArr[int.Parse (sequence[i]. ToString ())]=i;                         }                 }                 // Find all the difference                 int max=0;                 for(int i=0;i<10;i++)                 {                         if((DescArr[i]-AscArr[i])>max)                                 max=DescArr[i]-AscArr[i]-1;                 }                 // Report the maximum                 return max;                          }                  public static bool checkArr(int[] AscArr,int valuee)         {                 if(AscArr[valuee]==-1)                         return false;                 else                         return true;         } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 138100 ------------------------------------------------------------------ 4. sean@ public static long Contest9 (String sequence) { const int asciiZero = (int)'0' ; const int asciiNine = (int)'9' ; int i ; int symbol ; long distance ; long longestDistance = 0 ; long count = sequence.Length ; long [] first = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } ; long [] last = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } ; // Mark the start and end of the segments for (i = 0; i < count; i++) { symbol = (int)sequence[i] ; if (first[symbol] == -1) { first[symbol] = i ; } else { last[symbol] = i ; } } // Find the longest segment for (i = asciiZero; i <= asciiNine; i++) { if ((first[i] != -1) && (last[i] != -1)) { distance = last[i] - first[i] - 1 ; if (distance > longestDistance) { longestDistance = distance ; } } } return (longestDistance) ; } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 2411 ------------------------------------------------------------------ 5. rhuno@ public static long Contest9(String sequence) { Console.Write("Greatest Distance = "); // if the numbers are all the same, or the first and last are ==, answer = length - 2 if ( CompareStr(sequence) == true || sequence[0] == sequence[sequence.Length - 1]) { if (sequence.Length > 1) { Console.WriteLine(sequence.Length - 2); } else { Console.WriteLine("0"); } return -1; } int hi = 0; // select each digit in the string, and look for a matching digit // when/if found, compare the distance count to the current hi and // swap if necessary for( int z = 0; z < sequence.Length; z++ ) { int digit = sequence[z]; int count = 0; for( int a = z+1; a < sequence.Length; a++ ) { if( sequence[a] != digit ) { count+=1; } else if( digit == sequence[a] ) { if (count > hi) { hi = count; } count = 0; } } } Console.WriteLine(hi); return hi; } //************************* //* CompareStr( String str ) //* helper function, determine if string is composed of the all the same number //* assume are all the same, if we loop thru and find something diff, break and //* return false! //********************************************************************************* private static bool CompareStr(String str) { bool allSame = true; for( int loop = 0; loop < str.Length-1; loop++ ) { if (str[loop] != str[loop + 1]) { allSame = false; break; } } return allSame; } Your function writes in the console. As per the contest rules, your function shall return the result, and not write anything in the console! ------------------------------------------------------------------ 6. raistmaj@ public static long Contest9(String sequence)         {             int longitud = sequence.Length;             long maxL = 0;             // busco los numeros distintos             int posUno = sequence.IndexOf('0');             int posDis = sequence.LastIndexOf('0');             long currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('1');             posDis = sequence.LastIndexOf('1');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('2');             posDis = sequence.LastIndexOf('2');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('3');             posDis = sequence.LastIndexOf('3');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('4');             posDis = sequence.LastIndexOf('4');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('5');             posDis = sequence.LastIndexOf('5');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('6');             posDis = sequence.LastIndexOf('6');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('7');             posDis = sequence.LastIndexOf('7');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('8');             posDis = sequence.LastIndexOf('8');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             posUno = sequence.IndexOf('9');             posDis = sequence.LastIndexOf('9');             currDis = posDis - posUno;             if (currDis > maxL) { maxL = currDis; if (maxL == longitud - 1) return longitud - 2; };             return maxL - 1;         } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 4587 ------------------------------------------------------------------ 7. p_kalkoti@ /* This a program to find distance between equal numbers. first starting and final positions will be identified and then dist will be calculated*/ #include main () { int i,n,p=0,end,start,dist=0,k=0; char str[20],ch,temp; clrscr(); printf ("enter n\n"); scanf ("%d",&n); printf ("Enter \n"); for (i=0;i distancias[Int32.Parse(sequence[i].ToString())] && sequence.LastIndexOf(sequence[i])!=i) distancias[Int32.Parse(sequence[i].ToString())] = sequence.LastIndexOf(sequence[i]) - i; } } int max=distancias[0]; int t=0; for(int j=1;jmax) { max=distancias[j]; t = j; } } return max-1; } Test 1: passed Test 2: failed. Your result:15449, True result:15560 Test 3: passed Test 4: passed Total cycles : 4655792 ------------------------------------------------------------------ 9. akusei.x@ // Author:    Nathan Martini // Date:    09/06/06 public static long Contest9(string sequence) {     int longest = -1;     int start = sequence.Length - 1;     for (int i = start; i >= 0; i--)     {         longest = sequence.IndexOf(sequence[i], 0, i);         if (longest > -1)             break;     }     return longest; } Test 1: failed. Your result:0, True result:11550 Test 2: failed. Your result:26, True result:15560 Test 3: failed. Your result: 23104,True result:11550 Test 4: failed. Your result: 0,True result:1 Total cycles : 0 ------------------------------------------------------------------ 10. Kambiz.Veshgini@ public static long Contest9(String sequence) { int l = sequence.Length; int d = l-1; do{ for (int i = 0; ( i + d) < l; i++) if (sequence[i] == sequence[i+d]) return (long)(d - 1); d--; }while(true); } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 6387298 ------------------------------------------------------------------ 11. fencer04@ public static long Contest9(String sequence)         {             long distance = 0;             char[] array = sequence.ToCharArray();             for (int count1 = 0; count1 < array.Length; count1++)             {                 if (distance >= array.Length - count1) break;                 for (int count2 = count1; count2 < array.Length; count2++)                 {                     if (array[count1] == array[count2])                     {                         if ((count2 - count1) > distance)                         {                             distance = count2 - count1;                         }                     }                 }             }             return distance - 1;         } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 7247848 ------------------------------------------------------------------ 12. jorgegaona@ public static long Contest9(String sequence){                         String digit = "", maxdigit ="" ;                         long maxdistance = 0, currdistance;                         int posFirst , posLast , maxposFirst = 0, maxposLast = 0;                                                  Console.WriteLine(sequence);                         for(int i=0; i < sequence.Length; i++){                                                                  digit = sequence.Substring(i,1) ;                                 posFirst = sequence.IndexOf(digit);                                 posLast = sequence.LastIndexOf(digit);                                 if(                                         posFirst == i //check if it's the first occurence of the digit                                         &                                         posLast >i //check the last occurence of the same digit                                                                                                  //(that must exist at least twice) to show the distance                                                                                                 // between them                                 ){                                         currdistance = posLast - posFirst - 1;                                                                                  if(maxdistance < currdistance){ // checks if these digits have the longest distance                                                                                                         // between them                                                 maxdistance = currdistance;                                                 maxdigit = digit;                                                 maxposFirst = posFirst;                                                 maxposLast = posLast;                                         }// if maxdistance                                                                          }// if indexOf's                                                          }// end for                         Console.WriteLine("\nThe longest distance is between the '"+ maxdigit +"' in position " +                                                                 (maxposFirst + 1).ToString() + " and the '"+ maxdigit +"' in position " +                                                                 (maxposLast + 1).ToString() +  ", with a distance of "+ maxdistance.ToString() +                                                                 " digits");                         return maxdistance;                 }// end function Your function does not meet the contest requirements to return a result and not write anything in the console! After I removed the lines where you write in the console, your function didn't finish in 1 minute. ------------------------------------------------------------------ 13. jc95418@ public static int Contest9(string str) { int Prev_Best_Distance = 0; int Best_Distance = 0; int Range = 0; for (int i = 0; i < str.Length - 2; i++) { if ((Range = str.LastIndexOf(str[i]) - str.IndexOf(str[i])) == 0) continue; Prev_Best_Distance = --Range; if (Best_Distance < Prev_Best_Distance) Best_Distance = Prev_Best_Distance; if (str.Length - 2 - i <= Best_Distance) break; } return Best_Distance; } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 4042890 ------------------------------------------------------------------ 14.dustbunnny@ public static long Contest9(String sequence) {     //Determine the sequence bounds     int iSequenceLength = sequence.Length;     //Position iX to work up from the start of the string     for(int iX = 0; iX <= iSequenceLength - 1;iX++)     {         //compare from right to left one character at a time         //exiting with the difference value if there is a match         for(int iY = iSequenceLength - 1; iY > iX ;iY--)         {             if (sequence[iY] == sequence[iX])             {                 return iY - iX - 1;             }         }     }      //Return condition when there is only one character      //of each type in the string (0 distance)      return 0; } Test 1: passed Test 2: failed. Your result:15449, True result:15560 Test 3: passed Test 4: passed Total cycles : 513 ------------------------------------------------------------------ 15. dvhh@     public static long Contest9(String sequence)                 {                         int l=sequence.Length;                         int[] begin=new int[10];                         int[] end;                         int z='0';                         char[] s=sequence.ToCharArray();                         int i;                         for(i=0;i largestdistance ; j--)//While distance is longer than current record                         {                         if (chars[j] == c) //Match                         {                             largestdistance = j - i;                             break;                         }                     }                     //Add char to usedchars, never check that char again                     usedchars[usedcharcount] = c;                     usedcharcount++;                     if (usedcharcount == 10) return largestdistance - 1; //All digits have been checked.                 }                         }             return largestdistance - 1;         } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 2485 ------------------------------------------------------------------ 17.christian.schulze.berlin@ public static long Contest9(String sequence)         {             int[] lused = new int[10];             int[] rused = new int[10];             for (int i = 0; ; i++)             {                 if (rused[sequence[i] - '0'] > 0)                 {                     return sequence.Length - i - 1 - rused[sequence[i] - '0'];                 }                 else if (lused[sequence[i] - '0'] <= 0)                 {                     lused[sequence[i]-'0'] = i + 1;                 }                 if (lused[sequence[sequence.Length - i - 1] - '0'] > 0)                 {                     return sequence.Length - lused[sequence[sequence.Length - i - 1] - '0'] - i - 1;                 }                 else if (rused[sequence[sequence.Length - i - 1] - '0'] <= 0)                 {                     rused[sequence[sequence.Length - i - 1] - '0'] = i + 1;                 }             }             return 0;         } Test 1: passed Test 2: failed. Your result:15537, True result:15560 Test 3: passed Test 4: passed Total cycles : 984 ------------------------------------------------------------------ 18. bulareanuadrian@     public static long Contest9(String sequence)   {   int i, y;   long maxd,max;   maxd = 0;   max = 0;   for (i = 0; i < sequence.Length-1; i++)   {   for (y = sequence.Length-1; y > i; y--)   {     if (sequence[i] == sequence[y])   {   maxd = y - i - 1;   if (maxd > max)   {   max = maxd;   }   if (max >= sequence.Length - 3)   {   return max;   }   }   }   }   return max;   } Your function didn't finish in 1 minute. ------------------------------------------------------------------ 19. binupdm@ //Done by Binu Prasad.M public static long Contest9(String sequence)                 {                         int maxLength=0,strLength=sequence.Length-1;                         int maxPos=strLength;                         for(int i=0; i maxLength))                                         {                                                 maxLength=j-k-1;                                                 break;                                         }                                         k++;                                 }                                 maxPos--;                                 if(maxLength>0)break;                         }                         return(maxLength);                 } Your function didn't finish in 1 minute. ------------------------------------------------------------------ 20.barryokonoboh@ public static long Contest9( String sequence ) {    long distance = 0;    long tempDistance = 0;    for( long count = 48; count < 58; count++ )    {       tempDistance = sequence.LastIndexOf( ( char )count ) -                      sequence.IndexOf( ( char )count );       distance = distance > tempDistance ? distance : tempDistance;    }    return distance - 1; } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 6038 ------------------------------------------------------------------ 21.hamburger1984@ public static long Contest9(String sequence) {     int distance = 0;     for (int i = 0; i < sequence.Length - 2; i++)     {         for (int j = sequence.Length-1; j >= i + 2; j--)         {             if (sequence[i] == sequence[j] )                 if (distance < j - i - 1)                     distance = j - i - 1;             if(distance>=j-i-1)                 break;         }         if(distance>sequence.Length-i)             break;     }     return distance; } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 6380848 ------------------------------------------------------------------ 22.ranandbe@ public static void Contest9(String sequence)   {   int len=sequence.Length+1;   string[] digit=new string[len];   string[] pos=new string[len];   int[] dist=new int[len];   int sum=0;   int cnt=0;   int dum=0;   for(int i=0;i max) max = diff; } /* Return the distance , With this algorithm also the digit that has the longest distance can return */ return max-1; } } } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 2529 ------------------------------------------------------------------ 24.alexandru.clontea@ public static long Contest9(string sequence) { // comment! string does not accept a "long" indexer!!! it must be int. int digit; long[] minX = new long[10]; long[] maxX = new long[10]; long max=0; for (int ii = 0; ii < 10; ii++) { minX[ii] = 4294967296; maxX[ii] = -1; } for (int j = 0; j < sequence.Length; j++) { digit = (int)(sequence[j] - '0'); if (j < minX[digit]) minX[digit] = j; if (j > maxX[digit]) maxX[digit] = j; if (maxX[digit]>-1) if (max < maxX[digit] - minX[digit]) max = maxX[digit] - minX[digit]; } return (max>0)?max-1:0; } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 4955 ------------------------------------------------------------------ 25.kde_x2003@ public static long Contest9(String sequence)   {   // We change the string into array character for easier codes   char[] arrayChar = sequence.ToCharArray();   // For storing results   long result = -1;   Boolean found = false;   long temp = arrayChar.Length;   long limit = -1;   // We take the last character as a reference, search the same occurence from the first value   // If same occurence found, record the x position, if not then reduce the last character to the one in front of it   do   {   temp--;   char lastChar = arrayChar[temp];   for (long x = 0; x < temp; x++)   {   if (arrayChar[x] == lastChar)   {   found = true;   result = (temp - x)-1;   limit = x;   x = temp;   }   }   } while (!found);   // Now we know that we do not care with the one above the x position that we found before   // As the maximum distance would be the result that we found before or results coming from value behind the x position   // So we set the x position as limit and do for loop only for those below the limit   for (long x = 0; x < limit; x++)   {   for (long y = arrayChar.Length - 1; y > x; y--)   {   if (arrayChar[x] == arrayChar[y])   {   result = Math.Max(result, (y - x)-1);   }   }   }   return result;   } Your function did not finish in 1 minutes. ------------------------------------------------------------------ 26.abi.bellamkonda@ public class Contest { private const int N = 10; public static long Contest9(string sequence) { int m = 0; int t = 0; char c; int n = sequence.Length-1; for (int i = 0; i < N; i++) { c = (char)('0' + i); t = sequence.LastIndexOf(c) - sequence.IndexOf(c); m = (t > m) ? t : m; } return m-1; } } Test 1: passed Test 2: passed Test 3: passed Test 4: passed Total cycles : 6008 ------------------------------------------------------------------