Interview Problems
Some of most asked C++ problems that are asked by interviewers in Round 1 of Coding.
- Palindrome Number (without string conversion)To solve this problem, we can use a simple algorithm that involves reversing the digits of the given number and then comparing the reversed number with the original number. If they are the same, the number is a palindrome; otherwise, it’s not.
- Check Number is Palindrome Number or not?A “Palindrome Number” is a number that remains the same when its digits are reversed. For example, 121 and 454 are palindrome numbers, but 123 and 789 are not. The problem is to determine whether a given integer is a palindrome or not? To solve this problem in C++, we can follow the steps below:… Read more: Check Number is Palindrome Number or not?
Table of Contents
Replace the last word of a string with number
C++ Code for Replace the last word of a string with number Replace the first word of a string with a number in C++
sort a huge array of numbers with a max number.
If you have a huge array of numbers with a maximum value (say 101), you can use counting sort, which is a linear time sorting algorithm, to efficiently sort the array. Counting sort is particularly effective when the range of input values is limited and known in advance. Here’s a C++ implementation for sorting an […]
Implement square root function.
Square root using binary search: Square root using Newton-Raphson method:
Implement a priority queue using a heap
A priority queue is a data structure that maintains a set of elements, each associated with a priority. The basic operations on a priority queue typically include insertion (enqueue) and extraction of the highest-priority element (dequeue). Priority Queue using Binary Heap: A priority queue implemented using a binary heap is a common and efficient data […]
Graph Topological sort
Topological sorting is an ordering of the vertices of a directed graph such that for every directed edge (u, v), vertex u comes before vertex v in the ordering. In simpler terms, it is a linear ordering of the vertices such that for every directed edge, the source vertex comes before the destination vertex. Topological […]
Implement a thread-safe queue
A thread-safe queue is a data structure designed to be used concurrently by multiple threads without data corruption or race conditions. Ensuring thread safety is crucial in multithreaded applications where multiple threads may attempt to access or modify the queue simultaneously. A thread-safe queue typically employs synchronization mechanisms to provide safe and ordered access to […]
Implement a breadth-first search (BFS) on a graph.
Breadth-First Search (BFS) is graph traversal algorithm that explores a graph level by level, visiting all the neighbors of a vertex before moving on to the next level. BFS is often used to find the shortest path between two vertices and to determine the connected components of a graph. BFS uses a queue to keep […]
Implement depth-first search (DFS) on a graph.
Depth-First Search (DFS) is a graph traversal algorithm that explores as far as possible along each branch before backtracking. Algorithm Steps: DFS Implementation C++
Implement Circular queue.
A circular queue is a data structure that uses a fixed-size array or a linked list to represent a queue. In a circular queue, when the end of the queue is reached, it wraps around to the beginning. Output:
Producer Consumer problem
The producer-consumer problem is a classic synchronization problem in computer science and concurrent programming. It involves two types of processes, known as producers and consumers, which share a common, fixed-size buffer or queue. The goal is to ensure that producers and consumers can operate concurrently while avoiding issues like data corruption, race conditions, and deadlock. […]