0% found this document useful (0 votes)
1 views

exercise-2_math

Uploaded by

Deepak kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

exercise-2_math

Uploaded by

Deepak kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Given an integer N return the reverse of the given number.

Note: If a number has trailing zeros, then its reverse will not include them. For
e.g., reverse of 10400 will be 401 instead of 00401.

Examples
Example 1:
Input:N = 12345
Output:54321

2. Given two integers a and b, write a function to compute their LCM and GCD. The
function takes two integers a and b as input and returns a list containing their
LCM and GCD.

Example:

Input: a = 5 , b = 10
Output: 10 5
Explanation: LCM of 5 and 10 is 10, while their GCD is 5.

3. Given an integer N, return true it is an Armstrong number otherwise return


false.
An Amrstrong number is a number that is equal to the sum of its own digits each
raised to the power of the number of digits.

Example:
Input:N = 153
Output:True
Explanation: 1^3+5^3+3^3 = 1 + 125 + 27 = 153

4. Given an integer N, return all divisors of N.


A divisor of an integer N is a positive integer that divides N without leaving a
remainder.

Example:
Input:N = 36
Output:[1, 2, 3, 4, 6, 9, 12, 18, 36]

5. Given an integer N, check whether it is prime or not. A prime number is a number


that is only divisible by 1 and itself and the total number of divisors is 2.

6.Given an array arr containing only 0s, 1s, and 2s. Sort the array in ascending
order.
Examples:
Input: arr[] = [0, 2, 1, 2, 0]
Output: 0 0 1 2 2

7. Given an array arr. Find the majority element in the array. If no majority
exists, return -1.

A majority element in an array is an element that appears strictly more than


arr.size()/2 times in the array.

Examples:

Input: arr[] = [3, 1, 3, 3, 2]


Output: 3
Explanation: Since, 3 is present more than n/2 times, so it is the majority
element.
8. Given an array arr of non-negative numbers. The task is to find the first
equilibrium point in an array. The equilibrium point in an array is an index (or
position) such that the sum of all elements before that index is the same as the
sum of elements after it.
Note: Return equilibrium point in 1-based indexing. Return -1 if no such point
exists.

Examples:

Input: arr[] = [1, 3, 5, 2, 2]


Output: 3
Explanation: The equilibrium point is at position 3 as the sum of elements before
it (1+3) = sum of elements after it (2+2).

9. Given a positive integer n, find the nth fibonacci number. Since the answer can
be very large, return the answer modulo 1000000007.
Note: for the reference of this question take first fibonacci number to be 1.

Examples :
Input: n = 5
Output: 5
Explanation: 5 is the 5th number of fibonacci series.

10. Given three integers 'A' denoting the first term of an arithmetic sequence ,
'C' denoting the common difference of an arithmetic sequence and an integer 'B'.
you need to tell whether 'B' exists in the arithmetic sequence or not. Return 1 if
B is present in the sequence. Otherwise, returns 0.

Example 1:
Input: A = 1, B = 3, C = 2
Output: 1
Explaination: 3 is the second term of the
sequence starting with 1 and having a common
difference 2.

You might also like