TopcoderARCHIVE
Archive/Problems/CoolPairsEasy
SRM · Problem 15448

CoolPairsEasy

Problem statement, definition, constraints, and public examples.

Problem Statement

There is a group of N people. Each person in the group has a first name and a last name: the names of person i are firstname[i] and lastname[i].

If A and B are two different people such that the last name of person A is the same as the first name of person B, the ordered pair (A, B) is called cool.

Please calculate and return the number of cool pairs for the given group of people.

Definition

Class:
CoolPairsEasy
Method:
count
Parameters:
String[], String[]
Returns:
int
Method signature:
int count(String[] firstname, String[] lastname)
(be sure your method is public)

Constraints

  • N will be between 1 and 50, inclusive.
  • firstname and lastname will contain exactly N elements each.
  • Length of each element in firstname and lastname will have between 1 and 10, inclusive.
  • Each element in firstname and lastname will only consist of lowercase English letters ('a'-'z').

Examples

  1. {"elton", "tom", "john"}
    {"john", "jones", "cena"}
    Returns: 1
    The pair (0, 2) is a cool pair because both person 0's last name and person 2's first name is "john". (Person 0 is called "elton john" and person 2 is called "john cena".)
  2. {"james", "taylor"}
    {"taylor", "james"}
    Returns: 2
    Note that the cool pairs are ordered pairs. In this example, (0, 1) is a cool pair and (1, 0) is a different cool pair.
  3. {"jar"}
    {"jar"}
    Returns: 0
    Remember that the two people in a cool pair must be distinct. Even though "jar jar" has the same first and last name, (0, 0) is not a cool pair.
  4. {"lee", "stan", "ang", "marvin", "lee", "grace", "kelly", "jeremy"}
    {"marvin", "lee", "lee", "gaye", "mack", "kelly", "clarkson", "clarkson"}
    Returns: 6
  5. {"major", "major", "major"}
    {"major", "major", "major"}
    Returns: 6
    There are three distinct people in this example. Each of them is called "major major". There are six cool pairs: (0,1), (0,2), (1,0), (1,2), (2,0) and (2,1).
← All problems