diff --git a/content/notes/cli-bootable-usb-from-iso/index.md b/content/notes/cli-bootable-usb-from-iso/index.md new file mode 100644 index 0000000..6488558 --- /dev/null +++ b/content/notes/cli-bootable-usb-from-iso/index.md @@ -0,0 +1,19 @@ ++++ +title = 'CLI: Bootable USB From ISO' +date = 2024-03-31T09:29:19-23:53 +draft = false ++++ + +Check if flash drive is properly plugged and identify its label (something like `/dev/sda`): + +```bash +sudo fdisk -l +``` + +Run `dd` command to make a bootable USB from the ISO file: + +```bash +sudo dd bs=4M if=/path/to/file.iso of=/dev/sdX status=progress oflag=sync +``` + +Replace `/path/to/file.iso` with the path to your ISO file and replace `/dev/sdX` with the name of your device. diff --git a/content/notes/coding-interview-technical-questions/index.md b/content/notes/coding-interview-technical-questions/index.md new file mode 100644 index 0000000..0e3f8c8 --- /dev/null +++ b/content/notes/coding-interview-technical-questions/index.md @@ -0,0 +1,79 @@ ++++ +title = 'Coding Interview: Technical Questions' +date = 2024-03-09T07:50:00-00:00 +draft = false ++++ + +# Walking Through A Problem + +1. **Listen**: pay attention very closely +2. **Example**: debug your example and find special cases +3. **Brute force**: state a naive algorithm and then optimize it +4. **Optimize**: BUD Optimization or look (or ask) for unused info, make time vs. space tradeoff +5. **Walk Through**: make sure you understand each detail of your optimal solution before coding +6. **Implement**: modularize your code from the beginning and refactor +7. **Test**: code review, look for hot spots and special and edge cases + +### Technique #1: BUD Optimization + +Acronym for **B**ottlenecks, **U**nnecessary work and **D**uplicated work. Bottleneck is a part of your algorithm that slows down the overral runtime. Common ways this occurs are having one-time work that slows down your algorithm and having a chunk of work that is done repeatedly (like searching). Then look for unnecessary and duplicated work. + +### Technique #2: Do It Yourself + +Use a nice, big example and intuitively solve it. Think hard about how you solved it and reverse engineer your own approach. + +### Technique #3: Simplify And Generalize + +Multi-step approach that simplify some constraint (such as the data type). Solve the simplified version of the problem and then adapt for a more complex version. + +### Technique #4: Base Case And Build + +Solve the problem first for a base case and then build up for more complex cases. Generally lead to recursive algorithms. + +### Technique #5: Data Structure Brainstorm + +Solving a problem may be trivial once it occurs to use a specific data structure. The more problems you do, the more developed your instinct on which data structure to apply will be. + +# Handling Situations + +### Handling Incorrect Answers + +Candidates don't need to get every question right. You will be evaluated about how optimal your final solution was, how long it took to get there, hhow much help you needed, and how clean was your code. You will also be evaluated in comparison to other candidates and the questions my be too difficult to expect even a strong candidate to immediately spit out the optimal algorithm. + +### When You've Heard A Question Before + +If it occurs, admit this to your interviewer. Otherwise it may be highly dishonest if you don't reveal that you know the question and, conversely, you'll get big honesty points if you do reveal this. + +### The Perfect Language For Interviews + +Many top companies interviewers aren't picky about languages. Choose whatever language you're most comfortable with considering some points. + +- **Prevalence**: It's ideal for your interviewer to know the language you're coding in. Prefer widely known languages. +- **Readability**: Languages such as Scala or Objective-C have fairly different syntax. +- **Potential Problems**: For example, using C++ means that, in addition to all the usual bugs you can have in your code, you can have memory management and pointer issues. +- **Verbosity**: Languages with simple syntax may be preferred, but some verbosity can be reduced by abbreviating code (most interviewers wouldn't mind) +- **Ease of Use**: Some operations are easier in some languages than others. + +# Writing Good Code + +A good code is correct, efficient, simple, readable and maintainable. Striving for these aspects requires a balancing act. For example, it's often advisable to sacrifice some degree of efficiency to make code more maintainable, and vice versa. + +### Use Data Structures Generously + +Design your own data structure may be a good solution in some cases. It's a good point to evaluate with the interviewer. Some might argued that this is over-optimizing. + +### Modular + +Separate isolated chunks of code out into their own methods. This helps keep the code more maintainable, readable, testable and reusable. + +### Flexible And Robust + +Use variables instead of hard-coded values, use templates to solve a problem. You should write your code to solve a more general problem. + +### Error Checking + +Adopt failing fast and don't make assumptions about the input. If the error checks are much more than a quick if-statement, it may be best to leave some space where the error checks would go and indicate to your interviewer that you'll fill them in when you're finished with the rest of the code. + +# Don't Give Up! + +Interview questions can be overwhelming, but this is how they are supposed to be. It shouldn't be a surprise when you get a really tough problem. Show excitement about solving hard problems for extra points. diff --git a/content/notes/data-structures/index.md b/content/notes/data-structures/index.md new file mode 100644 index 0000000..36a032d --- /dev/null +++ b/content/notes/data-structures/index.md @@ -0,0 +1,169 @@ ++++ +title = 'Data Structures' +date = 2024-03-09T07:50:00-00:00 +draft = false ++++ + +# Arrays + +A contiguous memory block that stores elements of the same data type. The memory address of the first element in the array is the base address and any other element's address can be calculated using the base address and the size of each element. + +```python +array = [] +array.append(1) +array.append(3) +print(array[1]) # 3 +array.append(2) +print(array.remove(3)) # 3 +print(array.index(2)) # 1 +``` + +### Operations + +- **Access by index**: `O(1)` by calculating the position +- **Access by value**: `O(n)` by traversal +- **Write in the beginning**: `O(n)`, requires shifting elements +- **Write in the end**: `O(1)`, no shifting required + +### Pros And Cons + +**Pros**: Direct access using indexes, contiguous storage minimizes memory overhead, easy to sort. +**Cons**: Fixed (limited) size, inefficient writing due to shifting, unfilled memory keep allocated. + +# Linked List + +```python +class ListNode: + def __init__(self, val=0, next=None): + self.val = val + self.next = next + +class LinkedList: + def __init__(self): + self.head = None +# implements the following methods: +# def append(self, val): +# def remove(self, val): +# def display(self): +``` + +A linear data structure where elements (nodes) are connected through pointers. Doesn't require contiguous memory locations and each node contains a reference to the next one, allowing to be placed anywhere in the memory. + +### Operations + +- **Access by index**: `O(n)` by traversal +- **Access by value**: `O(n)` by traversal +- **Write in the beginning**: `O(1)` by pointing the new node to the old head +- **Write in the end**: `O(n)` by traversing and then pointing the last node to the new + +### Pros And Cons + +**Pros**: Dynamic size, no waste of memory, more efficient writing operations. +**Cons**: Access always requires traversing, node requires extra memory for pointers, traversing have a higher constant factor compared to arrays. + +# Stack + +It's a LIFO-behaved data structure with a pointer to the last element for fast access. The stack itself is a pre-allocated region of memory with a fixed size, and the memory for individual function calls on the stack is dynamically managed. So the nature of the allocation depends on the type of stack and the context in which it's used. + +```python +stack = [] +stack.push(1) +stack.push(3) +print(stack.pop()) # 3 +stack.push(2) +print(stack.pop()) # 2 +print(stack.pop()) # 1 +``` + +### Operations + +- **Access in the end**: `O(1)` by stack pointer +- **Write in the end**: `O(1)` by accessing via stack pointer and updating it + +# Queue + +It's a FIFO-behaved data structure that also can be pre-allocated or dynamically allocated depending on the type and context. + +```python +from collections import deque + +queue = deque() +deque.append(1) +deque.append(3) +print(queue.popleft()) # 1 +deque.append(2) +print(queue.popleft()) # 3 +print(queue.popleft()) # 2 +``` + +### Operations + +- **Access in the beginning/end**: `O(1)` by pointers +- **Enqueue (insertion)**: `O(1)` by accessing via pointer and updating it +- **Dequeue (deletion)**: `O(1)` by accessing via pointer and updating it + +# Hash Map + +It's a key-value pair collection, where each key is unique. It provides operation efficiency (**all operations are** `O(1)`) through memory overhead. Uses hashing function to convert a key into an index and maintains an array where each index corresponds to a bucket that can hold multiple pairs. + +# Set + +It's a unordered collection of distinct elements. Internally uses hash maps and **all operations are** `O(1)`. + +# Binary Tree + +It's a hierarchical data structure in which each node has at most two children and the topmost node is called root. + +### Traversal + +```python +def preorder_print(self, start, traversal): + """Root->Left->Right""" + if start: + traversal += (str(start.value) + "-") + traversal = self.preorder_print(start.left, traversal) + traversal = self.preorder_print(start.right, traversal) + return traversal +``` + +```python +def inorder_print(self, start, traversal): + """Left->Root->Right""" + if start: + traversal = self.inorder_print(start.left, traversal) + traversal += (str(start.value) + "-") + traversal = self.inorder_print(start.right, traversal) + return traversal +``` + +```python +def postorder_print(self, start, traversal): + """Left->Right->Root""" + if start: + traversal = self.postorder_print(start.left, traversal) + traversal = self.postorder_print(start.right, traversal) + traversal += (str(start.value) + "-") + return traversal +``` + +# Heap + +Is a specialized tree-based data structure that satisfies the heap property (for max and min heaps) and **all operations are** `O(log n)`. It's used to implement priority queues, for heap sort and graph algorithms like Dijkstra's. + +```python +import heapq + +min_heap = [] +heapq.heappush(min_heap, 4) +heapq.heappush(min_heap, 1) +heapq.heappush(min_heap, 3) +min_element = heapq.heappop(min_heap) +print(min_element) # 1 + +max_heap = [] +heapq.heappush(max_heap, -1) +heapq.heappush(max_heap, -4) +heapq.heappush(max_heap, -3) +max_element = -heapq.heappop(max_heap) +print(max_element) # 4 +``` diff --git a/content/notes/interview-storytelling/index.md b/content/notes/interview-storytelling/index.md new file mode 100644 index 0000000..a2c1f2b --- /dev/null +++ b/content/notes/interview-storytelling/index.md @@ -0,0 +1,40 @@ ++++ +title = 'Interview Storytelling' +date = 2024-03-10T12:58:19-23:53 +draft = false ++++ + +This post is inspired in a [video from A Life Engineered](https://www.youtube.com/watch?v=hU6BVxtGd5g) that gives many advices about telling good stories. He also explains how STAR model is more like a linter than a way to structure your story and compare it with U-shape model. This is also a fast cheatsheet, I won't talk about any of these topics in depth. + +### General Tips + +- Present yourself very quickly +- Do your homework and bring questions to the interviewers +- Talk about what you've done, not your team +- Challenges may be compatible with the level you aim +- Anchor your status and show that you can handle challenges of your level +- Show your career progression and growth mindset +- Have a good story to tell about your journey in programming + +### U-shape + +- Stablish **status** about yourself +- Explain the **challenge** and then deep dive into it +- Introduce **obstacles** +- **Climb** until the situation is proportionally better than how it started +- Make sure that you have an **imperfect solution** + +### STAR Model + +- Describe a **situation** +- Explain the **task** that you had to complete +- Describe the **actions** you took +- Show the **results** op your efforts + +### Most Frequent Questions + +- Challenging project/task +- Improvements in your team +- Successful projects +- Handling feedbacks +- 3 strengths and weaknesses diff --git a/content/notes/sorting-algorithms/index.md b/content/notes/sorting-algorithms/index.md new file mode 100644 index 0000000..7fc6b13 --- /dev/null +++ b/content/notes/sorting-algorithms/index.md @@ -0,0 +1,134 @@ ++++ +title = 'Sorting Algoithms' +date = 2024-03-10T15:24:15-00:00 +draft = false ++++ + +First we have to keep some concepts in mind. + +- **Inplace/Outplace**: use/don't use extra memory +- **Unstable/Stable**: position order change/don't change for repeated values + +### Selection Sort + +Divides the input list into a sorted and an unsorted region. Repeatedly selects the smallest element from the unsorted region and swaps it with the first element in the unsorted region. + +- Inplace and unstable +- O(n2) time and O(1) space + +```python +def selection_sort(arr): + for i in range(len(arr)): + min_idx = i + for j in range(i+1, n): + if arr[j] < arr[min_idx]: + min_idx = j + arr[i], arr[min_idx] = arr[min_idx], arr[i] +``` + +### Insertion Sort + +Builds a sorted portion of the list one element at a time. Iterates through the unsorted portion, selects an element, and inserts it into its correct position in the sorted portion. + +- Inplace and stable +- O(n2) time and O(1) space + +```python +def insertion_sort(arr): + for i in range(1, len(arr)): + key = arr[i] + j = i - 1 + while j >= 0 and key < arr[j]: + arr[j + 1] = arr[j] + j -= 1 + arr[j + 1] = key +``` + +### Bubble Sort + +Repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. Pass through the list is repeated until no swaps are needed, indicating the list is sorted. + +- Inplace and stable +- O(n2) timg and O(1) space + +```python +def bubble_sort(arr): + for i in range(len(arr)): + for j in range(0, len(arr)-i-1): + if arr[j] > arr[j+1]: + arr[j], arr[j+1] = arr[j+1], arr[j] +``` + +### Merge Sort + +Divides the list into two halves recursively until each sublist contains a single element. Merges the sorted sublists back together, comparing elements to arrange them in the correct order. + +- Outplace and stable +- O(n log n) time and O(n) space + +```python +def merge_sort(arr): + if len(arr) <= 1: + return arr + + mid = len(arr) // 2 + left_half = arr[:mid] + right_half = arr[mid:] + + left_half = merge_sort(left_half) + right_half = merge_sort(right_half) + return merge(left_half, right_half) + +def merge(left, right): + result = [] + i = j = 0 + + while i < len(left) and j < len(right): + if left[i] < right[j]: + result.append(left[i]) + i += 1 + else: + result.append(right[j]) + j += 1 + + result.extend(left[i:]) + result.extend(right[j:]) + return result +``` + +### Quick Sort + +Chooses a pivot element from the array and partitions the other elements into two subarrays according to whether they are less than or greater than the pivot. Recursively sorts the subarrays and concatenates them. + +- Inplace and unstable +- Average: O(n log n) time and O(log n)\* space +- Worst case: O(n2) time and O(n)* space + *because of recursion stack + +```python +def quick_sort(arr): + if len(arr) <= 1: + return arr + + pivot = arr[len(arr) // 2] + left = [x for x in arr if x < pivot] + middle = [x for x in arr if x == pivot] + right = [x for x in arr if x > pivot] + + return quick_sort(left) + middle + quick_sort(right) +``` + +### Heap Sort + +Builds a binary heap (max heap) from the input array. Repeatedly extracts the maximum element (root of the heap) and rebuilds the heap until the array is sorted. Not used as the main sorting algorithms of programming languages because it is unstable. + +- Inplace and unstable +- O(n log n) time and O(1) space + +```python +import heapq + +def heap_sort(arr): + heapq.heapify(arr) + return [heapq.heappop(arr) for _ in range(len(arr))] +``` diff --git a/public/404.html b/public/404.html index dd1c2f3..3905efd 100644 --- a/public/404.html +++ b/public/404.html @@ -31,7 +31,7 @@ - + diff --git a/public/categories/index.html b/public/categories/index.html index 89d4cfe..b03c1c1 100644 --- a/public/categories/index.html +++ b/public/categories/index.html @@ -31,7 +31,7 @@ - + diff --git a/public/index.html b/public/index.html index 4305b1c..6888559 100644 --- a/public/index.html +++ b/public/index.html @@ -30,7 +30,7 @@ - + diff --git a/public/index.xml b/public/index.xml index 39a5840..95feabd 100644 --- a/public/index.xml +++ b/public/index.xml @@ -6,7 +6,56 @@ Recent content on jpcairesf/Blog Hugo -- gohugo.io en-us - Tue, 05 Mar 2024 20:35:51 -0300 + Sun, 31 Mar 2024 09:29:19 -2353 + + Interview Storytelling + http://localhost:1313/blog/notes/interview-storytelling/ + Sun, 10 Mar 2024 12:58:19 -2353 + + http://localhost:1313/blog/notes/interview-storytelling/ + + This post is inspired in a video from A Life Engineered that gives many advices about telling good stories. He also explains how STAR model is more like a linter than a way to structure your story and compare it with U-shape model. This is also a fast cheatsheet, I won&rsquo;t talk about any of these topics in depth. +General Tips Present yourself very quickly Do your homework and bring questions to the interviewers Talk about what you&rsquo;ve done, not your team Challenges may be compatible with the level you aim Anchor your status and show that you can handle challenges of your level Show your career progression and growth mindset Have a good story to tell about your journey in programming U-shape Stablish status about yourself Explain the challenge and then deep dive into it Introduce obstacles Climb until the situation is proportionally better than how it started Make sure that you have an imperfect solution STAR Model Describe a situation Explain the task that you had to complete Describe the actions you took Show the results op your efforts Most Frequent Questions Challenging project/task Improvements in your team Successful projects Handling feedbacks 3 strengths and weaknesses + + + + + Sorting Algoithms + http://localhost:1313/blog/notes/sorting-algorithms/ + Sun, 10 Mar 2024 15:24:15 +0000 + + http://localhost:1313/blog/notes/sorting-algorithms/ + + First we have to keep some concepts in mind. +Inplace/Outplace: use/don&rsquo;t use extra memory Unstable/Stable: position order change/don&rsquo;t change for repeated values Selection Sort Divides the input list into a sorted and an unsorted region. Repeatedly selects the smallest element from the unsorted region and swaps it with the first element in the unsorted region. +Inplace and unstable O(n2) time and O(1) space def selection_sort(arr): for i in range(len(arr)): min_idx = i for j in range(i+1, n): if arr[j] &lt; arr[min_idx]: min_idx = j arr[i], arr[min_idx] = arr[min_idx], arr[i] Insertion Sort Builds a sorted portion of the list one element at a time. + + + + + Coding Interview: Technical Questions + http://localhost:1313/blog/notes/coding-interview-technical-questions/ + Sat, 09 Mar 2024 07:50:00 +0000 + + http://localhost:1313/blog/notes/coding-interview-technical-questions/ + + Walking Through A Problem Listen: pay attention very closely Example: debug your example and find special cases Brute force: state a naive algorithm and then optimize it Optimize: BUD Optimization or look (or ask) for unused info, make time vs. space tradeoff Walk Through: make sure you understand each detail of your optimal solution before coding Implement: modularize your code from the beginning and refactor Test: code review, look for hot spots and special and edge cases Technique #1: BUD Optimization Acronym for Bottlenecks, Unnecessary work and Duplicated work. + + + + + Data Structures + http://localhost:1313/blog/notes/data-structures/ + Sat, 09 Mar 2024 07:50:00 +0000 + + http://localhost:1313/blog/notes/data-structures/ + + Data Structures A very simplified note to cover the most important data structures with examples in python, operations time complexity and trade offs. +Arrays A contiguous memory block that stores elements of the same data type. The memory address of the first element in the array is the base address and any other element&rsquo;s address can be calculated using the base address and the size of each element. +array = [] array. + + + How Blogging Can Leverage Your Tech Career http://localhost:1313/blog/posts/how-blogging-can-leverage-your-tech-career/ diff --git a/public/notes/coding-interview-technical-questions/index.html b/public/notes/coding-interview-technical-questions/index.html new file mode 100644 index 0000000..dc21183 --- /dev/null +++ b/public/notes/coding-interview-technical-questions/index.html @@ -0,0 +1,338 @@ + + + + + +Coding Interview: Technical Questions | jpcairesf/Blog + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Coding Interview: Technical Questions

