Arnab Chakraborty has Published 4293 Articles

Program to find number of nodes in a range in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:51:34

915 Views

Suppose we have a BST, and we also have left and right bounds l and r, we have to find the count of all nodes in root whose values are present in between l and r (inclusive).So, if the input is likel = 7, r = 13, then the output ... Read More

Program to find number of bit 1 in the given number in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:50:37

131 Views

Suppose we have a number n, we have to find the number of bit 1 present in the binary representation of that number.So, if the input is like 12, then the output will be 2To solve this, we will follow these steps −count := 0while n is non-zero, docount := ... Read More

Program to find Nth Fibonacci Number in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:49:29

562 Views

Suppose we have a number n, we have to find the nth Fibonacci term. As we know the ith Fibonacci term f(i) = f(i-1) + f(i-2), the first two terms are 0, 1.So, if the input is like 15, then the output will be 610To solve this, we will follow ... Read More

Program to find number of ways to arrange n rooks so that they cannot attack each other in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:47:26

401 Views

Suppose we have a number n representing a chessboard of size n x n. We have to find the number of ways we can place n rooks, such that they cannot attack each other. Here two ways will be considered different if in one of the ways, some cell of ... Read More

Program to check whether given number is Narcissistic number or not in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:44:09

820 Views

Suppose we have a number n; we have to check whether it is equal to the sum of the digits of n to the power of the number of digits.So, if the input is like 9474, then the output will be True as 9^4 + 4^4 + 7^4 + 4^4 ... Read More

Program to sort all even and odd numbers in increasing and decreasing order respectively in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:38:27

3K+ Views

Suppose we have a list of numbers called nums, we have to sort the array by maintaining following criteriaEven numbers are sorted in ascending orderOdd numbers are sorted in descending orderThe relative positions of the even and odd numbers should not be changed.So, if the input is like [9, 14, ... Read More

Program to find length of contiguous strictly increasing sublist in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:37:26

215 Views

Suppose we have a list of numbers called nums, we have to find the maximum length of a contiguous strictly increasing sublist when we can remove one or zero elements from the list.So, if the input is like nums = [30, 11, 12, 13, 14, 15, 18, 17, 32], then ... Read More

Program to find all missing numbers from 1 to N in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:36:12

2K+ Views

Suppose we have a list of numbers called nums of size n where all numbers in the list are present in the interval [1, n] some elements may appear twice while others only once. We have to find all of the numbers from [1, n] such that they are not ... Read More

Program to find an element in list whose value is same as its frequency in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:34:55

198 Views

Suppose we have a list of numbers called nums, we have to check whether there is an element whose frequency in the list is same as its value or not.So, if the input is like [2, 4, 8, 10, 4, 4, 4], then the output will be TrueTo solve this, ... Read More

Program to find the minimum cost to arrange the numbers in ascending or descending order in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 06-Oct-2020 06:32:43

865 Views

Suppose we have a list of numbers called nums, we have to find the minimum cost to sort the list in any order (Ascending or Descending). Here the cost is the sum of differences between any element's old and new value.So, if the input is like [2, 5, 4], then ... Read More

Advertisements