Found 26504 Articles for Server Side Programming

Find n-th element in a series with only 2 digits (and 7) allowed in C++

sudhir sharma
Updated on 12-Mar-2021 08:28:25

254 Views

In this problem, we are given an integer N, denoting a series of numbers consisting of 4 and 7 only.The series is 4, 7, 44, 47, 74, 77, …The task is to find the n-th element in a series with only 2 digits (and 7) allowed.Let’s take an example to understand the problem, InputN = 4, Output47ExplanationThe series is: 4, 7, 44, 47, ….Solution ApproachA simple solution to the problem is creating the series till Nth number. It’s simple, if the current number’s last digit is 7. Then the last digit of previous and next numbers is 4.So, we will ... Read More

Find n positive integers that satisfy the given equations in C++

sudhir sharma
Updated on 12-Mar-2021 08:26:15

287 Views

In this problem, we are given three values A, B and N. Our task is to Find n positive integers that satisfy the given equations.Problem Description − We need to find the N positive values that satisfy both the equations, x12 + x22 + … xn2 ≥ A x1 + x2 + … xn ≤ BPrint n values if present, otherwise print -1.Let’s take an example to understand the problem, InputN = 4, A = 65, B = 16Output1 1 1 8ExplanationThe equations are −12 + 12 + 12 + 82 = 1 + 1 + 1 + 64 = ... Read More

Find N % (Remainder with 4) for a large value of N in C++

sudhir sharma
Updated on 12-Mar-2021 08:21:40

120 Views

In this problem, we are given a string num representing a large integer. Our task is to Find N % (Remainder with 4) for a large value of N.Problem Description − we will be finding the remainder of the number with 4.Let’s take an example to understand the problem, Inputnum = 453425245Output1Solution ApproachA simple solution to the problem is by using the fact that the remainder of the number with 4 can be found using the last two digits of the number. So, for any large number, we can find the remainder by dividing the number’s last two digits by ... Read More

Find Multiples of 2 or 3 or 5 less than or equal to N in C++

sudhir sharma
Updated on 12-Mar-2021 08:18:02

369 Views

In this problem, we are given a number N. Our task is to Find Multiples of 2 or 3 or 5 less than or equal to N.Problem Description − We will be counting all elements from 1 to N that are divisible by 2 or 3 or 5.Let’s take an example to understand the problem, InputN = 7Output5ExplanationAll the elements from 1 to 7 are : 1, 2, 3, 4, 5, 6, 7. Elements divisible by 2/3/5 are 2, 3, 4, 5, 6Solution ApproachA simple approach to solve the problem is by traversing all numbers from 1 to N and ... Read More

Find modular node in a linked list in C++

sudhir sharma
Updated on 12-Mar-2021 07:36:43

262 Views

In this problem, we are given a singly linked list LL and a number k. Our task is to Find modular node in a linked list.Problem Description − we need to find the last node of the linked list for which the index is divisible by k i.e. i % k == 0.Let’s take an example to understand the problem, Inputll = 3 -> 1 -> 9 -> 6 -> 8 -> 2, k = 4Output6ExplanationThe element 6 has index 4, which is divisible by 4.Solution ApproachA simple solution to the problem is by creating a counter to count the ... Read More

Find missing elements of a range in C++

sudhir sharma
Updated on 12-Mar-2021 07:33:23

446 Views

In this problem, we are given an array arr[] of size n and the start and end element denoting the range. Our task is to Find missing elements of a range.Problem Description − we will be finding the elements of the range that are not present in the range.Let’s take an example to understand the problem, Inputarr[] = {4, 6, 3, 7}, start = 3, end = 8Output5, 8ExplanationThe range is [3, 4, 5, 6, 7, 8]The array is {4, 6, 3, 7}Elements of range that are not present in array is 5, 8Solution ApproachYou can solve this problem in ... Read More

Find mirror of a given node in Binary tree in C++

sudhir sharma
Updated on 12-Mar-2021 07:28:27

218 Views

In this problem, we are given a binary tree. Our task is to Find mirror of a given node in the Binary tree. We will be given a node, and find the mirror image of that node in the opposite subtree.Let’s take an example to understand the problem, InputOutputmirror of B is E.Solution ApproachOne simple solution to solve the problem is by using the recursion from the root using two pointers for left subtree and right subtree. Then for the target value if any mirror is found return the mirror otherwise recur other nodes.Program to illustrate the working of our ... Read More

Find mirror image of a point in 2-D plane in C++

sudhir sharma
Updated on 12-Mar-2021 07:24:48

274 Views

In this problem, we are given a point P in a 2-D plane and the points a, b, c of the equation ax + by + c = 0. Our task is to find a mirror image of a point in 2-D plane.Let’s take an example to understand the problem, InputP = (2, 1), a = 1, b = -1, c = 0Output(1, 2)ExplanationThe plane looks like, Solution ApproachTo solve the problem, we need to find the equation point P' with coordinates (x', y'). So, we have R, the midpoint where the line form P - P' intersects the mirror ... Read More

Find minimum speed to finish all Jobs in C++

sudhir sharma
Updated on 12-Mar-2021 07:09:18

194 Views

In this problem, we are given an array arr[] consisting of n elements and an integer h. Each element of the array arr[] contains the number of pending jobs for the person and H is the time left to complete the jobs (in Hours). Our task is to Find minimum speed to finish all Jobs.Problem Description: We need to find the number of jobs the person needs to complete in one hour in order to complete all the jobs given in the array in H hours. If he can complete all specified at arr[i] in less than an hour, we ... Read More

Find minimum possible size of array with given rules for removing elements in C++

sudhir sharma
Updated on 12-Mar-2021 07:05:04

566 Views

In this problem, we are given an array of n numbers and an integer value k. Our task is to Find minimum possible size of the array with given rules for removing elements.Problem Description − we need to minimise the number of elements in the array. By using the follow deletion operation, The number of elements that can be removed at once is 3. The removal is possible if the three elements satisfy the two given conditions, Cond 1 − Three elements should be adjacent.>Cond 2 − the difference between two nearby elements is k, i.e. arr[i + 1] = ... Read More

Advertisements