- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

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

Suppose we have a list of elements called nums, and a value k. We have to find those elements which have occurred at least k number of times.

So, if the input is like nums = [2,5,6,2,6,1,3,6,3,8,2,5,9,3,5,1] k = 3, then the output will be [2, 5, 6, 3]

To solve this, we will follow these steps −

- c := a list containing frequencies of each elements present in nums
- res := a new list
- for each key n in c, do
- if c[n] >= k, then
- insert n at the end of res

- if c[n] >= k, then
- return res

Let us see the following implementation to get better understanding −

from collections import Counter def solve(nums, k): c = Counter(nums) res = [] for n in c: if c[n] >= k: res.append(n) return res nums = [2,5,6,2,6,1,3,6,3,8,2,5,9,3,5,1] k = 3 print(solve(nums, k))

[2,5,6,2,6,1,3,6,3,8,2,5,9,3,5,1], 3

[2, 5, 6, 3]

- Related Questions & Answers
- Program to find k where k elements have value at least k in Python
- Find all elements in array which have at-least two greater elements in C++
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Program to remove string characters which have occurred before in Python
- Count all elements in the array which appears at least K times after their first occurrence in C++
- Program to find number of elements in A are strictly less than at least k elements in B in Python
- Program to find largest average of sublist whose size at least k in Python
- Maximum sum subsequence with at-least k distant elements in C++ program
- Program to find a sub-list of size at least 2 whose sum is multiple of k in Python
- Program to find minimum sum subsequence by taking at least one element from consecutive 3 elements in python
- Program to find length of longest substring with character count of at least k in Python
- Program to find length of longest increasing subsequence with at least k odd values in Python
- Python program to check if two lists have at least one common element
- Maximum sum subsequence with at-least k distant elements in C++
- Program to find three unique elements from list whose sum is closest to k Python

Advertisements