
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Boss Fight in Python
Suppose we have a binary list called fighters and another list of binary lists called bosses. In fighters list the 1 is representing a fighter. Similarly, in bosses list 1 representing a boss. That fighters can beat a boss’s row if it contains more fighters than bosses. We have to return a new bosses matrix with defeated boss rows removed.
So, if the input is like fighters = [0,1,1]
0 | 1 | 1 |
0 | 0 | 0 |
0 | 0 | 1 |
0 | 1 | 1 |
1 | 1 | 1 |
then the output will be
0 | 1 | 1 |
1 | 1 | 1 |
To solve this, we will follow these steps −
fighter_cnt := sum of all elements of fighters
result := a new list
for each row in bosses, do
if fighter_cnt <= sum of each element in row, then
insert row at the end of result
return result
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, fighters, bosses): fighter_cnt = sum(fighters) result = [] for row in bosses: if fighter_cnt <= sum(row): result.append(row) return result ob = Solution() fighters = [0, 1, 1] bosses = [[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1]] print(ob.solve(fighters, bosses))
Input
[0, 1, 1], [[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1]]
Output
[[0, 1, 1], [1, 1, 1]]
- Related Articles
- The Fight
- Top Qualities of a Great Boss
- Crack Alphabets fight problem in JavaScript
- How to deal with a cynical boss?
- Fight or Flight Response: Meaning & Significance
- 6 Nutrients That Fight Erectile Dysfunction
- How to answer an arrogant boss without affecting egos of either?
- Boss vs Leader: Differences and Key Characteristics to Identify a Leader
- 7 Foods That Fight Back: Immune System Boosters
- 20 Foods That Can Help Fight Sugar Cravings
- The 10 Best Foods to Help Fight Stress
- Big Boss Tamil 2: Kamal Hassan opens the show on a high note
- What are some of the best quotes from Fight Club?
- Should You Get New COVID-19 Booster to Fight Omicron?
- What are the top four foods to help you fight against fatigue?

Advertisements