TheShocker1999
BAN USER 1of 1 vote
AnswersHave you ever faced a time when you felt a particlar code base or product was not ready to be released, if so what did you do and how did you work with the development team or stakeholder to make sure your views were heard
 TheShocker1999 in United States Report Duplicate  Flag  PURGE
Google Developer Advocate
I dont agree with that, please explain. If this was the optimal way, why isnt this used widely? Json is more widely used than this format, how is this more efficient space wise than using a exotic character as a separator and delimiting the character?
You are adding 2 bytes to every single string. Please explain this method
Ok, the checkstring was meant to see if the exotic character that I used to delimit was there in the string before we serialized it. But I see what you are saying, if all characters are possible, how can i use one to delimit, something I would have figured out, if i had a unicode chart, and more time than 9 minutes to think.
All characters are possible in Json also though, but json manages to be serialized. So I was using a similar method.
No, maybe i wrote down my explanation wrong. the deilimiter would be a character that was pre determined, a rare exotic character, and hard coded in (ex. !).
1. Loop through array of strings one by one.
2. Checkstring() would take that string, merge sort it, then check each index of the string until it find either the escape, or an unicode character value GREATER than the escape, and delimit it.
3. The the entire string would be returned, and escaped (ex Like: string1!string2)
That's basically exactly what i said, but the interviewer I think was looking for a better solution
 TheShocker1999 December 08, 2015I only had 9 minutes, when he asked me this question. I got as far as whats below, then when I had only 2 minutes left, he asked me to explain the rest of my thinking, which I did(see comments as to what I said).
string serialize(string input[], int size)
{
string Output;
for (int i = 0; i < size, i++)
{
Check(string[i]); //Check string for escape character, use a character high on the unicode chart, sort each string indexes by unicode value using merge sort then check first character of each string, if it is greater than the character you chose, then you know the string does not contain your escape character
//Add escape character to each string to separate values for deserialization
Output +=string[i];
}
return Output;
}
string deserialize(string input[], int size)
{
//didnt get to explain this function
}
I didnt have enough time to optimize or even think of a solution that would be better than O(n2). I know there are better solutions, but nothing came to mind during the interview.
 TheShocker1999 December 08, 2015Both the href and the on click are calling JavaScript funtions. The href cancels out the do something function.
 TheShocker1999 December 02, 2015Easy 0 (n) solution:
Convert each binary to string, merge sort string.
This is assuming that all characters are lowercase and ascii.
Create an int array of 26. Create a count int var. Loop through original string array, checking only the first and last letters. Add +1 to the int idex that corresponds with the ascii character code for both first and last letters. Before adding + 1 to character index if current int var is +1 to count, if current value is 1, 1. After looping through original string if count is greater than 0....the strings cannot make a circle. It 0, then they can.
Fastest solution. Nice.
 TheShocker1999 December 01, 2015This is assuming that all the dates are in order like the example and all dates are there (no gaps).
Read the first and last lines of each file. There are you have a range of all dates. Take the total number of days in divide the total file size by the total number of days this will give you the position to set the pointer at for a particular date.
Also assuming that we have the same number of cities for each date, take that particular date block with each city's name and store it in a we array.
To get a temperature for particular city do a binary search found the city name and get the temperature.
To get the the average of the top five cities do up merge sort sort by temperature lowest to highest get the top five indexes and take the average of that.
O (log n) solution
Best O(n) Solution, Express result as binary, convert if needed:
int main() {
string total = "XXX";
srand(time(0));
for (int x = 0; x < 3; x++)
{
if (((rand() % 5 + 1) + (rand() % 5 + 1)) > 5 )
total[x] = '0';
else
total[x] = '1';
}
}

TheShocker1999
December 01, 2015 Solution that runs o(n):
int* arrSum(int i0[], int &s0, int i1[], int s1) //accepts array1, size of array1, array2 and size of array2
{
int count = 0;
for (int i = 0; (i < s0) && (i < s1); i++) //iterates through array adding sum until either size is met.
{
int sum = i0[i] + i1[i];
if (sum > 9)
{
count++;
}
i0[i] = sum;
}
int tmpSize = (!(s0>s1) ? s0 : s1) + count; //gets smaller index, adds count of sums > 9 (2 Digit)
int *tmp = new int[tmpSize]; //creates tmp dynamic array
int j = 0; //used to iterate through temp array
for (int i = 0; i < tmpSize; i++) // iterates through original array of sums
{
if (i0[i] > 9)
{
tmp[j] = i0[i]/10; //places tens place into array index
tmp[j + 1] = i0[i]%10; //places ones place into array index
j++; // adds 1 to array to account for 2 indexes being split
}
else
tmp[j] = i0[i];
j++;
}
s0 = tmpSize;
return i0; // returns final array
}

