#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
🧩 FREE · 15 PROBLEMS

C++ Practice Problems: STL, OOP and Classic Algorithms

Practise the C++ that coding rounds expect: the STL, classes, virtual functions and BFS, with sample tests to check your output.

  • 📚 STL containers
  • 🏛️ Classes and virtual functions
  • ✅ Output checker

How to use the C++ Practice Problems

  1. 1. Pick a problemFilter by level and choose a problem. Its task and sample tests appear below.
  2. 2. Write and run it locallyWrite your C++ solution here (it's saved in this browser), then run it with g++ -std=c++17 on each sample input.
  3. 3. Check your outputPaste what your program printed for each test and press Check. Solved problems get a tick.

Topics covered

  • Containers: sort and unique, word counts with map, two-sum with unordered_map, distinct counts in a sliding window.
  • Adapters: balanced brackets with stack, k-th largest with a min-heap priority_queue.
  • Algorithms: merge, rotate, transform, prefix sums and BFS on a grid.
  • OOP: a Rectangle class with const member functions, and shapes with an abstract base class and unique_ptr.

All 15 reference solutions compile with g++ in C++17 mode with warnings treated as errors, and pass their tests.

Worked example: k-th largest element

Input 6 2 and 3 2 1 5 6 4 should print 5, the second largest. The duplicate case 3 2 and 5 5 4 also prints 5, because duplicates count. The suggested solution keeps a min-heap of size k: push each number and pop when the heap grows past k. The heap's top is the answer, in O(n log k) time, which is faster than sorting when k is small.

Checking your work

Run your program on each sample input and paste the output into the matching box. The checker compares line by line, ignoring spaces at line ends. Use the hint first and the solution only after a real attempt; reading a solution you couldn't have written is when the learning happens, so compare it with yours line by line.

Frequently asked questions

Can I use bits/stdc++.h?

Yes for practice with g++. In production code include only the headers you need.

Which standard do the solutions need?

C++17. One solution uses structured bindings, which need C++17.

Does the page compile my code?

No. Compile it locally; the page checks the output you paste.

Is the C++ practice problems free?

Yes. Everything in the C++ practice problems works without signing up. The first time you ask for a result, we ask once for your name and WhatsApp number; after that the C++ practice problems and every other Uncodemy tool open straight away.

More free tools

See all free tools