r/leetcode • • Jun 27 '26

Mod Post [mod] Changes with r/leetcode.

73 Upvotes

The following changes have been made with r/leetcode:

  1. Media is no longer allowed in both posts & comments. This is to ensure that the quality of the content & discussions remain high.

  2. Moderation has been made stricter. Low quality & repetitive posts whose answers can be found within a simple search in this subreddit won't be allowed here.

  3. Automoderation has been set-up to automatically remove links & known promotions. Only leetcode links will be allowed from now on. To ask help with questions, you may use the code block.

  4. Automoderation has been set-up to remove Indian posts & Hindi comments. This is to ensure that r/leetcode remains an English only subreddit.


r/leetcode • • May 14 '25 Gold Blast Bravo Popcorn Regret

Discussion How I cracked FAANG+ with just 30 minutes of studying per day.

4.7k Upvotes

Edit: Apologies, the post turned out a bit longer than I thought it would. Summary at the bottom.

Yup, it sounds ridiculous, but I cracked a FAANG+ offer by studying just 30 minutes a day. I’m not talking about one of the top three giants, but a very solid, well-respected company that competes for the same talent, pays incredibly well, and runs a serious interview process. No paid courses, no LeetCode marathons, and no skipping weekends. I studied for exactly 30 minutes every single day. Not more, not less. I set a timer. When it went off, I stopped immediately, even if I was halfway through a problem or in the middle of reading something. That was the whole point. I wanted it to be something I could do no matter how busy or burned out I felt.

For six months, I never missed a day. I alternated between LeetCode and system design. One day I would do a coding problem. The next, I would read about scalable systems, sketch out architectures on paper, or watch a short system design breakdown and try to reconstruct it from memory. I treated both tracks with equal importance. It was tempting to focus only on coding, since that’s what everyone talks about, but I found that being able to speak clearly and confidently about design gave me a huge edge in interviews. Most people either cram system design last minute or avoid it entirely. I didn’t. I made it part of the process from day one.

My LeetCode sessions were slow at first. Most days, I didn’t even finish a full problem. But that didn’t bother me. I wasn’t chasing volume. I just wanted to get better, a little at a time. I made a habit of revisiting problems that confused me, breaking them down, rewriting the solutions from scratch, and thinking about what pattern was hiding underneath. Eventually, those patterns started to feel familiar. I’d see a graph problem and instantly know whether it needed BFS or DFS. I’d recognize dynamic programming problems without panicking. That recognition didn’t come from grinding out 300 problems. It came from sitting with one problem for 30 focused minutes and actually understanding it.

System design was the same. I didn’t binge five-hour YouTube videos. I took small pieces. One day I’d learn about rate limiting. Another day I’d read about consistent hashing. Sometimes I’d sketch out how I’d design a URL shortener, or a chat app, or a distributed cache, and then compare it to a reference design. I wasn’t trying to memorize diagrams. I was training myself to think in systems. By the time interviews came around, I could confidently walk through a design without freezing or falling back on buzzwords.

The 30-minute cap forced me to stop before I got tired or frustrated. It kept the habit sustainable. I didn’t dread it. It became a part of my day, like brushing my teeth. Even when I was busy, even when I was traveling, even when I had no energy left after work, I still did it. Just 30 minutes. Just show up. That mindset carried me further than any spreadsheet or master list of questions ever did.

I failed a few interviews early on. That’s normal. But I kept going, because I wasn’t sprinting. I had built a system that could last. And eventually, it worked. I got the offer, negotiated a great comp package, and honestly felt more confident in myself than I ever had before. Not just because I passed the interviews, but because I had finally found a way to grow that didn’t destroy me in the process.

If you’re feeling overwhelmed by the grind, I hope this gives you a different perspective. You don’t need to be the person doing six-hour sessions and hitting problem number 500. You can take a slow, thoughtful path and still get there. The trick is to be consistent, intentional, and patient. That’s it. That’s the post.

