So I was asked this question in google onsite pre-pandamic era and I haven't found optimized answer for question, brute force exists but I feel there are better ways to do it.
So you are given a rule table something like this
Where there are 4 columns and first 3 are rules and 4th one is the value i.e if A1 && B1 && C1 is input then 20 should be the output, if A2 && B2 && C2 is the input then the table is outputing 30 and so on. These A1 B2 C3 ... Zn are just identifiers dont go on their names. Now instead of specefic rule name like A1, B1 C2.....Zn we have a special rule name * which means any rule. So in 4th row (A3, B4, *) it means any rules wich starts with A3 && B4 will match this row and output will be 60, think it like a pattern matching, any rules matching pattern A3B4* will output 60. A3 && B4 && * matches A3 && B4 && A1, A3 && B4 && Z5 , A3 && B4 && M8 etc etc.
That being said, IF the table is producing different output for same input OR if the output is non deterministic state OR if the table is confused what to output for certain rule it means the table is freaking AMBIGIOUS. In the example above 1st row and 3rd row give rise to ambiguty since for input A1 && B1 && C1 can output 20 or 40. 2nd row and 5th row also gives rise to ambiguty since if we input A2 && B2 && C2 table is confused whether to output 90 or 30 since these two rules are matching. But row 4th and row 6th are NON AMBIGOUS since the rules are matching but the output is also same so no confusion for table.
Now the question: Given such table just output if the table is ambigous, no need to output the ambigous rules, just true / false if table is AMBIGOUS. In matter of 45 min I was able to code brute force only that is checking each row with each other if the rules is same and if same then the output is same or not. This is O(n^2), n = no of rows, can anyone help me with better time complexity :-|