We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Fundamentals
  4. Connecting Towns
  5. Discussions

Connecting Towns

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 139 Discussions, By:

votes

Please Login in order to post a comment

  • stzsch
    5 years ago+ 4 comments

    Pretty annoying, not really a mathematics challenge, but rather a "know-how-to-deal-with-long-integers" challenge.

    31|
    Permalink
    View more Comments..
  • cfranco
    4 years ago+ 1 comment

    If you're failing all but 1 of the test cases, you more than likely did not implement the modulo described in the instructions. In my opinion this problem would be much better if we didn't have to handle data overflow in such a way. In any case it's only 1 extra line of code:

    var routeCount=1;
    for(int i=0;i<routes.Length;i++){
    	routeCount*=routes[i];
    	routeCount%=1234567;
    }
    return routeCount;
    
    16|
    Permalink
  • dewmeht
    6 years ago+ 1 comment

    For C# LINQ

    int result = arr.Aggregate(1, (a, b) => (b * a)%1234567);
    
    4|
    Permalink
  • wwuyxg
    2 years ago+ 0 comments
    connectingTowns(n, routes):
        p = 1
        for x in range(n-1):
            p = p * routes[x]
        return p%1234567
    

    lol..what a troll, this is just the number of ways to walk routes. hahahhaahahaha

    3|
    Permalink
  • nilkun
    5 years ago+ 2 comments

    Snippet.

    for(int j = 0; j < towns - 1; j++) {
                    routes *= scanner.nextInt();
                    for(;;) {
                    if (routes > 1234567) routes = routes - 1234567;
                        else break;
                	}
    }
    
    3|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature