Sach
BAN USER- 0of 0 votes
AnswersWrite a function which will sort a linked list efficiently. I explain merge sort, However interviewer was not agree with my answer.
- Sach in India
Interviewer was expecting answer bubble sort along with backtracking. Not convinced or agreed with his opinion though.| Report Duplicate | Flag | PURGE
GSLab Technical Architect C Data Structures - 0of 0 votes
AnswersSuppose you want to design a application which will be receiving thousands of requests from many clients. And Application need to update received infomration to different servers in real time. What mechanism will you use?
- Sach in India
For ex. Your application receives thousands of requests shares values along with exchange name from different client and application need pass it to different exchange servers ex. Mumbai Exchange, NSE and few more.
Application need to pass information to specific servers in real time.
Here is sample data your application will receive in fraction of seconds from mutiple clients.
110 share1 BOMEXCHG
222 share2 BOMEXCHG
5677 share3 NSE
5690 share3 BOMEXCHG
:
:
:| Report Duplicate | Flag | PURGE
GSLab Technical Architect Software Design - 0of 0 votes
Answerwrite a function to copy string. You are free to decide function parameters. But once you wrote the function, you need to specifically explain below points
- Sach in India
- Function parameters
- What are assumptions (For ex. Destination string should have sufficient memory allocated in advance. means function is not going to allocate memory for destination string)
- Limitation of your function
- Find bugs in your code.| Report Duplicate | Flag | PURGE
Hewlett Packard Tech Lead C - 0of 0 votes
AnswersThere is Ticketing vending machine which accepts Rs.1, Rs.2 and Rs. 5 coins. There is Rs. 5 Ticket. System will reject all invalid coins for ex. Rs 0.50, Rs. 0.25, Rs 10.
- Sach in India
System will not return any money or ticket if coin is invalid.| Report Duplicate | Flag | PURGE
Hewlett Packard Tech Lead Software Design - 0of 0 votes
AnswersDesign a your own Youtube. Which has feature like play, pause, resume, stop. Note that,
- Sach in India
- multiple users can be access multiple videos.
- Mutiple users can access same video at same time or different time.
- Need to tackle performance bottoleneck.| Report Duplicate | Flag | PURGE
Hewlett Packard Tech Lead Software Design - 0of 0 votes
AnswersThis interview was held 3 years back. adding this question for others reference.
- Sach in India
Design a picasa.i.e. A photo album application where user can store his pictures and share among the others using their email ids.
You need provide high level design for server and client.
I explained about
- storage on RDBMS database ( Interviewer was expecting some datwarehousing or NOSql over here but I could not explain as was not aware of it till that time)
- Different sizes of photo storage.
- Cache for recently accessed photos
- Cache for most accessed photos
- Regional servers
- Disaster management, clustering, HA| Report Duplicate | Flag | PURGE
Amazon SDE-2 Software Design - 0of 0 votes
AnswersWhat is Big-O and Big Theta notations?
- Sach in India| Report Duplicate | Flag | PURGE
Credit Suisse Tech Lead Algorithm - 0of 0 votes
AnswersUnix command which will display content of file which has more than 45 characters?
- Sach in India| Report Duplicate | Flag | PURGE
Credit Suisse Unix - 0of 0 votes
Answerswhat is function pointers? what is use of it ?
- Sach in India| Report Duplicate | Flag | PURGE
C - 0of 0 votes
Answerwhat is pointers and why pointers are used ?
- Sach in India| Report Duplicate | Flag | PURGE
C - 0of 0 votes
AnswersIn your application, why is JAVA preferred over C++?
- Sach in India| Report Duplicate | Flag | PURGE
Igate Technical Architect Knowledge Based Application / UI Design - 0of 0 votes
Answershow map is implemented? how insert and delete works?
- Sach in India| Report Duplicate | Flag | PURGE
Igate Technical Architect C++ Data Structures - 0of 0 votes
AnswersCan we use "char *" in map as a key?(note that he is not asking stl::string )
- Sach in India| Report Duplicate | Flag | PURGE
Igate Technical Architect C++
No. As thread is running in process address space, it will terminate you process.
Here is the linux code where thread 2 wont reach at the second printf.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
static void *thread_fun1 (void *arg)
{
char *msg = (char *) arg;
char *p = NULL;
printf (" Thread Func : Message = \"%s\"\n",msg);
*p='a';
}
static void *thread_fun (void *arg)
{
char *msg = (char *) arg;
int i=0;
printf (" Thread Func : Message = \"%s\"\n",msg);
while ( i++ < 10000) sleep (1000);
printf (" Thread Func : Message = \"%s\"\n",msg);
}
int main ()
{
pthread_t thread1, thread2;
const char *msg1=" Thread 1";
const char *msg2=" Thread 2";
int iret1, iret2;
/* concrete independent threads each of which will execute function */
iret1 = pthread_create (&thread1, NULL, thread_fun, (void *) msg1);
if (iret1) {
fprintf (stderr, "Error : pthread_create () return code %d\n", iret1);
exit (EXIT_FAILURE);
}
/* concrete independent threads each of which will execute function */
iret1 = pthread_create (&thread2, NULL, thread_fun1, (void *) msg2);
if (iret1) {
fprintf (stderr, "Error : pthread_create () return code %d\n", iret1);
exit (EXIT_FAILURE);
}
pthread_join (thread1, NULL);
pthread_join (thread2, NULL);
printf (" At the End\n");
}
non-recursive way
bool isMirrorTree (treeNode * root)
{
std::queue<treeNode *> treeQ;
bool isMirror = true;
if (root->l == NULL && root->r ==NULL)
return true;
if ((root->l == NULL && root->r !=NULL) ||
(root->l != NULL && root->r == NULL))
return false;
treeQ.push (root->l);
treeQ.push (root->r);
while (! treeQ.empty()) {
treeNode *first = treeQ.front ();
treeQ.pop ();
treeNode *second= treeQ.front ();
treeQ.pop ();
if ( first && second && first->x == second->x)
{
treeQ.push (first->l);
treeQ.push (second->r);
treeQ.push (first->r);
treeQ.push (second->l);
}
else
{
if (! (first == NULL && second == NULL))
isMirror =false;
break;
}
}
return isMirror;
}
Here is C++ code using two stacks
void zigZagTraversal (treeNode *node)
{
using namespace std;
std::stack <treeNode *> LRQueue;
std::stack <treeNode *> RLQueue;
treeNode *currentNode;
bool leftToRight =true;
LRQueue.push (node);
while (!LRQueue.empty () || !RLQueue.empty ()) {
if (leftToRight) {
currentNode = LRQueue.top();
printf (" %d ", currentNode->x);
if (currentNode->r)
RLQueue.push (currentNode->r); //Insert right first
if (currentNode->l)
RLQueue.push (currentNode->l);
LRQueue.pop ();
if (LRQueue.empty ()) {
leftToRight=false;
printf ("\n");
}
}
else {
currentNode = RLQueue.top();
printf (" %d ", currentNode->x);
if (currentNode->l)
LRQueue.push (currentNode->l); //Insert left first
if (currentNode->r)
LRQueue.push (currentNode->r);
RLQueue.pop ();
if (RLQueue.empty ()) {
leftToRight=true;
printf ("\n");
}
}
}
printf ("\n");
}
@sse : Good explanation. However it wont be that simple i think when you are performing parsing. because:
1. There might be different functions in different class hierarchy with same name and one is get called but another wont. For Ex.
class A {
fun1 ();
};
class B {
fun1 ();
};
B b;
b.fun1 (); //note fun1 is called but you need to determine b's type over here. So you have to maintain symbol table as well
2. functions called with using object but when you call it from class's another member function it wont called using any object (syntactically). For ex.
class A {
fun1 ();
};
class B {
fun1 ();
public :
fun2 () {
fun1 ()
}
};
In above scenario, you need to mark only B's fun1 as known. Also need to maintain per class functions list OR need to perform name mangling.
3. There is function declaration , definition and function call. You need to differentiate all those. It is more difficult when there is no argument. For ex.
//declaration
fun1 ();
//definition
fun1 ()
{
// do relevant stuff
}
//function call
fun1 ()
Most importantly, I think interviewer might have asked to write sudo code or algorithm instead of function/code (question says that write a function).
@ airfang613 : Excellent !!! It works perfectly with below changes :
int idx = (input - 1) % 26;
instead of
T idx = (input - 1) % 26;
Also there is not constructor which convert char to string, so you need to create char [26][2] array with string like "A\0", "B\0"...etc
There is no constructor available which will change char to string.so below statement need to modify :
res = kLookUp[idx] + res;
as
res.insert(res.begin(), kLookUp[idx]);
Can't access a file in parallel If any process lock the file. Incase of shared lock as well, It may degrade performance as it is IO operation, if your are not reading file sequentially, performance will degrade. You need to access file using memory mapping or using buffered I/O.
You can also use your own buffering mechanism creating a separate thread to maintain read buffer. Creating Consumer and Producer relating ship between two threads.
Here is C++ solution using set
- Sach July 02, 2015