Dev Duel

C++ Challenges

Work on variables, loops, functions, OOP, and problem-solving.

Filter challenges

Narrow down by difficulty or category.

Showing 92 of 92 challenges

All challenges

Practice concepts, improve problem-solving, and build confidence.

intermediate12 minutes

Reverse a String Without Built-Ins

Reverse a string manually without using built-in reverse helpers.

stringsstringsloops
beginner10 minutes

Calculate the Factorial of a Number in C++

Learn how to write a function that calculates the factorial of a given non-negative integer using C++.

functionsfunctionsloops
intermediate10 minutes

Refactor Messy Inventory Management Code

Improve the structure and readability of a cluttered C++ function that manages inventory updates while preserving its original behavior.

code-qualitycode refactoringstd::map
beginner10 minutes

Predict the Output of a Simple Loop and Conditional in C++

Analyze the given C++ code involving a loop and conditional statements, and predict the exact output it produces when run.

logicloopsconditionals
advanced10 minutes

Predict Output of Complex Recursive and Bitwise Operations in C++

Analyze a complex C++ program that uses recursion combined with bitwise operations and tricky short-circuit logic. Predict the exact output produced by the program without running it.

logicrecursionbitwise operations
beginner10 minutes

Fix the Bug in a C++ Function to Calculate Factorial

Identify and fix the bug in a simple C++ function intended to calculate the factorial of a given number. The function currently produces incorrect output for some inputs.

debuggingvariables initializationfor loop
advanced20 minutes

Implement a Thread-Safe Memoization Function in C++

Build a reusable templated function that memoizes results of expensive computations in a thread-safe manner using modern C++ features.

functionstemplatesthread safety
beginner10 minutes

Fix the Bug in Counting Even Numbers in an Array

Identify and fix the bug in the given C++ function that is supposed to count the number of even numbers in an integer array.

debuggingloopsarrays
intermediate10 minutes

Build a Function to Rotate Elements in an Array

Write a C++ function that rotates the elements of an array to the right by a given number of steps. The rotation should handle cases where the number of steps is larger than the array size.

functionsarraysin-place modification
beginner10 minutes

Simple Contact List Manager in C++

Create a basic contact list manager where users can add, display, and search contacts using console input and output.

mini-projectsstructsvectors
advanced15 minutes

Refactor Complex C++ Class for Improved Readability and Maintainability

Given a complex and messy C++ class implementation, refactor the code to improve readability, maintainability, and follow best OOP practices without changing the program's behavior.

code-qualityCode RefactoringC++ Best Practices
advanced15 minutes

Implement a Custom Memoized Recursive Function for Large Fibonacci Numbers

Write an optimized C++ function to compute Fibonacci numbers using memoization. The function must efficiently handle very large inputs by caching intermediate results to avoid exponential time complexity, showcasing mastery of recursion, dynamic programming, and function optimization.

functionsrecursionmemoization
beginner10 minutes

Refactor Messy Loop and Conditionals in C++

Improve the readability and maintainability of a C++ function that calculates the sum of even numbers in a vector. Keep its behavior exactly the same while cleaning up the code.

code-qualityloopsconditionals
intermediate10 minutes

Build a Function to Merge and Sort Two Arrays

Write a C++ function that takes two integer arrays as inputs, merges them into a single array, removes duplicates, and returns the sorted result.

functionsvectorssorting
beginner10 minutes

Build a Function to Calculate the Area of a Rectangle

Write a simple C++ function that calculates the area of a rectangle given its width and height.

functionsfunctionsreturn statement
intermediate10 minutes

Build a Function to Rotate a Vector by k Positions

Write a C++ function that takes a vector of integers and an integer k, and returns the vector rotated to the right by k positions. This exercise tests your understanding of vector manipulation, modular arithmetic, and function implementation.

functionsvectorsmodular arithmetic
beginner10 minutes

Fix the Bug in a Simple Temperature Converter

Debug a basic C++ function that is supposed to convert temperatures from Celsius to Fahrenheit but currently produces incorrect results.

debuggingarithmetic operationsoperator precedence
intermediate20 minutes

Build a Simple Inventory Management System in C++

