☑️ Finding Nearest Point That Has the Same X or Y Coordinate. ☑️
Code
# Code
```dart []
class Solution {
  int nearestValidPoint(int x, int y, List<List<int>> points) {
    List<int> distances = [];
    for(int i = 0; i < points.length; i++){
        if(points[i][0] == x || points[i][1] == y){
            distances.add((x-points[i][0]).abs() + (y-points[i][1]).abs());
        }
    }


    distances.sort((a, b) => a.compareTo(b));
    if(distances.isEmpty){
        return -1;
    }
    int smallestNumber = distances.first;
    print(smallestNumber);

    for(int i = 0; i < points.length; i++){
        if(smallestNumber == ((x-points[i][0]).abs() + (y-points[i][1]).abs()) && points[i][0] == x || points[i][1] == y && smallestNumber == ((x-points[i][0]).abs() + (y-points[i][1]).abs())){
            return i;
        }
    }
    return -1;
  }
}
```
['Array', 'Dart']