This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<vector<int> > Solution::diagonal(vector<vector<int> > &A) { | |
int n = A.size(); | |
vector<vector<int> > result; | |
int l = -1; | |
int i = 0; | |
int c = 0; | |
int r = 0; | |
int col = 0; | |
for (auto j = 0; j<n; ++j) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Solution::firstMissingPositive(vector<int> &A) { | |
sort(A.begin(), A.end()); | |
int c = 1; | |
for (auto const& a : A) | |
{ | |
if (a<1) | |
continue; | |
else if (a==c) | |
{ | |
++c; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool myCompare(const int x, const int y) | |
{ | |
auto tempx = x; | |
auto tempy = y; | |
auto cx = 0; | |
auto cy = 0; | |
while(tempx!=0 || tempy!=0) | |
{ | |
if(tempx!=0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Solution::setZeroes(vector<vector<int> > &A) { | |
int nR = A.size(); | |
int nC = A[0].size(); | |
vector<int> r; | |
vector<int> c; | |
for(int i=0; i<nR; ++i) | |
{ | |
for (int j=0; j<nC; ++j) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
You are in an infinite 2D grid where you can move in any of the 8 directions : | |
(x,y) to (x+1, y), (x - 1, y), (x, y+1), (x, y-1), (x-1, y-1), (x+1,y+1), (x-1,y+1), (x+1,y-1) | |
You are given a sequence of points and the order in which you need to cover the points. | |
Give the minimum number of steps in which you can achieve it. You start from the first point. | |
Example : Input : [(0, 0), (1, 1), (1, 2)] Output : 2 It takes 1 step to move from (0, 0) to (1, 1). | |
It takes one more step to move from (1, 1) to (1, 2). | |
This question is intentionally left slightly vague. | |
Clarify the question by trying out a few cases in the “See Expected Output” section. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for an interval. | |
* struct Interval { | |
* int start; | |
* int end; | |
* Interval() : start(0), end(0) {} | |
* Interval(int s, int e) : start(s), end(e) {} | |
* }; | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for an interval. | |
* struct Interval { | |
* int start; | |
* int end; | |
* Interval() : start(0), end(0) {} | |
* Interval(int s, int e) : start(s), end(e) {} | |
* }; | |
*/ | |
vector<Interval> Solution::insert(vector<Interval> &intervals, Interval newInterval) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int> Solution::wave(vector<int> &A) { | |
sort(A.begin(), A.end()); | |
int s = A.size(); | |
int i = 0; | |
while (i<=s-2) | |
{ | |
swap(A[i], A[i+1]); | |
i += 2; | |
} | |
return A; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int> Solution::spiralOrder(const vector<vector<int> > &A) { | |
vector<int> result; | |
// DO STUFF HERE AND POPULATE result | |
auto rows = A.size | |
if (rows == 0) | |
return vector<int> (); | |
auto columns = A[0].size(); | |
int T, B, L, R; | |
T = 0, B = rows - 1, L = 0, R = columns - 1; | |
int dir = 0; |