Find whether only two parallel lines contain all coordinates points or not | Java implementation of the above approach ; Find if slope is good with only two intercept ; if set of lines have only two distinct intercept ; Function to check if required solution exist ; check the result by processing the slope by starting three points ; Driver code
import java . util . * ; class GfG { static boolean isSlopeGood ( double slope , int arr [ ] , int n ) { Set < Double > setOfLines = new HashSet < Double > ( ) ; for ( int i = 0 ; i < n ; i ++ ) setOfLines . add ( arr [ i ] - slope * ( i ) ) ; return setOfLines . size ( ) == 2 ; } static boolean checkForParallel ( int arr [ ] , int n ) { boolean slope1 = isSlopeGood ( arr [ 1 ] - arr [ 0 ] , arr , n ) ; boolean slope2 = isSlopeGood ( arr [ 2 ] - arr [ 1 ] , arr , n ) ; boolean slope3 = isSlopeGood ( ( arr [ 2 ] - arr [ 0 ] ) / 2 , arr , n ) ; return ( slope1 == true slope2 == true slope3 == true ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 6 , 3 , 8 , 5 } ; int n = arr . length ; if ( checkForParallel ( arr , n ) == true ) System . out . println ( "1" ) ; else System . out . println ( "0" ) ; } }