## Google Interview Question

SDE1s**Country:**United States

int arr[]={2,2,2,3};

HashSet<Integer> set=new HashSet<>();

Queue<Integer> temp=new LinkedBlockingQueue<>();

boolean flag=true;

for(int j=0;j<arr.length;j++){

flag=set.add(arr[j]);

if(!flag){

temp.add(arr[j]);

}

}

while(!temp.isEmpty()){

int k=temp.poll();

k=k+1;

while(!set.add(k)){

k=k+1;

}

}

System.out.println(set.toString());

Javascript -- O(n) time and O(1) space

```
var special_sum = function (arr) {
if (arr.length == 0) return 0;
if (arr.length == 1) return arr[0];
let prev = arr[0];
for(let i = 1; i < arr.length; ++i) {
if(prev >= arr[i]) {
arr[i] = prev + 1;
}
prev = arr[i];
}
let sum = 0;
for(let i = 0; i < arr.length; ++i) {
sum += arr[i];
}
return sum;
}
```

O(n) time, O(1) space.

- Alex December 14, 2017