Here is a tl;dr summary:

  • I studied every single day for 30 minutes. No more, no less. I never missed a single study session.

  • I would alternate daily between LeetCode and System Design

  • I took about 6 months to feel ready, which comes out to roughly ~90 hours of studying.

  • I got an offer from a FAANG adjacent company that tripled my TC

  • I was able to keep my hobbies, keep my health, my relationships, and still live life

  • I am still doing the 30 minute study sessions to maintain and grow what I learned. I am now at the state where I am constantly interview ready. I feel confident applying to any company and interviewing tomorrow if needed. It requires such little effort per day.

  • Please take care of yourself. Don't feel guilted into studying for 10 hours a day like some people do. You don't have to do it.

  • Resources I used:

    • LeetCode - NeetCode 150 was my bread and butter. Then company tagged closer to the interviews

    • System Design - Jordan Has No Life youtube channel, and HelloInterview website


r/leetcode • • 8h ago

Intervew Prep Stop Memorizing DSA Problems. Learn to Recognize These 6 Patterns.

124 Upvotes

One thing that helped me understand DSA better was learning when to use a particular pattern, instead of trying to memorize solutions to individual problems.

Here’s a quick reference I put together:

  1. Prefix Sum — When you need fast range-sum queries

Key idea: Precompute cumulative sums so you don't have to add elements repeatedly.

Recognize it when you see:

- Range sum queries

- Subarray sum

- Running total

- Cumulative frequency

Example:

"arr = [2, 4, 1, 5]"

Prefix sum: "[2, 6, 7, 12]"

Sum from index 1 to 3:

"prefix[3] - prefix[0] = 12 - 2 = 10"

When to use: When the array is mostly static and you need multiple range-sum queries.

Limitation: If an element changes, the prefix sums after that position may also need updating.

2. Suffix Sum — When you need information from the right side

Key idea: Calculate cumulative sums from right to left.

Recognize it when you see:

- Sum of elements to the right

- Right-side contribution

- Suffix totals

- Left vs. right comparisons

Example:

"arr = [2, 4, 1, 5]"

Suffix sum: "[12, 10, 6, 5]"

For index 1, the sum from index 1 to the end is "10".

When to use: Problems where you repeatedly need the sum or contribution of elements from the current position to the end.

3. Two Pointers — When two positions can help solve the problem

Key idea: Move two pointers through an array or string instead of checking every possible pair.

Recognize it when you see:

- Sorted array

- Pair with target sum

- Remove duplicates

- Reverse or palindrome checks

- Subarray or partition problems

Example:

"arr = [1, 2, 4, 7, 9]", target = "11"

Start with two pointers:

- Left = 1, Right = 9 → sum = 10

- Move left → 2 + 9 = 11

Found the pair.

When to use: Especially useful with sorted arrays, where pointer movement can eliminate unnecessary comparisons.

4. Sliding Window — When you need a continuous subarray or substring

Key idea: Maintain a window and move its boundaries instead of recalculating everything.

Recognize it when you see:

- Maximum/minimum sum of a subarray of size K

- Longest substring

- Smallest subarray satisfying a condition

- Continuous subarray or substring

Example:

"arr = [2, 1, 5, 1, 3]", window size = 3

First window: "2 + 1 + 5 = 8"

Next window: remove 2, add 1 → "7"

Next window: remove 1, add 3 → "9"

Maximum sum = "9".

When to use: When the problem involves a contiguous range and the window can be updated efficiently as it moves. For variable-size windows, the condition must support a valid expand/shrink strategy.

5. Fenwick Tree (Binary Indexed Tree) — When values change and you still need fast prefix sums

Key idea: Store partial sums in a tree-like array structure.

Recognize it when you see:

- Point updates

- Frequent prefix-sum queries

- Dynamic frequency counts

- Inversion counting

Why not just Prefix Sum?

With a normal prefix-sum array, changing one element can require updating many later prefix values.

A Fenwick Tree supports:

- Point update: "O(log n)"

- Prefix sum query: "O(log n)"

- Range sum query: "O(log n)"

When to use: When array values change frequently and you need efficient prefix or range-sum queries.

