Prashant Nigam
BAN USER
private static void findCount(String[] strings) {
Map<Set<Character>, Integer> patterns = new HashMap<>();
for (String input : strings) {
Set<Character> pattern = new TreeSet<>();
for (char ch : input.toCharArray()) {
pattern.add(ch);
}
if (patterns.containsKey(pattern)) {
patterns.put(pattern, patterns.get(pattern)+1);
} else {
patterns.put(pattern, 1);
}
}
for (Set<Character> exp : patterns.keySet()) {
String s = exp.toString().replace("[", "").replace("]", "").replaceAll(", ", "");
System.out.println(s + " " + patterns.get(exp));
}
}
public static String compress(String input) {
if ((input == null) || input.isEmpty()) {
return "";
}
int count = 1;
String result = "";
char prevChar = input.charAt(0);
for (int i = 1; i < input.length(); i++) {
char thisChar = input.charAt(i);
if (thisChar == prevChar) {
count++;
} else {
result += prevChar + "" + count;
count = 1;
prevChar = thisChar;
}
}
result += prevChar + "" + count;
return result;
}
import java.util.ArrayList;
public class Alternate
{
public static void main(String[] args)
{
int[] a = new int[] {-5, -2, 5, 2, 4, 7, 1, 0, 8, -8} ;
ArrayList<Integer> negative = new ArrayList<Integer>() ;
ArrayList<Integer> positive = new ArrayList<Integer>() ;
for(int x : a)
{
if(x < 0)
negative.add(x) ;
else
positive.add(x) ;
}
int nSize = negative.size() ;
int pSize = positive.size() ;
int[] b = new int[nSize+pSize] ;
int nCount = 0 , pCount = 0 ;
for(int i = 0 ; i < (nSize + pSize) || nCount < nSize || pCount < pSize ; i ++)
{
if(i % 2 == 0 && nCount != nSize)
b[i] = negative.get(nCount ++) ;
else if(i % 2 != 0 && pCount != pSize)
b[i] = positive.get(pCount ++) ;
else if(nCount == nSize && pCount != pSize)
b[i] = positive.get(pCount ++) ;
else if(pCount == pSize && nCount != nSize)
b[i] = negative.get(nCount ++) ;
}
for(int x : b)
System.out.print(x+" ");
}
}
Repjudydschultz1234, Android test engineer at Eterno Infotech Pvt Ltd
Spent a weekend researching weebles in Nigeria. My current pet project is developing strategies for how to break someone's ...
Repbilliejeckley, SEO at Flipkart
Spent 2002-2008 testing the market for spit-takes in Los Angeles, CA. Spent 2001-2004 deploying how to get boyfriend back by ...
Repmarthavmoody, Consultant at Dell
Spent 2002-2010 investing in toy elephants in Pensacola, FL. Earned praised for my work testing the market for squirt guns ...
Repmarthajpatton, Data Scientist at AppPerfect
Managed a small team implementing gravy in Prescott, AZ. Developed several new methods for easy break up spells.Had some ...
Reprohitrana0777, Animator at AMD
I am work in free lancing as a editor in web developer. I also like play sports. I like kabaddi ...
Repthonylermat, OOPS Experienced at 247quickbookshelp
I have been assigned based on the successful candidate's level of training and experience but will include types of ...
Repjaynebackus, Applications Developer at Achieve Internet
I am Jayne And I am working as a Record center clerk in a company. Also I'm doing a ...
Time: O(n), Space: O(n)
- Prashant Nigam May 08, 2019