Alice and Bob made a list of topics and both of them voted if they like or dislike the topic. They wrote 0 to denote dislike and 1 to denote like. The task is to count the number of topics that both of them like or dislike.
Input: alice = “010101” bob = “101101”
alice and bob both like 4th and 6th topics and dislike the 5th topic. Hence, the output is 3.
Input: alice = “111111” bob = “000000”
There are no common likes or dislikes between alice and bob. Hence, the output is 0.
Input: alice = “110000” bob = “110011”
alice and bob both like 1st and 2nd topics and dislike 3rd and 4th topics. Hence, the result is 4.
- First, we have to iterate through each character of the string consisting of the likes and dislikes of alice.
- Then, we have to compare it with the corresponding entry of the string consisting of the likes and dislikes of bob.
- Finally, we will count the number of similar entries and print.
Below is the implementation.
3 0 4
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course