嚐味鹽-Yuanson
video: 模擬面試影片(漢)、模擬面試影片(英)
🧔:interviewer
👶:interviewee
🧔:你好,我是今天負責主持面試的David
👶:你好
🧔:希望你可以實作以下題目,有一串數字2~9的字串,每個數字都包含了一些字母,例如2可能表示a,b,c,在給你一串數字的情況下,返回這一串數字可能表示的所有字母組合,下面會給你對應的表格。
👶:好的,我想再跟您確認一下題目的要求,2代表的是a,b,c,3代表的是d,e,f,如果現在有一串數字是23,我應該要表示出這兩個集合能表示出的所有組合嗎,像ad,ae,af,bd,be,bf…
🧔:你的理解是正確的。
👶:嗯…,我預計一開始會使用一開始會使用字典來記錄每個數字對應的字母,後續用一個迴圈來偵測每一輪的數字和其對應的字母,從第一個數字開始逐步將字母組合起來找出答案
🧔:聽起來不錯,你可以開始了
👶:好
🧔:恩 還不錯 但有沒有速度更快的辦法
👶:痾 我想想,我預計會用遞迴的方式寫出一個function,先從最尾端偵測數字,將其代表的字母回傳後再與前一個數字的字母組合,逐步推出答案
🧔:你可以開始了
🧔:很好,那那在第二個問題中,題目提供兩個字串s跟t,他們的長度都是相同的,你需要判斷他們是不是同構的,像add跟egg這種,如果是add跟geg雖然字母數量對的上,但他們不是同構的,同時還要滿足一些條件,像假如a對應到e,那d就不能再對應到e
👶:好的,所以我需要確認兩個字串是不是同構來回傳true or false,如果只是對應字母的數量相同,但位置不一樣的話也不算同構嗎
🧔:沒錯
👶:恩,那我會先寫出兩個字典來記錄每個字分別對應到哪個字,後續寫一個迴圈來依序判斷兩者是否相等,如果是第一次出現的字,會先檢查對應的字有沒有被使用過,沒有的話會將這兩個字母記錄在字典中,後續再出現相同字母的話,再來判斷他們對應的跟字典上記錄的是不是一樣的,最後判斷結果
🧔:好~你可以開始了
🧔:還不錯,但顯得有點複雜,有沒有方法可以幫助你簡化這段程式碼呢
👶:恩…我知道了,我馬上就可以實作
🧔:好的,請隨時開始
🧔:恩,你表現得很好,請隨時留意信箱有關第二次英語面試的通知
🧔:Hello, Yuanson, I'm David. Welcome to the second round of the interview. Let's get started
👶:hi, i'm ready
🧔:ok,Here's question,given a binary array nums, return the maximum number of consecutive 1's in the array.
👶:Alright, it's a binary array, so I'll have an array that consists only of 0s and 1s, and I need to find the length of the longest consecutive sequence of 1s.
🧔:right
👶:I guess I could use a for loop to iterate through the entire string. I'll use two variables: one for the current length and another for the maximum length. Whenever I encounter '1', I'll increment the current length; if I encounter '0', it will reset to zero. I will compare the current length with the maximum length and update the maximum length
🧔:sounds good, feel free to code it
🧔:good, Is there any way to speed up the program?
👶:Ummm, sure I can do it
🧔:Well done, please wait for the following email
👶:thank you
generate_string(i)
,解釋這個 function 的功能,然後才開始實作generate_string
沒有被呼叫到,且 digits
非空時沒有回傳值