Create a console-based inventory management mini-project using C++. Implement features to add, update, delete, and display items stored in an inventory using vectors and classes.

mini-projectsclasses and objectsstd::vector
beginner10 minutes

Simple Task Tracker Mini-Project in C++

Build a basic console-based task tracker app in C++ that allows users to add, view, and remove tasks. Practice working with vectors, loops, and conditionals while creating a helpful daily tool.

mini-projectsvectorsloops
intermediate15 minutes

Build a Function to Compute Running Median from a Stream of Integers

Write a C++ function that accepts a vector of integers representing a stream of numbers and returns a vector containing the running median after each new number is added.

functionsheapspriority_queue
advanced15 minutes

Implement a Memoized Recursive Function to Compute the nth Catalan Number

Create an efficient C++ function that calculates the nth Catalan number using recursion with memoization. Catalan numbers appear in various combinatorial problems and grow quickly, so naive recursion is inefficient for larger inputs.

functionsrecursionmemoization
beginner10 minutes

Basic Calculator CLI Mini-Project in C++

Create a simple command-line calculator program in C++ that performs basic arithmetic operations like addition, subtraction, multiplication, and division based on user input.

mini-projectsvariablesconditional statements
advanced90 minutes

Advanced Multithreaded File Processing and Data Aggregation in C++

Create a performant C++ application that reads multiple large text files concurrently, processes the extracted data to compute aggregate statistics, and outputs a sorted summary report.

mini-projectsMultithreadingFile I/O
advanced120 minutes

Advanced Portfolio Management System in C++

Create a mini-project to design and implement a portfolio management system that tracks multiple investment assets, calculates real-time portfolio value, and supports transaction history and performance analysis.

mini-projectsclasses and objectsdata structures (maps, vectors)
intermediate10 minutes

Predict the Output of a Complex Nested Loop with Conditional Logic in C++

Analyze the given C++ code that uses nested loops with conditional statements to manipulate variables. Predict the output without running the code.

logicnested loopsconditional statements
intermediate10 minutes

C++ Student Grade Management System

Build a mini-project that manages student grades by storing names and scores, calculating averages, and allowing queries for top students.

mini-projectsClasses and StructsVectors
advanced15 minutes

Refactor a Complex C++ Matrix Multiplication with Thread Safety and Performance in Mind

Improve a messy and inefficient C++ matrix multiplication code by refactoring it to enhance readability, performance, and thread safety while preserving its original functionality.

code-qualityC++ refactoringperformance optimization
advanced20 minutes

Advanced C++ Code Refactor: Optimize and Modernize Complex Class Implementation

Given a legacy C++ class with complex logic, repetitive code, and poor maintainability, your task is to refactor it for readability, efficiency, and modern C++ best practices without altering its external behavior.

code-qualityModern C++Smart pointers
beginner10 minutes

Refactor a Simple Grade Calculator for Clarity

Improve the readability and structure of a basic C++ grade calculation function without changing its behavior.

code-qualityconditional statementscode readability
intermediate10 minutes

Predict the Output: Multi-dimensional Array and Pointer Arithmetic in C++

Analyze the provided C++ code snippet involving multi-dimensional arrays and pointer arithmetic. Predict the output without running the code.

logicpointer arithmeticmulti-dimensional arrays
beginner10 minutes

Build a Simple To-Do List Application in C++

Create a beginner-friendly console-based to-do list app where users can add, view, and remove tasks.

mini-projectsvectorsloops
advanced90 minutes

Advanced C++ Mini-Project: Multi-Threaded Task Scheduler with Prioritization

Build an advanced multi-threaded task scheduler in C++ that accepts tasks with different priorities, efficiently manages a thread pool, and executes tasks in priority order. The scheduler should support adding, cancelling, and monitoring tasks in real-time.

mini-projectsmultithreadingthread synchronization
beginner10 minutes

Simple Budget Tracker

Create a basic C++ program that helps track expenses and calculate the remaining budget. Users will input their total budget and then enter expenses one by one. The program will output the remaining budget after each expense and a summary at the end.

mini-projectsvariablesloops
advanced10 minutes

