• InstaByte
  • Posts
  • πŸ”΅πŸ”΄ Escape the matrix

πŸ”΅πŸ”΄ Escape the matrix

ALSO: How to design Dropbox

Welcome back, Interview Masters!

Today’s coding challenge has to do with matrices. Spoiler alert: it’s gonna get swirly!

This week, we’ll cover:

  • Spiral Matrix problem

  • How to design Dropbox?

Read time: under 4 minutes

CODING CHALLENGE

Spiral Matrix

Given an m x n matrix, return all elements of the matrix in spiral order.

Example:

Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]

Solve the problem here before reading the solution.

SOLUTION

To solve this problem, we'll use a layer-by-layer approach. We'll traverse the outer layer of the matrix first, then move inward.

We'll use four variables to keep track of the boundaries: top, bottom, left, and right. We'll start from the top-left corner and move right, then down, then left, then up.

While iterating through the matrix, we will add elements to our β€˜result’ list. After completing each direction, we'll update the corresponding boundary.

We'll continue this process until all elements are added to the result list.

The time complexity of this solution is O(m*n), where m is the number of rows and n is the number of columns in the matrix.

BONUS

The ultimate interview guides

This week we have a surprise for you: We have curated the Top 100 Interview questions and the Top Data Structures and Algorithms to study for interviews.

These guides cover the core concepts you must know to crush any technical interview. In other words, this is the 20% that will get 80% of the job done. Feel free to share them with all your friends. Have fun!

SYSTEM DESIGN EXPLAINED

How to design Dropbox?

Dropbox is a cloud storage service that allows users to store and sync files across devices. Let's look at the key components of its design.

The system uses a client-server architecture. The client (desktop/mobile app) watches for file changes in the user's workspace and syncs them with the server.

To optimize bandwidth usage, files are split into 4MB chunks before upload. Only modified chunks are synced, rather than entire files. This significantly reduces data transfer.

The main server-side components are:

  1. Meta Service: Manages file metadata and determines which chunks have changed. It uses a relational database (MySQL/PostgreSQL) for strong consistency, with a cache in front for performance.

  2. Block Service: Handles actual file chunk storage and retrieval. It uses a distributed file system like GlusterFS or S3 for durability.

  3. Notification Service: Broadcasts file changes to connected clients in real-time using Server-Sent Events. It consumes messages from a queue (RabbitMQ/Kafka) for scalability.

The system uses data deduplication to avoid storing duplicate chunks, which saves storage space. Caching and database sharding help with scalability. File chunks are replicated across multiple data centers for resilience.

You can dive into more details here.

REFER FOR THE WIN

🚨 We will host a Career Chat with a Googler on July 20th. Refer 10+ people to join a 30-minute Q&A session with Sahil. Looking forward to seeing many of you!

πŸ“Œ Share your referral link on LinkedIn or with your friends to unlock the treasures quicker!
πŸ“Œ Check your referrals status here.

NEWS

This week in the tech world

Instagram tests AI chatbots: Instagram is rolling out "AI Studio," allowing creators to make AI versions of themselves for fan interactions. The feature is in early testing in the US, with AI-generated responses clearly labeled.

OpenAI develops AI critic: OpenAI created CriticGPT, an AI model designed to evaluate responses from other AI systems. The tool aims to improve AI alignment and catch errors, particularly in computer code generation.

Meta accused of EU antitrust breach: The European Commission claims Meta's ad-supported subscription option for Facebook and Instagram violates EU antitrust rules. Meta could face fines up to $13.4 billion if found in breach.

OpenAI partners with Time magazine: OpenAI and Time struck a multi-year deal allowing OpenAI to access Time's content for AI training. The partnership aims to enhance OpenAI's products while providing Time access to AI technology.

Figma offers free AI upgrade: Figma CEO Dylan Field announced the company will absorb the cost of AI upgrades for customers in 2024. The move comes as Figma competes with Adobe and Canva in the design software market.

Robinhood acquires AI investing platform: Robinhood acquired Pluto, an AI-powered investment research platform. The move aims to integrate AI capabilities across Robinhood's platform and enhance personalized investment strategies for users.

Tesla beats Q2 delivery estimates: Tesla delivered 443,956 vehicles in Q2 2024, beating analyst expectations but down 4.8% year-over-year. The news sent Tesla shares up over 9%, despite overall sluggish sales in 2024.

BONUS

Just for laughs πŸ˜

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,