I have a following requirement that need to be cater in dapp.

1. Insert array of address
2. The array need to be unique. **If one of the array address already exists, reject and revert entire operation**.
3. dapp must able to retrieve the user address list
4. dapp must able to detect if a user address exists based on a user address input

Note:

1. The above requirement must be satisfied.
2. **Full Validation checking must be done by smart contract**.(cannot rely on client side checking alone).

Trying to use **3 for loop** doesn't seems be a very clever way for this as it become a cost expensive operation. Unfortunately this is the only solution i can think of to satisfy above condition. Anyone have experience on dealing with this?

```
// probably only one of mapping or list is needed
address[] public addressList;
mapping (address => bool) public userAddr; 

    function insertAddress(address[] addressUser) public returns (bool) {
        // loop addressUser and check if it is unique
        // loop addressUser and check if it exists in mapping
        // loop and push addressUser to addressList + insert addressUser to userAddr

        return true;
    }

```