Best spot
Best spot
+ 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 comments can some one explain me the question?
+ 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 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
+ 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.
Sort 9 Discussions, By:
Please Login in order to post a comment