- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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]
then the output will be
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
Let us see the following implementation to get better understanding −
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))
[0, 1, 1], [[0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1]]
[[0, 1, 1], [1, 1, 1]]
- How to deal with a cynical boss?
- What are some of the best quotes from Fight Club?
- How to answer an arrogant boss without affecting egos of either?
- What are the top four foods to help you fight against fatigue?
- Big Boss Tamil 2: Kamal Hassan opens the show on a high note
- I ruined an exam just because I was constantly thinking of a fight I had with my friend in past. How to avoid this in future?
- Bigg Boss Telugu creating news as Nani slaps a legal case on Sri Reddy for defamation and demands unconditional apology within 7 days
- ChainMap in Python
- Namedtuple in Python
- Deque in Python
- OrderedDict in Python
- Quine in Python
- Underscore(_) in Python
- Multiprocessing In Python