[MUSIC PLAYING]
MAIRIN CHESNEY: Want to participate
in coding competitions, but not sure how to start?
Then join Coding Practice with Kick Start.
Our beginner-friendly, four-day practice session
provides you the opportunity to try out
Googler-created problems without the pressure of a timed round
or scoreboard.
You'll be provided with other tools to help you get started,
such as starter code in several coding languages
and live help from Google engineers, who
are available to answer your questions throughout the week.
At the end of the four-day session,
we hope you'll join us live as Google engineers walk you
through detailed problem solutions.
Afterwards, these videos, along with problem analyses and test
set data, will be available to you
on the participant dashboard whenever
you want to dive back in or refresh your memory on how
to solve a particular problem.
This practice session is for you if you are new
to competitive programming, looking
to boost your skills before the next Kick Start round,
eager to learn something new, or just interested in connecting
with the global community.
Coding practice with Kick Start is a great way for you
to get comfortable solving algorithmic and
mathematical-style problems, develop your coding skills,
and apply what you've learned in school
and throughout your career.
How does coding practice with Kick Start work?
If you haven't already, create a Coding Competitions profile
and register for Kick Start at g.co/kickstart.
Be sure to use an active email address,
as we will be sending you important updates and resources
throughout the week.
When the practice session begins,
you'll head to the Kick Start homepage
and click on the Participate Now button
to get you to the problem dashboard.
In each session, there will be a sample problem
to help you get started.
You will also see four problems, which
you can work your way through in your own time
throughout the week.
You'll notice the scoreboard is hidden.
So you will be the only one able to view your results.
You can jump into the detailed problem statement
by clicking on the title of the problem.
Let's walk through this sample problem
together to familiarize yourself with the platform.
Let's begin with the problem statement.
You have gathered N bags of candy.
And you want to distribute the candy amongst N kids.
The i-th bag contains C of i pieces of candy.
You want to make sure that every kid gets
the same amount of candy and that the number of pieces
of candy they receive is the greatest possible.
Then we've got our input.
The first line gives the number of test cases,
T. Then for each test case, we have N bags
of candy, M kids, and then C1, C2,
all the way to CN pieces of candy per bag.
Finally, for our output, we need to print out
the number of pieces remaining after each child receives
their share according to the rules.
I happen to be a visual person.
So I like to use the sample input
to walk through a specific example
and think through how I'd approached the problem.
For the first sample input, I've got
7 bags of candy, which adds up to 28 pieces.
And I've got 3 kids.
If I start handing out candy, I can give each kid 9 pieces
and have 1 left over.
Remember, each kid needs to receive
the same amount of candy.
OK, so my answer here is 1.
And I think I can avoid manually handing out each piece of candy
by using the modulus operator.
Now it's time to code in the built-in editor
on the right-hand side.
I prefer Python.
So I used Python for this problem.
You can write code in a variety of languages.
So check out the FAQ for all supported languages.
Remember, these problems use standard input
and standard output.
You won't, and in fact you can't,
read from or print to a file.
If you're unfamiliar with how to read in and write out
in your language of choice, the Coding section of the FAQ
has some samples in the most popular languages.
Keep in mind that you can read in the input a little bit
at a time.
You don't have to do it all at once.
Although they sometimes say never trust the inputs,
for Kick Start, you don't need to worry
about verifying whether or not the input is correct.
It is.
I'm going to make a function to process each case.
My function has one argument, the test case number.
I can start by making sure I can read in the input.
Per the problem description, the first input line
of a given case will consist of two integers.
I'll read the line in with the input function
and then split it.
That leaves me with a list of strings.
I'll use the Python map function to turn it into integers
and, finally, make it a tuple with the tuple function.
Then I'll get the candy counts list in a similar way--
read it in, split it, make each element an integer with map,
and, finally, turn it into a list.
For outputting the answer, I'll use
the print function and these new fancy formatted string
literals.
There are lots of ways to format strings.
Use whatever works best for you.
If you're using a different language than Python,
your method of input and output will be slightly different.
See the Coding section of the FAQ
for more details and a few examples.
Now that I've got input and output figured out,
it's time for the actual computation work.
In our case, we need to sum up all the candy bags
to get the total number of pieces of candy.
I do this by looping through the candy_counts list
and adding each count to my total.
Then I calculate the amount of candy remaining
with total_candy, modulo, num_kids.
That handles an individual test case.
So as a final step, we loop through and process each case.
One gotcha here-- our outputs start with case number 1.
But our loop starts with 0.
So I add 1 to the case num make sure it gets printed out
correctly.
And then we're ready to submit our code here.
You can also test your code on our servers
by toggling the Test Run Mode button before actually
clicking Submit.
Judgments of your code will show up in the top left.
One last tip-- don't forget to carefully read how
the output should be formatted.
In our case here, it's the word case,
then pound, case number, colon, followed by your answer.
Remember that for each problem, your code
is going to be tested against a whole bunch of cases,
not just the sample cases you see.
This is to make sure that you've thought
about all possible inputs and coded up a solution that
can handle them all.
While you can assume the input will always be valid,
don't forget to spend a bit of time thinking
outside the box around what the inputs could look like.
In other words, think about edge cases.
Keep in mind that the actual problems you get
will likely be a bit more challenging than this one.
But don't worry too much.
The principles of solving a problem are the same.
Now that we've gone through this example problem,
you're ready to get started on solving the other practice
problems.
If you are unsure how to frame your solution, don't worry.
We've got you covered.
Download the starter code offered in Java, C++,
and Python at the top of the problem statement to help you
get started on your solution.
If you need additional assistance,
please utilize our Ask a Question button
on the dashboard, where a Googler will be able to jump in
and provide support.
You can also post on our Facebook group
to connect with the community, ask questions, and get
helpful tips from fellow coders.
Have a great week coding and learning more about Kick Start.
Grab a friend or two, practice, and, most importantly,
have fun.
See you at the end of the week on our on-demand video
page for our problem walkthrough stream
to watch how you can go about solving the problems you just
attempted.
Now, go get coding.
[MUSIC PLAYING]