Code RoomFilter contacts by email domain
MediumPrep Room Coding #5041

Filter contacts by email domain

CodingAlgorithms & data structuresMid–Senior~9 min

Given `contacts` with columns `email` and `name`, and a domain such as `x.com`, return the rows whose `email` ends with that domain. Return `email` and `name`, sorted by `email` ascending and then `name` ascending.

Implement
at_domain(contacts: dataframe, domain: str) → dataframe
Examples
in[{"__df__":[{"name":"Ann","email":"a@x.com"},{"name":"Bob","email":"b@x.com"},{"name":"Ann","email":"a@x.com"},{"name":"Cy","email":"c@x.com"},{"name":"Bobby","email":"b@x.com"}]},"x.com"]out[{"name":"Ann","email":"a@x.com"},{"name":"Ann","email":"a@x.com"},{"name":"Bob","email":"b@x.com"},{"name":"Bobby","email":"b@x.com"},{"name":"Cy","email":"c@x.com"}]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 9 min
InputExpectedGot
[{"__df__":[{"name":"Ann","email":"a@x.com"},{"name":"Bob","email":"b@x.com"},{"name":"Ann","email":"a@x.com"},{"name":"Cy","email":"c@x.com"},{"name":"Bobby","email":"b@x.com"}]},"x.com"][{"name":"Ann","email":"a@x.com"},{"name":"Ann","email":"a@x.com"},{"name":"Bob","email":"b@x.com"},{"name":"Bobby","email":"b@x.com"},{"name":"Cy","email":"c@x.com"}]not run yetsample