- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 7347 Articles for C++
![Sunidhi Bansal](https://www.tutorialspoint.com/assets/profiles/124656/profile/60_131452-1581053210.jpg)
114 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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
234 Views
Suppose we have a number n; we have to find the nth ugly number. As we know that the ugly numbers are those numbers, whose prime factors are only 2, 3 and 5. So if we want to find 10th ugly number, the output will be 12, as the first few ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 and so on.To solve this, we will follow these steps:Define an array v of size(n + 1)if n is same as 1, then:return 1two := 2, three := 3, five := 5twoIdx := 2, threeIdx := 2, fiveIdx := 2for initialize i := 2, when i
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
161 Views
Suppose we have two sorted lists. We have to find the median of these two lists. So if the arrays are like [1,5,8] and [2,3,6,9], then the answer will be 5.To solve this, we will follow these steps:Define a function solve(), this will take an array nums1, an array nums2,if size of nums1 > size of nums2, then:return solve(nums2, nums1)x := size of nums1, y := size of nums2low := 0, high := xtotalLength := x + ywhile low
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
304 Views
Suppose we have a number n, we have to find the number of lists of positive consecutive values that sum up to n.So, if the input is like n = 15, then the output will be 4, as The possible lists are: [1, 2, 3, 4, 5], [4, 5, 6], [7, 8], and [15].To solve this, we will follow these steps:begin := 1, end := 1, x := (n + 1)sum := 0while end = n, do:if sum is same as n, then:(increase count by 1)sum := sum - begin(increase begin by 1)(increase end by 1)return count + 1Let us ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
159 Views
Suppose we have a picture consisting of black and white pixels, we have to find the number of black lonely pixels. Here the picture is represented by a 2D char array consisting of 'B' and 'W', for the black and white pixels respectively.A black lonely pixel is actually 'B' that located at a specific position where the same row and same column don't have any other black pixels.If the input is like −WWBWBWBWWOutput will be 3. Because all the three 'B's are black lonely pixels.To solve this, we will follow these steps −n := size of picturem := (if n ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
306 Views
Suppose we have a node in a binary search tree, we have to find the in-order successor of that node in the BST. If there is no in-order successor, return null. As we know that the successor of a node is the node with the smallest key greater than value of node.We will have direct access to the node but not to the root of the tree. Here each node will have a reference to its parent node. Below is the definition for Node −class Node { public int val; public Node left; public Node right; ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
432 Views
Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We have to start position of ball, the destination and the maze, we have to find the shortest distance for the ball to stop at the destination. Here the distance is actually defined by the number of empty cells, that are covered by the ball (Excluding start position, including starting position). ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
3K+ Views
Suppose there is a ball in a maze with empty spaces and walls. Now the ball can go through empty paths by rolling any direction like up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next direction.We have to start position of ball, the destination and the maze, we have to check whether the ball could stop at the destination. The maze is represented by one 2D array. Here 1 indicates the wall and 0 indicates the empty space. The borders of the maze are all walls. ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
1K+ Views
Suppose we have a binary array; we have to find the maximum number of consecutive 1s in this array if we can flip at most one 0.So, if the input is like [1, 0, 1, 1, 0], then the output will be 4 because if we flip the first zero will get the maximum number of consecutive 1s. After flipping, the maximum number of consecutive 1s is 4.To solve this, we will follow these steps −ret := 1, n := size of numsif not n is non-zero, then −return 0j := 0, zero := 0for initialize i := 0, when ... Read More