May 2009 - May 2017 论坛八周年-你的足迹,我的骄傲



查看: 980|回复: 1

8.24 Google SE OA 挂经,一共两题1小时完成。

[复制链接] |试试Instant~ |关注本帖
wxgymsfd 发表于 2016-9-22 12:52:09 | 显示全部楼层 |阅读模式

2016(7-9月) 码农类 硕士 全职@Google - Other - 其他 |Failfresh grad应届毕业生


您需要 登录 才可以下载或查看,没有帐号?获取更多干活,快来注册


You are given an integer X. You must choose two adjacent digits and replace them with the larger of these two digits.
For example, from the integer X = 233614, you can obtain:. 1point 3acres 璁哄潧
33614 (by replacing 23 with 3);
23614 (by replacing 33 with 3 or 36 with 6);
23364 (by replacing 61 with 6 or 14 with 4);
You want to find the smallest number that can be obtained from X by replacing two adjacent digits with the larger of the two. In the above example, the smallest such number is 23364.
Write a function:
class Solution {public int solution (int X);}
that, given a positive integer X, returns the smallest number that can be obtained from X by replacing two adjacent digits with the larger of the two.
For example, given X = 233614, the function should return 23364, as explained above.
Assume that:
X is an integer within the range [10..1,000,000,000].In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.. more info on
第二题You are given a listing of directories and files in a file system. Each directory and file has a name, which is a non-empty
string consisting of alphanumerical characters. Additionally, the name of each file contains a single dot character; the part
of the name starting with the dot is called the extension. Directory names do not contain any dots. All the names are case-. 1point 3acres 璁哄潧
Each entry is listed on a separate line. Every directory is followed by the listing of its contents indented by one space
character. The contents of the root directory are not indented.
Here is a sample listing:
  dir 121
file2.gifWe have three files (picture.jpeg, file1.txt and file2.gif) and six directories (dir1, dir11, dir12, dir121, dir2 and the.鐣欏璁哄潧-涓浜-涓夊垎鍦
root directory). Directory dir12 contains two files (picture.jpeg and file1.txt) and an empty directory (dir121). The root 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
directory contains two directories (dir1 and dir2).
The absolute path of a directory is a string containing the names of directories which have to be traversed (from the root
directory) to reach the directory, separated by slash characters. For example, the absolute path to the directory dir121 is
dir1/dir12/dir121". Note that there is no "drive letter", such as "C: ", and each absolute path starts with a slash. The
absolute path of a root directory is The image files are the files with extensions .jpeg, .png or .gif (and only these extensions). We are only interested in directories that directly contain image files (that is, without looking in their subdirectories). We want to find the total length
of the absolute paths to all the directories that directly contain at least one image file. For example, in the file system.1point3acres缃
described above there are two directories that directly contain image files: "/dir1/dir12" and "Mia". Directory "/dir1"
doesn't directly contain any image files. The total length of the absolute paths "/dir1/dir12" and "/dir2" is 11 + 5 = 16.
Write a function:
int solution(char *S);
that, given a string S consisting of N characters which contains the listing of a file system, returns the total of lengths (in. visit for more.
characters) modulo 1,000,000,007 of the absolute paths to all the directories directly containing at least one image file. For
example, given the sample listing shown above, the function should return 16, as explained above. If there are no image. From 1point 3acres bbs
files in the listing, the function should return 0.. from:
Assume that:.鏈枃鍘熷垱鑷1point3acres璁哄潧
N is an integer within the range [1..3,000,000];.
string S consists only of alphanumerical characters (a-z and/or A-Z and/or 0-9), spaces, dots (.) and end-
of-line characters;
string S is a correct listing of a file system contents.
expected worst-case time complexity is 0(N);
expected worst-case space complexity is 0(N) (not counting the storage required for input arguments).



一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2017-5-26 21:32

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表