Practice
Greatest Common Divisor
Given 2 non negative integers m and n, find gcd(m, n)
GCD of 2 integers m and n is defined as the greatest integer g such that g is a divisor of both m and n.
Both m and n fit in a 32 bit signed integer.
Example
1 | m : 6 |
NOTE : DO NOT USE LIBRARY FUNCTIONS
1 | public class Solution { |
Rearrange Array
Rearrange a given array so that Arr[i] becomes Arr[Arr[i]] with O(1) extra space.
Example:
1 | Input : [1, 0] |
Lets say
N=size of the array. Then, following holds true :
- All elements in the array are in the range
[0, N-1]N * Ndoes not overflow for a signed integer
1 | public class Solution { |
Palindrome Integer
Determine whether an integer is a palindrome. Do this without extra space.
A palindrome integer is an integer x for which reverse(x) = x where reverse(x) is x with its digit reversed.
Negative numbers are not palindromic.
Example :
1 | Input : 12121 |
1 | public class Solution { |