Having spent the last couple of hours grading assignments, I decide it's time for a break. I take out my favourite colouring book, turn to a random page I haven't coloured in yet, and lay it on my desk. I then take out all my n crayons and line them up on the desk (it's a very long desk). The colour of the th crayon is a string c[i] (e.g. "blue"). Many of the crayons have the same colour. In fact, no matter how many crayons I have, there are at most 30 distinct colours amongst them. To start colouring, I always take a sublist (see Q1 for a definition) of the crayons laid on the desk and put away the rest (too many options can be overwhelming and can lead to indecision). I take a look at the line art in front of me and wonder, “How many different colours do I need to make this look great? One? Two? Maybe three?". Now you understand my dilemma and are fully aware of my indecision. You kindly decide to help me out by telling me for every number k, if I were to use k distinct colours, what would be the minimum number of crayons I'd need to take? Filename Your filename for this question must be q4.py. Input The input consists of a single line containing n space-separated names of colours specifying the list c. Output Let m be the number of distinct colours in c. Then, output m space-separated integers. The kt of them (1-based) should be the minimum number of crayons ľ'd need to take so that there are at least k distinct colours amongst them.
Having spent the last couple of hours grading assignments, I decide it's time for a break. I take out my favourite colouring book, turn to a random page I haven't coloured in yet, and lay it on my desk. I then take out all my n crayons and line them up on the desk (it's a very long desk). The colour of the th crayon is a string c[i] (e.g. "blue"). Many of the crayons have the same colour. In fact, no matter how many crayons I have, there are at most 30 distinct colours amongst them. To start colouring, I always take a sublist (see Q1 for a definition) of the crayons laid on the desk and put away the rest (too many options can be overwhelming and can lead to indecision). I take a look at the line art in front of me and wonder, “How many different colours do I need to make this look great? One? Two? Maybe three?". Now you understand my dilemma and are fully aware of my indecision. You kindly decide to help me out by telling me for every number k, if I were to use k distinct colours, what would be the minimum number of crayons I'd need to take? Filename Your filename for this question must be q4.py. Input The input consists of a single line containing n space-separated names of colours specifying the list c. Output Let m be the number of distinct colours in c. Then, output m space-separated integers. The kt of them (1-based) should be the minimum number of crayons ľ'd need to take so that there are at least k distinct colours amongst them.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
In python
![Having spent the last couple of hours grading assignments, I decide it's time for a
break. I take out my favourite colouring book, turn to a random page I haven't
coloured in yet, and lay it on my desk. I then take out all my n crayons and line
them up on the desk (it's a very long desk). The colour of the ith crayon is a string
c[i] (e.g. "blue"). Many of the crayons have the same colour. In fact, no matter
how many crayons I have, there are at most 30 distinct colours amongst them.
To start colouring, I always take a sublist (see Q1 for a definition) of the crayons
laid on the desk and put away the rest (too many options can be overwhelming
and can lead to indecision).
I take a look at the line art in front of me and wonder, "How many different
colours do I need to make this look great? One? Two? Maybe three?".
Now you understand my dilemma and are fully aware of my indecision. You
kindly decide to help me out by telling me for every number k, if I were to use k
distinct colours, what would be the minimum number of crayons I'd need to
take?
Filename
Your filename for this question must be q4. py.
Input
The input consists of a single line containing n space-separated names of colours
specifying the list c.
Output
Let m be the number of distinct colours in c. Then, output m space-separated
integers. The kih of them (1-based) should be the minimum number of crayons I'd
need to take so that there are at least k distinct colours amongst them.
Constraints](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd9560cc0-8b67-4312-a65d-776a1b7bd6fa%2F0c55edb4-039e-4935-8894-6d7c11cdbfea%2Fnrvoa4u_processed.png&w=3840&q=75)
Transcribed Image Text:Having spent the last couple of hours grading assignments, I decide it's time for a
break. I take out my favourite colouring book, turn to a random page I haven't
coloured in yet, and lay it on my desk. I then take out all my n crayons and line
them up on the desk (it's a very long desk). The colour of the ith crayon is a string
c[i] (e.g. "blue"). Many of the crayons have the same colour. In fact, no matter
how many crayons I have, there are at most 30 distinct colours amongst them.
To start colouring, I always take a sublist (see Q1 for a definition) of the crayons
laid on the desk and put away the rest (too many options can be overwhelming
and can lead to indecision).
I take a look at the line art in front of me and wonder, "How many different
colours do I need to make this look great? One? Two? Maybe three?".
Now you understand my dilemma and are fully aware of my indecision. You
kindly decide to help me out by telling me for every number k, if I were to use k
distinct colours, what would be the minimum number of crayons I'd need to
take?
Filename
Your filename for this question must be q4. py.
Input
The input consists of a single line containing n space-separated names of colours
specifying the list c.
Output
Let m be the number of distinct colours in c. Then, output m space-separated
integers. The kih of them (1-based) should be the minimum number of crayons I'd
need to take so that there are at least k distinct colours amongst them.
Constraints
![Constraints
• 1sns5 x 104
• 1s len(c[i]) < 5
• There are at most 30 distinct colours in c.
Time Limit
• Your program has to finish running within 4 seconds on any valid input.
Sample Input 1
green red red blue red red green
Sample Output 1
1 2 4
Sample 1 Explanation
• If I wanted to use only 1 colour, I could take any single crayon.
• If I wanted to use 2 distinct colours, I could take a sublist of length 2 such as
the sublist red blue.
• If I wanted to use all three colours, the smallest possible sublist would have
length 4. For example, I could take blue red red green.
Sample Input 2
rg z g b brr gyggyb
Sample Output 2
123 5 8](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd9560cc0-8b67-4312-a65d-776a1b7bd6fa%2F0c55edb4-039e-4935-8894-6d7c11cdbfea%2Fau0yfsg_processed.png&w=3840&q=75)
Transcribed Image Text:Constraints
• 1sns5 x 104
• 1s len(c[i]) < 5
• There are at most 30 distinct colours in c.
Time Limit
• Your program has to finish running within 4 seconds on any valid input.
Sample Input 1
green red red blue red red green
Sample Output 1
1 2 4
Sample 1 Explanation
• If I wanted to use only 1 colour, I could take any single crayon.
• If I wanted to use 2 distinct colours, I could take a sublist of length 2 such as
the sublist red blue.
• If I wanted to use all three colours, the smallest possible sublist would have
length 4. For example, I could take blue red red green.
Sample Input 2
rg z g b brr gyggyb
Sample Output 2
123 5 8
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY