Leorium
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    # 2025 年「資訊科技產業專案設計」課程第 1 次作業 > Richard 理查 ## Introduction ### Interviewer Hi Richard. Thanks for joining us today. I'm Dave, ML Lead Engineer at Moogle. And I’ll be leading this interview. We'll start with a quick chat with you, then move into some technical questions, and wrap up your questions with us. This is a conversation, not an interrogation, feel free to think out loud. We will use Hackmd for our interview. So, first of all, could you tell me more about yourself and walk me through your background? ### Interviewee Well. Thanks for having me here. My name is Richard. I just graduated from NFU (National Failure University) at Computer Science department this June. I have done several projects during my college journey. The most prominent one is ChickNovel, it currently got 10K monthly users, and it is primarily served as a next-generation social media alternative. ### Interviewer Cool. That is a great project, looking forward to future developments. So let's move on to the next part. ## [21. Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/description/) - Easy ### Interviewer In this part, we are going to evaluate your programming knowledge. Imagine this situation, we got two real-time data streams delivering sensor readings that come from two distinct servers that are based in different regions. You'll need to create a merged stream that maintains the sorted time-order for further analysis. The data streams are stored as linked list. How would you solve this problem? ### Interviewee (Repeat) Okay. So you would like me to merge two linked lists coming from different servers into one that is sorted in ascending time-order right? ### Interviewer Correct. ### Interviewee (Example) Cool. So, I would like to create a dummy input like this. Let list1 contain 1, 3, 7, and 8, and list2 contain 2, 5, and 9. > list1 = [1, 3, 7, 8] > list2 = [2, 5, 9] And the dummy output would be 1, 2, 3, 5, 7, 8, 9. > result = [1, 2, 3, 5, 7, 8, 9] Is my assumption correct? ### Interviewer Yes. So, how would you approach this problem? ### Interviewee (Approach) Okay. So, I will try to create a basic structure for the linked list, it contains a timestamp stored as an integer, and a value that stores sensor data, and a pointer that points to the next node. This is a singly linked list. ### Interviewer Can you explain why you choose to use singly linked list? ### Inteviewee Sure. The reason for choosing this approach is simplicity. If we are ever going to merge two sorted lists. It is unlikely that we need to access the previous node, so singly linked list is the most suitable for this scenario. ### Interviewer Okay. Then, for this case, we will only consider the singly linked list approach. Please continue with your approach. ### Interviewee Yeah. So the next part would be how should we merge two sorted linked list. My first intuition would be to use a temporary pointer for the head of the merged list. Then, I would create a indirect pointer that points to the head we created. Then, I will use a for-loop to iterate through each node in list1 and list2. Inside the loop body, I will determine whether one node has bigger value than the other node or not. If that is true, then I will store the greater-valued node using the indirect pointer. If the statement is false, then vice versa. And after each operation, point the current stored list to the next node. ### Interviewer Talk is cheap, show me the code. ### Interviewee (Code) First, I will define the List struct as such: ```c struct ListNode { int timestamp; int value; struct ListNode* next; }; ``` Then I will create a function to merge two linked lists. ```c struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) { struct ListNode* head = NULL; struct ListNode** ptr = &head; } ``` ### Interviewer Wait. So why do you need an extra pointer for indirection? ### Interviewee So the reason for this approach is that we want to avoid memory allocation for this case. If we use malloc instead of indirect pointer, then we need to free it somewhere else, the lifetime of this object is handed to the user, which might increase memory usage if the function caller does not free the list. ### Interviewer OK. ### Interviewee I'll continue to complete the code. So, I would use a while-loop where it ends when both list nodes are empty. Let's just assumes that the last node is NULL. Inside the loop body, we first compare the timestamp for list1 and list2, if the value in list1 is bigger, then we dereference ptr and assign it to list1. Then, we move list1 to its next node. We do the opposite if the first timestamp is greater than or equal to value2. At the end of each iteration, we move ptr to its next node. ```c ... while (list1 && list2) { if (list1->timestamp < list2->timestamp) { *ptr = list1; list1 = list1->next; } else { *ptr = list2; list2 = list2->next; } ptr = &(*ptr)->next; } return head; } ``` ### Interviewer Okay. So did you find any edge cases your code didn't catch? ### Interviewee (Test) Alright. I will try to run it with my dummy input. The input i mentioned earlier is: > list1 = [1, 3, 7, 8] > list2 = [2, 5, 9] And the dummy output is: > result = [1, 2, 3, 5, 7, 8, 9] each number represents seconds. so in real data, we can represents it as 20250901132501 (2025/09/01 13:25:01) Also, this number need 64-bit int to store, but here I use int for convenience. So, let me go thorugh each cases. ### Interviewee (Optimize) Oh. I see a bug there, I forgot to take into account the case where the two list aren't equal in number of nodes. So, I can add this LoC to make the code more complete. So the idea is that when it traverse all the nodes, we might have a scenario where the number of list nodes in these two lists aren't equal; therefore, we need to choose one node as the last node of the merged list. ```c *ptr = list1 ? list1 : list2; ``` ### Interviewer So. Could you tell me the time complexity and space complexity of this mergeTwoLists function? ### Interviewee Yes. The time complexity is O(n+m) (worst case), and space complexity is O(1). n and m is the number of nodes in list1 and list2. Because we need to iterate through them and rewire existing nodes. So the time complexity is these two numbers combined, or O(n+m). For space complexity, since only keep a few pointers in the function, therefore, it is O(1). ### Interviewer Okay. I think that's all for the first problem. Let's move on to the next one. ## [190. Reverse Bits](https://leetcode.com/problems/reverse-bits/description/) - Easy ### Interviewer Okay. So for the second problem, you need to create a function that reverses bits. In many low-level protocols, the bit order on the wire doesn’t always match the way we represent bytes in memory. For example, the USB protocol defines each byte is transmitted least significant bit first. What this means is that if we capture the raw USB traffic, we might need to reverse the bit order to understand what was sent. So, how would you approach this problem with the bits being a 32-bit unsigned integer? ### Interviewee (Repeat) Okay. So I will need to create a reverse bits function for 32-bit unsigned integer, right? ### Interviewer Correct. ### Interviewee (Example) So for example: | IO | Binary | | -------- | -------- | | Input | 00000000000000000000000000011100 | | Output | 00111000000000000000000000000000 | The function will reverse the bits as shown in output. Is my assumption correct? ### Interviewer Yes. ### Interviewee (Approach) So, my approach to this problem is to use a for-loop that iterates through each bit then use a bitwise shift operator to find each bit and shift it start from MSB. ### Interviwee (Code) I will now try to code it. ```c uint32_t reverseBits(uint32_t n) { uint32_t res = 0; for (int i = 0; i < 32; i++) { res |= ((n >> i) & 1) << (31 - i); } return res; } ``` ### Interviewee (Test) I will use the example to validate this function. | IO | Binary | | -------- | -------- | | Input | 00000000000000000000000000011100 | | Output | 00111000000000000000000000000000 | ### Interviewer Great. That is a good approach to this problem. But, can you not use for-loops in your solution? ### Interviewee (Optimize) Okay. I will try my best to do it. My first idea is to use bit masks. Since the width of the input are fixed at 32 bits, we can take advantage of that. Also, we don't need to list out 32 possiblities for reversing. We can do as such: First, we can swap the first 16 bits with the last 16 bits. Then, we can swap every 8-bit chunk Then, we can swap every 4-bit chunk Then, we can swap every 2-bit chunk Then, we can swap every bit with its neighbor. For example, if we want to reverse 0100, we can separate it into 01 and 00 and swap their position So, the new bit order becomes 0001. And then, we swap the bits with its neighbor. This then turns the bits into 0010 which is the reverse of 0100. So. I'll change the code with our new approach using bit masks. ```c uint32_t reverseBits(uint32_t n) { n = (n >> 16) | (n << 16); n = ((n & 0xFF00FF00) >> 8) | ((n & 0x00FF00FF) << 8); n = ((n & 0xF0F0F0F0) >> 4) | ((n & 0x0F0F0F0F) << 4); n = ((n & 0xCCCCCCCC) >> 2) | ((n & 0x33333333) << 2); n = ((n & 0xAAAAAAAA) >> 1) | ((n & 0x55555555) << 1); return n; } ``` ### Interviewer Great. That is a solid solution. So what is the Time & Space Complexity for this function you coded? ### interviewee This function is basically constant in time and space complexity, which means O(1). But it is more efficient than my previous for-loop solution though they are all in O(1). ### interviewer Great. Let's move on to our final problem. ## [322. Coin Change](https://leetcode.com/problems/coin-change/description/) - Medium ### Interviewer For our final question: you are given an integer array coins (denominations) and an integer amount (target sum), write a function that returns the minimum number of coins needed to make up that amount. If it’s not possible, return -1. You can assume infinite supply of each coin. ### Interviewee (Repeat) So, i will need to create a fucntion that calculates the minimum number of coins required to reach the target sum. Is that correct? ### Interviewer Yes. ### Interviewee (Example) So, I would first create an example. For example, if we have an array of ints like this: [1, 3, 4, 5] If the target sum is 7. The minumun number of coins required for this is 2, which contains the 3 and 4 denomination. Is my assumption correct? ### Interviewer Yes, it is correct. ### Interviewee (Approach) So, my approach to this problem would be using dynamic programming. I will first define an array of length amount + 1 and each element having the value of amount + 1. The length of the array is incremented by one because we need to consider where the amount is 0, meaning the target sum is 0 so the output would be 0, which means we need 0 coins. Next, I set each element to amount + 1 because we are calculating the minimum number of coins required. So, having a number exceeding the amount whould serve as a maximum value that no one can reach. Take our above example we should transform this idea into code: The idea is that we want to create a bottom-up solution using dynamic programming. let's bring back our example: [1, 3, 4, 5] for each element inside the array, we define it as such: ```c dp[0] = 0 dp[1] = 1 dp[2] = 1 + dp[1] = 2 dp[3] = 1 dp[4] = 1 dp[5] = 1 dp[6] = min(1 + dp[5], 1 + dp[3], 1 + dp[2], 1 + dp[1]) = min(2, 2, 3, 2) = 2 dp[7] = min(1 + dp[6], 1 + dp[4], 1 + dp[3], 1 + dp[2]) = min(3, 2, 2, 3) = 2 ``` This is a proof-of-concept of how it should operate. ### Interviewer Okay. I can see you trying hard to solve this problem. Can you implement your approach in C? ### interviewee (Code) Sure. I'll implement it in C. ```c int coinChange(int* coins, int coinsSize, int amount) { int dp[amount + 1]; for (int i = 0; i <= amount; i++) dp[i] = amount + 1; dp[0] = 0; for (int i = 0; i <= amount; i++) { for (int k = 0; k < coinsSize; k++) { int c = coins[k]; if (c <= i && dp[i - c] + 1 < dp[i]) dp[i] = dp[i - c] + 1; } } int ans = (dp[amount] > amount) ? -1 : dp[amount]; return ans; } ``` ### Interviewee (Test) I will use the example a wrote earlier for testing. [1, 3, 4, 5] ### Interviewer Great. In addition to that, can you tell me the time and space complexity of this function? ### Interviewee So the time complexity is O(coinsSize * amount) = O(mn) and the space complexity is O(amount) = O(n). ### Interviewer Great job. That’s all for today’s interview. Thanks again for your time and effort today, it was great hearing your thought process and seeing how you approached the problems. We’ll follow up with you soon.

    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