Skip to main content

MINIMUM DISTANCE BETWEEN TWO SIMILAR STRINGS

LATEST

  1. using System;
  2. using System.Linq;
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. int arrayLength;
  8. int T = Convert.ToInt32(Console.ReadLine());
  9. for(int i=0;i<T;i++)
  10. {
  11. arrayLength = Convert.ToInt32(Console.ReadLine());
  12. string Line = Console.ReadLine();
  13. GetMinimumDistanceBetweenStrings(arrayLength,Line);
  14. }
  15. }
  16. public static void GetMinimumDistanceBetweenStrings(int length,string Line)
  17. {
  18. int min = -1;
  19. int initial=0;
  20. string[] stringArray = Line.Split(" ");
  21. for(int start=0;start<length-1;start++)
  22. {
  23. for(int a=start+1;a<=length-1;a++)
  24. {
  25. if(stringArray[start]==stringArray[a])
  26. {
  27. if(initial==0)
  28. {
  29. min=a-start;
  30. initial++;
  31. }
  32. else
  33. {
  34. if((a-start)<min)
  35. {
  36. min=(a-start);
  37. }
  38. }
  39. }
  40. }
  41. }
  42. Console.WriteLine(min);
  43.  
  44. }
  45. }
Language: C#

Comments

Popular posts from this blog

Print word pattern - odd letters - beginner's code

1. Print the word with odd letters as P M R A O R G O R R A P M Solution: using System; public class Test { public static void Main() { string text = Console.ReadLine(); int n=text.Length; Pattern print = new Pattern (); print.XPattern(text,n); } } public class Pattern { public void XPattern(string text,int n) { char[] textarray = text.ToCharArray(); int reverseprinter = n-1; int middleLetter = n/2; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j && j!=middleLetter) { Console.Write(textarray[j]); } else if(j==reverseprinter) { Console.Write(textarray[reverseprinter]); reverseprinter--; } else { Console.Write("*"); } } Console.WriteLine(); } } } OUTPUT Please Enter text: INPUT : program p m r a o r g o r r a p m

GRANDSON PROBLEM

https://www.geeksforgeeks.org/zoho-interview-set-1-campus/ Given a two dimensional array of string like <”luke”, “shaw”> <”wayne”, “rooney”> <”rooney”, “ronaldo”> <”shaw”, “rooney”> Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2. SOLUTION using System; public class Test { public static void Main() { var noOfInputs = Console.ReadLine(); int noOfInputLines = Convert.ToInt32(noOfInputs); string[,] FatherSonArray= new String[noOfInputLines,noOfInputLines]; for(int father=0;father<noOfInputLines;father++) { for(int son=0;son<2;son++) { FatherSonArray[father,son] = Console.ReadLine(); } }     Console.WriteLine("No of grandchildrens:");     string GrandFather = Console.ReadLine();     int NoOfGrandSons=0;     Console.Wr...

BEGINNER's ALPHABET PALINDROME

PRINT ALPHABET PALINDROMIC PYRAMID USING C# using System; public class Test {       public static void Main()       {             var number = Console.ReadLine();             int n = Convert.ToInt32(number);             Pattern print = new Pattern();             print.PrintPalindromePattern(n);       } } public class Pattern {       public void PrintPalindromePattern(int n)       {             int dummy = 1;             char letter = 'A';             int reversep...