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
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 | |
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
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 |
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
##### 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): |
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
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 |
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
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 |
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
""" | |
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 |
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
""" | |
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 |
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
""" | |
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 | |
""" |
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
""" | |
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 |
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
# 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) |
NewerOlder