Skip to content

Instantly share code, notes, and snippets.

View sedmo's full-sized avatar

Stephan sedmo

View GitHub Profile
@sedmo
sedmo / valid-palindrome.cpp
Created August 3, 2020 18:22
Week Day 3 August 2020 leetcode challenge
class Solution {
void printArray(vector<char> arr){
cout<<"[";
for(auto c: arr){
cout<<c<<",";
}
cout<<"]"<<endl;
}
vector<char> stringToArrLower(string s){
@sedmo
sedmo / design_hashset.cpp
Last active August 2, 2020 17:31
I took the array of list approach. rbt would have been more optimal on worst case
// using chaining
class MyHashSet {
vector<list<int> *> hashSet;
const int CAP = 1000;
public:
/** Initialize your data structure here. */
// initializing with nullptr allows you not to create unnecessary space until needed i.e. on add
MyHashSet() {
hashSet = vector<list<int> *>(CAP, nullptr);
}
@sedmo
sedmo / main.cpp
Last active April 19, 2020 04:32
find word in grid of characters. return true if the word exists
class Solution {
private:
bool dfs(vector<vector<char>>&board, int count, int i, int j, string& word)
{
if(word.size() == count) //Signifies that we have reached the end of search
return true;
if(i<0 || j<0 || i>=board.size() || j>=board[0].size() || board[i][j]!=word[count])
return false;
//We check if element is within bounds and then check if the character at that is the same as the corresponding character in string word