Making friends

You opened a school with students. Each student will either belong to Team Red or Team Blue. The students in each team are friends with each other. However, you want them to make friends with students from the opposite team too. For example, if a student belongs to Team Red, you want that student to make friends with students from Team Blue.

Note: Friendship is mutual. If A is B's friend, then B is automatically A's friend. 

You give each student a number M that represents the number of friends that the student should have from the opposite team.

Your task is to determine whether it is possible for each student to have the number of friends represented by the number M.

Example:

Input:  n=2, m=1
Output: YES

Approach

Java


public class MakingFriends {
    public static void main(String[] args) {
        int n = 2;
        int m = 1;

        if (m == 0 || (n % 2 == 0 && m <= n / 2)) {
            System.out.println("Yes");
        } else
            System.out.println("No");
    }

}


No comments:

Post a Comment