Predict the Output of Complex Pointer and Reference Manipulations in C++

Analyze the given C++ code involving multiple levels of pointers, references, and pre/post-increment operators. Predict the exact output after all manipulations, demonstrating deep understanding of pointer arithmetic, reference binding, and operator precedence.

logicpointer arithmeticreference to pointer
advanced15 minutes

Build a Function to Perform Multi-level Memoized Matrix Chain Multiplication

Implement an optimized function to compute the minimum number of scalar multiplications needed to multiply a given chain of matrices using memoization to achieve efficient performance.

functionsdynamic programmingmemoization
intermediate10 minutes

Build a Function to Calculate the Running Median of an Integer Stream

Write a function in C++ that processes a stream of integers and returns the median after each new number is added. The function should efficiently handle the insertion and calculation steps to provide medians dynamically.

functionsheapspriority_queue
advanced20 minutes

Refactor Complex C++ Banking System for Maintainability and Performance

Refactor the provided C++ code of a banking system that handles multiple account types, transactions, and interest calculations. The goal is to improve code quality, maintainability, and performance without changing the system's behavior.

code-qualityinheritancepolymorphism
advanced15 minutes

Fix Memory Leak and Logic Bug in Custom Linked List Implementation

Identify and fix the memory management and logic bugs in a custom singly linked list class implemented in C++. The list supports insertion and search operations but has subtle issues causing memory leaks and incorrect behavior.

debuggingMemory managementPointers and dynamic allocation
intermediate15 minutes

Employee Performance Tracker

Build a C++ program to manage and analyze employee performance data by storing, updating, and calculating key statistics from the data.

mini-projectsstructsvectors
intermediate10 minutes

Fix the Logic Bug in the Array Frequency Counter

The given C++ function is intended to count the frequency of each integer in an input vector and return the result as a map. However, the current implementation produces incorrect frequency counts due to a logic bug. Your task is to identify and fix the bug so that the function returns accurate counts.

debuggingmap usageloops
intermediate10 minutes

Refactor Messy C++ Code for Calculating Statistics on an Integer Array

Improve and clean up a provided C++ function that calculates the minimum, maximum, and average of an integer array while maintaining the same behavior.

code-qualityCode RefactoringLoops
advanced15 minutes

Build a High-Performance Memoized Fibonacci Function Using C++ Templates

Create an advanced C++ function that computes Fibonacci numbers efficiently using both memoization and template metaprogramming techniques to optimize compile-time and run-time performance.

functionsmemoizationtemplate metaprogramming
beginner10 minutes

Fix the Bug in Celsius to Fahrenheit Conversion Function

A simple function to convert a temperature from Celsius to Fahrenheit contains a bug. Fix the function so it returns the correct Fahrenheit value.

debuggingbasic arithmeticorder of operations
intermediate15 minutes

Implement a Simple Task Manager CLI in C++

Create a command-line task manager application that allows users to add, list, complete, and remove tasks stored in memory during the program session.

mini-projectsstructs and classesvectors
beginner10 minutes

Simple Console Budget Tracker in C++

Build a beginner-friendly console application that helps users track their daily expenses and remaining budget.

mini-projectsvariablesloops
beginner10 minutes

Fix the Off-By-One Error in Loop Summation

Debug a simple function in C++ that aims to sum integers from 1 to n but produces incorrect results due to an off-by-one error in the loop.

debuggingloopsfor loop
intermediate10 minutes

Predict the Output: Array Transformation and Loop Logic in C++

Analyze the given C++ code snippet that performs multiple array transformations and loop operations. Predict the final output printed by the program without running it.

logicarray manipulationfor loops
advanced15 minutes

Refactor a Complex C++ Class for Cleaner Design and Performance

Refactor the given C++ class that manages a large dataset with inefficient and messy logic. Improve code readability, maintainability, and performance while preserving functionality.

code-qualitycode-refactoringconst-correctness
beginner10 minutes

Refactor a Function to Calculate Sum of Array Elements

Improve the clarity and quality of a simple C++ function that sums elements in an integer array, while keeping its behavior unchanged.

code-qualityloopsfunctions
intermediate10 minutes

