How to solve this problem ? Please help!!!!
Anonymous User
293

M pairs of integers are given, each integer is between 1 and N, inclusive. The pairs are (a1, b1),(a2,b2)....(am,bm).
Return true if there exist 2 integers x and y (1≤ x < y ≤ N) such that in each given pair at least one integer is equal to x or y else false.
Eg. N = 6, M = 4. And pairs are (2,3),(3,4),(4,5),(5,6) return true as x = 3 and y = 5.
How to solve this question?

constraints:
2≤N≤300000
1≤M≤300000

Comments (1)