Skip to content

Instantly share code, notes, and snippets.

@iCHAIT
Last active Apr 11, 2016
Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
int main() {
// your code goes here
char *s1, *s2;
printf("%d%d", sizeof(s1), sizeof(s2));
return 0;
}
// codechef IDE gives answer - 4,4
// my machine gives - 8,8
// correct answer - 4,2
# include <stdio.h>
# include <stdlib.h>
int main()
{
extern int i;
printf("\n%d",i);
return 0;
}
int i=20;
// how come this works?
# include <stdio.h>
int main()
{
int i=4;
switch(i)
{
default:
printf("\ndefault\n");
case 1:
printf("\ncase 1\n");
break;
case 2:
printf("\ncase 2\n");
break;
case 3:
printf("\ncase 3\n");
break;
}
return 0;
}
/* gives output -
default
case 1
how?
*/
# include <stdio.h>
int main()
{
int x=10,y=20,z=5,i;
i = x<y<z;
printf("\n%d",i);
return 0;
}
// how does this gives answer 1?
#include <stdio.h>
int main() {
int arr[] = {2,3,4, 1,6};
printf("\n%d\n%d", arr, sizeof ( arr ));
return 0;
}
//output - 123445, 20
// books gives 10
@iCHAIT
Copy link
Author

iCHAIT commented Apr 7, 2016

Q 1.16?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 7, 2016

Q 1.15?

compiler will throw a void int mismatch, what if we define int display() // works with warnings

@iCHAIT
Copy link
Author

iCHAIT commented Apr 8, 2016

Ist question of this

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

HOTS

  • Difference between struct and union?
  • Difference between malloc and calloc?
  • Sorting a stack
  • Suspicious pointer conversion?
  • Given an array of n numbers, return an array ans such that ans[i] contains the product of all elements in array except array[i]. Ex. array = {1, 7, 4, 3}, ans = {84, 12, 21, 28}. Do this in O(n) time and without using division.
  • The lift problem
  • The famous 2 eggs problem

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

HOTS @ adobe.pdf

I have a hard disk of 100 gb.It has one and only file of 80 GB (database backup).
What happens if i delete it and it goes to recycle bin.
Follow-up questions:
Is the memory freed from the hard disk.
What happens if i move it from one drive to another.
What happens in case of permanent delete.
What happens when we format the disk.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Gmail wants to provide a new enhanced service which offers auto-backup , promotional mails filtered,extra space for mail box etc which costs 50 rs per month.
They want to run a provisioning program which shows a popup to certain customers having options-

  1. Yes and then redirected to payment and all
  2. Remind me after 2 weeks.
  3. No
  4. Not happy with the service offered.
    Asked me to test this model.
    Later he asked me the factors which i will consider for choosing set of customers for this program.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

I have installed msword in my pc.Copied the C/program files/ folder into pen drive and pasted in another pc.Will it work? Why /Why not?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

There is one fb user in India and another in US.When they communicate, do they connect to same server. If not then how does the communication happen?What is the data that is being transferred.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Consider the code snippet

main()
{
  cout << "Hello";
} 

Without touching the above code snippet print
Hi
Hello
Bye

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Consider a recursive function with no end condition and architecture of your own laptop. What will happen? After how much time will the program crash.(Calculations and perfect answer was required)

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Write a client server simple code. How will you handle multiple requests? Will increasing number of threads solve the problem. What should be the optimal number of threads depending upon your computer architecture if you are receiving many requests in 10milliseconds time.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

How google handles 1 billion request in 1msec.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

three tires are given which can travel 14, 20, 26 kms . Two tires are required for travelling. Find the maximum distance which can be travelled.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

How much memory is made available to a user program by the kernel, is there any limit to it? What is the range of addresses a user program can have at max, what determines it?What happens if excess memory is allocated to a user program, say malloc in an infinite loop?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

What is the difference between mutex and a semaphore. Write down a crude implementation of both. How would you solve the mutual exclusion problem using semaphore. Propose a solution to the readers-writer problem.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

There are 2 people A and B. Both A and B have equal speed of walking. Both A and B have equal speed of running. Now assume that A runs for half the time and walks for half the time. While, B runs for half the distance and walks for half the distance. Can we tell conclusively who will win in a race?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

write an eight digit number in which 0th position represents number of zero in that number, 1st position represents number of 1’s in the number , 2nd number represents number of 2’s in the number …so on.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

U have n vending machine out of which 1 is defected find the defected machine in O(1) on solving this he modified it give general solution for the case in which 2 machine are defected O(1) solution were required.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Write a various test cases for checking the functionality of Adobe reader while saving it .

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

you have 100 coins on table, 60 heads and 40 tails. With your eyes closed, how can you separate the coins into 2 groups such that each group has same number of tails.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Then he asked me how you open notepad without using mouse.(simple),then he explain the internal logic behind this like what will happen if you press ctrl+s,ctrl+o etc.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

He told me that if he mails me an excel file and when i try to open it, it doesnt open. asked me all the possible reason to it.?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

He then told me that if he makes a new web browser and asks me to test it, what all thinks i would test. (again gave me a lot of time to think and tell him as many as i can)

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Find 2nd largest element in given array using min. no. of comparisons. I told him solution with 2n comparisions, but he kept insisting me to think more and reduce the comparisons.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

An array is given of size m. First n elements (n < m) are filled and rest contains junk. Write code for linear search to find an element x in first n elements. There would be 2 comparisons per iteration: (i < n) in for loop and (arr[i]==x). You have to reduce the no. of comparisons to 1 comparison/iteration.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

He asked me to implement a spell checker- first check if it is the correct word and then check words which are similar to the given word. Eg how google shows in Did you mean!

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Interviewer : A recursive function has no termination condition. What will happen when it runs.
Me: Stack overflow.

Interviewer: Given a simple recursive function which calls itself:

eg: void f() {
f();
}
How long will it run in your laptop.

Me: I asked for certain assumptions.
1st: what stack space shall I assume?
Interviewer: Half of RAM.(4 GB)

Me: 2nd: I further assumed 4 bytes are required for addressing.

time = (4 GB/ 4 Byte)/frequency; frequency-> processor speed (2.0 GHz)

This is not accurate solution… accuracy involves lot other parameters.
He was just checking my Approach that how I solve the problem.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

. Given an array of 1000 elements.Elements are multiplied in a for loop from 1 to thousand.
Time of execution is x milliseconds. How will you reduce x?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

There is box and in that box there are real numbers ranging from 1 to 10. What is the probability of getting 2 out of that box.

answer - 0

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

  • how to compile two .cpp codes together.
  • what is makefile? utilities?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

  • difference between #include “” and #include <>.
  • what gets included when we do #include?? does it includes the whole definition of the function or just the prototype?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Given 2 sorted arrays , find kth smallest element among them.

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Suppose you have a repository of a million records of mobile numbers. A lot of discussion on how will you store these numbers so that you can check whether a given number already exists in minimum space and time complexity?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Given a number say N. WAP to print the next greater number by using the same set of digits of N. For example:

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

Left shiiting an unsigned int or char by 1 is always equivalent to multiplying it by 2?

@iCHAIT
Copy link
Author

iCHAIT commented Apr 9, 2016

  • how would you dynamically allocate a 1D array?
  • how would you dynamically allocate a 2D array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment