Arnab Chakraborty has Published 4293 Articles

Find n-th element from Stern’s Diatomic Series in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:31:16

154 Views

Here we will see how to find the nth term in Stern’s Diatomic series. The series is like 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, … This is also known as fusc function. This series can be defined as βˆ’π‘(𝑛)=$p\lgroup\frac{n}{2}\rgroup$ π‘€β„Žπ‘’π‘› ... Read More

Find N integers with given difference between product and sum in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:21:28

174 Views

Suppose we have two integers N and D. We have to find a set of N integers, where the difference between their sum and product is the same as D. Suppose the N = 3, and D = 5, then the output will be 1, 2, 8. Here the sum ... Read More

Find multiple of x closest to or a ^ b (a raised to power b) in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:19:15

235 Views

Suppose we have three values, a, b and x. We have to find one multiple of x, that is nearest to ab. Suppose the numbers are x = 4, a = 3, b = 3, then the output will be 28, as this is nearest to 33 = 27The approach ... Read More

Find minimum positive integer x such that a(x^2) + b(x) + c >= k in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:14:25

311 Views

Suppose we have four integers a, b, c and k. We have to find the minimum positive value x, such that the following equation satisfies βˆ’π‘Žπ‘₯2+𝑏π‘₯+𝑐 β‰₯π‘˜If a = 3, b = 4, c = 5 and k = 6, then output will be 1To solve this, we will use ... Read More

Find minimum difference between any two element in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:12:02

737 Views

Suppose we have an array of n elements called A. We have to find the minimum difference between any two elements in that array. Suppose the A = [30, 5, 20, 9], then the result will be 4. this is the minimum distance of elements 5 and 9.To solve this ... Read More

Find maximum product of digits among numbers less than or equal to N in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:10:25

450 Views

Suppose, we have one integer N > 0. The task is to find the maximum product of digits among numbers less than or equal to N. If the N is 390, then the result is 216, as the number 389 is making maximum product 3 * 8 * 9 = ... Read More

Find maximum level product in Binary Tree in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:07:25

152 Views

Suppose, one binary tree is given. It has positive and negative nodes. We have to find the maximum product at each level of it.Consider this is the tree, so the product of level 0 is 4, product of level 1 is 2 * -5 = -10, and product of level ... Read More

Find longest sequence of 1’s in binary representation with one flip in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:04:04

2K+ Views

Suppose we have one integer n. Inside that, we can make the one-bit flip to generate the longest sequence of 1s. Suppose the number is 13, so binary representation is 1101. If we make a one-bit flip as make 0 to 1, it will be 1111. This is the longest ... Read More

Find Length of a Linked List (Iterative and Recursive) in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 10:01:36

742 Views

Here we will see how to find the length of a linked list using iterative and recursive approaches. If the head pointer is given, we have to follow these steps to get the length.For iterative approach βˆ’Take the head of the list, until the current pointer is not null, go ... Read More

Find last k digits in product of an array numbers in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 19-Dec-2019 09:58:48

163 Views

Suppose we have an array of n elements called A. We have another number k. Our task is to find last k digits of the product of elements in the array A. Suppose the A = [15, 22, 13, 19, 17], then the product is 1385670, the last k = ... Read More

Advertisements