Count Trailing Zeros in Binary Representation of a Number Using Bitset in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:45:13

4K+ Views

Given an integer num as input. The goal is to find the number of trailing zeroes in the binary representation of num using bitset.A bitset stores the bits 0s and 1s in it. It is an array of bits.For ExampleInputnum = 10OutputCount of number of trailing zeros in Binary representation of a number using Bitset are: 1ExplanationThe number 10 in binary is represented as 1010 so trailing zeroes in it is 1.Inputnum = 64OutputCount of number of trailing zeros in Binary representation of a number using Bitset are: 6ExplanationThe number 64 in binary is represented as 10000000 so trailing zeroes ... Read More

Count Number of Trailing Zeros in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:42:46

211 Views

Given an integer num as input. The goal is to find the number of trailing zeroes in the product 11 X 22 X 33 X…X numnum.For ExampleInputnum=5OutputCount of number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*.. are: 5ExplanationThe number of 2s and 5s in the product will be: 11 * 22* 33* 44* 55=11 * 22* 33* (22)4* 55. So total 10 2s and 5 5s, minimum is 5 so trailing zeroes will be 5.Inputnum=10OutputCount of number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*.. are: 5ExplanationThe number of 2s and 5s in the product will be: 11 *22*33*44*55*66 *77*88*99*1010 = 11 *22*33*44*55*66 *77*88*99*(2*5)10. So ... Read More

Set User Defined Variable with Table Name in MySQL Prepare Statement

AmitDiwan
Updated on 05-Jan-2021 06:41:34

2K+ Views

Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20) ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(StudentName) values('David'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(StudentName) values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Mike'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will ... Read More

Count Substrings with Exactly K Distinct Characters in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:39:57

1K+ Views

Given a string str[] containing lowercase alphabets only and an integer value k. The goal is to find the number of possible substrings of str that have exactly k distinct elements.For ExampleInputstr= ”pqr” k=2OutputCount of number of substrings with exactly k distinct characters are: 2ExplanationThe substrings having exactly 2 distinct elements are: “pq”, “qr”.Inputstr= ”stristr” k=4OutputCount of number of substrings with exactly k distinct characters are: 10ExplanationThe substrings having exactly 2 distinct elements are: “stri”, “tris”, “rist”, “istr”, “stris”, “trist”, “ristr”, “strist”, “tristr”, “stristr”.Approach used in the below program is as follows −In this approach we will an array array[26] ... Read More

Executing C Hash Code in Linux

Ajay yadav
Updated on 05-Jan-2021 06:38:26

5K+ Views

The .NET centric applications are meant to windows operating system up till now, but now Microsoft has introduced a new cross-platform application called Mono which enables the execution of the application developed under the .NET platform in Linux environment by giving an impression in such a way that as if we are running Linux package rather than executing .exe file.MonoMono is an open-source utility that allows the developer to execute .NET centric applications on other platforms such as Mac or Linux as it provides an installation package for Windows platform to compile and execute .NET assemblies on Windows OS without ever ... Read More

Count Number of Subsets Whose Median is Present in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:37:47

236 Views

Given an array arr[] containing positive numbers. The goal is to find subsets of elements of arr[] such that the median of values of the subset is also present in that set.For ExampleInputarr[] = { 1, 2, 3 }OutputCount of number of subsets whose median is also present in the same subset are: 4ExplanationThe sets with their medians in that same set are: [ 1 ], median is 1 [ 2 ], median is 2 [ 3 ], median is 3 [ 1, 2, 3 ], median is 2Inputarr[] = { 4, 6, 5 }OutputCount of number of subsets whose ... Read More

Count Number of Subsets with GCD Equal to a Given Number in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:34:41

412 Views

Given an array ar, containing positive numbers and an array GCD[] containing gcd values.The goal is to find the number of subsets of elements of arr[] that have gcd values as given in GCD[].For ExampleInputarr[] = {10, 5, 6, 3}, GCD[] = {2, 3, 5}OutputCount of number of subsets of a set with GCD equal to a given number are: 1 2 2ExplanationThe subsets with GCD equal to 2 is [ 10, 6 ]. Subsets with GCD equal to 3 is [ 3 ], [ 6, 3 ] Subsets with GCD equal to 5 is [ 5 ], [ 10, ... Read More

Count Rectangles with Side Ratio in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:33:03

225 Views

Given sides of rectangles in and range variables first and last. The goal is to find the count of rectangles that have a ratio of their side’s length/breadth lying in the range [ first, last].For ExampleInputrec[] = { { 200, 210 }, { 100, 50 }, { 300, 190}, {180, 200}, {300, 200}} and first = 1.0, last = 1.6OutputCount of number of rectangles such that ratio of sides lies in the range [a, b] are: 4ExplanationThe sides that have ratio in the range [ 1.0, 1.6 ] are : {200, 210}, {300, 190}, {180, 200}, {300, 200}Inputrec[] = { ... Read More

Count Subarrays with Greater Average in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:31:21

208 Views

Given an array arr[ ] of positive integers. The goal is to find the count of subarrays of arr[ ] that have an average of its elements greater than the average of the rest of the elements of arr[ ] that are not present in it.For ExampleInputarr[ ] = { 3, 2, 4 }OutputCount of number of sub-arrays such that the average of elements present in the sub−array is greater than that do not present in the sub−array are: 2ExplanationThe subarrays are − [ 3 ], [ 2 ], [ 4 ], [ 3, 2 ], [ 2, 4 ], ... Read More

Count Vowels in All Substrings of Given String in C++

Sunidhi Bansal
Updated on 05-Jan-2021 06:29:23

468 Views

Given a string str containing English alphabets. The goal is to find the number of vowels occurring in all the substrings of str. If string is “abcde” then substrings will be “a”, “b”, “c”, “d”, “e”, “ab”, “bc”, “cd”, “de”, “abc”, “bcd”, “cde”, “abcd”, “bcde”, “abcde”. The count of vowels in these substrings is 10. (a and e)For ExampleInputstr = ”aloe”OutputCount the number of vowels occurring in all the substrings of given string are: 14ExplanationThe substrings are: “a”, “l”, “o”, “e”, “al”, “lo”, “oe”, “alo”, “loe”, “aloe”. Total vowels in these are: 14Inputstr=”http”OutputCount the number of vowels occurring in all ... Read More

Advertisements