Refactor Messy Nested Loop Code to Improve Readability and Performance

You are given a C++ function that uses nested loops and multiple conditionals in a messy and repetitive way to find common elements between two integer vectors and sum them. Refactor the code to improve readability, reduce complexity, and maintain the same output.

code-qualityrefactoringSTL containers
advanced90 minutes

Advanced File System Explorer and Analyzer

Build a C++ program that recursively explores a given directory, constructs an in-memory model of the entire file system hierarchy starting at that directory, and generates detailed reports including total file counts, directory sizes, and file type distributions. The project tests your skills in recursion, data structures, file I/O, and performance optimization.

mini-projectsrecursionfilesystem
beginner10 minutes

Refactor Messy Function to Calculate Factorial

Improve the readability and structure of a simple factorial calculation function in C++ without changing its behavior.

code-qualityloopsfunctions
advanced45 minutes

Advanced Event Scheduler with Conflict Resolution in C++

Build an advanced event scheduler that manages multiple events with time conflicts resolution. The scheduler must support adding, removing, updating events, and querying free time slots efficiently.

mini-projectsinterval treesconflict resolution
advanced15 minutes

Fix Memory Leak and Logic Bugs in Advanced Custom Smart Pointer Implementation

You are given a custom smart pointer class in C++ designed to manage dynamic memory with reference counting. The implementation contains subtle memory leaks and logic bugs causing incorrect reference counting and dangling pointers. Your task is to identify and fix these bugs to ensure safe and correct memory management.

debuggingC++ pointersreference counting
beginner10 minutes

Basic Bank Account Manager

Create a simple bank account manager that allows deposits, withdrawals, and balance checks using functions and conditionals.

mini-projectsstructs/classesfunctions
advanced60 minutes

Implement a Multi-threaded File Search Utility in C++

Create an advanced multi-threaded file search utility in C++ that scans directories recursively to find files containing a specific keyword. The program should optimize search performance using concurrency and handle large directory trees efficiently.

mini-projectsmultithreadingfilesystem traversal
intermediate10 minutes

Predict the Output of Nested Loops and Conditionals in C++

Analyze the following C++ code with nested loops, conditionals, and array manipulation, then determine and predict what the output will be when the program runs.

logicnested loopsconditionals
advanced60 minutes

Advanced File System Simulator with Permissions and Command Parsing

Create a mini file system simulator in C++ that supports file creation, deletion, directory navigation, and permission handling with a command-line interface.

mini-projectsfile system simulationbitwise operations
advanced20 minutes

Fix Memory Leak and Logic Errors in a Multi-threaded Task Scheduler

You are given a flawed C++ implementation of a simple multi-threaded task scheduler that manages and executes tasks concurrently. The code contains memory leaks, race conditions, and logic errors that cause incorrect task execution and resource cleanup issues. Your job is to identify and fix the bugs to produce a robust, leak-free, and correctly functioning scheduler.

debuggingmemory managementmultithreading
advanced15 minutes

Refactor Legacy Inventory Management Code for Efficiency and Readability

Improve an inefficient, hard-to-read inventory management function written in C++ by refactoring it to use modern C++ features, enhance performance, and maintain identical behavior.

code-qualitycode refactoringC++ STL algorithms
advanced15 minutes

Fix the Bug in the Multithreaded Singleton Logger Implementation

Identify and fix the concurrency bug in a classic thread-safe Singleton Logger class in C++. The provided code attempts lazy initialization with double-checked locking but contains subtle issues that may cause race conditions or undefined behavior in a multithreaded environment.

debuggingthread safetysingleton pattern
advanced120 minutes

Develop a High-Performance Concurrent Web Crawler in C++

Build an advanced mini-project that involves designing and implementing a multithreaded web crawler in C++ capable of efficiently scanning and indexing web pages with rate limiting and duplicate URL detection.

mini-projectsmultithreadingconcurrency
intermediate10 minutes

Create a Function to Merge Two Sorted Arrays Without Duplicates

Build a C++ function that takes two sorted integer arrays and returns a new sorted array containing all unique elements from both arrays, effectively merging them without duplicates.

functionsvectorstwo-pointer technique
intermediate10 minutes

