Articles on Trending Technologies

Technical articles with clear explanations and examples

Minimum number of swaps required to sort an array in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 788 Views

Problem statementGiven an array of N distinct elements, find the minimum number of swaps required to sort the arrayExampleIf array is {4, 2, 1, 3} then 2 swaps are requiredSwap arr[0] with arr[2]Swap arr[2] with arr[3}Algorithm1. Create a vector of pair in C++ with first element as array alues and second element as array indices. 2. Sort the vector of pair according to the first element of the pairs. 3. Traverse the vector and check if the index mapped with the value is correct or not, if not then keep swapping until the element is placed correctly and keep counting ...

Read More

Timer in C++ using system calls

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Here we will see how to design timer in C++ using a system call. We will not use any graphics or animations. Here timer means the stopwatch, that is up-counting the time. The used system calls are −sleep(n) − This will help the program to sleep for n number of secondssystem() − This is used to execute the system command by passing command as an argument to this function.Example#include #include #include #include using namespace std; int hrs = 0; int mins = 0; int sec = 0; void showClk() {    system("cls");    cout

Read More

Minimum number of stops from given path in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 295 Views

Problem statementThere are many points in two-dimensional space which need to be visited in a specific sequence.Path from one point to other is always chosen as shortest path and path segments are always aligned with grid lines.We are given the path which is chosen for visiting the points. We need to tell the minimum number of points that must be needed to generate given paths.Algorithm1. We can solve this problem by observing the pattern of movement when visiting the stop 2. If we want to take the shortest path from one point to another point, then we will move in ...

Read More

Type Conversion in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Here we will see what are the type conversion techniques present in C++. There are mainly two types of type conversion. The implicit and explicit.Implicit type conversionThis is also known as automatic type conversion. This is done by the compiler without any external trigger from the user. This is done when one expression has more than one datatype is present.All datatypes are upgraded to the datatype of the large variable.bool -> char -> short int -> int -> unsigned int -> long -> unsigned -> long long -> float -> double -> long doubleIn the implicit conversion, it may lose ...

Read More

Convert Hexadecimal value String to ASCII value String in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 2K+ Views

In this tutorial, we will be discussing a program to convert hexadecimal value string to ASCII value string.For this we will be provided with a string with some hexadecimal values. Our task is to get that hexadecimal value and convert it into equivalent ASCII values.Example#include using namespace std; string convert_ASCII(string hex){    string ascii = "";    for (size_t i = 0; i < hex.length(); i += 2){       //taking two characters from hex string       string part = hex.substr(i, 2);       //changing it into base 16       char ch = stoul(part, nullptr, 16);       //putting it into the ASCII string       ascii += ch;    }    return ascii; } int main(){    cout

Read More

Minimum removal to make palindrome permutation in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 385 Views

Problem statementGiven a string S, we have to find minimum characters that we can remove to make any permutation of the string S a palindromeExampleIf str = “abcdba” then we remove to 1 character i.e. either ‘c’ or ‘d’.Algorithms1. There can be two types of a palindrome, even length, and odd length palindromes 2. We can deduce the fact that an even length palindrome must have every character occurring even number of times 3.An odd palindrome must have every character occurring even number of times except one character occurring odd number of time 4. Check the frequency of every character ...

Read More

Printing Pyramid in C++

Ajay yadav
Ajay yadav
Updated on 11-Mar-2026 632 Views

This article yields a “pyramid-like structure” as an output using the C++ programming code. In which the pyramid height and space are being determined by traversing double for loop constructs as following;Example#include using namespace std; int main() {    int space, rows=6;    for(int i = 1, k = 0; i

Read More

Convert min Heap to max Heap in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 913 Views

In this tutorial, we will be discussing a program to convert min heap to max heap.For this we will be provided with the array representation of the min heap. Our task is to convert that given min heap to max heap in O(n) time complexity.Example#include using namespace std; //converting a given subtree into a heap void convert_arrayheap(int arr[], int i, int n){    int l = 2*i + 1;    int r = 2*i + 2;    int largest = i;    if (l < n && arr[l] > arr[i])       largest = l;    if (r < ...

Read More

Minimum removals from array to make max – min <= K in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 523 Views

Problem statementGiven N integers and K, find the minimum number of elements that should be removed such that Amax - Amin

Read More

Construct a frequency array of digits of the values obtained from x^1, x^2, ....., x^nn in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 245 Views

Suppose we have two integers x and n. We have to find the array such that it contains the frequency of index numbers occurring in (x^1, x^2, … x^(n – 1), x^n). So if x = 15 and n = 3, then output will be [0, 1, 2, 2, 0, 3, 0, 1, 0, 0]. As we know that x^1 to x^n, the values are 15, 225 and 3375. So the frequency array is 0, 1, 2, 2, 0, 3, 0, 1, 0, 0To solve this, we will follow these steps −Maintain the frequency count array to store the counts ...

Read More
Showing 28131–28140 of 61,299 articles
Advertisements