- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find number of tasks can be finished with given conditions in Python

Suppose we have a list of tasks and another list of people. The tasks[i] determines the amount of strength required to perform the ith task. And the people[i] determines the amount of strength the ith person has. Finally, we have to find the number of tasks that can be finished if one person can perform at most one task.

So, if the input is like tasks = [4, 3, 9, 15], people = [10, 5, 3, 2], then the output will be 3, as the first person can perform task 9, second person can perform task 4, third person can perform task 3, and fourth person can't perform any tasks.

To solve this, we will follow these steps −

- sort the list tasks, sort the list people
- ct:= 0, ind:= 0
- for i in range 0 to size of people, do
- for j in range ind to size of tasks, do
- if people[i] >= tasks[j], then
- ct := ct + 1
- ind := ind + 1
- come out from the loop

- otherwise,
- come out from the loop

- if people[i] >= tasks[j], then

- for j in range ind to size of tasks, do
- return ct

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, tasks, people): tasks.sort() people.sort() ct=0 ind=0 for i in range(len(people)): for j in range(ind,len(tasks)): if people[i]>=tasks[j]: ct+=1 ind+=1 break else: break return ct ob = Solution() tasks = [4, 3, 9, 15] people = [10, 5, 3, 2] print(ob.solve(tasks, people))

## Input

[4, 3, 9, 15], [10, 5, 3, 2]

## Output

3

- Related Articles
- Program to check number of requests that will be processed with given conditions in python
- Program to check all tasks can be executed using given server cores or not in Python
- Program find number of subsets of colorful vertices that meets given conditions in Python
- Program to find number of elements in all permutation which are following given conditions in Python
- Program to find minimum time required to complete tasks with k time gap between same type tasks in Python
- Program to find out number of blocks that can be covered in Python
- Program to find maximum time to finish K tasks in Python
- Program to find minimum time to complete all tasks in python
- Program to find number of solutions for given equations with four parameters in Python
- Program to find length of longest word that can be formed from given letters in python
- Check if the given array can be reduced to zeros with the given operation performed given number of times in Python
- Program to find number of bit 1 in the given number in Python
- Python Program to find out the number of rooms in which a prize can be hidden
- Program to find number of possible BSTs can be generated using n distinct nodes in Python
- Program to count number of palindromes of size k can be formed from the given string characters in Python

Advertisements