Easy Java Solution

```
public class Solution {
public int lastRemaining(int n) {
return aux(n, true);
}
private int aux(int n, boolean toRight) {
if (n == 1)
return 1;
if (toRight)
return 2 * aux(n / 2, false);
else if (n % 2 == 0)
return 2 * aux(n / 2, true) - 1;
else
return 2 * aux(n / 2, true);
}
}
```