Coding Problem: String GFG Level 1
Motivation
Preparing for the assesment inside the firm.
Level 1
- Reverse words in a given string
- Longest Common Prefix
- Roman Number to Integer
- Integer to Roman
- Closest Strings
- Divisible by 7
- Encrypt the String – II
- Equal point in a string of brackets
- Isomorphic Strings
- Check if two strings are k-anagrams or not
- Panagram Checking
- Minimum Deletions
- Number of Distinct Subsequences
- Check if string is rotated by two places
Solution
- How to reverse a words in string,
S = i.like.this.program.very.much
Output: much.very.program.this.like.i
String reverseWords(String S)
{
String[] splittedString=S.split("\\.");
String reversedString="";
for(int i=splittedString.length-1;i>=0;i--){
if(i==0) {
reversedString+= splittedString[i];
break;
}
reversedString+= splittedString[i]+".";
}
return reversedString;
}