Python Coding Interview Questions (100+ Problems)

Coding interviews require strong problem-solving skills and a deep understanding of programming concepts. Python is widely used due to its simplicity and power.

This guide provides 100+ Python coding interview questions categorized from basic to advanced levels.

1. Basic Coding Questions

Q1. Swap two numbers

Python
Swap numbers
a, b = 5, 10
a, b = b, a
print(a, b)

Q2. Check even or odd

Python
Even or odd
n = int(input())
print("Even" if n % 2 == 0 else "Odd")

Q3. Find factorial

Python
Factorial
def fact(n):
    return 1 if n == 0 else n * fact(n-1)

2. String Problems

Q4. Reverse string

Python
Reverse
print(input()[::-1])

Q5. Check palindrome

Python
Palindrome
s = input()
print(s == s[::-1])

Q6. Count vowels

Python
Vowels
print(sum(1 for c in input() if c.lower() in 'aeiou'))

3. List Problems

Q7. Find max element

Python
Max element
print(max([1,2,3]))

Q8. Remove duplicates

Python
Remove duplicates
print(list(set([1,2,2,3])))

Q9. Sort list

Python
Sort
lst = [3,1,2]
lst.sort()

4. Dictionary Problems

Q10. Frequency count

Python
Frequency
lst = [1,2,2,3]
f = {}
for i in lst:
    f[i] = f.get(i,0)+1

5. DSA Problems

Q11. Binary search

Python
Binary search
def bs(arr, x):
    l, r = 0, len(arr)-1
    while l <= r:
        m = (l+r)//2
        if arr[m] == x:
            return m
        elif arr[m] < x:
            l = m+1
        else:
            r = m-1

Q12. Fibonacci DP

Python
DP Fibonacci
def fib(n):
    dp = [0,1]
    for i in range(2,n+1):
        dp.append(dp[i-1]+dp[i-2])
    return dp[n]

6. Advanced Problems

Q13. Two sum problem

Python
Two sum
def two_sum(nums, target):
    d = {}
    for i, n in enumerate(nums):
        if target-n in d:
            return [d[target-n], i]
        d[n] = i

Q14. Longest substring

Python
Longest substring
def longest(s):
    st=set();l=0;res=0
    for r in range(len(s)):
        while s[r] in st:
            st.remove(s[l]);l+=1
        st.add(s[r]);res=max(res,r-l+1)
    return res

7. Practice Problems (More)

1. Prime numbers.

2. Armstrong number.

3. Matrix multiplication.

4. Merge intervals.

5. Rotate array.

8. Interview Tips

1. Practice daily.

2. Focus on DSA.

3. Write clean code.

4. Optimize solutions.

Conclusion

Coding interview preparation requires consistent practice and understanding of problem-solving techniques.

Use this guide to strengthen your skills and crack technical interviews.