Infosys SP / DSE coding mock 1

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: Most identical pieces (Easy, 20 marks)

You may rearrange the letters of S in any order, then cut it into pieces that are all identical. What is the largest number of pieces you can get?

Input: One line: S.

Output: The largest number of identical pieces.

Constraints: 1 ≤ |S| ≤ 10^5; lowercase letters.

Input:
aabbcc

Output:
2

More examples and a hint

Problem 2: Maximum monsters defeated (Medium, 30 marks)

You start with E experience points. Monster i needs at least power[i] points to beat, and beating it gives you bonus[i] more points. If you fight a monster you cannot beat, you lose. You may fight the monsters in any order. What is the largest number you can defeat?

Input: First line: N and E. Second line: N powers. Third line: N bonuses.

Output: The largest number of monsters defeated.

Constraints: 1 ≤ N ≤ 10^5; 0 ≤ E, power[i], bonus[i] ≤ 10^9.

Input:
3 1
1 2 10
1 1 5

Output:
2

More examples and a hint

Problem 3: Make a binary string as small as possible (Hard, 50 marks)

A binary string S of length N stands for a number. You have CASH coins. Swapping any two characters costs A coins and flipping one character costs B coins; you can only do an operation you can pay for. Make the number as small as possible and print it modulo 10^9 + 7.

Input: First line: N. Second line: S. Third line: CASH A B.

Output: The smallest number modulo 10^9 + 7.

Constraints: 1 ≤ N ≤ 1000; 0 ≤ CASH ≤ 10^9; 1 ≤ A, B ≤ 10^9.

Input:
5
11010
4 1 3

Output:
3

More examples and a hint

Infosys test pattern and mock tests · All coding practice