+ + + + +
+ + +
+ + +
+
+

Walking Through A Problem

+
    +
  1. Listen: pay attention very closely
  2. +
  3. Example: debug your example and find special cases
  4. +
  5. Brute force: state a naive algorithm and then optimize it
  6. +
  7. Optimize: BUD Optimization or look (or ask) for unused info, make time vs. space tradeoff
  8. +
  9. Walk Through: make sure you understand each detail of your optimal solution before coding
  10. +
  11. Implement: modularize your code from the beginning and refactor
  12. +
  13. Test: code review, look for hot spots and special and edge cases
  14. +
+

Technique #1: BUD Optimization

+

Acronym for Bottlenecks, Unnecessary work and Duplicated work. Bottleneck is a part of your algorithm that slows down the overral runtime. Common ways this occurs are having one-time work that slows down your algorithm and having a chunk of work that is done repeatedly (like searching). Then look for unnecessary and duplicated work.

+

Technique #2: Do It Yourself

+

Use a nice, big example and intuitively solve it. Think hard about how you solved it and reverse engineer your own approach.

+

Technique #3: Simplify And Generalize

+

Multi-step approach that simplify some constraint (such as the data type). Solve the simplified version of the problem and then adapt for a more complex version.

+

Technique #4: Base Case And Build

+

Solve the problem first for a base case and then build up for more complex cases. Generally lead to recursive algorithms.

+

Technique #5: Data Structure Brainstorm

+

Solving a problem may be trivial once it occurs to use a specific data structure. The more problems you do, the more developed your instinct on which data structure to apply will be.

+

Handling Situations

+

Handling Incorrect Answers

+

Candidates don’t need to get every question right. You will be evaluated about how optimal your final solution was, how long it took to get there, hhow much help you needed, and how clean was your code. You will also be evaluated in comparison to other candidates and the questions my be too difficult to expect even a strong candidate to immediately spit out the optimal algorithm.

+

When You’ve Heard A Question Before

+

If it occurs, admit this to your interviewer. Otherwise it may be highly dishonest if you don’t reveal that you know the question and, conversely, you’ll get big honesty points if you do reveal this.

+

The Perfect Language For Interviews

+

Many top companies interviewers aren’t picky about languages. Choose whatever language you’re most comfortable with considering some points.

+
    +
  • Prevalence: It’s ideal for your interviewer to know the language you’re coding in. Prefer widely known languages.
  • +
  • Readability: Languages such as Scala or Objective-C have fairly different syntax.
  • +
  • Potential Problems: For example, using C++ means that, in addition to all the usual bugs you can have in your code, you can have memory management and pointer issues.
  • +
  • Verbosity: Languages with simple syntax may be preferred, but some verbosity can be reduced by abbreviating code (most interviewers wouldn’t mind)
  • +
  • Ease of Use: Some operations are easier in some languages than others.
  • +
