Maximum points of intersection n lines Last Updated : 03 Oct, 2022 Comments Improve Suggest changes Like Article Like Report You are given n straight lines. You have to find a maximum number of points of intersection with these n lines.Examples: Input : n = 4 Output : 6 Input : n = 2Output :1 Approach : As we have n number of line, and we have to find the maximum point of intersection using this n line. So this can be done using the combination. This problem can be thought of as a number of ways to select any two lines among n line. As every line intersects with others that are selected. So, the total number of points = nC2 Below is the implementation of the above approach: C++ // CPP program to find maximum intersecting // points #include <bits/stdc++.h> using namespace std; #define ll long int // nC2 = (n)*(n-1)/2; ll countMaxIntersect(ll n) { return (n) * (n - 1) / 2; } // Driver code int main() { // n is number of line ll n = 8; cout << countMaxIntersect(n) << endl; return 0; } Java // Java program to find maximum intersecting // points public class GFG { // nC2 = (n)*(n-1)/2; static long countMaxIntersect(long n) { return (n) * (n - 1) / 2; } // Driver code public static void main(String args[]) { // n is number of line long n = 8; System.out.println(countMaxIntersect(n)); } // This code is contributed by ANKITRAI1 } Python3 # Python3 program to find maximum # intersecting points #nC2 = (n)*(n-1)/2 def countMaxIntersect(n): return int(n*(n - 1)/2) #Driver code if __name__=='__main__': # n is number of line n = 8 print(countMaxIntersect(n)) # this code is contributed by # Shashank_Sharma C# // C# program to find maximum intersecting // points using System; class GFG { // nC2 = (n)*(n-1)/2; public static long countMaxIntersect(long n) { return (n) * (n - 1) / 2; } // Driver code public static void Main() { // n is number of line long n = 8; Console.WriteLine(countMaxIntersect(n)); } } // This code is contributed by Soumik PHP <?PHP // PHP program to find maximum intersecting // points // nC2 = (n)*(n-1)/2; function countMaxIntersect($n) { return ($n) * ($n - 1) / 2; } // Driver code // n is number of line $n = 8; echo countMaxIntersect($n) . "\n"; // This code is contributed by ChitraNayal ?> JavaScript <script> // Javascript program to find maximum intersecting // points // nC2 = (n)*(n-1)/2; function countMaxIntersect(n) { return (n) * (n - 1) / 2; } // Driver code // n is number of line var n = 8; document.write( countMaxIntersect(n) ); </script> Output: 28 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Maximum points of intersection n lines S sahilshelangia Follow Improve Article Tags : Misc Geometric Combinatorial Computer Science Fundamentals DSA +1 More Practice Tags : CombinatorialGeometricMisc Similar Reads Maximum points of intersection n circles Given a number n, we need to find the maximum number of times n circles intersect. Examples: Input : n = 2Output : 2 Input : n = 3Output : 6 Description and Derivation As we can see in above diagram, for each pair of circles, there can be maximum two intersection points. Therefore if we have n circl 3 min read Maximum possible intersection by moving centers of line segments Given three points on the X-axis which denotes the center of three line segments. The length of the line segment is also given as L. The task is to move the center of the given line segments by a distance of K to maximize the length of intersection between the three lines. Examples: Input: c1 = 1, c 5 min read Maximize count of intersecting line segments Given two arrays X[] and Y[], representing points on X and Y number lines, such that every similar-indexed array element forms a line segment, i.e. X[i] and Y[i] forms a line segment, the task is to find the maximum number of line segments that can be selected from the given array. Examples: Input: 8 min read Count maximum points on same line Given N point on a 2D plane as pair of (x, y) co-ordinates, we need to find maximum number of point which lie on the same line. Examples: Input : points[] = {-1, 1}, {0, 0}, {1, 1}, {2, 2}, {3, 3}, {3, 4} Output : 4 Then maximum number of point which lie on same line are 4, those point are {0, 0}, { 10 min read Find Maximum Number of Intersections on the Chart Given a line chart with n points connected by line segments and a 1-indexed integer array y[], where the ith point has coordinates (i, y[i]). There are no horizontal lines, meaning no two consecutive points have the same y-coordinate. The task is to find the maximum number of points of intersection 14 min read Like