diff --git a/Q1_process_mixed_data_types.md b/Q1_process_mixed_data_types.md new file mode 100644 index 0000000..9264339 --- /dev/null +++ b/Q1_process_mixed_data_types.md @@ -0,0 +1,192 @@ +--- +title: Process Mixed Data Types +--- + +# Problem Statement + +Write a function process_data(data: dict) -> dict that takes a dictionary with the following keys and performs the described operations: +'int': Add 15 to the integer value. +'float': Multiply the float value by 1.5. +'str': Convert the string to uppercase. +'list': Reverse the list. +'set': Add the number 100 to the set. +'dict': Add a new key-value pair 'hello': 'haha'. + +**Example** +```py3 +data = { + 'int': 5, + 'float': 2.5, + 'str': 'hello', + 'list': [1, 2, 3], + 'set': {1, 2, 3}, + 'dict': {'a': 1, 'b': 2} +} +process_data(data) +# Output: +{ + 'int': 20, + 'float': 3.75, + 'str': 'HELLO', + 'list': [3, 2, 1], + 'set': {1, 2, 3, 100}, + 'dict': {'a': 1, 'b': 2, 'hello': 'haha'} +} + +``` + +# Solution + +```py3 test.py -r 'python test.py' + +# some prefix + + + +# some suffix + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + + +``` + +# Public Test Cases + +## Input 1 + +``` +data = { + 'int': 10, + 'float': 4.0, + 'str': 'python', + 'list': [5, 6, 7], + 'set': {8, 9}, + 'dict': {'x': 1} +} +is_equal( + process_data(data), + { + 'int': 25, + 'float': 6.0, + 'str': 'PYTHON', + 'list': [7, 6, 5], + 'set': {8, 9, 100}, + 'dict': {'x': 1, 'hello': 'haha'} + } +) + +``` + +## Output 1 + +``` + { + 'int': 25, + 'float': 6.0, + 'str': 'PYTHON', + 'list': [7, 6, 5], + 'set': {8, 9, 100}, + 'dict': {'x': 1, 'hello': 'haha'} + } +``` + +## Input 2 + +``` +data = { + 'int': 0, + 'float': 1.0, + 'str': 'test', + 'list': [], + 'set': set(), + 'dict': {} +} +is_equal( + process_data(data), + { + 'int': 15, + 'float': 1.5, + 'str': 'TEST', + 'list': [], + 'set': {100}, + 'dict': {'hello': 'haha'} + } +) + +``` + +## Output 2 + +``` + { + 'int': 15, + 'float': 1.5, + 'str': 'TEST', + 'list': [], + 'set': {100}, + 'dict': {'hello': 'haha'} + } +``` + +# Private Test Cases + +## Input 1 + +``` +data = { + 'int': -5, + 'float': 0.0, + 'str': 'abcd', + 'list': [1], + 'set': {42}, + 'dict': {'k1': 'v1'} +} +is_equal( + process_data(data), + { + 'int': 10, + 'float': 0.0, + 'str': 'ABCD', + 'list': [1], + 'set': {42, 100}, + 'dict': {'k1': 'v1', 'hello': 'haha'} + } +) + +``` + +## Output 1 + +``` + { + 'int': 10, + 'float': 0.0, + 'str': 'ABCD', + 'list': [1], + 'set': {42, 100}, + 'dict': {'k1': 'v1', 'hello': 'haha'} + } +``` diff --git a/Q2_group_words_by_length.md b/Q2_group_words_by_length.md new file mode 100644 index 0000000..b7f0be0 --- /dev/null +++ b/Q2_group_words_by_length.md @@ -0,0 +1,103 @@ +--- +title: Group Words by Length +--- + +# Problem Statement + +Given a list of words, group them by their lengths and return a dictionary where the keys are the lengths, and the values are lists of words with that length. +**Example** +``` +words = ["apple", "bat", "car", "door", "ant", "elephant"] + +``` +The output should be: +{3: ["bat", "car", "ant"], 5: ["apple"], 4: ["door"], 8: ["elephant"]} + + +# Solution + +```py3 test.py -r 'python test.py' + + + +{% include '../function_type_and_is_equal_suffix.py.jinja' %} + + +``` + +# Public Test Cases + +## Input 1 + +``` +words = ["cat", "dog", "bird", "fish", "horse"] +is_equal( + group_words_by_length(words), + {3: ["cat", "dog"], 4: ["bird", "fish"], 5: ["horse"]} +) + +``` + +## Output 1 + +``` +{3: ["cat", "dog"], 4: ["bird", "fish"], 5: ["horse"]} + +``` + +## Input 2 + +``` +words = ["a", "to", "the", "quick", "brown", "fox"] +is_equal( + group_words_by_length(words), + {1: ["a"], 2: ["to"], 3: ["the"], 5: ["quick"], 4: ["brown", "fox"]} +) + +``` + +## Output 2 + +``` +{1: ["a"], 2: ["to"], 3: ["the"], 5: ["quick"], 4: ["brown", "fox"]} + +``` + +# Private Test Cases + +## Input 1 + +``` +words = ["blue", "red", "yellow", "pink", "orange"] +is_equal( + group_words_by_length(words), + {4: ["blue", "pink"], 3: ["red"], 6: ["yellow"], 6: ["orange"]} +) + +``` + +## Output 1 + +``` +{4: ["blue", "pink"], 3: ["red"], 6: ["yellow", "orange"]} + +``` diff --git a/Q3_unique_length_of3_palindrome_subsequence.md b/Q3_unique_length_of3_palindrome_subsequence.md new file mode 100644 index 0000000..a0b5e59 --- /dev/null +++ b/Q3_unique_length_of3_palindrome_subsequence.md @@ -0,0 +1,137 @@ +--- +title: Unique Length-3 Palindromic Subsequences +--- + +# Problem Statement + +Given a string s, find the number of unique palindromic subsequences of length 3 in the string. A subsequence is defined as a sequence derived from another sequence by deleting some or no elements without changing the order of the remaining elements. + +**Note:** + +**Input Format:** A single string s (1 ≤ |s| ≤ 10^4) consisting of lowercase English letters. + +**Output Format:** he count of unique palindromic subsequences of length 3. + +**Sample Input** +``` +aabca +``` +**Sample Output** +``` +3 +``` + +# Solution +```py test.py -r 'python test.py' + + +# Input parsing +s = input().strip() + +# Output the result +print(count_unique_palindromes(s)) + + + +``` + +# Public Test Cases + +## Input 1 + +``` +aabca +``` + +## Output 1 + +``` +3 +``` + + +## Input 2 + +``` +aaa +``` + +## Output 2 + +``` +1 +``` + + +## Input 3 + +``` +abc +``` + +## Output 3 + +``` +0 +``` + + +# Private Test Cases + +## Input 1 + +``` +abccba +``` + +## Output 1 + +``` +3 +``` + +## Input 2 + +``` +xyzzyx +``` + +## Output 2 + +``` +3 +``` diff --git a/Q4_magic_matrix.md b/Q4_magic_matrix.md new file mode 100644 index 0000000..e44403d --- /dev/null +++ b/Q4_magic_matrix.md @@ -0,0 +1,163 @@ +--- +title: Magic Matrix Finder +--- + +# Problem Statement + +A magic matrix is a square matrix where the sum of every row, column, and both diagonals is the same. Your task is to write a program that determines if the given matrix is a magic matrix. + +**Functions to Implement** + +**is_square_matrix(matrix: List[List[int]]) -> bool** + +Input: A list of lists matrix, where each sublist represents a row of the matrix. +Output: Returns True if the matrix is square (i.e., the number of rows equals the number of columns), otherwise False. + +**is_magic_matrix(matrix: List[List[int]]) -> bool** + +Input: A list of lists matrix, where each sublist represents a row of the matrix. +Output: Returns True if the matrix is a magic matrix, otherwise False. A magic matrix is a square matrix where the sum of each row, column, and both diagonals is the same. + +**Sample Input** +``` +matrix = [ [8, 1, 6], [3, 5, 7], [4, 9, 2] ] +``` +**Sample Output** +``` +True +``` + +# Solution +```py test.py -r 'python test.py' + + +# Input parsing +n = int(input("Enter the size of the matrix: ")) +matrix = [] +for _ in range(n): + row = list(map(int, input().split())) + matrix.append(row) + +# Output the result +if is_magic_matrix(matrix): + print("True") +else: + print("False") + + + +``` + +# Public Test Cases + +## Input 1 + +``` +matrix = [ + [8, 1, 6], + [9, 5, 7], + [4, 9, 2] +] + +``` + +## Output 1 + +``` +False +``` + + +## Input 2 + +``` +matrix = [ + [2, 7, 6], + [9, 5, 1], + [4, 3, 8] +] + +``` + +## Output 2 + +``` +True +``` + + +## Input 3 + +``` +matrix = [ + [8, 1, 6], + [3, 5, 7] +] + +``` + +## Output 3 + +``` +False +``` + + +# Private Test Cases + +## Input 1 + +``` +matrix = [ + [4, 9, 2], + [3, 5, 7], + [8, 1, 6] +] + +``` + +## Output 1 + +``` +True +```