+

Writing Good Code

+

A good code is correct, efficient, simple, readable and maintainable. Striving for these aspects requires a balancing act. For example, it’s often advisable to sacrifice some degree of efficiency to make code more maintainable, and vice versa.

+

Use Data Structures Generously

+

Design your own data structure may be a good solution in some cases. It’s a good point to evaluate with the interviewer. Some might argued that this is over-optimizing.

+

Modular

+

Separate isolated chunks of code out into their own methods. This helps keep the code more maintainable, readable, testable and reusable.

+

Flexible And Robust

+

Use variables instead of hard-coded values, use templates to solve a problem. You should write your code to solve a more general problem.

+

Error Checking

+

Adopt failing fast and don’t make assumptions about the input. If the error checks are much more than a quick if-statement, it may be best to leave some space where the error checks would go and indicate to your interviewer that you’ll fill them in when you’re finished with the rest of the code.

+

Don’t Give Up!

+

Interview questions can be overwhelming, but this is how they are supposed to be. It shouldn’t be a surprise when you get a really tough problem. Show excitement about solving hard problems for extra points.

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/notes/data-structures/index.html b/public/notes/data-structures/index.html new file mode 100644 index 0000000..436b6b4 --- /dev/null +++ b/public/notes/data-structures/index.html @@ -0,0 +1,434 @@ + + + + + +Data Structures | jpcairesf/Blog + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Data Structures

