Question: C# We are tracking down our rogue agent and she travels from place to place to avoid being tracked. Each of her travels are based

C# We are tracking down our rogue agent and she travels from place to place to avoid being tracked. Each of her travels are based on a list of itineraries in an unusual or incorrect order. The task is to determine the complete route she will take. You are given an array of routes containing her travel itineraries. Convert this into a complete, in-order list of the places she will travel. Specification Challenge.FindRoutes(routes) Parameters routes: Array - Array of itineraries Return Value string - An ordered list or destinations Constraints All inputs have at least one valid, complete route Examples routes [["USA","BRA"], ["JPN","PHL"], ["BRA","UAE"], ["UAE","JPN"]] Return Value "USA, BRA, UAE, JPN, PHL"

using System; using System.Collections.Generic;

class Program { static void Main(string[] args) { string[][] routes = new string[][] { new string[] { "USA", "BRA" }, new string[] { "JPN", "PHL" }, new string[] { "BRA", "UAE" }, new string[] { "UAE", "JPN" } };

Console.WriteLine(FindRoutes(routes)); }

static string FindRoutes(string[][] routes) { Dictionary> graph = new Dictionary>(); Dictionary indegree = new Dictionary();

// Create the graph foreach (var route in routes) { if (!graph.ContainsKey(route[0])) { graph[route[0]] = new List(); indegree[route[0]] = 0; }

if (!graph.ContainsKey(route[1])) { graph[route[1]] = new List(); indegree[route[1]] = 0; }

graph[route[0]].Add(route[1]); indegree[route[1]]++; }

Queue queue = new Queue(); foreach (var node in indegree) { if (node.Value == 0) { queue.Enqueue(node.Key); } }

string result = ""; while (queue.Count > 0) { string node = queue.Dequeue(); result += node + ", ";

foreach (var neighbor in graph[node]) { indegree[neighbor]--; if (indegree[neighbor] == 0) { queue.Enqueue(neighbor); } } }

return result.TrimEnd(new char[] { ',', ' ' }); } }

I got the following error

Program.FindRoutes(string[][])' is inaccessible due to its protection level

Thanks a lot

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!