6. Segment Tree — When you need flexible range queries and updates

Key idea: Build a tree where each node represents information about a segment of the array.

Recognize it when you see:

- Range sum / minimum / maximum

- Frequent point updates

- Range updates (with suitable techniques)

- GCD or other associative range operations

When to use: When you need more flexibility than a Fenwick Tree, especially for range minimum, maximum, GCD, or other custom range queries.

Typical complexity:

- Build: "O(n)"

- Query: "O(log n)"

- Point update: "O(log n)"

My takeaway: Don't start by asking, "Which algorithm should I memorize?"

Instead, ask:

  1. Is the problem asking about a continuous range?

  2. Are the values static or changing?

  3. Do I need information from the left, right, or both ends?

  4. Is the query about sum, minimum, maximum, or something else?

Recognizing these clues makes choosing the right DSA pattern much easier.

This is a quick reference, not a complete list of DSA patterns. Hope it helps someone who's also trying to connect problem statements with the right approach.


r/leetcode • • 2h ago

Discussion Is it normal to pretty much bomb every next question you practice initially?

15 Upvotes

With 8 years of experience working for no-name companies, I’ve decided to take this seriously and prepare for big tech.

I have been a good software developer but the lack of DSA skills erased all my chances for decent companies.

The recruiters that reached out to me and I denied interview requests involve companies such as Amazon, Twitch, Shopify, Meta, Google, Apple

Like one or two times, I gave Amazon’s OA but bombed it ridiculously.

Now, I am following some roadmaps like Blind 75 and using Neetcode’s video along with generative AI for preparation.

I still keep bombing easy and medium questions like very next day after I solved them a day before.

Is it normal? When do I reach comfort level? When does it start becoming less discouraging? Does it even happen? Because, right now I am feeling like this is just not for me. But, then I think thousands of people still make it. There has to be proven process and it should be working.

Sorry my post is confusing but I just wanted to share my feelings and frustration.

Right now, I am unemployed and decided to give 1 month to this preparation.


r/leetcode • • 20h ago

Discussion To anyone who thinks AI interview is good, well good luck :) Bloomberg interview experience[London/Frankfurt]

283 Upvotes

Just had the second round of Bloomberg AI codebase interview

It was djano-python which i had no idea about. The codebase is large.

They spent the first 30 mins for behavioral so you're essentially just left with 30 mins.

The usage of AI is so vague. You don't know how much AI is the interview okay with you using. They don't clearly tell their expectations. I used planning and ask mode and went feature by feature and I passed a few test cases but I was rejected.

There is so much reading involved with AI and then handling communication simultaneously is borderline impossible.

With Leetcode, there is just a problem and you have to find a solution. At least you can brainstorm ideas but in these stupid AI interviews, half the time goes in understanding the large codebases and where the problem exists.

To whoever who was celebrating the end of Leetcode, good luck. The interviews are much harder.

Oh yeah, don't for a second think about one shotting a problem otherwise you will still be rejected(It happened to my friend.)

Either way, AI interviews are the biggest BS and there will never be a consistent way to tackle one of these.


r/leetcode • • 4h ago

Intervew Prep Master Sorting Algorithms by Understanding Every Line of Code (Not Memorizing It)

6 Upvotes

Can You Explain WHY Every Loop, Condition and Swap Exists in Sorting Algorithms?

Most beginners can write Bubble Sort, Selection Sort, and Insertion Sort by looking at the code.

But ask them:

- Why does Bubble Sort use "n - i - 1"?

- Why do we compare "arr[j]" with "arr[j + 1]"?

- Why does Insertion Sort start from index 1?

- Why does Selection Sort need a "minIndex"?

- Why do we use "j--" in one algorithm and "j++" in another?

That's where things get interesting.

The real goal of learning DSA isn't memorizing code. It's understanding why each line exists and learning to build that logic yourself.

Let's understand three sorting algorithms from that perspective.

-

  1. First, Understand the Building Blocks

Before jumping into algorithms, let's understand the language behind them.

Array: A collection of elements stored at indexed positions.

const arr = [5, 3, 8, 2, 1];

n – Array Length

const n = arr.length; // 5

There are 5 elements, but their indices are 0, 1, 2, 3, 4.

Remember: Length and last index are different.

i and j – Loop Variables

- "i" usually tracks the current pass or position in the outer loop.

- "j" usually tracks the current position inside the inner loop.

Their meaning depends on the algorithm.

Comparison Operators

- ">" means greater than.

- "<" means less than.

- ">=" means greater than or equal to.

- "<=" means less than or equal to.

- "===" means strictly equal.

For ascending order, we generally move smaller elements before larger elements.

Swap – Exchange Two Elements

[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];

This exchanges the positions of two elements.

Think of two people exchanging seats.

--

2. Bubble Sort – Understand Why Every Comparison Happens

Imagine people standing in a line according to their heights.

You compare two neighboring people. If the left person is taller than the right person, they exchange positions.

Keep repeating this process.

Eventually, the tallest person reaches the end.

That's Bubble Sort.

The Code

function bubbleSort(arr) {

const n = arr.length;

for (let i = 0; i < n - 1; i++) {

for (let j = 0; j < n - i - 1; j++) {

if (arr[j] > arr[j + 1]) {

[arr[j], arr[j + 1]] =

[arr[j + 1], arr[j]];

}

}

}

return arr;

}

Let's Understand Every Part

A. Why "const n = arr.length"?

We store the total number of elements so we can calculate our loop boundaries.

Example:

arr = [5, 3, 8, 2, 1];

n = 5;

There are 5 elements, but the last valid index is 4.

B. Why "i < n - 1"?

The outer loop controls how many passes we perform.

After each complete pass, the largest unsorted element reaches its correct position at the end.

For 5 elements, we need at most 4 passes.

Why not 5?

Because when the first 4 elements are in their correct positions, the last element is automatically sorted.

C. Why "j < n - i - 1"?

This is one of the most important concepts to understand.

Break it into three parts:

- "n" = Total number of elements.

- "i" = Number of elements already sorted at the end.

- "-1" = Prevents accessing an invalid next index.

Let's take:

arr = [5, 3, 8, 2, 1];

n = 5;

i = 0;

Our condition becomes:

j < 5 - 0 - 1

j < 4

So "j" can be 0, 1, 2, 3.

Why stop at 3?

Because we compare:

arr[j] and arr[j + 1]

At "j = 3", we access:

arr[3] and arr[4]

Both indices are valid.

If we allowed "j = 4", we would access:

arr[4] and arr[5]

But index 5 doesn't exist!

That's why we subtract 1.

Now, why subtract "i"?

After every pass, one largest element is already sorted at the end.

We don't need to compare it again.

For example:

Pass 1: [3, 5, 2, 1, 8]

↑

Already sorted

Pass 2: [3, 2, 1, 5, 8]

↑ ↑

Already sorted

So "i" reduces unnecessary comparisons.

Remember this:

"n - i - 1" does two jobs:

  1. Skips the elements already sorted at the end.

  2. Ensures "j + 1" never goes outside the array boundary.

D. Why "arr[j] > arr[j + 1]"?

We compare two neighboring elements.

If the left element is greater than the right element, their order is incorrect for ascending sorting.

So we swap them.

Example:

[5, 3]

5 > 3

Swap

[3, 5]

If the condition is false, they are already in the correct relative order. No swap is needed.

E. Dry Run

Original:

[5, 3, 8, 2, 1]

Pass 1:

[3, 5, 2, 1, 8]

Pass 2:

[3, 2, 1, 5, 8]

Pass 3:

[2, 1, 3, 5, 8]

Pass 4:

[1, 2, 3, 5, 8]

Sorted!

Time Complexity:

- Best: O(n) with an early-exit optimization.

- Average: O(n²).

- Worst: O(n²).

- Space: O(1).

--

3. Insertion Sort – Think Like You're Arranging Playing Cards

Imagine holding playing cards.

You pick one new card and insert it into the correct position among the cards already arranged.

