IBM interview question

2 Moderate level DSA Question.