When handling a substantial number of points or points in a higher-dimensional space, a brute-force method may not be the most efficient. Instead, we can utilize a priority queue or a heap to keep track of the distances of all points alongside their respective coordinates. This arrangement allows us to access the smallest distance at the top of the heap in constant time. Below is an illustration using Python's heapq module: import heapq import math def closest_points ( points , K ) : heap = [ ] for point in points : distance = - math . sqrt ( sum ( [ i ** 2 for i in point ] ) ) if len ( heap ) == K : heapq . heappushpop ( heap , ( distance , point ) ) else : heapq . heappush ( heap , ( distance , point ) ) return [ i [ 1 ] for i in heap ] In this demonstration, we maintain the K smallest elements within the heap, ensuring that at the conclusion of the iteration, the heap holds the K points that are closest to the origin. This method can be more efficient for managing large datasets or higher-dimensional spaces.