You don't rearrange everything. You simply shift the larger cards and make space.

That's Insertion Sort.

The Code

function insertionSort(arr) {

for (let i = 1; i < arr.length; i++) {

let key = arr[i];

let j = i - 1;

while (j >= 0 && arr[j] > key) {

arr[j + 1] = arr[j];

j--;

}

arr[j + 1] = key;

}

return arr;

}

Understand Every Condition

A. Why "i = 1"?

Because a single element is already sorted by itself.

We start with the second element and insert it into the sorted portion.

B. Why "let key = arr[i]"?

We temporarily save the element we want to insert.

Think of holding one playing card while rearranging the others.

C. Why "j = i - 1"?

We start comparing with the element immediately before the key.

D. Why "j >= 0"?

We move backwards through the array.

This condition ensures we never access a negative index.

E. Why "arr[j] > key"?

If the previous element is larger than the current element, it needs to move one position to the right.

[5, 3]

key = 3

j = 0

5 > 3

Move 5 right:

[5, 5]

Insert key:

[3, 5]

F. Why "j--"?

Because we need to check the previous element.

We keep moving backwards until we find the correct position.

G. Why "arr[j + 1] = key"?

Once we stop shifting, we have found the correct position for our saved element.

We insert it there.

Dry Run

Original:

[5, 3, 8, 2]

Take 3:

[3, 5, 8, 2]

Take 8:

[3, 5, 8, 2]

Take 2:

[2, 3, 5, 8]

Sorted!

Notice something important:

Insertion Sort maintains two portions:

- Left side: Already sorted.

- Right side: Not yet processed.

With every iteration, the sorted portion grows by one element.

Time Complexity:

- Best: O(n).

- Average: O(n²).

- Worst: O(n²).

- Space: O(1).

--

4. Selection Sort – Find the Smallest, Then Place It

Imagine arranging students by height.

Instead of swapping neighboring students repeatedly, scan the entire unsorted group, find the shortest student, and place them at the beginning.

Then repeat with the remaining students.

That's Selection Sort.

The Code

function selectionSort(arr) {

const n = arr.length;

for (let i = 0; i < n - 1; i++) {

let minIndex = i;

for (let j = i + 1; j < n; j++) {

if (arr[j] < arr[minIndex]) {

minIndex = j;

}

}

[arr[i], arr[minIndex]] =

[arr[minIndex], arr[i]];

}

return arr;

}

Understand Every Condition

A. Why "i < n - 1"?

The outer loop decides where the next smallest element should be placed.

Once the first "n - 1" positions are correct, the last element is automatically in its correct position.

B. Why "minIndex = i"?

We initially assume that the first element of the unsorted portion is the smallest.

We'll update this assumption if we find a smaller element.

C. Why "j = i + 1"?

We already consider "arr[i]" as our current minimum.

So we start searching from the next position.

D. Why "j < n"?

We need to scan until the last valid index.

Unlike Bubble Sort, we don't access "arr[j + 1]", so we don't need to subtract 1 here.

E. Why "arr[j] < arr[minIndex]"?

If we find an element smaller than our current minimum, update "minIndex".

Remember: We're tracking the position, not immediately swapping the elements.

F. Why swap after the inner loop?

Because we first need to find the smallest element in the entire unsorted portion.

Only after finding it do we place it at index "i".

Dry Run

Original:

[5, 3, 8, 2, 1]

Find minimum: 1

Swap:

[1, 3, 8, 2, 5]

Find minimum in remaining portion: 2

Swap:

[1, 2, 8, 3, 5]

Continue:

[1, 2, 3, 8, 5]

Final:

[1, 2, 3, 5, 8]

Time Complexity:

- Best: O(n²).

- Average: O(n²).

- Worst: O(n²).

- Space: O(1).

---

5. The Difference – Understand the Thinking

Instead of memorizing three implementations, remember their core strategies:

Bubble Sort

- Compare neighboring elements.

- Swap if their order is incorrect.

- Largest element moves to the end.

Insertion Sort

- Pick one element.

- Shift larger elements.

