-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClevertap Backend Engineer Hiring Challenge hackerearth question 1
More file actions
72 lines (55 loc) · 2.81 KB
/
Clevertap Backend Engineer Hiring Challenge hackerearth question 1
File metadata and controls
72 lines (55 loc) · 2.81 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Question 1:
Mismatched Payments
CleverTap sends out invoices to all clients on the first day of each month, billed for the last month. For example, March’s invoice will be generated on the 1st of April. Some of the clients have their credits cards on file (billed automatically), and some choose to pay via cheques (posted to our office).
Our finance team needs to verify whether the cheque amount matches the due amount on the invoice generated or not.
Implement an efficient algorithm which is capable of handling 100,000,000 accounts. There will be no duplicate accounts.
Function description
You will be given all the account names and their dues (invoice amounts). You will also be given all the account names which have paid nu cheques and the amount that they paid.
You will have to write a function countMismatchedPayments. The function must return an integer denoting the number of accounts which haven’t paid the exact invoice amount.
countMismatchedPayments has the following parameters:
accountNames: an array of n strings, where each accountNames[i] is the name of an account
dues: an array of n integers, where each dues[i] is the invoiced amount for accountNames[i]
accountsPayingByCheques: an array of m strings containing the name of each account which pays by a cheque
chequeAmounts: An array of m integers, where each chequeAmounts[j] contains the cheque amount presented by accountsPayingByCheques[j].
Input
A number n denoting the number of accounts, followed by n lines - each containing the account name
A number n denoting the number of dues (same as the previous n), followed by n lines - each containing the account dues
A number m denoting accounts that have paid, followed by m lines - each containing account name
A number m denoting the amounts (same as previous m), followed by m lines - each containing the amount paid
Output
Number of accounts whose dues don’t match the paid amount
Constraints
1≤n≤100,000,000
1≤m≤n
#code
def countMismatchedPayments (n, accountNames, dues, m, accountsPayingByCheques, chequeAmounts):
c=0;
for i in range(0,m):
if(accountsPayingByCheques[i] in accountNames):
ind=accountNames.index(accountsPayingByCheques[i])
amt=dues[ind]
if(chequeAmounts[i]!=amt):
c=c+1;
else:
continue
return c;
n = int(input())
accountNames = []
for _ in range(n):
accountNames.append(input())
n = int(input())
dues = []
for _ in range(n):
temp = int(input())
dues.append(temp)
m = int(input())
accountsPayingByCheques = []
for _ in range(m):
accountsPayingByCheques.append(input())
m = int(input())
chequeAmounts = []
for _ in range(m):
temp = int(input())
chequeAmounts.append(temp)
out_ = countMismatchedPayments(n, accountNames, dues, m, accountsPayingByCheques, chequeAmounts)
print (out_)