#### SIMPLE SOLUTION FOR REVERSE INTEGER

**Intuition**

Check integer overflow condition,However, if the number is large such that the reverse overflows, the output will be some garbage value. If we give the input as any large number say 1000000045, then the output is some garbage value like 1105032705 or any other garbage value.

**Algorithm**

- determine sign of the x(input integer)
- make x absolute
- create a loop
- set remainder = x % 10
- set reverse = reverse * 10 + remainder
- check integer overflow condition.compare value of remainder with reverse % 10 if equal goto step 7 else return 0
- set x = x/10
- return reverse with sign
- exit

**C++**

```
class Solution {
public:
int reverse(int x) {
int rev=0, sum=0,count=0;
int sign = x<0? -1:1;
x=abs(x);
while(x>0)
{
int remainder = x % 10;
rev = rev*10 + remainder;
if((rev%10)!=remainder)
{
return 0;
}
x = x/10;
count++;
}
return (sign * rev);
}
};
```

**Complexity Analysis**

- Time complexity : O(count)

as count contains number of digits in integer x. - space complexity : O(count)

as counts equals to number of digits which is need to store.