Random Link ¯\_(ツ)_/¯ | ||
Aug 1, 2022 | » | Sorting and Searching
5 min; updated Aug 1, 2022
Order Statistics K-th Smallest Element in Sorted Matrix Given an \(N \times N\) matrix, where each of the rows and columns are sorted in ascending order, return the \(k^{th}\) smallest element in the matrix. The memory complexity must be better than \(O(N^2)\). It’s not guaranteed that matrix[r][c] > matrix[r-1][c], so we can’t compute the row (and similarly, the column) in which the \(k^{th}\) smallest element is in. Using a priority queue that holds the \(K\) smallest elements does not work because the memory usage is \(O(K)\), where \(K\) can be any value in \([1, N^2]\).... |
Jul 31, 2022 | » | Spanning 4-Directional Walks From Origin to Destination w/ Obstacles
3 min; updated Jul 31, 2022
Problem Given an \(M \times N\) integer array grid where grid[i][j] could be: 1 representing the starting square. There is exactly one starting square. 2 representing the ending square. There is exactly one ending square. 0 representing empty squares that we can walk over. -1 representing obstacles that we cannot walk over. Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.... |
Jun 4, 2022 | » | Enumerations in C++
7 min; updated Jun 4, 2022
Unscoped (or Plain or C-Style) Enumerations Plain (or C-style) enums are entered in the same scope as the name of their enum, and implicitly convert to their integer value, e.g. enum Color { red, green, blue }; int col = green; Color c2 = 1; // error: invalid conversion from 'int' to 'Color' [-fpermissive] enum CardColor { red, black }; // Error: "red" conflicts with a previous declaration... |
Jun 4, 2022 | » | User-Defined Types
(5 items)
Classes in C++; Structures in C++; Enumerations in C++; Unions in C++; Inheritance; |
May 30, 2022 | » | Templates in C++
4 min; updated May 30, 2022
A template is a class or a function that we can parameterize with a set of types or values. Parameterized Types The vector-of-doubles can be generalized to a vector-of-anything type by making it a template: // `template<typename T>` can be read as "for all types T". Older code // uses `template<class T>`, which is equivalent. template<typename T> class Vector { public: explicit Vector(int s); ~Vector() { delete[] elem; } // .... |
May 12, 2022 | » | Classes in C++
15 min; updated May 12, 2022
quotes Doug McIlroy: Those types are not “abstract”; they are as real as int and float. What is the context of this quote? A class is a user-defined type provided to represent a concept in the code of a program. Essentially, all language facilities beyond the fundamental types, operators, and statements exist to help define better class or to use them more conveniently.... |
Mar 16, 2022 | » | AoC 2021 Day 09: Smoke Basin
13 min; updated Mar 16, 2022
Multi-dimensional arrays using |