Count Number of Triples in an array that are collinear

后端 未结 6 772
梦谈多话
梦谈多话 2021-02-01 09:31

I was asked this Interview Question (C++,algos)and had no idea how to solve it.

Given an array say Arr[N] containing Cartesian coordinates of N distinct points count the

6条回答
  •  清酒与你
    2021-02-01 10:04

    If it's 2 dimension points: 3 points (P,Q,R) are collinear if (P,Q), (P,R) define the same slope.

    m = (p.x - q.x) / (p.y - q.y)  ; slope
    

    Somehow you need to check all possible combinations and check, an efficient algo is trick as the first naive is N*(N-1)*(N-2)...

提交回复
热议问题