Friend Circles Problem-Statement

There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature, i.e., if A is friend of B and B is friend of C, then A is also friend of C. A friend circle is a group of students who are directly or indirectly friends.

You have to complete a function int friendCricles(char[][] friends) which returns the number of friend circles in the class. Its argument, friends, is a NxN matrix which consists of characters 'Y' or 'N'. If friends[i][j] = 'Y', then ith and *jth students are friends with each other, otherwise not. You have to return the total number of friend circles in the class. Note: The method signature will differ by language. For example, Java will have 'int friendCircles(String[] friends)' where "friends" is an array of strings, which can be viewed as a 2-dimensional array of chracters.

Constraints

  • 1 <= N <= 300.
  • Each element of matrix friends will be 'Y' or 'N'.
  • Number of rows and columns will be equal in friends.
  • friends[i][i] = 'Y', where 0 <= i < N
  • friends[i][j] = friends[j][i], where 0 <= i < j < N

Input Format:

The function "friendCircles" contains a 2d string array "friends" as its argument.

Output Format:

Return a single integer denoting number of different circles that are present in the class.

Sample Input #00:

4

YYNN

YYYN

NYYN

NNNY

Sample Output #00:

2

Explanation #00:

Friend 4 is only friends with themself. Friends 1, 2, and 3 are in a friend circle together.

Sample Input #01:

5

YNNNN

NYNNN

NNYNN

NNNYN

NNNNY

Sample Output #01:

5

Explanation #01:

No student is friends with any other, so each friend circle will contain only one student {0}, {1}, {2}, {3}, {4}.

Attempts

TODO