Practice
400 problems, in the order the course teaches them. Every one runs on a real compiler against real test cases.
Start here
1. Print Hello World
Fundamentals · Foundation
0 / 400
solved
400 problems
Fundamentals
0 of 13- —1Print Hello WorldFoundation97%
- —2Add Two NumbersFoundation—
- —3Area and Perimeter of a RectangleFoundation—
- —4Swap Two NumbersFoundation—
- —5Celsius to FahrenheitFoundation—
- —6Sum of DigitsFoundation—
- —7Even or OddFoundation—
- —8Simple InterestFoundation—
- —9Length of a StringFoundation—
- —10Largest of Three NumbersFoundation—
- —11Absolute DifferenceFoundation—
- —12Leap YearFoundation—
- —13Grade From MarksFoundation—
Conditionals
0 of 14- —14Positive, Negative or ZeroFoundation—
- —15Vowel or ConsonantFoundation—
- —16Divisible by Three and FiveFoundation—
- —17Character TypeFoundation—
- —18Is It a Triangle?Foundation—
- —19Type of TriangleCore—
- —20Which Quadrant?Core—
- —21Electricity BillCore—
- —22Ticket Price by AgeFoundation—
- —23Largest of Four NumbersFoundation—
- —24Sort Three NumbersCore—
- —25Nature of Quadratic RootsCore—
- —26Day Name From NumberFoundation—
- —27BMI CategoryCore—
Loops
0 of 19- —28Sum of First N Natural NumbersFoundation—
- —29Count Down From NFoundation—
- —30FactorialFoundation—
- —31Multiplication TableFoundation—
- —32Count the DigitsFoundation—
- —33Reverse a NumberFoundation—
- —34Palindrome NumberFoundation—
- —35Is It Prime?Core—
- —36Nth Fibonacci NumberCore—
- —37Greatest Common DivisorCore—
- —38Lowest Common MultipleCore—
- —39Power of a NumberCore—
- —40Armstrong NumberCore—
- —41Perfect NumberCore—
- —42Sum of Even and Odd NumbersFoundation—
- —43Right-Angled Triangle PatternFoundation—
- —44Number PyramidCore—
- —45Count Primes Up To NChallenge—
- —46Digital RootCore—
Arrays & Matrices
0 of 20- —47Largest Element in an ArrayFoundation—
- —48Second Largest ElementCore—
- —49Sum and AverageFoundation—
- —50Count OccurrencesFoundation—
- —51First OccurrenceFoundation—
- —52Reverse an Array In PlaceCore—
- —53Is the Array Sorted?Foundation—
- —54Remove Duplicates from a Sorted ArrayCore—
- —55Move Zeros to the EndCore—
- —56Rotate an Array Left by KCore—
- —57Maximum Subarray SumChallenge—
- —58Pair With a Given SumChallenge—
- —59The Missing NumberCore—
- —60Majority ElementChallenge—
- —61Range Sum QueriesChallenge—
- —62Transpose a MatrixCore—
- —63Multiply Two MatricesChallenge—
- —64Spiral TraversalChallenge—
- —65Row With the Largest SumCore—
- —66Saddle PointChallenge—
Strings & Pointers
0 of 22- —67Reverse a StringFoundation—
- —68Count Vowels and ConsonantsFoundation—
- —69Palindrome StringCore—
- —70Toggle the CaseFoundation—
- —71Count the WordsCore—
- —72Remove All SpacesFoundation—
- —73Character FrequencyCore—
- —74First Non-Repeating CharacterChallenge—
- —75Are They Anagrams?Core—
- —76Remove Duplicate CharactersCore—
- —77Longest WordCore—
- —78Capitalise Each WordCore—
- —79Count Substring OccurrencesCore—
- —80Compare Two StringsFoundation—
- —81Is It a Rotation?Challenge—
- —82Longest Common PrefixCore—
- —83Swap Two Values Inside a FunctionCore—
- —84Sum an Array Through a PointerCore—
- —85Reverse an Array With Two PointersCore—
- —86Change a Value Through a PointerFoundation—
- —87Convert a String to an IntegerCore—
- —88Longest Substring Without RepeatsChallenge—
Structures
0 of 16- —89A Student RecordFoundation—
- —90Distance Between Two PointsFoundation—
- —91Rectangle From Two CornersCore—
- —92Convert Time to SecondsFoundation—
- —93Highest Scoring StudentCore—
- —94Total PayrollFoundation—
- —95Inventory ValueCore—
- —96Add Two TimesCore—
- —97Days Between Two DatesChallenge—
- —98Add Complex NumbersFoundation—
- —99Add Two FractionsChallenge—
- —100Students Above AverageCore—
- —101Sort Students by MarksCore—
- —102Count by DepartmentCore—
- —103Find Duplicate RecordsChallenge—
- —104Merge Two Sorted ListsChallenge—
Time Complexity
0 of 16- —105Sum of SquaresCore—
- —106Fast PowerChallenge—
- —107Binary SearchCore—
- —108Count Distinct ElementsCore—
- —109Most Frequent ElementCore—
- —110Pairs With a Given DifferenceChallenge—
- —111Best Window of Size KCore—
- —112Subarrays That Sum to ZeroChallenge—
- —113Longest Consecutive SequenceChallenge—
- —114Kth Smallest ElementCore—
- —115Duplicate Within K PositionsCore—
- —116Sum of All Subarray SumsChallenge—
- —117Count InversionsChallenge—
- —118Closest Pair SumChallenge—
- —119Minimum in Every WindowChallenge—
- —120Triplets Summing to ZeroChallenge—
Linked List
0 of 28- —121Build and Print a Linked ListFoundation—
- —122Count the NodesFoundation—
- —123Search a Linked ListFoundation—
- —124Insert at the BeginningFoundation—
- —125Insert at the EndFoundation—
- —126Insert at a PositionCore—
- —127Delete the First NodeFoundation—
- —128Delete the Last NodeCore—
- —129Delete a ValueCore—
- —130Reverse a Linked ListCore—
- —131Find the Middle NodeCore—
- —132Nth Node From the EndCore—
- —133Detect a CycleChallenge—
- —134Where Does the Cycle Start?Challenge—
- —135Remove Duplicates From a Sorted ListCore—
- —136Merge Two Sorted ListsCore—
- —137Is the List a Palindrome?Challenge—
- —138Sum of All NodesFoundation—
- —139Largest Value in the ListFoundation—
- —140Count OccurrencesFoundation—
- —141Swap Nodes in PairsChallenge—
- —142Rotate the ListChallenge—
- —143Remove the Nth Node From the EndChallenge—
- —144Where Two Lists JoinChallenge—
- —145Add Two Numbers Stored as ListsChallenge—
- —146Split by PositionChallenge—
- —147Reverse in Groups of KChallenge—
- —148Sort a Linked ListChallenge—
Stack
0 of 26- —149Stack OperationsFoundation—
- —150Reverse a String With a StackFoundation—
- —151Balanced ParenthesesCore—
- —152Balanced BracketsCore—
- —153Redundant BracketsChallenge—
- —154Next Greater ElementChallenge—
- —155Next Smaller ElementCore—
- —156Previous Greater ElementCore—
- —157Stock SpanChallenge—
- —158Evaluate a Postfix ExpressionCore—
- —159Evaluate a Prefix ExpressionCore—
- —160Infix to PostfixChallenge—
- —161Sort a StackChallenge—
- —162Reverse a StackCore—
- —163Delete the Middle of a StackCore—
- —164Stack With a MinimumChallenge—
- —165Remove Adjacent DuplicatesCore—
- —166Decode a Nested StringChallenge—
- —167Was This Pop Order Possible?Challenge—
- —168Asteroid CollisionChallenge—
- —169Largest Rectangle in a HistogramChallenge—
- —170Trapping Rain WaterChallenge—
- —171Longest Valid ParenthesesChallenge—
- —172Remove K DigitsChallenge—
- —173Simplify a File PathCore—
- —174Two Stacks in One ArrayChallenge—
Queue
0 of 26- —175Queue OperationsFoundation—
- —176Circular QueueCore—
- —177Running Sum of the Last KFoundation—
- —178Reverse a QueueFoundation—
- —179Reverse the First K of a QueueCore—
- —180Deque OperationsCore—
- —181Palindrome With a DequeCore—
- —182Interleave the Two HalvesCore—
- —183Generate Binary NumbersCore—
- —184Queue From Two StacksCore—
- —185Stack From Two QueuesCore—
- —186First Non-Repeating in a StreamChallenge—
- —187The Josephus ProblemChallenge—
- —188Sort a QueueCore—
- —189Round-Robin SchedulingCore—
- —190The Circular TourChallenge—
- —191Distinct Values in Every WindowCore—
- —192A Queue That Knows Its MaximumChallenge—
- —193Sliding Window MaximumChallenge—
- —194Sliding Window MinimumCore—
- —195Rotting OrangesChallenge—
- —196Shortest Path in a GridChallenge—
- —197Count the IslandsCore—
- —198Fewest Steps to a NumberChallenge—
- —199An LRU CacheChallenge—
- —200Design a Circular DequeChallenge—
Recursion & Backtracking
0 of 40- —201FactorialFoundation—
- —202Sum to NFoundation—
- —203CountdownFoundation—
- —204PowerFoundation—
- —205Count the DigitsFoundation—
- —206Sum of DigitsFoundation—
- —207Reverse a NumberFoundation—
- —208Greatest Common DivisorFoundation—
- —209FibonacciCore—
- —210Sum an ArrayFoundation—
- —211Largest in an ArrayFoundation—
- —212Palindrome NumberFoundation—
- —213Count a DigitFoundation—
- —214Multiply Without MultiplyingFoundation—
- —215Towers of HanoiCore—
- —216Binary SearchCore—
- —217Reverse a StringFoundation—
- —218Palindrome StringFoundation—
- —219How Many SubsetsCore—
- —220Climbing StairsCore—
- —221Collatz StepsCore—
- —222Power With a ModulusChallenge—
- —223Paths Through a GridChallenge—
- —224The Josephus ProblemChallenge—
- —225Decimal to BinaryFoundation—
- —226Count the VowelsFoundation—
- —227How Many OrderingsCore—
- —228N QueensChallenge—
- —229Does a Subset Add UpChallenge—
- —230Balanced Bracket StringsChallenge—
- —231Ways to Make an AmountChallenge—
- —232Paths Through a MazeChallenge—
- —233A Row of Pascal’s TriangleCore—
- —234Tiling With DominoesCore—
- —235Strings With No Two Ones TogetherCore—
- —236What Fits in the BagChallenge—
- —237Longest Common SubsequenceChallenge—
- —238A Function That Grows Too FastChallenge—
- —239Sum a Nested ListCore—
- —240Print the Digits ForwardsCore—
Searching & Sorting
0 of 40- —241First Position At Least XCore—
- —242How Many Times Does X AppearCore—
- —243The Kth Smallest ValueFoundation—
- —244Pairs That Add UpCore—
- —245Merge Two Sorted ListsFoundation—
- —246Sort ThemFoundation—
- —247Count the InversionsChallenge—
- —248Integer Square RootCore—
- —249Second LargestFoundation—
- —250Remove DuplicatesFoundation—
- —251Smallest Capacity That WorksChallenge—
- —252Find a PeakChallenge—
- —253Search a Rotated ArrayChallenge—
- —254Sort Zeros, Ones and TwosCore—
- —255Merge Overlapping IntervalsChallenge—
- —256Closest Two ValuesCore—
- —257Largest GapFoundation—
- —258The Majority ElementChallenge—
- —259Spread Them OutChallenge—
- —260Allocate the BooksChallenge—
- —261Where Would It GoFoundation—
- —262Floor and CeilingCore—
- —263Union of Two Sorted ListsCore—
- —264Intersection of Two Sorted ListsCore—
- —265Fairest SelectionCore—
- —266The H IndexChallenge—
- —267Fewest Swaps to SortChallenge—
- —268Sort by Distance from ZeroCore—
- —269Pairs a Fixed Distance ApartCore—
- —270One Swap AwayCore—
- —271Is One a Subset of the OtherCore—
- —272The Kth Largest ValueFoundation—
- —273The MedianFoundation—
- —274Smallest Missing PositiveCore—
- —275How Many Fall in the RangeCore—
- —276Largest Product of TwoCore—
- —277How Many PlatformsChallenge—
- —278Fit the Most MeetingsChallenge—
- —279Partition Around a ValueCore—
- —280Sort Words by LengthCore—
Hashing & Hash Tables
0 of 40- —281How Many Different ValuesFoundation—
- —282First Character That Appears OnceCore—
- —283Two That Add UpCore—
- —284How Often Does the Commonest AppearFoundation—
- —285Are They AnagramsFoundation—
- —286How Many Subarrays Add Up to KChallenge—
- —287Longest Run of Consecutive ValuesChallenge—
- —288First Value That RepeatsFoundation—
- —289A Repeat Close ByCore—
- —290One Missing, One RepeatedCore—
- —291The Most Common WordCore—
- —292Same Shape, Different LettersChallenge—
- —293Can You Build ItFoundation—
- —294How Many Anagram GroupsCore—
- —295The K Most Frequent ValuesCore—
- —296Distinct Values in Each WindowChallenge—
- —297Add Up What Appears OnceFoundation—
- —298Longest Stretch With No RepeatChallenge—
- —299Equal Zeros and OnesChallenge—
- —300Count Pairs With a Given SumCore—
- —301Is There a Zero-Sum StretchCore—
- —302How Many Zero-Sum StretchesChallenge—
- —303At Most K Different CharactersChallenge—
- —304Order by How OftenCore—
- —305Common to All ThreeCore—
- —306Most Frequent, Smallest WinsFoundation—
- —307Longest Stretch Adding to KChallenge—
- —308Smallest Window Holding EverythingChallenge—
- —309How Many Stretches Have At Most K ValuesChallenge—
- —310Same Values, Different OrderFoundation—
- —311First Value Seen TwiceFoundation—
- —312Equal Counts of Two ValuesChallenge—
- —313How Many Equal PairsFoundation—
- —314Appearing More Than a Third of the TimeCore—
- —315Longest Stretch Divisible by KChallenge—
- —316Smallest Window Covering a PatternChallenge—
- —317How Many Stretches Sum to KChallenge—
- —318Appearing Exactly TwiceFoundation—
- —319Distinct Pieces of Length KCore—
- —320Smallest Missing PositiveCore—
Trees & Binary Search Trees
0 of 40- —321Height of a TreeFoundation—
- —322Count the NodesFoundation—
- —323Sum of All ValuesFoundation—
- —324Largest Value in the TreeFoundation—
- —325Count the LeavesFoundation—
- —326Preorder TraversalFoundation—
- —327Inorder TraversalCore—
- —328Postorder TraversalCore—
- —329Level Order TraversalCore—
- —330Is It a Search TreeChallenge—
- —331Search a Binary Search TreeFoundation—
- —332Smallest Value in a Search TreeFoundation—
- —333Diameter of a TreeChallenge—
- —334Is the Tree BalancedChallenge—
- —335Sum of Each RowCore—
- —336Left View of a TreeCore—
- —337Right View of a TreeCore—
- —338Sum of the LeavesFoundation—
- —339Best Path from Root to LeafCore—
- —340How Many Nodes at Depth KFoundation—
- —341Mirror the TreeCore—
- —342Is the Tree SymmetricChallenge—
- —343Kth Smallest in a Search TreeCore—
- —344Values Inside a RangeFoundation—
- —345Is There a Path Adding to TCore—
- —346Lowest Common AncestorChallenge—
- —347Nodes With Two ChildrenFoundation—
- —348Nodes With Exactly One ChildFoundation—
- —349Zigzag Level OrderChallenge—
- —350Value at the Deepest LeafCore—
- —351Are Two Trees IdenticalCore—
- —352How Deep Is a ValueFoundation—
- —353Sum at One DepthFoundation—
- —354Distance Between Two NodesChallenge—
- —355Nodes Exactly K AwayChallenge—
- —356Best Path AnywhereChallenge—
- —357Largest Value Below XCore—
- —358Is the Tree CompleteChallenge—
- —359Size of a SubtreeFoundation—
- —360Insert Into a Search TreeCore—
Graphs, BFS & DFS
0 of 40- —361Breadth First OrderFoundation—
- —362Depth First OrderFoundation—
- —363How Many Connected PiecesCore—
- —364Fewest Edges Between Two VerticesCore—
- —365Does the Graph Have a CycleCore—
- —366Can It Be Two-ColouredChallenge—
- —367Size of the Largest ComponentCore—
- —368The Busiest VertexFoundation—
- —369Vertices With No EdgesFoundation—
- —370Is This Graph a TreeCore—
- —371Exactly K Steps AwayCore—
- —372Counting IslandsChallenge—
- —373Flood FillCore—
- —374Area of the Largest IslandCore—
- —375Shortest Way Through the MazeChallenge—
- —376Perimeter of the LandFoundation—
- —377How Long Until Everything RotsChallenge—
- —378Where Can You StartFoundation—
- —379A Cycle You Cannot EscapeChallenge—
- —380An Order That Respects Every ArrowChallenge—
- —381How Much Can You ReachCore—
- —382Counting TrianglesChallenge—
- —383Is Everyone Joined to EveryoneFoundation—
- —384Is It a StarCore—
- —385Edges Inside One ComponentCore—
- —386Friend CirclesCore—
- —387The Edge That Closed the LoopChallenge—
- —388Cheapest Route to the EndChallenge—
- —389Cheapest Way to Join EverythingChallenge—
- —390Knight to the Far CornerCore—
- —391The Longest Walk in a TreeChallenge—
- —392How Far Is the FurthestCore—
- —393Components of Exactly This SizeCore—
- —394Counting Paths of Two EdgesCore—
- —395A Vertex That Reaches EveryoneCore—
- —396Edges Needed to Join It All UpFoundation—
- —397How Many at Each DistanceCore—
- —398How Many Pairs Can Reach Each OtherChallenge—
- —399The Longest Chain of ArrowsChallenge—
- —400Everyone Can Reach EveryoneChallenge—