Find Maximum Goals in Penalty Shootout

Duration: 9 min

This video lesson is available to enrolled students.

Return to /learn/TCS-NQT-PREPARATION/advanced-coding/coding-questions/coding-question/asset-find-maximum-goals-in-penalty-shootout after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. TCS One Shot Free Videos & Notes: TCS Preparation
  2. Numerical Ability (Foundation Section): Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Mixture and Alligation, Permutation and Combination, Logarithm, Number System, HCF LCM, Sequence and Series (Series), Speed Time and Distance, Percentage, Average, Powers and Exponents (Surds and Indices), Algebra, Probability, Profit and Loss, Simple Interest and Compound Interest, Time and Work, Pipe and Cistern, Mensuration and Geometry, Mental Ability, Age Problems, Statistics, Arithmetic, Partnership, Speed Mathematics and Basic Mathematics
  3. Reasoning Ability (Foundation Section): Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Syllogisms, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Seating Arrangements, Blood Relations, Directions (Direction Test), Analytical Reasoning (Counting Figures Reasoning), Puzzle Solving (Puzzles), Calendar, Clock, Cubes & Dices, Selection Decision Table (Decision Making), Crypt Arithmetic, Venn Diagram, Data Arrangement, Inequality, Analogy, Ranking, Order and Sequence, Logical Sequence Of Words
  4. New Pattern-Verbal Ability (Foundation Section): Sentence Completion (Fill in the blanks), English Writing Ability
  5. Old Pattern-Verbal Ability (Foundation Section): Vocabulary, Noun, Subject Verb Agreement (Verb Noun Agreement), Adjectives, Tenses, Pronoun, Preposition, Articles, Direct and Indirect Speech, Conjunction, Modals, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Correction (Error Correction), Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Verbal Analogy (Word Based Analogy), Active Passive Voice (Voice), Determiner, Facts, Inference and Judgements, Adverb, Cloze Test (Cloze Passage), Sentence Construction, Verb
  6. Advanced Quantitative Ability: TCS NQT Advanced Quantitative Ability
  7. Advanced Reasoning Ability: TCS NQT Advanced Reasoning Ability
  8. Advanced Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Python for Placements by Yash Sir, DSA using Python, Object Oriented Programming (OOPS), Programming in C++, Java
  9. TCS Full Length Mock Test:
  10. TCS Interview & Resume Prep: MR & HR Interview Preparation, TCS Interview Preparation, Mock Interview, Interview Recordings, Resume Preparation, Resume Review
  11. Mega Test:
  12. Grand Test:
AI summary & chapters

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.

Loading lesson…