Category Archives: Data Structure

Move all zeros present in an array to the end

We have given an integer array, and we need to move all the zeros present in it to the end. And the output array must maintain the relative order of its elements, which means the order of other elements (except 0) must be in the same order. Example Input : [5,0,7,4,5,3,0,1,0,6] Output: [5,7,4,5,3,1,6,0,0,0] Explanation  In the output, you can… Read More »

Sort an array in one swap whose two elements are swapped

Problem Statement We have given an array in which all elements are sorted except two. Those two unsorted elements are swapped and we need to swap back so the array can be completely sorted. The challenge is we need to swap back the elements in linear time without duplicating the array or using any extra space. For Example… Read More »

Write a C++ Program to print a Man using Graphics

When it comes to designing graphics using any programming language we need to use a graphic library. In this C++ tutorial, we will learn how to print a Man Using C++ graphics library. For this tutorial, I will be using the DEV C++ IDE and its default compiler to write and execute the program. If you are using… Read More »

Construct a tree from Inorder and Level order traversals

You are given inorder and level order traversals. Create a Binary Tree using these given traversals. Inorder: In this traversal, we first visit the left subtree, then the root node, and the right subtree in the end. Level order: In this traversal, we visit every node, on a level before approaching the next level, in the top to… Read More »

Rearrange an array such that arr[i] = i

We have been given an integer array of size n, where every element a[i] is such that, 0<=a[i]<=n-1. Some of the elements may be missing. If the element is missing then there will be -1 written at the place of that element. We have to rearrange the array in such a way that each element a[i]=i and if,… Read More »