--- title: 資訊科技產業專案設計課程作業 5 --- # 資訊科技產業專案設計課程作業 5 > 貢獻者: 艾睡覺 Sleep :::warning behaviour question 在哪? :notes: jserv ::: ## Problem ### Busiest Time in The Mall :::spoiler The Westfield Mall management is trying to figure out what the busiest moment at the mall was last year. You’re given data extracted from the mall’s door detectors. Each data point is represented as an integer array whose size is 3. The values at indices 0, 1 and 2 are the timestamp, the count of visitors, and whether the visitors entered or exited the mall (0 for exit and 1 for entrance), respectively. Here’s an example of a data point: [ 1440084737, 4, 0 ]. Note that time is given in a Unix format called Epoch, which is a nonnegative integer holding the number of seconds that have elapsed since 00:00:00 UTC, Thursday, 1 January 1970. Given an array, data, of data points, write a function findBusiestPeriod that returns the time at which the mall reached its busiest moment last year. The return value is the timestamp, e.g. 1480640292. Note that if there is more than one period with the same visitor peak, return the earliest one. Assume that the array data is sorted in an ascending order by the timestamp. Explain your solution and analyze its time and space complexities. Example: input: data = [ [1487799425, 14, 1], [1487799425, 4, 0], [1487799425, 2, 0], [1487800378, 10, 1], [1487801478, 18, 0], [1487801478, 18, 1], [1487901013, 1, 0], [1487901211, 7, 1], [1487901211, 7, 0] ] output: 1487800378 # since the increase in the number of people # in the mall is the highest at that point Constraints: [time limit] 5000ms [input] array.array.integer data 1 ≤ data.length ≤ 100 [output] integer ::: ## 面試討論 * 每個 item 有三個參術,請問這三個參數分別代表什麼? * 第一個:代表進出入賣場的時間點 * 第二個:代表進出入賣場的人數 * 第三個:代表該時間點的人數是進入賣場還是離開。e.g. 0:離開, 1:進入 * 應該要輸出時間點最後一個狀態的人數 ## 程式碼 ```python def find_busiest_period(data): people = 0 ans = 0 ori_time = data[0][0] time_ans = data[0][0] time = data[0][0] for i in range(len(data)): pre_time = time time = data[i][0] people_num = data[i][1] state = data[i][2] pre_people = people if time != ori_time: ori_time = time if pre_people > ans: ans = pre_people time_ans = pre_time if (state): people += people_num else: people -= people_num if people > ans: time_ans = time return time_ans ``` ## 改進方案 * 對於語法的不熟悉 * 因為 interviewer 是會 python ,所以我也就使用 python 來寫,但有一些地方有卡住 * 如果有些語法不熟悉,可以實用其他方式來寫,避開當下不熟悉的語法 * 演算法的說明不夠清楚 * 有寫到一半,然後被 interviewer 說不了解我的 approach * 原本說明都是用口述,可能可以改成先把 pseudo code 寫出來 ## 學期表現 在第一次作業時,有學到 REACTO 的技巧,在第五次作業實際跟人面試時也有用上,也發現對方也有是用這個方法,Repeat ,Example , Approach, Code, Test,這次使用 Example 步驟時,針對題目實例,一一探討程式行為時,也有讓面試官發現她自己題目說明有些問題,才沒有發生寫一大半程式碼後,才發現方向完全錯誤的事情,面試完之後也有互相討論題目的解法,有哪些多餘的步驟可以省略,也發現自己其實是可以用英文跟別人溝通的,並沒有想像中可怕,雖然有些講的不流利,或是文法有錯,但靠著一些例子說明,大部份都還是可以理解的。 在第四次的作業中,我們需要去了解比較有名的軟體公司,挑選出自己想要去的公司,掌握自己目前的狀態,看看自己還有哪些不足,針對職缺做優劣分析,也因為這樣,找到了該職缺常考的面試題目,透過準備這些題目,讓自己未來在面試時不至於手忙腳亂。 在聽到很多學長姐自我介紹,了解到他們的經歷,有看到他們都是成大畢業,因為在某些領域找到自己感興趣的方向,認真花心思在上面,不斷的堆疊該領域的知識,以至於之後可以進到更好的公司,讓人相信如果願意努力的投注心力,自己可能有一天也能進到很棒的公司。 在聽完 Ian Tsai 學長的介紹後,覺得有看到一些新的方向,像是學長說到他最開始選擇新創的原因,以及他是如何判斷一間公司有沒有前景的方法,因為聽完後覺得深受啟發,所以後來也到 ptt 看了相關的文章,他說:「『真正的活著』建立在一連串殘酷的選擇上,進修,磨練,離鄉背井,告白,分手 ,殘酷來自於任何選擇都帶來犧牲,犧牲朋友,家庭,玩樂,健康,如果不選就是上天來選,這世界對不敢犧牲的人最殘酷」,這些話給了我很大的啟發,我目前的狀態就如他所說:「大學唸完,接著念碩士,很多都是懶惰,僵化,逃避思考」,就跟我當初可能逃避選擇要做什麼工作,所以才來念研究所的心境相符,而且不管逃避多久,最終總是要面對,Ian 的話也給我一些鼓勵了吧。 自我評分:8分 ![](https://i.imgur.com/NC6F9X3.png)