Beginners Problems on Sets
Given a list of numbers (e.g. [1,3,8,35, 4,2,3]) Print ‘YES’ if the next number has already been ‘seen’ before, and ‘NO’ if the next number hasn’t been encountered yet.
E.g. (using the example list): NO
NO
NO
NO
NO
NO
YES
Given a string of words as input, print the number of distinct words. From these distinct words, print the number of times ‘a’ appears.
E.g. The quick brown fox jumps over the lazy dog
8
1
We have 2 lists containing some numbers. Print the numbers that appear in both lists and in ascending order.
e.g. listA = [18, 2, 90, 3, 5]
listB = [2, 86, 42, 5, 7]
Output: 2 5
You’re surrounded by a group of people who speak different languages. Sift through all of them and display the necessary information. You are given:
- The number of people you’re surrounded by
- The number of languages are spoken by each person
- What languages are spoken by the corresponding person
You must display:
- The number of languages everyone in the group speaks
- What language(s) is spoken by everyone in the group
- The number of total languages spoken in the group
- What languages are spoken in the group
Input is in bold. Example:
How many people are there? 3
(To person 1) How many languages can you speak? 3
What languages can you speak in? English
Mandarin
Arabic
(To person 2) How many languages can you speak? 4
What languages can you speak in?
Portuguese
English
Tagalog
Arabic
(To person 3) How many languages can you speak? 1
What languages can you speak in?
English
Number of languages everyone speaks: 1
Spoken language(s) everyone speaks: English
Total languages spoken in the group: 5
Languages spoken: English, Mandarin, Arabic, Portuguese, Tagalog