TGViewer
Channel Public Channel
Coding Interview Preparation

Coding Interview Preparation

@coding_interview_preparation

Coding interview preparation for software engineers

Interview questions, DSA, clean solutions.
Join ๐Ÿ‘‰ https://rebrand.ly/bigdatachannels

Buy ads: https://telega.io/c/coding_interview_preparation

DMCA: @disclosure_bds
Contact: @mldatascientist
Subscribers
5.9K
Photos
486
Videos
2
Links
174

Showing posts older than #1402 ยท Back to latest

Older Posts 20 shown
Post #1401 284
๐Ÿ’ฐ SALARY NEGOTIATION #4 - Negotiating Equity, Not Just Salary

Especially at startups, equity can be worth more than the base salary difference - but most candidates don't know what questions to ask.

โœ… Questions to ask before accepting any equity offer:

1. "How many total shares are outstanding, fully diluted?" (Your number of shares means nothing without this - 10,000 shares out of 10 million is very different from 10,000 out of 100 million)

2. "What's the strike price, and what's the most recent 409A valuation?" (This tells you the real cost to exercise, and a rough sense of current value)

3. "What's the vesting schedule?" (Standard is 4 years with a 1-year cliff - meaning you get nothing if you leave before year one)

4. "Is there a post-termination exercise window longer than 90 days?" (Standard 90-day windows force ex-employees to either pay to exercise immediately or lose their vested equity - some companies now offer extended windows, which is a real, valuable perk to ask about)

If a recruiter can't answer these clearly, that's itself useful information about the company's transparency.

Bottom line: never treat "$X in equity" as a clean number to compare across offers without understanding the mechanics behind it.

Has anyone here actually had equity turn into real money? Tell us about it ๐Ÿ‘€
Post #1400 274
๐Ÿง  EDUCATIONAL CS #4 - Trees, Graphs, and the Difference That Matters

A tree is just a graph with two extra rules: no cycles, and exactly one path between any two nodes.


Tree: Graph (with cycle):
1 1 --- 2
/ \ | |
2 3 4 --- 3


Why does this distinction matter in interviews?

๐Ÿ”น In a tree, you never need to track visited nodes during traversal - since there are no cycles, you literally cannot revisit a node.

๐Ÿ”น In a graph, you MUST track visited nodes, or you risk infinite loops.

python
# Graph DFS - visited set is NOT optional
def dfs(graph, node, visited=None):
if visited is None:
visited = set()
if node in visited:
return
visited.add(node)
for neighbor in graph[node]:
dfs(graph, neighbor, visited)


Forgetting the visited set is one of the most common graph-traversal bugs in interviews - code that works perfectly on the example tree-like input, then infinite-loops the moment the interviewer adds one cycle to the test case (which they often do specifically to check this).

Also worth knowing cold: BFS finds the SHORTEST path in an unweighted graph; DFS does not guarantee that. If a problem says "shortest," that's your signal to reach for BFS.

Quick one: is a linked list technically a tree, a graph, both, or neither? ๐Ÿ‘‡
Post #1399 302
๐Ÿ—๏ธ SYSTEM DESIGN MONDAY #5 - Let's Design TinyURL

Time for our first full end-to-end design. Requirements:

โœ… Given a long URL, generate a short one
โœ… Given a short URL, redirect to the original
โœ… High read traffic (redirects happen constantly), lower write traffic (new URLs created less often)

Step 1 - the core challenge: how do we generate a short, unique code for each URL?

Option A: Hash the URL (like MD5) and take the first 7 characters. Risk: collisions, requires checking uniqueness.
Option B (better): use an auto-incrementing ID from the database, then convert it to base62 (a-z, A-Z, 0-9). ID 125 becomes something like "cb" - dramatically shorter, always unique by construction.

Step 2 - the architecture:

[Client] โ†’ [Load Balancer] โ†’ [App Servers] โ†’ [Cache] โ†’ [Database]
(hot URLs cached
for fast redirects)


Step 3 - the schema:

urls
+--------+--------------------------+---------------------+
| id | short_code | long_url | created_at |
+--------+------------+-------------+---------------------+
| 125 | cb | example.com | 2024-01-01 10:00:00 |


Step 4 - the follow-ups interviewers actually ask:
๐Ÿ”น "What if two servers generate the same ID at the same time?" โ†’ Use a centralized ID generator service, or database auto-increment, or a distributed ID scheme like Twitter's Snowflake.
๐Ÿ”น "How do you handle a URL that goes viral overnight?" โ†’ This is exactly why we cache hot URLs - the cache absorbs the read spike so the database doesn't get hammered.
๐Ÿ”น "Should short codes expire?" โ†’ Product decision, not purely technical - worth explicitly asking your interviewer this instead of assuming.

The key skill being tested isn't "do you know TinyURL" - it's whether you can reason from requirements to architecture out loud, and handle the follow-up curveballs.

If you were designing this, would you go with hash-based or counter-based short codes? ๐Ÿ‘‡
Post #1398 301
๐Ÿ” GUESS THE OUTPUT #5 - full breakdown

python
print(bool("False"))
print(bool(""))
print(bool([False]))
print(bool(0.0))


Answers:

True
False
True
False


Breakdown:
1๏ธโƒฃ "False" is a non-empty string - any non-empty string is truthy, REGARDLESS of its content. The string literally saying "False" doesn't matter.
2๏ธโƒฃ "" is an empty string - falsy.
3๏ธโƒฃ [False] is a list containing one element - and non-empty lists are always truthy, regardless of what's inside them.
4๏ธโƒฃ 0.0 is falsy, just like 0.

This one trips up even experienced developers because #1 and #3 look like they "should" be False at a glance, but Python's truthiness rules only care about emptiness/zero-ness of the container itself, never its contents.

Which one did you get wrong, if any? Be honest ๐Ÿ˜„
Post #1395 311
๐Ÿ” GUESS THE OUTPUT #5
Language: Python

python
print(bool("False"))
print(bool(""))
print(bool([False]))
print(bool(0.0))


Lock in your answer, then vote on the quiz below ๐Ÿ‘‡
Post #1394 356
๐Ÿ“Š SQL SATURDAY #5 - Window Functions (The Interview Differentiator)

If GROUP BY collapses rows, window functions let you calculate aggregates WITHOUT collapsing them - you keep every row, plus a calculated value alongside it. This is one of the clearest signals of SQL seniority in interviews.


sales
+----+------------+--------+
| id | department | amount |
+----+------------+--------+
| 1 | Eng | 100 |
| 2 | Eng | 200 |
| 3 | Sales | 150 |
| 4 | Sales | 300 |


Question: Show each sale alongside the total for its department, without collapsing rows.

sql
SELECT id, department, amount,
SUM(amount) OVER (PARTITION BY department) AS dept_total
FROM sales;



+----+------------+--------+------------+
| id | department | amount | dept_total |
+----+------------+--------+------------+
| 1 | Eng | 100 | 300 |
| 2 | Eng | 200 | 300 |
| 3 | Sales | 150 | 450 |
| 4 | Sales | 300 | 450 |


PARTITION BY is like GROUP BY, but it doesn't collapse the rows - every row keeps its own identity while gaining group-level context.

Another classic interview favorite - ranking within groups:
sql
SELECT id, department, amount,
RANK() OVER (PARTITION BY department ORDER BY amount DESC) AS dept_rank
FROM sales;


โš ๏ธ Interview trap: RANK() vs DENSE_RANK() vs ROW_NUMBER() - know the difference cold:
๐Ÿ”น ROW_NUMBER() - always unique, 1,2,3,4, even with ties
๐Ÿ”น RANK() - ties share a rank, but the NEXT rank skips (1,1,3,4)
๐Ÿ”น DENSE_RANK() - ties share a rank, next rank does NOT skip (1,1,2,3)

