We are given a total number of steps in a staircase that is n. A person can reach the next floor by skipping 1, 2 or 3 steps at a time. The goal is to find the number of ways in which the next floor can be reached by doing so.We will use the recursive method by keeping in mind that to reach any i’th step, a person has to jump from i-1th step ( skip 1 step) , i-2th step (skip 2 steps ) or i-3th step ( skip 3 steps ).Let’s understand with examples.Input N=3 stepsOutput Count of ways to ... Read More
We are given an input of N points on a 2-D space. The goal is to find the count of triplets of points from the input such that one point is the mid-point on the line between the other two. i.e if triplet is (A, B, C) then B is midpoint of A and C ( or any other combination of A, B, C ).We will do this by inserting all points as pairs into a vector. Then add all pairs from this vector in set. By taking two points from the set check if the sum of (x, ... Read More
We are given a positive integer N. The goal is to count the numbers less than or equal to N that have all 1’s in their binary representation. For example 1 is 1, 3 is 11, 7 is 111, 15 is 1111... so on.If we see the numbers then all of them are 2i-1. Where i start from 1. To check such numbers less than n. We’ll compare if 2i-1
We are given an array Arr[] of positive integers of size N. The goal is to count the number of elements in that array which can be represented as sum of parity primes, that is they can be shown as a sum of the same prime number. Ex; 4= 2+2, 6=3+3 or 2+2+2The sum of any two odd or even prime numbers will always be even. And except 0 and 2 all even numbers can be represented as sum of same primes.Let’s understand with examples.Input Arr[] = { 2, 5, 10, 15, 20, 25 }Output Number which satisfy condition : 3Explanation Numbers as ... Read More
We are given an array Arr[] of positive integers of size N. The goal is to count the number of trailing zeroes present in the product of all elements of the array.We will do this by counting the factors of each number. We will count 2 and 5 as factors of each number as the product of 2 and 5 is 10 which gives 1 trailing 0. In the end whichever count is smaller gives the count of trailing zeroes in the product. If we have 4 2’s and 6 5’s then there will be 4 trailing zeroes in the ... Read More
We are given a positive number N. The goal is to count the number of ways in which the number N can be divided into 3 parts. The parts may or may not be equal. N lies in range [1, 5000].We will do this by using three for loops for 3 parts of the number. Check at the innermost loop that the sum of all three is equal to N. If true, then increment the count of ways.Let’s understand with examples.Input − N=5Output − Number of ways to divide N in 3 parts: 2Explanation − 5 can be shown as ... Read More
We are a number N. The goal is to find numbers between 0 and N whose OR with N is equal to XOR with N.We will do this by traversing no. from i=0 to i
We are a number N. The goal is to find numbers between 0 and N whose difference with N is equal to XOR with N.We will do this by traversing no. from i=0 to i
We are a number X. The goal is to find numbers between 0 and X whose sum with X is equal to XOR with X.We will do this by traversing no. from i=0 to i
We are given an integer N which represents the number of cuts applied on a 2D-circle. Each circle divides the circle in two halves. Goal is to find the pieces of the circle after N cuts.Number of pieces= 2 * no. of cutsLet’s understand with examples.Input − N=1Output − Pieces of circle: 2Explanation −Input − N=3Output − Pieces of circle: 6Explanation −Approach used in the below program is as followsWe take N for a number of cuts.Take pieces=1*N.Print the result..Example#include using namespace std; int main(){ int N=2; Int pieces=2*N; cout
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP