当前位置: 首页 > 面试经验 >

9.14小米笔试

优质
小牛编辑
80浏览
2023-03-28

9.14小米笔试

试卷:算法方向

大概单选和多选涵盖的内容也是很广泛了,又是要求全面的人才。考察了CV方向,机器学习,NLP,相机模型,概率等等。

编程两道:

1. 数组左右两边依次操作选择数字,问是否可以某个时刻得到和为x的值,输出最小操作数。
思路:双指针每次选择更大的值操作,然后加一些判断条件。比较简单。
arr = []
while 1:
    s = input()

    if s != "":
        arr.append(list(map(int, s.replace("],", "").replace(" ", "").replace("[", "").replace("]", "").split(","))))
    else:
        break
# 使用自测数据按钮时调试用,正式提交时要删掉。
nums = arr[0]
length = arr[1][0]
x = arr[2][0]
cnt = 0
i, j = 0, length-1
while i <= j and x > 0:
    if nums[i] == x&nbs***bsp;nums[j] == x:
        cnt += 1
        break
    if x > nums[i] and x > nums[j]:
        if nums[i] > nums[j]:
            x -= nums[i]
            i += 1
        else:
            x -= nums[j]
            j -= 1
        cnt += 1
    elif x < nums[i] and x < nums[j]:
        cnt = -1
        break
    else:
        if x > nums[i] and x < nums[j]:
            x -= nums[i]
            i += 1
        else:
            x -= nums[j]
            j -= 1
        cnt += 1
print(cnt)

2. 实现两个数组的线性卷积和互信息。最终输出两个数组。
思路:用Numpy的自带函数去做,但是最后时间不够了可能细节没处理到位,最终可能case也没过几个,但是思路是没问题的就是格式差异。
import numpy as np

row1 = input().split(',')
row2 = input().split(',')
l1, l2 = int(row1[0]), int(row2[0])
arr1, arr2 = list(map(int, row1[1].split())), list(map(int, row2[1].split()))
nums1, nums2 = np.array(arr1), np.array(arr2)

linearconvol = list(np.convolve(nums1, nums2))
convol = list(map(str, linearconvol))
length1 = l1+l2-1
res1 = str(length1)+","+" ".join(convol)

linearcorrelate = list(np.correlate(nums1, nums2, 'full'))
length2 = l1+l2
correlate = list(map(str, linearcorrelate))+['0' for _ in range(length2-len(linearcorrelate))]
res2 = str(length2)+","+" ".join(correlate)
print(res1)
print(res2)

希望到时候看代码可以不只看通过率吧······
#小米笔试##小米##小米科技#
 类似资料: