0% found this document useful (0 votes)
5 views4 pages

String Basic Questions

The document contains a series of programming questions related to string manipulation in Java, including checking for palindromes, removing characters, counting words, and string compression. It provides input and output formats along with sample inputs and outputs for each task. The constraints for the string lengths are also specified, ensuring that the solutions handle large strings efficiently.
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)
5 views4 pages

String Basic Questions

The document contains a series of programming questions related to string manipulation in Java, including checking for palindromes, removing characters, counting words, and string compression. It provides input and output formats along with sample inputs and outputs for each task. The constraints for the string lengths are also specified, ensuring that the solutions handle large strings efficiently.
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
You are on page 1/ 4

String Basics

Q. How to check if a String is Palindrome? Hint: charAt()

Q. How to remove all occurrences of a given character from input String? Hint: replaceAll()

Q.Write a program to count number of words in a String? Hint: split()

Q. Read two String user input and check if first contains second? Hint: contains()

Q. Swap two Strings without using a third variable? Hint: substring() , concat()

Q. Check if two strings are anagrams of each other?

Q. Reverse a string in Java without using the reverse method?

Q. remove given characters from the string?

Q.

Reverse the given string word wise. That is, the last word in given string should come at 1st
place, last second word at 2nd place and so on. Individual words should remain as it is.

Input format :

String in a single line

Output format :

Word wise reversed string in a single line

Constraints :

0 <= |S| <= 10^7

where |S| represents the length of string, S.

Sample Input 1:

Welcome to Chitkara

Sample Output 1:

Chitkara to Welcome

Sample Input 2:

Always indent your code


Sample Output 2:

code your indent Always

*/

Q.

Write a program to do basic string compression. For a character which is consecutively


repeated more than once, replace consecutive duplicate occurrences with the count of
repetitions.

Exmple:

If a String has 'x' repeated 5 times, replace this "xxxxx" with "x5".

The string is compressed only when the repeated character count is more than 1.

Note :

Consecutive count of every character in the input string is less than equal to 9.

Input Format :

The first and the only line of input contains a string(no spaces in between).

Output Format :

The only line of output print the compressed string.

Note:

Return the compressed string and hence, no need to print.

Constraints :

0 <= |S| <= 10^7

Where |S| represents the length of string, S.


Time Limit: 1sec

Sample Input 1 :

aaabbccdsa

Sample Output 1 :

a3b2c2dsa

Sample Input 2 :

aaabbcddeeeee

Sample Output 2 :

a3b2cd2e5

*/

Q.

Given a string S (that can contain multiple words), you need to find the word which has
minimum length.

Note : If multiple words are of same length, then answer will be first minimum length word
in the string.

Words are seperated by single space only.

Input Format :

String S

Output Format :

Minimum length word

Constraints :

1 <= Length of String S <= 10^5

Sample Input 1 :

this is test string

Sample Output 1 :
is

Sample Input 2 :

abc de ghihjk a uvw h j

Sample Output 2 :

You might also like