skumaringuva
BAN USERvoid solution(String in)
{
HashMap<Character> hm = new HashMap<~> ();
for(int i=in.length-1;i>0;i--)
{
Character c = in.charAt(i);
if(!hm.containsKey(c))
{
hm.add(c);
System.out.print(c);
}
}
}
lets say we dont count the value of (ace king queen jack lets treat them as 0)and only treat numbers as numbers. So we have 4x10-1. that is 4x55. 220.
total sum of cards is max 220 when all are face up.
If we remove two cards, maximum 2x10, then its 200. number of numbers divisible by 7, 200/7 = 28 . so probability 28/200
Similarly if we remove cards with no value, its 31/220.
Average of these ((28/200)+(31/220))/2
Final result ((28/200)+(31/220))/2 * (probability of face up 0.5).
If we count the A K Q J as 14,13,12,11 then 200 more wil increase in the count. So total max is 420-(2x2s) , Min is 400.
((416/7)/416 +(400/7)/400)/2 * (0.5)
private void solution(int[] input1, int[] input2)
{
HashMap<Integer,Integer> hm = HashMap<Integer,Integer>();
for(int i=0,int j=0;i<input1.length ||j<input2.length;i++;j++)
{
if(i<input1.length && hm.containsKey(input1[i]))
{
int count = hm.get(input1[i]);
if(count == 0 || count >0)
{
// Do nothing, its either both or only A
}
else
{
// its there in both the lists
hm.put(input1[i],0);
}
}
else
hm.put(input[i],1);
if(j<input2.length && hm.containsKey(input2[j]))
{
int count = hm.get(input2[i]);
if(count == 0 || count <0)
{
// Do nothing, its either both or only B
}
else
{
// its there in both the lists
hm.put(input2[i],0);
}
}
else
hm.put(input[i],-1);
}
Iterator it = hm.entrySet().iterator();
while(it.hasNext())
{
Map.Entry pair = (Map.Entry) it.next();
if(it.getValue()!=0)
System.out.println(it.getValue());
}
}
- skumaringuva May 30, 2016if (symbol.length() > selectedSymbol.length() && name.contains(symbol))
Would save the "contains" call for same or smaller size strings, like when you compare Amazon with {A B C D MA zz,} It only compares for first and later single letters will not be compared at all. and After "MA" all of that size will be omitted.
- skumaringuva May 26, 2016Node resultNode;
private void postOrder(Node root, StringBuffer result)
{
if(root!=null)
{
StringBuffer leftBuf = new StringBuffer();
StringBuffer rightBuf = new StringBuffer();
postOrder(root.left,leftBuf);
postOrder(root.right,rightBuf);
if(leftBuf.equals(rightBuf))
{
// we got it, continue to see if there is bigger result. it will be overwritten by higher level node.
resultNode = root;
}
result.append(leftBuf);
result.append(rightBuf);
result.append(root.val);
}
}
- skumaringuva May 23, 2016
- skumaringuva December 28, 2020