Challenge EngineeringIntern-CodingChallenge UserSessions
Challenge EngineeringIntern-CodingChallenge UserSessions
Engineering Intern
A coding challenge for the engineering intern role at Slang
Overview
This document describes a coding challenge for engineering students looking to work as an
intern with Slang. We expect that you spend a maximum of two hours to develop a solution
that answers the problem listed below.
Feel free to submit your work quickly if you feel that you’ve adequately demonstrated your
abilities. Be sure to balance code quality, performance and productivity, and keep in mind that
we take attention to detail very seriously!
The task is based on a two-step real-world task that we’ve had to solve, and while it’s been
boiled down into specifications appropriate for a short development assessment, it is still
representative of some of the work you’d be exposed to in this role. We suggest that you read
through everything here — it’s a quick read — before starting. And, as always, let us know if
you have any questions or comments! I will be available to answer any questions at
[email protected] at any point throughout the day/night.
1/7
Specifications
The descriptions here are intentionally a bit free-form — we’d like you to make most of the
decisions yourself.
First Step
We’d like you to write a simple program that fetches some data from one of our REST APIs
(you’ll be given access before you start your challenge and we’ll share authentication header
needed), parses the received JSON to produce a new data structure, and posts the results to
another endpoint.
Request
GET https://api.slangapp.com/challenges/v1/activities
Content-Type: application/json
Authorization: Basic MTpC__SAMPLE__VjPQ== ← replace this with your key
Response
200
{"activities":
"id": 198891,
"user_id": "emr5zqid",
"answered_at": "2021-09-13T02:38:34.117-04:00",
"first_seen_at": "2021-09-13T02:38:16.117-04:00"
},
"id": 43990,
"user_id": "emr5zqid",
"answered_at": "2021-09-13T02:42:07.117-04:00",
"first_seen_at": "2021-09-13T02:41:51.117-04:00"
2/7
},
"id": 37191,
"user_id": "emr5zqid",
"answered_at": "2021-09-14T00:31:36.117-04:00",
"first_seen_at": "2021-09-14T00:31:25.117-04:00"
},
...
Or in case of error:
401 Unauthorized
You will get a JSON array containing a list of a few hundred “activities” in no particular order.
Each activity object has its unique ID, the unique ID of the user that answered that activity, a
first seen at timestamp and an answered at timestamp, both in UTC and ISO 8601 compliant.
Second Step
We’d like you to process this document so that we can get a list of user-sessions from these
activities. A user-session is defined as the time between first_seen_at of the first user’s activity
to the answered_at of the latest activity for a given user, as long as there isn’t more than 5
minutes between answered_at and first_seen_at. If more than 5 minutes have elapsed
between these two dates, we consider this a new user session. For example:
3/7
These user session objects should:
"user_sessions": {
"3pyg3scx": [
"ended_at": "2021-09-10T19:51:26.799-04:00",
"started_at": "2021-09-10T19:22:23.799-04:00",
"activity_ids": [
251953,
4/7
379044
],
"duration_seconds": 173.0
},
"ended_at": "2021-09-11T04:33:50.799-04:00",
"started_at": "2021-09-11T04:05:20.799-04:00",
"activity_ids": [
296400,
247727,
461955
],
"duration_seconds": 171.3
],
"5lqea95d": [
"ended_at": "2021-09-08T13:45:49.803-04:00",
"started_at": "2021-09-08T13:33:57.803-04:00",
"activity_ids": [
199554,
262339,
434783,
461142
],
"duration_seconds": 712.0
},
],
...
5/7
}
Notice how this “user_sessions” object is a dictionary where the keys are the user_ids and
the values are the array of user sessions for that user.
Third step
Once you have this new JSON data structure ready, you need to post it to another endpoint.
The format of this endpoint is:
Request
POST https://api.slangapp.com/challenges/v1/activities/sessions
Content-Type: application/json
Authorization: Basic MTpC__SAMPLE__VjPQ== ← replace this with your key
Body: {“user_sessions”: {...}}
Response
204 No content
Or in case of error:
401 Unauthorized
Sample code
Here’s some sample python code that deals with the API endpoints, feel free to use in your
solution (you can also choose whatever language you feel more comfortable with, other
languages have similar libraries to deal with API endpoints):
import requests
activities_response = requests.get("https://api.slangapp.com/challenges/v1/activities",
6/7
# activities_response.json() now gives you a python array of activities. You can now start
# iterating this array so you can start grouping by user sessions as per the spec.
# How would you implement this? This is the core of the challenge!
requests.post("https://api.slangapp.com/challenges/v1/activities/sessions",
Bonus question
Can you provide an accurate runtime complexity analysis for your algorithm?
Submission
In addition to submitting your answer to the endpoint provided in the third step, you should
submit your algorithms as a GitHub repository. You should share your repository with me
(username ricardovj), and you should use the repository as you would for any other project —
commit early and often! We’re interested in seeing the history of your work, too.
All right — that’s it. Thanks for reading through this, and let me know if you have any questions
or comments. We’re excited to see what you come up with!
7/7