• InstaByte
  • Posts
  • Convert Binary Tree into LinkedList

Convert Binary Tree into LinkedList

ALSO: What is a CDN?

In partnership with

Welcome back!

This week's problem can be solved with two different approaches. Which one do you prefer: recursive or iterative?

Today we will cover:

  • Flatten Binary Tree to Linked List

  • What is a CDN?

Read time: under 5 minutes

CODING CHALLENGE

Flatten Binary Tree to Linked List

Given the root of a binary tree, flatten the tree into a "linked list":

  • The "linked list" should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null.

  • The "linked list" should be in the same order as a pre-order traversal of the binary tree.

Example:

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

Solve the problem here before reading the solution.

PRESENTED BY CODEIUM

Unlock Windsurf Editor, by Codeium.

Introducing the Windsurf Editor, the first agentic IDE. All the features you know and love from Codeium’s extensions plus new capabilities such as Cascade that act as collaborative AI agents, combining the best of copilot and agent systems. This flow state of working with AI creates a step-change in AI capability that results in truly magical moments.

SOLUTION

We can solve this problem recursively or iteratively. The recursive solution is simpler to understand and that’s what we’ll cover today.

For each node, we will:

  1. Recursively flatten the left subtree.

  2. Recursively flatten the right subtree.

  3. Set the node.left to null

  4. Adjust node.right to match our required format: node —> Flattened left subtree —> Flattened right subtree

The time complexity of this solution is O(n) where n is the number of nodes in the tree.

NEXT WEEK IN INSTABYTE PRO

Next week, we will be sharing the following with InstaByte Pro members:

  1. 5 types of Stack problems. For each type, we’ll cover one example problem and its solution. We will also show you how to spot a problem that uses Stack in an interview.

  2. For System Design, we will cover 4 ways to handle concurrency in Databases. Interviewers love to ask questions around concurrent transactions because it’s a pretty hard topic to understand.

  3. Sahil will conduct discussion sessions on Stack problem patterns and Database Concurrency.

  4. Peer mock interviews are already underway.

If you’re interested, you can try out InstaByte Pro for free here:

SYSTEM DESIGN

What is a Content Delivery Network or CDN?

Imagine you're building the next big video streaming service - something like YouTube or Netflix. You've got all these amazing videos that people want to watch, and you're storing them safely in a cloud storage service like Amazon S3. Sounds great so far, right?

But here's where things get tricky. Let's say you have a user in India who wants to watch their favorite cat video. If your video is stored in a data center in the US, that video has to travel halfway across the world before it reaches their screen.

When videos have to travel such long distances, a few annoying things might happen. First, there's the waiting. You click play, and the video takes forever to start. Then comes the dreaded buffering - you know, that spinning circle that shows up right at the most exciting part of the video? This happens because the video data has to hop through multiple networks and cross oceans before reaching your device.

This is where CDNs (Content Delivery Networks) come to the rescue. Instead of having just one central storage location, CDNs maintain multiple copies of your content in different locations called "edge servers".

Now, when our friend in India wants to watch that cat video, they don't have to reach all the way to the US. Instead, they get the video from a nearby CDN server in Asia, maybe from Singapore or Bangalore.

CDNs don't store every single video at every location - that would be expensive and inefficient. Instead, they learn what content is popular in different regions and store it accordingly. If a particular video becomes viral in India, the CDN automatically ensures that multiple copies are available in servers across India.

FEATURED COURSES

5 Courses of the Week

 Python Data Fundamentals: Master essential Python data analysis skills through hands-on practice with Pandas, Seaborn, and Statistics.

 AI Fundamentals: Get a practical introduction to AI concepts including ChatGPT, large language models, and generative AI to understand how they're reshaping technology.

 ChatGPT Prompt Engineering for Developers: Learn how large language models work under the hood, master the art of prompt engineering, and build practical applications using LLM APIs.

 Applied Machine Learning in Python: Learn to build predictive models and data clusters using machine learning, while understanding how to create the right features for your analysis needs.

 Android Kotlin Developer: Master Android app development using Kotlin through hands-on projects, while learning industry-standard architecture patterns and testing practices.

 🎁 Holiday gift 🎁 Get 10% discount with code “POWERCOUPLE” at checkout - applicable to any NVIDIA courses or certifications!

NEWS

This Week in the Tech World

Source: X

Former OpenAI Researcher Dies: Suchir Balaji, 26, who left OpenAI and raised concerns about copyright violations in ChatGPT development, found dead in San Francisco. Medical examiner confirmed death as suicide.

TikTok Ban Looms: House committee warns Apple and Google to prepare for potential TikTok removal from app stores by January 19 if ByteDance doesn't divest. TikTok plans Supreme Court appeal citing First Amendment rights.

End-to-End Encryption Push: US government urges citizens to use end-to-end encrypted messaging after major telecom hack. WhatsApp and Signal recommended as most secure options, while SMS and regular texting deemed vulnerable.

Dexcom Adds AI to Glucose Monitor: Dexcom launches AI feature for its Stelo glucose monitor that analyzes how sleep, meals and activity impact blood sugar levels. The AI tool provides personalized weekly reports to users.

Suki and Google Cloud Partner: Health AI startup Suki expands beyond clinical documentation through Google Cloud partnership. New features let doctors quickly access patient histories and summaries. The company serves 350 health systems and tripled its client base in 2024.

Temu Tops App Downloads: Chinese e-commerce app Temu leads US iOS downloads for second year despite scrutiny. The app faces uncertainty with upcoming Trump presidency and potential changes to import duty exemptions that could affect pricing.

ChatGPT Outage Resolved: OpenAI's ChatGPT service restored after 4-hour outage. Company clarifies disruption was due to monitoring software implementation, not security breach. Comes as service hits 300 million weekly users.

Waymo Expands to Tokyo: Alphabet's Waymo announces first international expansion, testing self-driving cars in Tokyo starting 2025. Partnership with Japan's largest taxi operator will begin with human drivers mapping key areas.

IN THE AI WORLD

Drowning In Support Tickets? Maven AGI is here to help.

Maven AGI platform simplifies customer service by unifying systems, improving with every interaction, and automating up to 93% of responses. Seamlessly integrated with 50+ tools like Salesforce, Freshdesk, and Zendesk, Maven can deploy AI agents across multiple channels—text, email, web, voice, and apps—within days. Companies like Tripadvisor, ClickUp, and Rho slash response times by 60%, ensuring quicker support and exceptional customer satisfaction. Don’t let support tickets slow you down

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,