Interview Question


Country: India
Interview Type: In-Person




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

Use integer array to represent the number. That is how BigInteger is internally implemented in java api.

Take a look at the source code over here(Replace - by .) :

www-docjar-org/html/api/java/math/BigInteger.java.html

- chandershivdasani September 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

linked list or arraylist is good idea ....

- kavita.123green September 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

an array of chars or int

- someone September 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Try to use linked list.

Generally interviewers don't interested in common API, they are interested in algorithms. So, BigInteger not suitable. Array cannot be used too because interviewers interested in "unlimited" numbers, so only linked list is apropriate for this task.

- Vaclav September 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can u give a program implementation for it.

- pulkit.2810 September 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Arrays are suitable if you reallocate them when necessary. You could imagine using something like an ArrayList.

- eugene.yarovoi September 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Eugene, I can agree with you due to technical issues. But I'm still thinking that interviewers would like see something "linked list"-based. Maybe I'm wrong :)

P.S. You can easily find answer for this question at Laakmann's book "CRACKING THE CODING INTERVIEW, FOURTH EDITION", page 108

- Vaclav September 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, I really don't think there's anything wrong with using an array. You could discuss the tradeoffs with your interviewer.

Java uses an array to implement BigInteger.

- eugene.yarovoi September 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stdlib.h>
unsigned int count()
{
static unsigned long int num=0;
char ch;
if((ch = getchar())!='\n'){
num = 1 + count();
}
ungetc(ch, stdin);
return num;
}


int main()
{
char *str;
unsigned int long num;
num = count();
printf("number of char in the string is %l", num);
str = (char*)malloc((num+1)*sizeof(char));
scanf("%s", str);
return 0;
}


with the help of following code we can store at most (2^32-2) numbers of single digit in a string.. and as this is a array so we can easily use it in our program and

- Ashim September 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is the need of count function here?? We can easily do this as following..
  str=(char*)malloc(sizeof(char));
  scanf("%s",str);

- Anonymous September 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

To use linked list is best to store .....data

- angel September 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

use Biginteger in java or c#

- Ankit singh September 20, 2012 | Flag Reply


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