Greedy Algorithms

Advanced & DP

Making locally optimal choices that guarantee global optimal outcomes

432 problems·42 Easy·295 Medium·95 Hard
Pattern Study Guide & Cheat Sheet
▼

Make the locally optimal choice at each decision step with the mathematical guarantee that it leads to the globally optimal solution without backtracking.

Core Invariant: Greedy Choice Property: Can you prove by exchange argument that swapping a greedy decision with any alternative never produces a superior outcome? If yes, greedy holds.

Recognize it (Keywords & Signals)
  • Maximize profit / minimize cost with independent sequential choices
  • Jump game (maximum reachable index)
  • Gas station circuit / circular route
  • Task scheduler / candy distribution
  • Minimum arrows to burst balloons
When NOT to use

Local decisions constrain future options in conflicting ways (e.g. 0/1 Knapsack, Coin Change with arbitrary denominations; must use DP!).

How to solve (Step-by-step)
  1. 1.Identify the greedy metric (e.g. earliest finish time, farthest reach, max profit step).
  2. 2.Sort inputs if necessary to enforce the greedy ordering.
  3. 3.Maintain a single state variable (e.g., `farthest_reach = 0`, `current_gas = 0`).
  4. 4.Iterate through elements and update state irreversibly.
  5. 5.Return final accumulated score or boolean feasibility.
Watch for (Interview Traps)
  • Assuming greedy works without proof (e.g. Coin Change fails for denominations [1, 3, 4] with target 6)
  • Premature optimization: always verify if dynamic programming is required before committing to greedy
  • Failing to check if starting point is unreachable in Jump Game
Farthest Reach Greedy (Jump Game)
def can_jump(nums: list[int]) -> bool:
    farthest = 0
    
    for i, jump in enumerate(nums):
        # If current index is beyond the farthest reach, we cannot proceed
        if i > farthest:
            return False
        # Update maximum index we can reach
        farthest = max(farthest, i + jump)
        if farthest >= len(nums) - 1:
            return True
            
    return True
