-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mask-detection-project
- Loading branch information
Showing
21 changed files
with
3,817 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class MinStack: | ||
def __init__(self): | ||
self.st = [] | ||
self.mini = float('inf') | ||
|
||
def push(self, value: int): | ||
val = value | ||
if not self.st: | ||
self.mini = val | ||
self.st.append(val) | ||
else: | ||
if val < self.mini: | ||
self.st.append(2 * val - self.mini) | ||
self.mini = val | ||
else: | ||
self.st.append(val) | ||
print(f"Element Pushed: {value}") | ||
|
||
def pop(self): | ||
if not self.st: | ||
print("Stack is empty, cannot pop") | ||
return | ||
el = self.st.pop() | ||
if el < self.mini: | ||
print(f"Element popped: {self.mini}") | ||
self.mini = 2 * self.mini - el | ||
else: | ||
print(f"Element popped: {el}") | ||
|
||
def top(self) -> int: | ||
if not self.st: | ||
print("Stack is empty") | ||
return -1 | ||
el = self.st[-1] | ||
if el < self.mini: | ||
top_element = self.mini | ||
else: | ||
top_element = el | ||
print(f"Top Most Element is: {top_element}") | ||
return top_element | ||
|
||
def getMin(self) -> int: | ||
if not self.st: | ||
print("Stack is empty") | ||
return -1 | ||
print(f"Minimum Element in the stack is: {self.mini}") | ||
return self.mini | ||
|
||
# Sample input as per the question | ||
stack = MinStack() | ||
stack.push(9) | ||
stack.push(15) | ||
stack.getMin() | ||
stack.push(1) | ||
stack.getMin() | ||
stack.pop() | ||
stack.getMin() | ||
stack.push(4) | ||
stack.getMin() | ||
stack.pop() | ||
stack.top() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def is_stack_permutation(input, output): | ||
stack = [] # Use list as a stack | ||
j = 0 # Pointer for the output sequence | ||
for i in range(len(input)): | ||
# Push the current element of the input array onto the stack | ||
stack.append(input[i]) | ||
# Check if the top of the stack matches the output array | ||
while stack and stack[-1] == output[j]: | ||
stack.pop() | ||
j += 1 # Move to the next element in output | ||
# If j has reached the length of output, then output is a valid permutation | ||
return j == len(output) | ||
|
||
# Example usage | ||
input = [1, 2, 3] | ||
output = [2, 1, 3] | ||
|
||
if is_stack_permutation(input, output): | ||
print("Yes, it is a stack permutation") | ||
else: | ||
print("No, it is not a stack permutation") |
70 changes: 70 additions & 0 deletions
70
Algorithms_and_Data_Structures/Trees/Menu_Driven_Code_for_BFS.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from collections import deque | ||
|
||
class Node: | ||
def __init__(self, key): | ||
# Initialize a new node with the given key, left and right children as None | ||
self.left = None | ||
self.right = None | ||
self.val = key | ||
|
||
class BinaryTree: | ||
def __init__(self): | ||
# Initialize the binary tree with no root | ||
self.root = None | ||
|
||
def insert(self, key): | ||
# Public method to insert a new key into the binary tree | ||
if self.root is None: | ||
self.root = Node(key) # If tree is empty, create the root | ||
else: | ||
self._insert_rec(self.root, key) # Call the recursive insert method | ||
|
||
def _insert_rec(self, root, key): | ||
# Recursive helper method to insert a key into the tree | ||
if key < root.val: | ||
# If key is smaller, go left | ||
if root.left is None: | ||
root.left = Node(key) # Insert new node | ||
else: | ||
self._insert_rec(root.left, key) # Recur on left child | ||
else: | ||
# If key is greater or equal, go right | ||
if root.right is None: | ||
root.right = Node(key) # Insert new node | ||
else: | ||
self._insert_rec(root.right, key) # Recur on right child | ||
|
||
def bfs(self): | ||
if not self.root: | ||
print("Tree is empty") | ||
return | ||
|
||
queue = deque([self.root]) # Initialize a queue with the root node | ||
while queue: | ||
node = queue.popleft() # Remove the node from the front of the queue | ||
print(node.val, end=' ') # Visit the node | ||
|
||
if node.left: | ||
queue.append(node.left) # Add left child to the queue | ||
if node.right: | ||
queue.append(node.right) # Add right child to the queue | ||
|
||
def menu(): | ||
tree = BinaryTree() # Create a new BinaryTree instance | ||
while True: | ||
# Display menu options | ||
print("\n1. Insert\n2. BFS Traversal\n3. Exit") | ||
choice = int(input("Choose an option: ")) | ||
if choice == 1: | ||
key = int(input("Enter value to insert: ")) # Get value to insert | ||
tree.insert(key) # Insert value into the tree | ||
elif choice == 2: | ||
print("BFS Traversal: ", end='') | ||
tree.bfs() # Perform and print BFS traversal | ||
elif choice == 3: | ||
break # Exit the loop and program | ||
else: | ||
print("Invalid choice!") # Handle invalid input | ||
|
||
if __name__ == "__main__": | ||
menu() # Run the menu function if this file is executed |
18 changes: 18 additions & 0 deletions
18
Automation_Tools/Playlist-downloader/Playlist_downloader/__init__.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pytube import Playlist | ||
def download(playlist_id,download_path): | ||
try: | ||
playlist_url = 'https://www.youtube.com/playlist?list=' +playlist_id | ||
# Create a Playlist object | ||
playlist = Playlist(playlist_url) | ||
# download_path=r'{}'.format(download_path) | ||
# Specify the directory where you want to save the downloaded videos | ||
# Iterate through each video in the playlist and download it to the specified directory | ||
for video in playlist.videos: | ||
try: | ||
print(f'Downloading: {video.title}') | ||
video.streams.get_highest_resolution().download(output_path=download_path) | ||
print(f'{video.title} downloaded successfully!') | ||
except Exception as e: | ||
print(e) | ||
except Exception as e: | ||
print(e) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pytube == 15.0.0 | ||
setuptools==69.0.3 | ||
wheel==0.40.0 | ||
twine==5.1.1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from setuptools import setup | ||
setup(name="Playlist_downloader", | ||
version="1.0", | ||
description="Playlist Downloader simplifies the process of downloading YouTube playlists by providing a straightforward API to fetch and save videos from a given playlist URL.", | ||
long_description=open('README.md').read(), | ||
long_description_content_type='text/markdown', | ||
author="Yash Kumar Saini", | ||
packages=['Playlist_downloader'], | ||
license="MIT", | ||
install_requires=['pytube'] | ||
) |
Oops, something went wrong.