TCS NQT Full Mock 3: Advanced Coding
Part 2 of TCS NQT Full Mock 3: 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: Subarrays with sum K (Medium, 50 marks)
Count the contiguous subarrays whose elements add up to exactly K.
Input: First line: N. Second line: N integers (may be negative). Third line: K.
Output: The number of subarrays.
Constraints: 1 ≤ N ≤ 10^5.
Input:
5
1 2 3 -2 2
3
Output:
4Problem 2: Most profitable set of jobs (Hard, 50 marks)
N jobs each have a start time, an end time and a profit. Choose jobs that do not overlap (a job ending at time t allows another to start at t) to make the total profit as large as possible.
Input: First line: N. Next N lines: start, end and profit.
Output: The largest total profit.
Constraints: 1 ≤ N ≤ 10^5; 0 ≤ start < end ≤ 10^9; 1 ≤ profit ≤ 10^4.
Input:
4
1 3 50
2 5 20
3 6 70
5 7 30
Output:
120