diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/bongo.iml b/.idea/bongo.iml new file mode 100644 index 0000000..2044512 --- /dev/null +++ b/.idea/bongo.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f02ed55 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..480aa5a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/beginner-level/Problem-1/Problem-1.py b/beginner-level/Problem-1/Problem-1.py new file mode 100644 index 0000000..b6f8f19 --- /dev/null +++ b/beginner-level/Problem-1/Problem-1.py @@ -0,0 +1,5 @@ +inpt = "bongodev" + +out_a= [x for x in inpt] +out_a.reverse() +print("".join(out_a)) \ No newline at end of file diff --git a/beginner-level/Problem-1/Problem-1.txt b/beginner-level/Problem-1/Problem-1.txt new file mode 100644 index 0000000..e439d08 --- /dev/null +++ b/beginner-level/Problem-1/Problem-1.txt @@ -0,0 +1,8 @@ +Problem-1: Reverse a String Without Slicing +You are building a simple text utility tool for your web app. One of the requirements is to reverse a string input by a user. + +Input: "bongodev" + +Output: "vedognob" + +Hint: Use a loop to read the string from end to start. \ No newline at end of file diff --git a/beginner-level/Problem-10/Problem-10.py b/beginner-level/Problem-10/Problem-10.py new file mode 100644 index 0000000..3382fc8 --- /dev/null +++ b/beginner-level/Problem-10/Problem-10.py @@ -0,0 +1,18 @@ +def Prime(n): + if n < 0: + return 2 + if n == 5 or n == 7 or n == 3 or n == 2 or n == 1: + return 0 + if n%2==0 or n%3==0 or n%5==0 or n%7==0: + return 1 + else: + return 0 +prime_list = [] +num = int(input("Enter a number: ")) +for i in range(2,(num**2)): + if Prime(i)==0: + print("prime",i) + prime_list.append(i) + else: + print("not prime") +print(prime_list) \ No newline at end of file diff --git a/beginner-level/Problem-10/Problem-10.txt b/beginner-level/Problem-10/Problem-10.txt new file mode 100644 index 0000000..b774cfe --- /dev/null +++ b/beginner-level/Problem-10/Problem-10.txt @@ -0,0 +1,8 @@ +Problem-10: Check if a Number is Prime +Write a function to check if a number is prime, useful in some encryption schemes. + +Input: 29 + +Output: True + +Hint: Check divisibility from 2 to sqrt(n). \ No newline at end of file diff --git a/beginner-level/Problem-2/Problem-2.py b/beginner-level/Problem-2/Problem-2.py new file mode 100644 index 0000000..125489b --- /dev/null +++ b/beginner-level/Problem-2/Problem-2.py @@ -0,0 +1,10 @@ +Input= "Data Science is awesome" +vowels= ['a', 'e', 'i', 'o', 'u'] +count = 0 +for x in Input.lower(): + for y in vowels: + if x == y: + count+=1 + else: + pass +print(count) \ No newline at end of file diff --git a/beginner-level/Problem-2/Problem-2.txt b/beginner-level/Problem-2/Problem-2.txt new file mode 100644 index 0000000..abbaa29 --- /dev/null +++ b/beginner-level/Problem-2/Problem-2.txt @@ -0,0 +1,8 @@ +Problem-2: Count Vowels in a Sentence +As part of a data-cleaning pipeline, count how many vowels are in a string to later analyze readability. + +Input: "Data Science is awesome" + +Output: 9 + +Hint: Convert string to lowercase and check each character. \ No newline at end of file diff --git a/beginner-level/Problem-3/Problem-3.py b/beginner-level/Problem-3/Problem-3.py new file mode 100644 index 0000000..831b613 --- /dev/null +++ b/beginner-level/Problem-3/Problem-3.py @@ -0,0 +1,5 @@ +Input= ["ai", "ml", "python", "ml", "dl", "ai"] +Input_b= set(Input) +for i in Input_b: + if Input.count(i) > 1: + print(i) \ No newline at end of file diff --git a/beginner-level/Problem-3/Problem-3.txt b/beginner-level/Problem-3/Problem-3.txt new file mode 100644 index 0000000..41e796f --- /dev/null +++ b/beginner-level/Problem-3/Problem-3.txt @@ -0,0 +1,8 @@ +Problem-3: Find Duplicates in a List +You’re given a user-uploaded list of tags. Identify duplicates for suggestion cleanup. + +Input: ["ai", "ml", "python", "ml", "dl", "ai"] + +Output: ["ml", "ai"] + +Hint: Use a dictionary or set to track seen elements. \ No newline at end of file diff --git a/beginner-level/Problem-4/Problem-4.py b/beginner-level/Problem-4/Problem-4.py new file mode 100644 index 0000000..e3eb830 --- /dev/null +++ b/beginner-level/Problem-4/Problem-4.py @@ -0,0 +1,8 @@ +Input= "Madam" +Sample_a = list(Input.lower()) +Sample_b = Sample_a +Sample_b.reverse() +if Sample_b == Sample_a: + print(True) +else: + print(False) \ No newline at end of file diff --git a/beginner-level/Problem-4/Problem-4.txt b/beginner-level/Problem-4/Problem-4.txt new file mode 100644 index 0000000..6b9aabe --- /dev/null +++ b/beginner-level/Problem-4/Problem-4.txt @@ -0,0 +1,8 @@ +Problem-4: Check if a Word is a Palindrome +Write a function that checks if a word or phrase is the same when reversed, ignoring spaces and punctuation. + +Input: "Madam" + +Output: True + +Hint: Normalize the string and compare it to its reverse. \ No newline at end of file diff --git a/beginner-level/Problem-5/Problem-5.py b/beginner-level/Problem-5/Problem-5.py new file mode 100644 index 0000000..516b4f4 --- /dev/null +++ b/beginner-level/Problem-5/Problem-5.py @@ -0,0 +1,12 @@ +Input = [1, [2, 3], [4, [5]]] +B = [] +def flatten_list(A): + for item in A: + if isinstance(item, list): + B.extend(flatten_list(item)) + else: + B.append(item) + return B + + +print(flatten_list(Input)) \ No newline at end of file diff --git a/beginner-level/Problem-5/Problem-5.txt b/beginner-level/Problem-5/Problem-5.txt new file mode 100644 index 0000000..819dd7c --- /dev/null +++ b/beginner-level/Problem-5/Problem-5.txt @@ -0,0 +1,8 @@ +Problem-5: Flatten a Nested List +You are given a nested list of elements (e.g., UI config data). Flatten it into a single-level list. + +- **Input**: `[1, [2, 3], [4, [5]]]` + +- **Output**: `[1, 2, 3, 4, 5]` + +- **Hint**: Use recursion to handle sublists. \ No newline at end of file diff --git a/beginner-level/Problem-6/Problem-6.py b/beginner-level/Problem-6/Problem-6.py new file mode 100644 index 0000000..85597d5 --- /dev/null +++ b/beginner-level/Problem-6/Problem-6.py @@ -0,0 +1,6 @@ +Input= "python for web developers" +sample = Input.split(" ") +Output = [] +for x in sample: + Output.append(x.capitalize()) +print(" ".join(Output)) \ No newline at end of file diff --git a/beginner-level/Problem-6/Problem-6.txt b/beginner-level/Problem-6/Problem-6.txt new file mode 100644 index 0000000..c65de08 --- /dev/null +++ b/beginner-level/Problem-6/Problem-6.txt @@ -0,0 +1,8 @@ +Problem-6: Capitalize First Letter of Each Word +Build a custom title formatter that capitalizes the first letter of each word without using .title(). + +Input: "python for web developers" + +Output: "Python For Web Developers" + +Hint: Use .split() and loop through each word. \ No newline at end of file diff --git a/beginner-level/Problem-7/Problem-7.py b/beginner-level/Problem-7/Problem-7.py new file mode 100644 index 0000000..60dc2a7 --- /dev/null +++ b/beginner-level/Problem-7/Problem-7.py @@ -0,0 +1,3 @@ +nums = [1,2,3,4,6,7,8,9] +n=len(nums)+1 +print(((n*(n+1))//2)-sum(nums)) \ No newline at end of file diff --git a/beginner-level/Problem-7/Problem-7.txt b/beginner-level/Problem-7/Problem-7.txt new file mode 100644 index 0000000..0131e61 --- /dev/null +++ b/beginner-level/Problem-7/Problem-7.txt @@ -0,0 +1,8 @@ +Problem-7: Find Missing Number in a Sequence +You received log files indexed from 1 to n. One log is missing. Find it. + +Input: [1, 2, 4, 5] + +Output: 3 + +Hint: Use arithmetic formula for sum of n numbers. \ No newline at end of file diff --git a/beginner-level/Problem-8/Problem-8.py b/beginner-level/Problem-8/Problem-8.py new file mode 100644 index 0000000..1e47d14 --- /dev/null +++ b/beginner-level/Problem-8/Problem-8.py @@ -0,0 +1,7 @@ +def factorial(n): + if n==0: + return 1 + else: + return n*factorial(n-1) +A=5 +print(factorial(A)) \ No newline at end of file diff --git a/beginner-level/Problem-8/Problem-8.txt b/beginner-level/Problem-8/Problem-8.txt new file mode 100644 index 0000000..28a238f --- /dev/null +++ b/beginner-level/Problem-8/Problem-8.txt @@ -0,0 +1,8 @@ +Problem-8: Factorial Using Recursion +Write a function to return the factorial of a number, used in data science combinations calculation. + +Input: 5 + +Output: 120 + +Hint: Base case is 0! = 1, then recurse. \ No newline at end of file diff --git a/beginner-level/Problem-9/Problem-9.py b/beginner-level/Problem-9/Problem-9.py new file mode 100644 index 0000000..0abda0b --- /dev/null +++ b/beginner-level/Problem-9/Problem-9.py @@ -0,0 +1,2 @@ +A = 9875 +print(sum(map(int, list(str(A))))) \ No newline at end of file diff --git a/beginner-level/Problem-9/Problem-9.txt b/beginner-level/Problem-9/Problem-9.txt new file mode 100644 index 0000000..f12d553 --- /dev/null +++ b/beginner-level/Problem-9/Problem-9.txt @@ -0,0 +1,8 @@ +Problem-9: Sum of Digits of an Integer +For a gamification feature, sum the digits of a user’s ID to generate a unique color code. + +Input: 9875 + +Output: 29 + +Hint: Use // and % or string conversion. \ No newline at end of file diff --git a/intermediate-level/Problem-1/Problem-1.py b/intermediate-level/Problem-1/Problem-1.py new file mode 100644 index 0000000..f6aa67d --- /dev/null +++ b/intermediate-level/Problem-1/Problem-1.py @@ -0,0 +1,5 @@ +def longest_word(sentence): + words = sentence.split() + return max(words, key=len) +A= "Machine learning is fascinating" +print(longest_word(A)) \ No newline at end of file diff --git a/intermediate-level/Problem-1/Problem-1.txt b/intermediate-level/Problem-1/Problem-1.txt new file mode 100644 index 0000000..835597e --- /dev/null +++ b/intermediate-level/Problem-1/Problem-1.txt @@ -0,0 +1,5 @@ +Problem-1: Longest Word in a Sentence +Build a function that extracts the longest word from user-generated content. +Input: "Machine learning is fascinating" +Output: "fascinating" +Hint: Split string and use max() with key=len. \ No newline at end of file diff --git a/intermediate-level/Problem-10/Problem-10.py b/intermediate-level/Problem-10/Problem-10.py new file mode 100644 index 0000000..b636f6e --- /dev/null +++ b/intermediate-level/Problem-10/Problem-10.py @@ -0,0 +1,12 @@ +import re +from collections import Cou + +def most_frequent_word(text, stopwords): + words = re.findall(r'\w+', text.lower()) + filtered = [w for w in words if w not in stopwords] + counter = Counter(filtered) + return counter.most_common(1)[0] + +stopwords = {"the", "is", "and", "in", "to", "of"} +text = "Machine learning is the future and machine learning is powerful" +print(most_frequent_word(text, stopwords)) \ No newline at end of file diff --git a/intermediate-level/Problem-10/Problem-10.txt b/intermediate-level/Problem-10/Problem-10.txt new file mode 100644 index 0000000..b3c527d --- /dev/null +++ b/intermediate-level/Problem-10/Problem-10.txt @@ -0,0 +1,3 @@ +Problem-10: Most Frequent Word (Excluding Stopwords) +Analyze blog content and find the most frequent word, excluding common stopwords. +Hint: Clean punctuations, lowercase all, use Counter. \ No newline at end of file diff --git a/intermediate-level/Problem-2/Problem-2.py b/intermediate-level/Problem-2/Problem-2.py new file mode 100644 index 0000000..d0f5c8d --- /dev/null +++ b/intermediate-level/Problem-2/Problem-2.py @@ -0,0 +1,9 @@ +from collections import defaultdict + +def group_anagrams(words): + anagrams = defaultdict(list) + for word in words: + anagrams[''.join(sorted(word))].append(word) + return list(anagrams.values()) +A=["bat", "tab", "cat", "act"] +print(group_anagrams(A)) \ No newline at end of file diff --git a/intermediate-level/Problem-2/Problem-2.txt b/intermediate-level/Problem-2/Problem-2.txt new file mode 100644 index 0000000..c552463 --- /dev/null +++ b/intermediate-level/Problem-2/Problem-2.txt @@ -0,0 +1,4 @@ +Problem-2: Group Anagrams Together +Group similar words together in a UI (e.g., tags: ["bat", "tab", "cat", "act"]). +Output: [["bat", "tab"], ["cat", "act"]] +Hint: Use a dictionary where sorted word is key. \ No newline at end of file diff --git a/intermediate-level/Problem-3/Problem-3.py b/intermediate-level/Problem-3/Problem-3.py new file mode 100644 index 0000000..75b6072 --- /dev/null +++ b/intermediate-level/Problem-3/Problem-3.py @@ -0,0 +1,28 @@ +from collections import OrderedDict + + +class LRUCache: + def __init__(self, capacity: int): + self.cache = OrderedDict() + self.capacity = capacity + + def get(self, key: int) -> int: + if key not in self.cache: + return -1 + self.cache.move_to_end(key) + return self.cache[key] + + def put(self, key: int, value: int): + if key in self.cache: + self.cache.move_to_end(key) + self.cache[key] = value + if len(self.cache) > self.capacity: + self.cache.popitem(last=False) + + +cache = LRUCache(2) +cache.put(1, 1) +cache.put(2, 2) +print(cache.get(1)) +cache.put(3, 3) +print(cache.get(2)) \ No newline at end of file diff --git a/intermediate-level/Problem-3/Problem-3.txt b/intermediate-level/Problem-3/Problem-3.txt new file mode 100644 index 0000000..1eebe43 --- /dev/null +++ b/intermediate-level/Problem-3/Problem-3.txt @@ -0,0 +1,3 @@ +Problem-3: Implement an LRU Cache (Least Recently Used) +Simulate caching in a backend system. You need to implement a cache with get() and put() methods. +Hint: Use OrderedDict or create a custom class with a doubly linked list. \ No newline at end of file diff --git a/intermediate-level/Problem-4/Problem-4.py b/intermediate-level/Problem-4/Problem-4.py new file mode 100644 index 0000000..d2b5db9 --- /dev/null +++ b/intermediate-level/Problem-4/Problem-4.py @@ -0,0 +1,8 @@ +import re + +def validate_email(email): + pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$' + return bool(re.match(pattern, email)) + +print(validate_email("test@domain.com")) +print(validate_email("invalid-email")) \ No newline at end of file diff --git a/intermediate-level/Problem-4/Problem-4.txt b/intermediate-level/Problem-4/Problem-4.txt new file mode 100644 index 0000000..6b8ce84 --- /dev/null +++ b/intermediate-level/Problem-4/Problem-4.txt @@ -0,0 +1,5 @@ +Problem-4: Validate Email Format +Write a function that validates emails during user registration. +Input: "test@domain.com" +Output: True +Hint: Use regular expressions. \ No newline at end of file diff --git a/intermediate-level/Problem-5/Problem-5.py b/intermediate-level/Problem-5/Problem-5.py new file mode 100644 index 0000000..56ba61a --- /dev/null +++ b/intermediate-level/Problem-5/Problem-5.py @@ -0,0 +1,9 @@ +from functools import lru_cache + +@lru_cache(maxsize=None) +def fib(n): + if n <= 1: + return n + return fib(n-1) + fib(n-2) + +print(fib(50)) \ No newline at end of file diff --git a/intermediate-level/Problem-5/Problem-5.txt b/intermediate-level/Problem-5/Problem-5.txt new file mode 100644 index 0000000..025d5dc --- /dev/null +++ b/intermediate-level/Problem-5/Problem-5.txt @@ -0,0 +1,5 @@ +Problem-5: Fibonacci Using Memoization +Optimize a recursive Fibonacci function using caching, useful in DP-based ML solutions. +Input: 50 +Output: 12586269025 +Hint: Use @lru_cache from functools. \ No newline at end of file diff --git a/intermediate-level/Problem-6/Problem-6.py b/intermediate-level/Problem-6/Problem-6.py new file mode 100644 index 0000000..3a2edb0 --- /dev/null +++ b/intermediate-level/Problem-6/Problem-6.py @@ -0,0 +1,11 @@ +def flatten_json(data, parent_key='', sep='.'): + items = {} + for k, v in data.items(): + new_key = parent_key + sep + k if parent_key else k + if isinstance(v, dict): + items.update(flatten_json(v, new_key, sep=sep)) + else: + items[new_key] = v + return items + +print(flatten_json({"a": {"b": 1}})) \ No newline at end of file diff --git a/intermediate-level/Problem-6/Problem-6.txt b/intermediate-level/Problem-6/Problem-6.txt new file mode 100644 index 0000000..a348b22 --- /dev/null +++ b/intermediate-level/Problem-6/Problem-6.txt @@ -0,0 +1,5 @@ +Problem-6: Flatten a Nested JSON +Flatten a nested dictionary for storage in tabular format or NoSQL DB. +Input: {"a": {"b": 1}} +Output: {"a.b": 1} +Hint: Use recursion. \ No newline at end of file diff --git a/intermediate-level/Problem-7/Problem-7.py b/intermediate-level/Problem-7/Problem-7.py new file mode 100644 index 0000000..6a1f7b3 --- /dev/null +++ b/intermediate-level/Problem-7/Problem-7.py @@ -0,0 +1,12 @@ +from collections import Counter + +def top_ips(logfile): + counter = Counter() + with open(logfile, 'r') as f: + for line in f: + ip = line.split()[0] + counter[ip] += 1 + return counter.most_common(3) + + +print(top_ips("access.log")) \ No newline at end of file diff --git a/intermediate-level/Problem-7/Problem-7.txt b/intermediate-level/Problem-7/Problem-7.txt new file mode 100644 index 0000000..357b28b --- /dev/null +++ b/intermediate-level/Problem-7/Problem-7.txt @@ -0,0 +1,3 @@ +Problem-7: Analyze Access Logs and Count IPs +Parse Apache log and find the top 3 IPs with the most requests. +Hint: Read file line-by-line and count IPs using collections.Counter. \ No newline at end of file diff --git a/intermediate-level/Problem-8/Problem-8.py b/intermediate-level/Problem-8/Problem-8.py new file mode 100644 index 0000000..5d5f1e5 --- /dev/null +++ b/intermediate-level/Problem-8/Problem-8.py @@ -0,0 +1,14 @@ +def calculator(): + parts = input("Enter command: ").split() + cmd, x, y = parts[0], int(parts[1]), int(parts[2]) + if cmd == "add": + return x + y + elif cmd == "sub": + return x - y + elif cmd == "mul": + return x * y + elif cmd == "div": + return x / y if y != 0 else "Error: Division by zero" + + +print(calculator()) \ No newline at end of file diff --git a/intermediate-level/Problem-8/Problem-8.txt b/intermediate-level/Problem-8/Problem-8.txt new file mode 100644 index 0000000..456805f --- /dev/null +++ b/intermediate-level/Problem-8/Problem-8.txt @@ -0,0 +1,3 @@ +Problem-8: Command-line Calculator +Build a CLI tool that takes command add 5 7 and returns 12. +Hint: Parse input().split() and use if/elif for commands. \ No newline at end of file diff --git a/intermediate-level/Problem-9/Problem-9.py b/intermediate-level/Problem-9/Problem-9.py new file mode 100644 index 0000000..9db638f --- /dev/null +++ b/intermediate-level/Problem-9/Problem-9.py @@ -0,0 +1,14 @@ +import re + +def validate_password(password): + if (len(password) >= 8 and + re.search(r"[A-Z]", password) and + re.search(r"[a-z]", password) and + re.search(r"[0-9]", password) and + re.search(r"[@$!%*?&]", password)): + return True + return False + + +print(validate_password("StrongPass1!")) +print(validate_password("weak")) \ No newline at end of file diff --git a/intermediate-level/Problem-9/Problem-9.txt b/intermediate-level/Problem-9/Problem-9.txt new file mode 100644 index 0000000..bdec2c2 --- /dev/null +++ b/intermediate-level/Problem-9/Problem-9.txt @@ -0,0 +1,3 @@ +Problem-9: Password Validator (Security Utility) +Build a validator that checks for minimum length, uppercase, lowercase, number, and special character. +Hint: Use regex or manual checks with any(). \ No newline at end of file