Dev Prakash Sharma

Dev Prakash Sharma

414 Articles Published

Articles by Dev Prakash Sharma

Page 35 of 42

Circle Sort in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 522 Views

Circle Sort is an interesting sorting algorithm to sort a given array of elements. The algorithm compares the elements of the array diametrically and once the elements in one part is sorted, then continuously sort the other end of the array diametrically.ExampleLet us visualize the circle sort for an array. Let us suppose we have an array with 6 elements.Input:N = 6arr [ ] = { 2, 1, 5, 8, 7, 9 }When we draw concentric circles for each array element, then it will appear as followsOutput:1 2 5 7 8 9Explanation: After sorting the elements in the array using Circle ...

Read More

Copy list with random Pointer in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 844 Views

A Linked List is a linear data structure in which each node is having two blocks such that one block contains the value or data of the node and the other block contains the address of the next field.Let us assume that we have a linked list such that each node contains a random pointer which is pointing to other nodes in the list. The task is to construct the list with the same as the original list. Copying the list from the original list which is having some random pointer is called a 'Deep Copy' of the linked list.For ...

Read More

C++ Program to find the Shortest Distance to a character

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 614 Views

Given a string 'a' and a character 'char', the task is to print the distance of 'char' from each character of the given string. The size of the distance array is same as the size of the string, since we have to find the distance of the character from each character of the given string.For ExampleInput-1:a = “tutorialspoint”char = “o”Output: [ 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3]Explanation: In the given string, the distance of the character from each character of the given string is [3, 2, 1, 0, 1, 2, 3, 4, 5, 6, ...

Read More

Find the sum of left leaf nodes of a given Binary Tree in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 1K+ Views

Let us suppose we have a Binary Tree having a root node and its left child and right child. The task is to find the total sum of leaf nodes of the tree which are left to its parent node.For ExampleInput-1:      Output:15Explanation: In the given input Binary Tree, the sum of all the left leaf nodes is 9+4+2 = 15. So, the output is 15.Approach to Solve this ProblemWe have a Binary Tree and the task is to find the sum of all the leaf nodes which are left to its parent.The recursive approach to solve this problem is to ...

Read More

Intersection of Two Linked Lists in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 2K+ Views

A Linked List is a linear data structure in which each node has two blocks such that one block contains the value or data of the node and the other block contains the address of the next field.Let us assume that we have a linked list such that each node contains a random pointer which is pointing to the other nodes in the list. The task is to find the node at which two linked lists intersect each other. If they don't intersect, then return NULL or empty as output.For ExampleInput-1:             Output:2Explanation: Since the given linked ...

Read More

Largest Merge of Two Strings in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 308 Views

Let us suppose we have two strings 'a' and 'b' and a string 'merge'. The task is to fill the string 'merge' with the characters from 'a' and 'b' in such a way that, If the string 'a' is non-empty, then remove the first character from the string 'a' and copy it into string 'merge'.If the string 'b' is non-empty, then remove the first character from the string 'b' and copy it into string 'merge'.If the strings 'a' and 'b' are non-empty, then remove the first characters from string 'a' and copy it into string 'merge' and then remove the ...

Read More

Make three numbers Zero in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 307 Views

Let us suppose we have three numbers. The task is to count the total number of optimal steps to make all these numbers '0'.For ExampleInput-1:a = 4 b = 4c = 6Output:7Explanation: Total number of optimal steps to make all the numbers '0' is, (4, 4, 6)Removing '1' from 1st and 2nd number = (3, 3, 6)Removing '1' from 1st and 3rd number = (2, 3, 5)Removing '1' from 1st and 3rd number = (1 ,3, 4)Removing '1' from 1st and 3rd number = (0 ,3 ,3)Removing '1' from 2nd and 3rd number = (0 ,2, 2)Removing '1' from 2nd and ...

Read More

Powerful Integers in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 294 Views

Let us suppose we have three integers 'a' and 'b' and 'limit'. The task is to print the numbers in the range [a, limit]. List of these numbers is said to be powerful integers and represented as, a^i + b^j such that i >= 0 and j >= 0For ExampleInput-1:a = 2b = 5limit = 10Output:[2, 3, 4, 5, 6, 7, 9]Explanation: for each i and j,                        2^0 + 5^0 = 2   , 2^0 + 5^1= 6                       2^1 + ...

Read More

Write a program in C++ to split two strings to make it a palindrome

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 344 Views

A string is said to be a palindromic string if it remains the same after reversing it.In this particular problem, we've given two strings 'a' and 'b' of the same length. If they are split with some indexes, then the task is to check whether the sum of the strings makes a palindrome or not.Let's say we have two string 'a' and 'b' of length '4' and after splitting both the string at the index '3' such that,                  aaa | b  and bbb | aaaa (prefix of first string) + a(suffix of ...

Read More

Symmetric Tree in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 23-Feb-2021 787 Views

Let us suppose we have a binary tree and the task is to check whether it constructs a symmetry of itself or not. A Symmetric Binary tree constructs the mirror image of itself.For ExampleInput-1:           Output:TrueExplanation:Since the given binary tree constructs the mirror image of itself, the output is True.Input-2: Output:FalseExplanation:Since the given binary tree doesn't make a mirror image of itself, it is not symmetric.Approach to Solve this ProblemA symmetric binary tree is a tree which is the mirror image of itself, which means we have to check whether the left and right nodes of the tree are ...

Read More
Showing 341–350 of 414 articles
« Prev 1 33 34 35 36 37 42 Next »
Advertisements