# Java 26 CodeSignal Interview Guide

## Part 1 - Reverse a HashMap (Value → Key)

### Problem

Reverse a `Map<String,Integer>` into a `Map<Integer,String>`.

### Solution

```java
public static <K, V> Map<V, K> reverse(Map<K, V> input) {

    Map<V, K> result = new HashMap<>();

    for (Map.Entry<K, V> entry : input.entrySet()) {
        result.put(entry.getValue(), entry.getKey());
    }

    return result;
}
```

### Complexity

- Time: **O(n)**
- Space: **O(n)**

### Follow-up

If duplicate values exist:

```java
public static <K,V> Map<V,List<K>> reverseWithDuplicates(Map<K,V> input){

    Map<V,List<K>> result = new HashMap<>();

    for(var entry : input.entrySet()){

        result.computeIfAbsent(
                entry.getValue(),
                k -> new ArrayList<>())
              .add(entry.getKey());
    }

    return result;
}
```

### Interview Notes

- Mention that duplicate values overwrite entries in a normal `Map<V,K>`.
- If duplicates are possible, use `Map<V,List<K>>`.
