A Salesforce consultant evaluates a series of customer accounts represented as an array of integers accounts of size n.
Each integer represents the revenue (positive value) or loss (negative value) generated from interacting with a customer account.
The consultant starts at the first account (index 0) and must finish at the last account (index n-1).
From any account i, the consultant can:
Move to the next adjacent account (i + 1), or Jump to account (i + p), where p is a prime number ending in the digit 3 (e.g. 3, 13, 23, ...).
The objective is to determine the maximum total revenue that can be earned upon reaching the last account. The value at the final account must always be included in the total.
Example accounts = [0, 100, 200, -500, -100, -150, -50]
Optimal path:
0 -> 1 -> 2 -> 5 -> 6
Revenue:
0 + 100 + 200 - 150 - 50 = 100
Hence, the answer is:
100 Function Description
Complete the function:
int maxCustomerRevenue(vector<int> accounts)
Parameters accounts: an integer array representing revenue/loss for each customer. Returns int: the maximum amount of revenue at the end of the evaluation.
Input Format for Custom Testing
The custom testing format is the standard HackerRank format:
n accounts[0] accounts[1] ... accounts[n-1]
1 ≤ n ≤ 10^4 -10^4 ≤ accounts[i] ≤ 10^4 accounts[0] = 0
Adobe • Pending