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 / main.py
Created September 29, 2022 16:23
787. Cheapest Flights Within K Stops
class Solution(object):
def findCheapestPrice(self, n, flights, src, dst, k):
# bellman-ford
p = [float('inf') for _ in range(n)]
c = [float('inf') for _ in range(n)]
p[src] = 0
for i in range(k+1):
for u, v, w in flights:
c[v] = min(p[u]+w, c[v])
@ysinjab
ysinjab / main.py
Created September 28, 2022 18:50
1514. Path with Maximum Probability
class Solution(object):
def maxProbability(self, n, edges, succProb, start, end):
# it looks like dijsktra but with different relaxation
g = collections.defaultdict(dict)
for i in range(len(edges)):
s = edges[i][0]
d = edges[i][1]
p = succProb[i]
g[s][d] = g[d][s] = p
@ysinjab
ysinjab / main.py
Created September 12, 2022 11:41
584. Min Cost to Connect All Points (Kruskal’s Algorithm)
class Solution(object):
def minCostConnectPoints(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
edges = []
for i in range(len(points)):
for j in range(i, len(points)):
heapq.heappush(edges, (abs(points[i][0] - points[j][0]) + abs(points[i][1] - points[j][1]), i, j))
@ysinjab
ysinjab / main.go
Created September 3, 2022 09:56
133. Clone Graph
/**
* Definition for a Node.
* type Node struct {
* Val int
* Neighbors []*Node
* }
*/
func dfs(n *Node, visited map[*Node]*Node) *Node {
@ysinjab
ysinjab / main.go
Created August 21, 2022 17:37
1202.smalles.string.with.swaps
import (
"fmt"
"strings"
"sort"
"os"
"io"
)
type DisjointSet struct {
Nodes []int
}
@ysinjab
ysinjab / main.go
Last active September 3, 2022 09:56
547.number.of.provinces.disjoint.set.with.path.compression
package main
import "fmt"
type DisjointSet struct {
Nodes []int
RootsNumber *int
}
func (ds DisjointSet) Find(n int) int {
func fibonacci(n int) int {
if n <= 1 {
return n
}
return fibonacci(n-1) + fibonacci(n-2)
}
func main() {
// fibCalculator will calculate fibonacci number for a stream of numbers
fibCalculator := func(done <-chan interface{}, numbers <-chan int) <-chan interface{} {

Keybase proof

I hereby claim:

  • I am ysinjab on github.
  • I am ysinjab (https://keybase.io/ysinjab) on keybase.
  • I have a public key ASBtC1_AMzilP5xM9L_o4zBx3pQbGrzfNr5nx0-3NgwBSgo

To claim this, I am signing this object:

ubuntu@ip:~$ sudo docker stats 4263b7da070e
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
4263b7da070e 0.00% 972KiB / 990.7MiB 0.10% 828B / 0B 745kB / 0B 1
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
4263b7da070e 0.00% 972KiB / 990.7MiB 0.10% 828B / 0B 745kB / 0B 1
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
4263b7da070e 0.00% 972KiB / 990.7MiB 0.10% 828B / 0B 745kB / 0B 1
ubuntu@ip:~$ awk -F':' '{ print $1}' /etc/passwd
root
daemon
bin
sys
sync
games
man
lp
mail