Sunidhi Bansal has Published 1101 Articles

Recursive program to insert a star between pair of identical characters in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 07:06:09

568 Views

Given a string str1 as input. The goal is to insert a ‘*’ between a pair of identical characters in the input string and return the resultant string using a recursive approach.If the input string is str1= "wellness" then output will be "wel*lnes*s"ExamplesInput − str1="happiness"Output − String after adding * : hap*pines*sExplanation − ... Read More

Recursive Approach to find nth node from the end in the linked list in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 06:59:53

365 Views

Given a Singly linked list and positive integer N as input. The goal is to find the Nth node from the end in the given list using recursion. If the input list has nodes a → b → c → d → e → f and N is 4 then ... Read More

Recursive approach for alternating split of Linked List in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 06:56:48

255 Views

Given a Singly linked list as input. The goal is to split the list into two singly linked lists that have alternate nodes of the original list. If the input list has nodes a → b → c → d → e → f then after the split, two sub-lists ... Read More

Recursive insertion and traversal linked list in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 06:53:40

949 Views

We are given with integer values that will be used to form a linked list. The task is to firstly insert and then traverse a singly linked list using a recursive approach.Recursive addition of nodes at the endIf head is NULL → add node to headElse add to head( head ... Read More

Recursive program to linearly search an element in a given array in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 06:18:37

1K+ Views

Given an integer array Arr[] containing integer numbers in any order. The goal is to find the input integer val present in the array using recursive search on the array.If val is not found in the input array Arr[] then return -1. Print the index of val if found in ... Read More

Row-wise common elements in two diagonals of a square matrix in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 06:15:22

164 Views

Given a 2D square matrix as input. The goal is to find the elements that are common in both its primary and secondary diagonals. If the input matrix is1 2 3 2 2 4 1 4 7Then its primary diagonal is 1 2 7 and the secondary diagonal is 3 ... Read More

Row-wise vs column-wise traversal of matrix in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 06:08:30

3K+ Views

A matrix can be traversed in two ways. Row-mise traversal visits each row one by one starting from first row then second and so on till the last row. Elements in the row are returned from index 0 to the last index.In Column-wise traversal, elements are traversed from the first ... Read More

Reduce a number to 1 by performing given operations in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 05:39:26

871 Views

Given an integer Number as input. The goal is to find the minimum number of steps or operations required to reduce the input Number to 1. Operations that can be performed will be-:If Number is even, then Divide it by 2.If Number is odd, then increment or decrement it by ... Read More

Reduce the fraction to its lowest form in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 05:32:43

4K+ Views

Given two integers Num1 and Num2 as input. The integers can be represented as fraction Num1/Num2. The goal is to reduce this fraction to its lowest form.Using GCD to find highest denominatorWe will calculate the greatest common divisor of both numbers.Divide both numbers by that gcdSet both variables as quotient ... Read More

Reduce the array to a single integer with the given operation in C++

Sunidhi Bansal

Sunidhi Bansal

Updated on 03-Nov-2021 05:30:11

119 Views

Given an integer variable Number as input. Let us consider an array containing elements in the range 1 to Number in any order. If we perform an operation Number-1 times on an array such thatWe select two elements A and B from the arrayRemove A and B from arrayAdd sum ... Read More

Advertisements