Here is a simple O(N) solution with no additional space. The key idea is to iteratively add each digit starting from the least significant and in each iteration there are two possibilities: 1) pick the bigger of current digit and previous digit and combine it with the rest of the number or 2) just append current digit to "current number" with already replaced digit. Pick the smallest of 1) and 2) and assign it to current number. but it did take me more than 30 mins to solve this.. so not sure how fast were they expecting to get this done.

Works only for num >=0.

```
public static int getMinimumAdjacentReplaced(int num) {
int prevDigit = num%10;
int nextDigit = 0;
int remainingNum = num/10;
int multiplier = 1;
int prevAllDigits = 0;
int curReplacedNum = prevDigit;
while(remainingNum > 0) {
nextDigit = remainingNum%10;
int biggerDigit = nextDigit;
if (prevDigit > nextDigit)
biggerDigit = prevDigit;
int replacedNum1 = biggerDigit*multiplier + prevAllDigits;
int replacedNum2 = curReplacedNum + (nextDigit*multiplier);
curReplacedNum = replacedNum2;
if (replacedNum1 < replacedNum2) {
curReplacedNum = replacedNum1;
}
prevAllDigits = prevAllDigits + prevDigit*multiplier;
prevDigit = nextDigit;
multiplier *= 10;
remainingNum = remainingNum / 10;
}
return curReplacedNum;
}
```