Amazon Interview Question: You have been given an matrix... | Glassdoor

Interview Question

Software Development Engineer Intern Interview(Student Candidate) Gainesville, FL

You have been given an matrix of characters 5*5 which

  contains 24 elements a..y the matrix will look something like a b c d e f g h i j k l m n o p q r s t u v w x y You have been given alpha (starting character) and beta (Ending character) as two characters. You have to find all shortest paths between alpha and beta with a restriction that you are allowed to move vertical or horizontal.
Answer

Interview Answer

1 Answer

0

#include
#include

int main(int argc, char *argv[]) {
    char array[5][5];
    int i=0,j=0;
    char path[9]={'0'};
    char element='a';
    char source,destination;
    for(i=0;isc)
    {
        for(i=sc;i=dc;i--)
        {
        path[j]=array[sr][i];
        j++;
        }

    }

        if(dr>sr)
    {
        for(i=sr+1;i=dr;i--)
        {
        path[j]=array[i][dr];
        j++;
        }

    }
    printf("\n*********************Path************************\n");
    for(i=0;i<8;i++)
    {
        printf("%c ",path[i]);
    }
    return 0;
}

Anonymous on Jan 27, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.