Count Identical Digits in Digital Clock using C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:29:04

392 Views

Suppose we have a digital clock of type HH:MM. Which shows the time in hours and minutes only. We are given a number of hours and minutes as input. The goal is to count the number of times all digits are the same. H=M.This happens 3 times a day, first at 00:00 midnight, then at 11:11 and last at 22:22. As time is represented in 24 hour format.InputInput: 12 hours 22 minutes.Output2Explanation − For times 00:00 and 11:11. Twice in 12 hours.InputInput: 48 hours 22 minutes.Output5Explanation − For times 00:00 and 11:11, 22:22 .Approach used in the below program is ... Read More

Count Binary Strings with k Adjacent Set Bits in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:27:51

453 Views

We are given with integers N and K. We have binary strings of length N, containing 0’s and 1’s only. The goal is to find the number of such strings of length N that have K consecutive 1’s. I.e, if N=3, and K=2, then count all 3-digit binary strings possible that have 2 consecutive 1’s.Example − 111, here adjacent 1’s appear twice ( K times ).In 011 and 110 adjacent 1’s appeared once only.We will solve this by storing the results of previous values.Taking 3D array count[x][y][z]. Where x is N, y is K and z is last digit of ... Read More

Conventional Computing vs Quantum Computing in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:25:55

831 Views

As the computing world is constantly improvising. Everyday a new device comes into picture which makes previous versions unfit for current technological changes and development. Gone are the days when computers were room sized and calculations take hours.From vacuum tubes, transistors and integrated circuits to touch screen devices, the technological advancement has changed the computing methods as well. The programming styles for new devices have also changed. Traditional ways of writing programs don’t work for them. The software embedded needs to be efficient, more responsive and interactive.The basic difference is revolutionized hardware devices that are faster, less heat emissions and ... Read More

Getting Started with Contributing to Open Source in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:24:04

777 Views

What is an Open Source?Open Source is the term generally referred to as Open Source Software (OSS) in the software world. An OSS is generally the one which is freely available on the internet, to use, modify, test, and develop further accordingly. OSS is more convenient to use by various users across the world as it is modifiable in nature. Users have the choice of adding or removing software patches to it according to their requirements.It has drastically changed the software world for the benefit of programmers, developers, testers who try their hands on by contributing to open source.Why contribute ... Read More

Count BST Subtrees That Lie in Given Range in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:20:22

310 Views

We are given a Binary search tree as an input. The goal is to find the count of subtrees in BST which have node values in between the range of start and end. If start is 5 and end is 50. Then count subtrees in BST whose all nodes have weights >=5 and right = insert(70); ) and to the left of root ( root->left = insert(30); ).Variables l and h are used to store minimum and maximum value of a range.Variable count stores the count of BST’s inside the tree that are in range between l and h. Initially ... Read More

Count Distinct Points Visited on the Number Line in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:16:25

207 Views

We are given a binary sequence of 0’s and 1’s. Also assume a person is sitting at a position or point stored in current_pos. Now starting from current_pos, if the binary sequence has 0 then he moves one step left ( current_pos - 1). If it’s 1 he moves one step right ( current_pos + 1). The goal is to find distinct positions or points he visited after the whole binary sequence is completed.We will solve this using the number of times a point is visited. If frequency is non-zero, increase count of distinct points.InputPath[]= “001100” current_pos=3OutputDistinct points visited on ... Read More

Count Distinct Non-Negative Integer Pairs in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:13:34

461 Views

We are given a positive integer N. The goal is to count the pairs of distinct non-negative positive integers that satisfy the inequality: x*x + y*y < NWe will start from x=0 to x2 < N and y=0 to y2 < N . If any x2 + y2 < N, increase count of pairs.Inputn=4Outputdistinct pairs= 4Explanation − pairs will be (0, 0), (1, 1), (0, 1), (1, 0). All these satisfy the inequality x2 + y2 < 4Inputn=2Outputdistinct pairs= 3Explanation − pairs will be (0, 0), (0, 1), (1, 0). All these satisfy the inequality x2 + y2 < 2Approach ... Read More

Maximise Number of Toys Purchasable with Amount K in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:10:58

2K+ Views

We are given with the prices of toys in the form of an array and an amount K in hand. The goal is to purchase the maximum no. of toys with that amount. Each element of the array is a price of a single toy, so no. of toys is no. of elements. We will sort the array of prices in ascending order so that maximum toys of less prices can be purchased first followed by costly toys.Inputtoyprices[]= { 10, 20, 12, 15, 50, 30 } K=50OutputMaximum no. of toys that can be purchased : 3Explanation − Sorting prices of ... Read More

Maximum and Minimum Isolated Vertices in a Graph in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:10:08

523 Views

We are given with the number of edges Noe and number of vertices Nov. The goal is to find the minimum and maximum number of isolated vertices that are possible in such graphs which have no edges and No vertices count.An isolated vertex is the one that has no edge connected to it.For minimum isolated verticesWe will make sure that every edge is isolated. ( No two edges have common vertices ) Each edge requires only 2 vertices. So ,count of non isolated vertices = 2 * no. of edgescount of isolated vertices = total vertices - count of non ... Read More

Container With Most Water in C++

Sunidhi Bansal
Updated on 03-Aug-2020 10:06:57

288 Views

We are given an array of height of the walls of the container. The goal is to find the container that can contain the maximum volume of water. As heights of walls are elements of an array, the distance between them is considered as width between two walls. For example walls of height Arr[i] and Arr[j] have j-i width between them ( 0

Advertisements