Interviewers love asking you to explain this exact difference, then predict output on a tied dataset.

Which of the three ranking functions do you use most in your actual job? ๐Ÿ‘‡
Post #1393 325
๐Ÿ“„ RESUME ROAST #4

> "2020-2023: Software Engineer
> 2023-2024: Senior Software Engineer
> 2024-Present: Software Engineer II"

Spot the issue before I explain ๐Ÿ‘‡

.
.
.

The roast: This looks like a demotion, and recruiters WILL notice and wonder about it - even if "Software Engineer II" is actually a level ABOVE "Senior Software Engineer" at your specific company (title inflation and naming varies wildly between companies).

The resume doesn't explain that, so it just reads as a step backward, and most recruiters won't take the time to ask - they'll just quietly deprioritize the resume.

โœ… The fix: add a one-line clarifying note, or better, standardize your titles to reflect actual seniority level consistently:

> "2024-Present: Software Engineer II (Senior-equivalent level at [Company]'s leveling structure)"

Or simply pick the title that most clearly communicates your actual seniority to an outside reader, even if it's not your exact internal title - as long as it's honest and defensible if asked about in an interview.

Never assume the reader knows your company's internal quirks. Assume zero context and write for a stranger.

Anyone else dealt with a confusing title change like this? ๐Ÿ‘‡
Post #1392 288
๐ŸŽฏ CODING CHALLENGE #7 - Kth Largest Element in an Array
Difficulty: Medium | Asked at: Facebook, Amazon, Google


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


๐Ÿ’ก Hint: Sorting works but is O(n log n). Can you do better with a heap that only ever holds k elements?

Solution (min-heap approach):
python
import heapq

def find_kth_largest(nums, k):
heap = nums[:k]
heapq.heapify(heap)

for num in nums[k:]:
if num > heap[0]:
heapq.heapreplace(heap, num)

return heap[0]


Complexity: O(n log k) time, O(k) space - much better than sorting when k is small relative to n.

Common mistake: Using a max-heap of the FULL array (heapifying all n elements, then popping k times) - this works, but it's a weaker answer. Building a min-heap of just size k and comparing incoming elements against the smallest kept element is the optimization interviewers are hoping to see.

Alternative: Quickselect gets this down to average O(n) time, though worst case O(nยฒ) - a great follow-up to mention if you want to show extra depth.

Do you know Quickselect, or is the heap approach your default here? ๐Ÿ‘‡
Post #1391 286
๐Ÿ•ต๏ธ RECRUITER SECRETS #4 - What Actually Happens After Your Interview

Ever wondered what happens the moment you leave that Zoom call? Here's the real process at most mid-to-large companies:

1๏ธโƒฃ Each interviewer independently writes feedback and a rating (usually a scale like "Strong Hire / Hire / No Hire / Strong No Hire") before discussing with anyone else - this is intentional, to avoid groupthink.

2๏ธโƒฃ These are compiled into a packet for a hiring committee or debrief meeting - often people who never even met you.

3๏ธโƒฃ One "no hire" from a single round can sometimes be overridden by strong signal elsewhere, but a "strong no hire" is very difficult to recover from, even with great other rounds.

4๏ธโƒฃ The single biggest factor in close calls: whether interviewers can point to specific examples in their notes, not vague impressions. This is why articulating your thinking clearly matters so much - a vague "good vibes" interview generates a vague, easily-overruled recommendation.

Here's the actionable part: at the end of every round, briefly summarize what you just demonstrated. "Just to recap, I approached this with a hash map for O(1) lookups, handled the edge cases we discussed, and we walked through the complexity together." This gives the interviewer an easy, concrete sentence to write down - literally doing their job for them.

Did this change how you think about what happens after you leave the interview? ๐Ÿ‘‡
  • โค 2
