• InstaByte
  • Posts
  • Amazon keeps asking this problem

Amazon keeps asking this problem

ALSO: Why use Kafka?

Welcome back!

Amazon loves this week’s problem. Hope you enjoy the challenge!

Here’s what to expect today:

  • Longest substring without repeating characters

  • Why use Kafka?

Read time: under 4 minutes

CODING CHALLENGE

Longest Substring Without Repeating Characters

Given a string s, find the length of the longest substring without repeating characters.

Example 1:

Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.

Example 2:

Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

Example 3:

Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.

Solve the problem here before reading the solution.

SOLUTION

To solve this problem, we'll use a sliding window approach with a dictionary. We'll keep track of the characters we've seen and their indices.

We'll move the right pointer of our window, adding characters to the dictionary. If we find a repeating character, we'll move the left pointer to the right of the last occurrence of that character.

We'll update the maximum length of the substring as we go.

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

COMMUNITY

InstaByte Question Bank

🧠 Help each other by sharing the actual questions you were asked in a recent interview. Use this form to submit your question.  

We will share the submitted questions on this weekly newsletter - stay tuned!

Note: Your submission is anonymous.

SYSTEM DESIGN

Why Use Kafka?

Source: Daily Dose of Python on Medium

Apache Kafka is a distributed data streaming platform designed for high-throughput, real-time data processing. It is used to handle continuous streams of data from many different sources at the same time.

Key features of Kafka:

  1. Scalability: Kafka distributes data across multiple servers, allowing it to handle massive amounts of information beyond a single machine's capacity.

  2. Speed: With its decoupled write and read data streams, Kafka offers extremely low latency, making it ideal for real-time applications.

  3. Durability: Data is replicated across servers and written to disk, protecting against server failures.

  4. Flexible data retention: Kafka can store data for configurable periods, from seconds to years.

  5. Multiple consumer support: Unlike traditional message queues, Kafka allows multiple applications to read the same data stream independently.

Kafka's architecture combines messaging queue and publish-subscribe models. It organizes data into topics that are partitioned. The messages within a partition are processed in order.

Kafka is used to build real time data pipelines. For example, Uber drivers send their location to the server every few seconds. This location is added to a Kafka queue. From the queue, the location is read by different consumers for applications like matching drivers with riders or showing nearby drivers to the riders on the app.

NEWS

This Week in the Tech World

Source: Apple

Apple Unveils iPhone 16 and More: Apple announced iPhone 16, iPhone 16 Pro, Apple Watch Series 10, and AirPods 4. New features include larger displays, improved cameras, and AI capabilities. Preorders start Friday, with devices launching September 20.

Salesforce to Acquire Own for $1.9B: Salesforce announces plans to buy Own Co., a cloud backup startup, for $1.9 billion in cash. The deal aims to expand Salesforce's data protection offerings and is expected to close by January 2025.

Amazon Resumes Fresh Supermarket Expansion: After a yearlong pause, Amazon is opening new Fresh grocery stores with redesigned layouts. The company aims to increase its share in the competitive U.S. grocery market.

Qualcomm Collaborates on Mixed Reality Glasses: Qualcomm CEO reveals the company is working with Samsung and Google to develop mixed-reality smart glasses. The project aims to create a companion device for smartphones.

UK Regulator Challenges Google's Ad Practices: Britain's Competition and Markets Authority alleges Google's dominance in online advertising harms competition. The watchdog accuses Google of favoring its own ad tech services, potentially disadvantaging competitors.

California AG Warns Tech Platforms on Voter Protection: California's Attorney General cautions social media and AI companies to prevent voter deception ahead of elections. The warning follows incidents of AI-generated images spreading false political endorsements.

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.

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,