- 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

# Program to find number of elements in A are strictly less than at least k elements in B in Python

Suppose we have two lists of numbers A and B, and another value k, we have to find the number of elements in A that are strictly less than at least k elements in B.

So, if the input is like A = [6, -2, 100, 11] B = [33, 6, 30, 8, 14] k = 3, then the output will be 3, as -2, 6, and 11 are strictly less than 3 elements in B.

To solve this, we will follow these steps −

- if k is same as 0, then
- return size of A

- sort B in reverse order
- ct := 0
- for each i in A, do
- if i < B[k - 1], then
- ct := ct + 1

- if i < B[k - 1], then
- return ct

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, A, B, k): if k == 0: return len(A) B.sort(reverse=True) ct = 0 for i in A: if i < B[k - 1]: ct += 1 return ct ob = Solution() A = [6, -2, 100, 11] B = [33, 6, 30, 8, 14] k = 3 print(ob.solve(A, B, k))

## Input

[6, -2, 100, 11], [33, 6, 30, 8, 14], 3

## Output

3

- Related Questions & Answers
- Program to find k where k elements have value at least k in Python
- Python Program to remove elements that are less than K difference away in a list
- Program to find elements from list which have occurred at least k times in Python
- 8085 program to count number of elements which are less than 0A
- Python – Elements with factors count less than K
- Program to find list of elements which are less than limit and XOR is maximum in Python
- Maximum sum subsequence with at-least k distant elements in C++ program
- Maximum value K such that array has at-least K elements that are >= K in C++
- Maximum sum subsequence with at-least k distant elements in C++
- Program to count number of elements are placed at correct position in Python
- Find the number of elements greater than k in a sorted array using C++
- Program to find largest average of sublist whose size at least k in Python
- Number of elements less than or equal to a given number in a given subarray in C++
- Find all elements in array which have at-least two greater elements in C++
- Two Sum Less Than K in Python

Advertisements