- InstaByte
- Posts
- Elon Musk threatens Apple
Elon Musk threatens Apple
ALSO: API Gateway Design
Welcome back!
Ready for another hard problem this week? This week’s challenge looks simple, but finding an efficient solution is what makes it a hard. Let’s do this.
Today we will cover:
Find Median from Data Stream
API Gateway Design
Read time: under 4 minutes
CODING CHALLENGE
Find Median from Data Stream
The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.
For example, for
arr = [2,3,4]
, the median is3
.For example, for
arr = [2,3]
, the median is(2 + 3) / 2 = 2.5
.
Implement the MedianFinder class:
MedianFinder()
initializes theMedianFinder
object.void addNum(int num)
adds the integernum
from the data stream to the data structure.double findMedian()
returns the median of all elements so far. Answers within 10-5 of the actual answer will be accepted.
Example:
Input:
["MedianFinder", "addNum", "addNum", "findMedian", "addNum", "findMedian"]
[[], [1], [2], [], [3], []]
Output:
[null, null, null, 1.5, null, 2.0]
Explanation:
MedianFinder medianFinder = new MedianFinder();
medianFinder.addNum(1); // arr = [1]
medianFinder.addNum(2); // arr = [1, 2]
medianFinder.findMedian(); // return 1.5 (i.e., (1 + 2) / 2)
medianFinder.addNum(3); // arr[1, 2, 3]
medianFinder.findMedian(); // return 2.0
Solve the problem here before reading the solution.
PRESENTED BY MINIMAX AGENT
MiniMax Agent $150K Challenge
Think your AI idea could break the internet? Time to prove it. MiniMax is throwing $150,000 at the boldest creators from Aug 11-25th.
Your game plan:
Grab your starter pack – Register for 5,000 free credits
Build something wild – Create or remix with MiniMax Agent
Show it off – Submit your creation and blast it on socials
Two weeks. $150K up for grabs. Zero excuses.
SOLUTION
To solve this problem efficiently, we'll use two heaps: a max heap and a min heap. The max heap contains the smaller half of the numbers. The min heap contains the larger half of the numbers.
We make sure sizes of these heaps differ by at most 1. This makes the median lookup really fast. If the count of total numbers is odd, the median would be the top of larger heap. Otherwise, the median would be the average of tops.
This approach allows us to quickly find the median in O(1)
time and add numbers in O(log n)
time.
One thing to note is that Python does not support a max heap. We use negative values to simulate a max heap with Python's min heap.

SYSTEM DESIGN
API Gateway Design

When you're building a system with multiple microservices, letting clients communicate directly with each service creates many problems. Clients need to know about all services, handle different protocols, and deal with authentication multiple times. An API Gateway solves these problems by acting as a single entry point for all client requests.
Here's how an API Gateway helps:
Authentication & Authorization
Instead of implementing security in each microservice, the API Gateway handles it centrally. When a request comes in, the gateway first checks if the user is allowed to access the service. This means your microservices can focus on their core functionality rather than dealing with security.
Request Routing
The gateway knows where each service lives and forwards requests to the right place. If you move a service to a different server, you only need to update the gateway's routing configuration. Clients don't need to know or care about these changes.
Request/Response Transformation
Different clients (mobile apps, web browsers, IoT devices) might need data in different formats. The API Gateway can transform requests and responses to match what each client expects. For example, a mobile app might need a lightweight response while a web app needs more detailed data.
Rate Limiting
To protect your services from being overwhelmed, the gateway can limit how many requests each client can make. This prevents any single client from using too many resources and keeps your system stable.
Monitoring & Analytics
Since all requests go through the gateway, it's the perfect place to collect metrics about API usage. You can track things like response times, error rates, and popular endpoints without adding code to your services.
Best Practices:
1. Keep the gateway simple, avoid adding business logic
2. Use caching for frequently requested data
3. Implement circuit breakers to handle service failures gracefully
4. Monitor gateway performance closely
5. Plan for scaling, the gateway can become a bottleneck
FEATURED COURSES
5 Courses of the Week
✅ PHP Full Stack Bootcamp: Combines front-end (HTML, CSS, JavaScript) and back-end (PHP, MySQL, WordPress) development in one comprehensive course. Includes 80+ PHP projects and complete shopping cart website development. Prepares for freelance work and junior developer positions with certification.
✅ Applied Data Science Specialization: Develop practical Python skills using NumPy, Pandas, and visualization libraries. Master predictive modeling, model selection, and compelling data storytelling techniques. Complete real-world projects including financial data analysis and flight reliability monitoring dashboards.
✅ Linear Algebra for Data Science: Acquire fundamental linear algebra concepts specifically tailored for data science applications. Learn approachable methods without unnecessary proofs and complexity. Build a strong mathematical foundation to prepare for advanced data science studies.
✅ Meta Android Developer Certificate: Learn Android programming with Kotlin to build mobile apps like Facebook. Includes portfolio-building projects.
✅ Amazon Software Developer Certificate: Dive into real-world software development. You'll create desktop applications with integrated data handling and GUI features, building a substantial portfolio that demonstrates your technical skills to potential employers.
VOICE IS THE NEW KEYBOARD
Typing is a thing of the past.
Typeless turns your raw, unfiltered voice into beautifully polished writing - in real time.
It works like magic, feels like cheating, and allows your thoughts to flow more freely than ever before.
Your voice is your strength. Typeless turns it into a superpower.
NEWS
This Week in the Tech World

Musk Threatens Apple with Antitrust Lawsuit: Elon Musk accused Apple of antitrust violations, claiming it prevents AI companies besides OpenAI from reaching #1 in the App Store. He threatened "immediate legal action" over Grok's rankings and Apple's partnership with ChatGPT.
GPT-5 Rollout Creates User Revolt: OpenAI's GPT-5 launch sparked massive user complaints after automatically removing access to all previous AI models. CEO Sam Altman was forced to apologize as users reported broken workflows and performance issues.
StubHub IPO Returns in September: The ticketing marketplace resumed IPO plans after delaying in April due to tariff concerns. StubHub aims to go public next month following 10% revenue growth to $397.6 million in Q1.
Tesla Hiring Robotaxi Drivers Without NYC Permits: Tesla is recruiting test drivers in New York for "automated driving systems" but hasn't applied for required permits. The company operates robotaxis in Austin and plans to expand to Bay Area despite regulatory challenges.
China Questions Alibaba, ByteDance on Nvidia Chip Orders: Beijing is demanding tech companies justify their Nvidia H20 chip purchases instead of using domestic alternatives. Some companies are downsizing orders, calling Nvidia purchases "politically incorrect."
Trump Flip-Flops on Intel CEO: President Trump called Intel CEO Lip-Bu Tan a "success" days after demanding his resignation over China ties. The meeting marks a stark change from Trump's earlier demands that Tan step down immediately.
AOL Shuts Down Dial-Up Internet After 30 Years: AOL announced it will end dial-up internet service on September 30, marking the end of an era. The service that once connected millions now serves a dwindling user base as broadband dominates.
WHAT'S NEW IN AI?
Used by Execs at Google and OpenAI
Join 400,000+ professionals who rely on The AI Report to work smarter with AI.
Delivered daily, it breaks down tools, prompts, and real use cases—so you can implement AI without wasting time.
If they’re reading it, why aren’t you?
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! |
Until next time, take care! 🚀
Cheers,