Classroom Register (Student CRUD)
Programming Interview
Medium
8 views
Problem Description
Maintain a student register. Process q commands: ADD id name, DEL id, GET id, COUNT. Print output for each GET and COUNT.
Input Format
See description.
Output Format
See description.
Sample Test Case
Input:
7
ADD 101 Ravi
ADD 102 Neha
GET 101
DEL 102
GET 102
COUNT
COUNT
Output:
Ravi
NOT_FOUND
1
1
Constraints
Total operations up to 200000.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines or not lines[0].strip():
sys.exit(0)
q=int(lines[0].strip())
reg={}
out=[]
for i in range(1,1+q):
parts=(lines[i] if i < len(lines) else '').split()
if not parts:
continue
cmd=parts[0]
if cmd=='ADD':
sid=parts[1]
name=' '.join(parts[2:])
reg[sid]=name
elif cmd=='DEL':
reg.pop(parts[1],None)
elif cmd=='GET':
out.append(reg.get(parts[1],'NOT_FOUND'))
else:
out.append(str(len(reg)))
sys.stdout.write('\
'.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!