IBM CODING ASSESSMENT - IBM US - Standard - Data Science

ibm logo
ibm
Data ScienceUS
March 31, 202510 reads

Summary

I participated in an IBM US coding assessment for a Data Science role, which focused on designing an API rate-limiting system.

Full Experience

My coding assessment for IBM US, intended for a Data Science position, required me to design and implement an API rate-limiting system according to specified constraints. The problem statement detailed the requirements for handling incoming domain requests within various time windows, checking both 5-second and 30-second limits.

Interview Questions (1)

Q1
API Rate Limiting System
Data Structures & AlgorithmsHard

You are tasked with designing an API rate-limiting system that processes incoming requests while enforcing request limits. Given an array of domain requests, each request occurs at a specific second. The API gateway applies the following rate limits:

  • A domain can make at most 2 requests within a 5-second window.
  • A domain can make at most 5 requests within a 30-second window.

Write a function getDomainRequestStatus(requests) that determines whether each request can be processed. The function should return:

  • {status: 200, message: OK} if the request is allowed.
  • {status: 429, message: Too many requests} if the request exceeds the rate limit.

Input Format

  • requests: A list of domain names representing incoming requests.

Example

requests = ["www.xyz.com", "www.abc.com", "www.xyz.com", "www.pqr.com", "www.abc.com", "www.xyz.com", "www.xyz.com"]
print(getDomainRequestStatus(requests))

Expected Output

["{status: 200, message: OK}", 
 "{status: 200, message: OK}", 
 "{status: 200, message: OK}", 
 "{status: 200, message: OK}", 
 "{status: 200, message: OK}", 
 "{status: 200, message: OK}", 
 "{status: 429, message: Too many requests}"]

Constraints

  • The function should efficiently track request timestamps for each domain.
  • It should remove outdated requests beyond the 30-second window.
  • It must check both 5-second and 30-second limits before allowing a request.
Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!