😱 Meta asked this 55 times

ALSO: How to design Instagram

Welcome back, Interview Masters!

Today’s coding challenge was asked by Meta 55 times in the last 6 months. Ready to take it on?

In today’s newsletter, we’ll cover:

  • 3Sum problem

  • How to design Instagram?

Read time: under 5 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.

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 me 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).

PRESENTED BY ACI LEARNING

Tech Professionals are in High Demand 

Take your IT career to the next level and get ready for your next certification or brush up on your skills. Our video on-demand training library includes over 7,250 hours of courses plus hands-on skill labs and pre-certification practice tests.  

SYSTEM DESIGN EXPLAINED

How to design Instagram?

This week we’ll explore how to design a simplified version of a social media platform like Instagram. On this platform, users can share photos and follow others. They can also see a personalized newsfeed showcasing photos from people they follow.

To ensure a smooth user experience, the system prioritizes high availability over consistency.

The system utilizes a variety of databases, including:

  1. MySQL stores user information

  2. Neo4j tracks user relationships (who follows whom)

  3. Cassandra is used as key-value store for user photos

  4. Redis caches frequently accessed data for faster performance

To curate engaging newsfeeds, the system ranks photos based on popularity (likes and comments) as well as recency. This ensures users see the most interesting content first.

You can dive into more details here.

REFER FOR THE WIN

🚨🚨 New hidden treasure alert 🚨🚨 

We’re excited to launch a new reward: Refer 10+ people to join a Career Chat with Sahil, who works at Google!

📌 Check your referrals status here.

Share your referral link on LinkedIn or with your friends to unlock the treasures quicker!

NEWS

This week in the tech world

Source: Briefly on YouTube

World's first AI diplomat: Ukraine appointed Victoria Shi, an AI, as their first AI diplomat. Shi will deliver official messages, saving diplomats time. Keep an eye on Shi for updates, especially on consular affairs.

AI Engineers burnout: AI engineers at top tech companies face burnout due to intense pressure to meet breakneck deadlines. Prioritizing speed over responsible development raises ethical concerns. Many feel they're solving problems for investors, not the real world.

New iPads pack power: Apple unveiled powerful new iPad Pro and iPad Air models featuring the latest M4 chip. The iPad Pro comes in two sizes with a new Magic Keyboard accessory, while the iPad Air offers affordability in two sizes.

Google morale low despite earnings: Google staff aren't celebrating strong earnings. Cost cuts, layoffs, and a morale slump have employees questioning their compensation. Leadership promises investment and uses AI to understand concerns.

US limits chip sales to Huawei: The US revoked some export licenses to sell chips to China's Huawei. This is part of an effort to curb China's tech growth. Huawei, a company on the US's restricted-sales list, will face challenges due to the chip restrictions.

AI boosts humanoid robots: China's humanoid robots are getting smarter thanks to generative AI. This tech helps them understand their surroundings better, paving the way for robots that can tackle complex tasks.

POLL

Results from last week

This one’s for you

What's your current annual salary?

Login or Subscribe to participate in polls.

BONUS

Just for laughs 😏

Source: Programmer Humor

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.

Reviews of the week

Until next time, take care! 🚀

Cheers,