Skip to content

Instantly share code, notes, and snippets.

View HimanshuMittal01's full-sized avatar

Himanshu Mittal HimanshuMittal01

View GitHub Profile
@dosentmatter
dosentmatter / analysis.txt
Last active August 22, 2020 09:12
Leetcode 283. "Move Zeroes" Solutions 2/3 Analysis
I don't think Solution 2 is always better than Solution 3
First of all, it doesn't matter unless n is large, since both are O(n).
For both Solutions 2 and 3, you can skip operations when there are non-zeros at the beginning of the array by doing the following:
For Solution 2, you can skip moving when `lastNonZeroFoundAt == i`
For Solution 3, you can skip swapping when `lastNonZeroFoundAt == cur`
For Solution 2, even if you do a memset, that is an O(n) because it has to write each element to 0.
For Solution 3, we can say that swap is a 3 cost operation since it does 3 writes including the temporary variable.
@ar-pa
ar-pa / BigInt.cpp
Last active July 11, 2024 20:32
bignum class for C++
// In the name of Allah.
// We're nothing and you're everything.
// Ya Ali!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + 14, lg = 15;