Server Side Programming Articles - Page 1433 of 2650

Count subsets having distinct even numbers in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:16:00

270 Views

We are given an array of positive integers. The goal is to find the subsets of numbers in an array such that each subset has distinct even numbers in it. All sets with the same elements will be counted as 1. [2, 4, 6] and [6, 2, 4] are the same set.Let us understand with examplesInput − arr[] = {1, 3, 5, 7, 8, 3, 2 };Output −Count of subsets having distinct even numbers are − 3Explanation − Subsets will be − [2], [8], [2, 8]Input − arr[] = {2, 4, 6 };Output −Count of subsets having distinct even numbers ... Read More

Count substrings that starts with character X and ends with character Y in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:14:35

476 Views

We are given string str. The goal is to count the number of substrings in str that have starting character same as character X and ending character same as character Y. For example, if input is “artact” and X=’a’ and Y=’t’, the substrings will be “art”, “act”, “artact”. The count is 3.Let us understand with examples.Input − str=”abcccdef” X=’a’ Y=’c’Output −Count of substrings that starts with character X and ends with Y is − 3Explanation − Substrings will be“abc”, “abcc”, “abccc”. Total 3.Input − str=”tempest” X=’t’ Y=’t’Output − Count of substrings that starts with character X and ends with Y ... Read More

Count substrings with each character occurring at most k times in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:12:50

355 Views

We are given a string str. The goal is to count the number of substrings in str that have each character occurring utmost k times. For example if input is “abc” and k=1, the substrings will be “a”, “b”, “c”, “ab”, “bc”, “abc”.Let us understand with examples.Input − str=”abaefgf”Output − Count of substrings with same first and last characters are &mmius; 9Explanation − Substrings will be“a”, “b”, “a”, “e” ,”f”, “g”, “f”, “aba”, “fgf”. Total 9.Input − str=”abcdef”Output − Count of substrings with same first and last characters are: 6Explanation − Substrings will be -“a” , “b” , “c”, “d”, ... Read More

Count substrings with same first and last characters in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:10:08

553 Views

We are given a string str. The goal is to count the number of substrings in str that have the same starting and ending character. For example, if input is “baca” substrings will be “b”, “a”, “c”, “a”, “aca”. Total 5.Let us understand with examples.Input − str=”abaefgf”Output −Count of substrings with same first and last characters are: 9Explanation − Substrings will be“a”, “b”, “a”, “e” ,”f”, “g”, “f”, “aba”, “fgf”. Total 9.Input − str=”abcdef”Output −Count of substrings with same first and last characters are: 6Explanation − Substrings will be −“a” , “b” , “c”, “d”, “e” ,”f”. Total 6The approach ... Read More

Count Substrings with equal number of 0s, 1s and 2s in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:07:16

428 Views

We are given string str containing 0’s, 1’s, and 2’s only. The goal is to find all substrings of str that have equal numbers of 0’s 1’s and 2’s. If str is “12012”. Substrings with equal 0’s, 1’s, and 2’s will be “120”, “201” and “012”. The count will be 3.Let us understand with examples.Input − str=”112200120”Output −Count of Substrings with an equal number of 0s, 1s, and 2s are − 5Explanation − Substrings will bestr[0-5]=”112200”, str[1-6]=”122001”, str[5-7]=”012”, str[6-8]=”120”, str[7-0]=”201”Input − str=”12012”Output −Count of Substrings with an equal number of 0s, 1s, and 2s are: 3Explanation − Substrings will be ... Read More

Count occurrences of a string that can be constructed from another given string in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:05:26

237 Views

We are given with two strings str_1 and str_2 as input. The goal is to find the count of strings same as str_2 that can be constructed using letters picked from str_1 from which each character is used just once.Note − All alphabets in both are in the same case.Let us understand with examples.Input − str_1 = "abcaaaabca", str_2 = "bca";Output − Count occurrences of a string that can be constructed from another given string are: 2Explanation − Substrings bca in str_a −str_1[1-3]=”bca” and str[7-9]=”bca”Input − str_1 = "about", str_2 = "cout";Output − Count occurrences of a string that can ... Read More

Count Numbers with N digits which consists of odd number of 0's in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:04:40

324 Views

We are given a number N as input. The goal is to find all N digit numbers that have an odd number of 0’s as digits. The number also could have preceding zeros like in case of N=3 numbers included will be 000, 011, 012….990.Let us understand with examples.Input − N=3Output − Count of no. with N digits which consists of even number of 0's are − 244Explanation − All 3 digit numbers would be like −Smallest will be 000, then 011, 012, 013, 0014…..Highest will be 990.Input − N=5Output − Count of no. with N digits which consists of ... Read More

Count Numbers with N digits which consists of even number of 0's in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:02:25

198 Views

We are given a number N as input. The goal is to find all N digit numbers that have an even number of 0’s as digits. The number also could have preceding zeros like in case of N=3 numbers included will be 001, 002, 003….010….so on.Let us understand with examples.Input − N=4Output − Count of no. with N digits which consists of even number of 0's are − 7047Explanation − All 4 digits numbers would be like −Smallest will be 0000, then 0011, 0012, 0013, 0014…..Highest will be 9900.Input − N=5Output − Count of no. with N digits which consists ... Read More

Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B in C++

Sunidhi Bansal
Updated on 01-Dec-2020 12:01:08

706 Views

We are given an input N. The goal is to find all pairs of A, B such that 1

Program to convert a string to zigzag string of line count k in python

Arnab Chakraborty
Updated on 26-Nov-2020 08:34:06

367 Views

Suppose we have a string s and another value k, We have to find a new string by taking each character from s and starting diagonally from top left to bottom right until reaching the kth line, then go up to top right, and so on.So, if the input is like s = "ilovepythonprogramming" k = 5, then the output will beTo solve this, we will follow these steps:line := a new mapcnt := 0delta := 1for each index i and character c in s, doinsert (c, i) at the end of line[cnt]cnt := cnt + deltaif cnt is same ... Read More

Advertisements