Skip to content

Instantly share code, notes, and snippets.

@iCHAIT
Last active April 11, 2016 14:27
Show Gist options
  • Save iCHAIT/2d1d4c8b0a61fb6f6d4e57eaae53f6cb to your computer and use it in GitHub Desktop.
Save iCHAIT/2d1d4c8b0a61fb6f6d4e57eaae53f6cb to your computer and use it in GitHub Desktop.
#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 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