Incomprehensible incomprehensibility 🤔
🧠IntuitionWe need to create our own small data structure. And it is still unclear how they will be used in practice.But the fact of the matter is that a task is
# 🧠Intuition
We need to create our own small data structure. And it is still unclear how they will be used in practice.But the fact of the matter is that a task is a task that needs to be done. 

# 🎯What they want from us
To begin with, let's understand what they want from us to the end.
|nums            |command       |retern|Comments|
| ---            |----------------|------|--------|
| [ ]            |**NumberContainers**|null  |Creating a container|
| [ ],[10]       |**find(10)**        |-1    |we throw it into the system and return -1|
| [ ],[10],[2,10]|**Change(2,10)**    |null  |we throw it into the system and return null|
| [ ],[10],[2,10],[10]|**find(10)**   | 1    |we return the smallest index of 10|

# 🛠️Approach
starting 3 maps 
**index** for indexes
**group** for pairs of values
**isSorted** for the history of changes
```
	index    map[int]int
	group    map[int][]int
	isSorted map[int]bool
```

 🚀Change
---
checking if there is such an index in the containers
```
if prev, f := this.index[index]; f
```
if prev is not equal to what is there, then just change it to a new one.
```
if prev != number {
			this.remove(index, prev)
			this.add(index, number)
}
```
if there is nothing under this index, create a new one.
```
this.add(index, number)
```

🎯Find
---
we check for the total length, if we have created its current and immediately call the Find method, then return -1
```
if len(this.group[number]) == 0 {
		return -1
	}
```
We check the array, if it is sorted, we sort it, if not, we skip it.
```
if sorted := this.isSorted[number]; !sorted {
		sort.Ints(this.group[number])
		this.isSorted[number] = true
	}
```


we return the first index of the sorted number under this index
```
return this.group[number][0]
```









# ⌛Complexity
- **Time complexity**:
- $$O(N)Constructor$$
- $$O(N)Find$$
- $$O(1)Change$$

<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- **Space complexity**:
- $$O(N)Constructor$$
- $$O(N)Find$$
- $$O(1)Change$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# ♥️Code
```golang []
type NumberContainers struct {
	index    map[int]int
	group    map[int][]int
	isSorted map[int]bool
}

func Constructor() NumberContainers {
	return NumberContainers{
		index:    make(map[int]int),
		group:    make(map[int][]int),
		isSorted: make(map[int]bool),
	}
}

func (this *NumberContainers) Change(index int, number int) {
	if prev, f := this.index[index]; f {
		if prev != number {
			this.remove(index, prev)
			this.add(index, number)
		}
	} else {
		this.add(index, number)
	}
}

func (this *NumberContainers) add(index, number int) {
	this.index[index] = number
	this.group[number] = append(this.group[number], index)
	this.isSorted[number] = false
}

func (this *NumberContainers) remove(index, prev int) {
	for i := 0; i < len(this.group[prev]); i++ {
		if this.group[prev][i] == index {
			this.group[prev] = append(this.group[prev][:i], this.group[prev][i+1:]...)
			delete(this.index, index)
			return
		}
	}
}

func (this *NumberContainers) Find(number int) int {
	if len(this.group[number]) == 0 {
		return -1
	}

	if sorted := this.isSorted[number]; !sorted {
		sort.Ints(this.group[number])
		this.isSorted[number] = true
	}

	return this.group[number][0]
}



```
['Go']