---
# System prepended metadata

title: ASUS AICS
tags: [Interviews]

---

# ASUS AICS
###### tags: `Interviews`

## Coding test II
[Question](https://leetcode.com/problems/minimum-time-difference/description/?fbclid=IwAR2HcDaGhRL_ZT2Bu5fc3c1i_BoAnOCDDITiWB4zMuKuZPcHVAq3GHe5ljo)


## Coding test
### max distance
給定一個整數陣列，找出任兩個相同元素的最大距離
* test cases:
A = [2,1,3,4,5,6,7,2,3]
A = [2,2,2,2,2...,2] , A.size() = 50000


### Modify to the same
給定一個整數陣列，每次可以對任一數進行+1或-1，找出最小步數，讓整個陣列都是同個數值

*該陣列整數範圍為1~4
*陣列長度1~100000

* test cases:
[1,2,1,3,1,1,3]
[3,3,3]
[1,4,1,4]

#### Solution
>we can make the array elements equal to any number in the array but we are asked to find out the minimum number of operations. So,we should find a number which minimizes the cost of equalizing the elements and that number is the **middle element**.
```cpp=
#include<iostream>
using namespace std;
int min_ops(int arr[],int n)
{
    int mid = arr[n/2];
	int mid1 = arr[(n/2)-1];
	int res = 0,res1 = 0;
	for(int i=0;i<n;i++)
	{
		res = res + abs(arr[i] - mid);
		res1 = res1 +abs(arr[i] - mid1);
	}
	return min(res,res1);
}
int main()
{
    int arr1[] = {2,5,7,9,10};
    int arr2[] = {3,7,9,10};
    cout<<min_ops(arr1,5)<<endl;
    cout<<min_ops(arr2,4)<<endl;   
}
```

### Check multiple of 3
給定一個字串S，每個digit都是0~9，每次可以更換字串中一位數的一個digit，求所有變換可能中被3整除的個數

* test cases:
>* Example01
>      Given S = "23", should return 7. All numbers divisible by 3 that can be obtained after at most one change are (03, 21, 24, 27, 33, 63, 93).
>* Example02
>      Given S = "0081" should return 11. (0021, 0051, 0081, 0084, 0087, 0381, 0681, 0981, 3081, 6081, 9081)
>* Example03
>      Given S = "022" should return 9. (012, 021, 024, 027, 042, 072, 222, 522, 822)

#### Solution
1. 知道整除3的規律是所有位數加起來為3的倍數
2. 