Claude just crushed GPT

ALSO: Circuit Breaker pattern

In partnership with

Welcome back!

Today’s problem is every man’s dream. Let’s see if you get it or not.

Today we will cover:

  • 3Sum

  • Circuit Breaker Pattern

Read time: under 4 minutes

CODING CHALLENGE

3Sum

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

Example 1:

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Explanation: 
nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.

nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0.

nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0.

The distinct triplets are [-1,0,1] and [-1,-1,2].

Example 2:

Input: nums = [0,1,1]
Output: []
Explanation: The only possible triplet does not sum up to 0.

Solve the problem here before reading the solution.

PRESENTED BY GAMMA

The future of presentations, powered by AI

Gamma’s AI creates beautiful presentations, websites, and more. No design or coding skills required. Try it free today.

SOLUTION

To solve this problem, we will sort the array first. This will help us avoid duplicates. It would also enable us to use the two pointer approach. Let’s explain this in more detail.

The idea is to iterate the array and then find two other elements that sum up to -nums[i]. This would mean that nums[i] plus these two numbers would be 0. This will give us a valid triplet for the answer.

We will use the ‘twoSum’ function to find these two numbers. We would only look for the numbers to the right of the nums[i] to avoid duplicates. Since the array is sorted, we can use two pointers to find the numbers efficiently.

Sorting has a time complexity of O(n log n). Nested for loops have a time complexity of O(n^2). Since O(n^2) is bigger than O(n log n), overall time complexity is O(n^2).

SYSTEM DESIGN

Circuit Breaker Pattern

When your application calls external services, a lot can go wrong. Services can be slow, unresponsive, or completely down. Without proper handling, these failures can cascade through your system, making everything slow or unusable. The Circuit Breaker pattern prevents this by detecting failures and avoiding unnecessary calls to failing services.

Let’s say you’re calling an external service that's experiencing issues. Each call might take 30 seconds to timeout, and your application makes hundreds of such calls. Your users would face long delays, and your system's resources would be tied up waiting for responses that will never come.

The Circuit Breaker works like an electrical circuit breaker. It monitors for failures. When failures reach a threshold, the circuit "trips" and prevents further calls to the failing service. Instead, it fails fast by returning an error immediately. After a set time, it allows a few test calls to check if the service has recovered.

The Circuit Breaker has three states:

1. Closed: Normal operation, calls pass through

2. Open: Calls fail fast without attempting to execute

3. Half-Open: Allows a limited number of test calls to check recovery

Implementation is straightforward. You track the number of recent failures. When failures exceed a threshold (say 5 failures in 10 seconds), you open the circuit. After a timeout period (maybe 1 minute), you switch to half-open and allow test calls. If these succeed, close the circuit; if they fail, reopen it.

Here's how you might use a Circuit Breaker:

// 5 failures, 1 minute timeout
CircuitBreaker breaker = new CircuitBreaker(5, 60000); 

try {
    breaker.execute(() -> externalService.call());
} catch (CircuitBreakerOpenException e) {
    // Handle failure fast scenario
}

The Circuit Breaker pattern pairs well with fallbacks. When the circuit is open, you can return cached data, default values, or use alternative services instead of failing completely.

FEATURED COURSES

5 Certificates of the Week

 Amazon Junior Software Developer Certificate: Dive into real-world software development through a comprehensive 7-course series. You'll create desktop applications with integrated data handling and GUI features, building a substantial portfolio that demonstrates your technical skills to potential employers.

 Meta Front-End Developer Professional Certificate: Master web development skills by learning HTML5, CSS, JavaScript, and industry-standard design tools like Bootstrap and React. You'll complete multiple projects and a final capstone project, creating a front-end web application that showcases your new coding and design capabilities.

 IBM iOS and Android Mobile App Developer Certificate: Learn to develop cross-platform mobile apps for Android and iOS using multiple programming languages and development tools. This comprehensive program provides hands-on experience designing, building, and maintaining user-friendly mobile apps with no prior programming experience required.

 Google Cybersecurity Professional Certificate: Prepare for a high-growth cybersecurity career with expert-designed training from Google. Learn critical skills like Python, Linux, and security tools, with 170 hours of instruction that simulate real-world cybersecurity scenarios and prepare you for entry-level analyst roles.

 Epic Games Game Design Professional Certificate: Get an in-depth introduction to game design using Unreal Engine, covering everything from level design to blueprint scripting. You'll complete multiple hands-on projects culminating in creating your own personalized game prototype, gaining practical skills from industry professionals.

🎁 Get 40% off Coursera Plus for 3 Months valid from March 7th-10th

AI AT WORK 

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

Anthropic Launches Claude 3.7 Sonnet: Anthropic unveiled Claude 3.7 Sonnet, a hybrid reasoning AI model offering faster, more nuanced responses. The model features "extended thinking mode" on paid plans, improving performance in mathematics, coding, and real-world problem-solving.

Waymo Robotaxis Join Uber in Austin: Waymo launched its autonomous ride service through the Uber app in Austin, covering 37 square miles ahead of SXSW. This positions Waymo ahead of Tesla in the driverless transport race, with over 200,000 weekly paid trips already in other markets.

Microsoft Unveils AI for Doctors: Microsoft's new Dragon Copilot combines voice dictation with AI to draft clinical notes and answer medical queries, aiming to reduce doctors' administrative workload.

Amazon Palm Scanning at NYU Hospitals: Amazon One is bringing palm-scanning check-in to NYU Langone Health, reducing patient wait times from 2-3 minutes to under one minute. The contactless system promises voluntary participation and data privacy safeguards.

Samsung to Launch Vision Pro Rival: Samsung will release its "Project Moohan" XR headset this year with four cameras and Google Gemini integration, competing directly with Apple's $3,500 Vision Pro.

Microsoft Resolves Global Outage: Microsoft fixed a major global service disruption affecting Outlook, Teams, and Azure. Over 37,000 users reported issues, primarily in New York, Chicago, and Los Angeles, though the company hasn't disclosed the outage's root cause.

Asian Tech Stocks Fall on Tariff News: Asian tech stocks declined after Trump announced new tariffs on Canada, Mexico and China. Japanese semiconductor maker Advantest plunged 9%, while SoftBank dropped 6.25%.

MASTER AI TODAY

There’s a reason 400,000 professionals read this daily.

Join The AI Report, trusted by 400,000+ professionals at Google, Microsoft, and OpenAI. Get daily insights, tools, and strategies to master practical AI skills that drive results.

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,