GPT is open-source now!

ALSO: Quorum in Leaderless Replication

In partnership with

Welcome back!

This week, we’ll solve a hard but very popular interview problem. All the best!

Today we will cover:

  • Trapping Rain Water

  • Quorum in Leaderless Replication

Read time: under 4 minutes

CODING CHALLENGE

Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

Example 1:

Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 
6 units of rain water (blue section) are being trapped.

Example 2:

Input: height = [4,2,0,3,2,5]
Output: 9

Solve the problem here before reading the solution.

PRESENTED BY MINDSTREAM

Turn AI Into Your Income Stream

The AI economy is booming, and smart entrepreneurs are already profiting. Subscribe to Mindstream and get instant access to 200+ proven strategies to monetize AI tools like ChatGPT, Midjourney, and more. From content creation to automation services, discover actionable ways to build your AI-powered income. No coding required, just practical strategies that work.

SOLUTION

For any position in the array, the amount of water that can be trapped above that bar depends on two things: the tallest bar somewhere to its left and the tallest bar somewhere to its right.

If the tallest bar on the left is 5 units and the tallest on the right is 7 units, the water at this position can only go up to 5 units high. If the water goes above this level, it would spill over the left side. Once we know this water level, we subtract the current bar's height to get the actual water trapped at that position.

We'll maintain two pointers, one starting from the left end and one from the right end of the array. We'll also keep track of the maximum height seen so far from both sides.

At each step, we move the pointer with the smaller maximum height. This works because when we know one side has a smaller maximum, we can immediately calculate the water at that position. We don't need to check further because we've already found the limiting factor for the water level there.

This way, we can calculate water trapped as we go, moving the appropriate pointer inward after each calculation.

The time complexity of this solution is O(n), where n is the length of the height array.

SYSTEM DESIGN

Quorum in Leaderless Replication

In distributed databases, making sure your data is both available and consistent can be tricky. When one server fails, you don't want your entire system to stop working. Leaderless replication helps solve this by storing copies of data across multiple servers. But this raises a question: how many servers need to respond to consider a read or write operation successful? This is where quorum comes in.

Quorum is a minimum number of servers that must participate in a read or write operation. Let's say you have 5 servers storing your data. With a quorum of 3, any write operation must be confirmed by at least 3 servers before it's considered successful.

The key to making quorum work is following this formula: R + W > N, where:

  • R is the number of servers needed for a successful read

  • W is the number of servers needed for a successful write

  • N is the total number of servers

For example, if N=5, you might set W=3 and R=3. This means each write must be confirmed by 3 servers, and each read must get responses from 3 servers. Since 3+3>5, this ensures that read and write operations will always overlap on at least one server, giving you consistent data.

Different values of R and W let you optimize for different needs:

  • Setting W higher than R prioritizes consistency

  • Setting R higher than W gives faster writes but might return stale data

  • Setting R=1 and W=N gives fast reads but slow writes

Quorum isn't perfect though. If too many servers fail and you can't reach the required number of responses, the system becomes unavailable. Also, even with quorum, temporary inconsistencies can occur if servers haven't synchronized yet.

Here's how different quorum configurations compare:

Configuration

Read Speed

Write Speed

Consistency

Availability

R=1, W=N

Fast

Slow

Strong

Low

R=N, W=1

Slow

Fast

Weak

Low

R=W=(N+1)/2

Medium

Medium

Strong

Medium

FEATURED COURSES

5 Courses of the Week

 Amazon’s DSA: Implement and analyze fundamental data structures and algorithms in Java, including sorting, searching, and recursive techniques with JUnit testing methodology.

 Intro to Git and GitHub: Understand version control and learn how to collaborate with others using Git and Github.

 Amazon’s Software Developer Certificate: Dive into real-world software development where you'll create desktop apps with integrated data handling and GUI features, building a substantial portfolio that demonstrates your technical skills to potential employers.

 Hopkins’ R Programming: Develop effective data analysis skills by learning R programming fundamentals and statistical computing techniques. This covers installing software, accessing R packages, writing functions, debugging, profiling code, and organizing R code through practical examples.

 Stanford’s ML Specialization: Build practical ML models using NumPy, scikit-learn, and TensorFlow across supervised and unsupervised learning techniques. Learn to create real-world AI apps including neural networks, recommendation systems, and reinforcement learning models.

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?

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

NEWS

This Week in the Tech World

OpenAI Releases First Open Models Since GPT-2: OpenAI launched gpt-oss-120b and gpt-oss-20b, its first open-weight models since 2019. Users can download and run these models with configurable reasoning on their own hardware, competing with other open-source AI.

Amazon Lays Off 110 Employees in Wondery Unit: Amazon cut jobs in its podcast division and reshuffled its audio business. Wondery CEO Jen Sargent also stepped down. The company is consolidating podcast operations under Audible as video podcasts gain popularity.

DeepMind Reveals Genie 3 World Model: Google DeepMind unveiled Genie 3, which creates real-time interactive 3D worlds from prompts or images. The system generates 720p environments at 24fps that can be modified on the fly for gaming and AI training.

Tesla Co-Founder Uses Old EV Batteries for AI Data Centers: JB Straubel's Redwood Materials is repurposing used EV batteries to power AI data centers. The company partnered with Crusoe for a 12-megawatt solar microgrid using 63 MWh of second-life battery storage.

TSMC Discovers Potential Trade Secret Leaks: The world's largest chipmaker found unauthorized activities leading to potential trade secret theft. Former employees are suspected of attempting to steal 2-nanometer chip development secrets while still at the company.

OpenAI Offers 20 Million User Chats in NYT Lawsuit: OpenAI proposed sharing 20 million ChatGPT conversations for copyright lawsuit discovery, but The New York Times rejected it, demanding 120 million user chats instead. The dispute could delay the case by months.

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,