One mock question (Interviewer even does not know answer). If anyone can help.

Question: (Looking for answer in Java)

  • Basically, input is a Dictionary. The output looks for the number of follower.
  • But, it asks * no dulplicate compute (when you compute person A, you also need to record person B as well ? ) * this requirment confused me, otherwise dfs/bfs is easy to solve. Hence, I guess he just want to go through every person only once.
  • If anyone can help me out, I really appreciate it. Thanks

--- Below is the whole question and test case ---

Test Cases of "Followers" Problem

Input:
follwers = {A: B,
B: C,
C: A
}

Test Code:
cal_followers(followers, A)
cal_followers(followers, B)
cal_followers(followers, C)
cal_followers(followers, D)

Expected Output:
2
2
2
-1

Input:
follwers = {A: B, E, F,
B: C,
C: A
}

Test Code:
cal_followers(followers, A)
cal_followers(followers, B)
cal_followers(followers, C)
cal_followers(followers, D)

Expected Output:
4
4
4
-1

Input:
follwers = {A: B, E, F,
B: C, G,
C: A
}

Test Code:
cal_followers(followers, A)
cal_followers(followers, B)
cal_followers(followers, C)
cal_followers(followers, D)

Expected Output:
5
5
5
-1

Input:
follwers = {A: E, F,
B: F,
C: E
}

Test Code:
cal_followers(followers, A)
cal_followers(followers, B)
cal_followers(followers, C)
cal_followers(followers, D)

Expected Output:
2
1
1
-1

Comments (1)