Skip to content

Instantly share code, notes, and snippets.

View ysinjab's full-sized avatar
🎯
Focusing

Yasser Sinjab ysinjab

🎯
Focusing
View GitHub Profile
@ysinjab
ysinjab / gmail-github-filters.md
Created May 25, 2023 07:39 — forked from ldez/gmail-github-filters.md
Gmail and GitHub - Filters

Gmail and GitHub

How to filter emails from GitHub in Gmail and flag them with labels.

The labels in this document are just examples.

Pull Request

Filter Label
package concatenate_test
import (
"strings"
"testing"
)
func Concatenate(texts []string) string {
s := ""
for _, value := range texts {
@ysinjab
ysinjab / main.py
Created December 3, 2022 08:54
66. Plus One
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
for i in range(len(digits)-1, -1, -1):
if digits[i] == 9:
digits[i] = 0
else:
digits[i] += 1
return digits
return [1] + digits
@ysinjab
ysinjab / main.py
Created November 23, 2022 08:20
54. Spiral Matrix
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
i, j = 0, 0
left, right, down, up = False, True, False, False
n, m = len(matrix), len(matrix[0])
res = []
visited = set()
def is_wall(i, j):
@ysinjab
ysinjab / main.py
Created November 18, 2022 08:14
265. Paint House II
class Solution:
def minCostII(self, costs: List[List[int]]) -> int:
# Recursion or top-down approach
# state: at any given state returns the minimum cost of painting a house i
# with color k which is: costs[i][k] + minimum cost of painting a house i + 1 with not k
# state variables are:
# i house index
@ysinjab
ysinjab / main.py
Last active November 17, 2022 05:53
256. Paint House
class Solution:
def minCost(self, costs: List[List[int]]) -> int:
# recursion
# state is the current house we are painting with color c that has a cost + min of prev min
# state variables are i, c
# recurrence relation : dp(i, c) = cost[c] + min(dp(i + 1, c-1), dp(i + 1, c+1))
# base case: i == len(costs) return 0
# @lru_cache(None)
# def dp(i, c):
@ysinjab
ysinjab / main.py
Created November 16, 2022 06:12
714. Best Time to Buy and Sell Stock with Transaction Fee
class Solution:
def maxProfit(self, prices: List[int], fee: int) -> int:
# top-down solution
# holding_a_stock = 'HOLDING'
# not_holding_any_stock = 'NOT_HOLDING'
# @lru_cache(None)
# def dp(i, holding_status):
# if i == len(prices):
# return 0
@ysinjab
ysinjab / mian.py
Created November 9, 2022 06:26
1143. Longest Common Subsequence
class Solution:
def longestCommonSubsequence(self, text1: str, text2: str) -> int:
# top down approach: function dp
# state variables are (i, j) where i is index of text1 and j is index of text2
# if both carachters are equal retrun 1
# else choose the max between the two remaining
from functools import lru_cache
@lru_cache(maxsize=None)
@ysinjab
ysinjab / main.py
Created October 7, 2022 08:13
8. String to Integer (atoi)
class Solution(object):
def myAtoi(self, s):
"""
:type s: str
:rtype: int
"""
splitted = s.split(' ')
for i in splitted:
if not i:
continue
@ysinjab
ysinjab / main.py
Created October 2, 2022 21:10
210. Course Schedule II
class Solution(object):
def findOrder(self, num_courses, prerequisites):
"""
:type numCourses: int
:type prerequisites: List[List[int]]
:rtype: List[int]
"""
# basically this is Kahn algorithm for topological sorting
# I like it because it depends on the indegree centrality of the node
degrees = collections.defaultdict(int)