andrewgilmartin

andrewgilmartin / interview1 / 0.1.3

README.md

Overview

The algorithm sums the reward values found in a graph. Each node in the graph contains the reward value and a list of child nodes.

Usage

Input

The algorithm is given a URL referencing a node in the graph. Getting the URL must respond with a JSON encoded object with "children" and "reward" properties. The children are an array of URL references to other nodes. The reward is a numeric double.

For example, the URL

http://algo.work/interview/a

might return the JSON

{
  "children": [ 
	  "http://algo.work/interview/b",
	  "http://algo.work/interview/c"
  ],
  "reward": 1
}

It is not an error if the graph repeats child nodes, but it is an error if the graph is cyclic. A repeated child node is one where a node is referenced as a child of two or more parent nodes.

Output

The output is a single numeric double representing the sum of the rewards of all the nodes in the graph rooted at the given URL node reference.

Examples

For example, in the following replace the APIKEY with your API key (starts with "sim")

curl \
  -X POST \
  -d '"http://algo.work/interview/a"' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Simple APIKEY' \
	  'https://api.algorithmia.com/v1/algo/andrewgilmartin/interview1?timeout=300'