rajesh puppala
 

 

2.  Find Path

Problem Description

Sam is a tourist, One day he plans to go one country where there are N cities and each pair of city is connected to each other by a bidirectional road.
Sam want to visit each city exactly once and he wants to start in one city and end in another city after traveling exactly N-1 roads.
You have given a String[] path. If the j-th column of the i-th row of paths is '1', he must travel the road that connects city i and city j.


 

Suppose there are three cities(A,B,C), and Sam want to travel path between city A to city C. So there are 6 possible paths P(3,2)=6.
For this example String[]path is {"001","000","100"}
But only 4 paths allowed for Sam that are (B->A->C),(A->C->B),(B->C->A),(C->A->B) and paths( A->B->C) and (C->B->A) are not allowed because path A->C or C->A is not covered.

So you have to find the possible paths where String[] path is given..

Instructions to use Open PBT Client:

  1. Specify the work directory path in the 'Work Directory Path' field. The path should correspond to your solution work directory.
  2. Download the Support files by clicking the Get Support Files

.

  1. You will find the problem directories containing:
    • problem.h file
    • problem.c file

in your work directory.

  1. Write your solution in .c file

Step 1:

In your Solution File:

  1. Add Function int countPaths(char** paths)

Step 2:

  1. Pass the following parameter to the function countPaths()
    path is a character pointer represents the path in a matrix format as mentioned in the problem description.

Step 3:

Write the appropriate code as mentioned in the problem description by following the below given Constraints.

  1. The input should be the character array for the method, which basically shows an nxn matrix for the desired garph (The connected Cities)
  2. This matrix shows which path Sam have to travel.
  3. You need to figure out the number of possible paths which covers the path that Sam have to travel.
  4. Your method should return the number of possible paths.
  5. If the char** paths is null then your method should return -1.

The prototype of the function is:

int countPaths(char** paths)
Function will take a character pointer which is the representaion of the paths and return the feasible number of paths.

Constraint:

  • If the given path is null then return -1 ..

Example 1

Input:
{"001","000","100"}

Output:
         4

Example 2

Input:
{"000","100","000"}

Output:
         0

Explanation:There is no path which is satisfying the above condition.

For C solutions

Header File       :

FindPaths.h

File Name         :

FindPaths.c

Function Name  :

int countPaths(char** paths);

 

For C++ solutions

Header File

:

FindPaths.h

Class Name

:

FindPaths

Function Name

:

int countPaths(char** paths);

FileName

:

FindPaths.cpp

 

General Instructions

    *

The file / class names, functions, method signatures, header files to be used are mentioned in the problem statement. Do not use your own names or change the method signatures and fields. You can add any number of additional methods.

    *

Do not forget to mention the file extension, either .c or .cpp as the case maybe.

    *

For C solutions, change the value of "C_OR_CPP" macro in header file to 1 and for C++ solutions change the value to 2.

    *

Incase of iostream.h specify as iostream only.

 

 

 

Rajesh
7306947200
pedana
krishna dt

JOKES CORNER:
Some Good "Poor Jokes"...
Here are some really bad pj's...Read on if u like some...


Lion Roaring...
what happens when the lion roars???
...
TOM & JERRY Begins......



Hights of Optimism:r
Soldier: "Sir we are surrounded by enemies on all sides!!!"
Sardar Major" Excellent!!! we can attack in any direction"



Flirt like this
What is the height of Flirting?
Its When your love letter starts with "TO WHOMSOEVER IT MAY CONCERN"
..
BRILLIANT WAYS GIRLS TURN GUYS DOWN!!
HE: I'm a photographer I've been looking for a face like yours!
SHE: I'm a plastic surgeon. I've been looking for a face like yours!!!
HE: May I have the pleasure of this dance?
SHE: No, I'd like to have some pleasure too!!!

the sardar...
Q: Why did the Sardar take a pair binoculars with him to a funeral?
A: It was a distant relative's funeral.

gabbbar...
Gabber: Kitne Aadmi they.
Sambha: Sardar Do,
Gabber: Mujhe ginti nahi aati. Do kitne hotey hain?
Sambha: Sardar Do Ek ke baad aata hai.
Gabber : Aur Do ke pehle?
Sambha: Do ke pehle Ek aata hai.
Gabber: To beech mein kaun aata hai?
Sambha: Beech mein koi nahi aata.
Gabber: To fir Dono ek saath kyon nahi atey?
Sambha: Do Ek ke baad hi aa sakta hai, kyonki Do ek se bada hai.
Gabber: Do ek se bada hai? Kitna bada hai?
Sambha Do ek se Ek bada hai?
Gabber: Agar Do ek se ek bada hai to ek ek se kitna bada hai?
Sambha: Sardar, Maine tumhara namak khaya hai, mujhe goli mar do

ek ladki...
A Lady is standing up on top of the hill and she is going to push her Father down from the hill top.....
SO what is the name of this lady ???
... Well her Name is PUSH-PA!!!!!!!!!!

HE: How did you get to be so beautiful?
SHE: I must have been given your share!!!
HE: Will you come out with me this Saturday?
SHE: Sorry! I'm having a headache this weekend!!!
HE: Go on, don't be shy. Ask me out!
SHE: Okay, get out!!!
HE: I think I could make you very happy
SHE: Why? Are you leaving?
HE: What would you say if I asked u to marry me?
SHE: Nothing. I can't talk and laugh at the same time!!!
HE: Can I have your name?
SHE: Why, don't you already have one?
HE: Shall we go and see a film?
SHE: I've already seen it!!!
HE: Do you think it was fate that brought us together?
SHE: Nah, it was plain bad luck!!!
Today, there have been 1 visitors (14 hits) on this page!
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free