Introduction

Welcome to today's lesson! We'll explore a practical application of managing student enrollments for various courses using Go maps. Imagine you're operating an online course platform, and you need to efficiently handle enrollments, checks, and listings of students in different courses. Go maps are ideally suited for this problem due to their efficient lookups and storage operations. Furthermore, maps can emulate set behavior, helping us ensure that a student cannot enroll in a course more than once.

By the end of this session, you'll gain practical expertise in managing dynamic collection-like data with maps. Let’s dive in!

Introducing Methods to Implement

Here are the methods we need to implement in our enrollment system:

  • func (es *EnrollmentSystem) enroll(student string, course string): This method adds a student to a course. If the student is already enrolled, it does nothing, effectively behaving like a set addition.
  • func (es *EnrollmentSystem) unenroll(student string, course string) bool: This method removes a student from a course. It returns true if the student was enrolled and is now removed. Otherwise, it returns false. If, after unenrolling the student, the course becomes empty, the course is removed from the system.
  • func (es *EnrollmentSystem) isEnrolled(student string, course string) bool: This method checks if a student is currently enrolled in a given course. It returns true if the student is enrolled, and otherwise.
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal