Server Side Programming Articles - Page 2146 of 2650

Minimize ASCII values sum after removing all occurrences of one character in C++

Arnab Chakraborty
Updated on 21-Oct-2019 13:20:09

155 Views

Suppose we have a string. We have to minimize the sum of ASCII values, of each character to the string, after removing every occurrence of a particular character. Suppose a string is given like “hello” the sum of ASCII characters is (104 + 101 + 108 + 108 + 111) = 532. Now check occurrences of each characters.h has occurred one time, so cost is 1 * 104 = 104e has occurred one time, so cost is 1 * 101 = 101l has occurred one time, so cost is 2 * 108 = 216o has occurred one time, so cost ... Read More

Median and Mode using Counting Sort in C++

Arnab Chakraborty
Updated on 21-Oct-2019 13:18:44

400 Views

Consider we have an array of size n, we have to find the Median and Mode using the counting sort technique. This technique is useful, when the array elements are in limited range. Suppose the elements are {1, 1, 1, 2, 7, 1}, then the Mode is 1, and Median is 1.5. Let us see what is Median and what is Mode −Median is the middle number in a sorted list of numbersMode is the element whose occurrences are maximum in the listTo get the Median and Mode, we have to follow these steps −Assume that the size of the ... Read More

MCQ on Memory allocation and compilation process in C

Arnab Chakraborty
Updated on 21-Oct-2019 12:52:48

525 Views

Here we will see some MCQ questions on Memory Allocation and Compilation Processes.Question 1 − What will be the output of the following code − Live Demo#include #include int main() {    union my_union {       int i;       float f;       char c;    };    union my_union* u;    u = (union my_union*)malloc(sizeof(union my_union));    u->f = 20.60f;    printf("%f", u->f); }Options −Garbage Value20.600000Syntax Error20.6ExplanationUsing unions, we can use same memory location to hold multiple type of data. All member of union uses same memory location which has maximum space. Here ... Read More

Maximum Sum SubArray using Divide and Conquer in C++

Ravi Ranjan
Updated on 20-Aug-2025 13:41:56

1K+ Views

In this article, we have an array of integers. Our task is to find the maximum sum of a sub-array using divide and conquer algorithm. A sub-array is a continuous part of an array with consecutive array elements. For example: {2, 3, 4} is sub-array of {1, 2, 3, 4, 5} but {1, 4, 5} is not. What is Divide and Conquer Algorithm? The Divide and Conquer algorithm divides a problem into smaller sub-problems, and then each sub-problem is solved independently. We keep dividing the sub-problems till we reach a stage where no more division ... Read More

Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph in C++

Arnab Chakraborty
Updated on 21-Oct-2019 12:25:24

237 Views

Suppose we have a complete graph; we have to count number of Edge Disjoint Spanning trees. The Edge Disjoint Spanning trees are spanning trees, where no two trees in the set have an edge in common. Suppose the N (number of vertices) is 4, then output will be 2. The complete graph using 4 vertices is like below −Two edge disjoint spanning trees are like −The maximum number of edge disjoint spanning tree from a complete graph, with N vertices will be $[\frac{n}{2}]$Example#include #include using namespace std; int maxEdgeDisjointSpanningTree(int n){    return floor(n/2); } int main() {    int n = 4;    cout

Sorting an array according to another array using pair in STL in C++

Arnab Chakraborty
Updated on 21-Oct-2019 12:20:28

905 Views

Suppose we have two different arrays. We have to sort one array based on the other array using C++ STL pair class. Consider two arrays are like A1 = [2, 1, 5, 4, 9, 3, 6, 7, 10, 8], and another array is like A2 = [A, B, C, D, E, F, G, H, I, J], The output will be like: A1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], A2 = [B, A, F, D, C, G, H, J, E, I]Here we are using the pairs of C++ STL. The pair is formed by taking one ... Read More

Sort the array of strings according to alphabetical order defined by another string in C++

Arnab Chakraborty
Updated on 21-Oct-2019 12:18:01

377 Views

Suppose we have an array of strings, and another string is there for the reference. We have to take the reference string and using the order of the characters in the reference string we will sort the string array. Here we are considering the strings in the array, and the reference string is in lower case letters.Suppose the string array is like: [“hello”, “programming”, “science”, “computer”, “india”], the reference string is like: “pigvxbskyhqzelutoacfjrndmw”, After sorting the output string will be like [“programming”, “india”, “science”, “hello”, “computer”]The task is simple. We have to traverse the reference string, then store the character ... Read More

Sort elements of the array that occurs in between multiples of K in C++

Arnab Chakraborty
Updated on 21-Oct-2019 12:15:15

159 Views

Suppose we have an array A, and another integer K. We have to sort the elements that are in between any two multiples of K. Suppose A is like [2, 13, 3, 1, 21, 7, 8, 13, 12], and K = 2. The output will be [2, 1, 3, 7, 13, 21, 8, 13, 12]. Here multiple of 2 are 2, 8 and 12, the elements in between 2 and 8 are 13, 3, 1, 21, 7, they will be sorted as 1, 3, 7, 13, 21, the elements between 8 and 12 is only 13, so that is already ... Read More

C Program to check if a number is divisible by any of its digits

Sunidhi Bansal
Updated on 21-Oct-2019 11:59:18

2K+ Views

Given a number n, task is to find that any of the digit in the number divides the number completely or not. Like we are given a number 128625 is divisible by 5 which is also present in the number.ExampleInput: 53142 Output: yes Explanation: This number is divisible by 1, 2 and 3 which are the digits of the number Input: 223 Output: No Explanation: The number is not divisible by either 2 or 3The approach used below is as follows −We will start from the unit place and take the unit place’s number.Check whether the number is divisible or ... Read More

C Program for product of array

Sunidhi Bansal
Updated on 21-Oct-2019 11:53:57

10K+ Views

Given an array arr[n] of n number of elements, the task is to find the product of all the elements of that array.Like we have an array arr[7] of 7 elements so its product will be likeExampleInput: arr[] = { 10, 20, 3, 4, 8 } Output: 19200 Explanation: 10 x 20 x 3 x 4 x 8 = 19200 Input: arr[] = { 1, 2, 3, 4, 3, 2, 1 } Output: 144The approach used below is as follows −Take array input.Find its size.Iterate the array and Multiply each element of that arrayShow resultAlgorithmStart In function int prod_mat(int arr[], ... Read More

Advertisements