Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 10a305a

Browse files
HackerEarth String Algorithm Problems
1 parent 87d1ead commit 10a305a

File tree

6 files changed

+217
-0
lines changed

6 files changed

+217
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Given a string S, and two numbers N, M - arrange the characters of string in between the indexes N
2+
# and M (both inclusive) in descending order. (Indexing starts from 0).
3+
#
4+
# Input Format:
5+
# First line contains T - number of test cases.
6+
# Next T lines contains a string(S) and two numbers(N, M) separated by spaces.
7+
#
8+
# Output Format:
9+
# Print the modified string for each test case in new line.
10+
#
11+
# Constraints:
12+
#
13+
# 1≤T≤1000
14+
# 1≤|S|≤10000 // |S| denotes the length of string.
15+
# 0≤N≤M<|S|
16+
# S∈[a,z]
17+
#
18+
# SAMPLE INPUT
19+
# 3
20+
# hlleo 1 3
21+
# ooneefspd 0 8
22+
# effort 1 4
23+
#
24+
# SAMPLE OUTPUT
25+
# hlleo
26+
# spoonfeed
27+
# erofft
28+
29+
for i in range(int(input())):
30+
user_input = input()
31+
user_input = user_input.split()
32+
to_char = int(user_input[2])
33+
from_char = int(user_input[1])
34+
string = user_input[0][from_char:to_char + 1]
35+
replace = ''.join(sorted(string)[::-1])
36+
print(user_input[0][:from_char] + replace + user_input[0][to_char + 1:len(user_input[0])])
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Given a string containing only lower case letters ,print first occurrence of all the letters present
2+
# in that order only.
3+
#
4+
# Input :
5+
#
6+
# Test cases, t
7+
# string ,s
8+
# Output :
9+
#
10+
# Desired Output
11+
#
12+
# Constraint :
13+
#
14+
# string length <=200
15+
#
16+
# SAMPLE INPUT
17+
# 2
18+
# aasdvasvavda
19+
# sajhags
20+
#
21+
# SAMPLE OUTPUT
22+
# asdv
23+
# sajhg
24+
#
25+
26+
for _ in range(int(input())):
27+
user_input = input()
28+
string = []
29+
for i in range(len(user_input)):
30+
if user_input[i] not in string:
31+
string.append(user_input[i])
32+
33+
print(''.join(string))
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Monk introduces the concept of palindrome saying,"A palindrome is a sequence of characters which reads the s
2+
# ame backward or forward."
3+
# Now, since he loves things to be binary, he asks you to find whether the given string is palindrome or not.
4+
# If a given string is palindrome, you need to state that it is even palindrome (palindrome with even length)
5+
# or odd palindrome (palindrome with odd length).
6+
#
7+
# Input:
8+
# The first line consists of T, denoting the number of test cases.
9+
# Next follow T lines, each line consisting of a string of lowercase English alphabets.
10+
#
11+
# Output:
12+
# For each string , you need to find whether it is palindrome or not.
13+
# If it is not a palindrome, print NO.
14+
# If it is a palindrome, print YES followed by a space; then print EVEN it is an even palindrome
15+
# else print ODD.
16+
# Output for each string should be in a separate line.
17+
# See the sample output for clarification.
18+
#
19+
# Constraints:
20+
# 1≤T≤50
21+
# 1≤length of string≤105
22+
#
23+
# SAMPLE INPUT
24+
# 3
25+
# abc
26+
# abba
27+
# aba
28+
#
29+
# SAMPLE OUTPUT
30+
# NO
31+
# YES EVEN
32+
# YES ODD
33+
34+
for _ in range(int(input())):
35+
user_input = input()
36+
if user_input == user_input[::-1]:
37+
if len(user_input) % 2 == 0:
38+
print('YES EVEN')
39+
else:
40+
print('YES ODD')
41+
else:
42+
print('NO')
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Everyone is familiar with Pratik's obsession with DNA and how much he likes to find the correct pair for
2+
# the nucleotide bases. One day Samim found him exaggerating about his knowledge of DNA bases. So Samim
3+
# challenged Pratik about finding the correct base pair for the given DNA sequence and show the result.
4+
# Also he secretly introduced some of RNA nucleotide bases to test Pratik. Now initially he accepted the
5+
# challenge but soon found out about how big the sequence actually was, so he came to you ask him for your
6+
# in finding the sequence and keep his pride about the knowledge of DNA molecules.
7+
#
8+
# You are given a string that contains the nucleotide bases of DNA and RNA, you are needed to find the
9+
# correct pair for all the bases and print the corresponding sequence obtained. In case the sequence
10+
# contains a RNA base, print "Error RNA nucleobases found!" (without quotes).
11+
#
12+
# INPUT FORMAT
13+
#
14+
# The first line of input contains T, the no of test cases. The next line of input contains N, the no of
15+
# bases in each of the DNA sequence The line after that contains the DNA sequence.
16+
#
17+
# OUTPUT FORMAT
18+
#
19+
# For each test case output your answer on a new line.
20+
#
21+
# CONSTRAIN
22+
#
23+
# 1≤T≤10^4
24+
# 1≤N≤10^6
25+
#
26+
# SAMPLE INPUT
27+
# 3
28+
# 2
29+
# AG
30+
# 4
31+
# ATGC
32+
# 6
33+
# UGCACT
34+
#
35+
# SAMPLE OUTPUT
36+
# TC
37+
# TACG
38+
# Error RNA nucleobases found!
39+
40+
for _ in range(int(input())):
41+
string_length = int(input())
42+
string = input()
43+
check = {'A':'T', 'T':'A', 'G':'C', 'C':'G'}
44+
result = []
45+
46+
if 'U' in string:
47+
print('Error RNA nucleobases found!')
48+
else:
49+
for i in range(len(string)):
50+
result.append(check[string[i]])
51+
52+
print(''.join(result))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Manish has got the task to frame a speech for his professor at the university at the Annual sports meet.But
2+
# the problem is that the professor has speech dyslexia and he can't speak the words clearly which have vowels
3+
# in them. So Manish has to avoid such words and has to minimise their usage in the speech letter. Your task
4+
# is to help Manish mark the vowels in the words so that he can minimise their use. You are given a string S
5+
# consisting of lower case letters only. You need to count the number of vowels in the string S.
6+
#
7+
# INPUT The first line will contain an integer T denoting the number of test cases. The following T lines
8+
# will contain a string S in lower case letters only.
9+
#
10+
# OUTPUT Print the number the vowels in the string S.
11+
#
12+
# CONSTRAINTS 1<=T<=100
13+
#
14+
# SAMPLE INPUT
15+
# 1
16+
# hashes
17+
#
18+
# SAMPLE OUTPUT
19+
# 2
20+
21+
for _ in range(int(input())):
22+
string = input()
23+
count = 0
24+
for i in range(len(string)):
25+
if string[i] in ['a', 'e', 'i', 'o', 'u']:
26+
count += 1
27+
28+
print(count)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Doraemon gave Nobita a gadget that swaps words inside a string in the following manner :
2+
#
3+
# If there are W words, word 1 is swapped with word W, word 2 is swapped with word W-1 and so on. The
4+
# problem is that Nobita himself cannot verify the answer for large strings. Help him write a program to do so.
5+
#
6+
# INPUT :
7+
# the first line of the input contains the number of test cases. Each test case consists of a single line
8+
# containing the string.
9+
#
10+
# OUTPUT :
11+
# output the string with the words swapped as stated above.
12+
#
13+
# CONSTRAINTS :
14+
# |string length| <= 100000
15+
# string contains english alphabets and spaces
16+
#
17+
# SAMPLE INPUT
18+
# 1
19+
# hello world
20+
#
21+
# SAMPLE OUTPUT
22+
# world hello
23+
24+
for _ in range(int(input())):
25+
string = input().split()
26+
print(' '.join(string[::-1]))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /