- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# 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 Articles
- 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
- Python – Elements with factors count less than K
- 8085 program to count number of elements which are less than 0A
- 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++
- Program to count number of elements are placed at correct position in Python
- Maximum sum subsequence with at-least k distant elements in C++
- Find the number of elements greater than k in a sorted array using C++
- Number of elements less than or equal to a given number in a given subarray in C++
- Program to find largest average of sublist whose size at least k in Python
- Program to split lists into strictly increasing sublists of size greater than k in Python
- Program to count number of sublists with exactly k unique elements in Python

Advertisements