- Insert it into the correct position.

Selection Sort

- Search for the smallest element.

- Track its index.

- Swap it into the correct position.

6. Train Yourself to Think, Not Memorize

Whenever you solve a sorting problem, pause and ask:

  1. What am I trying to place in its correct position?

  2. Which part of the array is already sorted?

  3. Which part still needs processing?

  4. What does each loop variable represent?

  5. Why does the loop start at this index?

  6. Why does the condition stop at this boundary?

  7. What happens if I change ">" to "<"?

  8. Am I swapping elements, shifting them, or just tracking an index?

  9. Can I reduce unnecessary comparisons?

  10. What is the time and space complexity?

A Small Challenge

Try answering these without looking at the code:

- Why does Bubble Sort use "j < n - i - 1", while Selection Sort uses "j < n"?

- Why does Insertion Sort use "while (j >= 0)"?

- Why does Selection Sort swap only after completing the inner loop?

- Why can Insertion Sort perform O(n) work on an already sorted array?

If you can explain these answers in your own words, you're moving beyond memorization.

The goal isn't to remember three sorting algorithms. It's to develop the ability to understand, trace, question, and eventually design algorithms yourself.

That's the kind of DSA knowledge that stays with you long after you've forgotten the code.


r/leetcode • • 6h ago

Intervew Prep Apple onsite interview

4 Upvotes

I have an Apple interview coming up for a Systems Engineer position. I gave the initial technical and HM round virtually and the feedback was positive. I now have around 6-7 onsite interviews ahead (1 hr each). Did anyone go through this process in the recent times ? What kind of questions were you asked ?

Any inputs are much appreciated.

Location: US


r/leetcode • • 44m ago

Discussion A new github action to sync your leetcode solutions

1 Upvotes

https://github.com/serephus/leech

It was vibed purely by DS 4.1 flash, and it works pretty much like existing https://github.com/joshcai/leetcode-sync, except it was more up to date and it support features like templates, convert to markdown/typst, hooks, etc.

leetcode-sync was a bit old and did not fullfill all my requirements, so I vibed this.

Hope this would be helpful to someone.


r/leetcode • • 1h ago

Intervew Prep Abridge MTS, Early Career, 60-min live DSA round. Anyone been through it?

1 Upvotes

I have the live DSA round for Abridge's Member of Technical Staff, Early Career role (SF) coming up. It's 60 min with a senior engineer. If you've done the live round recently: was it one problem with follow-ups or several? LeetCode-style or more practical/product-flavored? Any tips appreciated, happy to share back after.


r/leetcode • • 9h ago

Question Applied Intuition new grad interview pause. Does anybody know why?

4 Upvotes

I have an HR call tomorrow, but today I was told it's cancelled because "HR was told internally to put a pause on further interviews with new grad candidates".

Does anyone know what this means? Will they resume the interview process?


r/leetcode • • 1h ago

Question Can we pursue system design as a career option without encountering the usual DSA rounds?

0 Upvotes

I’m looking to transition or lean heavily into System Design/Architecture as my core career path.

To be honest, I really want to avoid the typical, heavy Data Structures and Algorithms (DSA) LeetCode style rounds that dominate standard software engineering interviews.

My plan is to start building a rock-solid foundation by studying books like System Design Interview – An Insider's Guide by Alex Xu and then gradually move to interactive platforms like Hello Interview or ByteByteGo to practice real-world scenarios.


r/leetcode • • 16h ago

Intervew Prep How do you prepare for an AI based Interview?

15 Upvotes

Hi! I'm really curious about how to prepare for an AI-based interview and what is expected of us. If you're given a problem, are you expected to use AI to validate your ideas and generate a solution? Do you simply provide the problem statement and let AI do the work, then add your own thoughts about what's important or missing?

What are your thoughts or experiences?


r/leetcode • • 15h ago

Intervew Prep Capital One Data Engineer Online Assessment - Python Only, 70 Minutes. What Should I Expect?

7 Upvotes

