add flashcard generation tooling and binary search cards
- gen-flashcards.py: auto-generate recognition cards from all problem files - toolkit/gen-problem-cards.org: 199 auto-generated problem cards - 5 binary search tool cards (std::binary_search, std::lower_bound, comparison, two-sum pattern, sorting gotcha) - two-sum.org: add binary search C++ attempt - lc-org.el: add doom emacs localleader keybinding support
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#+ANKI_DECK: study_deck_02
|
||||
* Task: Two Sum complement lookup with lower_bound :cpp:binary-search:two-sum:retrieval::production:
|
||||
:PROPERTIES:
|
||||
:END:
|
||||
|
||||
** Front
|
||||
Given sorted ~nums~ and index ~i~, write C++ to check if ~target - nums[i]~ exists in the rest of the array using ~std::lower_bound~.
|
||||
|
||||
** Back
|
||||
#+begin_src cpp
|
||||
int complement = target - nums[i];
|
||||
auto it = std::lower_bound(nums.begin() + i + 1, nums.end(), complement);
|
||||
if (it != nums.end() && *it == complement) {
|
||||
return {(int)i, (int)std::distance(nums.begin(), it)};
|
||||
}
|
||||
#+end_src
|
||||
Reference in New Issue
Block a user