- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
484 Views
Friendly Numbers − According to number theory, friendly numbers are two or more numbers having the same abundancy index. Abundancy Index − Abundancy index of a natural number can be defined as the ratio between the sum of all the divisors of the natural number and the natural number itself. The abundancy of a number n can be expressed as $\mathrm{\frac{\sigma(n)}{n}}$ where $\mathrm{\sigma(n)}$ denotes the divisor function equal to all the divisors of n. For example, the abundancy index of the natural number 30 is, $$\mathrm{\frac{\sigma(30)}{30}=\frac{1+2+3+5+6+10+15+30}{30}=\frac{72}{30}=\frac{12}{5}}$$ A number n is said to be a ‘friendly number’ if there exists a ... Read More
99 Views
In this problem, we need to find the total number of ‘X’ shapes in the given matrix. We can construct the single ‘X’ shape using 1 or more adjacent ‘X’ elements. We can use the DFS (depth−first search) technique to solve the problem. For each ‘X’ element, we can find all adjacent elements using DFS and count it as a single ‘X’ shape. If we find a new ‘X’, we find its adjacent again. Here, we will use the iterative and recursive DFS to find the total number of ‘X” shapes. Problem statement − We have given a matrix[] of ... Read More
77 Views
A sequence is a collection of objects, and in our case, it is a collection of integers. The task is to find if a sequence with the usage of the addition and subtraction operator within the elements is divisible by M or not. Problem Statement Given an integer M and an array of integers. Using only addition and subtraction between elements check if there is a valid sequence whose solution is divisible by M. Sample Example 1 Input: M = 2, arr = {1, 2, 5} Output: TRUE Explanation − For the given array a valid sequence {1 ... Read More
371 Views
XNOR(Exclusive-NOR) gate is a digital logic gate that takes two inputs and gives one output. Its function is the logical complement of the Exclusive-OR (XOR) gate. The output is TRUE if both inputs are the same and FALSE if the inputs are different. The truth table of the XNOR gate is given below. A B Output 1 1 1 1 0 0 0 1 0 0 0 1 Problem Statement Given two numbers x and y. Find the XNOR of the two numbers. Sample Example 1 Input: x ... Read More
1K+ Views
Quick Sort is a Divide and Conquer algorithm. In this algorithm, we elect a pivot element and then partition the array around the pivot element. The two partitions are such that one part contains elements all lower than the pivot element and the other part contains elements all higher than the pivot element. Similarly, each part is further partitioned around a pivot selected in each part and this process is executed until one single element is reached. Choosing a Pivot A pivot can be chosen in an array as follows − A random pivot. Rightmost or leftmost element as ... Read More
114 Views
Let x and y be two numbers. In this case, x is said to be a divisor of y if when y is divided by x it returns zero remainder. The maximum occurring divisor in an interval is the number that is a divisor of the maximum number of elements of that interval. Problem Statement Given an interval [a, b]. Find the maximum occurring divisor in the range including both a and b, except ‘1’. In case all divisors have equal occurrence, return 1. Sample Example 1 Input [2, 5] Output 2 Explanation − Divisors of 2 = ... Read More
109 Views
Ramanujan-Nagell Equation is an example of the exponential Diophantine equation. The diophantine equation is a polynomial equation with integer coefficients of two or more unknowns. Only integral solutions are required for the Diophantine equation. Ramanujan-Nagell Equation is an equation between a square number and a number that is seven less than the power of 2, where the power of 2 can only be a natural number. Ramanujan conjectured that the diophantine equation 2y - 7 = x2 has positive integral solutions and was later proved by Nagell. $$\mathrm{2y−7=x^2\:has\:x\epsilon\:Z_+:x=1, 3, 5, 11, 181}$$ Triangular Number − It counts objects arranged in ... Read More
405 Views
Tarjan’s algorithm is to locate strongly linked components in a directed graph, Robert Tarjan created the graph traversal technique known as Tarjan's algorithm in 1972. Without going over previously processed nodes, it effectively locates and handles each highly related component using a depth-first search strategy and a stack data structure. The algorithm is often employed in computer science and graph theory and has several uses, including algorithm creation, network analysis, and data mining. Kosaraju’s algorithm consists of two passes over the graph. In the first pass, the graph is traversed in reverse order and a "finish time" is assigned ... Read More
167 Views
In this article, we will explore the problem of finding the longest substring in a given string that contains K distinct vowels. The problem can be solved using different algorithms in C++. This problem is commonly encountered in the field of computer science, particularly in text processing and natural language processing tasks. It tests one's ability to manipulate strings and handle edge cases. Syntax In the realm of C++, the class std::string epitomizes a string datatype. This versatile entity enables storage and manipulation of character sequences. The template class std::vector embodies a dynamic array, granting the ability to resize arrays ... Read More
152 Views
String manipulation is an essential skill in programming, as it helps us process and analyze text data efficiently. C++ provides a rich set of string manipulation functions and objects, making it easier to work with text data. In this article, we will discuss how to reverse a string according to the number of words in C++. Approaches Approach 1 − Using stringstreams and vectors Approach 2 − Using substrings and string manipulation functions Syntax String object in C++: The std::string class is a part of the C++ Standard Library and provides various string manipulation functions. String manipulation functions: ... Read More