谷歌店面

考了两题

第一题
A perfect square is a number made by squaring a whole number.

Some examples include 1, 4, 9, or 16, and so on – because they are the squared results of 1, 2, 3, 4, etc. However, 15 is not a perfect square, because the square root of 15 is not a whole or natural number.

Given some positive integer n, write a method to return the sum of all perfect squares less than n.

Example 1:

Input: n = 10
Output: 14
Explanation: 1 + 4 + 9 = 14

第二题 https://leetcode.com/problems/missing-ranges/

考了这题

Given a acyclic directed graph ( no cycle in it ) , give you the root id ( guarantee root node is valid root , i.e no path go into it , only out path ), find the longest path from root to leaf node ( among all path from root to leaf node, output the longest path length one )

imagine graph is like :
vector<vector<pair<int, int>>> graph;
graph[i] = {neighborId, path length to neighbor }

Google新鲜电面
白人小哥,最后聊working in google聊得挺开心的,不知道是不是错觉,感觉题比实习面得还简单。。。
problem 1:写一个函数,reverse一个number比如123一》321
注意corner case:比如reverse后不是number 10-》01
负数的处理
一个digit不用处理直接返回
problem 2:输出1一650中upside down以后合法的数。
upside down:6-》9
61-》16
如果upside down以后和原来的一样,不输出,比如11-》11不输出
1, 0, 8 upside down以后和原来一样 6-》9 9-》6有其他字符就是invalid
注意corner case 10-》01 not valid

请问一下61->16 还是19?