Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

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)

second: Using quick select (https://leetcode.com/problems/kth-largest-element-in-an-array/discuss/2180600/A-


Guide-to-Quick-Select-or-JAVA)

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.

4) Kth Ancestor of a Tree Node


Use the binary lifting in order to get the 2^k-th ancestor, for any possible k (this can be computed in O(n *
log(longest_path)), by always taking the 2^k-1 ancestor and then taking its 2^k-1 ancestor in order to find the 2^k
ancestor of the current node).
Then, based on the fact that any number can be written as a sum of powers of 2, you go from 2^v-th to 2^t-th
ancestor, until the k is formed by the sum of pows of 2.

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

Solved: Cache flow from L1 to L2 - Google Cloud Community

How is Virtual Memory Translated to Physical Memory? | VMware

Difference between Thread Context Switch and Process Context Switch - GeeksforGeeks

Context switching (xinuos.com)

Does thread have own stack? – KnowledgeBurrow.com

multithreading - What resources are shared between threads? - Stack Overflow

Difference Between Process and Thread (microcontrollerslab.com)

What is the relationship between Address and Memory Space in a Virtual Memory System?
(tutorialspoint.com)

You might also like