Skip to main content

Posts

Showing posts from 2019

Seating Arrangement

Akash  and  Vishal  are quite fond of travelling. They mostly travel by railways. They were travelling in a train one day and they got interested in the seating arrangement of their compartment. The compartment looked something like So they got interested to know the seat number facing them and the seat type facing them. The seats are denoted as follows : Window Seat :  WS Middle Seat :  MS Aisle Seat :  AS You will be given a seat number, find out the seat number facing you and the seat type, i.e.  WS ,  MS  or  AS . INPUT First line of input will consist of a single integer  T  denoting number of test-cases. Each test-case consists of a single integer  N  denoting the seat-number. OUTPUT For each test case, print the facing seat-number and the seat-type, separated by a single space in a new line. CONSTRAINTS 1<= T <=10 5 1<= N <=108 SAMPLE INPUT   2 18 40 SAMPLE OUTPUT   19 WS 45 A SOLUTION using

MINIMUM DISTANCE BETWEEN TWO SIMILAR STRINGS

LATEST using System ; using System . Linq ; public class Test { public static void Main () { int arrayLength ; int T = Convert . ToInt32 ( Console . ReadLine ()); for ( int i = 0 ; i < T ; i ++) { arrayLength = Convert . ToInt32 ( Console . ReadLine ()); string Line = Console . ReadLine (); GetMinimumDistanceBetweenStrings ( arrayLength , Line ); } } public static void GetMinimumDistanceBetweenStrings ( int length , string Line ) { int min = - 1 ; int initial = 0 ; string [] stringArray = Line . Split ( " " ); for ( int start = 0 ; start < length - 1 ; start ++) { for ( int a = start + 1 ; a <= length - 1 ; a ++) { if ( stringArray [ start ]== stringArray [ a ]) { if ( initial == 0 )

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.WriteLine(GrandFather);     s

CHARACTER OR VOWEL

LATEST using System; public class Test { public static void Main() {       var Letter = Console.ReadLine();       char c = char.Parse(Letter);       if(CheckIfCharacterisVowel(c))       {          Console.WriteLine("YES");       }       else       {       Console.WriteLine("NO");       } } public static bool CheckIfCharacterisVowel(char c) { if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'|| c=='a'||c=='e'||c=='i'||c=='o'||c=='u') { return true; } return false; } }

NQUEEN's PROBLEM

using System; public class GFG { static int n; static public void Main () { var TC = Console.ReadLine(); int T = Convert.ToInt32(TC); for(int a=0;a<T;a++) {     var no= Console.ReadLine();      n = Convert.ToInt32(no);     int [,]board =  new int [n,n];     InitializeBoardWithZeros(board,n,n);     SolveNQueen(board,0);     PrintBoard(board,n,n); } } static public void InitializeBoardWithZeros(int [,]board,int row,int col) {     for(int i=0;i<col;i++)     {         for(int j=0;j<row;j++)         {             board[i,j]=0;         }     }     } static public void PrintBoard(int [,]board,int row,int col) { for(int i=0;i<col;i++)     {         for(int j=0;j<row;j++)         {             Console.Write(" {0}",board[i,j]);         }         Console.WriteLine();     }      Console.WriteLine(); } static public bool SolveNQueen(int[,]board,int col) { if(col>=n) retu

BEGINNER's Palindromic pattern with number and stars

PRINT A PALINDROME WITH NUMBERS AND STARS APPROACH The same flag can be set to 0 and 1 simultaneously to print * and the Ith iteration number continuously inside the triangle. The same logic used in the previous problem is used here to create a triangle pattern. SOLUTION : using System; public class Test {           public static void Main()           {                    var number = Console.ReadLine();                    int n = Convert.ToInt32(number);                    Pattern print = new Pattern();                    print.StarNumberPyramid(n);           } } public class Pattern {           public void StarNumberPyramid(int n)           {                    int TotalNumberOfLetters = n*2+1;                    int leftTriangleCreater = n+1;                    int rightTriangleCreater = leftTriangleCreater;                    int innerNumber=0;                    for(int i=1;i<=n;i++)                    {                              fo

BEGINNER's TRICKY NUMBER FULL PYRAMID

                             PRINT A NUMBER PYRAMID AS MENTIONED BELOW : APPROACH The whole pyramid structure can be written in a single nested for loop instead of many separate loops A single nested for loop is used along with two flags that help in creating the pyramid structure.One flag moves towards left by 1 and the other to the right by 1. If the iteration is at the boundary of the triangle ( leftTriangleCreater, rightTriangleCreater)  , those can print the Ith Iteration value While loop can be used to control the values on the left and right. In the left , The while loop iterates till secondelement != middleNumber In the right, The while loop iterates till rightsecondElement > i SOLUTION using System; public class Test { public static void Main() {   var number = Console.ReadLine();   int n = Convert.ToInt32(number);   Pattern print = new Pattern();   print.NumberPyramid(n); } } public class Pattern { public vo

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 reversepalindrome;             char letteraftereachIteration ='A';             char reverseletter ='A';             for(int i=1;i<=n;i++)             {                     reversepalindrome = i-1;                   for(int j=1;j<=dummy;j++)                   {                         if(j<=i)                         {                         Console.Write(letter++);                         }                         else                         {                     

BEGINNER's PALINDROMIC NUMBER PYRAMID

LATEST PRINT A PALINDROME NUMBER PYRAMID AS SHOWN BELOW 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;             int reversepalindrome;             for(int i=1;i<=n;i++)             {                     reversepalindrome = i-1;                   for(int j=1;j<=dummy;j++)                   {                         if(j<=i)                         {                         Console.Write(j);                         }                         else                         {                               while(reversepalindrome!=0)                               {                               Console.Write(reversepali

BEGINNER's FULL NUMBER PYRAMID

using System; public class Test { public static void Main() { var no = Console.ReadLine(); int n = Convert.ToInt32(no); Pattern print = new Pattern(); print.Pyramid(n); } } public class Pattern { public  void Pyramid(int n) { int m = n*2; int left = n; int right = n; int dummy=1; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(j<left || j>right) { Console.Write(" "); } else { if(j==left && i!=n) { Console.Write("1"); } else if(j==right && i!=n) { Console.Write(i); } else if(i==n && dummy<=n) { Console.Write("{0} ",dummy); dummy++; } else { Console.Write(" "); } } } left--; right++; Console.WriteLine(); } } } INPUT : 5 OUTPUT: 1 1 2 1 3 1 4 1 2 3 4 5

Beginner's BUTTERFLY PATTERN

PRINT BUTTERFLY PATTERN USING C# using System; public class Test { public static void Main() { var no = Console.ReadLine(); int n = Convert.ToInt32(no); Pattern print = new Pattern(); print.Butterfly(n); } } public class Pattern { public void Butterfly(int n) {   int totalNoofStars = n*2;   int lefttriangle = 1;   int righttriangle = totalNoofStars;   for(int i=1;i<=totalNoofStars;i++)   {   if(i<=n)   {   lefttriangle++;   righttriangle--;   }   else   {    if(i==n+1)   {   lefttriangle= lefttriangle;   righttriangle = righttriangle;   }   else   {   lefttriangle--;   righttriangle++;   }   }   for(int j=1;j<=totalNoofStars;j++)   {   if(j<lefttriangle || j> righttriangle)   {   Console.Write("*");   }   else   {   Console.Write(" ");   }   }   Console.WriteL