Python Lists and Strings - Placement Practice Problems
Problem 1: Sum of Even and Odd Numbers
Write a program to read a list of integers and print the sum of all even numbers and the
sum of all odd numbers separately.
Example Input:
• List: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Example Output:
• Sum of even numbers: 30
• Sum of odd numbers: 25
Problem 2: Remove Duplicates Preserving Order
Given a list of integers, remove all duplicate elements while preserving the original order.
Print the resulting list.
Example Input:
• List: [1, 2, 3, 2, 4, 1, 5, 3]
Example Output:
• Result: [1, 2, 3, 4, 5]
Problem 3: Count Vowels and Consonants
Read a string and count how many vowels and consonants it contains. Ignore spaces and
treat uppercase and lowercase letters as the same.
Example Input:
• String: "Hello World"
Example Output:
• Vowels: 3
• Consonants: 7
VVITU - DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
1
Python Lists and Strings - Placement Practice Problems
Problem 4: Palindrome Check
Read a string and check whether it is a palindrome (the same forwards and backwards).
Ignore case and spaces.
Example Input:
• String: "A man a plan a canal Panama"
Example Output:
• Result: Palindrome
Problem 5: Find All Indices of Target
Given a list of integers and a target value, print the indices of all elements equal to the
target. If the target is not present, print "Not Found".
Example Input:
• List: [1, 3, 5, 3, 7, 3, 9]
• Target: 3
Example Output:
• Indices: [1, 3, 5]
Problem 6: Alternate Case String
Read a string and print a new string where all characters at even indices are in uppercase
and all characters at odd indices are in lowercase.
Example Input:
• String: "programming"
Example Output:
• Result: "PrOgRaMmInG"
Problem 7: Rotate List to the Right
Given a list of integers, rotate the list to the right by k positions (k can be less than or
greater than the length). For example, [1, 2, 3, 4, 5] rotated right by 2 becomes [4, 5, 1, 2,
3].
VVITU - DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
2
Python Lists and Strings - Placement Practice Problems
Example Input:
• List: [1, 2, 3, 4, 5]
• k: 2
Example Output:
• Result: [4, 5, 1, 2, 3]
Intermediate Level Problems (8–14)
Problem 8: Longest Word in Sentence
Read a sentence and print the word that has the maximum length. If multiple words have
the same maximum length, print the first such word.
Example Input:
• Sentence: "Python programming is amazing"
Example Output:
• Longest word: "programming"
Problem 9: Elements Appearing Exactly Once
Given a list of integers, print a new list that contains only the elements that appear exactly
once in the original list.
Example Input:
• List: [1, 2, 3, 2, 4, 1, 5]
Example Output:
• Result: [3, 4, 5]
Problem 10: Anagram Check
Read two strings and check whether one is an anagram of the other. Ignore spaces and
case (e.g., "Listen" and "Silent").
Example Input:
• String 1: "Listen"
• String 2: "Silent"
Example Output:
VVITU - DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
3
Python Lists and Strings - Placement Practice Problems
• Result: Anagrams
Problem 11: Separate Negative and Non-Negative Numbers
Given a list of integers, separate the list into two new lists: one containing all negative
numbers and one containing all non-negative numbers. Print both lists.
Example Input:
• List: [-3, 5, -1, 0, 8, -7, 2]
Example Output:
• Negative: [-3, -1, -7]
• Non-negative: [5, 0, 8, 2]
Problem 12: String Compression
Read a string and compress consecutive repeated characters by writing the character
followed by its count.
Example Input:
• String: "aaabbccccd"
Example Output:
• Result: "a3b2c4d1"
Problem 13: Move Zeros to End
Given a list of integers, move all zeros to the end of the list while maintaining the relative
order of non-zero elements.
Example Input:
• List: [0, 1, 0, 3, 12]
Example Output:
• Result: [1, 3, 12, 0, 0]
Problem 14: Sort Names by Length and Alphabetically
Read a list of strings (names) and print the list sorted first by length (shorter names first),
and if lengths are equal, sort alphabetically.
VVITU - DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
4
Python Lists and Strings - Placement Practice Problems
Example Input:
• List: ["John", "Alice", "Bob", "Charlie", "Eve"]
Example Output:
• Result: ["Bob", "Eve", "John", "Alice", "Charlie"]
Problem 15: First Non-Repeating Character
Given a string, find the first non-repeating character and print it. If every character
repeats, print "No unique character".
Example Input:
• String: "programming"
Example Output:
• Result: "p"
Problem 16: Find All Pairs with Given Sum
Read a list of integers and a number k. Print all pairs of elements whose sum is equal to k.
Each pair should be printed only once, and (a, b) is the same as (b, a).
Example Input:
• List: [1, 5, 7, -1, 5]
• k: 6
Example Output:
• Pairs: (1, 5), (7, -1)
Problem 17: Longest Increasing Subarray Length
Given a list of integers, find the length of the longest contiguous increasing subarray
(each next number strictly greater than previous). Print only the length.
Example Input:
• List: [1, 2, 3, 1, 2, 3, 4, 5]
Example Output:
VVITU - DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
5
Python Lists and Strings - Placement Practice Problems
• Length: 5
Problem 18: Reverse Words in Sentence
Read a sentence and reverse the order of words, but keep the characters in each word in
the same order.
Example Input:
• Sentence: "I love Python programming"
Example Output:
• Result: "programming Python love I"
Problem 19: Pangram Check
Read a string and check if it contains every letter of the English alphabet at least once
(pangram check). Ignore case and non-alphabetic characters.
Example Input:
• String: "The quick brown fox jumps over the lazy dog"
Example Output:
• Result: Pangram
Problem 20: Rearrange Even and Odd Numbers
Given a list of integers, rearrange the elements so that all even numbers come first,
followed by all odd numbers, while keeping the relative order inside the even group and
inside the odd group the same as in the original list.
Example Input:
• List: [3, 1, 2, 4, 5, 6, 7, 8]
Example Output:
• Result: [2, 4, 6, 8, 3, 1, 5, 7]
VVITU - DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
6