Help me in solving PPSCPP238 problem

My issue

Solution has error. It should be for(int j = 0; j < i; j++) in line 28 instead of j < i - 1 because adjacent elements are not getting checked due to this error.

My code

#include <iostream>
#include <cmath>
using namespace std;

struct Point {
    int x;
    int y;
};

float dist(Point p1, Point p2) {
    float ans = sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
    return ans;
}

int main() {
    int n; 
    cin >> n;   

    Point p[n];

    for(int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
    }

    float ans = 0;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < i; j++) {
            float distance = dist(p[i], p[j]);
            ans = max(ans, distance);
        }
    }

    cout << ans;
}

Learning course: Complete C++ course
Problem Link: Coding problem - 2 Practice Problem in Complete C++ course - CodeChef