Another day, another layoff

ALSO: Rate Limiting Algorithms

In partnership with

Welcome back!

This week, we'll solve a problem that I was asked in an Apple interview and I could not solve it. Let's see if you can.

Today we will cover:

  • Basic Calculator

  • Rate Limiting Algorithms

Read time: under 4 minutes

CODING CHALLENGE

Basic Calculator

Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.

Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().

Example 1:

Input: s = " 2-1 + 2 "
Output: 3

Example 2:

Input: s = "(1+(4+5+2)-3)+(6+8)"
Output: 23

Solve the problem here before reading the solution.

PRESENTED BY AI WITH ALLIE

Stop Asking AI Questions, and Start Building Personal AI Software.

Feeling overwhelmed by AI options or stuck on basic prompts? The AI Fast Track is your 5-day roadmap to solving problems faster with next-level artificial intelligence.

This free email course cuts through the noise with practical knowledge and real-world examples delivered daily. You'll go from learning essential foundations to writing effective prompts, building powerful Artifacts, creating a personal AI assistant, and developing working software—all without coding.

Join thousands who've transformed their workflows and future-proofed their AI skills in just one week.

SOLUTION

We can solve this problem using a stack to handle the parentheses. The main idea is to keep track of our current result and use the stack to remember previous results when we go into parentheses.

We'll use three variables: result to store our running total, number to build up multi-digit numbers, and sign to remember if the next number should be added or subtracted.

As we go through each character, we build numbers digit by digit and handle the + and - operators by updating our result and sign.

When we see an opening parenthesis (, we save our current result and sign on the stack, then start fresh for the expression inside the parentheses. When we see a closing parenthesis ), we finish calculating the expression inside, then pop our saved values from the stack to combine everything together.

This works because the stack helps us handle nested parentheses correctly. Each time we go deeper into parentheses, we save where we were and start over. When we come back out, we pick up where we left off.

The time complexity is O(n) because we look at each character once. The space complexity is O(n) for the stack, which grows with the number of nested parentheses.

SYSTEM DESIGN

Rate Limiting Algorithms

When building popular web services, you need to protect them from being overwhelmed by too many requests. Rate limiting helps by controlling how many requests a client can make within a specific time period. Let's look at some common algorithms used for rate limiting.

The simplest approach is Fixed Window rate limiting. Imagine dividing time into fixed windows (like minutes) and allowing only N requests per window. When a new minute starts, the counter resets. While simple to implement, this can lead to burst traffic at window boundaries. If your limit is 100 requests per minute, a client could make 100 requests at 11:59 and another 100 at 12:00, sending 200 requests in just two seconds.

Sliding Window rate limiting solves this boundary problem. Instead of fixed windows, it uses a rolling time window. When a request arrives, we count all requests in the last minute (or whatever time period we choose). This prevents burst traffic at window boundaries but requires more memory since we need to track the timestamp of each request.

Token Bucket is another popular algorithm. Imagine a bucket that holds tokens. New tokens are added at a fixed rate up to the bucket's capacity. Each request needs one token. If there are no tokens, the request is rejected. This allows for bursts of traffic (up to the bucket size) while maintaining a long-term rate limit.

Leaky Bucket works similarly but focuses on smoothing out traffic. Requests enter a queue (the bucket) that processes them at a constant rate. If the bucket is full, new requests are rejected. This ensures steady outflow but can lead to delays since requests wait in the queue.

FEATURED COURSES

5 Courses of the Week

 Master Python: Advanced Python skills for complex applications like file classification and web scraping, building a professional portfolio.

 Intro to Java: Functional Programming: Basic Java syntax foundation including conditional statements, functions, and loops for problem-solving.

 Intro to Data Analysis: Explore datasets using Python libraries NumPy, Pandas, and Matplotlib to pose and answer analytical questions.

 LLMs & RAG: Learn to build custom chatbots using NLP techniques, transformer architectures, and retrieval augmented generation (RAG), combining theory with practical Large Language Model (LLM) applications.

 Intro to TensorFlow for Deep Learning: Hands-on course covering neural network fundamentals, building and training models with TensorFlow/Keras, plus transfer learning techniques.

MASTER AI 

Used by Execs at Google and OpenAI

Join 400,000+ professionals who rely on The AI Report to work smarter with AI.

Delivered daily, it breaks down tools, prompts, and real use cases—so you can implement AI without wasting time.

If they’re reading it, why aren’t you?

NEWS

This Week in the Tech World

Bumble cuts 30% of workforce: Dating app Bumble is laying off 240 employees to save $40 million annually. It plans to reinvest this money in product development. The company raised its Q2 revenue forecast and saw shares jump 20% after the announcement.

Amazon launches more Kuiper satellites: Amazon sent 27 more internet satellites into orbit, competing with Starlink. The company needs 1,618 satellites by July 2026 to meet FCC requirements.

US House bans WhatsApp: House staffers can't use WhatsApp on government devices due to privacy concerns. Meta strongly disagrees, saying WhatsApp offers better security than most approved apps.

Meta tried buying Runway AI: Meta discussed acquiring AI video startup Runway before its $14.3 billion Scale AI investment. The takeover talks dissolved early, but Meta continues aggressive AI talent hunting.

DeepSeek aids China's military: US officials say Chinese AI firm DeepSeek supports military operations and evaded chip export controls using Southeast Asian shell companies to access restricted semiconductors.

Google faces UK search changes: Britain's competition watchdog may force Google to add choice screens and fair search rankings. The move targets Google's search dominance under new UK competition rules.

Tesla signs China battery deal: Tesla inked its first deal to build China's largest grid-scale battery plant worth $556 million. The project helps balance China's electricity grid amid US-China trade tensions.

Uber and Waymo expand to Atlanta: Waymo's self-driving cars are now available on Uber in Atlanta, covering 65 square miles. Riders pay regular Uber rates with no tipping required.

WHAT'S NEW IN AI?

Start learning AI in 2025

Keeping up with AI is hard – we get it!

That’s why over 1M professionals read Superhuman AI to stay ahead.

  • Get daily AI news, tools, and tutorials

  • Learn new AI skills you can use at work in 3 mins a day

  • Become 10X more productive

BONUS

Just for laughs 😏

HELP US

👋 Hi there! We are on a mission to provide as much value as possible for free. If you want this newsletter to remain free, please help us grow by referring your friends:

📌 Share your referral link on LinkedIn or directly with your friends.
📌 Check your referrals status here.

YOUR FEEDBACK

What did you think of this week's email?

Your feedback helps us create better emails for you!

Login or Subscribe to participate in polls.

Until next time, take care! 🚀

Cheers,