Post #1390 316
๐Ÿ› SPOT THE BUG #4
Language: JavaScript (React)

javascript
function UserProfile({ userId }) {
const [user, setUser] = useState(null);

useEffect(() => {
fetchUser(userId).then(data => setUser(data));
});

return <div>{user?.name}</div>;
}


What's the bug? ๐Ÿ‘‡

.
.
.

The bug: Missing dependency array in useEffect. Without [userId] (or even []), this effect runs after EVERY render - and since setUser triggers a re-render, and that re-render triggers the effect again, you get either an infinite fetch loop or, at minimum, wildly wasteful re-fetching.

Fixed version:
javascript
useEffect(() => {
fetchUser(userId).then(data => setUser(data));
}, [userId]); // only re-run when userId changes


โš ๏ธ Bonus bug hiding here too: if userId changes quickly (user navigates between profiles fast), an OLDER fetch can resolve AFTER a newer one, overwriting fresh data with stale data ("race condition"). The fix is usually a cleanup function that ignores outdated responses:

javascript
useEffect(() => {
let ignore = false;
fetchUser(userId).then(data => {
if (!ignore) setUser(data);
});
return () => { ignore = true; };
}, [userId]);


React hooks bugs are EXTREMELY common in frontend interviews right now. Have you been bitten by a missing dependency array before? ๐Ÿ‘‡
  • โค 1
Post #1389 277
๐Ÿ’ฌ POLL / DISCUSSION - Which Interview Round Scares You Most?

React with the emoji that matches your answer:

1๏ธโƒฃ Coding round
2๏ธโƒฃ System design round
3๏ธโƒฃ Behavioral round
4๏ธโƒฃ Take-home assignment
5๏ธโƒฃ "Culture fit" round with a random exec

Comment WHY below - the reasons are usually more interesting than the answer itself ๐Ÿ‘‡
Post #1388 380
๐Ÿ—ฃ๏ธ BEHAVIORAL INTERVIEW #3 - "Tell Me About a Conflict With a Coworker"

This one tests emotional maturity more than anything technical.

โŒ Instant red flags:
- Making the other person sound irrational or incompetent
- A story where you were 100% right and they were 100% wrong (real conflicts are rarely that clean)
- No resolution - just "it eventually blew over"

โœ… What works: pick a genuine disagreement about approach (not a personality clash), show you understood their perspective, and show how you reached resolution through communication, not just "waiting it out."

Example:
"A teammate and I disagreed on whether to refactor a legacy module before adding a new feature, or ship the feature first and refactor later. I initially pushed hard for refactoring first because I was worried about tech debt. Instead of just repeating my position, I asked him to walk me through his reasoning, and it turned out he had context I didn't - a hard deadline from a client commitment I wasn't aware of. We agreed on a middle path: ship the feature with a couple of safety tests around the risky area, and scheduled the refactor for the following sprint. It taught me to ask 'what am I missing?' before digging into a position."

Notice: real disagreement, real listening, real compromise, real lesson. That's the formula.

What's a work disagreement you'd feel comfortable sharing (with names/details changed, of course)? ๐Ÿ‘‡
Post #1387 330
๐ŸŽฏ CODING CHALLENGE #6 - Binary Tree Level Order Traversal
Difficulty: Medium | Asked at: Amazon, Microsoft, LinkedIn

Given a binary tree, return its values level by level (BFS).


3
/ \
9 20
/ \
15 7

Output: [[3], [9, 20], [15, 7]]


๐Ÿ’ก Hint: BFS naturally processes a tree level by level using a queue. The trick is tracking how many nodes belong to the CURRENT level before you start adding next-level nodes to the same queue.

Solution:
python
from collections import deque

def level_order(root):
if not root:
return []

result = []
queue = deque([root])

while queue:
level_size = len(queue)
current_level = []

for _ in range(level_size):
node = queue.popleft()
current_level.append(node.val)
if node.left:
queue.append(node.left)
if node.right:
queue.append(node.right)

