Infosys SP / DSE coding round, 29 Nov 2026 (another candidate)

The three problems a second candidate remembered from the same day.

3 problems, 3 hours, marks 33 / 33 / 34.

Problem 1: Maximum profit from sandwiches (Easy, 33 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:
10

More examples and a hint

Problem 2: Loose stones (Medium, 33 marks)

Stones 1 to N lie in a line between the near bank (position 0) and the far bank (position N + 1). In the string S, 0 marks a solid stone and 1 a loose one. You can jump 1 place forward for X coins or 2 places for Y coins, but never past N + 1. If you land on a loose stone you slip back one place and stay there. Find the minimum cost to reach N + 1, or print -1 if it is impossible.

Input: First line: N. Second line: S. Third line: X and Y.

Output: The minimum cost, or -1.

Constraints: 1 ≤ N ≤ 10^5; 1 ≤ X, Y ≤ 10^4.

Input:
3
010
1 3

Output:
5

More examples and a hint

Problem 3: Count common substrings (Medium, 34 marks)

Count the pairs (a substring of A, a substring of B) that are equal. Substrings at different positions count separately. For A = aba and B = ab the equal pairs are a–a (twice), b–b and ab–ab, so the answer is 4.

Input: First line: A. Second line: B.

Output: The number of equal pairs.

Constraints: 1 ≤ |A|, |B| ≤ 2000; lowercase letters.

Input:
aba
ab

Output:
4

More examples and a hint

Infosys test pattern and mock tests · All coding practice