Previous Next> Wael is a well-known stock market trader. Wael owes his success to his…
- User
Previous
Next>
Wael is a well-known stock market trader. Wael owes his success to his foresight. If Wael Invests in day 1, he will earn A[1] dollars, If he invests at day 2 he will earn A[2] dollars, and so on until day N.
He has to choose a sub-sequence of days (not necessarily consecutive) to invest in stocks such that the following conditions are met:
• The investment on Nth day must be made.
• He can invest on day i after investing on day į only if i -j <= D.
Wael allows you to invest along with him if A[i] is strictly larger than all A[j] days in which he had previously invested for all days (1 <= j < i).
You need to find the maximum possible number of days on which Wael will allow you to invest with him.
Function description
Complete the invest function in the editor below. It has the following parameter(s):
Name
Type
Description
N
INTEGER
The number of days.
D
INTEGER
The described integer D.
A
INTEGER ARRAY
The array describing earnings at each day.
Return
The function must return an INTEGER denoting the maximum possible number of days on which Wael will allow you to invest with him. code in cpp
- Assistant
To solve this problem, we need to implement a function that finds the longest subsequence of investment days such that:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.