• InstaByte
  • Posts
  • Snap cuts 1,000 jobs, blames AI

Snap cuts 1,000 jobs, blames AI

ALSO: API Gateway Design

In partnership with

Welcome back!

This week’s coding challenge is very popular with big tech companies because the solution is very elegant. Let’s see if you can solve it optimally.

Today we will cover:

  • Kth Smallest Element in a BST

  • API Gateway Design

Read time: under 4 minutes

CODING CHALLENGE

Kth Smallest Element in a BST

Given the root of a binary search tree, and an integer k, return the k-th smallest value (1-indexed) of all the values of the nodes in the tree.

Example 1:

Input: root = [3,1,4,null,2], k = 1
Output: 1

Example 2:

Input: root = [5,3,6,2,4,null,null,1], k = 3
Output: 3

Solve the problem here before reading the solution.

PRESENTED BY NEO

Fast browsing. Faster thinking.

Your browser gets you to a page. Norton Neo gets you to the answer. The first safe AI-native browser built by Norton moves with you from idea to action without slowing you down. Magic Box understands your intent before you finish typing. AI that works inside your flow, not beside it. No prompting. No copy-pasting. No switching apps.

Built-in AI, instantly and for free. Privacy handled by Norton. Built-in VPN and ad blocking protect you by default. No configuration. No extra apps. Nothing to think about.

Fast. Safe. Intelligent. That's Neo.

SOLUTION

To find the k-th smallest element in a BST, we can perform an inorder traversal.

Since inorder traversal of a BST visits nodes in ascending order, we just need to keep track of how many nodes we have visited.

We'll use an iterative approach with a stack to perform the inorder traversal. This avoids recursion stack overflow for very deep trees.

When we've visited k nodes, we'll have found our answer. This approach is efficient since we only need to traverse until we find the k-th element, not the entire tree.

The time complexity is O(H + k) where H is the height of the tree. In the worst case when k is large, it becomes O(N).

BECOME AI-NATIVE 

Learn how to code faster with AI in 5 mins a day

You're spending 40 hours a week writing code that AI could do in 10.

While you're grinding through pull requests, 200k+ engineers at OpenAI, Google & Meta are using AI to ship faster.

How?

The Code newsletter teaches them exactly which AI tools to use and how to use them.

Here's what you get:

  • AI coding techniques used by top engineers at top companies in just 5 mins a day

  • Tools and workflows that cut your coding time in half

  • Tech insights that keep you 6 months ahead

Sign up and get access to the Ultimate Claude code guide to ship 5X faster.

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

✅ Stanfords’s Algorithms Specialization: Master fundamental algorithms through programming assignments and conceptual learning. This specialization prepares you to excel in technical interviews and communicate fluently about algorithms without focusing on low-level implementation details.

✅ IBM’s Python for Data Science, AI & Development: Learn Python basics, data structures, and libraries (Pandas, NumPy) for data science and automation in this beginner-friendly course. You'll gain hands-on experience with Jupyter Notebooks, performing tasks like data collection and web scraping with APIs.

✅ Stanford’s ML Specialization: Build practical ML models using NumPy, scikit-learn, and TensorFlow across supervised and unsupervised learning techniques. Learn to create real-world AI applications including neural networks, recommendation systems, and reinforcement learning models.

✅ Hopkins’ R Programming: Develop effective data analysis skills by learning R programming fundamentals and statistical computing techniques. This course covers installing software, accessing R packages, writing functions, debugging, profiling code, and organizing R code through practical examples.

✅ Duke’s Intro to RAG: Build end-to-end Retrieval Augmented Generation systems using Pandas, SentenceTransformers and Qdrant in just 2 hours. This project-based course teaches you to create powerful generative AI apps with your own data using open-source tools.

NEWS

This Week in the Tech World

Snap cuts 1,000 jobs, blames AI: Snapchat's parent company is laying off 16% of its workforce and closing 300 open roles. CEO Spiegel says AI now generates over 65% of new code at Snap, enabling smaller teams to move faster.

Meta signs $21B CoreWeave deal: Meta expanded its AI cloud agreement with CoreWeave through 2032 to scale its inference workloads. The deal includes early deployments of Nvidia's Vera Rubin GPUs across multiple data centers.

Microsoft Patch Tuesday is massive: Microsoft fixed 167 vulnerabilities including an actively exploited SharePoint zero-day and a Defender privilege escalation bug. Admins should prioritize patching Office and SharePoint environments immediately.

Marimo RCE exploited in 10 hours: A critical pre-auth flaw in the popular Python notebook tool was weaponized before any PoC code existed. Attackers stole credentials from .env files and SSH keys within minutes of gaining access.

iPhone Fold enters trial production: Foxconn has started testing Apple's first foldable iPhone ahead of a planned fall launch. The device features a 7.8-inch inner display, a near-invisible crease, and could cost upwards of $2,000.

Framework teases Next Gen event: The modular PC maker is hinting at major Linux-first hardware dropping April 21. The teaser included logos for Ubuntu, Fedora, Arch, and Bazzite — the strongest Linux messaging from any consumer PC maker.

Tech layoffs blow past 99K in 2026: AI-driven restructuring is accelerating across Snap, Disney, Oracle, and others. Nearly half of all cuts this year are directly tied to AI and workflow automation.

US utilities plan $1.4 trillion spending surge: AI data center demand is forcing a historic power grid upgrade cycle over the next five years. Electricity is quickly becoming AI's hardest constraint, reshaping the economics of cloud computing.

GPU prices keep surging: Rising compute costs are turning infrastructure access into a competitive moat for Big Tech incumbents. For startups, the AI boom is no longer just a software race — it's a market for scarce industrial inputs.

Jane Street commits $6B to CoreWeave: The trading firm also made a $1B equity investment, signaling Wall Street's deepening bet on AI compute infrastructure. CoreWeave's total backlog now exceeds $88 billion through 2032.

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!

Login or Subscribe to participate in polls.

Until next time, take care! 🚀

Cheers,