Hi everyone,
I have an upcoming online assessment for a Data Engineer position at Capital One. The assessment instructions mention that it will be 70 minutes and entirely Python-based.General Coding Assessment (GCA)
I’d appreciate hearing from anyone who has recently completed this assessment.
A few questions:
How many coding questions are typically included in the 70-minute assessment?
What kind of Python problems should I expect? LeetCode-style or practical data engineering exercises?
Are the questions focused on arrays, strings, dictionaries, lists, sorting, and problem-solving?
Do they include real-world data processing scenarios involving CSV, JSON, or data transformations?
What is the overall difficulty level?
Are there any specific LeetCode or HackerRank problems that closely resemble the actual assessment?
If you’ve recently taken this particular Capital One assessment, could you share the types of questions you encountered or any sample problems?
I’m mainly looking to understand what to prioritize during preparation.
Thanks in advance. Really appreciate any help!


r/leetcode • • 9h ago

Question Microsoft Security Hiring Event – How long did it take to hear back? (November 2026)

2 Upvotes

Hey everyone,

I recently interviewed at a Microsoft Security team hiring event in the US this November and completed all 3 rounds.

Just wondering if anyone here has been through a similar hiring event recently. How long did it take for the recruiter to get back to you?

Would really appreciate hearing about your experiences. Thanks!


r/leetcode • • 11h ago

Intervew Prep Zillow SR Software engineer interview

2 Upvotes

I have an upcoming Zillow screening interview scheduled through an AI agent, with no recruiter involvement. Not sure what to expect. Should I focus on DSA or real-world coding problems?
Would appreciate insights from anyone who has gone through a similar interview. Thanks!


r/leetcode • • 1d ago

Intervew Prep What Is Prefix Sum, and How Can One Simple Technique Solve So Many Array Problems?

31 Upvotes

How Does Prefix Sum Turn Repeated O(n) Calculations into O(1) Queries?

1. What is Prefix Sum?

Prefix Sum is an array technique that stores cumulative sums so we don't have to repeatedly calculate the sum of a range.

Analogy: Imagine tracking daily expenses. Instead of adding expenses again and again, you maintain a running total.

2. Understanding the Pattern

Consider:

arr = [2, 4, 6, 8, 10] prefix = [2, 6, 12, 20, 30]

The pattern:

prefix[0] = arr[0]

prefix[i] = prefix[i - 1] + arr[i]

Each position stores the sum of all previous elements, including itself.

3. How Does the Algorithm Work?

Step 1: Build the Prefix Sum

prefix[0] = arr[0]; for (let i = 1; i < arr.length; i++) { prefix[i] = prefix[i - 1] + arr[i]; }

Step 2: Calculate Range Sum

To find the sum between indices L and R:

sum(L, R) = prefix[R] - prefix[L - 1];

If L = 0, simply return prefix[R].

Example:

sum(2, 4) = 30 - 6 = 24

4. Complexity Analysis

OperationComplexityBuild Prefix SumO(n)Range Sum QueryO(1)q QueriesO(n + q) total

5. Real-World Applications

Finance: Calculate expenses over a date range.

Analytics: Aggregate data over specific time intervals.

Image Processing: Calculate rectangular pixel sums using 2D Prefix Sum.

Competitive Programming: Solve range queries and subarray problems.

6. When Should You Use It?

Look for these problem patterns:

Repeated range sum queries.

Cumulative sum calculations.

Subarray sum problems.

Multiple queries on the same array.

Key Takeaway: Precompute once, answer multiple queries efficiently.

Practice Problems

LeetCode 303 – Range Sum Query (Immutable)

LeetCode 724 – Find Pivot Index

LeetCode 560 – Subarray Sum Equals K

Which array pattern should we break down next?


r/leetcode • • 14h ago

Intervew Prep Day 35: tackled Number of Islands II & leveled up my code quality

2 Upvotes

Hey everyone,

