Pick distinct numbers problem

Revision en1, by webstorms, 2016-05-23 10:37:53

Say you are given an array. Every cell in the array stores three numbers. The objective is to determine if you can select a number (from the 3 given) for each cell such that all numbers are distinct.

Example: Input: (1,2,3),(1,2,5),(2,5,6) Output: 1,5,6 (all of distinct, good)

Input: (1,1,1),(1,1,1),(2,5,6) Output: 1,1,6 (not all distinct, hence impossible)

Any ideas how this problem could be solved in good time complexity? My ideas where to think of this as a graph problem. Maybe there is a greedy approach to this?

Tags graph

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English webstorms 2016-05-23 10:37:53 571 Initial revision (published)