
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 1339 Articles for C

1K+ Views
We are given a string of alphabets. The array can have at least two occurrences of the same character. The task here is to find the maximum number of characters between any two occurrences of a character. If there is no repetition of any character then return -1.Input − string str = “abcdba”Output −Maximum number of characters between any two same character in a string − 4Explanation − The repeating characters are ‘a’ and ‘b’ only with indexes −1. 2‘a’ first index 0 last 5 , characters in between 5-0-1=4 2. ‘b’ first index 1 last 4 , characters in ... Read More

1K+ Views
We are given a number of chocolates present in consecutive boxes in the form of an array and a number k which represents the number of students among which these chocolates will be distributed. The task here is to choose consecutive boxes such that the sum of chocolates present in them can be equally distributed among k students. Also we have to make sure that the number of chocolates is maximum.For this we will traverse the array from left to right and start adding the number of chocolates and divide the sum by k. If it is fully divided with ... Read More

234 Views
We are given two lockers, say L1 and L2 that have some amount of money in the form of coins. L1 has A coins and L2 has B number of coins in it. We have to withdraw money or coins from the lockers such that the money drawn out is maximum. Each time the coins are drawn from any locker, it is replaced by coins 1 less than its previous count. If we draw A coins from L1 then it will be replaced by A-1 coins and if we draw B coins from L2 then it will be replaced by ... Read More

576 Views
We are given with an array of integers of size N and a number k. The array consists of integers in random order. The task is to find the maximum difference between the group of k-elements and rest of the array. The array will be divided into two parts. The first part is a group of k-elements taken out and the second part is the rest of the elements of the array. We have to select k elements such that the difference between the sum of elements in both groups is maximum.If k is smaller ( half of array size) ... Read More

568 Views
We are given with an array of integers of size N. The array consists of integers in random order. The task is to find the maximum difference between the first and last indexes of an element in the array. We have to find a number which appears twice in the array and the difference between its indexes is maximum. If there are more such pairs then we will store the maximum such difference between the indexes.Input Arr[] = { 2, 1, 3, 1, 3, 2, 5, 5 }.Output −Maximum difference between first and last indexes of an element in array − ... Read More

1K+ Views
We are given with an array of integers of size N. The array consists of integers in random order. The task is to find the maximum difference between two elements such that the larger element appears after the smaller number. That is Arr[j]-Arr[i] is maximum such that j>i.Input Arr[] = { 2, 1, 3, 8, 3, 19, 21}.Output −The maximum difference between two elements such that the larger element appears after the smaller number − 20Explanation − The maximum difference is between 21 and 1 and 21 appears after 1 in the array.Input Arr[] = {18, 2, 8, 1, 2, 3, 2, ... Read More

847 Views
The task is to find the greatest difference between the sum of m elements in an array. Suppose we have an array and a number m, then we will first find the sum of highest m numbers and then subtract the sum of lowest m numbers from it to get the maximum difference. So the main thing is to find two subsets of m numbers which have the highest sum and lowest sum.Let’s now understand what we have to do using an example −Input arr = {1, 2, 3, 4, 5} ; m=3Output Maximum difference here is : 6Explanation − Here the ... Read More

303 Views
We are given a matrix and the task is to find the greatest difference between the sum of elements in two rows of a matrix. Suppose we have a matrix M[i,j] with i rows and j columns. Let the rows be R0 to Ri-1. The difference will be calculated by subtracting the (sum of elements of Ry) - (sum of elements of Rx), where xMD. If it is so, update MD. Else check is RSum[row]

6K+ Views
Given three inputs first one is “a” which is for the first term of geometric series second is “r” which is the common ratio and “n” which are the number of series whose sum we have to find.Geometric series is a series which have a constant ratio between its successive terms. Using the above stated inputs “a”, “r” and “n” we have to find the geometric series i.e., a, ar, 𝑎𝑟2 , 𝑎𝑟3 , 𝑎𝑟4 , … and their sum, i.e., a + ar + 𝑎𝑟2+ 𝑎𝑟3 + 𝑎𝑟4 +…Inputa = 1 r = 0.5 n = 5Output1.937500Inputa = 2 ... Read More

320 Views
Given a number n, the task is to print the triangular patterns of alphabets of the length n. First print the n characters then decrement one from the beginning in each line.The triangular pattern of alphabet will be like in the given figure below −Input − n = 5Output Input − n = 3Output Approach used below is as follows to solve the problemTake input n and loop i from 1 to n.For every i iterate j from i to n for every j print a character subtract 1 and add the value of j to ‘A’ .AlgorithmStart In function int pattern( ... Read More