Find whether only two parallel lines contain all coordinates points or not | C # 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
using System ; using System . Collections . Generic ; class GfG { static bool isSlopeGood ( double slope , int [ ] arr , int n ) { HashSet < Double > setOfLines = new HashSet < Double > ( ) ; for ( int i = 0 ; i < n ; i ++ ) setOfLines . Add ( arr [ i ] - slope * ( i ) ) ; return setOfLines . Count == 2 ; } static bool checkForParallel ( int [ ] arr , int n ) { bool slope1 = isSlopeGood ( arr [ 1 ] - arr [ 0 ] , arr , n ) ; bool slope2 = isSlopeGood ( arr [ 2 ] - arr [ 1 ] , arr , n ) ; bool slope3 = isSlopeGood ( ( arr [ 2 ] - arr [ 0 ] ) / 2 , arr , n ) ; return ( slope1 == true slope2 == true slope3 == true ) ; } public static void Main ( ) { int [ ] arr = { 1 , 6 , 3 , 8 , 5 } ; int n = arr . Length ; if ( checkForParallel ( arr , n ) == true ) Console . WriteLine ( "1" ) ; else Console . WriteLine ( "0" ) ; } }