- InstaByte
- Posts
- FAANGs ❤️ Linked Lists
FAANGs ❤️ Linked Lists
ALSO: How to design Uber
Welcome back, Interview Masters!
Today’s coding challenge was asked by all FAANG companies in the past six months. Get ready to play with linked lists!
In today’s newsletter, we’ll cover:
Add Two Numbers problem
How to design Uber?
Read time: under 4 minutes
CODING CHALLENGE
Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Example 1:
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Example 2:
Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
Output: [8,9,9,9,0,0,0,1]
Solve the problem here before reading the solution.
SOLUTION
To solve this problem, we will iterate through both linked lists simultaneously, add the corresponding digits and keep track of the carry.
We'll create a dummy node to start the result linked list and a current node to build the result.
At each step:
Add the values of the current nodes of both lists (if they exist) and the carry.
Create a new node with the ones digit of the sum and add it to the result linked list.
Update the carry to be the tens digit of the sum.
Move to the next nodes in both lists.
After the loop, if there's still a carry, we'll add an additional node to the result.
The time complexity of this solution is O(max(m, n)
), where m
and n
are the lengths of the input linked lists.
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 Uber?
Uber uses microservices architecture. The main services are: Customer Service for handling user accounts, the Driver Service for managing driver information, the Ride Service for matching customers with drivers, and the Payment Service for processing transactions securely using third-party processors like Stripe.
Uber uses WebSockets to track driver and rider location, which allow for real-time updates without overwhelming the servers. They also use clever data structures called Quadtrees to quickly find nearby drivers when a customer requests a ride.
Uber uses techniques like sharding to distribute the database load and caching to speed up frequent requests. For redundancy and fault tolerance, Uber runs multiple copies of each service and uses message queues to make sure important notifications always get delivered.
You can dive into more details here.
QUICK TIP
👋 Move this email to your primary inbox to never miss coding challenges!
If you don’t know how to do it, check out this 1-min guide.
NEWS
This week in the tech world
Nvidia Surpasses Apple in Market Cap: Nvidia has overtaken Apple to become the second-most valuable public company in the U.S. The company's market cap now stands at $2.5 trillion. This milestone shows Nvidia's dominance in the AI and graphics processing markets.
LeCun Criticizes Musk: Meta AI chief Yann LeCun criticized Elon Musk for making "blatantly false" predictions and spreading conspiracy theories. LeCun's remarks highlight the growing tension between leading AI researchers and high-profile tech entrepreneurs.
Google Cuts Cloud Jobs: Google has cut at least 100 jobs from its rapidly expanding cloud division. These layoffs come as part of a broader cost-cutting effort despite the unit's growth.
Intel Launches New AI Chips: Intel has unveiled new AI chips aimed at reclaiming market share from Nvidia and AMD. These chips are part of Intel's strategy to re-establish itself as a key player in the AI hardware market.
Microsoft Layoffs in Mixed Reality: Microsoft confirmed layoffs in its mixed reality division but will continue selling HoloLens 2 headsets. The company remains committed to mixed reality technology despite the workforce reduction.
Amazon Prime Adds Grubhub: Amazon Prime now includes a Grubhub food-delivery subscription. This addition enhances the value proposition of Prime membership by offering food delivery services at no extra cost. The integration aims to attract more subscribers and boost customer satisfaction.
BONUS
Just for laughs 😏
REFER FOR THE WIN
👋 Hey! Share your referral link with friends to unlock Hidden Treasures:
📌 Share your referral link on LinkedIn or with your friends to unlock the treasures quicker!
📌 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! |
Until next time, take care! 🚀
Cheers,