Citrix System Inc Interview Question
Developer Program EngineersCountry: India
Interview Type: In-Person
Sort both the arrays A1 and A2 separately using any sorting which guarantees nlogn time
Create an output array A3 of size A1.length+A2.length
Have 2 pointers at the end of each array, compare them (may be using ASCII) and copy the elements to the new array A3, decrement the pointer based on the comparison
sample comparison part:
if (A1[end1] > A2[end2])
{
A3[end3] = A1[end1];
end1--;
}
else
{
A3[end3] = A2[end2];
end2--;
}
end3--;
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool comp(char c1, char c2)
{
return tolower(c1) < tolower(c2);
}
int main()
{
std::string str1 = "ab";
std::string str2 = "badg";
std::string str3;
str3 += str1 + str2;
std::sort(str3.begin(), str3.end(), comp);
cout << str3 << endl;
system("pause");
return 0;
}
bucket sort. Count frequency of each characters and then output in order.
- Anonymous November 01, 2013