TCS NQT Full Mock 1: Advanced Coding

Part 2 of TCS NQT Full Mock 1: two problems in 90 minutes, like the Advanced Coding section that Digital and Prime need. Practice problems written for this site in the style of the real test.

2 problems, 90 minutes, marks 50 / 50.

Problem 1: The date after N days (Medium, 50 marks)

Given a date in the form dd.mm.yyyy and a number N, print the date N days later in the same form. Use the usual calendar: a year is a leap year if it is divisible by 4, except years divisible by 100 that are not divisible by 400.

Input: First line: the date dd.mm.yyyy. Second line: N.

Output: The date N days later, as dd.mm.yyyy.

Constraints: The year is from 1900 to 2100; 0 ≤ N ≤ 10^6.

Input:
28.02.2024
1

Output:
29.02.2024

More examples and a hint

Problem 2: Best profit with at most K trades (Hard, 50 marks)

The price of a share is known for N days. A trade is buying one share on one day and selling it on a later day. You may hold at most one share at a time and make at most K trades. Find the largest total profit (0 if no trade helps).

Input: First line: N and K. Second line: N prices.

Output: The largest total profit.

Constraints: 1 ≤ N ≤ 10^5; 1 ≤ K ≤ 100; 1 ≤ price ≤ 10^4.

Input:
6 2
3 2 6 5 0 3

Output:
7

More examples and a hint

TCS NQT test pattern and mock tests · All coding practice