Professional Documents
Culture Documents
Algorithms and Data Structures
Algorithms and Data Structures
Bloomberg
1) https://leetcode.com/problems/kth-largest-element-in-an-array/
first: Using a priority queue (max heap) in order to sort the input and then popping k – 1 elements to get the kth
largest element (complexity: O(n log(n)) for inserting into the heap)
2) Word search
Use dfs to create each possible path of maximum length = length of the word
Prune in order to get rid of wrong paths from the first missing character (mismatch with the sought word)
3) Sum of Subarray Minimums (inspired from another problem, hard, that I solved in 5 mins some
time ago: https://leetcode.com/problems/sum-of-subarray-ranges )
Use an increasing stack to keep the track of the first element that is smaller than the current one on the left (same
to find the next smallest element, on the right). Then, knowing that the current number when iterating will be the
smallest for all contiguous subarrays that start on the left at any index greater than the first element smaller than
the current one, and also knowing that the end can be any index smaller than the next smaller element than the
current one, we know that there are k * k’ combinations of subarrays containing the current number as smallest
element.
5) Number of Islands
Iterate through the whole matrix and start a breadth first search from each tile that was not visited and has a value
of ‘1’ (aka is land).
C++ fundamentals
Namespace
- Collection of related names or identifiers (functions, class, variables) which helps to separate these
identifiers from similar identifiers in other namespaces or the global namespace
- All the identifiers provided by the standard header files (like iostream, fstream, string, vector) are
declared in the std namespace
- Use the namespace with the scope resolution operator (::), or with using directive(using namespace std) /
declaration (using std::cout; …) – tell the compiler that we want to bring only some identifiers to the
current namespace
-
Pointers
- types are meaningless, since pointers are integers which holds an address from memory
- in order to dereference the value, we use types to make our lifes easier, knowing the size of the
data stored at the address hold in the pointer
Python 3
Function parameters:
https://stackoverflow.com/questions/54709025/understanding-positional-arguments-in-python
Difference between Thread Context Switch and Process Context Switch - GeeksforGeeks
What is the relationship between Address and Memory Space in a Virtual Memory System?
(tutorialspoint.com)