+ + + + +
+ + +
+ + +
+
+

Data Structures

+

A very simplified note to cover the most important data structures with examples in python, operations time complexity and trade offs.

+

Arrays

+

A contiguous memory block that stores elements of the same data type. The memory address of the first element in the array is the base address and any other element’s address can be calculated using the base address and the size of each element.

+
array = []
+array.append(1)
+array.append(3)
+print(array[1]) # 3
+array.append(2)
+print(array.remove(3)) # 3
+print(array.index(2)) # 1
+

Operations

+
    +
  • Access by index: O(1) by calculating the position
  • +
  • Access by value: O(n) by traversal
  • +
  • Write in the beginning: O(n), requires shifting elements
  • +
  • Write in the end: O(1), no shifting required
  • +
+

Pros And Cons

+

Pros: Direct access using indexes, contiguous storage minimizes memory overhead, easy to sort. +Cons: Fixed (limited) size, inefficient writing due to shifting, unfilled memory keep allocated.

+

Linked List

+
class ListNode:
+    def __init__(self, val=0, next=None):
+        self.val = val
+        self.next = next
+
+class LinkedList:
+    def __init__(self):
+        self.head = None
+# implements the following methods:
+#    def append(self, val):
+#    def remove(self, val):
+#    def display(self):
+
+linked_list = LinkedList()
+linked_list.append(1)
+linked_list.append(2)
+linked_list.append(3)
+linked_list.display()  # Output: 1 -> 2 -> 3 -> None
+linked_list.remove(2)
+linked_list.display()  # Output: 1 -> 3 -> None
+

A linear data structure where elements (nodes) are connected through pointers. Doesn’t require contiguous memory locations and each node contains a reference to the next one, allowing to be placed anywhere in the memory.

+

Operations

