Coding Problem: String GFG Level 1

Motivation

Preparing for the assesment inside the firm.

Level 1

  1. Reverse words in a given string
  2. Longest Common Prefix
  3. Roman Number to Integer
  4. Integer to Roman
  5. Closest Strings
  6. Divisible by 7
  7. Encrypt the String – II
  8. Equal point in a string of brackets
  9. Isomorphic Strings
  10. Check if two strings are k-anagrams or not
  11. Panagram Checking
  12. Minimum Deletions
  13. Number of Distinct Subsequences
  14. Check if string is rotated by two places

Solution

  1. 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;
    }