Coding Exercise A and B Solution