Page Inspect
Internal Links
126
External Links
8
Images
7
Headings
19
Page Content
Title:Programming Interview Questions + Help Getting Job Offers | Interview Cake
Description:Free practice programming interview questions. Interview Cake helps you prep for interviews to land offers at companies like Google and Facebook.
HTML Size:307 KB
Markdown Size:24 KB
Fetched At:November 17, 2025
Page Structure
h2Get a free weekly practice problem!
h1Learn to ace
your programming interview.
h2NEW: Free 7-Day Email Course
h2Prepare with Interview Cake.Land your dream programming job.
h345+ rigorous practice questions with well-explained solutions
h3Integrated sandbox to code and test your answers
h3View and write code in 10 different programming languages
h3Detailed reference library explaining core coding concepts
h3Written by a smart human, for smart humans
h3Backed by my satisfaction guarantee
h2Whiteboard freeze
h2"Whaaat?? I never would've thought of that!"
h2We teach you how to come up with the answer.
h2Try a question now for free
h2Sample Programming Interview Question
h3Ready for more?
h5Programming interview questions by company:
h5Programming interview questions by topic:
h3Log in/sign up
Markdown Content
Programming Interview Questions + Help Getting Job Offers | Interview Cake
## Get a *free* weekly practice problem!
Keep that axe sharp.
No spam, ever. Easy unsubscribe.
*Cool, watch your inbox!*
× No thanks
Interview Cake by Exponent
Toggle navigation Interview Cake by Exponent
- Coding Questions
- All Questions
- Language-Specific Prep
- Python Interview Questions
- Java Interview Questions
- Javascript Interview Questions
- Company-Specific Prep
- Google Interview Questions
- Meta Interview Questions
- Amazon Interview Questions
- Tips
- First coding interview? Start here.
- General coding interview tips
- How to get un-stuck
- Beating impostor syndrome
- 24 hours before your onsite
- Why you're hitting dead ends
- Best ways to practice
- Organizing your interview timeline
- Mastering behavioral questions
- Common issues
- Glossary
- Big O Notation: , , etc
- Big O Notation Basics
- Big O Cheat Sheet
- Logarithms
- P vs. NP
- Search Algorithms
- Binary Search
- Breadth-First Search
- Depth-First Search
- Sorting Algorithms
- Big O Sorting Cheatsheet
- Counting Sort
- Insertion Sort
- Selection Sort
- Merge Sort
- Quicksort
- Heapsort
- Radix Sort
- Topological Sort
- Stable Sort
- Algorithm Heuristics
- Brute Force Algorithms
- Greedy Algorithms
- Bottom-Up Algorithms
- Overlapping Subproblems
- Memoization
- Just-In-Time vs. Ahead-Of-Time
- Base Case for Recursive Functions
- Data Structures
- Data Structures Index
- Data Structures for Coding Interviews
- Tuple
- Array
- Dynamic Array
- Hash Table
- Linked List
- Queue
- Priority Queue
- Stack
- Heap
- Trees
- Overview of Trees
- Balanced Tree
- Binary Tree
- Binary Search Tree
- Ternary Search Tree
- BST In-Order Traversal
- Complete Binary Tree
- Trie
- Graph
- Adjacency List
- Bloom Filter
- LRU Cache
- Language-Specific Features
- Short Circuit Evaluation
- Garbage Collection
- Closure
- Array Slicing
- Hashing
- Mutable vs Immutable
- Call Stack
- Process Heap
- In-Place Operation
- C Data Structure Interview Questions
- Binary & Bitwise Functions
- Binary Numbers
- Booleans
- Bits and Number of Possibilities
- Get Bit Value
- Bitwise AND
- Bitwise OR
- Bitwise XOR
- Bitwise NOT
- Bit Shifting
- Bit Manipulation
- Integer Overflow
- Other Concepts
- Combinatorics Interview Questions
- System Design Interview Questions
- Triangular Series
- The Modulus Operation
- Consistent Hashing
- Dijkstras Algorithm
- Testing and QA Interview Questions
- SQL Interview Questions
- Coaching
- Full Course
- Get the full course
- -
- Log out
- Log in to save progress
# Learn to ace your programming interview.
The programming interview is a **winnable game**. I'll show you the tricks
to quickly solve problems you've never seen before.
## NEW: Free 7-Day Email Course
I'll teach you the right *way of thinking* for breaking down tricky algorithmic coding interview questions you've never seen before.
No prior computer science training necessary—I'll get you up to speed quickly, skipping all the overly academic stuff.
No spam. Easy unsubscribe if you hate it.
You're in! Head over to your email inbox right now to read day one!
Try a question now
## Prepare with Interview Cake.
Land your dream programming job.
My coding interview prep course has a **98% success rate**. Here's why:
### 45+ rigorous practice questions with well-explained solutions
As an experienced tech interviewer and instructor at coding bootcamps, I know exactly what types of questions top-tier tech companies will throw at you during the interview process. Armed with that knowledge, I've crafted over 45 thoughtful coding interview questions designed to test and improve your skills.
### Integrated sandbox to code and test your answers
Interview Cake includes a built-in code editor, so you can write and test code as you go — just like you would in a real programming interview. Practice blackboarding code on-the-fly in an environment that will parallel your real-world experience.
### View and write code in 10 different programming languages
It doesn't matter whether you're interviewing using Python, Java, Ruby, or C. Select your preferred language on any Interview Cake page and we'll automatically translate all of the content in our site to your language of choice — including our reference materials. Or, mix it up to get experience across a variety of languages.
### Detailed reference library explaining core coding concepts
Big O notation. Breadth- and depth-first search. Greedy algorithms. Garbage collection. Arrays, hash tables, and bitwise functions. These are just a few of the concepts explained clearly and succinctly in my detailed reference library. Stop scrolling through endless pages of machine-written, SEO-optimized garbage and get right to the point with reference materials designed for humans.
### Written by a smart human, for smart humans
My materials are written with minimal fluff and the assumption that you are capable and your time is valuable. I get straight to the point and ramp you up at warp speed so that you can achieve deep mastery, quickly.
### Backed by my satisfaction guarantee
If you purchase access to Interview Cake and, within 30 days of your purchase, decide that it's not for you, just let me know. I'll issue you a 100% refund, no questions asked. I've run this website for a long time, and this policy has worked out well: 98% of users are satisfied.
-
-
-
-
-
-
-
-
-
-
**Rich** got the job at **Apple**:
**Thanks to your site, I have offers from Apple, Facebook and Google. That's a hell of an ROI!** I didn't go to school for computer science, and now I have multiple senior engineering offers from the world's best tech companies.
**Patrick** got the job at **Dropbox**:
**Honestly, this feels like cheating.** Very efficient way to spend your study time and definitely pays for itself!
**Cyrus** got the job at **Facebook**:
Your site was an invaluable resource and **really helped me develop the iterative algorithmic problem solving skills big tech companies & startups are looking for.** Great case of quality over quantity.
**Chris** got the job at **Palantir**:
I used a number of resources to help prep for the coding interviews but **Interview Cake stood out as by far and away the most useful.** I owe you a massive debt of thanks
**Eric** got the job at **Amazon**:
**Your site was really indispensable for the Google/Amazon interview process.** I've recommended your site to everyone I know that wants to become both a better programmer and a better interviewer. Great work.
**Zak** got the job at **Mixpanel**:
**I got offers from 7/8 of the companies at which I interviewed.** After not going through a formal interview process in nearly a decade, your site really helped build my confidence. You're a hero, Parker ;)
**Michael** got the job at **Google**:
Your website was so helpful that **I didn't just receive an offer from Google, I also received a competing offer from Amazon.**
**Luna** got the job at **Apple**:
I wish I had known about this website back when I was in algorithms class in college. **This made me finally understand a number of concepts that had eluded me for years.**
**Richie** got the job at **Microsoft**:
Right now I have an offer from Microsoft and I'm still in the interview process with Google and LinkedIn. **Life is pretty good, and I owe so much of that to Interview Cake.**
**Akshay** got the job at **Amazon**:
Having tried several resources for interview prep, I can honestly say that **Interview Cake provides the most structured and confidence-inducing approach.**
These are some of the companies that have offered our users jobs:
## Whiteboard freeze
We've all been there.
You're standing in front of the whiteboard, working on one of those tricky interview questions.
You're off to a reasonable start. Jotting down some notes on the board while thinking out loud.
Then, the whiteboard marker crawls to a halt. It hangs there, hovering above the board. Frozen.
*You're drawing a complete blank. Nothing.*
You make eye contact with your interviewer (or mock interviewer), who's watching you expectantly.
Is it hot in here all of a sudden?
## "Whaaat?? I *never* would've thought of that!"
The way to fix whiteboard freeze is to run practice problems...right?
The problem is, the way most people practice simply doesn't work.
Is this you?:
You pull up a practice problem, work on it, get as far as you can...
Until you get stuck. You give up and look at the answer.
*"Whaaat?? How do you even *come up* with something like that?"*
You understand *what the answer is*, but you have no idea *how you could have gotten there yourself*.
And *that's* the problem with this method of studying.
Learning *what the answer is* doesn't help you. You need to learn *how to come up with* the answer.
That's worth repeating:
**Learning *what the answer is* doesn't help you. You need to learn *how to come up with* the answer.**
## We teach you *how to come up with* the answer.
You'll learn the right *way of thinking* to quickly break down problems you've never seen before.
No more whiteboard freeze.
Here's how it works:
On Interview Cake, when you get stuck, you don't have to give up and look at the answer.
Instead, **we'll give you the *next logical step you should be making* to break down the question.**
We call this a "breakdown step." It's how we teach you *the right way to think about the problem*.
It's kinda like we're sitting there with you, guiding you along as you go.
Explaining what to do next. Step by step.
You'll see what we mean when you try it out:
⤵
## Try a question now for free
Enter your email below to get a link to a free trial question.
You'll see what we mean about learning *how to get the answer*, not just what the answer is.
*No spam, ever. Unsubscribe whenever.*
**You're in! Loading your free trial question...**
## Sample Programming Interview Question
**Writing programming interview questions hasn't made me rich yet ... so I might give up and start trading Apple stocks all day instead.**
First, I wanna know how much money I *could have* made yesterday if I'd been trading Apple stocks all day.
So I grabbed Apple's stock prices from yesterday and put them in a list called stock\_prices, where:
- The **indices** are the time (in minutes) past trade opening time, which was 9:30am local time.
- The **values** are the price (in US dollars) of one share of Apple stock at that time.
So if the stock cost $500 at 10:30am, that means stock\_prices\[60\] = 500.
Write an efficient function that takes stock\_prices and returns **the best profit I could have made from one purchase and one sale of one share of Apple stock yesterday.**
For example:
stock\_prices = \[10, 7, 5, 8, 11, 9\] get\_max\_profit(stock\_prices) # Returns 6 (buying for $5 and selling for $11)
No "shorting"—you need to buy before you can sell. Also, you can't buy *and* sell in the same time step—at least 1 minute has to pass.
**You can't just take the difference between the highest price and the lowest price**, because the highest price might come *before* the lowest price. And you have to buy before you can sell.
What if the price *goes down all day*? In that case, the best profit will be **negative**.
You can do this in time and space!
To start, try writing an example value for stock\_prices and finding the maximum profit "by hand." What's your process for figuring out the maximum profit?
The brute force approach would be to try *every pair of times* (treating the earlier time as the buy time and the later time as the sell time) and see which one is higher.
def get\_max\_profit(stock\_prices): max\_profit = 0 # Go through every time for outer\_time in xrange(len(stock\_prices)): # For every time, go through every other time for inner\_time in xrange(len(stock\_prices)): # For each pair, find the earlier and later times earlier\_time = min(outer\_time, inner\_time) later\_time = max(outer\_time, inner\_time) # And use those to find the earlier and later prices earlier\_price = stock\_prices\[earlier\_time\] later\_price = stock\_prices\[later\_time\] # See what our profit would be if we bought at the # earlier price and sold at the later price potential\_profit = later\_price - earlier\_price # Update max\_profit if we can do better max\_profit = max(max\_profit, potential\_profit) return max\_profit
But that will take time, since we have two nested loops—for *every* time, we're going through *every other* time. Also, **it's not correct**: we won't ever report a negative profit! Can we do better?
Well, we’re doing a lot of extra work. We’re looking at every pair *twice*. We know we have to buy before we sell, so in our *inner for loop* we could just look at every price **after** the price in our *outer for loop*.
That could look like this:
def get\_max\_profit(stock\_prices): max\_profit = 0 # Go through every price (with its index as the time) for earlier\_time, earlier\_price in enumerate(stock\_prices): # And go through all the LATER prices for later\_time in xrange(earlier\_time + 1, len(stock\_prices)): later\_price = stock\_prices\[later\_time\] # See what our profit would be if we bought at the # earlier price and sold at the later price potential\_profit = later\_price - earlier\_price # Update max\_profit if we can do better max\_profit = max(max\_profit, potential\_profit) return max\_profit
**What’s our runtime now?**
Well, our outer for loop goes through *all* the times and prices, but our inner for loop goes through *one fewer price each time*. So our total number of steps is the sum n + (n - 1) + (n - 2) ... + 2 + 1, which is *still* time.
We can do better!
If we're going to do better than , we're probably going to do it in either or . comes up in sorting and searching algorithms where we're recursively cutting the list in half. It's not obvious that we can save time by cutting the list in half here. Let's first see how well we can do by looping through the list only *once*.
Since we're trying to loop through the list once, let's use a greedy approach, where we keep a running max\_profit until we reach the end. We'll start our max\_profit at $0. As we're iterating, how do we know if we've found a new max\_profit?
At each iteration, our max\_profit is either:
- the same as the max\_profit at the last time step, or
- the max profit we can get by selling at the current\_price
How do we know when we have case (2)?
The max profit we can get by selling at the current\_price is simply the difference between the current\_price and the min\_price from earlier in the day. If this difference is greater than the current max\_profit, we have a new max\_profit.
So for every price, we’ll need to:
- keep track of the **lowest price we’ve seen so far**
- see if we can get a **better profit**
Here’s one possible solution:
def get\_max\_profit(stock\_prices): min\_price = stock\_prices\[0\] max\_profit = 0 for current\_price in stock\_prices: # Ensure min\_price is the lowest price we've seen so far min\_price = min(min\_price, current\_price) # See what our profit would be if we bought at the # min price and sold at the current price potential\_profit = current\_price - min\_price # Update max\_profit if we can do better max\_profit = max(max\_profit, potential\_profit) return max\_profit
We’re finding the max profit with one pass and constant space!
**Are we done?** Let’s think about some edge cases. What if the price *stays the same*? What if the price *goes down all day*?
If the price doesn't change, the max possible profit is 0. Our function will correctly return that. So we're good.
But if the value *goes down all day*, we’re in trouble. Our function would return 0, but there’s no way we could break even if the price always goes down.
**How can we handle this?**
Well, what are our options? Leaving our function as it is and just returning zero is *not* a reasonable option—we wouldn't know if our best profit was negative or *actually* zero, so we'd be losing information. Two reasonable options could be:
- **return a negative profit**. “What’s the least badly we could have done?”
- **raise an exception**. “We should not have purchased stocks yesterday!”
In this case, it’s probably best to go with option (1). The advantages of returning a negative profit are:
- We **more accurately answer the challenge**. If profit is "revenue minus expenses", we’re returning the *best* we could have done.
- It's **less opinionated**. We'll leave decisions up to our function’s users. It would be easy to wrap our function in a helper function to decide if it’s worth making a purchase.
- We allow ourselves to **collect better data**. It *matters* if we would have lost money, and it *matters* how much we would have lost. If we’re trying to get rich, we’ll probably care about those numbers.
**How can we adjust our function to return a negative profit if we can only lose money?** Initializing max\_profit to 0 won’t work...
Well, we started our min\_price at the first price, so let’s start our max\_profit at the *first profit we could get*—if we buy at the first time and sell at the second time.
min\_price = stock\_prices\[0\] max\_profit = stock\_prices\[1\] - stock\_prices\[0\]
But we have the potential for an index out of bounds error here, if stock\_prices has fewer than 2 prices.
We *do* want to raise an exception in that case, since *profit* requires buying *and* selling, which we can't do with less than 2 prices. So, let's explicitly check for this case and handle it:
if len(stock\_prices) < 2: raise ValueError('Getting a profit requires at least 2 prices') min\_price = stock\_prices\[0\] max\_profit = stock\_prices\[1\] - stock\_prices\[0\]
Ok, does that work?
No! **max\_profit is still always 0.** What’s happening?
If the price always goes down, min\_price is always set to the current\_price. So current\_price - min\_price comes out to 0, which of course will always be greater than a negative profit.
When we’re calculating the max\_profit, we need to make sure we never have a case where we try **both buying and selling stocks at the current\_price**.
To make sure we’re always buying at an *earlier* price, never the current\_price, let’s switch the order around so we calculate max\_profit *before* we update min\_price.
We'll also need to pay special attention to time 0. Make sure we don't try to buy *and* sell at time 0.
We’ll greedily walk through the list to track the max profit and lowest price so far.
For every price, we check if:
- we can get a better profit by buying at min\_price and selling at the current\_price
- we have a new min\_price
To start, we initialize:
- min\_price as the first price of the day
- max\_profit as the first profit we could get
We decided to return a *negative* profit if the price decreases all day and we can't make any money. We could have raised an exception instead, but returning the negative profit is cleaner, makes our function less opinionated, and ensures we don't lose information.
def get\_max\_profit(stock\_prices): if len(stock\_prices) < 2: raise ValueError('Getting a profit requires at least 2 prices') # We'll greedily update min\_price and max\_profit, so we initialize # them to the first price and the first possible profit min\_price = stock\_prices\[0\] max\_profit = stock\_prices\[1\] - stock\_prices\[0\] # Start at the second (index 1) time # We can't sell at the first time, since we must buy first, # and we can't buy and sell at the same time! # If we started at index 0, we'd try to buy \*and\* sell at time 0. # This would give a profit of 0, which is a problem if our # max\_profit is supposed to be \*negative\*--we'd return 0. for current\_time in xrange(1, len(stock\_prices)): current\_price = stock\_prices\[current\_time\] # See what our profit would be if we bought at the # min price and sold at the current price potential\_profit = current\_price - min\_price # Update max\_profit if we can do better max\_profit = max(max\_profit, potential\_profit) # Update min\_price so it's always # the lowest price we've seen so far min\_price = min(min\_price, current\_price) return max\_profit
time and space. We only loop through the list once.
This one's a good example of the greedy approach in action. Greedy approaches are great because they're *fast* (usually just one pass through the input). But they don't work for every problem.
How do you know if a problem will lend itself to a greedy approach? Best bet is to try it out and see if it works. Trying out a greedy approach should be one of the first ways you try to break down a new question.
To try it on a new problem, start by asking yourself:
"Suppose we *could* come up with the answer in one pass through the input, by simply updating the 'best answer so far' as we went. What ***additional values*** would we need to keep updated as we looked at each item in our input, in order to be able to update the **'best answer so far'** in constant time?"
In *this* case:
The "**best answer so far**" is, of course, the max profit that we can get based on the prices we've seen so far.
The "**additional value**" is the minimum price we've seen so far. If we keep that updated, we can use it to calculate the new max profit so far in constant time. The max profit is the larger of:
- The previous max profit
- The max profit we can get by selling now (the current price minus the minimum price seen so far)
Try applying this greedy methodology to future questions.
Share Tweet Share
Share Tweet Share
### Ready for more?
Check out our full course
We have plenty more practice programming interview questions. Some are easy, some are hard. If you're ready to **get really freaking good at programming interviews**, get started now
Want more coding interview help?
Check out interviewcake.com for more advice, guides, and practice questions.
Subscribe to our weekly question email list »
##### Programming interview questions by company:
- Google interview questions
- Meta interview questions
- Amazon interview questions
- Uber interview questions
- Microsoft interview questions
- Apple interview questions
- Netflix interview questions
- Dropbox interview questions
- eBay interview questions
- LinkedIn interview questions
- Oracle interview questions
- PayPal interview questions
- Yahoo interview questions
##### Programming interview questions by topic:
- SQL interview questions
- Testing and QA interview questions
- Bit manipulation interview questions
- Java interview questions
- Python interview questions
- Ruby interview questions
- JavaScript interview questions
- C++ interview questions
- C interview questions
- Swift interview questions
- Objective-C interview questions
- PHP interview questions
- C# interview questions
Copyright © 2025 Exponent Labs LLC All rights reserved.
21750 Hardy Oak Blvd Ste 104 PMB 82632, San Antonio, TX US 78258 (862) 294-2956
Privacy | Terms
Code editor
Reset editor
vim/emacs? regular vim emacs
Run
Report an issue
{"id":40049200,"username":"2025-11-17\_22:29:02\_6)\_s)%","email":null,"date\_joined":"2025-11-17T22:29:02.705544+00:00","first\_name":"","last\_name":"","full\_name":"","short\_name":"friend","is\_anonymous":true,"is\_on\_last\_question":false,"percent\_done":0,"num\_questions\_done":0,"num\_questions\_remaining":46,"is\_full\_access":false,"is\_student":false,"first\_payment\_date":null,"last\_payment\_date":null,"num\_free\_questions\_left":3,"terms\_has\_agreed\_to\_latest":false,"preferred\_content\_language":"","preferred\_editor\_language":"","is\_staff":false,"auth\_providers\_human\_readable\_list":"","num\_auth\_providers":0,"auth\_email":""}
×
### Log in/sign up
With just a couple clicks.
| Google Auth | GitHub Auth
We'll never post on your wall or message your friends.
Where do I enter my password?
Actually, **we don't support password-based login.** Never have. Just the OAuth methods above. Why?
- It's easy and quick. No "reset password" flow. No password to forget.
- It lets us avoid storing passwords that hackers could access and use to try to log into our users' email or bank accounts.
- It makes it harder for one person to share a paid Interview Cake account with multiple people.
“Interview Cake helped me so much when I needed to accelerate my learning for interviews. If you need something to use as a study guide, check it out :D — John Paul
. . .