Hafeezul Kareem has Published 380 Answers

Number of groups of magnets formed from N magnets in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 12:12:09

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 ... Read More

Number of flips to make binary string alternate - Set 1 in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 12:05:56

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 ... Read More

Number of even substrings in a string of digits in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 10:33:29

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 ... Read More

Number of elements smaller than root using preorder traversal of a BST in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 08:05:56

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 ... Read More

Number of elements less than or equal to a given number in a given subarray in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 07:52:26

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 ... Read More

Number of elements greater than modified mean in matrix in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 07:20:06

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 ... Read More

Number of digits to be removed to make a number divisible by 3 in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 07:11:56

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 ... Read More

Number of digits in the nth number made of given four digits in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 07:00:47

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 ... Read More

Number of Digits in a^b in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 06:53:53

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 ... Read More

Number of digits in 2 raised to power n in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 06:38:43

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 2 raised to power n. And the number of digits in the result. Let's see some examples.Input5Output2Input10Output4 AlgorithmInitialise the number n.Find the value ... Read More

Advertisements