C++ Articles

Page 351 of 597

Java program for minimum move to end operations to make all strings equal

Shubham Vora
Shubham Vora
Updated on 14-Nov-2024 299 Views

In this article, we will learn how to solve a problem where we are given an array of strings, and we need to make all strings equal by rotating them. This can be done by performing left rotations on the strings. We need to count the minimum number of operations required to do this. If it is impossible to make the strings equal, the output should be -1. Problem statement We have given an array containing n strings. All strings are permutations of each other. We need to count the total number of minimum operations required to make all strings ...

Read More

Check if a given String is palindrome using two pointer in C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 13-Nov-2024 14K+ Views

A palindrome is a word, phrase, number, or other sequence of characters that reads the same from both backward and forward sides. In strings, the palindrome strings are those strings that can be read the same from both left and right sides. In this article, we are going to learn how we can check if a given string is palindrome or not using the two-pointer technique in C++. Problem We are given a string, and we have to check if it is palindrome or not using the two-pointer method in C++. Example 1 ...

Read More

Number of pairs with maximum sum in C++

Aishwarya Naglot
Aishwarya Naglot
Updated on 12-Nov-2024 600 Views

We need to find a number of all the pairs that has the maximum sum, In a given array of integers. A pair consists of two numbers, and the sum is simply the result of adding them. We will see multiple solutions to this problem, starting with a naive (brute force) approach and moving to more optimized solutions. Below is the list of approaches we will cover in this article: Brute Force approach using two loops Max Sum Pairs with Sorting ...

Read More

Natural Numbers in C++ Program

Aishwarya Naglot
Aishwarya Naglot
Updated on 11-Nov-2024 4K+ Views

In this article, we will cover C++ programs to work with natural numbers. we use natural numbers in various operations, such as indexing arrays, performing loops, and validating user input. we will also write code to demonstrate how natural numbers can be used for these purposes in C++. Natural Numbers are a set of positive numbers, starting from 1 and going to infinity. natural numbers are: 1, 2, 3, 4, 5... etc In C++, understand concepts like conditions, loops, and how we store and manipulate variables. We will provide everything you need to know about natural numbers along with programs. ...

Read More

Nearest 1 in a binary matrix in C++

Aishwarya Naglot
Aishwarya Naglot
Updated on 05-Nov-2024 273 Views

In this article, we will show you how to find the minimum distance from each cell in a binary matrix to the nearest cell that contains the digit 1. We will see brute force as well as optimized approaches. Problem Statement Given a binary matrix, our task is to calculate the minimum distance for each cell to the nearest cell that contains the value 1, and if the current cell itself has 1 as a value, the distance will be 0. If the input matrix is as follows - 0 0 1 1 1 0 0 0 0 The ...

Read More

Longest double string of a Palindrome

Aishwarya Naglot
Aishwarya Naglot
Updated on 05-Nov-2024 177 Views

A contiguous sequence of characters, consisting of uppercase, lowercase, repetitive, or unique alphanumeric characters, forms a C++ string. Each string has a unique length, which may be either odd or even in nature. Longest Double String of a Palindrome A Palindromic string is a sequence of characters that reads the same from both the beginning and the end. In other words, characters at equivalent positions from the start and end have no difference. These palindromes can either have an even length or an odd length. The odd-length palindrome features a middle character separating the two equivalent halves. In this article, ...

Read More

Clear bit ranges in given number in C++

C++
Jiya Garg
Jiya Garg
Updated on 02-Sep-2024 452 Views

Given a number n, write C++ program to clear bits in the given range between l and r. Where, 1

Read More

How to sum up elements of a C++ vector?

Vishesh Raina
Vishesh Raina
Updated on 01-Aug-2024 28K+ Views

In this article, we will understand how to sum the elements present inside a vector in C++. A vector is a dynamically allocated array with variable size. The sum of elements of a vector can be calculated in a number of ways, and we will discuss two such ways. Problem Statement Given a non-empty vector of integers, calculate the sum of all elements of the vector using multiple approaches in C++. Examples The following examples give the input and output of some test cases : Input vector vec={1, 3, 4, 5, 2, 3} Output ...

Read More

Containers in C++ STL

sudhir sharma
sudhir sharma
Updated on 29-May-2024 1K+ Views

The C++ STL (Standard Template Library) is a powerful set of C++ template classes to provide general-purpose classes and functions with templates that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, and stacks.It is a library of container classes, algorithms, and iterators. It is a generalized library and so, its components are parameterized. Working knowledge of template classes is a prerequisite for working with STL.Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different ...

Read More

Maximum Sum Decreasing Subsequence in C++

Revathi Satya
Revathi Satya
Updated on 22-May-2024 461 Views

In this article, we are given an array arr[] of N integers. Our task is to find the Maximum Sum Decreasing Subsequence in C++. A Maximum Sum Decreasing Subsequence (MSDS) is a subsequence of a given sequence of array. Here the sequence elements are ordered in decreasing arrangement and the sum of these elements is the highest. Here, given a sequence of array a1, a2, …, an, the goal is to find a subsequence ai1, ai2, …, aik, where i1>i2>…>i1, such that we say the subsequence is ai1>ai2>…>aik (ordered in a decreasing order). The sequence of terms ai1+(ai2)...+(aik) is ...

Read More
Showing 3501–3510 of 5,962 articles
« Prev 1 349 350 351 352 353 597 Next »
Advertisements