Problem statementGiven four sides of quadrilateral a, b, c, d, find the maximum area of the quadrilateral possible from the given sides.AlgorithmWe can use below Brahmagupta’s formula to solve this problem −√(s-a)(s-b)(s-c)(s-d)In above formula s is semi-perimeter. It is calculated as follows −S = (a + b + c + d) / 2ExampleLet us now see an example − Live Demo#include using namespace std; double getMaxArea(double a, double b, double c, double d) { double s = (a + b + c + d) / 2; double area = (s - a) * (s - b) * (s ... Read More
Problem statementGiven an array of n positive elements. we need to find the maximum bitwise AND value generated by any pair of element from the array.ExampleIf input array is {10, 12, 15, 18} then maximum value of bitwise AND is 12.AlgorithmThe result of bitwise AND operations on single bit is maximum when both bits are 1. Considering this property −Start from the MSB and check whether we have minimum of two elements of array having set valueIf yes, then that MSB will be part of our solution and be added to result otherwise we will discard that bitSimilarly, iterating from ... Read More
Problem statementGiven a square matrix of order n*n, find the maximum and minimum from the matrixExampleIf given matrix is −{{15, 17, 19}, {5, 1, 7}, {14, 5, 16}} then Minimum number is 1 and maximum number is 19AlgorithmSelect two elements from the matrix one from the start of a row of the matrix another from the end of the same row of the matrixCompare them and next compare smaller of them to the minimum of the matrix and larger of them to the maximum of the matrix.We can see that for two elements we need 3 compare so for traversing ... Read More
Problem statementGiven a number n, the task is to find the maximum 0’s between two immediate 1’s in binary representation of given n. Return -1 if binary representation contains less than two 1’sExampleIf input number is 35 then its binary representation is −00100011In above binary representation there are 3 0’s between two immediate 1’s. Hence answer is 3.AlgorithmWe can use bitwise shift operator to solve this problem. We need to find the position of two immediate 1’s in binary representation of n and maximize the difference of these position.If number is 0 or power of 2 then return -1IInitialize variable ... Read More
Problem statementGiven a minimum heap find maximum element in that.ExampleIf input heap is −Then maximum element is 55AlgorithmIn minimum heap parent node will be lesser than its children. Hence we can conclude that a non-leaf node cannot be the maximum.Search maximum element in the leaf nodesExampleLet us now see an example − Live Demo#include using namespace std; int getMaxElement(int *heap, int n) { int maxVal = heap[n / 2]; for (int i = n / 2 + 1; i < n; ++i) { maxVal = max(maxVal, heap[i]); } return maxVal; } int main() { int heap[] = {15, 27, 22, 35, 29, 55, 48}; int n = sizeof(heap) / sizeof(heap[0]); cout
Problem statementGiven two arrays of equal size N, form maximum number of pairs by using their elements, one from the first array and second from the second array, such that an element from each array is used at-most once and the absolute difference between the selected elements used for forming a pair is less than or equal to a given element K.ExampleIf input is −arr1[] = {3, 4, 5, 2, 1}arr2[] = {6, 5, 4, 7, 15}and k = 3 then we can form following 4 pairs whose absolute difference is less than or equal to 3 −(1, 4), (2, ... Read More
Problem statementGiven an array of N integers, rearrange the array elements such that the next array element is greater than the previous element arr[i+1] > arr[i]ExampleIf input array is {300, 400, 400, 300} then rearranged array will be −{300, 400, 300, 400}. In this solution we get 2 indices with condition arr[i+1] > arr[i]. Hence answer is 2.AlgorithmIf all elements are distinct, then answer is simply n-1 where n is the number of elements in the arrayIf there are repeating elements, then answer is n – maxFrequencyExampleLet us now see an example − Live Demo#include #define MAX 1000 using namespace ... Read More
DescriptionThere is an array of (2 * n – 1) integers. We can change sign of exactly n elements in the array. In other words, we can select exactly n array elements, and multiply each of them by -1. Find the maximum sum of the array.ExampleIf input array is {-2, 100, -3} then we can obtain maximum changing sign of -2 and -3. After changing sign array becomes −{2, 100, 3} and maximum sum of this array is 105.AlgorithmCount negative numbersCalculate the sum of the array by taking absolute values of the numbers.Find the minimum number of the array by ... Read More
Background position is to set the beginning position of a background image. For this, use the background-position property.ExampleLet us now see an example − Live Demo body { background-image: url("https://www.tutorialspoint.com/images/Swift.png"); background-repeat: no-repeat; background-attachment: fixed; color: blue; background-position: left center; } .demo { text-decoration: overline underline; } Details Examination Center near ABC College. Exam begins at 9AM. OutputExampleLet us now see another example − Live Demo body { background-image: url("https://www.tutorialspoint.com/images/Swift.png"); background-repeat: no-repeat; background-attachment: fixed; color: blue; background-position: 50% 50%; } Details Examination Center near ABC College. Exam begins at 9AM. Output
As we know both define() and const are used to declare a constant in PHP script.SyntaxLet's discuss the difference between these two.The basic difference between these two is that const defines constants at compile time, whereas define() defines them at run time.We can't use the const keyword to declare constant in conditional blocks, while with define() we can achieve that.const accepts a static scalar(number, string or other constants like true, false, null, __FILE__), whereas define() takes any expression.consts are always case sensitive, whereas define() allows you to define case insensitive constants by passing true as the third argument.const can also ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP