-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCount the elements.py
45 lines (34 loc) · 1012 Bytes
/
Count the elements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#User function Template for python3
class Solution:
def countElements(self, a, b, n, query, q):
b.sort()
out = []
for i in query:
temp = 0
left, right = 0, len(b)-1
while left <= right:
mid = (left + right) // 2
if b[mid] <= a[i]:
temp = mid + 1
left = mid + 1
else:
right = mid - 1
out.append(temp)
return out
#{
# Driver Code Starts
#Initial Template for Python 3
t = int(input())
for _ in range(0, t):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
q = int(input())
query = []
ob = Solution()
for i in range(q):
query.append(int(input()))
ans = ob.countElements(a, b, n, query, q)
for i in range(q):
print(ans[i])
# } Driver Code Ends