+
    +
  • Access by index: O(n) by traversal
  • +
  • Access by value: O(n) by traversal
  • +
  • Write in the beginning: O(1) by pointing the new node to the old head
  • +
  • Write in the end: O(n) by traversing and then pointing the last node to the new
  • +
+

Pros And Cons

+

Pros: Dynamic size, no waste of memory, more efficient writing operations. +Cons: Access always requires traversing, node requires extra memory for pointers, traversing have a higher constant factor compared to arrays.

+

Stack

+

It’s a LIFO-behaved data structure with a pointer to the last element for fast access. The stack itself is a pre-allocated region of memory with a fixed size, and the memory for individual function calls on the stack is dynamically managed. So the nature of the allocation depends on the type of stack and the context in which it’s used.

+
stack = []
+stack.push(1)
+stack.push(3)
+print(stack.pop()) # 3
+stack.push(2)
+print(stack.pop()) # 2
+print(stack.pop()) # 1
+

Operations

+
    +
  • Access in the end: O(1) by stack pointer
  • +
  • Write in the end: O(1) by accessing via stack pointer and updating it
  • +
+

Queue

+

It’s a FIFO-behaved data structure that also can be pre-allocated or dynamically allocated depending on the type and context.

+
from collections import deque
+
+queue = deque()
+deque.append(1)
+deque.append(3)
+print(queue.popleft()) # 1
+deque.append(2)
+print(queue.popleft()) # 3
+print(queue.popleft()) # 2
+

Operations

+
    +
  • Access in the beginning/end: O(1) by pointers
  • +
  • Enqueue (insertion): O(1) by accessing via pointer and updating it
  • +
  • Dequeue (deletion): O(1) by accessing via pointer and updating it
  • +
+

Hash Map

+

It’s a key-value pair collection, where each key is unique. It provides operation efficiency (all operations are O(1)) through memory overhead. Uses hashing function to convert a key into an index and maintains an array where each index corresponds to a bucket that can hold multiple pairs.

+

Set

+

It’s a unordered collection of distinct elements. Internally uses hash maps and all operations are O(1).

+

Binary Tree

+

It’s a hierarchical data structure in which each node has at most two children and the topmost node is called root.

+

Traversal

+
def preorder_print(self, start, traversal):
+    """Root->Left->Right"""
+    if start:
+        traversal += (str(start.value) + "-")
+        traversal = self.preorder_print(start.left, traversal)
+        traversal = self.preorder_print(start.right, traversal)
+    return traversal
+
def inorder_print(self, start, traversal):
+    """Left->Root->Right"""
+    if start:
+        traversal = self.inorder_print(start.left, traversal)
+        traversal += (str(start.value) + "-")
+        traversal = self.inorder_print(start.right, traversal)
+    return traversal
+
def postorder_print(self, start, traversal):
+    """Left->Right->Root"""
+    if start:
+        traversal = self.postorder_print(start.left, traversal)
+        traversal = self.postorder_print(start.right, traversal)
+        traversal += (str(start.value) + "-")
+    return traversal
+

Heap

+

Is a specialized tree-based data structure that satisfies the heap property (for max and min heaps) and all operations are O(log n). It’s used to implement priority queues, for heap sort and graph algorithms like Dijkstra’s.

+
import heapq
+
+min_heap = []
+heapq.heappush(min_heap, 4)
+heapq.heappush(min_heap, 1)
+heapq.heappush(min_heap, 3)
+min_element = heapq.heappop(min_heap)
+print(min_element) # 1
+
+max_heap = []
+heapq.heappush(max_heap, -1)
+heapq.heappush(max_heap, -4)
+heapq.heappush(max_heap, -3)
+max_element = -heapq.heappop(max_heap)
+print(max_element) # 4
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/notes/index.html b/public/notes/index.html new file mode 100644 index 0000000..898f0ac --- /dev/null +++ b/public/notes/index.html @@ -0,0 +1,310 @@ + + + + + +Notes | jpcairesf/Blog + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Notes

+
+
+ + +

