Problem The K Weakest Rows in a Matrix Solution Uses Binary search to count 1s Uses heap to keep k weakest rows It naturally satisfies the condition for weak rows with the same number of soldiers. The smaller index row is processed first and hence any next row would not get pushed to the heap. […]

Read more## Find a Fibonacci Number with Matrix Exponentiation

Core Concepts We can represent any number with a power of (2 or 3 or anything). Evidence? The binary system đź™‚ So we can represent any number with log n bits and using 2 as the exponent. f(n) = f(n-1) + f(n-2) => f(n) = 1*f(n-1) + 1*f(n-2) [f(n)] = |1 1| * |f(n-1)| |f(n-2)| […]

Read more