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

Best spot

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 9 Discussions, By:

recency

Please Login in order to post a comment

  • thecodingsoluti2
    2 months ago+ 0 comments

    Here is Best Spot problem solution in Python Java C++ and C programming - https://programs.programmingoneonone.com/2021/07/hackerrank-best-spot-problem-solution.html

    0|
    Permalink
  • hr_ajinkya
    2 years ago+ 0 comments

    can some one explain me the question?

    0|
    Permalink
  • manvi_muskan
    3 years ago+ 0 comments

    Can someone suggest me ways to optimise my code ?

    r, c = map(int, input().split())
    l, t, smallest_sum, point = [], [], None, None
    
    for i in range(r):
        l.append(list(map(int,input().split())))
    
    h, w = map(int, input().split())
    for i in range(h):
        t.append(list(map(int,input().split())))
    
    for i in range(r-h+1):
        for j in range(c-w+1):
            temp_sum = 0
            for m in range(h):
                for n in range(w):
                    temp_sum += (l[i+m][j+n] - t[m][n])**2
            if smallest_sum == None or smallest_sum > temp_sum:
                    smallest_sum = temp_sum
                    point = i,j,
    print("{}\n{} {}".format(smallest_sum, point[0]+1, point[1]+1))
    
    0|
    Permalink
  • 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
  • PrateekAg1999
    5 years ago+ 0 comments

    i don't understand the question exactly.So,Someone helped me to sort the question?? Question is-In Chile, land are partitioned into a one large grid, where each element represents a land of size 1x1.

    Shaka is a newcomer in Chile and is trying to start his own business. He is planning to build a store. He has his own ideas for the "perfect store" which can be represented by a HxW grid. Element at position (i, j) represents height of land at index (i, j) in the grid.

    Shaka has purchased a land area which can be represented RxC grid (H <= R, W <= C). Shaka is interested in finding best HxW sub-grid in the acquired land. In order to compare the possible sub-grids, Shaka will be using the sum of squared difference between each cell of his "perfect store" and it's corresponding cell in the subgrid. Amongst all possible sub-grids, he will choose the one with smallest such sum.

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy