0% found this document useful (0 votes)
10 views3 pages

String Manipulation Interview Questions

The document outlines various programming tasks related to string manipulation, including reversing strings, counting character occurrences, and identifying duplicates. It provides code examples in Java for each task, demonstrating how to implement the logic without using certain methods or variables. Additionally, it includes assignments for further practice on string operations.

Uploaded by

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

String Manipulation Interview Questions

The document outlines various programming tasks related to string manipulation, including reversing strings, counting character occurrences, and identifying duplicates. It provides code examples in Java for each task, demonstrating how to implement the logic without using certain methods or variables. Additionally, it includes assignments for further practice on string operations.

Uploaded by

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

V.V.V.

Imp programs for interview


---------------------------------------
[Link] the given string without using third/temparary variable?
[Link] the given string using third variable?
[Link] the string without using length method or length variable?
-----------------------------
with respect to characters
-----------------------------
[Link] the [Link] occurance for each character in the given string?
======
Steps:
==============
[Link] set coll(HashSet) and add all the char og given string into set
[Link] each char of set with all char of given string
[Link] it is matching ,increament the count
[Link] both char and count
===============

[Link] the only duplicate characters in the given string?


[Link] only uniq characters in the given string?
//
[Link] the duplicate characters in the given string?
------------------
with respect string
-------------------
[Link] the [Link] occurance for each word in the given string?
[Link] the only duplicate words in the given string?
[Link] only uniq words in the given string?
[Link] the duplicate wordss in the given string?

[Link] logic
--------
String s="India";
{
for(int i=[Link]()-1;i>=0;i--)
{
[Link]([Link](i));
}
----------
package [Link];

public class ReverseOfString


{
public static void main(String [] args)
{
String s="India";
{
for(int i=[Link]()-1;i>=0;i--)
{
[Link]([Link](i));
}
}
}
}
--------------------
[Link]
----------------
package [Link];
public class StringThirdVariable
{
public static void main(String[] args)
{
String s="INDIA";
String rev="";
{
for(int i=[Link]()-1;i>=0;i--)//5-1=4>=0true Input:I N D I A
//1.0 1 2 3 4-->Index numberSS
{
rev=rev+[Link](i);//""+A=A 2.A+I=AI-->AI+D=AID--->AID+N=AIDN---
>AIDN+I=AIDNI
}
[Link](rev);//Output: AIDNI
}
}
}
--------------------------------------
[Link]
-------------------------
package [Link];

public class StringWithoutLengthMethodVar


{
public static void main(String[] args)
{
String s="INDIA";
{
Char ch[]=[Link]();
int count=0;
for(char a:ch)
{
count++;
}
[Link]("count="+count);
for(int i=count-1;i>=0;i--)
{
[Link](ch[i]);
}
}
}
}
------------------------------------------------------
Assignment
-------------------------------------------------------
[Link] s="Welcome to tyss company"?
output:company to tyss Welcome

[Link] s="abc12@45xyz%";
output: abcxyz
1245
@%

[Link] s="welcome to tyss";


output:"tyss to welcome"-->rev=rev+str[i]+" ";

[Link] s="india";
output:i
in
ind
indi
india

[Link] s="ab12@c4%5";
output:1 +2 +4 +5=12

Common questions

Powered by AI

To find occurrences of each word, split the string into words using spaces as delimiters. Utilize a HashMap to store each word as a key and its frequency as the value. For each word in the array, update its count in the map. This map provides word frequencies upon completion .

To remove duplicate characters, convert the string into a LinkedHashSet, which automatically handles duplicates. Then, iterate over the set to build a new string. This guarantees preserved order without duplicates, effectively filtering the original string .

To reverse a string using a third variable, initialize an empty string as the third variable. Iterate over the original string from the end to the start, appending each character to the third variable. The result is a reversed string stored in the third variable, as demonstrated in the provided code .

To print only unique words from a string, split the string into words. Use a HashMap to track word occurrences. Iterate over the words to fill the map. Afterwards, print words whose occurrence count equals one, signifying uniqueness .

To remove duplicate words while preserving order, split the string by spaces to separate words. Use a LinkedHashSet to automatically filter out duplicates while maintaining order of insertion. Finally, concatenate the words in the set back into a string .

To reverse the words, split the sentence into words using spaces. Reverse the order of these words. Concatenate the reversed words into a new string, separated by spaces. This preserves the original word order while reversing their positions, as shown in assignment examples .

To print only the duplicate characters, use a HashMap to maintain counts of each character. Iterate over the string, updating the count in the map. After processing, iterate through the map and print characters with counts greater than one, meaning they appear more than once in the string .

First, convert the string to a character array and manually count the characters using a loop to determine length. Use this length to iterate backwards over the character array, printing each character, which effectively reverses the string .

To find the occurrences of each character, first, create a HashSet to store each unique character from the string. Then, iterate over the HashSet and compare each character with those in the string. If a match occurs, increment a count. This will give you the frequency of each character .

To reverse a string without using a third or temporary variable, you would use a two-pointer approach. You swap characters starting from the beginning and end of the string moving towards the center. For a string "India", iterate over the string with pointers moving towards the center, swapping elements at the pointers, until all characters are reversed.

You might also like