sysprog
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2023 年「[資訊科技產業專案設計](https://hackmd.io/@sysprog/info2023)」作業 1 > 貢獻者: 卑鄙葛摟-Babygirl > 🧔:interviewer 👶:interviewee ## [21. Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) > [模擬面試影片(英)](https://www.youtube.com/watch?v=p5--6z5rnvo) ### 測驗說明與回答 🧔 : Hi,I am your interviewer. Here is the first question. You are given the heads of two sorted linked lists `list1` and `list2`. Could you merge the two lists in a non-decreasing sorted list? The list should be made by splicing together the nodes of the first two lists. And return the head of the merged linked list. 👶 : Okay, I have to deal with merging two sorted linked lists into a non-deccreasing sorted linked list. For example, `list1=[1,2,4]`,`list2=[1,3,4]`, `Output=[1,1,2,3,4,4]`. 👶 : I think I will use iterative approach to solve this problem. Use the while loop and iterate through the array comparing the two current node's value. To decide which current node to add to the merge list. So the time complexity is $O(|list1|+|list2|)$. 🧔 : Remember to consider empty linked lists. You can start to implement. 👶 : First, I check whether `list1` and `list2` are empty. If one of them is empty, I directly return the other list. Then maintain a head pointer and a current pointer on the merged linked list. And by comparing the first nodes of the two linked lists, the smaller node is used as the head of the merged linked list. I use the while loop to comparing the node of two linked lists sequentially. For all subsequent nodes in this two lists, I compare the current nodes of the two linked lists, So I choose the smaller current node and link it to the tail of the merged list, and moving the current pointer of that list to the next node. After adding a node to the merged linked list, the pointer of the merged list also points to the next node. I continue this operation when there are some remaining elements in both lists. Finally, if there are still some elements in only one list, this remaining list is linked to the tail of the merged list. ```cpp struct ListNode { int val; struct ListNode *next; }; struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2){ if(list1 == NULL) return list2; if(list2 == NULL) return list1; struct ListNode *head = list1; if(list1->val > list2->val) head = list2; struct ListNode *curr = malloc(sizeof(*curr)); while( list1 && list2) { if( list1->val <= list2->val) { curr->next = list1; list1 = list1->next; } else if( list1->val > list2->val) { curr->next = list2; list2 = list2->next; } curr = curr->next; } if(list1) curr->next = list1; if(list2) curr->next = list2; return head; } ``` 🧔 : Could you deal with recursive approach? 👶 : Yes, I can use the same concept to find the node with the smaller value in these two lists and splice them into a merged linked list. ```cpp struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2){ if(list1 == NULL) return list2; if(list2 == NULL) return list1; if( list1->val <= list2->val) { list1->next = mergeTwoLists(list1->next, list2); return list1; } else { list2->next = mergeTwoLists(list1, list2->next); return list2; } } ``` 🧔 : What is different between recursion and iteration? 👶 : About space, iteration can avoid the waste of space resources. If there are a lot of nodes, recursion may cause stack overflow. 👶 : About efficiency, recursion and iteration are similar. ## [206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) > [模擬面試影片(漢)](https://youtu.be/e0xsQr8mT3s) ### 測驗說明與回答 🧔 : 我會提供你一個指向一個 linked list 的指標叫做 `head`,反轉該列表並回傳。 👶 : 好的,我可以使用迭代的方法,在這裡我用到兩個指標來進行反轉,一個指標指向當前節點,另一個指標指向當前節點的前一個節點,當我遍歷該 linked list,依次反轉每一個指標,最後實現整個 linked list 的反轉。 ``` curr 1 -> 2 -> 3 -> NULL prev curr NULL <- 1 -> 2 -> 3 -> NULL prev curr NULL <- 1 <- 2 -> 3 -> NULL prev curr NULL <- 1 <- 2 <- 3 -> NULL prev NULL <- 1 <- 2 <- 3 ``` 🧔 : 好,你可以開始實作了。 ```cpp /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode* reverseList(struct ListNode* head){ struct ListNode* prev = NULL; struct ListNode* curr = head; while(curr != NULL){ struct ListNode* forward = curr->next; curr->next = prev; prev = curr; curr = forward; } return prev; } ``` 👶 : 時間複雜度為 O(n),空間複雜度為 O(1)。 🧔 : 這邊你有辦法改成用遞迴來實作嗎? 👶 : 可以的,遞迴的方法會不停呼叫函式直到最後一個節點,再將它的 next 指向前一個節點,依序返回直到遞迴結束。 ``` curr 1 -> 2 -> 3 -> NULL curr 1 -> 2 -> 3 -> NULL curr 1 -> 2 <- 3 curr 1 -> 2 <- 3 curr NULL <- 1 <- 2 <- 3 ``` 🧔 : 好,你可以開始實作了。 ```cpp struct ListNode* reverseList(struct ListNode* head){ if(head == NULL || head->next == NULL) return head; struct ListNode *prev = reverseList(head->next); head->next->next = head; head->next = NULL; return prev; } ``` 👶 : 在這裡因為使用到 stack 空間的關係,空間複雜度會是 O(n)。 ## [287. Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) > [模擬面試影片(漢)](https://youtu.be/e0xsQr8mT3s) ### 測驗說明與回答 🧔 : 我會提供妳一個包含 n + 1 個整數的整數陣列 `nums`,其中每個整數都在 [1, n] 範圍內(含)。而 `nums` 中只有一個重複的數字,請妳找出這個重複的數字。過程中不能修改 `nums`。 👶 : 好的,我的想法是額外使用一個陣列 `array` 來解決找出重複數字的問題。通過遍歷 `nums`,使用額外的 `array` 來記錄每個元素是否已經被訪問過。 🧔 : 這個方法的空間複雜度會是如何? 👶 : 會是 O(n) 。 🧔 : 請妳換個方法來保證只使用到常數額外空間。 👶 : 因為至少有一個數字重複,所以當遍歷 `nums` 時一定會進入一個循環。這個問題可以用 cycle detection 的方法來解決,也就是使用兩個指標 `slow` 和 `fast` 來追蹤數字,會分成兩步驟,第一個步驟檢查循環的存在,第二個步驟找到循環的起始點,也就是找到重複的數字。 👶 : 在第一步驟我們想要檢查循環的存在,當指標 `slow` 和 `fast` 從起點開始,`slow` 每次走一格,`fast` 每次走兩格,一直走下去如果它們能相遇,代表存在一個環。反之,若不存在環的話,兩個指標永遠不會相遇。而它們相遇的地點可能是在循環的任何位置,不一定是循環的起始點。 👶 : 在第二步驟我們想要找到循環的起始點,因為環周長減掉循環的起始點至相遇點的距離會等於從起點至環的起始點的距離,也就是說 `slow` 回到起點並每次走一格, `fast` 繼續每次走一格,它們再次相遇的點會是循環的起始點,就可以找到重複的數字。 ``` 環周長 - 循環的起始點至相遇點的距離 = 起點至環的起始點的距離 ``` 🧔 : 好,你可以開始實作了。 ```cpp int findDuplicate(int* nums, int numsSize){ int slow = nums[0]; int fast = nums[0]; do{ slow = nums[slow]; fast = nums[nums[fast]]; } while (slow != fast); slow = nums[0]; while(slow != fast) { slow = nums[slow]; fast = nums[fast]; } return slow; } ``` --- ## 第二次作業-他評01 ### 關於interviewer - [ ] 可改進之處 * [7:37](https://youtu.be/p5--6z5rnvo?t=457): 我覺得直接講說可不可以用recursion表示有點太提示了,或許可以換個講法,像是有沒有辦法用比較少的程式碼來達到目的呢? ### interviewee - [ ] 優點 * Example跟Approach明瞭 👏 - [ ] 可改進之處 * [2:18](https://youtu.be/p5--6z5rnvo?t=138): Merge Two Sorted List,這邊 interviewee 因為一些錯字修改了一下,有點尷尬,我覺得可以不用去修改,因為看得出你想宣告什麼型態。 - [ ] 其他建議 * [12:47](https://youtu.be/e0xsQr8mT3s?t=767): Find the Duplicate Number 在coding之前有講到有關環周長的公式,會希望在講解完之後簡單舉個例子帶入你的想法。 ## 第二次作業-他評02 ### interviewer - [ ] 可改進之處 * [10:33](https://youtu.be/e0xsQr8mT3s?t=633) 可以讓interviewee完成這個方法之後,再進行詢問 ### interviewee - [ ] 優點 * [0:47](https://youtu.be/p5--6z5rnvo?t=47): 主動分析時間複雜度 - [ ] 可改進之處 * [9:03](https://youtu.be/e0xsQr8mT3s?t=543): 避免頻繁畫面捲動 ## 第二次作業-他評03 ### interviewer - [ ] 優點 * 有提點interviewee應注意的細節 * 有提問兩種做法的相異處,可以測試到interviewee對程式的了解,而不是死背。 - [ ] 可改進之處 * [7:42](https://youtu.be/p5--6z5rnvo?si=z3eY1MLudzhL3_AB&t=462), [5:21](https://youtu.be/e0xsQr8mT3s?si=0VplKtVhVBPqEhFP&t=321): 感覺可以先對interviewee目前寫好的code做評論或提問,再請他優化,可能會比請他直接提供另外一種做法要更好 * [0:08](https://youtu.be/e0xsQr8mT3s?si=IVjKj75oolHPmcRN&t=8): 建議可以把題目包裝成另一情境,避免聽到關鍵字就開始背答案導致鑑別度不足,也可以考驗interviewee的理解能力和應變能力 ### interviewee - [ ] 優點 * 邊打code邊講解的很順暢 * [2:33](https://youtu.be/e0xsQr8mT3s?si=2xKOW1CJn-XAU1P8&t=153): 將所舉的例子key出來很清楚詳細,讓人一看就明白 - [ ] 可改進之處 * 可以增加一些肢體動作或停頓(加強)來讓自己的整段對話重點更加突出。 * 較為缺乏REACTO的 Test部分(英) ## 第二次作業-他評04 **Interviewer** - [ ] 優點 * 指示清晰 - [ ] 可改進的地方 * 要變換題型 * 互動太少,感受不到面試官有想認識面試者 * 感覺就很順的放水受試者 **Interviewee** - [ ] 優點 * 咬字清晰,2倍速可聽 * 解釋有邊打字,有個圖示很棒 * 邊coding的解釋很棒,不會尷尬,還會再用簡單文字表示,避免面試官恍神很棒 - [ ] 可改進的地方 * 要遵守"確認,舉例,說明方案,撰寫程式,驗證程式",可能要多確認下問題 * 測試可能要再多一點

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully