
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

336 Views
Given an array of numbers, we need to find the number of groups of size 2 and 3 that are divisible by 3. We can get the sums of two and three combination numbers and check whether they are divisible by 3 or not.Let's see an example.Inputarr = [1, 2, 3, 4]Output4 There are 4 combinations that are divisible by 3. The combinations are...[1, 2] [2, 4] [1, 2, 3] [2, 3, 4]AlgorithmInitialise the array.Write two loops to get all combinations of size two.Compute the sum of each group.If the sum is divisible by 3, then increment the count.Write three ... Read More

878 Views
The digit 1 represent positive pole whereas 0 represents negative pole.The magnet will have both poles as 10 or 01. A group can be formed with the magnets that attracts each other. The magnets with different pole facing each other will be in the same group.Here, you are given N number of magnets. You need to find out number of groups can be formed with them.Whenever there are two different magnets side by side, there forms a new group. In that case increment the count of the groups.Let's see an example.Inputmagnets = ["10", "01", "01", "01", "10", "01"]Output4 There are ... Read More

625 Views
Let's say you have given a binary string "10011". To make an alternate binary string, we need to flip a minimum of 2 characters as "10101".There are two possibilities for the alternate string. It will start with 0 or 1. We will check for two alternates and count the number of flips required for both.And then return the minimum of both. Let's see an example.Inputbinary = "10011"Output2 If we start the string with 0, then we have to flip 3 times. And if we start the string with 1, then we have to flip 2 times. The minimum is 2.AlgorithmInitialise ... Read More

357 Views
Given a string of digits, we need to find the count of even substrings in it. Let's see an example.Inputnum = "1234"Output6The even substrings that can be formed from the given string are2 12 4 34 234 1234AlgorithmInitialise the string with digits.Initialise the count to 0.Iterate over the string.Get the current digit by subtracting the char 0 from the current char digit.Check whether the digit is even or not.If the current digit is even, then add it's index plus 1 to the count.Return the count.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getEvenSubstringsCount(char str[]) ... Read More

108 Views
You are given the result of the preorder traversal. You need to find the number of elements that are smaller than the root.The first element in the preorder traversal is the root of the BST. Let's see an example.Inputpreorder_result = [5, 4, 2, 1, 7, 6, 8, 9]Output3 There are three elements that are less than the root. The root is 5.AlgorithmInitialise the preorder result in an array.Store the first element i.e.., root of the BST in a variable.Write a loop that iterates from the 2nd element of the preorder result.Compare every element with the root.If the current element is ... Read More

177 Views
You are given a number and subarray lower and upper bound indexes. You need to count a number of elements that are less than or equal to the given number. Let's see an example.Inputarr = [1, 2, 3, 4, 5, 6, 7, 8] k = 4 lower = 0 upper = 5Output4There are 4 elements between the index 0 and 5 that are less than or equal to 4.AlgorithmInitialise the array, number, and subarray indexes.Initialise the count to 0.Write a loop that iterates from the lower index of the subarray to the upper index of the subarray.If the current element ... Read More

149 Views
The modified mean of the matrix is defined as follows...(sum(row-wise min) + sum(column-wise max)) / (row_size + column_size)Let's see an example.1 2 3 4 5 6 7 8 9mean = (sum(1 + 4 + 7) + sum(7 + 8 + 9)) / (3 + 3)We have to find the mean first and then count the number of elements that are greater than mean.If we take the above example, then we will get 3 as the count. There are 3 elements that are greater than the mean which is 6.AlgorithmInitialise the matrix.Find the row-wise minimum elements sum.Find the column-wise maximum elements ... Read More

378 Views
You are given a number in string. You need to find how many digits need to be removed to make it divisible by 3.We make a number divisible by removing at most 2 digits. So, the maximum number of digits to be removed to make it divisible by 3 is 2.Let's see some examples.Input92Output1We can remove 2 to make it divisible by 3.Input999Output0The given number itself is divisible by 3.AlgorithmInitialise the number in string.Find the sum of the number.If the sum is divisible by 3, then return 0.If the sum is not divisible by 3 and the length of the ... Read More

198 Views
We need to find the number of digits in the nth number made of given four digits 1, 2, 3, and 4.The series with the above four digits is as follows1, 2, 3, 4, 11, 12, 13, 14, 21, 22, 23, 24...We need to find the number of digits of the nth number from the above series. If you carefully observe the pattern, you will find the following points.There are 4 numbers with digits 1.There are 16 numbers with digits 2.The pattern continues as the powers of 4.Let's see an exampleInput7Output2 The 7th number in the series is 13 and ... Read More

172 Views
The power of a number can be computed using the iterative multiplication or function that the language provides. It's a straightforward thing.Here, we have to find the a raised to power b. And the number of digits in the result. Let's see some examples.Inputa = 5 b = 2Output2 Inputa = 7 b = 6Output6 AlgorithmInitialise the number a and b.Find the value of ab.The ceil of log10(n) will give you number of digits in the number n.Find it and return it.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getDigitsCount(int a, int b) ... Read More