Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-153

DBSCAN Neighbors Within Eps

Problem

Return the sorted indices of all points within Euclidean distance eps of point i (including i itself).

Empty points returns [].

Hint

Use a less-than-or-equal comparison so boundary points still count as neighbors.

Test cases

case 1
in: [[[0,0],[0.5,0],[2,0],[2.5,0]],0,1]
expected: [0,1]
case 2
in: [[[0,0],[0.5,0],[2,0],[2.5,0]],3,0.6]
expected: [2,3]
case 3
in: [[[0,0],[0.5,0],[2,0],[2.5,0]],0,0.1]
expected: [0]
case 4
in: [[],0,1]
expected: []
Starter codePython
def dbscan_neighbors(points, i, eps):
    # Your code here
    pass

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