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
// Create the graph foreach (var route in routes) { if (!graph.ContainsKey(route[0])) { graph[route[0]] = new List
if (!graph.ContainsKey(route[1])) { graph[route[1]] = new List
graph[route[0]].Add(route[1]); indegree[route[1]]++; }
Queue
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
Get step-by-step solutions from verified subject matter experts
