Convert to base -1 || Java solution || Division based conversion 
Intuition1.The core idea is to perform a division-based conversion, similar to converting a number to any other base (e.g., base 2 or base 10). However, in base
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1.The core idea is to perform a division-based conversion, similar to converting a number to any other base (e.g., base 2 or base 10). However, in base -2, the base is negative, which introduces a few challenges when calculating remainders.
2.In any base conversion, the remainder after dividing the number by the base determines the digits of the new number. But in base -2, you need to handle two key aspects:
    #The remainder can be negative because you are dividing by a negative number.
    #The remainder must be adjusted to always be either 0 or 1 because the digits in the base -2 representation can only be 0 or 1.
3.The division process continues until the quotient becomes 0, which is similar to other base conversions.

# Approach
<!-- Describe your approach to solving the problem. -->
1.Start with the number to convert: We begin by dividing the number by -2 to find the first remainder.

2.Handle negative remainders: If the remainder is negative (which is possible when dividing by a negative base like -2), we adjust it to fit the allowed digits (0 or 1) by adding 2 to it. This also means we have to adjust the number accordingly by adding 2 so that the division still holds.

3.Update the number: After calculating the remainder, update the number by dividing it by -2.

4.Continue the process: Repeat the process until the number becomes 0.

5.Build the result: Each remainder represents a digit of the base -2 number, starting from the least significant digit. Thus, we append the remainder to a StringBuilder. Finally, reverse the string to get the correct base -2 representation.
# Edge Case:
Zero: The number 0 is a special case and directly translates to "0" in any base, including base -2.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
The time complexity of the conversion is O(log(|num|)), where |num| is the absolute value of the number being converted.

Reason: The algorithm works by repeatedly dividing the number by -2. In each step, the number is divided by -2, which reduces the size of the number logarithmically. The number of divisions is proportional to the logarithm of the absolute value of the number.

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
The space complexity is O(log(|num|)) due to the space required to store the result as a string. 

# Code
```java []
class Solution {
    public String baseNeg2(int n) {
        if(n==0) return "0";
        StringBuilder sb=new StringBuilder();
       while(n!=0)
       {
        int rem=n%-2;
        n/=-2;

        if(rem<0)
        {
            rem+=2;
            n+=1;
        }
        sb.insert(0,rem);
       }
       return sb.toString();
    }
}
```
['Java']