Skip to main content

Zoho Interview | Set 1 Question 3

Save the string “WELCOMETOZOHOCORPORATION” in a two dimensional array and search for substring like “too” in the two dimensional string both from left to right and from top to bottom.

w e L C O
M E T O Z
O H O C O
R P O R A
T I O n 
 
 
And print the start and ending index as
Start index : <1,2>
End index: <3, 2>



My Solution ::

#include <stdio.h>
main()
{
    char *c="welcometozohocorporation";
    char array[5][5];
    int x;
    int y;
    int i=0;
     for(x=0;x<5;x++)
  {
      for(y=0;y<5;y++)
      { array[x][y]=c[i]; //intialising the characters of string to the 2d array  
      i++;
     }}
     for(x=0;x<5;x++)
  {
      for(y=0;y<5;y++)
      {
   printf("array[%d][%d]=%c\n",x,y,array[x][y]);//printing the 2d array to make sure that it has been initialised with the string characters
      }
  }
  for(x=0;x<5;x++)
  {
      for(y=0;y<5;y++)
                 {
                 //check for left to right existence  
                 if((array[x][y]=='t')&&(array[x][y+1]=='o')&&(array[x][y+2]=='o'))
      {
      printf("it starts at %d,%d",x,y);
      printf("\n");
      printf("it ends at %d,%d",x,y+2);
      }
      printf("\n");
                    //check for top to bottom existence
      if((array[x][y]=='t')&&(array[x+1][y]=='o')&&(array[x+2][y]=='o'))
      {
      printf("it starts at %d,%d",x,y);
      printf("\n");
      printf("it ends at %d,%d",x+2,y);
      }
      }}

}

Comments

Post a Comment

Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

Zoho Puzzle Questions With Answers

Measuring Time Logic Puzzle You are given with two ropes with variable width. However if we start burning both the ropes, they will burn at exactly same time i.e. an hour. The ropes are non-homogeneous in nature. You are asked to measure 45 minutes by using these two ropes.

How can you do it?

Please note that you can’t break the rope in half as it is being clearly stated that the ropes are non-homogeneous in nature.
Answer & Explanation Solution: 45 minutes

Explanation :
All you have to do is burn the first rope from both the ends and the second rope from one end only simultaneously. The first rope will burn in 30 minutes (half of an hour since we burned from both sides) while the other rope would have burnt half. At this moment, light the second rope from the other end as well. Where, the second rope would have taken half an hour more to burn completely, it will take just 15 minutes as we have lit it from the other end too.

Thus you have successfully calculated 30+15 = 45 minutes …

Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as