We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Functional Programming
  3. Introduction
  4. Functions or Not?

Functions or Not?

Problem
Submissions
Leaderboard
Discussions

Objective
In this problem, we touch upon a basic concept that is fundamental to Functional Programming: identifying a relation which represents a valid function.

Task
You are given a set of unique ordered pairs constituting a relation. The -values form the domain, and the -values form the range to which they map. For each of these relations, identify whether they may possibly represent a valid function or not.

Note: You do not have to find the actual function, you just need to determine that the relation may be representative of some valid function.

Input Format

The first line contains an integer, , denoting the number of test cases. The subsequent lines describe test cases, and the input for each test case is as follows:

  1. The first line contains an integer, , the number of pairs in the test case.
  2. The subsequent lines each contain two space-separated integers describing the respective and values for each ordered pair.

Constraints

  • N

Output Format

On a new line for each test case, print if the set of ordered pairs represent a valid function, or if they do not.

Sample Input

2  
3  
1 1  
2 2  
3 3  
4
1 2
2 4
3 6  
4 8  

Sample Output

YES  
YES

Explanation

Test Case 0:
, Ordered Pairs: The set of ordered pairs represents a relation, which could represent a function such as , . Thus, we print on a new line.

Test Case 1:
, Ordered Pairs:
The set of ordered pairs represents a relation, which could represent a function such as , . Thus, we print on a new line.

Author

PRASHANTB1984

Difficulty

Easy

Max Score

5

Submitted By

3426

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature