Given a list of integers, the task is to find N largest elements assuming size of list is greater than or equal o N.

**Examples :**

Input : [4, 5, 1, 2, 9] N = 2 Output : [9, 5] Input : [81, 52, 45, 10, 3, 2, 96] N = 3 Output : [81, 96, 52]

A simple solution traverse the given list N times. In every traversal, find the maximum, add it to result, and remove it from the list. Below is the implementation :

`# Python program to find N largest ` `# element from given list of integers ` ` ` `# Function returns N largest elements ` `def` `Nmaxelements(list1, N): ` ` ` `final_list ` `=` `[] ` ` ` ` ` `for` `i ` `in` `range` `(` `0` `, N): ` ` ` `max1 ` `=` `0` ` ` ` ` `for` `j ` `in` `range` `(` `len` `(list1)): ` ` ` `if` `list1[j] > max1: ` ` ` `max1 ` `=` `list1[j]; ` ` ` ` ` `list1.remove(max1); ` ` ` `final_list.append(max1) ` ` ` ` ` `print` `(final_list) ` ` ` `# Driver code ` `list1 ` `=` `[` `2` `, ` `6` `, ` `41` `, ` `85` `, ` `0` `, ` `3` `, ` `7` `, ` `6` `, ` `10` `] ` `N ` `=` `2` ` ` `# Calling the function ` `Nmaxelements(list1, N) ` |

*chevron_right*

*filter_none*

Output :

[85, 41]

Time Complexity : O(N * size) where size is size of the given list.

Method 2:

`# Python program to find N largest ` `# element from given list of integers ` ` ` `l ` `=` `[` `1000` `,` `298` `,` `3579` `,` `100` `,` `200` `,` `-` `45` `,` `900` `] ` `n ` `=` `4` ` ` `l.sort() ` `print` `(l[` `-` `n:]) ` |

*chevron_right*

*filter_none*

Output:

[-45, 100, 200, 298, 900, 1000, 3579] Find the N largest element: 4 [298, 900, 1000, 3579]

Please refer k largest(or smallest) elements in an array for more efficient solutions of this problem.

Attention geek! Strengthen your foundations with the **Python Programming Foundation** Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the **Python DS** Course.

## Recommended Posts:

- Python Program to Print Largest Even and Largest Odd Number in a List
- Python | Largest, Smallest, Second Largest, Second Smallest in a List
- Python program to find largest number in a list
- Python program to find second largest number in a list
- Python | Indices of N largest elements in list
- Python | Find frequency of largest element in list
- Python program to find number of m contiguous elements of a List with a given sum
- Python program to find Tuples with positive elements in List of tuples
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Python program to find the frequency of the elements which are common in a list of strings
- Python program to find sum of elements in list
- Python Program for Find largest prime factor of a number
- Python Program to find largest element in an array
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Python | Convert List of String List to String List
- Python | Maximum sum of elements of list in a list of lists
- Python | Replace elements in second list with index of same element in first list
- Python | Sorting list of lists with similar list elements
- Python | Indices of sorted list of list elements

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.