Skip to main content
4 of 5
added 1 character in body
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282

Jelly,  15  18 bytes

+3 bytes to fix bugs in my method.

QL×’$⁼L
ŒPẎ€ÇÐfṪQL

A monadic link taking the list of friendships (edges) and returning an integer.

Try it online! forms the power-set of the edges in memory so is inefficient both in space and time (yep,that's O(2n) folks)!

How?

QL×’$⁼L - Link 1, isClique?: list, flattenedEdges  e.g. [1,3,2,3,3,4,4,1,4,2,2,1]
                                    ...from: [[1,3],[2,3],[3,4],[4,1],[4,2],[2,1]]
Q       - de-duplicate (gets unique ids)                [1,3,2,4]
 L      - length (get number of people involved)        4
    $   - last two links as a monad:
   ’    -   decrement                                   3
  ×     -   multiply                                    12
      L - length (of flattenedEdges)                    12
     ⁼  - equal?                                        1
        - (Note: the number of edges of a clique of size n is n*(n-1) and we're
        -  guaranteed no repeated edges and that all edges are two distinct ids)

ŒPẎ€ÇÐfṪQL - Link: list of lists, edges
ŒP         - power-set (all possible sets of edges (as lists))
  Ẏ€       - tighten €ach (flattens each list of edges to a list of the ids)
     Ðf    - filter keep those for which this is truthy:
    Ç      -   call last link (1) as a monad
       Ṫ   - tail (get the rightmost, note that ŒP is ordered by length)
        Q  - de-duplicate (get the unique ids)
         L - length (the number of friends in (one of the) largest clique(s))
Jonathan Allan
  • 110.1k
  • 7
  • 65
  • 282