Microsoft lays off 7,000

ALSO: Database Connection Pooling

Welcome back!

This week, we’ll solve one of the most popular interview problems. It has been asked more than 100 times in last 6 months.

Today we will cover:

  • Search in Rotated Sorted Array

  • Database Connection Pooling

Read time: under 4 minutes

CODING CHALLENGE

Search in Rotated Sorted Array

There is an integer array nums sorted in ascending order (with distinct values).

Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,5,6,7] might be rotated at pivot index 3 and become [4,5,6,7,0,1,2].

Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.

You must write an algorithm with O(log n) runtime complexity.

Example 1:

Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4

Example 2:

Input: nums = [4,5,6,7,0,1,2], target = 3
Output: -1

Example 3:

Input: nums = [1], target = 0
Output: -1

Solve the problem here before reading the solution.

HOW TO LEARN AI?

Start learning AI in 2025

Keeping up with AI is hard – we get it!

That’s why over 1M professionals read Superhuman AI to stay ahead.

  • Get daily AI news, tools, and tutorials

  • Learn new AI skills you can use at work in 3 mins a day

  • Become 10X more productive

SOLUTION

To solve this problem, we can use a modified Binary Search algorithm. When we do Binary Search, we divide the array into two halves: left half and right half.

In a rotated sorted array, at least one half (left or right) will always be sorted. First, we need to find which half of the array is sorted.

Once we identify the sorted half, we can check if our target lies within its range. If it does, we search in that half. If it doesn't, we search in the other half.

This process continues until we either find the target or determine it's not in the array.

The time complexity of this solution is O(log n) as we are using Binary Search.

WHAT'S NEW IN AI?

Learn how to make AI work for you

AI won’t take your job, but a person using AI might. That’s why 1,000,000+ professionals read The Rundown AI – the free newsletter that keeps you updated on the latest AI news and teaches you how to use it in just 5 minutes a day.

SYSTEM DESIGN

Database Connection Pooling

Opening and closing database connections for every request can significantly slow down your application. Each new connection requires TCP handshake, authentication, and memory allocation, all of which take time. Connection pooling solves this by maintaining a pool of reusable database connections.

Here's how connection pooling works. When your application starts, it creates a set of database connections and keeps them ready to use. When your code needs to query the database, it borrows a connection from the pool, uses it, and returns it back instead of closing it. This makes database operations much faster since connections are reused rather than created from scratch.

Here are some key practices to get the most out of connection pooling:

Pool Size: Start with pool size = number of CPU cores * 2. This gives enough connections to handle concurrent requests without wasting resources. Monitor connection usage and adjust if needed.

Connection Lifetime: Set a maximum lifetime for connections (usually a few hours) to prevent issues with stale connections. The pool will automatically replace old connections with fresh ones.

Timeout Settings: Set reasonable timeouts for both getting a connection from the pool and executing queries. This prevents requests from hanging when the pool is exhausted or queries are taking too long.

Monitoring: Track metrics like connection wait time, pool utilization, and connection errors. These help identify if your pool needs tuning.

FEATURED COURSES

5 Courses of the Week

 Data Structures and Algorithms in Python: Get hands-on practice with over 100 data structures and algorithm exercises and guidance from a dedicated mentor to help prepare you for interviews and on-the-job scenarios.

 Meta Front-End Developer Professional Certificate: Master web development skills by learning HTML5, CSS, JavaScript, and industry-standard design tools like Bootstrap and React. You'll complete multiple projects and a final capstone project, creating a front-end web application that showcases your new coding and design capabilities.

 Grokking the Modern System Design Interview: The ultimate guide to the System Design Interview – developed by Meta & Google engineers. Master distributed system fundamentals, and practice with real-world interview questions & mock interviews.

 Generative AI for Everyone: The course includes hands-on exercises in prompt engineering, real-world applications, and advanced AI implementation techniques. It aims to equip everyone with skills to effectively use AI in daily work and understand its broader impacts.

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

NEWS

This Week in the Tech World

Microsoft Cuts 7,000 Jobs: Microsoft is laying off 7,000 employees (about 3% of its workforce) across multiple locations and divisions including LinkedIn. The company cited the need to reduce management layers while continuing massive investment in AI infrastructure.

Perplexity Teams with PayPal: Perplexity is partnering with PayPal to enable in-chat shopping. Users will soon be able to book travel, buy products, and secure concert tickets without leaving the platform. The deal comes as Perplexity finalizes a $500 million funding round at a $14 billion valuation.

Google Tests AI Mode on Homepage: Google is testing an "AI Mode" button on its homepage, replacing the "I'm Feeling Lucky" button. The feature, not widely available yet, shows Google's push to compete in AI-driven search as it trails behind ChatGPT's estimated 160 million daily active users.

Chime Files for IPO: Fintech company Chime has filed to go public on the Nasdaq under the ticker "CHYM." The company emphasizes it's a technology company, not a bank, and reported $12.9 million in net income on $518.7 million in revenue for the March quarter.

Google Pays $1.4B to Texas: Google agreed to pay Texas nearly $1.4 billion to settle data privacy violation allegations. The settlement covers claims related to Chrome's incognito mode, Google Maps location tracking, and Google Photos biometric data collection.

DOGE Engineer's Device Compromised: Login credentials belonging to Kyle Schutt, a software engineer at both CISA and DOGE with access to sensitive government systems, have appeared in multiple public leaks from info-stealing malware, indicating his devices have been hacked.

SoftBank Backs OpenAI Restructure: SoftBank has endorsed OpenAI's restructuring plan that keeps the non-profit entity in control while transforming the for-profit division into a public benefit corporation. SoftBank's finance chief said "nothing has really changed" with the plan.

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,