Skip to content

Instantly share code, notes, and snippets.

View JyotinderSingh's full-sized avatar
:octocat:
Building and breaking things

Jyotinder Singh JyotinderSingh

:octocat:
Building and breaking things
View GitHub Profile
@JyotinderSingh
JyotinderSingh / catsvdogs.py
Created December 11, 2019 07:42
Cats and Dogs Classifier
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import RMSprop
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import os
import tensorflow as tf
import zipfile
base_dir = '/home/jyotinder/Programming/DeepLearning/dataset/dogs-vs-cats'
train_dir = os.path.join(base_dir, 'train')
@JyotinderSingh
JyotinderSingh / SubarraySumEqualsK.cpp
Last active June 20, 2020 21:45
Subarray Sum Equals K - C++ Solution
// https://leetcode.com/problems/subarray-sum-equals-k/
class Solution {
public:
int subarraySum(vector<int> &nums, int k)
{
unordered_map<int, int> map;
int count = 0;
// maintains sum of elements so far
int curr_sum = 0;
@JyotinderSingh
JyotinderSingh / DungeonGame.cpp
Last active January 19, 2022 06:32
Dungeon Game (LeetCode) | C++ Solution
// https://youtu.be/9PC2r6MAw1Q
// https://leetcode.com/problems/dungeon-game/
class Solution
{
public:
int calculateMinimumHP(vector<vector<int>> &dungeon)
{
if (dungeon.size() == 0 || dungeon[0].size() == 0)
return 1;
/*
@JyotinderSingh
JyotinderSingh / TwoSum.cpp
Created June 22, 2020 20:02
Two Sum (LeetCode) | Linear Time Algorithm
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> mp;
for(int i = 0; i < nums.size(); ++i) {
int complement = target - nums[i];
if(mp.find(complement) != mp.end()) {
return {mp[complement], i};
@JyotinderSingh
JyotinderSingh / 3Sum.cpp
Created June 23, 2020 11:19
3Sum (LeetCode) | Solution Explained
// https://leetcode.com/problems/3sum/
// Explanation:
// https://youtu.be/6WsddbKA_vg
class Solution {
public:
vector<vector<int>> threeSum(vector<int>& nums) {
vector<vector<int>> res;
if(nums.size() < 3) {
return res;
}
@JyotinderSingh
JyotinderSingh / UniqueBinarySearchTrees.cpp
Created June 24, 2020 14:37
Unique Binary Search Trees (LeetCode) | Dynamic Programming
class Solution {
public:
int numTrees(int n) {
vector<int> G(n + 1, 0);
G[0] = 1, G[1] = 1;
// Iterating for different values of N, in Bottom Up Approach
for(int i = 0; i <= n; ++i) {
// Looking at each case with all nodes as roots
@JyotinderSingh
JyotinderSingh / 4Sum.cpp
Created June 26, 2020 11:55
4Sum (LeetCode) | Algorithm Explanation
class Solution
{
public:
vector<vector<int>> fourSum(vector<int> &nums, int target)
{
vector<vector<int>> res;
if (nums.size() < 4)
{
return res;
}
@JyotinderSingh
JyotinderSingh / EditDistance.cpp
Created June 28, 2020 13:24
Edit Distance Algorithm Explanation | C++
class Solution {
public:
int minDistance(string word1, string word2) {
vector<vector<int>> dp(word2.size() + 1, vector<int> (word1.size() + 1));
/*
* Going downwards in the first column (for "" as the first string),
* we're performing the insert operation
* And the number of inserts to turn an empty string to a
* string with length L is L
@JyotinderSingh
JyotinderSingh / WordSearch.cpp
Created June 30, 2020 09:38
Word Search (LeetCode) | O(1) Space Algorithm Explanation
class Solution
{
public:
bool exist(vector<vector<char>> &board, string word)
{
for (int i = 0; i < board.size(); ++i)
{
for (int j = 0; j < board[0].size(); ++j)
@JyotinderSingh
JyotinderSingh / ArrangingCoins.cpp
Created July 1, 2020 09:28
Arranging Coins (LeetCode) | Binary Search Algorithm Explanation
class Solution {
public:
int arrangeCoins(int n) {
long n_long = (long) n;
long left = 1, right = n_long;
while(left <= right) {
long mid = left + (right - left) / 2; // (left + right) / 2
if(mid * (mid + 1) / 2 <= n_long) {