- Related Questions & Answers
- 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++
- Maximum sum subsequence with at-least k distant elements in C++
- Program to count number of elements are placed at correct position in Python
- Program to find largest average of sublist whose size at least k in Python
- Find all elements in array which have at-least two greater elements in C++
- Two Sum Less Than K in Python
- Program to find length of longest substring with character count of at least k in Python
- Print a number strictly less than a given number such that all its digits are distinct in C++
- Program to find length of longest increasing subsequence with at least k odd values in Python
- 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 split lists into strictly increasing sublists of size greater than k in Python

- 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 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 −

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))

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

3

Advertisements