Posted by admin June 26th 2018 at 20:06

```You want to determine the most popular person in the social network.
To do this, you will count the number of "2-friends" that each person has.
Person A is called a 2-friend of another person B
if they are friends with each ther or
if there exists some person C who is a friend of both A and B.
The most popular person is the person with the highest number of 2-friends.
(There might be more than one if multiple people all have the maximal number of 2-firends.)
You are given a String[] friends,
where the j-th character of the i-th element is 'Y'
if person i and person j are friends, and 'N' otherwise.
Return the number of 2-friends of the most popular person in this social network.```

```var freinds : [String] = ["NYNNN", "YNYNN", "NYNYN", "NNYNY", "NNNYN"]
var length : Int = freinds.characters.count
var maxCount : Int = 0
var fCount : Int = 0

for i in 0...freinds.count-1{
fCount = 0
for j in 0...length-1{
if i == j {
continue
}
if Array(freinds[i].characters)[j] == "Y" {
fCount += 1
}else{
for k in 0...length-1{
if Array(freinds[j].characters)[k] == "Y" && Array(freinds[k].characters)[i] == "Y" {
fCount += 1
break
}
}
}

}
maxCount = max(fCount, maxCount)
}

print(maxCount)```