g++ -std=c++17 practice/cpp/template.cpp && ./a.out
- Khi cap = 1, thì buffered channel chứa được một giá trị và không block main goroutine. Trong khi đó unbuffered channel sẽ block ngay.
package main
func main() {
bufferedChan := make(chan int, 1)
unbufferedChan := make(chan int)
bufferedChan <- 1 // OK
unbufferedChan <- 1 // deadlock
}
- Concurrent Programming in Go – Goroutines, Channels, and More Explained with Examples
- Go sync.Cond, the Most Overlooked Sync Mechanism
- Go Concurrency, Why Not?
- Learning Go in 2024; From Beginner to Senior
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
cargo new todo_list
- "Let me make sure I understand the problem correctly."
- "So, we are given [...], and we need to return [...], right?"
- "What are the constraints on the input size?"
- "Can the input contain duplicates or negative numbers?"
- "Is the input guaranteed to be sorted?"
- "I’ll first try a brute-force approach to understand the problem."
- "I think we can optimize it using a hashmap to reduce the time complexity."
- "This problem reminds me of [...], I think a similar technique applies here."
- "We can use a two-pointer approach since the array is sorted."
- "I’ll start by initializing [...]."
- "Then I’ll iterate through the array and do [...]."
- "At each step, I will check if [...]."
- "If the condition is met, I will return [...]."
- "Otherwise, I’ll continue the loop."
- "The time complexity is O(n) because we loop through the array once."
- "The space complexity is O(n) due to the extra storage used by the hashmap."
- "Let’s think about the edge cases."
- "If the input is empty or has only one element, we should return null."
- "Another edge case is when [...], which we should handle explicitly."
- "To summarize, I’m using [...], and this solution handles all edge cases with optimal time and space complexity."