TheShocker1999
November 30, 2015 better solution for range of primes O(N2) complexity:
int main() {
int max = 100;
int min = 0;
int sq = 0;
for (sq = 1; sq*sq<max; sq++){}
if (min <= 2)
for (int i = 1; i <= 2; i++){ cout << i << endl;}
min += ((min % 2 == 0)  (min == 0));
for (int i = min; i < max; i+=2)
{
bool prmFlag = true;
for (int j = sq; j > min  1; j)
{
if (j % 2 != 0)
if ((i % j == 0) && (j > 2) && (j != i))
prmFlag = false;
}
if ((prmFlag == true) && (i > 2))
cout << i << endl;
}
}

TheShocker1999
November 30, 2015 Here is a simple solution:
int main() {
int max = 100;
int min = 0;
int sq = 0;
for (sq = 1; sq*sq<max; sq++){}
if (min <= 2)
for (int i = 1; i <= 2; i++){ cout << i << endl;}
min += ((min % 2 == 0)  (min == 0));
for (int i = min; i < max; i+=2)
{
bool prmFlag = true;
for (int j = sq; j > min  1; j)
{
if (j % 2 != 0)
if ((i % j == 0) && (j > 2) && (j != i))
prmFlag = false;
}
if ((prmFlag == true) && (i > 2))
cout << i << endl;
}
}

TheShocker1999
November 30, 2015 I forgot to short circuit when found match:
int main() {
string s = "00as0de00000as00bp1000de000bp000as000de120bp";
string t[3] = { "bp1", "de", "as" }; // assumed input was or could be easily converted to an int array
bool blnMatch = true;
int len = sizeof(t) / sizeof(*t);
for (int i = 0; i < len; i++) //iterate through array of substrings
{
for (int j = 0; j < s.length(); j++) //check for start in long string
{
if (t[i][0] == s[j])
{
blnMatch = true; // initialize boolean
for (int x = 0; x < t[i].length(); x++) //Loop through substring, matching letters in both strings.
{
char v = t[i][x];
if ((s[(j + x)] != t[i][x]))
blnMatch = false; //sets flag to false when no match.
}
}
if ((j >= (s.length()  t[i].length())  1) && (blnMatch == false)) // if end of string and no match, prints.
{
cout << t[i] << ": substring not found" << endl;
break;
}
else if (blnMatch == true)
{
break;
}
}
}
}

TheShocker1999
November 29, 2015 Simple Solution:
int main() {
/*Given a sorted array and n, find the count of sum of 2 numbers greater than or equal to n*/
int chr[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int n = 10;
int arrSize = sizeof(chr) / sizeof(*chr);
int count = 0;
for (int i = 0; i < arrSize; i++)
{
for (int j = 0; j < arrSize; j++)
{
if (((chr[i] + chr[j]) >= n) && (i != j))
count++;
}
}
cout << count;
}

TheShocker1999
November 29, 2015 int main() {
ifstream fin("data.txt");
string s, e;
int n = 1;
char x = ' ';
getline(fin, s); // Get First Line
while (x != '\n') // Set Pointer to end of file, loop until beginning of last line
{
fin.seekg(n, std::ios::end);
fin.get(x);
n;
}
getline(fin, e); // Get Last Line
}

TheShocker1999
November 29, 2015 int main() {
string s = "moss wasgreatman a great mawasgreatmann";
string t[3] = { "was", "great", "manxxx" }; // assumed input was or could be easily converted to an int array
bool blnMatch = true;
int len = sizeof(t) / sizeof(*t);
for (int i = 0; i < len; i++) //iterate through array of substrings
{
for (int j = 0; j < s.length(); j++) //check for start in long string
{
if (t[i][0] == s[j])
{
blnMatch = true; // initialize boolean
for (int x = 1; x < t[i].length(); x++) //Loop through substring, matching letters in both strings.
{
if ((s[j + x] != t[i][x]))
blnMatch = false; //sets flag to false when no match.
}
}
if ((j >= (s.length()  t[i].length())  1) && (blnMatch == false)) // if end of string and no match, prints.
{
cout << t[i] << ": substring not found" << endl;
break;
}
}
}
}

TheShocker1999
November 28, 2015 int main() {
string s = "moss wasgreatman a great mawasgreatmann";
string t[3] = { "was", "great", "manxxx" };
bool blnMatch = true;
int len = sizeof(t) / sizeof(*t);
for (int i = 0; i < len; i++) //iterate through array of substrings
{
for (int j = 0; j < s.length(); j++) //check for start in long string
{
if (t[i][0] == s[j])
{
blnMatch = true; // initialize boolean
for (int x = 1; x < t[i].length(); x++) //Loop through substring, matching letters in both strings.
{
if ((s[j + x] != t[i][x]))
blnMatch = false; //sets flag to false when no match.
}
}
if ((j >= (s.length()  t[i].length())  1) && (blnMatch == false)) // if end of string and no match, prints.
{
cout << t[i] << ": substring not found" << endl;
break;
}
}
}
}

TheShocker1999
November 28, 2015
Exactly what I said. I said that in any community you will have a diversity of candidates that adopt that particular technology. and you have to scale documentation and support to aide in that transition.
 TheShocker1999 December 16, 2015