1.You have been given the responsibility to prepare the next campus test. You are given two lists of difficulties and points both of size n whose ith element represents difficulty and point of the ith question respectively.
There is one restriction on choosing the questions, that is, there cannot be a pair of questions such that one has higher difficulty but the other has higher points.
Select questions in a way that maximises sum of their points.
Return the sum of points of selected questions.
Example 1:
Input: difficulties = [1,2,3,4], points = [5,10,11,12]
Output: 38
Explanation: Select all questions
Example 2:
Input: difficulties = [1,18,5], points = [10,15,20]
Output: 30
Explanation: 2nd and 3rd questions cannot be selected together.
Each employee can complete a number of tasks each day before the day ends.As the CEO is your responsibility to track for each employee the first day at the end of which they are overwhelmed.
The ith employee has a limit of tasks N[i].At the end of day the number of new tasks per employee is 1 and j new tasks on the jth day.
An employee i can complete up to k[i] tasks each day before the end of that day, and if there are no tasks left they remain idle.
Example
t=1.N=[6],k=[2]
Day 1:No tasks at the start of day 1.Hence,the employee remains idle.1 task gets added at the end of the day.
Day 2: The employee completes the task and becomes idle.2 tasks are added to his workload at the end of the day leaving the employee with a workload of 2 tasks.
Day 3: 2 tasks are completed and 3 tasks gets added at the end of the day.
Day 4: 2 tasks done,1 pending task.4 more tasks gets added at the end of the day,leaving workload at 5
Day 5: Employee completes 2 tasks,leaving 3 pending tasks.5 more tasks get added making the employee overwhelmed.
Hence, the answer is [5].
3.Given array arr of length n, we define function f(arr) as,
if n = 1, f(arr) = arr[1]
else, f(arr) = f(arr[1]^arr[2], arr[2]^ arr[3],..., arr[n - 1] ^ arr[n])
where, ^ is bitwise XOR operator.
For example, arr = [1, 2, 4, 8], n = 4
f(1, 2, 4, 8) = f(1^2, 2^4, 4^8) = f(3, 6, 12) = f(3^6, 6^12) = f(5, 10) = f(5^10) =
f(15) = 15.
You need to answer q queries, each query you are given two integers I and r.
For each, what is the maximum of f for all continuous subsegments of the
array arr[l], arr[l+1],..., arr[r].
Constraints:
1<= n <= 5000
0<=arr[i]<= 2^30 - 1
1<=q <= 10^5
1<=l<=r<=n
Sample Testcase
Input
n = 6
arr = [1, 2, 4, 8, 16, 32]
q=4
queries = [[1, 6].[2, 5],[3, 4],[1, 2]]
Output
[60, 30, 12, 3]
Can aynone share efficient approaches for these questions.