面试之路: BNYMellon面试1

面试之路: BNYMellon OA

Coding 题

1.Holes in number
			1,2,3,5,7 = 0 holes
			0,4,6,9 = 1 holes
			8 = 2 holes
			input n;
public int countHoles(int n){
	if(n < 0) return 0;
	int[] arr = {1,0,0,0,1,0,1,0,2,1};
	
	int res = 0;
	while(n > 0){
		int temp = n % 10;
		res += arr[temp];
		n /= 10;
	}
	return res;	
}

2. DIstance Metric
给予一个数组, 寻找每个点与他相同数的点的距离和。
这里要返回Long数组;
	public List<Long> distanceMetric(List<Integer> arr){
		Long[] res = new Long[arr.size()];

    	for(int i = 0; i < arr.size(); i++){
	    	res[i] = new Long(0);
	    }
		//写的时候 放了一个错误把 i 和 j 的位置写反了,后面时间没了T T,幸好截图了才发现 原来 位置写反了。
	    for(int i = 0; i < arr.size(); i++){
	    	for(int j = 0; j < arr.size(); j++){
	    		if(arr.get(i) == arr.get(j) && i != j){
	    			int v = Math.abs(i - j);
	            	res[i] += new Long(v);
	    		}

	        }
	   	}
	   	return Arrays.asList(res);
	}


3. Student grade
给予一个schema 叫students
返回其 id, name, marks, grade
select s.id, s.name, s.marks,
case
when s.marks > 90 then 'A+'
when s.marks > 70 then 'A'
when s.marks > 50 then 'B'
when s.marks >=40 then 'C'
else 'Fail'
end as grade
from students s;

4. Sort in Array
	如果给一个数组排序, 用尾插入的方法,问最少要几次操作后,可以得到一个排好序的数组
public int sortInMin(List<Integer> arr){
	if(arr == null || arr.size() <= 1) return 0;
	
	Map<Integer, Integer> map = new HashMap<>();
	int count = 0;
	int last = arr.size();
	for(int i = 0;i < arr.size(); i++){
		map.put(arr.get(i), i);
	}
	Collections.sort(arr);
	
	for(int i = 0; i < arr.size() - 1; i++){
		if(map.get(arr.get(i))> map.get(arr.get(i+1))){
			count++;
			map.put(arr.get(i + 1), last++);
		}
	}
	return count;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值