2024

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/notes/index.xml b/public/notes/index.xml new file mode 100644 index 0000000..11f0cf9 --- /dev/null +++ b/public/notes/index.xml @@ -0,0 +1,60 @@ + + + + Notes on jpcairesf/Blog + http://localhost:1313/blog/notes/ + Recent content in Notes on jpcairesf/Blog + Hugo -- gohugo.io + en-us + Sun, 31 Mar 2024 09:29:19 -2353 + + Interview Storytelling + http://localhost:1313/blog/notes/interview-storytelling/ + Sun, 10 Mar 2024 12:58:19 -2353 + + http://localhost:1313/blog/notes/interview-storytelling/ + + This post is inspired in a video from A Life Engineered that gives many advices about telling good stories. He also explains how STAR model is more like a linter than a way to structure your story and compare it with U-shape model. This is also a fast cheatsheet, I won&rsquo;t talk about any of these topics in depth. +General Tips Present yourself very quickly Do your homework and bring questions to the interviewers Talk about what you&rsquo;ve done, not your team Challenges may be compatible with the level you aim Anchor your status and show that you can handle challenges of your level Show your career progression and growth mindset Have a good story to tell about your journey in programming U-shape Stablish status about yourself Explain the challenge and then deep dive into it Introduce obstacles Climb until the situation is proportionally better than how it started Make sure that you have an imperfect solution STAR Model Describe a situation Explain the task that you had to complete Describe the actions you took Show the results op your efforts Most Frequent Questions Challenging project/task Improvements in your team Successful projects Handling feedbacks 3 strengths and weaknesses + + + + + Sorting Algoithms + http://localhost:1313/blog/notes/sorting-algorithms/ + Sun, 10 Mar 2024 15:24:15 +0000 + + http://localhost:1313/blog/notes/sorting-algorithms/ + + First we have to keep some concepts in mind. +Inplace/Outplace: use/don&rsquo;t use extra memory Unstable/Stable: position order change/don&rsquo;t change for repeated values Selection Sort Divides the input list into a sorted and an unsorted region. Repeatedly selects the smallest element from the unsorted region and swaps it with the first element in the unsorted region. +Inplace and unstable O(n2) time and O(1) space def selection_sort(arr): for i in range(len(arr)): min_idx = i for j in range(i+1, n): if arr[j] &lt; arr[min_idx]: min_idx = j arr[i], arr[min_idx] = arr[min_idx], arr[i] Insertion Sort Builds a sorted portion of the list one element at a time. + + + + + Coding Interview: Technical Questions + http://localhost:1313/blog/notes/coding-interview-technical-questions/ + Sat, 09 Mar 2024 07:50:00 +0000 + + http://localhost:1313/blog/notes/coding-interview-technical-questions/ + + Walking Through A Problem Listen: pay attention very closely Example: debug your example and find special cases Brute force: state a naive algorithm and then optimize it Optimize: BUD Optimization or look (or ask) for unused info, make time vs. space tradeoff Walk Through: make sure you understand each detail of your optimal solution before coding Implement: modularize your code from the beginning and refactor Test: code review, look for hot spots and special and edge cases Technique #1: BUD Optimization Acronym for Bottlenecks, Unnecessary work and Duplicated work. + + + + + Data Structures + http://localhost:1313/blog/notes/data-structures/ + Sat, 09 Mar 2024 07:50:00 +0000 + + http://localhost:1313/blog/notes/data-structures/ + + Data Structures A very simplified note to cover the most important data structures with examples in python, operations time complexity and trade offs. +Arrays A contiguous memory block that stores elements of the same data type. The memory address of the first element in the array is the base address and any other element&rsquo;s address can be calculated using the base address and the size of each element. +array = [] array. + + + + + diff --git a/public/notes/interview-storytelling/index.html b/public/notes/interview-storytelling/index.html new file mode 100644 index 0000000..07cfbf5 --- /dev/null +++ b/public/notes/interview-storytelling/index.html @@ -0,0 +1,301 @@ + + + + + +Interview Storytelling | jpcairesf/Blog + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Interview Storytelling

+ + + + +
+ + +
+ + +
+
+

This post is inspired in a video from A Life Engineered that gives many advices about telling good stories. He also explains how STAR model is more like a linter than a way to structure your story and compare it with U-shape model. This is also a fast cheatsheet, I won’t talk about any of these topics in depth.

+

General Tips

+
    +
  • Present yourself very quickly
  • +
  • Do your homework and bring questions to the interviewers
  • +
  • Talk about what you’ve done, not your team
  • +
  • Challenges may be compatible with the level you aim
  • +
  • Anchor your status and show that you can handle challenges of your level
  • +
  • Show your career progression and growth mindset
  • +
  • Have a good story to tell about your journey in programming
  • +
+

U-shape

+
    +
  • Stablish status about yourself
  • +
  • Explain the challenge and then deep dive into it
  • +
  • Introduce obstacles
  • +
  • Climb until the situation is proportionally better than how it started
  • +
  • Make sure that you have an imperfect solution
  • +
+

STAR Model

+
    +
  • Describe a situation
  • +
  • Explain the task that you had to complete
  • +
  • Describe the actions you took
  • +
  • Show the results op your efforts
  • +
+

Most Frequent Questions

+
    +
  • Challenging project/task
  • +
  • Improvements in your team
  • +
  • Successful projects
  • +
  • Handling feedbacks
  • +
  • 3 strengths and weaknesses
  • +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/notes/sorting-algorithms/index.html b/public/notes/sorting-algorithms/index.html new file mode 100644 index 0000000..151a93d --- /dev/null +++ b/public/notes/sorting-algorithms/index.html @@ -0,0 +1,374 @@ + + + + + +Sorting Algoithms | jpcairesf/Blog + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

Sorting Algoithms

+ + + + +
+ + +
+ + +
+
+

First we have to keep some concepts in mind.

+
    +
  • Inplace/Outplace: use/don’t use extra memory
  • +
  • Unstable/Stable: position order change/don’t change for repeated values
  • +
+

Selection Sort

+

Divides the input list into a sorted and an unsorted region. Repeatedly selects the smallest element from the unsorted region and swaps it with the first element in the unsorted region.

+
    +
  • Inplace and unstable
  • +
  • O(n2) time and O(1) space
  • +
+
def selection_sort(arr):
+    for i in range(len(arr)):
+        min_idx = i
+        for j in range(i+1, n):
+            if arr[j] < arr[min_idx]:
+                min_idx = j
+        arr[i], arr[min_idx] = arr[min_idx], arr[i]
+

Insertion Sort

+

Builds a sorted portion of the list one element at a time. Iterates through the unsorted portion, selects an element, and inserts it into its correct position in the sorted portion.

