Search Media Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<stdio.h>
void main()
{
for(int i=1;i<=100;i++)
printf("%d",i);
}
less no of line it achevies all properties of algorthims

- vinil December 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

vinil it will take 100+1+1 that is space complexity is 102
and what about time and power complexity(means cpu utilization)

- sudhakar810nit February 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Compile time:

#include <iostream>
#include <ostream>

template <int N>
struct printN
{
    static void print(std::ostream& os)
    {
        printN<N-1>::print(os);
        os << N << std::endl;
    }
};

template <>
struct printN<1>
{
    static void print(std::ostream &os)
    {
        os << 1 << std::endl;
    }
};

int main() {
    printN<100>::print(std::cout);
    return 0;
}

- Ganesh August 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

plz explain also what is the complexities............
space and time complexity

- sudhakar810nit August 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

space & time O(1) { constant }

- Ganesh M August 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please write the code in c instead of c++?

- Arun September 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

#include<stdio.h>
void main()
{
for(int i=1;i<=100;i++)
printf("%d",i);
}
less no of lines

- vinil December 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

{
char i=-9;
while((i+=10)<100 && printf("%d%d%d%d%d%d%d%d%d%d",i,i+1,i+2,i+3,i+4,i+5,i+6,i+7,i+8,i+9));
}

it will reduce the time complexity by 10 times.
yes bt increase space complexity by 10 times.
bt over all 10+10+1 =21
rather dn 100+1+1=102

- sudhakar810nit February 03, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<conio.h>
struct
{
unsigned i:7;
}a;
void main()
{
clrscr();
while(++a.i!=100 && printf("%d",a.i));
getch();
}

EXPLANATION
look here-
1) BIT FIELD CONCEPT
i prefer bit field concept because we need only print 1-100 and it need only 7 bit so it save memory(space)

2)rather than using post increment i prefer pre increment becausethe implementation of post-increment (a++) must create a temporary storage for housing the original value of a, increment/store a, and return the original temporary value. In contrast, pre-increment (++a) only has to increment/store the value and return it – no temporary required.
IT ALSO MINIMIZE SAPCE (as compare to post increment)

3)the time complexity is O(n) and space complexity is just O(1) because here i used only one variable

4) but i am little bit confuse at comparison portion
in my opinion (!=) faster than < or > operator so thts the reson why i use !=.

- sudhakar810nit February 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(i=0;i++<=100;printf("%d",i););

- santhosh reddy September 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

What kind of stupid quesiton is this???? Complexities for a FIXED problem?
What's wrong with a loop? A few variables?

Here is the best I can come up with (in C like you want):

puts("1 2 3 4 5 6 7 8 9 10 11 12 <type it in here> 99 100");


//printf("1 2 3 4 .. 9 100") is more expensive because it is a varargs function

- bigphatkdawg September 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

num(int n)
{
if (n<100)
{
printf("%d",n);
num(n+1);
}
else
return;
}

- pranav August 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

pranav: here u make recursive function so it take more memory as well as power complexity is high

- Anonymous August 31, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Can we use system clock to get start time, read till its start time + 100 units. Here we are neither creating any variable(space complexity), nor incrementing them (time complexity).
Depending on the programming language, the cost of reading the system clock is only task we will be performing.

- kulldeep September 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Reading the system clock is usually going to be considerably more expensive than doing arithmetic or converting integers to strings. Besides, if you have to wait for the clock to change, you are probably constantly polling the clock, which means you're probably doing a lot more than just 100 reads. Comparisons to determine whether the time has changed since the last time you polled the clock are also not free.

It's not true that you won't create any variables, because you will need one to hold the time returned from the system clock, and you will also need a variable to hold the previous time returned by the system clock so that you can see whether it has changed. You'll also need one to hold the clock start time and / or the end time. You can see this program will have at least a few variables.

- eugene.yarovoi September 10, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More