2024 Visa OA

4道题70 min,都很简单,最后拿了600/600
1,判断数组里有多少个数比pivot大,多少个比pivot小,输出不同的结果
You are given an array ofintegers numbers and aninteger pivot .Let countGreater denote howmany integers within numbers are strictly greatelthan pivot ,and countLess denote how many!integers are strictly less than pivot
Your task is to compute countGreater andcountLess , then return:
"greater" if countcreater is greater thancountLess ,
"smaller" if countGreater is less thancountLess;
"tie" if they are equal.1
2,Given an array of strings schedule that
represents the schedule of bus arrival times and astring time that represents the current time, findout how many minutes ago the last bus left. lf thefirst bus for the day has yet to leave, returd -1
Time is represented as a string in the form ofHH:Mm (in the 24-hour format). Bus departuretimes are sorted in chronological order.
RULES
README
Please assume that if a bus is scheduled to leaveat the current time, it hasn't left yet.
Note: You are not expected to provide the most
Example
For schedule =["12:30","14:00""19:55"] and time = "14:30",the outputshould be solution(schedule, time)=30
3,一个m * n的matrix,一个robot起始点坐标,robot只能上下左右走,不会转弯。一些laser的坐标,laser会照射它所在的一行一列,问robot可以走的不被laser照射到的最长的路是多长。 用了upper,lower,left和right作为四个边界,扫描laser更新边界,四边各算一下取最大。很简单的一道题,但是有2个hidden case没过,可能是边界条件的问题
4,Given an empty array that should contain integersnumbers , your task is to process a list of
queries on it. Specifically, there are two types ofqueries:
"+x"-append x to numbers . numbersmay contain multiple instances of the sameinteger.
"-x" remove all the instancés of x from numbers
After processing each query, count the number oftriples (x,y,z)in numbers which meet thiscondition: both x-y and y= z are equal to agiven diff .Note that elements in numbers canbe rearranged to form triples to meet the condi‍‌‌‌‍‌‍‌‌‌‌‍‍‍‍‌‍‍‌‍‍tionThe final output should be an array of counts aftereach query in queries
看起来很绕其实很简单,但是每个query都要找一遍,所以就用了一个helper function,有一个map存数字的个数,每个query都更新map,然后找map中符合条件的数字,y = x + diff, z = y + diff看在不在map中,在的话数量就是map[x]map[y]map[z].

更多OA真题咨询,辅助VO OA,欢迎联系我

Leave a Reply

Your email address will not be published. Required fields are marked *