Skip to content

Instantly share code, notes, and snippets.

View Mahedi-61's full-sized avatar
๐Ÿ•Œ
Oh Lord! Bestow me with Knowledge

Md Mahedi Hasan Mahedi-61

๐Ÿ•Œ
Oh Lord! Bestow me with Knowledge
View GitHub Profile
1. DP (canSum) Given a target sum and an array of positive integers,
return true if the target sum can be constructed by summing any combination of elements from the array.
You may use an element of the array as many times as needed.
#Solution
def canSum(nums, target, memo={}):
if target in memo: return memo[target]
if target == 0: return True
elif target < 0: return False
1. FourSum:
You are given an integer array nums of size n, return an array of all the unique quadruplets
[nums[a], nums[b], nums[c], nums[d]] such that:
0 <= a, b, c, d < n
a, b, c, and d are distinct.
nums[a] + nums[b] + nums[c] + nums[d] == target
You may return the answer in any order. Note: [1,0,3,2] and [3,0,1,2] are considered as same quadruplets.
Example 1:
Input: nums = [3,2,3,-3,1,0], target = 3
@Mahedi-61
Mahedi-61 / lists_questions.py
Last active June 14, 2025 14:18
Q: Lists (inplace)
##### 1. List Rotate
You are given a list of n integers and a non-negative integer k.
Your task is to write a function called rotate that takes the list of integers and an integer k as input and rotates the
list to the right by k steps. The function should modify the input list in-place, and you should not return anything.
Constraints:
Each element of the input list is an integer.
The integer k is non-negative.
Function signature: def rotate(nums, k):
def bubble_sort(my_list):
for i in range(len(my_list)-1, 0, -1): #steps
for j in range(0, i):
if my_list[j] > my_list[j+1]:
temp = my_list[j]
my_list[j] = my_list[j+1]
my_list[j+1] = temp
return my_list
@Mahedi-61
Mahedi-61 / SqueezeNetCIFAR.py
Created February 1, 2022 04:24
SqueezeNet on CIFAR-10 Dataset
import torch
import torch.optim as optim
import numpy as np
from matplotlib import pyplot as plt
from tabnanny import check
from sklearn.metrics import confusion_matrix
import seaborn as sns
from torch import nn
import torch.nn.init as init
from torchvision import transforms, datasets
@Mahedi-61
Mahedi-61 / RBF_Pseudo_Inverse.py
Last active October 3, 2022 21:26
Radial Basis Function initialized on K-means and trained on Pseudo Inverse for MNIST digit classification
"""
modified from several gist of https://gist.github.com/tarlanahad
For Homework Assingment 12 (CpE 520)
"""
import numpy as np
import torchvision
from matplotlib import pyplot as plt
from sklearn.metrics import confusion_matrix
import seaborn as sns
@Mahedi-61
Mahedi-61 / RBF_classifier.py
Last active December 5, 2021 21:50
Radial Basis Function Netowork for MNIST classification tranined on gradient decent approach
"""
Author: Md Mahedi Hasan
For Homework Assingment 12 (CpE 520)
"""
import numpy as np
import os
import matplotlib.pyplot as plt
from torch.utils.data import DataLoader
from torchvision import transforms
@Mahedi-61
Mahedi-61 / KSOM.py
Created November 29, 2021 01:24
Implementing Kohonen Self Organizing Maps using numpy
"""
Script to implement simple self organizing map
@author: Riley Smith
Created: 1-27-21
"""
"""
@modified: Md Mahedi Hasan (11/28/2021)
For Homework Assingment 11 (CpE 520
"""
@Mahedi-61
Mahedi-61 / autoencoder_mnist.py
Last active November 18, 2021 20:47
3-layer autoencoder for MNIST digit reconstruction and classification with visualization (Pytorch)
"""
Course: Applications of NN (CpE - 520)
Homework Assignment 9
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import torch
@Mahedi-61
Mahedi-61 / parity-3-problem
Last active January 10, 2023 21:00
Solving Parity-3 problem using 3-layer from scratch
# solving parity-3 problems using numpy only
from os import error
import numpy as np
import math
np.random.seed(1)
def relu(x):
return np.maximum(0, x)