From 1eb1b286bd47ecef211165b9795c11b2f86b49bf Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:23:42 +0530 Subject: [PATCH 1/9] Create README.md pushing a contest problem that i got --- .../README.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /README.md diff --git a/For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /README.md b/For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /README.md new file mode 100644 index 0000000..e3ea551 --- /dev/null +++ b/For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /README.md @@ -0,0 +1,25 @@ + Recursive (Super) Digit Sum +Problem Statement +Find the super digit of a repeating number + +Let's consider the scenario of Alice and Bob. Alice has the number 987 and Bob wants to find the super digit of this number repeated 5 times. The super digit follows the following rules: + +If a number has only one digit, its super digit is equal to that digit. +Otherwise, the super digit of a number is calculated as the super digit of the sum of its digits. +In this case, Alice's number is 987, and Bob wants to repeat it 5 times. So, n = 987 and k = 5. Thus, n k is equal to 987987987987987. To find the super digit, we calculate the sum of the digits: (9 + 8 + 7 + 9 + 8 + 7 + 9 + 8 + 7 + 9 + 8 + 7 + 9 + 8 + 7 + 9 + 8 + 7) = 153. Since 153 has three digits, we further calculate its super digit: (1 + 5 + 3) = 9. Therefore, the super digit of 987 repeated 5 times is 9. + +Important Note: Ensure that you save your solution before progressing to the next question and before submitting your answer. + +Exercise-1 +input: +56785 +2 +output: +8 + +Exercise-2 +input: +65109 +3 +Output: +9 From 48e69145c5ed6c3af3247edc46ec3e13e1d70c4e Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:28:12 +0530 Subject: [PATCH 2/9] Create main.py python program --- .../Recursive (super) super digit sum /main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /main.py diff --git a/For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /main.py b/For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /main.py new file mode 100644 index 0000000..b2262bd --- /dev/null +++ b/For CS - Module 1 - Contest - Python /Recursive (super) super digit sum /main.py @@ -0,0 +1,15 @@ + def calculate_super_digit(number): + if len(str(number)) == 1: + return number + else: + return calculate_super_digit(sum(map(int, str(number)))) + + super_digit = calculate_super_digit(n * k) + return super_digit + +n = int(input()) +k = int(input()) + +super_digit_result = superDigit(n, k) +print(super_digit_result) + From 3bcf33a4f3c226a5779dbf327170d4d16ce21f5e Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:29:38 +0530 Subject: [PATCH 3/9] Create README.md --- .../job sequencing/README.md | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 For CS - Module 1 - Contest - Python /job sequencing/README.md diff --git a/For CS - Module 1 - Contest - Python /job sequencing/README.md b/For CS - Module 1 - Contest - Python /job sequencing/README.md new file mode 100644 index 0000000..6498f49 --- /dev/null +++ b/For CS - Module 1 - Contest - Python /job sequencing/README.md @@ -0,0 +1,47 @@ + +Problem Statement +Job Sequencing + +The problem at hand involves a set of jobs, each with a deadline and an associated profit. These jobs are subject to the constraint that only one job can be scheduled at a time, and each job takes exactly one unit of time to complete. The minimum deadline for a job is 1. +Input: The input consists of an array of jobs with their respective deadlines and profits. The order in which the jobs are listed in the input does not necessarily represent the optimal order. + +Job - Deadline - Profit +A - 2 - 100 +C - 2 - 27 +D - 1 - 25 +E - 3 - 15 +B - 1 - 19 + +The goal is to find a sequence of jobs that maximizes the total profit, subject to the constraint that each job must be completed before its deadline. + +Important Note: Ensure that you save your solution before progressing to the next question and before submitting your answer. + +Exercise-1 + +Input: +6 +a b c d e +2 1 2 1 3 +100 19 27 25 15 + +Note: +Line 1: job count +Line 2: job name +Line 3: deadline +Line 4:Profit + +Output: + +c a e + +Exercise-2 + +Input: + +5 +p q r s t +2 1 3 1 3 +99 190 27 25 15 + +Output: +q p r From 798c9f5c8e485278d020c1ca00262753053899b5 Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:33:10 +0530 Subject: [PATCH 4/9] Create main.py --- .../job sequencing/main.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 For CS - Module 1 - Contest - Python /job sequencing/main.py diff --git a/For CS - Module 1 - Contest - Python /job sequencing/main.py b/For CS - Module 1 - Contest - Python /job sequencing/main.py new file mode 100644 index 0000000..b54b598 --- /dev/null +++ b/For CS - Module 1 - Contest - Python /job sequencing/main.py @@ -0,0 +1,28 @@ +def job_sequencing(job_count, jobs, deadlines, profits): + arr = list(zip(jobs, deadlines, profits)) + arr.sort(key=lambda x: (-x[2], x[1])) + + result = [False] * max(deadlines) + scheduled_jobs = ['-1'] * max(deadlines) + + for i in range(len(arr)): + for j in range(min(max(deadlines) - 1, arr[i][1] - 1), -1, -1): + if result[j] is False: + result[j] = True + scheduled_jobs[j] = arr[i][0] + break + + return scheduled_jobs + + +# Reading input values +job_count = int(input()) +jobs = input().split() +deadlines = list(map(int, input().split())) +profits = list(map(int, input().split())) + +# Calling the function +scheduled_jobs = job_sequencing(job_count, jobs, deadlines, profits) + +# Outputting the result +print(' '.join(scheduled_jobs)) From d0b7e01a9390c53a6b8783bb266811b8c0fb0487 Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:34:30 +0530 Subject: [PATCH 5/9] Update README.md --- .../job sequencing/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/For CS - Module 1 - Contest - Python /job sequencing/README.md b/For CS - Module 1 - Contest - Python /job sequencing/README.md index 6498f49..b55be9f 100644 --- a/For CS - Module 1 - Contest - Python /job sequencing/README.md +++ b/For CS - Module 1 - Contest - Python /job sequencing/README.md @@ -6,12 +6,18 @@ The problem at hand involves a set of jobs, each with a deadline and an associat Input: The input consists of an array of jobs with their respective deadlines and profits. The order in which the jobs are listed in the input does not necessarily represent the optimal order. Job - Deadline - Profit + A - 2 - 100 + C - 2 - 27 + D - 1 - 25 + E - 3 - 15 + B - 1 - 19 + The goal is to find a sequence of jobs that maximizes the total profit, subject to the constraint that each job must be completed before its deadline. Important Note: Ensure that you save your solution before progressing to the next question and before submitting your answer. @@ -19,9 +25,13 @@ Important Note: Ensure that you save your solution before progressing to the nex Exercise-1 Input: + 6 + a b c d e + 2 1 2 1 3 + 100 19 27 25 15 Note: @@ -39,9 +49,13 @@ Exercise-2 Input: 5 + p q r s t + 2 1 3 1 3 + 99 190 27 25 15 Output: + q p r From 595ab3adc0bc4abb5ddef13360cf1651ed5c74e3 Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:47:48 +0530 Subject: [PATCH 6/9] Create README.md goat latin readme --- .../Goat Latin/README.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 For CS - Module 2 and 3 - Contest - Python /Goat Latin/README.md diff --git a/For CS - Module 2 and 3 - Contest - Python /Goat Latin/README.md b/For CS - Module 2 and 3 - Contest - Python /Goat Latin/README.md new file mode 100644 index 0000000..6fbdafc --- /dev/null +++ b/For CS - Module 2 and 3 - Contest - Python /Goat Latin/README.md @@ -0,0 +1,24 @@ +## Problem Statement +# Goat Latin Conversion + +Given a sentence, S, consisting of words separated by spaces, we want to convert it into "Goat Latin," which is a fictional language similar to Pig Latin. + +The rules for Goat Latin conversion are as follows: + +If a word begins with a vowel (a, e, i, o, or u), append "ma" to the end of the word. For example, the word 'apple' becomes 'applema'. + +If a word begins with a consonant (a letter that is not a vowel), remove the first letter, append it to the end of the word, and then add "ma". For example, the word "goat" becomes "oatgma". + +Add one letter 'a' to the end of each word based on its word index in the sentence, starting with 1. For example, the first word gets "a" added to the end, the second word gets "aa" added to the end, and so on. + +Write a program that takes the sentence S as input and returns the final sentence representing its conversion into Goat Latin. + +Important Note: Ensure that you save your solution before progressing to the next question and before submitting your answer. + +Exercise 1: + +Input: +aasssdd + +Output: +aasssddmaa From 73e592bf8a2cf0f1ee42ddf739a7fb17f17a2f29 Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 22:49:02 +0530 Subject: [PATCH 7/9] goat latin main.py file made --- .../Goat Latin/main.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 For CS - Module 2 and 3 - Contest - Python /Goat Latin/main.py diff --git a/For CS - Module 2 and 3 - Contest - Python /Goat Latin/main.py b/For CS - Module 2 and 3 - Contest - Python /Goat Latin/main.py new file mode 100644 index 0000000..e99f12c --- /dev/null +++ b/For CS - Module 2 and 3 - Contest - Python /Goat Latin/main.py @@ -0,0 +1,18 @@ +def toGoatLatin(S): + vowels = set('aeiouAEIOU') + words = S.split() + result = [] + + for i, word in enumerate(words, 1): + if word[0] in vowels: + word += 'ma' + 'a' * i + else: + word = word[1:] + word[0] + 'ma' + 'a' * i + + result.append(word) + + return ' '.join(result) + +S = input() + +print(toGoatLatin(S)) From 404080c8aedc825062695d989f796de5b64ac59b Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:05:00 +0530 Subject: [PATCH 8/9] made readme for network connection --- .../Network connection/README.md | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 For CS - Module 2 and 3 - Contest - Python /Network connection/README.md diff --git a/For CS - Module 2 and 3 - Contest - Python /Network connection/README.md b/For CS - Module 2 and 3 - Contest - Python /Network connection/README.md new file mode 100644 index 0000000..4e8fb9b --- /dev/null +++ b/For CS - Module 2 and 3 - Contest - Python /Network connection/README.md @@ -0,0 +1,73 @@ +## Number of Operations to Make Network Connected +## Problem Statement +# Connecting a network + +In a geographical region, there are N cities labeled from 1 to N. These cities are interconnected using various transportation routes forming a network. The city connectivity is represented by a list of connections between cities in the form of a 2D array route[][]. Each row (city1, city2) denotes a direct transportation route between city1 and city2. + +Your task is to ensure that all cities are connected either directly or indirectly. To achieve this, you can perform the following operations: + + Remove any existing transportation route between two cities. + Add a new transportation route between two disconnected cities. + +Your goal is to find the minimum number of operations required to achieve full connectivity of all cities in the region. + +Return the minimum number of times you need to do this in order to make all the cities connected. If it is not possible, return -1. + +Example +Input: N = 6, + +routes[][] = {{1, 2}, {2, 3}, {3, 5}, {4, 5}, {5, 6}} + +Output: +1 + +Exercise-1 + +Input : + +6 + +5 + +0 1 + +0 2 + +0 3 + +1 2 + +1 3 + +Note: +Line 1: Available cities +Line 2 : No of routes +From line 3 : connected cities pair + +Output : + +2 + +Exercise-2 + +Input: + +5 + +5 + +0 1 + +0 2 + +0 3 + +1 2 + +2 3 + + +Output: + +1 + From b30ac7fb1a659093a583c5be84a5ef5efbd4b76c Mon Sep 17 00:00:00 2001 From: ABHIJEET <93534675+SILICON-HAWK@users.noreply.github.com> Date: Wed, 13 Dec 2023 23:05:50 +0530 Subject: [PATCH 9/9] made main py for network connection --- .../Network connection/main.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 For CS - Module 2 and 3 - Contest - Python /Network connection/main.py diff --git a/For CS - Module 2 and 3 - Contest - Python /Network connection/main.py b/For CS - Module 2 and 3 - Contest - Python /Network connection/main.py new file mode 100644 index 0000000..1e3dcf1 --- /dev/null +++ b/For CS - Module 2 and 3 - Contest - Python /Network connection/main.py @@ -0,0 +1,48 @@ +class UnionFind: + def __init__(self, n): + self.parent = list(range(n)) + self.rank = [0] * n + + def find(self, x): + if self.parent[x] != x: + self.parent[x] = self.find(self.parent[x]) + return self.parent[x] + + def union(self, x, y): + root_x = self.find(x) + root_y = self.find(y) + + if root_x != root_y: + if self.rank[root_x] < self.rank[root_y]: + root_x, root_y = root_y, root_x + self.parent[root_y] = root_x + if self.rank[root_x] == self.rank[root_y]: + self.rank[root_x] += 1 + +def makeConnected(n, connections): + uf = UnionFind(n) + extra_connections = 0 + + for u, v in connections: + if uf.find(u) != uf.find(v): + uf.union(u, v) + else: + extra_connections += 1 + + components = len(set(uf.find(i) for i in range(n))) + + if extra_connections >= components - 1: + return components - 1 + else: + return -1 + +# Input +n = int(input()) # Number of available cities +m = int(input()) # Number of routes +connections = [] +for _ in range(m): + u, v = map(int, input().split()) + connections.append([u, v]) + +result = makeConnected(n, connections) +print(result)