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. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Best spot
  5. Discussions

Best spot

Problem
Submissions
Leaderboard
Discussions
Editorial

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

  • nquangcuong96
    4 years ago+ 0 comments

    Can anyone help me ! this is my code for the problem

    def bestSpot(heights, store):
        #
        # Write your code here.
        divide = (len(heights)-len(store)+1)
        ar = [0] * pow(divide,2)
        for i in range(len(ar)):
            for x in range(len(store)**2):
                ar[i] += pow(heights[int(i/divide)+int(x/len(store))][i%divide + x%len(store)] - store[int(x/len(store))][x%len(store)],2)
        print(min(ar))
        print(int(ar.index(min(ar))/divide)+int((len(store)*2 -1)/len(store)),ar.index(min(ar))%divide + (len(store)*2 -1)%len(store))
        #
    

    However, i dont know what wrong with this code, i try on paper and it is correct, but when submit, it fail

    -1|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy