回复: 3
跳转到指定楼层
上一主题 下一主题
收起左侧

Amazon Linux Find题目Python解法,求交流

🔗
匿名用户-UVWE4  2020-9-28 05:54:24 |倒序浏览

2020(7-9月) 码农类General 本科 全职@amazon - 内推 - HR筛选  | | Pass | 应届毕业生

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

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
本帖最后由
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
  1. # design for linux find
  2. from enum import Enum
  3. from abc import ABCMeta, abstractmethod
  4. from collections import deque


  5. class FileType(Enum):
  6.     video = 1
  7.     image = 2
  8.     text = 3
  9.     other = 4


  10. class File:
  11.     # children is list of File
  12.     def __init__(self, name: str, size: int, type=None, is_directory=False, children=[]):
  13.         self.name = name
  14.         self.size = size
  15.         self.type = type
  16.         self.is_directory = is_directory
  17.         self.children = children


  18. # build abstract class
  19. class Filter(metaclass=ABCMeta):
  20.     @abstractmethod
  21.     def apply_filter(self, file: File):
  22.         pass


  23. # extend previous abstract class Filter
  24. class MinSizeFilter(Filter):
  25.     def __init__(self, size):
  26.         self.size = size

  27.     def apply_filter(self, file):
  28.         return file.size >= self.size


  29. class TypeFilter(Filter):
  30.     def __init__(self, type):
  31.         self.type = type

  32.     def apply_filter(self, file):
  33.         return file.type == self.type


  34. # build FindCommand class
  35. class FindCommand:
  36.     def __init__(self, type=None, min_size=0):
  37.         self.min_size_filter = MinSizeFilter(min_size)
  38.         self.type_filter = TypeFilter(type)
  39.         self.file_lst = []

  40.     def get_required_file_list(self, file):
  41.         queue = deque([file])
  42.         while queue:
  43.             cur_file = queue.popleft()
  44.             if self.min_size_filter.apply_filter(cur_file) and self.type_filter.apply_filter(cur_file):
  45.                 self.file_lst.append(cur_file.name)
  46.             for child in cur_file.children:
  47.                 queue.append(child)
  48.         return self.file_lst


  49. file1 = File(name="photo1", size=6, type=FileType.image)
  50. print(file1.size)
  51. print(file1.type)

  52. min_size_filter_5 = MinSizeFilter(5)
  53. print(min_size_filter_5.apply_filter(file1))
  54. type_filter_image = TypeFilter(FileType.image)
  55. print(type_filter_image.apply_filter(file1))

  56. file2 = File(name="photo2", size=4, type=FileType.image)
  57. file3 = File(name="video1", size=4, type=FileType.video)
  58. file4 = File(name="photo3", size=6, type=FileType.image)
  59. directory1 = File(name="dir1", size=20, is_directory=True, children=[file1, file2, file3, file4])
  60. find_image_larger_than_5 = FindCommand(type=FileType.image, min_size=5)
  61. print(find_image_larger_than_5.get_required_file_list(directory1))
复制代码

评分

参与人数 2大米 +16 收起 理由
匿名用户-G3XGC + 15
armu + 1 赞一个

查看全部评分


上一篇:IMC Video Interview
下一篇:图森oa, 好心人求大米!
推荐
Jaye003 2020-9-29 09:02:23 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
jamesleborn 2020-9-28 13:28:26 | 只看该作者
全局:
这题是店面还是onsite问的?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-QABTC  2020-10-5 05:22:46 来自APP
这题就是588啊.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

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