Skip to content

Instantly share code, notes, and snippets.

View Se7soz's full-sized avatar

Hussein Elsayed Se7soz

View GitHub Profile
@Se7soz
Se7soz / prob3.cpp
Last active January 3, 2016 05:09
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
#include <iostream>
#include <cstring>
using namespace std;
string removeDuplicates(string s) {
bool chs[512];
memset(chs, false, sizeof chs);
int j = 0;
for(int i = 0; i < s.size(); i++) {
@Se7soz
Se7soz / prob4.cpp
Last active January 3, 2016 05:09
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
bool isAnagaram(string s1, string s2) {
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
return s1==s2;
}
@Se7soz
Se7soz / prob5.cpp
Last active April 25, 2017 18:24
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
void rotate90(vector<vector<int> >& image) {
int n = image.size();
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
swap(image[i][j], image[n-j-1][n-i-1]);
}
}
for(int i = 0; i < n/2; i++) {
@Se7soz
Se7soz / prob6.cpp
Last active May 12, 2017 19:54
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
void resetMtrx(vector<vector<int> >& mtrx) {
if(mtrx.size() == 0 || mtrx[0].size() == 0) return;
int rows[mtrx.size()], cols[mtrx[0].size()];
memset(rows, 1, sizeof rows);
memset(cols, 1, sizeof cols);
for(int i = 0; i < mtrx.size(); i++) {
@Se7soz
Se7soz / prob7.cpp
Last active January 3, 2016 05:18
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
bool isSubstring(string s1, string s2) {
return (s1.find(s2) != string::npos);
}
bool isRotated(string s1, string s2) {
string tmp = s1+s1;
return isSubstring(tmp, s2);
}
@Se7soz
Se7soz / prob8.cpp
Last active May 12, 2017 20:44
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
struct List {
int a;
List* nxt;
List(int a) {
this->a = a;
nxt = NULL;
}
void insert(int s) {
@Se7soz
Se7soz / prob9.cpp
Last active January 3, 2016 05:18
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
void remove(node* nd) {
if(nd == NULL || nd->nxt == NULL) return; // It should be in the middle
node* lnk1 = nd, *lnk2 = nd->nxt;
while(lnk2->nxt) {
swap(lnk1->d, lnk2->d);
lnk1 = lnk1->nxt;
lnk2 = lnk2->nxt;
@Se7soz
Se7soz / prob10.cpp
Last active January 3, 2016 05:18
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
node* sum(node* num1, node* num2) {
node* l1 = num1, *l2 = num2;
node* res = new node(0);
int rem = 0;
while(l1 && l2) {
int num = l1->d+l2->d+rem;
@Se7soz
Se7soz / prob11.cpp
Created January 15, 2014 11:35
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
#include "list.h" // See problem #8
node* getLoopStart(node* lst) {
node *lnk1 = lst, *lnk2 = lst;
while(lnk2->nxt) {
lnk1 = lnk1->nxt;
lnk2 = lnk2->nxt->nxt;
if(lnk2 == NULL) return NULL;
@Se7soz
Se7soz / prob12.cpp
Created January 15, 2014 11:38
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
#include<vector>
#define STACK_IS_EMPTY -1
class CustomStack {
private:
vector<int> stck;
vector<int> mn;
public: