Topic: Mathematical
Questions Successfully Completed: 2
1) Absolute Value | Easy |
2) Factorial Of Number | Easy |
Absolute Value
Time Complexity : O(1)
Space Complexity : O(1)
Question
Input: I = -32 Output: 32 Explanation: The absolute value of -32 is 32.
class Solution {
public int absolute(int I) {
int y = Math.abs(I);
return y;
}
}
Factorial Of Number
Time Complexity : O(n)
Space Complexity : O(1)
Question
Input: N = 13 Output: 6227020800 Explanation: 13! = 13 12 .. * 1 = 6227020800
public long factorial(int N) {
long mul = 1;
for(int i=N;i>0;i--){
mul = mul * i;
}
return mul;
}
Thank you for reading :)