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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Count Triplets
  2. Discussions

Count Triplets

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • prsephton
    3 months ago+ 0 comments

    Wow, that took a while. "The ratio of any two consecutive terms in a geometric progression is the same".

    def countTriplets(arr, r):
        ntuples = 0
        div_r = defaultdict(lambda: 0)
        r_val = defaultdict(lambda: 0)
        for v in arr:
            ntuples += div_r[v/r]
            div_r[v] += r_val[v/r]
            r_val[v] += 1
    
        return ntuples
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy