Bird
Raised Fist0
HLDsystem_design~10 mins

Online presence system in HLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main component that tracks user status.

HLD
class PresenceTracker {
  constructor() {
    this.users = new Map();
  }

  updateStatus(userId, status) {
    this.users.set(userId, [1]);
  }
}
Drag options to blanks, or click blank then click option'
Athis
Bstatus
CuserId
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using userId instead of status as the value.
Trying to assign this or users instead of status.
2fill in blank
medium

Complete the code to check if a user is currently online.

HLD
isUserOnline(userId) {
  return this.users.get(userId) === [1];
}
Drag options to blanks, or click blank then click option'
A'away'
B'offline'
C'online'
D'busy'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'offline' instead of 'online'.
Using a status that means away or busy.
3fill in blank
hard

Fix the error in the method that removes a user from the presence map.

HLD
removeUser(userId) {
  this.users.[1](userId);
}
Drag options to blanks, or click blank then click option'
Adelete
Bpop
Cdiscard
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove or pop which are not Map methods.
Using discard which is from other languages.
4fill in blank
hard

Fill both blanks to create a method that returns all users currently online.

HLD
getOnlineUsers() {
  return [...this.users.entries()].filter(([[1], [2]]) => [2] === 'online').map(([userId]) => userId);
}
Drag options to blanks, or click blank then click option'
AuserId
Bstatus
Cuser
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping userId and status names.
Using incorrect variable names that don't match the pair.
5fill in blank
hard

Fill all three blanks to implement a method that returns a count of users by status.

HLD
countByStatus() {
  const counts = {};
  for (const [1] of this.users.values()) {
    counts[[2]] = (counts[[3]] || 0) + 1;
  }
  return counts;
}
Drag options to blanks, or click blank then click option'
Astatus
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'user' instead of 'status' as the loop variable.
Using different variable names for the key and lookup.