+
    +
  • Inplace and stable
  • +
  • O(n2) time and O(1) space
  • +
+
def insertion_sort(arr):
+    for i in range(1, len(arr)):
+        key = arr[i]
+        j = i - 1
+        while j >= 0 and key < arr[j]:
+            arr[j + 1] = arr[j]
+            j -= 1
+        arr[j + 1] = key
+

Bubble Sort

+

Repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. Pass through the list is repeated until no swaps are needed, indicating the list is sorted.

+
    +
  • Inplace and stable
  • +
  • O(n2) timg and O(1) space
  • +
+
def bubble_sort(arr):
+    for i in range(len(arr)):
+        for j in range(0, len(arr)-i-1):
+            if arr[j] > arr[j+1]:
+                arr[j], arr[j+1] = arr[j+1], arr[j]
+

Merge Sort

+

Divides the list into two halves recursively until each sublist contains a single element. Merges the sorted sublists back together, comparing elements to arrange them in the correct order.

+
    +
  • Outplace and stable
  • +
  • O(n log n) time and O(n) space
  • +
+
def merge_sort(arr):
+    if len(arr) <= 1:
+        return arr
+
+    mid = len(arr) // 2
+    left_half = arr[:mid]
+    right_half = arr[mid:]
+
+    left_half = merge_sort(left_half)
+    right_half = merge_sort(right_half)
+    return merge(left_half, right_half)
+
+def merge(left, right):
+    result = []
+    i = j = 0
+
+    while i < len(left) and j < len(right):
+        if left[i] < right[j]:
+            result.append(left[i])
+            i += 1
+        else:
+            result.append(right[j])
+            j += 1
+
+    result.extend(left[i:])
+    result.extend(right[j:])
+    return result
+

Quick Sort

+

Chooses a pivot element from the array and partitions the other elements into two subarrays according to whether they are less than or greater than the pivot. Recursively sorts the subarrays and concatenates them.

+
    +
  • Inplace and unstable
  • +
  • Average: O(n log n) time and O(log n)* space
  • +
  • Worst case: O(n2) time and O(n)* space +*because of recursion stack
  • +
+
def quick_sort(arr):
+    if len(arr) <= 1:
+        return arr
+
+    pivot = arr[len(arr) // 2]
+    left = [x for x in arr if x < pivot]
+    middle = [x for x in arr if x == pivot]
+    right = [x for x in arr if x > pivot]
+
+    return quick_sort(left) + middle + quick_sort(right)
+

Heap Sort

+

Builds a binary heap (max heap) from the input array. Repeatedly extracts the maximum element (root of the heap) and rebuilds the heap until the array is sorted. Not used as the main sorting algorithms of programming languages because it is unstable.

+
    +
  • Inplace and unstable
  • +
  • O(n log n) time and O(1) space
  • +
+
import heapq
+
+def heap_sort(arr):
+    heapq.heapify(arr)
+    return [heapq.heappop(arr) for _ in range(len(arr))]
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/pages/about/index.html b/public/pages/about/index.html index 816bfe7..9afc43b 100644 --- a/public/pages/about/index.html +++ b/public/pages/about/index.html @@ -31,7 +31,7 @@ - + diff --git a/public/pages/index.html b/public/pages/index.html index 9d3c1d3..29f1536 100644 --- a/public/pages/index.html +++ b/public/pages/index.html @@ -31,7 +31,7 @@ - + diff --git a/public/posts/how-blogging-can-leverage-your-tech-career/index.html b/public/posts/how-blogging-can-leverage-your-tech-career/index.html index 0759e08..652a000 100644 --- a/public/posts/how-blogging-can-leverage-your-tech-career/index.html +++ b/public/posts/how-blogging-can-leverage-your-tech-career/index.html @@ -68,7 +68,7 @@ - + diff --git a/public/posts/index.html b/public/posts/index.html index 4f40b85..7b9712f 100644 --- a/public/posts/index.html +++ b/public/posts/index.html @@ -76,7 +76,7 @@ - + diff --git a/public/sitemap.xml b/public/sitemap.xml index fbd2c03..501726c 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -2,10 +2,25 @@ - http://localhost:1313/blog/posts/how-blogging-can-leverage-your-tech-career/ - 2024-03-05T20:35:51-03:00 - http://localhost:1313/blog/ + 2024-03-31T09:29:19-23:53 + + http://localhost:1313/blog/notes/ + 2024-03-31T09:29:19-23:53 + + http://localhost:1313/blog/notes/interview-storytelling/ + 2024-03-10T12:58:19-23:53 + + http://localhost:1313/blog/notes/sorting-algorithms/ + 2024-03-10T15:24:15+00:00 + + http://localhost:1313/blog/notes/coding-interview-technical-questions/ + 2024-03-09T07:50:00+00:00 + + http://localhost:1313/blog/notes/data-structures/ + 2024-03-09T07:50:00+00:00 + + http://localhost:1313/blog/posts/how-blogging-can-leverage-your-tech-career/ 2024-03-05T20:35:51-03:00 http://localhost:1313/blog/posts/ diff --git a/public/tags/index.html b/public/tags/index.html index fa334b4..e490148 100644 --- a/public/tags/index.html +++ b/public/tags/index.html @@ -31,7 +31,7 @@ - +