Count pairs of coordinates connected by a line with slope in the range [ | Java program for the above approach ; Function to find the number of pairs of points such that the line passing through them has a slope in the range [ - k , k ] ; Store the result ; Traverse through all the combination of points ; If pair satisfies the given condition ; Increment ans by 1 ; Print the result ; Driven Code ; Function Call
import java . util . * ; class GFG { static void findPairs ( int [ ] x , int [ ] y , int K ) { int n = x . length ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { if ( K * Math . abs ( x [ i ] - x [ j ] ) >= Math . abs ( y [ i ] - y [ j ] ) ) { ++ ans ; } } } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int [ ] X = { 2 , 1 , 0 } ; int [ ] Y = { 1 , 2 , 0 } ; int K = 1 ; findPairs ( X , Y , K ) ; } }