Campus Day 1 Assessment: Coding
Two previously asked problems (one easy, one medium) reported from TCS, Wipro, Infosys, Accenture and HCLTech tests. Python, JavaScript, C, C++ and Java are allowed.
2 problems, 40 minutes, marks 40 / 60.
Problem 1: First non-repeating character (Easy, 40 marks)
Print the first character of the string that appears exactly once. If there is none, print -1.
Input: One line: the string.
Output: A character, or -1.
Constraints: 1 ≤ length ≤ 10^5.
Input:
swiss
Output:
wProblem 2: Subarrays with sum K (Medium, 60 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:
4