Fix Bug in C++ Function to Find Maximum Product of Two Elements

The provided C++ function is intended to find the maximum product of any two distinct elements in an integer array. However, it contains logical and implementation bugs that lead to incorrect results or runtime errors. Your task is to identify and fix these bugs to ensure the function works correctly for all valid inputs.

debuggingnested loopsarray indexing
advanced90 minutes

Advanced Mini-Project: Design a Custom Event Scheduler with Recurrence Rules in C++

Build a robust event scheduler application that supports creating, storing, and querying events with complex recurrence rules, such as daily, weekly, or custom intervals. The scheduler should efficiently handle overlapping events and allow users to fetch upcoming events within a date range.

mini-projectsdate and time manipulationrecurrence rule processing
advanced30 minutes

Build a Function to Perform Symbolic Differentiation of Polynomials in C++

Create an advanced C++ function that takes a polynomial expression as a string input and returns its derivative as another string. This function should handle multiple terms, coefficients, exponents, and the variable x correctly, performing symbolic differentiation in standard mathematical notation.

functionsstring parsingsymbolic computation
advanced15 minutes

Fix Memory Leak and Concurrency Bug in Thread-Safe Cache Implementation

Given an incomplete and buggy thread-safe LRU cache implementation in C++, identify and fix issues related to memory leaks, data races, and incorrect cache eviction logic.

debuggingconcurrencymemory management
advanced10 minutes

Build a Memoized Recursive Function to Calculate Large Fibonacci Numbers

Implement an efficient recursive function in C++ that computes the nth Fibonacci number leveraging memoization to optimize overlapping subproblems, capable of handling large input values.

functionsrecursionmemoization
intermediate30 minutes

Inventory Management System for a Small Store

Build a simple inventory management mini-project in C++ to track products, stock levels, and sales transactions with multi-step logic and data structures.

mini-projectsclasses and structsunordered_map usage
beginner10 minutes

Simple Bank Account Transaction Tracker

Build a basic C++ program that tracks deposits and withdrawals for a single bank account and displays the final balance.

mini-projectsloopsconditionals
intermediate10 minutes

Build a Function to Rotate an Array by k Steps

Create a C++ function that rotates the elements of an integer array to the right by k steps. This function should handle cases where k is greater than the array length and work efficiently without using extra space for another array.

functionsarraysmodulo operation
advanced15 minutes

Fix Bug in Advanced Multithreaded Bank Account Simulation

You are given a broken multithreaded C++ program simulating deposits and withdrawals on a bank account. The code uses mutexes to protect the balance but still produces inconsistent results due to subtle bugs. Your task is to identify and fix these concurrency and logic bugs to ensure the balance always stays correct after concurrent operations.

debuggingmultithreadingmutex
beginner10 minutes

Build a Simple Bank Account Manager in C++

Create a basic console application in C++ to simulate a simple bank account manager that allows a user to deposit, withdraw, and check their balance.

mini-projectsClasses and ObjectsConditional statements
advanced10 minutes

Predict the Output of a Complex Recursive Lambda with State Captures in C++

Understand and predict the output of advanced C++ code involving recursive lambdas with mutable and reference state captures that manipulate shared variables and invoke themselves conditionally.

logicrecursive lambda functionsmutable lambda captures
advanced15 minutes

Refactor Legacy C++ Code to Enhance Readability and Performance

Given a legacy C++ function that processes and filters a vector of user data with multiple nested loops and repeated conditions, refactor the code to improve readability, reduce complexity, and optimize performance while preserving the original behavior.

code-qualityC++ STL algorithmscode refactoring
advanced15 minutes

Fix Bug in Optimized Matrix Chain Multiplication Implementation

The provided C++ code implements the Matrix Chain Multiplication algorithm using dynamic programming to find the minimum number of scalar multiplications needed to multiply a chain of matrices. However, the current implementation contains bugs that lead to incorrect results and occasional runtime errors. Your task is to identify and fix these bugs so the algorithm returns correct and optimized results.

debuggingdynamic programmingmatrix chain multiplication
advanced90 minutes

Advanced Multi-Threaded File Search and Filter Utility in C++

