Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
95d49f5
Added Day 1 Solution
programmer-prince Dec 1, 2024
6a50988
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 2, 2024
b132a70
Merge remote-tracking branch 'upstream/main' into the-ai-developer
programmer-prince Dec 2, 2024
7a8b91c
Added Day 2 Solution & Screenshots
programmer-prince Dec 2, 2024
d5711e9
Merge branch 'the-ai-developer' of https://github.com/the-ai-develope…
programmer-prince Dec 2, 2024
b0c40cf
Added Day 2 Solution
programmer-prince Dec 2, 2024
5e9c13a
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 3, 2024
35a3032
Added Day 3 Solution
programmer-prince Dec 3, 2024
379690d
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 4, 2024
59c6cb5
Added Day 4 Solution
programmer-prince Dec 4, 2024
c6a7243
Added Day 4 Solution
programmer-prince Dec 4, 2024
2e5f3a1
Added Day 4 Solution
programmer-prince Dec 4, 2024
0774bd1
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 6, 2024
4f1b80a
Added Day 5 And Day 6 Solution
programmer-prince Dec 6, 2024
4b64189
Added Day 7 Solution
programmer-prince Dec 7, 2024
bca8789
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 7, 2024
76bceb6
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 8, 2024
3576fe5
Added Day 8 Solution
programmer-prince Dec 8, 2024
a498707
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 17, 2024
93ef30e
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 26, 2024
3ba87df
Added Day 9 Solution
programmer-prince Dec 26, 2024
25a5f9d
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 26, 2024
fc2b4d9
Merge branch 'SVCE-ACM:main' into the-ai-developer
the-ai-developer Dec 31, 2024
4b4731d
Added Day 12 Solution
programmer-prince Dec 31, 2024
74aae57
Added Day 10 Solution
programmer-prince Jan 13, 2025
a80456b
Added Day 11 Solution
programmer-prince Jan 13, 2025
5d54f07
Added Day 12 Solution
programmer-prince Jan 13, 2025
c264572
Added Day 12 Solution
programmer-prince Jan 13, 2025
2e509c4
Added Day 13 Solution
programmer-prince Jan 15, 2025
1293a9d
Added Day 14 Solution
programmer-prince Jan 15, 2025
4239ef0
Added Day 15 Solution
programmer-prince Jan 15, 2025
964c0f3
Added Day 16 Solution
programmer-prince Jan 15, 2025
6ca8077
Added Day 17 Solution
programmer-prince Jan 15, 2025
d08b573
Added Day 17 Solution
programmer-prince Jan 15, 2025
40fb6b3
Added Day 18 And 19 Solution
programmer-prince Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Rc, Bc = map(int, input("Enter Red And Blue Blocks Count: ").split(" "))
if abs(Rc - Bc) != 1:
print("Not Possible!")
else:
Greatest = 'R' if Rc > Bc else 'B'
Smallest = 'R' if Rc < Bc else 'B'
Min = min(Rc, Bc)
result = []
for i in range(Min):
result.append(Greatest)
result.append(Smallest)
result.append(Greatest)
print("Anagram: ", ''.join(result))
52 changes: 52 additions & 0 deletions Solutions/python3_the-ai-developer_Concurrent-Task-Execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from collections import defaultdict, deque

def Exec_Ordr(tasks):
graph = defaultdict(list)
in_deg = defaultdict(int)

for task, dependencies in tasks:
in_deg[task]
for dep in dependencies:
graph[dep].append(task)
in_deg[task] += 1

queue = deque([task for task in in_deg if in_deg[task] == 0])
result = []

while queue:
current_batch = []
for _ in range(len(queue)):
task = queue.popleft()
current_batch.append(task)

for neighbor in graph[task]:
in_deg[neighbor] -= 1
if in_deg[neighbor] == 0:
queue.append(neighbor)

result.append(current_batch)

if sum(len(batch) for batch in result) != len(tasks):
return "Error: Cyclic dependency detected"

return result

if __name__ == "__main__":
n = int(input("Enter the number of tasks: "))
tasks = []

for _ in range(n):
task_id = input(f"Enter Task ID for Task {_+1}: ")
dependencies = input(f"Enter dependencies @Task {task_id}: ")
dependencies = dependencies.split(",") if dependencies else []
tasks.append((task_id, dependencies))

output = Exec_Ordr(tasks)

if isinstance(output, str):
print(output)
else:
print("Execution Order:")
for i, batch in enumerate(output, 1):
print(f"Step {i}: {batch}")

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print(f"Customers Who Returned Only Once: {list(map(int,input('Enter Return List: ').split())).count(1)}")
104 changes: 104 additions & 0 deletions Solutions/python3_the-ai-developer_Cybersecurity-Alert-Management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
from datetime import datetime, timedelta

class AlertManager:
def __init__(self):
self.alerts = {}

def parse_timestamp(self, timestamp):
try:
return datetime.strptime(timestamp, "%H:%M:%S")
except ValueError:
raise ValueError(f"Invalid timestamp format: {timestamp}. Expected HH:MM:SS.")

