Prateek Jangid

Prateek Jangid

165 Articles Published

Articles by Prateek Jangid

Page 5 of 17

C++ program to remove spaces from a string using String stream

Prateek Jangid
Prateek Jangid
Updated on 10-Aug-2022 1K+ Views

As the given problem says, we need to remove spaces from the string using a string stream. As the name suggests, a string stream converts a string into a stream. It works similar to cin in C++. It associates a string object that can access the string buffer in which it is stored. string s =" a for apple, b for ball"; res = solve(s); With a string buffer, we will read each word one by one and then concatenate it into a new string which will be our answer. Note − The class string stream is available ...

Read More

Removing a Number from Array to make It Geometric Progression using C++

Prateek Jangid
Prateek Jangid
Updated on 10-Aug-2022 207 Views

We are given an array of elements. We need to find whether the elements in the array are in Geometric Progression (GP) or not after removing any 1 element from the array. We can run out the possibilities and with observations to figure out that the first element is fake, or the second element is fake, or these 2 elements will give the common ratio of the array. After the common ratio is found, we can iterate on the array to see if all elements follow that rule. 2 base conditions would be to check if the first and second ...

Read More

C++ program to remove minimum elements from either side such that 2*min becomes more than max

Prateek Jangid
Prateek Jangid
Updated on 10-Aug-2022 505 Views

The problem involves removing elements from any side of a list of integers in such a way that 2*min is greater than max. vector arr = {250, 10, 11, 12, 19, 200}; res = solve(arr); We can use brute force approach. We can try all possible subarrays which satisfy and find the longest one in which 2*min > max condition holds. We can also use dynamic programming approach to try all possible subarray combinations that are overkill and not required. Example  (Using Vector ADT) Suppose we have an array such as “[250, 10, 11, 12, 19, 200]”. To get ...

Read More

Remove Duplicates from a Sorted Linked List Using Recursion

Prateek Jangid
Prateek Jangid
Updated on 10-Aug-2022 620 Views

A linked list is a sequence of elements that are connected together. Each list have a head and series of nodes and each node has data of the current node and link to next node. The basic operations of a linked list are insertion, deletion, search and delete. Removing duplicates from a sorted linked list One way to remove nodes from is using recursion. The idea is to compare each node with its adjacent node and delete the duplicate one they are equal. Our recursive call will return us to the next node. So for the next element, we will ...

Read More

Removing Brackets from an Algebraic String Containing + and – Operators using C++

Prateek Jangid
Prateek Jangid
Updated on 10-Aug-2022 690 Views

Given an algebraic string like p-(q-r)-s, we need to remove the brackets and convert this string to a string with the same mathematical result. So the string p-(q-r)-s is converted to p-q+r-s, giving us the same mathematical result. To achieve this, we can use a stack and keep track of whether or not we should flip the upcoming signs in the bracket expression. 0 mean + or no flip 1 mean - or flip So on every bracket opening, we will push either 0 or 1 depending on whether the signs in this bracket will flip or not. ...

Read More

C++ program to remove Nodes that Don't Lie in Any Path With Sum>=k

Prateek Jangid
Prateek Jangid
Updated on 10-Aug-2022 240 Views

In this problem, we have a binary tree with a path from the root node to the leaf node that is completely defined. The sum of all nodes from the root node to the leaf node must be greater than or equal to, a constant value, k. So we need to remove all nodes in those paths whose sum is less than k, such that the only paths left in the tree will be greater than k. An important thing to remember here is that a node may be a part of many paths, so only remove such nodes if ...

Read More

C++ Program to remove Characters from a Numeric String Such That String Becomes Divisible by 8

Prateek Jangid
Prateek Jangid
Updated on 18-May-2022 310 Views

Given a number in the form of a string, we need to find where to make it divisible by eight after deleting zero or more elements. In other words, we need to find whether there is a subsequence of the string, which is divisible by 8. Return the modified string or -1 if it is not possible.Any number whose last three digits are divisible by 8 is also divisible by 8. For example, 56992992 and 476360 are divisible by 8, but 2587788 is not. If the result is a whole number, then the original number is divisible by 8.We can ...

Read More

Partition Problem in C++

Prateek Jangid
Prateek Jangid
Updated on 07-Mar-2022 803 Views

In this problem, we must build C++ code to determine whether or not an array may be divided into two equal subarrays. Also, we have to check the condition if the sum of all the elements in both subarrays is exactly the same or not. The partitioning problem is a variant of the Subset Sum Problem, which is in turn a variant of the Knapsack Problem. We'll use the C++ programming language to tackle the partition problem. We must return a string with a Yes or No depending on whether the specified condition is fulfilled or not.Inputarr[] = {6, 4, ...

Read More

Palindrome Substring Queries in C++

Prateek Jangid
Prateek Jangid
Updated on 07-Mar-2022 635 Views

In this tutorial, we need to solve palindrome substring queries of the given string. Solving palindrome substring queries is far more complex than solving regular queries in C++. It requires a far more complex code and logic.In this tutorial, we are provided string str and Q number of substring[L...R] queries, each with two values L and R. we aim to write a program that will solve Queries to determine whether or not substring[L...R] is a palindrome. We must decide whether or not the substring formed within the range L to R is a palindrome to solve each query. For example ...

Read More

Making a Palindrome pair in an array of words (or strings) in C++

Prateek Jangid
Prateek Jangid
Updated on 07-Mar-2022 622 Views

"Madam" or "racecar" are two words that read the same backward as forwards, called palindromes.If we are given a collection or list of strings, we have to write a C++ code to find out if that can join any two strings in the list together to form a palindrome or not. If any such pair of strings exist in the given list, we have to print "Yes, " else we have to print "No."In this tutorial, input will be an array of strings, and output will be a string value accordingly, for exampleInputlist[] = {"flat", "tea", "chair", "ptalf", "tea"}OutputYesThere is ...

Read More
Showing 41–50 of 165 articles
« Prev 1 3 4 5 6 7 17 Next »
Advertisements