@@ -0,0 +1,1723 @@
+package com.deepak.Strings;%0A%0A/**%0A * %3Cp%3EProblem Statement%3C/p%3E%0A * %3Cp%3E Given a string of characters consisting of 0 or more spaces, %0A * remove all the spaces from this given string. %0A * Separation of spaces from other characters should be done in-place(without using extra space).%0A * Expected time and space complexity is O(n).%0A * For example, if the input string is %22  Hi, How are you?  %22 %0A * then the output returned should be %22Hi,Howareyou?%22%3C/p%3E%0A * %0A * @author Deepak%0A */%0Apublic class RemoveSpaces %7B%0A%09%0A%09/**%0A%09 * Method to start the flow of the program%0A%09 * @param args%0A%09 */%0A%09public static void main(String%5B%5D args) %7B%0A%09%09String strWithSpaces = %22  Hey, How are you doing?? %22;%0A%09%09String strWithOutSpaces = removeSpaces(strWithSpaces);%0A%09%09System.out.println(%22Actual String =%3E %22 + strWithSpaces);%0A%09%09System.out.println(%22String after removing spaces =%3E %22 + strWithOutSpaces);%0A%09%7D%0A%0A%09/**%0A%09 * Method to remove spaces with O(n%5E2) complexity %5BNot recommended%5D%0A%09 * %3Cp%3E Algorithm :%0A%09 * 1. Convert the entire string to char Array %0A%09 * 2. Loop through it and search for white space%0A%09 * 3. If found, loop through the array on right side%0A%09 * 4. Shift each element to left and decrease the array size by 1%0A%09 * 5. Repeat step 2-4 until all the white spaces are removed%3C/p%3E%0A%09 * %0A%09 * @param strWithSpaces%0A%09 * @return %7B@link String%7D%0A%09 */%0A%09private static String removeSpaces(String strWithSpaces) %7B%0A%09%09char%5B%5D strToCharArray = strWithSpaces.toCharArray();%0A%09%09int charArraySize = strToCharArray.length;%0A%09%09for (int i = 0; i %3C charArraySize; i++) %7B%0A%09%09%09if (strToCharArray%5Bi%5D == ' ') %7B%0A%09%09%09%09for (int j = i; j %3C charArraySize - 1; j++) %7B%0A%09%09%09%09%09strToCharArray%5Bj%5D = strToCharArray%5Bj+1%5D;%0A%09%09%09%09%7D%0A%09%09%09%09charArraySize--;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return new String(strToCharArray);%0A%09%7D%0A%09%0A%7D%0A

Remove Spaces - O(n^2) complexity [Not recommended]