Found 1862 Articles for Data Structure

Compute power of power k times % m

Simran Kumari
Updated on 23-Mar-2023 14:29:30

105 Views

Our objective to compute power of power k time % m, with the values of base, k and m provided as input − Look at the image above. Have you ever tried to compute such a problem? Let’s try it. Compute the power of power k times and then find modulo with m. Explanation In this question, x, k, and m are given. Compute ${x^{x{^x{^{^.{^{^.{^{^.}}}}}}}}}$ up to k times and then modulo with m. Let’s understand with an example. Given, x = 2, k = 4, and m = 6 So, Compute $2^{2^{2{^2}}}\:=\:4^{2{^2}}\:=\:16^2\:=\:256$ Then 256 % 6 ... Read More

Check whether an array can fit into another array by rearranging the elements in the array

Simran Kumari
Updated on 23-Mar-2023 14:27:13

241 Views

From the problem statement, we can understand that given two arrays, we have to check whether the first array can fit into the second array. In the real world, there are many instances where we need to check whether an array can fit into another array by rearranging the elements in the array. For a variety of reasons, programmers may need to reorder the items of an array to see if they can fit into another array. Memory management in computer programming is one such reason. When working with huge amounts of data, it is frequently more effective to use ... Read More

Stormer Numbers

Rinish Patidar
Updated on 14-Mar-2023 15:07:04

202 Views

For N to be a stormer number, the highest prime factor of the expression N^2+1 must be greater than or equal to 2*N and it should be a positive integer. For example, 4 is a stormer number. Since 4*4+1=17 has the greatest prime factor 17 itself which is greater than 8 i.e. 2*4. But 3 is not a stormer number because 3*3+1=10. The greatest prime factor of 10 is 5 which is less than 6 i.e. 2*3. In this problem, we are given a positive integer N and our goal is to print the first N stormer. INPUT: 4 ... Read More

Print first n Fibonacci Numbers using Direct Formula

Rinish Patidar
Updated on 14-Mar-2023 15:05:24

710 Views

In this article, we are going to solve the problem of printing first n Fibonacci Numbers using a direct formula. In mathematics, the fibonacci numbers often denoted by Fn (which indicates nth fibonacci number), form a series in which each number is equal to the sum of the preceding two numbers. The nth fibonacci number can be indicates as below − $$\mathrm{Fn\:=\:F_{n-1}\:+\:F_{n-2}}$$ The series begins with 0 and 1. The first few values in the fibonacci sequence, starting with 0 and 1 are − 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144. ... Read More

Number of Ones in the Smallest repunit

Rinish Patidar
Updated on 14-Mar-2023 15:03:25

233 Views

In this problem, we simply need to print the number of ones in the smallest repunit. A repunit is a positive number like 11, 111, or 1111 in recreational mathematics that only has the digit 1. A repunit is of the form $\mathrm{(10*n-1)/9}$ Example $\mathrm{(10*10-1)/9}$ gives 11. $\mathrm{(10*100-1)/9}$ gives 111. $\mathrm{(10*1000-1)/9}$ gives 1111. The above problem states that we are given any positive integer N with its unit digit 3 and we need to determine the smallest repunit that is divisible by the given number N. For example, If we are given N=13. Output: 6 N i.e. 13 perfectly divides ... Read More

Multiply the given number by 2 such that it is divisible by 10

Rinish Patidar
Updated on 14-Mar-2023 14:55:40

231 Views

This problem statement says that we are allowed to perform only one operation i.e. multiply the given number by 2 such that it is divisible by 10. We will be given a number say n. The only operation that we can perform on a given number is that we can multiply the given number by 2 until it is divisible by 10. We need to determine the minimum number of operations required to make the number such that it is divisible by 10 by repeatedly multiplying the given number n by 2. Else, print -1 if it is not possible ... Read More

Minimum steps in which N can be obtained using addition or subtraction at every step

Rinish Patidar
Updated on 14-Mar-2023 14:52:03

242 Views

From the above problem statement, our task is to get the minimum steps in which a given number N can be obtained using addition or subtraction at every step. We can understand that we need to print the minimum number of steps that we can perform and sequence of the steps on any given integer N to reach the number starting from 0 by addition or subtraction of the step number. In this problem set, we can add or subtract the number equal to the step count from the current location at each step. For instance, we can add either ... Read More

Level order traversal with direction change after every two levels(Implementation in C/C++)

Rinish Patidar
Updated on 20-Mar-2023 16:06:06

116 Views

Level Order TraversalThis is one of the algorithms that processes or prints all nodes of a binary tree by traversing through depth, starting at the root and moving on to its children and so forth.Example INPUT − OUTPUT − 2 4 7 3 6 11 This task involves printing a binary tree's level order traversal so that the first two levels are printed from right to left direction, and the next two levels from left to right direction, and so on. The challenge is that a binary tree's level order traverse must be ... Read More

Largest of two distinct numbers without using any conditional statements or operators

Rinish Patidar
Updated on 14-Mar-2023 14:33:44

1K+ Views

In this problem set, we will be given any two distinct positive numbers, let’s say a and b, we need to return the largest of two distinct numbers without using any conditional statements (if-else) or any operators(, ==, !=, etc.) in c++. The main difficulty of the problem includes that we need to determine the largest of any two distinct positive numbers without using any operators or conditional statements. For example, INPUT: x=12, y=20 OUTPUT: 20 INPUT: x=3, y=2 OUTPUT: 3 Below is the algorithm that we will be using to solve this problem. Algorithm We will use type casting ... Read More

Find the Smallest Positive Number Missing From an Unsorted Array

Rinish Patidar
Updated on 14-Mar-2023 14:31:04

2K+ Views

Our objective is to find the smallest positive number that is missing from an unsorted array. We will be given an array a[] of both positive and negative numbers, we need to get the smallest positive number that is missing from an unsorted array in this problem. We can modify the array given in this problem to solve it. For example, INPUT : a[] = {5, 8, -13, 0, 18, 1, 3} OUTPUT : 2 INPUT : a[] = {7, 10, -8, 1, 4} OUTPUT : 2 In the above examples, we are given an unsorted array as an input. ... Read More

Advertisements