CareerCup
BAN USERbool FindIfBalanced(char *exp) {
int count = 0
while (*exp) {
if (*exp == '(') {
count++;
} else if (*exp == ')'){
if (count == 0)
return false;
else
count;
}
exp++;
}
if (count == 0)
return true;
else
return false;
}
void Test_FindIfBalanced() {
char *exp[] = { "(a+b)", "()", "(a+b)+c", "((a+b))+c", "(((" };
for(int i=0;i<5;i++)
std::cout<<exp[i]<<" is "<<(FindIfBalanced(exp[i])?"Balanced":"NoBalanced")<<"\n";
}

CareerCup
November 04, 2014 int FindSum(node* n1, node* n2, node** r, int depth)
{
if (!n1 && !n2)
return 0;
node* result = (node*)malloc(sizeof(node));
n>value = value;
n>next = next;
*r = result;
int v1,v2,carry = 0;
if(!n1)
{
v1 = 0;
v2 = n2>value;
carry = FindSum(NULL,n2>next,&(result>next),depth+1);
}
else if(!n2)
{
v1 = n1>value;
v2 = 0;
carry = FindSum(n1>next,NULL,&(result>next),depth+1);
}
else
{
v1 = n1>value;
v2 = n2>value;
carry = FindSum(n1>next,n2>next,&(result>next),depth+1);
}
if (depth==1)
{
result>value = v1+v2+carry;
return 0;
}
else
{
int sum = v1+v2+carry;
result>value = sum%10;
return sum/10;
}
}
/// Call: FindSum(n1,n2,&result, 1)

CareerCup
May 02, 2013 <pre lang="" line="1" title="CodeMonkey52596" class="runthis">#include <stdio.h>
#include <string.h>
void replace(char* str, char* r) {
int spaces = 0;
int len = strlen(str);
int i=0;
for(i=0;i<len;i++) {
if(str[i] == ' ') spaces++;
}
if(spaces) {
int p = spaces*(strlen(r)1);
for(i=len;i>=0;i)
if(str[i] != ' ') {
str[i+p] = str[i];
} else {
int j = strlen(r)1;
while(j>=0) {
str[i+p] = r[j];
j;
p;
}
p++;
}
}
}
void main() {
char str[100] = "1 2 3 4 5 6 7 8 9 0 10 11 12 ";
// char str[100] = "I am CareerCup ";
printf("%s\n",str);
replace(str,"abc");
printf("%s\n",str);
}
</pre><pre title="CodeMonkey52596" input="yes">
</pre>
<pre lang="" line="1" title="CodeMonkey41229" class="runthis">void PreOrder(node* root) {
Stack s;
while(true) {
while(root) {
print(root>data);
push(&s,root);
root = root>left;
}
if(isempty(&s)) break;
else {
root = pop(&s);
root = root>right;
}
}
}
</pre><pre title="CodeMonkey41229" input="yes">
</pre>
NOTE: ((~0)<<i)^((~0)<<j) > will give a mask of type 0001111000 where first 1 from left starts at position j and last 1 is at position i.
{{
unsigned int set(unsigned int n, int i, int j, unsigned int m, int k, int l) {
unsigned mask = ((~0)<<l)^((~0)<<(k));
mask = mask & m; // get the bits between k and l from m
mask = mask >> l; // Removes the trailing 0's
mask = mask << j; // Pushes the bits of interest to left by j
unsigned mask1 = ((~0)<<i)^((~0)<<(j));
mask1 = ~mask1; / Invert the mask
mask1 = mask1 & n; // get all the bits except bits between i and j from n
return (mask1mask);
}
}}
Storage: Static Variables are always stored in static area of the program.
Scope: If there are define outside functions (global), then they are visible to all the functions in the file, but not in the other files.
Globals are also stored in the static area, but are visible to all the files that are linked. So functions in other files can link to global variables using extern, but they can link to static variable.
Reference Wiki: An anagram is .... the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once.
So ABCA and CBAA are not anagrams since letter B and last letter A are not rearranged. As mentioned in the question AABBC and CBBAA are not anagrams as third B is not changed.
And regarding AABBCC and BCA, if (strlen(s1) != strlen(s2)) return false; should takecare.
int CodedValue(Card c) {
return ((c.value)*10+c.suit)*10+ToInt(c.color);
}
Card[] GetUniqueElements(Card[] cards, int n) {
Cards* uniqueCards = new Cards[n];
int pos=0;
sort(cards); // sort based on the CodedValue of the card
for(int i=1;i<v;i++) {
if(CodedValue(cards[i1] != CodedValue(cards[i]) {
uniqueCards[pos++] = cards[i1];
}
}
uniqueCards[pos] = cards[n1];
return uniqueCards;
}
Example (1,1,R), (1,2,G), (1,1,R), (2,2,R), (2,2,B)
Coded Value:
(1,1,R)=> 111
(1,2,G)=> 122
(1,1,R)=> 111
(2,2,R)=> 221
(2,2,B)=> 223
Sorted Based on Coded values: (Clusters similar values)
(1,1,R)=> 111
(1,1,R)=> 111
(1,2,G)=> 122
(2,2,R)=> 221
(2,2,B)=> 223
Selection Give =>
(1,1,R)=> 111
(1,2,G)=> 122
(2,2,R)=> 221
(2,2,B)=> 223
RepShayneLJohnson, Scientific Officer at Cerberus Capital
I'm Shayne and I have a history of sensitivities that range from dietary issues to skin care and other ...
Repjohnagragg0, cox customer service at Deloitte Consulting LLP
I am friendly, I am a hard worker, even through difficult circumstances, I want to know about How to identify ...
Open Chat in New Window
Invariant: all characters before i have no duplicates and all characters after j are not yet checked and all characters between i and j are duplicates.
Hash is to identify if a char happens more than once (maintain count) and when it is copied set a marked 1 to identify it is already copied and any more insttances of it are duplicates.
 CareerCup December 02, 2014