Server Side Programming Articles - Page 498 of 2650

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

Prateek Jangid
Updated on 10-Aug-2022 08:41:07

957 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

C++ program to remove row or column wise duplicates from matrix of characters

Prateek Jangid
Updated on 10-Aug-2022 12:18:34

529 Views

We are given a 2D matrix with rows and columns. The matrix consists of elements in char data type. A method is devised to remove the elements which are duplicated in their respective rows or columns. In this method, we check if any element is repeating in its row or column for each character. If it is not repeated, we leave it as it was before. We can store the values occurring in each row and column in a map. After which, we can traverse again and take those values which are appearing only once in their row and column. ... Read More

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

Prateek Jangid
Updated on 10-Aug-2022 08:29:25

164 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
Updated on 10-Aug-2022 08:27:13

441 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
Updated on 10-Aug-2022 07:53:32

576 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

C++ program to remove characters from a numeric string to make it divisible by 8

Prateek Jangid
Updated on 10-Aug-2022 07:50:42

193 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. According to divisibility rules, 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 ... Read More

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

Prateek Jangid
Updated on 10-Aug-2022 07:47:23

631 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
Updated on 10-Aug-2022 07:27:18

198 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

Difference between Yield and Return in Python?

Pradeep Kumar
Updated on 10-Sep-2022 08:42:36

10K+ Views

In Python, the definition of generators is accomplished with the help of the yield statement. Therefore, before we dive into the specifics of what yield actually does, it's important that you get an overview of generators. If you have exposure to Python, then there is a good probability that you have previously worked with Python generators. Generators play an important function in Python. In Python, iterators can be generated using generators, however this process takes a somewhat different form. Python Generators are functions that may be dynamically paused and resumed and create a succession of outcomes. They can also be ... Read More

How to Perform Numpy Broadcasting using Python using dynamic arrays?

Vikram Chiluka
Updated on 17-Aug-2022 12:17:09

342 Views

"Broadcasting” refers to how NumPy handles arrays of different dimensions during arithmetic operations. The smaller array is "broadcast" across the larger array, subject to certain limits, to ensure that their shapes are consistent. Broadcasting allows you to vectorize array operations, allowing you to loop in C rather than Python." This is accomplished without the need for unnecessary data copies, resulting in efficient algorithm implementations. In some cases, broadcasting is a negative idea since it results in wasteful memory utilization, which slows down the computation. In this article, we will show you how to perform broadcasting with NumPy arrays using python. ... Read More

Advertisements