This file contains 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
class Graph: | |
def __init__(self, V: set[str], E: dict[dict[str, int]]) -> None: | |
super().__init__() | |
self.V = V | |
self.E = E | |
def dijkstra(self, s: str, t: str) -> int: | |
""" | |
Returns the shortest path from s to t | |
""" |
This file contains 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
# https://www.hackerrank.com/challenges/torque-and-development/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=graphs | |
from collections import defaultdict | |
def roadmap(cities: list[list[int]]) -> dict[int, set[int]]: | |
d = defaultdict(set) | |
for item in cities: | |
d[item[0]].add(item[1]) | |
d[item[1]].add(item[0]) | |
return d |
This file contains 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
# https://www.hackerrank.com/challenges/torque-and-development/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=graphs | |
from collections import defaultdict | |
def roadmap(cities: list[list[int]]) -> dict[int, set[int]]: | |
d = defaultdict(set) | |
for item in cities: | |
d[item[0]].add(item[1]) | |
d[item[1]].add(item[0]) | |
return d |
This file contains 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
# My solution to https://www.hackerrank.com/challenges/largest-rectangle/problem?h_r=internal-search | |
def largestRectangle(h: list): | |
stack = [(0, 0)] | |
h.append(0) | |
largest = 0 | |
for i, height in enumerate(h, 1): | |
tallest = stack[-1] | |
leftWall = i | |
while tallest[0] > height: |
This file contains 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
\documentclass[11pt]{report} | |
% To set margin width, text height, space for footnotes and all sorts | |
% of other settings related to the geometry of the pages in your | |
% report, use the 'geometry' package. | |
% | |
% http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=geometry | |
\usepackage[margin=2cm]{geometry} |
This file contains 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 { RenderCustomNodeElementFn } from "react-d3-tree/lib/types/common"; | |
export const LogiNode: RenderCustomNodeElementFn = ({ nodeDatum, toggleNode}) => { | |
const [x, y] = [0, -50]; | |
const [width, height] = [100, 100]; | |
return( | |
<g> | |
<rect width={width} height={height} x={x} y={y} onClick={toggleNode}> | |
</rect> | |
<text |
This file contains 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 { RenderCustomNodeElementFn } from "react-d3-tree/lib/types/common"; | |
export const LogiNode: RenderCustomNodeElementFn = ({ nodeDatum, toggleNode}) => { | |
const [x, y] = [0, -50]; | |
const [width, height] = [100, 100]; | |
return( | |
<g> | |
<rect x={x} y={y} width={width} height={height} onClick={toggleNode}> | |
</rect> | |
<foreignObject x={x} y={y} width={width} height={height}> |
This file contains 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 isValid(s: str) -> bool: | |
counter = Counter(s) | |
freqList = counter.most_common(None) | |
freqDict = defaultdict(list) | |
for freqTuple in freqList: | |
freqDict[freqTuple[1]].append(freqTuple[0]) | |
fd = dict(freqDict) | |
if len(fd.keys()) == 1: | |
return "YES" | |
if len(fd.keys()) == 2: |
This file contains 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 quicksort(arr: List[int])->List[int]: | |
l = len(arr) | |
if l == 0: | |
return [] | |
elif l == 1: | |
return arr | |
else: | |
pivot = arr.pop(0) | |
former = [] | |
latter = [] |
This file contains 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 abbreviation(a: str, b: str) -> str: | |
dfs = [(len(a) - 1, len(b) - 1)] | |
dp = set() | |
while len(dfs) > 0: | |
pa, pb = dfs.pop() | |
if (pa, pb) in dp: | |
# (pa, pb) has already tested false | |
continue | |
dp.add((pa, pb)) | |
if pb < 0: |
OlderNewer