KunalP
BAN USERpackage src;
import java.util.HashMap;
public class GoogleContinuousWordProb {
public static void main(String args[]) {
for (String problem : args)
{
HashMap<Character, Integer> charMap = new HashMap<Character, Integer>();
int maxRepeatingCharNumber = 0;
for (Character pch : problem.toCharArray())
{
if(charMap.isEmpty())
{
charMap.put(pch, 1);
maxRepeatingCharNumber++;
}
else if (charMap.containsKey(pch))
{
int pchNewCount = (charMap.get(pch) + 1);
charMap.put(pch, pchNewCount);
if (pchNewCount > maxRepeatingCharNumber)
maxRepeatingCharNumber = pchNewCount;
}
else
charMap.put(pch, 1);
}
if (((2*maxRepeatingCharNumber) - 1) > problem.length())
System.out.println("Poblem Word --> " + problem + " --> Invalid");
else
System.out.println("Poblem Word --> " + problem + " --> Valid");
}
}
}
public char[] compress(char[] A)
{
int k = 0;
for(int i = 0; i < A.length(); )
{
A[k] = A[i];
int j = i + 1;
while ((j < A.length()) && (A[i] == A[j]))
{
j++;
}
if(i < (j-1))
{
A[k+1] = j - i;
k = k + 2;
i = j;
}
else
{
i++;
k++;
if(i == A.length())
{
while(k < A.length())
{
A[k] = null;
k++;
}
}
}
}
return A;
}
- KunalP February 29, 2016