✅ Python Coding Interview Questions with Answers: Part-1 🐍💻 1️⃣ Reverse a String 🔄 Q: Write code to reverse a given string. Python Code: def reverse_string(s): return s[::-1] print(reverse_string("hello")) # Output: "olleh" 2️⃣ Check Palindrome ✨ Q: Check if a string is a palindrome (ignoring spaces & case). Python Code: def is_palindrome(s): s = s.replace(" ", "").lower() return s == s[::-1] print(is_palindrome("Race car")) # Output: True 3️⃣ Find Duplicate Elements in List 👯 Q: Print all duplicates from a list. Python Code: from collections import Counter def find_duplicates(lst): count = Counter(lst) return [item for item, freq in count.items() if freq > 1] print(find_duplicates([1, 2, 3, 2, 4, 1])) # Output: [1, 2] 4️⃣ Count Vowels in a String 🗣️ Q: Count number of vowels in a string. Python Code: def count_vowels(s): return sum(1 for char in s.lower() if char in "aeiou") print(count_vowels("Python is fun")) # Output: 4 5️⃣ Find Factorial Using Recursion 📈 Q: Write a recursive function to find factorial. Python Code: def factorial(n): if n == 0 or n == 1: return 1 return n * factorial(n - 1) print(factorial(5)) # Output: 120 💬 Double Tap ♥️ For Part-2 #Python #CodingInterview
25
1