diff --git a/IO_data_procession_question.md b/IO_data_procession_question.md new file mode 100644 index 0000000..5d65efc --- /dev/null +++ b/IO_data_procession_question.md @@ -0,0 +1,160 @@ +--- +title: Simple Product Sales Analysis +tags: ['python', 'data-types', 'strings', 'int', 'dictionaries', 'stdin'] +--- +# Problem Statement +Given a list of product sales, calculate: +1. The total quantity sold for each product (in alphabetical order) +2. The product that sold the most units (best seller) + +**Input Format:** First line contains N (number of sales). Next N lines contain space-separated product_name and quantity. + +**Output Format:** Print each product's total quantity in alphabetical order, followed by the best seller. + +**Note:** Product names contain only lowercase letters. + +**Sample Input** +``` +5 +apple 10 +banana 5 +apple 3 +orange 8 +banana 7 +``` + +**Sample Output** +``` +apple: 13 +banana: 12 +orange: 8 +best_seller: apple +``` + +**Explanation** +Apple sold 10+3=13 units, banana sold 5+7=12 units, and orange sold 8 units. Apple has the highest total sales (13), making it the best seller. + +# Solution +```py test.py -r 'python3 test.py' + +def analyze_sales(n: int) -> str: + ''' + Process n product sales and return formatted string + containing total sales per product and best seller. + ''' + + + +n = int(input()) +print(analyze_sales(n)) + +``` + +# Public Test Cases +## Input 1 +``` +5 +apple 10 +banana 5 +apple 3 +orange 8 +banana 7 +``` +## Output 1 +``` +apple: 13 +banana: 12 +orange: 8 +best_seller: apple +``` +## Input 2 +``` +3 +milk 3 +bread 2 +milk 4 +``` +## Output 2 +``` +bread: 2 +milk: 7 +best_seller: milk +``` +## Input 3 +``` +4 +tea 5 +coffee 5 +juice 5 +tea 1 +``` +## Output 3 +``` +coffee: 5 +juice: 5 +tea: 6 +best_seller: tea +``` + +# Private Test Cases +## Input 1 +``` +2 +book 1 +pen 1 +``` +## Output 1 +``` +book: 1 +pen: 1 +best_seller: book +``` +## Input 2 +``` +1 +apple 10 +``` +## Output 2 +``` +apple: 10 +best_seller: apple +``` +## Input 3 +``` +6 +water 2 +soda 3 +water 4 +juice 1 +soda 2 +water 1 +``` +## Output 3 +``` +juice: 1 +soda: 5 +water: 7 +best_seller: water +``` diff --git a/data_processing_question.md b/data_processing_question.md new file mode 100644 index 0000000..0a4c1e2 --- /dev/null +++ b/data_processing_question.md @@ -0,0 +1,131 @@ +--- +title: Process Student Grades +tags: ["data processing", "sorting", "Python"] +--- + +# Problem Statement + +Write a function `process_student_grades` that takes a list of tuples as input. Each tuple contains a student's name (string) and their grade (integer). The data is incomplete, as each student gets additional bonus marks of 5, capping the total marks to 100. + +The function should return the name of the student with the highest grade after applying the bonus. If there is a tie, return the alphabetically smallest name among the highest scorers. + +--- + +# Solution + +```python test.py -r 'python3 test.py' + + + + + +input_data = input().strip() +student_data = eval(input_data) +result = process_student_grades(student_data) +print(result) + + + +``` + +--- + +# Public Test Cases + +## Input 1 + +``` +[("Alice", 85), ("Bob", 92), ("Charlie", 92), ("David", 88)] +``` + +## Output 1 + +``` +Bob +``` + +## Input 2 + +``` +[("Eve", 90), ("Frank", 87), ("Grace", 90), ("Heidi", 85)] +``` + +## Output 2 + +``` +Eve +``` + +--- + +# Private Test Cases + +## Input 1 + +``` +[("Anna", 99), ("Bella", 98), ("Cara", 97)] +``` + +## Output 1 + +``` +Anna +``` + +## Input 2 + +``` +[("Zack", 88), ("Yasmin", 88), ("Xander", 88)] +``` + +## Output 2 + +``` +Xander +``` + +## Input 3 + +``` +[("Maya", 75), ("Noah", 70), ("Olivia", 80), ("Liam", 85)] +``` + +## Output 3 + +``` +Liam +``` + +## Input 4 + +``` +[("Ivy", 95), ("Jack", 95), ("Hannah", 95)] +``` + +## Output 4 + +``` +Hannah +``` diff --git a/data_type_question.md b/data_type_question.md new file mode 100644 index 0000000..f17b51a --- /dev/null +++ b/data_type_question.md @@ -0,0 +1,127 @@ +--- +title: Data Type Operations +tags: ['python', 'data-types', 'strings', 'lists', 'dictionaries', 'sets', 'type-conversion'] +--- +# Problem Statement +Implement a function `transform_data(num, text, items)` that performs the following operations: + +1. Takes three parameters: + - `num`: An integer or float + - `text`: A string + - `items`: A list of elements + +2. The function should: + - Convert the number to its absolute value and round it to 2 decimal places + - Convert the text to uppercase and remove any leading/trailing spaces + - Convert the list into a set to remove duplicates, then back to a sorted list + - Create a dictionary with three keys: + - 'number': processed number + - 'text': processed text + - 'items': processed list + +3. Return the resulting dictionary + +Example: +```python +Input: transform_data(-15.3267, " Hello world ", [1, 3, 2, 1, 4, 2]) +Output: {'number': 15.33, 'text': 'HELLO WORLD', 'items': [1, 2, 3, 4]} +``` + +# Solution +```python test.py -r 'python3 test.py' + +def transform_data(num, text, items): + + + +num = float(input()) +text = input() +items = eval(input()) +result = transform_data(num, text, items) +print(result) + + + +``` + +# Public Test Cases +## Input 1 +``` +-15.3267 + Hello world +[1, 3, 2, 1, 4, 2] +``` +## Output 1 +``` +{'number': 15.33, 'text': 'HELLO WORLD', 'items': [1, 2, 3, 4]} +``` +## Input 2 +``` +42.0 + Python +[5, 5, 5, 5] +``` +## Output 2 +``` +{'number': 42.0, 'text': 'PYTHON', 'items': [5]} +``` + +# Private Test Cases +## Input 1 +``` +-0.0056 + ALREADY upper +[10, 20, 30, 20, 10] +``` +## Output 1 +``` +{'number': 0.01, 'text': 'ALREADY UPPER', 'items': [10, 20, 30]} +``` +## Input 2 +``` +789.98765 + spaces everywhere +[] +``` +## Output 2 +``` +{'number': 789.99, 'text': 'SPACES EVERYWHERE', 'items': []} +``` +## Input 3 +``` +-123456.789 +NoSpaces +[1, 2, 3, 2, 1] +``` +## Output 3 +``` +{'number': 123456.79, 'text': 'NOSPACES', 'items': [1, 2, 3]} +``` +## Input 4 +``` +0.0 + +[9, 8, 7, 8, 9] +``` +## Output 4 +``` +{'number': 0.0, 'text': '', 'items': [7, 8, 9]} +``` \ No newline at end of file diff --git a/empty.md b/empty.md new file mode 100644 index 0000000..85d5e73 --- /dev/null +++ b/empty.md @@ -0,0 +1,123 @@ +--- +title: Find the Student with the Highest Grade +--- + +# Problem Statement + +Given a list of student names and their grades, find the name of the student with the highest grade. If multiple students have the same highest grade, return the lexicographically smallest name among them. + +**Input Format:** +A semicolon-separated list of student name-grade pairs in the format `name,grade`. Each pair is separated by a semicolon. + +**Output Format:** +The name of the student with the highest grade. + +**Sample Input** +``` +Alice,85;Bob,92;Charlie,92;David,88 +``` + +**Sample Output** +``` +Bob +``` + +**Explanation** + +The highest grade is 92, and the students with this grade are Bob and Charlie. Among them, "Bob" is lexicographically smaller. + +# Solution +```py test.py -r 'python3 test.py' + +def highest_grade_student(data: str) -> str: + ''' + Return the name of the student with the highest grade. + ''' + + + +data = input().strip() +print(highest_grade_student(data)) + +``` + +# Public Test Cases + +## Input 1 + +``` +Alice,85;Bob,92;Charlie,92;David,88 +``` + +## Output 1 + +``` +Bob +``` + +## Input 2 + +``` +Emma,75;Liam,90;Olivia,90;Sophia,90 +``` + +## Output 2 + +``` +Liam +``` + +## Input 3 + +``` +John,50;Jane,75;Doe,75;Adam,40 +``` + +## Output 3 + +``` +Doe +``` + +# Private Test Cases + +## Input 1 + +``` +Michael,80;Sarah,95;Alex,95;Zara,85 +``` + +## Output 1 + +``` +Alex +``` + +## Input 2 + +``` +Aaron,100;Zoe,100;Clara,99 +``` + +## Output 2 + +``` +Aaron +``` + +## Input 3 + +``` +Isabella,0 +``` + +## Output 3 + +``` +Isabella +``` diff --git a/function_problem_solving.md b/function_problem_solving.md new file mode 100644 index 0000000..59d5469 --- /dev/null +++ b/function_problem_solving.md @@ -0,0 +1,119 @@ +--- +title: Password Strength Validator +tags: ['python', 'functions', 'strings', 'lists', 'type-check'] +--- +# Problem Statement +Write a function that evaluates the strength of a given password based on specific criteria. + +The password must satisfy all the following conditions: +1. Password should have at least 8 characters +2. Password should contain at least one uppercase letter +3. Password should contain at least one lowercase letter +4. Password should contain atleast one digit +5. Password should contain at least one special character from: @#$%^&* + +**Input Format:** A single string representing the password +**Output Format:** A tuple containing (boolean, list) where: +- boolean indicates if the password meets all criteria (True/False) +- list contains feedback number for the unmet criteria (empty list if all criteria are met) + +**Sample Input** +``` +Hello123@ +``` +**Sample Output** +``` +(True, []) +``` +# Solution +```py test.py -r 'python3 test.py' + +def check_password_strength(password: str) -> tuple: + ''' + Evaluate password strength based on given criteria. + Returns (True, []) if password is strong, + (False, feedback) if criteria not met. + ''' + + + +password = input().strip() +result = check_password_strength(password) +print(result) + +``` +# Public Test Cases +## Input 1 +``` +Hello123@ +``` +## Output 1 +``` +(True, []) +``` +## Input 2 +``` +hello123 +``` +## Output 2 +``` +(False, [2, 5]) +``` +## Input 3 +``` +Ab1@defgh +``` +## Output 3 +``` +(True, []) +``` + +# Private Test Cases +## Input 1 +``` +Ab1 +``` +## Output 1 +``` +(False, [1, 5]) +``` +## Input 2 +``` +HELLO123@ +``` +## Output 2 +``` +(False, [3]) +``` +## Input 3 +``` +HelloWorld#1 +``` +## Output 3 +``` +(True, []) +``` \ No newline at end of file