Server Side Programming Articles - Page 497 of 2650

How to Find the Shortest Words in a Text File using Python?

Vikram Chiluka
Updated on 17-Aug-2022 12:20:19

3K+ Views

In this article, we will show you how to print all the shortest words from a given text file using python. The shortest words are the words which are having the same length as the shortest word (minimum length) in a text file. Assume we have taken a text file with the name TextFile.txt consisting of some random text. We will return all the shortest words from a given text file. TextFile.txt Good Morning Tutorials Point This is the Tutorials Point sample File Consisting of Specific abbreviated source codes in Python Seaborn Scala Imagination Summary and Explanation Welcome user Learn ... Read More

Replace every element with the least greater element on its right using C++

Prateek Jangid
Updated on 10-Aug-2022 09:27:51

258 Views

To find the least greater element on the right of an array of integers, we need to consider an array of integers. For each element, we need to find an element that is greater than the current element and is the least from all the candidate elements we have. Suppose we have elements such as [5, 23, 65, 31, 76, 32, 87, 23, 76, 32, 88]. vector arr = {5, 23, 65, 31, 76, 32, 87, 23, 76, 32, 88}; solve(arr); We can list our requirements and then think over the requirements to find a solution. We need a ... Read More

Replace each node with its Surpasser Count in Linked List Using C++

Prateek Jangid
Updated on 10-Aug-2022 09:16:23

229 Views

We are given a linked list, and we need to find elements in the given linked list which are greater and present in the right of the current element. The count of these elements needs to be substituted into the current node's value. Let's take a linked list with the following characters and replace each node with its Surpasser count − 4 -> 6 -> 1 -> 4 -> 6 -> 8 -> 5 -> 8 -> 3 From backward, traverse the linked list (so we do not need to worry about elements to the left of the current). ... Read More

C++ program to Replace Duplicates with Greater than Previous Duplicate Value

Prateek Jangid
Updated on 10-Aug-2022 12:54:28

330 Views

A series of integers is given in this article. Let's say we have an array of four elements without counting the repetitive elements, [2, 2, 5, 5, 7, 8, 7], and we have to make the array distinctive. Changing a value with one that is greater than the previous one is possible. In the above array, element 2 at index 1 becomes 3 as the next greater element. 5 at index 3 becomes 6 as the next greater and so on. So, in the end, our array becomes [2 3 5 6 7 8 9] and should minimize the sum ... Read More

C++ program to replace all occurrences of string AB with C without using extra space

Prateek Jangid
Updated on 10-Aug-2022 09:01:33

527 Views

In this article, we will replace "AB" with "C" in the given string having upper case latin characters. The occurrences of "AB" becomes "C, " but single "A" and "B" are unaffected. Let us look at some input scenarios − Let's have a string "ABOUTME" Input: "ABOUTME" Result: COUTME We start traversing the string from index one. We then check the current and previous elements for "B" and "A, " respectively. If we find it, then we replace the last append ("A") with a "C." The worst case time complexity will occur when there is no substring “AB” ... Read More

Replace All Consonants with Nearest Vowels In a String using C++ program

Prateek Jangid
Updated on 10-Aug-2022 08:59:19

1K+ Views

The method is devised to replace a string of consonants with the closest vowels from the alphabet (also known as lowercase Latin letters). If two vowels are equally close, we can replace them with the first ones in these letters. Let us look at some input scenarios − Suppose we have a string such as “ebgkjasjd, ” and now we need to change all the present consonants with the nearest vowels in a string. Input = "ebgkjasjd"; Result = ebgkjasjd eaeiiauie Taking element ‘b, ’ we can replace it with ‘a’ since that is the nearest vowel. We could ... Read More

Repeatedly Search for an Element by Doubling it After Every Successful Search Using C++

Prateek Jangid
Updated on 10-Aug-2022 08:56:48

401 Views

In this article, we are given an array of integers and a key. We must find the key repeatedly in the array and double it on each find in the array. We need to return the value not present in the array doing this operation. Some input scenarios to look at to understand how the method works in different cases Let's have an array [1, 2, 6, 3, 7, 4, 9], and its key is 1. Input: {1, 2, 3, 4, 5, 6}, k = 1 Result: 8 If we find 1 we double it to 2. If we ... Read More

C++ Program to find if the given string has Repeated Subsequence of Length 2 or More

Prateek Jangid
Updated on 10-Aug-2022 08:52:17

281 Views

Given a string, find a subsequence with the length, at least two, repeated in the string. The index of the subsequence element numbers must not be in the same order. string s = "PNDPNSP"; print("Repeated subsequence of length 2 or more: ", (check(s) ? "Yes" : "No")); Let us look at few examples below to see how the method works in different cases − Example 1 − str = "PNDPNSP" Explanation − Here, the answer is true because there is a subsequence "PN, " repeated in the string. Example 2 − str = "PPND" Explanation − Here, the answer ... Read More

C++ program to Reorder the Position of the Words in Alphabetical Order

Prateek Jangid
Updated on 10-Aug-2022 08:48:38

561 Views

In this problem, a string is taken as the input and we have to sort the words present in the string in a lexicographical order. To do that, we assign an index to each word in the string (differentiated with spaces in between) starting from 1, and the output is obtained in the form of sorted index. String = {“Hello”, “World”} “Hello” = 1 “World” = 2 Since the words in the input string are already in lexicographical order, the output is printed as “1 2”. Let us look at some input/result scenarios − Assuming all the words in ... Read More

C++ program to Reorder the Given String to Form a K-Concatenated String

Prateek Jangid
Updated on 10-Aug-2022 13:03:21

162 Views

We are given a string and an integer k, and we need to reorder the characters in the string so that it becomes the concatenation of k similar substring. If not possible, output the result as "Impossible”. string = "malaalam"; K = 2; res = solve(s, K); Example (Using Maps) Let's have a string "mottom" and K=2. The given string can be represented as the concatenation of 2 substrings like tomtom, motmot omtomt, etc. As in all 3, two substrings are joined together when k = 2. Using the string, we can determine how many times each character occurs. ... Read More

Advertisements