You are viewing a single comment's thread. Return to all comments →
Okay. As such, the only built-in used here, is "set". set() function forms a mathematical type of set and removes all the duplicate elements. Similarly, set.intersection() takes intersection of all the sets (as in mathematical context). Please have a look at the docs and tutorial for better understanding.
The logic is to form a set corresponding to each "rock" by removing the duplicate "gems". So, each set will have every gem present in rock, exactly once. Now, we just need to find the common gems in each set, which is basically equivalent to finding intersection of all sets mathematically. Thus, set.intersection gives the list of the "gems" present in each rock. The result just requires the count of gems, hence, length of above result is printed as answer.
Thanks. Now I got it finally.