0% found this document useful (0 votes)
2 views7 pages

String Problems

The document outlines a series of Python programming tasks focused on string manipulation, including operations like reversing strings, counting characters, and finding Hamming distances. Each task provides specific input and expected output examples to guide the implementation. The tasks range from basic string operations to more complex functions involving DNA sequences and palindrome checks.

Uploaded by

saifulswadhin25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

String Problems

The document outlines a series of Python programming tasks focused on string manipulation, including operations like reversing strings, counting characters, and finding Hamming distances. Each task provides specific input and expected output examples to guide the implementation. The tasks range from basic string operations to more complex functions involving DNA sequences and palindrome checks.

Uploaded by

saifulswadhin25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

StringProblems

August 26, 2025

0.0.1 Write a Python program that accepts a string from user. Your program should
create a new string by switching first & last character.
Input: HELLO

Output: OELLH

0.0.2 Write a Python program that accepts a string from user. Your program should
create a new string by shifting one position to left.
Input: HELLO

Output: ELLOH

0.0.3 Write a Python program that accepts a string from user. Your program should
reverse the string.
Input: HELLO

Output: OLLEH

0.0.4 Write a Python program that accepts a string from user. Your program should
print only characters that are on odd positions.
Input: HELLO

Output: EL

0.0.5 Write a Python program that accepts a string from user. Your program should
print only characters that are on even positions.
Input: HELLO

Output: HLO

0.0.6 Write a Python program that accepts a string from user. Your program should
convert only characters that are on even positions to uppercase.
Input: hello

1
Output: HeLlO

0.0.7 Write a Python program that accepts a string from user. Your program should
print only vowels.
Input: HellO

Output: eO

0.0.8 Write a Python program that accepts a string from user. Your program should
print only consonants.
Input: HellO

Output: Hll

0.0.9 Write a Python program that accepts a string from user. Your program should
print only vowels in reverse order.
Input: HellO

Output: Oe

0.0.10 Write a Python program that accepts a string from user. Your program should
print only consonants in reverse order.
Input: HellO

Output: llH

0.0.11 Write a Python program that accepts a string from user. Your program should
print only consonants in reverse order.
Input: HellO

Output: llH

0.0.12 Write a Python program that accepts a string from user. Your program should
print only consonants in reverse order.
Input: HellO

Output: llH

0.0.13 Write a Python program that accepts a string and arrange string characters
such that lowercase letters should come first.
Input: PytHon

2
Output: ytonPH

0.0.14 Write a Python program that accepts a string and count number lowercase
and uppercase letters.
Input: PytHon

Output:
UPPERCASE: 2
LOWERCASE: 4

0.0.15 Write a Python program that accepts a string and print sum of all the digits.
Input: a3B1c8ed5

Output: 17

0.0.16 Write a Python program that accepts a string and count all letters, digits, and
special symbols from a given string.
Input: P@#y39th^&i5on

Output:
Chars = 7
Digits = 3
Symbol = 4

0.0.17 Write a Python program that accepts a string and removal all characters from
a string except integers.
Input: He is 15 years and 10 months old

Output: 1510

0.0.18 Write a Python program that accepts a string and removal all duplicate char-
acters from a string without changing the order.
Input: Banana is a fruit

Output: Ban isfrut

Input: This is python

Output: This pyton

3
0.0.19 Write a Python program that accepts a string and change the characters to
next alphabetical characters.
If the string has ‘A’ then output will have ‘B’, simillarly if it has ‘g’ then output will be ‘h’. But if
the string has ‘Z’ then the output will be ‘A’ and simillarly if it has ‘z’ then the output will be ‘a’.

Input: Banana

Output: Cbmbmb

Input: Zebra

Output: Afcsb

0.0.20 Find Hamming Distance of two DNA strings


We say that position i in k-mers 𝑝1 … 𝑝𝑘 and 𝑞1 … 𝑞𝑘 is a mismatch if 𝑝𝑖 � 𝑞𝑖 . For example, CGAAT
and CGGAC have two mismatches. The number of mismatches between strings p and q is called
the Hamming distance between these strings and is denoted HammingDistance(p, q). Compute the
Hamming distance between two DNA strings. Given: Two DNA strings. Return: An integer value
representing the Hamming distance.

Input: GGGCCGTTGGT GGACCGTTGAC

Output: 3

0.0.21 Find the reverse complement of a DNA string.


In DNA strings, symbols ‘A’ and ‘T’ are complements of each other, as are ‘C’ and ‘G’. Given a
nucleotide p, we denote its complementary nucleotide as p. The reverse complement of a DNA
string Pattern = 𝑝1 …𝑝𝑛 is the string Pattern = 𝑝𝑛 … 𝑝1 formed by taking the complement of each
nucleotide in Pattern, then reversing the resulting string.
For example, the reverse complement of Pattern = “GTCA” is Pattern = “TGAC”.

Input: AAAACCCGGT

Output: ACCGGGTTTT

0.0.22 Given a string s, reverse the order of characters in each word within a sentence
while still preserving whitespace and initial word order.
Input: Let's take LeetCode contest

Output: s'teL ekat edoCteeL tsetnoc

0.0.23 Given a input line string, find the frequency of each letter in sorted order.
Input: This is A Sentence

4
Output:
3
A 1
S 1
T 1
c 1
e 3
h 1
i 2
n 2
s 2
t 1

Input: Orange Bananas Are Fruits

Output:
3
A 1
B 1
F 1
O 1
a 4
e 2
g 1
i 1
n 3
r 3
s 2
t 1
u 1

0.0.24 Given a input line string, find the frequency of all the vowels in sorted order.
Input: This is A Sentence

Output:
A 1
e 3
i 2

0.0.25 Given a input line string, find the largest word, if there is multiple largest
words print them all.
Input: This is a sample english sentence

Output: sentence

5
Input: Orange and banana are fruits

Output: Orange banana fruits

0.0.26 Given two input line of strings, merge each word position wise from both line
and print them in a single line.
Input:
Ora an ban ar fru
nge d ana e its

Output: Orange and banana are fruits

0.0.27 Given a input line string and your task is to swap cases. In other words,
convert all lowercase letters to uppercase letters and vice versa.
Input: Orange anD Banana aRe Fruits

Output: oRANGE ANd bANANA ArE fRUITS

0.0.28 Given a input string and your task is to generate all possible substring.
Input: Banana

Output:
B
Ba
Ban
Bana
Banan
Banana

0.0.29 Given a input line string and your task is to compress the string by replacing
repeated characters with the character and its count.
Input: aabcccccaaa

Output: a2b1c5a3

0.0.30 Given a input string and your task is to check if the string is a palindrome or
not.
Input: A man, a plan, a canal: Panama

Output: True

Input: race a car

6
Output: False

Explanation: A phrase is a palindrome if, after converting all uppercase letters into
lowercase letters and removing all non-alphanumeric characters, it reads the same
forward and backward. Alphanumeric characters include letters and numbers.

You might also like