Loading...
Main Page → Exercises → C++
Click a category below to view its available exercises.
C++ (725)
- Programming practice in C++, mostly at a CS1 and CS2 (first and second course) introductory level.
-
algorithms (22)
- These are miscellaneous problems involving various concepts and algorithms. These are intentionally not categorized by concepts (such as array, string, list, tree, recursion, etc.) so that you must consider for yourself the best way to solve the problem. This category might be useful when studying for a coding interview.
- baggageColors
- baggageColors2
- binaryBoarding
- binaryBoarding2
- compressString
- largestNumber
- longestUniqueString
- minSubrange
- isPermutation
- nextPermutation
- passports
- passports2
- sortThree
- sumCubes
- sumOf2020
- sum3Of2020
- surveys
- surveys2
- threeSum
- toboggan
- toboggan2
- validPasswords
- validPasswords2
-
arrays (27)
- arrayMystery
- arrayMystery2
- arrayMystery3
- arrayMysteryExam2
- arrayMysteryExam4
- arrayMysteryExam6
- banish
- collapsePairs
- computeAverage
- contains
- countDuplicates
- countUnique
- findMedian
- findRange
- getPercentEven
- hasMirrorTwice
- indexOf
- longestSortedSequence
- maxValue
- mystery1
- mystery2
- numUnique
- removePalindromes
- secondIndexOf
- sorted
- switchPairs
-
backtracking (36)
- canBalance
- canInterleave
- canMakeSum
- canPack
- chainExists
- combin
- contains
- crack
- cryptaSolver
- diceRolls
- diceSum
- diceSum2
- divide
- isElementSpellable
- isMeasurable
- knapsack
- knightsTour
- largestSum
- listTwiddles
- longestCommonSubsequence
- longestRepeatedSubsequence
- makeChange
- maxSum
- numberPuzzle
- partitionable
- permute
- phoneWords
- printAllBinary
- printAllDecimal
- printSquares
- printSubVectors
- rodCutting
- solveQueens
- squishWord
- waysToAverage
- waysToClimb
- weave
-
big-oh (14)
-
bit algorithms (10)
-
classes and objects (3)
-
collections (76)
- Using pre-existing collections from the C++ Standard Template Library (STL).
-
map (21)
-
set (8)
-
stack and queue (22)
-
vector (25)
- addStars
- collectionMystery1
- collectionMystery4
- countInRange
- cumulative
- findKeithNumbers
- histogram
- indexOfAll
- intersect
- isKeithNumber
- largestRectangleArea
- mean
- mostWater
- productOfOthers
- removeAll
- removeBadPairs
- removeConsecutiveDuplicates
- removeEvenLength
- reverse
- reverseFirstK
- stretch
- switchPairs
- vectorMystery1
- vectorMysteryInsert
- vectorMysteryRemove
-
SPL collections (118)
- Using collections from the Stanford Portable Library (SPL). We recommend using the exercises from the 'collections' category rather than this one unless you are a Stanford student using their custom libraries.
-
Vector (25)
- addStars
- collectionMystery1
- collectionMystery4
- countInRange
- cumulative
- findKeithNumbers
- histogram
- indexOfAll
- intersect
- isKeithNumber
- largestRectangleArea
- mean
- mostWater
- productOfOthers
- removeAll
- removeBadPairs
- removeConsecutiveDuplicates
- removeEvenLength
- reverse
- reverseFirstK
- stretch
- switchPairs
- vectorMystery1
- vectorMysteryInsert
- vectorMysteryRemove
-
Grid (14)
-
Stack and Queue (22)
-
Set (8)
-
Map (21)
-
PriorityQueue (1)
-
Graph (27)
- assignGroups
- bipartiteSets
- colorGraph
- containsBidiPath
- coolest
- findDominatingSet
- findEulerPath
- findHamiltonPath
- findLongestPath
- findMinimumVertexCover
- graphProperties1
- graphProperties2
- graphProperties3
- graphProperties4
- graphProperties5
- graphProperties6
- graphPropertiesExam1
- graphPropertiesExam2
- hasClique
- holidayShopping
- isConnected
- isDominatingSet
- isReachable
- kthLevelFriends
- maxIndependentSet
- popular
- tournamentWinners
-
collection implementation (158)
- Implementing your own C++ collection classes.
-
stack and queue (3)
-
set (1)
-
array lists (6)
- These exercises involve implementing a growable list of integer elements backed by an array.
- filter
- longestSortedSubsequence
- maxCount
- mirror
- removeDuplicates
- stretch
-
linked lists ListNode (22)
- Linked list exercises using pointers to a list node structure. These exercises involve modifying short sequences of nodes.
- 12-123
- 12-312
- 1234-2431
- 12-34-1342
- 12-34-1324
- 123-2-13
- 543-345
- 543-35-435
- 1-234-412-3
- 15-234-412-3
- 123-456-5342
- 12-34-41-23
- 1234-32-41
- 123-45-41-235
- 123-456-2614
- 123-45-4-253
- 1-23-32-14
- 12-345-32415
- 123-45-251-34
- 12-345-532-61
- 12-345-514-263
- 12rest34-5678-61rest3-2475
-
linked lists ptr (50)
- Linked list exercises using pointers to a list node structure.
- linkedListMystery1
- linkedListMystery2
- linkedListMystery3
- linkedListMystery4
- linkedListMystery5
- linkedListMystery11
- addBack
- addFront
- braid
- chopBothSides
- clump
- combineDuplicates
- consume
- contains
- countDuplicates
- countDuplicateStrings
- deleteBack
- doubleList
- eliminateFromRing
- expand
- getValue
- insert
- intersection
- isEmpty
- isSorted
- isSortedBy
- merge
- mergeUpTo
- middle
- min
- partitionSort
- printTargetRing
- remove
- removeAll
- removeAllThreshold
- removeBack
- removeFront
- removeRange
- reverse
- rotate
- setValue
- size
- split
- stutter
- surround
- switchEvens
- switchPairsOfPairs
- toString
- transferEvens
-
linked lists LinkedIntList (19)
- Linked list exercises using a linked list class and list node structure. These are more object-oriented than the pointer versions in the previous category.
- chopBothSides
- combineDuplicates
- consume
- countDuplicates
- deleteBack
- doubleList
- expand
- isSorted
- isSortedBy
- mergeUpTo
- min
- partitionSort
- removeAll
- removeRange
- reverse
- rotate
- split
- stutter
- transferEvens
-
binary trees ptr (34)
- Binary tree exercises using pointers to a tree node structure.
- completeToLevel
- completeToLevelString
- contains
- countLeftNodes
- hasPath
- height
- houseOfTudor
- isBalanced
- isBST
- isConsecutive
- levelTraversal
- limitLeaves
- limitPathSum
- makeFull
- printSideways
- range
- removeEveryKthLeaf
- removeFile
- removeLeaves
- removeMatchingLeaves
- sequential
- size
- stretch
- swapChildrenAtLevel
- tighten
- traversal1
- traversal2
- traversal3
- traversalsA
- traversalsB
- wordExists
- zigzagTraversal
- zip
-
binary search trees (BSTs) (8)
-
heaps (7)
- Exercises related to a binary min-heap.
- heapAddRemove0
- heapAddRemove1
- heapAddRemove2
- heapAddRemove6
- heapAddRemove7
- heapAddRemove8
- atLevel
-
hashing (8)
-
dynamic programming (14)
-
expressions (15)
-
if else (7)
-
inheritance (17)
- polymorphismMystery1
- polymorphismMystery2
- polymorphismMystery3
- polymorphismMystery4
- polymorphismMystery5
- polymorphismMystery6
- polymorphismMystery7
- polymorphismMystery8
- polymorphismMystery9
- polymorphismMystery10
- polymorphismMystery11
- polymorphismMysteryHamburger
- MemoryCalculator
- PancakeStack
- RiggedDice
- SortedStack
- UndoStack
-
input output streams (16)
-
loops (28)
- armstrongNumbers
- asciiFigure
- biggestAndSmallest
- book
- book2
- computeSumOfDigits
- fibonacci
- fizzBuzz
- floydsTriangle
- GuessingGame
- Guess2D
- loopMysteryExam1
- loopMysteryExam3
- loopMysteryExam5
- loopMysteryPrint1
- nthDigit
- numberLoops1
- numberLoops2
- numberLoops3
- numberSquare
- rangeOfNumbers
- sentinelSum
- sqrt
- starsPrint
- rocket
- rocket2
- spaceNeedle
- spaceNeedle2
-
parameters and returns (35)
- averageOf3
- binaryToDecimal
- Birthday
- BMI
- boxOfStars
- circleArea
- coinFlip
- computeDistance
- daysInMonth
- decimalToBinary
- digitCount
- factorCount
- factorial
- fitnessGoal
- Grades
- investment
- isMultiple
- isPrimeNumber
- parameterMystery2
- parameterMystery6
- parameterMystery13
- parameterMystery19sp3
- parameterMysteryBCA
- printPay
- Projectile
- quadratic
- referenceParameterMystery1
- referenceParameterMystery2
- returnMystery1
- showTwos
- sumOfDigits
- sumOfRange
- threeConsecutive
- triangle
- xkcdDatingRange
-
pointers (10)
-
programming basics (17)
-
recursion (61)
- collapseSequences
- combin
- countDuplicates
- countOccurrences
- countToBy
- crawl
- digitsSorted
- digitSum
- editDistance
- evaluateMathExpression
- evenDigits
- factorial
- gcd
- hanoi
- indexOf
- isPalindrome
- isSubsequence
- largestDigit
- lettersOnly
- longestRun
- matchCount
- mergeDigitPairs
- moveToEnd
- nonMatching
- numberSequence
- power
- printBinary
- printRange
- printStars
- recursionMystery1
- recursionMystery1X
- recursionMystery2
- recursionMystery2X
- recursionMystery348
- recursionMystery3
- recursionMystery4
- recursionMystery4X
- recursionMystery5
- recursionMystery648
- recursionMystery6
- recursionMystery7
- recursionMystery8
- recursionMystery9
- recursionMystery10
- recursionMystery11
- recursionMystery12
- recursionMystery13
- recursionMysteryComma
- recursionMysteryDivMod
- recursionMysteryMinus
- recursionMysteryPrintDigits
- removeEvens
- replaceAll
- reverseLines
- reverse
- sequence
- starString
- stutterStack
- sumOfSquares
- travel
- zigzag
-
searching (5)
-
sorting (6)
-
strings (30)
- addCommas
- caesarCipher
- containsTwice
- convertToAltCaps
- countWords
- crazyCaps
- dnaErrors
- dracula
- isAllVowels
- isPalindrome
- isRotation
- isVowel
- marshallMathers
- nameDiamond
- nameGame
- printBackward
- removeAll
- removeDuplicates
- repeat
- replaceAll
- reverse
- reverseChunks
- reverseWordOrder
- sameDashes
- startEndLetter
- stringMysteryAB
- stutter
- swapPairsInPlace
- switchPairs
- wordCount
You must log in before you can search for exercises or top users.
Is there a problem? Contact us.