Python Interview Programs
30 Python programs asked in SDET and automation interviews, ordered from easy to hard. Each one has a worked example, hints and starter code; sign in to see the reference solution.
Easy (12)
- Check whether a number is prime
Determine whether n is prime.
Easy· Math ·10 min
- Check whether a string is a palindrome
Determine whether a string reads identically from both ends.
Easy· Strings ·10 min
- Check whether two strings are anagrams
Determine whether two strings contain the same character multiset.
Easy· Hashing ·10 min
- Compute the factorial of a number
Compute n factorial exactly.
Easy· Numbers ·10 min
- Count vowels and consonants
Count the English vowels and consonants in a line.
Easy· Strings ·10 min
- Find the first occurrence with binary search
Return the first index of a target in a sorted array, or -1 if absent.
Easy· Sorting & Searching ·10 min
- Find the missing number from zero through n
Find the one missing integer from the inclusive range 0 through n.
Easy· Arrays ·10 min
- Find the second largest distinct value
Find the second largest distinct integer in an array.
Easy· Arrays ·10 min
- Generate the Fibonacci series
Print the first n Fibonacci numbers starting with 0 and 1.
Easy· Numbers ·10 min
- Remove duplicate values while preserving order
Return each array value once, in order of its first occurrence.
Easy· Collections ·10 min
- Reverse a string
Reverse the characters of the supplied string.
Easy· Strings ·10 min
- Sum the digits of an integer
Return the sum of the decimal digits of an integer.
Easy· Numbers ·10 min
Medium (13)
- Compress consecutive character runs
Encode each consecutive run as its character followed by its length.
Medium· Strings ·20 min
- Count subarrays with a target sum
Count nonempty contiguous subarrays whose sum equals a target.
Medium· Hashing ·20 min
- Find a pair of indices with a target sum
Return indices of two distinct array elements whose sum equals the target.
Medium· Hashing ·20 min
- Find the first non-repeated character
Return the first character that occurs exactly once, or NONE.
Medium· Hashing ·20 min
- Find the longest common prefix
Find the longest prefix shared by every supplied string.
Medium· Strings ·20 min
- Find the maximum contiguous subarray sum
Return the largest sum of a nonempty contiguous subarray.
Medium· Dynamic Programming ·20 min
- Group anagrams in first-seen order
Group lowercase words that are anagrams of each other.
Medium· Collections ·20 min
- List all primes up to n
Print all primes less than or equal to n in increasing order.
Medium· Math ·20 min
- Merge two sorted arrays
Merge two nondecreasing arrays into one sorted array.
Medium· Two Pointers ·20 min
- Move all zeros to the end
Move all zeros to the end of an array without changing nonzero order.
Medium· Two Pointers ·20 min
- Rotate an array to the right
Rotate an array right by k positions in place.
Medium· Arrays ·20 min
- Traverse a matrix in spiral order
Return matrix values in clockwise spiral order from the top-left cell.
Medium· Matrices ·20 min
- Validate balanced brackets
Determine whether a bracket string is correctly nested and balanced.
Medium· Stack & Queue ·20 min
Hard (5)
- Compute the minimum edit distance
Return the fewest single-character edits needed to transform one string into another.
Hard· Dynamic Programming ·35 min
- Find the longest strictly increasing subsequence length
Return the length of a longest strictly increasing subsequence.
Hard· Dynamic Programming ·35 min
- Find the longest substring without repeated characters
Return the maximum length of a substring containing no repeated characters.
Hard· Sliding Window ·35 min
- Find the maximum in every fixed-size window
Return the maximum value for every contiguous window of size k.
Hard· Stack & Queue ·35 min
- Find the minimum covering substring
Return the shortest substring of s containing every character of t with its required multiplicity.
Hard· Sliding Window ·35 min
