InMobi Interview Question for SDE1s


Country: India
Interview Type: Written Test




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

I don't understand why the output of 100 will the the value you give, I thought it should be 1 / (2 * 100) = 0.005.
Here is my code

import java.util.Scanner;

public class Solution{
	public String getAnswer(int input){
		input *= 2;
		int numerator = 1;
		StringBuilder sb = new StringBuilder();
		sb.append("0.");
		while(numerator != 0){
			//times 10 first
			numerator *= 10;
			//if numerator is less than denomerator
			//we have to times 10 again and again
			//and each time, we have to append a 0 
			//to the answer
			while(numerator < input){
				numerator *= 10;
				sb.append("0");
			}
			sb.append(numerator / input);
			numerator = numerator % input;
		}
		return sb.toString();
}

	public static void main(String[] args){
		int T;
		Scanner scanner = new Scanner(System.in);
		Solution s = new Solution();
		T = scanner.nextInt();
		for(int i  = 0; i < T; ++i){
			int input = scanner.nextInt();
			System.out.println(s.getAnswer(input));
		}
	}
}

- ravio May 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import sys

file = open('input')
for line in file:
    denominator = 2*int(line)
    numerator = 1 
    print('0.', end='')
    rem = -1
    while(rem != 0):
        numerator = numerator*10
        while numerator < denominator:
            numerator = numerator*10
            print('0', end='')
        else: 
            div = numerator / denominator
            rem = numerator % denominator
            print(int(div), end='')
            numerator=rem
    print()

- Ahana May 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't really understand why this is such a hard task, this is grade 2 math.
C#

static string recurs(int currnum, int divider, string curr)
        {
            currnum *= 10;
            int remain = currnum % divider;
            currnum /= divider;
            curr += currnum.ToString();
            Console.Write(currnum.ToString());
            if (remain == 0)
                return curr;
            else
                recurs(remain, divider, curr);
            return curr;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int number = n * 2;
            Console.Write("0.");
            recurs(1, number, "0.");
            Console.WriteLine();
            Console.ReadLine();
        }

- Aron June 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Guys, you have not understood the problem, its not 1/(2 x n) , its 1/(2 to the power n), its complicated calculation

- Seetha June 01, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Guys, you have not understood the problem, its not 1/(2 x n) , its 1/(2 to the power n), its complicated calculation

- Seetha June 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1/2^n can be written as (5/10)^n. now calculating 5^n
double d=Math.pow(5,n);(or can be done in logn time)(power of 5 will never end in 0)
int length=String.valueOf(d).length()
numberOfZeroseBefore=n-length

- Atul January 03, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

System.out.println(new BigDecimal(1 / Math.pow(2, n)).toPlainString());

- Anonymous September 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

System.out.println(new BigDecimal(1 / Math.pow(2, 100)).toPlainString());

- Anonymous September 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

System.out.println(new BigDecimal(1 / Math.pow(2, 100)).toPlainString());

- JayDee September 02, 2015 | 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