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 executor(driver_out): | |
return f"this is %s" %driver_out | |
def connector(driver): | |
return executor(driver()) | |
def blaster_driver(): | |
return "very important blasting info" | |
def contractor_driver(): |
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
from typing import Union | |
def lca(root: Node, v1: int, v2: int) -> Union[None, Node]: | |
if not root: return None | |
res = None | |
if root.info == v1 or root.info == v2: | |
res = root | |
left_res = lca(root.left, v1, v2) | |
if left_res and res: return res | |
right_res = lca(root.right, v1, v2) |
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
defmodule StackSort do | |
@moduledoc """ | |
Documentation for StackSort. | |
Recursively pops and compares all values with top | |
of the stack value and pushes it else keeps | |
popping out until invariant satisfied. | |
You will find only comments in docstrings. | |
I(t's a no brainer. |
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
from Stack import MyStack | |
class MinStack(MyStack): | |
def __init__(self): | |
super().__init__() | |
self.__min = None | |
self.__last_min_stack = MyStack() | |
def push(self, value): | |
if self.__last_min_stack.is_empty(): |
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
from Stack import MyStack | |
def next_greater_element(lst): | |
# Write your code here | |
s = MyStack() | |
ln = len(lst) | |
for idx in range(ln-1, -1, -1): | |
num = lst[idx] | |
while not s.is_empty() and s.top() <= num: | |
s.pop() |
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
from Stack import MyStack | |
import operator | |
OPERATORS = { | |
'*': operator.mul, | |
'/': operator.ifloordiv, | |
'+': operator.add, | |
'-': operator.sub, | |
} |
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
"""Lowest value at top, highest on top.""" | |
from Stack import MyStack | |
def sort_stack(stack): | |
if not stack.is_empty(): | |
top_val = stack.pop() | |
sort_stack(stack) | |
_insert(stack, top_val) |
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
from Queue import MyQueue | |
from Stack import MyStack | |
def reverseK(queue: MyQueue, k: int): | |
rem_size = queue.size() - k | |
if rem_size < 0 or k < 1: | |
return None | |
stack = MyStack() | |
for _ in range(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
# set the base image to Debian | |
# https://hub.docker.com/_/debian/ | |
FROM debian:latest | |
# replace shell with bash so we can source files | |
RUN rm /bin/sh && ln -s /bin/bash /bin/sh | |
# update the repository sources list | |
# and install dependencies | |
RUN apt-get update \ |
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 max_min_negative(lst, n, new_min, new_max): | |
res = [] | |
for i in range(n//2): | |
min_idx = i | |
max_idx = n-i-1 | |
res += [lst[max_idx], lst[min_idx]] | |
if n%2 == 1: | |
res[n-1] = lst[n//2] | |
return res |