Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    825 - Friends Of Appropriate Ages\.

    Medium

    There are n persons on a social media website. You are given an integer array ages where ages[i] is the age of the <code>i<sup>th</sup></code> person.

    A Person x will not send a friend request to a person y (x != y) if any of the following conditions is true:

    • age[y] &lt;= 0.5 * age[x] + 7

    • age[y] &gt; age[x]

    • age[y] &gt; 100 &amp;&amp; age[x] &lt; 100

    Otherwise, x will send a friend request to y.

    Note that if x sends a request to y, y will not necessarily send a request to x. Also, a person will not send a friend request to themself.

    Return the total number of friend requests made.

    Example 1:

    Input: ages = 16,16

    Output: 2

    Explanation: 2 people friend request each other.

    Example 2:

    Input: ages = 16,17,18

    Output: 2

    Explanation: Friend requests are made 17 -> 16, 18 -> 17.

    Example 3:

    Input: ages = 20,30,100,110,120

    Output: 3

    Explanation: Friend requests are made 110 -> 100, 120 -> 110, 120 -> 100.

    Constraints:

    • n == ages.length

    • <code>1 <= n <= 2 * 10<sup>4</sup></code>

    • 1 &lt;= ages[i] &lt;= 120

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer numFriendRequests(IntArray ages)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait