
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
Found 26504 Articles for Server Side Programming

866 Views
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

346 Views
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

365 Views
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

373 Views
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

175 Views
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

558 Views
the fmod()in python implements the math modulo operation. The remainder obtained after the division operation on two operands is known as modulo operation. It is a part of standard library under the math module. In the below examples we will see how the modulo operation gives different out puts under various scenarios.Positive numbersFor positive numbers, the result is the remainder of the operation after the first integer is divided by the second. Interesting the result always comes as a float as we can see from the type of the result.Example Live Demofrom math import fmod print(fmod(6, 7)) print(type(fmod(6, 7))) print(fmod(0, 7)) ... Read More

878 Views
We have usually seen the print command in python printing one line of output. But if we have multiple lines to print, then in this approach multiple print commands need to be written. This can be avoided by using another technique involving the three single quotes as seen below.Example Live Demoprint(''' Motivational Quote : Sometimes later becomes never, Do it now. Great things never come from comfort zones. The harder you work for something, the greater you'll feel when you achieve it. ''') Running the above code gives us the following result:Motivational Quote : Sometimes later becomes never, Do ... Read More

3K+ Views
In Python, a list is a built-in data structure that is used to store an ordered collection of multiple items in a single variable. Lists are mutable that means we can add, remove, and change its elements. In this article, we will learn how we can add the corresponding elements of two Python Lists. You are given two equal sized lists in Python and your task is to create a new list containing sum of corresponding elements of the lists.Consider the following input output scenario:Scenario Input: List1 = [3, 6, 9, 45, 6] List2 = [11, 14, 21, ... Read More

232 Views
Suppose we have an array A[] with n positive elements. We have to create another array B, such that B[i] is XOR of all elements of A[] except A[i]. So if the A = [2, 1, 5, 9], then B = [13, 14, 10, 6]To solve this, at first we have to find the XOR of all elements of A, and store it into variable x, then for each element of A[i], find B[i] = x XOR A[i]Example Live Demo#include using namespace std; void findXOR(int A[], int n) { int x = 0; for (int i = 0; ... Read More

208 Views
Suppose we have an array A[], with n elements. We have to find another array B[], whose size is n+1, such that GCD of B[i] and B[i + 1] is A[i]. If there are multiple solutions, then print one of them whose array sum is minimum. So if A = [1, 2, 3], then output will be [1, 2, 6, 3]When A has only one element say K, then B = [K, K]. So the B[0] will be A[0]. Now consider we are done up to index i, so we have already processed index i, and calculated B[i + 1]. ... Read More