Infosys SP / DSE coding mock 3
One easy, one medium and one hard problem in 3 hours, like the reported pattern (20, 30 and 50 marks).
3 problems, 3 hours, marks 20 / 30 / 50.
Problem 1: Maximum profit from sandwiches (Easy, 20 marks)
You have B slices of bread and F fillings. A plain sandwich uses 2 slices and 1 filling and sells for X; a club sandwich uses 3 slices and 2 fillings and sells for Y. Make any number of each so that the total money is as large as possible.
Input: One line: B F X Y.
Output: The largest total money.
Constraints: 0 ≤ B, F ≤ 10^6; 1 ≤ X, Y ≤ 10^6.
Input:
6 4 3 5
Output:
10Problem 2: Fewest changes to make a mountain (Medium, 30 marks)
A mountain array rises by exactly 1 per step from both ends towards the middle, with equal values at matching distances from the two ends, for example 1 2 3 2 1 or 6 7 8 8 7 6. Find the fewest elements you must change to turn the array into a mountain (values may become zero or negative).
Input: First line: N. Second line: N integers.
Output: The fewest changes.
Constraints: 1 ≤ N ≤ 10^5; |A[i]| ≤ 10^9.
Input:
5
1 2 3 2 1
Output:
0Problem 3: Largest XOR using at most half the numbers (Hard, 50 marks)
You are given N numbers, where N is even. Choose at most N/2 of them (from any positions) so that the XOR of the chosen numbers is as large as possible. Print that XOR.
Input: First line: N. Second line: N integers.
Output: The largest XOR.
Constraints: 2 ≤ N ≤ 120, N even; 1 ≤ A[i] < 2^14.
Input:
2
1 2
Output:
2