Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2198 of 2650
3K+ Views
In this problem, you are given an integer array arr of size n and an integer S. Your task is to find an element k in the array such that if all the elements greater than k in the array are replaced with k, then the sum of all the elements of the resultant array becomes equal to S. If such an element exists, print it; otherwise, print -1. Scenario 1: Input: int S = 9; int arr[] = { 1, 3, 2, 5, 8 }; Output: ... Read More
168 Views
Here we will see one problem, suppose one array is given. There are n elements. We have to find one index, where frequency of even numbers of its left and the frequency of even numbers of its right side are same, or the frequency of odd numbers of its left is same as the frequency of odd numbers of its right. If no such result is there, return -1.Suppose the array is like {4, 3, 2, 1, 2, 4}. The output is 2. The element at index 2 is 2, there is only one odd number at left of it, ... Read More
717 Views
The C++ STL or Standard Template Library is a collection of general-purpose classes and functions with templates for implementing many algorithms and data structures such as vectors, lists, queues, and stacks. The 4 components of STL are: Containers, Algorithms, Iterators, and Functors. In this article, we will discuss the functions of the header that work on arrays, and are introduced in C++ 11 and later versions. C++ Header The algorithm header provides various built-in functions that implement algorithms such as searching, sorting, finding the maximum element, etc. These functions perform various operations on containers such ... Read More
403 Views
In this problem, our task is to find the area of the largest triangle that can be inscribed in a regular hexagon. Each side of the hexagon and triangle is of length a and b, respectively. Area of the Largest Triangle Inscribed in a Hexagon You can calculate the area of the largest triangle inscribed in a regular hexagon using the following formula: $$ Area\ of\ triangle\ inside\ hexagon\ = \frac{3\sqrt{3}}{4} \cdot a^2 $$ Derivation The first step is to establish a relation between a and b, as the value of a(side of the hexagon) is ... Read More
135 Views
Here we will see the area of largest square that can be inscribed in an ellipse. The square in ellipse will be like below −The area of ellipse is −Now, if x and y are same, thenSo area is −Example#include #include using namespace std; float area(float a, float b) { if (a < 0 || b < 0 ) //if values are is negative it is invalid return -1; float area = (4*(a*a + b*b)) / (a*a*b*b); return area; } int main() { float a = 4, b = 2; cout
159 Views
Here we will see how to get the area of the circumcircle of any triangle whose sides are given. Here the side AB is a, BC is b and CA is c, the radius is ‘r’.The radius r is same as −Example#include #include using namespace std; float area(float a, float b, float c) { if (a < 0 || b < 0 || c < 0) //if values are is negative it is invalid return -1; float s = (a + b + c) /2; float triangle = sqrt(s * (s - ... Read More
456 Views
Unique Triplets that Sum up to a Given Value In this article, we will discuss different approaches to find all the unique triplets that sum up to the given value. Before that, first understand the given problem. We have been given an integer array with N elements, along with a target value. Our task is to find unique or distinct triplets (i.e., three numbers) from an array, whose sum is the same as the target value. Let's take a scenario to understand the problem in a better way: Scenario 1 Input: arr ={1, 2, 3, 4, 5, 6, 7} ... Read More
441 Views
In C++, both arrays and vectors are used to store elements, but the main difference is that arrays have a fixed size and cannot be changed once initialized. Whereas, vectors are dynamic, i., e we can change their size during runtime. In this article, we'll look at the advantages of using vectors over arrays in C++. Here's how we declare an array and a vector in C++: // Declaring an array int arr[5]; // Fixed-size array of 5 integers // Declaring a vector #include std::vector vec; // Dynamic vector of integers Advantages of ... Read More
944 Views
Here we will see how to perform the matrix addition and subtraction using multithreaded environment. The pthread is used to execute multiple threads simultaneously in C or C++.There are two matrices A and B. Order of each matrix is (m x n). Each thread will take each row, and perform addition or subtraction. So for m rows, there are m different threads.Example#include #include #include #include #define CORE 3 #define MAX 3 using namespace std; int AMat[MAX][MAX] = {{10, 20, 30}, {40, 50, 60}, {70, 80, 50} }; int BMat[MAX][MAX] = {{80, 60, 20}, {30, ... Read More
180 Views
Here we will see how to get the sum of the series with n-th term as n2 – (n-1)2. The recurrence relation is like below −Tn = n2 − (n−1)2So the series is −We need to find S mod (109 + 7), where S is the sum of all terms of the given series.Example#include #define X 1000000007 using namespace std; long long getSum(long long n) { return ((n % X) * (n % X)) % X; } int main() { long long n = 56789; cout