The key idea behind this question is to think like persons are vertices and friendships between persons as edges..
So this question reduces to :
There are n vertices ; k vertices out of which is not connected to each other by any path..So we have to determine max no of edges possible under this constraint
So the idea is to exclude this k vertices first , so we are left with (n-k) vertices..
Now max possible edges among these (n-k) vertices is possible if it is a clique ; meaning every vertex is connected to all other vertices in these (n-k) vertex set..
Hence no of edges = ^{n-k}C_{2}
Now we choose 1 out of those k excluded vertices , say v1and connect them to each of (n - k) vertices..Now if we go to choose any other vertex out of remaining (k-1) vertex say v2 , then that will imply having one path at least from v1 to v2 indirectly via the clique and thus violating condition..Hence we cannot connect v2 to vertices of the clique..
Hence max no of edges(friendships) possible = ^{n-k}C_{2} + (n-k)
= ^{n-k}C_{2} + ^{n-k}C_{1}
= ^{n-k+1}C_{2} [Using identity : ^{n}C_{r} + ^{n}C_{r-1} = ^{n+1}C_{r}]
Hence max no of friendships possible = ^{n-k+1}C_{2}