Programming Articles - Page 1383 of 3366

Copy list with random Pointer in Python

Dev Prakash Sharma
Updated on 23-Feb-2021 19:03:40

780 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

Breadth First Search on Matrix in Python

Dev Prakash Sharma
Updated on 23-Feb-2021 05:37:17

2K+ Views

In a given matrix, there are four objects to analyze the element position: left, right, bottom, and top.Breadth First Search is nothing but finding the shortest distance between the two elements of a given 2-D Matrix. Thus, in each cell, there are four operations we can perform which can be expressed in four numerals such as, '2' describes that the cell in the matrix is Source.'3' describes that the cell in the matrix is Destination.'1' describes that the cell can be moved further in a direction.'0' describes that the cell in the matrix can not be moved in any direction.On ... Read More

Balanced Binary Tree in Python

Dev Prakash Sharma
Updated on 23-Feb-2021 19:08:10

5K+ Views

In a binary tree, each node contains two children, i.e left child and right child. Let us suppose we have a binary tree and we need to check if the tree is balanced or not. A Binary tree is said to be balanced if the difference of height of left subtree and right subtree is less than or equal to '1'.ExampleInput-1: Output:TrueExplanation:The given binary tree is [1, 2, 3, NULL, NULL, 6, 7]. The height difference of its left subtree and right subtree is equal to '1', thus it is a height Balanced tree.Input-2:               Output:FalseExplanation:The given ... Read More

Symmetric Tree in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:10:18

729 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

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

Dev Prakash Sharma
Updated on 23-Feb-2021 19:14:29

309 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

How to Segregate a given Linked List in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 05:22:40

258 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 the data and a pointer which is pointing to the next node of the linked list. The task is to segregate the given Linked List. Segregating the linked list means we have to separate the odd indexed nodes and even index nodes in the list.Approach to Solve this ProblemTo ... Read More

Powerful Integers in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:19:43

272 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

Make three numbers Zero in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:22:11

273 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

Largest Merge of Two Strings in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:26:42

271 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

Intersection of Two Linked Lists in C++

Dev Prakash Sharma
Updated on 23-Feb-2021 19:28:35

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

Advertisements