Find Maximum Goals in Penalty Shootout

Duration: 9 min

This video lesson is available to enrolled students.

Enroll to watch — TCS SuperSet Course

AI Summary

An AI-generated summary of this video lecture.

This video is a programming lecture from Knowledge Gate that explains and solves a competitive programming problem. The problem involves two strikers, Lohia and Gosu, and a goalkeeper, Prince, who are practicing penalty shots. The goal is to determine the maximum number of goals each striker can score given their initial energy (X and Y) and the goalkeeper's energy (Z). The rules state that each player's energy decreases by 1 for every attempt, and a goal is scored only if the goalkeeper's energy is greater than 1. The striker with the higher energy gets to shoot first, and the process continues until the goalkeeper's energy reaches 1. The instructor first presents the problem statement, then demonstrates a step-by-step solution on a chalkboard using the example values X=14, Y=8, and Z=5. Finally, the instructor provides a complete C code solution, explaining the logic of the while loop and the conditional checks for each player's turn.

Chapters

  1. 0:00 2:00 00:00-02:00

    The video begins with the Knowledge Gate logo, followed by a slide that introduces the problem. The problem statement is displayed on a screen, which describes a scenario with three footballers: Lohia and Gosu as strikers and Prince as the goalkeeper. The task is to find the maximum number of goals scored by Lohia and Gosu. The rules are that each player's energy (X, Y, Z) decreases by 1 for every attempt, and a goal is only scored if Prince's energy is greater than 1. The input consists of the number of test cases and the three energy values. The output is the number of goals scored by each striker. The instructor, visible in a small window, begins to explain the problem, emphasizing that Lohia, being a junior player, is always favored for the penalty kick, which implies he goes first if both have the same energy.

  2. 2:00 5:00 02:00-05:00

    The instructor transitions to a chalkboard to demonstrate the solution. He writes the initial values for the example: Lohia's energy (X) is 14, Gosu's energy (Y) is 8, and Prince's energy (Z) is 5. He explains the logic step-by-step, showing that Lohia shoots first because his energy is higher. He then simulates the process, writing down the energy levels after each attempt. For instance, after Lohia's first shot, X becomes 13 and Z becomes 4. He continues this process, noting that a goal is scored only when Z > 1. He shows that Lohia scores a goal when Z is 4, 3, 2, and 1, but not when Z is 0. He also demonstrates that Gosu will score goals when his energy is sufficient and Z is still greater than 1. The instructor uses arrows and calculations to illustrate the sequence of events.

  3. 5:00 8:33 05:00-08:33

    The instructor moves to a code editor to provide a C program solution. He writes the code, starting with the necessary header and main function. He initializes variables for the energy values (x, y, z) and counters for goals (count1, count2). He then uses a while loop that continues as long as Prince's energy (z) is greater than 1. Inside the loop, he checks if Lohia's energy (x) is greater than 0. If so, he decrements x and z, and increments the goal counter for Lohia (count1). If Lohia's energy is 0, he checks if Gosu's energy (y) is greater than 0, and if so, he decrements y and z, and increments the goal counter for Gosu (count2). After the loop, he prints the final goal counts. The instructor explains that this logic correctly models the game's rules, ensuring the player with higher energy shoots first and that the game ends when Prince's energy reaches 1.

The video presents a comprehensive tutorial on solving a competitive programming problem. It follows a clear pedagogical structure: first, the problem is stated and its rules are explained. Second, a concrete example is worked through manually on a chalkboard to illustrate the logic and sequence of events. Third, a complete, functional C code solution is provided, with the instructor explaining the algorithm's implementation. The core concept is a simulation of a turn-based game with specific conditions for scoring and termination, which is effectively modeled using a while loop and conditional statements.