# 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 »

## Find the maximum product of two integers in an array

We have given an Integer array, and we need to find two numbers from the array whose product is the maximum. For example Input  arr = [-10, -10, 3, 4, -2, 25] output = [-10, -10] or [25,4] Explanation In the above array, we have 6 integer elements, and out of those 6 elements two pairs (-10, -10)… 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 »

## Program to Find LCM and HCF of two numbers

LCM stands for Least Common Multiple and HCF stands for Highest common factor. Finding LCM and HCF of two numbers is an elementary school math problem. The HCF is also known as GCD (Greatest Common Divisor). You may know how to calculate LCM and HCF of two numbers using pen and paper, now let’s write a program that… Read More »

## Write a Program to convert given inches into equivalent yard, and feet

In this article, we will write a program that can accept length in inches and convert it to the corresponding yard, and foot. The program can be made using simple arithmetic operations. If we look at the length converter there are 36 inches in 1 yard and 12 inches in 1 foot. Now let’s write our program that… 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 »

## Write a Program to read from a text file and then write in another text file

Every High-Level Programming language supports file handling, which helps us to write, read and append data into text and binary files. In this Programming tutorial, we will learn how to write a script in C++ and Python to read data from one file and write it into another. First, we will write data into out file1.txt file, then… 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 »

## Construct a Binary Tree from Inorder and Preorder traversals

You are given inorder and preorder 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. Preorder: In this traversal, we first visit the root node, then the left subtree, and the right subtree in the end. Example… 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 »