Skip to content

Commit

Permalink
Merge branch 'main' into mask-detection-project
Browse files Browse the repository at this point in the history
  • Loading branch information
Dharun235 authored Nov 2, 2024
2 parents df1bafc + 1d82b44 commit b81efe2
Show file tree
Hide file tree
Showing 21 changed files with 3,817 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/auto-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
// Check for participation roles in the issue body
const hasGSSOC = issueBody.includes('gssoc');
const hasHacktoberfest = issueBody.includes('hacktoberfest');
const hasHacktoberfest = issueBody.includes('hacktoberfest-2024');
const labelsToAdd = [];
Expand Down
61 changes: 61 additions & 0 deletions Algorithms_and_Data_Structures/Stack/Min_Stack.py
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()
21 changes: 21 additions & 0 deletions Algorithms_and_Data_Structures/Stack/Stack_permutation.py
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 Algorithms_and_Data_Structures/Trees/Menu_Driven_Code_for_BFS.py
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
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)
4 changes: 4 additions & 0 deletions Automation_Tools/Playlist-downloader/requirements.txt
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
11 changes: 11 additions & 0 deletions Automation_Tools/Playlist-downloader/setup.py
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']
)
Loading

0 comments on commit b81efe2

Please sign in to comment.