exercise-2_math
exercise-2_math
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.
Example:
Input:N = 153
Output:True
Explanation: 1^3+5^3+3^3 = 1 + 125 + 27 = 153
Example:
Input:N = 36
Output:[1, 2, 3, 4, 6, 9, 12, 18, 36]
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.
Examples:
Examples:
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.