一亩三分地论坛

 找回密码
 获取更多干货,去instant注册!

扫码关注一亩三分地公众号
查看: 699|回复: 1
收起左侧

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

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

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

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?获取更多干货,去instant注册!

x


鏉ユ簮涓浜.涓夊垎鍦拌鍧. 第一题:-google 1point3acres
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:. 1point3acres.com/bbs
33614 (by replacing 23 with 3);
23614 (by replacing 33 with 3 or 36 with 6);. visit 1point3acres.com for more.
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.
第二题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.1point3acres缃
of the name starting with the dot is called the extension. Directory names do not contain any dots. All the names are case- 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
sensitive.
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:
dir1
dir11
dir12
  picture.jpeg
  dir 121
   file1.txt
dir2
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. 1point 3acres 璁哄潧
directory contains two directories (dir1 and dir2).-google 1point3acres
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
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
characters) modulo 1,000,000,007 of the absolute paths to all the directories directly containing at least one image file. For. visit 1point3acres.com for more.
example, given the sample listing shown above, the function should return 16, as explained above. If there are no image
files in the listing, the function should return 0.. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
Assume that:
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.
Complexity:
expected worst-case time complexity is 0(N);
expected worst-case space complexity is 0(N) (not counting the storage required for input arguments).

本版积分规则

请点这里访问我们的新网站:一亩三分地Instant.

Instant搜索更强大,不扣积分,内容组织的更好更整洁!目前仍在beta版本,努力完善中!反馈请点这里

关闭

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

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

custom counter

GMT+8, 2016-12-8 06:25

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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