Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-235

Template Match Multiple Peaks

Problem

Find up to k non-overlapping peaks of a score map.

Consider positions in descending score order (ties by row then column) and greedily keep a position when its Chebyshev distance to every kept position is at least min_distance. Return [row, col, score] per peak with the score rounded to 4 decimal places.

Test cases

case 1
in: [[[5,1,4],[2,9,3],[6,0,7]],3,1]
expected: [[1,1,9],[2,2,7],[2,0,6]]
case 2
in: [[[5,1,4],[2,9,3],[6,0,7]],2,2]
expected: [[1,1,9]]
case 3
in: [[[1,1],[1,1]],2,1]
expected: [[0,0,1],[0,1,1]]
Starter codePython
def top_peaks(score_map, k, min_distance):
    # Your code here
    pass

3 test cases · run your code against them in the editor