def process_alert(self, alert):
alert_id = alert["id"]
timestamp = self.parse_timestamp(alert["timestamp"])
threat_level = alert["threat_level"]

if alert_id in self.alerts:
stored_alert = self.alerts[alert_id]
stored_time = stored_alert["timestamp"]

# Ignore alert if it's within 30 seconds
if timestamp - stored_time <= timedelta(seconds=30):
return

# Update threat level if higher
if threat_level > stored_alert["threat_level"]:
self.alerts[alert_id]["threat_level"] = threat_level
self.alerts[alert_id]["timestamp"] = timestamp
else:
self.alerts[alert_id] = {"timestamp": timestamp, "threat_level": threat_level}

def evict_old_alerts(self, current_time):
current_time = self.parse_timestamp(current_time)
ids_to_remove = []

print("\n[DEBUG] Current Time:", current_time)
print("[DEBUG] Stored Alerts Before Eviction:")
for alert_id, data in self.alerts.items():
print(f" - ID: {alert_id}, Timestamp: {data['timestamp']}, Threat Level: {data['threat_level']}")

for alert_id, data in self.alerts.items():
if current_time - data["timestamp"] > timedelta(minutes=5):
print(f"[DEBUG] Evicting Alert ID: {alert_id} (Timestamp: {data['timestamp']})")
ids_to_remove.append(alert_id)

for alert_id in ids_to_remove:
del self.alerts[alert_id]

print("[DEBUG] Stored Alerts After Eviction:")
for alert_id, data in self.alerts.items():
print(f" - ID: {alert_id}, Timestamp: {data['timestamp']}, Threat Level: {data['threat_level']}")

def get_stored_alerts(self):
result = []
for alert_id, data in self.alerts.items():
result.append({
"id": alert_id,
"timestamp": data["timestamp"].strftime("%H:%M:%S"),
"threat_level": data["threat_level"]
})
return result


def main():
alert_manager = AlertManager()
print("Enter alerts in the format: id,timestamp,threat_level (e.g., A123,00:00:10,3)")
print("Type 'stop' to finish...")

while True:
user_input = input("Enter alert: ").strip()
if user_input.lower() == "stop":
break

try:
alert_id, timestamp, threat_level = user_input.split(",")
alert = {
"id": alert_id.strip(),
"timestamp": timestamp.strip(),
"threat_level": int(threat_level.strip())
}
alert_manager.process_alert(alert)
except ValueError as e:
print(f"Invalid format. Please try again. Error: {e}")

current_time = input("Enter the current time (HH:MM:SS): ").strip()
try:
alert_manager.evict_old_alerts(current_time)
except ValueError as e:
print(f"Error with current time: {e}")
return

print("\nStored alerts:")
stored_alerts = alert_manager.get_stored_alerts()
if not stored_alerts:
print("No alerts to display.")
else:
for alert in stored_alerts:
print(f"ID: {alert['id']}, Timestamp: {alert['timestamp']}, Threat Level: {alert['threat_level']}")


if __name__ == "__main__":
main()

15 changes: 15 additions & 0 deletions Solutions/python3_the-ai-developer_Digit-Manipulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def DigitSqrSum(n):
def DigitSum(x):
square_sum=0
while x>0:
digit=x%10
square_sum+=digit*digit
x//=10
return square_sum
total_sum=0
for i in range(1,n+1):
total_sum += DigitSum(i)
return total_sum

print(f"Resultant Sum: {DigitSqrSum(int(input('Enter A Number: ')))}")

12 changes: 12 additions & 0 deletions Solutions/python3_the-ai-developer_Endless-Towers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def HanoiTower(n, source, target, auxiliary):
if n == 1:
print(f"Move disk 1 from {source} to {target}")
return
HanoiTower(n - 1, source, auxiliary, target)
print(f"Move disk {n} from {source} to {target}")
HanoiTower(n - 1, auxiliary, target, source)

n = int(input("Enter number of disks: "))
print(f"Minimum No.Of Moves: {(2**n)-1}!\nThe Move Sequence:")
HanoiTower(n, 'A', 'C', 'B')

17 changes: 17 additions & 0 deletions Solutions/python3_the-ai-developer_Holiday-Gift-Arrangement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def minTrips(houses, W):
trips = 0
current_load = 0

for gifts in houses:
if current_load + gifts > W:
trips += 1
current_load = 0
current_load += gifts

if current_load > 0:
trips += 1

return trips

print(f"Required Minimum No.Of Trips: {minTrips(list(map(int, input('Enter Gifts For Houses: ').split())), int(input('Enter Max Capacity: ')))}")

43 changes: 43 additions & 0 deletions Solutions/python3_the-ai-developer_Howards-Rare-Gems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def manachers_algorithm(S):
S1 = '#'.join('^{}$'.format(S))
LPS = [0] * len(S1)
center = right = 0