Build a high-performance, multi-threaded C++ utility to recursively search through directories for files matching specific content and metadata filters, then output a summary report. This mini-project will test your architectural design, concurrency control, file I/O, and advanced C++ skills.

mini-projectsMultithreading and concurrencyFilesystem operations and metadata
advanced120 minutes

Advanced File System Indexer and Search Tool in C++

Build a highly efficient file system indexer that recursively scans directories, indexes file metadata, and supports advanced search queries with filters and sorting, all implemented in C++.

mini-projectsfilesystem traversaldata structures and algorithms
intermediate10 minutes

Predict the Output of a Custom Array Transformation Function in C++

Analyze the given C++ code that transforms an integer array through nested loops and conditional swaps. Predict what the output will be when the code is executed with a specific input array.

logicnested loopsarray manipulation
advanced10 minutes

Implement a High-Performance Memoized Fibonacci Calculator in C++

Build a highly optimized C++ function to compute Fibonacci numbers using memoization to minimize time complexity for very large inputs without stack overflow or excessive memory usage.

functionsmemoizationdynamic programming
beginner10 minutes

Simple Bank Account Management System

Build a basic bank account management mini-project in C++ that allows creating an account, depositing money, withdrawing money, and showing the current balance.

mini-projectsclassesmethods
beginner10 minutes

Refactor Messy C++ Function to Improve Readability and Efficiency

Given a function with redundant variables and unclear naming, refactor it to improve code quality without changing its behavior.

code-qualityvariablesloops
beginner10 minutes

Simple Budget Tracker: Track Expenses and Calculate Balance

Create a beginner-friendly console program in C++ that allows users to input their income and a list of expenses, then calculates and displays the remaining balance.

mini-projectsvariablesloops
advanced15 minutes

Implement a High-Performance Memoized Fibonacci Function Using C++17 Features

Create an optimized recursive Fibonacci function that uses memoization with modern C++17 features such as std::unordered_map and constexpr optimizations to achieve efficient calculations for large Fibonacci indices.

functionsrecursionmemoization
intermediate10 minutes

Fix the Integer Array Reversal Bug in C++

The given C++ function is intended to reverse the elements of an integer array in place, but it contains logical errors causing incorrect output or runtime issues. Your task is to identify and fix the bugs so the array is reversed correctly.

debuggingarray indexingin-place array reversal
intermediate10 minutes

Predict Output: Logical Array State Manipulation in C++

Analyze a C++ function manipulating a boolean array with combined loop and conditional logic to determine what the final output will be.

logicboolean logicarrays
advanced60 minutes

Design and Implement a Thread-Safe LRU Cache in C++

Create a high-performance, thread-safe Least Recently Used (LRU) cache class in C++. The cache should support concurrent access from multiple threads and provide O(1) time complexity for insertions, lookups, and deletions.

mini-projectsConcurrency and thread safetyData structures (unordered_map and linked list)
beginner10 minutes

Simple Temperature Converter Mini Project

Build a small program that converts temperatures between Celsius and Fahrenheit scales, allowing users to enter a temperature and choose the conversion direction.

mini-projectsfunctionsconditionals
advanced15 minutes

Refactor and Optimize a Multithreaded Logging System in C++

Improve the readability, maintainability, and performance of an existing multithreaded logging system while preserving its functionality.

code-qualitymultithreadingmutex and locking
advanced15 minutes

Fix the Memory Leak and Logical Errors in a Custom Smart Pointer Implementation

Identify and fix memory management bugs and logical errors in a custom C++ shared pointer implementation to ensure proper resource deallocation and reference counting.

debuggingC++ pointersmemory management
advanced90 minutes

Advanced File System Simulation with C++

Create an advanced mini-project that simulates a hierarchical file system including files and folders with operations like add, delete, move, and search, using efficient data structures in C++.

mini-projectsObject-Oriented ProgrammingData Structures (Trees)
beginner10 minutes

Fix the Off-By-One Error in a Loop to Sum Integers

A simple C++ function intended to sum integers from 1 to n contains a bug causing incorrect results. Identify and fix the off-by-one error.

debuggingloopsconditionals