Cost
O(n) single pass or O(n log n) with sorting · O(1) auxiliary space (Extremely memory efficient when greedy choice property holds.)
Canonical problems
#55 Jump Game: Greedily extend farthest reachable milestone
#45 Jump Game II: Count jumps whenever current step boundary is reached
#134 Gas Station: If total gas >= total cost, start right after the worst deficit point
#621 Task Scheduler: Most frequent task forms idle slot framework
Medium·64 companies·Max freq 100%·Acc 60.4%
PornhubTableauPubMatic+61
Medium·51 companies·Max freq 100%·Acc 52.7%
SnapSnapSplunk+48
Medium·39 companies·Max freq 100%·Acc 41.2%
TecholutionTomTomNike+36
Medium·33 companies·Max freq 100%·Acc 48.3%
CME GroupScale AIBitGo+30
Medium·33 companies·Max freq 100%·Acc 0.4%
ZulilyPhonePeTomTom+30
Medium·30 companies·Max freq 100%·Acc 71.3%
CTC Global Sdn BhdCareemToast+27
Medium·28 companies·Max freq 100%·Acc 63.4%
BCGmicro1Roblox+25
Hard·24 companies·Max freq 100%·Acc 60.9%
BaiduYugabyteZeta Global+21
#135Candy
Hard·24 companies·Max freq 100%·Acc 48.8%
UnifyAppsBending SpoonsUrban Company+21
Medium·23 companies·Max freq 100%·Acc 43.3%
NykaaWorks ApplicationsJosh Technology+20
Medium·23 companies·Max freq 100%·Acc 0.4%
park+SnapCoupang+20
Medium·23 companies·Max freq 90%·Acc 57.4%
GrammarlyVerkadaZoho+20
Medium·21 companies·Max freq 100%·Acc 40.3%
PornhubAlibabaMotive+18
Medium·20 companies·Max freq 100%·Acc 57.3%
RobloxTeslaAmazon+17
Hard·20 companies·Max freq 100%·Acc 0.3%
XCyntexaX+17
Easy·17 companies·Max freq 100%·Acc 29.2%
HTCSOTILinkedIn+14
Medium·17 companies·Max freq 100%·Acc 0.4%
GopuffVisaSnowflake+14
Easy·16 companies·Max freq 100%·Acc 44.5%
WhatnotMetaFortinet+13
Medium·16 companies·Max freq 100%·Acc 51.0%
ZIPoyoSchrodinger+13
Medium·15 companies·Max freq 87%·Acc 0.6%
SigmoidUiPathIBM+12
Hard·14 companies·Max freq 100%·Acc 51.0%
Akuna CapitalTower Research CapitalDE Shaw+11
Medium·14 companies·Max freq 100%·Acc 0.5%
IncreffFactSetByteDance+11
Medium·13 companies·Max freq 100%·Acc 62.2%
Tower Research CapitalTower Research CapitalNagarro+10
Medium·13 companies·Max freq 69%·Acc 78.0%
MicrostrategyServiceNowVisa+10
Medium·12 companies·Max freq 100%·Acc 45.0%
Pony.aiPony.aiUrban Company+9
Medium·11 companies·Max freq 100%·Acc 77.6%
BrazeRobloxCapital One+8
Hard·11 companies·Max freq 100%·Acc 70.2%
WinZOPhonePeLyft+8
Medium·11 companies·Max freq 67%·Acc 82.0%
InMobiBarclaysNeetCode 150+8
Medium·10 companies·Max freq 100%·Acc 0.5%
NielsenMetaTikTok+7
Medium·10 companies·Max freq 100%·Acc 0.6%
LivspaceExpediaBarclays+7
Easy·10 companies·Max freq 63%·Acc 75.0%
IBMJPMorgan ChaseArista Networks+7
Hard·10 companies·Max freq 50%·Acc 0.7%
DE ShawSalesforceAmazon+7
Medium·9 companies·Max freq 100%·Acc 51.8%
Publicis SapientPony.aiPony.ai+6
Medium·9 companies·Max freq 100%·Acc 38.4%
LiveRampeBayTikTok+6
Medium·9 companies·Max freq 100%·Acc 57.0%
ExpediaAT&TBloomberg+6
Medium·9 companies·Max freq 100%·Acc 63.7%
FactSetByteDancePaytm+6
Easy·9 companies·Max freq 76%·Acc 59.3%
InfosysZalandoZoho+6
Hard·9 companies·Max freq 68%·Acc 78.2%
Dream11GoogleIBM+6
Easy·9 companies·Max freq 63%·Acc 55.3%
AccentureAmazonZoho+6
Medium·9 companies·Max freq 55%·Acc 72.3%
AppleCitadelInfosys+6
Hard·9 companies·Max freq 41%·Acc 57.3%
AtlassianOracleTikTok+6
Medium·8 companies·Max freq 100%·Acc 58.0%
WishCARS24DP world+5
Medium·8 companies·Max freq 100%·Acc 47.2%
MathWorksSquarepoint CapitalExpedia+5
Medium·8 companies·Max freq 100%·Acc 62.8%
Salesforce6senseNvidia+5
Medium·8 companies·Max freq 100%·Acc 65.5%
WayfairTikTokGeico+5
Hard·8 companies·Max freq 100%·Acc 47.8%
CitrixPhonePeFlipkart+5
Easy·8 companies·Max freq 100%·Acc 84.6%
HSBCHudson River TradingHudson River Trading+5
Medium·8 companies·Max freq 97%·Acc 44.7%
GeicoLinkedInMicrosoft+5
Hard·8 companies·Max freq 88%·Acc 44.9%
SoFiPhonePeLinkedIn+5
Medium·8 companies·Max freq 81%·Acc 45.2%
MolocoServiceNowExpedia+5
50 displayed (of 50 matching)Filtered: All Companies

Top Companies Testing Greedy Algorithms

Browse company-specific interview problem lists and recency breakdowns:

Explore All 22 DSA Coding Patterns

Master core algorithmic patterns tested in FAANG & Big Tech coding interviews.

Patterns Hub

Greedy Algorithms frequently asked questions

What is the Greedy Algorithms pattern in coding interviews?

Making locally optimal choices that guarantee global optimal outcomes It is categorized under Advanced & DP and features 432 curated interview problems across Easy (42), Medium (295), and Hard (95) difficulties.

Which tech companies frequently test Greedy Algorithms?

Companies frequently asking Greedy Algorithms questions include Amazon, Google, Microsoft, Bloomberg, Meta, Infosys.

How do I master the Greedy Algorithms pattern?

Start by studying the algorithmic strategy and template code, then practice Easy and Medium problems before attempting Hard problems under timed conditions.