📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 2
跳转到指定楼层
上一主题 下一主题
收起左侧

Headway蘿蔔OA

🔗
匿名用户-OZLAN  2026-4-21 08:29:37 |倒序浏览

2026(1-3月) 码农类General 本科 全职@headway - 内推 - 技术电面  | 😐 Neutral 😣 Hard | Fail | 在职跳槽

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

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

x
本帖最后由 匿名 于 2026-4-20 20:32 编辑

20分鐘討論: add comment to articles
30分鐘OOD:
1. 找bug: missing float
2. 完成count_journeys
3. 完成catch_speeders
最後一道來不及寫完 求加米
class LogEntry:
    def init(self, log_line):
        tokens = log_line.split(' ')
        # BUG WAS HERE: was tokens[0] stored as string
        # Fix: use float() to parse timestamp as number
        # Without this, timestamp subtraction returns NaN
        # causing catchSpeeders() to never detect speeders
        self.timestamp = float(tokens[0])
        self.license_plate = tokens[1]
        self.booth_type = tokens[3]
        location_str = tokens[2]
        self.location = int(location_str[:-1])
        direction_letter = location_str[-1]
        if direction_letter == 'E':
            self.direction = 'EAST'
        elif direction_letter == 'W':
            self.direction = 'WEST'
        else:
            raise ValueError('Invalid direction letter')

    def str(self):
        return (f"<LogEntry timestamp: {self.timestamp} license: {self.license_plate} "
                f"location: {self.location} direction: {self.direction} "
                f"booth type: {self.booth_type}>")


class LogFile:
    def init(self, file_contents):
        self.log_entries = []
        lines = file_contents.split('\n')
        for line in lines:
            if line.strip():
                log_entry = LogEntry(line.strip())
                self.log_entries.append(log_entry)

    @property
    def length(self):
        return len(self.log_entries)

    def item(self, index):
        return self.log_entries[index]

    def count_journeys(self):
        """
        TODO: Write a function named count_journeys() that returns
        how many complete journeys there are in the given LogFile.

        A complete journey consists of:
  • A driver entering the highway through an ENTRY
    您好!
    本帖隐藏的内容需要积分高于 188 才可浏览
    您当前积分为 0。
    使用VIP即刻解锁阅读权限或查看其他获取积分的方式
    游客,您好!
    本帖隐藏的内容需要积分高于 188 才可浏览
    您当前积分为 0。
    VIP即刻解锁阅读权限 或 查看其他获取积分的方式
    Unlock interview details and practice with AI
    Popular Interview Questions from Top Companies
    MAINROAD
    91874.493 JOX304 280E EXIT
    91982.102 THX138 290E EXIT
    92301.302 THX138 300E ENTRY
    92371.302 THX138 310E EXIT"""

        lf = LogFile(sample_log)
        assert lf.count_journeys() == 3, f"Expected 3, got {lf.count_journeys()}"
        print("test_count_journeys: OK")


    def test_catch_speeders():
        # TST002: 10km in 275 sec => ~130.91 km/h (speeder, 1 journey)
        # TST003: two segments both >= 120 km/h (speeder, 2 journeys)
        sample_log = """1000.000 TST002 270W ENTRY
    1275.000 TST002 260W EXIT
    2000.000 TST003 270W ENTRY
    2300.000 TST003 260W MAINROAD
    2601.000 TST003 250W EXIT
    5000.000 TST003 270W ENTRY
    5301.000 TST003 260W MAINROAD
    5602.000 TST003 250W EXIT"""

        lf = LogFile(sample_log)
        ticket_list = lf.catch_speeders()

        assert len([t for t in ticket_list if t == 'TST002']) == 1
        assert len([t for t in ticket_list if t == 'TST003']) == 2
        assert len(set(ticket_list)) == 2
        print("test_catch_speeders: OK")


    if name == 'main':
        test_log_entry()
        test_count_journeys()
        test_catch_speeders()
        print("\nAll tests passed!")

评分

参与人数 1大米 +5 收起 理由
匿名用户-H4NX3 + 5 感谢分享!

查看全部评分


上一篇:purestorage 面筋
下一篇:求人类学Anthropic VO Coding Q3
地里匿名用户
推荐
匿名用户-D7NMY  2026-4-21 09:47:23
这破公司看见就来气,recruiter跟我约30分钟的电话,问东问西扯了一个小时,到最后问我薪资要求,说给不到,扭头给拒了。
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-8HUJT  2026-9-10 12:23:29
那是全栈面试,还是仅针对后端的面试?
回复

使用道具 举报

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

本版积分规则

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