result.append(current_level)

return result


Complexity: O(n) time and space - every node is visited and queued exactly once.

Common mistake: Forgetting to snapshot level_size = len(queue) BEFORE the inner loop starts. If you check len(queue) inside the loop, it changes as you enqueue children, and your levels get mixed together.

BFS with a queue vs. DFS with recursion - do you know when to reach for each? That's often the actual follow-up question here ๐Ÿ‘‡
Post #1386 301
๐Ÿ—๏ธ SYSTEM DESIGN MONDAY #4 - Databases at Scale: Sharding & Replication

Your single database is now the bottleneck - too much data, too many writes, too many reads. Two techniques solve two different problems:

Replication (solves READ scaling):

โ”Œโ”€โ”€โ–ถ [Read Replica 1]
[Primary DB] โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ–ถ [Read Replica 2]
(writes) โ””โ”€โ”€โ–ถ [Read Replica 3]

All writes go to the primary. Reads get spread across replicas, which stay in sync via replication. Great when you have way more reads than writes (true for most apps).

โš ๏ธ Watch for replication lag - replicas can be milliseconds to seconds behind the primary. If a user posts a comment and immediately refreshes, they might not see it yet if they're routed to a lagging replica. This is a classic system design follow-up question.

Sharding (solves WRITE scaling and storage limits):

[Shard 1: users A-H] [Shard 2: users I-P] [Shard 3: users Q-Z]

Split your data across multiple databases, each holding a subset. Now write load AND storage is distributed, not just reads.

The hard part interviewers dig into: how do you pick a shard key? Pick badly (like splitting alphabetically by name) and you get "hot shards" - massively uneven load, since names aren't evenly distributed. A better key is often something like user_id % number_of_shards, or a hash of the ID, to spread load evenly.

The other hard part: cross-shard queries (like "find all users who did X across every shard") become expensive, since you often need to query every shard and merge results.

If you were sharding a system like Instagram by user_id, what's one query that would suddenly become painful? ๐Ÿ‘‡
Post #1385 282

Forwarded from Cool GitHub repositories

hiring-without-whiteboards

A list of companies (or teams) that don't have a broken hiring process. The companies and teams listed here use interview techniques and questions that resemble day-to-day work.

Creator: poteto
Stars โญ๏ธ: 51,200
Forked by: 3,903

Github Repo:
https://github.com/poteto/hiring-without-whiteboards

โž–โž–โž–โž–โž–โž–โž–โž–โž–โž–โž–โž–โž–โž–
Join @github_repositories_bds for more cool repositories. This channel belongs to @bigdataspecialist group
GitHub GitHub - poteto/hiring-without-whiteboards: โญ๏ธ Companies that don't have a broken hiring process โญ๏ธ Companies that don't have a broken hiring process - poteto/hiring-without-whiteboards
  • ๐Ÿ‘ 1
Post #1384 316
โš ๏ธ COMMON INTERVIEW MISTAKE #3 - Not Testing Your Own Code

You finish coding, say "I think that's it," and stop. The interviewer asks "are you sure this works?" - and you just... shrug.

This is one of the most avoidable point losses in the entire interview.

โœ… What to do instead: Before declaring you're done, manually trace through your code with the example input(s) given. Actually walk through it line by line, tracking variable values as you go - out loud.

"Let's trace through with nums = [2,7,11,15], target = 9. i=0, num=2, complement=7, not in seen yet, so seen={2:0}. i=1, num=7, complement=2, IS in seen at index 0 - so we return [0,1]. That matches the expected output."

This catches real bugs before the interviewer has to point them out (which is a much worse look), and it demonstrates the exact skill you'd use before merging a real pull request.

Bonus: always test at least one edge case too (empty input, single element, all duplicates) - don't just re-test the example they gave you.

