Server Side Programming Articles - Page 496 of 2650

C++ program to replace an element makes array elements consecutive

Prateek Jangid
Updated on 10-Aug-2022 10:01:57

605 Views

We are given an array of elements. We need to find if it is possible to change the value of any one element to make the array elements consecutive. If not possible, return -1 ; otherwise, the element needs to be changed. Let's suppose we have an array {4, 3, 9, 5, 6} and we have to sort this given array. Then start from the smallest and largest element checking the number of mismatches. If the number of mismatches is more than 1 on both sides of the array, the answer is -1. Otherwise, it is possible to get the ... Read More

C++ program to search an element in a sorted rotated array

Ravi Ranjan
Updated on 06-Jun-2025 19:16:12

1K+ Views

A sorted and rotated array is an array that is sorted in ascending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. The array can be said to be split into two halves and each half is a sorted array. For example: {5, 6, 7, 1, 2, 3} is a sorted and rotated array and {5, 6, 7, 8, 2, 5, 4, 5} is not a sorted and rotated array. In this article, we have an array of integers. Our task is ... Read More

How to Write a List Content to a File using Python?

Vikram Chiluka
Updated on 17-Aug-2022 12:11:22

4K+ Views

In this article, we will show you how to write the data present in the list into a text file using python. Assume we have taken a list and written all the elements of the list into a text file say "ListDataFile.txt" which has the following data after writing into it. Let’s say that we have following list in a text file − inputList = ['This', 'is', 'a', 'TutorialsPoint', 'sample', 'file'] we will get the following result of the above string with this program − This is a TutorialsPoint sample file Algorithm (Steps) Following are the Algorithm/steps to be ... Read More

Searching an Element in Doubly Circular Linked List using C++

Prateek Jangid
Updated on 10-Aug-2022 09:56:26

292 Views

Given a double circular linked list and key, we have to search the key in the linked list and give a proper message if found. Suppose we have a linked list with the specific characters, and we have to search for an element in it. So let's start with the following linked list − 5 8 9 2 4 We will use 4 as a key to finding the solution to the given problem. A double-linked list has no fixed head, so we will start from any node and then mark that node as ... Read More

C++ program to find Second Smallest Element in a Linked List

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

373 Views

An ordered collection of data elements, each with a link to its next element (and sometimes its predecessor), Suppose there is a linked list, then we need to find the second smallest element. The below are the following scenarios. Let’s assume some simple input and output scenarios Let’s assume this scenario that we are having a linked list contains elements in it are "8->4->6->2->9, ". Then after iterating entire linked list, the second smallest element will be 8. Input = 8->4->6->2->9 Output = 8 Programing way of implementing the linked list Node* head = new Node(8); head->next = new ... Read More

How to Remove Newline Characters from a text File?

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

5K+ Views

In this article, we will show you how to remove the newline character() from a given text file using python. Assume we have taken a text file with the name TextFile.txt consisting of some random text. We will remove the newline character() from a given text file. TextFile.txt Good Morning TutorialsPoint This is TutorialsPoint sample File Consisting of Specific source codes in Python, Seaborn, Scala Summary and Explanation Welcome TutorialsPoint Learn with a joy Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Create a variable to store the path of the ... Read More

C++ program to find Second most repeated word in a sequence

Prateek Jangid
Updated on 10-Aug-2022 09:52:54

459 Views

We are given an array of words, and we need to find the word whose frequency is the second largest in the array. Let’s assume some simple input and output scenarios Let’s assume we are having an array which consists of elements like [“point, ” “world, ” “articles, ” “articles, ” “articles, ” “world, ” “world, ” “world, ” “point”]. The frequency of words are − “point”: 2 “world”: 4 “articles”: 3 // This will be the second most repeated word in the array. So the second most repeated word is “articles, ” and our output is “articles.” Let’s ... Read More

Smallest integer > 1 which divides every element of the given array: Using C++

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

261 Views

In this article, we are given integers in an array, and we must find the smallest number which is greater than 1 that divides all the elements in the array. For example, let us consider a sample array [30, 90, 15, 45, 165]. vector arr = {30, 90, 15, 45, 165}; result = solve(arr); Now we can find the array's GCD(greatest common divisor). If it comes out to be 1 that means that only 1 can divide the whole array, and we can return -1 or "Not possible." If it's an integer, then this integer divides the whole ... Read More

C++ program to Replace Nodes with Duplicates in Linked List

Prateek Jangid
Updated on 10-Aug-2022 09:49:07

422 Views

In this article, we are given a linked list that contains elements from 1 to n and duplicates. Elements 1 to n will always be there with duplicates from [1..n]. We need to replace every duplicate element with n+1, n+2, and so on. Lets consider an example 1→2→2→4→5→3→6→6 Next n = 42. So every duplicate is replaced with n+1, n+2, and so on. The next 42 is replaced with 47, and the next 46 is replaced with 48, leaving the first instance as it is. First of all, we need to construct a binary tree in the main method as ... Read More

C++ program to Replace Every Matrix Element with Maximum of GCD of Row or Column

Prateek Jangid
Updated on 10-Aug-2022 09:47:24

463 Views

In this method, we need to replace every element in the given matrix with the maximum Greatest Common Divisor (GCD) of that row and column. Let us look at some input scenarios − Suppose we are given a 2D matrix of dimensions m*n is; Input: [[3, 2, 1, 4] [7, 6, 2, 8] [14, 20, 25, 17]]; In the above matrix, row 1 gcd(3, 2, 1, 4) = 1 and Column 2 gcd(3, 7, 14) = 1. So element 2 (1st row and 2nd column) becomes the maximum (1, 1) = 1. So on for all elements and our ... Read More

Advertisements