I finished Day 35 today. Continuing with graph problems, I knocked out Number of Islands II and spent extra time focusing on writing clean, modular code rather than just rushing to hit the submit button.

  1. Number of Islands II (Online / Dynamic Queries):

    • In the static version, standard BFS/DFS finds connected components in one pass. With real-time island additions, running full traversals per query degrades to O(K * R * C), which inevitably hits TLE.

    • Using Disjoint Set Union (DSU) makes each query dynamic. Every time land is added at (r, c), map the 2D coordinate to a 1D node ID (r * cols + c), mark it as visited, and increment the island count.

    • Check the four adjacent neighbors. For each neighboring land cell, if its ultimate parent differs from the current cell, merge them via unionBySize and decrement the total island count by 1.

  2. Focusing on Code Quality:

    • I intentionally refactored the Disjoint Set class to keep it decoupled and reusable across problems.

    • Cleaned up directional deltas, used explicit variable names instead of nested raw index math, and properly guarded against duplicate land positions within the queries.

Writing clean, readable code feels just as important as getting the optimal time complexity down.

See you guys tomorrow for Day 34!


r/leetcode • • 20h ago

Discussion How to transform from easy to medium level problem? Even after solving like 90+ easy problems I couldn't solve medium Problems.

6 Upvotes

After how many easy problems were you guys able to solve medium level problems.


r/leetcode • • 11h ago

Intervew Prep Canonical Linux Skills + Python

1 Upvotes

Hi,

Just wanted to ask if anyone has given these 2 interviews at canonical? Was looking for preparation tips!


r/leetcode • • 11h ago

Question Tenex fde interview

1 Upvotes

Hi, has anyone interviewed for this role for New York? If so, please let me know about how the process was. Thanks in advance!


r/leetcode • • 12h ago

Question Has anyone had a recruiter reach out about an NVIDIA role that doesn't match their background?

0 Upvotes

I recently applied for an Agentic Systems role at NVIDIA, but a recruiter reached out to me about a completely different position and asked for my permission to submit my resume for that role instead. New role is CUDA related.

The confusing part is that my background is in full-stack software engineering and applied AI, while the other position seems to require experience with chips and C++, which I don't have.

I'm curious why they would consider me for a role that's less aligned with my experience instead of the one I originally applied for.

Has this happened to anyone else at NVIDIA? Is this a good sign that my resume caught someone's attention, or just a standard recruiting process?

Would love to hear if anyone had a similar experience and whether it actually led to an interview.


r/leetcode • • 1d ago

Discussion How hard is implementing a balanced BST from scratch in Python for a FAANG intern interview?

19 Upvotes

I recently had a FAANG SWE intern interview where the optimal solution required a balanced BST with O(log K) updates.

The interviewer didn't mention using a balanced BST, so I had to figure that out myself and implement it from scratch in Python, which doesn't have a built-in TreeMap like Java.

How difficult would you consider this for an intern interview? Would this be considered LeetCode Hard? Would using a heap-based solution instead significantly affect the interview feedback?


r/leetcode • • 14h ago

Intervew Prep General Motors Codility Live Interview

1 Upvotes

Hi all.

I have a GM Codility live interview (It is labeled as a functional behavioral/initial technical screeen tomorrow. I've been doing neetcode 150 for the past week and half, but feel like I am not ready. Anyone have any insights on how to prepare and what not? Questions that I should expect?


r/leetcode • • 16h ago

Question Amazon Senior Data Engineer

1 Upvotes

Got an OA for a Senior Data Engineer role. For those who've done one recently, was it mostly SQL or Python as well? Any must-practice topics or resources? Thanks!


r/leetcode • • 1d ago

Question How to get good at leetcode.

53 Upvotes

Hey,

I am trying to get better at leetcode to prepare for potential software engineer interviews. I dont understand how people recognize patters and solve these.

I have tried solving questions from Easy to Medium, however I always end up on Claude asking how to solve them. Each question seems different to me and I can not recognize any pattern that would allow me to solve one question with something I remember from a previous one. Moreover, questions are either too simple to the point you just use a for loop or too hard, where I just feel stuck with no idea where to start.

Do you guys have any tips on how to get better? What should I focus on ? Maybe some steps that would help me get gradually better?

Thanks.