Do you naturally trace through your code, or does it feel like an extra step you skip under time pressure? ๐Ÿ‘‡
Post #1383 303
๐Ÿ•ต๏ธ RECRUITER SECRETS #3 - Why "We'll Get Back to You" Sometimes Means Nothing

Uncomfortable truth: sometimes a recruiter genuinely doesn't know when they'll get back to you, and "we'll follow up soon" is a real answer, not a brush-off - internal hiring processes are often slower and messier than candidates assume.

But here's what you SHOULD do instead of just waiting anxiously:

โœ… Ask directly at the end of every interview: "What does the timeline look like from here, and who should I follow up with?" This isn't pushy - it's expected, and it makes you look organized.

โœ… If you haven't heard back by the timeline they gave you, it's completely appropriate to send ONE polite follow-up: "Hi [Name], just checking in on the status of my application for [Role] - happy to provide anything else that's useful. Thanks!"

โœ… If you have a competing offer with a deadline, tell your recruiter immediately. Companies move surprisingly fast when there's real time pressure - this is one of the few legitimate ways to speed up a slow process.

What you should NOT do: message the hiring manager on LinkedIn every 2 days, or email multiple people at the company hoping someone responds faster. It reads as impatience, not enthusiasm.

Have you ever had to nudge a stalled interview process? What did you say? ๐Ÿ‘‡
Post #1382 288
๐Ÿ“Š SQL SATURDAY #4 - Subqueries and CTEs

Time to clean up messy nested queries. Same orders table as before.

The old, hard-to-read way (nested subquery):
sql
SELECT customer_id, total_spent
FROM (
SELECT customer_id, SUM(amount) AS total_spent
FROM orders
GROUP BY customer_id
) AS customer_totals
WHERE total_spent > 150;


The cleaner way, using a CTE (Common Table Expression):
sql
WITH customer_totals AS (
SELECT customer_id, SUM(amount) AS total_spent
FROM orders
GROUP BY customer_id
)
SELECT customer_id, total_spent
FROM customer_totals
WHERE total_spent > 150;


Same result, dramatically more readable - especially once you start chaining multiple CTEs together:

sql
WITH customer_totals AS (
SELECT customer_id, SUM(amount) AS total_spent
FROM orders
GROUP BY customer_id
),
big_spenders AS (
SELECT customer_id
FROM customer_totals
WHERE total_spent > 150
)
SELECT c.name
FROM customers c
JOIN big_spenders b ON c.id = b.customer_id;


๐Ÿ’ก Why interviewers love CTE questions: they reveal whether you can decompose a complex problem into logical, named steps - the same skill you need for clean production SQL, not just passing a test.

โš ๏ธ Performance note: CTEs aren't automatically materialized/cached in every database engine - in some (like older Postgres versions), a CTE could be re-run each time it's referenced. Worth knowing your specific database's behavior before assuming CTEs are always a free readability win.

Do you default to CTEs or subqueries in your day-to-day work? ๐Ÿ‘‡
  • ๐Ÿ‘ 1
Post #1381 346
๐Ÿ“„ RESUME ROAST #3

> "Team player with excellent communication skills, hard worker, fast learner, detail-oriented, passionate about technology."

Before I roast this - what's actually wrong with it? ๐Ÿ‘‡

.
.
.

The roast:
Every single word here is an unverifiable adjective. "Team player" and "hard worker" mean nothing to a hiring manager because literally every resume claims them, and there's zero evidence attached.

This section is functionally invisible - recruiters' eyes skip right past it, and it takes up valuable space that could hold something specific.

โœ… The fix: show, don't tell. Instead of claiming "excellent communication skills," demonstrate it:

> "Presented quarterly architecture reviews to both engineering and non-technical stakeholders, translating complex system tradeoffs into business impact."

That single sentence proves communication skills far more convincingly than the adjective ever could - and it does it without ever using the word "communication."

Go check your resume right now. Do you have any pure adjective-lists like this? Be honest ๐Ÿ˜…
  • โค 2
Older posts โ†’
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’