for i in range(1, len(S1) - 1):
mirror = 2 * center - i
if i < right:
LPS[i] = min(right - i, LPS[mirror])

while S1[i + LPS[i] + 1] == S1[i - (LPS[i] + 1)]:
LPS[i] += 1

if i + LPS[i] > right:
center = i
right = i + LPS[i]

max_len, centerIndex = max((j, i) for i, j in enumerate(LPS))
start = (centerIndex - max_len) // 2
end = (centerIndex + max_len) // 2
return S[start:end]

def MaxPalindromicChainInc(chain):
gem_values = {'D': 500, 'R': 250, 'E': 100}
longest_palindrome = manachers_algorithm(chain)

if not longest_palindrome:
return 0

print(f"Longest Plaindrome: {longest_palindrome}")

gem_sum = 0
for gem in longest_palindrome:
gem_sum += gem_values[gem]

profit = gem_sum * len(longest_palindrome)
return profit

if __name__ == "__main__":
chain = input("Enter Your Chain: ").strip()
profit = MaxPalindromicChainInc(chain)
print(f"Chain: {chain} -> Max Profit: ${profit}")

9 changes: 9 additions & 0 deletions Solutions/python3_the-ai-developer_Josephus-Problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def Josephus(List,CrntIdx,k):
if len(List)==1:
return List[0]
CrntIdx=(CrntIdx+k)%len(List)
del List[CrntIdx]
return Josephus(List,CrntIdx,k)

NPpl,k=list(map(int,input("Enter No.Of Peoples And The Kill Count: ").split()))
print(f"In Order To Be In A Safe Zone, You Need To Stand At: {Josephus([x for x in range(1,NPpl+1)],0,k-1)}")
27 changes: 27 additions & 0 deletions Solutions/python3_the-ai-developer_Min-Swap-Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def MinSwaps2Sort(arr):
n = len(arr)
paired = [(arr[i], i) for i in range(n)]
paired.sort(key=lambda x: x[0])

visited = [False] * n
swaps = 0

for i in range(n):
if visited[i] or paired[i][1] == i:
continue

cycle_length = 0
current = i
while not visited[current]:
visited[current] = True
next_index = paired[current][1]
current = next_index
cycle_length += 1

if cycle_length > 1:
swaps += (cycle_length - 1)

return swaps

print(f"Min No.Of Swaps: {MinSwaps2Sort(list(map(int,input('Enter Graph List: ').split(' '))))}")

3 changes: 3 additions & 0 deletions Solutions/python3_the-ai-developer_Plant-Growth-Tracker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import math
N = int(input("Enter No.Of Months: "))
print(f"No.Of Plants(Predicted!): {int(((1+math.sqrt(5))**N-(1-math.sqrt(5))**N)/(2**N*math.sqrt(5)))}")
40 changes: 40 additions & 0 deletions Solutions/python3_the-ai-developer_Smart-Ticketing-System.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from collections import deque

def TktCounter(N, requests):
vip_queue = deque()
regular_queue = deque()
result = []

for request in requests:
parts = request.split()
name = parts[0]
tickets_requested = int(parts[1])
is_vip = "VIP" in parts
if is_vip:
vip_queue.append((name, tickets_requested))
else:
regular_queue.append((name, tickets_requested))

while N > 0 and (vip_queue or regular_queue):
if vip_queue:
customer, tickets_requested = vip_queue.popleft()
else:
customer, tickets_requested = regular_queue.popleft()

if tickets_requested <= N:
result.append(f"{customer} purchased {tickets_requested} tickets")
N -= tickets_requested
else:
result.append(f"{customer} purchased {N} tickets")
N = 0

for queue in [vip_queue, regular_queue]:
while queue:
customer, _ = queue.popleft()
result.append(f"{customer} was not served")

return result

N = int(input("Enter No.Of Tickets: "))
Req_Booking = list(map(str,input("Enter Ticket Requests: ").split(",")))
print(f"Reservation Sheet!\n{TktCounter(N,Req_Booking)}")
39 changes: 39 additions & 0 deletions Solutions/python3_the-ai-developer_Split-The-Squad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from collections import Counter

def SplitTheSquad():
T = int(input("Enter No.Of Entities: "))
results = []

for x in range(T):
N, K, D = map(int, input(f"Enter The Values Of N,K And D Of Entity {x+1}: ").split())
A = list(map(int, input(f"Enter The List(A) Of Entitity {x+1}: ").split()))
freq = Counter(A)
U_total = len(freq)

if U_total < 2 * K:
results.append("NO")
continue

counts = sorted(freq.values(), reverse=True)
team1_count, team2_count = 0, 0
team1_uniques, team2_uniques = 0, 0

for count in counts:
if team1_uniques < K:
team1_count += count
team1_uniques += 1
elif team2_uniques < K:
team2_count += count
team2_uniques += 1
else:
break

if team1_uniques == K and team2_uniques == K and abs(team1_count - team2_count) <= D:
results.append("YES")
else:
results.append("NO")

print("\n".join(results))

SplitTheSquad()

Loading