Connecting Towns

Cities on a map are connected by a number of roads. The number of roads between each city is in an array and city 0 is the starting location. The number of roads from city 0 to city 1 is the first value in the array, from city 1 to city 2 is the second, and so on.

How many paths are there from city 0 to the last city in the list, modulo ?

Example

There are 3 roads to city 1,  roads to city 2 and 5 roads to city 3. The total number of roads is .

Example:

Input:  n = 3, routes = {1, 3}
Output: 3

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int connectingTowns(int nvector<introutes)
{
    int res = 1;
    for (int i = 0i < n - 1i++)
    {
        res = res * routes[i];
        res = res % 1234567;
    }
    return res;
}

int main()
{

    int n = 3;
    vector<introutes = {13};

    cout << connectingTowns(nroutes<< "\n";

    return 0;
}


No comments:

Post a Comment