Skip to content

wamaithaNyamu/graphTestProductiveSoftware

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn

Task

The system should support the following :

  • Given a transition, the system will know which status is the next one
  • Given a transition , and bulk of statuses : the system will find the correct path to the next status of the given transition . a. For example : given a transition [R,A,S] with array of statuses [ 4 , 5 , 2 ]

Design of the solution

Case 1:

exampleInput = {
  "transition":"['S', 'A', 'S']",	     
  "statuses":"['1', '2', '3']"	
}

Given a transition and a bulk of statuses the system :

  • The system assigns the current value as the last element of the statuses array.
  • The destination is the first value in the statuses array.
  • Keep track of the visited nodes and push to the visited array whenever we generate the next value
  • If the next value is a single value:
    • The next value of the status is retreived from the adjacency list
    • The transition string is derived from joining the current and the next
    • Current value is overwritten with next and the cycle continues until the next value is equal to the destination value
  • If the next value is an array and is not yet visited
    • Run a depth first search recursively and return the transition array of arrays and the visited set.
    • Return the shortest transition from the step above since the system seeks to find the shortest path to the destination
  • If the next value is visited continue with the loop

Case 2:

When given only a transition, the system should return the shortest path from the start of the transition

exampleInput = {
  "transition":"['S', 'A', 'S']",	     

}

In this case:

  • system returns all possible edges with the transition
  • Performs all the steps in case one ablove
  • Returns the edge with the shortest path

Built With

(back to top)

Getting Started

To run this project ensure you have nodejs installed on your system Find instructions on the Node.js documentation

Installation

  1. Clone the repo

    git clone https://github.com/wamaithanyamu/graphTestProductiveSoftware.git
  2. Navigate to the project foldler

    cd graphTestProductiveSoftware
  3. Install NPM packages

    npm install
  4. Run server

    npm run start:dev

(back to top)

Usage

You can test the endpoint using postman as shown below

License

Distributed under the MIT License. See LICENSE.txt for more information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published