Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3464 - Maximize the Distance Between Points on a Square.

    Hard

    You are given an integer side, representing the edge length of a square with corners at (0, 0), (0, side), (side, 0), and (side, side) on a Cartesian plane.

    You are also given a positive integer k and a 2D integer array points, where <code>pointsi = x<sub>i</sub>, y<sub>i</sub></code> represents the coordinate of a point lying on the boundary of the square.

    You need to select k elements among points such that the minimum Manhattan distance between any two points is maximized.

    Return the maximum possible minimum Manhattan distance between the selected k points.

    The Manhattan Distance between two cells <code>(x<sub>i</sub>, y<sub>i</sub>)</code> and <code>(x<sub>j</sub>, y<sub>j</sub>)</code> is <code>|x<sub>i</sub> - x<sub>j</sub>| + |y<sub>i</sub> - y<sub>j</sub>|</code>.

    Example 1:

    Input: side = 2, points = [0,2,2,0,2,2,0,0], k = 4

    Output: 2

    Explanation:

    Select all four points.

    Example 2:

    Input: side = 2, points = [0,0,1,2,2,0,2,2,2,1], k = 4

    Output: 1

    Explanation:

    Select the points (0, 0), (2, 0), (2, 2), and (2, 1).

    Example 3:

    Input: side = 2, points = [0,0,0,1,0,2,1,2,2,0,2,2,2,1], k = 5

    Output: 1

    Explanation:

    Select the points (0, 0), (0, 1), (0, 2), (1, 2), and (2, 2).

    Constraints:

    • <code>1 <= side <= 10<sup>9</sup></code>

    • <code>4 <= points.length <= min(4 * side, 15 * 10<sup>3</sup>)</code>

    • points[i] == [xi, yi]

    • The input is generated such that:

    • 4 &lt;= k &lt;= min(25, points.length)

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer maxDistance(Integer side, Array<IntArray> points, Integer k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait